blob: 38fd525f0f132b1bb0d606d6008a39b83a7f4827 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* ne-h8300.c: A NE2000 clone on H8/300 driver for linux. */
2/*
3 original ne.c
4 Written 1992-94 by Donald Becker.
5
6 Copyright 1993 United States Government as represented by the
7 Director, National Security Agency.
8
9 This software may be used and distributed according to the terms
10 of the GNU General Public License, incorporated herein by reference.
11
12 The author may be reached as becker@scyld.com, or C/O
13 Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
14
15 H8/300 modified
16 Yoshinori Sato <ysato@users.sourceforge.jp>
17*/
18
19static const char version1[] =
20"ne-h8300.c:v1.00 2004/04/11 ysato\n";
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/errno.h>
25#include <linux/init.h>
26#include <linux/interrupt.h>
27#include <linux/delay.h>
28#include <linux/netdevice.h>
29#include <linux/etherdevice.h>
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -080030#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <asm/system.h>
33#include <asm/io.h>
34#include <asm/irq.h>
35
Al Viro3470cb12006-10-10 00:19:36 +010036#define EI_SHIFT(x) (ei_local->reg_offset[x])
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include "8390.h"
39
40#define DRV_NAME "ne-h8300"
41
42/* Some defines that people can play with if so inclined. */
43
44/* Do we perform extra sanity checks on stuff ? */
45/* #define NE_SANITY_CHECK */
46
47/* Do we implement the read before write bugfix ? */
48/* #define NE_RW_BUGFIX */
49
50/* Do we have a non std. amount of memory? (in units of 256 byte pages) */
51/* #define PACKETBUF_MEMSIZE 0x40 */
52
53/* A zero-terminated list of I/O addresses to be probed at boot. */
54
55/* ---- No user-serviceable parts below ---- */
56
Al Viro3470cb12006-10-10 00:19:36 +010057static const char version[] =
58 "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
59
60#include "lib8390.c"
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define NE_BASE (dev->base_addr)
63#define NE_CMD 0x00
64#define NE_DATAPORT (ei_status.word16?0x20:0x10) /* NatSemi-defined port window offset. */
65#define NE_RESET (ei_status.word16?0x3f:0x1f) /* Issue a read to reset, a write to clear. */
66#define NE_IO_EXTENT (ei_status.word16?0x40:0x20)
67
68#define NESM_START_PG 0x40 /* First page of TX buffer */
69#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
70
71static int ne_probe1(struct net_device *dev, int ioaddr);
72
73static int ne_open(struct net_device *dev);
74static int ne_close(struct net_device *dev);
75
76static void ne_reset_8390(struct net_device *dev);
77static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
78 int ring_page);
79static void ne_block_input(struct net_device *dev, int count,
80 struct sk_buff *skb, int ring_offset);
81static void ne_block_output(struct net_device *dev, const int count,
82 const unsigned char *buf, const int start_page);
83
84
85static u32 reg_offset[16];
86
87static int __init init_reg_offset(struct net_device *dev,unsigned long base_addr)
88{
89 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
90 int i;
91 unsigned char bus_width;
92
93 bus_width = *(volatile unsigned char *)ABWCR;
94 bus_width &= 1 << ((base_addr >> 21) & 7);
95
96 for (i = 0; i < sizeof(reg_offset) / sizeof(u32); i++)
97 if (bus_width == 0)
98 reg_offset[i] = i * 2 + 1;
99 else
100 reg_offset[i] = i;
101
102 ei_local->reg_offset = reg_offset;
103 return 0;
104}
105
106static int __initdata h8300_ne_count = 0;
107#ifdef CONFIG_H8300H_H8MAX
108static unsigned long __initdata h8300_ne_base[] = { 0x800600 };
109static int h8300_ne_irq[] = {EXT_IRQ4};
110#endif
111#ifdef CONFIG_H8300H_AKI3068NET
112static unsigned long __initdata h8300_ne_base[] = { 0x200000 };
113static int h8300_ne_irq[] = {EXT_IRQ5};
114#endif
115
116static inline int init_dev(struct net_device *dev)
117{
118 if (h8300_ne_count < (sizeof(h8300_ne_base) / sizeof(unsigned long))) {
119 dev->base_addr = h8300_ne_base[h8300_ne_count];
120 dev->irq = h8300_ne_irq[h8300_ne_count];
121 h8300_ne_count++;
122 return 0;
123 } else
124 return -ENODEV;
125}
126
127/* Probe for various non-shared-memory ethercards.
128
129 NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
130 buffer memory space. NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
131 the SAPROM, while other supposed NE2000 clones must be detected by their
132 SA prefix.
133
134 Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
135 mode results in doubled values, which can be detected and compensated for.
136
137 The probe is also responsible for initializing the card and filling
138 in the 'dev' and 'ei_status' structures.
139
140 We use the minimum memory size for some ethercard product lines, iff we can't
141 distinguish models. You can increase the packet buffer size by setting
142 PACKETBUF_MEMSIZE. Reported Cabletron packet buffer locations are:
143 E1010 starts at 0x100 and ends at 0x2000.
144 E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
145 E2010 starts at 0x100 and ends at 0x4000.
146 E2010-x starts at 0x100 and ends at 0xffff. */
147
148static int __init do_ne_probe(struct net_device *dev)
149{
150 unsigned int base_addr = dev->base_addr;
151
152 SET_MODULE_OWNER(dev);
153
154 /* First check any supplied i/o locations. User knows best. <cough> */
155 if (base_addr > 0x1ff) /* Check a single specified location. */
156 return ne_probe1(dev, base_addr);
157 else if (base_addr != 0) /* Don't probe at all. */
158 return -ENXIO;
159
160 return -ENODEV;
161}
162
163static void cleanup_card(struct net_device *dev)
164{
165 free_irq(dev->irq, dev);
166 release_region(dev->base_addr, NE_IO_EXTENT);
167}
168
169#ifndef MODULE
170struct net_device * __init ne_probe(int unit)
171{
Al Viro3470cb12006-10-10 00:19:36 +0100172 struct net_device *dev = ____alloc_ei_netdev(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 int err;
174
175 if (!dev)
176 return ERR_PTR(-ENOMEM);
177
178 if (init_dev(dev))
179 return ERR_PTR(-ENODEV);
180
181 sprintf(dev->name, "eth%d", unit);
182 netdev_boot_setup_check(dev);
183
184 err = init_reg_offset(dev, dev->base_addr);
185 if (err)
186 goto out;
187
188 err = do_ne_probe(dev);
189 if (err)
190 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192out:
193 free_netdev(dev);
194 return ERR_PTR(err);
195}
196#endif
197
198static int __init ne_probe1(struct net_device *dev, int ioaddr)
199{
200 int i;
201 unsigned char SA_prom[16];
202 int wordlength = 2;
203 const char *name = NULL;
204 int start_page, stop_page;
205 int reg0, ret;
206 static unsigned version_printed;
207 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
208 unsigned char bus_width;
209
210 if (!request_region(ioaddr, NE_IO_EXTENT, DRV_NAME))
211 return -EBUSY;
212
213 reg0 = inb_p(ioaddr);
214 if (reg0 == 0xFF) {
215 ret = -ENODEV;
216 goto err_out;
217 }
218
219 /* Do a preliminary verification that we have a 8390. */
220 {
221 int regd;
222 outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
223 regd = inb_p(ioaddr + EI_SHIFT(0x0d));
224 outb_p(0xff, ioaddr + EI_SHIFT(0x0d));
225 outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
226 inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
227 if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
228 outb_p(reg0, ioaddr + EI_SHIFT(0));
229 outb_p(regd, ioaddr + EI_SHIFT(0x0d)); /* Restore the old values. */
230 ret = -ENODEV;
231 goto err_out;
232 }
233 }
234
235 if (ei_debug && version_printed++ == 0)
236 printk(KERN_INFO "%s", version1);
237
238 printk(KERN_INFO "NE*000 ethercard probe at %08x:", ioaddr);
239
240 /* Read the 16 bytes of station address PROM.
241 We must first initialize registers, similar to NS8390_init(eifdev, 0).
242 We can't reliably read the SAPROM address without this.
243 (I learned the hard way!). */
244 {
245 struct {unsigned char value, offset; } program_seq[] =
246 {
247 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
248 {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
249 {0x00, EN0_RCNTLO}, /* Clear the count regs. */
250 {0x00, EN0_RCNTHI},
251 {0x00, EN0_IMR}, /* Mask completion irq. */
252 {0xFF, EN0_ISR},
253 {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
254 {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
255 {32, EN0_RCNTLO},
256 {0x00, EN0_RCNTHI},
257 {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
258 {0x00, EN0_RSARHI},
259 {E8390_RREAD+E8390_START, E8390_CMD},
260 };
261
262 for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
263 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
264
265 }
266 bus_width = *(volatile unsigned char *)ABWCR;
267 bus_width &= 1 << ((ioaddr >> 21) & 7);
268 ei_status.word16 = (bus_width == 0); /* temporary setting */
269 for(i = 0; i < 16 /*sizeof(SA_prom)*/; i++) {
270 SA_prom[i] = inb_p(ioaddr + NE_DATAPORT);
271 inb_p(ioaddr + NE_DATAPORT); /* dummy read */
272 }
273
274 start_page = NESM_START_PG;
275 stop_page = NESM_STOP_PG;
276
277 if (bus_width)
278 wordlength = 1;
279 else
280 outb_p(0x49, ioaddr + EN0_DCFG);
281
282 /* Set up the rest of the parameters. */
283 name = (wordlength == 2) ? "NE2000" : "NE1000";
284
285 if (! dev->irq) {
286 printk(" failed to detect IRQ line.\n");
287 ret = -EAGAIN;
288 goto err_out;
289 }
290
291 /* Snarf the interrupt now. There's no point in waiting since we cannot
292 share and the board will usually be enabled. */
Al Viro3470cb12006-10-10 00:19:36 +0100293 ret = request_irq(dev->irq, __ei_interrupt, 0, name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 if (ret) {
295 printk (" unable to get IRQ %d (errno=%d).\n", dev->irq, ret);
296 goto err_out;
297 }
298
299 dev->base_addr = ioaddr;
300
301 for(i = 0; i < ETHER_ADDR_LEN; i++) {
302 printk(" %2.2x", SA_prom[i]);
303 dev->dev_addr[i] = SA_prom[i];
304 }
305
306 printk("\n%s: %s found at %#x, using IRQ %d.\n",
307 dev->name, name, ioaddr, dev->irq);
308
309 ei_status.name = name;
310 ei_status.tx_start_page = start_page;
311 ei_status.stop_page = stop_page;
312 ei_status.word16 = (wordlength == 2);
313
314 ei_status.rx_start_page = start_page + TX_PAGES;
315#ifdef PACKETBUF_MEMSIZE
316 /* Allow the packet buffer size to be overridden by know-it-alls. */
317 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
318#endif
319
320 ei_status.reset_8390 = &ne_reset_8390;
321 ei_status.block_input = &ne_block_input;
322 ei_status.block_output = &ne_block_output;
323 ei_status.get_8390_hdr = &ne_get_8390_hdr;
324 ei_status.priv = 0;
325 dev->open = &ne_open;
326 dev->stop = &ne_close;
327#ifdef CONFIG_NET_POLL_CONTROLLER
Al Viro3470cb12006-10-10 00:19:36 +0100328 dev->poll_controller = __ei_poll;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#endif
Al Viro3470cb12006-10-10 00:19:36 +0100330 __NS8390_init(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
b1fc5502005-05-12 20:11:55 -0400332 ret = register_netdev(dev);
333 if (ret)
334 goto out_irq;
335 return 0;
336out_irq:
337 free_irq(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338err_out:
339 release_region(ioaddr, NE_IO_EXTENT);
340 return ret;
341}
342
343static int ne_open(struct net_device *dev)
344{
Al Viro3470cb12006-10-10 00:19:36 +0100345 __ei_open(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return 0;
347}
348
349static int ne_close(struct net_device *dev)
350{
351 if (ei_debug > 1)
352 printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
Al Viro3470cb12006-10-10 00:19:36 +0100353 __ei_close(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return 0;
355}
356
357/* Hard reset the card. This used to pause for the same period that a
358 8390 reset command required, but that shouldn't be necessary. */
359
360static void ne_reset_8390(struct net_device *dev)
361{
362 unsigned long reset_start_time = jiffies;
363 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
364
365 if (ei_debug > 1)
366 printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies);
367
368 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
369 outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
370
371 ei_status.txing = 0;
372 ei_status.dmaing = 0;
373
374 /* This check _should_not_ be necessary, omit eventually. */
375 while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800376 if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 printk(KERN_WARNING "%s: ne_reset_8390() did not complete.\n", dev->name);
378 break;
379 }
380 outb_p(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */
381}
382
383/* Grab the 8390 specific header. Similar to the block_input routine, but
384 we don't need to be concerned with ring wrap as the header will be at
385 the start of a page, so we optimize accordingly. */
386
387static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
388{
389 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
390 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
391
392 if (ei_status.dmaing)
393 {
394 printk(KERN_EMERG "%s: DMAing conflict in ne_get_8390_hdr "
395 "[DMAstat:%d][irqlock:%d].\n",
396 dev->name, ei_status.dmaing, ei_status.irqlock);
397 return;
398 }
399
400 ei_status.dmaing |= 0x01;
401 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, NE_BASE + NE_CMD);
402 outb_p(sizeof(struct e8390_pkt_hdr), NE_BASE + EN0_RCNTLO);
403 outb_p(0, NE_BASE + EN0_RCNTHI);
404 outb_p(0, NE_BASE + EN0_RSARLO); /* On page boundary */
405 outb_p(ring_page, NE_BASE + EN0_RSARHI);
406 outb_p(E8390_RREAD+E8390_START, NE_BASE + NE_CMD);
407
408 if (ei_status.word16) {
409 int len;
410 unsigned short *p = (unsigned short *)hdr;
411 for (len = sizeof(struct e8390_pkt_hdr)>>1; len > 0; len--)
412 *p++ = inw(NE_BASE + NE_DATAPORT);
413 } else
414 insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
415
416 outb_p(ENISR_RDC, NE_BASE + EN0_ISR); /* Ack intr. */
417 ei_status.dmaing &= ~0x01;
418
419 le16_to_cpus(&hdr->count);
420}
421
422/* Block input and output, similar to the Crynwr packet driver. If you
423 are porting to a new ethercard, look at the packet driver source for hints.
424 The NEx000 doesn't share the on-board packet memory -- you have to put
425 the packet out through the "remote DMA" dataport using outb. */
426
427static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
428{
429 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
430#ifdef NE_SANITY_CHECK
431 int xfer_count = count;
432#endif
433 char *buf = skb->data;
434
435 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
436 if (ei_status.dmaing)
437 {
438 printk(KERN_EMERG "%s: DMAing conflict in ne_block_input "
439 "[DMAstat:%d][irqlock:%d].\n",
440 dev->name, ei_status.dmaing, ei_status.irqlock);
441 return;
442 }
443 ei_status.dmaing |= 0x01;
444 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, NE_BASE + NE_CMD);
445 outb_p(count & 0xff, NE_BASE + EN0_RCNTLO);
446 outb_p(count >> 8, NE_BASE + EN0_RCNTHI);
447 outb_p(ring_offset & 0xff, NE_BASE + EN0_RSARLO);
448 outb_p(ring_offset >> 8, NE_BASE + EN0_RSARHI);
449 outb_p(E8390_RREAD+E8390_START, NE_BASE + NE_CMD);
450 if (ei_status.word16)
451 {
452 int len;
453 unsigned short *p = (unsigned short *)buf;
454 for (len = count>>1; len > 0; len--)
455 *p++ = inw(NE_BASE + NE_DATAPORT);
456 if (count & 0x01)
457 {
458 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
459#ifdef NE_SANITY_CHECK
460 xfer_count++;
461#endif
462 }
463 } else {
464 insb(NE_BASE + NE_DATAPORT, buf, count);
465 }
466
467#ifdef NE_SANITY_CHECK
468 /* This was for the ALPHA version only, but enough people have
469 been encountering problems so it is still here. If you see
470 this message you either 1) have a slightly incompatible clone
471 or 2) have noise/speed problems with your bus. */
472
473 if (ei_debug > 1)
474 {
475 /* DMA termination address check... */
476 int addr, tries = 20;
477 do {
478 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
479 -- it's broken for Rx on some cards! */
480 int high = inb_p(NE_BASE + EN0_RSARHI);
481 int low = inb_p(NE_BASE + EN0_RSARLO);
482 addr = (high << 8) + low;
483 if (((ring_offset + xfer_count) & 0xff) == low)
484 break;
485 } while (--tries > 0);
486 if (tries <= 0)
487 printk(KERN_WARNING "%s: RX transfer address mismatch,"
488 "%#4.4x (expected) vs. %#4.4x (actual).\n",
489 dev->name, ring_offset + xfer_count, addr);
490 }
491#endif
492 outb_p(ENISR_RDC, NE_BASE + EN0_ISR); /* Ack intr. */
493 ei_status.dmaing &= ~0x01;
494}
495
496static void ne_block_output(struct net_device *dev, int count,
497 const unsigned char *buf, const int start_page)
498{
499 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
500 unsigned long dma_start;
501#ifdef NE_SANITY_CHECK
502 int retries = 0;
503#endif
504
505 /* Round the count up for word writes. Do we need to do this?
506 What effect will an odd byte count have on the 8390?
507 I should check someday. */
508
509 if (ei_status.word16 && (count & 0x01))
510 count++;
511
512 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
513 if (ei_status.dmaing)
514 {
515 printk(KERN_EMERG "%s: DMAing conflict in ne_block_output."
516 "[DMAstat:%d][irqlock:%d]\n",
517 dev->name, ei_status.dmaing, ei_status.irqlock);
518 return;
519 }
520 ei_status.dmaing |= 0x01;
521 /* We should already be in page 0, but to be safe... */
522 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, NE_BASE + NE_CMD);
523
524#ifdef NE_SANITY_CHECK
525retry:
526#endif
527
528#ifdef NE8390_RW_BUGFIX
529 /* Handle the read-before-write bug the same way as the
530 Crynwr packet driver -- the NatSemi method doesn't work.
531 Actually this doesn't always work either, but if you have
532 problems with your NEx000 this is better than nothing! */
533
534 outb_p(0x42, NE_BASE + EN0_RCNTLO);
535 outb_p(0x00, NE_BASE + EN0_RCNTHI);
536 outb_p(0x42, NE_BASE + EN0_RSARLO);
537 outb_p(0x00, NE_BASE + EN0_RSARHI);
538 outb_p(E8390_RREAD+E8390_START, NE_BASE + NE_CMD);
539 /* Make certain that the dummy read has occurred. */
540 udelay(6);
541#endif
542
543 outb_p(ENISR_RDC, NE_BASE + EN0_ISR);
544
545 /* Now the normal output. */
546 outb_p(count & 0xff, NE_BASE + EN0_RCNTLO);
547 outb_p(count >> 8, NE_BASE + EN0_RCNTHI);
548 outb_p(0x00, NE_BASE + EN0_RSARLO);
549 outb_p(start_page, NE_BASE + EN0_RSARHI);
550
551 outb_p(E8390_RWRITE+E8390_START, NE_BASE + NE_CMD);
552 if (ei_status.word16) {
553 int len;
554 unsigned short *p = (unsigned short *)buf;
555 for (len = count>>1; len > 0; len--)
556 outw(*p++, NE_BASE + NE_DATAPORT);
557 } else {
558 outsb(NE_BASE + NE_DATAPORT, buf, count);
559 }
560
561 dma_start = jiffies;
562
563#ifdef NE_SANITY_CHECK
564 /* This was for the ALPHA version only, but enough people have
565 been encountering problems so it is still here. */
566
567 if (ei_debug > 1)
568 {
569 /* DMA termination address check... */
570 int addr, tries = 20;
571 do {
572 int high = inb_p(NE_BASE + EN0_RSARHI);
573 int low = inb_p(NE_BASE + EN0_RSARLO);
574 addr = (high << 8) + low;
575 if ((start_page << 8) + count == addr)
576 break;
577 } while (--tries > 0);
578
579 if (tries <= 0)
580 {
581 printk(KERN_WARNING "%s: Tx packet transfer address mismatch,"
582 "%#4.4x (expected) vs. %#4.4x (actual).\n",
583 dev->name, (start_page << 8) + count, addr);
584 if (retries++ == 0)
585 goto retry;
586 }
587 }
588#endif
589
590 while ((inb_p(NE_BASE + EN0_ISR) & ENISR_RDC) == 0)
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800591 if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name);
593 ne_reset_8390(dev);
Al Viro3470cb12006-10-10 00:19:36 +0100594 __NS8390_init(dev,1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 break;
596 }
597
598 outb_p(ENISR_RDC, NE_BASE + EN0_ISR); /* Ack intr. */
599 ei_status.dmaing &= ~0x01;
600 return;
601}
602
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#ifdef MODULE
605#define MAX_NE_CARDS 1 /* Max number of NE cards per module */
606static struct net_device *dev_ne[MAX_NE_CARDS];
607static int io[MAX_NE_CARDS];
608static int irq[MAX_NE_CARDS];
609static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */
610
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800611module_param_array(io, int, NULL, 0);
612module_param_array(irq, int, NULL, 0);
613module_param_array(bad, int, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614MODULE_PARM_DESC(io, "I/O base address(es)");
615MODULE_PARM_DESC(irq, "IRQ number(s)");
616MODULE_DESCRIPTION("H8/300 NE2000 Ethernet driver");
617MODULE_LICENSE("GPL");
618
619/* This is set up so that no ISA autoprobe takes place. We can't guarantee
620that the ne2k probe is the last 8390 based probe to take place (as it
621is at boot) and so the probe will get confused by any other 8390 cards.
622ISA device autoprobes on a running machine are not recommended anyway. */
623
624int init_module(void)
625{
626 int this_dev, found = 0;
627 int err;
628
629 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
Al Viro3470cb12006-10-10 00:19:36 +0100630 struct net_device *dev = ____alloc_ei_netdev(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 if (!dev)
632 break;
633 if (io[this_dev]) {
634 dev->irq = irq[this_dev];
635 dev->mem_end = bad[this_dev];
636 dev->base_addr = io[this_dev];
637 } else {
638 dev->base_addr = h8300_ne_base[this_dev];
639 dev->irq = h8300_ne_irq[this_dev];
640 }
641 err = init_reg_offset(dev, dev->base_addr);
642 if (!err) {
643 if (do_ne_probe(dev) == 0) {
b1fc5502005-05-12 20:11:55 -0400644 dev_ne[found++] = dev;
645 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 }
647 }
648 free_netdev(dev);
649 if (found)
650 break;
651 if (io[this_dev] != 0)
652 printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", dev->base_addr);
653 else
654 printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n");
655 return -ENXIO;
656 }
657 if (found)
658 return 0;
659 return -ENODEV;
660}
661
662void cleanup_module(void)
663{
664 int this_dev;
665
666 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
667 struct net_device *dev = dev_ne[this_dev];
668 if (dev) {
669 unregister_netdev(dev);
670 cleanup_card(dev);
671 free_netdev(dev);
672 }
673 }
674}
675#endif /* MODULE */