]>
Commit | Line | Data |
---|---|---|
2874c5fd | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
1da177e4 LT |
2 | /* |
3 | * INET An implementation of the TCP/IP protocol suite for the LINUX | |
4 | * operating system. NET is implemented using the BSD Socket | |
5 | * interface as the means of communication with the user level. | |
6 | * | |
7 | * Definitions used by the ARCnet driver. | |
8 | * | |
9 | * Authors: Avery Pennarun and David Woodhouse | |
1da177e4 LT |
10 | */ |
11 | #ifndef _LINUX_ARCDEVICE_H | |
12 | #define _LINUX_ARCDEVICE_H | |
13 | ||
14 | #include <asm/timex.h> | |
15 | #include <linux/if_arcnet.h> | |
16 | ||
17 | #ifdef __KERNEL__ | |
0ab10314 | 18 | #include <linux/interrupt.h> |
1da177e4 | 19 | |
1da177e4 LT |
20 | /* |
21 | * RECON_THRESHOLD is the maximum number of RECON messages to receive | |
22 | * within one minute before printing a "cabling problem" warning. The | |
23 | * default value should be fine. | |
24 | * | |
25 | * After that, a "cabling restored" message will be printed on the next IRQ | |
26 | * if no RECON messages have been received for 10 seconds. | |
27 | * | |
28 | * Do not define RECON_THRESHOLD at all if you want to disable this feature. | |
29 | */ | |
30 | #define RECON_THRESHOLD 30 | |
31 | ||
1da177e4 LT |
32 | /* |
33 | * Define this to the minimum "timeout" value. If a transmit takes longer | |
34 | * than TX_TIMEOUT jiffies, Linux will abort the TX and retry. On a large | |
35 | * network, or one with heavy network traffic, this timeout may need to be | |
36 | * increased. The larger it is, though, the longer it will be between | |
37 | * necessary transmits - don't set this too high. | |
38 | */ | |
39 | #define TX_TIMEOUT (HZ * 200 / 1000) | |
40 | ||
1da177e4 LT |
41 | /* Display warnings about the driver being an ALPHA version. */ |
42 | #undef ALPHA_WARNING | |
43 | ||
1da177e4 LT |
44 | /* |
45 | * Debugging bitflags: each option can be enabled individually. | |
cb334648 | 46 | * |
1da177e4 LT |
47 | * Note: only debug flags included in the ARCNET_DEBUG_MAX define will |
48 | * actually be available. GCC will (at least, GCC 2.7.0 will) notice | |
49 | * lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize | |
50 | * them out. | |
51 | */ | |
52 | #define D_NORMAL 1 /* important operational info */ | |
53 | #define D_EXTRA 2 /* useful, but non-vital information */ | |
54 | #define D_INIT 4 /* show init/probe messages */ | |
55 | #define D_INIT_REASONS 8 /* show reasons for discarding probes */ | |
56 | #define D_RECON 32 /* print a message whenever token is lost */ | |
57 | #define D_PROTO 64 /* debug auto-protocol support */ | |
58 | /* debug levels below give LOTS of output during normal operation! */ | |
59 | #define D_DURING 128 /* trace operations (including irq's) */ | |
60 | #define D_TX 256 /* show tx packets */ | |
61 | #define D_RX 512 /* show rx packets */ | |
62 | #define D_SKB 1024 /* show skb's */ | |
63 | #define D_SKB_SIZE 2048 /* show skb sizes */ | |
64 | #define D_TIMING 4096 /* show time needed to copy buffers to card */ | |
65 | #define D_DEBUG 8192 /* Very detailed debug line for line */ | |
66 | ||
67 | #ifndef ARCNET_DEBUG_MAX | |
68 | #define ARCNET_DEBUG_MAX (127) /* change to ~0 if you want detailed debugging */ | |
69 | #endif | |
70 | ||
71 | #ifndef ARCNET_DEBUG | |
cb334648 | 72 | #define ARCNET_DEBUG (D_NORMAL | D_EXTRA) |
1da177e4 LT |
73 | #endif |
74 | extern int arcnet_debug; | |
75 | ||
72aeea48 | 76 | #define BUGLVL(x) ((x) & ARCNET_DEBUG_MAX & arcnet_debug) |
d77510f3 | 77 | |
1da177e4 | 78 | /* macros to simplify debug checking */ |
a34c0932 | 79 | #define arc_printk(x, dev, fmt, ...) \ |
d77510f3 | 80 | do { \ |
a34c0932 JP |
81 | if (BUGLVL(x)) { \ |
82 | if ((x) == D_NORMAL) \ | |
83 | netdev_warn(dev, fmt, ##__VA_ARGS__); \ | |
84 | else if ((x) < D_DURING) \ | |
85 | netdev_info(dev, fmt, ##__VA_ARGS__); \ | |
86 | else \ | |
87 | netdev_dbg(dev, fmt, ##__VA_ARGS__); \ | |
88 | } \ | |
d77510f3 JP |
89 | } while (0) |
90 | ||
a34c0932 | 91 | #define arc_cont(x, fmt, ...) \ |
d77510f3 | 92 | do { \ |
a34c0932 JP |
93 | if (BUGLVL(x)) \ |
94 | pr_cont(fmt, ##__VA_ARGS__); \ | |
d77510f3 | 95 | } while (0) |
1da177e4 LT |
96 | |
97 | /* see how long a function call takes to run, expressed in CPU cycles */ | |
a34c0932 | 98 | #define TIME(dev, name, bytes, call) \ |
72aeea48 JP |
99 | do { \ |
100 | if (BUGLVL(D_TIMING)) { \ | |
cb334648 JP |
101 | unsigned long _x, _y; \ |
102 | _x = get_cycles(); \ | |
103 | call; \ | |
104 | _y = get_cycles(); \ | |
a34c0932 JP |
105 | arc_printk(D_TIMING, dev, \ |
106 | "%s: %d bytes in %lu cycles == %lu Kbytes/100Mcycle\n", \ | |
107 | name, bytes, _y - _x, \ | |
108 | 100000000 / 1024 * bytes / (_y - _x + 1)); \ | |
72aeea48 | 109 | } else { \ |
cb334648 | 110 | call; \ |
72aeea48 JP |
111 | } \ |
112 | } while (0) | |
1da177e4 | 113 | |
1da177e4 LT |
114 | /* |
115 | * Time needed to reset the card - in ms (milliseconds). This works on my | |
116 | * SMC PC100. I can't find a reference that tells me just how long I | |
117 | * should wait. | |
118 | */ | |
119 | #define RESETtime (300) | |
120 | ||
121 | /* | |
122 | * These are the max/min lengths of packet payload, not including the | |
123 | * arc_hardware header, but definitely including the soft header. | |
124 | * | |
125 | * Note: packet sizes 254, 255, 256 are impossible because of the way | |
126 | * ARCnet registers work That's why RFC1201 defines "exception" packets. | |
127 | * In non-RFC1201 protocols, we have to just tack some extra bytes on the | |
128 | * end. | |
129 | */ | |
130 | #define MTU 253 /* normal packet max size */ | |
131 | #define MinTU 257 /* extended packet min size */ | |
132 | #define XMTU 508 /* extended packet max size */ | |
133 | ||
134 | /* status/interrupt mask bit fields */ | |
135 | #define TXFREEflag 0x01 /* transmitter available */ | |
136 | #define TXACKflag 0x02 /* transmitted msg. ackd */ | |
137 | #define RECONflag 0x04 /* network reconfigured */ | |
138 | #define TESTflag 0x08 /* test flag */ | |
139 | #define EXCNAKflag 0x08 /* excesive nak flag */ | |
140 | #define RESETflag 0x10 /* power-on-reset */ | |
141 | #define RES1flag 0x20 /* reserved - usually set by jumper */ | |
142 | #define RES2flag 0x40 /* reserved - usually set by jumper */ | |
143 | #define NORXflag 0x80 /* receiver inhibited */ | |
144 | ||
145 | /* Flags used for IO-mapped memory operations */ | |
146 | #define AUTOINCflag 0x40 /* Increase location with each access */ | |
147 | #define IOMAPflag 0x02 /* (for 90xx) Use IO mapped memory, not mmap */ | |
148 | #define ENABLE16flag 0x80 /* (for 90xx) Enable 16-bit mode */ | |
149 | ||
150 | /* in the command register, the following bits have these meanings: | |
151 | * 0-2 command | |
152 | * 3-4 page number (for enable rcv/xmt command) | |
153 | * 7 receive broadcasts | |
154 | */ | |
155 | #define NOTXcmd 0x01 /* disable transmitter */ | |
156 | #define NORXcmd 0x02 /* disable receiver */ | |
157 | #define TXcmd 0x03 /* enable transmitter */ | |
158 | #define RXcmd 0x04 /* enable receiver */ | |
159 | #define CONFIGcmd 0x05 /* define configuration */ | |
160 | #define CFLAGScmd 0x06 /* clear flags */ | |
161 | #define TESTcmd 0x07 /* load test flags */ | |
84286f19 | 162 | #define STARTIOcmd 0x18 /* start internal operation */ |
1da177e4 LT |
163 | |
164 | /* flags for "clear flags" command */ | |
165 | #define RESETclear 0x08 /* power-on-reset */ | |
166 | #define CONFIGclear 0x10 /* system reconfigured */ | |
167 | ||
168 | #define EXCNAKclear 0x0E /* Clear and acknowledge the excive nak bit */ | |
169 | ||
170 | /* flags for "load test flags" command */ | |
171 | #define TESTload 0x08 /* test flag (diagnostic) */ | |
172 | ||
173 | /* byte deposited into first address of buffers on reset */ | |
174 | #define TESTvalue 0321 /* that's octal for 0xD1 :) */ | |
175 | ||
176 | /* for "enable receiver" command */ | |
177 | #define RXbcasts 0x80 /* receive broadcasts */ | |
178 | ||
179 | /* flags for "define configuration" command */ | |
180 | #define NORMALconf 0x00 /* 1-249 byte packets */ | |
181 | #define EXTconf 0x08 /* 250-504 byte packets */ | |
182 | ||
183 | /* card feature flags, set during auto-detection. | |
184 | * (currently only used by com20020pci) | |
185 | */ | |
186 | #define ARC_IS_5MBIT 1 /* card default speed is 5MBit */ | |
187 | #define ARC_CAN_10MBIT 2 /* card uses COM20022, supporting 10MBit, | |
188 | but default is 2.5MBit. */ | |
189 | ||
1da177e4 LT |
190 | /* information needed to define an encapsulation driver */ |
191 | struct ArcProto { | |
192 | char suffix; /* a for RFC1201, e for ether-encap, etc. */ | |
193 | int mtu; /* largest possible packet */ | |
194 | int is_ip; /* This is a ip plugin - not a raw thing */ | |
195 | ||
cb334648 JP |
196 | void (*rx)(struct net_device *dev, int bufnum, |
197 | struct archdr *pkthdr, int length); | |
198 | int (*build_header)(struct sk_buff *skb, struct net_device *dev, | |
199 | unsigned short ethproto, uint8_t daddr); | |
1da177e4 LT |
200 | |
201 | /* these functions return '1' if the skb can now be freed */ | |
d6d7d3ed JP |
202 | int (*prepare_tx)(struct net_device *dev, struct archdr *pkt, |
203 | int length, int bufnum); | |
cb334648 JP |
204 | int (*continue_tx)(struct net_device *dev, int bufnum); |
205 | int (*ack_tx)(struct net_device *dev, int acked); | |
1da177e4 LT |
206 | }; |
207 | ||
208 | extern struct ArcProto *arc_proto_map[256], *arc_proto_default, | |
209 | *arc_bcast_proto, *arc_raw_proto; | |
1da177e4 | 210 | |
1da177e4 LT |
211 | /* |
212 | * "Incoming" is information needed for each address that could be sending | |
213 | * to us. Mostly for partially-received split packets. | |
214 | */ | |
215 | struct Incoming { | |
216 | struct sk_buff *skb; /* packet data buffer */ | |
701181ac | 217 | __be16 sequence; /* sequence number of assembly */ |
1da177e4 LT |
218 | uint8_t lastpacket, /* number of last packet (from 1) */ |
219 | numpackets; /* number of packets in split */ | |
220 | }; | |
221 | ||
1da177e4 LT |
222 | /* only needed for RFC1201 */ |
223 | struct Outgoing { | |
224 | struct ArcProto *proto; /* protocol driver that owns this: | |
225 | * if NULL, no packet is pending. | |
226 | */ | |
227 | struct sk_buff *skb; /* buffer from upper levels */ | |
228 | struct archdr *pkt; /* a pointer into the skb */ | |
229 | uint16_t length, /* bytes total */ | |
230 | dataleft, /* bytes left */ | |
231 | segnum, /* segment being sent */ | |
232 | numsegs; /* number of segments */ | |
233 | }; | |
234 | ||
8890624a MG |
235 | #define ARCNET_LED_NAME_SZ (IFNAMSIZ + 6) |
236 | ||
1da177e4 | 237 | struct arcnet_local { |
1da177e4 LT |
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 */ | |
256 | ||
1da177e4 LT |
257 | /* On preemtive and SMB a lock is needed */ |
258 | spinlock_t lock; | |
259 | ||
8890624a MG |
260 | struct led_trigger *tx_led_trig; |
261 | char tx_led_trig_name[ARCNET_LED_NAME_SZ]; | |
262 | struct led_trigger *recon_led_trig; | |
263 | char recon_led_trig_name[ARCNET_LED_NAME_SZ]; | |
264 | ||
59fbcbc6 MG |
265 | struct timer_list timer; |
266 | ||
05fcd31c MG |
267 | struct net_device *dev; |
268 | int reply_status; | |
269 | struct tasklet_struct reply_tasklet; | |
270 | ||
1da177e4 LT |
271 | /* |
272 | * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of | |
273 | * which can be used for either sending or receiving. The new dynamic | |
274 | * buffer management routines use a simple circular queue of available | |
275 | * buffers, and take them as they're needed. This way, we simplify | |
276 | * situations in which we (for example) want to pre-load a transmit | |
277 | * buffer, or start receiving while we copy a received packet to | |
278 | * memory. | |
cb334648 | 279 | * |
1da177e4 LT |
280 | * The rules: only the interrupt handler is allowed to _add_ buffers to |
281 | * the queue; thus, this doesn't require a lock. Both the interrupt | |
282 | * handler and the transmit function will want to _remove_ buffers, so | |
283 | * we need to handle the situation where they try to do it at the same | |
284 | * time. | |
cb334648 | 285 | * |
1da177e4 LT |
286 | * If next_buf == first_free_buf, the queue is empty. Since there are |
287 | * only four possible buffers, the queue should never be full. | |
288 | */ | |
289 | atomic_t buf_lock; | |
290 | int buf_queue[5]; | |
291 | int next_buf, first_free_buf; | |
292 | ||
293 | /* network "reconfiguration" handling */ | |
9307b570 CO |
294 | unsigned long first_recon; /* time of "first" RECON message to count */ |
295 | unsigned long last_recon; /* time of most recent RECON */ | |
1da177e4 | 296 | int num_recons; /* number of RECONs between first and last. */ |
db55b62c | 297 | int network_down; /* do we think the network is down? */ |
1da177e4 | 298 | |
db55b62c | 299 | int excnak_pending; /* We just got an excesive nak interrupt */ |
1da177e4 LT |
300 | |
301 | struct { | |
302 | uint16_t sequence; /* sequence number (incs with each packet) */ | |
701181ac | 303 | __be16 aborted_seq; |
1da177e4 LT |
304 | |
305 | struct Incoming incoming[256]; /* one from each address */ | |
306 | } rfc1201; | |
307 | ||
308 | /* really only used by rfc1201, but we'll pretend it's not */ | |
309 | struct Outgoing outgoing; /* packet currently being sent */ | |
310 | ||
311 | /* hardware-specific functions */ | |
312 | struct { | |
313 | struct module *owner; | |
cb334648 JP |
314 | void (*command)(struct net_device *dev, int cmd); |
315 | int (*status)(struct net_device *dev); | |
316 | void (*intmask)(struct net_device *dev, int mask); | |
317 | int (*reset)(struct net_device *dev, int really_reset); | |
318 | void (*open)(struct net_device *dev); | |
319 | void (*close)(struct net_device *dev); | |
8890624a MG |
320 | void (*datatrigger) (struct net_device * dev, int enable); |
321 | void (*recontrigger) (struct net_device * dev, int enable); | |
cb334648 | 322 | |
d6d7d3ed JP |
323 | void (*copy_to_card)(struct net_device *dev, int bufnum, |
324 | int offset, void *buf, int count); | |
325 | void (*copy_from_card)(struct net_device *dev, int bufnum, | |
326 | int offset, void *buf, int count); | |
1da177e4 LT |
327 | } hw; |
328 | ||
329 | void __iomem *mem_start; /* pointer to ioremap'ed MMIO */ | |
330 | }; | |
331 | ||
8890624a MG |
332 | enum arcnet_led_event { |
333 | ARCNET_LED_EVENT_RECON, | |
334 | ARCNET_LED_EVENT_OPEN, | |
335 | ARCNET_LED_EVENT_STOP, | |
336 | ARCNET_LED_EVENT_TX, | |
337 | }; | |
338 | ||
339 | void arcnet_led_event(struct net_device *netdev, enum arcnet_led_event event); | |
340 | void devm_arcnet_led_init(struct net_device *netdev, int index, int subid); | |
341 | ||
1da177e4 LT |
342 | #if ARCNET_DEBUG_MAX & D_SKB |
343 | void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc); | |
344 | #else | |
83df99b5 JP |
345 | static inline |
346 | void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc) | |
347 | { | |
348 | } | |
1da177e4 LT |
349 | #endif |
350 | ||
1da177e4 | 351 | void arcnet_unregister_proto(struct ArcProto *proto); |
7d12e780 | 352 | irqreturn_t arcnet_interrupt(int irq, void *dev_id); |
bca5b893 SH |
353 | struct net_device *alloc_arcdev(const char *name); |
354 | ||
355 | int arcnet_open(struct net_device *dev); | |
356 | int arcnet_close(struct net_device *dev); | |
61357325 | 357 | netdev_tx_t arcnet_send_packet(struct sk_buff *skb, |
cb334648 | 358 | struct net_device *dev); |
bca5b893 | 359 | void arcnet_timeout(struct net_device *dev); |
1da177e4 | 360 | |
e5fcfc1f JP |
361 | /* I/O equivalents */ |
362 | ||
0fec6513 JP |
363 | #ifdef CONFIG_SA1100_CT6001 |
364 | #define BUS_ALIGN 2 /* 8 bit device on a 16 bit bus - needs padding */ | |
365 | #else | |
366 | #define BUS_ALIGN 1 | |
367 | #endif | |
368 | ||
e5fcfc1f JP |
369 | /* addr and offset allow register like names to define the actual IO address. |
370 | * A configuration option multiplies the offset for alignment. | |
371 | */ | |
372 | #define arcnet_inb(addr, offset) \ | |
0fec6513 | 373 | inb((addr) + BUS_ALIGN * (offset)) |
e5fcfc1f | 374 | #define arcnet_outb(value, addr, offset) \ |
0fec6513 | 375 | outb(value, (addr) + BUS_ALIGN * (offset)) |
e5fcfc1f JP |
376 | |
377 | #define arcnet_insb(addr, offset, buffer, count) \ | |
0fec6513 | 378 | insb((addr) + BUS_ALIGN * (offset), buffer, count) |
e5fcfc1f | 379 | #define arcnet_outsb(addr, offset, buffer, count) \ |
0fec6513 | 380 | outsb((addr) + BUS_ALIGN * (offset), buffer, count) |
e5fcfc1f | 381 | |
9c76aa55 JP |
382 | #define arcnet_readb(addr, offset) \ |
383 | readb((addr) + (offset)) | |
384 | #define arcnet_writeb(value, addr, offset) \ | |
385 | writeb(value, (addr) + (offset)) | |
386 | ||
1da177e4 LT |
387 | #endif /* __KERNEL__ */ |
388 | #endif /* _LINUX_ARCDEVICE_H */ |