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