• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/net/
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 <acme@conectiva.com.br> - 2000/09/01
30	- get rid of check_region
31	- no need to check if dev == NULL in lne390_probe1
32*/
33
34static 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
54static int lne390_probe1(struct net_device *dev, int ioaddr);
55
56static void lne390_reset_8390(struct net_device *dev);
57
58static void lne390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
59static void lne390_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
60static void lne390_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page);
61
62#define LNE390_START_PG		0x00    /* First page of TX buffer	*/
63#define LNE390_STOP_PG		0x80    /* Last page +1 of RX ring	*/
64
65#define LNE390_ID_PORT		0xc80	/* Same for all EISA cards 	*/
66#define LNE390_IO_EXTENT	0x20
67#define LNE390_SA_PROM		0x16	/* Start of e'net addr.		*/
68#define LNE390_RESET_PORT	0xc84	/* From the pkt driver source	*/
69#define LNE390_NIC_OFFSET	0x00	/* Hello, the 8390 is *here*	*/
70
71#define LNE390_ADDR0		0x00	/* 3 byte vendor prefix		*/
72#define LNE390_ADDR1		0x80
73#define LNE390_ADDR2		0xe5
74
75#define LNE390_ID0	0x10009835	/* 0x3598 = 01101 01100 11000 = mlx */
76#define LNE390_ID1	0x11009835	/* above is the 390A, this is 390B  */
77
78#define LNE390_CFG1		0xc84	/* NB: 0xc84 is also "reset" port. */
79#define LNE390_CFG2		0xc90
80
81/*
82 *	You can OR any of the following bits together and assign it
83 *	to LNE390_DEBUG to get verbose driver info during operation.
84 *	Currently only the probe one is implemented.
85 */
86
87#define LNE390_D_PROBE	0x01
88#define LNE390_D_RX_PKT	0x02
89#define LNE390_D_TX_PKT	0x04
90#define LNE390_D_IRQ	0x08
91
92#define LNE390_DEBUG	0
93
94static unsigned char irq_map[] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
95static unsigned int shmem_mapA[] __initdata = {0xff, 0xfe, 0xfd, 0xfff, 0xffe, 0xffc, 0x0d, 0x0};
96static unsigned int shmem_mapB[] __initdata = {0xff, 0xfe, 0x0e, 0xfff, 0xffe, 0xffc, 0x0d, 0x0};
97
98/*
99 *	Probe for the card. The best way is to read the EISA ID if it
100 *	is known. Then we can check the prefix of the station address
101 *	PROM for a match against the value assigned to Mylex.
102 */
103
104static int __init do_lne390_probe(struct net_device *dev)
105{
106	unsigned short ioaddr = dev->base_addr;
107	int irq = dev->irq;
108	int mem_start = dev->mem_start;
109	int ret;
110
111	if (ioaddr > 0x1ff) {		/* Check a single specified location. */
112		if (!request_region(ioaddr, LNE390_IO_EXTENT, DRV_NAME))
113			return -EBUSY;
114		ret = lne390_probe1(dev, ioaddr);
115		if (ret)
116			release_region(ioaddr, LNE390_IO_EXTENT);
117		return ret;
118	}
119	else if (ioaddr > 0)		/* Don't probe at all. */
120		return -ENXIO;
121
122	if (!EISA_bus) {
123#if LNE390_DEBUG & LNE390_D_PROBE
124		printk("lne390-debug: Not an EISA bus. Not probing high ports.\n");
125#endif
126		return -ENXIO;
127	}
128
129	/* EISA spec allows for up to 16 slots, but 8 is typical. */
130	for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
131		if (!request_region(ioaddr, LNE390_IO_EXTENT, DRV_NAME))
132			continue;
133		if (lne390_probe1(dev, ioaddr) == 0)
134			return 0;
135		release_region(ioaddr, LNE390_IO_EXTENT);
136		dev->irq = irq;
137		dev->mem_start = mem_start;
138	}
139
140	return -ENODEV;
141}
142
143#ifndef MODULE
144struct net_device * __init lne390_probe(int unit)
145{
146	struct net_device *dev = alloc_ei_netdev();
147	int err;
148
149	if (!dev)
150		return ERR_PTR(-ENOMEM);
151
152	sprintf(dev->name, "eth%d", unit);
153	netdev_boot_setup_check(dev);
154
155	err = do_lne390_probe(dev);
156	if (err)
157		goto out;
158	return dev;
159out:
160	free_netdev(dev);
161	return ERR_PTR(err);
162}
163#endif
164
165static int __init lne390_probe1(struct net_device *dev, int ioaddr)
166{
167	int i, revision, ret;
168	unsigned long eisa_id;
169
170	if (inb_p(ioaddr + LNE390_ID_PORT) == 0xff) return -ENODEV;
171
172#if LNE390_DEBUG & LNE390_D_PROBE
173	printk("lne390-debug: probe at %#x, ID %#8x\n", ioaddr, inl(ioaddr + LNE390_ID_PORT));
174	printk("lne390-debug: config regs: %#x %#x\n",
175		inb(ioaddr + LNE390_CFG1), inb(ioaddr + LNE390_CFG2));
176#endif
177
178
179/*	Check the EISA ID of the card. */
180	eisa_id = inl(ioaddr + LNE390_ID_PORT);
181	if ((eisa_id != LNE390_ID0) && (eisa_id != LNE390_ID1)) {
182		return -ENODEV;
183	}
184
185	revision = (eisa_id >> 24) & 0x01;	/* 0 = rev A, 1 rev B */
186
187
188	for(i = 0; i < ETHER_ADDR_LEN; i++)
189		dev->dev_addr[i] = inb(ioaddr + LNE390_SA_PROM + i);
190	printk("lne390.c: LNE390%X in EISA slot %d, address %pM.\n",
191	       0xa+revision, ioaddr/0x1000, dev->dev_addr);
192
193	printk("lne390.c: ");
194
195	/* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */
196	if (dev->irq == 0) {
197		unsigned char irq_reg = inb(ioaddr + LNE390_CFG2) >> 3;
198		dev->irq = irq_map[irq_reg & 0x07];
199		printk("using");
200	} else {
201		/* This is useless unless we reprogram the card here too */
202		if (dev->irq == 2) dev->irq = 9;	/* Doh! */
203		printk("assigning");
204	}
205	printk(" IRQ %d,", dev->irq);
206
207	if ((ret = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev))) {
208		printk (" unable to get IRQ %d.\n", dev->irq);
209		return ret;
210	}
211
212	if (dev->mem_start == 0) {
213		unsigned char mem_reg = inb(ioaddr + LNE390_CFG2) & 0x07;
214
215		if (revision)	/* LNE390B */
216			dev->mem_start = shmem_mapB[mem_reg] * 0x10000;
217		else		/* LNE390A */
218			dev->mem_start = shmem_mapA[mem_reg] * 0x10000;
219		printk(" using ");
220	} else {
221		/* Should check for value in shmem_map and reprogram the card to use it */
222		dev->mem_start &= 0xfff0000;
223		printk(" assigning ");
224	}
225
226	printk("%dkB memory at physical address %#lx\n",
227			LNE390_STOP_PG/4, dev->mem_start);
228
229	/*
230	   BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
231	   the card mem within the region covered by `normal' RAM  !!!
232
233	   ioremap() will fail in that case.
234	*/
235	ei_status.mem = ioremap(dev->mem_start, LNE390_STOP_PG*0x100);
236	if (!ei_status.mem) {
237		printk(KERN_ERR "lne390.c: Unable to remap card memory above 1MB !!\n");
238		printk(KERN_ERR "lne390.c: Try using EISA SCU to set memory below 1MB.\n");
239		printk(KERN_ERR "lne390.c: Driver NOT installed.\n");
240		ret = -EAGAIN;
241		goto cleanup;
242	}
243	printk("lne390.c: remapped %dkB card memory to virtual address %p\n",
244			LNE390_STOP_PG/4, ei_status.mem);
245
246	dev->mem_start = (unsigned long)ei_status.mem;
247	dev->mem_end = dev->mem_start + (LNE390_STOP_PG - LNE390_START_PG)*256;
248
249	/* The 8390 offset is zero for the LNE390 */
250	dev->base_addr = ioaddr;
251
252	ei_status.name = "LNE390";
253	ei_status.tx_start_page = LNE390_START_PG;
254	ei_status.rx_start_page = LNE390_START_PG + TX_PAGES;
255	ei_status.stop_page = LNE390_STOP_PG;
256	ei_status.word16 = 1;
257
258	if (ei_debug > 0)
259		printk(version);
260
261	ei_status.reset_8390 = &lne390_reset_8390;
262	ei_status.block_input = &lne390_block_input;
263	ei_status.block_output = &lne390_block_output;
264	ei_status.get_8390_hdr = &lne390_get_8390_hdr;
265
266	dev->netdev_ops = &ei_netdev_ops;
267	NS8390_init(dev, 0);
268
269	ret = register_netdev(dev);
270	if (ret)
271		goto unmap;
272	return 0;
273unmap:
274	if (ei_status.reg0)
275		iounmap(ei_status.mem);
276cleanup:
277	free_irq(dev->irq, dev);
278	return ret;
279}
280
281/*
282 *	Reset as per the packet driver method. Judging by the EISA cfg
283 *	file, this just toggles the "Board Enable" bits (bit 2 and 0).
284 */
285
286static void lne390_reset_8390(struct net_device *dev)
287{
288	unsigned short ioaddr = dev->base_addr;
289
290	outb(0x04, ioaddr + LNE390_RESET_PORT);
291	if (ei_debug > 1) printk("%s: resetting the LNE390...", dev->name);
292
293	mdelay(2);
294
295	ei_status.txing = 0;
296	outb(0x01, ioaddr + LNE390_RESET_PORT);
297	if (ei_debug > 1) printk("reset done\n");
298}
299
300/*
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.
307 */
308
309/*
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.)
313 */
314
315static void
316lne390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
317{
318	void __iomem *hdr_start = ei_status.mem + ((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. */
321}
322
323/*
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.
327 */
328
329static void lne390_block_input(struct net_device *dev, int count, struct sk_buff *skb,
330						  int ring_offset)
331{
332	void __iomem *xfer_start = ei_status.mem + ring_offset - (LNE390_START_PG<<8);
333
334	if (ring_offset + count > (LNE390_STOP_PG<<8)) {
335		/* Packet wraps over end of ring buffer. */
336		int semi_count = (LNE390_STOP_PG<<8) - ring_offset;
337		memcpy_fromio(skb->data, xfer_start, semi_count);
338		count -= semi_count;
339		memcpy_fromio(skb->data + semi_count,
340			ei_status.mem + (TX_PAGES<<8), count);
341	} else {
342		/* Packet is in one chunk. */
343		memcpy_fromio(skb->data, xfer_start, count);
344	}
345}
346
347static void lne390_block_output(struct net_device *dev, int count,
348				const unsigned char *buf, int start_page)
349{
350	void __iomem *shmem = ei_status.mem + ((start_page - LNE390_START_PG)<<8);
351
352	count = (count + 3) & ~3;     /* Round up to doubleword */
353	memcpy_toio(shmem, buf, count);
354}
355
356
357#ifdef MODULE
358#define MAX_LNE_CARDS	4	/* Max number of LNE390 cards per module */
359static struct net_device *dev_lne[MAX_LNE_CARDS];
360static int io[MAX_LNE_CARDS];
361static int irq[MAX_LNE_CARDS];
362static int mem[MAX_LNE_CARDS];
363
364module_param_array(io, int, NULL, 0);
365module_param_array(irq, int, NULL, 0);
366module_param_array(mem, int, NULL, 0);
367MODULE_PARM_DESC(io, "I/O base address(es)");
368MODULE_PARM_DESC(irq, "IRQ number(s)");
369MODULE_PARM_DESC(mem, "memory base address(es)");
370MODULE_DESCRIPTION("Mylex LNE390A/B EISA Ethernet driver");
371MODULE_LICENSE("GPL");
372
373int __init init_module(void)
374{
375	struct net_device *dev;
376	int this_dev, found = 0;
377
378	for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) {
379		if (io[this_dev] == 0 && this_dev != 0)
380			break;
381		dev = alloc_ei_netdev();
382		if (!dev)
383			break;
384		dev->irq = irq[this_dev];
385		dev->base_addr = io[this_dev];
386		dev->mem_start = mem[this_dev];
387		if (do_lne390_probe(dev) == 0) {
388			dev_lne[found++] = dev;
389			continue;
390		}
391		free_netdev(dev);
392		printk(KERN_WARNING "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]);
393		break;
394	}
395	if (found)
396		return 0;
397	return -ENXIO;
398}
399
400static void cleanup_card(struct net_device *dev)
401{
402	free_irq(dev->irq, dev);
403	release_region(dev->base_addr, LNE390_IO_EXTENT);
404	iounmap(ei_status.mem);
405}
406
407void __exit cleanup_module(void)
408{
409	int this_dev;
410
411	for (this_dev = 0; this_dev < MAX_LNE_CARDS; this_dev++) {
412		struct net_device *dev = dev_lne[this_dev];
413		if (dev) {
414			unregister_netdev(dev);
415			cleanup_card(dev);
416			free_netdev(dev);
417		}
418	}
419}
420#endif /* MODULE */
421