-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1338 from ghaerr/eth
[kernel] First pass at allowing multiple NIC device drivers in kernel
- Loading branch information
Showing
11 changed files
with
168 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* ELKS Ethernet char device driver | ||
* June 2022 Greg Haerr | ||
*/ | ||
|
||
#include <linuxmt/init.h> | ||
#include <linuxmt/major.h> | ||
#include <linuxmt/errno.h> | ||
#include <linuxmt/kernel.h> | ||
#include <linuxmt/sched.h> | ||
|
||
/* character devices and their minor numbers */ | ||
extern struct file_operations ne2k_fops; /* 0 CONFIG_ETH_NE2K */ | ||
extern struct file_operations wd_fops; /* 1 CONFIG_ETH_WD */ | ||
extern struct file_operations el3_fops; /* 2 CONFIG_ETH_EL3 */ | ||
|
||
#define MAX_ETHS 3 | ||
|
||
struct eth { | ||
struct file_operations *ops; | ||
}; | ||
static struct eth eths[MAX_ETHS]; | ||
|
||
/* return file_operations pointer from minor number */ | ||
static struct file_operations *get_ops(dev_t dev) | ||
{ | ||
struct eth *eth = ðs[0]; | ||
unsigned short minor = MINOR(dev); | ||
|
||
do { | ||
if ((eth - eths) == minor) | ||
return eth->ops; | ||
} while (++eth < ðs[MAX_ETHS]); | ||
|
||
return NULL; | ||
} | ||
|
||
static int eth_open(struct inode *inode, struct file *file) | ||
{ | ||
struct file_operations *ops = get_ops(inode->i_rdev); | ||
|
||
if (!ops) | ||
return -ENODEV; | ||
|
||
printk("ETH open pid %d\n", current->pid); | ||
return ops->open(inode, file); | ||
} | ||
|
||
static void eth_release(struct inode *inode, struct file *file) | ||
{ | ||
struct file_operations *ops = get_ops(inode->i_rdev); | ||
|
||
if (!ops) | ||
return; | ||
|
||
printk("ETH close pid %d\n", current->pid); | ||
ops->release(inode, file); | ||
} | ||
|
||
static size_t eth_write(struct inode *inode, struct file *file, char *data, size_t len) | ||
{ | ||
struct file_operations *ops = get_ops(inode->i_rdev); | ||
|
||
if (!ops) | ||
return -ENODEV; | ||
return ops->write(inode, file, data, len); | ||
} | ||
|
||
static size_t eth_read(struct inode *inode, struct file *file, char *data, size_t len) | ||
{ | ||
struct file_operations *ops = get_ops(inode->i_rdev); | ||
|
||
if (!ops) | ||
return -ENODEV; | ||
return ops->read(inode, file, data, len); | ||
} | ||
|
||
static int eth_ioctl(struct inode *inode, struct file *file, int cmd, char *arg) | ||
{ | ||
struct file_operations *ops = get_ops(inode->i_rdev); | ||
|
||
if (!ops) | ||
return -ENODEV; | ||
return ops->ioctl(inode, file, cmd, arg); | ||
} | ||
|
||
static int eth_select(struct inode *inode, struct file *file, int sel_type) | ||
{ | ||
struct file_operations *ops = get_ops(inode->i_rdev); | ||
|
||
if (!ops) | ||
return -ENODEV; | ||
return ops->select(inode, file, sel_type); | ||
} | ||
|
||
static struct file_operations eth_fops = { | ||
NULL, /* lseek */ | ||
eth_read, | ||
eth_write, | ||
NULL, /* readdir */ | ||
eth_select, | ||
eth_ioctl, | ||
eth_open, | ||
eth_release | ||
}; | ||
|
||
void /*INITPROC*/ eth_init(void) | ||
{ | ||
register_chrdev(ETH_MAJOR, "eth", ð_fops); | ||
|
||
#ifdef CONFIG_ETH_NE2K | ||
eths[0].ops = &ne2k_fops; | ||
ne2k_drv_init(); | ||
#endif | ||
#ifdef CONFIG_ETH_WD | ||
eths[1].ops = &wd_fops; | ||
wd_drv_init(); | ||
#endif | ||
#ifdef CONFIG_ETH_EL3 | ||
eths[2].ops = &el3_fops; | ||
el3_drv_init(); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.