Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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