ia64/xen-unstable

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