1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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>
39#include <linux/mm.h>
40
41#include <asm/io.h>
42#include <asm/system.h>
43
44#include "8390.h"
45
46#define DRV_NAME "ne3210"
47
48static 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
55#define NE3210_STOP_PG 0x80
56
57#define NE3210_IO_EXTENT 0x20
58#define NE3210_SA_PROM 0x16
59#define NE3210_RESET_PORT 0xc84
60#define NE3210_NIC_OFFSET 0x00
61
62#define NE3210_ADDR0 0x00
63#define NE3210_ADDR1 0x00
64#define NE3210_ADDR2 0x1b
65
66#define NE3210_CFG1 0xc84
67#define NE3210_CFG2 0xc90
68#define NE3210_CFG_EXTENT (NE3210_CFG2 - NE3210_CFG1 + 1)
69
70
71
72
73
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
101 if (!(dev = alloc_ei_netdev ())) {
102 printk ("ne3210.c: unable to allocate memory for dev!\n");
103 return -ENOMEM;
104 }
105
106 SET_NETDEV_DEV(dev, device);
107 dev_set_drvdata(device, 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
127 port_index = inb(ioaddr + NE3210_CFG2) >> 6;
128 for(i = 0; i < ETHER_ADDR_LEN; i++)
129 dev->dev_addr[i] = inb(ioaddr + NE3210_SA_PROM + i);
130 printk("ne3210.c: NE3210 in EISA slot %d, media: %s, addr: %pM.\n",
131 edev->slot, ifmap[port_index], dev->dev_addr);
132
133
134 dev->irq = irq_map[(inb(ioaddr + NE3210_CFG2) >> 3) & 0x07];
135 printk("ne3210.c: using IRQ %d, ", dev->irq);
136
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
147
148
149 if (phys_mem > 1024*1024) {
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%llx.\n",
154 (u64)virt_to_phys(high_memory));
155 printk(KERN_CRIT "ne3210.c: Driver NOT installed.\n");
156 retval = -EINVAL;
157 goto out3;
158 }
159 }
160
161 if (!request_mem_region (phys_mem, NE3210_STOP_PG*0x100, DRV_NAME)) {
162 printk ("ne3210.c: Unable to request shared memory at physical address %#lx\n",
163 phys_mem);
164 goto out3;
165 }
166
167 printk("%dkB memory at physical address %#lx\n",
168 NE3210_STOP_PG/4, phys_mem);
169
170 ei_status.mem = ioremap(phys_mem, NE3210_STOP_PG*0x100);
171 if (!ei_status.mem) {
172 printk(KERN_ERR "ne3210.c: Unable to remap card memory !!\n");
173 printk(KERN_ERR "ne3210.c: Driver NOT installed.\n");
174 retval = -EAGAIN;
175 goto out4;
176 }
177 printk("ne3210.c: remapped %dkB card memory to virtual address %p\n",
178 NE3210_STOP_PG/4, ei_status.mem);
179 dev->mem_start = (unsigned long)ei_status.mem;
180 dev->mem_end = dev->mem_start + (NE3210_STOP_PG - NE3210_START_PG)*256;
181
182
183 dev->base_addr = ioaddr;
184
185 ei_status.name = "NE3210";
186 ei_status.tx_start_page = NE3210_START_PG;
187 ei_status.rx_start_page = NE3210_START_PG + TX_PAGES;
188 ei_status.stop_page = NE3210_STOP_PG;
189 ei_status.word16 = 1;
190 ei_status.priv = phys_mem;
191
192 if (ei_debug > 0)
193 printk("ne3210 loaded.\n");
194
195 ei_status.reset_8390 = &ne3210_reset_8390;
196 ei_status.block_input = &ne3210_block_input;
197 ei_status.block_output = &ne3210_block_output;
198 ei_status.get_8390_hdr = &ne3210_get_8390_hdr;
199
200 dev->netdev_ops = &ei_netdev_ops;
201
202 dev->if_port = ifmap_val[port_index];
203
204 if ((retval = register_netdev (dev)))
205 goto out5;
206
207 NS8390_init(dev, 0);
208 return 0;
209
210 out5:
211 iounmap(ei_status.mem);
212 out4:
213 release_mem_region (phys_mem, NE3210_STOP_PG*0x100);
214 out3:
215 free_irq (dev->irq, dev);
216 out2:
217 release_region (ioaddr + NE3210_CFG1, NE3210_CFG_EXTENT);
218 out1:
219 release_region (ioaddr, NE3210_IO_EXTENT);
220 out:
221 free_netdev (dev);
222
223 return retval;
224}
225
226static int __devexit ne3210_eisa_remove (struct device *device)
227{
228 struct net_device *dev = dev_get_drvdata(device);
229 unsigned long ioaddr = to_eisa_device (device)->base_addr;
230
231 unregister_netdev (dev);
232 iounmap(ei_status.mem);
233 release_mem_region (ei_status.priv, NE3210_STOP_PG*0x100);
234 free_irq (dev->irq, dev);
235 release_region (ioaddr + NE3210_CFG1, NE3210_CFG_EXTENT);
236 release_region (ioaddr, NE3210_IO_EXTENT);
237 free_netdev (dev);
238
239 return 0;
240}
241
242
243
244
245
246static void ne3210_reset_8390(struct net_device *dev)
247{
248 unsigned short ioaddr = dev->base_addr;
249
250 outb(0x04, ioaddr + NE3210_RESET_PORT);
251 if (ei_debug > 1) printk("%s: resetting the NE3210...", dev->name);
252
253 mdelay(2);
254
255 ei_status.txing = 0;
256 outb(0x01, ioaddr + NE3210_RESET_PORT);
257 if (ei_debug > 1) printk("reset done\n");
258
259 return;
260}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277static void
278ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
279{
280 void __iomem *hdr_start = ei_status.mem + ((ring_page - NE3210_START_PG)<<8);
281 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
282 hdr->count = (hdr->count + 3) & ~3;
283}
284
285
286
287
288
289
290
291static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb,
292 int ring_offset)
293{
294 void __iomem *start = ei_status.mem + ring_offset - NE3210_START_PG*256;
295
296 if (ring_offset + count > NE3210_STOP_PG*256) {
297
298 int semi_count = NE3210_STOP_PG*256 - ring_offset;
299 memcpy_fromio(skb->data, start, semi_count);
300 count -= semi_count;
301 memcpy_fromio(skb->data + semi_count,
302 ei_status.mem + TX_PAGES*256, count);
303 } else {
304
305 memcpy_fromio(skb->data, start, count);
306 }
307}
308
309static void ne3210_block_output(struct net_device *dev, int count,
310 const unsigned char *buf, int start_page)
311{
312 void __iomem *shmem = ei_status.mem + ((start_page - NE3210_START_PG)<<8);
313
314 count = (count + 3) & ~3;
315 memcpy_toio(shmem, buf, count);
316}
317
318static struct eisa_device_id ne3210_ids[] = {
319 { "EGL0101" },
320 { "NVL1801" },
321 { "" },
322};
323MODULE_DEVICE_TABLE(eisa, ne3210_ids);
324
325static struct eisa_driver ne3210_eisa_driver = {
326 .id_table = ne3210_ids,
327 .driver = {
328 .name = "ne3210",
329 .probe = ne3210_eisa_probe,
330 .remove = __devexit_p (ne3210_eisa_remove),
331 },
332};
333
334MODULE_DESCRIPTION("NE3210 EISA Ethernet driver");
335MODULE_LICENSE("GPL");
336MODULE_DEVICE_TABLE(eisa, ne3210_ids);
337
338static int ne3210_init(void)
339{
340 return eisa_driver_register (&ne3210_eisa_driver);
341}
342
343static void ne3210_cleanup(void)
344{
345 eisa_driver_unregister (&ne3210_eisa_driver);
346}
347
348module_init (ne3210_init);
349module_exit (ne3210_cleanup);
350