Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* ne2.c: A NE/2 Ethernet Driver for Linux. */ |
2 | /* | |
3 | Based on the NE2000 driver written by Donald Becker (1992-94). | |
4 | modified by Wim Dumon (Apr 1996) | |
5 | ||
6 | This software may be used and distributed according to the terms | |
7 | of the GNU General Public License, incorporated herein by reference. | |
8 | ||
9 | The author may be reached as wimpie@linux.cc.kuleuven.ac.be | |
10 | ||
11 | Currently supported: NE/2 | |
12 | This patch was never tested on other MCA-ethernet adapters, but it | |
13 | might work. Just give it a try and let me know if you have problems. | |
14 | Also mail me if it really works, please! | |
15 | ||
16 | Changelog: | |
17 | Mon Feb 3 16:26:02 MET 1997 | |
18 | - adapted the driver to work with the 2.1.25 kernel | |
19 | - multiple ne2 support (untested) | |
20 | - module support (untested) | |
21 | ||
22 | Fri Aug 28 00:18:36 CET 1998 (David Weinehall) | |
23 | - fixed a few minor typos | |
24 | - made the MODULE_PARM conditional (it only works with the v2.1.x kernels) | |
25 | - fixed the module support (Now it's working...) | |
26 | ||
27 | Mon Sep 7 19:01:44 CET 1998 (David Weinehall) | |
28 | - added support for Arco Electronics AE/2-card (experimental) | |
29 | ||
30 | Mon Sep 14 09:53:42 CET 1998 (David Weinehall) | |
31 | - added support for Compex ENET-16MC/P (experimental) | |
32 | ||
33 | Tue Sep 15 16:21:12 CET 1998 (David Weinehall, Magnus Jonsson, Tomas Ogren) | |
34 | - Miscellaneous bugfixes | |
35 | ||
36 | Tue Sep 19 16:21:12 CET 1998 (Magnus Jonsson) | |
37 | - Cleanup | |
38 | ||
39 | Wed Sep 23 14:33:34 CET 1998 (David Weinehall) | |
40 | - Restructuring and rewriting for v2.1.x compliance | |
41 | ||
42 | Wed Oct 14 17:19:21 CET 1998 (David Weinehall) | |
43 | - Added code that unregisters irq and proc-info | |
44 | - Version# bump | |
45 | ||
46 | Mon Nov 16 15:28:23 CET 1998 (Wim Dumon) | |
47 | - pass 'dev' as last parameter of request_irq in stead of 'NULL' | |
48 | ||
49 | Wed Feb 7 21:24:00 CET 2001 (Alfred Arnold) | |
50 | - added support for the D-Link DE-320CT | |
51 | ||
52 | * WARNING | |
53 | ------- | |
54 | This is alpha-test software. It is not guaranteed to work. As a | |
55 | matter of fact, I'm quite sure there are *LOTS* of bugs in here. I | |
56 | would like to hear from you if you use this driver, even if it works. | |
57 | If it doesn't work, be sure to send me a mail with the problems ! | |
58 | */ | |
59 | ||
60 | static const char *version = "ne2.c:v0.91 Nov 16 1998 Wim Dumon <wimpie@kotnet.org>\n"; | |
61 | ||
62 | #include <linux/module.h> | |
63 | #include <linux/kernel.h> | |
64 | #include <linux/types.h> | |
65 | #include <linux/fcntl.h> | |
66 | #include <linux/interrupt.h> | |
67 | #include <linux/ioport.h> | |
68 | #include <linux/in.h> | |
69 | #include <linux/slab.h> | |
70 | #include <linux/string.h> | |
71 | #include <linux/errno.h> | |
72 | #include <linux/init.h> | |
73 | #include <linux/mca-legacy.h> | |
74 | #include <linux/netdevice.h> | |
75 | #include <linux/etherdevice.h> | |
76 | #include <linux/skbuff.h> | |
77 | #include <linux/bitops.h> | |
78 | ||
79 | #include <asm/system.h> | |
80 | #include <asm/io.h> | |
81 | #include <asm/dma.h> | |
82 | ||
83 | #include "8390.h" | |
84 | ||
85 | #define DRV_NAME "ne2" | |
86 | ||
87 | /* Some defines that people can play with if so inclined. */ | |
88 | ||
89 | /* Do we perform extra sanity checks on stuff ? */ | |
90 | /* #define NE_SANITY_CHECK */ | |
91 | ||
92 | /* Do we implement the read before write bugfix ? */ | |
93 | /* #define NE_RW_BUGFIX */ | |
94 | ||
95 | /* Do we have a non std. amount of memory? (in units of 256 byte pages) */ | |
96 | /* #define PACKETBUF_MEMSIZE 0x40 */ | |
97 | ||
98 | ||
99 | /* ---- No user-serviceable parts below ---- */ | |
100 | ||
101 | #define NE_BASE (dev->base_addr) | |
102 | #define NE_CMD 0x00 | |
103 | #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */ | |
104 | #define NE_RESET 0x20 /* Issue a read to reset, a write to clear. */ | |
105 | #define NE_IO_EXTENT 0x30 | |
106 | ||
107 | #define NE1SM_START_PG 0x20 /* First page of TX buffer */ | |
108 | #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */ | |
109 | #define NESM_START_PG 0x40 /* First page of TX buffer */ | |
110 | #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ | |
111 | ||
112 | /* From the .ADF file: */ | |
113 | static unsigned int addresses[7] __initdata = | |
114 | {0x1000, 0x2020, 0x8020, 0xa0a0, 0xb0b0, 0xc0c0, 0xc3d0}; | |
115 | static int irqs[4] __initdata = {3, 4, 5, 9}; | |
116 | ||
117 | /* From the D-Link ADF file: */ | |
118 | static unsigned int dlink_addresses[4] __initdata = | |
119 | {0x300, 0x320, 0x340, 0x360}; | |
120 | static int dlink_irqs[8] __initdata = {3, 4, 5, 9, 10, 11, 14, 15}; | |
121 | ||
122 | struct ne2_adapters_t { | |
123 | unsigned int id; | |
124 | char *name; | |
125 | }; | |
126 | ||
127 | static struct ne2_adapters_t ne2_adapters[] __initdata = { | |
128 | { 0x6354, "Arco Ethernet Adapter AE/2" }, | |
129 | { 0x70DE, "Compex ENET-16 MC/P" }, | |
130 | { 0x7154, "Novell Ethernet Adapter NE/2" }, | |
131 | { 0x56ea, "D-Link DE-320CT" }, | |
132 | { 0x0000, NULL } | |
133 | }; | |
134 | ||
135 | extern int netcard_probe(struct net_device *dev); | |
136 | ||
137 | static int ne2_probe1(struct net_device *dev, int slot); | |
138 | ||
139 | static int ne_open(struct net_device *dev); | |
140 | static int ne_close(struct net_device *dev); | |
141 | ||
142 | static void ne_reset_8390(struct net_device *dev); | |
143 | static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, | |
144 | int ring_page); | |
145 | static void ne_block_input(struct net_device *dev, int count, | |
146 | struct sk_buff *skb, int ring_offset); | |
147 | static void ne_block_output(struct net_device *dev, const int count, | |
148 | const unsigned char *buf, const int start_page); | |
149 | ||
150 | ||
151 | /* | |
152 | * special code to read the DE-320's MAC address EEPROM. In contrast to a | |
153 | * standard NE design, this is a serial EEPROM (93C46) that has to be read | |
154 | * bit by bit. The EEPROM cotrol port at base + 0x1e has the following | |
155 | * layout: | |
156 | * | |
157 | * Bit 0 = Data out (read from EEPROM) | |
158 | * Bit 1 = Data in (write to EEPROM) | |
159 | * Bit 2 = Clock | |
160 | * Bit 3 = Chip Select | |
161 | * Bit 7 = ~50 kHz clock for defined delays | |
162 | * | |
163 | */ | |
164 | ||
165 | static void __init dlink_put_eeprom(unsigned char value, unsigned int addr) | |
166 | { | |
167 | int z; | |
168 | unsigned char v1, v2; | |
169 | ||
170 | /* write the value to the NIC EEPROM register */ | |
171 | ||
172 | outb(value, addr + 0x1e); | |
173 | ||
174 | /* now wait the clock line to toggle twice. Effectively, we are | |
175 | waiting (at least) for one clock cycle */ | |
176 | ||
177 | for (z = 0; z < 2; z++) { | |
178 | do { | |
179 | v1 = inb(addr + 0x1e); | |
180 | v2 = inb(addr + 0x1e); | |
181 | } | |
182 | while (!((v1 ^ v2) & 0x80)); | |
183 | } | |
184 | } | |
185 | ||
186 | static void __init dlink_send_eeprom_bit(unsigned int bit, unsigned int addr) | |
187 | { | |
188 | /* shift data bit into correct position */ | |
189 | ||
190 | bit = bit << 1; | |
191 | ||
192 | /* write value, keep clock line high for two cycles */ | |
193 | ||
194 | dlink_put_eeprom(0x09 | bit, addr); | |
195 | dlink_put_eeprom(0x0d | bit, addr); | |
196 | dlink_put_eeprom(0x0d | bit, addr); | |
197 | dlink_put_eeprom(0x09 | bit, addr); | |
198 | } | |
199 | ||
200 | static void __init dlink_send_eeprom_word(unsigned int value, unsigned int len, unsigned int addr) | |
201 | { | |
202 | int z; | |
203 | ||
204 | /* adjust bits so that they are left-aligned in a 16-bit-word */ | |
205 | ||
206 | value = value << (16 - len); | |
207 | ||
208 | /* shift bits out to the EEPROM */ | |
209 | ||
210 | for (z = 0; z < len; z++) { | |
211 | dlink_send_eeprom_bit((value & 0x8000) >> 15, addr); | |
212 | value = value << 1; | |
213 | } | |
214 | } | |
215 | ||
216 | static unsigned int __init dlink_get_eeprom(unsigned int eeaddr, unsigned int addr) | |
217 | { | |
218 | int z; | |
219 | unsigned int value = 0; | |
220 | ||
221 | /* pull the CS line low for a moment. This resets the EEPROM- | |
222 | internal logic, and makes it ready for a new command. */ | |
223 | ||
224 | dlink_put_eeprom(0x01, addr); | |
225 | dlink_put_eeprom(0x09, addr); | |
226 | ||
227 | /* send one start bit, read command (1 - 0), plus the address to | |
228 | the EEPROM */ | |
229 | ||
230 | dlink_send_eeprom_word(0x0180 | (eeaddr & 0x3f), 9, addr); | |
231 | ||
232 | /* get the data word. We clock by sending 0s to the EEPROM, which | |
233 | get ignored during the read process */ | |
234 | ||
235 | for (z = 0; z < 16; z++) { | |
236 | dlink_send_eeprom_bit(0, addr); | |
237 | value = (value << 1) | (inb(addr + 0x1e) & 0x01); | |
238 | } | |
239 | ||
240 | return value; | |
241 | } | |
242 | ||
243 | /* | |
244 | * Note that at boot, this probe only picks up one card at a time. | |
245 | */ | |
246 | ||
247 | static int __init do_ne2_probe(struct net_device *dev) | |
248 | { | |
249 | static int current_mca_slot = -1; | |
250 | int i; | |
251 | int adapter_found = 0; | |
252 | ||
253 | SET_MODULE_OWNER(dev); | |
254 | ||
255 | /* Do not check any supplied i/o locations. | |
256 | POS registers usually don't fail :) */ | |
257 | ||
258 | /* MCA cards have POS registers. | |
259 | Autodetecting MCA cards is extremely simple. | |
260 | Just search for the card. */ | |
261 | ||
262 | for(i = 0; (ne2_adapters[i].name != NULL) && !adapter_found; i++) { | |
263 | current_mca_slot = | |
264 | mca_find_unused_adapter(ne2_adapters[i].id, 0); | |
265 | ||
266 | if((current_mca_slot != MCA_NOTFOUND) && !adapter_found) { | |
267 | int res; | |
268 | mca_set_adapter_name(current_mca_slot, | |
269 | ne2_adapters[i].name); | |
270 | mca_mark_as_used(current_mca_slot); | |
271 | ||
272 | res = ne2_probe1(dev, current_mca_slot); | |
273 | if (res) | |
274 | mca_mark_as_unused(current_mca_slot); | |
275 | return res; | |
276 | } | |
277 | } | |
278 | return -ENODEV; | |
279 | } | |
280 | ||
281 | static void cleanup_card(struct net_device *dev) | |
282 | { | |
283 | mca_mark_as_unused(ei_status.priv); | |
284 | mca_set_adapter_procfn( ei_status.priv, NULL, NULL); | |
285 | free_irq(dev->irq, dev); | |
286 | release_region(dev->base_addr, NE_IO_EXTENT); | |
287 | } | |
288 | ||
289 | #ifndef MODULE | |
290 | struct net_device * __init ne2_probe(int unit) | |
291 | { | |
292 | struct net_device *dev = alloc_ei_netdev(); | |
293 | int err; | |
294 | ||
295 | if (!dev) | |
296 | return ERR_PTR(-ENOMEM); | |
297 | ||
298 | sprintf(dev->name, "eth%d", unit); | |
299 | netdev_boot_setup_check(dev); | |
300 | ||
301 | err = do_ne2_probe(dev); | |
302 | if (err) | |
303 | goto out; | |
1da177e4 | 304 | return dev; |
1da177e4 LT |
305 | out: |
306 | free_netdev(dev); | |
307 | return ERR_PTR(err); | |
308 | } | |
309 | #endif | |
310 | ||
311 | static int ne2_procinfo(char *buf, int slot, struct net_device *dev) | |
312 | { | |
313 | int len=0; | |
314 | ||
315 | len += sprintf(buf+len, "The NE/2 Ethernet Adapter\n" ); | |
316 | len += sprintf(buf+len, "Driver written by Wim Dumon "); | |
317 | len += sprintf(buf+len, "<wimpie@kotnet.org>\n"); | |
318 | len += sprintf(buf+len, "Modified by "); | |
319 | len += sprintf(buf+len, "David Weinehall <tao@acc.umu.se>\n"); | |
320 | len += sprintf(buf+len, "and by Magnus Jonsson <bigfoot@acc.umu.se>\n"); | |
321 | len += sprintf(buf+len, "Based on the original NE2000 drivers\n" ); | |
322 | len += sprintf(buf+len, "Base IO: %#x\n", (unsigned int)dev->base_addr); | |
323 | len += sprintf(buf+len, "IRQ : %d\n", dev->irq); | |
324 | ||
325 | #define HW_ADDR(i) dev->dev_addr[i] | |
326 | len += sprintf(buf+len, "HW addr : %x:%x:%x:%x:%x:%x\n", | |
327 | HW_ADDR(0), HW_ADDR(1), HW_ADDR(2), | |
328 | HW_ADDR(3), HW_ADDR(4), HW_ADDR(5) ); | |
329 | #undef HW_ADDR | |
330 | ||
331 | return len; | |
332 | } | |
333 | ||
334 | static int __init ne2_probe1(struct net_device *dev, int slot) | |
335 | { | |
336 | int i, base_addr, irq, retval; | |
337 | unsigned char POS; | |
338 | unsigned char SA_prom[32]; | |
339 | const char *name = "NE/2"; | |
340 | int start_page, stop_page; | |
341 | static unsigned version_printed; | |
342 | ||
343 | if (ei_debug && version_printed++ == 0) | |
344 | printk(version); | |
345 | ||
346 | printk("NE/2 ethercard found in slot %d:", slot); | |
347 | ||
348 | /* Read base IO and IRQ from the POS-registers */ | |
349 | POS = mca_read_stored_pos(slot, 2); | |
350 | if(!(POS % 2)) { | |
351 | printk(" disabled.\n"); | |
352 | return -ENODEV; | |
353 | } | |
354 | ||
355 | /* handle different POS register structure for D-Link card */ | |
356 | ||
357 | if (mca_read_stored_pos(slot, 0) == 0xea) { | |
358 | base_addr = dlink_addresses[(POS >> 5) & 0x03]; | |
359 | irq = dlink_irqs[(POS >> 2) & 0x07]; | |
360 | } | |
361 | else { | |
362 | i = (POS & 0xE)>>1; | |
363 | /* printk("Halleluja sdog, als er na de pijl een 1 staat is 1 - 1 == 0" | |
364 | " en zou het moeten werken -> %d\n", i); | |
365 | The above line was for remote testing, thanx to sdog ... */ | |
366 | base_addr = addresses[i - 1]; | |
367 | irq = irqs[(POS & 0x60)>>5]; | |
368 | } | |
369 | ||
370 | if (!request_region(base_addr, NE_IO_EXTENT, DRV_NAME)) | |
371 | return -EBUSY; | |
372 | ||
373 | #ifdef DEBUG | |
374 | printk("POS info : pos 2 = %#x ; base = %#x ; irq = %ld\n", POS, | |
375 | base_addr, irq); | |
376 | #endif | |
377 | ||
378 | #ifndef CRYNWR_WAY | |
379 | /* Reset the card the way they do it in the Crynwr packet driver */ | |
380 | for (i=0; i<8; i++) | |
381 | outb(0x0, base_addr + NE_RESET); | |
382 | inb(base_addr + NE_RESET); | |
383 | outb(0x21, base_addr + NE_CMD); | |
384 | if (inb(base_addr + NE_CMD) != 0x21) { | |
385 | printk("NE/2 adapter not responding\n"); | |
386 | retval = -ENODEV; | |
387 | goto out; | |
388 | } | |
389 | ||
390 | /* In the crynwr sources they do a RAM-test here. I skip it. I suppose | |
391 | my RAM is okay. Suppose your memory is broken. Then this test | |
392 | should fail and you won't be able to use your card. But if I do not | |
393 | test, you won't be able to use your card, neither. So this test | |
394 | won't help you. */ | |
395 | ||
396 | #else /* _I_ never tested it this way .. Go ahead and try ...*/ | |
397 | /* Reset card. Who knows what dain-bramaged state it was left in. */ | |
398 | { | |
399 | unsigned long reset_start_time = jiffies; | |
400 | ||
401 | /* DON'T change these to inb_p/outb_p or reset will fail on | |
402 | clones.. */ | |
403 | outb(inb(base_addr + NE_RESET), base_addr + NE_RESET); | |
404 | ||
405 | while ((inb_p(base_addr + EN0_ISR) & ENISR_RESET) == 0) | |
406 | if (jiffies - reset_start_time > 2*HZ/100) { | |
407 | printk(" not found (no reset ack).\n"); | |
408 | retval = -ENODEV; | |
409 | goto out; | |
410 | } | |
411 | ||
412 | outb_p(0xff, base_addr + EN0_ISR); /* Ack all intr. */ | |
413 | } | |
414 | #endif | |
415 | ||
416 | ||
417 | /* Read the 16 bytes of station address PROM. | |
418 | We must first initialize registers, similar to | |
419 | NS8390_init(eifdev, 0). | |
420 | We can't reliably read the SAPROM address without this. | |
421 | (I learned the hard way!). */ | |
422 | { | |
423 | struct { | |
424 | unsigned char value, offset; | |
425 | } program_seq[] = { | |
426 | /* Select page 0 */ | |
427 | {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, | |
428 | {0x49, EN0_DCFG}, /* Set WORD-wide (0x49) access. */ | |
429 | {0x00, EN0_RCNTLO}, /* Clear the count regs. */ | |
430 | {0x00, EN0_RCNTHI}, | |
431 | {0x00, EN0_IMR}, /* Mask completion irq. */ | |
432 | {0xFF, EN0_ISR}, | |
433 | {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */ | |
434 | {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */ | |
435 | {32, EN0_RCNTLO}, | |
436 | {0x00, EN0_RCNTHI}, | |
437 | {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */ | |
438 | {0x00, EN0_RSARHI}, | |
439 | {E8390_RREAD+E8390_START, E8390_CMD}, | |
440 | }; | |
441 | ||
442 | for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) | |
443 | outb_p(program_seq[i].value, base_addr + | |
444 | program_seq[i].offset); | |
445 | ||
446 | } | |
447 | for(i = 0; i < 6 /*sizeof(SA_prom)*/; i+=1) { | |
448 | SA_prom[i] = inb(base_addr + NE_DATAPORT); | |
449 | } | |
450 | ||
451 | /* I don't know whether the previous sequence includes the general | |
452 | board reset procedure, so better don't omit it and just overwrite | |
453 | the garbage read from a DE-320 with correct stuff. */ | |
454 | ||
455 | if (mca_read_stored_pos(slot, 0) == 0xea) { | |
456 | unsigned int v; | |
457 | ||
458 | for (i = 0; i < 3; i++) { | |
459 | v = dlink_get_eeprom(i, base_addr); | |
460 | SA_prom[(i << 1) ] = v & 0xff; | |
461 | SA_prom[(i << 1) + 1] = (v >> 8) & 0xff; | |
462 | } | |
463 | } | |
464 | ||
465 | start_page = NESM_START_PG; | |
466 | stop_page = NESM_STOP_PG; | |
467 | ||
468 | dev->irq=irq; | |
469 | ||
470 | /* Snarf the interrupt now. There's no point in waiting since we cannot | |
471 | share and the board will usually be enabled. */ | |
472 | retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev); | |
473 | if (retval) { | |
474 | printk (" unable to get IRQ %d (irqval=%d).\n", | |
475 | dev->irq, retval); | |
476 | goto out; | |
477 | } | |
478 | ||
479 | dev->base_addr = base_addr; | |
480 | ||
481 | for(i = 0; i < ETHER_ADDR_LEN; i++) { | |
482 | printk(" %2.2x", SA_prom[i]); | |
483 | dev->dev_addr[i] = SA_prom[i]; | |
484 | } | |
485 | ||
486 | printk("\n%s: %s found at %#x, using IRQ %d.\n", | |
487 | dev->name, name, base_addr, dev->irq); | |
488 | ||
489 | mca_set_adapter_procfn(slot, (MCA_ProcFn) ne2_procinfo, dev); | |
490 | ||
491 | ei_status.name = name; | |
492 | ei_status.tx_start_page = start_page; | |
493 | ei_status.stop_page = stop_page; | |
494 | ei_status.word16 = (2 == 2); | |
495 | ||
496 | ei_status.rx_start_page = start_page + TX_PAGES; | |
497 | #ifdef PACKETBUF_MEMSIZE | |
498 | /* Allow the packet buffer size to be overridden by know-it-alls. */ | |
499 | ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE; | |
500 | #endif | |
501 | ||
502 | ei_status.reset_8390 = &ne_reset_8390; | |
503 | ei_status.block_input = &ne_block_input; | |
504 | ei_status.block_output = &ne_block_output; | |
505 | ei_status.get_8390_hdr = &ne_get_8390_hdr; | |
506 | ||
507 | ei_status.priv = slot; | |
508 | ||
509 | dev->open = &ne_open; | |
510 | dev->stop = &ne_close; | |
511 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
512 | dev->poll_controller = ei_poll; | |
513 | #endif | |
514 | NS8390_init(dev, 0); | |
b1fc5505 | 515 | |
516 | retval = register_netdev(dev); | |
517 | if (retval) | |
518 | goto out1; | |
1da177e4 | 519 | return 0; |
b1fc5505 | 520 | out1: |
521 | mca_set_adapter_procfn( ei_status.priv, NULL, NULL); | |
522 | free_irq(dev->irq, dev); | |
1da177e4 LT |
523 | out: |
524 | release_region(base_addr, NE_IO_EXTENT); | |
525 | return retval; | |
526 | } | |
527 | ||
528 | static int ne_open(struct net_device *dev) | |
529 | { | |
530 | ei_open(dev); | |
531 | return 0; | |
532 | } | |
533 | ||
534 | static int ne_close(struct net_device *dev) | |
535 | { | |
536 | if (ei_debug > 1) | |
537 | printk("%s: Shutting down ethercard.\n", dev->name); | |
538 | ei_close(dev); | |
539 | return 0; | |
540 | } | |
541 | ||
542 | /* Hard reset the card. This used to pause for the same period that a | |
543 | 8390 reset command required, but that shouldn't be necessary. */ | |
544 | static void ne_reset_8390(struct net_device *dev) | |
545 | { | |
546 | unsigned long reset_start_time = jiffies; | |
547 | ||
548 | if (ei_debug > 1) | |
549 | printk("resetting the 8390 t=%ld...", jiffies); | |
550 | ||
551 | /* DON'T change these to inb_p/outb_p or reset will fail on clones. */ | |
552 | outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); | |
553 | ||
554 | ei_status.txing = 0; | |
555 | ei_status.dmaing = 0; | |
556 | ||
557 | /* This check _should_not_ be necessary, omit eventually. */ | |
558 | while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0) | |
559 | if (jiffies - reset_start_time > 2*HZ/100) { | |
560 | printk("%s: ne_reset_8390() did not complete.\n", | |
561 | dev->name); | |
562 | break; | |
563 | } | |
564 | outb_p(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */ | |
565 | } | |
566 | ||
567 | /* Grab the 8390 specific header. Similar to the block_input routine, but | |
568 | we don't need to be concerned with ring wrap as the header will be at | |
569 | the start of a page, so we optimize accordingly. */ | |
570 | ||
571 | static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, | |
572 | int ring_page) | |
573 | { | |
574 | ||
575 | int nic_base = dev->base_addr; | |
576 | ||
577 | /* This *shouldn't* happen. | |
578 | If it does, it's the last thing you'll see */ | |
579 | if (ei_status.dmaing) { | |
580 | printk("%s: DMAing conflict in ne_get_8390_hdr " | |
581 | "[DMAstat:%d][irqlock:%d].\n", | |
582 | dev->name, ei_status.dmaing, ei_status.irqlock); | |
583 | return; | |
584 | } | |
585 | ||
586 | ei_status.dmaing |= 0x01; | |
587 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); | |
588 | outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO); | |
589 | outb_p(0, nic_base + EN0_RCNTHI); | |
590 | outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */ | |
591 | outb_p(ring_page, nic_base + EN0_RSARHI); | |
592 | outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD); | |
593 | ||
594 | if (ei_status.word16) | |
595 | insw(NE_BASE + NE_DATAPORT, hdr, | |
596 | sizeof(struct e8390_pkt_hdr)>>1); | |
597 | else | |
598 | insb(NE_BASE + NE_DATAPORT, hdr, | |
599 | sizeof(struct e8390_pkt_hdr)); | |
600 | ||
601 | outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ | |
602 | ei_status.dmaing &= ~0x01; | |
603 | } | |
604 | ||
605 | /* Block input and output, similar to the Crynwr packet driver. If you | |
606 | are porting to a new ethercard, look at the packet driver source for | |
607 | hints. The NEx000 doesn't share the on-board packet memory -- you have | |
608 | to put the packet out through the "remote DMA" dataport using outb. */ | |
609 | ||
610 | static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, | |
611 | int ring_offset) | |
612 | { | |
613 | #ifdef NE_SANITY_CHECK | |
614 | int xfer_count = count; | |
615 | #endif | |
616 | int nic_base = dev->base_addr; | |
617 | char *buf = skb->data; | |
618 | ||
619 | /* This *shouldn't* happen. | |
620 | If it does, it's the last thing you'll see */ | |
621 | if (ei_status.dmaing) { | |
622 | printk("%s: DMAing conflict in ne_block_input " | |
623 | "[DMAstat:%d][irqlock:%d].\n", | |
624 | dev->name, ei_status.dmaing, ei_status.irqlock); | |
625 | return; | |
626 | } | |
627 | ei_status.dmaing |= 0x01; | |
628 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); | |
629 | outb_p(count & 0xff, nic_base + EN0_RCNTLO); | |
630 | outb_p(count >> 8, nic_base + EN0_RCNTHI); | |
631 | outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO); | |
632 | outb_p(ring_offset >> 8, nic_base + EN0_RSARHI); | |
633 | outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD); | |
634 | if (ei_status.word16) { | |
635 | insw(NE_BASE + NE_DATAPORT,buf,count>>1); | |
636 | if (count & 0x01) { | |
637 | buf[count-1] = inb(NE_BASE + NE_DATAPORT); | |
638 | #ifdef NE_SANITY_CHECK | |
639 | xfer_count++; | |
640 | #endif | |
641 | } | |
642 | } else { | |
643 | insb(NE_BASE + NE_DATAPORT, buf, count); | |
644 | } | |
645 | ||
646 | #ifdef NE_SANITY_CHECK | |
647 | /* This was for the ALPHA version only, but enough people have | |
648 | been encountering problems so it is still here. If you see | |
649 | this message you either 1) have a slightly incompatible clone | |
650 | or 2) have noise/speed problems with your bus. */ | |
651 | if (ei_debug > 1) { /* DMA termination address check... */ | |
652 | int addr, tries = 20; | |
653 | do { | |
654 | /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here | |
655 | -- it's broken for Rx on some cards! */ | |
656 | int high = inb_p(nic_base + EN0_RSARHI); | |
657 | int low = inb_p(nic_base + EN0_RSARLO); | |
658 | addr = (high << 8) + low; | |
659 | if (((ring_offset + xfer_count) & 0xff) == low) | |
660 | break; | |
661 | } while (--tries > 0); | |
662 | if (tries <= 0) | |
663 | printk("%s: RX transfer address mismatch," | |
664 | "%#4.4x (expected) vs. %#4.4x (actual).\n", | |
665 | dev->name, ring_offset + xfer_count, addr); | |
666 | } | |
667 | #endif | |
668 | outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ | |
669 | ei_status.dmaing &= ~0x01; | |
670 | } | |
671 | ||
672 | static void ne_block_output(struct net_device *dev, int count, | |
673 | const unsigned char *buf, const int start_page) | |
674 | { | |
675 | int nic_base = NE_BASE; | |
676 | unsigned long dma_start; | |
677 | #ifdef NE_SANITY_CHECK | |
678 | int retries = 0; | |
679 | #endif | |
680 | ||
681 | /* Round the count up for word writes. Do we need to do this? | |
682 | What effect will an odd byte count have on the 8390? | |
683 | I should check someday. */ | |
684 | if (ei_status.word16 && (count & 0x01)) | |
685 | count++; | |
686 | ||
687 | /* This *shouldn't* happen. | |
688 | If it does, it's the last thing you'll see */ | |
689 | if (ei_status.dmaing) { | |
690 | printk("%s: DMAing conflict in ne_block_output." | |
691 | "[DMAstat:%d][irqlock:%d]\n", | |
692 | dev->name, ei_status.dmaing, ei_status.irqlock); | |
693 | return; | |
694 | } | |
695 | ei_status.dmaing |= 0x01; | |
696 | /* We should already be in page 0, but to be safe... */ | |
697 | outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); | |
698 | ||
699 | #ifdef NE_SANITY_CHECK | |
700 | retry: | |
701 | #endif | |
702 | ||
703 | #ifdef NE8390_RW_BUGFIX | |
704 | /* Handle the read-before-write bug the same way as the | |
705 | Crynwr packet driver -- the NatSemi method doesn't work. | |
706 | Actually this doesn't always work either, but if you have | |
707 | problems with your NEx000 this is better than nothing! */ | |
708 | outb_p(0x42, nic_base + EN0_RCNTLO); | |
709 | outb_p(0x00, nic_base + EN0_RCNTHI); | |
710 | outb_p(0x42, nic_base + EN0_RSARLO); | |
711 | outb_p(0x00, nic_base + EN0_RSARHI); | |
712 | outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD); | |
713 | /* Make certain that the dummy read has occurred. */ | |
714 | SLOW_DOWN_IO; | |
715 | SLOW_DOWN_IO; | |
716 | SLOW_DOWN_IO; | |
717 | #endif | |
718 | ||
719 | outb_p(ENISR_RDC, nic_base + EN0_ISR); | |
720 | ||
721 | /* Now the normal output. */ | |
722 | outb_p(count & 0xff, nic_base + EN0_RCNTLO); | |
723 | outb_p(count >> 8, nic_base + EN0_RCNTHI); | |
724 | outb_p(0x00, nic_base + EN0_RSARLO); | |
725 | outb_p(start_page, nic_base + EN0_RSARHI); | |
726 | ||
727 | outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD); | |
728 | if (ei_status.word16) { | |
729 | outsw(NE_BASE + NE_DATAPORT, buf, count>>1); | |
730 | } else { | |
731 | outsb(NE_BASE + NE_DATAPORT, buf, count); | |
732 | } | |
733 | ||
734 | dma_start = jiffies; | |
735 | ||
736 | #ifdef NE_SANITY_CHECK | |
737 | /* This was for the ALPHA version only, but enough people have | |
738 | been encountering problems so it is still here. */ | |
739 | ||
740 | if (ei_debug > 1) { /* DMA termination address check... */ | |
741 | int addr, tries = 20; | |
742 | do { | |
743 | int high = inb_p(nic_base + EN0_RSARHI); | |
744 | int low = inb_p(nic_base + EN0_RSARLO); | |
745 | addr = (high << 8) + low; | |
746 | if ((start_page << 8) + count == addr) | |
747 | break; | |
748 | } while (--tries > 0); | |
749 | if (tries <= 0) { | |
750 | printk("%s: Tx packet transfer address mismatch," | |
751 | "%#4.4x (expected) vs. %#4.4x (actual).\n", | |
752 | dev->name, (start_page << 8) + count, addr); | |
753 | if (retries++ == 0) | |
754 | goto retry; | |
755 | } | |
756 | } | |
757 | #endif | |
758 | ||
759 | while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0) | |
760 | if (jiffies - dma_start > 2*HZ/100) { /* 20ms */ | |
761 | printk("%s: timeout waiting for Tx RDC.\n", dev->name); | |
762 | ne_reset_8390(dev); | |
763 | NS8390_init(dev,1); | |
764 | break; | |
765 | } | |
766 | ||
767 | outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ | |
768 | ei_status.dmaing &= ~0x01; | |
769 | return; | |
770 | } | |
771 | ||
772 | ||
773 | #ifdef MODULE | |
774 | #define MAX_NE_CARDS 4 /* Max number of NE cards per module */ | |
775 | static struct net_device *dev_ne[MAX_NE_CARDS]; | |
776 | static int io[MAX_NE_CARDS]; | |
777 | static int irq[MAX_NE_CARDS]; | |
778 | static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */ | |
779 | MODULE_LICENSE("GPL"); | |
780 | ||
781 | module_param_array(io, int, NULL, 0); | |
782 | module_param_array(irq, int, NULL, 0); | |
783 | module_param_array(bad, int, NULL, 0); | |
784 | MODULE_PARM_DESC(io, "(ignored)"); | |
785 | MODULE_PARM_DESC(irq, "(ignored)"); | |
786 | MODULE_PARM_DESC(bad, "(ignored)"); | |
787 | ||
788 | /* Module code fixed by David Weinehall */ | |
789 | ||
790 | int init_module(void) | |
791 | { | |
792 | struct net_device *dev; | |
793 | int this_dev, found = 0; | |
794 | ||
795 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | |
796 | dev = alloc_ei_netdev(); | |
797 | if (!dev) | |
798 | break; | |
799 | dev->irq = irq[this_dev]; | |
800 | dev->mem_end = bad[this_dev]; | |
801 | dev->base_addr = io[this_dev]; | |
802 | if (do_ne2_probe(dev) == 0) { | |
b1fc5505 | 803 | dev_ne[found++] = dev; |
804 | continue; | |
1da177e4 LT |
805 | } |
806 | free_netdev(dev); | |
807 | break; | |
808 | } | |
809 | if (found) | |
810 | return 0; | |
811 | printk(KERN_WARNING "ne2.c: No NE/2 card found\n"); | |
812 | return -ENXIO; | |
813 | } | |
814 | ||
815 | void cleanup_module(void) | |
816 | { | |
817 | int this_dev; | |
818 | ||
819 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | |
820 | struct net_device *dev = dev_ne[this_dev]; | |
821 | if (dev) { | |
822 | unregister_netdev(dev); | |
823 | cleanup_card(dev); | |
824 | free_netdev(dev); | |
825 | } | |
826 | } | |
827 | } | |
828 | #endif /* MODULE */ |