This source file includes following definitions.
- wd_probe
- wd_probe1
- wd_open
- wd_reset_8390
- wd_block_input
- wd_block_output
- wd_close_card
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 static char *version =
21 "wd.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
22
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/errno.h>
26 #include <linux/string.h>
27 #include <asm/io.h>
28 #include <asm/system.h>
29
30 #include <linux/netdevice.h>
31 #include "8390.h"
32 extern struct device *init_etherdev(struct device *dev, int sizeof_private,
33 unsigned long *mem_startp);
34
35
36 static unsigned int wd_portlist[] =
37 {0x300, 0x280, 0x380, 0x240, 0};
38
39 int wd_probe(struct device *dev);
40 int wd_probe1(struct device *dev, int ioaddr);
41
42 static int wd_open(struct device *dev);
43 static void wd_reset_8390(struct device *dev);
44 static int wd_block_input(struct device *dev, int count,
45 char *buf, int ring_offset);
46 static void wd_block_output(struct device *dev, int count,
47 const unsigned char *buf, const start_page);
48 static int wd_close_card(struct device *dev);
49
50
51 #define WD_START_PG 0x00
52 #define WD03_STOP_PG 0x20
53 #define WD13_STOP_PG 0x40
54
55 #define WD_CMDREG 0
56 #define WD_RESET 0x80
57 #define WD_MEMENB 0x40
58 #define WD_CMDREG5 5
59 #define ISA16 0x80
60 #define NIC16 0x40
61 #define WD_NIC_OFFSET 16
62 #define WD_IO_EXTENT 32
63
64
65
66
67
68
69
70
71
72
73 #ifdef HAVE_DEVLIST
74 struct netdev_entry wd_drv =
75 {"wd", wd_probe1, WD_IO_EXTENT, wd_portlist};
76 #else
77
78 int wd_probe(struct device *dev)
79 {
80 int i;
81 int base_addr = dev ? dev->base_addr : 0;
82
83 if (base_addr > 0x1ff)
84 return wd_probe1(dev, base_addr);
85 else if (base_addr != 0)
86 return ENXIO;
87
88 for (i = 0; wd_portlist[i]; i++) {
89 int ioaddr = wd_portlist[i];
90 if (check_region(ioaddr, WD_IO_EXTENT))
91 continue;
92 if (wd_probe1(dev, ioaddr) == 0)
93 return 0;
94 }
95
96 return ENODEV;
97 }
98 #endif
99
100 int wd_probe1(struct device *dev, int ioaddr)
101 {
102 int i;
103 int checksum = 0;
104 int ancient = 0;
105 int word16 = 0;
106 char *model_name;
107
108 for (i = 0; i < 8; i++)
109 checksum += inb(ioaddr + 8 + i);
110 if (inb(ioaddr + 8) == 0xff
111 || inb(ioaddr + 9) == 0xff
112 || (checksum & 0xff) != 0xFF)
113 return ENODEV;
114
115 if (dev == NULL)
116 dev = init_etherdev(0, sizeof(struct ei_device), 0);
117
118 printk("%s: WD80x3 at %#3x, ", dev->name, ioaddr);
119 for (i = 0; i < 6; i++)
120 printk(" %2.2X", dev->dev_addr[i] = inb(ioaddr + 8 + i));
121
122
123
124
125
126
127 if (inb(ioaddr+0) == 'P' && inb(ioaddr+1) == 'D') {
128 unsigned char reg5 = inb(ioaddr+5);
129
130 switch (inb(ioaddr+2)) {
131 case 0x03: word16 = 0; model_name = "PDI8023-8"; break;
132 case 0x05: word16 = 0; model_name = "PDUC8023"; break;
133 case 0x0a: word16 = 1; model_name = "PDI8023-16"; break;
134
135 default: word16 = 0; model_name = "PDI8023"; break;
136 }
137 dev->mem_start = ((reg5 & 0x1c) + 0xc0) << 12;
138 dev->irq = (reg5 & 0xe0) == 0xe0 ? 10 : (reg5 >> 5) + 1;
139 } else {
140
141
142
143
144
145
146 for (i = 0; i < 6; i++)
147 if (inb(ioaddr+i) != inb(ioaddr+8+i))
148 break;
149 if (i >= 6) {
150 ancient = 1;
151 model_name = "WD8003-old";
152 word16 = 0;
153 } else {
154 int tmp = inb(ioaddr+1);
155 outb( tmp ^ 0x01, ioaddr+1 );
156 if (((inb( ioaddr+1) & 0x01) == 0x01)
157 && (tmp & 0x01) == 0x01 ) {
158 int asic_reg5 = inb(ioaddr+WD_CMDREG5);
159
160 outb( NIC16 | (asic_reg5&0x1f), ioaddr+WD_CMDREG5);
161 outb(tmp, ioaddr+1);
162 model_name = "WD8013";
163 word16 = 1;
164 } else {
165 model_name = "WD8003";
166 word16 = 0;
167 }
168 outb(tmp, ioaddr+1);
169 }
170 #ifndef final_version
171 if ( !ancient && (inb(ioaddr+1) & 0x01) != (word16 & 0x01))
172 printk("\nWD80?3: Bus width conflict, %d (probe) != %d (reg report).",
173 word16 ? 16 : 8, (inb(ioaddr+1) & 0x01) ? 16 : 8);
174 #endif
175 }
176
177 #if defined(WD_SHMEM) && WD_SHMEM > 0x80000
178
179 dev->mem_start = WD_SHMEM;
180 #else
181 if (dev->mem_start == 0) {
182
183 int reg0 = inb(ioaddr);
184 if (reg0 == 0xff || reg0 == 0) {
185
186 dev->mem_start = 0xd0000;
187 printk(" assigning address %#lx", dev->mem_start);
188 } else {
189 int high_addr_bits = inb(ioaddr+WD_CMDREG5) & 0x1f;
190
191 if (high_addr_bits == 0x1f || word16 == 0)
192 high_addr_bits = 0x01;
193 dev->mem_start = ((reg0&0x3f) << 13) + (high_addr_bits << 19);
194 }
195 }
196 #endif
197
198
199 dev->base_addr = ioaddr+WD_NIC_OFFSET;
200
201 if (dev->irq < 2) {
202 int irqmap[] = {9,3,5,7,10,11,15,4};
203 int reg1 = inb(ioaddr+1);
204 int reg4 = inb(ioaddr+4);
205 if (ancient || reg1 == 0xff) {
206 short nic_addr = ioaddr+WD_NIC_OFFSET;
207
208
209
210
211 outb_p(E8390_NODMA + E8390_STOP, nic_addr);
212 outb(0x00, nic_addr+EN0_IMR);
213 autoirq_setup(0);
214 outb_p(0xff, nic_addr + EN0_IMR);
215 outb_p(0x00, nic_addr + EN0_RCNTLO);
216 outb_p(0x00, nic_addr + EN0_RCNTHI);
217 outb(E8390_RREAD+E8390_START, nic_addr);
218 dev->irq = autoirq_report(2);
219 outb_p(0x00, nic_addr+EN0_IMR);
220
221 if (ei_debug > 2)
222 printk(" autoirq is %d", dev->irq);
223 if (dev->irq < 2)
224 dev->irq = word16 ? 10 : 5;
225 } else
226 dev->irq = irqmap[((reg4 >> 5) & 0x03) + (reg1 & 0x04)];
227 } else if (dev->irq == 2)
228 dev->irq = 9;
229
230
231
232 if (request_irq(dev->irq, ei_interrupt, 0, "wd")) {
233 printk (" unable to get IRQ %d.\n", dev->irq);
234 return EAGAIN;
235 }
236
237
238 request_region(ioaddr, WD_IO_EXTENT,"wd");
239 ethdev_init(dev);
240
241 ei_status.name = model_name;
242 ei_status.word16 = word16;
243 ei_status.tx_start_page = WD_START_PG;
244 ei_status.rx_start_page = WD_START_PG + TX_PAGES;
245 ei_status.stop_page = word16 ? WD13_STOP_PG : WD03_STOP_PG;
246
247
248 dev->rmem_start = dev->mem_start + TX_PAGES*256;
249 dev->mem_end = dev->rmem_end
250 = dev->mem_start + (ei_status.stop_page - WD_START_PG)*256;
251
252 printk(" %s, IRQ %d, shared memory at %#lx-%#lx.\n",
253 model_name, dev->irq, dev->mem_start, dev->mem_end-1);
254 if (ei_debug > 0)
255 printk(version);
256
257 ei_status.reset_8390 = &wd_reset_8390;
258 ei_status.block_input = &wd_block_input;
259 ei_status.block_output = &wd_block_output;
260 dev->open = &wd_open;
261 dev->stop = &wd_close_card;
262 NS8390_init(dev, 0);
263
264 #if 1
265
266
267 if (inb(ioaddr+14) & 0x20)
268 outb(inb(ioaddr+4)|0x80, ioaddr+4);
269 #endif
270
271 return 0;
272 }
273
274 static int
275 wd_open(struct device *dev)
276 {
277 int ioaddr = dev->base_addr - WD_NIC_OFFSET;
278
279
280
281 ei_status.reg0 = ((dev->mem_start>>13) & 0x3f) | WD_MEMENB;
282 ei_status.reg5 = ((dev->mem_start>>19) & 0x1f) | NIC16;
283
284 if (ei_status.word16)
285 outb(ei_status.reg5, ioaddr+WD_CMDREG5);
286 outb(ei_status.reg0, ioaddr);
287
288 return ei_open(dev);
289 }
290
291 static void
292 wd_reset_8390(struct device *dev)
293 {
294 int wd_cmd_port = dev->base_addr - WD_NIC_OFFSET;
295
296 outb(WD_RESET, wd_cmd_port);
297 if (ei_debug > 1) printk("resetting the WD80x3 t=%lu...", jiffies);
298 ei_status.txing = 0;
299
300
301 outb((((dev->mem_start>>13) & 0x3f)|WD_MEMENB), wd_cmd_port);
302 if (ei_status.word16)
303 outb(NIC16 | ((dev->mem_start>>19) & 0x1f), wd_cmd_port+WD_CMDREG5);
304
305 if (ei_debug > 1) printk("reset done\n");
306 return;
307 }
308
309
310
311
312
313
314 static int
315 wd_block_input(struct device *dev, int count, char *buf, int ring_offset)
316 {
317 int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET;
318 long xfer_start = dev->mem_start + ring_offset - (WD_START_PG<<8);
319
320
321
322 if (count == 4) {
323 if (ei_status.word16)
324 outb(ISA16 | ei_status.reg5, wd_cmdreg+WD_CMDREG5);
325 ((int*)buf)[0] = ((int*)xfer_start)[0];
326 return 0;
327 }
328
329 if (xfer_start + count > dev->rmem_end) {
330
331 int semi_count = dev->rmem_end - xfer_start;
332 memcpy(buf, (char *)xfer_start, semi_count);
333 count -= semi_count;
334 memcpy(buf + semi_count, (char *)dev->rmem_start, count);
335 } else
336 memcpy(buf, (char *)xfer_start, count);
337
338
339 if (ei_status.word16)
340 outb(ei_status.reg5, wd_cmdreg+WD_CMDREG5);
341
342 return 0;
343 }
344
345 static void
346 wd_block_output(struct device *dev, int count, const unsigned char *buf,
347 int start_page)
348 {
349 int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET;
350 long shmem = dev->mem_start + ((start_page - WD_START_PG)<<8);
351
352
353 if (ei_status.word16) {
354
355 outb(ISA16 | ei_status.reg5, wd_cmdreg+WD_CMDREG5);
356 memcpy((char *)shmem, buf, count);
357 outb(ei_status.reg5, wd_cmdreg+WD_CMDREG5);
358 } else
359 memcpy((char *)shmem, buf, count);
360 }
361
362
363 static int
364 wd_close_card(struct device *dev)
365 {
366 int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET;
367
368 if (ei_debug > 1)
369 printk("%s: Shutting down ethercard.\n", dev->name);
370 NS8390_init(dev, 0);
371 dev->start = 0;
372
373
374 outb(ei_status.reg5, wd_cmdreg + WD_CMDREG5 );
375
376
377 outb(ei_status.reg0 & ~WD_MEMENB, wd_cmdreg);
378
379 return 0;
380 }
381
382
383
384
385
386
387
388
389
390