Linux Network Driver Programming (1)

Source: Internet
Author: User
(Reprinted) Linux Network DriverProgramWrite (1)

2001-06-15 ·
· Bordi · drinking water site


We need to write a Linux driver for our company's Nic. I am deeply aware of the importance of technical exchanges when I go through a process from scratch. Linux, as a powerful weapon to challenge Microsoft's monopoly, is increasingly
Everyone's favorite. I really hope she can grow fast in China. Post the program documentation to discuss the Linux technology and application and promote the popularization of Linux in China.

This article can be reproduced at will, but please do not post it in profitable publications.

1. Linux System Device Driver Overview

1.1 Linux Device Driver categories


Linux KernelSource codeOccupies a large proportion, the sourceCodeThe length of the driver is increasing. During the constant upgrade of the Linux kernel,
The driver structure is relatively stable. In the changes from 2.0.xx to 2.2.xx, the write of the driver has made some changes, but the porting from 2.0.xx to 2.2.xx only needs to be done.
A small amount of work.

Linux devices are divided into character devices and Block devices.
Device and network
Device. Character devices are devices that do not cache data during access. Block devices can read and write data in the cache, and block devices must be able to access random
Access), character devices do not have this requirement. Typical Character devices include the mouse, keyboard, and serial port. Block equipment mainly includes hard disk equipment, CD-ROM and so on. Install a File System
The operating system must be on the block device.

Network devices are specially processed in Linux. Linux's 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. The system supports the caching of sent and received data, provides traffic control mechanisms, 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 support provided by the operating system to the driver 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. Therefore, the driver must tell the system where your sending function is. The system will call your sending function when there is data to be sent.
Program. In addition, the driver directly controls the hardware, so the network hardware receives the data first, that is, the driver, which 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 is to send the received data to the system. 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 the driver's ability to respond to interruptions. Generally, an interrupt handler is registered in the system. The operating system calls the processing program of the driver when the hardware is interrupted. Linux supports interrupt sharing, that is, multiple devices share one interrupt.

1.2.3 clock


Clock is used in many places when implementing the driver. For example, timeout processing in some protocols and hardware polling without interruption mechanisms. The operating system should provide a timing mechanism for the driver. Generally at the specified time
Call back the registered clock function. In the network driver, if the hardware is not interrupted, the timer can provide poll to access the hardware. Or, it is required to implement some protocols.
Timeout retransmission.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.