4 Linux driver for Mylex LNE390 EISA Network Adapter
6 Copyright (C) 1996-1998, Paul Gortmaker.
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
11 Information and Code Sources:
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.
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.
26 You can try <http://www.mylex.com> if you want more info, as I've
27 never even seen one of these cards. :)
29 Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/09/01
30 - get rid of check_region
31 - no need to check if dev == NULL in lne390_probe1
34 static const char *version =
35 "lne390.c: Driver revision v0.99.1, 01/09/2000\n";
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>
48 #include <asm/system.h>
52 static int lne390_probe1(struct net_device *dev, int ioaddr);
54 static int lne390_open(struct net_device *dev);
55 static int lne390_close(struct net_device *dev);
57 static void lne390_reset_8390(struct net_device *dev);
59 static void lne390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
60 static void lne390_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
61 static void lne390_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page);
63 #define LNE390_START_PG 0x00 /* First page of TX buffer */
64 #define LNE390_STOP_PG 0x80 /* Last page +1 of RX ring */
66 #define LNE390_ID_PORT 0xc80 /* Same for all EISA cards */
67 #define LNE390_IO_EXTENT 0x20
68 #define LNE390_SA_PROM 0x16 /* Start of e'net addr. */
69 #define LNE390_RESET_PORT 0xc84 /* From the pkt driver source */
70 #define LNE390_NIC_OFFSET 0x00 /* Hello, the 8390 is *here* */
72 #define LNE390_ADDR0 0x00 /* 3 byte vendor prefix */
73 #define LNE390_ADDR1 0x80
74 #define LNE390_ADDR2 0xe5
76 #define LNE390_ID0 0x10009835 /* 0x3598 = 01101 01100 11000 = mlx */
77 #define LNE390_ID1 0x11009835 /* above is the 390A, this is 390B */
79 #define LNE390_CFG1 0xc84 /* NB: 0xc84 is also "reset" port. */
80 #define LNE390_CFG2 0xc90
83 * You can OR any of the following bits together and assign it
84 * to LNE390_DEBUG to get verbose driver info during operation.
85 * Currently only the probe one is implemented.
88 #define LNE390_D_PROBE 0x01
89 #define LNE390_D_RX_PKT 0x02
90 #define LNE390_D_TX_PKT 0x04
91 #define LNE390_D_IRQ 0x08
93 #define LNE390_DEBUG 0
95 static unsigned char irq_map[] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
96 static unsigned int shmem_mapA[] __initdata = {0xff, 0xfe, 0xfd, 0xfff, 0xffe, 0xffc, 0x0d, 0x0};
97 static unsigned int shmem_mapB[] __initdata = {0xff, 0xfe, 0x0e, 0xfff, 0xffe, 0xffc, 0x0d, 0x0};
100 * Probe for the card. The best way is to read the EISA ID if it
101 * is known. Then we can check the prefix of the station address
102 * PROM for a match against the value assigned to Mylex.
105 static int __init do_lne390_probe(struct net_device *dev)
107 unsigned short ioaddr = dev->base_addr;
109 int mem_start = dev->mem_start;
112 SET_MODULE_OWNER(dev);
114 if (ioaddr > 0x1ff) { /* Check a single specified location. */
115 if (!request_region(ioaddr, LNE390_IO_EXTENT, dev->name))
117 ret = lne390_probe1(dev, ioaddr);
119 release_region(ioaddr, LNE390_IO_EXTENT);
122 else if (ioaddr > 0) /* Don't probe at all. */
126 #if LNE390_DEBUG & LNE390_D_PROBE
127 printk("lne390-debug: Not an EISA bus. Not probing high ports.\n");
132 /* EISA spec allows for up to 16 slots, but 8 is typical. */
133 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
134 if (!request_region(ioaddr, LNE390_IO_EXTENT, dev->name))
136 if (lne390_probe1(dev, ioaddr) == 0)
138 release_region(ioaddr, LNE390_IO_EXTENT);
140 dev->mem_start = mem_start;
146 static void cleanup_card(struct net_device *dev)
148 free_irq(dev->irq, dev);
149 release_region(dev->base_addr, LNE390_IO_EXTENT);
151 iounmap((void *)dev->mem_start);
154 struct net_device * __init lne390_probe(int unit)
156 struct net_device *dev = alloc_ei_netdev();
160 return ERR_PTR(-ENOMEM);
162 sprintf(dev->name, "eth%d", unit);
163 netdev_boot_setup_check(dev);
165 err = do_lne390_probe(dev);
168 err = register_netdev(dev);
179 static int __init lne390_probe1(struct net_device *dev, int ioaddr)
181 int i, revision, ret;
182 unsigned long eisa_id;
184 if (inb_p(ioaddr + LNE390_ID_PORT) == 0xff) return -ENODEV;
186 #if LNE390_DEBUG & LNE390_D_PROBE
187 printk("lne390-debug: probe at %#x, ID %#8x\n", ioaddr, inl(ioaddr + LNE390_ID_PORT));
188 printk("lne390-debug: config regs: %#x %#x\n",
189 inb(ioaddr + LNE390_CFG1), inb(ioaddr + LNE390_CFG2));
193 /* Check the EISA ID of the card. */
194 eisa_id = inl(ioaddr + LNE390_ID_PORT);
195 if ((eisa_id != LNE390_ID0) && (eisa_id != LNE390_ID1)) {
199 revision = (eisa_id >> 24) & 0x01; /* 0 = rev A, 1 rev B */
202 /* Check the Mylex vendor ID as well. Not really required. */
203 if (inb(ioaddr + LNE390_SA_PROM + 0) != LNE390_ADDR0
204 || inb(ioaddr + LNE390_SA_PROM + 1) != LNE390_ADDR1
205 || inb(ioaddr + LNE390_SA_PROM + 2) != LNE390_ADDR2 ) {
206 printk("lne390.c: card not found");
207 for(i = 0; i < ETHER_ADDR_LEN; i++)
208 printk(" %02x", inb(ioaddr + LNE390_SA_PROM + i));
209 printk(" (invalid prefix).\n");
214 printk("lne390.c: LNE390%X in EISA slot %d, address", 0xa+revision, ioaddr/0x1000);
215 for(i = 0; i < ETHER_ADDR_LEN; i++)
216 printk(" %02x", (dev->dev_addr[i] = inb(ioaddr + LNE390_SA_PROM + i)));
217 printk(".\nlne390.c: ");
219 /* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */
221 unsigned char irq_reg = inb(ioaddr + LNE390_CFG2) >> 3;
222 dev->irq = irq_map[irq_reg & 0x07];
225 /* This is useless unless we reprogram the card here too */
226 if (dev->irq == 2) dev->irq = 9; /* Doh! */
229 printk(" IRQ %d,", dev->irq);
231 if ((ret = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev))) {
232 printk (" unable to get IRQ %d.\n", dev->irq);
236 if (dev->mem_start == 0) {
237 unsigned char mem_reg = inb(ioaddr + LNE390_CFG2) & 0x07;
239 if (revision) /* LNE390B */
240 dev->mem_start = shmem_mapB[mem_reg] * 0x10000;
242 dev->mem_start = shmem_mapA[mem_reg] * 0x10000;
245 /* Should check for value in shmem_map and reprogram the card to use it */
246 dev->mem_start &= 0xfff0000;
247 printk(" assigning ");
250 printk("%dkB memory at physical address %#lx\n",
251 LNE390_STOP_PG/4, dev->mem_start);
254 BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
255 the card mem within the region covered by `normal' RAM !!!
257 if (dev->mem_start > 1024*1024) { /* phys addr > 1MB */
258 if (dev->mem_start < virt_to_phys(high_memory)) {
259 printk(KERN_CRIT "lne390.c: Card RAM overlaps with normal memory!!!\n");
260 printk(KERN_CRIT "lne390.c: Use EISA SCU to set card memory below 1MB,\n");
261 printk(KERN_CRIT "lne390.c: or to an address above 0x%lx.\n", virt_to_phys(high_memory));
262 printk(KERN_CRIT "lne390.c: Driver NOT installed.\n");
266 dev->mem_start = (unsigned long)ioremap(dev->mem_start, LNE390_STOP_PG*0x100);
267 if (dev->mem_start == 0) {
268 printk(KERN_ERR "lne390.c: Unable to remap card memory above 1MB !!\n");
269 printk(KERN_ERR "lne390.c: Try using EISA SCU to set memory below 1MB.\n");
270 printk(KERN_ERR "lne390.c: Driver NOT installed.\n");
274 ei_status.reg0 = 1; /* Use as remap flag */
275 printk("lne390.c: remapped %dkB card memory to virtual address %#lx\n",
276 LNE390_STOP_PG/4, dev->mem_start);
279 dev->mem_end = ei_status.rmem_end = dev->mem_start
280 + (LNE390_STOP_PG - LNE390_START_PG)*256;
281 ei_status.rmem_start = dev->mem_start + TX_PAGES*256;
283 /* The 8390 offset is zero for the LNE390 */
284 dev->base_addr = ioaddr;
286 ei_status.name = "LNE390";
287 ei_status.tx_start_page = LNE390_START_PG;
288 ei_status.rx_start_page = LNE390_START_PG + TX_PAGES;
289 ei_status.stop_page = LNE390_STOP_PG;
290 ei_status.word16 = 1;
295 ei_status.reset_8390 = &lne390_reset_8390;
296 ei_status.block_input = &lne390_block_input;
297 ei_status.block_output = &lne390_block_output;
298 ei_status.get_8390_hdr = &lne390_get_8390_hdr;
300 dev->open = &lne390_open;
301 dev->stop = &lne390_close;
302 #ifdef CONFIG_NET_POLL_CONTROLLER
303 dev->poll_controller = ei_poll;
308 free_irq(dev->irq, dev);
313 * Reset as per the packet driver method. Judging by the EISA cfg
314 * file, this just toggles the "Board Enable" bits (bit 2 and 0).
317 static void lne390_reset_8390(struct net_device *dev)
319 unsigned short ioaddr = dev->base_addr;
321 outb(0x04, ioaddr + LNE390_RESET_PORT);
322 if (ei_debug > 1) printk("%s: resetting the LNE390...", dev->name);
327 outb(0x01, ioaddr + LNE390_RESET_PORT);
328 if (ei_debug > 1) printk("reset done\n");
334 * Note: In the following three functions is the implicit assumption
335 * that the associated memcpy will only use "rep; movsl" as long as
336 * we keep the counts as some multiple of doublewords. This is a
337 * requirement of the hardware, and also prevents us from using
338 * eth_io_copy_and_sum() since we can't guarantee it will limit
339 * itself to doubleword access.
343 * Grab the 8390 specific header. Similar to the block_input routine, but
344 * we don't need to be concerned with ring wrap as the header will be at
345 * the start of a page, so we optimize accordingly. (A single doubleword.)
349 lne390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
351 unsigned long hdr_start = dev->mem_start + ((ring_page - LNE390_START_PG)<<8);
352 isa_memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
353 hdr->count = (hdr->count + 3) & ~3; /* Round up allocation. */
357 * Block input and output are easy on shared memory ethercards, the only
358 * complication is when the ring buffer wraps. The count will already
359 * be rounded up to a doubleword value via lne390_get_8390_hdr() above.
362 static void lne390_block_input(struct net_device *dev, int count, struct sk_buff *skb,
365 unsigned long xfer_start = dev->mem_start + ring_offset - (LNE390_START_PG<<8);
367 if (xfer_start + count > ei_status.rmem_end) {
368 /* Packet wraps over end of ring buffer. */
369 int semi_count = ei_status.rmem_end - xfer_start;
370 isa_memcpy_fromio(skb->data, xfer_start, semi_count);
372 isa_memcpy_fromio(skb->data + semi_count, ei_status.rmem_start, count);
374 /* Packet is in one chunk. */
375 isa_memcpy_fromio(skb->data, xfer_start, count);
379 static void lne390_block_output(struct net_device *dev, int count,
380 const unsigned char *buf, int start_page)
382 unsigned long shmem = dev->mem_start + ((start_page - LNE390_START_PG)<<8);
384 count = (count + 3) & ~3; /* Round up to doubleword */
385 isa_memcpy_toio(shmem, buf, count);
388 static int lne390_open(struct net_device *dev)
394 static int lne390_close(struct net_device *dev)
398 printk("%s: Shutting down ethercard.\n", dev->name);
405 #define MAX_LNE_CARDS 4 /* Max number of LNE390 cards per module */
406 static struct net_device *dev_lne[MAX_LNE_CARDS];
407 static int io[MAX_LNE_CARDS];
408 static int irq[MAX_LNE_CARDS];
409 static int mem[MAX_LNE_CARDS];
411 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_LNE_CARDS) "i");
412 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_LNE_CARDS) "i");
413 MODULE_PARM(mem, "1-" __MODULE_STRING(MAX_LNE_CARDS) "i");
414 MODULE_PARM_DESC(io, "I/O base address(es)");
415 MODULE_PARM_DESC(irq, "IRQ number(s)");
416 MODULE_PARM_DESC(mem, "memory base address(es)");
417 MODULE_DESCRIPTION("Mylex LNE390A/B EISA Ethernet driver");
418 MODULE_LICENSE("GPL");
420 int init_module(void)
422 struct net_device *dev;
423 int this_dev, found = 0;
425 for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) {
426 if (io[this_dev] == 0 && this_dev != 0)
428 dev = alloc_ei_netdev();
431 dev->irq = irq[this_dev];
432 dev->base_addr = io[this_dev];
433 dev->mem_start = mem[this_dev];
434 if (do_lne390_probe(dev) == 0) {
435 if (register_netdev(dev) == 0) {
436 dev_lne[found++] = dev;
442 printk(KERN_WARNING "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]);
450 void cleanup_module(void)
454 for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) {
455 struct net_device *dev = dev_lne[this_dev];
457 unregister_netdev(dev);