Linux Network Device Driver Overview

Source: Internet
Author: User

I. Overview

Linux network device drivers follow common interfaces and are designed with an object-oriented method. A device is an object (net_device structure ). The most basic methods for a network device are initialization, sending, and receiving.

The architecture of Linux network device drivers can be divided into four layers: network protocol interface layer, network device interface layer, device driver function layer, and network device and media layer, as shown in 1. The main task of network device drivers is to complete the device driver function layer. In Linux, all network devices are abstracted as an interface, which provides a set of operations on all network devices. The data structure struct net_device indicates the running status of the network device in the kernel, that is, the network device interface. It includes both software-only network device interfaces, such as loopback, and hardware network device interfaces, such as Ethernet cards. The device chain with dev_base as the header pointer collectively manages all network devices. Each element in the device chain represents a network device interface. The data structure net_device contains many device methods for system access and protocol layer calls, including initialization, opening and closing the open and stop functions of network devices, and handling the hard_start_xmit functions sent by data packets, and interrupt processing functions.

Figure 1 network device driver architecture

Ii. Packet sending Process

When a packet is sent at the upper layer of the network subsystem, the data packet to be sent is encapsulated in the socket buffer SKB parameter by calling the ndo_start_xmit function implemented in the network device driver. In the specific implementation of the Data Packet sending function of the driver, it will first establish a DMA channel between the data block in the primary storage where the SKB data packet is located and the memory of the network device, start the DMA channel to transmit data packets from the primary memory to the device memory, and then the network device hardware sends the data packets through the network interface or antenna. After a packet is sent successfully, a hardware interrupt is sent to the processor, and some aftercare work is done in the Interrupt Processing Program, as shown in figure 2.

Figure 2 network device driver data packet sending Process

3. Data Packet receiving process

Packet receiving is an asynchronous process. Because of this, most network devices support data reception interruptions due to system performance considerations, therefore, the interrupt handler is used in the driver to receive data packets. A DMA channel has been established between the system primary storage and network devices. When data packets arrive at the network device, the data packets are automatically transmitted to the system primary storage, which generates an interruption signal, to enter the interrupt handler function of the driver. In the interrupt handler function, the driver first allocates a socket buffer SKB to accommodate the received data packet, and then transmits the SKB to the upper-Layer Code of the network subsystem, the specific transfer process is implemented by the driver calling the netif_rx (SKB) function. The upper-Layer Code is responsible for releasing the memory occupied by the SKB, as shown in 3.

Figure 3 network device-driven packet receiving process

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.