/* * This is the first field of the "visible" part of this structure * (i.e. as seen by users in the "Space.c" file). It is the name * the interface. */ char *name;
/* I/O specific fields - FIXME: Merge these and struct ifmap into one */ unsigned long rmem_end; /* shmem "recv" end */ unsigned long rmem_start; /* shmem "recv" start */ unsigned long mem_end; /* shared mem end */ unsigned long mem_start; /* shared mem start */ unsigned long base_addr; /* device I/O address */ unsigned char irq; /* device IRQ number */
/* Low-level status flags. */ volatile unsigned char start, /* start an Operation */ interrupt; /* interrupt arrived */ /* 在处理中断时interrupt设为1,处理完清0。 */ unsigned long tbusy; /* transmitter busy must be longg for bitops */
struct device *next;
/* The device initialization function. Called only once. */ /* 指向驱动程序的初始化方法。 */ int (*init)(struct device *dev);
/* Some hardware also needs these fields, but they are not part of the usual set specified in Space.c. */ /* 一些硬件可以在一块板上支持多个接口,可能用到if_port。 */ unsigned char if_port; /* Selectable AUI, TP,..*/ unsigned char dma; /* DMA channel */
/* * This marks the end of the "visible" part of the structure. All * fields hereafter are internal to the system, and may change at * will (read: may be cleaned up at will). */
/* These may be needed for future network-power-down code. */ /* trans_start记录最后一次成功发送的时间。可以用来确定硬件是否工作正常。*/ unsigned long trans_start; /* Time (in jiffies) of last Tx */ unsigned long last_rx; /* Time of last Rx */
/* flags里面有很多内容,定义在include/linux/if.h里。*/ unsigned short flags; /* interface flags (a la BSD) */ unsigned short family; /* address family ID (AF_INET) */ unsigned short metric; /* routing metric (not used) */ unsigned short mtu; /* interface MTU value */
/* type标明物理硬件的类型。主要说明硬件是否需要arp。定义在 include/linux/if_arp.h里。 */ unsigned short type; /* interface hardware type */
/* 上层协议层根据hard_header_len在发送数据缓冲区前面预留硬件帧头空间。*/ unsigned short hard_header_len; /* hardware hdr length */
/* priv指向驱动程序自己定义的一些参数。*/ void *priv; /* pointer to private data */
/* Interface address info. */ unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ unsigned char pad; /* make dev_addr alignedd to 8 bytes */ unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */ unsigned char addr_len; /* hardware address length */ unsigned long pa_addr; /* protocol address */ 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 */
/* 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,
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为设备名称。