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)) {
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 if (skb->free)
498 kfree_skb (skb, FREE_WRITE);
499
500
501 lp->stats.tx_aborted_errors++;
502
503 return 0;
504 }
505
506
507
508 static void
509 eexp_interrupt(int reg_ptr)
510 {
511 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
512 struct device *dev = (struct device *)(irq2dev_map[irq]);
513 struct net_local *lp;
514 int ioaddr, status, boguscount = 0;
515 short ack_cmd;
516
517 if (dev == NULL) {
518 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
519 return;
520 }
521 dev->interrupt = 1;
522
523 ioaddr = dev->base_addr;
524 lp = (struct net_local *)dev->priv;
525
526 status = inw(ioaddr + SCB_STATUS);
527
528 if (net_debug > 4) {
529 printk("%s: EExp interrupt, status %4.4x.\n", dev->name, status);
530 }
531
532
533 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
534
535
536 while (lp->tx_reap != lp->tx_head) {
537 unsigned short tx_status;
538 outw(lp->tx_reap, ioaddr + READ_PTR);
539 tx_status = inw(ioaddr);
540 if (tx_status == 0) {
541 if (net_debug > 5) printk("Couldn't reap %#x.\n", lp->tx_reap);
542 break;
543 }
544 if (tx_status & 0x2000) {
545 lp->stats.tx_packets++;
546 lp->stats.collisions += tx_status & 0xf;
547 dev->tbusy = 0;
548 mark_bh(INET_BH);
549 } else {
550 lp->stats.tx_errors++;
551 if (tx_status & 0x0600) lp->stats.tx_carrier_errors++;
552 if (tx_status & 0x0100) lp->stats.tx_fifo_errors++;
553 if (!(tx_status & 0x0040)) lp->stats.tx_heartbeat_errors++;
554 if (tx_status & 0x0020) lp->stats.tx_aborted_errors++;
555 }
556 if (net_debug > 5)
557 printk("Reaped %x, Tx status %04x.\n" , lp->tx_reap, tx_status);
558 lp->tx_reap += TX_BUF_SIZE;
559 if (lp->tx_reap > TX_BUF_END - TX_BUF_SIZE)
560 lp->tx_reap = TX_BUF_START;
561 if (++boguscount > 4)
562 break;
563 }
564
565 if (status & 0x4000) {
566 if (net_debug > 5)
567 printk("Received packet, rx_head %04x.\n", lp->rx_head);
568 eexp_rx(dev);
569 }
570
571
572 ack_cmd = status & 0xf000;
573
574 if ((status & 0x0700) != 0x0200 && dev->start) {
575 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
576 if (net_debug > 1)
577 printk("%s: Command unit stopped, status %04x, restarting.\n",
578 dev->name, status);
579
580
581 outw(IDLELOOP, ioaddr + WRITE_PTR);
582 outw(0, ioaddr);
583 outw(CmdNOp, ioaddr);
584 outw(IDLELOOP, ioaddr);
585 outw(IDLELOOP, SCB_CBL);
586 lp->tx_cmd_link = IDLELOOP + 4;
587 lp->tx_head = lp->tx_reap = TX_BUF_START;
588
589 outw(saved_write_ptr, ioaddr + WRITE_PTR);
590 ack_cmd |= CUC_START;
591 }
592
593 if ((status & 0x0070) != 0x0040 && dev->start) {
594 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
595
596
597 lp->stats.rx_errors++;
598 if (net_debug > 1) {
599 int cur_rxbuf = RX_BUF_START;
600 printk("%s: Rx unit stopped status %04x rx head %04x tail %04x.\n",
601 dev->name, status, lp->rx_head, lp->rx_tail);
602 while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE) {
603 int i;
604 printk(" Rx buf at %04x:", cur_rxbuf);
605 outw(cur_rxbuf, ioaddr + READ_PTR);
606 for (i = 0; i < 0x20; i += 2)
607 printk(" %04x", inw(ioaddr));
608 printk(".\n");
609 cur_rxbuf += RX_BUF_SIZE;
610 }
611 }
612 init_rx_bufs(dev);
613 outw(RX_BUF_START, SCB_RFA);
614 outw(saved_write_ptr, ioaddr + WRITE_PTR);
615 ack_cmd |= RX_START;
616 }
617
618 outw(ack_cmd, ioaddr + SCB_CMD);
619 outb(0, ioaddr + SIGNAL_CA);
620
621 if (net_debug > 5) {
622 printk("%s: EExp exiting interrupt, status %4.4x.\n", dev->name,
623 inw(ioaddr + SCB_CMD));
624 }
625
626 outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);
627 return;
628 }
629
630 static int
631 eexp_close(struct device *dev)
632 {
633 int ioaddr = dev->base_addr;
634
635 dev->tbusy = 1;
636 dev->start = 0;
637
638
639 outw(RX_SUSPEND | CUC_SUSPEND, ioaddr + SCB_CMD);
640 outb(0, ioaddr + SIGNAL_CA);
641
642
643 outb(0, ioaddr + SET_IRQ);
644
645 free_irq(dev->irq);
646
647 irq2dev_map[dev->irq] = 0;
648
649
650
651 return 0;
652 }
653
654
655
656 static struct enet_statistics *
657 eexp_get_stats(struct device *dev)
658 {
659 struct net_local *lp = (struct net_local *)dev->priv;
660
661
662
663 return &lp->stats;
664 }
665
666
667
668
669
670
671
672 static void
673 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
674 {
675 short ioaddr = dev->base_addr;
676 if (num_addrs < 0) {
677
678
679 } else if (num_addrs > 0) {
680
681
682 outw(SET_MC_CMD + 6, ioaddr + WRITE_PTR);
683 outw(num_addrs * 6, ioaddr);
684 outsw(ioaddr, addrs, num_addrs*3);
685
686 } else {
687
688
689 outw(99, ioaddr);
690 }
691 }
692
693
694
695
696 #define eeprom_delay() { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }}
697 #define EE_READ_CMD (6 << 6)
698
699 int
700 read_eeprom(int ioaddr, int location)
701 {
702 int i;
703 unsigned short retval = 0;
704 short ee_addr = ioaddr + EEPROM_Ctrl;
705 int read_cmd = location | EE_READ_CMD;
706 short ctrl_val = EE_CS | _586_RESET;
707
708 outb(ctrl_val, ee_addr);
709
710
711 for (i = 8; i >= 0; i--) {
712 short outval = (read_cmd & (1 << i)) ? ctrl_val | EE_DATA_WRITE
713 : ctrl_val;
714 outb(outval, ee_addr);
715 outb(outval | EE_SHIFT_CLK, ee_addr);
716 eeprom_delay();
717 outb(outval, ee_addr);
718 eeprom_delay();
719 }
720 outb(ctrl_val, ee_addr);
721
722 for (i = 16; i > 0; i--) {
723 outb(ctrl_val | EE_SHIFT_CLK, ee_addr); eeprom_delay();
724 retval = (retval << 1) | ((inb(ee_addr) & EE_DATA_READ) ? 1 : 0);
725 outb(ctrl_val, ee_addr); eeprom_delay();
726 }
727
728
729 ctrl_val &= ~EE_CS;
730 outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
731 eeprom_delay();
732 outb(ctrl_val, ee_addr);
733 eeprom_delay();
734 return retval;
735 }
736
737 static void
738 init_82586_mem(struct device *dev)
739 {
740 struct net_local *lp = (struct net_local *)dev->priv;
741 short ioaddr = dev->base_addr;
742
743
744
745 outb(inb(ioaddr + Config) | 0x02, ioaddr + Config);
746
747
748 outb(_586_RESET, ioaddr + EEPROM_Ctrl);
749
750
751 outw(0xfff6, ioaddr + WRITE_PTR);
752 outsw(ioaddr, init_words, sizeof(init_words)>>1);
753
754
755 outw(SA_OFFSET, ioaddr + WRITE_PTR);
756 outsw(ioaddr, dev->dev_addr, 3);
757
758
759 #ifdef initial_text_tx
760 lp->tx_cmd_link = DUMP_DATA + 4;
761 #else
762 lp->tx_cmd_link = IDLELOOP + 4;
763 #endif
764 lp->tx_head = lp->tx_reap = TX_BUF_START;
765
766 init_rx_bufs(dev);
767
768
769 outb(0x00, ioaddr + EEPROM_Ctrl);
770
771
772
773 outb(0, ioaddr + SIGNAL_CA);
774
775 {
776 int boguscnt = 50;
777 while (inw(ioaddr + SCB_STATUS) == 0)
778 if (--boguscnt == 0) {
779 printk("%s: i82586 initialization timed out with status %04x, cmd %04x.\n",
780 dev->name, inw(ioaddr + SCB_STATUS), inw(ioaddr + SCB_CMD));
781 break;
782 }
783
784 outb(0, ioaddr + SIGNAL_CA);
785 }
786
787
788 outb(inb(ioaddr + Config) & ~0x02, ioaddr + Config);
789 if (net_debug > 4)
790 printk("%s: Initialized 82586, status %04x.\n", dev->name,
791 inw(ioaddr + SCB_STATUS));
792 return;
793 }
794
795
796 static void init_rx_bufs(struct device *dev)
797 {
798 struct net_local *lp = (struct net_local *)dev->priv;
799 short ioaddr = dev->base_addr;
800
801 int cur_rxbuf = lp->rx_head = RX_BUF_START;
802
803
804 do {
805 outw(cur_rxbuf, ioaddr + WRITE_PTR);
806 outw(0x0000, ioaddr);
807 outw(0x0000, ioaddr);
808 outw(cur_rxbuf + RX_BUF_SIZE, ioaddr);
809 outw(cur_rxbuf + 22, ioaddr);
810 outw(0xFeed, ioaddr);
811 outw(0xF00d, ioaddr);
812 outw(0xF001, ioaddr);
813 outw(0x0505, ioaddr);
814 outw(0x2424, ioaddr);
815 outw(0x6565, ioaddr);
816 outw(0xdeaf, ioaddr);
817
818 outw(0x0000, ioaddr);
819 outw(-1, ioaddr);
820 outw(cur_rxbuf + 0x20, ioaddr);
821 outw(0x0000, ioaddr);
822
823 outw(0x8000 + RX_BUF_SIZE-0x20, ioaddr);
824
825 lp->rx_tail = cur_rxbuf;
826 cur_rxbuf += RX_BUF_SIZE;
827 } while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE);
828
829
830
831 outw(lp->rx_tail + 2, ioaddr + WRITE_PTR);
832 outw(0xC000, ioaddr);
833 outw(lp->rx_head, ioaddr);
834 }
835
836 static void
837 hardware_send_packet(struct device *dev, void *buf, short length)
838 {
839 struct net_local *lp = (struct net_local *)dev->priv;
840 short ioaddr = dev->base_addr;
841 short tx_block = lp->tx_head;
842
843
844 outw(tx_block, ioaddr + WRITE_PTR);
845 outw(0x0000, ioaddr);
846 outw(CMD_INTR|CmdTx, ioaddr);
847 outw(tx_block+16, ioaddr);
848 outw(tx_block+8, ioaddr);
849
850
851 outw(length | 0x8000, ioaddr);
852 outw(-1, ioaddr);
853 outw(tx_block+22, ioaddr);
854 outw(0x0000, ioaddr);
855
856
857 outw(0x0000, ioaddr);
858 outw(CmdNOp, ioaddr);
859 outw(tx_block+16, ioaddr);
860
861
862
863 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
864
865
866 outw(lp->tx_cmd_link, ioaddr + WRITE_PTR);
867 outw(tx_block, ioaddr);
868 lp->tx_cmd_link = tx_block + 20;
869
870
871 lp->tx_head = tx_block + TX_BUF_SIZE;
872 if (lp->tx_head > TX_BUF_END - TX_BUF_SIZE)
873 lp->tx_head = TX_BUF_START;
874
875 if (net_debug > 4) {
876 printk("%s: EExp @%x send length = %d, tx_block %3x, next %3x, "
877 "reap %4x status %4.4x.\n", dev->name, ioaddr, length,
878 tx_block, lp->tx_head, lp->tx_reap, inw(ioaddr + SCB_STATUS));
879 }
880
881 if (lp->tx_head != lp->tx_reap)
882 dev->tbusy = 0;
883 }
884
885 static void
886 eexp_rx(struct device *dev)
887 {
888 struct net_local *lp = (struct net_local *)dev->priv;
889 short ioaddr = dev->base_addr;
890 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
891 short rx_head = lp->rx_head;
892 short rx_tail = lp->rx_tail;
893 short boguscount = 10;
894 short frame_status;
895
896
897 outw(rx_head, ioaddr + READ_PTR);
898 while ((frame_status = inw(ioaddr)) < 0) {
899 short rfd_cmd = inw(ioaddr);
900 short next_rx_frame = inw(ioaddr);
901 short data_buffer_addr = inw(ioaddr);
902 short pkt_len;
903
904
905 outw(data_buffer_addr, ioaddr + READ_PTR);
906 pkt_len = inw(ioaddr);
907
908 if (rfd_cmd != 0 || data_buffer_addr != rx_head + 22
909 || pkt_len & 0xC000 != 0xC000) {
910 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x"
911 "next %04x data-buf @%04x %04x.\n", dev->name, rx_head,
912 frame_status, rfd_cmd, next_rx_frame, data_buffer_addr,
913 pkt_len);
914 } else if ((frame_status & 0x2000) == 0) {
915
916 lp->stats.rx_errors++;
917 if (frame_status & 0x0800) lp->stats.rx_crc_errors++;
918 if (frame_status & 0x0400) lp->stats.rx_frame_errors++;
919 if (frame_status & 0x0200) lp->stats.rx_fifo_errors++;
920 if (frame_status & 0x0100) lp->stats.rx_over_errors++;
921 if (frame_status & 0x0080) lp->stats.rx_length_errors++;
922 } else {
923
924 struct sk_buff *skb;
925
926 pkt_len &= 0x3fff;
927 skb = alloc_skb(pkt_len, GFP_ATOMIC);
928 if (skb == NULL) {
929 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
930 lp->stats.rx_dropped++;
931 break;
932 }
933 skb->len = pkt_len;
934 skb->dev = dev;
935
936 outw(data_buffer_addr + 10, ioaddr + READ_PTR);
937
938 insw(ioaddr, skb->data, (pkt_len + 1) >> 1);
939
940 netif_rx(skb);
941 lp->stats.rx_packets++;
942 }
943
944
945 outw(rx_head, ioaddr + WRITE_PTR);
946 outw(0x0000, ioaddr);
947 outw(0xC000, ioaddr);
948 #ifndef final_version
949 if (next_rx_frame != rx_head + RX_BUF_SIZE
950 && next_rx_frame != RX_BUF_START) {
951 printk("%s: Rx next frame at %#x is %#x instead of %#x.\n", dev->name,
952 rx_head, next_rx_frame, rx_head + RX_BUF_SIZE);
953 next_rx_frame = rx_head + RX_BUF_SIZE;
954 if (next_rx_frame >= RX_BUF_END - RX_BUF_SIZE)
955 next_rx_frame = RX_BUF_START;
956 }
957 #endif
958 outw(rx_tail+2, ioaddr + WRITE_PTR);
959 outw(0x0000, ioaddr);
960
961 #ifndef final_version
962 outw(rx_tail+4, ioaddr + READ_PTR);
963 if (inw(ioaddr) != rx_head) {
964 printk("%s: Rx buf link mismatch, at %04x link %04x instead of %04x.\n",
965 dev->name, rx_tail, (outw(rx_tail+4, ioaddr + READ_PTR),inw(ioaddr)),
966 rx_head);
967 outw(rx_head, ioaddr);
968 }
969 #endif
970
971 rx_tail = rx_head;
972 rx_head = next_rx_frame;
973 if (--boguscount == 0)
974 break;
975 outw(rx_head, ioaddr + READ_PTR);
976 }
977
978 lp->rx_head = rx_head;
979 lp->rx_tail = rx_tail;
980
981
982 outw(saved_write_ptr, ioaddr + WRITE_PTR);
983 }
984
985
986
987
988
989
990
991
992