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