Linux Network Device Driver Overview

Source: Internet
Author: User

I. Overview Linux network device drivers follow common interfaces. The design adopts 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 www.2cto. comLinux network device driver 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 2. Data Packet sending process when a data packet is sent at the upper layer of the network subsystem, call the ndo_start_xmit function implemented in the network device driver, the data packet to be sent is encapsulated in the socket buffer skb parameter. 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 data packet receiving is an asynchronous process, most network devices support data reception interruptions, so data packets are received by the interrupt processing program in the driver. 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.