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
43#include "8390.h"
44
45#define DRV_NAME "ne3210"
46
47static void ne3210_reset_8390(struct net_device *dev);
48
49static void ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
50static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
51static void ne3210_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page);
52
53#define NE3210_START_PG 0x00
54#define NE3210_STOP_PG 0x80
55
56#define NE3210_IO_EXTENT 0x20
57#define NE3210_SA_PROM 0x16
58#define NE3210_RESET_PORT 0xc84
59#define NE3210_NIC_OFFSET 0x00
60
61#define NE3210_ADDR0 0x00
62#define NE3210_ADDR1 0x00
63#define NE3210_ADDR2 0x1b
64
65#define NE3210_CFG1 0xc84
66#define NE3210_CFG2 0xc90
67#define NE3210_CFG_EXTENT (NE3210_CFG2 - NE3210_CFG1 + 1)
68
69
70
71
72
73
74
75#define NE3210_D_PROBE 0x01
76#define NE3210_D_RX_PKT 0x02
77#define NE3210_D_TX_PKT 0x04
78#define NE3210_D_IRQ 0x08
79
80#define NE3210_DEBUG 0x0
81
82static unsigned char irq_map[] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
83static unsigned int shmem_map[] __initdata = {0xff0, 0xfe0, 0xfff0, 0xd8, 0xffe0, 0xffc0, 0xd0, 0x0};
84static const char * const ifmap[] __initconst = {"UTP", "?", "BNC", "AUI"};
85static int ifmap_val[] __initdata = {
86 IF_PORT_10BASET,
87 IF_PORT_UNKNOWN,
88 IF_PORT_10BASE2,
89 IF_PORT_AUI,
90};
91
92static int __init ne3210_eisa_probe (struct device *device)
93{
94 unsigned long ioaddr, phys_mem;
95 int i, retval, port_index;
96 struct eisa_device *edev = to_eisa_device (device);
97 struct net_device *dev;
98
99
100 if (!(dev = alloc_ei_netdev ())) {
101 printk ("ne3210.c: unable to allocate memory for dev!\n");
102 return -ENOMEM;
103 }
104
105 SET_NETDEV_DEV(dev, device);
106 dev_set_drvdata(device, dev);
107 ioaddr = edev->base_addr;
108
109 if (!request_region(ioaddr, NE3210_IO_EXTENT, DRV_NAME)) {
110 retval = -EBUSY;
111 goto out;
112 }
113
114 if (!request_region(ioaddr + NE3210_CFG1,
115 NE3210_CFG_EXTENT, DRV_NAME)) {
116 retval = -EBUSY;
117 goto out1;
118 }
119
120#if NE3210_DEBUG & NE3210_D_PROBE
121 printk("ne3210-debug: probe at %#x, ID %s\n", ioaddr, edev->id.sig);
122 printk("ne3210-debug: config regs: %#x %#x\n",
123 inb(ioaddr + NE3210_CFG1), inb(ioaddr + NE3210_CFG2));
124#endif
125
126 port_index = inb(ioaddr + NE3210_CFG2) >> 6;
127 for (i = 0; i < ETH_ALEN; i++)
128 dev->dev_addr[i] = inb(ioaddr + NE3210_SA_PROM + i);
129 printk("ne3210.c: NE3210 in EISA slot %d, media: %s, addr: %pM.\n",
130 edev->slot, ifmap[port_index], dev->dev_addr);
131
132
133 dev->irq = irq_map[(inb(ioaddr + NE3210_CFG2) >> 3) & 0x07];
134 printk("ne3210.c: using IRQ %d, ", dev->irq);
135
136 retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev);
137 if (retval) {
138 printk (" unable to get IRQ %d.\n", dev->irq);
139 goto out2;
140 }
141
142 phys_mem = shmem_map[inb(ioaddr + NE3210_CFG2) & 0x07] * 0x1000;
143
144
145
146
147
148 if (phys_mem > 1024*1024) {
149 if (phys_mem < virt_to_phys(high_memory)) {
150 printk(KERN_CRIT "ne3210.c: Card RAM overlaps with normal memory!!!\n");
151 printk(KERN_CRIT "ne3210.c: Use EISA SCU to set card memory below 1MB,\n");
152 printk(KERN_CRIT "ne3210.c: or to an address above 0x%llx.\n",
153 (u64)virt_to_phys(high_memory));
154 printk(KERN_CRIT "ne3210.c: Driver NOT installed.\n");
155 retval = -EINVAL;
156 goto out3;
157 }
158 }
159
160 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 }
165
166 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
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)
192 printk("ne3210 loaded.\n");
193
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
199 dev->netdev_ops = &ei_netdev_ops;
200
201 dev->if_port = ifmap_val[port_index];
202
203 if ((retval = register_netdev (dev)))
204 goto out5;
205
206 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);
221
222 return retval;
223}
224
225static int ne3210_eisa_remove(struct device *device)
226{
227 struct net_device *dev = dev_get_drvdata(device);
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
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274static void
275ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
276{
277 void __iomem *hdr_start = ei_status.mem + ((ring_page - NE3210_START_PG)<<8);
278 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
279 hdr->count = (hdr->count + 3) & ~3;
280}
281
282
283
284
285
286
287
288static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb,
289 int ring_offset)
290{
291 void __iomem *start = ei_status.mem + ring_offset - NE3210_START_PG*256;
292
293 if (ring_offset + count > NE3210_STOP_PG*256) {
294
295 int semi_count = NE3210_STOP_PG*256 - ring_offset;
296 memcpy_fromio(skb->data, start, semi_count);
297 count -= semi_count;
298 memcpy_fromio(skb->data + semi_count,
299 ei_status.mem + TX_PAGES*256, count);
300 } else {
301
302 memcpy_fromio(skb->data, start, count);
303 }
304}
305
306static void ne3210_block_output(struct net_device *dev, int count,
307 const unsigned char *buf, int start_page)
308{
309 void __iomem *shmem = ei_status.mem + ((start_page - NE3210_START_PG)<<8);
310
311 count = (count + 3) & ~3;
312 memcpy_toio(shmem, buf, count);
313}
314
315static struct eisa_device_id ne3210_ids[] = {
316 { "EGL0101" },
317 { "NVL1801" },
318 { "" },
319};
320MODULE_DEVICE_TABLE(eisa, ne3210_ids);
321
322static struct eisa_driver ne3210_eisa_driver = {
323 .id_table = ne3210_ids,
324 .driver = {
325 .name = "ne3210",
326 .probe = ne3210_eisa_probe,
327 .remove = ne3210_eisa_remove,
328 },
329};
330
331MODULE_DESCRIPTION("NE3210 EISA Ethernet driver");
332MODULE_LICENSE("GPL");
333MODULE_DEVICE_TABLE(eisa, ne3210_ids);
334
335static int ne3210_init(void)
336{
337 return eisa_driver_register (&ne3210_eisa_driver);
338}
339
340static void ne3210_cleanup(void)
341{
342 eisa_driver_unregister (&ne3210_eisa_driver);
343}
344
345module_init (ne3210_init);
346module_exit (ne3210_cleanup);
347