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