linux-bk/include/linux/netdevice.h
<<
>>
Prefs
   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
  27
  28#include <linux/if.h>
  29#include <linux/if_ether.h>
  30#include <linux/if_packet.h>
  31
  32#include <asm/atomic.h>
  33#include <asm/cache.h>
  34#include <asm/byteorder.h>
  35
  36#ifdef __KERNEL__
  37#include <linux/config.h>
  38#include <linux/device.h>
  39#include <linux/percpu.h>
  40
  41struct divert_blk;
  42struct vlan_group;
  43struct ethtool_ops;
  44
  45                                        /* source back-compat hook */
  46#define SET_ETHTOOL_OPS(netdev,ops) \
  47        ( (netdev)->ethtool_ops = (ops) )
  48
  49#define HAVE_ALLOC_NETDEV               /* feature macro: alloc_xxxdev
  50                                           functions are available. */
  51#define HAVE_FREE_NETDEV
  52
  53#define NET_XMIT_SUCCESS        0
  54#define NET_XMIT_DROP           1       /* skb dropped                  */
  55#define NET_XMIT_CN             2       /* congestion notification      */
  56#define NET_XMIT_POLICED        3       /* skb is shot by police        */
  57#define NET_XMIT_BYPASS         4       /* packet does not leave via dequeue;
  58                                           (TC use only - dev_queue_xmit
  59                                           returns this as NET_XMIT_SUCCESS) */
  60
  61/* Backlog congestion levels */
  62#define NET_RX_SUCCESS          0   /* keep 'em coming, baby */
  63#define NET_RX_DROP             1  /* packet dropped */
  64#define NET_RX_CN_LOW           2   /* storm alert, just in case */
  65#define NET_RX_CN_MOD           3   /* Storm on its way! */
  66#define NET_RX_CN_HIGH          4   /* The storm is here */
  67#define NET_RX_BAD              5  /* packet dropped due to kernel error */
  68
  69#define net_xmit_errno(e)       ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
  70
  71#endif
  72
  73#define MAX_ADDR_LEN    32              /* Largest hardware address length */
  74
  75/*
  76 *      Compute the worst case header length according to the protocols
  77 *      used.
  78 */
  79 
  80#if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
  81#define LL_MAX_HEADER   32
  82#else
  83#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
  84#define LL_MAX_HEADER   96
  85#else
  86#define LL_MAX_HEADER   48
  87#endif
  88#endif
  89
  90#if !defined(CONFIG_NET_IPIP) && \
  91    !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
  92#define MAX_HEADER LL_MAX_HEADER
  93#else
  94#define MAX_HEADER (LL_MAX_HEADER + 48)
  95#endif
  96
  97/*
  98 *      Network device statistics. Akin to the 2.0 ether stats but
  99 *      with byte counters.
 100 */
 101 
 102struct net_device_stats
 103{
 104        unsigned long   rx_packets;             /* total packets received       */
 105        unsigned long   tx_packets;             /* total packets transmitted    */
 106        unsigned long   rx_bytes;               /* total bytes received         */
 107        unsigned long   tx_bytes;               /* total bytes transmitted      */
 108        unsigned long   rx_errors;              /* bad packets received         */
 109        unsigned long   tx_errors;              /* packet transmit problems     */
 110        unsigned long   rx_dropped;             /* no space in linux buffers    */
 111        unsigned long   tx_dropped;             /* no space available in linux  */
 112        unsigned long   multicast;              /* multicast packets received   */
 113        unsigned long   collisions;
 114
 115        /* detailed rx_errors: */
 116        unsigned long   rx_length_errors;
 117        unsigned long   rx_over_errors;         /* receiver ring buff overflow  */
 118        unsigned long   rx_crc_errors;          /* recved pkt with crc error    */
 119        unsigned long   rx_frame_errors;        /* recv'd frame alignment error */
 120        unsigned long   rx_fifo_errors;         /* recv'r fifo overrun          */
 121        unsigned long   rx_missed_errors;       /* receiver missed packet       */
 122
 123        /* detailed tx_errors */
 124        unsigned long   tx_aborted_errors;
 125        unsigned long   tx_carrier_errors;
 126        unsigned long   tx_fifo_errors;
 127        unsigned long   tx_heartbeat_errors;
 128        unsigned long   tx_window_errors;
 129        
 130        /* for cslip etc */
 131        unsigned long   rx_compressed;
 132        unsigned long   tx_compressed;
 133};
 134
 135
 136/* Media selection options. */
 137enum {
 138        IF_PORT_UNKNOWN = 0,
 139        IF_PORT_10BASE2,
 140        IF_PORT_10BASET,
 141        IF_PORT_AUI,
 142        IF_PORT_100BASET,
 143        IF_PORT_100BASETX,
 144        IF_PORT_100BASEFX
 145};
 146
 147#ifdef __KERNEL__
 148
 149#include <linux/cache.h>
 150#include <linux/skbuff.h>
 151
 152struct neighbour;
 153struct neigh_parms;
 154struct sk_buff;
 155
 156struct netif_rx_stats
 157{
 158        unsigned total;
 159        unsigned dropped;
 160        unsigned time_squeeze;
 161        unsigned throttled;
 162        unsigned fastroute_hit;
 163        unsigned fastroute_success;
 164        unsigned fastroute_defer;
 165        unsigned fastroute_deferred_out;
 166        unsigned fastroute_latency_reduction;
 167        unsigned cpu_collision;
 168};
 169
 170DECLARE_PER_CPU(struct netif_rx_stats, netdev_rx_stat);
 171
 172
 173/*
 174 *      We tag multicasts with these structures.
 175 */
 176 
 177struct dev_mc_list
 178{       
 179        struct dev_mc_list      *next;
 180        __u8                    dmi_addr[MAX_ADDR_LEN];
 181        unsigned char           dmi_addrlen;
 182        int                     dmi_users;
 183        int                     dmi_gusers;
 184};
 185
 186struct hh_cache
 187{
 188        struct hh_cache *hh_next;       /* Next entry                        */
 189        atomic_t        hh_refcnt;      /* number of users                   */
 190        unsigned short  hh_type;        /* protocol identifier, f.e ETH_P_IP
 191                                         *  NOTE:  For VLANs, this will be the
 192                                         *  encapuslated type. --BLG
 193                                         */
 194        int             hh_len;         /* length of header */
 195        int             (*hh_output)(struct sk_buff *skb);
 196        rwlock_t        hh_lock;
 197
 198        /* cached hardware header; allow for machine alignment needs.        */
 199#define HH_DATA_MOD     16
 200#define HH_DATA_OFF(__len) \
 201        (HH_DATA_MOD - ((__len) & (HH_DATA_MOD - 1)))
 202#define HH_DATA_ALIGN(__len) \
 203        (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
 204        unsigned long   hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
 205};
 206
 207/* Reserve HH_DATA_MOD byte aligned hard_header_len, but at least that much.
 208 * Alternative is:
 209 *   dev->hard_header_len ? (dev->hard_header_len +
 210 *                           (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0
 211 *
 212 * We could use other alignment values, but we must maintain the
 213 * relationship HH alignment <= LL alignment.
 214 */
 215#define LL_RESERVED_SPACE(dev) \
 216        (((dev)->hard_header_len&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
 217
 218/* These flag bits are private to the generic network queueing
 219 * layer, they may not be explicitly referenced by any other
 220 * code.
 221 */
 222
 223enum netdev_state_t
 224{
 225        __LINK_STATE_XOFF=0,
 226        __LINK_STATE_START,
 227        __LINK_STATE_PRESENT,
 228        __LINK_STATE_SCHED,
 229        __LINK_STATE_NOCARRIER,
 230        __LINK_STATE_RX_SCHED,
 231        __LINK_STATE_LINKWATCH_PENDING
 232};
 233
 234
 235/*
 236 * This structure holds at boot time configured netdevice settings. They
 237 * are then used in the device probing. 
 238 */
 239struct netdev_boot_setup {
 240        char name[IFNAMSIZ];
 241        struct ifmap map;
 242};
 243#define NETDEV_BOOT_SETUP_MAX 8
 244
 245
 246/*
 247 *      The DEVICE structure.
 248 *      Actually, this whole structure is a big mistake.  It mixes I/O
 249 *      data with strictly "high-level" data, and it has to know about
 250 *      almost every data structure used in the INET module.
 251 *
 252 *      FIXME: cleanup struct net_device such that network protocol info
 253 *      moves out.
 254 */
 255
 256struct net_device
 257{
 258
 259        /*
 260         * This is the first field of the "visible" part of this structure
 261         * (i.e. as seen by users in the "Space.c" file).  It is the name
 262         * the interface.
 263         */
 264        char                    name[IFNAMSIZ];
 265
 266        /*
 267         *      I/O specific fields
 268         *      FIXME: Merge these and struct ifmap into one
 269         */
 270        unsigned long           mem_end;        /* shared mem end       */
 271        unsigned long           mem_start;      /* shared mem start     */
 272        unsigned long           base_addr;      /* device I/O address   */
 273        unsigned int            irq;            /* device IRQ number    */
 274
 275        /*
 276         *      Some hardware also needs these fields, but they are not
 277         *      part of the usual set specified in Space.c.
 278         */
 279
 280        unsigned char           if_port;        /* Selectable AUI, TP,..*/
 281        unsigned char           dma;            /* DMA channel          */
 282
 283        unsigned long           state;
 284
 285        struct net_device       *next;
 286        
 287        /* The device initialization function. Called only once. */
 288        int                     (*init)(struct net_device *dev);
 289
 290        /* ------- Fields preinitialized in Space.c finish here ------- */
 291
 292        struct net_device       *next_sched;
 293
 294        /* Interface index. Unique device identifier    */
 295        int                     ifindex;
 296        int                     iflink;
 297
 298
 299        struct net_device_stats* (*get_stats)(struct net_device *dev);
 300        struct iw_statistics*   (*get_wireless_stats)(struct net_device *dev);
 301
 302        /* List of functions to handle Wireless Extensions (instead of ioctl).
 303         * See <net/iw_handler.h> for details. Jean II */
 304        struct iw_handler_def * wireless_handlers;
 305
 306        struct ethtool_ops *ethtool_ops;
 307
 308        /*
 309         * This marks the end of the "visible" part of the structure. All
 310         * fields hereafter are internal to the system, and may change at
 311         * will (read: may be cleaned up at will).
 312         */
 313
 314        /* These may be needed for future network-power-down code. */
 315        unsigned long           trans_start;    /* Time (in jiffies) of last Tx */
 316        unsigned long           last_rx;        /* Time of last Rx      */
 317
 318        unsigned short          flags;  /* interface flags (a la BSD)   */
 319        unsigned short          gflags;
 320        unsigned short          priv_flags; /* Like 'flags' but invisible to userspace. */
 321        unsigned short          unused_alignment_fixer; /* Because we need priv_flags,
 322                                                         * and we want to be 32-bit aligned.
 323                                                         */
 324
 325        unsigned                mtu;    /* interface MTU value          */
 326        unsigned short          type;   /* interface hardware type      */
 327        unsigned short          hard_header_len;        /* hardware hdr length  */
 328        void                    *priv;  /* pointer to private data      */
 329
 330        struct net_device       *master; /* Pointer to master device of a group,
 331                                          * which this device is member of.
 332                                          */
 333
 334        /* Interface address info. */
 335        unsigned char           broadcast[MAX_ADDR_LEN];        /* hw bcast add */
 336        unsigned char           dev_addr[MAX_ADDR_LEN]; /* hw address   */
 337        unsigned char           addr_len;       /* hardware address length      */
 338
 339        struct dev_mc_list      *mc_list;       /* Multicast mac addresses      */
 340        int                     mc_count;       /* Number of installed mcasts   */
 341        int                     promiscuity;
 342        int                     allmulti;
 343
 344        int                     watchdog_timeo;
 345        struct timer_list       watchdog_timer;
 346
 347        /* Protocol specific pointers */
 348        
 349        void                    *atalk_ptr;     /* AppleTalk link       */
 350        void                    *ip_ptr;        /* IPv4 specific data   */  
 351        void                    *dn_ptr;        /* DECnet specific data */
 352        void                    *ip6_ptr;       /* IPv6 specific data */
 353        void                    *ec_ptr;        /* Econet specific data */
 354        void                    *ax25_ptr;      /* AX.25 specific data */
 355
 356        struct list_head        poll_list;      /* Link to poll list    */
 357        int                     quota;
 358        int                     weight;
 359
 360        struct Qdisc            *qdisc;
 361        struct Qdisc            *qdisc_sleeping;
 362        struct Qdisc            *qdisc_list;
 363        struct Qdisc            *qdisc_ingress;
 364        unsigned long           tx_queue_len;   /* Max frames per queue allowed */
 365
 366        /* hard_start_xmit synchronizer */
 367        spinlock_t              xmit_lock;
 368        /* cpu id of processor entered to hard_start_xmit or -1,
 369           if nobody entered there.
 370         */
 371        int                     xmit_lock_owner;
 372        /* device queue lock */
 373        spinlock_t              queue_lock;
 374        /* Number of references to this device */
 375        atomic_t                refcnt;
 376        /* delayed register/unregister */
 377        struct list_head        todo_list;
 378
 379        /* register/unregister state machine */
 380        enum { NETREG_UNINITIALIZED=0,
 381               NETREG_REGISTERING,      /* called register_netdevice */
 382               NETREG_REGISTERED,       /* completed register todo */
 383               NETREG_UNREGISTERING,    /* called unregister_netdevice */
 384               NETREG_UNREGISTERED,     /* completed unregister todo */
 385               NETREG_RELEASED,         /* called free_netdev */
 386        } reg_state;
 387
 388        /* Net device features */
 389        int                     features;
 390#define NETIF_F_SG              1       /* Scatter/gather IO. */
 391#define NETIF_F_IP_CSUM         2       /* Can checksum only TCP/UDP over IPv4. */
 392#define NETIF_F_NO_CSUM         4       /* Does not require checksum. F.e. loopack. */
 393#define NETIF_F_HW_CSUM         8       /* Can checksum all the packets. */
 394#define NETIF_F_HIGHDMA         32      /* Can DMA to high memory. */
 395#define NETIF_F_FRAGLIST        64      /* Scatter/gather IO. */
 396#define NETIF_F_HW_VLAN_TX      128     /* Transmit VLAN hw acceleration */
 397#define NETIF_F_HW_VLAN_RX      256     /* Receive VLAN hw acceleration */
 398#define NETIF_F_HW_VLAN_FILTER  512     /* Receive filtering on VLAN */
 399#define NETIF_F_VLAN_CHALLENGED 1024    /* Device cannot handle VLAN packets */
 400#define NETIF_F_TSO             2048    /* Can offload TCP/IP segmentation */
 401
 402        /* Called after device is detached from network. */
 403        void                    (*uninit)(struct net_device *dev);
 404        /* Called after last user reference disappears. */
 405        void                    (*destructor)(struct net_device *dev);
 406
 407        /* Pointers to interface service routines.      */
 408        int                     (*open)(struct net_device *dev);
 409        int                     (*stop)(struct net_device *dev);
 410        int                     (*hard_start_xmit) (struct sk_buff *skb,
 411                                                    struct net_device *dev);
 412#define HAVE_NETDEV_POLL
 413        int                     (*poll) (struct net_device *dev, int *quota);
 414        int                     (*hard_header) (struct sk_buff *skb,
 415                                                struct net_device *dev,
 416                                                unsigned short type,
 417                                                void *daddr,
 418                                                void *saddr,
 419                                                unsigned len);
 420        int                     (*rebuild_header)(struct sk_buff *skb);
 421#define HAVE_MULTICAST                   
 422        void                    (*set_multicast_list)(struct net_device *dev);
 423#define HAVE_SET_MAC_ADDR                
 424        int                     (*set_mac_address)(struct net_device *dev,
 425                                                   void *addr);
 426#define HAVE_PRIVATE_IOCTL
 427        int                     (*do_ioctl)(struct net_device *dev,
 428                                            struct ifreq *ifr, int cmd);
 429#define HAVE_SET_CONFIG
 430        int                     (*set_config)(struct net_device *dev,
 431                                              struct ifmap *map);
 432#define HAVE_HEADER_CACHE
 433        int                     (*hard_header_cache)(struct neighbour *neigh,
 434                                                     struct hh_cache *hh);
 435        void                    (*header_cache_update)(struct hh_cache *hh,
 436                                                       struct net_device *dev,
 437                                                       unsigned char *  haddr);
 438#define HAVE_CHANGE_MTU
 439        int                     (*change_mtu)(struct net_device *dev, int new_mtu);
 440
 441#define HAVE_TX_TIMEOUT
 442        void                    (*tx_timeout) (struct net_device *dev);
 443
 444        void                    (*vlan_rx_register)(struct net_device *dev,
 445                                                    struct vlan_group *grp);
 446        void                    (*vlan_rx_add_vid)(struct net_device *dev,
 447                                                   unsigned short vid);
 448        void                    (*vlan_rx_kill_vid)(struct net_device *dev,
 449                                                    unsigned short vid);
 450
 451        int                     (*hard_header_parse)(struct sk_buff *skb,
 452                                                     unsigned char *haddr);
 453        int                     (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
 454        int                     (*accept_fastpath)(struct net_device *, struct dst_entry*);
 455
 456        /* bridge stuff */
 457        struct net_bridge_port  *br_port;
 458
 459#ifdef CONFIG_NET_FASTROUTE
 460#define NETDEV_FASTROUTE_HMASK 0xF
 461        /* Semi-private data. Keep it at the end of device struct. */
 462        rwlock_t                fastpath_lock;
 463        struct dst_entry        *fastpath[NETDEV_FASTROUTE_HMASK+1];
 464#endif
 465#ifdef CONFIG_NET_DIVERT
 466        /* this will get initialized at each interface type init routine */
 467        struct divert_blk       *divert;
 468#endif /* CONFIG_NET_DIVERT */
 469
 470        /* class/net/name entry */
 471        struct class_device     class_dev;
 472        struct net_device_stats* (*last_stats)(struct net_device *);
 473};
 474
 475#define SET_MODULE_OWNER(dev) do { } while (0)
 476/* Set the sysfs physical device reference for the network logical device
 477 * if set prior to registration will cause a symlink during initialization.
 478 */
 479#define SET_NETDEV_DEV(net, pdev)       ((net)->class_dev.dev = (pdev))
 480
 481struct packet_type {
 482        unsigned short          type;   /* This is really htons(ether_type).    */
 483        struct net_device               *dev;   /* NULL is wildcarded here              */
 484        int                     (*func) (struct sk_buff *, struct net_device *,
 485                                         struct packet_type *);
 486        void                    *af_packet_priv;
 487        struct list_head        list;
 488};
 489
 490#include <linux/interrupt.h>
 491#include <linux/notifier.h>
 492
 493extern struct net_device                loopback_dev;           /* The loopback */
 494extern struct net_device                *dev_base;              /* All devices */
 495extern rwlock_t                         dev_base_lock;          /* Device list lock */
 496
 497extern int                      netdev_boot_setup_add(char *name, struct ifmap *map);
 498extern int                      netdev_boot_setup_check(struct net_device *dev);
 499extern struct net_device    *dev_getbyhwaddr(unsigned short type, char *hwaddr);
 500extern struct net_device *__dev_getfirstbyhwtype(unsigned short type);
 501extern struct net_device *dev_getfirstbyhwtype(unsigned short type);
 502extern void             dev_add_pack(struct packet_type *pt);
 503extern void             dev_remove_pack(struct packet_type *pt);
 504extern void             __dev_remove_pack(struct packet_type *pt);
 505extern int              __dev_get(const char *name);
 506static inline int __deprecated dev_get(const char *name)
 507{
 508        return __dev_get(name);
 509}
 510extern struct net_device        *dev_get_by_flags(unsigned short flags,
 511                                                  unsigned short mask);
 512extern struct net_device        *__dev_get_by_flags(unsigned short flags,
 513                                                    unsigned short mask);
 514extern struct net_device        *dev_get_by_name(const char *name);
 515extern struct net_device        *__dev_get_by_name(const char *name);
 516extern struct net_device        *__dev_alloc(const char *name, int *err);
 517static inline __deprecated struct net_device *dev_alloc(const char *name, int *err)
 518{
 519        return __dev_alloc(name, err);
 520}
 521extern int              dev_alloc_name(struct net_device *dev, const char *name);
 522extern int              dev_open(struct net_device *dev);
 523extern int              dev_close(struct net_device *dev);
 524extern int              dev_queue_xmit(struct sk_buff *skb);
 525extern int              register_netdevice(struct net_device *dev);
 526extern int              unregister_netdevice(struct net_device *dev);
 527extern void             free_netdev(struct net_device *dev);
 528extern void             synchronize_net(void);
 529extern int              register_netdevice_notifier(struct notifier_block *nb);
 530extern int              unregister_netdevice_notifier(struct notifier_block *nb);
 531extern int              call_netdevice_notifiers(unsigned long val, void *v);
 532extern int              dev_new_index(void);
 533extern struct net_device        *dev_get_by_index(int ifindex);
 534extern struct net_device        *__dev_get_by_index(int ifindex);
 535extern int              dev_restart(struct net_device *dev);
 536
 537typedef int gifconf_func_t(struct net_device * dev, char * bufptr, int len);
 538extern int              register_gifconf(unsigned int family, gifconf_func_t * gifconf);
 539static inline int unregister_gifconf(unsigned int family)
 540{
 541        return register_gifconf(family, 0);
 542}
 543
 544/*
 545 * Incoming packets are placed on per-cpu queues so that
 546 * no locking is needed.
 547 */
 548
 549struct softnet_data
 550{
 551        int                     throttle;
 552        int                     cng_level;
 553        int                     avg_blog;
 554        struct sk_buff_head     input_pkt_queue;
 555        struct list_head        poll_list;
 556        struct net_device       *output_queue;
 557        struct sk_buff          *completion_queue;
 558
 559        struct net_device       backlog_dev;    /* Sorry. 8) */
 560};
 561
 562DECLARE_PER_CPU(struct softnet_data,softnet_data);
 563
 564#define HAVE_NETIF_QUEUE
 565
 566static inline void __netif_schedule(struct net_device *dev)
 567{
 568        if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) {
 569                unsigned long flags;
 570                struct softnet_data *sd;
 571
 572                local_irq_save(flags);
 573                sd = &__get_cpu_var(softnet_data);
 574                dev->next_sched = sd->output_queue;
 575                sd->output_queue = dev;
 576                raise_softirq_irqoff(NET_TX_SOFTIRQ);
 577                local_irq_restore(flags);
 578        }
 579}
 580
 581static inline void netif_schedule(struct net_device *dev)
 582{
 583        if (!test_bit(__LINK_STATE_XOFF, &dev->state))
 584                __netif_schedule(dev);
 585}
 586
 587static inline void netif_start_queue(struct net_device *dev)
 588{
 589        clear_bit(__LINK_STATE_XOFF, &dev->state);
 590}
 591
 592static inline void netif_wake_queue(struct net_device *dev)
 593{
 594        if (test_and_clear_bit(__LINK_STATE_XOFF, &dev->state))
 595                __netif_schedule(dev);
 596}
 597
 598static inline void netif_stop_queue(struct net_device *dev)
 599{
 600        set_bit(__LINK_STATE_XOFF, &dev->state);
 601}
 602
 603static inline int netif_queue_stopped(const struct net_device *dev)
 604{
 605        return test_bit(__LINK_STATE_XOFF, &dev->state);
 606}
 607
 608static inline int netif_running(const struct net_device *dev)
 609{
 610        return test_bit(__LINK_STATE_START, &dev->state);
 611}
 612
 613
 614/* Use this variant when it is known for sure that it
 615 * is executing from interrupt context.
 616 */
 617static inline void dev_kfree_skb_irq(struct sk_buff *skb)
 618{
 619        if (atomic_dec_and_test(&skb->users)) {
 620                struct softnet_data *sd;
 621                unsigned long flags;
 622
 623                local_irq_save(flags);
 624                sd = &__get_cpu_var(softnet_data);
 625                skb->next = sd->completion_queue;
 626                sd->completion_queue = skb;
 627                raise_softirq_irqoff(NET_TX_SOFTIRQ);
 628                local_irq_restore(flags);
 629        }
 630}
 631
 632/* Use this variant in places where it could be invoked
 633 * either from interrupt or non-interrupt context.
 634 */
 635static inline void dev_kfree_skb_any(struct sk_buff *skb)
 636{
 637        if (in_irq() || irqs_disabled())
 638                dev_kfree_skb_irq(skb);
 639        else
 640                dev_kfree_skb(skb);
 641}
 642
 643#define HAVE_NETIF_RX 1
 644extern int              netif_rx(struct sk_buff *skb);
 645#define HAVE_NETIF_RECEIVE_SKB 1
 646extern int              netif_receive_skb(struct sk_buff *skb);
 647extern int              dev_ioctl(unsigned int cmd, void *);
 648extern int              dev_ethtool(struct ifreq *);
 649extern unsigned         dev_get_flags(const struct net_device *);
 650extern int              dev_change_flags(struct net_device *, unsigned);
 651extern int              dev_set_mtu(struct net_device *, int);
 652extern void             dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
 653
 654extern void             dev_init(void);
 655
 656extern int              netdev_nit;
 657
 658/* Post buffer to the network code from _non interrupt_ context.
 659 * see net/core/dev.c for netif_rx description.
 660 */
 661static inline int netif_rx_ni(struct sk_buff *skb)
 662{
 663       int err = netif_rx(skb);
 664       if (softirq_pending(smp_processor_id()))
 665               do_softirq();
 666       return err;
 667}
 668
 669/* Called by rtnetlink.c:rtnl_unlock() */
 670extern void netdev_run_todo(void);
 671
 672static inline void dev_put(struct net_device *dev)
 673{
 674        atomic_dec(&dev->refcnt);
 675}
 676
 677#define __dev_put(dev) atomic_dec(&(dev)->refcnt)
 678#define dev_hold(dev) atomic_inc(&(dev)->refcnt)
 679
 680/* Carrier loss detection, dial on demand. The functions netif_carrier_on
 681 * and _off may be called from IRQ context, but it is caller
 682 * who is responsible for serialization of these calls.
 683 */
 684
 685extern void linkwatch_fire_event(struct net_device *dev);
 686
 687static inline int netif_carrier_ok(const struct net_device *dev)
 688{
 689        return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
 690}
 691
 692extern void __netdev_watchdog_up(struct net_device *dev);
 693
 694static inline void netif_carrier_on(struct net_device *dev)
 695{
 696        if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state))
 697                linkwatch_fire_event(dev);
 698        if (netif_running(dev))
 699                __netdev_watchdog_up(dev);
 700}
 701
 702static inline void netif_carrier_off(struct net_device *dev)
 703{
 704        if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state))
 705                linkwatch_fire_event(dev);
 706}
 707
 708/* Hot-plugging. */
 709static inline int netif_device_present(struct net_device *dev)
 710{
 711        return test_bit(__LINK_STATE_PRESENT, &dev->state);
 712}
 713
 714static inline void netif_device_detach(struct net_device *dev)
 715{
 716        if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) &&
 717            netif_running(dev)) {
 718                netif_stop_queue(dev);
 719        }
 720}
 721
 722static inline void netif_device_attach(struct net_device *dev)
 723{
 724        if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) &&
 725            netif_running(dev)) {
 726                netif_wake_queue(dev);
 727                __netdev_watchdog_up(dev);
 728        }
 729}
 730
 731/*
 732 * Network interface message level settings
 733 */
 734#define HAVE_NETIF_MSG 1
 735
 736enum {
 737        NETIF_MSG_DRV           = 0x0001,
 738        NETIF_MSG_PROBE         = 0x0002,
 739        NETIF_MSG_LINK          = 0x0004,
 740        NETIF_MSG_TIMER         = 0x0008,
 741        NETIF_MSG_IFDOWN        = 0x0010,
 742        NETIF_MSG_IFUP          = 0x0020,
 743        NETIF_MSG_RX_ERR        = 0x0040,
 744        NETIF_MSG_TX_ERR        = 0x0080,
 745        NETIF_MSG_TX_QUEUED     = 0x0100,
 746        NETIF_MSG_INTR          = 0x0200,
 747        NETIF_MSG_TX_DONE       = 0x0400,
 748        NETIF_MSG_RX_STATUS     = 0x0800,
 749        NETIF_MSG_PKTDATA       = 0x1000,
 750        NETIF_MSG_HW            = 0x2000,
 751        NETIF_MSG_WOL           = 0x4000,
 752};
 753
 754#define netif_msg_drv(p)        ((p)->msg_enable & NETIF_MSG_DRV)
 755#define netif_msg_probe(p)      ((p)->msg_enable & NETIF_MSG_PROBE)
 756#define netif_msg_link(p)       ((p)->msg_enable & NETIF_MSG_LINK)
 757#define netif_msg_timer(p)      ((p)->msg_enable & NETIF_MSG_TIMER)
 758#define netif_msg_ifdown(p)     ((p)->msg_enable & NETIF_MSG_IFDOWN)
 759#define netif_msg_ifup(p)       ((p)->msg_enable & NETIF_MSG_IFUP)
 760#define netif_msg_rx_err(p)     ((p)->msg_enable & NETIF_MSG_RX_ERR)
 761#define netif_msg_tx_err(p)     ((p)->msg_enable & NETIF_MSG_TX_ERR)
 762#define netif_msg_tx_queued(p)  ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
 763#define netif_msg_intr(p)       ((p)->msg_enable & NETIF_MSG_INTR)
 764#define netif_msg_tx_done(p)    ((p)->msg_enable & NETIF_MSG_TX_DONE)
 765#define netif_msg_rx_status(p)  ((p)->msg_enable & NETIF_MSG_RX_STATUS)
 766#define netif_msg_pktdata(p)    ((p)->msg_enable & NETIF_MSG_PKTDATA)
 767#define netif_msg_hw(p)         ((p)->msg_enable & NETIF_MSG_HW)
 768#define netif_msg_wol(p)        ((p)->msg_enable & NETIF_MSG_WOL)
 769
 770/* Schedule rx intr now? */
 771
 772static inline int netif_rx_schedule_prep(struct net_device *dev)
 773{
 774        return netif_running(dev) &&
 775                !test_and_set_bit(__LINK_STATE_RX_SCHED, &dev->state);
 776}
 777
 778/* Add interface to tail of rx poll list. This assumes that _prep has
 779 * already been called and returned 1.
 780 */
 781
 782static inline void __netif_rx_schedule(struct net_device *dev)
 783{
 784        unsigned long flags;
 785
 786        local_irq_save(flags);
 787        dev_hold(dev);
 788        list_add_tail(&dev->poll_list, &__get_cpu_var(softnet_data).poll_list);
 789        if (dev->quota < 0)
 790                dev->quota += dev->weight;
 791        else
 792                dev->quota = dev->weight;
 793        __raise_softirq_irqoff(NET_RX_SOFTIRQ);
 794        local_irq_restore(flags);
 795}
 796
 797/* Try to reschedule poll. Called by irq handler. */
 798
 799static inline void netif_rx_schedule(struct net_device *dev)
 800{
 801        if (netif_rx_schedule_prep(dev))
 802                __netif_rx_schedule(dev);
 803}
 804
 805/* Try to reschedule poll. Called by dev->poll() after netif_rx_complete().
 806 * Do not inline this?
 807 */
 808static inline int netif_rx_reschedule(struct net_device *dev, int undo)
 809{
 810        if (netif_rx_schedule_prep(dev)) {
 811                unsigned long flags;
 812
 813                dev->quota += undo;
 814
 815                local_irq_save(flags);
 816                list_add_tail(&dev->poll_list, &__get_cpu_var(softnet_data).poll_list);
 817                __raise_softirq_irqoff(NET_RX_SOFTIRQ);
 818                local_irq_restore(flags);
 819                return 1;
 820        }
 821        return 0;
 822}
 823
 824/* Remove interface from poll list: it must be in the poll list
 825 * on current cpu. This primitive is called by dev->poll(), when
 826 * it completes the work. The device cannot be out of poll list at this
 827 * moment, it is BUG().
 828 */
 829static inline void netif_rx_complete(struct net_device *dev)
 830{
 831        unsigned long flags;
 832
 833        local_irq_save(flags);
 834        if (!test_bit(__LINK_STATE_RX_SCHED, &dev->state)) BUG();
 835        list_del(&dev->poll_list);
 836        smp_mb__before_clear_bit();
 837        clear_bit(__LINK_STATE_RX_SCHED, &dev->state);
 838        local_irq_restore(flags);
 839}
 840
 841static inline void netif_poll_disable(struct net_device *dev)
 842{
 843        while (test_and_set_bit(__LINK_STATE_RX_SCHED, &dev->state)) {
 844                /* No hurry. */
 845                current->state = TASK_INTERRUPTIBLE;
 846                schedule_timeout(1);
 847        }
 848}
 849
 850static inline void netif_poll_enable(struct net_device *dev)
 851{
 852        clear_bit(__LINK_STATE_RX_SCHED, &dev->state);
 853}
 854
 855/* same as netif_rx_complete, except that local_irq_save(flags)
 856 * has already been issued
 857 */
 858static inline void __netif_rx_complete(struct net_device *dev)
 859{
 860        if (!test_bit(__LINK_STATE_RX_SCHED, &dev->state)) BUG();
 861        list_del(&dev->poll_list);
 862        smp_mb__before_clear_bit();
 863        clear_bit(__LINK_STATE_RX_SCHED, &dev->state);
 864}
 865
 866static inline void netif_tx_disable(struct net_device *dev)
 867{
 868        spin_lock_bh(&dev->xmit_lock);
 869        netif_stop_queue(dev);
 870        spin_unlock_bh(&dev->xmit_lock);
 871}
 872
 873/* These functions live elsewhere (drivers/net/net_init.c, but related) */
 874
 875extern void             ether_setup(struct net_device *dev);
 876extern void             fddi_setup(struct net_device *dev);
 877extern void             tr_setup(struct net_device *dev);
 878extern void             fc_setup(struct net_device *dev);
 879extern void             fc_freedev(struct net_device *dev);
 880/* Support for loadable net-drivers */
 881extern struct net_device *alloc_netdev(int sizeof_priv, const char *name,
 882                                       void (*setup)(struct net_device *));
 883extern int              register_netdev(struct net_device *dev);
 884extern void             unregister_netdev(struct net_device *dev);
 885/* Functions used for multicast support */
 886extern void             dev_mc_upload(struct net_device *dev);
 887extern int              dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
 888extern int              dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly);
 889extern void             dev_mc_discard(struct net_device *dev);
 890extern void             dev_set_promiscuity(struct net_device *dev, int inc);
 891extern void             dev_set_allmulti(struct net_device *dev, int inc);
 892extern void             netdev_state_change(struct net_device *dev);
 893/* Load a device via the kmod */
 894extern void             dev_load(const char *name);
 895extern void             dev_mcast_init(void);
 896extern int              netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev));
 897extern void             netdev_unregister_fc(int bit);
 898extern int              netdev_max_backlog;
 899extern int              weight_p;
 900extern unsigned long    netdev_fc_xoff;
 901extern atomic_t netdev_dropping;
 902extern int              netdev_set_master(struct net_device *dev, struct net_device *master);
 903extern struct sk_buff * skb_checksum_help(struct sk_buff *skb);
 904#ifdef CONFIG_NET_FASTROUTE
 905extern int              netdev_fastroute;
 906extern int              netdev_fastroute_obstacles;
 907extern void             dev_clear_fastroute(struct net_device *dev);
 908#endif
 909
 910#ifdef CONFIG_SYSCTL
 911extern char *net_sysctl_strdup(const char *s);
 912#endif
 913
 914#endif /* __KERNEL__ */
 915
 916#endif  /* _LINUX_DEV_H */
 917
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.