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@super.org>
14 * Alan Cox, <A.Cox@swansea.ac.uk>
15 * Bjorn Ekwall. <bj0rn@blox.se>
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 *
22 * Moved to /usr/include/linux for NET3
23 */
24 #ifndef _LINUX_NETDEVICE_H
25 #define _LINUX_NETDEVICE_H
26
27 #include <linux/config.h>
28 #include <linux/if.h>
29 #include <linux/if_ether.h>
30 #include <linux/skbuff.h>
31
32 /* for future expansion when we will have different priorities. */
33 #define DEV_NUMBUFFS 3
34 #define MAX_ADDR_LEN 7
35 #ifndef CONFIG_AX25
36 #ifndef CONFIG_TR
37 #define MAX_HEADER 32 /* We really need about 18 worst case .. so 32 is aligned */
38 #else
39 #define MAX_HEADER 48 /* Token Ring header needs 40 bytes ... 48 is aligned */
40 #endif
41 #else
42 #define MAX_HEADER 96 /* AX.25 + NetROM */
43 #endif
44
45 #define IS_MYADDR 1 /* address is (one of) our own */
46 #define IS_LOOPBACK 2 /* address is for LOOPBACK */
47 #define IS_BROADCAST 3 /* address is a valid broadcast */
48 #define IS_INVBCAST 4 /* Wrong netmask bcast not for us (unused)*/
49 #define IS_MULTICAST 5 /* Multicast IP address */
50
51 /*
52 * We tag these structures with multicasts.
53 */
54
55 struct dev_mc_list
56 {
57 struct dev_mc_list *next;
58 char dmi_addr[MAX_ADDR_LEN];
59 unsigned short dmi_addrlen;
60 unsigned short dmi_users;
61 };
62
63 struct hh_cache
64 {
65 struct hh_cache *hh_next;
66 unsigned long hh_refcnt; /* number of users */
67 void *hh_arp; /* Opaque pointer, used by
68 * any address resolution module,
69 * not only ARP.
70 */
71 unsigned short hh_type; /* protocol identifier, f.e ETH_P_IP */
72 char hh_uptodate; /* hh_data is valid */
73 char hh_data[16]; /* cached hardware header */
74 };
75
76 /*
77 * The DEVICE structure.
78 * Actually, this whole structure is a big mistake. It mixes I/O
79 * data with strictly "high-level" data, and it has to know about
80 * almost every data structure used in the INET module.
81 */
82 struct device
83 {
84
85 /*
86 * This is the first field of the "visible" part of this structure
87 * (i.e. as seen by users in the "Space.c" file). It is the name
88 * the interface.
89 */
90 char *name;
91
92 /* I/O specific fields - FIXME: Merge these and struct ifmap into one */
93 unsigned long rmem_end; /* shmem "recv" end */
94 unsigned long rmem_start; /* shmem "recv" start */
95 unsigned long mem_end; /* shared mem end */
96 unsigned long mem_start; /* shared mem start */
97 unsigned long base_addr; /* device I/O address */
98 unsigned char irq; /* device IRQ number */
99
100 /* Low-level status flags. */
101 volatile unsigned char start, /* start an operation */
102 interrupt; /* interrupt arrived */
103 unsigned long tbusy; /* transmitter busy must be long for bitops */
104
105 struct device *next;
106
107 /* The device initialization function. Called only once. */
108 int (*init)(struct device *dev);
109
110 /* Some hardware also needs these fields, but they are not part of the
111 usual set specified in Space.c. */
112 unsigned char if_port; /* Selectable AUI, TP,..*/
113 unsigned char dma; /* DMA channel */
114
115 struct enet_statistics* (*get_stats)(struct device *dev);
116
117 /*
118 * This marks the end of the "visible" part of the structure. All
119 * fields hereafter are internal to the system, and may change at
120 * will (read: may be cleaned up at will).
121 */
122
123 /* These may be needed for future network-power-down code. */
124 unsigned long trans_start; /* Time (in jiffies) of last Tx */
125 unsigned long last_rx; /* Time of last Rx */
126
127 unsigned short flags; /* interface flags (a la BSD) */
128 unsigned short family; /* address family ID (AF_INET) */
129 unsigned short metric; /* routing metric (not used) */
130 unsigned short mtu; /* interface MTU value */
131 unsigned short type; /* interface hardware type */
132 unsigned short hard_header_len; /* hardware hdr length */
133 void *priv; /* pointer to private data */
134
135 /* Interface address info. */
136 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
137 unsigned char pad; /* make dev_addr aligned to 8 bytes */
138 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */
139 unsigned char addr_len; /* hardware address length */
140 unsigned long pa_addr; /* protocol address */
141 unsigned long pa_brdaddr; /* protocol broadcast addr */
142 unsigned long pa_dstaddr; /* protocol P-P other side addr */
143 unsigned long pa_mask; /* protocol netmask */
144 unsigned short pa_alen; /* protocol address length */
145
146 struct dev_mc_list *mc_list; /* Multicast mac addresses */
147 int mc_count; /* Number of installed mcasts */
148
149 struct ip_mc_list *ip_mc_list; /* IP multicast filter chain */
150
151 /* For load balancing driver pair support */
152
153 unsigned long pkt_queue; /* Packets queued */
154 struct device *slave; /* Slave device */
155
156
157 /* Pointer to the interface buffers. */
158 struct sk_buff_head buffs[DEV_NUMBUFFS];
159
160 /* Pointers to interface service routines. */
161 int (*open)(struct device *dev);
162 int (*stop)(struct device *dev);
163 int (*hard_start_xmit) (struct sk_buff *skb,
164 struct device *dev);
165 int (*hard_header) (struct sk_buff *skb,
166 struct device *dev,
167 unsigned short type,
168 void *daddr,
169 void *saddr,
170 unsigned len);
171 int (*rebuild_header)(void *eth, struct device *dev,
172 unsigned long raddr, struct sk_buff *skb);
173 #define HAVE_MULTICAST
174 void (*set_multicast_list)(struct device *dev);
175 #define HAVE_SET_MAC_ADDR
176 int (*set_mac_address)(struct device *dev, void *addr);
177 #define HAVE_PRIVATE_IOCTL
178 int (*do_ioctl)(struct device *dev, struct ifreq *ifr, int cmd);
179 #define HAVE_SET_CONFIG
180 int (*set_config)(struct device *dev, struct ifmap *map);
181 #define HAVE_HEADER_CACHE
182 void (*header_cache_bind)(struct hh_cache **hhp, struct device *dev, unsigned short htype, __u32 daddr);
183 void (*header_cache_update)(struct hh_cache *hh, struct device *dev, unsigned char * haddr);
184 };
185
186
187 struct packet_type {
188 unsigned short type; /* This is really htons(ether_type). */
189 struct device * dev;
190 int (*func) (struct sk_buff *, struct device *,
191 struct packet_type *);
192 void *data;
193 struct packet_type *next;
194 };
195
196
197 #ifdef __KERNEL__
198
199 #include <linux/notifier.h>
200
201 /* Used by dev_rint */
202 #define IN_SKBUFF 1
203
204 extern volatile unsigned long in_bh;
205
206 extern struct device loopback_dev;
207 extern struct device *dev_base;
208 extern struct packet_type *ptype_base[16];
209
210
211 extern int ip_addr_match(unsigned long addr1, unsigned long addr2);
212 extern int ip_chk_addr(unsigned long addr);
213 extern struct device *ip_dev_check(unsigned long daddr);
214 extern unsigned long ip_my_addr(void);
215 extern unsigned long ip_get_mask(unsigned long addr);
216 extern struct device *ip_dev_find(unsigned long addr);
217 extern struct device *dev_getbytype(unsigned short type);
218
219 extern void dev_add_pack(struct packet_type *pt);
220 extern void dev_remove_pack(struct packet_type *pt);
221 extern struct device *dev_get(const char *name);
222 extern int dev_open(struct device *dev);
223 extern int dev_close(struct device *dev);
224 extern void dev_queue_xmit(struct sk_buff *skb, struct device *dev,
225 int pri);
226 #define HAVE_NETIF_RX 1
227 extern void netif_rx(struct sk_buff *skb);
228 /* The old interface to netif_rx(). */
229 extern int dev_rint(unsigned char *buff, long len, int flags,
230 struct device * dev);
231 extern void dev_transmit(void);
232 extern int in_net_bh(void);
233 extern void net_bh(void *tmp);
234 extern void dev_tint(struct device *dev);
235 extern int dev_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
236 extern int dev_ioctl(unsigned int cmd, void *);
237
238 extern void dev_init(void);
239
240 /* Locking protection for page faults during outputs to devices unloaded during the fault */
241
242 extern int dev_lockct;
243
244 /*
245 * These two dont currently need to be interrupt safe
246 * but they may do soon. Do it properly anyway.
247 */
248
249 extern __inline__ void dev_lock_list(void)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
250 {
251 unsigned long flags;
252 save_flags(flags);
253 cli();
254 dev_lockct++;
255 restore_flags(flags);
256 }
257
258 extern __inline__ void dev_unlock_list(void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
259 {
260 unsigned long flags;
261 save_flags(flags);
262 cli();
263 dev_lockct--;
264 restore_flags(flags);
265 }
266
267 /*
268 * This almost never occurs, isnt in performance critical paths
269 * and we can thus be relaxed about it
270 */
271
272 extern __inline__ void dev_lock_wait(void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
273 {
274 while(dev_lockct)
275 schedule();
276 }
277
278
279 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
280
281 extern void ether_setup(struct device *dev);
282 extern void tr_setup(struct device *dev);
283 extern int ether_config(struct device *dev, struct ifmap *map);
284 /* Support for loadable net-drivers */
285 extern int register_netdev(struct device *dev);
286 extern void unregister_netdev(struct device *dev);
287 extern int register_netdevice_notifier(struct notifier_block *nb);
288 extern int unregister_netdevice_notifier(struct notifier_block *nb);
289 /* Functions used for multicast support */
290 extern void dev_mc_upload(struct device *dev);
291 extern void dev_mc_delete(struct device *dev, void *addr, int alen, int all);
292 extern void dev_mc_add(struct device *dev, void *addr, int alen, int newonly);
293 extern void dev_mc_discard(struct device *dev);
294 /* This is the wrong place but it'll do for the moment */
295 extern void ip_mc_allhost(struct device *dev);
296 #endif /* __KERNEL__ */
297
298 #endif /* _LINUX_DEV_H */