Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Wavelan Pcmcia driver | |
3 | * | |
4 | * Jean II - HPLB '96 | |
5 | * | |
6 | * Reorganisation and extension of the driver. | |
7 | * Original copyright follow. See wavelan_cs.p.h for details. | |
8 | * | |
9 | * This code is derived from Anthony D. Joseph's code and all the changes here | |
10 | * are also under the original copyright below. | |
11 | * | |
12 | * This code supports version 2.00 of WaveLAN/PCMCIA cards (2.4GHz), and | |
13 | * can work on Linux 2.0.36 with support of David Hinds' PCMCIA Card Services | |
14 | * | |
15 | * Joe Finney (joe@comp.lancs.ac.uk) at Lancaster University in UK added | |
16 | * critical code in the routine to initialize the Modem Management Controller. | |
17 | * | |
18 | * Thanks to Alan Cox and Bruce Janson for their advice. | |
19 | * | |
20 | * -- Yunzhou Li (scip4166@nus.sg) | |
21 | * | |
22 | #ifdef WAVELAN_ROAMING | |
23 | * Roaming support added 07/22/98 by Justin Seger (jseger@media.mit.edu) | |
24 | * based on patch by Joe Finney from Lancaster University. | |
25 | #endif | |
26 | * | |
27 | * Lucent (formerly AT&T GIS, formerly NCR) WaveLAN PCMCIA card: An | |
28 | * Ethernet-like radio transceiver controlled by an Intel 82593 coprocessor. | |
29 | * | |
30 | * A non-shared memory PCMCIA ethernet driver for linux | |
31 | * | |
32 | * ISA version modified to support PCMCIA by Anthony Joseph (adj@lcs.mit.edu) | |
33 | * | |
34 | * | |
35 | * Joseph O'Sullivan & John Langford (josullvn@cs.cmu.edu & jcl@cs.cmu.edu) | |
36 | * | |
37 | * Apr 2 '98 made changes to bring the i82593 control/int handling in line | |
38 | * with offical specs... | |
39 | * | |
40 | **************************************************************************** | |
41 | * Copyright 1995 | |
42 | * Anthony D. Joseph | |
43 | * Massachusetts Institute of Technology | |
44 | * | |
45 | * Permission to use, copy, modify, and distribute this program | |
46 | * for any purpose and without fee is hereby granted, provided | |
47 | * that this copyright and permission notice appear on all copies | |
48 | * and supporting documentation, the name of M.I.T. not be used | |
49 | * in advertising or publicity pertaining to distribution of the | |
50 | * program without specific prior permission, and notice be given | |
51 | * in supporting documentation that copying and distribution is | |
52 | * by permission of M.I.T. M.I.T. makes no representations about | |
53 | * the suitability of this software for any purpose. It is pro- | |
54 | * vided "as is" without express or implied warranty. | |
55 | **************************************************************************** | |
56 | * | |
57 | */ | |
58 | ||
59 | /* Do *NOT* add other headers here, you are guaranteed to be wrong - Jean II */ | |
60 | #include "wavelan_cs.p.h" /* Private header */ | |
61 | ||
62 | /************************* MISC SUBROUTINES **************************/ | |
63 | /* | |
64 | * Subroutines which won't fit in one of the following category | |
65 | * (wavelan modem or i82593) | |
66 | */ | |
67 | ||
68 | #ifdef STRUCT_CHECK | |
69 | /*------------------------------------------------------------------*/ | |
70 | /* | |
71 | * Sanity routine to verify the sizes of the various WaveLAN interface | |
72 | * structures. | |
73 | */ | |
74 | static char * | |
75 | wv_structuct_check(void) | |
76 | { | |
77 | #define SC(t,s,n) if (sizeof(t) != s) return(n); | |
78 | ||
79 | SC(psa_t, PSA_SIZE, "psa_t"); | |
80 | SC(mmw_t, MMW_SIZE, "mmw_t"); | |
81 | SC(mmr_t, MMR_SIZE, "mmr_t"); | |
82 | ||
83 | #undef SC | |
84 | ||
85 | return((char *) NULL); | |
86 | } /* wv_structuct_check */ | |
87 | #endif /* STRUCT_CHECK */ | |
88 | ||
89 | /******************* MODEM MANAGEMENT SUBROUTINES *******************/ | |
90 | /* | |
91 | * Useful subroutines to manage the modem of the wavelan | |
92 | */ | |
93 | ||
94 | /*------------------------------------------------------------------*/ | |
95 | /* | |
96 | * Read from card's Host Adaptor Status Register. | |
97 | */ | |
98 | static inline u_char | |
99 | hasr_read(u_long base) | |
100 | { | |
101 | return(inb(HASR(base))); | |
102 | } /* hasr_read */ | |
103 | ||
104 | /*------------------------------------------------------------------*/ | |
105 | /* | |
106 | * Write to card's Host Adapter Command Register. | |
107 | */ | |
108 | static inline void | |
109 | hacr_write(u_long base, | |
110 | u_char hacr) | |
111 | { | |
112 | outb(hacr, HACR(base)); | |
113 | } /* hacr_write */ | |
114 | ||
115 | /*------------------------------------------------------------------*/ | |
116 | /* | |
117 | * Write to card's Host Adapter Command Register. Include a delay for | |
118 | * those times when it is needed. | |
119 | */ | |
120 | static inline void | |
121 | hacr_write_slow(u_long base, | |
122 | u_char hacr) | |
123 | { | |
124 | hacr_write(base, hacr); | |
125 | /* delay might only be needed sometimes */ | |
126 | mdelay(1); | |
127 | } /* hacr_write_slow */ | |
128 | ||
129 | /*------------------------------------------------------------------*/ | |
130 | /* | |
131 | * Read the Parameter Storage Area from the WaveLAN card's memory | |
132 | */ | |
133 | static void | |
134 | psa_read(struct net_device * dev, | |
135 | int o, /* offset in PSA */ | |
136 | u_char * b, /* buffer to fill */ | |
137 | int n) /* size to read */ | |
138 | { | |
139 | net_local *lp = netdev_priv(dev); | |
140 | u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1); | |
141 | ||
142 | while(n-- > 0) | |
143 | { | |
144 | *b++ = readb(ptr); | |
145 | /* Due to a lack of address decode pins, the WaveLAN PCMCIA card | |
146 | * only supports reading even memory addresses. That means the | |
147 | * increment here MUST be two. | |
148 | * Because of that, we can't use memcpy_fromio()... | |
149 | */ | |
150 | ptr += 2; | |
151 | } | |
152 | } /* psa_read */ | |
153 | ||
154 | /*------------------------------------------------------------------*/ | |
155 | /* | |
156 | * Write the Paramter Storage Area to the WaveLAN card's memory | |
157 | */ | |
158 | static void | |
159 | psa_write(struct net_device * dev, | |
160 | int o, /* Offset in psa */ | |
161 | u_char * b, /* Buffer in memory */ | |
162 | int n) /* Length of buffer */ | |
163 | { | |
164 | net_local *lp = netdev_priv(dev); | |
165 | u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1); | |
166 | int count = 0; | |
167 | kio_addr_t base = dev->base_addr; | |
168 | /* As there seem to have no flag PSA_BUSY as in the ISA model, we are | |
169 | * oblige to verify this address to know when the PSA is ready... */ | |
170 | volatile u_char __iomem *verify = lp->mem + PSA_ADDR + | |
171 | (psaoff(0, psa_comp_number) << 1); | |
172 | ||
173 | /* Authorize writting to PSA */ | |
174 | hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN); | |
175 | ||
176 | while(n-- > 0) | |
177 | { | |
178 | /* write to PSA */ | |
179 | writeb(*b++, ptr); | |
180 | ptr += 2; | |
181 | ||
182 | /* I don't have the spec, so I don't know what the correct | |
183 | * sequence to write is. This hack seem to work for me... */ | |
184 | count = 0; | |
185 | while((readb(verify) != PSA_COMP_PCMCIA_915) && (count++ < 100)) | |
186 | mdelay(1); | |
187 | } | |
188 | ||
189 | /* Put the host interface back in standard state */ | |
190 | hacr_write(base, HACR_DEFAULT); | |
191 | } /* psa_write */ | |
192 | ||
193 | #ifdef SET_PSA_CRC | |
194 | /*------------------------------------------------------------------*/ | |
195 | /* | |
196 | * Calculate the PSA CRC | |
197 | * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code | |
198 | * NOTE: By specifying a length including the CRC position the | |
199 | * returned value should be zero. (i.e. a correct checksum in the PSA) | |
200 | * | |
201 | * The Windows drivers don't use the CRC, but the AP and the PtP tool | |
202 | * depend on it. | |
203 | */ | |
204 | static u_short | |
205 | psa_crc(unsigned char * psa, /* The PSA */ | |
206 | int size) /* Number of short for CRC */ | |
207 | { | |
208 | int byte_cnt; /* Loop on the PSA */ | |
209 | u_short crc_bytes = 0; /* Data in the PSA */ | |
210 | int bit_cnt; /* Loop on the bits of the short */ | |
211 | ||
212 | for(byte_cnt = 0; byte_cnt < size; byte_cnt++ ) | |
213 | { | |
214 | crc_bytes ^= psa[byte_cnt]; /* Its an xor */ | |
215 | ||
216 | for(bit_cnt = 1; bit_cnt < 9; bit_cnt++ ) | |
217 | { | |
218 | if(crc_bytes & 0x0001) | |
219 | crc_bytes = (crc_bytes >> 1) ^ 0xA001; | |
220 | else | |
221 | crc_bytes >>= 1 ; | |
222 | } | |
223 | } | |
224 | ||
225 | return crc_bytes; | |
226 | } /* psa_crc */ | |
227 | #endif /* SET_PSA_CRC */ | |
228 | ||
229 | /*------------------------------------------------------------------*/ | |
230 | /* | |
231 | * update the checksum field in the Wavelan's PSA | |
232 | */ | |
233 | static void | |
234 | update_psa_checksum(struct net_device * dev) | |
235 | { | |
236 | #ifdef SET_PSA_CRC | |
237 | psa_t psa; | |
238 | u_short crc; | |
239 | ||
240 | /* read the parameter storage area */ | |
241 | psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa)); | |
242 | ||
243 | /* update the checksum */ | |
244 | crc = psa_crc((unsigned char *) &psa, | |
245 | sizeof(psa) - sizeof(psa.psa_crc[0]) - sizeof(psa.psa_crc[1]) | |
246 | - sizeof(psa.psa_crc_status)); | |
247 | ||
248 | psa.psa_crc[0] = crc & 0xFF; | |
249 | psa.psa_crc[1] = (crc & 0xFF00) >> 8; | |
250 | ||
251 | /* Write it ! */ | |
252 | psa_write(dev, (char *)&psa.psa_crc - (char *)&psa, | |
253 | (unsigned char *)&psa.psa_crc, 2); | |
254 | ||
255 | #ifdef DEBUG_IOCTL_INFO | |
256 | printk (KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n", | |
257 | dev->name, psa.psa_crc[0], psa.psa_crc[1]); | |
258 | ||
259 | /* Check again (luxury !) */ | |
260 | crc = psa_crc((unsigned char *) &psa, | |
261 | sizeof(psa) - sizeof(psa.psa_crc_status)); | |
262 | ||
263 | if(crc != 0) | |
264 | printk(KERN_WARNING "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", dev->name); | |
265 | #endif /* DEBUG_IOCTL_INFO */ | |
266 | #endif /* SET_PSA_CRC */ | |
267 | } /* update_psa_checksum */ | |
268 | ||
269 | /*------------------------------------------------------------------*/ | |
270 | /* | |
271 | * Write 1 byte to the MMC. | |
272 | */ | |
273 | static inline void | |
274 | mmc_out(u_long base, | |
275 | u_short o, | |
276 | u_char d) | |
277 | { | |
278 | int count = 0; | |
279 | ||
280 | /* Wait for MMC to go idle */ | |
281 | while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY)) | |
282 | udelay(10); | |
283 | ||
284 | outb((u_char)((o << 1) | MMR_MMI_WR), MMR(base)); | |
285 | outb(d, MMD(base)); | |
286 | } | |
287 | ||
288 | /*------------------------------------------------------------------*/ | |
289 | /* | |
290 | * Routine to write bytes to the Modem Management Controller. | |
291 | * We start by the end because it is the way it should be ! | |
292 | */ | |
293 | static inline void | |
294 | mmc_write(u_long base, | |
295 | u_char o, | |
296 | u_char * b, | |
297 | int n) | |
298 | { | |
299 | o += n; | |
300 | b += n; | |
301 | ||
302 | while(n-- > 0 ) | |
303 | mmc_out(base, --o, *(--b)); | |
304 | } /* mmc_write */ | |
305 | ||
306 | /*------------------------------------------------------------------*/ | |
307 | /* | |
308 | * Read 1 byte from the MMC. | |
309 | * Optimised version for 1 byte, avoid using memory... | |
310 | */ | |
311 | static inline u_char | |
312 | mmc_in(u_long base, | |
313 | u_short o) | |
314 | { | |
315 | int count = 0; | |
316 | ||
317 | while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY)) | |
318 | udelay(10); | |
319 | outb(o << 1, MMR(base)); /* Set the read address */ | |
320 | ||
321 | outb(0, MMD(base)); /* Required dummy write */ | |
322 | ||
323 | while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY)) | |
324 | udelay(10); | |
325 | return (u_char) (inb(MMD(base))); /* Now do the actual read */ | |
326 | } | |
327 | ||
328 | /*------------------------------------------------------------------*/ | |
329 | /* | |
330 | * Routine to read bytes from the Modem Management Controller. | |
331 | * The implementation is complicated by a lack of address lines, | |
332 | * which prevents decoding of the low-order bit. | |
333 | * (code has just been moved in the above function) | |
334 | * We start by the end because it is the way it should be ! | |
335 | */ | |
336 | static inline void | |
337 | mmc_read(u_long base, | |
338 | u_char o, | |
339 | u_char * b, | |
340 | int n) | |
341 | { | |
342 | o += n; | |
343 | b += n; | |
344 | ||
345 | while(n-- > 0) | |
346 | *(--b) = mmc_in(base, --o); | |
347 | } /* mmc_read */ | |
348 | ||
349 | /*------------------------------------------------------------------*/ | |
350 | /* | |
351 | * Get the type of encryption available... | |
352 | */ | |
353 | static inline int | |
354 | mmc_encr(u_long base) /* i/o port of the card */ | |
355 | { | |
356 | int temp; | |
357 | ||
358 | temp = mmc_in(base, mmroff(0, mmr_des_avail)); | |
359 | if((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES)) | |
360 | return 0; | |
361 | else | |
362 | return temp; | |
363 | } | |
364 | ||
365 | /*------------------------------------------------------------------*/ | |
366 | /* | |
367 | * Wait for the frequency EEprom to complete a command... | |
368 | * I hope this one will be optimally inlined... | |
369 | */ | |
370 | static inline void | |
371 | fee_wait(u_long base, /* i/o port of the card */ | |
372 | int delay, /* Base delay to wait for */ | |
373 | int number) /* Number of time to wait */ | |
374 | { | |
375 | int count = 0; /* Wait only a limited time */ | |
376 | ||
377 | while((count++ < number) && | |
378 | (mmc_in(base, mmroff(0, mmr_fee_status)) & MMR_FEE_STATUS_BUSY)) | |
379 | udelay(delay); | |
380 | } | |
381 | ||
382 | /*------------------------------------------------------------------*/ | |
383 | /* | |
384 | * Read bytes from the Frequency EEprom (frequency select cards). | |
385 | */ | |
386 | static void | |
387 | fee_read(u_long base, /* i/o port of the card */ | |
388 | u_short o, /* destination offset */ | |
389 | u_short * b, /* data buffer */ | |
390 | int n) /* number of registers */ | |
391 | { | |
392 | b += n; /* Position at the end of the area */ | |
393 | ||
394 | /* Write the address */ | |
395 | mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1); | |
396 | ||
397 | /* Loop on all buffer */ | |
398 | while(n-- > 0) | |
399 | { | |
400 | /* Write the read command */ | |
401 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_READ); | |
402 | ||
403 | /* Wait until EEprom is ready (should be quick !) */ | |
404 | fee_wait(base, 10, 100); | |
405 | ||
406 | /* Read the value */ | |
407 | *--b = ((mmc_in(base, mmroff(0, mmr_fee_data_h)) << 8) | | |
408 | mmc_in(base, mmroff(0, mmr_fee_data_l))); | |
409 | } | |
410 | } | |
411 | ||
412 | #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */ | |
413 | ||
414 | /*------------------------------------------------------------------*/ | |
415 | /* | |
416 | * Write bytes from the Frequency EEprom (frequency select cards). | |
417 | * This is a bit complicated, because the frequency eeprom has to | |
418 | * be unprotected and the write enabled. | |
419 | * Jean II | |
420 | */ | |
421 | static void | |
422 | fee_write(u_long base, /* i/o port of the card */ | |
423 | u_short o, /* destination offset */ | |
424 | u_short * b, /* data buffer */ | |
425 | int n) /* number of registers */ | |
426 | { | |
427 | b += n; /* Position at the end of the area */ | |
428 | ||
429 | #ifdef EEPROM_IS_PROTECTED /* disabled */ | |
430 | #ifdef DOESNT_SEEM_TO_WORK /* disabled */ | |
431 | /* Ask to read the protected register */ | |
432 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD); | |
433 | ||
434 | fee_wait(base, 10, 100); | |
435 | ||
436 | /* Read the protected register */ | |
437 | printk("Protected 2 : %02X-%02X\n", | |
438 | mmc_in(base, mmroff(0, mmr_fee_data_h)), | |
439 | mmc_in(base, mmroff(0, mmr_fee_data_l))); | |
440 | #endif /* DOESNT_SEEM_TO_WORK */ | |
441 | ||
442 | /* Enable protected register */ | |
443 | mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN); | |
444 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN); | |
445 | ||
446 | fee_wait(base, 10, 100); | |
447 | ||
448 | /* Unprotect area */ | |
449 | mmc_out(base, mmwoff(0, mmw_fee_addr), o + n); | |
450 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE); | |
451 | #ifdef DOESNT_SEEM_TO_WORK /* disabled */ | |
452 | /* Or use : */ | |
453 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR); | |
454 | #endif /* DOESNT_SEEM_TO_WORK */ | |
455 | ||
456 | fee_wait(base, 10, 100); | |
457 | #endif /* EEPROM_IS_PROTECTED */ | |
458 | ||
459 | /* Write enable */ | |
460 | mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN); | |
461 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN); | |
462 | ||
463 | fee_wait(base, 10, 100); | |
464 | ||
465 | /* Write the EEprom address */ | |
466 | mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1); | |
467 | ||
468 | /* Loop on all buffer */ | |
469 | while(n-- > 0) | |
470 | { | |
471 | /* Write the value */ | |
472 | mmc_out(base, mmwoff(0, mmw_fee_data_h), (*--b) >> 8); | |
473 | mmc_out(base, mmwoff(0, mmw_fee_data_l), *b & 0xFF); | |
474 | ||
475 | /* Write the write command */ | |
476 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WRITE); | |
477 | ||
478 | /* Wavelan doc says : wait at least 10 ms for EEBUSY = 0 */ | |
479 | mdelay(10); | |
480 | fee_wait(base, 10, 100); | |
481 | } | |
482 | ||
483 | /* Write disable */ | |
484 | mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS); | |
485 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS); | |
486 | ||
487 | fee_wait(base, 10, 100); | |
488 | ||
489 | #ifdef EEPROM_IS_PROTECTED /* disabled */ | |
490 | /* Reprotect EEprom */ | |
491 | mmc_out(base, mmwoff(0, mmw_fee_addr), 0x00); | |
492 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE); | |
493 | ||
494 | fee_wait(base, 10, 100); | |
495 | #endif /* EEPROM_IS_PROTECTED */ | |
496 | } | |
497 | #endif /* WIRELESS_EXT */ | |
498 | ||
499 | /******************* WaveLAN Roaming routines... ********************/ | |
500 | ||
501 | #ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */ | |
502 | ||
503 | unsigned char WAVELAN_BEACON_ADDRESS[]= {0x09,0x00,0x0e,0x20,0x03,0x00}; | |
504 | ||
505 | void wv_roam_init(struct net_device *dev) | |
506 | { | |
507 | net_local *lp= netdev_priv(dev); | |
508 | ||
509 | /* Do not remove this unless you have a good reason */ | |
510 | printk(KERN_NOTICE "%s: Warning, you have enabled roaming on" | |
511 | " device %s !\n", dev->name, dev->name); | |
512 | printk(KERN_NOTICE "Roaming is currently an experimental unsupported feature" | |
513 | " of the Wavelan driver.\n"); | |
514 | printk(KERN_NOTICE "It may work, but may also make the driver behave in" | |
515 | " erratic ways or crash.\n"); | |
516 | ||
517 | lp->wavepoint_table.head=NULL; /* Initialise WavePoint table */ | |
518 | lp->wavepoint_table.num_wavepoints=0; | |
519 | lp->wavepoint_table.locked=0; | |
520 | lp->curr_point=NULL; /* No default WavePoint */ | |
521 | lp->cell_search=0; | |
522 | ||
523 | lp->cell_timer.data=(long)lp; /* Start cell expiry timer */ | |
524 | lp->cell_timer.function=wl_cell_expiry; | |
525 | lp->cell_timer.expires=jiffies+CELL_TIMEOUT; | |
526 | add_timer(&lp->cell_timer); | |
527 | ||
528 | wv_nwid_filter(NWID_PROMISC,lp) ; /* Enter NWID promiscuous mode */ | |
529 | /* to build up a good WavePoint */ | |
530 | /* table... */ | |
531 | printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name); | |
532 | } | |
533 | ||
534 | void wv_roam_cleanup(struct net_device *dev) | |
535 | { | |
536 | wavepoint_history *ptr,*old_ptr; | |
537 | net_local *lp= netdev_priv(dev); | |
538 | ||
539 | printk(KERN_DEBUG "WaveLAN: Roaming Disabled on device %s\n",dev->name); | |
540 | ||
541 | /* Fixme : maybe we should check that the timer exist before deleting it */ | |
542 | del_timer(&lp->cell_timer); /* Remove cell expiry timer */ | |
543 | ptr=lp->wavepoint_table.head; /* Clear device's WavePoint table */ | |
544 | while(ptr!=NULL) | |
545 | { | |
546 | old_ptr=ptr; | |
547 | ptr=ptr->next; | |
548 | wl_del_wavepoint(old_ptr,lp); | |
549 | } | |
550 | } | |
551 | ||
552 | /* Enable/Disable NWID promiscuous mode on a given device */ | |
553 | void wv_nwid_filter(unsigned char mode, net_local *lp) | |
554 | { | |
555 | mm_t m; | |
556 | unsigned long flags; | |
557 | ||
558 | #ifdef WAVELAN_ROAMING_DEBUG | |
559 | printk(KERN_DEBUG "WaveLAN: NWID promisc %s, device %s\n",(mode==NWID_PROMISC) ? "on" : "off", lp->dev->name); | |
560 | #endif | |
561 | ||
562 | /* Disable interrupts & save flags */ | |
563 | spin_lock_irqsave(&lp->spinlock, flags); | |
564 | ||
565 | m.w.mmw_loopt_sel = (mode==NWID_PROMISC) ? MMW_LOOPT_SEL_DIS_NWID : 0x00; | |
566 | mmc_write(lp->dev->base_addr, (char *)&m.w.mmw_loopt_sel - (char *)&m, (unsigned char *)&m.w.mmw_loopt_sel, 1); | |
567 | ||
568 | if(mode==NWID_PROMISC) | |
569 | lp->cell_search=1; | |
570 | else | |
571 | lp->cell_search=0; | |
572 | ||
573 | /* ReEnable interrupts & restore flags */ | |
574 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
575 | } | |
576 | ||
577 | /* Find a record in the WavePoint table matching a given NWID */ | |
578 | wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp) | |
579 | { | |
580 | wavepoint_history *ptr=lp->wavepoint_table.head; | |
581 | ||
582 | while(ptr!=NULL){ | |
583 | if(ptr->nwid==nwid) | |
584 | return ptr; | |
585 | ptr=ptr->next; | |
586 | } | |
587 | return NULL; | |
588 | } | |
589 | ||
590 | /* Create a new wavepoint table entry */ | |
591 | wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp) | |
592 | { | |
593 | wavepoint_history *new_wavepoint; | |
594 | ||
595 | #ifdef WAVELAN_ROAMING_DEBUG | |
596 | printk(KERN_DEBUG "WaveLAN: New Wavepoint, NWID:%.4X\n",nwid); | |
597 | #endif | |
598 | ||
599 | if(lp->wavepoint_table.num_wavepoints==MAX_WAVEPOINTS) | |
600 | return NULL; | |
601 | ||
602 | new_wavepoint=(wavepoint_history *) kmalloc(sizeof(wavepoint_history),GFP_ATOMIC); | |
603 | if(new_wavepoint==NULL) | |
604 | return NULL; | |
605 | ||
606 | new_wavepoint->nwid=nwid; /* New WavePoints NWID */ | |
607 | new_wavepoint->average_fast=0; /* Running Averages..*/ | |
608 | new_wavepoint->average_slow=0; | |
609 | new_wavepoint->qualptr=0; /* Start of ringbuffer */ | |
610 | new_wavepoint->last_seq=seq-1; /* Last sequence no.seen */ | |
611 | memset(new_wavepoint->sigqual,0,WAVEPOINT_HISTORY);/* Empty ringbuffer */ | |
612 | ||
613 | new_wavepoint->next=lp->wavepoint_table.head;/* Add to wavepoint table */ | |
614 | new_wavepoint->prev=NULL; | |
615 | ||
616 | if(lp->wavepoint_table.head!=NULL) | |
617 | lp->wavepoint_table.head->prev=new_wavepoint; | |
618 | ||
619 | lp->wavepoint_table.head=new_wavepoint; | |
620 | ||
621 | lp->wavepoint_table.num_wavepoints++; /* no. of visible wavepoints */ | |
622 | ||
623 | return new_wavepoint; | |
624 | } | |
625 | ||
626 | /* Remove a wavepoint entry from WavePoint table */ | |
627 | void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp) | |
628 | { | |
629 | if(wavepoint==NULL) | |
630 | return; | |
631 | ||
632 | if(lp->curr_point==wavepoint) | |
633 | lp->curr_point=NULL; | |
634 | ||
635 | if(wavepoint->prev!=NULL) | |
636 | wavepoint->prev->next=wavepoint->next; | |
637 | ||
638 | if(wavepoint->next!=NULL) | |
639 | wavepoint->next->prev=wavepoint->prev; | |
640 | ||
641 | if(lp->wavepoint_table.head==wavepoint) | |
642 | lp->wavepoint_table.head=wavepoint->next; | |
643 | ||
644 | lp->wavepoint_table.num_wavepoints--; | |
645 | kfree(wavepoint); | |
646 | } | |
647 | ||
648 | /* Timer callback function - checks WavePoint table for stale entries */ | |
649 | void wl_cell_expiry(unsigned long data) | |
650 | { | |
651 | net_local *lp=(net_local *)data; | |
652 | wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point; | |
653 | ||
654 | #if WAVELAN_ROAMING_DEBUG > 1 | |
655 | printk(KERN_DEBUG "WaveLAN: Wavepoint timeout, dev %s\n",lp->dev->name); | |
656 | #endif | |
657 | ||
658 | if(lp->wavepoint_table.locked) | |
659 | { | |
660 | #if WAVELAN_ROAMING_DEBUG > 1 | |
661 | printk(KERN_DEBUG "WaveLAN: Wavepoint table locked...\n"); | |
662 | #endif | |
663 | ||
664 | lp->cell_timer.expires=jiffies+1; /* If table in use, come back later */ | |
665 | add_timer(&lp->cell_timer); | |
666 | return; | |
667 | } | |
668 | ||
669 | while(wavepoint!=NULL) | |
670 | { | |
671 | if(time_after(jiffies, wavepoint->last_seen + CELL_TIMEOUT)) | |
672 | { | |
673 | #ifdef WAVELAN_ROAMING_DEBUG | |
674 | printk(KERN_DEBUG "WaveLAN: Bye bye %.4X\n",wavepoint->nwid); | |
675 | #endif | |
676 | ||
677 | old_point=wavepoint; | |
678 | wavepoint=wavepoint->next; | |
679 | wl_del_wavepoint(old_point,lp); | |
680 | } | |
681 | else | |
682 | wavepoint=wavepoint->next; | |
683 | } | |
684 | lp->cell_timer.expires=jiffies+CELL_TIMEOUT; | |
685 | add_timer(&lp->cell_timer); | |
686 | } | |
687 | ||
688 | /* Update SNR history of a wavepoint */ | |
689 | void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq) | |
690 | { | |
691 | int i=0,num_missed=0,ptr=0; | |
692 | int average_fast=0,average_slow=0; | |
693 | ||
694 | num_missed=(seq-wavepoint->last_seq)%WAVEPOINT_HISTORY;/* Have we missed | |
695 | any beacons? */ | |
696 | if(num_missed) | |
697 | for(i=0;i<num_missed;i++) | |
698 | { | |
699 | wavepoint->sigqual[wavepoint->qualptr++]=0; /* If so, enter them as 0's */ | |
700 | wavepoint->qualptr %=WAVEPOINT_HISTORY; /* in the ringbuffer. */ | |
701 | } | |
702 | wavepoint->last_seen=jiffies; /* Add beacon to history */ | |
703 | wavepoint->last_seq=seq; | |
704 | wavepoint->sigqual[wavepoint->qualptr++]=sigqual; | |
705 | wavepoint->qualptr %=WAVEPOINT_HISTORY; | |
706 | ptr=(wavepoint->qualptr-WAVEPOINT_FAST_HISTORY+WAVEPOINT_HISTORY)%WAVEPOINT_HISTORY; | |
707 | ||
708 | for(i=0;i<WAVEPOINT_FAST_HISTORY;i++) /* Update running averages */ | |
709 | { | |
710 | average_fast+=wavepoint->sigqual[ptr++]; | |
711 | ptr %=WAVEPOINT_HISTORY; | |
712 | } | |
713 | ||
714 | average_slow=average_fast; | |
715 | for(i=WAVEPOINT_FAST_HISTORY;i<WAVEPOINT_HISTORY;i++) | |
716 | { | |
717 | average_slow+=wavepoint->sigqual[ptr++]; | |
718 | ptr %=WAVEPOINT_HISTORY; | |
719 | } | |
720 | ||
721 | wavepoint->average_fast=average_fast/WAVEPOINT_FAST_HISTORY; | |
722 | wavepoint->average_slow=average_slow/WAVEPOINT_HISTORY; | |
723 | } | |
724 | ||
725 | /* Perform a handover to a new WavePoint */ | |
726 | void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp) | |
727 | { | |
728 | kio_addr_t base = lp->dev->base_addr; | |
729 | mm_t m; | |
730 | unsigned long flags; | |
731 | ||
732 | if(wavepoint==lp->curr_point) /* Sanity check... */ | |
733 | { | |
734 | wv_nwid_filter(!NWID_PROMISC,lp); | |
735 | return; | |
736 | } | |
737 | ||
738 | #ifdef WAVELAN_ROAMING_DEBUG | |
739 | printk(KERN_DEBUG "WaveLAN: Doing handover to %.4X, dev %s\n",wavepoint->nwid,lp->dev->name); | |
740 | #endif | |
741 | ||
742 | /* Disable interrupts & save flags */ | |
743 | spin_lock_irqsave(&lp->spinlock, flags); | |
744 | ||
745 | m.w.mmw_netw_id_l = wavepoint->nwid & 0xFF; | |
746 | m.w.mmw_netw_id_h = (wavepoint->nwid & 0xFF00) >> 8; | |
747 | ||
748 | mmc_write(base, (char *)&m.w.mmw_netw_id_l - (char *)&m, (unsigned char *)&m.w.mmw_netw_id_l, 2); | |
749 | ||
750 | /* ReEnable interrupts & restore flags */ | |
751 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
752 | ||
753 | wv_nwid_filter(!NWID_PROMISC,lp); | |
754 | lp->curr_point=wavepoint; | |
755 | } | |
756 | ||
757 | /* Called when a WavePoint beacon is received */ | |
758 | static inline void wl_roam_gather(struct net_device * dev, | |
759 | u_char * hdr, /* Beacon header */ | |
760 | u_char * stats) /* SNR, Signal quality | |
761 | of packet */ | |
762 | { | |
763 | wavepoint_beacon *beacon= (wavepoint_beacon *)hdr; /* Rcvd. Beacon */ | |
764 | unsigned short nwid=ntohs(beacon->nwid); | |
765 | unsigned short sigqual=stats[2] & MMR_SGNL_QUAL; /* SNR of beacon */ | |
766 | wavepoint_history *wavepoint=NULL; /* WavePoint table entry */ | |
767 | net_local *lp = netdev_priv(dev); /* Device info */ | |
768 | ||
769 | #ifdef I_NEED_THIS_FEATURE | |
770 | /* Some people don't need this, some other may need it */ | |
771 | nwid=nwid^ntohs(beacon->domain_id); | |
772 | #endif | |
773 | ||
774 | #if WAVELAN_ROAMING_DEBUG > 1 | |
775 | printk(KERN_DEBUG "WaveLAN: beacon, dev %s:\n",dev->name); | |
776 | printk(KERN_DEBUG "Domain: %.4X NWID: %.4X SigQual=%d\n",ntohs(beacon->domain_id),nwid,sigqual); | |
777 | #endif | |
778 | ||
779 | lp->wavepoint_table.locked=1; /* <Mutex> */ | |
780 | ||
781 | wavepoint=wl_roam_check(nwid,lp); /* Find WavePoint table entry */ | |
782 | if(wavepoint==NULL) /* If no entry, Create a new one... */ | |
783 | { | |
784 | wavepoint=wl_new_wavepoint(nwid,beacon->seq,lp); | |
785 | if(wavepoint==NULL) | |
786 | goto out; | |
787 | } | |
788 | if(lp->curr_point==NULL) /* If this is the only WavePoint, */ | |
789 | wv_roam_handover(wavepoint, lp); /* Jump on it! */ | |
790 | ||
791 | wl_update_history(wavepoint, sigqual, beacon->seq); /* Update SNR history | |
792 | stats. */ | |
793 | ||
794 | if(lp->curr_point->average_slow < SEARCH_THRESH_LOW) /* If our current */ | |
795 | if(!lp->cell_search) /* WavePoint is getting faint, */ | |
796 | wv_nwid_filter(NWID_PROMISC,lp); /* start looking for a new one */ | |
797 | ||
798 | if(wavepoint->average_slow > | |
799 | lp->curr_point->average_slow + WAVELAN_ROAMING_DELTA) | |
800 | wv_roam_handover(wavepoint, lp); /* Handover to a better WavePoint */ | |
801 | ||
802 | if(lp->curr_point->average_slow > SEARCH_THRESH_HIGH) /* If our SNR is */ | |
803 | if(lp->cell_search) /* getting better, drop out of cell search mode */ | |
804 | wv_nwid_filter(!NWID_PROMISC,lp); | |
805 | ||
806 | out: | |
807 | lp->wavepoint_table.locked=0; /* </MUTEX> :-) */ | |
808 | } | |
809 | ||
810 | /* Test this MAC frame a WavePoint beacon */ | |
811 | static inline int WAVELAN_BEACON(unsigned char *data) | |
812 | { | |
813 | wavepoint_beacon *beacon= (wavepoint_beacon *)data; | |
814 | static wavepoint_beacon beacon_template={0xaa,0xaa,0x03,0x08,0x00,0x0e,0x20,0x03,0x00}; | |
815 | ||
816 | if(memcmp(beacon,&beacon_template,9)==0) | |
817 | return 1; | |
818 | else | |
819 | return 0; | |
820 | } | |
821 | #endif /* WAVELAN_ROAMING */ | |
822 | ||
823 | /************************ I82593 SUBROUTINES *************************/ | |
824 | /* | |
825 | * Useful subroutines to manage the Ethernet controller | |
826 | */ | |
827 | ||
828 | /*------------------------------------------------------------------*/ | |
829 | /* | |
830 | * Routine to synchronously send a command to the i82593 chip. | |
831 | * Should be called with interrupts disabled. | |
832 | * (called by wv_packet_write(), wv_ru_stop(), wv_ru_start(), | |
833 | * wv_82593_config() & wv_diag()) | |
834 | */ | |
835 | static int | |
836 | wv_82593_cmd(struct net_device * dev, | |
837 | char * str, | |
838 | int cmd, | |
839 | int result) | |
840 | { | |
841 | kio_addr_t base = dev->base_addr; | |
842 | int status; | |
843 | int wait_completed; | |
844 | long spin; | |
845 | ||
846 | /* Spin until the chip finishes executing its current command (if any) */ | |
847 | spin = 1000; | |
848 | do | |
849 | { | |
850 | /* Time calibration of the loop */ | |
851 | udelay(10); | |
852 | ||
853 | /* Read the interrupt register */ | |
854 | outb(OP0_NOP | CR0_STATUS_3, LCCR(base)); | |
855 | status = inb(LCSR(base)); | |
856 | } | |
857 | while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0)); | |
858 | ||
859 | /* If the interrupt hasn't be posted */ | |
860 | if(spin <= 0) | |
861 | { | |
862 | #ifdef DEBUG_INTERRUPT_ERROR | |
863 | printk(KERN_INFO "wv_82593_cmd: %s timeout (previous command), status 0x%02x\n", | |
864 | str, status); | |
865 | #endif | |
866 | return(FALSE); | |
867 | } | |
868 | ||
869 | /* Issue the command to the controller */ | |
870 | outb(cmd, LCCR(base)); | |
871 | ||
872 | /* If we don't have to check the result of the command | |
873 | * Note : this mean that the irq handler will deal with that */ | |
874 | if(result == SR0_NO_RESULT) | |
875 | return(TRUE); | |
876 | ||
877 | /* We are waiting for command completion */ | |
878 | wait_completed = TRUE; | |
879 | ||
880 | /* Busy wait while the LAN controller executes the command. */ | |
881 | spin = 1000; | |
882 | do | |
883 | { | |
884 | /* Time calibration of the loop */ | |
885 | udelay(10); | |
886 | ||
887 | /* Read the interrupt register */ | |
888 | outb(CR0_STATUS_0 | OP0_NOP, LCCR(base)); | |
889 | status = inb(LCSR(base)); | |
890 | ||
891 | /* Check if there was an interrupt posted */ | |
892 | if((status & SR0_INTERRUPT)) | |
893 | { | |
894 | /* Acknowledge the interrupt */ | |
895 | outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); | |
896 | ||
897 | /* Check if interrupt is a command completion */ | |
898 | if(((status & SR0_BOTH_RX_TX) != SR0_BOTH_RX_TX) && | |
899 | ((status & SR0_BOTH_RX_TX) != 0x0) && | |
900 | !(status & SR0_RECEPTION)) | |
901 | { | |
902 | /* Signal command completion */ | |
903 | wait_completed = FALSE; | |
904 | } | |
905 | else | |
906 | { | |
907 | /* Note : Rx interrupts will be handled later, because we can | |
908 | * handle multiple Rx packets at once */ | |
909 | #ifdef DEBUG_INTERRUPT_INFO | |
910 | printk(KERN_INFO "wv_82593_cmd: not our interrupt\n"); | |
911 | #endif | |
912 | } | |
913 | } | |
914 | } | |
915 | while(wait_completed && (spin-- > 0)); | |
916 | ||
917 | /* If the interrupt hasn't be posted */ | |
918 | if(wait_completed) | |
919 | { | |
920 | #ifdef DEBUG_INTERRUPT_ERROR | |
921 | printk(KERN_INFO "wv_82593_cmd: %s timeout, status 0x%02x\n", | |
922 | str, status); | |
923 | #endif | |
924 | return(FALSE); | |
925 | } | |
926 | ||
927 | /* Check the return code returned by the card (see above) against | |
928 | * the expected return code provided by the caller */ | |
929 | if((status & SR0_EVENT_MASK) != result) | |
930 | { | |
931 | #ifdef DEBUG_INTERRUPT_ERROR | |
932 | printk(KERN_INFO "wv_82593_cmd: %s failed, status = 0x%x\n", | |
933 | str, status); | |
934 | #endif | |
935 | return(FALSE); | |
936 | } | |
937 | ||
938 | return(TRUE); | |
939 | } /* wv_82593_cmd */ | |
940 | ||
941 | /*------------------------------------------------------------------*/ | |
942 | /* | |
943 | * This routine does a 593 op-code number 7, and obtains the diagnose | |
944 | * status for the WaveLAN. | |
945 | */ | |
946 | static inline int | |
947 | wv_diag(struct net_device * dev) | |
948 | { | |
949 | int ret = FALSE; | |
950 | ||
951 | if(wv_82593_cmd(dev, "wv_diag(): diagnose", | |
952 | OP0_DIAGNOSE, SR0_DIAGNOSE_PASSED)) | |
953 | ret = TRUE; | |
954 | ||
955 | #ifdef DEBUG_CONFIG_ERRORS | |
956 | printk(KERN_INFO "wavelan_cs: i82593 Self Test failed!\n"); | |
957 | #endif | |
958 | return(ret); | |
959 | } /* wv_diag */ | |
960 | ||
961 | /*------------------------------------------------------------------*/ | |
962 | /* | |
963 | * Routine to read len bytes from the i82593's ring buffer, starting at | |
964 | * chip address addr. The results read from the chip are stored in buf. | |
965 | * The return value is the address to use for next the call. | |
966 | */ | |
967 | static int | |
968 | read_ringbuf(struct net_device * dev, | |
969 | int addr, | |
970 | char * buf, | |
971 | int len) | |
972 | { | |
973 | kio_addr_t base = dev->base_addr; | |
974 | int ring_ptr = addr; | |
975 | int chunk_len; | |
976 | char * buf_ptr = buf; | |
977 | ||
978 | /* Get all the buffer */ | |
979 | while(len > 0) | |
980 | { | |
981 | /* Position the Program I/O Register at the ring buffer pointer */ | |
982 | outb(ring_ptr & 0xff, PIORL(base)); | |
983 | outb(((ring_ptr >> 8) & PIORH_MASK), PIORH(base)); | |
984 | ||
985 | /* First, determine how much we can read without wrapping around the | |
986 | ring buffer */ | |
987 | if((addr + len) < (RX_BASE + RX_SIZE)) | |
988 | chunk_len = len; | |
989 | else | |
990 | chunk_len = RX_BASE + RX_SIZE - addr; | |
991 | insb(PIOP(base), buf_ptr, chunk_len); | |
992 | buf_ptr += chunk_len; | |
993 | len -= chunk_len; | |
994 | ring_ptr = (ring_ptr - RX_BASE + chunk_len) % RX_SIZE + RX_BASE; | |
995 | } | |
996 | return(ring_ptr); | |
997 | } /* read_ringbuf */ | |
998 | ||
999 | /*------------------------------------------------------------------*/ | |
1000 | /* | |
1001 | * Reconfigure the i82593, or at least ask for it... | |
1002 | * Because wv_82593_config use the transmission buffer, we must do it | |
1003 | * when we are sure that there is no transmission, so we do it now | |
1004 | * or in wavelan_packet_xmit() (I can't find any better place, | |
1005 | * wavelan_interrupt is not an option...), so you may experience | |
1006 | * some delay sometime... | |
1007 | */ | |
1008 | static inline void | |
1009 | wv_82593_reconfig(struct net_device * dev) | |
1010 | { | |
1011 | net_local * lp = netdev_priv(dev); | |
1012 | dev_link_t * link = lp->link; | |
1013 | unsigned long flags; | |
1014 | ||
1015 | /* Arm the flag, will be cleard in wv_82593_config() */ | |
1016 | lp->reconfig_82593 = TRUE; | |
1017 | ||
1018 | /* Check if we can do it now ! */ | |
1019 | if((link->open) && (netif_running(dev)) && !(netif_queue_stopped(dev))) | |
1020 | { | |
1021 | spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */ | |
1022 | wv_82593_config(dev); | |
1023 | spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */ | |
1024 | } | |
1025 | else | |
1026 | { | |
1027 | #ifdef DEBUG_IOCTL_INFO | |
1028 | printk(KERN_DEBUG | |
1029 | "%s: wv_82593_reconfig(): delayed (state = %lX, link = %d)\n", | |
1030 | dev->name, dev->state, link->open); | |
1031 | #endif | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | /********************* DEBUG & INFO SUBROUTINES *********************/ | |
1036 | /* | |
1037 | * This routines are used in the code to show debug informations. | |
1038 | * Most of the time, it dump the content of hardware structures... | |
1039 | */ | |
1040 | ||
1041 | #ifdef DEBUG_PSA_SHOW | |
1042 | /*------------------------------------------------------------------*/ | |
1043 | /* | |
1044 | * Print the formatted contents of the Parameter Storage Area. | |
1045 | */ | |
1046 | static void | |
1047 | wv_psa_show(psa_t * p) | |
1048 | { | |
1049 | printk(KERN_DEBUG "##### wavelan psa contents: #####\n"); | |
1050 | printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n", | |
1051 | p->psa_io_base_addr_1, | |
1052 | p->psa_io_base_addr_2, | |
1053 | p->psa_io_base_addr_3, | |
1054 | p->psa_io_base_addr_4); | |
1055 | printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n", | |
1056 | p->psa_rem_boot_addr_1, | |
1057 | p->psa_rem_boot_addr_2, | |
1058 | p->psa_rem_boot_addr_3); | |
1059 | printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params); | |
1060 | printk("psa_int_req_no: %d\n", p->psa_int_req_no); | |
1061 | #ifdef DEBUG_SHOW_UNUSED | |
1062 | printk(KERN_DEBUG "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n", | |
1063 | p->psa_unused0[0], | |
1064 | p->psa_unused0[1], | |
1065 | p->psa_unused0[2], | |
1066 | p->psa_unused0[3], | |
1067 | p->psa_unused0[4], | |
1068 | p->psa_unused0[5], | |
1069 | p->psa_unused0[6]); | |
1070 | #endif /* DEBUG_SHOW_UNUSED */ | |
1071 | printk(KERN_DEBUG "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n", | |
1072 | p->psa_univ_mac_addr[0], | |
1073 | p->psa_univ_mac_addr[1], | |
1074 | p->psa_univ_mac_addr[2], | |
1075 | p->psa_univ_mac_addr[3], | |
1076 | p->psa_univ_mac_addr[4], | |
1077 | p->psa_univ_mac_addr[5]); | |
1078 | printk(KERN_DEBUG "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n", | |
1079 | p->psa_local_mac_addr[0], | |
1080 | p->psa_local_mac_addr[1], | |
1081 | p->psa_local_mac_addr[2], | |
1082 | p->psa_local_mac_addr[3], | |
1083 | p->psa_local_mac_addr[4], | |
1084 | p->psa_local_mac_addr[5]); | |
1085 | printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel); | |
1086 | printk("psa_comp_number: %d, ", p->psa_comp_number); | |
1087 | printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set); | |
1088 | printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ", | |
1089 | p->psa_feature_select); | |
1090 | printk("psa_subband/decay_update_prm: %d\n", p->psa_subband); | |
1091 | printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr); | |
1092 | printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay); | |
1093 | printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]); | |
1094 | printk("psa_nwid_select: %d\n", p->psa_nwid_select); | |
1095 | printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select); | |
1096 | printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", | |
1097 | p->psa_encryption_key[0], | |
1098 | p->psa_encryption_key[1], | |
1099 | p->psa_encryption_key[2], | |
1100 | p->psa_encryption_key[3], | |
1101 | p->psa_encryption_key[4], | |
1102 | p->psa_encryption_key[5], | |
1103 | p->psa_encryption_key[6], | |
1104 | p->psa_encryption_key[7]); | |
1105 | printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width); | |
1106 | printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ", | |
1107 | p->psa_call_code[0]); | |
1108 | printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", | |
1109 | p->psa_call_code[0], | |
1110 | p->psa_call_code[1], | |
1111 | p->psa_call_code[2], | |
1112 | p->psa_call_code[3], | |
1113 | p->psa_call_code[4], | |
1114 | p->psa_call_code[5], | |
1115 | p->psa_call_code[6], | |
1116 | p->psa_call_code[7]); | |
1117 | #ifdef DEBUG_SHOW_UNUSED | |
1118 | printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n", | |
1119 | p->psa_reserved[0], | |
1120 | p->psa_reserved[1], | |
1121 | p->psa_reserved[2], | |
1122 | p->psa_reserved[3]); | |
1123 | #endif /* DEBUG_SHOW_UNUSED */ | |
1124 | printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status); | |
1125 | printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]); | |
1126 | printk("psa_crc_status: 0x%02x\n", p->psa_crc_status); | |
1127 | } /* wv_psa_show */ | |
1128 | #endif /* DEBUG_PSA_SHOW */ | |
1129 | ||
1130 | #ifdef DEBUG_MMC_SHOW | |
1131 | /*------------------------------------------------------------------*/ | |
1132 | /* | |
1133 | * Print the formatted status of the Modem Management Controller. | |
1134 | * This function need to be completed... | |
1135 | */ | |
1136 | static void | |
1137 | wv_mmc_show(struct net_device * dev) | |
1138 | { | |
1139 | kio_addr_t base = dev->base_addr; | |
1140 | net_local * lp = netdev_priv(dev); | |
1141 | mmr_t m; | |
1142 | ||
1143 | /* Basic check */ | |
1144 | if(hasr_read(base) & HASR_NO_CLK) | |
1145 | { | |
1146 | printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n", | |
1147 | dev->name); | |
1148 | return; | |
1149 | } | |
1150 | ||
1151 | spin_lock_irqsave(&lp->spinlock, flags); | |
1152 | ||
1153 | /* Read the mmc */ | |
1154 | mmc_out(base, mmwoff(0, mmw_freeze), 1); | |
1155 | mmc_read(base, 0, (u_char *)&m, sizeof(m)); | |
1156 | mmc_out(base, mmwoff(0, mmw_freeze), 0); | |
1157 | ||
1158 | #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */ | |
1159 | /* Don't forget to update statistics */ | |
1160 | lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l; | |
1161 | #endif /* WIRELESS_EXT */ | |
1162 | ||
1163 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1164 | ||
1165 | printk(KERN_DEBUG "##### wavelan modem status registers: #####\n"); | |
1166 | #ifdef DEBUG_SHOW_UNUSED | |
1167 | printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", | |
1168 | m.mmr_unused0[0], | |
1169 | m.mmr_unused0[1], | |
1170 | m.mmr_unused0[2], | |
1171 | m.mmr_unused0[3], | |
1172 | m.mmr_unused0[4], | |
1173 | m.mmr_unused0[5], | |
1174 | m.mmr_unused0[6], | |
1175 | m.mmr_unused0[7]); | |
1176 | #endif /* DEBUG_SHOW_UNUSED */ | |
1177 | printk(KERN_DEBUG "Encryption algorythm: %02X - Status: %02X\n", | |
1178 | m.mmr_des_avail, m.mmr_des_status); | |
1179 | #ifdef DEBUG_SHOW_UNUSED | |
1180 | printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n", | |
1181 | m.mmr_unused1[0], | |
1182 | m.mmr_unused1[1], | |
1183 | m.mmr_unused1[2], | |
1184 | m.mmr_unused1[3], | |
1185 | m.mmr_unused1[4]); | |
1186 | #endif /* DEBUG_SHOW_UNUSED */ | |
1187 | printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n", | |
1188 | m.mmr_dce_status, | |
1189 | (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"", | |
1190 | (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ? | |
1191 | "loop test indicated," : "", | |
1192 | (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "", | |
1193 | (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ? | |
1194 | "jabber timer expired," : ""); | |
1195 | printk(KERN_DEBUG "Dsp ID: %02X\n", | |
1196 | m.mmr_dsp_id); | |
1197 | #ifdef DEBUG_SHOW_UNUSED | |
1198 | printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n", | |
1199 | m.mmr_unused2[0], | |
1200 | m.mmr_unused2[1]); | |
1201 | #endif /* DEBUG_SHOW_UNUSED */ | |
1202 | printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n", | |
1203 | (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l, | |
1204 | (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l); | |
1205 | printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n", | |
1206 | m.mmr_thr_pre_set & MMR_THR_PRE_SET, | |
1207 | (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below"); | |
1208 | printk(KERN_DEBUG "signal_lvl: %d [%s], ", | |
1209 | m.mmr_signal_lvl & MMR_SIGNAL_LVL, | |
1210 | (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg"); | |
1211 | printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL, | |
1212 | (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update"); | |
1213 | printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL, | |
1214 | (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0"); | |
1215 | #ifdef DEBUG_SHOW_UNUSED | |
1216 | printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l); | |
1217 | #endif /* DEBUG_SHOW_UNUSED */ | |
1218 | } /* wv_mmc_show */ | |
1219 | #endif /* DEBUG_MMC_SHOW */ | |
1220 | ||
1221 | #ifdef DEBUG_I82593_SHOW | |
1222 | /*------------------------------------------------------------------*/ | |
1223 | /* | |
1224 | * Print the formatted status of the i82593's receive unit. | |
1225 | */ | |
1226 | static void | |
1227 | wv_ru_show(struct net_device * dev) | |
1228 | { | |
1229 | net_local *lp = netdev_priv(dev); | |
1230 | ||
1231 | printk(KERN_DEBUG "##### wavelan i82593 receiver status: #####\n"); | |
1232 | printk(KERN_DEBUG "ru: rfp %d stop %d", lp->rfp, lp->stop); | |
1233 | /* | |
1234 | * Not implemented yet... | |
1235 | */ | |
1236 | printk("\n"); | |
1237 | } /* wv_ru_show */ | |
1238 | #endif /* DEBUG_I82593_SHOW */ | |
1239 | ||
1240 | #ifdef DEBUG_DEVICE_SHOW | |
1241 | /*------------------------------------------------------------------*/ | |
1242 | /* | |
1243 | * Print the formatted status of the WaveLAN PCMCIA device driver. | |
1244 | */ | |
1245 | static void | |
1246 | wv_dev_show(struct net_device * dev) | |
1247 | { | |
1248 | printk(KERN_DEBUG "dev:"); | |
1249 | printk(" state=%lX,", dev->state); | |
1250 | printk(" trans_start=%ld,", dev->trans_start); | |
1251 | printk(" flags=0x%x,", dev->flags); | |
1252 | printk("\n"); | |
1253 | } /* wv_dev_show */ | |
1254 | ||
1255 | /*------------------------------------------------------------------*/ | |
1256 | /* | |
1257 | * Print the formatted status of the WaveLAN PCMCIA device driver's | |
1258 | * private information. | |
1259 | */ | |
1260 | static void | |
1261 | wv_local_show(struct net_device * dev) | |
1262 | { | |
1263 | net_local *lp = netdev_priv(dev); | |
1264 | ||
1265 | printk(KERN_DEBUG "local:"); | |
1266 | /* | |
1267 | * Not implemented yet... | |
1268 | */ | |
1269 | printk("\n"); | |
1270 | } /* wv_local_show */ | |
1271 | #endif /* DEBUG_DEVICE_SHOW */ | |
1272 | ||
1273 | #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) | |
1274 | /*------------------------------------------------------------------*/ | |
1275 | /* | |
1276 | * Dump packet header (and content if necessary) on the screen | |
1277 | */ | |
1278 | static inline void | |
1279 | wv_packet_info(u_char * p, /* Packet to dump */ | |
1280 | int length, /* Length of the packet */ | |
1281 | char * msg1, /* Name of the device */ | |
1282 | char * msg2) /* Name of the function */ | |
1283 | { | |
1284 | int i; | |
1285 | int maxi; | |
1286 | ||
1287 | printk(KERN_DEBUG "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n", | |
1288 | msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length); | |
1289 | printk(KERN_DEBUG "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n", | |
1290 | msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13]); | |
1291 | ||
1292 | #ifdef DEBUG_PACKET_DUMP | |
1293 | ||
1294 | printk(KERN_DEBUG "data=\""); | |
1295 | ||
1296 | if((maxi = length) > DEBUG_PACKET_DUMP) | |
1297 | maxi = DEBUG_PACKET_DUMP; | |
1298 | for(i = 14; i < maxi; i++) | |
1299 | if(p[i] >= ' ' && p[i] <= '~') | |
1300 | printk(" %c", p[i]); | |
1301 | else | |
1302 | printk("%02X", p[i]); | |
1303 | if(maxi < length) | |
1304 | printk(".."); | |
1305 | printk("\"\n"); | |
1306 | printk(KERN_DEBUG "\n"); | |
1307 | #endif /* DEBUG_PACKET_DUMP */ | |
1308 | } | |
1309 | #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */ | |
1310 | ||
1311 | /*------------------------------------------------------------------*/ | |
1312 | /* | |
1313 | * This is the information which is displayed by the driver at startup | |
1314 | * There is a lot of flag to configure it at your will... | |
1315 | */ | |
1316 | static inline void | |
1317 | wv_init_info(struct net_device * dev) | |
1318 | { | |
1319 | kio_addr_t base = dev->base_addr; | |
1320 | psa_t psa; | |
1321 | int i; | |
1322 | ||
1323 | /* Read the parameter storage area */ | |
1324 | psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa)); | |
1325 | ||
1326 | #ifdef DEBUG_PSA_SHOW | |
1327 | wv_psa_show(&psa); | |
1328 | #endif | |
1329 | #ifdef DEBUG_MMC_SHOW | |
1330 | wv_mmc_show(dev); | |
1331 | #endif | |
1332 | #ifdef DEBUG_I82593_SHOW | |
1333 | wv_ru_show(dev); | |
1334 | #endif | |
1335 | ||
1336 | #ifdef DEBUG_BASIC_SHOW | |
1337 | /* Now, let's go for the basic stuff */ | |
1338 | printk(KERN_NOTICE "%s: WaveLAN: port %#lx, irq %d, hw_addr", | |
1339 | dev->name, base, dev->irq); | |
1340 | for(i = 0; i < WAVELAN_ADDR_SIZE; i++) | |
1341 | printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]); | |
1342 | ||
1343 | /* Print current network id */ | |
1344 | if(psa.psa_nwid_select) | |
1345 | printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]); | |
1346 | else | |
1347 | printk(", nwid off"); | |
1348 | ||
1349 | /* If 2.00 card */ | |
1350 | if(!(mmc_in(base, mmroff(0, mmr_fee_status)) & | |
1351 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) | |
1352 | { | |
1353 | unsigned short freq; | |
1354 | ||
1355 | /* Ask the EEprom to read the frequency from the first area */ | |
1356 | fee_read(base, 0x00 /* 1st area - frequency... */, | |
1357 | &freq, 1); | |
1358 | ||
1359 | /* Print frequency */ | |
1360 | printk(", 2.00, %ld", (freq >> 6) + 2400L); | |
1361 | ||
1362 | /* Hack !!! */ | |
1363 | if(freq & 0x20) | |
1364 | printk(".5"); | |
1365 | } | |
1366 | else | |
1367 | { | |
1368 | printk(", PCMCIA, "); | |
1369 | switch (psa.psa_subband) | |
1370 | { | |
1371 | case PSA_SUBBAND_915: | |
1372 | printk("915"); | |
1373 | break; | |
1374 | case PSA_SUBBAND_2425: | |
1375 | printk("2425"); | |
1376 | break; | |
1377 | case PSA_SUBBAND_2460: | |
1378 | printk("2460"); | |
1379 | break; | |
1380 | case PSA_SUBBAND_2484: | |
1381 | printk("2484"); | |
1382 | break; | |
1383 | case PSA_SUBBAND_2430_5: | |
1384 | printk("2430.5"); | |
1385 | break; | |
1386 | default: | |
1387 | printk("unknown"); | |
1388 | } | |
1389 | } | |
1390 | ||
1391 | printk(" MHz\n"); | |
1392 | #endif /* DEBUG_BASIC_SHOW */ | |
1393 | ||
1394 | #ifdef DEBUG_VERSION_SHOW | |
1395 | /* Print version information */ | |
1396 | printk(KERN_NOTICE "%s", version); | |
1397 | #endif | |
1398 | } /* wv_init_info */ | |
1399 | ||
1400 | /********************* IOCTL, STATS & RECONFIG *********************/ | |
1401 | /* | |
1402 | * We found here routines that are called by Linux on differents | |
1403 | * occasions after the configuration and not for transmitting data | |
1404 | * These may be called when the user use ifconfig, /proc/net/dev | |
1405 | * or wireless extensions | |
1406 | */ | |
1407 | ||
1408 | /*------------------------------------------------------------------*/ | |
1409 | /* | |
1410 | * Get the current ethernet statistics. This may be called with the | |
1411 | * card open or closed. | |
1412 | * Used when the user read /proc/net/dev | |
1413 | */ | |
1414 | static en_stats * | |
1415 | wavelan_get_stats(struct net_device * dev) | |
1416 | { | |
1417 | #ifdef DEBUG_IOCTL_TRACE | |
1418 | printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name); | |
1419 | #endif | |
1420 | ||
1421 | return(&((net_local *)netdev_priv(dev))->stats); | |
1422 | } | |
1423 | ||
1424 | /*------------------------------------------------------------------*/ | |
1425 | /* | |
1426 | * Set or clear the multicast filter for this adaptor. | |
1427 | * num_addrs == -1 Promiscuous mode, receive all packets | |
1428 | * num_addrs == 0 Normal mode, clear multicast list | |
1429 | * num_addrs > 0 Multicast mode, receive normal and MC packets, | |
1430 | * and do best-effort filtering. | |
1431 | */ | |
1432 | ||
1433 | static void | |
1434 | wavelan_set_multicast_list(struct net_device * dev) | |
1435 | { | |
1436 | net_local * lp = netdev_priv(dev); | |
1437 | ||
1438 | #ifdef DEBUG_IOCTL_TRACE | |
1439 | printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name); | |
1440 | #endif | |
1441 | ||
1442 | #ifdef DEBUG_IOCTL_INFO | |
1443 | printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n", | |
1444 | dev->name, dev->flags, dev->mc_count); | |
1445 | #endif | |
1446 | ||
1447 | if(dev->flags & IFF_PROMISC) | |
1448 | { | |
1449 | /* | |
1450 | * Enable promiscuous mode: receive all packets. | |
1451 | */ | |
1452 | if(!lp->promiscuous) | |
1453 | { | |
1454 | lp->promiscuous = 1; | |
1455 | lp->allmulticast = 0; | |
1456 | lp->mc_count = 0; | |
1457 | ||
1458 | wv_82593_reconfig(dev); | |
1459 | ||
1460 | /* Tell the kernel that we are doing a really bad job... */ | |
1461 | dev->flags |= IFF_PROMISC; | |
1462 | } | |
1463 | } | |
1464 | else | |
1465 | /* If all multicast addresses | |
1466 | * or too much multicast addresses for the hardware filter */ | |
1467 | if((dev->flags & IFF_ALLMULTI) || | |
1468 | (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES)) | |
1469 | { | |
1470 | /* | |
1471 | * Disable promiscuous mode, but active the all multicast mode | |
1472 | */ | |
1473 | if(!lp->allmulticast) | |
1474 | { | |
1475 | lp->promiscuous = 0; | |
1476 | lp->allmulticast = 1; | |
1477 | lp->mc_count = 0; | |
1478 | ||
1479 | wv_82593_reconfig(dev); | |
1480 | ||
1481 | /* Tell the kernel that we are doing a really bad job... */ | |
1482 | dev->flags |= IFF_ALLMULTI; | |
1483 | } | |
1484 | } | |
1485 | else | |
1486 | /* If there is some multicast addresses to send */ | |
1487 | if(dev->mc_list != (struct dev_mc_list *) NULL) | |
1488 | { | |
1489 | /* | |
1490 | * Disable promiscuous mode, but receive all packets | |
1491 | * in multicast list | |
1492 | */ | |
1493 | #ifdef MULTICAST_AVOID | |
1494 | if(lp->promiscuous || lp->allmulticast || | |
1495 | (dev->mc_count != lp->mc_count)) | |
1496 | #endif | |
1497 | { | |
1498 | lp->promiscuous = 0; | |
1499 | lp->allmulticast = 0; | |
1500 | lp->mc_count = dev->mc_count; | |
1501 | ||
1502 | wv_82593_reconfig(dev); | |
1503 | } | |
1504 | } | |
1505 | else | |
1506 | { | |
1507 | /* | |
1508 | * Switch to normal mode: disable promiscuous mode and | |
1509 | * clear the multicast list. | |
1510 | */ | |
1511 | if(lp->promiscuous || lp->mc_count == 0) | |
1512 | { | |
1513 | lp->promiscuous = 0; | |
1514 | lp->allmulticast = 0; | |
1515 | lp->mc_count = 0; | |
1516 | ||
1517 | wv_82593_reconfig(dev); | |
1518 | } | |
1519 | } | |
1520 | #ifdef DEBUG_IOCTL_TRACE | |
1521 | printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name); | |
1522 | #endif | |
1523 | } | |
1524 | ||
1525 | /*------------------------------------------------------------------*/ | |
1526 | /* | |
1527 | * This function doesn't exist... | |
1528 | * (Note : it was a nice way to test the reconfigure stuff...) | |
1529 | */ | |
1530 | #ifdef SET_MAC_ADDRESS | |
1531 | static int | |
1532 | wavelan_set_mac_address(struct net_device * dev, | |
1533 | void * addr) | |
1534 | { | |
1535 | struct sockaddr * mac = addr; | |
1536 | ||
1537 | /* Copy the address */ | |
1538 | memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE); | |
1539 | ||
1540 | /* Reconfig the beast */ | |
1541 | wv_82593_reconfig(dev); | |
1542 | ||
1543 | return 0; | |
1544 | } | |
1545 | #endif /* SET_MAC_ADDRESS */ | |
1546 | ||
1547 | #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */ | |
1548 | ||
1549 | /*------------------------------------------------------------------*/ | |
1550 | /* | |
1551 | * Frequency setting (for hardware able of it) | |
1552 | * It's a bit complicated and you don't really want to look into it... | |
1553 | */ | |
1554 | static inline int | |
1555 | wv_set_frequency(u_long base, /* i/o port of the card */ | |
1556 | iw_freq * frequency) | |
1557 | { | |
1558 | const int BAND_NUM = 10; /* Number of bands */ | |
1559 | long freq = 0L; /* offset to 2.4 GHz in .5 MHz */ | |
1560 | #ifdef DEBUG_IOCTL_INFO | |
1561 | int i; | |
1562 | #endif | |
1563 | ||
1564 | /* Setting by frequency */ | |
1565 | /* Theoritically, you may set any frequency between | |
1566 | * the two limits with a 0.5 MHz precision. In practice, | |
1567 | * I don't want you to have trouble with local | |
1568 | * regulations... */ | |
1569 | if((frequency->e == 1) && | |
1570 | (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8)) | |
1571 | { | |
1572 | freq = ((frequency->m / 10000) - 24000L) / 5; | |
1573 | } | |
1574 | ||
1575 | /* Setting by channel (same as wfreqsel) */ | |
1576 | /* Warning : each channel is 22MHz wide, so some of the channels | |
1577 | * will interfere... */ | |
1578 | if((frequency->e == 0) && | |
1579 | (frequency->m >= 0) && (frequency->m < BAND_NUM)) | |
1580 | { | |
1581 | /* Get frequency offset. */ | |
1582 | freq = channel_bands[frequency->m] >> 1; | |
1583 | } | |
1584 | ||
1585 | /* Verify if the frequency is allowed */ | |
1586 | if(freq != 0L) | |
1587 | { | |
1588 | u_short table[10]; /* Authorized frequency table */ | |
1589 | ||
1590 | /* Read the frequency table */ | |
1591 | fee_read(base, 0x71 /* frequency table */, | |
1592 | table, 10); | |
1593 | ||
1594 | #ifdef DEBUG_IOCTL_INFO | |
1595 | printk(KERN_DEBUG "Frequency table :"); | |
1596 | for(i = 0; i < 10; i++) | |
1597 | { | |
1598 | printk(" %04X", | |
1599 | table[i]); | |
1600 | } | |
1601 | printk("\n"); | |
1602 | #endif | |
1603 | ||
1604 | /* Look in the table if the frequency is allowed */ | |
1605 | if(!(table[9 - ((freq - 24) / 16)] & | |
1606 | (1 << ((freq - 24) % 16)))) | |
1607 | return -EINVAL; /* not allowed */ | |
1608 | } | |
1609 | else | |
1610 | return -EINVAL; | |
1611 | ||
1612 | /* If we get a usable frequency */ | |
1613 | if(freq != 0L) | |
1614 | { | |
1615 | unsigned short area[16]; | |
1616 | unsigned short dac[2]; | |
1617 | unsigned short area_verify[16]; | |
1618 | unsigned short dac_verify[2]; | |
1619 | /* Corresponding gain (in the power adjust value table) | |
1620 | * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8 | |
1621 | * & WCIN062D.DOC, page 6.2.9 */ | |
1622 | unsigned short power_limit[] = { 40, 80, 120, 160, 0 }; | |
1623 | int power_band = 0; /* Selected band */ | |
1624 | unsigned short power_adjust; /* Correct value */ | |
1625 | ||
1626 | /* Search for the gain */ | |
1627 | power_band = 0; | |
1628 | while((freq > power_limit[power_band]) && | |
1629 | (power_limit[++power_band] != 0)) | |
1630 | ; | |
1631 | ||
1632 | /* Read the first area */ | |
1633 | fee_read(base, 0x00, | |
1634 | area, 16); | |
1635 | ||
1636 | /* Read the DAC */ | |
1637 | fee_read(base, 0x60, | |
1638 | dac, 2); | |
1639 | ||
1640 | /* Read the new power adjust value */ | |
1641 | fee_read(base, 0x6B - (power_band >> 1), | |
1642 | &power_adjust, 1); | |
1643 | if(power_band & 0x1) | |
1644 | power_adjust >>= 8; | |
1645 | else | |
1646 | power_adjust &= 0xFF; | |
1647 | ||
1648 | #ifdef DEBUG_IOCTL_INFO | |
1649 | printk(KERN_DEBUG "Wavelan EEprom Area 1 :"); | |
1650 | for(i = 0; i < 16; i++) | |
1651 | { | |
1652 | printk(" %04X", | |
1653 | area[i]); | |
1654 | } | |
1655 | printk("\n"); | |
1656 | ||
1657 | printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n", | |
1658 | dac[0], dac[1]); | |
1659 | #endif | |
1660 | ||
1661 | /* Frequency offset (for info only...) */ | |
1662 | area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F); | |
1663 | ||
1664 | /* Receiver Principle main divider coefficient */ | |
1665 | area[3] = (freq >> 1) + 2400L - 352L; | |
1666 | area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF); | |
1667 | ||
1668 | /* Transmitter Main divider coefficient */ | |
1669 | area[13] = (freq >> 1) + 2400L; | |
1670 | area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF); | |
1671 | ||
1672 | /* Others part of the area are flags, bit streams or unused... */ | |
1673 | ||
1674 | /* Set the value in the DAC */ | |
1675 | dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80); | |
1676 | dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF); | |
1677 | ||
1678 | /* Write the first area */ | |
1679 | fee_write(base, 0x00, | |
1680 | area, 16); | |
1681 | ||
1682 | /* Write the DAC */ | |
1683 | fee_write(base, 0x60, | |
1684 | dac, 2); | |
1685 | ||
1686 | /* We now should verify here that the EEprom writting was ok */ | |
1687 | ||
1688 | /* ReRead the first area */ | |
1689 | fee_read(base, 0x00, | |
1690 | area_verify, 16); | |
1691 | ||
1692 | /* ReRead the DAC */ | |
1693 | fee_read(base, 0x60, | |
1694 | dac_verify, 2); | |
1695 | ||
1696 | /* Compare */ | |
1697 | if(memcmp(area, area_verify, 16 * 2) || | |
1698 | memcmp(dac, dac_verify, 2 * 2)) | |
1699 | { | |
1700 | #ifdef DEBUG_IOCTL_ERROR | |
1701 | printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n"); | |
1702 | #endif | |
1703 | return -EOPNOTSUPP; | |
1704 | } | |
1705 | ||
1706 | /* We must download the frequency parameters to the | |
1707 | * synthetisers (from the EEprom - area 1) | |
1708 | * Note : as the EEprom is auto decremented, we set the end | |
1709 | * if the area... */ | |
1710 | mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F); | |
1711 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), | |
1712 | MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD); | |
1713 | ||
1714 | /* Wait until the download is finished */ | |
1715 | fee_wait(base, 100, 100); | |
1716 | ||
1717 | /* We must now download the power adjust value (gain) to | |
1718 | * the synthetisers (from the EEprom - area 7 - DAC) */ | |
1719 | mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61); | |
1720 | mmc_out(base, mmwoff(0, mmw_fee_ctrl), | |
1721 | MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD); | |
1722 | ||
1723 | /* Wait until the download is finished */ | |
1724 | fee_wait(base, 100, 100); | |
1725 | ||
1726 | #ifdef DEBUG_IOCTL_INFO | |
1727 | /* Verification of what we have done... */ | |
1728 | ||
1729 | printk(KERN_DEBUG "Wavelan EEprom Area 1 :"); | |
1730 | for(i = 0; i < 16; i++) | |
1731 | { | |
1732 | printk(" %04X", | |
1733 | area_verify[i]); | |
1734 | } | |
1735 | printk("\n"); | |
1736 | ||
1737 | printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n", | |
1738 | dac_verify[0], dac_verify[1]); | |
1739 | #endif | |
1740 | ||
1741 | return 0; | |
1742 | } | |
1743 | else | |
1744 | return -EINVAL; /* Bah, never get there... */ | |
1745 | } | |
1746 | ||
1747 | /*------------------------------------------------------------------*/ | |
1748 | /* | |
1749 | * Give the list of available frequencies | |
1750 | */ | |
1751 | static inline int | |
1752 | wv_frequency_list(u_long base, /* i/o port of the card */ | |
1753 | iw_freq * list, /* List of frequency to fill */ | |
1754 | int max) /* Maximum number of frequencies */ | |
1755 | { | |
1756 | u_short table[10]; /* Authorized frequency table */ | |
1757 | long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */ | |
1758 | int i; /* index in the table */ | |
1759 | const int BAND_NUM = 10; /* Number of bands */ | |
1760 | int c = 0; /* Channel number */ | |
1761 | ||
1762 | /* Read the frequency table */ | |
1763 | fee_read(base, 0x71 /* frequency table */, | |
1764 | table, 10); | |
1765 | ||
1766 | /* Look all frequencies */ | |
1767 | i = 0; | |
1768 | for(freq = 0; freq < 150; freq++) | |
1769 | /* Look in the table if the frequency is allowed */ | |
1770 | if(table[9 - (freq / 16)] & (1 << (freq % 16))) | |
1771 | { | |
1772 | /* Compute approximate channel number */ | |
1773 | while((((channel_bands[c] >> 1) - 24) < freq) && | |
1774 | (c < BAND_NUM)) | |
1775 | c++; | |
1776 | list[i].i = c; /* Set the list index */ | |
1777 | ||
1778 | /* put in the list */ | |
1779 | list[i].m = (((freq + 24) * 5) + 24000L) * 10000; | |
1780 | list[i++].e = 1; | |
1781 | ||
1782 | /* Check number */ | |
1783 | if(i >= max) | |
1784 | return(i); | |
1785 | } | |
1786 | ||
1787 | return(i); | |
1788 | } | |
1789 | ||
1790 | #ifdef IW_WIRELESS_SPY | |
1791 | /*------------------------------------------------------------------*/ | |
1792 | /* | |
1793 | * Gather wireless spy statistics : for each packet, compare the source | |
1794 | * address with out list, and if match, get the stats... | |
1795 | * Sorry, but this function really need wireless extensions... | |
1796 | */ | |
1797 | static inline void | |
1798 | wl_spy_gather(struct net_device * dev, | |
1799 | u_char * mac, /* MAC address */ | |
1800 | u_char * stats) /* Statistics to gather */ | |
1801 | { | |
1802 | struct iw_quality wstats; | |
1803 | ||
1804 | wstats.qual = stats[2] & MMR_SGNL_QUAL; | |
1805 | wstats.level = stats[0] & MMR_SIGNAL_LVL; | |
1806 | wstats.noise = stats[1] & MMR_SILENCE_LVL; | |
1807 | wstats.updated = 0x7; | |
1808 | ||
1809 | /* Update spy records */ | |
1810 | wireless_spy_update(dev, mac, &wstats); | |
1811 | } | |
1812 | #endif /* IW_WIRELESS_SPY */ | |
1813 | ||
1814 | #ifdef HISTOGRAM | |
1815 | /*------------------------------------------------------------------*/ | |
1816 | /* | |
1817 | * This function calculate an histogram on the signal level. | |
1818 | * As the noise is quite constant, it's like doing it on the SNR. | |
1819 | * We have defined a set of interval (lp->his_range), and each time | |
1820 | * the level goes in that interval, we increment the count (lp->his_sum). | |
1821 | * With this histogram you may detect if one wavelan is really weak, | |
1822 | * or you may also calculate the mean and standard deviation of the level... | |
1823 | */ | |
1824 | static inline void | |
1825 | wl_his_gather(struct net_device * dev, | |
1826 | u_char * stats) /* Statistics to gather */ | |
1827 | { | |
1828 | net_local * lp = netdev_priv(dev); | |
1829 | u_char level = stats[0] & MMR_SIGNAL_LVL; | |
1830 | int i; | |
1831 | ||
1832 | /* Find the correct interval */ | |
1833 | i = 0; | |
1834 | while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++])) | |
1835 | ; | |
1836 | ||
1837 | /* Increment interval counter */ | |
1838 | (lp->his_sum[i])++; | |
1839 | } | |
1840 | #endif /* HISTOGRAM */ | |
1841 | ||
1842 | static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | |
1843 | { | |
1844 | strncpy(info->driver, "wavelan_cs", sizeof(info->driver)-1); | |
1845 | } | |
1846 | ||
1847 | static struct ethtool_ops ops = { | |
1848 | .get_drvinfo = wl_get_drvinfo | |
1849 | }; | |
1850 | ||
1851 | /*------------------------------------------------------------------*/ | |
1852 | /* | |
1853 | * Wireless Handler : get protocol name | |
1854 | */ | |
1855 | static int wavelan_get_name(struct net_device *dev, | |
1856 | struct iw_request_info *info, | |
1857 | union iwreq_data *wrqu, | |
1858 | char *extra) | |
1859 | { | |
1860 | strcpy(wrqu->name, "WaveLAN"); | |
1861 | return 0; | |
1862 | } | |
1863 | ||
1864 | /*------------------------------------------------------------------*/ | |
1865 | /* | |
1866 | * Wireless Handler : set NWID | |
1867 | */ | |
1868 | static int wavelan_set_nwid(struct net_device *dev, | |
1869 | struct iw_request_info *info, | |
1870 | union iwreq_data *wrqu, | |
1871 | char *extra) | |
1872 | { | |
1873 | kio_addr_t base = dev->base_addr; | |
1874 | net_local *lp = netdev_priv(dev); | |
1875 | psa_t psa; | |
1876 | mm_t m; | |
1877 | unsigned long flags; | |
1878 | int ret = 0; | |
1879 | ||
1880 | /* Disable interrupts and save flags. */ | |
1881 | spin_lock_irqsave(&lp->spinlock, flags); | |
1882 | ||
1883 | /* Set NWID in WaveLAN. */ | |
1884 | if (!wrqu->nwid.disabled) { | |
1885 | /* Set NWID in psa */ | |
1886 | psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8; | |
1887 | psa.psa_nwid[1] = wrqu->nwid.value & 0xFF; | |
1888 | psa.psa_nwid_select = 0x01; | |
1889 | psa_write(dev, | |
1890 | (char *) psa.psa_nwid - (char *) &psa, | |
1891 | (unsigned char *) psa.psa_nwid, 3); | |
1892 | ||
1893 | /* Set NWID in mmc. */ | |
1894 | m.w.mmw_netw_id_l = psa.psa_nwid[1]; | |
1895 | m.w.mmw_netw_id_h = psa.psa_nwid[0]; | |
1896 | mmc_write(base, | |
1897 | (char *) &m.w.mmw_netw_id_l - | |
1898 | (char *) &m, | |
1899 | (unsigned char *) &m.w.mmw_netw_id_l, 2); | |
1900 | mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00); | |
1901 | } else { | |
1902 | /* Disable NWID in the psa. */ | |
1903 | psa.psa_nwid_select = 0x00; | |
1904 | psa_write(dev, | |
1905 | (char *) &psa.psa_nwid_select - | |
1906 | (char *) &psa, | |
1907 | (unsigned char *) &psa.psa_nwid_select, | |
1908 | 1); | |
1909 | ||
1910 | /* Disable NWID in the mmc (no filtering). */ | |
1911 | mmc_out(base, mmwoff(0, mmw_loopt_sel), | |
1912 | MMW_LOOPT_SEL_DIS_NWID); | |
1913 | } | |
1914 | /* update the Wavelan checksum */ | |
1915 | update_psa_checksum(dev); | |
1916 | ||
1917 | /* Enable interrupts and restore flags. */ | |
1918 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1919 | ||
1920 | return ret; | |
1921 | } | |
1922 | ||
1923 | /*------------------------------------------------------------------*/ | |
1924 | /* | |
1925 | * Wireless Handler : get NWID | |
1926 | */ | |
1927 | static int wavelan_get_nwid(struct net_device *dev, | |
1928 | struct iw_request_info *info, | |
1929 | union iwreq_data *wrqu, | |
1930 | char *extra) | |
1931 | { | |
1932 | net_local *lp = netdev_priv(dev); | |
1933 | psa_t psa; | |
1934 | unsigned long flags; | |
1935 | int ret = 0; | |
1936 | ||
1937 | /* Disable interrupts and save flags. */ | |
1938 | spin_lock_irqsave(&lp->spinlock, flags); | |
1939 | ||
1940 | /* Read the NWID. */ | |
1941 | psa_read(dev, | |
1942 | (char *) psa.psa_nwid - (char *) &psa, | |
1943 | (unsigned char *) psa.psa_nwid, 3); | |
1944 | wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1]; | |
1945 | wrqu->nwid.disabled = !(psa.psa_nwid_select); | |
1946 | wrqu->nwid.fixed = 1; /* Superfluous */ | |
1947 | ||
1948 | /* Enable interrupts and restore flags. */ | |
1949 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1950 | ||
1951 | return ret; | |
1952 | } | |
1953 | ||
1954 | /*------------------------------------------------------------------*/ | |
1955 | /* | |
1956 | * Wireless Handler : set frequency | |
1957 | */ | |
1958 | static int wavelan_set_freq(struct net_device *dev, | |
1959 | struct iw_request_info *info, | |
1960 | union iwreq_data *wrqu, | |
1961 | char *extra) | |
1962 | { | |
1963 | kio_addr_t base = dev->base_addr; | |
1964 | net_local *lp = netdev_priv(dev); | |
1965 | unsigned long flags; | |
1966 | int ret; | |
1967 | ||
1968 | /* Disable interrupts and save flags. */ | |
1969 | spin_lock_irqsave(&lp->spinlock, flags); | |
1970 | ||
1971 | /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */ | |
1972 | if (!(mmc_in(base, mmroff(0, mmr_fee_status)) & | |
1973 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) | |
1974 | ret = wv_set_frequency(base, &(wrqu->freq)); | |
1975 | else | |
1976 | ret = -EOPNOTSUPP; | |
1977 | ||
1978 | /* Enable interrupts and restore flags. */ | |
1979 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
1980 | ||
1981 | return ret; | |
1982 | } | |
1983 | ||
1984 | /*------------------------------------------------------------------*/ | |
1985 | /* | |
1986 | * Wireless Handler : get frequency | |
1987 | */ | |
1988 | static int wavelan_get_freq(struct net_device *dev, | |
1989 | struct iw_request_info *info, | |
1990 | union iwreq_data *wrqu, | |
1991 | char *extra) | |
1992 | { | |
1993 | kio_addr_t base = dev->base_addr; | |
1994 | net_local *lp = netdev_priv(dev); | |
1995 | psa_t psa; | |
1996 | unsigned long flags; | |
1997 | int ret = 0; | |
1998 | ||
1999 | /* Disable interrupts and save flags. */ | |
2000 | spin_lock_irqsave(&lp->spinlock, flags); | |
2001 | ||
2002 | /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). | |
2003 | * Does it work for everybody, especially old cards? */ | |
2004 | if (!(mmc_in(base, mmroff(0, mmr_fee_status)) & | |
2005 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) { | |
2006 | unsigned short freq; | |
2007 | ||
2008 | /* Ask the EEPROM to read the frequency from the first area. */ | |
2009 | fee_read(base, 0x00, &freq, 1); | |
2010 | wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000; | |
2011 | wrqu->freq.e = 1; | |
2012 | } else { | |
2013 | psa_read(dev, | |
2014 | (char *) &psa.psa_subband - (char *) &psa, | |
2015 | (unsigned char *) &psa.psa_subband, 1); | |
2016 | ||
2017 | if (psa.psa_subband <= 4) { | |
2018 | wrqu->freq.m = fixed_bands[psa.psa_subband]; | |
2019 | wrqu->freq.e = (psa.psa_subband != 0); | |
2020 | } else | |
2021 | ret = -EOPNOTSUPP; | |
2022 | } | |
2023 | ||
2024 | /* Enable interrupts and restore flags. */ | |
2025 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2026 | ||
2027 | return ret; | |
2028 | } | |
2029 | ||
2030 | /*------------------------------------------------------------------*/ | |
2031 | /* | |
2032 | * Wireless Handler : set level threshold | |
2033 | */ | |
2034 | static int wavelan_set_sens(struct net_device *dev, | |
2035 | struct iw_request_info *info, | |
2036 | union iwreq_data *wrqu, | |
2037 | char *extra) | |
2038 | { | |
2039 | kio_addr_t base = dev->base_addr; | |
2040 | net_local *lp = netdev_priv(dev); | |
2041 | psa_t psa; | |
2042 | unsigned long flags; | |
2043 | int ret = 0; | |
2044 | ||
2045 | /* Disable interrupts and save flags. */ | |
2046 | spin_lock_irqsave(&lp->spinlock, flags); | |
2047 | ||
2048 | /* Set the level threshold. */ | |
2049 | /* We should complain loudly if wrqu->sens.fixed = 0, because we | |
2050 | * can't set auto mode... */ | |
2051 | psa.psa_thr_pre_set = wrqu->sens.value & 0x3F; | |
2052 | psa_write(dev, | |
2053 | (char *) &psa.psa_thr_pre_set - (char *) &psa, | |
2054 | (unsigned char *) &psa.psa_thr_pre_set, 1); | |
2055 | /* update the Wavelan checksum */ | |
2056 | update_psa_checksum(dev); | |
2057 | mmc_out(base, mmwoff(0, mmw_thr_pre_set), | |
2058 | psa.psa_thr_pre_set); | |
2059 | ||
2060 | /* Enable interrupts and restore flags. */ | |
2061 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2062 | ||
2063 | return ret; | |
2064 | } | |
2065 | ||
2066 | /*------------------------------------------------------------------*/ | |
2067 | /* | |
2068 | * Wireless Handler : get level threshold | |
2069 | */ | |
2070 | static int wavelan_get_sens(struct net_device *dev, | |
2071 | struct iw_request_info *info, | |
2072 | union iwreq_data *wrqu, | |
2073 | char *extra) | |
2074 | { | |
2075 | net_local *lp = netdev_priv(dev); | |
2076 | psa_t psa; | |
2077 | unsigned long flags; | |
2078 | int ret = 0; | |
2079 | ||
2080 | /* Disable interrupts and save flags. */ | |
2081 | spin_lock_irqsave(&lp->spinlock, flags); | |
2082 | ||
2083 | /* Read the level threshold. */ | |
2084 | psa_read(dev, | |
2085 | (char *) &psa.psa_thr_pre_set - (char *) &psa, | |
2086 | (unsigned char *) &psa.psa_thr_pre_set, 1); | |
2087 | wrqu->sens.value = psa.psa_thr_pre_set & 0x3F; | |
2088 | wrqu->sens.fixed = 1; | |
2089 | ||
2090 | /* Enable interrupts and restore flags. */ | |
2091 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2092 | ||
2093 | return ret; | |
2094 | } | |
2095 | ||
2096 | /*------------------------------------------------------------------*/ | |
2097 | /* | |
2098 | * Wireless Handler : set encryption key | |
2099 | */ | |
2100 | static int wavelan_set_encode(struct net_device *dev, | |
2101 | struct iw_request_info *info, | |
2102 | union iwreq_data *wrqu, | |
2103 | char *extra) | |
2104 | { | |
2105 | kio_addr_t base = dev->base_addr; | |
2106 | net_local *lp = netdev_priv(dev); | |
2107 | unsigned long flags; | |
2108 | psa_t psa; | |
2109 | int ret = 0; | |
2110 | ||
2111 | /* Disable interrupts and save flags. */ | |
2112 | spin_lock_irqsave(&lp->spinlock, flags); | |
2113 | ||
2114 | /* Check if capable of encryption */ | |
2115 | if (!mmc_encr(base)) { | |
2116 | ret = -EOPNOTSUPP; | |
2117 | } | |
2118 | ||
2119 | /* Check the size of the key */ | |
2120 | if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) { | |
2121 | ret = -EINVAL; | |
2122 | } | |
2123 | ||
2124 | if(!ret) { | |
2125 | /* Basic checking... */ | |
2126 | if (wrqu->encoding.length == 8) { | |
2127 | /* Copy the key in the driver */ | |
2128 | memcpy(psa.psa_encryption_key, extra, | |
2129 | wrqu->encoding.length); | |
2130 | psa.psa_encryption_select = 1; | |
2131 | ||
2132 | psa_write(dev, | |
2133 | (char *) &psa.psa_encryption_select - | |
2134 | (char *) &psa, | |
2135 | (unsigned char *) &psa. | |
2136 | psa_encryption_select, 8 + 1); | |
2137 | ||
2138 | mmc_out(base, mmwoff(0, mmw_encr_enable), | |
2139 | MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE); | |
2140 | mmc_write(base, mmwoff(0, mmw_encr_key), | |
2141 | (unsigned char *) &psa. | |
2142 | psa_encryption_key, 8); | |
2143 | } | |
2144 | ||
2145 | /* disable encryption */ | |
2146 | if (wrqu->encoding.flags & IW_ENCODE_DISABLED) { | |
2147 | psa.psa_encryption_select = 0; | |
2148 | psa_write(dev, | |
2149 | (char *) &psa.psa_encryption_select - | |
2150 | (char *) &psa, | |
2151 | (unsigned char *) &psa. | |
2152 | psa_encryption_select, 1); | |
2153 | ||
2154 | mmc_out(base, mmwoff(0, mmw_encr_enable), 0); | |
2155 | } | |
2156 | /* update the Wavelan checksum */ | |
2157 | update_psa_checksum(dev); | |
2158 | } | |
2159 | ||
2160 | /* Enable interrupts and restore flags. */ | |
2161 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2162 | ||
2163 | return ret; | |
2164 | } | |
2165 | ||
2166 | /*------------------------------------------------------------------*/ | |
2167 | /* | |
2168 | * Wireless Handler : get encryption key | |
2169 | */ | |
2170 | static int wavelan_get_encode(struct net_device *dev, | |
2171 | struct iw_request_info *info, | |
2172 | union iwreq_data *wrqu, | |
2173 | char *extra) | |
2174 | { | |
2175 | kio_addr_t base = dev->base_addr; | |
2176 | net_local *lp = netdev_priv(dev); | |
2177 | psa_t psa; | |
2178 | unsigned long flags; | |
2179 | int ret = 0; | |
2180 | ||
2181 | /* Disable interrupts and save flags. */ | |
2182 | spin_lock_irqsave(&lp->spinlock, flags); | |
2183 | ||
2184 | /* Check if encryption is available */ | |
2185 | if (!mmc_encr(base)) { | |
2186 | ret = -EOPNOTSUPP; | |
2187 | } else { | |
2188 | /* Read the encryption key */ | |
2189 | psa_read(dev, | |
2190 | (char *) &psa.psa_encryption_select - | |
2191 | (char *) &psa, | |
2192 | (unsigned char *) &psa. | |
2193 | psa_encryption_select, 1 + 8); | |
2194 | ||
2195 | /* encryption is enabled ? */ | |
2196 | if (psa.psa_encryption_select) | |
2197 | wrqu->encoding.flags = IW_ENCODE_ENABLED; | |
2198 | else | |
2199 | wrqu->encoding.flags = IW_ENCODE_DISABLED; | |
2200 | wrqu->encoding.flags |= mmc_encr(base); | |
2201 | ||
2202 | /* Copy the key to the user buffer */ | |
2203 | wrqu->encoding.length = 8; | |
2204 | memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length); | |
2205 | } | |
2206 | ||
2207 | /* Enable interrupts and restore flags. */ | |
2208 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2209 | ||
2210 | return ret; | |
2211 | } | |
2212 | ||
2213 | #ifdef WAVELAN_ROAMING_EXT | |
2214 | /*------------------------------------------------------------------*/ | |
2215 | /* | |
2216 | * Wireless Handler : set ESSID (domain) | |
2217 | */ | |
2218 | static int wavelan_set_essid(struct net_device *dev, | |
2219 | struct iw_request_info *info, | |
2220 | union iwreq_data *wrqu, | |
2221 | char *extra) | |
2222 | { | |
2223 | net_local *lp = netdev_priv(dev); | |
2224 | unsigned long flags; | |
2225 | int ret = 0; | |
2226 | ||
2227 | /* Disable interrupts and save flags. */ | |
2228 | spin_lock_irqsave(&lp->spinlock, flags); | |
2229 | ||
2230 | /* Check if disable */ | |
2231 | if(wrqu->data.flags == 0) | |
2232 | lp->filter_domains = 0; | |
2233 | else { | |
2234 | char essid[IW_ESSID_MAX_SIZE + 1]; | |
2235 | char * endp; | |
2236 | ||
2237 | /* Terminate the string */ | |
2238 | memcpy(essid, extra, wrqu->data.length); | |
2239 | essid[IW_ESSID_MAX_SIZE] = '\0'; | |
2240 | ||
2241 | #ifdef DEBUG_IOCTL_INFO | |
2242 | printk(KERN_DEBUG "SetEssid : ``%s''\n", essid); | |
2243 | #endif /* DEBUG_IOCTL_INFO */ | |
2244 | ||
2245 | /* Convert to a number (note : Wavelan specific) */ | |
2246 | lp->domain_id = simple_strtoul(essid, &endp, 16); | |
2247 | /* Has it worked ? */ | |
2248 | if(endp > essid) | |
2249 | lp->filter_domains = 1; | |
2250 | else { | |
2251 | lp->filter_domains = 0; | |
2252 | ret = -EINVAL; | |
2253 | } | |
2254 | } | |
2255 | ||
2256 | /* Enable interrupts and restore flags. */ | |
2257 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2258 | ||
2259 | return ret; | |
2260 | } | |
2261 | ||
2262 | /*------------------------------------------------------------------*/ | |
2263 | /* | |
2264 | * Wireless Handler : get ESSID (domain) | |
2265 | */ | |
2266 | static int wavelan_get_essid(struct net_device *dev, | |
2267 | struct iw_request_info *info, | |
2268 | union iwreq_data *wrqu, | |
2269 | char *extra) | |
2270 | { | |
2271 | net_local *lp = netdev_priv(dev); | |
2272 | ||
2273 | /* Is the domain ID active ? */ | |
2274 | wrqu->data.flags = lp->filter_domains; | |
2275 | ||
2276 | /* Copy Domain ID into a string (Wavelan specific) */ | |
2277 | /* Sound crazy, be we can't have a snprintf in the kernel !!! */ | |
2278 | sprintf(extra, "%lX", lp->domain_id); | |
2279 | extra[IW_ESSID_MAX_SIZE] = '\0'; | |
2280 | ||
2281 | /* Set the length */ | |
2282 | wrqu->data.length = strlen(extra) + 1; | |
2283 | ||
2284 | return 0; | |
2285 | } | |
2286 | ||
2287 | /*------------------------------------------------------------------*/ | |
2288 | /* | |
2289 | * Wireless Handler : set AP address | |
2290 | */ | |
2291 | static int wavelan_set_wap(struct net_device *dev, | |
2292 | struct iw_request_info *info, | |
2293 | union iwreq_data *wrqu, | |
2294 | char *extra) | |
2295 | { | |
2296 | #ifdef DEBUG_IOCTL_INFO | |
2297 | printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n", | |
2298 | wrqu->ap_addr.sa_data[0], | |
2299 | wrqu->ap_addr.sa_data[1], | |
2300 | wrqu->ap_addr.sa_data[2], | |
2301 | wrqu->ap_addr.sa_data[3], | |
2302 | wrqu->ap_addr.sa_data[4], | |
2303 | wrqu->ap_addr.sa_data[5]); | |
2304 | #endif /* DEBUG_IOCTL_INFO */ | |
2305 | ||
2306 | return -EOPNOTSUPP; | |
2307 | } | |
2308 | ||
2309 | /*------------------------------------------------------------------*/ | |
2310 | /* | |
2311 | * Wireless Handler : get AP address | |
2312 | */ | |
2313 | static int wavelan_get_wap(struct net_device *dev, | |
2314 | struct iw_request_info *info, | |
2315 | union iwreq_data *wrqu, | |
2316 | char *extra) | |
2317 | { | |
2318 | /* Should get the real McCoy instead of own Ethernet address */ | |
2319 | memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE); | |
2320 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; | |
2321 | ||
2322 | return -EOPNOTSUPP; | |
2323 | } | |
2324 | #endif /* WAVELAN_ROAMING_EXT */ | |
2325 | ||
2326 | #ifdef WAVELAN_ROAMING | |
2327 | /*------------------------------------------------------------------*/ | |
2328 | /* | |
2329 | * Wireless Handler : set mode | |
2330 | */ | |
2331 | static int wavelan_set_mode(struct net_device *dev, | |
2332 | struct iw_request_info *info, | |
2333 | union iwreq_data *wrqu, | |
2334 | char *extra) | |
2335 | { | |
2336 | net_local *lp = netdev_priv(dev); | |
2337 | unsigned long flags; | |
2338 | int ret = 0; | |
2339 | ||
2340 | /* Disable interrupts and save flags. */ | |
2341 | spin_lock_irqsave(&lp->spinlock, flags); | |
2342 | ||
2343 | /* Check mode */ | |
2344 | switch(wrqu->mode) { | |
2345 | case IW_MODE_ADHOC: | |
2346 | if(do_roaming) { | |
2347 | wv_roam_cleanup(dev); | |
2348 | do_roaming = 0; | |
2349 | } | |
2350 | break; | |
2351 | case IW_MODE_INFRA: | |
2352 | if(!do_roaming) { | |
2353 | wv_roam_init(dev); | |
2354 | do_roaming = 1; | |
2355 | } | |
2356 | break; | |
2357 | default: | |
2358 | ret = -EINVAL; | |
2359 | } | |
2360 | ||
2361 | /* Enable interrupts and restore flags. */ | |
2362 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2363 | ||
2364 | return ret; | |
2365 | } | |
2366 | ||
2367 | /*------------------------------------------------------------------*/ | |
2368 | /* | |
2369 | * Wireless Handler : get mode | |
2370 | */ | |
2371 | static int wavelan_get_mode(struct net_device *dev, | |
2372 | struct iw_request_info *info, | |
2373 | union iwreq_data *wrqu, | |
2374 | char *extra) | |
2375 | { | |
2376 | if(do_roaming) | |
2377 | wrqu->mode = IW_MODE_INFRA; | |
2378 | else | |
2379 | wrqu->mode = IW_MODE_ADHOC; | |
2380 | ||
2381 | return 0; | |
2382 | } | |
2383 | #endif /* WAVELAN_ROAMING */ | |
2384 | ||
2385 | /*------------------------------------------------------------------*/ | |
2386 | /* | |
2387 | * Wireless Handler : get range info | |
2388 | */ | |
2389 | static int wavelan_get_range(struct net_device *dev, | |
2390 | struct iw_request_info *info, | |
2391 | union iwreq_data *wrqu, | |
2392 | char *extra) | |
2393 | { | |
2394 | kio_addr_t base = dev->base_addr; | |
2395 | net_local *lp = netdev_priv(dev); | |
2396 | struct iw_range *range = (struct iw_range *) extra; | |
2397 | unsigned long flags; | |
2398 | int ret = 0; | |
2399 | ||
2400 | /* Set the length (very important for backward compatibility) */ | |
2401 | wrqu->data.length = sizeof(struct iw_range); | |
2402 | ||
2403 | /* Set all the info we don't care or don't know about to zero */ | |
2404 | memset(range, 0, sizeof(struct iw_range)); | |
2405 | ||
2406 | /* Set the Wireless Extension versions */ | |
2407 | range->we_version_compiled = WIRELESS_EXT; | |
2408 | range->we_version_source = 9; | |
2409 | ||
2410 | /* Set information in the range struct. */ | |
2411 | range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */ | |
2412 | range->min_nwid = 0x0000; | |
2413 | range->max_nwid = 0xFFFF; | |
2414 | ||
2415 | range->sensitivity = 0x3F; | |
2416 | range->max_qual.qual = MMR_SGNL_QUAL; | |
2417 | range->max_qual.level = MMR_SIGNAL_LVL; | |
2418 | range->max_qual.noise = MMR_SILENCE_LVL; | |
2419 | range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */ | |
2420 | /* Need to get better values for those two */ | |
2421 | range->avg_qual.level = 30; | |
2422 | range->avg_qual.noise = 8; | |
2423 | ||
2424 | range->num_bitrates = 1; | |
2425 | range->bitrate[0] = 2000000; /* 2 Mb/s */ | |
2426 | ||
2427 | /* Event capability (kernel + driver) */ | |
2428 | range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) | | |
2429 | IW_EVENT_CAPA_MASK(0x8B04) | | |
2430 | IW_EVENT_CAPA_MASK(0x8B06)); | |
2431 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | |
2432 | ||
2433 | /* Disable interrupts and save flags. */ | |
2434 | spin_lock_irqsave(&lp->spinlock, flags); | |
2435 | ||
2436 | /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */ | |
2437 | if (!(mmc_in(base, mmroff(0, mmr_fee_status)) & | |
2438 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) { | |
2439 | range->num_channels = 10; | |
2440 | range->num_frequency = wv_frequency_list(base, range->freq, | |
2441 | IW_MAX_FREQUENCIES); | |
2442 | } else | |
2443 | range->num_channels = range->num_frequency = 0; | |
2444 | ||
2445 | /* Encryption supported ? */ | |
2446 | if (mmc_encr(base)) { | |
2447 | range->encoding_size[0] = 8; /* DES = 64 bits key */ | |
2448 | range->num_encoding_sizes = 1; | |
2449 | range->max_encoding_tokens = 1; /* Only one key possible */ | |
2450 | } else { | |
2451 | range->num_encoding_sizes = 0; | |
2452 | range->max_encoding_tokens = 0; | |
2453 | } | |
2454 | ||
2455 | /* Enable interrupts and restore flags. */ | |
2456 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2457 | ||
2458 | return ret; | |
2459 | } | |
2460 | ||
2461 | /*------------------------------------------------------------------*/ | |
2462 | /* | |
2463 | * Wireless Private Handler : set quality threshold | |
2464 | */ | |
2465 | static int wavelan_set_qthr(struct net_device *dev, | |
2466 | struct iw_request_info *info, | |
2467 | union iwreq_data *wrqu, | |
2468 | char *extra) | |
2469 | { | |
2470 | kio_addr_t base = dev->base_addr; | |
2471 | net_local *lp = netdev_priv(dev); | |
2472 | psa_t psa; | |
2473 | unsigned long flags; | |
2474 | ||
2475 | /* Disable interrupts and save flags. */ | |
2476 | spin_lock_irqsave(&lp->spinlock, flags); | |
2477 | ||
2478 | psa.psa_quality_thr = *(extra) & 0x0F; | |
2479 | psa_write(dev, | |
2480 | (char *) &psa.psa_quality_thr - (char *) &psa, | |
2481 | (unsigned char *) &psa.psa_quality_thr, 1); | |
2482 | /* update the Wavelan checksum */ | |
2483 | update_psa_checksum(dev); | |
2484 | mmc_out(base, mmwoff(0, mmw_quality_thr), | |
2485 | psa.psa_quality_thr); | |
2486 | ||
2487 | /* Enable interrupts and restore flags. */ | |
2488 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2489 | ||
2490 | return 0; | |
2491 | } | |
2492 | ||
2493 | /*------------------------------------------------------------------*/ | |
2494 | /* | |
2495 | * Wireless Private Handler : get quality threshold | |
2496 | */ | |
2497 | static int wavelan_get_qthr(struct net_device *dev, | |
2498 | struct iw_request_info *info, | |
2499 | union iwreq_data *wrqu, | |
2500 | char *extra) | |
2501 | { | |
2502 | net_local *lp = netdev_priv(dev); | |
2503 | psa_t psa; | |
2504 | unsigned long flags; | |
2505 | ||
2506 | /* Disable interrupts and save flags. */ | |
2507 | spin_lock_irqsave(&lp->spinlock, flags); | |
2508 | ||
2509 | psa_read(dev, | |
2510 | (char *) &psa.psa_quality_thr - (char *) &psa, | |
2511 | (unsigned char *) &psa.psa_quality_thr, 1); | |
2512 | *(extra) = psa.psa_quality_thr & 0x0F; | |
2513 | ||
2514 | /* Enable interrupts and restore flags. */ | |
2515 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2516 | ||
2517 | return 0; | |
2518 | } | |
2519 | ||
2520 | #ifdef WAVELAN_ROAMING | |
2521 | /*------------------------------------------------------------------*/ | |
2522 | /* | |
2523 | * Wireless Private Handler : set roaming | |
2524 | */ | |
2525 | static int wavelan_set_roam(struct net_device *dev, | |
2526 | struct iw_request_info *info, | |
2527 | union iwreq_data *wrqu, | |
2528 | char *extra) | |
2529 | { | |
2530 | net_local *lp = netdev_priv(dev); | |
2531 | unsigned long flags; | |
2532 | ||
2533 | /* Disable interrupts and save flags. */ | |
2534 | spin_lock_irqsave(&lp->spinlock, flags); | |
2535 | ||
2536 | /* Note : should check if user == root */ | |
2537 | if(do_roaming && (*extra)==0) | |
2538 | wv_roam_cleanup(dev); | |
2539 | else if(do_roaming==0 && (*extra)!=0) | |
2540 | wv_roam_init(dev); | |
2541 | ||
2542 | do_roaming = (*extra); | |
2543 | ||
2544 | /* Enable interrupts and restore flags. */ | |
2545 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2546 | ||
2547 | return 0; | |
2548 | } | |
2549 | ||
2550 | /*------------------------------------------------------------------*/ | |
2551 | /* | |
2552 | * Wireless Private Handler : get quality threshold | |
2553 | */ | |
2554 | static int wavelan_get_roam(struct net_device *dev, | |
2555 | struct iw_request_info *info, | |
2556 | union iwreq_data *wrqu, | |
2557 | char *extra) | |
2558 | { | |
2559 | *(extra) = do_roaming; | |
2560 | ||
2561 | return 0; | |
2562 | } | |
2563 | #endif /* WAVELAN_ROAMING */ | |
2564 | ||
2565 | #ifdef HISTOGRAM | |
2566 | /*------------------------------------------------------------------*/ | |
2567 | /* | |
2568 | * Wireless Private Handler : set histogram | |
2569 | */ | |
2570 | static int wavelan_set_histo(struct net_device *dev, | |
2571 | struct iw_request_info *info, | |
2572 | union iwreq_data *wrqu, | |
2573 | char *extra) | |
2574 | { | |
2575 | net_local *lp = netdev_priv(dev); | |
2576 | ||
2577 | /* Check the number of intervals. */ | |
2578 | if (wrqu->data.length > 16) { | |
2579 | return(-E2BIG); | |
2580 | } | |
2581 | ||
2582 | /* Disable histo while we copy the addresses. | |
2583 | * As we don't disable interrupts, we need to do this */ | |
2584 | lp->his_number = 0; | |
2585 | ||
2586 | /* Are there ranges to copy? */ | |
2587 | if (wrqu->data.length > 0) { | |
2588 | /* Copy interval ranges to the driver */ | |
2589 | memcpy(lp->his_range, extra, wrqu->data.length); | |
2590 | ||
2591 | { | |
2592 | int i; | |
2593 | printk(KERN_DEBUG "Histo :"); | |
2594 | for(i = 0; i < wrqu->data.length; i++) | |
2595 | printk(" %d", lp->his_range[i]); | |
2596 | printk("\n"); | |
2597 | } | |
2598 | ||
2599 | /* Reset result structure. */ | |
2600 | memset(lp->his_sum, 0x00, sizeof(long) * 16); | |
2601 | } | |
2602 | ||
2603 | /* Now we can set the number of ranges */ | |
2604 | lp->his_number = wrqu->data.length; | |
2605 | ||
2606 | return(0); | |
2607 | } | |
2608 | ||
2609 | /*------------------------------------------------------------------*/ | |
2610 | /* | |
2611 | * Wireless Private Handler : get histogram | |
2612 | */ | |
2613 | static int wavelan_get_histo(struct net_device *dev, | |
2614 | struct iw_request_info *info, | |
2615 | union iwreq_data *wrqu, | |
2616 | char *extra) | |
2617 | { | |
2618 | net_local *lp = netdev_priv(dev); | |
2619 | ||
2620 | /* Set the number of intervals. */ | |
2621 | wrqu->data.length = lp->his_number; | |
2622 | ||
2623 | /* Give back the distribution statistics */ | |
2624 | if(lp->his_number > 0) | |
2625 | memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number); | |
2626 | ||
2627 | return(0); | |
2628 | } | |
2629 | #endif /* HISTOGRAM */ | |
2630 | ||
2631 | /*------------------------------------------------------------------*/ | |
2632 | /* | |
2633 | * Structures to export the Wireless Handlers | |
2634 | */ | |
2635 | ||
2636 | static const struct iw_priv_args wavelan_private_args[] = { | |
2637 | /*{ cmd, set_args, get_args, name } */ | |
2638 | { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" }, | |
2639 | { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" }, | |
2640 | { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" }, | |
2641 | { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" }, | |
2642 | { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" }, | |
2643 | { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" }, | |
2644 | }; | |
2645 | ||
2646 | static const iw_handler wavelan_handler[] = | |
2647 | { | |
2648 | NULL, /* SIOCSIWNAME */ | |
2649 | wavelan_get_name, /* SIOCGIWNAME */ | |
2650 | wavelan_set_nwid, /* SIOCSIWNWID */ | |
2651 | wavelan_get_nwid, /* SIOCGIWNWID */ | |
2652 | wavelan_set_freq, /* SIOCSIWFREQ */ | |
2653 | wavelan_get_freq, /* SIOCGIWFREQ */ | |
2654 | #ifdef WAVELAN_ROAMING | |
2655 | wavelan_set_mode, /* SIOCSIWMODE */ | |
2656 | wavelan_get_mode, /* SIOCGIWMODE */ | |
2657 | #else /* WAVELAN_ROAMING */ | |
2658 | NULL, /* SIOCSIWMODE */ | |
2659 | NULL, /* SIOCGIWMODE */ | |
2660 | #endif /* WAVELAN_ROAMING */ | |
2661 | wavelan_set_sens, /* SIOCSIWSENS */ | |
2662 | wavelan_get_sens, /* SIOCGIWSENS */ | |
2663 | NULL, /* SIOCSIWRANGE */ | |
2664 | wavelan_get_range, /* SIOCGIWRANGE */ | |
2665 | NULL, /* SIOCSIWPRIV */ | |
2666 | NULL, /* SIOCGIWPRIV */ | |
2667 | NULL, /* SIOCSIWSTATS */ | |
2668 | NULL, /* SIOCGIWSTATS */ | |
2669 | iw_handler_set_spy, /* SIOCSIWSPY */ | |
2670 | iw_handler_get_spy, /* SIOCGIWSPY */ | |
2671 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ | |
2672 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ | |
2673 | #ifdef WAVELAN_ROAMING_EXT | |
2674 | wavelan_set_wap, /* SIOCSIWAP */ | |
2675 | wavelan_get_wap, /* SIOCGIWAP */ | |
2676 | NULL, /* -- hole -- */ | |
2677 | NULL, /* SIOCGIWAPLIST */ | |
2678 | NULL, /* -- hole -- */ | |
2679 | NULL, /* -- hole -- */ | |
2680 | wavelan_set_essid, /* SIOCSIWESSID */ | |
2681 | wavelan_get_essid, /* SIOCGIWESSID */ | |
2682 | #else /* WAVELAN_ROAMING_EXT */ | |
2683 | NULL, /* SIOCSIWAP */ | |
2684 | NULL, /* SIOCGIWAP */ | |
2685 | NULL, /* -- hole -- */ | |
2686 | NULL, /* SIOCGIWAPLIST */ | |
2687 | NULL, /* -- hole -- */ | |
2688 | NULL, /* -- hole -- */ | |
2689 | NULL, /* SIOCSIWESSID */ | |
2690 | NULL, /* SIOCGIWESSID */ | |
2691 | #endif /* WAVELAN_ROAMING_EXT */ | |
2692 | NULL, /* SIOCSIWNICKN */ | |
2693 | NULL, /* SIOCGIWNICKN */ | |
2694 | NULL, /* -- hole -- */ | |
2695 | NULL, /* -- hole -- */ | |
2696 | NULL, /* SIOCSIWRATE */ | |
2697 | NULL, /* SIOCGIWRATE */ | |
2698 | NULL, /* SIOCSIWRTS */ | |
2699 | NULL, /* SIOCGIWRTS */ | |
2700 | NULL, /* SIOCSIWFRAG */ | |
2701 | NULL, /* SIOCGIWFRAG */ | |
2702 | NULL, /* SIOCSIWTXPOW */ | |
2703 | NULL, /* SIOCGIWTXPOW */ | |
2704 | NULL, /* SIOCSIWRETRY */ | |
2705 | NULL, /* SIOCGIWRETRY */ | |
2706 | wavelan_set_encode, /* SIOCSIWENCODE */ | |
2707 | wavelan_get_encode, /* SIOCGIWENCODE */ | |
2708 | }; | |
2709 | ||
2710 | static const iw_handler wavelan_private_handler[] = | |
2711 | { | |
2712 | wavelan_set_qthr, /* SIOCIWFIRSTPRIV */ | |
2713 | wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */ | |
2714 | #ifdef WAVELAN_ROAMING | |
2715 | wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */ | |
2716 | wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */ | |
2717 | #else /* WAVELAN_ROAMING */ | |
2718 | NULL, /* SIOCIWFIRSTPRIV + 2 */ | |
2719 | NULL, /* SIOCIWFIRSTPRIV + 3 */ | |
2720 | #endif /* WAVELAN_ROAMING */ | |
2721 | #ifdef HISTOGRAM | |
2722 | wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */ | |
2723 | wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */ | |
2724 | #endif /* HISTOGRAM */ | |
2725 | }; | |
2726 | ||
2727 | static const struct iw_handler_def wavelan_handler_def = | |
2728 | { | |
2729 | .num_standard = sizeof(wavelan_handler)/sizeof(iw_handler), | |
2730 | .num_private = sizeof(wavelan_private_handler)/sizeof(iw_handler), | |
2731 | .num_private_args = sizeof(wavelan_private_args)/sizeof(struct iw_priv_args), | |
2732 | .standard = wavelan_handler, | |
2733 | .private = wavelan_private_handler, | |
2734 | .private_args = wavelan_private_args, | |
2735 | .get_wireless_stats = wavelan_get_wireless_stats, | |
2736 | }; | |
2737 | ||
2738 | /*------------------------------------------------------------------*/ | |
2739 | /* | |
2740 | * Get wireless statistics | |
2741 | * Called by /proc/net/wireless... | |
2742 | */ | |
2743 | static iw_stats * | |
2744 | wavelan_get_wireless_stats(struct net_device * dev) | |
2745 | { | |
2746 | kio_addr_t base = dev->base_addr; | |
2747 | net_local * lp = netdev_priv(dev); | |
2748 | mmr_t m; | |
2749 | iw_stats * wstats; | |
2750 | unsigned long flags; | |
2751 | ||
2752 | #ifdef DEBUG_IOCTL_TRACE | |
2753 | printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name); | |
2754 | #endif | |
2755 | ||
2756 | /* Disable interrupts & save flags */ | |
2757 | spin_lock_irqsave(&lp->spinlock, flags); | |
2758 | ||
2759 | wstats = &lp->wstats; | |
2760 | ||
2761 | /* Get data from the mmc */ | |
2762 | mmc_out(base, mmwoff(0, mmw_freeze), 1); | |
2763 | ||
2764 | mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1); | |
2765 | mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2); | |
2766 | mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4); | |
2767 | ||
2768 | mmc_out(base, mmwoff(0, mmw_freeze), 0); | |
2769 | ||
2770 | /* Copy data to wireless stuff */ | |
2771 | wstats->status = m.mmr_dce_status & MMR_DCE_STATUS; | |
2772 | wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL; | |
2773 | wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL; | |
2774 | wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL; | |
2775 | wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) | | |
2776 | ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) | | |
2777 | ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5)); | |
2778 | wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l; | |
2779 | wstats->discard.code = 0L; | |
2780 | wstats->discard.misc = 0L; | |
2781 | ||
2782 | /* ReEnable interrupts & restore flags */ | |
2783 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
2784 | ||
2785 | #ifdef DEBUG_IOCTL_TRACE | |
2786 | printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name); | |
2787 | #endif | |
2788 | return &lp->wstats; | |
2789 | } | |
2790 | #endif /* WIRELESS_EXT */ | |
2791 | ||
2792 | /************************* PACKET RECEPTION *************************/ | |
2793 | /* | |
2794 | * This part deal with receiving the packets. | |
2795 | * The interrupt handler get an interrupt when a packet has been | |
2796 | * successfully received and called this part... | |
2797 | */ | |
2798 | ||
2799 | /*------------------------------------------------------------------*/ | |
2800 | /* | |
2801 | * Calculate the starting address of the frame pointed to by the receive | |
2802 | * frame pointer and verify that the frame seem correct | |
2803 | * (called by wv_packet_rcv()) | |
2804 | */ | |
2805 | static inline int | |
2806 | wv_start_of_frame(struct net_device * dev, | |
2807 | int rfp, /* end of frame */ | |
2808 | int wrap) /* start of buffer */ | |
2809 | { | |
2810 | kio_addr_t base = dev->base_addr; | |
2811 | int rp; | |
2812 | int len; | |
2813 | ||
2814 | rp = (rfp - 5 + RX_SIZE) % RX_SIZE; | |
2815 | outb(rp & 0xff, PIORL(base)); | |
2816 | outb(((rp >> 8) & PIORH_MASK), PIORH(base)); | |
2817 | len = inb(PIOP(base)); | |
2818 | len |= inb(PIOP(base)) << 8; | |
2819 | ||
2820 | /* Sanity checks on size */ | |
2821 | /* Frame too big */ | |
2822 | if(len > MAXDATAZ + 100) | |
2823 | { | |
2824 | #ifdef DEBUG_RX_ERROR | |
2825 | printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n", | |
2826 | dev->name, rfp, len); | |
2827 | #endif | |
2828 | return(-1); | |
2829 | } | |
2830 | ||
2831 | /* Frame too short */ | |
2832 | if(len < 7) | |
2833 | { | |
2834 | #ifdef DEBUG_RX_ERROR | |
2835 | printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n", | |
2836 | dev->name, rfp, len); | |
2837 | #endif | |
2838 | return(-1); | |
2839 | } | |
2840 | ||
2841 | /* Wrap around buffer */ | |
2842 | if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */ | |
2843 | { | |
2844 | #ifdef DEBUG_RX_ERROR | |
2845 | printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n", | |
2846 | dev->name, wrap, rfp, len); | |
2847 | #endif | |
2848 | return(-1); | |
2849 | } | |
2850 | ||
2851 | return((rp - len + RX_SIZE) % RX_SIZE); | |
2852 | } /* wv_start_of_frame */ | |
2853 | ||
2854 | /*------------------------------------------------------------------*/ | |
2855 | /* | |
2856 | * This routine does the actual copy of data (including the ethernet | |
2857 | * header structure) from the WaveLAN card to an sk_buff chain that | |
2858 | * will be passed up to the network interface layer. NOTE: We | |
2859 | * currently don't handle trailer protocols (neither does the rest of | |
2860 | * the network interface), so if that is needed, it will (at least in | |
2861 | * part) be added here. The contents of the receive ring buffer are | |
2862 | * copied to a message chain that is then passed to the kernel. | |
2863 | * | |
2864 | * Note: if any errors occur, the packet is "dropped on the floor" | |
2865 | * (called by wv_packet_rcv()) | |
2866 | */ | |
2867 | static inline void | |
2868 | wv_packet_read(struct net_device * dev, | |
2869 | int fd_p, | |
2870 | int sksize) | |
2871 | { | |
2872 | net_local * lp = netdev_priv(dev); | |
2873 | struct sk_buff * skb; | |
2874 | ||
2875 | #ifdef DEBUG_RX_TRACE | |
2876 | printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n", | |
2877 | dev->name, fd_p, sksize); | |
2878 | #endif | |
2879 | ||
2880 | /* Allocate some buffer for the new packet */ | |
2881 | if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL) | |
2882 | { | |
2883 | #ifdef DEBUG_RX_ERROR | |
2884 | printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n", | |
2885 | dev->name, sksize); | |
2886 | #endif | |
2887 | lp->stats.rx_dropped++; | |
2888 | /* | |
2889 | * Not only do we want to return here, but we also need to drop the | |
2890 | * packet on the floor to clear the interrupt. | |
2891 | */ | |
2892 | return; | |
2893 | } | |
2894 | ||
2895 | skb->dev = dev; | |
2896 | ||
2897 | skb_reserve(skb, 2); | |
2898 | fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize); | |
2899 | skb->protocol = eth_type_trans(skb, dev); | |
2900 | ||
2901 | #ifdef DEBUG_RX_INFO | |
2902 | wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read"); | |
2903 | #endif /* DEBUG_RX_INFO */ | |
2904 | ||
2905 | /* Statistics gathering & stuff associated. | |
2906 | * It seem a bit messy with all the define, but it's really simple... */ | |
2907 | if( | |
2908 | #ifdef IW_WIRELESS_SPY | |
2909 | (lp->spy_data.spy_number > 0) || | |
2910 | #endif /* IW_WIRELESS_SPY */ | |
2911 | #ifdef HISTOGRAM | |
2912 | (lp->his_number > 0) || | |
2913 | #endif /* HISTOGRAM */ | |
2914 | #ifdef WAVELAN_ROAMING | |
2915 | (do_roaming) || | |
2916 | #endif /* WAVELAN_ROAMING */ | |
2917 | 0) | |
2918 | { | |
2919 | u_char stats[3]; /* Signal level, Noise level, Signal quality */ | |
2920 | ||
2921 | /* read signal level, silence level and signal quality bytes */ | |
2922 | fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE, | |
2923 | stats, 3); | |
2924 | #ifdef DEBUG_RX_INFO | |
2925 | printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n", | |
2926 | dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F); | |
2927 | #endif | |
2928 | ||
2929 | #ifdef WAVELAN_ROAMING | |
2930 | if(do_roaming) | |
2931 | if(WAVELAN_BEACON(skb->data)) | |
2932 | wl_roam_gather(dev, skb->data, stats); | |
2933 | #endif /* WAVELAN_ROAMING */ | |
2934 | ||
2935 | #ifdef WIRELESS_SPY | |
2936 | wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats); | |
2937 | #endif /* WIRELESS_SPY */ | |
2938 | #ifdef HISTOGRAM | |
2939 | wl_his_gather(dev, stats); | |
2940 | #endif /* HISTOGRAM */ | |
2941 | } | |
2942 | ||
2943 | /* | |
2944 | * Hand the packet to the Network Module | |
2945 | */ | |
2946 | netif_rx(skb); | |
2947 | ||
2948 | /* Keep stats up to date */ | |
2949 | dev->last_rx = jiffies; | |
2950 | lp->stats.rx_packets++; | |
2951 | lp->stats.rx_bytes += sksize; | |
2952 | ||
2953 | #ifdef DEBUG_RX_TRACE | |
2954 | printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name); | |
2955 | #endif | |
2956 | return; | |
2957 | } | |
2958 | ||
2959 | /*------------------------------------------------------------------*/ | |
2960 | /* | |
2961 | * This routine is called by the interrupt handler to initiate a | |
2962 | * packet transfer from the card to the network interface layer above | |
2963 | * this driver. This routine checks if a buffer has been successfully | |
2964 | * received by the WaveLAN card. If so, the routine wv_packet_read is | |
2965 | * called to do the actual transfer of the card's data including the | |
2966 | * ethernet header into a packet consisting of an sk_buff chain. | |
2967 | * (called by wavelan_interrupt()) | |
2968 | * Note : the spinlock is already grabbed for us and irq are disabled. | |
2969 | */ | |
2970 | static inline void | |
2971 | wv_packet_rcv(struct net_device * dev) | |
2972 | { | |
2973 | kio_addr_t base = dev->base_addr; | |
2974 | net_local * lp = netdev_priv(dev); | |
2975 | int newrfp; | |
2976 | int rp; | |
2977 | int len; | |
2978 | int f_start; | |
2979 | int status; | |
2980 | int i593_rfp; | |
2981 | int stat_ptr; | |
2982 | u_char c[4]; | |
2983 | ||
2984 | #ifdef DEBUG_RX_TRACE | |
2985 | printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name); | |
2986 | #endif | |
2987 | ||
2988 | /* Get the new receive frame pointer from the i82593 chip */ | |
2989 | outb(CR0_STATUS_2 | OP0_NOP, LCCR(base)); | |
2990 | i593_rfp = inb(LCSR(base)); | |
2991 | i593_rfp |= inb(LCSR(base)) << 8; | |
2992 | i593_rfp %= RX_SIZE; | |
2993 | ||
2994 | /* Get the new receive frame pointer from the WaveLAN card. | |
2995 | * It is 3 bytes more than the increment of the i82593 receive | |
2996 | * frame pointer, for each packet. This is because it includes the | |
2997 | * 3 roaming bytes added by the mmc. | |
2998 | */ | |
2999 | newrfp = inb(RPLL(base)); | |
3000 | newrfp |= inb(RPLH(base)) << 8; | |
3001 | newrfp %= RX_SIZE; | |
3002 | ||
3003 | #ifdef DEBUG_RX_INFO | |
3004 | printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n", | |
3005 | dev->name, i593_rfp, lp->stop, newrfp, lp->rfp); | |
3006 | #endif | |
3007 | ||
3008 | #ifdef DEBUG_RX_ERROR | |
3009 | /* If no new frame pointer... */ | |
3010 | if(lp->overrunning || newrfp == lp->rfp) | |
3011 | printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n", | |
3012 | dev->name, i593_rfp, lp->stop, newrfp, lp->rfp); | |
3013 | #endif | |
3014 | ||
3015 | /* Read all frames (packets) received */ | |
3016 | while(newrfp != lp->rfp) | |
3017 | { | |
3018 | /* A frame is composed of the packet, followed by a status word, | |
3019 | * the length of the frame (word) and the mmc info (SNR & qual). | |
3020 | * It's because the length is at the end that we can only scan | |
3021 | * frames backward. */ | |
3022 | ||
3023 | /* Find the first frame by skipping backwards over the frames */ | |
3024 | rp = newrfp; /* End of last frame */ | |
3025 | while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) && | |
3026 | (f_start != -1)) | |
3027 | rp = f_start; | |
3028 | ||
3029 | /* If we had a problem */ | |
3030 | if(f_start == -1) | |
3031 | { | |
3032 | #ifdef DEBUG_RX_ERROR | |
3033 | printk(KERN_INFO "wavelan_cs: cannot find start of frame "); | |
3034 | printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n", | |
3035 | i593_rfp, lp->stop, newrfp, lp->rfp); | |
3036 | #endif | |
3037 | lp->rfp = rp; /* Get to the last usable frame */ | |
3038 | continue; | |
3039 | } | |
3040 | ||
3041 | /* f_start point to the beggining of the first frame received | |
3042 | * and rp to the beggining of the next one */ | |
3043 | ||
3044 | /* Read status & length of the frame */ | |
3045 | stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE; | |
3046 | stat_ptr = read_ringbuf(dev, stat_ptr, c, 4); | |
3047 | status = c[0] | (c[1] << 8); | |
3048 | len = c[2] | (c[3] << 8); | |
3049 | ||
3050 | /* Check status */ | |
3051 | if((status & RX_RCV_OK) != RX_RCV_OK) | |
3052 | { | |
3053 | lp->stats.rx_errors++; | |
3054 | if(status & RX_NO_SFD) | |
3055 | lp->stats.rx_frame_errors++; | |
3056 | if(status & RX_CRC_ERR) | |
3057 | lp->stats.rx_crc_errors++; | |
3058 | if(status & RX_OVRRUN) | |
3059 | lp->stats.rx_over_errors++; | |
3060 | ||
3061 | #ifdef DEBUG_RX_FAIL | |
3062 | printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n", | |
3063 | dev->name, status); | |
3064 | #endif | |
3065 | } | |
3066 | else | |
3067 | /* Read the packet and transmit to Linux */ | |
3068 | wv_packet_read(dev, f_start, len - 2); | |
3069 | ||
3070 | /* One frame has been processed, skip it */ | |
3071 | lp->rfp = rp; | |
3072 | } | |
3073 | ||
3074 | /* | |
3075 | * Update the frame stop register, but set it to less than | |
3076 | * the full 8K to allow space for 3 bytes of signal strength | |
3077 | * per packet. | |
3078 | */ | |
3079 | lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE; | |
3080 | outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base)); | |
3081 | outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base)); | |
3082 | outb(OP1_SWIT_TO_PORT_0, LCCR(base)); | |
3083 | ||
3084 | #ifdef DEBUG_RX_TRACE | |
3085 | printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name); | |
3086 | #endif | |
3087 | } | |
3088 | ||
3089 | /*********************** PACKET TRANSMISSION ***********************/ | |
3090 | /* | |
3091 | * This part deal with sending packet through the wavelan | |
3092 | * We copy the packet to the send buffer and then issue the send | |
3093 | * command to the i82593. The result of this operation will be | |
3094 | * checked in wavelan_interrupt() | |
3095 | */ | |
3096 | ||
3097 | /*------------------------------------------------------------------*/ | |
3098 | /* | |
3099 | * This routine fills in the appropriate registers and memory | |
3100 | * locations on the WaveLAN card and starts the card off on | |
3101 | * the transmit. | |
3102 | * (called in wavelan_packet_xmit()) | |
3103 | */ | |
3104 | static inline void | |
3105 | wv_packet_write(struct net_device * dev, | |
3106 | void * buf, | |
3107 | short length) | |
3108 | { | |
3109 | net_local * lp = netdev_priv(dev); | |
3110 | kio_addr_t base = dev->base_addr; | |
3111 | unsigned long flags; | |
3112 | int clen = length; | |
3113 | register u_short xmtdata_base = TX_BASE; | |
3114 | ||
3115 | #ifdef DEBUG_TX_TRACE | |
3116 | printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length); | |
3117 | #endif | |
3118 | ||
3119 | spin_lock_irqsave(&lp->spinlock, flags); | |
3120 | ||
3121 | /* Write the length of data buffer followed by the buffer */ | |
3122 | outb(xmtdata_base & 0xff, PIORL(base)); | |
3123 | outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base)); | |
3124 | outb(clen & 0xff, PIOP(base)); /* lsb */ | |
3125 | outb(clen >> 8, PIOP(base)); /* msb */ | |
3126 | ||
3127 | /* Send the data */ | |
3128 | outsb(PIOP(base), buf, clen); | |
3129 | ||
3130 | /* Indicate end of transmit chain */ | |
3131 | outb(OP0_NOP, PIOP(base)); | |
3132 | /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */ | |
3133 | outb(OP0_NOP, PIOP(base)); | |
3134 | ||
3135 | /* Reset the transmit DMA pointer */ | |
3136 | hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET); | |
3137 | hacr_write(base, HACR_DEFAULT); | |
3138 | /* Send the transmit command */ | |
3139 | wv_82593_cmd(dev, "wv_packet_write(): transmit", | |
3140 | OP0_TRANSMIT, SR0_NO_RESULT); | |
3141 | ||
3142 | /* Make sure the watchdog will keep quiet for a while */ | |
3143 | dev->trans_start = jiffies; | |
3144 | ||
3145 | /* Keep stats up to date */ | |
3146 | lp->stats.tx_bytes += length; | |
3147 | ||
3148 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
3149 | ||
3150 | #ifdef DEBUG_TX_INFO | |
3151 | wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write"); | |
3152 | #endif /* DEBUG_TX_INFO */ | |
3153 | ||
3154 | #ifdef DEBUG_TX_TRACE | |
3155 | printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name); | |
3156 | #endif | |
3157 | } | |
3158 | ||
3159 | /*------------------------------------------------------------------*/ | |
3160 | /* | |
3161 | * This routine is called when we want to send a packet (NET3 callback) | |
3162 | * In this routine, we check if the harware is ready to accept | |
3163 | * the packet. We also prevent reentrance. Then, we call the function | |
3164 | * to send the packet... | |
3165 | */ | |
3166 | static int | |
3167 | wavelan_packet_xmit(struct sk_buff * skb, | |
3168 | struct net_device * dev) | |
3169 | { | |
3170 | net_local * lp = netdev_priv(dev); | |
3171 | unsigned long flags; | |
3172 | ||
3173 | #ifdef DEBUG_TX_TRACE | |
3174 | printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name, | |
3175 | (unsigned) skb); | |
3176 | #endif | |
3177 | ||
3178 | /* | |
3179 | * Block a timer-based transmit from overlapping a previous transmit. | |
3180 | * In other words, prevent reentering this routine. | |
3181 | */ | |
3182 | netif_stop_queue(dev); | |
3183 | ||
3184 | /* If somebody has asked to reconfigure the controller, | |
3185 | * we can do it now */ | |
3186 | if(lp->reconfig_82593) | |
3187 | { | |
3188 | spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */ | |
3189 | wv_82593_config(dev); | |
3190 | spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */ | |
3191 | /* Note : the configure procedure was totally synchronous, | |
3192 | * so the Tx buffer is now free */ | |
3193 | } | |
3194 | ||
3195 | #ifdef DEBUG_TX_ERROR | |
3196 | if (skb->next) | |
3197 | printk(KERN_INFO "skb has next\n"); | |
3198 | #endif | |
3199 | ||
3200 | /* Check if we need some padding */ | |
3201 | /* Note : on wireless the propagation time is in the order of 1us, | |
3202 | * and we don't have the Ethernet specific requirement of beeing | |
3203 | * able to detect collisions, therefore in theory we don't really | |
3204 | * need to pad. Jean II */ | |
3205 | if (skb->len < ETH_ZLEN) { | |
3206 | skb = skb_padto(skb, ETH_ZLEN); | |
3207 | if (skb == NULL) | |
3208 | return 0; | |
3209 | } | |
3210 | ||
3211 | wv_packet_write(dev, skb->data, skb->len); | |
3212 | ||
3213 | dev_kfree_skb(skb); | |
3214 | ||
3215 | #ifdef DEBUG_TX_TRACE | |
3216 | printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name); | |
3217 | #endif | |
3218 | return(0); | |
3219 | } | |
3220 | ||
3221 | /********************** HARDWARE CONFIGURATION **********************/ | |
3222 | /* | |
3223 | * This part do the real job of starting and configuring the hardware. | |
3224 | */ | |
3225 | ||
3226 | /*------------------------------------------------------------------*/ | |
3227 | /* | |
3228 | * Routine to initialize the Modem Management Controller. | |
3229 | * (called by wv_hw_config()) | |
3230 | */ | |
3231 | static inline int | |
3232 | wv_mmc_init(struct net_device * dev) | |
3233 | { | |
3234 | kio_addr_t base = dev->base_addr; | |
3235 | psa_t psa; | |
3236 | mmw_t m; | |
3237 | int configured; | |
3238 | int i; /* Loop counter */ | |
3239 | ||
3240 | #ifdef DEBUG_CONFIG_TRACE | |
3241 | printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name); | |
3242 | #endif | |
3243 | ||
3244 | /* Read the parameter storage area */ | |
3245 | psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa)); | |
3246 | ||
3247 | /* | |
3248 | * Check the first three octets of the MAC addr for the manufacturer's code. | |
3249 | * Note: If you get the error message below, you've got a | |
3250 | * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on | |
3251 | * how to configure your card... | |
3252 | */ | |
3253 | for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++) | |
3254 | if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) && | |
3255 | (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) && | |
3256 | (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2])) | |
3257 | break; | |
3258 | ||
3259 | /* If we have not found it... */ | |
3260 | if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3)) | |
3261 | { | |
3262 | #ifdef DEBUG_CONFIG_ERRORS | |
3263 | printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n", | |
3264 | dev->name, psa.psa_univ_mac_addr[0], | |
3265 | psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]); | |
3266 | #endif | |
3267 | return FALSE; | |
3268 | } | |
3269 | ||
3270 | /* Get the MAC address */ | |
3271 | memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE); | |
3272 | ||
3273 | #ifdef USE_PSA_CONFIG | |
3274 | configured = psa.psa_conf_status & 1; | |
3275 | #else | |
3276 | configured = 0; | |
3277 | #endif | |
3278 | ||
3279 | /* Is the PSA is not configured */ | |
3280 | if(!configured) | |
3281 | { | |
3282 | /* User will be able to configure NWID after (with iwconfig) */ | |
3283 | psa.psa_nwid[0] = 0; | |
3284 | psa.psa_nwid[1] = 0; | |
3285 | ||
3286 | /* As NWID is not set : no NWID checking */ | |
3287 | psa.psa_nwid_select = 0; | |
3288 | ||
3289 | /* Disable encryption */ | |
3290 | psa.psa_encryption_select = 0; | |
3291 | ||
3292 | /* Set to standard values | |
3293 | * 0x04 for AT, | |
3294 | * 0x01 for MCA, | |
3295 | * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document) | |
3296 | */ | |
3297 | if (psa.psa_comp_number & 1) | |
3298 | psa.psa_thr_pre_set = 0x01; | |
3299 | else | |
3300 | psa.psa_thr_pre_set = 0x04; | |
3301 | psa.psa_quality_thr = 0x03; | |
3302 | ||
3303 | /* It is configured */ | |
3304 | psa.psa_conf_status |= 1; | |
3305 | ||
3306 | #ifdef USE_PSA_CONFIG | |
3307 | /* Write the psa */ | |
3308 | psa_write(dev, (char *)psa.psa_nwid - (char *)&psa, | |
3309 | (unsigned char *)psa.psa_nwid, 4); | |
3310 | psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa, | |
3311 | (unsigned char *)&psa.psa_thr_pre_set, 1); | |
3312 | psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa, | |
3313 | (unsigned char *)&psa.psa_quality_thr, 1); | |
3314 | psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa, | |
3315 | (unsigned char *)&psa.psa_conf_status, 1); | |
3316 | /* update the Wavelan checksum */ | |
3317 | update_psa_checksum(dev); | |
3318 | #endif /* USE_PSA_CONFIG */ | |
3319 | } | |
3320 | ||
3321 | /* Zero the mmc structure */ | |
3322 | memset(&m, 0x00, sizeof(m)); | |
3323 | ||
3324 | /* Copy PSA info to the mmc */ | |
3325 | m.mmw_netw_id_l = psa.psa_nwid[1]; | |
3326 | m.mmw_netw_id_h = psa.psa_nwid[0]; | |
3327 | ||
3328 | if(psa.psa_nwid_select & 1) | |
3329 | m.mmw_loopt_sel = 0x00; | |
3330 | else | |
3331 | m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID; | |
3332 | ||
3333 | memcpy(&m.mmw_encr_key, &psa.psa_encryption_key, | |
3334 | sizeof(m.mmw_encr_key)); | |
3335 | ||
3336 | if(psa.psa_encryption_select) | |
3337 | m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE; | |
3338 | else | |
3339 | m.mmw_encr_enable = 0; | |
3340 | ||
3341 | m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F; | |
3342 | m.mmw_quality_thr = psa.psa_quality_thr & 0x0F; | |
3343 | ||
3344 | /* | |
3345 | * Set default modem control parameters. | |
3346 | * See NCR document 407-0024326 Rev. A. | |
3347 | */ | |
3348 | m.mmw_jabber_enable = 0x01; | |
3349 | m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN; | |
3350 | m.mmw_ifs = 0x20; | |
3351 | m.mmw_mod_delay = 0x04; | |
3352 | m.mmw_jam_time = 0x38; | |
3353 | ||
3354 | m.mmw_des_io_invert = 0; | |
3355 | m.mmw_freeze = 0; | |
3356 | m.mmw_decay_prm = 0; | |
3357 | m.mmw_decay_updat_prm = 0; | |
3358 | ||
3359 | /* Write all info to mmc */ | |
3360 | mmc_write(base, 0, (u_char *)&m, sizeof(m)); | |
3361 | ||
3362 | /* The following code start the modem of the 2.00 frequency | |
3363 | * selectable cards at power on. It's not strictly needed for the | |
3364 | * following boots... | |
3365 | * The original patch was by Joe Finney for the PCMCIA driver, but | |
3366 | * I've cleaned it a bit and add documentation. | |
3367 | * Thanks to Loeke Brederveld from Lucent for the info. | |
3368 | */ | |
3369 | ||
3370 | /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable) | |
3371 | * (does it work for everybody ? - especially old cards...) */ | |
3372 | /* Note : WFREQSEL verify that it is able to read from EEprom | |
3373 | * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID | |
3374 | * is 0xA (Xilinx version) or 0xB (Ariadne version). | |
3375 | * My test is more crude but do work... */ | |
3376 | if(!(mmc_in(base, mmroff(0, mmr_fee_status)) & | |
3377 | (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) | |
3378 | { | |
3379 | /* We must download the frequency parameters to the | |
3380 | * synthetisers (from the EEprom - area 1) | |
3381 | * Note : as the EEprom is auto decremented, we set the end | |
3382 | * if the area... */ | |
3383 | m.mmw_fee_addr = 0x0F; | |
3384 | m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD; | |
3385 | mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m, | |
3386 | (unsigned char *)&m.mmw_fee_ctrl, 2); | |
3387 | ||
3388 | /* Wait until the download is finished */ | |
3389 | fee_wait(base, 100, 100); | |
3390 | ||
3391 | #ifdef DEBUG_CONFIG_INFO | |
3392 | /* The frequency was in the last word downloaded... */ | |
3393 | mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m, | |
3394 | (unsigned char *)&m.mmw_fee_data_l, 2); | |
3395 | ||
3396 | /* Print some info for the user */ | |
3397 | printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n", | |
3398 | dev->name, | |
3399 | ((m.mmw_fee_data_h << 4) | | |
3400 | (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L); | |
3401 | #endif | |
3402 | ||
3403 | /* We must now download the power adjust value (gain) to | |
3404 | * the synthetisers (from the EEprom - area 7 - DAC) */ | |
3405 | m.mmw_fee_addr = 0x61; | |
3406 | m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD; | |
3407 | mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m, | |
3408 | (unsigned char *)&m.mmw_fee_ctrl, 2); | |
3409 | ||
3410 | /* Wait until the download is finished */ | |
3411 | } /* if 2.00 card */ | |
3412 | ||
3413 | #ifdef DEBUG_CONFIG_TRACE | |
3414 | printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name); | |
3415 | #endif | |
3416 | return TRUE; | |
3417 | } | |
3418 | ||
3419 | /*------------------------------------------------------------------*/ | |
3420 | /* | |
3421 | * Routine to gracefully turn off reception, and wait for any commands | |
3422 | * to complete. | |
3423 | * (called in wv_ru_start() and wavelan_close() and wavelan_event()) | |
3424 | */ | |
3425 | static int | |
3426 | wv_ru_stop(struct net_device * dev) | |
3427 | { | |
3428 | kio_addr_t base = dev->base_addr; | |
3429 | net_local * lp = netdev_priv(dev); | |
3430 | unsigned long flags; | |
3431 | int status; | |
3432 | int spin; | |
3433 | ||
3434 | #ifdef DEBUG_CONFIG_TRACE | |
3435 | printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name); | |
3436 | #endif | |
3437 | ||
3438 | spin_lock_irqsave(&lp->spinlock, flags); | |
3439 | ||
3440 | /* First, send the LAN controller a stop receive command */ | |
3441 | wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv", | |
3442 | OP0_STOP_RCV, SR0_NO_RESULT); | |
3443 | ||
3444 | /* Then, spin until the receive unit goes idle */ | |
3445 | spin = 300; | |
3446 | do | |
3447 | { | |
3448 | udelay(10); | |
3449 | outb(OP0_NOP | CR0_STATUS_3, LCCR(base)); | |
3450 | status = inb(LCSR(base)); | |
3451 | } | |
3452 | while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0)); | |
3453 | ||
3454 | /* Now, spin until the chip finishes executing its current command */ | |
3455 | do | |
3456 | { | |
3457 | udelay(10); | |
3458 | outb(OP0_NOP | CR0_STATUS_3, LCCR(base)); | |
3459 | status = inb(LCSR(base)); | |
3460 | } | |
3461 | while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0)); | |
3462 | ||
3463 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
3464 | ||
3465 | /* If there was a problem */ | |
3466 | if(spin <= 0) | |
3467 | { | |
3468 | #ifdef DEBUG_CONFIG_ERRORS | |
3469 | printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n", | |
3470 | dev->name); | |
3471 | #endif | |
3472 | return FALSE; | |
3473 | } | |
3474 | ||
3475 | #ifdef DEBUG_CONFIG_TRACE | |
3476 | printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name); | |
3477 | #endif | |
3478 | return TRUE; | |
3479 | } /* wv_ru_stop */ | |
3480 | ||
3481 | /*------------------------------------------------------------------*/ | |
3482 | /* | |
3483 | * This routine starts the receive unit running. First, it checks if | |
3484 | * the card is actually ready. Then the card is instructed to receive | |
3485 | * packets again. | |
3486 | * (called in wv_hw_reset() & wavelan_open()) | |
3487 | */ | |
3488 | static int | |
3489 | wv_ru_start(struct net_device * dev) | |
3490 | { | |
3491 | kio_addr_t base = dev->base_addr; | |
3492 | net_local * lp = netdev_priv(dev); | |
3493 | unsigned long flags; | |
3494 | ||
3495 | #ifdef DEBUG_CONFIG_TRACE | |
3496 | printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name); | |
3497 | #endif | |
3498 | ||
3499 | /* | |
3500 | * We need to start from a quiescent state. To do so, we could check | |
3501 | * if the card is already running, but instead we just try to shut | |
3502 | * it down. First, we disable reception (in case it was already enabled). | |
3503 | */ | |
3504 | if(!wv_ru_stop(dev)) | |
3505 | return FALSE; | |
3506 | ||
3507 | spin_lock_irqsave(&lp->spinlock, flags); | |
3508 | ||
3509 | /* Now we know that no command is being executed. */ | |
3510 | ||
3511 | /* Set the receive frame pointer and stop pointer */ | |
3512 | lp->rfp = 0; | |
3513 | outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base)); | |
3514 | ||
3515 | /* Reset ring management. This sets the receive frame pointer to 1 */ | |
3516 | outb(OP1_RESET_RING_MNGMT, LCCR(base)); | |
3517 | ||
3518 | #if 0 | |
3519 | /* XXX the i82593 manual page 6-4 seems to indicate that the stop register | |
3520 | should be set as below */ | |
3521 | /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/ | |
3522 | #elif 0 | |
3523 | /* but I set it 0 instead */ | |
3524 | lp->stop = 0; | |
3525 | #else | |
3526 | /* but I set it to 3 bytes per packet less than 8K */ | |
3527 | lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE; | |
3528 | #endif | |
3529 | outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base)); | |
3530 | outb(OP1_INT_ENABLE, LCCR(base)); | |
3531 | outb(OP1_SWIT_TO_PORT_0, LCCR(base)); | |
3532 | ||
3533 | /* Reset receive DMA pointer */ | |
3534 | hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET); | |
3535 | hacr_write_slow(base, HACR_DEFAULT); | |
3536 | ||
3537 | /* Receive DMA on channel 1 */ | |
3538 | wv_82593_cmd(dev, "wv_ru_start(): rcv-enable", | |
3539 | CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT); | |
3540 | ||
3541 | #ifdef DEBUG_I82593_SHOW | |
3542 | { | |
3543 | int status; | |
3544 | int opri; | |
3545 | int spin = 10000; | |
3546 | ||
3547 | /* spin until the chip starts receiving */ | |
3548 | do | |
3549 | { | |
3550 | outb(OP0_NOP | CR0_STATUS_3, LCCR(base)); | |
3551 | status = inb(LCSR(base)); | |
3552 | if(spin-- <= 0) | |
3553 | break; | |
3554 | } | |
3555 | while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) && | |
3556 | ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY)); | |
3557 | printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n", | |
3558 | (status & SR3_RCV_STATE_MASK), i); | |
3559 | } | |
3560 | #endif | |
3561 | ||
3562 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
3563 | ||
3564 | #ifdef DEBUG_CONFIG_TRACE | |
3565 | printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name); | |
3566 | #endif | |
3567 | return TRUE; | |
3568 | } | |
3569 | ||
3570 | /*------------------------------------------------------------------*/ | |
3571 | /* | |
3572 | * This routine does a standard config of the WaveLAN controller (i82593). | |
3573 | * In the ISA driver, this is integrated in wavelan_hardware_reset() | |
3574 | * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit()) | |
3575 | */ | |
3576 | static int | |
3577 | wv_82593_config(struct net_device * dev) | |
3578 | { | |
3579 | kio_addr_t base = dev->base_addr; | |
3580 | net_local * lp = netdev_priv(dev); | |
3581 | struct i82593_conf_block cfblk; | |
3582 | int ret = TRUE; | |
3583 | ||
3584 | #ifdef DEBUG_CONFIG_TRACE | |
3585 | printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name); | |
3586 | #endif | |
3587 | ||
3588 | /* Create & fill i82593 config block | |
3589 | * | |
3590 | * Now conform to Wavelan document WCIN085B | |
3591 | */ | |
3592 | memset(&cfblk, 0x00, sizeof(struct i82593_conf_block)); | |
3593 | cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */ | |
3594 | cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */ | |
3595 | cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */ | |
3596 | cfblk.fifo_32 = 1; | |
3597 | cfblk.throttle_enb = FALSE; | |
3598 | cfblk.contin = TRUE; /* enable continuous mode */ | |
3599 | cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */ | |
3600 | cfblk.addr_len = WAVELAN_ADDR_SIZE; | |
3601 | cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */ | |
3602 | cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */ | |
3603 | cfblk.loopback = FALSE; | |
3604 | cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */ | |
3605 | cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */ | |
3606 | cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */ | |
3607 | cfblk.ifrm_spc = 0x20; /* 32 bit times interframe spacing */ | |
3608 | cfblk.slottim_low = 0x20; /* 32 bit times slot time */ | |
3609 | cfblk.slottim_hi = 0x0; | |
3610 | cfblk.max_retr = 15; | |
3611 | cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */ | |
3612 | cfblk.bc_dis = FALSE; /* Enable broadcast reception */ | |
3613 | cfblk.crs_1 = TRUE; /* Transmit without carrier sense */ | |
3614 | cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */ | |
3615 | cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */ | |
3616 | cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */ | |
3617 | cfblk.cs_filter = 0; /* CS is recognized immediately */ | |
3618 | cfblk.crs_src = FALSE; /* External carrier sense */ | |
3619 | cfblk.cd_filter = 0; /* CD is recognized immediately */ | |
3620 | cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */ | |
3621 | cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */ | |
3622 | cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */ | |
3623 | cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */ | |
3624 | cfblk.artx = TRUE; /* Disable automatic retransmission */ | |
3625 | cfblk.sarec = TRUE; /* Disable source addr trig of CD */ | |
3626 | cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */ | |
3627 | cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */ | |
3628 | cfblk.lbpkpol = TRUE; /* Loopback pin active high */ | |
3629 | cfblk.fdx = FALSE; /* Disable full duplex operation */ | |
3630 | cfblk.dummy_6 = 0x3f; /* all ones */ | |
3631 | cfblk.mult_ia = FALSE; /* No multiple individual addresses */ | |
3632 | cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */ | |
3633 | cfblk.dummy_1 = TRUE; /* set to 1 */ | |
3634 | cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */ | |
3635 | #ifdef MULTICAST_ALL | |
3636 | cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */ | |
3637 | #else | |
3638 | cfblk.mc_all = FALSE; /* No multicast all mode */ | |
3639 | #endif | |
3640 | cfblk.rcv_mon = 0; /* Monitor mode disabled */ | |
3641 | cfblk.frag_acpt = TRUE; /* Do not accept fragments */ | |
3642 | cfblk.tstrttrs = FALSE; /* No start transmission threshold */ | |
3643 | cfblk.fretx = TRUE; /* FIFO automatic retransmission */ | |
3644 | cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */ | |
3645 | cfblk.sttlen = TRUE; /* 6 byte status registers */ | |
3646 | cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */ | |
3647 | cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */ | |
3648 | cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */ | |
3649 | cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */ | |
3650 | ||
3651 | #ifdef DEBUG_I82593_SHOW | |
3652 | { | |
3653 | u_char *c = (u_char *) &cfblk; | |
3654 | int i; | |
3655 | printk(KERN_DEBUG "wavelan_cs: config block:"); | |
3656 | for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++) | |
3657 | { | |
3658 | if((i % 16) == 0) printk("\n" KERN_DEBUG); | |
3659 | printk("%02x ", *c); | |
3660 | } | |
3661 | printk("\n"); | |
3662 | } | |
3663 | #endif | |
3664 | ||
3665 | /* Copy the config block to the i82593 */ | |
3666 | outb(TX_BASE & 0xff, PIORL(base)); | |
3667 | outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base)); | |
3668 | outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */ | |
3669 | outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */ | |
3670 | outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block)); | |
3671 | ||
3672 | /* reset transmit DMA pointer */ | |
3673 | hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET); | |
3674 | hacr_write(base, HACR_DEFAULT); | |
3675 | if(!wv_82593_cmd(dev, "wv_82593_config(): configure", | |
3676 | OP0_CONFIGURE, SR0_CONFIGURE_DONE)) | |
3677 | ret = FALSE; | |
3678 | ||
3679 | /* Initialize adapter's ethernet MAC address */ | |
3680 | outb(TX_BASE & 0xff, PIORL(base)); | |
3681 | outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base)); | |
3682 | outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */ | |
3683 | outb(0, PIOP(base)); /* byte count msb */ | |
3684 | outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE); | |
3685 | ||
3686 | /* reset transmit DMA pointer */ | |
3687 | hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET); | |
3688 | hacr_write(base, HACR_DEFAULT); | |
3689 | if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup", | |
3690 | OP0_IA_SETUP, SR0_IA_SETUP_DONE)) | |
3691 | ret = FALSE; | |
3692 | ||
3693 | #ifdef WAVELAN_ROAMING | |
3694 | /* If roaming is enabled, join the "Beacon Request" multicast group... */ | |
3695 | /* But only if it's not in there already! */ | |
3696 | if(do_roaming) | |
3697 | dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1); | |
3698 | #endif /* WAVELAN_ROAMING */ | |
3699 | ||
3700 | /* If any multicast address to set */ | |
3701 | if(lp->mc_count) | |
3702 | { | |
3703 | struct dev_mc_list * dmi; | |
3704 | int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count; | |
3705 | ||
3706 | #ifdef DEBUG_CONFIG_INFO | |
3707 | printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n", | |
3708 | dev->name, lp->mc_count); | |
3709 | for(dmi=dev->mc_list; dmi; dmi=dmi->next) | |
3710 | printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n", | |
3711 | dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2], | |
3712 | dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] ); | |
3713 | #endif | |
3714 | ||
3715 | /* Initialize adapter's ethernet multicast addresses */ | |
3716 | outb(TX_BASE & 0xff, PIORL(base)); | |
3717 | outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base)); | |
3718 | outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */ | |
3719 | outb((addrs_len >> 8), PIOP(base)); /* byte count msb */ | |
3720 | for(dmi=dev->mc_list; dmi; dmi=dmi->next) | |
3721 | outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen); | |
3722 | ||
3723 | /* reset transmit DMA pointer */ | |
3724 | hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET); | |
3725 | hacr_write(base, HACR_DEFAULT); | |
3726 | if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup", | |
3727 | OP0_MC_SETUP, SR0_MC_SETUP_DONE)) | |
3728 | ret = FALSE; | |
3729 | lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */ | |
3730 | } | |
3731 | ||
3732 | /* Job done, clear the flag */ | |
3733 | lp->reconfig_82593 = FALSE; | |
3734 | ||
3735 | #ifdef DEBUG_CONFIG_TRACE | |
3736 | printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name); | |
3737 | #endif | |
3738 | return(ret); | |
3739 | } | |
3740 | ||
3741 | /*------------------------------------------------------------------*/ | |
3742 | /* | |
3743 | * Read the Access Configuration Register, perform a software reset, | |
3744 | * and then re-enable the card's software. | |
3745 | * | |
3746 | * If I understand correctly : reset the pcmcia interface of the | |
3747 | * wavelan. | |
3748 | * (called by wv_config()) | |
3749 | */ | |
3750 | static inline int | |
3751 | wv_pcmcia_reset(struct net_device * dev) | |
3752 | { | |
3753 | int i; | |
3754 | conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 }; | |
3755 | dev_link_t * link = ((net_local *)netdev_priv(dev))->link; | |
3756 | ||
3757 | #ifdef DEBUG_CONFIG_TRACE | |
3758 | printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name); | |
3759 | #endif | |
3760 | ||
3761 | i = pcmcia_access_configuration_register(link->handle, ®); | |
3762 | if(i != CS_SUCCESS) | |
3763 | { | |
3764 | cs_error(link->handle, AccessConfigurationRegister, i); | |
3765 | return FALSE; | |
3766 | } | |
3767 | ||
3768 | #ifdef DEBUG_CONFIG_INFO | |
3769 | printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n", | |
3770 | dev->name, (u_int) reg.Value); | |
3771 | #endif | |
3772 | ||
3773 | reg.Action = CS_WRITE; | |
3774 | reg.Value = reg.Value | COR_SW_RESET; | |
3775 | i = pcmcia_access_configuration_register(link->handle, ®); | |
3776 | if(i != CS_SUCCESS) | |
3777 | { | |
3778 | cs_error(link->handle, AccessConfigurationRegister, i); | |
3779 | return FALSE; | |
3780 | } | |
3781 | ||
3782 | reg.Action = CS_WRITE; | |
3783 | reg.Value = COR_LEVEL_IRQ | COR_CONFIG; | |
3784 | i = pcmcia_access_configuration_register(link->handle, ®); | |
3785 | if(i != CS_SUCCESS) | |
3786 | { | |
3787 | cs_error(link->handle, AccessConfigurationRegister, i); | |
3788 | return FALSE; | |
3789 | } | |
3790 | ||
3791 | #ifdef DEBUG_CONFIG_TRACE | |
3792 | printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name); | |
3793 | #endif | |
3794 | return TRUE; | |
3795 | } | |
3796 | ||
3797 | /*------------------------------------------------------------------*/ | |
3798 | /* | |
3799 | * wavelan_hw_config() is called after a CARD_INSERTION event is | |
3800 | * received, to configure the wavelan hardware. | |
3801 | * Note that the reception will be enabled in wavelan->open(), so the | |
3802 | * device is configured but idle... | |
3803 | * Performs the following actions: | |
3804 | * 1. A pcmcia software reset (using wv_pcmcia_reset()) | |
3805 | * 2. A power reset (reset DMA) | |
3806 | * 3. Reset the LAN controller | |
3807 | * 4. Initialize the radio modem (using wv_mmc_init) | |
3808 | * 5. Configure LAN controller (using wv_82593_config) | |
3809 | * 6. Perform a diagnostic on the LAN controller | |
3810 | * (called by wavelan_event() & wv_hw_reset()) | |
3811 | */ | |
3812 | static int | |
3813 | wv_hw_config(struct net_device * dev) | |
3814 | { | |
3815 | net_local * lp = netdev_priv(dev); | |
3816 | kio_addr_t base = dev->base_addr; | |
3817 | unsigned long flags; | |
3818 | int ret = FALSE; | |
3819 | ||
3820 | #ifdef DEBUG_CONFIG_TRACE | |
3821 | printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name); | |
3822 | #endif | |
3823 | ||
3824 | #ifdef STRUCT_CHECK | |
3825 | if(wv_structuct_check() != (char *) NULL) | |
3826 | { | |
3827 | printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: \"%s\"\n", | |
3828 | dev->name, wv_structuct_check()); | |
3829 | return FALSE; | |
3830 | } | |
3831 | #endif /* STRUCT_CHECK == 1 */ | |
3832 | ||
3833 | /* Reset the pcmcia interface */ | |
3834 | if(wv_pcmcia_reset(dev) == FALSE) | |
3835 | return FALSE; | |
3836 | ||
3837 | /* Disable interrupts */ | |
3838 | spin_lock_irqsave(&lp->spinlock, flags); | |
3839 | ||
3840 | /* Disguised goto ;-) */ | |
3841 | do | |
3842 | { | |
3843 | /* Power UP the module + reset the modem + reset host adapter | |
3844 | * (in fact, reset DMA channels) */ | |
3845 | hacr_write_slow(base, HACR_RESET); | |
3846 | hacr_write(base, HACR_DEFAULT); | |
3847 | ||
3848 | /* Check if the module has been powered up... */ | |
3849 | if(hasr_read(base) & HASR_NO_CLK) | |
3850 | { | |
3851 | #ifdef DEBUG_CONFIG_ERRORS | |
3852 | printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n", | |
3853 | dev->name); | |
3854 | #endif | |
3855 | break; | |
3856 | } | |
3857 | ||
3858 | /* initialize the modem */ | |
3859 | if(wv_mmc_init(dev) == FALSE) | |
3860 | { | |
3861 | #ifdef DEBUG_CONFIG_ERRORS | |
3862 | printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n", | |
3863 | dev->name); | |
3864 | #endif | |
3865 | break; | |
3866 | } | |
3867 | ||
3868 | /* reset the LAN controller (i82593) */ | |
3869 | outb(OP0_RESET, LCCR(base)); | |
3870 | mdelay(1); /* A bit crude ! */ | |
3871 | ||
3872 | /* Initialize the LAN controller */ | |
3873 | if(wv_82593_config(dev) == FALSE) | |
3874 | { | |
3875 | #ifdef DEBUG_CONFIG_ERRORS | |
3876 | printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n", | |
3877 | dev->name); | |
3878 | #endif | |
3879 | break; | |
3880 | } | |
3881 | ||
3882 | /* Diagnostic */ | |
3883 | if(wv_diag(dev) == FALSE) | |
3884 | { | |
3885 | #ifdef DEBUG_CONFIG_ERRORS | |
3886 | printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n", | |
3887 | dev->name); | |
3888 | #endif | |
3889 | break; | |
3890 | } | |
3891 | ||
3892 | /* | |
3893 | * insert code for loopback test here | |
3894 | */ | |
3895 | ||
3896 | /* The device is now configured */ | |
3897 | lp->configured = 1; | |
3898 | ret = TRUE; | |
3899 | } | |
3900 | while(0); | |
3901 | ||
3902 | /* Re-enable interrupts */ | |
3903 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
3904 | ||
3905 | #ifdef DEBUG_CONFIG_TRACE | |
3906 | printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name); | |
3907 | #endif | |
3908 | return(ret); | |
3909 | } | |
3910 | ||
3911 | /*------------------------------------------------------------------*/ | |
3912 | /* | |
3913 | * Totally reset the wavelan and restart it. | |
3914 | * Performs the following actions: | |
3915 | * 1. Call wv_hw_config() | |
3916 | * 2. Start the LAN controller's receive unit | |
3917 | * (called by wavelan_event(), wavelan_watchdog() and wavelan_open()) | |
3918 | */ | |
3919 | static inline void | |
3920 | wv_hw_reset(struct net_device * dev) | |
3921 | { | |
3922 | net_local * lp = netdev_priv(dev); | |
3923 | ||
3924 | #ifdef DEBUG_CONFIG_TRACE | |
3925 | printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name); | |
3926 | #endif | |
3927 | ||
3928 | lp->nresets++; | |
3929 | lp->configured = 0; | |
3930 | ||
3931 | /* Call wv_hw_config() for most of the reset & init stuff */ | |
3932 | if(wv_hw_config(dev) == FALSE) | |
3933 | return; | |
3934 | ||
3935 | /* start receive unit */ | |
3936 | wv_ru_start(dev); | |
3937 | ||
3938 | #ifdef DEBUG_CONFIG_TRACE | |
3939 | printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name); | |
3940 | #endif | |
3941 | } | |
3942 | ||
3943 | /*------------------------------------------------------------------*/ | |
3944 | /* | |
3945 | * wv_pcmcia_config() is called after a CARD_INSERTION event is | |
3946 | * received, to configure the PCMCIA socket, and to make the ethernet | |
3947 | * device available to the system. | |
3948 | * (called by wavelan_event()) | |
3949 | */ | |
3950 | static inline int | |
3951 | wv_pcmcia_config(dev_link_t * link) | |
3952 | { | |
3953 | client_handle_t handle = link->handle; | |
3954 | tuple_t tuple; | |
3955 | cisparse_t parse; | |
3956 | struct net_device * dev = (struct net_device *) link->priv; | |
3957 | int i; | |
3958 | u_char buf[64]; | |
3959 | win_req_t req; | |
3960 | memreq_t mem; | |
3961 | net_local * lp = netdev_priv(dev); | |
3962 | ||
3963 | ||
3964 | #ifdef DEBUG_CONFIG_TRACE | |
3965 | printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link); | |
3966 | #endif | |
3967 | ||
3968 | /* | |
3969 | * This reads the card's CONFIG tuple to find its configuration | |
3970 | * registers. | |
3971 | */ | |
3972 | do | |
3973 | { | |
3974 | tuple.Attributes = 0; | |
3975 | tuple.DesiredTuple = CISTPL_CONFIG; | |
3976 | i = pcmcia_get_first_tuple(handle, &tuple); | |
3977 | if(i != CS_SUCCESS) | |
3978 | break; | |
3979 | tuple.TupleData = (cisdata_t *)buf; | |
3980 | tuple.TupleDataMax = 64; | |
3981 | tuple.TupleOffset = 0; | |
3982 | i = pcmcia_get_tuple_data(handle, &tuple); | |
3983 | if(i != CS_SUCCESS) | |
3984 | break; | |
3985 | i = pcmcia_parse_tuple(handle, &tuple, &parse); | |
3986 | if(i != CS_SUCCESS) | |
3987 | break; | |
3988 | link->conf.ConfigBase = parse.config.base; | |
3989 | link->conf.Present = parse.config.rmask[0]; | |
3990 | } | |
3991 | while(0); | |
3992 | if(i != CS_SUCCESS) | |
3993 | { | |
3994 | cs_error(link->handle, ParseTuple, i); | |
3995 | link->state &= ~DEV_CONFIG_PENDING; | |
3996 | return FALSE; | |
3997 | } | |
3998 | ||
3999 | /* Configure card */ | |
4000 | link->state |= DEV_CONFIG; | |
4001 | do | |
4002 | { | |
4003 | i = pcmcia_request_io(link->handle, &link->io); | |
4004 | if(i != CS_SUCCESS) | |
4005 | { | |
4006 | cs_error(link->handle, RequestIO, i); | |
4007 | break; | |
4008 | } | |
4009 | ||
4010 | /* | |
4011 | * Now allocate an interrupt line. Note that this does not | |
4012 | * actually assign a handler to the interrupt. | |
4013 | */ | |
4014 | i = pcmcia_request_irq(link->handle, &link->irq); | |
4015 | if(i != CS_SUCCESS) | |
4016 | { | |
4017 | cs_error(link->handle, RequestIRQ, i); | |
4018 | break; | |
4019 | } | |
4020 | ||
4021 | /* | |
4022 | * This actually configures the PCMCIA socket -- setting up | |
4023 | * the I/O windows and the interrupt mapping. | |
4024 | */ | |
4025 | link->conf.ConfigIndex = 1; | |
4026 | i = pcmcia_request_configuration(link->handle, &link->conf); | |
4027 | if(i != CS_SUCCESS) | |
4028 | { | |
4029 | cs_error(link->handle, RequestConfiguration, i); | |
4030 | break; | |
4031 | } | |
4032 | ||
4033 | /* | |
4034 | * Allocate a small memory window. Note that the dev_link_t | |
4035 | * structure provides space for one window handle -- if your | |
4036 | * device needs several windows, you'll need to keep track of | |
4037 | * the handles in your private data structure, link->priv. | |
4038 | */ | |
4039 | req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; | |
4040 | req.Base = req.Size = 0; | |
4041 | req.AccessSpeed = mem_speed; | |
4042 | i = pcmcia_request_window(&link->handle, &req, &link->win); | |
4043 | if(i != CS_SUCCESS) | |
4044 | { | |
4045 | cs_error(link->handle, RequestWindow, i); | |
4046 | break; | |
4047 | } | |
4048 | ||
4049 | lp->mem = ioremap(req.Base, req.Size); | |
4050 | dev->mem_start = (u_long)lp->mem; | |
4051 | dev->mem_end = dev->mem_start + req.Size; | |
4052 | ||
4053 | mem.CardOffset = 0; mem.Page = 0; | |
4054 | i = pcmcia_map_mem_page(link->win, &mem); | |
4055 | if(i != CS_SUCCESS) | |
4056 | { | |
4057 | cs_error(link->handle, MapMemPage, i); | |
4058 | break; | |
4059 | } | |
4060 | ||
4061 | /* Feed device with this info... */ | |
4062 | dev->irq = link->irq.AssignedIRQ; | |
4063 | dev->base_addr = link->io.BasePort1; | |
4064 | netif_start_queue(dev); | |
4065 | ||
4066 | #ifdef DEBUG_CONFIG_INFO | |
4067 | printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART %p IRQ %d IOPORT 0x%x\n", | |
4068 | lp->mem, dev->irq, (u_int) dev->base_addr); | |
4069 | #endif | |
4070 | ||
4071 | SET_NETDEV_DEV(dev, &handle_to_dev(handle)); | |
4072 | i = register_netdev(dev); | |
4073 | if(i != 0) | |
4074 | { | |
4075 | #ifdef DEBUG_CONFIG_ERRORS | |
4076 | printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n"); | |
4077 | #endif | |
4078 | break; | |
4079 | } | |
4080 | } | |
4081 | while(0); /* Humm... Disguised goto !!! */ | |
4082 | ||
4083 | link->state &= ~DEV_CONFIG_PENDING; | |
4084 | /* If any step failed, release any partially configured state */ | |
4085 | if(i != 0) | |
4086 | { | |
4087 | wv_pcmcia_release(link); | |
4088 | return FALSE; | |
4089 | } | |
4090 | ||
4091 | strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name); | |
4092 | link->dev = &((net_local *) netdev_priv(dev))->node; | |
4093 | ||
4094 | #ifdef DEBUG_CONFIG_TRACE | |
4095 | printk(KERN_DEBUG "<-wv_pcmcia_config()\n"); | |
4096 | #endif | |
4097 | return TRUE; | |
4098 | } | |
4099 | ||
4100 | /*------------------------------------------------------------------*/ | |
4101 | /* | |
4102 | * After a card is removed, wv_pcmcia_release() will unregister the net | |
4103 | * device, and release the PCMCIA configuration. If the device is | |
4104 | * still open, this will be postponed until it is closed. | |
4105 | */ | |
4106 | static void | |
4107 | wv_pcmcia_release(dev_link_t *link) | |
4108 | { | |
4109 | struct net_device * dev = (struct net_device *) link->priv; | |
4110 | net_local * lp = netdev_priv(dev); | |
4111 | ||
4112 | #ifdef DEBUG_CONFIG_TRACE | |
4113 | printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link); | |
4114 | #endif | |
4115 | ||
4116 | /* Don't bother checking to see if these succeed or not */ | |
4117 | iounmap(lp->mem); | |
4118 | pcmcia_release_window(link->win); | |
4119 | pcmcia_release_configuration(link->handle); | |
4120 | pcmcia_release_io(link->handle, &link->io); | |
4121 | pcmcia_release_irq(link->handle, &link->irq); | |
4122 | ||
4123 | link->state &= ~DEV_CONFIG; | |
4124 | ||
4125 | #ifdef DEBUG_CONFIG_TRACE | |
4126 | printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name); | |
4127 | #endif | |
4128 | } | |
4129 | ||
4130 | /************************ INTERRUPT HANDLING ************************/ | |
4131 | ||
4132 | /* | |
4133 | * This function is the interrupt handler for the WaveLAN card. This | |
4134 | * routine will be called whenever: | |
4135 | * 1. A packet is received. | |
4136 | * 2. A packet has successfully been transferred and the unit is | |
4137 | * ready to transmit another packet. | |
4138 | * 3. A command has completed execution. | |
4139 | */ | |
4140 | static irqreturn_t | |
4141 | wavelan_interrupt(int irq, | |
4142 | void * dev_id, | |
4143 | struct pt_regs * regs) | |
4144 | { | |
4145 | struct net_device * dev; | |
4146 | net_local * lp; | |
4147 | kio_addr_t base; | |
4148 | int status0; | |
4149 | u_int tx_status; | |
4150 | ||
4151 | if ((dev = dev_id) == NULL) | |
4152 | { | |
4153 | #ifdef DEBUG_INTERRUPT_ERROR | |
4154 | printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.\n", | |
4155 | irq); | |
4156 | #endif | |
4157 | return IRQ_NONE; | |
4158 | } | |
4159 | ||
4160 | #ifdef DEBUG_INTERRUPT_TRACE | |
4161 | printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name); | |
4162 | #endif | |
4163 | ||
4164 | lp = netdev_priv(dev); | |
4165 | base = dev->base_addr; | |
4166 | ||
4167 | #ifdef DEBUG_INTERRUPT_INFO | |
4168 | /* Check state of our spinlock (it should be cleared) */ | |
4169 | if(spin_is_locked(&lp->spinlock)) | |
4170 | printk(KERN_DEBUG | |
4171 | "%s: wavelan_interrupt(): spinlock is already locked !!!\n", | |
4172 | dev->name); | |
4173 | #endif | |
4174 | ||
4175 | /* Prevent reentrancy. We need to do that because we may have | |
4176 | * multiple interrupt handler running concurently. | |
4177 | * It is safe because interrupts are disabled before aquiring | |
4178 | * the spinlock. */ | |
4179 | spin_lock(&lp->spinlock); | |
4180 | ||
4181 | /* Treat all pending interrupts */ | |
4182 | while(1) | |
4183 | { | |
4184 | /* ---------------- INTERRUPT CHECKING ---------------- */ | |
4185 | /* | |
4186 | * Look for the interrupt and verify the validity | |
4187 | */ | |
4188 | outb(CR0_STATUS_0 | OP0_NOP, LCCR(base)); | |
4189 | status0 = inb(LCSR(base)); | |
4190 | ||
4191 | #ifdef DEBUG_INTERRUPT_INFO | |
4192 | printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0, | |
4193 | (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT); | |
4194 | if(status0&SR0_INTERRUPT) | |
4195 | { | |
4196 | printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" : | |
4197 | ((status0 & SR0_EXECUTION) ? "cmd" : | |
4198 | ((status0 & SR0_RECEPTION) ? "recv" : "unknown")), | |
4199 | (status0 & SR0_EVENT_MASK)); | |
4200 | } | |
4201 | else | |
4202 | printk("\n"); | |
4203 | #endif | |
4204 | ||
4205 | /* Return if no actual interrupt from i82593 (normal exit) */ | |
4206 | if(!(status0 & SR0_INTERRUPT)) | |
4207 | break; | |
4208 | ||
4209 | /* If interrupt is both Rx and Tx or none... | |
4210 | * This code in fact is there to catch the spurious interrupt | |
4211 | * when you remove the wavelan pcmcia card from the socket */ | |
4212 | if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) || | |
4213 | ((status0 & SR0_BOTH_RX_TX) == 0x0)) | |
4214 | { | |
4215 | #ifdef DEBUG_INTERRUPT_INFO | |
4216 | printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n", | |
4217 | dev->name, status0); | |
4218 | #endif | |
4219 | /* Acknowledge the interrupt */ | |
4220 | outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); | |
4221 | break; | |
4222 | } | |
4223 | ||
4224 | /* ----------------- RECEIVING PACKET ----------------- */ | |
4225 | /* | |
4226 | * When the wavelan signal the reception of a new packet, | |
4227 | * we call wv_packet_rcv() to copy if from the buffer and | |
4228 | * send it to NET3 | |
4229 | */ | |
4230 | if(status0 & SR0_RECEPTION) | |
4231 | { | |
4232 | #ifdef DEBUG_INTERRUPT_INFO | |
4233 | printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name); | |
4234 | #endif | |
4235 | ||
4236 | if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT) | |
4237 | { | |
4238 | #ifdef DEBUG_INTERRUPT_ERROR | |
4239 | printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n", | |
4240 | dev->name); | |
4241 | #endif | |
4242 | lp->stats.rx_over_errors++; | |
4243 | lp->overrunning = 1; | |
4244 | } | |
4245 | ||
4246 | /* Get the packet */ | |
4247 | wv_packet_rcv(dev); | |
4248 | lp->overrunning = 0; | |
4249 | ||
4250 | /* Acknowledge the interrupt */ | |
4251 | outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); | |
4252 | continue; | |
4253 | } | |
4254 | ||
4255 | /* ---------------- COMMAND COMPLETION ---------------- */ | |
4256 | /* | |
4257 | * Interrupts issued when the i82593 has completed a command. | |
4258 | * Most likely : transmission done | |
4259 | */ | |
4260 | ||
4261 | /* If a transmission has been done */ | |
4262 | if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE || | |
4263 | (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE || | |
4264 | (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE) | |
4265 | { | |
4266 | #ifdef DEBUG_TX_ERROR | |
4267 | if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE) | |
4268 | printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n", | |
4269 | dev->name); | |
4270 | #endif | |
4271 | ||
4272 | /* Get transmission status */ | |
4273 | tx_status = inb(LCSR(base)); | |
4274 | tx_status |= (inb(LCSR(base)) << 8); | |
4275 | #ifdef DEBUG_INTERRUPT_INFO | |
4276 | printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n", | |
4277 | dev->name); | |
4278 | { | |
4279 | u_int rcv_bytes; | |
4280 | u_char status3; | |
4281 | rcv_bytes = inb(LCSR(base)); | |
4282 | rcv_bytes |= (inb(LCSR(base)) << 8); | |
4283 | status3 = inb(LCSR(base)); | |
4284 | printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n", | |
4285 | tx_status, rcv_bytes, (u_int) status3); | |
4286 | } | |
4287 | #endif | |
4288 | /* Check for possible errors */ | |
4289 | if((tx_status & TX_OK) != TX_OK) | |
4290 | { | |
4291 | lp->stats.tx_errors++; | |
4292 | ||
4293 | if(tx_status & TX_FRTL) | |
4294 | { | |
4295 | #ifdef DEBUG_TX_ERROR | |
4296 | printk(KERN_INFO "%s: wv_interrupt(): frame too long\n", | |
4297 | dev->name); | |
4298 | #endif | |
4299 | } | |
4300 | if(tx_status & TX_UND_RUN) | |
4301 | { | |
4302 | #ifdef DEBUG_TX_FAIL | |
4303 | printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n", | |
4304 | dev->name); | |
4305 | #endif | |
4306 | lp->stats.tx_aborted_errors++; | |
4307 | } | |
4308 | if(tx_status & TX_LOST_CTS) | |
4309 | { | |
4310 | #ifdef DEBUG_TX_FAIL | |
4311 | printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name); | |
4312 | #endif | |
4313 | lp->stats.tx_carrier_errors++; | |
4314 | } | |
4315 | if(tx_status & TX_LOST_CRS) | |
4316 | { | |
4317 | #ifdef DEBUG_TX_FAIL | |
4318 | printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n", | |
4319 | dev->name); | |
4320 | #endif | |
4321 | lp->stats.tx_carrier_errors++; | |
4322 | } | |
4323 | if(tx_status & TX_HRT_BEAT) | |
4324 | { | |
4325 | #ifdef DEBUG_TX_FAIL | |
4326 | printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name); | |
4327 | #endif | |
4328 | lp->stats.tx_heartbeat_errors++; | |
4329 | } | |
4330 | if(tx_status & TX_DEFER) | |
4331 | { | |
4332 | #ifdef DEBUG_TX_FAIL | |
4333 | printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n", | |
4334 | dev->name); | |
4335 | #endif | |
4336 | } | |
4337 | /* Ignore late collisions since they're more likely to happen | |
4338 | * here (the WaveLAN design prevents the LAN controller from | |
4339 | * receiving while it is transmitting). We take action only when | |
4340 | * the maximum retransmit attempts is exceeded. | |
4341 | */ | |
4342 | if(tx_status & TX_COLL) | |
4343 | { | |
4344 | if(tx_status & TX_MAX_COL) | |
4345 | { | |
4346 | #ifdef DEBUG_TX_FAIL | |
4347 | printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n", | |
4348 | dev->name); | |
4349 | #endif | |
4350 | if(!(tx_status & TX_NCOL_MASK)) | |
4351 | { | |
4352 | lp->stats.collisions += 0x10; | |
4353 | } | |
4354 | } | |
4355 | } | |
4356 | } /* if(!(tx_status & TX_OK)) */ | |
4357 | ||
4358 | lp->stats.collisions += (tx_status & TX_NCOL_MASK); | |
4359 | lp->stats.tx_packets++; | |
4360 | ||
4361 | netif_wake_queue(dev); | |
4362 | outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */ | |
4363 | } | |
4364 | else /* if interrupt = transmit done or retransmit done */ | |
4365 | { | |
4366 | #ifdef DEBUG_INTERRUPT_ERROR | |
4367 | printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n", | |
4368 | status0); | |
4369 | #endif | |
4370 | outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */ | |
4371 | } | |
4372 | } /* while(1) */ | |
4373 | ||
4374 | spin_unlock(&lp->spinlock); | |
4375 | ||
4376 | #ifdef DEBUG_INTERRUPT_TRACE | |
4377 | printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name); | |
4378 | #endif | |
4379 | ||
4380 | /* We always return IRQ_HANDLED, because we will receive empty | |
4381 | * interrupts under normal operations. Anyway, it doesn't matter | |
4382 | * as we are dealing with an ISA interrupt that can't be shared. | |
4383 | * | |
4384 | * Explanation : under heavy receive, the following happens : | |
4385 | * ->wavelan_interrupt() | |
4386 | * (status0 & SR0_INTERRUPT) != 0 | |
4387 | * ->wv_packet_rcv() | |
4388 | * (status0 & SR0_INTERRUPT) != 0 | |
4389 | * ->wv_packet_rcv() | |
4390 | * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event | |
4391 | * <-wavelan_interrupt() | |
4392 | * ->wavelan_interrupt() | |
4393 | * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt | |
4394 | * <-wavelan_interrupt() | |
4395 | * Jean II */ | |
4396 | return IRQ_HANDLED; | |
4397 | } /* wv_interrupt */ | |
4398 | ||
4399 | /*------------------------------------------------------------------*/ | |
4400 | /* | |
4401 | * Watchdog: when we start a transmission, a timer is set for us in the | |
4402 | * kernel. If the transmission completes, this timer is disabled. If | |
4403 | * the timer expires, we are called and we try to unlock the hardware. | |
4404 | * | |
4405 | * Note : This watchdog is move clever than the one in the ISA driver, | |
4406 | * because it try to abort the current command before reseting | |
4407 | * everything... | |
4408 | * On the other hand, it's a bit simpler, because we don't have to | |
4409 | * deal with the multiple Tx buffers... | |
4410 | */ | |
4411 | static void | |
4412 | wavelan_watchdog(struct net_device * dev) | |
4413 | { | |
4414 | net_local * lp = netdev_priv(dev); | |
4415 | kio_addr_t base = dev->base_addr; | |
4416 | unsigned long flags; | |
4417 | int aborted = FALSE; | |
4418 | ||
4419 | #ifdef DEBUG_INTERRUPT_TRACE | |
4420 | printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name); | |
4421 | #endif | |
4422 | ||
4423 | #ifdef DEBUG_INTERRUPT_ERROR | |
4424 | printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n", | |
4425 | dev->name); | |
4426 | #endif | |
4427 | ||
4428 | spin_lock_irqsave(&lp->spinlock, flags); | |
4429 | ||
4430 | /* Ask to abort the current command */ | |
4431 | outb(OP0_ABORT, LCCR(base)); | |
4432 | ||
4433 | /* Wait for the end of the command (a bit hackish) */ | |
4434 | if(wv_82593_cmd(dev, "wavelan_watchdog(): abort", | |
4435 | OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED)) | |
4436 | aborted = TRUE; | |
4437 | ||
4438 | /* Release spinlock here so that wv_hw_reset() can grab it */ | |
4439 | spin_unlock_irqrestore(&lp->spinlock, flags); | |
4440 | ||
4441 | /* Check if we were successful in aborting it */ | |
4442 | if(!aborted) | |
4443 | { | |
4444 | /* It seem that it wasn't enough */ | |
4445 | #ifdef DEBUG_INTERRUPT_ERROR | |
4446 | printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n", | |
4447 | dev->name); | |
4448 | #endif | |
4449 | wv_hw_reset(dev); | |
4450 | } | |
4451 | ||
4452 | #ifdef DEBUG_PSA_SHOW | |
4453 | { | |
4454 | psa_t psa; | |
4455 | psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa)); | |
4456 | wv_psa_show(&psa); | |
4457 | } | |
4458 | #endif | |
4459 | #ifdef DEBUG_MMC_SHOW | |
4460 | wv_mmc_show(dev); | |
4461 | #endif | |
4462 | #ifdef DEBUG_I82593_SHOW | |
4463 | wv_ru_show(dev); | |
4464 | #endif | |
4465 | ||
4466 | /* We are no more waiting for something... */ | |
4467 | netif_wake_queue(dev); | |
4468 | ||
4469 | #ifdef DEBUG_INTERRUPT_TRACE | |
4470 | printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name); | |
4471 | #endif | |
4472 | } | |
4473 | ||
4474 | /********************* CONFIGURATION CALLBACKS *********************/ | |
4475 | /* | |
4476 | * Here are the functions called by the pcmcia package (cardmgr) and | |
4477 | * linux networking (NET3) for initialization, configuration and | |
4478 | * deinstallations of the Wavelan Pcmcia Hardware. | |
4479 | */ | |
4480 | ||
4481 | /*------------------------------------------------------------------*/ | |
4482 | /* | |
4483 | * Configure and start up the WaveLAN PCMCIA adaptor. | |
4484 | * Called by NET3 when it "open" the device. | |
4485 | */ | |
4486 | static int | |
4487 | wavelan_open(struct net_device * dev) | |
4488 | { | |
4489 | net_local * lp = netdev_priv(dev); | |
4490 | dev_link_t * link = lp->link; | |
4491 | kio_addr_t base = dev->base_addr; | |
4492 | ||
4493 | #ifdef DEBUG_CALLBACK_TRACE | |
4494 | printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name, | |
4495 | (unsigned int) dev); | |
4496 | #endif | |
4497 | ||
4498 | /* Check if the modem is powered up (wavelan_close() power it down */ | |
4499 | if(hasr_read(base) & HASR_NO_CLK) | |
4500 | { | |
4501 | /* Power up (power up time is 250us) */ | |
4502 | hacr_write(base, HACR_DEFAULT); | |
4503 | ||
4504 | /* Check if the module has been powered up... */ | |
4505 | if(hasr_read(base) & HASR_NO_CLK) | |
4506 | { | |
4507 | #ifdef DEBUG_CONFIG_ERRORS | |
4508 | printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n", | |
4509 | dev->name); | |
4510 | #endif | |
4511 | return FALSE; | |
4512 | } | |
4513 | } | |
4514 | ||
4515 | /* Start reception and declare the driver ready */ | |
4516 | if(!lp->configured) | |
4517 | return FALSE; | |
4518 | if(!wv_ru_start(dev)) | |
4519 | wv_hw_reset(dev); /* If problem : reset */ | |
4520 | netif_start_queue(dev); | |
4521 | ||
4522 | /* Mark the device as used */ | |
4523 | link->open++; | |
4524 | ||
4525 | #ifdef WAVELAN_ROAMING | |
4526 | if(do_roaming) | |
4527 | wv_roam_init(dev); | |
4528 | #endif /* WAVELAN_ROAMING */ | |
4529 | ||
4530 | #ifdef DEBUG_CALLBACK_TRACE | |
4531 | printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name); | |
4532 | #endif | |
4533 | return 0; | |
4534 | } | |
4535 | ||
4536 | /*------------------------------------------------------------------*/ | |
4537 | /* | |
4538 | * Shutdown the WaveLAN PCMCIA adaptor. | |
4539 | * Called by NET3 when it "close" the device. | |
4540 | */ | |
4541 | static int | |
4542 | wavelan_close(struct net_device * dev) | |
4543 | { | |
4544 | dev_link_t * link = ((net_local *)netdev_priv(dev))->link; | |
4545 | kio_addr_t base = dev->base_addr; | |
4546 | ||
4547 | #ifdef DEBUG_CALLBACK_TRACE | |
4548 | printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name, | |
4549 | (unsigned int) dev); | |
4550 | #endif | |
4551 | ||
4552 | /* If the device isn't open, then nothing to do */ | |
4553 | if(!link->open) | |
4554 | { | |
4555 | #ifdef DEBUG_CONFIG_INFO | |
4556 | printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name); | |
4557 | #endif | |
4558 | return 0; | |
4559 | } | |
4560 | ||
4561 | #ifdef WAVELAN_ROAMING | |
4562 | /* Cleanup of roaming stuff... */ | |
4563 | if(do_roaming) | |
4564 | wv_roam_cleanup(dev); | |
4565 | #endif /* WAVELAN_ROAMING */ | |
4566 | ||
4567 | link->open--; | |
4568 | ||
4569 | /* If the card is still present */ | |
4570 | if(netif_running(dev)) | |
4571 | { | |
4572 | netif_stop_queue(dev); | |
4573 | ||
4574 | /* Stop receiving new messages and wait end of transmission */ | |
4575 | wv_ru_stop(dev); | |
4576 | ||
4577 | /* Power down the module */ | |
4578 | hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT)); | |
4579 | } | |
4580 | ||
4581 | #ifdef DEBUG_CALLBACK_TRACE | |
4582 | printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name); | |
4583 | #endif | |
4584 | return 0; | |
4585 | } | |
4586 | ||
4587 | /*------------------------------------------------------------------*/ | |
4588 | /* | |
4589 | * wavelan_attach() creates an "instance" of the driver, allocating | |
4590 | * local data structures for one device (one interface). The device | |
4591 | * is registered with Card Services. | |
4592 | * | |
4593 | * The dev_link structure is initialized, but we don't actually | |
4594 | * configure the card at this point -- we wait until we receive a | |
4595 | * card insertion event. | |
4596 | */ | |
4597 | static dev_link_t * | |
4598 | wavelan_attach(void) | |
4599 | { | |
4600 | client_reg_t client_reg; /* Register with cardmgr */ | |
4601 | dev_link_t * link; /* Info for cardmgr */ | |
4602 | struct net_device * dev; /* Interface generic data */ | |
4603 | net_local * lp; /* Interface specific data */ | |
4604 | int ret; | |
4605 | ||
4606 | #ifdef DEBUG_CALLBACK_TRACE | |
4607 | printk(KERN_DEBUG "-> wavelan_attach()\n"); | |
4608 | #endif | |
4609 | ||
4610 | /* Initialize the dev_link_t structure */ | |
4611 | link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); | |
4612 | if (!link) return NULL; | |
4613 | memset(link, 0, sizeof(struct dev_link_t)); | |
4614 | ||
4615 | /* The io structure describes IO port mapping */ | |
4616 | link->io.NumPorts1 = 8; | |
4617 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; | |
4618 | link->io.IOAddrLines = 3; | |
4619 | ||
4620 | /* Interrupt setup */ | |
4621 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; | |
4622 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; | |
4623 | link->irq.Handler = wavelan_interrupt; | |
4624 | ||
4625 | /* General socket configuration */ | |
4626 | link->conf.Attributes = CONF_ENABLE_IRQ; | |
4627 | link->conf.Vcc = 50; | |
4628 | link->conf.IntType = INT_MEMORY_AND_IO; | |
4629 | ||
4630 | /* Chain drivers */ | |
4631 | link->next = dev_list; | |
4632 | dev_list = link; | |
4633 | ||
4634 | /* Allocate the generic data structure */ | |
4635 | dev = alloc_etherdev(sizeof(net_local)); | |
4636 | if (!dev) { | |
4637 | kfree(link); | |
4638 | return NULL; | |
4639 | } | |
4640 | link->priv = link->irq.Instance = dev; | |
4641 | ||
4642 | lp = netdev_priv(dev); | |
4643 | ||
4644 | /* Init specific data */ | |
4645 | lp->configured = 0; | |
4646 | lp->reconfig_82593 = FALSE; | |
4647 | lp->nresets = 0; | |
4648 | /* Multicast stuff */ | |
4649 | lp->promiscuous = 0; | |
4650 | lp->allmulticast = 0; | |
4651 | lp->mc_count = 0; | |
4652 | ||
4653 | /* Init spinlock */ | |
4654 | spin_lock_init(&lp->spinlock); | |
4655 | ||
4656 | /* back links */ | |
4657 | lp->link = link; | |
4658 | lp->dev = dev; | |
4659 | ||
4660 | /* wavelan NET3 callbacks */ | |
4661 | SET_MODULE_OWNER(dev); | |
4662 | dev->open = &wavelan_open; | |
4663 | dev->stop = &wavelan_close; | |
4664 | dev->hard_start_xmit = &wavelan_packet_xmit; | |
4665 | dev->get_stats = &wavelan_get_stats; | |
4666 | dev->set_multicast_list = &wavelan_set_multicast_list; | |
4667 | #ifdef SET_MAC_ADDRESS | |
4668 | dev->set_mac_address = &wavelan_set_mac_address; | |
4669 | #endif /* SET_MAC_ADDRESS */ | |
4670 | ||
4671 | /* Set the watchdog timer */ | |
4672 | dev->tx_timeout = &wavelan_watchdog; | |
4673 | dev->watchdog_timeo = WATCHDOG_JIFFIES; | |
4674 | SET_ETHTOOL_OPS(dev, &ops); | |
4675 | ||
4676 | #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */ | |
4677 | dev->wireless_handlers = &wavelan_handler_def; | |
4678 | lp->wireless_data.spy_data = &lp->spy_data; | |
4679 | dev->wireless_data = &lp->wireless_data; | |
4680 | #endif | |
4681 | ||
4682 | /* Other specific data */ | |
4683 | dev->mtu = WAVELAN_MTU; | |
4684 | ||
4685 | /* Register with Card Services */ | |
4686 | client_reg.dev_info = &dev_info; | |
4687 | client_reg.EventMask = | |
4688 | CS_EVENT_REGISTRATION_COMPLETE | | |
4689 | CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | | |
4690 | CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | | |
4691 | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME; | |
4692 | client_reg.event_handler = &wavelan_event; | |
4693 | client_reg.Version = 0x0210; | |
4694 | client_reg.event_callback_args.client_data = link; | |
4695 | ||
4696 | #ifdef DEBUG_CONFIG_INFO | |
4697 | printk(KERN_DEBUG "wavelan_attach(): almost done, calling pcmcia_register_client\n"); | |
4698 | #endif | |
4699 | ||
4700 | ret = pcmcia_register_client(&link->handle, &client_reg); | |
4701 | if(ret != 0) | |
4702 | { | |
4703 | cs_error(link->handle, RegisterClient, ret); | |
4704 | wavelan_detach(link); | |
4705 | return NULL; | |
4706 | } | |
4707 | ||
4708 | #ifdef DEBUG_CALLBACK_TRACE | |
4709 | printk(KERN_DEBUG "<- wavelan_attach()\n"); | |
4710 | #endif | |
4711 | ||
4712 | return link; | |
4713 | } | |
4714 | ||
4715 | /*------------------------------------------------------------------*/ | |
4716 | /* | |
4717 | * This deletes a driver "instance". The device is de-registered with | |
4718 | * Card Services. If it has been released, all local data structures | |
4719 | * are freed. Otherwise, the structures will be freed when the device | |
4720 | * is released. | |
4721 | */ | |
4722 | static void | |
4723 | wavelan_detach(dev_link_t * link) | |
4724 | { | |
4725 | #ifdef DEBUG_CALLBACK_TRACE | |
4726 | printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link); | |
4727 | #endif | |
4728 | ||
4729 | /* | |
4730 | * If the device is currently configured and active, we won't | |
4731 | * actually delete it yet. Instead, it is marked so that when the | |
4732 | * release() function is called, that will trigger a proper | |
4733 | * detach(). | |
4734 | */ | |
4735 | if(link->state & DEV_CONFIG) | |
4736 | { | |
4737 | /* Some others haven't done their job : give them another chance */ | |
4738 | wv_pcmcia_release(link); | |
4739 | } | |
4740 | ||
4741 | /* Break the link with Card Services */ | |
4742 | if(link->handle) | |
4743 | pcmcia_deregister_client(link->handle); | |
4744 | ||
4745 | /* Remove the interface data from the linked list */ | |
4746 | if(dev_list == link) | |
4747 | dev_list = link->next; | |
4748 | else | |
4749 | { | |
4750 | dev_link_t * prev = dev_list; | |
4751 | ||
4752 | while((prev != (dev_link_t *) NULL) && (prev->next != link)) | |
4753 | prev = prev->next; | |
4754 | ||
4755 | if(prev == (dev_link_t *) NULL) | |
4756 | { | |
4757 | #ifdef DEBUG_CONFIG_ERRORS | |
4758 | printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.\n"); | |
4759 | #endif | |
4760 | return; | |
4761 | } | |
4762 | ||
4763 | prev->next = link->next; | |
4764 | } | |
4765 | ||
4766 | /* Free pieces */ | |
4767 | if(link->priv) | |
4768 | { | |
4769 | struct net_device * dev = (struct net_device *) link->priv; | |
4770 | ||
4771 | /* Remove ourselves from the kernel list of ethernet devices */ | |
4772 | /* Warning : can't be called from interrupt, timer or wavelan_close() */ | |
4773 | if (link->dev) | |
4774 | unregister_netdev(dev); | |
4775 | link->dev = NULL; | |
4776 | ((net_local *)netdev_priv(dev))->link = NULL; | |
4777 | ((net_local *)netdev_priv(dev))->dev = NULL; | |
4778 | free_netdev(dev); | |
4779 | } | |
4780 | kfree(link); | |
4781 | ||
4782 | #ifdef DEBUG_CALLBACK_TRACE | |
4783 | printk(KERN_DEBUG "<- wavelan_detach()\n"); | |
4784 | #endif | |
4785 | } | |
4786 | ||
4787 | /*------------------------------------------------------------------*/ | |
4788 | /* | |
4789 | * The card status event handler. Mostly, this schedules other stuff | |
4790 | * to run after an event is received. A CARD_REMOVAL event also sets | |
4791 | * some flags to discourage the net drivers from trying to talk to the | |
4792 | * card any more. | |
4793 | */ | |
4794 | static int | |
4795 | wavelan_event(event_t event, /* The event received */ | |
4796 | int priority, | |
4797 | event_callback_args_t * args) | |
4798 | { | |
4799 | dev_link_t * link = (dev_link_t *) args->client_data; | |
4800 | struct net_device * dev = (struct net_device *) link->priv; | |
4801 | ||
4802 | #ifdef DEBUG_CALLBACK_TRACE | |
4803 | printk(KERN_DEBUG "->wavelan_event(): %s\n", | |
4804 | ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" : | |
4805 | ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" : | |
4806 | ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" : | |
4807 | ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" : | |
4808 | ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" : | |
4809 | ((event == CS_EVENT_PM_RESUME) ? "pm resume" : | |
4810 | ((event == CS_EVENT_CARD_RESET) ? "card reset" : | |
4811 | "unknown")))))))); | |
4812 | #endif | |
4813 | ||
4814 | switch(event) | |
4815 | { | |
4816 | case CS_EVENT_REGISTRATION_COMPLETE: | |
4817 | #ifdef DEBUG_CONFIG_INFO | |
4818 | printk(KERN_DEBUG "wavelan_cs: registration complete\n"); | |
4819 | #endif | |
4820 | break; | |
4821 | ||
4822 | case CS_EVENT_CARD_REMOVAL: | |
4823 | /* Oups ! The card is no more there */ | |
4824 | link->state &= ~DEV_PRESENT; | |
4825 | if(link->state & DEV_CONFIG) | |
4826 | { | |
4827 | /* Accept no more transmissions */ | |
4828 | netif_device_detach(dev); | |
4829 | ||
4830 | /* Release the card */ | |
4831 | wv_pcmcia_release(link); | |
4832 | } | |
4833 | break; | |
4834 | ||
4835 | case CS_EVENT_CARD_INSERTION: | |
4836 | /* Reset and configure the card */ | |
4837 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; | |
4838 | if(wv_pcmcia_config(link) && | |
4839 | wv_hw_config(dev)) | |
4840 | wv_init_info(dev); | |
4841 | else | |
4842 | dev->irq = 0; | |
4843 | break; | |
4844 | ||
4845 | case CS_EVENT_PM_SUSPEND: | |
4846 | /* NB: wavelan_close will be called, but too late, so we are | |
4847 | * obliged to close nicely the wavelan here. David, could you | |
4848 | * close the device before suspending them ? And, by the way, | |
4849 | * could you, on resume, add a "route add -net ..." after the | |
4850 | * ifconfig up ? Thanks... */ | |
4851 | ||
4852 | /* Stop receiving new messages and wait end of transmission */ | |
4853 | wv_ru_stop(dev); | |
4854 | ||
4855 | /* Power down the module */ | |
4856 | hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT)); | |
4857 | ||
4858 | /* The card is now suspended */ | |
4859 | link->state |= DEV_SUSPEND; | |
4860 | /* Fall through... */ | |
4861 | case CS_EVENT_RESET_PHYSICAL: | |
4862 | if(link->state & DEV_CONFIG) | |
4863 | { | |
4864 | if(link->open) | |
4865 | netif_device_detach(dev); | |
4866 | pcmcia_release_configuration(link->handle); | |
4867 | } | |
4868 | break; | |
4869 | ||
4870 | case CS_EVENT_PM_RESUME: | |
4871 | link->state &= ~DEV_SUSPEND; | |
4872 | /* Fall through... */ | |
4873 | case CS_EVENT_CARD_RESET: | |
4874 | if(link->state & DEV_CONFIG) | |
4875 | { | |
4876 | pcmcia_request_configuration(link->handle, &link->conf); | |
4877 | if(link->open) /* If RESET -> True, If RESUME -> False ? */ | |
4878 | { | |
4879 | wv_hw_reset(dev); | |
4880 | netif_device_attach(dev); | |
4881 | } | |
4882 | } | |
4883 | break; | |
4884 | } | |
4885 | ||
4886 | #ifdef DEBUG_CALLBACK_TRACE | |
4887 | printk(KERN_DEBUG "<-wavelan_event()\n"); | |
4888 | #endif | |
4889 | return 0; | |
4890 | } | |
4891 | ||
4892 | static struct pcmcia_driver wavelan_driver = { | |
4893 | .owner = THIS_MODULE, | |
4894 | .drv = { | |
4895 | .name = "wavelan_cs", | |
4896 | }, | |
4897 | .attach = wavelan_attach, | |
4898 | .detach = wavelan_detach, | |
4899 | }; | |
4900 | ||
4901 | static int __init | |
4902 | init_wavelan_cs(void) | |
4903 | { | |
4904 | return pcmcia_register_driver(&wavelan_driver); | |
4905 | } | |
4906 | ||
4907 | static void __exit | |
4908 | exit_wavelan_cs(void) | |
4909 | { | |
4910 | pcmcia_unregister_driver(&wavelan_driver); | |
4911 | } | |
4912 | ||
4913 | module_init(init_wavelan_cs); | |
4914 | module_exit(exit_wavelan_cs); |