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