ethdev: move info filling of PCI into drivers
[dpdk.git] / drivers / net / fm10k / fm10k_ethdev.c
index 0ecc167..a97a483 100644 (file)
 #define MAX_QUERY_SWITCH_STATE_TIMES 10
 /* Wait interval to get switch status */
 #define WAIT_SWITCH_MSG_US    100000
+/* A period of quiescence for switch */
+#define FM10K_SWITCH_QUIESCE_US 10000
 /* Number of chars per uint32 type */
 #define CHARS_PER_UINT32 (sizeof(uint32_t))
 #define BIT_MASK_PER_UINT32 ((1 << CHARS_PER_UINT32) - 1)
 
 /* default 1:1 map from queue ID to interrupt vector ID */
-#define Q2V(dev, queue_id) (dev->pci_dev->intr_handle.intr_vec[queue_id])
+#define Q2V(pci_dev, queue_id) ((pci_dev)->intr_handle.intr_vec[queue_id])
 
 /* First 64 Logical ports for PF/VMDQ, second 64 for Flow director */
 #define MAX_LPORT_NUM    128
@@ -675,7 +677,7 @@ fm10k_dev_tx_init(struct rte_eth_dev *dev)
                /* Enable use of FTAG bit in TX descriptor, PFVTCTL
                 * register is read-only for VF.
                 */
-               if (fm10k_check_ftag(dev->pci_dev->devargs)) {
+               if (fm10k_check_ftag(dev->pci_dev->device.devargs)) {
                        if (hw->mac.type == fm10k_mac_pf) {
                                FM10K_WRITE_REG(hw, FM10K_PFVTCTL(i),
                                                FM10K_PFVTCTL_FTAG_DESC_ENABLE);
@@ -693,8 +695,9 @@ fm10k_dev_tx_init(struct rte_eth_dev *dev)
                                base_addr >> (CHAR_BIT * sizeof(uint32_t)));
                FM10K_WRITE_REG(hw, FM10K_TDLEN(i), size);
 
-               /* assign default SGLORT for each TX queue */
-               FM10K_WRITE_REG(hw, FM10K_TX_SGLORT(i), hw->mac.dglort_map);
+               /* assign default SGLORT for each TX queue by PF */
+               if (hw->mac.type == fm10k_mac_pf)
+                       FM10K_WRITE_REG(hw, FM10K_TX_SGLORT(i), hw->mac.dglort_map);
        }
 
        /* set up vector or scalar TX function as appropriate */
@@ -708,7 +711,8 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 {
        struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct fm10k_macvlan_filter_info *macvlan;
-       struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+       struct rte_pci_device *pdev = dev->pci_dev;
+       struct rte_intr_handle *intr_handle = &pdev->intr_handle;
        int i, ret;
        struct fm10k_rx_queue *rxq;
        uint64_t base_addr;
@@ -722,13 +726,13 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
        i = 0;
        if (rte_intr_dp_is_en(intr_handle)) {
                for (; i < dev->data->nb_rx_queues; i++) {
-                       FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(dev, i));
+                       FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(pdev, i));
                        if (hw->mac.type == fm10k_mac_pf)
-                               FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, i)),
+                               FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
                                        FM10K_ITR_AUTOMASK |
                                        FM10K_ITR_MASK_CLEAR);
                        else
-                               FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, i)),
+                               FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
                                        FM10K_ITR_AUTOMASK |
                                        FM10K_ITR_MASK_CLEAR);
                }
@@ -1168,7 +1172,8 @@ static void
 fm10k_dev_stop(struct rte_eth_dev *dev)
 {
        struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+       struct rte_pci_device *pdev = dev->pci_dev;
+       struct rte_intr_handle *intr_handle = &pdev->intr_handle;
        int i;
 
        PMD_INIT_FUNC_TRACE();
@@ -1187,10 +1192,10 @@ fm10k_dev_stop(struct rte_eth_dev *dev)
                        FM10K_WRITE_REG(hw, FM10K_RXINT(i),
                                3 << FM10K_RXINT_TIMER_SHIFT);
                        if (hw->mac.type == fm10k_mac_pf)
-                               FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, i)),
+                               FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
                                        FM10K_ITR_MASK_SET);
                        else
-                               FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, i)),
+                               FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
                                        FM10K_ITR_MASK_SET);
                }
        }
@@ -1233,6 +1238,9 @@ fm10k_dev_close(struct rte_eth_dev *dev)
                MAX_LPORT_NUM, false);
        fm10k_mbx_unlock(hw);
 
+       /* allow 10ms for device to quiesce */
+       rte_delay_us(FM10K_SWITCH_QUIESCE_US);
+
        /* Stop mailbox service first */
        fm10k_close_mbx_service(hw);
        fm10k_dev_stop(dev);
