summaryrefslogtreecommitdiffstats
path: root/vlib
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2016-08-23 00:53:22 +0200
committerDave Barach <openvpp@barachs.net>2016-08-23 12:46:21 +0000
commitb1b1a14977f77d9805dd2cb11c7e8ddfc404818a (patch)
tree323fa241a8b70f18599ad5f7a5cc474beb6c41c7 /vlib
parent3cd9e730f9db0d998e5e8a27ddff1da5a123625b (diff)
Fix PCI vendor_id/device_id detection for SR-IOV devices
Change-Id: I06ae392c7c8c3b4be7fd46560add442f42927c22 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'vlib')
-rw-r--r--vlib/vlib/pci/linux_pci.c26
-rw-r--r--vlib/vlib/pci/pci.c6
-rw-r--r--vlib/vlib/pci/pci.h5
3 files changed, 25 insertions, 12 deletions
diff --git a/vlib/vlib/pci/linux_pci.c b/vlib/vlib/pci/linux_pci.c
index acd913a91e7..f9ee47ac145 100644
--- a/vlib/vlib/pci/linux_pci.c
+++ b/vlib/vlib/pci/linux_pci.c
@@ -99,12 +99,9 @@ vlib_pci_bind_to_uio (vlib_pci_device_t * d, char *uio_driver_name)
DIR *dir = 0;
struct dirent *e;
int fd;
- pci_config_header_t *c;
u8 *dev_dir_name = format (0, "/sys/bus/pci/devices/%U",
format_vlib_pci_addr, &d->bus_address);
- c = &d->config0.header;
-
/* if uio sub-directory exists, we are fine, device is
already bound to UIO driver */
s = format (s, "%v/uio%c", dev_dir_name, 0);
@@ -186,7 +183,7 @@ vlib_pci_bind_to_uio (vlib_pci_device_t * d, char *uio_driver_name)
vec_reset_length (s);
s = format (s, "/sys/bus/pci/drivers/%s/new_id%c", uio_driver_name, 0);
- vlib_sysfs_write ((char *) s, "0x%04x 0x%04x", c->vendor_id, c->device_id);
+ vlib_sysfs_write ((char *) s, "0x%04x 0x%04x", d->vendor_id, d->device_id);
vec_reset_length (s);
s = format (s, "/sys/bus/pci/drivers/%s/bind%c", uio_driver_name, 0);
@@ -427,17 +424,14 @@ init_device_from_registered (vlib_main_t * vm,
vlib_pci_main_t *pm = &pci_main;
pci_device_registration_t *r;
pci_device_id_t *i;
- pci_config_header_t *c;
clib_error_t *error;
- c = &dev->config0.header;
-
r = pm->pci_device_registrations;
while (r)
{
for (i = r->supported_devices; i->vendor_id != 0; i++)
- if (i->vendor_id == c->vendor_id && i->device_id == c->device_id)
+ if (i->vendor_id == dev->vendor_id && i->device_id == dev->device_id)
{
error = vlib_pci_bind_to_uio (dev, "uio_pci_generic");
if (error)
@@ -474,6 +468,7 @@ scan_device (void *arg, u8 * dev_dir_name, u8 * ignored)
clib_error_t *error = 0;
vlib_pci_device_t *dev;
linux_pci_device_t pdev = { 0 };
+ u32 tmp;
f = format (0, "%v/config%c", dev_dir_name, 0);
fd = open ((char *) f, O_RDWR);
@@ -592,6 +587,21 @@ scan_device (void *arg, u8 * dev_dir_name, u8 * ignored)
f = format (f, "%v/numa_node%c", dev_dir_name, 0);
vlib_sysfs_read ((char *) f, "%u", &dev->numa_node);
+ vec_reset_length (f);
+ f = format (f, "%v/class%c", dev_dir_name, 0);
+ vlib_sysfs_read ((char *) f, "0x%x", &tmp);
+ dev->device_class = tmp >> 8;
+
+ vec_reset_length (f);
+ f = format (f, "%v/vendor%c", dev_dir_name, 0);
+ vlib_sysfs_read ((char *) f, "0x%x", &tmp);
+ dev->vendor_id = tmp;
+
+ vec_reset_length (f);
+ f = format (f, "%v/device%c", dev_dir_name, 0);
+ vlib_sysfs_read ((char *) f, "0x%x", &tmp);
+ dev->device_id = tmp;
+
done:
vec_free (f);
return error;
diff --git a/vlib/vlib/pci/pci.c b/vlib/vlib/pci/pci.c
index 73ae541320a..07d89fda233 100644
--- a/vlib/vlib/pci/pci.c
+++ b/vlib/vlib/pci/pci.c
@@ -58,7 +58,6 @@ show_pci_fn (vlib_main_t * vm,
{
vlib_pci_main_t *pm = &pci_main;
vlib_pci_device_t *d;
- pci_config_header_t *c;
int show_all = 0;
u8 *s = 0;
@@ -77,9 +76,8 @@ show_pci_fn (vlib_main_t * vm,
/* *INDENT-OFF* */
pool_foreach (d, pm->pci_devs, ({
- c = &d->config0.header;
- if (c->device_class != PCI_CLASS_NETWORK_ETHERNET && !show_all)
+ if (d->device_class != PCI_CLASS_NETWORK_ETHERNET && !show_all)
continue;
vec_reset_length (s);
@@ -89,7 +87,7 @@ show_pci_fn (vlib_main_t * vm,
vlib_cli_output (vm, "%-13U%-7v%04x:%04x %-15U%-20s%-40v",
format_vlib_pci_addr, &d->bus_address, s,
- c->vendor_id, c->device_id,
+ d->vendor_id, d->device_id,
format_vlib_pci_link_speed, d,
d->driver_name ? (char *) d->driver_name : "",
d->product_name);
diff --git a/vlib/vlib/pci/pci.h b/vlib/vlib/pci/pci.h
index 06e10b80e59..3b83b89208b 100644
--- a/vlib/vlib/pci/pci.h
+++ b/vlib/vlib/pci/pci.h
@@ -74,6 +74,11 @@ typedef struct vlib_pci_device
/* Numa Node */
int numa_node;
+ /* Device data */
+ u16 device_class;
+ u16 vendor_id;
+ u16 device_id;
+
/* Vital Product Data */
u8 *product_name;
u8 *vpd_r;