This source file includes following definitions.
- ni65_open
- ni65_close
- ni65_probe
- ni65_probe1
- am7990_reinit
- ni65_interrupt
- xmit_intr
- recv_intr
- ni65_send_packet
- ni65_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 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/string.h>
36 #include <linux/ptrace.h>
37 #include <linux/errno.h>
38 #include <linux/ioport.h>
39 #include <linux/malloc.h>
40 #include <linux/interrupt.h>
41 #include <asm/bitops.h>
42 #include <asm/io.h>
43 #include <asm/dma.h>
44
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/skbuff.h>
48
49 #include "ni65.h"
50
51
52
53
54
55 #ifndef HAVE_PORTRESERVE
56 #define check_region(ioaddr, size) 0
57 #define request_region(ioaddr, size,name) do ; while (0)
58 #endif
59
60 #ifndef NET_DEBUG
61 #define NET_DEBUG 2
62 #endif
63
64
65
66
67 #define NI65_TOTAL_SIZE 16
68
69 #define SA_ADDR0 0x02
70 #define SA_ADDR1 0x07
71 #define SA_ADDR2 0x01
72 #define CARD_ID0 0x00
73 #define CARD_ID1 0x55
74
75
76
77 #define PORT dev->base_addr
78
79 #define RMDNUM 8
80 #define RMDNUMMASK 0x6000
81 #define TMDNUM 4
82 #define TMDNUMMASK 0x4000
83
84 #define R_BUF_SIZE 1518
85 #define T_BUF_SIZE 1518
86
87 #define MEMSIZE 8+RMDNUM*8+TMDNUM*8
88
89 #define L_DATAREG 0x00
90 #define L_ADDRREG 0x02
91
92 #define L_RESET 0x04
93 #define L_CONFIG 0x05
94 #define L_EBASE 0x08
95
96
97
98
99
100 #define CSR0 0x00
101 #define CSR1 0x01
102 #define CSR2 0x02
103 #define CSR3 0x03
104
105
106 #undef NO_STATIC
107
108 #define writereg(val,reg) {outw(reg,PORT+L_ADDRREG);inw(PORT+L_ADDRREG); \
109 outw(val,PORT+L_DATAREG);inw(PORT+L_DATAREG);}
110 #define readreg(reg) (outw(reg,PORT+L_ADDRREG),inw(PORT+L_ADDRREG),\
111 inw(PORT+L_DATAREG))
112 #define writedatareg(val) {outw(val,PORT+L_DATAREG);inw(PORT+L_DATAREG);}
113
114 static int ni65_probe1(struct device *dev,int);
115 static void ni65_interrupt(int irq, struct pt_regs *regs);
116 static void recv_intr(struct device *dev);
117 static void xmit_intr(struct device *dev);
118 static int ni65_open(struct device *dev);
119 static int am7990_reinit(struct device *dev);
120 static int ni65_send_packet(struct sk_buff *skb, struct device *dev);
121 static int ni65_close(struct device *dev);
122 static struct enet_statistics *ni65_get_stats(struct device *);
123
124 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
125
126 struct priv
127 {
128 struct init_block ib;
129 void *memptr;
130 struct rmd *rmdhead;
131 struct tmd *tmdhead;
132 int rmdnum;
133 int tmdnum,tmdlast;
134 struct sk_buff *recv_skb[RMDNUM];
135 void *tmdbufs[TMDNUM];
136 int lock,xmit_queued;
137 struct enet_statistics stats;
138 };
139
140 int irqtab[] = { 9,12,15,5 };
141 int dmatab[] = { 0,3,5,6 };
142
143
144
145
146
147 static int ni65_open(struct device *dev)
148 {
149 if(am7990_reinit(dev))
150 {
151 dev->tbusy = 0;
152 dev->interrupt = 0;
153 dev->start = 1;
154 return 0;
155 }
156 else
157 {
158 dev->start = 0;
159 return -EAGAIN;
160 }
161 }
162
163 static int ni65_close(struct device *dev)
164 {
165 outw(0,PORT+L_RESET);
166 dev->tbusy = 1;
167 dev->start = 0;
168 return 0;
169 }
170
171
172
173
174
175
176 int ni65_probe(struct device *dev)
177 {
178 int *port, ports[] = {0x300,0x320,0x340,0x360, 0};
179 int base_addr = dev->base_addr;
180
181 if (base_addr > 0x1ff)
182 return ni65_probe1(dev, base_addr);
183 else if (base_addr > 0)
184 return ENXIO;
185
186 for (port = ports; *port; port++)
187 {
188 int ioaddr = *port;
189 if (check_region(ioaddr, NI65_TOTAL_SIZE))
190 continue;
191 if( !(inb(ioaddr+L_EBASE+6) == CARD_ID0) ||
192 !(inb(ioaddr+L_EBASE+7) == CARD_ID1) )
193 continue;
194 dev->base_addr = ioaddr;
195 if (ni65_probe1(dev, ioaddr) == 0)
196 return 0;
197 }
198
199 dev->base_addr = base_addr;
200 return ENODEV;
201 }
202
203
204 static int ni65_probe1(struct device *dev,int ioaddr)
205 {
206 int i;
207 unsigned char station_addr[6];
208 struct priv *p;
209
210 for(i=0;i<6;i++)
211 station_addr[i] = dev->dev_addr[i] = inb(PORT+L_EBASE+i);
212
213 if(station_addr[0] != SA_ADDR0 || station_addr[1] != SA_ADDR1)
214 {
215 printk("%s: wrong Hardaddress \n",dev->name);
216 return ENODEV;
217 }
218
219 if(dev->irq == 0)
220 dev->irq = irqtab[(inw(PORT+L_CONFIG)>>2)&3];
221 if(dev->dma == 0)
222 dev->dma = dmatab[inw(PORT+L_CONFIG)&3];
223
224 printk("%s: %s found at %#3lx, IRQ %d DMA %d.\n", dev->name,
225 "network card", dev->base_addr, dev->irq,dev->dma);
226
227 {
228 int irqval = request_irq(dev->irq, &ni65_interrupt,0,"ni65");
229 if (irqval) {
230 printk ("%s: unable to get IRQ %d (irqval=%d).\n",
231 dev->name,dev->irq, irqval);
232 return EAGAIN;
233 }
234 if(request_dma(dev->dma, "ni65") != 0)
235 {
236 printk("%s: Can't request dma-channel %d\n",dev->name,(int) dev->dma);
237 free_irq(dev->irq);
238 return EAGAIN;
239 }
240 }
241 irq2dev_map[dev->irq] = dev;
242
243
244 request_region(ioaddr,NI65_TOTAL_SIZE,"ni65");
245
246 p = dev->priv = (void *) kmalloc(sizeof(struct priv),GFP_KERNEL);
247 if (p == NULL)
248 return -ENOMEM;
249 memset((char *) dev->priv,0,sizeof(struct priv));
250
251 dev->open = ni65_open;
252 dev->stop = ni65_close;
253 dev->hard_start_xmit = ni65_send_packet;
254 dev->get_stats = ni65_get_stats;
255 dev->set_multicast_list = set_multicast_list;
256
257 ether_setup(dev);
258
259 dev->flags &= ~IFF_MULTICAST;
260 dev->interrupt = 0;
261 dev->tbusy = 0;
262 dev->start = 0;
263
264 if( (p->memptr = kmalloc(MEMSIZE,GFP_KERNEL)) == NULL) {
265 printk("%s: Can't alloc TMD/RMD-buffer.\n",dev->name);
266 return EAGAIN;
267 }
268 if( (unsigned long) (p->memptr + MEMSIZE) & 0xff000000) {
269 printk("%s: Can't alloc TMD/RMD buffer in lower 16MB!\n",dev->name);
270 return EAGAIN;
271 }
272 p->tmdhead = (struct tmd *) ((( (unsigned long)p->memptr ) + 8) & 0xfffffff8);
273 p->rmdhead = (struct rmd *) (p->tmdhead + TMDNUM);
274
275 #ifndef NO_STATIC
276 for(i=0;i<TMDNUM;i++)
277 {
278 if( (p->tmdbufs[i] = kmalloc(T_BUF_SIZE,GFP_ATOMIC)) == NULL) {
279 printk("%s: Can't alloc Xmit-Mem.\n",dev->name);
280 return EAGAIN;
281 }
282 if( (unsigned long) (p->tmdbufs[i]+T_BUF_SIZE) & 0xff000000) {
283 printk("%s: Can't alloc Xmit-Mem in lower 16MB!\n",dev->name);
284 return EAGAIN;
285 }
286 }
287 #endif
288
289 for(i=0;i<RMDNUM;i++)
290 {
291 if( (p->recv_skb[i] = dev_alloc_skb(R_BUF_SIZE)) == NULL) {
292 printk("%s: unable to alloc recv-mem\n",dev->name);
293 return EAGAIN;
294 }
295 if( (unsigned long) (p->recv_skb[i]->data + R_BUF_SIZE) & 0xff000000) {
296 printk("%s: unable to alloc receive-memory in lower 16MB!\n",dev->name);
297 return EAGAIN;
298 }
299 }
300
301 return 0;
302 }
303
304
305
306
307
308 static int am7990_reinit(struct device *dev)
309 {
310 int i,j;
311 struct tmd *tmdp;
312 struct rmd *rmdp;
313 struct priv *p = (struct priv *) dev->priv;
314
315 p->lock = 0;
316 p->xmit_queued = 0;
317
318 disable_dma(dev->dma);
319 set_dma_mode(dev->dma,DMA_MODE_CASCADE);
320 enable_dma(dev->dma);
321
322 outw(0,PORT+L_RESET);
323 if(inw(PORT+L_DATAREG) != 0x4)
324 {
325 printk("%s: can't RESET ni6510 card: %04x\n",dev->name,(int) inw(PORT+L_DATAREG));
326 disable_dma(dev->dma);
327 free_dma(dev->dma);
328 free_irq(dev->irq);
329 return 0;
330 }
331
332
333
334 memset(p->memptr,0,MEMSIZE);
335
336 p->tmdnum = 0; p->tmdlast = 0;
337 for(i=0;i<TMDNUM;i++)
338 {
339 tmdp = p->tmdhead + i;
340 #ifndef NO_STATIC
341 tmdp->u.buffer = (unsigned long) p->tmdbufs[i];
342 #endif
343 tmdp->u.s.status = XMIT_START | XMIT_END;
344 }
345
346 p->rmdnum = 0;
347 for(i=0;i<RMDNUM;i++)
348 {
349 rmdp = p->rmdhead + i;
350 rmdp->u.buffer = (unsigned long) p->recv_skb[i]->data;
351 rmdp->u.s.status = RCV_OWN;
352 rmdp->blen = -R_BUF_SIZE;
353 rmdp->mlen = 0;
354 }
355
356 for(i=0;i<6;i++)
357 {
358 p->ib.eaddr[i] = dev->dev_addr[i];
359 }
360 p->ib.mode = 0;
361 for(i=0;i<8;i++)
362 p->ib.filter[i] = 0;
363 p->ib.trplow = (unsigned short) (( (unsigned long) p->tmdhead ) & 0xffff);
364 p->ib.trphigh = (unsigned short) ((( (unsigned long) p->tmdhead )>>16) & 0x00ff) | TMDNUMMASK;
365 p->ib.rrplow = (unsigned short) (( (unsigned long) p->rmdhead ) & 0xffff);
366 p->ib.rrphigh = (unsigned short) ((( (unsigned long) p->rmdhead )>>16) & 0x00ff) | RMDNUMMASK;
367
368 writereg(0,CSR3);
369 writereg((unsigned short) (((unsigned long) &(p->ib)) & 0xffff),CSR1);
370 writereg((unsigned short) (((unsigned long) &(p->ib))>>16),CSR2);
371
372 writereg(CSR0_INIT,CSR0);
373
374
375
376
377
378 for(i=0;i<5;i++)
379 {
380 for(j=0;j<2000000;j++);
381 if(inw(PORT+L_DATAREG) & CSR0_IDON) break;
382 }
383 if(i == 5)
384 {
385 printk("%s: can't init am7990, status: %04x\n",dev->name,(int) inw(PORT+L_DATAREG));
386 disable_dma(dev->dma);
387 free_dma(dev->dma);
388 free_irq(dev->irq);
389 return 0;
390 }
391
392 writedatareg(CSR0_CLRALL | CSR0_INEA | CSR0_STRT);
393
394 return 1;
395 }
396
397
398
399
400
401 static void ni65_interrupt(int irq, struct pt_regs * regs)
402 {
403 int csr0;
404 struct device *dev = (struct device *) irq2dev_map[irq];
405
406 if (dev == NULL) {
407 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
408 return;
409 }
410
411 csr0 = inw(PORT+L_DATAREG);
412 writedatareg(csr0 & CSR0_CLRALL);
413
414 dev->interrupt = 1;
415
416 if(csr0 & CSR0_ERR)
417 {
418 struct priv *p = (struct priv *) dev->priv;
419
420 if(csr0 & CSR0_BABL)
421 p->stats.tx_errors++;
422 if(csr0 & CSR0_MISS)
423 p->stats.rx_errors++;
424 }
425
426 if(csr0 & CSR0_RINT)
427 {
428 recv_intr(dev);
429 }
430 if(csr0 & CSR0_TINT)
431 {
432 xmit_intr(dev);
433 }
434
435 writedatareg(CSR0_INEA);
436 dev->interrupt = 0;
437
438 return;
439 }
440
441
442
443
444
445
446 static void xmit_intr(struct device *dev)
447 {
448 int tmdstat;
449 struct tmd *tmdp;
450 struct priv *p = (struct priv *) dev->priv;
451
452 #ifdef NO_STATIC
453 struct sk_buff *skb;
454 #endif
455
456 while(p->xmit_queued)
457 {
458 tmdp = p->tmdhead + p->tmdlast;
459 tmdstat = tmdp->u.s.status;
460 if(tmdstat & XMIT_OWN)
461 break;
462 #ifdef NO_STATIC
463 skb = (struct sk_buff *) p->tmdbufs[p->tmdlast];
464 dev_kfree_skb(skb,FREE_WRITE);
465 #endif
466
467 if(tmdstat & XMIT_ERR)
468 {
469 printk("%s: xmit-error: %04x %04x\n",dev->name,(int) tmdstat,(int) tmdp->status2);
470 if(tmdp->status2 & XMIT_TDRMASK)
471 printk("%s: tdr-problems (e.g. no resistor)\n",dev->name);
472
473
474 if(tmdp->status2 & XMIT_RTRY)
475 p->stats.tx_aborted_errors++;
476 if(tmdp->status2 & XMIT_LCAR)
477 p->stats.tx_carrier_errors++;
478 p->stats.tx_errors++;
479 tmdp->status2 = 0;
480 }
481 else
482 p->stats.tx_packets++;
483
484 p->tmdlast = (p->tmdlast + 1) & (TMDNUM-1);
485 if(p->tmdlast == p->tmdnum)
486 p->xmit_queued = 0;
487 }
488
489 dev->tbusy = 0;
490 mark_bh(NET_BH);
491 }
492
493
494
495
496
497 static void recv_intr(struct device *dev)
498 {
499 struct rmd *rmdp;
500 int rmdstat,len;
501 struct sk_buff *skb,*skb1;
502 struct priv *p = (struct priv *) dev->priv;
503
504 rmdp = p->rmdhead + p->rmdnum;
505 while(!( (rmdstat = rmdp->u.s.status) & RCV_OWN))
506 {
507 if( (rmdstat & (RCV_START | RCV_END)) != (RCV_START | RCV_END) )
508 {
509 if(rmdstat & RCV_START)
510 {
511 p->stats.rx_errors++;
512 p->stats.rx_length_errors++;
513 printk("%s: packet too long\n",dev->name);
514 }
515 rmdp->u.s.status = RCV_OWN;
516 }
517 else if(rmdstat & RCV_ERR)
518 {
519 printk("%s: receive-error: %04x\n",dev->name,(int) rmdstat );
520 p->stats.rx_errors++;
521 if(rmdstat & RCV_FRAM) p->stats.rx_frame_errors++;
522 if(rmdstat & RCV_OFLO) p->stats.rx_over_errors++;
523 if(rmdstat & RCV_CRC) p->stats.rx_crc_errors++;
524 rmdp->u.s.status = RCV_OWN;
525 printk("%s: lance-status: %04x\n",dev->name,(int) inw(PORT+L_DATAREG));
526 }
527 else
528 {
529 len = (rmdp->mlen & 0x0fff) - 4;
530 skb = dev_alloc_skb(R_BUF_SIZE);
531 if(skb != NULL)
532 {
533 if( (unsigned long) (skb->data + R_BUF_SIZE) & 0xff000000) {
534 memcpy(skb_put(skb,len),p->recv_skb[p->rmdnum]->data,len);
535 skb1 = skb;
536 }
537 else {
538 skb1 = p->recv_skb[p->rmdnum];
539 p->recv_skb[p->rmdnum] = skb;
540 rmdp->u.buffer = (unsigned long) skb_put(skb1,len);
541 }
542 rmdp->u.s.status = RCV_OWN;
543 rmdp->mlen = 0;
544 skb1->dev = dev;
545 p->stats.rx_packets++;
546 skb1->protocol=eth_type_trans(skb1,dev);
547 netif_rx(skb1);
548 }
549 else
550 {
551 rmdp->u.s.status = RCV_OWN;
552 printk("%s: can't alloc new sk_buff\n",dev->name);
553 p->stats.rx_dropped++;
554 }
555 }
556 p->rmdnum++; p->rmdnum &= RMDNUM-1;
557 rmdp = p->rmdhead + p->rmdnum;
558 }
559 }
560
561
562
563
564
565 static int ni65_send_packet(struct sk_buff *skb, struct device *dev)
566 {
567 struct priv *p = (struct priv *) dev->priv;
568 struct tmd *tmdp;
569
570 if(dev->tbusy)
571 {
572 int tickssofar = jiffies - dev->trans_start;
573 if (tickssofar < 25)
574 return 1;
575
576 printk("%s: xmitter timed out, try to restart!\n",dev->name);
577 am7990_reinit(dev);
578 dev->tbusy=0;
579 dev->trans_start = jiffies;
580 }
581
582 if(skb == NULL)
583 {
584 dev_tint(dev);
585 return 0;
586 }
587
588 if (skb->len <= 0)
589 return 0;
590
591 if (set_bit(0, (void*)&dev->tbusy) != 0)
592 {
593 printk("%s: Transmitter access conflict.\n", dev->name);
594 return 1;
595 }
596 if(set_bit(0,(void*) &p->lock) != 0)
597 {
598 printk("%s: Queue was locked!\n",dev->name);
599 return 1;
600 }
601
602 {
603 short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
604
605 tmdp = p->tmdhead + p->tmdnum;
606
607 #ifdef NO_STATIC
608 tmdp->u.buffer = (unsigned long) (skb->data);
609 p->tmdbufs[p->tmdnum] = skb;
610 #else
611 memcpy((char *) (tmdp->u.buffer & 0x00ffffff),(char *)skb->data,skb->len);
612 dev_kfree_skb (skb, FREE_WRITE);
613 #endif
614 tmdp->blen = -len;
615 tmdp->u.s.status = XMIT_OWN | XMIT_START | XMIT_END;
616
617 cli();
618 p->xmit_queued = 1;
619 writedatareg(CSR0_TDMD | CSR0_INEA);
620 p->tmdnum++; p->tmdnum &= TMDNUM-1;
621
622 if( !((p->tmdhead + p->tmdnum)->u.s.status & XMIT_OWN) )
623 dev->tbusy = 0;
624 p->lock = 0;
625 sti();
626
627 dev->trans_start = jiffies;
628
629 }
630
631 return 0;
632 }
633
634 static struct enet_statistics *ni65_get_stats(struct device *dev)
635 {
636 return &((struct priv *) dev->priv)->stats;
637 }
638
639 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs)
640 {
641 }
642
643
644
645
646