The LDT fixes in particular fix some potentially random strange behaviour.
[davej-history.git] / drivers / net / wavelan.c
blob5c43c9a3abbdb7e7a18e41df9c6b341eeb262271
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.
176 * (called by wv_82586_stop())
178 static inline void wv_ints_off(device * dev)
180 net_local *lp = (net_local *) dev->priv;
181 unsigned long ioaddr = dev->base_addr;
183 lp->hacr &= ~HACR_INTRON;
184 hacr_write(ioaddr, lp->hacr);
185 } /* wv_ints_off */
187 /*------------------------------------------------------------------*/
189 * Enable interrupts on the WaveLAN hardware.
190 * (called by wv_hw_reset())
192 static inline void wv_ints_on(device * dev)
194 net_local *lp = (net_local *) dev->priv;
195 unsigned long ioaddr = dev->base_addr;
197 lp->hacr |= HACR_INTRON;
198 hacr_write(ioaddr, lp->hacr);
199 } /* wv_ints_on */
201 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
203 * Useful subroutines to manage the modem of the WaveLAN
206 /*------------------------------------------------------------------*/
208 * Read the Parameter Storage Area from the WaveLAN card's memory
211 * Read bytes from the PSA.
213 static void psa_read(unsigned long ioaddr, u16 hacr, int o, /* offset in PSA */
214 u8 * b, /* buffer to fill */
215 int n)
216 { /* size to read */
217 wv_16_off(ioaddr, hacr);
219 while (n-- > 0) {
220 outw(o, PIOR2(ioaddr));
221 o++;
222 *b++ = inb(PIOP2(ioaddr));
225 wv_16_on(ioaddr, hacr);
226 } /* psa_read */
228 /*------------------------------------------------------------------*/
230 * Write the Parameter Storage Area to the WaveLAN card's memory.
232 static void psa_write(unsigned long ioaddr, u16 hacr, int o, /* Offset in PSA */
233 u8 * b, /* Buffer in memory */
234 int n)
235 { /* Length of buffer */
236 int count = 0;
238 wv_16_off(ioaddr, hacr);
240 while (n-- > 0) {
241 outw(o, PIOR2(ioaddr));
242 o++;
244 outb(*b, PIOP2(ioaddr));
245 b++;
247 /* Wait for the memory to finish its write cycle */
248 count = 0;
249 while ((count++ < 100) &&
250 (hasr_read(ioaddr) & HASR_PSA_BUSY)) mdelay(1);
253 wv_16_on(ioaddr, hacr);
254 } /* psa_write */
256 #ifdef SET_PSA_CRC
257 /*------------------------------------------------------------------*/
259 * Calculate the PSA CRC
260 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
261 * NOTE: By specifying a length including the CRC position the
262 * returned value should be zero. (i.e. a correct checksum in the PSA)
264 * The Windows drivers don't use the CRC, but the AP and the PtP tool
265 * depend on it.
267 static inline u16 psa_crc(u8 * psa, /* The PSA */
268 int size)
269 { /* Number of short for CRC */
270 int byte_cnt; /* Loop on the PSA */
271 u16 crc_bytes = 0; /* Data in the PSA */
272 int bit_cnt; /* Loop on the bits of the short */
274 for (byte_cnt = 0; byte_cnt < size; byte_cnt++) {
275 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
277 for (bit_cnt = 1; bit_cnt < 9; bit_cnt++) {
278 if (crc_bytes & 0x0001)
279 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
280 else
281 crc_bytes >>= 1;
285 return crc_bytes;
286 } /* psa_crc */
287 #endif /* SET_PSA_CRC */
289 /*------------------------------------------------------------------*/
291 * update the checksum field in the Wavelan's PSA
293 static void update_psa_checksum(device * dev, unsigned long ioaddr, u16 hacr)
295 #ifdef SET_PSA_CRC
296 psa_t psa;
297 u16 crc;
299 /* read the parameter storage area */
300 psa_read(ioaddr, hacr, 0, (unsigned char *) &psa, sizeof(psa));
302 /* update the checksum */
303 crc = psa_crc((unsigned char *) &psa,
304 sizeof(psa) - sizeof(psa.psa_crc[0]) -
305 sizeof(psa.psa_crc[1])
306 - sizeof(psa.psa_crc_status));
308 psa.psa_crc[0] = crc & 0xFF;
309 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
311 /* Write it ! */
312 psa_write(ioaddr, hacr, (char *) &psa.psa_crc - (char *) &psa,
313 (unsigned char *) &psa.psa_crc, 2);
315 #ifdef DEBUG_IOCTL_INFO
316 printk(KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
317 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
319 /* Check again (luxury !) */
320 crc = psa_crc((unsigned char *) &psa,
321 sizeof(psa) - sizeof(psa.psa_crc_status));
323 if (crc != 0)
324 printk(KERN_WARNING
325 "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n",
326 dev->name);
327 #endif /* DEBUG_IOCTL_INFO */
328 #endif /* SET_PSA_CRC */
329 } /* update_psa_checksum */
331 /*------------------------------------------------------------------*/
333 * Write 1 byte to the MMC.
335 static inline void mmc_out(unsigned long ioaddr, u16 o, u8 d)
337 /* Wait for MMC to go idle */
338 while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
340 outw((u16) (((u16) d << 8) | (o << 1) | 1), MMCR(ioaddr));
343 /*------------------------------------------------------------------*/
345 * Routine to write bytes to the Modem Management Controller.
346 * We start at the end because it is the way it should be!
348 static inline void mmc_write(unsigned long ioaddr, u8 o, u8 * b, int n)
350 o += n;
351 b += n;
353 while (n-- > 0)
354 mmc_out(ioaddr, --o, *(--b));
355 } /* mmc_write */
357 /*------------------------------------------------------------------*/
359 * Read a byte from the MMC.
360 * Optimised version for 1 byte, avoid using memory.
362 static inline u8 mmc_in(unsigned long ioaddr, u16 o)
364 while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
365 outw(o << 1, MMCR(ioaddr));
367 while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
368 return (u8) (inw(MMCR(ioaddr)) >> 8);
371 /*------------------------------------------------------------------*/
373 * Routine to read bytes from the Modem Management Controller.
374 * The implementation is complicated by a lack of address lines,
375 * which prevents decoding of the low-order bit.
376 * (code has just been moved in the above function)
377 * We start at the end because it is the way it should be!
379 static inline void mmc_read(unsigned long ioaddr, u8 o, u8 * b, int n)
381 o += n;
382 b += n;
384 while (n-- > 0)
385 *(--b) = mmc_in(ioaddr, --o);
386 } /* mmc_read */
388 /*------------------------------------------------------------------*/
390 * Get the type of encryption available.
392 static inline int mmc_encr(unsigned long ioaddr)
393 { /* I/O port of the card */
394 int temp;
396 temp = mmc_in(ioaddr, mmroff(0, mmr_des_avail));
397 if ((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
398 return 0;
399 else
400 return temp;
403 /*------------------------------------------------------------------*/
405 * Wait for the frequency EEPROM to complete a command.
406 * I hope this one will be optimally inlined.
408 static inline void fee_wait(unsigned long ioaddr, /* I/O port of the card */
409 int delay, /* Base delay to wait for */
410 int number)
411 { /* Number of time to wait */
412 int count = 0; /* Wait only a limited time */
414 while ((count++ < number) &&
415 (mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
416 MMR_FEE_STATUS_BUSY)) udelay(delay);
419 /*------------------------------------------------------------------*/
421 * Read bytes from the Frequency EEPROM (frequency select cards).
423 static void fee_read(unsigned long ioaddr, /* I/O port of the card */
424 u16 o, /* destination offset */
425 u16 * b, /* data buffer */
426 int n)
427 { /* number of registers */
428 b += n; /* Position at the end of the area */
430 /* Write the address */
431 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
433 /* Loop on all buffer */
434 while (n-- > 0) {
435 /* Write the read command */
436 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
437 MMW_FEE_CTRL_READ);
439 /* Wait until EEPROM is ready (should be quick). */
440 fee_wait(ioaddr, 10, 100);
442 /* Read the value. */
443 *--b = ((mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)) << 8) |
444 mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
448 #ifdef WIRELESS_EXT /* if the wireless extension exists in the kernel */
450 /*------------------------------------------------------------------*/
452 * Write bytes from the Frequency EEPROM (frequency select cards).
453 * This is a bit complicated, because the frequency EEPROM has to
454 * be unprotected and the write enabled.
455 * Jean II
457 static void fee_write(unsigned long ioaddr, /* I/O port of the card */
458 u16 o, /* destination offset */
459 u16 * b, /* data buffer */
460 int n)
461 { /* number of registers */
462 b += n; /* Position at the end of the area. */
464 #ifdef EEPROM_IS_PROTECTED /* disabled */
465 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
466 /* Ask to read the protected register */
467 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
469 fee_wait(ioaddr, 10, 100);
471 /* Read the protected register. */
472 printk("Protected 2: %02X-%02X\n",
473 mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)),
474 mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
475 #endif /* DOESNT_SEEM_TO_WORK */
477 /* Enable protected register. */
478 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
479 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
481 fee_wait(ioaddr, 10, 100);
483 /* Unprotect area. */
484 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n);
485 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
486 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
487 /* or use: */
488 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
489 #endif /* DOESNT_SEEM_TO_WORK */
491 fee_wait(ioaddr, 10, 100);
492 #endif /* EEPROM_IS_PROTECTED */
494 /* Write enable. */
495 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
496 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
498 fee_wait(ioaddr, 10, 100);
500 /* Write the EEPROM address. */
501 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
503 /* Loop on all buffer */
504 while (n-- > 0) {
505 /* Write the value. */
506 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
507 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
509 /* Write the write command. */
510 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
511 MMW_FEE_CTRL_WRITE);
513 /* WaveLAN documentation says to wait at least 10 ms for EEBUSY = 0 */
514 mdelay(10);
515 fee_wait(ioaddr, 10, 100);
518 /* Write disable. */
519 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
520 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
522 fee_wait(ioaddr, 10, 100);
524 #ifdef EEPROM_IS_PROTECTED /* disabled */
525 /* Reprotect EEPROM. */
526 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x00);
527 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
529 fee_wait(ioaddr, 10, 100);
530 #endif /* EEPROM_IS_PROTECTED */
532 #endif /* WIRELESS_EXT */
534 /************************ I82586 SUBROUTINES *************************/
536 * Useful subroutines to manage the Ethernet controller
539 /*------------------------------------------------------------------*/
541 * Read bytes from the on-board RAM.
542 * Why does inlining this function make it fail?
544 static /*inline */ void obram_read(unsigned long ioaddr,
545 u16 o, u8 * b, int n)
547 outw(o, PIOR1(ioaddr));
548 insw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
551 /*------------------------------------------------------------------*/
553 * Write bytes to the on-board RAM.
555 static inline void obram_write(unsigned long ioaddr, u16 o, u8 * b, int n)
557 outw(o, PIOR1(ioaddr));
558 outsw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
561 /*------------------------------------------------------------------*/
563 * Acknowledge the reading of the status issued by the i82586.
565 static void wv_ack(device * dev)
567 net_local *lp = (net_local *) dev->priv;
568 unsigned long ioaddr = dev->base_addr;
569 u16 scb_cs;
570 int i;
572 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
573 (unsigned char *) &scb_cs, sizeof(scb_cs));
574 scb_cs &= SCB_ST_INT;
576 if (scb_cs == 0)
577 return;
579 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
580 (unsigned char *) &scb_cs, sizeof(scb_cs));
582 set_chan_attn(ioaddr, lp->hacr);
584 for (i = 1000; i > 0; i--) {
585 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
586 (unsigned char *) &scb_cs, sizeof(scb_cs));
587 if (scb_cs == 0)
588 break;
590 udelay(10);
592 udelay(100);
594 #ifdef DEBUG_CONFIG_ERROR
595 if (i <= 0)
596 printk(KERN_INFO
597 "%s: wv_ack(): board not accepting command.\n",
598 dev->name);
599 #endif
602 /*------------------------------------------------------------------*/
604 * Set channel attention bit and busy wait until command has
605 * completed, then acknowledge completion of the command.
607 static inline int wv_synchronous_cmd(device * dev, const char *str)
609 net_local *lp = (net_local *) dev->priv;
610 unsigned long ioaddr = dev->base_addr;
611 u16 scb_cmd;
612 ach_t cb;
613 int i;
615 scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO;
616 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
617 (unsigned char *) &scb_cmd, sizeof(scb_cmd));
619 set_chan_attn(ioaddr, lp->hacr);
621 for (i = 1000; i > 0; i--) {
622 obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb,
623 sizeof(cb));
624 if (cb.ac_status & AC_SFLD_C)
625 break;
627 udelay(10);
629 udelay(100);
631 if (i <= 0 || !(cb.ac_status & AC_SFLD_OK)) {
632 #ifdef DEBUG_CONFIG_ERROR
633 printk(KERN_INFO "%s: %s failed; status = 0x%x\n",
634 dev->name, str, cb.ac_status);
635 #endif
636 #ifdef DEBUG_I82586_SHOW
637 wv_scb_show(ioaddr);
638 #endif
639 return -1;
642 /* Ack the status */
643 wv_ack(dev);
645 return 0;
648 /*------------------------------------------------------------------*/
650 * Configuration commands completion interrupt.
651 * Check if done, and if OK.
653 static inline int
654 wv_config_complete(device * dev, unsigned long ioaddr, net_local * lp)
656 unsigned short mcs_addr;
657 unsigned short status;
658 int ret;
660 #ifdef DEBUG_INTERRUPT_TRACE
661 printk(KERN_DEBUG "%s: ->wv_config_complete()\n", dev->name);
662 #endif
664 mcs_addr = lp->tx_first_in_use + sizeof(ac_tx_t) + sizeof(ac_nop_t)
665 + sizeof(tbd_t) + sizeof(ac_cfg_t) + sizeof(ac_ias_t);
667 /* Read the status of the last command (set mc list). */
668 obram_read(ioaddr, acoff(mcs_addr, ac_status),
669 (unsigned char *) &status, sizeof(status));
671 /* If not completed -> exit */
672 if ((status & AC_SFLD_C) == 0)
673 ret = 0; /* Not ready to be scrapped */
674 else {
675 #ifdef DEBUG_CONFIG_ERROR
676 unsigned short cfg_addr;
677 unsigned short ias_addr;
679 /* Check mc_config command */
680 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
681 printk(KERN_INFO
682 "%s: wv_config_complete(): set_multicast_address failed; status = 0x%x\n",
683 dev->name, status);
685 /* check ia-config command */
686 ias_addr = mcs_addr - sizeof(ac_ias_t);
687 obram_read(ioaddr, acoff(ias_addr, ac_status),
688 (unsigned char *) &status, sizeof(status));
689 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
690 printk(KERN_INFO
691 "%s: wv_config_complete(): set_MAC_address failed; status = 0x%x\n",
692 dev->name, status);
694 /* Check config command. */
695 cfg_addr = ias_addr - sizeof(ac_cfg_t);
696 obram_read(ioaddr, acoff(cfg_addr, ac_status),
697 (unsigned char *) &status, sizeof(status));
698 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
699 printk(KERN_INFO
700 "%s: wv_config_complete(): configure failed; status = 0x%x\n",
701 dev->name, status);
702 #endif /* DEBUG_CONFIG_ERROR */
704 ret = 1; /* Ready to be scrapped */
707 #ifdef DEBUG_INTERRUPT_TRACE
708 printk(KERN_DEBUG "%s: <-wv_config_complete() - %d\n", dev->name,
709 ret);
710 #endif
711 return ret;
714 /*------------------------------------------------------------------*/
716 * Command completion interrupt.
717 * Reclaim as many freed tx buffers as we can.
718 * (called in wavelan_interrupt()).
719 * Note : the spinlock is already grabbed for us.
721 static int wv_complete(device * dev, unsigned long ioaddr, net_local * lp)
723 int nreaped = 0;
725 #ifdef DEBUG_INTERRUPT_TRACE
726 printk(KERN_DEBUG "%s: ->wv_complete()\n", dev->name);
727 #endif
729 /* Loop on all the transmit buffers */
730 while (lp->tx_first_in_use != I82586NULL) {
731 unsigned short tx_status;
733 /* Read the first transmit buffer */
734 obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status),
735 (unsigned char *) &tx_status,
736 sizeof(tx_status));
738 /* If not completed -> exit */
739 if ((tx_status & AC_SFLD_C) == 0)
740 break;
742 /* Hack for reconfiguration */
743 if (tx_status == 0xFFFF)
744 if (!wv_config_complete(dev, ioaddr, lp))
745 break; /* Not completed */
747 /* We now remove this buffer */
748 nreaped++;
749 --lp->tx_n_in_use;
752 if (lp->tx_n_in_use > 0)
753 printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
756 /* Was it the last one? */
757 if (lp->tx_n_in_use <= 0)
758 lp->tx_first_in_use = I82586NULL;
759 else {
760 /* Next one in the chain */
761 lp->tx_first_in_use += TXBLOCKZ;
762 if (lp->tx_first_in_use >=
763 OFFSET_CU +
764 NTXBLOCKS * TXBLOCKZ) lp->tx_first_in_use -=
765 NTXBLOCKS * TXBLOCKZ;
768 /* Hack for reconfiguration */
769 if (tx_status == 0xFFFF)
770 continue;
772 /* Now, check status of the finished command */
773 if (tx_status & AC_SFLD_OK) {
774 int ncollisions;
776 lp->stats.tx_packets++;
777 ncollisions = tx_status & AC_SFLD_MAXCOL;
778 lp->stats.collisions += ncollisions;
779 #ifdef DEBUG_TX_INFO
780 if (ncollisions > 0)
781 printk(KERN_DEBUG
782 "%s: wv_complete(): tx completed after %d collisions.\n",
783 dev->name, ncollisions);
784 #endif
785 } else {
786 lp->stats.tx_errors++;
787 if (tx_status & AC_SFLD_S10) {
788 lp->stats.tx_carrier_errors++;
789 #ifdef DEBUG_TX_FAIL
790 printk(KERN_DEBUG
791 "%s: wv_complete(): tx error: no CS.\n",
792 dev->name);
793 #endif
795 if (tx_status & AC_SFLD_S9) {
796 lp->stats.tx_carrier_errors++;
797 #ifdef DEBUG_TX_FAIL
798 printk(KERN_DEBUG
799 "%s: wv_complete(): tx error: lost CTS.\n",
800 dev->name);
801 #endif
803 if (tx_status & AC_SFLD_S8) {
804 lp->stats.tx_fifo_errors++;
805 #ifdef DEBUG_TX_FAIL
806 printk(KERN_DEBUG
807 "%s: wv_complete(): tx error: slow DMA.\n",
808 dev->name);
809 #endif
811 if (tx_status & AC_SFLD_S6) {
812 lp->stats.tx_heartbeat_errors++;
813 #ifdef DEBUG_TX_FAIL
814 printk(KERN_DEBUG
815 "%s: wv_complete(): tx error: heart beat.\n",
816 dev->name);
817 #endif
819 if (tx_status & AC_SFLD_S5) {
820 lp->stats.tx_aborted_errors++;
821 #ifdef DEBUG_TX_FAIL
822 printk(KERN_DEBUG
823 "%s: wv_complete(): tx error: too many collisions.\n",
824 dev->name);
825 #endif
829 #ifdef DEBUG_TX_INFO
830 printk(KERN_DEBUG
831 "%s: wv_complete(): tx completed, tx_status 0x%04x\n",
832 dev->name, tx_status);
833 #endif
836 #ifdef DEBUG_INTERRUPT_INFO
837 if (nreaped > 1)
838 printk(KERN_DEBUG "%s: wv_complete(): reaped %d\n",
839 dev->name, nreaped);
840 #endif
843 * Inform upper layers.
845 if (lp->tx_n_in_use < NTXBLOCKS - 1) {
846 netif_wake_queue(dev);
848 #ifdef DEBUG_INTERRUPT_TRACE
849 printk(KERN_DEBUG "%s: <-wv_complete()\n", dev->name);
850 #endif
851 return nreaped;
854 /*------------------------------------------------------------------*/
856 * Reconfigure the i82586, or at least ask for it.
857 * Because wv_82586_config uses a transmission buffer, we must do it
858 * when we are sure that there is one left, so we do it now
859 * or in wavelan_packet_xmit() (I can't find any better place,
860 * wavelan_interrupt is not an option), so you may experience
861 * delays sometimes.
863 static inline void wv_82586_reconfig(device * dev)
865 net_local *lp = (net_local *) dev->priv;
866 unsigned long flags;
868 /* Arm the flag, will be cleard in wv_82586_config() */
869 lp->reconfig_82586 = 1;
871 /* Check if we can do it now ! */
872 if((netif_running(dev)) && !(netif_queue_stopped(dev))) {
873 wv_splhi(lp, &flags);
874 /* May fail */
875 wv_82586_config(dev);
876 wv_splx(lp, &flags);
878 else {
879 #ifdef DEBUG_CONFIG_INFO
880 printk(KERN_DEBUG
881 "%s: wv_82586_reconfig(): delayed (state = %lX)\n",
882 dev->name, dev->state);
883 #endif
887 /********************* DEBUG & INFO SUBROUTINES *********************/
889 * This routine is used in the code to show information for debugging.
890 * Most of the time, it dumps the contents of hardware structures.
893 #ifdef DEBUG_PSA_SHOW
894 /*------------------------------------------------------------------*/
896 * Print the formatted contents of the Parameter Storage Area.
898 static void wv_psa_show(psa_t * p)
900 printk(KERN_DEBUG "##### WaveLAN PSA contents: #####\n");
901 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
902 p->psa_io_base_addr_1,
903 p->psa_io_base_addr_2,
904 p->psa_io_base_addr_3, p->psa_io_base_addr_4);
905 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
906 p->psa_rem_boot_addr_1,
907 p->psa_rem_boot_addr_2, p->psa_rem_boot_addr_3);
908 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
909 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
910 #ifdef DEBUG_SHOW_UNUSED
911 printk(KERN_DEBUG
912 "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
913 p->psa_unused0[0], p->psa_unused0[1], p->psa_unused0[2],
914 p->psa_unused0[3], p->psa_unused0[4], p->psa_unused0[5],
915 p->psa_unused0[6]);
916 #endif /* DEBUG_SHOW_UNUSED */
917 printk(KERN_DEBUG
918 "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
919 p->psa_univ_mac_addr[0], p->psa_univ_mac_addr[1],
920 p->psa_univ_mac_addr[2], p->psa_univ_mac_addr[3],
921 p->psa_univ_mac_addr[4], p->psa_univ_mac_addr[5]);
922 printk(KERN_DEBUG
923 "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
924 p->psa_local_mac_addr[0], p->psa_local_mac_addr[1],
925 p->psa_local_mac_addr[2], p->psa_local_mac_addr[3],
926 p->psa_local_mac_addr[4], p->psa_local_mac_addr[5]);
927 printk(KERN_DEBUG "psa_univ_local_sel: %d, ",
928 p->psa_univ_local_sel);
929 printk("psa_comp_number: %d, ", p->psa_comp_number);
930 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
931 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
932 p->psa_feature_select);
933 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
934 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
935 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
936 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0],
937 p->psa_nwid[1]);
938 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
939 printk(KERN_DEBUG "psa_encryption_select: %d, ",
940 p->psa_encryption_select);
941 printk
942 ("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
943 p->psa_encryption_key[0], p->psa_encryption_key[1],
944 p->psa_encryption_key[2], p->psa_encryption_key[3],
945 p->psa_encryption_key[4], p->psa_encryption_key[5],
946 p->psa_encryption_key[6], p->psa_encryption_key[7]);
947 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
948 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
949 p->psa_call_code[0]);
950 printk
951 ("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
952 p->psa_call_code[0], p->psa_call_code[1], p->psa_call_code[2],
953 p->psa_call_code[3], p->psa_call_code[4], p->psa_call_code[5],
954 p->psa_call_code[6], p->psa_call_code[7]);
955 #ifdef DEBUG_SHOW_UNUSED
956 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
957 p->psa_reserved[0],
958 p->psa_reserved[1], p->psa_reserved[2], p->psa_reserved[3]);
959 #endif /* DEBUG_SHOW_UNUSED */
960 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
961 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
962 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
963 } /* wv_psa_show */
964 #endif /* DEBUG_PSA_SHOW */
966 #ifdef DEBUG_MMC_SHOW
967 /*------------------------------------------------------------------*/
969 * Print the formatted status of the Modem Management Controller.
970 * This function needs to be completed.
972 static void wv_mmc_show(device * dev)
974 unsigned long ioaddr = dev->base_addr;
975 net_local *lp = (net_local *) dev->priv;
976 mmr_t m;
978 /* Basic check */
979 if (hasr_read(ioaddr) & HASR_NO_CLK) {
980 printk(KERN_WARNING
981 "%s: wv_mmc_show: modem not connected\n",
982 dev->name);
983 return;
986 /* Read the mmc */
987 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
988 mmc_read(ioaddr, 0, (u8 *) & m, sizeof(m));
989 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
991 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
992 /* Don't forget to update statistics */
993 lp->wstats.discard.nwid +=
994 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
995 #endif /* WIRELESS_EXT */
997 printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n");
998 #ifdef DEBUG_SHOW_UNUSED
999 printk(KERN_DEBUG
1000 "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1001 m.mmr_unused0[0], m.mmr_unused0[1], m.mmr_unused0[2],
1002 m.mmr_unused0[3], m.mmr_unused0[4], m.mmr_unused0[5],
1003 m.mmr_unused0[6], m.mmr_unused0[7]);
1004 #endif /* DEBUG_SHOW_UNUSED */
1005 printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
1006 m.mmr_des_avail, m.mmr_des_status);
1007 #ifdef DEBUG_SHOW_UNUSED
1008 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1009 m.mmr_unused1[0],
1010 m.mmr_unused1[1],
1011 m.mmr_unused1[2], m.mmr_unused1[3], m.mmr_unused1[4]);
1012 #endif /* DEBUG_SHOW_UNUSED */
1013 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1014 m.mmr_dce_status,
1016 mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ?
1017 "energy detected," : "",
1019 mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1020 "loop test indicated," : "",
1022 mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ?
1023 "transmitter on," : "",
1025 mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1026 "jabber timer expired," : "");
1027 printk(KERN_DEBUG "Dsp ID: %02X\n", m.mmr_dsp_id);
1028 #ifdef DEBUG_SHOW_UNUSED
1029 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1030 m.mmr_unused2[0], m.mmr_unused2[1]);
1031 #endif /* DEBUG_SHOW_UNUSED */
1032 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1033 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1034 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1035 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1036 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1038 mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" :
1039 "below");
1040 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1041 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1043 mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" :
1044 "no new msg");
1045 printk("silence_lvl: %d [%s], ",
1046 m.mmr_silence_lvl & MMR_SILENCE_LVL,
1048 mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" :
1049 "no new update");
1050 printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1052 mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" :
1053 "Antenna 0");
1054 #ifdef DEBUG_SHOW_UNUSED
1055 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1056 #endif /* DEBUG_SHOW_UNUSED */
1057 } /* wv_mmc_show */
1058 #endif /* DEBUG_MMC_SHOW */
1060 #ifdef DEBUG_I82586_SHOW
1061 /*------------------------------------------------------------------*/
1063 * Print the last block of the i82586 memory.
1065 static void wv_scb_show(unsigned long ioaddr)
1067 scb_t scb;
1069 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
1070 sizeof(scb));
1072 printk(KERN_DEBUG "##### WaveLAN system control block: #####\n");
1074 printk(KERN_DEBUG "status: ");
1075 printk("stat 0x%x[%s%s%s%s] ",
1076 (scb.
1077 scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA |
1078 SCB_ST_RNR)) >> 12,
1079 (scb.
1080 scb_status & SCB_ST_CX) ? "command completion interrupt," :
1081 "", (scb.scb_status & SCB_ST_FR) ? "frame received," : "",
1082 (scb.
1083 scb_status & SCB_ST_CNA) ? "command unit not active," : "",
1084 (scb.
1085 scb_status & SCB_ST_RNR) ? "receiving unit not ready," :
1086 "");
1087 printk("cus 0x%x[%s%s%s] ", (scb.scb_status & SCB_ST_CUS) >> 8,
1088 ((scb.scb_status & SCB_ST_CUS) ==
1089 SCB_ST_CUS_IDLE) ? "idle" : "",
1090 ((scb.scb_status & SCB_ST_CUS) ==
1091 SCB_ST_CUS_SUSP) ? "suspended" : "",
1092 ((scb.scb_status & SCB_ST_CUS) ==
1093 SCB_ST_CUS_ACTV) ? "active" : "");
1094 printk("rus 0x%x[%s%s%s%s]\n", (scb.scb_status & SCB_ST_RUS) >> 4,
1095 ((scb.scb_status & SCB_ST_RUS) ==
1096 SCB_ST_RUS_IDLE) ? "idle" : "",
1097 ((scb.scb_status & SCB_ST_RUS) ==
1098 SCB_ST_RUS_SUSP) ? "suspended" : "",
1099 ((scb.scb_status & SCB_ST_RUS) ==
1100 SCB_ST_RUS_NRES) ? "no resources" : "",
1101 ((scb.scb_status & SCB_ST_RUS) ==
1102 SCB_ST_RUS_RDY) ? "ready" : "");
1104 printk(KERN_DEBUG "command: ");
1105 printk("ack 0x%x[%s%s%s%s] ",
1106 (scb.
1107 scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR |
1108 SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12,
1109 (scb.
1110 scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "",
1111 (scb.
1112 scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "",
1113 (scb.
1114 scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "",
1115 (scb.
1116 scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : "");
1117 printk("cuc 0x%x[%s%s%s%s%s] ",
1118 (scb.scb_command & SCB_CMD_CUC) >> 8,
1119 ((scb.scb_command & SCB_CMD_CUC) ==
1120 SCB_CMD_CUC_NOP) ? "nop" : "",
1121 ((scb.scb_command & SCB_CMD_CUC) ==
1122 SCB_CMD_CUC_GO) ? "start cbl_offset" : "",
1123 ((scb.scb_command & SCB_CMD_CUC) ==
1124 SCB_CMD_CUC_RES) ? "resume execution" : "",
1125 ((scb.scb_command & SCB_CMD_CUC) ==
1126 SCB_CMD_CUC_SUS) ? "suspend execution" : "",
1127 ((scb.scb_command & SCB_CMD_CUC) ==
1128 SCB_CMD_CUC_ABT) ? "abort execution" : "");
1129 printk("ruc 0x%x[%s%s%s%s%s]\n",
1130 (scb.scb_command & SCB_CMD_RUC) >> 4,
1131 ((scb.scb_command & SCB_CMD_RUC) ==
1132 SCB_CMD_RUC_NOP) ? "nop" : "",
1133 ((scb.scb_command & SCB_CMD_RUC) ==
1134 SCB_CMD_RUC_GO) ? "start rfa_offset" : "",
1135 ((scb.scb_command & SCB_CMD_RUC) ==
1136 SCB_CMD_RUC_RES) ? "resume reception" : "",
1137 ((scb.scb_command & SCB_CMD_RUC) ==
1138 SCB_CMD_RUC_SUS) ? "suspend reception" : "",
1139 ((scb.scb_command & SCB_CMD_RUC) ==
1140 SCB_CMD_RUC_ABT) ? "abort reception" : "");
1142 printk(KERN_DEBUG "cbl_offset 0x%x ", scb.scb_cbl_offset);
1143 printk("rfa_offset 0x%x\n", scb.scb_rfa_offset);
1145 printk(KERN_DEBUG "crcerrs %d ", scb.scb_crcerrs);
1146 printk("alnerrs %d ", scb.scb_alnerrs);
1147 printk("rscerrs %d ", scb.scb_rscerrs);
1148 printk("ovrnerrs %d\n", scb.scb_ovrnerrs);
1151 /*------------------------------------------------------------------*/
1153 * Print the formatted status of the i82586's receive unit.
1155 static void wv_ru_show(device * dev)
1157 /* net_local *lp = (net_local *) dev->priv; */
1159 printk(KERN_DEBUG
1160 "##### WaveLAN i82586 receiver unit status: #####\n");
1161 printk(KERN_DEBUG "ru:");
1163 * Not implemented yet
1165 printk("\n");
1166 } /* wv_ru_show */
1168 /*------------------------------------------------------------------*/
1170 * Display info about one control block of the i82586 memory.
1172 static void wv_cu_show_one(device * dev, net_local * lp, int i, u16 p)
1174 unsigned long ioaddr;
1175 ac_tx_t actx;
1177 ioaddr = dev->base_addr;
1179 printk("%d: 0x%x:", i, p);
1181 obram_read(ioaddr, p, (unsigned char *) &actx, sizeof(actx));
1182 printk(" status=0x%x,", actx.tx_h.ac_status);
1183 printk(" command=0x%x,", actx.tx_h.ac_command);
1187 tbd_t tbd;
1189 obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
1190 printk(" tbd_status=0x%x,", tbd.tbd_status);
1194 printk("|");
1197 /*------------------------------------------------------------------*/
1199 * Print status of the command unit of the i82586.
1201 static void wv_cu_show(device * dev)
1203 net_local *lp = (net_local *) dev->priv;
1204 unsigned int i;
1205 u16 p;
1207 printk(KERN_DEBUG
1208 "##### WaveLAN i82586 command unit status: #####\n");
1210 printk(KERN_DEBUG);
1211 for (i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++) {
1212 wv_cu_show_one(dev, lp, i, p);
1214 p += TXBLOCKZ;
1215 if (p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
1216 p -= NTXBLOCKS * TXBLOCKZ;
1218 printk("\n");
1220 #endif /* DEBUG_I82586_SHOW */
1222 #ifdef DEBUG_DEVICE_SHOW
1223 /*------------------------------------------------------------------*/
1225 * Print the formatted status of the WaveLAN PCMCIA device driver.
1227 static void wv_dev_show(device * dev)
1229 printk(KERN_DEBUG "dev:");
1230 printk(" state=%lX,", dev->state);
1231 printk(" trans_start=%ld,", dev->trans_start);
1232 printk(" flags=0x%x,", dev->flags);
1233 printk("\n");
1234 } /* wv_dev_show */
1236 /*------------------------------------------------------------------*/
1238 * Print the formatted status of the WaveLAN PCMCIA device driver's
1239 * private information.
1241 static void wv_local_show(device * dev)
1243 net_local *lp;
1245 lp = (net_local *) dev->priv;
1247 printk(KERN_DEBUG "local:");
1248 printk(" tx_n_in_use=%d,", lp->tx_n_in_use);
1249 printk(" hacr=0x%x,", lp->hacr);
1250 printk(" rx_head=0x%x,", lp->rx_head);
1251 printk(" rx_last=0x%x,", lp->rx_last);
1252 printk(" tx_first_free=0x%x,", lp->tx_first_free);
1253 printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use);
1254 printk("\n");
1255 } /* wv_local_show */
1256 #endif /* DEBUG_DEVICE_SHOW */
1258 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1259 /*------------------------------------------------------------------*/
1261 * Dump packet header (and content if necessary) on the screen
1263 static inline void wv_packet_info(u8 * p, /* Packet to dump */
1264 int length, /* Length of the packet */
1265 char *msg1, /* Name of the device */
1266 char *msg2)
1267 { /* Name of the function */
1268 int i;
1269 int maxi;
1271 printk(KERN_DEBUG
1272 "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1273 msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1274 printk(KERN_DEBUG
1275 "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1276 msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12],
1277 p[13]);
1279 #ifdef DEBUG_PACKET_DUMP
1281 printk(KERN_DEBUG "data=\"");
1283 if ((maxi = length) > DEBUG_PACKET_DUMP)
1284 maxi = DEBUG_PACKET_DUMP;
1285 for (i = 14; i < maxi; i++)
1286 if (p[i] >= ' ' && p[i] <= '~')
1287 printk(" %c", p[i]);
1288 else
1289 printk("%02X", p[i]);
1290 if (maxi < length)
1291 printk("..");
1292 printk("\"\n");
1293 printk(KERN_DEBUG "\n");
1294 #endif /* DEBUG_PACKET_DUMP */
1296 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1298 /*------------------------------------------------------------------*/
1300 * This is the information which is displayed by the driver at startup.
1301 * There are lots of flags for configuring it to your liking.
1303 static inline void wv_init_info(device * dev)
1305 short ioaddr = dev->base_addr;
1306 net_local *lp = (net_local *) dev->priv;
1307 psa_t psa;
1308 int i;
1310 /* Read the parameter storage area */
1311 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
1313 #ifdef DEBUG_PSA_SHOW
1314 wv_psa_show(&psa);
1315 #endif
1316 #ifdef DEBUG_MMC_SHOW
1317 wv_mmc_show(dev);
1318 #endif
1319 #ifdef DEBUG_I82586_SHOW
1320 wv_cu_show(dev);
1321 #endif
1323 #ifdef DEBUG_BASIC_SHOW
1324 /* Now, let's go for the basic stuff. */
1325 printk(KERN_NOTICE "%s: WaveLAN at %#x,", dev->name, ioaddr);
1326 for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
1327 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1328 printk(", IRQ %d", dev->irq);
1330 /* Print current network ID. */
1331 if (psa.psa_nwid_select)
1332 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0],
1333 psa.psa_nwid[1]);
1334 else
1335 printk(", nwid off");
1337 /* If 2.00 card */
1338 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1339 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1340 unsigned short freq;
1342 /* Ask the EEPROM to read the frequency from the first area. */
1343 fee_read(ioaddr, 0x00, &freq, 1);
1345 /* Print frequency */
1346 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1348 /* Hack! */
1349 if (freq & 0x20)
1350 printk(".5");
1351 } else {
1352 printk(", PC");
1353 switch (psa.psa_comp_number) {
1354 case PSA_COMP_PC_AT_915:
1355 case PSA_COMP_PC_AT_2400:
1356 printk("-AT");
1357 break;
1358 case PSA_COMP_PC_MC_915:
1359 case PSA_COMP_PC_MC_2400:
1360 printk("-MC");
1361 break;
1362 case PSA_COMP_PCMCIA_915:
1363 printk("MCIA");
1364 break;
1365 default:
1366 printk("?");
1368 printk(", ");
1369 switch (psa.psa_subband) {
1370 case PSA_SUBBAND_915:
1371 printk("915");
1372 break;
1373 case PSA_SUBBAND_2425:
1374 printk("2425");
1375 break;
1376 case PSA_SUBBAND_2460:
1377 printk("2460");
1378 break;
1379 case PSA_SUBBAND_2484:
1380 printk("2484");
1381 break;
1382 case PSA_SUBBAND_2430_5:
1383 printk("2430.5");
1384 break;
1385 default:
1386 printk("?");
1390 printk(" MHz\n");
1391 #endif /* DEBUG_BASIC_SHOW */
1393 #ifdef DEBUG_VERSION_SHOW
1394 /* Print version information */
1395 printk(KERN_NOTICE "%s", version);
1396 #endif
1397 } /* wv_init_info */
1399 /********************* IOCTL, STATS & RECONFIG *********************/
1401 * We found here routines that are called by Linux on different
1402 * occasions after the configuration and not for transmitting data
1403 * These may be called when the user use ifconfig, /proc/net/dev
1404 * or wireless extensions
1407 /*------------------------------------------------------------------*/
1409 * Get the current Ethernet statistics. This may be called with the
1410 * card open or closed.
1411 * Used when the user read /proc/net/dev
1413 static en_stats *wavelan_get_stats(device * dev)
1415 #ifdef DEBUG_IOCTL_TRACE
1416 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1417 #endif
1419 return (&((net_local *) dev->priv)->stats);
1422 /*------------------------------------------------------------------*/
1424 * Set or clear the multicast filter for this adaptor.
1425 * num_addrs == -1 Promiscuous mode, receive all packets
1426 * num_addrs == 0 Normal mode, clear multicast list
1427 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1428 * and do best-effort filtering.
1430 static void wavelan_set_multicast_list(device * dev)
1432 net_local *lp = (net_local *) dev->priv;
1434 #ifdef DEBUG_IOCTL_TRACE
1435 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n",
1436 dev->name);
1437 #endif
1439 #ifdef DEBUG_IOCTL_INFO
1440 printk(KERN_DEBUG
1441 "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1442 dev->name, dev->flags, dev->mc_count);
1443 #endif
1445 /* Are we asking for promiscuous mode,
1446 * or all multicast addresses (we don't have that!)
1447 * or too many multicast addresses for the hardware filter? */
1448 if ((dev->flags & IFF_PROMISC) ||
1449 (dev->flags & IFF_ALLMULTI) ||
1450 (dev->mc_count > I82586_MAX_MULTICAST_ADDRESSES)) {
1452 * Enable promiscuous mode: receive all packets.
1454 if (!lp->promiscuous) {
1455 lp->promiscuous = 1;
1456 lp->mc_count = 0;
1458 wv_82586_reconfig(dev);
1460 /* Tell the kernel that we are doing a really bad job. */
1461 dev->flags |= IFF_PROMISC;
1463 } else
1464 /* Are there multicast addresses to send? */
1465 if (dev->mc_list != (struct dev_mc_list *) NULL) {
1467 * Disable promiscuous mode, but receive all packets
1468 * in multicast list
1470 #ifdef MULTICAST_AVOID
1471 if (lp->promiscuous || (dev->mc_count != lp->mc_count))
1472 #endif
1474 lp->promiscuous = 0;
1475 lp->mc_count = dev->mc_count;
1477 wv_82586_reconfig(dev);
1479 } else {
1481 * Switch to normal mode: disable promiscuous mode and
1482 * clear the multicast list.
1484 if (lp->promiscuous || lp->mc_count == 0) {
1485 lp->promiscuous = 0;
1486 lp->mc_count = 0;
1488 wv_82586_reconfig(dev);
1491 #ifdef DEBUG_IOCTL_TRACE
1492 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n",
1493 dev->name);
1494 #endif
1497 /*------------------------------------------------------------------*/
1499 * This function doesn't exist.
1500 * (Note : it was a nice way to test the reconfigure stuff...)
1502 #ifdef SET_MAC_ADDRESS
1503 static int wavelan_set_mac_address(device * dev, void *addr)
1505 struct sockaddr *mac = addr;
1507 /* Copy the address. */
1508 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1510 /* Reconfigure the beast. */
1511 wv_82586_reconfig(dev);
1513 return 0;
1515 #endif /* SET_MAC_ADDRESS */
1517 #ifdef WIRELESS_EXT /* if wireless extensions exist in the kernel */
1519 /*------------------------------------------------------------------*/
1521 * Frequency setting (for hardware capable of it)
1522 * It's a bit complicated and you don't really want to look into it.
1523 * (called in wavelan_ioctl)
1525 static inline int wv_set_frequency(unsigned long ioaddr, /* I/O port of the card */
1526 iw_freq * frequency)
1528 const int BAND_NUM = 10; /* Number of bands */
1529 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1530 #ifdef DEBUG_IOCTL_INFO
1531 int i;
1532 #endif
1534 /* Setting by frequency */
1535 /* Theoretically, you may set any frequency between
1536 * the two limits with a 0.5 MHz precision. In practice,
1537 * I don't want you to have trouble with local regulations.
1539 if ((frequency->e == 1) &&
1540 (frequency->m >= (int) 2.412e8)
1541 && (frequency->m <= (int) 2.487e8)) {
1542 freq = ((frequency->m / 10000) - 24000L) / 5;
1545 /* Setting by channel (same as wfreqsel) */
1546 /* Warning: each channel is 22 MHz wide, so some of the channels
1547 * will interfere. */
1548 if ((frequency->e == 0) &&
1549 (frequency->m >= 0) && (frequency->m < BAND_NUM)) {
1550 /* Get frequency offset. */
1551 freq = channel_bands[frequency->m] >> 1;
1554 /* Verify that the frequency is allowed. */
1555 if (freq != 0L) {
1556 u16 table[10]; /* Authorized frequency table */
1558 /* Read the frequency table. */
1559 fee_read(ioaddr, 0x71, table, 10);
1561 #ifdef DEBUG_IOCTL_INFO
1562 printk(KERN_DEBUG "Frequency table: ");
1563 for (i = 0; i < 10; i++) {
1564 printk(" %04X", table[i]);
1566 printk("\n");
1567 #endif
1569 /* Look in the table to see whether the frequency is allowed. */
1570 if (!(table[9 - ((freq - 24) / 16)] &
1571 (1 << ((freq - 24) % 16)))) return -EINVAL; /* not allowed */
1572 } else
1573 return -EINVAL;
1575 /* if we get a usable frequency */
1576 if (freq != 0L) {
1577 unsigned short area[16];
1578 unsigned short dac[2];
1579 unsigned short area_verify[16];
1580 unsigned short dac_verify[2];
1581 /* Corresponding gain (in the power adjust value table)
1582 * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8
1583 * and WCIN062D.DOC, page 6.2.9. */
1584 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1585 int power_band = 0; /* Selected band */
1586 unsigned short power_adjust; /* Correct value */
1588 /* Search for the gain. */
1589 power_band = 0;
1590 while ((freq > power_limit[power_band]) &&
1591 (power_limit[++power_band] != 0));
1593 /* Read the first area. */
1594 fee_read(ioaddr, 0x00, area, 16);
1596 /* Read the DAC. */
1597 fee_read(ioaddr, 0x60, dac, 2);
1599 /* Read the new power adjust value. */
1600 fee_read(ioaddr, 0x6B - (power_band >> 1), &power_adjust,
1602 if (power_band & 0x1)
1603 power_adjust >>= 8;
1604 else
1605 power_adjust &= 0xFF;
1607 #ifdef DEBUG_IOCTL_INFO
1608 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1609 for (i = 0; i < 16; i++) {
1610 printk(" %04X", area[i]);
1612 printk("\n");
1614 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1615 dac[0], dac[1]);
1616 #endif
1618 /* Frequency offset (for info only) */
1619 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1621 /* Receiver Principle main divider coefficient */
1622 area[3] = (freq >> 1) + 2400L - 352L;
1623 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1625 /* Transmitter Main divider coefficient */
1626 area[13] = (freq >> 1) + 2400L;
1627 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1629 /* Other parts of the area are flags, bit streams or unused. */
1631 /* Set the value in the DAC. */
1632 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1633 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1635 /* Write the first area. */
1636 fee_write(ioaddr, 0x00, area, 16);
1638 /* Write the DAC. */
1639 fee_write(ioaddr, 0x60, dac, 2);
1641 /* We now should verify here that the writing of the EEPROM went OK. */
1643 /* Reread the first area. */
1644 fee_read(ioaddr, 0x00, area_verify, 16);
1646 /* Reread the DAC. */
1647 fee_read(ioaddr, 0x60, dac_verify, 2);
1649 /* Compare. */
1650 if (memcmp(area, area_verify, 16 * 2) ||
1651 memcmp(dac, dac_verify, 2 * 2)) {
1652 #ifdef DEBUG_IOCTL_ERROR
1653 printk(KERN_INFO
1654 "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n");
1655 #endif
1656 return -EOPNOTSUPP;
1659 /* We must download the frequency parameters to the
1660 * synthesizers (from the EEPROM - area 1)
1661 * Note: as the EEPROM is automatically decremented, we set the end
1662 * if the area... */
1663 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x0F);
1664 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1665 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1667 /* Wait until the download is finished. */
1668 fee_wait(ioaddr, 100, 100);
1670 /* We must now download the power adjust value (gain) to
1671 * the synthesizers (from the EEPROM - area 7 - DAC). */
1672 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x61);
1673 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1674 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1676 /* Wait for the download to finish. */
1677 fee_wait(ioaddr, 100, 100);
1679 #ifdef DEBUG_IOCTL_INFO
1680 /* Verification of what we have done */
1682 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1683 for (i = 0; i < 16; i++) {
1684 printk(" %04X", area_verify[i]);
1686 printk("\n");
1688 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1689 dac_verify[0], dac_verify[1]);
1690 #endif
1692 return 0;
1693 } else
1694 return -EINVAL; /* Bah, never get there... */
1697 /*------------------------------------------------------------------*/
1699 * Give the list of available frequencies.
1701 static inline int wv_frequency_list(unsigned long ioaddr, /* I/O port of the card */
1702 iw_freq * list, /* List of frequencies to fill */
1703 int max)
1704 { /* Maximum number of frequencies */
1705 u16 table[10]; /* Authorized frequency table */
1706 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1707 int i; /* index in the table */
1708 int c = 0; /* Channel number */
1710 /* Read the frequency table. */
1711 fee_read(ioaddr, 0x71 /* frequency table */ , table, 10);
1713 /* Check all frequencies. */
1714 i = 0;
1715 for (freq = 0; freq < 150; freq++)
1716 /* Look in the table if the frequency is allowed */
1717 if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
1718 /* Compute approximate channel number */
1719 while ((((channel_bands[c] >> 1) - 24) < freq) &&
1720 (c < NELS(channel_bands)))
1721 c++;
1722 list[i].i = c; /* Set the list index */
1724 /* put in the list */
1725 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1726 list[i++].e = 1;
1728 /* Check number. */
1729 if (i >= max)
1730 return (i);
1733 return (i);
1736 #ifdef WIRELESS_SPY
1737 /*------------------------------------------------------------------*/
1739 * Gather wireless spy statistics: for each packet, compare the source
1740 * address with our list, and if they match, get the statistics.
1741 * Sorry, but this function really needs the wireless extensions.
1743 static inline void wl_spy_gather(device * dev, u8 * mac, /* MAC address */
1744 u8 * stats)
1745 { /* Statistics to gather */
1746 net_local *lp = (net_local *) dev->priv;
1747 int i;
1749 /* Check all addresses. */
1750 for (i = 0; i < lp->spy_number; i++)
1751 /* If match */
1752 if (!memcmp(mac, lp->spy_address[i], WAVELAN_ADDR_SIZE)) {
1753 /* Update statistics */
1754 lp->spy_stat[i].qual = stats[2] & MMR_SGNL_QUAL;
1755 lp->spy_stat[i].level = stats[0] & MMR_SIGNAL_LVL;
1756 lp->spy_stat[i].noise = stats[1] & MMR_SILENCE_LVL;
1757 lp->spy_stat[i].updated = 0x7;
1760 #endif /* WIRELESS_SPY */
1762 #ifdef HISTOGRAM
1763 /*------------------------------------------------------------------*/
1765 * This function calculates a histogram of the signal level.
1766 * As the noise is quite constant, it's like doing it on the SNR.
1767 * We have defined a set of interval (lp->his_range), and each time
1768 * the level goes in that interval, we increment the count (lp->his_sum).
1769 * With this histogram you may detect if one WaveLAN is really weak,
1770 * or you may also calculate the mean and standard deviation of the level.
1772 static inline void wl_his_gather(device * dev, u8 * stats)
1773 { /* Statistics to gather */
1774 net_local *lp = (net_local *) dev->priv;
1775 u8 level = stats[0] & MMR_SIGNAL_LVL;
1776 int i;
1778 /* Find the correct interval. */
1779 i = 0;
1780 while ((i < (lp->his_number - 1))
1781 && (level >= lp->his_range[i++]));
1783 /* Increment interval counter. */
1784 (lp->his_sum[i])++;
1786 #endif /* HISTOGRAM */
1788 /*------------------------------------------------------------------*/
1790 * Perform ioctl for configuration and information.
1791 * It is here that the wireless extensions are treated (iwconfig).
1793 static int wavelan_ioctl(struct net_device *dev, /* device on which the ioctl is applied */
1794 struct ifreq *rq, /* data passed */
1795 int cmd)
1796 { /* ioctl number */
1797 unsigned long ioaddr = dev->base_addr;
1798 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
1799 struct iwreq *wrq = (struct iwreq *) rq;
1800 psa_t psa;
1801 mm_t m;
1802 unsigned long flags;
1803 int ret = 0;
1804 int err = 0;
1806 #ifdef DEBUG_IOCTL_TRACE
1807 printk(KERN_DEBUG "%s: ->wavelan_ioctl(cmd=0x%X)\n", dev->name,
1808 cmd);
1809 #endif
1811 /* Disable interrupts and save flags. */
1812 wv_splhi(lp, &flags);
1814 /* Look what is the request */
1815 switch (cmd) {
1816 /* --------------- WIRELESS EXTENSIONS --------------- */
1818 case SIOCGIWNAME:
1819 strcpy(wrq->u.name, "WaveLAN");
1820 break;
1822 case SIOCSIWNWID:
1823 /* Set NWID in WaveLAN. */
1824 if (!wrq->u.nwid.disabled) {
1825 /* Set NWID in psa */
1826 psa.psa_nwid[0] =
1827 (wrq->u.nwid.value & 0xFF00) >> 8;
1828 psa.psa_nwid[1] = wrq->u.nwid.value & 0xFF;
1829 psa.psa_nwid_select = 0x01;
1830 psa_write(ioaddr, lp->hacr,
1831 (char *) psa.psa_nwid - (char *) &psa,
1832 (unsigned char *) psa.psa_nwid, 3);
1834 /* Set NWID in mmc. */
1835 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1836 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1837 mmc_write(ioaddr,
1838 (char *) &m.w.mmw_netw_id_l -
1839 (char *) &m,
1840 (unsigned char *) &m.w.mmw_netw_id_l, 2);
1841 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), 0x00);
1842 } else {
1843 /* Disable NWID in the psa. */
1844 psa.psa_nwid_select = 0x00;
1845 psa_write(ioaddr, lp->hacr,
1846 (char *) &psa.psa_nwid_select -
1847 (char *) &psa,
1848 (unsigned char *) &psa.psa_nwid_select,
1851 /* Disable NWID in the mmc (no filtering). */
1852 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel),
1853 MMW_LOOPT_SEL_DIS_NWID);
1855 /* update the Wavelan checksum */
1856 update_psa_checksum(dev, ioaddr, lp->hacr);
1857 break;
1859 case SIOCGIWNWID:
1860 /* Read the NWID. */
1861 psa_read(ioaddr, lp->hacr,
1862 (char *) psa.psa_nwid - (char *) &psa,
1863 (unsigned char *) psa.psa_nwid, 3);
1864 wrq->u.nwid.value =
1865 (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1866 wrq->u.nwid.disabled = !(psa.psa_nwid_select);
1867 wrq->u.nwid.fixed = 1; /* Superfluous */
1868 break;
1870 case SIOCSIWFREQ:
1871 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1872 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1873 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1874 ret = wv_set_frequency(ioaddr, &(wrq->u.freq));
1875 else
1876 ret = -EOPNOTSUPP;
1877 break;
1879 case SIOCGIWFREQ:
1880 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
1881 * Does it work for everybody, especially old cards? */
1882 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1883 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1884 unsigned short freq;
1886 /* Ask the EEPROM to read the frequency from the first area. */
1887 fee_read(ioaddr, 0x00, &freq, 1);
1888 wrq->u.freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
1889 wrq->u.freq.e = 1;
1890 } else {
1891 psa_read(ioaddr, lp->hacr,
1892 (char *) &psa.psa_subband - (char *) &psa,
1893 (unsigned char *) &psa.psa_subband, 1);
1895 if (psa.psa_subband <= 4) {
1896 wrq->u.freq.m =
1897 fixed_bands[psa.psa_subband];
1898 wrq->u.freq.e = (psa.psa_subband != 0);
1899 } else
1900 ret = -EOPNOTSUPP;
1902 break;
1904 case SIOCSIWSENS:
1905 /* Set the level threshold. */
1906 /* We should complain loudly if wrq->u.sens.fixed = 0, because we
1907 * can't set auto mode... */
1908 psa.psa_thr_pre_set = wrq->u.sens.value & 0x3F;
1909 psa_write(ioaddr, lp->hacr,
1910 (char *) &psa.psa_thr_pre_set - (char *) &psa,
1911 (unsigned char *) &psa.psa_thr_pre_set, 1);
1912 /* update the Wavelan checksum */
1913 update_psa_checksum(dev, ioaddr, lp->hacr);
1914 mmc_out(ioaddr, mmwoff(0, mmw_thr_pre_set),
1915 psa.psa_thr_pre_set);
1916 break;
1918 case SIOCGIWSENS:
1919 /* Read the level threshold. */
1920 psa_read(ioaddr, lp->hacr,
1921 (char *) &psa.psa_thr_pre_set - (char *) &psa,
1922 (unsigned char *) &psa.psa_thr_pre_set, 1);
1923 wrq->u.sens.value = psa.psa_thr_pre_set & 0x3F;
1924 wrq->u.sens.fixed = 1;
1925 break;
1927 case SIOCSIWENCODE:
1928 /* Set encryption key */
1929 if (!mmc_encr(ioaddr)) {
1930 ret = -EOPNOTSUPP;
1931 break;
1934 /* Basic checking... */
1935 if (wrq->u.encoding.pointer != (caddr_t) 0) {
1936 /* Check the size of the key */
1937 if (wrq->u.encoding.length != 8) {
1938 ret = -EINVAL;
1939 break;
1942 /* Copy the key in the driver */
1943 wv_splx(lp, &flags);
1944 err = copy_from_user(psa.psa_encryption_key,
1945 wrq->u.encoding.pointer,
1946 wrq->u.encoding.length);
1947 wv_splhi(lp, &flags);
1948 if (err) {
1949 ret = -EFAULT;
1950 break;
1953 psa.psa_encryption_select = 1;
1954 psa_write(ioaddr, lp->hacr,
1955 (char *) &psa.psa_encryption_select -
1956 (char *) &psa,
1957 (unsigned char *) &psa.
1958 psa_encryption_select, 8 + 1);
1960 mmc_out(ioaddr, mmwoff(0, mmw_encr_enable),
1961 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
1962 mmc_write(ioaddr, mmwoff(0, mmw_encr_key),
1963 (unsigned char *) &psa.
1964 psa_encryption_key, 8);
1967 if (wrq->u.encoding.flags & IW_ENCODE_DISABLED) { /* disable encryption */
1968 psa.psa_encryption_select = 0;
1969 psa_write(ioaddr, lp->hacr,
1970 (char *) &psa.psa_encryption_select -
1971 (char *) &psa,
1972 (unsigned char *) &psa.
1973 psa_encryption_select, 1);
1975 mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), 0);
1977 /* update the Wavelan checksum */
1978 update_psa_checksum(dev, ioaddr, lp->hacr);
1979 break;
1981 case SIOCGIWENCODE:
1982 /* Read the encryption key */
1983 if (!mmc_encr(ioaddr)) {
1984 ret = -EOPNOTSUPP;
1985 break;
1988 /* only super-user can see encryption key */
1989 if (!capable(CAP_NET_ADMIN)) {
1990 ret = -EPERM;
1991 break;
1994 /* Basic checking... */
1995 if (wrq->u.encoding.pointer != (caddr_t) 0) {
1996 /* Verify the user buffer */
1997 ret =
1998 verify_area(VERIFY_WRITE,
1999 wrq->u.encoding.pointer, 8);
2000 if (ret)
2001 break;
2003 psa_read(ioaddr, lp->hacr,
2004 (char *) &psa.psa_encryption_select -
2005 (char *) &psa,
2006 (unsigned char *) &psa.
2007 psa_encryption_select, 1 + 8);
2009 /* encryption is enabled ? */
2010 if (psa.psa_encryption_select)
2011 wrq->u.encoding.flags = IW_ENCODE_ENABLED;
2012 else
2013 wrq->u.encoding.flags = IW_ENCODE_DISABLED;
2014 wrq->u.encoding.flags |= mmc_encr(ioaddr);
2016 /* Copy the key to the user buffer */
2017 wrq->u.encoding.length = 8;
2018 wv_splx(lp, &flags);
2019 if (copy_to_user(wrq->u.encoding.pointer,
2020 psa.psa_encryption_key, 8))
2021 ret = -EFAULT;
2022 wv_splhi(lp, &flags);
2024 break;
2026 case SIOCGIWRANGE:
2027 /* basic checking */
2028 if (wrq->u.data.pointer != (caddr_t) 0) {
2029 struct iw_range range;
2031 /* Set the length (useless: it's constant). */
2032 wrq->u.data.length = sizeof(struct iw_range);
2034 /* Set information in the range struct. */
2035 range.throughput = 1.6 * 1000 * 1000; /* don't argue on this ! */
2036 range.min_nwid = 0x0000;
2037 range.max_nwid = 0xFFFF;
2039 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2040 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2041 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2042 range.num_channels = 10;
2043 range.num_frequency =
2044 wv_frequency_list(ioaddr, range.freq,
2045 IW_MAX_FREQUENCIES);
2046 } else
2047 range.num_channels = range.num_frequency =
2050 range.sensitivity = 0x3F;
2051 range.max_qual.qual = MMR_SGNL_QUAL;
2052 range.max_qual.level = MMR_SIGNAL_LVL;
2053 range.max_qual.noise = MMR_SILENCE_LVL;
2055 range.num_bitrates = 1;
2056 range.bitrate[0] = 2000000; /* 2 Mb/s */
2058 /* Encryption supported ? */
2059 if (mmc_encr(ioaddr)) {
2060 range.encoding_size[0] = 8; /* DES = 64 bits key */
2061 range.num_encoding_sizes = 1;
2062 range.max_encoding_tokens = 1; /* Only one key possible */
2063 } else {
2064 range.num_encoding_sizes = 0;
2065 range.max_encoding_tokens = 0;
2068 /* Copy structure to the user buffer. */
2069 wv_splx(lp, &flags);
2070 if (copy_to_user(wrq->u.data.pointer,
2071 &range,
2072 sizeof(struct iw_range)))
2073 ret = -EFAULT;
2074 wv_splhi(lp, &flags);
2076 break;
2078 case SIOCGIWPRIV:
2079 /* Basic checking */
2080 if (wrq->u.data.pointer != (caddr_t) 0) {
2081 struct iw_priv_args priv[] = {
2082 /* { cmd,
2083 set_args,
2084 get_args,
2085 name } */
2086 { SIOCSIPQTHR,
2087 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2089 "setqualthr" },
2090 { SIOCGIPQTHR,
2092 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2093 "getqualthr" },
2094 { SIOCSIPHISTO,
2095 IW_PRIV_TYPE_BYTE | 16,
2097 "sethisto" },
2098 { SIOCGIPHISTO,
2100 IW_PRIV_TYPE_INT | 16,
2101 "gethisto" },
2104 /* Set the number of available ioctls. */
2105 wrq->u.data.length = 4;
2107 /* Copy structure to the user buffer. */
2108 wv_splx(lp, &flags);
2109 if (copy_to_user(wrq->u.data.pointer,
2110 (u8 *) priv,
2111 sizeof(priv)))
2112 ret = -EFAULT;
2113 wv_splhi(lp, &flags);
2115 break;
2117 #ifdef WIRELESS_SPY
2118 case SIOCSIWSPY:
2119 /* Set the spy list */
2121 /* Check the number of addresses. */
2122 if (wrq->u.data.length > IW_MAX_SPY) {
2123 ret = -E2BIG;
2124 break;
2126 lp->spy_number = wrq->u.data.length;
2128 /* Are there are addresses to copy? */
2129 if (lp->spy_number > 0) {
2130 struct sockaddr address[IW_MAX_SPY];
2131 int i;
2133 /* Copy addresses to the driver. */
2134 wv_splx(lp, &flags);
2135 err = copy_from_user(address,
2136 wrq->u.data.pointer,
2137 sizeof(struct sockaddr)
2138 * lp->spy_number);
2139 wv_splhi(lp, &flags);
2140 if (err) {
2141 ret = -EFAULT;
2142 break;
2145 /* Copy addresses to the lp structure. */
2146 for (i = 0; i < lp->spy_number; i++) {
2147 memcpy(lp->spy_address[i],
2148 address[i].sa_data,
2149 WAVELAN_ADDR_SIZE);
2152 /* Reset structure. */
2153 memset(lp->spy_stat, 0x00,
2154 sizeof(iw_qual) * IW_MAX_SPY);
2156 #ifdef DEBUG_IOCTL_INFO
2157 printk(KERN_DEBUG
2158 "SetSpy: set of new addresses is: \n");
2159 for (i = 0; i < wrq->u.data.length; i++)
2160 printk(KERN_DEBUG
2161 "%02X:%02X:%02X:%02X:%02X:%02X \n",
2162 lp->spy_address[i][0],
2163 lp->spy_address[i][1],
2164 lp->spy_address[i][2],
2165 lp->spy_address[i][3],
2166 lp->spy_address[i][4],
2167 lp->spy_address[i][5]);
2168 #endif /* DEBUG_IOCTL_INFO */
2171 break;
2173 case SIOCGIWSPY:
2174 /* Get the spy list and spy stats. */
2176 /* Set the number of addresses */
2177 wrq->u.data.length = lp->spy_number;
2179 /* Does the user want to have the addresses back? */
2180 if ((lp->spy_number > 0)
2181 && (wrq->u.data.pointer != (caddr_t) 0)) {
2182 struct sockaddr address[IW_MAX_SPY];
2183 int i;
2185 /* Copy addresses from the lp structure. */
2186 for (i = 0; i < lp->spy_number; i++) {
2187 memcpy(address[i].sa_data,
2188 lp->spy_address[i],
2189 WAVELAN_ADDR_SIZE);
2190 address[i].sa_family = AF_UNIX;
2193 /* Copy addresses to the user buffer. */
2194 wv_splx(lp, &flags);
2195 err = copy_to_user(wrq->u.data.pointer,
2196 address,
2197 sizeof(struct sockaddr)
2198 * lp->spy_number);
2200 /* Copy stats to the user buffer (just after). */
2201 err |= copy_to_user(wrq->u.data.pointer
2202 + (sizeof(struct sockaddr)
2203 * lp->spy_number),
2204 lp->spy_stat,
2205 sizeof(iw_qual) * lp->spy_number);
2206 wv_splhi(lp, &flags);
2207 if (err) {
2208 ret = -EFAULT;
2209 break;
2212 /* Reset updated flags. */
2213 for (i = 0; i < lp->spy_number; i++)
2214 lp->spy_stat[i].updated = 0x0;
2216 /* if(pointer != NULL) */
2217 break;
2218 #endif /* WIRELESS_SPY */
2220 /* ------------------ PRIVATE IOCTL ------------------ */
2222 case SIOCSIPQTHR:
2223 if (!capable(CAP_NET_ADMIN)) {
2224 ret = -EPERM;
2225 break;
2227 psa.psa_quality_thr = *(wrq->u.name) & 0x0F;
2228 psa_write(ioaddr, lp->hacr,
2229 (char *) &psa.psa_quality_thr - (char *) &psa,
2230 (unsigned char *) &psa.psa_quality_thr, 1);
2231 /* update the Wavelan checksum */
2232 update_psa_checksum(dev, ioaddr, lp->hacr);
2233 mmc_out(ioaddr, mmwoff(0, mmw_quality_thr),
2234 psa.psa_quality_thr);
2235 break;
2237 case SIOCGIPQTHR:
2238 psa_read(ioaddr, lp->hacr,
2239 (char *) &psa.psa_quality_thr - (char *) &psa,
2240 (unsigned char *) &psa.psa_quality_thr, 1);
2241 *(wrq->u.name) = psa.psa_quality_thr & 0x0F;
2242 break;
2244 #ifdef HISTOGRAM
2245 case SIOCSIPHISTO:
2246 /* Verify that the user is root. */
2247 if (!capable(CAP_NET_ADMIN)) {
2248 ret = -EPERM;
2249 break;
2252 /* Check the number of intervals. */
2253 if (wrq->u.data.length > 16) {
2254 ret = -E2BIG;
2255 break;
2257 lp->his_number = wrq->u.data.length;
2259 /* Are there addresses to copy? */
2260 if (lp->his_number > 0) {
2261 /* Copy interval ranges to the driver */
2262 wv_splx(lp, &flags);
2263 err = copy_from_user(lp->his_range,
2264 wrq->u.data.pointer,
2265 sizeof(char) * lp->his_number);
2266 wv_splhi(lp, &flags);
2267 if (err) {
2268 ret = -EFAULT;
2269 break;
2272 /* Reset structure. */
2273 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2275 break;
2277 case SIOCGIPHISTO:
2278 /* Set the number of intervals. */
2279 wrq->u.data.length = lp->his_number;
2281 /* Give back the distribution statistics */
2282 if ((lp->his_number > 0)
2283 && (wrq->u.data.pointer != (caddr_t) 0)) {
2284 /* Copy data to the user buffer. */
2285 wv_splx(lp, &flags);
2286 if (copy_to_user(wrq->u.data.pointer,
2287 lp->his_sum,
2288 sizeof(long) * lp->his_number);
2289 ret = -EFAULT;
2290 wv_splhi(lp, &flags);
2292 } /* if(pointer != NULL) */
2293 break;
2294 #endif /* HISTOGRAM */
2296 /* ------------------- OTHER IOCTL ------------------- */
2298 default:
2299 ret = -EOPNOTSUPP;
2300 } /* switch (cmd) */
2302 /* Enable interrupts and restore flags. */
2303 wv_splx(lp, &flags);
2305 #ifdef DEBUG_IOCTL_TRACE
2306 printk(KERN_DEBUG "%s: <-wavelan_ioctl()\n", dev->name);
2307 #endif
2308 return ret;
2311 /*------------------------------------------------------------------*/
2313 * Get wireless statistics.
2314 * Called by /proc/net/wireless
2316 static iw_stats *wavelan_get_wireless_stats(device * dev)
2318 unsigned long ioaddr = dev->base_addr;
2319 net_local *lp = (net_local *) dev->priv;
2320 mmr_t m;
2321 iw_stats *wstats;
2322 unsigned long flags;
2324 #ifdef DEBUG_IOCTL_TRACE
2325 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n",
2326 dev->name);
2327 #endif
2329 /* Check */
2330 if (lp == (net_local *) NULL)
2331 return (iw_stats *) NULL;
2333 /* Disable interrupts and save flags. */
2334 wv_splhi(lp, &flags);
2336 wstats = &lp->wstats;
2338 /* Get data from the mmc. */
2339 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2341 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2342 mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l,
2344 mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set,
2347 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2349 /* Copy data to wireless stuff. */
2350 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2351 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2352 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2353 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2354 wstats->qual.updated = (((m. mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7)
2355 | ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6)
2356 | ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2357 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2358 wstats->discard.code = 0L;
2359 wstats->discard.misc = 0L;
2361 /* Enable interrupts and restore flags. */
2362 wv_splx(lp, &flags);
2364 #ifdef DEBUG_IOCTL_TRACE
2365 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n",
2366 dev->name);
2367 #endif
2368 return &lp->wstats;
2370 #endif /* WIRELESS_EXT */
2372 /************************* PACKET RECEPTION *************************/
2374 * This part deals with receiving the packets.
2375 * The interrupt handler gets an interrupt when a packet has been
2376 * successfully received and calls this part.
2379 /*------------------------------------------------------------------*/
2381 * This routine does the actual copying of data (including the Ethernet
2382 * header structure) from the WaveLAN card to an sk_buff chain that
2383 * will be passed up to the network interface layer. NOTE: we
2384 * currently don't handle trailer protocols (neither does the rest of
2385 * the network interface), so if that is needed, it will (at least in
2386 * part) be added here. The contents of the receive ring buffer are
2387 * copied to a message chain that is then passed to the kernel.
2389 * Note: if any errors occur, the packet is "dropped on the floor".
2390 * (called by wv_packet_rcv())
2392 static inline void
2393 wv_packet_read(device * dev, u16 buf_off, int sksize)
2395 net_local *lp = (net_local *) dev->priv;
2396 unsigned long ioaddr = dev->base_addr;
2397 struct sk_buff *skb;
2399 #ifdef DEBUG_RX_TRACE
2400 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2401 dev->name, buf_off, sksize);
2402 #endif
2404 /* Allocate buffer for the data */
2405 if ((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL) {
2406 #ifdef DEBUG_RX_ERROR
2407 printk(KERN_INFO
2408 "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
2409 dev->name, sksize);
2410 #endif
2411 lp->stats.rx_dropped++;
2412 return;
2415 skb->dev = dev;
2417 /* Copy the packet to the buffer. */
2418 obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize);
2419 skb->protocol = eth_type_trans(skb, dev);
2421 #ifdef DEBUG_RX_INFO
2422 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2423 #endif /* DEBUG_RX_INFO */
2425 /* Statistics-gathering and associated stuff.
2426 * It seem a bit messy with all the define, but it's really simple... */
2427 #if defined(WIRELESS_SPY) || defined(HISTOGRAM)
2428 if (
2429 #ifdef WIRELESS_SPY
2430 (lp->spy_number > 0) ||
2431 #endif /* WIRELESS_SPY */
2432 #ifdef HISTOGRAM
2433 (lp->his_number > 0) ||
2434 #endif /* HISTOGRAM */
2435 0) {
2436 u8 stats[3]; /* signal level, noise level, signal quality */
2438 /* Read signal level, silence level and signal quality bytes. */
2439 /* Note: in the PCMCIA hardware, these are part of the frame. It seems
2440 * that for the ISA hardware, it's nowhere to be found in the frame,
2441 * so I'm obliged to do this (it has a side effect on /proc/net/wireless).
2442 * Any ideas?
2444 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2445 mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3);
2446 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2448 #ifdef DEBUG_RX_INFO
2449 printk(KERN_DEBUG
2450 "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2451 dev->name, stats[0] & 0x3F, stats[1] & 0x3F,
2452 stats[2] & 0x0F);
2453 #endif
2455 /* Spying stuff */
2456 #ifdef WIRELESS_SPY
2457 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE,
2458 stats);
2459 #endif /* WIRELESS_SPY */
2460 #ifdef HISTOGRAM
2461 wl_his_gather(dev, stats);
2462 #endif /* HISTOGRAM */
2464 #endif /* defined(WIRELESS_SPY) || defined(HISTOGRAM) */
2467 * Hand the packet to the network module.
2469 netif_rx(skb);
2471 /* Keep statistics up to date */
2472 lp->stats.rx_packets++;
2473 lp->stats.rx_bytes += skb->len;
2475 #ifdef DEBUG_RX_TRACE
2476 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2477 #endif
2480 /*------------------------------------------------------------------*/
2482 * Transfer as many packets as we can
2483 * from the device RAM.
2484 * (called in wavelan_interrupt()).
2485 * Note : the spinlock is already grabbed for us.
2487 static inline void wv_receive(device * dev)
2489 unsigned long ioaddr = dev->base_addr;
2490 net_local *lp = (net_local *) dev->priv;
2491 fd_t fd;
2492 rbd_t rbd;
2493 int nreaped = 0;
2495 #ifdef DEBUG_RX_TRACE
2496 printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name);
2497 #endif
2499 /* Loop on each received packet. */
2500 for (;;) {
2501 obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd,
2502 sizeof(fd));
2504 /* Note about the status :
2505 * It start up to be 0 (the value we set). Then, when the RU
2506 * grab the buffer to prepare for reception, it sets the
2507 * FD_STATUS_B flag. When the RU has finished receiving the
2508 * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
2509 * completion and set the other flags to indicate the eventual
2510 * errors. FD_STATUS_OK indicates that the reception was OK.
2513 /* If the current frame is not complete, we have reached the end. */
2514 if ((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
2515 break; /* This is how we exit the loop. */
2517 nreaped++;
2519 /* Check whether frame was correctly received. */
2520 if ((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK) {
2521 /* Does the frame contain a pointer to the data? Let's check. */
2522 if (fd.fd_rbd_offset != I82586NULL) {
2523 /* Read the receive buffer descriptor */
2524 obram_read(ioaddr, fd.fd_rbd_offset,
2525 (unsigned char *) &rbd,
2526 sizeof(rbd));
2528 #ifdef DEBUG_RX_ERROR
2529 if ((rbd.rbd_status & RBD_STATUS_EOF) !=
2530 RBD_STATUS_EOF) printk(KERN_INFO
2531 "%s: wv_receive(): missing EOF flag.\n",
2532 dev->name);
2534 if ((rbd.rbd_status & RBD_STATUS_F) !=
2535 RBD_STATUS_F) printk(KERN_INFO
2536 "%s: wv_receive(): missing F flag.\n",
2537 dev->name);
2538 #endif /* DEBUG_RX_ERROR */
2540 /* Read the packet and transmit to Linux */
2541 wv_packet_read(dev, rbd.rbd_bufl,
2542 rbd.
2543 rbd_status &
2544 RBD_STATUS_ACNT);
2546 #ifdef DEBUG_RX_ERROR
2547 else /* if frame has no data */
2548 printk(KERN_INFO
2549 "%s: wv_receive(): frame has no data.\n",
2550 dev->name);
2551 #endif
2552 } else { /* If reception was no successful */
2554 lp->stats.rx_errors++;
2556 #ifdef DEBUG_RX_INFO
2557 printk(KERN_DEBUG
2558 "%s: wv_receive(): frame not received successfully (%X).\n",
2559 dev->name, fd.fd_status);
2560 #endif
2562 #ifdef DEBUG_RX_ERROR
2563 if ((fd.fd_status & FD_STATUS_S6) != 0)
2564 printk(KERN_INFO
2565 "%s: wv_receive(): no EOF flag.\n",
2566 dev->name);
2567 #endif
2569 if ((fd.fd_status & FD_STATUS_S7) != 0) {
2570 lp->stats.rx_length_errors++;
2571 #ifdef DEBUG_RX_FAIL
2572 printk(KERN_DEBUG
2573 "%s: wv_receive(): frame too short.\n",
2574 dev->name);
2575 #endif
2578 if ((fd.fd_status & FD_STATUS_S8) != 0) {
2579 lp->stats.rx_over_errors++;
2580 #ifdef DEBUG_RX_FAIL
2581 printk(KERN_DEBUG
2582 "%s: wv_receive(): rx DMA overrun.\n",
2583 dev->name);
2584 #endif
2587 if ((fd.fd_status & FD_STATUS_S9) != 0) {
2588 lp->stats.rx_fifo_errors++;
2589 #ifdef DEBUG_RX_FAIL
2590 printk(KERN_DEBUG
2591 "%s: wv_receive(): ran out of resources.\n",
2592 dev->name);
2593 #endif
2596 if ((fd.fd_status & FD_STATUS_S10) != 0) {
2597 lp->stats.rx_frame_errors++;
2598 #ifdef DEBUG_RX_FAIL
2599 printk(KERN_DEBUG
2600 "%s: wv_receive(): alignment error.\n",
2601 dev->name);
2602 #endif
2605 if ((fd.fd_status & FD_STATUS_S11) != 0) {
2606 lp->stats.rx_crc_errors++;
2607 #ifdef DEBUG_RX_FAIL
2608 printk(KERN_DEBUG
2609 "%s: wv_receive(): CRC error.\n",
2610 dev->name);
2611 #endif
2615 fd.fd_status = 0;
2616 obram_write(ioaddr, fdoff(lp->rx_head, fd_status),
2617 (unsigned char *) &fd.fd_status,
2618 sizeof(fd.fd_status));
2620 fd.fd_command = FD_COMMAND_EL;
2621 obram_write(ioaddr, fdoff(lp->rx_head, fd_command),
2622 (unsigned char *) &fd.fd_command,
2623 sizeof(fd.fd_command));
2625 fd.fd_command = 0;
2626 obram_write(ioaddr, fdoff(lp->rx_last, fd_command),
2627 (unsigned char *) &fd.fd_command,
2628 sizeof(fd.fd_command));
2630 lp->rx_last = lp->rx_head;
2631 lp->rx_head = fd.fd_link_offset;
2632 } /* for(;;) -> loop on all frames */
2634 #ifdef DEBUG_RX_INFO
2635 if (nreaped > 1)
2636 printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n",
2637 dev->name, nreaped);
2638 #endif
2639 #ifdef DEBUG_RX_TRACE
2640 printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name);
2641 #endif
2644 /*********************** PACKET TRANSMISSION ***********************/
2646 * This part deals with sending packets through the WaveLAN.
2650 /*------------------------------------------------------------------*/
2652 * This routine fills in the appropriate registers and memory
2653 * locations on the WaveLAN card and starts the card off on
2654 * the transmit.
2656 * The principle:
2657 * Each block contains a transmit command, a NOP command,
2658 * a transmit block descriptor and a buffer.
2659 * The CU read the transmit block which point to the tbd,
2660 * read the tbd and the content of the buffer.
2661 * When it has finish with it, it goes to the next command
2662 * which in our case is the NOP. The NOP points on itself,
2663 * so the CU stop here.
2664 * When we add the next block, we modify the previous nop
2665 * to make it point on the new tx command.
2666 * Simple, isn't it ?
2668 * (called in wavelan_packet_xmit())
2670 static inline int wv_packet_write(device * dev, void *buf, short length)
2672 net_local *lp = (net_local *) dev->priv;
2673 unsigned long ioaddr = dev->base_addr;
2674 unsigned short txblock;
2675 unsigned short txpred;
2676 unsigned short tx_addr;
2677 unsigned short nop_addr;
2678 unsigned short tbd_addr;
2679 unsigned short buf_addr;
2680 ac_tx_t tx;
2681 ac_nop_t nop;
2682 tbd_t tbd;
2683 int clen = length;
2684 unsigned long flags;
2686 #ifdef DEBUG_TX_TRACE
2687 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name,
2688 length);
2689 #endif
2691 /* Do we need some padding? */
2692 if (clen < ETH_ZLEN)
2693 clen = ETH_ZLEN;
2695 wv_splhi(lp, &flags);
2697 /* Check nothing bad has happened */
2698 if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
2699 #ifdef DEBUG_TX_ERROR
2700 printk(KERN_INFO "%s: wv_packet_write(): Tx queue full.\n",
2701 dev->name);
2702 #endif
2703 wv_splx(lp, &flags);
2704 return 1;
2707 /* Calculate addresses of next block and previous block. */
2708 txblock = lp->tx_first_free;
2709 txpred = txblock - TXBLOCKZ;
2710 if (txpred < OFFSET_CU)
2711 txpred += NTXBLOCKS * TXBLOCKZ;
2712 lp->tx_first_free += TXBLOCKZ;
2713 if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
2714 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
2716 lp->tx_n_in_use++;
2718 /* Calculate addresses of the different parts of the block. */
2719 tx_addr = txblock;
2720 nop_addr = tx_addr + sizeof(tx);
2721 tbd_addr = nop_addr + sizeof(nop);
2722 buf_addr = tbd_addr + sizeof(tbd);
2725 * Transmit command
2727 tx.tx_h.ac_status = 0;
2728 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
2729 (unsigned char *) &tx.tx_h.ac_status,
2730 sizeof(tx.tx_h.ac_status));
2733 * NOP command
2735 nop.nop_h.ac_status = 0;
2736 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2737 (unsigned char *) &nop.nop_h.ac_status,
2738 sizeof(nop.nop_h.ac_status));
2739 nop.nop_h.ac_link = nop_addr;
2740 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2741 (unsigned char *) &nop.nop_h.ac_link,
2742 sizeof(nop.nop_h.ac_link));
2745 * Transmit buffer descriptor
2747 tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen);
2748 tbd.tbd_next_bd_offset = I82586NULL;
2749 tbd.tbd_bufl = buf_addr;
2750 tbd.tbd_bufh = 0;
2751 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd));
2754 * Data
2756 obram_write(ioaddr, buf_addr, buf, length);
2759 * Overwrite the predecessor NOP link
2760 * so that it points to this txblock.
2762 nop_addr = txpred + sizeof(tx);
2763 nop.nop_h.ac_status = 0;
2764 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2765 (unsigned char *) &nop.nop_h.ac_status,
2766 sizeof(nop.nop_h.ac_status));
2767 nop.nop_h.ac_link = txblock;
2768 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2769 (unsigned char *) &nop.nop_h.ac_link,
2770 sizeof(nop.nop_h.ac_link));
2772 /* Keep stats up to date. */
2773 lp->stats.tx_bytes += length;
2775 if (lp->tx_first_in_use == I82586NULL)
2776 lp->tx_first_in_use = txblock;
2778 if (lp->tx_n_in_use < NTXBLOCKS - 1)
2779 netif_wake_queue(dev);
2781 wv_splx(lp, &flags);
2783 #ifdef DEBUG_TX_INFO
2784 wv_packet_info((u8 *) buf, length, dev->name,
2785 "wv_packet_write");
2786 #endif /* DEBUG_TX_INFO */
2788 #ifdef DEBUG_TX_TRACE
2789 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
2790 #endif
2792 return 0;
2795 /*------------------------------------------------------------------*/
2797 * This routine is called when we want to send a packet (NET3 callback)
2798 * In this routine, we check if the harware is ready to accept
2799 * the packet. We also prevent reentrance. Then we call the function
2800 * to send the packet.
2802 static int wavelan_packet_xmit(struct sk_buff *skb, device * dev)
2804 net_local *lp = (net_local *) dev->priv;
2805 unsigned long flags;
2807 #ifdef DEBUG_TX_TRACE
2808 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
2809 (unsigned) skb);
2810 #endif
2813 * Block a timer-based transmit from overlapping.
2814 * In other words, prevent reentering this routine.
2816 netif_stop_queue(dev);
2818 /* If somebody has asked to reconfigure the controller,
2819 * we can do it now.
2821 if (lp->reconfig_82586) {
2822 wv_splhi(lp, &flags);
2823 wv_82586_config(dev);
2824 wv_splx(lp, &flags);
2825 /* Check that we can continue */
2826 if (lp->tx_n_in_use == (NTXBLOCKS - 1))
2827 return 1;
2829 #ifdef DEBUG_TX_ERROR
2830 if (skb->next)
2831 printk(KERN_INFO "skb has next\n");
2832 #endif
2834 /* Write packet on the card */
2835 if(wv_packet_write(dev, skb->data, skb->len))
2836 return 1; /* We failed */
2838 dev_kfree_skb(skb);
2840 #ifdef DEBUG_TX_TRACE
2841 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
2842 #endif
2843 return 0;
2846 /*********************** HARDWARE CONFIGURATION ***********************/
2848 * This part does the real job of starting and configuring the hardware.
2851 /*--------------------------------------------------------------------*/
2853 * Routine to initialize the Modem Management Controller.
2854 * (called by wv_hw_reset())
2856 static inline int wv_mmc_init(device * dev)
2858 unsigned long ioaddr = dev->base_addr;
2859 net_local *lp = (net_local *) dev->priv;
2860 psa_t psa;
2861 mmw_t m;
2862 int configured;
2864 #ifdef DEBUG_CONFIG_TRACE
2865 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
2866 #endif
2868 /* Read the parameter storage area. */
2869 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
2871 #ifdef USE_PSA_CONFIG
2872 configured = psa.psa_conf_status & 1;
2873 #else
2874 configured = 0;
2875 #endif
2877 /* Is the PSA is not configured */
2878 if (!configured) {
2879 /* User will be able to configure NWID later (with iwconfig). */
2880 psa.psa_nwid[0] = 0;
2881 psa.psa_nwid[1] = 0;
2883 /* no NWID checking since NWID is not set */
2884 psa.psa_nwid_select = 0;
2886 /* Disable encryption */
2887 psa.psa_encryption_select = 0;
2889 /* Set to standard values:
2890 * 0x04 for AT,
2891 * 0x01 for MCA,
2892 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
2894 if (psa.psa_comp_number & 1)
2895 psa.psa_thr_pre_set = 0x01;
2896 else
2897 psa.psa_thr_pre_set = 0x04;
2898 psa.psa_quality_thr = 0x03;
2900 /* It is configured */
2901 psa.psa_conf_status |= 1;
2903 #ifdef USE_PSA_CONFIG
2904 /* Write the psa. */
2905 psa_write(ioaddr, lp->hacr,
2906 (char *) psa.psa_nwid - (char *) &psa,
2907 (unsigned char *) psa.psa_nwid, 4);
2908 psa_write(ioaddr, lp->hacr,
2909 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2910 (unsigned char *) &psa.psa_thr_pre_set, 1);
2911 psa_write(ioaddr, lp->hacr,
2912 (char *) &psa.psa_quality_thr - (char *) &psa,
2913 (unsigned char *) &psa.psa_quality_thr, 1);
2914 psa_write(ioaddr, lp->hacr,
2915 (char *) &psa.psa_conf_status - (char *) &psa,
2916 (unsigned char *) &psa.psa_conf_status, 1);
2917 /* update the Wavelan checksum */
2918 update_psa_checksum(dev, ioaddr, lp->hacr);
2919 #endif
2922 /* Zero the mmc structure. */
2923 memset(&m, 0x00, sizeof(m));
2925 /* Copy PSA info to the mmc. */
2926 m.mmw_netw_id_l = psa.psa_nwid[1];
2927 m.mmw_netw_id_h = psa.psa_nwid[0];
2929 if (psa.psa_nwid_select & 1)
2930 m.mmw_loopt_sel = 0x00;
2931 else
2932 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
2934 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
2935 sizeof(m.mmw_encr_key));
2937 if (psa.psa_encryption_select)
2938 m.mmw_encr_enable =
2939 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
2940 else
2941 m.mmw_encr_enable = 0;
2943 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
2944 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
2947 * Set default modem control parameters.
2948 * See NCR document 407-0024326 Rev. A.
2950 m.mmw_jabber_enable = 0x01;
2951 m.mmw_freeze = 0;
2952 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
2953 m.mmw_ifs = 0x20;
2954 m.mmw_mod_delay = 0x04;
2955 m.mmw_jam_time = 0x38;
2957 m.mmw_des_io_invert = 0;
2958 m.mmw_decay_prm = 0;
2959 m.mmw_decay_updat_prm = 0;
2961 /* Write all info to MMC. */
2962 mmc_write(ioaddr, 0, (u8 *) & m, sizeof(m));
2964 /* The following code starts the modem of the 2.00 frequency
2965 * selectable cards at power on. It's not strictly needed for the
2966 * following boots.
2967 * The original patch was by Joe Finney for the PCMCIA driver, but
2968 * I've cleaned it up a bit and added documentation.
2969 * Thanks to Loeke Brederveld from Lucent for the info.
2972 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
2973 * Does it work for everybody, especially old cards? */
2974 /* Note: WFREQSEL verifies that it is able to read a sensible
2975 * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
2976 * is 0xA (Xilinx version) or 0xB (Ariadne version).
2977 * My test is more crude but does work. */
2978 if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2979 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2980 /* We must download the frequency parameters to the
2981 * synthesizers (from the EEPROM - area 1)
2982 * Note: as the EEPROM is automatically decremented, we set the end
2983 * if the area... */
2984 m.mmw_fee_addr = 0x0F;
2985 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
2986 mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
2987 (unsigned char *) &m.mmw_fee_ctrl, 2);
2989 /* Wait until the download is finished. */
2990 fee_wait(ioaddr, 100, 100);
2992 #ifdef DEBUG_CONFIG_INFO
2993 /* The frequency was in the last word downloaded. */
2994 mmc_read(ioaddr, (char *) &m.mmw_fee_data_l - (char *) &m,
2995 (unsigned char *) &m.mmw_fee_data_l, 2);
2997 /* Print some info for the user. */
2998 printk(KERN_DEBUG
2999 "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n",
3000 dev->name,
3001 ((m.
3002 mmw_fee_data_h << 4) | (m.mmw_fee_data_l >> 4)) *
3003 5 / 2 + 24000L);
3004 #endif
3006 /* We must now download the power adjust value (gain) to
3007 * the synthesizers (from the EEPROM - area 7 - DAC). */
3008 m.mmw_fee_addr = 0x61;
3009 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3010 mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
3011 (unsigned char *) &m.mmw_fee_ctrl, 2);
3013 /* Wait until the download is finished. */
3015 /* if 2.00 card */
3016 #ifdef DEBUG_CONFIG_TRACE
3017 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3018 #endif
3019 return 0;
3022 /*------------------------------------------------------------------*/
3024 * Construct the fd and rbd structures.
3025 * Start the receive unit.
3026 * (called by wv_hw_reset())
3028 static inline int wv_ru_start(device * dev)
3030 net_local *lp = (net_local *) dev->priv;
3031 unsigned long ioaddr = dev->base_addr;
3032 u16 scb_cs;
3033 fd_t fd;
3034 rbd_t rbd;
3035 u16 rx;
3036 u16 rx_next;
3037 int i;
3039 #ifdef DEBUG_CONFIG_TRACE
3040 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3041 #endif
3043 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3044 (unsigned char *) &scb_cs, sizeof(scb_cs));
3045 if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
3046 return 0;
3048 lp->rx_head = OFFSET_RU;
3050 for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next) {
3051 rx_next =
3052 (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
3054 fd.fd_status = 0;
3055 fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
3056 fd.fd_link_offset = rx_next;
3057 fd.fd_rbd_offset = rx + sizeof(fd);
3058 obram_write(ioaddr, rx, (unsigned char *) &fd, sizeof(fd));
3060 rbd.rbd_status = 0;
3061 rbd.rbd_next_rbd_offset = I82586NULL;
3062 rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
3063 rbd.rbd_bufh = 0;
3064 rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
3065 obram_write(ioaddr, rx + sizeof(fd),
3066 (unsigned char *) &rbd, sizeof(rbd));
3068 lp->rx_last = rx;
3071 obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
3072 (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
3074 scb_cs = SCB_CMD_RUC_GO;
3075 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3076 (unsigned char *) &scb_cs, sizeof(scb_cs));
3078 set_chan_attn(ioaddr, lp->hacr);
3080 for (i = 1000; i > 0; i--) {
3081 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3082 (unsigned char *) &scb_cs, sizeof(scb_cs));
3083 if (scb_cs == 0)
3084 break;
3086 udelay(10);
3089 if (i <= 0) {
3090 #ifdef DEBUG_CONFIG_ERROR
3091 printk(KERN_INFO
3092 "%s: wavelan_ru_start(): board not accepting command.\n",
3093 dev->name);
3094 #endif
3095 return -1;
3097 #ifdef DEBUG_CONFIG_TRACE
3098 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3099 #endif
3100 return 0;
3103 /*------------------------------------------------------------------*/
3105 * Initialise the transmit blocks.
3106 * Start the command unit executing the NOP
3107 * self-loop of the first transmit block.
3109 * Here we create the list of send buffers used to transmit packets
3110 * between the PC and the command unit. For each buffer, we create a
3111 * buffer descriptor (pointing on the buffer), a transmit command
3112 * (pointing to the buffer descriptor) and a NOP command.
3113 * The transmit command is linked to the NOP, and the NOP to itself.
3114 * When we will have finished executing the transmit command, we will
3115 * then loop on the NOP. By releasing the NOP link to a new command,
3116 * we may send another buffer.
3118 * (called by wv_hw_reset())
3120 static inline int wv_cu_start(device * dev)
3122 net_local *lp = (net_local *) dev->priv;
3123 unsigned long ioaddr = dev->base_addr;
3124 int i;
3125 u16 txblock;
3126 u16 first_nop;
3127 u16 scb_cs;
3129 #ifdef DEBUG_CONFIG_TRACE
3130 printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
3131 #endif
3133 lp->tx_first_free = OFFSET_CU;
3134 lp->tx_first_in_use = I82586NULL;
3136 for (i = 0, txblock = OFFSET_CU;
3137 i < NTXBLOCKS; i++, txblock += TXBLOCKZ) {
3138 ac_tx_t tx;
3139 ac_nop_t nop;
3140 tbd_t tbd;
3141 unsigned short tx_addr;
3142 unsigned short nop_addr;
3143 unsigned short tbd_addr;
3144 unsigned short buf_addr;
3146 tx_addr = txblock;
3147 nop_addr = tx_addr + sizeof(tx);
3148 tbd_addr = nop_addr + sizeof(nop);
3149 buf_addr = tbd_addr + sizeof(tbd);
3151 tx.tx_h.ac_status = 0;
3152 tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
3153 tx.tx_h.ac_link = nop_addr;
3154 tx.tx_tbd_offset = tbd_addr;
3155 obram_write(ioaddr, tx_addr, (unsigned char *) &tx,
3156 sizeof(tx));
3158 nop.nop_h.ac_status = 0;
3159 nop.nop_h.ac_command = acmd_nop;
3160 nop.nop_h.ac_link = nop_addr;
3161 obram_write(ioaddr, nop_addr, (unsigned char *) &nop,
3162 sizeof(nop));
3164 tbd.tbd_status = TBD_STATUS_EOF;
3165 tbd.tbd_next_bd_offset = I82586NULL;
3166 tbd.tbd_bufl = buf_addr;
3167 tbd.tbd_bufh = 0;
3168 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd,
3169 sizeof(tbd));
3172 first_nop =
3173 OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
3174 obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
3175 (unsigned char *) &first_nop, sizeof(first_nop));
3177 scb_cs = SCB_CMD_CUC_GO;
3178 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3179 (unsigned char *) &scb_cs, sizeof(scb_cs));
3181 set_chan_attn(ioaddr, lp->hacr);
3183 for (i = 1000; i > 0; i--) {
3184 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3185 (unsigned char *) &scb_cs, sizeof(scb_cs));
3186 if (scb_cs == 0)
3187 break;
3189 udelay(10);
3192 if (i <= 0) {
3193 #ifdef DEBUG_CONFIG_ERROR
3194 printk(KERN_INFO
3195 "%s: wavelan_cu_start(): board not accepting command.\n",
3196 dev->name);
3197 #endif
3198 return -1;
3201 lp->tx_n_in_use = 0;
3202 netif_start_queue(dev);
3203 #ifdef DEBUG_CONFIG_TRACE
3204 printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
3205 #endif
3206 return 0;
3209 /*------------------------------------------------------------------*/
3211 * This routine does a standard configuration of the WaveLAN
3212 * controller (i82586).
3214 * It initialises the scp, iscp and scb structure
3215 * The first two are just pointers to the next.
3216 * The last one is used for basic configuration and for basic
3217 * communication (interrupt status).
3219 * (called by wv_hw_reset())
3221 static inline int wv_82586_start(device * dev)
3223 net_local *lp = (net_local *) dev->priv;
3224 unsigned long ioaddr = dev->base_addr;
3225 scp_t scp; /* system configuration pointer */
3226 iscp_t iscp; /* intermediate scp */
3227 scb_t scb; /* system control block */
3228 ach_t cb; /* Action command header */
3229 u8 zeroes[512];
3230 int i;
3232 #ifdef DEBUG_CONFIG_TRACE
3233 printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
3234 #endif
3237 * Clear the onboard RAM.
3239 memset(&zeroes[0], 0x00, sizeof(zeroes));
3240 for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
3241 obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
3244 * Construct the command unit structures:
3245 * scp, iscp, scb, cb.
3247 memset(&scp, 0x00, sizeof(scp));
3248 scp.scp_sysbus = SCP_SY_16BBUS;
3249 scp.scp_iscpl = OFFSET_ISCP;
3250 obram_write(ioaddr, OFFSET_SCP, (unsigned char *) &scp,
3251 sizeof(scp));
3253 memset(&iscp, 0x00, sizeof(iscp));
3254 iscp.iscp_busy = 1;
3255 iscp.iscp_offset = OFFSET_SCB;
3256 obram_write(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3257 sizeof(iscp));
3259 /* Our first command is to reset the i82586. */
3260 memset(&scb, 0x00, sizeof(scb));
3261 scb.scb_command = SCB_CMD_RESET;
3262 scb.scb_cbl_offset = OFFSET_CU;
3263 scb.scb_rfa_offset = OFFSET_RU;
3264 obram_write(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3265 sizeof(scb));
3267 set_chan_attn(ioaddr, lp->hacr);
3269 /* Wait for command to finish. */
3270 for (i = 1000; i > 0; i--) {
3271 obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3272 sizeof(iscp));
3274 if (iscp.iscp_busy == (unsigned short) 0)
3275 break;
3277 udelay(10);
3280 if (i <= 0) {
3281 #ifdef DEBUG_CONFIG_ERROR
3282 printk(KERN_INFO
3283 "%s: wv_82586_start(): iscp_busy timeout.\n",
3284 dev->name);
3285 #endif
3286 return -1;
3289 /* Check command completion. */
3290 for (i = 15; i > 0; i--) {
3291 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3292 sizeof(scb));
3294 if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
3295 break;
3297 udelay(10);
3300 if (i <= 0) {
3301 #ifdef DEBUG_CONFIG_ERROR
3302 printk(KERN_INFO
3303 "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
3304 dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
3305 #endif
3306 return -1;
3309 wv_ack(dev);
3311 /* Set the action command header. */
3312 memset(&cb, 0x00, sizeof(cb));
3313 cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
3314 cb.ac_link = OFFSET_CU;
3315 obram_write(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3317 if (wv_synchronous_cmd(dev, "diag()") == -1)
3318 return -1;
3320 obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3321 if (cb.ac_status & AC_SFLD_FAIL) {
3322 #ifdef DEBUG_CONFIG_ERROR
3323 printk(KERN_INFO
3324 "%s: wv_82586_start(): i82586 Self Test failed.\n",
3325 dev->name);
3326 #endif
3327 return -1;
3329 #ifdef DEBUG_I82586_SHOW
3330 wv_scb_show(ioaddr);
3331 #endif
3333 #ifdef DEBUG_CONFIG_TRACE
3334 printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
3335 #endif
3336 return 0;
3339 /*------------------------------------------------------------------*/
3341 * This routine does a standard configuration of the WaveLAN
3342 * controller (i82586).
3344 * This routine is a violent hack. We use the first free transmit block
3345 * to make our configuration. In the buffer area, we create the three
3346 * configuration commands (linked). We make the previous NOP point to
3347 * the beginning of the buffer instead of the tx command. After, we go
3348 * as usual to the NOP command.
3349 * Note that only the last command (mc_set) will generate an interrupt.
3351 * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit())
3353 static void wv_82586_config(device * dev)
3355 net_local *lp = (net_local *) dev->priv;
3356 unsigned long ioaddr = dev->base_addr;
3357 unsigned short txblock;
3358 unsigned short txpred;
3359 unsigned short tx_addr;
3360 unsigned short nop_addr;
3361 unsigned short tbd_addr;
3362 unsigned short cfg_addr;
3363 unsigned short ias_addr;
3364 unsigned short mcs_addr;
3365 ac_tx_t tx;
3366 ac_nop_t nop;
3367 ac_cfg_t cfg; /* Configure action */
3368 ac_ias_t ias; /* IA-setup action */
3369 ac_mcs_t mcs; /* Multicast setup */
3370 struct dev_mc_list *dmi;
3372 #ifdef DEBUG_CONFIG_TRACE
3373 printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
3374 #endif
3376 /* Check nothing bad has happened */
3377 if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
3378 #ifdef DEBUG_CONFIG_ERROR
3379 printk(KERN_INFO "%s: wv_82586_config(): Tx queue full.\n",
3380 dev->name);
3381 #endif
3382 return;
3385 /* Calculate addresses of next block and previous block. */
3386 txblock = lp->tx_first_free;
3387 txpred = txblock - TXBLOCKZ;
3388 if (txpred < OFFSET_CU)
3389 txpred += NTXBLOCKS * TXBLOCKZ;
3390 lp->tx_first_free += TXBLOCKZ;
3391 if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
3392 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
3394 lp->tx_n_in_use++;
3396 /* Calculate addresses of the different parts of the block. */
3397 tx_addr = txblock;
3398 nop_addr = tx_addr + sizeof(tx);
3399 tbd_addr = nop_addr + sizeof(nop);
3400 cfg_addr = tbd_addr + sizeof(tbd_t); /* beginning of the buffer */
3401 ias_addr = cfg_addr + sizeof(cfg);
3402 mcs_addr = ias_addr + sizeof(ias);
3405 * Transmit command
3407 tx.tx_h.ac_status = 0xFFFF; /* Fake completion value */
3408 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
3409 (unsigned char *) &tx.tx_h.ac_status,
3410 sizeof(tx.tx_h.ac_status));
3413 * NOP command
3415 nop.nop_h.ac_status = 0;
3416 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3417 (unsigned char *) &nop.nop_h.ac_status,
3418 sizeof(nop.nop_h.ac_status));
3419 nop.nop_h.ac_link = nop_addr;
3420 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3421 (unsigned char *) &nop.nop_h.ac_link,
3422 sizeof(nop.nop_h.ac_link));
3424 /* Create a configure action. */
3425 memset(&cfg, 0x00, sizeof(cfg));
3428 * For Linux we invert AC_CFG_ALOC() so as to conform
3429 * to the way that net packets reach us from above.
3430 * (See also ac_tx_t.)
3432 * Updated from Wavelan Manual WCIN085B
3434 cfg.cfg_byte_cnt =
3435 AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
3436 cfg.cfg_fifolim = AC_CFG_FIFOLIM(4);
3437 cfg.cfg_byte8 = AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0);
3438 cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
3439 AC_CFG_ILPBCK(0) |
3440 AC_CFG_PRELEN(AC_CFG_PLEN_2) |
3441 AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
3442 cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
3443 AC_CFG_ACR(6) | AC_CFG_LINPRIO(0);
3444 cfg.cfg_ifs = 0x20;
3445 cfg.cfg_slotl = 0x0C;
3446 cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0);
3447 cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
3448 AC_CFG_BTSTF(0) |
3449 AC_CFG_CRC16(0) |
3450 AC_CFG_NCRC(0) |
3451 AC_CFG_TNCRS(1) |
3452 AC_CFG_MANCH(0) |
3453 AC_CFG_BCDIS(0) | AC_CFG_PRM(lp->promiscuous);
3454 cfg.cfg_byte15 = AC_CFG_ICDS(0) |
3455 AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0);
3457 cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
3459 cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
3461 cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
3462 cfg.cfg_h.ac_link = ias_addr;
3463 obram_write(ioaddr, cfg_addr, (unsigned char *) &cfg, sizeof(cfg));
3465 /* Set up the MAC address */
3466 memset(&ias, 0x00, sizeof(ias));
3467 ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
3468 ias.ias_h.ac_link = mcs_addr;
3469 memcpy(&ias.ias_addr[0], (unsigned char *) &dev->dev_addr[0],
3470 sizeof(ias.ias_addr));
3471 obram_write(ioaddr, ias_addr, (unsigned char *) &ias, sizeof(ias));
3473 /* Initialize adapter's Ethernet multicast addresses */
3474 memset(&mcs, 0x00, sizeof(mcs));
3475 mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
3476 mcs.mcs_h.ac_link = nop_addr;
3477 mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
3478 obram_write(ioaddr, mcs_addr, (unsigned char *) &mcs, sizeof(mcs));
3480 /* Any address to set? */
3481 if (lp->mc_count) {
3482 for (dmi = dev->mc_list; dmi; dmi = dmi->next)
3483 outsw(PIOP1(ioaddr), (u16 *) dmi->dmi_addr,
3484 WAVELAN_ADDR_SIZE >> 1);
3486 #ifdef DEBUG_CONFIG_INFO
3487 printk(KERN_DEBUG
3488 "%s: wv_82586_config(): set %d multicast addresses:\n",
3489 dev->name, lp->mc_count);
3490 for (dmi = dev->mc_list; dmi; dmi = dmi->next)
3491 printk(KERN_DEBUG
3492 " %02x:%02x:%02x:%02x:%02x:%02x\n",
3493 dmi->dmi_addr[0], dmi->dmi_addr[1],
3494 dmi->dmi_addr[2], dmi->dmi_addr[3],
3495 dmi->dmi_addr[4], dmi->dmi_addr[5]);
3496 #endif
3500 * Overwrite the predecessor NOP link
3501 * so that it points to the configure action.
3503 nop_addr = txpred + sizeof(tx);
3504 nop.nop_h.ac_status = 0;
3505 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3506 (unsigned char *) &nop.nop_h.ac_status,
3507 sizeof(nop.nop_h.ac_status));
3508 nop.nop_h.ac_link = cfg_addr;
3509 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3510 (unsigned char *) &nop.nop_h.ac_link,
3511 sizeof(nop.nop_h.ac_link));
3513 /* Job done, clear the flag */
3514 lp->reconfig_82586 = 0;
3516 if (lp->tx_first_in_use == I82586NULL)
3517 lp->tx_first_in_use = txblock;
3519 if (lp->tx_n_in_use == (NTXBLOCKS - 1))
3520 netif_stop_queue(dev);
3522 #ifdef DEBUG_CONFIG_TRACE
3523 printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
3524 #endif
3527 /*------------------------------------------------------------------*/
3529 * This routine, called by wavelan_close(), gracefully stops the
3530 * WaveLAN controller (i82586).
3531 * (called by wavelan_close())
3533 static inline void wv_82586_stop(device * dev)
3535 net_local *lp = (net_local *) dev->priv;
3536 unsigned long ioaddr = dev->base_addr;
3537 u16 scb_cmd;
3539 #ifdef DEBUG_CONFIG_TRACE
3540 printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
3541 #endif
3543 /* Suspend both command unit and receive unit. */
3544 scb_cmd =
3545 (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC &
3546 SCB_CMD_RUC_SUS);
3547 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3548 (unsigned char *) &scb_cmd, sizeof(scb_cmd));
3549 set_chan_attn(ioaddr, lp->hacr);
3551 /* No more interrupts */
3552 wv_ints_off(dev);
3554 #ifdef DEBUG_CONFIG_TRACE
3555 printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
3556 #endif
3559 /*------------------------------------------------------------------*/
3561 * Totally reset the WaveLAN and restart it.
3562 * Performs the following actions:
3563 * 1. A power reset (reset DMA)
3564 * 2. Initialize the radio modem (using wv_mmc_init)
3565 * 3. Reset & Configure LAN controller (using wv_82586_start)
3566 * 4. Start the LAN controller's command unit
3567 * 5. Start the LAN controller's receive unit
3568 * (called by wavelan_interrupt(), wavelan_watchdog() & wavelan_open())
3570 static int wv_hw_reset(device * dev)
3572 net_local *lp = (net_local *) dev->priv;
3573 unsigned long ioaddr = dev->base_addr;
3575 #ifdef DEBUG_CONFIG_TRACE
3576 printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
3577 (unsigned int) dev);
3578 #endif
3580 /* Increase the number of resets done. */
3581 lp->nresets++;
3583 wv_hacr_reset(ioaddr);
3584 lp->hacr = HACR_DEFAULT;
3586 if ((wv_mmc_init(dev) < 0) || (wv_82586_start(dev) < 0))
3587 return -1;
3589 /* Enable the card to send interrupts. */
3590 wv_ints_on(dev);
3592 /* Start card functions */
3593 if (wv_cu_start(dev) < 0)
3594 return -1;
3596 /* Setup the controller and parameters */
3597 wv_82586_config(dev);
3599 /* Finish configuration with the receive unit */
3600 if (wv_ru_start(dev) < 0)
3601 return -1;
3603 #ifdef DEBUG_CONFIG_TRACE
3604 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3605 #endif
3606 return 0;
3609 /*------------------------------------------------------------------*/
3611 * Check if there is a WaveLAN at the specific base address.
3612 * As a side effect, this reads the MAC address.
3613 * (called in wavelan_probe() and init_module())
3615 static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac)
3617 int i; /* Loop counter */
3619 /* Check if the base address if available. */
3620 if (check_region(ioaddr, sizeof(ha_t)))
3621 return -EADDRINUSE; /* ioaddr already used */
3623 /* Reset host interface */
3624 wv_hacr_reset(ioaddr);
3626 /* Read the MAC address from the parameter storage area. */
3627 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
3628 mac, 6);
3631 * Check the first three octets of the address for the manufacturer's code.
3632 * Note: if this can't find your WaveLAN card, you've got a
3633 * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on
3634 * how to configure your card.
3636 for (i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3637 if ((mac[0] == MAC_ADDRESSES[i][0]) &&
3638 (mac[1] == MAC_ADDRESSES[i][1]) &&
3639 (mac[2] == MAC_ADDRESSES[i][2]))
3640 return 0;
3642 #ifdef DEBUG_CONFIG_INFO
3643 printk(KERN_WARNING
3644 "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
3645 ioaddr, mac[0], mac[1], mac[2]);
3646 #endif
3647 return -ENODEV;
3650 /************************ INTERRUPT HANDLING ************************/
3653 * This function is the interrupt handler for the WaveLAN card. This
3654 * routine will be called whenever:
3656 static void wavelan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3658 device *dev;
3659 unsigned long ioaddr;
3660 net_local *lp;
3661 u16 hasr;
3662 u16 status;
3663 u16 ack_cmd;
3665 dev = dev_id;
3667 #ifdef DEBUG_INTERRUPT_TRACE
3668 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
3669 #endif
3671 lp = (net_local *) dev->priv;
3672 ioaddr = dev->base_addr;
3674 #ifdef DEBUG_INTERRUPT_INFO
3675 /* Check state of our spinlock */
3676 if(spin_is_locked(&lp->spinlock))
3677 printk(KERN_DEBUG
3678 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
3679 dev->name);
3680 #endif
3682 /* Prevent reentrancy. We need to do that because we may have
3683 * multiple interrupt handler running concurrently.
3684 * It is safe because wv_splhi() disables interrupts before acquiring
3685 * the spinlock. */
3686 spin_lock(&lp->spinlock);
3688 /* Check modem interupt */
3689 if ((hasr = hasr_read(ioaddr)) & HASR_MMC_INTR) {
3690 u8 dce_status;
3693 * Interrupt from the modem management controller.
3694 * This will clear it -- ignored for now.
3696 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status,
3697 sizeof(dce_status));
3698 #ifdef DEBUG_INTERRUPT_ERROR
3699 printk(KERN_INFO
3700 "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
3701 dev->name, dce_status);
3702 #endif
3705 /* Check if not controller interrupt */
3706 if ((hasr & HASR_82586_INTR) == 0) {
3707 #ifdef DEBUG_INTERRUPT_ERROR
3708 printk(KERN_INFO
3709 "%s: wavelan_interrupt(): interrupt not coming from i82586\n",
3710 dev->name);
3711 #endif
3712 spin_unlock (&lp->spinlock);
3713 return;
3716 /* Read interrupt data. */
3717 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3718 (unsigned char *) &status, sizeof(status));
3721 * Acknowledge the interrupt(s).
3723 ack_cmd = status & SCB_ST_INT;
3724 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3725 (unsigned char *) &ack_cmd, sizeof(ack_cmd));
3726 set_chan_attn(ioaddr, lp->hacr);
3728 #ifdef DEBUG_INTERRUPT_INFO
3729 printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
3730 dev->name, status);
3731 #endif
3733 /* Command completed. */
3734 if ((status & SCB_ST_CX) == SCB_ST_CX) {
3735 #ifdef DEBUG_INTERRUPT_INFO
3736 printk(KERN_DEBUG
3737 "%s: wavelan_interrupt(): command completed.\n",
3738 dev->name);
3739 #endif
3740 wv_complete(dev, ioaddr, lp);
3743 /* Frame received. */
3744 if ((status & SCB_ST_FR) == SCB_ST_FR) {
3745 #ifdef DEBUG_INTERRUPT_INFO
3746 printk(KERN_DEBUG
3747 "%s: wavelan_interrupt(): received packet.\n",
3748 dev->name);
3749 #endif
3750 wv_receive(dev);
3753 /* Check the state of the command unit. */
3754 if (((status & SCB_ST_CNA) == SCB_ST_CNA) ||
3755 (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) &&
3756 (netif_running(dev)))) {
3757 #ifdef DEBUG_INTERRUPT_ERROR
3758 printk(KERN_INFO
3759 "%s: wavelan_interrupt(): CU inactive -- restarting\n",
3760 dev->name);
3761 #endif
3762 wv_hw_reset(dev);
3765 /* Check the state of the command unit. */
3766 if (((status & SCB_ST_RNR) == SCB_ST_RNR) ||
3767 (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) &&
3768 (netif_running(dev)))) {
3769 #ifdef DEBUG_INTERRUPT_ERROR
3770 printk(KERN_INFO
3771 "%s: wavelan_interrupt(): RU not ready -- restarting\n",
3772 dev->name);
3773 #endif
3774 wv_hw_reset(dev);
3777 /* Release spinlock */
3778 spin_unlock (&lp->spinlock);
3780 #ifdef DEBUG_INTERRUPT_TRACE
3781 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
3782 #endif
3785 /*------------------------------------------------------------------*/
3787 * Watchdog: when we start a transmission, a timer is set for us in the
3788 * kernel. If the transmission completes, this timer is disabled. If
3789 * the timer expires, we are called and we try to unlock the hardware.
3791 static void wavelan_watchdog(device * dev)
3793 net_local * lp = (net_local *)dev->priv;
3794 u_long ioaddr = dev->base_addr;
3795 unsigned long flags;
3796 unsigned int nreaped;
3798 #ifdef DEBUG_INTERRUPT_TRACE
3799 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
3800 #endif
3802 #ifdef DEBUG_INTERRUPT_ERROR
3803 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
3804 dev->name);
3805 #endif
3807 /* Check that we came here for something */
3808 if (lp->tx_n_in_use <= 0) {
3809 return;
3812 wv_splhi(lp, &flags);
3814 /* Try to see if some buffers are not free (in case we missed
3815 * an interrupt */
3816 nreaped = wv_complete(dev, ioaddr, lp);
3818 #ifdef DEBUG_INTERRUPT_INFO
3819 printk(KERN_DEBUG
3820 "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
3821 dev->name, nreaped, lp->tx_n_in_use);
3822 #endif
3824 #ifdef DEBUG_PSA_SHOW
3826 psa_t psa;
3827 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3828 wv_psa_show(&psa);
3830 #endif
3831 #ifdef DEBUG_MMC_SHOW
3832 wv_mmc_show(dev);
3833 #endif
3834 #ifdef DEBUG_I82586_SHOW
3835 wv_cu_show(dev);
3836 #endif
3838 /* If no buffer has been freed */
3839 if (nreaped == 0) {
3840 #ifdef DEBUG_INTERRUPT_ERROR
3841 printk(KERN_INFO
3842 "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
3843 dev->name);
3844 #endif
3845 wv_hw_reset(dev);
3848 /* At this point, we should have some free Tx buffer ;-) */
3849 if (lp->tx_n_in_use < NTXBLOCKS - 1)
3850 netif_wake_queue(dev);
3852 wv_splx(lp, &flags);
3854 #ifdef DEBUG_INTERRUPT_TRACE
3855 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
3856 #endif
3859 /********************* CONFIGURATION CALLBACKS *********************/
3861 * Here are the functions called by the Linux networking code (NET3)
3862 * for initialization, configuration and deinstallations of the
3863 * WaveLAN ISA hardware.
3866 /*------------------------------------------------------------------*/
3868 * Configure and start up the WaveLAN PCMCIA adaptor.
3869 * Called by NET3 when it "opens" the device.
3871 static int wavelan_open(device * dev)
3873 net_local * lp = (net_local *)dev->priv;
3874 unsigned long flags;
3876 #ifdef DEBUG_CALLBACK_TRACE
3877 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
3878 (unsigned int) dev);
3879 #endif
3881 /* Check irq */
3882 if (dev->irq == 0) {
3883 #ifdef DEBUG_CONFIG_ERROR
3884 printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n",
3885 dev->name);
3886 #endif
3887 return -ENXIO;
3890 if (request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0)
3892 #ifdef DEBUG_CONFIG_ERROR
3893 printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n",
3894 dev->name);
3895 #endif
3896 return -EAGAIN;
3899 wv_splhi(lp, &flags);
3901 if (wv_hw_reset(dev) != -1) {
3902 netif_start_queue(dev);
3903 } else {
3904 free_irq(dev->irq, dev);
3905 #ifdef DEBUG_CONFIG_ERROR
3906 printk(KERN_INFO
3907 "%s: wavelan_open(): impossible to start the card\n",
3908 dev->name);
3909 #endif
3910 wv_splx(lp, &flags);
3911 return -EAGAIN;
3913 wv_splx(lp, &flags);
3915 MOD_INC_USE_COUNT;
3917 #ifdef DEBUG_CALLBACK_TRACE
3918 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
3919 #endif
3920 return 0;
3923 /*------------------------------------------------------------------*/
3925 * Shut down the WaveLAN ISA card.
3926 * Called by NET3 when it "closes" the device.
3928 static int wavelan_close(device * dev)
3930 net_local *lp = (net_local *) dev->priv;
3931 unsigned long flags;
3933 #ifdef DEBUG_CALLBACK_TRACE
3934 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
3935 (unsigned int) dev);
3936 #endif
3938 netif_stop_queue(dev);
3941 * Flush the Tx and disable Rx.
3943 wv_splhi(lp, &flags);
3944 wv_82586_stop(dev);
3945 wv_splx(lp, &flags);
3947 free_irq(dev->irq, dev);
3949 MOD_DEC_USE_COUNT;
3951 #ifdef DEBUG_CALLBACK_TRACE
3952 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
3953 #endif
3954 return 0;
3957 /*------------------------------------------------------------------*/
3959 * Probe an I/O address, and if the WaveLAN is there configure the
3960 * device structure
3961 * (called by wavelan_probe() and via init_module()).
3963 static int __init wavelan_config(device * dev)
3965 unsigned long ioaddr = dev->base_addr;
3966 u8 irq_mask;
3967 int irq;
3968 net_local *lp;
3970 #ifdef DEBUG_CALLBACK_TRACE
3971 printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%lx)\n",
3972 dev->name, (unsigned int) dev, ioaddr);
3973 #endif
3975 /* Check IRQ argument on command line. */
3976 if (dev->irq != 0) {
3977 irq_mask = wv_irq_to_psa(dev->irq);
3979 if (irq_mask == 0) {
3980 #ifdef DEBUG_CONFIG_ERROR
3981 printk(KERN_WARNING
3982 "%s: wavelan_config(): invalid IRQ %d ignored.\n",
3983 dev->name, dev->irq);
3984 #endif
3985 dev->irq = 0;
3986 } else {
3987 #ifdef DEBUG_CONFIG_INFO
3988 printk(KERN_DEBUG
3989 "%s: wavelan_config(): changing IRQ to %d\n",
3990 dev->name, dev->irq);
3991 #endif
3992 psa_write(ioaddr, HACR_DEFAULT,
3993 psaoff(0, psa_int_req_no), &irq_mask, 1);
3994 /* update the Wavelan checksum */
3995 update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
3996 wv_hacr_reset(ioaddr);
4000 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no),
4001 &irq_mask, 1);
4002 if ((irq = wv_psa_to_irq(irq_mask)) == -1) {
4003 #ifdef DEBUG_CONFIG_ERROR
4004 printk(KERN_INFO
4005 "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
4006 dev->name, irq_mask);
4007 #endif
4008 return -EAGAIN;
4011 dev->irq = irq;
4013 request_region(ioaddr, sizeof(ha_t), "wavelan");
4015 dev->mem_start = 0x0000;
4016 dev->mem_end = 0x0000;
4017 dev->if_port = 0;
4019 /* Initialize device structures */
4020 dev->priv = kmalloc(sizeof(net_local), GFP_KERNEL);
4021 if (dev->priv == NULL)
4022 return -ENOMEM;
4023 memset(dev->priv, 0x00, sizeof(net_local));
4024 lp = (net_local *) dev->priv;
4026 /* Back link to the device structure. */
4027 lp->dev = dev;
4028 /* Add the device at the beginning of the linked list. */
4029 lp->next = wavelan_list;
4030 wavelan_list = lp;
4032 lp->hacr = HACR_DEFAULT;
4034 /* Multicast stuff */
4035 lp->promiscuous = 0;
4036 lp->mc_count = 0;
4038 /* Init spinlock */
4039 spin_lock_init(&lp->spinlock);
4042 * Fill in the fields of the device structure
4043 * with generic Ethernet values.
4045 ether_setup(dev);
4047 dev->open = wavelan_open;
4048 dev->stop = wavelan_close;
4049 dev->hard_start_xmit = wavelan_packet_xmit;
4050 dev->get_stats = wavelan_get_stats;
4051 dev->set_multicast_list = &wavelan_set_multicast_list;
4052 dev->tx_timeout = &wavelan_watchdog;
4053 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4054 #ifdef SET_MAC_ADDRESS
4055 dev->set_mac_address = &wavelan_set_mac_address;
4056 #endif /* SET_MAC_ADDRESS */
4058 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
4059 dev->do_ioctl = wavelan_ioctl;
4060 dev->get_wireless_stats = wavelan_get_wireless_stats;
4061 #endif
4063 dev->mtu = WAVELAN_MTU;
4065 /* Display nice information. */
4066 wv_init_info(dev);
4068 #ifdef DEBUG_CALLBACK_TRACE
4069 printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
4070 #endif
4071 return 0;
4074 /*------------------------------------------------------------------*/
4076 * Check for a network adaptor of this type. Return '0' iff one
4077 * exists. There seem to be different interpretations of
4078 * the initial value of dev->base_addr.
4079 * We follow the example in drivers/net/ne.c.
4080 * (called in "Space.c")
4082 int __init wavelan_probe(device * dev)
4084 short base_addr;
4085 mac_addr mac; /* MAC address (check existence of WaveLAN) */
4086 int i;
4087 int r;
4089 #ifdef DEBUG_CALLBACK_TRACE
4090 printk(KERN_DEBUG
4091 "%s: ->wavelan_probe(dev=0x%x (base_addr=0x%x))\n",
4092 dev->name, (unsigned int) dev,
4093 (unsigned int) dev->base_addr);
4094 #endif
4096 #ifdef STRUCT_CHECK
4097 if (wv_struct_check() != (char *) NULL) {
4098 printk(KERN_WARNING
4099 "%s: wavelan_probe(): structure/compiler botch: \"%s\"\n",
4100 dev->name, wv_struct_check());
4101 return -ENODEV;
4103 #endif /* STRUCT_CHECK */
4105 /* Check the value of the command line parameter for base address. */
4106 base_addr = dev->base_addr;
4108 /* Don't probe at all. */
4109 if (base_addr < 0) {
4110 #ifdef DEBUG_CONFIG_ERROR
4111 printk(KERN_WARNING
4112 "%s: wavelan_probe(): invalid base address\n",
4113 dev->name);
4114 #endif
4115 return -ENXIO;
4118 /* Check a single specified location. */
4119 if (base_addr > 0x100) {
4120 /* Check if there is something at this base address */
4121 if ((r = wv_check_ioaddr(base_addr, mac)) == 0) {
4122 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4123 r = wavelan_config(dev);
4125 #ifdef DEBUG_CONFIG_INFO
4126 if (r != 0)
4127 printk(KERN_DEBUG
4128 "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
4129 dev->name, base_addr);
4130 #endif
4132 #ifdef DEBUG_CALLBACK_TRACE
4133 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4134 #endif
4135 return r;
4138 /* Scan all possible addresses of the WaveLAN hardware. */
4139 for (i = 0; i < NELS(iobase); i++) {
4140 /* Check whether there is something at this base address. */
4141 if (wv_check_ioaddr(iobase[i], mac) == 0) {
4142 dev->base_addr = iobase[i]; /* Copy base address. */
4143 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4144 if (wavelan_config(dev) == 0) {
4145 #ifdef DEBUG_CALLBACK_TRACE
4146 printk(KERN_DEBUG
4147 "%s: <-wavelan_probe()\n",
4148 dev->name);
4149 #endif
4150 return 0;
4155 /* We may have touched base_addr. Another driver may not like it. */
4156 dev->base_addr = base_addr;
4158 #ifdef DEBUG_CONFIG_INFO
4159 printk(KERN_DEBUG "%s: wavelan_probe(): no device found\n",
4160 dev->name);
4161 #endif
4163 return -ENODEV;
4166 /****************************** MODULE ******************************/
4168 * Module entry point: insertion and removal
4171 #ifdef MODULE
4172 /*------------------------------------------------------------------*/
4174 * Insertion of the module
4175 * I'm now quite proud of the multi-device support.
4177 int init_module(void)
4179 mac_addr mac; /* MAC address (check WaveLAN existence) */
4180 int ret = -EIO; /* Return error if no cards found */
4181 int i;
4183 #ifdef DEBUG_MODULE_TRACE
4184 printk(KERN_DEBUG "-> init_module()\n");
4185 #endif
4187 /* If probing is asked */
4188 if (io[0] == 0) {
4189 #ifdef DEBUG_CONFIG_ERROR
4190 printk(KERN_WARNING
4191 "WaveLAN init_module(): doing device probing (bad !)\n");
4192 printk(KERN_WARNING
4193 "Specify base addresses while loading module to correct the problem\n");
4194 #endif
4196 /* Copy the basic set of address to be probed. */
4197 for (i = 0; i < NELS(iobase); i++)
4198 io[i] = iobase[i];
4202 /* Loop on all possible base addresses. */
4203 i = -1;
4204 while ((io[++i] != 0) && (i < NELS(io))) {
4205 /* Check if there is something at this base address. */
4206 if (wv_check_ioaddr(io[i], mac) == 0) {
4207 device *dev;
4209 /* Create device and set basic arguments. */
4210 dev =
4211 kmalloc(sizeof(struct net_device), GFP_KERNEL);
4212 if (dev == NULL) {
4213 ret = -ENOMEM;
4214 break;
4216 memset(dev, 0x00, sizeof(struct net_device));
4217 memcpy(dev->name, name[i], IFNAMSIZ); /* Copy name */
4218 dev->base_addr = io[i];
4219 dev->irq = irq[i];
4220 dev->init = &wavelan_config;
4221 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4223 /* Try to create the device. */
4224 if (register_netdev(dev) != 0) {
4225 /* Deallocate everything. */
4226 /* Note: if dev->priv is mallocated, there is no way to fail. */
4227 kfree(dev);
4228 } else {
4229 /* If at least one device OK, we do not fail */
4230 ret = 0;
4232 } /* if there is something at the address */
4233 } /* Loop on all addresses. */
4235 #ifdef DEBUG_CONFIG_ERROR
4236 if (wavelan_list == (net_local *) NULL)
4237 printk(KERN_WARNING
4238 "WaveLAN init_module(): no device found\n");
4239 #endif
4241 #ifdef DEBUG_MODULE_TRACE
4242 printk(KERN_DEBUG "<- init_module()\n");
4243 #endif
4244 return ret;
4247 /*------------------------------------------------------------------*/
4249 * Removal of the module
4251 void cleanup_module(void)
4253 #ifdef DEBUG_MODULE_TRACE
4254 printk(KERN_DEBUG "-> cleanup_module()\n");
4255 #endif
4257 /* Loop on all devices and release them. */
4258 while (wavelan_list != (net_local *) NULL) {
4259 device *dev = wavelan_list->dev;
4261 #ifdef DEBUG_CONFIG_INFO
4262 printk(KERN_DEBUG
4263 "%s: cleanup_module(): removing device at 0x%x\n",
4264 dev->name, (unsigned int) dev);
4265 #endif
4267 /* Release the ioport region. */
4268 release_region(dev->base_addr, sizeof(ha_t));
4270 /* Definitely remove the device. */
4271 unregister_netdev(dev);
4273 /* Unlink the device. */
4274 wavelan_list = wavelan_list->next;
4276 /* Free pieces. */
4277 kfree(dev->priv);
4278 kfree(dev);
4281 #ifdef DEBUG_MODULE_TRACE
4282 printk(KERN_DEBUG "<- cleanup_module()\n");
4283 #endif
4285 #endif /* MODULE */
4288 * This software may only be used and distributed
4289 * according to the terms of the GNU Public License.
4291 * This software was developed as a component of the
4292 * Linux operating system.
4293 * It is based on other device drivers and information
4294 * either written or supplied by:
4295 * Ajay Bakre (bakre@paul.rutgers.edu),
4296 * Donald Becker (becker@cesdis.gsfc.nasa.gov),
4297 * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
4298 * Anders Klemets (klemets@it.kth.se),
4299 * Vladimir V. Kolpakov (w@stier.koenig.ru),
4300 * Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
4301 * Pauline Middelink (middelin@polyware.iaf.nl),
4302 * Robert Morris (rtm@das.harvard.edu),
4303 * Jean Tourrilhes (jt@hplb.hpl.hp.com),
4304 * Girish Welling (welling@paul.rutgers.edu),
4306 * Thanks go also to:
4307 * James Ashton (jaa101@syseng.anu.edu.au),
4308 * Alan Cox (alan@redhat.com),
4309 * Allan Creighton (allanc@cs.usyd.edu.au),
4310 * Matthew Geier (matthew@cs.usyd.edu.au),
4311 * Remo di Giovanni (remo@cs.usyd.edu.au),
4312 * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
4313 * Vipul Gupta (vgupta@cs.binghamton.edu),
4314 * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
4315 * Tim Nicholson (tim@cs.usyd.edu.au),
4316 * Ian Parkin (ian@cs.usyd.edu.au),
4317 * John Rosenberg (johnr@cs.usyd.edu.au),
4318 * George Rossi (george@phm.gov.au),
4319 * Arthur Scott (arthur@cs.usyd.edu.au),
4320 * Peter Storey,
4321 * for their assistance and advice.
4323 * Please send bug reports, updates, comments to:
4325 * Bruce Janson Email: bruce@cs.usyd.edu.au
4326 * Basser Department of Computer Science Phone: +61-2-9351-3423
4327 * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838