ethdev: add device flag to bypass auto-filled queue xstats
[dpdk.git] / drivers / net / e1000 / igb_ethdev.c
index f6bfdd6..ac4b8f1 100644 (file)
 
 static int  eth_igb_configure(struct rte_eth_dev *dev);
 static int  eth_igb_start(struct rte_eth_dev *dev);
-static void eth_igb_stop(struct rte_eth_dev *dev);
+static int  eth_igb_stop(struct rte_eth_dev *dev);
 static int  eth_igb_dev_set_link_up(struct rte_eth_dev *dev);
 static int  eth_igb_dev_set_link_down(struct rte_eth_dev *dev);
-static void eth_igb_close(struct rte_eth_dev *dev);
+static int eth_igb_close(struct rte_eth_dev *dev);
 static int eth_igb_reset(struct rte_eth_dev *dev);
 static int  eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
 static int  eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
-static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
-static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
+static int  eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
+static int  eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
 static int  eth_igb_link_update(struct rte_eth_dev *dev,
                                int wait_to_complete);
 static int eth_igb_stats_get(struct rte_eth_dev *dev,
@@ -154,12 +154,12 @@ static int eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
 static void igbvf_intr_disable(struct e1000_hw *hw);
 static int igbvf_dev_configure(struct rte_eth_dev *dev);
 static int igbvf_dev_start(struct rte_eth_dev *dev);
-static void igbvf_dev_stop(struct rte_eth_dev *dev);
-static void igbvf_dev_close(struct rte_eth_dev *dev);
+static int igbvf_dev_stop(struct rte_eth_dev *dev);
+static int igbvf_dev_close(struct rte_eth_dev *dev);
 static int igbvf_promiscuous_enable(struct rte_eth_dev *dev);
 static int igbvf_promiscuous_disable(struct rte_eth_dev *dev);
-static void igbvf_allmulticast_enable(struct rte_eth_dev *dev);
-static void igbvf_allmulticast_disable(struct rte_eth_dev *dev);
+static int igbvf_allmulticast_enable(struct rte_eth_dev *dev);
+static int igbvf_allmulticast_disable(struct rte_eth_dev *dev);
 static int eth_igbvf_link_update(struct e1000_hw *hw);
 static int eth_igbvf_stats_get(struct rte_eth_dev *dev,
                                struct rte_eth_stats *rte_stats);
@@ -380,10 +380,6 @@ static const struct eth_dev_ops eth_igb_ops = {
        .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
        .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
        .rx_queue_release     = eth_igb_rx_queue_release,
-       .rx_queue_count       = eth_igb_rx_queue_count,
-       .rx_descriptor_done   = eth_igb_rx_descriptor_done,
-       .rx_descriptor_status = eth_igb_rx_descriptor_status,
-       .tx_descriptor_status = eth_igb_tx_descriptor_status,
        .tx_queue_setup       = eth_igb_tx_queue_setup,
        .tx_queue_release     = eth_igb_tx_queue_release,
        .tx_done_cleanup      = eth_igb_tx_done_cleanup,
@@ -441,11 +437,9 @@ static const struct eth_dev_ops igbvf_eth_dev_ops = {
        .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
        .rx_queue_setup       = eth_igb_rx_queue_setup,
        .rx_queue_release     = eth_igb_rx_queue_release,
-       .rx_descriptor_done   = eth_igb_rx_descriptor_done,
-       .rx_descriptor_status = eth_igb_rx_descriptor_status,
-       .tx_descriptor_status = eth_igb_tx_descriptor_status,
        .tx_queue_setup       = eth_igb_tx_queue_setup,
        .tx_queue_release     = eth_igb_tx_queue_release,
+       .tx_done_cleanup      = eth_igb_tx_done_cleanup,
        .set_mc_addr_list     = eth_igb_set_mc_addr_list,
        .rxq_info_get         = igb_rxq_info_get,
        .txq_info_get         = igb_txq_info_get,
@@ -753,6 +747,10 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
        uint32_t ctrl_ext;
 
        eth_dev->dev_ops = &eth_igb_ops;
+       eth_dev->rx_queue_count = eth_igb_rx_queue_count;
+       eth_dev->rx_descriptor_done   = eth_igb_rx_descriptor_done;
+       eth_dev->rx_descriptor_status = eth_igb_rx_descriptor_status;
+       eth_dev->tx_descriptor_status = eth_igb_tx_descriptor_status;
        eth_dev->rx_pkt_burst = &eth_igb_recv_pkts;
        eth_dev->tx_pkt_burst = &eth_igb_xmit_pkts;
        eth_dev->tx_pkt_prepare = &eth_igb_prep_pkts;
@@ -767,6 +765,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
        }
 
        rte_eth_copy_pci_info(eth_dev, pci_dev);
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
 
        hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
 
@@ -886,6 +885,8 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
        /* enable support intr */
        igb_intr_enable(eth_dev);
 
+       eth_igb_dev_set_link_down(eth_dev);
+
        /* initialize filter info */
        memset(filter_info, 0,
               sizeof(struct e1000_filter_info));
@@ -912,61 +913,12 @@ err_late:
 static int
 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-       struct rte_pci_device *pci_dev;
-       struct rte_intr_handle *intr_handle;
-       struct e1000_hw *hw;
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(eth_dev->data->dev_private);
-       struct e1000_filter_info *filter_info =
-               E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
-
        PMD_INIT_FUNC_TRACE();
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-               return -EPERM;
-
-       hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-       pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-       intr_handle = &pci_dev->intr_handle;
-
-       if (adapter->stopped == 0)
-               eth_igb_close(eth_dev);
-
-       eth_dev->dev_ops = NULL;
-       eth_dev->rx_pkt_burst = NULL;
-       eth_dev->tx_pkt_burst = NULL;
-
-       /* Reset any pending lock */
-       igb_reset_swfw_lock(hw);
-
-       /* uninitialize PF if max_vfs not zero */
-       igb_pf_host_uninit(eth_dev);
-
-       /* disable uio intr before callback unregister */
-       rte_intr_disable(intr_handle);
-       rte_intr_callback_unregister(intr_handle,
-                                    eth_igb_interrupt_handler, eth_dev);
-
-       /* clear the SYN filter info */
-       filter_info->syn_info = 0;
-
-       /* clear the ethertype filters info */
-       filter_info->ethertype_mask = 0;
-       memset(filter_info->ethertype_filters, 0,
-               E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
-
-       /* clear the rss filter info */
-       memset(&filter_info->rss_info, 0,
-               sizeof(struct igb_rte_flow_rss_conf));
+               return 0;
 
-       /* remove all ntuple filters of the device */
-       igb_ntuple_filter_uninit(eth_dev);
-
-       /* remove all flex filters of the device */
-       igb_flex_filter_uninit(eth_dev);
-
-       /* clear all the filters list */
-       igb_filterlist_flush(eth_dev);
+       eth_igb_close(eth_dev);
 
        return 0;
 }
@@ -990,6 +942,9 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
        PMD_INIT_FUNC_TRACE();
 
        eth_dev->dev_ops = &igbvf_eth_dev_ops;
+       eth_dev->rx_descriptor_done   = eth_igb_rx_descriptor_done;
+       eth_dev->rx_descriptor_status = eth_igb_rx_descriptor_status;
+       eth_dev->tx_descriptor_status = eth_igb_tx_descriptor_status;
        eth_dev->rx_pkt_burst = &eth_igb_recv_pkts;
        eth_dev->tx_pkt_burst = &eth_igb_xmit_pkts;
        eth_dev->tx_pkt_prepare = &eth_igb_prep_pkts;
@@ -1005,6 +960,7 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 
        pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
        rte_eth_copy_pci_info(eth_dev, pci_dev);
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
 
        hw->device_id = pci_dev->id.device_id;
        hw->vendor_id = pci_dev->id.vendor_id;
@@ -1077,27 +1033,12 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(eth_dev->data->dev_private);
-       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-
        PMD_INIT_FUNC_TRACE();
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-               return -EPERM;
-
-       if (adapter->stopped == 0)
-               igbvf_dev_close(eth_dev);
+               return 0;
 
-       eth_dev->dev_ops = NULL;
-       eth_dev->rx_pkt_burst = NULL;
-       eth_dev->tx_pkt_burst = NULL;
-
-       /* disable uio intr before callback unregister */
-       rte_intr_disable(&pci_dev->intr_handle);
-       rte_intr_callback_unregister(&pci_dev->intr_handle,
-                                    eth_igbvf_interrupt_handler,
-                                    (void *)eth_dev);
+       igbvf_dev_close(eth_dev);
 
        return 0;
 }
@@ -1236,6 +1177,9 @@ eth_igb_configure(struct rte_eth_dev *dev)
 
        PMD_INIT_FUNC_TRACE();
 
+       if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
+               dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
+
        /* multipe queue mode checking */
        ret  = igb_check_mq_mode(dev);
        if (ret != 0) {
@@ -1499,13 +1443,18 @@ error_invalid_config:
  *  global reset on the MAC.
  *
  **********************************************************************/
-static void
+static int
 eth_igb_stop(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        struct rte_eth_link link;
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct e1000_adapter *adapter =
+               E1000_DEV_PRIVATE(dev->data->dev_private);
+
+       if (adapter->stopped)
+               return 0;
 
        eth_igb_rxtx_control(dev, false);
 
@@ -1517,8 +1466,9 @@ eth_igb_stop(struct rte_eth_dev *dev)
        igb_pf_reset_hw(hw);
        E1000_WRITE_REG(hw, E1000_WUC, 0);
 
-       /* Set bit for Go Link disconnect */
-       if (hw->mac.type >= e1000_82580) {
+       /* Set bit for Go Link disconnect if PHY reset is not blocked */
+       if (hw->mac.type >= e1000_82580 &&
+           (e1000_check_reset_block(hw) != E1000_BLK_PHY_RESET)) {
                uint32_t phpm_reg;
 
                phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
@@ -1547,6 +1497,11 @@ eth_igb_stop(struct rte_eth_dev *dev)
                rte_free(intr_handle->intr_vec);
                intr_handle->intr_vec = NULL;
        }
+
+       adapter->stopped = true;
+       dev->data->dev_started = 0;
+
+       return 0;
 }
 
 static int
@@ -1575,25 +1530,29 @@ eth_igb_dev_set_link_down(struct rte_eth_dev *dev)
        return 0;
 }
 
-static void
+static int
 eth_igb_close(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(dev->data->dev_private);
        struct rte_eth_link link;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct e1000_filter_info *filter_info =
+               E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+       int ret;
+
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
 
-       eth_igb_stop(dev);
-       adapter->stopped = 1;
+       ret = eth_igb_stop(dev);
 
        e1000_phy_hw_reset(hw);
        igb_release_manageability(hw);
        igb_hw_control_release(hw);
 
-       /* Clear bit for Go Link disconnect */
-       if (hw->mac.type >= e1000_82580) {
+       /* Clear bit for Go Link disconnect if PHY reset is not blocked */
+       if (hw->mac.type >= e1000_82580 &&
+           (e1000_check_reset_block(hw) != E1000_BLK_PHY_RESET)) {
                uint32_t phpm_reg;
 
                phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
@@ -1610,6 +1569,38 @@ eth_igb_close(struct rte_eth_dev *dev)
 
        memset(&link, 0, sizeof(link));
        rte_eth_linkstatus_set(dev, &link);
+
+       /* Reset any pending lock */
+       igb_reset_swfw_lock(hw);
+
+       /* uninitialize PF if max_vfs not zero */
+       igb_pf_host_uninit(dev);
+
+       rte_intr_callback_unregister(intr_handle,
+                                    eth_igb_interrupt_handler, dev);
+
+       /* clear the SYN filter info */
+       filter_info->syn_info = 0;
+
+       /* clear the ethertype filters info */
+       filter_info->ethertype_mask = 0;
+       memset(filter_info->ethertype_filters, 0,
+               E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
+
+       /* clear the rss filter info */
+       memset(&filter_info->rss_info, 0,
+               sizeof(struct igb_rte_flow_rss_conf));
+
+       /* remove all ntuple filters of the device */
+       igb_ntuple_filter_uninit(dev);
+
+       /* remove all flex filters of the device */
+       igb_flex_filter_uninit(dev);
+
+       /* clear all the filters list */
+       igb_filterlist_flush(dev);
+
+       return ret;
 }
 
 /*
@@ -2557,7 +2548,7 @@ eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
        return 0;
 }
 
-static void
+static int
 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw =
@@ -2567,9 +2558,11 @@ eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
        rctl = E1000_READ_REG(hw, E1000_RCTL);
        rctl |= E1000_RCTL_MPE;
        E1000_WRITE_REG(hw, E1000_RCTL, rctl);
+
+       return 0;
 }
 
-static void
+static int
 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw =
@@ -2577,10 +2570,12 @@ eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
        uint32_t rctl;
 
        if (dev->data->promiscuous == 1)
-               return; /* must remain in all_multicast mode */
+               return 0; /* must remain in all_multicast mode */
        rctl = E1000_READ_REG(hw, E1000_RCTL);
        rctl &= (~E1000_RCTL_MPE);
        E1000_WRITE_REG(hw, E1000_RCTL, rctl);
+
+       return 0;
 }
 
 static int
@@ -2917,13 +2912,12 @@ eth_igb_interrupt_action(struct rte_eth_dev *dev,
                                     dev->data->port_id);
                }
 
-               PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
+               PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
                             pci_dev->addr.domain,
                             pci_dev->addr.bus,
                             pci_dev->addr.devid,
                             pci_dev->addr.function);
-               _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
-                                             NULL);
+               rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
        }
 
        return 0;
