26 #include <linux/module.h>
27 #include <linux/stddef.h>
28 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/errno.h>
35 #include <linux/netdevice.h>
38 #include <linux/bitops.h>
40 #include <asm/cacheflush.h>
41 #include <asm/setup.h>
44 #include <asm/pgtable.h>
46 #include <asm/idprom.h>
47 #include <asm/machines.h>
57 #define LANCE_OBIO 0x120000
58 #define LANCE_IRQ IRQ_AUTO_3
72 static int lance_debug = 1;
78 #define DPRINTK(n,a) \
80 if (lance_debug >= n) \
88 #define TX_LOG_RING_SIZE 3
89 #define RX_LOG_RING_SIZE 5
93 #define TX_RING_SIZE (1 << TX_LOG_RING_SIZE)
94 #define TX_RING_LEN_BITS (TX_LOG_RING_SIZE << 5)
95 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
97 #define RX_RING_SIZE (1 << RX_LOG_RING_SIZE)
98 #define RX_RING_LEN_BITS (RX_LOG_RING_SIZE << 5)
99 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
102 #define PKT_BUF_SZ 1544
105 #define PKTBUF_ADDR(head) (void *)((unsigned long)(MEM) | (head)->base)
111 volatile unsigned char flag;
119 volatile unsigned char flag;
162 #define DREG lp->iobase[0]
163 #define AREG lp->iobase[1]
164 #define REGA(a) (*( AREG = (a), &DREG ))
169 #define TMD1_ENP 0x01
170 #define TMD1_STP 0x02
171 #define TMD1_DEF 0x04
172 #define TMD1_ONE 0x08
173 #define TMD1_MORE 0x10
174 #define TMD1_ERR 0x40
175 #define TMD1_OWN 0x80
177 #define TMD1_OWN_CHIP TMD1_OWN
178 #define TMD1_OWN_HOST 0
181 #define TMD3_TDR 0x03FF
182 #define TMD3_RTRY 0x0400
183 #define TMD3_LCAR 0x0800
184 #define TMD3_LCOL 0x1000
185 #define TMD3_UFLO 0x4000
186 #define TMD3_BUFF 0x8000
189 #define RMD1_ENP 0x01
190 #define RMD1_STP 0x02
191 #define RMD1_BUFF 0x04
192 #define RMD1_CRC 0x08
193 #define RMD1_OFLO 0x10
194 #define RMD1_FRAM 0x20
195 #define RMD1_ERR 0x40
196 #define RMD1_OWN 0x80
198 #define RMD1_OWN_CHIP RMD1_OWN
199 #define RMD1_OWN_HOST 0
211 #define CSR0_INIT 0x0001
212 #define CSR0_STRT 0x0002
213 #define CSR0_STOP 0x0004
214 #define CSR0_TDMD 0x0008
215 #define CSR0_TXON 0x0010
216 #define CSR0_RXON 0x0020
217 #define CSR0_INEA 0x0040
218 #define CSR0_INTR 0x0080
219 #define CSR0_IDON 0x0100
220 #define CSR0_TINT 0x0200
221 #define CSR0_RINT 0x0400
222 #define CSR0_MERR 0x0800
223 #define CSR0_MISS 0x1000
224 #define CSR0_CERR 0x2000
225 #define CSR0_BABL 0x4000
226 #define CSR0_ERR 0x8000
229 #define CSR3_BCON 0x0001
230 #define CSR3_ACON 0x0002
231 #define CSR3_BSWP 0x0004
300 .ndo_set_rx_mode = set_multicast_list,
301 .ndo_set_mac_address =
NULL,
308 unsigned long ioaddr;
312 static int did_version;
313 volatile unsigned short *ioaddr_probe;
314 unsigned short tmp1, tmp2;
327 ioaddr_probe = (
volatile unsigned short *)ioaddr;
328 tmp1 = ioaddr_probe[0];
329 tmp2 = ioaddr_probe[1];
331 ioaddr_probe[1] =
CSR0;
335 ioaddr_probe[0] =
tmp1;
336 ioaddr_probe[1] = tmp2;
344 lp = netdev_priv(dev);
356 lp->
iobase = (
volatile unsigned short *)ioaddr;
372 printk(
"%s: SUN3 Lance at io %#lx, mem %#lx, irq %d, hwaddr ",
374 (
unsigned long)ioaddr,
379 for(i = 0; i < 6 ; i++)
392 MEM->init.mode = 0x0000;
393 MEM->init.filter[0] = 0x00000000;
394 MEM->init.filter[1] = 0x00000000;
402 DPRINTK(2, (
"initaddr: %08lx rx_ring: %08lx tx_ring: %08lx\n",
406 if (did_version++ == 0)
426 lance_init_ring(dev);
436 DPRINTK( 2, (
"lance_open(): opening %s failed, i=%d, csr0=%04x\n",
444 netif_start_queue(dev);
454 static void lance_init_ring(
struct net_device *dev )
466 MEM->tx_head[
i].flag = 0;
467 MEM->tx_head[
i].base_hi =
469 MEM->tx_head[
i].length = 0;
470 MEM->tx_head[
i].misc = 0;
476 MEM->rx_head[
i].base_hi =
479 MEM->rx_head[
i].msg_length = 0;
490 MEM->init.mode = 0x0000;
491 MEM->init.filter[0] = 0x00000000;
492 MEM->init.filter[1] = 0x00000000;
521 DPRINTK( 1, (
"%s: transmit start.\n",
525 if (netif_queue_stopped(dev)) {
527 if (tickssofar <
HZ/5)
530 DPRINTK( 1, (
"%s: transmit timed out, status %04x, resetting.\n",
538 dev->
stats.tx_errors++;
540 if(lance_debug >= 2) {
542 printk(
"Ring data: old_tx %d new_tx %d%s new_rx %d\n",
547 printk(
"rx #%d: base=%04x blen=%04x mlen=%04x\n",
548 i,
MEM->rx_head[i].base,
549 -
MEM->rx_head[i].buf_length,
550 MEM->rx_head[i].msg_length);
552 printk(
"tx #%d: base=%04x len=%04x misc=%04x\n",
553 i,
MEM->tx_head[i].base,
554 -
MEM->tx_head[i].length,
555 MEM->tx_head[i].misc );
558 lance_init_ring(dev);
561 netif_start_queue(dev);
573 netif_stop_queue(dev);
582 DPRINTK( 2, (
"%s: lance_start_xmit() called, csr0 %4.4x.\n",
588 DPRINTK( 1, (
"INIT not set, reinitializing...\n"));
590 lance_init_ring(dev);
597 if (lance_debug >= 2) {
598 printk(
"%s: TX pkt %d type 0x%04x"
600 " data at 0x%08x len %d\n",
603 (
int)skb->
data, (
int)skb->
len );
623 head->
length = (-len) | 0xf000;
637 DPRINTK( 2, (
"%s: lance_start_xmit() exiting, csr0 %4.4x.\n",
644 netif_start_queue(dev);
661 DPRINTK( 1, (
"lance_interrupt(): invalid dev_id\n" ));
666 DPRINTK( 2, (
"%s: Re-entering the interrupt handler.\n", dev->
name ));
683 DPRINTK( 2, (
"%s: interrupt csr0=%04x new csr=%04x.\n",
699 while( old_tx != lp->
new_tx) {
702 DPRINTK(3, (
"on tx_ring %d\n", old_tx));
709 dev->
stats.tx_errors++;
714 dev->
stats.tx_fifo_errors++;
715 printk(
"%s: Tx FIFO error\n",
719 lance_init_ring(dev);
727 dev->
stats.collisions++;
729 dev->
stats.tx_packets++;
730 DPRINTK(3, (
"cleared tx ring %d\n", old_tx));
739 if (netif_queue_stopped(dev)) {
741 netif_start_queue(dev);
742 netif_wake_queue(dev);
752 DPRINTK( 1, (
"%s: Bus master arbitration failure (?!?), "
753 "status %04x.\n", dev->
name, csr0 ));
757 lance_init_ring(dev);
768 if(
DREG & (CSR0_RINT | CSR0_TINT)) {
769 DPRINTK(2, (
"restarting interrupt, csr0=%#04x\n",
DREG));
773 DPRINTK( 2, (
"%s: exiting interrupt, csr0=%#04x.\n",
788 int status = head->
flag;
796 dev->
stats.rx_errors++;
810 dev->
stats.rx_errors++;
813 skb = netdev_alloc_skb(dev, pkt_len + 2);
815 DPRINTK( 1, (
"%s: Memory squeeze, deferring packet.\n",
818 dev->
stats.rx_dropped++;
826 if (lance_debug >= 3) {
828 printk(
"%s: RX pkt %d type 0x%04x"
833 printk(
" data %02x %02x %02x %02x %02x %02x %02x %02x "
835 data[15], data[16], data[17], data[18],
836 data[19], data[20], data[21], data[22],
840 if (lance_debug >= 3) {
842 printk(
"%s: RX pkt %d type 0x%04x len %d\n ", dev->
name, entry, ((
u_short *)data)[6], pkt_len);
846 skb_reserve( skb, 2 );
848 skb_copy_to_linear_data(skb,
854 dev->
stats.rx_packets++;
878 netif_stop_queue(dev);
882 DPRINTK( 2, (
"%s: Shutting down ethercard, status was %2.2x.\n",
900 static void set_multicast_list(
struct net_device *dev )
904 if(netif_queue_stopped(dev))
913 DPRINTK( 3, (
"%s: Promiscuous mode enabled.\n", dev->
name ));
916 short multicast_table[4];
921 memset( multicast_table, (num_addrs == 0) ? 0 : -1,
922 sizeof(multicast_table) );
923 for( i = 0; i < 4; i++ )
946 if (IS_ERR(sun3lance_dev))
947 return PTR_ERR(sun3lance_dev);