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_ALLOC_SKB
107 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
108 #define kfree_skbmem(buff, size) kfree_s(buff,size)
111 #define APRICOT_DEBUG 2
114 int i596_debug
= APRICOT_DEBUG
;
119 #define I596_TOTAL_SIZE 17
123 #define CMD_EOL 0x8000 /* The last command of the list, stop. */
124 #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
125 #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
127 #define CMD_FLEX 0x0008 /* Enable flexible memory model */
130 CmdNOp
= 0, CmdSASetup
= 1, CmdConfigure
= 2, CmdMulticastList
= 3,
131 CmdTx
= 4, CmdTDR
= 5, CmdDump
= 6, CmdDiagnose
= 7
134 #define STAT_C 0x8000 /* Set to 0 after execution */
135 #define STAT_B 0x4000 /* Command being executed */
136 #define STAT_OK 0x2000 /* Command executed ok */
137 #define STAT_A 0x1000 /* Command aborted */
139 #define CUC_START 0x0100
140 #define CUC_RESUME 0x0200
141 #define CUC_SUSPEND 0x0300
142 #define CUC_ABORT 0x0400
143 #define RX_START 0x0010
144 #define RX_RESUME 0x0020
145 #define RX_SUSPEND 0x0030
146 #define RX_ABORT 0x0040
149 unsigned short porthi
;
150 unsigned short portlo
;
155 unsigned short status
;
156 unsigned short command
;
157 struct i596_cmd
*next
;
161 #define SIZE_MASK 0x3fff
166 struct i596_tbd
*next
;
172 struct i596_tbd
*tbd
;
175 struct sk_buff
*skb
; /* So we can free it after tx */
181 struct i596_rfd
*next
;
183 unsigned short count
;
188 #define RX_RING_SIZE 16
191 unsigned short status
;
192 unsigned short command
;
193 struct i596_cmd
*cmd
;
194 struct i596_rfd
*rfd
;
195 unsigned long crc_err
;
196 unsigned long align_err
;
197 unsigned long resource_err
;
198 unsigned long over_err
;
199 unsigned long rcvdt_err
;
200 unsigned long short_err
;
202 unsigned short t_off
;
207 struct i596_scb
*scb
;
211 unsigned long sysbus
;
213 struct i596_iscp
*iscp
;
216 struct i596_private
{
217 volatile struct i596_scp scp
;
218 volatile struct i596_iscp iscp
;
219 volatile struct i596_scb scb
;
220 struct i596_cmd set_add
;
222 struct i596_cmd set_conf
;
223 char i596_config
[16];
226 int last_restart
__attribute__((aligned(4)));
227 struct i596_rfd
*rx_tail
;
228 struct i596_cmd
*cmd_tail
;
229 struct i596_cmd
*cmd_head
;
231 unsigned long last_cmd
;
232 struct net_device_stats stats
;
237 0x8E, /* length, prefetch on */
238 0xC8, /* fifo to 8, monitor off */
240 0xc0, /* don't save bad frames */
242 0x80, /* don't save bad frames */
244 0x2E, /* No source address insertion, 8 byte preamble */
245 0x00, /* priority and backoff defaults */
246 0x60, /* interframe spacing */
247 0x00, /* slot time LSB */
248 0xf2, /* slot time and retries */
249 0x00, /* promiscuous mode */
250 0x00, /* collision detect */
251 0x40, /* minimum frame length */
254 0x7f /* *multi IA */ };
256 static int i596_open(struct net_device
*dev
);
257 static int i596_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
258 static void i596_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
259 static int i596_close(struct net_device
*dev
);
260 static struct net_device_stats
*i596_get_stats(struct net_device
*dev
);
261 static void i596_add_cmd(struct net_device
*dev
, struct i596_cmd
*cmd
);
262 static void print_eth(char *);
263 static void set_multicast_list(struct net_device
*dev
);
265 static int ticks_limit
= 25;
266 static int max_cmd_backlog
= 16;
269 static inline void CA(struct net_device
*dev
)
271 #ifdef CONFIG_MVME16x_NET
272 if (MACH_IS_MVME16x
) {
273 ((struct i596_reg
*) dev
->base_addr
)->ca
= 1;
276 #ifdef CONFIG_BVME6000_NET
277 if (MACH_IS_BVME6000
) {
278 volatile u32 i
= *(volatile u32
*) (dev
->base_addr
);
281 #ifdef CONFIG_APRICOT_i596
282 if (MACH_IS_APRICOT
) {
283 outw(0, (short) (dev
->base_addr
) + 4);
289 static inline void MPU_PORT(struct net_device
*dev
, int c
, volatile void *x
)
291 #ifdef CONFIG_MVME16x_NET
292 if (MACH_IS_MVME16x
) {
293 struct i596_reg
*p
= (struct i596_reg
*) (dev
->base_addr
);
294 p
->porthi
= ((c
) | (u32
) (x
)) & 0xffff;
295 p
->portlo
= ((c
) | (u32
) (x
)) >> 16;
298 #ifdef CONFIG_BVME6000_NET
299 if (MACH_IS_BVME6000
) {
300 u32 v
= (u32
) (c
) | (u32
) (x
);
301 v
= ((u32
) (v
) << 16) | ((u32
) (v
) >> 16);
302 *(volatile u32
*) dev
->base_addr
= v
;
304 *(volatile u32
*) dev
->base_addr
= v
;
310 #if defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET)
311 static void i596_error(int irq
, void *dev_id
, struct pt_regs
*regs
)
313 struct net_device
*dev
= dev_id
;
314 struct i596_cmd
*cmd
;
316 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
317 printk("i596_error: lp = 0x%08x\n", (u32
) lp
);
318 printk("scp at %08x, .sysbus = %08x, .iscp = %08x\n",
319 (u32
) & lp
->scp
, (u32
) lp
->scp
.sysbus
, (u32
) lp
->scp
.iscp
);
320 printk("iscp at %08x, .stat = %08x, .scb = %08x\n",
321 (u32
) & lp
->iscp
, (u32
) lp
->iscp
.stat
, (u32
) lp
->iscp
.scb
);
322 printk("scb at %08x, .status = %04x, .command = %04x\n",
323 (u32
) & lp
->scb
, lp
->scb
.status
, lp
->scb
.command
);
324 printk(" .cmd = %08x, .rfd = %08x\n", (u32
) lp
->scb
.cmd
,
326 cmd
= WSWAPcmd(lp
->scb
.cmd
);
327 while (cmd
&& (u32
) cmd
< 0x1000000) {
328 printk("cmd at %08x, .status = %04x, .command = %04x, .next = %08x\n",
329 (u32
) cmd
, cmd
->status
, cmd
->command
, (u32
) cmd
->next
);
330 cmd
= WSWAPcmd(cmd
->next
);
336 static inline int init_rx_bufs(struct net_device
*dev
, int num
)
338 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
340 struct i596_rfd
*rfd
;
342 lp
->scb
.rfd
= (struct i596_rfd
*) I596_NULL
;
345 printk("%s: init_rx_bufs %d.\n", dev
->name
, num
);
347 for (i
= 0; i
< num
; i
++) {
348 if (!(rfd
= (struct i596_rfd
*) kmalloc(sizeof(struct i596_rfd
), GFP_KERNEL
)))
352 rfd
->rbd
= I596_NULL
;
361 rfd
->next
= lp
->scb
.rfd
;
362 lp
->scb
.rfd
= WSWAPrfd(rfd
);
366 lp
->rx_tail
->next
= lp
->scb
.rfd
;
371 static inline void remove_rx_bufs(struct net_device
*dev
)
373 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
374 struct i596_rfd
*rfd
= WSWAPrfd(lp
->scb
.rfd
);
376 lp
->rx_tail
->next
= (struct i596_rfd
*) I596_NULL
;
379 lp
->scb
.rfd
= rfd
->next
;
381 rfd
= WSWAPrfd(lp
->scb
.rfd
);
383 while (rfd
!= lp
->rx_tail
);
386 static inline void init_i596_mem(struct net_device
*dev
)
388 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
389 #if !defined(CONFIG_MVME16x_NET) && !defined(CONFIG_BVME6000_NET)
390 short ioaddr
= dev
->base_addr
;
392 int boguscnt
= 100000;
395 #if defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET)
396 #ifdef CONFIG_MVME16x_NET
397 if (MACH_IS_MVME16x
) {
398 volatile unsigned char *pcc2
= (unsigned char *) 0xfff42000;
400 /* Disable all ints for now */
403 pcc2
[0x2b] = 0x40; /* Set snooping bits now! */
406 #ifdef CONFIG_BVME6000_NET
407 if (MACH_IS_BVME6000
) {
408 volatile unsigned char *ethirq
= (unsigned char *) BVME_ETHIRQ_REG
;
414 MPU_PORT(dev
, PORT_RESET
, 0);
416 udelay(100); /* Wait 100us - seems to help */
418 /* change the scp address */
420 MPU_PORT(dev
, PORT_ALTSCP
, &lp
->scp
);
424 /* change the scp address */
427 outb(4, ioaddr
+ 0xf);
428 outw(((((int) &lp
->scp
) & 0xffff) | 2), ioaddr
);
429 outw((((int) &lp
->scp
) >> 16) & 0xffff, ioaddr
);
432 lp
->last_cmd
= jiffies
;
434 #ifdef CONFIG_MVME16x_NET
436 lp
->scp
.sysbus
= 0x00000054;
438 #ifdef CONFIG_BVME6000_NET
439 if (MACH_IS_BVME6000
)
440 lp
->scp
.sysbus
= 0x0000004c;
442 #ifdef CONFIG_APRICOT_i596
444 lp
->scp
.sysbus
= 0x00440000;
447 lp
->scp
.iscp
= WSWAPiscp(&(lp
->iscp
));
448 lp
->iscp
.scb
= WSWAPscb(&(lp
->scb
));
449 lp
->iscp
.stat
= ISCP_BUSY
;
452 lp
->cmd_head
= lp
->scb
.cmd
= (struct i596_cmd
*) I596_NULL
;
455 printk("%s: starting i82596.\n", dev
->name
);
457 #if !defined(CONFIG_MVME16x_NET) && !defined(CONFIG_BVME6000_NET)
458 (void) inb(ioaddr
+ 0x10);
459 outb(4, ioaddr
+ 0xf);
463 while (lp
->iscp
.stat
)
464 if (--boguscnt
== 0) {
465 printk("%s: i82596 initialization timed out with status %4.4x, cmd %4.4x.\n",
466 dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
471 #ifdef CONFIG_MVME16x_NET
472 if (MACH_IS_MVME16x
) {
473 volatile unsigned char *pcc2
= (unsigned char *) 0xfff42000;
475 /* Enable ints, etc. now */
477 pcc2
[0x2a] = 0x55; /* Edge sensitive */
481 #ifdef CONFIG_BVME6000_NET
482 if (MACH_IS_BVME6000
) {
483 volatile unsigned char *ethirq
= (unsigned char *) BVME_ETHIRQ_REG
;
489 memcpy(lp
->i596_config
, init_setup
, 14);
490 lp
->set_conf
.command
= CmdConfigure
;
491 i596_add_cmd(dev
, &lp
->set_conf
);
493 memcpy(lp
->eth_addr
, dev
->dev_addr
, 6);
494 lp
->set_add
.command
= CmdSASetup
;
495 i596_add_cmd(dev
, &lp
->set_add
);
497 lp
->tdr
.command
= CmdTDR
;
498 i596_add_cmd(dev
, &lp
->tdr
);
505 while (lp
->scb
.command
)
506 if (--boguscnt
== 0) {
507 printk("%s: receive unit start timed out with status %4.4x, cmd %4.4x.\n",
508 dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
511 lp
->scb
.command
= RX_START
;
514 restore_flags(flags
);
517 while (lp
->scb
.command
)
518 if (--boguscnt
== 0) {
519 printk("i82596 init timed out with status %4.4x, cmd %4.4x.\n",
520 lp
->scb
.status
, lp
->scb
.command
);
526 static inline int i596_rx(struct net_device
*dev
)
528 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
529 struct i596_rfd
*rfd
;
533 printk("i596_rx()\n");
535 rfd
= WSWAPrfd(lp
->scb
.rfd
); /* Reference next frame descriptor to check */
537 while ((rfd
->stat
) & STAT_C
) { /* Loop while we have complete frames */
539 print_eth(rfd
->data
);
541 if ((rfd
->stat
) & STAT_OK
) {
543 int pkt_len
= rfd
->count
& 0x3fff;
544 struct sk_buff
*skb
= dev_alloc_skb(pkt_len
);
549 printk("%s: i596_rx Memory squeeze, dropping packet.\n", dev
->name
);
550 lp
->stats
.rx_dropped
++;
553 memcpy(skb_put(skb
, pkt_len
), rfd
->data
, pkt_len
);
554 skb
->protocol
= eth_type_trans(skb
, dev
);
556 lp
->stats
.rx_packets
++;
557 lp
->stats
.rx_bytes
+= pkt_len
;
560 lp
->stats
.rx_errors
++;
561 if ((rfd
->stat
) & 0x0001)
562 lp
->stats
.collisions
++;
563 if ((rfd
->stat
) & 0x0080)
564 lp
->stats
.rx_length_errors
++;
565 if ((rfd
->stat
) & 0x0100)
566 lp
->stats
.rx_over_errors
++;
567 if ((rfd
->stat
) & 0x0200)
568 lp
->stats
.rx_fifo_errors
++;
569 if ((rfd
->stat
) & 0x0400)
570 lp
->stats
.rx_frame_errors
++;
571 if ((rfd
->stat
) & 0x0800)
572 lp
->stats
.rx_crc_errors
++;
573 if ((rfd
->stat
) & 0x1000)
574 lp
->stats
.rx_length_errors
++;
577 /* Clear the buffer descriptor count and EOF + F flags */
582 lp
->rx_tail
->cmd
= 0;
584 lp
->scb
.rfd
= rfd
->next
;
585 rfd
= WSWAPrfd(lp
->scb
.rfd
); /* Next frame descriptor to check */
589 printk("frames %d\n", frames
);
594 static inline void i596_cleanup_cmd(struct i596_private
*lp
)
596 struct i596_cmd
*ptr
;
600 printk("i596_cleanup_cmd\n");
602 while (lp
->cmd_head
!= (struct i596_cmd
*) I596_NULL
) {
605 lp
->cmd_head
= WSWAPcmd(lp
->cmd_head
->next
);
608 switch ((ptr
->command
) & 0x7) {
611 struct tx_cmd
*tx_cmd
= (struct tx_cmd
*) ptr
;
612 struct sk_buff
*skb
= tx_cmd
->skb
;
616 lp
->stats
.tx_errors
++;
617 lp
->stats
.tx_aborted_errors
++;
619 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
623 case CmdMulticastList
:
625 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
630 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
634 while (lp
->scb
.command
)
635 if (--boguscnt
== 0) {
636 printk("i596_cleanup_cmd timed out with status %4.4x, cmd %4.4x.\n",
637 lp
->scb
.status
, lp
->scb
.command
);
640 lp
->scb
.cmd
= WSWAPcmd(lp
->cmd_head
);
643 static inline void i596_reset(struct net_device
*dev
, struct i596_private
*lp
, int ioaddr
)
649 printk("i596_reset\n");
654 while (lp
->scb
.command
)
655 if (--boguscnt
== 0) {
656 printk("i596_reset timed out with status %4.4x, cmd %4.4x.\n",
657 lp
->scb
.status
, lp
->scb
.command
);
663 lp
->scb
.command
= CUC_ABORT
| RX_ABORT
;
666 /* wait for shutdown */
669 while (lp
->scb
.command
)
670 if (--boguscnt
== 0) {
671 printk("i596_reset 2 timed out with status %4.4x, cmd %4.4x.\n",
672 lp
->scb
.status
, lp
->scb
.command
);
675 restore_flags(flags
);
677 i596_cleanup_cmd(lp
);
686 static void i596_add_cmd(struct net_device
*dev
, struct i596_cmd
*cmd
)
688 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
689 int ioaddr
= dev
->base_addr
;
694 printk("i596_add_cmd\n");
697 cmd
->command
|= (CMD_EOL
| CMD_INTR
);
698 cmd
->next
= (struct i596_cmd
*) I596_NULL
;
703 * RGH 300597: Looks to me like there could be a race condition
704 * here. Just because we havn't picked up all the command items
705 * yet, doesn't mean that the 82596 hasn't finished processing
706 * them. So, we may need to do a CUC_START anyway.
707 * Maybe not. If it interrupts saying the CU is idle when there
708 * is still something in the cmd queue, the int handler with restart
712 if (lp
->cmd_head
!= (struct i596_cmd
*) I596_NULL
) {
713 lp
->cmd_tail
->next
= WSWAPcmd(cmd
);
716 while (lp
->scb
.command
)
717 if (--boguscnt
== 0) {
718 printk("i596_add_cmd timed out with status %4.4x, cmd %4.4x.\n",
719 lp
->scb
.status
, lp
->scb
.command
);
722 lp
->scb
.cmd
= WSWAPcmd(cmd
);
723 lp
->scb
.command
= CUC_START
;
729 lp
->cmd_head
= WSWAPcmd(lp
->scb
.cmd
); /* Is this redundant? RGH 300597 */
730 restore_flags(flags
);
732 if (lp
->cmd_backlog
> max_cmd_backlog
) {
733 unsigned long tickssofar
= jiffies
- lp
->last_cmd
;
735 if (tickssofar
< ticks_limit
)
738 printk("%s: command unit timed out, status resetting.\n", dev
->name
);
740 i596_reset(dev
, lp
, ioaddr
);
744 static int i596_open(struct net_device
*dev
)
749 printk("%s: i596_open() irq %d.\n", dev
->name
, dev
->irq
);
751 if (request_irq(dev
->irq
, &i596_interrupt
, 0, "apricot", dev
))
753 #ifdef CONFIG_MVME16x_NET
754 if (MACH_IS_MVME16x
) {
755 if (request_irq(0x56, &i596_error
, 0, "apricot_error", dev
))
759 if ((i
= init_rx_bufs(dev
, RX_RING_SIZE
)) < RX_RING_SIZE
)
760 printk("%s: only able to allocate %d receive buffers\n", dev
->name
, i
);
763 free_irq(dev
->irq
, dev
);
771 /* Initialize the 82596 memory */
774 return 0; /* Always succeed */
777 static int i596_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
779 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
780 int ioaddr
= dev
->base_addr
;
781 struct tx_cmd
*tx_cmd
;
784 printk("%s: 82596 start xmit\n", dev
->name
);
786 /* Transmitter timeout, serious problems. */
788 int tickssofar
= jiffies
- dev
->trans_start
;
791 printk("%s: transmit timed out, status resetting.\n",
793 lp
->stats
.tx_errors
++;
794 /* Try to restart the adaptor */
795 if (lp
->last_restart
== lp
->stats
.tx_packets
) {
797 printk("Resetting board.\n");
799 /* Shutdown and restart */
800 i596_reset(dev
, lp
, ioaddr
);
802 /* Issue a channel attention signal */
804 printk("Kicking board.\n");
805 lp
->scb
.command
= CUC_START
| RX_START
;
807 lp
->last_restart
= lp
->stats
.tx_packets
;
810 dev
->trans_start
= jiffies
;
813 printk("%s: i596_start_xmit() called\n", dev
->name
);
815 /* Block a timer-based transmit from overlapping. This could better be
816 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
817 if (test_and_set_bit(0, (void *) &dev
->tbusy
) != 0)
818 printk("%s: Transmitter access conflict.\n", dev
->name
);
820 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
821 dev
->trans_start
= jiffies
;
823 tx_cmd
= (struct tx_cmd
*) kmalloc((sizeof(struct tx_cmd
) + sizeof(struct i596_tbd
)), GFP_ATOMIC
);
824 if (tx_cmd
== NULL
) {
825 printk("%s: i596_xmit Memory squeeze, dropping packet.\n", dev
->name
);
826 lp
->stats
.tx_dropped
++;
830 struct i596_tbd
*tbd
= (struct i596_tbd
*) (tx_cmd
+ 1);
831 tx_cmd
->tbd
= WSWAPtbd(tbd
);
832 tbd
->next
= (struct i596_tbd
*) I596_NULL
;
834 tx_cmd
->cmd
.command
= CMD_FLEX
| CmdTx
;
840 tbd
->size
= EOF
| length
;
842 tbd
->data
= WSWAPchar(skb
->data
);
845 print_eth(skb
->data
);
846 i596_add_cmd(dev
, (struct i596_cmd
*) tx_cmd
);
848 lp
->stats
.tx_packets
++;
849 lp
->stats
.tx_bytes
+= length
;
859 static void print_eth(char *add
)
863 printk("print_eth(%08x)\n", (unsigned int) add
);
865 for (i
= 0; i
< 6; i
++)
866 printk(" %2.2X", (unsigned char) add
[i
]);
870 for (i
= 0; i
< 6; i
++)
871 printk(" %2.2X", (unsigned char) add
[i
+ 6]);
873 printk("type %2.2X%2.2X\n", (unsigned char) add
[12], (unsigned char) add
[13]);
876 int __init
i82596_probe(struct net_device
*dev
)
879 struct i596_private
*lp
;
882 #ifdef CONFIG_MVME16x_NET
883 if (MACH_IS_MVME16x
) {
884 static int probed
= 0;
886 if (mvme16x_config
& MVME16x_CONFIG_NO_ETHERNET
) {
887 printk("Ethernet probe disabled - chip not present\n");
893 memcpy(eth_addr
, (void *) 0xfffc1f2c, 6); /* YUCK! Get addr from NOVRAM */
894 dev
->base_addr
= MVME_I596_BASE
;
895 dev
->irq
= (unsigned) MVME16x_IRQ_I596
;
898 #ifdef CONFIG_BVME6000_NET
899 if (MACH_IS_BVME6000
) {
900 volatile unsigned char *rtc
= (unsigned char *) BVME_RTC_BASE
;
901 unsigned char msr
= rtc
[3];
905 for (i
= 0; i
< 6; i
++)
906 eth_addr
[i
] = rtc
[i
* 4 + 7]; /* Stored in RTC RAM at offset 1 */
908 dev
->base_addr
= BVME_I596_BASE
;
909 dev
->irq
= (unsigned) BVME_IRQ_I596
;
912 #ifdef CONFIG_APRICOT_INTEL
916 /* this is easy the ethernet interface can only be at 0x300 */
917 /* first check nothing is already registered here */
919 if (check_region(ioaddr
, I596_TOTAL_SIZE
))
922 for (i
= 0; i
< 8; i
++) {
923 eth_addr
[i
] = inb(ioaddr
+ 8 + i
);
924 checksum
+= eth_addr
[i
];
927 /* checksum is a multiple of 0x100, got this wrong first time
928 some machines have 0x100, some 0x200. The DOS driver doesn't
929 even bother with the checksum */
931 if (checksum
% 0x100)
934 /* Some other boards trip the checksum.. but then appear as ether
935 address 0. Trap these - AC */
937 if (memcmp(eth_addr
, "\x00\x00\x49", 3) != 0)
940 request_region(ioaddr
, I596_TOTAL_SIZE
, "i596");
942 dev
->base_addr
= ioaddr
;
946 printk("%s: 82596 at %#3lx,", dev
->name
, dev
->base_addr
);
948 for (i
= 0; i
< 6; i
++)
949 printk(" %2.2X", dev
->dev_addr
[i
] = eth_addr
[i
]);
951 printk(" IRQ %d.\n", dev
->irq
);
956 /* The APRICOT-specific entries in the device structure. */
957 dev
->open
= &i596_open
;
958 dev
->stop
= &i596_close
;
959 dev
->hard_start_xmit
= &i596_start_xmit
;
960 dev
->get_stats
= &i596_get_stats
;
961 dev
->set_multicast_list
= &set_multicast_list
;
963 dev
->mem_start
= (int) kmalloc(sizeof(struct i596_private
) + 0x0f, GFP_KERNEL
);
965 dev
->priv
= (void *) ((dev
->mem_start
+ 0xf) & 0xfffffff0);
967 lp
= (struct i596_private
*) dev
->priv
;
969 printk("%s: lp at 0x%08lx, lp->scb at 0x%08lx\n"
970 ,dev
->name
, (unsigned long) lp
, (unsigned long) &lp
->scb
);
971 memset((void *) lp
, 0, sizeof(struct i596_private
));
973 lp
->scb
.cmd
= (struct i596_cmd
*) I596_NULL
;
974 lp
->scb
.rfd
= (struct i596_rfd
*) I596_NULL
;
979 static void i596_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
981 struct net_device
*dev
= dev_id
;
982 struct i596_private
*lp
;
985 unsigned short status
, ack_cmd
= 0;
987 #ifdef CONFIG_BVME6000_NET
988 if (MACH_IS_BVME6000
) {
989 if (*(char *) BVME_LOCAL_IRQ_STAT
& BVME_ETHERR
) {
990 i596_error(BVME_IRQ_I596
, NULL
, NULL
);
996 printk("i596_interrupt(): irq %d for unknown device.\n", irq
);
1000 printk("%s: i596_interrupt(): irq %d\n", dev
->name
, irq
);
1003 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
1007 ioaddr
= dev
->base_addr
;
1009 lp
= (struct i596_private
*) dev
->priv
;
1011 while (lp
->scb
.command
)
1012 if (--boguscnt
== 0) {
1013 printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
1016 status
= lp
->scb
.status
;
1019 printk("%s: i596 interrupt, status %4.4x.\n", dev
->name
, status
);
1021 ack_cmd
= status
& 0xf000;
1023 if ((status
& 0x8000) || (status
& 0x2000)) {
1024 struct i596_cmd
*ptr
;
1026 if ((i596_debug
> 4) && (status
& 0x8000))
1027 printk("%s: i596 interrupt completed command.\n", dev
->name
);
1028 if ((i596_debug
> 4) && (status
& 0x2000))
1029 printk("%s: i596 interrupt command unit inactive %x.\n", dev
->name
, status
& 0x0700);
1031 while ((lp
->cmd_head
!= (struct i596_cmd
*) I596_NULL
) && (lp
->cmd_head
->status
& STAT_C
)) {
1035 printk("cmd_head->status = %04x, ->command = %04x\n",
1036 lp
->cmd_head
->status
, lp
->cmd_head
->command
);
1037 lp
->cmd_head
= WSWAPcmd(lp
->cmd_head
->next
);
1040 switch ((ptr
->command
) & 0x7) {
1043 struct tx_cmd
*tx_cmd
= (struct tx_cmd
*) ptr
;
1044 struct sk_buff
*skb
= tx_cmd
->skb
;
1046 if ((ptr
->status
) & STAT_OK
) {
1048 print_eth(skb
->data
);
1050 lp
->stats
.tx_errors
++;
1051 if ((ptr
->status
) & 0x0020)
1052 lp
->stats
.collisions
++;
1053 if (!((ptr
->status
) & 0x0040))
1054 lp
->stats
.tx_heartbeat_errors
++;
1055 if ((ptr
->status
) & 0x0400)
1056 lp
->stats
.tx_carrier_errors
++;
1057 if ((ptr
->status
) & 0x0800)
1058 lp
->stats
.collisions
++;
1059 if ((ptr
->status
) & 0x1000)
1060 lp
->stats
.tx_aborted_errors
++;
1065 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
1069 case CmdMulticastList
:
1071 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
1077 unsigned long status
= *((unsigned long *) (ptr
+ 1));
1079 if (status
& 0x8000) {
1081 printk("%s: link ok.\n", dev
->name
);
1083 if (status
& 0x4000)
1084 printk("%s: Transceiver problem.\n", dev
->name
);
1085 if (status
& 0x2000)
1086 printk("%s: Termination problem.\n", dev
->name
);
1087 if (status
& 0x1000)
1088 printk("%s: Short circuit.\n", dev
->name
);
1091 printk("%s: Time %ld.\n", dev
->name
, status
& 0x07ff);
1097 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
1098 /* Zap command so set_multicast_list() knows it is free */
1103 ptr
->next
= (struct i596_cmd
*) I596_NULL
;
1105 lp
->last_cmd
= jiffies
;
1109 while ((ptr
!= (struct i596_cmd
*) I596_NULL
) && (ptr
!= lp
->cmd_tail
)) {
1110 ptr
->command
&= 0x1fff;
1111 ptr
= WSWAPcmd(ptr
->next
);
1114 if ((lp
->cmd_head
!= (struct i596_cmd
*) I596_NULL
) && (dev
->start
))
1115 ack_cmd
|= CUC_START
;
1116 lp
->scb
.cmd
= WSWAPcmd(lp
->cmd_head
);
1118 if ((status
& 0x1000) || (status
& 0x4000)) {
1119 if ((i596_debug
> 4) && (status
& 0x4000))
1120 printk("%s: i596 interrupt received a frame.\n", dev
->name
);
1121 /* Only RX_START if stopped - RGH 07-07-96 */
1122 if (status
& 0x1000) {
1124 ack_cmd
|= RX_START
;
1126 printk("%s: i596 interrupt receive unit inactive %x.\n", dev
->name
, status
& 0x00f0);
1130 /* acknowledge the interrupt */
1132 /* COMMENTED OUT <<<<<
1133 if ((lp->scb.cmd != (struct i596_cmd *) I596_NULL) && (dev->start))
1134 ack_cmd |= CUC_START;
1137 while (lp
->scb
.command
)
1138 if (--boguscnt
== 0) {
1139 printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
1142 lp
->scb
.command
= ack_cmd
;
1144 #ifdef CONFIG_MVME16x_NET
1145 if (MACH_IS_MVME16x
) {
1146 /* Ack the interrupt */
1148 volatile unsigned char *pcc2
= (unsigned char *) 0xfff42000;
1153 #ifdef CONFIG_BVME6000_NET
1154 if (MACH_IS_BVME6000
) {
1155 volatile unsigned char *ethirq
= (unsigned char *) BVME_ETHIRQ_REG
;
1161 #ifdef CONFIG_APRICOT_INTEL
1162 (void) inb(ioaddr
+ 0x10);
1163 outb(4, ioaddr
+ 0xf);
1168 printk("%s: exiting interrupt.\n", dev
->name
);
1174 static int i596_close(struct net_device
*dev
)
1176 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
1177 int boguscnt
= 2000;
1178 unsigned long flags
;
1184 printk("%s: Shutting down ethercard, status was %4.4x.\n",
1185 dev
->name
, lp
->scb
.status
);
1190 while (lp
->scb
.command
)
1191 if (--boguscnt
== 0) {
1192 printk("%s: close1 timed out with status %4.4x, cmd %4.4x.\n",
1193 dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
1196 lp
->scb
.command
= CUC_ABORT
| RX_ABORT
;
1201 while (lp
->scb
.command
)
1202 if (--boguscnt
== 0) {
1203 printk("%s: close2 timed out with status %4.4x, cmd %4.4x.\n",
1204 dev
->name
, lp
->scb
.status
, lp
->scb
.command
);
1207 restore_flags(flags
);
1209 i596_cleanup_cmd(lp
);
1211 #ifdef CONFIG_MVME16x_NET
1212 if (MACH_IS_MVME16x
) {
1213 volatile unsigned char *pcc2
= (unsigned char *) 0xfff42000;
1215 /* Disable all ints */
1218 pcc2
[0x2b] = 0x40; /* Set snooping bits now! */
1221 #ifdef CONFIG_BVME6000_NET
1222 if (MACH_IS_BVME6000
) {
1223 volatile unsigned char *ethirq
= (unsigned char *) BVME_ETHIRQ_REG
;
1229 free_irq(dev
->irq
, dev
);
1230 remove_rx_bufs(dev
);
1236 static struct net_device_stats
*
1237 i596_get_stats(struct net_device
*dev
)
1239 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
1245 * Set or clear the multicast filter for this adaptor.
1248 static void set_multicast_list(struct net_device
*dev
)
1250 struct i596_private
*lp
= (struct i596_private
*) dev
->priv
;
1251 struct i596_cmd
*cmd
;
1255 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");
1257 if ((dev
->flags
& IFF_PROMISC
) && !(lp
->i596_config
[8] & 0x01)) {
1258 lp
->i596_config
[8] |= 0x01;
1261 if (!(dev
->flags
& IFF_PROMISC
) && (lp
->i596_config
[8] & 0x01)) {
1262 lp
->i596_config
[8] &= ~0x01;
1265 if ((dev
->flags
& IFF_ALLMULTI
) && (lp
->i596_config
[11] & 0x20)) {
1266 lp
->i596_config
[11] &= ~0x20;
1269 if (!(dev
->flags
& IFF_ALLMULTI
) && !(lp
->i596_config
[11] & 0x20)) {
1270 lp
->i596_config
[11] |= 0x20;
1274 if (lp
->set_conf
.command
)
1275 printk("%s: config change request already queued\n",
1278 lp
->set_conf
.command
= CmdConfigure
;
1279 i596_add_cmd(dev
, &lp
->set_conf
);
1282 if (dev
->mc_count
> 0) {
1283 struct dev_mc_list
*dmi
;
1285 cmd
= (struct i596_cmd
*) kmalloc(sizeof(struct i596_cmd
) + 2 + dev
->mc_count
* 6, GFP_ATOMIC
);
1287 printk("%s: set_multicast Memory squeeze.\n", dev
->name
);
1290 cmd
->command
= CmdMulticastList
;
1291 *((unsigned short *) (cmd
+ 1)) = dev
->mc_count
* 6;
1292 cp
= ((unsigned char *) (cmd
+ 1)) + 2;
1293 for (dmi
= dev
->mc_list
; dmi
!= NULL
; dmi
= dmi
->next
) {
1294 memcpy(cp
, dmi
->dmi_addr
, 6);
1296 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));
1300 print_eth(((char *) (cmd
+ 1)) + 2);
1301 i596_add_cmd(dev
, cmd
);
1306 static unsigned int i596_portlist
[] __initdata
=
1308 struct netdev_entry i596_drv
=
1309 {"apricot", i82596_probe
, I596_TOTAL_SIZE
, apricot_portlist
};
1313 static char devicename
[9] =
1315 static struct net_device dev_apricot
=
1317 devicename
, /* device name inserted by /linux/drivers/net/net_init.c */
1320 0, 0, 0, NULL
, i82596_probe
};
1322 static int io
= 0x300;
1323 static int irq
= 10;
1324 MODULE_PARM(irq
, "i");
1326 int init_module(void)
1328 dev_apricot
.base_addr
= io
;
1329 dev_apricot
.irq
= irq
;
1330 if (register_netdev(&dev_apricot
) != 0)
1335 void cleanup_module(void)
1337 unregister_netdev(&dev_apricot
);
1338 kfree((void *) dev_apricot
.mem_start
);
1339 dev_apricot
.priv
= NULL
;
1341 /* If we don't do this, we can't re-insmod it later. */
1342 release_region(dev_apricot
.base_addr
, I596_TOTAL_SIZE
);
1349 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 82596.c"