vfio: support hotplug
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_pci.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <string.h>
35 #include <dirent.h>
36
37 #include <rte_log.h>
38 #include <rte_pci.h>
39 #include <rte_eal_memconfig.h>
40 #include <rte_malloc.h>
41 #include <rte_devargs.h>
42 #include <rte_memcpy.h>
43
44 #include "eal_filesystem.h"
45 #include "eal_private.h"
46 #include "eal_pci_init.h"
47
48 /**
49  * @file
50  * PCI probing under linux
51  *
52  * This code is used to simulate a PCI probe by parsing information in sysfs.
53  * When a registered device matches a driver, it is then initialized with
54  * IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it).
55  */
56
57 static int
58 pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
59 {
60         int count;
61         char path[PATH_MAX];
62         char *name;
63
64         if (!filename || !dri_name)
65                 return -1;
66
67         count = readlink(filename, path, PATH_MAX);
68         if (count >= PATH_MAX)
69                 return -1;
70
71         /* For device does not have a driver */
72         if (count < 0)
73                 return 1;
74
75         path[count] = '\0';
76
77         name = strrchr(path, '/');
78         if (name) {
79                 strncpy(dri_name, name + 1, strlen(name + 1) + 1);
80                 return 0;
81         }
82
83         return -1;
84 }
85
86 /* Map pci device */
87 int
88 rte_eal_pci_map_device(struct rte_pci_device *dev)
89 {
90         int ret = -1;
91
92         /* try mapping the NIC resources using VFIO if it exists */
93         switch (dev->kdrv) {
94         case RTE_KDRV_VFIO:
95 #ifdef VFIO_PRESENT
96                 if (pci_vfio_is_enabled())
97                         ret = pci_vfio_map_resource(dev);
98 #endif
99                 break;
100         case RTE_KDRV_IGB_UIO:
101         case RTE_KDRV_UIO_GENERIC:
102                 if (rte_eal_using_phys_addrs()) {
103                         /* map resources for devices that use uio */
104                         ret = pci_uio_map_resource(dev);
105                 }
106                 break;
107         default:
108                 RTE_LOG(DEBUG, EAL,
109                         "  Not managed by a supported kernel driver, skipped\n");
110                 ret = 1;
111                 break;
112         }
113
114         return ret;
115 }
116
117 /* Unmap pci device */
118 void
119 rte_eal_pci_unmap_device(struct rte_pci_device *dev)
120 {
121         /* try unmapping the NIC resources using VFIO if it exists */
122         switch (dev->kdrv) {
123         case RTE_KDRV_VFIO:
124 #ifdef VFIO_PRESENT
125                 if (pci_vfio_is_enabled())
126                         pci_vfio_unmap_resource(dev);
127 #endif
128                 break;
129         case RTE_KDRV_IGB_UIO:
130         case RTE_KDRV_UIO_GENERIC:
131                 /* unmap resources for devices that use uio */
132                 pci_uio_unmap_resource(dev);
133                 break;
134         default:
135                 RTE_LOG(DEBUG, EAL,
136                         "  Not managed by a supported kernel driver, skipped\n");
137                 break;
138         }
139 }
140
141 void *
142 pci_find_max_end_va(void)
143 {
144         const struct rte_memseg *seg = rte_eal_get_physmem_layout();
145         const struct rte_memseg *last = seg;
146         unsigned i = 0;
147
148         for (i = 0; i < RTE_MAX_MEMSEG; i++, seg++) {
149                 if (seg->addr == NULL)
150                         break;
151
152                 if (seg->addr > last->addr)
153                         last = seg;
154
155         }
156         return RTE_PTR_ADD(last->addr, last->len);
157 }
158
159 /* parse one line of the "resource" sysfs file (note that the 'line'
160  * string is modified)
161  */
162 int
163 pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr,
164         uint64_t *end_addr, uint64_t *flags)
165 {
166         union pci_resource_info {
167                 struct {
168                         char *phys_addr;
169                         char *end_addr;
170                         char *flags;
171                 };
172                 char *ptrs[PCI_RESOURCE_FMT_NVAL];
173         } res_info;
174
175         if (rte_strsplit(line, len, res_info.ptrs, 3, ' ') != 3) {
176                 RTE_LOG(ERR, EAL,
177                         "%s(): bad resource format\n", __func__);
178                 return -1;
179         }
180         errno = 0;
181         *phys_addr = strtoull(res_info.phys_addr, NULL, 16);
182         *end_addr = strtoull(res_info.end_addr, NULL, 16);
183         *flags = strtoull(res_info.flags, NULL, 16);
184         if (errno != 0) {
185                 RTE_LOG(ERR, EAL,
186                         "%s(): bad resource format\n", __func__);
187                 return -1;
188         }
189
190         return 0;
191 }
192
193 /* parse the "resource" sysfs file */
194 static int
195 pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
196 {
197         FILE *f;
198         char buf[BUFSIZ];
199         int i;
200         uint64_t phys_addr, end_addr, flags;
201
202         f = fopen(filename, "r");
203         if (f == NULL) {
204                 RTE_LOG(ERR, EAL, "Cannot open sysfs resource\n");
205                 return -1;
206         }
207
208         for (i = 0; i<PCI_MAX_RESOURCE; i++) {
209
210                 if (fgets(buf, sizeof(buf), f) == NULL) {
211                         RTE_LOG(ERR, EAL,
212                                 "%s(): cannot read resource\n", __func__);
213                         goto error;
214                 }
215                 if (pci_parse_one_sysfs_resource(buf, sizeof(buf), &phys_addr,
216                                 &end_addr, &flags) < 0)
217                         goto error;
218
219                 if (flags & IORESOURCE_MEM) {
220                         dev->mem_resource[i].phys_addr = phys_addr;
221                         dev->mem_resource[i].len = end_addr - phys_addr + 1;
222                         /* not mapped for now */
223                         dev->mem_resource[i].addr = NULL;
224                 }
225         }
226         fclose(f);
227         return 0;
228
229 error:
230         fclose(f);
231         return -1;
232 }
233
234 /* Scan one pci sysfs entry, and fill the devices list from it. */
235 static int
236 pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
237 {
238         char filename[PATH_MAX];
239         unsigned long tmp;
240         struct rte_pci_device *dev;
241         char driver[PATH_MAX];
242         int ret;
243
244         dev = malloc(sizeof(*dev));
245         if (dev == NULL)
246                 return -1;
247
248         memset(dev, 0, sizeof(*dev));
249         dev->addr = *addr;
250
251         /* get vendor id */
252         snprintf(filename, sizeof(filename), "%s/vendor", dirname);
253         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
254                 free(dev);
255                 return -1;
256         }
257         dev->id.vendor_id = (uint16_t)tmp;
258
259         /* get device id */
260         snprintf(filename, sizeof(filename), "%s/device", dirname);
261         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
262                 free(dev);
263                 return -1;
264         }
265         dev->id.device_id = (uint16_t)tmp;
266
267         /* get subsystem_vendor id */
268         snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
269                  dirname);
270         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
271                 free(dev);
272                 return -1;
273         }
274         dev->id.subsystem_vendor_id = (uint16_t)tmp;
275
276         /* get subsystem_device id */
277         snprintf(filename, sizeof(filename), "%s/subsystem_device",
278                  dirname);
279         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
280                 free(dev);
281                 return -1;
282         }
283         dev->id.subsystem_device_id = (uint16_t)tmp;
284
285         /* get class_id */
286         snprintf(filename, sizeof(filename), "%s/class",
287                  dirname);
288         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
289                 free(dev);
290                 return -1;
291         }
292         /* the least 24 bits are valid: class, subclass, program interface */
293         dev->id.class_id = (uint32_t)tmp & RTE_CLASS_ANY_ID;
294
295         /* get max_vfs */
296         dev->max_vfs = 0;
297         snprintf(filename, sizeof(filename), "%s/max_vfs", dirname);
298         if (!access(filename, F_OK) &&
299             eal_parse_sysfs_value(filename, &tmp) == 0)
300                 dev->max_vfs = (uint16_t)tmp;
301         else {
302                 /* for non igb_uio driver, need kernel version >= 3.8 */
303                 snprintf(filename, sizeof(filename),
304                          "%s/sriov_numvfs", dirname);
305                 if (!access(filename, F_OK) &&
306                     eal_parse_sysfs_value(filename, &tmp) == 0)
307                         dev->max_vfs = (uint16_t)tmp;
308         }
309
310         /* get numa node */
311         snprintf(filename, sizeof(filename), "%s/numa_node",
312                  dirname);
313         if (access(filename, R_OK) != 0) {
314                 /* if no NUMA support, set default to 0 */
315                 dev->device.numa_node = 0;
316         } else {
317                 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
318                         free(dev);
319                         return -1;
320                 }
321                 dev->device.numa_node = tmp;
322         }
323
324         /* parse resources */
325         snprintf(filename, sizeof(filename), "%s/resource", dirname);
326         if (pci_parse_sysfs_resource(filename, dev) < 0) {
327                 RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__);
328                 free(dev);
329                 return -1;
330         }
331
332         /* parse driver */
333         snprintf(filename, sizeof(filename), "%s/driver", dirname);
334         ret = pci_get_kernel_driver_by_path(filename, driver);
335         if (ret < 0) {
336                 RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
337                 free(dev);
338                 return -1;
339         }
340
341         if (!ret) {
342                 if (!strcmp(driver, "vfio-pci"))
343                         dev->kdrv = RTE_KDRV_VFIO;
344                 else if (!strcmp(driver, "igb_uio"))
345                         dev->kdrv = RTE_KDRV_IGB_UIO;
346                 else if (!strcmp(driver, "uio_pci_generic"))
347                         dev->kdrv = RTE_KDRV_UIO_GENERIC;
348                 else
349                         dev->kdrv = RTE_KDRV_UNKNOWN;
350         } else
351                 dev->kdrv = RTE_KDRV_NONE;
352
353         /* device is valid, add in list (sorted) */
354         if (TAILQ_EMPTY(&pci_device_list)) {
355                 rte_eal_device_insert(&dev->device);
356                 TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
357         } else {
358                 struct rte_pci_device *dev2;
359                 int ret;
360
361                 TAILQ_FOREACH(dev2, &pci_device_list, next) {
362                         ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
363                         if (ret > 0)
364                                 continue;
365
366                         if (ret < 0) {
367                                 TAILQ_INSERT_BEFORE(dev2, dev, next);
368                                 rte_eal_device_insert(&dev->device);
369                         } else { /* already registered */
370                                 dev2->kdrv = dev->kdrv;
371                                 dev2->max_vfs = dev->max_vfs;
372                                 memmove(dev2->mem_resource, dev->mem_resource,
373                                         sizeof(dev->mem_resource));
374                                 free(dev);
375                         }
376                         return 0;
377                 }
378                 rte_eal_device_insert(&dev->device);
379                 TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
380         }
381
382         return 0;
383 }
384
385 int
386 pci_update_device(const struct rte_pci_addr *addr)
387 {
388         char filename[PATH_MAX];
389
390         snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT,
391                  pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid,
392                  addr->function);
393
394         return pci_scan_one(filename, addr);
395 }
396
397 /*
398  * split up a pci address into its constituent parts.
399  */
400 static int
401 parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr *addr)
402 {
403         /* first split on ':' */
404         union splitaddr {
405                 struct {
406                         char *domain;
407                         char *bus;
408                         char *devid;
409                         char *function;
410                 };
411                 char *str[PCI_FMT_NVAL]; /* last element-separator is "." not ":" */
412         } splitaddr;
413
414         char *buf_copy = strndup(buf, bufsize);
415         if (buf_copy == NULL)
416                 return -1;
417
418         if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':')
419                         != PCI_FMT_NVAL - 1)
420                 goto error;
421         /* final split is on '.' between devid and function */
422         splitaddr.function = strchr(splitaddr.devid,'.');
423         if (splitaddr.function == NULL)
424                 goto error;
425         *splitaddr.function++ = '\0';
426
427         /* now convert to int values */
428         errno = 0;
429         addr->domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
430         addr->bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
431         addr->devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
432         addr->function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
433         if (errno != 0)
434                 goto error;
435
436         free(buf_copy); /* free the copy made with strdup */
437         return 0;
438 error:
439         free(buf_copy);
440         return -1;
441 }
442
443 /*
444  * Scan the content of the PCI bus, and the devices in the devices
445  * list
446  */
447 int
448 rte_eal_pci_scan(void)
449 {
450         struct dirent *e;
451         DIR *dir;
452         char dirname[PATH_MAX];
453         struct rte_pci_addr addr;
454
455         dir = opendir(pci_get_sysfs_path());
456         if (dir == NULL) {
457                 RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
458                         __func__, strerror(errno));
459                 return -1;
460         }
461
462         while ((e = readdir(dir)) != NULL) {
463                 if (e->d_name[0] == '.')
464                         continue;
465
466                 if (parse_pci_addr_format(e->d_name, sizeof(e->d_name), &addr) != 0)
467                         continue;
468
469                 snprintf(dirname, sizeof(dirname), "%s/%s",
470                                 pci_get_sysfs_path(), e->d_name);
471                 if (pci_scan_one(dirname, &addr) < 0)
472                         goto error;
473         }
474         closedir(dir);
475         return 0;
476
477 error:
478         closedir(dir);
479         return -1;
480 }
481
482 /* Read PCI config space. */
483 int rte_eal_pci_read_config(const struct rte_pci_device *device,
484                             void *buf, size_t len, off_t offset)
485 {
486         const struct rte_intr_handle *intr_handle = &device->intr_handle;
487
488         switch (intr_handle->type) {
489         case RTE_INTR_HANDLE_UIO:
490         case RTE_INTR_HANDLE_UIO_INTX:
491                 return pci_uio_read_config(intr_handle, buf, len, offset);
492
493 #ifdef VFIO_PRESENT
494         case RTE_INTR_HANDLE_VFIO_MSIX:
495         case RTE_INTR_HANDLE_VFIO_MSI:
496         case RTE_INTR_HANDLE_VFIO_LEGACY:
497                 return pci_vfio_read_config(intr_handle, buf, len, offset);
498 #endif
499         default:
500                 RTE_LOG(ERR, EAL,
501                         "Unknown handle type of fd %d\n",
502                                         intr_handle->fd);
503                 return -1;
504         }
505 }
506
507 /* Write PCI config space. */
508 int rte_eal_pci_write_config(const struct rte_pci_device *device,
509                              const void *buf, size_t len, off_t offset)
510 {
511         const struct rte_intr_handle *intr_handle = &device->intr_handle;
512
513         switch (intr_handle->type) {
514         case RTE_INTR_HANDLE_UIO:
515         case RTE_INTR_HANDLE_UIO_INTX:
516                 return pci_uio_write_config(intr_handle, buf, len, offset);
517
518 #ifdef VFIO_PRESENT
519         case RTE_INTR_HANDLE_VFIO_MSIX:
520         case RTE_INTR_HANDLE_VFIO_MSI:
521         case RTE_INTR_HANDLE_VFIO_LEGACY:
522                 return pci_vfio_write_config(intr_handle, buf, len, offset);
523 #endif
524         default:
525                 RTE_LOG(ERR, EAL,
526                         "Unknown handle type of fd %d\n",
527                                         intr_handle->fd);
528                 return -1;
529         }
530 }
531
532 #if defined(RTE_ARCH_X86)
533 static int
534 pci_ioport_map(struct rte_pci_device *dev, int bar __rte_unused,
535                struct rte_pci_ioport *p)
536 {
537         uint16_t start, end;
538         FILE *fp;
539         char *line = NULL;
540         char pci_id[16];
541         int found = 0;
542         size_t linesz;
543
544         snprintf(pci_id, sizeof(pci_id), PCI_PRI_FMT,
545                  dev->addr.domain, dev->addr.bus,
546                  dev->addr.devid, dev->addr.function);
547
548         fp = fopen("/proc/ioports", "r");
549         if (fp == NULL) {
550                 RTE_LOG(ERR, EAL, "%s(): can't open ioports\n", __func__);
551                 return -1;
552         }
553
554         while (getdelim(&line, &linesz, '\n', fp) > 0) {
555                 char *ptr = line;
556                 char *left;
557                 int n;
558
559                 n = strcspn(ptr, ":");
560                 ptr[n] = 0;
561                 left = &ptr[n + 1];
562
563                 while (*left && isspace(*left))
564                         left++;
565
566                 if (!strncmp(left, pci_id, strlen(pci_id))) {
567                         found = 1;
568
569                         while (*ptr && isspace(*ptr))
570                                 ptr++;
571
572                         sscanf(ptr, "%04hx-%04hx", &start, &end);
573
574                         break;
575                 }
576         }
577
578         free(line);
579         fclose(fp);
580
581         if (!found)
582                 return -1;
583
584         dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
585         p->base = start;
586         RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%x\n", start);
587
588         return 0;
589 }
590 #endif
591
592 int
593 rte_eal_pci_ioport_map(struct rte_pci_device *dev, int bar,
594                        struct rte_pci_ioport *p)
595 {
596         int ret = -1;
597
598         switch (dev->kdrv) {
599 #ifdef VFIO_PRESENT
600         case RTE_KDRV_VFIO:
601                 if (pci_vfio_is_enabled())
602                         ret = pci_vfio_ioport_map(dev, bar, p);
603                 break;
604 #endif
605         case RTE_KDRV_IGB_UIO:
606                 ret = pci_uio_ioport_map(dev, bar, p);
607                 break;
608         case RTE_KDRV_UIO_GENERIC:
609 #if defined(RTE_ARCH_X86)
610                 ret = pci_ioport_map(dev, bar, p);
611 #else
612                 ret = pci_uio_ioport_map(dev, bar, p);
613 #endif
614                 break;
615         case RTE_KDRV_NONE:
616 #if defined(RTE_ARCH_X86)
617                 ret = pci_ioport_map(dev, bar, p);
618 #endif
619                 break;
620         default:
621                 break;
622         }
623
624         if (!ret)
625                 p->dev = dev;
626
627         return ret;
628 }
629
630 void
631 rte_eal_pci_ioport_read(struct rte_pci_ioport *p,
632                         void *data, size_t len, off_t offset)
633 {
634         switch (p->dev->kdrv) {
635 #ifdef VFIO_PRESENT
636         case RTE_KDRV_VFIO:
637                 pci_vfio_ioport_read(p, data, len, offset);
638                 break;
639 #endif
640         case RTE_KDRV_IGB_UIO:
641                 pci_uio_ioport_read(p, data, len, offset);
642                 break;
643         case RTE_KDRV_UIO_GENERIC:
644                 pci_uio_ioport_read(p, data, len, offset);
645                 break;
646         case RTE_KDRV_NONE:
647 #if defined(RTE_ARCH_X86)
648                 pci_uio_ioport_read(p, data, len, offset);
649 #endif
650                 break;
651         default:
652                 break;
653         }
654 }
655
656 void
657 rte_eal_pci_ioport_write(struct rte_pci_ioport *p,
658                          const void *data, size_t len, off_t offset)
659 {
660         switch (p->dev->kdrv) {
661 #ifdef VFIO_PRESENT
662         case RTE_KDRV_VFIO:
663                 pci_vfio_ioport_write(p, data, len, offset);
664                 break;
665 #endif
666         case RTE_KDRV_IGB_UIO:
667                 pci_uio_ioport_write(p, data, len, offset);
668                 break;
669         case RTE_KDRV_UIO_GENERIC:
670                 pci_uio_ioport_write(p, data, len, offset);
671                 break;
672         case RTE_KDRV_NONE:
673 #if defined(RTE_ARCH_X86)
674                 pci_uio_ioport_write(p, data, len, offset);
675 #endif
676                 break;
677         default:
678                 break;
679         }
680 }
681
682 int
683 rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
684 {
685         int ret = -1;
686
687         switch (p->dev->kdrv) {
688 #ifdef VFIO_PRESENT
689         case RTE_KDRV_VFIO:
690                 if (pci_vfio_is_enabled())
691                         ret = pci_vfio_ioport_unmap(p);
692                 break;
693 #endif
694         case RTE_KDRV_IGB_UIO:
695                 ret = pci_uio_ioport_unmap(p);
696                 break;
697         case RTE_KDRV_UIO_GENERIC:
698 #if defined(RTE_ARCH_X86)
699                 ret = 0;
700 #else
701                 ret = pci_uio_ioport_unmap(p);
702 #endif
703                 break;
704         case RTE_KDRV_NONE:
705 #if defined(RTE_ARCH_X86)
706                 ret = 0;
707 #endif
708                 break;
709         default:
710                 break;
711         }
712
713         return ret;
714 }
715
716 /* Init the PCI EAL subsystem */
717 int
718 rte_eal_pci_init(void)
719 {
720         /* for debug purposes, PCI can be disabled */
721         if (internal_config.no_pci)
722                 return 0;
723
724         if (rte_eal_pci_scan() < 0) {
725                 RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
726                 return -1;
727         }
728
729         return 0;
730 }