【linux驱动分析】之dm9000驱动分析(四):net_device结构体

net_device结构体,定义在include/linux/netdevice.h中,这是一个很复杂的结构体,先把代码清单列出来,再用到的过程中,逐步分析,最后来这里做个总结。
下面的代码是linux-2.6.38中的。
  1 /*
  2  *    The DEVICE structure.
  3  *    Actually, this whole structure is a big mistake.  It mixes I/O
  4  *    data with strictly "high-level" data, and it has to know about
  5  *    almost every data structure used in the INET module.
  6  *
  7  *    FIXME: cleanup struct net_device such that network protocol info
  8  *    moves out.
  9  */
 10 
 11 struct net_device {
 12 
 13     /*
 14      * This is the first field of the "visible" part of this structure
 15      * (i.e. as seen by users in the "Space.c" file).  It is the name
 16      * of the interface.
 17      */
 18     char            name[IFNAMSIZ];
 19 
 20     struct pm_qos_request_list pm_qos_req;
 21 
 22     /* device name hash chain */
 23     struct hlist_node    name_hlist;
 24     /* snmp alias */
 25     char             *ifalias;
 26 
 27     /*
 28      *    I/O specific fields
 29      *    FIXME: Merge these and struct ifmap into one
 30      */
 31     unsigned long        mem_end;    /* shared mem end    */
 32     unsigned long        mem_start;    /* shared mem start    */
 33     unsigned long        base_addr;    /* device I/O address    */
 34     unsigned int        irq;        /* device IRQ number    */
 35 
 36     /*
 37      *    Some hardware also needs these fields, but they are not
 38      *    part of the usual set specified in Space.c.
 39      */
 40 
 41     unsigned char        if_port;    /* Selectable AUI, TP,..*/
 42     unsigned char        dma;        /* DMA channel        */
 43 
 44     unsigned long        state;
 45 
 46     struct list_head    dev_list;
 47     struct list_head    napi_list;
 48     struct list_head    unreg_list;
 49 
 50     /* Net device features */
 51     unsigned long        features;
 52 #define NETIF_F_SG        1    /* Scatter/gather IO. */
 53 #define NETIF_F_IP_CSUM        2    /* Can checksum TCP/UDP over IPv4. */
 54 #define NETIF_F_NO_CSUM        4    /* Does not require checksum. F.e. loopack. */
 55 #define NETIF_F_HW_CSUM        8    /* Can checksum all the packets. */
 56 #define NETIF_F_IPV6_CSUM    16    /* Can checksum TCP/UDP over IPV6 */
 57 #define NETIF_F_HIGHDMA        32    /* Can DMA to high memory. */
 58 #define NETIF_F_FRAGLIST    64    /* Scatter/gather IO. */
 59 #define NETIF_F_HW_VLAN_TX    128    /* Transmit VLAN hw acceleration */
 60 #define NETIF_F_HW_VLAN_RX    256    /* Receive VLAN hw acceleration */
 61 #define NETIF_F_HW_VLAN_FILTER    512    /* Receive filtering on VLAN */
 62 #define NETIF_F_VLAN_CHALLENGED    1024    /* Device cannot handle VLAN packets */
 63 #define NETIF_F_GSO        2048    /* Enable software GSO. */
 64 #define NETIF_F_LLTX        4096    /* LockLess TX - deprecated. Please */
 65                     /* do not use LLTX in new drivers */
 66 #define NETIF_F_NETNS_LOCAL    8192    /* Does not change network namespaces */
 67 #define NETIF_F_GRO        16384    /* Generic receive offload */
 68 #define NETIF_F_LRO        32768    /* large receive offload */
 69 
 70 /* the GSO_MASK reserves bits 16 through 23 */
 71 #define NETIF_F_FCOE_CRC    (1 << 24) /* FCoE CRC32 */
 72 #define NETIF_F_SCTP_CSUM    (1 << 25) /* SCTP checksum offload */
 73 #define NETIF_F_FCOE_MTU    (1 << 26) /* Supports max FCoE MTU, 2158 bytes*/
 74 #define NETIF_F_NTUPLE        (1 << 27) /* N-tuple filters supported */
 75 #define NETIF_F_RXHASH        (1 << 28) /* Receive hashing offload */
 76 
 77     /* Segmentation offload features */
 78 #define NETIF_F_GSO_SHIFT    16
 79 #define NETIF_F_GSO_MASK    0x00ff0000
 80 #define NETIF_F_TSO        (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT)
 81 #define NETIF_F_UFO        (SKB_GSO_UDP << NETIF_F_GSO_SHIFT)
 82 #define NETIF_F_GSO_ROBUST    (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT)
 83 #define NETIF_F_TSO_ECN        (SKB_GSO_TCP_ECN << NETIF_F_GSO_SHIFT)
 84 #define NETIF_F_TSO6        (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)
 85 #define NETIF_F_FSO        (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT)
 86 
 87     /* List of features with software fallbacks. */
 88 #define NETIF_F_GSO_SOFTWARE    (NETIF_F_TSO | NETIF_F_TSO_ECN | \
 89                  NETIF_F_TSO6 | NETIF_F_UFO)
 90 
 91 
 92 #define NETIF_F_GEN_CSUM    (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)
 93 #define NETIF_F_V4_CSUM        (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM)
 94 #define NETIF_F_V6_CSUM        (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)
 95 #define NETIF_F_ALL_CSUM    (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM)
 96 
 97     /*
 98      * If one device supports one of these features, then enable them
 99      * for all in netdev_increment_features.
100      */
101 #define NETIF_F_ONE_FOR_ALL    (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \
102                  NETIF_F_SG | NETIF_F_HIGHDMA |        \
103                  NETIF_F_FRAGLIST)
104 
105     /* Interface index. Unique device identifier    */
106     int            ifindex;
107     int            iflink;
108 
109     struct net_device_stats    stats;
110     atomic_long_t        rx_dropped; /* dropped packets by core network
111                          * Do not use this in drivers.
112                          */
113 
114 #ifdef CONFIG_WIRELESS_EXT
115     /* List of functions to handle Wireless Extensions (instead of ioctl).
116      * See  for details. Jean II */
117     const struct iw_handler_def *    wireless_handlers;
118     /* Instance data managed by the core of Wireless Extensions. */
119     struct iw_public_data *    wireless_data;
120 #endif
121     /* Management operations */
122     const struct net_device_ops *netdev_ops;
123     const struct ethtool_ops *ethtool_ops;
124 
125     /* Hardware header description */
126     const struct header_ops *header_ops;
127 
128     unsigned int        flags;    /* interface flags (a la BSD)    */
129     unsigned short        gflags;
130         unsigned int            priv_flags; /* Like 'flags' but invisible to userspace. */
131     unsigned short        padded;    /* How much padding added by alloc_netdev() */
132 
133     unsigned char        operstate; /* RFC2863 operstate */
134     unsigned char        link_mode; /* mapping policy to operstate */
135 
136     unsigned int        mtu;    /* interface MTU value        */
137     unsigned short        type;    /* interface hardware type    */
138     unsigned short        hard_header_len;    /* hardware hdr length    */
139 
140     /* extra head- and tailroom the hardware may need, but not in all cases
141      * can this be guaranteed, especially tailroom. Some cases also use
142      * LL_MAX_HEADER instead to allocate the skb.
143      */
144     unsigned short        needed_headroom;
145     unsigned short        needed_tailroom;
146 
147     /* Interface address info. */
148     unsigned char        perm_addr[MAX_ADDR_LEN]; /* permanent hw address */
149     unsigned char        addr_assign_type; /* hw address assignment type */
150     unsigned char        addr_len;    /* hardware address length    */
151     unsigned short          dev_id;        /* for shared network cards */
152 
153     spinlock_t        addr_list_lock;
154     struct netdev_hw_addr_list    uc;    /* Unicast mac addresses */
155     struct netdev_hw_addr_list    mc;    /* Multicast mac addresses */
156     int            uc_promisc;
157     unsigned int        promiscuity;
158     unsigned int        allmulti;
159 
160 
161     /* Protocol specific pointers */
162 
163 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
164     struct vlan_group __rcu    *vlgrp;        /* VLAN group */
165 #endif
166 #ifdef CONFIG_NET_DSA
167     void            *dsa_ptr;    /* dsa specific data */
168 #endif
169     void             *atalk_ptr;    /* AppleTalk link     */
170     struct in_device __rcu    *ip_ptr;    /* IPv4 specific data    */
171     struct dn_dev __rcu     *dn_ptr;        /* DECnet specific data */
172     struct inet6_dev __rcu    *ip6_ptr;       /* IPv6 specific data */
173     void            *ec_ptr;    /* Econet specific data    */
174     void            *ax25_ptr;    /* AX.25 specific data */
175     struct wireless_dev    *ieee80211_ptr;    /* IEEE 802.11 specific data,
176                            assign before registering */
177 
178 /*
179  * Cache lines mostly used on receive path (including eth_type_trans())
180  */
181     unsigned long        last_rx;    /* Time of last Rx
182                          * This should not be set in
183                          * drivers, unless really needed,
184                          * because network stack (bonding)
185                          * use it if/when necessary, to
186                          * avoid dirtying this cache line.
187                          */
188 
189     struct net_device    *master; /* Pointer to master device of a group,
190                       * which this device is member of.
191                       */
192 
193     /* Interface address info used in eth_type_trans() */
194     unsigned char        *dev_addr;    /* hw address, (before bcast
195                            because most packets are
196                            unicast) */
197 
198     struct netdev_hw_addr_list    dev_addrs; /* list of device
199                               hw addresses */
200 
201     unsigned char        broadcast[MAX_ADDR_LEN];    /* hw bcast add    */
202 
203 #ifdef CONFIG_RPS
204     struct kset        *queues_kset;
205 
206     struct netdev_rx_queue    *_rx;
207 
208     /* Number of RX queues allocated at register_netdev() time */
209     unsigned int        num_rx_queues;
210 
211     /* Number of RX queues currently active in device */
212     unsigned int        real_num_rx_queues;
213 #endif
214 
215     rx_handler_func_t __rcu    *rx_handler;
216     void __rcu        *rx_handler_data;
217 
218     struct netdev_queue __rcu *ingress_queue;
219 
220 /*
221  * Cache lines mostly used on transmit path
222  */
223     struct netdev_queue    *_tx ____cacheline_aligned_in_smp;
224 
225     /* Number of TX queues allocated at alloc_netdev_mq() time  */
226     unsigned int        num_tx_queues;
227 
228     /* Number of TX queues currently active in device  */
229     unsigned int        real_num_tx_queues;
230 
231     /* root qdisc from userspace point of view */
232     struct Qdisc        *qdisc;
233 
234     unsigned long        tx_queue_len;    /* Max frames per queue allowed */
235     spinlock_t        tx_global_lock;
236 
237 #ifdef CONFIG_XPS
238     struct xps_dev_maps __rcu *xps_maps;
239 #endif
240 
241     /* These may be needed for future network-power-down code. */
242 
243     /*
244      * trans_start here is expensive for high speed devices on SMP,
245      * please use netdev_queue->trans_start instead.
246      */
247     unsigned long        trans_start;    /* Time (in jiffies) of last Tx    */
248 
249     int            watchdog_timeo; /* used by dev_watchdog() */
250     struct timer_list    watchdog_timer;
251 
252     /* Number of references to this device */
253     int __percpu        *pcpu_refcnt;
254 
255     /* delayed register/unregister */
256     struct list_head    todo_list;
257     /* device index hash chain */
258     struct hlist_node    index_hlist;
259 
260     struct list_head    link_watch_list;
261 
262     /* register/unregister state machine */
263     enum { NETREG_UNINITIALIZED=0,
264            NETREG_REGISTERED,    /* completed register_netdevice */
265            NETREG_UNREGISTERING,    /* called unregister_netdevice */
266            NETREG_UNREGISTERED,    /* completed unregister todo */
267            NETREG_RELEASED,        /* called free_netdev */
268            NETREG_DUMMY,        /* dummy device for NAPI poll */
269     } reg_state:16;
270 
271     enum {
272         RTNL_LINK_INITIALIZED,
273         RTNL_LINK_INITIALIZING,
274     } rtnl_link_state:16;
275 
276     /* Called from unregister, can be used to call free_netdev */
277     void (*destructor)(struct net_device *dev);
278 
279 #ifdef CONFIG_NETPOLL
280     struct netpoll_info    *npinfo;
281 #endif
282 
283 #ifdef CONFIG_NET_NS
284     /* Network namespace this network device is inside */
285     struct net        *nd_net;
286 #endif
287 
288     /* mid-layer private */
289     union {
290         void                *ml_priv;
291         struct pcpu_lstats __percpu    *lstats; /* loopback stats */
292         struct pcpu_tstats __percpu    *tstats; /* tunnel stats */
293         struct pcpu_dstats __percpu    *dstats; /* dummy stats */
294     };
295     /* GARP */
296     struct garp_port __rcu    *garp_port;
297 
298     /* class/net/name entry */
299     struct device        dev;
300     /* space for optional device, statistics, and wireless sysfs groups */
301     const struct attribute_group *sysfs_groups[4];
302 
303     /* rtnetlink link ops */
304     const struct rtnl_link_ops *rtnl_link_ops;
305 
306     /* VLAN feature mask */
307     unsigned long vlan_features;
308 
309     /* for setting kernel sock attribute on TCP connection setup */
310 #define GSO_MAX_SIZE        65536
311     unsigned int        gso_max_size;
312 
313 #ifdef CONFIG_DCB
314     /* Data Center Bridging netlink ops */
315     const struct dcbnl_rtnl_ops *dcbnl_ops;
316 #endif
317 
318 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
319     /* max exchange id for FCoE LRO by ddp */
320     unsigned int        fcoe_ddp_xid;
321 #endif
322     /* n-tuple filter list attached to this device */
323     struct ethtool_rx_ntuple_list ethtool_ntuple_list;
324 
325     /* phy device may attach itself for hardware timestamping */
326     struct phy_device *phydev;
327 };

你可能感兴趣的:(arm-linux驱动开发,Linux)