Import 2.3.18pre1
[davej-history.git] / drivers / net / lne390.c
blob5f99b56d9cd07ebf8be0d27926cbd1281a87fa99
1 /*
2 lne390.c
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 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. :)
31 static const char *version =
32 "lne390.c: Driver revision v0.99, 12/05/98\n";
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/sched.h>
37 #include <linux/errno.h>
38 #include <linux/string.h>
39 #include <linux/delay.h>
40 #include <linux/init.h>
42 #include <asm/io.h>
43 #include <asm/system.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include "8390.h"
49 int lne390_probe(struct net_device *dev);
50 int lne390_probe1(struct net_device *dev, int ioaddr);
52 static int lne390_open(struct net_device *dev);
53 static int lne390_close(struct net_device *dev);
55 static void lne390_reset_8390(struct net_device *dev);
57 static void lne390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
58 static void lne390_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
59 static void lne390_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page);
61 #define LNE390_START_PG 0x00 /* First page of TX buffer */
62 #define LNE390_STOP_PG 0x80 /* Last page +1 of RX ring */
64 #define LNE390_ID_PORT 0xc80 /* Same for all EISA cards */
65 #define LNE390_IO_EXTENT 0x20
66 #define LNE390_SA_PROM 0x16 /* Start of e'net addr. */
67 #define LNE390_RESET_PORT 0xc84 /* From the pkt driver source */
68 #define LNE390_NIC_OFFSET 0x00 /* Hello, the 8390 is *here* */
70 #define LNE390_ADDR0 0x00 /* 3 byte vendor prefix */
71 #define LNE390_ADDR1 0x80
72 #define LNE390_ADDR2 0xe5
74 #define LNE390_ID0 0x10009835 /* 0x3598 = 01101 01100 11000 = mlx */
75 #define LNE390_ID1 0x11009835 /* above is the 390A, this is 390B */
77 #define LNE390_CFG1 0xc84 /* NB: 0xc84 is also "reset" port. */
78 #define LNE390_CFG2 0xc90
81 * You can OR any of the following bits together and assign it
82 * to LNE390_DEBUG to get verbose driver info during operation.
83 * Currently only the probe one is implemented.
86 #define LNE390_D_PROBE 0x01
87 #define LNE390_D_RX_PKT 0x02
88 #define LNE390_D_TX_PKT 0x04
89 #define LNE390_D_IRQ 0x08
91 #define LNE390_DEBUG 0
93 static unsigned char irq_map[] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
94 static unsigned int shmem_mapA[] __initdata = {0xff, 0xfe, 0xfd, 0xfff, 0xffe, 0xffc, 0x0d, 0x0};
95 static unsigned int shmem_mapB[] __initdata = {0xff, 0xfe, 0x0e, 0xfff, 0xffe, 0xffc, 0x0d, 0x0};
98 * Probe for the card. The best way is to read the EISA ID if it
99 * is known. Then we can check the prefix of the station address
100 * PROM for a match against the value assigned to Mylex.
103 int __init lne390_probe(struct net_device *dev)
105 unsigned short ioaddr = dev->base_addr;
107 if (ioaddr > 0x1ff) /* Check a single specified location. */
108 return lne390_probe1(dev, ioaddr);
109 else if (ioaddr > 0) /* Don't probe at all. */
110 return ENXIO;
112 if (!EISA_bus) {
113 #if LNE390_DEBUG & LNE390_D_PROBE
114 printk("lne390-debug: Not an EISA bus. Not probing high ports.\n");
115 #endif
116 return ENXIO;
119 /* EISA spec allows for up to 16 slots, but 8 is typical. */
120 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
121 if (check_region(ioaddr , LNE390_IO_EXTENT))
122 continue;
123 if (lne390_probe1(dev, ioaddr) == 0)
124 return 0;
127 return ENODEV;
130 int __init lne390_probe1(struct net_device *dev, int ioaddr)
132 int i, revision;
133 unsigned long eisa_id;
135 if (inb_p(ioaddr + LNE390_ID_PORT) == 0xff) return -ENODEV;
137 #if LNE390_DEBUG & LNE390_D_PROBE
138 printk("lne390-debug: probe at %#x, ID %#8x\n", ioaddr, inl(ioaddr + LNE390_ID_PORT));
139 printk("lne390-debug: config regs: %#x %#x\n",
140 inb(ioaddr + LNE390_CFG1), inb(ioaddr + LNE390_CFG2));
141 #endif
144 /* Check the EISA ID of the card. */
145 eisa_id = inl(ioaddr + LNE390_ID_PORT);
146 if ((eisa_id != LNE390_ID0) && (eisa_id != LNE390_ID1)) {
147 return ENODEV;
150 revision = (eisa_id >> 24) & 0x01; /* 0 = rev A, 1 rev B */
152 #if 0
153 /* Check the Mylex vendor ID as well. Not really required. */
154 if (inb(ioaddr + LNE390_SA_PROM + 0) != LNE390_ADDR0
155 || inb(ioaddr + LNE390_SA_PROM + 1) != LNE390_ADDR1
156 || inb(ioaddr + LNE390_SA_PROM + 2) != LNE390_ADDR2 ) {
157 printk("lne390.c: card not found");
158 for(i = 0; i < ETHER_ADDR_LEN; i++)
159 printk(" %02x", inb(ioaddr + LNE390_SA_PROM + i));
160 printk(" (invalid prefix).\n");
161 return ENODEV;
163 #endif
165 if (load_8390_module("lne390.c"))
166 return -ENOSYS;
168 /* We should have a "dev" from Space.c or the static module table. */
169 if (dev == NULL) {
170 printk("lne390.c: Passed a NULL device.\n");
171 dev = init_etherdev(0, 0);
174 /* Allocate dev->priv and fill in 8390 specific dev fields. */
175 if (ethdev_init(dev)) {
176 printk ("lne390.c: unable to allocate memory for dev->priv!\n");
177 return -ENOMEM;
180 printk("lne390.c: LNE390%X in EISA slot %d, address", 0xa+revision, ioaddr/0x1000);
181 for(i = 0; i < ETHER_ADDR_LEN; i++)
182 printk(" %02x", (dev->dev_addr[i] = inb(ioaddr + LNE390_SA_PROM + i)));
183 printk(".\nlne390.c: ");
185 /* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */
186 if (dev->irq == 0) {
187 unsigned char irq_reg = inb(ioaddr + LNE390_CFG2) >> 3;
188 dev->irq = irq_map[irq_reg & 0x07];
189 printk("using");
190 } else {
191 /* This is useless unless we reprogram the card here too */
192 if (dev->irq == 2) dev->irq = 9; /* Doh! */
193 printk("assigning");
195 printk(" IRQ %d,", dev->irq);
197 if (request_irq(dev->irq, ei_interrupt, 0, "lne390", dev)) {
198 printk (" unable to get IRQ %d.\n", dev->irq);
199 kfree(dev->priv);
200 dev->priv = NULL;
201 return EAGAIN;
204 if (dev->mem_start == 0) {
205 unsigned char mem_reg = inb(ioaddr + LNE390_CFG2) & 0x07;
207 if (revision) /* LNE390B */
208 dev->mem_start = shmem_mapB[mem_reg] * 0x10000;
209 else /* LNE390A */
210 dev->mem_start = shmem_mapA[mem_reg] * 0x10000;
211 printk(" using ");
212 } else {
213 /* Should check for value in shmem_map and reprogram the card to use it */
214 dev->mem_start &= 0xfff0000;
215 printk(" assigning ");
218 printk("%dkB memory at physical address %#lx\n",
219 LNE390_STOP_PG/4, dev->mem_start);
222 BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
223 the card mem within the region covered by `normal' RAM !!!
225 if (dev->mem_start > 1024*1024) { /* phys addr > 1MB */
226 if (dev->mem_start < virt_to_bus(high_memory)) {
227 printk(KERN_CRIT "lne390.c: Card RAM overlaps with normal memory!!!\n");
228 printk(KERN_CRIT "lne390.c: Use EISA SCU to set card memory below 1MB,\n");
229 printk(KERN_CRIT "lne390.c: or to an address above 0x%lx.\n", virt_to_bus(high_memory));
230 printk(KERN_CRIT "lne390.c: Driver NOT installed.\n");
231 free_irq(dev->irq, dev);
232 kfree(dev->priv);
233 dev->priv = NULL;
234 return EINVAL;
236 dev->mem_start = (unsigned long)ioremap(dev->mem_start, LNE390_STOP_PG*0x100);
237 if (dev->mem_start == 0) {
238 printk(KERN_ERR "lne390.c: Unable to remap card memory above 1MB !!\n");
239 printk(KERN_ERR "lne390.c: Try using EISA SCU to set memory below 1MB.\n");
240 printk(KERN_ERR "lne390.c: Driver NOT installed.\n");
241 free_irq(dev->irq, dev);
242 kfree(dev->priv);
243 dev->priv = NULL;
244 return EAGAIN;
246 ei_status.reg0 = 1; /* Use as remap flag */
247 printk("lne390.c: remapped %dkB card memory to virtual address %#lx\n",
248 LNE390_STOP_PG/4, dev->mem_start);
251 dev->mem_end = dev->rmem_end = dev->mem_start
252 + (LNE390_STOP_PG - LNE390_START_PG)*256;
253 dev->rmem_start = dev->mem_start + TX_PAGES*256;
255 /* The 8390 offset is zero for the LNE390 */
256 dev->base_addr = ioaddr;
257 request_region(dev->base_addr, LNE390_IO_EXTENT, "lne390");
259 ei_status.name = "LNE390";
260 ei_status.tx_start_page = LNE390_START_PG;
261 ei_status.rx_start_page = LNE390_START_PG + TX_PAGES;
262 ei_status.stop_page = LNE390_STOP_PG;
263 ei_status.word16 = 1;
265 if (ei_debug > 0)
266 printk(version);
268 ei_status.reset_8390 = &lne390_reset_8390;
269 ei_status.block_input = &lne390_block_input;
270 ei_status.block_output = &lne390_block_output;
271 ei_status.get_8390_hdr = &lne390_get_8390_hdr;
273 dev->open = &lne390_open;
274 dev->stop = &lne390_close;
275 NS8390_init(dev, 0);
276 return 0;
280 * Reset as per the packet driver method. Judging by the EISA cfg
281 * file, this just toggles the "Board Enable" bits (bit 2 and 0).
284 static void lne390_reset_8390(struct net_device *dev)
286 unsigned short ioaddr = dev->base_addr;
288 outb(0x04, ioaddr + LNE390_RESET_PORT);
289 if (ei_debug > 1) printk("%s: resetting the LNE390...", dev->name);
291 mdelay(2);
293 ei_status.txing = 0;
294 outb(0x01, ioaddr + LNE390_RESET_PORT);
295 if (ei_debug > 1) printk("reset done\n");
297 return;
301 * Note: In the following three functions is the implicit assumption
302 * that the associated memcpy will only use "rep; movsl" as long as
303 * we keep the counts as some multiple of doublewords. This is a
304 * requirement of the hardware, and also prevents us from using
305 * eth_io_copy_and_sum() since we can't guarantee it will limit
306 * itself to doubleword access.
310 * Grab the 8390 specific header. Similar to the block_input routine, but
311 * we don't need to be concerned with ring wrap as the header will be at
312 * the start of a page, so we optimize accordingly. (A single doubleword.)
315 static void
316 lne390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
318 unsigned long hdr_start = dev->mem_start + ((ring_page - LNE390_START_PG)<<8);
319 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
320 hdr->count = (hdr->count + 3) & ~3; /* Round up allocation. */
324 * Block input and output are easy on shared memory ethercards, the only
325 * complication is when the ring buffer wraps. The count will already
326 * be rounded up to a doubleword value via lne390_get_8390_hdr() above.
329 static void lne390_block_input(struct net_device *dev, int count, struct sk_buff *skb,
330 int ring_offset)
332 unsigned long xfer_start = dev->mem_start + ring_offset - (LNE390_START_PG<<8);
334 if (xfer_start + count > dev->rmem_end) {
335 /* Packet wraps over end of ring buffer. */
336 int semi_count = dev->rmem_end - xfer_start;
337 memcpy_fromio(skb->data, xfer_start, semi_count);
338 count -= semi_count;
339 memcpy_fromio(skb->data + semi_count, dev->rmem_start, count);
340 } else {
341 /* Packet is in one chunk. */
342 memcpy_fromio(skb->data, xfer_start, count);
346 static void lne390_block_output(struct net_device *dev, int count,
347 const unsigned char *buf, int start_page)
349 unsigned long shmem = dev->mem_start + ((start_page - LNE390_START_PG)<<8);
351 count = (count + 3) & ~3; /* Round up to doubleword */
352 memcpy_toio(shmem, buf, count);
355 static int lne390_open(struct net_device *dev)
357 ei_open(dev);
358 MOD_INC_USE_COUNT;
359 return 0;
362 static int lne390_close(struct net_device *dev)
365 if (ei_debug > 1)
366 printk("%s: Shutting down ethercard.\n", dev->name);
368 ei_close(dev);
369 MOD_DEC_USE_COUNT;
370 return 0;
373 #ifdef MODULE
374 #define MAX_LNE_CARDS 4 /* Max number of LNE390 cards per module */
375 #define NAMELEN 8 /* # of chars for storing dev->name */
376 static char namelist[NAMELEN * MAX_LNE_CARDS] = { 0, };
377 static struct net_device dev_lne[MAX_LNE_CARDS] = {
379 NULL, /* assign a chunk of namelist[] below */
380 0, 0, 0, 0,
381 0, 0,
382 0, 0, 0, NULL, NULL
386 static int io[MAX_LNE_CARDS] = { 0, };
387 static int irq[MAX_LNE_CARDS] = { 0, };
388 static int mem[MAX_LNE_CARDS] = { 0, };
390 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_LNE_CARDS) "i");
391 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_LNE_CARDS) "i");
392 MODULE_PARM(mem, "1-" __MODULE_STRING(MAX_LNE_CARDS) "i");
394 int init_module(void)
396 int this_dev, found = 0;
398 for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) {
399 struct net_device *dev = &dev_lne[this_dev];
400 dev->name = namelist+(NAMELEN*this_dev);
401 dev->irq = irq[this_dev];
402 dev->base_addr = io[this_dev];
403 dev->mem_start = mem[this_dev];
404 dev->init = lne390_probe;
405 /* Default is to only install one card. */
406 if (io[this_dev] == 0 && this_dev != 0) break;
407 if (register_netdev(dev) != 0) {
408 printk(KERN_WARNING "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]);
409 if (found != 0) { /* Got at least one. */
410 lock_8390_module();
411 return 0;
413 return -ENXIO;
415 found++;
417 lock_8390_module();
418 return 0;
421 void cleanup_module(void)
423 int this_dev;
425 for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) {
426 struct net_device *dev = &dev_lne[this_dev];
427 if (dev->priv != NULL) {
428 void *priv = dev->priv;
429 free_irq(dev->irq, dev);
430 release_region(dev->base_addr, LNE390_IO_EXTENT);
431 if (ei_status.reg0)
432 iounmap((void *)dev->mem_start);
433 unregister_netdev(dev);
434 kfree(priv);
437 unlock_8390_module();
439 #endif /* MODULE */