Linux网络驱动程序howto

1.in module_init  

dev->your_netdev=alloc_netdev(sizeof(struct your_priv),intfname,your_setup);//in future, you can get your_priv by netdev_priv(your_netdev)  

your_setup function will called before register, you should do hardware check, IRQ probe and etc. but do'nt call request_irq and other like function to hold resource.

You need to assign function pointer, such as open, close, hard_start_xmit 

register_netdev(dev->your_netdev)

2. in module_exit  

unregister_netdev(dev->your_netdev)  

free_netdev(dev->your_netdev)

3 open and close function 

i n open function,

you should request all necessary resource, such as IRQ and port.  

you should init network_device->dev_addr 

You also need to call netif_start_queue to indicate the device is ready to transfer package 

in close function, 

you need to release all held resource 

call netif_stop_queue to indicate the device is stopped to transfer package

4 transfer function hard_start_xmit 

when having package to send, kernel will call this function to send package 

set dev->trans_start 

call hardware specific function to send package

5 receive function 

when there is package incoming, interrupt handler will be called 

for rx interrupt, create a sdk, and call netif_rx to send package to upper layer

6 NAPI poll function

the process is: 

when get rx interrupt, disable interrupt, and call netif_rx_schedule(dev) to make poll function executed in near future 

in poll function, process as many as possible packages(limited by budge parameter got from parameter). If all package in incoming buffer is processed, enable interrupt again, and call netif_rx_complete to disable poll function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值