1 |
199 |
simons |
/* atarilance.c: Ethernet driver for VME Lance cards on the Atari */
|
2 |
|
|
/*
|
3 |
|
|
Written 1995/96 by Roman Hodek (Roman.Hodek@informatik.uni-erlangen.de)
|
4 |
|
|
|
5 |
|
|
This software may be used and distributed according to the terms
|
6 |
|
|
of the GNU Public License, incorporated herein by reference.
|
7 |
|
|
|
8 |
|
|
This drivers was written with the following sources of reference:
|
9 |
|
|
- The driver for the Riebl Lance card by the TU Vienna.
|
10 |
|
|
- The modified TUW driver for PAM's VME cards
|
11 |
|
|
- The PC-Linux driver for Lance cards (but this is for bus master
|
12 |
|
|
cards, not the shared memory ones)
|
13 |
|
|
- The Amiga Ariadne driver
|
14 |
|
|
|
15 |
|
|
v1.0: (in 1.2.13pl4/0.9.13)
|
16 |
|
|
Initial version
|
17 |
|
|
v1.1: (in 1.2.13pl5)
|
18 |
|
|
more comments
|
19 |
|
|
deleted some debugging stuff
|
20 |
|
|
optimized register access (keep AREG pointing to CSR0)
|
21 |
|
|
following AMD, CSR0_STRT should be set only after IDON is detected
|
22 |
|
|
use memcpy() for data transfers, that also employs long word moves
|
23 |
|
|
better probe procedure for 24-bit systems
|
24 |
|
|
non-VME-RieblCards need extra delays in memcpy
|
25 |
|
|
must also do write test, since 0xfxe00000 may hit ROM
|
26 |
|
|
use 8/32 tx/rx buffers, which should give better NFS performance;
|
27 |
|
|
this is made possible by shifting the last packet buffer after the
|
28 |
|
|
RieblCard reserved area
|
29 |
|
|
v1.2: (in 1.2.13pl8)
|
30 |
|
|
again fixed probing for the Falcon; 0xfe01000 hits phys. 0x00010000
|
31 |
|
|
and thus RAM, in case of no Lance found all memory contents have to
|
32 |
|
|
be restored!
|
33 |
|
|
Now possible to compile as module.
|
34 |
|
|
v1.3: 03/30/96 Jes Sorensen, Roman (in 1.3)
|
35 |
|
|
Several little 1.3 adaptions
|
36 |
|
|
When the lance is stopped it jumps back into little-endian
|
37 |
|
|
mode. It is therefore necessary to put it back where it
|
38 |
|
|
belongs, in big endian mode, in order to make things work.
|
39 |
|
|
This might be the reason why multicast-mode didn't work
|
40 |
|
|
before, but I'm not able to test it as I only got an Amiga
|
41 |
|
|
(we had similar problems with the A2065 driver).
|
42 |
|
|
|
43 |
|
|
*/
|
44 |
|
|
|
45 |
|
|
static char *version = "atarilance.c: v1.3 04/04/96 "
|
46 |
|
|
"Roman.Hodek@informatik.uni-erlangen.de\n";
|
47 |
|
|
|
48 |
|
|
#include <linux/module.h>
|
49 |
|
|
|
50 |
|
|
#include <linux/stddef.h>
|
51 |
|
|
#include <linux/kernel.h>
|
52 |
|
|
#include <linux/sched.h>
|
53 |
|
|
#include <linux/string.h>
|
54 |
|
|
#include <linux/ptrace.h>
|
55 |
|
|
#include <linux/errno.h>
|
56 |
|
|
#include <linux/malloc.h>
|
57 |
|
|
#include <linux/interrupt.h>
|
58 |
|
|
|
59 |
|
|
#include <asm/irq.h>
|
60 |
|
|
#include <asm/atarihw.h>
|
61 |
|
|
#include <asm/atariints.h>
|
62 |
|
|
#include <asm/bitops.h>
|
63 |
|
|
#include <asm/io.h>
|
64 |
|
|
#include <asm/bootinfo.h>
|
65 |
|
|
|
66 |
|
|
#include <linux/netdevice.h>
|
67 |
|
|
#include <linux/etherdevice.h>
|
68 |
|
|
#include <linux/skbuff.h>
|
69 |
|
|
|
70 |
|
|
/* Debug level:
|
71 |
|
|
* 0 = silent, print only serious errors
|
72 |
|
|
* 1 = normal, print error messages
|
73 |
|
|
* 2 = debug, print debug infos
|
74 |
|
|
* 3 = debug, print even more debug infos (packet data)
|
75 |
|
|
*/
|
76 |
|
|
|
77 |
|
|
#define LANCE_DEBUG 1
|
78 |
|
|
|
79 |
|
|
#ifdef LANCE_DEBUG
|
80 |
|
|
static int lance_debug = LANCE_DEBUG;
|
81 |
|
|
#else
|
82 |
|
|
static int lance_debug = 1;
|
83 |
|
|
#endif
|
84 |
|
|
|
85 |
|
|
/* Print debug messages on probing? */
|
86 |
|
|
#undef LANCE_DEBUG_PROBE
|
87 |
|
|
|
88 |
|
|
#define DPRINTK(n,a) \
|
89 |
|
|
do { \
|
90 |
|
|
if (lance_debug >= n) \
|
91 |
|
|
printk a; \
|
92 |
|
|
} while( 0 )
|
93 |
|
|
|
94 |
|
|
#ifdef LANCE_DEBUG_PROBE
|
95 |
|
|
# define PROBE_PRINT(a) printk a
|
96 |
|
|
#else
|
97 |
|
|
# define PROBE_PRINT(a)
|
98 |
|
|
#endif
|
99 |
|
|
|
100 |
|
|
/* These define the number of Rx and Tx buffers as log2. (Only powers
|
101 |
|
|
* of two are valid)
|
102 |
|
|
* Much more rx buffers (32) are reserved than tx buffers (8), since receiving
|
103 |
|
|
* is more time critical then sending and packets may have to remain in the
|
104 |
|
|
* board's memory when main memory is low.
|
105 |
|
|
*/
|
106 |
|
|
|
107 |
|
|
#define TX_LOG_RING_SIZE 3
|
108 |
|
|
#define RX_LOG_RING_SIZE 5
|
109 |
|
|
|
110 |
|
|
/* These are the derived values */
|
111 |
|
|
|
112 |
|
|
#define TX_RING_SIZE (1 << TX_LOG_RING_SIZE)
|
113 |
|
|
#define TX_RING_LEN_BITS (TX_LOG_RING_SIZE << 5)
|
114 |
|
|
#define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
|
115 |
|
|
|
116 |
|
|
#define RX_RING_SIZE (1 << RX_LOG_RING_SIZE)
|
117 |
|
|
#define RX_RING_LEN_BITS (RX_LOG_RING_SIZE << 5)
|
118 |
|
|
#define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
|
119 |
|
|
|
120 |
|
|
/* The LANCE Rx and Tx ring descriptors. */
|
121 |
|
|
struct lance_rx_head {
|
122 |
|
|
unsigned short base; /* Low word of base addr */
|
123 |
|
|
volatile unsigned char flag;
|
124 |
|
|
unsigned char base_hi; /* High word of base addr (unused) */
|
125 |
|
|
short buf_length; /* This length is 2s complement! */
|
126 |
|
|
volatile short msg_length; /* This length is "normal". */
|
127 |
|
|
};
|
128 |
|
|
|
129 |
|
|
struct lance_tx_head {
|
130 |
|
|
unsigned short base; /* Low word of base addr */
|
131 |
|
|
volatile unsigned char flag;
|
132 |
|
|
unsigned char base_hi; /* High word of base addr (unused) */
|
133 |
|
|
short length; /* Length is 2s complement! */
|
134 |
|
|
volatile short misc;
|
135 |
|
|
};
|
136 |
|
|
|
137 |
|
|
struct ringdesc {
|
138 |
|
|
unsigned short adr_lo; /* Low 16 bits of address */
|
139 |
|
|
unsigned char len; /* Length bits */
|
140 |
|
|
unsigned char adr_hi; /* High 8 bits of address (unused) */
|
141 |
|
|
};
|
142 |
|
|
|
143 |
|
|
/* The LANCE initialization block, described in databook. */
|
144 |
|
|
struct lance_init_block {
|
145 |
|
|
unsigned short mode; /* Pre-set mode */
|
146 |
|
|
unsigned char hwaddr[6]; /* Physical ethernet address */
|
147 |
|
|
unsigned filter[2]; /* Multicast filter (unused). */
|
148 |
|
|
/* Receive and transmit ring base, along with length bits. */
|
149 |
|
|
struct ringdesc rx_ring;
|
150 |
|
|
struct ringdesc tx_ring;
|
151 |
|
|
};
|
152 |
|
|
|
153 |
|
|
/* The whole layout of the Lance shared memory */
|
154 |
|
|
struct lance_memory {
|
155 |
|
|
struct lance_init_block init;
|
156 |
|
|
struct lance_tx_head tx_head[TX_RING_SIZE];
|
157 |
|
|
struct lance_rx_head rx_head[RX_RING_SIZE];
|
158 |
|
|
char packet_area[0]; /* packet data follow after the
|
159 |
|
|
* init block and the ring
|
160 |
|
|
* descriptors and are located
|
161 |
|
|
* at runtime */
|
162 |
|
|
};
|
163 |
|
|
|
164 |
|
|
/* RieblCard specifics:
|
165 |
|
|
* The original TOS driver for these cards reserves the area from offset
|
166 |
|
|
* 0xee70 to 0xeebb for storing configuration data. Of interest to us is the
|
167 |
|
|
* Ethernet address there, and the magic for verifying the data's validity.
|
168 |
|
|
* The reserved area isn't touch by packet buffers. Furthermore, offset 0xfffe
|
169 |
|
|
* is reserved for the interrupt vector number.
|
170 |
|
|
*/
|
171 |
|
|
#define RIEBL_RSVD_START 0xee70
|
172 |
|
|
#define RIEBL_RSVD_END 0xeec0
|
173 |
|
|
#define RIEBL_MAGIC 0x09051990
|
174 |
|
|
#define RIEBL_MAGIC_ADDR ((unsigned long *)(((char *)MEM) + 0xee8a))
|
175 |
|
|
#define RIEBL_HWADDR_ADDR ((unsigned char *)(((char *)MEM) + 0xee8e))
|
176 |
|
|
#define RIEBL_IVEC_ADDR ((unsigned short *)(((char *)MEM) + 0xfffe))
|
177 |
|
|
|
178 |
|
|
/* This is a default address for the old RieblCards without a battery
|
179 |
|
|
* that have no ethernet address at boot time. 00:00:36:04 is the
|
180 |
|
|
* prefix for Riebl cards, the 00:00 at the end is arbitrary.
|
181 |
|
|
*/
|
182 |
|
|
|
183 |
|
|
static unsigned char OldRieblDefHwaddr[6] = {
|
184 |
|
|
0x00, 0x00, 0x36, 0x04, 0x00, 0x00
|
185 |
|
|
};
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
/* I/O registers of the Lance chip */
|
189 |
|
|
|
190 |
|
|
struct lance_ioreg {
|
191 |
|
|
/* base+0x0 */ volatile unsigned short data;
|
192 |
|
|
/* base+0x2 */ volatile unsigned short addr;
|
193 |
|
|
unsigned char _dummy1[3];
|
194 |
|
|
/* base+0x7 */ volatile unsigned char ivec;
|
195 |
|
|
unsigned char _dummy2[5];
|
196 |
|
|
/* base+0xd */ volatile unsigned char eeprom;
|
197 |
|
|
unsigned char _dummy3;
|
198 |
|
|
/* base+0xf */ volatile unsigned char mem;
|
199 |
|
|
};
|
200 |
|
|
|
201 |
|
|
/* Types of boards this driver supports */
|
202 |
|
|
|
203 |
|
|
enum lance_type {
|
204 |
|
|
OLD_RIEBL, /* old Riebl card without battery */
|
205 |
|
|
NEW_RIEBL, /* new Riebl card with battery */
|
206 |
|
|
PAM_CARD /* PAM card with EEPROM */
|
207 |
|
|
};
|
208 |
|
|
|
209 |
|
|
static char *lance_names[] = {
|
210 |
|
|
"Riebl-Card (without battery)",
|
211 |
|
|
"Riebl-Card (with battery)",
|
212 |
|
|
"PAM intern card"
|
213 |
|
|
};
|
214 |
|
|
|
215 |
|
|
/* The driver's private device structure */
|
216 |
|
|
|
217 |
|
|
struct lance_private {
|
218 |
|
|
enum lance_type cardtype;
|
219 |
|
|
struct lance_ioreg *iobase;
|
220 |
|
|
struct lance_memory *mem;
|
221 |
|
|
int cur_rx, cur_tx; /* The next free ring entry */
|
222 |
|
|
int dirty_tx; /* Ring entries to be freed. */
|
223 |
|
|
/* copy function */
|
224 |
|
|
void *(*memcpy_f)( void *, const void *, size_t );
|
225 |
|
|
struct enet_statistics stats;
|
226 |
|
|
/* These two must be ints for set_bit() */
|
227 |
|
|
int tx_full;
|
228 |
|
|
int lock;
|
229 |
|
|
};
|
230 |
|
|
|
231 |
|
|
/* I/O register access macros */
|
232 |
|
|
|
233 |
|
|
#define MEM lp->mem
|
234 |
|
|
#define DREG IO->data
|
235 |
|
|
#define AREG IO->addr
|
236 |
|
|
#define REGA(a) ( AREG = (a), DREG )
|
237 |
|
|
|
238 |
|
|
/* Definitions for packet buffer access: */
|
239 |
|
|
#define PKT_BUF_SZ 1544
|
240 |
|
|
/* Get the address of a packet buffer corresponding to a given buffer head */
|
241 |
|
|
#define PKTBUF_ADDR(head) (((unsigned char *)(MEM)) + (head)->base)
|
242 |
|
|
|
243 |
|
|
/* Possible memory/IO addresses for probing */
|
244 |
|
|
|
245 |
|
|
struct lance_addr {
|
246 |
|
|
unsigned long memaddr;
|
247 |
|
|
unsigned long ioaddr;
|
248 |
|
|
int slow_flag;
|
249 |
|
|
} lance_addr_list[] = {
|
250 |
|
|
{ 0xfe010000, 0xfe00fff0, 0 }, /* RieblCard VME in TT */
|
251 |
|
|
{ 0xffc10000, 0xffc0fff0, 0 }, /* RieblCard VME in MegaSTE
|
252 |
|
|
(highest byte stripped) */
|
253 |
|
|
{ 0xffe00000, 0xffff7000, 1 }, /* RieblCard in ST
|
254 |
|
|
(highest byte stripped) */
|
255 |
|
|
{ 0xffd00000, 0xffff7000, 1 }, /* RieblCard in ST with hw modif. to
|
256 |
|
|
avoid conflict with ROM
|
257 |
|
|
(highest byte stripped) */
|
258 |
|
|
{ 0xffcf0000, 0xffcffff0, 0 }, /* PAMCard VME in TT and MSTE
|
259 |
|
|
(highest byte stripped) */
|
260 |
|
|
};
|
261 |
|
|
|
262 |
|
|
#define N_LANCE_ADDR (sizeof(lance_addr_list)/sizeof(*lance_addr_list))
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
/* Definitions for the Lance */
|
266 |
|
|
|
267 |
|
|
/* tx_head flags */
|
268 |
|
|
#define TMD1_ENP 0x01 /* end of packet */
|
269 |
|
|
#define TMD1_STP 0x02 /* start of packet */
|
270 |
|
|
#define TMD1_DEF 0x04 /* deferred */
|
271 |
|
|
#define TMD1_ONE 0x08 /* one retry needed */
|
272 |
|
|
#define TMD1_MORE 0x10 /* more than one retry needed */
|
273 |
|
|
#define TMD1_ERR 0x40 /* error summary */
|
274 |
|
|
#define TMD1_OWN 0x80 /* ownership (set: chip owns) */
|
275 |
|
|
|
276 |
|
|
#define TMD1_OWN_CHIP TMD1_OWN
|
277 |
|
|
#define TMD1_OWN_HOST 0
|
278 |
|
|
|
279 |
|
|
/* tx_head misc field */
|
280 |
|
|
#define TMD3_TDR 0x03FF /* Time Domain Reflectometry counter */
|
281 |
|
|
#define TMD3_RTRY 0x0400 /* failed after 16 retries */
|
282 |
|
|
#define TMD3_LCAR 0x0800 /* carrier lost */
|
283 |
|
|
#define TMD3_LCOL 0x1000 /* late collision */
|
284 |
|
|
#define TMD3_UFLO 0x4000 /* underflow (late memory) */
|
285 |
|
|
#define TMD3_BUFF 0x8000 /* buffering error (no ENP) */
|
286 |
|
|
|
287 |
|
|
/* rx_head flags */
|
288 |
|
|
#define RMD1_ENP 0x01 /* end of packet */
|
289 |
|
|
#define RMD1_STP 0x02 /* start of packet */
|
290 |
|
|
#define RMD1_BUFF 0x04 /* buffer error */
|
291 |
|
|
#define RMD1_CRC 0x08 /* CRC error */
|
292 |
|
|
#define RMD1_OFLO 0x10 /* overflow */
|
293 |
|
|
#define RMD1_FRAM 0x20 /* framing error */
|
294 |
|
|
#define RMD1_ERR 0x40 /* error summary */
|
295 |
|
|
#define RMD1_OWN 0x80 /* ownership (set: ship owns) */
|
296 |
|
|
|
297 |
|
|
#define RMD1_OWN_CHIP RMD1_OWN
|
298 |
|
|
#define RMD1_OWN_HOST 0
|
299 |
|
|
|
300 |
|
|
/* register names */
|
301 |
|
|
#define CSR0 0 /* mode/status */
|
302 |
|
|
#define CSR1 1 /* init block addr (low) */
|
303 |
|
|
#define CSR2 2 /* init block addr (high) */
|
304 |
|
|
#define CSR3 3 /* misc */
|
305 |
|
|
#define CSR8 8 /* address filter */
|
306 |
|
|
#define CSR15 15 /* promiscuous mode */
|
307 |
|
|
|
308 |
|
|
/* CSR0 */
|
309 |
|
|
/* (R=readable, W=writeable, S=set on write, C=clear on write) */
|
310 |
|
|
#define CSR0_INIT 0x0001 /* initialize (RS) */
|
311 |
|
|
#define CSR0_STRT 0x0002 /* start (RS) */
|
312 |
|
|
#define CSR0_STOP 0x0004 /* stop (RS) */
|
313 |
|
|
#define CSR0_TDMD 0x0008 /* transmit demand (RS) */
|
314 |
|
|
#define CSR0_TXON 0x0010 /* transmitter on (R) */
|
315 |
|
|
#define CSR0_RXON 0x0020 /* receiver on (R) */
|
316 |
|
|
#define CSR0_INEA 0x0040 /* interrupt enable (RW) */
|
317 |
|
|
#define CSR0_INTR 0x0080 /* interrupt active (R) */
|
318 |
|
|
#define CSR0_IDON 0x0100 /* initialization done (RC) */
|
319 |
|
|
#define CSR0_TINT 0x0200 /* transmitter interrupt (RC) */
|
320 |
|
|
#define CSR0_RINT 0x0400 /* receiver interrupt (RC) */
|
321 |
|
|
#define CSR0_MERR 0x0800 /* memory error (RC) */
|
322 |
|
|
#define CSR0_MISS 0x1000 /* missed frame (RC) */
|
323 |
|
|
#define CSR0_CERR 0x2000 /* carrier error (no heartbeat :-) (RC) */
|
324 |
|
|
#define CSR0_BABL 0x4000 /* babble: tx-ed too many bits (RC) */
|
325 |
|
|
#define CSR0_ERR 0x8000 /* error (RC) */
|
326 |
|
|
|
327 |
|
|
/* CSR3 */
|
328 |
|
|
#define CSR3_BCON 0x0001 /* byte control */
|
329 |
|
|
#define CSR3_ACON 0x0002 /* ALE control */
|
330 |
|
|
#define CSR3_BSWP 0x0004 /* byte swap (1=big endian) */
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
/***************************** Prototypes *****************************/
|
335 |
|
|
|
336 |
|
|
static int addr_accessible( volatile void *regp, int wordflag, int
|
337 |
|
|
writeflag );
|
338 |
|
|
static unsigned long lance_probe1( struct device *dev, struct lance_addr
|
339 |
|
|
*init_rec );
|
340 |
|
|
static int lance_open( struct device *dev );
|
341 |
|
|
static void lance_init_ring( struct device *dev );
|
342 |
|
|
static int lance_start_xmit( struct sk_buff *skb, struct device *dev );
|
343 |
|
|
static void lance_interrupt( int irq, struct pt_regs *fp, struct device
|
344 |
|
|
*dev );
|
345 |
|
|
static int lance_rx( struct device *dev );
|
346 |
|
|
static int lance_close( struct device *dev );
|
347 |
|
|
static struct enet_statistics *lance_get_stats( struct device *dev );
|
348 |
|
|
static void set_multicast_list( struct device *dev );
|
349 |
|
|
static int lance_set_mac_address( struct device *dev, void *addr );
|
350 |
|
|
|
351 |
|
|
/************************* End of Prototypes **************************/
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
void *slow_memcpy( void *dst, const void *src, size_t len )
|
358 |
|
|
|
359 |
|
|
{ char *cto = dst;
|
360 |
|
|
const char *cfrom = src;
|
361 |
|
|
|
362 |
|
|
while( len-- ) {
|
363 |
|
|
*cto++ = *cfrom++;
|
364 |
|
|
MFPDELAY();
|
365 |
|
|
}
|
366 |
|
|
return( dst );
|
367 |
|
|
}
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
int atarilance_probe( struct device *dev )
|
371 |
|
|
|
372 |
|
|
{ int i;
|
373 |
|
|
static int found = 0;
|
374 |
|
|
|
375 |
|
|
if (!MACH_IS_ATARI || found)
|
376 |
|
|
/* Assume there's only one board possible... That seems true, since
|
377 |
|
|
* the Riebl/PAM board's address cannot be changed. */
|
378 |
|
|
return( ENODEV );
|
379 |
|
|
|
380 |
|
|
for( i = 0; i < N_LANCE_ADDR; ++i ) {
|
381 |
|
|
if (lance_probe1( dev, &lance_addr_list[i] )) {
|
382 |
|
|
found = 1;
|
383 |
|
|
return( 0 );
|
384 |
|
|
}
|
385 |
|
|
}
|
386 |
|
|
|
387 |
|
|
return( ENODEV );
|
388 |
|
|
}
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
/* Derived from hwreg_present() in atari/config.c: */
|
392 |
|
|
|
393 |
|
|
static int addr_accessible( volatile void *regp, int wordflag, int writeflag )
|
394 |
|
|
|
395 |
|
|
{ int ret;
|
396 |
|
|
long flags;
|
397 |
|
|
long *vbr, save_berr;
|
398 |
|
|
|
399 |
|
|
save_flags(flags);
|
400 |
|
|
cli();
|
401 |
|
|
|
402 |
|
|
__asm__ __volatile__ ( "movec %/vbr,%0" : "=r" (vbr) : );
|
403 |
|
|
save_berr = vbr[2];
|
404 |
|
|
|
405 |
|
|
__asm__ __volatile__
|
406 |
|
|
( "movel %/sp,%/d1\n\t"
|
407 |
|
|
"movel #Lberr,%2@\n\t"
|
408 |
|
|
"moveq #0,%0\n\t"
|
409 |
|
|
"tstl %3\n\t"
|
410 |
|
|
"bne 1f\n\t"
|
411 |
|
|
"moveb %1@,%/d0\n\t"
|
412 |
|
|
"nop \n\t"
|
413 |
|
|
"bra 2f\n"
|
414 |
|
|
"1: movew %1@,%/d0\n\t"
|
415 |
|
|
"nop \n"
|
416 |
|
|
"2: tstl %4\n\t"
|
417 |
|
|
"beq 2f\n\t"
|
418 |
|
|
"tstl %3\n\t"
|
419 |
|
|
"bne 1f\n\t"
|
420 |
|
|
"clrb %1@\n\t"
|
421 |
|
|
"nop \n\t"
|
422 |
|
|
"moveb %/d0,%1@\n\t"
|
423 |
|
|
"nop \n\t"
|
424 |
|
|
"bra 2f\n"
|
425 |
|
|
"1: clrw %1@\n\t"
|
426 |
|
|
"nop \n\t"
|
427 |
|
|
"movew %/d0,%1@\n\t"
|
428 |
|
|
"nop \n"
|
429 |
|
|
"2: moveq #1,%0\n"
|
430 |
|
|
"Lberr: movel %/d1,%/sp"
|
431 |
|
|
: "=&d" (ret)
|
432 |
|
|
: "a" (regp), "a" (&vbr[2]), "rm" (wordflag), "rm" (writeflag)
|
433 |
|
|
: "d0", "d1", "memory"
|
434 |
|
|
);
|
435 |
|
|
|
436 |
|
|
vbr[2] = save_berr;
|
437 |
|
|
restore_flags(flags);
|
438 |
|
|
|
439 |
|
|
return( ret );
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
|
443 |
|
|
static unsigned long lance_probe1( struct device *dev,
|
444 |
|
|
struct lance_addr *init_rec )
|
445 |
|
|
|
446 |
|
|
{ volatile unsigned short *memaddr =
|
447 |
|
|
(volatile unsigned short *)init_rec->memaddr;
|
448 |
|
|
volatile unsigned short *ioaddr =
|
449 |
|
|
(volatile unsigned short *)init_rec->ioaddr;
|
450 |
|
|
struct lance_private *lp;
|
451 |
|
|
struct lance_ioreg *IO;
|
452 |
|
|
int i;
|
453 |
|
|
static int did_version = 0;
|
454 |
|
|
unsigned short save1, save2;
|
455 |
|
|
|
456 |
|
|
PROBE_PRINT(( "Probing for Lance card at mem %#lx io %#lx\n",
|
457 |
|
|
(long)memaddr, (long)ioaddr ));
|
458 |
|
|
|
459 |
|
|
/* Test whether memory readable and writable */
|
460 |
|
|
PROBE_PRINT(( "lance_probe1: testing memory to be accessible\n" ));
|
461 |
|
|
if (!addr_accessible( memaddr, 1, 1 )) goto probe_fail;
|
462 |
|
|
|
463 |
|
|
/* Written values should come back... */
|
464 |
|
|
PROBE_PRINT(( "lance_probe1: testing memory to be writable (1)\n" ));
|
465 |
|
|
save1 = *memaddr;
|
466 |
|
|
*memaddr = 0x0001;
|
467 |
|
|
if (*memaddr != 0x0001) goto probe_fail;
|
468 |
|
|
PROBE_PRINT(( "lance_probe1: testing memory to be writable (2)\n" ));
|
469 |
|
|
*memaddr = 0x0000;
|
470 |
|
|
if (*memaddr != 0x0000) goto probe_fail;
|
471 |
|
|
*memaddr = save1;
|
472 |
|
|
|
473 |
|
|
/* First port should be readable and writable */
|
474 |
|
|
PROBE_PRINT(( "lance_probe1: testing ioport to be accessible\n" ));
|
475 |
|
|
if (!addr_accessible( ioaddr, 1, 1 )) goto probe_fail;
|
476 |
|
|
|
477 |
|
|
/* and written values should be readable */
|
478 |
|
|
PROBE_PRINT(( "lance_probe1: testing ioport to be writeable\n" ));
|
479 |
|
|
save2 = ioaddr[1];
|
480 |
|
|
ioaddr[1] = 0x0001;
|
481 |
|
|
if (ioaddr[1] != 0x0001) goto probe_fail;
|
482 |
|
|
|
483 |
|
|
/* The CSR0_INIT bit should not be readable */
|
484 |
|
|
PROBE_PRINT(( "lance_probe1: testing CSR0 register function (1)\n" ));
|
485 |
|
|
save1 = ioaddr[0];
|
486 |
|
|
ioaddr[1] = CSR0;
|
487 |
|
|
ioaddr[0] = CSR0_INIT | CSR0_STOP;
|
488 |
|
|
if (ioaddr[0] != CSR0_STOP) {
|
489 |
|
|
ioaddr[0] = save1;
|
490 |
|
|
ioaddr[1] = save2;
|
491 |
|
|
goto probe_fail;
|
492 |
|
|
}
|
493 |
|
|
PROBE_PRINT(( "lance_probe1: testing CSR0 register function (2)\n" ));
|
494 |
|
|
ioaddr[0] = CSR0_STOP;
|
495 |
|
|
if (ioaddr[0] != CSR0_STOP) {
|
496 |
|
|
ioaddr[0] = save1;
|
497 |
|
|
ioaddr[1] = save2;
|
498 |
|
|
goto probe_fail;
|
499 |
|
|
}
|
500 |
|
|
|
501 |
|
|
/* Now ok... */
|
502 |
|
|
PROBE_PRINT(( "lance_probe1: Lance card detected\n" ));
|
503 |
|
|
goto probe_ok;
|
504 |
|
|
|
505 |
|
|
probe_fail:
|
506 |
|
|
return( 0 );
|
507 |
|
|
|
508 |
|
|
probe_ok:
|
509 |
|
|
init_etherdev( dev, sizeof(struct lance_private) );
|
510 |
|
|
if (!dev->priv)
|
511 |
|
|
dev->priv = kmalloc( sizeof(struct lance_private), GFP_KERNEL );
|
512 |
|
|
lp = (struct lance_private *)dev->priv;
|
513 |
|
|
MEM = (struct lance_memory *)memaddr;
|
514 |
|
|
IO = lp->iobase = (struct lance_ioreg *)ioaddr;
|
515 |
|
|
dev->base_addr = (unsigned long)ioaddr; /* informational only */
|
516 |
|
|
lp->memcpy_f = init_rec->slow_flag ? slow_memcpy : memcpy;
|
517 |
|
|
|
518 |
|
|
REGA( CSR0 ) = CSR0_STOP;
|
519 |
|
|
|
520 |
|
|
/* Now test for type: If the eeprom I/O port is readable, it is a
|
521 |
|
|
* PAM card */
|
522 |
|
|
if (addr_accessible( &(IO->eeprom), 0, 0 )) {
|
523 |
|
|
/* Switch back to Ram */
|
524 |
|
|
i = IO->mem;
|
525 |
|
|
lp->cardtype = PAM_CARD;
|
526 |
|
|
}
|
527 |
|
|
else if (*RIEBL_MAGIC_ADDR == RIEBL_MAGIC) {
|
528 |
|
|
lp->cardtype = NEW_RIEBL;
|
529 |
|
|
}
|
530 |
|
|
else
|
531 |
|
|
lp->cardtype = OLD_RIEBL;
|
532 |
|
|
|
533 |
|
|
if (lp->cardtype == PAM_CARD ||
|
534 |
|
|
memaddr == (unsigned short *)0xffe00000) {
|
535 |
|
|
/* PAMs card and Riebl on ST use level 5 autovector */
|
536 |
|
|
add_isr( IRQ_AUTO_5, (isrfunc)lance_interrupt, IRQ_TYPE_PRIO, dev,
|
537 |
|
|
"PAM/Riebl-ST Ethernet" );
|
538 |
|
|
dev->irq = (unsigned short)IRQ_AUTO_5;
|
539 |
|
|
}
|
540 |
|
|
else {
|
541 |
|
|
/* For VME-RieblCards, request a free VME int;
|
542 |
|
|
* (This must be unsigned long, since dev->irq is short and the
|
543 |
|
|
* IRQ_MACHSPEC bit would be cut off...)
|
544 |
|
|
*/
|
545 |
|
|
unsigned long irq = atari_register_vme_int();
|
546 |
|
|
if (!irq) {
|
547 |
|
|
printk( "Lance: request for VME interrupt failed\n" );
|
548 |
|
|
return( 0 );
|
549 |
|
|
}
|
550 |
|
|
add_isr( irq, (isrfunc)lance_interrupt, IRQ_TYPE_PRIO, dev,
|
551 |
|
|
"Riebl-VME Ethernet" );
|
552 |
|
|
dev->irq = irq;
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
printk("%s: %s at io %#lx, mem %#lx, irq %d%s, hwaddr ",
|
556 |
|
|
dev->name, lance_names[lp->cardtype],
|
557 |
|
|
(unsigned long)ioaddr,
|
558 |
|
|
(unsigned long)memaddr,
|
559 |
|
|
dev->irq,
|
560 |
|
|
init_rec->slow_flag ? " (slow memcpy)" : "" );
|
561 |
|
|
|
562 |
|
|
/* Get the ethernet address */
|
563 |
|
|
switch( lp->cardtype ) {
|
564 |
|
|
case OLD_RIEBL:
|
565 |
|
|
/* No ethernet address! (Set some default address) */
|
566 |
|
|
memcpy( dev->dev_addr, OldRieblDefHwaddr, 6 );
|
567 |
|
|
break;
|
568 |
|
|
case NEW_RIEBL:
|
569 |
|
|
lp->memcpy_f( dev->dev_addr, RIEBL_HWADDR_ADDR, 6 );
|
570 |
|
|
break;
|
571 |
|
|
case PAM_CARD:
|
572 |
|
|
i = IO->eeprom;
|
573 |
|
|
for( i = 0; i < 6; ++i )
|
574 |
|
|
dev->dev_addr[i] =
|
575 |
|
|
((((unsigned short *)MEM)[i*2] & 0x0f) << 4) |
|
576 |
|
|
((((unsigned short *)MEM)[i*2+1] & 0x0f));
|
577 |
|
|
i = IO->mem;
|
578 |
|
|
break;
|
579 |
|
|
}
|
580 |
|
|
for( i = 0; i < 6; ++i )
|
581 |
|
|
printk( "%02x%s", dev->dev_addr[i], (i < 5) ? ":" : "\n" );
|
582 |
|
|
if (lp->cardtype == OLD_RIEBL) {
|
583 |
|
|
printk( "%s: Warning: This is a default ethernet address!\n",
|
584 |
|
|
dev->name );
|
585 |
|
|
printk( " Use \"ifconfig hw ether ...\" to set the address.\n" );
|
586 |
|
|
}
|
587 |
|
|
|
588 |
|
|
MEM->init.mode = 0x0000; /* Disable Rx and Tx. */
|
589 |
|
|
for( i = 0; i < 6; i++ )
|
590 |
|
|
MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */
|
591 |
|
|
MEM->init.filter[0] = 0x00000000;
|
592 |
|
|
MEM->init.filter[1] = 0x00000000;
|
593 |
|
|
MEM->init.rx_ring.adr_lo = offsetof( struct lance_memory, rx_head );
|
594 |
|
|
MEM->init.rx_ring.adr_hi = 0;
|
595 |
|
|
MEM->init.rx_ring.len = RX_RING_LEN_BITS;
|
596 |
|
|
MEM->init.tx_ring.adr_lo = offsetof( struct lance_memory, tx_head );
|
597 |
|
|
MEM->init.tx_ring.adr_hi = 0;
|
598 |
|
|
MEM->init.tx_ring.len = TX_RING_LEN_BITS;
|
599 |
|
|
|
600 |
|
|
if (lp->cardtype == PAM_CARD)
|
601 |
|
|
IO->ivec = IRQ_SOURCE_TO_VECTOR(dev->irq);
|
602 |
|
|
else
|
603 |
|
|
*RIEBL_IVEC_ADDR = IRQ_SOURCE_TO_VECTOR(dev->irq);
|
604 |
|
|
|
605 |
|
|
if (did_version++ == 0)
|
606 |
|
|
DPRINTK( 1, ( version ));
|
607 |
|
|
|
608 |
|
|
/* The LANCE-specific entries in the device structure. */
|
609 |
|
|
dev->open = &lance_open;
|
610 |
|
|
dev->hard_start_xmit = &lance_start_xmit;
|
611 |
|
|
dev->stop = &lance_close;
|
612 |
|
|
dev->get_stats = &lance_get_stats;
|
613 |
|
|
dev->set_multicast_list = &set_multicast_list;
|
614 |
|
|
dev->set_mac_address = &lance_set_mac_address;
|
615 |
|
|
dev->start = 0;
|
616 |
|
|
|
617 |
|
|
memset( &lp->stats, 0, sizeof(lp->stats) );
|
618 |
|
|
|
619 |
|
|
return( 1 );
|
620 |
|
|
}
|
621 |
|
|
|
622 |
|
|
|
623 |
|
|
static int lance_open( struct device *dev )
|
624 |
|
|
|
625 |
|
|
{ struct lance_private *lp = (struct lance_private *)dev->priv;
|
626 |
|
|
struct lance_ioreg *IO = lp->iobase;
|
627 |
|
|
int i;
|
628 |
|
|
|
629 |
|
|
DPRINTK( 2, ( "%s: lance_open()\n", dev->name ));
|
630 |
|
|
|
631 |
|
|
lance_init_ring(dev);
|
632 |
|
|
/* Re-initialize the LANCE, and start it when done. */
|
633 |
|
|
|
634 |
|
|
REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
|
635 |
|
|
REGA( CSR2 ) = 0;
|
636 |
|
|
REGA( CSR1 ) = 0;
|
637 |
|
|
REGA( CSR0 ) = CSR0_INIT;
|
638 |
|
|
/* From now on, AREG is kept to point to CSR0 */
|
639 |
|
|
|
640 |
|
|
i = 1000000;
|
641 |
|
|
while (--i > 0)
|
642 |
|
|
if (DREG & CSR0_IDON)
|
643 |
|
|
break;
|
644 |
|
|
if (i < 0 || (DREG & CSR0_ERR)) {
|
645 |
|
|
DPRINTK( 2, ( "lance_open(): opening %s failed, i=%d, csr0=%04x\n",
|
646 |
|
|
dev->name, i, DREG ));
|
647 |
|
|
DREG = CSR0_STOP;
|
648 |
|
|
return( -EIO );
|
649 |
|
|
}
|
650 |
|
|
DREG = CSR0_IDON;
|
651 |
|
|
DREG = CSR0_STRT;
|
652 |
|
|
DREG = CSR0_INEA;
|
653 |
|
|
|
654 |
|
|
dev->tbusy = 0;
|
655 |
|
|
dev->interrupt = 0;
|
656 |
|
|
dev->start = 1;
|
657 |
|
|
|
658 |
|
|
DPRINTK( 2, ( "%s: LANCE is open, csr0 %04x\n", dev->name, DREG ));
|
659 |
|
|
MOD_INC_USE_COUNT;
|
660 |
|
|
|
661 |
|
|
return( 0 );
|
662 |
|
|
}
|
663 |
|
|
|
664 |
|
|
|
665 |
|
|
/* Initialize the LANCE Rx and Tx rings. */
|
666 |
|
|
|
667 |
|
|
static void lance_init_ring( struct device *dev )
|
668 |
|
|
|
669 |
|
|
{ struct lance_private *lp = (struct lance_private *)dev->priv;
|
670 |
|
|
int i;
|
671 |
|
|
unsigned offset;
|
672 |
|
|
|
673 |
|
|
lp->lock = 0;
|
674 |
|
|
lp->tx_full = 0;
|
675 |
|
|
lp->cur_rx = lp->cur_tx = 0;
|
676 |
|
|
lp->dirty_tx = 0;
|
677 |
|
|
|
678 |
|
|
offset = offsetof( struct lance_memory, packet_area );
|
679 |
|
|
|
680 |
|
|
/* If the packet buffer at offset 'o' would conflict with the reserved area
|
681 |
|
|
* of RieblCards, advance it */
|
682 |
|
|
#define CHECK_OFFSET(o) \
|
683 |
|
|
do { \
|
684 |
|
|
if (lp->cardtype == OLD_RIEBL || lp->cardtype == NEW_RIEBL) { \
|
685 |
|
|
if (((o) < RIEBL_RSVD_START) ? (o)+PKT_BUF_SZ > RIEBL_RSVD_START \
|
686 |
|
|
: (o) < RIEBL_RSVD_END) \
|
687 |
|
|
(o) = RIEBL_RSVD_END; \
|
688 |
|
|
} \
|
689 |
|
|
} while(0)
|
690 |
|
|
|
691 |
|
|
for( i = 0; i < TX_RING_SIZE; i++ ) {
|
692 |
|
|
CHECK_OFFSET(offset);
|
693 |
|
|
MEM->tx_head[i].base = offset;
|
694 |
|
|
MEM->tx_head[i].flag = TMD1_OWN_HOST;
|
695 |
|
|
MEM->tx_head[i].base_hi = 0;
|
696 |
|
|
MEM->tx_head[i].length = 0;
|
697 |
|
|
MEM->tx_head[i].misc = 0;
|
698 |
|
|
offset += PKT_BUF_SZ;
|
699 |
|
|
}
|
700 |
|
|
|
701 |
|
|
for( i = 0; i < RX_RING_SIZE; i++ ) {
|
702 |
|
|
CHECK_OFFSET(offset);
|
703 |
|
|
MEM->rx_head[i].base = offset;
|
704 |
|
|
MEM->rx_head[i].flag = TMD1_OWN_CHIP;
|
705 |
|
|
MEM->rx_head[i].base_hi = 0;
|
706 |
|
|
MEM->rx_head[i].buf_length = -PKT_BUF_SZ;
|
707 |
|
|
MEM->rx_head[i].msg_length = 0;
|
708 |
|
|
offset += PKT_BUF_SZ;
|
709 |
|
|
}
|
710 |
|
|
}
|
711 |
|
|
|
712 |
|
|
|
713 |
|
|
static int lance_start_xmit( struct sk_buff *skb, struct device *dev )
|
714 |
|
|
|
715 |
|
|
{ struct lance_private *lp = (struct lance_private *)dev->priv;
|
716 |
|
|
struct lance_ioreg *IO = lp->iobase;
|
717 |
|
|
int entry, len;
|
718 |
|
|
struct lance_tx_head *head;
|
719 |
|
|
unsigned long flags;
|
720 |
|
|
|
721 |
|
|
/* Transmitter timeout, serious problems. */
|
722 |
|
|
if (dev->tbusy) {
|
723 |
|
|
int tickssofar = jiffies - dev->trans_start;
|
724 |
|
|
if (tickssofar < 20)
|
725 |
|
|
return( 1 );
|
726 |
|
|
AREG = CSR0;
|
727 |
|
|
DPRINTK( 1, ( "%s: transmit timed out, status %04x, resetting.\n",
|
728 |
|
|
dev->name, DREG ));
|
729 |
|
|
DREG = CSR0_STOP;
|
730 |
|
|
/*
|
731 |
|
|
* Always set BSWP after a STOP as STOP puts it back into
|
732 |
|
|
* little endian mode.
|
733 |
|
|
*/
|
734 |
|
|
REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
|
735 |
|
|
lp->stats.tx_errors++;
|
736 |
|
|
#ifndef final_version
|
737 |
|
|
{ int i;
|
738 |
|
|
DPRINTK( 2, ( "Ring data: dirty_tx %d cur_tx %d%s cur_rx %d\n",
|
739 |
|
|
lp->dirty_tx, lp->cur_tx,
|
740 |
|
|
lp->tx_full ? " (full)" : "",
|
741 |
|
|
lp->cur_rx ));
|
742 |
|
|
for( i = 0 ; i < RX_RING_SIZE; i++ )
|
743 |
|
|
DPRINTK( 2, ( "rx #%d: base=%04x blen=%04x mlen=%04x\n",
|
744 |
|
|
i, MEM->rx_head[i].base,
|
745 |
|
|
-MEM->rx_head[i].buf_length,
|
746 |
|
|
MEM->rx_head[i].msg_length ));
|
747 |
|
|
for( i = 0 ; i < TX_RING_SIZE; i++ )
|
748 |
|
|
DPRINTK( 2, ( "tx #%d: base=%04x len=%04x misc=%04x\n",
|
749 |
|
|
i, MEM->tx_head[i].base,
|
750 |
|
|
-MEM->tx_head[i].length,
|
751 |
|
|
MEM->tx_head[i].misc ));
|
752 |
|
|
}
|
753 |
|
|
#endif
|
754 |
|
|
lance_init_ring(dev);
|
755 |
|
|
REGA( CSR0 ) = CSR0_INEA | CSR0_INIT | CSR0_STRT;
|
756 |
|
|
|
757 |
|
|
dev->tbusy = 0;
|
758 |
|
|
dev->trans_start = jiffies;
|
759 |
|
|
dev_kfree_skb(skb, FREE_WRITE);
|
760 |
|
|
return( 0 );
|
761 |
|
|
}
|
762 |
|
|
|
763 |
|
|
if (skb == NULL) {
|
764 |
|
|
dev_tint( dev );
|
765 |
|
|
return( 0 );
|
766 |
|
|
}
|
767 |
|
|
|
768 |
|
|
if (skb->len <= 0)
|
769 |
|
|
return( 0 );
|
770 |
|
|
|
771 |
|
|
DPRINTK( 2, ( "%s: lance_start_xmit() called, csr0 %4.4x.\n",
|
772 |
|
|
dev->name, DREG ));
|
773 |
|
|
|
774 |
|
|
/* Block a timer-based transmit from overlapping. This could better be
|
775 |
|
|
done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
|
776 |
|
|
if (set_bit( 0, (void*)&dev->tbusy ) != 0) {
|
777 |
|
|
DPRINTK( 0, ( "%s: Transmitter access conflict.\n", dev->name ));
|
778 |
|
|
return 1;
|
779 |
|
|
}
|
780 |
|
|
|
781 |
|
|
if (set_bit( 0, (void*)&lp->lock ) != 0) {
|
782 |
|
|
DPRINTK( 0, ( "%s: tx queue lock!.\n", dev->name ));
|
783 |
|
|
/* don't clear dev->tbusy flag. */
|
784 |
|
|
return 1;
|
785 |
|
|
}
|
786 |
|
|
|
787 |
|
|
/* Fill in a Tx ring entry */
|
788 |
|
|
if (lance_debug >= 3) {
|
789 |
|
|
u_char *p;
|
790 |
|
|
int i;
|
791 |
|
|
printk( "%s: TX pkt type 0x%04x from ", dev->name,
|
792 |
|
|
((u_short *)skb->data)[6]);
|
793 |
|
|
for( p = &((u_char *)skb->data)[6], i = 0; i < 6; i++ )
|
794 |
|
|
printk("%02x%s", *p++, i != 5 ? ":" : "" );
|
795 |
|
|
printk(" to ");
|
796 |
|
|
for( p = (u_char *)skb->data, i = 0; i < 6; i++ )
|
797 |
|
|
printk("%02x%s", *p++, i != 5 ? ":" : "" );
|
798 |
|
|
printk(" data at 0x%08x len %d\n", (int)skb->data,
|
799 |
|
|
(int)skb->len );
|
800 |
|
|
}
|
801 |
|
|
|
802 |
|
|
/* We're not prepared for the int until the last flags are set/reset. And
|
803 |
|
|
* the int may happen already after setting the OWN_CHIP... */
|
804 |
|
|
save_flags(flags);
|
805 |
|
|
cli();
|
806 |
|
|
|
807 |
|
|
/* Mask to ring buffer boundary. */
|
808 |
|
|
entry = lp->cur_tx & TX_RING_MOD_MASK;
|
809 |
|
|
head = &(MEM->tx_head[entry]);
|
810 |
|
|
|
811 |
|
|
/* Caution: the write order is important here, set the "ownership" bits
|
812 |
|
|
* last.
|
813 |
|
|
*/
|
814 |
|
|
|
815 |
|
|
/* The old LANCE chips doesn't automatically pad buffers to min. size. */
|
816 |
|
|
len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
|
817 |
|
|
/* PAM-Card has a bug: Can only send packets with even number of bytes! */
|
818 |
|
|
if (lp->cardtype == PAM_CARD && (len & 1))
|
819 |
|
|
++len;
|
820 |
|
|
|
821 |
|
|
head->length = -len;
|
822 |
|
|
head->misc = 0;
|
823 |
|
|
lp->memcpy_f( PKTBUF_ADDR(head), (void *)skb->data, skb->len );
|
824 |
|
|
head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP;
|
825 |
|
|
dev_kfree_skb( skb, FREE_WRITE );
|
826 |
|
|
lp->cur_tx++;
|
827 |
|
|
while( lp->cur_tx >= TX_RING_SIZE && lp->dirty_tx >= TX_RING_SIZE ) {
|
828 |
|
|
lp->cur_tx -= TX_RING_SIZE;
|
829 |
|
|
lp->dirty_tx -= TX_RING_SIZE;
|
830 |
|
|
}
|
831 |
|
|
|
832 |
|
|
/* Trigger an immediate send poll. */
|
833 |
|
|
DREG = CSR0_INEA | CSR0_TDMD;
|
834 |
|
|
dev->trans_start = jiffies;
|
835 |
|
|
|
836 |
|
|
lp->lock = 0;
|
837 |
|
|
if ((MEM->tx_head[(entry+1) & TX_RING_MOD_MASK].flag & TMD1_OWN) ==
|
838 |
|
|
TMD1_OWN_HOST)
|
839 |
|
|
dev->tbusy = 0;
|
840 |
|
|
else
|
841 |
|
|
lp->tx_full = 1;
|
842 |
|
|
restore_flags(flags);
|
843 |
|
|
|
844 |
|
|
return 0;
|
845 |
|
|
}
|
846 |
|
|
|
847 |
|
|
/* The LANCE interrupt handler. */
|
848 |
|
|
|
849 |
|
|
static void lance_interrupt( int irq, struct pt_regs *fp, struct device *dev )
|
850 |
|
|
|
851 |
|
|
{ struct lance_private *lp;
|
852 |
|
|
struct lance_ioreg *IO;
|
853 |
|
|
int csr0, boguscnt = 10;
|
854 |
|
|
|
855 |
|
|
if (dev == NULL) {
|
856 |
|
|
DPRINTK( 1, ( "lance_interrupt(): interrupt for unknown device.\n" ));
|
857 |
|
|
return;
|
858 |
|
|
}
|
859 |
|
|
|
860 |
|
|
lp = (struct lance_private *)dev->priv;
|
861 |
|
|
IO = lp->iobase;
|
862 |
|
|
AREG = CSR0;
|
863 |
|
|
|
864 |
|
|
if (dev->interrupt)
|
865 |
|
|
DPRINTK( 2, ( "%s: Re-entering the interrupt handler.\n", dev->name ));
|
866 |
|
|
dev->interrupt = 1;
|
867 |
|
|
|
868 |
|
|
while( ((csr0 = DREG) & (CSR0_ERR | CSR0_TINT | CSR0_RINT)) &&
|
869 |
|
|
--boguscnt >= 0) {
|
870 |
|
|
/* Acknowledge all of the current interrupt sources ASAP. */
|
871 |
|
|
DREG = csr0 & ~(CSR0_INIT | CSR0_STRT | CSR0_STOP |
|
872 |
|
|
CSR0_TDMD | CSR0_INEA);
|
873 |
|
|
|
874 |
|
|
DPRINTK( 2, ( "%s: interrupt csr0=%04x new csr=%04x.\n",
|
875 |
|
|
dev->name, csr0, DREG ));
|
876 |
|
|
|
877 |
|
|
if (csr0 & CSR0_RINT) /* Rx interrupt */
|
878 |
|
|
lance_rx( dev );
|
879 |
|
|
|
880 |
|
|
if (csr0 & CSR0_TINT) { /* Tx-done interrupt */
|
881 |
|
|
int dirty_tx = lp->dirty_tx;
|
882 |
|
|
|
883 |
|
|
while( dirty_tx < lp->cur_tx) {
|
884 |
|
|
int entry = dirty_tx & TX_RING_MOD_MASK;
|
885 |
|
|
int status = MEM->tx_head[entry].flag;
|
886 |
|
|
|
887 |
|
|
if (status & TMD1_OWN_CHIP)
|
888 |
|
|
break; /* It still hasn't been Txed */
|
889 |
|
|
|
890 |
|
|
MEM->tx_head[entry].flag = 0;
|
891 |
|
|
|
892 |
|
|
if (status & TMD1_ERR) {
|
893 |
|
|
/* There was an major error, log it. */
|
894 |
|
|
int err_status = MEM->tx_head[entry].misc;
|
895 |
|
|
lp->stats.tx_errors++;
|
896 |
|
|
if (err_status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
|
897 |
|
|
if (err_status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
|
898 |
|
|
if (err_status & TMD3_LCOL) lp->stats.tx_window_errors++;
|
899 |
|
|
if (err_status & TMD3_UFLO) {
|
900 |
|
|
/* Ackk! On FIFO errors the Tx unit is turned off! */
|
901 |
|
|
lp->stats.tx_fifo_errors++;
|
902 |
|
|
/* Remove this verbosity later! */
|
903 |
|
|
DPRINTK( 1, ( "%s: Tx FIFO error! Status %04x\n",
|
904 |
|
|
dev->name, csr0 ));
|
905 |
|
|
/* Restart the chip. */
|
906 |
|
|
DREG = CSR0_STRT;
|
907 |
|
|
}
|
908 |
|
|
} else {
|
909 |
|
|
if (status & (TMD1_MORE | TMD1_ONE | TMD1_DEF))
|
910 |
|
|
lp->stats.collisions++;
|
911 |
|
|
lp->stats.tx_packets++;
|
912 |
|
|
}
|
913 |
|
|
dirty_tx++;
|
914 |
|
|
}
|
915 |
|
|
|
916 |
|
|
#ifndef final_version
|
917 |
|
|
if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {
|
918 |
|
|
DPRINTK( 0, ( "out-of-sync dirty pointer,"
|
919 |
|
|
" %d vs. %d, full=%d.\n",
|
920 |
|
|
dirty_tx, lp->cur_tx, lp->tx_full ));
|
921 |
|
|
dirty_tx += TX_RING_SIZE;
|
922 |
|
|
}
|
923 |
|
|
#endif
|
924 |
|
|
|
925 |
|
|
if (lp->tx_full && dev->tbusy
|
926 |
|
|
&& dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {
|
927 |
|
|
/* The ring is no longer full, clear tbusy. */
|
928 |
|
|
lp->tx_full = 0;
|
929 |
|
|
dev->tbusy = 0;
|
930 |
|
|
mark_bh( NET_BH );
|
931 |
|
|
}
|
932 |
|
|
|
933 |
|
|
lp->dirty_tx = dirty_tx;
|
934 |
|
|
}
|
935 |
|
|
|
936 |
|
|
/* Log misc errors. */
|
937 |
|
|
if (csr0 & CSR0_BABL) lp->stats.tx_errors++; /* Tx babble. */
|
938 |
|
|
if (csr0 & CSR0_MISS) lp->stats.rx_errors++; /* Missed a Rx frame. */
|
939 |
|
|
if (csr0 & CSR0_MERR) {
|
940 |
|
|
DPRINTK( 1, ( "%s: Bus master arbitration failure (?!?), "
|
941 |
|
|
"status %04x.\n", dev->name, csr0 ));
|
942 |
|
|
/* Restart the chip. */
|
943 |
|
|
DREG = CSR0_STRT;
|
944 |
|
|
}
|
945 |
|
|
}
|
946 |
|
|
|
947 |
|
|
/* Clear any other interrupt, and set interrupt enable. */
|
948 |
|
|
DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR |
|
949 |
|
|
CSR0_IDON | CSR0_INEA;
|
950 |
|
|
|
951 |
|
|
DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n",
|
952 |
|
|
dev->name, DREG ));
|
953 |
|
|
dev->interrupt = 0;
|
954 |
|
|
return;
|
955 |
|
|
}
|
956 |
|
|
|
957 |
|
|
|
958 |
|
|
static int lance_rx( struct device *dev )
|
959 |
|
|
|
960 |
|
|
{ struct lance_private *lp = (struct lance_private *)dev->priv;
|
961 |
|
|
int entry = lp->cur_rx & RX_RING_MOD_MASK;
|
962 |
|
|
int i;
|
963 |
|
|
|
964 |
|
|
DPRINTK( 2, ( "%s: rx int, flag=%04x\n", dev->name,
|
965 |
|
|
MEM->rx_head[entry].flag ));
|
966 |
|
|
|
967 |
|
|
/* If we own the next entry, it's a new packet. Send it up. */
|
968 |
|
|
while( (MEM->rx_head[entry].flag & RMD1_OWN) == RMD1_OWN_HOST ) {
|
969 |
|
|
struct lance_rx_head *head = &(MEM->rx_head[entry]);
|
970 |
|
|
int status = head->flag;
|
971 |
|
|
|
972 |
|
|
if (status != (RMD1_ENP|RMD1_STP)) { /* There was an error. */
|
973 |
|
|
/* There is a tricky error noted by John Murphy,
|
974 |
|
|
<murf@perftech.com> to Russ Nelson: Even with full-sized
|
975 |
|
|
buffers it's possible for a jabber packet to use two
|
976 |
|
|
buffers, with only the last correctly noting the error. */
|
977 |
|
|
if (status & RMD1_ENP) /* Only count a general error at the */
|
978 |
|
|
lp->stats.rx_errors++; /* end of a packet.*/
|
979 |
|
|
if (status & RMD1_FRAM) lp->stats.rx_frame_errors++;
|
980 |
|
|
if (status & RMD1_OFLO) lp->stats.rx_over_errors++;
|
981 |
|
|
if (status & RMD1_CRC) lp->stats.rx_crc_errors++;
|
982 |
|
|
if (status & RMD1_BUFF) lp->stats.rx_fifo_errors++;
|
983 |
|
|
head->flag &= (RMD1_ENP|RMD1_STP);
|
984 |
|
|
} else {
|
985 |
|
|
/* Malloc up new buffer, compatible with net-3. */
|
986 |
|
|
short pkt_len = head->msg_length & 0xfff;
|
987 |
|
|
struct sk_buff *skb;
|
988 |
|
|
|
989 |
|
|
if (pkt_len < 60) {
|
990 |
|
|
printk( "%s: Runt packet!\n", dev->name );
|
991 |
|
|
lp->stats.rx_errors++;
|
992 |
|
|
}
|
993 |
|
|
else {
|
994 |
|
|
skb = dev_alloc_skb( pkt_len+2 );
|
995 |
|
|
if (skb == NULL) {
|
996 |
|
|
DPRINTK( 1, ( "%s: Memory squeeze, deferring packet.\n",
|
997 |
|
|
dev->name ));
|
998 |
|
|
for( i = 0; i < RX_RING_SIZE; i++ )
|
999 |
|
|
if (MEM->rx_head[(entry+i) & RX_RING_MOD_MASK].flag &
|
1000 |
|
|
RMD1_OWN_CHIP)
|
1001 |
|
|
break;
|
1002 |
|
|
|
1003 |
|
|
if (i > RX_RING_SIZE - 2) {
|
1004 |
|
|
lp->stats.rx_dropped++;
|
1005 |
|
|
head->flag |= RMD1_OWN_CHIP;
|
1006 |
|
|
lp->cur_rx++;
|
1007 |
|
|
}
|
1008 |
|
|
break;
|
1009 |
|
|
}
|
1010 |
|
|
|
1011 |
|
|
if (lance_debug >= 3) {
|
1012 |
|
|
u_char *data = PKTBUF_ADDR(head), *p;
|
1013 |
|
|
printk( "%s: RX pkt type 0x%04x from ", dev->name,
|
1014 |
|
|
((u_short *)data)[6]);
|
1015 |
|
|
for( p = &data[6], i = 0; i < 6; i++ )
|
1016 |
|
|
printk("%02x%s", *p++, i != 5 ? ":" : "" );
|
1017 |
|
|
printk(" to ");
|
1018 |
|
|
for( p = data, i = 0; i < 6; i++ )
|
1019 |
|
|
printk("%02x%s", *p++, i != 5 ? ":" : "" );
|
1020 |
|
|
printk(" data %02x %02x %02x %02x %02x %02x %02x %02x "
|
1021 |
|
|
"len %d\n",
|
1022 |
|
|
data[15], data[16], data[17], data[18],
|
1023 |
|
|
data[19], data[20], data[21], data[22],
|
1024 |
|
|
pkt_len );
|
1025 |
|
|
}
|
1026 |
|
|
|
1027 |
|
|
skb->dev = dev;
|
1028 |
|
|
skb_reserve( skb, 2 ); /* 16 byte align */
|
1029 |
|
|
skb_put( skb, pkt_len ); /* Make room */
|
1030 |
|
|
lp->memcpy_f( skb->data, PKTBUF_ADDR(head), pkt_len );
|
1031 |
|
|
skb->protocol = eth_type_trans( skb, dev );
|
1032 |
|
|
netif_rx( skb );
|
1033 |
|
|
lp->stats.rx_packets++;
|
1034 |
|
|
}
|
1035 |
|
|
}
|
1036 |
|
|
|
1037 |
|
|
head->flag |= RMD1_OWN_CHIP;
|
1038 |
|
|
entry = (++lp->cur_rx) & RX_RING_MOD_MASK;
|
1039 |
|
|
}
|
1040 |
|
|
lp->cur_rx &= RX_RING_MOD_MASK;
|
1041 |
|
|
|
1042 |
|
|
/* From lance.c (Donald Becker): */
|
1043 |
|
|
/* We should check that at least two ring entries are free. If not,
|
1044 |
|
|
we should free one and mark stats->rx_dropped++. */
|
1045 |
|
|
|
1046 |
|
|
return 0;
|
1047 |
|
|
}
|
1048 |
|
|
|
1049 |
|
|
|
1050 |
|
|
static int lance_close( struct device *dev )
|
1051 |
|
|
|
1052 |
|
|
{ struct lance_private *lp = (struct lance_private *)dev->priv;
|
1053 |
|
|
struct lance_ioreg *IO = lp->iobase;
|
1054 |
|
|
|
1055 |
|
|
dev->start = 0;
|
1056 |
|
|
dev->tbusy = 1;
|
1057 |
|
|
|
1058 |
|
|
AREG = CSR0;
|
1059 |
|
|
|
1060 |
|
|
DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n",
|
1061 |
|
|
dev->name, DREG ));
|
1062 |
|
|
|
1063 |
|
|
/* We stop the LANCE here -- it occasionally polls
|
1064 |
|
|
memory if we don't. */
|
1065 |
|
|
DREG = CSR0_STOP;
|
1066 |
|
|
|
1067 |
|
|
MOD_DEC_USE_COUNT;
|
1068 |
|
|
return 0;
|
1069 |
|
|
}
|
1070 |
|
|
|
1071 |
|
|
|
1072 |
|
|
static struct enet_statistics *lance_get_stats( struct device *dev )
|
1073 |
|
|
|
1074 |
|
|
{ struct lance_private *lp = (struct lance_private *)dev->priv;
|
1075 |
|
|
|
1076 |
|
|
return &lp->stats;
|
1077 |
|
|
}
|
1078 |
|
|
|
1079 |
|
|
|
1080 |
|
|
/* Set or clear the multicast filter for this adaptor.
|
1081 |
|
|
num_addrs == -1 Promiscuous mode, receive all packets
|
1082 |
|
|
num_addrs == 0 Normal mode, clear multicast list
|
1083 |
|
|
num_addrs > 0 Multicast mode, receive normal and MC packets, and do
|
1084 |
|
|
best-effort filtering.
|
1085 |
|
|
*/
|
1086 |
|
|
|
1087 |
|
|
static void set_multicast_list( struct device *dev )
|
1088 |
|
|
|
1089 |
|
|
{ struct lance_private *lp = (struct lance_private *)dev->priv;
|
1090 |
|
|
struct lance_ioreg *IO = lp->iobase;
|
1091 |
|
|
|
1092 |
|
|
if (!dev->start)
|
1093 |
|
|
/* Only possible if board is already started */
|
1094 |
|
|
return;
|
1095 |
|
|
|
1096 |
|
|
/* We take the simple way out and always enable promiscuous mode. */
|
1097 |
|
|
DREG = CSR0_STOP; /* Temporarily stop the lance. */
|
1098 |
|
|
|
1099 |
|
|
if (dev->flags & IFF_PROMISC) {
|
1100 |
|
|
/* Log any net taps. */
|
1101 |
|
|
DPRINTK( 1, ( "%s: Promiscuous mode enabled.\n", dev->name ));
|
1102 |
|
|
REGA( CSR15 ) = 0x8000; /* Set promiscuous mode */
|
1103 |
|
|
} else {
|
1104 |
|
|
short multicast_table[4];
|
1105 |
|
|
int num_addrs = dev->mc_count;
|
1106 |
|
|
int i;
|
1107 |
|
|
/* We don't use the multicast table, but rely on upper-layer
|
1108 |
|
|
* filtering. */
|
1109 |
|
|
memset( multicast_table, (num_addrs == 0) ? 0 : -1,
|
1110 |
|
|
sizeof(multicast_table) );
|
1111 |
|
|
for( i = 0; i < 4; i++ )
|
1112 |
|
|
REGA( CSR8+i ) = multicast_table[i];
|
1113 |
|
|
REGA( CSR15 ) = 0; /* Unset promiscuous mode */
|
1114 |
|
|
}
|
1115 |
|
|
|
1116 |
|
|
/*
|
1117 |
|
|
* Always set BSWP after a STOP as STOP puts it back into
|
1118 |
|
|
* little endian mode.
|
1119 |
|
|
*/
|
1120 |
|
|
REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
|
1121 |
|
|
|
1122 |
|
|
/* Resume normal operation and reset AREG to CSR0 */
|
1123 |
|
|
REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT;
|
1124 |
|
|
}
|
1125 |
|
|
|
1126 |
|
|
|
1127 |
|
|
/* This is needed for old RieblCards and possible for new RieblCards */
|
1128 |
|
|
|
1129 |
|
|
static int lance_set_mac_address( struct device *dev, void *addr )
|
1130 |
|
|
|
1131 |
|
|
{ struct lance_private *lp = (struct lance_private *)dev->priv;
|
1132 |
|
|
struct sockaddr *saddr = addr;
|
1133 |
|
|
int i;
|
1134 |
|
|
|
1135 |
|
|
if (lp->cardtype != OLD_RIEBL && lp->cardtype != NEW_RIEBL)
|
1136 |
|
|
return( -EOPNOTSUPP );
|
1137 |
|
|
|
1138 |
|
|
if (dev->start) {
|
1139 |
|
|
/* Only possible while card isn't started */
|
1140 |
|
|
DPRINTK( 1, ( "%s: hwaddr can be set only while card isn't open.\n",
|
1141 |
|
|
dev->name ));
|
1142 |
|
|
return( -EIO );
|
1143 |
|
|
}
|
1144 |
|
|
|
1145 |
|
|
memcpy( dev->dev_addr, saddr->sa_data, dev->addr_len );
|
1146 |
|
|
for( i = 0; i < 6; i++ )
|
1147 |
|
|
MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */
|
1148 |
|
|
lp->memcpy_f( RIEBL_HWADDR_ADDR, dev->dev_addr, 6 );
|
1149 |
|
|
/* set also the magic for future sessions */
|
1150 |
|
|
*RIEBL_MAGIC_ADDR = RIEBL_MAGIC;
|
1151 |
|
|
|
1152 |
|
|
return( 0 );
|
1153 |
|
|
}
|
1154 |
|
|
|
1155 |
|
|
|
1156 |
|
|
#ifdef MODULE
|
1157 |
|
|
static char devicename[9] = { 0, };
|
1158 |
|
|
|
1159 |
|
|
static struct device atarilance_dev =
|
1160 |
|
|
{
|
1161 |
|
|
devicename, /* filled in by register_netdev() */
|
1162 |
|
|
0, 0, 0, 0, /* memory */
|
1163 |
|
|
0, 0, /* base, irq */
|
1164 |
|
|
0, 0, 0, NULL, atarilance_probe,
|
1165 |
|
|
};
|
1166 |
|
|
|
1167 |
|
|
int init_module(void)
|
1168 |
|
|
|
1169 |
|
|
{ int err;
|
1170 |
|
|
|
1171 |
|
|
if ((err = register_netdev( &atarilance_dev ))) {
|
1172 |
|
|
if (err == -EIO) {
|
1173 |
|
|
printk( "No Atari Lance board found. Module not loaded.\n");
|
1174 |
|
|
}
|
1175 |
|
|
return( err );
|
1176 |
|
|
}
|
1177 |
|
|
return( 0 );
|
1178 |
|
|
}
|
1179 |
|
|
|
1180 |
|
|
void cleanup_module(void)
|
1181 |
|
|
|
1182 |
|
|
{
|
1183 |
|
|
unregister_netdev( &atarilance_dev );
|
1184 |
|
|
}
|
1185 |
|
|
|
1186 |
|
|
#endif /* MODULE */
|
1187 |
|
|
|
1188 |
|
|
|
1189 |
|
|
/*
|
1190 |
|
|
* Local variables:
|
1191 |
|
|
* c-indent-level: 4
|
1192 |
|
|
* tab-width: 4
|
1193 |
|
|
* End:
|
1194 |
|
|
*/
|