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