pci: move NUMA node check from scan to probe
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_pci.c
index 1bd3496..2041d5f 100644 (file)
@@ -88,7 +88,7 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
 
 /* Map pci device */
 int
-rte_eal_pci_map_device(struct rte_pci_device *dev)
+rte_pci_map_device(struct rte_pci_device *dev)
 {
        int ret = -1;
 
@@ -119,7 +119,7 @@ rte_eal_pci_map_device(struct rte_pci_device *dev)
 
 /* Unmap pci device */
 void
-rte_eal_pci_unmap_device(struct rte_pci_device *dev)
+rte_pci_unmap_device(struct rte_pci_device *dev)
 {
        /* try unmapping the NIC resources using VFIO if it exists */
        switch (dev->kdrv) {
@@ -310,19 +310,16 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
                        dev->max_vfs = (uint16_t)tmp;
        }
 
-       /* get numa node */
+       /* get numa node, default to 0 if not present */
        snprintf(filename, sizeof(filename), "%s/numa_node",
                 dirname);
-       if (access(filename, R_OK) != 0) {
-               /* if no NUMA support, set default to 0 */
-               dev->device.numa_node = 0;
-       } else {
-               if (eal_parse_sysfs_value(filename, &tmp) < 0) {
-                       free(dev);
-                       return -1;
-               }
+
+       if (eal_parse_sysfs_value(filename, &tmp) == 0)
                dev->device.numa_node = tmp;
-       }
+       else
+               dev->device.numa_node = -1;
+
+       pci_name_set(dev);
 
        /* parse resources */
        snprintf(filename, sizeof(filename), "%s/resource", dirname);
@@ -354,32 +351,31 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
                dev->kdrv = RTE_KDRV_NONE;
 
        /* device is valid, add in list (sorted) */
-       if (TAILQ_EMPTY(&pci_device_list)) {
-               rte_eal_device_insert(&dev->device);
-               TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+       if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
+               rte_pci_add_device(dev);
        } else {
                struct rte_pci_device *dev2;
                int ret;
 
-               TAILQ_FOREACH(dev2, &pci_device_list, next) {
+               TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
                        ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
                        if (ret > 0)
                                continue;
 
                        if (ret < 0) {
-                               TAILQ_INSERT_BEFORE(dev2, dev, next);
-                               rte_eal_device_insert(&dev->device);
+                               rte_pci_insert_device(dev2, dev);
                        } else { /* already registered */
                                dev2->kdrv = dev->kdrv;
                                dev2->max_vfs = dev->max_vfs;
+                               pci_name_set(dev2);
                                memmove(dev2->mem_resource, dev->mem_resource,
                                        sizeof(dev->mem_resource));
                                free(dev);
                        }
                        return 0;
                }
-               rte_eal_device_insert(&dev->device);
-               TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+
+               rte_pci_add_device(dev);
        }
 
        return 0;
@@ -429,10 +425,10 @@ parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr *addr)
 
        /* now convert to int values */
        errno = 0;
-       addr->domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
-       addr->bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
-       addr->devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
-       addr->function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
+       addr->domain = strtoul(splitaddr.domain, NULL, 16);
+       addr->bus = strtoul(splitaddr.bus, NULL, 16);
+       addr->devid = strtoul(splitaddr.devid, NULL, 16);
+       addr->function = strtoul(splitaddr.function, NULL, 10);
        if (errno != 0)
                goto error;
 
@@ -448,13 +444,17 @@ error:
  * list
  */
 int
-rte_eal_pci_scan(void)
+rte_pci_scan(void)
 {
        struct dirent *e;
        DIR *dir;
        char dirname[PATH_MAX];
        struct rte_pci_addr addr;
 
+       /* for debug purposes, PCI can be disabled */
+       if (internal_config.no_pci)
+               return 0;
+
        dir = opendir(pci_get_sysfs_path());
        if (dir == NULL) {
                RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
@@ -471,6 +471,7 @@ rte_eal_pci_scan(void)
 
                snprintf(dirname, sizeof(dirname), "%s/%s",
                                pci_get_sysfs_path(), e->d_name);
+
                if (pci_scan_one(dirname, &addr) < 0)
                        goto error;
        }
@@ -483,8 +484,8 @@ error:
 }
 
 /* Read PCI config space. */
-int rte_eal_pci_read_config(const struct rte_pci_device *device,
-                           void *buf, size_t len, off_t offset)
+int rte_pci_read_config(const struct rte_pci_device *device,
+               void *buf, size_t len, off_t offset)
 {
        const struct rte_intr_handle *intr_handle = &device->intr_handle;
 
@@ -508,8 +509,8 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device,
 }
 
 /* Write PCI config space. */
-int rte_eal_pci_write_config(const struct rte_pci_device *device,
-                            const void *buf, size_t len, off_t offset)
+int rte_pci_write_config(const struct rte_pci_device *device,
+               const void *buf, size_t len, off_t offset)
 {
        const struct rte_intr_handle *intr_handle = &device->intr_handle;
 
@@ -535,7 +536,7 @@ int rte_eal_pci_write_config(const struct rte_pci_device *device,
 #if defined(RTE_ARCH_X86)
 static int
 pci_ioport_map(struct rte_pci_device *dev, int bar __rte_unused,
-              struct rte_pci_ioport *p)
+               struct rte_pci_ioport *p)
 {
        uint16_t start, end;
        FILE *fp;
@@ -593,8 +594,8 @@ pci_ioport_map(struct rte_pci_device *dev, int bar __rte_unused,
 #endif
 
 int
-rte_eal_pci_ioport_map(struct rte_pci_device *dev, int bar,
-                      struct rte_pci_ioport *p)
+rte_pci_ioport_map(struct rte_pci_device *dev, int bar,
+               struct rte_pci_ioport *p)
 {
        int ret = -1;
 
@@ -631,8 +632,8 @@ rte_eal_pci_ioport_map(struct rte_pci_device *dev, int bar,
 }
 
 void
-rte_eal_pci_ioport_read(struct rte_pci_ioport *p,
-                       void *data, size_t len, off_t offset)
+rte_pci_ioport_read(struct rte_pci_ioport *p,
+               void *data, size_t len, off_t offset)
 {
        switch (p->dev->kdrv) {
 #ifdef VFIO_PRESENT
@@ -657,8 +658,8 @@ rte_eal_pci_ioport_read(struct rte_pci_ioport *p,
 }
 
 void
-rte_eal_pci_ioport_write(struct rte_pci_ioport *p,
-                        const void *data, size_t len, off_t offset)
+rte_pci_ioport_write(struct rte_pci_ioport *p,
+               const void *data, size_t len, off_t offset)
 {
        switch (p->dev->kdrv) {
 #ifdef VFIO_PRESENT
@@ -683,7 +684,7 @@ rte_eal_pci_ioport_write(struct rte_pci_ioport *p,
 }
 
 int
-rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
+rte_pci_ioport_unmap(struct rte_pci_ioport *p)
 {
        int ret = -1;
 
@@ -715,19 +716,3 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 
        return ret;
 }
-
-/* Init the PCI EAL subsystem */
-int
-rte_eal_pci_init(void)
-{
-       /* for debug purposes, PCI can be disabled */
-       if (internal_config.no_pci)
-               return 0;
-
-       if (rte_eal_pci_scan() < 0) {
-               RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
-               return -1;
-       }
-
-       return 0;
-}