1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45static char version[] = "atarilance.c: v1.3 04/04/96 "
46 "Roman.Hodek@informatik.uni-erlangen.de\n";
47
48#include <linux/module.h>
49
50#include <linux/stddef.h>
51#include <linux/kernel.h>
52#include <linux/sched.h>
53#include <linux/string.h>
54#include <linux/errno.h>
55#include <linux/slab.h>
56#include <linux/interrupt.h>
57#include <linux/init.h>
58
59#include <asm/setup.h>
60#include <asm/irq.h>
61#include <asm/atarihw.h>
62#include <asm/atariints.h>
63#include <asm/bitops.h>
64#include <asm/io.h>
65
66#include <linux/netdevice.h>
67#include <linux/etherdevice.h>
68#include <linux/skbuff.h>
69
70
71
72
73
74
75
76
77#define LANCE_DEBUG 1
78
79#ifdef LANCE_DEBUG
80static int lance_debug = LANCE_DEBUG;
81#else
82static int lance_debug = 1;
83#endif
84MODULE_PARM(lance_debug, "i");
85MODULE_PARM_DESC(lance_debug, "atarilance debug level (0-3)");
86MODULE_LICENSE("GPL");
87
88
89#undef LANCE_DEBUG_PROBE
90
91#define DPRINTK(n,a) \
92 do { \
93 if (lance_debug >= n) \
94 printk a; \
95 } while( 0 )
96
97#ifdef LANCE_DEBUG_PROBE
98# define PROBE_PRINT(a) printk a
99#else
100# define PROBE_PRINT(a)
101#endif
102
103
104
105
106
107
108
109
110#define TX_LOG_RING_SIZE 3
111#define RX_LOG_RING_SIZE 5
112
113
114
115#define TX_RING_SIZE (1 << TX_LOG_RING_SIZE)
116#define TX_RING_LEN_BITS (TX_LOG_RING_SIZE << 5)
117#define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
118
119#define RX_RING_SIZE (1 << RX_LOG_RING_SIZE)
120#define RX_RING_LEN_BITS (RX_LOG_RING_SIZE << 5)
121#define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
122
123#define TX_TIMEOUT 20
124
125
126struct lance_rx_head {
127 unsigned short base;
128 volatile unsigned char flag;
129 unsigned char base_hi;
130 short buf_length;
131 volatile short msg_length;
132};
133
134struct lance_tx_head {
135 unsigned short base;
136 volatile unsigned char flag;
137 unsigned char base_hi;
138 short length;
139 volatile short misc;
140};
141
142struct ringdesc {
143 unsigned short adr_lo;
144 unsigned char len;
145 unsigned char adr_hi;
146};
147
148
149struct lance_init_block {
150 unsigned short mode;
151 unsigned char hwaddr[6];
152 unsigned filter[2];
153
154 struct ringdesc rx_ring;
155 struct ringdesc tx_ring;
156};
157
158
159struct lance_memory {
160 struct lance_init_block init;
161 struct lance_tx_head tx_head[TX_RING_SIZE];
162 struct lance_rx_head rx_head[RX_RING_SIZE];
163 char packet_area[0];
164
165
166
167};
168
169
170
171
172
173
174
175
176#define RIEBL_RSVD_START 0xee70
177#define RIEBL_RSVD_END 0xeec0
178#define RIEBL_MAGIC 0x09051990
179#define RIEBL_MAGIC_ADDR ((unsigned long *)(((char *)MEM) + 0xee8a))
180#define RIEBL_HWADDR_ADDR ((unsigned char *)(((char *)MEM) + 0xee8e))
181#define RIEBL_IVEC_ADDR ((unsigned short *)(((char *)MEM) + 0xfffe))
182
183
184
185
186
187
188static unsigned char OldRieblDefHwaddr[6] = {
189 0x00, 0x00, 0x36, 0x04, 0x00, 0x00
190};
191
192
193
194
195struct lance_ioreg {
196 volatile unsigned short data;
197 volatile unsigned short addr;
198 unsigned char _dummy1[3];
199 volatile unsigned char ivec;
200 unsigned char _dummy2[5];
201 volatile unsigned char eeprom;
202 unsigned char _dummy3;
203 volatile unsigned char mem;
204};
205
206
207
208enum lance_type {
209 OLD_RIEBL,
210 NEW_RIEBL,
211 PAM_CARD
212};
213
214static char *lance_names[] = {
215 "Riebl-Card (without battery)",
216 "Riebl-Card (with battery)",
217 "PAM intern card"
218};
219
220
221
222struct lance_private {
223 enum lance_type cardtype;
224 struct lance_ioreg *iobase;
225 struct lance_memory *mem;
226 int cur_rx, cur_tx;
227 int dirty_tx;
228
229 void *(*memcpy_f)( void *, const void *, size_t );
230 struct net_device_stats stats;
231
232 long tx_full;
233 spinlock_t devlock;
234};
235
236
237
238#define MEM lp->mem
239#define DREG IO->data
240#define AREG IO->addr
241#define REGA(a) ( AREG = (a), DREG )
242
243
244#define PKT_BUF_SZ 1544
245
246#define PKTBUF_ADDR(head) (((unsigned char *)(MEM)) + (head)->base)
247
248
249
250struct lance_addr {
251 unsigned long memaddr;
252 unsigned long ioaddr;
253 int slow_flag;
254} lance_addr_list[] = {
255 { 0xfe010000, 0xfe00fff0, 0 },
256 { 0xffc10000, 0xffc0fff0, 0 },
257
258 { 0xffe00000, 0xffff7000, 1 },
259
260 { 0xffd00000, 0xffff7000, 1 },
261
262
263 { 0xffcf0000, 0xffcffff0, 0 },
264
265 { 0xfecf0000, 0xfecffff0, 0 },
266
267};
268
269#define N_LANCE_ADDR (sizeof(lance_addr_list)/sizeof(*lance_addr_list))
270
271
272
273
274
275#define TMD1_ENP 0x01
276#define TMD1_STP 0x02
277#define TMD1_DEF 0x04
278#define TMD1_ONE 0x08
279#define TMD1_MORE 0x10
280#define TMD1_ERR 0x40
281#define TMD1_OWN 0x80
282
283#define TMD1_OWN_CHIP TMD1_OWN
284#define TMD1_OWN_HOST 0
285
286
287#define TMD3_TDR 0x03FF
288#define TMD3_RTRY 0x0400
289#define TMD3_LCAR 0x0800
290#define TMD3_LCOL 0x1000
291#define TMD3_UFLO 0x4000
292#define TMD3_BUFF 0x8000
293
294
295#define RMD1_ENP 0x01
296#define RMD1_STP 0x02
297#define RMD1_BUFF 0x04
298#define RMD1_CRC 0x08
299#define RMD1_OFLO 0x10
300#define RMD1_FRAM 0x20
301#define RMD1_ERR 0x40
302#define RMD1_OWN 0x80
303
304#define RMD1_OWN_CHIP RMD1_OWN
305#define RMD1_OWN_HOST 0
306
307
308#define CSR0 0
309#define CSR1 1
310#define CSR2 2
311#define CSR3 3
312#define CSR8 8
313#define CSR15 15
314
315
316
317#define CSR0_INIT 0x0001
318#define CSR0_STRT 0x0002
319#define CSR0_STOP 0x0004
320#define CSR0_TDMD 0x0008
321#define CSR0_TXON 0x0010
322#define CSR0_RXON 0x0020
323#define CSR0_INEA 0x0040
324#define CSR0_INTR 0x0080
325#define CSR0_IDON 0x0100
326#define CSR0_TINT 0x0200
327#define CSR0_RINT 0x0400
328#define CSR0_MERR 0x0800
329#define CSR0_MISS 0x1000
330#define CSR0_CERR 0x2000
331#define CSR0_BABL 0x4000
332#define CSR0_ERR 0x8000
333
334
335#define CSR3_BCON 0x0001
336#define CSR3_ACON 0x0002
337#define CSR3_BSWP 0x0004
338
339
340
341
342
343static int addr_accessible( volatile void *regp, int wordflag, int
344 writeflag );
345static unsigned long lance_probe1( struct net_device *dev, struct lance_addr
346 *init_rec );
347static int lance_open( struct net_device *dev );
348static void lance_init_ring( struct net_device *dev );
349static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev );
350static void lance_interrupt( int irq, void *dev_id, struct pt_regs *fp );
351static int lance_rx( struct net_device *dev );
352static int lance_close( struct net_device *dev );
353static struct net_device_stats *lance_get_stats( struct net_device *dev );
354static void set_multicast_list( struct net_device *dev );
355static int lance_set_mac_address( struct net_device *dev, void *addr );
356static void lance_tx_timeout (struct net_device *dev);
357
358
359
360
361
362
363
364static void *slow_memcpy( void *dst, const void *src, size_t len )
365
366{ char *cto = dst;
367 const char *cfrom = src;
368
369 while( len-- ) {
370 *cto++ = *cfrom++;
371 MFPDELAY();
372 }
373 return( dst );
374}
375
376
377int __init atarilance_probe( struct net_device *dev )
378{
379 int i;
380 static int found;
381
382 SET_MODULE_OWNER(dev);
383
384 if (!MACH_IS_ATARI || found)
385
386
387 return( ENODEV );
388
389 for( i = 0; i < N_LANCE_ADDR; ++i ) {
390 if (lance_probe1( dev, &lance_addr_list[i] )) {
391 found = 1;
392 return( 0 );
393 }
394 }
395
396 return( ENODEV );
397}
398
399
400
401
402static int __init addr_accessible( volatile void *regp, int wordflag, int writeflag )
403{
404 int ret;
405 long flags;
406 long *vbr, save_berr;
407
408 save_flags(flags);
409 cli();
410
411 __asm__ __volatile__ ( "movec %/vbr,%0" : "=r" (vbr) : );
412 save_berr = vbr[2];
413
414 __asm__ __volatile__
415 ( "movel %/sp,%/d1\n\t"
416 "movel #Lberr,%2@\n\t"
417 "moveq #0,%0\n\t"
418 "tstl %3\n\t"
419 "bne 1f\n\t"
420 "moveb %1@,%/d0\n\t"
421 "nop \n\t"
422 "bra 2f\n"
423"1: movew %1@,%/d0\n\t"
424 "nop \n"
425"2: tstl %4\n\t"
426 "beq 2f\n\t"
427 "tstl %3\n\t"
428 "bne 1f\n\t"
429 "clrb %1@\n\t"
430 "nop \n\t"
431 "moveb %/d0,%1@\n\t"
432 "nop \n\t"
433 "bra 2f\n"
434"1: clrw %1@\n\t"
435 "nop \n\t"
436 "movew %/d0,%1@\n\t"
437 "nop \n"
438"2: moveq #1,%0\n"
439"Lberr: movel %/d1,%/sp"
440 : "=&d" (ret)
441 : "a" (regp), "a" (&vbr[2]), "rm" (wordflag), "rm" (writeflag)
442 : "d0", "d1", "memory"
443 );
444
445 vbr[2] = save_berr;
446 restore_flags(flags);
447
448 return( ret );
449}
450
451
452static unsigned long __init lance_probe1( struct net_device *dev,
453 struct lance_addr *init_rec )
454{
455 volatile unsigned short *memaddr =
456 (volatile unsigned short *)init_rec->memaddr;
457 volatile unsigned short *ioaddr =
458 (volatile unsigned short *)init_rec->ioaddr;
459 struct lance_private *lp;
460 struct lance_ioreg *IO;
461 int i;
462 static int did_version;
463 unsigned short save1, save2;
464
465 PROBE_PRINT(( "Probing for Lance card at mem %#lx io %#lx\n",
466 (long)memaddr, (long)ioaddr ));
467
468
469 PROBE_PRINT(( "lance_probe1: testing memory to be accessible\n" ));
470 if (!addr_accessible( memaddr, 1, 1 )) goto probe_fail;
471
472
473 PROBE_PRINT(( "lance_probe1: testing memory to be writable (1)\n" ));
474 save1 = *memaddr;
475 *memaddr = 0x0001;
476 if (*memaddr != 0x0001) goto probe_fail;
477 PROBE_PRINT(( "lance_probe1: testing memory to be writable (2)\n" ));
478 *memaddr = 0x0000;
479 if (*memaddr != 0x0000) goto probe_fail;
480 *memaddr = save1;
481
482
483 PROBE_PRINT(( "lance_probe1: testing ioport to be accessible\n" ));
484 if (!addr_accessible( ioaddr, 1, 1 )) goto probe_fail;
485
486
487 PROBE_PRINT(( "lance_probe1: testing ioport to be writeable\n" ));
488 save2 = ioaddr[1];
489 ioaddr[1] = 0x0001;
490 if (ioaddr[1] != 0x0001) goto probe_fail;
491
492
493 PROBE_PRINT(( "lance_probe1: testing CSR0 register function (1)\n" ));
494 save1 = ioaddr[0];
495 ioaddr[1] = CSR0;
496 ioaddr[0] = CSR0_INIT | CSR0_STOP;
497 if (ioaddr[0] != CSR0_STOP) {
498 ioaddr[0] = save1;
499 ioaddr[1] = save2;
500 goto probe_fail;
501 }
502 PROBE_PRINT(( "lance_probe1: testing CSR0 register function (2)\n" ));
503 ioaddr[0] = CSR0_STOP;
504 if (ioaddr[0] != CSR0_STOP) {
505 ioaddr[0] = save1;
506 ioaddr[1] = save2;
507 goto probe_fail;
508 }
509
510
511 PROBE_PRINT(( "lance_probe1: Lance card detected\n" ));
512 goto probe_ok;
513
514 probe_fail:
515 return( 0 );
516
517 probe_ok:
518 init_etherdev( dev, sizeof(struct lance_private) );
519 if (!dev->priv) {
520 dev->priv = kmalloc( sizeof(struct lance_private), GFP_KERNEL );
521 if (!dev->priv)
522 return 0;
523 }
524 lp = (struct lance_private *)dev->priv;
525 MEM = (struct lance_memory *)memaddr;
526 IO = lp->iobase = (struct lance_ioreg *)ioaddr;
527 dev->base_addr = (unsigned long)ioaddr;
528 lp->memcpy_f = init_rec->slow_flag ? slow_memcpy : memcpy;
529
530 REGA( CSR0 ) = CSR0_STOP;
531
532
533
534 if (addr_accessible( &(IO->eeprom), 0, 0 )) {
535
536 i = IO->mem;
537 lp->cardtype = PAM_CARD;
538 }
539 else if (*RIEBL_MAGIC_ADDR == RIEBL_MAGIC) {
540 lp->cardtype = NEW_RIEBL;
541 }
542 else
543 lp->cardtype = OLD_RIEBL;
544
545 if (lp->cardtype == PAM_CARD ||
546 memaddr == (unsigned short *)0xffe00000) {
547
548 if (request_irq(IRQ_AUTO_5, lance_interrupt, IRQ_TYPE_PRIO,
549 "PAM/Riebl-ST Ethernet", dev)) {
550 printk( "Lance: request for irq %d failed\n", IRQ_AUTO_5 );
551 return( 0 );
552 }
553 dev->irq = (unsigned short)IRQ_AUTO_5;
554 }
555 else {
556
557
558
559
560 unsigned long irq = atari_register_vme_int();
561 if (!irq) {
562 printk( "Lance: request for VME interrupt failed\n" );
563 return( 0 );
564 }
565 if (request_irq(irq, lance_interrupt, IRQ_TYPE_PRIO,
566 "Riebl-VME Ethernet", dev)) {
567 printk( "Lance: request for irq %ld failed\n", irq );
568 return( 0 );
569 }
570 dev->irq = irq;
571 }
572
573 printk("%s: %s at io %#lx, mem %#lx, irq %d%s, hwaddr ",
574 dev->name, lance_names[lp->cardtype],
575 (unsigned long)ioaddr,
576 (unsigned long)memaddr,
577 dev->irq,
578 init_rec->slow_flag ? " (slow memcpy)" : "" );
579
580
581 switch( lp->cardtype ) {
582 case OLD_RIEBL:
583
584 memcpy( dev->dev_addr, OldRieblDefHwaddr, 6 );
585 break;
586 case NEW_RIEBL:
587 lp->memcpy_f( dev->dev_addr, RIEBL_HWADDR_ADDR, 6 );
588 break;
589 case PAM_CARD:
590 i = IO->eeprom;
591 for( i = 0; i < 6; ++i )
592 dev->dev_addr[i] =
593 ((((unsigned short *)MEM)[i*2] & 0x0f) << 4) |
594 ((((unsigned short *)MEM)[i*2+1] & 0x0f));
595 i = IO->mem;
596 break;
597 }
598 for( i = 0; i < 6; ++i )
599 printk( "%02x%s", dev->dev_addr[i], (i < 5) ? ":" : "\n" );
600 if (lp->cardtype == OLD_RIEBL) {
601 printk( "%s: Warning: This is a default ethernet address!\n",
602 dev->name );
603 printk( " Use \"ifconfig hw ether ...\" to set the address.\n" );
604 }
605
606 lp->devlock = SPIN_LOCK_UNLOCKED;
607
608 MEM->init.mode = 0x0000;
609 for( i = 0; i < 6; i++ )
610 MEM->init.hwaddr[i] = dev->dev_addr[i^1];
611 MEM->init.filter[0] = 0x00000000;
612 MEM->init.filter[1] = 0x00000000;
613 MEM->init.rx_ring.adr_lo = offsetof( struct lance_memory, rx_head );
614 MEM->init.rx_ring.adr_hi = 0;
615 MEM->init.rx_ring.len = RX_RING_LEN_BITS;
616 MEM->init.tx_ring.adr_lo = offsetof( struct lance_memory, tx_head );
617 MEM->init.tx_ring.adr_hi = 0;
618 MEM->init.tx_ring.len = TX_RING_LEN_BITS;
619
620 if (lp->cardtype == PAM_CARD)
621 IO->ivec = IRQ_SOURCE_TO_VECTOR(dev->irq);
622 else
623 *RIEBL_IVEC_ADDR = IRQ_SOURCE_TO_VECTOR(dev->irq);
624
625 if (did_version++ == 0)
626 DPRINTK( 1, ( version ));
627
628
629 dev->open = &lance_open;
630 dev->hard_start_xmit = &lance_start_xmit;
631 dev->stop = &lance_close;
632 dev->get_stats = &lance_get_stats;
633 dev->set_multicast_list = &set_multicast_list;
634 dev->set_mac_address = &lance_set_mac_address;
635
636
637 dev->tx_timeout = lance_tx_timeout;
638 dev->watchdog_timeo = TX_TIMEOUT;
639
640
641#if 0
642 dev->start = 0;
643#endif
644
645 memset( &lp->stats, 0, sizeof(lp->stats) );
646
647 return( 1 );
648}
649
650
651static int lance_open( struct net_device *dev )
652
653{ struct lance_private *lp = (struct lance_private *)dev->priv;
654 struct lance_ioreg *IO = lp->iobase;
655 int i;
656
657 DPRINTK( 2, ( "%s: lance_open()\n", dev->name ));
658
659 lance_init_ring(dev);
660
661
662 REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
663 REGA( CSR2 ) = 0;
664 REGA( CSR1 ) = 0;
665 REGA( CSR0 ) = CSR0_INIT;
666
667
668 i = 1000000;
669 while (--i > 0)
670 if (DREG & CSR0_IDON)
671 break;
672 if (i < 0 || (DREG & CSR0_ERR)) {
673 DPRINTK( 2, ( "lance_open(): opening %s failed, i=%d, csr0=%04x\n",
674 dev->name, i, DREG ));
675 DREG = CSR0_STOP;
676 return( -EIO );
677 }
678 DREG = CSR0_IDON;
679 DREG = CSR0_STRT;
680 DREG = CSR0_INEA;
681
682 netif_start_queue (dev);
683
684 DPRINTK( 2, ( "%s: LANCE is open, csr0 %04x\n", dev->name, DREG ));
685
686 return( 0 );
687}
688
689
690
691
692static void lance_init_ring( struct net_device *dev )
693
694{ struct lance_private *lp = (struct lance_private *)dev->priv;
695 int i;
696 unsigned offset;
697
698 lp->tx_full = 0;
699 lp->cur_rx = lp->cur_tx = 0;
700 lp->dirty_tx = 0;
701
702 offset = offsetof( struct lance_memory, packet_area );
703
704
705
706#define CHECK_OFFSET(o) \
707 do { \
708 if (lp->cardtype == OLD_RIEBL || lp->cardtype == NEW_RIEBL) { \
709 if (((o) < RIEBL_RSVD_START) ? (o)+PKT_BUF_SZ > RIEBL_RSVD_START \
710 : (o) < RIEBL_RSVD_END) \
711 (o) = RIEBL_RSVD_END; \
712 } \
713 } while(0)
714
715 for( i = 0; i < TX_RING_SIZE; i++ ) {
716 CHECK_OFFSET(offset);
717 MEM->tx_head[i].base = offset;
718 MEM->tx_head[i].flag = TMD1_OWN_HOST;
719 MEM->tx_head[i].base_hi = 0;
720 MEM->tx_head[i].length = 0;
721 MEM->tx_head[i].misc = 0;
722 offset += PKT_BUF_SZ;
723 }
724
725 for( i = 0; i < RX_RING_SIZE; i++ ) {
726 CHECK_OFFSET(offset);
727 MEM->rx_head[i].base = offset;
728 MEM->rx_head[i].flag = TMD1_OWN_CHIP;
729 MEM->rx_head[i].base_hi = 0;
730 MEM->rx_head[i].buf_length = -PKT_BUF_SZ;
731 MEM->rx_head[i].msg_length = 0;
732 offset += PKT_BUF_SZ;
733 }
734}
735
736
737
738
739
740static void lance_tx_timeout (struct net_device *dev)
741{
742 struct lance_private *lp = (struct lance_private *) dev->priv;
743 struct lance_ioreg *IO = lp->iobase;
744
745 AREG = CSR0;
746 DPRINTK( 1, ( "%s: transmit timed out, status %04x, resetting.\n",
747 dev->name, DREG ));
748 DREG = CSR0_STOP;
749
750
751
752
753 REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
754 lp->stats.tx_errors++;
755#ifndef final_version
756 { int i;
757 DPRINTK( 2, ( "Ring data: dirty_tx %d cur_tx %d%s cur_rx %d\n",
758 lp->dirty_tx, lp->cur_tx,
759 lp->tx_full ? " (full)" : "",
760 lp->cur_rx ));
761 for( i = 0 ; i < RX_RING_SIZE; i++ )
762 DPRINTK( 2, ( "rx #%d: base=%04x blen=%04x mlen=%04x\n",
763 i, MEM->rx_head[i].base,
764 -MEM->rx_head[i].buf_length,
765 MEM->rx_head[i].msg_length ));
766 for( i = 0 ; i < TX_RING_SIZE; i++ )
767 DPRINTK( 2, ( "tx #%d: base=%04x len=%04x misc=%04x\n",
768 i, MEM->tx_head[i].base,
769 -MEM->tx_head[i].length,
770 MEM->tx_head[i].misc ));
771 }
772#endif
773
774
775 lance_init_ring(dev);
776 REGA( CSR0 ) = CSR0_INEA | CSR0_INIT | CSR0_STRT;
777 dev->trans_start = jiffies;
778 netif_wake_queue (dev);
779}
780
781
782
783static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev )
784
785{ struct lance_private *lp = (struct lance_private *)dev->priv;
786 struct lance_ioreg *IO = lp->iobase;
787 int entry, len;
788 struct lance_tx_head *head;
789 unsigned long flags;
790
791 DPRINTK( 2, ( "%s: lance_start_xmit() called, csr0 %4.4x.\n",
792 dev->name, DREG ));
793
794 netif_stop_queue (dev);
795
796
797 if (lance_debug >= 3) {
798 u_char *p;
799 int i;
800 printk( "%s: TX pkt type 0x%04x from ", dev->name,
801 ((u_short *)skb->data)[6]);
802 for( p = &((u_char *)skb->data)[6], i = 0; i < 6; i++ )
803 printk("%02x%s", *p++, i != 5 ? ":" : "" );
804 printk(" to ");
805 for( p = (u_char *)skb->data, i = 0; i < 6; i++ )
806 printk("%02x%s", *p++, i != 5 ? ":" : "" );
807 printk(" data at 0x%08x len %d\n", (int)skb->data,
808 (int)skb->len );
809 }
810
811
812
813 spin_lock_irqsave (&lp->devlock, flags);
814
815
816 entry = lp->cur_tx & TX_RING_MOD_MASK;
817 head = &(MEM->tx_head[entry]);
818
819
820
821
822
823
824 len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
825
826 if (lp->cardtype == PAM_CARD && (len & 1))
827 ++len;
828
829 head->length = -len;
830 head->misc = 0;
831 lp->memcpy_f( PKTBUF_ADDR(head), (void *)skb->data, skb->len );
832 head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP;
833 lp->stats.tx_bytes += skb->len;
834 dev_kfree_skb( skb );
835 lp->cur_tx++;
836 while( lp->cur_tx >= TX_RING_SIZE && lp->dirty_tx >= TX_RING_SIZE ) {
837 lp->cur_tx -= TX_RING_SIZE;
838 lp->dirty_tx -= TX_RING_SIZE;
839 }
840
841
842 DREG = CSR0_INEA | CSR0_TDMD;
843 dev->trans_start = jiffies;
844
845 if ((MEM->tx_head[(entry+1) & TX_RING_MOD_MASK].flag & TMD1_OWN) ==
846 TMD1_OWN_HOST)
847 netif_start_queue (dev);
848 else
849 lp->tx_full = 1;
850 spin_unlock_irqrestore (&lp->devlock, flags);
851
852 return 0;
853}
854
855
856
857static void lance_interrupt( int irq, void *dev_id, struct pt_regs *fp)
858{
859 struct net_device *dev = dev_id;
860 struct lance_private *lp;
861 struct lance_ioreg *IO;
862 int csr0, boguscnt = 10;
863
864 if (dev == NULL) {
865 DPRINTK( 1, ( "lance_interrupt(): interrupt for unknown device.\n" ));
866 return;
867 }
868
869 lp = (struct lance_private *)dev->priv;
870 IO = lp->iobase;
871 spin_lock (&lp->devlock);
872
873 AREG = CSR0;
874
875 while( ((csr0 = DREG) & (CSR0_ERR | CSR0_TINT | CSR0_RINT)) &&
876 --boguscnt >= 0) {
877
878 DREG = csr0 & ~(CSR0_INIT | CSR0_STRT | CSR0_STOP |
879 CSR0_TDMD | CSR0_INEA);
880
881 DPRINTK( 2, ( "%s: interrupt csr0=%04x new csr=%04x.\n",
882 dev->name, csr0, DREG ));
883
884 if (csr0 & CSR0_RINT)
885 lance_rx( dev );
886
887 if (csr0 & CSR0_TINT) {
888 int dirty_tx = lp->dirty_tx;
889
890 while( dirty_tx < lp->cur_tx) {
891 int entry = dirty_tx & TX_RING_MOD_MASK;
892 int status = MEM->tx_head[entry].flag;
893
894 if (status & TMD1_OWN_CHIP)
895 break;
896
897 MEM->tx_head[entry].flag = 0;
898
899 if (status & TMD1_ERR) {
900
901 int err_status = MEM->tx_head[entry].misc;
902 lp->stats.tx_errors++;
903 if (err_status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
904 if (err_status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
905 if (err_status & TMD3_LCOL) lp->stats.tx_window_errors++;
906 if (err_status & TMD3_UFLO) {
907
908 lp->stats.tx_fifo_errors++;
909
910 DPRINTK( 1, ( "%s: Tx FIFO error! Status %04x\n",
911 dev->name, csr0 ));
912
913 DREG = CSR0_STRT;
914 }
915 } else {
916 if (status & (TMD1_MORE | TMD1_ONE | TMD1_DEF))
917 lp->stats.collisions++;
918 lp->stats.tx_packets++;
919 }
920
921
922 dirty_tx++;
923 }
924
925#ifndef final_version
926 if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {
927 DPRINTK( 0, ( "out-of-sync dirty pointer,"
928 " %d vs. %d, full=%ld.\n",
929 dirty_tx, lp->cur_tx, lp->tx_full ));
930 dirty_tx += TX_RING_SIZE;
931 }
932#endif
933
934 if (lp->tx_full && (netif_queue_stopped(dev))
935 && dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {
936
937 lp->tx_full = 0;
938 netif_wake_queue (dev);
939 }
940
941 lp->dirty_tx = dirty_tx;
942 }
943
944
945 if (csr0 & CSR0_BABL) lp->stats.tx_errors++;
946 if (csr0 & CSR0_MISS) lp->stats.rx_errors++;
947 if (csr0 & CSR0_MERR) {
948 DPRINTK( 1, ( "%s: Bus master arbitration failure (?!?), "
949 "status %04x.\n", dev->name, csr0 ));
950
951 DREG = CSR0_STRT;
952 }
953 }
954
955
956 DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR |
957 CSR0_IDON | CSR0_INEA;
958
959 DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n",
960 dev->name, DREG ));
961
962 spin_unlock (&lp->devlock);
963}
964
965
966static int lance_rx( struct net_device *dev )
967
968{ struct lance_private *lp = (struct lance_private *)dev->priv;
969 int entry = lp->cur_rx & RX_RING_MOD_MASK;
970 int i;
971
972 DPRINTK( 2, ( "%s: rx int, flag=%04x\n", dev->name,
973 MEM->rx_head[entry].flag ));
974
975
976 while( (MEM->rx_head[entry].flag & RMD1_OWN) == RMD1_OWN_HOST ) {
977 struct lance_rx_head *head = &(MEM->rx_head[entry]);
978 int status = head->flag;
979
980 if (status != (RMD1_ENP|RMD1_STP)) {
981
982
983
984
985 if (status & RMD1_ENP)
986 lp->stats.rx_errors++;
987 if (status & RMD1_FRAM) lp->stats.rx_frame_errors++;
988 if (status & RMD1_OFLO) lp->stats.rx_over_errors++;
989 if (status & RMD1_CRC) lp->stats.rx_crc_errors++;
990 if (status & RMD1_BUFF) lp->stats.rx_fifo_errors++;
991 head->flag &= (RMD1_ENP|RMD1_STP);
992 } else {
993
994 short pkt_len = head->msg_length & 0xfff;
995 struct sk_buff *skb;
996
997 if (pkt_len < 60) {
998 printk( "%s: Runt packet!\n", dev->name );
999 lp->stats.rx_errors++;
1000 }
1001 else {
1002 skb = dev_alloc_skb( pkt_len+2 );
1003 if (skb == NULL) {
1004 DPRINTK( 1, ( "%s: Memory squeeze, deferring packet.\n",
1005 dev->name ));
1006 for( i = 0; i < RX_RING_SIZE; i++ )
1007 if (MEM->rx_head[(entry+i) & RX_RING_MOD_MASK].flag &
1008 RMD1_OWN_CHIP)
1009 break;
1010
1011 if (i > RX_RING_SIZE - 2) {
1012 lp->stats.rx_dropped++;
1013 head->flag |= RMD1_OWN_CHIP;
1014 lp->cur_rx++;
1015 }
1016 break;
1017 }
1018
1019 if (lance_debug >= 3) {
1020 u_char *data = PKTBUF_ADDR(head), *p;
1021 printk( "%s: RX pkt type 0x%04x from ", dev->name,
1022 ((u_short *)data)[6]);
1023 for( p = &data[6], i = 0; i < 6; i++ )
1024 printk("%02x%s", *p++, i != 5 ? ":" : "" );
1025 printk(" to ");
1026 for( p = data, i = 0; i < 6; i++ )
1027 printk("%02x%s", *p++, i != 5 ? ":" : "" );
1028 printk(" data %02x %02x %02x %02x %02x %02x %02x %02x "
1029 "len %d\n",
1030 data[15], data[16], data[17], data[18],
1031 data[19], data[20], data[21], data[22],
1032 pkt_len );
1033 }
1034
1035 skb->dev = dev;
1036 skb_reserve( skb, 2 );
1037 skb_put( skb, pkt_len );
1038 lp->memcpy_f( skb->data, PKTBUF_ADDR(head), pkt_len );
1039 skb->protocol = eth_type_trans( skb, dev );
1040 netif_rx( skb );
1041 dev->last_rx = jiffies;
1042 lp->stats.rx_packets++;
1043 lp->stats.rx_bytes += pkt_len;
1044 }
1045 }
1046
1047 head->flag |= RMD1_OWN_CHIP;
1048 entry = (++lp->cur_rx) & RX_RING_MOD_MASK;
1049 }
1050 lp->cur_rx &= RX_RING_MOD_MASK;
1051
1052
1053
1054
1055
1056 return 0;
1057}
1058
1059
1060static int lance_close( struct net_device *dev )
1061
1062{ struct lance_private *lp = (struct lance_private *)dev->priv;
1063 struct lance_ioreg *IO = lp->iobase;
1064
1065 netif_stop_queue (dev);
1066
1067 AREG = CSR0;
1068
1069 DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n",
1070 dev->name, DREG ));
1071
1072
1073
1074 DREG = CSR0_STOP;
1075
1076 return 0;
1077}
1078
1079
1080static struct net_device_stats *lance_get_stats( struct net_device *dev )
1081
1082{ struct lance_private *lp = (struct lance_private *)dev->priv;
1083
1084 return &lp->stats;
1085}
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095static void set_multicast_list( struct net_device *dev )
1096
1097{ struct lance_private *lp = (struct lance_private *)dev->priv;
1098 struct lance_ioreg *IO = lp->iobase;
1099
1100 if (netif_running(dev))
1101
1102 return;
1103
1104
1105 DREG = CSR0_STOP;
1106
1107 if (dev->flags & IFF_PROMISC) {
1108
1109 DPRINTK( 1, ( "%s: Promiscuous mode enabled.\n", dev->name ));
1110 REGA( CSR15 ) = 0x8000;
1111 } else {
1112 short multicast_table[4];
1113 int num_addrs = dev->mc_count;
1114 int i;
1115
1116
1117 memset( multicast_table, (num_addrs == 0) ? 0 : -1,
1118 sizeof(multicast_table) );
1119 for( i = 0; i < 4; i++ )
1120 REGA( CSR8+i ) = multicast_table[i];
1121 REGA( CSR15 ) = 0;
1122 }
1123
1124
1125
1126
1127
1128 REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
1129
1130
1131 REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT;
1132}
1133
1134
1135
1136
1137static int lance_set_mac_address( struct net_device *dev, void *addr )
1138
1139{ struct lance_private *lp = (struct lance_private *)dev->priv;
1140 struct sockaddr *saddr = addr;
1141 int i;
1142
1143 if (lp->cardtype != OLD_RIEBL && lp->cardtype != NEW_RIEBL)
1144 return( -EOPNOTSUPP );
1145
1146 if (netif_running(dev)) {
1147
1148 DPRINTK( 1, ( "%s: hwaddr can be set only while card isn't open.\n",
1149 dev->name ));
1150 return( -EIO );
1151 }
1152
1153 memcpy( dev->dev_addr, saddr->sa_data, dev->addr_len );
1154 for( i = 0; i < 6; i++ )
1155 MEM->init.hwaddr[i] = dev->dev_addr[i^1];
1156 lp->memcpy_f( RIEBL_HWADDR_ADDR, dev->dev_addr, 6 );
1157
1158 *RIEBL_MAGIC_ADDR = RIEBL_MAGIC;
1159
1160 return( 0 );
1161}
1162
1163
1164#ifdef MODULE
1165static struct net_device atarilance_dev;
1166
1167int init_module(void)
1168
1169{ int err;
1170
1171 atarilance_dev.init = atarilance_probe;
1172 if ((err = register_netdev( &atarilance_dev ))) {
1173 if (err == -EIO) {
1174 printk( "No Atari Lance board found. Module not loaded.\n");
1175 }
1176 return( err );
1177 }
1178 return( 0 );
1179}
1180
1181void cleanup_module(void)
1182
1183{
1184 unregister_netdev( &atarilance_dev );
1185}
1186
1187#endif
1188
1189
1190
1191
1192
1193
1194
1195
1196