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