@@ -1381,16 +1389,18 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
        struct rte_eth_dev_info *dev_info)
 {
        struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct rte_pci_device *pdev = dev->pci_dev;
 
        PMD_INIT_FUNC_TRACE();
 
+       dev_info->pci_dev            = pdev;
        dev_info->min_rx_bufsize     = FM10K_MIN_RX_BUF_SIZE;
        dev_info->max_rx_pktlen      = FM10K_MAX_PKT_SIZE;
        dev_info->max_rx_queues      = hw->mac.max_queues;
        dev_info->max_tx_queues      = hw->mac.max_queues;
        dev_info->max_mac_addrs      = FM10K_MAX_MACADDR_NUM;
        dev_info->max_hash_mac_addrs = 0;
-       dev_info->max_vfs            = dev->pci_dev->max_vfs;
+       dev_info->max_vfs            = pdev->max_vfs;
        dev_info->vmdq_pool_base     = 0;
        dev_info->vmdq_queue_base    = 0;
        dev_info->max_vmdq_pools     = ETH_32_POOLS;
@@ -2327,15 +2337,16 @@ static int
 fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
        struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct rte_pci_device *pdev = dev->pci_dev;
 
        /* Enable ITR */
        if (hw->mac.type == fm10k_mac_pf)
-               FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, queue_id)),
+               FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
                        FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
        else
-               FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, queue_id)),
+               FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
                        FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
-       rte_intr_enable(&dev->pci_dev->intr_handle);
+       rte_intr_enable(&pdev->intr_handle);
        return 0;
 }
 
@@ -2343,13 +2354,14 @@ static int
 fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
        struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct rte_pci_device *pdev = dev->pci_dev;
 
        /* Disable ITR */
        if (hw->mac.type == fm10k_mac_pf)
-               FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, queue_id)),
+               FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
                        FM10K_ITR_MASK_SET);
        else
-               FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, queue_id)),
+               FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
                        FM10K_ITR_MASK_SET);
        return 0;
 }
@@ -2358,7 +2370,8 @@ static int
 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 {
        struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+       struct rte_pci_device *pdev = dev->pci_dev;
+       struct rte_intr_handle *intr_handle = &pdev->intr_handle;
        uint32_t intr_vector, vec;
        uint16_t queue_id;
        int result = 0;
@@ -2374,7 +2387,7 @@ fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
        intr_vector = dev->data->nb_rx_queues;
 
        /* disable interrupt first */
-       rte_intr_disable(&dev->pci_dev->intr_handle);
+       rte_intr_disable(intr_handle);
        if (hw->mac.type == fm10k_mac_pf)
                fm10k_dev_disable_intr_pf(dev);
        else
@@ -2409,7 +2422,7 @@ fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
                fm10k_dev_enable_intr_pf(dev);
        else
                fm10k_dev_enable_intr_vf(dev);
-       rte_intr_enable(&dev->pci_dev->intr_handle);
+       rte_intr_enable(intr_handle);
        hw->mac.ops.update_int_moderator(hw);
        return result;
 }
@@ -2524,7 +2537,7 @@ error:
  */
 static void
 fm10k_dev_interrupt_handler_pf(
-                       __rte_unused struct rte_intr_handle *handle,
+                       struct rte_intr_handle *handle,
                        void *param)
 {
        struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -2575,7 +2588,7 @@ fm10k_dev_interrupt_handler_pf(
        FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
                                        FM10K_ITR_MASK_CLEAR);
        /* Re-enable interrupt from host side */
-       rte_intr_enable(&(dev->pci_dev->intr_handle));
+       rte_intr_enable(handle);
 }
 
 /**
@@ -2591,7 +2604,7 @@ fm10k_dev_interrupt_handler_pf(
  */
 static void
 fm10k_dev_interrupt_handler_vf(
-                       __rte_unused struct rte_intr_handle *handle,
+                       struct rte_intr_handle *handle,
                        void *param)
 {
        struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -2609,7 +2622,7 @@ fm10k_dev_interrupt_handler_vf(
        FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
                                        FM10K_ITR_MASK_CLEAR);
        /* Re-enable interrupt from host side */
-       rte_intr_enable(&(dev->pci_dev->intr_handle));
+       rte_intr_enable(handle);
 }
 
 /* Mailbox message handler in VF */
@@ -2731,7 +2744,7 @@ fm10k_set_tx_function(struct rte_eth_dev *dev)
        int use_sse = 1;
        uint16_t tx_ftag_en = 0;
 
