Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Raspberry Pie 4 Wired Network Card driver debugging

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of raspberry pie 4 cable network card driver debugging, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.

Raspberry pie 4 wired network card driver debugging notes 1. Overview

From the point of view of the bottom players of raspberry pie, raspberry pie 4 is a better development board. Before the raspberry pie 4, the drivers of the wired network card were all connected to the USB device, that is to say, the previous raspberry pie had to enable the USB protocol, and then turn on the network card, so the difference in network speed and network processing efficiency would not be flattered. Broadcom bcm network card chip is still good, this time for raspberry pie 4 adaptation and gigabit Ethernet port, with raspberry pie 4 A72 4 core chip, is really a very conscientious development board. Learning network programming, in addition to familiar with a variety of TCP,UDP protocols, if you can understand how the underlying driver works, it is also the icing on the cake. This article mainly aims at the raspberry pie 4 wired network card driver model, as well as the data sending and receiving way, carries on the comb summary, at the same time learns some better network card design pattern.

two。 A brief introduction to the wired network card of raspberry pie 4

For the raspberry pie 4 wired network card, the data on the Internet is quite scarce. I can only speculate the behavior of the raspberry pie network card through sporadic fragmented data. Combined with the code of uboot and Linux, it is adapted to the lwip protocol stack of rt-thread to complete the networking function of the raspberry pie. For related code, please refer to

Https://github.com/RT-Thread/rt-thread/blob/master/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c

The raspberry pie 4 carries Broadcom GENETv5, the fifth-generation genet of Broadcom, and specifically adapts to the Broadcom ®BCM54213PE single-port GRMII Gigabit Ethernet transceiver. The specific chip manual can be downloaded from the address below.

Https://gitee.com/bigmagic/raspi_sd_fw/blob/master/doc/raspi4/BCM54213PE_datasheet.PDF

This is a three-speed 1000BASE-T / 100BASE-TX / 10BASE-T Gigabit Ethernet (GbE) transceiver integrated in a single CMOS chip. BCM54213PE is a highly integrated solution that integrates digital adaptive equalizers, ADC, phase-locked loops, line drivers, encoders, decoders, echo canceller, crosstalk canceller and all necessary support circuits. Based on Broadcom's recognized digital signal processor technology, BCM54213PE is fully compliant with RGMII standards and is compatible with industry-standard Ethernet MAC and switch controllers.

3. Design ideas

When writing any code implementation, there should be a design, the quality of the design directly determines the final shaping effect. The debugging driver should not look at the problem step by step, but should use a strategically advantageous thinking to look at the solution to the problem, what to do first and then, and what is the relationship between the two. The debugging of complex modules often involves the coupling of several devices, and the characteristics of these coupling are often the clues of driver debugging. Just like playing games, following one clue after another will eventually solve the driving path.

When debugging the network card driver, we must also pay attention to two things: one is the serial management data bus interface (MDIO), and the other is the controller register of the chip and the network card.

The MDIO interface is composed of two data lines, MDC and MDIO. Through these two lines, the microcontroller can access the register groups introduced in the physical layer chip, and these register groups determine the connection information of the physical layer, such as the rate of the network port queried, the status of the network port and so on.

The second is the data processing register directly related to the chip, such as DMA control, interrupt control and so on.

In order to access the network card data, the above two points need to be understood and mastered.

4. The process of debugging raspberry pie 4 wired network card

In the process of debugging, I found that the network port is matched by the speed of the router network port, so it is necessary for MDIO to communicate and query the status of the network card chip, so as to judge whether the currently connected router is a gigabit network card or a 100-megabit network card. If no judgment is made, the upper layer data communication cannot be carried out if the rate does not match.

In addition, after power up, there is a transceiver count inside the cable Ethernet data transceiver, and this count z value will be directly related to the DMA linked list behind me, so every time after initialization, the count needs to be cleared, which takes a little time and needs to be delayed, so it is best to make a judgment until it is empty.

These are two key details, and there are no other processes that need to be paid special attention to. Then you need to understand the structure of the DMA data linked list.

On raspberry pie 4, managing network data sending and receiving is a structure made up of DMA linked lists. Each transceiver list has 256 DMA descriptors, each of which records separately

1. High-order address (high 32-bit of 64-bit address)

two。 Low-order address (low 32-bit of 64-bit address)

3. Maximum length information received

With regard to the order in which it is received, if no data has been received before, when a frame of network packet arrives, the DMA linked list starts with the DMA linked list at offset 0 and places the received data at the address declared by the DMA descriptor.

It is important to note that for received DMA descriptors, each descriptor should point to an address of a non-cache area, because the use of cache often causes memory consistency problems, which can also be solved by writing back cache data. When we allocate memory, we can allocate a whole section of space, for example, by 256descriptors, assuming that the maximum length of each receiving packet is 2K, then we need to allocate 512K of continuous memory space to receive data. Whenever a packet comes, the pointer will automatically point to the next dma descriptor, which is done by hardware and has nothing to do with software. The other pointer is to determine which dma descriptor is currently read. As the amount of data accumulates, the data will always be stored in the next descriptor, and packet loss will not occur due to the lack of processing speed.

This design is very good, which avoids the problem of packet loss caused by too much and fast network data, and greatly simplifies the model of data reading through the offset of the pointer.

The data transmission does not need to be so complex, of course, the hardware also has this descriptor, for simple applications, directly use a descriptor to fill the data that needs to be sent, give it to DMA, and then wait for the interrupt to come.

5. Notification of interruption of wired network card for raspberry pie 4

There is a standard GIC on the raspberry pie 4, which is more generic for interrupt handling.

Query its data manual, you can see that the interrupt number is 29, here is only a peripheral interrupt number, but also to be distributed by GIC, so according to the routing rules of GIC

Finally, it can be calculated that the break number is 16029. With this interrupt number, then configure the wired Ethernet interrupt controller of bcm2711, open the DMA to receive and send the interrupt, and then the relevant interrupt can be generated.

Thank you for reading this article carefully. I hope the article "sample analysis of raspberry pie 4 cable network card driver debugging" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report