4 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/types.h>
48 #include <sys/queue.h>
50 #include <sys/ioctl.h>
52 #include <rte_interrupts.h>
55 #include <rte_common.h>
56 #include <rte_launch.h>
57 #include <rte_memory.h>
58 #include <rte_memzone.h>
59 #include <rte_tailq.h>
61 #include <rte_eal_memconfig.h>
62 #include <rte_per_lcore.h>
63 #include <rte_lcore.h>
64 #include <rte_malloc.h>
65 #include <rte_string_fns.h>
66 #include <rte_debug.h>
68 #include "eal_filesystem.h"
69 #include "eal_private.h"
73 * PCI probing under linux
75 * This code is used to simulate a PCI probe by parsing information in
76 * sysfs. Moreover, when a registered driver matches a device, the
77 * kernel driver currently using it is unloaded and replaced by
78 * igb_uio module, which is a very minimal userland driver for Intel
79 * network card, only providing access to PCI BAR to applications, and
80 * enabling bus master.
91 * For multi-process we need to reproduce all PCI mappings in secondary
92 * processes, so save them in a tailq.
95 TAILQ_ENTRY(uio_resource) next;
97 struct rte_pci_addr pci_addr;
100 struct uio_map maps[PCI_MAX_RESOURCE];
103 TAILQ_HEAD(uio_res_list, uio_resource);
105 static struct uio_res_list *uio_res_list = NULL;
106 static int pci_parse_sysfs_value(const char *filename, uint64_t *val);
108 /* forward prototype of function called in pci_switch_module below */
109 static int pci_uio_map_resource(struct rte_pci_device *dev);
111 #ifdef RTE_EAL_UNBIND_PORTS
112 #define PROC_MODULES "/proc/modules"
114 #define IGB_UIO_NAME "igb_uio"
116 #define UIO_DRV_PATH "/sys/bus/pci/drivers/%s"
118 /* maximum time to wait that /dev/uioX appears */
119 #define UIO_DEV_WAIT_TIMEOUT 3 /* seconds */
122 * Check that a kernel module is loaded. Returns 0 on success, or if the
123 * parameter is NULL, or -1 if the module is not loaded.
126 pci_uio_check_module(const char *module_name)
132 if (module_name == NULL)
135 f = fopen(PROC_MODULES, "r");
137 RTE_LOG(ERR, EAL, "Cannot open "PROC_MODULES": %s\n",
142 while(fgets(buf, sizeof(buf), f) != NULL) {
144 for (i = 0; i < sizeof(buf) && buf[i] != '\0'; i++) {
149 if (strncmp(buf, module_name, sizeof(buf)) == 0) {
158 /* bind a PCI to the kernel module driver */
160 pci_bind_device(struct rte_pci_device *dev, char dr_path[])
165 char dev_bind[PATH_MAX];
166 struct rte_pci_addr *loc = &dev->addr;
168 n = rte_snprintf(dev_bind, sizeof(dev_bind), "%s/bind", dr_path);
169 if ((n < 0) || (n >= (int)sizeof(buf))) {
170 RTE_LOG(ERR, EAL, "Cannot rte_snprintf device bind path\n");
174 f = fopen(dev_bind, "w");
176 RTE_LOG(ERR, EAL, "Cannot open %s\n", dev_bind);
179 n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
180 loc->domain, loc->bus, loc->devid, loc->function);
181 if ((n < 0) || (n >= (int)sizeof(buf))) {
182 RTE_LOG(ERR, EAL, "Cannot rte_snprintf PCI infos\n");
186 if (fwrite(buf, n, 1, f) == 0) {
196 pci_uio_bind_device(struct rte_pci_device *dev, const char *module_name)
201 char uio_newid[PATH_MAX];
202 char uio_bind[PATH_MAX];
204 n = rte_snprintf(uio_newid, sizeof(uio_newid), UIO_DRV_PATH "/new_id", module_name);
205 if ((n < 0) || (n >= (int)sizeof(uio_newid))) {
206 RTE_LOG(ERR, EAL, "Cannot rte_snprintf uio_newid name\n");
210 n = rte_snprintf(uio_bind, sizeof(uio_bind), UIO_DRV_PATH, module_name);
211 if ((n < 0) || (n >= (int)sizeof(uio_bind))) {
212 RTE_LOG(ERR, EAL, "Cannot rte_snprintf uio_bind name\n");
216 n = rte_snprintf(buf, sizeof(buf), "%x %x\n",
217 dev->id.vendor_id, dev->id.device_id);
218 if ((n < 0) || (n >= (int)sizeof(buf))) {
219 RTE_LOG(ERR, EAL, "Cannot rte_snprintf vendor_id/device_id\n");
223 f = fopen(uio_newid, "w");
225 RTE_LOG(ERR, EAL, "Cannot open %s\n", uio_newid);
228 if (fwrite(buf, n, 1, f) == 0) {
234 pci_bind_device(dev, uio_bind);
238 /* unbind kernel driver for this device */
240 pci_unbind_kernel_driver(struct rte_pci_device *dev)
244 char filename[PATH_MAX];
246 struct rte_pci_addr *loc = &dev->addr;
248 /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
249 rte_snprintf(filename, sizeof(filename),
250 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind",
251 loc->domain, loc->bus, loc->devid, loc->function);
253 f = fopen(filename, "w");
254 if (f == NULL) /* device was not bound */
257 n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
258 loc->domain, loc->bus, loc->devid, loc->function);
259 if ((n < 0) || (n >= (int)sizeof(buf))) {
260 RTE_LOG(ERR, EAL, "%s(): rte_snprintf failed\n", __func__);
263 if (fwrite(buf, n, 1, f) == 0) {
264 RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
279 pci_switch_module(struct rte_pci_driver *dr, struct rte_pci_device *dev,
280 int uio_status, const char *module_name)
282 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
283 /* check that our driver is loaded */
284 if (uio_status != 0 &&
285 (uio_status = pci_uio_check_module(module_name)) != 0)
286 rte_exit(EXIT_FAILURE, "The %s module is required by the "
287 "%s driver\n", module_name, dr->name);
289 /* unbind current driver, bind ours */
290 if (pci_unbind_kernel_driver(dev) < 0)
292 if (pci_uio_bind_device(dev, module_name) < 0)
295 /* map the NIC resources */
296 if (pci_uio_map_resource(dev) < 0)
302 #endif /* ifdef EAL_UNBIND_PORTS */
304 /* map a particular resource from a file */
306 pci_map_resource(struct rte_pci_device *dev, void *requested_addr,
307 const char *devname, off_t offset, size_t size)
312 #ifdef RTE_EAL_UNBIND_PORTS
314 * open devname, and mmap it: it can take some time to
315 * appear, so we wait some time before returning an error
318 fd = dev->intr_handle.fd;
319 for (n = 0; n < UIO_DEV_WAIT_TIMEOUT*10 && fd < 0; n++) {
321 if ((fd = open(devname, O_RDWR)) < 0 && errno != ENOENT)
327 * open devname, to mmap it
329 fd = open(devname, O_RDWR);
332 RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
333 devname, strerror(errno));
337 /* Map the PCI memory resource of device */
338 mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
339 MAP_SHARED, fd, offset);
340 if (mapaddr == MAP_FAILED ||
341 (requested_addr != NULL && mapaddr != requested_addr)) {
342 RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
343 " %s (%p)\n", __func__, devname, fd, requested_addr,
344 (unsigned long)size, (unsigned long)offset,
345 strerror(errno), mapaddr);
349 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
350 /* save fd if in primary process */
351 dev->intr_handle.fd = fd;
352 dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
354 /* fd is not needed in slave process, close it */
355 dev->intr_handle.fd = -1;
356 dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
360 RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr);
365 dev->intr_handle.fd = -1;
366 dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
371 #define OFF_MAX ((uint64_t)(off_t)-1)
373 pci_uio_get_mappings(const char *devname, struct uio_map maps[], size_t nb_maps)
376 char dirname[PATH_MAX];
377 char filename[PATH_MAX];
378 uint64_t offset, size;
380 for (i = 0; i != nb_maps; i++) {
382 /* check if map directory exists */
383 rte_snprintf(dirname, sizeof(dirname),
384 "%s/maps/map%u", devname, i);
386 if (access(dirname, F_OK) != 0)
389 /* get mapping offset */
390 rte_snprintf(filename, sizeof(filename),
391 "%s/offset", dirname);
392 if (pci_parse_sysfs_value(filename, &offset) < 0) {
394 "%s(): cannot parse offset of %s\n",
399 /* get mapping size */
400 rte_snprintf(filename, sizeof(filename),
402 if (pci_parse_sysfs_value(filename, &size) < 0) {
404 "%s(): cannot parse size of %s\n",
409 /* get mapping physical address */
410 rte_snprintf(filename, sizeof(filename),
412 if (pci_parse_sysfs_value(filename, &maps[i].phaddr) < 0) {
414 "%s(): cannot parse addr of %s\n",
419 if ((offset > OFF_MAX) || (size > SIZE_MAX)) {
421 "%s(): offset/size exceed system max value\n",
426 maps[i].offset = offset;
433 pci_uio_map_secondary(struct rte_pci_device *dev)
436 struct uio_resource *uio_res;
438 TAILQ_FOREACH(uio_res, uio_res_list, next) {
440 /* skip this element if it doesn't match our PCI address */
441 if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
444 for (i = 0; i != uio_res->nb_maps; i++) {
445 if (pci_map_resource(dev, uio_res->maps[i].addr,
447 (off_t)uio_res->maps[i].offset,
448 (size_t)uio_res->maps[i].size) !=
449 uio_res->maps[i].addr) {
451 "Cannot mmap device resource\n");
458 RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
462 /* map the PCI resource of a PCI device in virtual memory */
464 pci_uio_map_resource(struct rte_pci_device *dev)
469 char dirname[PATH_MAX];
470 char dirname2[PATH_MAX];
471 char devname[PATH_MAX]; /* contains the /dev/uioX */
478 struct rte_pci_addr *loc = &dev->addr;
479 struct uio_resource *uio_res;
480 struct uio_map *maps;
482 dev->intr_handle.fd = -1;
484 /* secondary processes - use already recorded details */
485 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
486 return (pci_uio_map_secondary(dev));
488 /* depending on kernel version, uio can be located in uio/uioX
491 rte_snprintf(dirname, sizeof(dirname),
492 "/sys/bus/pci/devices/" PCI_PRI_FMT "/uio",
493 loc->domain, loc->bus, loc->devid, loc->function);
495 dir = opendir(dirname);
497 /* retry with the parent directory */
498 rte_snprintf(dirname, sizeof(dirname),
499 "/sys/bus/pci/devices/" PCI_PRI_FMT,
500 loc->domain, loc->bus, loc->devid, loc->function);
501 dir = opendir(dirname);
504 RTE_LOG(ERR, EAL, "Cannot opendir %s\n", dirname);
509 /* take the first file starting with "uio" */
510 while ((e = readdir(dir)) != NULL) {
511 /* format could be uio%d ...*/
512 int shortprefix_len = sizeof("uio") - 1;
513 /* ... or uio:uio%d */
514 int longprefix_len = sizeof("uio:uio") - 1;
517 if (strncmp(e->d_name, "uio", 3) != 0)
520 /* first try uio%d */
522 uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10);
523 if (errno == 0 && endptr != e->d_name) {
524 rte_snprintf(dirname2, sizeof(dirname2),
525 "%s/uio%u", dirname, uio_num);
529 /* then try uio:uio%d */
531 uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10);
532 if (errno == 0 && endptr != e->d_name) {
533 rte_snprintf(dirname2, sizeof(dirname2),
534 "%s/uio:uio%u", dirname, uio_num);
540 /* No uio resource found */
542 RTE_LOG(WARNING, EAL, " "PCI_PRI_FMT" not managed by UIO driver, "
543 "skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
547 /* allocate the mapping details for secondary processes*/
548 if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
550 "%s(): cannot store uio mmap details\n", __func__);
554 rte_snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
555 rte_snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
556 memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
558 /* collect info about device mappings */
559 if ((nb_maps = pci_uio_get_mappings(dirname2, uio_res->maps,
560 sizeof (uio_res->maps) / sizeof (uio_res->maps[0])))
564 uio_res->nb_maps = nb_maps;
567 pagesz = sysconf(_SC_PAGESIZE);
569 maps = uio_res->maps;
570 for (i = 0; i != PCI_MAX_RESOURCE; i++) {
573 if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
576 for (j = 0; j != nb_maps && (phaddr != maps[j].phaddr ||
577 dev->mem_resource[i].len != maps[j].size);
581 /* if matching map is found, then use it */
584 if (maps[j].addr != NULL ||
585 (mapaddr = pci_map_resource(dev,
586 NULL, devname, (off_t)offset,
587 (size_t)maps[j].size)) == NULL) {
591 maps[j].addr = mapaddr;
592 maps[j].offset = offset;
593 dev->mem_resource[i].addr = mapaddr;
597 TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
602 /* parse the "resource" sysfs file */
603 #define IORESOURCE_MEM 0x00000200
606 pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
610 union pci_resource_info {
616 char *ptrs[PCI_RESOURCE_FMT_NVAL];
619 uint64_t phys_addr, end_addr, flags;
621 f = fopen(filename, "r");
623 RTE_LOG(ERR, EAL, "Cannot open sysfs resource\n");
627 for (i = 0; i<PCI_MAX_RESOURCE; i++) {
629 if (fgets(buf, sizeof(buf), f) == NULL) {
631 "%s(): cannot read resource\n", __func__);
635 if (rte_strsplit(buf, sizeof(buf), res_info.ptrs, 3, ' ') != 3) {
637 "%s(): bad resource format\n", __func__);
641 phys_addr = strtoull(res_info.phys_addr, NULL, 16);
642 end_addr = strtoull(res_info.end_addr, NULL, 16);
643 flags = strtoull(res_info.flags, NULL, 16);
646 "%s(): bad resource format\n", __func__);
650 if (flags & IORESOURCE_MEM) {
651 dev->mem_resource[i].phys_addr = phys_addr;
652 dev->mem_resource[i].len = end_addr - phys_addr + 1;
653 /* not mapped for now */
654 dev->mem_resource[i].addr = NULL;
666 * parse a sysfs file containing one integer value
667 * different to the eal version, as it needs to work with 64-bit values
670 pci_parse_sysfs_value(const char *filename, uint64_t *val)
676 f = fopen(filename, "r");
678 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
683 if (fgets(buf, sizeof(buf), f) == NULL) {
684 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
689 *val = strtoull(buf, &end, 0);
690 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
691 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
700 /* Compare two PCI device addresses. */
702 pci_addr_comparison(struct rte_pci_addr *addr, struct rte_pci_addr *addr2)
704 uint64_t dev_addr = (addr->domain << 24) + (addr->bus << 16) + (addr->devid << 8) + addr->function;
705 uint64_t dev_addr2 = (addr2->domain << 24) + (addr2->bus << 16) + (addr2->devid << 8) + addr2->function;
707 if (dev_addr > dev_addr2)
714 /* Scan one pci sysfs entry, and fill the devices list from it. */
716 pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
717 uint8_t devid, uint8_t function)
719 char filename[PATH_MAX];
721 struct rte_pci_device *dev;
723 dev = malloc(sizeof(*dev));
728 memset(dev, 0, sizeof(*dev));
729 dev->addr.domain = domain;
731 dev->addr.devid = devid;
732 dev->addr.function = function;
735 rte_snprintf(filename, sizeof(filename), "%s/vendor", dirname);
736 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
740 dev->id.vendor_id = (uint16_t)tmp;
743 rte_snprintf(filename, sizeof(filename), "%s/device", dirname);
744 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
748 dev->id.device_id = (uint16_t)tmp;
750 /* get subsystem_vendor id */
751 rte_snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
753 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
757 dev->id.subsystem_vendor_id = (uint16_t)tmp;
759 /* get subsystem_device id */
760 rte_snprintf(filename, sizeof(filename), "%s/subsystem_device",
762 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
766 dev->id.subsystem_device_id = (uint16_t)tmp;
770 rte_snprintf(filename, sizeof(filename), "%s/max_vfs", dirname);
771 if (!access(filename, F_OK) &&
772 eal_parse_sysfs_value(filename, &tmp) == 0) {
773 dev->max_vfs = (uint16_t)tmp;
777 rte_snprintf(filename, sizeof(filename), "%s/numa_node",
779 if (access(filename, R_OK) != 0) {
780 /* if no NUMA support just set node to 0 */
783 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
787 dev->numa_node = tmp;
790 /* parse resources */
791 rte_snprintf(filename, sizeof(filename), "%s/resource", dirname);
792 if (pci_parse_sysfs_resource(filename, dev) < 0) {
793 RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__);
798 /* device is valid, add in list (sorted) */
799 if (TAILQ_EMPTY(&device_list)) {
800 TAILQ_INSERT_TAIL(&device_list, dev, next);
803 struct rte_pci_device *dev2 = NULL;
805 TAILQ_FOREACH(dev2, &device_list, next) {
806 if (pci_addr_comparison(&dev->addr, &dev2->addr))
809 TAILQ_INSERT_BEFORE(dev2, dev, next);
813 TAILQ_INSERT_TAIL(&device_list, dev, next);
820 * split up a pci address into its constituent parts.
823 parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain,
824 uint8_t *bus, uint8_t *devid, uint8_t *function)
826 /* first split on ':' */
834 char *str[PCI_FMT_NVAL]; /* last element-separator is "." not ":" */
837 char *buf_copy = strndup(buf, bufsize);
838 if (buf_copy == NULL)
841 if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':')
844 /* final split is on '.' between devid and function */
845 splitaddr.function = strchr(splitaddr.devid,'.');
846 if (splitaddr.function == NULL)
848 *splitaddr.function++ = '\0';
850 /* now convert to int values */
852 *domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
853 *bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
854 *devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
855 *function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
859 free(buf_copy); /* free the copy made with strdup */
867 * Scan the content of the PCI bus, and the devices in the devices
875 char dirname[PATH_MAX];
877 uint8_t bus, devid, function;
879 dir = opendir(SYSFS_PCI_DEVICES);
881 RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
882 __func__, strerror(errno));
886 while ((e = readdir(dir)) != NULL) {
887 if (e->d_name[0] == '.')
890 if (parse_pci_addr_format(e->d_name, sizeof(e->d_name), &domain,
891 &bus, &devid, &function) != 0)
894 rte_snprintf(dirname, sizeof(dirname), "%s/%s", SYSFS_PCI_DEVICES,
896 if (pci_scan_one(dirname, domain, bus, devid, function) < 0)
908 * If vendor/device ID match, call the devinit() function of the
912 rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
914 struct rte_pci_id *id_table;
915 #ifdef RTE_EAL_UNBIND_PORTS
916 const char *module_name = NULL;
919 if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO)
920 module_name = IGB_UIO_NAME;
923 for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
925 /* check if device's identifiers match the driver's ones */
926 if (id_table->vendor_id != dev->id.vendor_id &&
927 id_table->vendor_id != PCI_ANY_ID)
929 if (id_table->device_id != dev->id.device_id &&
930 id_table->device_id != PCI_ANY_ID)
932 if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
933 id_table->subsystem_vendor_id != PCI_ANY_ID)
935 if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
936 id_table->subsystem_device_id != PCI_ANY_ID)
939 struct rte_pci_addr *loc = &dev->addr;
941 RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
942 loc->domain, loc->bus, loc->devid, loc->function,
945 RTE_LOG(DEBUG, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id,
946 dev->id.device_id, dr->name);
948 /* no initialization when blacklisted, return without error */
949 if (dev->blacklisted) {
950 RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n");
954 #ifdef RTE_EAL_UNBIND_PORTS
955 /* Unbind PCI devices if needed */
956 if (module_name != NULL)
957 if (pci_switch_module(dr, dev, uio_status, module_name) < 0)
960 /* just map the NIC resources */
961 if (pci_uio_map_resource(dev) < 0)
965 /* We always should have BAR0 mapped */
966 if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
967 dev->mem_resource[0].addr == NULL) {
969 "%s(): BAR0 is not mapped\n",
974 /* reference driver structure */
977 /* call the driver devinit() function */
978 return dr->devinit(dr, dev);
980 /* return positive value if driver is not found */
984 /* Init the PCI EAL subsystem */
986 rte_eal_pci_init(void)
988 TAILQ_INIT(&driver_list);
989 TAILQ_INIT(&device_list);
990 uio_res_list = RTE_TAILQ_RESERVE_BY_IDX(RTE_TAILQ_PCI, uio_res_list);
992 /* for debug purposes, PCI can be disabled */
993 if (internal_config.no_pci)
996 if (pci_scan() < 0) {
997 RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);