X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Fbsdapp%2Fnic_uio%2Fnic_uio.c;h=4bd7545a55a2d8a52f325927ff6cc6f32e5d4433;hb=a4f0a2dbe5abc2cadf0300fb4d5767b66254035d;hp=ce97dfcf680268da6c96c6d9b9ade608c3b94792;hpb=764bf26873b95761ac3bd4b98251d3c497c65a90;p=dpdk.git diff --git a/lib/librte_eal/bsdapp/nic_uio/nic_uio.c b/lib/librte_eal/bsdapp/nic_uio/nic_uio.c index ce97dfcf68..4bd7545a55 100644 --- a/lib/librte_eal/bsdapp/nic_uio/nic_uio.c +++ b/lib/librte_eal/bsdapp/nic_uio/nic_uio.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 @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include /* structs, prototypes for pci bus stuff and DEVMETHOD */ #include #include +#include #include #include @@ -54,6 +55,9 @@ __FBSDID("$FreeBSD$"); #define MAX_BARS (PCIR_MAX_BAR_0 + 1) +#define MAX_DETACHED_DEVICES 128 +static device_t detached_devices[MAX_DETACHED_DEVICES] = {}; +static int num_detached = 0; struct nic_uio_softc { device_t dev_t; @@ -102,20 +106,6 @@ struct pci_bdf { uint32_t function; }; - -#define RTE_PCI_DEV_ID_DECL_EM(vend, dev) {vend, dev}, -#define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {vend, dev}, -#define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {vend, dev}, -#define RTE_PCI_DEV_ID_DECL_IXGBE(vend, dev) {vend, dev}, -#define RTE_PCI_DEV_ID_DECL_IXGBEVF(vend, dev) {vend, dev}, -#define RTE_PCI_DEV_ID_DECL_VIRTIO(vend, dev) {vend, dev}, - -const struct device devices[] = { -#include -}; -#define NUM_DEVICES (sizeof(devices)/sizeof(devices[0])) - - static devclass_t nic_uio_devclass; DEFINE_CLASS_0(nic_uio, nic_uio_driver, nic_uio_methods, sizeof(struct nic_uio_softc)); @@ -126,7 +116,7 @@ nic_uio_mmap(struct cdev *cdev, vm_ooffset_t offset, vm_paddr_t *paddr, int prot, vm_memattr_t *memattr) { *paddr = offset; - return (0); + return 0; } static int @@ -171,13 +161,13 @@ nic_uio_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t size, int -nic_uio_open(struct cdev *dev, int oflags, int devtype, d_thread_t *td) +nic_uio_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { return 0; } int -nic_uio_close(struct cdev *dev, int fflag, int devtype, d_thread_t *td) +nic_uio_close(struct cdev *dev, int fflag, int devtype, struct thread *td) { return 0; } @@ -186,16 +176,62 @@ static int nic_uio_probe (device_t dev) { int i; + unsigned int bus = pci_get_bus(dev); + unsigned int device = pci_get_slot(dev); + unsigned int function = pci_get_function(dev); - for (i = 0; i < NUM_DEVICES; i++) - if (pci_get_vendor(dev) == devices[i].vend && - pci_get_device(dev) == devices[i].dev) { + char bdf_str[256]; + char *token, *remaining; + + /* First check if we found this on load */ + for (i = 0; i < num_detached; i++) + if (bus == pci_get_bus(detached_devices[i]) && + device == pci_get_slot(detached_devices[i]) && + function == pci_get_function(detached_devices[i])) { + device_set_desc(dev, "DPDK PCI Device"); + return BUS_PROBE_SPECIFIC; + } + + /* otherwise check if it's a new device and if it matches the BDF */ + memset(bdf_str, 0, sizeof(bdf_str)); + TUNABLE_STR_FETCH("hw.nic_uio.bdfs", bdf_str, sizeof(bdf_str)); + remaining = bdf_str; + while (1) { + if (remaining == NULL || remaining[0] == '\0') + break; + token = strsep(&remaining, ",:"); + if (token == NULL) + break; + bus = strtol(token, NULL, 10); + token = strsep(&remaining, ",:"); + if (token == NULL) + break; + device = strtol(token, NULL, 10); + token = strsep(&remaining, ",:"); + if (token == NULL) + break; + function = strtol(token, NULL, 10); - device_set_desc(dev, "Intel(R) DPDK PCI Device"); - return (BUS_PROBE_SPECIFIC); + if (bus == pci_get_bus(dev) && + device == pci_get_slot(dev) && + function == pci_get_function(dev)) { + + if (num_detached < MAX_DETACHED_DEVICES) { + printf("%s: probed dev=%p\n", + __func__, dev); + detached_devices[num_detached++] = dev; + device_set_desc(dev, "DPDK PCI Device"); + return BUS_PROBE_SPECIFIC; + } else { + printf("%s: reached MAX_DETACHED_DEVICES=%d. dev=%p won't be reattached\n", + __func__, MAX_DETACHED_DEVICES, + dev); + break; + } } + } - return (ENXIO); + return ENXIO; } static int @@ -234,7 +270,7 @@ nic_uio_detach(device_t dev) if (PCI_BAR_IO(pci_read_config(dev, sc->bar_id[i], 4))) bus_release_resource(dev, SYS_RES_IOPORT, sc->bar_id[i], sc->bar_res[i]); - else + else bus_release_resource(dev, SYS_RES_MEMORY, sc->bar_id[i], sc->bar_res[i]); } @@ -248,7 +284,6 @@ static void nic_uio_load(void) { uint32_t bus, device, function; - int i; device_t dev; char bdf_str[256]; char *token, *remaining; @@ -256,6 +291,7 @@ nic_uio_load(void) memset(bdf_str, 0, sizeof(bdf_str)); TUNABLE_STR_FETCH("hw.nic_uio.bdfs", bdf_str, sizeof(bdf_str)); remaining = bdf_str; + printf("nic_uio: hw.nic_uio.bdfs = '%s'\n", bdf_str); /* * Users should specify PCI BDFs in the format "b:d:f,b:d:f,b:d:f". * But the code below does not try differentiate between : and , @@ -284,23 +320,41 @@ nic_uio_load(void) function = strtol(token, NULL, 10); dev = pci_find_bsf(bus, device, function); - if (dev != NULL) - for (i = 0; i < NUM_DEVICES; i++) - if (pci_get_vendor(dev) == devices[i].vend && - pci_get_device(dev) == devices[i].dev) - device_detach(dev); + if (dev == NULL) + continue; + + if (num_detached < MAX_DETACHED_DEVICES) { + printf("nic_uio_load: detaching and storing dev=%p\n", + dev); + detached_devices[num_detached++] = dev; + } else { + printf("nic_uio_load: reached MAX_DETACHED_DEVICES=%d. dev=%p won't be reattached\n", + MAX_DETACHED_DEVICES, dev); + } + device_detach(dev); } } static void nic_uio_unload(void) { + int i; + printf("nic_uio_unload: entered...\n"); + + for (i = 0; i < num_detached; i++) { + printf("nic_uio_unload: calling to device_probe_and_attach for dev=%p...\n", + detached_devices[i]); + device_probe_and_attach(detached_devices[i]); + printf("nic_uio_unload: done.\n"); + } + + printf("nic_uio_unload: leaving...\n"); } static int nic_uio_shutdown(void) { - return (0); + return 0; } static int @@ -321,5 +375,5 @@ nic_uio_modevent(module_t mod, int type, void *arg) break; } - return (0); + return 0; }