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.
12 * AT&T GIS (nee NCR) WaveLAN card:
13 * An Ethernet-like radio transceiver
14 * controlled by an Intel 82586 coprocessor.
17 #include "wavelan.p.h" /* Private header */
19 /************************* MISC SUBROUTINES **************************/
21 * Subroutines which won't fit in one of the following category
22 * (WaveLAN modem or i82586)
25 /*------------------------------------------------------------------*/
27 * Translate irq number to PSA irq parameter
29 static u8 wv_irq_to_psa(int irq)
31 if (irq < 0 || irq >= ARRAY_SIZE(irqvals))
37 /*------------------------------------------------------------------*/
39 * Translate PSA irq parameter to irq number
41 static int __init wv_psa_to_irq(u8 irqval)
45 for (i = 0; i < ARRAY_SIZE(irqvals); i++)
46 if (irqvals[i] == irqval)
52 /********************* HOST ADAPTER SUBROUTINES *********************/
54 * Useful subroutines to manage the WaveLAN ISA interface
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.
61 /*------------------------------------------------------------------*/
63 * Read from card's Host Adaptor Status Register.
65 static inline u16 hasr_read(unsigned long ioaddr)
67 return inw(HASR(ioaddr));
70 /*------------------------------------------------------------------*/
72 * Write to card's Host Adapter Command Register.
74 static inline void hacr_write(unsigned long ioaddr, u16 hacr)
76 outw(hacr, HACR(ioaddr));
79 /*------------------------------------------------------------------*/
81 * Write to card's Host Adapter Command Register. Include a delay for
82 * those times when it is needed.
84 static void hacr_write_slow(unsigned long ioaddr, u16 hacr)
86 hacr_write(ioaddr, hacr);
87 /* delay might only be needed sometimes */
89 } /* hacr_write_slow */
91 /*------------------------------------------------------------------*/
93 * Set the channel attention bit.
95 static inline void set_chan_attn(unsigned long ioaddr, u16 hacr)
97 hacr_write(ioaddr, hacr | HACR_CA);
100 /*------------------------------------------------------------------*/
102 * Reset, and then set host adaptor into default mode.
104 static inline void wv_hacr_reset(unsigned long ioaddr)
106 hacr_write_slow(ioaddr, HACR_RESET);
107 hacr_write(ioaddr, HACR_DEFAULT);
108 } /* wv_hacr_reset */
110 /*------------------------------------------------------------------*/
112 * Set the I/O transfer over the ISA bus to 8-bit mode
114 static inline void wv_16_off(unsigned long ioaddr, u16 hacr)
116 hacr &= ~HACR_16BITS;
117 hacr_write(ioaddr, hacr);
120 /*------------------------------------------------------------------*/
122 * Set the I/O transfer over the ISA bus to 8-bit mode
124 static inline void wv_16_on(unsigned long ioaddr, u16 hacr)
127 hacr_write(ioaddr, hacr);
130 /*------------------------------------------------------------------*/
132 * Disable interrupts on the WaveLAN hardware.
133 * (called by wv_82586_stop())
135 static inline void wv_ints_off(struct net_device *dev)
137 net_local *lp = netdev_priv(dev);
138 unsigned long ioaddr = dev->base_addr;
140 lp->hacr &= ~HACR_INTRON;
141 hacr_write(ioaddr, lp->hacr);
144 /*------------------------------------------------------------------*/
146 * Enable interrupts on the WaveLAN hardware.
147 * (called by wv_hw_reset())
149 static inline void wv_ints_on(struct net_device *dev)
151 net_local *lp = netdev_priv(dev);
152 unsigned long ioaddr = dev->base_addr;
154 lp->hacr |= HACR_INTRON;
155 hacr_write(ioaddr, lp->hacr);
158 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
160 * Useful subroutines to manage the modem of the WaveLAN
163 /*------------------------------------------------------------------*/
165 * Read the Parameter Storage Area from the WaveLAN card's memory
168 * Read bytes from the PSA.
170 static void psa_read(unsigned long ioaddr,
172 int o, /* offset in PSA */
173 u8 *b, /*buffer to fill */
176 wv_16_off(ioaddr, hacr);
179 outw(o, PIOR2(ioaddr));
181 *b++ = inb(PIOP2(ioaddr));
184 wv_16_on(ioaddr, hacr);
187 /*------------------------------------------------------------------*/
189 * Write the Parameter Storage Area to the WaveLAN card's memory.
191 static void psa_write(unsigned long ioaddr,
193 int o, /* Offset in PSA */
194 u8 *b, /*buffer in memory */
196 { /* Length of buffer */
199 wv_16_off(ioaddr, hacr);
202 outw(o, PIOR2(ioaddr));
205 outb(*b, PIOP2(ioaddr));
208 /* Wait for the memory to finish its write cycle */
210 while ((count++ < 100) && (hasr_read(ioaddr) & HASR_PSA_BUSY))
214 wv_16_on(ioaddr, hacr);
218 /*------------------------------------------------------------------*/
220 * Calculate the PSA CRC
221 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
222 * NOTE: By specifying a length including the CRC position the
223 * returned value should be zero. (i.e. a correct checksum in the PSA)
225 * The Windows drivers don't use the CRC, but the AP and the PtP tool
228 static u16 psa_crc(u8 *psa, /* The PSA */
230 { /* Number of short for CRC */
231 int byte_cnt; /* Loop on the PSA */
232 u16 crc_bytes = 0; /* Data in the PSA */
233 int bit_cnt; /* Loop on the bits of the short */
235 for (byte_cnt = 0; byte_cnt < size; byte_cnt++) {
236 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
238 for (bit_cnt = 1; bit_cnt < 9; bit_cnt++) {
239 if (crc_bytes & 0x0001)
240 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
248 #endif /* SET_PSA_CRC */
250 /*------------------------------------------------------------------*/
252 * update the checksum field in the Wavelan's PSA
254 static void update_psa_checksum(struct net_device *dev,
255 unsigned long ioaddr,
262 /* read the parameter storage area */
263 psa_read(ioaddr, hacr, 0, (unsigned char *) &psa, sizeof(psa));
265 /* update the checksum */
266 crc = psa_crc((unsigned char *) &psa,
267 sizeof(psa) - sizeof(psa.psa_crc[0]) -
268 sizeof(psa.psa_crc[1])
269 - sizeof(psa.psa_crc_status));
271 psa.psa_crc[0] = crc & 0xFF;
272 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
275 psa_write(ioaddr, hacr, (char *) &psa.psa_crc - (char *) &psa,
276 (unsigned char *) &psa.psa_crc, 2);
278 #ifdef DEBUG_IOCTL_INFO
279 printk(KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
280 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
282 /* Check again (luxury !) */
283 crc = psa_crc((unsigned char *) &psa,
284 sizeof(psa) - sizeof(psa.psa_crc_status));
288 "%s: update_psa_checksum(): CRC does not \
289 agree with PSA data (even after recalculating)\n",
291 #endif /* DEBUG_IOCTL_INFO */
292 #endif /* SET_PSA_CRC */
293 } /* update_psa_checksum */
295 /*------------------------------------------------------------------*/
297 * Write 1 byte to the MMC.
299 static void mmc_out(unsigned long ioaddr, u16 o, u8 d)
303 /* Wait for MMC to go idle */
304 while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
307 outw((u16) (((u16) d << 8) | (o << 1) | 1), MMCR(ioaddr));
310 /*------------------------------------------------------------------*/
312 * Routine to write bytes to the Modem Management Controller.
313 * We start at the end because it is the way it should be!
315 static void mmc_write(unsigned long ioaddr, u8 o, u8 *b, int n)
321 mmc_out(ioaddr, --o, *(--b));
324 /*------------------------------------------------------------------*/
326 * Read a byte from the MMC.
327 * Optimised version for 1 byte, avoid using memory.
329 static u8 mmc_in(unsigned long ioaddr, u16 o)
333 while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
335 outw(o << 1, MMCR(ioaddr));
337 while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
339 return (u8) (inw(MMCR(ioaddr)) >> 8);
342 /*------------------------------------------------------------------*/
344 * Routine to read bytes from the Modem Management Controller.
345 * The implementation is complicated by a lack of address lines,
346 * which prevents decoding of the low-order bit.
347 * (code has just been moved in the above function)
348 * We start at the end because it is the way it should be!
350 static inline void mmc_read(unsigned long ioaddr, u8 o, u8 *b, int n)
356 *(--b) = mmc_in(ioaddr, --o);
359 /*------------------------------------------------------------------*/
361 * Get the type of encryption available.
363 static inline int mmc_encr(unsigned long ioaddr)
364 { /* I/O port of the card */
367 temp = mmc_in(ioaddr, mmroff(0, mmr_des_avail));
368 if ((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
374 /*------------------------------------------------------------------*/
376 * Wait for the frequency EEPROM to complete a command.
377 * I hope this one will be optimally inlined.
379 static inline void fee_wait(unsigned long ioaddr, /* I/O port of the card */
380 int delay, /*base delay to wait for */
382 { /* Number of time to wait */
383 int count = 0; /* Wait only a limited time */
385 while ((count++ < number) &&
386 (mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
387 MMR_FEE_STATUS_BUSY))
391 /*------------------------------------------------------------------*/
393 * Read bytes from the Frequency EEPROM (frequency select cards).
395 static void fee_read(unsigned long ioaddr, /* I/O port of the card */
396 u16 o, /* destination offset */
397 u16 *b, /* data buffer */
399 { /* number of registers */
400 b += n; /* Position at the end of the area */
402 /* Write the address */
403 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
405 /* Loop on all buffer */
407 /* Write the read command */
408 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
411 /* Wait until EEPROM is ready (should be quick). */
412 fee_wait(ioaddr, 10, 100);
414 /* Read the value. */
415 *--b = ((mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)) << 8) |
416 mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
421 /*------------------------------------------------------------------*/
423 * Write bytes from the Frequency EEPROM (frequency select cards).
424 * This is a bit complicated, because the frequency EEPROM has to
425 *be unprotected and the write enabled.
428 static void fee_write(unsigned long ioaddr, /* I/O port of the card */
429 u16 o, /* destination offset */
430 u16 *b, /* data buffer */
432 { /* number of registers */
433 b += n; /* Position at the end of the area. */
435 #ifdef EEPROM_IS_PROTECTED /* disabled */
436 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
437 /* Ask to read the protected register */
438 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
440 fee_wait(ioaddr, 10, 100);
442 /* Read the protected register. */
443 printk("Protected 2: %02X-%02X\n",
444 mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)),
445 mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
446 #endif /* DOESNT_SEEM_TO_WORK */
448 /* Enable protected register. */
449 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
450 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
452 fee_wait(ioaddr, 10, 100);
454 /* Unprotect area. */
455 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n);
456 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
457 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
459 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
460 #endif /* DOESNT_SEEM_TO_WORK */
462 fee_wait(ioaddr, 10, 100);
463 #endif /* EEPROM_IS_PROTECTED */
466 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
467 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
469 fee_wait(ioaddr, 10, 100);
471 /* Write the EEPROM address. */
472 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
474 /* Loop on all buffer */
476 /* Write the value. */
477 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
478 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
480 /* Write the write command. */
481 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
484 /* WaveLAN documentation says to
485 * wait at least 10 ms for EEBUSY = 0
488 fee_wait(ioaddr, 10, 100);
492 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
493 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
495 fee_wait(ioaddr, 10, 100);
497 #ifdef EEPROM_IS_PROTECTED /* disabled */
498 /* Reprotect EEPROM. */
499 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x00);
500 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
502 fee_wait(ioaddr, 10, 100);
503 #endif /* EEPROM_IS_PROTECTED */
506 /************************ I82586 SUBROUTINES *************************/
508 * Useful subroutines to manage the Ethernet controller
511 /*------------------------------------------------------------------*/
513 * Read bytes from the on-board RAM.
514 * Why does inlining this function make it fail?
516 static /*inline */ void obram_read(unsigned long ioaddr,
519 outw(o, PIOR1(ioaddr));
520 insw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
523 /*------------------------------------------------------------------*/
525 * Write bytes to the on-board RAM.
527 static inline void obram_write(unsigned long ioaddr, u16 o, u8 *b, int n)
529 outw(o, PIOR1(ioaddr));
530 outsw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
533 /*------------------------------------------------------------------*/
535 * Acknowledge the reading of the status issued by the i82586.
537 static void wv_ack(struct net_device *dev)
539 net_local *lp = netdev_priv(dev);
540 unsigned long ioaddr = dev->base_addr;
544 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
545 (unsigned char *) &scb_cs, sizeof(scb_cs));
546 scb_cs &= SCB_ST_INT;
551 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
552 (unsigned char *) &scb_cs, sizeof(scb_cs));
554 set_chan_attn(ioaddr, lp->hacr);
556 for (i = 1000; i > 0; i--) {
557 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
558 (unsigned char *) &scb_cs, sizeof(scb_cs));
566 #ifdef DEBUG_CONFIG_ERROR
569 "%s: wv_ack(): board not accepting command.\n",
574 /*------------------------------------------------------------------*/
576 * Set channel attention bit and busy wait until command has
577 * completed, then acknowledge completion of the command.
579 static int wv_synchronous_cmd(struct net_device *dev, const char *str)
581 net_local *lp = netdev_priv(dev);
582 unsigned long ioaddr = dev->base_addr;
587 scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO;
588 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
589 (unsigned char *) &scb_cmd, sizeof(scb_cmd));
591 set_chan_attn(ioaddr, lp->hacr);
593 for (i = 1000; i > 0; i--) {
594 obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb,
596 if (cb.ac_status & AC_SFLD_C)
603 if (i <= 0 || !(cb.ac_status & AC_SFLD_OK)) {
604 #ifdef DEBUG_CONFIG_ERROR
605 printk(KERN_INFO "%s: %s failed; status = 0x%x\n",
606 dev->name, str, cb.ac_status);
608 #ifdef DEBUG_I82586_SHOW
620 /*------------------------------------------------------------------*/
622 * Configuration commands completion interrupt.
623 * Check if done, and if OK.
626 wv_config_complete(struct net_device *dev, unsigned long ioaddr, net_local * lp)
628 unsigned short mcs_addr;
629 unsigned short status;
632 #ifdef DEBUG_INTERRUPT_TRACE
633 printk(KERN_DEBUG "%s: ->wv_config_complete()\n", dev->name);
636 mcs_addr = lp->tx_first_in_use + sizeof(ac_tx_t) + sizeof(ac_nop_t)
637 + sizeof(tbd_t) + sizeof(ac_cfg_t) + sizeof(ac_ias_t);
639 /* Read the status of the last command (set mc list). */
640 obram_read(ioaddr, acoff(mcs_addr, ac_status),
641 (unsigned char *) &status, sizeof(status));
643 /* If not completed -> exit */
644 if ((status & AC_SFLD_C) == 0)
645 ret = 0; /* Not ready to be scrapped */
647 #ifdef DEBUG_CONFIG_ERROR
648 unsigned short cfg_addr;
649 unsigned short ias_addr;
651 /* Check mc_config command */
652 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
654 "%s: wv_config_complete(): \
655 set_multicast_address failed; status = 0x%x\n",
658 /* check ia-config command */
659 ias_addr = mcs_addr - sizeof(ac_ias_t);
660 obram_read(ioaddr, acoff(ias_addr, ac_status),
661 (unsigned char *) &status, sizeof(status));
662 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
664 "%s: wv_config_complete(): set_MAC_address \
665 failed; status = 0x%x\n",
668 /* Check config command. */
669 cfg_addr = ias_addr - sizeof(ac_cfg_t);
670 obram_read(ioaddr, acoff(cfg_addr, ac_status),
671 (unsigned char *) &status, sizeof(status));
672 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
674 "%s: wv_config_complete(): configure failed; \
677 #endif /* DEBUG_CONFIG_ERROR */
679 ret = 1; /* Ready to be scrapped */
682 #ifdef DEBUG_INTERRUPT_TRACE
683 printk(KERN_DEBUG "%s: <-wv_config_complete() - %d\n", dev->name,
689 /*------------------------------------------------------------------*/
691 * Command completion interrupt.
692 * Reclaim as many freed tx buffers as we can.
693 * (called in wavelan_interrupt()).
694 * Note : the spinlock is already grabbed for us.
696 static int wv_complete(struct net_device *dev,
697 unsigned long ioaddr,
702 #ifdef DEBUG_INTERRUPT_TRACE
703 printk(KERN_DEBUG "%s: ->wv_complete()\n", dev->name);
706 /* Loop on all the transmit buffers */
707 while (lp->tx_first_in_use != I82586NULL) {
708 unsigned short tx_status;
710 /* Read the first transmit buffer */
711 obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status),
712 (unsigned char *) &tx_status,
715 /* If not completed -> exit */
716 if ((tx_status & AC_SFLD_C) == 0)
719 /* Hack for reconfiguration */
720 if (tx_status == 0xFFFF)
721 if (!wv_config_complete(dev, ioaddr, lp))
722 break; /* Not completed */
724 /* We now remove this buffer */
729 if (lp->tx_n_in_use > 0)
730 printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
733 /* Was it the last one? */
734 if (lp->tx_n_in_use <= 0)
735 lp->tx_first_in_use = I82586NULL;
737 /* Next one in the chain */
738 lp->tx_first_in_use += TXBLOCKZ;
739 if (lp->tx_first_in_use >=
740 OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
741 lp->tx_first_in_use -= NTXBLOCKS * TXBLOCKZ;
744 /* Hack for reconfiguration */
745 if (tx_status == 0xFFFF)
748 /* Now, check status of the finished command */
749 if (tx_status & AC_SFLD_OK) {
752 dev->stats.tx_packets++;
753 ncollisions = tx_status & AC_SFLD_MAXCOL;
754 dev->stats.collisions += ncollisions;
758 "%s: wv_complete(): tx completed after \
760 dev->name, ncollisions);
763 dev->stats.tx_errors++;
764 if (tx_status & AC_SFLD_S10) {
765 dev->stats.tx_carrier_errors++;
768 "%s: wv_complete(): tx error: no CS.\n",
772 if (tx_status & AC_SFLD_S9) {
773 dev->stats.tx_carrier_errors++;
776 "%s: wv_complete(): tx error: \
781 if (tx_status & AC_SFLD_S8) {
782 dev->stats.tx_fifo_errors++;
785 "%s: wv_complete(): tx error: \
790 if (tx_status & AC_SFLD_S6) {
791 dev->stats.tx_heartbeat_errors++;
794 "%s: wv_complete(): tx error: \
799 if (tx_status & AC_SFLD_S5) {
800 dev->stats.tx_aborted_errors++;
803 "%s: wv_complete(): tx error: \
804 too many collisions.\n",
812 "%s: wv_complete(): tx completed, tx_status 0x%04x\n",
813 dev->name, tx_status);
817 #ifdef DEBUG_INTERRUPT_INFO
819 printk(KERN_DEBUG "%s: wv_complete(): reaped %d\n",
824 * Inform upper layers.
826 if (lp->tx_n_in_use < NTXBLOCKS - 1)
827 netif_wake_queue(dev);
829 #ifdef DEBUG_INTERRUPT_TRACE
830 printk(KERN_DEBUG "%s: <-wv_complete()\n", dev->name);
835 /*------------------------------------------------------------------*/
837 * Reconfigure the i82586, or at least ask for it.
838 *because wv_82586_config uses a transmission buffer, we must do it
839 * when we are sure that there is one left, so we do it now
840 * or in wavelan_packet_xmit() (I can't find any better place,
841 * wavelan_interrupt is not an option), so you may experience
844 static void wv_82586_reconfig(struct net_device *dev)
846 net_local *lp = netdev_priv(dev);
849 /* Arm the flag, will be cleard in wv_82586_config() */
850 lp->reconfig_82586 = 1;
852 /* Check if we can do it now ! */
853 if ((netif_running(dev)) && !(netif_queue_stopped(dev))) {
854 spin_lock_irqsave(&lp->spinlock, flags);
856 wv_82586_config(dev);
857 spin_unlock_irqrestore(&lp->spinlock, flags);
859 #ifdef DEBUG_CONFIG_INFO
861 "%s: wv_82586_reconfig(): delayed (state = %lX)\n",
862 dev->name, dev->state);
867 /********************* DEBUG & INFO SUBROUTINES *********************/
869 * This routine is used in the code to show information for debugging.
870 * Most of the time, it dumps the contents of hardware structures.
873 #ifdef DEBUG_PSA_SHOW
874 /*------------------------------------------------------------------*/
876 * Print the formatted contents of the Parameter Storage Area.
878 static void wv_psa_show(psa_t *p)
880 printk(KERN_DEBUG "##### WaveLAN PSA contents: #####\n");
881 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
882 p->psa_io_base_addr_1,
883 p->psa_io_base_addr_2,
884 p->psa_io_base_addr_3, p->psa_io_base_addr_4);
885 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
886 p->psa_rem_boot_addr_1,
887 p->psa_rem_boot_addr_2, p->psa_rem_boot_addr_3);
888 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
889 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
890 #ifdef DEBUG_SHOW_UNUSED
891 printk(KERN_DEBUG "psa_unused0[]: %pM\n", p->psa_unused0);
892 #endif /* DEBUG_SHOW_UNUSED */
893 printk(KERN_DEBUG "psa_univ_mac_addr[]: %pM\n", p->psa_univ_mac_addr);
894 printk(KERN_DEBUG "psa_local_mac_addr[]: %pM\n", p->psa_local_mac_addr);
895 printk(KERN_DEBUG "psa_univ_local_sel: %d, ",
896 p->psa_univ_local_sel);
897 printk("psa_comp_number: %d, ", p->psa_comp_number);
898 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
899 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
900 p->psa_feature_select);
901 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
902 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
903 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
904 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0],
906 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
907 printk(KERN_DEBUG "psa_encryption_select: %d, ",
908 p->psa_encryption_select);
910 ("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
911 p->psa_encryption_key[0], p->psa_encryption_key[1],
912 p->psa_encryption_key[2], p->psa_encryption_key[3],
913 p->psa_encryption_key[4], p->psa_encryption_key[5],
914 p->psa_encryption_key[6], p->psa_encryption_key[7]);
915 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
916 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
917 p->psa_call_code[0]);
919 ("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
920 p->psa_call_code[0], p->psa_call_code[1], p->psa_call_code[2],
921 p->psa_call_code[3], p->psa_call_code[4], p->psa_call_code[5],
922 p->psa_call_code[6], p->psa_call_code[7]);
923 #ifdef DEBUG_SHOW_UNUSED
924 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X\n",
927 #endif /* DEBUG_SHOW_UNUSED */
928 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
929 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
930 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
932 #endif /* DEBUG_PSA_SHOW */
934 #ifdef DEBUG_MMC_SHOW
935 /*------------------------------------------------------------------*/
937 * Print the formatted status of the Modem Management Controller.
938 * This function needs to be completed.
940 static void wv_mmc_show(struct net_device *dev)
942 unsigned long ioaddr = dev->base_addr;
943 net_local *lp = netdev_priv(dev);
947 if (hasr_read(ioaddr) & HASR_NO_CLK) {
949 "%s: wv_mmc_show: modem not connected\n",
955 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
956 mmc_read(ioaddr, 0, (u8 *) &m, sizeof(m));
957 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
959 /* Don't forget to update statistics */
960 lp->wstats.discard.nwid +=
961 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
963 printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n");
964 #ifdef DEBUG_SHOW_UNUSED
966 "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
967 m.mmr_unused0[0], m.mmr_unused0[1], m.mmr_unused0[2],
968 m.mmr_unused0[3], m.mmr_unused0[4], m.mmr_unused0[5],
969 m.mmr_unused0[6], m.mmr_unused0[7]);
970 #endif /* DEBUG_SHOW_UNUSED */
971 printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
972 m.mmr_des_avail, m.mmr_des_status);
973 #ifdef DEBUG_SHOW_UNUSED
974 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
977 m.mmr_unused1[2], m.mmr_unused1[3], m.mmr_unused1[4]);
978 #endif /* DEBUG_SHOW_UNUSED */
979 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
982 mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ?
983 "energy detected," : "",
985 mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
986 "loop test indicated," : "",
988 mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ?
989 "transmitter on," : "",
991 mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
992 "jabber timer expired," : "");
993 printk(KERN_DEBUG "Dsp ID: %02X\n", m.mmr_dsp_id);
994 #ifdef DEBUG_SHOW_UNUSED
995 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
996 m.mmr_unused2[0], m.mmr_unused2[1]);
997 #endif /* DEBUG_SHOW_UNUSED */
998 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
999 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1000 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1001 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1002 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1004 mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" :
1006 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1007 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1009 mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" :
1011 printk("silence_lvl: %d [%s], ",
1012 m.mmr_silence_lvl & MMR_SILENCE_LVL,
1014 mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" :
1016 printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1018 mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" :
1020 #ifdef DEBUG_SHOW_UNUSED
1021 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1022 #endif /* DEBUG_SHOW_UNUSED */
1024 #endif /* DEBUG_MMC_SHOW */
1026 #ifdef DEBUG_I82586_SHOW
1027 /*------------------------------------------------------------------*/
1029 * Print the last block of the i82586 memory.
1031 static void wv_scb_show(unsigned long ioaddr)
1035 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
1038 printk(KERN_DEBUG "##### WaveLAN system control block: #####\n");
1040 printk(KERN_DEBUG "status: ");
1041 printk("stat 0x%x[%s%s%s%s] ",
1043 scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA |
1046 scb_status & SCB_ST_CX) ? "command completion interrupt," :
1047 "", (scb.scb_status & SCB_ST_FR) ? "frame received," : "",
1049 scb_status & SCB_ST_CNA) ? "command unit not active," : "",
1051 scb_status & SCB_ST_RNR) ? "receiving unit not ready," :
1053 printk("cus 0x%x[%s%s%s] ", (scb.scb_status & SCB_ST_CUS) >> 8,
1054 ((scb.scb_status & SCB_ST_CUS) ==
1055 SCB_ST_CUS_IDLE) ? "idle" : "",
1056 ((scb.scb_status & SCB_ST_CUS) ==
1057 SCB_ST_CUS_SUSP) ? "suspended" : "",
1058 ((scb.scb_status & SCB_ST_CUS) ==
1059 SCB_ST_CUS_ACTV) ? "active" : "");
1060 printk("rus 0x%x[%s%s%s%s]\n", (scb.scb_status & SCB_ST_RUS) >> 4,
1061 ((scb.scb_status & SCB_ST_RUS) ==
1062 SCB_ST_RUS_IDLE) ? "idle" : "",
1063 ((scb.scb_status & SCB_ST_RUS) ==
1064 SCB_ST_RUS_SUSP) ? "suspended" : "",
1065 ((scb.scb_status & SCB_ST_RUS) ==
1066 SCB_ST_RUS_NRES) ? "no resources" : "",
1067 ((scb.scb_status & SCB_ST_RUS) ==
1068 SCB_ST_RUS_RDY) ? "ready" : "");
1070 printk(KERN_DEBUG "command: ");
1071 printk("ack 0x%x[%s%s%s%s] ",
1073 scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR |
1074 SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12,
1076 scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "",
1078 scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "",
1080 scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "",
1082 scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : "");
1083 printk("cuc 0x%x[%s%s%s%s%s] ",
1084 (scb.scb_command & SCB_CMD_CUC) >> 8,
1085 ((scb.scb_command & SCB_CMD_CUC) ==
1086 SCB_CMD_CUC_NOP) ? "nop" : "",
1087 ((scb.scb_command & SCB_CMD_CUC) ==
1088 SCB_CMD_CUC_GO) ? "start cbl_offset" : "",
1089 ((scb.scb_command & SCB_CMD_CUC) ==
1090 SCB_CMD_CUC_RES) ? "resume execution" : "",
1091 ((scb.scb_command & SCB_CMD_CUC) ==
1092 SCB_CMD_CUC_SUS) ? "suspend execution" : "",
1093 ((scb.scb_command & SCB_CMD_CUC) ==
1094 SCB_CMD_CUC_ABT) ? "abort execution" : "");
1095 printk("ruc 0x%x[%s%s%s%s%s]\n",
1096 (scb.scb_command & SCB_CMD_RUC) >> 4,
1097 ((scb.scb_command & SCB_CMD_RUC) ==
1098 SCB_CMD_RUC_NOP) ? "nop" : "",
1099 ((scb.scb_command & SCB_CMD_RUC) ==
1100 SCB_CMD_RUC_GO) ? "start rfa_offset" : "",
1101 ((scb.scb_command & SCB_CMD_RUC) ==
1102 SCB_CMD_RUC_RES) ? "resume reception" : "",
1103 ((scb.scb_command & SCB_CMD_RUC) ==
1104 SCB_CMD_RUC_SUS) ? "suspend reception" : "",
1105 ((scb.scb_command & SCB_CMD_RUC) ==
1106 SCB_CMD_RUC_ABT) ? "abort reception" : "");
1108 printk(KERN_DEBUG "cbl_offset 0x%x ", scb.scb_cbl_offset);
1109 printk("rfa_offset 0x%x\n", scb.scb_rfa_offset);
1111 printk(KERN_DEBUG "crcerrs %d ", scb.scb_crcerrs);
1112 printk("alnerrs %d ", scb.scb_alnerrs);
1113 printk("rscerrs %d ", scb.scb_rscerrs);
1114 printk("ovrnerrs %d\n", scb.scb_ovrnerrs);
1117 /*------------------------------------------------------------------*/
1119 * Print the formatted status of the i82586's receive unit.
1121 static void wv_ru_show(struct net_device *dev)
1124 "##### WaveLAN i82586 receiver unit status: #####\n");
1125 printk(KERN_DEBUG "ru:");
1127 * Not implemented yet
1132 /*------------------------------------------------------------------*/
1134 * Display info about one control block of the i82586 memory.
1136 static void wv_cu_show_one(struct net_device *dev, net_local * lp, int i, u16 p)
1138 unsigned long ioaddr;
1141 ioaddr = dev->base_addr;
1143 printk("%d: 0x%x:", i, p);
1145 obram_read(ioaddr, p, (unsigned char *) &actx, sizeof(actx));
1146 printk(" status=0x%x,", actx.tx_h.ac_status);
1147 printk(" command=0x%x,", actx.tx_h.ac_command);
1153 obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
1154 printk(" tbd_status=0x%x,", tbd.tbd_status);
1161 /*------------------------------------------------------------------*/
1163 * Print status of the command unit of the i82586.
1165 static void wv_cu_show(struct net_device *dev)
1167 net_local *lp = netdev_priv(dev);
1172 "##### WaveLAN i82586 command unit status: #####\n");
1175 for (i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++) {
1176 wv_cu_show_one(dev, lp, i, p);
1179 if (p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
1180 p -= NTXBLOCKS * TXBLOCKZ;
1184 #endif /* DEBUG_I82586_SHOW */
1186 #ifdef DEBUG_DEVICE_SHOW
1187 /*------------------------------------------------------------------*/
1189 * Print the formatted status of the WaveLAN PCMCIA device driver.
1191 static void wv_dev_show(struct net_device *dev)
1193 printk(KERN_DEBUG "dev:");
1194 printk(" state=%lX,", dev->state);
1195 printk(" trans_start=%ld,", dev->trans_start);
1196 printk(" flags=0x%x,", dev->flags);
1200 /*------------------------------------------------------------------*/
1202 * Print the formatted status of the WaveLAN PCMCIA device driver's
1203 * private information.
1205 static void wv_local_show(struct net_device *dev)
1209 lp = netdev_priv(dev);
1211 printk(KERN_DEBUG "local:");
1212 printk(" tx_n_in_use=%d,", lp->tx_n_in_use);
1213 printk(" hacr=0x%x,", lp->hacr);
1214 printk(" rx_head=0x%x,", lp->rx_head);
1215 printk(" rx_last=0x%x,", lp->rx_last);
1216 printk(" tx_first_free=0x%x,", lp->tx_first_free);
1217 printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use);
1219 } /* wv_local_show */
1220 #endif /* DEBUG_DEVICE_SHOW */
1222 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1223 /*------------------------------------------------------------------*/
1225 * Dump packet header (and content if necessary) on the screen
1227 static inline void wv_packet_info(u8 * p, /* Packet to dump */
1228 int length, /* Length of the packet */
1229 char *msg1, /* Name of the device */
1231 { /* Name of the function */
1236 "%s: %s(): dest %pM, length %d\n",
1237 msg1, msg2, p, length);
1239 "%s: %s(): src %pM, type 0x%02X%02X\n",
1240 msg1, msg2, &p[6], p[12], p[13]);
1242 #ifdef DEBUG_PACKET_DUMP
1244 printk(KERN_DEBUG "data=\"");
1246 if ((maxi = length) > DEBUG_PACKET_DUMP)
1247 maxi = DEBUG_PACKET_DUMP;
1248 for (i = 14; i < maxi; i++)
1249 if (p[i] >= ' ' && p[i] <= '~')
1250 printk(" %c", p[i]);
1252 printk("%02X", p[i]);
1256 printk(KERN_DEBUG "\n");
1257 #endif /* DEBUG_PACKET_DUMP */
1259 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1261 /*------------------------------------------------------------------*/
1263 * This is the information which is displayed by the driver at startup.
1264 * There are lots of flags for configuring it to your liking.
1266 static void wv_init_info(struct net_device *dev)
1268 short ioaddr = dev->base_addr;
1269 net_local *lp = netdev_priv(dev);
1272 /* Read the parameter storage area */
1273 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
1275 #ifdef DEBUG_PSA_SHOW
1278 #ifdef DEBUG_MMC_SHOW
1281 #ifdef DEBUG_I82586_SHOW
1285 #ifdef DEBUG_BASIC_SHOW
1286 /* Now, let's go for the basic stuff. */
1287 printk(KERN_NOTICE "%s: WaveLAN at %#x, %pM, IRQ %d",
1288 dev->name, ioaddr, dev->dev_addr, dev->irq);
1290 /* Print current network ID. */
1291 if (psa.psa_nwid_select)
1292 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0],
1295 printk(", nwid off");
1298 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1299 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1300 unsigned short freq;
1302 /* Ask the EEPROM to read the frequency from the first area. */
1303 fee_read(ioaddr, 0x00, &freq, 1);
1305 /* Print frequency */
1306 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1313 switch (psa.psa_comp_number) {
1314 case PSA_COMP_PC_AT_915:
1315 case PSA_COMP_PC_AT_2400:
1318 case PSA_COMP_PC_MC_915:
1319 case PSA_COMP_PC_MC_2400:
1322 case PSA_COMP_PCMCIA_915:
1329 switch (psa.psa_subband) {
1330 case PSA_SUBBAND_915:
1333 case PSA_SUBBAND_2425:
1336 case PSA_SUBBAND_2460:
1339 case PSA_SUBBAND_2484:
1342 case PSA_SUBBAND_2430_5:
1351 #endif /* DEBUG_BASIC_SHOW */
1353 #ifdef DEBUG_VERSION_SHOW
1354 /* Print version information */
1355 printk(KERN_NOTICE "%s", version);
1357 } /* wv_init_info */
1359 /********************* IOCTL, STATS & RECONFIG *********************/
1361 * We found here routines that are called by Linux on different
1362 * occasions after the configuration and not for transmitting data
1363 * These may be called when the user use ifconfig, /proc/net/dev
1364 * or wireless extensions
1368 /*------------------------------------------------------------------*/
1370 * Set or clear the multicast filter for this adaptor.
1371 * num_addrs == -1 Promiscuous mode, receive all packets
1372 * num_addrs == 0 Normal mode, clear multicast list
1373 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1374 * and do best-effort filtering.
1376 static void wavelan_set_multicast_list(struct net_device *dev)
1378 net_local *lp = netdev_priv(dev);
1380 #ifdef DEBUG_IOCTL_TRACE
1381 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n",
1385 #ifdef DEBUG_IOCTL_INFO
1387 "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1388 dev->name, dev->flags, netdev_mc_count(dev));
1391 /* Are we asking for promiscuous mode,
1392 * or all multicast addresses (we don't have that!)
1393 * or too many multicast addresses for the hardware filter? */
1394 if ((dev->flags & IFF_PROMISC) ||
1395 (dev->flags & IFF_ALLMULTI) ||
1396 (netdev_mc_count(dev) > I82586_MAX_MULTICAST_ADDRESSES)) {
1398 * Enable promiscuous mode: receive all packets.
1400 if (!lp->promiscuous) {
1401 lp->promiscuous = 1;
1404 wv_82586_reconfig(dev);
1407 /* Are there multicast addresses to send? */
1408 if (!netdev_mc_empty(dev)) {
1410 * Disable promiscuous mode, but receive all packets
1413 #ifdef MULTICAST_AVOID
1414 if (lp->promiscuous || (netdev_mc_count(dev) != lp->mc_count))
1417 lp->promiscuous = 0;
1418 lp->mc_count = netdev_mc_count(dev);
1420 wv_82586_reconfig(dev);
1424 * Switch to normal mode: disable promiscuous mode and
1425 * clear the multicast list.
1427 if (lp->promiscuous || lp->mc_count == 0) {
1428 lp->promiscuous = 0;
1431 wv_82586_reconfig(dev);
1434 #ifdef DEBUG_IOCTL_TRACE
1435 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n",
1440 /*------------------------------------------------------------------*/
1442 * This function doesn't exist.
1443 * (Note : it was a nice way to test the reconfigure stuff...)
1445 #ifdef SET_MAC_ADDRESS
1446 static int wavelan_set_mac_address(struct net_device *dev, void *addr)
1448 struct sockaddr *mac = addr;
1450 /* Copy the address. */
1451 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1453 /* Reconfigure the beast. */
1454 wv_82586_reconfig(dev);
1458 #endif /* SET_MAC_ADDRESS */
1461 /*------------------------------------------------------------------*/
1463 * Frequency setting (for hardware capable of it)
1464 * It's a bit complicated and you don't really want to look into it.
1465 * (called in wavelan_ioctl)
1467 static int wv_set_frequency(unsigned long ioaddr, /* I/O port of the card */
1468 iw_freq * frequency)
1470 const int BAND_NUM = 10; /* Number of bands */
1471 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1472 #ifdef DEBUG_IOCTL_INFO
1476 /* Setting by frequency */
1477 /* Theoretically, you may set any frequency between
1478 * the two limits with a 0.5 MHz precision. In practice,
1479 * I don't want you to have trouble with local regulations.
1481 if ((frequency->e == 1) &&
1482 (frequency->m >= (int) 2.412e8)
1483 && (frequency->m <= (int) 2.487e8)) {
1484 freq = ((frequency->m / 10000) - 24000L) / 5;
1487 /* Setting by channel (same as wfreqsel) */
1488 /* Warning: each channel is 22 MHz wide, so some of the channels
1489 * will interfere. */
1490 if ((frequency->e == 0) && (frequency->m < BAND_NUM)) {
1491 /* Get frequency offset. */
1492 freq = channel_bands[frequency->m] >> 1;
1495 /* Verify that the frequency is allowed. */
1497 u16 table[10]; /* Authorized frequency table */
1499 /* Read the frequency table. */
1500 fee_read(ioaddr, 0x71, table, 10);
1502 #ifdef DEBUG_IOCTL_INFO
1503 printk(KERN_DEBUG "Frequency table: ");
1504 for (i = 0; i < 10; i++) {
1505 printk(" %04X", table[i]);
1510 /* Look in the table to see whether the frequency is allowed. */
1511 if (!(table[9 - ((freq - 24) / 16)] &
1512 (1 << ((freq - 24) % 16)))) return -EINVAL; /* not allowed */
1516 /* if we get a usable frequency */
1518 unsigned short area[16];
1519 unsigned short dac[2];
1520 unsigned short area_verify[16];
1521 unsigned short dac_verify[2];
1522 /* Corresponding gain (in the power adjust value table)
1523 * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8
1524 * and WCIN062D.DOC, page 6.2.9. */
1525 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1526 int power_band = 0; /* Selected band */
1527 unsigned short power_adjust; /* Correct value */
1529 /* Search for the gain. */
1531 while ((freq > power_limit[power_band]) &&
1532 (power_limit[++power_band] != 0));
1534 /* Read the first area. */
1535 fee_read(ioaddr, 0x00, area, 16);
1538 fee_read(ioaddr, 0x60, dac, 2);
1540 /* Read the new power adjust value. */
1541 fee_read(ioaddr, 0x6B - (power_band >> 1), &power_adjust,
1543 if (power_band & 0x1)
1546 power_adjust &= 0xFF;
1548 #ifdef DEBUG_IOCTL_INFO
1549 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1550 for (i = 0; i < 16; i++) {
1551 printk(" %04X", area[i]);
1555 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1559 /* Frequency offset (for info only) */
1560 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1562 /* Receiver Principle main divider coefficient */
1563 area[3] = (freq >> 1) + 2400L - 352L;
1564 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1566 /* Transmitter Main divider coefficient */
1567 area[13] = (freq >> 1) + 2400L;
1568 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1570 /* Other parts of the area are flags, bit streams or unused. */
1572 /* Set the value in the DAC. */
1573 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1574 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1576 /* Write the first area. */
1577 fee_write(ioaddr, 0x00, area, 16);
1579 /* Write the DAC. */
1580 fee_write(ioaddr, 0x60, dac, 2);
1582 /* We now should verify here that the writing of the EEPROM went OK. */
1584 /* Reread the first area. */
1585 fee_read(ioaddr, 0x00, area_verify, 16);
1587 /* Reread the DAC. */
1588 fee_read(ioaddr, 0x60, dac_verify, 2);
1591 if (memcmp(area, area_verify, 16 * 2) ||
1592 memcmp(dac, dac_verify, 2 * 2)) {
1593 #ifdef DEBUG_IOCTL_ERROR
1595 "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n");
1600 /* We must download the frequency parameters to the
1601 * synthesizers (from the EEPROM - area 1)
1602 * Note: as the EEPROM is automatically decremented, we set the end
1604 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x0F);
1605 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1606 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1608 /* Wait until the download is finished. */
1609 fee_wait(ioaddr, 100, 100);
1611 /* We must now download the power adjust value (gain) to
1612 * the synthesizers (from the EEPROM - area 7 - DAC). */
1613 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x61);
1614 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1615 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1617 /* Wait for the download to finish. */
1618 fee_wait(ioaddr, 100, 100);
1620 #ifdef DEBUG_IOCTL_INFO
1621 /* Verification of what we have done */
1623 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1624 for (i = 0; i < 16; i++) {
1625 printk(" %04X", area_verify[i]);
1629 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1630 dac_verify[0], dac_verify[1]);
1635 return -EINVAL; /*bah, never get there... */
1638 /*------------------------------------------------------------------*/
1640 * Give the list of available frequencies.
1642 static int wv_frequency_list(unsigned long ioaddr, /* I/O port of the card */
1643 iw_freq * list, /* List of frequencies to fill */
1645 { /* Maximum number of frequencies */
1646 u16 table[10]; /* Authorized frequency table */
1647 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1648 int i; /* index in the table */
1649 int c = 0; /* Channel number */
1651 /* Read the frequency table. */
1652 fee_read(ioaddr, 0x71 /* frequency table */ , table, 10);
1654 /* Check all frequencies. */
1656 for (freq = 0; freq < 150; freq++)
1657 /* Look in the table if the frequency is allowed */
1658 if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
1659 /* Compute approximate channel number */
1660 while ((c < ARRAY_SIZE(channel_bands)) &&
1661 (((channel_bands[c] >> 1) - 24) < freq))
1663 list[i].i = c; /* Set the list index */
1665 /* put in the list */
1666 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1677 #ifdef IW_WIRELESS_SPY
1678 /*------------------------------------------------------------------*/
1680 * Gather wireless spy statistics: for each packet, compare the source
1681 * address with our list, and if they match, get the statistics.
1682 * Sorry, but this function really needs the wireless extensions.
1684 static inline void wl_spy_gather(struct net_device *dev,
1685 u8 * mac, /* MAC address */
1686 u8 * stats) /* Statistics to gather */
1688 struct iw_quality wstats;
1690 wstats.qual = stats[2] & MMR_SGNL_QUAL;
1691 wstats.level = stats[0] & MMR_SIGNAL_LVL;
1692 wstats.noise = stats[1] & MMR_SILENCE_LVL;
1693 wstats.updated = 0x7;
1695 /* Update spy records */
1696 wireless_spy_update(dev, mac, &wstats);
1698 #endif /* IW_WIRELESS_SPY */
1701 /*------------------------------------------------------------------*/
1703 * This function calculates a histogram of the signal level.
1704 * As the noise is quite constant, it's like doing it on the SNR.
1705 * We have defined a set of interval (lp->his_range), and each time
1706 * the level goes in that interval, we increment the count (lp->his_sum).
1707 * With this histogram you may detect if one WaveLAN is really weak,
1708 * or you may also calculate the mean and standard deviation of the level.
1710 static inline void wl_his_gather(struct net_device *dev, u8 * stats)
1711 { /* Statistics to gather */
1712 net_local *lp = netdev_priv(dev);
1713 u8 level = stats[0] & MMR_SIGNAL_LVL;
1716 /* Find the correct interval. */
1718 while ((i < (lp->his_number - 1))
1719 && (level >= lp->his_range[i++]));
1721 /* Increment interval counter. */
1724 #endif /* HISTOGRAM */
1726 /*------------------------------------------------------------------*/
1728 * Wireless Handler : get protocol name
1730 static int wavelan_get_name(struct net_device *dev,
1731 struct iw_request_info *info,
1732 union iwreq_data *wrqu,
1735 strcpy(wrqu->name, "WaveLAN");
1739 /*------------------------------------------------------------------*/
1741 * Wireless Handler : set NWID
1743 static int wavelan_set_nwid(struct net_device *dev,
1744 struct iw_request_info *info,
1745 union iwreq_data *wrqu,
1748 unsigned long ioaddr = dev->base_addr;
1749 net_local *lp = netdev_priv(dev); /* lp is not unused */
1752 unsigned long flags;
1755 /* Disable interrupts and save flags. */
1756 spin_lock_irqsave(&lp->spinlock, flags);
1758 /* Set NWID in WaveLAN. */
1759 if (!wrqu->nwid.disabled) {
1760 /* Set NWID in psa */
1761 psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
1762 psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
1763 psa.psa_nwid_select = 0x01;
1764 psa_write(ioaddr, lp->hacr,
1765 (char *) psa.psa_nwid - (char *) &psa,
1766 (unsigned char *) psa.psa_nwid, 3);
1768 /* Set NWID in mmc. */
1769 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1770 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1772 (char *) &m.w.mmw_netw_id_l -
1774 (unsigned char *) &m.w.mmw_netw_id_l, 2);
1775 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), 0x00);
1777 /* Disable NWID in the psa. */
1778 psa.psa_nwid_select = 0x00;
1779 psa_write(ioaddr, lp->hacr,
1780 (char *) &psa.psa_nwid_select -
1782 (unsigned char *) &psa.psa_nwid_select,
1785 /* Disable NWID in the mmc (no filtering). */
1786 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel),
1787 MMW_LOOPT_SEL_DIS_NWID);
1789 /* update the Wavelan checksum */
1790 update_psa_checksum(dev, ioaddr, lp->hacr);
1792 /* Enable interrupts and restore flags. */
1793 spin_unlock_irqrestore(&lp->spinlock, flags);
1798 /*------------------------------------------------------------------*/
1800 * Wireless Handler : get NWID
1802 static int wavelan_get_nwid(struct net_device *dev,
1803 struct iw_request_info *info,
1804 union iwreq_data *wrqu,
1807 unsigned long ioaddr = dev->base_addr;
1808 net_local *lp = netdev_priv(dev); /* lp is not unused */
1810 unsigned long flags;
1813 /* Disable interrupts and save flags. */
1814 spin_lock_irqsave(&lp->spinlock, flags);
1816 /* Read the NWID. */
1817 psa_read(ioaddr, lp->hacr,
1818 (char *) psa.psa_nwid - (char *) &psa,
1819 (unsigned char *) psa.psa_nwid, 3);
1820 wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1821 wrqu->nwid.disabled = !(psa.psa_nwid_select);
1822 wrqu->nwid.fixed = 1; /* Superfluous */
1824 /* Enable interrupts and restore flags. */
1825 spin_unlock_irqrestore(&lp->spinlock, flags);
1830 /*------------------------------------------------------------------*/
1832 * Wireless Handler : set frequency
1834 static int wavelan_set_freq(struct net_device *dev,
1835 struct iw_request_info *info,
1836 union iwreq_data *wrqu,
1839 unsigned long ioaddr = dev->base_addr;
1840 net_local *lp = netdev_priv(dev); /* lp is not unused */
1841 unsigned long flags;
1844 /* Disable interrupts and save flags. */
1845 spin_lock_irqsave(&lp->spinlock, flags);
1847 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1848 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1849 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1850 ret = wv_set_frequency(ioaddr, &(wrqu->freq));
1854 /* Enable interrupts and restore flags. */
1855 spin_unlock_irqrestore(&lp->spinlock, flags);
1860 /*------------------------------------------------------------------*/
1862 * Wireless Handler : get frequency
1864 static int wavelan_get_freq(struct net_device *dev,
1865 struct iw_request_info *info,
1866 union iwreq_data *wrqu,
1869 unsigned long ioaddr = dev->base_addr;
1870 net_local *lp = netdev_priv(dev); /* lp is not unused */
1872 unsigned long flags;
1875 /* Disable interrupts and save flags. */
1876 spin_lock_irqsave(&lp->spinlock, flags);
1878 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
1879 * Does it work for everybody, especially old cards? */
1880 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1881 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1882 unsigned short freq;
1884 /* Ask the EEPROM to read the frequency from the first area. */
1885 fee_read(ioaddr, 0x00, &freq, 1);
1886 wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
1889 psa_read(ioaddr, lp->hacr,
1890 (char *) &psa.psa_subband - (char *) &psa,
1891 (unsigned char *) &psa.psa_subband, 1);
1893 if (psa.psa_subband <= 4) {
1894 wrqu->freq.m = fixed_bands[psa.psa_subband];
1895 wrqu->freq.e = (psa.psa_subband != 0);
1900 /* Enable interrupts and restore flags. */
1901 spin_unlock_irqrestore(&lp->spinlock, flags);
1906 /*------------------------------------------------------------------*/
1908 * Wireless Handler : set level threshold
1910 static int wavelan_set_sens(struct net_device *dev,
1911 struct iw_request_info *info,
1912 union iwreq_data *wrqu,
1915 unsigned long ioaddr = dev->base_addr;
1916 net_local *lp = netdev_priv(dev); /* lp is not unused */
1918 unsigned long flags;
1921 /* Disable interrupts and save flags. */
1922 spin_lock_irqsave(&lp->spinlock, flags);
1924 /* Set the level threshold. */
1925 /* We should complain loudly if wrqu->sens.fixed = 0, because we
1926 * can't set auto mode... */
1927 psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
1928 psa_write(ioaddr, lp->hacr,
1929 (char *) &psa.psa_thr_pre_set - (char *) &psa,
1930 (unsigned char *) &psa.psa_thr_pre_set, 1);
1931 /* update the Wavelan checksum */
1932 update_psa_checksum(dev, ioaddr, lp->hacr);
1933 mmc_out(ioaddr, mmwoff(0, mmw_thr_pre_set),
1934 psa.psa_thr_pre_set);
1936 /* Enable interrupts and restore flags. */
1937 spin_unlock_irqrestore(&lp->spinlock, flags);
1942 /*------------------------------------------------------------------*/
1944 * Wireless Handler : get level threshold
1946 static int wavelan_get_sens(struct net_device *dev,
1947 struct iw_request_info *info,
1948 union iwreq_data *wrqu,
1951 unsigned long ioaddr = dev->base_addr;
1952 net_local *lp = netdev_priv(dev); /* lp is not unused */
1954 unsigned long flags;
1957 /* Disable interrupts and save flags. */
1958 spin_lock_irqsave(&lp->spinlock, flags);
1960 /* Read the level threshold. */
1961 psa_read(ioaddr, lp->hacr,
1962 (char *) &psa.psa_thr_pre_set - (char *) &psa,
1963 (unsigned char *) &psa.psa_thr_pre_set, 1);
1964 wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
1965 wrqu->sens.fixed = 1;
1967 /* Enable interrupts and restore flags. */
1968 spin_unlock_irqrestore(&lp->spinlock, flags);
1973 /*------------------------------------------------------------------*/
1975 * Wireless Handler : set encryption key
1977 static int wavelan_set_encode(struct net_device *dev,
1978 struct iw_request_info *info,
1979 union iwreq_data *wrqu,
1982 unsigned long ioaddr = dev->base_addr;
1983 net_local *lp = netdev_priv(dev); /* lp is not unused */
1984 unsigned long flags;
1988 /* Disable interrupts and save flags. */
1989 spin_lock_irqsave(&lp->spinlock, flags);
1991 /* Check if capable of encryption */
1992 if (!mmc_encr(ioaddr)) {
1996 /* Check the size of the key */
1997 if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
2002 /*basic checking... */
2003 if (wrqu->encoding.length == 8) {
2004 /* Copy the key in the driver */
2005 memcpy(psa.psa_encryption_key, extra,
2006 wrqu->encoding.length);
2007 psa.psa_encryption_select = 1;
2009 psa_write(ioaddr, lp->hacr,
2010 (char *) &psa.psa_encryption_select -
2012 (unsigned char *) &psa.
2013 psa_encryption_select, 8 + 1);
2015 mmc_out(ioaddr, mmwoff(0, mmw_encr_enable),
2016 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2017 mmc_write(ioaddr, mmwoff(0, mmw_encr_key),
2018 (unsigned char *) &psa.
2019 psa_encryption_key, 8);
2022 /* disable encryption */
2023 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
2024 psa.psa_encryption_select = 0;
2025 psa_write(ioaddr, lp->hacr,
2026 (char *) &psa.psa_encryption_select -
2028 (unsigned char *) &psa.
2029 psa_encryption_select, 1);
2031 mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), 0);
2033 /* update the Wavelan checksum */
2034 update_psa_checksum(dev, ioaddr, lp->hacr);
2037 /* Enable interrupts and restore flags. */
2038 spin_unlock_irqrestore(&lp->spinlock, flags);
2043 /*------------------------------------------------------------------*/
2045 * Wireless Handler : get encryption key
2047 static int wavelan_get_encode(struct net_device *dev,
2048 struct iw_request_info *info,
2049 union iwreq_data *wrqu,
2052 unsigned long ioaddr = dev->base_addr;
2053 net_local *lp = netdev_priv(dev); /* lp is not unused */
2055 unsigned long flags;
2058 /* Disable interrupts and save flags. */
2059 spin_lock_irqsave(&lp->spinlock, flags);
2061 /* Check if encryption is available */
2062 if (!mmc_encr(ioaddr)) {
2065 /* Read the encryption key */
2066 psa_read(ioaddr, lp->hacr,
2067 (char *) &psa.psa_encryption_select -
2069 (unsigned char *) &psa.
2070 psa_encryption_select, 1 + 8);
2072 /* encryption is enabled ? */
2073 if (psa.psa_encryption_select)
2074 wrqu->encoding.flags = IW_ENCODE_ENABLED;
2076 wrqu->encoding.flags = IW_ENCODE_DISABLED;
2077 wrqu->encoding.flags |= mmc_encr(ioaddr);
2079 /* Copy the key to the user buffer */
2080 wrqu->encoding.length = 8;
2081 memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
2084 /* Enable interrupts and restore flags. */
2085 spin_unlock_irqrestore(&lp->spinlock, flags);
2090 /*------------------------------------------------------------------*/
2092 * Wireless Handler : get range info
2094 static int wavelan_get_range(struct net_device *dev,
2095 struct iw_request_info *info,
2096 union iwreq_data *wrqu,
2099 unsigned long ioaddr = dev->base_addr;
2100 net_local *lp = netdev_priv(dev); /* lp is not unused */
2101 struct iw_range *range = (struct iw_range *) extra;
2102 unsigned long flags;
2105 /* Set the length (very important for backward compatibility) */
2106 wrqu->data.length = sizeof(struct iw_range);
2108 /* Set all the info we don't care or don't know about to zero */
2109 memset(range, 0, sizeof(struct iw_range));
2111 /* Set the Wireless Extension versions */
2112 range->we_version_compiled = WIRELESS_EXT;
2113 range->we_version_source = 9;
2115 /* Set information in the range struct. */
2116 range->throughput = 1.6 * 1000 * 1000; /* don't argue on this ! */
2117 range->min_nwid = 0x0000;
2118 range->max_nwid = 0xFFFF;
2120 range->sensitivity = 0x3F;
2121 range->max_qual.qual = MMR_SGNL_QUAL;
2122 range->max_qual.level = MMR_SIGNAL_LVL;
2123 range->max_qual.noise = MMR_SILENCE_LVL;
2124 range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
2125 /* Need to get better values for those two */
2126 range->avg_qual.level = 30;
2127 range->avg_qual.noise = 8;
2129 range->num_bitrates = 1;
2130 range->bitrate[0] = 2000000; /* 2 Mb/s */
2132 /* Event capability (kernel + driver) */
2133 range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
2134 IW_EVENT_CAPA_MASK(0x8B04));
2135 range->event_capa[1] = IW_EVENT_CAPA_K_1;
2137 /* Disable interrupts and save flags. */
2138 spin_lock_irqsave(&lp->spinlock, flags);
2140 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2141 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2142 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2143 range->num_channels = 10;
2144 range->num_frequency = wv_frequency_list(ioaddr, range->freq,
2145 IW_MAX_FREQUENCIES);
2147 range->num_channels = range->num_frequency = 0;
2149 /* Encryption supported ? */
2150 if (mmc_encr(ioaddr)) {
2151 range->encoding_size[0] = 8; /* DES = 64 bits key */
2152 range->num_encoding_sizes = 1;
2153 range->max_encoding_tokens = 1; /* Only one key possible */
2155 range->num_encoding_sizes = 0;
2156 range->max_encoding_tokens = 0;
2159 /* Enable interrupts and restore flags. */
2160 spin_unlock_irqrestore(&lp->spinlock, flags);
2165 /*------------------------------------------------------------------*/
2167 * Wireless Private Handler : set quality threshold
2169 static int wavelan_set_qthr(struct net_device *dev,
2170 struct iw_request_info *info,
2171 union iwreq_data *wrqu,
2174 unsigned long ioaddr = dev->base_addr;
2175 net_local *lp = netdev_priv(dev); /* lp is not unused */
2177 unsigned long flags;
2179 /* Disable interrupts and save flags. */
2180 spin_lock_irqsave(&lp->spinlock, flags);
2182 psa.psa_quality_thr = *(extra) & 0x0F;
2183 psa_write(ioaddr, lp->hacr,
2184 (char *) &psa.psa_quality_thr - (char *) &psa,
2185 (unsigned char *) &psa.psa_quality_thr, 1);
2186 /* update the Wavelan checksum */
2187 update_psa_checksum(dev, ioaddr, lp->hacr);
2188 mmc_out(ioaddr, mmwoff(0, mmw_quality_thr),
2189 psa.psa_quality_thr);
2191 /* Enable interrupts and restore flags. */
2192 spin_unlock_irqrestore(&lp->spinlock, flags);
2197 /*------------------------------------------------------------------*/
2199 * Wireless Private Handler : get quality threshold
2201 static int wavelan_get_qthr(struct net_device *dev,
2202 struct iw_request_info *info,
2203 union iwreq_data *wrqu,
2206 unsigned long ioaddr = dev->base_addr;
2207 net_local *lp = netdev_priv(dev); /* lp is not unused */
2209 unsigned long flags;
2211 /* Disable interrupts and save flags. */
2212 spin_lock_irqsave(&lp->spinlock, flags);
2214 psa_read(ioaddr, lp->hacr,
2215 (char *) &psa.psa_quality_thr - (char *) &psa,
2216 (unsigned char *) &psa.psa_quality_thr, 1);
2217 *(extra) = psa.psa_quality_thr & 0x0F;
2219 /* Enable interrupts and restore flags. */
2220 spin_unlock_irqrestore(&lp->spinlock, flags);
2226 /*------------------------------------------------------------------*/
2228 * Wireless Private Handler : set histogram
2230 static int wavelan_set_histo(struct net_device *dev,
2231 struct iw_request_info *info,
2232 union iwreq_data *wrqu,
2235 net_local *lp = netdev_priv(dev); /* lp is not unused */
2237 /* Check the number of intervals. */
2238 if (wrqu->data.length > 16) {
2242 /* Disable histo while we copy the addresses.
2243 * As we don't disable interrupts, we need to do this */
2246 /* Are there ranges to copy? */
2247 if (wrqu->data.length > 0) {
2248 /* Copy interval ranges to the driver */
2249 memcpy(lp->his_range, extra, wrqu->data.length);
2253 printk(KERN_DEBUG "Histo :");
2254 for(i = 0; i < wrqu->data.length; i++)
2255 printk(" %d", lp->his_range[i]);
2259 /* Reset result structure. */
2260 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2263 /* Now we can set the number of ranges */
2264 lp->his_number = wrqu->data.length;
2269 /*------------------------------------------------------------------*/
2271 * Wireless Private Handler : get histogram
2273 static int wavelan_get_histo(struct net_device *dev,
2274 struct iw_request_info *info,
2275 union iwreq_data *wrqu,
2278 net_local *lp = netdev_priv(dev); /* lp is not unused */
2280 /* Set the number of intervals. */
2281 wrqu->data.length = lp->his_number;
2283 /* Give back the distribution statistics */
2284 if(lp->his_number > 0)
2285 memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
2289 #endif /* HISTOGRAM */
2291 /*------------------------------------------------------------------*/
2293 * Structures to export the Wireless Handlers
2296 static const iw_handler wavelan_handler[] =
2298 NULL, /* SIOCSIWNAME */
2299 wavelan_get_name, /* SIOCGIWNAME */
2300 wavelan_set_nwid, /* SIOCSIWNWID */
2301 wavelan_get_nwid, /* SIOCGIWNWID */
2302 wavelan_set_freq, /* SIOCSIWFREQ */
2303 wavelan_get_freq, /* SIOCGIWFREQ */
2304 NULL, /* SIOCSIWMODE */
2305 NULL, /* SIOCGIWMODE */
2306 wavelan_set_sens, /* SIOCSIWSENS */
2307 wavelan_get_sens, /* SIOCGIWSENS */
2308 NULL, /* SIOCSIWRANGE */
2309 wavelan_get_range, /* SIOCGIWRANGE */
2310 NULL, /* SIOCSIWPRIV */
2311 NULL, /* SIOCGIWPRIV */
2312 NULL, /* SIOCSIWSTATS */
2313 NULL, /* SIOCGIWSTATS */
2314 iw_handler_set_spy, /* SIOCSIWSPY */
2315 iw_handler_get_spy, /* SIOCGIWSPY */
2316 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2317 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2318 NULL, /* SIOCSIWAP */
2319 NULL, /* SIOCGIWAP */
2320 NULL, /* -- hole -- */
2321 NULL, /* SIOCGIWAPLIST */
2322 NULL, /* -- hole -- */
2323 NULL, /* -- hole -- */
2324 NULL, /* SIOCSIWESSID */
2325 NULL, /* SIOCGIWESSID */
2326 NULL, /* SIOCSIWNICKN */
2327 NULL, /* SIOCGIWNICKN */
2328 NULL, /* -- hole -- */
2329 NULL, /* -- hole -- */
2330 NULL, /* SIOCSIWRATE */
2331 NULL, /* SIOCGIWRATE */
2332 NULL, /* SIOCSIWRTS */
2333 NULL, /* SIOCGIWRTS */
2334 NULL, /* SIOCSIWFRAG */
2335 NULL, /* SIOCGIWFRAG */
2336 NULL, /* SIOCSIWTXPOW */
2337 NULL, /* SIOCGIWTXPOW */
2338 NULL, /* SIOCSIWRETRY */
2339 NULL, /* SIOCGIWRETRY */
2340 /*bummer ! Why those are only at the end ??? */
2341 wavelan_set_encode, /* SIOCSIWENCODE */
2342 wavelan_get_encode, /* SIOCGIWENCODE */
2345 static const iw_handler wavelan_private_handler[] =
2347 wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
2348 wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
2350 wavelan_set_histo, /* SIOCIWFIRSTPRIV + 2 */
2351 wavelan_get_histo, /* SIOCIWFIRSTPRIV + 3 */
2352 #endif /* HISTOGRAM */
2355 static const struct iw_priv_args wavelan_private_args[] = {
2356 /*{ cmd, set_args, get_args, name } */
2357 { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2358 { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2359 { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
2360 { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
2363 static const struct iw_handler_def wavelan_handler_def =
2365 .num_standard = ARRAY_SIZE(wavelan_handler),
2366 .num_private = ARRAY_SIZE(wavelan_private_handler),
2367 .num_private_args = ARRAY_SIZE(wavelan_private_args),
2368 .standard = wavelan_handler,
2369 .private = wavelan_private_handler,
2370 .private_args = wavelan_private_args,
2371 .get_wireless_stats = wavelan_get_wireless_stats,
2374 /*------------------------------------------------------------------*/
2376 * Get wireless statistics.
2377 * Called by /proc/net/wireless
2379 static iw_stats *wavelan_get_wireless_stats(struct net_device *dev)
2381 unsigned long ioaddr = dev->base_addr;
2382 net_local *lp = netdev_priv(dev);
2385 unsigned long flags;
2387 #ifdef DEBUG_IOCTL_TRACE
2388 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n",
2393 if (lp == (net_local *) NULL)
2394 return (iw_stats *) NULL;
2396 /* Disable interrupts and save flags. */
2397 spin_lock_irqsave(&lp->spinlock, flags);
2399 wstats = &lp->wstats;
2401 /* Get data from the mmc. */
2402 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2404 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2405 mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l,
2407 mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set,
2410 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2412 /* Copy data to wireless stuff. */
2413 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2414 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2415 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2416 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2417 wstats->qual.updated = (((m. mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7)
2418 | ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6)
2419 | ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2420 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2421 wstats->discard.code = 0L;
2422 wstats->discard.misc = 0L;
2424 /* Enable interrupts and restore flags. */
2425 spin_unlock_irqrestore(&lp->spinlock, flags);
2427 #ifdef DEBUG_IOCTL_TRACE
2428 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n",
2434 /************************* PACKET RECEPTION *************************/
2436 * This part deals with receiving the packets.
2437 * The interrupt handler gets an interrupt when a packet has been
2438 * successfully received and calls this part.
2441 /*------------------------------------------------------------------*/
2443 * This routine does the actual copying of data (including the Ethernet
2444 * header structure) from the WaveLAN card to an sk_buff chain that
2445 * will be passed up to the network interface layer. NOTE: we
2446 * currently don't handle trailer protocols (neither does the rest of
2447 * the network interface), so if that is needed, it will (at least in
2448 * part) be added here. The contents of the receive ring buffer are
2449 * copied to a message chain that is then passed to the kernel.
2451 * Note: if any errors occur, the packet is "dropped on the floor".
2452 * (called by wv_packet_rcv())
2455 wv_packet_read(struct net_device *dev, u16 buf_off, int sksize)
2457 net_local *lp = netdev_priv(dev);
2458 unsigned long ioaddr = dev->base_addr;
2459 struct sk_buff *skb;
2461 #ifdef DEBUG_RX_TRACE
2462 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2463 dev->name, buf_off, sksize);
2466 /* Allocate buffer for the data */
2467 if ((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL) {
2468 #ifdef DEBUG_RX_ERROR
2470 "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
2473 dev->stats.rx_dropped++;
2477 /* Copy the packet to the buffer. */
2478 obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize);
2479 skb->protocol = eth_type_trans(skb, dev);
2481 #ifdef DEBUG_RX_INFO
2482 wv_packet_info(skb_mac_header(skb), sksize, dev->name,
2484 #endif /* DEBUG_RX_INFO */
2486 /* Statistics-gathering and associated stuff.
2487 * It seem a bit messy with all the define, but it's really
2490 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
2491 (lp->spy_data.spy_number > 0) ||
2492 #endif /* IW_WIRELESS_SPY */
2494 (lp->his_number > 0) ||
2495 #endif /* HISTOGRAM */
2497 u8 stats[3]; /* signal level, noise level, signal quality */
2499 /* Read signal level, silence level and signal quality bytes */
2500 /* Note: in the PCMCIA hardware, these are part of the frame.
2501 * It seems that for the ISA hardware, it's nowhere to be
2502 * found in the frame, so I'm obliged to do this (it has a
2503 * side effect on /proc/net/wireless).
2506 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2507 mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3);
2508 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2510 #ifdef DEBUG_RX_INFO
2512 "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2513 dev->name, stats[0] & 0x3F, stats[1] & 0x3F,
2518 #ifdef IW_WIRELESS_SPY
2519 wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE,
2521 #endif /* IW_WIRELESS_SPY */
2523 wl_his_gather(dev, stats);
2524 #endif /* HISTOGRAM */
2528 * Hand the packet to the network module.
2532 /* Keep statistics up to date */
2533 dev->stats.rx_packets++;
2534 dev->stats.rx_bytes += sksize;
2536 #ifdef DEBUG_RX_TRACE
2537 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2541 /*------------------------------------------------------------------*/
2543 * Transfer as many packets as we can
2544 * from the device RAM.
2545 * (called in wavelan_interrupt()).
2546 * Note : the spinlock is already grabbed for us.
2548 static void wv_receive(struct net_device *dev)
2550 unsigned long ioaddr = dev->base_addr;
2551 net_local *lp = netdev_priv(dev);
2556 #ifdef DEBUG_RX_TRACE
2557 printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name);
2560 /* Loop on each received packet. */
2562 obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd,
2565 /* Note about the status :
2566 * It start up to be 0 (the value we set). Then, when the RU
2567 * grab the buffer to prepare for reception, it sets the
2568 * FD_STATUS_B flag. When the RU has finished receiving the
2569 * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
2570 * completion and set the other flags to indicate the eventual
2571 * errors. FD_STATUS_OK indicates that the reception was OK.
2574 /* If the current frame is not complete, we have reached the end. */
2575 if ((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
2576 break; /* This is how we exit the loop. */
2580 /* Check whether frame was correctly received. */
2581 if ((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK) {
2582 /* Does the frame contain a pointer to the data? Let's check. */
2583 if (fd.fd_rbd_offset != I82586NULL) {
2584 /* Read the receive buffer descriptor */
2585 obram_read(ioaddr, fd.fd_rbd_offset,
2586 (unsigned char *) &rbd,
2589 #ifdef DEBUG_RX_ERROR
2590 if ((rbd.rbd_status & RBD_STATUS_EOF) !=
2591 RBD_STATUS_EOF) printk(KERN_INFO
2592 "%s: wv_receive(): missing EOF flag.\n",
2595 if ((rbd.rbd_status & RBD_STATUS_F) !=
2596 RBD_STATUS_F) printk(KERN_INFO
2597 "%s: wv_receive(): missing F flag.\n",
2599 #endif /* DEBUG_RX_ERROR */
2601 /* Read the packet and transmit to Linux */
2602 wv_packet_read(dev, rbd.rbd_bufl,
2607 #ifdef DEBUG_RX_ERROR
2608 else /* if frame has no data */
2610 "%s: wv_receive(): frame has no data.\n",
2613 } else { /* If reception was no successful */
2615 dev->stats.rx_errors++;
2617 #ifdef DEBUG_RX_INFO
2619 "%s: wv_receive(): frame not received successfully (%X).\n",
2620 dev->name, fd.fd_status);
2623 #ifdef DEBUG_RX_ERROR
2624 if ((fd.fd_status & FD_STATUS_S6) != 0)
2626 "%s: wv_receive(): no EOF flag.\n",
2630 if ((fd.fd_status & FD_STATUS_S7) != 0) {
2631 dev->stats.rx_length_errors++;
2632 #ifdef DEBUG_RX_FAIL
2634 "%s: wv_receive(): frame too short.\n",
2639 if ((fd.fd_status & FD_STATUS_S8) != 0) {
2640 dev->stats.rx_over_errors++;
2641 #ifdef DEBUG_RX_FAIL
2643 "%s: wv_receive(): rx DMA overrun.\n",
2648 if ((fd.fd_status & FD_STATUS_S9) != 0) {
2649 dev->stats.rx_fifo_errors++;
2650 #ifdef DEBUG_RX_FAIL
2652 "%s: wv_receive(): ran out of resources.\n",
2657 if ((fd.fd_status & FD_STATUS_S10) != 0) {
2658 dev->stats.rx_frame_errors++;
2659 #ifdef DEBUG_RX_FAIL
2661 "%s: wv_receive(): alignment error.\n",
2666 if ((fd.fd_status & FD_STATUS_S11) != 0) {
2667 dev->stats.rx_crc_errors++;
2668 #ifdef DEBUG_RX_FAIL
2670 "%s: wv_receive(): CRC error.\n",
2677 obram_write(ioaddr, fdoff(lp->rx_head, fd_status),
2678 (unsigned char *) &fd.fd_status,
2679 sizeof(fd.fd_status));
2681 fd.fd_command = FD_COMMAND_EL;
2682 obram_write(ioaddr, fdoff(lp->rx_head, fd_command),
2683 (unsigned char *) &fd.fd_command,
2684 sizeof(fd.fd_command));
2687 obram_write(ioaddr, fdoff(lp->rx_last, fd_command),
2688 (unsigned char *) &fd.fd_command,
2689 sizeof(fd.fd_command));
2691 lp->rx_last = lp->rx_head;
2692 lp->rx_head = fd.fd_link_offset;
2693 } /* for(;;) -> loop on all frames */
2695 #ifdef DEBUG_RX_INFO
2697 printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n",
2698 dev->name, nreaped);
2700 #ifdef DEBUG_RX_TRACE
2701 printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name);
2705 /*********************** PACKET TRANSMISSION ***********************/
2707 * This part deals with sending packets through the WaveLAN.
2711 /*------------------------------------------------------------------*/
2713 * This routine fills in the appropriate registers and memory
2714 * locations on the WaveLAN card and starts the card off on
2718 * Each block contains a transmit command, a NOP command,
2719 * a transmit block descriptor and a buffer.
2720 * The CU read the transmit block which point to the tbd,
2721 * read the tbd and the content of the buffer.
2722 * When it has finish with it, it goes to the next command
2723 * which in our case is the NOP. The NOP points on itself,
2724 * so the CU stop here.
2725 * When we add the next block, we modify the previous nop
2726 * to make it point on the new tx command.
2727 * Simple, isn't it ?
2729 * (called in wavelan_packet_xmit())
2731 static int wv_packet_write(struct net_device *dev, void *buf, short length)
2733 net_local *lp = netdev_priv(dev);
2734 unsigned long ioaddr = dev->base_addr;
2735 unsigned short txblock;
2736 unsigned short txpred;
2737 unsigned short tx_addr;
2738 unsigned short nop_addr;
2739 unsigned short tbd_addr;
2740 unsigned short buf_addr;
2745 unsigned long flags;
2747 #ifdef DEBUG_TX_TRACE
2748 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name,
2752 spin_lock_irqsave(&lp->spinlock, flags);
2754 /* Check nothing bad has happened */
2755 if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
2756 #ifdef DEBUG_TX_ERROR
2757 printk(KERN_INFO "%s: wv_packet_write(): Tx queue full.\n",
2760 spin_unlock_irqrestore(&lp->spinlock, flags);
2764 /* Calculate addresses of next block and previous block. */
2765 txblock = lp->tx_first_free;
2766 txpred = txblock - TXBLOCKZ;
2767 if (txpred < OFFSET_CU)
2768 txpred += NTXBLOCKS * TXBLOCKZ;
2769 lp->tx_first_free += TXBLOCKZ;
2770 if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
2771 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
2775 /* Calculate addresses of the different parts of the block. */
2777 nop_addr = tx_addr + sizeof(tx);
2778 tbd_addr = nop_addr + sizeof(nop);
2779 buf_addr = tbd_addr + sizeof(tbd);
2784 tx.tx_h.ac_status = 0;
2785 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
2786 (unsigned char *) &tx.tx_h.ac_status,
2787 sizeof(tx.tx_h.ac_status));
2792 nop.nop_h.ac_status = 0;
2793 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2794 (unsigned char *) &nop.nop_h.ac_status,
2795 sizeof(nop.nop_h.ac_status));
2796 nop.nop_h.ac_link = nop_addr;
2797 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2798 (unsigned char *) &nop.nop_h.ac_link,
2799 sizeof(nop.nop_h.ac_link));
2802 * Transmit buffer descriptor
2804 tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen);
2805 tbd.tbd_next_bd_offset = I82586NULL;
2806 tbd.tbd_bufl = buf_addr;
2808 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd));
2813 obram_write(ioaddr, buf_addr, buf, length);
2816 * Overwrite the predecessor NOP link
2817 * so that it points to this txblock.
2819 nop_addr = txpred + sizeof(tx);
2820 nop.nop_h.ac_status = 0;
2821 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2822 (unsigned char *) &nop.nop_h.ac_status,
2823 sizeof(nop.nop_h.ac_status));
2824 nop.nop_h.ac_link = txblock;
2825 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2826 (unsigned char *) &nop.nop_h.ac_link,
2827 sizeof(nop.nop_h.ac_link));
2829 /* Make sure the watchdog will keep quiet for a while */
2830 dev->trans_start = jiffies;
2832 /* Keep stats up to date. */
2833 dev->stats.tx_bytes += length;
2835 if (lp->tx_first_in_use == I82586NULL)
2836 lp->tx_first_in_use = txblock;
2838 if (lp->tx_n_in_use < NTXBLOCKS - 1)
2839 netif_wake_queue(dev);
2841 spin_unlock_irqrestore(&lp->spinlock, flags);
2843 #ifdef DEBUG_TX_INFO
2844 wv_packet_info((u8 *) buf, length, dev->name,
2846 #endif /* DEBUG_TX_INFO */
2848 #ifdef DEBUG_TX_TRACE
2849 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
2855 /*------------------------------------------------------------------*/
2857 * This routine is called when we want to send a packet (NET3 callback)
2858 * In this routine, we check if the harware is ready to accept
2859 * the packet. We also prevent reentrance. Then we call the function
2860 * to send the packet.
2862 static netdev_tx_t wavelan_packet_xmit(struct sk_buff *skb,
2863 struct net_device *dev)
2865 net_local *lp = netdev_priv(dev);
2866 unsigned long flags;
2867 char data[ETH_ZLEN];
2869 #ifdef DEBUG_TX_TRACE
2870 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
2875 *block a timer-based transmit from overlapping.
2876 * In other words, prevent reentering this routine.
2878 netif_stop_queue(dev);
2880 /* If somebody has asked to reconfigure the controller,
2883 if (lp->reconfig_82586) {
2884 spin_lock_irqsave(&lp->spinlock, flags);
2885 wv_82586_config(dev);
2886 spin_unlock_irqrestore(&lp->spinlock, flags);
2887 /* Check that we can continue */
2888 if (lp->tx_n_in_use == (NTXBLOCKS - 1))
2889 return NETDEV_TX_BUSY;
2892 /* Do we need some padding? */
2893 /* Note : on wireless the propagation time is in the order of 1us,
2894 * and we don't have the Ethernet specific requirement of beeing
2895 * able to detect collisions, therefore in theory we don't really
2896 * need to pad. Jean II */
2897 if (skb->len < ETH_ZLEN) {
2898 memset(data, 0, ETH_ZLEN);
2899 skb_copy_from_linear_data(skb, data, skb->len);
2900 /* Write packet on the card */
2901 if(wv_packet_write(dev, data, ETH_ZLEN))
2902 return NETDEV_TX_BUSY; /* We failed */
2904 else if(wv_packet_write(dev, skb->data, skb->len))
2905 return NETDEV_TX_BUSY; /* We failed */
2910 #ifdef DEBUG_TX_TRACE
2911 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
2913 return NETDEV_TX_OK;
2916 /*********************** HARDWARE CONFIGURATION ***********************/
2918 * This part does the real job of starting and configuring the hardware.
2921 /*--------------------------------------------------------------------*/
2923 * Routine to initialize the Modem Management Controller.
2924 * (called by wv_hw_reset())
2926 static int wv_mmc_init(struct net_device *dev)
2928 unsigned long ioaddr = dev->base_addr;
2929 net_local *lp = netdev_priv(dev);
2934 #ifdef DEBUG_CONFIG_TRACE
2935 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
2938 /* Read the parameter storage area. */
2939 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
2941 #ifdef USE_PSA_CONFIG
2942 configured = psa.psa_conf_status & 1;
2947 /* Is the PSA is not configured */
2949 /* User will be able to configure NWID later (with iwconfig). */
2950 psa.psa_nwid[0] = 0;
2951 psa.psa_nwid[1] = 0;
2953 /* no NWID checking since NWID is not set */
2954 psa.psa_nwid_select = 0;
2956 /* Disable encryption */
2957 psa.psa_encryption_select = 0;
2959 /* Set to standard values:
2962 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
2964 if (psa.psa_comp_number & 1)
2965 psa.psa_thr_pre_set = 0x01;
2967 psa.psa_thr_pre_set = 0x04;
2968 psa.psa_quality_thr = 0x03;
2970 /* It is configured */
2971 psa.psa_conf_status |= 1;
2973 #ifdef USE_PSA_CONFIG
2974 /* Write the psa. */
2975 psa_write(ioaddr, lp->hacr,
2976 (char *) psa.psa_nwid - (char *) &psa,
2977 (unsigned char *) psa.psa_nwid, 4);
2978 psa_write(ioaddr, lp->hacr,
2979 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2980 (unsigned char *) &psa.psa_thr_pre_set, 1);
2981 psa_write(ioaddr, lp->hacr,
2982 (char *) &psa.psa_quality_thr - (char *) &psa,
2983 (unsigned char *) &psa.psa_quality_thr, 1);
2984 psa_write(ioaddr, lp->hacr,
2985 (char *) &psa.psa_conf_status - (char *) &psa,
2986 (unsigned char *) &psa.psa_conf_status, 1);
2987 /* update the Wavelan checksum */
2988 update_psa_checksum(dev, ioaddr, lp->hacr);
2992 /* Zero the mmc structure. */
2993 memset(&m, 0x00, sizeof(m));
2995 /* Copy PSA info to the mmc. */
2996 m.mmw_netw_id_l = psa.psa_nwid[1];
2997 m.mmw_netw_id_h = psa.psa_nwid[0];
2999 if (psa.psa_nwid_select & 1)
3000 m.mmw_loopt_sel = 0x00;
3002 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
3004 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
3005 sizeof(m.mmw_encr_key));
3007 if (psa.psa_encryption_select)
3009 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
3011 m.mmw_encr_enable = 0;
3013 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
3014 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
3017 * Set default modem control parameters.
3018 * See NCR document 407-0024326 Rev. A.
3020 m.mmw_jabber_enable = 0x01;
3022 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
3024 m.mmw_mod_delay = 0x04;
3025 m.mmw_jam_time = 0x38;
3027 m.mmw_des_io_invert = 0;
3028 m.mmw_decay_prm = 0;
3029 m.mmw_decay_updat_prm = 0;
3031 /* Write all info to MMC. */
3032 mmc_write(ioaddr, 0, (u8 *) & m, sizeof(m));
3034 /* The following code starts the modem of the 2.00 frequency
3035 * selectable cards at power on. It's not strictly needed for the
3037 * The original patch was by Joe Finney for the PCMCIA driver, but
3038 * I've cleaned it up a bit and added documentation.
3039 * Thanks to Loeke Brederveld from Lucent for the info.
3042 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3043 * Does it work for everybody, especially old cards? */
3044 /* Note: WFREQSEL verifies that it is able to read a sensible
3045 * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
3046 * is 0xA (Xilinx version) or 0xB (Ariadne version).
3047 * My test is more crude but does work. */
3048 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
3049 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
3050 /* We must download the frequency parameters to the
3051 * synthesizers (from the EEPROM - area 1)
3052 * Note: as the EEPROM is automatically decremented, we set the end
3054 m.mmw_fee_addr = 0x0F;
3055 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3056 mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
3057 (unsigned char *) &m.mmw_fee_ctrl, 2);
3059 /* Wait until the download is finished. */
3060 fee_wait(ioaddr, 100, 100);
3062 #ifdef DEBUG_CONFIG_INFO
3063 /* The frequency was in the last word downloaded. */
3064 mmc_read(ioaddr, (char *) &m.mmw_fee_data_l - (char *) &m,
3065 (unsigned char *) &m.mmw_fee_data_l, 2);
3067 /* Print some info for the user. */
3069 "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n",
3072 mmw_fee_data_h << 4) | (m.mmw_fee_data_l >> 4)) *
3076 /* We must now download the power adjust value (gain) to
3077 * the synthesizers (from the EEPROM - area 7 - DAC). */
3078 m.mmw_fee_addr = 0x61;
3079 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3080 mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
3081 (unsigned char *) &m.mmw_fee_ctrl, 2);
3083 /* Wait until the download is finished. */
3086 #ifdef DEBUG_CONFIG_TRACE
3087 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3092 /*------------------------------------------------------------------*/
3094 * Construct the fd and rbd structures.
3095 * Start the receive unit.
3096 * (called by wv_hw_reset())
3098 static int wv_ru_start(struct net_device *dev)
3100 net_local *lp = netdev_priv(dev);
3101 unsigned long ioaddr = dev->base_addr;
3109 #ifdef DEBUG_CONFIG_TRACE
3110 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3113 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3114 (unsigned char *) &scb_cs, sizeof(scb_cs));
3115 if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
3118 lp->rx_head = OFFSET_RU;
3120 for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next) {
3122 (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
3125 fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
3126 fd.fd_link_offset = rx_next;
3127 fd.fd_rbd_offset = rx + sizeof(fd);
3128 obram_write(ioaddr, rx, (unsigned char *) &fd, sizeof(fd));
3131 rbd.rbd_next_rbd_offset = I82586NULL;
3132 rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
3134 rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
3135 obram_write(ioaddr, rx + sizeof(fd),
3136 (unsigned char *) &rbd, sizeof(rbd));
3141 obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
3142 (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
3144 scb_cs = SCB_CMD_RUC_GO;
3145 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3146 (unsigned char *) &scb_cs, sizeof(scb_cs));
3148 set_chan_attn(ioaddr, lp->hacr);
3150 for (i = 1000; i > 0; i--) {
3151 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3152 (unsigned char *) &scb_cs, sizeof(scb_cs));
3160 #ifdef DEBUG_CONFIG_ERROR
3162 "%s: wavelan_ru_start(): board not accepting command.\n",
3167 #ifdef DEBUG_CONFIG_TRACE
3168 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3173 /*------------------------------------------------------------------*/
3175 * Initialise the transmit blocks.
3176 * Start the command unit executing the NOP
3177 * self-loop of the first transmit block.
3179 * Here we create the list of send buffers used to transmit packets
3180 *between the PC and the command unit. For each buffer, we create a
3181 *buffer descriptor (pointing on the buffer), a transmit command
3182 * (pointing to the buffer descriptor) and a NOP command.
3183 * The transmit command is linked to the NOP, and the NOP to itself.
3184 * When we will have finished executing the transmit command, we will
3185 * then loop on the NOP. By releasing the NOP link to a new command,
3186 * we may send another buffer.
3188 * (called by wv_hw_reset())
3190 static int wv_cu_start(struct net_device *dev)
3192 net_local *lp = netdev_priv(dev);
3193 unsigned long ioaddr = dev->base_addr;
3199 #ifdef DEBUG_CONFIG_TRACE
3200 printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
3203 lp->tx_first_free = OFFSET_CU;
3204 lp->tx_first_in_use = I82586NULL;
3206 for (i = 0, txblock = OFFSET_CU;
3207 i < NTXBLOCKS; i++, txblock += TXBLOCKZ) {
3211 unsigned short tx_addr;
3212 unsigned short nop_addr;
3213 unsigned short tbd_addr;
3214 unsigned short buf_addr;
3217 nop_addr = tx_addr + sizeof(tx);
3218 tbd_addr = nop_addr + sizeof(nop);
3219 buf_addr = tbd_addr + sizeof(tbd);
3221 tx.tx_h.ac_status = 0;
3222 tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
3223 tx.tx_h.ac_link = nop_addr;
3224 tx.tx_tbd_offset = tbd_addr;
3225 obram_write(ioaddr, tx_addr, (unsigned char *) &tx,
3228 nop.nop_h.ac_status = 0;
3229 nop.nop_h.ac_command = acmd_nop;
3230 nop.nop_h.ac_link = nop_addr;
3231 obram_write(ioaddr, nop_addr, (unsigned char *) &nop,
3234 tbd.tbd_status = TBD_STATUS_EOF;
3235 tbd.tbd_next_bd_offset = I82586NULL;
3236 tbd.tbd_bufl = buf_addr;
3238 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd,
3243 OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
3244 obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
3245 (unsigned char *) &first_nop, sizeof(first_nop));
3247 scb_cs = SCB_CMD_CUC_GO;
3248 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3249 (unsigned char *) &scb_cs, sizeof(scb_cs));
3251 set_chan_attn(ioaddr, lp->hacr);
3253 for (i = 1000; i > 0; i--) {
3254 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3255 (unsigned char *) &scb_cs, sizeof(scb_cs));
3263 #ifdef DEBUG_CONFIG_ERROR
3265 "%s: wavelan_cu_start(): board not accepting command.\n",
3271 lp->tx_n_in_use = 0;
3272 netif_start_queue(dev);
3273 #ifdef DEBUG_CONFIG_TRACE
3274 printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
3279 /*------------------------------------------------------------------*/
3281 * This routine does a standard configuration of the WaveLAN
3282 * controller (i82586).
3284 * It initialises the scp, iscp and scb structure
3285 * The first two are just pointers to the next.
3286 * The last one is used for basic configuration and for basic
3287 * communication (interrupt status).
3289 * (called by wv_hw_reset())
3291 static int wv_82586_start(struct net_device *dev)
3293 net_local *lp = netdev_priv(dev);
3294 unsigned long ioaddr = dev->base_addr;
3295 scp_t scp; /* system configuration pointer */
3296 iscp_t iscp; /* intermediate scp */
3297 scb_t scb; /* system control block */
3298 ach_t cb; /* Action command header */
3302 #ifdef DEBUG_CONFIG_TRACE
3303 printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
3307 * Clear the onboard RAM.
3309 memset(&zeroes[0], 0x00, sizeof(zeroes));
3310 for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
3311 obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
3314 * Construct the command unit structures:
3315 * scp, iscp, scb, cb.
3317 memset(&scp, 0x00, sizeof(scp));
3318 scp.scp_sysbus = SCP_SY_16BBUS;
3319 scp.scp_iscpl = OFFSET_ISCP;
3320 obram_write(ioaddr, OFFSET_SCP, (unsigned char *) &scp,
3323 memset(&iscp, 0x00, sizeof(iscp));
3325 iscp.iscp_offset = OFFSET_SCB;
3326 obram_write(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3329 /* Our first command is to reset the i82586. */
3330 memset(&scb, 0x00, sizeof(scb));
3331 scb.scb_command = SCB_CMD_RESET;
3332 scb.scb_cbl_offset = OFFSET_CU;
3333 scb.scb_rfa_offset = OFFSET_RU;
3334 obram_write(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3337 set_chan_attn(ioaddr, lp->hacr);
3339 /* Wait for command to finish. */
3340 for (i = 1000; i > 0; i--) {
3341 obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3344 if (iscp.iscp_busy == (unsigned short) 0)
3351 #ifdef DEBUG_CONFIG_ERROR
3353 "%s: wv_82586_start(): iscp_busy timeout.\n",
3359 /* Check command completion. */
3360 for (i = 15; i > 0; i--) {
3361 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3364 if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
3371 #ifdef DEBUG_CONFIG_ERROR
3373 "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
3374 dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
3381 /* Set the action command header. */
3382 memset(&cb, 0x00, sizeof(cb));
3383 cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
3384 cb.ac_link = OFFSET_CU;
3385 obram_write(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3387 if (wv_synchronous_cmd(dev, "diag()") == -1)
3390 obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3391 if (cb.ac_status & AC_SFLD_FAIL) {
3392 #ifdef DEBUG_CONFIG_ERROR
3394 "%s: wv_82586_start(): i82586 Self Test failed.\n",
3399 #ifdef DEBUG_I82586_SHOW
3400 wv_scb_show(ioaddr);
3403 #ifdef DEBUG_CONFIG_TRACE
3404 printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
3409 /*------------------------------------------------------------------*/
3411 * This routine does a standard configuration of the WaveLAN
3412 * controller (i82586).
3414 * This routine is a violent hack. We use the first free transmit block
3415 * to make our configuration. In the buffer area, we create the three
3416 * configuration commands (linked). We make the previous NOP point to
3417 * the beginning of the buffer instead of the tx command. After, we go
3418 * as usual to the NOP command.
3419 * Note that only the last command (mc_set) will generate an interrupt.
3421 * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit())
3423 static void wv_82586_config(struct net_device *dev)
3425 net_local *lp = netdev_priv(dev);
3426 unsigned long ioaddr = dev->base_addr;
3427 unsigned short txblock;
3428 unsigned short txpred;
3429 unsigned short tx_addr;
3430 unsigned short nop_addr;
3431 unsigned short tbd_addr;
3432 unsigned short cfg_addr;
3433 unsigned short ias_addr;
3434 unsigned short mcs_addr;
3437 ac_cfg_t cfg; /* Configure action */
3438 ac_ias_t ias; /* IA-setup action */
3439 ac_mcs_t mcs; /* Multicast setup */
3440 struct dev_mc_list *dmi;
3442 #ifdef DEBUG_CONFIG_TRACE
3443 printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
3446 /* Check nothing bad has happened */
3447 if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
3448 #ifdef DEBUG_CONFIG_ERROR
3449 printk(KERN_INFO "%s: wv_82586_config(): Tx queue full.\n",
3455 /* Calculate addresses of next block and previous block. */
3456 txblock = lp->tx_first_free;
3457 txpred = txblock - TXBLOCKZ;
3458 if (txpred < OFFSET_CU)
3459 txpred += NTXBLOCKS * TXBLOCKZ;
3460 lp->tx_first_free += TXBLOCKZ;
3461 if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
3462 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
3466 /* Calculate addresses of the different parts of the block. */
3468 nop_addr = tx_addr + sizeof(tx);
3469 tbd_addr = nop_addr + sizeof(nop);
3470 cfg_addr = tbd_addr + sizeof(tbd_t); /*beginning of the buffer */
3471 ias_addr = cfg_addr + sizeof(cfg);
3472 mcs_addr = ias_addr + sizeof(ias);
3477 tx.tx_h.ac_status = 0xFFFF; /* Fake completion value */
3478 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
3479 (unsigned char *) &tx.tx_h.ac_status,
3480 sizeof(tx.tx_h.ac_status));
3485 nop.nop_h.ac_status = 0;
3486 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3487 (unsigned char *) &nop.nop_h.ac_status,
3488 sizeof(nop.nop_h.ac_status));
3489 nop.nop_h.ac_link = nop_addr;
3490 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3491 (unsigned char *) &nop.nop_h.ac_link,
3492 sizeof(nop.nop_h.ac_link));
3494 /* Create a configure action. */
3495 memset(&cfg, 0x00, sizeof(cfg));
3498 * For Linux we invert AC_CFG_ALOC() so as to conform
3499 * to the way that net packets reach us from above.
3500 * (See also ac_tx_t.)
3502 * Updated from Wavelan Manual WCIN085B
3505 AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
3506 cfg.cfg_fifolim = AC_CFG_FIFOLIM(4);
3507 cfg.cfg_byte8 = AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0);
3508 cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
3510 AC_CFG_PRELEN(AC_CFG_PLEN_2) |
3511 AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
3512 cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
3513 AC_CFG_ACR(6) | AC_CFG_LINPRIO(0);
3515 cfg.cfg_slotl = 0x0C;
3516 cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0);
3517 cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
3523 AC_CFG_BCDIS(0) | AC_CFG_PRM(lp->promiscuous);
3524 cfg.cfg_byte15 = AC_CFG_ICDS(0) |
3525 AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0);
3527 cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
3529 cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
3531 cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
3532 cfg.cfg_h.ac_link = ias_addr;
3533 obram_write(ioaddr, cfg_addr, (unsigned char *) &cfg, sizeof(cfg));
3535 /* Set up the MAC address */
3536 memset(&ias, 0x00, sizeof(ias));
3537 ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
3538 ias.ias_h.ac_link = mcs_addr;
3539 memcpy(&ias.ias_addr[0], (unsigned char *) &dev->dev_addr[0],
3540 sizeof(ias.ias_addr));
3541 obram_write(ioaddr, ias_addr, (unsigned char *) &ias, sizeof(ias));
3543 /* Initialize adapter's Ethernet multicast addresses */
3544 memset(&mcs, 0x00, sizeof(mcs));
3545 mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
3546 mcs.mcs_h.ac_link = nop_addr;
3547 mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
3548 obram_write(ioaddr, mcs_addr, (unsigned char *) &mcs, sizeof(mcs));
3550 /* Any address to set? */
3552 netdev_for_each_mc_addr(dmi, dev)
3553 outsw(PIOP1(ioaddr), (u16 *) dmi->dmi_addr,
3554 WAVELAN_ADDR_SIZE >> 1);
3556 #ifdef DEBUG_CONFIG_INFO
3558 "%s: wv_82586_config(): set %d multicast addresses:\n",
3559 dev->name, lp->mc_count);
3560 netdev_for_each_mc_addr(dmi, dev)
3561 printk(KERN_DEBUG " %pM\n", dmi->dmi_addr);
3566 * Overwrite the predecessor NOP link
3567 * so that it points to the configure action.
3569 nop_addr = txpred + sizeof(tx);
3570 nop.nop_h.ac_status = 0;
3571 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3572 (unsigned char *) &nop.nop_h.ac_status,
3573 sizeof(nop.nop_h.ac_status));
3574 nop.nop_h.ac_link = cfg_addr;
3575 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3576 (unsigned char *) &nop.nop_h.ac_link,
3577 sizeof(nop.nop_h.ac_link));
3579 /* Job done, clear the flag */
3580 lp->reconfig_82586 = 0;
3582 if (lp->tx_first_in_use == I82586NULL)
3583 lp->tx_first_in_use = txblock;
3585 if (lp->tx_n_in_use == (NTXBLOCKS - 1))
3586 netif_stop_queue(dev);
3588 #ifdef DEBUG_CONFIG_TRACE
3589 printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
3593 /*------------------------------------------------------------------*/
3595 * This routine, called by wavelan_close(), gracefully stops the
3596 * WaveLAN controller (i82586).
3597 * (called by wavelan_close())
3599 static void wv_82586_stop(struct net_device *dev)
3601 net_local *lp = netdev_priv(dev);
3602 unsigned long ioaddr = dev->base_addr;
3605 #ifdef DEBUG_CONFIG_TRACE
3606 printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
3609 /* Suspend both command unit and receive unit. */
3611 (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC &
3613 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3614 (unsigned char *) &scb_cmd, sizeof(scb_cmd));
3615 set_chan_attn(ioaddr, lp->hacr);
3617 /* No more interrupts */
3620 #ifdef DEBUG_CONFIG_TRACE
3621 printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
3625 /*------------------------------------------------------------------*/
3627 * Totally reset the WaveLAN and restart it.
3628 * Performs the following actions:
3629 * 1. A power reset (reset DMA)
3630 * 2. Initialize the radio modem (using wv_mmc_init)
3631 * 3. Reset & Configure LAN controller (using wv_82586_start)
3632 * 4. Start the LAN controller's command unit
3633 * 5. Start the LAN controller's receive unit
3634 * (called by wavelan_interrupt(), wavelan_watchdog() & wavelan_open())
3636 static int wv_hw_reset(struct net_device *dev)
3638 net_local *lp = netdev_priv(dev);
3639 unsigned long ioaddr = dev->base_addr;
3641 #ifdef DEBUG_CONFIG_TRACE
3642 printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
3643 (unsigned int) dev);
3646 /* Increase the number of resets done. */
3649 wv_hacr_reset(ioaddr);
3650 lp->hacr = HACR_DEFAULT;
3652 if ((wv_mmc_init(dev) < 0) || (wv_82586_start(dev) < 0))
3655 /* Enable the card to send interrupts. */
3658 /* Start card functions */
3659 if (wv_cu_start(dev) < 0)
3662 /* Setup the controller and parameters */
3663 wv_82586_config(dev);
3665 /* Finish configuration with the receive unit */
3666 if (wv_ru_start(dev) < 0)
3669 #ifdef DEBUG_CONFIG_TRACE
3670 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3675 /*------------------------------------------------------------------*/
3677 * Check if there is a WaveLAN at the specific base address.
3678 * As a side effect, this reads the MAC address.
3679 * (called in wavelan_probe() and init_module())
3681 static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac)
3683 int i; /* Loop counter */
3685 /* Check if the base address if available. */
3686 if (!request_region(ioaddr, sizeof(ha_t), "wavelan probe"))
3687 return -EBUSY; /* ioaddr already used */
3689 /* Reset host interface */
3690 wv_hacr_reset(ioaddr);
3692 /* Read the MAC address from the parameter storage area. */
3693 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
3696 release_region(ioaddr, sizeof(ha_t));
3699 * Check the first three octets of the address for the manufacturer's code.
3700 * Note: if this can't find your WaveLAN card, you've got a
3701 * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on
3702 * how to configure your card.
3704 for (i = 0; i < ARRAY_SIZE(MAC_ADDRESSES); i++)
3705 if ((mac[0] == MAC_ADDRESSES[i][0]) &&
3706 (mac[1] == MAC_ADDRESSES[i][1]) &&
3707 (mac[2] == MAC_ADDRESSES[i][2]))
3710 #ifdef DEBUG_CONFIG_INFO
3712 "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
3713 ioaddr, mac[0], mac[1], mac[2]);
3718 /************************ INTERRUPT HANDLING ************************/
3721 * This function is the interrupt handler for the WaveLAN card. This
3722 * routine will be called whenever:
3724 static irqreturn_t wavelan_interrupt(int irq, void *dev_id)
3726 struct net_device *dev;
3727 unsigned long ioaddr;
3735 #ifdef DEBUG_INTERRUPT_TRACE
3736 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
3739 lp = netdev_priv(dev);
3740 ioaddr = dev->base_addr;
3742 #ifdef DEBUG_INTERRUPT_INFO
3743 /* Check state of our spinlock */
3744 if(spin_is_locked(&lp->spinlock))
3746 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
3750 /* Prevent reentrancy. We need to do that because we may have
3751 * multiple interrupt handler running concurrently.
3752 * It is safe because interrupts are disabled before acquiring
3754 spin_lock(&lp->spinlock);
3756 /* We always had spurious interrupts at startup, but lately I
3757 * saw them comming *between* the request_irq() and the
3758 * spin_lock_irqsave() in wavelan_open(), so the spinlock
3759 * protection is no enough.
3760 * So, we also check lp->hacr that will tell us is we enabled
3761 * irqs or not (see wv_ints_on()).
3762 * We can't use netif_running(dev) because we depend on the
3763 * proper processing of the irq generated during the config. */
3765 /* Which interrupt it is ? */
3766 hasr = hasr_read(ioaddr);
3768 #ifdef DEBUG_INTERRUPT_INFO
3770 "%s: wavelan_interrupt(): hasr 0x%04x; hacr 0x%04x.\n",
3771 dev->name, hasr, lp->hacr);
3774 /* Check modem interrupt */
3775 if ((hasr & HASR_MMC_INTR) && (lp->hacr & HACR_MMC_INT_ENABLE)) {
3779 * Interrupt from the modem management controller.
3780 * This will clear it -- ignored for now.
3782 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status,
3783 sizeof(dce_status));
3785 #ifdef DEBUG_INTERRUPT_ERROR
3787 "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
3788 dev->name, dce_status);
3792 /* Check if not controller interrupt */
3793 if (((hasr & HASR_82586_INTR) == 0) ||
3794 ((lp->hacr & HACR_82586_INT_ENABLE) == 0)) {
3795 #ifdef DEBUG_INTERRUPT_ERROR
3797 "%s: wavelan_interrupt(): interrupt not coming from i82586 - hasr 0x%04x.\n",
3800 spin_unlock (&lp->spinlock);
3804 /* Read interrupt data. */
3805 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3806 (unsigned char *) &status, sizeof(status));
3809 * Acknowledge the interrupt(s).
3811 ack_cmd = status & SCB_ST_INT;
3812 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3813 (unsigned char *) &ack_cmd, sizeof(ack_cmd));
3814 set_chan_attn(ioaddr, lp->hacr);
3816 #ifdef DEBUG_INTERRUPT_INFO
3817 printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
3821 /* Command completed. */
3822 if ((status & SCB_ST_CX) == SCB_ST_CX) {
3823 #ifdef DEBUG_INTERRUPT_INFO
3825 "%s: wavelan_interrupt(): command completed.\n",
3828 wv_complete(dev, ioaddr, lp);
3831 /* Frame received. */
3832 if ((status & SCB_ST_FR) == SCB_ST_FR) {
3833 #ifdef DEBUG_INTERRUPT_INFO
3835 "%s: wavelan_interrupt(): received packet.\n",
3841 /* Check the state of the command unit. */
3842 if (((status & SCB_ST_CNA) == SCB_ST_CNA) ||
3843 (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) &&
3844 (netif_running(dev)))) {
3845 #ifdef DEBUG_INTERRUPT_ERROR
3847 "%s: wavelan_interrupt(): CU inactive -- restarting\n",
3853 /* Check the state of the command unit. */
3854 if (((status & SCB_ST_RNR) == SCB_ST_RNR) ||
3855 (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) &&
3856 (netif_running(dev)))) {
3857 #ifdef DEBUG_INTERRUPT_ERROR
3859 "%s: wavelan_interrupt(): RU not ready -- restarting\n",
3865 /* Release spinlock */
3866 spin_unlock (&lp->spinlock);
3868 #ifdef DEBUG_INTERRUPT_TRACE
3869 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
3874 /*------------------------------------------------------------------*/
3876 * Watchdog: when we start a transmission, a timer is set for us in the
3877 * kernel. If the transmission completes, this timer is disabled. If
3878 * the timer expires, we are called and we try to unlock the hardware.
3880 static void wavelan_watchdog(struct net_device * dev)
3882 net_local *lp = netdev_priv(dev);
3883 u_long ioaddr = dev->base_addr;
3884 unsigned long flags;
3885 unsigned int nreaped;
3887 #ifdef DEBUG_INTERRUPT_TRACE
3888 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
3891 #ifdef DEBUG_INTERRUPT_ERROR
3892 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
3896 /* Check that we came here for something */
3897 if (lp->tx_n_in_use <= 0) {
3901 spin_lock_irqsave(&lp->spinlock, flags);
3903 /* Try to see if some buffers are not free (in case we missed
3905 nreaped = wv_complete(dev, ioaddr, lp);
3907 #ifdef DEBUG_INTERRUPT_INFO
3909 "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
3910 dev->name, nreaped, lp->tx_n_in_use);
3913 #ifdef DEBUG_PSA_SHOW
3916 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3920 #ifdef DEBUG_MMC_SHOW
3923 #ifdef DEBUG_I82586_SHOW
3927 /* If no buffer has been freed */
3929 #ifdef DEBUG_INTERRUPT_ERROR
3931 "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
3937 /* At this point, we should have some free Tx buffer ;-) */
3938 if (lp->tx_n_in_use < NTXBLOCKS - 1)
3939 netif_wake_queue(dev);
3941 spin_unlock_irqrestore(&lp->spinlock, flags);
3943 #ifdef DEBUG_INTERRUPT_TRACE
3944 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
3948 /********************* CONFIGURATION CALLBACKS *********************/
3950 * Here are the functions called by the Linux networking code (NET3)
3951 * for initialization, configuration and deinstallations of the
3952 * WaveLAN ISA hardware.
3955 /*------------------------------------------------------------------*/
3957 * Configure and start up the WaveLAN PCMCIA adaptor.
3958 * Called by NET3 when it "opens" the device.
3960 static int wavelan_open(struct net_device *dev)
3962 net_local *lp = netdev_priv(dev);
3963 unsigned long flags;
3965 #ifdef DEBUG_CALLBACK_TRACE
3966 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
3967 (unsigned int) dev);
3971 if (dev->irq == 0) {
3972 #ifdef DEBUG_CONFIG_ERROR
3973 printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n",
3979 if (request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0)
3981 #ifdef DEBUG_CONFIG_ERROR
3982 printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n",
3988 spin_lock_irqsave(&lp->spinlock, flags);
3990 if (wv_hw_reset(dev) != -1) {
3991 netif_start_queue(dev);
3993 free_irq(dev->irq, dev);
3994 #ifdef DEBUG_CONFIG_ERROR
3996 "%s: wavelan_open(): impossible to start the card\n",
3999 spin_unlock_irqrestore(&lp->spinlock, flags);
4002 spin_unlock_irqrestore(&lp->spinlock, flags);
4004 #ifdef DEBUG_CALLBACK_TRACE
4005 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
4010 /*------------------------------------------------------------------*/
4012 * Shut down the WaveLAN ISA card.
4013 * Called by NET3 when it "closes" the device.
4015 static int wavelan_close(struct net_device *dev)
4017 net_local *lp = netdev_priv(dev);
4018 unsigned long flags;
4020 #ifdef DEBUG_CALLBACK_TRACE
4021 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
4022 (unsigned int) dev);
4025 netif_stop_queue(dev);
4028 * Flush the Tx and disable Rx.
4030 spin_lock_irqsave(&lp->spinlock, flags);
4032 spin_unlock_irqrestore(&lp->spinlock, flags);
4034 free_irq(dev->irq, dev);
4036 #ifdef DEBUG_CALLBACK_TRACE
4037 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
4042 static const struct net_device_ops wavelan_netdev_ops = {
4043 .ndo_open = wavelan_open,
4044 .ndo_stop = wavelan_close,
4045 .ndo_start_xmit = wavelan_packet_xmit,
4046 .ndo_set_multicast_list = wavelan_set_multicast_list,
4047 .ndo_tx_timeout = wavelan_watchdog,
4048 .ndo_change_mtu = eth_change_mtu,
4049 .ndo_validate_addr = eth_validate_addr,
4050 #ifdef SET_MAC_ADDRESS
4051 .ndo_set_mac_address = wavelan_set_mac_address
4053 .ndo_set_mac_address = eth_mac_addr,
4058 /*------------------------------------------------------------------*/
4060 * Probe an I/O address, and if the WaveLAN is there configure the
4062 * (called by wavelan_probe() and via init_module()).
4064 static int __init wavelan_config(struct net_device *dev, unsigned short ioaddr)
4072 if (!request_region(ioaddr, sizeof(ha_t), "wavelan"))
4075 err = wv_check_ioaddr(ioaddr, mac);
4079 memcpy(dev->dev_addr, mac, 6);
4081 dev->base_addr = ioaddr;
4083 #ifdef DEBUG_CALLBACK_TRACE
4084 printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%lx)\n",
4085 dev->name, (unsigned int) dev, ioaddr);
4088 /* Check IRQ argument on command line. */
4089 if (dev->irq != 0) {
4090 irq_mask = wv_irq_to_psa(dev->irq);
4092 if (irq_mask == 0) {
4093 #ifdef DEBUG_CONFIG_ERROR
4095 "%s: wavelan_config(): invalid IRQ %d ignored.\n",
4096 dev->name, dev->irq);
4100 #ifdef DEBUG_CONFIG_INFO
4102 "%s: wavelan_config(): changing IRQ to %d\n",
4103 dev->name, dev->irq);
4105 psa_write(ioaddr, HACR_DEFAULT,
4106 psaoff(0, psa_int_req_no), &irq_mask, 1);
4107 /* update the Wavelan checksum */
4108 update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
4109 wv_hacr_reset(ioaddr);
4113 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no),
4115 if ((irq = wv_psa_to_irq(irq_mask)) == -1) {
4116 #ifdef DEBUG_CONFIG_ERROR
4118 "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
4119 dev->name, irq_mask);
4127 dev->mem_start = 0x0000;
4128 dev->mem_end = 0x0000;
4131 /* Initialize device structures */
4132 memset(netdev_priv(dev), 0, sizeof(net_local));
4133 lp = netdev_priv(dev);
4135 /*back link to the device structure. */
4137 /* Add the device at the beginning of the linked list. */
4138 lp->next = wavelan_list;
4141 lp->hacr = HACR_DEFAULT;
4143 /* Multicast stuff */
4144 lp->promiscuous = 0;
4148 spin_lock_init(&lp->spinlock);
4150 dev->netdev_ops = &wavelan_netdev_ops;
4151 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4152 dev->wireless_handlers = &wavelan_handler_def;
4153 lp->wireless_data.spy_data = &lp->spy_data;
4154 dev->wireless_data = &lp->wireless_data;
4156 dev->mtu = WAVELAN_MTU;
4158 /* Display nice information. */
4161 #ifdef DEBUG_CALLBACK_TRACE
4162 printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
4166 release_region(ioaddr, sizeof(ha_t));
4170 /*------------------------------------------------------------------*/
4172 * Check for a network adaptor of this type. Return '0' iff one
4173 * exists. There seem to be different interpretations of
4174 * the initial value of dev->base_addr.
4175 * We follow the example in drivers/net/ne.c.
4176 * (called in "Space.c")
4178 struct net_device * __init wavelan_probe(int unit)
4180 struct net_device *dev;
4186 /* compile-time check the sizes of structures */
4187 BUILD_BUG_ON(sizeof(psa_t) != PSA_SIZE);
4188 BUILD_BUG_ON(sizeof(mmw_t) != MMW_SIZE);
4189 BUILD_BUG_ON(sizeof(mmr_t) != MMR_SIZE);
4190 BUILD_BUG_ON(sizeof(ha_t) != HA_SIZE);
4192 dev = alloc_etherdev(sizeof(net_local));
4194 return ERR_PTR(-ENOMEM);
4196 sprintf(dev->name, "eth%d", unit);
4197 netdev_boot_setup_check(dev);
4198 base_addr = dev->base_addr;
4201 #ifdef DEBUG_CALLBACK_TRACE
4203 "%s: ->wavelan_probe(dev=%p (base_addr=0x%x))\n",
4204 dev->name, dev, (unsigned int) dev->base_addr);
4207 /* Don't probe at all. */
4208 if (base_addr < 0) {
4209 #ifdef DEBUG_CONFIG_ERROR
4211 "%s: wavelan_probe(): invalid base address\n",
4215 } else if (base_addr > 0x100) { /* Check a single specified location. */
4216 r = wavelan_config(dev, base_addr);
4217 #ifdef DEBUG_CONFIG_INFO
4220 "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
4221 dev->name, base_addr);
4224 #ifdef DEBUG_CALLBACK_TRACE
4225 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4227 } else { /* Scan all possible addresses of the WaveLAN hardware. */
4228 for (i = 0; i < ARRAY_SIZE(iobase); i++) {
4230 if (wavelan_config(dev, iobase[i]) == 0) {
4231 #ifdef DEBUG_CALLBACK_TRACE
4233 "%s: <-wavelan_probe()\n",
4239 if (i == ARRAY_SIZE(iobase))
4244 r = register_netdev(dev);
4249 release_region(dev->base_addr, sizeof(ha_t));
4250 wavelan_list = wavelan_list->next;
4256 /****************************** MODULE ******************************/
4258 * Module entry point: insertion and removal
4262 /*------------------------------------------------------------------*/
4264 * Insertion of the module
4265 * I'm now quite proud of the multi-device support.
4267 int __init init_module(void)
4269 int ret = -EIO; /* Return error if no cards found */
4272 #ifdef DEBUG_MODULE_TRACE
4273 printk(KERN_DEBUG "-> init_module()\n");
4276 /* If probing is asked */
4278 #ifdef DEBUG_CONFIG_ERROR
4280 "WaveLAN init_module(): doing device probing (bad !)\n");
4282 "Specify base addresses while loading module to correct the problem\n");
4285 /* Copy the basic set of address to be probed. */
4286 for (i = 0; i < ARRAY_SIZE(iobase); i++)
4291 /* Loop on all possible base addresses. */
4292 for (i = 0; i < ARRAY_SIZE(io) && io[i] != 0; i++) {
4293 struct net_device *dev = alloc_etherdev(sizeof(net_local));
4297 strcpy(dev->name, name[i]); /* Copy name */
4298 dev->base_addr = io[i];
4301 /* Check if there is something at this base address. */
4302 if (wavelan_config(dev, io[i]) == 0) {
4303 if (register_netdev(dev) != 0) {
4304 release_region(dev->base_addr, sizeof(ha_t));
4305 wavelan_list = wavelan_list->next;
4314 #ifdef DEBUG_CONFIG_ERROR
4317 "WaveLAN init_module(): no device found\n");
4320 #ifdef DEBUG_MODULE_TRACE
4321 printk(KERN_DEBUG "<- init_module()\n");
4326 /*------------------------------------------------------------------*/
4328 * Removal of the module
4330 void cleanup_module(void)
4332 #ifdef DEBUG_MODULE_TRACE
4333 printk(KERN_DEBUG "-> cleanup_module()\n");
4336 /* Loop on all devices and release them. */
4337 while (wavelan_list) {
4338 struct net_device *dev = wavelan_list->dev;
4340 #ifdef DEBUG_CONFIG_INFO
4342 "%s: cleanup_module(): removing device at 0x%x\n",
4343 dev->name, (unsigned int) dev);
4345 unregister_netdev(dev);
4347 release_region(dev->base_addr, sizeof(ha_t));
4348 wavelan_list = wavelan_list->next;
4353 #ifdef DEBUG_MODULE_TRACE
4354 printk(KERN_DEBUG "<- cleanup_module()\n");
4358 MODULE_LICENSE("GPL");
4361 * This software may only be used and distributed
4362 * according to the terms of the GNU General Public License.
4364 * This software was developed as a component of the
4365 * Linux operating system.
4366 * It is based on other device drivers and information
4367 * either written or supplied by:
4368 * Ajay Bakre (bakre@paul.rutgers.edu),
4369 * Donald Becker (becker@scyld.com),
4370 * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
4371 * Anders Klemets (klemets@it.kth.se),
4372 * Vladimir V. Kolpakov (w@stier.koenig.ru),
4373 * Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
4374 * Pauline Middelink (middelin@polyware.iaf.nl),
4375 * Robert Morris (rtm@das.harvard.edu),
4376 * Jean Tourrilhes (jt@hplb.hpl.hp.com),
4377 * Girish Welling (welling@paul.rutgers.edu),
4379 * Thanks go also to:
4380 * James Ashton (jaa101@syseng.anu.edu.au),
4381 * Alan Cox (alan@lxorguk.ukuu.org.uk),
4382 * Allan Creighton (allanc@cs.usyd.edu.au),
4383 * Matthew Geier (matthew@cs.usyd.edu.au),
4384 * Remo di Giovanni (remo@cs.usyd.edu.au),
4385 * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
4386 * Vipul Gupta (vgupta@cs.binghamton.edu),
4387 * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
4388 * Tim Nicholson (tim@cs.usyd.edu.au),
4389 * Ian Parkin (ian@cs.usyd.edu.au),
4390 * John Rosenberg (johnr@cs.usyd.edu.au),
4391 * George Rossi (george@phm.gov.au),
4392 * Arthur Scott (arthur@cs.usyd.edu.au),
4394 * for their assistance and advice.
4396 * Please send bug reports, updates, comments to:
4398 *bruce Janson Email: bruce@cs.usyd.edu.au
4399 *basser Department of Computer Science Phone: +61-2-9351-3423
4400 * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838