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 if (skb->free)
498 kfree_skb (skb, FREE_WRITE);
499
500 /* You might need to clean up and record Tx statistics here. */
501 lp->stats.tx_aborted_errors++;
502
503 return 0;
504 }
505
506 /* The typical workload of the driver:
507 Handle the network interface interrupts. */
508 static void
509 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)
*/
510 {
511 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
512 struct device *dev = (struct device *)(irq2dev_map[irq]);
513 struct net_local *lp;
514 int ioaddr, status, boguscount = 0;
515 short ack_cmd;
516
517 if (dev == NULL) {
518 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
519 return;
520 }
521 dev->interrupt = 1;
522
523 ioaddr = dev->base_addr;
524 lp = (struct net_local *)dev->priv;
525
526 status = inw(ioaddr + SCB_STATUS);
527
528 if (net_debug > 4) {
529 printk("%s: EExp interrupt, status %4.4x.\n", dev->name, status);
530 }
531
532 /* Disable the 82586's input to the interrupt line. */
533 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
534
535 /* Reap the Tx packet buffers. */
536 while (lp->tx_reap != lp->tx_head) { /* if (status & 0x8000) */
537 unsigned short tx_status;
538 outw(lp->tx_reap, ioaddr + READ_PTR);
539 tx_status = inw(ioaddr);
540 if (tx_status == 0) {
541 if (net_debug > 5) printk("Couldn't reap %#x.\n", lp->tx_reap);
542 break;
543 }
544 if (tx_status & 0x2000) {
545 lp->stats.tx_packets++;
546 lp->stats.collisions += tx_status & 0xf;
547 dev->tbusy = 0;
548 mark_bh(INET_BH); /* Inform upper layers. */
549 } else {
550 lp->stats.tx_errors++;
551 if (tx_status & 0x0600) lp->stats.tx_carrier_errors++;
552 if (tx_status & 0x0100) lp->stats.tx_fifo_errors++;
553 if (!(tx_status & 0x0040)) lp->stats.tx_heartbeat_errors++;
554 if (tx_status & 0x0020) lp->stats.tx_aborted_errors++;
555 }
556 if (net_debug > 5)
557 printk("Reaped %x, Tx status %04x.\n" , lp->tx_reap, tx_status);
558 lp->tx_reap += TX_BUF_SIZE;
559 if (lp->tx_reap > TX_BUF_END - TX_BUF_SIZE)
560 lp->tx_reap = TX_BUF_START;
561 if (++boguscount > 4)
562 break;
563 }
564
565 if (status & 0x4000) { /* Packet received. */
566 if (net_debug > 5)
567 printk("Received packet, rx_head %04x.\n", lp->rx_head);
568 eexp_rx(dev);
569 }
570
571 /* Acknowledge the interrupt sources. */
572 ack_cmd = status & 0xf000;
573
574 if ((status & 0x0700) != 0x0200 && dev->start) {
575 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
576 if (net_debug > 1)
577 printk("%s: Command unit stopped, status %04x, restarting.\n",
578 dev->name, status);
579 /* If this ever occurs we must re-write the idle loop, reset
580 the Tx list, and do a complete restart of the command unit. */
581 outw(IDLELOOP, ioaddr + WRITE_PTR);
582 outw(0, ioaddr);
583 outw(CmdNOp, ioaddr);
584 outw(IDLELOOP, ioaddr);
585 outw(IDLELOOP, SCB_CBL);
586 lp->tx_cmd_link = IDLELOOP + 4;
587 lp->tx_head = lp->tx_reap = TX_BUF_START;
588 /* Restore the saved write pointer. */
589 outw(saved_write_ptr, ioaddr + WRITE_PTR);
590 ack_cmd |= CUC_START;
591 }
592
593 if ((status & 0x0070) != 0x0040 && dev->start) {
594 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
595 /* The Rx unit is not ready, it must be hung. Restart the receiver by
596 initializing the rx buffers, and issuing an Rx start command. */
597 lp->stats.rx_errors++;
598 if (net_debug > 1) {
599 int cur_rxbuf = RX_BUF_START;
600 printk("%s: Rx unit stopped status %04x rx head %04x tail %04x.\n",
601 dev->name, status, lp->rx_head, lp->rx_tail);
602 while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE) {
603 int i;
604 printk(" Rx buf at %04x:", cur_rxbuf);
605 outw(cur_rxbuf, ioaddr + READ_PTR);
606 for (i = 0; i < 0x20; i += 2)
607 printk(" %04x", inw(ioaddr));
608 printk(".\n");
609 cur_rxbuf += RX_BUF_SIZE;
610 }
611 }
612 init_rx_bufs(dev);
613 outw(RX_BUF_START, SCB_RFA);
614 outw(saved_write_ptr, ioaddr + WRITE_PTR);
615 ack_cmd |= RX_START;
616 }
617
618 outw(ack_cmd, ioaddr + SCB_CMD);
619 outb(0, ioaddr + SIGNAL_CA);
620
621 if (net_debug > 5) {
622 printk("%s: EExp exiting interrupt, status %4.4x.\n", dev->name,
623 inw(ioaddr + SCB_CMD));
624 }
625 /* Enable the 82586's input to the interrupt line. */
626 outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);
627 return;
628 }
629
630 static int
631 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)
*/
632 {
633 int ioaddr = dev->base_addr;
634
635 dev->tbusy = 1;
636 dev->start = 0;
637
638 /* Flush the Tx and disable Rx. */
639 outw(RX_SUSPEND | CUC_SUSPEND, ioaddr + SCB_CMD);
640 outb(0, ioaddr + SIGNAL_CA);
641
642 /* Disable the physical interrupt line. */
643 outb(0, ioaddr + SET_IRQ);
644
645 free_irq(dev->irq);
646
647 irq2dev_map[dev->irq] = 0;
648
649 /* Update the statistics here. */
650
651 return 0;
652 }
653
654 /* Get the current statistics. This may be called with the card open or
655 closed. */
656 static struct enet_statistics *
657 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)
*/
658 {
659 struct net_local *lp = (struct net_local *)dev->priv;
660
661 /* ToDo: decide if there are any useful statistics from the SCB. */
662
663 return &lp->stats;
664 }
665
666 /* Set or clear the multicast filter for this adaptor.
667 num_addrs == -1 Promiscuous mode, receive all packets
668 num_addrs == 0 Normal mode, clear multicast list
669 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
670 best-effort filtering.
671 */
672 static void
673 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)
*/
674 {
675 short ioaddr = dev->base_addr;
676 if (num_addrs < 0) {
677 /* Not written yet, this requires expanding the init_words config
678 cmd. */
679 } else if (num_addrs > 0) {
680 /* Fill in the SET_MC_CMD with the number of address bytes, followed
681 by the list of multicast addresses to be accepted. */
682 outw(SET_MC_CMD + 6, ioaddr + WRITE_PTR);
683 outw(num_addrs * 6, ioaddr);
684 outsw(ioaddr, addrs, num_addrs*3); /* 3 = addr len in words */
685 /* We must trigger a whole 586 reset due to a bug. */
686 } else {
687 /* Not written yet, this requires expanding the init_words config
688 cmd. */
689 outw(99, ioaddr); /* Disable promiscuous mode, use normal mode */
690 }
691 }
692
693 /* The horrible routine to read a word from the serial EEPROM. */
694
695 /* The delay between EEPROM clock transitions. */
696 #define eeprom_delay() { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }}
697 #define EE_READ_CMD (6 << 6)
698
699 int
700 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)
*/
701 {
702 int i;
703 unsigned short retval = 0;
704 short ee_addr = ioaddr + EEPROM_Ctrl;
705 int read_cmd = location | EE_READ_CMD;
706 short ctrl_val = EE_CS | _586_RESET;
707
708 outb(ctrl_val, ee_addr);
709
710 /* Shift the read command bits out. */
711 for (i = 8; i >= 0; i--) {
712 short outval = (read_cmd & (1 << i)) ? ctrl_val | EE_DATA_WRITE
713 : ctrl_val;
714 outb(outval, ee_addr);
715 outb(outval | EE_SHIFT_CLK, ee_addr); /* EEPROM clock tick. */
716 eeprom_delay();
717 outb(outval, ee_addr); /* Finish EEPROM a clock tick. */
718 eeprom_delay();
719 }
720 outb(ctrl_val, ee_addr);
721
722 for (i = 16; i > 0; i--) {
723 outb(ctrl_val | EE_SHIFT_CLK, ee_addr); eeprom_delay();
724 retval = (retval << 1) | ((inb(ee_addr) & EE_DATA_READ) ? 1 : 0);
725 outb(ctrl_val, ee_addr); eeprom_delay();
726 }
727
728 /* Terminate the EEPROM access. */
729 ctrl_val &= ~EE_CS;
730 outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
731 eeprom_delay();
732 outb(ctrl_val, ee_addr);
733 eeprom_delay();
734 return retval;
735 }
736
737 static void
738 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)
*/
739 {
740 struct net_local *lp = (struct net_local *)dev->priv;
741 short ioaddr = dev->base_addr;
742
743 /* Enable loopback to protect the wire while starting up.
744 This is Superstition From Crynwr. */
745 outb(inb(ioaddr + Config) | 0x02, ioaddr + Config);
746
747 /* Hold the 586 in reset during the memory initialization. */
748 outb(_586_RESET, ioaddr + EEPROM_Ctrl);
749
750 /* Place the write pointer at 0xfff6 (address-aliased to 0xfffff6). */
751 outw(0xfff6, ioaddr + WRITE_PTR);
752 outsw(ioaddr, init_words, sizeof(init_words)>>1);
753
754 /* Fill in the station address. */
755 outw(SA_OFFSET, ioaddr + WRITE_PTR);
756 outsw(ioaddr, dev->dev_addr, 3);
757
758 /* The Tx-block list is written as needed. We just set up the values. */
759 #ifdef initial_text_tx
760 lp->tx_cmd_link = DUMP_DATA + 4;
761 #else
762 lp->tx_cmd_link = IDLELOOP + 4;
763 #endif
764 lp->tx_head = lp->tx_reap = TX_BUF_START;
765
766 init_rx_bufs(dev);
767
768 /* Start the 586 by releasing the reset line. */
769 outb(0x00, ioaddr + EEPROM_Ctrl);
770
771 /* This was time consuming to track down: you need to give two channel
772 attention signals to reliably start up the i82586. */
773 outb(0, ioaddr + SIGNAL_CA);
774
775 {
776 int boguscnt = 50;
777 while (inw(ioaddr + SCB_STATUS) == 0)
778 if (--boguscnt == 0) {
779 printk("%s: i82586 initialization timed out with status %04x, cmd %04x.\n",
780 dev->name, inw(ioaddr + SCB_STATUS), inw(ioaddr + SCB_CMD));
781 break;
782 }
783 /* Issue channel-attn -- the 82586 won't start without it. */
784 outb(0, ioaddr + SIGNAL_CA);
785 }
786
787 /* Disable loopback. */
788 outb(inb(ioaddr + Config) & ~0x02, ioaddr + Config);
789 if (net_debug > 4)
790 printk("%s: Initialized 82586, status %04x.\n", dev->name,
791 inw(ioaddr + SCB_STATUS));
792 return;
793 }
794
795 /* Initialize the Rx-block list. */
796 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)
*/
797 {
798 struct net_local *lp = (struct net_local *)dev->priv;
799 short ioaddr = dev->base_addr;
800
801 int cur_rxbuf = lp->rx_head = RX_BUF_START;
802
803 /* Initialize each Rx frame + data buffer. */
804 do { /* While there is room for one more. */
805 outw(cur_rxbuf, ioaddr + WRITE_PTR);
806 outw(0x0000, ioaddr); /* Status */
807 outw(0x0000, ioaddr); /* Command */
808 outw(cur_rxbuf + RX_BUF_SIZE, ioaddr); /* Link */
809 outw(cur_rxbuf + 22, ioaddr); /* Buffer offset */
810 outw(0xFeed, ioaddr); /* Pad for dest addr. */
811 outw(0xF00d, ioaddr);
812 outw(0xF001, ioaddr);
813 outw(0x0505, ioaddr); /* Pad for source addr. */
814 outw(0x2424, ioaddr);
815 outw(0x6565, ioaddr);
816 outw(0xdeaf, ioaddr); /* Pad for protocol. */
817
818 outw(0x0000, ioaddr); /* Buffer: Actual count */
819 outw(-1, ioaddr); /* Buffer: Next (none). */
820 outw(cur_rxbuf + 0x20, ioaddr); /* Buffer: Address low */
821 outw(0x0000, ioaddr);
822 /* Finally, the number of bytes in the buffer. */
823 outw(0x8000 + RX_BUF_SIZE-0x20, ioaddr);
824
825 lp->rx_tail = cur_rxbuf;
826 cur_rxbuf += RX_BUF_SIZE;
827 } while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE);
828
829 /* Terminate the list by setting the EOL bit, and wrap the pointer to make
830 the list a ring. */
831 outw(lp->rx_tail + 2, ioaddr + WRITE_PTR);
832 outw(0xC000, ioaddr); /* Command, mark as last. */
833 outw(lp->rx_head, ioaddr); /* Link */
834 }
835
836 static void
837 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)
*/
838 {
839 struct net_local *lp = (struct net_local *)dev->priv;
840 short ioaddr = dev->base_addr;
841 short tx_block = lp->tx_head;
842
843 /* Set the write pointer to the Tx block, and put out the header. */
844 outw(tx_block, ioaddr + WRITE_PTR);
845 outw(0x0000, ioaddr); /* Tx status */
846 outw(CMD_INTR|CmdTx, ioaddr); /* Tx command */
847 outw(tx_block+16, ioaddr); /* Next command is a NoOp. */
848 outw(tx_block+8, ioaddr); /* Data Buffer offset. */
849
850 /* Output the data buffer descriptor. */
851 outw(length | 0x8000, ioaddr); /* Byte count parameter. */
852 outw(-1, ioaddr); /* No next data buffer. */
853 outw(tx_block+22, ioaddr); /* Buffer follows the NoOp command. */
854 outw(0x0000, ioaddr); /* Buffer address high bits (always zero). */
855
856 /* Output the Loop-back NoOp command. */
857 outw(0x0000, ioaddr); /* Tx status */
858 outw(CmdNOp, ioaddr); /* Tx command */
859 outw(tx_block+16, ioaddr); /* Next is myself. */
860
861 /* Output the packet using the write pointer.
862 Hmmm, it feels a little like a 3c501! */
863 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
864
865 /* Set the old command link pointing to this send packet. */
866 outw(lp->tx_cmd_link, ioaddr + WRITE_PTR);
867 outw(tx_block, ioaddr);
868 lp->tx_cmd_link = tx_block + 20;
869
870 /* Set the next free tx region. */
871 lp->tx_head = tx_block + TX_BUF_SIZE;
872 if (lp->tx_head > TX_BUF_END - TX_BUF_SIZE)
873 lp->tx_head = TX_BUF_START;
874
875 if (net_debug > 4) {
876 printk("%s: EExp @%x send length = %d, tx_block %3x, next %3x, "
877 "reap %4x status %4.4x.\n", dev->name, ioaddr, length,
878 tx_block, lp->tx_head, lp->tx_reap, inw(ioaddr + SCB_STATUS));
879 }
880
881 if (lp->tx_head != lp->tx_reap)
882 dev->tbusy = 0;
883 }
884
885 static void
886 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)
*/
887 {
888 struct net_local *lp = (struct net_local *)dev->priv;
889 short ioaddr = dev->base_addr;
890 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
891 short rx_head = lp->rx_head;
892 short rx_tail = lp->rx_tail;
893 short boguscount = 10;
894 short frame_status;
895
896 /* Set the read pointer to the Rx frame. */
897 outw(rx_head, ioaddr + READ_PTR);
898 while ((frame_status = inw(ioaddr)) < 0) { /* Command complete */
899 short rfd_cmd = inw(ioaddr);
900 short next_rx_frame = inw(ioaddr);
901 short data_buffer_addr = inw(ioaddr);
902 short pkt_len;
903
904 /* Set the read pointer the data buffer. */
905 outw(data_buffer_addr, ioaddr + READ_PTR);
906 pkt_len = inw(ioaddr);
907
908 if (rfd_cmd != 0 || data_buffer_addr != rx_head + 22
909 || pkt_len & 0xC000 != 0xC000) {
910 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x"
911 "next %04x data-buf @%04x %04x.\n", dev->name, rx_head,
912 frame_status, rfd_cmd, next_rx_frame, data_buffer_addr,
913 pkt_len);
914 } else if ((frame_status & 0x2000) == 0) {
915 /* Frame Rxed, but with error. */
916 lp->stats.rx_errors++;
917 if (frame_status & 0x0800) lp->stats.rx_crc_errors++;
918 if (frame_status & 0x0400) lp->stats.rx_frame_errors++;
919 if (frame_status & 0x0200) lp->stats.rx_fifo_errors++;
920 if (frame_status & 0x0100) lp->stats.rx_over_errors++;
921 if (frame_status & 0x0080) lp->stats.rx_length_errors++;
922 } else {
923 /* Malloc up new buffer. */
924 struct sk_buff *skb;
925
926 pkt_len &= 0x3fff;
927 skb = alloc_skb(pkt_len, GFP_ATOMIC);
928 if (skb == NULL) {
929 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
930 lp->stats.rx_dropped++;
931 break;
932 }
933 skb->len = pkt_len;
934 skb->dev = dev;
935
936 outw(data_buffer_addr + 10, ioaddr + READ_PTR);
937
938 insw(ioaddr, skb->data, (pkt_len + 1) >> 1);
939
940 netif_rx(skb);
941 lp->stats.rx_packets++;
942 }
943
944 /* Clear the status word and set End-of-List on the rx frame. */
945 outw(rx_head, ioaddr + WRITE_PTR);
946 outw(0x0000, ioaddr);
947 outw(0xC000, ioaddr);
948 #ifndef final_version
949 if (next_rx_frame != rx_head + RX_BUF_SIZE
950 && next_rx_frame != RX_BUF_START) {
951 printk("%s: Rx next frame at %#x is %#x instead of %#x.\n", dev->name,
952 rx_head, next_rx_frame, rx_head + RX_BUF_SIZE);
953 next_rx_frame = rx_head + RX_BUF_SIZE;
954 if (next_rx_frame >= RX_BUF_END - RX_BUF_SIZE)
955 next_rx_frame = RX_BUF_START;
956 }
957 #endif
958 outw(rx_tail+2, ioaddr + WRITE_PTR);
959 outw(0x0000, ioaddr); /* Clear the end-of-list on the prev. RFD. */
960
961 #ifndef final_version
962 outw(rx_tail+4, ioaddr + READ_PTR);
963 if (inw(ioaddr) != rx_head) {
964 printk("%s: Rx buf link mismatch, at %04x link %04x instead of %04x.\n",
965 dev->name, rx_tail, (outw(rx_tail+4, ioaddr + READ_PTR),inw(ioaddr)),
966 rx_head);
967 outw(rx_head, ioaddr);
968 }
969 #endif
970
971 rx_tail = rx_head;
972 rx_head = next_rx_frame;
973 if (--boguscount == 0)
974 break;
975 outw(rx_head, ioaddr + READ_PTR);
976 }
977
978 lp->rx_head = rx_head;
979 lp->rx_tail = rx_tail;
980
981 /* Restore the original write pointer. */
982 outw(saved_write_ptr, ioaddr + WRITE_PTR);
983 }
984
985 /*
986 * Local variables:
987 * 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"
988 * version-control: t
989 * kept-new-versions: 5
990 * tab-width: 4
991 * End:
992 */