4

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.

Zaid Aly
  • 163
  • 1
  • 17
user786
  • 3,902
  • 4
  • 40
  • 72
  • 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 packets – user786 Jan 19 '21 at 09:58
  • 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 explain – user786 Jan 19 '21 at 10:21
  • basically the outcome of this will be mmap functionality enabled in intel `e1000e` Ethernet pci device driver – user786 Jan 19 '21 at 10:25
  • 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 driver – user786 Jan 19 '21 at 11:14
  • 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"] – user786 Jan 19 '21 at 16:41
  • 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 explain – user786 Feb 02 '21 at 16:12
  • Or use DNA buffer for sharing – user786 Feb 02 '21 at 16:35
  • 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) – domen Feb 03 '21 at 09:05
  • @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 netdevice – user786 Aug 17 '21 at 09:44
  • @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 again – user786 Aug 19 '21 at 15:27

0 Answers0