Adds the start/stop/close routine of the flower PF vNIC.
And we reuse the configure/link_update routine.

Signed-off-by: Chaoyong He <chaoyong...@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderl...@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower.c | 185 ++++++++++++++++++++++++++++++++++++
 1 file changed, 185 insertions(+)

diff --git a/drivers/net/nfp/flower/nfp_flower.c 
b/drivers/net/nfp/flower/nfp_flower.c
index ad0dff1..e0c0ab3 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -6,6 +6,7 @@
 #include <rte_common.h>
 #include <rte_service_component.h>
 #include <rte_malloc.h>
+#include <rte_alarm.h>
 #include <ethdev_pci.h>
 #include <ethdev_driver.h>
 
@@ -40,8 +41,168 @@
        .tx_free_thresh = DEFAULT_TX_FREE_THRESH,
 };
 
+static int
+nfp_flower_pf_start(struct rte_eth_dev *dev)
+{
+       int ret;
+       uint32_t new_ctrl;
+       uint32_t update = 0;
+       struct nfp_net_hw *hw;
+
+       hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+       /* Disabling queues just in case... */
+       nfp_net_disable_queues(dev);
+
+       /* Enabling the required queues in the device */
+       nfp_net_enable_queues(dev);
+
+       new_ctrl = nfp_check_offloads(dev);
+
+       /* Writing configuration parameters in the device */
+       nfp_net_params_setup(hw);
+
+       nfp_net_rss_config_default(dev);
+       update |= NFP_NET_CFG_UPDATE_RSS;
+
+       if (hw->cap & NFP_NET_CFG_CTRL_RSS2)
+               new_ctrl |= NFP_NET_CFG_CTRL_RSS2;
+       else
+               new_ctrl |= NFP_NET_CFG_CTRL_RSS;
+
+       /* Enable device */
+       new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
+
+       update |= NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING;
+
+       if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
+               new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG;
+
+       nn_cfg_writel(hw, NFP_NET_CFG_CTRL, new_ctrl);
+
+       /* If an error when reconfig we avoid to change hw state */
+       ret = nfp_net_reconfig(hw, new_ctrl, update);
+       if (ret != 0) {
+               PMD_INIT_LOG(ERR, "Failed to reconfig PF vnic");
+               return -EIO;
+       }
+
+       hw->ctrl = new_ctrl;
+
+       /* Setup the freelist ring */
+       ret = nfp_net_rx_freelist_setup(dev);
+       if (ret != 0) {
+               PMD_INIT_LOG(ERR, "Error with flower PF vNIC freelist setup");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+/* Stop device: disable rx and tx functions to allow for reconfiguring. */
+static int
+nfp_flower_pf_stop(struct rte_eth_dev *dev)
+{
+       uint16_t i;
+       struct nfp_net_hw *hw;
+       struct nfp_net_txq *this_tx_q;
+       struct nfp_net_rxq *this_rx_q;
+
+       hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+       nfp_net_disable_queues(dev);
+
+       /* Clear queues */
+       for (i = 0; i < dev->data->nb_tx_queues; i++) {
+               this_tx_q = (struct nfp_net_txq *)dev->data->tx_queues[i];
+               nfp_net_reset_tx_queue(this_tx_q);
+       }
+
+       for (i = 0; i < dev->data->nb_rx_queues; i++) {
+               this_rx_q = (struct nfp_net_rxq *)dev->data->rx_queues[i];
+               nfp_net_reset_rx_queue(this_rx_q);
+       }
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+               /* Configure the physical port down */
+               nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
+       else
+               nfp_eth_set_configured(dev->process_private, hw->nfp_idx, 0);
+
+       return 0;
+}
+
+/* Reset and stop device. The device can not be restarted. */
+static int
+nfp_flower_pf_close(struct rte_eth_dev *dev)
+{
+       uint16_t i;
+       struct nfp_net_hw *hw;
+       struct nfp_pf_dev *pf_dev;
+       struct nfp_net_txq *this_tx_q;
+       struct nfp_net_rxq *this_rx_q;
+       struct rte_pci_device *pci_dev;
+       struct nfp_app_fw_flower *app_fw_flower;
+
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
+
+       pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+       hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+       app_fw_flower = NFP_PRIV_TO_APP_FW_FLOWER(pf_dev->app_fw_priv);
+
+       /*
+        * We assume that the DPDK application is stopping all the
+        * threads/queues before calling the device close function.
+        */
+       nfp_net_disable_queues(dev);
+
+       /* Clear queues */
+       for (i = 0; i < dev->data->nb_tx_queues; i++) {
+               this_tx_q = (struct nfp_net_txq *)dev->data->tx_queues[i];
+               nfp_net_reset_tx_queue(this_tx_q);
+       }
+
+       for (i = 0; i < dev->data->nb_rx_queues; i++) {
+               this_rx_q = (struct nfp_net_rxq *)dev->data->rx_queues[i];
+               nfp_net_reset_rx_queue(this_rx_q);
+       }
+
+       /* Cancel possible impending LSC work here before releasing the port*/
+       rte_eal_alarm_cancel(nfp_net_dev_interrupt_delayed_handler, (void 
*)dev);
+
+       nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
+
+       rte_eth_dev_release_port(dev);
+
+       /* Now it is safe to free all PF resources */
+       PMD_DRV_LOG(INFO, "Freeing PF resources");
+       nfp_cpp_area_free(pf_dev->ctrl_area);
+       nfp_cpp_area_free(pf_dev->hwqueues_area);
+       free(pf_dev->hwinfo);
+       free(pf_dev->sym_tbl);
+       nfp_cpp_free(pf_dev->cpp);
+       rte_free(app_fw_flower);
+       rte_free(pf_dev);
+
+       rte_intr_disable(pci_dev->intr_handle);
+
+       /* unregister callback func from eal lib */
+       rte_intr_callback_unregister(pci_dev->intr_handle,
+                       nfp_net_dev_interrupt_handler, (void *)dev);
+
+       return 0;
+}
+
 static const struct eth_dev_ops nfp_flower_pf_vnic_ops = {
        .dev_infos_get          = nfp_net_infos_get,
+       .link_update            = nfp_net_link_update,
+       .dev_configure          = nfp_net_configure,
+
+       .dev_start              = nfp_flower_pf_start,
+       .dev_stop               = nfp_flower_pf_stop,
+       .dev_close              = nfp_flower_pf_close,
 };
 
 static void
@@ -310,6 +471,24 @@
 }
 
 static int
+nfp_flower_start_pf_vnic(struct nfp_net_hw *hw)
+{
+       int ret;
+       uint16_t port_id;
+
+       port_id = hw->eth_dev->data->port_id;
+
+       /* Start the device */
+       ret = rte_eth_dev_start(port_id);
+       if (ret != 0) {
+               PMD_INIT_LOG(ERR, "Could not start PF device %d", port_id);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int
 nfp_flower_pf_vnic_service(void *arg)
 {
        int ret;
@@ -321,6 +500,12 @@
                goto pf_vnic_cleanup;
        }
 
+       ret = nfp_flower_start_pf_vnic(app_fw_flower->pf_hw);
+       if (ret != 0) {
+               PMD_DRV_LOG(ERR, "Could not start flower PF vNIC");
+               goto pf_vnic_cleanup;
+       }
+
        return 0;
 
 pf_vnic_cleanup:
-- 
1.8.3.1

Reply via email to