Blame view

drivers/net/arcnet/arcdevice.h 14 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /*
   * INET         An implementation of the TCP/IP protocol suite for the LINUX
   *              operating system.  NET  is implemented using the  BSD Socket
   *              interface as the means of communication with the user level.
   *
   *              Definitions used by the ARCnet driver.
   *
   * Authors:     Avery Pennarun and David Woodhouse
   *
   *              This program is free software; you can redistribute it and/or
   *              modify it under the terms of the GNU General Public License
   *              as published by the Free Software Foundation; either version
   *              2 of the License, or (at your option) any later version.
   *
   */
  #ifndef _LINUX_ARCDEVICE_H
  #define _LINUX_ARCDEVICE_H
  
  #include <asm/timex.h>
  #include <linux/if_arcnet.h>
  
  #ifdef __KERNEL__
a6b7a4078   Alexey Dobriyan   net: remove inter...
23
  #include  <linux/irqreturn.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
28
29
30
31
32
33
34
35
  /*
   * RECON_THRESHOLD is the maximum number of RECON messages to receive
   * within one minute before printing a "cabling problem" warning. The
   * default value should be fine.
   *
   * After that, a "cabling restored" message will be printed on the next IRQ
   * if no RECON messages have been received for 10 seconds.
   *
   * Do not define RECON_THRESHOLD at all if you want to disable this feature.
   */
  #define RECON_THRESHOLD 30
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
40
41
42
43
  /*
   * Define this to the minimum "timeout" value.  If a transmit takes longer
   * than TX_TIMEOUT jiffies, Linux will abort the TX and retry.  On a large
   * network, or one with heavy network traffic, this timeout may need to be
   * increased.  The larger it is, though, the longer it will be between
   * necessary transmits - don't set this too high.
   */
  #define TX_TIMEOUT (HZ * 200 / 1000)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
  /* Display warnings about the driver being an ALPHA version. */
  #undef ALPHA_WARNING
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
  /*
   * Debugging bitflags: each option can be enabled individually.
cb334648a   Joe Perches   arcnet: Use norma...
48
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
   * Note: only debug flags included in the ARCNET_DEBUG_MAX define will
   *   actually be available.  GCC will (at least, GCC 2.7.0 will) notice
   *   lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize
   *   them out.
   */
  #define D_NORMAL	1	/* important operational info             */
  #define D_EXTRA		2	/* useful, but non-vital information      */
  #define	D_INIT		4	/* show init/probe messages               */
  #define D_INIT_REASONS	8	/* show reasons for discarding probes     */
  #define D_RECON		32	/* print a message whenever token is lost */
  #define D_PROTO		64	/* debug auto-protocol support            */
  /* debug levels below give LOTS of output during normal operation! */
  #define D_DURING	128	/* trace operations (including irq's)     */
  #define D_TX	        256	/* show tx packets                        */
  #define D_RX		512	/* show rx packets                        */
  #define D_SKB		1024	/* show skb's                             */
  #define D_SKB_SIZE	2048	/* show skb sizes			  */
  #define D_TIMING	4096	/* show time needed to copy buffers to card */
  #define D_DEBUG         8192    /* Very detailed debug line for line */
  
  #ifndef ARCNET_DEBUG_MAX
  #define ARCNET_DEBUG_MAX (127)	/* change to ~0 if you want detailed debugging */
  #endif
  
  #ifndef ARCNET_DEBUG
cb334648a   Joe Perches   arcnet: Use norma...
74
  #define ARCNET_DEBUG (D_NORMAL | D_EXTRA)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
76
  #endif
  extern int arcnet_debug;
72aeea484   Joe Perches   arcnet: Expand od...
77
  #define BUGLVL(x)	((x) & ARCNET_DEBUG_MAX & arcnet_debug)
d77510f34   Joe Perches   arcnet: Neaten BU...
78

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  /* macros to simplify debug checking */
a34c0932c   Joe Perches   arcnet: Convert B...
80
  #define arc_printk(x, dev, fmt, ...)					\
