45 static char version[] =
"atarilance.c: v1.3 04/04/96 "
48 #include <linux/netdevice.h>
50 #include <linux/module.h>
51 #include <linux/stddef.h>
52 #include <linux/kernel.h>
53 #include <linux/string.h>
54 #include <linux/errno.h>
58 #include <linux/bitops.h>
60 #include <asm/setup.h>
78 static int lance_debug = 1;
85 #undef LANCE_DEBUG_PROBE
87 #define DPRINTK(n,a) \
89 if (lance_debug >= n) \
93 #ifdef LANCE_DEBUG_PROBE
94 # define PROBE_PRINT(a) printk a
96 # define PROBE_PRINT(a)
106 #define TX_LOG_RING_SIZE 3
107 #define RX_LOG_RING_SIZE 5
111 #define TX_RING_SIZE (1 << TX_LOG_RING_SIZE)
112 #define TX_RING_LEN_BITS (TX_LOG_RING_SIZE << 5)
113 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
115 #define RX_RING_SIZE (1 << RX_LOG_RING_SIZE)
116 #define RX_RING_LEN_BITS (RX_LOG_RING_SIZE << 5)
117 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
119 #define TX_TIMEOUT (HZ/5)
172 #define RIEBL_RSVD_START 0xee70
173 #define RIEBL_RSVD_END 0xeec0
174 #define RIEBL_MAGIC 0x09051990
175 #define RIEBL_MAGIC_ADDR ((unsigned long *)(((char *)MEM) + 0xee8a))
176 #define RIEBL_HWADDR_ADDR ((unsigned char *)(((char *)MEM) + 0xee8e))
177 #define RIEBL_IVEC_ADDR ((unsigned short *)(((char *)MEM) + 0xfffe))
184 static unsigned char OldRieblDefHwaddr[6] = {
185 0x00, 0x00, 0x36, 0x04, 0x00, 0x00
199 volatile unsigned char mem;
210 static char *lance_names[] = {
211 "Riebl-Card (without battery)",
212 "Riebl-Card (with battery)",
225 void *(*memcpy_f)(
void *,
const void *,
size_t );
234 #define DREG IO->data
235 #define AREG IO->addr
236 #define REGA(a) (*( AREG = (a), &DREG ))
239 #define PKT_BUF_SZ 1544
241 #define PKTBUF_ADDR(head) (((unsigned char *)(MEM)) + (head)->base)
245 static struct lance_addr {
247 unsigned long ioaddr;
249 } lance_addr_list[] = {
250 { 0xfe010000, 0xfe00fff0, 0 },
251 { 0xffc10000, 0xffc0fff0, 0 },
253 { 0xffe00000, 0xffff7000, 1 },
255 { 0xffd00000, 0xffff7000, 1 },
258 { 0xffcf0000, 0xffcffff0, 0 },
260 { 0xfecf0000, 0xfecffff0, 0 },
264 #define N_LANCE_ADDR ARRAY_SIZE(lance_addr_list)
270 #define TMD1_ENP 0x01
271 #define TMD1_STP 0x02
272 #define TMD1_DEF 0x04
273 #define TMD1_ONE 0x08
274 #define TMD1_MORE 0x10
275 #define TMD1_ERR 0x40
276 #define TMD1_OWN 0x80
278 #define TMD1_OWN_CHIP TMD1_OWN
279 #define TMD1_OWN_HOST 0
282 #define TMD3_TDR 0x03FF
283 #define TMD3_RTRY 0x0400
284 #define TMD3_LCAR 0x0800
285 #define TMD3_LCOL 0x1000
286 #define TMD3_UFLO 0x4000
287 #define TMD3_BUFF 0x8000
290 #define RMD1_ENP 0x01
291 #define RMD1_STP 0x02
292 #define RMD1_BUFF 0x04
293 #define RMD1_CRC 0x08
294 #define RMD1_OFLO 0x10
295 #define RMD1_FRAM 0x20
296 #define RMD1_ERR 0x40
297 #define RMD1_OWN 0x80
299 #define RMD1_OWN_CHIP RMD1_OWN
300 #define RMD1_OWN_HOST 0
312 #define CSR0_INIT 0x0001
313 #define CSR0_STRT 0x0002
314 #define CSR0_STOP 0x0004
315 #define CSR0_TDMD 0x0008
316 #define CSR0_TXON 0x0010
317 #define CSR0_RXON 0x0020
318 #define CSR0_INEA 0x0040
319 #define CSR0_INTR 0x0080
320 #define CSR0_IDON 0x0100
321 #define CSR0_TINT 0x0200
322 #define CSR0_RINT 0x0400
323 #define CSR0_MERR 0x0800
324 #define CSR0_MISS 0x1000
325 #define CSR0_CERR 0x2000
326 #define CSR0_BABL 0x4000
327 #define CSR0_ERR 0x8000
330 #define CSR3_BCON 0x0001
331 #define CSR3_ACON 0x0002
332 #define CSR3_BSWP 0x0004
338 static unsigned long lance_probe1(
struct net_device *
dev,
struct lance_addr
356 static void *slow_memcpy(
void *
dst,
const void *
src,
size_t len )
359 const char *cfrom =
src;
390 if (lance_probe1( dev, &lance_addr_list[i] )) {
406 static noinline int __init addr_accessible(
volatile void *regp,
int wordflag,
411 long *vbr, save_berr;
415 __asm__ __volatile__ (
"movec %/vbr,%0" :
"=r" (vbr) : );
419 (
"movel %/sp,%/d1\n\t"
420 "movel #Lberr,%2@\n\t"
427 "1: movew %1@,%/d0\n\t"
443 "Lberr: movel %/d1,%/sp"
445 :
"a" (regp),
"a" (&vbr[2]),
"rm" (wordflag),
"rm" (writeflag)
446 :
"d0",
"d1",
"memory"
459 .ndo_set_rx_mode = set_multicast_list,
460 .ndo_set_mac_address = lance_set_mac_address,
467 struct lance_addr *init_rec )
469 volatile unsigned short *
memaddr =
470 (
volatile unsigned short *)init_rec->memaddr;
471 volatile unsigned short *ioaddr =
472 (
volatile unsigned short *)init_rec->ioaddr;
476 static int did_version;
477 unsigned short save1, save2;
479 PROBE_PRINT((
"Probing for Lance card at mem %#lx io %#lx\n",
480 (
long)memaddr, (
long)ioaddr ));
483 PROBE_PRINT((
"lance_probe1: testing memory to be accessible\n" ));
484 if (!addr_accessible( memaddr, 1, 1 ))
goto probe_fail;
487 PROBE_PRINT((
"lance_probe1: testing memory to be writable (1)\n" ));
490 if (*memaddr != 0x0001)
goto probe_fail;
491 PROBE_PRINT((
"lance_probe1: testing memory to be writable (2)\n" ));
493 if (*memaddr != 0x0000)
goto probe_fail;
497 PROBE_PRINT((
"lance_probe1: testing ioport to be accessible\n" ));
498 if (!addr_accessible( ioaddr, 1, 1 ))
goto probe_fail;
501 PROBE_PRINT((
"lance_probe1: testing ioport to be writeable\n" ));
504 if (ioaddr[1] != 0x0001)
goto probe_fail;
507 PROBE_PRINT((
"lance_probe1: testing CSR0 register function (1)\n" ));
516 PROBE_PRINT((
"lance_probe1: testing CSR0 register function (2)\n" ));
525 PROBE_PRINT((
"lance_probe1: Lance card detected\n" ));
532 lp = netdev_priv(dev);
542 if (addr_accessible( &(IO->
eeprom), 0, 0 )) {
554 memaddr == (
unsigned short *)0xffe00000) {
557 "PAM,Riebl-ST Ethernet", dev)) {
558 printk(
"Lance: request for irq %d failed\n", IRQ_AUTO_5 );
561 dev->
irq = IRQ_AUTO_5;
567 printk(
"Lance: request for VME interrupt failed\n" );
571 "Riebl-VME Ethernet", dev)) {
572 printk(
"Lance: request for irq %u failed\n", irq );
578 printk(
"%s: %s at io %#lx, mem %#lx, irq %d%s, hwaddr ",
580 (
unsigned long)ioaddr,
581 (
unsigned long)memaddr,
583 init_rec->slow_flag ?
" (slow memcpy)" :
"" );
596 for( i = 0; i < 6; ++
i )
598 ((((
unsigned short *)
MEM)[i*2] & 0x0f) << 4) |
599 ((((
unsigned short *)
MEM)[i*2+1] & 0x0f));
605 printk(
"%s: Warning: This is a default ethernet address!\n",
607 printk(
" Use \"ifconfig hw ether ...\" to set the address.\n" );
612 MEM->init.mode = 0x0000;
613 for( i = 0; i < 6; i++ )
615 MEM->init.filter[0] = 0x00000000;
616 MEM->init.filter[1] = 0x00000000;
618 MEM->init.rx_ring.adr_hi = 0;
621 MEM->init.tx_ring.adr_hi = 0;
629 if (did_version++ == 0)
649 lance_init_ring(dev);
663 DPRINTK( 2, (
"lance_open(): opening %s failed, i=%d, csr0=%04x\n",
672 netif_start_queue (dev);
682 static void lance_init_ring(
struct net_device *dev )
696 #define CHECK_OFFSET(o) \
698 if (lp->cardtype == OLD_RIEBL || lp->cardtype == NEW_RIEBL) { \
699 if (((o) < RIEBL_RSVD_START) ? (o)+PKT_BUF_SZ > RIEBL_RSVD_START \
700 : (o) < RIEBL_RSVD_END) \
701 (o) = RIEBL_RSVD_END; \
709 MEM->tx_head[
i].base_hi = 0;
710 MEM->tx_head[
i].length = 0;
711 MEM->tx_head[
i].misc = 0;
719 MEM->rx_head[
i].base_hi = 0;
721 MEM->rx_head[
i].msg_length = 0;
736 DPRINTK( 1, (
"%s: transmit timed out, status %04x, resetting.\n",
744 dev->
stats.tx_errors++;
745 #ifndef final_version
747 DPRINTK( 2, (
"Ring data: dirty_tx %d cur_tx %d%s cur_rx %d\n",
752 DPRINTK( 2, (
"rx #%d: base=%04x blen=%04x mlen=%04x\n",
753 i,
MEM->rx_head[i].base,
754 -
MEM->rx_head[i].buf_length,
755 MEM->rx_head[i].msg_length ));
757 DPRINTK( 2, (
"tx #%d: base=%04x len=%04x misc=%04x\n",
758 i,
MEM->tx_head[i].base,
759 -
MEM->tx_head[i].length,
760 MEM->tx_head[i].misc ));
765 lance_init_ring(dev);
768 netif_wake_queue(dev);
781 DPRINTK( 2, (
"%s: lance_start_xmit() called, csr0 %4.4x.\n",
793 if (len > skb->
len) {
794 if (skb_padto(skb, len))
798 netif_stop_queue (dev);
801 if (lance_debug >= 3) {
802 printk(
"%s: TX pkt type 0x%04x from %pM to %pM"
803 " data at 0x%08x len %d\n",
806 (
int)skb->
data, (
int)skb->
len );
827 dev_kfree_skb( skb );
829 while( lp->
cur_tx >= TX_RING_SIZE && lp->
dirty_tx >= TX_RING_SIZE ) {
839 netif_start_queue (dev);
842 spin_unlock_irqrestore (&lp->
devlock, flags);
854 int csr0, boguscnt = 10;
858 DPRINTK( 1, (
"lance_interrupt(): interrupt for unknown device.\n" ));
862 lp = netdev_priv(dev);
875 DPRINTK( 2, (
"%s: interrupt csr0=%04x new csr=%04x.\n",
884 while( dirty_tx < lp->cur_tx) {
895 int err_status =
MEM->tx_head[
entry].misc;
896 dev->
stats.tx_errors++;
902 dev->
stats.tx_fifo_errors++;
904 DPRINTK( 1, (
"%s: Tx FIFO error! Status %04x\n",
911 dev->
stats.collisions++;
912 dev->
stats.tx_packets++;
919 #ifndef final_version
920 if (lp->
cur_tx - dirty_tx >= TX_RING_SIZE) {
921 DPRINTK( 0, (
"out-of-sync dirty pointer,"
922 " %d vs. %d, full=%ld.\n",
928 if (lp->
tx_full && (netif_queue_stopped(dev)) &&
929 dirty_tx > lp->
cur_tx - TX_RING_SIZE + 2) {
932 netif_wake_queue (dev);
942 DPRINTK( 1, (
"%s: Bus master arbitration failure (?!?), "
943 "status %04x.\n", dev->
name, csr0 ));
953 DPRINTK( 2, (
"%s: exiting interrupt, csr0=%#04x.\n",
967 DPRINTK( 2, (
"%s: rx int, flag=%04x\n", dev->
name,
968 MEM->rx_head[entry].flag ));
973 int status = head->
flag;
981 dev->
stats.rx_errors++;
994 dev->
stats.rx_errors++;
997 skb = netdev_alloc_skb(dev, pkt_len + 2);
999 DPRINTK( 1, (
"%s: Memory squeeze, deferring packet.\n",
1006 if (i > RX_RING_SIZE - 2) {
1007 dev->
stats.rx_dropped++;
1014 if (lance_debug >= 3) {
1018 "data %02x %02x %02x %02x %02x %02x %02x %02x "
1022 data[15], data[16], data[17], data[18],
1023 data[19], data[20], data[21], data[22],
1027 skb_reserve( skb, 2 );
1032 dev->
stats.rx_packets++;
1055 netif_stop_queue (dev);
1059 DPRINTK( 2, (
"%s: Shutting down ethercard, status was %2.2x.\n",
1077 static void set_multicast_list(
struct net_device *dev )
1082 if (netif_running(dev))
1091 DPRINTK( 2, (
"%s: Promiscuous mode enabled.\n", dev->
name ));
1094 short multicast_table[4];
1099 memset( multicast_table, (num_addrs == 0) ? 0 : -1,
1100 sizeof(multicast_table) );
1101 for( i = 0; i < 4; i++ )
1119 static int lance_set_mac_address(
struct net_device *dev,
void *
addr )
1128 if (netif_running(dev)) {
1130 DPRINTK( 1, (
"%s: hwaddr can be set only while card isn't open.\n",
1136 for( i = 0; i < 6; i++ )
1149 static int __init atarilance_module_init(
void)
1152 if (IS_ERR(atarilance_dev))
1153 return PTR_ERR(atarilance_dev);
1157 static void __exit atarilance_module_exit(
void)