Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

netdevice.h

Go to the documentation of this file.
00001 /*
00002  * INET         An implementation of the TCP/IP protocol suite for the LINUX
00003  *              operating system.  INET is implemented using the  BSD Socket
00004  *              interface as the means of communication with the user level.
00005  *
00006  *              Definitions for the Interfaces handler.
00007  *
00008  * Version:     @(#)dev.h       1.0.10  08/12/93
00009  *
00010  * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
00011  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
00012  *              Corey Minyard <wf-rch!minyard@relay.EU.net>
00013  *              Donald J. Becker, <becker@cesdis.gsfc.nasa.gov>
00014  *              Alan Cox, <Alan.Cox@linux.org>
00015  *              Bjorn Ekwall. <bj0rn@blox.se>
00016  *
00017  *              This program is free software; you can redistribute it and/or
00018  *              modify it under the terms of the GNU General Public License
00019  *              as published by the Free Software Foundation; either version
00020  *              2 of the License, or (at your option) any later version.
00021  *
00022  *              Moved to /usr/include/linux for NET3
00023  */
00024 #ifndef _LINUX_NETDEVICE_H
00025 #define _LINUX_NETDEVICE_H
00026 
00027 #ifdef __KERNEL__
00028 #include <linux/config.h>
00029 #endif
00030 #include <linux/if.h>
00031 #include <linux/if_ether.h>
00032 #include <linux/if_packet.h>
00033 
00034 #include <asm/atomic.h>
00035 
00036 #ifdef __KERNEL__
00037 #ifdef CONFIG_NET_PROFILE
00038 #include <net/profile.h>
00039 #endif
00040 #endif
00041 
00042 struct divert_blk;
00043 
00044 /*
00045  *      For future expansion when we will have different priorities. 
00046  */
00047  
00048 #define MAX_ADDR_LEN    7               /* Largest hardware address length */
00049 
00050 /*
00051  *      Compute the worst case header length according to the protocols
00052  *      used.
00053  */
00054  
00055 #if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
00056 #define LL_MAX_HEADER   32
00057 #else
00058 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
00059 #define LL_MAX_HEADER   96
00060 #else
00061 #define LL_MAX_HEADER   48
00062 #endif
00063 #endif
00064 
00065 #if !defined(CONFIG_NET_IPIP) && \
00066     !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
00067 #define MAX_HEADER LL_MAX_HEADER
00068 #else
00069 #define MAX_HEADER (LL_MAX_HEADER + 48)
00070 #endif
00071 
00072 /*
00073  *      Network device statistics. Akin to the 2.0 ether stats but
00074  *      with byte counters.
00075  */
00076  
00077 struct net_device_stats
00078 {
00079         unsigned long   rx_packets;             /* total packets received       */
00080         unsigned long   tx_packets;             /* total packets transmitted    */
00081         unsigned long   rx_bytes;               /* total bytes received         */
00082         unsigned long   tx_bytes;               /* total bytes transmitted      */
00083         unsigned long   rx_errors;              /* bad packets received         */
00084         unsigned long   tx_errors;              /* packet transmit problems     */
00085         unsigned long   rx_dropped;             /* no space in linux buffers    */
00086         unsigned long   tx_dropped;             /* no space available in linux  */
00087         unsigned long   multicast;              /* multicast packets received   */
00088         unsigned long   collisions;
00089 
00090         /* detailed rx_errors: */
00091         unsigned long   rx_length_errors;
00092         unsigned long   rx_over_errors;         /* receiver ring buff overflow  */
00093         unsigned long   rx_crc_errors;          /* recved pkt with crc error    */
00094         unsigned long   rx_frame_errors;        /* recv'd frame alignment error */
00095         unsigned long   rx_fifo_errors;         /* recv'r fifo overrun          */
00096         unsigned long   rx_missed_errors;       /* receiver missed packet       */
00097 
00098         /* detailed tx_errors */
00099         unsigned long   tx_aborted_errors;
00100         unsigned long   tx_carrier_errors;
00101         unsigned long   tx_fifo_errors;
00102         unsigned long   tx_heartbeat_errors;
00103         unsigned long   tx_window_errors;
00104         
00105         /* for cslip etc */
00106         unsigned long   rx_compressed;
00107         unsigned long   tx_compressed;
00108 };
00109 
00110 #ifdef CONFIG_NET_FASTROUTE
00111 struct net_fastroute_stats
00112 {
00113         int             hits;
00114         int             succeed;
00115         int             deferred;
00116         int             latency_reduction;
00117 };
00118 #endif
00119 
00120 /* Media selection options. */
00121 enum {
00122         IF_PORT_UNKNOWN = 0,
00123         IF_PORT_10BASE2,
00124         IF_PORT_10BASET,
00125         IF_PORT_AUI,
00126         IF_PORT_100BASET,
00127         IF_PORT_100BASETX,
00128         IF_PORT_100BASEFX
00129 };
00130 
00131 #ifdef __KERNEL__
00132 
00133 extern const char *if_port_text[];
00134 
00135 #include <linux/skbuff.h>
00136 
00137 struct neighbour;
00138 struct neigh_parms;
00139 struct sk_buff;
00140 
00141 /*
00142  *      We tag multicasts with these structures.
00143  */
00144  
00145 struct dev_mc_list
00146 {       
00147         struct dev_mc_list      *next;
00148         __u8                    dmi_addr[MAX_ADDR_LEN];
00149         unsigned char           dmi_addrlen;
00150         int                     dmi_users;
00151         int                     dmi_gusers;
00152 };
00153 
00154 struct hh_cache
00155 {
00156         struct hh_cache *hh_next;       /* Next entry                        */
00157         atomic_t        hh_refcnt;      /* number of users                   */
00158         unsigned short  hh_type;        /* protocol identifier, f.e ETH_P_IP */
00159         int             (*hh_output)(struct sk_buff *skb);
00160         rwlock_t        hh_lock;
00161         /* cached hardware header; allow for machine alignment needs.        */
00162         unsigned long   hh_data[16/sizeof(unsigned long)];
00163 };
00164 
00165 
00166 /*
00167  *      The DEVICE structure.
00168  *      Actually, this whole structure is a big mistake.  It mixes I/O
00169  *      data with strictly "high-level" data, and it has to know about
00170  *      almost every data structure used in the INET module.
00171  *
00172  *      FIXME: cleanup struct device such that network protocol info
00173  *      moves out.
00174  */
00175 
00176 struct device
00177 {
00178 
00179         /*
00180          * This is the first field of the "visible" part of this structure
00181          * (i.e. as seen by users in the "Space.c" file).  It is the name
00182          * the interface.
00183          */
00184         char                    *name;
00185 
00186         /*
00187          *      I/O specific fields
00188          *      FIXME: Merge these and struct ifmap into one
00189          */
00190         unsigned long           rmem_end;       /* shmem "recv" end     */
00191         unsigned long           rmem_start;     /* shmem "recv" start   */
00192         unsigned long           mem_end;        /* shared mem end       */
00193         unsigned long           mem_start;      /* shared mem start     */
00194         unsigned long           base_addr;      /* device I/O address   */
00195         unsigned int            irq;            /* device IRQ number    */
00196         
00197         /* Low-level status flags. */
00198         volatile unsigned char  start;          /* start an operation   */
00199         /*
00200          * These two are just single-bit flags, but due to atomicity
00201          * reasons they have to be inside a "unsigned long". However,
00202          * they should be inside the SAME unsigned long instead of
00203          * this wasteful use of memory..
00204          */
00205         unsigned long           interrupt;      /* bitops.. */
00206         unsigned long           tbusy;          /* transmitter busy */
00207         
00208         struct device           *next;
00209         
00210         /* The device initialization function. Called only once. */
00211         int                     (*init)(struct device *dev);
00212         void                    (*destructor)(struct device *dev);
00213 
00214         /* Interface index. Unique device identifier    */
00215         int                     ifindex;
00216         int                     iflink;
00217 
00218         /*
00219          *      Some hardware also needs these fields, but they are not
00220          *      part of the usual set specified in Space.c.
00221          */
00222 
00223         unsigned char           if_port;        /* Selectable AUI, TP,..*/
00224         unsigned char           dma;            /* DMA channel          */
00225 
00226         struct net_device_stats* (*get_stats)(struct device *dev);
00227         struct iw_statistics*   (*get_wireless_stats)(struct device *dev);
00228 
00229         /*
00230          * This marks the end of the "visible" part of the structure. All
00231          * fields hereafter are internal to the system, and may change at
00232          * will (read: may be cleaned up at will).
00233          */
00234 
00235         /* These may be needed for future network-power-down code. */
00236         unsigned long           trans_start;    /* Time (in jiffies) of last Tx */
00237         unsigned long           last_rx;        /* Time of last Rx      */
00238         
00239         unsigned short          flags;  /* interface flags (a la BSD)   */
00240         unsigned short          gflags;
00241         unsigned                mtu;    /* interface MTU value          */
00242         unsigned short          type;   /* interface hardware type      */
00243         unsigned short          hard_header_len;        /* hardware hdr length  */
00244         void                    *priv;  /* pointer to private data      */
00245         
00246         /* Interface address info. */
00247         unsigned char           broadcast[MAX_ADDR_LEN];        /* hw bcast add */
00248         unsigned char           pad;            /* make dev_addr aligned to 8 bytes */
00249         unsigned char           dev_addr[MAX_ADDR_LEN]; /* hw address   */
00250         unsigned char           addr_len;       /* hardware address length      */
00251 
00252         struct dev_mc_list      *mc_list;       /* Multicast mac addresses      */
00253         int                     mc_count;       /* Number of installed mcasts   */
00254         int                     promiscuity;
00255         int                     allmulti;
00256     
00257         /* For load balancing driver pair support */
00258   
00259         unsigned long           pkt_queue;      /* Packets queued       */
00260         struct device           *slave;         /* Slave device         */
00261 
00262         /* Protocol specific pointers */
00263         
00264         void                    *atalk_ptr;     /* AppleTalk link       */
00265         void                    *ip_ptr;        /* IPv4 specific data   */  
00266         void                    *dn_ptr;        /* DECnet specific data */
00267 
00268         struct Qdisc            *qdisc;
00269         struct Qdisc            *qdisc_sleeping;
00270         struct Qdisc            *qdisc_list;
00271         unsigned long           tx_queue_len;   /* Max frames per queue allowed */
00272 
00273         /* Bridge stuff */
00274         int                     bridge_port_id;         
00275         
00276         /* Pointers to interface service routines.      */
00277         int                     (*open)(struct device *dev);
00278         int                     (*stop)(struct device *dev);
00279         int                     (*hard_start_xmit) (struct sk_buff *skb,
00280                                                     struct device *dev);
00281         int                     (*hard_header) (struct sk_buff *skb,
00282                                                 struct device *dev,
00283                                                 unsigned short type,
00284                                                 void *daddr,
00285                                                 void *saddr,
00286                                                 unsigned len);
00287         int                     (*rebuild_header)(struct sk_buff *skb);
00288 #define HAVE_MULTICAST                   
00289         void                    (*set_multicast_list)(struct device *dev);
00290 #define HAVE_SET_MAC_ADDR                
00291         int                     (*set_mac_address)(struct device *dev,
00292                                                    void *addr);
00293 #define HAVE_PRIVATE_IOCTL
00294         int                     (*do_ioctl)(struct device *dev,
00295                                             struct ifreq *ifr, int cmd);
00296 #define HAVE_SET_CONFIG
00297         int                     (*set_config)(struct device *dev,
00298                                               struct ifmap *map);
00299 #define HAVE_HEADER_CACHE
00300         int                     (*hard_header_cache)(struct neighbour *neigh,
00301                                                      struct hh_cache *hh);
00302         void                    (*header_cache_update)(struct hh_cache *hh,
00303                                                        struct device *dev,
00304                                                        unsigned char *  haddr);
00305 #define HAVE_CHANGE_MTU
00306         int                     (*change_mtu)(struct device *dev, int new_mtu);
00307 
00308         int                     (*hard_header_parse)(struct sk_buff *skb,
00309                                                      unsigned char *haddr);
00310         int                     (*neigh_setup)(struct device *dev, struct neigh_parms *);
00311         int                     (*accept_fastpath)(struct device *, struct dst_entry*);
00312 
00313 #ifdef CONFIG_NET_FASTROUTE
00314         /* Really, this semaphore may be necessary and for not fastroute code;
00315            f.e. SMP??
00316          */
00317         int                     tx_semaphore;
00318 #define NETDEV_FASTROUTE_HMASK 0xF
00319         /* Semi-private data. Keep it at the end of device struct. */
00320         struct dst_entry        *fastpath[NETDEV_FASTROUTE_HMASK+1];
00321 #endif
00322 
00323 #ifdef CONFIG_NET_DIVERT
00324         /* this will get initialized at each interface type init routine */
00325         struct divert_blk       *divert;
00326 #endif /* CONFIG_NET_DIVERT */
00327 };
00328 
00329 
00330 struct packet_type 
00331 {
00332         unsigned short          type;   /* This is really htons(ether_type).    */
00333         struct device           *dev;   /* NULL is wildcarded here              */
00334         int                     (*func) (struct sk_buff *, struct device *,
00335                                          struct packet_type *);
00336         void                    *data;  /* Private to the packet type           */
00337         struct packet_type      *next;
00338 };
00339 
00340 
00341 #include <linux/interrupt.h>
00342 #include <linux/notifier.h>
00343 
00344 extern struct device            loopback_dev;           /* The loopback */
00345 extern struct device            *dev_base;              /* All devices */
00346 extern struct packet_type       *ptype_base[16];        /* Hashed types */
00347 extern int                      netdev_dropping;
00348 extern int                      net_cpu_congestion;
00349 
00350 extern struct device    *dev_getbyhwaddr(unsigned short type, char *hwaddr);
00351 extern void             dev_add_pack(struct packet_type *pt);
00352 extern void             dev_remove_pack(struct packet_type *pt);
00353 extern struct device    *dev_get(const char *name);
00354 extern struct device    *dev_alloc(const char *name, int *err);
00355 extern int              dev_alloc_name(struct device *dev, const char *name);
00356 extern int              dev_open(struct device *dev);
00357 extern int              dev_close(struct device *dev);
00358 extern int              dev_queue_xmit(struct sk_buff *skb);
00359 extern void             dev_loopback_xmit(struct sk_buff *skb);
00360 extern int              register_netdevice(struct device *dev);
00361 extern int              unregister_netdevice(struct device *dev);
00362 extern int              register_netdevice_notifier(struct notifier_block *nb);
00363 extern int              unregister_netdevice_notifier(struct notifier_block *nb);
00364 extern int              dev_new_index(void);
00365 extern struct device    *dev_get_by_index(int ifindex);
00366 extern int              dev_restart(struct device *dev);
00367 
00368 typedef int gifconf_func_t(struct device * dev, char * bufptr, int len);
00369 extern int              register_gifconf(unsigned int family, gifconf_func_t * gifconf);
00370 extern __inline__ int unregister_gifconf(unsigned int family)
00371 {
00372         return register_gifconf(family, 0);
00373 }
00374 
00375 #define HAVE_NETIF_RX 1
00376 extern void             netif_rx(struct sk_buff *skb);
00377 extern void             net_bh(void);
00378 extern int              dev_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
00379 extern int              dev_ioctl(unsigned int cmd, void *);
00380 extern int              dev_change_flags(struct device *, unsigned);
00381 extern void             dev_queue_xmit_nit(struct sk_buff *skb, struct device *dev);
00382 
00383 extern void             dev_init(void);
00384 
00385 extern int              netdev_nit;
00386 
00387 /* Locking protection for page faults during outputs to devices unloaded during the fault */
00388 
00389 extern atomic_t         dev_lockct;
00390 
00391 /*
00392  *      These two don't currently need to be atomic
00393  *      but they may do soon. Do it properly anyway.
00394  */
00395 
00396 extern __inline__ void  dev_lock_list(void)
00397 {
00398         atomic_inc(&dev_lockct);
00399 }
00400 
00401 extern __inline__ void  dev_unlock_list(void)
00402 {
00403         atomic_dec(&dev_lockct);
00404 }
00405 
00406 /*
00407  *      This almost never occurs, isn't in performance critical paths
00408  *      and we can thus be relaxed about it. 
00409  *
00410  *      FIXME: What if this is being run as a real time process ??
00411  *              Linus: We need a way to force a yield here ?
00412  *
00413  *      FIXME: Though dev_lockct is atomic varible, locking procedure
00414  *              is not atomic.
00415  */
00416 
00417 extern __inline__ void dev_lock_wait(void)
00418 {
00419         while (atomic_read(&dev_lockct)) {
00420                 current->policy |= SCHED_YIELD;
00421                 schedule();
00422         }
00423 }
00424 
00425 extern __inline__ void dev_init_buffers(struct device *dev)
00426 {
00427         /* DO NOTHING */
00428 }
00429 
00430 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
00431 
00432 extern void             ether_setup(struct device *dev);
00433 extern void             fddi_setup(struct device *dev);
00434 extern void             tr_setup(struct device *dev);
00435 extern void             fc_setup(struct device *dev);
00436 extern void             tr_freedev(struct device *dev);
00437 extern void             fc_freedev(struct device *dev);
00438 extern int              ether_config(struct device *dev, struct ifmap *map);
00439 /* Support for loadable net-drivers */
00440 extern int              register_netdev(struct device *dev);
00441 extern void             unregister_netdev(struct device *dev);
00442 extern int              register_trdev(struct device *dev);
00443 extern void             unregister_trdev(struct device *dev);
00444 extern int              register_fddidev(struct device *dev);
00445 extern void             unregister_fddidev(struct device *dev);
00446 extern int              register_fcdev(struct device *dev);
00447 extern void             unregister_fcdev(struct device *dev);
00448 /* Functions used for multicast support */
00449 extern void             dev_mc_upload(struct device *dev);
00450 extern int              dev_mc_delete(struct device *dev, void *addr, int alen, int all);
00451 extern int              dev_mc_add(struct device *dev, void *addr, int alen, int newonly);
00452 extern void             dev_mc_discard(struct device *dev);
00453 extern void             dev_set_promiscuity(struct device *dev, int inc);
00454 extern void             dev_set_allmulti(struct device *dev, int inc);
00455 extern void             netdev_state_change(struct device *dev);
00456 /* Load a device via the kmod */
00457 extern void             dev_load(const char *name);
00458 extern void             dev_mcast_init(void);
00459 extern int              netdev_register_fc(struct device *dev, void (*stimul)(struct device *dev));
00460 extern void             netdev_unregister_fc(int bit);
00461 extern int              netdev_dropping;
00462 extern int              netdev_max_backlog;
00463 extern atomic_t         netdev_rx_dropped;
00464 extern unsigned long    netdev_fc_xoff;
00465 #ifdef CONFIG_NET_FASTROUTE
00466 extern int              netdev_fastroute;
00467 extern int              netdev_fastroute_obstacles;
00468 extern void             dev_clear_fastroute(struct device *dev);
00469 extern struct net_fastroute_stats dev_fastroute_stat;
00470 #endif
00471 
00472 
00473 #endif /* __KERNEL__ */
00474 
00475 #endif  /* _LINUX_DEV_H */