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