|
|
1.1 root 1: /* ne.c: A general non-shared-memory NS8390 ethernet driver for linux. */
2: /*
3: Written 1992-94 by Donald Becker.
4:
5: Copyright 1993 United States Government as represented by the
6: Director, National Security Agency.
7:
8: This software may be used and distributed according to the terms
9: of the GNU Public License, incorporated herein by reference.
10:
11: The author may be reached as [email protected], or C/O
12: Center of Excellence in Space Data and Information Sciences
13: Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
14:
15: This driver should work with many programmed-I/O 8390-based ethernet
16: boards. Currently it supports the NE1000, NE2000, many clones,
17: and some Cabletron products.
18:
19: Changelog:
20:
21: Paul Gortmaker : use ENISR_RDC to monitor Tx PIO uploads, made
22: sanity checks and bad clone support optional.
23: Paul Gortmaker : new reset code, reset card after probe at boot.
24: Paul Gortmaker : multiple card support for module users.
25: Paul Gortmaker : Support for PCI ne2k clones, similar to lance.c
26: Paul Gortmaker : Allow users with bad cards to avoid full probe.
27: Paul Gortmaker : PCI probe changes, more PCI cards supported.
28:
29: */
30:
31: /* Routines for the NatSemi-based designs (NE[12]000). */
32:
33: static const char *version =
34: "ne.c:v1.10 9/23/94 Donald Becker ([email protected])\n";
35:
36:
37: #include <linux/module.h>
38: #include <linux/config.h>
39: #include <linux/kernel.h>
40: #include <linux/sched.h>
41: #include <linux/errno.h>
42: #include <linux/pci.h>
43: #include <linux/bios32.h>
44: #include <asm/system.h>
45: #include <asm/io.h>
46:
47: #include <linux/netdevice.h>
48: #include <linux/etherdevice.h>
49: #include "8390.h"
50:
51: /* Some defines that people can play with if so inclined. */
52:
53: /* Do we support clones that don't adhere to 14,15 of the SAprom ? */
54: #define SUPPORT_NE_BAD_CLONES
55:
56: /* Do we perform extra sanity checks on stuff ? */
57: /* #define NE_SANITY_CHECK */
58:
59: /* Do we implement the read before write bugfix ? */
60: /* #define NE_RW_BUGFIX */
61:
62: /* Do we have a non std. amount of memory? (in units of 256 byte pages) */
63: /* #define PACKETBUF_MEMSIZE 0x40 */
64:
65: #if defined(HAVE_DEVLIST) || !defined(MODULE)
66: /* A zero-terminated list of I/O addresses to be probed. */
67: static unsigned int netcard_portlist[] =
68: { 0x300, 0x280, 0x320, 0x340, 0x360, 0};
69: #endif /* defined(HAVE_DEVLIST) || !defined(MODULE) */
70:
71: #ifdef CONFIG_PCI
72: /* Ack! People are making PCI ne2000 clones! Oh the horror, the horror... */
73: static struct { unsigned short vendor, dev_id;}
74: pci_clone_list[] = {
75: {PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8029},
76: {PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_89C940},
77: {PCI_VENDOR_ID_COMPEX, PCI_DEVICE_ID_COMPEX_RL2000},
78: {PCI_VENDOR_ID_KTI, PCI_DEVICE_ID_KTI_ET32P2},
79: {PCI_VENDOR_ID_NETVIN, PCI_DEVICE_ID_NETVIN_NV5000SC},
80: {PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C926},
81: {0,}
82: };
83: #endif
84:
85: #ifdef SUPPORT_NE_BAD_CLONES
86: /* A list of bad clones that we none-the-less recognize. */
87: static struct { const char *name8, *name16; unsigned char SAprefix[4];}
88: bad_clone_list[] = {
89: {"DE100", "DE200", {0x00, 0xDE, 0x01,}},
90: {"DE120", "DE220", {0x00, 0x80, 0xc8,}},
91: {"DFI1000", "DFI2000", {'D', 'F', 'I',}}, /* Original, eh? */
92: {"EtherNext UTP8", "EtherNext UTP16", {0x00, 0x00, 0x79}},
93: {"NE1000","NE2000-invalid", {0x00, 0x00, 0xd8}}, /* Ancient real NE1000. */
94: {"NN1000", "NN2000", {0x08, 0x03, 0x08}}, /* Outlaw no-name clone. */
95: {"4-DIM8","4-DIM16", {0x00,0x00,0x4d,}}, /* Outlaw 4-Dimension cards. */
96: {"Con-Intl_8", "Con-Intl_16", {0x00, 0x00, 0x24}}, /* Connect Int'nl */
97: {"ET-100","ET-200", {0x00, 0x45, 0x54}}, /* YANG and YA clone */
98: {"COMPEX","COMPEX16",{0x00,0x80,0x48}}, /* Broken ISA Compex cards */
99: {"E-LAN100", "E-LAN200", {0x00, 0x00, 0x5d}}, /* Broken ne1000 clones */
1.1.1.2 ! root 100: {"RealTek 8029", "RealTek 8029", {0x00, 0x3e, 0x4d}}, /* RealTek PCI cards */
1.1 root 101: {0,}
102: };
103: #endif
104:
105: /* ---- No user-serviceable parts below ---- */
106:
107: #define NE_BASE (dev->base_addr)
108: #define NE_CMD 0x00
109: #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
110: #define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
111: #define NE_IO_EXTENT 0x20
112:
113: #define NE1SM_START_PG 0x20 /* First page of TX buffer */
114: #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
115: #define NESM_START_PG 0x40 /* First page of TX buffer */
116: #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
117:
118: /* Non-zero only if the current card is a PCI with BIOS-set IRQ. */
119: static unsigned char pci_irq_line = 0;
120:
121: int ne_probe(struct device *dev);
122: #ifdef CONFIG_PCI
123: static int ne_probe_pci(struct device *dev);
124: #endif
125: static int ne_probe1(struct device *dev, int ioaddr);
126:
127: static int ne_open(struct device *dev);
128: static int ne_close(struct device *dev);
129:
130: static void ne_reset_8390(struct device *dev);
131: static void ne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
132: int ring_page);
133: static void ne_block_input(struct device *dev, int count,
134: struct sk_buff *skb, int ring_offset);
135: static void ne_block_output(struct device *dev, const int count,
136: const unsigned char *buf, const int start_page);
137:
138:
139: /* Probe for various non-shared-memory ethercards.
140:
141: NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
142: buffer memory space. NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
143: the SAPROM, while other supposed NE2000 clones must be detected by their
144: SA prefix.
145:
146: Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
147: mode results in doubled values, which can be detected and compensated for.
148:
149: The probe is also responsible for initializing the card and filling
150: in the 'dev' and 'ei_status' structures.
151:
152: We use the minimum memory size for some ethercard product lines, iff we can't
153: distinguish models. You can increase the packet buffer size by setting
154: PACKETBUF_MEMSIZE. Reported Cabletron packet buffer locations are:
155: E1010 starts at 0x100 and ends at 0x2000.
156: E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
157: E2010 starts at 0x100 and ends at 0x4000.
158: E2010-x starts at 0x100 and ends at 0xffff. */
159:
160: #ifdef HAVE_DEVLIST
161: struct netdev_entry netcard_drv =
162: {"ne", ne_probe1, NE_IO_EXTENT, netcard_portlist};
163: #else
164:
165: /* Note that this probe only picks up one card at a time, even for multiple
166: PCI ne2k cards. Use "ether=0,0,eth1" if you have a second PCI ne2k card.
167: This keeps things consistent regardless of the bus type of the card. */
168:
169: int ne_probe(struct device *dev)
170: {
171: #ifndef MODULE
172: int i;
173: #endif /* MODULE */
174: int base_addr = dev ? dev->base_addr : 0;
175:
176: /* First check any supplied i/o locations. User knows best. <cough> */
177: if (base_addr > 0x1ff) /* Check a single specified location. */
178: return ne_probe1(dev, base_addr);
179: else if (base_addr != 0) /* Don't probe at all. */
180: return ENXIO;
181:
182: #ifdef CONFIG_PCI
183: /* Then look for any installed PCI clones */
184: if (pcibios_present() && (ne_probe_pci(dev) == 0))
185: return 0;
186: #endif
187:
188: #ifndef MODULE
189: /* Last resort. The semi-risky ISA auto-probe. */
190: for (i = 0; netcard_portlist[i]; i++) {
191: int ioaddr = netcard_portlist[i];
192: if (check_region(ioaddr, NE_IO_EXTENT))
193: continue;
194: if (ne_probe1(dev, ioaddr) == 0)
195: return 0;
196: }
197: #endif
198:
199: return ENODEV;
200: }
201: #endif
202:
203: #ifdef CONFIG_PCI
204: static int ne_probe_pci(struct device *dev)
205: {
206: int i;
207:
208: for (i = 0; pci_clone_list[i].vendor != 0; i++) {
209: unsigned char pci_bus, pci_device_fn;
210: unsigned int pci_ioaddr;
211: u16 pci_command, new_command;
212: int pci_index;
213:
214: for (pci_index = 0; pci_index < 8; pci_index++) {
215: if (pcibios_find_device (pci_clone_list[i].vendor,
216: pci_clone_list[i].dev_id, pci_index,
217: &pci_bus, &pci_device_fn) != 0)
218: break; /* No more of these type of cards */
219: pcibios_read_config_dword(pci_bus, pci_device_fn,
220: PCI_BASE_ADDRESS_0, &pci_ioaddr);
221: /* Strip the I/O address out of the returned value */
222: pci_ioaddr &= PCI_BASE_ADDRESS_IO_MASK;
223: /* Avoid already found cards from previous calls */
224: if (check_region(pci_ioaddr, NE_IO_EXTENT))
225: continue;
226: pcibios_read_config_byte(pci_bus, pci_device_fn,
227: PCI_INTERRUPT_LINE, &pci_irq_line);
228: break; /* Beauty -- got a valid card. */
229: }
230: if (pci_irq_line == 0) continue; /* Try next PCI ID */
231: printk("ne.c: PCI BIOS reports NE 2000 clone at i/o %#x, irq %d.\n",
232: pci_ioaddr, pci_irq_line);
233:
234: pcibios_read_config_word(pci_bus, pci_device_fn,
235: PCI_COMMAND, &pci_command);
236:
237: /* Activate the card: fix for brain-damaged Win98 BIOSes. */
238: new_command = pci_command | PCI_COMMAND_IO;
239: if (pci_command != new_command) {
240: printk(KERN_INFO " The PCI BIOS has not enabled this"
241: " NE2k clone! Updating PCI command %4.4x->%4.4x.\n",
242: pci_command, new_command);
243: pcibios_write_config_word(pci_bus, pci_device_fn,
244: PCI_COMMAND, new_command);
245: }
246:
247: if (ne_probe1(dev, pci_ioaddr) != 0) { /* Shouldn't happen. */
248: printk(KERN_ERR "ne.c: Probe of PCI card at %#x failed.\n", pci_ioaddr);
249: pci_irq_line = 0;
250: return -ENXIO;
251: }
252: pci_irq_line = 0;
253: return 0;
254: }
255: return -ENODEV;
256: }
257: #endif /* CONFIG_PCI */
258:
259: static int ne_probe1(struct device *dev, int ioaddr)
260: {
261: int i;
262: unsigned char SA_prom[32];
263: int wordlength = 2;
264: const char *name = NULL;
265: int start_page, stop_page;
266: int neX000, ctron, bad_card;
267: int reg0 = inb_p(ioaddr);
268: static unsigned version_printed = 0;
269:
270: if (reg0 == 0xFF)
271: return ENODEV;
272:
273: /* Do a preliminary verification that we have a 8390. */
274: { int regd;
275: outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
276: regd = inb_p(ioaddr + 0x0d);
277: outb_p(0xff, ioaddr + 0x0d);
278: outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
279: inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
280: if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
281: outb_p(reg0, ioaddr);
282: outb_p(regd, ioaddr + 0x0d); /* Restore the old values. */
283: return ENODEV;
284: }
285: }
286:
287: /* We should have a "dev" from Space.c or the static module table. */
288: if (dev == NULL) {
289: printk(KERN_ERR "ne.c: Passed a NULL device.\n");
290: dev = init_etherdev(0, 0);
291: }
292:
293: if (ei_debug && version_printed++ == 0)
294: printk(version);
295:
296: printk("NE*000 ethercard probe at %#3x:", ioaddr);
297:
298: /* A user with a poor card that fails to ack the reset, or that
299: does not have a valid 0x57,0x57 signature can still use this
300: without having to recompile. Specifying an i/o address along
301: with an otherwise unused dev->mem_end value of "0xBAD" will
302: cause the driver to skip these parts of the probe. */
303:
304: bad_card = ((dev->base_addr != 0) && (dev->mem_end == 0xbad));
305:
306: /* Reset card. Who knows what dain-bramaged state it was left in. */
307: { unsigned long reset_start_time = jiffies;
308:
309: /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
310: outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
311:
312: while ((inb_p(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
313: if (jiffies - reset_start_time > 2*HZ/100) {
314: if (bad_card) {
315: printk(" (warning: no reset ack)");
316: break;
317: } else {
318: printk(" not found (no reset ack).\n");
319: return ENODEV;
320: }
321: }
322:
323: outb_p(0xff, ioaddr + EN0_ISR); /* Ack all intr. */
324: }
325:
326: /* Read the 16 bytes of station address PROM.
327: We must first initialize registers, similar to NS8390_init(eifdev, 0).
328: We can't reliably read the SAPROM address without this.
329: (I learned the hard way!). */
330: {
331: struct {unsigned char value, offset; } program_seq[] = {
332: {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
333: {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
334: {0x00, EN0_RCNTLO}, /* Clear the count regs. */
335: {0x00, EN0_RCNTHI},
336: {0x00, EN0_IMR}, /* Mask completion irq. */
337: {0xFF, EN0_ISR},
338: {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
339: {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
340: {32, EN0_RCNTLO},
341: {0x00, EN0_RCNTHI},
342: {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
343: {0x00, EN0_RSARHI},
344: {E8390_RREAD+E8390_START, E8390_CMD},
345: };
346: for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
347: outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
348:
349: }
350: for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
351: SA_prom[i] = inb(ioaddr + NE_DATAPORT);
352: SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
353: if (SA_prom[i] != SA_prom[i+1])
354: wordlength = 1;
355: }
356:
357: /* At this point, wordlength *only* tells us if the SA_prom is doubled
358: up or not because some broken PCI cards don't respect the byte-wide
359: request in program_seq above, and hence don't have doubled up values.
360: These broken cards would otherwise be detected as an ne1000. */
361:
362: if (wordlength == 2)
363: for (i = 0; i < 16; i++)
364: SA_prom[i] = SA_prom[i+i];
365:
366: if (pci_irq_line || ioaddr >= 0x400)
367: wordlength = 2; /* Catch broken PCI cards mentioned above. */
368:
369: if (wordlength == 2) {
370: /* We must set the 8390 for word mode. */
371: outb_p(0x49, ioaddr + EN0_DCFG);
372: start_page = NESM_START_PG;
373: stop_page = NESM_STOP_PG;
374: } else {
375: start_page = NE1SM_START_PG;
376: stop_page = NE1SM_STOP_PG;
377: }
378:
379: neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
380: ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
381:
382: /* Set up the rest of the parameters. */
383: if (neX000 || bad_card) {
384: name = (wordlength == 2) ? "NE2000" : "NE1000";
385: } else if (ctron) {
386: name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
387: start_page = 0x01;
388: stop_page = (wordlength == 2) ? 0x40 : 0x20;
389: } else {
390: #ifdef SUPPORT_NE_BAD_CLONES
391: /* Ack! Well, there might be a *bad* NE*000 clone there.
392: Check for total bogus addresses. */
393: for (i = 0; bad_clone_list[i].name8; i++) {
394: if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
395: SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
396: SA_prom[2] == bad_clone_list[i].SAprefix[2]) {
397: if (wordlength == 2) {
398: name = bad_clone_list[i].name16;
399: } else {
400: name = bad_clone_list[i].name8;
401: }
402: break;
403: }
404: }
405: if (bad_clone_list[i].name8 == NULL) {
406: printk(" not found (invalid signature %2.2x %2.2x).\n",
407: SA_prom[14], SA_prom[15]);
408: return ENXIO;
409: }
410: #else
411: printk(" not found.\n");
412: return ENXIO;
413: #endif
414:
415: }
416:
417: if (pci_irq_line)
418: dev->irq = pci_irq_line;
419:
420: if (dev->irq < 2) {
421: autoirq_setup(0);
422: outb_p(0x50, ioaddr + EN0_IMR); /* Enable one interrupt. */
423: outb_p(0x00, ioaddr + EN0_RCNTLO);
424: outb_p(0x00, ioaddr + EN0_RCNTHI);
425: outb_p(E8390_RREAD+E8390_START, ioaddr); /* Trigger it... */
426: outb_p(0x00, ioaddr + EN0_IMR); /* Mask it again. */
427: dev->irq = autoirq_report(0);
428: if (ei_debug > 2)
429: printk(" autoirq is %d\n", dev->irq);
430: } else if (dev->irq == 2)
431: /* Fixup for users that don't know that IRQ 2 is really IRQ 9,
432: or don't know which one to set. */
433: dev->irq = 9;
434:
435: if (! dev->irq) {
436: printk(" failed to detect IRQ line.\n");
437: return EAGAIN;
438: }
439:
440: /* Snarf the interrupt now. There's no point in waiting since we cannot
441: share (with ISA cards) and the board will usually be enabled. */
442: {
443: int irqval = request_irq(dev->irq, ei_interrupt,
444: pci_irq_line ? SA_SHIRQ : 0, name, dev);
445: if (irqval) {
446: printk (" unable to get IRQ %d (irqval=%d).\n", dev->irq, irqval);
447: return EAGAIN;
448: }
449: }
450:
451: dev->base_addr = ioaddr;
452:
453: /* Allocate dev->priv and fill in 8390 specific dev fields. */
454: if (ethdev_init(dev)) {
455: printk (" unable to get memory for dev->priv.\n");
456: free_irq(dev->irq, NULL);
457: return -ENOMEM;
458: }
459:
460: request_region(ioaddr, NE_IO_EXTENT, name);
461:
462: for(i = 0; i < ETHER_ADDR_LEN; i++) {
463: printk(" %2.2x", SA_prom[i]);
464: dev->dev_addr[i] = SA_prom[i];
465: }
466:
467: printk("\n%s: %s found at %#x, using IRQ %d.\n",
468: dev->name, name, ioaddr, dev->irq);
469:
470: ei_status.name = name;
471: ei_status.tx_start_page = start_page;
472: ei_status.stop_page = stop_page;
473: ei_status.word16 = (wordlength == 2);
474:
475: ei_status.rx_start_page = start_page + TX_PAGES;
476: #ifdef PACKETBUF_MEMSIZE
477: /* Allow the packet buffer size to be overridden by know-it-alls. */
478: ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
479: #endif
480:
481: ei_status.reset_8390 = &ne_reset_8390;
482: ei_status.block_input = &ne_block_input;
483: ei_status.block_output = &ne_block_output;
484: ei_status.get_8390_hdr = &ne_get_8390_hdr;
485: dev->open = &ne_open;
486: dev->stop = &ne_close;
487: NS8390_init(dev, 0);
488: return 0;
489: }
490:
491: static int
492: ne_open(struct device *dev)
493: {
494: ei_open(dev);
495: MOD_INC_USE_COUNT;
496: return 0;
497: }
498:
499: static int
500: ne_close(struct device *dev)
501: {
502: if (ei_debug > 1)
503: printk("%s: Shutting down ethercard.\n", dev->name);
504: ei_close(dev);
505: MOD_DEC_USE_COUNT;
506: return 0;
507: }
508:
509: /* Hard reset the card. This used to pause for the same period that a
510: 8390 reset command required, but that shouldn't be necessary. */
511: static void
512: ne_reset_8390(struct device *dev)
513: {
514: unsigned long reset_start_time = jiffies;
515:
516: if (ei_debug > 1) printk("resetting the 8390 t=%ld...", jiffies);
517:
518: /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
519: outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
520:
521: ei_status.txing = 0;
522: ei_status.dmaing = 0;
523:
524: /* This check _should_not_ be necessary, omit eventually. */
525: while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
526: if (jiffies - reset_start_time > 2*HZ/100) {
527: printk("%s: ne_reset_8390() did not complete.\n", dev->name);
528: break;
529: }
530: outb_p(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */
531: }
532:
533: /* Grab the 8390 specific header. Similar to the block_input routine, but
534: we don't need to be concerned with ring wrap as the header will be at
535: the start of a page, so we optimize accordingly. */
536:
537: static void
538: ne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
539: {
540:
541: int nic_base = dev->base_addr;
542:
543: /* This *shouldn't* happen. If it does, it's the last thing you'll see */
544: if (ei_status.dmaing) {
545: printk("%s: DMAing conflict in ne_get_8390_hdr "
546: "[DMAstat:%d][irqlock:%d][intr:%d].\n",
547: dev->name, ei_status.dmaing, ei_status.irqlock,
548: dev->interrupt);
549: return;
550: }
551:
552: ei_status.dmaing |= 0x01;
553: outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
554: outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
555: outb_p(0, nic_base + EN0_RCNTHI);
556: outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
557: outb_p(ring_page, nic_base + EN0_RSARHI);
558: outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
559:
560: if (ei_status.word16)
561: insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
562: else
563: insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
564:
565: outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
566: ei_status.dmaing &= ~0x01;
567: }
568:
569: /* Block input and output, similar to the Crynwr packet driver. If you
570: are porting to a new ethercard, look at the packet driver source for hints.
571: The NEx000 doesn't share the on-board packet memory -- you have to put
572: the packet out through the "remote DMA" dataport using outb. */
573:
574: static void
575: ne_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
576: {
577: #ifdef NE_SANITY_CHECK
578: int xfer_count = count;
579: #endif
580: int nic_base = dev->base_addr;
581: char *buf = skb->data;
582:
583: /* This *shouldn't* happen. If it does, it's the last thing you'll see */
584: if (ei_status.dmaing) {
585: printk("%s: DMAing conflict in ne_block_input "
586: "[DMAstat:%d][irqlock:%d][intr:%d].\n",
587: dev->name, ei_status.dmaing, ei_status.irqlock,
588: dev->interrupt);
589: return;
590: }
591: ei_status.dmaing |= 0x01;
592: outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
593: outb_p(count & 0xff, nic_base + EN0_RCNTLO);
594: outb_p(count >> 8, nic_base + EN0_RCNTHI);
595: outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
596: outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
597: outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
598: if (ei_status.word16) {
599: insw(NE_BASE + NE_DATAPORT,buf,count>>1);
600: if (count & 0x01) {
601: buf[count-1] = inb(NE_BASE + NE_DATAPORT);
602: #ifdef NE_SANITY_CHECK
603: xfer_count++;
604: #endif
605: }
606: } else {
607: insb(NE_BASE + NE_DATAPORT, buf, count);
608: }
609:
610: #ifdef NE_SANITY_CHECK
611: /* This was for the ALPHA version only, but enough people have
612: been encountering problems so it is still here. If you see
613: this message you either 1) have a slightly incompatible clone
614: or 2) have noise/speed problems with your bus. */
615: if (ei_debug > 1) { /* DMA termination address check... */
616: int addr, tries = 20;
617: do {
618: /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
619: -- it's broken for Rx on some cards! */
620: int high = inb_p(nic_base + EN0_RSARHI);
621: int low = inb_p(nic_base + EN0_RSARLO);
622: addr = (high << 8) + low;
623: if (((ring_offset + xfer_count) & 0xff) == low)
624: break;
625: } while (--tries > 0);
626: if (tries <= 0)
627: printk("%s: RX transfer address mismatch,"
628: "%#4.4x (expected) vs. %#4.4x (actual).\n",
629: dev->name, ring_offset + xfer_count, addr);
630: }
631: #endif
632: outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
633: ei_status.dmaing &= ~0x01;
634: }
635:
636: static void
637: ne_block_output(struct device *dev, int count,
638: const unsigned char *buf, const int start_page)
639: {
640: int nic_base = NE_BASE;
641: unsigned long dma_start;
642: #ifdef NE_SANITY_CHECK
643: int retries = 0;
644: #endif
645:
646: /* Round the count up for word writes. Do we need to do this?
647: What effect will an odd byte count have on the 8390?
648: I should check someday. */
649: if (ei_status.word16 && (count & 0x01))
650: count++;
651:
652: /* This *shouldn't* happen. If it does, it's the last thing you'll see */
653: if (ei_status.dmaing) {
654: printk("%s: DMAing conflict in ne_block_output."
655: "[DMAstat:%d][irqlock:%d][intr:%d]\n",
656: dev->name, ei_status.dmaing, ei_status.irqlock,
657: dev->interrupt);
658: return;
659: }
660: ei_status.dmaing |= 0x01;
661: /* We should already be in page 0, but to be safe... */
662: outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
663:
664: #ifdef NE_SANITY_CHECK
665: retry:
666: #endif
667:
668: #ifdef NE8390_RW_BUGFIX
669: /* Handle the read-before-write bug the same way as the
670: Crynwr packet driver -- the NatSemi method doesn't work.
671: Actually this doesn't always work either, but if you have
672: problems with your NEx000 this is better than nothing! */
673: outb_p(0x42, nic_base + EN0_RCNTLO);
674: outb_p(0x00, nic_base + EN0_RCNTHI);
675: outb_p(0x42, nic_base + EN0_RSARLO);
676: outb_p(0x00, nic_base + EN0_RSARHI);
677: outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
678: /* Make certain that the dummy read has occurred. */
679: SLOW_DOWN_IO;
680: SLOW_DOWN_IO;
681: SLOW_DOWN_IO;
682: #endif
683:
684: outb_p(ENISR_RDC, nic_base + EN0_ISR);
685:
686: /* Now the normal output. */
687: outb_p(count & 0xff, nic_base + EN0_RCNTLO);
688: outb_p(count >> 8, nic_base + EN0_RCNTHI);
689: outb_p(0x00, nic_base + EN0_RSARLO);
690: outb_p(start_page, nic_base + EN0_RSARHI);
691:
692: outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
693: if (ei_status.word16) {
694: outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
695: } else {
696: outsb(NE_BASE + NE_DATAPORT, buf, count);
697: }
698:
699: dma_start = jiffies;
700:
701: #ifdef NE_SANITY_CHECK
702: /* This was for the ALPHA version only, but enough people have
703: been encountering problems so it is still here. */
704: if (ei_debug > 1) { /* DMA termination address check... */
705: int addr, tries = 20;
706: do {
707: int high = inb_p(nic_base + EN0_RSARHI);
708: int low = inb_p(nic_base + EN0_RSARLO);
709: addr = (high << 8) + low;
710: if ((start_page << 8) + count == addr)
711: break;
712: } while (--tries > 0);
713: if (tries <= 0) {
714: printk("%s: Tx packet transfer address mismatch,"
715: "%#4.4x (expected) vs. %#4.4x (actual).\n",
716: dev->name, (start_page << 8) + count, addr);
717: if (retries++ == 0)
718: goto retry;
719: }
720: }
721: #endif
722:
723: while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
724: if (jiffies - dma_start > 2*HZ/100) { /* 20ms */
725: printk("%s: timeout waiting for Tx RDC.\n", dev->name);
726: ne_reset_8390(dev);
727: NS8390_init(dev,1);
728: break;
729: }
730:
731: outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
732: ei_status.dmaing &= ~0x01;
733: return;
734: }
735:
736:
737: #ifdef MODULE
738: #define MAX_NE_CARDS 4 /* Max number of NE cards per module */
739: #define NAMELEN 8 /* # of chars for storing dev->name */
740: static char namelist[NAMELEN * MAX_NE_CARDS] = { 0, };
741: static struct device dev_ne[MAX_NE_CARDS] = {
742: {
743: NULL, /* assign a chunk of namelist[] below */
744: 0, 0, 0, 0,
745: 0, 0,
746: 0, 0, 0, NULL, NULL
747: },
748: };
749:
750: static int io[MAX_NE_CARDS] = { 0, };
751: static int irq[MAX_NE_CARDS] = { 0, };
752: static int bad[MAX_NE_CARDS] = { 0, };
753:
754: /* This is set up so that no autoprobe takes place. We can't guarantee
755: that the ne2k probe is the last 8390 based probe to take place (as it
756: is at boot) and so the probe will get confused by any other 8390 cards.
757: ISA device autoprobes on a running machine are not recommended anyway. */
758:
759: int
760: init_module(void)
761: {
762: int this_dev, found = 0;
763:
764: for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
765: struct device *dev = &dev_ne[this_dev];
766: dev->name = namelist+(NAMELEN*this_dev);
767: dev->irq = irq[this_dev];
768: dev->base_addr = io[this_dev];
769: dev->init = ne_probe;
770: dev->mem_end = bad[this_dev];
771: if (register_netdev(dev) == 0) {
772: found++;
773: continue;
774: }
775: if (found != 0) /* Got at least one. */
776: return 0;
777: if (io[this_dev] != 0)
778: printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", io[this_dev]);
779: else
780: printk(KERN_NOTICE "ne.c: No PCI cards found. Use \"io=0xNNN\" value(s) for ISA cards.\n");
781: return -ENXIO;
782: }
783:
784: return 0;
785: }
786:
787: void
788: cleanup_module(void)
789: {
790: int this_dev;
791:
792: for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
793: struct device *dev = &dev_ne[this_dev];
794: if (dev->priv != NULL) {
795: kfree(dev->priv);
796: dev->priv = NULL;
797: free_irq(dev->irq, dev);
798: irq2dev_map[dev->irq] = NULL;
799: release_region(dev->base_addr, NE_IO_EXTENT);
800: unregister_netdev(dev);
801: }
802: }
803: }
804: #endif /* MODULE */
805:
806: /*
807: * Local variables:
808: * compile-command: "gcc -DKERNEL -Wall -O6 -fomit-frame-pointer -I/usr/src/linux/net/tcp -c ne.c"
809: * version-control: t
810: * kept-new-versions: 5
811: * End:
812: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.