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