X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Fbsdapp%2Feal%2Feal_pci.c;h=5457a21b6cb624324c0baf54848a1da32be476c0;hb=ff708facfcbf42f3dcb3c62d82ecd93e7b8c2506;hp=5c4d81b64fc7403f403e0c6b66351f82b1247dc4;hpb=d10296d7ea9c7e4f0da51ff2fb9c89b838e06940;p=dpdk.git diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 5c4d81b64f..5457a21b6c 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -1,13 +1,13 @@ /*- * BSD LICENSE - * + * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright @@ -17,7 +17,7 @@ * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -58,7 +58,6 @@ #include #include #include -#include #include #include #include @@ -156,10 +155,6 @@ fail: return NULL; } -#ifndef OFF_MAX -#define OFF_MAX ((uint64_t)(off_t)-1) -#endif - static int pci_uio_map_secondary(struct rte_pci_device *dev) { @@ -187,7 +182,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev) } RTE_LOG(ERR, EAL, "Cannot find resource for device\n"); - return -1; + return 1; } /* map the PCI resource of a PCI device in virtual memory */ @@ -211,13 +206,13 @@ pci_uio_map_resource(struct rte_pci_device *dev) if (rte_eal_process_type() != RTE_PROC_PRIMARY) return (pci_uio_map_secondary(dev)); - rte_snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u", + snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u", dev->addr.bus, dev->addr.devid, dev->addr.function); if (access(devname, O_RDWR) < 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; + return 1; } /* save fd if in primary process */ @@ -236,7 +231,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) return (-1); } - rte_snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname); + snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname); memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr)); @@ -274,23 +269,6 @@ pci_uio_map_resource(struct rte_pci_device *dev) return (0); } -/* parse the "resource" sysfs file */ -#define IORESOURCE_MEM 0x00000200 - -/* Compare two PCI device addresses. */ -static int -pci_addr_comparison(struct rte_pci_addr *addr, struct rte_pci_addr *addr2) -{ - uint64_t dev_addr = (addr->domain << 24) + (addr->bus << 16) + (addr->devid << 8) + addr->function; - uint64_t dev_addr2 = (addr2->domain << 24) + (addr2->bus << 16) + (addr2->devid << 8) + addr2->function; - - if (dev_addr > dev_addr2) - return 1; - else - return 0; -} - - /* Scan one pci sysfs entry, and fill the devices list from it. */ static int pci_scan_one(int dev_pci_fd, struct pci_conf *conf) @@ -360,21 +338,32 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) /* device is valid, add in list (sorted) */ if (TAILQ_EMPTY(&pci_device_list)) { TAILQ_INSERT_TAIL(&pci_device_list, dev, next); - } + } else { struct rte_pci_device *dev2 = NULL; + int ret; TAILQ_FOREACH(dev2, &pci_device_list, next) { - if (pci_addr_comparison(&dev->addr, &dev2->addr)) + ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr); + if (ret > 0) continue; - else { + else if (ret < 0) { TAILQ_INSERT_BEFORE(dev2, dev, next); return 0; + } else { /* already registered */ + /* update pt_driver */ + dev2->pt_driver = dev->pt_driver; + dev2->max_vfs = dev->max_vfs; + memmove(dev2->mem_resource, + dev->mem_resource, + sizeof(dev->mem_resource)); + free(dev); + return 0; } } TAILQ_INSERT_TAIL(&pci_device_list, dev, next); } - + return 0; skipdev: @@ -389,7 +378,7 @@ skipdev: static int pci_scan(void) { - int fd = -1; + int fd; unsigned dev_count = 0; struct pci_conf matches[16]; struct pci_conf_io conf_io = { @@ -440,6 +429,7 @@ int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) { struct rte_pci_id *id_table; + int ret; for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) { @@ -474,10 +464,11 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d return 0; } - if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) { + if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { /* map resources for devices that use igb_uio */ - if (pci_uio_map_resource(dev) < 0) - return -1; + ret = pci_uio_map_resource(dev); + if (ret != 0) + return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && rte_eal_process_type() == RTE_PROC_PRIMARY) { /* unbind current driver */ @@ -501,7 +492,7 @@ rte_eal_pci_init(void) { TAILQ_INIT(&pci_driver_list); TAILQ_INIT(&pci_device_list); - uio_res_list = RTE_TAILQ_RESERVE_BY_IDX(RTE_TAILQ_PCI, uio_res_list); + uio_res_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_PCI, uio_res_list); /* for debug purposes, PCI can be disabled */ if (internal_config.no_pci)