In order to write PCI ethernet driver. How to implement MMAP in the PCI Ethernet driver
Asked Answered
C

0

5

In Ethernet PCI device driver if the driver allows applications to map user-space buffer to Driver virtual memory and allow the user to call MMAP on device driver file after opening it. Then how do implement MMAP in the PCI ETHERNET Network device driver?

I have already looked in the dev_pci struct. There are some members that are named as they have something to do with MMAP but I could not pinpoint how to make a device driver implement MMAP.

In the book Linux Device Driver, the author did not specifically relate Memory Mapping in device driver with PCI device driver or Network device driver.

Any help on how to enable my PCI/Network/Ethernet device driver to handle MMAP calls from user space and mapping the user is given buffer into the driver's virtual memory I am looking for especially how to register XX___mmap(...) implementation function in the device driver with PCI and network device driver. I have dev_pci and net_dev device drivers in a device driver.

Chita answered 16/1, 2021 at 11:54 Comment(10)
So basically it looks like I must have to associate file with my some struct that contains pci dev. My idea was I get packets in interrupt handler and associate that with some virtual mapped area or page. So this is my question if I have struct vm_area_struct and in it I have vm_start & vm_end & offset then how to write packets to virtual address of kernel mapped user buffer which I will do in poll handler of netdev_ops for receiving packetsChita
So question is really about Does it make sense: if I use char driver with file operations for mmap and pci driver for pci device for ethernet device and "BOTH Combined in One driver c file" with single __init. I guess this is the only way to do this. unless if there is any other option. Please explainChita
basically the outcome of this will be mmap functionality enabled in intel e1000e Ethernet pci device driverChita
I will probably use int pci_mmap_page_range function declared in pci.h for building new page in kernel virtual memory that I will be used in mmap implemented function in the driverChita
ok don't answer me just anyone please say: Is this how backdoor drivers work just found something that I may/may not understood? if it is then does it mean bypassing a kernel stack is wrong [not technically meant by "is wrong"]Chita
Need to know now whether in mmap function given access to global variable containing the base address of pci device from /dev/mem or use some function please explainChita
Or use DNA buffer for sharingChita
This provides a bit more context to the other question. If you don't want just a hack and occasional raw register write, then a proper driver will probably be written in kernel (there are userspace drivers, but dma and irq are tricky, not sure about performance either; not even sure it's possible in case of PCI)Catheryncatheter
@stackinside yes please elaborate. this sounds interesting to me. But please add few words on linux-kernel-repo/drivers/pci/mmap.c there are just 3 or 4 functions that Interest me. also on is there a way I can attach file device driver to tp in tp = netdev_priv(dev); private data. because I like to maintain linkedList of tcp only packets received in Napi poll handler and to send packets just maintain another linkedList of userspace-write ethernet frames and just send inside ndo_start_xmit of netdeviceChita
@stackinside Should you find this interesting / helpful, let me know. I then should be able to elaborate a little bit on this suggestion in an answer below. thanks for info on Packet_MMAP, actually I tried and I am getting packet frames. Now I like to add simple BPF filter to attach to my socket getting frames using PACKET_MMAP. Can u tell me about this please. Its really interesting I like to find more. can u help. thanks againChita

© 2022 - 2024 — McMap. All rights reserved.