[PATCH] iomem annotations (ac3200.c)
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / net / ac3200.c
1 /* ac3200.c: A driver for the Ansel Communications EISA ethernet adaptor. */
2 /*
3 Written 1993, 1994 by Donald Becker.
4 Copyright 1993 United States Government as represented by the Director,
5 National Security Agency. This software may only be used and distributed
6 according to the terms of the GNU General Public License as modified by SRC,
7 incorporated herein by reference.
8
9 The author may be reached as becker@scyld.com, or C/O
10 Scyld Computing Corporation
11 410 Severn Ave., Suite 210
12 Annapolis MD 21403
13
14 This is driver for the Ansel Communications Model 3200 EISA Ethernet LAN
15 Adapter. The programming information is from the users manual, as related
16 by glee@ardnassak.math.clemson.edu.
17
18 Changelog:
19
20 Paul Gortmaker 05/98 : add support for shared mem above 1MB.
21
22 */
23
24 static const char version[] =
25 "ac3200.c:v1.01 7/1/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
26
27 #include <linux/module.h>
28 #include <linux/eisa.h>
29 #include <linux/kernel.h>
30 #include <linux/errno.h>
31 #include <linux/string.h>
32 #include <linux/netdevice.h>
33 #include <linux/etherdevice.h>
34 #include <linux/init.h>
35
36 #include <asm/system.h>
37 #include <asm/io.h>
38 #include <asm/irq.h>
39
40 #include "8390.h"
41
42 #define DRV_NAME "ac3200"
43
44 /* Offsets from the base address. */
45 #define AC_NIC_BASE 0x00
46 #define AC_SA_PROM 0x16 /* The station address PROM. */
47 #define AC_ADDR0 0x00 /* Prefix station address values. */
48 #define AC_ADDR1 0x40
49 #define AC_ADDR2 0x90
50 #define AC_ID_PORT 0xC80
51 #define AC_EISA_ID 0x0110d305
52 #define AC_RESET_PORT 0xC84
53 #define AC_RESET 0x00
54 #define AC_ENABLE 0x01
55 #define AC_CONFIG 0xC90 /* The configuration port. */
56
57 #define AC_IO_EXTENT 0x20
58 /* Actually accessed is:
59 * AC_NIC_BASE (0-15)
60 * AC_SA_PROM (0-5)
61 * AC_ID_PORT (0-3)
62 * AC_RESET_PORT
63 * AC_CONFIG
64 */
65
66 /* Decoding of the configuration register. */
67 static unsigned char config2irqmap[8] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
68 static int addrmap[8] =
69 {0xFF0000, 0xFE0000, 0xFD0000, 0xFFF0000, 0xFFE0000, 0xFFC0000, 0xD0000, 0 };
70 static const char *port_name[4] = { "10baseT", "invalid", "AUI", "10base2"};
71
72 #define config2irq(configval) config2irqmap[((configval) >> 3) & 7]
73 #define config2mem(configval) addrmap[(configval) & 7]
74 #define config2name(configval) port_name[((configval) >> 6) & 3]
75
76 /* First and last 8390 pages. */
77 #define AC_START_PG 0x00 /* First page of 8390 TX buffer */
78 #define AC_STOP_PG 0x80 /* Last page +1 of the 8390 RX ring */
79
80 static int ac_probe1(int ioaddr, struct net_device *dev);
81
82 static int ac_open(struct net_device *dev);
83 static void ac_reset_8390(struct net_device *dev);
84 static void ac_block_input(struct net_device *dev, int count,
85 struct sk_buff *skb, int ring_offset);
86 static void ac_block_output(struct net_device *dev, const int count,
87 const unsigned char *buf, const int start_page);
88 static void ac_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
89 int ring_page);
90
91 static int ac_close_card(struct net_device *dev);
92 \f
93
94 /* Probe for the AC3200.
95
96 The AC3200 can be identified by either the EISA configuration registers,
97 or the unique value in the station address PROM.
98 */
99
100 static int __init do_ac3200_probe(struct net_device *dev)
101 {
102 unsigned short ioaddr = dev->base_addr;
103 int irq = dev->irq;
104 int mem_start = dev->mem_start;
105
106 SET_MODULE_OWNER(dev);
107
108 if (ioaddr > 0x1ff) /* Check a single specified location. */
109 return ac_probe1(ioaddr, dev);
110 else if (ioaddr > 0) /* Don't probe at all. */
111 return -ENXIO;
112
113 if ( ! EISA_bus)
114 return -ENXIO;
115
116 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
117 if (ac_probe1(ioaddr, dev) == 0)
118 return 0;
119 dev->irq = irq;
120 dev->mem_start = mem_start;
121 }
122
123 return -ENODEV;
124 }
125
126 static void cleanup_card(struct net_device *dev)
127 {
128 /* Someday free_irq may be in ac_close_card() */
129 free_irq(dev->irq, dev);
130 release_region(dev->base_addr, AC_IO_EXTENT);
131 iounmap(ei_status.mem);
132 }
133
134 #ifndef MODULE
135 struct net_device * __init ac3200_probe(int unit)
136 {
137 struct net_device *dev = alloc_ei_netdev();
138 int err;
139
140 if (!dev)
141 return ERR_PTR(-ENOMEM);
142
143 sprintf(dev->name, "eth%d", unit);
144 netdev_boot_setup_check(dev);
145
146 err = do_ac3200_probe(dev);
147 if (err)
148 goto out;
149 return dev;
150 out:
151 free_netdev(dev);
152 return ERR_PTR(err);
153 }
154 #endif
155
156 static int __init ac_probe1(int ioaddr, struct net_device *dev)
157 {
158 int i, retval;
159
160 if (!request_region(ioaddr, AC_IO_EXTENT, DRV_NAME))
161 return -EBUSY;
162
163 if (inb_p(ioaddr + AC_ID_PORT) == 0xff) {
164 retval = -ENODEV;
165 goto out;
166 }
167
168 if (inl(ioaddr + AC_ID_PORT) != AC_EISA_ID) {
169 retval = -ENODEV;
170 goto out;
171 }
172
173 #ifndef final_version
174 printk(KERN_DEBUG "AC3200 ethercard configuration register is %#02x,"
175 " EISA ID %02x %02x %02x %02x.\n", inb(ioaddr + AC_CONFIG),
176 inb(ioaddr + AC_ID_PORT + 0), inb(ioaddr + AC_ID_PORT + 1),
177 inb(ioaddr + AC_ID_PORT + 2), inb(ioaddr + AC_ID_PORT + 3));
178 #endif
179
180 printk("AC3200 in EISA slot %d, node", ioaddr/0x1000);
181 for(i = 0; i < 6; i++)
182 printk(" %02x", dev->dev_addr[i] = inb(ioaddr + AC_SA_PROM + i));
183
184 #if 0
185 /* Check the vendor ID/prefix. Redundant after checking the EISA ID */
186 if (inb(ioaddr + AC_SA_PROM + 0) != AC_ADDR0
187 || inb(ioaddr + AC_SA_PROM + 1) != AC_ADDR1
188 || inb(ioaddr + AC_SA_PROM + 2) != AC_ADDR2 ) {
189 printk(", not found (invalid prefix).\n");
190 retval = -ENODEV;
191 goto out;
192 }
193 #endif
194
195 /* Assign and allocate the interrupt now. */
196 if (dev->irq == 0) {
197 dev->irq = config2irq(inb(ioaddr + AC_CONFIG));
198 printk(", using");
199 } else {
200 dev->irq = irq_canonicalize(dev->irq);
201 printk(", assigning");
202 }
203
204 retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev);
205 if (retval) {
206 printk (" nothing! Unable to get IRQ %d.\n", dev->irq);
207 goto out1;
208 }
209
210 printk(" IRQ %d, %s port\n", dev->irq, port_name[dev->if_port]);
211
212 dev->base_addr = ioaddr;
213
214 #ifdef notyet
215 if (dev->mem_start) { /* Override the value from the board. */
216 for (i = 0; i < 7; i++)
217 if (addrmap[i] == dev->mem_start)
218 break;
219 if (i >= 7)
220 i = 0;
221 outb((inb(ioaddr + AC_CONFIG) & ~7) | i, ioaddr + AC_CONFIG);
222 }
223 #endif
224
225 dev->if_port = inb(ioaddr + AC_CONFIG) >> 6;
226 dev->mem_start = config2mem(inb(ioaddr + AC_CONFIG));
227
228 printk("%s: AC3200 at %#3x with %dkB memory at physical address %#lx.\n",
229 dev->name, ioaddr, AC_STOP_PG/4, dev->mem_start);
230
231 /*
232 * BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
233 * the card mem within the region covered by `normal' RAM !!!
234 *
235 * ioremap() will fail in that case.
236 */
237 ei_status.mem = ioremap(dev->mem_start, AC_STOP_PG*0x100);
238 if (!ei_status.mem) {
239 printk(KERN_ERR "ac3200.c: Unable to remap card memory above 1MB !!\n");
240 printk(KERN_ERR "ac3200.c: Try using EISA SCU to set memory below 1MB.\n");
241 printk(KERN_ERR "ac3200.c: Driver NOT installed.\n");
242 retval = -EINVAL;
243 goto out1;
244 }
245 printk("ac3200.c: remapped %dkB card memory to virtual address %p\n",
246 AC_STOP_PG/4, ei_status.mem);
247
248 dev->mem_start = (unsigned long)ei_status.mem;
249 dev->mem_end = dev->mem_start + (AC_STOP_PG - AC_START_PG)*256;
250
251 ei_status.name = "AC3200";
252 ei_status.tx_start_page = AC_START_PG;
253 ei_status.rx_start_page = AC_START_PG + TX_PAGES;
254 ei_status.stop_page = AC_STOP_PG;
255 ei_status.word16 = 1;
256
257 if (ei_debug > 0)
258 printk(version);
259
260 ei_status.reset_8390 = &ac_reset_8390;
261 ei_status.block_input = &ac_block_input;
262 ei_status.block_output = &ac_block_output;
263 ei_status.get_8390_hdr = &ac_get_8390_hdr;
264
265 dev->open = &ac_open;
266 dev->stop = &ac_close_card;
267 #ifdef CONFIG_NET_POLL_CONTROLLER
268 dev->poll_controller = ei_poll;
269 #endif
270 NS8390_init(dev, 0);
271
272 retval = register_netdev(dev);
273 if (retval)
274 goto out2;
275 return 0;
276 out2:
277 if (ei_status.reg0)
278 iounmap(ei_status.mem);
279 out1:
280 free_irq(dev->irq, dev);
281 out:
282 release_region(ioaddr, AC_IO_EXTENT);
283 return retval;
284 }
285
286 static int ac_open(struct net_device *dev)
287 {
288 #ifdef notyet
289 /* Someday we may enable the IRQ and shared memory here. */
290 int ioaddr = dev->base_addr;
291 #endif
292
293 ei_open(dev);
294 return 0;
295 }
296
297 static void ac_reset_8390(struct net_device *dev)
298 {
299 ushort ioaddr = dev->base_addr;
300
301 outb(AC_RESET, ioaddr + AC_RESET_PORT);
302 if (ei_debug > 1) printk("resetting AC3200, t=%ld...", jiffies);
303
304 ei_status.txing = 0;
305 outb(AC_ENABLE, ioaddr + AC_RESET_PORT);
306 if (ei_debug > 1) printk("reset done\n");
307
308 return;
309 }
310
311 /* Grab the 8390 specific header. Similar to the block_input routine, but
312 we don't need to be concerned with ring wrap as the header will be at
313 the start of a page, so we optimize accordingly. */
314
315 static void
316 ac_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
317 {
318 void __iomem *hdr_start = ei_status.mem + ((ring_page - AC_START_PG)<<8);
319 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
320 }
321
322 /* Block input and output are easy on shared memory ethercards, the only
323 complication is when the ring buffer wraps. */
324
325 static void ac_block_input(struct net_device *dev, int count, struct sk_buff *skb,
326 int ring_offset)
327 {
328 void __iomem *start = ei_status.mem + ring_offset - AC_START_PG*256;
329
330 if (ring_offset + count > AC_STOP_PG*256) {
331 /* We must wrap the input move. */
332 int semi_count = AC_STOP_PG*256 - ring_offset;
333 memcpy_fromio(skb->data, start, semi_count);
334 count -= semi_count;
335 memcpy_fromio(skb->data + semi_count,
336 ei_status.mem + TX_PAGES*256, count);
337 } else {
338 /* Packet is in one chunk -- we can copy + cksum. */
339 eth_io_copy_and_sum(skb, start, count, 0);
340 }
341 }
342
343 static void ac_block_output(struct net_device *dev, int count,
344 const unsigned char *buf, int start_page)
345 {
346 void __iomem *shmem = ei_status.mem + ((start_page - AC_START_PG)<<8);
347
348 memcpy_toio(shmem, buf, count);
349 }
350
351 static int ac_close_card(struct net_device *dev)
352 {
353 if (ei_debug > 1)
354 printk("%s: Shutting down ethercard.\n", dev->name);
355
356 #ifdef notyet
357 /* We should someday disable shared memory and interrupts. */
358 outb(0x00, ioaddr + 6); /* Disable interrupts. */
359 free_irq(dev->irq, dev);
360 #endif
361
362 ei_close(dev);
363 return 0;
364 }
365
366 #ifdef MODULE
367 #define MAX_AC32_CARDS 4 /* Max number of AC32 cards per module */
368 static struct net_device *dev_ac32[MAX_AC32_CARDS];
369 static int io[MAX_AC32_CARDS];
370 static int irq[MAX_AC32_CARDS];
371 static int mem[MAX_AC32_CARDS];
372 module_param_array(io, int, NULL, 0);
373 module_param_array(irq, int, NULL, 0);
374 module_param_array(mem, int, NULL, 0);
375 MODULE_PARM_DESC(io, "I/O base address(es)");
376 MODULE_PARM_DESC(irq, "IRQ number(s)");
377 MODULE_PARM_DESC(mem, "Memory base address(es)");
378 MODULE_DESCRIPTION("Ansel AC3200 EISA ethernet driver");
379 MODULE_LICENSE("GPL");
380
381 int
382 init_module(void)
383 {
384 struct net_device *dev;
385 int this_dev, found = 0;
386
387 for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) {
388 if (io[this_dev] == 0 && this_dev != 0)
389 break;
390 dev = alloc_ei_netdev();
391 if (!dev)
392 break;
393 dev->irq = irq[this_dev];
394 dev->base_addr = io[this_dev];
395 dev->mem_start = mem[this_dev]; /* Currently ignored by driver */
396 if (do_ac3200_probe(dev) == 0) {
397 dev_ac32[found++] = dev;
398 continue;
399 }
400 free_netdev(dev);
401 printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]);
402 break;
403 }
404 if (found)
405 return 0;
406 return -ENXIO;
407 }
408
409 void
410 cleanup_module(void)
411 {
412 int this_dev;
413
414 for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) {
415 struct net_device *dev = dev_ac32[this_dev];
416 if (dev) {
417 unregister_netdev(dev);
418 cleanup_card(dev);
419 free_netdev(dev);
420 }
421 }
422 }
423 #endif /* MODULE */