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 static char *version =
25 "eexpress.c:v0.07 1/19/94 Donald Becker (becker@super.org)\n";
26
27 #include <linux/config.h>
28
29
30
31
32
33
34
35
36
37
38
39
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/types.h>
43 #include <linux/fcntl.h>
44 #include <linux/interrupt.h>
45 #include <linux/ptrace.h>
46 #include <linux/ioport.h>
47 #include <linux/string.h>
48 #include <linux/in.h>
49 #include <asm/system.h>
50 #include <asm/bitops.h>
51 #include <asm/io.h>
52 #include <asm/dma.h>
53 #include <linux/errno.h>
54
55 #include <linux/netdevice.h>
56 #include <linux/etherdevice.h>
57 #include <linux/skbuff.h>
58 #ifdef MODULE
59 #include <linux/module.h>
60 #include "../../tools/version.h"
61 #endif
62
63 #include <linux/malloc.h>
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 0x0680
199 #define TX_BUF_END 0x2000
200
201 #define RX_BUF_START 0x2000
202 #define RX_BUF_SIZE (0x640)
203 #define RX_BUF_END 0x4000
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
238 static short init_words[] = {
239 0x0000,
240 0x0000,0x0000,
241 0,0,
242 0x0001,
243 0x0008,0,0,
244
245 0,0xf000|RX_START|CUC_START,
246 CONFIG_CMD,
247 RX_BUF_START,
248 0,0,0,0,
249
250
251 0, CmdConfigure,
252 SET_SA_CMD,
253 0x0804,
254 0x2e40,
255 0,
256
257
258 0, CmdSASetup,
259 SET_MC_CMD,
260 0xaa00,0xb000,0x0bad,
261
262
263 0, CmdNOp, IDLELOOP, 0 ,
264
265
266 0, CmdTDR, IDLELOOP, 0,
267
268
269 0, CmdDump, IDLELOOP, DUMP_DATA,
270
271
272 0, CmdDiagnose, IDLELOOP,
273
274
275 #ifdef initial_text_tx
276 0, CmdMulticastList, DUMP_DATA, 0,
277 #else
278 0, CmdMulticastList, IDLELOOP, 0,
279 #endif
280
281
282 0, CmdTx, DUMP_DATA, DUMP_DATA+8, 0x83ff, -1, DUMP_DATA, 0,
283 };
284
285
286
287 extern int express_probe(struct device *dev);
288
289 static int eexp_probe1(struct device *dev, short ioaddr);
290 static int eexp_open(struct device *dev);
291 static int eexp_send_packet(struct sk_buff *skb, struct device *dev);
292 static void eexp_interrupt(int reg_ptr);
293 static void eexp_rx(struct device *dev);
294 static int eexp_close(struct device *dev);
295 static struct enet_statistics *eexp_get_stats(struct device *dev);
296 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
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 printk("EtherExpress ID checksum is %04x.\n", sum);
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 dev->set_multicast_list = &set_multicast_list;
408
409
410
411 ether_setup(dev);
412
413 return 0;
414 }
415
416
417
418 static char irqrmap[]={0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0};
419
420 static int
421 eexp_open(struct device *dev)
422 {
423 int ioaddr = dev->base_addr;
424
425 if (dev->irq == 0 || irqrmap[dev->irq] == 0)
426 return -ENXIO;
427
428 if (irq2dev_map[dev->irq] != 0
429
430 || (irq2dev_map[dev->irq] = dev) == 0
431 || request_irq(dev->irq, &eexp_interrupt, 0, "EExpress")) {
432 return -EAGAIN;
433 }
434
435
436 init_82586_mem(dev);
437
438
439 outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);
440
441 dev->tbusy = 0;
442 dev->interrupt = 0;
443 dev->start = 1;
444 #ifdef MODULE
445 MOD_INC_USE_COUNT;
446 #endif
447 return 0;
448 }
449
450 static int
451 eexp_send_packet(struct sk_buff *skb, struct device *dev)
452 {
453 struct net_local *lp = (struct net_local *)dev->priv;
454 int ioaddr = dev->base_addr;
455
456 if (dev->tbusy) {
457
458
459 int tickssofar = jiffies - dev->trans_start;
460 if (tickssofar < 5)
461 return 1;
462 if (net_debug > 1)
463 printk("%s: transmit timed out, %s? ", dev->name,
464 inw(ioaddr+SCB_STATUS) & 0x8000 ? "IRQ conflict" :
465 "network cable problem");
466 lp->stats.tx_errors++;
467
468 if (lp->last_restart == lp->stats.tx_packets) {
469 if (net_debug > 1) printk("Resetting board.\n");
470
471 init_82586_mem(dev);
472 } else {
473
474 if (net_debug > 1) printk("Kicking board.\n");
475 outw(0xf000|CUC_START|RX_START, ioaddr + SCB_CMD);
476 outb(0, ioaddr + SIGNAL_CA);
477 lp->last_restart = lp->stats.tx_packets;
478 }
479 dev->tbusy=0;
480 dev->trans_start = jiffies;
481 }
482
483
484
485
486 if (skb == NULL) {
487 dev_tint(dev);
488 return 0;
489 }
490
491
492 if (set_bit(0, (void*)&dev->tbusy) != 0)
493 printk("%s: Transmitter access conflict.\n", dev->name);
494 else {
495 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
496 unsigned char *buf = skb->data;
497
498
499 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
500 hardware_send_packet(dev, buf, length);
501 dev->trans_start = jiffies;
502
503 outb(0x08 | irqrmap[dev->irq], ioaddr + SET_IRQ);
504 }
505
506 dev_kfree_skb (skb, FREE_WRITE);
507
508
509 lp->stats.tx_aborted_errors++;
510
511 return 0;
512 }
513
514
515
516 static void
517 eexp_interrupt(int reg_ptr)
518 {
519 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
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
659 #ifdef MODULE
660 MOD_DEC_USE_COUNT;
661 #endif
662 return 0;
663 }
664
665
666
667 static struct enet_statistics *
668 eexp_get_stats(struct device *dev)
669 {
670 struct net_local *lp = (struct net_local *)dev->priv;
671
672
673
674 return &lp->stats;
675 }
676
677
678
679
680
681
682
683 static void
684 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
685 {
686 short ioaddr = dev->base_addr;
687 if (num_addrs < 0) {
688
689
690 } else if (num_addrs > 0) {
691
692
693 outw(SET_MC_CMD + 6, ioaddr + WRITE_PTR);
694 outw(num_addrs * 6, ioaddr);
695 outsw(ioaddr, addrs, num_addrs*3);
696
697 } else {
698
699
700 outw(99, ioaddr);
701 }
702 }
703
704
705
706
707 #define eeprom_delay() { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }}
708 #define EE_READ_CMD (6 << 6)
709
710 int
711 read_eeprom(int ioaddr, int location)
712 {
713 int i;
714 unsigned short retval = 0;
715 short ee_addr = ioaddr + EEPROM_Ctrl;
716 int read_cmd = location | EE_READ_CMD;
717 short ctrl_val = EE_CS | _586_RESET;
718
719 outb(ctrl_val, ee_addr);
720
721
722 for (i = 8; i >= 0; i--) {
723 short outval = (read_cmd & (1 << i)) ? ctrl_val | EE_DATA_WRITE
724 : ctrl_val;
725 outb(outval, ee_addr);
726 outb(outval | EE_SHIFT_CLK, ee_addr);
727 eeprom_delay();
728 outb(outval, ee_addr);
729 eeprom_delay();
730 }
731 outb(ctrl_val, ee_addr);
732
733 for (i = 16; i > 0; i--) {
734 outb(ctrl_val | EE_SHIFT_CLK, ee_addr); eeprom_delay();
735 retval = (retval << 1) | ((inb(ee_addr) & EE_DATA_READ) ? 1 : 0);
736 outb(ctrl_val, ee_addr); eeprom_delay();
737 }
738
739
740 ctrl_val &= ~EE_CS;
741 outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
742 eeprom_delay();
743 outb(ctrl_val, ee_addr);
744 eeprom_delay();
745 return retval;
746 }
747
748 static void
749 init_82586_mem(struct device *dev)
750 {
751 struct net_local *lp = (struct net_local *)dev->priv;
752 short ioaddr = dev->base_addr;
753
754
755
756 outb(inb(ioaddr + Config) | 0x02, ioaddr + Config);
757
758
759 outb(_586_RESET, ioaddr + EEPROM_Ctrl);
760
761
762 outw(0xfff6, ioaddr + WRITE_PTR);
763 outsw(ioaddr, init_words, sizeof(init_words)>>1);
764
765
766 outw(SA_OFFSET, ioaddr + WRITE_PTR);
767 outsw(ioaddr, dev->dev_addr, 3);
768
769
770 #ifdef initial_text_tx
771 lp->tx_cmd_link = DUMP_DATA + 4;
772 #else
773 lp->tx_cmd_link = IDLELOOP + 4;
774 #endif
775 lp->tx_head = lp->tx_reap = TX_BUF_START;
776
777 init_rx_bufs(dev);
778
779
780 outb(0x00, ioaddr + EEPROM_Ctrl);
781
782
783
784 outb(0, ioaddr + SIGNAL_CA);
785
786 {
787 int boguscnt = 50;
788 while (inw(ioaddr + SCB_STATUS) == 0)
789 if (--boguscnt == 0) {
790 printk("%s: i82586 initialization timed out with status %04x, cmd %04x.\n",
791 dev->name, inw(ioaddr + SCB_STATUS), inw(ioaddr + SCB_CMD));
792 break;
793 }
794
795 outb(0, ioaddr + SIGNAL_CA);
796 }
797
798
799 outb(inb(ioaddr + Config) & ~0x02, ioaddr + Config);
800 if (net_debug > 4)
801 printk("%s: Initialized 82586, status %04x.\n", dev->name,
802 inw(ioaddr + SCB_STATUS));
803 return;
804 }
805
806
807 static void init_rx_bufs(struct device *dev)
808 {
809 struct net_local *lp = (struct net_local *)dev->priv;
810 short ioaddr = dev->base_addr;
811
812 int cur_rxbuf = lp->rx_head = RX_BUF_START;
813
814
815 do {
816 outw(cur_rxbuf, ioaddr + WRITE_PTR);
817 outw(0x0000, ioaddr);
818 outw(0x0000, ioaddr);
819 outw(cur_rxbuf + RX_BUF_SIZE, ioaddr);
820 outw(cur_rxbuf + 22, ioaddr);
821 outw(0xFeed, ioaddr);
822 outw(0xF00d, ioaddr);
823 outw(0xF001, ioaddr);
824 outw(0x0505, ioaddr);
825 outw(0x2424, ioaddr);
826 outw(0x6565, ioaddr);
827 outw(0xdeaf, ioaddr);
828
829 outw(0x0000, ioaddr);
830 outw(-1, ioaddr);
831 outw(cur_rxbuf + 0x20, ioaddr);
832 outw(0x0000, ioaddr);
833
834 outw(0x8000 + RX_BUF_SIZE-0x20, ioaddr);
835
836 lp->rx_tail = cur_rxbuf;
837 cur_rxbuf += RX_BUF_SIZE;
838 } while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE);
839
840
841
842 outw(lp->rx_tail + 2, ioaddr + WRITE_PTR);
843 outw(0xC000, ioaddr);
844 outw(lp->rx_head, ioaddr);
845 }
846
847 static void
848 hardware_send_packet(struct device *dev, void *buf, short length)
849 {
850 struct net_local *lp = (struct net_local *)dev->priv;
851 short ioaddr = dev->base_addr;
852 short tx_block = lp->tx_head;
853
854
855 outw(tx_block, ioaddr + WRITE_PTR);
856 outw(0x0000, ioaddr);
857 outw(CMD_INTR|CmdTx, ioaddr);
858 outw(tx_block+16, ioaddr);
859 outw(tx_block+8, ioaddr);
860
861
862 outw(length | 0x8000, ioaddr);
863 outw(-1, ioaddr);
864 outw(tx_block+22, ioaddr);
865 outw(0x0000, ioaddr);
866
867
868 outw(0x0000, ioaddr);
869 outw(CmdNOp, ioaddr);
870 outw(tx_block+16, ioaddr);
871
872
873
874 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
875
876
877 outw(lp->tx_cmd_link, ioaddr + WRITE_PTR);
878 outw(tx_block, ioaddr);
879 lp->tx_cmd_link = tx_block + 20;
880
881
882 lp->tx_head = tx_block + TX_BUF_SIZE;
883 if (lp->tx_head > TX_BUF_END - TX_BUF_SIZE)
884 lp->tx_head = TX_BUF_START;
885
886 if (net_debug > 4) {
887 printk("%s: EExp @%x send length = %d, tx_block %3x, next %3x, "
888 "reap %4x status %4.4x.\n", dev->name, ioaddr, length,
889 tx_block, lp->tx_head, lp->tx_reap, inw(ioaddr + SCB_STATUS));
890 }
891
892 if (lp->tx_head != lp->tx_reap)
893 dev->tbusy = 0;
894 }
895
896 static void
897 eexp_rx(struct device *dev)
898 {
899 struct net_local *lp = (struct net_local *)dev->priv;
900 short ioaddr = dev->base_addr;
901 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
902 short rx_head = lp->rx_head;
903 short rx_tail = lp->rx_tail;
904 short boguscount = 10;
905 short frame_status;
906
907
908 outw(rx_head, ioaddr + READ_PTR);
909 while ((frame_status = inw(ioaddr)) < 0) {
910 short rfd_cmd = inw(ioaddr);
911 short next_rx_frame = inw(ioaddr);
912 short data_buffer_addr = inw(ioaddr);
913 short pkt_len;
914
915
916 outw(data_buffer_addr, ioaddr + READ_PTR);
917 pkt_len = inw(ioaddr);
918
919 if (rfd_cmd != 0 || data_buffer_addr != rx_head + 22
920 || pkt_len & 0xC000 != 0xC000) {
921 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x"
922 "next %04x data-buf @%04x %04x.\n", dev->name, rx_head,
923 frame_status, rfd_cmd, next_rx_frame, data_buffer_addr,
924 pkt_len);
925 } else if ((frame_status & 0x2000) == 0) {
926
927 lp->stats.rx_errors++;
928 if (frame_status & 0x0800) lp->stats.rx_crc_errors++;
929 if (frame_status & 0x0400) lp->stats.rx_frame_errors++;
930 if (frame_status & 0x0200) lp->stats.rx_fifo_errors++;
931 if (frame_status & 0x0100) lp->stats.rx_over_errors++;
932 if (frame_status & 0x0080) lp->stats.rx_length_errors++;
933 } else {
934
935 struct sk_buff *skb;
936
937 pkt_len &= 0x3fff;
938 skb = alloc_skb(pkt_len, GFP_ATOMIC);
939 if (skb == NULL) {
940 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
941 lp->stats.rx_dropped++;
942 break;
943 }
944 skb->len = pkt_len;
945 skb->dev = dev;
946
947 outw(data_buffer_addr + 10, ioaddr + READ_PTR);
948
949 insw(ioaddr, skb->data, (pkt_len + 1) >> 1);
950
951 netif_rx(skb);
952 lp->stats.rx_packets++;
953 }
954
955
956 outw(rx_head, ioaddr + WRITE_PTR);
957 outw(0x0000, ioaddr);
958 outw(0xC000, ioaddr);
959 #ifndef final_version
960 if (next_rx_frame != rx_head + RX_BUF_SIZE
961 && next_rx_frame != RX_BUF_START) {
962 printk("%s: Rx next frame at %#x is %#x instead of %#x.\n", dev->name,
963 rx_head, next_rx_frame, rx_head + RX_BUF_SIZE);
964 next_rx_frame = rx_head + RX_BUF_SIZE;
965 if (next_rx_frame >= RX_BUF_END - RX_BUF_SIZE)
966 next_rx_frame = RX_BUF_START;
967 }
968 #endif
969 outw(rx_tail+2, ioaddr + WRITE_PTR);
970 outw(0x0000, ioaddr);
971
972 #ifndef final_version
973 outw(rx_tail+4, ioaddr + READ_PTR);
974 if (inw(ioaddr) != rx_head) {
975 printk("%s: Rx buf link mismatch, at %04x link %04x instead of %04x.\n",
976 dev->name, rx_tail, (outw(rx_tail+4, ioaddr + READ_PTR),inw(ioaddr)),
977 rx_head);
978 outw(rx_head, ioaddr);
979 }
980 #endif
981
982 rx_tail = rx_head;
983 rx_head = next_rx_frame;
984 if (--boguscount == 0)
985 break;
986 outw(rx_head, ioaddr + READ_PTR);
987 }
988
989 lp->rx_head = rx_head;
990 lp->rx_tail = rx_tail;
991
992
993 outw(saved_write_ptr, ioaddr + WRITE_PTR);
994 }
995
996 #ifdef MODULE
997 char kernel_version[] = UTS_RELEASE;
998 static struct device dev_eexpress = {
999 " " , 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, express_probe };
1000
1001 int
1002 init_module(void)
1003 {
1004 if (register_netdev(&dev_eexpress) != 0)
1005 return -EIO;
1006 return 0;
1007 }
1008
1009 void
1010 cleanup_module(void)
1011 {
1012 if (MOD_IN_USE)
1013 printk("express: device busy, remove delayed\n");
1014 else
1015 {
1016 unregister_netdev(&dev_eexpress);
1017 kfree_s(dev_eexpress.priv,sizeof(struct net_local));
1018 dev_eexpress.priv=NULL;
1019 }
1020 }
1021 #endif
1022
1023
1024
1025
1026
1027
1028
1029