Import 2.3.18pre1
[davej-history.git] / drivers / net / wavelan.c
blob96a4e479055e8068f3f278601bd6923da6dd7be8
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 * 1024 * 1024; /* 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())
2243 return -EPERM;
2244 psa.psa_quality_thr = *(wrq->u.name) & 0x0F;
2245 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_quality_thr - (char *)&psa,
2246 (unsigned char *)&psa.psa_quality_thr, 1);
2247 /* update the Wavelan checksum */
2248 update_psa_checksum(dev, ioaddr, lp->hacr);
2249 mmc_out(ioaddr, mmwoff(0, mmw_quality_thr), psa.psa_quality_thr);
2250 break;
2252 case SIOCGIPQTHR:
2253 psa_read(ioaddr, lp->hacr, (char *)&psa.psa_quality_thr - (char *)&psa,
2254 (unsigned char *)&psa.psa_quality_thr, 1);
2255 *(wrq->u.name) = psa.psa_quality_thr & 0x0F;
2256 break;
2258 #ifdef HISTOGRAM
2259 case SIOCSIPHISTO:
2260 /* Verify that the user is root. */
2261 if(!suser())
2262 return -EPERM;
2264 /* Check the number of intervals. */
2265 if(wrq->u.data.length > 16)
2267 ret = -E2BIG;
2268 break;
2270 lp->his_number = wrq->u.data.length;
2272 /* Are there addresses to copy? */
2273 if(lp->his_number > 0)
2275 /* Copy interval ranges to the driver */
2276 if (copy_from_user(lp->his_range, wrq->u.data.pointer, sizeof(char) * lp->his_number)) {
2277 ret = -EFAULT;
2278 break;
2281 /* Reset structure. */
2282 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2284 break;
2286 case SIOCGIPHISTO:
2287 /* Set the number of intervals. */
2288 wrq->u.data.length = lp->his_number;
2290 /* Give back the distribution statistics */
2291 if((lp->his_number > 0) && (wrq->u.data.pointer != (caddr_t) 0))
2293 /* Copy data to the user buffer. */
2294 if (copy_to_user(wrq->u.data.pointer, lp->his_sum, sizeof(long) * lp->his_number))
2295 ret = -EFAULT;
2297 } /* if(pointer != NULL) */
2298 break;
2299 #endif /* HISTOGRAM */
2301 /* ------------------- OTHER IOCTL ------------------- */
2303 default:
2304 ret = -EOPNOTSUPP;
2307 /* Enable interrupts and restore flags. */
2308 wv_splx(x);
2310 #ifdef DEBUG_IOCTL_TRACE
2311 printk(KERN_DEBUG "%s: <-wavelan_ioctl()\n", dev->name);
2312 #endif
2313 return ret;
2316 /*------------------------------------------------------------------*/
2318 * Get wireless statistics.
2319 * Called by /proc/net/wireless
2321 static iw_stats *
2322 wavelan_get_wireless_stats(device * dev)
2324 u_long ioaddr = dev->base_addr;
2325 net_local * lp = (net_local *) dev->priv;
2326 mmr_t m;
2327 iw_stats * wstats;
2328 unsigned long x;
2330 #ifdef DEBUG_IOCTL_TRACE
2331 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
2332 #endif
2334 /* Disable interrupts and save flags. */
2335 x = wv_splhi();
2337 if(lp == (net_local *) NULL)
2338 return (iw_stats *) NULL;
2339 wstats = &lp->wstats;
2341 /* Get data from the mmc. */
2342 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2344 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2345 mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
2346 mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
2348 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2350 /* Copy data to wireless stuff. */
2351 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2352 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2353 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2354 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2355 wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
2356 ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
2357 ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2358 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2359 wstats->discard.code = 0L;
2360 wstats->discard.misc = 0L;
2362 /* Enable interrupts and restore flags. */
2363 wv_splx(x);
2365 #ifdef DEBUG_IOCTL_TRACE
2366 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
2367 #endif
2368 return &lp->wstats;
2370 #endif /* WIRELESS_EXT */
2372 /************************* PACKET RECEPTION *************************/
2374 * This part deals with receiving the packets.
2375 * The interrupt handler gets an interrupt when a packet has been
2376 * successfully received and calls this part.
2379 /*------------------------------------------------------------------*/
2381 * This routine does the actual copying of data (including the Ethernet
2382 * header structure) from the WaveLAN card to an sk_buff chain that
2383 * will be passed up to the network interface layer. NOTE: we
2384 * currently don't handle trailer protocols (neither does the rest of
2385 * the network interface), so if that is needed, it will (at least in
2386 * part) be added here. The contents of the receive ring buffer are
2387 * copied to a message chain that is then passed to the kernel.
2389 * Note: if any errors occur, the packet is "dropped on the floor".
2390 * (called by wv_packet_rcv())
2392 static inline void
2393 wv_packet_read(device * dev,
2394 u_short buf_off,
2395 int sksize)
2397 net_local * lp = (net_local *) dev->priv;
2398 u_long ioaddr = dev->base_addr;
2399 struct sk_buff * skb;
2401 #ifdef DEBUG_RX_TRACE
2402 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2403 dev->name, buf_off, sksize);
2404 #endif
2406 /* Allocate buffer for the data */
2407 if((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL)
2409 #ifdef DEBUG_RX_ERROR
2410 printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
2411 dev->name, sksize);
2412 #endif
2413 lp->stats.rx_dropped++;
2414 return;
2417 skb->dev = dev;
2419 /* Copy the packet to the buffer. */
2420 obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize);
2421 skb->protocol=eth_type_trans(skb, dev);
2423 #ifdef DEBUG_RX_INFO
2424 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2425 #endif /* DEBUG_RX_INFO */
2427 /* Statistics-gathering and associated stuff.
2428 * It seem a bit messy with all the define, but it's really simple... */
2429 #if defined(WIRELESS_SPY) || defined(HISTOGRAM)
2431 #ifdef WIRELESS_SPY
2432 (lp->spy_number > 0) ||
2433 #endif /* WIRELESS_SPY */
2434 #ifdef HISTOGRAM
2435 (lp->his_number > 0) ||
2436 #endif /* HISTOGRAM */
2439 u_char stats[3]; /* signal level, noise level, signal quality */
2441 /* Read signal level, silence level and signal quality bytes. */
2442 /* Note: in the PCMCIA hardware, these are part of the frame. It seems
2443 * that for the ISA hardware, it's nowhere to be found in the frame,
2444 * so I'm obliged to do this (it has a side effect on /proc/net/wireless).
2445 * Any ideas?
2447 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2448 mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3);
2449 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2451 #ifdef DEBUG_RX_INFO
2452 printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2453 dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
2454 #endif
2456 /* Spying stuff */
2457 #ifdef WIRELESS_SPY
2458 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
2459 #endif /* WIRELESS_SPY */
2460 #ifdef HISTOGRAM
2461 wl_his_gather(dev, stats);
2462 #endif /* HISTOGRAM */
2464 #endif /* defined(WIRELESS_SPY) || defined(HISTOGRAM) */
2467 * Hand the packet to the network module.
2469 netif_rx(skb);
2471 /* Keep statistics up to date */
2472 lp->stats.rx_packets++;
2473 lp->stats.rx_bytes += skb->len;
2475 #ifdef DEBUG_RX_TRACE
2476 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2477 #endif
2480 /*------------------------------------------------------------------*/
2482 * Transfer as many packets as we can
2483 * from the device RAM.
2484 * Called by the interrupt handler.
2486 static inline void
2487 wv_receive(device * dev)
2489 u_long ioaddr = dev->base_addr;
2490 net_local * lp = (net_local *)dev->priv;
2491 fd_t fd;
2492 rbd_t rbd;
2493 int nreaped = 0;
2495 #ifdef DEBUG_RX_TRACE
2496 printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name);
2497 #endif
2499 /* Loop on each received packet. */
2500 for(;;)
2502 obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd, sizeof(fd));
2504 /* Note about the status :
2505 * It start up to be 0 (the value we set). Then, when the RU
2506 * grab the buffer to prepare for reception, it sets the
2507 * FD_STATUS_B flag. When the RU has finished receiving the
2508 * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
2509 * completion and set the other flags to indicate the eventual
2510 * errors. FD_STATUS_OK indicates that the reception was OK.
2513 /* If the current frame is not complete, we have reached the end. */
2514 if((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
2515 break; /* This is how we exit the loop. */
2517 nreaped++;
2519 /* Check whether frame was correctly received. */
2520 if((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK)
2522 /* Does the frame contain a pointer to the data? Let's check. */
2523 if(fd.fd_rbd_offset != I82586NULL)
2525 /* Read the receive buffer descriptor */
2526 obram_read(ioaddr, fd.fd_rbd_offset,
2527 (unsigned char *) &rbd, sizeof(rbd));
2529 #ifdef DEBUG_RX_ERROR
2530 if((rbd.rbd_status & RBD_STATUS_EOF) != RBD_STATUS_EOF)
2531 printk(KERN_INFO "%s: wv_receive(): missing EOF flag.\n",
2532 dev->name);
2534 if((rbd.rbd_status & RBD_STATUS_F) != RBD_STATUS_F)
2535 printk(KERN_INFO "%s: wv_receive(): missing F flag.\n",
2536 dev->name);
2537 #endif /* DEBUG_RX_ERROR */
2539 /* Read the packet and transmit to Linux */
2540 wv_packet_read(dev, rbd.rbd_bufl,
2541 rbd.rbd_status & RBD_STATUS_ACNT);
2543 #ifdef DEBUG_RX_ERROR
2544 else /* if frame has no data */
2545 printk(KERN_INFO "%s: wv_receive(): frame has no data.\n",
2546 dev->name);
2547 #endif
2549 else /* If reception was no successful */
2551 lp->stats.rx_errors++;
2553 #ifdef DEBUG_RX_INFO
2554 printk(KERN_DEBUG "%s: wv_receive(): frame not received successfully (%X).\n",
2555 dev->name, fd.fd_status);
2556 #endif
2558 #ifdef DEBUG_RX_ERROR
2559 if((fd.fd_status & FD_STATUS_S6) != 0)
2560 printk(KERN_INFO "%s: wv_receive(): no EOF flag.\n", dev->name);
2561 #endif
2563 if((fd.fd_status & FD_STATUS_S7) != 0)
2565 lp->stats.rx_length_errors++;
2566 #ifdef DEBUG_RX_FAIL
2567 printk(KERN_DEBUG "%s: wv_receive(): frame too short.\n",
2568 dev->name);
2569 #endif
2572 if((fd.fd_status & FD_STATUS_S8) != 0)
2574 lp->stats.rx_over_errors++;
2575 #ifdef DEBUG_RX_FAIL
2576 printk(KERN_DEBUG "%s: wv_receive(): rx DMA overrun.\n",
2577 dev->name);
2578 #endif
2581 if((fd.fd_status & FD_STATUS_S9) != 0)
2583 lp->stats.rx_fifo_errors++;
2584 #ifdef DEBUG_RX_FAIL
2585 printk(KERN_DEBUG "%s: wv_receive(): ran out of resources.\n",
2586 dev->name);
2587 #endif
2590 if((fd.fd_status & FD_STATUS_S10) != 0)
2592 lp->stats.rx_frame_errors++;
2593 #ifdef DEBUG_RX_FAIL
2594 printk(KERN_DEBUG "%s: wv_receive(): alignment error.\n",
2595 dev->name);
2596 #endif
2599 if((fd.fd_status & FD_STATUS_S11) != 0)
2601 lp->stats.rx_crc_errors++;
2602 #ifdef DEBUG_RX_FAIL
2603 printk(KERN_DEBUG "%s: wv_receive(): CRC error.\n", dev->name);
2604 #endif
2608 fd.fd_status = 0;
2609 obram_write(ioaddr, fdoff(lp->rx_head, fd_status),
2610 (unsigned char *) &fd.fd_status, sizeof(fd.fd_status));
2612 fd.fd_command = FD_COMMAND_EL;
2613 obram_write(ioaddr, fdoff(lp->rx_head, fd_command),
2614 (unsigned char *) &fd.fd_command, sizeof(fd.fd_command));
2616 fd.fd_command = 0;
2617 obram_write(ioaddr, fdoff(lp->rx_last, fd_command),
2618 (unsigned char *) &fd.fd_command, sizeof(fd.fd_command));
2620 lp->rx_last = lp->rx_head;
2621 lp->rx_head = fd.fd_link_offset;
2622 } /* for(;;) -> loop on all frames */
2624 #ifdef DEBUG_RX_INFO
2625 if(nreaped > 1)
2626 printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n", dev->name, nreaped);
2627 #endif
2628 #ifdef DEBUG_RX_TRACE
2629 printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name);
2630 #endif
2633 /*********************** PACKET TRANSMISSION ***********************/
2635 * This part deals with sending packets through the WaveLAN.
2639 /*------------------------------------------------------------------*/
2641 * This routine fills in the appropriate registers and memory
2642 * locations on the WaveLAN card and starts the card off on
2643 * the transmit.
2645 * The principle:
2646 * Each block contains a transmit command, a NOP command,
2647 * a transmit block descriptor and a buffer.
2648 * The CU read the transmit block which point to the tbd,
2649 * read the tbd and the content of the buffer.
2650 * When it has finish with it, it goes to the next command
2651 * which in our case is the NOP. The NOP points on itself,
2652 * so the CU stop here.
2653 * When we add the next block, we modify the previous nop
2654 * to make it point on the new tx command.
2655 * Simple, isn't it ?
2657 * (called in wavelan_packet_xmit())
2659 static inline void
2660 wv_packet_write(device * dev,
2661 void * buf,
2662 short length)
2664 net_local * lp = (net_local *) dev->priv;
2665 u_long ioaddr = dev->base_addr;
2666 unsigned short txblock;
2667 unsigned short txpred;
2668 unsigned short tx_addr;
2669 unsigned short nop_addr;
2670 unsigned short tbd_addr;
2671 unsigned short buf_addr;
2672 ac_tx_t tx;
2673 ac_nop_t nop;
2674 tbd_t tbd;
2675 int clen = length;
2676 unsigned long x;
2678 #ifdef DEBUG_TX_TRACE
2679 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
2680 #endif
2682 /* Do we need some padding? */
2683 if(clen < ETH_ZLEN)
2684 clen = ETH_ZLEN;
2686 x = wv_splhi();
2688 /* Calculate addresses of next block and previous block. */
2689 txblock = lp->tx_first_free;
2690 txpred = txblock - TXBLOCKZ;
2691 if(txpred < OFFSET_CU)
2692 txpred += NTXBLOCKS * TXBLOCKZ;
2693 lp->tx_first_free += TXBLOCKZ;
2694 if(lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
2695 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
2698 if (lp->tx_n_in_use > 0)
2699 printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
2702 lp->tx_n_in_use++;
2704 /* Calculate addresses of the different parts of the block. */
2705 tx_addr = txblock;
2706 nop_addr = tx_addr + sizeof(tx);
2707 tbd_addr = nop_addr + sizeof(nop);
2708 buf_addr = tbd_addr + sizeof(tbd);
2711 * Transmit command
2713 tx.tx_h.ac_status = 0;
2714 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
2715 (unsigned char *) &tx.tx_h.ac_status,
2716 sizeof(tx.tx_h.ac_status));
2719 * NOP command
2721 nop.nop_h.ac_status = 0;
2722 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2723 (unsigned char *) &nop.nop_h.ac_status,
2724 sizeof(nop.nop_h.ac_status));
2725 nop.nop_h.ac_link = nop_addr;
2726 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2727 (unsigned char *) &nop.nop_h.ac_link,
2728 sizeof(nop.nop_h.ac_link));
2731 * Transmit buffer descriptor
2733 tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen);
2734 tbd.tbd_next_bd_offset = I82586NULL;
2735 tbd.tbd_bufl = buf_addr;
2736 tbd.tbd_bufh = 0;
2737 obram_write(ioaddr, tbd_addr, (unsigned char *)&tbd, sizeof(tbd));
2740 * Data
2742 obram_write(ioaddr, buf_addr, buf, length);
2745 * Overwrite the predecessor NOP link
2746 * so that it points to this txblock.
2748 nop_addr = txpred + sizeof(tx);
2749 nop.nop_h.ac_status = 0;
2750 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2751 (unsigned char *)&nop.nop_h.ac_status,
2752 sizeof(nop.nop_h.ac_status));
2753 nop.nop_h.ac_link = txblock;
2754 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2755 (unsigned char *) &nop.nop_h.ac_link,
2756 sizeof(nop.nop_h.ac_link));
2758 /* Keep stats up to date. */
2759 lp->stats.tx_bytes += length;
2761 /* If watchdog not already active, activate it... */
2762 if(lp->watchdog.prev == (timer_list *) NULL)
2764 /* Set timer to expire in WATCHDOG_JIFFIES. */
2765 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
2766 add_timer(&lp->watchdog);
2769 if(lp->tx_first_in_use == I82586NULL)
2770 lp->tx_first_in_use = txblock;
2772 if(lp->tx_n_in_use < NTXBLOCKS - 1)
2773 dev->tbusy = 0;
2775 wv_splx(x);
2777 #ifdef DEBUG_TX_INFO
2778 wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
2779 #endif /* DEBUG_TX_INFO */
2781 #ifdef DEBUG_TX_TRACE
2782 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
2783 #endif
2786 /*------------------------------------------------------------------*/
2788 * This routine is called when we want to send a packet (NET3 callback)
2789 * In this routine, we check if the harware is ready to accept
2790 * the packet. We also prevent reentrance. Then we call the function
2791 * to send the packet.
2793 static int
2794 wavelan_packet_xmit(struct sk_buff * skb,
2795 device * dev)
2797 net_local * lp = (net_local *)dev->priv;
2799 #ifdef DEBUG_TX_TRACE
2800 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
2801 (unsigned) skb);
2802 #endif
2804 /* This flag indicate that the hardware can't perform a transmission.
2805 * Theoretically, NET3 checks it before sending a packet to the driver,
2806 * but in fact it never does that and pools continuously.
2807 * As the watchdog will abort overly long transmissions, we are quite safe.
2809 if(dev->tbusy)
2810 return 1;
2813 * Block a timer-based transmit from overlapping.
2814 * In other words, prevent reentering this routine.
2816 if(test_and_set_bit(0, (void *)&dev->tbusy) != 0)
2817 #ifdef DEBUG_TX_ERROR
2818 printk(KERN_INFO "%s: Transmitter access conflict.\n", dev->name);
2819 #endif
2820 else
2822 /* If somebody has asked to reconfigure the controller,
2823 * we can do it now.
2825 if(lp->reconfig_82586)
2827 wv_82586_config(dev);
2828 if(dev->tbusy)
2829 return 1;
2832 #ifdef DEBUG_TX_ERROR
2833 if(skb->next)
2834 printk(KERN_INFO "skb has next\n");
2835 #endif
2837 wv_packet_write(dev, skb->data, skb->len);
2840 dev_kfree_skb(skb);
2842 #ifdef DEBUG_TX_TRACE
2843 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
2844 #endif
2845 return 0;
2848 /*********************** HARDWARE CONFIGURATION ***********************/
2850 * This part does the real job of starting and configuring the hardware.
2853 /*--------------------------------------------------------------------*/
2855 * Routine to initialize the Modem Management Controller.
2856 * (called by wv_hw_reset())
2858 static inline int
2859 wv_mmc_init(device * dev)
2861 u_long ioaddr = dev->base_addr;
2862 net_local * lp = (net_local *)dev->priv;
2863 psa_t psa;
2864 mmw_t m;
2865 int configured;
2867 #ifdef DEBUG_CONFIG_TRACE
2868 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
2869 #endif
2871 /* Read the parameter storage area. */
2872 psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
2874 #ifdef USE_PSA_CONFIG
2875 configured = psa.psa_conf_status & 1;
2876 #else
2877 configured = 0;
2878 #endif
2880 /* Is the PSA is not configured */
2881 if(!configured)
2883 /* User will be able to configure NWID later (with iwconfig). */
2884 psa.psa_nwid[0] = 0;
2885 psa.psa_nwid[1] = 0;
2887 /* no NWID checking since NWID is not set */
2888 psa.psa_nwid_select = 0;
2890 /* Disable encryption */
2891 psa.psa_encryption_select = 0;
2893 /* Set to standard values:
2894 * 0x04 for AT,
2895 * 0x01 for MCA,
2896 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
2898 if (psa.psa_comp_number & 1)
2899 psa.psa_thr_pre_set = 0x01;
2900 else
2901 psa.psa_thr_pre_set = 0x04;
2902 psa.psa_quality_thr = 0x03;
2904 /* It is configured */
2905 psa.psa_conf_status |= 1;
2907 #ifdef USE_PSA_CONFIG
2908 /* Write the psa. */
2909 psa_write(ioaddr, lp->hacr, (char *)psa.psa_nwid - (char *)&psa,
2910 (unsigned char *)psa.psa_nwid, 4);
2911 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_thr_pre_set - (char *)&psa,
2912 (unsigned char *)&psa.psa_thr_pre_set, 1);
2913 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_quality_thr - (char *)&psa,
2914 (unsigned char *)&psa.psa_quality_thr, 1);
2915 psa_write(ioaddr, lp->hacr, (char *)&psa.psa_conf_status - (char *)&psa,
2916 (unsigned char *)&psa.psa_conf_status, 1);
2917 /* update the Wavelan checksum */
2918 update_psa_checksum(dev, ioaddr, lp->hacr);
2919 #endif
2922 /* Zero the mmc structure. */
2923 memset(&m, 0x00, sizeof(m));
2925 /* Copy PSA info to the mmc. */
2926 m.mmw_netw_id_l = psa.psa_nwid[1];
2927 m.mmw_netw_id_h = psa.psa_nwid[0];
2929 if(psa.psa_nwid_select & 1)
2930 m.mmw_loopt_sel = 0x00;
2931 else
2932 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
2934 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
2935 sizeof(m.mmw_encr_key));
2937 if(psa.psa_encryption_select)
2938 m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
2939 else
2940 m.mmw_encr_enable = 0;
2942 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
2943 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
2946 * Set default modem control parameters.
2947 * See NCR document 407-0024326 Rev. A.
2949 m.mmw_jabber_enable = 0x01;
2950 m.mmw_freeze = 0;
2951 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
2952 m.mmw_ifs = 0x20;
2953 m.mmw_mod_delay = 0x04;
2954 m.mmw_jam_time = 0x38;
2956 m.mmw_des_io_invert = 0;
2957 m.mmw_decay_prm = 0;
2958 m.mmw_decay_updat_prm = 0;
2960 /* Write all info to MMC. */
2961 mmc_write(ioaddr, 0, (u_char *)&m, sizeof(m));
2963 /* The following code starts the modem of the 2.00 frequency
2964 * selectable cards at power on. It's not strictly needed for the
2965 * following boots.
2966 * The original patch was by Joe Finney for the PCMCIA driver, but
2967 * I've cleaned it up a bit and added documentation.
2968 * Thanks to Loeke Brederveld from Lucent for the info.
2971 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
2972 * Does it work for everybody, especially old cards? */
2973 /* Note: WFREQSEL verifies that it is able to read a sensible
2974 * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
2975 * is 0xA (Xilinx version) or 0xB (Ariadne version).
2976 * My test is more crude but does work. */
2977 if(!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2978 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
2980 /* We must download the frequency parameters to the
2981 * synthesizers (from the EEPROM - area 1)
2982 * Note: as the EEPROM is automatically decremented, we set the end
2983 * if the area... */
2984 m.mmw_fee_addr = 0x0F;
2985 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
2986 mmc_write(ioaddr, (char *)&m.mmw_fee_ctrl - (char *)&m,
2987 (unsigned char *)&m.mmw_fee_ctrl, 2);
2989 /* Wait until the download is finished. */
2990 fee_wait(ioaddr, 100, 100);
2992 #ifdef DEBUG_CONFIG_INFO
2993 /* The frequency was in the last word downloaded. */
2994 mmc_read(ioaddr, (char *)&m.mmw_fee_data_l - (char *)&m,
2995 (unsigned char *)&m.mmw_fee_data_l, 2);
2997 /* Print some info for the user. */
2998 printk(KERN_DEBUG "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n",
2999 dev->name,
3000 ((m.mmw_fee_data_h << 4) |
3001 (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
3002 #endif
3004 /* We must now download the power adjust value (gain) to
3005 * the synthesizers (from the EEPROM - area 7 - DAC). */
3006 m.mmw_fee_addr = 0x61;
3007 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3008 mmc_write(ioaddr, (char *)&m.mmw_fee_ctrl - (char *)&m,
3009 (unsigned char *)&m.mmw_fee_ctrl, 2);
3011 /* Wait until the download is finished. */
3012 } /* if 2.00 card */
3014 #ifdef DEBUG_CONFIG_TRACE
3015 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3016 #endif
3017 return 0;
3020 /*------------------------------------------------------------------*/
3022 * Construct the fd and rbd structures.
3023 * Start the receive unit.
3024 * (called by wv_hw_reset())
3026 static inline int
3027 wv_ru_start(device * dev)
3029 net_local * lp = (net_local *) dev->priv;
3030 u_long ioaddr = dev->base_addr;
3031 u_short scb_cs;
3032 fd_t fd;
3033 rbd_t rbd;
3034 u_short rx;
3035 u_short rx_next;
3036 int i;
3038 #ifdef DEBUG_CONFIG_TRACE
3039 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3040 #endif
3042 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status), (unsigned char *)&scb_cs, sizeof(scb_cs));
3043 if((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
3044 return 0;
3046 lp->rx_head = OFFSET_RU;
3048 for(i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next)
3050 rx_next = (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
3052 fd.fd_status = 0;
3053 fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
3054 fd.fd_link_offset = rx_next;
3055 fd.fd_rbd_offset = rx + sizeof(fd);
3056 obram_write(ioaddr, rx, (unsigned char *)&fd, sizeof(fd));
3058 rbd.rbd_status = 0;
3059 rbd.rbd_next_rbd_offset = I82586NULL;
3060 rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
3061 rbd.rbd_bufh = 0;
3062 rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
3063 obram_write(ioaddr, rx + sizeof(fd),
3064 (unsigned char *) &rbd, sizeof(rbd));
3066 lp->rx_last = rx;
3069 obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
3070 (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
3072 scb_cs = SCB_CMD_RUC_GO;
3073 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3074 (unsigned char *) &scb_cs, sizeof(scb_cs));
3076 set_chan_attn(ioaddr, lp->hacr);
3078 for(i = 1000; i > 0; i--)
3080 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3081 (unsigned char *) &scb_cs, sizeof(scb_cs));
3082 if (scb_cs == 0)
3083 break;
3085 udelay(10);
3088 if(i <= 0)
3090 #ifdef DEBUG_CONFIG_ERROR
3091 printk(KERN_INFO "%s: wavelan_ru_start(): board not accepting command.\n",
3092 dev->name);
3093 #endif
3094 return -1;
3097 #ifdef DEBUG_CONFIG_TRACE
3098 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3099 #endif
3100 return 0;
3103 /*------------------------------------------------------------------*/
3105 * Initialise the transmit blocks.
3106 * Start the command unit executing the NOP
3107 * self-loop of the first transmit block.
3109 * Here we create the list of send buffers used to transmit packets
3110 * between the PC and the command unit. For each buffer, we create a
3111 * buffer descriptor (pointing on the buffer), a transmit command
3112 * (pointing to the buffer descriptor) and a NOP command.
3113 * The transmit command is linked to the NOP, and the NOP to itself.
3114 * When we will have finished executing the transmit command, we will
3115 * then loop on the NOP. By releasing the NOP link to a new command,
3116 * we may send another buffer.
3118 * (called by wv_hw_reset())
3120 static inline int
3121 wv_cu_start(device * dev)
3123 net_local * lp = (net_local *) dev->priv;
3124 u_long ioaddr = dev->base_addr;
3125 int i;
3126 u_short txblock;
3127 u_short first_nop;
3128 u_short scb_cs;
3130 #ifdef DEBUG_CONFIG_TRACE
3131 printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
3132 #endif
3134 lp->tx_first_free = OFFSET_CU;
3135 lp->tx_first_in_use = I82586NULL;
3137 for(i = 0, txblock = OFFSET_CU;
3138 i < NTXBLOCKS;
3139 i++, txblock += TXBLOCKZ)
3141 ac_tx_t tx;
3142 ac_nop_t nop;
3143 tbd_t tbd;
3144 unsigned short tx_addr;
3145 unsigned short nop_addr;
3146 unsigned short tbd_addr;
3147 unsigned short buf_addr;
3149 tx_addr = txblock;
3150 nop_addr = tx_addr + sizeof(tx);
3151 tbd_addr = nop_addr + sizeof(nop);
3152 buf_addr = tbd_addr + sizeof(tbd);
3154 tx.tx_h.ac_status = 0;
3155 tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
3156 tx.tx_h.ac_link = nop_addr;
3157 tx.tx_tbd_offset = tbd_addr;
3158 obram_write(ioaddr, tx_addr, (unsigned char *) &tx, sizeof(tx));
3160 nop.nop_h.ac_status = 0;
3161 nop.nop_h.ac_command = acmd_nop;
3162 nop.nop_h.ac_link = nop_addr;
3163 obram_write(ioaddr, nop_addr, (unsigned char *) &nop, sizeof(nop));
3165 tbd.tbd_status = TBD_STATUS_EOF;
3166 tbd.tbd_next_bd_offset = I82586NULL;
3167 tbd.tbd_bufl = buf_addr;
3168 tbd.tbd_bufh = 0;
3169 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd));
3172 first_nop = OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
3173 obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
3174 (unsigned char *) &first_nop, sizeof(first_nop));
3176 scb_cs = SCB_CMD_CUC_GO;
3177 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3178 (unsigned char *) &scb_cs, sizeof(scb_cs));
3180 set_chan_attn(ioaddr, lp->hacr);
3182 for(i = 1000; i > 0; i--)
3184 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3185 (unsigned char *) &scb_cs, sizeof(scb_cs));
3186 if (scb_cs == 0)
3187 break;
3189 udelay(10);
3192 if(i <= 0)
3194 #ifdef DEBUG_CONFIG_ERROR
3195 printk(KERN_INFO "%s: wavelan_cu_start(): board not accepting command.\n",
3196 dev->name);
3197 #endif
3198 return -1;
3201 lp->tx_n_in_use = 0;
3202 dev->tbusy = 0;
3204 #ifdef DEBUG_CONFIG_TRACE
3205 printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
3206 #endif
3207 return 0;
3210 /*------------------------------------------------------------------*/
3212 * This routine does a standard configuration of the WaveLAN
3213 * controller (i82586).
3215 * It initialises the scp, iscp and scb structure
3216 * The first two are just pointers to the next.
3217 * The last one is used for basic configuration and for basic
3218 * communication (interrupt status).
3220 * (called by wv_hw_reset())
3222 static inline int
3223 wv_82586_start(device * dev)
3225 net_local * lp = (net_local *) dev->priv;
3226 u_long ioaddr = dev->base_addr;
3227 scp_t scp; /* system configuration pointer */
3228 iscp_t iscp; /* intermediate scp */
3229 scb_t scb; /* system control block */
3230 ach_t cb; /* Action command header */
3231 u_char zeroes[512];
3232 int i;
3234 #ifdef DEBUG_CONFIG_TRACE
3235 printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
3236 #endif
3239 * Clear the onboard RAM.
3241 memset(&zeroes[0], 0x00, sizeof(zeroes));
3242 for(i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
3243 obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
3246 * Construct the command unit structures:
3247 * scp, iscp, scb, cb.
3249 memset(&scp, 0x00, sizeof(scp));
3250 scp.scp_sysbus = SCP_SY_16BBUS;
3251 scp.scp_iscpl = OFFSET_ISCP;
3252 obram_write(ioaddr, OFFSET_SCP, (unsigned char *)&scp, sizeof(scp));
3254 memset(&iscp, 0x00, sizeof(iscp));
3255 iscp.iscp_busy = 1;
3256 iscp.iscp_offset = OFFSET_SCB;
3257 obram_write(ioaddr, OFFSET_ISCP, (unsigned char *)&iscp, sizeof(iscp));
3259 /* Our first command is to reset the i82586. */
3260 memset(&scb, 0x00, sizeof(scb));
3261 scb.scb_command = SCB_CMD_RESET;
3262 scb.scb_cbl_offset = OFFSET_CU;
3263 scb.scb_rfa_offset = OFFSET_RU;
3264 obram_write(ioaddr, OFFSET_SCB, (unsigned char *)&scb, sizeof(scb));
3266 set_chan_attn(ioaddr, lp->hacr);
3268 /* Wait for command to finish. */
3269 for(i = 1000; i > 0; i--)
3271 obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp, sizeof(iscp));
3273 if(iscp.iscp_busy == (unsigned short) 0)
3274 break;
3276 udelay(10);
3279 if(i <= 0)
3281 #ifdef DEBUG_CONFIG_ERROR
3282 printk(KERN_INFO "%s: wv_82586_start(): iscp_busy timeout.\n",
3283 dev->name);
3284 #endif
3285 return -1;
3288 /* Check command completion. */
3289 for(i = 15; i > 0; i--)
3291 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb, sizeof(scb));
3293 if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
3294 break;
3296 udelay(10);
3299 if (i <= 0)
3301 #ifdef DEBUG_CONFIG_ERROR
3302 printk(KERN_INFO "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
3303 dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
3304 #endif
3305 return -1;
3308 wv_ack(dev);
3310 /* Set the action command header. */
3311 memset(&cb, 0x00, sizeof(cb));
3312 cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
3313 cb.ac_link = OFFSET_CU;
3314 obram_write(ioaddr, OFFSET_CU, (unsigned char *)&cb, sizeof(cb));
3316 if(wv_synchronous_cmd(dev, "diag()") == -1)
3317 return -1;
3319 obram_read(ioaddr, OFFSET_CU, (unsigned char *)&cb, sizeof(cb));
3320 if(cb.ac_status & AC_SFLD_FAIL)
3322 #ifdef DEBUG_CONFIG_ERROR
3323 printk(KERN_INFO "%s: wv_82586_start(): i82586 Self Test failed.\n",
3324 dev->name);
3325 #endif
3326 return -1;
3329 #ifdef DEBUG_I82586_SHOW
3330 wv_scb_show(ioaddr);
3331 #endif
3333 #ifdef DEBUG_CONFIG_TRACE
3334 printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
3335 #endif
3336 return 0;
3339 /*------------------------------------------------------------------*/
3341 * This routine does a standard configuration of the WaveLAN
3342 * controller (i82586).
3344 * This routine is a violent hack. We use the first free transmit block
3345 * to make our configuration. In the buffer area, we create the three
3346 * configuration commands (linked). We make the previous NOP point to
3347 * the beginning of the buffer instead of the tx command. After, we go
3348 * as usual to the NOP command.
3349 * Note that only the last command (mc_set) will generate an interrupt.
3351 * (called by wv_hw_reset(), wv_82586_reconfig())
3353 static void
3354 wv_82586_config(device * dev)
3356 net_local * lp = (net_local *) dev->priv;
3357 u_long ioaddr = dev->base_addr;
3358 unsigned short txblock;
3359 unsigned short txpred;
3360 unsigned short tx_addr;
3361 unsigned short nop_addr;
3362 unsigned short tbd_addr;
3363 unsigned short cfg_addr;
3364 unsigned short ias_addr;
3365 unsigned short mcs_addr;
3366 ac_tx_t tx;
3367 ac_nop_t nop;
3368 ac_cfg_t cfg; /* Configure action */
3369 ac_ias_t ias; /* IA-setup action */
3370 ac_mcs_t mcs; /* Multicast setup */
3371 struct dev_mc_list * dmi;
3372 unsigned long x;
3374 #ifdef DEBUG_CONFIG_TRACE
3375 printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
3376 #endif
3378 x = wv_splhi();
3380 /* Calculate addresses of next block and previous block. */
3381 txblock = lp->tx_first_free;
3382 txpred = txblock - TXBLOCKZ;
3383 if(txpred < OFFSET_CU)
3384 txpred += NTXBLOCKS * TXBLOCKZ;
3385 lp->tx_first_free += TXBLOCKZ;
3386 if(lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
3387 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
3389 lp->tx_n_in_use++;
3391 /* Calculate addresses of the different parts of the block. */
3392 tx_addr = txblock;
3393 nop_addr = tx_addr + sizeof(tx);
3394 tbd_addr = nop_addr + sizeof(nop);
3395 cfg_addr = tbd_addr + sizeof(tbd_t); /* beginning of the buffer */
3396 ias_addr = cfg_addr + sizeof(cfg);
3397 mcs_addr = ias_addr + sizeof(ias);
3400 * Transmit command
3402 tx.tx_h.ac_status = 0xFFFF; /* Fake completion value */
3403 obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
3404 (unsigned char *) &tx.tx_h.ac_status,
3405 sizeof(tx.tx_h.ac_status));
3408 * NOP command
3410 nop.nop_h.ac_status = 0;
3411 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3412 (unsigned char *) &nop.nop_h.ac_status,
3413 sizeof(nop.nop_h.ac_status));
3414 nop.nop_h.ac_link = nop_addr;
3415 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3416 (unsigned char *) &nop.nop_h.ac_link,
3417 sizeof(nop.nop_h.ac_link));
3419 /* Create a configure action. */
3420 memset(&cfg, 0x00, sizeof(cfg));
3423 * For Linux we invert AC_CFG_ALOC() so as to conform
3424 * to the way that net packets reach us from above.
3425 * (See also ac_tx_t.)
3427 * Updated from Wavelan Manual WCIN085B
3429 cfg.cfg_byte_cnt = AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
3430 cfg.cfg_fifolim = AC_CFG_FIFOLIM(4);
3431 cfg.cfg_byte8 = AC_CFG_SAV_BF(1) |
3432 AC_CFG_SRDY(0);
3433 cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
3434 AC_CFG_ILPBCK(0) |
3435 AC_CFG_PRELEN(AC_CFG_PLEN_2) |
3436 AC_CFG_ALOC(1) |
3437 AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
3438 cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
3439 AC_CFG_ACR(6) |
3440 AC_CFG_LINPRIO(0);
3441 cfg.cfg_ifs = 0x20;
3442 cfg.cfg_slotl = 0x0C;
3443 cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) |
3444 AC_CFG_SLTTMHI(0);
3445 cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
3446 AC_CFG_BTSTF(0) |
3447 AC_CFG_CRC16(0) |
3448 AC_CFG_NCRC(0) |
3449 AC_CFG_TNCRS(1) |
3450 AC_CFG_MANCH(0) |
3451 AC_CFG_BCDIS(0) |
3452 AC_CFG_PRM(lp->promiscuous);
3453 cfg.cfg_byte15 = AC_CFG_ICDS(0) |
3454 AC_CFG_CDTF(0) |
3455 AC_CFG_ICSS(0) |
3456 AC_CFG_CSTF(0);
3458 cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
3460 cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
3462 cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
3463 cfg.cfg_h.ac_link = ias_addr;
3464 obram_write(ioaddr, cfg_addr, (unsigned char *)&cfg, sizeof(cfg));
3466 /* Set up the MAC address */
3467 memset(&ias, 0x00, sizeof(ias));
3468 ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
3469 ias.ias_h.ac_link = mcs_addr;
3470 memcpy(&ias.ias_addr[0], (unsigned char *)&dev->dev_addr[0], sizeof(ias.ias_addr));
3471 obram_write(ioaddr, ias_addr, (unsigned char *)&ias, sizeof(ias));
3473 /* Initialize adapter's Ethernet multicast addresses */
3474 memset(&mcs, 0x00, sizeof(mcs));
3475 mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
3476 mcs.mcs_h.ac_link = nop_addr;
3477 mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
3478 obram_write(ioaddr, mcs_addr, (unsigned char *)&mcs, sizeof(mcs));
3480 /* Any address to set? */
3481 if(lp->mc_count)
3483 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3484 outsw(PIOP1(ioaddr), (u_short *) dmi->dmi_addr,
3485 WAVELAN_ADDR_SIZE >> 1);
3487 #ifdef DEBUG_CONFIG_INFO
3488 printk(KERN_DEBUG "%s: wv_82586_config(): set %d multicast addresses:\n",
3489 dev->name, lp->mc_count);
3490 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3491 printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n",
3492 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
3493 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
3494 #endif
3498 * Overwrite the predecessor NOP link
3499 * so that it points to the configure action.
3501 nop_addr = txpred + sizeof(tx);
3502 nop.nop_h.ac_status = 0;
3503 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3504 (unsigned char *)&nop.nop_h.ac_status,
3505 sizeof(nop.nop_h.ac_status));
3506 nop.nop_h.ac_link = cfg_addr;
3507 obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3508 (unsigned char *) &nop.nop_h.ac_link,
3509 sizeof(nop.nop_h.ac_link));
3511 /* If watchdog not already active, activate it... */
3512 if(lp->watchdog.prev == (timer_list *) NULL)
3514 /* set timer to expire in WATCHDOG_JIFFIES */
3515 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
3516 add_timer(&lp->watchdog);
3519 lp->reconfig_82586 = 0;
3521 if(lp->tx_first_in_use == I82586NULL)
3522 lp->tx_first_in_use = txblock;
3524 if(lp->tx_n_in_use < NTXBLOCKS - 1)
3525 dev->tbusy = 0;
3527 wv_splx(x);
3529 #ifdef DEBUG_CONFIG_TRACE
3530 printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
3531 #endif
3534 /*------------------------------------------------------------------*/
3536 * This routine, called by wavelan_close(), gracefully stops the
3537 * WaveLAN controller (i82586).
3539 static inline void
3540 wv_82586_stop(device * dev)
3542 net_local * lp = (net_local *) dev->priv;
3543 u_long ioaddr = dev->base_addr;
3544 u_short scb_cmd;
3546 #ifdef DEBUG_CONFIG_TRACE
3547 printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
3548 #endif
3550 /* Suspend both command unit and receive unit. */
3551 scb_cmd = (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC & SCB_CMD_RUC_SUS);
3552 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3553 (unsigned char *)&scb_cmd, sizeof(scb_cmd));
3554 set_chan_attn(ioaddr, lp->hacr);
3556 /* No more interrupts */
3557 wv_ints_off(dev);
3559 #ifdef DEBUG_CONFIG_TRACE
3560 printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
3561 #endif
3564 /*------------------------------------------------------------------*/
3566 * Totally reset the WaveLAN and restart it.
3567 * Performs the following actions:
3568 * 1. A power reset (reset DMA)
3569 * 2. Initialize the radio modem (using wv_mmc_init)
3570 * 3. Reset & Configure LAN controller (using wv_82586_start)
3571 * 4. Start the LAN controller's command unit
3572 * 5. Start the LAN controller's receive unit
3574 static int
3575 wv_hw_reset(device * dev)
3577 net_local * lp = (net_local *)dev->priv;
3578 u_long ioaddr = dev->base_addr;
3580 #ifdef DEBUG_CONFIG_TRACE
3581 printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
3582 (unsigned int)dev);
3583 #endif
3585 /* If watchdog was activated, kill it! */
3586 if(lp->watchdog.prev != (timer_list *) NULL)
3587 del_timer(&lp->watchdog);
3589 /* Increase the number of resets done. */
3590 lp->nresets++;
3592 wv_hacr_reset(ioaddr);
3593 lp->hacr = HACR_DEFAULT;
3595 if((wv_mmc_init(dev) < 0) ||
3596 (wv_82586_start(dev) < 0))
3597 return -1;
3599 /* Enable the card to send interrupts. */
3600 wv_ints_on(dev);
3602 /* Start card functions */
3603 if(wv_cu_start(dev) < 0)
3604 return -1;
3606 /* Setup the controller and parameters */
3607 wv_82586_config(dev);
3609 /* Finish configuration with the receive unit */
3610 if(wv_ru_start(dev) < 0)
3611 return -1;
3613 #ifdef DEBUG_CONFIG_TRACE
3614 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3615 #endif
3616 return 0;
3619 /*------------------------------------------------------------------*/
3621 * Check if there is a WaveLAN at the specific base address.
3622 * As a side effect, this reads the MAC address.
3623 * (called in wavelan_probe() and init_module())
3625 static int
3626 wv_check_ioaddr(u_long ioaddr,
3627 u_char * mac)
3629 int i; /* Loop counter */
3631 /* Check if the base address if available. */
3632 if(check_region(ioaddr, sizeof(ha_t)))
3633 return EADDRINUSE; /* ioaddr already used */
3635 /* Reset host interface */
3636 wv_hacr_reset(ioaddr);
3638 /* Read the MAC address from the parameter storage area. */
3639 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
3640 mac, 6);
3643 * Check the first three octets of the address for the manufacturer's code.
3644 * Note: if this can't find your WaveLAN card, you've got a
3645 * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on
3646 * how to configure your card.
3648 for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3649 if((mac[0] == MAC_ADDRESSES[i][0]) &&
3650 (mac[1] == MAC_ADDRESSES[i][1]) &&
3651 (mac[2] == MAC_ADDRESSES[i][2]))
3652 return 0;
3654 #ifdef DEBUG_CONFIG_INFO
3655 printk(KERN_WARNING "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
3656 ioaddr, mac[0], mac[1], mac[2]);
3657 #endif
3658 return ENODEV;
3661 /************************ INTERRUPT HANDLING ************************/
3664 * This function is the interrupt handler for the WaveLAN card. This
3665 * routine will be called whenever:
3667 static void
3668 wavelan_interrupt(int irq,
3669 void * dev_id,
3670 struct pt_regs * regs)
3672 device * dev;
3673 u_long ioaddr;
3674 net_local * lp;
3675 u_short hasr;
3676 u_short status;
3677 u_short ack_cmd;
3679 dev = dev_id;
3681 #ifdef DEBUG_INTERRUPT_TRACE
3682 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
3683 #endif
3685 lp = (net_local *) dev->priv;
3686 ioaddr = dev->base_addr;
3688 /* Prevent reentrance. What should we do here? */
3689 #ifdef DEBUG_INTERRUPT_ERROR
3690 if(dev->interrupt)
3691 printk(KERN_INFO "%s: wavelan_interrupt(): Re-entering the interrupt handler.\n",
3692 dev->name);
3693 #endif
3694 dev->interrupt = 1;
3696 if((hasr = hasr_read(ioaddr)) & HASR_MMC_INTR)
3698 u_char dce_status;
3701 * Interrupt from the modem management controller.
3702 * This will clear it -- ignored for now.
3704 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status, sizeof(dce_status));
3705 #ifdef DEBUG_INTERRUPT_ERROR
3706 printk(KERN_INFO "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
3707 dev->name, dce_status);
3708 #endif
3711 if((hasr & HASR_82586_INTR) == 0)
3713 dev->interrupt = 0;
3714 #ifdef DEBUG_INTERRUPT_ERROR
3715 printk(KERN_INFO "%s: wavelan_interrupt(): interrupt not coming from i82586\n",
3716 dev->name);
3717 #endif
3718 return;
3721 /* Read interrupt data. */
3722 obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3723 (unsigned char *) &status, sizeof(status));
3726 * Acknowledge the interrupt(s).
3728 ack_cmd = status & SCB_ST_INT;
3729 obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3730 (unsigned char *) &ack_cmd, sizeof(ack_cmd));
3731 set_chan_attn(ioaddr, lp->hacr);
3733 #ifdef DEBUG_INTERRUPT_INFO
3734 printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
3735 dev->name, status);
3736 #endif
3738 /* Command completed. */
3739 if((status & SCB_ST_CX) == SCB_ST_CX)
3741 #ifdef DEBUG_INTERRUPT_INFO
3742 printk(KERN_DEBUG "%s: wavelan_interrupt(): command completed.\n",
3743 dev->name);
3744 #endif
3745 wv_complete(dev, ioaddr, lp);
3747 /* If watchdog was activated, kill it ! */
3748 if(lp->watchdog.prev != (timer_list *) NULL)
3749 del_timer(&lp->watchdog);
3750 if(lp->tx_n_in_use > 0)
3752 /* set timer to expire in WATCHDOG_JIFFIES */
3753 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
3754 add_timer(&lp->watchdog);
3758 /* Frame received. */
3759 if((status & SCB_ST_FR) == SCB_ST_FR)
3761 #ifdef DEBUG_INTERRUPT_INFO
3762 printk(KERN_DEBUG "%s: wavelan_interrupt(): received packet.\n",
3763 dev->name);
3764 #endif
3765 wv_receive(dev);
3768 /* Check the state of the command unit. */
3769 if(((status & SCB_ST_CNA) == SCB_ST_CNA) ||
3770 (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) && dev->start))
3772 #ifdef DEBUG_INTERRUPT_ERROR
3773 printk(KERN_INFO "%s: wavelan_interrupt(): CU inactive -- restarting\n",
3774 dev->name);
3775 #endif
3776 wv_hw_reset(dev);
3779 /* Check the state of the command unit. */
3780 if(((status & SCB_ST_RNR) == SCB_ST_RNR) ||
3781 (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) && dev->start))
3783 #ifdef DEBUG_INTERRUPT_ERROR
3784 printk(KERN_INFO "%s: wavelan_interrupt(): RU not ready -- restarting\n",
3785 dev->name);
3786 #endif
3787 wv_hw_reset(dev);
3790 dev->interrupt = 0;
3792 #ifdef DEBUG_INTERRUPT_TRACE
3793 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
3794 #endif
3797 /*------------------------------------------------------------------*/
3799 * Watchdog: when we start a transmission, we set a timer in the
3800 * kernel. If the transmission completes, this timer is disabled. If
3801 * the timer expires, we try to unlock the hardware.
3803 * Note: this watchdog doesn't work on the same principle as the
3804 * watchdog in the previous version of the ISA driver. I made it this
3805 * way because the overhead of add_timer() and del_timer() is nothing
3806 * and because it avoids calling the watchdog, saving some CPU.
3808 static void
3809 wavelan_watchdog(u_long a)
3811 device * dev;
3812 net_local * lp;
3813 u_long ioaddr;
3814 unsigned long x;
3815 unsigned int nreaped;
3817 dev = (device *) a;
3818 ioaddr = dev->base_addr;
3819 lp = (net_local *) dev->priv;
3821 #ifdef DEBUG_INTERRUPT_TRACE
3822 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
3823 #endif
3825 #ifdef DEBUG_INTERRUPT_ERROR
3826 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
3827 dev->name);
3828 #endif
3830 x = wv_splhi();
3832 dev = (device *) a;
3833 ioaddr = dev->base_addr;
3834 lp = (net_local *) dev->priv;
3836 if(lp->tx_n_in_use <= 0)
3838 wv_splx(x);
3839 return;
3842 nreaped = wv_complete(dev, ioaddr, lp);
3844 #ifdef DEBUG_INTERRUPT_INFO
3845 printk(KERN_DEBUG "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
3846 dev->name, nreaped, lp->tx_n_in_use);
3847 #endif
3849 #ifdef DEBUG_PSA_SHOW
3851 psa_t psa;
3852 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3853 wv_psa_show(&psa);
3855 #endif
3856 #ifdef DEBUG_MMC_SHOW
3857 wv_mmc_show(dev);
3858 #endif
3859 #ifdef DEBUG_I82586_SHOW
3860 wv_cu_show(dev);
3861 #endif
3863 /* If no buffer has been freed */
3864 if(nreaped == 0)
3866 #ifdef DEBUG_INTERRUPT_ERROR
3867 printk(KERN_INFO "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
3868 dev->name);
3869 #endif
3870 wv_hw_reset(dev);
3872 else
3873 /* Reset watchdog for next transmission. */
3874 if(lp->tx_n_in_use > 0)
3876 /* set timer to expire in WATCHDOG_JIFFIES */
3877 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
3878 add_timer(&lp->watchdog);
3881 wv_splx(x);
3883 #ifdef DEBUG_INTERRUPT_TRACE
3884 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
3885 #endif
3888 /********************* CONFIGURATION CALLBACKS *********************/
3890 * Here are the functions called by the Linux networking code (NET3)
3891 * for initialization, configuration and deinstallations of the
3892 * WaveLAN ISA hardware.
3895 /*------------------------------------------------------------------*/
3897 * Configure and start up the WaveLAN PCMCIA adaptor.
3898 * Called by NET3 when it "opens" the device.
3900 static int
3901 wavelan_open(device * dev)
3903 u_long x;
3905 #ifdef DEBUG_CALLBACK_TRACE
3906 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
3907 (unsigned int) dev);
3908 #endif
3910 /* Check irq */
3911 if(dev->irq == 0)
3913 #ifdef DEBUG_CONFIG_ERROR
3914 printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n", dev->name);
3915 #endif
3916 return -ENXIO;
3919 if(request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0)
3921 #ifdef DEBUG_CONFIG_ERROR
3922 printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n", dev->name);
3923 #endif
3924 return -EAGAIN;
3927 x = wv_splhi();
3928 if(wv_hw_reset(dev) != -1)
3930 dev->interrupt = 0;
3931 dev->start = 1;
3933 else
3935 free_irq(dev->irq, dev);
3936 #ifdef DEBUG_CONFIG_ERROR
3937 printk(KERN_INFO "%s: wavelan_open(): impossible to start the card\n",
3938 dev->name);
3939 #endif
3940 return -EAGAIN;
3942 wv_splx(x);
3944 MOD_INC_USE_COUNT;
3946 #ifdef DEBUG_CALLBACK_TRACE
3947 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
3948 #endif
3949 return 0;
3952 /*------------------------------------------------------------------*/
3954 * Shut down the WaveLAN ISA card.
3955 * Called by NET3 when it "closes" the device.
3957 static int
3958 wavelan_close(device * dev)
3960 net_local * lp = (net_local *)dev->priv;
3962 #ifdef DEBUG_CALLBACK_TRACE
3963 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
3964 (unsigned int) dev);
3965 #endif
3967 /* Don't do the job twice. */
3968 if(dev->start == 0)
3969 return 0;
3971 dev->tbusy = 1;
3972 dev->start = 0;
3974 /* If watchdog was activated, kill it! */
3975 if(lp->watchdog.prev != (timer_list *) NULL)
3976 del_timer(&lp->watchdog);
3979 * Flush the Tx and disable Rx.
3981 wv_82586_stop(dev);
3983 free_irq(dev->irq, dev);
3985 MOD_DEC_USE_COUNT;
3987 #ifdef DEBUG_CALLBACK_TRACE
3988 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
3989 #endif
3990 return 0;
3993 /*------------------------------------------------------------------*/
3995 * Probe an I/O address, and if the WaveLAN is there configure the
3996 * device structure
3997 * (called by wavelan_probe() and via init_module()).
3999 static int __init
4000 wavelan_config(device * dev)
4002 u_long ioaddr = dev->base_addr;
4003 u_char irq_mask;
4004 int irq;
4005 net_local * lp;
4007 #ifdef DEBUG_CALLBACK_TRACE
4008 printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%x)\n", dev->name,
4009 (unsigned int)dev, ioaddr);
4010 #endif
4012 /* Check IRQ argument on command line. */
4013 if(dev->irq != 0)
4015 irq_mask = wv_irq_to_psa(dev->irq);
4017 if(irq_mask == 0)
4019 #ifdef DEBUG_CONFIG_ERROR
4020 printk(KERN_WARNING "%s: wavelan_config(): invalid IRQ %d ignored.\n",
4021 dev->name, dev->irq);
4022 #endif
4023 dev->irq = 0;
4025 else
4027 #ifdef DEBUG_CONFIG_INFO
4028 printk(KERN_DEBUG "%s: wavelan_config(): changing IRQ to %d\n",
4029 dev->name, dev->irq);
4030 #endif
4031 psa_write(ioaddr, HACR_DEFAULT,
4032 psaoff(0, psa_int_req_no), &irq_mask, 1);
4033 /* update the Wavelan checksum */
4034 update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
4035 wv_hacr_reset(ioaddr);
4039 psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no), &irq_mask, 1);
4040 if((irq = wv_psa_to_irq(irq_mask)) == -1)
4042 #ifdef DEBUG_CONFIG_ERROR
4043 printk(KERN_INFO "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
4044 dev->name, irq_mask);
4045 #endif
4046 return EAGAIN;
4049 dev->irq = irq;
4051 request_region(ioaddr, sizeof(ha_t), "wavelan");
4053 dev->mem_start = 0x0000;
4054 dev->mem_end = 0x0000;
4055 dev->if_port = 0;
4057 /* Initialize device structures */
4058 dev->priv = kmalloc(sizeof(net_local), GFP_KERNEL);
4059 if(dev->priv == NULL)
4060 return -ENOMEM;
4061 memset(dev->priv, 0x00, sizeof(net_local));
4062 lp = (net_local *)dev->priv;
4064 /* Back link to the device structure. */
4065 lp->dev = dev;
4066 /* Add the device at the beginning of the linked list. */
4067 lp->next = wavelan_list;
4068 wavelan_list = lp;
4070 lp->hacr = HACR_DEFAULT;
4072 lp->watchdog.function = wavelan_watchdog;
4073 lp->watchdog.data = (unsigned long) dev;
4074 lp->promiscuous = 0;
4075 lp->mc_count = 0;
4078 * Fill in the fields of the device structure
4079 * with generic Ethernet values.
4081 ether_setup(dev);
4083 dev->open = wavelan_open;
4084 dev->stop = wavelan_close;
4085 dev->hard_start_xmit = wavelan_packet_xmit;
4086 dev->get_stats = wavelan_get_stats;
4087 dev->set_multicast_list = &wavelan_set_multicast_list;
4088 #ifdef SET_MAC_ADDRESS
4089 dev->set_mac_address = &wavelan_set_mac_address;
4090 #endif /* SET_MAC_ADDRESS */
4092 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
4093 dev->do_ioctl = wavelan_ioctl;
4094 dev->get_wireless_stats = wavelan_get_wireless_stats;
4095 #endif
4097 dev->mtu = WAVELAN_MTU;
4099 /* Display nice information. */
4100 wv_init_info(dev);
4102 #ifdef DEBUG_CALLBACK_TRACE
4103 printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
4104 #endif
4105 return 0;
4108 /*------------------------------------------------------------------*/
4110 * Check for a network adaptor of this type. Return '0' iff one
4111 * exists. There seem to be different interpretations of
4112 * the initial value of dev->base_addr.
4113 * We follow the example in drivers/net/ne.c.
4114 * (called in "Space.c")
4116 int __init
4117 wavelan_probe(device * dev)
4119 short base_addr;
4120 mac_addr mac; /* MAC address (check existence of WaveLAN) */
4121 int i;
4122 int r;
4124 #ifdef DEBUG_CALLBACK_TRACE
4125 printk(KERN_DEBUG "%s: ->wavelan_probe(dev=0x%x (base_addr=0x%x))\n",
4126 dev->name, (unsigned int)dev, (unsigned int)dev->base_addr);
4127 #endif
4129 #ifdef STRUCT_CHECK
4130 if (wv_struct_check() != (char *) NULL)
4132 printk(KERN_WARNING "%s: wavelan_probe(): structure/compiler botch: \"%s\"\n",
4133 dev->name, wv_struct_check());
4134 return ENODEV;
4136 #endif /* STRUCT_CHECK */
4138 /* Check the value of the command line parameter for base address. */
4139 base_addr = dev->base_addr;
4141 /* Don't probe at all. */
4142 if(base_addr < 0)
4144 #ifdef DEBUG_CONFIG_ERROR
4145 printk(KERN_WARNING "%s: wavelan_probe(): invalid base address\n",
4146 dev->name);
4147 #endif
4148 return ENXIO;
4151 /* Check a single specified location. */
4152 if(base_addr > 0x100)
4154 /* Check if there is something at this base address */
4155 if((r = wv_check_ioaddr(base_addr, mac)) == 0)
4157 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4158 r = wavelan_config(dev);
4161 #ifdef DEBUG_CONFIG_INFO
4162 if(r != 0)
4163 printk(KERN_DEBUG "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
4164 dev->name, base_addr);
4165 #endif
4167 #ifdef DEBUG_CALLBACK_TRACE
4168 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4169 #endif
4170 return r;
4173 /* Scan all possible addresses of the WaveLAN hardware. */
4174 for(i = 0; i < NELS(iobase); i++)
4176 /* Check whether there is something at this base address. */
4177 if(wv_check_ioaddr(iobase[i], mac) == 0)
4179 dev->base_addr = iobase[i]; /* Copy base address. */
4180 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4181 if(wavelan_config(dev) == 0)
4183 #ifdef DEBUG_CALLBACK_TRACE
4184 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4185 #endif
4186 return 0;
4191 /* We may have touched base_addr. Another driver may not like it. */
4192 dev->base_addr = base_addr;
4194 #ifdef DEBUG_CONFIG_INFO
4195 printk(KERN_DEBUG "%s: wavelan_probe(): no device found\n",
4196 dev->name);
4197 #endif
4199 return ENODEV;
4202 /****************************** MODULE ******************************/
4204 * Module entry point: insertion and removal
4207 #ifdef MODULE
4208 /*------------------------------------------------------------------*/
4210 * Insertion of the module
4211 * I'm now quite proud of the multi-device support.
4214 init_module(void)
4216 mac_addr mac; /* MAC address (check WaveLAN existence) */
4217 int ret = -EIO; /* Return error if no cards found */
4218 int i;
4220 #ifdef DEBUG_MODULE_TRACE
4221 printk(KERN_DEBUG "-> init_module()\n");
4222 #endif
4224 /* If probing is asked */
4225 if(io[0] == 0)
4227 #ifdef DEBUG_CONFIG_ERROR
4228 printk(KERN_WARNING "WaveLAN init_module(): doing device probing (bad !)\n");
4229 printk(KERN_WARNING "Specify base addresses while loading module to correct the problem\n");
4230 #endif
4232 /* Copy the basic set of address to be probed. */
4233 for(i = 0; i < NELS(iobase); i++)
4234 io[i] = iobase[i];
4238 /* Loop on all possible base addresses. */
4239 i = -1;
4240 while((io[++i] != 0) && (i < NELS(io)))
4242 /* Check if there is something at this base address. */
4243 if(wv_check_ioaddr(io[i], mac) == 0)
4245 device * dev;
4247 /* Create device and set basic arguments. */
4248 dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
4249 if(dev==NULL)
4251 ret = -ENOMEM;
4252 break;
4254 memset(dev, 0x00, sizeof(struct net_device));
4255 dev->name = name[i];
4256 dev->base_addr = io[i];
4257 dev->irq = irq[i];
4258 dev->init = &wavelan_config;
4259 memcpy(dev->dev_addr, mac, 6); /* Copy MAC address. */
4261 /* Try to create the device. */
4262 if(register_netdev(dev) != 0)
4264 /* Deallocate everything. */
4265 /* Note: if dev->priv is mallocated, there is no way to fail. */
4266 kfree_s(dev, sizeof(struct net_device));
4268 else
4270 /* If at least one device OK, we do not fail */
4271 ret = 0;
4273 } /* if there is something at the address */
4274 } /* Loop on all addresses. */
4276 #ifdef DEBUG_CONFIG_ERROR
4277 if(wavelan_list == (net_local *) NULL)
4278 printk(KERN_WARNING "WaveLAN init_module(): no device found\n");
4279 #endif
4281 #ifdef DEBUG_MODULE_TRACE
4282 printk(KERN_DEBUG "<- init_module()\n");
4283 #endif
4284 return ret;
4287 /*------------------------------------------------------------------*/
4289 * Removal of the module
4291 void
4292 cleanup_module(void)
4294 #ifdef DEBUG_MODULE_TRACE
4295 printk(KERN_DEBUG "-> cleanup_module()\n");
4296 #endif
4298 /* Loop on all devices and release them. */
4299 while(wavelan_list != (net_local *) NULL)
4301 device * dev = wavelan_list->dev;
4303 #ifdef DEBUG_CONFIG_INFO
4304 printk(KERN_DEBUG "%s: cleanup_module(): removing device at 0x%x\n",
4305 dev->name, (unsigned int) dev);
4306 #endif
4308 /* Release the ioport region. */
4309 release_region(dev->base_addr, sizeof(ha_t));
4311 /* Definitely remove the device. */
4312 unregister_netdev(dev);
4314 /* Unlink the device. */
4315 wavelan_list = wavelan_list->next;
4317 /* Free pieces. */
4318 kfree_s(dev->priv, sizeof(struct net_local));
4319 kfree_s(dev, sizeof(struct net_device));
4322 #ifdef DEBUG_MODULE_TRACE
4323 printk(KERN_DEBUG "<- cleanup_module()\n");
4324 #endif
4326 #endif /* MODULE */
4329 * This software may only be used and distributed
4330 * according to the terms of the GNU Public License.
4332 * This software was developed as a component of the
4333 * Linux operating system.
4334 * It is based on other device drivers and information
4335 * either written or supplied by:
4336 * Ajay Bakre (bakre@paul.rutgers.edu),
4337 * Donald Becker (becker@cesdis.gsfc.nasa.gov),
4338 * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
4339 * Anders Klemets (klemets@it.kth.se),
4340 * Vladimir V. Kolpakov (w@stier.koenig.ru),
4341 * Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
4342 * Pauline Middelink (middelin@polyware.iaf.nl),
4343 * Robert Morris (rtm@das.harvard.edu),
4344 * Jean Tourrilhes (jt@hplb.hpl.hp.com),
4345 * Girish Welling (welling@paul.rutgers.edu),
4347 * Thanks go also to:
4348 * James Ashton (jaa101@syseng.anu.edu.au),
4349 * Alan Cox (iialan@iiit.swan.ac.uk),
4350 * Allan Creighton (allanc@cs.usyd.edu.au),
4351 * Matthew Geier (matthew@cs.usyd.edu.au),
4352 * Remo di Giovanni (remo@cs.usyd.edu.au),
4353 * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
4354 * Vipul Gupta (vgupta@cs.binghamton.edu),
4355 * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
4356 * Tim Nicholson (tim@cs.usyd.edu.au),
4357 * Ian Parkin (ian@cs.usyd.edu.au),
4358 * John Rosenberg (johnr@cs.usyd.edu.au),
4359 * George Rossi (george@phm.gov.au),
4360 * Arthur Scott (arthur@cs.usyd.edu.au),
4361 * Peter Storey,
4362 * for their assistance and advice.
4364 * Please send bug reports, updates, comments to:
4366 * Bruce Janson Email: bruce@cs.usyd.edu.au
4367 * Basser Department of Computer Science Phone: +61-2-9351-3423
4368 * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838