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