1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48static const char version[] =
49 "es3210.c: Driver revision v0.03, 14/09/96\n";
50
51#include <linux/module.h>
52#include <linux/eisa.h>
53#include <linux/kernel.h>
54#include <linux/errno.h>
55#include <linux/string.h>
56#include <linux/init.h>
57#include <linux/netdevice.h>
58#include <linux/etherdevice.h>
59
60#include <asm/io.h>
61#include <asm/system.h>
62
63#include "8390.h"
64
65static int es_probe1(struct net_device *dev, int ioaddr);
66
67static void es_reset_8390(struct net_device *dev);
68
69static void es_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
70static void es_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
71static void es_block_output(struct net_device *dev, int count, const unsigned char *buf, int start_page);
72
73#define ES_START_PG 0x00
74#define ES_STOP_PG 0x40
75
76#define ES_IO_EXTENT 0x37
77#define ES_ID_PORT 0xc80
78#define ES_SA_PROM 0xc90
79#define ES_RESET_PORT 0xc84
80#define ES_NIC_OFFSET 0xca0
81
82#define ES_ADDR0 0x02
83#define ES_ADDR1 0x07
84#define ES_ADDR2 0x01
85
86
87
88
89
90
91
92#define ES_EISA_ID1 0x01012949
93#define ES_EISA_ID2 0x02012949
94
95#define ES_CFG1 0xcc0
96#define ES_CFG2 0xcc1
97#define ES_CFG3 0xcc2
98#define ES_CFG4 0xcc3
99#define ES_CFG5 0xcc4
100#define ES_CFG6 0xc84
101
102
103
104
105
106
107
108#define ES_D_PROBE 0x01
109#define ES_D_RX_PKT 0x02
110#define ES_D_TX_PKT 0x04
111#define ED_D_IRQ 0x08
112
113#define ES_DEBUG 0
114
115static unsigned char lo_irq_map[] __initdata = {3, 4, 5, 6, 7, 9, 10};
116static unsigned char hi_irq_map[] __initdata = {11, 12, 0, 14, 0, 0, 0, 15};
117
118
119
120
121
122
123
124static int __init do_es_probe(struct net_device *dev)
125{
126 unsigned short ioaddr = dev->base_addr;
127 int irq = dev->irq;
128 int mem_start = dev->mem_start;
129
130 if (ioaddr > 0x1ff)
131 return es_probe1(dev, ioaddr);
132 else if (ioaddr > 0)
133 return -ENXIO;
134
135 if (!EISA_bus) {
136#if ES_DEBUG & ES_D_PROBE
137 printk("es3210.c: Not EISA bus. Not probing high ports.\n");
138#endif
139 return -ENXIO;
140 }
141
142
143 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
144 if (es_probe1(dev, ioaddr) == 0)
145 return 0;
146 dev->irq = irq;
147 dev->mem_start = mem_start;
148 }
149
150 return -ENODEV;
151}
152
153#ifndef MODULE
154struct net_device * __init es_probe(int unit)
155{
156 struct net_device *dev = alloc_ei_netdev();
157 int err;
158
159 if (!dev)
160 return ERR_PTR(-ENOMEM);
161
162 sprintf(dev->name, "eth%d", unit);
163 netdev_boot_setup_check(dev);
164
165 err = do_es_probe(dev);
166 if (err)
167 goto out;
168 return dev;
169out:
170 free_netdev(dev);
171 return ERR_PTR(err);
172}
173#endif
174
175static int __init es_probe1(struct net_device *dev, int ioaddr)
176{
177 int i, retval;
178 unsigned long eisa_id;
179
180 if (!request_region(ioaddr + ES_SA_PROM, ES_IO_EXTENT, "es3210"))
181 return -ENODEV;
182
183#if ES_DEBUG & ES_D_PROBE
184 printk("es3210.c: probe at %#x, ID %#8x\n", ioaddr, inl(ioaddr + ES_ID_PORT));
185 printk("es3210.c: config regs: %#x %#x %#x %#x %#x %#x\n",
186 inb(ioaddr + ES_CFG1), inb(ioaddr + ES_CFG2), inb(ioaddr + ES_CFG3),
187 inb(ioaddr + ES_CFG4), inb(ioaddr + ES_CFG5), inb(ioaddr + ES_CFG6));
188#endif
189
190
191 eisa_id = inl(ioaddr + ES_ID_PORT);
192 if ((eisa_id != ES_EISA_ID1) && (eisa_id != ES_EISA_ID2)) {
193 retval = -ENODEV;
194 goto out;
195 }
196
197 for (i = 0; i < ETHER_ADDR_LEN ; i++)
198 dev->dev_addr[i] = inb(ioaddr + ES_SA_PROM + i);
199
200
201 if (dev->dev_addr[0] != ES_ADDR0 ||
202 dev->dev_addr[1] != ES_ADDR1 ||
203 dev->dev_addr[2] != ES_ADDR2) {
204 printk("es3210.c: card not found %pM (invalid_prefix).\n",
205 dev->dev_addr);
206 retval = -ENODEV;
207 goto out;
208 }
209
210 printk("es3210.c: ES3210 rev. %ld at %#x, node %pM",
211 eisa_id>>24, ioaddr, dev->dev_addr);
212
213
214 if (dev->irq == 0) {
215 unsigned char hi_irq = inb(ioaddr + ES_CFG2) & 0x07;
216 unsigned char lo_irq = inb(ioaddr + ES_CFG1) & 0xfe;
217
218 if (hi_irq != 0) {
219 dev->irq = hi_irq_map[hi_irq - 1];
220 } else {
221 int i = 0;
222 while (lo_irq > (1<<i)) i++;
223 dev->irq = lo_irq_map[i];
224 }
225 printk(" using IRQ %d", dev->irq);
226#if ES_DEBUG & ES_D_PROBE
227 printk("es3210.c: hi_irq %#x, lo_irq %#x, dev->irq = %d\n",
228 hi_irq, lo_irq, dev->irq);
229#endif
230 } else {
231 if (dev->irq == 2)
232 dev->irq = 9;
233 printk(" assigning IRQ %d", dev->irq);
234 }
235
236 if (request_irq(dev->irq, ei_interrupt, 0, "es3210", dev)) {
237 printk (" unable to get IRQ %d.\n", dev->irq);
238 retval = -EAGAIN;
239 goto out;
240 }
241
242 if (dev->mem_start == 0) {
243 unsigned char mem_enabled = inb(ioaddr + ES_CFG2) & 0xc0;
244 unsigned char mem_bits = inb(ioaddr + ES_CFG3) & 0x07;
245
246 if (mem_enabled != 0x80) {
247 printk(" shared mem disabled - giving up\n");
248 retval = -ENXIO;
249 goto out1;
250 }
251 dev->mem_start = 0xC0000 + mem_bits*0x4000;
252 printk(" using ");
253 } else {
254 printk(" assigning ");
255 }
256
257 ei_status.mem = ioremap(dev->mem_start, (ES_STOP_PG - ES_START_PG)*256);
258 if (!ei_status.mem) {
259 printk("ioremap failed - giving up\n");
260 retval = -ENXIO;
261 goto out1;
262 }
263
264 dev->mem_end = dev->mem_start + (ES_STOP_PG - ES_START_PG)*256;
265
266 printk("mem %#lx-%#lx\n", dev->mem_start, dev->mem_end-1);
267
268#if ES_DEBUG & ES_D_PROBE
269 if (inb(ioaddr + ES_CFG5))
270 printk("es3210: Warning - DMA channel enabled, but not used here.\n");
271#endif
272
273 dev->base_addr = ioaddr + ES_NIC_OFFSET;
274
275 ei_status.name = "ES3210";
276 ei_status.tx_start_page = ES_START_PG;
277 ei_status.rx_start_page = ES_START_PG + TX_PAGES;
278 ei_status.stop_page = ES_STOP_PG;
279 ei_status.word16 = 1;
280
281 if (ei_debug > 0)
282 printk(version);
283
284 ei_status.reset_8390 = &es_reset_8390;
285 ei_status.block_input = &es_block_input;
286 ei_status.block_output = &es_block_output;
287 ei_status.get_8390_hdr = &es_get_8390_hdr;
288
289 dev->netdev_ops = &ei_netdev_ops;
290 NS8390_init(dev, 0);
291
292 retval = register_netdev(dev);
293 if (retval)
294 goto out1;
295 return 0;
296out1:
297 free_irq(dev->irq, dev);
298out:
299 release_region(ioaddr + ES_SA_PROM, ES_IO_EXTENT);
300 return retval;
301}
302
303
304
305
306
307
308static void es_reset_8390(struct net_device *dev)
309{
310 unsigned short ioaddr = dev->base_addr;
311 unsigned long end;
312
313 outb(0x04, ioaddr + ES_RESET_PORT);
314 if (ei_debug > 1) printk("%s: resetting the ES3210...", dev->name);
315
316 end = jiffies + 2*HZ/100;
317 while ((signed)(end - jiffies) > 0) continue;
318
319 ei_status.txing = 0;
320 outb(0x01, ioaddr + ES_RESET_PORT);
321 if (ei_debug > 1) printk("reset done\n");
322
323 return;
324}
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341static void
342es_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
343{
344 void __iomem *hdr_start = ei_status.mem + ((ring_page - ES_START_PG)<<8);
345 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
346 hdr->count = (hdr->count + 3) & ~3;
347}
348
349
350
351
352
353
354
355static void es_block_input(struct net_device *dev, int count, struct sk_buff *skb,
356 int ring_offset)
357{
358 void __iomem *xfer_start = ei_status.mem + ring_offset - ES_START_PG*256;
359
360 if (ring_offset + count > ES_STOP_PG*256) {
361
362 int semi_count = ES_STOP_PG*256 - ring_offset;
363 memcpy_fromio(skb->data, xfer_start, semi_count);
364 count -= semi_count;
365 memcpy_fromio(skb->data + semi_count, ei_status.mem, count);
366 } else {
367
368 memcpy_fromio(skb->data, xfer_start, count);
369 }
370}
371
372static void es_block_output(struct net_device *dev, int count,
373 const unsigned char *buf, int start_page)
374{
375 void __iomem *shmem = ei_status.mem + ((start_page - ES_START_PG)<<8);
376
377 count = (count + 3) & ~3;
378 memcpy_toio(shmem, buf, count);
379}
380
381#ifdef MODULE
382#define MAX_ES_CARDS 4
383#define NAMELEN 8
384static struct net_device *dev_es3210[MAX_ES_CARDS];
385static int io[MAX_ES_CARDS];
386static int irq[MAX_ES_CARDS];
387static int mem[MAX_ES_CARDS];
388
389module_param_array(io, int, NULL, 0);
390module_param_array(irq, int, NULL, 0);
391module_param_array(mem, int, NULL, 0);
392MODULE_PARM_DESC(io, "I/O base address(es)");
393MODULE_PARM_DESC(irq, "IRQ number(s)");
394MODULE_PARM_DESC(mem, "memory base address(es)");
395MODULE_DESCRIPTION("Racal-Interlan ES3210 EISA ethernet driver");
396MODULE_LICENSE("GPL");
397
398int __init init_module(void)
399{
400 struct net_device *dev;
401 int this_dev, found = 0;
402
403 for (this_dev = 0; this_dev < MAX_ES_CARDS; this_dev++) {
404 if (io[this_dev] == 0 && this_dev != 0)
405 break;
406 dev = alloc_ei_netdev();
407 if (!dev)
408 break;
409 dev->irq = irq[this_dev];
410 dev->base_addr = io[this_dev];
411 dev->mem_start = mem[this_dev];
412 if (do_es_probe(dev) == 0) {
413 dev_es3210[found++] = dev;
414 continue;
415 }
416 free_netdev(dev);
417 printk(KERN_WARNING "es3210.c: No es3210 card found (i/o = 0x%x).\n", io[this_dev]);
418 break;
419 }
420 if (found)
421 return 0;
422 return -ENXIO;
423}
424
425static void cleanup_card(struct net_device *dev)
426{
427 free_irq(dev->irq, dev);
428 release_region(dev->base_addr, ES_IO_EXTENT);
429 iounmap(ei_status.mem);
430}
431
432void __exit
433cleanup_module(void)
434{
435 int this_dev;
436
437 for (this_dev = 0; this_dev < MAX_ES_CARDS; this_dev++) {
438 struct net_device *dev = dev_es3210[this_dev];
439 if (dev) {
440 unregister_netdev(dev);
441 cleanup_card(dev);
442 free_netdev(dev);
443 }
444 }
445}
446#endif
447
448