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