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