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