DMA proxy and how it is used to copy ethernet frames to user buffer

1

This is the code I am refering to: https://github.com/mstuehn/dma_proxy/blob/master/dma_proxy.c

At line 841 it uses call to dma_set_coherent_mask and passing generic device pchannel_p->proxy_device_p.

    dma_set_coherent_mask(pchannel_p->proxy_device_p, 0xFFFFFFFF);
            pchannel_p->interface_p = (struct dma_proxy_channel_interface *)
                dmam_alloc_coherent(pchannel_p->proxy_device_p,
                                    sizeof(struct dma_proxy_channel_interface),
                                    &pchannel_p->interface_phys_addr, GFP_KERNEL); 
                                    
            

pchannel_p is of type dma_proxy_channel.

    struct dma_proxy_channel {
        struct dma_proxy_channel_interface *interface_p;    /* user to kernel space interface */
        dma_addr_t interface_phys_addr;

        struct device *proxy_device_p;              /* character device support */
        struct device *dma_device_p;
        dev_t dev_node;
        struct cdev cdev;
        struct class *class_p;

        struct dma_chan *channel_p;             /* dma support */
        struct completion cmp;
        dma_cookie_t cookie;
        dma_addr_t dma_handle;
        u32 direction;                      /* DMA_MEM_TO_DEV or DMA_DEV_TO_MEM */
    };

static struct dma_proxy_channel channels[CHANNEL_COUNT];

This is how its passed to create_channel where multiple calls to dma_set_coherent_mask are made for both _rx and _tx.

create_channel(&channels[0], "_tx", DMA_MEM_TO_DEV);

My question is: if my device -- that the DMA proxy driver targets -- is a PCI network card (NIC card) then will I supply struct pci_dev obj_rx and struct pci_dev_tx to two calls to dma_set_coherent_mask to create DMA channels for both receive and transmit?

And if I want to be able to read network packets then how is it possible since I see using NAPI and ISR will look bit odd since my char driver will not be able to read ethernet frames and copy them to user buffer since that work needed to be done in read or mmap.

So how can I suppose to read a packet from userspace application with mmap or read system calls? What do I have to add to copy ethernet frames to user buffer and be able to get packets with application's mmap and read calls?

update

I just want some one to read the comment link I posted. And give me some close semblence of working solution for rx and tx. For any device. I will use Realteck r 8169 device. Kernel has its sources as driver.

c
dma
asked on Stack Overflow Apr 12, 2021 by user786 • edited Apr 21, 2021 by user786

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0