This source file includes following definitions.
- mem_on
- mem_off
- e2100_probe
- e21_probe1
- e21_open
- e21_reset_8390
- e21_get_8390_hdr
- e21_block_input
- e21_block_output
- e21_close
- init_module
- cleanup_module
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
30
31
32
33
34 static const char *version =
35 "e2100.c:v1.01 7/21/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
36
37 #include <linux/module.h>
38
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
43 #include <linux/ioport.h>
44 #include <linux/netdevice.h>
45 #include <linux/etherdevice.h>
46
47 #include <asm/io.h>
48 #include <asm/system.h>
49
50 #include "8390.h"
51
52 static int e21_probe_list[] = {0x300, 0x280, 0x380, 0x220, 0};
53
54
55
56
57 #define E21_NIC_OFFSET 0
58 #define E21_ASIC 0x10
59 #define E21_MEM_ENABLE 0x10
60 #define E21_MEM_ON 0x05
61 #define E21_MEM_ON_8 0x07
62 #define E21_MEM_BASE 0x11
63 #define E21_IRQ_LOW 0x12
64 #define E21_IRQ_HIGH 0x14
65 #define E21_MEDIA 0x14
66 #define E21_ALT_IFPORT 0x02
67 #define E21_BIG_MEM 0x04
68 #define E21_SAPROM 0x10
69 #define E21_IO_EXTENT 0x20
70
71 extern inline void mem_on(short port, volatile char *mem_base,
72 unsigned char start_page )
73 {
74
75
76 mem_base[start_page];
77 inb(port + E21_MEM_ENABLE);
78 outb(E21_MEM_ON, port + E21_MEM_ENABLE + E21_MEM_ON);
79 }
80
81 extern inline void mem_off(short port)
82 {
83 inb(port + E21_MEM_ENABLE);
84 outb(0x00, port + E21_MEM_ENABLE);
85 }
86
87
88
89
90
91 #define E21_RX_START_PG 0x00
92 #define E21_RX_STOP_PG 0x30
93 #define E21_BIG_RX_STOP_PG 0xF0
94 #define E21_TX_START_PG E21_RX_STOP_PG
95
96 int e2100_probe(struct device *dev);
97 int e21_probe1(struct device *dev, int ioaddr);
98
99 static int e21_open(struct device *dev);
100 static void e21_reset_8390(struct device *dev);
101 static void e21_block_input(struct device *dev, int count,
102 struct sk_buff *skb, int ring_offset);
103 static void e21_block_output(struct device *dev, int count,
104 const unsigned char *buf, const start_page);
105 static void e21_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
106 int ring_page);
107
108 static int e21_close(struct device *dev);
109
110
111
112
113
114
115
116
117
118 int e2100_probe(struct device *dev)
119 {
120 int *port;
121 int base_addr = dev->base_addr;
122
123 if (base_addr > 0x1ff)
124 return e21_probe1(dev, base_addr);
125 else if (base_addr != 0)
126 return ENXIO;
127
128 for (port = e21_probe_list; *port; port++) {
129 if (check_region(*port, E21_IO_EXTENT))
130 continue;
131 if (e21_probe1(dev, *port) == 0)
132 return 0;
133 }
134
135 return ENODEV;
136 }
137
138 int e21_probe1(struct device *dev, int ioaddr)
139 {
140 int i, status;
141 unsigned char *station_addr = dev->dev_addr;
142 static unsigned version_printed = 0;
143
144
145 if (inb(ioaddr + E21_SAPROM + 0) != 0x00
146 || inb(ioaddr + E21_SAPROM + 1) != 0x00
147 || inb(ioaddr + E21_SAPROM + 2) != 0x1d)
148 return ENODEV;
149
150
151 outb(E8390_NODMA + E8390_STOP, ioaddr);
152 SLOW_DOWN_IO;
153 status = inb(ioaddr);
154 if (status != 0x21 && status != 0x23)
155 return ENODEV;
156
157
158 for (i = 0; i < 6; i++)
159 station_addr[i] = inb(ioaddr + E21_SAPROM + i);
160
161 inb(ioaddr + E21_MEDIA);
162 outb(0, ioaddr + E21_ASIC);
163
164 if (ei_debug && version_printed++ == 0)
165 printk(version);
166
167
168 if (dev == NULL) {
169 printk("e2100.c: Passed a NULL device.\n");
170 dev = init_etherdev(0, 0);
171 }
172
173 printk("%s: E21** at %#3x,", dev->name, ioaddr);
174 for (i = 0; i < 6; i++)
175 printk(" %02X", station_addr[i]);
176
177 if (dev->irq < 2) {
178 int irqlist[] = {15,11,10,12,5,9,3,4}, i;
179 for (i = 0; i < 8; i++)
180 if (request_irq (irqlist[i], NULL, 0, "bogus", NULL) != -EBUSY) {
181 dev->irq = irqlist[i];
182 break;
183 }
184 if (i >= 8) {
185 printk(" unable to get IRQ %d.\n", dev->irq);
186 return EAGAIN;
187 }
188 } else if (dev->irq == 2)
189 dev->irq = 9;
190
191
192 if (ethdev_init(dev)) {
193 printk (" unable to get memory for dev->priv.\n");
194 return -ENOMEM;
195 }
196
197
198 request_region(ioaddr, E21_IO_EXTENT, "e2100");
199
200
201 dev->base_addr = ioaddr;
202
203 ei_status.name = "E2100";
204 ei_status.word16 = 1;
205 ei_status.tx_start_page = E21_TX_START_PG;
206 ei_status.rx_start_page = E21_RX_START_PG;
207 ei_status.stop_page = E21_RX_STOP_PG;
208 ei_status.saved_irq = dev->irq;
209
210
211
212 if (dev->mem_end & 15)
213 dev->if_port = dev->mem_end & 7;
214 else {
215 dev->if_port = 0;
216 inb(ioaddr + E21_MEDIA);
217 for(i = 0; i < 6; i++)
218 if (station_addr[i] != inb(ioaddr + E21_SAPROM + 8 + i)) {
219 dev->if_port = 1;
220 break;
221 }
222 }
223
224
225
226
227 if (dev->mem_start == 0)
228 dev->mem_start = 0xd0000;
229
230 #ifdef notdef
231
232
233 dev->rmem_start = dev->mem_start + TX_PAGES*256;
234 dev->mem_end = dev->rmem_end = dev->mem_start + 2*1024;
235 #endif
236
237 printk(", IRQ %d, %s media, memory @ %#lx.\n", dev->irq,
238 dev->if_port ? "secondary" : "primary", dev->mem_start);
239
240 ei_status.reset_8390 = &e21_reset_8390;
241 ei_status.block_input = &e21_block_input;
242 ei_status.block_output = &e21_block_output;
243 ei_status.get_8390_hdr = &e21_get_8390_hdr;
244 dev->open = &e21_open;
245 dev->stop = &e21_close;
246 NS8390_init(dev, 0);
247
248 return 0;
249 }
250
251 static int
252 e21_open(struct device *dev)
253 {
254 short ioaddr = dev->base_addr;
255
256 if (request_irq(dev->irq, ei_interrupt, 0, "e2100", NULL)) {
257 return EBUSY;
258 }
259 irq2dev_map[dev->irq] = dev;
260
261
262 inb(ioaddr + E21_IRQ_LOW);
263 outb(0, ioaddr + E21_ASIC + (dev->irq & 7));
264 inb(ioaddr + E21_IRQ_HIGH);
265 outb(0, ioaddr + E21_ASIC + (dev->irq > 7 ? 1:0)
266 + (dev->if_port ? E21_ALT_IFPORT : 0));
267 inb(ioaddr + E21_MEM_BASE);
268 outb(0, ioaddr + E21_ASIC + ((dev->mem_start >> 17) & 7));
269
270 ei_open(dev);
271 MOD_INC_USE_COUNT;
272 return 0;
273 }
274
275 static void
276 e21_reset_8390(struct device *dev)
277 {
278 short ioaddr = dev->base_addr;
279
280 outb(0x01, ioaddr);
281 if (ei_debug > 1) printk("resetting the E2180x3 t=%ld...", jiffies);
282 ei_status.txing = 0;
283
284
285
286 if (ei_debug > 1) printk("reset done\n");
287 return;
288 }
289
290
291
292
293 static void
294 e21_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
295 {
296
297 short ioaddr = dev->base_addr;
298 char *shared_mem = (char *)dev->mem_start;
299
300 mem_on(ioaddr, shared_mem, ring_page);
301
302 #ifdef notdef
303
304 memcpy_fromio(hdr, shared_mem, sizeof(struct e8390_pkt_hdr));
305 #else
306 ((unsigned int*)hdr)[0] = readl(shared_mem);
307 #endif
308
309
310 mem_off(ioaddr);
311
312 }
313
314
315
316
317 static void
318 e21_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
319 {
320 short ioaddr = dev->base_addr;
321 char *shared_mem = (char *)dev->mem_start;
322
323 mem_on(ioaddr, shared_mem, (ring_offset>>8));
324
325
326 eth_io_copy_and_sum(skb, dev->mem_start + (ring_offset & 0xff), count, 0);
327
328 mem_off(ioaddr);
329 }
330
331 static void
332 e21_block_output(struct device *dev, int count, const unsigned char *buf,
333 int start_page)
334 {
335 short ioaddr = dev->base_addr;
336 volatile char *shared_mem = (char *)dev->mem_start;
337
338
339
340 readb(shared_mem + start_page);
341 mem_on(ioaddr, shared_mem, start_page);
342
343 memcpy_toio(shared_mem, buf, count);
344 mem_off(ioaddr);
345 }
346
347 static int
348 e21_close(struct device *dev)
349 {
350 short ioaddr = dev->base_addr;
351
352 if (ei_debug > 1)
353 printk("%s: Shutting down ethercard.\n", dev->name);
354
355 free_irq(dev->irq, NULL);
356 dev->irq = ei_status.saved_irq;
357
358
359 inb(ioaddr + E21_IRQ_LOW);
360 outb(0, ioaddr + E21_ASIC);
361 inb(ioaddr + E21_IRQ_HIGH);
362 outb(0, ioaddr + E21_ASIC);
363
364 irq2dev_map[dev->irq] = NULL;
365
366 ei_close(dev);
367
368
369
370 mem_off(ioaddr);
371
372 MOD_DEC_USE_COUNT;
373
374 return 0;
375 }
376
377 #ifdef HAVE_DEVLIST
378 struct netdev_entry e21_drv =
379 {"e21", e21_probe1, E21_IO_EXTENT, e21_probe_list};
380 #endif
381
382
383 #ifdef MODULE
384 #define MAX_E21_CARDS 4
385 #define NAMELEN 8
386 static char namelist[NAMELEN * MAX_E21_CARDS] = { 0, };
387 static struct device dev_e21[MAX_E21_CARDS] = {
388 {
389 NULL,
390 0, 0, 0, 0,
391 0, 0,
392 0, 0, 0, NULL, NULL
393 },
394 };
395
396 static int io[MAX_E21_CARDS] = { 0, };
397 static int irq[MAX_E21_CARDS] = { 0, };
398 static int mem[MAX_E21_CARDS] = { 0, };
399 static int xcvr[MAX_E21_CARDS] = { 0, };
400
401
402
403 int
404 init_module(void)
405 {
406 int this_dev, found = 0;
407
408 for (this_dev = 0; this_dev < MAX_E21_CARDS; this_dev++) {
409 struct device *dev = &dev_e21[this_dev];
410 dev->name = namelist+(NAMELEN*this_dev);
411 dev->irq = irq[this_dev];
412 dev->base_addr = io[this_dev];
413 dev->mem_start = mem[this_dev];
414 dev->mem_end = xcvr[this_dev];
415 dev->init = e2100_probe;
416 if (io[this_dev] == 0) {
417 if (this_dev != 0) break;
418 printk(KERN_NOTICE "e2100.c: Presently autoprobing (not recommended) for a single card.\n");
419 }
420 if (register_netdev(dev) != 0) {
421 printk(KERN_WARNING "e2100.c: No E2100 card found (i/o = 0x%x).\n", io[this_dev]);
422 if (found != 0) return 0;
423 return -ENXIO;
424 }
425 found++;
426 }
427
428 return 0;
429 }
430
431 void
432 cleanup_module(void)
433 {
434 int this_dev;
435
436 for (this_dev = 0; this_dev < MAX_E21_CARDS; this_dev++) {
437 struct device *dev = &dev_e21[this_dev];
438 if (dev->priv != NULL) {
439
440 kfree(dev->priv);
441 dev->priv = NULL;
442 release_region(dev->base_addr, E21_IO_EXTENT);
443 unregister_netdev(dev);
444 }
445 }
446 }
447 #endif
448
449
450
451
452
453
454
455
456