Merge with 2.3.99-pre1.
[linux-2.6/linux-mips.git] / drivers / net / wavelan.c
blob2162d5ff00f13ac827e42d5322e610a8df91249f
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 * Wrapper for disabling interrupts and locking the driver.
28 * (note : inline, so optimised away)
30 static inline void wv_splhi(net_local * lp,
31 unsigned long * pflags)
33 spin_lock_irqsave(&lp->spinlock, *pflags);
34 /* Note : above does the cli(); itself */
37 /*------------------------------------------------------------------*/
39 * Wrapper for re-enabling interrupts and un-locking the driver.
41 static inline void wv_splx(net_local * lp,
42 unsigned long * pflags)
44 spin_unlock_irqrestore(&lp->spinlock, *pflags);
47 /*------------------------------------------------------------------*/
49 * Translate irq number to PSA irq parameter
51 static u8 wv_irq_to_psa(int irq)
53 if (irq < 0 || irq >= NELS(irqvals))
54 return 0;
56 return irqvals[irq];
59 /*------------------------------------------------------------------*/
61 * Translate PSA irq parameter to irq number
63 static int __init wv_psa_to_irq(u8 irqval)
65 int irq;
67 for (irq = 0; irq < NELS(irqvals); irq++)
68 if (irqvals[irq] == irqval)
69 return irq;
71 return -1;
74 #ifdef STRUCT_CHECK
75 /*------------------------------------------------------------------*/
77 * Sanity routine to verify the sizes of the various WaveLAN interface
78 * structures.
80 static char *wv_struct_check(void)
82 #define SC(t,s,n) if (sizeof(t) != s) return(n);
84 SC(psa_t, PSA_SIZE, "psa_t");
85 SC(mmw_t, MMW_SIZE, "mmw_t");
86 SC(mmr_t, MMR_SIZE, "mmr_t");
87 SC(ha_t, HA_SIZE, "ha_t");
89 #undef SC
91 return ((char *) NULL);
92 } /* wv_struct_check */
93 #endif /* STRUCT_CHECK */
95 /********************* HOST ADAPTER SUBROUTINES *********************/
97 * Useful subroutines to manage the WaveLAN ISA interface
99 * One major difference with the PCMCIA hardware (except the port mapping)
100 * is that we have to keep the state of the Host Control Register
101 * because of the interrupt enable & bus size flags.
104 /*------------------------------------------------------------------*/
106 * Read from card's Host Adaptor Status Register.
108 static inline u16 hasr_read(unsigned long ioaddr)
110 return (inw(HASR(ioaddr)));
111 } /* hasr_read */
113 /*------------------------------------------------------------------*/
115 * Write to card's Host Adapter Command Register.
117 static inline void hacr_write(unsigned long ioaddr, u16 hacr)
119 outw(hacr, HACR(ioaddr));
120 } /* hacr_write */
122 /*------------------------------------------------------------------*/
124 * Write to card's Host Adapter Command Register. Include a delay for
125 * those times when it is needed.
127 static inline void hacr_write_slow(unsigned long ioaddr, u16 hacr)
129 hacr_write(ioaddr, hacr);
130 /* delay might only be needed sometimes */
131 mdelay(1);
132 } /* hacr_write_slow */
134 /*------------------------------------------------------------------*/
136 * Set the channel attention bit.
138 static inline void set_chan_attn(unsigned long ioaddr, u16 hacr)
140 hacr_write(ioaddr, hacr | HACR_CA);
141 } /* set_chan_attn */
143 /*------------------------------------------------------------------*/
145 * Reset, and then set host adaptor into default mode.
147 static inline void wv_hacr_reset(unsigned long ioaddr)
149 hacr_write_slow(ioaddr, HACR_RESET);
150 hacr_write(ioaddr, HACR_DEFAULT);
151 } /* wv_hacr_reset */
153 /*------------------------------------------------------------------*/
155 * Set the I/O transfer over the ISA bus to 8-bit mode
157 static inline void wv_16_off(unsigned long ioaddr, u16 hacr)
159 hacr &= ~HACR_16BITS;
160 hacr_write(ioaddr, hacr);
161 } /* wv_16_off */
163 /*------------------------------------------------------------------*/
165 * Set the I/O transfer over the ISA bus to 8-bit mode
167 static inline void wv_16_on(unsigned long ioaddr, u16 hacr)
169 hacr |= HACR_16BITS;
170 hacr_write(ioaddr, hacr);
171 } /* wv_16_on */
173 /*------------------------------------------------------------------*/
175 * Disable interrupts on the WaveLAN hardware.
177 static inline void wv_ints_off(device * dev)
179 net_local *lp = (net_local *) dev->priv;
180 unsigned long ioaddr = dev->base_addr;
181 unsigned long flags;
183 wv_splhi(lp, &flags);
185 lp->hacr &= ~HACR_INTRON;
186 hacr_write(ioaddr, lp->hacr);
188 wv_splx(lp, &flags);
189 } /* wv_ints_off */
191 /*------------------------------------------------------------------*/
193 * Enable interrupts on the WaveLAN hardware.
195 static inline void wv_ints_on(device * dev)
197 net_local *lp = (net_local *) dev->priv;
198 unsigned long ioaddr = dev->base_addr;
199 unsigned long flags;
201 wv_splhi(lp, &flags);
203 lp->hacr |= HACR_INTRON;
204 hacr_write(ioaddr, lp->hacr);
206 wv_splx(lp, &flags);
207 } /* wv_ints_on */
209 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
211 * Useful subroutines to manage the modem of the WaveLAN
214 /*------------------------------------------------------------------*/
216 * Read the Parameter Storage Area from the WaveLAN card's memory
219 * Read bytes from the PSA.
221 static void psa_read(unsigned long ioaddr, u16 hacr, int o, /* offset in PSA */
222 u8 * b, /* buffer to fill */
223 int n)
224 { /* size to read */
225 wv_16_off(ioaddr, hacr);
227 while (n-- > 0) {
228 outw(o, PIOR2(ioaddr));
229 o++;
230 *b++ = inb(PIOP2(ioaddr));
233 wv_16_on(ioaddr, hacr);
234 } /* psa_read */
236 /*------------------------------------------------------------------*/
238 * Write the Parameter Storage Area to the WaveLAN card's memory.
240 static void psa_write(unsigned long ioaddr, u16 hacr, int o, /* Offset in PSA */
241 u8 * b, /* Buffer in memory */
242 int n)
243 { /* Length of buffer */
244 int count = 0;
246 wv_16_off(ioaddr, hacr);
248 while (n-- > 0) {
249 outw(o, PIOR2(ioaddr));
250 o++;
252 outb(*b, PIOP2(ioaddr));
253 b++;
255 /* Wait for the memory to finish its write cycle */
256 count = 0;
257 while ((count++ < 100) &&
258 (hasr_read(ioaddr) & HASR_PSA_BUSY)) mdelay(1);
261 wv_16_on(ioaddr, hacr);
262 } /* psa_write */
264 #ifdef SET_PSA_CRC
265 /*------------------------------------------------------------------*/
267 * Calculate the PSA CRC
268 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
269 * NOTE: By specifying a length including the CRC position the
270 * returned value should be zero. (i.e. a correct checksum in the PSA)
272 * The Windows drivers don't use the CRC, but the AP and the PtP tool
273 * depend on it.
275 static inline u16 psa_crc(u8 * psa, /* The PSA */
276 int size)
277 { /* Number of short for CRC */
278 int byte_cnt; /* Loop on the PSA */
279 u16 crc_bytes = 0; /* Data in the PSA */
280 int bit_cnt; /* Loop on the bits of the short */
282 for (byte_cnt = 0; byte_cnt < size; byte_cnt++) {
283 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
285 for (bit_cnt = 1; bit_cnt < 9; bit_cnt++) {
286 if (crc_bytes & 0x0001)
287 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
288 else
289 crc_bytes >>= 1;
293 return crc_bytes;
294 } /* psa_crc */
295 #endif /* SET_PSA_CRC */
297 /*------------------------------------------------------------------*/
299 * update the checksum field in the Wavelan's PSA
301 static void update_psa_checksum(device * dev, unsigned long ioaddr, u16 hacr)
303 #ifdef SET_PSA_CRC
304 psa_t psa;
305 u16 crc;
307 /* read the parameter storage area */
308 psa_read(ioaddr, hacr, 0, (unsigned char *) &psa, sizeof(psa));
310 /* update the checksum */
311 crc = psa_crc((unsigned char *) &psa,
312 sizeof(psa) - sizeof(psa.psa_crc[0]) -
313 sizeof(psa.psa_crc[1])
314 - sizeof(psa.psa_crc_status));
316 psa.psa_crc[0] = crc & 0xFF;
317 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
319 /* Write it ! */
320 psa_write(ioaddr, hacr, (char *) &psa.psa_crc - (char *) &psa,
321 (unsigned char *) &psa.psa_crc, 2);
323 #ifdef DEBUG_IOCTL_INFO
324 printk(KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
325 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
327 /* Check again (luxury !) */
328 crc = psa_crc((unsigned char *) &psa,
329 sizeof(psa) - sizeof(psa.psa_crc_status));
331 if (crc != 0)
332 printk(KERN_WARNING
333 "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n",
334 dev->name);
335 #endif /* DEBUG_IOCTL_INFO */
336 #endif /* SET_PSA_CRC */
337 } /* update_psa_checksum */
339 /*------------------------------------------------------------------*/
341 * Write 1 byte to the MMC.
343 static inline void mmc_out(unsigned long ioaddr, u16 o, u8 d)
345 /* Wait for MMC to go idle */
346 while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
348 outw((u16) (((u16) d << 8) | (o << 1) | 1), MMCR(ioaddr));
351 /*------------------------------------------------------------------*/
353 * Routine to write bytes to the Modem Management Controller.
354 * We start at the end because it is the way it should be!
356 static inline void mmc_write(unsigned long ioaddr, u8 o, u8 * b, int n)
358 o += n;
359 b += n;
361 while (n-- > 0)
362 mmc_out(ioaddr, --o, *(--b));
363 } /* mmc_write */
365 /*------------------------------------------------------------------*/
367 * Read a byte from the MMC.
368 * Optimised version for 1 byte, avoid using memory.
370 static inline u8 mmc_in(unsigned long ioaddr, u16 o)
372 while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
373 outw(o << 1, MMCR(ioaddr));
375 while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
376 return (u8) (inw(MMCR(ioaddr)) >> 8);
379 /*------------------------------------------------------------------*/
381 * Routine to read bytes from the Modem Management Controller.
382 * The implementation is complicated by a lack of address lines,
383 * which prevents decoding of the low-order bit.
384 * (code has just been moved in the above function)
385 * We start at the end because it is the way it should be!
387 static inline void mmc_read(unsigned long ioaddr, u8 o, u8 * b, int n)
389 o += n;
390 b += n;
392 while (n-- > 0)
393 *(--b) = mmc_in(ioaddr, --o);
394 } /* mmc_read */
396 /*------------------------------------------------------------------*/
398 * Get the type of encryption available.
400 static inline int mmc_encr(unsigned long ioaddr)
401 { /* I/O port of the card */
402 int temp;
404 temp = mmc_in(ioaddr, mmroff(0, mmr_des_avail));
405 if ((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
406 return 0;
407 else
408 return temp;
411 /*------------------------------------------------------------------*/
413 * Wait for the frequency EEPROM to complete a command.
414 * I hope this one will be optimally inlined.
416 static inline void fee_wait(unsigned long ioaddr, /* I/O port of the card */
417 int delay, /* Base delay to wait for */
418 int number)
419 { /* Number of time to wait */
420 int count = 0; /* Wait only a limited time */
422 while ((count++ < number) &&
423 (mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
424 MMR_FEE_STATUS_BUSY)) udelay(delay);
427 /*------------------------------------------------------------------*/
429 * Read bytes from the Frequency EEPROM (frequency select cards).
431 static void fee_read(unsigned long ioaddr, /* I/O port of the card */
432 u16 o, /* destination offset */
433 u16 * b, /* data buffer */
434 int n)
435 { /* number of registers */
436 b += n; /* Position at the end of the area */
438 /* Write the address */
439 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
441 /* Loop on all buffer */
442 while (n-- > 0) {
443 /* Write the read command */
444 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
445 MMW_FEE_CTRL_READ);
447 /* Wait until EEPROM is ready (should be quick). */
448 fee_wait(ioaddr, 10, 100);
450 /* Read the value. */
451 *--b = ((mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)) << 8) |
452 mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
456 #ifdef WIRELESS_EXT /* if the wireless extension exists in the kernel */
458 /*------------------------------------------------------------------*/
460 * Write bytes from the Frequency EEPROM (frequency select cards).
461 * This is a bit complicated, because the frequency EEPROM has to
462 * be unprotected and the write enabled.
463 * Jean II
465 static void fee_write(unsigned long ioaddr, /* I/O port of the card */
466 u16 o, /* destination offset */
467 u16 * b, /* data buffer */
468 int n)
469 { /* number of registers */
470 b += n; /* Position at the end of the area. */
472 #ifdef EEPROM_IS_PROTECTED /* disabled */
473 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
474 /* Ask to read the protected register */
475 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
477 fee_wait(ioaddr, 10, 100);
479 /* Read the protected register. */
480 printk("Protected 2: %02X-%02X\n",
481 mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)),
482 mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
483 #endif /* DOESNT_SEEM_TO_WORK */
485 /* Enable protected register. */
486 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
487 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
489 fee_wait(ioaddr, 10, 100);
491 /* Unprotect area. */
492 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n);
493 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
494 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
495 /* or use: */
496 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
497 #endif /* DOESNT_SEEM_TO_WORK */
499 fee_wait(ioaddr, 10, 100);
500 #endif /* EEPROM_IS_PROTECTED */
502 /* Write enable. */
503 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
504 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
506 fee_wait(ioaddr, 10, 100);
508 /* Write the EEPROM address. */
509 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
511 /* Loop on all buffer */
512 while (n-- > 0) {
513 /* Write the value. */
514 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
515 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
517 /* Write the write command. */
518 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
519 MMW_FEE_CTRL_WRITE);
521 /* WaveLAN documentation says to wait at least 10 ms for EEBUSY = 0 */
522 mdelay(10);
523 fee_wait(ioaddr, 10, 100);
526 /* Write disable. */
527 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
528 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
530 fee_wait(ioaddr, 10, 100);
532 #ifdef EEPROM_IS_PROTECTED /* disabled */
533 /* Reprotect EEPROM. */
534 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x00);
535 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
537 fee_wait(ioaddr, 10, 100);
538 #endif /* EEPROM_IS_PROTECTED */
540 #endif /* WIRELESS_EXT */
542 /************************ I82586 SUBROUTINES *************************/
544 * Useful subroutines to manage the Ethernet controller
547 /*------------------------------------------------------------------*/
549 * Read bytes from the on-board RAM.
550 * Why does inlining this function make it fail?
552 static /*inline */ void obram_read(unsigned long ioaddr,
553 u16 o, u8 * b, int n)
555 outw(o, PIOR1(ioaddr));
556 insw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
559 /*------------------------------------------------------------------*/
561 * Write bytes to the on-board RAM.
563 static inline void obram_write(unsigned long ioaddr, u16 o, u8 * b, int n)
565 outw(o, PIOR1(ioaddr));
566 outsw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
569 /*------------------------------------------------------------------*/
571 * Acknowledge the reading of the status issued by the i82586.
573 static void wv_ack(device * dev)
575 net_local *lp = (net_local *) dev->priv;
576 unsigned long ioaddr = dev->base_addr;
577 u16 scb_cs;
578 int i;
580 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
581 (unsigned char *) &scb_cs, sizeof(scb_cs));
582 scb_cs &= SCB_ST_INT;
584 if (scb_cs == 0)
585 return;
587 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
588 (unsigned char *) &scb_cs, sizeof(scb_cs));
590 set_chan_attn(ioaddr, lp->hacr);
592 for (i = 1000; i > 0; i--) {
593 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
594 (unsigned char *) &scb_cs, sizeof(scb_cs));
595 if (scb_cs == 0)
596 break;
598 udelay(10);
600 udelay(100);
602 #ifdef DEBUG_CONFIG_ERROR
603 if (i <= 0)
604 printk(KERN_INFO
605 "%s: wv_ack(): board not accepting command.\n",
606 dev->name);
607 #endif
610 /*------------------------------------------------------------------*/
612 * Set channel attention bit and busy wait until command has
613 * completed, then acknowledge completion of the command.
615 static inline int wv_synchronous_cmd(device * dev, const char *str)
617 net_local *lp = (net_local *) dev->priv;
618 unsigned long ioaddr = dev->base_addr;
619 u16 scb_cmd;
620 ach_t cb;
621 int i;
623 scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO;
624 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
625 (unsigned char *) &scb_cmd, sizeof(scb_cmd));
627 set_chan_attn(ioaddr, lp->hacr);
629 for (i = 1000; i > 0; i--) {
630 obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb,
631 sizeof(cb));
632 if (cb.ac_status & AC_SFLD_C)
633 break;
635 udelay(10);
637 udelay(100);
639 if (i <= 0 || !(cb.ac_status & AC_SFLD_OK)) {
640 #ifdef DEBUG_CONFIG_ERROR
641 printk(KERN_INFO "%s: %s failed; status = 0x%x\n",
642 dev->name, str, cb.ac_status);
643 #endif
644 #ifdef DEBUG_I82586_SHOW
645 wv_scb_show(ioaddr);
646 #endif
647 return -1;
650 /* Ack the status */
651 wv_ack(dev);
653 return 0;
656 /*------------------------------------------------------------------*/
658 * Configuration commands completion interrupt.
659 * Check if done, and if OK.
661 static inline int
662 wv_config_complete(device * dev, unsigned long ioaddr, net_local * lp)
664 unsigned short mcs_addr;
665 unsigned short status;
666 int ret;
668 #ifdef DEBUG_INTERRUPT_TRACE
669 printk(KERN_DEBUG "%s: ->wv_config_complete()\n", dev->name);
670 #endif
672 mcs_addr = lp->tx_first_in_use + sizeof(ac_tx_t) + sizeof(ac_nop_t)
673 + sizeof(tbd_t) + sizeof(ac_cfg_t) + sizeof(ac_ias_t);
675 /* Read the status of the last command (set mc list). */
676 obram_read(ioaddr, acoff(mcs_addr, ac_status),
677 (unsigned char *) &status, sizeof(status));
679 /* If not completed -> exit */
680 if ((status & AC_SFLD_C) == 0)
681 ret = 0; /* Not ready to be scrapped */
682 else {
683 #ifdef DEBUG_CONFIG_ERROR
684 unsigned short cfg_addr;
685 unsigned short ias_addr;
687 /* Check mc_config command */
688 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
689 printk(KERN_INFO
690 "%s: wv_config_complete(): set_multicast_address failed; status = 0x%x\n",
691 dev->name, status);
693 /* check ia-config command */
694 ias_addr = mcs_addr - sizeof(ac_ias_t);
695 obram_read(ioaddr, acoff(ias_addr, ac_status),
696 (unsigned char *) &status, sizeof(status));
697 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
698 printk(KERN_INFO
699 "%s: wv_config_complete(): set_MAC_address failed; status = 0x%x\n",
700 dev->name, status);
702 /* Check config command. */
703 cfg_addr = ias_addr - sizeof(ac_cfg_t);
704 obram_read(ioaddr, acoff(cfg_addr, ac_status),
705 (unsigned char *) &status, sizeof(status));
706 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
707 printk(KERN_INFO
708 "%s: wv_config_complete(): configure failed; status = 0x%x\n",
709 dev->name, status);
710 #endif /* DEBUG_CONFIG_ERROR */
712 ret = 1; /* Ready to be scrapped */
715 #ifdef DEBUG_INTERRUPT_TRACE
716 printk(KERN_DEBUG "%s: <-wv_config_complete() - %d\n", dev->name,
717 ret);
718 #endif
719 return ret;
722 /*------------------------------------------------------------------*/
724 * Command completion interrupt.
725 * Reclaim as many freed tx buffers as we can.
726 * (called in wavelan_interrupt()).
727 * Note : the spinlock is already grabbed for us.
729 static int wv_complete(device * dev, unsigned long ioaddr, net_local * lp)
731 int nreaped = 0;
733 #ifdef DEBUG_INTERRUPT_TRACE
734 printk(KERN_DEBUG "%s: ->wv_complete()\n", dev->name);
735 #endif
737 /* Loop on all the transmit buffers */
738 while (lp->tx_first_in_use != I82586NULL) {
739 unsigned short tx_status;
741 /* Read the first transmit buffer */
742 obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status),
743 (unsigned char *) &tx_status,
744 sizeof(tx_status));
746 /* If not completed -> exit */
747 if ((tx_status & AC_SFLD_C) == 0)
748 break;
750 /* Hack for reconfiguration */
751 if (tx_status == 0xFFFF)
752 if (!wv_config_complete(dev, ioaddr, lp))
753 break; /* Not completed */
755 /* We now remove this buffer */
756 nreaped++;
757 --lp->tx_n_in_use;
760 if (lp->tx_n_in_use > 0)
761 printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
764 /* Was it the last one? */
765 if (lp->tx_n_in_use <= 0)
766 lp->tx_first_in_use = I82586NULL;
767 else {
768 /* Next one in the chain */
769 lp->tx_first_in_use += TXBLOCKZ;
770 if (lp->tx_first_in_use >=
771 OFFSET_CU +
772 NTXBLOCKS * TXBLOCKZ) lp->tx_first_in_use -=
773 NTXBLOCKS * TXBLOCKZ;
776 /* Hack for reconfiguration */
777 if (tx_status == 0xFFFF)
778 continue;
780 /* Now, check status of the finished command */
781 if (tx_status & AC_SFLD_OK) {
782 int ncollisions;
784 lp->stats.tx_packets++;
785 ncollisions = tx_status & AC_SFLD_MAXCOL;
786 lp->stats.collisions += ncollisions;
787 #ifdef DEBUG_TX_INFO
788 if (ncollisions > 0)
789 printk(KERN_DEBUG
790 "%s: wv_complete(): tx completed after %d collisions.\n",
791 dev->name, ncollisions);
792 #endif
793 } else {
794 lp->stats.tx_errors++;
795 if (tx_status & AC_SFLD_S10) {
796 lp->stats.tx_carrier_errors++;
797 #ifdef DEBUG_TX_FAIL
798 printk(KERN_DEBUG
799 "%s: wv_complete(): tx error: no CS.\n",
800 dev->name);
801 #endif
803 if (tx_status & AC_SFLD_S9) {
804 lp->stats.tx_carrier_errors++;
805 #ifdef DEBUG_TX_FAIL
806 printk(KERN_DEBUG
807 "%s: wv_complete(): tx error: lost CTS.\n",
808 dev->name);
809 #endif
811 if (tx_status & AC_SFLD_S8) {
812 lp->stats.tx_fifo_errors++;
813 #ifdef DEBUG_TX_FAIL
814 printk(KERN_DEBUG
815 "%s: wv_complete(): tx error: slow DMA.\n",
816 dev->name);
817 #endif
819 if (tx_status & AC_SFLD_S6) {
820 lp->stats.tx_heartbeat_errors++;
821 #ifdef DEBUG_TX_FAIL
822 printk(KERN_DEBUG
823 "%s: wv_complete(): tx error: heart beat.\n",
824 dev->name);
825 #endif
827 if (tx_status & AC_SFLD_S5) {
828 lp->stats.tx_aborted_errors++;
829 #ifdef DEBUG_TX_FAIL
830 printk(KERN_DEBUG
831 "%s: wv_complete(): tx error: too many collisions.\n",
832 dev->name);
833 #endif
837 #ifdef DEBUG_TX_INFO
838 printk(KERN_DEBUG
839 "%s: wv_complete(): tx completed, tx_status 0x%04x\n",
840 dev->name, tx_status);
841 #endif
844 #ifdef DEBUG_INTERRUPT_INFO
845 if (nreaped > 1)
846 printk(KERN_DEBUG "%s: wv_complete(): reaped %d\n",
847 dev->name, nreaped);
848 #endif
851 * Inform upper layers.
853 if (lp->tx_n_in_use < NTXBLOCKS - 1) {
854 netif_wake_queue(dev);
856 #ifdef DEBUG_INTERRUPT_TRACE
857 printk(KERN_DEBUG "%s: <-wv_complete()\n", dev->name);
858 #endif
859 return nreaped;
862 /*------------------------------------------------------------------*/
864 * Reconfigure the i82586, or at least ask for it.
865 * Because wv_82586_config uses a transmission buffer, we must do it
866 * when we are sure that there is one left, so we do it now
867 * or in wavelan_packet_xmit() (I can't find any better place,
868 * wavelan_interrupt is not an option), so you may experience
869 * delays sometimes.
871 static inline void wv_82586_reconfig(device * dev)
873 net_local *lp = (net_local *) dev->priv;
875 /* Arm the flag, will be cleard in wv_82586_config() */
876 lp->reconfig_82586 = 1;
878 /* Check if we can do it now ! */
879 if((netif_running(dev)) && !(netif_queue_stopped(dev)))
880 /* May fail */
881 wv_82586_config(dev);
882 else {
883 #ifdef DEBUG_CONFIG_INFO
884 printk(KERN_DEBUG
885 "%s: wv_82586_reconfig(): delayed (state = %lX)\n",
886 dev->name, dev->state);
887 #endif
891 /********************* DEBUG & INFO SUBROUTINES *********************/
893 * This routine is used in the code to show information for debugging.
894 * Most of the time, it dumps the contents of hardware structures.
897 #ifdef DEBUG_PSA_SHOW
898 /*------------------------------------------------------------------*/
900 * Print the formatted contents of the Parameter Storage Area.
902 static void wv_psa_show(psa_t * p)
904 printk(KERN_DEBUG "##### WaveLAN PSA contents: #####\n");
905 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
906 p->psa_io_base_addr_1,
907 p->psa_io_base_addr_2,
908 p->psa_io_base_addr_3, p->psa_io_base_addr_4);
909 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
910 p->psa_rem_boot_addr_1,
911 p->psa_rem_boot_addr_2, p->psa_rem_boot_addr_3);
912 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
913 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
914 #ifdef DEBUG_SHOW_UNUSED
915 printk(KERN_DEBUG
916 "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
917 p->psa_unused0[0], p->psa_unused0[1], p->psa_unused0[2],
918 p->psa_unused0[3], p->psa_unused0[4], p->psa_unused0[5],
919 p->psa_unused0[6]);
920 #endif /* DEBUG_SHOW_UNUSED */
921 printk(KERN_DEBUG
922 "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
923 p->psa_univ_mac_addr[0], p->psa_univ_mac_addr[1],
924 p->psa_univ_mac_addr[2], p->psa_univ_mac_addr[3],
925 p->psa_univ_mac_addr[4], p->psa_univ_mac_addr[5]);
926 printk(KERN_DEBUG
927 "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
928 p->psa_local_mac_addr[0], p->psa_local_mac_addr[1],
929 p->psa_local_mac_addr[2], p->psa_local_mac_addr[3],
930 p->psa_local_mac_addr[4], p->psa_local_mac_addr[5]);
931 printk(KERN_DEBUG "psa_univ_local_sel: %d, ",
932 p->psa_univ_local_sel);
933 printk("psa_comp_number: %d, ", p->psa_comp_number);
934 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
935 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
936 p->psa_feature_select);
937 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
938 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
939 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
940 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0],
941 p->psa_nwid[1]);
942 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
943 printk(KERN_DEBUG "psa_encryption_select: %d, ",
944 p->psa_encryption_select);
945 printk
946 ("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
947 p->psa_encryption_key[0], p->psa_encryption_key[1],
948 p->psa_encryption_key[2], p->psa_encryption_key[3],
949 p->psa_encryption_key[4], p->psa_encryption_key[5],
950 p->psa_encryption_key[6], p->psa_encryption_key[7]);
951 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
952 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
953 p->psa_call_code[0]);
954 printk
955 ("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
956 p->psa_call_code[0], p->psa_call_code[1], p->psa_call_code[2],
957 p->psa_call_code[3], p->psa_call_code[4], p->psa_call_code[5],
958 p->psa_call_code[6], p->psa_call_code[7]);
959 #ifdef DEBUG_SHOW_UNUSED
960 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
961 p->psa_reserved[0],
962 p->psa_reserved[1], p->psa_reserved[2], p->psa_reserved[3]);
963 #endif /* DEBUG_SHOW_UNUSED */
964 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
965 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
966 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
967 } /* wv_psa_show */
968 #endif /* DEBUG_PSA_SHOW */
970 #ifdef DEBUG_MMC_SHOW
971 /*------------------------------------------------------------------*/
973 * Print the formatted status of the Modem Management Controller.
974 * This function needs to be completed.
976 static void wv_mmc_show(device * dev)
978 unsigned long ioaddr = dev->base_addr;
979 net_local *lp = (net_local *) dev->priv;
980 mmr_t m;
982 /* Basic check */
983 if (hasr_read(ioaddr) & HASR_NO_CLK) {
984 printk(KERN_WARNING
985 "%s: wv_mmc_show: modem not connected\n",
986 dev->name);
987 return;
990 /* Read the mmc */
991 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
992 mmc_read(ioaddr, 0, (u8 *) & m, sizeof(m));
993 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
995 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
996 /* Don't forget to update statistics */
997 lp->wstats.discard.nwid +=
998 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
999 #endif /* WIRELESS_EXT */
1001 printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n");
1002 #ifdef DEBUG_SHOW_UNUSED
1003 printk(KERN_DEBUG
1004 "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1005 m.mmr_unused0[0], m.mmr_unused0[1], m.mmr_unused0[2],
1006 m.mmr_unused0[3], m.mmr_unused0[4], m.mmr_unused0[5],
1007 m.mmr_unused0[6], m.mmr_unused0[7]);
1008 #endif /* DEBUG_SHOW_UNUSED */
1009 printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
1010 m.mmr_des_avail, m.mmr_des_status);
1011 #ifdef DEBUG_SHOW_UNUSED
1012 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1013 m.mmr_unused1[0],
1014 m.mmr_unused1[1],
1015 m.mmr_unused1[2], m.mmr_unused1[3], m.mmr_unused1[4]);
1016 #endif /* DEBUG_SHOW_UNUSED */
1017 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1018 m.mmr_dce_status,
1020 mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ?
1021 "energy detected," : "",
1023 mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1024 "loop test indicated," : "",
1026 mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ?
1027 "transmitter on," : "",
1029 mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1030 "jabber timer expired," : "");
1031 printk(KERN_DEBUG "Dsp ID: %02X\n", m.mmr_dsp_id);
1032 #ifdef DEBUG_SHOW_UNUSED
1033 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1034 m.mmr_unused2[0], m.mmr_unused2[1]);
1035 #endif /* DEBUG_SHOW_UNUSED */
1036 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1037 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1038 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1039 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1040 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1042 mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" :
1043 "below");
1044 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1045 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1047 mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" :
1048 "no new msg");
1049 printk("silence_lvl: %d [%s], ",
1050 m.mmr_silence_lvl & MMR_SILENCE_LVL,
1052 mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" :
1053 "no new update");
1054 printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1056 mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" :
1057 "Antenna 0");
1058 #ifdef DEBUG_SHOW_UNUSED
1059 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1060 #endif /* DEBUG_SHOW_UNUSED */
1061 } /* wv_mmc_show */
1062 #endif /* DEBUG_MMC_SHOW */
1064 #ifdef DEBUG_I82586_SHOW
1065 /*------------------------------------------------------------------*/
1067 * Print the last block of the i82586 memory.
1069 static void wv_scb_show(unsigned long ioaddr)
1071 scb_t scb;
1073 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
1074 sizeof(scb));
1076 printk(KERN_DEBUG "##### WaveLAN system control block: #####\n");
1078 printk(KERN_DEBUG "status: ");
1079 printk("stat 0x%x[%s%s%s%s] ",
1080 (scb.
1081 scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA |
1082 SCB_ST_RNR)) >> 12,
1083 (scb.
1084 scb_status & SCB_ST_CX) ? "command completion interrupt," :
1085 "", (scb.scb_status & SCB_ST_FR) ? "frame received," : "",
1086 (scb.
1087 scb_status & SCB_ST_CNA) ? "command unit not active," : "",
1088 (scb.
1089 scb_status & SCB_ST_RNR) ? "receiving unit not ready," :
1090 "");
1091 printk("cus 0x%x[%s%s%s] ", (scb.scb_status & SCB_ST_CUS) >> 8,
1092 ((scb.scb_status & SCB_ST_CUS) ==
1093 SCB_ST_CUS_IDLE) ? "idle" : "",
1094 ((scb.scb_status & SCB_ST_CUS) ==
1095 SCB_ST_CUS_SUSP) ? "suspended" : "",
1096 ((scb.scb_status & SCB_ST_CUS) ==
1097 SCB_ST_CUS_ACTV) ? "active" : "");
1098 printk("rus 0x%x[%s%s%s%s]\n", (scb.scb_status & SCB_ST_RUS) >> 4,
1099 ((scb.scb_status & SCB_ST_RUS) ==
1100 SCB_ST_RUS_IDLE) ? "idle" : "",
1101 ((scb.scb_status & SCB_ST_RUS) ==
1102 SCB_ST_RUS_SUSP) ? "suspended" : "",
1103 ((scb.scb_status & SCB_ST_RUS) ==
1104 SCB_ST_RUS_NRES) ? "no resources" : "",
1105 ((scb.scb_status & SCB_ST_RUS) ==
1106 SCB_ST_RUS_RDY) ? "ready" : "");
1108 printk(KERN_DEBUG "command: ");
1109 printk("ack 0x%x[%s%s%s%s] ",
1110 (scb.
1111 scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR |
1112 SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12,
1113 (scb.
1114 scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "",
1115 (scb.
1116 scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "",
1117 (scb.
1118 scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "",
1119 (scb.
1120 scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : "");
1121 printk("cuc 0x%x[%s%s%s%s%s] ",
1122 (scb.scb_command & SCB_CMD_CUC) >> 8,
1123 ((scb.scb_command & SCB_CMD_CUC) ==
1124 SCB_CMD_CUC_NOP) ? "nop" : "",
1125 ((scb.scb_command & SCB_CMD_CUC) ==
1126 SCB_CMD_CUC_GO) ? "start cbl_offset" : "",
1127 ((scb.scb_command & SCB_CMD_CUC) ==
1128 SCB_CMD_CUC_RES) ? "resume execution" : "",
1129 ((scb.scb_command & SCB_CMD_CUC) ==
1130 SCB_CMD_CUC_SUS) ? "suspend execution" : "",
1131 ((scb.scb_command & SCB_CMD_CUC) ==
1132 SCB_CMD_CUC_ABT) ? "abort execution" : "");
1133 printk("ruc 0x%x[%s%s%s%s%s]\n",
1134 (scb.scb_command & SCB_CMD_RUC) >> 4,
1135 ((scb.scb_command & SCB_CMD_RUC) ==
1136 SCB_CMD_RUC_NOP) ? "nop" : "",
1137 ((scb.scb_command & SCB_CMD_RUC) ==
1138 SCB_CMD_RUC_GO) ? "start rfa_offset" : "",
1139 ((scb.scb_command & SCB_CMD_RUC) ==
1140 SCB_CMD_RUC_RES) ? "resume reception" : "",
1141 ((scb.scb_command & SCB_CMD_RUC) ==
1142 SCB_CMD_RUC_SUS) ? "suspend reception" : "",
1143 ((scb.scb_command & SCB_CMD_RUC) ==
1144 SCB_CMD_RUC_ABT) ? "abort reception" : "");
1146 printk(KERN_DEBUG "cbl_offset 0x%x ", scb.scb_cbl_offset);
1147 printk("rfa_offset 0x%x\n", scb.scb_rfa_offset);
1149 printk(KERN_DEBUG "crcerrs %d ", scb.scb_crcerrs);
1150 printk("alnerrs %d ", scb.scb_alnerrs);
1151 printk("rscerrs %d ", scb.scb_rscerrs);
1152 printk("ovrnerrs %d\n", scb.scb_ovrnerrs);
1155 /*------------------------------------------------------------------*/
1157 * Print the formatted status of the i82586's receive unit.
1159 static void wv_ru_show(device * dev)
1161 /* net_local *lp = (net_local *) dev->priv; */
1163 printk(KERN_DEBUG
1164 "##### WaveLAN i82586 receiver unit status: #####\n");
1165 printk(KERN_DEBUG "ru:");
1167 * Not implemented yet
1169 printk("\n");
1170 } /* wv_ru_show */
1172 /*------------------------------------------------------------------*/
1174 * Display info about one control block of the i82586 memory.
1176 static void wv_cu_show_one(device * dev, net_local * lp, int i, u16 p)
1178 unsigned long ioaddr;
1179 ac_tx_t actx;
1181 ioaddr = dev->base_addr;
1183 printk("%d: 0x%x:", i, p);
1185 obram_read(ioaddr, p, (unsigned char *) &actx, sizeof(actx));
1186 printk(" status=0x%x,", actx.tx_h.ac_status);
1187 printk(" command=0x%x,", actx.tx_h.ac_command);
1191 tbd_t tbd;
1193 obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
1194 printk(" tbd_status=0x%x,", tbd.tbd_status);
1198 printk("|");
1201 /*------------------------------------------------------------------*/
1203 * Print status of the command unit of the i82586.
1205 static void wv_cu_show(device * dev)
1207 net_local *lp = (net_local *) dev->priv;
1208 unsigned int i;
1209 u16 p;
1211 printk(KERN_DEBUG
1212 "##### WaveLAN i82586 command unit status: #####\n");
1214 printk(KERN_DEBUG);
1215 for (i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++) {
1216 wv_cu_show_one(dev, lp, i, p);
1218 p += TXBLOCKZ;
1219 if (p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
1220 p -= NTXBLOCKS * TXBLOCKZ;
1222 printk("\n");
1224 #endif /* DEBUG_I82586_SHOW */
1226 #ifdef DEBUG_DEVICE_SHOW
1227 /*------------------------------------------------------------------*/
1229 * Print the formatted status of the WaveLAN PCMCIA device driver.
1231 static void wv_dev_show(device * dev)
1233 printk(KERN_DEBUG "dev:");
1234 printk(" state=%lX,", dev->state);
1235 printk(" trans_start=%ld,", dev->trans_start);
1236 printk(" flags=0x%x,", dev->flags);
1237 printk("\n");
1238 } /* wv_dev_show */
1240 /*------------------------------------------------------------------*/
1242 * Print the formatted status of the WaveLAN PCMCIA device driver's
1243 * private information.
1245 static void wv_local_show(device * dev)
1247 net_local *lp;
1249 lp = (net_local *) dev->priv;
1251 printk(KERN_DEBUG "local:");
1252 printk(" tx_n_in_use=%d,", lp->tx_n_in_use);
1253 printk(" hacr=0x%x,", lp->hacr);
1254 printk(" rx_head=0x%x,", lp->rx_head);
1255 printk(" rx_last=0x%x,", lp->rx_last);
1256 printk(" tx_first_free=0x%x,", lp->tx_first_free);
1257 printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use);
1258 printk("\n");
1259 } /* wv_local_show */
1260 #endif /* DEBUG_DEVICE_SHOW */
1262 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1263 /*------------------------------------------------------------------*/
1265 * Dump packet header (and content if necessary) on the screen
1267 static inline void wv_packet_info(u8 * p, /* Packet to dump */
1268 int length, /* Length of the packet */
1269 char *msg1, /* Name of the device */
1270 char *msg2)
1271 { /* Name of the function */
1272 int i;
1273 int maxi;
1275 printk(KERN_DEBUG
1276 "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1277 msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1278 printk(KERN_DEBUG
1279 "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1280 msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12],
1281 p[13]);
1283 #ifdef DEBUG_PACKET_DUMP
1285 printk(KERN_DEBUG "data=\"");
1287 if ((maxi = length) > DEBUG_PACKET_DUMP)
1288 maxi = DEBUG_PACKET_DUMP;
1289 for (i = 14; i < maxi; i++)
1290 if (p[i] >= ' ' && p[i] <= '~')
1291 printk(" %c", p[i]);
1292 else
1293 printk("%02X", p[i]);
1294 if (maxi < length)
1295 printk("..");
1296 printk("\"\n");
1297 printk(KERN_DEBUG "\n");
1298 #endif /* DEBUG_PACKET_DUMP */
1300 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1302 /*------------------------------------------------------------------*/
1304 * This is the information which is displayed by the driver at startup.
1305 * There are lots of flags for configuring it to your liking.
1307 static inline void wv_init_info(device * dev)
1309 short ioaddr = dev->base_addr;
1310 net_local *lp = (net_local *) dev->priv;
1311 psa_t psa;
1312 int i;
1314 /* Read the parameter storage area */
1315 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
1317 #ifdef DEBUG_PSA_SHOW
1318 wv_psa_show(&psa);
1319 #endif
1320 #ifdef DEBUG_MMC_SHOW
1321 wv_mmc_show(dev);
1322 #endif
1323 #ifdef DEBUG_I82586_SHOW
1324 wv_cu_show(dev);
1325 #endif
1327 #ifdef DEBUG_BASIC_SHOW
1328 /* Now, let's go for the basic stuff. */
1329 printk(KERN_NOTICE "%s: WaveLAN at %#x,", dev->name, ioaddr);
1330 for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
1331 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1332 printk(", IRQ %d", dev->irq);
1334 /* Print current network ID. */
1335 if (psa.psa_nwid_select)
1336 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0],
1337 psa.psa_nwid[1]);
1338 else
1339 printk(", nwid off");
1341 /* If 2.00 card */
1342 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1343 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1344 unsigned short freq;
1346 /* Ask the EEPROM to read the frequency from the first area. */
1347 fee_read(ioaddr, 0x00, &freq, 1);
1349 /* Print frequency */
1350 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1352 /* Hack! */
1353 if (freq & 0x20)
1354 printk(".5");
1355 } else {
1356 printk(", PC");
1357 switch (psa.psa_comp_number) {
1358 case PSA_COMP_PC_AT_915:
1359 case PSA_COMP_PC_AT_2400:
1360 printk("-AT");
1361 break;
1362 case PSA_COMP_PC_MC_915:
1363 case PSA_COMP_PC_MC_2400:
1364 printk("-MC");
1365 break;
1366 case PSA_COMP_PCMCIA_915:
1367 printk("MCIA");
1368 break;
1369 default:
1370 printk("?");
1372 printk(", ");
1373 switch (psa.psa_subband) {
1374 case PSA_SUBBAND_915:
1375 printk("915");
1376 break;
1377 case PSA_SUBBAND_2425:
1378 printk("2425");
1379 break;
1380 case PSA_SUBBAND_2460:
1381 printk("2460");
1382 break;
1383 case PSA_SUBBAND_2484:
1384 printk("2484");
1385 break;
1386 case PSA_SUBBAND_2430_5:
1387 printk("2430.5");
1388 break;
1389 default:
1390 printk("?");
1394 printk(" MHz\n");
1395 #endif /* DEBUG_BASIC_SHOW */
1397 #ifdef DEBUG_VERSION_SHOW
1398 /* Print version information */
1399 printk(KERN_NOTICE "%s", version);
1400 #endif
1401 } /* wv_init_info */
1403 /********************* IOCTL, STATS & RECONFIG *********************/
1405 * We found here routines that are called by Linux on different
1406 * occasions after the configuration and not for transmitting data
1407 * These may be called when the user use ifconfig, /proc/net/dev
1408 * or wireless extensions
1411 /*------------------------------------------------------------------*/
1413 * Get the current Ethernet statistics. This may be called with the
1414 * card open or closed.
1415 * Used when the user read /proc/net/dev
1417 static en_stats *wavelan_get_stats(device * dev)
1419 #ifdef DEBUG_IOCTL_TRACE
1420 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1421 #endif
1423 return (&((net_local *) dev->priv)->stats);
1426 /*------------------------------------------------------------------*/
1428 * Set or clear the multicast filter for this adaptor.
1429 * num_addrs == -1 Promiscuous mode, receive all packets
1430 * num_addrs == 0 Normal mode, clear multicast list
1431 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1432 * and do best-effort filtering.
1434 static void wavelan_set_multicast_list(device * dev)
1436 net_local *lp = (net_local *) dev->priv;
1438 #ifdef DEBUG_IOCTL_TRACE
1439 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n",
1440 dev->name);
1441 #endif
1443 #ifdef DEBUG_IOCTL_INFO
1444 printk(KERN_DEBUG
1445 "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1446 dev->name, dev->flags, dev->mc_count);
1447 #endif
1449 /* Are we asking for promiscuous mode,
1450 * or all multicast addresses (we don't have that!)
1451 * or too many multicast addresses for the hardware filter? */
1452 if ((dev->flags & IFF_PROMISC) ||
1453 (dev->flags & IFF_ALLMULTI) ||
1454 (dev->mc_count > I82586_MAX_MULTICAST_ADDRESSES)) {
1456 * Enable promiscuous mode: receive all packets.
1458 if (!lp->promiscuous) {
1459 lp->promiscuous = 1;
1460 lp->mc_count = 0;
1462 wv_82586_reconfig(dev);
1464 /* Tell the kernel that we are doing a really bad job. */
1465 dev->flags |= IFF_PROMISC;
1467 } else
1468 /* Are there multicast addresses to send? */
1469 if (dev->mc_list != (struct dev_mc_list *) NULL) {
1471 * Disable promiscuous mode, but receive all packets
1472 * in multicast list
1474 #ifdef MULTICAST_AVOID
1475 if (lp->promiscuous || (dev->mc_count != lp->mc_count))
1476 #endif
1478 lp->promiscuous = 0;
1479 lp->mc_count = dev->mc_count;
1481 wv_82586_reconfig(dev);
1483 } else {
1485 * Switch to normal mode: disable promiscuous mode and
1486 * clear the multicast list.
1488 if (lp->promiscuous || lp->mc_count == 0) {
1489 lp->promiscuous = 0;
1490 lp->mc_count = 0;
1492 wv_82586_reconfig(dev);
1495 #ifdef DEBUG_IOCTL_TRACE
1496 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n",
1497 dev->name);
1498 #endif
1501 /*------------------------------------------------------------------*/
1503 * This function doesn't exist.
1504 * (Note : it was a nice way to test the reconfigure stuff...)
1506 #ifdef SET_MAC_ADDRESS
1507 static int wavelan_set_mac_address(device * dev, void *addr)
1509 struct sockaddr *mac = addr;
1511 /* Copy the address. */
1512 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1514 /* Reconfigure the beast. */
1515 wv_82586_reconfig(dev);
1517 return 0;
1519 #endif /* SET_MAC_ADDRESS */
1521 #ifdef WIRELESS_EXT /* if wireless extensions exist in the kernel */
1523 /*------------------------------------------------------------------*/
1525 * Frequency setting (for hardware capable of it)
1526 * It's a bit complicated and you don't really want to look into it.
1527 * (called in wavelan_ioctl)
1529 static inline int wv_set_frequency(unsigned long ioaddr, /* I/O port of the card */
1530 iw_freq * frequency)
1532 const int BAND_NUM = 10; /* Number of bands */
1533 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1534 #ifdef DEBUG_IOCTL_INFO
1535 int i;
1536 #endif
1538 /* Setting by frequency */
1539 /* Theoretically, you may set any frequency between
1540 * the two limits with a 0.5 MHz precision. In practice,
1541 * I don't want you to have trouble with local regulations.
1543 if ((frequency->e == 1) &&
1544 (frequency->m >= (int) 2.412e8)
1545 && (frequency->m <= (int) 2.487e8)) {
1546 freq = ((frequency->m / 10000) - 24000L) / 5;
1549 /* Setting by channel (same as wfreqsel) */
1550 /* Warning: each channel is 22 MHz wide, so some of the channels
1551 * will interfere. */
1552 if ((frequency->e == 0) &&
1553 (frequency->m >= 0) && (frequency->m < BAND_NUM)) {
1554 /* Get frequency offset. */
1555 freq = channel_bands[frequency->m] >> 1;
1558 /* Verify that the frequency is allowed. */
1559 if (freq != 0L) {
1560 u16 table[10]; /* Authorized frequency table */
1562 /* Read the frequency table. */
1563 fee_read(ioaddr, 0x71, table, 10);
1565 #ifdef DEBUG_IOCTL_INFO
1566 printk(KERN_DEBUG "Frequency table: ");
1567 for (i = 0; i < 10; i++) {
1568 printk(" %04X", table[i]);
1570 printk("\n");
1571 #endif
1573 /* Look in the table to see whether the frequency is allowed. */
1574 if (!(table[9 - ((freq - 24) / 16)] &
1575 (1 << ((freq - 24) % 16)))) return -EINVAL; /* not allowed */
1576 } else
1577 return -EINVAL;
1579 /* if we get a usable frequency */
1580 if (freq != 0L) {
1581 unsigned short area[16];
1582 unsigned short dac[2];
1583 unsigned short area_verify[16];
1584 unsigned short dac_verify[2];
1585 /* Corresponding gain (in the power adjust value table)
1586 * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8
1587 * and WCIN062D.DOC, page 6.2.9. */
1588 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1589 int power_band = 0; /* Selected band */
1590 unsigned short power_adjust; /* Correct value */
1592 /* Search for the gain. */
1593 power_band = 0;
1594 while ((freq > power_limit[power_band]) &&
1595 (power_limit[++power_band] != 0));
1597 /* Read the first area. */
1598 fee_read(ioaddr, 0x00, area, 16);
1600 /* Read the DAC. */
1601 fee_read(ioaddr, 0x60, dac, 2);
1603 /* Read the new power adjust value. */
1604 fee_read(ioaddr, 0x6B - (power_band >> 1), &power_adjust,
1606 if (power_band & 0x1)
1607 power_adjust >>= 8;
1608 else
1609 power_adjust &= 0xFF;
1611 #ifdef DEBUG_IOCTL_INFO
1612 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1613 for (i = 0; i < 16; i++) {
1614 printk(" %04X", area[i]);
1616 printk("\n");
1618 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1619 dac[0], dac[1]);
1620 #endif
1622 /* Frequency offset (for info only) */
1623 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1625 /* Receiver Principle main divider coefficient */
1626 area[3] = (freq >> 1) + 2400L - 352L;
1627 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1629 /* Transmitter Main divider coefficient */
1630 area[13] = (freq >> 1) + 2400L;
1631 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1633 /* Other parts of the area are flags, bit streams or unused. */
1635 /* Set the value in the DAC. */
1636 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1637 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1639 /* Write the first area. */
1640 fee_write(ioaddr, 0x00, area, 16);
1642 /* Write the DAC. */
1643 fee_write(ioaddr, 0x60, dac, 2);
1645 /* We now should verify here that the writing of the EEPROM went OK. */
1647 /* Reread the first area. */
1648 fee_read(ioaddr, 0x00, area_verify, 16);
1650 /* Reread the DAC. */
1651 fee_read(ioaddr, 0x60, dac_verify, 2);
1653 /* Compare. */
1654 if (memcmp(area, area_verify, 16 * 2) ||
1655 memcmp(dac, dac_verify, 2 * 2)) {
1656 #ifdef DEBUG_IOCTL_ERROR
1657 printk(KERN_INFO
1658 "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n");
1659 #endif
1660 return -EOPNOTSUPP;
1663 /* We must download the frequency parameters to the
1664 * synthesizers (from the EEPROM - area 1)
1665 * Note: as the EEPROM is automatically decremented, we set the end
1666 * if the area... */
1667 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x0F);
1668 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1669 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1671 /* Wait until the download is finished. */
1672 fee_wait(ioaddr, 100, 100);
1674 /* We must now download the power adjust value (gain) to
1675 * the synthesizers (from the EEPROM - area 7 - DAC). */
1676 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x61);
1677 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1678 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1680 /* Wait for the download to finish. */
1681 fee_wait(ioaddr, 100, 100);
1683 #ifdef DEBUG_IOCTL_INFO
1684 /* Verification of what we have done */
1686 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1687 for (i = 0; i < 16; i++) {
1688 printk(" %04X", area_verify[i]);
1690 printk("\n");
1692 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1693 dac_verify[0], dac_verify[1]);
1694 #endif
1696 return 0;
1697 } else
1698 return -EINVAL; /* Bah, never get there... */
1701 /*------------------------------------------------------------------*/
1703 * Give the list of available frequencies.
1705 static inline int wv_frequency_list(unsigned long ioaddr, /* I/O port of the card */
1706 iw_freq * list, /* List of frequencies to fill */
1707 int max)
1708 { /* Maximum number of frequencies */
1709 u16 table[10]; /* Authorized frequency table */
1710 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1711 int i; /* index in the table */
1712 int c = 0; /* Channel number */
1714 /* Read the frequency table. */
1715 fee_read(ioaddr, 0x71 /* frequency table */ , table, 10);
1717 /* Check all frequencies. */
1718 i = 0;
1719 for (freq = 0; freq < 150; freq++)
1720 /* Look in the table if the frequency is allowed */
1721 if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
1722 /* Compute approximate channel number */
1723 while ((((channel_bands[c] >> 1) - 24) < freq) &&
1724 (c < NELS(channel_bands)))
1725 c++;
1726 list[i].i = c; /* Set the list index */
1728 /* put in the list */
1729 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1730 list[i++].e = 1;
1732 /* Check number. */
1733 if (i >= max)
1734 return (i);
1737 return (i);
1740 #ifdef WIRELESS_SPY
1741 /*------------------------------------------------------------------*/
1743 * Gather wireless spy statistics: for each packet, compare the source
1744 * address with our list, and if they match, get the statistics.
1745 * Sorry, but this function really needs the wireless extensions.
1747 static inline void wl_spy_gather(device * dev, u8 * mac, /* MAC address */
1748 u8 * stats)
1749 { /* Statistics to gather */
1750 net_local *lp = (net_local *) dev->priv;
1751 int i;
1753 /* Check all addresses. */
1754 for (i = 0; i < lp->spy_number; i++)
1755 /* If match */
1756 if (!memcmp(mac, lp->spy_address[i], WAVELAN_ADDR_SIZE)) {
1757 /* Update statistics */
1758 lp->spy_stat[i].qual = stats[2] & MMR_SGNL_QUAL;
1759 lp->spy_stat[i].level = stats[0] & MMR_SIGNAL_LVL;
1760 lp->spy_stat[i].noise = stats[1] & MMR_SILENCE_LVL;
1761 lp->spy_stat[i].updated = 0x7;
1764 #endif /* WIRELESS_SPY */
1766 #ifdef HISTOGRAM
1767 /*------------------------------------------------------------------*/
1769 * This function calculates a histogram of the signal level.
1770 * As the noise is quite constant, it's like doing it on the SNR.
1771 * We have defined a set of interval (lp->his_range), and each time
1772 * the level goes in that interval, we increment the count (lp->his_sum).
1773 * With this histogram you may detect if one WaveLAN is really weak,
1774 * or you may also calculate the mean and standard deviation of the level.
1776 static inline void wl_his_gather(device * dev, u8 * stats)
1777 { /* Statistics to gather */
1778 net_local *lp = (net_local *) dev->priv;
1779 u8 level = stats[0] & MMR_SIGNAL_LVL;
1780 int i;
1782 /* Find the correct interval. */
1783 i = 0;
1784 while ((i < (lp->his_number - 1))
1785 && (level >= lp->his_range[i++]));
1787 /* Increment interval counter. */
1788 (lp->his_sum[i])++;
1790 #endif /* HISTOGRAM */
1792 /*------------------------------------------------------------------*/
1794 * Perform ioctl for configuration and information.
1795 * It is here that the wireless extensions are treated (iwconfig).
1797 static int wavelan_ioctl(struct net_device *dev, /* device on which the ioctl is applied */
1798 struct ifreq *rq, /* data passed */
1799 int cmd)
1800 { /* ioctl number */
1801 unsigned long ioaddr = dev->base_addr;
1802 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
1803 struct iwreq *wrq = (struct iwreq *) rq;
1804 psa_t psa;
1805 mm_t m;
1806 unsigned long flags;
1807 int ret = 0;
1808 int err = 0;
1810 #ifdef DEBUG_IOCTL_TRACE
1811 printk(KERN_DEBUG "%s: ->wavelan_ioctl(cmd=0x%X)\n", dev->name,
1812 cmd);
1813 #endif
1815 /* Disable interrupts and save flags. */
1816 wv_splhi(lp, &flags);
1818 /* Look what is the request */
1819 switch (cmd) {
1820 /* --------------- WIRELESS EXTENSIONS --------------- */
1822 case SIOCGIWNAME:
1823 strcpy(wrq->u.name, "WaveLAN");
1824 break;
1826 case SIOCSIWNWID:
1827 /* Set NWID in WaveLAN. */
1828 if (!wrq->u.nwid.disabled) {
1829 /* Set NWID in psa */
1830 psa.psa_nwid[0] =
1831 (wrq->u.nwid.value & 0xFF00) >> 8;
1832 psa.psa_nwid[1] = wrq->u.nwid.value & 0xFF;
1833 psa.psa_nwid_select = 0x01;
1834 psa_write(ioaddr, lp->hacr,
1835 (char *) psa.psa_nwid - (char *) &psa,
1836 (unsigned char *) psa.psa_nwid, 3);
1838 /* Set NWID in mmc. */
1839 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1840 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1841 mmc_write(ioaddr,
1842 (char *) &m.w.mmw_netw_id_l -
1843 (char *) &m,
1844 (unsigned char *) &m.w.mmw_netw_id_l, 2);
1845 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), 0x00);
1846 } else {
1847 /* Disable NWID in the psa. */
1848 psa.psa_nwid_select = 0x00;
1849 psa_write(ioaddr, lp->hacr,
1850 (char *) &psa.psa_nwid_select -
1851 (char *) &psa,
1852 (unsigned char *) &psa.psa_nwid_select,
1855 /* Disable NWID in the mmc (no filtering). */
1856 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel),
1857 MMW_LOOPT_SEL_DIS_NWID);
1859 /* update the Wavelan checksum */
1860 update_psa_checksum(dev, ioaddr, lp->hacr);
1861 break;
1863 case SIOCGIWNWID:
1864 /* Read the NWID. */
1865 psa_read(ioaddr, lp->hacr,
1866 (char *) psa.psa_nwid - (char *) &psa,
1867 (unsigned char *) psa.psa_nwid, 3);
1868 wrq->u.nwid.value =
1869 (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1870 wrq->u.nwid.disabled = !(psa.psa_nwid_select);
1871 wrq->u.nwid.fixed = 1; /* Superfluous */
1872 break;
1874 case SIOCSIWFREQ:
1875 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1876 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1877 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1878 ret = wv_set_frequency(ioaddr, &(wrq->u.freq));
1879 else
1880 ret = -EOPNOTSUPP;
1881 break;
1883 case SIOCGIWFREQ:
1884 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
1885 * Does it work for everybody, especially old cards? */
1886 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1887 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1888 unsigned short freq;
1890 /* Ask the EEPROM to read the frequency from the first area. */
1891 fee_read(ioaddr, 0x00, &freq, 1);
1892 wrq->u.freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
1893 wrq->u.freq.e = 1;
1894 } else {
1895 psa_read(ioaddr, lp->hacr,
1896 (char *) &psa.psa_subband - (char *) &psa,
1897 (unsigned char *) &psa.psa_subband, 1);
1899 if (psa.psa_subband <= 4) {
1900 wrq->u.freq.m =
1901 fixed_bands[psa.psa_subband];
1902 wrq->u.freq.e = (psa.psa_subband != 0);
1903 } else
1904 ret = -EOPNOTSUPP;
1906 break;
1908 case SIOCSIWSENS:
1909 /* Set the level threshold. */
1910 /* We should complain loudly if wrq->u.sens.fixed = 0, because we
1911 * can't set auto mode... */
1912 psa.psa_thr_pre_set = wrq->u.sens.value & 0x3F;
1913 psa_write(ioaddr, lp->hacr,
1914 (char *) &psa.psa_thr_pre_set - (char *) &psa,
1915 (unsigned char *) &psa.psa_thr_pre_set, 1);
1916 /* update the Wavelan checksum */
1917 update_psa_checksum(dev, ioaddr, lp->hacr);
1918 mmc_out(ioaddr, mmwoff(0, mmw_thr_pre_set),
1919 psa.psa_thr_pre_set);
1920 break;
1922 case SIOCGIWSENS:
1923 /* Read the level threshold. */
1924 psa_read(ioaddr, lp->hacr,
1925 (char *) &psa.psa_thr_pre_set - (char *) &psa,
1926 (unsigned char *) &psa.psa_thr_pre_set, 1);
1927 wrq->u.sens.value = psa.psa_thr_pre_set & 0x3F;
1928 wrq->u.sens.fixed = 1;
1929 break;
1931 case SIOCSIWENCODE:
1932 /* Set encryption key */
1933 if (!mmc_encr(ioaddr)) {
1934 ret = -EOPNOTSUPP;
1935 break;
1938 /* Basic checking... */
1939 if (wrq->u.encoding.pointer != (caddr_t) 0) {
1940 /* Check the size of the key */
1941 if (wrq->u.encoding.length != 8) {
1942 ret = -EINVAL;
1943 break;
1946 /* Copy the key in the driver */
1947 wv_splx(lp, &flags);
1948 err = copy_from_user(psa.psa_encryption_key,
1949 wrq->u.encoding.pointer,
1950 wrq->u.encoding.length);
1951 wv_splhi(lp, &flags);
1952 if (err) {
1953 ret = -EFAULT;
1954 break;
1957 psa.psa_encryption_select = 1;
1958 psa_write(ioaddr, lp->hacr,
1959 (char *) &psa.psa_encryption_select -
1960 (char *) &psa,
1961 (unsigned char *) &psa.
1962 psa_encryption_select, 8 + 1);
1964 mmc_out(ioaddr, mmwoff(0, mmw_encr_enable),
1965 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
1966 mmc_write(ioaddr, mmwoff(0, mmw_encr_key),
1967 (unsigned char *) &psa.
1968 psa_encryption_key, 8);
1971 if (wrq->u.encoding.flags & IW_ENCODE_DISABLED) { /* disable encryption */
1972 psa.psa_encryption_select = 0;
1973 psa_write(ioaddr, lp->hacr,
1974 (char *) &psa.psa_encryption_select -
1975 (char *) &psa,
1976 (unsigned char *) &psa.
1977 psa_encryption_select, 1);
1979 mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), 0);
1981 /* update the Wavelan checksum */
1982 update_psa_checksum(dev, ioaddr, lp->hacr);
1983 break;
1985 case SIOCGIWENCODE:
1986 /* Read the encryption key */
1987 if (!mmc_encr(ioaddr)) {
1988 ret = -EOPNOTSUPP;
1989 break;
1992 /* only super-user can see encryption key */
1993 if (!capable(CAP_NET_ADMIN)) {
1994 ret = -EPERM;
1995 break;
1998 /* Basic checking... */
1999 if (wrq->u.encoding.pointer != (caddr_t) 0) {
2000 /* Verify the user buffer */
2001 ret =
2002 verify_area(VERIFY_WRITE,
2003 wrq->u.encoding.pointer, 8);
2004 if (ret)
2005 break;
2007 psa_read(ioaddr, lp->hacr,
2008 (char *) &psa.psa_encryption_select -
2009 (char *) &psa,
2010 (unsigned char *) &psa.
2011 psa_encryption_select, 1 + 8);
2013 /* encryption is enabled ? */
2014 if (psa.psa_encryption_select)
2015 wrq->u.encoding.flags = IW_ENCODE_ENABLED;
2016 else
2017 wrq->u.encoding.flags = IW_ENCODE_DISABLED;
2018 wrq->u.encoding.flags |= mmc_encr(ioaddr);
2020 /* Copy the key to the user buffer */
2021 wrq->u.encoding.length = 8;
2022 wv_splx(lp, &flags);
2023 if (copy_to_user(wrq->u.encoding.pointer,
2024 psa.psa_encryption_key, 8))
2025 ret = -EFAULT;
2026 wv_splhi(lp, &flags);
2028 break;
2030 case SIOCGIWRANGE:
2031 /* basic checking */
2032 if (wrq->u.data.pointer != (caddr_t) 0) {
2033 struct iw_range range;
2035 /* Set the length (useless: it's constant). */
2036 wrq->u.data.length = sizeof(struct iw_range);
2038 /* Set information in the range struct. */
2039 range.throughput = 1.6 * 1000 * 1000; /* don't argue on this ! */
2040 range.min_nwid = 0x0000;
2041 range.max_nwid = 0xFFFF;
2043 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2044 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2045 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2046 range.num_channels = 10;
2047 range.num_frequency =
2048 wv_frequency_list(ioaddr, range.freq,
2049 IW_MAX_FREQUENCIES);
2050 } else
2051 range.num_channels = range.num_frequency =
2054 range.sensitivity = 0x3F;
2055 range.max_qual.qual = MMR_SGNL_QUAL;
2056 range.max_qual.level = MMR_SIGNAL_LVL;
2057 range.max_qual.noise = MMR_SILENCE_LVL;
2059 range.num_bitrates = 1;
2060 range.bitrate[0] = 2000000; /* 2 Mb/s */
2062 /* Encryption supported ? */
2063 if (mmc_encr(ioaddr)) {
2064 range.encoding_size[0] = 8; /* DES = 64 bits key */
2065 range.num_encoding_sizes = 1;
2066 range.max_encoding_tokens = 1; /* Only one key possible */
2067 } else {
2068 range.num_encoding_sizes = 0;
2069 range.max_encoding_tokens = 0;
2072 /* Copy structure to the user buffer. */
2073 wv_splx(lp, &flags);
2074 if (copy_to_user(wrq->u.data.pointer,
2075 &range,
2076 sizeof(struct iw_range)))
2077 ret = -EFAULT;
2078 wv_splhi(lp, &flags);
2080 break;
2082 case SIOCGIWPRIV:
2083 /* Basic checking */
2084 if (wrq->u.data.pointer != (caddr_t) 0) {
2085 struct iw_priv_args priv[] = {
2086 /* { cmd,
2087 set_args,
2088 get_args,
2089 name } */
2090 { SIOCSIPQTHR,
2091 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2093 "setqualthr" },
2094 { SIOCGIPQTHR,
2096 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2097 "getqualthr" },
2098 { SIOCSIPHISTO,
2099 IW_PRIV_TYPE_BYTE | 16,
2101 "sethisto" },
2102 { SIOCGIPHISTO,
2104 IW_PRIV_TYPE_INT | 16,
2105 "gethisto" },
2108 /* Set the number of available ioctls. */
2109 wrq->u.data.length = 4;
2111 /* Copy structure to the user buffer. */
2112 wv_splx(lp, &flags);
2113 if (copy_to_user(wrq->u.data.pointer,
2114 (u8 *) priv,
2115 sizeof(priv)))
2116 ret = -EFAULT;
2117 wv_splhi(lp, &flags);
2119 break;
2121 #ifdef WIRELESS_SPY
2122 case SIOCSIWSPY:
2123 /* Set the spy list */
2125 /* Check the number of addresses. */
2126 if (wrq->u.data.length > IW_MAX_SPY) {
2127 ret = -E2BIG;
2128 break;
2130 lp->spy_number = wrq->u.data.length;
2132 /* Are there are addresses to copy? */
2133 if (lp->spy_number > 0) {
2134 struct sockaddr address[IW_MAX_SPY];
2135 int i;
2137 /* Copy addresses to the driver. */
2138 wv_splx(lp, &flags);
2139 err = copy_from_user(address,
2140 wrq->u.data.pointer,
2141 sizeof(struct sockaddr)
2142 * lp->spy_number);
2143 wv_splhi(lp, &flags);
2144 if (err) {
2145 ret = -EFAULT;
2146 break;
2149 /* Copy addresses to the lp structure. */
2150 for (i = 0; i < lp->spy_number; i++) {
2151 memcpy(lp->spy_address[i],
2152 address[i].sa_data,
2153 WAVELAN_ADDR_SIZE);
2156 /* Reset structure. */
2157 memset(lp->spy_stat, 0x00,
2158 sizeof(iw_qual) * IW_MAX_SPY);
2160 #ifdef DEBUG_IOCTL_INFO
2161 printk(KERN_DEBUG
2162 "SetSpy: set of new addresses is: \n");
2163 for (i = 0; i < wrq->u.data.length; i++)
2164 printk(KERN_DEBUG
2165 "%02X:%02X:%02X:%02X:%02X:%02X \n",
2166 lp->spy_address[i][0],
2167 lp->spy_address[i][1],
2168 lp->spy_address[i][2],
2169 lp->spy_address[i][3],
2170 lp->spy_address[i][4],
2171 lp->spy_address[i][5]);
2172 #endif /* DEBUG_IOCTL_INFO */
2175 break;
2177 case SIOCGIWSPY:
2178 /* Get the spy list and spy stats. */
2180 /* Set the number of addresses */
2181 wrq->u.data.length = lp->spy_number;
2183 /* Does the user want to have the addresses back? */
2184 if ((lp->spy_number > 0)
2185 && (wrq->u.data.pointer != (caddr_t) 0)) {
2186 struct sockaddr address[IW_MAX_SPY];
2187 int i;
2189 /* Copy addresses from the lp structure. */
2190 for (i = 0; i < lp->spy_number; i++) {
2191 memcpy(address[i].sa_data,
2192 lp->spy_address[i],
2193 WAVELAN_ADDR_SIZE);
2194 address[i].sa_family = AF_UNIX;
2197 /* Copy addresses to the user buffer. */
2198 wv_splx(lp, &flags);
2199 err = copy_to_user(wrq->u.data.pointer,
2200 address,
2201 sizeof(struct sockaddr)
2202 * lp->spy_number);
2204 /* Copy stats to the user buffer (just after). */
2205 err |= copy_to_user(wrq->u.data.pointer
2206 + (sizeof(struct sockaddr)
2207 * lp->spy_number),
2208 lp->spy_stat,
2209 sizeof(iw_qual) * lp->spy_number);
2210 wv_splhi(lp, &flags);
2211 if (err) {
2212 ret = -EFAULT;
2213 break;
2216 /* Reset updated flags. */
2217 for (i = 0; i < lp->spy_number; i++)
2218 lp->spy_stat[i].updated = 0x0;
2220 /* if(pointer != NULL) */
2221 break;
2222 #endif /* WIRELESS_SPY */
2224 /* ------------------ PRIVATE IOCTL ------------------ */
2226 case SIOCSIPQTHR:
2227 if (!capable(CAP_NET_ADMIN)) {
2228 ret = -EPERM;
2229 break;
2231 psa.psa_quality_thr = *(wrq->u.name) & 0x0F;
2232 psa_write(ioaddr, lp->hacr,
2233 (char *) &psa.psa_quality_thr - (char *) &psa,
2234 (unsigned char *) &psa.psa_quality_thr, 1);
2235 /* update the Wavelan checksum */
2236 update_psa_checksum(dev, ioaddr, lp->hacr);
2237 mmc_out(ioaddr, mmwoff(0, mmw_quality_thr),
2238 psa.psa_quality_thr);
2239 break;
2241 case SIOCGIPQTHR:
2242 psa_read(ioaddr, lp->hacr,
2243 (char *) &psa.psa_quality_thr - (char *) &psa,
2244 (unsigned char *) &psa.psa_quality_thr, 1);
2245 *(wrq->u.name) = psa.psa_quality_thr & 0x0F;
2246 break;
2248 #ifdef HISTOGRAM
2249 case SIOCSIPHISTO:
2250 /* Verify that the user is root. */
2251 if (!capable(CAP_NET_ADMIN)) {
2252 ret = -EPERM;
2253 break;
2256 /* Check the number of intervals. */
2257 if (wrq->u.data.length > 16) {
2258 ret = -E2BIG;
2259 break;
2261 lp->his_number = wrq->u.data.length;
2263 /* Are there addresses to copy? */
2264 if (lp->his_number > 0) {
2265 /* Copy interval ranges to the driver */
2266 wv_splx(lp, &flags);
2267 err = copy_from_user(lp->his_range,
2268 wrq->u.data.pointer,
2269 sizeof(char) * lp->his_number);
2270 wv_splhi(lp, &flags);
2271 if (err) {
2272 ret = -EFAULT;
2273 break;
2276 /* Reset structure. */
2277 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2279 break;
2281 case SIOCGIPHISTO:
2282 /* Set the number of intervals. */
2283 wrq->u.data.length = lp->his_number;
2285 /* Give back the distribution statistics */
2286 if ((lp->his_number > 0)
2287 && (wrq->u.data.pointer != (caddr_t) 0)) {
2288 /* Copy data to the user buffer. */
2289 wv_splx(lp, &flags);
2290 if (copy_to_user(wrq->u.data.pointer,
2291 lp->his_sum,
2292 sizeof(long) * lp->his_number);
2293 ret = -EFAULT;
2294 wv_splhi(lp, &flags);
2296 } /* if(pointer != NULL) */
2297 break;
2298 #endif /* HISTOGRAM */
2300 /* ------------------- OTHER IOCTL ------------------- */
2302 default:
2303 ret = -EOPNOTSUPP;
2304 } /* switch (cmd) */
2306 /* Enable interrupts and restore flags. */
2307 wv_splx(lp, &flags);
2309 #ifdef DEBUG_IOCTL_TRACE
2310 printk(KERN_DEBUG "%s: <-wavelan_ioctl()\n", dev->name);
2311 #endif
2312 return ret;
2315 /*------------------------------------------------------------------*/
2317 * Get wireless statistics.
2318 * Called by /proc/net/wireless
2320 static iw_stats *wavelan_get_wireless_stats(device * dev)
2322 unsigned long ioaddr = dev->base_addr;
2323 net_local *lp = (net_local *) dev->priv;
2324 mmr_t m;
2325 iw_stats *wstats;
2326 unsigned long flags;
2328 #ifdef DEBUG_IOCTL_TRACE
2329 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n",
2330 dev->name);
2331 #endif
2333 /* Check */
2334 if (lp == (net_local *) NULL)
2335 return (iw_stats *) NULL;
2337 /* Disable interrupts and save flags. */
2338 wv_splhi(lp, &flags);
2340 wstats = &lp->wstats;
2342 /* Get data from the mmc. */
2343 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2345 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2346 mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l,
2348 mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set,
2351 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2353 /* Copy data to wireless stuff. */
2354 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2355 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2356 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2357 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2358 wstats->qual.updated = (((m. mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7)
2359 | ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6)
2360 | ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2361 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2362 wstats->discard.code = 0L;
2363 wstats->discard.misc = 0L;
2365 /* Enable interrupts and restore flags. */
2366 wv_splx(lp, &flags);
2368 #ifdef DEBUG_IOCTL_TRACE
2369 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n",
2370 dev->name);
2371 #endif
2372 return &lp->wstats;
2374 #endif /* WIRELESS_EXT */
2376 /************************* PACKET RECEPTION *************************/
2378 * This part deals with receiving the packets.
2379 * The interrupt handler gets an interrupt when a packet has been
2380 * successfully received and calls this part.
2383 /*------------------------------------------------------------------*/
2385 * This routine does the actual copying of data (including the Ethernet
2386 * header structure) from the WaveLAN card to an sk_buff chain that
2387 * will be passed up to the network interface layer. NOTE: we
2388 * currently don't handle trailer protocols (neither does the rest of
2389 * the network interface), so if that is needed, it will (at least in
2390 * part) be added here. The contents of the receive ring buffer are
2391 * copied to a message chain that is then passed to the kernel.
2393 * Note: if any errors occur, the packet is "dropped on the floor".
2394 * (called by wv_packet_rcv())
2396 static inline void
2397 wv_packet_read(device * dev, u16 buf_off, int sksize)
2399 net_local *lp = (net_local *) dev->priv;
2400 unsigned long ioaddr = dev->base_addr;
2401 struct sk_buff *skb;
2403 #ifdef DEBUG_RX_TRACE
2404 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2405 dev->name, buf_off, sksize);
2406 #endif
2408 /* Allocate buffer for the data */
2409 if ((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL) {
2410 #ifdef DEBUG_RX_ERROR
2411 printk(KERN_INFO
2412 "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
2413 dev->name, sksize);
2414 #endif
2415 lp->stats.rx_dropped++;
2416 return;
2419 skb->dev = dev;
2421 /* Copy the packet to the buffer. */
2422 obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize);
2423 skb->protocol = eth_type_trans(skb, dev);
2425 #ifdef DEBUG_RX_INFO
2426 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2427 #endif /* DEBUG_RX_INFO */
2429 /* Statistics-gathering and associated stuff.
2430 * It seem a bit messy with all the define, but it's really simple... */
2431 #if defined(WIRELESS_SPY) || defined(HISTOGRAM)
2432 if (
2433 #ifdef WIRELESS_SPY
2434 (lp->spy_number > 0) ||
2435 #endif /* WIRELESS_SPY */
2436 #ifdef HISTOGRAM
2437 (lp->his_number > 0) ||
2438 #endif /* HISTOGRAM */
2439 0) {
2440 u8 stats[3]; /* signal level, noise level, signal quality */
2442 /* Read signal level, silence level and signal quality bytes. */
2443 /* Note: in the PCMCIA hardware, these are part of the frame. It seems
2444 * that for the ISA hardware, it's nowhere to be found in the frame,
2445 * so I'm obliged to do this (it has a side effect on /proc/net/wireless).
2446 * Any ideas?
2448 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2449 mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3);
2450 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2452 #ifdef DEBUG_RX_INFO
2453 printk(KERN_DEBUG
2454 "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2455 dev->name, stats[0] & 0x3F, stats[1] & 0x3F,
2456 stats[2] & 0x0F);
2457 #endif
2459 /* Spying stuff */
2460 #ifdef WIRELESS_SPY
2461 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE,
2462 stats);
2463 #endif /* WIRELESS_SPY */
2464 #ifdef HISTOGRAM
2465 wl_his_gather(dev, stats);
2466 #endif /* HISTOGRAM */
2468 #endif /* defined(WIRELESS_SPY) || defined(HISTOGRAM) */
2471 * Hand the packet to the network module.
2473 netif_rx(skb);
2475 /* Keep statistics up to date */
2476 lp->stats.rx_packets++;
2477 lp->stats.rx_bytes += skb->len;
2479 #ifdef DEBUG_RX_TRACE
2480 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2481 #endif
2484 /*------------------------------------------------------------------*/
2486 * Transfer as many packets as we can
2487 * from the device RAM.
2488 * (called in wavelan_interrupt()).
2489 * Note : the spinlock is already grabbed for us.
2491 static inline void wv_receive(device * dev)
2493 unsigned long ioaddr = dev->base_addr;
2494 net_local *lp = (net_local *) dev->priv;
2495 fd_t fd;
2496 rbd_t rbd;
2497 int nreaped = 0;
2499 #ifdef DEBUG_RX_TRACE
2500 printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name);
2501 #endif
2503 /* Loop on each received packet. */
2504 for (;;) {
2505 obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd,
2506 sizeof(fd));
2508 /* Note about the status :
2509 * It start up to be 0 (the value we set). Then, when the RU
2510 * grab the buffer to prepare for reception, it sets the
2511 * FD_STATUS_B flag. When the RU has finished receiving the
2512 * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
2513 * completion and set the other flags to indicate the eventual
2514 * errors. FD_STATUS_OK indicates that the reception was OK.
2517 /* If the current frame is not complete, we have reached the end. */
2518 if ((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
2519 break; /* This is how we exit the loop. */
2521 nreaped++;
2523 /* Check whether frame was correctly received. */
2524 if ((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK) {
2525 /* Does the frame contain a pointer to the data? Let's check. */
2526 if (fd.fd_rbd_offset != I82586NULL) {
2527 /* Read the receive buffer descriptor */
2528 obram_read(ioaddr, fd.fd_rbd_offset,
2529 (unsigned char *) &rbd,
2530 sizeof(rbd));
2532 #ifdef DEBUG_RX_ERROR
2533 if ((rbd.rbd_status & RBD_STATUS_EOF) !=
2534 RBD_STATUS_EOF) printk(KERN_INFO
2535 "%s: wv_receive(): missing EOF flag.\n",
2536 dev->name);
2538 if ((rbd.rbd_status & RBD_STATUS_F) !=
2539 RBD_STATUS_F) printk(KERN_INFO
2540 "%s: wv_receive(): missing F flag.\n",
2541 dev->name);
2542 #endif /* DEBUG_RX_ERROR */
2544 /* Read the packet and transmit to Linux */
2545 wv_packet_read(dev, rbd.rbd_bufl,
2546 rbd.
2547 rbd_status &
2548 RBD_STATUS_ACNT);
2550 #ifdef DEBUG_RX_ERROR
2551 else /* if frame has no data */
2552 printk(KERN_INFO
2553 "%s: wv_receive(): frame has no data.\n",
2554 dev->name);
2555 #endif
2556 } else { /* If reception was no successful */
2558 lp->stats.rx_errors++;
2560 #ifdef DEBUG_RX_INFO
2561 printk(KERN_DEBUG
2562 "%s: wv_receive(): frame not received successfully (%X).\n",
2563 dev->name, fd.fd_status);
2564 #endif
2566 #ifdef DEBUG_RX_ERROR
2567 if ((fd.fd_status & FD_STATUS_S6) != 0)
2568 printk(KERN_INFO
2569 "%s: wv_receive(): no EOF flag.\n",
2570 dev->name);
2571 #endif
2573 if ((fd.fd_status & FD_STATUS_S7) != 0) {
2574 lp->stats.rx_length_errors++;
2575 #ifdef DEBUG_RX_FAIL
2576 printk(KERN_DEBUG
2577 "%s: wv_receive(): frame too short.\n",
2578 dev->name);
2579 #endif
2582 if ((fd.fd_status & FD_STATUS_S8) != 0) {
2583 lp->stats.rx_over_errors++;
2584 #ifdef DEBUG_RX_FAIL
2585 printk(KERN_DEBUG
2586 "%s: wv_receive(): rx DMA overrun.\n",
2587 dev->name);
2588 #endif
2591 if ((fd.fd_status & FD_STATUS_S9) != 0) {
2592 lp->stats.rx_fifo_errors++;
2593 #ifdef DEBUG_RX_FAIL
2594 printk(KERN_DEBUG
2595 "%s: wv_receive(): ran out of resources.\n",
2596 dev->name);
2597 #endif
2600 if ((fd.fd_status & FD_STATUS_S10) != 0) {
2601 lp->stats.rx_frame_errors++;
2602 #ifdef DEBUG_RX_FAIL
2603 printk(KERN_DEBUG
2604 "%s: wv_receive(): alignment error.\n",
2605 dev->name);
2606 #endif
2609 if ((fd.fd_status & FD_STATUS_S11) != 0) {
2610 lp->stats.rx_crc_errors++;
2611 #ifdef DEBUG_RX_FAIL
2612 printk(KERN_DEBUG
2613 "%s: wv_receive(): CRC error.\n",
2614 dev->name);
2615 #endif
2619 fd.fd_status = 0;
2620 obram_write(ioaddr, fdoff(lp->rx_head, fd_status),
2621 (unsigned char *) &fd.fd_status,
2622 sizeof(fd.fd_status));
2624 fd.fd_command = FD_COMMAND_EL;
2625 obram_write(ioaddr, fdoff(lp->rx_head, fd_command),
2626 (unsigned char *) &fd.fd_command,
2627 sizeof(fd.fd_command));
2629 fd.fd_command = 0;
2630 obram_write(ioaddr, fdoff(lp->rx_last, fd_command),
2631 (unsigned char *) &fd.fd_command,
2632 sizeof(fd.fd_command));
2634 lp->rx_last = lp->rx_head;
2635 lp->rx_head = fd.fd_link_offset;
2636 } /* for(;;) -> loop on all frames */
2638 #ifdef DEBUG_RX_INFO
2639 if (nreaped > 1)
2640 printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n",
2641 dev->name, nreaped);
2642 #endif
2643 #ifdef DEBUG_RX_TRACE
2644 printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name);
2645 #endif
2648 /*********************** PACKET TRANSMISSION ***********************/
2650 * This part deals with sending packets through the WaveLAN.
2654 /*------------------------------------------------------------------*/
2656 * This routine fills in the appropriate registers and memory
2657 * locations on the WaveLAN card and starts the card off on
2658 * the transmit.
2660 * The principle:
2661 * Each block contains a transmit command, a NOP command,
2662 * a transmit block descriptor and a buffer.
2663 * The CU read the transmit block which point to the tbd,
2664 * read the tbd and the content of the buffer.
2665 * When it has finish with it, it goes to the next command
2666 * which in our case is the NOP. The NOP points on itself,
2667 * so the CU stop here.
2668 * When we add the next block, we modify the previous nop
2669 * to make it point on the new tx command.
2670 * Simple, isn't it ?
2672 * (called in wavelan_packet_xmit())
2674 static inline int wv_packet_write(device * dev, void *buf, short length)
2676 net_local *lp = (net_local *) dev->priv;
2677 unsigned long ioaddr = dev->base_addr;
2678 unsigned short txblock;
2679 unsigned short txpred;
2680 unsigned short tx_addr;
2681 unsigned short nop_addr;
2682 unsigned short tbd_addr;
2683 unsigned short buf_addr;
2684 ac_tx_t tx;
2685 ac_nop_t nop;
2686 tbd_t tbd;
2687 int clen = length;
2688 unsigned long flags;
2690 #ifdef DEBUG_TX_TRACE
2691 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name,
2692 length);
2693 #endif
2695 /* Do we need some padding? */
2696 if (clen < ETH_ZLEN)
2697 clen = ETH_ZLEN;
2699 wv_splhi(lp, &flags);
2701 /* Check nothing bad has happened */
2702 if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
2703 #ifdef DEBUG_TX_ERROR
2704 printk(KERN_INFO "%s: wv_packet_write(): Tx queue full.\n",
2705 dev->name);
2706 #endif
2707 wv_splx(lp, &flags);
2708 return 1;
2711 /* Calculate addresses of next block and previous block. */
2712 txblock = lp->tx_first_free;
2713 txpred = txblock - TXBLOCKZ;
2714 if (txpred < OFFSET_CU)
2715 txpred += NTXBLOCKS * TXBLOCKZ;
2716 lp->tx_first_free += TXBLOCKZ;
2717 if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
2718 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
2720 lp->tx_n_in_use++;
2722 /* Calculate addresses of the different parts of the block. */
2723 tx_addr = txblock;
2724 nop_addr = tx_addr + sizeof(tx);
2725 tbd_addr = nop_addr + sizeof(nop);
2726 buf_addr = tbd_addr + sizeof(tbd);
2729 * Transmit command
2731 tx.tx_h.ac_status = 0;
2732 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
2733 (unsigned char *) &tx.tx_h.ac_status,
2734 sizeof(tx.tx_h.ac_status));
2737 * NOP command
2739 nop.nop_h.ac_status = 0;
2740 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2741 (unsigned char *) &nop.nop_h.ac_status,
2742 sizeof(nop.nop_h.ac_status));
2743 nop.nop_h.ac_link = nop_addr;
2744 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2745 (unsigned char *) &nop.nop_h.ac_link,
2746 sizeof(nop.nop_h.ac_link));
2749 * Transmit buffer descriptor
2751 tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen);
2752 tbd.tbd_next_bd_offset = I82586NULL;
2753 tbd.tbd_bufl = buf_addr;
2754 tbd.tbd_bufh = 0;
2755 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd));
2758 * Data
2760 obram_write(ioaddr, buf_addr, buf, length);
2763 * Overwrite the predecessor NOP link
2764 * so that it points to this txblock.
2766 nop_addr = txpred + sizeof(tx);
2767 nop.nop_h.ac_status = 0;
2768 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2769 (unsigned char *) &nop.nop_h.ac_status,
2770 sizeof(nop.nop_h.ac_status));
2771 nop.nop_h.ac_link = txblock;
2772 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2773 (unsigned char *) &nop.nop_h.ac_link,
2774 sizeof(nop.nop_h.ac_link));
2776 /* Keep stats up to date. */
2777 lp->stats.tx_bytes += length;
2779 if (lp->tx_first_in_use == I82586NULL)
2780 lp->tx_first_in_use = txblock;
2782 if (lp->tx_n_in_use < NTXBLOCKS - 1)
2783 netif_wake_queue(dev);
2785 wv_splx(lp, &flags);
2787 #ifdef DEBUG_TX_INFO
2788 wv_packet_info((u8 *) buf, length, dev->name,
2789 "wv_packet_write");
2790 #endif /* DEBUG_TX_INFO */
2792 #ifdef DEBUG_TX_TRACE
2793 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
2794 #endif
2796 return 0;
2799 /*------------------------------------------------------------------*/
2801 * This routine is called when we want to send a packet (NET3 callback)
2802 * In this routine, we check if the harware is ready to accept
2803 * the packet. We also prevent reentrance. Then we call the function
2804 * to send the packet.
2806 static int wavelan_packet_xmit(struct sk_buff *skb, device * dev)
2808 net_local *lp = (net_local *) dev->priv;
2810 #ifdef DEBUG_TX_TRACE
2811 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
2812 (unsigned) skb);
2813 #endif
2816 * Block a timer-based transmit from overlapping.
2817 * In other words, prevent reentering this routine.
2819 netif_stop_queue(dev);
2821 /* If somebody has asked to reconfigure the controller,
2822 * we can do it now.
2824 if (lp->reconfig_82586) {
2825 wv_82586_config(dev);
2826 /* Check that we can continue */
2827 if (lp->tx_n_in_use == (NTXBLOCKS - 1))
2828 return 1;
2830 #ifdef DEBUG_TX_ERROR
2831 if (skb->next)
2832 printk(KERN_INFO "skb has next\n");
2833 #endif
2835 /* Write packet on the card */
2836 if(wv_packet_write(dev, skb->data, skb->len))
2837 return 1; /* We failed */
2839 dev_kfree_skb(skb);
2841 #ifdef DEBUG_TX_TRACE
2842 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
2843 #endif
2844 return 0;
2847 /*********************** HARDWARE CONFIGURATION ***********************/
2849 * This part does the real job of starting and configuring the hardware.
2852 /*--------------------------------------------------------------------*/
2854 * Routine to initialize the Modem Management Controller.
2855 * (called by wv_hw_reset())
2857 static inline int wv_mmc_init(device * dev)
2859 unsigned long ioaddr = dev->base_addr;
2860 net_local *lp = (net_local *) dev->priv;
2861 psa_t psa;
2862 mmw_t m;
2863 int configured;
2865 #ifdef DEBUG_CONFIG_TRACE
2866 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
2867 #endif
2869 /* Read the parameter storage area. */
2870 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
2872 #ifdef USE_PSA_CONFIG
2873 configured = psa.psa_conf_status & 1;
2874 #else
2875 configured = 0;
2876 #endif
2878 /* Is the PSA is not configured */
2879 if (!configured) {
2880 /* User will be able to configure NWID later (with iwconfig). */
2881 psa.psa_nwid[0] = 0;
2882 psa.psa_nwid[1] = 0;
2884 /* no NWID checking since NWID is not set */
2885 psa.psa_nwid_select = 0;
2887 /* Disable encryption */
2888 psa.psa_encryption_select = 0;
2890 /* Set to standard values:
2891 * 0x04 for AT,
2892 * 0x01 for MCA,
2893 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
2895 if (psa.psa_comp_number & 1)
2896 psa.psa_thr_pre_set = 0x01;
2897 else
2898 psa.psa_thr_pre_set = 0x04;
2899 psa.psa_quality_thr = 0x03;
2901 /* It is configured */
2902 psa.psa_conf_status |= 1;
2904 #ifdef USE_PSA_CONFIG
2905 /* Write the psa. */
2906 psa_write(ioaddr, lp->hacr,
2907 (char *) psa.psa_nwid - (char *) &psa,
2908 (unsigned char *) psa.psa_nwid, 4);
2909 psa_write(ioaddr, lp->hacr,
2910 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2911 (unsigned char *) &psa.psa_thr_pre_set, 1);
2912 psa_write(ioaddr, lp->hacr,
2913 (char *) &psa.psa_quality_thr - (char *) &psa,
2914 (unsigned char *) &psa.psa_quality_thr, 1);
2915 psa_write(ioaddr, lp->hacr,
2916 (char *) &psa.psa_conf_status - (char *) &psa,
2917 (unsigned char *) &psa.psa_conf_status, 1);
2918 /* update the Wavelan checksum */
2919 update_psa_checksum(dev, ioaddr, lp->hacr);
2920 #endif
2923 /* Zero the mmc structure. */
2924 memset(&m, 0x00, sizeof(m));
2926 /* Copy PSA info to the mmc. */
2927 m.mmw_netw_id_l = psa.psa_nwid[1];
2928 m.mmw_netw_id_h = psa.psa_nwid[0];
2930 if (psa.psa_nwid_select & 1)
2931 m.mmw_loopt_sel = 0x00;
2932 else
2933 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
2935 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
2936 sizeof(m.mmw_encr_key));
2938 if (psa.psa_encryption_select)
2939 m.mmw_encr_enable =
2940 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
2941 else
2942 m.mmw_encr_enable = 0;
2944 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
2945 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
2948 * Set default modem control parameters.
2949 * See NCR document 407-0024326 Rev. A.
2951 m.mmw_jabber_enable = 0x01;
2952 m.mmw_freeze = 0;
2953 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
2954 m.mmw_ifs = 0x20;
2955 m.mmw_mod_delay = 0x04;
2956 m.mmw_jam_time = 0x38;
2958 m.mmw_des_io_invert = 0;
2959 m.mmw_decay_prm = 0;
2960 m.mmw_decay_updat_prm = 0;
2962 /* Write all info to MMC. */
2963 mmc_write(ioaddr, 0, (u8 *) & m, sizeof(m));
2965 /* The following code starts the modem of the 2.00 frequency
2966 * selectable cards at power on. It's not strictly needed for the
2967 * following boots.
2968 * The original patch was by Joe Finney for the PCMCIA driver, but
2969 * I've cleaned it up a bit and added documentation.
2970 * Thanks to Loeke Brederveld from Lucent for the info.
2973 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
2974 * Does it work for everybody, especially old cards? */
2975 /* Note: WFREQSEL verifies that it is able to read a sensible
2976 * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
2977 * is 0xA (Xilinx version) or 0xB (Ariadne version).
2978 * My test is more crude but does work. */
2979 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2980 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2981 /* We must download the frequency parameters to the
2982 * synthesizers (from the EEPROM - area 1)
2983 * Note: as the EEPROM is automatically decremented, we set the end
2984 * if the area... */
2985 m.mmw_fee_addr = 0x0F;
2986 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
2987 mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
2988 (unsigned char *) &m.mmw_fee_ctrl, 2);
2990 /* Wait until the download is finished. */
2991 fee_wait(ioaddr, 100, 100);
2993 #ifdef DEBUG_CONFIG_INFO
2994 /* The frequency was in the last word downloaded. */
2995 mmc_read(ioaddr, (char *) &m.mmw_fee_data_l - (char *) &m,
2996 (unsigned char *) &m.mmw_fee_data_l, 2);
2998 /* Print some info for the user. */
2999 printk(KERN_DEBUG
3000 "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n",
3001 dev->name,
3002 ((m.
3003 mmw_fee_data_h << 4) | (m.mmw_fee_data_l >> 4)) *
3004 5 / 2 + 24000L);
3005 #endif
3007 /* We must now download the power adjust value (gain) to
3008 * the synthesizers (from the EEPROM - area 7 - DAC). */
3009 m.mmw_fee_addr = 0x61;
3010 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3011 mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
3012 (unsigned char *) &m.mmw_fee_ctrl, 2);
3014 /* Wait until the download is finished. */
3016 /* if 2.00 card */
3017 #ifdef DEBUG_CONFIG_TRACE
3018 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3019 #endif
3020 return 0;
3023 /*------------------------------------------------------------------*/
3025 * Construct the fd and rbd structures.
3026 * Start the receive unit.
3027 * (called by wv_hw_reset())
3029 static inline int wv_ru_start(device * dev)
3031 net_local *lp = (net_local *) dev->priv;
3032 unsigned long ioaddr = dev->base_addr;
3033 u16 scb_cs;
3034 fd_t fd;
3035 rbd_t rbd;
3036 u16 rx;
3037 u16 rx_next;
3038 int i;
3040 #ifdef DEBUG_CONFIG_TRACE
3041 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3042 #endif
3044 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3045 (unsigned char *) &scb_cs, sizeof(scb_cs));
3046 if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
3047 return 0;
3049 lp->rx_head = OFFSET_RU;
3051 for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next) {
3052 rx_next =
3053 (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
3055 fd.fd_status = 0;
3056 fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
3057 fd.fd_link_offset = rx_next;
3058 fd.fd_rbd_offset = rx + sizeof(fd);
3059 obram_write(ioaddr, rx, (unsigned char *) &fd, sizeof(fd));
3061 rbd.rbd_status = 0;
3062 rbd.rbd_next_rbd_offset = I82586NULL;
3063 rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
3064 rbd.rbd_bufh = 0;
3065 rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
3066 obram_write(ioaddr, rx + sizeof(fd),
3067 (unsigned char *) &rbd, sizeof(rbd));
3069 lp->rx_last = rx;
3072 obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
3073 (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
3075 scb_cs = SCB_CMD_RUC_GO;
3076 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3077 (unsigned char *) &scb_cs, sizeof(scb_cs));
3079 set_chan_attn(ioaddr, lp->hacr);
3081 for (i = 1000; i > 0; i--) {
3082 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3083 (unsigned char *) &scb_cs, sizeof(scb_cs));
3084 if (scb_cs == 0)
3085 break;
3087 udelay(10);
3090 if (i <= 0) {
3091 #ifdef DEBUG_CONFIG_ERROR
3092 printk(KERN_INFO
3093 "%s: wavelan_ru_start(): board not accepting command.\n",
3094 dev->name);
3095 #endif
3096 return -1;
3098 #ifdef DEBUG_CONFIG_TRACE
3099 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3100 #endif
3101 return 0;
3104 /*------------------------------------------------------------------*/
3106 * Initialise the transmit blocks.
3107 * Start the command unit executing the NOP
3108 * self-loop of the first transmit block.
3110 * Here we create the list of send buffers used to transmit packets
3111 * between the PC and the command unit. For each buffer, we create a
3112 * buffer descriptor (pointing on the buffer), a transmit command
3113 * (pointing to the buffer descriptor) and a NOP command.
3114 * The transmit command is linked to the NOP, and the NOP to itself.
3115 * When we will have finished executing the transmit command, we will
3116 * then loop on the NOP. By releasing the NOP link to a new command,
3117 * we may send another buffer.
3119 * (called by wv_hw_reset())
3121 static inline int wv_cu_start(device * dev)
3123 net_local *lp = (net_local *) dev->priv;
3124 unsigned long ioaddr = dev->base_addr;
3125 int i;
3126 u16 txblock;
3127 u16 first_nop;
3128 u16 scb_cs;
3130 #ifdef DEBUG_CONFIG_TRACE
3131 printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
3132 #endif
3134 lp->tx_first_free = OFFSET_CU;
3135 lp->tx_first_in_use = I82586NULL;
3137 for (i = 0, txblock = OFFSET_CU;
3138 i < NTXBLOCKS; i++, txblock += TXBLOCKZ) {
3139 ac_tx_t tx;
3140 ac_nop_t nop;
3141 tbd_t tbd;
3142 unsigned short tx_addr;
3143 unsigned short nop_addr;
3144 unsigned short tbd_addr;
3145 unsigned short buf_addr;
3147 tx_addr = txblock;
3148 nop_addr = tx_addr + sizeof(tx);
3149 tbd_addr = nop_addr + sizeof(nop);
3150 buf_addr = tbd_addr + sizeof(tbd);
3152 tx.tx_h.ac_status = 0;
3153 tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
3154 tx.tx_h.ac_link = nop_addr;
3155 tx.tx_tbd_offset = tbd_addr;
3156 obram_write(ioaddr, tx_addr, (unsigned char *) &tx,
3157 sizeof(tx));
3159 nop.nop_h.ac_status = 0;
3160 nop.nop_h.ac_command = acmd_nop;
3161 nop.nop_h.ac_link = nop_addr;
3162 obram_write(ioaddr, nop_addr, (unsigned char *) &nop,
3163 sizeof(nop));
3165 tbd.tbd_status = TBD_STATUS_EOF;
3166 tbd.tbd_next_bd_offset = I82586NULL;
3167 tbd.tbd_bufl = buf_addr;
3168 tbd.tbd_bufh = 0;
3169 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd,
3170 sizeof(tbd));
3173 first_nop =
3174 OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
3175 obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
3176 (unsigned char *) &first_nop, sizeof(first_nop));
3178 scb_cs = SCB_CMD_CUC_GO;
3179 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3180 (unsigned char *) &scb_cs, sizeof(scb_cs));
3182 set_chan_attn(ioaddr, lp->hacr);
3184 for (i = 1000; i > 0; i--) {
3185 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3186 (unsigned char *) &scb_cs, sizeof(scb_cs));
3187 if (scb_cs == 0)
3188 break;
3190 udelay(10);
3193 if (i <= 0) {
3194 #ifdef DEBUG_CONFIG_ERROR
3195 printk(KERN_INFO
3196 "%s: wavelan_cu_start(): board not accepting command.\n",
3197 dev->name);
3198 #endif
3199 return -1;
3202 lp->tx_n_in_use = 0;
3203 netif_start_queue(dev);
3204 #ifdef DEBUG_CONFIG_TRACE
3205 printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
3206 #endif
3207 return 0;
3210 /*------------------------------------------------------------------*/
3212 * This routine does a standard configuration of the WaveLAN
3213 * controller (i82586).
3215 * It initialises the scp, iscp and scb structure
3216 * The first two are just pointers to the next.
3217 * The last one is used for basic configuration and for basic
3218 * communication (interrupt status).
3220 * (called by wv_hw_reset())
3222 static inline int wv_82586_start(device * dev)
3224 net_local *lp = (net_local *) dev->priv;
3225 unsigned long ioaddr = dev->base_addr;
3226 scp_t scp; /* system configuration pointer */
3227 iscp_t iscp; /* intermediate scp */
3228 scb_t scb; /* system control block */
3229 ach_t cb; /* Action command header */
3230 u8 zeroes[512];
3231 int i;
3233 #ifdef DEBUG_CONFIG_TRACE
3234 printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
3235 #endif
3238 * Clear the onboard RAM.
3240 memset(&zeroes[0], 0x00, sizeof(zeroes));
3241 for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
3242 obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
3245 * Construct the command unit structures:
3246 * scp, iscp, scb, cb.
3248 memset(&scp, 0x00, sizeof(scp));
3249 scp.scp_sysbus = SCP_SY_16BBUS;
3250 scp.scp_iscpl = OFFSET_ISCP;
3251 obram_write(ioaddr, OFFSET_SCP, (unsigned char *) &scp,
3252 sizeof(scp));
3254 memset(&iscp, 0x00, sizeof(iscp));
3255 iscp.iscp_busy = 1;
3256 iscp.iscp_offset = OFFSET_SCB;
3257 obram_write(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3258 sizeof(iscp));
3260 /* Our first command is to reset the i82586. */
3261 memset(&scb, 0x00, sizeof(scb));
3262 scb.scb_command = SCB_CMD_RESET;
3263 scb.scb_cbl_offset = OFFSET_CU;
3264 scb.scb_rfa_offset = OFFSET_RU;
3265 obram_write(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3266 sizeof(scb));
3268 set_chan_attn(ioaddr, lp->hacr);
3270 /* Wait for command to finish. */
3271 for (i = 1000; i > 0; i--) {
3272 obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3273 sizeof(iscp));
3275 if (iscp.iscp_busy == (unsigned short) 0)
3276 break;
3278 udelay(10);
3281 if (i <= 0) {
3282 #ifdef DEBUG_CONFIG_ERROR
3283 printk(KERN_INFO
3284 "%s: wv_82586_start(): iscp_busy timeout.\n",
3285 dev->name);
3286 #endif
3287 return -1;
3290 /* Check command completion. */
3291 for (i = 15; i > 0; i--) {
3292 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3293 sizeof(scb));
3295 if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
3296 break;
3298 udelay(10);
3301 if (i <= 0) {
3302 #ifdef DEBUG_CONFIG_ERROR
3303 printk(KERN_INFO
3304 "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
3305 dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
3306 #endif
3307 return -1;
3310 wv_ack(dev);
3312 /* Set the action command header. */
3313 memset(&cb, 0x00, sizeof(cb));
3314 cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
3315 cb.ac_link = OFFSET_CU;
3316 obram_write(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3318 if (wv_synchronous_cmd(dev, "diag()") == -1)
3319 return -1;
3321 obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3322 if (cb.ac_status & AC_SFLD_FAIL) {
3323 #ifdef DEBUG_CONFIG_ERROR
3324 printk(KERN_INFO
3325 "%s: wv_82586_start(): i82586 Self Test failed.\n",
3326 dev->name);
3327 #endif
3328 return -1;
3330 #ifdef DEBUG_I82586_SHOW
3331 wv_scb_show(ioaddr);
3332 #endif
3334 #ifdef DEBUG_CONFIG_TRACE
3335 printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
3336 #endif
3337 return 0;
3340 /*------------------------------------------------------------------*/
3342 * This routine does a standard configuration of the WaveLAN
3343 * controller (i82586).
3345 * This routine is a violent hack. We use the first free transmit block
3346 * to make our configuration. In the buffer area, we create the three
3347 * configuration commands (linked). We make the previous NOP point to
3348 * the beginning of the buffer instead of the tx command. After, we go
3349 * as usual to the NOP command.
3350 * Note that only the last command (mc_set) will generate an interrupt.
3352 * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit())
3354 static void wv_82586_config(device * dev)
3356 net_local *lp = (net_local *) dev->priv;
3357 unsigned long ioaddr = dev->base_addr;
3358 unsigned short txblock;
3359 unsigned short txpred;
3360 unsigned short tx_addr;
3361 unsigned short nop_addr;
3362 unsigned short tbd_addr;
3363 unsigned short cfg_addr;
3364 unsigned short ias_addr;
3365 unsigned short mcs_addr;
3366 ac_tx_t tx;
3367 ac_nop_t nop;
3368 ac_cfg_t cfg; /* Configure action */
3369 ac_ias_t ias; /* IA-setup action */
3370 ac_mcs_t mcs; /* Multicast setup */
3371 struct dev_mc_list *dmi;
3372 unsigned long flags;
3374 #ifdef DEBUG_CONFIG_TRACE
3375 printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
3376 #endif
3378 wv_splhi(lp, &flags);
3380 /* Check nothing bad has happened */
3381 if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
3382 #ifdef DEBUG_CONFIG_ERROR
3383 printk(KERN_INFO "%s: wv_82586_config(): Tx queue full.\n",
3384 dev->name);
3385 #endif
3386 wv_splx(lp, &flags);
3387 return;
3390 /* Calculate addresses of next block and previous block. */
3391 txblock = lp->tx_first_free;
3392 txpred = txblock - TXBLOCKZ;
3393 if (txpred < OFFSET_CU)
3394 txpred += NTXBLOCKS * TXBLOCKZ;
3395 lp->tx_first_free += TXBLOCKZ;
3396 if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
3397 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
3399 lp->tx_n_in_use++;
3401 /* Calculate addresses of the different parts of the block. */
3402 tx_addr = txblock;
3403 nop_addr = tx_addr + sizeof(tx);
3404 tbd_addr = nop_addr + sizeof(nop);
3405 cfg_addr = tbd_addr + sizeof(tbd_t); /* beginning of the buffer */
3406 ias_addr = cfg_addr + sizeof(cfg);
3407 mcs_addr = ias_addr + sizeof(ias);
3410 * Transmit command
3412 tx.tx_h.ac_status = 0xFFFF; /* Fake completion value */
3413 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
3414 (unsigned char *) &tx.tx_h.ac_status,
3415 sizeof(tx.tx_h.ac_status));
3418 * NOP command
3420 nop.nop_h.ac_status = 0;
3421 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3422 (unsigned char *) &nop.nop_h.ac_status,
3423 sizeof(nop.nop_h.ac_status));
3424 nop.nop_h.ac_link = nop_addr;
3425 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3426 (unsigned char *) &nop.nop_h.ac_link,
3427 sizeof(nop.nop_h.ac_link));
3429 /* Create a configure action. */
3430 memset(&cfg, 0x00, sizeof(cfg));
3433 * For Linux we invert AC_CFG_ALOC() so as to conform
3434 * to the way that net packets reach us from above.
3435 * (See also ac_tx_t.)
3437 * Updated from Wavelan Manual WCIN085B
3439 cfg.cfg_byte_cnt =
3440 AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
3441 cfg.cfg_fifolim = AC_CFG_FIFOLIM(4);
3442 cfg.cfg_byte8 = AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0);
3443 cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
3444 AC_CFG_ILPBCK(0) |
3445 AC_CFG_PRELEN(AC_CFG_PLEN_2) |
3446 AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
3447 cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
3448 AC_CFG_ACR(6) | AC_CFG_LINPRIO(0);
3449 cfg.cfg_ifs = 0x20;
3450 cfg.cfg_slotl = 0x0C;
3451 cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0);
3452 cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
3453 AC_CFG_BTSTF(0) |
3454 AC_CFG_CRC16(0) |
3455 AC_CFG_NCRC(0) |
3456 AC_CFG_TNCRS(1) |
3457 AC_CFG_MANCH(0) |
3458 AC_CFG_BCDIS(0) | AC_CFG_PRM(lp->promiscuous);
3459 cfg.cfg_byte15 = AC_CFG_ICDS(0) |
3460 AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0);
3462 cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
3464 cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
3466 cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
3467 cfg.cfg_h.ac_link = ias_addr;
3468 obram_write(ioaddr, cfg_addr, (unsigned char *) &cfg, sizeof(cfg));
3470 /* Set up the MAC address */
3471 memset(&ias, 0x00, sizeof(ias));
3472 ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
3473 ias.ias_h.ac_link = mcs_addr;
3474 memcpy(&ias.ias_addr[0], (unsigned char *) &dev->dev_addr[0],
3475 sizeof(ias.ias_addr));
3476 obram_write(ioaddr, ias_addr, (unsigned char *) &ias, sizeof(ias));
3478 /* Initialize adapter's Ethernet multicast addresses */
3479 memset(&mcs, 0x00, sizeof(mcs));
3480 mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
3481 mcs.mcs_h.ac_link = nop_addr;
3482 mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
3483 obram_write(ioaddr, mcs_addr, (unsigned char *) &mcs, sizeof(mcs));
3485 /* Any address to set? */
3486 if (lp->mc_count) {
3487 for (dmi = dev->mc_list; dmi; dmi = dmi->next)
3488 outsw(PIOP1(ioaddr), (u16 *) dmi->dmi_addr,
3489 WAVELAN_ADDR_SIZE >> 1);
3491 #ifdef DEBUG_CONFIG_INFO
3492 printk(KERN_DEBUG
3493 "%s: wv_82586_config(): set %d multicast addresses:\n",
3494 dev->name, lp->mc_count);
3495 for (dmi = dev->mc_list; dmi; dmi = dmi->next)
3496 printk(KERN_DEBUG
3497 " %02x:%02x:%02x:%02x:%02x:%02x\n",
3498 dmi->dmi_addr[0], dmi->dmi_addr[1],
3499 dmi->dmi_addr[2], dmi->dmi_addr[3],
3500 dmi->dmi_addr[4], dmi->dmi_addr[5]);
3501 #endif
3505 * Overwrite the predecessor NOP link
3506 * so that it points to the configure action.
3508 nop_addr = txpred + sizeof(tx);
3509 nop.nop_h.ac_status = 0;
3510 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3511 (unsigned char *) &nop.nop_h.ac_status,
3512 sizeof(nop.nop_h.ac_status));
3513 nop.nop_h.ac_link = cfg_addr;
3514 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3515 (unsigned char *) &nop.nop_h.ac_link,
3516 sizeof(nop.nop_h.ac_link));
3518 /* Job done, clear the flag */
3519 lp->reconfig_82586 = 0;
3521 if (lp->tx_first_in_use == I82586NULL)
3522 lp->tx_first_in_use = txblock;
3524 if (lp->tx_n_in_use == (NTXBLOCKS - 1))
3525 netif_stop_queue(dev);
3527 wv_splx(lp, &flags);
3529 #ifdef DEBUG_CONFIG_TRACE
3530 printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
3531 #endif
3534 /*------------------------------------------------------------------*/
3536 * This routine, called by wavelan_close(), gracefully stops the
3537 * WaveLAN controller (i82586).
3539 static inline void wv_82586_stop(device * dev)
3541 net_local *lp = (net_local *) dev->priv;
3542 unsigned long ioaddr = dev->base_addr;
3543 u16 scb_cmd;
3545 #ifdef DEBUG_CONFIG_TRACE
3546 printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
3547 #endif
3549 /* Suspend both command unit and receive unit. */
3550 scb_cmd =
3551 (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC &
3552 SCB_CMD_RUC_SUS);
3553 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3554 (unsigned char *) &scb_cmd, sizeof(scb_cmd));
3555 set_chan_attn(ioaddr, lp->hacr);
3557 /* No more interrupts */
3558 wv_ints_off(dev);
3560 #ifdef DEBUG_CONFIG_TRACE
3561 printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
3562 #endif
3565 /*------------------------------------------------------------------*/
3567 * Totally reset the WaveLAN and restart it.
3568 * Performs the following actions:
3569 * 1. A power reset (reset DMA)
3570 * 2. Initialize the radio modem (using wv_mmc_init)
3571 * 3. Reset & Configure LAN controller (using wv_82586_start)
3572 * 4. Start the LAN controller's command unit
3573 * 5. Start the LAN controller's receive unit
3575 static int wv_hw_reset(device * dev)
3577 net_local *lp = (net_local *) dev->priv;
3578 unsigned long ioaddr = dev->base_addr;
3580 #ifdef DEBUG_CONFIG_TRACE
3581 printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
3582 (unsigned int) dev);
3583 #endif
3585 /* Increase the number of resets done. */
3586 lp->nresets++;
3588 wv_hacr_reset(ioaddr);
3589 lp->hacr = HACR_DEFAULT;
3591 if ((wv_mmc_init(dev) < 0) || (wv_82586_start(dev) < 0))
3592 return -1;
3594 /* Enable the card to send interrupts. */
3595 wv_ints_on(dev);
3597 /* Start card functions */
3598 if (wv_cu_start(dev) < 0)
3599 return -1;
3601 /* Setup the controller and parameters */
3602 wv_82586_config(dev);
3604 /* Finish configuration with the receive unit */
3605 if (wv_ru_start(dev) < 0)
3606 return -1;
3608 #ifdef DEBUG_CONFIG_TRACE
3609 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3610 #endif
3611 return 0;
3614 /*------------------------------------------------------------------*/
3616 * Check if there is a WaveLAN at the specific base address.
3617 * As a side effect, this reads the MAC address.
3618 * (called in wavelan_probe() and init_module())
3620 static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac)
3622 int i; /* Loop counter */
3624 /* Check if the base address if available. */
3625 if (check_region(ioaddr, sizeof(ha_t)))
3626 return EADDRINUSE; /* ioaddr already used */
3628 /* Reset host interface */
3629 wv_hacr_reset(ioaddr);
3631 /* Read the MAC address from the parameter storage area. */
3632 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
3633 mac, 6);
3636 * Check the first three octets of the address for the manufacturer's code.
3637 * Note: if this can't find your WaveLAN card, you've got a
3638 * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on
3639 * how to configure your card.
3641 for (i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3642 if ((mac[0] == MAC_ADDRESSES[i][0]) &&
3643 (mac[1] == MAC_ADDRESSES[i][1]) &&
3644 (mac[2] == MAC_ADDRESSES[i][2]))
3645 return 0;
3647 #ifdef DEBUG_CONFIG_INFO
3648 printk(KERN_WARNING
3649 "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
3650 ioaddr, mac[0], mac[1], mac[2]);
3651 #endif
3652 return ENODEV;
3655 /************************ INTERRUPT HANDLING ************************/
3658 * This function is the interrupt handler for the WaveLAN card. This
3659 * routine will be called whenever:
3661 static void wavelan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3663 device *dev;
3664 unsigned long ioaddr;
3665 net_local *lp;
3666 u16 hasr;
3667 u16 status;
3668 u16 ack_cmd;
3670 dev = dev_id;
3672 #ifdef DEBUG_INTERRUPT_TRACE
3673 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
3674 #endif
3676 lp = (net_local *) dev->priv;
3677 ioaddr = dev->base_addr;
3679 #ifdef DEBUG_INTERRUPT_ERROR
3680 /* Check state of our spinlock (it should be cleared) */
3681 if(spin_is_locked(&lp->spinlock))
3682 printk(KERN_INFO
3683 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
3684 dev->name);
3685 #endif
3687 /* Prevent reentrancy. It is safe because wv_splhi disable interrupts
3688 * before aquiring the spinlock */
3689 spin_lock(&lp->spinlock);
3691 /* Check modem interupt */
3692 if ((hasr = hasr_read(ioaddr)) & HASR_MMC_INTR) {
3693 u8 dce_status;
3696 * Interrupt from the modem management controller.
3697 * This will clear it -- ignored for now.
3699 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status,
3700 sizeof(dce_status));
3701 #ifdef DEBUG_INTERRUPT_ERROR
3702 printk(KERN_INFO
3703 "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
3704 dev->name, dce_status);
3705 #endif
3708 /* Check if not controller interrupt */
3709 if ((hasr & HASR_82586_INTR) == 0) {
3710 #ifdef DEBUG_INTERRUPT_ERROR
3711 printk(KERN_INFO
3712 "%s: wavelan_interrupt(): interrupt not coming from i82586\n",
3713 dev->name);
3714 #endif
3715 return;
3718 /* Read interrupt data. */
3719 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3720 (unsigned char *) &status, sizeof(status));
3723 * Acknowledge the interrupt(s).
3725 ack_cmd = status & SCB_ST_INT;
3726 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3727 (unsigned char *) &ack_cmd, sizeof(ack_cmd));
3728 set_chan_attn(ioaddr, lp->hacr);
3730 #ifdef DEBUG_INTERRUPT_INFO
3731 printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
3732 dev->name, status);
3733 #endif
3735 /* Command completed. */
3736 if ((status & SCB_ST_CX) == SCB_ST_CX) {
3737 #ifdef DEBUG_INTERRUPT_INFO
3738 printk(KERN_DEBUG
3739 "%s: wavelan_interrupt(): command completed.\n",
3740 dev->name);
3741 #endif
3742 wv_complete(dev, ioaddr, lp);
3745 /* Frame received. */
3746 if ((status & SCB_ST_FR) == SCB_ST_FR) {
3747 #ifdef DEBUG_INTERRUPT_INFO
3748 printk(KERN_DEBUG
3749 "%s: wavelan_interrupt(): received packet.\n",
3750 dev->name);
3751 #endif
3752 wv_receive(dev);
3755 /* Release spinlock here so that wv_hw_reset() can grab it */
3756 spin_unlock (&lp->spinlock);
3758 /* Check the state of the command unit. */
3759 if (((status & SCB_ST_CNA) == SCB_ST_CNA) ||
3760 (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) &&
3761 (netif_running(dev)))) {
3762 #ifdef DEBUG_INTERRUPT_ERROR
3763 printk(KERN_INFO
3764 "%s: wavelan_interrupt(): CU inactive -- restarting\n",
3765 dev->name);
3766 #endif
3767 wv_hw_reset(dev);
3770 /* Check the state of the command unit. */
3771 if (((status & SCB_ST_RNR) == SCB_ST_RNR) ||
3772 (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) &&
3773 (netif_running(dev)))) {
3774 #ifdef DEBUG_INTERRUPT_ERROR
3775 printk(KERN_INFO
3776 "%s: wavelan_interrupt(): RU not ready -- restarting\n",
3777 dev->name);
3778 #endif
3779 wv_hw_reset(dev);
3782 #ifdef DEBUG_INTERRUPT_TRACE
3783 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
3784 #endif
3787 /*------------------------------------------------------------------*/
3789 * Watchdog: when we start a transmission, a timer is set for us in the
3790 * kernel. If the transmission completes, this timer is disabled. If
3791 * the timer expires, we are called and we try to unlock the hardware.
3793 static void wavelan_watchdog(device * dev)
3795 net_local * lp = (net_local *)dev->priv;
3796 u_long ioaddr = dev->base_addr;
3797 unsigned long flags;
3798 unsigned int nreaped;
3800 #ifdef DEBUG_INTERRUPT_TRACE
3801 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
3802 #endif
3804 #ifdef DEBUG_INTERRUPT_ERROR
3805 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
3806 dev->name);
3807 #endif
3809 wv_splhi(lp, &flags);
3811 /* Check that we came here for something */
3812 if (lp->tx_n_in_use <= 0) {
3813 wv_splx(lp, &flags);
3814 return;
3817 /* Try to see if some buffers are not free (in case we missed
3818 * an interrupt */
3819 nreaped = wv_complete(dev, ioaddr, lp);
3821 #ifdef DEBUG_INTERRUPT_INFO
3822 printk(KERN_DEBUG
3823 "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
3824 dev->name, nreaped, lp->tx_n_in_use);
3825 #endif
3827 #ifdef DEBUG_PSA_SHOW
3829 psa_t psa;
3830 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3831 wv_psa_show(&psa);
3833 #endif
3834 #ifdef DEBUG_MMC_SHOW
3835 wv_mmc_show(dev);
3836 #endif
3837 #ifdef DEBUG_I82586_SHOW
3838 wv_cu_show(dev);
3839 #endif
3841 /* If no buffer has been freed */
3842 if (nreaped == 0) {
3843 #ifdef DEBUG_INTERRUPT_ERROR
3844 printk(KERN_INFO
3845 "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
3846 dev->name);
3847 #endif
3848 wv_hw_reset(dev);
3851 /* At this point, we should have some free Tx buffer ;-) */
3852 if (lp->tx_n_in_use < NTXBLOCKS - 1)
3853 netif_wake_queue(dev);
3855 wv_splx(lp, &flags);
3857 #ifdef DEBUG_INTERRUPT_TRACE
3858 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
3859 #endif
3862 /********************* CONFIGURATION CALLBACKS *********************/
3864 * Here are the functions called by the Linux networking code (NET3)
3865 * for initialization, configuration and deinstallations of the
3866 * WaveLAN ISA hardware.
3869 /*------------------------------------------------------------------*/
3871 * Configure and start up the WaveLAN PCMCIA adaptor.
3872 * Called by NET3 when it "opens" the device.
3874 static int wavelan_open(device * dev)
3876 net_local * lp = (net_local *)dev->priv;
3877 unsigned long flags;
3879 #ifdef DEBUG_CALLBACK_TRACE
3880 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
3881 (unsigned int) dev);
3882 #endif
3884 /* Check irq */
3885 if (dev->irq == 0) {
3886 #ifdef DEBUG_CONFIG_ERROR
3887 printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n",
3888 dev->name);
3889 #endif
3890 return -ENXIO;
3893 if (request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0)
3895 #ifdef DEBUG_CONFIG_ERROR
3896 printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n",
3897 dev->name);
3898 #endif
3899 return -EAGAIN;
3902 wv_splhi(lp, &flags);
3904 if (wv_hw_reset(dev) != -1) {
3905 netif_start_queue(dev);
3906 } else {
3907 free_irq(dev->irq, dev);
3908 #ifdef DEBUG_CONFIG_ERROR
3909 printk(KERN_INFO
3910 "%s: wavelan_open(): impossible to start the card\n",
3911 dev->name);
3912 #endif
3913 return -EAGAIN;
3915 wv_splx(lp, &flags);
3917 MOD_INC_USE_COUNT;
3919 #ifdef DEBUG_CALLBACK_TRACE
3920 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
3921 #endif
3922 return 0;
3925 /*------------------------------------------------------------------*/
3927 * Shut down the WaveLAN ISA card.
3928 * Called by NET3 when it "closes" the device.
3930 static int wavelan_close(device * dev)
3932 #ifdef DEBUG_CALLBACK_TRACE
3933 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
3934 (unsigned int) dev);
3935 #endif
3937 netif_stop_queue(dev);
3940 * Flush the Tx and disable Rx.
3942 wv_82586_stop(dev);
3944 free_irq(dev->irq, dev);
3946 MOD_DEC_USE_COUNT;
3948 #ifdef DEBUG_CALLBACK_TRACE
3949 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
3950 #endif
3951 return 0;
3954 /*------------------------------------------------------------------*/
3956 * Probe an I/O address, and if the WaveLAN is there configure the
3957 * device structure
3958 * (called by wavelan_probe() and via init_module()).
3960 static int __init wavelan_config(device * dev)
3962 unsigned long ioaddr = dev->base_addr;
3963 u8 irq_mask;
3964 int irq;
3965 net_local *lp;
3967 #ifdef DEBUG_CALLBACK_TRACE
3968 printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%x)\n",
3969 dev->name, (unsigned int) dev, ioaddr);
3970 #endif
3972 /* Check IRQ argument on command line. */
3973 if (dev->irq != 0) {
3974 irq_mask = wv_irq_to_psa(dev->irq);
3976 if (irq_mask == 0) {
3977 #ifdef DEBUG_CONFIG_ERROR
3978 printk(KERN_WARNING
3979 "%s: wavelan_config(): invalid IRQ %d ignored.\n",
3980 dev->name, dev->irq);
3981 #endif
3982 dev->irq = 0;
3983 } else {
3984 #ifdef DEBUG_CONFIG_INFO
3985 printk(KERN_DEBUG
3986 "%s: wavelan_config(): changing IRQ to %d\n",
3987 dev->name, dev->irq);
3988 #endif
3989 psa_write(ioaddr, HACR_DEFAULT,
3990 psaoff(0, psa_int_req_no), &irq_mask, 1);
3991 /* update the Wavelan checksum */
3992 update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
3993 wv_hacr_reset(ioaddr);
3997 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no),
3998 &irq_mask, 1);
3999 if ((irq = wv_psa_to_irq(irq_mask)) == -1) {
4000 #ifdef DEBUG_CONFIG_ERROR
4001 printk(KERN_INFO
4002 "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
4003 dev->name, irq_mask);
4004 #endif
4005 return EAGAIN;
4008 dev->irq = irq;
4010 request_region(ioaddr, sizeof(ha_t), "wavelan");
4012 dev->mem_start = 0x0000;
4013 dev->mem_end = 0x0000;
4014 dev->if_port = 0;
4016 /* Initialize device structures */
4017 dev->priv = kmalloc(sizeof(net_local), GFP_KERNEL);
4018 if (dev->priv == NULL)
4019 return -ENOMEM;
4020 memset(dev->priv, 0x00, sizeof(net_local));
4021 lp = (net_local *) dev->priv;
4023 /* Back link to the device structure. */
4024 lp->dev = dev;
4025 /* Add the device at the beginning of the linked list. */
4026 lp->next = wavelan_list;
4027 wavelan_list = lp;
4029 lp->hacr = HACR_DEFAULT;
4031 /* Multicast stuff */
4032 lp->promiscuous = 0;
4033 lp->mc_count = 0;
4035 /* Init spinlock */
4036 spin_lock_init(&lp->spinlock);
4039 * Fill in the fields of the device structure
4040 * with generic Ethernet values.
4042 ether_setup(dev);
4044 dev->open = wavelan_open;
4045 dev->stop = wavelan_close;
4046 dev->hard_start_xmit = wavelan_packet_xmit;
4047 dev->get_stats = wavelan_get_stats;
4048 dev->set_multicast_list = &wavelan_set_multicast_list;
4049 dev->tx_timeout = &wavelan_watchdog;
4050 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4051 #ifdef SET_MAC_ADDRESS
4052 dev->set_mac_address = &wavelan_set_mac_address;
4053 #endif /* SET_MAC_ADDRESS */
4055 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
4056 dev->do_ioctl = wavelan_ioctl;
4057 dev->get_wireless_stats = wavelan_get_wireless_stats;
4058 #endif
4060 dev->mtu = WAVELAN_MTU;
4062 /* Display nice information. */
4063 wv_init_info(dev);
4065 #ifdef DEBUG_CALLBACK_TRACE
4066 printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
4067 #endif
4068 return 0;
4071 /*------------------------------------------------------------------*/
4073 * Check for a network adaptor of this type. Return '0' iff one
4074 * exists. There seem to be different interpretations of
4075 * the initial value of dev->base_addr.
4076 * We follow the example in drivers/net/ne.c.
4077 * (called in "Space.c")
4079 int __init wavelan_probe(device * dev)
4081 short base_addr;
4082 mac_addr mac; /* MAC address (check existence of WaveLAN) */
4083 int i;
4084 int r;
4086 #ifdef DEBUG_CALLBACK_TRACE
4087 printk(KERN_DEBUG
4088 "%s: ->wavelan_probe(dev=0x%x (base_addr=0x%x))\n",
4089 dev->name, (unsigned int) dev,
4090 (unsigned int) dev->base_addr);
4091 #endif
4093 #ifdef STRUCT_CHECK
4094 if (wv_struct_check() != (char *) NULL) {
4095 printk(KERN_WARNING
4096 "%s: wavelan_probe(): structure/compiler botch: \"%s\"\n",
4097 dev->name, wv_struct_check());
4098 return ENODEV;
4100 #endif /* STRUCT_CHECK */
4102 /* Check the value of the command line parameter for base address. */
4103 base_addr = dev->base_addr;
4105 /* Don't probe at all. */
4106 if (base_addr < 0) {
4107 #ifdef DEBUG_CONFIG_ERROR
4108 printk(KERN_WARNING
4109 "%s: wavelan_probe(): invalid base address\n",
4110 dev->name);
4111 #endif
4112 return ENXIO;
4115 /* Check a single specified location. */
4116 if (base_addr > 0x100) {
4117 /* Check if there is something at this base address */
4118 if ((r = wv_check_ioaddr(base_addr, mac)) == 0) {
4119 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4120 r = wavelan_config(dev);
4122 #ifdef DEBUG_CONFIG_INFO
4123 if (r != 0)
4124 printk(KERN_DEBUG
4125 "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
4126 dev->name, base_addr);
4127 #endif
4129 #ifdef DEBUG_CALLBACK_TRACE
4130 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4131 #endif
4132 return r;
4135 /* Scan all possible addresses of the WaveLAN hardware. */
4136 for (i = 0; i < NELS(iobase); i++) {
4137 /* Check whether there is something at this base address. */
4138 if (wv_check_ioaddr(iobase[i], mac) == 0) {
4139 dev->base_addr = iobase[i]; /* Copy base address. */
4140 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4141 if (wavelan_config(dev) == 0) {
4142 #ifdef DEBUG_CALLBACK_TRACE
4143 printk(KERN_DEBUG
4144 "%s: <-wavelan_probe()\n",
4145 dev->name);
4146 #endif
4147 return 0;
4152 /* We may have touched base_addr. Another driver may not like it. */
4153 dev->base_addr = base_addr;
4155 #ifdef DEBUG_CONFIG_INFO
4156 printk(KERN_DEBUG "%s: wavelan_probe(): no device found\n",
4157 dev->name);
4158 #endif
4160 return ENODEV;
4163 /****************************** MODULE ******************************/
4165 * Module entry point: insertion and removal
4168 #ifdef MODULE
4169 /*------------------------------------------------------------------*/
4171 * Insertion of the module
4172 * I'm now quite proud of the multi-device support.
4174 int init_module(void)
4176 mac_addr mac; /* MAC address (check WaveLAN existence) */
4177 int ret = -EIO; /* Return error if no cards found */
4178 int i;
4180 #ifdef DEBUG_MODULE_TRACE
4181 printk(KERN_DEBUG "-> init_module()\n");
4182 #endif
4184 /* If probing is asked */
4185 if (io[0] == 0) {
4186 #ifdef DEBUG_CONFIG_ERROR
4187 printk(KERN_WARNING
4188 "WaveLAN init_module(): doing device probing (bad !)\n");
4189 printk(KERN_WARNING
4190 "Specify base addresses while loading module to correct the problem\n");
4191 #endif
4193 /* Copy the basic set of address to be probed. */
4194 for (i = 0; i < NELS(iobase); i++)
4195 io[i] = iobase[i];
4199 /* Loop on all possible base addresses. */
4200 i = -1;
4201 while ((io[++i] != 0) && (i < NELS(io))) {
4202 /* Check if there is something at this base address. */
4203 if (wv_check_ioaddr(io[i], mac) == 0) {
4204 device *dev;
4206 /* Create device and set basic arguments. */
4207 dev =
4208 kmalloc(sizeof(struct net_device), GFP_KERNEL);
4209 if (dev == NULL) {
4210 ret = -ENOMEM;
4211 break;
4213 memset(dev, 0x00, sizeof(struct net_device));
4214 dev->name = name[i];
4215 dev->base_addr = io[i];
4216 dev->irq = irq[i];
4217 dev->init = &wavelan_config;
4218 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4220 /* Try to create the device. */
4221 if (register_netdev(dev) != 0) {
4222 /* Deallocate everything. */
4223 /* Note: if dev->priv is mallocated, there is no way to fail. */
4224 kfree_s(dev, sizeof(struct net_device));
4225 } else {
4226 /* If at least one device OK, we do not fail */
4227 ret = 0;
4229 } /* if there is something at the address */
4230 } /* Loop on all addresses. */
4232 #ifdef DEBUG_CONFIG_ERROR
4233 if (wavelan_list == (net_local *) NULL)
4234 printk(KERN_WARNING
4235 "WaveLAN init_module(): no device found\n");
4236 #endif
4238 #ifdef DEBUG_MODULE_TRACE
4239 printk(KERN_DEBUG "<- init_module()\n");
4240 #endif
4241 return ret;
4244 /*------------------------------------------------------------------*/
4246 * Removal of the module
4248 void cleanup_module(void)
4250 #ifdef DEBUG_MODULE_TRACE
4251 printk(KERN_DEBUG "-> cleanup_module()\n");
4252 #endif
4254 /* Loop on all devices and release them. */
4255 while (wavelan_list != (net_local *) NULL) {
4256 device *dev = wavelan_list->dev;
4258 #ifdef DEBUG_CONFIG_INFO
4259 printk(KERN_DEBUG
4260 "%s: cleanup_module(): removing device at 0x%x\n",
4261 dev->name, (unsigned int) dev);
4262 #endif
4264 /* Release the ioport region. */
4265 release_region(dev->base_addr, sizeof(ha_t));
4267 /* Definitely remove the device. */
4268 unregister_netdev(dev);
4270 /* Unlink the device. */
4271 wavelan_list = wavelan_list->next;
4273 /* Free pieces. */
4274 kfree_s(dev->priv, sizeof(struct net_local));
4275 kfree_s(dev, sizeof(struct net_device));
4278 #ifdef DEBUG_MODULE_TRACE
4279 printk(KERN_DEBUG "<- cleanup_module()\n");
4280 #endif
4282 #endif /* MODULE */
4285 * This software may only be used and distributed
4286 * according to the terms of the GNU Public License.
4288 * This software was developed as a component of the
4289 * Linux operating system.
4290 * It is based on other device drivers and information
4291 * either written or supplied by:
4292 * Ajay Bakre (bakre@paul.rutgers.edu),
4293 * Donald Becker (becker@cesdis.gsfc.nasa.gov),
4294 * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
4295 * Anders Klemets (klemets@it.kth.se),
4296 * Vladimir V. Kolpakov (w@stier.koenig.ru),
4297 * Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
4298 * Pauline Middelink (middelin@polyware.iaf.nl),
4299 * Robert Morris (rtm@das.harvard.edu),
4300 * Jean Tourrilhes (jt@hplb.hpl.hp.com),
4301 * Girish Welling (welling@paul.rutgers.edu),
4303 * Thanks go also to:
4304 * James Ashton (jaa101@syseng.anu.edu.au),
4305 * Alan Cox (alan@redhat.com),
4306 * Allan Creighton (allanc@cs.usyd.edu.au),
4307 * Matthew Geier (matthew@cs.usyd.edu.au),
4308 * Remo di Giovanni (remo@cs.usyd.edu.au),
4309 * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
4310 * Vipul Gupta (vgupta@cs.binghamton.edu),
4311 * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
4312 * Tim Nicholson (tim@cs.usyd.edu.au),
4313 * Ian Parkin (ian@cs.usyd.edu.au),
4314 * John Rosenberg (johnr@cs.usyd.edu.au),
4315 * George Rossi (george@phm.gov.au),
4316 * Arthur Scott (arthur@cs.usyd.edu.au),
4317 * Peter Storey,
4318 * for their assistance and advice.
4320 * Please send bug reports, updates, comments to:
4322 * Bruce Janson Email: bruce@cs.usyd.edu.au
4323 * Basser Department of Computer Science Phone: +61-2-9351-3423
4324 * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838