Network card driver descriptor helps hand function

  • Foreword
    In the network card driver, both the CPU and the MAC controller need to read or write to the DMA descriptor space. DMA descriptor space will also use CACHE and zero-copy technology. In the past, it used to drive itself to apply for, associate memory and refresh (flush and invalidate) CACHE.
    Descriptor Assistant is to complete these tasks in the kernel and provide an interface to the driver. This article will do some analysis of these interface functions.
  • Create
    Realize sending static memory space application, sending zero-copy memory creation (but not applying for space), receiving static memory space application, receiving zero-copy memory space application, and CACHE refresh. The function prototype and input parameters are shown in the program list 2.1:
    Program list 2.1
    / create descriptor helper /
    struct netdev_desc_helper
    netdev_desc_helper_create (size_t each_buf_size, / The size of each frame /
    size_t pad_size, /
    PAD /
    int cache_ts_en, /
    Send static memory cache refresh enable/
    int cache_rs_en, /
    Receive static memory cache refresh enable/
    int cache_zc_en, /
    Receive zero copy memory cache refresh enable/
    int tx_buf_cnt, /< /em> Send Descriptor Number/
    int rx_buf_cnt, /
    Receive Descriptor Number/
    int tx_zc_en, /
    Send Zero Copy Enable/
    int rx_zc_cnt) /
    The number of receiving zero copy pools*/
    It can be seen that receiving zero copy is enabled by default, and the number of zero copy pools is twice the number of receiving descriptors, that is, twice the space is requested (I will analyze this below). The creation process is shown in Figure 2.1:
    Analysis of NIC Driver Descriptor Assistant Function
    Picture 2.1 Descriptor assistant creation
    The point to be concerned here is that the size of each node in the zero-copy pool is the frame size plus the node header size, the frame corresponds to the pbuf space, and the actual data storage is the payload space in the pbuf. The relationship is shown in Figure 2.2:
    Analysis of NIC Driver Descriptor Assistant Function
    Figure 2.2 Zero copy pool node structure
  • Sending
    Sending needs to pay attention to two functions. Before sending, prepare will associate the pbuf->payload to be sent by the upper layer with the sending descriptor. After sending, clean is the pbuf space Release. Figure 3.1:
    Analysis of network card driver descriptor assistant function
    Figure 3.1 Send Process
  • Receiving
    Receiving is also concerned with two functions. Input and fetch the content before receiving, and refill the re-association descriptor with the zero copy pool after receiving. But there is one more process. When initializing, associate the zero-copy address pool with the receiving descriptor and write it to the MAC controller. Figure 4.1:
    Analysis of network card driver descriptor assistant functionFigure 4.1 The receiving process is right here Why does the receiving zero copy pool apply for 2 times the memory as a speculation, because the other space can be used again after being used up, and the receiving descriptor space has to wait for the upper layer to return to the zero copy pool list, when the upper layer returns it in time, zero The number of copy pools is actually not as large as the application, so the extreme case is to apply for 2 times.
  • Leave a Comment

    Your email address will not be published.