[Country EMBED strategy] [133] [Network card driver Architecture analysis]

Source: Internet
Author: User

Linux Network Subsystem

1. System call Interface: Provides system call

2. Protocol agnostic Interface: Unified network protocol for system call interface use

3. Network protocol stack: Implement network protocol

4. Device independent Interface: Unified device driver for network protocol use

5. Device driver: Implement network card driver

Linux drivers have a structure in the kernel to describe, first find the device description structure, and then find how the device is registered and initialized.

Network card description Structure

In the Linux kernel, each NIC is described by a net_device structure, some of which are key members:

Char Name[ifnamsiz] Device name, such as: eth%d

unsigned long base_addr I/O base Address

Const Strcut net_device_ops *netdev_ops NIC Operation set

Nic Operation Collection

Similar to the file_operations structure in character device drivers, the NET_DEVICE_OPS structure records the operations supported by the NIC.

struct const struct Net_device_ops dm9000_netdev_ops = {

. Ndo_open = Dm9000_open,

. Ndo_stop = Dm9000_stop,

. Ndo_start_xmit = Dm9000_start_xmit,

. Ndo_do_ioctl = Dm9000_ioctl,

. ndo_validate_addr = Eth_validate_addr,

. ndo_set_mac_address = Eth_mac_addr

};

Network packets

Each network packet in the Linux kernel is described by a socket buffer struct struct sk_buff, that is, a SK_BUFF structure is a network packet, and pointers to Sk_buff are often referred to as SKB, for example: struct Sk_buff *skb.

The members within a struct SK_BUFF structure are: head,data,tail,end. Head and end are the start and end addresses of the network packet, and data and tail are the starting and ending positions of the network packet's valid data. The range of data and tail does not exceed the range of head and end.

Network Card driver Architecture Analysis CS8900.C

Analyze driver initialization, sending and receiving when analyzing the NIC driver. The first step is to find the module's Ingress Module_init, but in the early Linux drivers the module's entry was init_module. The sending function of the NIC data is in the Net_device_op operation Collection, and the receiving of the NIC data is completed in the interrupt.

NIC Initialization

1. Assigning Net_device, using Alloc_etherdev

2. Initializing the Net_device structure

2.1. Initialize the interrupt number

2.2. Initialize the base site

2.3. Initialize the MAC address

2.4. Initialize Netdev_ops

3. Initializing hardware

4. Register the NIC driver and use Register_netdev

Network card data transmission

1. Notify upper layer protocol to suspend data transfer to NIC, use Netif_stop_queue

2. Write the data in the SKB to the NIC Register

3. Release SKB space and use DEV_KFREE_SBK

43 Send interrupt processing, notify the upper layer protocol, you can transfer data to the NIC, using Netif_wake_queue

Network card Data Reception

1. Read Receive status

2. Read the received data length

3. Assigning SKB structures, using DEV_ALLOC_SKB

4. Read the data from the network card register and deposit to SKB

5. SKB the received packet to the protocol stack, using NETIF_RX

[Country EMBED strategy] [133] [Network card driver Architecture analysis]

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.