* add p cc
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / net / wavelan.c
blob2dd4eaa120020a5b6477e8654e637a1dd5daa86f
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.
9 */
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.
29 static inline unsigned long
30 wv_splhi(void)
32 unsigned long flags;
34 save_flags(flags);
35 cli();
37 return(flags);
40 /*------------------------------------------------------------------*/
42 * Wrapper for re-enabling interrupts.
44 static inline void
45 wv_splx(unsigned long flags)
47 restore_flags(flags);
50 /*------------------------------------------------------------------*/
52 * Translate irq number to PSA irq parameter
54 static u_char
55 wv_irq_to_psa(int irq)
57 if(irq < 0 || irq >= NELS(irqvals))
58 return 0;
60 return irqvals[irq];
63 /*------------------------------------------------------------------*/
65 * Translate PSA irq parameter to irq number
67 static int __init
68 wv_psa_to_irq(u_char irqval)
70 int irq;
72 for(irq = 0; irq < NELS(irqvals); irq++)
73 if(irqvals[irq] == irqval)
74 return irq;
76 return -1;
79 #ifdef STRUCT_CHECK
80 /*------------------------------------------------------------------*/
82 * Sanity routine to verify the sizes of the various WaveLAN interface
83 * structures.
85 static char *
86 wv_struct_check(void)
88 #define SC(t,s,n) if (sizeof(t) != s) return(n);
90 SC(psa_t, PSA_SIZE, "psa_t");
91 SC(mmw_t, MMW_SIZE, "mmw_t");
92 SC(mmr_t, MMR_SIZE, "mmr_t");
93 SC(ha_t, HA_SIZE, "ha_t");
95 #undef SC
97 return((char *) NULL);
98 } /* wv_struct_check */
99 #endif /* STRUCT_CHECK */
101 /********************* HOST ADAPTER SUBROUTINES *********************/
103 * Useful subroutines to manage the WaveLAN ISA interface
105 * One major difference with the PCMCIA hardware (except the port mapping)
106 * is that we have to keep the state of the Host Control Register
107 * because of the interrupt enable & bus size flags.
110 /*------------------------------------------------------------------*/
112 * Read from card's Host Adaptor Status Register.
114 static inline u_short
115 hasr_read(u_long ioaddr)
117 return(inw(HASR(ioaddr)));
118 } /* hasr_read */
120 /*------------------------------------------------------------------*/
122 * Write to card's Host Adapter Command Register.
124 static inline void
125 hacr_write(u_long ioaddr,
126 u_short hacr)
128 outw(hacr, HACR(ioaddr));
129 } /* hacr_write */
131 /*------------------------------------------------------------------*/
133 * Write to card's Host Adapter Command Register. Include a delay for
134 * those times when it is needed.
136 static inline void
137 hacr_write_slow(u_long ioaddr,
138 u_short hacr)
140 hacr_write(ioaddr, hacr);
141 /* delay might only be needed sometimes */
142 mdelay(1);
143 } /* hacr_write_slow */
145 /*------------------------------------------------------------------*/
147 * Set the channel attention bit.
149 static inline void
150 set_chan_attn(u_long ioaddr,
151 u_short hacr)
153 hacr_write(ioaddr, hacr | HACR_CA);
154 } /* set_chan_attn */
156 /*------------------------------------------------------------------*/
158 * Reset, and then set host adaptor into default mode.
160 static inline void
161 wv_hacr_reset(u_long ioaddr)
163 hacr_write_slow(ioaddr, HACR_RESET);
164 hacr_write(ioaddr, HACR_DEFAULT);
165 } /* wv_hacr_reset */
167 /*------------------------------------------------------------------*/
169 * Set the I/O transfer over the ISA bus to 8-bit mode
171 static inline void
172 wv_16_off(u_long ioaddr,
173 u_short hacr)
175 hacr &= ~HACR_16BITS;
176 hacr_write(ioaddr, hacr);
177 } /* wv_16_off */
179 /*------------------------------------------------------------------*/
181 * Set the I/O transfer over the ISA bus to 8-bit mode
183 static inline void
184 wv_16_on(u_long ioaddr,
185 u_short hacr)
187 hacr |= HACR_16BITS;
188 hacr_write(ioaddr, hacr);
189 } /* wv_16_on */
191 /*------------------------------------------------------------------*/
193 * Disable interrupts on the WaveLAN hardware.
195 static inline void
196 wv_ints_off(device * dev)
198 net_local * lp = (net_local *)dev->priv;
199 u_long ioaddr = dev->base_addr;
200 u_long x;
202 x = wv_splhi();
204 lp->hacr &= ~HACR_INTRON;
205 hacr_write(ioaddr, lp->hacr);
207 wv_splx(x);
208 } /* wv_ints_off */
210 /*------------------------------------------------------------------*/
212 * Enable interrupts on the WaveLAN hardware.
214 static inline void
215 wv_ints_on(device * dev)
217 net_local * lp = (net_local *)dev->priv;
218 u_long ioaddr = dev->base_addr;
219 u_long x;
221 x = wv_splhi();
223 lp->hacr |= HACR_INTRON;
224 hacr_write(ioaddr, lp->hacr);
226 wv_splx(x);
227 } /* wv_ints_on */
229 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
231 * Useful subroutines to manage the modem of the WaveLAN
234 /*------------------------------------------------------------------*/
236 * Read the Parameter Storage Area from the WaveLAN card's memory
239 * Read bytes from the PSA.
241 static void
242 psa_read(u_long ioaddr,
243 u_short hacr,
244 int o, /* offset in PSA */
245 u_char * b, /* buffer to fill */
246 int n) /* size to read */
248 wv_16_off(ioaddr, hacr);
250 while(n-- > 0)
252 outw(o, PIOR2(ioaddr));
253 o++;
254 *b++ = inb(PIOP2(ioaddr));
257 wv_16_on(ioaddr, hacr);
258 } /* psa_read */
260 /*------------------------------------------------------------------*/
262 * Write the Parameter Storage Area to the WaveLAN card's memory.
264 static void
265 psa_write(u_long ioaddr,
266 u_short hacr,
267 int o, /* Offset in PSA */
268 u_char * b, /* Buffer in memory */
269 int n) /* Length of buffer */
271 int count = 0;
273 wv_16_off(ioaddr, hacr);
275 while(n-- > 0)
277 outw(o, PIOR2(ioaddr));
278 o++;
280 outb(*b, PIOP2(ioaddr));
281 b++;
283 /* Wait for the memory to finish its write cycle */
284 count = 0;
285 while((count++ < 100) &&
286 (hasr_read(ioaddr) & HASR_PSA_BUSY))
287 mdelay(1);
290 wv_16_on(ioaddr, hacr);
291 } /* psa_write */
293 #ifdef SET_PSA_CRC
294 /*------------------------------------------------------------------*/
296 * Calculate the PSA CRC
297 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
298 * NOTE: By specifying a length including the CRC position the
299 * returned value should be zero. (i.e. a correct checksum in the PSA)
301 * The Windows drivers don't use the CRC, but the AP and the PtP tool
302 * depend on it.
304 static inline u_short
305 psa_crc(u_char * psa, /* The PSA */
306 int size) /* Number of short for CRC */
308 int byte_cnt; /* Loop on the PSA */
309 u_short crc_bytes = 0; /* Data in the PSA */
310 int bit_cnt; /* Loop on the bits of the short */
312 for(byte_cnt = 0; byte_cnt < size; byte_cnt++ )
314 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
316 for(bit_cnt = 1; bit_cnt < 9; bit_cnt++ )
318 if(crc_bytes & 0x0001)
319 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
320 else
321 crc_bytes >>= 1 ;
325 return crc_bytes;
326 } /* psa_crc */
327 #endif /* SET_PSA_CRC */
329 /*------------------------------------------------------------------*/
331 * update the checksum field in the Wavelan's PSA
333 static void
334 update_psa_checksum(device * dev,
335 u_long ioaddr,
336 u_short hacr)
338 #ifdef SET_PSA_CRC
339 psa_t psa;
340 u_short crc;
342 /* read the parameter storage area */
343 psa_read(ioaddr, hacr, 0, (unsigned char *) &psa, sizeof(psa));
345 /* update the checksum */
346 crc = psa_crc((unsigned char *) &psa,
347 sizeof(psa) - sizeof(psa.psa_crc[0]) - sizeof(psa.psa_crc[1])
348 - sizeof(psa.psa_crc_status));
350 psa.psa_crc[0] = crc & 0xFF;
351 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
353 /* Write it ! */
354 psa_write(ioaddr, hacr, (char *)&psa.psa_crc - (char *)&psa,
355 (unsigned char *)&psa.psa_crc, 2);
357 #ifdef DEBUG_IOCTL_INFO
358 printk (KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
359 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
361 /* Check again (luxury !) */
362 crc = psa_crc ((unsigned char *) &psa,
363 sizeof(psa) - sizeof(psa.psa_crc_status));
365 if(crc != 0)
366 printk(KERN_WARNING "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", dev->name);
367 #endif /* DEBUG_IOCTL_INFO */
368 #endif /* SET_PSA_CRC */
369 } /* update_psa_checksum */
371 /*------------------------------------------------------------------*/
373 * Write 1 byte to the MMC.
375 static inline void
376 mmc_out(u_long ioaddr,
377 u_short o,
378 u_char d)
380 /* Wait for MMC to go idle */
381 while(inw(HASR(ioaddr)) & HASR_MMC_BUSY)
384 outw((u_short) (((u_short) d << 8) | (o << 1) | 1),
385 MMCR(ioaddr));
388 /*------------------------------------------------------------------*/
390 * Routine to write bytes to the Modem Management Controller.
391 * We start at the end because it is the way it should be!
393 static inline void
394 mmc_write(u_long ioaddr,
395 u_char o,
396 u_char * b,
397 int n)
399 o += n;
400 b += n;
402 while(n-- > 0 )
403 mmc_out(ioaddr, --o, *(--b));
404 } /* mmc_write */
406 /*------------------------------------------------------------------*/
408 * Read a byte from the MMC.
409 * Optimised version for 1 byte, avoid using memory.
411 static inline u_char
412 mmc_in(u_long ioaddr,
413 u_short o)
415 while(inw(HASR(ioaddr)) & HASR_MMC_BUSY)
417 outw(o << 1, MMCR(ioaddr));
419 while(inw(HASR(ioaddr)) & HASR_MMC_BUSY)
421 return (u_char) (inw(MMCR(ioaddr)) >> 8);
424 /*------------------------------------------------------------------*/
426 * Routine to read bytes from the Modem Management Controller.
427 * The implementation is complicated by a lack of address lines,
428 * which prevents decoding of the low-order bit.
429 * (code has just been moved in the above function)
430 * We start at the end because it is the way it should be!
432 static inline void
433 mmc_read(u_long ioaddr,
434 u_char o,
435 u_char * b,
436 int n)
438 o += n;
439 b += n;
441 while(n-- > 0)
442 *(--b) = mmc_in(ioaddr, --o);
443 } /* mmc_read */
445 /*------------------------------------------------------------------*/
447 * Get the type of encryption available.
449 static inline int
450 mmc_encr(u_long ioaddr) /* I/O port of the card */
452 int temp;
454 temp = mmc_in(ioaddr, mmroff(0, mmr_des_avail));
455 if((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
456 return 0;
457 else
458 return temp;
461 /*------------------------------------------------------------------*/
463 * Wait for the frequency EEPROM to complete a command.
464 * I hope this one will be optimally inlined.
466 static inline void
467 fee_wait(u_long ioaddr, /* I/O port of the card */
468 int delay, /* Base delay to wait for */
469 int number) /* Number of time to wait */
471 int count = 0; /* Wait only a limited time */
473 while((count++ < number) &&
474 (mmc_in(ioaddr, mmroff(0, mmr_fee_status)) & MMR_FEE_STATUS_BUSY))
475 udelay(delay);
478 /*------------------------------------------------------------------*/
480 * Read bytes from the Frequency EEPROM (frequency select cards).
482 static void
483 fee_read(u_long ioaddr, /* I/O port of the card */
484 u_short o, /* destination offset */
485 u_short * b, /* data buffer */
486 int n) /* number of registers */
488 b += n; /* Position at the end of the area */
490 /* Write the address */
491 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
493 /* Loop on all buffer */
494 while(n-- > 0)
496 /* Write the read command */
497 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_READ);
499 /* Wait until EEPROM is ready (should be quick). */
500 fee_wait(ioaddr, 10, 100);
502 /* Read the value. */
503 *--b = ((mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)) << 8) |
504 mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
508 #ifdef WIRELESS_EXT /* if the wireless extension exists in the kernel */
510 /*------------------------------------------------------------------*/
512 * Write bytes from the Frequency EEPROM (frequency select cards).
513 * This is a bit complicated, because the frequency EEPROM has to
514 * be unprotected and the write enabled.
515 * Jean II
517 static void
518 fee_write(u_long ioaddr, /* I/O port of the card */
519 u_short o, /* destination offset */
520 u_short * b, /* data buffer */
521 int n) /* number of registers */
523 b += n; /* Position at the end of the area. */
525 #ifdef EEPROM_IS_PROTECTED /* disabled */
526 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
527 /* Ask to read the protected register */
528 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
530 fee_wait(ioaddr, 10, 100);
532 /* Read the protected register. */
533 printk("Protected 2: %02X-%02X\n",
534 mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)),
535 mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
536 #endif /* DOESNT_SEEM_TO_WORK */
538 /* Enable protected register. */
539 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
540 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
542 fee_wait(ioaddr, 10, 100);
544 /* Unprotect area. */
545 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n);
546 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
547 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
548 /* or use: */
549 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
550 #endif /* DOESNT_SEEM_TO_WORK */
552 fee_wait(ioaddr, 10, 100);
553 #endif /* EEPROM_IS_PROTECTED */
555 /* Write enable. */
556 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
557 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
559 fee_wait(ioaddr, 10, 100);
561 /* Write the EEPROM address. */
562 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
564 /* Loop on all buffer */
565 while(n-- > 0)
567 /* Write the value. */
568 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
569 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
571 /* Write the write command. */
572 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WRITE);
574 /* WaveLAN documentation says to wait at least 10 ms for EEBUSY = 0 */
575 mdelay(10);
576 fee_wait(ioaddr, 10, 100);
579 /* Write disable. */
580 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
581 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
583 fee_wait(ioaddr, 10, 100);
585 #ifdef EEPROM_IS_PROTECTED /* disabled */
586 /* Reprotect EEPROM. */
587 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x00);
588 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
590 fee_wait(ioaddr, 10, 100);
591 #endif /* EEPROM_IS_PROTECTED */
593 #endif /* WIRELESS_EXT */
595 /************************ I82586 SUBROUTINES *************************/
597 * Useful subroutines to manage the Ethernet controller
600 /*------------------------------------------------------------------*/
602 * Read bytes from the on-board RAM.
603 * Why does inlining this function make it fail?
605 static /*inline*/ void
606 obram_read(u_long ioaddr,
607 u_short o,
608 u_char * b,
609 int n)
611 outw(o, PIOR1(ioaddr));
612 insw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
615 /*------------------------------------------------------------------*/
617 * Write bytes to the on-board RAM.
619 static inline void
620 obram_write(u_long ioaddr,
621 u_short o,
622 u_char * b,
623 int n)
625 outw(o, PIOR1(ioaddr));
626 outsw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
629 /*------------------------------------------------------------------*/
631 * Acknowledge the reading of the status issued by the i82586.
633 static void
634 wv_ack(device * dev)
636 net_local * lp = (net_local *)dev->priv;
637 u_long ioaddr = dev->base_addr;
638 u_short scb_cs;
639 int i;
641 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
642 (unsigned char *) &scb_cs, sizeof(scb_cs));
643 scb_cs &= SCB_ST_INT;
645 if(scb_cs == 0)
646 return;
648 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
649 (unsigned char *) &scb_cs, sizeof(scb_cs));
651 set_chan_attn(ioaddr, lp->hacr);
653 for(i = 1000; i > 0; i--)
655 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cs, sizeof(scb_cs));
656 if(scb_cs == 0)
657 break;
659 udelay(10);
661 udelay(100);
663 #ifdef DEBUG_CONFIG_ERROR
664 if(i <= 0)
665 printk(KERN_INFO "%s: wv_ack(): board not accepting command.\n",
666 dev->name);
667 #endif
670 /*------------------------------------------------------------------*/
672 * Set channel attention bit and busy wait until command has
673 * completed, then acknowledge completion of the command.
675 static inline int
676 wv_synchronous_cmd(device * dev,
677 const char * str)
679 net_local * lp = (net_local *)dev->priv;
680 u_long ioaddr = dev->base_addr;
681 u_short scb_cmd;
682 ach_t cb;
683 int i;
685 scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO;
686 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
687 (unsigned char *) &scb_cmd, sizeof(scb_cmd));
689 set_chan_attn(ioaddr, lp->hacr);
691 for (i = 1000; i > 0; i--)
693 obram_read(ioaddr, OFFSET_CU, (unsigned char *)&cb, sizeof(cb));
694 if (cb.ac_status & AC_SFLD_C)
695 break;
697 udelay(10);
699 udelay(100);
701 if(i <= 0 || !(cb.ac_status & AC_SFLD_OK))
703 #ifdef DEBUG_CONFIG_ERROR
704 printk(KERN_INFO "%s: %s failed; status = 0x%x\n",
705 dev->name, str, cb.ac_status);
706 #endif
707 #ifdef DEBUG_I82586_SHOW
708 wv_scb_show(ioaddr);
709 #endif
710 return -1;
713 /* Ack the status */
714 wv_ack(dev);
716 return 0;
719 /*------------------------------------------------------------------*/
721 * Configuration commands completion interrupt.
722 * Check if done, and if OK.
724 static inline int
725 wv_config_complete(device * dev,
726 u_long ioaddr,
727 net_local * lp)
729 unsigned short mcs_addr;
730 unsigned short status;
731 int ret;
733 #ifdef DEBUG_INTERRUPT_TRACE
734 printk(KERN_DEBUG "%s: ->wv_config_complete()\n", dev->name);
735 #endif
737 mcs_addr = lp->tx_first_in_use + sizeof(ac_tx_t) + sizeof(ac_nop_t)
738 + sizeof(tbd_t) + sizeof(ac_cfg_t) + sizeof(ac_ias_t);
740 /* Read the status of the last command (set mc list). */
741 obram_read(ioaddr, acoff(mcs_addr, ac_status), (unsigned char *)&status, sizeof(status));
743 /* If not completed -> exit */
744 if((status & AC_SFLD_C) == 0)
745 ret = 0; /* Not ready to be scrapped */
746 else
748 #ifdef DEBUG_CONFIG_ERROR
749 unsigned short cfg_addr;
750 unsigned short ias_addr;
752 /* Check mc_config command */
753 if((status & AC_SFLD_OK) != AC_SFLD_OK)
754 printk(KERN_INFO "%s: wv_config_complete(): set_multicast_address failed; status = 0x%x\n",
755 dev->name, status);
757 /* check ia-config command */
758 ias_addr = mcs_addr - sizeof(ac_ias_t);
759 obram_read(ioaddr, acoff(ias_addr, ac_status), (unsigned char *)&status, sizeof(status));
760 if((status & AC_SFLD_OK) != AC_SFLD_OK)
761 printk(KERN_INFO "%s: wv_config_complete(): set_MAC_address failed; status = 0x%x\n",
762 dev->name, status);
764 /* Check config command. */
765 cfg_addr = ias_addr - sizeof(ac_cfg_t);
766 obram_read(ioaddr, acoff(cfg_addr, ac_status), (unsigned char *)&status, sizeof(status));
767 if((status & AC_SFLD_OK) != AC_SFLD_OK)
768 printk(KERN_INFO "%s: wv_config_complete(): configure failed; status = 0x%x\n",
769 dev->name, status);
770 #endif /* DEBUG_CONFIG_ERROR */
772 ret = 1; /* Ready to be scrapped */
775 #ifdef DEBUG_INTERRUPT_TRACE
776 printk(KERN_DEBUG "%s: <-wv_config_complete() - %d\n", dev->name, ret);
777 #endif
778 return ret;
781 /*------------------------------------------------------------------*/
783 * Command completion interrupt.
784 * Reclaim as many freed tx buffers as we can.
786 static int
787 wv_complete(device * dev,
788 u_long ioaddr,
789 net_local * lp)
791 int nreaped = 0;
793 #ifdef DEBUG_INTERRUPT_TRACE
794 printk(KERN_DEBUG "%s: ->wv_complete()\n", dev->name);
795 #endif
797 /* Loop on all the transmit buffers */
798 while(lp->tx_first_in_use != I82586NULL)
800 unsigned short tx_status;
802 /* Read the first transmit buffer */
803 obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status), (unsigned char *)&tx_status, sizeof(tx_status));
805 /* If not completed -> exit */
806 if((tx_status & AC_SFLD_C) == 0)
807 break;
809 /* Hack for reconfiguration */
810 if(tx_status == 0xFFFF)
811 if(!wv_config_complete(dev, ioaddr, lp))
812 break; /* Not completed */
814 /* We now remove this buffer */
815 nreaped++;
816 --lp->tx_n_in_use;
819 if (lp->tx_n_in_use > 0)
820 printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
823 /* Was it the last one? */
824 if(lp->tx_n_in_use <= 0)
825 lp->tx_first_in_use = I82586NULL;
826 else
828 /* Next one in the chain */
829 lp->tx_first_in_use += TXBLOCKZ;
830 if(lp->tx_first_in_use >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
831 lp->tx_first_in_use -= NTXBLOCKS * TXBLOCKZ;
834 /* Hack for reconfiguration */
835 if(tx_status == 0xFFFF)
836 continue;
838 /* Now, check status of the finished command */
839 if(tx_status & AC_SFLD_OK)
841 int ncollisions;
843 lp->stats.tx_packets++;
844 ncollisions = tx_status & AC_SFLD_MAXCOL;
845 lp->stats.collisions += ncollisions;
846 #ifdef DEBUG_TX_INFO
847 if(ncollisions > 0)
848 printk(KERN_DEBUG "%s: wv_complete(): tx completed after %d collisions.\n",
849 dev->name, ncollisions);
850 #endif
852 else
854 lp->stats.tx_errors++;
855 if(tx_status & AC_SFLD_S10)
857 lp->stats.tx_carrier_errors++;
858 #ifdef DEBUG_TX_FAIL
859 printk(KERN_DEBUG "%s: wv_complete(): tx error: no CS.\n",
860 dev->name);
861 #endif
863 if(tx_status & AC_SFLD_S9)
865 lp->stats.tx_carrier_errors++;
866 #ifdef DEBUG_TX_FAIL
867 printk(KERN_DEBUG "%s: wv_complete(): tx error: lost CTS.\n",
868 dev->name);
869 #endif
871 if(tx_status & AC_SFLD_S8)
873 lp->stats.tx_fifo_errors++;
874 #ifdef DEBUG_TX_FAIL
875 printk(KERN_DEBUG "%s: wv_complete(): tx error: slow DMA.\n",
876 dev->name);
877 #endif
879 if(tx_status & AC_SFLD_S6)
881 lp->stats.tx_heartbeat_errors++;
882 #ifdef DEBUG_TX_FAIL
883 printk(KERN_DEBUG "%s: wv_complete(): tx error: heart beat.\n",
884 dev->name);
885 #endif
887 if(tx_status & AC_SFLD_S5)
889 lp->stats.tx_aborted_errors++;
890 #ifdef DEBUG_TX_FAIL
891 printk(KERN_DEBUG "%s: wv_complete(): tx error: too many collisions.\n",
892 dev->name);
893 #endif
897 #ifdef DEBUG_TX_INFO
898 printk(KERN_DEBUG "%s: wv_complete(): tx completed, tx_status 0x%04x\n",
899 dev->name, tx_status);
900 #endif
903 #ifdef DEBUG_INTERRUPT_INFO
904 if(nreaped > 1)
905 printk(KERN_DEBUG "%s: wv_complete(): reaped %d\n", dev->name, nreaped);
906 #endif
909 * Inform upper layers.
911 if(lp->tx_n_in_use < NTXBLOCKS - 1)
913 dev->tbusy = 0;
914 mark_bh(NET_BH);
917 #ifdef DEBUG_INTERRUPT_TRACE
918 printk(KERN_DEBUG "%s: <-wv_complete()\n", dev->name);
919 #endif
920 return nreaped;
923 /*------------------------------------------------------------------*/
925 * Reconfigure the i82586, or at least ask for it.
926 * Because wv_82586_config uses a transmission buffer, we must do it
927 * when we are sure that there is one left, so we do it now
928 * or in wavelan_packet_xmit() (I can't find any better place,
929 * wavelan_interrupt is not an option), so you may experience
930 * delays sometimes.
932 static inline void
933 wv_82586_reconfig(device * dev)
935 net_local * lp = (net_local *)dev->priv;
937 /* Check if we can do it now ! */
938 if(!(dev->start) || (test_and_set_bit(0, (void *)&dev->tbusy) != 0))
940 lp->reconfig_82586 = 1;
941 #ifdef DEBUG_CONFIG_INFO
942 printk(KERN_DEBUG "%s: wv_82586_reconfig(): delayed (busy = %ld, start = %d)\n",
943 dev->name, dev->tbusy, dev->start);
944 #endif
946 else
947 wv_82586_config(dev);
950 /********************* DEBUG & INFO SUBROUTINES *********************/
952 * This routine is used in the code to show information for debugging.
953 * Most of the time, it dumps the contents of hardware structures.
956 #ifdef DEBUG_PSA_SHOW
957 /*------------------------------------------------------------------*/
959 * Print the formatted contents of the Parameter Storage Area.
961 static void
962 wv_psa_show(psa_t * p)
964 printk(KERN_DEBUG "##### WaveLAN PSA contents: #####\n");
965 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
966 p->psa_io_base_addr_1,
967 p->psa_io_base_addr_2,
968 p->psa_io_base_addr_3,
969 p->psa_io_base_addr_4);
970 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
971 p->psa_rem_boot_addr_1,
972 p->psa_rem_boot_addr_2,
973 p->psa_rem_boot_addr_3);
974 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
975 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
976 #ifdef DEBUG_SHOW_UNUSED
977 printk(KERN_DEBUG "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
978 p->psa_unused0[0],
979 p->psa_unused0[1],
980 p->psa_unused0[2],
981 p->psa_unused0[3],
982 p->psa_unused0[4],
983 p->psa_unused0[5],
984 p->psa_unused0[6]);
985 #endif /* DEBUG_SHOW_UNUSED */
986 printk(KERN_DEBUG "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
987 p->psa_univ_mac_addr[0],
988 p->psa_univ_mac_addr[1],
989 p->psa_univ_mac_addr[2],
990 p->psa_univ_mac_addr[3],
991 p->psa_univ_mac_addr[4],
992 p->psa_univ_mac_addr[5]);
993 printk(KERN_DEBUG "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
994 p->psa_local_mac_addr[0],
995 p->psa_local_mac_addr[1],
996 p->psa_local_mac_addr[2],
997 p->psa_local_mac_addr[3],
998 p->psa_local_mac_addr[4],
999 p->psa_local_mac_addr[5]);
1000 printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel);
1001 printk("psa_comp_number: %d, ", p->psa_comp_number);
1002 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
1003 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
1004 p->psa_feature_select);
1005 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
1006 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
1007 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
1008 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]);
1009 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
1010 printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select);
1011 printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1012 p->psa_encryption_key[0],
1013 p->psa_encryption_key[1],
1014 p->psa_encryption_key[2],
1015 p->psa_encryption_key[3],
1016 p->psa_encryption_key[4],
1017 p->psa_encryption_key[5],
1018 p->psa_encryption_key[6],
1019 p->psa_encryption_key[7]);
1020 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
1021 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
1022 p->psa_call_code[0]);
1023 printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1024 p->psa_call_code[0],
1025 p->psa_call_code[1],
1026 p->psa_call_code[2],
1027 p->psa_call_code[3],
1028 p->psa_call_code[4],
1029 p->psa_call_code[5],
1030 p->psa_call_code[6],
1031 p->psa_call_code[7]);
1032 #ifdef DEBUG_SHOW_UNUSED
1033 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
1034 p->psa_reserved[0],
1035 p->psa_reserved[1],
1036 p->psa_reserved[2],
1037 p->psa_reserved[3]);
1038 #endif /* DEBUG_SHOW_UNUSED */
1039 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
1040 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
1041 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
1042 } /* wv_psa_show */
1043 #endif /* DEBUG_PSA_SHOW */
1045 #ifdef DEBUG_MMC_SHOW
1046 /*------------------------------------------------------------------*/
1048 * Print the formatted status of the Modem Management Controller.
1049 * This function needs to be completed.
1051 static void
1052 wv_mmc_show(device * dev)
1054 u_long ioaddr = dev->base_addr;
1055 net_local * lp = (net_local *)dev->priv;
1056 mmr_t m;
1058 /* Basic check */
1059 if(hasr_read(ioaddr) & HASR_NO_CLK)
1061 printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n",
1062 dev->name);
1063 return;
1066 /* Read the mmc */
1067 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
1068 mmc_read(ioaddr, 0, (u_char *)&m, sizeof(m));
1069 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
1071 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
1072 /* Don't forget to update statistics */
1073 lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
1074 #endif /* WIRELESS_EXT */
1076 printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n");
1077 #ifdef DEBUG_SHOW_UNUSED
1078 printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1079 m.mmr_unused0[0],
1080 m.mmr_unused0[1],
1081 m.mmr_unused0[2],
1082 m.mmr_unused0[3],
1083 m.mmr_unused0[4],
1084 m.mmr_unused0[5],
1085 m.mmr_unused0[6],
1086 m.mmr_unused0[7]);
1087 #endif /* DEBUG_SHOW_UNUSED */
1088 printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
1089 m.mmr_des_avail, m.mmr_des_status);
1090 #ifdef DEBUG_SHOW_UNUSED
1091 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1092 m.mmr_unused1[0],
1093 m.mmr_unused1[1],
1094 m.mmr_unused1[2],
1095 m.mmr_unused1[3],
1096 m.mmr_unused1[4]);
1097 #endif /* DEBUG_SHOW_UNUSED */
1098 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1099 m.mmr_dce_status,
1100 (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"",
1101 (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1102 "loop test indicated," : "",
1103 (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "",
1104 (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1105 "jabber timer expired," : "");
1106 printk(KERN_DEBUG "Dsp ID: %02X\n",
1107 m.mmr_dsp_id);
1108 #ifdef DEBUG_SHOW_UNUSED
1109 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1110 m.mmr_unused2[0],
1111 m.mmr_unused2[1]);
1112 #endif /* DEBUG_SHOW_UNUSED */
1113 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1114 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1115 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1116 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1117 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1118 (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below");
1119 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1120 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1121 (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg");
1122 printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL,
1123 (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update");
1124 printk("sgnl_qual: 0x%x [%s]\n",
1125 m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1126 (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0");
1127 #ifdef DEBUG_SHOW_UNUSED
1128 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1129 #endif /* DEBUG_SHOW_UNUSED */
1130 } /* wv_mmc_show */
1131 #endif /* DEBUG_MMC_SHOW */
1133 #ifdef DEBUG_I82586_SHOW
1134 /*------------------------------------------------------------------*/
1136 * Print the last block of the i82586 memory.
1138 static void
1139 wv_scb_show(u_long ioaddr)
1141 scb_t scb;
1143 obram_read(ioaddr, OFFSET_SCB, (unsigned char *)&scb, sizeof(scb));
1145 printk(KERN_DEBUG "##### WaveLAN system control block: #####\n");
1147 printk(KERN_DEBUG "status: ");
1148 printk("stat 0x%x[%s%s%s%s] ",
1149 (scb.scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA | SCB_ST_RNR)) >> 12,
1150 (scb.scb_status & SCB_ST_CX) ? "command completion interrupt," : "",
1151 (scb.scb_status & SCB_ST_FR) ? "frame received," : "",
1152 (scb.scb_status & SCB_ST_CNA) ? "command unit not active," : "",
1153 (scb.scb_status & SCB_ST_RNR) ? "receiving unit not ready," : "");
1154 printk("cus 0x%x[%s%s%s] ",
1155 (scb.scb_status & SCB_ST_CUS) >> 8,
1156 ((scb.scb_status & SCB_ST_CUS) == SCB_ST_CUS_IDLE) ? "idle" : "",
1157 ((scb.scb_status & SCB_ST_CUS) == SCB_ST_CUS_SUSP) ? "suspended" : "",
1158 ((scb.scb_status & SCB_ST_CUS) == SCB_ST_CUS_ACTV) ? "active" : "");
1159 printk("rus 0x%x[%s%s%s%s]\n",
1160 (scb.scb_status & SCB_ST_RUS) >> 4,
1161 ((scb.scb_status & SCB_ST_RUS) == SCB_ST_RUS_IDLE) ? "idle" : "",
1162 ((scb.scb_status & SCB_ST_RUS) == SCB_ST_RUS_SUSP) ? "suspended" : "",
1163 ((scb.scb_status & SCB_ST_RUS) == SCB_ST_RUS_NRES) ? "no resources" : "",
1164 ((scb.scb_status & SCB_ST_RUS) == SCB_ST_RUS_RDY) ? "ready" : "");
1166 printk(KERN_DEBUG "command: ");
1167 printk("ack 0x%x[%s%s%s%s] ",
1168 (scb.scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR | SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12,
1169 (scb.scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "",
1170 (scb.scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "",
1171 (scb.scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "",
1172 (scb.scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : "");
1173 printk("cuc 0x%x[%s%s%s%s%s] ",
1174 (scb.scb_command & SCB_CMD_CUC) >> 8,
1175 ((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_NOP) ? "nop" : "",
1176 ((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_GO) ? "start cbl_offset" : "",
1177 ((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_RES) ? "resume execution" : "",
1178 ((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_SUS) ? "suspend execution" : "",
1179 ((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_ABT) ? "abort execution" : "");
1180 printk("ruc 0x%x[%s%s%s%s%s]\n",
1181 (scb.scb_command & SCB_CMD_RUC) >> 4,
1182 ((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_NOP) ? "nop" : "",
1183 ((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_GO) ? "start rfa_offset" : "",
1184 ((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_RES) ? "resume reception" : "",
1185 ((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_SUS) ? "suspend reception" : "",
1186 ((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_ABT) ? "abort reception" : "");
1188 printk(KERN_DEBUG "cbl_offset 0x%x ", scb.scb_cbl_offset);
1189 printk("rfa_offset 0x%x\n", scb.scb_rfa_offset);
1191 printk(KERN_DEBUG "crcerrs %d ", scb.scb_crcerrs);
1192 printk("alnerrs %d ", scb.scb_alnerrs);
1193 printk("rscerrs %d ", scb.scb_rscerrs);
1194 printk("ovrnerrs %d\n", scb.scb_ovrnerrs);
1197 /*------------------------------------------------------------------*/
1199 * Print the formatted status of the i82586's receive unit.
1201 static void
1202 wv_ru_show(device * dev)
1204 /* net_local *lp = (net_local *) dev->priv; */
1206 printk(KERN_DEBUG "##### WaveLAN i82586 receiver unit status: #####\n");
1207 printk(KERN_DEBUG "ru:");
1209 * Not implemented yet
1211 printk("\n");
1212 } /* wv_ru_show */
1214 /*------------------------------------------------------------------*/
1216 * Display info about one control block of the i82586 memory.
1218 static void
1219 wv_cu_show_one(device * dev,
1220 net_local * lp,
1221 int i,
1222 u_short p)
1224 u_long ioaddr;
1225 ac_tx_t actx;
1227 ioaddr = dev->base_addr;
1229 printk("%d: 0x%x:", i, p);
1231 obram_read(ioaddr, p, (unsigned char *)&actx, sizeof(actx));
1232 printk(" status=0x%x,", actx.tx_h.ac_status);
1233 printk(" command=0x%x,", actx.tx_h.ac_command);
1237 tbd_t tbd;
1239 obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
1240 printk(" tbd_status=0x%x,", tbd.tbd_status);
1244 printk("|");
1247 /*------------------------------------------------------------------*/
1249 * Print status of the command unit of the i82586.
1251 static void
1252 wv_cu_show(device * dev)
1254 net_local * lp = (net_local *)dev->priv;
1255 unsigned int i;
1256 u_short p;
1258 printk(KERN_DEBUG "##### WaveLAN i82586 command unit status: #####\n");
1260 printk(KERN_DEBUG);
1261 for(i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++)
1263 wv_cu_show_one(dev, lp, i, p);
1265 p += TXBLOCKZ;
1266 if(p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
1267 p -= NTXBLOCKS * TXBLOCKZ;
1269 printk("\n");
1271 #endif /* DEBUG_I82586_SHOW */
1273 #ifdef DEBUG_DEVICE_SHOW
1274 /*------------------------------------------------------------------*/
1276 * Print the formatted status of the WaveLAN PCMCIA device driver.
1278 static void
1279 wv_dev_show(device * dev)
1281 printk(KERN_DEBUG "dev:");
1282 printk(" start=%d,", dev->start);
1283 printk(" tbusy=%ld,", dev->tbusy);
1284 printk(" interrupt=%d,", dev->interrupt);
1285 printk(" trans_start=%ld,", dev->trans_start);
1286 printk(" flags=0x%x,", dev->flags);
1287 printk("\n");
1288 } /* wv_dev_show */
1290 /*------------------------------------------------------------------*/
1292 * Print the formatted status of the WaveLAN PCMCIA device driver's
1293 * private information.
1295 static void
1296 wv_local_show(device * dev)
1298 net_local *lp;
1300 lp = (net_local *)dev->priv;
1302 printk(KERN_DEBUG "local:");
1303 printk(" tx_n_in_use=%d,", lp->tx_n_in_use);
1304 printk(" hacr=0x%x,", lp->hacr);
1305 printk(" rx_head=0x%x,", lp->rx_head);
1306 printk(" rx_last=0x%x,", lp->rx_last);
1307 printk(" tx_first_free=0x%x,", lp->tx_first_free);
1308 printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use);
1309 printk("\n");
1310 } /* wv_local_show */
1311 #endif /* DEBUG_DEVICE_SHOW */
1313 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1314 /*------------------------------------------------------------------*/
1316 * Dump packet header (and content if necessary) on the screen
1318 static inline void
1319 wv_packet_info(u_char * p, /* Packet to dump */
1320 int length, /* Length of the packet */
1321 char * msg1, /* Name of the device */
1322 char * msg2) /* Name of the function */
1324 int i;
1325 int maxi;
1327 printk(KERN_DEBUG "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1328 msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1329 printk(KERN_DEBUG "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1330 msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13]);
1332 #ifdef DEBUG_PACKET_DUMP
1334 printk(KERN_DEBUG "data=\"");
1336 if((maxi = length) > DEBUG_PACKET_DUMP)
1337 maxi = DEBUG_PACKET_DUMP;
1338 for(i = 14; i < maxi; i++)
1339 if(p[i] >= ' ' && p[i] <= '~')
1340 printk(" %c", p[i]);
1341 else
1342 printk("%02X", p[i]);
1343 if(maxi < length)
1344 printk("..");
1345 printk("\"\n");
1346 printk(KERN_DEBUG "\n");
1347 #endif /* DEBUG_PACKET_DUMP */
1349 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1351 /*------------------------------------------------------------------*/
1353 * This is the information which is displayed by the driver at startup.
1354 * There are lots of flags for configuring it to your liking.
1356 static inline void
1357 wv_init_info(device * dev)
1359 short ioaddr = dev->base_addr;
1360 net_local * lp = (net_local *)dev->priv;
1361 psa_t psa;
1362 int i;
1364 /* Read the parameter storage area */
1365 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
1367 #ifdef DEBUG_PSA_SHOW
1368 wv_psa_show(&psa);
1369 #endif
1370 #ifdef DEBUG_MMC_SHOW
1371 wv_mmc_show(dev);
1372 #endif
1373 #ifdef DEBUG_I82586_SHOW
1374 wv_cu_show(dev);
1375 #endif
1377 #ifdef DEBUG_BASIC_SHOW
1378 /* Now, let's go for the basic stuff. */
1379 printk(KERN_NOTICE "%s: WaveLAN at %#x,", dev->name, ioaddr);
1380 for(i = 0; i < WAVELAN_ADDR_SIZE; i++)
1381 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1382 printk(", IRQ %d", dev->irq);
1384 /* Print current network ID. */
1385 if(psa.psa_nwid_select)
1386 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
1387 else
1388 printk(", nwid off");
1390 /* If 2.00 card */
1391 if(!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1392 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1394 unsigned short freq;
1396 /* Ask the EEPROM to read the frequency from the first area. */
1397 fee_read(ioaddr, 0x00, &freq, 1);
1399 /* Print frequency */
1400 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1402 /* Hack! */
1403 if(freq & 0x20)
1404 printk(".5");
1406 else
1408 printk(", PC");
1409 switch(psa.psa_comp_number)
1411 case PSA_COMP_PC_AT_915:
1412 case PSA_COMP_PC_AT_2400:
1413 printk("-AT");
1414 break;
1415 case PSA_COMP_PC_MC_915:
1416 case PSA_COMP_PC_MC_2400:
1417 printk("-MC");
1418 break;
1419 case PSA_COMP_PCMCIA_915:
1420 printk("MCIA");
1421 break;
1422 default:
1423 printk("?");
1425 printk(", ");
1426 switch (psa.psa_subband)
1428 case PSA_SUBBAND_915:
1429 printk("915");
1430 break;
1431 case PSA_SUBBAND_2425:
1432 printk("2425");
1433 break;
1434 case PSA_SUBBAND_2460:
1435 printk("2460");
1436 break;
1437 case PSA_SUBBAND_2484:
1438 printk("2484");
1439 break;
1440 case PSA_SUBBAND_2430_5:
1441 printk("2430.5");
1442 break;
1443 default:
1444 printk("?");
1448 printk(" MHz\n");
1449 #endif /* DEBUG_BASIC_SHOW */
1451 #ifdef DEBUG_VERSION_SHOW
1452 /* Print version information */
1453 printk(KERN_NOTICE "%s", version);
1454 #endif
1455 } /* wv_init_info */
1457 /********************* IOCTL, STATS & RECONFIG *********************/
1459 * We found here routines that are called by Linux on different
1460 * occasions after the configuration and not for transmitting data
1461 * These may be called when the user use ifconfig, /proc/net/dev
1462 * or wireless extensions
1465 /*------------------------------------------------------------------*/
1467 * Get the current Ethernet statistics. This may be called with the
1468 * card open or closed.
1469 * Used when the user read /proc/net/dev
1471 static en_stats *
1472 wavelan_get_stats(device * dev)
1474 #ifdef DEBUG_IOCTL_TRACE
1475 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1476 #endif
1478 return(&((net_local *) dev->priv)->stats);
1481 /*------------------------------------------------------------------*/
1483 * Set or clear the multicast filter for this adaptor.
1484 * num_addrs == -1 Promiscuous mode, receive all packets
1485 * num_addrs == 0 Normal mode, clear multicast list
1486 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1487 * and do best-effort filtering.
1489 static void
1490 wavelan_set_multicast_list(device * dev)
1492 net_local * lp = (net_local *) dev->priv;
1494 #ifdef DEBUG_IOCTL_TRACE
1495 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
1496 #endif
1498 #ifdef DEBUG_IOCTL_INFO
1499 printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1500 dev->name, dev->flags, dev->mc_count);
1501 #endif
1503 /* Are we asking for promiscuous mode,
1504 * or all multicast addresses (we don't have that!)
1505 * or too many multicast addresses for the hardware filter? */
1506 if((dev->flags & IFF_PROMISC) ||
1507 (dev->flags & IFF_ALLMULTI) ||
1508 (dev->mc_count > I82586_MAX_MULTICAST_ADDRESSES))
1511 * Enable promiscuous mode: receive all packets.
1513 if(!lp->promiscuous)
1515 lp->promiscuous = 1;
1516 lp->mc_count = 0;
1518 wv_82586_reconfig(dev);
1520 /* Tell the kernel that we are doing a really bad job. */
1521 dev->flags |= IFF_PROMISC;
1524 else
1525 /* Are there multicast addresses to send? */
1526 if(dev->mc_list != (struct dev_mc_list *) NULL)
1529 * Disable promiscuous mode, but receive all packets
1530 * in multicast list
1532 #ifdef MULTICAST_AVOID
1533 if(lp->promiscuous ||
1534 (dev->mc_count != lp->mc_count))
1535 #endif
1537 lp->promiscuous = 0;
1538 lp->mc_count = dev->mc_count;
1540 wv_82586_reconfig(dev);
1543 else
1546 * Switch to normal mode: disable promiscuous mode and
1547 * clear the multicast list.
1549 if(lp->promiscuous || lp->mc_count == 0)
1551 lp->promiscuous = 0;
1552 lp->mc_count = 0;
1554 wv_82586_reconfig(dev);
1557 #ifdef DEBUG_IOCTL_TRACE
1558 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
1559 #endif
1562 /*------------------------------------------------------------------*/
1564 * This function doesn't exist.
1565 * (Note : it was a nice way to test the reconfigure stuff...)
1567 #ifdef SET_MAC_ADDRESS
1568 static int
1569 wavelan_set_mac_address(device * dev,
1570 void * addr)
1572 struct sockaddr * mac = addr;
1574 /* Copy the address. */
1575 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1577 /* Reconfigure the beast. */
1578 wv_82586_reconfig(dev);
1580 return 0;
1582 #endif /* SET_MAC_ADDRESS */
1584 #ifdef WIRELESS_EXT /* if wireless extensions exist in the kernel */
1586 /*------------------------------------------------------------------*/
1588 * Frequency setting (for hardware capable of it)
1589 * It's a bit complicated and you don't really want to look into it.
1590 * (called in wavelan_ioctl)
1592 static inline int
1593 wv_set_frequency(u_long ioaddr, /* I/O port of the card */
1594 iw_freq * frequency)
1596 const int BAND_NUM = 10; /* Number of bands */
1597 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1598 #ifdef DEBUG_IOCTL_INFO
1599 int i;
1600 #endif
1602 /* Setting by frequency */
1603 /* Theoretically, you may set any frequency between
1604 * the two limits with a 0.5 MHz precision. In practice,
1605 * I don't want you to have trouble with local regulations.
1607 if((frequency->e == 1) &&
1608 (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
1610 freq = ((frequency->m / 10000) - 24000L) / 5;
1613 /* Setting by channel (same as wfreqsel) */
1614 /* Warning: each channel is 22 MHz wide, so some of the channels
1615 * will interfere. */
1616 if((frequency->e == 0) &&
1617 (frequency->m >= 0) && (frequency->m < BAND_NUM))
1619 /* Get frequency offset. */
1620 freq = channel_bands[frequency->m] >> 1;
1623 /* Verify that the frequency is allowed. */
1624 if(freq != 0L)
1626 u_short table[10]; /* Authorized frequency table */
1628 /* Read the frequency table. */
1629 fee_read(ioaddr, 0x71, table, 10);
1631 #ifdef DEBUG_IOCTL_INFO
1632 printk(KERN_DEBUG "Frequency table: ");
1633 for(i = 0; i < 10; i++)
1635 printk(" %04X",
1636 table[i]);
1638 printk("\n");
1639 #endif
1641 /* Look in the table to see whether the frequency is allowed. */
1642 if(!(table[9 - ((freq - 24) / 16)] &
1643 (1 << ((freq - 24) % 16))))
1644 return -EINVAL; /* not allowed */
1646 else
1647 return -EINVAL;
1649 /* if we get a usable frequency */
1650 if(freq != 0L)
1652 unsigned short area[16];
1653 unsigned short dac[2];
1654 unsigned short area_verify[16];
1655 unsigned short dac_verify[2];
1656 /* Corresponding gain (in the power adjust value table)
1657 * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8
1658 * and WCIN062D.DOC, page 6.2.9. */
1659 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1660 int power_band = 0; /* Selected band */
1661 unsigned short power_adjust; /* Correct value */
1663 /* Search for the gain. */
1664 power_band = 0;
1665 while((freq > power_limit[power_band]) &&
1666 (power_limit[++power_band] != 0))
1669 /* Read the first area. */
1670 fee_read(ioaddr, 0x00, area, 16);
1672 /* Read the DAC. */
1673 fee_read(ioaddr, 0x60, dac, 2);
1675 /* Read the new power adjust value. */
1676 fee_read(ioaddr, 0x6B - (power_band >> 1), &power_adjust, 1);
1677 if(power_band & 0x1)
1678 power_adjust >>= 8;
1679 else
1680 power_adjust &= 0xFF;
1682 #ifdef DEBUG_IOCTL_INFO
1683 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1684 for(i = 0; i < 16; i++)
1686 printk(" %04X",
1687 area[i]);
1689 printk("\n");
1691 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1692 dac[0], dac[1]);
1693 #endif
1695 /* Frequency offset (for info only) */
1696 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1698 /* Receiver Principle main divider coefficient */
1699 area[3] = (freq >> 1) + 2400L - 352L;
1700 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1702 /* Transmitter Main divider coefficient */
1703 area[13] = (freq >> 1) + 2400L;
1704 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1706 /* Other parts of the area are flags, bit streams or unused. */
1708 /* Set the value in the DAC. */
1709 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1710 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1712 /* Write the first area. */
1713 fee_write(ioaddr, 0x00,
1714 area, 16);
1716 /* Write the DAC. */
1717 fee_write(ioaddr, 0x60,
1718 dac, 2);
1720 /* We now should verify here that the writing of the EEPROM went OK. */
1722 /* Reread the first area. */
1723 fee_read(ioaddr, 0x00, area_verify, 16);
1725 /* Reread the DAC. */
1726 fee_read(ioaddr, 0x60, dac_verify, 2);
1728 /* Compare. */
1729 if(memcmp(area, area_verify, 16 * 2) ||
1730 memcmp(dac, dac_verify, 2 * 2))
1732 #ifdef DEBUG_IOCTL_ERROR
1733 printk(KERN_INFO "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n");
1734 #endif
1735 return -EOPNOTSUPP;
1738 /* We must download the frequency parameters to the
1739 * synthesizers (from the EEPROM - area 1)
1740 * Note: as the EEPROM is automatically decremented, we set the end
1741 * if the area... */
1742 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x0F);
1743 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1744 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1746 /* Wait until the download is finished. */
1747 fee_wait(ioaddr, 100, 100);
1749 /* We must now download the power adjust value (gain) to
1750 * the synthesizers (from the EEPROM - area 7 - DAC). */
1751 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x61);
1752 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1753 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1755 /* Wait for the download to finish. */
1756 fee_wait(ioaddr, 100, 100);
1758 #ifdef DEBUG_IOCTL_INFO
1759 /* Verification of what we have done */
1761 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1762 for(i = 0; i < 16; i++)
1764 printk(" %04X",
1765 area_verify[i]);
1767 printk("\n");
1769 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1770 dac_verify[0], dac_verify[1]);
1771 #endif
1773 return 0;
1775 else
1776 return -EINVAL; /* Bah, never get there... */
1779 /*------------------------------------------------------------------*/
1781 * Give the list of available frequencies.
1783 static inline int
1784 wv_frequency_list(u_long ioaddr, /* I/O port of the card */
1785 iw_freq * list, /* List of frequencies to fill */
1786 int max) /* Maximum number of frequencies */
1788 u_short table[10]; /* Authorized frequency table */
1789 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1790 int i; /* index in the table */
1791 int c = 0; /* Channel number */
1793 /* Read the frequency table. */
1794 fee_read(ioaddr, 0x71 /* frequency table */, table, 10);
1796 /* Check all frequencies. */
1797 i = 0;
1798 for(freq = 0; freq < 150; freq++)
1799 /* Look in the table if the frequency is allowed */
1800 if(table[9 - (freq / 16)] & (1 << (freq % 16)))
1802 /* Compute approximate channel number */
1803 while((((channel_bands[c] >> 1) - 24) < freq) &&
1804 (c < NELS(channel_bands)))
1805 c++;
1806 list[i].i = c; /* Set the list index */
1808 /* put in the list */
1809 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1810 list[i++].e = 1;
1812 /* Check number. */
1813 if(i >= max)
1814 return(i);
1817 return(i);
1820 #ifdef WIRELESS_SPY
1821 /*------------------------------------------------------------------*/
1823 * Gather wireless spy statistics: for each packet, compare the source
1824 * address with our list, and if they match, get the statistics.
1825 * Sorry, but this function really needs the wireless extensions.
1827 static inline void
1828 wl_spy_gather(device * dev,
1829 u_char * mac, /* MAC address */
1830 u_char * stats) /* Statistics to gather */
1832 net_local * lp = (net_local *) dev->priv;
1833 int i;
1835 /* Check all addresses. */
1836 for(i = 0; i < lp->spy_number; i++)
1837 /* If match */
1838 if(!memcmp(mac, lp->spy_address[i], WAVELAN_ADDR_SIZE))
1840 /* Update statistics */
1841 lp->spy_stat[i].qual = stats[2] & MMR_SGNL_QUAL;
1842 lp->spy_stat[i].level = stats[0] & MMR_SIGNAL_LVL;
1843 lp->spy_stat[i].noise = stats[1] & MMR_SILENCE_LVL;
1844 lp->spy_stat[i].updated = 0x7;
1847 #endif /* WIRELESS_SPY */
1849 #ifdef HISTOGRAM
1850 /*------------------------------------------------------------------*/
1852 * This function calculates a histogram of the signal level.
1853 * As the noise is quite constant, it's like doing it on the SNR.
1854 * We have defined a set of interval (lp->his_range), and each time
1855 * the level goes in that interval, we increment the count (lp->his_sum).
1856 * With this histogram you may detect if one WaveLAN is really weak,
1857 * or you may also calculate the mean and standard deviation of the level.
1859 static inline void
1860 wl_his_gather(device * dev,
1861 u_char * stats) /* Statistics to gather */
1863 net_local * lp = (net_local *) dev->priv;
1864 u_char level = stats[0] & MMR_SIGNAL_LVL;
1865 int i;
1867 /* Find the correct interval. */
1868 i = 0;
1869 while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
1872 /* Increment interval counter. */
1873 (lp->his_sum[i])++;
1875 #endif /* HISTOGRAM */
1877 /*------------------------------------------------------------------*/
1879 * Perform ioctl for configuration and information.
1880 * It is here that the wireless extensions are treated (iwconfig).
1882 static int
1883 wavelan_ioctl(struct net_device * dev, /* device on which the ioctl is applied */
1884 struct ifreq * rq, /* data passed */
1885 int cmd) /* ioctl number */
1887 u_long ioaddr = dev->base_addr;
1888 net_local * lp = (net_local *)dev->priv; /* lp is not unused */
1889 struct iwreq * wrq = (struct iwreq *) rq;
1890 psa_t psa;
1891 mm_t m;
1892 unsigned long x;
1893 int ret = 0;
1895 #ifdef DEBUG_IOCTL_TRACE
1896 printk(KERN_DEBUG "%s: ->wavelan_ioctl(cmd=0x%X)\n", dev->name, cmd);
1897 #endif
1899 /* Disable interrupts and save flags. */
1900 x = wv_splhi();
1902 /* Look what is the request */
1903 switch(cmd)
1905 /* --------------- WIRELESS EXTENSIONS --------------- */
1907 case SIOCGIWNAME:
1908 strcpy(wrq->u.name, "WaveLAN");
1909 break;
1911 case SIOCSIWNWID:
1912 /* Set NWID in WaveLAN. */
1913 if(wrq->u.nwid.on)
1915 /* Set NWID in psa. */
1916 psa.psa_nwid[0] = (wrq->u.nwid.nwid & 0xFF00) >> 8;
1917 psa.psa_nwid[1] = wrq->u.nwid.nwid & 0xFF;
1918 psa.psa_nwid_select = 0x01;
1919 psa_write(ioaddr, lp->hacr, (char *)psa.psa_nwid - (char *)&psa,
1920 (unsigned char *)psa.psa_nwid, 3);
1922 /* Set NWID in mmc. */
1923 m.w.mmw_netw_id_l = wrq->u.nwid.nwid & 0xFF;
1924 m.w.mmw_netw_id_h = (wrq->u.nwid.nwid & 0xFF00) >> 8;
1925 mmc_write(ioaddr, (char *)&m.w.mmw_netw_id_l - (char *)&m,
1926 (unsigned char *)&m.w.mmw_netw_id_l, 2);
1927 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), 0x00);
1929 else
1931 /* Disable NWID in the psa. */
1932 psa.psa_nwid_select = 0x00;
1933 psa_write(ioaddr, lp->hacr,
1934 (char *)&psa.psa_nwid_select - (char *)&psa,
1935 (unsigned char *)&psa.psa_nwid_select, 1);
1937 /* Disable NWID in the mmc (no filtering). */
1938 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), MMW_LOOPT_SEL_DIS_NWID);
1940 /* update the Wavelan checksum */
1941 update_psa_checksum(dev, ioaddr, lp->hacr);
1942 break;
1944 case SIOCGIWNWID:
1945 /* Read the NWID. */
1946 psa_read(ioaddr, lp->hacr, (char *)psa.psa_nwid - (char *)&psa,
1947 (unsigned char *)psa.psa_nwid, 3);
1948 wrq->u.nwid.nwid = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1949 wrq->u.nwid.on = psa.psa_nwid_select;
1950 break;
1952 case SIOCSIWFREQ:
1953 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1954 if(!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1955 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1956 ret = wv_set_frequency(ioaddr, &(wrq->u.freq));
1957 else
1958 ret = -EOPNOTSUPP;
1959 break;
1961 case SIOCGIWFREQ:
1962 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
1963 * Does it work for everybody, especially old cards? */
1964 if(!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1965 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1967 unsigned short freq;
1969 /* Ask the EEPROM to read the frequency from the first area. */
1970 fee_read(ioaddr, 0x00, &freq, 1);
1971 wrq->u.freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
1972 wrq->u.freq.e = 1;
1974 else
1976 psa_read(ioaddr, lp->hacr, (char *)&psa.psa_subband - (char *)&psa,
1977 (unsigned char *)&psa.psa_subband, 1);
1979 if(psa.psa_subband <= 4)
1981 wrq->u.freq.m = fixed_bands[psa.psa_subband];
1982 wrq->u.freq.e = (psa.psa_subband != 0);
1984 else
1985 ret = -EOPNOTSUPP;
1987 break;
1989 case SIOCSIWSENS:
1990 /* Set the level threshold. */
1991 /* We should complain loudly if wrq->u.sens.fixed = 0, because we
1992 * can't set auto mode... */
1993 psa.psa_thr_pre_set = wrq->u.sens.value & 0x3F;
1994 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_thr_pre_set - (char *)&psa,
1995 (unsigned char *) &psa.psa_thr_pre_set, 1);
1996 /* update the Wavelan checksum */
1997 update_psa_checksum(dev, ioaddr, lp->hacr);
1998 mmc_out(ioaddr, mmwoff(0, mmw_thr_pre_set), psa.psa_thr_pre_set);
1999 break;
2001 case SIOCGIWSENS:
2002 /* Read the level threshold. */
2003 psa_read(ioaddr, lp->hacr, (char *)&psa.psa_thr_pre_set - (char *)&psa,
2004 (unsigned char *) &psa.psa_thr_pre_set, 1);
2005 wrq->u.sens.value = psa.psa_thr_pre_set & 0x3F;
2006 wrq->u.sens.fixed = 1;
2007 break;
2009 case SIOCSIWENCODE:
2010 /* Set encryption key. */
2011 if(!mmc_encr(ioaddr))
2013 ret = -EOPNOTSUPP;
2014 break;
2017 if(wrq->u.encoding.method)
2018 { /* Enable encryption. */
2019 int i;
2020 long long key = wrq->u.encoding.code;
2022 for(i = 7; i >= 0; i--)
2024 psa.psa_encryption_key[i] = key & 0xFF;
2025 key >>= 8;
2027 psa.psa_encryption_select = 1;
2028 psa_write(ioaddr, lp->hacr,
2029 (char *) &psa.psa_encryption_select - (char *) &psa,
2030 (unsigned char *) &psa.psa_encryption_select, 8+1);
2032 mmc_out(ioaddr, mmwoff(0, mmw_encr_enable),
2033 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2034 mmc_write(ioaddr, mmwoff(0, mmw_encr_key),
2035 (unsigned char *) &psa.psa_encryption_key, 8);
2037 else
2038 { /* Disable encryption. */
2039 psa.psa_encryption_select = 0;
2040 psa_write(ioaddr, lp->hacr,
2041 (char *) &psa.psa_encryption_select - (char *) &psa,
2042 (unsigned char *) &psa.psa_encryption_select, 1);
2044 mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), 0);
2046 /* update the Wavelan checksum */
2047 update_psa_checksum(dev, ioaddr, lp->hacr);
2048 break;
2050 case SIOCGIWENCODE:
2051 /* Read the encryption key. */
2052 if(!mmc_encr(ioaddr))
2054 ret = -EOPNOTSUPP;
2055 break;
2058 /* Only super-user can see encryption key. */
2059 if(!suser())
2061 ret = -EPERM;
2062 break;
2064 else
2066 int i;
2067 long long key = 0;
2069 psa_read(ioaddr, lp->hacr,
2070 (char *) &psa.psa_encryption_select - (char *) &psa,
2071 (unsigned char *) &psa.psa_encryption_select, 1+8);
2072 for(i = 0; i < 8; i++)
2074 key <<= 8;
2075 key += psa.psa_encryption_key[i];
2077 wrq->u.encoding.code = key;
2079 /* encryption is enabled */
2080 if(psa.psa_encryption_select)
2081 wrq->u.encoding.method = mmc_encr(ioaddr);
2082 else
2083 wrq->u.encoding.method = 0;
2085 break;
2087 case SIOCGIWRANGE:
2088 /* basic checking */
2089 if(wrq->u.data.pointer != (caddr_t) 0)
2091 struct iw_range range;
2093 /* Set the length (useless: it's constant). */
2094 wrq->u.data.length = sizeof(struct iw_range);
2096 /* Set information in the range struct. */
2097 range.throughput = 1.6 * 1000 * 1000; /* don't argue on this ! */
2098 range.min_nwid = 0x0000;
2099 range.max_nwid = 0xFFFF;
2101 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2102 if(!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2103 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
2105 range.num_channels = 10;
2106 range.num_frequency = wv_frequency_list(ioaddr, range.freq,
2107 IW_MAX_FREQUENCIES);
2109 else
2110 range.num_channels = range.num_frequency = 0;
2112 range.sensitivity = 0x3F;
2113 range.max_qual.qual = MMR_SGNL_QUAL;
2114 range.max_qual.level = MMR_SIGNAL_LVL;
2115 range.max_qual.noise = MMR_SILENCE_LVL;
2117 range.num_bitrates = 1;
2118 range.bitrate[0] = 2000000; /* 2 Mb/s */
2120 /* Copy structure to the user buffer. */
2121 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2122 ret = -EFAULT;
2124 break;
2126 case SIOCGIWPRIV:
2127 /* Basic checking */
2128 if(wrq->u.data.pointer != (caddr_t) 0)
2130 struct iw_priv_args priv[] =
2131 { /* cmd, set_args, get_args, name */
2132 { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2133 { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2135 { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
2136 { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
2139 /* Set the number of available ioctls. */
2140 wrq->u.data.length = 4;
2142 /* Copy structure to the user buffer. */
2143 if (copy_to_user(wrq->u.data.pointer, (u_char *) priv, sizeof(priv)))
2144 ret = -EFAULT;
2146 break;
2148 #ifdef WIRELESS_SPY
2149 case SIOCSIWSPY:
2150 /* Set the spy list */
2152 /* Check the number of addresses. */
2153 if(wrq->u.data.length > IW_MAX_SPY)
2155 ret = -E2BIG;
2156 break;
2158 lp->spy_number = wrq->u.data.length;
2160 /* Are there are addresses to copy? */
2161 if(lp->spy_number > 0)
2163 struct sockaddr address[IW_MAX_SPY];
2164 int i;
2166 /* Copy addresses to the driver. */
2167 if (copy_from_user(address, wrq->u.data.pointer, sizeof(struct sockaddr) * lp->spy_number)) {
2168 ret = -EFAULT;
2169 break;
2172 /* Copy addresses to the lp structure. */
2173 for(i = 0; i < lp->spy_number; i++)
2175 memcpy(lp->spy_address[i], address[i].sa_data,
2176 WAVELAN_ADDR_SIZE);
2179 /* Reset structure. */
2180 memset(lp->spy_stat, 0x00, sizeof(iw_qual) * IW_MAX_SPY);
2182 #ifdef DEBUG_IOCTL_INFO
2183 printk(KERN_DEBUG "SetSpy: set of new addresses is: \n");
2184 for(i = 0; i < wrq->u.data.length; i++)
2185 printk(KERN_DEBUG "%02X:%02X:%02X:%02X:%02X:%02X \n",
2186 lp->spy_address[i][0],
2187 lp->spy_address[i][1],
2188 lp->spy_address[i][2],
2189 lp->spy_address[i][3],
2190 lp->spy_address[i][4],
2191 lp->spy_address[i][5]);
2192 #endif /* DEBUG_IOCTL_INFO */
2195 break;
2197 case SIOCGIWSPY:
2198 /* Get the spy list and spy stats. */
2200 /* Set the number of addresses */
2201 wrq->u.data.length = lp->spy_number;
2203 /* Does the user want to have the addresses back? */
2204 if((lp->spy_number > 0) && (wrq->u.data.pointer != (caddr_t) 0))
2206 struct sockaddr address[IW_MAX_SPY];
2207 int i;
2209 /* Copy addresses from the lp structure. */
2210 for(i = 0; i < lp->spy_number; i++)
2212 memcpy(address[i].sa_data, lp->spy_address[i],
2213 WAVELAN_ADDR_SIZE);
2214 address[i].sa_family = AF_UNIX;
2217 /* Copy addresses to the user buffer. */
2218 if (copy_to_user(wrq->u.data.pointer, address, sizeof(struct sockaddr) * lp->spy_number)) {
2219 ret = -EFAULT;
2220 break;
2223 /* Copy stats to the user buffer (just after). */
2224 if (copy_to_user(wrq->u.data.pointer +
2225 (sizeof(struct sockaddr) * lp->spy_number),
2226 lp->spy_stat, sizeof(iw_qual) * lp->spy_number)) {
2227 ret = -EFAULT;
2228 break;
2231 /* Reset updated flags. */
2232 for(i = 0; i < lp->spy_number; i++)
2233 lp->spy_stat[i].updated = 0x0;
2234 } /* if(pointer != NULL) */
2236 break;
2237 #endif /* WIRELESS_SPY */
2239 /* ------------------ PRIVATE IOCTL ------------------ */
2241 case SIOCSIPQTHR:
2242 if(!suser())
2244 ret = -EPERM;
2245 break;
2247 psa.psa_quality_thr = *(wrq->u.name) & 0x0F;
2248 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_quality_thr - (char *)&psa,
2249 (unsigned char *)&psa.psa_quality_thr, 1);
2250 /* update the Wavelan checksum */
2251 update_psa_checksum(dev, ioaddr, lp->hacr);
2252 mmc_out(ioaddr, mmwoff(0, mmw_quality_thr), psa.psa_quality_thr);
2253 break;
2255 case SIOCGIPQTHR:
2256 psa_read(ioaddr, lp->hacr, (char *)&psa.psa_quality_thr - (char *)&psa,
2257 (unsigned char *)&psa.psa_quality_thr, 1);
2258 *(wrq->u.name) = psa.psa_quality_thr & 0x0F;
2259 break;
2261 #ifdef HISTOGRAM
2262 case SIOCSIPHISTO:
2263 /* Verify that the user is root. */
2264 if(!suser())
2266 ret = -EPERM;
2267 break;
2270 /* Check the number of intervals. */
2271 if(wrq->u.data.length > 16)
2273 ret = -E2BIG;
2274 break;
2276 lp->his_number = wrq->u.data.length;
2278 /* Are there addresses to copy? */
2279 if(lp->his_number > 0)
2281 /* Copy interval ranges to the driver */
2282 if (copy_from_user(lp->his_range, wrq->u.data.pointer, sizeof(char) * lp->his_number)) {
2283 ret = -EFAULT;
2284 break;
2287 /* Reset structure. */
2288 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2290 break;
2292 case SIOCGIPHISTO:
2293 /* Set the number of intervals. */
2294 wrq->u.data.length = lp->his_number;
2296 /* Give back the distribution statistics */
2297 if((lp->his_number > 0) && (wrq->u.data.pointer != (caddr_t) 0))
2299 /* Copy data to the user buffer. */
2300 if (copy_to_user(wrq->u.data.pointer, lp->his_sum, sizeof(long) * lp->his_number))
2301 ret = -EFAULT;
2303 } /* if(pointer != NULL) */
2304 break;
2305 #endif /* HISTOGRAM */
2307 /* ------------------- OTHER IOCTL ------------------- */
2309 default:
2310 ret = -EOPNOTSUPP;
2313 /* Enable interrupts and restore flags. */
2314 wv_splx(x);
2316 #ifdef DEBUG_IOCTL_TRACE
2317 printk(KERN_DEBUG "%s: <-wavelan_ioctl()\n", dev->name);
2318 #endif
2319 return ret;
2322 /*------------------------------------------------------------------*/
2324 * Get wireless statistics.
2325 * Called by /proc/net/wireless
2327 static iw_stats *
2328 wavelan_get_wireless_stats(device * dev)
2330 u_long ioaddr = dev->base_addr;
2331 net_local * lp = (net_local *) dev->priv;
2332 mmr_t m;
2333 iw_stats * wstats;
2334 unsigned long x;
2336 #ifdef DEBUG_IOCTL_TRACE
2337 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
2338 #endif
2340 /* Disable interrupts and save flags. */
2341 x = wv_splhi();
2343 if(lp == (net_local *) NULL)
2344 return (iw_stats *) NULL;
2345 wstats = &lp->wstats;
2347 /* Get data from the mmc. */
2348 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2350 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2351 mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
2352 mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
2354 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2356 /* Copy data to wireless stuff. */
2357 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2358 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2359 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2360 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2361 wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
2362 ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
2363 ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2364 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2365 wstats->discard.code = 0L;
2366 wstats->discard.misc = 0L;
2368 /* Enable interrupts and restore flags. */
2369 wv_splx(x);
2371 #ifdef DEBUG_IOCTL_TRACE
2372 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
2373 #endif
2374 return &lp->wstats;
2376 #endif /* WIRELESS_EXT */
2378 /************************* PACKET RECEPTION *************************/
2380 * This part deals with receiving the packets.
2381 * The interrupt handler gets an interrupt when a packet has been
2382 * successfully received and calls this part.
2385 /*------------------------------------------------------------------*/
2387 * This routine does the actual copying of data (including the Ethernet
2388 * header structure) from the WaveLAN card to an sk_buff chain that
2389 * will be passed up to the network interface layer. NOTE: we
2390 * currently don't handle trailer protocols (neither does the rest of
2391 * the network interface), so if that is needed, it will (at least in
2392 * part) be added here. The contents of the receive ring buffer are
2393 * copied to a message chain that is then passed to the kernel.
2395 * Note: if any errors occur, the packet is "dropped on the floor".
2396 * (called by wv_packet_rcv())
2398 static inline void
2399 wv_packet_read(device * dev,
2400 u_short buf_off,
2401 int sksize)
2403 net_local * lp = (net_local *) dev->priv;
2404 u_long ioaddr = dev->base_addr;
2405 struct sk_buff * skb;
2407 #ifdef DEBUG_RX_TRACE
2408 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2409 dev->name, buf_off, sksize);
2410 #endif
2412 /* Allocate buffer for the data */
2413 if((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL)
2415 #ifdef DEBUG_RX_ERROR
2416 printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
2417 dev->name, sksize);
2418 #endif
2419 lp->stats.rx_dropped++;
2420 return;
2423 skb->dev = dev;
2425 /* Copy the packet to the buffer. */
2426 obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize);
2427 skb->protocol=eth_type_trans(skb, dev);
2429 #ifdef DEBUG_RX_INFO
2430 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2431 #endif /* DEBUG_RX_INFO */
2433 /* Statistics-gathering and associated stuff.
2434 * It seem a bit messy with all the define, but it's really simple... */
2435 #if defined(WIRELESS_SPY) || defined(HISTOGRAM)
2437 #ifdef WIRELESS_SPY
2438 (lp->spy_number > 0) ||
2439 #endif /* WIRELESS_SPY */
2440 #ifdef HISTOGRAM
2441 (lp->his_number > 0) ||
2442 #endif /* HISTOGRAM */
2445 u_char stats[3]; /* signal level, noise level, signal quality */
2447 /* Read signal level, silence level and signal quality bytes. */
2448 /* Note: in the PCMCIA hardware, these are part of the frame. It seems
2449 * that for the ISA hardware, it's nowhere to be found in the frame,
2450 * so I'm obliged to do this (it has a side effect on /proc/net/wireless).
2451 * Any ideas?
2453 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2454 mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3);
2455 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2457 #ifdef DEBUG_RX_INFO
2458 printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2459 dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
2460 #endif
2462 /* Spying stuff */
2463 #ifdef WIRELESS_SPY
2464 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
2465 #endif /* WIRELESS_SPY */
2466 #ifdef HISTOGRAM
2467 wl_his_gather(dev, stats);
2468 #endif /* HISTOGRAM */
2470 #endif /* defined(WIRELESS_SPY) || defined(HISTOGRAM) */
2473 * Hand the packet to the network module.
2475 netif_rx(skb);
2477 /* Keep statistics up to date */
2478 lp->stats.rx_packets++;
2479 lp->stats.rx_bytes += skb->len;
2481 #ifdef DEBUG_RX_TRACE
2482 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2483 #endif
2486 /*------------------------------------------------------------------*/
2488 * Transfer as many packets as we can
2489 * from the device RAM.
2490 * Called by the interrupt handler.
2492 static inline void
2493 wv_receive(device * dev)
2495 u_long ioaddr = dev->base_addr;
2496 net_local * lp = (net_local *)dev->priv;
2497 fd_t fd;
2498 rbd_t rbd;
2499 int nreaped = 0;
2501 #ifdef DEBUG_RX_TRACE
2502 printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name);
2503 #endif
2505 /* Loop on each received packet. */
2506 for(;;)
2508 obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd, sizeof(fd));
2510 /* Note about the status :
2511 * It start up to be 0 (the value we set). Then, when the RU
2512 * grab the buffer to prepare for reception, it sets the
2513 * FD_STATUS_B flag. When the RU has finished receiving the
2514 * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
2515 * completion and set the other flags to indicate the eventual
2516 * errors. FD_STATUS_OK indicates that the reception was OK.
2519 /* If the current frame is not complete, we have reached the end. */
2520 if((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
2521 break; /* This is how we exit the loop. */
2523 nreaped++;
2525 /* Check whether frame was correctly received. */
2526 if((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK)
2528 /* Does the frame contain a pointer to the data? Let's check. */
2529 if(fd.fd_rbd_offset != I82586NULL)
2531 /* Read the receive buffer descriptor */
2532 obram_read(ioaddr, fd.fd_rbd_offset,
2533 (unsigned char *) &rbd, sizeof(rbd));
2535 #ifdef DEBUG_RX_ERROR
2536 if((rbd.rbd_status & RBD_STATUS_EOF) != RBD_STATUS_EOF)
2537 printk(KERN_INFO "%s: wv_receive(): missing EOF flag.\n",
2538 dev->name);
2540 if((rbd.rbd_status & RBD_STATUS_F) != RBD_STATUS_F)
2541 printk(KERN_INFO "%s: wv_receive(): missing F flag.\n",
2542 dev->name);
2543 #endif /* DEBUG_RX_ERROR */
2545 /* Read the packet and transmit to Linux */
2546 wv_packet_read(dev, rbd.rbd_bufl,
2547 rbd.rbd_status & RBD_STATUS_ACNT);
2549 #ifdef DEBUG_RX_ERROR
2550 else /* if frame has no data */
2551 printk(KERN_INFO "%s: wv_receive(): frame has no data.\n",
2552 dev->name);
2553 #endif
2555 else /* If reception was no successful */
2557 lp->stats.rx_errors++;
2559 #ifdef DEBUG_RX_INFO
2560 printk(KERN_DEBUG "%s: wv_receive(): frame not received successfully (%X).\n",
2561 dev->name, fd.fd_status);
2562 #endif
2564 #ifdef DEBUG_RX_ERROR
2565 if((fd.fd_status & FD_STATUS_S6) != 0)
2566 printk(KERN_INFO "%s: wv_receive(): no EOF flag.\n", dev->name);
2567 #endif
2569 if((fd.fd_status & FD_STATUS_S7) != 0)
2571 lp->stats.rx_length_errors++;
2572 #ifdef DEBUG_RX_FAIL
2573 printk(KERN_DEBUG "%s: wv_receive(): frame too short.\n",
2574 dev->name);
2575 #endif
2578 if((fd.fd_status & FD_STATUS_S8) != 0)
2580 lp->stats.rx_over_errors++;
2581 #ifdef DEBUG_RX_FAIL
2582 printk(KERN_DEBUG "%s: wv_receive(): rx DMA overrun.\n",
2583 dev->name);
2584 #endif
2587 if((fd.fd_status & FD_STATUS_S9) != 0)
2589 lp->stats.rx_fifo_errors++;
2590 #ifdef DEBUG_RX_FAIL
2591 printk(KERN_DEBUG "%s: wv_receive(): ran out of resources.\n",
2592 dev->name);
2593 #endif
2596 if((fd.fd_status & FD_STATUS_S10) != 0)
2598 lp->stats.rx_frame_errors++;
2599 #ifdef DEBUG_RX_FAIL
2600 printk(KERN_DEBUG "%s: wv_receive(): alignment error.\n",
2601 dev->name);
2602 #endif
2605 if((fd.fd_status & FD_STATUS_S11) != 0)
2607 lp->stats.rx_crc_errors++;
2608 #ifdef DEBUG_RX_FAIL
2609 printk(KERN_DEBUG "%s: wv_receive(): CRC error.\n", dev->name);
2610 #endif
2614 fd.fd_status = 0;
2615 obram_write(ioaddr, fdoff(lp->rx_head, fd_status),
2616 (unsigned char *) &fd.fd_status, sizeof(fd.fd_status));
2618 fd.fd_command = FD_COMMAND_EL;
2619 obram_write(ioaddr, fdoff(lp->rx_head, fd_command),
2620 (unsigned char *) &fd.fd_command, sizeof(fd.fd_command));
2622 fd.fd_command = 0;
2623 obram_write(ioaddr, fdoff(lp->rx_last, fd_command),
2624 (unsigned char *) &fd.fd_command, sizeof(fd.fd_command));
2626 lp->rx_last = lp->rx_head;
2627 lp->rx_head = fd.fd_link_offset;
2628 } /* for(;;) -> loop on all frames */
2630 #ifdef DEBUG_RX_INFO
2631 if(nreaped > 1)
2632 printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n", dev->name, nreaped);
2633 #endif
2634 #ifdef DEBUG_RX_TRACE
2635 printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name);
2636 #endif
2639 /*********************** PACKET TRANSMISSION ***********************/
2641 * This part deals with sending packets through the WaveLAN.
2645 /*------------------------------------------------------------------*/
2647 * This routine fills in the appropriate registers and memory
2648 * locations on the WaveLAN card and starts the card off on
2649 * the transmit.
2651 * The principle:
2652 * Each block contains a transmit command, a NOP command,
2653 * a transmit block descriptor and a buffer.
2654 * The CU read the transmit block which point to the tbd,
2655 * read the tbd and the content of the buffer.
2656 * When it has finish with it, it goes to the next command
2657 * which in our case is the NOP. The NOP points on itself,
2658 * so the CU stop here.
2659 * When we add the next block, we modify the previous nop
2660 * to make it point on the new tx command.
2661 * Simple, isn't it ?
2663 * (called in wavelan_packet_xmit())
2665 static inline void
2666 wv_packet_write(device * dev,
2667 void * buf,
2668 short length)
2670 net_local * lp = (net_local *) dev->priv;
2671 u_long ioaddr = dev->base_addr;
2672 unsigned short txblock;
2673 unsigned short txpred;
2674 unsigned short tx_addr;
2675 unsigned short nop_addr;
2676 unsigned short tbd_addr;
2677 unsigned short buf_addr;
2678 ac_tx_t tx;
2679 ac_nop_t nop;
2680 tbd_t tbd;
2681 int clen = length;
2682 unsigned long x;
2684 #ifdef DEBUG_TX_TRACE
2685 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
2686 #endif
2688 /* Do we need some padding? */
2689 if(clen < ETH_ZLEN)
2690 clen = ETH_ZLEN;
2692 x = wv_splhi();
2694 /* Calculate addresses of next block and previous block. */
2695 txblock = lp->tx_first_free;
2696 txpred = txblock - TXBLOCKZ;
2697 if(txpred < OFFSET_CU)
2698 txpred += NTXBLOCKS * TXBLOCKZ;
2699 lp->tx_first_free += TXBLOCKZ;
2700 if(lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
2701 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
2704 if (lp->tx_n_in_use > 0)
2705 printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
2708 lp->tx_n_in_use++;
2710 /* Calculate addresses of the different parts of the block. */
2711 tx_addr = txblock;
2712 nop_addr = tx_addr + sizeof(tx);
2713 tbd_addr = nop_addr + sizeof(nop);
2714 buf_addr = tbd_addr + sizeof(tbd);
2717 * Transmit command
2719 tx.tx_h.ac_status = 0;
2720 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
2721 (unsigned char *) &tx.tx_h.ac_status,
2722 sizeof(tx.tx_h.ac_status));
2725 * NOP command
2727 nop.nop_h.ac_status = 0;
2728 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2729 (unsigned char *) &nop.nop_h.ac_status,
2730 sizeof(nop.nop_h.ac_status));
2731 nop.nop_h.ac_link = nop_addr;
2732 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2733 (unsigned char *) &nop.nop_h.ac_link,
2734 sizeof(nop.nop_h.ac_link));
2737 * Transmit buffer descriptor
2739 tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen);
2740 tbd.tbd_next_bd_offset = I82586NULL;
2741 tbd.tbd_bufl = buf_addr;
2742 tbd.tbd_bufh = 0;
2743 obram_write(ioaddr, tbd_addr, (unsigned char *)&tbd, sizeof(tbd));
2746 * Data
2748 obram_write(ioaddr, buf_addr, buf, length);
2751 * Overwrite the predecessor NOP link
2752 * so that it points to this txblock.
2754 nop_addr = txpred + sizeof(tx);
2755 nop.nop_h.ac_status = 0;
2756 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2757 (unsigned char *)&nop.nop_h.ac_status,
2758 sizeof(nop.nop_h.ac_status));
2759 nop.nop_h.ac_link = txblock;
2760 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2761 (unsigned char *) &nop.nop_h.ac_link,
2762 sizeof(nop.nop_h.ac_link));
2764 /* Keep stats up to date. */
2765 lp->stats.tx_bytes += length;
2767 /* If watchdog not already active, activate it... */
2768 if(lp->watchdog.prev == (timer_list *) NULL)
2770 /* Set timer to expire in WATCHDOG_JIFFIES. */
2771 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
2772 add_timer(&lp->watchdog);
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 dev->tbusy = 0;
2781 wv_splx(x);
2783 #ifdef DEBUG_TX_INFO
2784 wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
2785 #endif /* DEBUG_TX_INFO */
2787 #ifdef DEBUG_TX_TRACE
2788 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
2789 #endif
2792 /*------------------------------------------------------------------*/
2794 * This routine is called when we want to send a packet (NET3 callback)
2795 * In this routine, we check if the harware is ready to accept
2796 * the packet. We also prevent reentrance. Then we call the function
2797 * to send the packet.
2799 static int
2800 wavelan_packet_xmit(struct sk_buff * skb,
2801 device * dev)
2803 net_local * lp = (net_local *)dev->priv;
2805 #ifdef DEBUG_TX_TRACE
2806 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
2807 (unsigned) skb);
2808 #endif
2810 /* This flag indicate that the hardware can't perform a transmission.
2811 * Theoretically, NET3 checks it before sending a packet to the driver,
2812 * but in fact it never does that and pools continuously.
2813 * As the watchdog will abort overly long transmissions, we are quite safe.
2815 if(dev->tbusy)
2816 return 1;
2819 * Block a timer-based transmit from overlapping.
2820 * In other words, prevent reentering this routine.
2822 if(test_and_set_bit(0, (void *)&dev->tbusy) != 0)
2823 #ifdef DEBUG_TX_ERROR
2824 printk(KERN_INFO "%s: Transmitter access conflict.\n", dev->name);
2825 #endif
2826 else
2828 /* If somebody has asked to reconfigure the controller,
2829 * we can do it now.
2831 if(lp->reconfig_82586)
2833 wv_82586_config(dev);
2834 if(dev->tbusy)
2835 return 1;
2838 #ifdef DEBUG_TX_ERROR
2839 if(skb->next)
2840 printk(KERN_INFO "skb has next\n");
2841 #endif
2843 wv_packet_write(dev, skb->data, skb->len);
2846 dev_kfree_skb(skb);
2848 #ifdef DEBUG_TX_TRACE
2849 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
2850 #endif
2851 return 0;
2854 /*********************** HARDWARE CONFIGURATION ***********************/
2856 * This part does the real job of starting and configuring the hardware.
2859 /*--------------------------------------------------------------------*/
2861 * Routine to initialize the Modem Management Controller.
2862 * (called by wv_hw_reset())
2864 static inline int
2865 wv_mmc_init(device * dev)
2867 u_long ioaddr = dev->base_addr;
2868 net_local * lp = (net_local *)dev->priv;
2869 psa_t psa;
2870 mmw_t m;
2871 int configured;
2873 #ifdef DEBUG_CONFIG_TRACE
2874 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
2875 #endif
2877 /* Read the parameter storage area. */
2878 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
2880 #ifdef USE_PSA_CONFIG
2881 configured = psa.psa_conf_status & 1;
2882 #else
2883 configured = 0;
2884 #endif
2886 /* Is the PSA is not configured */
2887 if(!configured)
2889 /* User will be able to configure NWID later (with iwconfig). */
2890 psa.psa_nwid[0] = 0;
2891 psa.psa_nwid[1] = 0;
2893 /* no NWID checking since NWID is not set */
2894 psa.psa_nwid_select = 0;
2896 /* Disable encryption */
2897 psa.psa_encryption_select = 0;
2899 /* Set to standard values:
2900 * 0x04 for AT,
2901 * 0x01 for MCA,
2902 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
2904 if (psa.psa_comp_number & 1)
2905 psa.psa_thr_pre_set = 0x01;
2906 else
2907 psa.psa_thr_pre_set = 0x04;
2908 psa.psa_quality_thr = 0x03;
2910 /* It is configured */
2911 psa.psa_conf_status |= 1;
2913 #ifdef USE_PSA_CONFIG
2914 /* Write the psa. */
2915 psa_write(ioaddr, lp->hacr, (char *)psa.psa_nwid - (char *)&psa,
2916 (unsigned char *)psa.psa_nwid, 4);
2917 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_thr_pre_set - (char *)&psa,
2918 (unsigned char *)&psa.psa_thr_pre_set, 1);
2919 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_quality_thr - (char *)&psa,
2920 (unsigned char *)&psa.psa_quality_thr, 1);
2921 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_conf_status - (char *)&psa,
2922 (unsigned char *)&psa.psa_conf_status, 1);
2923 /* update the Wavelan checksum */
2924 update_psa_checksum(dev, ioaddr, lp->hacr);
2925 #endif
2928 /* Zero the mmc structure. */
2929 memset(&m, 0x00, sizeof(m));
2931 /* Copy PSA info to the mmc. */
2932 m.mmw_netw_id_l = psa.psa_nwid[1];
2933 m.mmw_netw_id_h = psa.psa_nwid[0];
2935 if(psa.psa_nwid_select & 1)
2936 m.mmw_loopt_sel = 0x00;
2937 else
2938 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
2940 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
2941 sizeof(m.mmw_encr_key));
2943 if(psa.psa_encryption_select)
2944 m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
2945 else
2946 m.mmw_encr_enable = 0;
2948 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
2949 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
2952 * Set default modem control parameters.
2953 * See NCR document 407-0024326 Rev. A.
2955 m.mmw_jabber_enable = 0x01;
2956 m.mmw_freeze = 0;
2957 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
2958 m.mmw_ifs = 0x20;
2959 m.mmw_mod_delay = 0x04;
2960 m.mmw_jam_time = 0x38;
2962 m.mmw_des_io_invert = 0;
2963 m.mmw_decay_prm = 0;
2964 m.mmw_decay_updat_prm = 0;
2966 /* Write all info to MMC. */
2967 mmc_write(ioaddr, 0, (u_char *)&m, sizeof(m));
2969 /* The following code starts the modem of the 2.00 frequency
2970 * selectable cards at power on. It's not strictly needed for the
2971 * following boots.
2972 * The original patch was by Joe Finney for the PCMCIA driver, but
2973 * I've cleaned it up a bit and added documentation.
2974 * Thanks to Loeke Brederveld from Lucent for the info.
2977 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
2978 * Does it work for everybody, especially old cards? */
2979 /* Note: WFREQSEL verifies that it is able to read a sensible
2980 * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
2981 * is 0xA (Xilinx version) or 0xB (Ariadne version).
2982 * My test is more crude but does work. */
2983 if(!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2984 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
2986 /* We must download the frequency parameters to the
2987 * synthesizers (from the EEPROM - area 1)
2988 * Note: as the EEPROM is automatically decremented, we set the end
2989 * if the area... */
2990 m.mmw_fee_addr = 0x0F;
2991 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
2992 mmc_write(ioaddr, (char *)&m.mmw_fee_ctrl - (char *)&m,
2993 (unsigned char *)&m.mmw_fee_ctrl, 2);
2995 /* Wait until the download is finished. */
2996 fee_wait(ioaddr, 100, 100);
2998 #ifdef DEBUG_CONFIG_INFO
2999 /* The frequency was in the last word downloaded. */
3000 mmc_read(ioaddr, (char *)&m.mmw_fee_data_l - (char *)&m,
3001 (unsigned char *)&m.mmw_fee_data_l, 2);
3003 /* Print some info for the user. */
3004 printk(KERN_DEBUG "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n",
3005 dev->name,
3006 ((m.mmw_fee_data_h << 4) |
3007 (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
3008 #endif
3010 /* We must now download the power adjust value (gain) to
3011 * the synthesizers (from the EEPROM - area 7 - DAC). */
3012 m.mmw_fee_addr = 0x61;
3013 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3014 mmc_write(ioaddr, (char *)&m.mmw_fee_ctrl - (char *)&m,
3015 (unsigned char *)&m.mmw_fee_ctrl, 2);
3017 /* Wait until the download is finished. */
3018 } /* if 2.00 card */
3020 #ifdef DEBUG_CONFIG_TRACE
3021 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3022 #endif
3023 return 0;
3026 /*------------------------------------------------------------------*/
3028 * Construct the fd and rbd structures.
3029 * Start the receive unit.
3030 * (called by wv_hw_reset())
3032 static inline int
3033 wv_ru_start(device * dev)
3035 net_local * lp = (net_local *) dev->priv;
3036 u_long ioaddr = dev->base_addr;
3037 u_short scb_cs;
3038 fd_t fd;
3039 rbd_t rbd;
3040 u_short rx;
3041 u_short rx_next;
3042 int i;
3044 #ifdef DEBUG_CONFIG_TRACE
3045 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3046 #endif
3048 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status), (unsigned char *)&scb_cs, sizeof(scb_cs));
3049 if((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
3050 return 0;
3052 lp->rx_head = OFFSET_RU;
3054 for(i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next)
3056 rx_next = (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
3058 fd.fd_status = 0;
3059 fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
3060 fd.fd_link_offset = rx_next;
3061 fd.fd_rbd_offset = rx + sizeof(fd);
3062 obram_write(ioaddr, rx, (unsigned char *)&fd, sizeof(fd));
3064 rbd.rbd_status = 0;
3065 rbd.rbd_next_rbd_offset = I82586NULL;
3066 rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
3067 rbd.rbd_bufh = 0;
3068 rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
3069 obram_write(ioaddr, rx + sizeof(fd),
3070 (unsigned char *) &rbd, sizeof(rbd));
3072 lp->rx_last = rx;
3075 obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
3076 (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
3078 scb_cs = SCB_CMD_RUC_GO;
3079 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3080 (unsigned char *) &scb_cs, sizeof(scb_cs));
3082 set_chan_attn(ioaddr, lp->hacr);
3084 for(i = 1000; i > 0; i--)
3086 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3087 (unsigned char *) &scb_cs, sizeof(scb_cs));
3088 if (scb_cs == 0)
3089 break;
3091 udelay(10);
3094 if(i <= 0)
3096 #ifdef DEBUG_CONFIG_ERROR
3097 printk(KERN_INFO "%s: wavelan_ru_start(): board not accepting command.\n",
3098 dev->name);
3099 #endif
3100 return -1;
3103 #ifdef DEBUG_CONFIG_TRACE
3104 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3105 #endif
3106 return 0;
3109 /*------------------------------------------------------------------*/
3111 * Initialise the transmit blocks.
3112 * Start the command unit executing the NOP
3113 * self-loop of the first transmit block.
3115 * Here we create the list of send buffers used to transmit packets
3116 * between the PC and the command unit. For each buffer, we create a
3117 * buffer descriptor (pointing on the buffer), a transmit command
3118 * (pointing to the buffer descriptor) and a NOP command.
3119 * The transmit command is linked to the NOP, and the NOP to itself.
3120 * When we will have finished executing the transmit command, we will
3121 * then loop on the NOP. By releasing the NOP link to a new command,
3122 * we may send another buffer.
3124 * (called by wv_hw_reset())
3126 static inline int
3127 wv_cu_start(device * dev)
3129 net_local * lp = (net_local *) dev->priv;
3130 u_long ioaddr = dev->base_addr;
3131 int i;
3132 u_short txblock;
3133 u_short first_nop;
3134 u_short scb_cs;
3136 #ifdef DEBUG_CONFIG_TRACE
3137 printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
3138 #endif
3140 lp->tx_first_free = OFFSET_CU;
3141 lp->tx_first_in_use = I82586NULL;
3143 for(i = 0, txblock = OFFSET_CU;
3144 i < NTXBLOCKS;
3145 i++, txblock += TXBLOCKZ)
3147 ac_tx_t tx;
3148 ac_nop_t nop;
3149 tbd_t tbd;
3150 unsigned short tx_addr;
3151 unsigned short nop_addr;
3152 unsigned short tbd_addr;
3153 unsigned short buf_addr;
3155 tx_addr = txblock;
3156 nop_addr = tx_addr + sizeof(tx);
3157 tbd_addr = nop_addr + sizeof(nop);
3158 buf_addr = tbd_addr + sizeof(tbd);
3160 tx.tx_h.ac_status = 0;
3161 tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
3162 tx.tx_h.ac_link = nop_addr;
3163 tx.tx_tbd_offset = tbd_addr;
3164 obram_write(ioaddr, tx_addr, (unsigned char *) &tx, sizeof(tx));
3166 nop.nop_h.ac_status = 0;
3167 nop.nop_h.ac_command = acmd_nop;
3168 nop.nop_h.ac_link = nop_addr;
3169 obram_write(ioaddr, nop_addr, (unsigned char *) &nop, sizeof(nop));
3171 tbd.tbd_status = TBD_STATUS_EOF;
3172 tbd.tbd_next_bd_offset = I82586NULL;
3173 tbd.tbd_bufl = buf_addr;
3174 tbd.tbd_bufh = 0;
3175 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd));
3178 first_nop = OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
3179 obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
3180 (unsigned char *) &first_nop, sizeof(first_nop));
3182 scb_cs = SCB_CMD_CUC_GO;
3183 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3184 (unsigned char *) &scb_cs, sizeof(scb_cs));
3186 set_chan_attn(ioaddr, lp->hacr);
3188 for(i = 1000; i > 0; i--)
3190 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3191 (unsigned char *) &scb_cs, sizeof(scb_cs));
3192 if (scb_cs == 0)
3193 break;
3195 udelay(10);
3198 if(i <= 0)
3200 #ifdef DEBUG_CONFIG_ERROR
3201 printk(KERN_INFO "%s: wavelan_cu_start(): board not accepting command.\n",
3202 dev->name);
3203 #endif
3204 return -1;
3207 lp->tx_n_in_use = 0;
3208 dev->tbusy = 0;
3210 #ifdef DEBUG_CONFIG_TRACE
3211 printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
3212 #endif
3213 return 0;
3216 /*------------------------------------------------------------------*/
3218 * This routine does a standard configuration of the WaveLAN
3219 * controller (i82586).
3221 * It initialises the scp, iscp and scb structure
3222 * The first two are just pointers to the next.
3223 * The last one is used for basic configuration and for basic
3224 * communication (interrupt status).
3226 * (called by wv_hw_reset())
3228 static inline int
3229 wv_82586_start(device * dev)
3231 net_local * lp = (net_local *) dev->priv;
3232 u_long ioaddr = dev->base_addr;
3233 scp_t scp; /* system configuration pointer */
3234 iscp_t iscp; /* intermediate scp */
3235 scb_t scb; /* system control block */
3236 ach_t cb; /* Action command header */
3237 u_char zeroes[512];
3238 int i;
3240 #ifdef DEBUG_CONFIG_TRACE
3241 printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
3242 #endif
3245 * Clear the onboard RAM.
3247 memset(&zeroes[0], 0x00, sizeof(zeroes));
3248 for(i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
3249 obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
3252 * Construct the command unit structures:
3253 * scp, iscp, scb, cb.
3255 memset(&scp, 0x00, sizeof(scp));
3256 scp.scp_sysbus = SCP_SY_16BBUS;
3257 scp.scp_iscpl = OFFSET_ISCP;
3258 obram_write(ioaddr, OFFSET_SCP, (unsigned char *)&scp, sizeof(scp));
3260 memset(&iscp, 0x00, sizeof(iscp));
3261 iscp.iscp_busy = 1;
3262 iscp.iscp_offset = OFFSET_SCB;
3263 obram_write(ioaddr, OFFSET_ISCP, (unsigned char *)&iscp, sizeof(iscp));
3265 /* Our first command is to reset the i82586. */
3266 memset(&scb, 0x00, sizeof(scb));
3267 scb.scb_command = SCB_CMD_RESET;
3268 scb.scb_cbl_offset = OFFSET_CU;
3269 scb.scb_rfa_offset = OFFSET_RU;
3270 obram_write(ioaddr, OFFSET_SCB, (unsigned char *)&scb, sizeof(scb));
3272 set_chan_attn(ioaddr, lp->hacr);
3274 /* Wait for command to finish. */
3275 for(i = 1000; i > 0; i--)
3277 obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp, sizeof(iscp));
3279 if(iscp.iscp_busy == (unsigned short) 0)
3280 break;
3282 udelay(10);
3285 if(i <= 0)
3287 #ifdef DEBUG_CONFIG_ERROR
3288 printk(KERN_INFO "%s: wv_82586_start(): iscp_busy timeout.\n",
3289 dev->name);
3290 #endif
3291 return -1;
3294 /* Check command completion. */
3295 for(i = 15; i > 0; i--)
3297 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb, sizeof(scb));
3299 if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
3300 break;
3302 udelay(10);
3305 if (i <= 0)
3307 #ifdef DEBUG_CONFIG_ERROR
3308 printk(KERN_INFO "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
3309 dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
3310 #endif
3311 return -1;
3314 wv_ack(dev);
3316 /* Set the action command header. */
3317 memset(&cb, 0x00, sizeof(cb));
3318 cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
3319 cb.ac_link = OFFSET_CU;
3320 obram_write(ioaddr, OFFSET_CU, (unsigned char *)&cb, sizeof(cb));
3322 if(wv_synchronous_cmd(dev, "diag()") == -1)
3323 return -1;
3325 obram_read(ioaddr, OFFSET_CU, (unsigned char *)&cb, sizeof(cb));
3326 if(cb.ac_status & AC_SFLD_FAIL)
3328 #ifdef DEBUG_CONFIG_ERROR
3329 printk(KERN_INFO "%s: wv_82586_start(): i82586 Self Test failed.\n",
3330 dev->name);
3331 #endif
3332 return -1;
3335 #ifdef DEBUG_I82586_SHOW
3336 wv_scb_show(ioaddr);
3337 #endif
3339 #ifdef DEBUG_CONFIG_TRACE
3340 printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
3341 #endif
3342 return 0;
3345 /*------------------------------------------------------------------*/
3347 * This routine does a standard configuration of the WaveLAN
3348 * controller (i82586).
3350 * This routine is a violent hack. We use the first free transmit block
3351 * to make our configuration. In the buffer area, we create the three
3352 * configuration commands (linked). We make the previous NOP point to
3353 * the beginning of the buffer instead of the tx command. After, we go
3354 * as usual to the NOP command.
3355 * Note that only the last command (mc_set) will generate an interrupt.
3357 * (called by wv_hw_reset(), wv_82586_reconfig())
3359 static void
3360 wv_82586_config(device * dev)
3362 net_local * lp = (net_local *) dev->priv;
3363 u_long ioaddr = dev->base_addr;
3364 unsigned short txblock;
3365 unsigned short txpred;
3366 unsigned short tx_addr;
3367 unsigned short nop_addr;
3368 unsigned short tbd_addr;
3369 unsigned short cfg_addr;
3370 unsigned short ias_addr;
3371 unsigned short mcs_addr;
3372 ac_tx_t tx;
3373 ac_nop_t nop;
3374 ac_cfg_t cfg; /* Configure action */
3375 ac_ias_t ias; /* IA-setup action */
3376 ac_mcs_t mcs; /* Multicast setup */
3377 struct dev_mc_list * dmi;
3378 unsigned long x;
3380 #ifdef DEBUG_CONFIG_TRACE
3381 printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
3382 #endif
3384 x = wv_splhi();
3386 /* Calculate addresses of next block and previous block. */
3387 txblock = lp->tx_first_free;
3388 txpred = txblock - TXBLOCKZ;
3389 if(txpred < OFFSET_CU)
3390 txpred += NTXBLOCKS * TXBLOCKZ;
3391 lp->tx_first_free += TXBLOCKZ;
3392 if(lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
3393 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
3395 lp->tx_n_in_use++;
3397 /* Calculate addresses of the different parts of the block. */
3398 tx_addr = txblock;
3399 nop_addr = tx_addr + sizeof(tx);
3400 tbd_addr = nop_addr + sizeof(nop);
3401 cfg_addr = tbd_addr + sizeof(tbd_t); /* beginning of the buffer */
3402 ias_addr = cfg_addr + sizeof(cfg);
3403 mcs_addr = ias_addr + sizeof(ias);
3406 * Transmit command
3408 tx.tx_h.ac_status = 0xFFFF; /* Fake completion value */
3409 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
3410 (unsigned char *) &tx.tx_h.ac_status,
3411 sizeof(tx.tx_h.ac_status));
3414 * NOP command
3416 nop.nop_h.ac_status = 0;
3417 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3418 (unsigned char *) &nop.nop_h.ac_status,
3419 sizeof(nop.nop_h.ac_status));
3420 nop.nop_h.ac_link = nop_addr;
3421 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3422 (unsigned char *) &nop.nop_h.ac_link,
3423 sizeof(nop.nop_h.ac_link));
3425 /* Create a configure action. */
3426 memset(&cfg, 0x00, sizeof(cfg));
3429 * For Linux we invert AC_CFG_ALOC() so as to conform
3430 * to the way that net packets reach us from above.
3431 * (See also ac_tx_t.)
3433 * Updated from Wavelan Manual WCIN085B
3435 cfg.cfg_byte_cnt = 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) |
3438 AC_CFG_SRDY(0);
3439 cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
3440 AC_CFG_ILPBCK(0) |
3441 AC_CFG_PRELEN(AC_CFG_PLEN_2) |
3442 AC_CFG_ALOC(1) |
3443 AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
3444 cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
3445 AC_CFG_ACR(6) |
3446 AC_CFG_LINPRIO(0);
3447 cfg.cfg_ifs = 0x20;
3448 cfg.cfg_slotl = 0x0C;
3449 cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) |
3450 AC_CFG_SLTTMHI(0);
3451 cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
3452 AC_CFG_BTSTF(0) |
3453 AC_CFG_CRC16(0) |
3454 AC_CFG_NCRC(0) |
3455 AC_CFG_TNCRS(1) |
3456 AC_CFG_MANCH(0) |
3457 AC_CFG_BCDIS(0) |
3458 AC_CFG_PRM(lp->promiscuous);
3459 cfg.cfg_byte15 = AC_CFG_ICDS(0) |
3460 AC_CFG_CDTF(0) |
3461 AC_CFG_ICSS(0) |
3462 AC_CFG_CSTF(0);
3464 cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
3466 cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
3468 cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
3469 cfg.cfg_h.ac_link = ias_addr;
3470 obram_write(ioaddr, cfg_addr, (unsigned char *)&cfg, sizeof(cfg));
3472 /* Set up the MAC address */
3473 memset(&ias, 0x00, sizeof(ias));
3474 ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
3475 ias.ias_h.ac_link = mcs_addr;
3476 memcpy(&ias.ias_addr[0], (unsigned char *)&dev->dev_addr[0], sizeof(ias.ias_addr));
3477 obram_write(ioaddr, ias_addr, (unsigned char *)&ias, sizeof(ias));
3479 /* Initialize adapter's Ethernet multicast addresses */
3480 memset(&mcs, 0x00, sizeof(mcs));
3481 mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
3482 mcs.mcs_h.ac_link = nop_addr;
3483 mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
3484 obram_write(ioaddr, mcs_addr, (unsigned char *)&mcs, sizeof(mcs));
3486 /* Any address to set? */
3487 if(lp->mc_count)
3489 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3490 outsw(PIOP1(ioaddr), (u_short *) dmi->dmi_addr,
3491 WAVELAN_ADDR_SIZE >> 1);
3493 #ifdef DEBUG_CONFIG_INFO
3494 printk(KERN_DEBUG "%s: wv_82586_config(): set %d multicast addresses:\n",
3495 dev->name, lp->mc_count);
3496 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3497 printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n",
3498 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
3499 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
3500 #endif
3504 * Overwrite the predecessor NOP link
3505 * so that it points to the configure action.
3507 nop_addr = txpred + sizeof(tx);
3508 nop.nop_h.ac_status = 0;
3509 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3510 (unsigned char *)&nop.nop_h.ac_status,
3511 sizeof(nop.nop_h.ac_status));
3512 nop.nop_h.ac_link = cfg_addr;
3513 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3514 (unsigned char *) &nop.nop_h.ac_link,
3515 sizeof(nop.nop_h.ac_link));
3517 /* If watchdog not already active, activate it... */
3518 if(lp->watchdog.prev == (timer_list *) NULL)
3520 /* set timer to expire in WATCHDOG_JIFFIES */
3521 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
3522 add_timer(&lp->watchdog);
3525 lp->reconfig_82586 = 0;
3527 if(lp->tx_first_in_use == I82586NULL)
3528 lp->tx_first_in_use = txblock;
3530 if(lp->tx_n_in_use < NTXBLOCKS - 1)
3531 dev->tbusy = 0;
3533 wv_splx(x);
3535 #ifdef DEBUG_CONFIG_TRACE
3536 printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
3537 #endif
3540 /*------------------------------------------------------------------*/
3542 * This routine, called by wavelan_close(), gracefully stops the
3543 * WaveLAN controller (i82586).
3545 static inline void
3546 wv_82586_stop(device * dev)
3548 net_local * lp = (net_local *) dev->priv;
3549 u_long ioaddr = dev->base_addr;
3550 u_short scb_cmd;
3552 #ifdef DEBUG_CONFIG_TRACE
3553 printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
3554 #endif
3556 /* Suspend both command unit and receive unit. */
3557 scb_cmd = (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC & SCB_CMD_RUC_SUS);
3558 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3559 (unsigned char *)&scb_cmd, sizeof(scb_cmd));
3560 set_chan_attn(ioaddr, lp->hacr);
3562 /* No more interrupts */
3563 wv_ints_off(dev);
3565 #ifdef DEBUG_CONFIG_TRACE
3566 printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
3567 #endif
3570 /*------------------------------------------------------------------*/
3572 * Totally reset the WaveLAN and restart it.
3573 * Performs the following actions:
3574 * 1. A power reset (reset DMA)
3575 * 2. Initialize the radio modem (using wv_mmc_init)
3576 * 3. Reset & Configure LAN controller (using wv_82586_start)
3577 * 4. Start the LAN controller's command unit
3578 * 5. Start the LAN controller's receive unit
3580 static int
3581 wv_hw_reset(device * dev)
3583 net_local * lp = (net_local *)dev->priv;
3584 u_long ioaddr = dev->base_addr;
3586 #ifdef DEBUG_CONFIG_TRACE
3587 printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
3588 (unsigned int)dev);
3589 #endif
3591 /* If watchdog was activated, kill it! */
3592 if(lp->watchdog.prev != (timer_list *) NULL)
3593 del_timer(&lp->watchdog);
3595 /* Increase the number of resets done. */
3596 lp->nresets++;
3598 wv_hacr_reset(ioaddr);
3599 lp->hacr = HACR_DEFAULT;
3601 if((wv_mmc_init(dev) < 0) ||
3602 (wv_82586_start(dev) < 0))
3603 return -1;
3605 /* Enable the card to send interrupts. */
3606 wv_ints_on(dev);
3608 /* Start card functions */
3609 if(wv_cu_start(dev) < 0)
3610 return -1;
3612 /* Setup the controller and parameters */
3613 wv_82586_config(dev);
3615 /* Finish configuration with the receive unit */
3616 if(wv_ru_start(dev) < 0)
3617 return -1;
3619 #ifdef DEBUG_CONFIG_TRACE
3620 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3621 #endif
3622 return 0;
3625 /*------------------------------------------------------------------*/
3627 * Check if there is a WaveLAN at the specific base address.
3628 * As a side effect, this reads the MAC address.
3629 * (called in wavelan_probe() and init_module())
3631 static int
3632 wv_check_ioaddr(u_long ioaddr,
3633 u_char * mac)
3635 int i; /* Loop counter */
3637 /* Check if the base address if available. */
3638 if(check_region(ioaddr, sizeof(ha_t)))
3639 return EADDRINUSE; /* ioaddr already used */
3641 /* Reset host interface */
3642 wv_hacr_reset(ioaddr);
3644 /* Read the MAC address from the parameter storage area. */
3645 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
3646 mac, 6);
3649 * Check the first three octets of the address for the manufacturer's code.
3650 * Note: if this can't find your WaveLAN card, you've got a
3651 * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on
3652 * how to configure your card.
3654 for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3655 if((mac[0] == MAC_ADDRESSES[i][0]) &&
3656 (mac[1] == MAC_ADDRESSES[i][1]) &&
3657 (mac[2] == MAC_ADDRESSES[i][2]))
3658 return 0;
3660 #ifdef DEBUG_CONFIG_INFO
3661 printk(KERN_WARNING "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
3662 ioaddr, mac[0], mac[1], mac[2]);
3663 #endif
3664 return ENODEV;
3667 /************************ INTERRUPT HANDLING ************************/
3670 * This function is the interrupt handler for the WaveLAN card. This
3671 * routine will be called whenever:
3673 static void
3674 wavelan_interrupt(int irq,
3675 void * dev_id,
3676 struct pt_regs * regs)
3678 device * dev;
3679 u_long ioaddr;
3680 net_local * lp;
3681 u_short hasr;
3682 u_short status;
3683 u_short ack_cmd;
3685 dev = dev_id;
3687 #ifdef DEBUG_INTERRUPT_TRACE
3688 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
3689 #endif
3691 lp = (net_local *) dev->priv;
3692 ioaddr = dev->base_addr;
3694 /* Prevent reentrance. What should we do here? */
3695 #ifdef DEBUG_INTERRUPT_ERROR
3696 if(dev->interrupt)
3697 printk(KERN_INFO "%s: wavelan_interrupt(): Re-entering the interrupt handler.\n",
3698 dev->name);
3699 #endif
3700 dev->interrupt = 1;
3702 if((hasr = hasr_read(ioaddr)) & HASR_MMC_INTR)
3704 u_char dce_status;
3707 * Interrupt from the modem management controller.
3708 * This will clear it -- ignored for now.
3710 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status, sizeof(dce_status));
3711 #ifdef DEBUG_INTERRUPT_ERROR
3712 printk(KERN_INFO "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
3713 dev->name, dce_status);
3714 #endif
3717 if((hasr & HASR_82586_INTR) == 0)
3719 dev->interrupt = 0;
3720 #ifdef DEBUG_INTERRUPT_ERROR
3721 printk(KERN_INFO "%s: wavelan_interrupt(): interrupt not coming from i82586\n",
3722 dev->name);
3723 #endif
3724 return;
3727 /* Read interrupt data. */
3728 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3729 (unsigned char *) &status, sizeof(status));
3732 * Acknowledge the interrupt(s).
3734 ack_cmd = status & SCB_ST_INT;
3735 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3736 (unsigned char *) &ack_cmd, sizeof(ack_cmd));
3737 set_chan_attn(ioaddr, lp->hacr);
3739 #ifdef DEBUG_INTERRUPT_INFO
3740 printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
3741 dev->name, status);
3742 #endif
3744 /* Command completed. */
3745 if((status & SCB_ST_CX) == SCB_ST_CX)
3747 #ifdef DEBUG_INTERRUPT_INFO
3748 printk(KERN_DEBUG "%s: wavelan_interrupt(): command completed.\n",
3749 dev->name);
3750 #endif
3751 wv_complete(dev, ioaddr, lp);
3753 /* If watchdog was activated, kill it ! */
3754 if(lp->watchdog.prev != (timer_list *) NULL)
3755 del_timer(&lp->watchdog);
3756 if(lp->tx_n_in_use > 0)
3758 /* set timer to expire in WATCHDOG_JIFFIES */
3759 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
3760 add_timer(&lp->watchdog);
3764 /* Frame received. */
3765 if((status & SCB_ST_FR) == SCB_ST_FR)
3767 #ifdef DEBUG_INTERRUPT_INFO
3768 printk(KERN_DEBUG "%s: wavelan_interrupt(): received packet.\n",
3769 dev->name);
3770 #endif
3771 wv_receive(dev);
3774 /* Check the state of the command unit. */
3775 if(((status & SCB_ST_CNA) == SCB_ST_CNA) ||
3776 (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) && dev->start))
3778 #ifdef DEBUG_INTERRUPT_ERROR
3779 printk(KERN_INFO "%s: wavelan_interrupt(): CU inactive -- restarting\n",
3780 dev->name);
3781 #endif
3782 wv_hw_reset(dev);
3785 /* Check the state of the command unit. */
3786 if(((status & SCB_ST_RNR) == SCB_ST_RNR) ||
3787 (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) && dev->start))
3789 #ifdef DEBUG_INTERRUPT_ERROR
3790 printk(KERN_INFO "%s: wavelan_interrupt(): RU not ready -- restarting\n",
3791 dev->name);
3792 #endif
3793 wv_hw_reset(dev);
3796 dev->interrupt = 0;
3798 #ifdef DEBUG_INTERRUPT_TRACE
3799 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
3800 #endif
3803 /*------------------------------------------------------------------*/
3805 * Watchdog: when we start a transmission, we set a timer in the
3806 * kernel. If the transmission completes, this timer is disabled. If
3807 * the timer expires, we try to unlock the hardware.
3809 * Note: this watchdog doesn't work on the same principle as the
3810 * watchdog in the previous version of the ISA driver. I made it this
3811 * way because the overhead of add_timer() and del_timer() is nothing
3812 * and because it avoids calling the watchdog, saving some CPU.
3814 static void
3815 wavelan_watchdog(u_long a)
3817 device * dev;
3818 net_local * lp;
3819 u_long ioaddr;
3820 unsigned long x;
3821 unsigned int nreaped;
3823 dev = (device *) a;
3824 ioaddr = dev->base_addr;
3825 lp = (net_local *) dev->priv;
3827 #ifdef DEBUG_INTERRUPT_TRACE
3828 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
3829 #endif
3831 #ifdef DEBUG_INTERRUPT_ERROR
3832 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
3833 dev->name);
3834 #endif
3836 x = wv_splhi();
3838 dev = (device *) a;
3839 ioaddr = dev->base_addr;
3840 lp = (net_local *) dev->priv;
3842 if(lp->tx_n_in_use <= 0)
3844 wv_splx(x);
3845 return;
3848 nreaped = wv_complete(dev, ioaddr, lp);
3850 #ifdef DEBUG_INTERRUPT_INFO
3851 printk(KERN_DEBUG "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
3852 dev->name, nreaped, lp->tx_n_in_use);
3853 #endif
3855 #ifdef DEBUG_PSA_SHOW
3857 psa_t psa;
3858 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3859 wv_psa_show(&psa);
3861 #endif
3862 #ifdef DEBUG_MMC_SHOW
3863 wv_mmc_show(dev);
3864 #endif
3865 #ifdef DEBUG_I82586_SHOW
3866 wv_cu_show(dev);
3867 #endif
3869 /* If no buffer has been freed */
3870 if(nreaped == 0)
3872 #ifdef DEBUG_INTERRUPT_ERROR
3873 printk(KERN_INFO "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
3874 dev->name);
3875 #endif
3876 wv_hw_reset(dev);
3878 else
3879 /* Reset watchdog for next transmission. */
3880 if(lp->tx_n_in_use > 0)
3882 /* set timer to expire in WATCHDOG_JIFFIES */
3883 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
3884 add_timer(&lp->watchdog);
3887 wv_splx(x);
3889 #ifdef DEBUG_INTERRUPT_TRACE
3890 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
3891 #endif
3894 /********************* CONFIGURATION CALLBACKS *********************/
3896 * Here are the functions called by the Linux networking code (NET3)
3897 * for initialization, configuration and deinstallations of the
3898 * WaveLAN ISA hardware.
3901 /*------------------------------------------------------------------*/
3903 * Configure and start up the WaveLAN PCMCIA adaptor.
3904 * Called by NET3 when it "opens" the device.
3906 static int
3907 wavelan_open(device * dev)
3909 u_long x;
3911 #ifdef DEBUG_CALLBACK_TRACE
3912 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
3913 (unsigned int) dev);
3914 #endif
3916 /* Check irq */
3917 if(dev->irq == 0)
3919 #ifdef DEBUG_CONFIG_ERROR
3920 printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n", dev->name);
3921 #endif
3922 return -ENXIO;
3925 if(request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0)
3927 #ifdef DEBUG_CONFIG_ERROR
3928 printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n", dev->name);
3929 #endif
3930 return -EAGAIN;
3933 x = wv_splhi();
3934 if(wv_hw_reset(dev) != -1)
3936 dev->interrupt = 0;
3937 dev->start = 1;
3939 else
3941 free_irq(dev->irq, dev);
3942 #ifdef DEBUG_CONFIG_ERROR
3943 printk(KERN_INFO "%s: wavelan_open(): impossible to start the card\n",
3944 dev->name);
3945 #endif
3946 return -EAGAIN;
3948 wv_splx(x);
3950 MOD_INC_USE_COUNT;
3952 #ifdef DEBUG_CALLBACK_TRACE
3953 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
3954 #endif
3955 return 0;
3958 /*------------------------------------------------------------------*/
3960 * Shut down the WaveLAN ISA card.
3961 * Called by NET3 when it "closes" the device.
3963 static int
3964 wavelan_close(device * dev)
3966 net_local * lp = (net_local *)dev->priv;
3968 #ifdef DEBUG_CALLBACK_TRACE
3969 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
3970 (unsigned int) dev);
3971 #endif
3973 /* Don't do the job twice. */
3974 if(dev->start == 0)
3975 return 0;
3977 dev->tbusy = 1;
3978 dev->start = 0;
3980 /* If watchdog was activated, kill it! */
3981 if(lp->watchdog.prev != (timer_list *) NULL)
3982 del_timer(&lp->watchdog);
3985 * Flush the Tx and disable Rx.
3987 wv_82586_stop(dev);
3989 free_irq(dev->irq, dev);
3991 MOD_DEC_USE_COUNT;
3993 #ifdef DEBUG_CALLBACK_TRACE
3994 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
3995 #endif
3996 return 0;
3999 /*------------------------------------------------------------------*/
4001 * Probe an I/O address, and if the WaveLAN is there configure the
4002 * device structure
4003 * (called by wavelan_probe() and via init_module()).
4005 static int __init
4006 wavelan_config(device * dev)
4008 u_long ioaddr = dev->base_addr;
4009 u_char irq_mask;
4010 int irq;
4011 net_local * lp;
4013 #ifdef DEBUG_CALLBACK_TRACE
4014 printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%x)\n", dev->name,
4015 (unsigned int)dev, ioaddr);
4016 #endif
4018 /* Check IRQ argument on command line. */
4019 if(dev->irq != 0)
4021 irq_mask = wv_irq_to_psa(dev->irq);
4023 if(irq_mask == 0)
4025 #ifdef DEBUG_CONFIG_ERROR
4026 printk(KERN_WARNING "%s: wavelan_config(): invalid IRQ %d ignored.\n",
4027 dev->name, dev->irq);
4028 #endif
4029 dev->irq = 0;
4031 else
4033 #ifdef DEBUG_CONFIG_INFO
4034 printk(KERN_DEBUG "%s: wavelan_config(): changing IRQ to %d\n",
4035 dev->name, dev->irq);
4036 #endif
4037 psa_write(ioaddr, HACR_DEFAULT,
4038 psaoff(0, psa_int_req_no), &irq_mask, 1);
4039 /* update the Wavelan checksum */
4040 update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
4041 wv_hacr_reset(ioaddr);
4045 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no), &irq_mask, 1);
4046 if((irq = wv_psa_to_irq(irq_mask)) == -1)
4048 #ifdef DEBUG_CONFIG_ERROR
4049 printk(KERN_INFO "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
4050 dev->name, irq_mask);
4051 #endif
4052 return EAGAIN;
4055 dev->irq = irq;
4057 request_region(ioaddr, sizeof(ha_t), "wavelan");
4059 dev->mem_start = 0x0000;
4060 dev->mem_end = 0x0000;
4061 dev->if_port = 0;
4063 /* Initialize device structures */
4064 dev->priv = kmalloc(sizeof(net_local), GFP_KERNEL);
4065 if(dev->priv == NULL)
4066 return -ENOMEM;
4067 memset(dev->priv, 0x00, sizeof(net_local));
4068 lp = (net_local *)dev->priv;
4070 /* Back link to the device structure. */
4071 lp->dev = dev;
4072 /* Add the device at the beginning of the linked list. */
4073 lp->next = wavelan_list;
4074 wavelan_list = lp;
4076 lp->hacr = HACR_DEFAULT;
4078 lp->watchdog.function = wavelan_watchdog;
4079 lp->watchdog.data = (unsigned long) dev;
4080 lp->promiscuous = 0;
4081 lp->mc_count = 0;
4084 * Fill in the fields of the device structure
4085 * with generic Ethernet values.
4087 ether_setup(dev);
4089 dev->open = wavelan_open;
4090 dev->stop = wavelan_close;
4091 dev->hard_start_xmit = wavelan_packet_xmit;
4092 dev->get_stats = wavelan_get_stats;
4093 dev->set_multicast_list = &wavelan_set_multicast_list;
4094 #ifdef SET_MAC_ADDRESS
4095 dev->set_mac_address = &wavelan_set_mac_address;
4096 #endif /* SET_MAC_ADDRESS */
4098 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
4099 dev->do_ioctl = wavelan_ioctl;
4100 dev->get_wireless_stats = wavelan_get_wireless_stats;
4101 #endif
4103 dev->mtu = WAVELAN_MTU;
4105 /* Display nice information. */
4106 wv_init_info(dev);
4108 #ifdef DEBUG_CALLBACK_TRACE
4109 printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
4110 #endif
4111 return 0;
4114 /*------------------------------------------------------------------*/
4116 * Check for a network adaptor of this type. Return '0' iff one
4117 * exists. There seem to be different interpretations of
4118 * the initial value of dev->base_addr.
4119 * We follow the example in drivers/net/ne.c.
4120 * (called in "Space.c")
4122 int __init
4123 wavelan_probe(device * dev)
4125 short base_addr;
4126 mac_addr mac; /* MAC address (check existence of WaveLAN) */
4127 int i;
4128 int r;
4130 #ifdef DEBUG_CALLBACK_TRACE
4131 printk(KERN_DEBUG "%s: ->wavelan_probe(dev=0x%x (base_addr=0x%x))\n",
4132 dev->name, (unsigned int)dev, (unsigned int)dev->base_addr);
4133 #endif
4135 #ifdef STRUCT_CHECK
4136 if (wv_struct_check() != (char *) NULL)
4138 printk(KERN_WARNING "%s: wavelan_probe(): structure/compiler botch: \"%s\"\n",
4139 dev->name, wv_struct_check());
4140 return ENODEV;
4142 #endif /* STRUCT_CHECK */
4144 /* Check the value of the command line parameter for base address. */
4145 base_addr = dev->base_addr;
4147 /* Don't probe at all. */
4148 if(base_addr < 0)
4150 #ifdef DEBUG_CONFIG_ERROR
4151 printk(KERN_WARNING "%s: wavelan_probe(): invalid base address\n",
4152 dev->name);
4153 #endif
4154 return ENXIO;
4157 /* Check a single specified location. */
4158 if(base_addr > 0x100)
4160 /* Check if there is something at this base address */
4161 if((r = wv_check_ioaddr(base_addr, mac)) == 0)
4163 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4164 r = wavelan_config(dev);
4167 #ifdef DEBUG_CONFIG_INFO
4168 if(r != 0)
4169 printk(KERN_DEBUG "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
4170 dev->name, base_addr);
4171 #endif
4173 #ifdef DEBUG_CALLBACK_TRACE
4174 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4175 #endif
4176 return r;
4179 /* Scan all possible addresses of the WaveLAN hardware. */
4180 for(i = 0; i < NELS(iobase); i++)
4182 /* Check whether there is something at this base address. */
4183 if(wv_check_ioaddr(iobase[i], mac) == 0)
4185 dev->base_addr = iobase[i]; /* Copy base address. */
4186 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4187 if(wavelan_config(dev) == 0)
4189 #ifdef DEBUG_CALLBACK_TRACE
4190 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4191 #endif
4192 return 0;
4197 /* We may have touched base_addr. Another driver may not like it. */
4198 dev->base_addr = base_addr;
4200 #ifdef DEBUG_CONFIG_INFO
4201 printk(KERN_DEBUG "%s: wavelan_probe(): no device found\n",
4202 dev->name);
4203 #endif
4205 return ENODEV;
4208 /****************************** MODULE ******************************/
4210 * Module entry point: insertion and removal
4213 #ifdef MODULE
4214 /*------------------------------------------------------------------*/
4216 * Insertion of the module
4217 * I'm now quite proud of the multi-device support.
4220 init_module(void)
4222 mac_addr mac; /* MAC address (check WaveLAN existence) */
4223 int ret = -EIO; /* Return error if no cards found */
4224 int i;
4226 #ifdef DEBUG_MODULE_TRACE
4227 printk(KERN_DEBUG "-> init_module()\n");
4228 #endif
4230 /* If probing is asked */
4231 if(io[0] == 0)
4233 #ifdef DEBUG_CONFIG_ERROR
4234 printk(KERN_WARNING "WaveLAN init_module(): doing device probing (bad !)\n");
4235 printk(KERN_WARNING "Specify base addresses while loading module to correct the problem\n");
4236 #endif
4238 /* Copy the basic set of address to be probed. */
4239 for(i = 0; i < NELS(iobase); i++)
4240 io[i] = iobase[i];
4244 /* Loop on all possible base addresses. */
4245 i = -1;
4246 while((io[++i] != 0) && (i < NELS(io)))
4248 /* Check if there is something at this base address. */
4249 if(wv_check_ioaddr(io[i], mac) == 0)
4251 device * dev;
4253 /* Create device and set basic arguments. */
4254 dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
4255 if(dev==NULL)
4257 ret = -ENOMEM;
4258 break;
4260 memset(dev, 0x00, sizeof(struct net_device));
4261 dev->name = name[i];
4262 dev->base_addr = io[i];
4263 dev->irq = irq[i];
4264 dev->init = &wavelan_config;
4265 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4267 /* Try to create the device. */
4268 if(register_netdev(dev) != 0)
4270 /* Deallocate everything. */
4271 /* Note: if dev->priv is mallocated, there is no way to fail. */
4272 kfree_s(dev, sizeof(struct net_device));
4274 else
4276 /* If at least one device OK, we do not fail */
4277 ret = 0;
4279 } /* if there is something at the address */
4280 } /* Loop on all addresses. */
4282 #ifdef DEBUG_CONFIG_ERROR
4283 if(wavelan_list == (net_local *) NULL)
4284 printk(KERN_WARNING "WaveLAN init_module(): no device found\n");
4285 #endif
4287 #ifdef DEBUG_MODULE_TRACE
4288 printk(KERN_DEBUG "<- init_module()\n");
4289 #endif
4290 return ret;
4293 /*------------------------------------------------------------------*/
4295 * Removal of the module
4297 void
4298 cleanup_module(void)
4300 #ifdef DEBUG_MODULE_TRACE
4301 printk(KERN_DEBUG "-> cleanup_module()\n");
4302 #endif
4304 /* Loop on all devices and release them. */
4305 while(wavelan_list != (net_local *) NULL)
4307 device * dev = wavelan_list->dev;
4309 #ifdef DEBUG_CONFIG_INFO
4310 printk(KERN_DEBUG "%s: cleanup_module(): removing device at 0x%x\n",
4311 dev->name, (unsigned int) dev);
4312 #endif
4314 /* Release the ioport region. */
4315 release_region(dev->base_addr, sizeof(ha_t));
4317 /* Definitely remove the device. */
4318 unregister_netdev(dev);
4320 /* Unlink the device. */
4321 wavelan_list = wavelan_list->next;
4323 /* Free pieces. */
4324 kfree_s(dev->priv, sizeof(struct net_local));
4325 kfree_s(dev, sizeof(struct net_device));
4328 #ifdef DEBUG_MODULE_TRACE
4329 printk(KERN_DEBUG "<- cleanup_module()\n");
4330 #endif
4332 #endif /* MODULE */
4335 * This software may only be used and distributed
4336 * according to the terms of the GNU Public License.
4338 * This software was developed as a component of the
4339 * Linux operating system.
4340 * It is based on other device drivers and information
4341 * either written or supplied by:
4342 * Ajay Bakre (bakre@paul.rutgers.edu),
4343 * Donald Becker (becker@cesdis.gsfc.nasa.gov),
4344 * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
4345 * Anders Klemets (klemets@it.kth.se),
4346 * Vladimir V. Kolpakov (w@stier.koenig.ru),
4347 * Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
4348 * Pauline Middelink (middelin@polyware.iaf.nl),
4349 * Robert Morris (rtm@das.harvard.edu),
4350 * Jean Tourrilhes (jt@hplb.hpl.hp.com),
4351 * Girish Welling (welling@paul.rutgers.edu),
4353 * Thanks go also to:
4354 * James Ashton (jaa101@syseng.anu.edu.au),
4355 * Alan Cox (iialan@iiit.swan.ac.uk),
4356 * Allan Creighton (allanc@cs.usyd.edu.au),
4357 * Matthew Geier (matthew@cs.usyd.edu.au),
4358 * Remo di Giovanni (remo@cs.usyd.edu.au),
4359 * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
4360 * Vipul Gupta (vgupta@cs.binghamton.edu),
4361 * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
4362 * Tim Nicholson (tim@cs.usyd.edu.au),
4363 * Ian Parkin (ian@cs.usyd.edu.au),
4364 * John Rosenberg (johnr@cs.usyd.edu.au),
4365 * George Rossi (george@phm.gov.au),
4366 * Arthur Scott (arthur@cs.usyd.edu.au),
4367 * Peter Storey,
4368 * for their assistance and advice.
4370 * Please send bug reports, updates, comments to:
4372 * Bruce Janson Email: bruce@cs.usyd.edu.au
4373 * Basser Department of Computer Science Phone: +61-2-9351-3423
4374 * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838