This source file includes following definitions.
- ni52_close
- ni52_open
- check586
- alloc586
- ni52_probe
- ni52_probe1
- init586
- alloc_rfa
- ni52_interrupt
- ni52_rcv_int
- ni52_rnr_int
- ni52_xmt_int
- startrecv586
- ni52_send_packet
- ni52_get_stats
- set_multicast_list
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 #include <linux/kernel.h>
81 #include <linux/sched.h>
82 #include <linux/string.h>
83 #include <linux/errno.h>
84 #include <linux/ioport.h>
85 #include <linux/malloc.h>
86 #include <linux/interrupt.h>
87 #include <linux/delay.h>
88 #include <asm/bitops.h>
89 #include <asm/io.h>
90
91 #include <linux/netdevice.h>
92 #include <linux/etherdevice.h>
93 #include <linux/skbuff.h>
94
95 #include "ni52.h"
96
97 #define DEBUG
98 #define SYSBUSVAL 1
99
100 #define ni_attn586() {outb(0,dev->base_addr+NI52_ATTENTION);}
101 #define ni_reset586() {outb(0,dev->base_addr+NI52_RESET);}
102
103 #define make32(ptr16) (p->memtop + (short) (ptr16) )
104 #define make24(ptr32) ((char *) (ptr32) - p->base)
105 #define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop ))
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 #define RECV_BUFF_SIZE 1524
122 #define XMIT_BUFF_SIZE 1524
123 #define NUM_XMIT_BUFFS 1
124 #define NUM_RECV_BUFFS_8 4
125 #define NUM_RECV_BUFFS_16 9
126 #define NO_NOPCOMMANDS
127
128
129
130 #define DELAY(x) {int i=jiffies; \
131 if(loops_per_sec == 1) \
132 while(i+(x)>jiffies); \
133 else \
134 __delay((loops_per_sec>>5)*x); \
135 }
136
137
138 #define DELAY_16(); { __delay( (loops_per_sec>>16)+1 ); }
139
140
141 #define WAIT_4_SCB_CMD() { int i; \
142 for(i=0;i<1024;i++) { \
143 if(!p->scb->cmd) break; \
144 DELAY_16(); \
145 if(i == 1023) { \
146 printk("%s: scb_cmd timed out .. resetting i82586\n",dev->name); \
147 ni_reset586(); } } }
148
149 extern void autoirq_setup(int waittime);
150 extern int autoirq_report(int waittime);
151 extern void *irq2dev_map[16];
152
153 #define NI52_TOTAL_SIZE 16
154 #define NI52_ADDR0 0x02
155 #define NI52_ADDR1 0x07
156 #define NI52_ADDR2 0x01
157
158 #ifndef HAVE_PORTRESERVE
159 #define check_region(ioaddr, size) 0
160 #define request_region(ioaddr, size,name) do ; while (0)
161 #endif
162
163 static int ni52_probe1(struct device *dev,int ioaddr);
164 static void ni52_interrupt(int irq,struct pt_regs *reg_ptr);
165 static int ni52_open(struct device *dev);
166 static int ni52_close(struct device *dev);
167 static int ni52_send_packet(struct sk_buff *,struct device *);
168 static struct enet_statistics *ni52_get_stats(struct device *dev);
169 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
170
171
172 static int init586(struct device *dev,int num_addrs,void *addrs);
173 static int check586(struct device *dev,char *where,unsigned size);
174 static void alloc586(struct device *dev);
175 static void startrecv586(struct device *dev);
176 static void *alloc_rfa(struct device *dev,void *ptr);
177 static void ni52_rcv_int(struct device *dev);
178 static void ni52_xmt_int(struct device *dev);
179 static void ni52_rnr_int(struct device *dev);
180
181 struct priv
182 {
183 struct enet_statistics stats;
184 unsigned long base;
185 char *memtop;
186 volatile struct rfd_struct *rfd_last,*rfd_top,*rfd_first;
187 volatile struct scp_struct *scp;
188 volatile struct iscp_struct *iscp;
189 volatile struct scb_struct *scb;
190 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
191 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
192 #if (NUM_XMIT_BUFFS == 1)
193 volatile struct nop_cmd_struct *nop_cmds[2];
194 #else
195 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
196 #endif
197 volatile int nop_point,num_recv_buffs;
198 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
199 volatile int xmit_count,xmit_last;
200 };
201
202
203
204
205
206
207 static int ni52_close(struct device *dev)
208 {
209 free_irq(dev->irq);
210 irq2dev_map[dev->irq] = 0;
211
212 ni_reset586();
213
214 dev->start = 0;
215 dev->tbusy = 0;
216
217 return 0;
218 }
219
220
221
222
223
224 static int ni52_open(struct device *dev)
225 {
226 alloc586(dev);
227 init586(dev,0,NULL);
228 startrecv586(dev);
229
230 if(request_irq(dev->irq, &ni52_interrupt,0,"ni52"))
231 {
232 ni_reset586();
233 return -EAGAIN;
234 }
235 irq2dev_map[dev->irq] = dev;
236
237 dev->interrupt = 0;
238 dev->tbusy = 0;
239 dev->start = 1;
240
241 return 0;
242 }
243
244
245
246
247
248 static int check586(struct device *dev,char *where,unsigned size)
249 {
250 struct priv *p = (struct priv *) dev->priv;
251 char *iscp_addrs[2];
252 int i;
253
254 p->base = (unsigned long) where + size - 0x01000000;
255 p->memtop = where + size;
256 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
257 memset((char *)p->scp,0, sizeof(struct scp_struct));
258 p->scp->sysbus = SYSBUSVAL;
259
260 iscp_addrs[0] = where;
261 iscp_addrs[1]= (char *) p->scp - sizeof(struct iscp_struct);
262
263 for(i=0;i<2;i++)
264 {
265 p->iscp = (struct iscp_struct *) iscp_addrs[i];
266 memset((char *)p->iscp,0, sizeof(struct iscp_struct));
267
268 p->scp->iscp = make24(p->iscp);
269 p->iscp->busy = 1;
270
271 ni_reset586();
272 ni_attn586();
273 DELAY(2);
274
275 if(p->iscp->busy)
276 return 0;
277 }
278 return 1;
279 }
280
281
282
283
284
285 void alloc586(struct device *dev)
286 {
287 struct priv *p = (struct priv *) dev->priv;
288
289 ni_reset586();
290 DELAY(2);
291
292 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
293 p->scb = (struct scb_struct *) (dev->mem_start);
294 p->iscp = (struct iscp_struct *) ((char *)p->scp - sizeof(struct iscp_struct));
295
296 memset((char *) p->iscp,0,sizeof(struct iscp_struct));
297 memset((char *) p->scp ,0,sizeof(struct scp_struct));
298
299 p->scp->iscp = make24(p->iscp);
300 p->scp->sysbus = SYSBUSVAL;
301 p->iscp->scb_offset = make16(p->scb);
302
303 p->iscp->busy = 1;
304 ni_reset586();
305 ni_attn586();
306
307 DELAY(2);
308
309 if(p->iscp->busy)
310 printk("%s: Init-Problems (alloc).\n",dev->name);
311
312 memset((char *)p->scb,0,sizeof(struct scb_struct));
313 }
314
315
316
317
318
319 int ni52_probe(struct device *dev)
320 {
321 int *port, ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
322 int base_addr = dev->base_addr;
323
324 if (base_addr > 0x1ff)
325 if( (inb(base_addr+NI52_MAGIC1) == NI52_MAGICVAL1) &&
326 (inb(base_addr+NI52_MAGIC2) == NI52_MAGICVAL2))
327 return ni52_probe1(dev, base_addr);
328 else if (base_addr > 0)
329 return ENXIO;
330
331 for (port = ports; *port; port++) {
332 int ioaddr = *port;
333 if (check_region(ioaddr, NI52_TOTAL_SIZE))
334 continue;
335 if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
336 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2))
337 continue;
338
339 dev->base_addr = ioaddr;
340 if (ni52_probe1(dev, ioaddr) == 0)
341 return 0;
342 }
343
344 dev->base_addr = base_addr;
345 return ENODEV;
346 }
347
348 static int ni52_probe1(struct device *dev,int ioaddr)
349 {
350 long memaddrs[] = { 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000,0xd8000, 0 };
351 int i,size;
352
353 for(i=0;i<ETH_ALEN;i++)
354 dev->dev_addr[i] = inb(dev->base_addr+i);
355
356 if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
357 || dev->dev_addr[2] != NI52_ADDR2)
358 return ENODEV;
359
360 printk("%s: Ni52 found at %#3x, ",dev->name,dev->base_addr);
361
362 request_region(ioaddr,NI52_TOTAL_SIZE,"ni52");
363
364 dev->priv = (void *) kmalloc(sizeof(struct priv),GFP_KERNEL);
365
366 memset((char *) dev->priv,0,sizeof(struct priv));
367
368
369
370
371 if(dev->mem_start != 0)
372 {
373 size = 0x4000;
374 if(!check586(dev,(char *) dev->mem_start,size)) {
375 size = 0x2000;
376 if(!check586(dev,(char *) dev->mem_start,size)) {
377 printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start);
378 return ENODEV;
379 }
380 }
381 }
382 else
383 {
384 for(i=0;;i++)
385 {
386 if(!memaddrs[i]) {
387 printk("?memprobe, Can't find io-memory!\n");
388 return ENODEV;
389 }
390 dev->mem_start = memaddrs[i];
391 size = 0x2000;
392 if(check586(dev,(char *)dev->mem_start,size))
393 break;
394 size = 0x4000;
395 if(check586(dev,(char *)dev->mem_start,size))
396 break;
397 }
398 }
399 dev->mem_end = dev->mem_start + size;
400
401 ((struct priv *) (dev->priv))->base = dev->mem_start + size - 0x01000000;
402 alloc586(dev);
403
404
405 if(size == 0x2000)
406 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8;
407 else
408 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16;
409
410 printk("Memaddr: 0x%lx, Memsize: %d, ",dev->mem_start,size);
411
412 if(dev->irq < 2)
413 {
414 autoirq_setup(0);
415 ni_reset586();
416 ni_attn586();
417 if(!(dev->irq = autoirq_report(2)))
418 {
419 printk("?autoirq, Failed to detect IRQ line!\n");
420 return 1;
421 }
422 }
423 else if(dev->irq == 2)
424 dev->irq = 9;
425
426 printk("IRQ %d.\n",dev->irq);
427
428 dev->open = &ni52_open;
429 dev->stop = &ni52_close;
430 dev->get_stats = &ni52_get_stats;
431 dev->hard_start_xmit = &ni52_send_packet;
432 dev->set_multicast_list = &set_multicast_list;
433
434 dev->if_port = 0;
435
436 ether_setup(dev);
437
438 dev->tbusy = 0;
439 dev->interrupt = 0;
440 dev->start = 0;
441
442 return 0;
443 }
444
445
446
447
448
449
450 static int init586(struct device *dev,int num_addrs,void *addrs)
451 {
452 void *ptr;
453 unsigned long s;
454 int i,result=0;
455 struct priv *p = (struct priv *) dev->priv;
456 volatile struct configure_cmd_struct *cfg_cmd;
457 volatile struct iasetup_cmd_struct *ias_cmd;
458 volatile struct tdr_cmd_struct *tdr_cmd;
459 volatile struct mcsetup_cmd_struct *mc_cmd;
460
461 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
462
463 cfg_cmd = (struct configure_cmd_struct *)ptr;
464 cfg_cmd->cmd_status = 0;
465 cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
466 cfg_cmd->cmd_link = 0xffff;
467
468 cfg_cmd->byte_cnt = 0x0a;
469 cfg_cmd->fifo = 0x08;
470 cfg_cmd->sav_bf = 0x40;
471 cfg_cmd->adr_len = 0x2e;
472 cfg_cmd->priority = 0x00;
473 cfg_cmd->ifs = 0x60;
474 cfg_cmd->time_low = 0x00;
475 cfg_cmd->time_high = 0xf2;
476 cfg_cmd->promisc = (num_addrs < 0) ? 1 : 0;
477 cfg_cmd->carr_coll = 0x00;
478
479 p->scb->cbl_offset = make16(cfg_cmd);
480
481 p->scb->cmd = CUC_START;
482 ni_attn586();
483
484 s = jiffies;
485 while(!(cfg_cmd->cmd_status & STAT_COMPL))
486 if(jiffies-s > 30) break;
487
488 if((cfg_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK))
489 {
490 printk("%s (ni52): configure command failed: %x\n",dev->name,cfg_cmd->cmd_status);
491 return 1;
492 }
493
494
495
496
497 ias_cmd = (struct iasetup_cmd_struct *)ptr;
498
499 ias_cmd->cmd_status = 0;
500 ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST;
501 ias_cmd->cmd_link = 0xffff;
502
503 memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN);
504
505 p->scb->cbl_offset = make16(ias_cmd);
506
507 p->scb->cmd = CUC_START;
508 ni_attn586();
509
510 s = jiffies;
511 while(!(ias_cmd->cmd_status & STAT_COMPL))
512 if(jiffies-s > 30) break;
513
514 if((ias_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) {
515 printk("%s (ni52): individual address setup command failed: %04x\n",dev->name,ias_cmd->cmd_status);
516 return 1;
517 }
518
519
520
521
522 tdr_cmd = (struct tdr_cmd_struct *)ptr;
523
524 tdr_cmd->cmd_status = 0;
525 tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
526 tdr_cmd->cmd_link = 0xffff;
527 tdr_cmd->status = 0;
528
529 p->scb->cbl_offset = make16(tdr_cmd);
530
531 p->scb->cmd = CUC_START;
532 ni_attn586();
533
534 s = jiffies;
535 while(!(tdr_cmd->cmd_status & STAT_COMPL))
536 if(jiffies - s > 30) {
537 printk("%s: Problems while running the TDR.\n",dev->name);
538 result = 1;
539 }
540
541 if(!result)
542 {
543 DELAY(2);
544 result = tdr_cmd->status;
545
546 p->scb->cmd = p->scb->status & STAT_MASK;
547 ni_attn586();
548
549 if(result & TDR_LNK_OK) ;
550 else if(result & TDR_XCVR_PRB)
551 printk("%s: TDR: Transceiver problem!\n",dev->name);
552 else if(result & TDR_ET_OPN)
553 printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
554 else if(result & TDR_ET_SRT)
555 {
556 if (result & TDR_TIMEMASK)
557 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
558 }
559 else
560 printk("%s: TDR: Unknown status %04x\n",dev->name,result);
561 }
562
563
564
565
566 p->scb->cmd = p->scb->status & STAT_MASK;
567 ni_attn586();
568
569
570
571
572 #if (NUM_XMIT_BUFFS == 1)
573 for(i=0;i<2;i++)
574 {
575 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
576 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
577 p->nop_cmds[i]->cmd_status = 0;
578 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
579 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
580 }
581 p->xmit_cmds[0] = (struct transmit_cmd_struct *)ptr;
582 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
583 #else
584 for(i=0;i<NUM_XMIT_BUFFS;i++)
585 {
586 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
587 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
588 p->nop_cmds[i]->cmd_status = 0;
589 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
590 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
591 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr;
592 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
593 }
594 #endif
595
596 ptr = alloc_rfa(dev,(void *)ptr);
597
598
599
600
601
602 if(num_addrs > 0)
603 {
604 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
605 if(len <= 0)
606 {
607 printk("%s: Ooooops, no memory for MC-Setup!\n",dev->name);
608 }
609 else
610 {
611 if(len < num_addrs)
612 {
613 num_addrs = len;
614 printk("%s: Sorry, can only apply %d MC-Address(es).\n",dev->name,num_addrs);
615 }
616 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
617 mc_cmd->cmd_status = 0;
618 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
619 mc_cmd->cmd_link = 0xffff;
620 mc_cmd->mc_cnt = num_addrs * 6;
621 for(i=0;i<num_addrs;i++)
622 memcpy((char *) mc_cmd->mc_list[i],((char (*)[6]) addrs)[i],6);
623 p->scb->cbl_offset = make16(mc_cmd);
624 p->scb->cmd = CUC_START;
625 ni_attn586();
626 s = jiffies;
627 while(!(mc_cmd->cmd_status & STAT_COMPL))
628 if(jiffies - s > 30)
629 break;
630 if(!(mc_cmd->cmd_status & STAT_COMPL))
631 printk("%s: Can't apply multicast-address-list.\n",dev->name);
632 }
633 }
634
635
636
637
638 for(i=0;i<NUM_XMIT_BUFFS;i++)
639 {
640 p->xmit_cbuffs[i] = (char *)ptr;
641 ptr = (char *) ptr + XMIT_BUFF_SIZE;
642 p->xmit_buffs[i] = (struct tbd_struct *)ptr;
643 ptr = (char *) ptr + sizeof(struct tbd_struct);
644 if((void *)ptr > (void *)p->iscp)
645 {
646 printk("%s: not enough shared-mem for your configuration!\n",dev->name);
647 return 1;
648 }
649 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct));
650 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct));
651 p->xmit_cmds[i]->cmd_status = STAT_COMPL;
652 p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
653 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
654 p->xmit_buffs[i]->next = 0xffff;
655 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
656 }
657
658 p->xmit_count = 0;
659 p->xmit_last = 0;
660 #ifndef NO_NOPCOMMANDS
661 p->nop_point = 0;
662 #endif
663
664
665
666
667 #ifndef NO_NOPCOMMANDS
668 p->scb->cbl_offset = make16(p->nop_cmds[0]);
669 p->scb->cmd = CUC_START;
670 ni_attn586();
671 WAIT_4_SCB_CMD();
672 #else
673 p->xmit_cmds[0]->cmd_link = 0xffff;
674 p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_LAST | CMD_INT;
675 #endif
676
677 return 0;
678 }
679
680
681
682
683
684
685 static void *alloc_rfa(struct device *dev,void *ptr)
686 {
687 volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr;
688 volatile struct rbd_struct *rbd;
689 int i;
690 struct priv *p = (struct priv *) dev->priv;
691
692 memset((char *) rfd,0,sizeof(struct rfd_struct)*p->num_recv_buffs);
693 p->rfd_first = rfd;
694
695 for(i = 0; i < p->num_recv_buffs; i++)
696 rfd[i].next = make16(rfd + (i+1) % p->num_recv_buffs);
697 rfd[p->num_recv_buffs-1].last = RFD_SUSP;
698
699 ptr = (void *) (rfd + p->num_recv_buffs);
700
701 rbd = (struct rbd_struct *) ptr;
702 ptr = (void *) (rbd + p->num_recv_buffs);
703
704
705 memset((char *) rbd,0,sizeof(struct rbd_struct)*p->num_recv_buffs);
706
707 for(i=0;i<p->num_recv_buffs;i++)
708 {
709 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs));
710 rbd[i].size = RECV_BUFF_SIZE;
711 rbd[i].buffer = make24(ptr);
712 ptr = (char *) ptr + RECV_BUFF_SIZE;
713 }
714
715 p->rfd_top = p->rfd_first;
716 p->rfd_last = p->rfd_first + p->num_recv_buffs - 1;
717
718 p->scb->rfa_offset = make16(p->rfd_first);
719 p->rfd_first->rbd_offset = make16(rbd);
720
721 return ptr;
722 }
723
724
725
726
727
728
729 static void ni52_interrupt(int irq,struct pt_regs *reg_ptr)
730 {
731 struct device *dev = (struct device *) irq2dev_map[irq];
732 unsigned short stat;
733 struct priv *p;
734
735 if (dev == NULL) {
736 printk ("ni52-interrupt: irq %d for unknown device.\n",(int) -(((struct pt_regs *)reg_ptr)->orig_eax+2));
737 return;
738 }
739 p = (struct priv *) dev->priv;
740
741 dev->interrupt = 1;
742
743 while((stat=p->scb->status & STAT_MASK))
744 {
745 p->scb->cmd = stat;
746 ni_attn586();
747
748 if(stat & STAT_CX)
749 ni52_xmt_int(dev);
750
751 if(stat & STAT_FR)
752 ni52_rcv_int(dev);
753
754 #ifndef NO_NOPCOMMANDS
755 if(stat & STAT_CNA)
756 {
757 if(dev->start)
758 printk("%s: oops! CU has left active state. stat: %04x/%04x.\n",dev->name,(int) stat,(int) p->scb->status);
759 }
760 #endif
761
762 if(stat & STAT_RNR)
763 {
764 if(p->scb->status & RU_SUSPEND)
765 {
766 WAIT_4_SCB_CMD();
767 p->scb->cmd = RUC_RESUME;
768 ni_attn586();
769 }
770 else
771 {
772 printk("%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n",dev->name,(int) stat,(int) p->scb->status);
773 ni52_rnr_int(dev);
774 }
775 }
776 WAIT_4_SCB_CMD();
777 if(p->scb->cmd)
778 break;
779 }
780
781 dev->interrupt = 0;
782 }
783
784
785
786
787
788 static void ni52_rcv_int(struct device *dev)
789 {
790 int status;
791 unsigned short totlen;
792 struct sk_buff *skb;
793 struct rbd_struct *rbd;
794 struct priv *p = (struct priv *) dev->priv;
795
796 for(;(status = p->rfd_top->status) & STAT_COMPL;)
797 {
798 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
799
800 if(status & STAT_OK)
801 {
802 if( (totlen = rbd->status) & RBD_LAST)
803 {
804 totlen &= RBD_MASK;
805 rbd->status = 0;
806 skb = (struct sk_buff *) alloc_skb(totlen, GFP_ATOMIC);
807 if(skb != NULL)
808 {
809 skb->len = totlen;
810 skb->dev = dev;
811 memcpy( (char *) skb->data,(char *) p->base+(unsigned long) rbd->buffer, totlen);
812 netif_rx(skb);
813 p->stats.rx_packets++;
814 }
815 else
816 p->stats.rx_dropped++;
817 }
818 else
819 {
820 printk("%s: received oversized frame.\n",dev->name);
821 p->stats.rx_dropped++;
822 }
823 }
824 else
825 {
826 printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
827 p->stats.rx_errors++;
828 }
829 p->rfd_top->status = 0;
830 p->rfd_top->last = RFD_SUSP;
831 p->rfd_last->last = 0;
832 p->rfd_last = p->rfd_top;
833 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next);
834 }
835 }
836
837
838
839
840
841 static void ni52_rnr_int(struct device *dev)
842 {
843 struct priv *p = (struct priv *) dev->priv;
844
845 p->stats.rx_errors++;
846
847 WAIT_4_SCB_CMD();
848 p->scb->cmd = RUC_ABORT;
849 ni_attn586();
850 WAIT_4_SCB_CMD();
851
852 alloc_rfa(dev,(char *)p->rfd_first);
853 startrecv586(dev);
854
855 printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->status);
856
857 }
858
859
860
861
862
863 static void ni52_xmt_int(struct device *dev)
864 {
865 int status;
866 struct priv *p = (struct priv *) dev->priv;
867
868 status = p->xmit_cmds[p->xmit_last]->cmd_status;
869 if(!(status & STAT_COMPL))
870 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name);
871
872 if(status & STAT_OK)
873 {
874 p->stats.tx_packets++;
875 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
876 }
877 else
878 {
879 p->stats.tx_errors++;
880 if(status & TCMD_LATECOLL) {
881 printk("%s: late collision detected.\n",dev->name);
882 p->stats.collisions++;
883 }
884 else if(status & TCMD_NOCARRIER) {
885 p->stats.tx_carrier_errors++;
886 printk("%s: no carrier detected.\n",dev->name);
887 }
888 else if(status & TCMD_LOSTCTS)
889 printk("%s: loss of CTS detected.\n",dev->name);
890 else if(status & TCMD_UNDERRUN) {
891 p->stats.tx_fifo_errors++;
892 printk("%s: DMA underrun detected.\n",dev->name);
893 }
894 else if(status & TCMD_MAXCOLL) {
895 printk("%s: Max. collisions exceeded.\n",dev->name);
896 p->stats.collisions += 16;
897 }
898 }
899
900 #if (NUM_XMIT_BUFFS != 1)
901 if( (++p->xmit_last) == NUM_XMIT_BUFFS)
902 p->xmit_last = 0;
903 #endif
904
905 dev->tbusy = 0;
906 mark_bh(NET_BH);
907 }
908
909
910
911
912
913 static void startrecv586(struct device *dev)
914 {
915 struct priv *p = (struct priv *) dev->priv;
916
917 p->scb->rfa_offset = make16(p->rfd_first);
918 p->scb->cmd = RUC_START;
919 ni_attn586();
920 WAIT_4_SCB_CMD();
921 }
922
923
924
925
926
927 static int ni52_send_packet(struct sk_buff *skb, struct device *dev)
928 {
929 int len,i;
930 #ifndef NO_NOPCOMMANDS
931 int next_nop;
932 #endif
933 struct priv *p = (struct priv *) dev->priv;
934
935 if(dev->tbusy)
936 {
937 int tickssofar = jiffies - dev->trans_start;
938 if (tickssofar < 5)
939 return 1;
940
941 if(p->scb->status & CU_ACTIVE)
942 {
943 dev->tbusy = 0;
944 #ifdef DEBUG
945 printk("%s: strange ... timeout with CU active?!?\n",dev->name);
946 printk("%s: X0: %04x N0: %04x N1: %04x %d\n",dev->name,(int)p->xmit_cmds[0]->cmd_status,(int)p->nop_cmds[0]->cmd_status,(int)p->nop_cmds[1]->cmd_status,(int)p->nop_point);
947 #endif
948 p->scb->cmd = CUC_ABORT;
949 ni_attn586();
950 WAIT_4_SCB_CMD();
951 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
952 p->scb->cmd = CUC_START;
953 ni_attn586();
954 WAIT_4_SCB_CMD();
955 dev->trans_start = jiffies;
956 return 0;
957 }
958 else
959 {
960 #ifdef DEBUG
961 printk("%s: xmitter timed out, try to restart! stat: %04x\n",dev->name,p->scb->status);
962 printk("%s: command-stats: %04x %04x\n",dev->name,p->xmit_cmds[0]->cmd_status,p->xmit_cmds[1]->cmd_status);
963 #endif
964 ni52_close(dev);
965 ni52_open(dev);
966 }
967 dev->trans_start = jiffies;
968 return 0;
969 }
970
971 if(skb == NULL)
972 {
973 dev_tint(dev);
974 return 0;
975 }
976
977 if (skb->len <= 0)
978 return 0;
979 if(skb->len > XMIT_BUFF_SIZE)
980 {
981 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %ld bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
982 return 0;
983 }
984
985 if (set_bit(0, (void*)&dev->tbusy) != 0)
986 printk("%s: Transmitter access conflict.\n", dev->name);
987 else
988 {
989 memcpy((char *)p->xmit_cbuffs[p->xmit_count],(char *)(skb->data),skb->len);
990 len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
991
992 #if (NUM_XMIT_BUFFS == 1)
993 # ifdef NO_NOPCOMMANDS
994 p->xmit_buffs[0]->size = TBD_LAST | len;
995 for(i=0;i<16;i++)
996 {
997 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
998 p->scb->cmd = CUC_START;
999 p->xmit_cmds[0]->cmd_status = 0;
1000
1001 ni_attn586();
1002 dev->trans_start = jiffies;
1003 if(!i)
1004 dev_kfree_skb(skb,FREE_WRITE);
1005 WAIT_4_SCB_CMD();
1006 if( (p->scb->status & CU_ACTIVE))
1007 break;
1008 if(p->xmit_cmds[0]->cmd_status)
1009 break;
1010 if(i==15)
1011 printk("%s: Can't start transmit-command.\n",dev->name);
1012 }
1013 # else
1014 next_nop = (p->nop_point + 1) & 0x1;
1015 p->xmit_buffs[0]->size = TBD_LAST | len;
1016
1017 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1018 = make16((p->nop_cmds[next_nop]));
1019 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1020
1021 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1022 dev->trans_start = jiffies;
1023 p->nop_point = next_nop;
1024 dev_kfree_skb(skb,FREE_WRITE);
1025 # endif
1026 #else
1027 p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
1028 if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS )
1029 next_nop = 0;
1030
1031 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1032 p->xmit_cmds[p->xmit_count]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1033 = make16((p->nop_cmds[next_nop]));
1034 p->nop_cmds[next_nop]->cmd_status = 0;
1035
1036 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
1037 dev->trans_start = jiffies;
1038 p->xmit_count = next_nop;
1039
1040 cli();
1041 if(p->xmit_count != p->xmit_last)
1042 dev->tbusy = 0;
1043 sti();
1044 dev_kfree_skb(skb,FREE_WRITE);
1045 #endif
1046 }
1047 return 0;
1048 }
1049
1050
1051
1052
1053
1054 static struct enet_statistics *ni52_get_stats(struct device *dev)
1055 {
1056 struct priv *p = (struct priv *) dev->priv;
1057 unsigned short crc,aln,rsc,ovrn;
1058
1059 crc = p->scb->crc_errs;
1060 p->scb->crc_errs -= crc;
1061 aln = p->scb->aln_errs;
1062 p->scb->aln_errs -= aln;
1063 rsc = p->scb->rsc_errs;
1064 p->scb->rsc_errs -= rsc;
1065 ovrn = p->scb->ovrn_errs;
1066 p->scb->ovrn_errs -= ovrn;
1067
1068 p->stats.rx_crc_errors += crc;
1069 p->stats.rx_fifo_errors += ovrn;
1070 p->stats.rx_frame_errors += aln;
1071 p->stats.rx_dropped += rsc;
1072
1073 return &p->stats;
1074 }
1075
1076
1077
1078
1079
1080 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs)
1081 {
1082 if(!dev->start && !num_addrs)
1083 {
1084 printk("%s: Can't apply promiscuous/multicastmode to a not running interface.\n",dev->name);
1085 return;
1086 }
1087
1088 dev->start = 0;
1089 alloc586(dev);
1090 init586(dev,num_addrs,addrs);
1091 startrecv586(dev);
1092 dev->start = 1;
1093 }
1094
1095
1096
1097