Linux网络驱动程序编写(二)5

Linux网络驱动程序编写(二)5

2001-06-15· ·Bordi··饮水思源站

上一页  1 2 3 4 5  

2.3 网络驱动程序中用到的数据结构
      最重要的是网络设备的数据结构。定义在include/linux/netdevice.h里。它的注释已经足够详尽。
struct device
{

  /*
   * 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_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 long
 for

  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。 */
  /* 一些硬件可以在一块板上支持多个接口,可能用到if_port。 */
  unsigned char           if_port;              /* Selectable AUI, TP,..*/
  unsigned char           dma;                  /* DMA channel          */

  struct enet_statistics* (*get_stats)(struct device *dev);

  /*
   * 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 aligned
 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             */

  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                     (*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 dev
ice
*dev, unsigned short htype, __u32 daddr);
*dev, unsigned short htype, __u32 daddr);
  void                    (*header_cache_update)(struct hh_cache *hh, struct dev
ice
*dev, unsigned char *  haddr);
#define HAVE_CHANGE_MTU

  struct iw_statistics*   (*get_wireless_stats)(struct device *dev);
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值