ethdev: do not scan all PCI devices on attach
[dpdk.git] / lib / librte_ether / rte_ethdev.c
index f62a9ec..11329cf 100644 (file)
@@ -58,7 +58,6 @@
 #include <rte_atomic.h>
 #include <rte_branch_prediction.h>
 #include <rte_common.h>
-#include <rte_ring.h>
 #include <rte_mempool.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
@@ -220,20 +219,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
        return eth_dev;
 }
 
-static int
-rte_eth_dev_create_unique_device_name(char *name, size_t size,
-               struct rte_pci_device *pci_dev)
-{
-       int ret;
-
-       ret = snprintf(name, size, "%d:%d.%d",
-                       pci_dev->addr.bus, pci_dev->addr.devid,
-                       pci_dev->addr.function);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
 int
 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 {
@@ -245,9 +230,9 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
        return 0;
 }
 
-static int
-rte_eth_dev_init(struct rte_pci_driver *pci_drv,
-                struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
+                     struct rte_pci_device *pci_dev)
 {
        struct eth_driver    *eth_drv;
        struct rte_eth_dev *eth_dev;
@@ -257,9 +242,8 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 
        eth_drv = (struct eth_driver *)pci_drv;
 
-       /* Create unique Ethernet device name using PCI address */
-       rte_eth_dev_create_unique_device_name(ethdev_name,
-                       sizeof(ethdev_name), pci_dev);
+       rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+                       sizeof(ethdev_name));
 
        eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
        if (eth_dev == NULL)
@@ -299,8 +283,8 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
        return diag;
 }
 
-static int
-rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
+int
+rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 {
        const struct eth_driver *eth_drv;
        struct rte_eth_dev *eth_dev;
@@ -310,9 +294,8 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
        if (pci_dev == NULL)
                return -EINVAL;
 
-       /* Create unique Ethernet device name using PCI address */
-       rte_eth_dev_create_unique_device_name(ethdev_name,
-                       sizeof(ethdev_name), pci_dev);
+       rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+                       sizeof(ethdev_name));
 
        eth_dev = rte_eth_dev_allocated(ethdev_name);
        if (eth_dev == NULL)
@@ -340,28 +323,6 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
        return 0;
 }
 
-/**
- * Register an Ethernet [Poll Mode] driver.
- *
- * Function invoked by the initialization function of an Ethernet driver
- * to simultaneously register itself as a PCI driver and as an Ethernet
- * Poll Mode Driver.
- * Invokes the rte_eal_pci_register() function to register the *pci_drv*
- * structure embedded in the *eth_drv* structure, after having stored the
- * address of the rte_eth_dev_init() function in the *devinit* field of
- * the *pci_drv* structure.
- * During the PCI probing phase, the rte_eth_dev_init() function is
- * invoked for each PCI [Ethernet device] matching the embedded PCI
- * identifiers provided by the driver.
- */
-void
-rte_eth_driver_register(struct eth_driver *eth_drv)
-{
-       eth_drv->pci_drv.devinit = rte_eth_dev_init;
-       eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
-       rte_eal_pci_register(&eth_drv->pci_drv);
-}
-
 int
 rte_eth_dev_is_valid_port(uint8_t port_id)
 {
@@ -507,9 +468,6 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 static int
 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
 {
-       /* re-construct pci_device_list */
-       if (rte_eal_pci_scan())
-               goto err;
        /* Invoke probe func of the driver can handle the new device. */
        if (rte_eal_pci_probe_one(addr))
                goto err;
@@ -538,7 +496,7 @@ rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
        if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
                goto err;
 
-       /* invoke devuninit func of the pci driver,
+       /* invoke remove func of the pci driver,
         * also remove the device from pci_device_list */
        if (rte_eal_pci_detach(&freed_addr))
                goto err;