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