[Linux Device Driver] network device drivers (III)

Source: Internet
Author: User


Notes for compiling Linux network drivers

3.1 interrupt sharing

In Linux, several devices run to share the same interrupt. If you need to share, specify the sharing method when applying. Definition of system-provided request_irq () call:

Int request_irq (unsigned int IRQ,
Void (* Handler) (int irq, void * dev_id, struct pt_regs * regs ),
Unsigned long flags,
Const char * devname,
Void * dev_id );

If the sharing is interrupted, flags sets the sa_shirq attribute so that other devices can apply for the same interruption. Note that this attribute must be set for all devices that use this interrupt when calling request_irq. When the system calls back each interrupt handler, you can use the dev_id parameter to find the corresponding device. When the system calls back each interrupt handler, you can use the dev_id parameter to find the corresponding device. Generally, dev_id is set to the device structure. The system uses the dev_id parameter to call each interrupt handler in sequence.

3.2 handling of busy hardware sending

Generally, tbusy is set to 1 for sending busy messages. After processing the sent data, clear tbusy in the sending end interrupt, and use mark_bh () to call the notification system to continue sending.

Another method is to disable tbusy from being set to 1, so that the system always considers the hardware idle, but reports cannot be sent successfully. The system will always try again.

3.3 Flow Control)

Traffic control is required for sending and receiving network data. These controls are implemented in the system and do not need to be implemented by the driver. Each device data structure has a parameter Dev-> tx_queue_len, which indicates the maximum number of cached data packets sent. Another aspect of Throttling during sending is the sending window of the higher-level protocol (there is a sending window in the TCP protocol ). When the window size is reached, the high-level protocol will not send data again.

The receiving traffic control is also divided into two levels. There are limits on the cached data packets of netif_rx. In addition, the high-level protocol also has a maximum amount of data to be processed.

Sending and receiving Throttling is processed in do_dev_queue_xmit () and netif_rx () of net/CORE/dev. C.

3.4 debugging

Many Linux drivers are compiled into the kernel to form a large Kernel File. However, this is quite troublesome for debugging. You can use the module method to debug the driver. The driver that supports the module method must provide two functions: int init_module (void) and void cleanup_module (void ). Init_module () is called when this module is loaded. In this function, register_netdev () can be used to register the device. If init_module () is returned, 0 indicates success, and negative indicates failure. Cleanup_module () is called when the driver is uninstalled. It clears the occupied resources and calls unregister_netdev ().

The module can be dynamically loaded and detached. Manually load and use the insmod command, uninstall and use the rmmod command, and check that the modules in the kernel use the lsmod command.
  

Further reading

Linux program design materials can be obtained from the Internet. This is the benefit of open source code. There is no "undisclosed secret ". The main materials I read when writing the driver include:
Linux kernel source code
The Linux kernel hacker's Guide by Michael K. Johnson
Linux Kernel module programming guide by Ori pomerantz
Device Drivers in Linux by Olly in BBS
You can select a template as the start. The kernel source code contains a network driver template, drivers/NET/skeleton. C. Contains the basic content of the driver. However, this template is intended for Ethernet devices. Ethernet processing has special "benefits" in Linux systems. If it is not an Ethernet device, pay attention to some details, mainly in the initialization program.

Finally, it is probably the most effective help to listen to the experiences of other developers by referring to programs written by others.

Previous Article: [Linux Device Driver] Network Device Driver (2)
Next article: Volatile keywords description and Test

Related Article

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.