45 #include <sys/types.h> 49 #include <sys/ioctl.h> 51 #include <linux/ethtool.h> 52 #include <linux/sockios.h> 66 u8 * dev_dir_name =
format(0,
"/sys/bus/pci/devices/%U",
73 s =
format (s,
"%v/uio%c", dev_dir_name, 0);
74 if (access ( (
char *) s, F_OK) == 0)
80 dir = opendir (
"/sys/class/net");
86 "read /sys/class/net",
91 fd = socket(PF_INET, SOCK_DGRAM, 0);
93 while((e = readdir (dir)))
96 struct ethtool_drvinfo drvinfo;
98 if (e->d_name[0] ==
'.')
101 memset(&ifr, 0,
sizeof ifr);
102 memset(&drvinfo, 0,
sizeof drvinfo);
103 ifr.ifr_data = (
char *) &drvinfo;
104 strncpy(ifr.ifr_name, e->d_name, IFNAMSIZ);
105 drvinfo.cmd = ETHTOOL_GDRVINFO;
106 ioctl (fd, SIOCETHTOOL, &ifr);
108 if (strcmp ((
char *) s, drvinfo.bus_info))
111 memset (&ifr, 0,
sizeof(ifr));
112 strncpy (ifr.ifr_name, e->d_name, IFNAMSIZ);
113 ioctl (fd, SIOCGIFFLAGS, &ifr);
116 if (ifr.ifr_flags & IFF_UP)
119 "interface %s is up",
129 s =
format (s,
"%v/driver/unbind%c", dev_dir_name, 0);
133 s =
format (s,
"/sys/bus/pci/drivers/%s/new_id%c", uio_driver_name, 0);
137 s =
format (s,
"/sys/bus/pci/drivers/%s/bind%c", uio_driver_name, 0);
200 if (stat ((
char *) file_name, &b) >= 0)
207 u32 reg_offset,
u32 reg_value)
218 error =
write_sys_fs (file_name,
"%x %x", reg_offset, reg_value);
241 error =
write_sys_fs (
"/sys/bus/pci/drivers/uio_pci_dma/new_id",
245 error =
write_sys_fs (
"/sys/bus/pci/drivers/uio_pci_dma/bind",
246 "%04x:%02x:%02x.%x", x[0], x[1], x[2], x[3]);
258 char * uio_name = (
char *)
format (0,
"/dev/uio%d%c", l->
uio_minor, 0);
259 l->
uio_fd = open (uio_name, O_RDWR);
270 template.file_descriptor = l->
uio_fd;
310 if (address != lseek (p->
config_fd, address, SEEK_SET))
334 struct stat stat_buf;
338 int flags = MAP_SHARED;
344 fd = open ((
char *) file_name, O_RDWR);
351 if (fstat (fd, &stat_buf) < 0)
362 *result = mmap (addr,
364 PROT_READ | PROT_WRITE,
368 if (*result == (
void *) -1)
429 for (
i = 0; r->supported_devices[
i].vendor_id != 0;
i++)
440 link_name =
format (0,
"/sys/bus/pci/drivers/%s", r->kernel_driver);
441 if (stat ((
char *)link_name, &b) >= 0)
442 r->kernel_driver_running++;
444 r->kernel_driver_running=0;
447 return r->kernel_driver_running;
466 for (i = r->supported_devices; i->
vendor_id != 0; i++)
471 if (r->kernel_driver_running == 1)
474 "\tUninstall the associated linux kernel " 475 "driver: sudo rmmod %s",
481 return r->init_function (vm, dev);
483 r = r->next_registration;
509 f =
format (0,
"%v/config%c", dev_dir_name, 0);
510 fd = open ((
char *) f, O_RDWR);
514 fd = open ((
char *) f, O_RDONLY);
537 memset (&all_ones, ~0,
sizeof (all_ones));
539 if (! memcmp (&dev->
config0.
header, &all_ones, sizeof (all_ones)))
559 if (!
unformat (&input,
"/sys/bus/pci/devices/%U",
592 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) ...
pci_device_registration_t * pci_device_registrations
#define hash_set(h, key, value)
sll srl srl sll sra u16x4 i
static u8 * format_vlib_pci_addr(u8 *s, va_list *va)
clib_error_t * pci_bus_init(vlib_main_t *vm)
static clib_error_t * init_device(vlib_main_t *vm, vlib_pci_device_t *dev, linux_pci_device_t *pdev)
always_inline uword unix_file_add(unix_main_t *um, unix_file_t *template)
always_inline void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
#define clib_error_report(e)
static clib_error_t * scan_uio_dir(void *arg, u8 *path_name, u8 *file_name)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vlib_pci_addr_t bus_address
static clib_error_t * init_device_from_registered(vlib_main_t *vm, vlib_pci_device_t *dev, linux_pci_device_t *pdev)
#define VLIB_INIT_FUNCTION(x)
vlib_pci_addr_t bus_address
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)
u32 device_input_node_index
clib_error_t * vlib_pci_bind_to_uio(vlib_pci_device_t *d, char *uio_driver_name)
#define clib_warning(format, args...)
#define vlib_call_init_function(vm, x)
static void linux_pci_device_free(linux_pci_device_t *l)
always_inline void pci_config_type1_little_to_host(pci_config_type1_regs_t *r)
#define pool_elt_at_index(p, i)
static u8 kernel_driver_installed(pci_device_registration_t *r)
uword * pci_dev_index_by_pci_addr
vlib_pci_device_t * pci_devs
static clib_error_t * os_map_pci_resource_internal(uword os_handle, u32 resource, u8 *addr, void **result)
#define clib_error_return_unix(e, args...)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
clib_error_t * os_read_write_pci_config(uword os_handle, vlib_read_or_write_t read_or_write, uword address, void *data, u32 n_bytes)
static clib_error_t * linux_pci_uio_error_ready(unix_file_t *uf)
linux_pci_main_t linux_pci_main
clib_error_t * os_map_pci_resource_fixed(uword os_handle, u32 resource, u8 *addr, void **result)
#define vec_free(V)
Free vector's memory (no header).
#define clib_error_free(e)
#define hash_create(elts, value_bytes)
#define clib_elf_section_data_next(a, extra)
void os_add_pci_disable_interrupts_reg(uword os_handle, u32 resource, u32 reg_offset, u32 reg_value)
pci_config_type1_regs_t config1
static uword unformat_vlib_pci_addr(unformat_input_t *input, va_list *args)
#define clib_unix_error(format, args...)
static clib_error_t * scan_device(void *arg, u8 *dev_dir_name, u8 *ignored)
pci_config_type0_regs_t config0
clib_error_t * write_sys_fs(char *file_name, char *fmt,...)
u8 * format_os_pci_handle(u8 *s, va_list *va)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void os_free_pci_device(uword os_handle)
static uword pci_resource_size(uword os_handle, uword resource)
struct _pci_device_registration pci_device_registration_t
clib_error_t * os_map_pci_resource(uword os_handle, u32 resource, void **result)
static clib_error_t * linux_pci_uio_read_ready(unix_file_t *uf)
always_inline vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
#define clib_error_return(e, args...)
always_inline void pci_config_type0_little_to_host(pci_config_type0_regs_t *r)
pci_device_registration_t * pci_device_next_registered(pci_device_registration_t *r)
linux_pci_device_t * linux_pci_devices
uword runtime_data[(128-1 *sizeof(vlib_node_function_t *)-1 *sizeof(vlib_error_t *)-11 *sizeof(u32)-5 *sizeof(u16))/sizeof(uword)]
pci_config_header_t header
static void add_device(vlib_pci_device_t *dev, linux_pci_device_t *pdev)