diff options
author | Damjan Marion <damarion@cisco.com> | 2017-10-05 15:32:41 +0200 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2017-12-09 14:10:17 +0000 |
commit | cef87f1a5eb4d69cf11ce1cd3c5506edcfba74c4 (patch) | |
tree | bc9ee3eb220f9c8a1fb416a45768a99b2f5be53b /src/vlib/pci | |
parent | 34719e37bf820e8398ca9159725f7f4c42764aeb (diff) |
vlib: PCI rework to support VFIO
Also fixes old ixge driver, so it works with recent physmem changes and
vfio.
Change-Id: Id4be74b34daed47cd281a77eec43d6692340d882
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/pci')
-rw-r--r-- | src/vlib/pci/pci.c | 78 | ||||
-rw-r--r-- | src/vlib/pci/pci.h | 125 |
2 files changed, 110 insertions, 93 deletions
diff --git a/src/vlib/pci/pci.c b/src/vlib/pci/pci.c index 1f1edab62e6..f50ae2d9edf 100644 --- a/src/vlib/pci/pci.c +++ b/src/vlib/pci/pci.c @@ -52,25 +52,24 @@ vlib_pci_main_t pci_main; -vlib_pci_device_t * -vlib_get_pci_device (vlib_pci_addr_t * addr) +vlib_pci_device_info_t * __attribute__ ((weak)) +vlib_pci_get_device_info (vlib_pci_addr_t * addr, clib_error_t ** error) { - vlib_pci_main_t *pm = &pci_main; - uword *p; - p = hash_get (pm->pci_dev_index_by_pci_addr, addr->as_u32); - - if (p == 0) - return 0; + if (error) + *error = clib_error_return (0, "unsupported"); + return 0; +} - return vec_elt_at_index (pm->pci_devs, p[0]); +vlib_pci_addr_t * __attribute__ ((weak)) vlib_pci_get_all_dev_addrs () +{ + return 0; } static clib_error_t * show_pci_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { - vlib_pci_main_t *pm = &pci_main; - vlib_pci_device_t *d; + vlib_pci_addr_t *addr = 0, *addrs; int show_all = 0; u8 *s = 0; @@ -87,28 +86,36 @@ show_pci_fn (vlib_main_t * vm, "Address", "Sock", "VID:PID", "Link Speed", "Driver", "Product Name", "Vital Product Data"); + addrs = vlib_pci_get_all_dev_addrs (); /* *INDENT-OFF* */ - pool_foreach (d, pm->pci_devs, ({ - - if (d->device_class != PCI_CLASS_NETWORK_ETHERNET && !show_all) - continue; - - vec_reset_length (s); - - if (d->numa_node >= 0) - s = format (s, " %d", d->numa_node); - - vlib_cli_output (vm, "%-13U%-5v%04x:%04x %-13U%-16s%-32v%U", - format_vlib_pci_addr, &d->bus_address, s, - d->vendor_id, d->device_id, - format_vlib_pci_link_speed, d, - d->driver_name ? (char *) d->driver_name : "", - d->product_name, - format_vlib_pci_vpd, d->vpd_r, 0); - })); -/* *INDENT-ON* */ + vec_foreach (addr, addrs) + { + vlib_pci_device_info_t *d; + d = vlib_pci_get_device_info (addr, 0); + + if (!d) + continue; + + if (d->device_class != PCI_CLASS_NETWORK_ETHERNET && !show_all) + continue; + + vec_reset_length (s); + if (d->numa_node >= 0) + s = format (s, " %d", d->numa_node); + + vlib_cli_output (vm, "%-13U%-5v%04x:%04x %-13U%-16s%-32v%U", + format_vlib_pci_addr, addr, s, + d->vendor_id, d->device_id, + format_vlib_pci_link_speed, d, + d->driver_name ? (char *) d->driver_name : "", + d->product_name, + format_vlib_pci_vpd, d->vpd_r, 0); + vlib_pci_free_device_info (d); + } + /* *INDENT-ON* */ vec_free (s); + vec_free (addrs); return 0; } @@ -138,16 +145,9 @@ format_vlib_pci_addr (u8 * s, va_list * va) } u8 * -format_vlib_pci_handle (u8 * s, va_list * va) -{ - vlib_pci_addr_t *addr = va_arg (*va, vlib_pci_addr_t *); - return format (s, "%x/%x/%x", addr->bus, addr->slot, addr->function); -} - -u8 * format_vlib_pci_link_speed (u8 * s, va_list * va) { - vlib_pci_device_t *d = va_arg (*va, vlib_pci_device_t *); + vlib_pci_device_info_t *d = va_arg (*va, vlib_pci_device_info_t *); pcie_config_regs_t *r = pci_config_find_capability (&d->config0, PCI_CAP_ID_PCIE); int width; @@ -250,7 +250,7 @@ VLIB_CLI_COMMAND (show_pci_command, static) = { clib_error_t * pci_bus_init (vlib_main_t * vm) { - return 0; + return vlib_call_init_function (vm, pci_bus_init); } VLIB_INIT_FUNCTION (pci_bus_init); diff --git a/src/vlib/pci/pci.h b/src/vlib/pci/pci.h index 2141080936d..e1bc4172e8b 100644 --- a/src/vlib/pci/pci.h +++ b/src/vlib/pci/pci.h @@ -43,33 +43,24 @@ #include <vlib/vlib.h> #include <vlib/pci/pci_config.h> +/* *INDENT-OFF* */ typedef CLIB_PACKED (union - { - struct - { -u16 domain; u8 bus; u8 slot: 5; u8 function:3;}; - u32 as_u32;}) vlib_pci_addr_t; - -typedef struct vlib_pci_device { - /* Operating system handle for this device. */ - uword os_handle; - - vlib_pci_addr_t bus_address; - - /* First 64 bytes of configuration space. */ - union - { - pci_config_type0_regs_t config0; - pci_config_type1_regs_t config1; - u8 config_data[256]; - }; - - /* Interrupt handler */ - void (*interrupt_handler) (struct vlib_pci_device * dev); - - /* Driver name */ - u8 *driver_name; + struct + { + u16 domain; + u8 bus; + u8 slot: 5; + u8 function:3; + }; + u32 as_u32; +}) vlib_pci_addr_t; +/* *INDENT-ON* */ + +typedef struct vlib_pci_device_info +{ + /* addr */ + vlib_pci_addr_t addr; /* Numa Node */ int numa_node; @@ -84,10 +75,42 @@ typedef struct vlib_pci_device u8 *vpd_r; u8 *vpd_w; - /* Private data */ - uword private_data; + /* Driver name */ + u8 *driver_name; + + /* First 64 bytes of configuration space. */ + union + { + pci_config_type0_regs_t config0; + pci_config_type1_regs_t config1; + u8 config_data[256]; + }; + + /* IOMMU Group */ + int iommu_group; + +} vlib_pci_device_info_t; + +typedef u32 vlib_pci_dev_handle_t; -} vlib_pci_device_t; +vlib_pci_device_info_t *vlib_pci_get_device_info (vlib_pci_addr_t * addr, + clib_error_t ** error); +vlib_pci_addr_t *vlib_pci_get_all_dev_addrs (); +vlib_pci_addr_t *vlib_pci_get_addr (vlib_pci_dev_handle_t h); +uword vlib_pci_get_private_data (vlib_pci_dev_handle_t h); +void vlib_pci_set_private_data (vlib_pci_dev_handle_t h, uword private_data); + +static inline void +vlib_pci_free_device_info (vlib_pci_device_info_t * di) +{ + if (!di) + return; + vec_free (di->product_name); + vec_free (di->vpd_r); + vec_free (di->vpd_w); + vec_free (di->driver_name); + clib_mem_free (di); +} typedef struct { @@ -97,10 +120,11 @@ typedef struct typedef struct _pci_device_registration { /* Driver init function. */ - clib_error_t *(*init_function) (vlib_main_t * vm, vlib_pci_device_t * dev); + clib_error_t *(*init_function) (vlib_main_t * vm, + vlib_pci_dev_handle_t handle); /* Interrupt handler */ - void (*interrupt_handler) (vlib_pci_device_t * dev); + void (*interrupt_handler) (vlib_pci_dev_handle_t handle); /* List of registrations */ struct _pci_device_registration *next_registration; @@ -113,9 +137,7 @@ typedef struct _pci_device_registration typedef struct { vlib_main_t *vlib_main; - vlib_pci_device_t *pci_devs; pci_device_registration_t *pci_device_registrations; - uword *pci_dev_index_by_pci_addr; } vlib_pci_main_t; extern vlib_pci_main_t pci_main; @@ -132,21 +154,21 @@ static void __vlib_add_pci_device_registration_##x (void) \ } \ __VA_ARGS__ pci_device_registration_t x -clib_error_t *vlib_pci_bind_to_uio (vlib_pci_device_t * d, +clib_error_t *vlib_pci_bind_to_uio (vlib_pci_addr_t * addr, char *uio_driver_name); /* Configuration space read/write. */ -clib_error_t *vlib_pci_read_write_config (vlib_pci_device_t * dev, +clib_error_t *vlib_pci_read_write_config (vlib_pci_dev_handle_t handle, vlib_read_or_write_t read_or_write, uword address, void *data, u32 n_bytes); #define _(t) \ static inline clib_error_t * \ -vlib_pci_read_config_##t (vlib_pci_device_t * dev, \ +vlib_pci_read_config_##t (vlib_pci_dev_handle_t h, \ uword address, t * data) \ { \ - return vlib_pci_read_write_config (dev, VLIB_READ,address, data, \ + return vlib_pci_read_write_config (h, VLIB_READ,address, data, \ sizeof (data[0])); \ } @@ -158,10 +180,10 @@ _(u8); #define _(t) \ static inline clib_error_t * \ -vlib_pci_write_config_##t (vlib_pci_device_t * dev, uword address, \ +vlib_pci_write_config_##t (vlib_pci_dev_handle_t h, uword address, \ t * data) \ { \ - return vlib_pci_read_write_config (dev, VLIB_WRITE, \ + return vlib_pci_read_write_config (h, VLIB_WRITE, \ address, data, sizeof (data[0])); \ } @@ -172,45 +194,45 @@ _(u8); #undef _ static inline clib_error_t * -vlib_pci_intr_enable (vlib_pci_device_t * dev) +vlib_pci_intr_enable (vlib_pci_dev_handle_t h) { u16 command; clib_error_t *err; - err = vlib_pci_read_config_u16 (dev, 4, &command); + err = vlib_pci_read_config_u16 (h, 4, &command); if (err) return err; command &= ~PCI_COMMAND_INTX_DISABLE; - return vlib_pci_write_config_u16 (dev, 4, &command); + return vlib_pci_write_config_u16 (h, 4, &command); } static inline clib_error_t * -vlib_pci_intr_disable (vlib_pci_device_t * dev) +vlib_pci_intr_disable (vlib_pci_dev_handle_t h) { u16 command; clib_error_t *err; - err = vlib_pci_read_config_u16 (dev, 4, &command); + err = vlib_pci_read_config_u16 (h, 4, &command); if (err) return err; command |= PCI_COMMAND_INTX_DISABLE; - return vlib_pci_write_config_u16 (dev, 4, &command); + return vlib_pci_write_config_u16 (h, 4, &command); } static inline clib_error_t * -vlib_pci_bus_master_enable (vlib_pci_device_t * dev) +vlib_pci_bus_master_enable (vlib_pci_dev_handle_t h) { clib_error_t *err; u16 command; /* Set bus master enable (BME) */ - err = vlib_pci_read_config_u16 (dev, 4, &command); + err = vlib_pci_read_config_u16 (h, 4, &command); if (err) return err; @@ -220,23 +242,18 @@ vlib_pci_bus_master_enable (vlib_pci_device_t * dev) command |= PCI_COMMAND_BUS_MASTER; - return vlib_pci_write_config_u16 (dev, 4, &command); + return vlib_pci_write_config_u16 (h, 4, &command); } -clib_error_t *vlib_pci_map_resource (vlib_pci_device_t * dev, u32 resource, +clib_error_t *vlib_pci_map_resource (vlib_pci_dev_handle_t h, u32 resource, void **result); -clib_error_t *vlib_pci_map_resource_fixed (vlib_pci_device_t * dev, +clib_error_t *vlib_pci_map_resource_fixed (vlib_pci_dev_handle_t h, u32 resource, u8 * addr, void **result); -vlib_pci_device_t *vlib_get_pci_device (vlib_pci_addr_t * addr); -/* Free's device. */ -void vlib_pci_free_device (vlib_pci_device_t * dev); - unformat_function_t unformat_vlib_pci_addr; format_function_t format_vlib_pci_addr; -format_function_t format_vlib_pci_handle; format_function_t format_vlib_pci_link_speed; format_function_t format_vlib_pci_vpd; |