What is the relationship of DMA ring buffer and TX/RX ring for a network card?
Asked Answered
S

3

14

I know that for a network card, OS must allocate tx/rx rings for it so that when OS wants to receive/transmit packets, the network card will know where the packets are and which packets are to be transmit.

And when I read about DMA, I see something named DMA ring buffer. Are the DMA ring and tx/rx ring the same thing?Or what is the relationship?

Sewellyn answered 23/11, 2017 at 7:56 Comment(0)
R
7

Short Answer: These are the same.

More details: First, see this post which is very related to your question.

In this article it says:

A variant of the asynchronous approach is often seen with network cards. These cards often expect to see a circular buffer (often called a DMA ring buffer) established in memory shared with the processor; each incoming packet is placed in the next available buffer in the ring, and an interrupt is signaled. The driver then passes the network packets to the rest of the kernel, and places a new DMA buffer in the ring.

The DMA ring allows the NIC to directly access the memory used by the software. The software (NIC's driver in the kernel case) is allocating memory for the rings and then mapping it as DMA memory, so the NIC would know it may access it. TX packets will be created in this memory by the software and will be read and transmitted by the NIC (usually after the software signals the NIC it should start transmitting). RX packets will be written to this memory by the NIC and will be read and processed by the software (usually after an interrupt is issued to signal there's work).

Hope this helps.

Roundsman answered 23/11, 2017 at 8:15 Comment(5)
so the ring buffer is allocated in memory rather than NIC storage, and NIC knows where the rings are. As I know the ring format is hardware-specific and there is some register in NIC of ring location, so the NIC will just find the ring and read it according to its own format, then it will find the packets?Sewellyn
Yes, the format of the data in the rings should be consistent with the API to the NIC. Each vendor usually have a PRM (Programmer Reference Manual) which explains how the data should be constrcuted.Roundsman
Got it. It does help me a lot. THX!Sewellyn
I want to ask if the ring is the queue, what is the difference, thanks!Fungal
The ring is the representation of the device RX/TX queue. It is used for data transfer between the kernel stack and the device.Roundsman
R
21
  1. Ring Buffer Contains Start and End Address of Buffer in RAM. TX Ring will contain addresses of Buffer in RAM that contains data to be transmitted. RX Ring will contains address of Buffer in RAM where NIC will place data.

    These rings are present in RAM.

  2. TX buffer and RX buffer are are in RAM pointed by TX/RX rings.

  3. Now Network Card Register has Location of Rings Buffer in RAM .

Now 1 and 2 can be DMA able buffer , they are called DMA TX/RX ring and DMA TX/RX buffer. Now since RX/TX ring must remain throughout they are made as consistent/coherent DMA type of meory. While Buffers are made streaming/Single DMA type of memory

enter image description here enter image description here enter image description here enter image description here

Reathareave answered 26/12, 2019 at 18:7 Comment(6)
Nice drawings @Alok. Just curious, did you copy them from some source or handmade them:)Switchboard
@Switchboard nope, they are taken from various sources and i dont own themReathareave
Do you know how the head and tail pointer are related to the Rx Ring Buffer reading and writing packets between the NIC device and the driver? I am confused on that part.Ordway
I'm confused, why in figure 3 (the sequence diagram) the "ring" is located on NIC? Maybe for that model it is the very way of implementation. But "that ring" is different from "other rings" talked about in this post, right?Punish
Here are some nice articles that describe exactly the above diagrams. medium.com/coccoc-engineering-blog/… mdpi.com/1424-8220/18/10/3267/htmAgnosticism
Very nice diagrams. One detail question: the DMA-able memory region that NIC writes to, isn't it same as the buffer accessed by the network stack? After all, they're both main memory. Why would the kernel allocate two buffer and do copy between them? According to the last diagram, the DMA-able memory is allocated by alloc_skb() and linked (pointed) to by descriptor in the Rx ring. When the kernel picks up skb filled by NIC, it can just directly hook it up to linked list in network stack, right? (not copying)Bettiebettina
R
7

Short Answer: These are the same.

More details: First, see this post which is very related to your question.

In this article it says:

A variant of the asynchronous approach is often seen with network cards. These cards often expect to see a circular buffer (often called a DMA ring buffer) established in memory shared with the processor; each incoming packet is placed in the next available buffer in the ring, and an interrupt is signaled. The driver then passes the network packets to the rest of the kernel, and places a new DMA buffer in the ring.

The DMA ring allows the NIC to directly access the memory used by the software. The software (NIC's driver in the kernel case) is allocating memory for the rings and then mapping it as DMA memory, so the NIC would know it may access it. TX packets will be created in this memory by the software and will be read and transmitted by the NIC (usually after the software signals the NIC it should start transmitting). RX packets will be written to this memory by the NIC and will be read and processed by the software (usually after an interrupt is issued to signal there's work).

Hope this helps.

Roundsman answered 23/11, 2017 at 8:15 Comment(5)
so the ring buffer is allocated in memory rather than NIC storage, and NIC knows where the rings are. As I know the ring format is hardware-specific and there is some register in NIC of ring location, so the NIC will just find the ring and read it according to its own format, then it will find the packets?Sewellyn
Yes, the format of the data in the rings should be consistent with the API to the NIC. Each vendor usually have a PRM (Programmer Reference Manual) which explains how the data should be constrcuted.Roundsman
Got it. It does help me a lot. THX!Sewellyn
I want to ask if the ring is the queue, what is the difference, thanks!Fungal
The ring is the representation of the device RX/TX queue. It is used for data transfer between the kernel stack and the device.Roundsman
S
0

DMA ring buffer and TX/RX rings are the same thing.
DMA has two type of ring buffers

  • TX ring buffer - used for transmitting data from kernel to device
  • RX ring buffer - used for receiving data from device to kernel
Scorch answered 18/7, 2020 at 13:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.