Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * WaveLAN ISA driver | |
3 | * | |
4 | * Jean II - HPLB '96 | |
5 | * | |
6 | * Reorganisation and extension of the driver. | |
7 | * Original copyright follows (also see the end of this file). | |
8 | * See wavelan.p.h for details. | |
9 | * | |
10 | * | |
11 | * | |
12 | * AT&T GIS (nee NCR) WaveLAN card: | |
13 | * An Ethernet-like radio transceiver | |
14 | * controlled by an Intel 82586 coprocessor. | |
15 | */ | |
16 | ||
17 | #include "wavelan.p.h" /* Private header */ | |
18 | ||
19 | /************************* MISC SUBROUTINES **************************/ | |
20 | /* | |
21 | * Subroutines which won't fit in one of the following category | |
22 | * (WaveLAN modem or i82586) | |
23 | */ | |
24 | ||
25 | /*------------------------------------------------------------------*/ | |
26 | /* | |
27 | * Translate irq number to PSA irq parameter | |
28 | */ | |
29 | static u8 wv_irq_to_psa(int irq) | |
30 | { | |
0a92dd0a | 31 | if (irq < 0 || irq >= ARRAY_SIZE(irqvals)) |
1da177e4 LT |
32 | return 0; |
33 | ||
34 | return irqvals[irq]; | |
35 | } | |
36 | ||
37 | /*------------------------------------------------------------------*/ | |
38 | /* | |
39 | * Translate PSA irq parameter to irq number | |
40 | */ | |
41 | static int __init wv_psa_to_irq(u8 irqval) | |
42 | { | |
43 | int irq; | |
44 | ||
0a92dd0a | 45 | for (irq = 0; irq < ARRAY_SIZE(irqvals); irq++) |
1da177e4 LT |
46 | if (irqvals[irq] == irqval) |
47 | return irq; | |
48 | ||
49 | return -1; | |
50 | } | |
51 | ||
52 | #ifdef STRUCT_CHECK | |
53 | /*------------------------------------------------------------------*/ | |
54 | /* | |
55 | * Sanity routine to verify the sizes of the various WaveLAN interface | |
56 | * structures. | |
57 | */ | |
58 | static char *wv_struct_check(void) | |
59 | { | |
60 | #define SC(t,s,n) if (sizeof(t) != s) return(n); | |
61 | ||
62 | SC(psa_t, PSA_SIZE, "psa_t"); | |
63 | SC(mmw_t, MMW_SIZE, "mmw_t"); | |
64 | SC(mmr_t, MMR_SIZE, "mmr_t"); | |
65 | SC(ha_t, HA_SIZE, "ha_t"); | |
66 | ||
67 | #undef SC | |
68 | ||
69 | return ((char *) NULL); | |
70 | } /* wv_struct_check */ | |
71 | #endif /* STRUCT_CHECK */ | |
72 | ||
73 | /********************* HOST ADAPTER SUBROUTINES *********************/ | |
74 | /* | |
75 | * Useful subroutines to manage the WaveLAN ISA interface | |
76 | * | |
77 | * One major difference with the PCMCIA hardware (except the port mapping) | |
78 | * is that we have to keep the state of the Host Control Register | |
79 | * because of the interrupt enable & bus size flags. | |
80 | */ | |
81 | ||
82 | /*------------------------------------------------------------------*/ | |
83 | /* | |
84 | * Read from card's Host Adaptor Status Register. | |
85 | */ | |
86 | static inline u16 hasr_read(unsigned long ioaddr) | |
87 | { | |
88 | return (inw(HASR(ioaddr))); | |
89 | } /* hasr_read */ | |
90 | ||
91 | /*------------------------------------------------------------------*/ | |
92 | /* | |
93 | * Write to card's Host Adapter Command Register. | |
94 | */ | |
95 | static inline void hacr_write(unsigned long ioaddr, u16 hacr) | |
96 | { | |
97 | outw(hacr, HACR(ioaddr)); | |
98 | } /* hacr_write */ | |
99 | ||
100 | /*------------------------------------------------------------------*/ | |
101 | /* | |
102 | * Write to card's Host Adapter Command Register. Include a delay for | |
103 | * those times when it is needed. | |
104 | */ | |
858119e1 | 105 | static void hacr_write_slow(unsigned long ioaddr, u16 hacr) |
1da177e4 LT |
106 | { |
107 | hacr_write(ioaddr, hacr); | |
108 | /* delay might only be needed sometimes */ | |
109 | mdelay(1); | |
110 | } /* hacr_write_slow */ | |
111 | ||
112 | /*------------------------------------------------------------------*/ | |
113 | /* | |
114 | * Set the channel attention bit. | |
115 | */ | |
116 | static inline void set_chan_attn(unsigned long ioaddr, u16 hacr) | |
117 | { | |
118 | hacr_write(ioaddr, hacr | HACR_CA); | |
119 | } /* set_chan_attn */ | |
120 | ||
121 | /*------------------------------------------------------------------*/ | |
122 | /* | |
123 | * Reset, and then set host adaptor into default mode. | |
124 | */ | |
125 | static inline void wv_hacr_reset(unsigned long ioaddr) | |
126 | { | |
127 | hacr_write_slow(ioaddr, HACR_RESET); | |
128 | hacr_write(ioaddr, HACR_DEFAULT); | |
129 | } /* wv_hacr_reset */ | |
130 | ||
131 | /*------------------------------------------------------------------*/ | |
132 | /* | |
133 | * Set the I/O transfer over the ISA bus to 8-bit mode | |
134 | */ | |
135 | static inline void wv_16_off(unsigned long ioaddr, u16 hacr) | |
136 | { | |
137 | hacr &= ~HACR_16BITS; | |
138 | hacr_write(ioaddr, hacr); | |
139 | } /* wv_16_off */ | |
140 | ||
141 | /*------------------------------------------------------------------*/ | |
142 | /* | |
143 | * Set the I/O transfer over the ISA bus to 8-bit mode | |
144 | */ | |
145 | static inline void wv_16_on(unsigned long ioaddr, u16 hacr) | |
146 | { | |
147 | hacr |= HACR_16BITS; | |
148 | hacr_write(ioaddr, hacr); | |
149 | } /* wv_16_on */ | |
150 | ||
151 | /*------------------------------------------------------------------*/ | |
152 | /* | |
153 | * Disable interrupts on the WaveLAN hardware. | |
154 | * (called by wv_82586_stop()) | |
155 | */ | |
156 | static inline void wv_ints_off(struct net_device * dev) | |
157 | { | |
158 | net_local *lp = (net_local *) dev->priv; | |
159 | unsigned long ioaddr = dev->base_addr; | |
160 | ||
161 | lp->hacr &= ~HACR_INTRON; | |
162 | hacr_write(ioaddr, lp->hacr); | |
163 | } /* wv_ints_off */ | |
164 | ||
165 | /*------------------------------------------------------------------*/ | |
166 | /* | |
167 | * Enable interrupts on the WaveLAN hardware. | |
168 | * (called by wv_hw_reset()) | |
169 | */ | |
170 | static inline void wv_ints_on(struct net_device * dev) | |
171 | { | |
172 | net_local *lp = (net_local *) dev->priv; | |
173 | unsigned long ioaddr = dev->base_addr; | |
174 | ||
175 | lp->hacr |= HACR_INTRON; | |
176 | hacr_write(ioaddr, lp->hacr); | |
177 | } /* wv_ints_on */ | |
178 | ||
179 | /******************* MODEM MANAGEMENT SUBROUTINES *******************/ | |
180 | /* | |
181 | * Useful subroutines to manage the modem of the WaveLAN | |
182 | */ | |
183 | ||
184 | /*------------------------------------------------------------------*/ | |
185 | /* | |
186 | * Read the Parameter Storage Area from the WaveLAN card's memory | |
187 | */ | |
188 | /* | |
189 | * Read bytes from the PSA. | |
190 | */ | |
191 | static void psa_read(unsigned long ioaddr, u16 hacr, int o, /* offset in PSA */ | |
192 | u8 * b, /* buffer to fill */ | |
193 | int n) | |
194 | { /* size to read */ | |
195 | wv_16_off(ioaddr, hacr); | |
196 | ||
197 | while (n-- > 0) { | |
198 | outw(o, PIOR2(ioaddr)); | |
199 | o++; | |
200 | *b++ = inb(PIOP2(ioaddr)); | |
201 | } | |
202 | ||
203 | wv_16_on(ioaddr, hacr); | |
204 | } /* psa_read */ | |
205 | ||
206 | /*------------------------------------------------------------------*/ | |
207 | /* | |
208 | * Write the Parameter Storage Area to the WaveLAN card's memory. | |
209 | */ | |
210 | static void psa_write(unsigned long ioaddr, u16 hacr, int o, /* Offset in PSA */ | |
211 | u8 * b, /* Buffer in memory */ | |
212 | int n) | |
213 | { /* Length of buffer */ | |
214 | int count = 0; | |
215 | ||
216 | wv_16_off(ioaddr, hacr); | |
217 | ||
218 | while (n-- > 0) { | |
219 | outw(o, PIOR2(ioaddr)); | |
220 | o++; | |
221 | ||
222 | outb(*b, PIOP2(ioaddr)); | |
223 | b++; | |
224 | ||
225 | /* Wait for the memory to finish its write cycle */ | |
226 | count = 0; | |
227 | while ((count++ < 100) && | |
228 | (hasr_read(ioaddr) & HASR_PSA_BUSY)) mdelay(1); | |
229 | } | |
230 | ||
231 | wv_16_on(ioaddr, hacr); | |
232 | } /* psa_write */ | |
233 | ||
234 | #ifdef SET_PSA_CRC | |
235 | /*------------------------------------------------------------------*/ | |
236 | /* | |
237 | * Calculate the PSA CRC | |
238 | * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code | |
239 | * NOTE: By specifying a length including the CRC position the | |
240 | * returned value should be zero. (i.e. a correct checksum in the PSA) | |
241 | * | |
242 | * The Windows drivers don't use the CRC, but the AP and the PtP tool | |
243 | * depend on it. | |
244 | */ | |
858119e1 | 245 | static u16 psa_crc(u8 * psa, /* The PSA */ |
1da177e4 LT |
246 | int size) |
247 | { /* Number of short for CRC */ | |
248 | int byte_cnt; /* Loop on the PSA */ | |
249 | u16 crc_bytes = 0; /* Data in the PSA */ | |
250 | int bit_cnt; /* Loop on the bits of the short */ | |
251 | ||
252 | for (byte_cnt = 0; byte_cnt < size; byte_cnt++) { | |
253 | crc_bytes ^= psa[byte_cnt]; /* Its an xor */ | |
254 | ||
255 | for (bit_cnt = 1; bit_cnt < 9; bit_cnt++) { | |
256 | if (crc_bytes & 0x0001) | |
257 | crc_bytes = (crc_bytes >> 1) ^ 0xA001; | |
258 | else | |
259 | crc_bytes >>= 1; | |
260 | } | |
261 | } | |
262 | ||
263 | return crc_bytes; | |
264 | } /* psa_crc */ | |
265 | #endif /* SET_PSA_CRC */ | |
266 | ||
267 | /*------------------------------------------------------------------*/ | |
268 | /* | |
269 | * update the checksum field in the Wavelan's PSA | |
270 | */ | |
271 | static void update_psa_checksum(struct net_device * dev, unsigned long ioaddr, u16 hacr) | |
272 | { | |
273 | #ifdef SET_PSA_CRC | |
274 | psa_t psa; | |
275 | u16 crc; | |
276 | ||
277 | /* read the parameter storage area */ | |
278 | psa_read(ioaddr, hacr, 0, (unsigned char *) &psa, sizeof(psa)); | |
279 | ||
280 | /* update the checksum */ | |
281 | crc = psa_crc((unsigned char *) &psa, | |
282 | sizeof(psa) - sizeof(psa.psa_crc[0]) - | |
283 | sizeof(psa.psa_crc[1]) | |
284 | - sizeof(psa.psa_crc_status)); | |
285 | ||
286 | psa.psa_crc[0] = crc & 0xFF; | |
287 | psa.psa_crc[1] = (crc & 0xFF00) >> 8; | |
288 | ||
289 | /* Write it ! */ | |
290 | psa_write(ioaddr, hacr, (char *) &psa.psa_crc - (char *) &psa, | |
291 | (unsigned char *) &psa.psa_crc, 2); | |
292 | ||
293 | #ifdef DEBUG_IOCTL_INFO | |
294 | printk(KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n", | |
295 | dev->name, psa.psa_crc[0], psa.psa_crc[1]); | |
296 | ||
297 | /* Check again (luxury !) */ | |
298 | crc = psa_crc((unsigned char *) &psa, | |
299 | sizeof(psa) - sizeof(psa.psa_crc_status)); | |
300 | ||
301 | if (crc != 0) | |
302 | printk(KERN_WARNING | |
303 | "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", | |
304 | dev->name); | |
305 | #endif /* DEBUG_IOCTL_INFO */ | |
306 | #endif /* SET_PSA_CRC */ | |
307 | } /* update_psa_checksum */ | |
308 | ||
309 | /*------------------------------------------------------------------*/ | |
310 | /* | |
311 | * Write 1 byte to the MMC. | |
312 | */ | |
858119e1 | 313 | static void mmc_out(unsigned long ioaddr, u16 o, u8 d) |
1da177e4 LT |
314 | { |
315 | int count = 0; | |
316 | ||
317 | /* Wait for MMC to go idle */ | |
318 | while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY)) | |
319 | udelay(10); | |
320 | ||
321 | outw((u16) (((u16) d << 8) | (o << 1) | 1), MMCR(ioaddr)); | |
322 | } | |
323 | ||
324 | /*------------------------------------------------------------------*/ | |
325 | /* | |
326 | * Routine to write bytes to the Modem Management Controller. | |
327 | * We start at the end because it is the way it should be! | |
328 | */ | |
858119e1 | 329 | static void mmc_write(unsigned long ioaddr, u8 o, u8 * b, int n) |
1da177e4 LT |
330 | { |
331 | o += n; | |
332 | b += n; | |
333 | ||
334 | while (n-- > 0) | |
335 | mmc_out(ioaddr, --o, *(--b)); | |
336 | } /* mmc_write */ | |
337 | ||
338 | /*------------------------------------------------------------------*/ | |
339 | /* | |
340 | * Read a byte from the MMC. | |
341 | * Optimised version for 1 byte, avoid using memory. | |
342 | */ | |
858119e1 | 343 | static u8 mmc_in(unsigned long ioaddr, u16 o) |
1da177e4 LT |
344 | { |
345 | int count = 0; | |
346 | ||
347 | while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY)) | |
348 | udelay(10); | |
349 | outw(o << 1, MMCR(ioaddr)); | |
350 | ||
351 | while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY)) | |
352 | udelay(10); | |
353 | return (u8) (inw(MMCR(ioaddr)) >> 8); | |
354 | } | |
355 | ||
356 | /*------------------------------------------------------------------*/ | |
357 | /* | |
358 | * Routine to read bytes from the Modem Management Controller. | |
359 | * The implementation is complicated by a lack of address lines, | |
360 | * which prevents decoding of the low-order bit. | |
361 | * (code has just been moved in the above function) | |
362 | * We start at the end because it is the way it should be! | |
363 | */ | |
364 | static inline void mmc_read(unsigned long ioaddr, u8 o, u8 * b, int n) | |
365 | { | |
366 | o += n; | |
367 | b += n; | |
368 | ||
369 | while (n-- > 0) | |
370 | *(--b) = mmc_in(ioaddr, --o); | |
371 | } /* mmc_read */ | |
372 | ||
373 | /*------------------------------------------------------------------*/ | |
374 | /* | |
375 | * Get the type of encryption available. | |
376 | */ | |
377 | static inline int mmc_encr(unsigned long ioaddr) | |
378 | { /* I/O port of the card */ | |
379 | int temp; | |
380 | ||
381 | temp = mmc_in(ioaddr, mmroff(0, mmr_des_avail)); | |
382 | if ((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES)) | |
383 | return 0; | |
384 | else | |
385 | return temp; | |
386 | } | |
387 | ||
388 | /*------------------------------------------------------------------*/ | |
389 | /* | |
390 | * Wait for the frequency EEPROM to complete a command. | |
391 | * I hope this one will be optimally inlined. | |
392 | */ | |
393 | static inline void fee_wait(unsigned long ioaddr, /* I/O port of the card */ | |
394 | int delay, /* Base delay to wait for */ | |
395 | int number) | |
396 | { /* Number of time to wait */ | |
397 | int count = 0; /* Wait only a limited time */ | |
398 | ||
399 | while ((count++ < number) && | |
400 | (mmc_in(ioaddr, mmroff(0, mmr_fee_status)) & | |
401 | MMR_FEE_STATUS_BUSY)) udelay(delay); | |
402 | } | |
403 | ||
404 | /*------------------------------------------------------------------*/ | |
405 | /* | |
406 | * Read bytes from the Frequency EEPROM (frequency select cards). | |
407 | */ | |
408 | static void fee_read(unsigned long ioaddr, /* I/O port of the card */ | |
409 | u16 o, /* destination offset */ | |
410 | u16 * b, /* data buffer */ | |
411 | int n) | |
412 | { /* number of registers */ | |
413 | b += n; /* Position at the end of the area */ | |
414 | ||
415 | /* Write the address */ | |
416 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1); | |
417 | ||
418 | /* Loop on all buffer */ | |
419 | while (n-- > 0) { | |
420 | /* Write the read command */ | |
421 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), | |
422 | MMW_FEE_CTRL_READ); | |
423 | ||
424 | /* Wait until EEPROM is ready (should be quick). */ | |
425 | fee_wait(ioaddr, 10, 100); | |
426 | ||
427 | /* Read the value. */ | |
428 | *--b = ((mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)) << 8) | | |
429 | mmc_in(ioaddr, mmroff(0, mmr_fee_data_l))); | |
430 | } | |
431 | } | |
432 | ||
1da177e4 LT |
433 | |
434 | /*------------------------------------------------------------------*/ | |
435 | /* | |
436 | * Write bytes from the Frequency EEPROM (frequency select cards). | |
437 | * This is a bit complicated, because the frequency EEPROM has to | |
438 | * be unprotected and the write enabled. | |
439 | * Jean II | |
440 | */ | |
441 | static void fee_write(unsigned long ioaddr, /* I/O port of the card */ | |
442 | u16 o, /* destination offset */ | |
443 | u16 * b, /* data buffer */ | |
444 | int n) | |
445 | { /* number of registers */ | |
446 | b += n; /* Position at the end of the area. */ | |
447 | ||
448 | #ifdef EEPROM_IS_PROTECTED /* disabled */ | |
449 | #ifdef DOESNT_SEEM_TO_WORK /* disabled */ | |
450 | /* Ask to read the protected register */ | |
451 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD); | |
452 | ||
453 | fee_wait(ioaddr, 10, 100); | |
454 | ||
455 | /* Read the protected register. */ | |
456 | printk("Protected 2: %02X-%02X\n", | |
457 | mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)), | |
458 | mmc_in(ioaddr, mmroff(0, mmr_fee_data_l))); | |
459 | #endif /* DOESNT_SEEM_TO_WORK */ | |
460 | ||
461 | /* Enable protected register. */ | |
462 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN); | |
463 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN); | |
464 | ||
465 | fee_wait(ioaddr, 10, 100); | |
466 | ||
467 | /* Unprotect area. */ | |
468 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n); | |
469 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE); | |
470 | #ifdef DOESNT_SEEM_TO_WORK /* disabled */ | |
471 | /* or use: */ | |
472 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR); | |
473 | #endif /* DOESNT_SEEM_TO_WORK */ | |
474 | ||
475 | fee_wait(ioaddr, 10, 100); | |
476 | #endif /* EEPROM_IS_PROTECTED */ | |
477 | ||
478 | /* Write enable. */ | |
479 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN); | |
480 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN); | |
481 | ||
482 | fee_wait(ioaddr, 10, 100); | |
483 | ||
484 | /* Write the EEPROM address. */ | |
485 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1); | |
486 | ||
487 | /* Loop on all buffer */ | |
488 | while (n-- > 0) { | |
489 | /* Write the value. */ | |
490 | mmc_out(ioaddr, mmwoff(0, mmw_fee_data_h), (*--b) >> 8); | |
491 | mmc_out(ioaddr, mmwoff(0, mmw_fee_data_l), *b & 0xFF); | |
492 | ||
493 | /* Write the write command. */ | |
494 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), | |
495 | MMW_FEE_CTRL_WRITE); | |
496 | ||
497 | /* WaveLAN documentation says to wait at least 10 ms for EEBUSY = 0 */ | |
498 | mdelay(10); | |
499 | fee_wait(ioaddr, 10, 100); | |
500 | } | |
501 | ||
502 | /* Write disable. */ | |
503 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS); | |
504 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS); | |
505 | ||
506 | fee_wait(ioaddr, 10, 100); | |
507 | ||
508 | #ifdef EEPROM_IS_PROTECTED /* disabled */ | |
509 | /* Reprotect EEPROM. */ | |
510 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x00); | |
511 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE); | |
512 | ||
513 | fee_wait(ioaddr, 10, 100); | |
514 | #endif /* EEPROM_IS_PROTECTED */ | |
515 | } | |
1da177e4 LT |
516 | |
517 | /************************ I82586 SUBROUTINES *************************/ | |
518 | /* | |
519 | * Useful subroutines to manage the Ethernet controller | |
520 | */ | |
521 | ||
522 | /*------------------------------------------------------------------*/ | |
523 | /* | |
524 | * Read bytes from the on-board RAM. | |
525 | * Why does inlining this function make it fail? | |
526 | */ | |
527 | static /*inline */ void obram_read(unsigned long ioaddr, | |
528 | u16 o, u8 * b, int n) | |
529 | { | |
530 | outw(o, PIOR1(ioaddr)); | |
531 | insw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1); | |
532 | } | |
533 | ||
534 | /*------------------------------------------------------------------*/ | |
535 | /* | |
536 | * Write bytes to the on-board RAM. | |
537 | */ | |
538 | static inline void obram_write(unsigned long ioaddr, u16 o, u8 * b, int n) | |
539 | { | |
540 | outw(o, PIOR1(ioaddr)); | |
541 | outsw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1); | |
542 | } | |
543 | ||
544 | /*------------------------------------------------------------------*/ | |
545 | /* | |
546 | * Acknowledge the reading of the status issued by the i82586. | |
547 | */ | |
548 | static void wv_ack(struct net_device * dev) | |
549 | { | |
550 | net_local *lp = (net_local *) dev->priv; | |
551 | unsigned long ioaddr = dev->base_addr; | |
552 | u16 scb_cs; | |
553 | int i; | |
554 | ||
555 | obram_read(ioaddr, scboff(OFFSET_SCB, scb_status), | |
556 | (unsigned char *) &scb_cs, sizeof(scb_cs)); | |
557 | scb_cs &= SCB_ST_INT; | |
558 | ||
559 | if (scb_cs == 0) | |
560 | return; | |
561 | ||
562 | obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), | |
563 | (unsigned char *) &scb_cs, sizeof(scb_cs)); | |
564 | ||
565 | set_chan_attn(ioaddr, lp->hacr); | |
566 | ||
567 | for (i = 1000; i > 0; i--) { | |
568 | obram_read(ioaddr, scboff(OFFSET_SCB, scb_command), | |
569 | (unsigned char *) &scb_cs, sizeof(scb_cs)); | |
570 | if (scb_cs == 0) | |
571 | break; | |
572 | ||
573 | udelay(10); | |
574 | } | |
575 | udelay(100); | |
576 | ||
577 | #ifdef DEBUG_CONFIG_ERROR | |
578 | if (i <= 0) | |
579 | printk(KERN_INFO | |
580 | "%s: wv_ack(): board not accepting command.\n", | |
581 | dev->name); | |
582 | #endif | |
583 | } | |
584 | ||
585 | /*------------------------------------------------------------------*/ | |
586 | /* | |
587 | * Set channel attention bit and busy wait until command has | |
588 | * completed, then acknowledge completion of the command. | |
589 | */ | |
858119e1 | 590 | static int wv_synchronous_cmd(struct net_device * dev, const char *str) |
1da177e4 LT |
591 | { |
592 | net_local *lp = (net_local *) dev->priv; | |
593 | unsigned long ioaddr = dev->base_addr; | |
594 | u16 scb_cmd; | |
595 | ach_t cb; | |
596 | int i; | |
597 | ||
598 | scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO; | |
599 | obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), | |
600 | (unsigned char *) &scb_cmd, sizeof(scb_cmd)); | |
601 | ||
602 | set_chan_attn(ioaddr, lp->hacr); | |
603 | ||
604 | for (i = 1000; i > 0; i--) { | |
605 | obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, | |
606 | sizeof(cb)); | |
607 | if (cb.ac_status & AC_SFLD_C) | |
608 | break; | |
609 | ||
610 | udelay(10); | |
611 | } | |
612 | udelay(100); | |
613 | ||
614 | if (i <= 0 || !(cb.ac_status & AC_SFLD_OK)) { | |
615 | #ifdef DEBUG_CONFIG_ERROR | |
616 | printk(KERN_INFO "%s: %s failed; status = 0x%x\n", | |
617 | dev->name, str, cb.ac_status); | |
618 | #endif | |
619 | #ifdef DEBUG_I82586_SHOW | |
620 | wv_scb_show(ioaddr); | |
621 | #endif | |
622 | return -1; | |
623 | } | |
624 | ||
625 | /* Ack the status */ | |
626 | wv_ack(dev); | |
627 | ||
628 | return 0; | |
629 | } | |
630 | ||
631 | /*------------------------------------------------------------------*/ | |
632 | /* | |
633 | * Configuration commands completion interrupt. | |
634 | * Check if done, and if OK. | |
635 | */ | |
858119e1 | 636 | static int |
1da177e4 LT |
637 | wv_config_complete(struct net_device * dev, unsigned long ioaddr, net_local * lp) |
638 | { | |
639 | unsigned short mcs_addr; | |
640 | unsigned short status; | |
641 | int ret; | |
642 | ||
643 | #ifdef DEBUG_INTERRUPT_TRACE | |
644 | printk(KERN_DEBUG "%s: ->wv_config_complete()\n", dev->name); | |
645 | #endif | |
646 | ||
647 | mcs_addr = lp->tx_first_in_use + sizeof(ac_tx_t) + sizeof(ac_nop_t) | |
648 | + sizeof(tbd_t) + sizeof(ac_cfg_t) + sizeof(ac_ias_t); | |
649 | ||
650 | /* Read the status of the last command (set mc list). */ | |
651 | obram_read(ioaddr, acoff(mcs_addr, ac_status), | |
652 | (unsigned char *) &status, sizeof(status)); | |
653 | ||
654 | /* If not completed -> exit */ | |
655 | if ((status & AC_SFLD_C) == 0) | |
656 | ret = 0; /* Not ready to be scrapped */ | |
657 | else { | |
658 | #ifdef DEBUG_CONFIG_ERROR | |
659 | unsigned short cfg_addr; | |
660 | unsigned short ias_addr; | |
661 | ||
662 | /* Check mc_config command */ | |
663 | if ((status & AC_SFLD_OK) != AC_SFLD_OK) | |
664 | printk(KERN_INFO | |
665 | "%s: wv_config_complete(): set_multicast_address failed; status = 0x%x\n", | |
666 | dev->name, status); | |
667 | ||
668 | /* check ia-config command */ | |
669 | ias_addr = mcs_addr - sizeof(ac_ias_t); | |
670 | obram_read(ioaddr, acoff(ias_addr, ac_status), | |
671 | (unsigned char *) &status, sizeof(status)); | |
672 | if ((status & AC_SFLD_OK) != AC_SFLD_OK) | |
673 | printk(KERN_INFO | |
674 | "%s: wv_config_complete(): set_MAC_address failed; status = 0x%x\n", | |
675 | dev->name, status); | |
676 | ||
677 | /* Check config command. */ | |
678 | cfg_addr = ias_addr - sizeof(ac_cfg_t); | |
679 | obram_read(ioaddr, acoff(cfg_addr, ac_status), | |
680 | (unsigned char *) &status, sizeof(status)); | |
681 | if ((status & AC_SFLD_OK) != AC_SFLD_OK) | |
682 | printk(KERN_INFO | |
683 | "%s: wv_config_complete(): configure failed; status = 0x%x\n", | |
684 | dev->name, status); | |
685 | #endif /* DEBUG_CONFIG_ERROR */ | |
686 | ||
687 | ret = 1; /* Ready to be scrapped */ | |
688 | } | |
689 | ||
690 | #ifdef DEBUG_INTERRUPT_TRACE | |
691 | printk(KERN_DEBUG "%s: <-wv_config_complete() - %d\n", dev->name, | |
692 | ret); | |
693 | #endif | |
694 | return ret; | |
695 | } | |
696 | ||
697 | /*------------------------------------------------------------------*/ | |
698 | /* | |
699 | * Command completion interrupt. | |
700 | * Reclaim as many freed tx buffers as we can. | |
701 | * (called in wavelan_interrupt()). | |
702 | * Note : the spinlock is already grabbed for us. | |
703 | */ | |
704 | static int wv_complete(struct net_device * dev, unsigned long ioaddr, net_local * lp) | |
705 | { | |
706 | int nreaped = 0; | |
707 | ||
708 | #ifdef DEBUG_INTERRUPT_TRACE | |
709 | printk(KERN_DEBUG "%s: ->wv_complete()\n", dev->name); | |
710 | #endif | |
711 | ||
712 | /* Loop on all the transmit buffers */ | |
713 | while (lp->tx_first_in_use != I82586NULL) { | |
714 | unsigned short tx_status; | |
715 | ||
716 | /* Read the first transmit buffer */ | |
717 | obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status), | |
718 | (unsigned char *) &tx_status, | |
719 | sizeof(tx_status)); | |
720 | ||
721 | /* If not completed -> exit */ | |
722 | if ((tx_status & AC_SFLD_C) == 0) | |
723 | break; | |
724 | ||
725 | /* Hack for reconfiguration */ | |
726 | if (tx_status == 0xFFFF) | |
727 | if (!wv_config_complete(dev, ioaddr, lp)) | |
728 | break; /* Not completed */ | |
729 | ||
730 | /* We now remove this buffer */ | |
731 | nreaped++; | |
732 | --lp->tx_n_in_use; | |
733 | ||
734 | /* | |
735 | if (lp->tx_n_in_use > 0) | |
736 | printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]); | |
737 | */ | |
738 | ||
739 | /* Was it the last one? */ | |
740 | if (lp->tx_n_in_use <= 0) | |
741 | lp->tx_first_in_use = I82586NULL; | |
742 | else { | |
743 | /* Next one in the chain */ | |
744 | lp->tx_first_in_use += TXBLOCKZ; | |
745 | if (lp->tx_first_in_use >= | |
746 | OFFSET_CU + | |
747 | NTXBLOCKS * TXBLOCKZ) lp->tx_first_in_use -= | |
748 | NTXBLOCKS * TXBLOCKZ; | |
749 | } | |
750 | ||
751 | /* Hack for reconfiguration */ | |
752 | if (tx_status == 0xFFFF) | |
753 | continue; | |
754 | ||
755 | /* Now, check status of the finished command */ | |
756 | if (tx_status & AC_SFLD_OK) { | |
757 | int ncollisions; | |
758 | ||
759 | lp->stats.tx_packets++; | |
760 | ncollisions = tx_status & AC_SFLD_MAXCOL; | |
761 | lp->stats.collisions += ncollisions; | |
762 | #ifdef DEBUG_TX_INFO | |
763 | if (ncollisions > 0) | |
764 | printk(KERN_DEBUG | |
765 | "%s: wv_complete(): tx completed after %d collisions.\n", | |
766 | dev->name, ncollisions); | |
767 | #endif | |
768 | } else { | |
769 | lp->stats.tx_errors++; | |
770 | if (tx_status & AC_SFLD_S10) { | |
771 | lp->stats.tx_carrier_errors++; | |
772 | #ifdef DEBUG_TX_FAIL | |
773 | printk(KERN_DEBUG | |
774 | "%s: wv_complete(): tx error: no CS.\n", | |
775 | dev->name); | |
776 | #endif | |
777 | } | |
778 | if (tx_status & AC_SFLD_S9) { | |
779 | lp->stats.tx_carrier_errors++; | |
780 | #ifdef DEBUG_TX_FAIL | |
781 | printk(KERN_DEBUG | |
782 | "%s: wv_complete(): tx error: lost CTS.\n", | |
783 | dev->name); | |
784 | #endif | |
785 | } | |
786 | if (tx_status & AC_SFLD_S8) { | |
787 | lp->stats.tx_fifo_errors++; | |
788 | #ifdef DEBUG_TX_FAIL | |
789 | printk(KERN_DEBUG | |
790 | "%s: wv_complete(): tx error: slow DMA.\n", | |
791 | dev->name); | |
792 | #endif | |
793 | } | |
794 | if (tx_status & AC_SFLD_S6) { | |
795 | lp->stats.tx_heartbeat_errors++; | |
796 | #ifdef DEBUG_TX_FAIL | |
797 | printk(KERN_DEBUG | |
798 | "%s: wv_complete(): tx error: heart beat.\n", | |
799 | dev->name); | |
800 | #endif | |
801 | } | |
802 | if (tx_status & AC_SFLD_S5) { | |
803 | lp->stats.tx_aborted_errors++; | |
804 | #ifdef DEBUG_TX_FAIL | |
805 | printk(KERN_DEBUG | |
806 | "%s: wv_complete(): tx error: too many collisions.\n", | |
807 | dev->name); | |
808 | #endif | |
809 | } | |
810 | } | |
811 | ||
812 | #ifdef DEBUG_TX_INFO | |
813 | printk(KERN_DEBUG | |
814 | "%s: wv_complete(): tx completed, tx_status 0x%04x\n", | |
815 | dev->name, tx_status); | |
816 | #endif | |
817 | } | |
818 | ||
819 | #ifdef DEBUG_INTERRUPT_INFO | |
820 | if (nreaped > 1) | |
821 | printk(KERN_DEBUG "%s: wv_complete(): reaped %d\n", | |
822 | dev->name, nreaped); | |
823 | #endif | |
824 | ||
825 | /* | |
826 | * Inform upper layers. | |
827 | */ | |
828 | if (lp->tx_n_in_use < NTXBLOCKS - 1) { | |
829 | netif_wake_queue(dev); | |
830 | } | |
831 | #ifdef DEBUG_INTERRUPT_TRACE | |
832 | printk(KERN_DEBUG "%s: <-wv_complete()\n", dev->name); | |
833 | #endif | |
834 | return nreaped; | |
835 | } | |
836 | ||
837 | /*------------------------------------------------------------------*/ | |
838 | /* | |
839 | * Reconfigure the i82586, or at least ask for it. | |
840 | * Because wv_82586_config uses a transmission buffer, we must do it | |
841 | * when we are sure that there is one left, so we do it now | |
842 | * or in wavelan_packet_xmit() (I can't find any better place, | |
843 | * wavelan_interrupt is not an option), so you may experience | |
844 | * delays sometimes. | |
845 | */ | |
858119e1 | 846 | static void wv_82586_reconfig(struct net_device * dev) |
1da177e4 LT |
847 | { |
848 | net_local *lp = (net_local *) dev->priv; | |
849 | unsigned long flags; | |
850 | ||
851 | /* Arm the flag, will be cleard in wv_82586_config() */ | |
852 | lp->reconfig_82586 = 1; | |
853 | ||
854 | /* Check if we can do it now ! */ | |
855 | if((netif_running(dev)) && !(netif_queue_stopped(dev))) { | |
856 | spin_lock_irqsave(&lp->spinlock, flags); | |
857 | /* May fail */ | |
858 | wv_82586_config(dev); | |
859 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
860 | } | |
861 | else { | |
862 | #ifdef DEBUG_CONFIG_INFO | |
863 | printk(KERN_DEBUG | |
864 | "%s: wv_82586_reconfig(): delayed (state = %lX)\n", | |
865 | dev->name, dev->state); | |
866 | #endif | |
867 | } | |
868 | } | |
869 | ||
870 | /********************* DEBUG & INFO SUBROUTINES *********************/ | |
871 | /* | |
872 | * This routine is used in the code to show information for debugging. | |
873 | * Most of the time, it dumps the contents of hardware structures. | |
874 | */ | |
875 | ||
876 | #ifdef DEBUG_PSA_SHOW | |
877 | /*------------------------------------------------------------------*/ | |
878 | /* | |
879 | * Print the formatted contents of the Parameter Storage Area. | |
880 | */ | |
881 | static void wv_psa_show(psa_t * p) | |
882 | { | |
883 | printk(KERN_DEBUG "##### WaveLAN PSA contents: #####\n"); | |
884 | printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n", | |
885 | p->psa_io_base_addr_1, | |
886 | p->psa_io_base_addr_2, | |
887 | p->psa_io_base_addr_3, p->psa_io_base_addr_4); | |
888 | printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n", | |
889 | p->psa_rem_boot_addr_1, | |
890 | p->psa_rem_boot_addr_2, p->psa_rem_boot_addr_3); | |
891 | printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params); | |
892 | printk("psa_int_req_no: %d\n", p->psa_int_req_no); | |
893 | #ifdef DEBUG_SHOW_UNUSED | |
894 | printk(KERN_DEBUG | |
895 | "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n", | |
896 | p->psa_unused0[0], p->psa_unused0[1], p->psa_unused0[2], | |
897 | p->psa_unused0[3], p->psa_unused0[4], p->psa_unused0[5], | |
898 | p->psa_unused0[6]); | |
899 | #endif /* DEBUG_SHOW_UNUSED */ | |
900 | printk(KERN_DEBUG | |
901 | "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n", | |
902 | p->psa_univ_mac_addr[0], p->psa_univ_mac_addr[1], | |
903 | p->psa_univ_mac_addr[2], p->psa_univ_mac_addr[3], | |
904 | p->psa_univ_mac_addr[4], p->psa_univ_mac_addr[5]); | |
905 | printk(KERN_DEBUG | |
906 | "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n", | |
907 | p->psa_local_mac_addr[0], p->psa_local_mac_addr[1], | |
908 | p->psa_local_mac_addr[2], p->psa_local_mac_addr[3], | |
909 | p->psa_local_mac_addr[4], p->psa_local_mac_addr[5]); | |
910 | printk(KERN_DEBUG "psa_univ_local_sel: %d, ", | |
911 | p->psa_univ_local_sel); | |
912 | printk("psa_comp_number: %d, ", p->psa_comp_number); | |
913 | printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set); | |
914 | printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ", | |
915 | p->psa_feature_select); | |
916 | printk("psa_subband/decay_update_prm: %d\n", p->psa_subband); | |
917 | printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr); | |
918 | printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay); | |
919 | printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], | |
920 | p->psa_nwid[1]); | |
921 | printk("psa_nwid_select: %d\n", p->psa_nwid_select); | |
922 | printk(KERN_DEBUG "psa_encryption_select: %d, ", | |
923 | p->psa_encryption_select); | |
924 | printk | |
925 | ("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", | |
926 | p->psa_encryption_key[0], p->psa_encryption_key[1], | |
927 | p->psa_encryption_key[2], p->psa_encryption_key[3], | |
928 | p->psa_encryption_key[4], p->psa_encryption_key[5], | |
929 | p->psa_encryption_key[6], p->psa_encryption_key[7]); | |
930 | printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width); | |
931 | printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ", | |
932 | p->psa_call_code[0]); | |
933 | printk | |
934 | ("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", | |
935 | p->psa_call_code[0], p->psa_call_code[1], p->psa_call_code[2], | |
936 | p->psa_call_code[3], p->psa_call_code[4], p->psa_call_code[5], | |
937 | p->psa_call_code[6], p->psa_call_code[7]); | |
938 | #ifdef DEBUG_SHOW_UNUSED | |
939 | printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n", | |
940 | p->psa_reserved[0], | |
941 | p->psa_reserved[1], p->psa_reserved[2], p->psa_reserved[3]); | |
942 | #endif /* DEBUG_SHOW_UNUSED */ | |
943 | printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status); | |
944 | printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]); | |
945 | printk("psa_crc_status: 0x%02x\n", p->psa_crc_status); | |
946 | } /* wv_psa_show */ | |
947 | #endif /* DEBUG_PSA_SHOW */ | |
948 | ||
949 | #ifdef DEBUG_MMC_SHOW | |
950 | /*------------------------------------------------------------------*/ | |
951 | /* | |
952 | * Print the formatted status of the Modem Management Controller. | |
953 | * This function needs to be completed. | |
954 | */ | |
955 | static void wv_mmc_show(struct net_device * dev) | |
956 | { | |
957 | unsigned long ioaddr = dev->base_addr; | |
958 | net_local *lp = (net_local *) dev->priv; | |
959 | mmr_t m; | |
960 | ||
961 | /* Basic check */ | |
962 | if (hasr_read(ioaddr) & HASR_NO_CLK) { | |
963 | printk(KERN_WARNING | |
964 | "%s: wv_mmc_show: modem not connected\n", | |
965 | dev->name); | |
966 | return; | |
967 | } | |
968 | ||
969 | /* Read the mmc */ | |
970 | mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1); | |
971 | mmc_read(ioaddr, 0, (u8 *) & m, sizeof(m)); | |
972 | mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0); | |
973 | ||
1da177e4 LT |
974 | /* Don't forget to update statistics */ |
975 | lp->wstats.discard.nwid += | |
976 | (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l; | |
1da177e4 LT |
977 | |
978 | printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n"); | |
979 | #ifdef DEBUG_SHOW_UNUSED | |
980 | printk(KERN_DEBUG | |
981 | "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", | |
982 | m.mmr_unused0[0], m.mmr_unused0[1], m.mmr_unused0[2], | |
983 | m.mmr_unused0[3], m.mmr_unused0[4], m.mmr_unused0[5], | |
984 | m.mmr_unused0[6], m.mmr_unused0[7]); | |
985 | #endif /* DEBUG_SHOW_UNUSED */ | |
986 | printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n", | |
987 | m.mmr_des_avail, m.mmr_des_status); | |
988 | #ifdef DEBUG_SHOW_UNUSED | |
989 | printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n", | |
990 | m.mmr_unused1[0], | |
991 | m.mmr_unused1[1], | |
992 | m.mmr_unused1[2], m.mmr_unused1[3], m.mmr_unused1[4]); | |
993 | #endif /* DEBUG_SHOW_UNUSED */ | |
994 | printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n", | |
995 | m.mmr_dce_status, | |
996 | (m. | |
997 | mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? | |
998 | "energy detected," : "", | |
999 | (m. | |
1000 | mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ? | |
1001 | "loop test indicated," : "", | |
1002 | (m. | |
1003 | mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? | |
1004 | "transmitter on," : "", | |
1005 | (m. | |
1006 | mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ? | |
1007 | "jabber timer expired," : ""); | |
1008 | printk(KERN_DEBUG "Dsp ID: %02X\n", m.mmr_dsp_id); | |
1009 | #ifdef DEBUG_SHOW_UNUSED | |
1010 | printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n", | |
1011 | m.mmr_unused2[0], m.mmr_unused2[1]); | |
1012 | #endif /* DEBUG_SHOW_UNUSED */ | |
1013 | printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n", | |
1014 | (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l, | |
1015 | (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l); | |
1016 | printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n", | |
1017 | m.mmr_thr_pre_set & MMR_THR_PRE_SET, | |
1018 | (m. | |
1019 | mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : | |
1020 | "below"); | |
1021 | printk(KERN_DEBUG "signal_lvl: %d [%s], ", | |
1022 | m.mmr_signal_lvl & MMR_SIGNAL_LVL, | |
1023 | (m. | |
1024 | mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : | |
1025 | "no new msg"); | |
1026 | printk("silence_lvl: %d [%s], ", | |
1027 | m.mmr_silence_lvl & MMR_SILENCE_LVL, | |
1028 | (m. | |
1029 | mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : | |
1030 | "no new update"); | |
1031 | printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL, | |
1032 | (m. | |
1033 | mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : | |
1034 | "Antenna 0"); | |
1035 | #ifdef DEBUG_SHOW_UNUSED | |
1036 | printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l); | |
1037 | #endif /* DEBUG_SHOW_UNUSED */ | |
1038 | } /* wv_mmc_show */ | |
1039 | #endif /* DEBUG_MMC_SHOW */ | |
1040 | ||
1041 | #ifdef DEBUG_I82586_SHOW | |
1042 | /*------------------------------------------------------------------*/ | |
1043 | /* | |
1044 | * Print the last block of the i82586 memory. | |
1045 | */ | |
1046 | static void wv_scb_show(unsigned long ioaddr) | |
1047 | { | |
1048 | scb_t scb; | |
1049 | ||
1050 | obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb, | |
1051 | sizeof(scb)); | |
1052 | ||
1053 | printk(KERN_DEBUG "##### WaveLAN system control block: #####\n"); | |
1054 | ||
1055 | printk(KERN_DEBUG "status: "); | |
1056 | printk("stat 0x%x[%s%s%s%s] ", | |
1057 | (scb. | |
1058 | scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA | | |
1059 | SCB_ST_RNR)) >> 12, | |
1060 | (scb. | |
1061 | scb_status & SCB_ST_CX) ? "command completion interrupt," : | |
1062 | "", (scb.scb_status & SCB_ST_FR) ? "frame received," : "", | |
1063 | (scb. | |
1064 | scb_status & SCB_ST_CNA) ? "command unit not active," : "", | |
1065 | (scb. | |
1066 | scb_status & SCB_ST_RNR) ? "receiving unit not ready," : | |
1067 | ""); | |
1068 | printk("cus 0x%x[%s%s%s] ", (scb.scb_status & SCB_ST_CUS) >> 8, | |
1069 | ((scb.scb_status & SCB_ST_CUS) == | |
1070 | SCB_ST_CUS_IDLE) ? "idle" : "", | |
1071 | ((scb.scb_status & SCB_ST_CUS) == | |
1072 | SCB_ST_CUS_SUSP) ? "suspended" : "", | |
1073 | ((scb.scb_status & SCB_ST_CUS) == | |
1074 | SCB_ST_CUS_ACTV) ? "active" : ""); | |
1075 | printk("rus 0x%x[%s%s%s%s]\n", (scb.scb_status & SCB_ST_RUS) >> 4, | |
1076 | ((scb.scb_status & SCB_ST_RUS) == | |
1077 | SCB_ST_RUS_IDLE) ? "idle" : "", | |
1078 | ((scb.scb_status & SCB_ST_RUS) == | |
1079 | SCB_ST_RUS_SUSP) ? "suspended" : "", | |
1080 | ((scb.scb_status & SCB_ST_RUS) == | |
1081 | SCB_ST_RUS_NRES) ? "no resources" : "", | |
1082 | ((scb.scb_status & SCB_ST_RUS) == | |
1083 | SCB_ST_RUS_RDY) ? "ready" : ""); | |
1084 | ||
1085 | printk(KERN_DEBUG "command: "); | |
1086 | printk("ack 0x%x[%s%s%s%s] ", | |
1087 | (scb. | |
1088 | scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR | | |
1089 | SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12, | |
1090 | (scb. | |
1091 | scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "", | |
1092 | (scb. | |
1093 | scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "", | |
1094 | (scb. | |
1095 | scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "", | |
1096 | (scb. | |
1097 | scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : ""); | |
1098 | printk("cuc 0x%x[%s%s%s%s%s] ", | |
1099 | (scb.scb_command & SCB_CMD_CUC) >> 8, | |
1100 | ((scb.scb_command & SCB_CMD_CUC) == | |
1101 | SCB_CMD_CUC_NOP) ? "nop" : "", | |
1102 | ((scb.scb_command & SCB_CMD_CUC) == | |
1103 | SCB_CMD_CUC_GO) ? "start cbl_offset" : "", | |
1104 | ((scb.scb_command & SCB_CMD_CUC) == | |
1105 | SCB_CMD_CUC_RES) ? "resume execution" : "", | |
1106 | ((scb.scb_command & SCB_CMD_CUC) == | |
1107 | SCB_CMD_CUC_SUS) ? "suspend execution" : "", | |
1108 | ((scb.scb_command & SCB_CMD_CUC) == | |
1109 | SCB_CMD_CUC_ABT) ? "abort execution" : ""); | |
1110 | printk("ruc 0x%x[%s%s%s%s%s]\n", | |
1111 | (scb.scb_command & SCB_CMD_RUC) >> 4, | |
1112 | ((scb.scb_command & SCB_CMD_RUC) == | |
1113 | SCB_CMD_RUC_NOP) ? "nop" : "", | |
1114 | ((scb.scb_command & SCB_CMD_RUC) == | |
1115 | SCB_CMD_RUC_GO) ? "start rfa_offset" : "", | |
1116 | ((scb.scb_command & SCB_CMD_RUC) == | |
1117 | SCB_CMD_RUC_RES) ? "resume reception" : "", | |
1118 | ((scb.scb_command & SCB_CMD_RUC) == | |
1119 | SCB_CMD_RUC_SUS) ? "suspend reception" : "", | |
1120 | ((scb.scb_command & SCB_CMD_RUC) == | |
1121 | SCB_CMD_RUC_ABT) ? "abort reception" : ""); | |
1122 | ||
1123 | printk(KERN_DEBUG "cbl_offset 0x%x ", scb.scb_cbl_offset); | |
1124 | printk("rfa_offset 0x%x\n", scb.scb_rfa_offset); | |
1125 | ||
1126 | printk(KERN_DEBUG "crcerrs %d ", scb.scb_crcerrs); | |
1127 | printk("alnerrs %d ", scb.scb_alnerrs); | |
1128 | printk("rscerrs %d ", scb.scb_rscerrs); | |
1129 | printk("ovrnerrs %d\n", scb.scb_ovrnerrs); | |
1130 | } | |
1131 | ||
1132 | /*------------------------------------------------------------------*/ | |
1133 | /* | |
1134 | * Print the formatted status of the i82586's receive unit. | |
1135 | */ | |
1136 | static void wv_ru_show(struct net_device * dev) | |
1137 | { | |
1138 | /* net_local *lp = (net_local *) dev->priv; */ | |
1139 | ||
1140 | printk(KERN_DEBUG | |
1141 | "##### WaveLAN i82586 receiver unit status: #####\n"); | |
1142 | printk(KERN_DEBUG "ru:"); | |
1143 | /* | |
1144 | * Not implemented yet | |
1145 | */ | |
1146 | printk("\n"); | |
1147 | } /* wv_ru_show */ | |
1148 | ||
1149 | /*------------------------------------------------------------------*/ | |
1150 | /* | |
1151 | * Display info about one control block of the i82586 memory. | |
1152 | */ | |
1153 | static void wv_cu_show_one(struct net_device * dev, net_local * lp, int i, u16 p) | |
1154 | { | |
1155 | unsigned long ioaddr; | |
1156 | ac_tx_t actx; | |
1157 | ||
1158 | ioaddr = dev->base_addr; | |
1159 | ||
1160 | printk("%d: 0x%x:", i, p); | |
1161 | ||
1162 | obram_read(ioaddr, p, (unsigned char *) &actx, sizeof(actx)); | |
1163 | printk(" status=0x%x,", actx.tx_h.ac_status); | |
1164 | printk(" command=0x%x,", actx.tx_h.ac_command); | |
1165 | ||
1166 | /* | |
1167 | { | |
1168 | tbd_t tbd; | |
1169 | ||
1170 | obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd)); | |
1171 | printk(" tbd_status=0x%x,", tbd.tbd_status); | |
1172 | } | |
1173 | */ | |
1174 | ||
1175 | printk("|"); | |
1176 | } | |
1177 | ||
1178 | /*------------------------------------------------------------------*/ | |
1179 | /* | |
1180 | * Print status of the command unit of the i82586. | |
1181 | */ | |
1182 | static void wv_cu_show(struct net_device * dev) | |
1183 | { | |
1184 | net_local *lp = (net_local *) dev->priv; | |
1185 | unsigned int i; | |
1186 | u16 p; | |
1187 | ||
1188 | printk(KERN_DEBUG | |
1189 | "##### WaveLAN i82586 command unit status: #####\n"); | |
1190 | ||
1191 | printk(KERN_DEBUG); | |
1192 | for (i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++) { | |
1193 | wv_cu_show_one(dev, lp, i, p); | |
1194 | ||
1195 | p += TXBLOCKZ; | |
1196 | if (p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ) | |
1197 | p -= NTXBLOCKS * TXBLOCKZ; | |
1198 | } | |
1199 | printk("\n"); | |
1200 | } | |
1201 | #endif /* DEBUG_I82586_SHOW */ | |
1202 | ||
1203 | #ifdef DEBUG_DEVICE_SHOW | |
1204 | /*------------------------------------------------------------------*/ | |
1205 | /* | |
1206 | * Print the formatted status of the WaveLAN PCMCIA device driver. | |
1207 | */ | |
1208 | static void wv_dev_show(struct net_device * dev) | |
1209 | { | |
1210 | printk(KERN_DEBUG "dev:"); | |
1211 | printk(" state=%lX,", dev->state); | |
1212 | printk(" trans_start=%ld,", dev->trans_start); | |
1213 | printk(" flags=0x%x,", dev->flags); | |
1214 | printk("\n"); | |
1215 | } /* wv_dev_show */ | |
1216 | ||
1217 | /*------------------------------------------------------------------*/ | |
1218 | /* | |
1219 | * Print the formatted status of the WaveLAN PCMCIA device driver's | |
1220 | * private information. | |
1221 | */ | |
1222 | static void wv_local_show(struct net_device * dev) | |
1223 | { | |
1224 | net_local *lp; | |
1225 | ||
1226 | lp = (net_local *) dev->priv; | |
1227 | ||
1228 | printk(KERN_DEBUG "local:"); | |
1229 | printk(" tx_n_in_use=%d,", lp->tx_n_in_use); | |
1230 | printk(" hacr=0x%x,", lp->hacr); | |
1231 | printk(" rx_head=0x%x,", lp->rx_head); | |
1232 | printk(" rx_last=0x%x,", lp->rx_last); | |
1233 | printk(" tx_first_free=0x%x,", lp->tx_first_free); | |
1234 | printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use); | |
1235 | printk("\n"); | |
1236 | } /* wv_local_show */ | |
1237 | #endif /* DEBUG_DEVICE_SHOW */ | |
1238 | ||
1239 | #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) | |
1240 | /*------------------------------------------------------------------*/ | |
1241 | /* | |
1242 | * Dump packet header (and content if necessary) on the screen | |
1243 | */ | |
1244 | static inline void wv_packet_info(u8 * p, /* Packet to dump */ | |
1245 | int length, /* Length of the packet */ | |
1246 | char *msg1, /* Name of the device */ | |
1247 | char *msg2) | |
1248 | { /* Name of the function */ | |
1249 | int i; | |
1250 | int maxi; | |
1251 | ||
1252 | printk(KERN_DEBUG | |
1253 | "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n", | |
1254 | msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length); | |
1255 | printk(KERN_DEBUG | |
1256 | "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n", | |
1257 | msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], | |
1258 | p[13]); | |
1259 | ||
1260 | #ifdef DEBUG_PACKET_DUMP | |
1261 | ||
1262 | printk(KERN_DEBUG "data=\""); | |
1263 | ||
1264 | if ((maxi = length) > DEBUG_PACKET_DUMP) | |
1265 | maxi = DEBUG_PACKET_DUMP; | |
1266 | for (i = 14; i < maxi; i++) | |
1267 | if (p[i] >= ' ' && p[i] <= '~') | |
1268 | printk(" %c", p[i]); | |
1269 | else | |
1270 | printk("%02X", p[i]); | |
1271 | if (maxi < length) | |
1272 | printk(".."); | |
1273 | printk("\"\n"); | |
1274 | printk(KERN_DEBUG "\n"); | |
1275 | #endif /* DEBUG_PACKET_DUMP */ | |
1276 | } | |
1277 | #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */ | |
1278 | ||
1279 | /*------------------------------------------------------------------*/ | |
1280 | /* | |
1281 | * This is the information which is displayed by the driver at startup. | |
1282 | * There are lots of flags for configuring it to your liking. | |
1283 | */ | |
858119e1 | 1284 | static void wv_init_info(struct net_device * dev) |
1da177e4 LT |
1285 | { |
1286 | short ioaddr = dev->base_addr; | |
1287 | net_local *lp = (net_local *) dev->priv; | |
1288 | psa_t psa; | |
1289 | int i; | |
1290 | ||
1291 | /* Read the parameter storage area */ | |
1292 | psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa)); | |
1293 | ||
1294 | #ifdef DEBUG_PSA_SHOW | |
1295 | wv_psa_show(&psa); | |
1296 | #endif | |
1297 | #ifdef DEBUG_MMC_SHOW | |
1298 | wv_mmc_show(dev); | |
1299 | #endif | |
1300 | #ifdef DEBUG_I82586_SHOW | |
1301 | wv_cu_show(dev); | |
1302 | #endif | |
1303 | ||
1304 | #ifdef DEBUG_BASIC_SHOW | |
1305 | /* Now, let's go for the basic stuff. */ | |
1306 | printk(KERN_NOTICE "%s: WaveLAN at %#x,", dev->name, ioaddr); | |
1307 | for (i = 0; i < WAVELAN_ADDR_SIZE; i++) | |
1308 | printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]); | |
1309 | printk(", IRQ %d", dev->irq); | |
1310 | ||
1311 | /* Print current network ID. */ | |
1312 | if (psa.psa_nwid_select) | |
1313 | printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], | |
1314 | psa.psa_nwid[1]); | |
1315 | else | |
1316 | printk(", nwid off"); | |
1317 | ||
1318 | /* If 2.00 card */ | |
1319 | if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) & | |
1320 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) { | |
1321 | unsigned short freq; | |
1322 | ||
1323 | /* Ask the EEPROM to read the frequency from the first area. */ | |
1324 | fee_read(ioaddr, 0x00, &freq, 1); | |
1325 | ||
1326 | /* Print frequency */ | |
1327 | printk(", 2.00, %ld", (freq >> 6) + 2400L); | |
1328 | ||
1329 | /* Hack! */ | |
1330 | if (freq & 0x20) | |
1331 | printk(".5"); | |
1332 | } else { | |
1333 | printk(", PC"); | |
1334 | switch (psa.psa_comp_number) { | |
1335 | case PSA_COMP_PC_AT_915: | |
1336 | case PSA_COMP_PC_AT_2400: | |
1337 | printk("-AT"); | |
1338 | break; | |
1339 | case PSA_COMP_PC_MC_915: | |
1340 | case PSA_COMP_PC_MC_2400: | |
1341 | printk("-MC"); | |
1342 | break; | |
1343 | case PSA_COMP_PCMCIA_915: | |
1344 | printk("MCIA"); | |
1345 | break; | |
1346 | default: | |
1347 | printk("?"); | |
1348 | } | |
1349 | printk(", "); | |
1350 | switch (psa.psa_subband) { | |
1351 | case PSA_SUBBAND_915: | |
1352 | printk("915"); | |
1353 | break; | |
1354 | case PSA_SUBBAND_2425: | |
1355 | printk("2425"); | |
1356 | break; | |
1357 | case PSA_SUBBAND_2460: | |
1358 | printk("2460"); | |
1359 | break; | |
1360 | case PSA_SUBBAND_2484: | |
1361 | printk("2484"); | |
1362 | break; | |
1363 | case PSA_SUBBAND_2430_5: | |
1364 | printk("2430.5"); | |
1365 | break; | |
1366 | default: | |
1367 | printk("?"); | |
1368 | } | |
1369 | } | |
1370 | ||
1371 | printk(" MHz\n"); | |
1372 | #endif /* DEBUG_BASIC_SHOW */ | |
1373 | ||
1374 | #ifdef DEBUG_VERSION_SHOW | |
1375 | /* Print version information */ | |
1376 | printk(KERN_NOTICE "%s", version); | |
1377 | #endif | |
1378 | } /* wv_init_info */ | |
1379 | ||
1380 | /********************* IOCTL, STATS & RECONFIG *********************/ | |
1381 | /* | |
1382 | * We found here routines that are called by Linux on different | |
1383 | * occasions after the configuration and not for transmitting data | |
1384 | * These may be called when the user use ifconfig, /proc/net/dev | |
1385 | * or wireless extensions | |
1386 | */ | |
1387 | ||
1388 | /*------------------------------------------------------------------*/ | |
1389 | /* | |
1390 | * Get the current Ethernet statistics. This may be called with the | |
1391 | * card open or closed. | |
1392 | * Used when the user read /proc/net/dev | |
1393 | */ | |
1394 | static en_stats *wavelan_get_stats(struct net_device * dev) | |
1395 | { | |
1396 | #ifdef DEBUG_IOCTL_TRACE | |
1397 | printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name); | |
1398 | #endif | |
1399 | ||
1400 | return (&((net_local *) dev->priv)->stats); | |
1401 | } | |
1402 | ||
1403 | /*------------------------------------------------------------------*/ | |
1404 | /* | |
1405 | * Set or clear the multicast filter for this adaptor. | |
1406 | * num_addrs == -1 Promiscuous mode, receive all packets | |
1407 | * num_addrs == 0 Normal mode, clear multicast list | |
1408 | * num_addrs > 0 Multicast mode, receive normal and MC packets, | |
1409 | * and do best-effort filtering. | |
1410 | */ | |
1411 | static void wavelan_set_multicast_list(struct net_device * dev) | |
1412 | { | |
1413 | net_local *lp = (net_local *) dev->priv; | |
1414 | ||
1415 | #ifdef DEBUG_IOCTL_TRACE | |
1416 | printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", | |
1417 | dev->name); | |
1418 | #endif | |
1419 | ||
1420 | #ifdef DEBUG_IOCTL_INFO | |
1421 | printk(KERN_DEBUG | |
1422 | "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n", | |
1423 | dev->name, dev->flags, dev->mc_count); | |
1424 | #endif | |
1425 | ||
1426 | /* Are we asking for promiscuous mode, | |
1427 | * or all multicast addresses (we don't have that!) | |
1428 | * or too many multicast addresses for the hardware filter? */ | |
1429 | if ((dev->flags & IFF_PROMISC) || | |
1430 | (dev->flags & IFF_ALLMULTI) || | |
1431 | (dev->mc_count > I82586_MAX_MULTICAST_ADDRESSES)) { | |
1432 | /* | |
1433 | * Enable promiscuous mode: receive all packets. | |
1434 | */ | |
1435 | if (!lp->promiscuous) { | |
1436 | lp->promiscuous = 1; | |
1437 | lp->mc_count = 0; | |
1438 | ||
1439 | wv_82586_reconfig(dev); | |
1440 | ||
1441 | /* Tell the kernel that we are doing a really bad job. */ | |
1442 | dev->flags |= IFF_PROMISC; | |
1443 | } | |
1444 | } else | |
1445 | /* Are there multicast addresses to send? */ | |
1446 | if (dev->mc_list != (struct dev_mc_list *) NULL) { | |
1447 | /* | |
1448 | * Disable promiscuous mode, but receive all packets | |
1449 | * in multicast list | |
1450 | */ | |
1451 | #ifdef MULTICAST_AVOID | |
1452 | if (lp->promiscuous || (dev->mc_count != lp->mc_count)) | |
1453 | #endif | |
1454 | { | |
1455 | lp->promiscuous = 0; | |
1456 | lp->mc_count = dev->mc_count; | |
1457 | ||
1458 | wv_82586_reconfig(dev); | |
1459 | } | |
1460 | } else { | |
1461 | /* | |
1462 | * Switch to normal mode: disable promiscuous mode and | |
1463 | * clear the multicast list. | |
1464 | */ | |
1465 | if (lp->promiscuous || lp->mc_count == 0) { | |
1466 | lp->promiscuous = 0; | |
1467 | lp->mc_count = 0; | |
1468 | ||
1469 | wv_82586_reconfig(dev); | |
1470 | } | |
1471 | } | |
1472 | #ifdef DEBUG_IOCTL_TRACE | |
1473 | printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", | |
1474 | dev->name); | |
1475 | #endif | |
1476 | } | |
1477 | ||
1478 | /*------------------------------------------------------------------*/ | |
1479 | /* | |
1480 | * This function doesn't exist. | |
1481 | * (Note : it was a nice way to test the reconfigure stuff...) | |
1482 | */ | |
1483 | #ifdef SET_MAC_ADDRESS | |
1484 | static int wavelan_set_mac_address(struct net_device * dev, void *addr) | |
1485 | { | |
1486 | struct sockaddr *mac = addr; | |
1487 | ||
1488 | /* Copy the address. */ | |
1489 | memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE); | |
1490 | ||
1491 | /* Reconfigure the beast. */ | |
1492 | wv_82586_reconfig(dev); | |
1493 | ||
1494 | return 0; | |
1495 | } | |
1496 | #endif /* SET_MAC_ADDRESS */ | |
1497 | ||
1da177e4 LT |
1498 | |
1499 | /*------------------------------------------------------------------*/ | |
1500 | /* | |
1501 | * Frequency setting (for hardware capable of it) | |
1502 | * It's a bit complicated and you don't really want to look into it. | |
1503 | * (called in wavelan_ioctl) | |
1504 | */ | |
858119e1 | 1505 | static int wv_set_frequency(unsigned long ioaddr, /* I/O port of the card */ |
1da177e4 LT |
1506 | iw_freq * frequency) |
1507 | { | |
1508 | const int BAND_NUM = 10; /* Number of bands */ | |
1509 | long freq = 0L; /* offset to 2.4 GHz in .5 MHz */ | |
1510 | #ifdef DEBUG_IOCTL_INFO | |
1511 | int i; | |
1512 | #endif | |
1513 | ||
1514 | /* Setting by frequency */ | |
1515 | /* Theoretically, you may set any frequency between | |
1516 | * the two limits with a 0.5 MHz precision. In practice, | |
1517 | * I don't want you to have trouble with local regulations. | |
1518 | */ | |
1519 | if ((frequency->e == 1) && | |
1520 | (frequency->m >= (int) 2.412e8) | |
1521 | && (frequency->m <= (int) 2.487e8)) { | |
1522 | freq = ((frequency->m / 10000) - 24000L) / 5; | |
1523 | } | |
1524 | ||
1525 | /* Setting by channel (same as wfreqsel) */ | |
1526 | /* Warning: each channel is 22 MHz wide, so some of the channels | |
1527 | * will interfere. */ | |
1528 | if ((frequency->e == 0) && (frequency->m < BAND_NUM)) { | |
1529 | /* Get frequency offset. */ | |
1530 | freq = channel_bands[frequency->m] >> 1; | |
1531 | } | |
1532 | ||
1533 | /* Verify that the frequency is allowed. */ | |
1534 | if (freq != 0L) { | |
1535 | u16 table[10]; /* Authorized frequency table */ | |
1536 | ||
1537 | /* Read the frequency table. */ | |
1538 | fee_read(ioaddr, 0x71, table, 10); | |
1539 | ||
1540 | #ifdef DEBUG_IOCTL_INFO | |
1541 | printk(KERN_DEBUG "Frequency table: "); | |
1542 | for (i = 0; i < 10; i++) { | |
1543 | printk(" %04X", table[i]); | |
1544 | } | |
1545 | printk("\n"); | |
1546 | #endif | |
1547 | ||
1548 | /* Look in the table to see whether the frequency is allowed. */ | |
1549 | if (!(table[9 - ((freq - 24) / 16)] & | |
1550 | (1 << ((freq - 24) % 16)))) return -EINVAL; /* not allowed */ | |
1551 | } else | |
1552 | return -EINVAL; | |
1553 | ||
1554 | /* if we get a usable frequency */ | |
1555 | if (freq != 0L) { | |
1556 | unsigned short area[16]; | |
1557 | unsigned short dac[2]; | |
1558 | unsigned short area_verify[16]; | |
1559 | unsigned short dac_verify[2]; | |
1560 | /* Corresponding gain (in the power adjust value table) | |
1561 | * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8 | |
1562 | * and WCIN062D.DOC, page 6.2.9. */ | |
1563 | unsigned short power_limit[] = { 40, 80, 120, 160, 0 }; | |
1564 | int power_band = 0; /* Selected band */ | |
1565 | unsigned short power_adjust; /* Correct value */ | |
1566 | ||
1567 | /* Search for the gain. */ | |
1568 | power_band = 0; | |
1569 | while ((freq > power_limit[power_band]) && | |
1570 | (power_limit[++power_band] != 0)); | |
1571 | ||
1572 | /* Read the first area. */ | |
1573 | fee_read(ioaddr, 0x00, area, 16); | |
1574 | ||
1575 | /* Read the DAC. */ | |
1576 | fee_read(ioaddr, 0x60, dac, 2); | |
1577 | ||
1578 | /* Read the new power adjust value. */ | |
1579 | fee_read(ioaddr, 0x6B - (power_band >> 1), &power_adjust, | |
1580 | 1); | |
1581 | if (power_band & 0x1) | |
1582 | power_adjust >>= 8; | |
1583 | else | |
1584 | power_adjust &= 0xFF; | |
1585 | ||
1586 | #ifdef DEBUG_IOCTL_INFO | |
1587 | printk(KERN_DEBUG "WaveLAN EEPROM Area 1: "); | |
1588 | for (i = 0; i < 16; i++) { | |
1589 | printk(" %04X", area[i]); | |
1590 | } | |
1591 | printk("\n"); | |
1592 | ||
1593 | printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n", | |
1594 | dac[0], dac[1]); | |
1595 | #endif | |
1596 | ||
1597 | /* Frequency offset (for info only) */ | |
1598 | area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F); | |
1599 | ||
1600 | /* Receiver Principle main divider coefficient */ | |
1601 | area[3] = (freq >> 1) + 2400L - 352L; | |
1602 | area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF); | |
1603 | ||
1604 | /* Transmitter Main divider coefficient */ | |
1605 | area[13] = (freq >> 1) + 2400L; | |
1606 | area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF); | |
1607 | ||
1608 | /* Other parts of the area are flags, bit streams or unused. */ | |
1609 | ||
1610 | /* Set the value in the DAC. */ | |
1611 | dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80); | |
1612 | dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF); | |
1613 | ||
1614 | /* Write the first area. */ | |
1615 | fee_write(ioaddr, 0x00, area, 16); | |
1616 | ||
1617 | /* Write the DAC. */ | |
1618 | fee_write(ioaddr, 0x60, dac, 2); | |
1619 | ||
1620 | /* We now should verify here that the writing of the EEPROM went OK. */ | |
1621 | ||
1622 | /* Reread the first area. */ | |
1623 | fee_read(ioaddr, 0x00, area_verify, 16); | |
1624 | ||
1625 | /* Reread the DAC. */ | |
1626 | fee_read(ioaddr, 0x60, dac_verify, 2); | |
1627 | ||
1628 | /* Compare. */ | |
1629 | if (memcmp(area, area_verify, 16 * 2) || | |
1630 | memcmp(dac, dac_verify, 2 * 2)) { | |
1631 | #ifdef DEBUG_IOCTL_ERROR | |
1632 | printk(KERN_INFO | |
1633 | "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n"); | |
1634 | #endif | |
1635 | return -EOPNOTSUPP; | |
1636 | } | |
1637 | ||
1638 | /* We must download the frequency parameters to the | |
1639 | * synthesizers (from the EEPROM - area 1) | |
1640 | * Note: as the EEPROM is automatically decremented, we set the end | |
1641 | * if the area... */ | |
1642 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x0F); | |
1643 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), | |
1644 | MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD); | |
1645 | ||
1646 | /* Wait until the download is finished. */ | |
1647 | fee_wait(ioaddr, 100, 100); | |
1648 | ||
1649 | /* We must now download the power adjust value (gain) to | |
1650 | * the synthesizers (from the EEPROM - area 7 - DAC). */ | |
1651 | mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x61); | |
1652 | mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), | |
1653 | MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD); | |
1654 | ||
1655 | /* Wait for the download to finish. */ | |
1656 | fee_wait(ioaddr, 100, 100); | |
1657 | ||
1658 | #ifdef DEBUG_IOCTL_INFO | |
1659 | /* Verification of what we have done */ | |
1660 | ||
1661 | printk(KERN_DEBUG "WaveLAN EEPROM Area 1: "); | |
1662 | for (i = 0; i < 16; i++) { | |
1663 | printk(" %04X", area_verify[i]); | |
1664 | } | |
1665 | printk("\n"); | |
1666 | ||
1667 | printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n", | |
1668 | dac_verify[0], dac_verify[1]); | |
1669 | #endif | |
1670 | ||
1671 | return 0; | |
1672 | } else | |
1673 | return -EINVAL; /* Bah, never get there... */ | |
1674 | } | |
1675 | ||
1676 | /*------------------------------------------------------------------*/ | |
1677 | /* | |
1678 | * Give the list of available frequencies. | |
1679 | */ | |
858119e1 | 1680 | static int wv_frequency_list(unsigned long ioaddr, /* I/O port of the card */ |
1da177e4 LT |
1681 | iw_freq * list, /* List of frequencies to fill */ |
1682 | int max) | |
1683 | { /* Maximum number of frequencies */ | |
1684 | u16 table[10]; /* Authorized frequency table */ | |
1685 | long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */ | |
1686 | int i; /* index in the table */ | |
1687 | int c = 0; /* Channel number */ | |
1688 | ||
1689 | /* Read the frequency table. */ | |
1690 | fee_read(ioaddr, 0x71 /* frequency table */ , table, 10); | |
1691 | ||
1692 | /* Check all frequencies. */ | |
1693 | i = 0; | |
1694 | for (freq = 0; freq < 150; freq++) | |
1695 | /* Look in the table if the frequency is allowed */ | |
1696 | if (table[9 - (freq / 16)] & (1 << (freq % 16))) { | |
1697 | /* Compute approximate channel number */ | |
0a92dd0a | 1698 | while ((c < ARRAY_SIZE(channel_bands)) && |
a192491a | 1699 | (((channel_bands[c] >> 1) - 24) < freq)) |
1da177e4 LT |
1700 | c++; |
1701 | list[i].i = c; /* Set the list index */ | |
1702 | ||
1703 | /* put in the list */ | |
1704 | list[i].m = (((freq + 24) * 5) + 24000L) * 10000; | |
1705 | list[i++].e = 1; | |
1706 | ||
1707 | /* Check number. */ | |
1708 | if (i >= max) | |
1709 | return (i); | |
1710 | } | |
1711 | ||
1712 | return (i); | |
1713 | } | |
1714 | ||
1715 | #ifdef IW_WIRELESS_SPY | |
1716 | /*------------------------------------------------------------------*/ | |
1717 | /* | |
1718 | * Gather wireless spy statistics: for each packet, compare the source | |
1719 | * address with our list, and if they match, get the statistics. | |
1720 | * Sorry, but this function really needs the wireless extensions. | |
1721 | */ | |
1722 | static inline void wl_spy_gather(struct net_device * dev, | |
1723 | u8 * mac, /* MAC address */ | |
1724 | u8 * stats) /* Statistics to gather */ | |
1725 | { | |
1726 | struct iw_quality wstats; | |
1727 | ||
1728 | wstats.qual = stats[2] & MMR_SGNL_QUAL; | |
1729 | wstats.level = stats[0] & MMR_SIGNAL_LVL; | |
1730 | wstats.noise = stats[1] & MMR_SILENCE_LVL; | |
1731 | wstats.updated = 0x7; | |
1732 | ||
1733 | /* Update spy records */ | |
1734 | wireless_spy_update(dev, mac, &wstats); | |
1735 | } | |
1736 | #endif /* IW_WIRELESS_SPY */ | |
1737 | ||
1738 | #ifdef HISTOGRAM | |
1739 | /*------------------------------------------------------------------*/ | |
1740 | /* | |
1741 | * This function calculates a histogram of the signal level. | |
1742 | * As the noise is quite constant, it's like doing it on the SNR. | |
1743 | * We have defined a set of interval (lp->his_range), and each time | |
1744 | * the level goes in that interval, we increment the count (lp->his_sum). | |
1745 | * With this histogram you may detect if one WaveLAN is really weak, | |
1746 | * or you may also calculate the mean and standard deviation of the level. | |
1747 | */ | |
1748 | static inline void wl_his_gather(struct net_device * dev, u8 * stats) | |
1749 | { /* Statistics to gather */ | |
1750 | net_local *lp = (net_local *) dev->priv; | |
1751 | u8 level = stats[0] & MMR_SIGNAL_LVL; | |
1752 | int i; | |
1753 | ||
1754 | /* Find the correct interval. */ | |
1755 | i = 0; | |
1756 | while ((i < (lp->his_number - 1)) | |
1757 | && (level >= lp->his_range[i++])); | |
1758 | ||
1759 | /* Increment interval counter. */ | |
1760 | (lp->his_sum[i])++; | |
1761 | } | |
1762 | #endif /* HISTOGRAM */ | |
1763 | ||
1764 | /*------------------------------------------------------------------*/ | |
1765 | /* | |
1766 | * Wireless Handler : get protocol name | |
1767 | */ | |
1768 | static int wavelan_get_name(struct net_device *dev, | |
1769 | struct iw_request_info *info, | |
1770 | union iwreq_data *wrqu, | |
1771 | char *extra) | |
1772 | { | |
1773 | strcpy(wrqu->name, "WaveLAN"); | |
1774 | return 0; | |
1775 | } | |
1776 | ||
1777 | /*------------------------------------------------------------------*/ | |
1778 | /* | |
1779 | * Wireless Handler : set NWID | |
1780 | */ | |
1781 | static int wavelan_set_nwid(struct net_device *dev, | |
1782 | struct iw_request_info *info, | |
1783 | union iwreq_data *wrqu, | |
1784 | char *extra) | |
1785 | { | |
1786 | unsigned long ioaddr = dev->base_addr; | |
1787 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
1788 | psa_t psa; | |
1789 | mm_t m; | |
1790 | unsigned long flags; | |
1791 | int ret = 0; | |
1792 | ||
1793 | /* Disable interrupts and save flags. */ | |
1794 | spin_lock_irqsave(&lp->spinlock, flags); | |
1795 | ||
1796 | /* Set NWID in WaveLAN. */ | |
1797 | if (!wrqu->nwid.disabled) { | |
1798 | /* Set NWID in psa */ | |
1799 | psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8; | |
1800 | psa.psa_nwid[1] = wrqu->nwid.value & 0xFF; | |
1801 | psa.psa_nwid_select = 0x01; | |
1802 | psa_write(ioaddr, lp->hacr, | |
1803 | (char *) psa.psa_nwid - (char *) &psa, | |
1804 | (unsigned char *) psa.psa_nwid, 3); | |
1805 | ||
1806 | /* Set NWID in mmc. */ | |
1807 | m.w.mmw_netw_id_l = psa.psa_nwid[1]; | |
1808 | m.w.mmw_netw_id_h = psa.psa_nwid[0]; | |
1809 | mmc_write(ioaddr, | |
1810 | (char *) &m.w.mmw_netw_id_l - | |
1811 | (char *) &m, | |
1812 | (unsigned char *) &m.w.mmw_netw_id_l, 2); | |
1813 | mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), 0x00); | |
1814 | } else { | |
1815 | /* Disable NWID in the psa. */ | |
1816 | psa.psa_nwid_select = 0x00; | |
1817 | psa_write(ioaddr, lp->hacr, | |
1818 | (char *) &psa.psa_nwid_select - | |
1819 | (char *) &psa, | |
1820 | (unsigned char *) &psa.psa_nwid_select, | |
1821 | 1); | |
1822 | ||
1823 | /* Disable NWID in the mmc (no filtering). */ | |
1824 | mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), | |
1825 | MMW_LOOPT_SEL_DIS_NWID); | |
1826 | } | |
1827 | /* update the Wavelan checksum */ | |
1828 | update_psa_checksum(dev, ioaddr, lp->hacr); | |
1829 | ||
1830 | /* Enable interrupts and restore flags. */ | |
1831 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1832 | ||
1833 | return ret; | |
1834 | } | |
1835 | ||
1836 | /*------------------------------------------------------------------*/ | |
1837 | /* | |
1838 | * Wireless Handler : get NWID | |
1839 | */ | |
1840 | static int wavelan_get_nwid(struct net_device *dev, | |
1841 | struct iw_request_info *info, | |
1842 | union iwreq_data *wrqu, | |
1843 | char *extra) | |
1844 | { | |
1845 | unsigned long ioaddr = dev->base_addr; | |
1846 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
1847 | psa_t psa; | |
1848 | unsigned long flags; | |
1849 | int ret = 0; | |
1850 | ||
1851 | /* Disable interrupts and save flags. */ | |
1852 | spin_lock_irqsave(&lp->spinlock, flags); | |
1853 | ||
1854 | /* Read the NWID. */ | |
1855 | psa_read(ioaddr, lp->hacr, | |
1856 | (char *) psa.psa_nwid - (char *) &psa, | |
1857 | (unsigned char *) psa.psa_nwid, 3); | |
1858 | wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1]; | |
1859 | wrqu->nwid.disabled = !(psa.psa_nwid_select); | |
1860 | wrqu->nwid.fixed = 1; /* Superfluous */ | |
1861 | ||
1862 | /* Enable interrupts and restore flags. */ | |
1863 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1864 | ||
1865 | return ret; | |
1866 | } | |
1867 | ||
1868 | /*------------------------------------------------------------------*/ | |
1869 | /* | |
1870 | * Wireless Handler : set frequency | |
1871 | */ | |
1872 | static int wavelan_set_freq(struct net_device *dev, | |
1873 | struct iw_request_info *info, | |
1874 | union iwreq_data *wrqu, | |
1875 | char *extra) | |
1876 | { | |
1877 | unsigned long ioaddr = dev->base_addr; | |
1878 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
1879 | unsigned long flags; | |
1880 | int ret; | |
1881 | ||
1882 | /* Disable interrupts and save flags. */ | |
1883 | spin_lock_irqsave(&lp->spinlock, flags); | |
1884 | ||
1885 | /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */ | |
1886 | if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) & | |
1887 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) | |
1888 | ret = wv_set_frequency(ioaddr, &(wrqu->freq)); | |
1889 | else | |
1890 | ret = -EOPNOTSUPP; | |
1891 | ||
1892 | /* Enable interrupts and restore flags. */ | |
1893 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1894 | ||
1895 | return ret; | |
1896 | } | |
1897 | ||
1898 | /*------------------------------------------------------------------*/ | |
1899 | /* | |
1900 | * Wireless Handler : get frequency | |
1901 | */ | |
1902 | static int wavelan_get_freq(struct net_device *dev, | |
1903 | struct iw_request_info *info, | |
1904 | union iwreq_data *wrqu, | |
1905 | char *extra) | |
1906 | { | |
1907 | unsigned long ioaddr = dev->base_addr; | |
1908 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
1909 | psa_t psa; | |
1910 | unsigned long flags; | |
1911 | int ret = 0; | |
1912 | ||
1913 | /* Disable interrupts and save flags. */ | |
1914 | spin_lock_irqsave(&lp->spinlock, flags); | |
1915 | ||
1916 | /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). | |
1917 | * Does it work for everybody, especially old cards? */ | |
1918 | if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) & | |
1919 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) { | |
1920 | unsigned short freq; | |
1921 | ||
1922 | /* Ask the EEPROM to read the frequency from the first area. */ | |
1923 | fee_read(ioaddr, 0x00, &freq, 1); | |
1924 | wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000; | |
1925 | wrqu->freq.e = 1; | |
1926 | } else { | |
1927 | psa_read(ioaddr, lp->hacr, | |
1928 | (char *) &psa.psa_subband - (char *) &psa, | |
1929 | (unsigned char *) &psa.psa_subband, 1); | |
1930 | ||
1931 | if (psa.psa_subband <= 4) { | |
1932 | wrqu->freq.m = fixed_bands[psa.psa_subband]; | |
1933 | wrqu->freq.e = (psa.psa_subband != 0); | |
1934 | } else | |
1935 | ret = -EOPNOTSUPP; | |
1936 | } | |
1937 | ||
1938 | /* Enable interrupts and restore flags. */ | |
1939 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1940 | ||
1941 | return ret; | |
1942 | } | |
1943 | ||
1944 | /*------------------------------------------------------------------*/ | |
1945 | /* | |
1946 | * Wireless Handler : set level threshold | |
1947 | */ | |
1948 | static int wavelan_set_sens(struct net_device *dev, | |
1949 | struct iw_request_info *info, | |
1950 | union iwreq_data *wrqu, | |
1951 | char *extra) | |
1952 | { | |
1953 | unsigned long ioaddr = dev->base_addr; | |
1954 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
1955 | psa_t psa; | |
1956 | unsigned long flags; | |
1957 | int ret = 0; | |
1958 | ||
1959 | /* Disable interrupts and save flags. */ | |
1960 | spin_lock_irqsave(&lp->spinlock, flags); | |
1961 | ||
1962 | /* Set the level threshold. */ | |
1963 | /* We should complain loudly if wrqu->sens.fixed = 0, because we | |
1964 | * can't set auto mode... */ | |
1965 | psa.psa_thr_pre_set = wrqu->sens.value & 0x3F; | |
1966 | psa_write(ioaddr, lp->hacr, | |
1967 | (char *) &psa.psa_thr_pre_set - (char *) &psa, | |
1968 | (unsigned char *) &psa.psa_thr_pre_set, 1); | |
1969 | /* update the Wavelan checksum */ | |
1970 | update_psa_checksum(dev, ioaddr, lp->hacr); | |
1971 | mmc_out(ioaddr, mmwoff(0, mmw_thr_pre_set), | |
1972 | psa.psa_thr_pre_set); | |
1973 | ||
1974 | /* Enable interrupts and restore flags. */ | |
1975 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1976 | ||
1977 | return ret; | |
1978 | } | |
1979 | ||
1980 | /*------------------------------------------------------------------*/ | |
1981 | /* | |
1982 | * Wireless Handler : get level threshold | |
1983 | */ | |
1984 | static int wavelan_get_sens(struct net_device *dev, | |
1985 | struct iw_request_info *info, | |
1986 | union iwreq_data *wrqu, | |
1987 | char *extra) | |
1988 | { | |
1989 | unsigned long ioaddr = dev->base_addr; | |
1990 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
1991 | psa_t psa; | |
1992 | unsigned long flags; | |
1993 | int ret = 0; | |
1994 | ||
1995 | /* Disable interrupts and save flags. */ | |
1996 | spin_lock_irqsave(&lp->spinlock, flags); | |
1997 | ||
1998 | /* Read the level threshold. */ | |
1999 | psa_read(ioaddr, lp->hacr, | |
2000 | (char *) &psa.psa_thr_pre_set - (char *) &psa, | |
2001 | (unsigned char *) &psa.psa_thr_pre_set, 1); | |
2002 | wrqu->sens.value = psa.psa_thr_pre_set & 0x3F; | |
2003 | wrqu->sens.fixed = 1; | |
2004 | ||
2005 | /* Enable interrupts and restore flags. */ | |
2006 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2007 | ||
2008 | return ret; | |
2009 | } | |
2010 | ||
2011 | /*------------------------------------------------------------------*/ | |
2012 | /* | |
2013 | * Wireless Handler : set encryption key | |
2014 | */ | |
2015 | static int wavelan_set_encode(struct net_device *dev, | |
2016 | struct iw_request_info *info, | |
2017 | union iwreq_data *wrqu, | |
2018 | char *extra) | |
2019 | { | |
2020 | unsigned long ioaddr = dev->base_addr; | |
2021 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
2022 | unsigned long flags; | |
2023 | psa_t psa; | |
2024 | int ret = 0; | |
2025 | ||
2026 | /* Disable interrupts and save flags. */ | |
2027 | spin_lock_irqsave(&lp->spinlock, flags); | |
2028 | ||
2029 | /* Check if capable of encryption */ | |
2030 | if (!mmc_encr(ioaddr)) { | |
2031 | ret = -EOPNOTSUPP; | |
2032 | } | |
2033 | ||
2034 | /* Check the size of the key */ | |
2035 | if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) { | |
2036 | ret = -EINVAL; | |
2037 | } | |
2038 | ||
2039 | if(!ret) { | |
2040 | /* Basic checking... */ | |
2041 | if (wrqu->encoding.length == 8) { | |
2042 | /* Copy the key in the driver */ | |
2043 | memcpy(psa.psa_encryption_key, extra, | |
2044 | wrqu->encoding.length); | |
2045 | psa.psa_encryption_select = 1; | |
2046 | ||
2047 | psa_write(ioaddr, lp->hacr, | |
2048 | (char *) &psa.psa_encryption_select - | |
2049 | (char *) &psa, | |
2050 | (unsigned char *) &psa. | |
2051 | psa_encryption_select, 8 + 1); | |
2052 | ||
2053 | mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), | |
2054 | MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE); | |
2055 | mmc_write(ioaddr, mmwoff(0, mmw_encr_key), | |
2056 | (unsigned char *) &psa. | |
2057 | psa_encryption_key, 8); | |
2058 | } | |
2059 | ||
2060 | /* disable encryption */ | |
2061 | if (wrqu->encoding.flags & IW_ENCODE_DISABLED) { | |
2062 | psa.psa_encryption_select = 0; | |
2063 | psa_write(ioaddr, lp->hacr, | |
2064 | (char *) &psa.psa_encryption_select - | |
2065 | (char *) &psa, | |
2066 | (unsigned char *) &psa. | |
2067 | psa_encryption_select, 1); | |
2068 | ||
2069 | mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), 0); | |
2070 | } | |
2071 | /* update the Wavelan checksum */ | |
2072 | update_psa_checksum(dev, ioaddr, lp->hacr); | |
2073 | } | |
2074 | ||
2075 | /* Enable interrupts and restore flags. */ | |
2076 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2077 | ||
2078 | return ret; | |
2079 | } | |
2080 | ||
2081 | /*------------------------------------------------------------------*/ | |
2082 | /* | |
2083 | * Wireless Handler : get encryption key | |
2084 | */ | |
2085 | static int wavelan_get_encode(struct net_device *dev, | |
2086 | struct iw_request_info *info, | |
2087 | union iwreq_data *wrqu, | |
2088 | char *extra) | |
2089 | { | |
2090 | unsigned long ioaddr = dev->base_addr; | |
2091 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
2092 | psa_t psa; | |
2093 | unsigned long flags; | |
2094 | int ret = 0; | |
2095 | ||
2096 | /* Disable interrupts and save flags. */ | |
2097 | spin_lock_irqsave(&lp->spinlock, flags); | |
2098 | ||
2099 | /* Check if encryption is available */ | |
2100 | if (!mmc_encr(ioaddr)) { | |
2101 | ret = -EOPNOTSUPP; | |
2102 | } else { | |
2103 | /* Read the encryption key */ | |
2104 | psa_read(ioaddr, lp->hacr, | |
2105 | (char *) &psa.psa_encryption_select - | |
2106 | (char *) &psa, | |
2107 | (unsigned char *) &psa. | |
2108 | psa_encryption_select, 1 + 8); | |
2109 | ||
2110 | /* encryption is enabled ? */ | |
2111 | if (psa.psa_encryption_select) | |
2112 | wrqu->encoding.flags = IW_ENCODE_ENABLED; | |
2113 | else | |
2114 | wrqu->encoding.flags = IW_ENCODE_DISABLED; | |
2115 | wrqu->encoding.flags |= mmc_encr(ioaddr); | |
2116 | ||
2117 | /* Copy the key to the user buffer */ | |
2118 | wrqu->encoding.length = 8; | |
2119 | memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length); | |
2120 | } | |
2121 | ||
2122 | /* Enable interrupts and restore flags. */ | |
2123 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2124 | ||
2125 | return ret; | |
2126 | } | |
2127 | ||
2128 | /*------------------------------------------------------------------*/ | |
2129 | /* | |
2130 | * Wireless Handler : get range info | |
2131 | */ | |
2132 | static int wavelan_get_range(struct net_device *dev, | |
2133 | struct iw_request_info *info, | |
2134 | union iwreq_data *wrqu, | |
2135 | char *extra) | |
2136 | { | |
2137 | unsigned long ioaddr = dev->base_addr; | |
2138 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
2139 | struct iw_range *range = (struct iw_range *) extra; | |
2140 | unsigned long flags; | |
2141 | int ret = 0; | |
2142 | ||
2143 | /* Set the length (very important for backward compatibility) */ | |
2144 | wrqu->data.length = sizeof(struct iw_range); | |
2145 | ||
2146 | /* Set all the info we don't care or don't know about to zero */ | |
2147 | memset(range, 0, sizeof(struct iw_range)); | |
2148 | ||
2149 | /* Set the Wireless Extension versions */ | |
2150 | range->we_version_compiled = WIRELESS_EXT; | |
2151 | range->we_version_source = 9; | |
2152 | ||
2153 | /* Set information in the range struct. */ | |
2154 | range->throughput = 1.6 * 1000 * 1000; /* don't argue on this ! */ | |
2155 | range->min_nwid = 0x0000; | |
2156 | range->max_nwid = 0xFFFF; | |
2157 | ||
2158 | range->sensitivity = 0x3F; | |
2159 | range->max_qual.qual = MMR_SGNL_QUAL; | |
2160 | range->max_qual.level = MMR_SIGNAL_LVL; | |
2161 | range->max_qual.noise = MMR_SILENCE_LVL; | |
2162 | range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */ | |
2163 | /* Need to get better values for those two */ | |
2164 | range->avg_qual.level = 30; | |
2165 | range->avg_qual.noise = 8; | |
2166 | ||
2167 | range->num_bitrates = 1; | |
2168 | range->bitrate[0] = 2000000; /* 2 Mb/s */ | |
2169 | ||
2170 | /* Event capability (kernel + driver) */ | |
2171 | range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) | | |
2172 | IW_EVENT_CAPA_MASK(0x8B04)); | |
2173 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | |
2174 | ||
2175 | /* Disable interrupts and save flags. */ | |
2176 | spin_lock_irqsave(&lp->spinlock, flags); | |
2177 | ||
2178 | /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */ | |
2179 | if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) & | |
2180 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) { | |
2181 | range->num_channels = 10; | |
2182 | range->num_frequency = wv_frequency_list(ioaddr, range->freq, | |
2183 | IW_MAX_FREQUENCIES); | |
2184 | } else | |
2185 | range->num_channels = range->num_frequency = 0; | |
2186 | ||
2187 | /* Encryption supported ? */ | |
2188 | if (mmc_encr(ioaddr)) { | |
2189 | range->encoding_size[0] = 8; /* DES = 64 bits key */ | |
2190 | range->num_encoding_sizes = 1; | |
2191 | range->max_encoding_tokens = 1; /* Only one key possible */ | |
2192 | } else { | |
2193 | range->num_encoding_sizes = 0; | |
2194 | range->max_encoding_tokens = 0; | |
2195 | } | |
2196 | ||
2197 | /* Enable interrupts and restore flags. */ | |
2198 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2199 | ||
2200 | return ret; | |
2201 | } | |
2202 | ||
2203 | /*------------------------------------------------------------------*/ | |
2204 | /* | |
2205 | * Wireless Private Handler : set quality threshold | |
2206 | */ | |
2207 | static int wavelan_set_qthr(struct net_device *dev, | |
2208 | struct iw_request_info *info, | |
2209 | union iwreq_data *wrqu, | |
2210 | char *extra) | |
2211 | { | |
2212 | unsigned long ioaddr = dev->base_addr; | |
2213 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
2214 | psa_t psa; | |
2215 | unsigned long flags; | |
2216 | ||
2217 | /* Disable interrupts and save flags. */ | |
2218 | spin_lock_irqsave(&lp->spinlock, flags); | |
2219 | ||
2220 | psa.psa_quality_thr = *(extra) & 0x0F; | |
2221 | psa_write(ioaddr, lp->hacr, | |
2222 | (char *) &psa.psa_quality_thr - (char *) &psa, | |
2223 | (unsigned char *) &psa.psa_quality_thr, 1); | |
2224 | /* update the Wavelan checksum */ | |
2225 | update_psa_checksum(dev, ioaddr, lp->hacr); | |
2226 | mmc_out(ioaddr, mmwoff(0, mmw_quality_thr), | |
2227 | psa.psa_quality_thr); | |
2228 | ||
2229 | /* Enable interrupts and restore flags. */ | |
2230 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2231 | ||
2232 | return 0; | |
2233 | } | |
2234 | ||
2235 | /*------------------------------------------------------------------*/ | |
2236 | /* | |
2237 | * Wireless Private Handler : get quality threshold | |
2238 | */ | |
2239 | static int wavelan_get_qthr(struct net_device *dev, | |
2240 | struct iw_request_info *info, | |
2241 | union iwreq_data *wrqu, | |
2242 | char *extra) | |
2243 | { | |
2244 | unsigned long ioaddr = dev->base_addr; | |
2245 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
2246 | psa_t psa; | |
2247 | unsigned long flags; | |
2248 | ||
2249 | /* Disable interrupts and save flags. */ | |
2250 | spin_lock_irqsave(&lp->spinlock, flags); | |
2251 | ||
2252 | psa_read(ioaddr, lp->hacr, | |
2253 | (char *) &psa.psa_quality_thr - (char *) &psa, | |
2254 | (unsigned char *) &psa.psa_quality_thr, 1); | |
2255 | *(extra) = psa.psa_quality_thr & 0x0F; | |
2256 | ||
2257 | /* Enable interrupts and restore flags. */ | |
2258 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2259 | ||
2260 | return 0; | |
2261 | } | |
2262 | ||
2263 | #ifdef HISTOGRAM | |
2264 | /*------------------------------------------------------------------*/ | |
2265 | /* | |
2266 | * Wireless Private Handler : set histogram | |
2267 | */ | |
2268 | static int wavelan_set_histo(struct net_device *dev, | |
2269 | struct iw_request_info *info, | |
2270 | union iwreq_data *wrqu, | |
2271 | char *extra) | |
2272 | { | |
2273 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
2274 | ||
2275 | /* Check the number of intervals. */ | |
2276 | if (wrqu->data.length > 16) { | |
2277 | return(-E2BIG); | |
2278 | } | |
2279 | ||
2280 | /* Disable histo while we copy the addresses. | |
2281 | * As we don't disable interrupts, we need to do this */ | |
2282 | lp->his_number = 0; | |
2283 | ||
2284 | /* Are there ranges to copy? */ | |
2285 | if (wrqu->data.length > 0) { | |
2286 | /* Copy interval ranges to the driver */ | |
2287 | memcpy(lp->his_range, extra, wrqu->data.length); | |
2288 | ||
2289 | { | |
2290 | int i; | |
2291 | printk(KERN_DEBUG "Histo :"); | |
2292 | for(i = 0; i < wrqu->data.length; i++) | |
2293 | printk(" %d", lp->his_range[i]); | |
2294 | printk("\n"); | |
2295 | } | |
2296 | ||
2297 | /* Reset result structure. */ | |
2298 | memset(lp->his_sum, 0x00, sizeof(long) * 16); | |
2299 | } | |
2300 | ||
2301 | /* Now we can set the number of ranges */ | |
2302 | lp->his_number = wrqu->data.length; | |
2303 | ||
2304 | return(0); | |
2305 | } | |
2306 | ||
2307 | /*------------------------------------------------------------------*/ | |
2308 | /* | |
2309 | * Wireless Private Handler : get histogram | |
2310 | */ | |
2311 | static int wavelan_get_histo(struct net_device *dev, | |
2312 | struct iw_request_info *info, | |
2313 | union iwreq_data *wrqu, | |
2314 | char *extra) | |
2315 | { | |
2316 | net_local *lp = (net_local *) dev->priv; /* lp is not unused */ | |
2317 | ||
2318 | /* Set the number of intervals. */ | |
2319 | wrqu->data.length = lp->his_number; | |
2320 | ||
2321 | /* Give back the distribution statistics */ | |
2322 | if(lp->his_number > 0) | |
2323 | memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number); | |
2324 | ||
2325 | return(0); | |
2326 | } | |
2327 | #endif /* HISTOGRAM */ | |
2328 | ||
2329 | /*------------------------------------------------------------------*/ | |
2330 | /* | |
2331 | * Structures to export the Wireless Handlers | |
2332 | */ | |
2333 | ||
2334 | static const iw_handler wavelan_handler[] = | |
2335 | { | |
2336 | NULL, /* SIOCSIWNAME */ | |
2337 | wavelan_get_name, /* SIOCGIWNAME */ | |
2338 | wavelan_set_nwid, /* SIOCSIWNWID */ | |
2339 | wavelan_get_nwid, /* SIOCGIWNWID */ | |
2340 | wavelan_set_freq, /* SIOCSIWFREQ */ | |
2341 | wavelan_get_freq, /* SIOCGIWFREQ */ | |
2342 | NULL, /* SIOCSIWMODE */ | |
2343 | NULL, /* SIOCGIWMODE */ | |
2344 | wavelan_set_sens, /* SIOCSIWSENS */ | |
2345 | wavelan_get_sens, /* SIOCGIWSENS */ | |
2346 | NULL, /* SIOCSIWRANGE */ | |
2347 | wavelan_get_range, /* SIOCGIWRANGE */ | |
2348 | NULL, /* SIOCSIWPRIV */ | |
2349 | NULL, /* SIOCGIWPRIV */ | |
2350 | NULL, /* SIOCSIWSTATS */ | |
2351 | NULL, /* SIOCGIWSTATS */ | |
2352 | iw_handler_set_spy, /* SIOCSIWSPY */ | |
2353 | iw_handler_get_spy, /* SIOCGIWSPY */ | |
2354 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ | |
2355 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ | |
2356 | NULL, /* SIOCSIWAP */ | |
2357 | NULL, /* SIOCGIWAP */ | |
2358 | NULL, /* -- hole -- */ | |
2359 | NULL, /* SIOCGIWAPLIST */ | |
2360 | NULL, /* -- hole -- */ | |
2361 | NULL, /* -- hole -- */ | |
2362 | NULL, /* SIOCSIWESSID */ | |
2363 | NULL, /* SIOCGIWESSID */ | |
2364 | NULL, /* SIOCSIWNICKN */ | |
2365 | NULL, /* SIOCGIWNICKN */ | |
2366 | NULL, /* -- hole -- */ | |
2367 | NULL, /* -- hole -- */ | |
2368 | NULL, /* SIOCSIWRATE */ | |
2369 | NULL, /* SIOCGIWRATE */ | |
2370 | NULL, /* SIOCSIWRTS */ | |
2371 | NULL, /* SIOCGIWRTS */ | |
2372 | NULL, /* SIOCSIWFRAG */ | |
2373 | NULL, /* SIOCGIWFRAG */ | |
2374 | NULL, /* SIOCSIWTXPOW */ | |
2375 | NULL, /* SIOCGIWTXPOW */ | |
2376 | NULL, /* SIOCSIWRETRY */ | |
2377 | NULL, /* SIOCGIWRETRY */ | |
2378 | /* Bummer ! Why those are only at the end ??? */ | |
2379 | wavelan_set_encode, /* SIOCSIWENCODE */ | |
2380 | wavelan_get_encode, /* SIOCGIWENCODE */ | |
2381 | }; | |
2382 | ||
2383 | static const iw_handler wavelan_private_handler[] = | |
2384 | { | |
2385 | wavelan_set_qthr, /* SIOCIWFIRSTPRIV */ | |
2386 | wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */ | |
2387 | #ifdef HISTOGRAM | |
2388 | wavelan_set_histo, /* SIOCIWFIRSTPRIV + 2 */ | |
2389 | wavelan_get_histo, /* SIOCIWFIRSTPRIV + 3 */ | |
2390 | #endif /* HISTOGRAM */ | |
2391 | }; | |
2392 | ||
2393 | static const struct iw_priv_args wavelan_private_args[] = { | |
2394 | /*{ cmd, set_args, get_args, name } */ | |
2395 | { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" }, | |
2396 | { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" }, | |
2397 | { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" }, | |
2398 | { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" }, | |
2399 | }; | |
2400 | ||
2401 | static const struct iw_handler_def wavelan_handler_def = | |
2402 | { | |
2403 | .num_standard = sizeof(wavelan_handler)/sizeof(iw_handler), | |
2404 | .num_private = sizeof(wavelan_private_handler)/sizeof(iw_handler), | |
2405 | .num_private_args = sizeof(wavelan_private_args)/sizeof(struct iw_priv_args), | |
2406 | .standard = wavelan_handler, | |
2407 | .private = wavelan_private_handler, | |
2408 | .private_args = wavelan_private_args, | |
2409 | .get_wireless_stats = wavelan_get_wireless_stats, | |
2410 | }; | |
2411 | ||
2412 | /*------------------------------------------------------------------*/ | |
2413 | /* | |
2414 | * Get wireless statistics. | |
2415 | * Called by /proc/net/wireless | |
2416 | */ | |
2417 | static iw_stats *wavelan_get_wireless_stats(struct net_device * dev) | |
2418 | { | |
2419 | unsigned long ioaddr = dev->base_addr; | |
2420 | net_local *lp = (net_local *) dev->priv; | |
2421 | mmr_t m; | |
2422 | iw_stats *wstats; | |
2423 | unsigned long flags; | |
2424 | ||
2425 | #ifdef DEBUG_IOCTL_TRACE | |
2426 | printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", | |
2427 | dev->name); | |
2428 | #endif | |
2429 | ||
2430 | /* Check */ | |
2431 | if (lp == (net_local *) NULL) | |
2432 | return (iw_stats *) NULL; | |
2433 | ||
2434 | /* Disable interrupts and save flags. */ | |
2435 | spin_lock_irqsave(&lp->spinlock, flags); | |
2436 | ||
2437 | wstats = &lp->wstats; | |
2438 | ||
2439 | /* Get data from the mmc. */ | |
2440 | mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1); | |
2441 | ||
2442 | mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1); | |
2443 | mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, | |
2444 | 2); | |
2445 | mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, | |
2446 | 4); | |
2447 | ||
2448 | mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0); | |
2449 | ||
2450 | /* Copy data to wireless stuff. */ | |
2451 | wstats->status = m.mmr_dce_status & MMR_DCE_STATUS; | |
2452 | wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL; | |
2453 | wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL; | |
2454 | wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL; | |
2455 | wstats->qual.updated = (((m. mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) | |
2456 | | ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) | |
2457 | | ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5)); | |
2458 | wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l; | |
2459 | wstats->discard.code = 0L; | |
2460 | wstats->discard.misc = 0L; | |
2461 | ||
2462 | /* Enable interrupts and restore flags. */ | |
2463 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2464 | ||
2465 | #ifdef DEBUG_IOCTL_TRACE | |
2466 | printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", | |
2467 | dev->name); | |
2468 | #endif | |
2469 | return &lp->wstats; | |
2470 | } | |
1da177e4 LT |
2471 | |
2472 | /************************* PACKET RECEPTION *************************/ | |
2473 | /* | |
2474 | * This part deals with receiving the packets. | |
2475 | * The interrupt handler gets an interrupt when a packet has been | |
2476 | * successfully received and calls this part. | |
2477 | */ | |
2478 | ||
2479 | /*------------------------------------------------------------------*/ | |
2480 | /* | |
2481 | * This routine does the actual copying of data (including the Ethernet | |
2482 | * header structure) from the WaveLAN card to an sk_buff chain that | |
2483 | * will be passed up to the network interface layer. NOTE: we | |
2484 | * currently don't handle trailer protocols (neither does the rest of | |
2485 | * the network interface), so if that is needed, it will (at least in | |
2486 | * part) be added here. The contents of the receive ring buffer are | |
2487 | * copied to a message chain that is then passed to the kernel. | |
2488 | * | |
2489 | * Note: if any errors occur, the packet is "dropped on the floor". | |
2490 | * (called by wv_packet_rcv()) | |
2491 | */ | |
858119e1 | 2492 | static void |
1da177e4 LT |
2493 | wv_packet_read(struct net_device * dev, u16 buf_off, int sksize) |
2494 | { | |
2495 | net_local *lp = (net_local *) dev->priv; | |
2496 | unsigned long ioaddr = dev->base_addr; | |
2497 | struct sk_buff *skb; | |
2498 | ||
2499 | #ifdef DEBUG_RX_TRACE | |
2500 | printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n", | |
2501 | dev->name, buf_off, sksize); | |
2502 | #endif | |
2503 | ||
2504 | /* Allocate buffer for the data */ | |
2505 | if ((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL) { | |
2506 | #ifdef DEBUG_RX_ERROR | |
2507 | printk(KERN_INFO | |
2508 | "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n", | |
2509 | dev->name, sksize); | |
2510 | #endif | |
2511 | lp->stats.rx_dropped++; | |
2512 | return; | |
2513 | } | |
2514 | ||
1da177e4 LT |
2515 | /* Copy the packet to the buffer. */ |
2516 | obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize); | |
2517 | skb->protocol = eth_type_trans(skb, dev); | |
2518 | ||
2519 | #ifdef DEBUG_RX_INFO | |
98e399f8 ACM |
2520 | wv_packet_info(skb_mac_header(skb), sksize, dev->name, |
2521 | "wv_packet_read"); | |
1da177e4 LT |
2522 | #endif /* DEBUG_RX_INFO */ |
2523 | ||
2524 | /* Statistics-gathering and associated stuff. | |
2525 | * It seem a bit messy with all the define, but it's really | |
2526 | * simple... */ | |
2527 | if ( | |
2528 | #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */ | |
2529 | (lp->spy_data.spy_number > 0) || | |
2530 | #endif /* IW_WIRELESS_SPY */ | |
2531 | #ifdef HISTOGRAM | |
2532 | (lp->his_number > 0) || | |
2533 | #endif /* HISTOGRAM */ | |
2534 | 0) { | |
2535 | u8 stats[3]; /* signal level, noise level, signal quality */ | |
2536 | ||
2537 | /* Read signal level, silence level and signal quality bytes */ | |
2538 | /* Note: in the PCMCIA hardware, these are part of the frame. | |
2539 | * It seems that for the ISA hardware, it's nowhere to be | |
2540 | * found in the frame, so I'm obliged to do this (it has a | |
2541 | * side effect on /proc/net/wireless). | |
2542 | * Any ideas? | |
2543 | */ | |
2544 | mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1); | |
2545 | mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3); | |
2546 | mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0); | |
2547 | ||
2548 | #ifdef DEBUG_RX_INFO | |
2549 | printk(KERN_DEBUG | |
2550 | "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n", | |
2551 | dev->name, stats[0] & 0x3F, stats[1] & 0x3F, | |
2552 | stats[2] & 0x0F); | |
2553 | #endif | |
2554 | ||
2555 | /* Spying stuff */ | |
2556 | #ifdef IW_WIRELESS_SPY | |
98e399f8 | 2557 | wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE, |
1da177e4 LT |
2558 | stats); |
2559 | #endif /* IW_WIRELESS_SPY */ | |
2560 | #ifdef HISTOGRAM | |
2561 | wl_his_gather(dev, stats); | |
2562 | #endif /* HISTOGRAM */ | |
2563 | } | |
2564 | ||
2565 | /* | |
2566 | * Hand the packet to the network module. | |
2567 | */ | |
2568 | netif_rx(skb); | |
2569 | ||
2570 | /* Keep statistics up to date */ | |
2571 | dev->last_rx = jiffies; | |
2572 | lp->stats.rx_packets++; | |
2573 | lp->stats.rx_bytes += sksize; | |
2574 | ||
2575 | #ifdef DEBUG_RX_TRACE | |
2576 | printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name); | |
2577 | #endif | |
2578 | } | |
2579 | ||
2580 | /*------------------------------------------------------------------*/ | |
2581 | /* | |
2582 | * Transfer as many packets as we can | |
2583 | * from the device RAM. | |
2584 | * (called in wavelan_interrupt()). | |
2585 | * Note : the spinlock is already grabbed for us. | |
2586 | */ | |
858119e1 | 2587 | static void wv_receive(struct net_device * dev) |
1da177e4 LT |
2588 | { |
2589 | unsigned long ioaddr = dev->base_addr; | |
2590 | net_local *lp = (net_local *) dev->priv; | |
2591 | fd_t fd; | |
2592 | rbd_t rbd; | |
2593 | int nreaped = 0; | |
2594 | ||
2595 | #ifdef DEBUG_RX_TRACE | |
2596 | printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name); | |
2597 | #endif | |
2598 | ||
2599 | /* Loop on each received packet. */ | |
2600 | for (;;) { | |
2601 | obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd, | |
2602 | sizeof(fd)); | |
2603 | ||
2604 | /* Note about the status : | |
2605 | * It start up to be 0 (the value we set). Then, when the RU | |
2606 | * grab the buffer to prepare for reception, it sets the | |
2607 | * FD_STATUS_B flag. When the RU has finished receiving the | |
2608 | * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate | |
2609 | * completion and set the other flags to indicate the eventual | |
2610 | * errors. FD_STATUS_OK indicates that the reception was OK. | |
2611 | */ | |
2612 | ||
2613 | /* If the current frame is not complete, we have reached the end. */ | |
2614 | if ((fd.fd_status & FD_STATUS_C) != FD_STATUS_C) | |
2615 | break; /* This is how we exit the loop. */ | |
2616 | ||
2617 | nreaped++; | |
2618 | ||
2619 | /* Check whether frame was correctly received. */ | |
2620 | if ((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK) { | |
2621 | /* Does the frame contain a pointer to the data? Let's check. */ | |
2622 | if (fd.fd_rbd_offset != I82586NULL) { | |
2623 | /* Read the receive buffer descriptor */ | |
2624 | obram_read(ioaddr, fd.fd_rbd_offset, | |
2625 | (unsigned char *) &rbd, | |
2626 | sizeof(rbd)); | |
2627 | ||
2628 | #ifdef DEBUG_RX_ERROR | |
2629 | if ((rbd.rbd_status & RBD_STATUS_EOF) != | |
2630 | RBD_STATUS_EOF) printk(KERN_INFO | |
2631 | "%s: wv_receive(): missing EOF flag.\n", | |
2632 | dev->name); | |
2633 | ||
2634 | if ((rbd.rbd_status & RBD_STATUS_F) != | |
2635 | RBD_STATUS_F) printk(KERN_INFO | |
2636 | "%s: wv_receive(): missing F flag.\n", | |
2637 | dev->name); | |
2638 | #endif /* DEBUG_RX_ERROR */ | |
2639 | ||
2640 | /* Read the packet and transmit to Linux */ | |
2641 | wv_packet_read(dev, rbd.rbd_bufl, | |
2642 | rbd. | |
2643 | rbd_status & | |
2644 | RBD_STATUS_ACNT); | |
2645 | } | |
2646 | #ifdef DEBUG_RX_ERROR | |
2647 | else /* if frame has no data */ | |
2648 | printk(KERN_INFO | |
2649 | "%s: wv_receive(): frame has no data.\n", | |
2650 | dev->name); | |
2651 | #endif | |
2652 | } else { /* If reception was no successful */ | |
2653 | ||
2654 | lp->stats.rx_errors++; | |
2655 | ||
2656 | #ifdef DEBUG_RX_INFO | |
2657 | printk(KERN_DEBUG | |
2658 | "%s: wv_receive(): frame not received successfully (%X).\n", | |
2659 | dev->name, fd.fd_status); | |
2660 | #endif | |
2661 | ||
2662 | #ifdef DEBUG_RX_ERROR | |
2663 | if ((fd.fd_status & FD_STATUS_S6) != 0) | |
2664 | printk(KERN_INFO | |
2665 | "%s: wv_receive(): no EOF flag.\n", | |
2666 | dev->name); | |
2667 | #endif | |
2668 | ||
2669 | if ((fd.fd_status & FD_STATUS_S7) != 0) { | |
2670 | lp->stats.rx_length_errors++; | |
2671 | #ifdef DEBUG_RX_FAIL | |
2672 | printk(KERN_DEBUG | |
2673 | "%s: wv_receive(): frame too short.\n", | |
2674 | dev->name); | |
2675 | #endif | |
2676 | } | |
2677 | ||
2678 | if ((fd.fd_status & FD_STATUS_S8) != 0) { | |
2679 | lp->stats.rx_over_errors++; | |
2680 | #ifdef DEBUG_RX_FAIL | |
2681 | printk(KERN_DEBUG | |
2682 | "%s: wv_receive(): rx DMA overrun.\n", | |
2683 | dev->name); | |
2684 | #endif | |
2685 | } | |
2686 | ||
2687 | if ((fd.fd_status & FD_STATUS_S9) != 0) { | |
2688 | lp->stats.rx_fifo_errors++; | |
2689 | #ifdef DEBUG_RX_FAIL | |
2690 | printk(KERN_DEBUG | |
2691 | "%s: wv_receive(): ran out of resources.\n", | |
2692 | dev->name); | |
2693 | #endif | |
2694 | } | |
2695 | ||
2696 | if ((fd.fd_status & FD_STATUS_S10) != 0) { | |
2697 | lp->stats.rx_frame_errors++; | |
2698 | #ifdef DEBUG_RX_FAIL | |
2699 | printk(KERN_DEBUG | |
2700 | "%s: wv_receive(): alignment error.\n", | |
2701 | dev->name); | |
2702 | #endif | |
2703 | } | |
2704 | ||
2705 | if ((fd.fd_status & FD_STATUS_S11) != 0) { | |
2706 | lp->stats.rx_crc_errors++; | |
2707 | #ifdef DEBUG_RX_FAIL | |
2708 | printk(KERN_DEBUG | |
2709 | "%s: wv_receive(): CRC error.\n", | |
2710 | dev->name); | |
2711 | #endif | |
2712 | } | |
2713 | } | |
2714 | ||
2715 | fd.fd_status = 0; | |
2716 | obram_write(ioaddr, fdoff(lp->rx_head, fd_status), | |
2717 | (unsigned char *) &fd.fd_status, | |
2718 | sizeof(fd.fd_status)); | |
2719 | ||
2720 | fd.fd_command = FD_COMMAND_EL; | |
2721 | obram_write(ioaddr, fdoff(lp->rx_head, fd_command), | |
2722 | (unsigned char *) &fd.fd_command, | |
2723 | sizeof(fd.fd_command)); | |
2724 | ||
2725 | fd.fd_command = 0; | |
2726 | obram_write(ioaddr, fdoff(lp->rx_last, fd_command), | |
2727 | (unsigned char *) &fd.fd_command, | |
2728 | sizeof(fd.fd_command)); | |
2729 | ||
2730 | lp->rx_last = lp->rx_head; | |
2731 | lp->rx_head = fd.fd_link_offset; | |
2732 | } /* for(;;) -> loop on all frames */ | |
2733 | ||
2734 | #ifdef DEBUG_RX_INFO | |
2735 | if (nreaped > 1) | |
2736 | printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n", | |
2737 | dev->name, nreaped); | |
2738 | #endif | |
2739 | #ifdef DEBUG_RX_TRACE | |
2740 | printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name); | |
2741 | #endif | |
2742 | } | |
2743 | ||
2744 | /*********************** PACKET TRANSMISSION ***********************/ | |
2745 | /* | |
2746 | * This part deals with sending packets through the WaveLAN. | |
2747 | * | |
2748 | */ | |
2749 | ||
2750 | /*------------------------------------------------------------------*/ | |
2751 | /* | |
2752 | * This routine fills in the appropriate registers and memory | |
2753 | * locations on the WaveLAN card and starts the card off on | |
2754 | * the transmit. | |
2755 | * | |
2756 | * The principle: | |
2757 | * Each block contains a transmit command, a NOP command, | |
2758 | * a transmit block descriptor and a buffer. | |
2759 | * The CU read the transmit block which point to the tbd, | |
2760 | * read the tbd and the content of the buffer. | |
2761 | * When it has finish with it, it goes to the next command | |
2762 | * which in our case is the NOP. The NOP points on itself, | |
2763 | * so the CU stop here. | |
2764 | * When we add the next block, we modify the previous nop | |
2765 | * to make it point on the new tx command. | |
2766 | * Simple, isn't it ? | |
2767 | * | |
2768 | * (called in wavelan_packet_xmit()) | |
2769 | */ | |
858119e1 | 2770 | static int wv_packet_write(struct net_device * dev, void *buf, short length) |
1da177e4 LT |
2771 | { |
2772 | net_local *lp = (net_local *) dev->priv; | |
2773 | unsigned long ioaddr = dev->base_addr; | |
2774 | unsigned short txblock; | |
2775 | unsigned short txpred; | |
2776 | unsigned short tx_addr; | |
2777 | unsigned short nop_addr; | |
2778 | unsigned short tbd_addr; | |
2779 | unsigned short buf_addr; | |
2780 | ac_tx_t tx; | |
2781 | ac_nop_t nop; | |
2782 | tbd_t tbd; | |
2783 | int clen = length; | |
2784 | unsigned long flags; | |
2785 | ||
2786 | #ifdef DEBUG_TX_TRACE | |
2787 | printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, | |
2788 | length); | |
2789 | #endif | |
2790 | ||
2791 | spin_lock_irqsave(&lp->spinlock, flags); | |
2792 | ||
2793 | /* Check nothing bad has happened */ | |
2794 | if (lp->tx_n_in_use == (NTXBLOCKS - 1)) { | |
2795 | #ifdef DEBUG_TX_ERROR | |
2796 | printk(KERN_INFO "%s: wv_packet_write(): Tx queue full.\n", | |
2797 | dev->name); | |
2798 | #endif | |
2799 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2800 | return 1; | |
2801 | } | |
2802 | ||
2803 | /* Calculate addresses of next block and previous block. */ | |
2804 | txblock = lp->tx_first_free; | |
2805 | txpred = txblock - TXBLOCKZ; | |
2806 | if (txpred < OFFSET_CU) | |
2807 | txpred += NTXBLOCKS * TXBLOCKZ; | |
2808 | lp->tx_first_free += TXBLOCKZ; | |
2809 | if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ) | |
2810 | lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ; | |
2811 | ||
2812 | lp->tx_n_in_use++; | |
2813 | ||
2814 | /* Calculate addresses of the different parts of the block. */ | |
2815 | tx_addr = txblock; | |
2816 | nop_addr = tx_addr + sizeof(tx); | |
2817 | tbd_addr = nop_addr + sizeof(nop); | |
2818 | buf_addr = tbd_addr + sizeof(tbd); | |
2819 | ||
2820 | /* | |
2821 | * Transmit command | |
2822 | */ | |
2823 | tx.tx_h.ac_status = 0; | |
2824 | obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status), | |
2825 | (unsigned char *) &tx.tx_h.ac_status, | |
2826 | sizeof(tx.tx_h.ac_status)); | |
2827 | ||
2828 | /* | |
2829 | * NOP command | |
2830 | */ | |
2831 | nop.nop_h.ac_status = 0; | |
2832 | obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status), | |
2833 | (unsigned char *) &nop.nop_h.ac_status, | |
2834 | sizeof(nop.nop_h.ac_status)); | |
2835 | nop.nop_h.ac_link = nop_addr; | |
2836 | obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link), | |
2837 | (unsigned char *) &nop.nop_h.ac_link, | |
2838 | sizeof(nop.nop_h.ac_link)); | |
2839 | ||
2840 | /* | |
2841 | * Transmit buffer descriptor | |
2842 | */ | |
2843 | tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen); | |
2844 | tbd.tbd_next_bd_offset = I82586NULL; | |
2845 | tbd.tbd_bufl = buf_addr; | |
2846 | tbd.tbd_bufh = 0; | |
2847 | obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd)); | |
2848 | ||
2849 | /* | |
2850 | * Data | |
2851 | */ | |
2852 | obram_write(ioaddr, buf_addr, buf, length); | |
2853 | ||
2854 | /* | |
2855 | * Overwrite the predecessor NOP link | |
2856 | * so that it points to this txblock. | |
2857 | */ | |
2858 | nop_addr = txpred + sizeof(tx); | |
2859 | nop.nop_h.ac_status = 0; | |
2860 | obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status), | |
2861 | (unsigned char *) &nop.nop_h.ac_status, | |
2862 | sizeof(nop.nop_h.ac_status)); | |
2863 | nop.nop_h.ac_link = txblock; | |
2864 | obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link), | |
2865 | (unsigned char *) &nop.nop_h.ac_link, | |
2866 | sizeof(nop.nop_h.ac_link)); | |
2867 | ||
2868 | /* Make sure the watchdog will keep quiet for a while */ | |
2869 | dev->trans_start = jiffies; | |
2870 | ||
2871 | /* Keep stats up to date. */ | |
2872 | lp->stats.tx_bytes += length; | |
2873 | ||
2874 | if (lp->tx_first_in_use == I82586NULL) | |
2875 | lp->tx_first_in_use = txblock; | |
2876 | ||
2877 | if (lp->tx_n_in_use < NTXBLOCKS - 1) | |
2878 | netif_wake_queue(dev); | |
2879 | ||
2880 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2881 | ||
2882 | #ifdef DEBUG_TX_INFO | |
2883 | wv_packet_info((u8 *) buf, length, dev->name, | |
2884 | "wv_packet_write"); | |
2885 | #endif /* DEBUG_TX_INFO */ | |
2886 | ||
2887 | #ifdef DEBUG_TX_TRACE | |
2888 | printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name); | |
2889 | #endif | |
2890 | ||
2891 | return 0; | |
2892 | } | |
2893 | ||
2894 | /*------------------------------------------------------------------*/ | |
2895 | /* | |
2896 | * This routine is called when we want to send a packet (NET3 callback) | |
2897 | * In this routine, we check if the harware is ready to accept | |
2898 | * the packet. We also prevent reentrance. Then we call the function | |
2899 | * to send the packet. | |
2900 | */ | |
2901 | static int wavelan_packet_xmit(struct sk_buff *skb, struct net_device * dev) | |
2902 | { | |
2903 | net_local *lp = (net_local *) dev->priv; | |
2904 | unsigned long flags; | |
aa95abef | 2905 | char data[ETH_ZLEN]; |
1da177e4 LT |
2906 | |
2907 | #ifdef DEBUG_TX_TRACE | |
2908 | printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name, | |
2909 | (unsigned) skb); | |
2910 | #endif | |
2911 | ||
2912 | /* | |
2913 | * Block a timer-based transmit from overlapping. | |
2914 | * In other words, prevent reentering this routine. | |
2915 | */ | |
2916 | netif_stop_queue(dev); | |
2917 | ||
2918 | /* If somebody has asked to reconfigure the controller, | |
2919 | * we can do it now. | |
2920 | */ | |
2921 | if (lp->reconfig_82586) { | |
2922 | spin_lock_irqsave(&lp->spinlock, flags); | |
2923 | wv_82586_config(dev); | |
2924 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2925 | /* Check that we can continue */ | |
2926 | if (lp->tx_n_in_use == (NTXBLOCKS - 1)) | |
2927 | return 1; | |
2928 | } | |
2929 | #ifdef DEBUG_TX_ERROR | |
2930 | if (skb->next) | |
2931 | printk(KERN_INFO "skb has next\n"); | |
2932 | #endif | |
2933 | ||
2934 | /* Do we need some padding? */ | |
2935 | /* Note : on wireless the propagation time is in the order of 1us, | |
2936 | * and we don't have the Ethernet specific requirement of beeing | |
2937 | * able to detect collisions, therefore in theory we don't really | |
2938 | * need to pad. Jean II */ | |
2939 | if (skb->len < ETH_ZLEN) { | |
aa95abef | 2940 | memset(data, 0, ETH_ZLEN); |
d626f62b | 2941 | skb_copy_from_linear_data(skb, data, skb->len); |
aa95abef AC |
2942 | /* Write packet on the card */ |
2943 | if(wv_packet_write(dev, data, ETH_ZLEN)) | |
2944 | return 1; /* We failed */ | |
1da177e4 | 2945 | } |
aa95abef | 2946 | else if(wv_packet_write(dev, skb->data, skb->len)) |
1da177e4 LT |
2947 | return 1; /* We failed */ |
2948 | ||
aa95abef | 2949 | |
1da177e4 LT |
2950 | dev_kfree_skb(skb); |
2951 | ||
2952 | #ifdef DEBUG_TX_TRACE | |
2953 | printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name); | |
2954 | #endif | |
2955 | return 0; | |
2956 | } | |
2957 | ||
2958 | /*********************** HARDWARE CONFIGURATION ***********************/ | |
2959 | /* | |
2960 | * This part does the real job of starting and configuring the hardware. | |
2961 | */ | |
2962 | ||
2963 | /*--------------------------------------------------------------------*/ | |
2964 | /* | |
2965 | * Routine to initialize the Modem Management Controller. | |
2966 | * (called by wv_hw_reset()) | |
2967 | */ | |
858119e1 | 2968 | static int wv_mmc_init(struct net_device * dev) |
1da177e4 LT |
2969 | { |
2970 | unsigned long ioaddr = dev->base_addr; | |
2971 | net_local *lp = (net_local *) dev->priv; | |
2972 | psa_t psa; | |
2973 | mmw_t m; | |
2974 | int configured; | |
2975 | ||
2976 | #ifdef DEBUG_CONFIG_TRACE | |
2977 | printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name); | |
2978 | #endif | |
2979 | ||
2980 | /* Read the parameter storage area. */ | |
2981 | psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa)); | |
2982 | ||
2983 | #ifdef USE_PSA_CONFIG | |
2984 | configured = psa.psa_conf_status & 1; | |
2985 | #else | |
2986 | configured = 0; | |
2987 | #endif | |
2988 | ||
2989 | /* Is the PSA is not configured */ | |
2990 | if (!configured) { | |
2991 | /* User will be able to configure NWID later (with iwconfig). */ | |
2992 | psa.psa_nwid[0] = 0; | |
2993 | psa.psa_nwid[1] = 0; | |
2994 | ||
2995 | /* no NWID checking since NWID is not set */ | |
2996 | psa.psa_nwid_select = 0; | |
2997 | ||
2998 | /* Disable encryption */ | |
2999 | psa.psa_encryption_select = 0; | |
3000 | ||
3001 | /* Set to standard values: | |
3002 | * 0x04 for AT, | |
3003 | * 0x01 for MCA, | |
3004 | * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document) | |
3005 | */ | |
3006 | if (psa.psa_comp_number & 1) | |
3007 | psa.psa_thr_pre_set = 0x01; | |
3008 | else | |
3009 | psa.psa_thr_pre_set = 0x04; | |
3010 | psa.psa_quality_thr = 0x03; | |
3011 | ||
3012 | /* It is configured */ | |
3013 | psa.psa_conf_status |= 1; | |
3014 | ||
3015 | #ifdef USE_PSA_CONFIG | |
3016 | /* Write the psa. */ | |
3017 | psa_write(ioaddr, lp->hacr, | |
3018 | (char *) psa.psa_nwid - (char *) &psa, | |
3019 | (unsigned char *) psa.psa_nwid, 4); | |
3020 | psa_write(ioaddr, lp->hacr, | |
3021 | (char *) &psa.psa_thr_pre_set - (char *) &psa, | |
3022 | (unsigned char *) &psa.psa_thr_pre_set, 1); | |
3023 | psa_write(ioaddr, lp->hacr, | |
3024 | (char *) &psa.psa_quality_thr - (char *) &psa, | |
3025 | (unsigned char *) &psa.psa_quality_thr, 1); | |
3026 | psa_write(ioaddr, lp->hacr, | |
3027 | (char *) &psa.psa_conf_status - (char *) &psa, | |
3028 | (unsigned char *) &psa.psa_conf_status, 1); | |
3029 | /* update the Wavelan checksum */ | |
3030 | update_psa_checksum(dev, ioaddr, lp->hacr); | |
3031 | #endif | |
3032 | } | |
3033 | ||
3034 | /* Zero the mmc structure. */ | |
3035 | memset(&m, 0x00, sizeof(m)); | |
3036 | ||
3037 | /* Copy PSA info to the mmc. */ | |
3038 | m.mmw_netw_id_l = psa.psa_nwid[1]; | |
3039 | m.mmw_netw_id_h = psa.psa_nwid[0]; | |
3040 | ||
3041 | if (psa.psa_nwid_select & 1) | |
3042 | m.mmw_loopt_sel = 0x00; | |
3043 | else | |
3044 | m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID; | |
3045 | ||
3046 | memcpy(&m.mmw_encr_key, &psa.psa_encryption_key, | |
3047 | sizeof(m.mmw_encr_key)); | |
3048 | ||
3049 | if (psa.psa_encryption_select) | |
3050 | m.mmw_encr_enable = | |
3051 | MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE; | |
3052 | else | |
3053 | m.mmw_encr_enable = 0; | |
3054 | ||
3055 | m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F; | |
3056 | m.mmw_quality_thr = psa.psa_quality_thr & 0x0F; | |
3057 | ||
3058 | /* | |
3059 | * Set default modem control parameters. | |
3060 | * See NCR document 407-0024326 Rev. A. | |
3061 | */ | |
3062 | m.mmw_jabber_enable = 0x01; | |
3063 | m.mmw_freeze = 0; | |
3064 | m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN; | |
3065 | m.mmw_ifs = 0x20; | |
3066 | m.mmw_mod_delay = 0x04; | |
3067 | m.mmw_jam_time = 0x38; | |
3068 | ||
3069 | m.mmw_des_io_invert = 0; | |
3070 | m.mmw_decay_prm = 0; | |
3071 | m.mmw_decay_updat_prm = 0; | |
3072 | ||
3073 | /* Write all info to MMC. */ | |
3074 | mmc_write(ioaddr, 0, (u8 *) & m, sizeof(m)); | |
3075 | ||
3076 | /* The following code starts the modem of the 2.00 frequency | |
3077 | * selectable cards at power on. It's not strictly needed for the | |
3078 | * following boots. | |
3079 | * The original patch was by Joe Finney for the PCMCIA driver, but | |
3080 | * I've cleaned it up a bit and added documentation. | |
3081 | * Thanks to Loeke Brederveld from Lucent for the info. | |
3082 | */ | |
3083 | ||
3084 | /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable) | |
3085 | * Does it work for everybody, especially old cards? */ | |
3086 | /* Note: WFREQSEL verifies that it is able to read a sensible | |
3087 | * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID | |
3088 | * is 0xA (Xilinx version) or 0xB (Ariadne version). | |
3089 | * My test is more crude but does work. */ | |
3090 | if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) & | |
3091 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) { | |
3092 | /* We must download the frequency parameters to the | |
3093 | * synthesizers (from the EEPROM - area 1) | |
3094 | * Note: as the EEPROM is automatically decremented, we set the end | |
3095 | * if the area... */ | |
3096 | m.mmw_fee_addr = 0x0F; | |
3097 | m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD; | |
3098 | mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m, | |
3099 | (unsigned char *) &m.mmw_fee_ctrl, 2); | |
3100 | ||
3101 | /* Wait until the download is finished. */ | |
3102 | fee_wait(ioaddr, 100, 100); | |
3103 | ||
3104 | #ifdef DEBUG_CONFIG_INFO | |
3105 | /* The frequency was in the last word downloaded. */ | |
3106 | mmc_read(ioaddr, (char *) &m.mmw_fee_data_l - (char *) &m, | |
3107 | (unsigned char *) &m.mmw_fee_data_l, 2); | |
3108 | ||
3109 | /* Print some info for the user. */ | |
3110 | printk(KERN_DEBUG | |
3111 | "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n", | |
3112 | dev->name, | |
3113 | ((m. | |
3114 | mmw_fee_data_h << 4) | (m.mmw_fee_data_l >> 4)) * | |
3115 | 5 / 2 + 24000L); | |
3116 | #endif | |
3117 | ||
3118 | /* We must now download the power adjust value (gain) to | |
3119 | * the synthesizers (from the EEPROM - area 7 - DAC). */ | |
3120 | m.mmw_fee_addr = 0x61; | |
3121 | m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD; | |
3122 | mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m, | |
3123 | (unsigned char *) &m.mmw_fee_ctrl, 2); | |
3124 | ||
3125 | /* Wait until the download is finished. */ | |
3126 | } | |
3127 | /* if 2.00 card */ | |
3128 | #ifdef DEBUG_CONFIG_TRACE | |
3129 | printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name); | |
3130 | #endif | |
3131 | return 0; | |
3132 | } | |
3133 | ||
3134 | /*------------------------------------------------------------------*/ | |
3135 | /* | |
3136 | * Construct the fd and rbd structures. | |
3137 | * Start the receive unit. | |
3138 | * (called by wv_hw_reset()) | |
3139 | */ | |
858119e1 | 3140 | static int wv_ru_start(struct net_device * dev) |
1da177e4 LT |
3141 | { |
3142 | net_local *lp = (net_local *) dev->priv; | |
3143 | unsigned long ioaddr = dev->base_addr; | |
3144 | u16 scb_cs; | |
3145 | fd_t fd; | |
3146 | rbd_t rbd; | |
3147 | u16 rx; | |
3148 | u16 rx_next; | |
3149 | int i; | |
3150 | ||
3151 | #ifdef DEBUG_CONFIG_TRACE | |
3152 | printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name); | |
3153 | #endif | |
3154 | ||
3155 | obram_read(ioaddr, scboff(OFFSET_SCB, scb_status), | |
3156 | (unsigned char *) &scb_cs, sizeof(scb_cs)); | |
3157 | if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY) | |
3158 | return 0; | |
3159 | ||
3160 | lp->rx_head = OFFSET_RU; | |
3161 | ||
3162 | for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next) { | |
3163 | rx_next = | |
3164 | (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ; | |
3165 | ||
3166 | fd.fd_status = 0; | |
3167 | fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0; | |
3168 | fd.fd_link_offset = rx_next; | |
3169 | fd.fd_rbd_offset = rx + sizeof(fd); | |
3170 | obram_write(ioaddr, rx, (unsigned char *) &fd, sizeof(fd)); | |
3171 | ||
3172 | rbd.rbd_status = 0; | |
3173 | rbd.rbd_next_rbd_offset = I82586NULL; | |
3174 | rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd); | |
3175 | rbd.rbd_bufh = 0; | |
3176 | rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ); | |
3177 | obram_write(ioaddr, rx + sizeof(fd), | |
3178 | (unsigned char *) &rbd, sizeof(rbd)); | |
3179 | ||
3180 | lp->rx_last = rx; | |
3181 | } | |
3182 | ||
3183 | obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset), | |
3184 | (unsigned char *) &lp->rx_head, sizeof(lp->rx_head)); | |
3185 | ||
3186 | scb_cs = SCB_CMD_RUC_GO; | |
3187 | obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), | |
3188 | (unsigned char *) &scb_cs, sizeof(scb_cs)); | |
3189 | ||
3190 | set_chan_attn(ioaddr, lp->hacr); | |
3191 | ||
3192 | for (i = 1000; i > 0; i--) { | |
3193 | obram_read(ioaddr, scboff(OFFSET_SCB, scb_command), | |
3194 | (unsigned char *) &scb_cs, sizeof(scb_cs)); | |
3195 | if (scb_cs == 0) | |
3196 | break; | |
3197 | ||
3198 | udelay(10); | |
3199 | } | |
3200 | ||
3201 | if (i <= 0) { | |
3202 | #ifdef DEBUG_CONFIG_ERROR | |
3203 | printk(KERN_INFO | |
3204 | "%s: wavelan_ru_start(): board not accepting command.\n", | |
3205 | dev->name); | |
3206 | #endif | |
3207 | return -1; | |
3208 | } | |
3209 | #ifdef DEBUG_CONFIG_TRACE | |
3210 | printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name); | |
3211 | #endif | |
3212 | return 0; | |
3213 | } | |
3214 | ||
3215 | /*------------------------------------------------------------------*/ | |
3216 | /* | |
3217 | * Initialise the transmit blocks. | |
3218 | * Start the command unit executing the NOP | |
3219 | * self-loop of the first transmit block. | |
3220 | * | |
3221 | * Here we create the list of send buffers used to transmit packets | |
3222 | * between the PC and the command unit. For each buffer, we create a | |
3223 | * buffer descriptor (pointing on the buffer), a transmit command | |
3224 | * (pointing to the buffer descriptor) and a NOP command. | |
3225 | * The transmit command is linked to the NOP, and the NOP to itself. | |
3226 | * When we will have finished executing the transmit command, we will | |
3227 | * then loop on the NOP. By releasing the NOP link to a new command, | |
3228 | * we may send another buffer. | |
3229 | * | |
3230 | * (called by wv_hw_reset()) | |
3231 | */ | |
858119e1 | 3232 | static int wv_cu_start(struct net_device * dev) |
1da177e4 LT |
3233 | { |
3234 | net_local *lp = (net_local *) dev->priv; | |
3235 | unsigned long ioaddr = dev->base_addr; | |
3236 | int i; | |
3237 | u16 txblock; | |
3238 | u16 first_nop; | |
3239 | u16 scb_cs; | |
3240 | ||
3241 | #ifdef DEBUG_CONFIG_TRACE | |
3242 | printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name); | |
3243 | #endif | |
3244 | ||
3245 | lp->tx_first_free = OFFSET_CU; | |
3246 | lp->tx_first_in_use = I82586NULL; | |
3247 | ||
3248 | for (i = 0, txblock = OFFSET_CU; | |
3249 | i < NTXBLOCKS; i++, txblock += TXBLOCKZ) { | |
3250 | ac_tx_t tx; | |
3251 | ac_nop_t nop; | |
3252 | tbd_t tbd; | |
3253 | unsigned short tx_addr; | |
3254 | unsigned short nop_addr; | |
3255 | unsigned short tbd_addr; | |
3256 | unsigned short buf_addr; | |
3257 | ||
3258 | tx_addr = txblock; | |
3259 | nop_addr = tx_addr + sizeof(tx); | |
3260 | tbd_addr = nop_addr + sizeof(nop); | |
3261 | buf_addr = tbd_addr + sizeof(tbd); | |
3262 | ||
3263 | tx.tx_h.ac_status = 0; | |
3264 | tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I; | |
3265 | tx.tx_h.ac_link = nop_addr; | |
3266 | tx.tx_tbd_offset = tbd_addr; | |
3267 | obram_write(ioaddr, tx_addr, (unsigned char *) &tx, | |
3268 | sizeof(tx)); | |
3269 | ||
3270 | nop.nop_h.ac_status = 0; | |
3271 | nop.nop_h.ac_command = acmd_nop; | |
3272 | nop.nop_h.ac_link = nop_addr; | |
3273 | obram_write(ioaddr, nop_addr, (unsigned char *) &nop, | |
3274 | sizeof(nop)); | |
3275 | ||
3276 | tbd.tbd_status = TBD_STATUS_EOF; | |
3277 | tbd.tbd_next_bd_offset = I82586NULL; | |
3278 | tbd.tbd_bufl = buf_addr; | |
3279 | tbd.tbd_bufh = 0; | |
3280 | obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, | |
3281 | sizeof(tbd)); | |
3282 | } | |
3283 | ||
3284 | first_nop = | |
3285 | OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t); | |
3286 | obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset), | |
3287 | (unsigned char *) &first_nop, sizeof(first_nop)); | |
3288 | ||
3289 | scb_cs = SCB_CMD_CUC_GO; | |
3290 | obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), | |
3291 | (unsigned char *) &scb_cs, sizeof(scb_cs)); | |
3292 | ||
3293 | set_chan_attn(ioaddr, lp->hacr); | |
3294 | ||
3295 | for (i = 1000; i > 0; i--) { | |
3296 | obram_read(ioaddr, scboff(OFFSET_SCB, scb_command), | |
3297 | (unsigned char *) &scb_cs, sizeof(scb_cs)); | |
3298 | if (scb_cs == 0) | |
3299 | break; | |
3300 | ||
3301 | udelay(10); | |
3302 | } | |
3303 | ||
3304 | if (i <= 0) { | |
3305 | #ifdef DEBUG_CONFIG_ERROR | |
3306 | printk(KERN_INFO | |
3307 | "%s: wavelan_cu_start(): board not accepting command.\n", | |
3308 | dev->name); | |
3309 | #endif | |
3310 | return -1; | |
3311 | } | |
3312 | ||
3313 | lp->tx_n_in_use = 0; | |
3314 | netif_start_queue(dev); | |
3315 | #ifdef DEBUG_CONFIG_TRACE | |
3316 | printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name); | |
3317 | #endif | |
3318 | return 0; | |
3319 | } | |
3320 | ||
3321 | /*------------------------------------------------------------------*/ | |
3322 | /* | |
3323 | * This routine does a standard configuration of the WaveLAN | |
3324 | * controller (i82586). | |
3325 | * | |
3326 | * It initialises the scp, iscp and scb structure | |
3327 | * The first two are just pointers to the next. | |
3328 | * The last one is used for basic configuration and for basic | |
3329 | * communication (interrupt status). | |
3330 | * | |
3331 | * (called by wv_hw_reset()) | |
3332 | */ | |
858119e1 | 3333 | static int wv_82586_start(struct net_device * dev) |
1da177e4 LT |
3334 | { |
3335 | net_local *lp = (net_local *) dev->priv; | |
3336 | unsigned long ioaddr = dev->base_addr; | |
3337 | scp_t scp; /* system configuration pointer */ | |
3338 | iscp_t iscp; /* intermediate scp */ | |
3339 | scb_t scb; /* system control block */ | |
3340 | ach_t cb; /* Action command header */ | |
3341 | u8 zeroes[512]; | |
3342 | int i; | |
3343 | ||
3344 | #ifdef DEBUG_CONFIG_TRACE | |
3345 | printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name); | |
3346 | #endif | |
3347 | ||
3348 | /* | |
3349 | * Clear the onboard RAM. | |
3350 | */ | |
3351 | memset(&zeroes[0], 0x00, sizeof(zeroes)); | |
3352 | for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes)) | |
3353 | obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes)); | |
3354 | ||
3355 | /* | |
3356 | * Construct the command unit structures: | |
3357 | * scp, iscp, scb, cb. | |
3358 | */ | |
3359 | memset(&scp, 0x00, sizeof(scp)); | |
3360 | scp.scp_sysbus = SCP_SY_16BBUS; | |
3361 | scp.scp_iscpl = OFFSET_ISCP; | |
3362 | obram_write(ioaddr, OFFSET_SCP, (unsigned char *) &scp, | |
3363 | sizeof(scp)); | |
3364 | ||
3365 | memset(&iscp, 0x00, sizeof(iscp)); | |
3366 | iscp.iscp_busy = 1; | |
3367 | iscp.iscp_offset = OFFSET_SCB; | |
3368 | obram_write(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp, | |
3369 | sizeof(iscp)); | |
3370 | ||
3371 | /* Our first command is to reset the i82586. */ | |
3372 | memset(&scb, 0x00, sizeof(scb)); | |
3373 | scb.scb_command = SCB_CMD_RESET; | |
3374 | scb.scb_cbl_offset = OFFSET_CU; | |
3375 | scb.scb_rfa_offset = OFFSET_RU; | |
3376 | obram_write(ioaddr, OFFSET_SCB, (unsigned char *) &scb, | |
3377 | sizeof(scb)); | |
3378 | ||
3379 | set_chan_attn(ioaddr, lp->hacr); | |
3380 | ||
3381 | /* Wait for command to finish. */ | |
3382 | for (i = 1000; i > 0; i--) { | |
3383 | obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp, | |
3384 | sizeof(iscp)); | |
3385 | ||
3386 | if (iscp.iscp_busy == (unsigned short) 0) | |
3387 | break; | |
3388 | ||
3389 | udelay(10); | |
3390 | } | |
3391 | ||
3392 | if (i <= 0) { | |
3393 | #ifdef DEBUG_CONFIG_ERROR | |
3394 | printk(KERN_INFO | |
3395 | "%s: wv_82586_start(): iscp_busy timeout.\n", | |
3396 | dev->name); | |
3397 | #endif | |
3398 | return -1; | |
3399 | } | |
3400 | ||
3401 | /* Check command completion. */ | |
3402 | for (i = 15; i > 0; i--) { | |
3403 | obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb, | |
3404 | sizeof(scb)); | |
3405 | ||
3406 | if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA)) | |
3407 | break; | |
3408 | ||
3409 | udelay(10); | |
3410 | } | |
3411 | ||
3412 | if (i <= 0) { | |
3413 | #ifdef DEBUG_CONFIG_ERROR | |
3414 | printk(KERN_INFO | |
3415 | "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n", | |
3416 | dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status); | |
3417 | #endif | |
3418 | return -1; | |
3419 | } | |
3420 | ||
3421 | wv_ack(dev); | |
3422 | ||
3423 | /* Set the action command header. */ | |
3424 | memset(&cb, 0x00, sizeof(cb)); | |
3425 | cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose); | |
3426 | cb.ac_link = OFFSET_CU; | |
3427 | obram_write(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb)); | |
3428 | ||
3429 | if (wv_synchronous_cmd(dev, "diag()") == -1) | |
3430 | return -1; | |
3431 | ||
3432 | obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb)); | |
3433 | if (cb.ac_status & AC_SFLD_FAIL) { | |
3434 | #ifdef DEBUG_CONFIG_ERROR | |
3435 | printk(KERN_INFO | |
3436 | "%s: wv_82586_start(): i82586 Self Test failed.\n", | |
3437 | dev->name); | |
3438 | #endif | |
3439 | return -1; | |
3440 | } | |
3441 | #ifdef DEBUG_I82586_SHOW | |
3442 | wv_scb_show(ioaddr); | |
3443 | #endif | |
3444 | ||
3445 | #ifdef DEBUG_CONFIG_TRACE | |
3446 | printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name); | |
3447 | #endif | |
3448 | return 0; | |
3449 | } | |
3450 | ||
3451 | /*------------------------------------------------------------------*/ | |
3452 | /* | |
3453 | * This routine does a standard configuration of the WaveLAN | |
3454 | * controller (i82586). | |
3455 | * | |
3456 | * This routine is a violent hack. We use the first free transmit block | |
3457 | * to make our configuration. In the buffer area, we create the three | |
3458 | * configuration commands (linked). We make the previous NOP point to | |
3459 | * the beginning of the buffer instead of the tx command. After, we go | |
3460 | * as usual to the NOP command. | |
3461 | * Note that only the last command (mc_set) will generate an interrupt. | |
3462 | * | |
3463 | * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit()) | |
3464 | */ | |
3465 | static void wv_82586_config(struct net_device * dev) | |
3466 | { | |
3467 | net_local *lp = (net_local *) dev->priv; | |
3468 | unsigned long ioaddr = dev->base_addr; | |
3469 | unsigned short txblock; | |
3470 | unsigned short txpred; | |
3471 | unsigned short tx_addr; | |
3472 | unsigned short nop_addr; | |
3473 | unsigned short tbd_addr; | |
3474 | unsigned short cfg_addr; | |
3475 | unsigned short ias_addr; | |
3476 | unsigned short mcs_addr; | |
3477 | ac_tx_t tx; | |
3478 | ac_nop_t nop; | |
3479 | ac_cfg_t cfg; /* Configure action */ | |
3480 | ac_ias_t ias; /* IA-setup action */ | |
3481 | ac_mcs_t mcs; /* Multicast setup */ | |
3482 | struct dev_mc_list *dmi; | |
3483 | ||
3484 | #ifdef DEBUG_CONFIG_TRACE | |
3485 | printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name); | |
3486 | #endif | |
3487 | ||
3488 | /* Check nothing bad has happened */ | |
3489 | if (lp->tx_n_in_use == (NTXBLOCKS - 1)) { | |
3490 | #ifdef DEBUG_CONFIG_ERROR | |
3491 | printk(KERN_INFO "%s: wv_82586_config(): Tx queue full.\n", | |
3492 | dev->name); | |
3493 | #endif | |
3494 | return; | |
3495 | } | |
3496 | ||
3497 | /* Calculate addresses of next block and previous block. */ | |
3498 | txblock = lp->tx_first_free; | |
3499 | txpred = txblock - TXBLOCKZ; | |
3500 | if (txpred < OFFSET_CU) | |
3501 | txpred += NTXBLOCKS * TXBLOCKZ; | |
3502 | lp->tx_first_free += TXBLOCKZ; | |
3503 | if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ) | |
3504 | lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ; | |
3505 | ||
3506 | lp->tx_n_in_use++; | |
3507 | ||
3508 | /* Calculate addresses of the different parts of the block. */ | |
3509 | tx_addr = txblock; | |
3510 | nop_addr = tx_addr + sizeof(tx); | |
3511 | tbd_addr = nop_addr + sizeof(nop); | |
3512 | cfg_addr = tbd_addr + sizeof(tbd_t); /* beginning of the buffer */ | |
3513 | ias_addr = cfg_addr + sizeof(cfg); | |
3514 | mcs_addr = ias_addr + sizeof(ias); | |
3515 | ||
3516 | /* | |
3517 | * Transmit command | |
3518 | */ | |
3519 | tx.tx_h.ac_status = 0xFFFF; /* Fake completion value */ | |
3520 | obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status), | |
3521 | (unsigned char *) &tx.tx_h.ac_status, | |
3522 | sizeof(tx.tx_h.ac_status)); | |
3523 | ||
3524 | /* | |
3525 | * NOP command | |
3526 | */ | |
3527 | nop.nop_h.ac_status = 0; | |
3528 | obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status), | |
3529 | (unsigned char *) &nop.nop_h.ac_status, | |
3530 | sizeof(nop.nop_h.ac_status)); | |
3531 | nop.nop_h.ac_link = nop_addr; | |
3532 | obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link), | |
3533 | (unsigned char *) &nop.nop_h.ac_link, | |
3534 | sizeof(nop.nop_h.ac_link)); | |
3535 | ||
3536 | /* Create a configure action. */ | |
3537 | memset(&cfg, 0x00, sizeof(cfg)); | |
3538 | ||
3539 | /* | |
3540 | * For Linux we invert AC_CFG_ALOC() so as to conform | |
3541 | * to the way that net packets reach us from above. | |
3542 | * (See also ac_tx_t.) | |
3543 | * | |
3544 | * Updated from Wavelan Manual WCIN085B | |
3545 | */ | |
3546 | cfg.cfg_byte_cnt = | |
3547 | AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t)); | |
3548 | cfg.cfg_fifolim = AC_CFG_FIFOLIM(4); | |
3549 | cfg.cfg_byte8 = AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0); | |
3550 | cfg.cfg_byte9 = AC_CFG_ELPBCK(0) | | |
3551 | AC_CFG_ILPBCK(0) | | |
3552 | AC_CFG_PRELEN(AC_CFG_PLEN_2) | | |
3553 | AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE); | |
3554 | cfg.cfg_byte10 = AC_CFG_BOFMET(1) | | |
3555 | AC_CFG_ACR(6) | AC_CFG_LINPRIO(0); | |
3556 | cfg.cfg_ifs = 0x20; | |
3557 | cfg.cfg_slotl = 0x0C; | |
3558 | cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0); | |
3559 | cfg.cfg_byte14 = AC_CFG_FLGPAD(0) | | |
3560 | AC_CFG_BTSTF(0) | | |
3561 | AC_CFG_CRC16(0) | | |
3562 | AC_CFG_NCRC(0) | | |
3563 | AC_CFG_TNCRS(1) | | |
3564 | AC_CFG_MANCH(0) | | |
3565 | AC_CFG_BCDIS(0) | AC_CFG_PRM(lp->promiscuous); | |
3566 | cfg.cfg_byte15 = AC_CFG_ICDS(0) | | |
3567 | AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0); | |
3568 | /* | |
3569 | cfg.cfg_min_frm_len = AC_CFG_MNFRM(64); | |
3570 | */ | |
3571 | cfg.cfg_min_frm_len = AC_CFG_MNFRM(8); | |
3572 | ||
3573 | cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure); | |
3574 | cfg.cfg_h.ac_link = ias_addr; | |
3575 | obram_write(ioaddr, cfg_addr, (unsigned char *) &cfg, sizeof(cfg)); | |
3576 | ||
3577 | /* Set up the MAC address */ | |
3578 | memset(&ias, 0x00, sizeof(ias)); | |
3579 | ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup); | |
3580 | ias.ias_h.ac_link = mcs_addr; | |
3581 | memcpy(&ias.ias_addr[0], (unsigned char *) &dev->dev_addr[0], | |
3582 | sizeof(ias.ias_addr)); | |
3583 | obram_write(ioaddr, ias_addr, (unsigned char *) &ias, sizeof(ias)); | |
3584 | ||
3585 | /* Initialize adapter's Ethernet multicast addresses */ | |
3586 | memset(&mcs, 0x00, sizeof(mcs)); | |
3587 | mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup); | |
3588 | mcs.mcs_h.ac_link = nop_addr; | |
3589 | mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count; | |
3590 | obram_write(ioaddr, mcs_addr, (unsigned char *) &mcs, sizeof(mcs)); | |
3591 | ||
3592 | /* Any address to set? */ | |
3593 | if (lp->mc_count) { | |
3594 | for (dmi = dev->mc_list; dmi; dmi = dmi->next) | |
3595 | outsw(PIOP1(ioaddr), (u16 *) dmi->dmi_addr, | |
3596 | WAVELAN_ADDR_SIZE >> 1); | |
3597 | ||
3598 | #ifdef DEBUG_CONFIG_INFO | |
3599 | printk(KERN_DEBUG | |
3600 | "%s: wv_82586_config(): set %d multicast addresses:\n", | |
3601 | dev->name, lp->mc_count); | |
3602 | for (dmi = dev->mc_list; dmi; dmi = dmi->next) | |
3603 | printk(KERN_DEBUG | |
3604 | " %02x:%02x:%02x:%02x:%02x:%02x\n", | |
3605 | dmi->dmi_addr[0], dmi->dmi_addr[1], | |
3606 | dmi->dmi_addr[2], dmi->dmi_addr[3], | |
3607 | dmi->dmi_addr[4], dmi->dmi_addr[5]); | |
3608 | #endif | |
3609 | } | |
3610 | ||
3611 | /* | |
3612 | * Overwrite the predecessor NOP link | |
3613 | * so that it points to the configure action. | |
3614 | */ | |
3615 | nop_addr = txpred + sizeof(tx); | |
3616 | nop.nop_h.ac_status = 0; | |
3617 | obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status), | |
3618 | (unsigned char *) &nop.nop_h.ac_status, | |
3619 | sizeof(nop.nop_h.ac_status)); | |
3620 | nop.nop_h.ac_link = cfg_addr; | |
3621 | obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link), | |
3622 | (unsigned char *) &nop.nop_h.ac_link, | |
3623 | sizeof(nop.nop_h.ac_link)); | |
3624 | ||
3625 | /* Job done, clear the flag */ | |
3626 | lp->reconfig_82586 = 0; | |
3627 | ||
3628 | if (lp->tx_first_in_use == I82586NULL) | |
3629 | lp->tx_first_in_use = txblock; | |
3630 | ||
3631 | if (lp->tx_n_in_use == (NTXBLOCKS - 1)) | |
3632 | netif_stop_queue(dev); | |
3633 | ||
3634 | #ifdef DEBUG_CONFIG_TRACE | |
3635 | printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name); | |
3636 | #endif | |
3637 | } | |
3638 | ||
3639 | /*------------------------------------------------------------------*/ | |
3640 | /* | |
3641 | * This routine, called by wavelan_close(), gracefully stops the | |
3642 | * WaveLAN controller (i82586). | |
3643 | * (called by wavelan_close()) | |
3644 | */ | |
858119e1 | 3645 | static void wv_82586_stop(struct net_device * dev) |
1da177e4 LT |
3646 | { |
3647 | net_local *lp = (net_local *) dev->priv; | |
3648 | unsigned long ioaddr = dev->base_addr; | |
3649 | u16 scb_cmd; | |
3650 | ||
3651 | #ifdef DEBUG_CONFIG_TRACE | |
3652 | printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name); | |
3653 | #endif | |
3654 | ||
3655 | /* Suspend both command unit and receive unit. */ | |
3656 | scb_cmd = | |
3657 | (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC & | |
3658 | SCB_CMD_RUC_SUS); | |
3659 | obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), | |
3660 | (unsigned char *) &scb_cmd, sizeof(scb_cmd)); | |
3661 | set_chan_attn(ioaddr, lp->hacr); | |
3662 | ||
3663 | /* No more interrupts */ | |
3664 | wv_ints_off(dev); | |
3665 | ||
3666 | #ifdef DEBUG_CONFIG_TRACE | |
3667 | printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name); | |
3668 | #endif | |
3669 | } | |
3670 | ||
3671 | /*------------------------------------------------------------------*/ | |
3672 | /* | |
3673 | * Totally reset the WaveLAN and restart it. | |
3674 | * Performs the following actions: | |
3675 | * 1. A power reset (reset DMA) | |
3676 | * 2. Initialize the radio modem (using wv_mmc_init) | |
3677 | * 3. Reset & Configure LAN controller (using wv_82586_start) | |
3678 | * 4. Start the LAN controller's command unit | |
3679 | * 5. Start the LAN controller's receive unit | |
3680 | * (called by wavelan_interrupt(), wavelan_watchdog() & wavelan_open()) | |
3681 | */ | |
3682 | static int wv_hw_reset(struct net_device * dev) | |
3683 | { | |
3684 | net_local *lp = (net_local *) dev->priv; | |
3685 | unsigned long ioaddr = dev->base_addr; | |
3686 | ||
3687 | #ifdef DEBUG_CONFIG_TRACE | |
3688 | printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name, | |
3689 | (unsigned int) dev); | |
3690 | #endif | |
3691 | ||
3692 | /* Increase the number of resets done. */ | |
3693 | lp->nresets++; | |
3694 | ||
3695 | wv_hacr_reset(ioaddr); | |
3696 | lp->hacr = HACR_DEFAULT; | |
3697 | ||
3698 | if ((wv_mmc_init(dev) < 0) || (wv_82586_start(dev) < 0)) | |
3699 | return -1; | |
3700 | ||
3701 | /* Enable the card to send interrupts. */ | |
3702 | wv_ints_on(dev); | |
3703 | ||
3704 | /* Start card functions */ | |
3705 | if (wv_cu_start(dev) < 0) | |
3706 | return -1; | |
3707 | ||
3708 | /* Setup the controller and parameters */ | |
3709 | wv_82586_config(dev); | |
3710 | ||
3711 | /* Finish configuration with the receive unit */ | |
3712 | if (wv_ru_start(dev) < 0) | |
3713 | return -1; | |
3714 | ||
3715 | #ifdef DEBUG_CONFIG_TRACE | |
3716 | printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name); | |
3717 | #endif | |
3718 | return 0; | |
3719 | } | |
3720 | ||
3721 | /*------------------------------------------------------------------*/ | |
3722 | /* | |
3723 | * Check if there is a WaveLAN at the specific base address. | |
3724 | * As a side effect, this reads the MAC address. | |
3725 | * (called in wavelan_probe() and init_module()) | |
3726 | */ | |
3727 | static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac) | |
3728 | { | |
3729 | int i; /* Loop counter */ | |
3730 | ||
3731 | /* Check if the base address if available. */ | |
3732 | if (!request_region(ioaddr, sizeof(ha_t), "wavelan probe")) | |
3733 | return -EBUSY; /* ioaddr already used */ | |
3734 | ||
3735 | /* Reset host interface */ | |
3736 | wv_hacr_reset(ioaddr); | |
3737 | ||
3738 | /* Read the MAC address from the parameter storage area. */ | |
3739 | psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr), | |
3740 | mac, 6); | |
3741 | ||
3742 | release_region(ioaddr, sizeof(ha_t)); | |
3743 | ||
3744 | /* | |
3745 | * Check the first three octets of the address for the manufacturer's code. | |
3746 | * Note: if this can't find your WaveLAN card, you've got a | |
3747 | * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on | |
3748 | * how to configure your card. | |
3749 | */ | |
3750 | for (i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++) | |
3751 | if ((mac[0] == MAC_ADDRESSES[i][0]) && | |
3752 | (mac[1] == MAC_ADDRESSES[i][1]) && | |
3753 | (mac[2] == MAC_ADDRESSES[i][2])) | |
3754 | return 0; | |
3755 | ||
3756 | #ifdef DEBUG_CONFIG_INFO | |
3757 | printk(KERN_WARNING | |
3758 | "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n", | |
3759 | ioaddr, mac[0], mac[1], mac[2]); | |
3760 | #endif | |
3761 | return -ENODEV; | |
3762 | } | |
3763 | ||
3764 | /************************ INTERRUPT HANDLING ************************/ | |
3765 | ||
3766 | /* | |
3767 | * This function is the interrupt handler for the WaveLAN card. This | |
3768 | * routine will be called whenever: | |
3769 | */ | |
7d12e780 | 3770 | static irqreturn_t wavelan_interrupt(int irq, void *dev_id) |
1da177e4 LT |
3771 | { |
3772 | struct net_device *dev; | |
3773 | unsigned long ioaddr; | |
3774 | net_local *lp; | |
3775 | u16 hasr; | |
3776 | u16 status; | |
3777 | u16 ack_cmd; | |
3778 | ||
3779 | dev = dev_id; | |
3780 | ||
3781 | #ifdef DEBUG_INTERRUPT_TRACE | |
3782 | printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name); | |
3783 | #endif | |
3784 | ||
3785 | lp = (net_local *) dev->priv; | |
3786 | ioaddr = dev->base_addr; | |
3787 | ||
3788 | #ifdef DEBUG_INTERRUPT_INFO | |
3789 | /* Check state of our spinlock */ | |
3790 | if(spin_is_locked(&lp->spinlock)) | |
3791 | printk(KERN_DEBUG | |
3792 | "%s: wavelan_interrupt(): spinlock is already locked !!!\n", | |
3793 | dev->name); | |
3794 | #endif | |
3795 | ||
3796 | /* Prevent reentrancy. We need to do that because we may have | |
3797 | * multiple interrupt handler running concurrently. | |
3798 | * It is safe because interrupts are disabled before acquiring | |
3799 | * the spinlock. */ | |
3800 | spin_lock(&lp->spinlock); | |
3801 | ||
3802 | /* We always had spurious interrupts at startup, but lately I | |
3803 | * saw them comming *between* the request_irq() and the | |
3804 | * spin_lock_irqsave() in wavelan_open(), so the spinlock | |
3805 | * protection is no enough. | |
3806 | * So, we also check lp->hacr that will tell us is we enabled | |
3807 | * irqs or not (see wv_ints_on()). | |
3808 | * We can't use netif_running(dev) because we depend on the | |
3809 | * proper processing of the irq generated during the config. */ | |
3810 | ||
3811 | /* Which interrupt it is ? */ | |
3812 | hasr = hasr_read(ioaddr); | |
3813 | ||
3814 | #ifdef DEBUG_INTERRUPT_INFO | |
3815 | printk(KERN_INFO | |
3816 | "%s: wavelan_interrupt(): hasr 0x%04x; hacr 0x%04x.\n", | |
3817 | dev->name, hasr, lp->hacr); | |
3818 | #endif | |
3819 | ||
3820 | /* Check modem interrupt */ | |
3821 | if ((hasr & HASR_MMC_INTR) && (lp->hacr & HACR_MMC_INT_ENABLE)) { | |
3822 | u8 dce_status; | |
3823 | ||
3824 | /* | |
3825 | * Interrupt from the modem management controller. | |
3826 | * This will clear it -- ignored for now. | |
3827 | */ | |
3828 | mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status, | |
3829 | sizeof(dce_status)); | |
3830 | ||
3831 | #ifdef DEBUG_INTERRUPT_ERROR | |
3832 | printk(KERN_INFO | |
3833 | "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n", | |
3834 | dev->name, dce_status); | |
3835 | #endif | |
3836 | } | |
3837 | ||
3838 | /* Check if not controller interrupt */ | |
3839 | if (((hasr & HASR_82586_INTR) == 0) || | |
3840 | ((lp->hacr & HACR_82586_INT_ENABLE) == 0)) { | |
3841 | #ifdef DEBUG_INTERRUPT_ERROR | |
3842 | printk(KERN_INFO | |
3843 | "%s: wavelan_interrupt(): interrupt not coming from i82586 - hasr 0x%04x.\n", | |
3844 | dev->name, hasr); | |
3845 | #endif | |
3846 | spin_unlock (&lp->spinlock); | |
3847 | return IRQ_NONE; | |
3848 | } | |
3849 | ||
3850 | /* Read interrupt data. */ | |
3851 | obram_read(ioaddr, scboff(OFFSET_SCB, scb_status), | |
3852 | (unsigned char *) &status, sizeof(status)); | |
3853 | ||
3854 | /* | |
3855 | * Acknowledge the interrupt(s). | |
3856 | */ | |
3857 | ack_cmd = status & SCB_ST_INT; | |
3858 | obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), | |
3859 | (unsigned char *) &ack_cmd, sizeof(ack_cmd)); | |
3860 | set_chan_attn(ioaddr, lp->hacr); | |
3861 | ||
3862 | #ifdef DEBUG_INTERRUPT_INFO | |
3863 | printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n", | |
3864 | dev->name, status); | |
3865 | #endif | |
3866 | ||
3867 | /* Command completed. */ | |
3868 | if ((status & SCB_ST_CX) == SCB_ST_CX) { | |
3869 | #ifdef DEBUG_INTERRUPT_INFO | |
3870 | printk(KERN_DEBUG | |
3871 | "%s: wavelan_interrupt(): command completed.\n", | |
3872 | dev->name); | |
3873 | #endif | |
3874 | wv_complete(dev, ioaddr, lp); | |
3875 | } | |
3876 | ||
3877 | /* Frame received. */ | |
3878 | if ((status & SCB_ST_FR) == SCB_ST_FR) { | |
3879 | #ifdef DEBUG_INTERRUPT_INFO | |
3880 | printk(KERN_DEBUG | |
3881 | "%s: wavelan_interrupt(): received packet.\n", | |
3882 | dev->name); | |
3883 | #endif | |
3884 | wv_receive(dev); | |
3885 | } | |
3886 | ||
3887 | /* Check the state of the command unit. */ | |
3888 | if (((status & SCB_ST_CNA) == SCB_ST_CNA) || | |
3889 | (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) && | |
3890 | (netif_running(dev)))) { | |
3891 | #ifdef DEBUG_INTERRUPT_ERROR | |
3892 | printk(KERN_INFO | |
3893 | "%s: wavelan_interrupt(): CU inactive -- restarting\n", | |
3894 | dev->name); | |
3895 | #endif | |
3896 | wv_hw_reset(dev); | |
3897 | } | |
3898 | ||
3899 | /* Check the state of the command unit. */ | |
3900 | if (((status & SCB_ST_RNR) == SCB_ST_RNR) || | |
3901 | (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) && | |
3902 | (netif_running(dev)))) { | |
3903 | #ifdef DEBUG_INTERRUPT_ERROR | |
3904 | printk(KERN_INFO | |
3905 | "%s: wavelan_interrupt(): RU not ready -- restarting\n", | |
3906 | dev->name); | |
3907 | #endif | |
3908 | wv_hw_reset(dev); | |
3909 | } | |
3910 | ||
3911 | /* Release spinlock */ | |
3912 | spin_unlock (&lp->spinlock); | |
3913 | ||
3914 | #ifdef DEBUG_INTERRUPT_TRACE | |
3915 | printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name); | |
3916 | #endif | |
3917 | return IRQ_HANDLED; | |
3918 | } | |
3919 | ||
3920 | /*------------------------------------------------------------------*/ | |
3921 | /* | |
3922 | * Watchdog: when we start a transmission, a timer is set for us in the | |
3923 | * kernel. If the transmission completes, this timer is disabled. If | |
3924 | * the timer expires, we are called and we try to unlock the hardware. | |
3925 | */ | |
3926 | static void wavelan_watchdog(struct net_device * dev) | |
3927 | { | |
3928 | net_local * lp = (net_local *)dev->priv; | |
3929 | u_long ioaddr = dev->base_addr; | |
3930 | unsigned long flags; | |
3931 | unsigned int nreaped; | |
3932 | ||
3933 | #ifdef DEBUG_INTERRUPT_TRACE | |
3934 | printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name); | |
3935 | #endif | |
3936 | ||
3937 | #ifdef DEBUG_INTERRUPT_ERROR | |
3938 | printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n", | |
3939 | dev->name); | |
3940 | #endif | |
3941 | ||
3942 | /* Check that we came here for something */ | |
3943 | if (lp->tx_n_in_use <= 0) { | |
3944 | return; | |
3945 | } | |
3946 | ||
3947 | spin_lock_irqsave(&lp->spinlock, flags); | |
3948 | ||
3949 | /* Try to see if some buffers are not free (in case we missed | |
3950 | * an interrupt */ | |
3951 | nreaped = wv_complete(dev, ioaddr, lp); | |
3952 | ||
3953 | #ifdef DEBUG_INTERRUPT_INFO | |
3954 | printk(KERN_DEBUG | |
3955 | "%s: wavelan_watchdog(): %d reaped, %d remain.\n", | |
3956 | dev->name, nreaped, lp->tx_n_in_use); | |
3957 | #endif | |
3958 | ||
3959 | #ifdef DEBUG_PSA_SHOW | |
3960 | { | |
3961 | psa_t psa; | |
3962 | psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa)); | |
3963 | wv_psa_show(&psa); | |
3964 | } | |
3965 | #endif | |
3966 | #ifdef DEBUG_MMC_SHOW | |
3967 | wv_mmc_show(dev); | |
3968 | #endif | |
3969 | #ifdef DEBUG_I82586_SHOW | |
3970 | wv_cu_show(dev); | |
3971 | #endif | |
3972 | ||
3973 | /* If no buffer has been freed */ | |
3974 | if (nreaped == 0) { | |
3975 | #ifdef DEBUG_INTERRUPT_ERROR | |
3976 | printk(KERN_INFO | |
3977 | "%s: wavelan_watchdog(): cleanup failed, trying reset\n", | |
3978 | dev->name); | |
3979 | #endif | |
3980 | wv_hw_reset(dev); | |
3981 | } | |
3982 | ||
3983 | /* At this point, we should have some free Tx buffer ;-) */ | |
3984 | if (lp->tx_n_in_use < NTXBLOCKS - 1) | |
3985 | netif_wake_queue(dev); | |
3986 | ||
3987 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
3988 | ||
3989 | #ifdef DEBUG_INTERRUPT_TRACE | |
3990 | printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name); | |
3991 | #endif | |
3992 | } | |
3993 | ||
3994 | /********************* CONFIGURATION CALLBACKS *********************/ | |
3995 | /* | |
3996 | * Here are the functions called by the Linux networking code (NET3) | |
3997 | * for initialization, configuration and deinstallations of the | |
3998 | * WaveLAN ISA hardware. | |
3999 | */ | |
4000 | ||
4001 | /*------------------------------------------------------------------*/ | |
4002 | /* | |
4003 | * Configure and start up the WaveLAN PCMCIA adaptor. | |
4004 | * Called by NET3 when it "opens" the device. | |
4005 | */ | |
4006 | static int wavelan_open(struct net_device * dev) | |
4007 | { | |
4008 | net_local * lp = (net_local *)dev->priv; | |
4009 | unsigned long flags; | |
4010 | ||
4011 | #ifdef DEBUG_CALLBACK_TRACE | |
4012 | printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name, | |
4013 | (unsigned int) dev); | |
4014 | #endif | |
4015 | ||
4016 | /* Check irq */ | |
4017 | if (dev->irq == 0) { | |
4018 | #ifdef DEBUG_CONFIG_ERROR | |
4019 | printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n", | |
4020 | dev->name); | |
4021 | #endif | |
4022 | return -ENXIO; | |
4023 | } | |
4024 | ||
4025 | if (request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0) | |
4026 | { | |
4027 | #ifdef DEBUG_CONFIG_ERROR | |
4028 | printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n", | |
4029 | dev->name); | |
4030 | #endif | |
4031 | return -EAGAIN; | |
4032 | } | |
4033 | ||
4034 | spin_lock_irqsave(&lp->spinlock, flags); | |
4035 | ||
4036 | if (wv_hw_reset(dev) != -1) { | |
4037 | netif_start_queue(dev); | |
4038 | } else { | |
4039 | free_irq(dev->irq, dev); | |
4040 | #ifdef DEBUG_CONFIG_ERROR | |
4041 | printk(KERN_INFO | |
4042 | "%s: wavelan_open(): impossible to start the card\n", | |
4043 | dev->name); | |
4044 | #endif | |
4045 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
4046 | return -EAGAIN; | |
4047 | } | |
4048 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
4049 | ||
4050 | #ifdef DEBUG_CALLBACK_TRACE | |
4051 | printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name); | |
4052 | #endif | |
4053 | return 0; | |
4054 | } | |
4055 | ||
4056 | /*------------------------------------------------------------------*/ | |
4057 | /* | |
4058 | * Shut down the WaveLAN ISA card. | |
4059 | * Called by NET3 when it "closes" the device. | |
4060 | */ | |
4061 | static int wavelan_close(struct net_device * dev) | |
4062 | { | |
4063 | net_local *lp = (net_local *) dev->priv; | |
4064 | unsigned long flags; | |
4065 | ||
4066 | #ifdef DEBUG_CALLBACK_TRACE | |
4067 | printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name, | |
4068 | (unsigned int) dev); | |
4069 | #endif | |
4070 | ||
4071 | netif_stop_queue(dev); | |
4072 | ||
4073 | /* | |
4074 | * Flush the Tx and disable Rx. | |
4075 | */ | |
4076 | spin_lock_irqsave(&lp->spinlock, flags); | |
4077 | wv_82586_stop(dev); | |
4078 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
4079 | ||
4080 | free_irq(dev->irq, dev); | |
4081 | ||
4082 | #ifdef DEBUG_CALLBACK_TRACE | |
4083 | printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name); | |
4084 | #endif | |
4085 | return 0; | |
4086 | } | |
4087 | ||
4088 | /*------------------------------------------------------------------*/ | |
4089 | /* | |
4090 | * Probe an I/O address, and if the WaveLAN is there configure the | |
4091 | * device structure | |
4092 | * (called by wavelan_probe() and via init_module()). | |
4093 | */ | |
4094 | static int __init wavelan_config(struct net_device *dev, unsigned short ioaddr) | |
4095 | { | |
4096 | u8 irq_mask; | |
4097 | int irq; | |
4098 | net_local *lp; | |
4099 | mac_addr mac; | |
4100 | int err; | |
4101 | ||
4102 | if (!request_region(ioaddr, sizeof(ha_t), "wavelan")) | |
4103 | return -EADDRINUSE; | |
4104 | ||
4105 | err = wv_check_ioaddr(ioaddr, mac); | |
4106 | if (err) | |
4107 | goto out; | |
4108 | ||
4109 | memcpy(dev->dev_addr, mac, 6); | |
4110 | ||
4111 | dev->base_addr = ioaddr; | |
4112 | ||
4113 | #ifdef DEBUG_CALLBACK_TRACE | |
4114 | printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%lx)\n", | |
4115 | dev->name, (unsigned int) dev, ioaddr); | |
4116 | #endif | |
4117 | ||
4118 | /* Check IRQ argument on command line. */ | |
4119 | if (dev->irq != 0) { | |
4120 | irq_mask = wv_irq_to_psa(dev->irq); | |
4121 | ||
4122 | if (irq_mask == 0) { | |
4123 | #ifdef DEBUG_CONFIG_ERROR | |
4124 | printk(KERN_WARNING | |
4125 | "%s: wavelan_config(): invalid IRQ %d ignored.\n", | |
4126 | dev->name, dev->irq); | |
4127 | #endif | |
4128 | dev->irq = 0; | |
4129 | } else { | |
4130 | #ifdef DEBUG_CONFIG_INFO | |
4131 | printk(KERN_DEBUG | |
4132 | "%s: wavelan_config(): changing IRQ to %d\n", | |
4133 | dev->name, dev->irq); | |
4134 | #endif | |
4135 | psa_write(ioaddr, HACR_DEFAULT, | |
4136 | psaoff(0, psa_int_req_no), &irq_mask, 1); | |
4137 | /* update the Wavelan checksum */ | |
4138 | update_psa_checksum(dev, ioaddr, HACR_DEFAULT); | |
4139 | wv_hacr_reset(ioaddr); | |
4140 | } | |
4141 | } | |
4142 | ||
4143 | psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no), | |
4144 | &irq_mask, 1); | |
4145 | if ((irq = wv_psa_to_irq(irq_mask)) == -1) { | |
4146 | #ifdef DEBUG_CONFIG_ERROR | |
4147 | printk(KERN_INFO | |
4148 | "%s: wavelan_config(): could not wavelan_map_irq(%d).\n", | |
4149 | dev->name, irq_mask); | |
4150 | #endif | |
4151 | err = -EAGAIN; | |
4152 | goto out; | |
4153 | } | |
4154 | ||
4155 | dev->irq = irq; | |
4156 | ||
4157 | dev->mem_start = 0x0000; | |
4158 | dev->mem_end = 0x0000; | |
4159 | dev->if_port = 0; | |
4160 | ||
4161 | /* Initialize device structures */ | |
4162 | memset(dev->priv, 0, sizeof(net_local)); | |
4163 | lp = (net_local *) dev->priv; | |
4164 | ||
4165 | /* Back link to the device structure. */ | |
4166 | lp->dev = dev; | |
4167 | /* Add the device at the beginning of the linked list. */ | |
4168 | lp->next = wavelan_list; | |
4169 | wavelan_list = lp; | |
4170 | ||
4171 | lp->hacr = HACR_DEFAULT; | |
4172 | ||
4173 | /* Multicast stuff */ | |
4174 | lp->promiscuous = 0; | |
4175 | lp->mc_count = 0; | |
4176 | ||
4177 | /* Init spinlock */ | |
4178 | spin_lock_init(&lp->spinlock); | |
4179 | ||
4180 | SET_MODULE_OWNER(dev); | |
4181 | dev->open = wavelan_open; | |
4182 | dev->stop = wavelan_close; | |
4183 | dev->hard_start_xmit = wavelan_packet_xmit; | |
4184 | dev->get_stats = wavelan_get_stats; | |
4185 | dev->set_multicast_list = &wavelan_set_multicast_list; | |
4186 | dev->tx_timeout = &wavelan_watchdog; | |
4187 | dev->watchdog_timeo = WATCHDOG_JIFFIES; | |
4188 | #ifdef SET_MAC_ADDRESS | |
4189 | dev->set_mac_address = &wavelan_set_mac_address; | |
4190 | #endif /* SET_MAC_ADDRESS */ | |
4191 | ||
1da177e4 LT |
4192 | dev->wireless_handlers = &wavelan_handler_def; |
4193 | lp->wireless_data.spy_data = &lp->spy_data; | |
4194 | dev->wireless_data = &lp->wireless_data; | |
1da177e4 LT |
4195 | |
4196 | dev->mtu = WAVELAN_MTU; | |
4197 | ||
4198 | /* Display nice information. */ | |
4199 | wv_init_info(dev); | |
4200 | ||
4201 | #ifdef DEBUG_CALLBACK_TRACE | |
4202 | printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name); | |
4203 | #endif | |
4204 | return 0; | |
4205 | out: | |
4206 | release_region(ioaddr, sizeof(ha_t)); | |
4207 | return err; | |
4208 | } | |
4209 | ||
4210 | /*------------------------------------------------------------------*/ | |
4211 | /* | |
4212 | * Check for a network adaptor of this type. Return '0' iff one | |
4213 | * exists. There seem to be different interpretations of | |
4214 | * the initial value of dev->base_addr. | |
4215 | * We follow the example in drivers/net/ne.c. | |
4216 | * (called in "Space.c") | |
4217 | */ | |
4218 | struct net_device * __init wavelan_probe(int unit) | |
4219 | { | |
4220 | struct net_device *dev; | |
4221 | short base_addr; | |
4222 | int def_irq; | |
4223 | int i; | |
4224 | int r = 0; | |
4225 | ||
4226 | #ifdef STRUCT_CHECK | |
4227 | if (wv_struct_check() != (char *) NULL) { | |
4228 | printk(KERN_WARNING | |
4229 | "%s: wavelan_probe(): structure/compiler botch: \"%s\"\n", | |
4230 | dev->name, wv_struct_check()); | |
4231 | return -ENODEV; | |
4232 | } | |
4233 | #endif /* STRUCT_CHECK */ | |
4234 | ||
4235 | dev = alloc_etherdev(sizeof(net_local)); | |
4236 | if (!dev) | |
4237 | return ERR_PTR(-ENOMEM); | |
4238 | ||
4239 | sprintf(dev->name, "eth%d", unit); | |
4240 | netdev_boot_setup_check(dev); | |
4241 | base_addr = dev->base_addr; | |
4242 | def_irq = dev->irq; | |
4243 | ||
4244 | #ifdef DEBUG_CALLBACK_TRACE | |
4245 | printk(KERN_DEBUG | |
4246 | "%s: ->wavelan_probe(dev=%p (base_addr=0x%x))\n", | |
4247 | dev->name, dev, (unsigned int) dev->base_addr); | |
4248 | #endif | |
4249 | ||
4250 | /* Don't probe at all. */ | |
4251 | if (base_addr < 0) { | |
4252 | #ifdef DEBUG_CONFIG_ERROR | |
4253 | printk(KERN_WARNING | |
4254 | "%s: wavelan_probe(): invalid base address\n", | |
4255 | dev->name); | |
4256 | #endif | |
4257 | r = -ENXIO; | |
4258 | } else if (base_addr > 0x100) { /* Check a single specified location. */ | |
4259 | r = wavelan_config(dev, base_addr); | |
4260 | #ifdef DEBUG_CONFIG_INFO | |
4261 | if (r != 0) | |
4262 | printk(KERN_DEBUG | |
4263 | "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n", | |
4264 | dev->name, base_addr); | |
4265 | #endif | |
4266 | ||
4267 | #ifdef DEBUG_CALLBACK_TRACE | |
4268 | printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name); | |
4269 | #endif | |
4270 | } else { /* Scan all possible addresses of the WaveLAN hardware. */ | |
0a92dd0a | 4271 | for (i = 0; i < ARRAY_SIZE(iobase); i++) { |
1da177e4 LT |
4272 | dev->irq = def_irq; |
4273 | if (wavelan_config(dev, iobase[i]) == 0) { | |
4274 | #ifdef DEBUG_CALLBACK_TRACE | |
4275 | printk(KERN_DEBUG | |
4276 | "%s: <-wavelan_probe()\n", | |
4277 | dev->name); | |
4278 | #endif | |
4279 | break; | |
4280 | } | |
4281 | } | |
0a92dd0a | 4282 | if (i == ARRAY_SIZE(iobase)) |
1da177e4 LT |
4283 | r = -ENODEV; |
4284 | } | |
4285 | if (r) | |
4286 | goto out; | |
4287 | r = register_netdev(dev); | |
4288 | if (r) | |
4289 | goto out1; | |
4290 | return dev; | |
4291 | out1: | |
4292 | release_region(dev->base_addr, sizeof(ha_t)); | |
4293 | wavelan_list = wavelan_list->next; | |
4294 | out: | |
4295 | free_netdev(dev); | |
4296 | return ERR_PTR(r); | |
4297 | } | |
4298 | ||
4299 | /****************************** MODULE ******************************/ | |
4300 | /* | |
4301 | * Module entry point: insertion and removal | |
4302 | */ | |
4303 | ||
4304 | #ifdef MODULE | |
4305 | /*------------------------------------------------------------------*/ | |
4306 | /* | |
4307 | * Insertion of the module | |
4308 | * I'm now quite proud of the multi-device support. | |
4309 | */ | |
53072d68 | 4310 | int __init init_module(void) |
1da177e4 LT |
4311 | { |
4312 | int ret = -EIO; /* Return error if no cards found */ | |
4313 | int i; | |
4314 | ||
4315 | #ifdef DEBUG_MODULE_TRACE | |
4316 | printk(KERN_DEBUG "-> init_module()\n"); | |
4317 | #endif | |
4318 | ||
4319 | /* If probing is asked */ | |
4320 | if (io[0] == 0) { | |
4321 | #ifdef DEBUG_CONFIG_ERROR | |
4322 | printk(KERN_WARNING | |
4323 | "WaveLAN init_module(): doing device probing (bad !)\n"); | |
4324 | printk(KERN_WARNING | |
4325 | "Specify base addresses while loading module to correct the problem\n"); | |
4326 | #endif | |
4327 | ||
4328 | /* Copy the basic set of address to be probed. */ | |
0a92dd0a | 4329 | for (i = 0; i < ARRAY_SIZE(iobase); i++) |
1da177e4 LT |
4330 | io[i] = iobase[i]; |
4331 | } | |
4332 | ||
4333 | ||
4334 | /* Loop on all possible base addresses. */ | |
4335 | i = -1; | |
0a92dd0a | 4336 | while ((io[++i] != 0) && (i < ARRAY_SIZE(io))) { |
1da177e4 LT |
4337 | struct net_device *dev = alloc_etherdev(sizeof(net_local)); |
4338 | if (!dev) | |
4339 | break; | |
4340 | if (name[i]) | |
4341 | strcpy(dev->name, name[i]); /* Copy name */ | |
4342 | dev->base_addr = io[i]; | |
4343 | dev->irq = irq[i]; | |
4344 | ||
4345 | /* Check if there is something at this base address. */ | |
4346 | if (wavelan_config(dev, io[i]) == 0) { | |
4347 | if (register_netdev(dev) != 0) { | |
4348 | release_region(dev->base_addr, sizeof(ha_t)); | |
4349 | wavelan_list = wavelan_list->next; | |
4350 | } else { | |
4351 | ret = 0; | |
4352 | continue; | |
4353 | } | |
4354 | } | |
4355 | free_netdev(dev); | |
4356 | } | |
4357 | ||
4358 | #ifdef DEBUG_CONFIG_ERROR | |
4359 | if (!wavelan_list) | |
4360 | printk(KERN_WARNING | |
4361 | "WaveLAN init_module(): no device found\n"); | |
4362 | #endif | |
4363 | ||
4364 | #ifdef DEBUG_MODULE_TRACE | |
4365 | printk(KERN_DEBUG "<- init_module()\n"); | |
4366 | #endif | |
4367 | return ret; | |
4368 | } | |
4369 | ||
4370 | /*------------------------------------------------------------------*/ | |
4371 | /* | |
4372 | * Removal of the module | |
4373 | */ | |
4374 | void cleanup_module(void) | |
4375 | { | |
4376 | #ifdef DEBUG_MODULE_TRACE | |
4377 | printk(KERN_DEBUG "-> cleanup_module()\n"); | |
4378 | #endif | |
4379 | ||
4380 | /* Loop on all devices and release them. */ | |
4381 | while (wavelan_list) { | |
4382 | struct net_device *dev = wavelan_list->dev; | |
4383 | ||
4384 | #ifdef DEBUG_CONFIG_INFO | |
4385 | printk(KERN_DEBUG | |
4386 | "%s: cleanup_module(): removing device at 0x%x\n", | |
4387 | dev->name, (unsigned int) dev); | |
4388 | #endif | |
4389 | unregister_netdev(dev); | |
4390 | ||
4391 | release_region(dev->base_addr, sizeof(ha_t)); | |
4392 | wavelan_list = wavelan_list->next; | |
4393 | ||
4394 | free_netdev(dev); | |
4395 | } | |
4396 | ||
4397 | #ifdef DEBUG_MODULE_TRACE | |
4398 | printk(KERN_DEBUG "<- cleanup_module()\n"); | |
4399 | #endif | |
4400 | } | |
4401 | #endif /* MODULE */ | |
4402 | MODULE_LICENSE("GPL"); | |
4403 | ||
4404 | /* | |
4405 | * This software may only be used and distributed | |
4406 | * according to the terms of the GNU General Public License. | |
4407 | * | |
4408 | * This software was developed as a component of the | |
4409 | * Linux operating system. | |
4410 | * It is based on other device drivers and information | |
4411 | * either written or supplied by: | |
4412 | * Ajay Bakre (bakre@paul.rutgers.edu), | |
4413 | * Donald Becker (becker@scyld.com), | |
4414 | * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com), | |
4415 | * Anders Klemets (klemets@it.kth.se), | |
4416 | * Vladimir V. Kolpakov (w@stier.koenig.ru), | |
4417 | * Marc Meertens (Marc.Meertens@Utrecht.NCR.com), | |
4418 | * Pauline Middelink (middelin@polyware.iaf.nl), | |
4419 | * Robert Morris (rtm@das.harvard.edu), | |
4420 | * Jean Tourrilhes (jt@hplb.hpl.hp.com), | |
4421 | * Girish Welling (welling@paul.rutgers.edu), | |
4422 | * | |
4423 | * Thanks go also to: | |
4424 | * James Ashton (jaa101@syseng.anu.edu.au), | |
4425 | * Alan Cox (alan@redhat.com), | |
4426 | * Allan Creighton (allanc@cs.usyd.edu.au), | |
4427 | * Matthew Geier (matthew@cs.usyd.edu.au), | |
4428 | * Remo di Giovanni (remo@cs.usyd.edu.au), | |
4429 | * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de), | |
4430 | * Vipul Gupta (vgupta@cs.binghamton.edu), | |
4431 | * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM), | |
4432 | * Tim Nicholson (tim@cs.usyd.edu.au), | |
4433 | * Ian Parkin (ian@cs.usyd.edu.au), | |
4434 | * John Rosenberg (johnr@cs.usyd.edu.au), | |
4435 | * George Rossi (george@phm.gov.au), | |
4436 | * Arthur Scott (arthur@cs.usyd.edu.au), | |
4437 | * Peter Storey, | |
4438 | * for their assistance and advice. | |
4439 | * | |
4440 | * Please send bug reports, updates, comments to: | |
4441 | * | |
4442 | * Bruce Janson Email: bruce@cs.usyd.edu.au | |
4443 | * Basser Department of Computer Science Phone: +61-2-9351-3423 | |
4444 | * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838 | |
4445 | */ |