1. 首页
  2. 操作系统
  3. Linux
  4. 一个用户空间网卡驱动的设计和实现

一个用户空间网卡驱动的设计和实现

上传者: 2020-07-30 11:43:34上传 PDF文件 103.09KB 热度 28次
一个基于UIO和UIO-DMA的用户空间网卡驱动的设计和实现。4 Implementation/* enable Pci bus-mastering *In this part, the implementation of the userspaceRTL8139 drivcr will bc instroduccd. Thc rclation-Another task is calling the UIO-DMa backend'sship of the driver, UIO framework and UTO-DMA is interface function in order to use the functions suprevealed in Figure 1plied by the UIO-DMA. A U1O-DMa device id willbe returned. We must export the UIo-DMa deviceid to userspace, because in the userspace part of theUIO-DMA need it as a parameter in order to find towhich device it provides servicesuio_8139d_open()k Open uIo dma device. Allocate a newe id whichcan be used by userspace to createDMA mappingsif (uio-dma_device_open (&private->pci_devuiodma_id)<0)t/* export uio_dma_id to userspace *if (device_create-file(&private->pci_dev->dev, &devattruio dma id))fFIGURE I: Relationship between UlOcore. UrO-DMA and niC driverAnd a interrupt handler which is usedAs depicted in Figure 1, there is a small piece ofknownledge the interrupt is optional(I have explained the reason in section 3code in the kernel part. This part of code providesthe corninumicatioin with the UIo core to allocate* If the interrupt is caused by ourand record the resources needed by our driver andwareregister a uio devicc which in behalf of our drivcr tomask all interrupt of our hw, and returnthe uio coreIRQ_HANDLEd else return IRQ_NONEstatic irqreturn_t uio_8139d_handler(uio_8139d__probe ()if (pci_enable_device(dev))goto out-freeif (pci-request_regions(dev,uio_8139)goto out-disable;The code above is almost all that we need to do inkernel space for a driverinfo->mem L0. addr pci_resource_start(dev, 1);Now let's turn to the userpart of the driverif (! info->mem [0]. addr)goto out-releaseAftcr wc insert thc kcrncl moduldcs of thc NICdriver(uio ko, k_8139 ko and uio_dma. ko), a lot ofinfo->em [0] name ="mem_ mapinfo->mem[o].internal addrfiles will be createdpci-ioremap_bar(dev, 1)m[0.internal-addr)goto out-releaseuiooul0-dmafo->rem[0」.izc主 resource len〔dev1);Sls /sys/class/uio/uio0info->mem [0]. memtype UIO_MEM_PHYS;addr name offset sizeinfo->。penuloinfo->release ul0 8139d releasenamc contains the cards control mcmory's namcinfo->name = uio 8139dregistered in the kernel part and size is the mem-info>version =0.0.1ory's size in bytes. 11io0 can be used to map theinfo->irq dev->irqinfo->irq-_flags IRQF-SHAREDards control memory to process's virtual memoryinfo->handler uio 8139d handlerspace while uio-dma is used to do the DMA relatedif (uio-register-device(&dev->dev, infooperatiOn. First, the control menory of the cards){should be mapped to userspaceint fd open ("/dev/uio0 ,D_RDWR)away. ) I ping the fake IP address on another maMap the register regions to processshine. the result is as followsvirtual memspaceuo driverid accessap(NULL, size_of-ctl,PROT READ PROT WRITE, MAP ShARED, fd-192.168.1.225 ping sta七1122 packets transmitted, 122 received, 0%packet loss, time 121001msrtt min/avg/max/mdevAfter the mmap operation, pointer access can be0.106/0.115/0.149/0.011msused as a base address to operate the cards registersThen i use the default in kernel driver of rtl8139Second, handling of the interrupt. In the inter-Do the samc ping tostrupt handling threadsin-kernel driverwhile(1)t/ Waiting for the interrupt. *---192.168 1.225 ping statisticsif (read (dev node ->dev->fds->dev fd,122 packets transmitted, 122 received, 0%irq_count, 4)!=4)packet loss, time 121003mscontinue jrtt min/avg/max/mdevread the interrupt status register *0.225/0.260/0.316/0.019msint status RTL R16 (IntrStatus)/* Unmask all interrupt *The results show that our uio driver works wellThird, the DMA operationl. To allocate the 6 Conclusion and Future workmemory for DMA, uio-dma-alloc( is called. Thedetails of this function:The userspace NiC driver can work properly and it/* allocate the uio dma area *ioctl(fd, UIO_DMA_ALLOC, (unsigned long)&bypasses the linux kernel network stack which willareg)implify the safety verification workmap the uio dma area to userspace, da->This approach also allows experimenting withaddr is the uio dma areas virtualaddress can be used by the userspacencw safcty rcalcd protocols as wcll as using thcscdriver */da->addr mmap (NUll, da->size, PROT_READwithout the need to integrate them in mainlinePROT WRITE MAP SHARED fd, da->Linux. This is especia lly important as integrationmmap_offset)iof special purpose code in the Linux kernel is ty pi-cally not simple and maintenance of mainline code isda-addr is the virtual address of the UIO-DMagenerally non-trivial as wellmemory bufferOf course. there are still some problems. IAfter the UIo-DMA memory areas is allocatethe current prototype implementation, we parsed themap DMA arca to a device is nccdedraw packct by ourself. Wc planned to cxtract theraw packet processing code from libpcap and designioctl( fd, UIO-DMA_MAP, (unsigned long) a more friendly interface of the driver. More in-depthnregand detailed experiments will be designed to evaluateIn the kernel space, dma_ single will be called the userspace nic drFor example, the contextto complete the required actions. As the unmapping switch cost of the userspace driver. the interrupt laof the UIO-DMA Illennory, I think you may get the tency and the performance cost incurred by the UIOanswer ioctl(fd, UIO__\ he kerneSimilarlDMA. The UIO-DMA implementation has not bccndma_unmap_single will be called inmerged into the mainline kernel vet. So we will tto optimize the current uIO-DMA implementationand integrate it, into the utO framework5 BenchmarkIn order to test if our uio driver can work properly7 Acknowledgmentsa icMP demon program is designed based on theuserspace RTL8139D driver. The structure of our We sincerely thank all those people who supportdemon is revealed in Figure: 1. The function of us to develop this solution. Especially we want tothe icMP demon program is just to send the ICMP thank Max Krasnyansky, Hans J. Koch. Greg Kroahreplies. In the ICMP implementaion, we assume Hartman. A special thank you goes to professorthat the 192. 168. 1. 226 is our IP address(The pack- Zhou Qingguo who gave somc important suggcstionsets whose dest IP are not 192.168. 1.225 are throw about this implementationReferences14 Documentation/ Doc Book/uiohowto tmpl[1] Userspace I/0 drivers in a realtime conteat, Hans [5 driver/uio/. Koch. Linutronix gmbh. 13th realtime linuxWorkshop6 driver/net/8139too.c2 Get More Device Drivers out of the Kernel!,Peter Chubb* NATIONAL ICT AUSTRALIA AND7 driver/net/via-rhinecTHE UNIVERSITY OF NEW SOUTH WALES18 Advanced Programming in the UNIX Environ-3 UIO-DMA kernel backend code, Max Krasnyanment Second Edition. w. Richard Stevenssky,maxk@qualcommm.comStephen A. rago
用户评论
码姐姐匿名网友 2020-07-30 11:43:34

给了我很大启发。

码姐姐匿名网友 2020-07-30 11:43:34

没大用到,不过还是谢谢了

码姐姐匿名网友 2020-07-30 11:43:34

比较简单,还是没有弄太明白