Linux 网卡驱动相关——03
struct priv_struct *mycard_priv;
netdev = alloc_etherdev(sizeof(struct priv_struct));
mycard_priv = netdev->priv;
#include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> #include <linux/ethtool.h> struct net_device_stats mycard_stats; /* Statistics */ /* Fill ethtool_ops methods from a suitable place in the driver */ struct ethtool_ops mycard_ethtool_ops = {/* ... */.get_eeprom = mycard_get_eeprom, /* Dump EEPROM contents *//* ... */ }; /* Initialize/probe the card. For PCI cards, this is invokedfrom (or is itself) the probe() method. In that case, thefunction is declared as:static struct net_device *init_mycard(struct pci_dev *pdev, conststruct pci_device_id *id) */ static struct net_device * init_mycard() {struct net_device *netdev;struct priv_struct mycard_priv;/* ... */netdev = alloc_etherdev(sizeof(struct priv_struct));/* Common methods */netdev->netdev_ops = &my_netdev_ops;dev->ethtool_ops = &my_ethtool_ops;dev->watchdog_timeo = TX_TIMEOUT;netif_napi_add(dev, &tp->napi, my_poll, 64);/* Register the interface */register_netdev(netdev);/* ... *//* Get MAC address from attached EEPROM *//* ... *//* Download microcode if needed *//* ... */ } /* The interrupt handler */ static irqreturn_t mycard_interrupt(int irq, void *dev_id) {struct net_device *netdev = dev_id;struct sk_buff *skb;unsigned int length;/* ... */if (receive_interrupt) {/* We were interrupted due to packet reception. At this point,the NIC has already DMA'ed received data to an sk_buff thatwas pre-allocated and mapped during device open. Obtain theaddress of the sk_buff depending on your data structuredesign and assign it to 'skb'. 'length' is similarly obtainedfrom the NIC by reading the descriptor used to DMA data fromthe card. Now, skb->data contains the receive data. *//* ... *//* For PCI cards, perform a pci_unmap_single() on thereceived buffer in order to allow the CPU to access it *//* ... *//* Allow the data go to the tail of the packet by movingskb->tail down by length bytes and increasingskb->len correspondingly */skb_put(skb, length)/* Pass the packet to the TCP/IP stack */ #if !defined (USE_NAPI) /* Do it the old way */netif_rx(skb); #else /* Do it the NAPI way */if (napi_schedule_prep(&priv->napi))) {/* Disable NIC interrupt. Implementation not shown. */disable_nic_interrupt(); /* Post the packet to the protocol layer andadd the device to the poll list */__napi_schedule(&priv->napi);} #endif} else if (tx_complete_interrupt) {/* Transmit Complete Interrupt *//* ... *//* Unmap and free transmit resources such asDMA descriptors and buffers. Free sk_buffs orreclaim them into a free pool *//* ... */ } } /* Driver open */ static int mycard_open(struct net_device *netdev) {/* ... *//* Request irq */request_irq(irq, mycard_interrupt, IRQF_SHARED,netdev->name, dev);/* Fill transmit and receive rings *//* See the section,"Buffer Management and Concurrency Control" *//* ... *//* Provide free descriptor addresses to the card *//* ... *//* Convey your readiness to accept data from thenetworking stack */netif_start_queue(netdev);/* ... */ } /* Driver close */ static int mycard_close(struct net_device *netdev) {/* ... *//* Ask the networking stack to stop sending down data */netif_stop_queue(netdev);/* ... */ } /* Called when the device is unplugged or when the module isreleased. For PCI cards, this is invoked from (or is itself)the remove() method. In that case, the function is declared as:static void __devexit mycard_remove(struct pci_dev *pdev) */ static void __devexit mycard_remove(){struct net_device *netdev;/* ... *//* For a PCI card, obtain the associated netdev as follows,assuming that the probe() method performed a correspondingpci_set_drvdata(pdev, netdev) after allocating the netdev */netdev = pci_get_drvdata(pdev); /*unregister_netdev(netdev); /* Reverse of register_netdev() *//* ... */free_netdev(netdev); /* Reverse of alloc_netdev() *//* ... */ } /* Suspend method. For PCI devices, this is part ofthe pci_driver structure discussed in Chapter 10 */ static int mycard_suspend(struct pci_dev *pdev, pm_message_t state) {/* ... */netif_device_detach(netdev);/* ... */ } /* Resume method. For PCI devices, this is part ofthe pci_driver structure discussed in Chapter 10 */ static int mycard_resume(struct pci_dev *pdev) {/* ... */netif_device_attach(netdev);/* ... */ } /* Get statistics */ static struct net_device_stats * mycard_get_stats(struct net_device *netdev) {/* House keeping *//* ... */return(&mycard_stats); } /* Dump EEPROM contents. This is an ethtool_ops operation */ static int mycard_get_eeprom(struct net_device *netdev,struct ethtool_eeprom *eeprom, uint8_t *bytes) {/* Read data from the accompanying EEPROM *//* ... */ }/* Poll method */ static int mycard_poll(struct net_device *netdev, int *budget) {/* Post packets to the protocol layer usingnetif_receive_skb() *//* ... */if (no_more_ingress_packets()){/* Remove the device from the polled list */__napi_complete(netdev);/* Fall back to interrupt mode. Implementation not shown */enable_nic_interrupt();return 0;} } /* Transmit method */ static int mycard_xmit_frame(struct sk_buff *skb, struct net_device *netdev) {/* DMA the transmit packet from the associated sk_buffto card memory *//* ... *//* Manage buffers *//* ... */ }
Linux 网卡驱动相关——03相关推荐
- linux双网卡驱动配置,linux网卡驱动安装、双网卡绑定
本次课程包含RAID0/1/5/6/10/50/60配置实验(使用Dell R720服务器实验).Redhat/CentOS/ubuntu/windows操作系统安装.windows/linux网卡绑 ...
- 6.S081 lab: networking e1000 网卡驱动 附 Linux 网卡驱动编写分析
本文是 6.S081 操作系统课程学习最后一个 lab,编写一个 intel 的 e1000 网卡的驱动在 xv6 下.需要复习知识有:操作系统知识,计算机组成原理 DMA 相关,循环缓冲区的概念,e ...
- linux网卡驱动源码分析(一)
linux网卡驱动源码分析(一) linux struct linux内核 网络 descriptor resources 转自http://blog.csdn.net/ustc_dylan/arti ...
- linux网卡驱动对XDP支持情况
各个网卡厂商对应的Linux内核驱动如下 Mellanox: mlx4 (4.8) and mlx5 (4.9) QLogic/Cavium: qede (4.10) Virtio_net: (4.1 ...
- linux网卡驱动离线安装_Linux网卡驱动的安装方式
如何安装Linux网卡驱动呢,看看下面的说明. 适用机型: 所有xSeries 205; 所有xSeries 206; 所有xSeries 225; 所有xSeries 226; 所有xSeries ...
- linux网卡驱动开发视频,Linux下网卡驱动程序的开发.doc
Linux下网卡驱动程序的开发 论文题目:Linux下网卡驱动程序的开发 专 业: 年 级: 学生学号: 学生姓名: 指导教师: 完成时间: Linux下网卡驱动程序的开发 八年经验 专业指导毕业设计 ...
- Linux网卡驱动分析之RTL8139(五)
Linux网卡驱动分析之RTL8139(五) deliver_skb(dev.c) // 该函数就是调用个协议的接收函数处理该skb 包,进入第三层网络层处理 static __inline__ in ...
- Linux网卡驱动设计
Linux网卡驱动设计 Linux网络体系结构 Linux的优点之一在于它丰富而稳定的网络协议栈.其范围从协议无关层到各种具体的网络协议实现. 协议层次对比图 网络接口层提供访问物理设备的驱动程序,对 ...
- linux网卡驱动 pdf,Linux下网卡驱动程序.pdf
zekairecv 于 2015-10-04 00:58:57发表: 谢谢 weilee1 于 2015-04-19 17:41:05发表: 看看 雪语阑风 于 2014-12-04 11:03:39 ...
最新文章
- Linux字符设备驱动程序的框架(新写法)
- python注册登录系统_Python实现简单用户注册信息管理系统
- linux系统中的目录讲解
- HTML 块标签,行内标签,行内块标签以及之间的相互转换
- js监听只读文本框_js 动态控制 input 框 的只读属性
- pycharm python部署_使用PyCharm配合部署Python的Django框架的配置纪实
- day10 java的this关键字
- 机器学习笔记(6):多类逻辑回归-使用gluon
- 数据可视化工具的意义有哪些
- Python(五):list、tuple
- Javascript+PHP实现在线拍照功能
- 间接访问百度浏览器c语言程序,百度浏览器支持“.网址”域名访问 让中文上网更便捷...
- 网站运营的9个常用搜索技巧
- 良仓远行 · 硅谷遇上西雅图,同游招募
- 电信联通提高手机补贴
- wpa_supplicant、hostapd编译
- Scrolling and zooming chart with ChartScroller
- 微信扫描下载提示以及js判断用户手机系统
- Aop介绍 ,aop使用 aop解释
- centos命令行常用快捷键