This source file includes following definitions.
- init_rx_bufs
- init_i596_mem
- i596_rx
- i596_cleanup_cmd
- i596_reset
- i596_add_cmd
- i596_open
- i596_start_xmit
- print_eth
- apricot_init
- i596_interrupt
- i596_close
- i596_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 static char *version = "apricot.c:v0.02 19/05/94\n";
21
22 #include <linux/config.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/string.h>
26 #include <linux/ptrace.h>
27 #include <linux/errno.h>
28 #include <linux/ioport.h>
29 #include <linux/malloc.h>
30 #include <linux/interrupt.h>
31 #include <asm/bitops.h>
32 #include <asm/io.h>
33 #include <asm/dma.h>
34
35 #include <linux/netdevice.h>
36 #include <linux/etherdevice.h>
37 #include <linux/skbuff.h>
38
39 #ifndef HAVE_PORTRESERVE
40 #define check_region(addr, size) 0
41 #define snarf_region(addr, size) do ; while(0)
42 #endif
43
44 #ifndef HAVE_ALLOC_SKB
45 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
46 #define kfree_skbmem(buff, size) kfree_s(buff,size)
47 #endif
48
49 struct device *init_etherdev(struct device *dev, int sizeof_private,
50 unsigned long *mem_start);
51
52 #define APRICOT_DEBUG 1
53
54 #ifdef APRICOT_DEBUG
55 int i596_debug = APRICOT_DEBUG;
56 #else
57 int i596_debug = 1;
58 #endif
59
60 #define APRICOT_TOTAL_SIZE 17
61
62 #define CMD_EOL 0x8000
63 #define CMD_SUSP 0x4000
64 #define CMD_INTR 0x2000
65
66 #define CMD_FLEX 0x0008
67
68 enum commands {
69 CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
70 CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7};
71
72 #define STAT_C 0x8000
73 #define STAT_B 0x4000
74 #define STAT_OK 0x2000
75 #define STAT_A 0x1000
76
77 #define CUC_START 0x0100
78 #define CUC_RESUME 0x0200
79 #define CUC_SUSPEND 0x0300
80 #define CUC_ABORT 0x0400
81 #define RX_START 0x0010
82 #define RX_RESUME 0x0020
83 #define RX_SUSPEND 0x0030
84 #define RX_ABORT 0x0040
85
86 struct i596_cmd {
87 unsigned short status;
88 unsigned short command;
89 struct i596_cmd *next;
90 };
91
92 #define EOF 0x8000
93 #define SIZE_MASK 0x3fff
94
95 struct i596_tbd {
96 unsigned short size;
97 unsigned short pad;
98 struct i596_tbd *next;
99 char *data;
100 };
101
102 struct tx_cmd {
103 struct i596_cmd cmd;
104 struct i596_tbd *tbd;
105 unsigned short size;
106 unsigned short pad;
107 };
108
109 struct i596_rfd {
110 unsigned short stat;
111 unsigned short cmd;
112 struct i596_rfd *next;
113 long rbd;
114 unsigned short count;
115 unsigned short size;
116 char data[1532];
117 };
118
119 #define RX_RING_SIZE 16
120
121 struct i596_scb {
122 unsigned short status;
123 unsigned short command;
124 struct i596_cmd *cmd;
125 struct i596_rfd *rfd;
126 unsigned long crc_err;
127 unsigned long align_err;
128 unsigned long resource_err;
129 unsigned long over_err;
130 unsigned long rcvdt_err;
131 unsigned long short_err;
132 unsigned short t_on;
133 unsigned short t_off;
134 };
135
136 struct i596_iscp {
137 unsigned long stat;
138 struct i596_scb *scb;
139 };
140
141 struct i596_scp {
142 unsigned long sysbus;
143 unsigned long pad;
144 struct i596_iscp *iscp;
145 };
146
147 struct i596_private {
148 struct i596_scp scp;
149 struct i596_iscp iscp;
150 struct i596_scb scb;
151 struct i596_cmd set_add;
152 char eth_addr[8];
153 struct i596_cmd set_conf;
154 char i596_config[16];
155 struct i596_cmd tdr;
156 unsigned long stat;
157 struct i596_rfd rx[RX_RING_SIZE];
158 int last_restart;
159 struct i596_rfd *rx_tail;
160 struct i596_cmd *cmd_tail;
161 struct i596_cmd *cmd_head;
162 int cmd_backlog;
163 unsigned long last_cmd;
164 struct enet_statistics stats;
165 };
166
167 char init_setup[] = {
168 0x8E,
169 0xC8,
170 0x80,
171 0x2E,
172 0x00,
173 0x60,
174 0x00,
175 0xf2,
176 0x00,
177 0x00,
178 0x40,
179 0xff,
180 0x00,
181 0x7f };
182
183 char adds[] = {0x00, 0x00, 0x49, 0x20, 0x54, 0xDA, 0x80, 0x00, 0x4e, 0x02, 0xb7, 0xb8};
184
185 static int i596_open(struct device *dev);
186 static int i596_start_xmit(struct sk_buff *skb, struct device *dev);
187 static void i596_interrupt(int reg_ptr);
188 static int i596_close(struct device *dev);
189 static struct enet_statistics *i596_get_stats(struct device *dev);
190 static void i596_add_cmd(struct device *dev, struct i596_cmd *cmd);
191 static void print_eth(char *);
192 #ifdef HAVE_MULTICAST
193 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
194 #endif
195
196
197 static inline void
198 init_rx_bufs(struct device *dev)
199 {
200 struct i596_private *lp = (struct i596_private *)dev->priv;
201 int i;
202 int boguscnt = 100;
203 short ioaddr = dev->base_addr;
204
205 if (i596_debug > 1) printk ("%s: init_rx_bufs.\n", dev->name);
206
207 for (i = 0; i < RX_RING_SIZE; i++)
208 {
209 if (i == 0)
210 {
211 lp->scb.rfd = &lp->rx[0];
212 }
213 if (i == (RX_RING_SIZE - 1))
214 {
215 lp->rx_tail = &(lp->rx[i]);
216 lp->rx[i].next = &lp->rx[0];
217 lp->rx[i].cmd = CMD_EOL;
218 }
219 else
220 {
221 lp->rx[i].next = &lp->rx[i+1];
222 lp->rx[i].cmd = 0x0000;
223 }
224 lp->rx[i].stat = 0x0000;
225 lp->rx[i].rbd = 0xffffffff;
226 lp->rx[i].count = 0;
227 lp->rx[i].size = 1532;
228 }
229
230 while (lp->scb.status, lp->scb.command)
231 if (--boguscnt == 0)
232 {
233 printk("%s: init_rx_bufs timed out with status %4.4x, cmd %4.4x.\n",
234 dev->name, lp->scb.status, lp->scb.command);
235 break;
236 }
237
238 lp->scb.command = RX_START;
239 outw(0, ioaddr+4);
240
241 return;
242
243 }
244
245 static inline void
246 init_i596_mem(struct device *dev)
247 {
248 struct i596_private *lp = (struct i596_private *)dev->priv;
249 short ioaddr = dev->base_addr;
250 int boguscnt = 100;
251
252
253 outw(0, ioaddr);
254 outw(0, ioaddr);
255 outb(4, ioaddr+0xf);
256 outw(((((int)&lp->scp) & 0xffff) | 2), ioaddr);
257 outw((((int)&lp->scp)>>16) & 0xffff, ioaddr);
258
259 lp->last_cmd=jiffies;
260
261 lp->scp.sysbus = 0x00440000;
262 lp->scp.iscp = &(lp->iscp);
263 lp->iscp.scb = &(lp->scb);
264 lp->iscp.stat = 0x0001;
265 lp->cmd_backlog = 0;
266
267 lp->cmd_head = lp->scb.cmd = (struct i596_cmd *) -1;
268
269 if (i596_debug > 2) printk("%s: starting i82596.\n", dev->name);
270
271 (void) inb (ioaddr+0x10);
272 outb(4, ioaddr+0xf);
273 outw(0, ioaddr+4);
274
275 while (lp->iscp.stat)
276 if (--boguscnt == 0)
277 {
278 printk("%s: i82596 initialization timed out with status %4.4x, cmd %4.4x.\n",
279 dev->name, lp->scb.status, lp->scb.command);
280 break;
281 }
282
283 memcpy (lp->i596_config, init_setup, 14);
284 lp->set_conf.command = CmdConfigure;
285 i596_add_cmd(dev, &lp->set_conf);
286
287 memcpy (lp->eth_addr, dev->dev_addr, 6);
288 lp->set_add.command = CmdSASetup;
289 i596_add_cmd(dev, &lp->set_add);
290
291 lp->tdr.command = CmdTDR;
292 i596_add_cmd(dev, &lp->tdr);
293
294 init_rx_bufs(dev);
295
296 boguscnt=200;
297 while (lp->scb.status, lp->scb.command)
298 if (--boguscnt == 0)
299 {
300 printk("i82596 init timed out with status %4.4x, cmd %4.4x.\n",
301 lp->scb.status, lp->scb.command);
302 break;
303 }
304
305 return;
306 }
307
308 static inline int
309 i596_rx(struct device *dev)
310 {
311 struct i596_private *lp = (struct i596_private *)dev->priv;
312 int frames=0;
313
314 if (i596_debug > 3) printk ("i596_rx()\n");
315
316 while ((lp->scb.rfd->stat) & STAT_C)
317 {
318 if (i596_debug >2) print_eth(lp->scb.rfd->data);
319
320 if ((lp->scb.rfd->stat) & STAT_OK)
321 {
322
323 int pkt_len = lp->scb.rfd->count & 0x3fff;
324 struct sk_buff *skb = alloc_skb(pkt_len, GFP_ATOMIC);
325
326 frames++;
327
328 if (skb == NULL)
329 {
330 printk ("%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
331 lp->stats.rx_dropped++;
332 break;
333 }
334
335 skb->len = pkt_len;
336 skb->dev=dev;
337 memcpy(skb->data, lp->scb.rfd->data, pkt_len);
338
339 netif_rx(skb);
340 lp->stats.rx_packets++;
341
342 if (i596_debug > 4) print_eth(skb->data);
343 }
344 else
345 {
346 lp->stats.rx_errors++;
347 if ((lp->scb.rfd->stat) & 0x0001) lp->stats.collisions++;
348 if ((lp->scb.rfd->stat) & 0x0080) lp->stats.rx_length_errors++;
349 if ((lp->scb.rfd->stat) & 0x0100) lp->stats.rx_over_errors++;
350 if ((lp->scb.rfd->stat) & 0x0200) lp->stats.rx_fifo_errors++;
351 if ((lp->scb.rfd->stat) & 0x0400) lp->stats.rx_frame_errors++;
352 if ((lp->scb.rfd->stat) & 0x0800) lp->stats.rx_crc_errors++;
353 if ((lp->scb.rfd->stat) & 0x1000) lp->stats.rx_length_errors++;
354 }
355
356 lp->scb.rfd->stat=0;
357 lp->rx_tail->cmd=0;
358 lp->rx_tail=lp->scb.rfd;
359 lp->scb.rfd=lp->scb.rfd->next;
360 lp->rx_tail->count=0;
361 lp->rx_tail->cmd=CMD_EOL;
362
363 }
364
365 if (i596_debug > 3) printk ("frames %d\n", frames);
366
367 return 0;
368 }
369
370 static inline void
371 i596_cleanup_cmd(struct i596_private *lp)
372 {
373 struct i596_cmd *ptr;
374 int boguscnt = 100;
375
376 if (i596_debug > 4) printk ("i596_cleanup_cmd\n");
377
378 while (lp->cmd_head != (struct i596_cmd *) -1)
379 {
380 ptr = lp->cmd_head;
381
382 lp->cmd_head = lp->cmd_head->next;
383 lp->cmd_backlog--;
384
385 switch ((ptr->command) & 0x7)
386 {
387 case CmdTx:
388 {
389 struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
390 struct sk_buff *skb = ((struct sk_buff *)(tx_cmd->tbd->data)) -1;
391
392 dev_kfree_skb(skb, FREE_WRITE);
393
394 lp->stats.tx_errors++;
395 lp->stats.tx_aborted_errors++;
396
397 ptr->next = (struct i596_cmd * ) -1;
398 kfree_s((unsigned char *)tx_cmd, (sizeof (struct tx_cmd) + sizeof (struct i596_tbd)));
399 break;
400 }
401 case CmdMulticastList:
402 {
403 unsigned short count = *((unsigned short *) (ptr + 1));
404
405 ptr->next = (struct i596_cmd * ) -1;
406 kfree_s((unsigned char *)ptr, (sizeof (struct i596_cmd) + count + 2));
407 break;
408 }
409 default:
410 ptr->next = (struct i596_cmd * ) -1;
411 }
412 }
413
414 while (lp->scb.status, lp->scb.command)
415 if (--boguscnt == 0)
416 {
417 printk("i596_cleanup_cmd timed out with status %4.4x, cmd %4.4x.\n",
418 lp->scb.status, lp->scb.command);
419 break;
420 }
421
422 lp->scb.cmd = lp->cmd_head;
423 }
424
425 static inline void
426 i596_reset(struct device *dev, struct i596_private *lp, int ioaddr)
427 {
428 int boguscnt = 100;
429
430 if (i596_debug > 4) printk ("i596_reset\n");
431
432 while (lp->scb.status, lp->scb.command)
433 if (--boguscnt == 0)
434 {
435 printk("i596_reset timed out with status %4.4x, cmd %4.4x.\n",
436 lp->scb.status, lp->scb.command);
437 break;
438 }
439
440 dev->start=0;
441 dev->tbusy=1;
442
443 lp->scb.command=CUC_ABORT|RX_ABORT;
444 outw(0, ioaddr+4);
445
446
447 boguscnt = 400;
448
449 while ((lp->scb.status, lp->scb.command) || lp->scb.command)
450 if (--boguscnt == 0)
451 {
452 printk("i596_reset 2 timed out with status %4.4x, cmd %4.4x.\n",
453 lp->scb.status, lp->scb.command);
454 break;
455 }
456
457 i596_cleanup_cmd(lp);
458 i596_rx(dev);
459
460 dev->start=1;
461 dev->tbusy=0;
462 dev->interrupt=0;
463 init_i596_mem(dev);
464 }
465
466 static void i596_add_cmd(struct device *dev, struct i596_cmd *cmd)
467 {
468 struct i596_private *lp = (struct i596_private *)dev->priv;
469 int ioaddr = dev->base_addr;
470 unsigned long flags;
471 int boguscnt = 100;
472
473 if (i596_debug > 4) printk ("i596_add_cmd\n");
474
475 cmd->status = 0;
476 cmd->command |= (CMD_EOL|CMD_INTR);
477 cmd->next = (struct i596_cmd *) -1;
478
479 save_flags(flags);
480 cli();
481 if (lp->cmd_head != (struct i596_cmd *) -1)
482 lp->cmd_tail->next = cmd;
483 else
484 {
485 lp->cmd_head=cmd;
486 while (lp->scb.status, lp->scb.command)
487 if (--boguscnt == 0)
488 {
489 printk("i596_add_cmd timed out with status %4.4x, cmd %4.4x.\n",
490 lp->scb.status, lp->scb.command);
491 break;
492 }
493
494 lp->scb.cmd = cmd;
495 lp->scb.command = CUC_START;
496 outw (0, ioaddr+4);
497 }
498 lp->cmd_tail=cmd;
499 lp->cmd_backlog++;
500
501 lp->cmd_head=lp->scb.cmd;
502 restore_flags(flags);
503
504 if (lp->cmd_backlog > 16)
505 {
506 int tickssofar = jiffies - lp->last_cmd;
507
508 if (tickssofar < 25) return;
509
510 printk("%s: command unit timed out, status resetting.\n", dev->name);
511
512 i596_reset(dev, lp, ioaddr);
513 }
514 }
515
516 static int
517 i596_open(struct device *dev)
518 {
519 if (request_irq(dev->irq, &i596_interrupt, 0, "apricot")) {
520 return -EAGAIN;
521 }
522
523 irq2dev_map[dev->irq] = dev;
524
525 if (i596_debug > 1)
526 printk("%s: i596_open() irq %d.\n",
527 dev->name, dev->irq);
528
529 dev->tbusy = 0;
530 dev->interrupt = 0;
531 dev->start = 1;
532
533
534 init_i596_mem(dev);
535
536 return 0;
537 }
538
539 static int
540 i596_start_xmit(struct sk_buff *skb, struct device *dev)
541 {
542 struct i596_private *lp = (struct i596_private *)dev->priv;
543 int ioaddr = dev->base_addr;
544 struct tx_cmd *tx_cmd;
545
546 if (i596_debug > 2) printk ("%s: Apricot start xmit\n", dev->name);
547
548
549 if (dev->tbusy) {
550 int tickssofar = jiffies - dev->trans_start;
551 if (tickssofar < 5)
552 return 1;
553 printk("%s: transmit timed out, status resetting.\n",
554 dev->name);
555 lp->stats.tx_errors++;
556
557 if (lp->last_restart == lp->stats.tx_packets) {
558 if (i596_debug > 1) printk ("Resetting board.\n");
559
560
561 i596_reset(dev,lp, ioaddr);
562 } else {
563
564 if (i596_debug > 1) printk ("Kicking board.\n");
565
566 lp->scb.command=CUC_START|RX_START;
567 outw(0, ioaddr+4);
568
569 lp->last_restart = lp->stats.tx_packets;
570 }
571 dev->tbusy = 0;
572 dev->trans_start = jiffies;
573 }
574
575
576
577
578 if (skb == NULL) {
579 dev_tint(dev);
580 return 0;
581 }
582
583
584 if (skb->len <= 0) return 0;
585
586 if (i596_debug > 3) printk("%s: i596_start_xmit() called\n", dev->name);
587
588
589
590 if (set_bit(0, (void*)&dev->tbusy) != 0)
591 printk("%s: Transmitter access conflict.\n", dev->name);
592 else
593 {
594 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
595 dev->trans_start=jiffies;
596
597 tx_cmd = (struct tx_cmd *) kmalloc ((sizeof (struct tx_cmd) + sizeof (struct i596_tbd)), GFP_ATOMIC);
598 if (tx_cmd == NULL)
599 {
600 printk ("%s: i596_xmit Memory squeeze, dropping packet.\n", dev->name);
601 lp->stats.tx_dropped++;
602
603 dev_kfree_skb(skb, FREE_WRITE);
604 }
605 else
606 {
607 tx_cmd->tbd = (struct i596_tbd *) (tx_cmd + 1);
608 tx_cmd->tbd->next = (struct i596_tbd *) -1;
609
610 tx_cmd->cmd.command = CMD_FLEX|CmdTx;
611
612 tx_cmd->pad = 0;
613 tx_cmd->size = 0;
614 tx_cmd->tbd->pad = 0;
615 tx_cmd->tbd->size = EOF | length;
616
617 tx_cmd->tbd->data = skb->data;
618
619 if (i596_debug > 3) print_eth(skb->data);
620
621 i596_add_cmd(dev, (struct i596_cmd *)tx_cmd);
622
623 lp->stats.tx_packets++;
624 }
625 }
626
627 dev->tbusy = 0;
628
629 return 0;
630 }
631
632
633 static void print_eth(char *add)
634 {
635 int i;
636
637 printk ("Dest ");
638 for (i = 0; i < 6; i++)
639 printk(" %2.2X", (unsigned char)add[i]);
640 printk ("\n");
641
642 printk ("Source");
643 for (i = 0; i < 6; i++)
644 printk(" %2.2X", (unsigned char)add[i+6]);
645 printk ("\n");
646 printk ("type %2.2X%2.2X\n", (unsigned char)add[12], (unsigned char)add[13]);
647 }
648
649 unsigned long apricot_init(unsigned long mem_start, unsigned long mem_end)
650 {
651 struct device *dev;
652 int i;
653 int checksum = 0;
654 int ioaddr = 0x300;
655
656
657
658
659 if (check_region(ioaddr, APRICOT_TOTAL_SIZE))
660 return mem_start;
661
662 for (i = 0; i < 8; i++)
663 checksum += inb(ioaddr + 8 + i);
664
665
666
667
668
669 if (checksum % 0x100) return mem_start;
670
671 dev = init_etherdev(0, (sizeof (struct i596_private) + 0xf), &mem_start);
672
673 printk("%s: Apricot 82596 at %#3x,", dev->name, ioaddr);
674
675 for (i = 0; i < 6; i++)
676 printk(" %2.2X", dev->dev_addr[i] = inb(ioaddr +8 + i));
677
678 dev->base_addr = ioaddr;
679 dev->irq = 10;
680 printk(" IRQ %d.\n", dev->irq);
681
682 snarf_region(ioaddr, APRICOT_TOTAL_SIZE);
683
684 if (i596_debug > 0)
685 printk(version);
686
687
688 dev->open = &i596_open;
689 dev->stop = &i596_close;
690 dev->hard_start_xmit = &i596_start_xmit;
691 dev->get_stats = &i596_get_stats;
692 #ifdef HAVE_MULTICAST
693 dev->set_multicast_list = &set_multicast_list;
694 #endif
695
696
697 dev->priv = (void *)(((int) dev->priv + 0xf) & 0xfffffff0);
698
699 return mem_start;
700 }
701
702 static void
703 i596_interrupt(int reg_ptr)
704 {
705 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
706 struct device *dev = (struct device *)(irq2dev_map[irq]);
707 struct i596_private *lp;
708 short ioaddr;
709 int boguscnt = 200;
710 unsigned short status, ack_cmd=0;
711
712 if (dev == NULL) {
713 printk ("i596_interrupt(): irq %d for unknown device.\n", irq);
714 return;
715 }
716
717 if (i596_debug > 3) printk ("%s: i596_interrupt(): irq %d\n",dev->name, irq);
718
719 if (dev->interrupt)
720 printk("%s: Re-entering the interrupt handler.\n", dev->name);
721
722 dev->interrupt = 1;
723
724 ioaddr = dev->base_addr;
725
726 lp = (struct i596_private *)dev->priv;
727
728 while (lp->scb.status, lp->scb.command)
729 if (--boguscnt == 0)
730 {
731 printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev->name, lp->scb.status, lp->scb.command);
732 break;
733 }
734 status = lp->scb.status;
735
736 if (i596_debug > 4)
737 printk("%s: i596 interrupt, status %4.4x.\n", dev->name, status);
738
739 ack_cmd = status & 0xf000;
740
741 if ((status & 0x8000) || (status & 0x2000))
742 {
743 struct i596_cmd *ptr;
744
745 if ((i596_debug > 4) && (status & 0x8000))
746 printk("%s: i596 interrupt completed command.\n", dev->name);
747 if ((i596_debug > 4) && (status & 0x2000))
748 printk("%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700);
749
750 while ((lp->cmd_head != (struct i596_cmd *) -1) && (lp->cmd_head->status & STAT_C))
751 {
752 ptr = lp->cmd_head;
753
754 lp->cmd_head = lp->cmd_head->next;
755 lp->cmd_backlog--;
756
757 switch ((ptr->command) & 0x7)
758 {
759 case CmdTx:
760 {
761 struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
762 struct sk_buff *skb = ((struct sk_buff *)(tx_cmd->tbd->data)) -1;
763
764 dev_kfree_skb(skb, FREE_WRITE);
765
766 if ((ptr->status) & STAT_OK)
767 {
768 if (i596_debug >2) print_eth(skb->data);
769 }
770 else
771 {
772 lp->stats.tx_errors++;
773 if ((ptr->status) & 0x0020) lp->stats.collisions++;
774 if (!((ptr->status) & 0x0040)) lp->stats.tx_heartbeat_errors++;
775 if ((ptr->status) & 0x0400) lp->stats.tx_carrier_errors++;
776 if ((ptr->status) & 0x0800) lp->stats.collisions++;
777 if ((ptr->status) & 0x1000) lp->stats.tx_aborted_errors++;
778 }
779
780
781 ptr->next = (struct i596_cmd * ) -1;
782 kfree_s((unsigned char *)tx_cmd, (sizeof (struct tx_cmd) + sizeof (struct i596_tbd)));
783 break;
784 }
785 case CmdMulticastList:
786 {
787 unsigned short count = *((unsigned short *) (ptr + 1));
788
789 ptr->next = (struct i596_cmd * ) -1;
790 kfree_s((unsigned char *)ptr, (sizeof (struct i596_cmd) + count + 2));
791 break;
792 }
793 case CmdTDR:
794 {
795 unsigned long status = *((unsigned long *) (ptr + 1));
796
797 if (status & 0x8000)
798 {
799 if (i596_debug > 3)
800 printk("%s: link ok.\n", dev->name);
801 }
802 else
803 {
804 if (status & 0x4000)
805 printk("%s: Transceiver problem.\n", dev->name);
806 if (status & 0x2000)
807 printk("%s: Termination problem.\n", dev->name);
808 if (status & 0x1000)
809 printk("%s: Short circuit.\n", dev->name);
810
811 printk("%s: Time %ld.\n", dev->name, status & 0x07ff);
812 }
813 }
814 default:
815 ptr->next = (struct i596_cmd * ) -1;
816
817 lp->last_cmd=jiffies;
818 }
819 }
820
821 ptr = lp->cmd_head;
822 while ((ptr != (struct i596_cmd *) -1) && (ptr != lp->cmd_tail))
823 {
824 ptr->command &= 0x1fff;
825 ptr = ptr->next;
826 }
827
828 if ((lp->cmd_head != (struct i596_cmd *) -1) && (dev->start)) ack_cmd |= CUC_START;
829 lp->scb.cmd = lp->cmd_head;
830 }
831
832 if ((status & 0x1000) || (status & 0x4000))
833 {
834 if ((i596_debug > 4) && (status & 0x4000))
835 printk("%s: i596 interrupt received a frame.\n", dev->name);
836 if ((i596_debug > 4) && (status & 0x1000))
837 printk("%s: i596 interrupt receive unit inactive %x.\n", dev->name, status & 0x0070);
838
839 i596_rx(dev);
840
841 if (dev->start) ack_cmd |= RX_START;
842 }
843
844
845
846
847
848
849 boguscnt = 100;
850 while (lp->scb.status, lp->scb.command)
851 if (--boguscnt == 0)
852 {
853 printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev->name, lp->scb.status, lp->scb.command);
854 break;
855 }
856 lp->scb.command = ack_cmd;
857
858 (void) inb (ioaddr+0x10);
859 outb (4, ioaddr+0xf);
860 outw (0, ioaddr+4);
861
862 if (i596_debug > 4)
863 printk("%s: exiting interrupt.\n", dev->name);
864
865 dev->interrupt = 0;
866 return;
867 }
868
869 static int
870 i596_close(struct device *dev)
871 {
872 int ioaddr = dev->base_addr;
873 struct i596_private *lp = (struct i596_private *)dev->priv;
874
875 dev->start = 0;
876 dev->tbusy = 1;
877
878 if (i596_debug > 1)
879 printk("%s: Shutting down ethercard, status was %4.4x.\n",
880 dev->name, lp->scb.status);
881
882 lp->scb.command = CUC_ABORT|RX_ABORT;
883 outw(0, ioaddr+4);
884
885 i596_cleanup_cmd(lp);
886
887 free_irq(dev->irq);
888 irq2dev_map[dev->irq] = 0;
889
890 return 0;
891 }
892
893 static struct enet_statistics *
894 i596_get_stats(struct device *dev)
895 {
896 struct i596_private *lp = (struct i596_private *)dev->priv;
897
898 return &lp->stats;
899 }
900
901 #ifdef HAVE_MULTICAST
902
903
904
905
906
907
908 static void
909 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
910 {
911 struct i596_private *lp = (struct i596_private *)dev->priv;
912 struct i596_cmd *cmd;
913
914 if (i596_debug > 1)
915 printk ("%s: set multicast list %d\n", dev->name, num_addrs);
916
917 if (num_addrs > 0) {
918 cmd = (struct i596_cmd *) kmalloc(sizeof(struct i596_cmd)+2+num_addrs*6, GFP_ATOMIC);
919 if (cmd == NULL)
920 {
921 printk ("%s: set_multicast Memory squeeze.\n", dev->name);
922 return;
923 }
924
925 cmd->command = CmdMulticastList;
926 *((unsigned short *) (cmd + 1)) = num_addrs * 6;
927 memcpy (((char *)(cmd + 1))+2, addrs, num_addrs * 6);
928 print_eth (((char *)(cmd + 1)) + 2);
929
930 i596_add_cmd(dev, cmd);
931 } else
932 {
933 if (lp->set_conf.next != (struct i596_cmd * ) -1) return;
934 if (num_addrs == 0)
935 lp->i596_config[8] &= ~0x01;
936 else
937 lp->i596_config[8] |= 0x01;
938
939 i596_add_cmd(dev, &lp->set_conf);
940 }
941
942 }
943 #endif
944
945 #ifdef HAVE_DEVLIST
946 static unsigned int apricot_portlist[] = {0x300, 0};
947 struct netdev_entry apricot_drv =
948 {"apricot", apricot_init, APRICOT_TOTAL_SIZE, apricot_portlist};
949 #endif
950
951
952
953
954
955