44 #include <sys/types.h> 48 #include <sys/ioctl.h> 50 #include <linux/ethtool.h> 51 #include <linux/sockios.h> 90 char *uio_driver_name);
102 u8 *dev_dir_name =
format (0,
"/sys/bus/pci/devices/%U",
107 s =
format (s,
"%v/uio%c", dev_dir_name, 0);
108 if (access ((
char *) s, F_OK) == 0)
114 dir = opendir (
"/sys/class/net");
120 "read /sys/class/net",
125 fd = socket (PF_INET, SOCK_DGRAM, 0);
132 while ((e = readdir (dir)))
135 struct ethtool_drvinfo drvinfo;
137 if (e->d_name[0] ==
'.')
140 memset (&ifr, 0,
sizeof ifr);
141 memset (&drvinfo, 0,
sizeof drvinfo);
142 ifr.ifr_data = (
char *) &drvinfo;
143 strncpy (ifr.ifr_name, e->d_name, IFNAMSIZ - 1);
144 drvinfo.cmd = ETHTOOL_GDRVINFO;
145 if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
148 if ((errno != ENOTSUP) && (errno != ENODEV))
154 if (strcmp ((
char *) s, drvinfo.bus_info))
157 memset (&ifr, 0,
sizeof (ifr));
158 strncpy (ifr.ifr_name, e->d_name, IFNAMSIZ - 1);
159 if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0)
167 if (ifr.ifr_flags & IFF_UP)
170 "interface %s is up",
181 s =
format (s,
"%v/driver/unbind%c", dev_dir_name, 0);
185 s =
format (s,
"/sys/bus/pci/drivers/%s/new_id%c", uio_driver_name, 0);
189 s =
format (s,
"/sys/bus/pci/drivers/%s/bind%c", uio_driver_name, 0);
220 int __attribute__ ((unused)) rv;
266 l->
uio_fd = open (uio_name, O_RDWR);
277 template.file_descriptor = l->
uio_fd;
279 template.private_data = dev - pm->
pci_devs;
304 uword address,
void *data,
u32 n_bytes)
313 n = pread (p->
config_fd, data, n_bytes, address);
315 n = pwrite (p->
config_fd, data, n_bytes, address);
331 struct stat stat_buf;
335 int flags = MAP_SHARED;
341 fd = open ((
char *) file_name, O_RDWR);
348 if (fstat (fd, &stat_buf) < 0)
359 *result = mmap (addr,
361 PROT_READ | PROT_WRITE, flags,
364 if (*result == (
void *) -1)
393 (dev->
os_handle, resource, addr, result));
413 for (
i = 0; r->supported_devices[
i].vendor_id != 0;
i++)
433 for (i = r->supported_devices; i->
vendor_id != 0; i++)
445 return r->init_function (vm, dev);
447 r = r->next_registration;
473 f =
format (0,
"%v/config%c", dev_dir_name, 0);
474 fd = open ((
char *) f, O_RDWR);
478 fd = open ((
char *) f, O_RDONLY);
504 memset (&all_ones, ~0,
sizeof (all_ones));
506 if (!memcmp (&dev->
config0.
header, &all_ones, sizeof (all_ones)))
527 if (!
unformat (&input,
"/sys/bus/pci/devices/%U",
545 f =
format (f,
"%v/vpd%c", dev_dir_name, 0);
546 fd = open ((
char *) f, O_RDONLY);
555 if (read (fd, &tag, 3) != 3)
558 if (tag[0] != 0x82 && tag[0] != 0x90 && tag[0] != 0x91)
561 len = (tag[2] << 8) | tag[1];
564 if (read (fd, data, len) != len)
571 else if (tag[0] == 0x90)
573 else if (tag[0] == 0x91)
582 f =
format (f,
"%v/driver%c", dev_dir_name, 0);
587 f =
format (f,
"%v/numa_node%c", dev_dir_name, 0);
591 f =
format (f,
"%v/class%c", dev_dir_name, 0);
596 f =
format (f,
"%v/vendor%c", dev_dir_name, 0);
601 f =
format (f,
"%v/device%c", dev_dir_name, 0);
621 ASSERT (
sizeof (vlib_pci_addr_t) ==
sizeof (
u32));
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static clib_error_t * os_map_pci_resource_internal(uword os_handle, u32 resource, u8 *addr, void **result)
format_function_t format_vlib_pci_addr
#define hash_set(h, key, value)
sll srl srl sll sra u16x4 i
static void linux_pci_device_free(linux_pci_device_t *l)
static clib_error_t * init_device(vlib_main_t *vm, vlib_pci_device_t *dev, linux_pci_device_t *pdev)
pci_config_type1_regs_t config1
pci_device_registration_t * pci_device_registrations
clib_error_t * vlib_pci_bind_to_uio(vlib_pci_device_t *d, char *uio_driver_name)
unformat_function_t unformat_vlib_pci_addr
static void add_device(vlib_pci_device_t *dev, linux_pci_device_t *pdev)
u8 * vlib_sysfs_link_to_name(char *link)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
vlib_pci_addr_t bus_address
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define clib_unix_error(format, args...)
static void pci_config_type1_little_to_host(pci_config_type1_regs_t *r)
#define VLIB_INIT_FUNCTION(x)
uword * pci_dev_index_by_pci_addr
clib_error_t * vlib_pci_map_resource_fixed(vlib_pci_device_t *dev, u32 resource, u8 *addr, void **result)
#define clib_error_return(e, args...)
struct _pci_device_registration pci_device_registration_t
clib_error_t * vlib_pci_read_write_config(vlib_pci_device_t *dev, vlib_read_or_write_t read_or_write, uword address, void *data, u32 n_bytes)
static clib_error_t * init_device_from_registered(vlib_main_t *vm, vlib_pci_device_t *dev, linux_pci_device_t *pdev)
#define vlib_call_init_function(vm, x)
static clib_error_t * linux_pci_uio_read_ready(unix_file_t *uf)
static uword unix_file_add(unix_main_t *um, unix_file_t *template)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
clib_error_t * vlib_sysfs_read(char *file_name, char *fmt,...)
vlib_pci_device_t * pci_devs
#define clib_error_return_unix(e, args...)
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
void(* interrupt_handler)(struct vlib_pci_device *dev)
static clib_error_t * vlib_pci_intr_enable(vlib_pci_device_t *dev)
clib_error_t * linux_pci_init(vlib_main_t *vm)
void vlib_pci_free_device(vlib_pci_device_t *dev)
static void pci_config_type0_little_to_host(pci_config_type0_regs_t *r)
#define vec_free(V)
Free vector's memory (no header).
pci_config_type0_regs_t config0
#define hash_create(elts, value_bytes)
#define clib_elf_section_data_next(a, extra)
static clib_error_t * scan_device(void *arg, u8 *dev_dir_name, u8 *ignored)
clib_error_t * pci_bus_init(vlib_main_t *vm)
static clib_error_t * scan_uio_dir(void *arg, u8 *path_name, u8 *file_name)
#define clib_error_report(e)
clib_error_t * vlib_pci_map_resource(vlib_pci_device_t *dev, u32 resource, void **result)
linux_pci_main_t linux_pci_main
clib_error_t * foreach_directory_file(char *dir_name, clib_error_t *(*f)(void *arg, u8 *path_name, u8 *file_name), void *arg, int scan_dirs)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define clib_unix_warning(format, args...)
pci_device_registration_t * pci_device_next_registered(pci_device_registration_t *r)
clib_error_t * vlib_sysfs_write(char *file_name, char *fmt,...)
static clib_error_t * linux_pci_uio_error_ready(unix_file_t *uf)
linux_pci_device_t * linux_pci_devices
pci_config_header_t header