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