1
2 /* eexpress.c: Intel EtherExpress device driver for Linux. */
3 /*
4 Written 1993 by Donald Becker.
5 Copyright 1993 United States Government as represented by the Director,
6 National Security Agency. This software may only be used and distributed
7 according to the terms of the GNU Public License as modified by SRC,
8 incorported herein by reference.
9
10 The author may be reached as becker@super.org or
11 C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
12
13 Things remaining to do:
14 Check that the 586 and ASIC are reset/unreset at the right times.
15 Check tx and rx buffer setup.
16 The current Tx is single-buffer-only.
17 Move the theory of operation and memory map documentation.
18 Rework the board error reset
19 The statistics need to be updated correctly.
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 Sources:
29 This driver wouldn't have been written with the availability of the
30 Crynwr driver source code. It provided a known-working implementation
31 that filled in the gaping holes of the Intel documention. Three cheers
32 for Russ Nelson.
33
34 Intel Microcommunications Databook, Vol. 1, 1990. It provides just enough
35 info that the casual reader might think that it documents the i82586.
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 /* use 0 for production, 1 for verification, 2..7 for debug */
60 #ifndef NET_DEBUG
61 #define NET_DEBUG 2
62 #endif
63 static unsigned int net_debug = NET_DEBUG;
64
65 /*
66 Details of the i82586.
67
68 You'll really need the databook to understand the details of this part,
69 but the outline is that the i82586 has two seperate processing units.
70
71 The Rx unit uses a list of frame descriptors and a list of data buffer
72 descriptors. We use full-sized (1518 byte) data buffers, so there is
73 a one-to-one pairing of frame descriptors to buffer descriptors.
74
75 The Tx ("command") unit executes a list of commands that look like:
76 Status word Written by the 82586 when the command is done.
77 Command word Command in lower 3 bits, post-command action in upper 3
78 Link word The address of the next command.
79 Parameters (as needed).
80
81 Some definitions related to the Command Word are:
82 */
83 #define CMD_EOL 0x8000 /* The last command of the list, stop. */
84 #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
85 #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
86
87 enum commands {
88 CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
89 CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7};
90
91 /* Information that need to be kept for each board. */
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 Details of the EtherExpress Implementation
104 The EtherExpress takes an unusual approach to host access to packet buffer
105 memory. The host can use either the Dataport, with independent
106 autoincrementing read and write pointers, or it can I/O map 32 bytes of the
107 memory using the "Shadow Memory Pointer" (SMB) as follows:
108 ioaddr Normal EtherExpress registers
109 ioaddr+0x4000...0x400f Buffer Memory at SMB...SMB+15
110 ioaddr+0x8000...0x800f Buffer Memory at SMB+16...SMB+31
111 ioaddr+0xC000...0xC007 "" SMB+16...SMB+23 (hardware flaw?)
112 ioaddr+0xC008...0xC00f Buffer Memory at 0x0008...0x000f
113 The last I/O map set is useful if you put the i82586 System Command Block
114 (the command mailbox) exactly at 0x0008. (There seems to be some
115 undocumented init structure at 0x0000-7, so I had to use the Crywnr memory
116 setup verbatim for those four words anyway.)
117
118 A problem with using either one of these mechanisms is that you must run
119 single-threaded, or the interrupt handler must restore a changed value of
120 the read, write, or SMB pointers.
121
122 Unlike the Crynwr driver, my driver mostly ignores the I/O mapped "feature"
123 and relies heavily on the dataport for buffer memory access. To minimize
124 switching, the read_pointer is dedicated to the Rx interrupt handler, and
125 the write_pointer is used by the send_packet() routine (it's carefully saved
126 and restored when it's needed by the interrupt handler).
127 */
128
129 /* Offsets from the base I/O address. */
130 #define DATAPORT 0 /* Data Transfer Register. */
131 #define WRITE_PTR 2 /* Write Address Pointer. */
132 #define READ_PTR 4 /* Read Address Pointer. */
133 #define SIGNAL_CA 6 /* Frob the 82586 Channel Attention line. */
134 #define SET_IRQ 7 /* IRQ Select. */
135 #define SHADOW_PTR 8 /* Shadow Memory Bank Pointer. */
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 /* EEPROM_Ctrl bits. */
143
144 #define EE_SHIFT_CLK 0x01 /* EEPROM shift clock. */
145 #define EE_CS 0x02 /* EEPROM chip select. */
146 #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
147 #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
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 /* Offsets to elements of the System Control Block structure. */
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 /* Command BLock offset. */
162 #define SCB_RFA 0xc00E /* Rx Frame Area offset. */
163
164 /*
165 What follows in 'init_words[]' is the "program" that is downloaded to the
166 82586 memory. It's mostly tables and command blocks, and starts at the
167 reset address 0xfffff6.
168
169 Even with the additional "don't care" values, doing it this way takes less
170 program space than initializing the individual tables, and I feel it's much
171 cleaner.
172
173 The databook is particularly useless for the first two structures; they are
174 completely undocumented. I had to use the Crynwr driver as an example.
175
176 The memory setup is as follows:
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 /* A 170 byte buffer for dump and Set-MC into. */
189
190 #define TX_BUF_START 0x0100
191 #define NUM_TX_BUFS 4
192 #define TX_BUF_SIZE 0x0680 /* packet+header+TBD+extra (1518+14+20+16) */
193 #define TX_BUF_END 0x2000
194
195 #define RX_BUF_START 0x2000
196 #define RX_BUF_SIZE (0x640) /* packet+header+RBD+extra */
197 #define RX_BUF_END 0x4000
198
199 /*
200 That's it: only 86 bytes to set up the beast, including every extra
201 command available. The 170 byte buffer at DUMP_DATA is shared between the
202 Dump command (called only by the diagnostic program) and the SetMulticastList
203 command.
204
205 To complete the memory setup you only have to write the station address at
206 SA_OFFSET and create the Tx & Rx buffer lists.
207
208 The Tx command chain and buffer list is setup as follows:
209 A Tx command table, with the data buffer pointing to...
210 A Tx data buffer descriptor. The packet is in a single buffer, rather than
211 chaining together several smaller buffers.
212 A NoOp command, which initially points to itself,
213 And the packet data.
214
215 A transmit is done by filling in the Tx command table and data buffer,
216 re-writing the NoOp command, and finally changing the offset of the last
217 command to point to the current Tx command. When the Tx command is finished,
218 it jumps to the NoOp, when it loops until the next Tx command changes the
219 "link offset" in the NoOp. This way the 82586 never has to go through the
220 slow restart sequence.
221
222 The Rx buffer list is set up in the obvious ring structure. We have enough
223 memory (and low enough interrupt latency) that we can avoid the complicated
224 Rx buffer linked lists by alway associating a full-size Rx data buffer with
225 each Rx data frame.
226
227 I current use four transmit buffers starting at TX_BUF_START (0x0100), and
228 use the rest of memory, from RX_BUF_START to RX_BUF_END, for Rx buffers.
229
230 */
231
232 static short init_words[] = {
233 0x0000, /* Set bus size to 16 bits. */
234 0x0000,0x0000, /* Set control mailbox (SCB) addr. */
235 0,0, /* pad to 0x000000. */
236 0x0001, /* Status word that's cleared when init is done. */
237 0x0008,0,0, /* SCB offset, (skip, skip) */
238
239 0,0xf000|RX_START|CUC_START, /* SCB status and cmd. */
240 CONFIG_CMD, /* Command list pointer, points to Configure. */
241 RX_BUF_START, /* Rx block list. */
242 0,0,0,0, /* Error count: CRC, align, buffer, overrun. */
243
244 /* 0x0018: Configure command. Change to put MAC data with packet. */
245 0, CmdConfigure, /* Status, command. */
246 SET_SA_CMD, /* Next command is Set Station Addr. */
247 0x0804, /* "4" bytes of config data, 8 byte FIFO. */
248 0x2e40, /* Magic values, including MAC data location. */
249 0, /* Unused pad word. */
250
251 /* 0x0024: Setup station address command. */
252 0, CmdSASetup,
253 SET_MC_CMD, /* Next command. */
254 0xaa00,0xb000,0x0bad, /* Station address (to be filled in) */
255
256 /* 0x0030: NOP, looping back to itself. Point to first Tx buffer to Tx. */
257 0, CmdNOp, IDLELOOP, 0 /* pad */,
258
259 /* 0x0038: A unused Time-Domain Reflectometer command. */
260 0, CmdTDR, IDLELOOP, 0,
261
262 /* 0x0040: An unused Dump State command. */
263 0, CmdDump, IDLELOOP, DUMP_DATA,
264
265 /* 0x0048: An unused Diagnose command. */
266 0, CmdDiagnose, IDLELOOP,
267
268 /* 0x004E: An empty set-multicast-list command. */
269 #ifdef initial_text_tx
270 0, CmdMulticastList, DUMP_DATA, 0,
271 #else
272 0, CmdMulticastList, IDLELOOP, 0,
273 #endif
274
275 /* 0x0056: A continuous transmit command, only here for testing. */
276 0, CmdTx, DUMP_DATA, DUMP_DATA+8, 0x83ff, -1, DUMP_DATA, 0,
277 };
278
279 /* Index to functions, as function prototypes. */
280
281 extern int express_probe(struct device *dev); /* Called from Space.c */
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 /* Check for a network adaptor of this type, and return '0' iff one exists.
299 If dev->base_addr == 0, probe all likely locations.
300 If dev->base_addr == 1, always return failure.
301 If dev->base_addr == 2, (detachable devices only) alloate space for the
302 device and return success.
303 */
304 int
305 express_probe(struct device *dev)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
306 {
307 /* Don't probe all settable addresses, 0x[23][0-7]0, just common ones. */
308 int *port, ports[] = {0x300, 0x270, 0x320, 0x340, 0};
309 int base_addr = dev->base_addr;
310
311 if (base_addr > 0x1ff) /* Check a single specified location. */
312 return eexp_probe1(dev, base_addr);
313 else if (base_addr > 0)
314 return ENXIO; /* Don't probe at all. */
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; /* ENODEV would be more accurate. */
336 }
337
338 int eexp_probe1(struct device *dev, short ioaddr)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
339 {
340 unsigned short station_addr[3];
341 int i;
342
343 printk("%s: EtherExpress at %#x,", dev->name, ioaddr);
344
345 /* The station address is stored !backwards! in the EEPROM, reverse
346 after reading. (Hmmm, a little brain-damage there at Intel, eh?) */
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 /* Check the first three octets of the S.A. for the manufactor's code. */
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 /* We've committed to using the board, and can start filling in *dev. */
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 /* There is no reason for the driver to care, but I print out the
368 interface to minimize bogus bug reports. */
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 /* Release the IRQ line so that it can be shared if we don't use the
380 ethercard. */
381 outb(0x00, ioaddr + SET_IRQ);
382 }
383
384 /* It's now OK to leave the board in reset, pending the open(). */
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 /* Initialize the device structure. */
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 /* Fill in the fields of the device structure with ethernet-generic values. */
404
405 ether_setup(dev);
406
407 return 0;
408 }
409
410
411 /* Reverse IRQ map: the value to put in the SET_IRQ reg. for IRQ<index>. */
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)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
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 /* This is always true, but avoid the false IRQ. */
424 || (irq2dev_map[dev->irq] = dev) == 0
425 || request_irq(dev->irq, &eexp_interrupt)) {
426 return -EAGAIN;
427 }
428
429 /* Initialize the 82586 memory and start it. */
430 init_82586_mem(dev);
431
432 /* Enable the interrupt line. */
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)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
443 {
444 struct net_local *lp = (struct net_local *)dev->priv;
445 int ioaddr = dev->base_addr;
446
447 if (dev->tbusy) {
448 /* If we get here, some higher level has decided we are broken.
449 There should really be a "kick me" function call instead. */
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 /* Try to restart the adaptor. */
459 if (lp->last_restart == lp->stats.tx_packets) {
460 if (net_debug > 1) printk("Resetting board.\n");
461 /* Completely reset the adaptor. */
462 init_82586_mem(dev);
463 } else {
464 /* Issue the channel attention signal and hope it "gets better". */
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 /* If some higher layer thinks we've missed an tx-done interrupt
475 we are passed NULL. Caution: dev_tint() handles the cli()/sti()
476 itself. */
477 if (skb == NULL) {
478 dev_tint(dev);
479 return 0;
480 }
481
482 /* Block a timer-based transmit from overlapping. */
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 /* Disable the 82586's input to the interrupt line. */
490 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
491 hardware_send_packet(dev, buf, length);
492 dev->trans_start = jiffies;
493 /* Enable the 82586 interrupt input. */
494 outb(0x08 | irqrmap[dev->irq], ioaddr + SET_IRQ);
495 }
496
497 dev_kfree_skb (skb, FREE_WRITE);
498
499 /* You might need to clean up and record Tx statistics here. */
500 lp->stats.tx_aborted_errors++;
501
502 return 0;
503 }
504
505 /* The typical workload of the driver:
506 Handle the network interface interrupts. */
507 static void
508 eexp_interrupt(int reg_ptr)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
509 {
510 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
511 struct device *dev = (struct device *)(irq2dev_map[irq]);
512 struct net_local *lp;
513 int ioaddr, status, boguscount = 0;
514 short ack_cmd;
515
516 if (dev == NULL) {
517 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
518 return;
519 }
520 dev->interrupt = 1;
521
522 ioaddr = dev->base_addr;
523 lp = (struct net_local *)dev->priv;
524
525 status = inw(ioaddr + SCB_STATUS);
526
527 if (net_debug > 4) {
528 printk("%s: EExp interrupt, status %4.4x.\n", dev->name, status);
529 }
530
531 /* Disable the 82586's input to the interrupt line. */
532 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
533
534 /* Reap the Tx packet buffers. */
535 while (lp->tx_reap != lp->tx_head) { /* if (status & 0x8000) */
536 unsigned short tx_status;
537 outw(lp->tx_reap, ioaddr + READ_PTR);
538 tx_status = inw(ioaddr);
539 if (tx_status == 0) {
540 if (net_debug > 5) printk("Couldn't reap %#x.\n", lp->tx_reap);
541 break;
542 }
543 if (tx_status & 0x2000) {
544 lp->stats.tx_packets++;
545 lp->stats.collisions += tx_status & 0xf;
546 dev->tbusy = 0;
547 mark_bh(NET_BH); /* Inform upper layers. */
548 } else {
549 lp->stats.tx_errors++;
550 if (tx_status & 0x0600) lp->stats.tx_carrier_errors++;
551 if (tx_status & 0x0100) lp->stats.tx_fifo_errors++;
552 if (!(tx_status & 0x0040)) lp->stats.tx_heartbeat_errors++;
553 if (tx_status & 0x0020) lp->stats.tx_aborted_errors++;
554 }
555 if (net_debug > 5)
556 printk("Reaped %x, Tx status %04x.\n" , lp->tx_reap, tx_status);
557 lp->tx_reap += TX_BUF_SIZE;
558 if (lp->tx_reap > TX_BUF_END - TX_BUF_SIZE)
559 lp->tx_reap = TX_BUF_START;
560 if (++boguscount > 4)
561 break;
562 }
563
564 if (status & 0x4000) { /* Packet received. */
565 if (net_debug > 5)
566 printk("Received packet, rx_head %04x.\n", lp->rx_head);
567 eexp_rx(dev);
568 }
569
570 /* Acknowledge the interrupt sources. */
571 ack_cmd = status & 0xf000;
572
573 if ((status & 0x0700) != 0x0200 && dev->start) {
574 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
575 if (net_debug > 1)
576 printk("%s: Command unit stopped, status %04x, restarting.\n",
577 dev->name, status);
578 /* If this ever occurs we must re-write the idle loop, reset
579 the Tx list, and do a complete restart of the command unit. */
580 outw(IDLELOOP, ioaddr + WRITE_PTR);
581 outw(0, ioaddr);
582 outw(CmdNOp, ioaddr);
583 outw(IDLELOOP, ioaddr);
584 outw(IDLELOOP, SCB_CBL);
585 lp->tx_cmd_link = IDLELOOP + 4;
586 lp->tx_head = lp->tx_reap = TX_BUF_START;
587 /* Restore the saved write pointer. */
588 outw(saved_write_ptr, ioaddr + WRITE_PTR);
589 ack_cmd |= CUC_START;
590 }
591
592 if ((status & 0x0070) != 0x0040 && dev->start) {
593 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
594 /* The Rx unit is not ready, it must be hung. Restart the receiver by
595 initializing the rx buffers, and issuing an Rx start command. */
596 lp->stats.rx_errors++;
597 if (net_debug > 1) {
598 int cur_rxbuf = RX_BUF_START;
599 printk("%s: Rx unit stopped status %04x rx head %04x tail %04x.\n",
600 dev->name, status, lp->rx_head, lp->rx_tail);
601 while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE) {
602 int i;
603 printk(" Rx buf at %04x:", cur_rxbuf);
604 outw(cur_rxbuf, ioaddr + READ_PTR);
605 for (i = 0; i < 0x20; i += 2)
606 printk(" %04x", inw(ioaddr));
607 printk(".\n");
608 cur_rxbuf += RX_BUF_SIZE;
609 }
610 }
611 init_rx_bufs(dev);
612 outw(RX_BUF_START, SCB_RFA);
613 outw(saved_write_ptr, ioaddr + WRITE_PTR);
614 ack_cmd |= RX_START;
615 }
616
617 outw(ack_cmd, ioaddr + SCB_CMD);
618 outb(0, ioaddr + SIGNAL_CA);
619
620 if (net_debug > 5) {
621 printk("%s: EExp exiting interrupt, status %4.4x.\n", dev->name,
622 inw(ioaddr + SCB_CMD));
623 }
624 /* Enable the 82586's input to the interrupt line. */
625 outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);
626 return;
627 }
628
629 static int
630 eexp_close(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
631 {
632 int ioaddr = dev->base_addr;
633
634 dev->tbusy = 1;
635 dev->start = 0;
636
637 /* Flush the Tx and disable Rx. */
638 outw(RX_SUSPEND | CUC_SUSPEND, ioaddr + SCB_CMD);
639 outb(0, ioaddr + SIGNAL_CA);
640
641 /* Disable the physical interrupt line. */
642 outb(0, ioaddr + SET_IRQ);
643
644 free_irq(dev->irq);
645
646 irq2dev_map[dev->irq] = 0;
647
648 /* Update the statistics here. */
649
650 return 0;
651 }
652
653 /* Get the current statistics. This may be called with the card open or
654 closed. */
655 static struct enet_statistics *
656 eexp_get_stats(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
657 {
658 struct net_local *lp = (struct net_local *)dev->priv;
659
660 /* ToDo: decide if there are any useful statistics from the SCB. */
661
662 return &lp->stats;
663 }
664
665 /* Set or clear the multicast filter for this adaptor.
666 num_addrs == -1 Promiscuous mode, receive all packets
667 num_addrs == 0 Normal mode, clear multicast list
668 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
669 best-effort filtering.
670 */
671 static void
672 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
673 {
674 short ioaddr = dev->base_addr;
675 if (num_addrs < 0) {
676 /* Not written yet, this requires expanding the init_words config
677 cmd. */
678 } else if (num_addrs > 0) {
679 /* Fill in the SET_MC_CMD with the number of address bytes, followed
680 by the list of multicast addresses to be accepted. */
681 outw(SET_MC_CMD + 6, ioaddr + WRITE_PTR);
682 outw(num_addrs * 6, ioaddr);
683 outsw(ioaddr, addrs, num_addrs*3); /* 3 = addr len in words */
684 /* We must trigger a whole 586 reset due to a bug. */
685 } else {
686 /* Not written yet, this requires expanding the init_words config
687 cmd. */
688 outw(99, ioaddr); /* Disable promiscuous mode, use normal mode */
689 }
690 }
691
692 /* The horrible routine to read a word from the serial EEPROM. */
693
694 /* The delay between EEPROM clock transitions. */
695 #define eeprom_delay() { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }}
696 #define EE_READ_CMD (6 << 6)
697
698 int
699 read_eeprom(int ioaddr, int location)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
700 {
701 int i;
702 unsigned short retval = 0;
703 short ee_addr = ioaddr + EEPROM_Ctrl;
704 int read_cmd = location | EE_READ_CMD;
705 short ctrl_val = EE_CS | _586_RESET;
706
707 outb(ctrl_val, ee_addr);
708
709 /* Shift the read command bits out. */
710 for (i = 8; i >= 0; i--) {
711 short outval = (read_cmd & (1 << i)) ? ctrl_val | EE_DATA_WRITE
712 : ctrl_val;
713 outb(outval, ee_addr);
714 outb(outval | EE_SHIFT_CLK, ee_addr); /* EEPROM clock tick. */
715 eeprom_delay();
716 outb(outval, ee_addr); /* Finish EEPROM a clock tick. */
717 eeprom_delay();
718 }
719 outb(ctrl_val, ee_addr);
720
721 for (i = 16; i > 0; i--) {
722 outb(ctrl_val | EE_SHIFT_CLK, ee_addr); eeprom_delay();
723 retval = (retval << 1) | ((inb(ee_addr) & EE_DATA_READ) ? 1 : 0);
724 outb(ctrl_val, ee_addr); eeprom_delay();
725 }
726
727 /* Terminate the EEPROM access. */
728 ctrl_val &= ~EE_CS;
729 outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
730 eeprom_delay();
731 outb(ctrl_val, ee_addr);
732 eeprom_delay();
733 return retval;
734 }
735
736 static void
737 init_82586_mem(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
738 {
739 struct net_local *lp = (struct net_local *)dev->priv;
740 short ioaddr = dev->base_addr;
741
742 /* Enable loopback to protect the wire while starting up.
743 This is Superstition From Crynwr. */
744 outb(inb(ioaddr + Config) | 0x02, ioaddr + Config);
745
746 /* Hold the 586 in reset during the memory initialization. */
747 outb(_586_RESET, ioaddr + EEPROM_Ctrl);
748
749 /* Place the write pointer at 0xfff6 (address-aliased to 0xfffff6). */
750 outw(0xfff6, ioaddr + WRITE_PTR);
751 outsw(ioaddr, init_words, sizeof(init_words)>>1);
752
753 /* Fill in the station address. */
754 outw(SA_OFFSET, ioaddr + WRITE_PTR);
755 outsw(ioaddr, dev->dev_addr, 3);
756
757 /* The Tx-block list is written as needed. We just set up the values. */
758 #ifdef initial_text_tx
759 lp->tx_cmd_link = DUMP_DATA + 4;
760 #else
761 lp->tx_cmd_link = IDLELOOP + 4;
762 #endif
763 lp->tx_head = lp->tx_reap = TX_BUF_START;
764
765 init_rx_bufs(dev);
766
767 /* Start the 586 by releasing the reset line. */
768 outb(0x00, ioaddr + EEPROM_Ctrl);
769
770 /* This was time consuming to track down: you need to give two channel
771 attention signals to reliably start up the i82586. */
772 outb(0, ioaddr + SIGNAL_CA);
773
774 {
775 int boguscnt = 50;
776 while (inw(ioaddr + SCB_STATUS) == 0)
777 if (--boguscnt == 0) {
778 printk("%s: i82586 initialization timed out with status %04x, cmd %04x.\n",
779 dev->name, inw(ioaddr + SCB_STATUS), inw(ioaddr + SCB_CMD));
780 break;
781 }
782 /* Issue channel-attn -- the 82586 won't start without it. */
783 outb(0, ioaddr + SIGNAL_CA);
784 }
785
786 /* Disable loopback. */
787 outb(inb(ioaddr + Config) & ~0x02, ioaddr + Config);
788 if (net_debug > 4)
789 printk("%s: Initialized 82586, status %04x.\n", dev->name,
790 inw(ioaddr + SCB_STATUS));
791 return;
792 }
793
794 /* Initialize the Rx-block list. */
795 static void init_rx_bufs(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
796 {
797 struct net_local *lp = (struct net_local *)dev->priv;
798 short ioaddr = dev->base_addr;
799
800 int cur_rxbuf = lp->rx_head = RX_BUF_START;
801
802 /* Initialize each Rx frame + data buffer. */
803 do { /* While there is room for one more. */
804 outw(cur_rxbuf, ioaddr + WRITE_PTR);
805 outw(0x0000, ioaddr); /* Status */
806 outw(0x0000, ioaddr); /* Command */
807 outw(cur_rxbuf + RX_BUF_SIZE, ioaddr); /* Link */
808 outw(cur_rxbuf + 22, ioaddr); /* Buffer offset */
809 outw(0xFeed, ioaddr); /* Pad for dest addr. */
810 outw(0xF00d, ioaddr);
811 outw(0xF001, ioaddr);
812 outw(0x0505, ioaddr); /* Pad for source addr. */
813 outw(0x2424, ioaddr);
814 outw(0x6565, ioaddr);
815 outw(0xdeaf, ioaddr); /* Pad for protocol. */
816
817 outw(0x0000, ioaddr); /* Buffer: Actual count */
818 outw(-1, ioaddr); /* Buffer: Next (none). */
819 outw(cur_rxbuf + 0x20, ioaddr); /* Buffer: Address low */
820 outw(0x0000, ioaddr);
821 /* Finally, the number of bytes in the buffer. */
822 outw(0x8000 + RX_BUF_SIZE-0x20, ioaddr);
823
824 lp->rx_tail = cur_rxbuf;
825 cur_rxbuf += RX_BUF_SIZE;
826 } while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE);
827
828 /* Terminate the list by setting the EOL bit, and wrap the pointer to make
829 the list a ring. */
830 outw(lp->rx_tail + 2, ioaddr + WRITE_PTR);
831 outw(0xC000, ioaddr); /* Command, mark as last. */
832 outw(lp->rx_head, ioaddr); /* Link */
833 }
834
835 static void
836 hardware_send_packet(struct device *dev, void *buf, short length)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
837 {
838 struct net_local *lp = (struct net_local *)dev->priv;
839 short ioaddr = dev->base_addr;
840 short tx_block = lp->tx_head;
841
842 /* Set the write pointer to the Tx block, and put out the header. */
843 outw(tx_block, ioaddr + WRITE_PTR);
844 outw(0x0000, ioaddr); /* Tx status */
845 outw(CMD_INTR|CmdTx, ioaddr); /* Tx command */
846 outw(tx_block+16, ioaddr); /* Next command is a NoOp. */
847 outw(tx_block+8, ioaddr); /* Data Buffer offset. */
848
849 /* Output the data buffer descriptor. */
850 outw(length | 0x8000, ioaddr); /* Byte count parameter. */
851 outw(-1, ioaddr); /* No next data buffer. */
852 outw(tx_block+22, ioaddr); /* Buffer follows the NoOp command. */
853 outw(0x0000, ioaddr); /* Buffer address high bits (always zero). */
854
855 /* Output the Loop-back NoOp command. */
856 outw(0x0000, ioaddr); /* Tx status */
857 outw(CmdNOp, ioaddr); /* Tx command */
858 outw(tx_block+16, ioaddr); /* Next is myself. */
859
860 /* Output the packet using the write pointer.
861 Hmmm, it feels a little like a 3c501! */
862 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
863
864 /* Set the old command link pointing to this send packet. */
865 outw(lp->tx_cmd_link, ioaddr + WRITE_PTR);
866 outw(tx_block, ioaddr);
867 lp->tx_cmd_link = tx_block + 20;
868
869 /* Set the next free tx region. */
870 lp->tx_head = tx_block + TX_BUF_SIZE;
871 if (lp->tx_head > TX_BUF_END - TX_BUF_SIZE)
872 lp->tx_head = TX_BUF_START;
873
874 if (net_debug > 4) {
875 printk("%s: EExp @%x send length = %d, tx_block %3x, next %3x, "
876 "reap %4x status %4.4x.\n", dev->name, ioaddr, length,
877 tx_block, lp->tx_head, lp->tx_reap, inw(ioaddr + SCB_STATUS));
878 }
879
880 if (lp->tx_head != lp->tx_reap)
881 dev->tbusy = 0;
882 }
883
884 static void
885 eexp_rx(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
886 {
887 struct net_local *lp = (struct net_local *)dev->priv;
888 short ioaddr = dev->base_addr;
889 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
890 short rx_head = lp->rx_head;
891 short rx_tail = lp->rx_tail;
892 short boguscount = 10;
893 short frame_status;
894
895 /* Set the read pointer to the Rx frame. */
896 outw(rx_head, ioaddr + READ_PTR);
897 while ((frame_status = inw(ioaddr)) < 0) { /* Command complete */
898 short rfd_cmd = inw(ioaddr);
899 short next_rx_frame = inw(ioaddr);
900 short data_buffer_addr = inw(ioaddr);
901 short pkt_len;
902
903 /* Set the read pointer the data buffer. */
904 outw(data_buffer_addr, ioaddr + READ_PTR);
905 pkt_len = inw(ioaddr);
906
907 if (rfd_cmd != 0 || data_buffer_addr != rx_head + 22
908 || pkt_len & 0xC000 != 0xC000) {
909 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x"
910 "next %04x data-buf @%04x %04x.\n", dev->name, rx_head,
911 frame_status, rfd_cmd, next_rx_frame, data_buffer_addr,
912 pkt_len);
913 } else if ((frame_status & 0x2000) == 0) {
914 /* Frame Rxed, but with error. */
915 lp->stats.rx_errors++;
916 if (frame_status & 0x0800) lp->stats.rx_crc_errors++;
917 if (frame_status & 0x0400) lp->stats.rx_frame_errors++;
918 if (frame_status & 0x0200) lp->stats.rx_fifo_errors++;
919 if (frame_status & 0x0100) lp->stats.rx_over_errors++;
920 if (frame_status & 0x0080) lp->stats.rx_length_errors++;
921 } else {
922 /* Malloc up new buffer. */
923 struct sk_buff *skb;
924
925 pkt_len &= 0x3fff;
926 skb = alloc_skb(pkt_len, GFP_ATOMIC);
927 if (skb == NULL) {
928 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
929 lp->stats.rx_dropped++;
930 break;
931 }
932 skb->len = pkt_len;
933 skb->dev = dev;
934
935 outw(data_buffer_addr + 10, ioaddr + READ_PTR);
936
937 insw(ioaddr, skb->data, (pkt_len + 1) >> 1);
938
939 netif_rx(skb);
940 lp->stats.rx_packets++;
941 }
942
943 /* Clear the status word and set End-of-List on the rx frame. */
944 outw(rx_head, ioaddr + WRITE_PTR);
945 outw(0x0000, ioaddr);
946 outw(0xC000, ioaddr);
947 #ifndef final_version
948 if (next_rx_frame != rx_head + RX_BUF_SIZE
949 && next_rx_frame != RX_BUF_START) {
950 printk("%s: Rx next frame at %#x is %#x instead of %#x.\n", dev->name,
951 rx_head, next_rx_frame, rx_head + RX_BUF_SIZE);
952 next_rx_frame = rx_head + RX_BUF_SIZE;
953 if (next_rx_frame >= RX_BUF_END - RX_BUF_SIZE)
954 next_rx_frame = RX_BUF_START;
955 }
956 #endif
957 outw(rx_tail+2, ioaddr + WRITE_PTR);
958 outw(0x0000, ioaddr); /* Clear the end-of-list on the prev. RFD. */
959
960 #ifndef final_version
961 outw(rx_tail+4, ioaddr + READ_PTR);
962 if (inw(ioaddr) != rx_head) {
963 printk("%s: Rx buf link mismatch, at %04x link %04x instead of %04x.\n",
964 dev->name, rx_tail, (outw(rx_tail+4, ioaddr + READ_PTR),inw(ioaddr)),
965 rx_head);
966 outw(rx_head, ioaddr);
967 }
968 #endif
969
970 rx_tail = rx_head;
971 rx_head = next_rx_frame;
972 if (--boguscount == 0)
973 break;
974 outw(rx_head, ioaddr + READ_PTR);
975 }
976
977 lp->rx_head = rx_head;
978 lp->rx_tail = rx_tail;
979
980 /* Restore the original write pointer. */
981 outw(saved_write_ptr, ioaddr + WRITE_PTR);
982 }
983
984 /*
985 * Local variables:
986 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -I/usr/src/linux/drivers/net -Wall -Wstrict-prototypes -O6 -m486 -c eexpress.c"
987 * version-control: t
988 * kept-new-versions: 5
989 * tab-width: 4
990 * End:
991 */