This source file includes following definitions.
- express_probe
- eexp_probe1
- eexp_open
- eexp_send_packet
- eexp_interrupt
- eexp_close
- eexp_get_stats
- set_multicast_list
- read_eeprom
- init_82586_mem
- init_rx_bufs
- hardware_send_packet
- eexp_rx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 static char *version =
23 "eexpress.c:v0.07 1/19/94 Donald Becker (becker@super.org)\n";
24
25 #include <linux/config.h>
26
27
28
29
30
31
32
33
34
35
36
37
38 #include <linux/kernel.h>
39 #include <linux/sched.h>
40 #include <linux/types.h>
41 #include <linux/fcntl.h>
42 #include <linux/interrupt.h>
43 #include <linux/ptrace.h>
44 #include <linux/ioport.h>
45 #include <linux/string.h>
46 #include <linux/in.h>
47 #include <asm/system.h>
48 #include <asm/bitops.h>
49 #include <asm/io.h>
50 #include <asm/dma.h>
51 #include <linux/errno.h>
52
53 #include <linux/netdevice.h>
54 #include <linux/etherdevice.h>
55 #include <linux/skbuff.h>
56
57 #include <linux/malloc.h>
58
59
60 #ifndef NET_DEBUG
61 #define NET_DEBUG 2
62 #endif
63 static unsigned int net_debug = NET_DEBUG;
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 #define CMD_EOL 0x8000
84 #define CMD_SUSP 0x4000
85 #define CMD_INTR 0x2000
86
87 enum commands {
88 CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
89 CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7};
90
91
92 struct net_local {
93 struct enet_statistics stats;
94 int last_restart;
95 short rx_head;
96 short rx_tail;
97 short tx_head;
98 short tx_cmd_link;
99 short tx_reap;
100 };
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 #define DATAPORT 0
131 #define WRITE_PTR 2
132 #define READ_PTR 4
133 #define SIGNAL_CA 6
134 #define SET_IRQ 7
135 #define SHADOW_PTR 8
136 #define MEM_Ctrl 11
137 #define MEM_Page_Ctrl 12
138 #define Config 13
139 #define EEPROM_Ctrl 14
140 #define ID_PORT 15
141
142
143
144 #define EE_SHIFT_CLK 0x01
145 #define EE_CS 0x02
146 #define EE_DATA_WRITE 0x04
147 #define EE_DATA_READ 0x08
148 #define EE_CTRL_BITS (EE_SHIFT_CLK | EE_CS | EE_DATA_WRITE | EE_DATA_READ)
149 #define ASIC_RESET 0x40
150 #define _586_RESET 0x80
151
152
153 #define SCB_STATUS 0xc008
154 #define SCB_CMD 0xc00A
155 #define CUC_START 0x0100
156 #define CUC_RESUME 0x0200
157 #define CUC_SUSPEND 0x0300
158 #define RX_START 0x0010
159 #define RX_RESUME 0x0020
160 #define RX_SUSPEND 0x0030
161 #define SCB_CBL 0xc00C
162 #define SCB_RFA 0xc00E
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179 #define CONFIG_CMD 0x0018
180 #define SET_SA_CMD 0x0024
181 #define SA_OFFSET 0x002A
182 #define IDLELOOP 0x30
183 #define TDR_CMD 0x38
184 #define TDR_TIME 0x3C
185 #define DUMP_CMD 0x40
186 #define DIAG_CMD 0x48
187 #define SET_MC_CMD 0x4E
188 #define DUMP_DATA 0x56
189
190 #define TX_BUF_START 0x0100
191 #define NUM_TX_BUFS 4
192 #define TX_BUF_SIZE 0x0680
193 #define TX_BUF_END 0x2000
194
195 #define RX_BUF_START 0x2000
196 #define RX_BUF_SIZE (0x640)
197 #define RX_BUF_END 0x4000
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232 static short init_words[] = {
233 0x0000,
234 0x0000,0x0000,
235 0,0,
236 0x0001,
237 0x0008,0,0,
238
239 0,0xf000|RX_START|CUC_START,
240 CONFIG_CMD,
241 RX_BUF_START,
242 0,0,0,0,
243
244
245 0, CmdConfigure,
246 SET_SA_CMD,
247 0x0804,
248 0x2e40,
249 0,
250
251
252 0, CmdSASetup,
253 SET_MC_CMD,
254 0xaa00,0xb000,0x0bad,
255
256
257 0, CmdNOp, IDLELOOP, 0 ,
258
259
260 0, CmdTDR, IDLELOOP, 0,
261
262
263 0, CmdDump, IDLELOOP, DUMP_DATA,
264
265
266 0, CmdDiagnose, IDLELOOP,
267
268
269 #ifdef initial_text_tx
270 0, CmdMulticastList, DUMP_DATA, 0,
271 #else
272 0, CmdMulticastList, IDLELOOP, 0,
273 #endif
274
275
276 0, CmdTx, DUMP_DATA, DUMP_DATA+8, 0x83ff, -1, DUMP_DATA, 0,
277 };
278
279
280
281 extern int express_probe(struct device *dev);
282
283 static int eexp_probe1(struct device *dev, short ioaddr);
284 static int eexp_open(struct device *dev);
285 static int eexp_send_packet(struct sk_buff *skb, struct device *dev);
286 static void eexp_interrupt(int reg_ptr);
287 static void eexp_rx(struct device *dev);
288 static int eexp_close(struct device *dev);
289 static struct enet_statistics *eexp_get_stats(struct device *dev);
290 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
291
292 static int read_eeprom(int ioaddr, int location);
293 static void hardware_send_packet(struct device *dev, void *buf, short length);
294 static void init_82586_mem(struct device *dev);
295 static void init_rx_bufs(struct device *dev);
296
297
298
299
300
301
302
303
304 int
305 express_probe(struct device *dev)
306 {
307
308 int *port, ports[] = {0x300, 0x270, 0x320, 0x340, 0};
309 int base_addr = dev->base_addr;
310
311 if (base_addr > 0x1ff)
312 return eexp_probe1(dev, base_addr);
313 else if (base_addr > 0)
314 return ENXIO;
315
316 for (port = &ports[0]; *port; port++) {
317 short id_addr = *port + ID_PORT;
318 unsigned short sum = 0;
319 int i;
320 #ifdef notdef
321 for (i = 16; i > 0; i--)
322 sum += inb(id_addr);
323 printk("EtherExpress ID checksum is %04x.\n", sum);
324 #else
325 for (i = 4; i > 0; i--) {
326 short id_val = inb(id_addr);
327 sum |= (id_val >> 4) << ((id_val & 3) << 2);
328 }
329 #endif
330 if (sum == 0xbaba
331 && eexp_probe1(dev, *port) == 0)
332 return 0;
333 }
334
335 return ENODEV;
336 }
337
338 int eexp_probe1(struct device *dev, short ioaddr)
339 {
340 unsigned short station_addr[3];
341 int i;
342
343 printk("%s: EtherExpress at %#x,", dev->name, ioaddr);
344
345
346
347 station_addr[0] = read_eeprom(ioaddr, 2);
348 station_addr[1] = read_eeprom(ioaddr, 3);
349 station_addr[2] = read_eeprom(ioaddr, 4);
350
351
352 if (station_addr[2] != 0x00aa || (station_addr[1] & 0xff00) != 0x0000) {
353 printk(" rejected (invalid address %04x%04x%04x).\n",
354 station_addr[2], station_addr[1], station_addr[0]);
355 return ENODEV;
356 }
357
358
359 snarf_region(ioaddr, 16);
360 dev->base_addr = ioaddr;
361
362 for (i = 0; i < 6; i++) {
363 dev->dev_addr[i] = ((unsigned char*)station_addr)[5-i];
364 printk(" %02x", dev->dev_addr[i]);
365 }
366
367
368
369 {
370 char irqmap[] = {0, 9, 3, 4, 5, 10, 11, 0};
371 char *ifmap[] = {"AUI", "BNC", "10baseT"};
372 enum iftype {AUI=0, BNC=1, TP=2};
373 unsigned short setupval = read_eeprom(ioaddr, 0);
374
375 dev->irq = irqmap[setupval >> 13];
376 dev->if_port = (setupval & 0x1000) == 0 ? AUI :
377 read_eeprom(ioaddr, 5) & 0x1 ? TP : BNC;
378 printk(", IRQ %d, Interface %s.\n", dev->irq, ifmap[dev->if_port]);
379
380
381 outb(0x00, ioaddr + SET_IRQ);
382 }
383
384
385 outb(ASIC_RESET, ioaddr + EEPROM_Ctrl);
386
387 if ((dev->mem_start & 0xf) > 0)
388 net_debug = dev->mem_start & 7;
389
390 if (net_debug)
391 printk(version);
392
393
394 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
395 memset(dev->priv, 0, sizeof(struct net_local));
396
397 dev->open = eexp_open;
398 dev->stop = eexp_close;
399 dev->hard_start_xmit = eexp_send_packet;
400 dev->get_stats = eexp_get_stats;
401 dev->set_multicast_list = &set_multicast_list;
402
403
404
405 ether_setup(dev);
406
407 return 0;
408 }
409
410
411
412 static char irqrmap[]={0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0};
413
414 static int
415 eexp_open(struct device *dev)
416 {
417 int ioaddr = dev->base_addr;
418
419 if (dev->irq == 0 || irqrmap[dev->irq] == 0)
420 return -ENXIO;
421
422 if (irq2dev_map[dev->irq] != 0
423
424 || (irq2dev_map[dev->irq] = dev) == 0
425 || request_irq(dev->irq, &eexp_interrupt, 0, "EExpress")) {
426 return -EAGAIN;
427 }
428
429
430 init_82586_mem(dev);
431
432
433 outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);
434
435 dev->tbusy = 0;
436 dev->interrupt = 0;
437 dev->start = 1;
438 return 0;
439 }
440
441 static int
442 eexp_send_packet(struct sk_buff *skb, struct device *dev)
443 {
444 struct net_local *lp = (struct net_local *)dev->priv;
445 int ioaddr = dev->base_addr;
446
447 if (dev->tbusy) {
448
449
450 int tickssofar = jiffies - dev->trans_start;
451 if (tickssofar < 5)
452 return 1;
453 if (net_debug > 1)
454 printk("%s: transmit timed out, %s? ", dev->name,
455 inw(ioaddr+SCB_STATUS) & 0x8000 ? "IRQ conflict" :
456 "network cable problem");
457 lp->stats.tx_errors++;
458
459 if (lp->last_restart == lp->stats.tx_packets) {
460 if (net_debug > 1) printk("Resetting board.\n");
461
462 init_82586_mem(dev);
463 } else {
464
465 if (net_debug > 1) printk("Kicking board.\n");
466 outw(0xf000|CUC_START|RX_START, ioaddr + SCB_CMD);
467 outb(0, ioaddr + SIGNAL_CA);
468 lp->last_restart = lp->stats.tx_packets;
469 }
470 dev->tbusy=0;
471 dev->trans_start = jiffies;
472 }
473
474
475
476
477 if (skb == NULL) {
478 dev_tint(dev);
479 return 0;
480 }
481
482
483 if (set_bit(0, (void*)&dev->tbusy) != 0)
484 printk("%s: Transmitter access conflict.\n", dev->name);
485 else {
486 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
487 unsigned char *buf = skb->data;
488
489
490 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
491 hardware_send_packet(dev, buf, length);
492 dev->trans_start = jiffies;
493
494 outb(0x08 | irqrmap[dev->irq], ioaddr + SET_IRQ);
495 }
496
497 dev_kfree_skb (skb, FREE_WRITE);
498
499
500 lp->stats.tx_aborted_errors++;
501
502 return 0;
503 }
504
505
506
507 static void
508 eexp_interrupt(int reg_ptr)
509 {
510 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
511 struct device *dev = (struct device *)(irq2dev_map[irq]);
512 struct net_local *lp;
513 int ioaddr, status, boguscount = 0;
514 short ack_cmd;
515
516 if (dev == NULL) {
517 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
518 return;
519 }
520 dev->interrupt = 1;
521
522 ioaddr = dev->base_addr;
523 lp = (struct net_local *)dev->priv;
524
525 status = inw(ioaddr + SCB_STATUS);
526
527 if (net_debug > 4) {
528 printk("%s: EExp interrupt, status %4.4x.\n", dev->name, status);
529 }
530
531
532 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
533
534
535 while (lp->tx_reap != lp->tx_head) {
536 unsigned short tx_status;
537 outw(lp->tx_reap, ioaddr + READ_PTR);
538 tx_status = inw(ioaddr);
539 if (tx_status == 0) {
540 if (net_debug > 5) printk("Couldn't reap %#x.\n", lp->tx_reap);
541 break;
542 }
543 if (tx_status & 0x2000) {
544 lp->stats.tx_packets++;
545 lp->stats.collisions += tx_status & 0xf;
546 dev->tbusy = 0;
547 mark_bh(NET_BH);
548 } else {
549 lp->stats.tx_errors++;
550 if (tx_status & 0x0600) lp->stats.tx_carrier_errors++;
551 if (tx_status & 0x0100) lp->stats.tx_fifo_errors++;
552 if (!(tx_status & 0x0040)) lp->stats.tx_heartbeat_errors++;
553 if (tx_status & 0x0020) lp->stats.tx_aborted_errors++;
554 }
555 if (net_debug > 5)
556 printk("Reaped %x, Tx status %04x.\n" , lp->tx_reap, tx_status);
557 lp->tx_reap += TX_BUF_SIZE;
558 if (lp->tx_reap > TX_BUF_END - TX_BUF_SIZE)
559 lp->tx_reap = TX_BUF_START;
560 if (++boguscount > 4)
561 break;
562 }
563
564 if (status & 0x4000) {
565 if (net_debug > 5)
566 printk("Received packet, rx_head %04x.\n", lp->rx_head);
567 eexp_rx(dev);
568 }
569
570
571 ack_cmd = status & 0xf000;
572
573 if ((status & 0x0700) != 0x0200 && dev->start) {
574 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
575 if (net_debug > 1)
576 printk("%s: Command unit stopped, status %04x, restarting.\n",
577 dev->name, status);
578
579
580 outw(IDLELOOP, ioaddr + WRITE_PTR);
581 outw(0, ioaddr);
582 outw(CmdNOp, ioaddr);
583 outw(IDLELOOP, ioaddr);
584 outw(IDLELOOP, SCB_CBL);
585 lp->tx_cmd_link = IDLELOOP + 4;
586 lp->tx_head = lp->tx_reap = TX_BUF_START;
587
588 outw(saved_write_ptr, ioaddr + WRITE_PTR);
589 ack_cmd |= CUC_START;
590 }
591
592 if ((status & 0x0070) != 0x0040 && dev->start) {
593 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
594
595
596 lp->stats.rx_errors++;
597 if (net_debug > 1) {
598 int cur_rxbuf = RX_BUF_START;
599 printk("%s: Rx unit stopped status %04x rx head %04x tail %04x.\n",
600 dev->name, status, lp->rx_head, lp->rx_tail);
601 while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE) {
602 int i;
603 printk(" Rx buf at %04x:", cur_rxbuf);
604 outw(cur_rxbuf, ioaddr + READ_PTR);
605 for (i = 0; i < 0x20; i += 2)
606 printk(" %04x", inw(ioaddr));
607 printk(".\n");
608 cur_rxbuf += RX_BUF_SIZE;
609 }
610 }
611 init_rx_bufs(dev);
612 outw(RX_BUF_START, SCB_RFA);
613 outw(saved_write_ptr, ioaddr + WRITE_PTR);
614 ack_cmd |= RX_START;
615 }
616
617 outw(ack_cmd, ioaddr + SCB_CMD);
618 outb(0, ioaddr + SIGNAL_CA);
619
620 if (net_debug > 5) {
621 printk("%s: EExp exiting interrupt, status %4.4x.\n", dev->name,
622 inw(ioaddr + SCB_CMD));
623 }
624
625 outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);
626 return;
627 }
628
629 static int
630 eexp_close(struct device *dev)
631 {
632 int ioaddr = dev->base_addr;
633
634 dev->tbusy = 1;
635 dev->start = 0;
636
637
638 outw(RX_SUSPEND | CUC_SUSPEND, ioaddr + SCB_CMD);
639 outb(0, ioaddr + SIGNAL_CA);
640
641
642 outb(0, ioaddr + SET_IRQ);
643
644 free_irq(dev->irq);
645
646 irq2dev_map[dev->irq] = 0;
647
648
649
650 return 0;
651 }
652
653
654
655 static struct enet_statistics *
656 eexp_get_stats(struct device *dev)
657 {
658 struct net_local *lp = (struct net_local *)dev->priv;
659
660
661
662 return &lp->stats;
663 }
664
665
666
667
668
669
670
671 static void
672 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
673 {
674 short ioaddr = dev->base_addr;
675 if (num_addrs < 0) {
676
677
678 } else if (num_addrs > 0) {
679
680
681 outw(SET_MC_CMD + 6, ioaddr + WRITE_PTR);
682 outw(num_addrs * 6, ioaddr);
683 outsw(ioaddr, addrs, num_addrs*3);
684
685 } else {
686
687
688 outw(99, ioaddr);
689 }
690 }
691
692
693
694
695 #define eeprom_delay() { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }}
696 #define EE_READ_CMD (6 << 6)
697
698 int
699 read_eeprom(int ioaddr, int location)
700 {
701 int i;
702 unsigned short retval = 0;
703 short ee_addr = ioaddr + EEPROM_Ctrl;
704 int read_cmd = location | EE_READ_CMD;
705 short ctrl_val = EE_CS | _586_RESET;
706
707 outb(ctrl_val, ee_addr);
708
709
710 for (i = 8; i >= 0; i--) {
711 short outval = (read_cmd & (1 << i)) ? ctrl_val | EE_DATA_WRITE
712 : ctrl_val;
713 outb(outval, ee_addr);
714 outb(outval | EE_SHIFT_CLK, ee_addr);
715 eeprom_delay();
716 outb(outval, ee_addr);
717 eeprom_delay();
718 }
719 outb(ctrl_val, ee_addr);
720
721 for (i = 16; i > 0; i--) {
722 outb(ctrl_val | EE_SHIFT_CLK, ee_addr); eeprom_delay();
723 retval = (retval << 1) | ((inb(ee_addr) & EE_DATA_READ) ? 1 : 0);
724 outb(ctrl_val, ee_addr); eeprom_delay();
725 }
726
727
728 ctrl_val &= ~EE_CS;
729 outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
730 eeprom_delay();
731 outb(ctrl_val, ee_addr);
732 eeprom_delay();
733 return retval;
734 }
735
736 static void
737 init_82586_mem(struct device *dev)
738 {
739 struct net_local *lp = (struct net_local *)dev->priv;
740 short ioaddr = dev->base_addr;
741
742
743
744 outb(inb(ioaddr + Config) | 0x02, ioaddr + Config);
745
746
747 outb(_586_RESET, ioaddr + EEPROM_Ctrl);
748
749
750 outw(0xfff6, ioaddr + WRITE_PTR);
751 outsw(ioaddr, init_words, sizeof(init_words)>>1);
752
753
754 outw(SA_OFFSET, ioaddr + WRITE_PTR);
755 outsw(ioaddr, dev->dev_addr, 3);
756
757
758 #ifdef initial_text_tx
759 lp->tx_cmd_link = DUMP_DATA + 4;
760 #else
761 lp->tx_cmd_link = IDLELOOP + 4;
762 #endif
763 lp->tx_head = lp->tx_reap = TX_BUF_START;
764
765 init_rx_bufs(dev);
766
767
768 outb(0x00, ioaddr + EEPROM_Ctrl);
769
770
771
772 outb(0, ioaddr + SIGNAL_CA);
773
774 {
775 int boguscnt = 50;
776 while (inw(ioaddr + SCB_STATUS) == 0)
777 if (--boguscnt == 0) {
778 printk("%s: i82586 initialization timed out with status %04x, cmd %04x.\n",
779 dev->name, inw(ioaddr + SCB_STATUS), inw(ioaddr + SCB_CMD));
780 break;
781 }
782
783 outb(0, ioaddr + SIGNAL_CA);
784 }
785
786
787 outb(inb(ioaddr + Config) & ~0x02, ioaddr + Config);
788 if (net_debug > 4)
789 printk("%s: Initialized 82586, status %04x.\n", dev->name,
790 inw(ioaddr + SCB_STATUS));
791 return;
792 }
793
794
795 static void init_rx_bufs(struct device *dev)
796 {
797 struct net_local *lp = (struct net_local *)dev->priv;
798 short ioaddr = dev->base_addr;
799
800 int cur_rxbuf = lp->rx_head = RX_BUF_START;
801
802
803 do {
804 outw(cur_rxbuf, ioaddr + WRITE_PTR);
805 outw(0x0000, ioaddr);
806 outw(0x0000, ioaddr);
807 outw(cur_rxbuf + RX_BUF_SIZE, ioaddr);
808 outw(cur_rxbuf + 22, ioaddr);
809 outw(0xFeed, ioaddr);
810 outw(0xF00d, ioaddr);
811 outw(0xF001, ioaddr);
812 outw(0x0505, ioaddr);
813 outw(0x2424, ioaddr);
814 outw(0x6565, ioaddr);
815 outw(0xdeaf, ioaddr);
816
817 outw(0x0000, ioaddr);
818 outw(-1, ioaddr);
819 outw(cur_rxbuf + 0x20, ioaddr);
820 outw(0x0000, ioaddr);
821
822 outw(0x8000 + RX_BUF_SIZE-0x20, ioaddr);
823
824 lp->rx_tail = cur_rxbuf;
825 cur_rxbuf += RX_BUF_SIZE;
826 } while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE);
827
828
829
830 outw(lp->rx_tail + 2, ioaddr + WRITE_PTR);
831 outw(0xC000, ioaddr);
832 outw(lp->rx_head, ioaddr);
833 }
834
835 static void
836 hardware_send_packet(struct device *dev, void *buf, short length)
837 {
838 struct net_local *lp = (struct net_local *)dev->priv;
839 short ioaddr = dev->base_addr;
840 short tx_block = lp->tx_head;
841
842
843 outw(tx_block, ioaddr + WRITE_PTR);
844 outw(0x0000, ioaddr);
845 outw(CMD_INTR|CmdTx, ioaddr);
846 outw(tx_block+16, ioaddr);
847 outw(tx_block+8, ioaddr);
848
849
850 outw(length | 0x8000, ioaddr);
851 outw(-1, ioaddr);
852 outw(tx_block+22, ioaddr);
853 outw(0x0000, ioaddr);
854
855
856 outw(0x0000, ioaddr);
857 outw(CmdNOp, ioaddr);
858 outw(tx_block+16, ioaddr);
859
860
861
862 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
863
864
865 outw(lp->tx_cmd_link, ioaddr + WRITE_PTR);
866 outw(tx_block, ioaddr);
867 lp->tx_cmd_link = tx_block + 20;
868
869
870 lp->tx_head = tx_block + TX_BUF_SIZE;
871 if (lp->tx_head > TX_BUF_END - TX_BUF_SIZE)
872 lp->tx_head = TX_BUF_START;
873
874 if (net_debug > 4) {
875 printk("%s: EExp @%x send length = %d, tx_block %3x, next %3x, "
876 "reap %4x status %4.4x.\n", dev->name, ioaddr, length,
877 tx_block, lp->tx_head, lp->tx_reap, inw(ioaddr + SCB_STATUS));
878 }
879
880 if (lp->tx_head != lp->tx_reap)
881 dev->tbusy = 0;
882 }
883
884 static void
885 eexp_rx(struct device *dev)
886 {
887 struct net_local *lp = (struct net_local *)dev->priv;
888 short ioaddr = dev->base_addr;
889 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
890 short rx_head = lp->rx_head;
891 short rx_tail = lp->rx_tail;
892 short boguscount = 10;
893 short frame_status;
894
895
896 outw(rx_head, ioaddr + READ_PTR);
897 while ((frame_status = inw(ioaddr)) < 0) {
898 short rfd_cmd = inw(ioaddr);
899 short next_rx_frame = inw(ioaddr);
900 short data_buffer_addr = inw(ioaddr);
901 short pkt_len;
902
903
904 outw(data_buffer_addr, ioaddr + READ_PTR);
905 pkt_len = inw(ioaddr);
906
907 if (rfd_cmd != 0 || data_buffer_addr != rx_head + 22
908 || pkt_len & 0xC000 != 0xC000) {
909 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x"
910 "next %04x data-buf @%04x %04x.\n", dev->name, rx_head,
911 frame_status, rfd_cmd, next_rx_frame, data_buffer_addr,
912 pkt_len);
913 } else if ((frame_status & 0x2000) == 0) {
914
915 lp->stats.rx_errors++;
916 if (frame_status & 0x0800) lp->stats.rx_crc_errors++;
917 if (frame_status & 0x0400) lp->stats.rx_frame_errors++;
918 if (frame_status & 0x0200) lp->stats.rx_fifo_errors++;
919 if (frame_status & 0x0100) lp->stats.rx_over_errors++;
920 if (frame_status & 0x0080) lp->stats.rx_length_errors++;
921 } else {
922
923 struct sk_buff *skb;
924
925 pkt_len &= 0x3fff;
926 skb = alloc_skb(pkt_len, GFP_ATOMIC);
927 if (skb == NULL) {
928 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
929 lp->stats.rx_dropped++;
930 break;
931 }
932 skb->len = pkt_len;
933 skb->dev = dev;
934
935 outw(data_buffer_addr + 10, ioaddr + READ_PTR);
936
937 insw(ioaddr, skb->data, (pkt_len + 1) >> 1);
938
939 netif_rx(skb);
940 lp->stats.rx_packets++;
941 }
942
943
944 outw(rx_head, ioaddr + WRITE_PTR);
945 outw(0x0000, ioaddr);
946 outw(0xC000, ioaddr);
947 #ifndef final_version
948 if (next_rx_frame != rx_head + RX_BUF_SIZE
949 && next_rx_frame != RX_BUF_START) {
950 printk("%s: Rx next frame at %#x is %#x instead of %#x.\n", dev->name,
951 rx_head, next_rx_frame, rx_head + RX_BUF_SIZE);
952 next_rx_frame = rx_head + RX_BUF_SIZE;
953 if (next_rx_frame >= RX_BUF_END - RX_BUF_SIZE)
954 next_rx_frame = RX_BUF_START;
955 }
956 #endif
957 outw(rx_tail+2, ioaddr + WRITE_PTR);
958 outw(0x0000, ioaddr);
959
960 #ifndef final_version
961 outw(rx_tail+4, ioaddr + READ_PTR);
962 if (inw(ioaddr) != rx_head) {
963 printk("%s: Rx buf link mismatch, at %04x link %04x instead of %04x.\n",
964 dev->name, rx_tail, (outw(rx_tail+4, ioaddr + READ_PTR),inw(ioaddr)),
965 rx_head);
966 outw(rx_head, ioaddr);
967 }
968 #endif
969
970 rx_tail = rx_head;
971 rx_head = next_rx_frame;
972 if (--boguscount == 0)
973 break;
974 outw(rx_head, ioaddr + READ_PTR);
975 }
976
977 lp->rx_head = rx_head;
978 lp->rx_tail = rx_tail;
979
980
981 outw(saved_write_ptr, ioaddr + WRITE_PTR);
982 }
983
984
985
986
987
988
989
990
991