This source file includes following definitions.
- ac3200_probe
- ac_probe1
- ac_open
- ac_reset_8390
- ac_get_8390_hdr
- ac_block_input
- ac_block_output
- ac_close_card
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 static const char *version =
18 "ac3200.c:v1.01 7/1/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
19
20 #include <linux/module.h>
21
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
24 #include <linux/errno.h>
25 #include <linux/string.h>
26 #include <linux/netdevice.h>
27 #include <linux/etherdevice.h>
28
29 #include <asm/system.h>
30 #include <asm/io.h>
31
32 #include "8390.h"
33
34
35 #define AC_NIC_BASE 0x00
36 #define AC_SA_PROM 0x16
37 #define AC_ADDR0 0x00
38 #define AC_ADDR1 0x40
39 #define AC_ADDR2 0x90
40 #define AC_ID_PORT 0xC80
41 #define AC_EISA_ID 0x0110d305
42 #define AC_RESET_PORT 0xC84
43 #define AC_RESET 0x00
44 #define AC_ENABLE 0x01
45 #define AC_CONFIG 0xC90
46
47 #define AC_IO_EXTENT 0x10
48
49
50
51
52
53
54
55
56
57 static unsigned char config2irqmap[8] = {15, 12, 11, 10, 9, 7, 5, 3};
58 static int addrmap[8] =
59 {0xFF0000, 0xFE0000, 0xFD0000, 0xFFF0000, 0xFFE0000, 0xFFC0000, 0xD0000, 0 };
60 static const char *port_name[4] = { "10baseT", "invalid", "AUI", "10base2"};
61
62 #define config2irq(configval) config2irqmap[((configval) >> 3) & 7]
63 #define config2mem(configval) addrmap[(configval) & 7]
64 #define config2name(configval) port_name[((configval) >> 6) & 3]
65
66
67 #define AC_START_PG 0x00
68 #define AC_STOP_PG 0x80
69
70 int ac3200_probe(struct device *dev);
71 static int ac_probe1(int ioaddr, struct device *dev);
72
73 static int ac_open(struct device *dev);
74 static void ac_reset_8390(struct device *dev);
75 static void ac_block_input(struct device *dev, int count,
76 struct sk_buff *skb, int ring_offset);
77 static void ac_block_output(struct device *dev, const int count,
78 const unsigned char *buf, const int start_page);
79 static void ac_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
80 int ring_page);
81
82 static int ac_close_card(struct device *dev);
83
84
85
86
87
88
89
90
91 int ac3200_probe(struct device *dev)
92 {
93 unsigned short ioaddr = dev->base_addr;
94
95 if (ioaddr > 0x1ff)
96 return ac_probe1(ioaddr, dev);
97 else if (ioaddr > 0)
98 return ENXIO;
99
100
101 if ( ! EISA_bus)
102 return ENXIO;
103
104 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000)
105 if (ac_probe1(ioaddr, dev) == 0)
106 return 0;
107
108 return ENODEV;
109 }
110
111 static int ac_probe1(int ioaddr, struct device *dev)
112 {
113 int i;
114
115 #ifndef final_version
116 printk("AC3200 ethercard probe at %#3x:", ioaddr);
117
118 for(i = 0; i < 6; i++)
119 printk(" %02x", inb(ioaddr + AC_SA_PROM + i));
120 #endif
121
122
123
124 if (inb(ioaddr + AC_SA_PROM + 0) != AC_ADDR0
125 || inb(ioaddr + AC_SA_PROM + 1) != AC_ADDR1
126 || inb(ioaddr + AC_SA_PROM + 2) != AC_ADDR2 ) {
127 #ifndef final_version
128 printk(" not found (invalid prefix).\n");
129 #endif
130 return ENODEV;
131 }
132
133
134 for (i = 0; i < 4; i++)
135 if (inl(ioaddr + AC_ID_PORT) != AC_EISA_ID) {
136 printk("EISA ID mismatch, %8x vs %8x.\n",
137 inl(ioaddr + AC_EISA_ID), AC_EISA_ID);
138 return ENODEV;
139 }
140
141 for(i = 0; i < ETHER_ADDR_LEN; i++)
142 dev->dev_addr[i] = inb(ioaddr + AC_SA_PROM + i);
143
144 #ifndef final_version
145 printk("\nAC3200 ethercard configuration register is %#02x,"
146 " EISA ID %02x %02x %02x %02x.\n", inb(ioaddr + AC_CONFIG),
147 inb(ioaddr + AC_ID_PORT + 0), inb(ioaddr + AC_ID_PORT + 1),
148 inb(ioaddr + AC_ID_PORT + 2), inb(ioaddr + AC_ID_PORT + 3));
149 #endif
150
151
152 if (dev->irq == 0)
153 dev->irq = config2irq(inb(ioaddr + AC_CONFIG));
154 else if (dev->irq == 2)
155 dev->irq = 9;
156
157 if (request_irq(dev->irq, ei_interrupt, 0, "ac3200")) {
158 printk (" unable to get IRQ %d.\n", dev->irq);
159 return EAGAIN;
160 }
161
162 request_region(ioaddr, AC_IO_EXTENT, "ac3200");
163
164 dev->base_addr = ioaddr;
165
166 #ifdef notyet
167 if (dev->mem_start) {
168 for (i = 0; i < 7; i++)
169 if (addrmap[i] == dev->mem_start)
170 break;
171 if (i >= 7)
172 i = 0;
173 outb((inb(ioaddr + AC_CONFIG) & ~7) | i, ioaddr + AC_CONFIG);
174 }
175 #endif
176
177 dev->if_port = inb(ioaddr + AC_CONFIG) >> 6;
178 dev->mem_start = config2mem(inb(ioaddr + AC_CONFIG));
179 dev->rmem_start = dev->mem_start + TX_PAGES*256;
180 dev->mem_end = dev->rmem_end = dev->mem_start
181 + (AC_STOP_PG - AC_START_PG)*256;
182
183 ethdev_init(dev);
184
185 ei_status.name = "AC3200";
186 ei_status.tx_start_page = AC_START_PG;
187 ei_status.rx_start_page = AC_START_PG + TX_PAGES;
188 ei_status.stop_page = AC_STOP_PG;
189 ei_status.word16 = 1;
190
191 printk("\n%s: AC3200 at %#x, IRQ %d, %s port, shared memory %#lx-%#lx.\n",
192 dev->name, ioaddr, dev->irq, port_name[dev->if_port],
193 dev->mem_start, dev->mem_end-1);
194
195 if (ei_debug > 0)
196 printk(version);
197
198 ei_status.reset_8390 = &ac_reset_8390;
199 ei_status.block_input = &ac_block_input;
200 ei_status.block_output = &ac_block_output;
201 ei_status.get_8390_hdr = &ac_get_8390_hdr;
202
203 dev->open = &ac_open;
204 dev->stop = &ac_close_card;
205 NS8390_init(dev, 0);
206 return 0;
207 }
208
209 static int ac_open(struct device *dev)
210 {
211 int rc;
212 #ifdef notyet
213
214 int ioaddr = dev->base_addr;
215
216 if (request_irq(dev->irq, ei_interrupt, 0, "ac3200"))
217 return -EAGAIN;
218 #endif
219
220 rc = ei_open(dev);
221 if (rc != 0) return rc;
222
223 MOD_INC_USE_COUNT;
224
225 return 0;
226 }
227
228 static void ac_reset_8390(struct device *dev)
229 {
230 ushort ioaddr = dev->base_addr;
231
232 outb(AC_RESET, ioaddr + AC_RESET_PORT);
233 if (ei_debug > 1) printk("resetting AC3200, t=%ld...", jiffies);
234
235 ei_status.txing = 0;
236 outb(AC_ENABLE, ioaddr + AC_RESET_PORT);
237 if (ei_debug > 1) printk("reset done\n");
238
239 return;
240 }
241
242
243
244
245
246 static void
247 ac_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
248 {
249 unsigned long hdr_start = dev->mem_start + ((ring_page - AC_START_PG)<<8);
250 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
251 }
252
253
254
255
256 static void ac_block_input(struct device *dev, int count, struct sk_buff *skb,
257 int ring_offset)
258 {
259 unsigned long xfer_start = dev->mem_start + ring_offset - (AC_START_PG<<8);
260
261 if (xfer_start + count > dev->rmem_end) {
262
263 int semi_count = dev->rmem_end - xfer_start;
264 memcpy_fromio(skb->data, xfer_start, semi_count);
265 count -= semi_count;
266 memcpy_fromio(skb->data + semi_count, dev->rmem_start, count);
267 } else {
268
269 eth_io_copy_and_sum(skb, xfer_start, count, 0);
270 }
271 }
272
273 static void ac_block_output(struct device *dev, int count,
274 const unsigned char *buf, int start_page)
275 {
276 unsigned long shmem = dev->mem_start + ((start_page - AC_START_PG)<<8);
277
278 memcpy_toio(shmem, buf, count);
279 }
280
281 static int ac_close_card(struct device *dev)
282 {
283 dev->start = 0;
284 dev->tbusy = 1;
285
286 if (ei_debug > 1)
287 printk("%s: Shutting down ethercard.\n", dev->name);
288
289 #ifdef notyet
290
291 outb(0x00, ioaddr + 6);
292 free_irq(dev->irq);
293 irq2dev_map[dev->irq] = 0;
294 #endif
295
296 NS8390_init(dev, 0);
297
298 MOD_DEC_USE_COUNT;
299
300 return 0;
301 }
302
303 #ifdef MODULE
304 static char devicename[9] = { 0, };
305 static struct device dev_ac3200 = {
306 devicename,
307 0, 0, 0, 0,
308 0, 0,
309 0, 0, 0, NULL, ac3200_probe };
310
311 static int io = 0;
312 static int irq = 0;
313
314 int init_module(void)
315 {
316 dev_ac3200.base_addr = io;
317 dev_ac3200.irq = irq;
318 if (register_netdev(&dev_ac3200) != 0) {
319 printk("ac3200: register_netdev() returned non-zero.\n");
320 return -EIO;
321 }
322 return 0;
323 }
324
325 void
326 cleanup_module(void)
327 {
328 unregister_netdev(&dev_ac3200);
329
330
331 free_irq(dev_ac3200.irq);
332 release_region(dev_ac3200.base_addr, AC_IO_EXTENT);
333 }
334 #endif
335
336
337
338
339
340
341
342
343