Linux operating system network driverProgramWrite
1. Linux System Device Driver Overview
1.1 Linux Device Driver categories
1.2 compile some basic concepts of the driver
Ii. network device drivers in Linux
2.1 Structure of the Network Driver
2.2 Basic Methods for network drivers
2.3 data structures used in network drivers
2.4 Common System Support
Iii. problems that may occur when writing Linux network drivers
3.1 interrupt sharing
3.2 handling of busy hardware sending
3.3 Flow Control)
3.4 debugging
4. Further reading
V. Miscellaneous
1. Linux System Device Driver Overview
1.1 Linux Device Driver categories
Linux DevicesDriveLinux KernelSource codeOccupies a large proportion, the sourceCodeLength day
Increase, mainly because of the increase in drivers. The driver structure during the continuous upgrade of the Linux Kernel
Relatively stable. In the changes from 2.0.xx to 2.2.xx, the write of the driver has made some changes,
Porting from 2.0.xx driver to 2.2.xx only requiresDo a small amount.
Linux devices include character devices, Block devices, and networks.
Device (netwOrk device. Character devices are devices that do not cache data during access. Block device read/write
And block devices must be able to access random resources.
This requirement. Typical Character devices include the mouse, keyboard, and serial port. Block devices mainly include hard disk floppy disks
Equipment, CD-ROM, etc. A file system must be installed on a block device to enter the operating system.
Network devices are specially processed in Linux. Linux network system is mainly based on bsd unix socket
Mechanism. A special data structure (sk_buff) is defined between the system and the driver for data transmission. System
The system supports caching of sent and received data, provides a traffic control mechanism, and supports multiple protocols.
1.2 compile some basic concepts of the driver
No matter what the operating system driver is, there are some general concepts. The operating system provides the driver
Program support is also roughly the same. The following describes some basic requirements for network device drivers.
1.2.1 sending and receiving
This is the most basic function of a network device. A network card does nothing more than sending and receiving. So drive
The system will tell the system where your sending function is. The system will call your sending function when there is data to be sent.
Send program. In addition, because the driver directly operates the hardware, the network hardware has the first time to receive data.
The driver is responsible for processing the raw data and then sending it to the system.
System. Here, the operating system must provide two mechanisms: one is to find the sending function of the driver, and the other
The driver sends the received data to the system.
1.2.2 interruption
Interruptions play an important role in modern computer structures. The operating system must provide drivers to respond to interruptions.
Capabilities. Generally, an interrupt handler is registered in the system. After hardware interruption of the Operating System
Call the processing program of the driver. Linux supports interrupt sharing, that is, multiple devices share one interrupt.
1.2.3 clock
InNowThe clock is used in many places when the driver is running. For example, timeout processing in some protocols is not in progress.
Hardware polling of the disconnected mechanism. The operating system should provide a timing mechanism for the driver. Usually at the scheduled time
After the callback, the registered clock function is called back. In the network driver, if the hardware is not interrupted, Set
The timer can provide polling(Poll) access the hardware. Or the timeout required to implement some protocols.
Retransmission.