aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ne3210.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/ne3210.c
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/net/ne3210.c')
-rw-r--r--drivers/net/ne3210.c374
1 files changed, 374 insertions, 0 deletions
diff --git a/drivers/net/ne3210.c b/drivers/net/ne3210.c
new file mode 100644
index 00000000000..6c92f096901
--- /dev/null
+++ b/drivers/net/ne3210.c
@@ -0,0 +1,374 @@
1/*
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
17 The NE3210 is an EISA shared memory NS8390 implementation. Shared
18 memory address > 1MB should work with this driver.
19
20 Note that the .cfg file (3/11/93, v1.0) has AUI and BNC switched
21 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
29static const char *version =
30 "ne3210.c: Driver revision v0.03, 30/09/98\n";
31
32#include <linux/module.h>
33#include <linux/eisa.h>
34#include <linux/kernel.h>
35#include <linux/errno.h>
36#include <linux/string.h>
37#include <linux/delay.h>
38#include <linux/init.h>
39#include <linux/interrupt.h>
40#include <linux/netdevice.h>
41#include <linux/etherdevice.h>
42
43#include <asm/io.h>
44#include <asm/system.h>
45
46#include "8390.h"
47
48#define DRV_NAME "ne3210"
49
50static int ne3210_open(struct net_device *dev);
51static int ne3210_close(struct net_device *dev);
52
53static void ne3210_reset_8390(struct net_device *dev);
54
55static void ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
56static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
57static void ne3210_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page);
58
59#define NE3210_START_PG 0x00 /* First page of TX buffer */
60#define NE3210_STOP_PG 0x80 /* Last page +1 of RX ring */
61
62#define NE3210_IO_EXTENT 0x20
63#define NE3210_SA_PROM 0x16 /* Start of e'net addr. */
64#define NE3210_RESET_PORT 0xc84
65#define NE3210_NIC_OFFSET 0x00 /* Hello, the 8390 is *here* */
66
67#define NE3210_ADDR0 0x00 /* 3 byte vendor prefix */
68#define NE3210_ADDR1 0x00
69#define NE3210_ADDR2 0x1b
70
71#define NE3210_CFG1 0xc84 /* NB: 0xc84 is also "reset" port. */
72#define NE3210_CFG2 0xc90
73#define NE3210_CFG_EXTENT (NE3210_CFG2 - NE3210_CFG1 + 1)
74
75/*
76 * You can OR any of the following bits together and assign it
77 * to NE3210_DEBUG to get verbose driver info during operation.
78 * Currently only the probe one is implemented.
79 */
80
81#define NE3210_D_PROBE 0x01
82#define NE3210_D_RX_PKT 0x02
83#define NE3210_D_TX_PKT 0x04
84#define NE3210_D_IRQ 0x08
85
86#define NE3210_DEBUG 0x0
87
88static unsigned char irq_map[] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
89static unsigned int shmem_map[] __initdata = {0xff0, 0xfe0, 0xfff0, 0xd8, 0xffe0, 0xffc0, 0xd0, 0x0};
90static const char *ifmap[] __initdata = {"UTP", "?", "BNC", "AUI"};
91static int ifmap_val[] __initdata = {
92 IF_PORT_10BASET,
93 IF_PORT_UNKNOWN,
94 IF_PORT_10BASE2,
95 IF_PORT_AUI,
96};
97
98static int __init ne3210_eisa_probe (struct device *device)
99{
100 unsigned long ioaddr, phys_mem;
101 int i, retval, port_index;
102 struct eisa_device *edev = to_eisa_device (device);
103 struct net_device *dev;
104
105 /* Allocate dev->priv and fill in 8390 specific dev fields. */
106 if (!(dev = alloc_ei_netdev ())) {
107 printk ("ne3210.c: unable to allocate memory for dev!\n");
108 return -ENOMEM;
109 }
110
111 SET_MODULE_OWNER(dev);
112 SET_NETDEV_DEV(dev, device);
113 device->driver_data = dev;
114 ioaddr = edev->base_addr;
115
116 if (!request_region(ioaddr, NE3210_IO_EXTENT, DRV_NAME)) {
117 retval = -EBUSY;
118 goto out;
119 }
120
121 if (!request_region(ioaddr + NE3210_CFG1,
122 NE3210_CFG_EXTENT, DRV_NAME)) {
123 retval = -EBUSY;
124 goto out1;
125 }
126
127#if NE3210_DEBUG & NE3210_D_PROBE
128 printk("ne3210-debug: probe at %#x, ID %s\n", ioaddr, edev->id.sig);
129 printk("ne3210-debug: config regs: %#x %#x\n",
130 inb(ioaddr + NE3210_CFG1), inb(ioaddr + NE3210_CFG2));
131#endif
132
133
134 port_index = inb(ioaddr + NE3210_CFG2) >> 6;
135 printk("ne3210.c: NE3210 in EISA slot %d, media: %s, addr:",
136 edev->slot, ifmap[port_index]);
137 for(i = 0; i < ETHER_ADDR_LEN; i++)
138 printk(" %02x", (dev->dev_addr[i] = inb(ioaddr + NE3210_SA_PROM + i)));
139
140
141 /* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */
142 dev->irq = irq_map[(inb(ioaddr + NE3210_CFG2) >> 3) & 0x07];
143 printk(".\nne3210.c: using IRQ %d, ", dev->irq);
144
145 retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev);
146 if (retval) {
147 printk (" unable to get IRQ %d.\n", dev->irq);
148 goto out2;
149 }
150
151 phys_mem = shmem_map[inb(ioaddr + NE3210_CFG2) & 0x07] * 0x1000;
152
153 /*
154 BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
155 the card mem within the region covered by `normal' RAM !!!
156 */
157 if (phys_mem > 1024*1024) { /* phys addr > 1MB */
158 if (phys_mem < virt_to_phys(high_memory)) {
159 printk(KERN_CRIT "ne3210.c: Card RAM overlaps with normal memory!!!\n");
160 printk(KERN_CRIT "ne3210.c: Use EISA SCU to set card memory below 1MB,\n");
161 printk(KERN_CRIT "ne3210.c: or to an address above 0x%lx.\n", virt_to_phys(high_memory));
162 printk(KERN_CRIT "ne3210.c: Driver NOT installed.\n");
163 retval = -EINVAL;
164 goto out3;
165 }
166 }
167
168 if (!request_mem_region (phys_mem, NE3210_STOP_PG*0x100, DRV_NAME)) {
169 printk ("ne3210.c: Unable to request shared memory at physical address %#lx\n",
170 phys_mem);
171 goto out3;
172 }
173
174 printk("%dkB memory at physical address %#lx\n",
175 NE3210_STOP_PG/4, phys_mem);
176
177 ei_status.mem = ioremap(phys_mem, NE3210_STOP_PG*0x100);
178 if (!ei_status.mem) {
179 printk(KERN_ERR "ne3210.c: Unable to remap card memory !!\n");
180 printk(KERN_ERR "ne3210.c: Driver NOT installed.\n");
181 retval = -EAGAIN;
182 goto out4;
183 }
184 printk("ne3210.c: remapped %dkB card memory to virtual address %p\n",
185 NE3210_STOP_PG/4, ei_status.mem);
186 dev->mem_start = (unsigned long)ei_status.mem;
187 dev->mem_end = dev->mem_start + (NE3210_STOP_PG - NE3210_START_PG)*256;
188
189 /* The 8390 offset is zero for the NE3210 */
190 dev->base_addr = ioaddr;
191
192 ei_status.name = "NE3210";
193 ei_status.tx_start_page = NE3210_START_PG;
194 ei_status.rx_start_page = NE3210_START_PG + TX_PAGES;
195 ei_status.stop_page = NE3210_STOP_PG;
196 ei_status.word16 = 1;
197 ei_status.priv = phys_mem;
198
199 if (ei_debug > 0)
200 printk(version);
201
202 ei_status.reset_8390 = &ne3210_reset_8390;
203 ei_status.block_input = &ne3210_block_input;
204 ei_status.block_output = &ne3210_block_output;
205 ei_status.get_8390_hdr = &ne3210_get_8390_hdr;
206
207 dev->open = &ne3210_open;
208 dev->stop = &ne3210_close;
209#ifdef CONFIG_NET_POLL_CONTROLLER
210 dev->poll_controller = ei_poll;
211#endif
212 dev->if_port = ifmap_val[port_index];
213
214 if ((retval = register_netdev (dev)))
215 goto out5;
216
217 NS8390_init(dev, 0);
218 return 0;
219
220 out5:
221 iounmap(ei_status.mem);
222 out4:
223 release_mem_region (phys_mem, NE3210_STOP_PG*0x100);
224 out3:
225 free_irq (dev->irq, dev);
226 out2:
227 release_region (ioaddr + NE3210_CFG1, NE3210_CFG_EXTENT);
228 out1:
229 release_region (ioaddr, NE3210_IO_EXTENT);
230 out:
231 free_netdev (dev);
232
233 return retval;
234}
235
236static int __devexit ne3210_eisa_remove (struct device *device)
237{
238 struct net_device *dev = device->driver_data;
239 unsigned long ioaddr = to_eisa_device (device)->base_addr;
240
241 unregister_netdev (dev);
242 iounmap(ei_status.mem);
243 release_mem_region (ei_status.priv, NE3210_STOP_PG*0x100);
244 free_irq (dev->irq, dev);
245 release_region (ioaddr + NE3210_CFG1, NE3210_CFG_EXTENT);
246 release_region (ioaddr, NE3210_IO_EXTENT);
247 free_netdev (dev);
248
249 return 0;
250}
251
252/*
253 * Reset by toggling the "Board Enable" bits (bit 2 and 0).
254 */
255
256static void ne3210_reset_8390(struct net_device *dev)
257{
258 unsigned short ioaddr = dev->base_addr;
259
260 outb(0x04, ioaddr + NE3210_RESET_PORT);
261 if (ei_debug > 1) printk("%s: resetting the NE3210...", dev->name);
262
263 mdelay(2);
264
265 ei_status.txing = 0;
266 outb(0x01, ioaddr + NE3210_RESET_PORT);
267 if (ei_debug > 1) printk("reset done\n");
268
269 return;
270}
271
272/*
273 * Note: In the following three functions is the implicit assumption
274 * that the associated memcpy will only use "rep; movsl" as long as
275 * we keep the counts as some multiple of doublewords. This is a
276 * requirement of the hardware, and also prevents us from using
277 * eth_io_copy_and_sum() since we can't guarantee it will limit
278 * itself to doubleword access.
279 */
280
281/*
282 * Grab the 8390 specific header. Similar to the block_input routine, but
283 * we don't need to be concerned with ring wrap as the header will be at
284 * the start of a page, so we optimize accordingly. (A single doubleword.)
285 */
286
287static void
288ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
289{
290 void __iomem *hdr_start = ei_status.mem + ((ring_page - NE3210_START_PG)<<8);
291 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
292 hdr->count = (hdr->count + 3) & ~3; /* Round up allocation. */
293}
294
295/*
296 * Block input and output are easy on shared memory ethercards, the only
297 * complication is when the ring buffer wraps. The count will already
298 * be rounded up to a doubleword value via ne3210_get_8390_hdr() above.
299 */
300
301static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb,
302 int ring_offset)
303{
304 void __iomem *start = ei_status.mem + ring_offset - NE3210_START_PG*256;
305
306 if (ring_offset + count > NE3210_STOP_PG*256) {
307 /* Packet wraps over end of ring buffer. */
308 int semi_count = NE3210_STOP_PG*256 - ring_offset;
309 memcpy_fromio(skb->data, start, semi_count);
310 count -= semi_count;
311 memcpy_fromio(skb->data + semi_count,
312 ei_status.mem + TX_PAGES*256, count);
313 } else {
314 /* Packet is in one chunk. */
315 memcpy_fromio(skb->data, start, count);
316 }
317}
318
319static void ne3210_block_output(struct net_device *dev, int count,
320 const unsigned char *buf, int start_page)
321{
322 void __iomem *shmem = ei_status.mem + ((start_page - NE3210_START_PG)<<8);
323
324 count = (count + 3) & ~3; /* Round up to doubleword */
325 memcpy_toio(shmem, buf, count);
326}
327
328static int ne3210_open(struct net_device *dev)
329{
330 ei_open(dev);
331 return 0;
332}
333
334static int ne3210_close(struct net_device *dev)
335{
336
337 if (ei_debug > 1)
338 printk("%s: Shutting down ethercard.\n", dev->name);
339
340 ei_close(dev);
341 return 0;
342}
343
344static struct eisa_device_id ne3210_ids[] = {
345 { "EGL0101" },
346 { "NVL1801" },
347 { "" },
348};
349
350static struct eisa_driver ne3210_eisa_driver = {
351 .id_table = ne3210_ids,
352 .driver = {
353 .name = "ne3210",
354 .probe = ne3210_eisa_probe,
355 .remove = __devexit_p (ne3210_eisa_remove),
356 },
357};
358
359MODULE_DESCRIPTION("NE3210 EISA Ethernet driver");
360MODULE_LICENSE("GPL");
361MODULE_DEVICE_TABLE(eisa, ne3210_ids);
362
363int ne3210_init(void)
364{
365 return eisa_driver_register (&ne3210_eisa_driver);
366}
367
368void ne3210_cleanup(void)
369{
370 eisa_driver_unregister (&ne3210_eisa_driver);
371}
372
373module_init (ne3210_init);
374module_exit (ne3210_cleanup);