On 7 2 , 6 56 , !truth <noddy_zh...@asustek.com.cnwrote:
Hi,
i feel confused about the following program, and it's works to get a
pointer-member's address.
#define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)
static inline void *netdev_priv(struct net_device *dev)
{ return (char *)dev + ((sizeof(struct net_device)+
NETDEV_ALIGN_CONST)
& ~NETDEV_ALIGN_CONST);
}
sorry, i entry a wrong key, but did not finished my thread.
go on
the *struct net_device* is as follows, also you can refer to the
webpage:
http://www.gelato.unsw.edu.au/lxr/source/include/linux/
netdevice.h#L260
260 struct net_device
261 {
262
263 /*
264 * This is the first field of the "visible" part of this
structure
265 * (i.e. as seen by users in the "Space.c" file). It is
the name
266 * the interface.
267 */
268 char name[IFNAMSIZ];
269 /* device name hash chain */
270 struct hlist_node name_hlist;
271
272 /*
273 * I/O specific fields
274 * FIXME: Merge these and struct ifmap into one
275 */
276 unsigned long mem_end; /* shared mem
end */
277 unsigned long mem_start; /* shared mem
start */
278 unsigned long base_addr; /* device I/O
address */
279 unsigned int irq; /* device IRQ
number */
280
281 /*
282 * Some hardware also needs these fields, but they
are not
283 * part of the usual set specified in Space.c.
284 */
285
286 unsigned char if_port; /* Selectable AUI,
TP,..*/
287 unsigned char dma; /* DMA
channel */
288
289 unsigned long state;
290
291 struct net_device *next;
292
293 /* The device initialization function. Called only once.
*/
294 int (*init)(struct net_device *dev);
295
296 /* ------- Fields preinitialized in Space.c finish here
------- */
297
298 /* Net device features */
299 unsigned long features;
300 #define NETIF_F_SG 1 /* Scatter/gather IO. */
301 #define NETIF_F_IP_CSUM 2 /* Can checksum only TCP/
UDP over IPv4. */
302 #define NETIF_F_NO_CSUM 4 /* Does not require
checksum. F.e. loopack. */
303 #define NETIF_F_HW_CSUM 8 /* Can checksum all the
packets. */
304 #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory.
*/
305 #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */
306 #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw
acceleration */
307 #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw
acceleration */
308 #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on
VLAN */
309 #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle
VLAN packets */
310 #define NETIF_F_TSO 2048 /* Can offload TCP/IP
segmentation */
311 #define NETIF_F_LLTX 4096 /* LockLess TX */
312 #define NETIF_F_UFO 8192 /* Can offload UDP Large
Send*/
313
314 struct net_device *next_sched;
315
316 /* Interface index. Unique device identifier */
317 int ifindex;
318 int iflink;
319
320
321 struct net_device_stats* (*get_stats)(struct net_device
*dev);
322 struct iw_statistics* (*get_wireless_stats)(struct
net_device *dev);
323
324 /* List of functions to handle Wireless Extensions
(instead of ioctl).
325 * See <net/iw_handler.hfor details. Jean II */
326 const struct iw_handler_def * wireless_handlers;
327 /* Instance data managed by the core of Wireless
Extensions. */
328 struct iw_public_data * wireless_data;
329
330 struct ethtool_ops *ethtool_ops;
331
332 /*
333 * This marks the end of the "visible" part of the
structure. All
334 * fields hereafter are internal to the system, and may
change at
335 * will (read: may be cleaned up at will).
336 */
337
338
339 unsigned int flags; /* interface flags (a la
BSD) */
340 unsigned short gflags;
341 unsigned short priv_flags; /* Like 'flags' but
invisible to userspace. */
342 unsigned short padded; /* How much padding added
by alloc_netdev() */
343
344 unsigned char operstate; /* RFC2863 operstate */
345 unsigned char link_mode; /* mapping policy to
operstate */
346
347 unsigned mtu; /* interface MTU
value */
348 unsigned short type; /* interface hardware
type */
349 unsigned short hard_header_len; /*
hardware hdr length */
350
351 struct net_device *master; /* Pointer to master
device of a group,
352 * which this device is
member of.
353 */
354
355 /* Interface address info. */
356 unsigned char perm_addr[MAX_ADDR_LEN]; /*
permanent hw address */
357 unsigned char addr_len; /* hardware
address length */
358 unsigned short dev_id; /* for shared
network cards */
359
360 struct dev_mc_list *mc_list; /* Multicast mac
addresses */
361 int mc_count; /* Number of
installed mcasts */
362 int promiscuity;
363 int allmulti;
364
365
366 /* Protocol specific pointers */
367
368 void *atalk_ptr; /* AppleTalk
link */
369 void *ip_ptr; /* IPv4 specific
data */
370 void *dn_ptr; /* DECnet specific
data */
371 void *ip6_ptr; /* IPv6 specific
data */
372 void *ec_ptr; /* Econet specific
data */
373 void *ax25_ptr; /* AX.25 specific
data */
374
375 /*
376 * Cache line mostly used on receive path (including
eth_type_trans())
377 */
378 struct list_head poll_list
____cacheline_aligned_in_smp;
379 /* Link to poll list */
380
381 int (*poll) (struct net_device *dev,
int *quota);
382 int quota;
383 int weight;
384 unsigned long last_rx; /* Time of last
Rx */
385 /* Interface address info used in eth_type_trans() */
386 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw
address, (before bcast
387 because
most packets are unicast) */
388
389 unsigned char broadcast[MAX_ADDR_LEN]; /*
hw bcast add */
390
391 /*
392 * Cache line mostly used on queue transmit path (qdisc)
393 */
394 /* device queue lock */
395 spinlock_t queue_lock
____cacheline_aligned_in_smp;
396 struct Qdisc *qdisc;
397 struct Qdisc *qdisc_sleeping;
398 struct list_head qdisc_list;
399 unsigned long tx_queue_len; /* Max frames per
queue allowed */
400
401 /* ingress path synchronizer */
402 spinlock_t ingress_lock;
403 struct Qdisc *qdisc_ingress;
404
405 /*
406 * One part is mostly used on xmit path (device)
407 */
408 /* hard_start_xmit synchronizer */
409 spinlock_t xmit_lock
____cacheline_aligned_in_smp;
410 /* cpu id of processor entered to hard_start_xmit or -1,
411 if nobody entered there.
412 */
413 int xmit_lock_owner;
414 void *priv; /* pointer to private
data */
415 int (*hard_start_xmit) (struct sk_buff
*skb,
416 struct
net_device *dev);
417 /* These may be needed for future network-power-down code.
*/
418 unsigned long trans_start; /* Time (in
jiffies) of last Tx */
419
420 int watchdog_timeo; /* used by
dev_watchdog() */
421 struct timer_list watchdog_timer;
422
423 /*
424 * refcnt is a very hot point, so align it on SMP
425 */
426 /* Number of references to this device */
427 atomic_t refcnt
____cacheline_aligned_in_smp;
428
429 /* delayed register/unregister */
430 struct list_head todo_list;
431 /* device index hash chain */
432 struct hlist_node index_hlist;
433
434 /* register/unregister state machine */
435 enum { NETREG_UNINITIALIZED=0,
436 NETREG_REGISTERED, /* completed
register_netdevice */
437 NETREG_UNREGISTERING, /* called
unregister_netdevice */
438 NETREG_UNREGISTERED, /* completed unregister
todo */
439 NETREG_RELEASED, /* called free_netdev */
440 } reg_state;
441
442 /* Called after device is detached from network. */
443 void (*uninit)(struct net_device *dev);
444 /* Called after last user reference disappears. */
445 void (*destructor)(struct net_device
*dev);
446
447 /* Pointers to interface service routines. */
448 int (*open)(struct net_device *dev);
449 int (*stop)(struct net_device *dev);
450 #define HAVE_NETDEV_POLL
451 int (*hard_header) (struct sk_buff
*skb,
452 struct net_device
*dev,
453 unsigned short
type,
454 void *daddr,
455 void *saddr,
456 unsigned len);
457 int (*rebuild_header)(struct sk_buff
*skb);
458 #define HAVE_MULTICAST
459 void (*set_multicast_list)(struct
net_device *dev);
460 #define HAVE_SET_MAC_ADDR
461 int (*set_mac_address)(struct
net_device *dev,
462 void *addr);
463 #define HAVE_PRIVATE_IOCTL
464 int (*do_ioctl)(struct net_device
*dev,
465 struct ifreq *ifr, int
cmd);
466 #define HAVE_SET_CONFIG
467 int (*set_config)(struct net_device
*dev,
468 struct ifmap *map);
469 #define HAVE_HEADER_CACHE
470 int (*hard_header_cache)(struct
neighbour *neigh,
471 struct
hh_cache *hh);
472 void (*header_cache_update)(struct
hh_cache *hh,
473 struct
net_device *dev,
474 unsigned
char * haddr);
475 #define HAVE_CHANGE_MTU
476 int (*change_mtu)(struct net_device
*dev, int new_mtu);
477
478 #define HAVE_TX_TIMEOUT
479 void (*tx_timeout) (struct net_device
*dev);
480
481 void (*vlan_rx_register)(struct
net_device *dev,
482 struct
vlan_group *grp);
483 void (*vlan_rx_add_vid)(struct
net_device *dev,
484 unsigned short
vid);
485 void (*vlan_rx_kill_vid)(struct
net_device *dev,
486 unsigned short
vid);
487
488 int (*hard_header_parse)(struct
sk_buff *skb,
489 unsigned char
*haddr);
490 int (*neigh_setup)(struct net_device
*dev, struct neigh_parms *);
491 #ifdef CONFIG_NETPOLL
492 struct netpoll_info *npinfo;
493 #endif
494 #ifdef CONFIG_NET_POLL_CONTROLLER
495 void (*poll_controller)(struct
net_device *dev);
496 #endif
497
498 /* bridge stuff */
499 struct net_bridge_port *br_port;
500
501 #ifdef CONFIG_NET_DIVERT
502 /* this will get initialized at each interface type init
routine */
503 struct divert_blk *divert;
504 #endif /* CONFIG_NET_DIVERT */
505
506 /* class/net/name entry */
507 struct class_device class_dev;
508 /* space for optional statistics and wireless sysfs groups
*/
509 struct attribute_group *sysfs_groups[3];
510 };