4 * Copyright(c) 2010-2014 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>
67 #include <rte_devargs.h>
69 #include "rte_pci_dev_ids.h"
70 #include "eal_filesystem.h"
71 #include "eal_private.h"
75 * PCI probing under linux
77 * This code is used to simulate a PCI probe by parsing information in
78 * sysfs. Moreover, when a registered driver matches a device, the
79 * kernel driver currently using it is unloaded and replaced by
80 * igb_uio module, which is a very minimal userland driver for Intel
81 * network card, only providing access to PCI BAR to applications, and
82 * enabling bus master.
93 * For multi-process we need to reproduce all PCI mappings in secondary
94 * processes, so save them in a tailq.
97 TAILQ_ENTRY(uio_resource) next;
99 struct rte_pci_addr pci_addr;
102 struct uio_map maps[PCI_MAX_RESOURCE];
105 TAILQ_HEAD(uio_res_list, uio_resource);
107 static struct uio_res_list *uio_res_list = NULL;
108 static int pci_parse_sysfs_value(const char *filename, uint64_t *val);
110 /* unbind kernel driver for this device */
112 pci_unbind_kernel_driver(struct rte_pci_device *dev)
116 char filename[PATH_MAX];
118 struct rte_pci_addr *loc = &dev->addr;
120 /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
121 rte_snprintf(filename, sizeof(filename),
122 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind",
123 loc->domain, loc->bus, loc->devid, loc->function);
125 f = fopen(filename, "w");
126 if (f == NULL) /* device was not bound */
129 n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
130 loc->domain, loc->bus, loc->devid, loc->function);
131 if ((n < 0) || (n >= (int)sizeof(buf))) {
132 RTE_LOG(ERR, EAL, "%s(): rte_snprintf failed\n", __func__);
135 if (fwrite(buf, n, 1, f) == 0) {
136 RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
149 #ifdef RTE_EAL_UNBIND_PORTS
150 #define PROC_MODULES "/proc/modules"
152 #define IGB_UIO_NAME "igb_uio"
154 #define UIO_DRV_PATH "/sys/bus/pci/drivers/%s"
156 /* maximum time to wait that /dev/uioX appears */
157 #define UIO_DEV_WAIT_TIMEOUT 3 /* seconds */
160 * Check that a kernel module is loaded. Returns 0 on success, or if the
161 * parameter is NULL, or -1 if the module is not loaded.
164 pci_uio_check_module(const char *module_name)
170 if (module_name == NULL)
173 f = fopen(PROC_MODULES, "r");
175 RTE_LOG(ERR, EAL, "Cannot open "PROC_MODULES": %s\n",
180 while(fgets(buf, sizeof(buf), f) != NULL) {
182 for (i = 0; i < sizeof(buf) && buf[i] != '\0'; i++) {
187 if (strncmp(buf, module_name, sizeof(buf)) == 0) {
196 /* bind a PCI to the kernel module driver */
198 pci_bind_device(struct rte_pci_device *dev, char dr_path[])
203 char dev_bind[PATH_MAX];
204 struct rte_pci_addr *loc = &dev->addr;
206 n = rte_snprintf(dev_bind, sizeof(dev_bind), "%s/bind", dr_path);
207 if ((n < 0) || (n >= (int)sizeof(buf))) {
208 RTE_LOG(ERR, EAL, "Cannot rte_snprintf device bind path\n");
212 f = fopen(dev_bind, "w");
214 RTE_LOG(ERR, EAL, "Cannot open %s\n", dev_bind);
217 n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
218 loc->domain, loc->bus, loc->devid, loc->function);
219 if ((n < 0) || (n >= (int)sizeof(buf))) {
220 RTE_LOG(ERR, EAL, "Cannot rte_snprintf PCI infos\n");
224 if (fwrite(buf, n, 1, f) == 0) {
234 pci_uio_bind_device(struct rte_pci_device *dev, const char *module_name)
239 char uio_newid[PATH_MAX];
240 char uio_bind[PATH_MAX];
242 n = rte_snprintf(uio_newid, sizeof(uio_newid), UIO_DRV_PATH "/new_id", module_name);
243 if ((n < 0) || (n >= (int)sizeof(uio_newid))) {
244 RTE_LOG(ERR, EAL, "Cannot rte_snprintf uio_newid name\n");
248 n = rte_snprintf(uio_bind, sizeof(uio_bind), UIO_DRV_PATH, module_name);
249 if ((n < 0) || (n >= (int)sizeof(uio_bind))) {
250 RTE_LOG(ERR, EAL, "Cannot rte_snprintf uio_bind name\n");
254 n = rte_snprintf(buf, sizeof(buf), "%x %x\n",
255 dev->id.vendor_id, dev->id.device_id);
256 if ((n < 0) || (n >= (int)sizeof(buf))) {
257 RTE_LOG(ERR, EAL, "Cannot rte_snprintf vendor_id/device_id\n");
261 f = fopen(uio_newid, "w");
263 RTE_LOG(ERR, EAL, "Cannot open %s\n", uio_newid);
266 if (fwrite(buf, n, 1, f) == 0) {
272 pci_bind_device(dev, uio_bind);
277 pci_switch_module(struct rte_pci_driver *dr, struct rte_pci_device *dev,
278 const char *module_name)
280 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
281 /* check that our driver is loaded */
282 if (pci_uio_check_module(module_name) != 0)
283 rte_exit(EXIT_FAILURE, "The %s module is required by the "
284 "%s driver\n", module_name, dr->name);
286 /* unbind current driver, bind ours */
287 if (pci_unbind_kernel_driver(dev) < 0)
289 if (pci_uio_bind_device(dev, module_name) < 0)
296 #endif /* ifdef EAL_UNBIND_PORTS */
298 /* map a particular resource from a file */
300 pci_map_resource(void *requested_addr, const char *devname, off_t offset,
306 #ifdef RTE_EAL_UNBIND_PORTS
308 * open devname, and mmap it: it can take some time to
309 * appear, so we wait some time before returning an error
312 for (n = 0; n < UIO_DEV_WAIT_TIMEOUT*10; n++) {
314 if ((fd = open(devname, O_RDWR)) < 0 && errno != ENOENT)
320 * open devname, to mmap it
322 fd = open(devname, O_RDWR);
325 RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
326 devname, strerror(errno));
330 /* Map the PCI memory resource of device */
331 mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
332 MAP_SHARED, fd, offset);
334 if (mapaddr == MAP_FAILED ||
335 (requested_addr != NULL && mapaddr != requested_addr)) {
336 RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
337 " %s (%p)\n", __func__, devname, fd, requested_addr,
338 (unsigned long)size, (unsigned long)offset,
339 strerror(errno), mapaddr);
343 RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr);
351 #define OFF_MAX ((uint64_t)(off_t)-1)
353 pci_uio_get_mappings(const char *devname, struct uio_map maps[], size_t nb_maps)
356 char dirname[PATH_MAX];
357 char filename[PATH_MAX];
358 uint64_t offset, size;
360 for (i = 0; i != nb_maps; i++) {
362 /* check if map directory exists */
363 rte_snprintf(dirname, sizeof(dirname),
364 "%s/maps/map%u", devname, i);
366 if (access(dirname, F_OK) != 0)
369 /* get mapping offset */
370 rte_snprintf(filename, sizeof(filename),
371 "%s/offset", dirname);
372 if (pci_parse_sysfs_value(filename, &offset) < 0) {
374 "%s(): cannot parse offset of %s\n",
379 /* get mapping size */
380 rte_snprintf(filename, sizeof(filename),
382 if (pci_parse_sysfs_value(filename, &size) < 0) {
384 "%s(): cannot parse size of %s\n",
389 /* get mapping physical address */
390 rte_snprintf(filename, sizeof(filename),
392 if (pci_parse_sysfs_value(filename, &maps[i].phaddr) < 0) {
394 "%s(): cannot parse addr of %s\n",
399 if ((offset > OFF_MAX) || (size > SIZE_MAX)) {
401 "%s(): offset/size exceed system max value\n",
406 maps[i].offset = offset;
413 pci_uio_map_secondary(struct rte_pci_device *dev)
416 struct uio_resource *uio_res;
418 TAILQ_FOREACH(uio_res, uio_res_list, next) {
420 /* skip this element if it doesn't match our PCI address */
421 if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
424 for (i = 0; i != uio_res->nb_maps; i++) {
425 if (pci_map_resource(uio_res->maps[i].addr,
427 (off_t)uio_res->maps[i].offset,
428 (size_t)uio_res->maps[i].size)
429 != uio_res->maps[i].addr) {
431 "Cannot mmap device resource\n");
438 RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
442 static int pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
445 char filename[PATH_MAX];
447 unsigned major, minor;
450 /* get the name of the sysfs file that contains the major and minor
451 * of the uio device and read its content */
452 rte_snprintf(filename, sizeof(filename), "%s/dev", sysfs_uio_path);
454 f = fopen(filename, "r");
456 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs to get major:minor\n",
461 ret = fscanf(f, "%d:%d", &major, &minor);
463 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs to get major:minor\n",
470 /* create the char device "mknod /dev/uioX c major minor" */
471 rte_snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num);
472 dev = makedev(major, minor);
473 ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev);
475 RTE_LOG(ERR, EAL, "%s(): mknod() failed %s\n",
476 __func__, strerror(errno));
484 * Return the uioX char device used for a pci device. On success, return
485 * the UIO number and fill dstbuf string with the path of the device in
486 * sysfs. On error, return a negative value. In this case dstbuf is
489 static int pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
492 struct rte_pci_addr *loc = &dev->addr;
493 unsigned int uio_num;
496 char dirname[PATH_MAX];
498 /* depending on kernel version, uio can be located in uio/uioX
501 rte_snprintf(dirname, sizeof(dirname),
502 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio",
503 loc->domain, loc->bus, loc->devid, loc->function);
505 dir = opendir(dirname);
507 /* retry with the parent directory */
508 rte_snprintf(dirname, sizeof(dirname),
509 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT,
510 loc->domain, loc->bus, loc->devid, loc->function);
511 dir = opendir(dirname);
514 RTE_LOG(ERR, EAL, "Cannot opendir %s\n", dirname);
519 /* take the first file starting with "uio" */
520 while ((e = readdir(dir)) != NULL) {
521 /* format could be uio%d ...*/
522 int shortprefix_len = sizeof("uio") - 1;
523 /* ... or uio:uio%d */
524 int longprefix_len = sizeof("uio:uio") - 1;
527 if (strncmp(e->d_name, "uio", 3) != 0)
530 /* first try uio%d */
532 uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10);
533 if (errno == 0 && endptr != (e->d_name + shortprefix_len)) {
534 rte_snprintf(dstbuf, buflen, "%s/uio%u", dirname, uio_num);
538 /* then try uio:uio%d */
540 uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10);
541 if (errno == 0 && endptr != (e->d_name + longprefix_len)) {
542 rte_snprintf(dstbuf, buflen, "%s/uio:uio%u", dirname, uio_num);
548 /* No uio resource found */
552 /* create uio device if we've been asked to */
553 if (internal_config.create_uio_dev && pci_mknod_uio_dev(dstbuf, uio_num) < 0)
554 RTE_LOG(WARNING, EAL, "Cannot create /dev/uio%u\n", uio_num);
559 /* map the PCI resource of a PCI device in virtual memory */
561 pci_uio_map_resource(struct rte_pci_device *dev)
564 char dirname[PATH_MAX];
565 char devname[PATH_MAX]; /* contains the /dev/uioX */
572 struct rte_pci_addr *loc = &dev->addr;
573 struct uio_resource *uio_res;
574 struct uio_map *maps;
576 dev->intr_handle.fd = -1;
577 dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
579 /* secondary processes - use already recorded details */
580 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
581 return (pci_uio_map_secondary(dev));
583 /* find uio resource */
584 uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
586 RTE_LOG(WARNING, EAL, " "PCI_PRI_FMT" not managed by UIO driver, "
587 "skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
590 rte_snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
592 /* save fd if in primary process */
593 dev->intr_handle.fd = open(devname, O_RDWR);
594 if (dev->intr_handle.fd < 0) {
595 RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
596 devname, strerror(errno));
599 dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
601 /* allocate the mapping details for secondary processes*/
602 if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
604 "%s(): cannot store uio mmap details\n", __func__);
608 rte_snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
609 memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
611 /* collect info about device mappings */
612 nb_maps = pci_uio_get_mappings(dirname, uio_res->maps,
613 RTE_DIM(uio_res->maps));
619 uio_res->nb_maps = nb_maps;
622 pagesz = sysconf(_SC_PAGESIZE);
624 maps = uio_res->maps;
625 for (i = 0; i != PCI_MAX_RESOURCE; i++) {
628 if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
631 for (j = 0; j != nb_maps && (phaddr != maps[j].phaddr ||
632 dev->mem_resource[i].len != maps[j].size);
636 /* if matching map is found, then use it */
639 if (maps[j].addr != NULL ||
640 (mapaddr = pci_map_resource(NULL, devname,
642 (size_t)maps[j].size)
648 maps[j].addr = mapaddr;
649 maps[j].offset = offset;
650 dev->mem_resource[i].addr = mapaddr;
654 TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
659 /* parse the "resource" sysfs file */
660 #define IORESOURCE_MEM 0x00000200
663 pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
667 union pci_resource_info {
673 char *ptrs[PCI_RESOURCE_FMT_NVAL];
676 uint64_t phys_addr, end_addr, flags;
678 f = fopen(filename, "r");
680 RTE_LOG(ERR, EAL, "Cannot open sysfs resource\n");
684 for (i = 0; i<PCI_MAX_RESOURCE; i++) {
686 if (fgets(buf, sizeof(buf), f) == NULL) {
688 "%s(): cannot read resource\n", __func__);
692 if (rte_strsplit(buf, sizeof(buf), res_info.ptrs, 3, ' ') != 3) {
694 "%s(): bad resource format\n", __func__);
698 phys_addr = strtoull(res_info.phys_addr, NULL, 16);
699 end_addr = strtoull(res_info.end_addr, NULL, 16);
700 flags = strtoull(res_info.flags, NULL, 16);
703 "%s(): bad resource format\n", __func__);
707 if (flags & IORESOURCE_MEM) {
708 dev->mem_resource[i].phys_addr = phys_addr;
709 dev->mem_resource[i].len = end_addr - phys_addr + 1;
710 /* not mapped for now */
711 dev->mem_resource[i].addr = NULL;
723 * parse a sysfs file containing one integer value
724 * different to the eal version, as it needs to work with 64-bit values
727 pci_parse_sysfs_value(const char *filename, uint64_t *val)
733 f = fopen(filename, "r");
735 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
740 if (fgets(buf, sizeof(buf), f) == NULL) {
741 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
746 *val = strtoull(buf, &end, 0);
747 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
748 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
757 /* Compare two PCI device addresses. */
759 pci_addr_comparison(struct rte_pci_addr *addr, struct rte_pci_addr *addr2)
761 uint64_t dev_addr = (addr->domain << 24) + (addr->bus << 16) + (addr->devid << 8) + addr->function;
762 uint64_t dev_addr2 = (addr2->domain << 24) + (addr2->bus << 16) + (addr2->devid << 8) + addr2->function;
764 if (dev_addr > dev_addr2)
771 /* Scan one pci sysfs entry, and fill the devices list from it. */
773 pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
774 uint8_t devid, uint8_t function)
776 char filename[PATH_MAX];
778 struct rte_pci_device *dev;
780 dev = malloc(sizeof(*dev));
785 memset(dev, 0, sizeof(*dev));
786 dev->addr.domain = domain;
788 dev->addr.devid = devid;
789 dev->addr.function = function;
792 rte_snprintf(filename, sizeof(filename), "%s/vendor", dirname);
793 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
797 dev->id.vendor_id = (uint16_t)tmp;
800 rte_snprintf(filename, sizeof(filename), "%s/device", dirname);
801 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
805 dev->id.device_id = (uint16_t)tmp;
807 /* get subsystem_vendor id */
808 rte_snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
810 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
814 dev->id.subsystem_vendor_id = (uint16_t)tmp;
816 /* get subsystem_device id */
817 rte_snprintf(filename, sizeof(filename), "%s/subsystem_device",
819 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
823 dev->id.subsystem_device_id = (uint16_t)tmp;
827 rte_snprintf(filename, sizeof(filename), "%s/max_vfs", dirname);
828 if (!access(filename, F_OK) &&
829 eal_parse_sysfs_value(filename, &tmp) == 0) {
830 dev->max_vfs = (uint16_t)tmp;
834 rte_snprintf(filename, sizeof(filename), "%s/numa_node",
836 if (access(filename, R_OK) != 0) {
837 /* if no NUMA support just set node to 0 */
840 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
844 dev->numa_node = tmp;
847 /* parse resources */
848 rte_snprintf(filename, sizeof(filename), "%s/resource", dirname);
849 if (pci_parse_sysfs_resource(filename, dev) < 0) {
850 RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__);
855 /* device is valid, add in list (sorted) */
856 if (TAILQ_EMPTY(&pci_device_list)) {
857 TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
860 struct rte_pci_device *dev2 = NULL;
862 TAILQ_FOREACH(dev2, &pci_device_list, next) {
863 if (pci_addr_comparison(&dev->addr, &dev2->addr))
866 TAILQ_INSERT_BEFORE(dev2, dev, next);
870 TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
877 * split up a pci address into its constituent parts.
880 parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain,
881 uint8_t *bus, uint8_t *devid, uint8_t *function)
883 /* first split on ':' */
891 char *str[PCI_FMT_NVAL]; /* last element-separator is "." not ":" */
894 char *buf_copy = strndup(buf, bufsize);
895 if (buf_copy == NULL)
898 if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':')
901 /* final split is on '.' between devid and function */
902 splitaddr.function = strchr(splitaddr.devid,'.');
903 if (splitaddr.function == NULL)
905 *splitaddr.function++ = '\0';
907 /* now convert to int values */
909 *domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
910 *bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
911 *devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
912 *function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
916 free(buf_copy); /* free the copy made with strdup */
924 * Scan the content of the PCI bus, and the devices in the devices
932 char dirname[PATH_MAX];
934 uint8_t bus, devid, function;
936 dir = opendir(SYSFS_PCI_DEVICES);
938 RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
939 __func__, strerror(errno));
943 while ((e = readdir(dir)) != NULL) {
944 if (e->d_name[0] == '.')
947 if (parse_pci_addr_format(e->d_name, sizeof(e->d_name), &domain,
948 &bus, &devid, &function) != 0)
951 rte_snprintf(dirname, sizeof(dirname), "%s/%s", SYSFS_PCI_DEVICES,
953 if (pci_scan_one(dirname, domain, bus, devid, function) < 0)
965 * If vendor/device ID match, call the devinit() function of the
969 rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
971 struct rte_pci_id *id_table;
973 for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
975 /* check if device's identifiers match the driver's ones */
976 if (id_table->vendor_id != dev->id.vendor_id &&
977 id_table->vendor_id != PCI_ANY_ID)
979 if (id_table->device_id != dev->id.device_id &&
980 id_table->device_id != PCI_ANY_ID)
982 if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
983 id_table->subsystem_vendor_id != PCI_ANY_ID)
985 if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
986 id_table->subsystem_device_id != PCI_ANY_ID)
989 struct rte_pci_addr *loc = &dev->addr;
991 RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
992 loc->domain, loc->bus, loc->devid, loc->function,
995 RTE_LOG(DEBUG, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id,
996 dev->id.device_id, dr->name);
998 /* no initialization when blacklisted, return without error */
999 if (dev->devargs != NULL &&
1000 dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
1001 RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n");
1005 #ifdef RTE_EAL_UNBIND_PORTS
1006 if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) {
1007 /* unbind current driver and bind on igb_uio */
1008 if (pci_switch_module(dr, dev, IGB_UIO_NAME) < 0)
1013 if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) {
1014 /* map resources for devices that use igb_uio */
1015 if (pci_uio_map_resource(dev) < 0)
1017 } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
1018 rte_eal_process_type() == RTE_PROC_PRIMARY) {
1019 /* unbind current driver */
1020 if (pci_unbind_kernel_driver(dev) < 0)
1024 /* reference driver structure */
1027 /* call the driver devinit() function */
1028 return dr->devinit(dr, dev);
1030 /* return positive value if driver is not found */
1034 /* Init the PCI EAL subsystem */
1036 rte_eal_pci_init(void)
1038 TAILQ_INIT(&pci_driver_list);
1039 TAILQ_INIT(&pci_device_list);
1040 uio_res_list = RTE_TAILQ_RESERVE_BY_IDX(RTE_TAILQ_PCI, uio_res_list);
1042 /* for debug purposes, PCI can be disabled */
1043 if (internal_config.no_pci)
1046 if (pci_scan() < 0) {
1047 RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);