资源描述:
《LinuxTCPIP协议详注之数据包的接收》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、LinuxTCP/IP协议详注之数据包的接收与其说这篇文章分析了网卡驱动中中数据包的接收,还不如说是以e100为例,对网卡驱动编写的一个说明。当然,对数据包的接收说的很清楚。转载数据包的接收作者:kendoKernel:2.6.12一、从网卡说起这并非是一个网卡驱动分析的专门文档,只是对网卡处理数据包的流程进行一个重点的分析。这里以Intel的e100驱动为例进行分析。大多数网卡都是一个PCI设备,PCI设备都包含了一个标准的配置寄存器,寄存器中,包含了PCI设备的厂商ID、设备ID等等信息,驱动程序使用来描述这些寄存器的标识符。如下:CODE:structpci_device_id{__u3
2、2vendor,device;/*VendoranddeviceIDorPCI_ANY_ID*/__u32subvendor,subdevice;/*SubsystemID'sorPCI_ANY_ID*/__u32class,class_mask;/*(class,subclass,prog-if)triplet*/kernel_ulong_tdriver_data;/*Dataprivatetothedriver*/};这样,在驱动程序中,常常就可以看到定义一个structpci_device_id类型的数组,告诉内核支持不同类型的PCI设备的列表,以e100驱动为例:#defineINTE
3、L_8255X_ETHERNET_DEVICE(device_id,ich){PCI_VENDOR_ID_INTEL,device_id,PCI_ANY_ID,PCI_ANY_ID,PCI_CLASS_NETWORK_ETHERNET<<8,0xFFFF00,ich}staticstructpci_device_ide100_id_table[]={INTEL_8255X_ETHERNET_DEVICE(0x1029,0),INTEL_8255X_ETHERNET_DEVICE(0x1030,0),INTEL_8255X_ETHERNET_DEVICE(0x1031,3),……/*略过一大
4、堆支持的设备*/{0,}};在内核中,一个PCI设备,使用structpci_driver结构来描述,structpci_driver{structlist_headnode;char*name;structmodule*owner;conststructpci_device_id*id_table;/*mustbenon-NULLforprobetobecalled*/int(*probe)(structpci_dev*dev,conststructpci_device_id*id);/*Newdeviceinserted*/void(*remove)(structpci_dev*dev);
5、/*Deviceremoved(NULLifnotahot-plugcapabledriver)*/int(*suspend)(structpci_dev*dev,pm_message_tstate);/*Devicesuspended*/int(*resume)(structpci_dev*dev);/*Devicewokenup*/int(*enable_wake)(structpci_dev*dev,pci_power_tstate,intenable);/*Enablewakeevent*/void(*shutdown)(structpci_dev*dev);structdevice_
6、driverdriver;structpci_dynidsdynids;};因为在系统引导的时候,PCI设备已经被识别,当内核发现一个已经检测到的设备同驱动注册的id_table中的信息相匹配时,它就会触发驱动的probe函数,以e100为例:/**定义一个名为e100_driver的PCI设备*1、设备的探测函数为e100_probe;*2、设备的id_table表为e100_id_table*/staticstructpci_drivere100_driver={.name=DRV_NAME,.id_table=e100_id_table,.probe=e100_probe,.remove
7、=__devexit_p(e100_remove),#ifdefCONFIG_PM.suspend=e100_suspend,.resume=e100_resume,#endif.driver={.shutdown=e100_shutdown,}};这样,如果系统检测到有与id_table中对应的设备时,就调用驱动的probe函数。驱动设备在init函数中,调用pci_module_init函数初