Linux網(wǎng)卡驅(qū)動程序編寫
{
/*
*Thisisthefirstfieldofthevisiblepartofthisstructure
*(i.e.asseenbyusersintheSpace.cfile).Itisthename
*theinterface.
*/
char*name;
/*I/Ospecificfields-FIXME:Mergetheseandstructifmapintoone*/
unsignedlongrmem_end;/*shmemrecvend*/
unsignedlongrmem_start;/*shmemrecvstart*/
unsignedlongmem_end;/*sharedmemend*/
unsignedlongmem_start;/*sharedmemstart*/
unsignedlongbase_addr;/*deviceI/Oaddress*/
unsignedcharirq;/*deviceIRQnumber*/
/*Low-levelstatusflags.*/
volatileunsignedcharstart,/*startanoperation*/
interrupt;/*interruptarrived*/
/*在處理中斷時interrupt設為1,處理完清0。*/
unsignedlongtbusy;/*transmitterbusymustbelongfor
bitops*/
structdevice*next;
/*Thedeviceinitializationfunction.Calledonlyonce.*/
/*指向驅(qū)動程序的初始化方法。*/
int(*init)(structdevice*dev);
/*Somehardwarealsoneedsthesefields,buttheyarenotpartofthe
usualsetspecifiedinSpace.c.*/
/*一些硬件可以在一塊板上支持多個接口,可能用到if_port。*/
unsignedcharif_port;/*SelectableAUI,TP,..*/
unsignedchardma;/*DMAchannel*/
structenet_statistics*(*get_stats)(structdevice*dev);
/*
*Thismarkstheendofthevisiblepartofthestructure.All
*fieldshereafterareinternaltothesystem,andmaychangeat
*will(read:maybecleanedupatwill).
*/
/*Thesemaybeneededforfuturenetwork-power-downcode.*/
/*trans_start記錄最后一次成功發(fā)送的時間??梢杂脕泶_定硬件是否工作正常。*/
unsignedlongtrans_start;/*Time(injiffies)oflastTx*/
unsignedlonglast_rx;/*TimeoflastRx*/
/*flags里面有很多內(nèi)容,定義在include/linux/if.h里。*/
unsignedshortflags;/*interfaceflags(alaBSD)*/
unsignedshortfamily;/*addressfamilyID(AF_INET)*/
unsignedshortmetric;/*routingmetric(notused)*/
unsignedshortmtu;/*interfaceMTUvalue*/
/*type標明物理硬件的類型。主要說明硬件是否需要arp。定義在
include/linux/if_arp.h里。*/
unsignedshorttype;/*interfacehardwaretype*/
/*上層協(xié)議層根據(jù)hard_header_len在發(fā)送數(shù)據(jù)緩沖區(qū)前面預留硬件幀頭空間。*/
unsignedshorthard_header_len;/*hardwarehdrlength*/
/*priv指向驅(qū)動程序自己定義的一些參數(shù)。*/
void*priv;/*pointertoprivatedata*/
/*Interfaceaddressinfo.*/
unsignedcharbroadcast[MAX_ADDR_LEN];/*hwbcastadd*/
unsignedcharpad;/*makedev_addralignedto8
bytes*/
unsignedchardev_addr[MAX_ADDR_LEN];/*hwaddress*/
unsignedcharaddr_len;/*hardwareaddresslength*/
unsignedlongpa_addr;/*protocoladdress*/
unsignedlongpa_brdaddr;/*protocolbroadcastaddr*/
unsignedlongpa_dstaddr;/*protocolP-Pothersideaddr*/
unsignedlongpa_mask;/*protocolnetmask*/
unsignedshortpa_alen;/*protocoladdresslength*/
structdev_mc_list*mc_list;/*Multicastmacaddresses*/
intmc_count;/*Numberofinstalledmcasts*/
structip_mc_list*ip_mc_list;/*IPmulticastfilterchain*/
__u32tx_queue_len;/*Maxframesperqueueallowed*/
/*Forloadbalancingdriverpairsupport*/
unsignedlongpkt_queue;/*Packetsqueued*/
structdevice*slave;/*Slavedevice*/
structnet_alias_info*alias_info;/*maindevaliasinfo*/
structnet_alias*my_alias;/*aliasdevs*/
/*Pointertotheinterfacebuffers.*/
structsk_buff_headbuffs[DEV_NUMBUFFS];
/*Pointerstointerfaceserviceroutines.*/
int(*open)(structdevice*dev);
int(*stop)(structdevice*dev);
int(*hard_start_xmit)(structsk_buff*skb,
structdevice*dev);
int(*hard_header)(structsk_buff*skb,
structdevice*dev,
unsignedshorttype,
void*daddr,
void*saddr,
unsignedlen);
int(*rebuild_header)(void*eth,structdevice*dev,
unsignedlongraddr,structsk_buff*skb);
#defineHAVE_MULTICAST
void(*set_multicast_list)(structdevice*dev);
#defineHAVE_SET_MAC_ADDR
int(*set_mac_address)(structdevice*dev,void*addr);
#defineHAVE_PRIVATE_IOCTL
int(*do_ioctl)(structdevice*dev,structifreq*ifr,intcmd);
#defineHAVE_SET_CONFIG
int(*set_config)(structdevice*dev,structifmap*map);
#defineHAVE_HEADER_CACHE
void(*header_cache_bind)(structhh_cache**hhp,structdevice
*dev,unsignedshorthtype,__u32daddr);
void(*header_cache_update)(structhh_cache*hh,structdevice
*dev,unsignedchar*haddr);
#defineHAVE_CHANGE_MTU
int(*change_mtu)(structdevice*dev,intnew_mtu);
structiw_statistics*(*get_wireless_stats)(structdevice*dev);
};
2.4常用的系統(tǒng)支持
2.4.1內(nèi)存申請和釋放
include/linux/kernel.h里聲明了kmalloc()和kfree()。用于在內(nèi)核模式下申請和釋放內(nèi)存。
void*kmalloc(unsignedintlen,intpriority);
voidkfree(void*__ptr);
linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)
評論