ia64/xen-unstable

view xen/include/xeno/netdevice.h @ 945:db2e1ea917df

bitkeeper revision 1.596.1.3 (3fb3b41eWUoRU0H8A0jEX5roXjxKkA)

Many files:
Greatly simplified Xen softirqs. They are now only executed in outermost Xen activation; they are never called within an irq context.
author kaf24@scramble.cl.cam.ac.uk
date Thu Nov 13 16:41:02 2003 +0000 (2003-11-13)
parents 125f43340354
children 7a554cbf0f58
line source
1 /*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for the Interfaces handler.
7 *
8 * Version: @(#)dev.h 1.0.10 08/12/93
9 *
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov>
14 * Alan Cox, <Alan.Cox@linux.org>
15 * Bjorn Ekwall. <bj0rn@blox.se>
16 * Pekka Riikonen <priikone@poseidon.pspt.fi>
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 *
23 * Moved to /usr/include/linux for NET3
24 */
25 #ifndef _LINUX_NETDEVICE_H
26 #define _LINUX_NETDEVICE_H
28 #include <xeno/if.h>
29 #include <xeno/if_ether.h>
30 #include <xeno/if_packet.h>
31 #include <xeno/sched.h>
32 #include <xeno/interrupt.h>
34 #include <asm/atomic.h>
35 #include <asm/cache.h>
36 #include <asm/byteorder.h>
38 #ifdef __KERNEL__
39 #include <xeno/config.h>
41 struct vlan_group;
43 /* Backlog congestion levels */
44 #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
45 #define NET_RX_DROP 1 /* packet dropped */
47 #endif
49 #define MAX_ADDR_LEN 8 /* Largest hardware address length */
51 /*
52 * Network device statistics. Akin to the 2.0 ether stats but
53 * with byte counters.
54 */
56 struct net_device_stats
57 {
58 unsigned long rx_packets; /* total packets received */
59 unsigned long tx_packets; /* total packets transmitted */
60 unsigned long rx_bytes; /* total bytes received */
61 unsigned long tx_bytes; /* total bytes transmitted */
62 unsigned long rx_errors; /* bad packets received */
63 unsigned long tx_errors; /* packet transmit problems */
64 unsigned long rx_dropped; /* no space in linux buffers */
65 unsigned long tx_dropped; /* no space available in linux */
66 unsigned long multicast; /* multicast packets received */
67 unsigned long collisions;
69 /* detailed rx_errors: */
70 unsigned long rx_length_errors;
71 unsigned long rx_over_errors; /* receiver ring buff overflow */
72 unsigned long rx_crc_errors; /* recved pkt with crc error */
73 unsigned long rx_frame_errors; /* recv'd frame alignment error */
74 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
75 unsigned long rx_missed_errors; /* receiver missed packet */
77 /* detailed tx_errors */
78 unsigned long tx_aborted_errors;
79 unsigned long tx_carrier_errors;
80 unsigned long tx_fifo_errors;
81 unsigned long tx_heartbeat_errors;
82 unsigned long tx_window_errors;
84 /* for cslip etc */
85 unsigned long rx_compressed;
86 unsigned long tx_compressed;
87 };
90 /* Media selection options. */
91 enum {
92 IF_PORT_UNKNOWN = 0,
93 IF_PORT_10BASE2,
94 IF_PORT_10BASET,
95 IF_PORT_AUI,
96 IF_PORT_100BASET,
97 IF_PORT_100BASETX,
98 IF_PORT_100BASEFX
99 };
101 #ifdef __KERNEL__
103 extern const char *if_port_text[];
105 #include <xeno/cache.h>
106 #include <xeno/skbuff.h>
108 struct neighbour;
109 struct neigh_parms;
110 struct sk_buff;
112 struct netif_rx_stats
113 {
114 unsigned total;
115 unsigned dropped;
116 unsigned time_squeeze;
117 unsigned throttled;
118 unsigned fastroute_hit;
119 unsigned fastroute_success;
120 unsigned fastroute_defer;
121 unsigned fastroute_deferred_out;
122 unsigned fastroute_latency_reduction;
123 unsigned cpu_collision;
124 } __attribute__ ((__aligned__(SMP_CACHE_BYTES)));
126 extern struct netif_rx_stats netdev_rx_stat[];
129 /*
130 * We tag multicasts with these structures.
131 */
133 struct dev_mc_list
134 {
135 struct dev_mc_list *next;
136 __u8 dmi_addr[MAX_ADDR_LEN];
137 unsigned char dmi_addrlen;
138 int dmi_users;
139 int dmi_gusers;
140 };
142 struct hh_cache
143 {
144 struct hh_cache *hh_next; /* Next entry */
145 atomic_t hh_refcnt; /* number of users */
146 unsigned short hh_type; /* protocol identifier, f.e ETH_P_IP
147 * NOTE: For VLANs, this will be the
148 * encapuslated type. --BLG
149 */
150 int hh_len; /* length of header */
151 int (*hh_output)(struct sk_buff *skb);
152 rwlock_t hh_lock;
153 /* cached hardware header; allow for machine alignment needs. */
154 unsigned long hh_data[16/sizeof(unsigned long)];
155 };
157 /* These flag bits are private to the generic network queueing
158 * layer, they may not be explicitly referenced by any other
159 * code.
160 */
162 enum netdev_state_t
163 {
164 __LINK_STATE_XOFF=0,
165 __LINK_STATE_START,
166 __LINK_STATE_PRESENT,
167 __LINK_STATE_NOCARRIER
168 };
171 /*
172 * The DEVICE structure.
173 * Actually, this whole structure is a big mistake. It mixes I/O
174 * data with strictly "high-level" data, and it has to know about
175 * almost every data structure used in the INET module.
176 *
177 * FIXME: cleanup struct net_device such that network protocol info
178 * moves out.
179 */
181 struct net_device
182 {
183 /*
184 * This is the first field of the "visible" part of this structure
185 * (i.e. as seen by users in the "Space.c" file). It is the name
186 * the interface.
187 */
188 char name[IFNAMSIZ];
190 /*
191 * I/O specific fields
192 * FIXME: Merge these and struct ifmap into one
193 */
194 unsigned long rmem_end; /* shmem "recv" end */
195 unsigned long rmem_start; /* shmem "recv" start */
196 unsigned long mem_end; /* shared mem end */
197 unsigned long mem_start; /* shared mem start */
198 unsigned long base_addr; /* device I/O address */
199 unsigned int irq; /* device IRQ number */
201 /*
202 * Some hardware also needs these fields, but they are not
203 * part of the usual set specified in Space.c.
204 */
206 unsigned char if_port; /* Selectable AUI, TP,..*/
207 unsigned char dma; /* DMA channel */
209 unsigned long state;
211 struct net_device *next;
213 /* The device initialization function. Called only once. */
214 int (*init)(struct net_device *dev);
216 /* ------- Fields preinitialized in Space.c finish here ------- */
218 struct net_device *next_sched;
220 /* Interface index. Unique device identifier */
221 int ifindex;
222 int iflink;
225 struct net_device_stats* (*get_stats)(struct net_device *dev);
226 struct iw_statistics* (*get_wireless_stats)(struct net_device *dev);
228 /*
229 * This marks the end of the "visible" part of the structure. All
230 * fields hereafter are internal to the system, and may change at
231 * will (read: may be cleaned up at will).
232 */
234 /* These may be needed for future network-power-down code. */
235 unsigned long trans_start; /* Time (in jiffies) of last Tx */
236 unsigned long last_rx; /* Time of last Rx */
238 unsigned short flags; /* interface flags (a la BSD) */
239 unsigned short gflags;
240 unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */
241 unsigned short unused_alignment_fixer; /* Because we need priv_flags,
242 * and we want to be 32-bit aligned.
243 */
245 unsigned mtu; /* interface MTU value */
246 unsigned short type; /* interface hardware type */
247 unsigned short hard_header_len; /* hardware hdr length */
248 void *priv; /* pointer to private data */
250 struct net_device *master; /* Pointer to master device of a group,
251 * which this device is member of.
252 */
254 /* Interface address info. */
255 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
256 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */
257 unsigned char addr_len; /* hardware address length */
259 struct dev_mc_list *mc_list; /* Multicast mac addresses */
260 int mc_count; /* Number of installed mcasts */
261 int promiscuity;
262 int allmulti;
264 int watchdog_timeo;
265 struct timer_list watchdog_timer;
267 /* Protocol specific pointers */
269 void *atalk_ptr; /* AppleTalk link */
270 void *ip_ptr; /* IPv4 specific data */
271 void *dn_ptr; /* DECnet specific data */
272 void *ip6_ptr; /* IPv6 specific data */
273 void *ec_ptr; /* Econet specific data */
275 /* hard_start_xmit synchronizer */
276 spinlock_t xmit_lock;
277 /* cpu id of processor entered to hard_start_xmit or -1,
278 if nobody entered there.
279 */
280 int xmit_lock_owner;
281 /* device queue lock */
282 spinlock_t queue_lock;
283 /* Number of references to this device */
284 atomic_t refcnt;
285 /* The flag marking that device is unregistered, but held by an user */
286 int deadbeaf;
288 /* Net device features */
289 int features;
290 #define NETIF_F_SG 1 /* Scatter/gather IO. */
291 #define NETIF_F_IP_CSUM 2 /* Can checksum only TCP/UDP over IPv4. */
292 #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */
293 #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */
294 #define NETIF_F_DYNALLOC 16 /* Self-dectructable device. */
295 #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */
296 #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */
297 #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw acceleration */
298 #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw acceleration */
299 #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on VLAN */
300 #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */
302 /* Called after device is detached from network. */
303 void (*uninit)(struct net_device *dev);
304 /* Called after last user reference disappears. */
305 void (*destructor)(struct net_device *dev);
307 /* Pointers to interface service routines. */
308 int (*open)(struct net_device *dev);
309 int (*stop)(struct net_device *dev);
310 int (*hard_start_xmit) (struct sk_buff *skb,
311 struct net_device *dev);
312 #if 0
313 int (*poll) (struct net_device *dev, int *quota); /* XXX IAP */
314 #endif
315 int (*hard_header) (struct sk_buff *skb,
316 struct net_device *dev,
317 unsigned short type,
318 void *daddr,
319 void *saddr,
320 unsigned len);
321 int (*rebuild_header)(struct sk_buff *skb);
322 #define HAVE_MULTICAST
323 void (*set_multicast_list)(struct net_device *dev);
324 #define HAVE_SET_MAC_ADDR
325 int (*set_mac_address)(struct net_device *dev,
326 void *addr);
327 #define HAVE_PRIVATE_IOCTL
328 int (*do_ioctl)(struct net_device *dev,
329 struct ifreq *ifr, int cmd);
330 #define HAVE_SET_CONFIG
331 int (*set_config)(struct net_device *dev,
332 struct ifmap *map);
333 #define HAVE_HEADER_CACHE
334 int (*hard_header_cache)(struct neighbour *neigh,
335 struct hh_cache *hh);
336 void (*header_cache_update)(struct hh_cache *hh,
337 struct net_device *dev,
338 unsigned char * haddr);
339 #define HAVE_CHANGE_MTU
340 int (*change_mtu)(struct net_device *dev, int new_mtu);
342 #define HAVE_TX_TIMEOUT
343 void (*tx_timeout) (struct net_device *dev);
345 void (*vlan_rx_register)(struct net_device *dev,
346 struct vlan_group *grp);
347 void (*vlan_rx_add_vid)(struct net_device *dev,
348 unsigned short vid);
349 void (*vlan_rx_kill_vid)(struct net_device *dev,
350 unsigned short vid);
352 int (*hard_header_parse)(struct sk_buff *skb,
353 unsigned char *haddr);
354 int (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
355 // int (*accept_fastpath)(struct net_device *, struct dst_entry*);
357 /* open/release and usage marking */
358 struct module *owner;
360 /* bridge stuff */
361 struct net_bridge_port *br_port;
362 };
365 struct packet_type
366 {
367 unsigned short type; /* This is really htons(ether_type). */
368 struct net_device *dev; /* NULL is wildcarded here */
369 int (*func) (struct sk_buff *, struct net_device *,
370 struct packet_type *);
371 void *data; /* Private to the packet type */
372 struct packet_type *next;
373 };
376 #include <xeno/interrupt.h>
378 extern struct net_device *dev_base; /* All devices */
379 extern rwlock_t dev_base_lock; /* Device list lock */
381 extern int netdev_boot_setup_add(char *name, struct ifmap *map);
382 extern int netdev_boot_setup_check(struct net_device *dev);
383 extern struct net_device *dev_getbyhwaddr(unsigned short type, char *hwaddr);
384 extern void dev_add_pack(struct packet_type *pt);
385 extern void dev_remove_pack(struct packet_type *pt);
386 extern int dev_get(const char *name);
387 extern struct net_device *dev_get_by_name(const char *name);
388 extern struct net_device *__dev_get_by_name(const char *name);
389 extern struct net_device *dev_alloc(const char *name, int *err);
390 extern int dev_alloc_name(struct net_device *dev, const char *name);
391 extern int dev_open(struct net_device *dev);
392 extern int dev_close(struct net_device *dev);
393 extern int register_netdevice(struct net_device *dev);
394 extern int unregister_netdevice(struct net_device *dev);
395 extern void dev_shutdown(struct net_device *dev);
396 extern void dev_activate(struct net_device *dev);
397 extern void dev_deactivate(struct net_device *dev);
398 extern void dev_init_scheduler(struct net_device *dev);
399 extern int dev_new_index(void);
400 extern struct net_device *dev_get_by_index(int ifindex);
401 extern struct net_device *__dev_get_by_index(int ifindex);
402 extern int dev_restart(struct net_device *dev);
404 typedef int gifconf_func_t(struct net_device * dev, char * bufptr, int len);
405 extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf);
406 static inline int unregister_gifconf(unsigned int family)
407 {
408 return register_gifconf(family, 0);
409 }
411 extern struct tasklet_struct net_tx_tasklet;
413 extern struct list_head net_schedule_list;
414 extern spinlock_t net_schedule_list_lock;
416 #define HAVE_NETIF_QUEUE
418 static inline void __netif_schedule(struct net_device *dev)
419 {
420 tasklet_schedule(&net_tx_tasklet);
421 }
423 static inline void netif_schedule(struct net_device *dev)
424 {
425 if (!test_bit(__LINK_STATE_XOFF, &dev->state))
426 __netif_schedule(dev);
427 }
429 static inline void netif_start_queue(struct net_device *dev)
430 {
431 clear_bit(__LINK_STATE_XOFF, &dev->state);
432 }
434 static inline void netif_wake_queue(struct net_device *dev)
435 {
436 if (test_and_clear_bit(__LINK_STATE_XOFF, &dev->state))
437 __netif_schedule(dev);
438 }
440 static inline void netif_stop_queue(struct net_device *dev)
441 {
442 set_bit(__LINK_STATE_XOFF, &dev->state);
443 }
445 static inline int netif_queue_stopped(struct net_device *dev)
446 {
447 return test_bit(__LINK_STATE_XOFF, &dev->state);
448 }
450 static inline int netif_running(struct net_device *dev)
451 {
452 return test_bit(__LINK_STATE_START, &dev->state);
453 }
456 /*
457 * Xen does not need deferred skb freeing, as all destructor hook functions
458 * are IRQ safe. Linux needed more care for some destructors...
459 */
460 #define dev_kfree_skb_irq(_skb) dev_kfree_skb(_skb)
461 #define dev_kfree_skb_any(_skb) dev_kfree_skb(_skb)
463 extern void net_call_rx_atomic(void (*fn)(void));
464 extern int netif_rx(struct sk_buff *skb);
465 extern int dev_ioctl(unsigned int cmd, void *);
466 extern int dev_change_flags(struct net_device *, unsigned);
467 extern void dev_init(void);
469 extern int netdev_finish_unregister(struct net_device *dev);
471 static inline void dev_put(struct net_device *dev)
472 {
473 if (atomic_dec_and_test(&dev->refcnt))
474 netdev_finish_unregister(dev);
475 }
477 #define __dev_put(dev) atomic_dec(&(dev)->refcnt)
478 #define dev_hold(dev) atomic_inc(&(dev)->refcnt)
480 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
481 * and _off may be called from IRQ context, but it is caller
482 * who is responsible for serialization of these calls.
483 */
485 static inline int netif_carrier_ok(struct net_device *dev)
486 {
487 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
488 }
490 extern void __netdev_watchdog_up(struct net_device *dev);
492 static inline void netif_carrier_on(struct net_device *dev)
493 {
494 clear_bit(__LINK_STATE_NOCARRIER, &dev->state);
495 if (netif_running(dev))
496 __netdev_watchdog_up(dev);
497 }
499 static inline void netif_carrier_off(struct net_device *dev)
500 {
501 set_bit(__LINK_STATE_NOCARRIER, &dev->state);
502 }
504 /* Hot-plugging. */
505 static inline int netif_device_present(struct net_device *dev)
506 {
507 return test_bit(__LINK_STATE_PRESENT, &dev->state);
508 }
510 static inline void netif_device_detach(struct net_device *dev)
511 {
512 if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) &&
513 netif_running(dev)) {
514 netif_stop_queue(dev);
515 }
516 }
518 static inline void netif_device_attach(struct net_device *dev)
519 {
520 if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) &&
521 netif_running(dev)) {
522 netif_wake_queue(dev);
523 __netdev_watchdog_up(dev);
524 }
525 }
527 /*
528 * Network interface message level settings
529 */
530 #define HAVE_NETIF_MSG 1
532 enum {
533 NETIF_MSG_DRV = 0x0001,
534 NETIF_MSG_PROBE = 0x0002,
535 NETIF_MSG_LINK = 0x0004,
536 NETIF_MSG_TIMER = 0x0008,
537 NETIF_MSG_IFDOWN = 0x0010,
538 NETIF_MSG_IFUP = 0x0020,
539 NETIF_MSG_RX_ERR = 0x0040,
540 NETIF_MSG_TX_ERR = 0x0080,
541 NETIF_MSG_TX_QUEUED = 0x0100,
542 NETIF_MSG_INTR = 0x0200,
543 NETIF_MSG_TX_DONE = 0x0400,
544 NETIF_MSG_RX_STATUS = 0x0800,
545 NETIF_MSG_PKTDATA = 0x1000,
546 };
548 #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
549 #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
550 #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
551 #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
552 #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
553 #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
554 #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
555 #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
556 #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
557 #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
558 #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
559 #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
560 #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
562 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
564 extern void ether_setup(struct net_device *dev);
565 extern void fddi_setup(struct net_device *dev);
566 extern void tr_setup(struct net_device *dev);
567 extern void fc_setup(struct net_device *dev);
568 extern void fc_freedev(struct net_device *dev);
569 /* Support for loadable net-drivers */
570 extern int register_netdev(struct net_device *dev);
571 extern void unregister_netdev(struct net_device *dev);
572 /* Functions used for multicast support */
573 extern void dev_mc_upload(struct net_device *dev);
574 extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
575 extern int dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly);
576 extern void dev_mc_discard(struct net_device *dev);
577 extern void dev_set_promiscuity(struct net_device *dev, int inc);
578 extern void dev_set_allmulti(struct net_device *dev, int inc);
579 extern void netdev_state_change(struct net_device *dev);
580 /* Load a device via the kmod */
581 extern void dev_load(const char *name);
582 extern void dev_mcast_init(void);
583 extern int netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev));
584 extern void netdev_unregister_fc(int bit);
585 extern unsigned long netdev_fc_xoff;
586 extern int netdev_set_master(struct net_device *dev, struct net_device *master);
587 extern struct sk_buff * skb_checksum_help(struct sk_buff *skb);
589 extern void alert_slow_netdevice(struct net_device *dev, char *nictype);
591 #endif /* __KERNEL__ */
593 #endif /* _LINUX_DEV_H */