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