Network protocol stack 14: network card sending/receiving data process using the connect Function Decomposition

Source: Internet
Author: User

After queuing the data packet priority, the link layer extracts the data packet to be sent from the header of the queue with the highest priority, and transmits it to the data sending function of the NIC Driver, generally, the name is xxx_hard_xmit (). Because of the different hardware, the writing method varies, and a standard writing method cannot be abstracted, but its process and purpose remain unchanged, the image can be extracted. The general process is as follows:

1. determine whether the network adapter is busy by using the tbusy (transmit busy) in the device structure net_device. If it is equal to 1, the network adapter is busy, that is, data is still being transmitted, at this time, data cannot be transmitted, but is determined whether to time out. If not time out, it indicates that the network adapter is busy and the data packet is being sent. In this case, the system will return directly. If the data packet is timed out, reinitialize the relevant registers, set tbusy = 0, and then proceed to the following steps.

2. Set tbusy = 1 to prepare for data transmission. Because of this setting, if tbusy = 1 is encountered when the following data needs to be sent, it will repeat the first step of determination.

3. the hardware starts to transmit data packets. At this time, it is mainly done by performing operations on the NIC registers. In general, we will provide the address of the data to be transferred and the length of the data, then the data is sent out through the chip register.

4. Send data in a for loop until the data is completely sent. After sending data, you need to release the data packet that has just been passed in and reclaim the relevant memory for future use.

5. Finally, modify the statistical information of the device to complete the transmission.

 

 

At this point, the connect function completes all local transmission from package and transmission of data packets to the process of sending data from the network adapter. Subsequent data is forwarded over Ethernet, the destination IP address sent to the remote end. At this time, the connect function starts to sleep and waits for confirmation that the data is transferred back from the remote end.

 

 

The connect function is waiting to confirm the arrival of data, that is, the problem that needs to be solved is how the data is uploaded from the NIC to the link layer. This process is also because of the different hardware of the network card, and there is no standard writing, there is only one standard process.

1. when the network adapter receives a complete data packet (hardware completes receiving and is a complete data packet, that is, the network adapter itself has a buffer and can temporarily store data ), an interruption signal will occur to the system. This interruption signal is naturally associated with an interrupt processing program recorded by the BIOS during system startup, the following describes how to call the interrupt handler to handle the interrupt.

2. check whether the network adapter is busy by using the interrupt member in the device structure net_device. If interrupt = 1, it indicates that other processes are running the interrupt processing program, and then exit. Otherwise, proceed to the following steps.

3. Set interrupt = 1, indicating that the process is using the interrupt processing program. Other processes are not currently available.

4. Read the interrupt Status Register and determine the cause of the interruption Based on the Status Register. There are two reasons: one is that new data packets arrive, and the other is that the data transmitted last time has been completed.

5. If a new data packet arrives, the subfunction of the received data packet is called to receive the data.

6. If it is caused by the completion of the last data transmission, the upper layer of the notification protocol will modify the interface statistics and disable the tbusy flag to prepare for the next transmission.

7. Disable the interrupt flag, indicating that the interrupt operation is complete. Now other processes can use the interrupt handler function.

 

The procedure of calling a sub-function to receive data in step 5 is roughly as follows:

1. Apply for the SKB buffer to the data packet to be received, used to store the data packet

2. read data from hardware to the SKB buffer zone

3. Call the netif_rx () function to send data to the link layer.

4. Modify the statistics of the API.

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.