Skip to content

Commit

Permalink
- Updating dpdk_iface.ko module which now supports dynamic allocation…
Browse files Browse the repository at this point in the history
… of major numbers.
  • Loading branch information
ajamshed committed Oct 2, 2018
1 parent 80e2742 commit 2d308b5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
9 changes: 7 additions & 2 deletions dpdk-iface-kmod/dpdk_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -256,14 +257,18 @@ iface_pci_init_module(void)

printk(KERN_INFO "%s: Loaded\n",
THIS_MODULE->name);

/* record major number */
major_no = ret;

return 0;
}
/*--------------------------------------------------------------------------*/
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);
Expand Down
6 changes: 3 additions & 3 deletions dpdk-iface-kmod/dpdk_iface_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__ */
53 changes: 47 additions & 6 deletions dpdk-iface-kmod/dpdk_iface_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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...");
Expand Down

0 comments on commit 2d308b5

Please sign in to comment.