unsigned long pa_brdaddr; /* protocol broadcast addr */
unsigned long pa_dstaddr; /* protocol P-P other side addr */
unsigned long pa_mask; /* protocol netmask */
unsigned short pa_alen; /* protocol address length */
struct dev_mc_list *mc_list; /* Multicast mac addresses */
int mc_count; /* Number of installed mcasts */
struct ip_mc_list *ip_mc_list; /* IP multicast filter chain */
__u32 tx_queue_len; /* Max frames per queue allowed */
------------------ Linux作業系統網路驅動程式編寫 ------------------- ------------ Contact the author by mailto:bordi@bordi.dhs.org ------
/* For load balancing driver pair support */
unsigned long pkt_queue; /* Packets queued */ struct device *slave; /* Slave device */ struct net_alias_info *alias_info; /* main dev alias info */ struct net_alias *my_alias; /* alias devs */
/* Pointer to the interface buffers. */ struct sk_buff_head buffs[DEV_NUMBUFFS];
/* Pointers to interface service routines. */ int (*open)(struct device *dev); int (*stop)(struct device *dev); int (*hard_start_xmit) (struct sk_buff *skb, struct device *dev); int (*hard_header) (struct sk_buff *skb, struct device *dev, unsigned short type, void *daddr, void *saddr, unsigned len); int (*rebuild_header)(void *eth, struct device *dev,
unsigned long raddr, struct sk_buff *skb);
#define HAVE_MULTICAST void (*set_multicast_list)(struct device *dev); #define HAVE_SET_MAC_ADDR int (*set_mac_address)(struct device *dev, void *addr); #define HAVE_PRIVATE_IOCTL int (*do_ioctl)(struct device *dev, struct ifreq *ifr, int cmd); #define HAVE_SET_CONFIG int (*set_config)(struct device *dev, struct ifmap *map); #define HAVE_HEADER_CACHE void (*header_cache_bind)(struct hh_cache **hhp, struct device *dev, unsigned short htype, __u32 daddr); void (*header_cache_update)(struct hh_cache *hh, struct device *dev, unsigned char * haddr); #define HAVE_CHANGE_MTU int (*change_mtu)(struct device *dev, int new_mtu);
------------------ Linux作業系統網路驅動程式編寫 ------------------- ------------ Contact the author by mailto:bordi@bordi.dhs.org ------
個timer_list加進定時佇列。
2.4.4 I/O I/O埠的存取使用: inline unsigned int inb(unsigned short port); inline unsigned int inb_p(unsigned short port); inline void outb(char value, unsigned short port); inline void outb_p(char value, unsigned short port); 在include/adm/io.h裏定義。 inb_p()、outb_p()與inb()、outb_p()的不同在於前者在存取I/O時有等待 (pause)一適應慢速的I/O設備。 為了防止存取I/O時發生衝突,Linux提供對埠使用情況的控制。在使用埠 之前,可以檢查需要的I/O是否正在被使用,如果沒有,則把埠標記為正在使用, 使用完後再釋放。系統提供以下幾個函數做這些工作。 int check_region(unsigned int from, unsigned int extent); void request_region(unsigned int from, unsigned int extent,const char *name); void release_region(unsigned int from, unsigned int extent); 其中的參數from表示用到的I/O埠的起始位址,extent標明從from開始的端 口數目。name為設備名稱。
-------------------------------------------------- | Tail room(free) | -------------------------------------------------- After alloc_skb()
-------------------------------------------------- | Head room | Tail room(free) | -------------------------------------------------- After skb_reserve()
-------------------------------------------------- | Head room | Data area | Tail room(free) | -------------------------------------------------- After skb_put()
-------------------------------------------------- |Head| skb_ | Data | Tail room(free) | |room| push | | | | | Data area | | -------------------------------------------------- After skb_push()
-------------------------------------------------- | Head | skb_ | Data area | Tail room(free) | | | pull | | | | Head room | | | -------------------------------------------------- After skb_pull()
------------------ Linux作業系統網路驅動程式編寫 ------------------- ------------ Contact the author by mailto:bordi@bordi.dhs.org ------
三.編寫Linux網路驅動程式中需要注意的問題
3.1 中斷共用 Linux系統運行幾個設備共用同一個中斷。需要共用的話,在申請的時候指明 共用方式。系統提供的request_irq()調用的定義: int request_irq(unsigned int irq, void (*handler)(int irq, void *dev_id, struct pt_regs *regs), unsigned long irqflags, const char * devname, void *dev_id); 如果共用中斷,irqflags設置SA_SHIRQ屬性,這樣就允許別的設備申請同一個 中斷。需要注意所有用到這個中斷的設備在調用request_irq()都必須設置這個屬 性。系統在回調每個中斷處理程式時,可以用dev_id這個參數找到相應的設備。一 般dev_id就設為device結構本身。系統處理共用中斷是用各自的dev_id參數依次調 用每一個中斷處理程式。