@@ -2985,8 +2979,8 @@ void igbvf_mbx_process(struct rte_eth_dev *dev)
                /* dummy mbx read to ack pf */
                if (mbx->ops.read(hw, &in_msg, 1, 0))
                        return;
-               _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
-                                             NULL);
+               rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
+                                            NULL);
        }
 }
 
@@ -3265,6 +3259,9 @@ igbvf_dev_configure(struct rte_eth_dev *dev)
        PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
                     dev->data->port_id);
 
+       if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
+               dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
+
        /*
         * VF has no ability to enable/disable HW CRC
         * Keep the persistent behavior the same as Host PF
@@ -3345,11 +3342,16 @@ igbvf_dev_start(struct rte_eth_dev *dev)
        return 0;
 }
 
-static void
+static int
 igbvf_dev_stop(struct rte_eth_dev *dev)
 {
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct e1000_adapter *adapter =
+               E1000_DEV_PRIVATE(dev->data->dev_private);
+
+       if (adapter->stopped)
+               return 0;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -3372,22 +3374,32 @@ igbvf_dev_stop(struct rte_eth_dev *dev)
                rte_free(intr_handle->intr_vec);
                intr_handle->intr_vec = NULL;
        }
+
+       adapter->stopped = true;
+       dev->data->dev_started = 0;
+
+       return 0;
 }
 
-static void
+static int
 igbvf_dev_close(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(dev->data->dev_private);
        struct rte_ether_addr addr;
+       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+       int ret;
 
        PMD_INIT_FUNC_TRACE();
 
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
+
        e1000_reset_hw(hw);
 
-       igbvf_dev_stop(dev);
-       adapter->stopped = 1;
+       ret = igbvf_dev_stop(dev);
+       if (ret != 0)
+               return ret;
+
        igb_dev_free_queues(dev);
 
        /**
@@ -3398,6 +3410,12 @@ igbvf_dev_close(struct rte_eth_dev *dev)
 
        memset(&addr, 0, sizeof(addr));
        igbvf_default_mac_addr_set(dev, &addr);
+
+       rte_intr_callback_unregister(&pci_dev->intr_handle,
+                                    eth_igbvf_interrupt_handler,
+                                    (void *)dev);
+
+       return 0;
 }
 
 static int
@@ -3425,7 +3443,7 @@ igbvf_promiscuous_disable(struct rte_eth_dev *dev)
        return 0;
 }
 
-static void
+static int
 igbvf_allmulticast_enable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -3433,9 +3451,11 @@ igbvf_allmulticast_enable(struct rte_eth_dev *dev)
        /* In promiscuous mode multicast promisc already set */
        if (dev->data->promiscuous == 0)
                e1000_promisc_set_vf(hw, e1000_promisc_multicast);
+
+       return 0;
 }
 
-static void
+static int
 igbvf_allmulticast_disable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -3443,6 +3463,8 @@ igbvf_allmulticast_disable(struct rte_eth_dev *dev)
        /* In promiscuous mode leave multicast promisc enabled */
        if (dev->data->promiscuous == 0)
                e1000_promisc_set_vf(hw, e1000_promisc_disabled);
+
+       return 0;
 }
 
 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)