arcnet: Neaten BUGMSG macro defines
[cascardo/linux.git] / include / linux / arcdevice.h
1 /*
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.
5  *
6  *              Definitions used by the ARCnet driver.
7  *
8  * Authors:     Avery Pennarun and David Woodhouse
9  *
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.
14  *
15  */
16 #ifndef _LINUX_ARCDEVICE_H
17 #define _LINUX_ARCDEVICE_H
18
19 #include <asm/timex.h>
20 #include <linux/if_arcnet.h>
21
22 #ifdef __KERNEL__
23 #include  <linux/irqreturn.h>
24
25 /*
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.
29  *
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.
32  *
33  * Do not define RECON_THRESHOLD at all if you want to disable this feature.
34  */
35 #define RECON_THRESHOLD 30
36
37 /*
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.
43  */
44 #define TX_TIMEOUT (HZ * 200 / 1000)
45
46 /* Display warnings about the driver being an ALPHA version. */
47 #undef ALPHA_WARNING
48
49 /*
50  * Debugging bitflags: each option can be enabled individually.
51  *
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
55  *   them out.
56  */
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 */
71
72 #ifndef ARCNET_DEBUG_MAX
73 #define ARCNET_DEBUG_MAX (127)  /* change to ~0 if you want detailed debugging */
74 #endif
75
76 #ifndef ARCNET_DEBUG
77 #define ARCNET_DEBUG (D_NORMAL | D_EXTRA)
78 #endif
79 extern int arcnet_debug;
80
81 #define BUGLVL_TEST(x)  ((x) & ARCNET_DEBUG_MAX & arcnet_debug)
82 #define BUGLVL(x)       if (BUGLVL_TEST(x))
83
84 /* macros to simplify debug checking */
85 #define BUGMSG(x, fmt, ...)                                             \
86 do {                                                                    \
87         if (BUGLVL_TEST(x))                                             \
88                 printk("%s%6s: " fmt,                                   \
89                        (x) == D_NORMAL  ? KERN_WARNING :                \
90                        (x) < D_DURING ? KERN_INFO : KERN_DEBUG,         \
91                        dev->name, ##__VA_ARGS__);                       \
92 } while (0)
93
94 #define BUGMSG2(x, fmt, ...)                                            \
95 do {                                                                    \
96         if (BUGLVL_TEST(x))                                             \
97                 printk(fmt, ##__VA_ARGS__);                             \
98 } while (0)
99
100 /* see how long a function call takes to run, expressed in CPU cycles */
101 #define TIME(name, bytes, call) BUGLVL(D_TIMING) {                      \
102                 unsigned long _x, _y;                                   \
103                 _x = get_cycles();                                      \
104                 call;                                                   \
105                 _y = get_cycles();                                      \
106                 BUGMSG(D_TIMING,                                        \
107                        "%s: %d bytes in %lu cycles == "                 \
108                        "%lu Kbytes/100Mcycle\n",                        \
109                        name, bytes, _y - _x,                            \
110                        100000000 / 1024 * bytes / (_y - _x + 1));       \
111         }                                                               \
112         else {                                                          \
113                 call;                                                   \
114         }
115
116 /*
117  * Time needed to reset the card - in ms (milliseconds).  This works on my
118  * SMC PC100.  I can't find a reference that tells me just how long I
119  * should wait.
120  */
121 #define RESETtime (300)
122
123 /*
124  * These are the max/min lengths of packet payload, not including the
125  * arc_hardware header, but definitely including the soft header.
126  *
127  * Note: packet sizes 254, 255, 256 are impossible because of the way
128  * ARCnet registers work  That's why RFC1201 defines "exception" packets.
129  * In non-RFC1201 protocols, we have to just tack some extra bytes on the
130  * end.
131  */
132 #define MTU     253             /* normal packet max size */
133 #define MinTU   257             /* extended packet min size */
134 #define XMTU    508             /* extended packet max size */
135
136 /* status/interrupt mask bit fields */
137 #define TXFREEflag      0x01    /* transmitter available */
138 #define TXACKflag       0x02    /* transmitted msg. ackd */
139 #define RECONflag       0x04    /* network reconfigured */
140 #define TESTflag        0x08    /* test flag */
141 #define EXCNAKflag      0x08    /* excesive nak flag */
142 #define RESETflag       0x10    /* power-on-reset */
143 #define RES1flag        0x20    /* reserved - usually set by jumper */
144 #define RES2flag        0x40    /* reserved - usually set by jumper */
145 #define NORXflag        0x80    /* receiver inhibited */
146
147 /* Flags used for IO-mapped memory operations */
148 #define AUTOINCflag     0x40    /* Increase location with each access */
149 #define IOMAPflag       0x02    /* (for 90xx) Use IO mapped memory, not mmap */
150 #define ENABLE16flag    0x80    /* (for 90xx) Enable 16-bit mode */
151
152 /* in the command register, the following bits have these meanings:
153  *                0-2     command
154  *                3-4     page number (for enable rcv/xmt command)
155  *                 7      receive broadcasts
156  */
157 #define NOTXcmd         0x01    /* disable transmitter */
158 #define NORXcmd         0x02    /* disable receiver */
159 #define TXcmd           0x03    /* enable transmitter */
160 #define RXcmd           0x04    /* enable receiver */
161 #define CONFIGcmd       0x05    /* define configuration */
162 #define CFLAGScmd       0x06    /* clear flags */
163 #define TESTcmd         0x07    /* load test flags */
164
165 /* flags for "clear flags" command */
166 #define RESETclear      0x08    /* power-on-reset */
167 #define CONFIGclear     0x10    /* system reconfigured */
168
169 #define EXCNAKclear     0x0E    /* Clear and acknowledge the excive nak bit */
170
171 /* flags for "load test flags" command */
172 #define TESTload        0x08    /* test flag (diagnostic) */
173
174 /* byte deposited into first address of buffers on reset */
175 #define TESTvalue       0321    /* that's octal for 0xD1 :) */
176
177 /* for "enable receiver" command */
178 #define RXbcasts        0x80    /* receive broadcasts */
179
180 /* flags for "define configuration" command */
181 #define NORMALconf      0x00    /* 1-249 byte packets */
182 #define EXTconf         0x08    /* 250-504 byte packets */
183
184 /* card feature flags, set during auto-detection.
185  * (currently only used by com20020pci)
186  */
187 #define ARC_IS_5MBIT    1   /* card default speed is 5MBit */
188 #define ARC_CAN_10MBIT  2   /* card uses COM20022, supporting 10MBit,
189                                  but default is 2.5MBit. */
190
191 /* information needed to define an encapsulation driver */
192 struct ArcProto {
193         char suffix;            /* a for RFC1201, e for ether-encap, etc. */
194         int mtu;                /* largest possible packet */
195         int is_ip;              /* This is a ip plugin - not a raw thing */
196
197         void (*rx)(struct net_device *dev, int bufnum,
198                    struct archdr *pkthdr, int length);
199         int (*build_header)(struct sk_buff *skb, struct net_device *dev,
200                             unsigned short ethproto, uint8_t daddr);
201
202         /* these functions return '1' if the skb can now be freed */
203         int (*prepare_tx)(struct net_device *dev, struct archdr *pkt, int length,
204                           int bufnum);
205         int (*continue_tx)(struct net_device *dev, int bufnum);
206         int (*ack_tx)(struct net_device *dev, int acked);
207 };
208
209 extern struct ArcProto *arc_proto_map[256], *arc_proto_default,
210         *arc_bcast_proto, *arc_raw_proto;
211
212 /*
213  * "Incoming" is information needed for each address that could be sending
214  * to us.  Mostly for partially-received split packets.
215  */
216 struct Incoming {
217         struct sk_buff *skb;    /* packet data buffer             */
218         __be16 sequence;        /* sequence number of assembly    */
219         uint8_t lastpacket,     /* number of last packet (from 1) */
220                 numpackets;     /* number of packets in split     */
221 };
222
223 /* only needed for RFC1201 */
224 struct Outgoing {
225         struct ArcProto *proto; /* protocol driver that owns this:
226                                  *   if NULL, no packet is pending.
227                                  */
228         struct sk_buff *skb;    /* buffer from upper levels */
229         struct archdr *pkt;     /* a pointer into the skb */
230         uint16_t length,        /* bytes total */
231                 dataleft,       /* bytes left */
232                 segnum,         /* segment being sent */
233                 numsegs;        /* number of segments */
234 };
235
236 struct arcnet_local {
237         uint8_t config,         /* current value of CONFIG register */
238                 timeout,        /* Extended timeout for COM20020 */
239                 backplane,      /* Backplane flag for COM20020 */
240                 clockp,         /* COM20020 clock divider */
241                 clockm,         /* COM20020 clock multiplier flag */
242                 setup,          /* Contents of setup1 register */
243                 setup2,         /* Contents of setup2 register */
244                 intmask;        /* current value of INTMASK register */
245         uint8_t default_proto[256];     /* default encap to use for each host */
246         int     cur_tx,         /* buffer used by current transmit, or -1 */
247                 next_tx,        /* buffer where a packet is ready to send */
248                 cur_rx;         /* current receive buffer */
249         int     lastload_dest,  /* can last loaded packet be acked? */
250                 lasttrans_dest; /* can last TX'd packet be acked? */
251         int     timed_out;      /* need to process TX timeout and drop packet */
252         unsigned long last_timeout;     /* time of last reported timeout */
253         char *card_name;        /* card ident string */
254         int card_flags;         /* special card features */
255
256         /* On preemtive and SMB a lock is needed */
257         spinlock_t lock;
258
259         /*
260          * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of
261          * which can be used for either sending or receiving.  The new dynamic
262          * buffer management routines use a simple circular queue of available
263          * buffers, and take them as they're needed.  This way, we simplify
264          * situations in which we (for example) want to pre-load a transmit
265          * buffer, or start receiving while we copy a received packet to
266          * memory.
267          *
268          * The rules: only the interrupt handler is allowed to _add_ buffers to
269          * the queue; thus, this doesn't require a lock.  Both the interrupt
270          * handler and the transmit function will want to _remove_ buffers, so
271          * we need to handle the situation where they try to do it at the same
272          * time.
273          *
274          * If next_buf == first_free_buf, the queue is empty.  Since there are
275          * only four possible buffers, the queue should never be full.
276          */
277         atomic_t buf_lock;
278         int buf_queue[5];
279         int next_buf, first_free_buf;
280
281         /* network "reconfiguration" handling */
282         unsigned long first_recon; /* time of "first" RECON message to count */
283         unsigned long last_recon;  /* time of most recent RECON */
284         int num_recons;         /* number of RECONs between first and last. */
285         int network_down;       /* do we think the network is down? */
286
287         int excnak_pending;    /* We just got an excesive nak interrupt */
288
289         struct {
290                 uint16_t sequence;      /* sequence number (incs with each packet) */
291                 __be16 aborted_seq;
292
293                 struct Incoming incoming[256];  /* one from each address */
294         } rfc1201;
295
296         /* really only used by rfc1201, but we'll pretend it's not */
297         struct Outgoing outgoing;       /* packet currently being sent */
298
299         /* hardware-specific functions */
300         struct {
301                 struct module *owner;
302                 void (*command)(struct net_device *dev, int cmd);
303                 int (*status)(struct net_device *dev);
304                 void (*intmask)(struct net_device *dev, int mask);
305                 int (*reset)(struct net_device *dev, int really_reset);
306                 void (*open)(struct net_device *dev);
307                 void (*close)(struct net_device *dev);
308
309                 void (*copy_to_card)(struct net_device *dev, int bufnum, int offset,
310                                      void *buf, int count);
311                 void (*copy_from_card)(struct net_device *dev, int bufnum, int offset,
312                                        void *buf, int count);
313         } hw;
314
315         void __iomem *mem_start;        /* pointer to ioremap'ed MMIO */
316 };
317
318 #define ARCRESET(x)  (lp->hw.reset(dev, (x)))
319 #define ACOMMAND(x)  (lp->hw.command(dev, (x)))
320 #define ASTATUS()    (lp->hw.status(dev))
321 #define AINTMASK(x)  (lp->hw.intmask(dev, (x)))
322
323 #if ARCNET_DEBUG_MAX & D_SKB
324 void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc);
325 #else
326 #define arcnet_dump_skb(dev, skb, desc) ;
327 #endif
328
329 void arcnet_unregister_proto(struct ArcProto *proto);
330 irqreturn_t arcnet_interrupt(int irq, void *dev_id);
331 struct net_device *alloc_arcdev(const char *name);
332
333 int arcnet_open(struct net_device *dev);
334 int arcnet_close(struct net_device *dev);
335 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
336                                struct net_device *dev);
337 void arcnet_timeout(struct net_device *dev);
338
339 #endif                          /* __KERNEL__ */
340 #endif                          /* _LINUX_ARCDEVICE_H */