1 /* 82596.c: A generic 82596 ethernet driver for linux. */
4 Written 1994 by Mark Evans.
5 This driver is for the Apricot 82596 bus-master interface
7 Modularised 12/94 Mark Evans
10 Modified to support the 82596 ethernet chips on 680x0 VME boards.
11 by Richard Hirst <richard@sleepie.demon.co.uk>
14 *** Untested on Apricot hardware, and may require some hacking
15 *** to make it work. The old 82596.c reported hasn't worked
16 *** since 1.3.xx anyway. I have been unable to find any users
17 *** of Apricot hardware to test this on.
19 Most of my modifications relate to the braindead big-endian
20 implementation by Intel. When the i596 is operating in
21 'big-endian' mode, it thinks a 32 bit value of 0x12345678
22 should be stored as 0x56781234. This is a real pain, when
23 you have linked lists which are shared by the 680x0 and the
27 Written 1993 by Donald Becker.
28 Copyright 1993 United States Government as represented by the Director,
29 National Security Agency. This software may only be used and distributed
30 according to the terms of the GNU Public License as modified by SRC,
31 incorporated herein by reference.
33 The author may be reached as becker@super.org or
34 C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
38 static const char *version
= "82596.c:v1.0 15/07/98\n";
40 #include <linux/config.h>
41 #include <linux/module.h>
43 #include <linux/kernel.h>
44 #include <linux/sched.h>
45 #include <linux/string.h>
46 #include <linux/ptrace.h>
47 #include <linux/errno.h>
48 #include <linux/ioport.h>
49 #include <linux/malloc.h>
50 #include <linux/interrupt.h>
51 #include <linux/delay.h>
52 #include <linux/netdevice.h>
53 #include <linux/etherdevice.h>
54 #include <linux/skbuff.h>
55 #include <linux/init.h>
57 #include <asm/bitops.h>
60 #include <asm/pgtable.h> /*?? */
62 #ifdef CONFIG_MVME16x_NET
63 #include <asm/mvme16xhw.h>
65 #ifdef CONFIG_BVME6000_NET
66 #include <asm/bvme6000hw.h>
70 * Define various macros for Channel Attention, word swapping etc., dependent
71 * on architecture. MVME and BVME are 680x0 based, otherwise it is Intel.
75 #define WSWAPrfd(x) ((struct i596_rfd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
76 #define WSWAPrbd(x) ((struct i596_rbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
77 #define WSWAPiscp(x) ((struct i596_iscp *)(((u32)(x)<<16) | ((((u32)(x)))>>16)))
78 #define WSWAPscb(x) ((struct i596_scb *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
79 #define WSWAPcmd(x) ((struct i596_cmd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
80 #define WSWAPtbd(x) ((struct i596_tbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
81 #define WSWAPchar(x) ((char *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
82 #define ISCP_BUSY 0x00010000
83 #define MACH_IS_APRICOT 0
86 #define WSWAPiscp(x) ((struct i596_iscp *)(x))
87 #define WSWAPscb(x) ((struct i596_scb *)(x))
90 #define WSWAPchar(x) x
91 #define ISCP_BUSY 0x0001
92 #define MACH_IS_APRICOT 1
96 * The MPU_PORT command allows direct access to the 82596. With PORT access
97 * the following commands are available (p5-18). The 32-bit port command
98 * must be word-swapped with the most significant word written first.
99 * This only applies to VME boards.
101 #define PORT_RESET 0x00 /* reset 82596 */
102 #define PORT_SELFTEST 0x01 /* selftest */
103 #define PORT_ALTSCP 0x02 /* alternate SCB address */
104 #define PORT_ALTDUMP 0x03 /* Alternate DUMP address */
106 #ifndef HAVE_PORTRESERVE
107 #define check_region(addr, size) 0
108 #define request_region(addr, size,name) do ; while(0)
111 #ifndef HAVE_ALLOC_SKB
112 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
113 #define kfree_skbmem(buff, size) kfree_s(buff,size)
116 #define APRICOT_DEBUG 2
119 int i596_debug
= APRICOT_DEBUG
;
124 #define I596_TOTAL_SIZE 17
128 #define CMD_EOL 0x8000 /* The last command of the list, stop. */
129 #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
130 #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
132 #define CMD_FLEX 0x0008 /* Enable flexible memory model */
135 CmdNOp
= 0, CmdSASetup
= 1, CmdConfigure
= 2, CmdMulticastList
= 3,
136 CmdTx
= 4, CmdTDR
= 5, CmdDump
= 6, CmdDiagnose
= 7
139 #define STAT_C 0x8000 /* Set to 0 after execution */
140 #define STAT_B 0x4000 /* Command being executed */
141 #define STAT_OK 0x2000 /* Command executed ok */
142 #define STAT_A 0x1000 /* Command aborted */
144 #define CUC_START 0x0100
145 #define CUC_RESUME 0x0200
146 #define CUC_SUSPEND 0x0300
147 #define CUC_ABORT 0x0400
148 #define RX_START 0x0010
149 #define RX_RESUME 0x0020
150 #define RX_SUSPEND 0x0030
151 #define RX_ABORT 0x0040
154 unsigned short porthi
;
155 unsigned short portlo
;
160 unsigned short status
;
161 unsigned short command
;
162 struct i596_cmd
*next
;
166 #define SIZE_MASK 0x3fff
171 struct i596_tbd
*next
;
177 struct i596_tbd
*tbd
;
180 struct sk_buff
*skb
; /* So we can free it after tx */
186 struct i596_rfd
*next
;
188 unsigned short count
;
193 #define RX_RING_SIZE 16
196 unsigned short status
;
197 unsigned short command
;
198 struct i596_cmd
*cmd
;
199 struct i596_rfd
*rfd
;
200 unsigned long crc_err
;
201 unsigned long align_err
;
202 unsigned long resource_err
;
203 unsigned long over_err
;
204 unsigned long rcvdt_err
;
205 unsigned long short_err
;
207 unsigned short t_off
;
212 struct i596_scb
*scb
;
216 unsigned long sysbus
;
218 struct i596_iscp
*iscp
;
221 struct i596_private
{
222 volatile struct i596_scp scp
;
223 volatile struct i596_iscp iscp
;
224 volatile struct i596_scb scb
;
225 struct i596_cmd set_add
;
227 struct i596_cmd set_conf
;
228 char i596_config
[16];
231 int last_restart
__attribute__((aligned(4)));
232 struct i596_rfd
*rx_tail
;
233 struct i596_cmd
*cmd_tail
;
234 struct i596_cmd
*cmd_head
;
236 unsigned long last_cmd
;
237 struct net_device_stats stats
;
242 0x8E, /* length, prefetch on */
243 0xC8, /* fifo to 8, monitor off */
245 0xc0, /* don't save bad frames */
247 0x80, /* don't save bad frames */
249 0x2E, /* No source address insertion, 8 byte preamble */
250 0x00, /* priority and backoff defaults */
251 0x60, /* interframe spacing */
252 0x00, /* slot time LSB */
253 0xf2, /* slot time and retries */
254 0x00, /* promiscuous mode */
255 0x00, /* collision detect */
256 0x40, /* minimum frame length */
259 0x7f /* *multi IA */ };
261 static int i596_open(struct device
*dev
);
262 static int i596_start_xmit(struct sk_buff
*skb
, struct device
*dev
);
263 static void i596_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
264 static int i596_close(struct device
*dev
);
265 static struct net_device_stats
*i596_get_stats(struct device
*dev
);
266 static void i596_add_cmd(struct device
*dev
, struct i596_cmd
*cmd
);
267 static void print_eth(char *);
268 static void set_multicast_list(struct device
*dev
);
270 static int ticks_limit
= 25;
271 static int max_cmd_backlog
= 16;
274 static inline void CA(struct device
*dev
)
276 #ifdef CONFIG_MVME16x_NET
277 if (MACH_IS_MVME16x
) {
278 ((struct i596_reg
*) dev
->base_addr
)->ca
= 1;
281 #ifdef CONFIG_BVME6000_NET
282 if (MACH_IS_BVME6000
) {
283 volatile u32 i
= *(volatile u32
*) (dev
->base_addr
);
286 #ifdef CONFIG_APRICOT_i596
287 if (MACH_IS_APRICOT
) {
288 outw(0, (short) (dev
->base_addr
) + 4);
294 static inline void MPU_PORT(struct device
*dev
, int c
, volatile void *x
)
296 #ifdef CONFIG_MVME16x_NET
297 if (MACH_IS_MVME16x
) {
298 struct i596_reg
*p
= (struct i596_reg
*) (dev
->base_addr
);
299 p
->porthi
= ((c
) | (u32
) (x
)) & 0xffff;
300 p
->portlo
= ((c
) | (u32
) (x
)) >> 16;
303 #ifdef CONFIG_BVME6000_NET
304 if (MACH_IS_BVME6000
) {
305 u32 v
= (u32
) (c
) | (u32
) (x
);
306 v
= ((u32
) (v
) << 16) | ((u32
) (v
) >> 16);
307 *(volatile u32
*) dev
->base_addr
= v
;
309 *(volatile u32
*) dev
->base_addr
= v
;
315 #if defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET)
316 static void i596_error(int irq
, void *dev_id
, struct pt_regs
*regs
)
318 struct device
*dev
= dev_id
;
319 struct i596_cmd
*cmd
;
321 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
322 printk("i596_error: lp = 0x%08x\n", (u32
) lp
);
323 printk("scp at %08x, .sysbus = %08x, .iscp = %08x\n",
324 (u32
) & lp
->scp
, (u32
) lp
->scp
.sysbus
, (u32
) lp
->scp
.iscp
);
325 printk("iscp at %08x, .stat = %08x, .scb = %08x\n",
326 (u32
) & lp
->iscp
, (u32
) lp
->iscp
.stat
, (u32
) lp
->iscp
.scb
);
327 printk("scb at %08x, .status = %04x, .command = %04x\n",
328 (u32
) & lp
->scb
, lp
->scb
.status
, lp
->scb
.command
);
329 printk(" .cmd = %08x, .rfd = %08x\n", (u32
) lp
->scb
.cmd
,
331 cmd
= WSWAPcmd(lp
->scb
.cmd
);
332 while (cmd
&& (u32
) cmd
< 0x1000000) {
333 printk("cmd at %08x, .status = %04x, .command = %04x, .next = %08x\n",
334 (u32
) cmd
, cmd
->status
, cmd
->command
, (u32
) cmd
->next
);
335 cmd
= WSWAPcmd(cmd
->next
);
341 static inline int init_rx_bufs(struct device
*dev
, int num
)
343 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
345 struct i596_rfd
*rfd
;
347 lp
->scb
.rfd
= (struct i596_rfd
*) I596_NULL
;
350 printk("%s: init_rx_bufs %d.\n", dev
->name
, num
);
352 for (i
= 0; i
< num
; i
++) {
353 if (!(rfd
= (struct i596_rfd
*) kmalloc(sizeof(struct i596_rfd
), GFP_KERNEL
)))
357 rfd
->rbd
= I596_NULL
;
366 rfd
->next
= lp
->scb
.rfd
;
367 lp
->scb
.rfd
= WSWAPrfd(rfd
);
371 lp
->rx_tail
->next
= lp
->scb
.rfd
;
376 static inline void remove_rx_bufs(struct device
*dev
)
378 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
379 struct i596_rfd
*rfd
= WSWAPrfd(lp
->scb
.rfd
);
381 lp
->rx_tail
->next
= (struct i596_rfd
*) I596_NULL
;
384 lp
->scb
.rfd
= rfd
->next
;
386 rfd
= WSWAPrfd(lp
->scb
.rfd
);
388 while (rfd
!= lp
->rx_tail
);
391 static inline void init_i596_mem(struct device
*dev
)
393 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
394 #if !defined(CONFIG_MVME16x_NET) && !defined(CONFIG_BVME6000_NET)
395 short ioaddr
= dev
->base_addr
;
397 int boguscnt
= 100000;
400 #if defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET)
401 #ifdef CONFIG_MVME16x_NET
402 if (MACH_IS_MVME16x
) {
403 volatile unsigned char *pcc2
= (unsigned char *) 0xfff42000;
405 /* Disable all ints for now */
408 pcc2
[0x2b] = 0x40; /* Set snooping bits now! */
411 #ifdef CONFIG_BVME6000_NET
412 if (MACH_IS_BVME6000
) {
413 volatile unsigned char *ethirq
= (unsigned char *) BVME_ETHIRQ_REG
;
419 MPU_PORT(dev
, PORT_RESET
, 0);
421 udelay(100); /* Wait 100us - seems to help */
423 /* change the scp address */
425 MPU_PORT(dev
, PORT_ALTSCP
, &lp
->scp
);
429 /* change the scp address */
432 outb(4, ioaddr
+ 0xf);
433 outw(((((int) &lp
->scp
) & 0xffff) | 2), ioaddr
);
434 outw((((int) &lp
->scp
) >> 16) & 0xffff, ioaddr
);
437 lp
->last_cmd
= jiffies
;
439 #ifdef CONFIG_MVME16x_NET
441 lp
->scp
.sysbus
= 0x00000054;
443 #ifdef CONFIG_BVME6000_NET
444 if (MACH_IS_BVME6000
)
445 lp
->scp
.sysbus
= 0x0000004c;
447 #ifdef CONFIG_APRICOT_i596
449 lp
->scp
.sysbus
= 0x00440000;
452 lp
->scp
.iscp
= WSWAPiscp(&(lp
->iscp
));
453 lp
->iscp
.scb
= WSWAPscb(&(lp
->scb
));
454 lp
->iscp
.stat
= ISCP_BUSY
;
457 lp
->cmd_head
= lp
->scb
.cmd
= (struct i596_cmd
*) I596_NULL
;
460 printk("%s: starting i82596.\n", dev
->name
);
462 #if !defined(CONFIG_MVME16x_NET) && !defined(CONFIG_BVME6000_NET)
463 (void) inb(ioaddr
+ 0x10);
464 outb(4, ioaddr
+ 0xf);
468 while (lp
->iscp
.stat
)
469 if (--boguscnt
== 0) {
470 printk("%s: i82596 initialization timed out with status %4.4x, cmd %4.4x.\n",
471 dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
476 #ifdef CONFIG_MVME16x_NET
477 if (MACH_IS_MVME16x
) {
478 volatile unsigned char *pcc2
= (unsigned char *) 0xfff42000;
480 /* Enable ints, etc. now */
482 pcc2
[0x2a] = 0x55; /* Edge sensitive */
486 #ifdef CONFIG_BVME6000_NET
487 if (MACH_IS_BVME6000
) {
488 volatile unsigned char *ethirq
= (unsigned char *) BVME_ETHIRQ_REG
;
494 memcpy(lp
->i596_config
, init_setup
, 14);
495 lp
->set_conf
.command
= CmdConfigure
;
496 i596_add_cmd(dev
, &lp
->set_conf
);
498 memcpy(lp
->eth_addr
, dev
->dev_addr
, 6);
499 lp
->set_add
.command
= CmdSASetup
;
500 i596_add_cmd(dev
, &lp
->set_add
);
502 lp
->tdr
.command
= CmdTDR
;
503 i596_add_cmd(dev
, &lp
->tdr
);
510 while (lp
->scb
.command
)
511 if (--boguscnt
== 0) {
512 printk("%s: receive unit start timed out with status %4.4x, cmd %4.4x.\n",
513 dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
516 lp
->scb
.command
= RX_START
;
519 restore_flags(flags
);
522 while (lp
->scb
.command
)
523 if (--boguscnt
== 0) {
524 printk("i82596 init timed out with status %4.4x, cmd %4.4x.\n",
525 lp
->scb
.status
, lp
->scb
.command
);
531 static inline int i596_rx(struct device
*dev
)
533 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
534 struct i596_rfd
*rfd
;
538 printk("i596_rx()\n");
540 rfd
= WSWAPrfd(lp
->scb
.rfd
); /* Reference next frame descriptor to check */
542 while ((rfd
->stat
) & STAT_C
) { /* Loop while we have complete frames */
544 print_eth(rfd
->data
);
546 if ((rfd
->stat
) & STAT_OK
) {
548 int pkt_len
= rfd
->count
& 0x3fff;
549 struct sk_buff
*skb
= dev_alloc_skb(pkt_len
);
554 printk("%s: i596_rx Memory squeeze, dropping packet.\n", dev
->name
);
555 lp
->stats
.rx_dropped
++;
558 memcpy(skb_put(skb
, pkt_len
), rfd
->data
, pkt_len
);
559 skb
->protocol
= eth_type_trans(skb
, dev
);
561 lp
->stats
.rx_packets
++;
562 lp
->stats
.rx_bytes
+= pkt_len
;
565 lp
->stats
.rx_errors
++;
566 if ((rfd
->stat
) & 0x0001)
567 lp
->stats
.collisions
++;
568 if ((rfd
->stat
) & 0x0080)
569 lp
->stats
.rx_length_errors
++;
570 if ((rfd
->stat
) & 0x0100)
571 lp
->stats
.rx_over_errors
++;
572 if ((rfd
->stat
) & 0x0200)
573 lp
->stats
.rx_fifo_errors
++;
574 if ((rfd
->stat
) & 0x0400)
575 lp
->stats
.rx_frame_errors
++;
576 if ((rfd
->stat
) & 0x0800)
577 lp
->stats
.rx_crc_errors
++;
578 if ((rfd
->stat
) & 0x1000)
579 lp
->stats
.rx_length_errors
++;
582 /* Clear the buffer descriptor count and EOF + F flags */
587 lp
->rx_tail
->cmd
= 0;
589 lp
->scb
.rfd
= rfd
->next
;
590 rfd
= WSWAPrfd(lp
->scb
.rfd
); /* Next frame descriptor to check */
594 printk("frames %d\n", frames
);
599 static inline void i596_cleanup_cmd(struct i596_private
*lp
)
601 struct i596_cmd
*ptr
;
605 printk("i596_cleanup_cmd\n");
607 while (lp
->cmd_head
!= (struct i596_cmd
*) I596_NULL
) {
610 lp
->cmd_head
= WSWAPcmd(lp
->cmd_head
->next
);
613 switch ((ptr
->command
) & 0x7) {
616 struct tx_cmd
*tx_cmd
= (struct tx_cmd
*) ptr
;
617 struct sk_buff
*skb
= tx_cmd
->skb
;
621 lp
->stats
.tx_errors
++;
622 lp
->stats
.tx_aborted_errors
++;
624 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
628 case CmdMulticastList
:
630 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
635 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
639 while (lp
->scb
.command
)
640 if (--boguscnt
== 0) {
641 printk("i596_cleanup_cmd timed out with status %4.4x, cmd %4.4x.\n",
642 lp
->scb
.status
, lp
->scb
.command
);
645 lp
->scb
.cmd
= WSWAPcmd(lp
->cmd_head
);
648 static inline void i596_reset(struct device
*dev
, struct i596_private
*lp
, int ioaddr
)
654 printk("i596_reset\n");
659 while (lp
->scb
.command
)
660 if (--boguscnt
== 0) {
661 printk("i596_reset timed out with status %4.4x, cmd %4.4x.\n",
662 lp
->scb
.status
, lp
->scb
.command
);
668 lp
->scb
.command
= CUC_ABORT
| RX_ABORT
;
671 /* wait for shutdown */
674 while (lp
->scb
.command
)
675 if (--boguscnt
== 0) {
676 printk("i596_reset 2 timed out with status %4.4x, cmd %4.4x.\n",
677 lp
->scb
.status
, lp
->scb
.command
);
680 restore_flags(flags
);
682 i596_cleanup_cmd(lp
);
691 static void i596_add_cmd(struct device
*dev
, struct i596_cmd
*cmd
)
693 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
694 int ioaddr
= dev
->base_addr
;
699 printk("i596_add_cmd\n");
702 cmd
->command
|= (CMD_EOL
| CMD_INTR
);
703 cmd
->next
= (struct i596_cmd
*) I596_NULL
;
708 * RGH 300597: Looks to me like there could be a race condition
709 * here. Just because we havn't picked up all the command items
710 * yet, doesn't mean that the 82596 hasn't finished processing
711 * them. So, we may need to do a CUC_START anyway.
712 * Maybe not. If it interrupts saying the CU is idle when there
713 * is still something in the cmd queue, the int handler with restart
717 if (lp
->cmd_head
!= (struct i596_cmd
*) I596_NULL
) {
718 lp
->cmd_tail
->next
= WSWAPcmd(cmd
);
721 while (lp
->scb
.command
)
722 if (--boguscnt
== 0) {
723 printk("i596_add_cmd timed out with status %4.4x, cmd %4.4x.\n",
724 lp
->scb
.status
, lp
->scb
.command
);
727 lp
->scb
.cmd
= WSWAPcmd(cmd
);
728 lp
->scb
.command
= CUC_START
;
734 lp
->cmd_head
= WSWAPcmd(lp
->scb
.cmd
); /* Is this redundant? RGH 300597 */
735 restore_flags(flags
);
737 if (lp
->cmd_backlog
> max_cmd_backlog
) {
738 unsigned long tickssofar
= jiffies
- lp
->last_cmd
;
740 if (tickssofar
< ticks_limit
)
743 printk("%s: command unit timed out, status resetting.\n", dev
->name
);
745 i596_reset(dev
, lp
, ioaddr
);
749 static int i596_open(struct device
*dev
)
754 printk("%s: i596_open() irq %d.\n", dev
->name
, dev
->irq
);
756 if (request_irq(dev
->irq
, &i596_interrupt
, 0, "apricot", dev
))
758 #ifdef CONFIG_MVME16x_NET
759 if (MACH_IS_MVME16x
) {
760 if (request_irq(0x56, &i596_error
, 0, "apricot_error", dev
))
764 if ((i
= init_rx_bufs(dev
, RX_RING_SIZE
)) < RX_RING_SIZE
)
765 printk("%s: only able to allocate %d receive buffers\n", dev
->name
, i
);
768 free_irq(dev
->irq
, dev
);
776 /* Initialize the 82596 memory */
779 return 0; /* Always succeed */
782 static int i596_start_xmit(struct sk_buff
*skb
, struct device
*dev
)
784 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
785 int ioaddr
= dev
->base_addr
;
786 struct tx_cmd
*tx_cmd
;
789 printk("%s: 82596 start xmit\n", dev
->name
);
791 /* Transmitter timeout, serious problems. */
793 int tickssofar
= jiffies
- dev
->trans_start
;
796 printk("%s: transmit timed out, status resetting.\n",
798 lp
->stats
.tx_errors
++;
799 /* Try to restart the adaptor */
800 if (lp
->last_restart
== lp
->stats
.tx_packets
) {
802 printk("Resetting board.\n");
804 /* Shutdown and restart */
805 i596_reset(dev
, lp
, ioaddr
);
807 /* Issue a channel attention signal */
809 printk("Kicking board.\n");
810 lp
->scb
.command
= CUC_START
| RX_START
;
812 lp
->last_restart
= lp
->stats
.tx_packets
;
815 dev
->trans_start
= jiffies
;
818 printk("%s: i596_start_xmit() called\n", dev
->name
);
820 /* Block a timer-based transmit from overlapping. This could better be
821 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
822 if (test_and_set_bit(0, (void *) &dev
->tbusy
) != 0)
823 printk("%s: Transmitter access conflict.\n", dev
->name
);
825 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
826 dev
->trans_start
= jiffies
;
828 tx_cmd
= (struct tx_cmd
*) kmalloc((sizeof(struct tx_cmd
) + sizeof(struct i596_tbd
)), GFP_ATOMIC
);
829 if (tx_cmd
== NULL
) {
830 printk("%s: i596_xmit Memory squeeze, dropping packet.\n", dev
->name
);
831 lp
->stats
.tx_dropped
++;
835 struct i596_tbd
*tbd
= (struct i596_tbd
*) (tx_cmd
+ 1);
836 tx_cmd
->tbd
= WSWAPtbd(tbd
);
837 tbd
->next
= (struct i596_tbd
*) I596_NULL
;
839 tx_cmd
->cmd
.command
= CMD_FLEX
| CmdTx
;
845 tbd
->size
= EOF
| length
;
847 tbd
->data
= WSWAPchar(skb
->data
);
850 print_eth(skb
->data
);
851 i596_add_cmd(dev
, (struct i596_cmd
*) tx_cmd
);
853 lp
->stats
.tx_packets
++;
854 lp
->stats
.tx_bytes
+= length
;
864 static void print_eth(char *add
)
868 printk("print_eth(%08x)\n", (unsigned int) add
);
870 for (i
= 0; i
< 6; i
++)
871 printk(" %2.2X", (unsigned char) add
[i
]);
875 for (i
= 0; i
< 6; i
++)
876 printk(" %2.2X", (unsigned char) add
[i
+ 6]);
878 printk("type %2.2X%2.2X\n", (unsigned char) add
[12], (unsigned char) add
[13]);
881 __initfunc(int i82596_probe(struct device
*dev
))
884 struct i596_private
*lp
;
887 #ifdef CONFIG_MVME16x_NET
888 if (MACH_IS_MVME16x
) {
889 static int probed
= 0;
891 if (mvme16x_config
& MVME16x_CONFIG_NO_ETHERNET
) {
892 printk("Ethernet probe disabled - chip not present\n");
898 memcpy(eth_addr
, (void *) 0xfffc1f2c, 6); /* YUCK! Get addr from NOVRAM */
899 dev
->base_addr
= MVME_I596_BASE
;
900 dev
->irq
= (unsigned) MVME16x_IRQ_I596
;
903 #ifdef CONFIG_BVME6000_NET
904 if (MACH_IS_BVME6000
) {
905 volatile unsigned char *rtc
= (unsigned char *) BVME_RTC_BASE
;
906 unsigned char msr
= rtc
[3];
910 for (i
= 0; i
< 6; i
++)
911 eth_addr
[i
] = rtc
[i
* 4 + 7]; /* Stored in RTC RAM at offset 1 */
913 dev
->base_addr
= BVME_I596_BASE
;
914 dev
->irq
= (unsigned) BVME_IRQ_I596
;
917 #ifdef CONFIG_APRICOT_INTEL
921 /* this is easy the ethernet interface can only be at 0x300 */
922 /* first check nothing is already registered here */
924 if (check_region(ioaddr
, I596_TOTAL_SIZE
))
927 for (i
= 0; i
< 8; i
++) {
928 eth_addr
[i
] = inb(ioaddr
+ 8 + i
);
929 checksum
+= eth_addr
[i
];
932 /* checksum is a multiple of 0x100, got this wrong first time
933 some machines have 0x100, some 0x200. The DOS driver doesn't
934 even bother with the checksum */
936 if (checksum
% 0x100)
939 /* Some other boards trip the checksum.. but then appear as ether
940 address 0. Trap these - AC */
942 if (memcmp(eth_addr
, "\x00\x00\x49", 3) != 0)
945 request_region(ioaddr
, I596_TOTAL_SIZE
, "i596");
947 dev
->base_addr
= ioaddr
;
951 printk("%s: 82596 at %#3lx,", dev
->name
, dev
->base_addr
);
953 for (i
= 0; i
< 6; i
++)
954 printk(" %2.2X", dev
->dev_addr
[i
] = eth_addr
[i
]);
956 printk(" IRQ %d.\n", dev
->irq
);
961 /* The APRICOT-specific entries in the device structure. */
962 dev
->open
= &i596_open
;
963 dev
->stop
= &i596_close
;
964 dev
->hard_start_xmit
= &i596_start_xmit
;
965 dev
->get_stats
= &i596_get_stats
;
966 dev
->set_multicast_list
= &set_multicast_list
;
968 dev
->mem_start
= (int) kmalloc(sizeof(struct i596_private
) + 0x0f, GFP_KERNEL
);
970 dev
->priv
= (void *) ((dev
->mem_start
+ 0xf) & 0xfffffff0);
972 lp
= (struct i596_private
*) dev
->priv
;
974 printk("%s: lp at 0x%08lx, lp->scb at 0x%08lx\n"
975 ,dev
->name
, (unsigned long) lp
, (unsigned long) &lp
->scb
);
976 memset((void *) lp
, 0, sizeof(struct i596_private
));
978 lp
->scb
.cmd
= (struct i596_cmd
*) I596_NULL
;
979 lp
->scb
.rfd
= (struct i596_rfd
*) I596_NULL
;
984 static void i596_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
986 struct device
*dev
= dev_id
;
987 struct i596_private
*lp
;
990 unsigned short status
, ack_cmd
= 0;
992 #ifdef CONFIG_BVME6000_NET
993 if (MACH_IS_BVME6000
) {
994 if (*(char *) BVME_LOCAL_IRQ_STAT
& BVME_ETHERR
) {
995 i596_error(BVME_IRQ_I596
, NULL
, NULL
);
1001 printk("i596_interrupt(): irq %d for unknown device.\n", irq
);
1005 printk("%s: i596_interrupt(): irq %d\n", dev
->name
, irq
);
1008 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
1012 ioaddr
= dev
->base_addr
;
1014 lp
= (struct i596_private
*) dev
->priv
;
1016 while (lp
->scb
.command
)
1017 if (--boguscnt
== 0) {
1018 printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
1021 status
= lp
->scb
.status
;
1024 printk("%s: i596 interrupt, status %4.4x.\n", dev
->name
, status
);
1026 ack_cmd
= status
& 0xf000;
1028 if ((status
& 0x8000) || (status
& 0x2000)) {
1029 struct i596_cmd
*ptr
;
1031 if ((i596_debug
> 4) && (status
& 0x8000))
1032 printk("%s: i596 interrupt completed command.\n", dev
->name
);
1033 if ((i596_debug
> 4) && (status
& 0x2000))
1034 printk("%s: i596 interrupt command unit inactive %x.\n", dev
->name
, status
& 0x0700);
1036 while ((lp
->cmd_head
!= (struct i596_cmd
*) I596_NULL
) && (lp
->cmd_head
->status
& STAT_C
)) {
1040 printk("cmd_head->status = %04x, ->command = %04x\n",
1041 lp
->cmd_head
->status
, lp
->cmd_head
->command
);
1042 lp
->cmd_head
= WSWAPcmd(lp
->cmd_head
->next
);
1045 switch ((ptr
->command
) & 0x7) {
1048 struct tx_cmd
*tx_cmd
= (struct tx_cmd
*) ptr
;
1049 struct sk_buff
*skb
= tx_cmd
->skb
;
1051 if ((ptr
->status
) & STAT_OK
) {
1053 print_eth(skb
->data
);
1055 lp
->stats
.tx_errors
++;
1056 if ((ptr
->status
) & 0x0020)
1057 lp
->stats
.collisions
++;
1058 if (!((ptr
->status
) & 0x0040))
1059 lp
->stats
.tx_heartbeat_errors
++;
1060 if ((ptr
->status
) & 0x0400)
1061 lp
->stats
.tx_carrier_errors
++;
1062 if ((ptr
->status
) & 0x0800)
1063 lp
->stats
.collisions
++;
1064 if ((ptr
->status
) & 0x1000)
1065 lp
->stats
.tx_aborted_errors
++;
1070 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
1074 case CmdMulticastList
:
1076 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
1082 unsigned long status
= *((unsigned long *) (ptr
+ 1));
1084 if (status
& 0x8000) {
1086 printk("%s: link ok.\n", dev
->name
);
1088 if (status
& 0x4000)
1089 printk("%s: Transceiver problem.\n", dev
->name
);
1090 if (status
& 0x2000)
1091 printk("%s: Termination problem.\n", dev
->name
);
1092 if (status
& 0x1000)
1093 printk("%s: Short circuit.\n", dev
->name
);
1096 printk("%s: Time %ld.\n", dev
->name
, status
& 0x07ff);
1102 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
1103 /* Zap command so set_multicast_list() knows it is free */
1108 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
1110 lp
->last_cmd
= jiffies
;
1114 while ((ptr
!= (struct i596_cmd
*) I596_NULL
) && (ptr
!= lp
->cmd_tail
)) {
1115 ptr
->command
&= 0x1fff;
1116 ptr
= WSWAPcmd(ptr
->next
);
1119 if ((lp
->cmd_head
!= (struct i596_cmd
*) I596_NULL
) && (dev
->start
))
1120 ack_cmd
|= CUC_START
;
1121 lp
->scb
.cmd
= WSWAPcmd(lp
->cmd_head
);
1123 if ((status
& 0x1000) || (status
& 0x4000)) {
1124 if ((i596_debug
> 4) && (status
& 0x4000))
1125 printk("%s: i596 interrupt received a frame.\n", dev
->name
);
1126 /* Only RX_START if stopped - RGH 07-07-96 */
1127 if (status
& 0x1000) {
1129 ack_cmd
|= RX_START
;
1131 printk("%s: i596 interrupt receive unit inactive %x.\n", dev
->name
, status
& 0x00f0);
1135 /* acknowledge the interrupt */
1137 /* COMMENTED OUT <<<<<
1138 if ((lp->scb.cmd != (struct i596_cmd *) I596_NULL) && (dev->start))
1139 ack_cmd |= CUC_START;
1142 while (lp
->scb
.command
)
1143 if (--boguscnt
== 0) {
1144 printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
1147 lp
->scb
.command
= ack_cmd
;
1149 #ifdef CONFIG_MVME16x_NET
1150 if (MACH_IS_MVME16x
) {
1151 /* Ack the interrupt */
1153 volatile unsigned char *pcc2
= (unsigned char *) 0xfff42000;
1158 #ifdef CONFIG_BVME6000_NET
1159 if (MACH_IS_BVME6000
) {
1160 volatile unsigned char *ethirq
= (unsigned char *) BVME_ETHIRQ_REG
;
1166 #ifdef CONFIG_APRICOT_INTEL
1167 (void) inb(ioaddr
+ 0x10);
1168 outb(4, ioaddr
+ 0xf);
1173 printk("%s: exiting interrupt.\n", dev
->name
);
1179 static int i596_close(struct device
*dev
)
1181 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
1182 int boguscnt
= 2000;
1183 unsigned long flags
;
1189 printk("%s: Shutting down ethercard, status was %4.4x.\n",
1190 dev
->name
, lp
->scb
.status
);
1195 while (lp
->scb
.command
)
1196 if (--boguscnt
== 0) {
1197 printk("%s: close1 timed out with status %4.4x, cmd %4.4x.\n",
1198 dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
1201 lp
->scb
.command
= CUC_ABORT
| RX_ABORT
;
1206 while (lp
->scb
.command
)
1207 if (--boguscnt
== 0) {
1208 printk("%s: close2 timed out with status %4.4x, cmd %4.4x.\n",
1209 dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
1212 restore_flags(flags
);
1214 i596_cleanup_cmd(lp
);
1216 #ifdef CONFIG_MVME16x_NET
1217 if (MACH_IS_MVME16x
) {
1218 volatile unsigned char *pcc2
= (unsigned char *) 0xfff42000;
1220 /* Disable all ints */
1223 pcc2
[0x2b] = 0x40; /* Set snooping bits now! */
1226 #ifdef CONFIG_BVME6000_NET
1227 if (MACH_IS_BVME6000
) {
1228 volatile unsigned char *ethirq
= (unsigned char *) BVME_ETHIRQ_REG
;
1234 free_irq(dev
->irq
, dev
);
1235 remove_rx_bufs(dev
);
1241 static struct net_device_stats
*
1242 i596_get_stats(struct device
*dev
)
1244 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
1250 * Set or clear the multicast filter for this adaptor.
1253 static void set_multicast_list(struct device
*dev
)
1255 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
1256 struct i596_cmd
*cmd
;
1260 printk("%s: set multicast list, %d entries, promisc %s, allmulti %s\n", dev
->name
, dev
->mc_count
, dev
->flags
& IFF_PROMISC
? "ON" : "OFF", dev
->flags
& IFF_ALLMULTI
? "ON" : "OFF");
1262 if ((dev
->flags
& IFF_PROMISC
) && !(lp
->i596_config
[8] & 0x01)) {
1263 lp
->i596_config
[8] |= 0x01;
1266 if (!(dev
->flags
& IFF_PROMISC
) && (lp
->i596_config
[8] & 0x01)) {
1267 lp
->i596_config
[8] &= ~0x01;
1270 if ((dev
->flags
& IFF_ALLMULTI
) && (lp
->i596_config
[11] & 0x20)) {
1271 lp
->i596_config
[11] &= ~0x20;
1274 if (!(dev
->flags
& IFF_ALLMULTI
) && !(lp
->i596_config
[11] & 0x20)) {
1275 lp
->i596_config
[11] |= 0x20;
1279 if (lp
->set_conf
.command
)
1280 printk("%s: config change request already queued\n",
1283 lp
->set_conf
.command
= CmdConfigure
;
1284 i596_add_cmd(dev
, &lp
->set_conf
);
1287 if (dev
->mc_count
> 0) {
1288 struct dev_mc_list
*dmi
;
1290 cmd
= (struct i596_cmd
*) kmalloc(sizeof(struct i596_cmd
) + 2 + dev
->mc_count
* 6, GFP_ATOMIC
);
1292 printk("%s: set_multicast Memory squeeze.\n", dev
->name
);
1295 cmd
->command
= CmdMulticastList
;
1296 *((unsigned short *) (cmd
+ 1)) = dev
->mc_count
* 6;
1297 cp
= ((unsigned char *) (cmd
+ 1)) + 2;
1298 for (dmi
= dev
->mc_list
; dmi
!= NULL
; dmi
= dmi
->next
) {
1299 memcpy(cp
, dmi
->dmi_addr
, 6);
1301 printk("%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n", dev
->name
, *(cp
+ 0), *(cp
+ 1), *(cp
+ 2), *(cp
+ 3), *(cp
+ 4), *(cp
+ 5));
1305 print_eth(((char *) (cmd
+ 1)) + 2);
1306 i596_add_cmd(dev
, cmd
);
1311 static unsigned int i596_portlist
[] __initdata
=
1313 struct netdev_entry i596_drv
=
1314 {"apricot", i82596_probe
, I596_TOTAL_SIZE
, apricot_portlist
};
1318 static char devicename
[9] =
1320 static struct device dev_apricot
=
1322 devicename
, /* device name inserted by /linux/drivers/net/net_init.c */
1325 0, 0, 0, NULL
, i82596_probe
};
1327 static int io
= 0x300;
1328 static int irq
= 10;
1329 MODULE_PARM(irq
, "i");
1331 int init_module(void)
1333 dev_apricot
.base_addr
= io
;
1334 dev_apricot
.irq
= irq
;
1335 if (register_netdev(&dev_apricot
) != 0)
1340 void cleanup_module(void)
1342 unregister_netdev(&dev_apricot
);
1343 kfree((void *) dev_apricot
.mem_start
);
1344 dev_apricot
.priv
= NULL
;
1346 /* If we don't do this, we can't re-insmod it later. */
1347 release_region(dev_apricot
.base_addr
, I596_TOTAL_SIZE
);
1354 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 82596.c"