Linux driver writing

  
 

Working requires writing a Linux driver for one of our company's network cards. Experience a process from scratch and feel the importance of technical communication. As a powerful weapon to challenge the soft monopoly, Linux is increasingly loved by everyone. I really hope that she can grow up rapidly in China. Post the program documentation and hope to discuss Linux technology and applications with you to promote the popularization of Linux in China.

LinuxOperating System
Network Driver Writing 1. Linux System Device Driver Overview 1.1 Linux Device Driver Classification 1.2 Writing Basic Concepts of Drivers II. Linux System Network Device Driver 2.1 The structure of the network driver 2.2 The basic method of the network driver 2.3 The data structure used in the network driver 2.4 Common system support III. Problems that may be encountered in writing Linux network drivers 3.1 Interrupt sharing 3.2 Processing when the hardware sends busy 3.3 Flow Control 3.4 Debugging IV. Further Reading V. Miscellaneous


A. Linux System Device Driver Overview 1.1 Linux Device Driver Classification Linux Device Drivers in Linux The kernel source code accounts for a large proportion, and the length of the source code is increasing, mainly due to the increase of drivers. In the ongoing upgrade of the Linux kernel, the structure of the driver is relatively stable. In the 2.0.xx to 2.2.xx changes, the driver has been changed, but from the 2.0.xx driver to the 2.2.xx port, only a small amount of work is required. Linux system devices are classified into three types: character devices (char devices), block devices, and network devices. A character device is a device that is not cached when accessed. Block devices are cached to support read and write, and block devices must be able to access random access. Character devices do not have this requirement. Typical character devices include mice, keyboards, serial ports, and the like. The block device mainly includes a hard disk floppy disk device, a CD-ROM, and the like. A file system must be installed on the block device to be installed into the operating system. Network devices do specialized processing in Linux. The Linux network system is mainly based on the socket mechanism of BSD unix. A special data structure (sk_buff) is defined between the system and the driver for data transfer. The system supports caching of sending data and receiving data, providing a flow control mechanism and providing support for multiple protocols.

1.2 Some basic concepts for writing drivers There are some general concepts about what operating system drivers are. The support provided by the operating system to the driver is also roughly the same. Here are some basic requirements for network device drivers. 1.2.1 Sending and Receiving This is the most basic function of a network device. What a network card does is nothing more than sending and receiving. So the driver tells the system where your send function is, and the system will call your send program when there is data to send. In addition, since the driver directly manipulates the hardware, the network hardware has the data received first, that is, the driver, which is responsible for processing the original data and then sending it to the system. Here, the operating system must provide two mechanisms, one is to find the driver's send function, and the other is to send the received data to the system. 1.2.2 Interrupts Interrupts have an important place in modern computer architecture. The operating system must provide the ability for the driver to respond to interrupts. It is common to register an interrupt handler into the system. The operating system calls the driver's handler after a hardware interrupt occurs. Linux supports interrupt sharing, where multiple devices share an interrupt. 1.2.3 Clocks Clocks are used in many places when implementing drivers. For example, timeout processing in some protocols, hardware polling without interrupt mechanism, etc. The operating system should provide a timing mechanism for the driver. It is common to call back the registered clock function after the predetermined time has elapsed. In the network driver, if the hardware has no interrupt function, the timer can provide access to the hardware in a polling manner. Or it is a timeout retransmission required to implement certain protocols. 2. Linux system network device driver 2.1 Network driver structure All Linux network drivers follow a common interface. The design is based on an object-oriented approach. A device is an object (device structure) that has its own data and methods inside. The first parameter of each device's method is called the device object itself. This way you can access your own data (similar to the this reference of the object-oriented program design). The most basic methods of a network device are initialization, sending and receiving. ------------------- ---------------------

Copyright © Windows knowledge All Rights Reserved