问题
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.
回答1:
What I need to do is create a filesystem driver or block device driver or char device driver that in turn create a file on my system. Basically it will be a special char or block device file. I can read and write to it after opening it from application. the device file will be the entry point of my device driver. Once I have a user space data then I can simple read or write to io ports. So for this task if u need to do it right then read-up I/O operations function like readl
or writel
so using these functions I can read from NIC card for this I just need to see Receive Descriptor Head queue
and Receive Descriptor Tail queue
I can get npkt_t
from there
A packet consists of an npkt_t structure, which has data buffers associated with it. If the driver wants to create a packet to send upstream, it should call alloc_up_npkt(). Source https://www.qnx.com/developers/docs/6.3.0SP3/ddk_en/network/npkt_t.html
It really not that difficult since the code is available for linux kernel network stack and that is how it can be accomplished. but this is the only way for file based hotplug driver
There are many char device, block device, filesystem drivers available for examples in form of tutorials, so the main task is creating the actual ethernet frame and doing everything that required and done in kernel stack.
来源:https://stackoverflow.com/questions/65749351/in-order-to-write-pci-ethernet-driver-how-to-implement-mmap-in-the-pci-ethernet