From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C0AD7A00C5 for ; Fri, 29 May 2020 05:59:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7467C1D5EC; Fri, 29 May 2020 05:59:12 +0200 (CEST) Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by dpdk.org (Postfix) with ESMTP id 090551D5EC for ; Fri, 29 May 2020 05:59:10 +0200 (CEST) Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4439A3996BD3BC17A560 for ; Fri, 29 May 2020 11:59:03 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Fri, 29 May 2020 11:58:54 +0800 From: "Wei Hu (Xavier)" To: CC: , Date: Fri, 29 May 2020 11:57:33 +0800 Message-ID: <1590724654-23075-6-git-send-email-xavier.huwei@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1590724654-23075-1-git-send-email-xavier.huwei@huawei.com> References: <1590724654-23075-1-git-send-email-xavier.huwei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-stable] [PATCH 19.11 5/6] net/hns3: fix Rx interrupt after reset X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" From: Chengwen Feng [ upstream commit af1857b05c63caac3cb0f84deca7a43e0bcf4beb ] Currently, Rx interrupt cannot work normally after reset (such as FLR, global reset and IMP reset), when running l3fwd-power application based on hns3 network engine. The root cause is that the hardware configuration about Rx interrupt does not recover after reset. This patch fixes it with the following modification. 1. The internal static function named hns3(vf)_init_ring_with_vector is moved from hns3_init_pf to hns3(vf)_init_hardware because hns3(vf)_init_hardware is called both in the initialization and the RESET_STAGE_DEV_INIT stage of the reset process. 2. The internal static function named hns3(vf)_restore_rx_interrupt is added in hns3(vf)_restore_conf, it is used to recover hardware configuration about interrupt vectors of rx queues in the RESET_STAGE_DEV_INIT stage of the reset process. 3. The internal static function named hns3_dev_all_rx_queue_intr_enable and hns3_enable_all_queues are added in hns3(vf)_dev_start(which called in the initialization, so after calling the rte_eth_dev_start API successfully, the driver is ready to work. 4. The function named hns3_dev_all_rx_queue_intr_enable and hns3_enable_all_queues are also added in hns3(vf)_start_service(which called in the RESET_STAGE_DEV_INIT stage of the reset process), so after start_service, the driver is ready to work. Note: 1. Because FLR will clear queue's interrupt enable bit hardware configuration, so we add calling hns3_dev_all_rx_queue_intr_enable to enable interrupt before enabling queues. 2. After finished the initialization, we can enable queues to work by calling the internal function named hns3_enable_all_queues. Fixes: 02a7b55657b2 ("net/hns3: support Rx interrupt") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Signed-off-by: Wei Hu (Xavier) Signed-off-by: Hongbo Zheng --- drivers/net/hns3/hns3_ethdev.c | 84 ++++++++++++++++++++++++++++++++------- drivers/net/hns3/hns3_ethdev_vf.c | 83 ++++++++++++++++++++++++++++++-------- drivers/net/hns3/hns3_intr.c | 2 + drivers/net/hns3/hns3_rxtx.c | 27 ++++++++++++- drivers/net/hns3/hns3_rxtx.h | 2 + 5 files changed, 165 insertions(+), 33 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index 35f317a..c693913 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -4134,6 +4134,19 @@ hns3_init_hardware(struct hns3_adapter *hns) PMD_INIT_LOG(ERR, "Failed to config gro: %d", ret); goto err_mac_init; } + + /* + * In the initialization clearing the all hardware mapping relationship + * configurations between queues and interrupt vectors is needed, so + * some error caused by the residual configurations, such as the + * unexpected interrupt, can be avoid. + */ + ret = hns3_init_ring_with_vector(hw); + if (ret) { + PMD_INIT_LOG(ERR, "Failed to init ring intr vector: %d", ret); + goto err_mac_init; + } + return 0; err_mac_init: @@ -4212,16 +4225,6 @@ hns3_init_pf(struct rte_eth_dev *eth_dev) goto err_fdir; } - /* - * In the initialization clearing the all hardware mapping relationship - * configurations between queues and interrupt vectors is needed, so - * some error caused by the residual configurations, such as the - * unexpected interrupt, can be avoid. - */ - ret = hns3_init_ring_with_vector(hw); - if (ret) - goto err_fdir; - return 0; err_fdir: @@ -4366,6 +4369,31 @@ hns3_map_rx_interrupt(struct rte_eth_dev *dev) return ret; } +static int +hns3_restore_rx_interrupt(struct hns3_hw *hw) +{ + struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id]; + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; + uint16_t q_id; + int ret; + + if (dev->data->dev_conf.intr_conf.rxq == 0) + return 0; + + if (rte_intr_dp_is_en(intr_handle)) { + for (q_id = 0; q_id < hw->used_rx_queues; q_id++) { + ret = hns3_bind_ring_with_vector(hw, + intr_handle->intr_vec[q_id], true, + HNS3_RING_TYPE_RX, q_id); + if (ret) + return ret; + } + } + + return 0; +} + static void hns3_restore_filter(struct rte_eth_dev *dev) { @@ -4393,17 +4421,30 @@ hns3_dev_start(struct rte_eth_dev *dev) return ret; } - hw->adapter_state = HNS3_NIC_STARTED; - rte_spinlock_unlock(&hw->lock); ret = hns3_map_rx_interrupt(dev); - if (ret) + if (ret) { + hw->adapter_state = HNS3_NIC_CONFIGURED; + rte_spinlock_unlock(&hw->lock); return ret; + } + + hw->adapter_state = HNS3_NIC_STARTED; + rte_spinlock_unlock(&hw->lock); + hns3_set_rxtx_function(dev); hns3_mp_req_start_rxtx(dev); rte_eal_alarm_set(HNS3_SERVICE_INTERVAL, hns3_service_handler, dev); hns3_restore_filter(dev); + /* Enable interrupt of all rx queues before enabling queues */ + hns3_dev_all_rx_queue_intr_enable(hw, true); + /* + * When finished the initialization, enable queues to receive/transmit + * packets. + */ + hns3_enable_all_queues(hw, true); + hns3_info(hw, "hns3 dev start successful!"); return 0; } @@ -4484,12 +4525,12 @@ hns3_dev_stop(struct rte_eth_dev *dev) rte_spinlock_lock(&hw->lock); if (rte_atomic16_read(&hw->reset.resetting) == 0) { hns3_do_stop(hns); + hns3_unmap_rx_interrupt(dev); hns3_dev_release_mbufs(hns); hw->adapter_state = HNS3_NIC_CONFIGURED; } rte_eal_alarm_cancel(hns3_service_handler, dev); rte_spinlock_unlock(&hw->lock); - hns3_unmap_rx_interrupt(dev); } static void @@ -5003,9 +5044,18 @@ hns3_start_service(struct hns3_adapter *hns) eth_dev = &rte_eth_devices[hw->data->port_id]; hns3_set_rxtx_function(eth_dev); hns3_mp_req_start_rxtx(eth_dev); - if (hw->adapter_state == HNS3_NIC_STARTED) + if (hw->adapter_state == HNS3_NIC_STARTED) { hns3_service_handler(eth_dev); + /* Enable interrupt of all rx queues before enabling queues */ + hns3_dev_all_rx_queue_intr_enable(hw, true); + /* + * When finished the initialization, enable queues to receive + * and transmit packets. + */ + hns3_enable_all_queues(hw, true); + } + return 0; } @@ -5039,6 +5089,10 @@ hns3_restore_conf(struct hns3_adapter *hns) if (ret) goto err_promisc; + ret = hns3_restore_rx_interrupt(hw); + if (ret) + goto err_promisc; + if (hns->hw.adapter_state == HNS3_NIC_STARTED) { ret = hns3_do_start(hns, false); if (ret) diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c index 428a6d2..11d7dea 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -1235,6 +1235,18 @@ hns3vf_init_hardware(struct hns3_adapter *hns) goto err_init_hardware; } + /* + * In the initialization clearing the all hardware mapping relationship + * configurations between queues and interrupt vectors is needed, so + * some error caused by the residual configurations, such as the + * unexpected interrupt, can be avoid. + */ + ret = hns3vf_init_ring_with_vector(hw); + if (ret) { + PMD_INIT_LOG(ERR, "Failed to init ring intr vector: %d", ret); + goto err_init_hardware; + } + ret = hns3vf_set_alive(hw, true); if (ret) { PMD_INIT_LOG(ERR, "Failed to VF send alive to PF: %d", ret); @@ -1325,16 +1337,6 @@ hns3vf_init_vf(struct rte_eth_dev *eth_dev) hns3_set_default_rss_args(hw); - /* - * In the initialization clearing the all hardware mapping relationship - * configurations between queues and interrupt vectors is needed, so - * some error caused by the residual configurations, such as the - * unexpected interrupt, can be avoid. - */ - ret = hns3vf_init_ring_with_vector(hw); - if (ret) - goto err_get_config; - (void)hns3_stats_reset(eth_dev); return 0; @@ -1444,13 +1446,12 @@ hns3vf_dev_stop(struct rte_eth_dev *dev) rte_spinlock_lock(&hw->lock); if (rte_atomic16_read(&hw->reset.resetting) == 0) { hns3vf_do_stop(hns); + hns3vf_unmap_rx_interrupt(dev); hns3_dev_release_mbufs(hns); hw->adapter_state = HNS3_NIC_CONFIGURED; } rte_eal_alarm_cancel(hns3vf_service_handler, dev); rte_spinlock_unlock(&hw->lock); - - hns3vf_unmap_rx_interrupt(dev); } static void @@ -1602,6 +1603,31 @@ hns3vf_map_rx_interrupt(struct rte_eth_dev *dev) return ret; } +static int +hns3vf_restore_rx_interrupt(struct hns3_hw *hw) +{ + struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id]; + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; + uint16_t q_id; + int ret; + + if (dev->data->dev_conf.intr_conf.rxq == 0) + return 0; + + if (rte_intr_dp_is_en(intr_handle)) { + for (q_id = 0; q_id < hw->used_rx_queues; q_id++) { + ret = hns3vf_bind_ring_with_vector(hw, + intr_handle->intr_vec[q_id], true, + HNS3_RING_TYPE_RX, q_id); + if (ret) + return ret; + } + } + + return 0; +} + static void hns3vf_restore_filter(struct rte_eth_dev *dev) { @@ -1627,17 +1653,29 @@ hns3vf_dev_start(struct rte_eth_dev *dev) rte_spinlock_unlock(&hw->lock); return ret; } - hw->adapter_state = HNS3_NIC_STARTED; - rte_spinlock_unlock(&hw->lock); ret = hns3vf_map_rx_interrupt(dev); - if (ret) + if (ret) { + hw->adapter_state = HNS3_NIC_CONFIGURED; + rte_spinlock_unlock(&hw->lock); return ret; + } + hw->adapter_state = HNS3_NIC_STARTED; + rte_spinlock_unlock(&hw->lock); + hns3_set_rxtx_function(dev); hns3_mp_req_start_rxtx(dev); rte_eal_alarm_set(HNS3VF_SERVICE_INTERVAL, hns3vf_service_handler, dev); hns3vf_restore_filter(dev); + /* Enable interrupt of all rx queues before enabling queues */ + hns3_dev_all_rx_queue_intr_enable(hw, true); + /* + * When finished the initialization, enable queues to receive/transmit + * packets. + */ + hns3_enable_all_queues(hw, true); + return ret; } @@ -1789,9 +1827,18 @@ hns3vf_start_service(struct hns3_adapter *hns) eth_dev = &rte_eth_devices[hw->data->port_id]; hns3_set_rxtx_function(eth_dev); hns3_mp_req_start_rxtx(eth_dev); - if (hw->adapter_state == HNS3_NIC_STARTED) + if (hw->adapter_state == HNS3_NIC_STARTED) { hns3vf_service_handler(eth_dev); + /* Enable interrupt of all rx queues before enabling queues */ + hns3_dev_all_rx_queue_intr_enable(hw, true); + /* + * When finished the initialization, enable queues to receive + * and transmit packets. + */ + hns3_enable_all_queues(hw, true); + } + return 0; } @@ -1813,6 +1860,10 @@ hns3vf_restore_conf(struct hns3_adapter *hns) if (ret) goto err_vlan_table; + ret = hns3vf_restore_rx_interrupt(hw); + if (ret) + goto err_vlan_table; + if (hw->adapter_state == HNS3_NIC_STARTED) { ret = hns3vf_do_start(hns, false); if (ret) diff --git a/drivers/net/hns3/hns3_intr.c b/drivers/net/hns3/hns3_intr.c index 6c3ebd3..9953a1d 100644 --- a/drivers/net/hns3/hns3_intr.c +++ b/drivers/net/hns3/hns3_intr.c @@ -1001,7 +1001,9 @@ hns3_reset_post(struct hns3_adapter *hns) hw->reset.attempts = 0; hw->reset.stats.success_cnt++; hw->reset.stage = RESET_STAGE_NONE; + rte_spinlock_lock(&hw->lock); hw->reset.ops->start_service(hns); + rte_spinlock_unlock(&hw->lock); gettimeofday(&tv, NULL); timersub(&tv, &hw->reset.start_time, &tv_delta); hns3_warn(hw, "%s reset done fail_cnt:%" PRIx64 diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c index edf0038..a0fcb4c 100644 --- a/drivers/net/hns3/hns3_rxtx.c +++ b/drivers/net/hns3/hns3_rxtx.c @@ -315,7 +315,7 @@ hns3_init_tx_queue_hw(struct hns3_tx_queue *txq) HNS3_CFG_DESC_NUM(txq->nb_tx_desc)); } -static void +void hns3_enable_all_queues(struct hns3_hw *hw, bool en) { uint16_t nb_rx_q = hw->data->nb_rx_queues; @@ -543,6 +543,26 @@ hns3_queue_intr_enable(struct hns3_hw *hw, uint16_t queue_id, bool en) hns3_write_dev(hw, addr, value); } +/* + * Enable all rx queue interrupt when in interrupt rx mode. + * This api was called before enable queue rx&tx (in normal start or reset + * recover scenes), used to fix hardware rx queue interrupt enable was clear + * when FLR. + */ +void +hns3_dev_all_rx_queue_intr_enable(struct hns3_hw *hw, bool en) +{ + struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id]; + uint16_t nb_rx_q = hw->data->nb_rx_queues; + int i; + + if (dev->data->dev_conf.intr_conf.rxq == 0) + return; + + for (i = 0; i < nb_rx_q; i++) + hns3_queue_intr_enable(hw, i, en); +} + int hns3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id) { @@ -740,6 +760,10 @@ hns3_start_tx_queues(struct hns3_adapter *hns) hns3_init_tx_ring_tc(hns); } +/* + * Start all queues. + * Note: just init and setup queues, and don't enable queue rx&tx. + */ int hns3_start_queues(struct hns3_adapter *hns, bool reset_queue) { @@ -761,7 +785,6 @@ hns3_start_queues(struct hns3_adapter *hns, bool reset_queue) } hns3_start_tx_queues(hns); - hns3_enable_all_queues(hw, true); return 0; } diff --git a/drivers/net/hns3/hns3_rxtx.h b/drivers/net/hns3/hns3_rxtx.h index ba89425..b751472 100644 --- a/drivers/net/hns3/hns3_rxtx.h +++ b/drivers/net/hns3/hns3_rxtx.h @@ -303,8 +303,10 @@ void hns3_dev_rx_queue_release(void *queue); void hns3_dev_tx_queue_release(void *queue); void hns3_free_all_queues(struct rte_eth_dev *dev); int hns3_reset_all_queues(struct hns3_adapter *hns); +void hns3_dev_all_rx_queue_intr_enable(struct hns3_hw *hw, bool en); int hns3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id); int hns3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id); +void hns3_enable_all_queues(struct hns3_hw *hw, bool en); int hns3_start_queues(struct hns3_adapter *hns, bool reset_queue); int hns3_stop_queues(struct hns3_adapter *hns, bool reset_queue); void hns3_dev_release_mbufs(struct hns3_adapter *hns); -- 2.7.4