blob: fac43fd6fc87782a42455b852cec62a56333849f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 ne3210.c
3
4 Linux driver for Novell NE3210 EISA Network Adapter
5
6 Copyright (C) 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 my other EISA 8390 drivers (lne390, es3210, smc-ultra32)
14 2) The existing myriad of other Linux 8390 drivers by Donald Becker.
15 3) Info for getting IRQ and sh-mem gleaned from the EISA cfg file
16
Jeff Garzik6aa20a22006-09-13 13:24:59 -040017 The NE3210 is an EISA shared memory NS8390 implementation. Shared
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 memory address > 1MB should work with this driver.
19
Jeff Garzik6aa20a22006-09-13 13:24:59 -040020 Note that the .cfg file (3/11/93, v1.0) has AUI and BNC switched
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 around (or perhaps there are some defective/backwards cards ???)
22
23 This driver WILL NOT WORK FOR THE NE3200 - it is completely different
24 and does not use an 8390 at all.
25
26 Updated to EISA probing API 5/2003 by Marc Zyngier.
27*/
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/module.h>
30#include <linux/eisa.h>
31#include <linux/kernel.h>
32#include <linux/errno.h>
33#include <linux/string.h>
34#include <linux/delay.h>
35#include <linux/init.h>
36#include <linux/interrupt.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
Al Virod7fe0f22006-12-03 23:15:30 -050039#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#include <asm/io.h>
42#include <asm/system.h>
43
44#include "8390.h"
45
46#define DRV_NAME "ne3210"
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static void ne3210_reset_8390(struct net_device *dev);
49
50static void ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
51static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
52static void ne3210_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page);
53
54#define NE3210_START_PG 0x00 /* First page of TX buffer */
55#define NE3210_STOP_PG 0x80 /* Last page +1 of RX ring */
56
57#define NE3210_IO_EXTENT 0x20
58#define NE3210_SA_PROM 0x16 /* Start of e'net addr. */
59#define NE3210_RESET_PORT 0xc84
60#define NE3210_NIC_OFFSET 0x00 /* Hello, the 8390 is *here* */
61
62#define NE3210_ADDR0 0x00 /* 3 byte vendor prefix */
63#define NE3210_ADDR1 0x00
64#define NE3210_ADDR2 0x1b
65
66#define NE3210_CFG1 0xc84 /* NB: 0xc84 is also "reset" port. */
67#define NE3210_CFG2 0xc90
68#define NE3210_CFG_EXTENT (NE3210_CFG2 - NE3210_CFG1 + 1)
69
70/*
71 * You can OR any of the following bits together and assign it
72 * to NE3210_DEBUG to get verbose driver info during operation.
73 * Currently only the probe one is implemented.
74 */
75
76#define NE3210_D_PROBE 0x01
77#define NE3210_D_RX_PKT 0x02
78#define NE3210_D_TX_PKT 0x04
79#define NE3210_D_IRQ 0x08
80
81#define NE3210_DEBUG 0x0
82
83static unsigned char irq_map[] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
84static unsigned int shmem_map[] __initdata = {0xff0, 0xfe0, 0xfff0, 0xd8, 0xffe0, 0xffc0, 0xd0, 0x0};
85static const char *ifmap[] __initdata = {"UTP", "?", "BNC", "AUI"};
86static int ifmap_val[] __initdata = {
87 IF_PORT_10BASET,
88 IF_PORT_UNKNOWN,
89 IF_PORT_10BASE2,
90 IF_PORT_AUI,
91};
92
93static int __init ne3210_eisa_probe (struct device *device)
94{
95 unsigned long ioaddr, phys_mem;
96 int i, retval, port_index;
97 struct eisa_device *edev = to_eisa_device (device);
98 struct net_device *dev;
99
100 /* Allocate dev->priv and fill in 8390 specific dev fields. */
101 if (!(dev = alloc_ei_netdev ())) {
102 printk ("ne3210.c: unable to allocate memory for dev!\n");
103 return -ENOMEM;
104 }
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 SET_NETDEV_DEV(dev, device);
107 device->driver_data = dev;
108 ioaddr = edev->base_addr;
109
110 if (!request_region(ioaddr, NE3210_IO_EXTENT, DRV_NAME)) {
111 retval = -EBUSY;
112 goto out;
113 }
114
115 if (!request_region(ioaddr + NE3210_CFG1,
116 NE3210_CFG_EXTENT, DRV_NAME)) {
117 retval = -EBUSY;
118 goto out1;
119 }
120
121#if NE3210_DEBUG & NE3210_D_PROBE
122 printk("ne3210-debug: probe at %#x, ID %s\n", ioaddr, edev->id.sig);
123 printk("ne3210-debug: config regs: %#x %#x\n",
124 inb(ioaddr + NE3210_CFG1), inb(ioaddr + NE3210_CFG2));
125#endif
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 port_index = inb(ioaddr + NE3210_CFG2) >> 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 for(i = 0; i < ETHER_ADDR_LEN; i++)
Joe Perches0795af52007-10-03 17:59:30 -0700129 dev->dev_addr[i] = inb(ioaddr + NE3210_SA_PROM + i);
Johannes Berge1749612008-10-27 15:59:26 -0700130 printk("ne3210.c: NE3210 in EISA slot %d, media: %s, addr: %pM.\n",
131 edev->slot, ifmap[port_index], dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 /* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */
134 dev->irq = irq_map[(inb(ioaddr + NE3210_CFG2) >> 3) & 0x07];
Joe Perches0795af52007-10-03 17:59:30 -0700135 printk("ne3210.c: using IRQ %d, ", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev);
138 if (retval) {
139 printk (" unable to get IRQ %d.\n", dev->irq);
140 goto out2;
141 }
142
143 phys_mem = shmem_map[inb(ioaddr + NE3210_CFG2) & 0x07] * 0x1000;
144
145 /*
146 BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
147 the card mem within the region covered by `normal' RAM !!!
148 */
149 if (phys_mem > 1024*1024) { /* phys addr > 1MB */
150 if (phys_mem < virt_to_phys(high_memory)) {
151 printk(KERN_CRIT "ne3210.c: Card RAM overlaps with normal memory!!!\n");
152 printk(KERN_CRIT "ne3210.c: Use EISA SCU to set card memory below 1MB,\n");
153 printk(KERN_CRIT "ne3210.c: or to an address above 0x%lx.\n", virt_to_phys(high_memory));
154 printk(KERN_CRIT "ne3210.c: Driver NOT installed.\n");
155 retval = -EINVAL;
156 goto out3;
157 }
158 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (!request_mem_region (phys_mem, NE3210_STOP_PG*0x100, DRV_NAME)) {
161 printk ("ne3210.c: Unable to request shared memory at physical address %#lx\n",
162 phys_mem);
163 goto out3;
164 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 printk("%dkB memory at physical address %#lx\n",
167 NE3210_STOP_PG/4, phys_mem);
168
169 ei_status.mem = ioremap(phys_mem, NE3210_STOP_PG*0x100);
170 if (!ei_status.mem) {
171 printk(KERN_ERR "ne3210.c: Unable to remap card memory !!\n");
172 printk(KERN_ERR "ne3210.c: Driver NOT installed.\n");
173 retval = -EAGAIN;
174 goto out4;
175 }
176 printk("ne3210.c: remapped %dkB card memory to virtual address %p\n",
177 NE3210_STOP_PG/4, ei_status.mem);
178 dev->mem_start = (unsigned long)ei_status.mem;
179 dev->mem_end = dev->mem_start + (NE3210_STOP_PG - NE3210_START_PG)*256;
180
181 /* The 8390 offset is zero for the NE3210 */
182 dev->base_addr = ioaddr;
183
184 ei_status.name = "NE3210";
185 ei_status.tx_start_page = NE3210_START_PG;
186 ei_status.rx_start_page = NE3210_START_PG + TX_PAGES;
187 ei_status.stop_page = NE3210_STOP_PG;
188 ei_status.word16 = 1;
189 ei_status.priv = phys_mem;
190
191 if (ei_debug > 0)
Adrian Bunk9d8cc1b2005-09-03 14:04:55 -0700192 printk("ne3210 loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 ei_status.reset_8390 = &ne3210_reset_8390;
195 ei_status.block_input = &ne3210_block_input;
196 ei_status.block_output = &ne3210_block_output;
197 ei_status.get_8390_hdr = &ne3210_get_8390_hdr;
198
Stephen Hemmingerd2699412008-11-25 18:23:35 -0800199 dev->netdev_ops = &ei_netdev_ops;
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 dev->if_port = ifmap_val[port_index];
202
203 if ((retval = register_netdev (dev)))
204 goto out5;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 NS8390_init(dev, 0);
207 return 0;
208
209 out5:
210 iounmap(ei_status.mem);
211 out4:
212 release_mem_region (phys_mem, NE3210_STOP_PG*0x100);
213 out3:
214 free_irq (dev->irq, dev);
215 out2:
216 release_region (ioaddr + NE3210_CFG1, NE3210_CFG_EXTENT);
217 out1:
218 release_region (ioaddr, NE3210_IO_EXTENT);
219 out:
220 free_netdev (dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return retval;
223}
224
225static int __devexit ne3210_eisa_remove (struct device *device)
226{
227 struct net_device *dev = device->driver_data;
228 unsigned long ioaddr = to_eisa_device (device)->base_addr;
229
230 unregister_netdev (dev);
231 iounmap(ei_status.mem);
232 release_mem_region (ei_status.priv, NE3210_STOP_PG*0x100);
233 free_irq (dev->irq, dev);
234 release_region (ioaddr + NE3210_CFG1, NE3210_CFG_EXTENT);
235 release_region (ioaddr, NE3210_IO_EXTENT);
236 free_netdev (dev);
237
238 return 0;
239}
240
241/*
242 * Reset by toggling the "Board Enable" bits (bit 2 and 0).
243 */
244
245static void ne3210_reset_8390(struct net_device *dev)
246{
247 unsigned short ioaddr = dev->base_addr;
248
249 outb(0x04, ioaddr + NE3210_RESET_PORT);
250 if (ei_debug > 1) printk("%s: resetting the NE3210...", dev->name);
251
252 mdelay(2);
253
254 ei_status.txing = 0;
255 outb(0x01, ioaddr + NE3210_RESET_PORT);
256 if (ei_debug > 1) printk("reset done\n");
257
258 return;
259}
260
261/*
262 * Note: In the following three functions is the implicit assumption
263 * that the associated memcpy will only use "rep; movsl" as long as
264 * we keep the counts as some multiple of doublewords. This is a
265 * requirement of the hardware, and also prevents us from using
266 * eth_io_copy_and_sum() since we can't guarantee it will limit
267 * itself to doubleword access.
268 */
269
270/*
271 * Grab the 8390 specific header. Similar to the block_input routine, but
272 * we don't need to be concerned with ring wrap as the header will be at
273 * the start of a page, so we optimize accordingly. (A single doubleword.)
274 */
275
276static void
277ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
278{
279 void __iomem *hdr_start = ei_status.mem + ((ring_page - NE3210_START_PG)<<8);
280 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
281 hdr->count = (hdr->count + 3) & ~3; /* Round up allocation. */
282}
283
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400284/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 * Block input and output are easy on shared memory ethercards, the only
286 * complication is when the ring buffer wraps. The count will already
287 * be rounded up to a doubleword value via ne3210_get_8390_hdr() above.
288 */
289
290static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb,
291 int ring_offset)
292{
293 void __iomem *start = ei_status.mem + ring_offset - NE3210_START_PG*256;
294
295 if (ring_offset + count > NE3210_STOP_PG*256) {
296 /* Packet wraps over end of ring buffer. */
297 int semi_count = NE3210_STOP_PG*256 - ring_offset;
298 memcpy_fromio(skb->data, start, semi_count);
299 count -= semi_count;
300 memcpy_fromio(skb->data + semi_count,
301 ei_status.mem + TX_PAGES*256, count);
302 } else {
303 /* Packet is in one chunk. */
304 memcpy_fromio(skb->data, start, count);
305 }
306}
307
308static void ne3210_block_output(struct net_device *dev, int count,
309 const unsigned char *buf, int start_page)
310{
311 void __iomem *shmem = ei_status.mem + ((start_page - NE3210_START_PG)<<8);
312
313 count = (count + 3) & ~3; /* Round up to doubleword */
314 memcpy_toio(shmem, buf, count);
315}
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317static struct eisa_device_id ne3210_ids[] = {
318 { "EGL0101" },
319 { "NVL1801" },
320 { "" },
321};
Michael Tokarev07563c72006-09-27 01:50:56 -0700322MODULE_DEVICE_TABLE(eisa, ne3210_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324static struct eisa_driver ne3210_eisa_driver = {
325 .id_table = ne3210_ids,
326 .driver = {
327 .name = "ne3210",
328 .probe = ne3210_eisa_probe,
329 .remove = __devexit_p (ne3210_eisa_remove),
330 },
331};
332
333MODULE_DESCRIPTION("NE3210 EISA Ethernet driver");
334MODULE_LICENSE("GPL");
335MODULE_DEVICE_TABLE(eisa, ne3210_ids);
336
Adrian Bunk9d8cc1b2005-09-03 14:04:55 -0700337static int ne3210_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 return eisa_driver_register (&ne3210_eisa_driver);
340}
341
Adrian Bunk9d8cc1b2005-09-03 14:04:55 -0700342static void ne3210_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
344 eisa_driver_unregister (&ne3210_eisa_driver);
345}
346
347module_init (ne3210_init);
348module_exit (ne3210_cleanup);