E1000e NIC Driver Analysis-architecture of NIC Driver

Source: Internet
Author: User

During hardware power-on initialization, the BIOS checks all PCI devices and assigns a physical address to each device. The address is obtained and written to the configuration space of the device through the bios, And the CPU cannot be accessed directly, the driver can map this configuration space to common memory through ioremap for CPU access.

When the operating system is initialized, each PCI device is assigned a pci_dev structure and the previously allocated physical address is written to the resource field of pci_dev. In the driver, you can read this field to get the configuration space address of the device. The pci_resource_start () and pci_resource_len () functions obtain the start address and size of the configuration space, then, the ioremap is mapped to the memory for CPU access to control the device.

When the e1000e NIC Driver is loaded, it is obvious that the module_init (e1000_init_module) macro is called and then the e1000_init_module () function is called. This function will further call the pci_register_driver () function.

The pci_register_driver () function uses a pci_driver structure as the input parameter. This structure defines the operation functions related to PCI devices, such as probe, shutdown, and remove. The most important thing is to define id_table. We know that the NIC device is also a PCI device, and the id_table of all PCI devices in the system has been allocated in the system startup phase, the main purpose here is to compare the id_table in the pci_driver structure with the id_table of all PCI devices, find the matching item, retrieve the pci_dev structure of the PCI device, and call the probe method.

/* PCI device API driver */

Static struct pci_driver e1000_driver = {

. Name = e1000e_driver_name,

. Id_table = e1000_pci_tbl,

. Probe = e1000_probe,

. Remove = _ devexit_p (e1000_remove ),

# Ifdef config_pm

. Driver. PM = & e1000_pm_ops,

# Endif

. Shutdown = e1000_shutdown,

. Err_handler = & e1000_err_handler

};

 

Before introducing the specific code, we first introduce the three data structures related to the driver: pci_dev, net_device, and e1000_adapter. These three data structures enable the transition from hardware to software drivers. To understand the NIC drivers, you must understand the relationship between these three structures.

The pci_dev structure is retained during the start-up phase, reflecting all the applicable specifications of PCI devices. The net_device structure is the NIC operation structure of the driver layer. These two structures both represent Nic devices, but they are different in view. net_device is an abstraction of a specific adapter and provides a unified structure for upper-layer protocols, the NIC Driver implements this abstraction based on a specific adapter. The actual operation of the NIC driver is a specific adapter, which is a structure indicated by the e1000_adapter in the hardware-related adapter. The adapter reflects most of the hardware-related features, in addition to directly operating the pci_dev structure, the NIC driver operates on the adapter structure. The adapter structure reflects the relationship between net_device and pci_dev, and achieves adapter independence for network devices.

Describes the relationship between the three data results. The pci_dev structure represents the configuration space of the NIC and the I/O memory area. The net_device structure is equivalent to the abstract interface used to operate the NIC to the kernel. In addition to the hardware independence, the e1000_adapter structure also manages the corresponding buffer for sending and receiving data packets. The virtual address mapped to the physical address space of the NIC is also saved in the modified structure. The e1000_hw structure in the e1000_adapter structure stores the hardware parameters of the network adapter. The value is obtained by reading the structure of pci_dev.

For example, the user-mode packet sending and receiving driver netmap inherits the e1000_adapter and net_device structures in the NIC Driver to operate hardware, send and receive queues, and provide upstream interfaces.

 

 

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.