Loading...
1/*
2 * linux/drivers/acorn/net/ether1.c
3 *
4 * Copyright (C) 1996-2000 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Acorn ether1 driver (82586 chip) for Acorn machines
11 *
12 * We basically keep two queues in the cards memory - one for transmit
13 * and one for receive. Each has a head and a tail. The head is where
14 * we/the chip adds packets to be transmitted/received, and the tail
15 * is where the transmitter has got to/where the receiver will stop.
16 * Both of these queues are circular, and since the chip is running
17 * all the time, we have to be careful when we modify the pointers etc
18 * so that the buffer memory contents is valid all the time.
19 *
20 * Change log:
21 * 1.00 RMK Released
22 * 1.01 RMK 19/03/1996 Transfers the last odd byte onto/off of the card now.
23 * 1.02 RMK 25/05/1997 Added code to restart RU if it goes not ready
24 * 1.03 RMK 14/09/1997 Cleaned up the handling of a reset during the TX interrupt.
25 * Should prevent lockup.
26 * 1.04 RMK 17/09/1997 Added more info when initialsation of chip goes wrong.
27 * TDR now only reports failure when chip reports non-zero
28 * TDR time-distance.
29 * 1.05 RMK 31/12/1997 Removed calls to dev_tint for 2.1
30 * 1.06 RMK 10/02/2000 Updated for 2.3.43
31 * 1.07 RMK 13/05/2000 Updated for 2.3.99-pre8
32 */
33
34#include <linux/module.h>
35#include <linux/kernel.h>
36#include <linux/types.h>
37#include <linux/fcntl.h>
38#include <linux/interrupt.h>
39#include <linux/ioport.h>
40#include <linux/in.h>
41#include <linux/slab.h>
42#include <linux/string.h>
43#include <linux/errno.h>
44#include <linux/device.h>
45#include <linux/init.h>
46#include <linux/netdevice.h>
47#include <linux/etherdevice.h>
48#include <linux/skbuff.h>
49#include <linux/bitops.h>
50
51#include <asm/io.h>
52#include <asm/dma.h>
53#include <asm/ecard.h>
54
55#define __ETHER1_C
56#include "ether1.h"
57
58static unsigned int net_debug = NET_DEBUG;
59
60#define BUFFER_SIZE 0x10000
61#define TX_AREA_START 0x00100
62#define TX_AREA_END 0x05000
63#define RX_AREA_START 0x05000
64#define RX_AREA_END 0x0fc00
65
66static int ether1_open(struct net_device *dev);
67static int ether1_sendpacket(struct sk_buff *skb, struct net_device *dev);
68static irqreturn_t ether1_interrupt(int irq, void *dev_id);
69static int ether1_close(struct net_device *dev);
70static void ether1_setmulticastlist(struct net_device *dev);
71static void ether1_timeout(struct net_device *dev);
72
73/* ------------------------------------------------------------------------- */
74
75static char version[] = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
76
77#define BUS_16 16
78#define BUS_8 8
79
80/* ------------------------------------------------------------------------- */
81
82#define DISABLEIRQS 1
83#define NORMALIRQS 0
84
85#define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
86#define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
87
88static inline unsigned short
89ether1_inw_p (struct net_device *dev, int addr, int svflgs)
90{
91 unsigned long flags;
92 unsigned short ret;
93
94 if (svflgs)
95 local_irq_save (flags);
96
97 writeb(addr >> 12, REG_PAGE);
98 ret = readw(ETHER1_RAM + ((addr & 4095) << 1));
99 if (svflgs)
100 local_irq_restore (flags);
101 return ret;
102}
103
104static inline void
105ether1_outw_p (struct net_device *dev, unsigned short val, int addr, int svflgs)
106{
107 unsigned long flags;
108
109 if (svflgs)
110 local_irq_save (flags);
111
112 writeb(addr >> 12, REG_PAGE);
113 writew(val, ETHER1_RAM + ((addr & 4095) << 1));
114 if (svflgs)
115 local_irq_restore (flags);
116}
117
118/*
119 * Some inline assembler to allow fast transfers on to/off of the card.
120 * Since this driver depends on some features presented by the ARM
121 * specific architecture, and that you can't configure this driver
122 * without specifiing ARM mode, this is not a problem.
123 *
124 * This routine is essentially an optimised memcpy from the card's
125 * onboard RAM to kernel memory.
126 */
127static void
128ether1_writebuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
129{
130 unsigned int page, thislen, offset;
131 void __iomem *addr;
132
133 offset = start & 4095;
134 page = start >> 12;
135 addr = ETHER1_RAM + (offset << 1);
136
137 if (offset + length > 4096)
138 thislen = 4096 - offset;
139 else
140 thislen = length;
141
142 do {
143 int used;
144
145 writeb(page, REG_PAGE);
146 length -= thislen;
147
148 __asm__ __volatile__(
149 "subs %3, %3, #2\n\
150 bmi 2f\n\
1511: ldr %0, [%1], #2\n\
152 mov %0, %0, lsl #16\n\
153 orr %0, %0, %0, lsr #16\n\
154 str %0, [%2], #4\n\
155 subs %3, %3, #2\n\
156 bmi 2f\n\
157 ldr %0, [%1], #2\n\
158 mov %0, %0, lsl #16\n\
159 orr %0, %0, %0, lsr #16\n\
160 str %0, [%2], #4\n\
161 subs %3, %3, #2\n\
162 bmi 2f\n\
163 ldr %0, [%1], #2\n\
164 mov %0, %0, lsl #16\n\
165 orr %0, %0, %0, lsr #16\n\
166 str %0, [%2], #4\n\
167 subs %3, %3, #2\n\
168 bmi 2f\n\
169 ldr %0, [%1], #2\n\
170 mov %0, %0, lsl #16\n\
171 orr %0, %0, %0, lsr #16\n\
172 str %0, [%2], #4\n\
173 subs %3, %3, #2\n\
174 bpl 1b\n\
1752: adds %3, %3, #1\n\
176 ldreqb %0, [%1]\n\
177 streqb %0, [%2]"
178 : "=&r" (used), "=&r" (data)
179 : "r" (addr), "r" (thislen), "1" (data));
180
181 addr = ETHER1_RAM;
182
183 thislen = length;
184 if (thislen > 4096)
185 thislen = 4096;
186 page++;
187 } while (thislen);
188}
189
190static void
191ether1_readbuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
192{
193 unsigned int page, thislen, offset;
194 void __iomem *addr;
195
196 offset = start & 4095;
197 page = start >> 12;
198 addr = ETHER1_RAM + (offset << 1);
199
200 if (offset + length > 4096)
201 thislen = 4096 - offset;
202 else
203 thislen = length;
204
205 do {
206 int used;
207
208 writeb(page, REG_PAGE);
209 length -= thislen;
210
211 __asm__ __volatile__(
212 "subs %3, %3, #2\n\
213 bmi 2f\n\
2141: ldr %0, [%2], #4\n\
215 strb %0, [%1], #1\n\
216 mov %0, %0, lsr #8\n\
217 strb %0, [%1], #1\n\
218 subs %3, %3, #2\n\
219 bmi 2f\n\
220 ldr %0, [%2], #4\n\
221 strb %0, [%1], #1\n\
222 mov %0, %0, lsr #8\n\
223 strb %0, [%1], #1\n\
224 subs %3, %3, #2\n\
225 bmi 2f\n\
226 ldr %0, [%2], #4\n\
227 strb %0, [%1], #1\n\
228 mov %0, %0, lsr #8\n\
229 strb %0, [%1], #1\n\
230 subs %3, %3, #2\n\
231 bmi 2f\n\
232 ldr %0, [%2], #4\n\
233 strb %0, [%1], #1\n\
234 mov %0, %0, lsr #8\n\
235 strb %0, [%1], #1\n\
236 subs %3, %3, #2\n\
237 bpl 1b\n\
2382: adds %3, %3, #1\n\
239 ldreqb %0, [%2]\n\
240 streqb %0, [%1]"
241 : "=&r" (used), "=&r" (data)
242 : "r" (addr), "r" (thislen), "1" (data));
243
244 addr = ETHER1_RAM;
245
246 thislen = length;
247 if (thislen > 4096)
248 thislen = 4096;
249 page++;
250 } while (thislen);
251}
252
253static int
254ether1_ramtest(struct net_device *dev, unsigned char byte)
255{
256 unsigned char *buffer = kmalloc (BUFFER_SIZE, GFP_KERNEL);
257 int i, ret = BUFFER_SIZE;
258 int max_errors = 15;
259 int bad = -1;
260 int bad_start = 0;
261
262 if (!buffer)
263 return 1;
264
265 memset (buffer, byte, BUFFER_SIZE);
266 ether1_writebuffer (dev, buffer, 0, BUFFER_SIZE);
267 memset (buffer, byte ^ 0xff, BUFFER_SIZE);
268 ether1_readbuffer (dev, buffer, 0, BUFFER_SIZE);
269
270 for (i = 0; i < BUFFER_SIZE; i++) {
271 if (buffer[i] != byte) {
272 if (max_errors >= 0 && bad != buffer[i]) {
273 if (bad != -1)
274 printk ("\n");
275 printk (KERN_CRIT "%s: RAM failed with (%02X instead of %02X) at 0x%04X",
276 dev->name, buffer[i], byte, i);
277 ret = -ENODEV;
278 max_errors --;
279 bad = buffer[i];
280 bad_start = i;
281 }
282 } else {
283 if (bad != -1) {
284 if (bad_start == i - 1)
285 printk ("\n");
286 else
287 printk (" - 0x%04X\n", i - 1);
288 bad = -1;
289 }
290 }
291 }
292
293 if (bad != -1)
294 printk (" - 0x%04X\n", BUFFER_SIZE);
295 kfree (buffer);
296
297 return ret;
298}
299
300static int
301ether1_reset (struct net_device *dev)
302{
303 writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
304 return BUS_16;
305}
306
307static int
308ether1_init_2(struct net_device *dev)
309{
310 int i;
311 dev->mem_start = 0;
312
313 i = ether1_ramtest (dev, 0x5a);
314
315 if (i > 0)
316 i = ether1_ramtest (dev, 0x1e);
317
318 if (i <= 0)
319 return -ENODEV;
320
321 dev->mem_end = i;
322 return 0;
323}
324
325/*
326 * These are the structures that are loaded into the ether RAM card to
327 * initialise the 82586
328 */
329
330/* at 0x0100 */
331#define NOP_ADDR (TX_AREA_START)
332#define NOP_SIZE (0x06)
333static nop_t init_nop = {
334 0,
335 CMD_NOP,
336 NOP_ADDR
337};
338
339/* at 0x003a */
340#define TDR_ADDR (0x003a)
341#define TDR_SIZE (0x08)
342static tdr_t init_tdr = {
343 0,
344 CMD_TDR | CMD_INTR,
345 NOP_ADDR,
346 0
347};
348
349/* at 0x002e */
350#define MC_ADDR (0x002e)
351#define MC_SIZE (0x0c)
352static mc_t init_mc = {
353 0,
354 CMD_SETMULTICAST,
355 TDR_ADDR,
356 0,
357 { { 0, } }
358};
359
360/* at 0x0022 */
361#define SA_ADDR (0x0022)
362#define SA_SIZE (0x0c)
363static sa_t init_sa = {
364 0,
365 CMD_SETADDRESS,
366 MC_ADDR,
367 { 0, }
368};
369
370/* at 0x0010 */
371#define CFG_ADDR (0x0010)
372#define CFG_SIZE (0x12)
373static cfg_t init_cfg = {
374 0,
375 CMD_CONFIG,
376 SA_ADDR,
377 8,
378 8,
379 CFG8_SRDY,
380 CFG9_PREAMB8 | CFG9_ADDRLENBUF | CFG9_ADDRLEN(6),
381 0,
382 0x60,
383 0,
384 CFG13_RETRY(15) | CFG13_SLOTH(2),
385 0,
386};
387
388/* at 0x0000 */
389#define SCB_ADDR (0x0000)
390#define SCB_SIZE (0x10)
391static scb_t init_scb = {
392 0,
393 SCB_CMDACKRNR | SCB_CMDACKCNA | SCB_CMDACKFR | SCB_CMDACKCX,
394 CFG_ADDR,
395 RX_AREA_START,
396 0,
397 0,
398 0,
399 0
400};
401
402/* at 0xffee */
403#define ISCP_ADDR (0xffee)
404#define ISCP_SIZE (0x08)
405static iscp_t init_iscp = {
406 1,
407 SCB_ADDR,
408 0x0000,
409 0x0000
410};
411
412/* at 0xfff6 */
413#define SCP_ADDR (0xfff6)
414#define SCP_SIZE (0x0a)
415static scp_t init_scp = {
416 SCP_SY_16BBUS,
417 { 0, 0 },
418 ISCP_ADDR,
419 0
420};
421
422#define RFD_SIZE (0x16)
423static rfd_t init_rfd = {
424 0,
425 0,
426 0,
427 0,
428 { 0, },
429 { 0, },
430 0
431};
432
433#define RBD_SIZE (0x0a)
434static rbd_t init_rbd = {
435 0,
436 0,
437 0,
438 0,
439 ETH_FRAME_LEN + 8
440};
441
442#define TX_SIZE (0x08)
443#define TBD_SIZE (0x08)
444
445static int
446ether1_init_for_open (struct net_device *dev)
447{
448 int i, status, addr, next, next2;
449 int failures = 0;
450 unsigned long timeout;
451
452 writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
453
454 for (i = 0; i < 6; i++)
455 init_sa.sa_addr[i] = dev->dev_addr[i];
456
457 /* load data structures into ether1 RAM */
458 ether1_writebuffer (dev, &init_scp, SCP_ADDR, SCP_SIZE);
459 ether1_writebuffer (dev, &init_iscp, ISCP_ADDR, ISCP_SIZE);
460 ether1_writebuffer (dev, &init_scb, SCB_ADDR, SCB_SIZE);
461 ether1_writebuffer (dev, &init_cfg, CFG_ADDR, CFG_SIZE);
462 ether1_writebuffer (dev, &init_sa, SA_ADDR, SA_SIZE);
463 ether1_writebuffer (dev, &init_mc, MC_ADDR, MC_SIZE);
464 ether1_writebuffer (dev, &init_tdr, TDR_ADDR, TDR_SIZE);
465 ether1_writebuffer (dev, &init_nop, NOP_ADDR, NOP_SIZE);
466
467 if (ether1_readw(dev, CFG_ADDR, cfg_t, cfg_command, NORMALIRQS) != CMD_CONFIG) {
468 printk (KERN_ERR "%s: detected either RAM fault or compiler bug\n",
469 dev->name);
470 return 1;
471 }
472
473 /*
474 * setup circularly linked list of { rfd, rbd, buffer }, with
475 * all rfds circularly linked, rbds circularly linked.
476 * First rfd is linked to scp, first rbd is linked to first
477 * rfd. Last rbd has a suspend command.
478 */
479 addr = RX_AREA_START;
480 do {
481 next = addr + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
482 next2 = next + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
483
484 if (next2 >= RX_AREA_END) {
485 next = RX_AREA_START;
486 init_rfd.rfd_command = RFD_CMDEL | RFD_CMDSUSPEND;
487 priv(dev)->rx_tail = addr;
488 } else
489 init_rfd.rfd_command = 0;
490 if (addr == RX_AREA_START)
491 init_rfd.rfd_rbdoffset = addr + RFD_SIZE;
492 else
493 init_rfd.rfd_rbdoffset = 0;
494 init_rfd.rfd_link = next;
495 init_rbd.rbd_link = next + RFD_SIZE;
496 init_rbd.rbd_bufl = addr + RFD_SIZE + RBD_SIZE;
497
498 ether1_writebuffer (dev, &init_rfd, addr, RFD_SIZE);
499 ether1_writebuffer (dev, &init_rbd, addr + RFD_SIZE, RBD_SIZE);
500 addr = next;
501 } while (next2 < RX_AREA_END);
502
503 priv(dev)->tx_link = NOP_ADDR;
504 priv(dev)->tx_head = NOP_ADDR + NOP_SIZE;
505 priv(dev)->tx_tail = TDR_ADDR;
506 priv(dev)->rx_head = RX_AREA_START;
507
508 /* release reset & give 586 a prod */
509 priv(dev)->resetting = 1;
510 priv(dev)->initialising = 1;
511 writeb(CTRL_RST, REG_CONTROL);
512 writeb(0, REG_CONTROL);
513 writeb(CTRL_CA, REG_CONTROL);
514
515 /* 586 should now unset iscp.busy */
516 timeout = jiffies + HZ/2;
517 while (ether1_readw(dev, ISCP_ADDR, iscp_t, iscp_busy, DISABLEIRQS) == 1) {
518 if (time_after(jiffies, timeout)) {
519 printk (KERN_WARNING "%s: can't initialise 82586: iscp is busy\n", dev->name);
520 return 1;
521 }
522 }
523
524 /* check status of commands that we issued */
525 timeout += HZ/10;
526 while (((status = ether1_readw(dev, CFG_ADDR, cfg_t, cfg_status, DISABLEIRQS))
527 & STAT_COMPLETE) == 0) {
528 if (time_after(jiffies, timeout))
529 break;
530 }
531
532 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
533 printk (KERN_WARNING "%s: can't initialise 82586: config status %04X\n", dev->name, status);
534 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
535 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
536 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
537 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
538 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
539 failures += 1;
540 }
541
542 timeout += HZ/10;
543 while (((status = ether1_readw(dev, SA_ADDR, sa_t, sa_status, DISABLEIRQS))
544 & STAT_COMPLETE) == 0) {
545 if (time_after(jiffies, timeout))
546 break;
547 }
548
549 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
550 printk (KERN_WARNING "%s: can't initialise 82586: set address status %04X\n", dev->name, status);
551 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
552 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
553 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
554 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
555 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
556 failures += 1;
557 }
558
559 timeout += HZ/10;
560 while (((status = ether1_readw(dev, MC_ADDR, mc_t, mc_status, DISABLEIRQS))
561 & STAT_COMPLETE) == 0) {
562 if (time_after(jiffies, timeout))
563 break;
564 }
565
566 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
567 printk (KERN_WARNING "%s: can't initialise 82586: set multicast status %04X\n", dev->name, status);
568 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
569 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
570 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
571 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
572 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
573 failures += 1;
574 }
575
576 timeout += HZ;
577 while (((status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_status, DISABLEIRQS))
578 & STAT_COMPLETE) == 0) {
579 if (time_after(jiffies, timeout))
580 break;
581 }
582
583 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
584 printk (KERN_WARNING "%s: can't tdr (ignored)\n", dev->name);
585 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
586 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
587 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
588 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
589 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
590 } else {
591 status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_result, DISABLEIRQS);
592 if (status & TDR_XCVRPROB)
593 printk (KERN_WARNING "%s: i/f failed tdr: transceiver problem\n", dev->name);
594 else if ((status & (TDR_SHORT|TDR_OPEN)) && (status & TDR_TIME)) {
595#ifdef FANCY
596 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d.%d us away\n", dev->name,
597 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME) / 10,
598 (status & TDR_TIME) % 10);
599#else
600 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d clks away\n", dev->name,
601 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME));
602#endif
603 }
604 }
605
606 if (failures)
607 ether1_reset (dev);
608 return failures ? 1 : 0;
609}
610
611/* ------------------------------------------------------------------------- */
612
613static int
614ether1_txalloc (struct net_device *dev, int size)
615{
616 int start, tail;
617
618 size = (size + 1) & ~1;
619 tail = priv(dev)->tx_tail;
620
621 if (priv(dev)->tx_head + size > TX_AREA_END) {
622 if (tail > priv(dev)->tx_head)
623 return -1;
624 start = TX_AREA_START;
625 if (start + size > tail)
626 return -1;
627 priv(dev)->tx_head = start + size;
628 } else {
629 if (priv(dev)->tx_head < tail && (priv(dev)->tx_head + size) > tail)
630 return -1;
631 start = priv(dev)->tx_head;
632 priv(dev)->tx_head += size;
633 }
634
635 return start;
636}
637
638static int
639ether1_open (struct net_device *dev)
640{
641 if (request_irq(dev->irq, ether1_interrupt, 0, "ether1", dev))
642 return -EAGAIN;
643
644 if (ether1_init_for_open (dev)) {
645 free_irq (dev->irq, dev);
646 return -EAGAIN;
647 }
648
649 netif_start_queue(dev);
650
651 return 0;
652}
653
654static void
655ether1_timeout(struct net_device *dev)
656{
657 printk(KERN_WARNING "%s: transmit timeout, network cable problem?\n",
658 dev->name);
659 printk(KERN_WARNING "%s: resetting device\n", dev->name);
660
661 ether1_reset (dev);
662
663 if (ether1_init_for_open (dev))
664 printk (KERN_ERR "%s: unable to restart interface\n", dev->name);
665
666 dev->stats.tx_errors++;
667 netif_wake_queue(dev);
668}
669
670static int
671ether1_sendpacket (struct sk_buff *skb, struct net_device *dev)
672{
673 int tmp, tst, nopaddr, txaddr, tbdaddr, dataddr;
674 unsigned long flags;
675 tx_t tx;
676 tbd_t tbd;
677 nop_t nop;
678
679 if (priv(dev)->restart) {
680 printk(KERN_WARNING "%s: resetting device\n", dev->name);
681
682 ether1_reset(dev);
683
684 if (ether1_init_for_open(dev))
685 printk(KERN_ERR "%s: unable to restart interface\n", dev->name);
686 else
687 priv(dev)->restart = 0;
688 }
689
690 if (skb->len < ETH_ZLEN) {
691 if (skb_padto(skb, ETH_ZLEN))
692 goto out;
693 }
694
695 /*
696 * insert packet followed by a nop
697 */
698 txaddr = ether1_txalloc (dev, TX_SIZE);
699 tbdaddr = ether1_txalloc (dev, TBD_SIZE);
700 dataddr = ether1_txalloc (dev, skb->len);
701 nopaddr = ether1_txalloc (dev, NOP_SIZE);
702
703 tx.tx_status = 0;
704 tx.tx_command = CMD_TX | CMD_INTR;
705 tx.tx_link = nopaddr;
706 tx.tx_tbdoffset = tbdaddr;
707 tbd.tbd_opts = TBD_EOL | skb->len;
708 tbd.tbd_link = I82586_NULL;
709 tbd.tbd_bufl = dataddr;
710 tbd.tbd_bufh = 0;
711 nop.nop_status = 0;
712 nop.nop_command = CMD_NOP;
713 nop.nop_link = nopaddr;
714
715 local_irq_save(flags);
716 ether1_writebuffer (dev, &tx, txaddr, TX_SIZE);
717 ether1_writebuffer (dev, &tbd, tbdaddr, TBD_SIZE);
718 ether1_writebuffer (dev, skb->data, dataddr, skb->len);
719 ether1_writebuffer (dev, &nop, nopaddr, NOP_SIZE);
720 tmp = priv(dev)->tx_link;
721 priv(dev)->tx_link = nopaddr;
722
723 /* now reset the previous nop pointer */
724 ether1_writew(dev, txaddr, tmp, nop_t, nop_link, NORMALIRQS);
725
726 local_irq_restore(flags);
727
728 /* handle transmit */
729
730 /* check to see if we have room for a full sized ether frame */
731 tmp = priv(dev)->tx_head;
732 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
733 priv(dev)->tx_head = tmp;
734 dev_kfree_skb (skb);
735
736 if (tst == -1)
737 netif_stop_queue(dev);
738
739 out:
740 return NETDEV_TX_OK;
741}
742
743static void
744ether1_xmit_done (struct net_device *dev)
745{
746 nop_t nop;
747 int caddr, tst;
748
749 caddr = priv(dev)->tx_tail;
750
751again:
752 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
753
754 switch (nop.nop_command & CMD_MASK) {
755 case CMD_TDR:
756 /* special case */
757 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
758 != (unsigned short)I82586_NULL) {
759 ether1_writew(dev, SCB_CMDCUCSTART | SCB_CMDRXSTART, SCB_ADDR, scb_t,
760 scb_command, NORMALIRQS);
761 writeb(CTRL_CA, REG_CONTROL);
762 }
763 priv(dev)->tx_tail = NOP_ADDR;
764 return;
765
766 case CMD_NOP:
767 if (nop.nop_link == caddr) {
768 if (priv(dev)->initialising == 0)
769 printk (KERN_WARNING "%s: strange command complete with no tx command!\n", dev->name);
770 else
771 priv(dev)->initialising = 0;
772 return;
773 }
774 if (caddr == nop.nop_link)
775 return;
776 caddr = nop.nop_link;
777 goto again;
778
779 case CMD_TX:
780 if (nop.nop_status & STAT_COMPLETE)
781 break;
782 printk (KERN_ERR "%s: strange command complete without completed command\n", dev->name);
783 priv(dev)->restart = 1;
784 return;
785
786 default:
787 printk (KERN_WARNING "%s: strange command %d complete! (offset %04X)", dev->name,
788 nop.nop_command & CMD_MASK, caddr);
789 priv(dev)->restart = 1;
790 return;
791 }
792
793 while (nop.nop_status & STAT_COMPLETE) {
794 if (nop.nop_status & STAT_OK) {
795 dev->stats.tx_packets++;
796 dev->stats.collisions += (nop.nop_status & STAT_COLLISIONS);
797 } else {
798 dev->stats.tx_errors++;
799
800 if (nop.nop_status & STAT_COLLAFTERTX)
801 dev->stats.collisions++;
802 if (nop.nop_status & STAT_NOCARRIER)
803 dev->stats.tx_carrier_errors++;
804 if (nop.nop_status & STAT_TXLOSTCTS)
805 printk (KERN_WARNING "%s: cts lost\n", dev->name);
806 if (nop.nop_status & STAT_TXSLOWDMA)
807 dev->stats.tx_fifo_errors++;
808 if (nop.nop_status & STAT_COLLEXCESSIVE)
809 dev->stats.collisions += 16;
810 }
811
812 if (nop.nop_link == caddr) {
813 printk (KERN_ERR "%s: tx buffer chaining error: tx command points to itself\n", dev->name);
814 break;
815 }
816
817 caddr = nop.nop_link;
818 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
819 if ((nop.nop_command & CMD_MASK) != CMD_NOP) {
820 printk (KERN_ERR "%s: tx buffer chaining error: no nop after tx command\n", dev->name);
821 break;
822 }
823
824 if (caddr == nop.nop_link)
825 break;
826
827 caddr = nop.nop_link;
828 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
829 if ((nop.nop_command & CMD_MASK) != CMD_TX) {
830 printk (KERN_ERR "%s: tx buffer chaining error: no tx command after nop\n", dev->name);
831 break;
832 }
833 }
834 priv(dev)->tx_tail = caddr;
835
836 caddr = priv(dev)->tx_head;
837 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
838 priv(dev)->tx_head = caddr;
839 if (tst != -1)
840 netif_wake_queue(dev);
841}
842
843static void
844ether1_recv_done (struct net_device *dev)
845{
846 int status;
847 int nexttail, rbdaddr;
848 rbd_t rbd;
849
850 do {
851 status = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_status, NORMALIRQS);
852 if ((status & RFD_COMPLETE) == 0)
853 break;
854
855 rbdaddr = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_rbdoffset, NORMALIRQS);
856 ether1_readbuffer (dev, &rbd, rbdaddr, RBD_SIZE);
857
858 if ((rbd.rbd_status & (RBD_EOF | RBD_ACNTVALID)) == (RBD_EOF | RBD_ACNTVALID)) {
859 int length = rbd.rbd_status & RBD_ACNT;
860 struct sk_buff *skb;
861
862 length = (length + 1) & ~1;
863 skb = netdev_alloc_skb(dev, length + 2);
864
865 if (skb) {
866 skb_reserve (skb, 2);
867
868 ether1_readbuffer (dev, skb_put (skb, length), rbd.rbd_bufl, length);
869
870 skb->protocol = eth_type_trans (skb, dev);
871 netif_rx (skb);
872 dev->stats.rx_packets++;
873 } else
874 dev->stats.rx_dropped++;
875 } else {
876 printk(KERN_WARNING "%s: %s\n", dev->name,
877 (rbd.rbd_status & RBD_EOF) ? "oversized packet" : "acnt not valid");
878 dev->stats.rx_dropped++;
879 }
880
881 nexttail = ether1_readw(dev, priv(dev)->rx_tail, rfd_t, rfd_link, NORMALIRQS);
882 /* nexttail should be rx_head */
883 if (nexttail != priv(dev)->rx_head)
884 printk(KERN_ERR "%s: receiver buffer chaining error (%04X != %04X)\n",
885 dev->name, nexttail, priv(dev)->rx_head);
886 ether1_writew(dev, RFD_CMDEL | RFD_CMDSUSPEND, nexttail, rfd_t, rfd_command, NORMALIRQS);
887 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_command, NORMALIRQS);
888 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_status, NORMALIRQS);
889 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_rbdoffset, NORMALIRQS);
890
891 priv(dev)->rx_tail = nexttail;
892 priv(dev)->rx_head = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_link, NORMALIRQS);
893 } while (1);
894}
895
896static irqreturn_t
897ether1_interrupt (int irq, void *dev_id)
898{
899 struct net_device *dev = (struct net_device *)dev_id;
900 int status;
901
902 status = ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS);
903
904 if (status) {
905 ether1_writew(dev, status & (SCB_STRNR | SCB_STCNA | SCB_STFR | SCB_STCX),
906 SCB_ADDR, scb_t, scb_command, NORMALIRQS);
907 writeb(CTRL_CA | CTRL_ACK, REG_CONTROL);
908 if (status & SCB_STCX) {
909 ether1_xmit_done (dev);
910 }
911 if (status & SCB_STCNA) {
912 if (priv(dev)->resetting == 0)
913 printk (KERN_WARNING "%s: CU went not ready ???\n", dev->name);
914 else
915 priv(dev)->resetting += 1;
916 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
917 != (unsigned short)I82586_NULL) {
918 ether1_writew(dev, SCB_CMDCUCSTART, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
919 writeb(CTRL_CA, REG_CONTROL);
920 }
921 if (priv(dev)->resetting == 2)
922 priv(dev)->resetting = 0;
923 }
924 if (status & SCB_STFR) {
925 ether1_recv_done (dev);
926 }
927 if (status & SCB_STRNR) {
928 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS) & SCB_STRXSUSP) {
929 printk (KERN_WARNING "%s: RU went not ready: RU suspended\n", dev->name);
930 ether1_writew(dev, SCB_CMDRXRESUME, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
931 writeb(CTRL_CA, REG_CONTROL);
932 dev->stats.rx_dropped++; /* we suspended due to lack of buffer space */
933 } else
934 printk(KERN_WARNING "%s: RU went not ready: %04X\n", dev->name,
935 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS));
936 printk (KERN_WARNING "RU ptr = %04X\n", ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset,
937 NORMALIRQS));
938 }
939 } else
940 writeb(CTRL_ACK, REG_CONTROL);
941
942 return IRQ_HANDLED;
943}
944
945static int
946ether1_close (struct net_device *dev)
947{
948 ether1_reset (dev);
949
950 free_irq(dev->irq, dev);
951
952 return 0;
953}
954
955/*
956 * Set or clear the multicast filter for this adaptor.
957 * num_addrs == -1 Promiscuous mode, receive all packets.
958 * num_addrs == 0 Normal mode, clear multicast list.
959 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
960 * best-effort filtering.
961 */
962static void
963ether1_setmulticastlist (struct net_device *dev)
964{
965}
966
967/* ------------------------------------------------------------------------- */
968
969static void ether1_banner(void)
970{
971 static unsigned int version_printed = 0;
972
973 if (net_debug && version_printed++ == 0)
974 printk(KERN_INFO "%s", version);
975}
976
977static const struct net_device_ops ether1_netdev_ops = {
978 .ndo_open = ether1_open,
979 .ndo_stop = ether1_close,
980 .ndo_start_xmit = ether1_sendpacket,
981 .ndo_set_rx_mode = ether1_setmulticastlist,
982 .ndo_tx_timeout = ether1_timeout,
983 .ndo_validate_addr = eth_validate_addr,
984 .ndo_change_mtu = eth_change_mtu,
985 .ndo_set_mac_address = eth_mac_addr,
986};
987
988static int
989ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
990{
991 struct net_device *dev;
992 int i, ret = 0;
993
994 ether1_banner();
995
996 ret = ecard_request_resources(ec);
997 if (ret)
998 goto out;
999
1000 dev = alloc_etherdev(sizeof(struct ether1_priv));
1001 if (!dev) {
1002 ret = -ENOMEM;
1003 goto release;
1004 }
1005
1006 SET_NETDEV_DEV(dev, &ec->dev);
1007
1008 dev->irq = ec->irq;
1009 priv(dev)->base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
1010 if (!priv(dev)->base) {
1011 ret = -ENOMEM;
1012 goto free;
1013 }
1014
1015 if ((priv(dev)->bus_type = ether1_reset(dev)) == 0) {
1016 ret = -ENODEV;
1017 goto free;
1018 }
1019
1020 for (i = 0; i < 6; i++)
1021 dev->dev_addr[i] = readb(IDPROM_ADDRESS + (i << 2));
1022
1023 if (ether1_init_2(dev)) {
1024 ret = -ENODEV;
1025 goto free;
1026 }
1027
1028 dev->netdev_ops = ðer1_netdev_ops;
1029 dev->watchdog_timeo = 5 * HZ / 100;
1030
1031 ret = register_netdev(dev);
1032 if (ret)
1033 goto free;
1034
1035 printk(KERN_INFO "%s: ether1 in slot %d, %pM\n",
1036 dev->name, ec->slot_no, dev->dev_addr);
1037
1038 ecard_set_drvdata(ec, dev);
1039 return 0;
1040
1041 free:
1042 free_netdev(dev);
1043 release:
1044 ecard_release_resources(ec);
1045 out:
1046 return ret;
1047}
1048
1049static void ether1_remove(struct expansion_card *ec)
1050{
1051 struct net_device *dev = ecard_get_drvdata(ec);
1052
1053 ecard_set_drvdata(ec, NULL);
1054
1055 unregister_netdev(dev);
1056 free_netdev(dev);
1057 ecard_release_resources(ec);
1058}
1059
1060static const struct ecard_id ether1_ids[] = {
1061 { MANU_ACORN, PROD_ACORN_ETHER1 },
1062 { 0xffff, 0xffff }
1063};
1064
1065static struct ecard_driver ether1_driver = {
1066 .probe = ether1_probe,
1067 .remove = ether1_remove,
1068 .id_table = ether1_ids,
1069 .drv = {
1070 .name = "ether1",
1071 },
1072};
1073
1074static int __init ether1_init(void)
1075{
1076 return ecard_register_driver(ðer1_driver);
1077}
1078
1079static void __exit ether1_exit(void)
1080{
1081 ecard_remove_driver(ðer1_driver);
1082}
1083
1084module_init(ether1_init);
1085module_exit(ether1_exit);
1086
1087MODULE_LICENSE("GPL");
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/drivers/acorn/net/ether1.c
4 *
5 * Copyright (C) 1996-2000 Russell King
6 *
7 * Acorn ether1 driver (82586 chip) for Acorn machines
8 *
9 * We basically keep two queues in the cards memory - one for transmit
10 * and one for receive. Each has a head and a tail. The head is where
11 * we/the chip adds packets to be transmitted/received, and the tail
12 * is where the transmitter has got to/where the receiver will stop.
13 * Both of these queues are circular, and since the chip is running
14 * all the time, we have to be careful when we modify the pointers etc
15 * so that the buffer memory contents is valid all the time.
16 *
17 * Change log:
18 * 1.00 RMK Released
19 * 1.01 RMK 19/03/1996 Transfers the last odd byte onto/off of the card now.
20 * 1.02 RMK 25/05/1997 Added code to restart RU if it goes not ready
21 * 1.03 RMK 14/09/1997 Cleaned up the handling of a reset during the TX interrupt.
22 * Should prevent lockup.
23 * 1.04 RMK 17/09/1997 Added more info when initialsation of chip goes wrong.
24 * TDR now only reports failure when chip reports non-zero
25 * TDR time-distance.
26 * 1.05 RMK 31/12/1997 Removed calls to dev_tint for 2.1
27 * 1.06 RMK 10/02/2000 Updated for 2.3.43
28 * 1.07 RMK 13/05/2000 Updated for 2.3.99-pre8
29 */
30
31#include <linux/module.h>
32#include <linux/kernel.h>
33#include <linux/types.h>
34#include <linux/fcntl.h>
35#include <linux/interrupt.h>
36#include <linux/ioport.h>
37#include <linux/in.h>
38#include <linux/slab.h>
39#include <linux/string.h>
40#include <linux/errno.h>
41#include <linux/device.h>
42#include <linux/init.h>
43#include <linux/netdevice.h>
44#include <linux/etherdevice.h>
45#include <linux/skbuff.h>
46#include <linux/bitops.h>
47
48#include <asm/io.h>
49#include <asm/dma.h>
50#include <asm/ecard.h>
51
52#define __ETHER1_C
53#include "ether1.h"
54
55static unsigned int net_debug = NET_DEBUG;
56
57#define BUFFER_SIZE 0x10000
58#define TX_AREA_START 0x00100
59#define TX_AREA_END 0x05000
60#define RX_AREA_START 0x05000
61#define RX_AREA_END 0x0fc00
62
63static int ether1_open(struct net_device *dev);
64static netdev_tx_t ether1_sendpacket(struct sk_buff *skb,
65 struct net_device *dev);
66static irqreturn_t ether1_interrupt(int irq, void *dev_id);
67static int ether1_close(struct net_device *dev);
68static void ether1_setmulticastlist(struct net_device *dev);
69static void ether1_timeout(struct net_device *dev);
70
71/* ------------------------------------------------------------------------- */
72
73static char version[] = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
74
75#define BUS_16 16
76#define BUS_8 8
77
78/* ------------------------------------------------------------------------- */
79
80#define DISABLEIRQS 1
81#define NORMALIRQS 0
82
83#define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
84#define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
85
86static inline unsigned short
87ether1_inw_p (struct net_device *dev, int addr, int svflgs)
88{
89 unsigned long flags;
90 unsigned short ret;
91
92 if (svflgs)
93 local_irq_save (flags);
94
95 writeb(addr >> 12, REG_PAGE);
96 ret = readw(ETHER1_RAM + ((addr & 4095) << 1));
97 if (svflgs)
98 local_irq_restore (flags);
99 return ret;
100}
101
102static inline void
103ether1_outw_p (struct net_device *dev, unsigned short val, int addr, int svflgs)
104{
105 unsigned long flags;
106
107 if (svflgs)
108 local_irq_save (flags);
109
110 writeb(addr >> 12, REG_PAGE);
111 writew(val, ETHER1_RAM + ((addr & 4095) << 1));
112 if (svflgs)
113 local_irq_restore (flags);
114}
115
116/*
117 * Some inline assembler to allow fast transfers on to/off of the card.
118 * Since this driver depends on some features presented by the ARM
119 * specific architecture, and that you can't configure this driver
120 * without specifiing ARM mode, this is not a problem.
121 *
122 * This routine is essentially an optimised memcpy from the card's
123 * onboard RAM to kernel memory.
124 */
125static void
126ether1_writebuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
127{
128 unsigned int page, thislen, offset;
129 void __iomem *addr;
130
131 offset = start & 4095;
132 page = start >> 12;
133 addr = ETHER1_RAM + (offset << 1);
134
135 if (offset + length > 4096)
136 thislen = 4096 - offset;
137 else
138 thislen = length;
139
140 do {
141 int used;
142
143 writeb(page, REG_PAGE);
144 length -= thislen;
145
146 __asm__ __volatile__(
147 "subs %3, %3, #2\n\
148 bmi 2f\n\
1491: ldr %0, [%1], #2\n\
150 mov %0, %0, lsl #16\n\
151 orr %0, %0, %0, lsr #16\n\
152 str %0, [%2], #4\n\
153 subs %3, %3, #2\n\
154 bmi 2f\n\
155 ldr %0, [%1], #2\n\
156 mov %0, %0, lsl #16\n\
157 orr %0, %0, %0, lsr #16\n\
158 str %0, [%2], #4\n\
159 subs %3, %3, #2\n\
160 bmi 2f\n\
161 ldr %0, [%1], #2\n\
162 mov %0, %0, lsl #16\n\
163 orr %0, %0, %0, lsr #16\n\
164 str %0, [%2], #4\n\
165 subs %3, %3, #2\n\
166 bmi 2f\n\
167 ldr %0, [%1], #2\n\
168 mov %0, %0, lsl #16\n\
169 orr %0, %0, %0, lsr #16\n\
170 str %0, [%2], #4\n\
171 subs %3, %3, #2\n\
172 bpl 1b\n\
1732: adds %3, %3, #1\n\
174 ldreqb %0, [%1]\n\
175 streqb %0, [%2]"
176 : "=&r" (used), "=&r" (data)
177 : "r" (addr), "r" (thislen), "1" (data));
178
179 addr = ETHER1_RAM;
180
181 thislen = length;
182 if (thislen > 4096)
183 thislen = 4096;
184 page++;
185 } while (thislen);
186}
187
188static void
189ether1_readbuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
190{
191 unsigned int page, thislen, offset;
192 void __iomem *addr;
193
194 offset = start & 4095;
195 page = start >> 12;
196 addr = ETHER1_RAM + (offset << 1);
197
198 if (offset + length > 4096)
199 thislen = 4096 - offset;
200 else
201 thislen = length;
202
203 do {
204 int used;
205
206 writeb(page, REG_PAGE);
207 length -= thislen;
208
209 __asm__ __volatile__(
210 "subs %3, %3, #2\n\
211 bmi 2f\n\
2121: ldr %0, [%2], #4\n\
213 strb %0, [%1], #1\n\
214 mov %0, %0, lsr #8\n\
215 strb %0, [%1], #1\n\
216 subs %3, %3, #2\n\
217 bmi 2f\n\
218 ldr %0, [%2], #4\n\
219 strb %0, [%1], #1\n\
220 mov %0, %0, lsr #8\n\
221 strb %0, [%1], #1\n\
222 subs %3, %3, #2\n\
223 bmi 2f\n\
224 ldr %0, [%2], #4\n\
225 strb %0, [%1], #1\n\
226 mov %0, %0, lsr #8\n\
227 strb %0, [%1], #1\n\
228 subs %3, %3, #2\n\
229 bmi 2f\n\
230 ldr %0, [%2], #4\n\
231 strb %0, [%1], #1\n\
232 mov %0, %0, lsr #8\n\
233 strb %0, [%1], #1\n\
234 subs %3, %3, #2\n\
235 bpl 1b\n\
2362: adds %3, %3, #1\n\
237 ldreqb %0, [%2]\n\
238 streqb %0, [%1]"
239 : "=&r" (used), "=&r" (data)
240 : "r" (addr), "r" (thislen), "1" (data));
241
242 addr = ETHER1_RAM;
243
244 thislen = length;
245 if (thislen > 4096)
246 thislen = 4096;
247 page++;
248 } while (thislen);
249}
250
251static int
252ether1_ramtest(struct net_device *dev, unsigned char byte)
253{
254 unsigned char *buffer = kmalloc (BUFFER_SIZE, GFP_KERNEL);
255 int i, ret = BUFFER_SIZE;
256 int max_errors = 15;
257 int bad = -1;
258 int bad_start = 0;
259
260 if (!buffer)
261 return 1;
262
263 memset (buffer, byte, BUFFER_SIZE);
264 ether1_writebuffer (dev, buffer, 0, BUFFER_SIZE);
265 memset (buffer, byte ^ 0xff, BUFFER_SIZE);
266 ether1_readbuffer (dev, buffer, 0, BUFFER_SIZE);
267
268 for (i = 0; i < BUFFER_SIZE; i++) {
269 if (buffer[i] != byte) {
270 if (max_errors >= 0 && bad != buffer[i]) {
271 if (bad != -1)
272 printk ("\n");
273 printk (KERN_CRIT "%s: RAM failed with (%02X instead of %02X) at 0x%04X",
274 dev->name, buffer[i], byte, i);
275 ret = -ENODEV;
276 max_errors --;
277 bad = buffer[i];
278 bad_start = i;
279 }
280 } else {
281 if (bad != -1) {
282 if (bad_start == i - 1)
283 printk ("\n");
284 else
285 printk (" - 0x%04X\n", i - 1);
286 bad = -1;
287 }
288 }
289 }
290
291 if (bad != -1)
292 printk (" - 0x%04X\n", BUFFER_SIZE);
293 kfree (buffer);
294
295 return ret;
296}
297
298static int
299ether1_reset (struct net_device *dev)
300{
301 writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
302 return BUS_16;
303}
304
305static int
306ether1_init_2(struct net_device *dev)
307{
308 int i;
309 dev->mem_start = 0;
310
311 i = ether1_ramtest (dev, 0x5a);
312
313 if (i > 0)
314 i = ether1_ramtest (dev, 0x1e);
315
316 if (i <= 0)
317 return -ENODEV;
318
319 dev->mem_end = i;
320 return 0;
321}
322
323/*
324 * These are the structures that are loaded into the ether RAM card to
325 * initialise the 82586
326 */
327
328/* at 0x0100 */
329#define NOP_ADDR (TX_AREA_START)
330#define NOP_SIZE (0x06)
331static nop_t init_nop = {
332 0,
333 CMD_NOP,
334 NOP_ADDR
335};
336
337/* at 0x003a */
338#define TDR_ADDR (0x003a)
339#define TDR_SIZE (0x08)
340static tdr_t init_tdr = {
341 0,
342 CMD_TDR | CMD_INTR,
343 NOP_ADDR,
344 0
345};
346
347/* at 0x002e */
348#define MC_ADDR (0x002e)
349#define MC_SIZE (0x0c)
350static mc_t init_mc = {
351 0,
352 CMD_SETMULTICAST,
353 TDR_ADDR,
354 0,
355 { { 0, } }
356};
357
358/* at 0x0022 */
359#define SA_ADDR (0x0022)
360#define SA_SIZE (0x0c)
361static sa_t init_sa = {
362 0,
363 CMD_SETADDRESS,
364 MC_ADDR,
365 { 0, }
366};
367
368/* at 0x0010 */
369#define CFG_ADDR (0x0010)
370#define CFG_SIZE (0x12)
371static cfg_t init_cfg = {
372 0,
373 CMD_CONFIG,
374 SA_ADDR,
375 8,
376 8,
377 CFG8_SRDY,
378 CFG9_PREAMB8 | CFG9_ADDRLENBUF | CFG9_ADDRLEN(6),
379 0,
380 0x60,
381 0,
382 CFG13_RETRY(15) | CFG13_SLOTH(2),
383 0,
384};
385
386/* at 0x0000 */
387#define SCB_ADDR (0x0000)
388#define SCB_SIZE (0x10)
389static scb_t init_scb = {
390 0,
391 SCB_CMDACKRNR | SCB_CMDACKCNA | SCB_CMDACKFR | SCB_CMDACKCX,
392 CFG_ADDR,
393 RX_AREA_START,
394 0,
395 0,
396 0,
397 0
398};
399
400/* at 0xffee */
401#define ISCP_ADDR (0xffee)
402#define ISCP_SIZE (0x08)
403static iscp_t init_iscp = {
404 1,
405 SCB_ADDR,
406 0x0000,
407 0x0000
408};
409
410/* at 0xfff6 */
411#define SCP_ADDR (0xfff6)
412#define SCP_SIZE (0x0a)
413static scp_t init_scp = {
414 SCP_SY_16BBUS,
415 { 0, 0 },
416 ISCP_ADDR,
417 0
418};
419
420#define RFD_SIZE (0x16)
421static rfd_t init_rfd = {
422 0,
423 0,
424 0,
425 0,
426 { 0, },
427 { 0, },
428 0
429};
430
431#define RBD_SIZE (0x0a)
432static rbd_t init_rbd = {
433 0,
434 0,
435 0,
436 0,
437 ETH_FRAME_LEN + 8
438};
439
440#define TX_SIZE (0x08)
441#define TBD_SIZE (0x08)
442
443static int
444ether1_init_for_open (struct net_device *dev)
445{
446 int i, status, addr, next, next2;
447 int failures = 0;
448 unsigned long timeout;
449
450 writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
451
452 for (i = 0; i < 6; i++)
453 init_sa.sa_addr[i] = dev->dev_addr[i];
454
455 /* load data structures into ether1 RAM */
456 ether1_writebuffer (dev, &init_scp, SCP_ADDR, SCP_SIZE);
457 ether1_writebuffer (dev, &init_iscp, ISCP_ADDR, ISCP_SIZE);
458 ether1_writebuffer (dev, &init_scb, SCB_ADDR, SCB_SIZE);
459 ether1_writebuffer (dev, &init_cfg, CFG_ADDR, CFG_SIZE);
460 ether1_writebuffer (dev, &init_sa, SA_ADDR, SA_SIZE);
461 ether1_writebuffer (dev, &init_mc, MC_ADDR, MC_SIZE);
462 ether1_writebuffer (dev, &init_tdr, TDR_ADDR, TDR_SIZE);
463 ether1_writebuffer (dev, &init_nop, NOP_ADDR, NOP_SIZE);
464
465 if (ether1_readw(dev, CFG_ADDR, cfg_t, cfg_command, NORMALIRQS) != CMD_CONFIG) {
466 printk (KERN_ERR "%s: detected either RAM fault or compiler bug\n",
467 dev->name);
468 return 1;
469 }
470
471 /*
472 * setup circularly linked list of { rfd, rbd, buffer }, with
473 * all rfds circularly linked, rbds circularly linked.
474 * First rfd is linked to scp, first rbd is linked to first
475 * rfd. Last rbd has a suspend command.
476 */
477 addr = RX_AREA_START;
478 do {
479 next = addr + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
480 next2 = next + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
481
482 if (next2 >= RX_AREA_END) {
483 next = RX_AREA_START;
484 init_rfd.rfd_command = RFD_CMDEL | RFD_CMDSUSPEND;
485 priv(dev)->rx_tail = addr;
486 } else
487 init_rfd.rfd_command = 0;
488 if (addr == RX_AREA_START)
489 init_rfd.rfd_rbdoffset = addr + RFD_SIZE;
490 else
491 init_rfd.rfd_rbdoffset = 0;
492 init_rfd.rfd_link = next;
493 init_rbd.rbd_link = next + RFD_SIZE;
494 init_rbd.rbd_bufl = addr + RFD_SIZE + RBD_SIZE;
495
496 ether1_writebuffer (dev, &init_rfd, addr, RFD_SIZE);
497 ether1_writebuffer (dev, &init_rbd, addr + RFD_SIZE, RBD_SIZE);
498 addr = next;
499 } while (next2 < RX_AREA_END);
500
501 priv(dev)->tx_link = NOP_ADDR;
502 priv(dev)->tx_head = NOP_ADDR + NOP_SIZE;
503 priv(dev)->tx_tail = TDR_ADDR;
504 priv(dev)->rx_head = RX_AREA_START;
505
506 /* release reset & give 586 a prod */
507 priv(dev)->resetting = 1;
508 priv(dev)->initialising = 1;
509 writeb(CTRL_RST, REG_CONTROL);
510 writeb(0, REG_CONTROL);
511 writeb(CTRL_CA, REG_CONTROL);
512
513 /* 586 should now unset iscp.busy */
514 timeout = jiffies + HZ/2;
515 while (ether1_readw(dev, ISCP_ADDR, iscp_t, iscp_busy, DISABLEIRQS) == 1) {
516 if (time_after(jiffies, timeout)) {
517 printk (KERN_WARNING "%s: can't initialise 82586: iscp is busy\n", dev->name);
518 return 1;
519 }
520 }
521
522 /* check status of commands that we issued */
523 timeout += HZ/10;
524 while (((status = ether1_readw(dev, CFG_ADDR, cfg_t, cfg_status, DISABLEIRQS))
525 & STAT_COMPLETE) == 0) {
526 if (time_after(jiffies, timeout))
527 break;
528 }
529
530 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
531 printk (KERN_WARNING "%s: can't initialise 82586: config status %04X\n", dev->name, status);
532 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
533 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
534 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
535 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
536 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
537 failures += 1;
538 }
539
540 timeout += HZ/10;
541 while (((status = ether1_readw(dev, SA_ADDR, sa_t, sa_status, DISABLEIRQS))
542 & STAT_COMPLETE) == 0) {
543 if (time_after(jiffies, timeout))
544 break;
545 }
546
547 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
548 printk (KERN_WARNING "%s: can't initialise 82586: set address status %04X\n", dev->name, status);
549 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
550 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
551 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
552 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
553 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
554 failures += 1;
555 }
556
557 timeout += HZ/10;
558 while (((status = ether1_readw(dev, MC_ADDR, mc_t, mc_status, DISABLEIRQS))
559 & STAT_COMPLETE) == 0) {
560 if (time_after(jiffies, timeout))
561 break;
562 }
563
564 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
565 printk (KERN_WARNING "%s: can't initialise 82586: set multicast status %04X\n", dev->name, status);
566 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
567 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
568 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
569 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
570 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
571 failures += 1;
572 }
573
574 timeout += HZ;
575 while (((status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_status, DISABLEIRQS))
576 & STAT_COMPLETE) == 0) {
577 if (time_after(jiffies, timeout))
578 break;
579 }
580
581 if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
582 printk (KERN_WARNING "%s: can't tdr (ignored)\n", dev->name);
583 printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
584 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
585 ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
586 ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
587 ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
588 } else {
589 status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_result, DISABLEIRQS);
590 if (status & TDR_XCVRPROB)
591 printk (KERN_WARNING "%s: i/f failed tdr: transceiver problem\n", dev->name);
592 else if ((status & (TDR_SHORT|TDR_OPEN)) && (status & TDR_TIME)) {
593#ifdef FANCY
594 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d.%d us away\n", dev->name,
595 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME) / 10,
596 (status & TDR_TIME) % 10);
597#else
598 printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d clks away\n", dev->name,
599 status & TDR_SHORT ? "short" : "open", (status & TDR_TIME));
600#endif
601 }
602 }
603
604 if (failures)
605 ether1_reset (dev);
606 return failures ? 1 : 0;
607}
608
609/* ------------------------------------------------------------------------- */
610
611static int
612ether1_txalloc (struct net_device *dev, int size)
613{
614 int start, tail;
615
616 size = (size + 1) & ~1;
617 tail = priv(dev)->tx_tail;
618
619 if (priv(dev)->tx_head + size > TX_AREA_END) {
620 if (tail > priv(dev)->tx_head)
621 return -1;
622 start = TX_AREA_START;
623 if (start + size > tail)
624 return -1;
625 priv(dev)->tx_head = start + size;
626 } else {
627 if (priv(dev)->tx_head < tail && (priv(dev)->tx_head + size) > tail)
628 return -1;
629 start = priv(dev)->tx_head;
630 priv(dev)->tx_head += size;
631 }
632
633 return start;
634}
635
636static int
637ether1_open (struct net_device *dev)
638{
639 if (request_irq(dev->irq, ether1_interrupt, 0, "ether1", dev))
640 return -EAGAIN;
641
642 if (ether1_init_for_open (dev)) {
643 free_irq (dev->irq, dev);
644 return -EAGAIN;
645 }
646
647 netif_start_queue(dev);
648
649 return 0;
650}
651
652static void
653ether1_timeout(struct net_device *dev)
654{
655 printk(KERN_WARNING "%s: transmit timeout, network cable problem?\n",
656 dev->name);
657 printk(KERN_WARNING "%s: resetting device\n", dev->name);
658
659 ether1_reset (dev);
660
661 if (ether1_init_for_open (dev))
662 printk (KERN_ERR "%s: unable to restart interface\n", dev->name);
663
664 dev->stats.tx_errors++;
665 netif_wake_queue(dev);
666}
667
668static netdev_tx_t
669ether1_sendpacket (struct sk_buff *skb, struct net_device *dev)
670{
671 int tmp, tst, nopaddr, txaddr, tbdaddr, dataddr;
672 unsigned long flags;
673 tx_t tx;
674 tbd_t tbd;
675 nop_t nop;
676
677 if (priv(dev)->restart) {
678 printk(KERN_WARNING "%s: resetting device\n", dev->name);
679
680 ether1_reset(dev);
681
682 if (ether1_init_for_open(dev))
683 printk(KERN_ERR "%s: unable to restart interface\n", dev->name);
684 else
685 priv(dev)->restart = 0;
686 }
687
688 if (skb->len < ETH_ZLEN) {
689 if (skb_padto(skb, ETH_ZLEN))
690 goto out;
691 }
692
693 /*
694 * insert packet followed by a nop
695 */
696 txaddr = ether1_txalloc (dev, TX_SIZE);
697 tbdaddr = ether1_txalloc (dev, TBD_SIZE);
698 dataddr = ether1_txalloc (dev, skb->len);
699 nopaddr = ether1_txalloc (dev, NOP_SIZE);
700
701 tx.tx_status = 0;
702 tx.tx_command = CMD_TX | CMD_INTR;
703 tx.tx_link = nopaddr;
704 tx.tx_tbdoffset = tbdaddr;
705 tbd.tbd_opts = TBD_EOL | skb->len;
706 tbd.tbd_link = I82586_NULL;
707 tbd.tbd_bufl = dataddr;
708 tbd.tbd_bufh = 0;
709 nop.nop_status = 0;
710 nop.nop_command = CMD_NOP;
711 nop.nop_link = nopaddr;
712
713 local_irq_save(flags);
714 ether1_writebuffer (dev, &tx, txaddr, TX_SIZE);
715 ether1_writebuffer (dev, &tbd, tbdaddr, TBD_SIZE);
716 ether1_writebuffer (dev, skb->data, dataddr, skb->len);
717 ether1_writebuffer (dev, &nop, nopaddr, NOP_SIZE);
718 tmp = priv(dev)->tx_link;
719 priv(dev)->tx_link = nopaddr;
720
721 /* now reset the previous nop pointer */
722 ether1_writew(dev, txaddr, tmp, nop_t, nop_link, NORMALIRQS);
723
724 local_irq_restore(flags);
725
726 /* handle transmit */
727
728 /* check to see if we have room for a full sized ether frame */
729 tmp = priv(dev)->tx_head;
730 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
731 priv(dev)->tx_head = tmp;
732 dev_kfree_skb (skb);
733
734 if (tst == -1)
735 netif_stop_queue(dev);
736
737 out:
738 return NETDEV_TX_OK;
739}
740
741static void
742ether1_xmit_done (struct net_device *dev)
743{
744 nop_t nop;
745 int caddr, tst;
746
747 caddr = priv(dev)->tx_tail;
748
749again:
750 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
751
752 switch (nop.nop_command & CMD_MASK) {
753 case CMD_TDR:
754 /* special case */
755 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
756 != (unsigned short)I82586_NULL) {
757 ether1_writew(dev, SCB_CMDCUCSTART | SCB_CMDRXSTART, SCB_ADDR, scb_t,
758 scb_command, NORMALIRQS);
759 writeb(CTRL_CA, REG_CONTROL);
760 }
761 priv(dev)->tx_tail = NOP_ADDR;
762 return;
763
764 case CMD_NOP:
765 if (nop.nop_link == caddr) {
766 if (priv(dev)->initialising == 0)
767 printk (KERN_WARNING "%s: strange command complete with no tx command!\n", dev->name);
768 else
769 priv(dev)->initialising = 0;
770 return;
771 }
772 if (caddr == nop.nop_link)
773 return;
774 caddr = nop.nop_link;
775 goto again;
776
777 case CMD_TX:
778 if (nop.nop_status & STAT_COMPLETE)
779 break;
780 printk (KERN_ERR "%s: strange command complete without completed command\n", dev->name);
781 priv(dev)->restart = 1;
782 return;
783
784 default:
785 printk (KERN_WARNING "%s: strange command %d complete! (offset %04X)", dev->name,
786 nop.nop_command & CMD_MASK, caddr);
787 priv(dev)->restart = 1;
788 return;
789 }
790
791 while (nop.nop_status & STAT_COMPLETE) {
792 if (nop.nop_status & STAT_OK) {
793 dev->stats.tx_packets++;
794 dev->stats.collisions += (nop.nop_status & STAT_COLLISIONS);
795 } else {
796 dev->stats.tx_errors++;
797
798 if (nop.nop_status & STAT_COLLAFTERTX)
799 dev->stats.collisions++;
800 if (nop.nop_status & STAT_NOCARRIER)
801 dev->stats.tx_carrier_errors++;
802 if (nop.nop_status & STAT_TXLOSTCTS)
803 printk (KERN_WARNING "%s: cts lost\n", dev->name);
804 if (nop.nop_status & STAT_TXSLOWDMA)
805 dev->stats.tx_fifo_errors++;
806 if (nop.nop_status & STAT_COLLEXCESSIVE)
807 dev->stats.collisions += 16;
808 }
809
810 if (nop.nop_link == caddr) {
811 printk (KERN_ERR "%s: tx buffer chaining error: tx command points to itself\n", dev->name);
812 break;
813 }
814
815 caddr = nop.nop_link;
816 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
817 if ((nop.nop_command & CMD_MASK) != CMD_NOP) {
818 printk (KERN_ERR "%s: tx buffer chaining error: no nop after tx command\n", dev->name);
819 break;
820 }
821
822 if (caddr == nop.nop_link)
823 break;
824
825 caddr = nop.nop_link;
826 ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
827 if ((nop.nop_command & CMD_MASK) != CMD_TX) {
828 printk (KERN_ERR "%s: tx buffer chaining error: no tx command after nop\n", dev->name);
829 break;
830 }
831 }
832 priv(dev)->tx_tail = caddr;
833
834 caddr = priv(dev)->tx_head;
835 tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
836 priv(dev)->tx_head = caddr;
837 if (tst != -1)
838 netif_wake_queue(dev);
839}
840
841static void
842ether1_recv_done (struct net_device *dev)
843{
844 int status;
845 int nexttail, rbdaddr;
846 rbd_t rbd;
847
848 do {
849 status = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_status, NORMALIRQS);
850 if ((status & RFD_COMPLETE) == 0)
851 break;
852
853 rbdaddr = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_rbdoffset, NORMALIRQS);
854 ether1_readbuffer (dev, &rbd, rbdaddr, RBD_SIZE);
855
856 if ((rbd.rbd_status & (RBD_EOF | RBD_ACNTVALID)) == (RBD_EOF | RBD_ACNTVALID)) {
857 int length = rbd.rbd_status & RBD_ACNT;
858 struct sk_buff *skb;
859
860 length = (length + 1) & ~1;
861 skb = netdev_alloc_skb(dev, length + 2);
862
863 if (skb) {
864 skb_reserve (skb, 2);
865
866 ether1_readbuffer (dev, skb_put (skb, length), rbd.rbd_bufl, length);
867
868 skb->protocol = eth_type_trans (skb, dev);
869 netif_rx (skb);
870 dev->stats.rx_packets++;
871 } else
872 dev->stats.rx_dropped++;
873 } else {
874 printk(KERN_WARNING "%s: %s\n", dev->name,
875 (rbd.rbd_status & RBD_EOF) ? "oversized packet" : "acnt not valid");
876 dev->stats.rx_dropped++;
877 }
878
879 nexttail = ether1_readw(dev, priv(dev)->rx_tail, rfd_t, rfd_link, NORMALIRQS);
880 /* nexttail should be rx_head */
881 if (nexttail != priv(dev)->rx_head)
882 printk(KERN_ERR "%s: receiver buffer chaining error (%04X != %04X)\n",
883 dev->name, nexttail, priv(dev)->rx_head);
884 ether1_writew(dev, RFD_CMDEL | RFD_CMDSUSPEND, nexttail, rfd_t, rfd_command, NORMALIRQS);
885 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_command, NORMALIRQS);
886 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_status, NORMALIRQS);
887 ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_rbdoffset, NORMALIRQS);
888
889 priv(dev)->rx_tail = nexttail;
890 priv(dev)->rx_head = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_link, NORMALIRQS);
891 } while (1);
892}
893
894static irqreturn_t
895ether1_interrupt (int irq, void *dev_id)
896{
897 struct net_device *dev = (struct net_device *)dev_id;
898 int status;
899
900 status = ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS);
901
902 if (status) {
903 ether1_writew(dev, status & (SCB_STRNR | SCB_STCNA | SCB_STFR | SCB_STCX),
904 SCB_ADDR, scb_t, scb_command, NORMALIRQS);
905 writeb(CTRL_CA | CTRL_ACK, REG_CONTROL);
906 if (status & SCB_STCX) {
907 ether1_xmit_done (dev);
908 }
909 if (status & SCB_STCNA) {
910 if (priv(dev)->resetting == 0)
911 printk (KERN_WARNING "%s: CU went not ready ???\n", dev->name);
912 else
913 priv(dev)->resetting += 1;
914 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
915 != (unsigned short)I82586_NULL) {
916 ether1_writew(dev, SCB_CMDCUCSTART, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
917 writeb(CTRL_CA, REG_CONTROL);
918 }
919 if (priv(dev)->resetting == 2)
920 priv(dev)->resetting = 0;
921 }
922 if (status & SCB_STFR) {
923 ether1_recv_done (dev);
924 }
925 if (status & SCB_STRNR) {
926 if (ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS) & SCB_STRXSUSP) {
927 printk (KERN_WARNING "%s: RU went not ready: RU suspended\n", dev->name);
928 ether1_writew(dev, SCB_CMDRXRESUME, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
929 writeb(CTRL_CA, REG_CONTROL);
930 dev->stats.rx_dropped++; /* we suspended due to lack of buffer space */
931 } else
932 printk(KERN_WARNING "%s: RU went not ready: %04X\n", dev->name,
933 ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS));
934 printk (KERN_WARNING "RU ptr = %04X\n", ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset,
935 NORMALIRQS));
936 }
937 } else
938 writeb(CTRL_ACK, REG_CONTROL);
939
940 return IRQ_HANDLED;
941}
942
943static int
944ether1_close (struct net_device *dev)
945{
946 ether1_reset (dev);
947
948 free_irq(dev->irq, dev);
949
950 return 0;
951}
952
953/*
954 * Set or clear the multicast filter for this adaptor.
955 * num_addrs == -1 Promiscuous mode, receive all packets.
956 * num_addrs == 0 Normal mode, clear multicast list.
957 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
958 * best-effort filtering.
959 */
960static void
961ether1_setmulticastlist (struct net_device *dev)
962{
963}
964
965/* ------------------------------------------------------------------------- */
966
967static void ether1_banner(void)
968{
969 static unsigned int version_printed = 0;
970
971 if (net_debug && version_printed++ == 0)
972 printk(KERN_INFO "%s", version);
973}
974
975static const struct net_device_ops ether1_netdev_ops = {
976 .ndo_open = ether1_open,
977 .ndo_stop = ether1_close,
978 .ndo_start_xmit = ether1_sendpacket,
979 .ndo_set_rx_mode = ether1_setmulticastlist,
980 .ndo_tx_timeout = ether1_timeout,
981 .ndo_validate_addr = eth_validate_addr,
982 .ndo_set_mac_address = eth_mac_addr,
983};
984
985static int
986ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
987{
988 struct net_device *dev;
989 int i, ret = 0;
990
991 ether1_banner();
992
993 ret = ecard_request_resources(ec);
994 if (ret)
995 goto out;
996
997 dev = alloc_etherdev(sizeof(struct ether1_priv));
998 if (!dev) {
999 ret = -ENOMEM;
1000 goto release;
1001 }
1002
1003 SET_NETDEV_DEV(dev, &ec->dev);
1004
1005 dev->irq = ec->irq;
1006 priv(dev)->base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
1007 if (!priv(dev)->base) {
1008 ret = -ENOMEM;
1009 goto free;
1010 }
1011
1012 if ((priv(dev)->bus_type = ether1_reset(dev)) == 0) {
1013 ret = -ENODEV;
1014 goto free;
1015 }
1016
1017 for (i = 0; i < 6; i++)
1018 dev->dev_addr[i] = readb(IDPROM_ADDRESS + (i << 2));
1019
1020 if (ether1_init_2(dev)) {
1021 ret = -ENODEV;
1022 goto free;
1023 }
1024
1025 dev->netdev_ops = ðer1_netdev_ops;
1026 dev->watchdog_timeo = 5 * HZ / 100;
1027
1028 ret = register_netdev(dev);
1029 if (ret)
1030 goto free;
1031
1032 printk(KERN_INFO "%s: ether1 in slot %d, %pM\n",
1033 dev->name, ec->slot_no, dev->dev_addr);
1034
1035 ecard_set_drvdata(ec, dev);
1036 return 0;
1037
1038 free:
1039 free_netdev(dev);
1040 release:
1041 ecard_release_resources(ec);
1042 out:
1043 return ret;
1044}
1045
1046static void ether1_remove(struct expansion_card *ec)
1047{
1048 struct net_device *dev = ecard_get_drvdata(ec);
1049
1050 ecard_set_drvdata(ec, NULL);
1051
1052 unregister_netdev(dev);
1053 free_netdev(dev);
1054 ecard_release_resources(ec);
1055}
1056
1057static const struct ecard_id ether1_ids[] = {
1058 { MANU_ACORN, PROD_ACORN_ETHER1 },
1059 { 0xffff, 0xffff }
1060};
1061
1062static struct ecard_driver ether1_driver = {
1063 .probe = ether1_probe,
1064 .remove = ether1_remove,
1065 .id_table = ether1_ids,
1066 .drv = {
1067 .name = "ether1",
1068 },
1069};
1070
1071static int __init ether1_init(void)
1072{
1073 return ecard_register_driver(ðer1_driver);
1074}
1075
1076static void __exit ether1_exit(void)
1077{
1078 ecard_remove_driver(ðer1_driver);
1079}
1080
1081module_init(ether1_init);
1082module_exit(ether1_exit);
1083
1084MODULE_LICENSE("GPL");