-       if (fm10k_check_ftag(dev->pci_dev->devargs))
+       if (fm10k_check_ftag(dev->pci_dev->device.devargs))
                tx_ftag_en = 1;
 
        for (i = 0; i < dev->data->nb_tx_queues; i++) {
@@ -2762,7 +2775,7 @@ fm10k_set_rx_function(struct rte_eth_dev *dev)
        uint16_t i, rx_using_sse;
        uint16_t rx_ftag_en = 0;
 
-       if (fm10k_check_ftag(dev->pci_dev->devargs))
+       if (fm10k_check_ftag(dev->pci_dev->device.devargs))
                rx_ftag_en = 1;
 
        /* In order to allow Vector Rx there are a few configuration
@@ -2821,6 +2834,8 @@ static int
 eth_fm10k_dev_init(struct rte_eth_dev *dev)
 {
        struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct rte_pci_device *pdev = dev->pci_dev;
+       struct rte_intr_handle *intr_handle = &pdev->intr_handle;
        int diag, i;
        struct fm10k_macvlan_filter_info *macvlan;
 
@@ -2834,18 +2849,18 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
-       rte_eth_copy_pci_info(dev, dev->pci_dev);
+       rte_eth_copy_pci_info(dev, pdev);
 
        macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
        memset(macvlan, 0, sizeof(*macvlan));
        /* Vendor and Device ID need to be set before init of shared code */
        memset(hw, 0, sizeof(*hw));
-       hw->device_id = dev->pci_dev->id.device_id;
-       hw->vendor_id = dev->pci_dev->id.vendor_id;
-       hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
-       hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
+       hw->device_id = pdev->id.device_id;
+       hw->vendor_id = pdev->id.vendor_id;
+       hw->subsystem_device_id = pdev->id.subsystem_device_id;
+       hw->subsystem_vendor_id = pdev->id.subsystem_vendor_id;
        hw->revision_id = 0;
-       hw->hw_addr = (void *)dev->pci_dev->mem_resource[0].addr;
+       hw->hw_addr = (void *)pdev->mem_resource[0].addr;
        if (hw->hw_addr == NULL) {
                PMD_INIT_LOG(ERR, "Bad mem resource."
                        " Try to blacklist unused devices.");
@@ -2915,20 +2930,20 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)
        /*PF/VF has different interrupt handling mechanism */
        if (hw->mac.type == fm10k_mac_pf) {
                /* register callback func to eal lib */
-               rte_intr_callback_register(&(dev->pci_dev->intr_handle),
+               rte_intr_callback_register(intr_handle,
                        fm10k_dev_interrupt_handler_pf, (void *)dev);
 
                /* enable MISC interrupt */
                fm10k_dev_enable_intr_pf(dev);
        } else { /* VF */
-               rte_intr_callback_register(&(dev->pci_dev->intr_handle),
+               rte_intr_callback_register(intr_handle,
                        fm10k_dev_interrupt_handler_vf, (void *)dev);
 
                fm10k_dev_enable_intr_vf(dev);
        }
 
        /* Enable intr after callback registered */
-       rte_intr_enable(&(dev->pci_dev->intr_handle));
+       rte_intr_enable(intr_handle);
 
        hw->mac.ops.update_int_moderator(hw);
 
@@ -2998,7 +3013,8 @@ static int
 eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 {
        struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-
+       struct rte_pci_device *pdev = dev->pci_dev;
+       struct rte_intr_handle *intr_handle = &pdev->intr_handle;
        PMD_INIT_FUNC_TRACE();
 
        /* only uninitialize in the primary process */
@@ -3013,7 +3029,7 @@ eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
        dev->tx_pkt_burst = NULL;
 
        /* disable uio/vfio intr */
-       rte_intr_disable(&(dev->pci_dev->intr_handle));
+       rte_intr_disable(intr_handle);
 
        /*PF/VF has different interrupt handling mechanism */
        if (hw->mac.type == fm10k_mac_pf) {
@@ -3021,13 +3037,13 @@ eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
                fm10k_dev_disable_intr_pf(dev);
 
                /* unregister callback func to eal lib */
-               rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+               rte_intr_callback_unregister(intr_handle,
                        fm10k_dev_interrupt_handler_pf, (void *)dev);
        } else {
                /* disable interrupt */
                fm10k_dev_disable_intr_vf(dev);
 
-               rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+               rte_intr_callback_unregister(intr_handle,
                        fm10k_dev_interrupt_handler_vf, (void *)dev);
        }
 
@@ -3055,34 +3071,17 @@ static const struct rte_pci_id pci_id_fm10k_map[] = {
 
 static struct eth_driver rte_pmd_fm10k = {
        .pci_drv = {
-               .name = "rte_pmd_fm10k",
                .id_table = pci_id_fm10k_map,
                .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
                        RTE_PCI_DRV_DETACHABLE,
+               .probe = rte_eth_dev_pci_probe,
+               .remove = rte_eth_dev_pci_remove,
        },
        .eth_dev_init = eth_fm10k_dev_init,
        .eth_dev_uninit = eth_fm10k_dev_uninit,
        .dev_private_size = sizeof(struct fm10k_adapter),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI FM10K devices.
- */
-static int
-rte_pmd_fm10k_init(__rte_unused const char *name,
-       __rte_unused const char *params)
-{
-       PMD_INIT_FUNC_TRACE();
-       rte_eth_driver_register(&rte_pmd_fm10k);
-       return 0;
-}
-
-static struct rte_driver rte_fm10k_driver = {
-       .type = PMD_PDEV,
-       .init = rte_pmd_fm10k_init,
-};
-
-PMD_REGISTER_DRIVER(rte_fm10k_driver, net_fm10k);
-DRIVER_REGISTER_PCI_TABLE(net_fm10k, pci_id_fm10k_map);
+RTE_PMD_REGISTER_PCI(net_fm10k, rte_pmd_fm10k.pci_drv);
+RTE_PMD_REGISTER_PCI_TABLE(net_fm10k, pci_id_fm10k_map);
+RTE_PMD_REGISTER_KMOD_DEP(net_fm10k, "* igb_uio | uio_pci_generic | vfio");