【linux驱动分析】之dm9000驱动分析(五):另外几个重要的结构体

来源:互联网 发布:向量用矩阵表示 编辑:程序博客网 时间:2024/06/05 15:12
除了sk_buff和net_device,dm9000驱动中用到的另外几个重要的结构体
一、platform_driver
定义在include/linux/platform_device.h中,代码如下:
1 struct platform_driver {2     int (*probe)(struct platform_device *);3     int (*remove)(struct platform_device *);4     void (*shutdown)(struct platform_device *);5     int (*suspend)(struct platform_device *, pm_message_t state);6     int (*resume)(struct platform_device *);7     struct device_driver driver;8     const struct platform_device_id *id_table;9 };
dm9000.c中的初始化:
1 static struct platform_driver dm9000_driver = {2     .driver    = {3         .name    = "dm9000",4         .owner     = THIS_MODULE,5         .pm     = &dm9000_drv_pm_ops,6     },7     .probe   = dm9000_probe,8     .remove  = __devexit_p(dm9000_drv_remove),9 };
二、net_device_ops
操作网络设备的函数,定义在include/linux/netdevice.h中,它有很多成员,这里只列出dm9000驱动用到的:
 1 static const struct net_device_ops dm9000_netdev_ops = { 2     .ndo_open        = dm9000_open, 3     .ndo_stop        = dm9000_stop, 4     .ndo_start_xmit        = dm9000_start_xmit, 5     .ndo_tx_timeout        = dm9000_timeout, 6     .ndo_set_multicast_list    = dm9000_hash_table, 7     .ndo_do_ioctl        = dm9000_ioctl, 8     .ndo_change_mtu        = eth_change_mtu, 9     .ndo_validate_addr    = eth_validate_addr,10     .ndo_set_mac_address    = eth_mac_addr,11 #ifdef CONFIG_NET_POLL_CONTROLLER12     .ndo_poll_controller    = dm9000_poll_controller,13 #endif14 };

三、ethtool_ops
ethtool_ops定义在include/linux/ethtool.h中,它有很多成员,这里只列出dm9000驱动用到的:
 1 static const struct ethtool_ops dm9000_ethtool_ops = { 2     .get_drvinfo        = dm9000_get_drvinfo, 3     .get_settings        = dm9000_get_settings, 4     .set_settings        = dm9000_set_settings, 5     .get_msglevel        = dm9000_get_msglevel, 6     .set_msglevel        = dm9000_set_msglevel, 7     .nway_reset        = dm9000_nway_reset, 8     .get_link        = dm9000_get_link, 9     .get_wol        = dm9000_get_wol,10     .set_wol        = dm9000_set_wol,11      .get_eeprom_len        = dm9000_get_eeprom_len,12      .get_eeprom        = dm9000_get_eeprom,13      .set_eeprom        = dm9000_set_eeprom,14     .get_rx_csum        = dm9000_get_rx_csum,15     .set_rx_csum        = dm9000_set_rx_csum,16     .get_tx_csum        = ethtool_op_get_tx_csum,17     .set_tx_csum        = dm9000_set_tx_csum,18 };
四、board_info
用来保存芯片相关的一些信息。
 1 /* Structure/enum declaration ------------------------------- */ 2 typedef struct board_info { 3  4     void __iomem    *io_addr;    /* Register I/O base address */ 5     void __iomem    *io_data;    /* Data I/O address */ 6     u16         irq;        /* IRQ */ 7  8     u16        tx_pkt_cnt; 9     u16        queue_pkt_len;10     u16        queue_start_addr;11     u16        queue_ip_summed;12     u16        dbug_cnt;13     u8        io_mode;        /* 0:word, 2:byte */14     u8        phy_addr;15     u8        imr_all;16 17     unsigned int    flags;18     unsigned int    in_suspend :1;19     unsigned int    wake_supported :1;20     int        debug_level;21 22     enum dm9000_type type;23 24     void (*inblk)(void __iomem *port, void *data, int length);25     void (*outblk)(void __iomem *port, void *data, int length);26     void (*dumpblk)(void __iomem *port, int length);27 28     struct device    *dev;         /* parent device */29 30     struct resource    *addr_res;   /* resources found */31     struct resource *data_res;32     struct resource    *addr_req;   /* resources requested */33     struct resource *data_req;34     struct resource *irq_res;35 36     int         irq_wake;37 38     struct mutex     addr_lock;    /* phy and eeprom access lock */39 40     struct delayed_work phy_poll;41     struct net_device  *ndev;42 43     spinlock_t    lock;44 45     struct mii_if_info mii;46     u32        msg_enable;47     u32        wake_state;48 49     int        rx_csum;50     int        can_csum;51     int        ip_summed;52 } board_info_t;

20 0