]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | lne390.c | |
3 | ||
4 | Linux driver for Mylex LNE390 EISA Network Adapter | |
5 | ||
6 | Copyright (C) 1996-1998, Paul Gortmaker. | |
7 | ||
8 | This software may be used and distributed according to the terms | |
9 | of the GNU General Public License, incorporated herein by reference. | |
10 | ||
11 | Information and Code Sources: | |
12 | ||
13 | 1) Based upon framework of es3210 driver. | |
14 | 2) The existing myriad of other Linux 8390 drivers by Donald Becker. | |
15 | 3) Russ Nelson's asm packet driver provided additional info. | |
16 | 4) Info for getting IRQ and sh-mem gleaned from the EISA cfg files. | |
17 | ||
18 | The LNE390 is an EISA shared memory NS8390 implementation. Note | |
19 | that all memory copies to/from the board must be 32bit transfers. | |
20 | There are two versions of the card: the lne390a and the lne390b. | |
21 | Going by the EISA cfg files, the "a" has jumpers to select between | |
22 | BNC/AUI, but the "b" also has RJ-45 and selection is via the SCU. | |
23 | The shared memory address selection is also slightly different. | |
24 | Note that shared memory address > 1MB are supported with this driver. | |
25 | ||
26 | You can try <http://www.mylex.com> if you want more info, as I've | |
27 | never even seen one of these cards. :) | |
28 | ||
29 | Arnaldo Carvalho de Melo <[email protected]> - 2000/09/01 | |
30 | - get rid of check_region | |
31 | - no need to check if dev == NULL in lne390_probe1 | |
32 | */ | |
33 | ||
34 | static const char *version = | |
35 | "lne390.c: Driver revision v0.99.1, 01/09/2000\n"; | |
36 | ||
37 | #include <linux/module.h> | |
38 | #include <linux/eisa.h> | |
39 | #include <linux/kernel.h> | |
40 | #include <linux/errno.h> | |
41 | #include <linux/string.h> | |
42 | #include <linux/delay.h> | |
43 | #include <linux/init.h> | |
44 | #include <linux/netdevice.h> | |
45 | #include <linux/etherdevice.h> | |
46 | ||
47 | #include <asm/io.h> | |
48 | #include <asm/system.h> | |
49 | ||
50 | #include "8390.h" | |
51 | ||
52 | #define DRV_NAME "lne390" | |
53 | ||
54 | static int lne390_probe1(struct net_device *dev, int ioaddr); | |
55 | ||
56 | static int lne390_open(struct net_device *dev); | |
57 | static int lne390_close(struct net_device *dev); | |
58 | ||
59 | static void lne390_reset_8390(struct net_device *dev); | |
60 | ||
61 | static void lne390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page); | |
62 | static void lne390_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset); | |
63 | static void lne390_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page); | |
64 | ||
65 | #define LNE390_START_PG 0x00 /* First page of TX buffer */ | |
66 | #define LNE390_STOP_PG 0x80 /* Last page +1 of RX ring */ | |
67 | ||
68 | #define LNE390_ID_PORT 0xc80 /* Same for all EISA cards */ | |
69 | #define LNE390_IO_EXTENT 0x20 | |
70 | #define LNE390_SA_PROM 0x16 /* Start of e'net addr. */ | |
71 | #define LNE390_RESET_PORT 0xc84 /* From the pkt driver source */ | |
72 | #define LNE390_NIC_OFFSET 0x00 /* Hello, the 8390 is *here* */ | |
73 | ||
74 | #define LNE390_ADDR0 0x00 /* 3 byte vendor prefix */ | |
75 | #define LNE390_ADDR1 0x80 | |
76 | #define LNE390_ADDR2 0xe5 | |
77 | ||
78 | #define LNE390_ID0 0x10009835 /* 0x3598 = 01101 01100 11000 = mlx */ | |
79 | #define LNE390_ID1 0x11009835 /* above is the 390A, this is 390B */ | |
80 | ||
81 | #define LNE390_CFG1 0xc84 /* NB: 0xc84 is also "reset" port. */ | |
82 | #define LNE390_CFG2 0xc90 | |
83 | ||
84 | /* | |
85 | * You can OR any of the following bits together and assign it | |
86 | * to LNE390_DEBUG to get verbose driver info during operation. | |
87 | * Currently only the probe one is implemented. | |
88 | */ | |
89 | ||
90 | #define LNE390_D_PROBE 0x01 | |
91 | #define LNE390_D_RX_PKT 0x02 | |
92 | #define LNE390_D_TX_PKT 0x04 | |
93 | #define LNE390_D_IRQ 0x08 | |
94 | ||
95 | #define LNE390_DEBUG 0 | |
96 | ||
97 | static unsigned char irq_map[] __initdata = {15, 12, 11, 10, 9, 7, 5, 3}; | |
98 | static unsigned int shmem_mapA[] __initdata = {0xff, 0xfe, 0xfd, 0xfff, 0xffe, 0xffc, 0x0d, 0x0}; | |
99 | static unsigned int shmem_mapB[] __initdata = {0xff, 0xfe, 0x0e, 0xfff, 0xffe, 0xffc, 0x0d, 0x0}; | |
100 | ||
101 | /* | |
102 | * Probe for the card. The best way is to read the EISA ID if it | |
103 | * is known. Then we can check the prefix of the station address | |
104 | * PROM for a match against the value assigned to Mylex. | |
105 | */ | |
106 | ||
107 | static int __init do_lne390_probe(struct net_device *dev) | |
108 | { | |
109 | unsigned short ioaddr = dev->base_addr; | |
110 | int irq = dev->irq; | |
111 | int mem_start = dev->mem_start; | |
112 | int ret; | |
113 | ||
114 | SET_MODULE_OWNER(dev); | |
115 | ||
116 | if (ioaddr > 0x1ff) { /* Check a single specified location. */ | |
117 | if (!request_region(ioaddr, LNE390_IO_EXTENT, DRV_NAME)) | |
118 | return -EBUSY; | |
119 | ret = lne390_probe1(dev, ioaddr); | |
120 | if (ret) | |
121 | release_region(ioaddr, LNE390_IO_EXTENT); | |
122 | return ret; | |
123 | } | |
124 | else if (ioaddr > 0) /* Don't probe at all. */ | |
125 | return -ENXIO; | |
126 | ||
127 | if (!EISA_bus) { | |
128 | #if LNE390_DEBUG & LNE390_D_PROBE | |
129 | printk("lne390-debug: Not an EISA bus. Not probing high ports.\n"); | |
130 | #endif | |
131 | return -ENXIO; | |
132 | } | |
133 | ||
134 | /* EISA spec allows for up to 16 slots, but 8 is typical. */ | |
135 | for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) { | |
136 | if (!request_region(ioaddr, LNE390_IO_EXTENT, DRV_NAME)) | |
137 | continue; | |
138 | if (lne390_probe1(dev, ioaddr) == 0) | |
139 | return 0; | |
140 | release_region(ioaddr, LNE390_IO_EXTENT); | |
141 | dev->irq = irq; | |
142 | dev->mem_start = mem_start; | |
143 | } | |
144 | ||
145 | return -ENODEV; | |
146 | } | |
147 | ||
148 | static void cleanup_card(struct net_device *dev) | |
149 | { | |
150 | free_irq(dev->irq, dev); | |
151 | release_region(dev->base_addr, LNE390_IO_EXTENT); | |
152 | iounmap(ei_status.mem); | |
153 | } | |
154 | ||
155 | #ifndef MODULE | |
156 | struct net_device * __init lne390_probe(int unit) | |
157 | { | |
158 | struct net_device *dev = alloc_ei_netdev(); | |
159 | int err; | |
160 | ||
161 | if (!dev) | |
162 | return ERR_PTR(-ENOMEM); | |
163 | ||
164 | sprintf(dev->name, "eth%d", unit); | |
165 | netdev_boot_setup_check(dev); | |
166 | ||
167 | err = do_lne390_probe(dev); | |
168 | if (err) | |
169 | goto out; | |
1da177e4 | 170 | return dev; |
1da177e4 LT |
171 | out: |
172 | free_netdev(dev); | |
173 | return ERR_PTR(err); | |
174 | } | |
175 | #endif | |
176 | ||
177 | static int __init lne390_probe1(struct net_device *dev, int ioaddr) | |
178 | { | |
179 | int i, revision, ret; | |
180 | unsigned long eisa_id; | |
181 | ||
182 | if (inb_p(ioaddr + LNE390_ID_PORT) == 0xff) return -ENODEV; | |
183 | ||
184 | #if LNE390_DEBUG & LNE390_D_PROBE | |
185 | printk("lne390-debug: probe at %#x, ID %#8x\n", ioaddr, inl(ioaddr + LNE390_ID_PORT)); | |
186 | printk("lne390-debug: config regs: %#x %#x\n", | |
187 | inb(ioaddr + LNE390_CFG1), inb(ioaddr + LNE390_CFG2)); | |
188 | #endif | |
189 | ||
190 | ||
191 | /* Check the EISA ID of the card. */ | |
192 | eisa_id = inl(ioaddr + LNE390_ID_PORT); | |
193 | if ((eisa_id != LNE390_ID0) && (eisa_id != LNE390_ID1)) { | |
194 | return -ENODEV; | |
195 | } | |
196 | ||
197 | revision = (eisa_id >> 24) & 0x01; /* 0 = rev A, 1 rev B */ | |
198 | ||
199 | #if 0 | |
200 | /* Check the Mylex vendor ID as well. Not really required. */ | |
201 | if (inb(ioaddr + LNE390_SA_PROM + 0) != LNE390_ADDR0 | |
202 | || inb(ioaddr + LNE390_SA_PROM + 1) != LNE390_ADDR1 | |
203 | || inb(ioaddr + LNE390_SA_PROM + 2) != LNE390_ADDR2 ) { | |
204 | printk("lne390.c: card not found"); | |
205 | for(i = 0; i < ETHER_ADDR_LEN; i++) | |
206 | printk(" %02x", inb(ioaddr + LNE390_SA_PROM + i)); | |
207 | printk(" (invalid prefix).\n"); | |
208 | return -ENODEV; | |
209 | } | |
210 | #endif | |
211 | ||
212 | printk("lne390.c: LNE390%X in EISA slot %d, address", 0xa+revision, ioaddr/0x1000); | |
213 | for(i = 0; i < ETHER_ADDR_LEN; i++) | |
214 | printk(" %02x", (dev->dev_addr[i] = inb(ioaddr + LNE390_SA_PROM + i))); | |
215 | printk(".\nlne390.c: "); | |
216 | ||
217 | /* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */ | |
218 | if (dev->irq == 0) { | |
219 | unsigned char irq_reg = inb(ioaddr + LNE390_CFG2) >> 3; | |
220 | dev->irq = irq_map[irq_reg & 0x07]; | |
221 | printk("using"); | |
222 | } else { | |
223 | /* This is useless unless we reprogram the card here too */ | |
224 | if (dev->irq == 2) dev->irq = 9; /* Doh! */ | |
225 | printk("assigning"); | |
226 | } | |
227 | printk(" IRQ %d,", dev->irq); | |
228 | ||
229 | if ((ret = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev))) { | |
230 | printk (" unable to get IRQ %d.\n", dev->irq); | |
231 | return ret; | |
232 | } | |
233 | ||
234 | if (dev->mem_start == 0) { | |
235 | unsigned char mem_reg = inb(ioaddr + LNE390_CFG2) & 0x07; | |
236 | ||
237 | if (revision) /* LNE390B */ | |
238 | dev->mem_start = shmem_mapB[mem_reg] * 0x10000; | |
239 | else /* LNE390A */ | |
240 | dev->mem_start = shmem_mapA[mem_reg] * 0x10000; | |
241 | printk(" using "); | |
242 | } else { | |
243 | /* Should check for value in shmem_map and reprogram the card to use it */ | |
244 | dev->mem_start &= 0xfff0000; | |
245 | printk(" assigning "); | |
246 | } | |
247 | ||
248 | printk("%dkB memory at physical address %#lx\n", | |
249 | LNE390_STOP_PG/4, dev->mem_start); | |
250 | ||
251 | /* | |
252 | BEWARE!! Some dain-bramaged EISA SCUs will allow you to put | |
253 | the card mem within the region covered by `normal' RAM !!! | |
254 | ||
255 | ioremap() will fail in that case. | |
256 | */ | |
257 | ei_status.mem = ioremap(dev->mem_start, LNE390_STOP_PG*0x100); | |
258 | if (!ei_status.mem) { | |
259 | printk(KERN_ERR "lne390.c: Unable to remap card memory above 1MB !!\n"); | |
260 | printk(KERN_ERR "lne390.c: Try using EISA SCU to set memory below 1MB.\n"); | |
261 | printk(KERN_ERR "lne390.c: Driver NOT installed.\n"); | |
262 | ret = -EAGAIN; | |
263 | goto cleanup; | |
264 | } | |
265 | printk("lne390.c: remapped %dkB card memory to virtual address %p\n", | |
266 | LNE390_STOP_PG/4, ei_status.mem); | |
267 | ||
268 | dev->mem_start = (unsigned long)ei_status.mem; | |
269 | dev->mem_end = dev->mem_start + (LNE390_STOP_PG - LNE390_START_PG)*256; | |
270 | ||
271 | /* The 8390 offset is zero for the LNE390 */ | |
272 | dev->base_addr = ioaddr; | |
273 | ||
274 | ei_status.name = "LNE390"; | |
275 | ei_status.tx_start_page = LNE390_START_PG; | |
276 | ei_status.rx_start_page = LNE390_START_PG + TX_PAGES; | |
277 | ei_status.stop_page = LNE390_STOP_PG; | |
278 | ei_status.word16 = 1; | |
279 | ||
280 | if (ei_debug > 0) | |
281 | printk(version); | |
282 | ||
283 | ei_status.reset_8390 = &lne390_reset_8390; | |
284 | ei_status.block_input = &lne390_block_input; | |
285 | ei_status.block_output = &lne390_block_output; | |
286 | ei_status.get_8390_hdr = &lne390_get_8390_hdr; | |
287 | ||
288 | dev->open = &lne390_open; | |
289 | dev->stop = &lne390_close; | |
290 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
291 | dev->poll_controller = ei_poll; | |
292 | #endif | |
293 | NS8390_init(dev, 0); | |
b1fc5505 HX |
294 | |
295 | ret = register_netdev(dev); | |
296 | if (ret) | |
297 | goto unmap; | |
1da177e4 | 298 | return 0; |
b1fc5505 HX |
299 | unmap: |
300 | if (ei_status.reg0) | |
387d890d | 301 | iounmap(ei_status.mem); |
1da177e4 LT |
302 | cleanup: |
303 | free_irq(dev->irq, dev); | |
304 | return ret; | |
305 | } | |
306 | ||
307 | /* | |
308 | * Reset as per the packet driver method. Judging by the EISA cfg | |
309 | * file, this just toggles the "Board Enable" bits (bit 2 and 0). | |
310 | */ | |
311 | ||
312 | static void lne390_reset_8390(struct net_device *dev) | |
313 | { | |
314 | unsigned short ioaddr = dev->base_addr; | |
315 | ||
316 | outb(0x04, ioaddr + LNE390_RESET_PORT); | |
317 | if (ei_debug > 1) printk("%s: resetting the LNE390...", dev->name); | |
318 | ||
319 | mdelay(2); | |
320 | ||
321 | ei_status.txing = 0; | |
322 | outb(0x01, ioaddr + LNE390_RESET_PORT); | |
323 | if (ei_debug > 1) printk("reset done\n"); | |
324 | ||
325 | return; | |
326 | } | |
327 | ||
328 | /* | |
329 | * Note: In the following three functions is the implicit assumption | |
330 | * that the associated memcpy will only use "rep; movsl" as long as | |
331 | * we keep the counts as some multiple of doublewords. This is a | |
332 | * requirement of the hardware, and also prevents us from using | |
333 | * eth_io_copy_and_sum() since we can't guarantee it will limit | |
334 | * itself to doubleword access. | |
335 | */ | |
336 | ||
337 | /* | |
338 | * Grab the 8390 specific header. Similar to the block_input routine, but | |
339 | * we don't need to be concerned with ring wrap as the header will be at | |
340 | * the start of a page, so we optimize accordingly. (A single doubleword.) | |
341 | */ | |
342 | ||
343 | static void | |
344 | lne390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) | |
345 | { | |
346 | void __iomem *hdr_start = ei_status.mem + ((ring_page - LNE390_START_PG)<<8); | |
347 | memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr)); | |
348 | hdr->count = (hdr->count + 3) & ~3; /* Round up allocation. */ | |
349 | } | |
350 | ||
351 | /* | |
352 | * Block input and output are easy on shared memory ethercards, the only | |
353 | * complication is when the ring buffer wraps. The count will already | |
354 | * be rounded up to a doubleword value via lne390_get_8390_hdr() above. | |
355 | */ | |
356 | ||
357 | static void lne390_block_input(struct net_device *dev, int count, struct sk_buff *skb, | |
358 | int ring_offset) | |
359 | { | |
360 | void __iomem *xfer_start = ei_status.mem + ring_offset - (LNE390_START_PG<<8); | |
361 | ||
362 | if (ring_offset + count > (LNE390_STOP_PG<<8)) { | |
363 | /* Packet wraps over end of ring buffer. */ | |
364 | int semi_count = (LNE390_STOP_PG<<8) - ring_offset; | |
365 | memcpy_fromio(skb->data, xfer_start, semi_count); | |
366 | count -= semi_count; | |
367 | memcpy_fromio(skb->data + semi_count, | |
368 | ei_status.mem + (TX_PAGES<<8), count); | |
369 | } else { | |
370 | /* Packet is in one chunk. */ | |
371 | memcpy_fromio(skb->data, xfer_start, count); | |
372 | } | |
373 | } | |
374 | ||
375 | static void lne390_block_output(struct net_device *dev, int count, | |
376 | const unsigned char *buf, int start_page) | |
377 | { | |
378 | void __iomem *shmem = ei_status.mem + ((start_page - LNE390_START_PG)<<8); | |
379 | ||
380 | count = (count + 3) & ~3; /* Round up to doubleword */ | |
381 | memcpy_toio(shmem, buf, count); | |
382 | } | |
383 | ||
384 | static int lne390_open(struct net_device *dev) | |
385 | { | |
386 | ei_open(dev); | |
387 | return 0; | |
388 | } | |
389 | ||
390 | static int lne390_close(struct net_device *dev) | |
391 | { | |
392 | ||
393 | if (ei_debug > 1) | |
394 | printk("%s: Shutting down ethercard.\n", dev->name); | |
395 | ||
396 | ei_close(dev); | |
397 | return 0; | |
398 | } | |
399 | ||
400 | #ifdef MODULE | |
401 | #define MAX_LNE_CARDS 4 /* Max number of LNE390 cards per module */ | |
402 | static struct net_device *dev_lne[MAX_LNE_CARDS]; | |
403 | static int io[MAX_LNE_CARDS]; | |
404 | static int irq[MAX_LNE_CARDS]; | |
405 | static int mem[MAX_LNE_CARDS]; | |
406 | ||
407 | module_param_array(io, int, NULL, 0); | |
408 | module_param_array(irq, int, NULL, 0); | |
409 | module_param_array(mem, int, NULL, 0); | |
410 | MODULE_PARM_DESC(io, "I/O base address(es)"); | |
411 | MODULE_PARM_DESC(irq, "IRQ number(s)"); | |
412 | MODULE_PARM_DESC(mem, "memory base address(es)"); | |
413 | MODULE_DESCRIPTION("Mylex LNE390A/B EISA Ethernet driver"); | |
414 | MODULE_LICENSE("GPL"); | |
415 | ||
416 | int init_module(void) | |
417 | { | |
418 | struct net_device *dev; | |
419 | int this_dev, found = 0; | |
420 | ||
421 | for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) { | |
422 | if (io[this_dev] == 0 && this_dev != 0) | |
423 | break; | |
424 | dev = alloc_ei_netdev(); | |
425 | if (!dev) | |
426 | break; | |
427 | dev->irq = irq[this_dev]; | |
428 | dev->base_addr = io[this_dev]; | |
429 | dev->mem_start = mem[this_dev]; | |
430 | if (do_lne390_probe(dev) == 0) { | |
b1fc5505 HX |
431 | dev_lne[found++] = dev; |
432 | continue; | |
1da177e4 LT |
433 | } |
434 | free_netdev(dev); | |
435 | printk(KERN_WARNING "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]); | |
436 | break; | |
437 | } | |
438 | if (found) | |
439 | return 0; | |
440 | return -ENXIO; | |
441 | } | |
442 | ||
443 | void cleanup_module(void) | |
444 | { | |
445 | int this_dev; | |
446 | ||
447 | for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) { | |
448 | struct net_device *dev = dev_lne[this_dev]; | |
449 | if (dev) { | |
450 | unregister_netdev(dev); | |
451 | cleanup_card(dev); | |
452 | free_netdev(dev); | |
453 | } | |
454 | } | |
455 | } | |
456 | #endif /* MODULE */ | |
457 |