From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 515E946027; Thu, 9 Jan 2025 05:04:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1432F40E64; Thu, 9 Jan 2025 05:04:01 +0100 (CET) Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) by mails.dpdk.org (Postfix) with ESMTP id 6CD7840E3A for ; Thu, 9 Jan 2025 05:03:57 +0100 (CET) X-QQ-mid: bizesmtp84t1736395432tl3rxqu3 X-QQ-Originating-IP: I7jNcm1A7GMGBStU/MRYees/+/k3Ckn8mX6Q1Xmdivg= Received: from DSK-zaiyuwang.trustnetic.com ( [218.72.126.41]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 09 Jan 2025 12:03:51 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6501786585617269005 From: Zaiyu Wang To: dev@dpdk.org Cc: Zaiyu Wang , Jiawen Wu Subject: [PATCH 12/15] net/ngbe: add start/stop/reset/close ops for VF device Date: Thu, 9 Jan 2025 12:02:22 +0800 Message-Id: <20250109040227.1016-13-zaiyuwang@trustnetic.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20250109040227.1016-1-zaiyuwang@trustnetic.com> References: <20250109040227.1016-1-zaiyuwang@trustnetic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvrgz:qybglogicsvrgz5a-1 X-QQ-XMAILINFO: MvUCj+jJbjsSDvBXUm3r37+t1bLhyUsuJfcXfw9rHCs5XYuc85YXhVpA Wpn29Y+rYz87P7j23gRex8KaKLFLI1axCTn2oJc7u1vX2xbXU43TlQ2wIh9NNLFYUT5PlXN h78Bj6buZ5s8qt9s78NlUx/UoZ7Wh+fsrvdj5RNyCpZG+e1ZKA/ZT/1DLVroWkQGVqGUGS/ 2R/bKo2323XtL2RBrt8gGkY4EnxkoKd7JHkBiMlNUDmglEqUUgavbpwQPsoW4i8s/ttMmu7 C++KD0uMI8HASCJTrs2dQCnCd2aBKlNijQdTqbLtsgdZ3bGv1oNuEqU7yYV8SrOrtJol2Sd FNhsq/LzB8JDKhMJ8qpKc3qYGWIIKoN5ucQ+jH1LIe9zle29VTv/WwFQfxCM/5Cr9/9JUmA y/Uizti/2XkCs5RQ87kadtzEa3sAS2z2fhRKcp2iU4ECy3L8jHH2/In5CMgJnC0lkIf04VZ gm8rhHuL4ncbFH7Uaqt4yrdrAMB5a11yNdPTGcMDbZbznoDSBpL0sz6FN5+YQXAVvM6v9ev d5+WBfdhMskvNDVQio1hT/0o21IiKKjT1BOnR1A0xtDPs/LuhTvm+G6Q0HkFeju8HCI7ZQX AXVxDhhWQSDmt24H0NN5hrqVRMHFaHplSKHIKbrycKoy3FFR3ERbD/LW9eV/vA7u1d1OyMB Lg4K8+mQb++rfLvk0Tb/43MYrfgOihoZTIXAbGT+20UFoP+TDnAl4NbQZPfn55QeOE2xusE 0CCyxhVAvUkgZ4VJNamCJRw+eOrmIjehX4+z9dBFHooFappOd7JjTj7D016pDGbXUP6aKRp nv56vEuIaUKA29Ym12g7d7qTekuqkhAVMhftsGzmzyFf5Js95ZUKtsHTcpm9VzVGz+wHQ1c S59YO/1KAb5dKTATYRYjZMAt7f3DvhBd+BmPTYHGNJw9IPktovJE3Z93sJgKrT/Wg7IuLjs HPL47VWl5M5/tDiX2PsM0cH9u6V0TW2Gv2msXZViOxlSUQUTeAnFGn75j3f7h+N5GvDpbdW 1C5GJL2g== X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= X-QQ-RECHKSPAM: 0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add the complete configuration process for start/stop/reset/close ops, so that applications can enable the device correctly. Signed-off-by: Zaiyu Wang --- drivers/net/ngbe/ngbe_ethdev_vf.c | 170 +++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 1 deletion(-) diff --git a/drivers/net/ngbe/ngbe_ethdev_vf.c b/drivers/net/ngbe/ngbe_ethdev_vf.c index 434776b26b..ac02b7ac7f 100644 --- a/drivers/net/ngbe/ngbe_ethdev_vf.c +++ b/drivers/net/ngbe/ngbe_ethdev_vf.c @@ -555,12 +555,151 @@ ngbevf_dev_configure(struct rte_eth_dev *dev) return 0; } +static int +ngbevf_dev_start(struct rte_eth_dev *dev) +{ + struct ngbe_hw *hw = ngbe_dev_hw(dev); + uint32_t intr_vector = 0; + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; + + int err, mask = 0; + + PMD_INIT_FUNC_TRACE(); + + err = hw->mac.reset_hw(hw); + if (err) { + PMD_INIT_LOG(ERR, "Unable to reset vf hardware (%d)", err); + return err; + } + hw->mac.get_link_status = true; + + /* negotiate mailbox API version to use with the PF. */ + ngbevf_negotiate_api(hw); + + ngbevf_dev_tx_init(dev); + + /* This can fail when allocating mbufs for descriptor rings */ + err = ngbevf_dev_rx_init(dev); + + /** + * In this case, reuses the MAC address assigned by VF + * initialization. + */ + if (err != 0 && err != NGBE_ERR_INVALID_MAC_ADDR) { + PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err); + ngbe_dev_clear_queues(dev); + return err; + } + + /* Set vfta */ + ngbevf_set_vfta_all(dev, 1); + + /* Set HW strip */ + mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK | + RTE_ETH_VLAN_EXTEND_MASK; + err = ngbevf_vlan_offload_config(dev, mask); + if (err) { + PMD_INIT_LOG(ERR, "Unable to set VLAN offload (%d)", err); + ngbe_dev_clear_queues(dev); + return err; + } + + ngbevf_dev_rxtx_start(dev); + + /* check and configure queue intr-vector mapping */ + if (rte_intr_cap_multiple(intr_handle) && + dev->data->dev_conf.intr_conf.rxq) { + /* According to datasheet, only vector 0/1/2 can be used, + * now only one vector is used for Rx queue + */ + intr_vector = 1; + if (rte_intr_efd_enable(intr_handle, intr_vector)) + return -1; + } + + if (rte_intr_dp_is_en(intr_handle)) { + if (rte_intr_vec_list_alloc(intr_handle, "intr_vec", + dev->data->nb_rx_queues)) { + PMD_INIT_LOG(ERR, + "Failed to allocate %d rx_queues intr_vec", + dev->data->nb_rx_queues); + return -ENOMEM; + } + } + + ngbevf_configure_msix(dev); + + /* When a VF port is bound to VFIO-PCI, only miscellaneous interrupt + * is mapped to VFIO vector 0 in eth_ngbevf_dev_init( ). + * If previous VFIO interrupt mapping setting in eth_ngbevf_dev_init( ) + * is not cleared, it will fail when following rte_intr_enable( ) tries + * to map Rx queue interrupt to other VFIO vectors. + * So clear uio/vfio intr/evevnfd first to avoid failure. + */ + rte_intr_disable(intr_handle); + + rte_intr_enable(intr_handle); + + /* Re-enable interrupt for VF */ + ngbevf_intr_enable(dev); + + /* + * Update link status right before return, because it may + * start link configuration process in a separate thread. + */ + ngbevf_dev_link_update(dev, 0); + + hw->adapter_stopped = false; + + return 0; +} + +static int +ngbevf_dev_stop(struct rte_eth_dev *dev) +{ + struct ngbe_hw *hw = ngbe_dev_hw(dev); + struct ngbe_adapter *adapter = ngbe_dev_adapter(dev); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; + + if (hw->adapter_stopped) + return 0; + + PMD_INIT_FUNC_TRACE(); + + ngbevf_intr_disable(dev); + + hw->adapter_stopped = 1; + hw->mac.stop_hw(hw); + + /* + * Clear what we set, but we still keep shadow_vfta to + * restore after device starts + */ + ngbevf_set_vfta_all(dev, 0); + + /* Clear stored conf */ + dev->data->scattered_rx = 0; + + ngbe_dev_clear_queues(dev); + + /* Clean datapath event and queue/vec mapping */ + rte_intr_efd_disable(intr_handle); + rte_intr_vec_list_free(intr_handle); + + adapter->rss_reta_updated = 0; + + return 0; +} + static int ngbevf_dev_close(struct rte_eth_dev *dev) { struct ngbe_hw *hw = ngbe_dev_hw(dev); struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); struct rte_intr_handle *intr_handle = pci_dev->intr_handle; + int ret; PMD_INIT_FUNC_TRACE(); if (rte_eal_process_type() != RTE_PROC_PRIMARY) @@ -568,6 +707,10 @@ ngbevf_dev_close(struct rte_eth_dev *dev) hw->mac.reset_hw(hw); + ret = ngbevf_dev_stop(dev); + + ngbe_dev_free_queues(dev); + /** * Remove the VF MAC address ro ensure * that the VF traffic goes to the PF @@ -588,7 +731,24 @@ ngbevf_dev_close(struct rte_eth_dev *dev) rte_intr_callback_unregister(intr_handle, ngbevf_dev_interrupt_handler, dev); - return 0; + return ret; +} + +/* + * Reset VF device + */ +static int +ngbevf_dev_reset(struct rte_eth_dev *dev) +{ + int ret; + + ret = eth_ngbevf_dev_uninit(dev); + if (ret) + return ret; + + ret = eth_ngbevf_dev_init(dev); + + return ret; } static void ngbevf_set_vfta_all(struct rte_eth_dev *dev, bool on) @@ -1078,12 +1238,16 @@ ngbevf_dev_interrupt_handler(void *param) */ static const struct eth_dev_ops ngbevf_eth_dev_ops = { .dev_configure = ngbevf_dev_configure, + .dev_start = ngbevf_dev_start, + .dev_stop = ngbevf_dev_stop, .link_update = ngbevf_dev_link_update, .stats_get = ngbevf_dev_stats_get, .xstats_get = ngbevf_dev_xstats_get, .stats_reset = ngbevf_dev_stats_reset, .xstats_reset = ngbevf_dev_stats_reset, .xstats_get_names = ngbevf_dev_xstats_get_names, + .dev_close = ngbevf_dev_close, + .dev_reset = ngbevf_dev_reset, .promiscuous_enable = ngbevf_dev_promiscuous_enable, .promiscuous_disable = ngbevf_dev_promiscuous_disable, .allmulticast_enable = ngbevf_dev_allmulticast_enable, @@ -1093,6 +1257,10 @@ static const struct eth_dev_ops ngbevf_eth_dev_ops = { .vlan_filter_set = ngbevf_vlan_filter_set, .vlan_strip_queue_set = ngbevf_vlan_strip_queue_set, .vlan_offload_set = ngbevf_vlan_offload_set, + .rx_queue_setup = ngbe_dev_rx_queue_setup, + .rx_queue_release = ngbe_dev_rx_queue_release, + .tx_queue_setup = ngbe_dev_tx_queue_setup, + .tx_queue_release = ngbe_dev_tx_queue_release, .rx_queue_intr_enable = ngbevf_dev_rx_queue_intr_enable, .rx_queue_intr_disable = ngbevf_dev_rx_queue_intr_disable, .mac_addr_add = ngbevf_add_mac_addr, -- 2.21.0.windows.1