- Updating dpdk_iface.ko module which now supports dynamic allocation of major numbers.
parent
80e2742464
commit
2d308b5886
|
@ -33,6 +33,7 @@
|
|||
/*--------------------------------------------------------------------------*/
|
||||
struct stats_struct sarrays[MAX_DEVICES][MAX_QID] = {{{0, 0, 0, 0, 0, 0, 0, 0, 0}}};
|
||||
struct stats_struct old_sarrays[MAX_DEVICES][MAX_QID] = {{{0, 0, 0, 0, 0, 0, 0, 0, 0}}};
|
||||
static int major_no = -1;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int
|
||||
update_stats(struct stats_struct *stats)
|
||||
|
@ -245,7 +246,7 @@ iface_pci_init_module(void)
|
|||
{
|
||||
int ret;
|
||||
|
||||
ret = register_chrdev(MAJOR_NO /* MAJOR */,
|
||||
ret = register_chrdev(0, /* MAJOR */,
|
||||
DEV_NAME /*NAME*/,
|
||||
&igb_net_fops);
|
||||
if (ret < 0) {
|
||||
|
@ -256,6 +257,10 @@ iface_pci_init_module(void)
|
|||
|
||||
printk(KERN_INFO "%s: Loaded\n",
|
||||
THIS_MODULE->name);
|
||||
|
||||
/* record major number */
|
||||
major_no = ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
@ -263,7 +268,7 @@ static void __exit
|
|||
iface_pci_exit_module(void)
|
||||
{
|
||||
clear_all_netdevices();
|
||||
unregister_chrdev(MAJOR_NO, DEV_NAME);
|
||||
unregister_chrdev(major_no, DEV_NAME);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
module_init(iface_pci_init_module);
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
#ifndef __KERNEL__
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include <asm/bitsperlong.h>
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* major number */
|
||||
#define MAJOR_NO 511 //1110
|
||||
/* dev name */
|
||||
#define DEV_NAME "dpdk-iface"
|
||||
#define DEV_PATH "/dev/"DEV_NAME
|
||||
#define DEV_PROC_PATH "/proc/devices"
|
||||
/* ioctl# */
|
||||
#define SEND_STATS 0
|
||||
#define CREATE_IFACE 1
|
||||
|
@ -40,6 +40,6 @@ typedef struct PciDevice {
|
|||
char ifname[IFNAMSIZ];
|
||||
};
|
||||
PciAddress pa;
|
||||
} PciDevice __attribute__((aligned(64)));
|
||||
} PciDevice __attribute__((aligned(__BITS_PER_LONG)));
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#endif /* __DPDK_IFACE_COMMON_H__ */
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
#include <rte_ethdev.h>
|
||||
#include "dpdk_iface_common.h"
|
||||
/*--------------------------------------------------------------------------*/
|
||||
//#define DEBUG 1
|
||||
#define SYSFS_PCI_DRIVER_PATH "/sys/bus/pci/drivers/"
|
||||
#define SYSFS_PCI_IGB_UIO SYSFS_PCI_DRIVER_PATH"igb_uio"
|
||||
#define SYSFS_PCI_VFIO_PCI SYSFS_PCI_DRIVER_PATH"vfio-pci"
|
||||
#define SYSFS_PCI_UIOPCIGEN SYSFS_PCI_DRIVER_PATH"uio_pci_generic"
|
||||
#define RTE_ARGC_MAX (RTE_MAX_ETHPORTS << 1) + 7
|
||||
//#define DEBUG 1
|
||||
#define SYSFS_PCI_DRIVER_PATH "/sys/bus/pci/drivers/"
|
||||
#define SYSFS_PCI_IGB_UIO SYSFS_PCI_DRIVER_PATH"igb_uio"
|
||||
#define SYSFS_PCI_VFIO_PCI SYSFS_PCI_DRIVER_PATH"vfio-pci"
|
||||
#define SYSFS_PCI_UIOPCIGEN SYSFS_PCI_DRIVER_PATH"uio_pci_generic"
|
||||
#define RTE_ARGC_MAX (RTE_MAX_ETHPORTS << 1) + 7
|
||||
/*--------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
PciDevice pd;
|
||||
|
@ -144,6 +144,43 @@ probe_all_rte_devices(char **argv, int *argc)
|
|||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int
|
||||
fetch_major_no()
|
||||
{
|
||||
FILE *f;
|
||||
int major_no;
|
||||
char *line;
|
||||
size_t len;
|
||||
char dummy[512];
|
||||
|
||||
major_no = -1;
|
||||
len = 0;
|
||||
line = NULL;
|
||||
|
||||
f = fopen(DEV_PROC_PATH, "r");
|
||||
if (f == NULL) {
|
||||
fprintf(stderr, "Can't open %s file\n", DEV_PROC_PATH);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (getline(&line, &len, f) != -1) {
|
||||
if (strstr(line, DEV_NAME) != NULL) {
|
||||
if (sscanf(line, "%d %s", &major_no, dummy) == 2) {
|
||||
free(line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
line = NULL;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
/* close the file descriptor */
|
||||
fclose(f);
|
||||
|
||||
return major_no;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int ret, fd, num_devices, i;
|
||||
|
@ -183,7 +220,11 @@ main(int argc, char **argv)
|
|||
"\033[32m not present. \033[0m \n");
|
||||
|
||||
/* create dpdk-iface device node entry */
|
||||
#if 0
|
||||
dev = makedev(MAJOR_NO, 0);
|
||||
#else
|
||||
dev = makedev(fetch_major_no(), 0);
|
||||
#endif
|
||||
ret = mknod(DEV_PATH, S_IFCHR | O_RDWR, dev);
|
||||
if (ret == 0)
|
||||
fprintf(stderr, "Creating device node entry...");
|
||||
|
|
Loading…
Reference in New Issue