2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. NET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * Definitions used by the ARCnet driver.
8 * Authors: Avery Pennarun and David Woodhouse
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
16 #ifndef _LINUX_ARCDEVICE_H
17 #define _LINUX_ARCDEVICE_H
19 #include <asm/timex.h>
20 #include <linux/if_arcnet.h>
23 #include <linux/irqreturn.h>
26 * RECON_THRESHOLD is the maximum number of RECON messages to receive
27 * within one minute before printing a "cabling problem" warning. The
28 * default value should be fine.
30 * After that, a "cabling restored" message will be printed on the next IRQ
31 * if no RECON messages have been received for 10 seconds.
33 * Do not define RECON_THRESHOLD at all if you want to disable this feature.
35 #define RECON_THRESHOLD 30
38 * Define this to the minimum "timeout" value. If a transmit takes longer
39 * than TX_TIMEOUT jiffies, Linux will abort the TX and retry. On a large
40 * network, or one with heavy network traffic, this timeout may need to be
41 * increased. The larger it is, though, the longer it will be between
42 * necessary transmits - don't set this too high.
44 #define TX_TIMEOUT (HZ * 200 / 1000)
46 /* Display warnings about the driver being an ALPHA version. */
50 * Debugging bitflags: each option can be enabled individually.
52 * Note: only debug flags included in the ARCNET_DEBUG_MAX define will
53 * actually be available. GCC will (at least, GCC 2.7.0 will) notice
54 * lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize
57 #define D_NORMAL 1 /* important operational info */
58 #define D_EXTRA 2 /* useful, but non-vital information */
59 #define D_INIT 4 /* show init/probe messages */
60 #define D_INIT_REASONS 8 /* show reasons for discarding probes */
61 #define D_RECON 32 /* print a message whenever token is lost */
62 #define D_PROTO 64 /* debug auto-protocol support */
63 /* debug levels below give LOTS of output during normal operation! */
64 #define D_DURING 128 /* trace operations (including irq's) */
65 #define D_TX 256 /* show tx packets */
66 #define D_RX 512 /* show rx packets */
67 #define D_SKB 1024 /* show skb's */
68 #define D_SKB_SIZE 2048 /* show skb sizes */
69 #define D_TIMING 4096 /* show time needed to copy buffers to card */
70 #define D_DEBUG 8192 /* Very detailed debug line for line */
72 #ifndef ARCNET_DEBUG_MAX
73 #define ARCNET_DEBUG_MAX (127) /* change to ~0 if you want detailed debugging */
77 #define ARCNET_DEBUG (D_NORMAL | D_EXTRA)
79 extern int arcnet_debug;
81 #define BUGLVL(x) ((x) & ARCNET_DEBUG_MAX & arcnet_debug)
83 /* macros to simplify debug checking */
84 #define BUGMSG(x, fmt, ...) \
87 printk("%s%6s: " fmt, \
88 (x) == D_NORMAL ? KERN_WARNING : \
89 (x) < D_DURING ? KERN_INFO : KERN_DEBUG, \
90 dev->name, ##__VA_ARGS__); \
93 #define BUGMSG2(x, fmt, ...) \
96 printk(fmt, ##__VA_ARGS__); \
99 /* see how long a function call takes to run, expressed in CPU cycles */
100 #define TIME(name, bytes, call) \
102 if (BUGLVL(D_TIMING)) { \
103 unsigned long _x, _y; \
108 "%s: %d bytes in %lu cycles == " \
109 "%lu Kbytes/100Mcycle\n", \
110 name, bytes, _y - _x, \
111 100000000 / 1024 * bytes / (_y - _x + 1)); \
118 * Time needed to reset the card - in ms (milliseconds). This works on my
119 * SMC PC100. I can't find a reference that tells me just how long I
122 #define RESETtime (300)
125 * These are the max/min lengths of packet payload, not including the
126 * arc_hardware header, but definitely including the soft header.
128 * Note: packet sizes 254, 255, 256 are impossible because of the way
129 * ARCnet registers work That's why RFC1201 defines "exception" packets.
130 * In non-RFC1201 protocols, we have to just tack some extra bytes on the
133 #define MTU 253 /* normal packet max size */
134 #define MinTU 257 /* extended packet min size */
135 #define XMTU 508 /* extended packet max size */
137 /* status/interrupt mask bit fields */
138 #define TXFREEflag 0x01 /* transmitter available */
139 #define TXACKflag 0x02 /* transmitted msg. ackd */
140 #define RECONflag 0x04 /* network reconfigured */
141 #define TESTflag 0x08 /* test flag */
142 #define EXCNAKflag 0x08 /* excesive nak flag */
143 #define RESETflag 0x10 /* power-on-reset */
144 #define RES1flag 0x20 /* reserved - usually set by jumper */
145 #define RES2flag 0x40 /* reserved - usually set by jumper */
146 #define NORXflag 0x80 /* receiver inhibited */
148 /* Flags used for IO-mapped memory operations */
149 #define AUTOINCflag 0x40 /* Increase location with each access */
150 #define IOMAPflag 0x02 /* (for 90xx) Use IO mapped memory, not mmap */
151 #define ENABLE16flag 0x80 /* (for 90xx) Enable 16-bit mode */
153 /* in the command register, the following bits have these meanings:
155 * 3-4 page number (for enable rcv/xmt command)
156 * 7 receive broadcasts
158 #define NOTXcmd 0x01 /* disable transmitter */
159 #define NORXcmd 0x02 /* disable receiver */
160 #define TXcmd 0x03 /* enable transmitter */
161 #define RXcmd 0x04 /* enable receiver */
162 #define CONFIGcmd 0x05 /* define configuration */
163 #define CFLAGScmd 0x06 /* clear flags */
164 #define TESTcmd 0x07 /* load test flags */
166 /* flags for "clear flags" command */
167 #define RESETclear 0x08 /* power-on-reset */
168 #define CONFIGclear 0x10 /* system reconfigured */
170 #define EXCNAKclear 0x0E /* Clear and acknowledge the excive nak bit */
172 /* flags for "load test flags" command */
173 #define TESTload 0x08 /* test flag (diagnostic) */
175 /* byte deposited into first address of buffers on reset */
176 #define TESTvalue 0321 /* that's octal for 0xD1 :) */
178 /* for "enable receiver" command */
179 #define RXbcasts 0x80 /* receive broadcasts */
181 /* flags for "define configuration" command */
182 #define NORMALconf 0x00 /* 1-249 byte packets */
183 #define EXTconf 0x08 /* 250-504 byte packets */
185 /* card feature flags, set during auto-detection.
186 * (currently only used by com20020pci)
188 #define ARC_IS_5MBIT 1 /* card default speed is 5MBit */
189 #define ARC_CAN_10MBIT 2 /* card uses COM20022, supporting 10MBit,
190 but default is 2.5MBit. */
192 /* information needed to define an encapsulation driver */
194 char suffix; /* a for RFC1201, e for ether-encap, etc. */
195 int mtu; /* largest possible packet */
196 int is_ip; /* This is a ip plugin - not a raw thing */
198 void (*rx)(struct net_device *dev, int bufnum,
199 struct archdr *pkthdr, int length);
200 int (*build_header)(struct sk_buff *skb, struct net_device *dev,
201 unsigned short ethproto, uint8_t daddr);
203 /* these functions return '1' if the skb can now be freed */
204 int (*prepare_tx)(struct net_device *dev, struct archdr *pkt, int length,
206 int (*continue_tx)(struct net_device *dev, int bufnum);
207 int (*ack_tx)(struct net_device *dev, int acked);
210 extern struct ArcProto *arc_proto_map[256], *arc_proto_default,
211 *arc_bcast_proto, *arc_raw_proto;
214 * "Incoming" is information needed for each address that could be sending
215 * to us. Mostly for partially-received split packets.
218 struct sk_buff *skb; /* packet data buffer */
219 __be16 sequence; /* sequence number of assembly */
220 uint8_t lastpacket, /* number of last packet (from 1) */
221 numpackets; /* number of packets in split */
224 /* only needed for RFC1201 */
226 struct ArcProto *proto; /* protocol driver that owns this:
227 * if NULL, no packet is pending.
229 struct sk_buff *skb; /* buffer from upper levels */
230 struct archdr *pkt; /* a pointer into the skb */
231 uint16_t length, /* bytes total */
232 dataleft, /* bytes left */
233 segnum, /* segment being sent */
234 numsegs; /* number of segments */
237 struct arcnet_local {
238 uint8_t config, /* current value of CONFIG register */
239 timeout, /* Extended timeout for COM20020 */
240 backplane, /* Backplane flag for COM20020 */
241 clockp, /* COM20020 clock divider */
242 clockm, /* COM20020 clock multiplier flag */
243 setup, /* Contents of setup1 register */
244 setup2, /* Contents of setup2 register */
245 intmask; /* current value of INTMASK register */
246 uint8_t default_proto[256]; /* default encap to use for each host */
247 int cur_tx, /* buffer used by current transmit, or -1 */
248 next_tx, /* buffer where a packet is ready to send */
249 cur_rx; /* current receive buffer */
250 int lastload_dest, /* can last loaded packet be acked? */
251 lasttrans_dest; /* can last TX'd packet be acked? */
252 int timed_out; /* need to process TX timeout and drop packet */
253 unsigned long last_timeout; /* time of last reported timeout */
254 char *card_name; /* card ident string */
255 int card_flags; /* special card features */
257 /* On preemtive and SMB a lock is needed */
261 * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of
262 * which can be used for either sending or receiving. The new dynamic
263 * buffer management routines use a simple circular queue of available
264 * buffers, and take them as they're needed. This way, we simplify
265 * situations in which we (for example) want to pre-load a transmit
266 * buffer, or start receiving while we copy a received packet to
269 * The rules: only the interrupt handler is allowed to _add_ buffers to
270 * the queue; thus, this doesn't require a lock. Both the interrupt
271 * handler and the transmit function will want to _remove_ buffers, so
272 * we need to handle the situation where they try to do it at the same
275 * If next_buf == first_free_buf, the queue is empty. Since there are
276 * only four possible buffers, the queue should never be full.
280 int next_buf, first_free_buf;
282 /* network "reconfiguration" handling */
283 unsigned long first_recon; /* time of "first" RECON message to count */
284 unsigned long last_recon; /* time of most recent RECON */
285 int num_recons; /* number of RECONs between first and last. */
286 int network_down; /* do we think the network is down? */
288 int excnak_pending; /* We just got an excesive nak interrupt */
291 uint16_t sequence; /* sequence number (incs with each packet) */
294 struct Incoming incoming[256]; /* one from each address */
297 /* really only used by rfc1201, but we'll pretend it's not */
298 struct Outgoing outgoing; /* packet currently being sent */
300 /* hardware-specific functions */
302 struct module *owner;
303 void (*command)(struct net_device *dev, int cmd);
304 int (*status)(struct net_device *dev);
305 void (*intmask)(struct net_device *dev, int mask);
306 int (*reset)(struct net_device *dev, int really_reset);
307 void (*open)(struct net_device *dev);
308 void (*close)(struct net_device *dev);
310 void (*copy_to_card)(struct net_device *dev, int bufnum, int offset,
311 void *buf, int count);
312 void (*copy_from_card)(struct net_device *dev, int bufnum, int offset,
313 void *buf, int count);
316 void __iomem *mem_start; /* pointer to ioremap'ed MMIO */
319 #define ARCRESET(x) (lp->hw.reset(dev, (x)))
320 #define ACOMMAND(x) (lp->hw.command(dev, (x)))
321 #define ASTATUS() (lp->hw.status(dev))
322 #define AINTMASK(x) (lp->hw.intmask(dev, (x)))
324 #if ARCNET_DEBUG_MAX & D_SKB
325 void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc);
327 #define arcnet_dump_skb(dev, skb, desc) ;
330 void arcnet_unregister_proto(struct ArcProto *proto);
331 irqreturn_t arcnet_interrupt(int irq, void *dev_id);
332 struct net_device *alloc_arcdev(const char *name);
334 int arcnet_open(struct net_device *dev);
335 int arcnet_close(struct net_device *dev);
336 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
337 struct net_device *dev);
338 void arcnet_timeout(struct net_device *dev);
340 #endif /* __KERNEL__ */
341 #endif /* _LINUX_ARCDEVICE_H */