d77510f34   Joe Perches   arcnet: Neaten BU...
81
  do {									\
a34c0932c   Joe Perches   arcnet: Convert B...
82
83
84
85
86
87
88
89
  	if (BUGLVL(x)) {						\
  		if ((x) == D_NORMAL)					\
  			netdev_warn(dev, fmt, ##__VA_ARGS__);		\
  		else if ((x) < D_DURING)				\
  			netdev_info(dev, fmt, ##__VA_ARGS__);		\
  		else							\
  			netdev_dbg(dev, fmt, ##__VA_ARGS__);		\
  	}								\
d77510f34   Joe Perches   arcnet: Neaten BU...
90
  } while (0)
a34c0932c   Joe Perches   arcnet: Convert B...
91
  #define arc_cont(x, fmt, ...)						\
d77510f34   Joe Perches   arcnet: Neaten BU...
92
  do {									\
a34c0932c   Joe Perches   arcnet: Convert B...
93
94
  	if (BUGLVL(x))							\
  		pr_cont(fmt, ##__VA_ARGS__);				\
d77510f34   Joe Perches   arcnet: Neaten BU...
95
  } while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
  
  /* see how long a function call takes to run, expressed in CPU cycles */
a34c0932c   Joe Perches   arcnet: Convert B...
98
  #define TIME(dev, name, bytes, call)					\
72aeea484   Joe Perches   arcnet: Expand od...
99
100
  do {									\
  	if (BUGLVL(D_TIMING)) {						\
cb334648a   Joe Perches   arcnet: Use norma...
101
102
103
104
  		unsigned long _x, _y;					\
  		_x = get_cycles();					\
  		call;							\
  		_y = get_cycles();					\
a34c0932c   Joe Perches   arcnet: Convert B...
105
106
107
108
109
  		arc_printk(D_TIMING, dev,				\
  			   "%s: %d bytes in %lu cycles == %lu Kbytes/100Mcycle
  ", \
  			   name, bytes, _y - _x,			\
  			   100000000 / 1024 * bytes / (_y - _x + 1));	\
72aeea484   Joe Perches   arcnet: Expand od...
110
  	} else {							\
cb334648a   Joe Perches   arcnet: Use norma...
111
  		call;							\
72aeea484   Joe Perches   arcnet: Expand od...
112
113
  	}								\
  } while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  /*
   * Time needed to reset the card - in ms (milliseconds).  This works on my
   * SMC PC100.  I can't find a reference that tells me just how long I
   * should wait.
   */
  #define RESETtime (300)
  
  /*
   * These are the max/min lengths of packet payload, not including the
   * arc_hardware header, but definitely including the soft header.
   *
   * Note: packet sizes 254, 255, 256 are impossible because of the way
   * ARCnet registers work  That's why RFC1201 defines "exception" packets.
   * In non-RFC1201 protocols, we have to just tack some extra bytes on the
   * end.
   */
  #define MTU	253		/* normal packet max size */
  #define MinTU	257		/* extended packet min size */
  #define XMTU	508		/* extended packet max size */
  
  /* status/interrupt mask bit fields */
  #define TXFREEflag	0x01	/* transmitter available */
  #define TXACKflag       0x02	/* transmitted msg. ackd */
  #define RECONflag       0x04	/* network reconfigured */
  #define TESTflag        0x08	/* test flag */
  #define EXCNAKflag      0x08    /* excesive nak flag */
  #define RESETflag       0x10	/* power-on-reset */
  #define RES1flag        0x20	/* reserved - usually set by jumper */
  #define RES2flag        0x40	/* reserved - usually set by jumper */
  #define NORXflag        0x80	/* receiver inhibited */
  
  /* Flags used for IO-mapped memory operations */
  #define AUTOINCflag     0x40	/* Increase location with each access */
  #define IOMAPflag       0x02	/* (for 90xx) Use IO mapped memory, not mmap */
  #define ENABLE16flag    0x80	/* (for 90xx) Enable 16-bit mode */
  
  /* in the command register, the following bits have these meanings:
   *                0-2     command
   *                3-4     page number (for enable rcv/xmt command)
   *                 7      receive broadcasts
   */
  #define NOTXcmd         0x01	/* disable transmitter */
  #define NORXcmd         0x02	/* disable receiver */
  #define TXcmd           0x03	/* enable transmitter */
  #define RXcmd           0x04	/* enable receiver */
  #define CONFIGcmd       0x05	/* define configuration */
  #define CFLAGScmd       0x06	/* clear flags */
  #define TESTcmd         0x07	/* load test flags */
84286f191   Michael Grzeschik   arcnet: com20020:...
163
  #define STARTIOcmd      0x18	/* start internal operation */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  
  /* flags for "clear flags" command */
  #define RESETclear      0x08	/* power-on-reset */
  #define CONFIGclear     0x10	/* system reconfigured */
  
  #define EXCNAKclear     0x0E    /* Clear and acknowledge the excive nak bit */
  
  /* flags for "load test flags" command */
  #define TESTload        0x08	/* test flag (diagnostic) */
  
  /* byte deposited into first address of buffers on reset */
  #define TESTvalue       0321	/* that's octal for 0xD1 :) */
  
  /* for "enable receiver" command */
  #define RXbcasts        0x80	/* receive broadcasts */
  
  /* flags for "define configuration" command */
  #define NORMALconf      0x00	/* 1-249 byte packets */
  #define EXTconf         0x08	/* 250-504 byte packets */
  
  /* card feature flags, set during auto-detection.
   * (currently only used by com20020pci)
   */
  #define ARC_IS_5MBIT    1   /* card default speed is 5MBit */
  #define ARC_CAN_10MBIT  2   /* card uses COM20022, supporting 10MBit,
  				 but default is 2.5MBit. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
191
192
193
194
  /* information needed to define an encapsulation driver */
  struct ArcProto {
  	char suffix;		/* a for RFC1201, e for ether-encap, etc. */
  	int mtu;		/* largest possible packet */
  	int is_ip;              /* This is a ip plugin - not a raw thing */
cb334648a   Joe Perches   arcnet: Use norma...
195
196
197
198
  	void (*rx)(struct net_device *dev, int bufnum,
  		   struct archdr *pkthdr, int length);
  	int (*build_header)(struct sk_buff *skb, struct net_device *dev,
  			    unsigned short ethproto, uint8_t daddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
200
  
  	/* these functions return '1' if the skb can now be freed */
d6d7d3ed5   Joe Perches   arcnet: Wrap some...
201
202
  	int (*prepare_tx)(struct net_device *dev, struct archdr *pkt,
  			  int length, int bufnum);
cb334648a   Joe Perches   arcnet: Use norma...
203
204
  	int (*continue_tx)(struct net_device *dev, int bufnum);
  	int (*ack_tx)(struct net_device *dev, int acked);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
206
207
208
  };
  
  extern struct ArcProto *arc_proto_map[256], *arc_proto_default,
  	*arc_bcast_proto, *arc_raw_proto;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
210
211
212
213
214
215
  /*
   * "Incoming" is information needed for each address that could be sending
   * to us.  Mostly for partially-received split packets.
   */
  struct Incoming {
  	struct sk_buff *skb;	/* packet data buffer             */
701181ac1   Al Viro   arcnet endianness...
216
  	__be16 sequence;	/* sequence number of assembly    */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
218
219
  	uint8_t lastpacket,	/* number of last packet (from 1) */
  		numpackets;	/* number of packets in split     */
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
220
221
222
223
224
225
226
227
228
229
230
231
  /* only needed for RFC1201 */
  struct Outgoing {
  	struct ArcProto *proto;	/* protocol driver that owns this:
  				 *   if NULL, no packet is pending.
  				 */
  	struct sk_buff *skb;	/* buffer from upper levels */
  	struct archdr *pkt;	/* a pointer into the skb */
  	uint16_t length,	/* bytes total */
  		dataleft,	/* bytes left */
  		segnum,		/* segment being sent */
  		numsegs;	/* number of segments */
  };
8890624a4   Michael Grzeschik   arcnet: com20020-...
232
  #define ARCNET_LED_NAME_SZ (IFNAMSIZ + 6)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
  struct arcnet_local {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
  	uint8_t config,		/* current value of CONFIG register */
  		timeout,	/* Extended timeout for COM20020 */
  		backplane,	/* Backplane flag for COM20020 */
  		clockp,		/* COM20020 clock divider */
  		clockm,		/* COM20020 clock multiplier flag */
  		setup,		/* Contents of setup1 register */
  		setup2,		/* Contents of setup2 register */
  		intmask;	/* current value of INTMASK register */
  	uint8_t default_proto[256];	/* default encap to use for each host */
  	int	cur_tx,		/* buffer used by current transmit, or -1 */
  		next_tx,	/* buffer where a packet is ready to send */
  		cur_rx;		/* current receive buffer */
  	int	lastload_dest,	/* can last loaded packet be acked? */
  		lasttrans_dest;	/* can last TX'd packet be acked? */
  	int	timed_out;	/* need to process TX timeout and drop packet */
  	unsigned long last_timeout;	/* time of last reported timeout */
  	char *card_name;	/* card ident string */
  	int card_flags;		/* special card features */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
252
253
  	/* On preemtive and SMB a lock is needed */
  	spinlock_t lock;
8890624a4   Michael Grzeschik   arcnet: com20020-...
254
255
256
257
  	struct led_trigger *tx_led_trig;
  	char tx_led_trig_name[ARCNET_LED_NAME_SZ];
  	struct led_trigger *recon_led_trig;
  	char recon_led_trig_name[ARCNET_LED_NAME_SZ];
59fbcbc61   Michael Grzeschik   arcnet: add netif...
258
  	struct timer_list	timer;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
259
260
261
262
263
264
265
266
  	/*
  	 * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of
  	 * which can be used for either sending or receiving.  The new dynamic
  	 * buffer management routines use a simple circular queue of available
  	 * buffers, and take them as they're needed.  This way, we simplify
  	 * situations in which we (for example) want to pre-load a transmit
  	 * buffer, or start receiving while we copy a received packet to
  	 * memory.
cb334648a   Joe Perches   arcnet: Use norma...
267
  	 *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268
269
270
271
272
  	 * The rules: only the interrupt handler is allowed to _add_ buffers to
  	 * the queue; thus, this doesn't require a lock.  Both the interrupt
  	 * handler and the transmit function will want to _remove_ buffers, so
  	 * we need to handle the situation where they try to do it at the same
  	 * time.
cb334648a   Joe Perches   arcnet: Use norma...
273
  	 *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
274
275
276
277
278
279
280
281
  	 * If next_buf == first_free_buf, the queue is empty.  Since there are
  	 * only four possible buffers, the queue should never be full.
  	 */
  	atomic_t buf_lock;
  	int buf_queue[5];
  	int next_buf, first_free_buf;
  
  	/* network "reconfiguration" handling */
9307b570a   S.Çağlar Onur   drivers/net/arcne...
282
283
  	unsigned long first_recon; /* time of "first" RECON message to count */
  	unsigned long last_recon;  /* time of most recent RECON */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
  	int num_recons;		/* number of RECONs between first and last. */
db55b62ca   Rasmus Villemoes   net: arcnet: Remo...
285
  	int network_down;	/* do we think the network is down? */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286

db55b62ca   Rasmus Villemoes   net: arcnet: Remo...
287
  	int excnak_pending;    /* We just got an excesive nak interrupt */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
289
290
  
  	struct {
  		uint16_t sequence;	/* sequence number (incs with each packet) */
701181ac1   Al Viro   arcnet endianness...
291
  		__be16 aborted_seq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
293
294
295
296
297
298
299
300
301
  
  		struct Incoming incoming[256];	/* one from each address */
  	} rfc1201;
  
  	/* really only used by rfc1201, but we'll pretend it's not */
  	struct Outgoing outgoing;	/* packet currently being sent */
  
  	/* hardware-specific functions */
  	struct {
  		struct module *owner;
cb334648a   Joe Perches   arcnet: Use norma...
302
303
304
305
306
307
  		void (*command)(struct net_device *dev, int cmd);
  		int (*status)(struct net_device *dev);
  		void (*intmask)(struct net_device *dev, int mask);
  		int (*reset)(struct net_device *dev, int really_reset);
  		void (*open)(struct net_device *dev);
  		void (*close)(struct net_device *dev);
8890624a4   Michael Grzeschik   arcnet: com20020-...
308
309
  		void (*datatrigger) (struct net_device * dev, int enable);
  		void (*recontrigger) (struct net_device * dev, int enable);
cb334648a   Joe Perches   arcnet: Use norma...
310

d6d7d3ed5   Joe Perches   arcnet: Wrap some...
311
312
313
314
  		void (*copy_to_card)(struct net_device *dev, int bufnum,
  				     int offset, void *buf, int count);
  		void (*copy_from_card)(struct net_device *dev, int bufnum,
  				       int offset, void *buf, int count);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
315
316
317
318
  	} hw;
  
  	void __iomem *mem_start;	/* pointer to ioremap'ed MMIO */
  };
8890624a4   Michael Grzeschik   arcnet: com20020-...
319
320
321
322
323
324
325
326
327
  enum arcnet_led_event {
  	ARCNET_LED_EVENT_RECON,
  	ARCNET_LED_EVENT_OPEN,
  	ARCNET_LED_EVENT_STOP,
  	ARCNET_LED_EVENT_TX,
  };
  
  void arcnet_led_event(struct net_device *netdev, enum arcnet_led_event event);
  void devm_arcnet_led_init(struct net_device *netdev, int index, int subid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
329
330
  #if ARCNET_DEBUG_MAX & D_SKB
  void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc);
  #else
83df99b50   Joe Perches   arcnet: Convert a...
331
332
333
334
  static inline
  void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc)
  {
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336
  void arcnet_unregister_proto(struct ArcProto *proto);
7d12e780e   David Howells   IRQ: Maintain reg...
337
  irqreturn_t arcnet_interrupt(int irq, void *dev_id);
bca5b8939   Stephen Hemminger   arcnet: convert t...
338
339
340
341
  struct net_device *alloc_arcdev(const char *name);
  
  int arcnet_open(struct net_device *dev);
  int arcnet_close(struct net_device *dev);
61357325f   Stephen Hemminger   netdev: convert b...
342
  netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
cb334648a   Joe Perches   arcnet: Use norma...
343
  			       struct net_device *dev);
bca5b8939   Stephen Hemminger   arcnet: convert t...
344
  void arcnet_timeout(struct net_device *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345

e5fcfc1f8   Joe Perches   arcnet: Add arcne...
346
  /* I/O equivalents */
0fec65130   Joe Perches   arcnet: com20020:...
347
348
349
350
351
  #ifdef CONFIG_SA1100_CT6001
  #define BUS_ALIGN  2  /* 8 bit device on a 16 bit bus - needs padding */
  #else
  #define BUS_ALIGN  1
  #endif
e5fcfc1f8   Joe Perches   arcnet: Add arcne...
352
353
354
355
  /* addr and offset allow register like names to define the actual IO  address.
   * A configuration option multiplies the offset for alignment.
   */
  #define arcnet_inb(addr, offset)					\
0fec65130   Joe Perches   arcnet: com20020:...
356
  	inb((addr) + BUS_ALIGN * (offset))
e5fcfc1f8   Joe Perches   arcnet: Add arcne...
357
  #define arcnet_outb(value, addr, offset)				\
0fec65130   Joe Perches   arcnet: com20020:...
358
  	outb(value, (addr) + BUS_ALIGN * (offset))
e5fcfc1f8   Joe Perches   arcnet: Add arcne...
359
360
  
  #define arcnet_insb(addr, offset, buffer, count)			\
0fec65130   Joe Perches   arcnet: com20020:...
361
  	insb((addr) + BUS_ALIGN * (offset), buffer, count)
e5fcfc1f8   Joe Perches   arcnet: Add arcne...
362
  #define arcnet_outsb(addr, offset, buffer, count)			\
0fec65130   Joe Perches   arcnet: com20020:...
363
  	outsb((addr) + BUS_ALIGN * (offset), buffer, count)
e5fcfc1f8   Joe Perches   arcnet: Add arcne...
364

9c76aa551   Joe Perches   arcnet: arcdevice...
365
366
367
368
  #define arcnet_readb(addr, offset)					\
  	readb((addr) + (offset))
  #define arcnet_writeb(value, addr, offset)				\
  	writeb(value, (addr) + (offset))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
370
  #endif				/* __KERNEL__ */
  #endif				/* _LINUX_ARCDEVICE_H */