X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Flinuxapp%2Feal%2Feal_pci.c;h=9538efee0e3e10095b8fb725fec0dcb2c2b591bf;hb=2ef79b212a79e87afd16fd75376c1e0d49ca2942;hp=2adc0fc952338f8c810cc0d31bf25fd78313130c;hpb=1c1d4d7a923d4804f1926fc5264f9ecdd8977b04;p=dpdk.git diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 2adc0fc952..9538efee0e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2013 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,7 +64,9 @@ #include #include #include +#include +#include "rte_pci_dev_ids.h" #include "eal_filesystem.h" #include "eal_private.h" @@ -459,44 +461,74 @@ pci_uio_map_secondary(struct rte_pci_device *dev) return -1; } -/* map the PCI resource of a PCI device in virtual memory */ -static int -pci_uio_map_resource(struct rte_pci_device *dev) +static int pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num) { - int i, j; + FILE *f; + char filename[PATH_MAX]; + int ret; + unsigned major, minor; + dev_t dev; + + /* get the name of the sysfs file that contains the major and minor + * of the uio device and read its content */ + rte_snprintf(filename, sizeof(filename), "%s/dev", sysfs_uio_path); + + f = fopen(filename, "r"); + if (f == NULL) { + RTE_LOG(ERR, EAL, "%s(): cannot open sysfs to get major:minor\n", + __func__); + return -1; + } + + ret = fscanf(f, "%d:%d", &major, &minor); + if (ret != 2) { + RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs to get major:minor\n", + __func__); + fclose(f); + return -1; + } + fclose(f); + + /* create the char device "mknod /dev/uioX c major minor" */ + rte_snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num); + dev = makedev(major, minor); + ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev); + if (f == NULL) { + RTE_LOG(ERR, EAL, "%s(): mknod() failed %s\n", + __func__, strerror(errno)); + return -1; + } + + return ret; +} + +/* + * Return the uioX char device used for a pci device. On success, return + * the UIO number and fill dstbuf string with the path of the device in + * sysfs. On error, return a negative value. In this case dstbuf is + * invalid. + */ +static int pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf, + unsigned int buflen) +{ + struct rte_pci_addr *loc = &dev->addr; + unsigned int uio_num; struct dirent *e; DIR *dir; char dirname[PATH_MAX]; - char dirname2[PATH_MAX]; - char devname[PATH_MAX]; /* contains the /dev/uioX */ - void *mapaddr; - unsigned uio_num; - uint64_t phaddr; - uint64_t offset; - uint64_t pagesz; - ssize_t nb_maps; - struct rte_pci_addr *loc = &dev->addr; - struct uio_resource *uio_res; - struct uio_map *maps; - - dev->intr_handle.fd = -1; - - /* secondary processes - use already recorded details */ - if (rte_eal_process_type() != RTE_PROC_PRIMARY) - return (pci_uio_map_secondary(dev)); /* depending on kernel version, uio can be located in uio/uioX * or uio:uioX */ rte_snprintf(dirname, sizeof(dirname), - "/sys/bus/pci/devices/" PCI_PRI_FMT "/uio", + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio", loc->domain, loc->bus, loc->devid, loc->function); dir = opendir(dirname); if (dir == NULL) { /* retry with the parent directory */ rte_snprintf(dirname, sizeof(dirname), - "/sys/bus/pci/devices/" PCI_PRI_FMT, + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT, loc->domain, loc->bus, loc->devid, loc->function); dir = opendir(dirname); @@ -520,43 +552,104 @@ pci_uio_map_resource(struct rte_pci_device *dev) /* first try uio%d */ errno = 0; uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10); - if (errno == 0 && endptr != e->d_name) { - rte_snprintf(dirname2, sizeof(dirname2), - "%s/uio%u", dirname, uio_num); + if (errno == 0 && endptr != (e->d_name + shortprefix_len)) { + rte_snprintf(dstbuf, buflen, "%s/uio%u", dirname, uio_num); break; } /* then try uio:uio%d */ errno = 0; uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10); - if (errno == 0 && endptr != e->d_name) { - rte_snprintf(dirname2, sizeof(dirname2), - "%s/uio:uio%u", dirname, uio_num); + if (errno == 0 && endptr != (e->d_name + longprefix_len)) { + rte_snprintf(dstbuf, buflen, "%s/uio:uio%u", dirname, uio_num); break; } } closedir(dir); /* No uio resource found */ - if (e == NULL) { + if (e == NULL) + return -1; + + /* create uio device if we've been asked to */ + if (internal_config.create_uio_dev && pci_mknod_uio_dev(dstbuf, uio_num) < 0) + RTE_LOG(WARNING, EAL, "Cannot create /dev/uio%u\n", uio_num); + + return uio_num; +} + +/* map the PCI resource of a PCI device in virtual memory */ +static int +pci_uio_map_resource(struct rte_pci_device *dev) +{ + int i, j; + char dirname[PATH_MAX]; + char filename[PATH_MAX]; + char devname[PATH_MAX]; /* contains the /dev/uioX */ + void *mapaddr; + int uio_num; + unsigned long start,size; + uint64_t phaddr; + uint64_t offset; + uint64_t pagesz; + ssize_t nb_maps; + struct rte_pci_addr *loc = &dev->addr; + struct uio_resource *uio_res; + struct uio_map *maps; + + dev->intr_handle.fd = -1; + + /* secondary processes - use already recorded details */ + if ((rte_eal_process_type() != RTE_PROC_PRIMARY) && + (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET)) + return (pci_uio_map_secondary(dev)); + + /* find uio resource */ + uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname)); + if (uio_num < 0) { RTE_LOG(WARNING, EAL, " "PCI_PRI_FMT" not managed by UIO driver, " "skipping\n", loc->domain, loc->bus, loc->devid, loc->function); return -1; } + if(dev->id.vendor_id == PCI_VENDOR_ID_QUMRANET) { + /* get portio size */ + rte_snprintf(filename, sizeof(filename), + "%s/portio/port0/size", dirname); + if (eal_parse_sysfs_value(filename, &size) < 0) { + RTE_LOG(ERR, EAL, "%s(): cannot parse size\n", + __func__); + return -1; + } + + /* get portio start */ + rte_snprintf(filename, sizeof(filename), + "%s/portio/port0/start", dirname); + if (eal_parse_sysfs_value(filename, &start) < 0) { + RTE_LOG(ERR, EAL, "%s(): cannot parse portio start\n", + __func__); + return -1; + } + dev->mem_resource[0].addr = (void *)(uintptr_t)start; + dev->mem_resource[0].len = (uint64_t)size; + RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%lx with size=0x%lx\n", start, size); + /* rte_virtio_pmd does not need any other bar even if available */ + return (0); + } + /* allocate the mapping details for secondary processes*/ if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) { RTE_LOG(ERR, EAL, "%s(): cannot store uio mmap details\n", __func__); return (-1); } - + rte_snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num); rte_snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname); memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr)); - + /* collect info about device mappings */ - if ((nb_maps = pci_uio_get_mappings(dirname2, uio_res->maps, + if ((nb_maps = pci_uio_get_mappings(dirname, uio_res->maps, sizeof (uio_res->maps) / sizeof (uio_res->maps[0]))) < 0) return (nb_maps); @@ -796,13 +889,13 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, } /* device is valid, add in list (sorted) */ - if (TAILQ_EMPTY(&device_list)) { - TAILQ_INSERT_TAIL(&device_list, dev, next); + if (TAILQ_EMPTY(&pci_device_list)) { + TAILQ_INSERT_TAIL(&pci_device_list, dev, next); } else { struct rte_pci_device *dev2 = NULL; - TAILQ_FOREACH(dev2, &device_list, next) { + TAILQ_FOREACH(dev2, &pci_device_list, next) { if (pci_addr_comparison(&dev->addr, &dev2->addr)) continue; else { @@ -810,7 +903,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, return 0; } } - TAILQ_INSERT_TAIL(&device_list, dev, next); + TAILQ_INSERT_TAIL(&pci_device_list, dev, next); } return 0; @@ -912,13 +1005,6 @@ int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) { struct rte_pci_id *id_table; -#ifdef RTE_EAL_UNBIND_PORTS - const char *module_name = NULL; - int uio_status = -1; - - if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) - module_name = IGB_UIO_NAME; -#endif for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) { @@ -946,31 +1032,30 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d dev->id.device_id, dr->name); /* no initialization when blacklisted, return without error */ - if (dev->blacklisted) { + if (dev->devargs != NULL && + dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) { RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n"); return 0; } #ifdef RTE_EAL_UNBIND_PORTS - /* Unbind PCI devices if needed */ - if (module_name != NULL) - if (pci_switch_module(dr, dev, uio_status, module_name) < 0) + if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) { + /* unbind driver and load uio resources for Intel NICs */ + if (pci_switch_module(dr, dev, 1, IGB_UIO_NAME) < 0) return -1; + } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && + rte_eal_process_type() == RTE_PROC_PRIMARY) { + /* unbind current driver */ + if (pci_unbind_kernel_driver(dev) < 0) + return -1; + } #else - /* just map the NIC resources */ - if (pci_uio_map_resource(dev) < 0) - return -1; + if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) + /* just map resources for Intel NICs */ + if (pci_uio_map_resource(dev) < 0) + return -1; #endif - /* We always should have BAR0 mapped */ - if (rte_eal_process_type() == RTE_PROC_PRIMARY && - dev->mem_resource[0].addr == NULL) { - RTE_LOG(ERR, EAL, - "%s(): BAR0 is not mapped\n", - __func__); - return (-1); - } - /* reference driver structure */ dev->driver = dr; @@ -985,8 +1070,8 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d int rte_eal_pci_init(void) { - TAILQ_INIT(&driver_list); - TAILQ_INIT(&device_list); + TAILQ_INIT(&pci_driver_list); + TAILQ_INIT(&pci_device_list); uio_res_list = RTE_TAILQ_RESERVE_BY_IDX(RTE_TAILQ_PCI, uio_res_list); /* for debug purposes, PCI can be disabled */