2 * Wavelan Pcmcia driver
6 * Reorganisation and extension of the driver.
7 * Original copyright follow. See wavelan_cs.p.h for details.
9 * This code is derived from Anthony D. Joseph's code and all the changes here
10 * are also under the original copyright below.
12 * This code supports version 2.00 of WaveLAN/PCMCIA cards (2.4GHz), and
13 * can work on Linux 2.0.36 with support of David Hinds' PCMCIA Card Services
15 * Joe Finney (joe@comp.lancs.ac.uk) at Lancaster University in UK added
16 * critical code in the routine to initialize the Modem Management Controller.
18 * Thanks to Alan Cox and Bruce Janson for their advice.
20 * -- Yunzhou Li (scip4166@nus.sg)
22 #ifdef WAVELAN_ROAMING
23 * Roaming support added 07/22/98 by Justin Seger (jseger@media.mit.edu)
24 * based on patch by Joe Finney from Lancaster University.
27 * Lucent (formerly AT&T GIS, formerly NCR) WaveLAN PCMCIA card: An
28 * Ethernet-like radio transceiver controlled by an Intel 82593 coprocessor.
30 * A non-shared memory PCMCIA ethernet driver for linux
32 * ISA version modified to support PCMCIA by Anthony Joseph (adj@lcs.mit.edu)
35 * Joseph O'Sullivan & John Langford (josullvn@cs.cmu.edu & jcl@cs.cmu.edu)
37 * Apr 2 '98 made changes to bring the i82593 control/int handling in line
38 * with offical specs...
40 ****************************************************************************
43 * Massachusetts Institute of Technology
45 * Permission to use, copy, modify, and distribute this program
46 * for any purpose and without fee is hereby granted, provided
47 * that this copyright and permission notice appear on all copies
48 * and supporting documentation, the name of M.I.T. not be used
49 * in advertising or publicity pertaining to distribution of the
50 * program without specific prior permission, and notice be given
51 * in supporting documentation that copying and distribution is
52 * by permission of M.I.T. M.I.T. makes no representations about
53 * the suitability of this software for any purpose. It is pro-
54 * vided "as is" without express or implied warranty.
55 ****************************************************************************
59 /* Do *NOT* add other headers here, you are guaranteed to be wrong - Jean II */
60 #include "wavelan_cs.p.h" /* Private header */
62 /************************* MISC SUBROUTINES **************************/
64 * Subroutines which won't fit in one of the following category
65 * (wavelan modem or i82593)
69 /*------------------------------------------------------------------*/
71 * Sanity routine to verify the sizes of the various WaveLAN interface
75 wv_structuct_check(void)
77 #define SC(t,s,n) if (sizeof(t) != s) return(n);
79 SC(psa_t, PSA_SIZE, "psa_t");
80 SC(mmw_t, MMW_SIZE, "mmw_t");
81 SC(mmr_t, MMR_SIZE, "mmr_t");
85 return((char *) NULL);
86 } /* wv_structuct_check */
87 #endif /* STRUCT_CHECK */
89 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
91 * Useful subroutines to manage the modem of the wavelan
94 /*------------------------------------------------------------------*/
96 * Read from card's Host Adaptor Status Register.
99 hasr_read(u_long base)
101 return(inb(HASR(base)));
104 /*------------------------------------------------------------------*/
106 * Write to card's Host Adapter Command Register.
109 hacr_write(u_long base,
112 outb(hacr, HACR(base));
115 /*------------------------------------------------------------------*/
117 * Write to card's Host Adapter Command Register. Include a delay for
118 * those times when it is needed.
121 hacr_write_slow(u_long base,
124 hacr_write(base, hacr);
125 /* delay might only be needed sometimes */
127 } /* hacr_write_slow */
129 /*------------------------------------------------------------------*/
131 * Read the Parameter Storage Area from the WaveLAN card's memory
134 psa_read(struct net_device * dev,
135 int o, /* offset in PSA */
136 u_char * b, /* buffer to fill */
137 int n) /* size to read */
139 net_local *lp = netdev_priv(dev);
140 u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
145 /* Due to a lack of address decode pins, the WaveLAN PCMCIA card
146 * only supports reading even memory addresses. That means the
147 * increment here MUST be two.
148 * Because of that, we can't use memcpy_fromio()...
154 /*------------------------------------------------------------------*/
156 * Write the Paramter Storage Area to the WaveLAN card's memory
159 psa_write(struct net_device * dev,
160 int o, /* Offset in psa */
161 u_char * b, /* Buffer in memory */
162 int n) /* Length of buffer */
164 net_local *lp = netdev_priv(dev);
165 u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
167 kio_addr_t base = dev->base_addr;
168 /* As there seem to have no flag PSA_BUSY as in the ISA model, we are
169 * oblige to verify this address to know when the PSA is ready... */
170 volatile u_char __iomem *verify = lp->mem + PSA_ADDR +
171 (psaoff(0, psa_comp_number) << 1);
173 /* Authorize writting to PSA */
174 hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN);
182 /* I don't have the spec, so I don't know what the correct
183 * sequence to write is. This hack seem to work for me... */
185 while((readb(verify) != PSA_COMP_PCMCIA_915) && (count++ < 100))
189 /* Put the host interface back in standard state */
190 hacr_write(base, HACR_DEFAULT);
194 /*------------------------------------------------------------------*/
196 * Calculate the PSA CRC
197 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
198 * NOTE: By specifying a length including the CRC position the
199 * returned value should be zero. (i.e. a correct checksum in the PSA)
201 * The Windows drivers don't use the CRC, but the AP and the PtP tool
205 psa_crc(unsigned char * psa, /* The PSA */
206 int size) /* Number of short for CRC */
208 int byte_cnt; /* Loop on the PSA */
209 u_short crc_bytes = 0; /* Data in the PSA */
210 int bit_cnt; /* Loop on the bits of the short */
212 for(byte_cnt = 0; byte_cnt < size; byte_cnt++ )
214 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
216 for(bit_cnt = 1; bit_cnt < 9; bit_cnt++ )
218 if(crc_bytes & 0x0001)
219 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
227 #endif /* SET_PSA_CRC */
229 /*------------------------------------------------------------------*/
231 * update the checksum field in the Wavelan's PSA
234 update_psa_checksum(struct net_device * dev)
240 /* read the parameter storage area */
241 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
243 /* update the checksum */
244 crc = psa_crc((unsigned char *) &psa,
245 sizeof(psa) - sizeof(psa.psa_crc[0]) - sizeof(psa.psa_crc[1])
246 - sizeof(psa.psa_crc_status));
248 psa.psa_crc[0] = crc & 0xFF;
249 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
252 psa_write(dev, (char *)&psa.psa_crc - (char *)&psa,
253 (unsigned char *)&psa.psa_crc, 2);
255 #ifdef DEBUG_IOCTL_INFO
256 printk (KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
257 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
259 /* Check again (luxury !) */
260 crc = psa_crc((unsigned char *) &psa,
261 sizeof(psa) - sizeof(psa.psa_crc_status));
264 printk(KERN_WARNING "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", dev->name);
265 #endif /* DEBUG_IOCTL_INFO */
266 #endif /* SET_PSA_CRC */
267 } /* update_psa_checksum */
269 /*------------------------------------------------------------------*/
271 * Write 1 byte to the MMC.
280 /* Wait for MMC to go idle */
281 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
284 outb((u_char)((o << 1) | MMR_MMI_WR), MMR(base));
288 /*------------------------------------------------------------------*/
290 * Routine to write bytes to the Modem Management Controller.
291 * We start by the end because it is the way it should be !
294 mmc_write(u_long base,
303 mmc_out(base, --o, *(--b));
306 /*------------------------------------------------------------------*/
308 * Read 1 byte from the MMC.
309 * Optimised version for 1 byte, avoid using memory...
317 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
319 outb(o << 1, MMR(base)); /* Set the read address */
321 outb(0, MMD(base)); /* Required dummy write */
323 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
325 return (u_char) (inb(MMD(base))); /* Now do the actual read */
328 /*------------------------------------------------------------------*/
330 * Routine to read bytes from the Modem Management Controller.
331 * The implementation is complicated by a lack of address lines,
332 * which prevents decoding of the low-order bit.
333 * (code has just been moved in the above function)
334 * We start by the end because it is the way it should be !
337 mmc_read(u_long base,
346 *(--b) = mmc_in(base, --o);
349 /*------------------------------------------------------------------*/
351 * Get the type of encryption available...
354 mmc_encr(u_long base) /* i/o port of the card */
358 temp = mmc_in(base, mmroff(0, mmr_des_avail));
359 if((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
365 /*------------------------------------------------------------------*/
367 * Wait for the frequency EEprom to complete a command...
368 * I hope this one will be optimally inlined...
371 fee_wait(u_long base, /* i/o port of the card */
372 int delay, /* Base delay to wait for */
373 int number) /* Number of time to wait */
375 int count = 0; /* Wait only a limited time */
377 while((count++ < number) &&
378 (mmc_in(base, mmroff(0, mmr_fee_status)) & MMR_FEE_STATUS_BUSY))
382 /*------------------------------------------------------------------*/
384 * Read bytes from the Frequency EEprom (frequency select cards).
387 fee_read(u_long base, /* i/o port of the card */
388 u_short o, /* destination offset */
389 u_short * b, /* data buffer */
390 int n) /* number of registers */
392 b += n; /* Position at the end of the area */
394 /* Write the address */
395 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
397 /* Loop on all buffer */
400 /* Write the read command */
401 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_READ);
403 /* Wait until EEprom is ready (should be quick !) */
404 fee_wait(base, 10, 100);
407 *--b = ((mmc_in(base, mmroff(0, mmr_fee_data_h)) << 8) |
408 mmc_in(base, mmroff(0, mmr_fee_data_l)));
412 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
414 /*------------------------------------------------------------------*/
416 * Write bytes from the Frequency EEprom (frequency select cards).
417 * This is a bit complicated, because the frequency eeprom has to
418 * be unprotected and the write enabled.
422 fee_write(u_long base, /* i/o port of the card */
423 u_short o, /* destination offset */
424 u_short * b, /* data buffer */
425 int n) /* number of registers */
427 b += n; /* Position at the end of the area */
429 #ifdef EEPROM_IS_PROTECTED /* disabled */
430 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
431 /* Ask to read the protected register */
432 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
434 fee_wait(base, 10, 100);
436 /* Read the protected register */
437 printk("Protected 2 : %02X-%02X\n",
438 mmc_in(base, mmroff(0, mmr_fee_data_h)),
439 mmc_in(base, mmroff(0, mmr_fee_data_l)));
440 #endif /* DOESNT_SEEM_TO_WORK */
442 /* Enable protected register */
443 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
444 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
446 fee_wait(base, 10, 100);
449 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n);
450 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
451 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
453 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
454 #endif /* DOESNT_SEEM_TO_WORK */
456 fee_wait(base, 10, 100);
457 #endif /* EEPROM_IS_PROTECTED */
460 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
461 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
463 fee_wait(base, 10, 100);
465 /* Write the EEprom address */
466 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
468 /* Loop on all buffer */
471 /* Write the value */
472 mmc_out(base, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
473 mmc_out(base, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
475 /* Write the write command */
476 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WRITE);
478 /* Wavelan doc says : wait at least 10 ms for EEBUSY = 0 */
480 fee_wait(base, 10, 100);
484 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
485 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
487 fee_wait(base, 10, 100);
489 #ifdef EEPROM_IS_PROTECTED /* disabled */
490 /* Reprotect EEprom */
491 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x00);
492 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
494 fee_wait(base, 10, 100);
495 #endif /* EEPROM_IS_PROTECTED */
497 #endif /* WIRELESS_EXT */
499 /******************* WaveLAN Roaming routines... ********************/
501 #ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */
503 unsigned char WAVELAN_BEACON_ADDRESS[]= {0x09,0x00,0x0e,0x20,0x03,0x00};
505 void wv_roam_init(struct net_device *dev)
507 net_local *lp= netdev_priv(dev);
509 /* Do not remove this unless you have a good reason */
510 printk(KERN_NOTICE "%s: Warning, you have enabled roaming on"
511 " device %s !\n", dev->name, dev->name);
512 printk(KERN_NOTICE "Roaming is currently an experimental unsupported feature"
513 " of the Wavelan driver.\n");
514 printk(KERN_NOTICE "It may work, but may also make the driver behave in"
515 " erratic ways or crash.\n");
517 lp->wavepoint_table.head=NULL; /* Initialise WavePoint table */
518 lp->wavepoint_table.num_wavepoints=0;
519 lp->wavepoint_table.locked=0;
520 lp->curr_point=NULL; /* No default WavePoint */
523 lp->cell_timer.data=(long)lp; /* Start cell expiry timer */
524 lp->cell_timer.function=wl_cell_expiry;
525 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
526 add_timer(&lp->cell_timer);
528 wv_nwid_filter(NWID_PROMISC,lp) ; /* Enter NWID promiscuous mode */
529 /* to build up a good WavePoint */
531 printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name);
534 void wv_roam_cleanup(struct net_device *dev)
536 wavepoint_history *ptr,*old_ptr;
537 net_local *lp= netdev_priv(dev);
539 printk(KERN_DEBUG "WaveLAN: Roaming Disabled on device %s\n",dev->name);
541 /* Fixme : maybe we should check that the timer exist before deleting it */
542 del_timer(&lp->cell_timer); /* Remove cell expiry timer */
543 ptr=lp->wavepoint_table.head; /* Clear device's WavePoint table */
548 wl_del_wavepoint(old_ptr,lp);
552 /* Enable/Disable NWID promiscuous mode on a given device */
553 void wv_nwid_filter(unsigned char mode, net_local *lp)
558 #ifdef WAVELAN_ROAMING_DEBUG
559 printk(KERN_DEBUG "WaveLAN: NWID promisc %s, device %s\n",(mode==NWID_PROMISC) ? "on" : "off", lp->dev->name);
562 /* Disable interrupts & save flags */
563 spin_lock_irqsave(&lp->spinlock, flags);
565 m.w.mmw_loopt_sel = (mode==NWID_PROMISC) ? MMW_LOOPT_SEL_DIS_NWID : 0x00;
566 mmc_write(lp->dev->base_addr, (char *)&m.w.mmw_loopt_sel - (char *)&m, (unsigned char *)&m.w.mmw_loopt_sel, 1);
568 if(mode==NWID_PROMISC)
573 /* ReEnable interrupts & restore flags */
574 spin_unlock_irqrestore(&lp->spinlock, flags);
577 /* Find a record in the WavePoint table matching a given NWID */
578 wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp)
580 wavepoint_history *ptr=lp->wavepoint_table.head;
590 /* Create a new wavepoint table entry */
591 wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp)
593 wavepoint_history *new_wavepoint;
595 #ifdef WAVELAN_ROAMING_DEBUG
596 printk(KERN_DEBUG "WaveLAN: New Wavepoint, NWID:%.4X\n",nwid);
599 if(lp->wavepoint_table.num_wavepoints==MAX_WAVEPOINTS)
602 new_wavepoint=(wavepoint_history *) kmalloc(sizeof(wavepoint_history),GFP_ATOMIC);
603 if(new_wavepoint==NULL)
606 new_wavepoint->nwid=nwid; /* New WavePoints NWID */
607 new_wavepoint->average_fast=0; /* Running Averages..*/
608 new_wavepoint->average_slow=0;
609 new_wavepoint->qualptr=0; /* Start of ringbuffer */
610 new_wavepoint->last_seq=seq-1; /* Last sequence no.seen */
611 memset(new_wavepoint->sigqual,0,WAVEPOINT_HISTORY);/* Empty ringbuffer */
613 new_wavepoint->next=lp->wavepoint_table.head;/* Add to wavepoint table */
614 new_wavepoint->prev=NULL;
616 if(lp->wavepoint_table.head!=NULL)
617 lp->wavepoint_table.head->prev=new_wavepoint;
619 lp->wavepoint_table.head=new_wavepoint;
621 lp->wavepoint_table.num_wavepoints++; /* no. of visible wavepoints */
623 return new_wavepoint;
626 /* Remove a wavepoint entry from WavePoint table */
627 void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp)
632 if(lp->curr_point==wavepoint)
635 if(wavepoint->prev!=NULL)
636 wavepoint->prev->next=wavepoint->next;
638 if(wavepoint->next!=NULL)
639 wavepoint->next->prev=wavepoint->prev;
641 if(lp->wavepoint_table.head==wavepoint)
642 lp->wavepoint_table.head=wavepoint->next;
644 lp->wavepoint_table.num_wavepoints--;
648 /* Timer callback function - checks WavePoint table for stale entries */
649 void wl_cell_expiry(unsigned long data)
651 net_local *lp=(net_local *)data;
652 wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point;
654 #if WAVELAN_ROAMING_DEBUG > 1
655 printk(KERN_DEBUG "WaveLAN: Wavepoint timeout, dev %s\n",lp->dev->name);
658 if(lp->wavepoint_table.locked)
660 #if WAVELAN_ROAMING_DEBUG > 1
661 printk(KERN_DEBUG "WaveLAN: Wavepoint table locked...\n");
664 lp->cell_timer.expires=jiffies+1; /* If table in use, come back later */
665 add_timer(&lp->cell_timer);
669 while(wavepoint!=NULL)
671 if(time_after(jiffies, wavepoint->last_seen + CELL_TIMEOUT))
673 #ifdef WAVELAN_ROAMING_DEBUG
674 printk(KERN_DEBUG "WaveLAN: Bye bye %.4X\n",wavepoint->nwid);
678 wavepoint=wavepoint->next;
679 wl_del_wavepoint(old_point,lp);
682 wavepoint=wavepoint->next;
684 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
685 add_timer(&lp->cell_timer);
688 /* Update SNR history of a wavepoint */
689 void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq)
691 int i=0,num_missed=0,ptr=0;
692 int average_fast=0,average_slow=0;
694 num_missed=(seq-wavepoint->last_seq)%WAVEPOINT_HISTORY;/* Have we missed
697 for(i=0;i<num_missed;i++)
699 wavepoint->sigqual[wavepoint->qualptr++]=0; /* If so, enter them as 0's */
700 wavepoint->qualptr %=WAVEPOINT_HISTORY; /* in the ringbuffer. */
702 wavepoint->last_seen=jiffies; /* Add beacon to history */
703 wavepoint->last_seq=seq;
704 wavepoint->sigqual[wavepoint->qualptr++]=sigqual;
705 wavepoint->qualptr %=WAVEPOINT_HISTORY;
706 ptr=(wavepoint->qualptr-WAVEPOINT_FAST_HISTORY+WAVEPOINT_HISTORY)%WAVEPOINT_HISTORY;
708 for(i=0;i<WAVEPOINT_FAST_HISTORY;i++) /* Update running averages */
710 average_fast+=wavepoint->sigqual[ptr++];
711 ptr %=WAVEPOINT_HISTORY;
714 average_slow=average_fast;
715 for(i=WAVEPOINT_FAST_HISTORY;i<WAVEPOINT_HISTORY;i++)
717 average_slow+=wavepoint->sigqual[ptr++];
718 ptr %=WAVEPOINT_HISTORY;
721 wavepoint->average_fast=average_fast/WAVEPOINT_FAST_HISTORY;
722 wavepoint->average_slow=average_slow/WAVEPOINT_HISTORY;
725 /* Perform a handover to a new WavePoint */
726 void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp)
728 kio_addr_t base = lp->dev->base_addr;
732 if(wavepoint==lp->curr_point) /* Sanity check... */
734 wv_nwid_filter(!NWID_PROMISC,lp);
738 #ifdef WAVELAN_ROAMING_DEBUG
739 printk(KERN_DEBUG "WaveLAN: Doing handover to %.4X, dev %s\n",wavepoint->nwid,lp->dev->name);
742 /* Disable interrupts & save flags */
743 spin_lock_irqsave(&lp->spinlock, flags);
745 m.w.mmw_netw_id_l = wavepoint->nwid & 0xFF;
746 m.w.mmw_netw_id_h = (wavepoint->nwid & 0xFF00) >> 8;
748 mmc_write(base, (char *)&m.w.mmw_netw_id_l - (char *)&m, (unsigned char *)&m.w.mmw_netw_id_l, 2);
750 /* ReEnable interrupts & restore flags */
751 spin_unlock_irqrestore(&lp->spinlock, flags);
753 wv_nwid_filter(!NWID_PROMISC,lp);
754 lp->curr_point=wavepoint;
757 /* Called when a WavePoint beacon is received */
758 static inline void wl_roam_gather(struct net_device * dev,
759 u_char * hdr, /* Beacon header */
760 u_char * stats) /* SNR, Signal quality
763 wavepoint_beacon *beacon= (wavepoint_beacon *)hdr; /* Rcvd. Beacon */
764 unsigned short nwid=ntohs(beacon->nwid);
765 unsigned short sigqual=stats[2] & MMR_SGNL_QUAL; /* SNR of beacon */
766 wavepoint_history *wavepoint=NULL; /* WavePoint table entry */
767 net_local *lp = netdev_priv(dev); /* Device info */
769 #ifdef I_NEED_THIS_FEATURE
770 /* Some people don't need this, some other may need it */
771 nwid=nwid^ntohs(beacon->domain_id);
774 #if WAVELAN_ROAMING_DEBUG > 1
775 printk(KERN_DEBUG "WaveLAN: beacon, dev %s:\n",dev->name);
776 printk(KERN_DEBUG "Domain: %.4X NWID: %.4X SigQual=%d\n",ntohs(beacon->domain_id),nwid,sigqual);
779 lp->wavepoint_table.locked=1; /* <Mutex> */
781 wavepoint=wl_roam_check(nwid,lp); /* Find WavePoint table entry */
782 if(wavepoint==NULL) /* If no entry, Create a new one... */
784 wavepoint=wl_new_wavepoint(nwid,beacon->seq,lp);
788 if(lp->curr_point==NULL) /* If this is the only WavePoint, */
789 wv_roam_handover(wavepoint, lp); /* Jump on it! */
791 wl_update_history(wavepoint, sigqual, beacon->seq); /* Update SNR history
794 if(lp->curr_point->average_slow < SEARCH_THRESH_LOW) /* If our current */
795 if(!lp->cell_search) /* WavePoint is getting faint, */
796 wv_nwid_filter(NWID_PROMISC,lp); /* start looking for a new one */
798 if(wavepoint->average_slow >
799 lp->curr_point->average_slow + WAVELAN_ROAMING_DELTA)
800 wv_roam_handover(wavepoint, lp); /* Handover to a better WavePoint */
802 if(lp->curr_point->average_slow > SEARCH_THRESH_HIGH) /* If our SNR is */
803 if(lp->cell_search) /* getting better, drop out of cell search mode */
804 wv_nwid_filter(!NWID_PROMISC,lp);
807 lp->wavepoint_table.locked=0; /* </MUTEX> :-) */
810 /* Test this MAC frame a WavePoint beacon */
811 static inline int WAVELAN_BEACON(unsigned char *data)
813 wavepoint_beacon *beacon= (wavepoint_beacon *)data;
814 static wavepoint_beacon beacon_template={0xaa,0xaa,0x03,0x08,0x00,0x0e,0x20,0x03,0x00};
816 if(memcmp(beacon,&beacon_template,9)==0)
821 #endif /* WAVELAN_ROAMING */
823 /************************ I82593 SUBROUTINES *************************/
825 * Useful subroutines to manage the Ethernet controller
828 /*------------------------------------------------------------------*/
830 * Routine to synchronously send a command to the i82593 chip.
831 * Should be called with interrupts disabled.
832 * (called by wv_packet_write(), wv_ru_stop(), wv_ru_start(),
833 * wv_82593_config() & wv_diag())
836 wv_82593_cmd(struct net_device * dev,
841 kio_addr_t base = dev->base_addr;
846 /* Spin until the chip finishes executing its current command (if any) */
850 /* Time calibration of the loop */
853 /* Read the interrupt register */
854 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
855 status = inb(LCSR(base));
857 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
859 /* If the interrupt hasn't be posted */
862 #ifdef DEBUG_INTERRUPT_ERROR
863 printk(KERN_INFO "wv_82593_cmd: %s timeout (previous command), status 0x%02x\n",
869 /* Issue the command to the controller */
870 outb(cmd, LCCR(base));
872 /* If we don't have to check the result of the command
873 * Note : this mean that the irq handler will deal with that */
874 if(result == SR0_NO_RESULT)
877 /* We are waiting for command completion */
878 wait_completed = TRUE;
880 /* Busy wait while the LAN controller executes the command. */
884 /* Time calibration of the loop */
887 /* Read the interrupt register */
888 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
889 status = inb(LCSR(base));
891 /* Check if there was an interrupt posted */
892 if((status & SR0_INTERRUPT))
894 /* Acknowledge the interrupt */
895 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
897 /* Check if interrupt is a command completion */
898 if(((status & SR0_BOTH_RX_TX) != SR0_BOTH_RX_TX) &&
899 ((status & SR0_BOTH_RX_TX) != 0x0) &&
900 !(status & SR0_RECEPTION))
902 /* Signal command completion */
903 wait_completed = FALSE;
907 /* Note : Rx interrupts will be handled later, because we can
908 * handle multiple Rx packets at once */
909 #ifdef DEBUG_INTERRUPT_INFO
910 printk(KERN_INFO "wv_82593_cmd: not our interrupt\n");
915 while(wait_completed && (spin-- > 0));
917 /* If the interrupt hasn't be posted */
920 #ifdef DEBUG_INTERRUPT_ERROR
921 printk(KERN_INFO "wv_82593_cmd: %s timeout, status 0x%02x\n",
927 /* Check the return code returned by the card (see above) against
928 * the expected return code provided by the caller */
929 if((status & SR0_EVENT_MASK) != result)
931 #ifdef DEBUG_INTERRUPT_ERROR
932 printk(KERN_INFO "wv_82593_cmd: %s failed, status = 0x%x\n",
941 /*------------------------------------------------------------------*/
943 * This routine does a 593 op-code number 7, and obtains the diagnose
944 * status for the WaveLAN.
947 wv_diag(struct net_device * dev)
951 if(wv_82593_cmd(dev, "wv_diag(): diagnose",
952 OP0_DIAGNOSE, SR0_DIAGNOSE_PASSED))
955 #ifdef DEBUG_CONFIG_ERRORS
956 printk(KERN_INFO "wavelan_cs: i82593 Self Test failed!\n");
961 /*------------------------------------------------------------------*/
963 * Routine to read len bytes from the i82593's ring buffer, starting at
964 * chip address addr. The results read from the chip are stored in buf.
965 * The return value is the address to use for next the call.
968 read_ringbuf(struct net_device * dev,
973 kio_addr_t base = dev->base_addr;
976 char * buf_ptr = buf;
978 /* Get all the buffer */
981 /* Position the Program I/O Register at the ring buffer pointer */
982 outb(ring_ptr & 0xff, PIORL(base));
983 outb(((ring_ptr >> 8) & PIORH_MASK), PIORH(base));
985 /* First, determine how much we can read without wrapping around the
987 if((addr + len) < (RX_BASE + RX_SIZE))
990 chunk_len = RX_BASE + RX_SIZE - addr;
991 insb(PIOP(base), buf_ptr, chunk_len);
992 buf_ptr += chunk_len;
994 ring_ptr = (ring_ptr - RX_BASE + chunk_len) % RX_SIZE + RX_BASE;
999 /*------------------------------------------------------------------*/
1001 * Reconfigure the i82593, or at least ask for it...
1002 * Because wv_82593_config use the transmission buffer, we must do it
1003 * when we are sure that there is no transmission, so we do it now
1004 * or in wavelan_packet_xmit() (I can't find any better place,
1005 * wavelan_interrupt is not an option...), so you may experience
1006 * some delay sometime...
1009 wv_82593_reconfig(struct net_device * dev)
1011 net_local * lp = netdev_priv(dev);
1012 dev_link_t * link = lp->link;
1013 unsigned long flags;
1015 /* Arm the flag, will be cleard in wv_82593_config() */
1016 lp->reconfig_82593 = TRUE;
1018 /* Check if we can do it now ! */
1019 if((link->open) && (netif_running(dev)) && !(netif_queue_stopped(dev)))
1021 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
1022 wv_82593_config(dev);
1023 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
1027 #ifdef DEBUG_IOCTL_INFO
1029 "%s: wv_82593_reconfig(): delayed (state = %lX, link = %d)\n",
1030 dev->name, dev->state, link->open);
1035 /********************* DEBUG & INFO SUBROUTINES *********************/
1037 * This routines are used in the code to show debug informations.
1038 * Most of the time, it dump the content of hardware structures...
1041 #ifdef DEBUG_PSA_SHOW
1042 /*------------------------------------------------------------------*/
1044 * Print the formatted contents of the Parameter Storage Area.
1047 wv_psa_show(psa_t * p)
1049 printk(KERN_DEBUG "##### wavelan psa contents: #####\n");
1050 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
1051 p->psa_io_base_addr_1,
1052 p->psa_io_base_addr_2,
1053 p->psa_io_base_addr_3,
1054 p->psa_io_base_addr_4);
1055 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
1056 p->psa_rem_boot_addr_1,
1057 p->psa_rem_boot_addr_2,
1058 p->psa_rem_boot_addr_3);
1059 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
1060 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
1061 #ifdef DEBUG_SHOW_UNUSED
1062 printk(KERN_DEBUG "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1070 #endif /* DEBUG_SHOW_UNUSED */
1071 printk(KERN_DEBUG "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
1072 p->psa_univ_mac_addr[0],
1073 p->psa_univ_mac_addr[1],
1074 p->psa_univ_mac_addr[2],
1075 p->psa_univ_mac_addr[3],
1076 p->psa_univ_mac_addr[4],
1077 p->psa_univ_mac_addr[5]);
1078 printk(KERN_DEBUG "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
1079 p->psa_local_mac_addr[0],
1080 p->psa_local_mac_addr[1],
1081 p->psa_local_mac_addr[2],
1082 p->psa_local_mac_addr[3],
1083 p->psa_local_mac_addr[4],
1084 p->psa_local_mac_addr[5]);
1085 printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel);
1086 printk("psa_comp_number: %d, ", p->psa_comp_number);
1087 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
1088 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
1089 p->psa_feature_select);
1090 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
1091 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
1092 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
1093 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]);
1094 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
1095 printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select);
1096 printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1097 p->psa_encryption_key[0],
1098 p->psa_encryption_key[1],
1099 p->psa_encryption_key[2],
1100 p->psa_encryption_key[3],
1101 p->psa_encryption_key[4],
1102 p->psa_encryption_key[5],
1103 p->psa_encryption_key[6],
1104 p->psa_encryption_key[7]);
1105 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
1106 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
1107 p->psa_call_code[0]);
1108 printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1109 p->psa_call_code[0],
1110 p->psa_call_code[1],
1111 p->psa_call_code[2],
1112 p->psa_call_code[3],
1113 p->psa_call_code[4],
1114 p->psa_call_code[5],
1115 p->psa_call_code[6],
1116 p->psa_call_code[7]);
1117 #ifdef DEBUG_SHOW_UNUSED
1118 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
1122 p->psa_reserved[3]);
1123 #endif /* DEBUG_SHOW_UNUSED */
1124 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
1125 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
1126 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
1128 #endif /* DEBUG_PSA_SHOW */
1130 #ifdef DEBUG_MMC_SHOW
1131 /*------------------------------------------------------------------*/
1133 * Print the formatted status of the Modem Management Controller.
1134 * This function need to be completed...
1137 wv_mmc_show(struct net_device * dev)
1139 kio_addr_t base = dev->base_addr;
1140 net_local * lp = netdev_priv(dev);
1144 if(hasr_read(base) & HASR_NO_CLK)
1146 printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n",
1151 spin_lock_irqsave(&lp->spinlock, flags);
1154 mmc_out(base, mmwoff(0, mmw_freeze), 1);
1155 mmc_read(base, 0, (u_char *)&m, sizeof(m));
1156 mmc_out(base, mmwoff(0, mmw_freeze), 0);
1158 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1159 /* Don't forget to update statistics */
1160 lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
1161 #endif /* WIRELESS_EXT */
1163 spin_unlock_irqrestore(&lp->spinlock, flags);
1165 printk(KERN_DEBUG "##### wavelan modem status registers: #####\n");
1166 #ifdef DEBUG_SHOW_UNUSED
1167 printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1176 #endif /* DEBUG_SHOW_UNUSED */
1177 printk(KERN_DEBUG "Encryption algorythm: %02X - Status: %02X\n",
1178 m.mmr_des_avail, m.mmr_des_status);
1179 #ifdef DEBUG_SHOW_UNUSED
1180 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1186 #endif /* DEBUG_SHOW_UNUSED */
1187 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1189 (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"",
1190 (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1191 "loop test indicated," : "",
1192 (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "",
1193 (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1194 "jabber timer expired," : "");
1195 printk(KERN_DEBUG "Dsp ID: %02X\n",
1197 #ifdef DEBUG_SHOW_UNUSED
1198 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1201 #endif /* DEBUG_SHOW_UNUSED */
1202 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1203 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1204 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1205 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1206 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1207 (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below");
1208 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1209 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1210 (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg");
1211 printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL,
1212 (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update");
1213 printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1214 (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0");
1215 #ifdef DEBUG_SHOW_UNUSED
1216 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1217 #endif /* DEBUG_SHOW_UNUSED */
1219 #endif /* DEBUG_MMC_SHOW */
1221 #ifdef DEBUG_I82593_SHOW
1222 /*------------------------------------------------------------------*/
1224 * Print the formatted status of the i82593's receive unit.
1227 wv_ru_show(struct net_device * dev)
1229 net_local *lp = netdev_priv(dev);
1231 printk(KERN_DEBUG "##### wavelan i82593 receiver status: #####\n");
1232 printk(KERN_DEBUG "ru: rfp %d stop %d", lp->rfp, lp->stop);
1234 * Not implemented yet...
1238 #endif /* DEBUG_I82593_SHOW */
1240 #ifdef DEBUG_DEVICE_SHOW
1241 /*------------------------------------------------------------------*/
1243 * Print the formatted status of the WaveLAN PCMCIA device driver.
1246 wv_dev_show(struct net_device * dev)
1248 printk(KERN_DEBUG "dev:");
1249 printk(" state=%lX,", dev->state);
1250 printk(" trans_start=%ld,", dev->trans_start);
1251 printk(" flags=0x%x,", dev->flags);
1255 /*------------------------------------------------------------------*/
1257 * Print the formatted status of the WaveLAN PCMCIA device driver's
1258 * private information.
1261 wv_local_show(struct net_device * dev)
1263 net_local *lp = netdev_priv(dev);
1265 printk(KERN_DEBUG "local:");
1267 * Not implemented yet...
1270 } /* wv_local_show */
1271 #endif /* DEBUG_DEVICE_SHOW */
1273 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1274 /*------------------------------------------------------------------*/
1276 * Dump packet header (and content if necessary) on the screen
1279 wv_packet_info(u_char * p, /* Packet to dump */
1280 int length, /* Length of the packet */
1281 char * msg1, /* Name of the device */
1282 char * msg2) /* Name of the function */
1287 printk(KERN_DEBUG "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1288 msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1289 printk(KERN_DEBUG "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1290 msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13]);
1292 #ifdef DEBUG_PACKET_DUMP
1294 printk(KERN_DEBUG "data=\"");
1296 if((maxi = length) > DEBUG_PACKET_DUMP)
1297 maxi = DEBUG_PACKET_DUMP;
1298 for(i = 14; i < maxi; i++)
1299 if(p[i] >= ' ' && p[i] <= '~')
1300 printk(" %c", p[i]);
1302 printk("%02X", p[i]);
1306 printk(KERN_DEBUG "\n");
1307 #endif /* DEBUG_PACKET_DUMP */
1309 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1311 /*------------------------------------------------------------------*/
1313 * This is the information which is displayed by the driver at startup
1314 * There is a lot of flag to configure it at your will...
1317 wv_init_info(struct net_device * dev)
1319 kio_addr_t base = dev->base_addr;
1323 /* Read the parameter storage area */
1324 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
1326 #ifdef DEBUG_PSA_SHOW
1329 #ifdef DEBUG_MMC_SHOW
1332 #ifdef DEBUG_I82593_SHOW
1336 #ifdef DEBUG_BASIC_SHOW
1337 /* Now, let's go for the basic stuff */
1338 printk(KERN_NOTICE "%s: WaveLAN: port %#lx, irq %d, hw_addr",
1339 dev->name, base, dev->irq);
1340 for(i = 0; i < WAVELAN_ADDR_SIZE; i++)
1341 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1343 /* Print current network id */
1344 if(psa.psa_nwid_select)
1345 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
1347 printk(", nwid off");
1350 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1351 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1353 unsigned short freq;
1355 /* Ask the EEprom to read the frequency from the first area */
1356 fee_read(base, 0x00 /* 1st area - frequency... */,
1359 /* Print frequency */
1360 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1368 printk(", PCMCIA, ");
1369 switch (psa.psa_subband)
1371 case PSA_SUBBAND_915:
1374 case PSA_SUBBAND_2425:
1377 case PSA_SUBBAND_2460:
1380 case PSA_SUBBAND_2484:
1383 case PSA_SUBBAND_2430_5:
1392 #endif /* DEBUG_BASIC_SHOW */
1394 #ifdef DEBUG_VERSION_SHOW
1395 /* Print version information */
1396 printk(KERN_NOTICE "%s", version);
1398 } /* wv_init_info */
1400 /********************* IOCTL, STATS & RECONFIG *********************/
1402 * We found here routines that are called by Linux on differents
1403 * occasions after the configuration and not for transmitting data
1404 * These may be called when the user use ifconfig, /proc/net/dev
1405 * or wireless extensions
1408 /*------------------------------------------------------------------*/
1410 * Get the current ethernet statistics. This may be called with the
1411 * card open or closed.
1412 * Used when the user read /proc/net/dev
1415 wavelan_get_stats(struct net_device * dev)
1417 #ifdef DEBUG_IOCTL_TRACE
1418 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1421 return(&((net_local *)netdev_priv(dev))->stats);
1424 /*------------------------------------------------------------------*/
1426 * Set or clear the multicast filter for this adaptor.
1427 * num_addrs == -1 Promiscuous mode, receive all packets
1428 * num_addrs == 0 Normal mode, clear multicast list
1429 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1430 * and do best-effort filtering.
1434 wavelan_set_multicast_list(struct net_device * dev)
1436 net_local * lp = netdev_priv(dev);
1438 #ifdef DEBUG_IOCTL_TRACE
1439 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
1442 #ifdef DEBUG_IOCTL_INFO
1443 printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1444 dev->name, dev->flags, dev->mc_count);
1447 if(dev->flags & IFF_PROMISC)
1450 * Enable promiscuous mode: receive all packets.
1452 if(!lp->promiscuous)
1454 lp->promiscuous = 1;
1455 lp->allmulticast = 0;
1458 wv_82593_reconfig(dev);
1460 /* Tell the kernel that we are doing a really bad job... */
1461 dev->flags |= IFF_PROMISC;
1465 /* If all multicast addresses
1466 * or too much multicast addresses for the hardware filter */
1467 if((dev->flags & IFF_ALLMULTI) ||
1468 (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
1471 * Disable promiscuous mode, but active the all multicast mode
1473 if(!lp->allmulticast)
1475 lp->promiscuous = 0;
1476 lp->allmulticast = 1;
1479 wv_82593_reconfig(dev);
1481 /* Tell the kernel that we are doing a really bad job... */
1482 dev->flags |= IFF_ALLMULTI;
1486 /* If there is some multicast addresses to send */
1487 if(dev->mc_list != (struct dev_mc_list *) NULL)
1490 * Disable promiscuous mode, but receive all packets
1493 #ifdef MULTICAST_AVOID
1494 if(lp->promiscuous || lp->allmulticast ||
1495 (dev->mc_count != lp->mc_count))
1498 lp->promiscuous = 0;
1499 lp->allmulticast = 0;
1500 lp->mc_count = dev->mc_count;
1502 wv_82593_reconfig(dev);
1508 * Switch to normal mode: disable promiscuous mode and
1509 * clear the multicast list.
1511 if(lp->promiscuous || lp->mc_count == 0)
1513 lp->promiscuous = 0;
1514 lp->allmulticast = 0;
1517 wv_82593_reconfig(dev);
1520 #ifdef DEBUG_IOCTL_TRACE
1521 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
1525 /*------------------------------------------------------------------*/
1527 * This function doesn't exist...
1528 * (Note : it was a nice way to test the reconfigure stuff...)
1530 #ifdef SET_MAC_ADDRESS
1532 wavelan_set_mac_address(struct net_device * dev,
1535 struct sockaddr * mac = addr;
1537 /* Copy the address */
1538 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1540 /* Reconfig the beast */
1541 wv_82593_reconfig(dev);
1545 #endif /* SET_MAC_ADDRESS */
1547 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1549 /*------------------------------------------------------------------*/
1551 * Frequency setting (for hardware able of it)
1552 * It's a bit complicated and you don't really want to look into it...
1555 wv_set_frequency(u_long base, /* i/o port of the card */
1556 iw_freq * frequency)
1558 const int BAND_NUM = 10; /* Number of bands */
1559 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1560 #ifdef DEBUG_IOCTL_INFO
1564 /* Setting by frequency */
1565 /* Theoritically, you may set any frequency between
1566 * the two limits with a 0.5 MHz precision. In practice,
1567 * I don't want you to have trouble with local
1569 if((frequency->e == 1) &&
1570 (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
1572 freq = ((frequency->m / 10000) - 24000L) / 5;
1575 /* Setting by channel (same as wfreqsel) */
1576 /* Warning : each channel is 22MHz wide, so some of the channels
1577 * will interfere... */
1578 if((frequency->e == 0) &&
1579 (frequency->m >= 0) && (frequency->m < BAND_NUM))
1581 /* Get frequency offset. */
1582 freq = channel_bands[frequency->m] >> 1;
1585 /* Verify if the frequency is allowed */
1588 u_short table[10]; /* Authorized frequency table */
1590 /* Read the frequency table */
1591 fee_read(base, 0x71 /* frequency table */,
1594 #ifdef DEBUG_IOCTL_INFO
1595 printk(KERN_DEBUG "Frequency table :");
1596 for(i = 0; i < 10; i++)
1604 /* Look in the table if the frequency is allowed */
1605 if(!(table[9 - ((freq - 24) / 16)] &
1606 (1 << ((freq - 24) % 16))))
1607 return -EINVAL; /* not allowed */
1612 /* If we get a usable frequency */
1615 unsigned short area[16];
1616 unsigned short dac[2];
1617 unsigned short area_verify[16];
1618 unsigned short dac_verify[2];
1619 /* Corresponding gain (in the power adjust value table)
1620 * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
1621 * & WCIN062D.DOC, page 6.2.9 */
1622 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1623 int power_band = 0; /* Selected band */
1624 unsigned short power_adjust; /* Correct value */
1626 /* Search for the gain */
1628 while((freq > power_limit[power_band]) &&
1629 (power_limit[++power_band] != 0))
1632 /* Read the first area */
1633 fee_read(base, 0x00,
1637 fee_read(base, 0x60,
1640 /* Read the new power adjust value */
1641 fee_read(base, 0x6B - (power_band >> 1),
1643 if(power_band & 0x1)
1646 power_adjust &= 0xFF;
1648 #ifdef DEBUG_IOCTL_INFO
1649 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1650 for(i = 0; i < 16; i++)
1657 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1661 /* Frequency offset (for info only...) */
1662 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1664 /* Receiver Principle main divider coefficient */
1665 area[3] = (freq >> 1) + 2400L - 352L;
1666 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1668 /* Transmitter Main divider coefficient */
1669 area[13] = (freq >> 1) + 2400L;
1670 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1672 /* Others part of the area are flags, bit streams or unused... */
1674 /* Set the value in the DAC */
1675 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1676 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1678 /* Write the first area */
1679 fee_write(base, 0x00,
1683 fee_write(base, 0x60,
1686 /* We now should verify here that the EEprom writting was ok */
1688 /* ReRead the first area */
1689 fee_read(base, 0x00,
1692 /* ReRead the DAC */
1693 fee_read(base, 0x60,
1697 if(memcmp(area, area_verify, 16 * 2) ||
1698 memcmp(dac, dac_verify, 2 * 2))
1700 #ifdef DEBUG_IOCTL_ERROR
1701 printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
1706 /* We must download the frequency parameters to the
1707 * synthetisers (from the EEprom - area 1)
1708 * Note : as the EEprom is auto decremented, we set the end
1710 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
1711 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1712 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1714 /* Wait until the download is finished */
1715 fee_wait(base, 100, 100);
1717 /* We must now download the power adjust value (gain) to
1718 * the synthetisers (from the EEprom - area 7 - DAC) */
1719 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
1720 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1721 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1723 /* Wait until the download is finished */
1724 fee_wait(base, 100, 100);
1726 #ifdef DEBUG_IOCTL_INFO
1727 /* Verification of what we have done... */
1729 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1730 for(i = 0; i < 16; i++)
1737 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1738 dac_verify[0], dac_verify[1]);
1744 return -EINVAL; /* Bah, never get there... */
1747 /*------------------------------------------------------------------*/
1749 * Give the list of available frequencies
1752 wv_frequency_list(u_long base, /* i/o port of the card */
1753 iw_freq * list, /* List of frequency to fill */
1754 int max) /* Maximum number of frequencies */
1756 u_short table[10]; /* Authorized frequency table */
1757 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1758 int i; /* index in the table */
1759 const int BAND_NUM = 10; /* Number of bands */
1760 int c = 0; /* Channel number */
1762 /* Read the frequency table */
1763 fee_read(base, 0x71 /* frequency table */,
1766 /* Look all frequencies */
1768 for(freq = 0; freq < 150; freq++)
1769 /* Look in the table if the frequency is allowed */
1770 if(table[9 - (freq / 16)] & (1 << (freq % 16)))
1772 /* Compute approximate channel number */
1773 while((((channel_bands[c] >> 1) - 24) < freq) &&
1776 list[i].i = c; /* Set the list index */
1778 /* put in the list */
1779 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1790 #ifdef IW_WIRELESS_SPY
1791 /*------------------------------------------------------------------*/
1793 * Gather wireless spy statistics : for each packet, compare the source
1794 * address with out list, and if match, get the stats...
1795 * Sorry, but this function really need wireless extensions...
1798 wl_spy_gather(struct net_device * dev,
1799 u_char * mac, /* MAC address */
1800 u_char * stats) /* Statistics to gather */
1802 struct iw_quality wstats;
1804 wstats.qual = stats[2] & MMR_SGNL_QUAL;
1805 wstats.level = stats[0] & MMR_SIGNAL_LVL;
1806 wstats.noise = stats[1] & MMR_SILENCE_LVL;
1807 wstats.updated = 0x7;
1809 /* Update spy records */
1810 wireless_spy_update(dev, mac, &wstats);
1812 #endif /* IW_WIRELESS_SPY */
1815 /*------------------------------------------------------------------*/
1817 * This function calculate an histogram on the signal level.
1818 * As the noise is quite constant, it's like doing it on the SNR.
1819 * We have defined a set of interval (lp->his_range), and each time
1820 * the level goes in that interval, we increment the count (lp->his_sum).
1821 * With this histogram you may detect if one wavelan is really weak,
1822 * or you may also calculate the mean and standard deviation of the level...
1825 wl_his_gather(struct net_device * dev,
1826 u_char * stats) /* Statistics to gather */
1828 net_local * lp = netdev_priv(dev);
1829 u_char level = stats[0] & MMR_SIGNAL_LVL;
1832 /* Find the correct interval */
1834 while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
1837 /* Increment interval counter */
1840 #endif /* HISTOGRAM */
1842 static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1844 strncpy(info->driver, "wavelan_cs", sizeof(info->driver)-1);
1847 static struct ethtool_ops ops = {
1848 .get_drvinfo = wl_get_drvinfo
1851 /*------------------------------------------------------------------*/
1853 * Wireless Handler : get protocol name
1855 static int wavelan_get_name(struct net_device *dev,
1856 struct iw_request_info *info,
1857 union iwreq_data *wrqu,
1860 strcpy(wrqu->name, "WaveLAN");
1864 /*------------------------------------------------------------------*/
1866 * Wireless Handler : set NWID
1868 static int wavelan_set_nwid(struct net_device *dev,
1869 struct iw_request_info *info,
1870 union iwreq_data *wrqu,
1873 kio_addr_t base = dev->base_addr;
1874 net_local *lp = netdev_priv(dev);
1877 unsigned long flags;
1880 /* Disable interrupts and save flags. */
1881 spin_lock_irqsave(&lp->spinlock, flags);
1883 /* Set NWID in WaveLAN. */
1884 if (!wrqu->nwid.disabled) {
1885 /* Set NWID in psa */
1886 psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
1887 psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
1888 psa.psa_nwid_select = 0x01;
1890 (char *) psa.psa_nwid - (char *) &psa,
1891 (unsigned char *) psa.psa_nwid, 3);
1893 /* Set NWID in mmc. */
1894 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1895 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1897 (char *) &m.w.mmw_netw_id_l -
1899 (unsigned char *) &m.w.mmw_netw_id_l, 2);
1900 mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
1902 /* Disable NWID in the psa. */
1903 psa.psa_nwid_select = 0x00;
1905 (char *) &psa.psa_nwid_select -
1907 (unsigned char *) &psa.psa_nwid_select,
1910 /* Disable NWID in the mmc (no filtering). */
1911 mmc_out(base, mmwoff(0, mmw_loopt_sel),
1912 MMW_LOOPT_SEL_DIS_NWID);
1914 /* update the Wavelan checksum */
1915 update_psa_checksum(dev);
1917 /* Enable interrupts and restore flags. */
1918 spin_unlock_irqrestore(&lp->spinlock, flags);
1923 /*------------------------------------------------------------------*/
1925 * Wireless Handler : get NWID
1927 static int wavelan_get_nwid(struct net_device *dev,
1928 struct iw_request_info *info,
1929 union iwreq_data *wrqu,
1932 net_local *lp = netdev_priv(dev);
1934 unsigned long flags;
1937 /* Disable interrupts and save flags. */
1938 spin_lock_irqsave(&lp->spinlock, flags);
1940 /* Read the NWID. */
1942 (char *) psa.psa_nwid - (char *) &psa,
1943 (unsigned char *) psa.psa_nwid, 3);
1944 wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1945 wrqu->nwid.disabled = !(psa.psa_nwid_select);
1946 wrqu->nwid.fixed = 1; /* Superfluous */
1948 /* Enable interrupts and restore flags. */
1949 spin_unlock_irqrestore(&lp->spinlock, flags);
1954 /*------------------------------------------------------------------*/
1956 * Wireless Handler : set frequency
1958 static int wavelan_set_freq(struct net_device *dev,
1959 struct iw_request_info *info,
1960 union iwreq_data *wrqu,
1963 kio_addr_t base = dev->base_addr;
1964 net_local *lp = netdev_priv(dev);
1965 unsigned long flags;
1968 /* Disable interrupts and save flags. */
1969 spin_lock_irqsave(&lp->spinlock, flags);
1971 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1972 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1973 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1974 ret = wv_set_frequency(base, &(wrqu->freq));
1978 /* Enable interrupts and restore flags. */
1979 spin_unlock_irqrestore(&lp->spinlock, flags);
1984 /*------------------------------------------------------------------*/
1986 * Wireless Handler : get frequency
1988 static int wavelan_get_freq(struct net_device *dev,
1989 struct iw_request_info *info,
1990 union iwreq_data *wrqu,
1993 kio_addr_t base = dev->base_addr;
1994 net_local *lp = netdev_priv(dev);
1996 unsigned long flags;
1999 /* Disable interrupts and save flags. */
2000 spin_lock_irqsave(&lp->spinlock, flags);
2002 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
2003 * Does it work for everybody, especially old cards? */
2004 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2005 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2006 unsigned short freq;
2008 /* Ask the EEPROM to read the frequency from the first area. */
2009 fee_read(base, 0x00, &freq, 1);
2010 wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
2014 (char *) &psa.psa_subband - (char *) &psa,
2015 (unsigned char *) &psa.psa_subband, 1);
2017 if (psa.psa_subband <= 4) {
2018 wrqu->freq.m = fixed_bands[psa.psa_subband];
2019 wrqu->freq.e = (psa.psa_subband != 0);
2024 /* Enable interrupts and restore flags. */
2025 spin_unlock_irqrestore(&lp->spinlock, flags);
2030 /*------------------------------------------------------------------*/
2032 * Wireless Handler : set level threshold
2034 static int wavelan_set_sens(struct net_device *dev,
2035 struct iw_request_info *info,
2036 union iwreq_data *wrqu,
2039 kio_addr_t base = dev->base_addr;
2040 net_local *lp = netdev_priv(dev);
2042 unsigned long flags;
2045 /* Disable interrupts and save flags. */
2046 spin_lock_irqsave(&lp->spinlock, flags);
2048 /* Set the level threshold. */
2049 /* We should complain loudly if wrqu->sens.fixed = 0, because we
2050 * can't set auto mode... */
2051 psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
2053 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2054 (unsigned char *) &psa.psa_thr_pre_set, 1);
2055 /* update the Wavelan checksum */
2056 update_psa_checksum(dev);
2057 mmc_out(base, mmwoff(0, mmw_thr_pre_set),
2058 psa.psa_thr_pre_set);
2060 /* Enable interrupts and restore flags. */
2061 spin_unlock_irqrestore(&lp->spinlock, flags);
2066 /*------------------------------------------------------------------*/
2068 * Wireless Handler : get level threshold
2070 static int wavelan_get_sens(struct net_device *dev,
2071 struct iw_request_info *info,
2072 union iwreq_data *wrqu,
2075 net_local *lp = netdev_priv(dev);
2077 unsigned long flags;
2080 /* Disable interrupts and save flags. */
2081 spin_lock_irqsave(&lp->spinlock, flags);
2083 /* Read the level threshold. */
2085 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2086 (unsigned char *) &psa.psa_thr_pre_set, 1);
2087 wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
2088 wrqu->sens.fixed = 1;
2090 /* Enable interrupts and restore flags. */
2091 spin_unlock_irqrestore(&lp->spinlock, flags);
2096 /*------------------------------------------------------------------*/
2098 * Wireless Handler : set encryption key
2100 static int wavelan_set_encode(struct net_device *dev,
2101 struct iw_request_info *info,
2102 union iwreq_data *wrqu,
2105 kio_addr_t base = dev->base_addr;
2106 net_local *lp = netdev_priv(dev);
2107 unsigned long flags;
2111 /* Disable interrupts and save flags. */
2112 spin_lock_irqsave(&lp->spinlock, flags);
2114 /* Check if capable of encryption */
2115 if (!mmc_encr(base)) {
2119 /* Check the size of the key */
2120 if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
2125 /* Basic checking... */
2126 if (wrqu->encoding.length == 8) {
2127 /* Copy the key in the driver */
2128 memcpy(psa.psa_encryption_key, extra,
2129 wrqu->encoding.length);
2130 psa.psa_encryption_select = 1;
2133 (char *) &psa.psa_encryption_select -
2135 (unsigned char *) &psa.
2136 psa_encryption_select, 8 + 1);
2138 mmc_out(base, mmwoff(0, mmw_encr_enable),
2139 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2140 mmc_write(base, mmwoff(0, mmw_encr_key),
2141 (unsigned char *) &psa.
2142 psa_encryption_key, 8);
2145 /* disable encryption */
2146 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
2147 psa.psa_encryption_select = 0;
2149 (char *) &psa.psa_encryption_select -
2151 (unsigned char *) &psa.
2152 psa_encryption_select, 1);
2154 mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
2156 /* update the Wavelan checksum */
2157 update_psa_checksum(dev);
2160 /* Enable interrupts and restore flags. */
2161 spin_unlock_irqrestore(&lp->spinlock, flags);
2166 /*------------------------------------------------------------------*/
2168 * Wireless Handler : get encryption key
2170 static int wavelan_get_encode(struct net_device *dev,
2171 struct iw_request_info *info,
2172 union iwreq_data *wrqu,
2175 kio_addr_t base = dev->base_addr;
2176 net_local *lp = netdev_priv(dev);
2178 unsigned long flags;
2181 /* Disable interrupts and save flags. */
2182 spin_lock_irqsave(&lp->spinlock, flags);
2184 /* Check if encryption is available */
2185 if (!mmc_encr(base)) {
2188 /* Read the encryption key */
2190 (char *) &psa.psa_encryption_select -
2192 (unsigned char *) &psa.
2193 psa_encryption_select, 1 + 8);
2195 /* encryption is enabled ? */
2196 if (psa.psa_encryption_select)
2197 wrqu->encoding.flags = IW_ENCODE_ENABLED;
2199 wrqu->encoding.flags = IW_ENCODE_DISABLED;
2200 wrqu->encoding.flags |= mmc_encr(base);
2202 /* Copy the key to the user buffer */
2203 wrqu->encoding.length = 8;
2204 memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
2207 /* Enable interrupts and restore flags. */
2208 spin_unlock_irqrestore(&lp->spinlock, flags);
2213 #ifdef WAVELAN_ROAMING_EXT
2214 /*------------------------------------------------------------------*/
2216 * Wireless Handler : set ESSID (domain)
2218 static int wavelan_set_essid(struct net_device *dev,
2219 struct iw_request_info *info,
2220 union iwreq_data *wrqu,
2223 net_local *lp = netdev_priv(dev);
2224 unsigned long flags;
2227 /* Disable interrupts and save flags. */
2228 spin_lock_irqsave(&lp->spinlock, flags);
2230 /* Check if disable */
2231 if(wrqu->data.flags == 0)
2232 lp->filter_domains = 0;
2234 char essid[IW_ESSID_MAX_SIZE + 1];
2237 /* Terminate the string */
2238 memcpy(essid, extra, wrqu->data.length);
2239 essid[IW_ESSID_MAX_SIZE] = '\0';
2241 #ifdef DEBUG_IOCTL_INFO
2242 printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
2243 #endif /* DEBUG_IOCTL_INFO */
2245 /* Convert to a number (note : Wavelan specific) */
2246 lp->domain_id = simple_strtoul(essid, &endp, 16);
2247 /* Has it worked ? */
2249 lp->filter_domains = 1;
2251 lp->filter_domains = 0;
2256 /* Enable interrupts and restore flags. */
2257 spin_unlock_irqrestore(&lp->spinlock, flags);
2262 /*------------------------------------------------------------------*/
2264 * Wireless Handler : get ESSID (domain)
2266 static int wavelan_get_essid(struct net_device *dev,
2267 struct iw_request_info *info,
2268 union iwreq_data *wrqu,
2271 net_local *lp = netdev_priv(dev);
2273 /* Is the domain ID active ? */
2274 wrqu->data.flags = lp->filter_domains;
2276 /* Copy Domain ID into a string (Wavelan specific) */
2277 /* Sound crazy, be we can't have a snprintf in the kernel !!! */
2278 sprintf(extra, "%lX", lp->domain_id);
2279 extra[IW_ESSID_MAX_SIZE] = '\0';
2281 /* Set the length */
2282 wrqu->data.length = strlen(extra) + 1;
2287 /*------------------------------------------------------------------*/
2289 * Wireless Handler : set AP address
2291 static int wavelan_set_wap(struct net_device *dev,
2292 struct iw_request_info *info,
2293 union iwreq_data *wrqu,
2296 #ifdef DEBUG_IOCTL_INFO
2297 printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
2298 wrqu->ap_addr.sa_data[0],
2299 wrqu->ap_addr.sa_data[1],
2300 wrqu->ap_addr.sa_data[2],
2301 wrqu->ap_addr.sa_data[3],
2302 wrqu->ap_addr.sa_data[4],
2303 wrqu->ap_addr.sa_data[5]);
2304 #endif /* DEBUG_IOCTL_INFO */
2309 /*------------------------------------------------------------------*/
2311 * Wireless Handler : get AP address
2313 static int wavelan_get_wap(struct net_device *dev,
2314 struct iw_request_info *info,
2315 union iwreq_data *wrqu,
2318 /* Should get the real McCoy instead of own Ethernet address */
2319 memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
2320 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
2324 #endif /* WAVELAN_ROAMING_EXT */
2326 #ifdef WAVELAN_ROAMING
2327 /*------------------------------------------------------------------*/
2329 * Wireless Handler : set mode
2331 static int wavelan_set_mode(struct net_device *dev,
2332 struct iw_request_info *info,
2333 union iwreq_data *wrqu,
2336 net_local *lp = netdev_priv(dev);
2337 unsigned long flags;
2340 /* Disable interrupts and save flags. */
2341 spin_lock_irqsave(&lp->spinlock, flags);
2344 switch(wrqu->mode) {
2347 wv_roam_cleanup(dev);
2361 /* Enable interrupts and restore flags. */
2362 spin_unlock_irqrestore(&lp->spinlock, flags);
2367 /*------------------------------------------------------------------*/
2369 * Wireless Handler : get mode
2371 static int wavelan_get_mode(struct net_device *dev,
2372 struct iw_request_info *info,
2373 union iwreq_data *wrqu,
2377 wrqu->mode = IW_MODE_INFRA;
2379 wrqu->mode = IW_MODE_ADHOC;
2383 #endif /* WAVELAN_ROAMING */
2385 /*------------------------------------------------------------------*/
2387 * Wireless Handler : get range info
2389 static int wavelan_get_range(struct net_device *dev,
2390 struct iw_request_info *info,
2391 union iwreq_data *wrqu,
2394 kio_addr_t base = dev->base_addr;
2395 net_local *lp = netdev_priv(dev);
2396 struct iw_range *range = (struct iw_range *) extra;
2397 unsigned long flags;
2400 /* Set the length (very important for backward compatibility) */
2401 wrqu->data.length = sizeof(struct iw_range);
2403 /* Set all the info we don't care or don't know about to zero */
2404 memset(range, 0, sizeof(struct iw_range));
2406 /* Set the Wireless Extension versions */
2407 range->we_version_compiled = WIRELESS_EXT;
2408 range->we_version_source = 9;
2410 /* Set information in the range struct. */
2411 range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
2412 range->min_nwid = 0x0000;
2413 range->max_nwid = 0xFFFF;
2415 range->sensitivity = 0x3F;
2416 range->max_qual.qual = MMR_SGNL_QUAL;
2417 range->max_qual.level = MMR_SIGNAL_LVL;
2418 range->max_qual.noise = MMR_SILENCE_LVL;
2419 range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
2420 /* Need to get better values for those two */
2421 range->avg_qual.level = 30;
2422 range->avg_qual.noise = 8;
2424 range->num_bitrates = 1;
2425 range->bitrate[0] = 2000000; /* 2 Mb/s */
2427 /* Event capability (kernel + driver) */
2428 range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
2429 IW_EVENT_CAPA_MASK(0x8B04) |
2430 IW_EVENT_CAPA_MASK(0x8B06));
2431 range->event_capa[1] = IW_EVENT_CAPA_K_1;
2433 /* Disable interrupts and save flags. */
2434 spin_lock_irqsave(&lp->spinlock, flags);
2436 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2437 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2438 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2439 range->num_channels = 10;
2440 range->num_frequency = wv_frequency_list(base, range->freq,
2441 IW_MAX_FREQUENCIES);
2443 range->num_channels = range->num_frequency = 0;
2445 /* Encryption supported ? */
2446 if (mmc_encr(base)) {
2447 range->encoding_size[0] = 8; /* DES = 64 bits key */
2448 range->num_encoding_sizes = 1;
2449 range->max_encoding_tokens = 1; /* Only one key possible */
2451 range->num_encoding_sizes = 0;
2452 range->max_encoding_tokens = 0;
2455 /* Enable interrupts and restore flags. */
2456 spin_unlock_irqrestore(&lp->spinlock, flags);
2461 /*------------------------------------------------------------------*/
2463 * Wireless Private Handler : set quality threshold
2465 static int wavelan_set_qthr(struct net_device *dev,
2466 struct iw_request_info *info,
2467 union iwreq_data *wrqu,
2470 kio_addr_t base = dev->base_addr;
2471 net_local *lp = netdev_priv(dev);
2473 unsigned long flags;
2475 /* Disable interrupts and save flags. */
2476 spin_lock_irqsave(&lp->spinlock, flags);
2478 psa.psa_quality_thr = *(extra) & 0x0F;
2480 (char *) &psa.psa_quality_thr - (char *) &psa,
2481 (unsigned char *) &psa.psa_quality_thr, 1);
2482 /* update the Wavelan checksum */
2483 update_psa_checksum(dev);
2484 mmc_out(base, mmwoff(0, mmw_quality_thr),
2485 psa.psa_quality_thr);
2487 /* Enable interrupts and restore flags. */
2488 spin_unlock_irqrestore(&lp->spinlock, flags);
2493 /*------------------------------------------------------------------*/
2495 * Wireless Private Handler : get quality threshold
2497 static int wavelan_get_qthr(struct net_device *dev,
2498 struct iw_request_info *info,
2499 union iwreq_data *wrqu,
2502 net_local *lp = netdev_priv(dev);
2504 unsigned long flags;
2506 /* Disable interrupts and save flags. */
2507 spin_lock_irqsave(&lp->spinlock, flags);
2510 (char *) &psa.psa_quality_thr - (char *) &psa,
2511 (unsigned char *) &psa.psa_quality_thr, 1);
2512 *(extra) = psa.psa_quality_thr & 0x0F;
2514 /* Enable interrupts and restore flags. */
2515 spin_unlock_irqrestore(&lp->spinlock, flags);
2520 #ifdef WAVELAN_ROAMING
2521 /*------------------------------------------------------------------*/
2523 * Wireless Private Handler : set roaming
2525 static int wavelan_set_roam(struct net_device *dev,
2526 struct iw_request_info *info,
2527 union iwreq_data *wrqu,
2530 net_local *lp = netdev_priv(dev);
2531 unsigned long flags;
2533 /* Disable interrupts and save flags. */
2534 spin_lock_irqsave(&lp->spinlock, flags);
2536 /* Note : should check if user == root */
2537 if(do_roaming && (*extra)==0)
2538 wv_roam_cleanup(dev);
2539 else if(do_roaming==0 && (*extra)!=0)
2542 do_roaming = (*extra);
2544 /* Enable interrupts and restore flags. */
2545 spin_unlock_irqrestore(&lp->spinlock, flags);
2550 /*------------------------------------------------------------------*/
2552 * Wireless Private Handler : get quality threshold
2554 static int wavelan_get_roam(struct net_device *dev,
2555 struct iw_request_info *info,
2556 union iwreq_data *wrqu,
2559 *(extra) = do_roaming;
2563 #endif /* WAVELAN_ROAMING */
2566 /*------------------------------------------------------------------*/
2568 * Wireless Private Handler : set histogram
2570 static int wavelan_set_histo(struct net_device *dev,
2571 struct iw_request_info *info,
2572 union iwreq_data *wrqu,
2575 net_local *lp = netdev_priv(dev);
2577 /* Check the number of intervals. */
2578 if (wrqu->data.length > 16) {
2582 /* Disable histo while we copy the addresses.
2583 * As we don't disable interrupts, we need to do this */
2586 /* Are there ranges to copy? */
2587 if (wrqu->data.length > 0) {
2588 /* Copy interval ranges to the driver */
2589 memcpy(lp->his_range, extra, wrqu->data.length);
2593 printk(KERN_DEBUG "Histo :");
2594 for(i = 0; i < wrqu->data.length; i++)
2595 printk(" %d", lp->his_range[i]);
2599 /* Reset result structure. */
2600 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2603 /* Now we can set the number of ranges */
2604 lp->his_number = wrqu->data.length;
2609 /*------------------------------------------------------------------*/
2611 * Wireless Private Handler : get histogram
2613 static int wavelan_get_histo(struct net_device *dev,
2614 struct iw_request_info *info,
2615 union iwreq_data *wrqu,
2618 net_local *lp = netdev_priv(dev);
2620 /* Set the number of intervals. */
2621 wrqu->data.length = lp->his_number;
2623 /* Give back the distribution statistics */
2624 if(lp->his_number > 0)
2625 memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
2629 #endif /* HISTOGRAM */
2631 /*------------------------------------------------------------------*/
2633 * Structures to export the Wireless Handlers
2636 static const struct iw_priv_args wavelan_private_args[] = {
2637 /*{ cmd, set_args, get_args, name } */
2638 { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2639 { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2640 { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" },
2641 { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
2642 { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
2643 { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
2646 static const iw_handler wavelan_handler[] =
2648 NULL, /* SIOCSIWNAME */
2649 wavelan_get_name, /* SIOCGIWNAME */
2650 wavelan_set_nwid, /* SIOCSIWNWID */
2651 wavelan_get_nwid, /* SIOCGIWNWID */
2652 wavelan_set_freq, /* SIOCSIWFREQ */
2653 wavelan_get_freq, /* SIOCGIWFREQ */
2654 #ifdef WAVELAN_ROAMING
2655 wavelan_set_mode, /* SIOCSIWMODE */
2656 wavelan_get_mode, /* SIOCGIWMODE */
2657 #else /* WAVELAN_ROAMING */
2658 NULL, /* SIOCSIWMODE */
2659 NULL, /* SIOCGIWMODE */
2660 #endif /* WAVELAN_ROAMING */
2661 wavelan_set_sens, /* SIOCSIWSENS */
2662 wavelan_get_sens, /* SIOCGIWSENS */
2663 NULL, /* SIOCSIWRANGE */
2664 wavelan_get_range, /* SIOCGIWRANGE */
2665 NULL, /* SIOCSIWPRIV */
2666 NULL, /* SIOCGIWPRIV */
2667 NULL, /* SIOCSIWSTATS */
2668 NULL, /* SIOCGIWSTATS */
2669 iw_handler_set_spy, /* SIOCSIWSPY */
2670 iw_handler_get_spy, /* SIOCGIWSPY */
2671 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2672 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2673 #ifdef WAVELAN_ROAMING_EXT
2674 wavelan_set_wap, /* SIOCSIWAP */
2675 wavelan_get_wap, /* SIOCGIWAP */
2676 NULL, /* -- hole -- */
2677 NULL, /* SIOCGIWAPLIST */
2678 NULL, /* -- hole -- */
2679 NULL, /* -- hole -- */
2680 wavelan_set_essid, /* SIOCSIWESSID */
2681 wavelan_get_essid, /* SIOCGIWESSID */
2682 #else /* WAVELAN_ROAMING_EXT */
2683 NULL, /* SIOCSIWAP */
2684 NULL, /* SIOCGIWAP */
2685 NULL, /* -- hole -- */
2686 NULL, /* SIOCGIWAPLIST */
2687 NULL, /* -- hole -- */
2688 NULL, /* -- hole -- */
2689 NULL, /* SIOCSIWESSID */
2690 NULL, /* SIOCGIWESSID */
2691 #endif /* WAVELAN_ROAMING_EXT */
2692 NULL, /* SIOCSIWNICKN */
2693 NULL, /* SIOCGIWNICKN */
2694 NULL, /* -- hole -- */
2695 NULL, /* -- hole -- */
2696 NULL, /* SIOCSIWRATE */
2697 NULL, /* SIOCGIWRATE */
2698 NULL, /* SIOCSIWRTS */
2699 NULL, /* SIOCGIWRTS */
2700 NULL, /* SIOCSIWFRAG */
2701 NULL, /* SIOCGIWFRAG */
2702 NULL, /* SIOCSIWTXPOW */
2703 NULL, /* SIOCGIWTXPOW */
2704 NULL, /* SIOCSIWRETRY */
2705 NULL, /* SIOCGIWRETRY */
2706 wavelan_set_encode, /* SIOCSIWENCODE */
2707 wavelan_get_encode, /* SIOCGIWENCODE */
2710 static const iw_handler wavelan_private_handler[] =
2712 wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
2713 wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
2714 #ifdef WAVELAN_ROAMING
2715 wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */
2716 wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */
2717 #else /* WAVELAN_ROAMING */
2718 NULL, /* SIOCIWFIRSTPRIV + 2 */
2719 NULL, /* SIOCIWFIRSTPRIV + 3 */
2720 #endif /* WAVELAN_ROAMING */
2722 wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */
2723 wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */
2724 #endif /* HISTOGRAM */
2727 static const struct iw_handler_def wavelan_handler_def =
2729 .num_standard = sizeof(wavelan_handler)/sizeof(iw_handler),
2730 .num_private = sizeof(wavelan_private_handler)/sizeof(iw_handler),
2731 .num_private_args = sizeof(wavelan_private_args)/sizeof(struct iw_priv_args),
2732 .standard = wavelan_handler,
2733 .private = wavelan_private_handler,
2734 .private_args = wavelan_private_args,
2735 .get_wireless_stats = wavelan_get_wireless_stats,
2738 /*------------------------------------------------------------------*/
2740 * Get wireless statistics
2741 * Called by /proc/net/wireless...
2744 wavelan_get_wireless_stats(struct net_device * dev)
2746 kio_addr_t base = dev->base_addr;
2747 net_local * lp = netdev_priv(dev);
2750 unsigned long flags;
2752 #ifdef DEBUG_IOCTL_TRACE
2753 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
2756 /* Disable interrupts & save flags */
2757 spin_lock_irqsave(&lp->spinlock, flags);
2759 wstats = &lp->wstats;
2761 /* Get data from the mmc */
2762 mmc_out(base, mmwoff(0, mmw_freeze), 1);
2764 mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2765 mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
2766 mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
2768 mmc_out(base, mmwoff(0, mmw_freeze), 0);
2770 /* Copy data to wireless stuff */
2771 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2772 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2773 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2774 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2775 wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
2776 ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
2777 ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2778 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2779 wstats->discard.code = 0L;
2780 wstats->discard.misc = 0L;
2782 /* ReEnable interrupts & restore flags */
2783 spin_unlock_irqrestore(&lp->spinlock, flags);
2785 #ifdef DEBUG_IOCTL_TRACE
2786 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
2790 #endif /* WIRELESS_EXT */
2792 /************************* PACKET RECEPTION *************************/
2794 * This part deal with receiving the packets.
2795 * The interrupt handler get an interrupt when a packet has been
2796 * successfully received and called this part...
2799 /*------------------------------------------------------------------*/
2801 * Calculate the starting address of the frame pointed to by the receive
2802 * frame pointer and verify that the frame seem correct
2803 * (called by wv_packet_rcv())
2806 wv_start_of_frame(struct net_device * dev,
2807 int rfp, /* end of frame */
2808 int wrap) /* start of buffer */
2810 kio_addr_t base = dev->base_addr;
2814 rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
2815 outb(rp & 0xff, PIORL(base));
2816 outb(((rp >> 8) & PIORH_MASK), PIORH(base));
2817 len = inb(PIOP(base));
2818 len |= inb(PIOP(base)) << 8;
2820 /* Sanity checks on size */
2822 if(len > MAXDATAZ + 100)
2824 #ifdef DEBUG_RX_ERROR
2825 printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
2826 dev->name, rfp, len);
2831 /* Frame too short */
2834 #ifdef DEBUG_RX_ERROR
2835 printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
2836 dev->name, rfp, len);
2841 /* Wrap around buffer */
2842 if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
2844 #ifdef DEBUG_RX_ERROR
2845 printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
2846 dev->name, wrap, rfp, len);
2851 return((rp - len + RX_SIZE) % RX_SIZE);
2852 } /* wv_start_of_frame */
2854 /*------------------------------------------------------------------*/
2856 * This routine does the actual copy of data (including the ethernet
2857 * header structure) from the WaveLAN card to an sk_buff chain that
2858 * will be passed up to the network interface layer. NOTE: We
2859 * currently don't handle trailer protocols (neither does the rest of
2860 * the network interface), so if that is needed, it will (at least in
2861 * part) be added here. The contents of the receive ring buffer are
2862 * copied to a message chain that is then passed to the kernel.
2864 * Note: if any errors occur, the packet is "dropped on the floor"
2865 * (called by wv_packet_rcv())
2868 wv_packet_read(struct net_device * dev,
2872 net_local * lp = netdev_priv(dev);
2873 struct sk_buff * skb;
2875 #ifdef DEBUG_RX_TRACE
2876 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2877 dev->name, fd_p, sksize);
2880 /* Allocate some buffer for the new packet */
2881 if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
2883 #ifdef DEBUG_RX_ERROR
2884 printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
2887 lp->stats.rx_dropped++;
2889 * Not only do we want to return here, but we also need to drop the
2890 * packet on the floor to clear the interrupt.
2897 skb_reserve(skb, 2);
2898 fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
2899 skb->protocol = eth_type_trans(skb, dev);
2901 #ifdef DEBUG_RX_INFO
2902 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2903 #endif /* DEBUG_RX_INFO */
2905 /* Statistics gathering & stuff associated.
2906 * It seem a bit messy with all the define, but it's really simple... */
2908 #ifdef IW_WIRELESS_SPY
2909 (lp->spy_data.spy_number > 0) ||
2910 #endif /* IW_WIRELESS_SPY */
2912 (lp->his_number > 0) ||
2913 #endif /* HISTOGRAM */
2914 #ifdef WAVELAN_ROAMING
2916 #endif /* WAVELAN_ROAMING */
2919 u_char stats[3]; /* Signal level, Noise level, Signal quality */
2921 /* read signal level, silence level and signal quality bytes */
2922 fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
2924 #ifdef DEBUG_RX_INFO
2925 printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2926 dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
2929 #ifdef WAVELAN_ROAMING
2931 if(WAVELAN_BEACON(skb->data))
2932 wl_roam_gather(dev, skb->data, stats);
2933 #endif /* WAVELAN_ROAMING */
2936 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
2937 #endif /* WIRELESS_SPY */
2939 wl_his_gather(dev, stats);
2940 #endif /* HISTOGRAM */
2944 * Hand the packet to the Network Module
2948 /* Keep stats up to date */
2949 dev->last_rx = jiffies;
2950 lp->stats.rx_packets++;
2951 lp->stats.rx_bytes += sksize;
2953 #ifdef DEBUG_RX_TRACE
2954 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2959 /*------------------------------------------------------------------*/
2961 * This routine is called by the interrupt handler to initiate a
2962 * packet transfer from the card to the network interface layer above
2963 * this driver. This routine checks if a buffer has been successfully
2964 * received by the WaveLAN card. If so, the routine wv_packet_read is
2965 * called to do the actual transfer of the card's data including the
2966 * ethernet header into a packet consisting of an sk_buff chain.
2967 * (called by wavelan_interrupt())
2968 * Note : the spinlock is already grabbed for us and irq are disabled.
2971 wv_packet_rcv(struct net_device * dev)
2973 kio_addr_t base = dev->base_addr;
2974 net_local * lp = netdev_priv(dev);
2984 #ifdef DEBUG_RX_TRACE
2985 printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
2988 /* Get the new receive frame pointer from the i82593 chip */
2989 outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
2990 i593_rfp = inb(LCSR(base));
2991 i593_rfp |= inb(LCSR(base)) << 8;
2992 i593_rfp %= RX_SIZE;
2994 /* Get the new receive frame pointer from the WaveLAN card.
2995 * It is 3 bytes more than the increment of the i82593 receive
2996 * frame pointer, for each packet. This is because it includes the
2997 * 3 roaming bytes added by the mmc.
2999 newrfp = inb(RPLL(base));
3000 newrfp |= inb(RPLH(base)) << 8;
3003 #ifdef DEBUG_RX_INFO
3004 printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3005 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
3008 #ifdef DEBUG_RX_ERROR
3009 /* If no new frame pointer... */
3010 if(lp->overrunning || newrfp == lp->rfp)
3011 printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3012 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
3015 /* Read all frames (packets) received */
3016 while(newrfp != lp->rfp)
3018 /* A frame is composed of the packet, followed by a status word,
3019 * the length of the frame (word) and the mmc info (SNR & qual).
3020 * It's because the length is at the end that we can only scan
3021 * frames backward. */
3023 /* Find the first frame by skipping backwards over the frames */
3024 rp = newrfp; /* End of last frame */
3025 while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
3029 /* If we had a problem */
3032 #ifdef DEBUG_RX_ERROR
3033 printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
3034 printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3035 i593_rfp, lp->stop, newrfp, lp->rfp);
3037 lp->rfp = rp; /* Get to the last usable frame */
3041 /* f_start point to the beggining of the first frame received
3042 * and rp to the beggining of the next one */
3044 /* Read status & length of the frame */
3045 stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
3046 stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
3047 status = c[0] | (c[1] << 8);
3048 len = c[2] | (c[3] << 8);
3051 if((status & RX_RCV_OK) != RX_RCV_OK)
3053 lp->stats.rx_errors++;
3054 if(status & RX_NO_SFD)
3055 lp->stats.rx_frame_errors++;
3056 if(status & RX_CRC_ERR)
3057 lp->stats.rx_crc_errors++;
3058 if(status & RX_OVRRUN)
3059 lp->stats.rx_over_errors++;
3061 #ifdef DEBUG_RX_FAIL
3062 printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
3067 /* Read the packet and transmit to Linux */
3068 wv_packet_read(dev, f_start, len - 2);
3070 /* One frame has been processed, skip it */
3075 * Update the frame stop register, but set it to less than
3076 * the full 8K to allow space for 3 bytes of signal strength
3079 lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3080 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3081 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3082 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3084 #ifdef DEBUG_RX_TRACE
3085 printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
3089 /*********************** PACKET TRANSMISSION ***********************/
3091 * This part deal with sending packet through the wavelan
3092 * We copy the packet to the send buffer and then issue the send
3093 * command to the i82593. The result of this operation will be
3094 * checked in wavelan_interrupt()
3097 /*------------------------------------------------------------------*/
3099 * This routine fills in the appropriate registers and memory
3100 * locations on the WaveLAN card and starts the card off on
3102 * (called in wavelan_packet_xmit())
3105 wv_packet_write(struct net_device * dev,
3109 net_local * lp = netdev_priv(dev);
3110 kio_addr_t base = dev->base_addr;
3111 unsigned long flags;
3113 register u_short xmtdata_base = TX_BASE;
3115 #ifdef DEBUG_TX_TRACE
3116 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
3119 spin_lock_irqsave(&lp->spinlock, flags);
3121 /* Write the length of data buffer followed by the buffer */
3122 outb(xmtdata_base & 0xff, PIORL(base));
3123 outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3124 outb(clen & 0xff, PIOP(base)); /* lsb */
3125 outb(clen >> 8, PIOP(base)); /* msb */
3128 outsb(PIOP(base), buf, clen);
3130 /* Indicate end of transmit chain */
3131 outb(OP0_NOP, PIOP(base));
3132 /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
3133 outb(OP0_NOP, PIOP(base));
3135 /* Reset the transmit DMA pointer */
3136 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3137 hacr_write(base, HACR_DEFAULT);
3138 /* Send the transmit command */
3139 wv_82593_cmd(dev, "wv_packet_write(): transmit",
3140 OP0_TRANSMIT, SR0_NO_RESULT);
3142 /* Make sure the watchdog will keep quiet for a while */
3143 dev->trans_start = jiffies;
3145 /* Keep stats up to date */
3146 lp->stats.tx_bytes += length;
3148 spin_unlock_irqrestore(&lp->spinlock, flags);
3150 #ifdef DEBUG_TX_INFO
3151 wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
3152 #endif /* DEBUG_TX_INFO */
3154 #ifdef DEBUG_TX_TRACE
3155 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
3159 /*------------------------------------------------------------------*/
3161 * This routine is called when we want to send a packet (NET3 callback)
3162 * In this routine, we check if the harware is ready to accept
3163 * the packet. We also prevent reentrance. Then, we call the function
3164 * to send the packet...
3167 wavelan_packet_xmit(struct sk_buff * skb,
3168 struct net_device * dev)
3170 net_local * lp = netdev_priv(dev);
3171 unsigned long flags;
3173 #ifdef DEBUG_TX_TRACE
3174 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
3179 * Block a timer-based transmit from overlapping a previous transmit.
3180 * In other words, prevent reentering this routine.
3182 netif_stop_queue(dev);
3184 /* If somebody has asked to reconfigure the controller,
3185 * we can do it now */
3186 if(lp->reconfig_82593)
3188 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
3189 wv_82593_config(dev);
3190 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
3191 /* Note : the configure procedure was totally synchronous,
3192 * so the Tx buffer is now free */
3195 #ifdef DEBUG_TX_ERROR
3197 printk(KERN_INFO "skb has next\n");
3200 /* Check if we need some padding */
3201 /* Note : on wireless the propagation time is in the order of 1us,
3202 * and we don't have the Ethernet specific requirement of beeing
3203 * able to detect collisions, therefore in theory we don't really
3204 * need to pad. Jean II */
3205 if (skb->len < ETH_ZLEN) {
3206 skb = skb_padto(skb, ETH_ZLEN);
3211 wv_packet_write(dev, skb->data, skb->len);
3215 #ifdef DEBUG_TX_TRACE
3216 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
3221 /********************** HARDWARE CONFIGURATION **********************/
3223 * This part do the real job of starting and configuring the hardware.
3226 /*------------------------------------------------------------------*/
3228 * Routine to initialize the Modem Management Controller.
3229 * (called by wv_hw_config())
3232 wv_mmc_init(struct net_device * dev)
3234 kio_addr_t base = dev->base_addr;
3238 int i; /* Loop counter */
3240 #ifdef DEBUG_CONFIG_TRACE
3241 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
3244 /* Read the parameter storage area */
3245 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3248 * Check the first three octets of the MAC addr for the manufacturer's code.
3249 * Note: If you get the error message below, you've got a
3250 * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
3251 * how to configure your card...
3253 for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3254 if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
3255 (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
3256 (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
3259 /* If we have not found it... */
3260 if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
3262 #ifdef DEBUG_CONFIG_ERRORS
3263 printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
3264 dev->name, psa.psa_univ_mac_addr[0],
3265 psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
3270 /* Get the MAC address */
3271 memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
3273 #ifdef USE_PSA_CONFIG
3274 configured = psa.psa_conf_status & 1;
3279 /* Is the PSA is not configured */
3282 /* User will be able to configure NWID after (with iwconfig) */
3283 psa.psa_nwid[0] = 0;
3284 psa.psa_nwid[1] = 0;
3286 /* As NWID is not set : no NWID checking */
3287 psa.psa_nwid_select = 0;
3289 /* Disable encryption */
3290 psa.psa_encryption_select = 0;
3292 /* Set to standard values
3295 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
3297 if (psa.psa_comp_number & 1)
3298 psa.psa_thr_pre_set = 0x01;
3300 psa.psa_thr_pre_set = 0x04;
3301 psa.psa_quality_thr = 0x03;
3303 /* It is configured */
3304 psa.psa_conf_status |= 1;
3306 #ifdef USE_PSA_CONFIG
3308 psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
3309 (unsigned char *)psa.psa_nwid, 4);
3310 psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
3311 (unsigned char *)&psa.psa_thr_pre_set, 1);
3312 psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
3313 (unsigned char *)&psa.psa_quality_thr, 1);
3314 psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
3315 (unsigned char *)&psa.psa_conf_status, 1);
3316 /* update the Wavelan checksum */
3317 update_psa_checksum(dev);
3318 #endif /* USE_PSA_CONFIG */
3321 /* Zero the mmc structure */
3322 memset(&m, 0x00, sizeof(m));
3324 /* Copy PSA info to the mmc */
3325 m.mmw_netw_id_l = psa.psa_nwid[1];
3326 m.mmw_netw_id_h = psa.psa_nwid[0];
3328 if(psa.psa_nwid_select & 1)
3329 m.mmw_loopt_sel = 0x00;
3331 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
3333 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
3334 sizeof(m.mmw_encr_key));
3336 if(psa.psa_encryption_select)
3337 m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
3339 m.mmw_encr_enable = 0;
3341 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
3342 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
3345 * Set default modem control parameters.
3346 * See NCR document 407-0024326 Rev. A.
3348 m.mmw_jabber_enable = 0x01;
3349 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
3351 m.mmw_mod_delay = 0x04;
3352 m.mmw_jam_time = 0x38;
3354 m.mmw_des_io_invert = 0;
3356 m.mmw_decay_prm = 0;
3357 m.mmw_decay_updat_prm = 0;
3359 /* Write all info to mmc */
3360 mmc_write(base, 0, (u_char *)&m, sizeof(m));
3362 /* The following code start the modem of the 2.00 frequency
3363 * selectable cards at power on. It's not strictly needed for the
3364 * following boots...
3365 * The original patch was by Joe Finney for the PCMCIA driver, but
3366 * I've cleaned it a bit and add documentation.
3367 * Thanks to Loeke Brederveld from Lucent for the info.
3370 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3371 * (does it work for everybody ? - especially old cards...) */
3372 /* Note : WFREQSEL verify that it is able to read from EEprom
3373 * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
3374 * is 0xA (Xilinx version) or 0xB (Ariadne version).
3375 * My test is more crude but do work... */
3376 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
3377 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
3379 /* We must download the frequency parameters to the
3380 * synthetisers (from the EEprom - area 1)
3381 * Note : as the EEprom is auto decremented, we set the end
3383 m.mmw_fee_addr = 0x0F;
3384 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3385 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3386 (unsigned char *)&m.mmw_fee_ctrl, 2);
3388 /* Wait until the download is finished */
3389 fee_wait(base, 100, 100);
3391 #ifdef DEBUG_CONFIG_INFO
3392 /* The frequency was in the last word downloaded... */
3393 mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
3394 (unsigned char *)&m.mmw_fee_data_l, 2);
3396 /* Print some info for the user */
3397 printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
3399 ((m.mmw_fee_data_h << 4) |
3400 (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
3403 /* We must now download the power adjust value (gain) to
3404 * the synthetisers (from the EEprom - area 7 - DAC) */
3405 m.mmw_fee_addr = 0x61;
3406 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3407 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3408 (unsigned char *)&m.mmw_fee_ctrl, 2);
3410 /* Wait until the download is finished */
3411 } /* if 2.00 card */
3413 #ifdef DEBUG_CONFIG_TRACE
3414 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3419 /*------------------------------------------------------------------*/
3421 * Routine to gracefully turn off reception, and wait for any commands
3423 * (called in wv_ru_start() and wavelan_close() and wavelan_event())
3426 wv_ru_stop(struct net_device * dev)
3428 kio_addr_t base = dev->base_addr;
3429 net_local * lp = netdev_priv(dev);
3430 unsigned long flags;
3434 #ifdef DEBUG_CONFIG_TRACE
3435 printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
3438 spin_lock_irqsave(&lp->spinlock, flags);
3440 /* First, send the LAN controller a stop receive command */
3441 wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
3442 OP0_STOP_RCV, SR0_NO_RESULT);
3444 /* Then, spin until the receive unit goes idle */
3449 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3450 status = inb(LCSR(base));
3452 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
3454 /* Now, spin until the chip finishes executing its current command */
3458 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3459 status = inb(LCSR(base));
3461 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
3463 spin_unlock_irqrestore(&lp->spinlock, flags);
3465 /* If there was a problem */
3468 #ifdef DEBUG_CONFIG_ERRORS
3469 printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
3475 #ifdef DEBUG_CONFIG_TRACE
3476 printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
3481 /*------------------------------------------------------------------*/
3483 * This routine starts the receive unit running. First, it checks if
3484 * the card is actually ready. Then the card is instructed to receive
3486 * (called in wv_hw_reset() & wavelan_open())
3489 wv_ru_start(struct net_device * dev)
3491 kio_addr_t base = dev->base_addr;
3492 net_local * lp = netdev_priv(dev);
3493 unsigned long flags;
3495 #ifdef DEBUG_CONFIG_TRACE
3496 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3500 * We need to start from a quiescent state. To do so, we could check
3501 * if the card is already running, but instead we just try to shut
3502 * it down. First, we disable reception (in case it was already enabled).
3504 if(!wv_ru_stop(dev))
3507 spin_lock_irqsave(&lp->spinlock, flags);
3509 /* Now we know that no command is being executed. */
3511 /* Set the receive frame pointer and stop pointer */
3513 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3515 /* Reset ring management. This sets the receive frame pointer to 1 */
3516 outb(OP1_RESET_RING_MNGMT, LCCR(base));
3519 /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
3520 should be set as below */
3521 /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
3523 /* but I set it 0 instead */
3526 /* but I set it to 3 bytes per packet less than 8K */
3527 lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3529 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3530 outb(OP1_INT_ENABLE, LCCR(base));
3531 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3533 /* Reset receive DMA pointer */
3534 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3535 hacr_write_slow(base, HACR_DEFAULT);
3537 /* Receive DMA on channel 1 */
3538 wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
3539 CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
3541 #ifdef DEBUG_I82593_SHOW
3547 /* spin until the chip starts receiving */
3550 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3551 status = inb(LCSR(base));
3555 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
3556 ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
3557 printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
3558 (status & SR3_RCV_STATE_MASK), i);
3562 spin_unlock_irqrestore(&lp->spinlock, flags);
3564 #ifdef DEBUG_CONFIG_TRACE
3565 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3570 /*------------------------------------------------------------------*/
3572 * This routine does a standard config of the WaveLAN controller (i82593).
3573 * In the ISA driver, this is integrated in wavelan_hardware_reset()
3574 * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
3577 wv_82593_config(struct net_device * dev)
3579 kio_addr_t base = dev->base_addr;
3580 net_local * lp = netdev_priv(dev);
3581 struct i82593_conf_block cfblk;
3584 #ifdef DEBUG_CONFIG_TRACE
3585 printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
3588 /* Create & fill i82593 config block
3590 * Now conform to Wavelan document WCIN085B
3592 memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
3593 cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
3594 cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
3595 cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
3597 cfblk.throttle_enb = FALSE;
3598 cfblk.contin = TRUE; /* enable continuous mode */
3599 cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
3600 cfblk.addr_len = WAVELAN_ADDR_SIZE;
3601 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
3602 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
3603 cfblk.loopback = FALSE;
3604 cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */
3605 cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */
3606 cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */
3607 cfblk.ifrm_spc = 0x20; /* 32 bit times interframe spacing */
3608 cfblk.slottim_low = 0x20; /* 32 bit times slot time */
3609 cfblk.slottim_hi = 0x0;
3610 cfblk.max_retr = 15;
3611 cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
3612 cfblk.bc_dis = FALSE; /* Enable broadcast reception */
3613 cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
3614 cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
3615 cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
3616 cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
3617 cfblk.cs_filter = 0; /* CS is recognized immediately */
3618 cfblk.crs_src = FALSE; /* External carrier sense */
3619 cfblk.cd_filter = 0; /* CD is recognized immediately */
3620 cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
3621 cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
3622 cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
3623 cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
3624 cfblk.artx = TRUE; /* Disable automatic retransmission */
3625 cfblk.sarec = TRUE; /* Disable source addr trig of CD */
3626 cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
3627 cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
3628 cfblk.lbpkpol = TRUE; /* Loopback pin active high */
3629 cfblk.fdx = FALSE; /* Disable full duplex operation */
3630 cfblk.dummy_6 = 0x3f; /* all ones */
3631 cfblk.mult_ia = FALSE; /* No multiple individual addresses */
3632 cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
3633 cfblk.dummy_1 = TRUE; /* set to 1 */
3634 cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
3635 #ifdef MULTICAST_ALL
3636 cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
3638 cfblk.mc_all = FALSE; /* No multicast all mode */
3640 cfblk.rcv_mon = 0; /* Monitor mode disabled */
3641 cfblk.frag_acpt = TRUE; /* Do not accept fragments */
3642 cfblk.tstrttrs = FALSE; /* No start transmission threshold */
3643 cfblk.fretx = TRUE; /* FIFO automatic retransmission */
3644 cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
3645 cfblk.sttlen = TRUE; /* 6 byte status registers */
3646 cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
3647 cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
3648 cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
3649 cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
3651 #ifdef DEBUG_I82593_SHOW
3653 u_char *c = (u_char *) &cfblk;
3655 printk(KERN_DEBUG "wavelan_cs: config block:");
3656 for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
3658 if((i % 16) == 0) printk("\n" KERN_DEBUG);
3659 printk("%02x ", *c);
3665 /* Copy the config block to the i82593 */
3666 outb(TX_BASE & 0xff, PIORL(base));
3667 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3668 outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
3669 outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
3670 outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
3672 /* reset transmit DMA pointer */
3673 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3674 hacr_write(base, HACR_DEFAULT);
3675 if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
3676 OP0_CONFIGURE, SR0_CONFIGURE_DONE))
3679 /* Initialize adapter's ethernet MAC address */
3680 outb(TX_BASE & 0xff, PIORL(base));
3681 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3682 outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
3683 outb(0, PIOP(base)); /* byte count msb */
3684 outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
3686 /* reset transmit DMA pointer */
3687 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3688 hacr_write(base, HACR_DEFAULT);
3689 if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
3690 OP0_IA_SETUP, SR0_IA_SETUP_DONE))
3693 #ifdef WAVELAN_ROAMING
3694 /* If roaming is enabled, join the "Beacon Request" multicast group... */
3695 /* But only if it's not in there already! */
3697 dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
3698 #endif /* WAVELAN_ROAMING */
3700 /* If any multicast address to set */
3703 struct dev_mc_list * dmi;
3704 int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
3706 #ifdef DEBUG_CONFIG_INFO
3707 printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
3708 dev->name, lp->mc_count);
3709 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3710 printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n",
3711 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
3712 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
3715 /* Initialize adapter's ethernet multicast addresses */
3716 outb(TX_BASE & 0xff, PIORL(base));
3717 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3718 outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
3719 outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
3720 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3721 outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
3723 /* reset transmit DMA pointer */
3724 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3725 hacr_write(base, HACR_DEFAULT);
3726 if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
3727 OP0_MC_SETUP, SR0_MC_SETUP_DONE))
3729 lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
3732 /* Job done, clear the flag */
3733 lp->reconfig_82593 = FALSE;
3735 #ifdef DEBUG_CONFIG_TRACE
3736 printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
3741 /*------------------------------------------------------------------*/
3743 * Read the Access Configuration Register, perform a software reset,
3744 * and then re-enable the card's software.
3746 * If I understand correctly : reset the pcmcia interface of the
3748 * (called by wv_config())
3751 wv_pcmcia_reset(struct net_device * dev)
3754 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
3755 dev_link_t * link = ((net_local *)netdev_priv(dev))->link;
3757 #ifdef DEBUG_CONFIG_TRACE
3758 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
3761 i = pcmcia_access_configuration_register(link->handle, ®);
3764 cs_error(link->handle, AccessConfigurationRegister, i);
3768 #ifdef DEBUG_CONFIG_INFO
3769 printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
3770 dev->name, (u_int) reg.Value);
3773 reg.Action = CS_WRITE;
3774 reg.Value = reg.Value | COR_SW_RESET;
3775 i = pcmcia_access_configuration_register(link->handle, ®);
3778 cs_error(link->handle, AccessConfigurationRegister, i);
3782 reg.Action = CS_WRITE;
3783 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3784 i = pcmcia_access_configuration_register(link->handle, ®);
3787 cs_error(link->handle, AccessConfigurationRegister, i);
3791 #ifdef DEBUG_CONFIG_TRACE
3792 printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
3797 /*------------------------------------------------------------------*/
3799 * wavelan_hw_config() is called after a CARD_INSERTION event is
3800 * received, to configure the wavelan hardware.
3801 * Note that the reception will be enabled in wavelan->open(), so the
3802 * device is configured but idle...
3803 * Performs the following actions:
3804 * 1. A pcmcia software reset (using wv_pcmcia_reset())
3805 * 2. A power reset (reset DMA)
3806 * 3. Reset the LAN controller
3807 * 4. Initialize the radio modem (using wv_mmc_init)
3808 * 5. Configure LAN controller (using wv_82593_config)
3809 * 6. Perform a diagnostic on the LAN controller
3810 * (called by wavelan_event() & wv_hw_reset())
3813 wv_hw_config(struct net_device * dev)
3815 net_local * lp = netdev_priv(dev);
3816 kio_addr_t base = dev->base_addr;
3817 unsigned long flags;
3820 #ifdef DEBUG_CONFIG_TRACE
3821 printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
3825 if(wv_structuct_check() != (char *) NULL)
3827 printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: \"%s\"\n",
3828 dev->name, wv_structuct_check());
3831 #endif /* STRUCT_CHECK == 1 */
3833 /* Reset the pcmcia interface */
3834 if(wv_pcmcia_reset(dev) == FALSE)
3837 /* Disable interrupts */
3838 spin_lock_irqsave(&lp->spinlock, flags);
3840 /* Disguised goto ;-) */
3843 /* Power UP the module + reset the modem + reset host adapter
3844 * (in fact, reset DMA channels) */
3845 hacr_write_slow(base, HACR_RESET);
3846 hacr_write(base, HACR_DEFAULT);
3848 /* Check if the module has been powered up... */
3849 if(hasr_read(base) & HASR_NO_CLK)
3851 #ifdef DEBUG_CONFIG_ERRORS
3852 printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
3858 /* initialize the modem */
3859 if(wv_mmc_init(dev) == FALSE)
3861 #ifdef DEBUG_CONFIG_ERRORS
3862 printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n",
3868 /* reset the LAN controller (i82593) */
3869 outb(OP0_RESET, LCCR(base));
3870 mdelay(1); /* A bit crude ! */
3872 /* Initialize the LAN controller */
3873 if(wv_82593_config(dev) == FALSE)
3875 #ifdef DEBUG_CONFIG_ERRORS
3876 printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n",
3883 if(wv_diag(dev) == FALSE)
3885 #ifdef DEBUG_CONFIG_ERRORS
3886 printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n",
3893 * insert code for loopback test here
3896 /* The device is now configured */
3902 /* Re-enable interrupts */
3903 spin_unlock_irqrestore(&lp->spinlock, flags);
3905 #ifdef DEBUG_CONFIG_TRACE
3906 printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
3911 /*------------------------------------------------------------------*/
3913 * Totally reset the wavelan and restart it.
3914 * Performs the following actions:
3915 * 1. Call wv_hw_config()
3916 * 2. Start the LAN controller's receive unit
3917 * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
3920 wv_hw_reset(struct net_device * dev)
3922 net_local * lp = netdev_priv(dev);
3924 #ifdef DEBUG_CONFIG_TRACE
3925 printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
3931 /* Call wv_hw_config() for most of the reset & init stuff */
3932 if(wv_hw_config(dev) == FALSE)
3935 /* start receive unit */
3938 #ifdef DEBUG_CONFIG_TRACE
3939 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3943 /*------------------------------------------------------------------*/
3945 * wv_pcmcia_config() is called after a CARD_INSERTION event is
3946 * received, to configure the PCMCIA socket, and to make the ethernet
3947 * device available to the system.
3948 * (called by wavelan_event())
3951 wv_pcmcia_config(dev_link_t * link)
3953 client_handle_t handle = link->handle;
3956 struct net_device * dev = (struct net_device *) link->priv;
3961 net_local * lp = netdev_priv(dev);
3964 #ifdef DEBUG_CONFIG_TRACE
3965 printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
3969 * This reads the card's CONFIG tuple to find its configuration
3974 tuple.Attributes = 0;
3975 tuple.DesiredTuple = CISTPL_CONFIG;
3976 i = pcmcia_get_first_tuple(handle, &tuple);
3979 tuple.TupleData = (cisdata_t *)buf;
3980 tuple.TupleDataMax = 64;
3981 tuple.TupleOffset = 0;
3982 i = pcmcia_get_tuple_data(handle, &tuple);
3985 i = pcmcia_parse_tuple(handle, &tuple, &parse);
3988 link->conf.ConfigBase = parse.config.base;
3989 link->conf.Present = parse.config.rmask[0];
3994 cs_error(link->handle, ParseTuple, i);
3995 link->state &= ~DEV_CONFIG_PENDING;
3999 /* Configure card */
4000 link->state |= DEV_CONFIG;
4003 i = pcmcia_request_io(link->handle, &link->io);
4006 cs_error(link->handle, RequestIO, i);
4011 * Now allocate an interrupt line. Note that this does not
4012 * actually assign a handler to the interrupt.
4014 i = pcmcia_request_irq(link->handle, &link->irq);
4017 cs_error(link->handle, RequestIRQ, i);
4022 * This actually configures the PCMCIA socket -- setting up
4023 * the I/O windows and the interrupt mapping.
4025 link->conf.ConfigIndex = 1;
4026 i = pcmcia_request_configuration(link->handle, &link->conf);
4029 cs_error(link->handle, RequestConfiguration, i);
4034 * Allocate a small memory window. Note that the dev_link_t
4035 * structure provides space for one window handle -- if your
4036 * device needs several windows, you'll need to keep track of
4037 * the handles in your private data structure, link->priv.
4039 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
4040 req.Base = req.Size = 0;
4041 req.AccessSpeed = mem_speed;
4042 i = pcmcia_request_window(&link->handle, &req, &link->win);
4045 cs_error(link->handle, RequestWindow, i);
4049 lp->mem = ioremap(req.Base, req.Size);
4050 dev->mem_start = (u_long)lp->mem;
4051 dev->mem_end = dev->mem_start + req.Size;
4053 mem.CardOffset = 0; mem.Page = 0;
4054 i = pcmcia_map_mem_page(link->win, &mem);
4057 cs_error(link->handle, MapMemPage, i);
4061 /* Feed device with this info... */
4062 dev->irq = link->irq.AssignedIRQ;
4063 dev->base_addr = link->io.BasePort1;
4064 netif_start_queue(dev);
4066 #ifdef DEBUG_CONFIG_INFO
4067 printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART %p IRQ %d IOPORT 0x%x\n",
4068 lp->mem, dev->irq, (u_int) dev->base_addr);
4071 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
4072 i = register_netdev(dev);
4075 #ifdef DEBUG_CONFIG_ERRORS
4076 printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
4081 while(0); /* Humm... Disguised goto !!! */
4083 link->state &= ~DEV_CONFIG_PENDING;
4084 /* If any step failed, release any partially configured state */
4087 wv_pcmcia_release(link);
4091 strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
4092 link->dev = &((net_local *) netdev_priv(dev))->node;
4094 #ifdef DEBUG_CONFIG_TRACE
4095 printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
4100 /*------------------------------------------------------------------*/
4102 * After a card is removed, wv_pcmcia_release() will unregister the net
4103 * device, and release the PCMCIA configuration. If the device is
4104 * still open, this will be postponed until it is closed.
4107 wv_pcmcia_release(dev_link_t *link)
4109 struct net_device * dev = (struct net_device *) link->priv;
4110 net_local * lp = netdev_priv(dev);
4112 #ifdef DEBUG_CONFIG_TRACE
4113 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
4116 /* Don't bother checking to see if these succeed or not */
4118 pcmcia_release_window(link->win);
4119 pcmcia_release_configuration(link->handle);
4120 pcmcia_release_io(link->handle, &link->io);
4121 pcmcia_release_irq(link->handle, &link->irq);
4123 link->state &= ~DEV_CONFIG;
4125 #ifdef DEBUG_CONFIG_TRACE
4126 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
4130 /************************ INTERRUPT HANDLING ************************/
4133 * This function is the interrupt handler for the WaveLAN card. This
4134 * routine will be called whenever:
4135 * 1. A packet is received.
4136 * 2. A packet has successfully been transferred and the unit is
4137 * ready to transmit another packet.
4138 * 3. A command has completed execution.
4141 wavelan_interrupt(int irq,
4143 struct pt_regs * regs)
4145 struct net_device * dev;
4151 if ((dev = dev_id) == NULL)
4153 #ifdef DEBUG_INTERRUPT_ERROR
4154 printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.\n",
4160 #ifdef DEBUG_INTERRUPT_TRACE
4161 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
4164 lp = netdev_priv(dev);
4165 base = dev->base_addr;
4167 #ifdef DEBUG_INTERRUPT_INFO
4168 /* Check state of our spinlock (it should be cleared) */
4169 if(spin_is_locked(&lp->spinlock))
4171 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
4175 /* Prevent reentrancy. We need to do that because we may have
4176 * multiple interrupt handler running concurently.
4177 * It is safe because interrupts are disabled before aquiring
4179 spin_lock(&lp->spinlock);
4181 /* Treat all pending interrupts */
4184 /* ---------------- INTERRUPT CHECKING ---------------- */
4186 * Look for the interrupt and verify the validity
4188 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
4189 status0 = inb(LCSR(base));
4191 #ifdef DEBUG_INTERRUPT_INFO
4192 printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
4193 (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
4194 if(status0&SR0_INTERRUPT)
4196 printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
4197 ((status0 & SR0_EXECUTION) ? "cmd" :
4198 ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
4199 (status0 & SR0_EVENT_MASK));
4205 /* Return if no actual interrupt from i82593 (normal exit) */
4206 if(!(status0 & SR0_INTERRUPT))
4209 /* If interrupt is both Rx and Tx or none...
4210 * This code in fact is there to catch the spurious interrupt
4211 * when you remove the wavelan pcmcia card from the socket */
4212 if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
4213 ((status0 & SR0_BOTH_RX_TX) == 0x0))
4215 #ifdef DEBUG_INTERRUPT_INFO
4216 printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
4217 dev->name, status0);
4219 /* Acknowledge the interrupt */
4220 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4224 /* ----------------- RECEIVING PACKET ----------------- */
4226 * When the wavelan signal the reception of a new packet,
4227 * we call wv_packet_rcv() to copy if from the buffer and
4230 if(status0 & SR0_RECEPTION)
4232 #ifdef DEBUG_INTERRUPT_INFO
4233 printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
4236 if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
4238 #ifdef DEBUG_INTERRUPT_ERROR
4239 printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
4242 lp->stats.rx_over_errors++;
4243 lp->overrunning = 1;
4246 /* Get the packet */
4248 lp->overrunning = 0;
4250 /* Acknowledge the interrupt */
4251 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4255 /* ---------------- COMMAND COMPLETION ---------------- */
4257 * Interrupts issued when the i82593 has completed a command.
4258 * Most likely : transmission done
4261 /* If a transmission has been done */
4262 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
4263 (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
4264 (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4266 #ifdef DEBUG_TX_ERROR
4267 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4268 printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
4272 /* Get transmission status */
4273 tx_status = inb(LCSR(base));
4274 tx_status |= (inb(LCSR(base)) << 8);
4275 #ifdef DEBUG_INTERRUPT_INFO
4276 printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
4281 rcv_bytes = inb(LCSR(base));
4282 rcv_bytes |= (inb(LCSR(base)) << 8);
4283 status3 = inb(LCSR(base));
4284 printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
4285 tx_status, rcv_bytes, (u_int) status3);
4288 /* Check for possible errors */
4289 if((tx_status & TX_OK) != TX_OK)
4291 lp->stats.tx_errors++;
4293 if(tx_status & TX_FRTL)
4295 #ifdef DEBUG_TX_ERROR
4296 printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
4300 if(tx_status & TX_UND_RUN)
4302 #ifdef DEBUG_TX_FAIL
4303 printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
4306 lp->stats.tx_aborted_errors++;
4308 if(tx_status & TX_LOST_CTS)
4310 #ifdef DEBUG_TX_FAIL
4311 printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
4313 lp->stats.tx_carrier_errors++;
4315 if(tx_status & TX_LOST_CRS)
4317 #ifdef DEBUG_TX_FAIL
4318 printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
4321 lp->stats.tx_carrier_errors++;
4323 if(tx_status & TX_HRT_BEAT)
4325 #ifdef DEBUG_TX_FAIL
4326 printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
4328 lp->stats.tx_heartbeat_errors++;
4330 if(tx_status & TX_DEFER)
4332 #ifdef DEBUG_TX_FAIL
4333 printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
4337 /* Ignore late collisions since they're more likely to happen
4338 * here (the WaveLAN design prevents the LAN controller from
4339 * receiving while it is transmitting). We take action only when
4340 * the maximum retransmit attempts is exceeded.
4342 if(tx_status & TX_COLL)
4344 if(tx_status & TX_MAX_COL)
4346 #ifdef DEBUG_TX_FAIL
4347 printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
4350 if(!(tx_status & TX_NCOL_MASK))
4352 lp->stats.collisions += 0x10;
4356 } /* if(!(tx_status & TX_OK)) */
4358 lp->stats.collisions += (tx_status & TX_NCOL_MASK);
4359 lp->stats.tx_packets++;
4361 netif_wake_queue(dev);
4362 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4364 else /* if interrupt = transmit done or retransmit done */
4366 #ifdef DEBUG_INTERRUPT_ERROR
4367 printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
4370 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4374 spin_unlock(&lp->spinlock);
4376 #ifdef DEBUG_INTERRUPT_TRACE
4377 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
4380 /* We always return IRQ_HANDLED, because we will receive empty
4381 * interrupts under normal operations. Anyway, it doesn't matter
4382 * as we are dealing with an ISA interrupt that can't be shared.
4384 * Explanation : under heavy receive, the following happens :
4385 * ->wavelan_interrupt()
4386 * (status0 & SR0_INTERRUPT) != 0
4388 * (status0 & SR0_INTERRUPT) != 0
4390 * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event
4391 * <-wavelan_interrupt()
4392 * ->wavelan_interrupt()
4393 * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt
4394 * <-wavelan_interrupt()
4397 } /* wv_interrupt */
4399 /*------------------------------------------------------------------*/
4401 * Watchdog: when we start a transmission, a timer is set for us in the
4402 * kernel. If the transmission completes, this timer is disabled. If
4403 * the timer expires, we are called and we try to unlock the hardware.
4405 * Note : This watchdog is move clever than the one in the ISA driver,
4406 * because it try to abort the current command before reseting
4408 * On the other hand, it's a bit simpler, because we don't have to
4409 * deal with the multiple Tx buffers...
4412 wavelan_watchdog(struct net_device * dev)
4414 net_local * lp = netdev_priv(dev);
4415 kio_addr_t base = dev->base_addr;
4416 unsigned long flags;
4417 int aborted = FALSE;
4419 #ifdef DEBUG_INTERRUPT_TRACE
4420 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
4423 #ifdef DEBUG_INTERRUPT_ERROR
4424 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
4428 spin_lock_irqsave(&lp->spinlock, flags);
4430 /* Ask to abort the current command */
4431 outb(OP0_ABORT, LCCR(base));
4433 /* Wait for the end of the command (a bit hackish) */
4434 if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
4435 OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
4438 /* Release spinlock here so that wv_hw_reset() can grab it */
4439 spin_unlock_irqrestore(&lp->spinlock, flags);
4441 /* Check if we were successful in aborting it */
4444 /* It seem that it wasn't enough */
4445 #ifdef DEBUG_INTERRUPT_ERROR
4446 printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
4452 #ifdef DEBUG_PSA_SHOW
4455 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
4459 #ifdef DEBUG_MMC_SHOW
4462 #ifdef DEBUG_I82593_SHOW
4466 /* We are no more waiting for something... */
4467 netif_wake_queue(dev);
4469 #ifdef DEBUG_INTERRUPT_TRACE
4470 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
4474 /********************* CONFIGURATION CALLBACKS *********************/
4476 * Here are the functions called by the pcmcia package (cardmgr) and
4477 * linux networking (NET3) for initialization, configuration and
4478 * deinstallations of the Wavelan Pcmcia Hardware.
4481 /*------------------------------------------------------------------*/
4483 * Configure and start up the WaveLAN PCMCIA adaptor.
4484 * Called by NET3 when it "open" the device.
4487 wavelan_open(struct net_device * dev)
4489 net_local * lp = netdev_priv(dev);
4490 dev_link_t * link = lp->link;
4491 kio_addr_t base = dev->base_addr;
4493 #ifdef DEBUG_CALLBACK_TRACE
4494 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
4495 (unsigned int) dev);
4498 /* Check if the modem is powered up (wavelan_close() power it down */
4499 if(hasr_read(base) & HASR_NO_CLK)
4501 /* Power up (power up time is 250us) */
4502 hacr_write(base, HACR_DEFAULT);
4504 /* Check if the module has been powered up... */
4505 if(hasr_read(base) & HASR_NO_CLK)
4507 #ifdef DEBUG_CONFIG_ERRORS
4508 printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
4515 /* Start reception and declare the driver ready */
4518 if(!wv_ru_start(dev))
4519 wv_hw_reset(dev); /* If problem : reset */
4520 netif_start_queue(dev);
4522 /* Mark the device as used */
4525 #ifdef WAVELAN_ROAMING
4528 #endif /* WAVELAN_ROAMING */
4530 #ifdef DEBUG_CALLBACK_TRACE
4531 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
4536 /*------------------------------------------------------------------*/
4538 * Shutdown the WaveLAN PCMCIA adaptor.
4539 * Called by NET3 when it "close" the device.
4542 wavelan_close(struct net_device * dev)
4544 dev_link_t * link = ((net_local *)netdev_priv(dev))->link;
4545 kio_addr_t base = dev->base_addr;
4547 #ifdef DEBUG_CALLBACK_TRACE
4548 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
4549 (unsigned int) dev);
4552 /* If the device isn't open, then nothing to do */
4555 #ifdef DEBUG_CONFIG_INFO
4556 printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
4561 #ifdef WAVELAN_ROAMING
4562 /* Cleanup of roaming stuff... */
4564 wv_roam_cleanup(dev);
4565 #endif /* WAVELAN_ROAMING */
4569 /* If the card is still present */
4570 if(netif_running(dev))
4572 netif_stop_queue(dev);
4574 /* Stop receiving new messages and wait end of transmission */
4577 /* Power down the module */
4578 hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
4581 #ifdef DEBUG_CALLBACK_TRACE
4582 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
4587 /*------------------------------------------------------------------*/
4589 * wavelan_attach() creates an "instance" of the driver, allocating
4590 * local data structures for one device (one interface). The device
4591 * is registered with Card Services.
4593 * The dev_link structure is initialized, but we don't actually
4594 * configure the card at this point -- we wait until we receive a
4595 * card insertion event.
4598 wavelan_attach(void)
4600 client_reg_t client_reg; /* Register with cardmgr */
4601 dev_link_t * link; /* Info for cardmgr */
4602 struct net_device * dev; /* Interface generic data */
4603 net_local * lp; /* Interface specific data */
4606 #ifdef DEBUG_CALLBACK_TRACE
4607 printk(KERN_DEBUG "-> wavelan_attach()\n");
4610 /* Initialize the dev_link_t structure */
4611 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
4612 if (!link) return NULL;
4613 memset(link, 0, sizeof(struct dev_link_t));
4615 /* The io structure describes IO port mapping */
4616 link->io.NumPorts1 = 8;
4617 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
4618 link->io.IOAddrLines = 3;
4620 /* Interrupt setup */
4621 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
4622 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
4623 link->irq.Handler = wavelan_interrupt;
4625 /* General socket configuration */
4626 link->conf.Attributes = CONF_ENABLE_IRQ;
4627 link->conf.Vcc = 50;
4628 link->conf.IntType = INT_MEMORY_AND_IO;
4631 link->next = dev_list;
4634 /* Allocate the generic data structure */
4635 dev = alloc_etherdev(sizeof(net_local));
4640 link->priv = link->irq.Instance = dev;
4642 lp = netdev_priv(dev);
4644 /* Init specific data */
4646 lp->reconfig_82593 = FALSE;
4648 /* Multicast stuff */
4649 lp->promiscuous = 0;
4650 lp->allmulticast = 0;
4654 spin_lock_init(&lp->spinlock);
4660 /* wavelan NET3 callbacks */
4661 SET_MODULE_OWNER(dev);
4662 dev->open = &wavelan_open;
4663 dev->stop = &wavelan_close;
4664 dev->hard_start_xmit = &wavelan_packet_xmit;
4665 dev->get_stats = &wavelan_get_stats;
4666 dev->set_multicast_list = &wavelan_set_multicast_list;
4667 #ifdef SET_MAC_ADDRESS
4668 dev->set_mac_address = &wavelan_set_mac_address;
4669 #endif /* SET_MAC_ADDRESS */
4671 /* Set the watchdog timer */
4672 dev->tx_timeout = &wavelan_watchdog;
4673 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4674 SET_ETHTOOL_OPS(dev, &ops);
4676 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
4677 dev->wireless_handlers = &wavelan_handler_def;
4678 lp->wireless_data.spy_data = &lp->spy_data;
4679 dev->wireless_data = &lp->wireless_data;
4682 /* Other specific data */
4683 dev->mtu = WAVELAN_MTU;
4685 /* Register with Card Services */
4686 client_reg.dev_info = &dev_info;
4687 client_reg.Version = 0x0210;
4688 client_reg.event_callback_args.client_data = link;
4690 #ifdef DEBUG_CONFIG_INFO
4691 printk(KERN_DEBUG "wavelan_attach(): almost done, calling pcmcia_register_client\n");
4694 ret = pcmcia_register_client(&link->handle, &client_reg);
4697 cs_error(link->handle, RegisterClient, ret);
4698 wavelan_detach(link);
4702 #ifdef DEBUG_CALLBACK_TRACE
4703 printk(KERN_DEBUG "<- wavelan_attach()\n");
4709 /*------------------------------------------------------------------*/
4711 * This deletes a driver "instance". The device is de-registered with
4712 * Card Services. If it has been released, all local data structures
4713 * are freed. Otherwise, the structures will be freed when the device
4717 wavelan_detach(dev_link_t * link)
4719 #ifdef DEBUG_CALLBACK_TRACE
4720 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4724 * If the device is currently configured and active, we won't
4725 * actually delete it yet. Instead, it is marked so that when the
4726 * release() function is called, that will trigger a proper
4729 if(link->state & DEV_CONFIG)
4731 /* Some others haven't done their job : give them another chance */
4732 wv_pcmcia_release(link);
4735 /* Break the link with Card Services */
4737 pcmcia_deregister_client(link->handle);
4739 /* Remove the interface data from the linked list */
4740 if(dev_list == link)
4741 dev_list = link->next;
4744 dev_link_t * prev = dev_list;
4746 while((prev != (dev_link_t *) NULL) && (prev->next != link))
4749 if(prev == (dev_link_t *) NULL)
4751 #ifdef DEBUG_CONFIG_ERRORS
4752 printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.\n");
4757 prev->next = link->next;
4763 struct net_device * dev = (struct net_device *) link->priv;
4765 /* Remove ourselves from the kernel list of ethernet devices */
4766 /* Warning : can't be called from interrupt, timer or wavelan_close() */
4768 unregister_netdev(dev);
4770 ((net_local *)netdev_priv(dev))->link = NULL;
4771 ((net_local *)netdev_priv(dev))->dev = NULL;
4776 #ifdef DEBUG_CALLBACK_TRACE
4777 printk(KERN_DEBUG "<- wavelan_detach()\n");
4781 /*------------------------------------------------------------------*/
4783 * The card status event handler. Mostly, this schedules other stuff
4784 * to run after an event is received. A CARD_REMOVAL event also sets
4785 * some flags to discourage the net drivers from trying to talk to the
4789 wavelan_event(event_t event, /* The event received */
4791 event_callback_args_t * args)
4793 dev_link_t * link = (dev_link_t *) args->client_data;
4794 struct net_device * dev = (struct net_device *) link->priv;
4796 #ifdef DEBUG_CALLBACK_TRACE
4797 printk(KERN_DEBUG "->wavelan_event(): %s\n",
4798 ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" :
4799 ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" :
4800 ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" :
4801 ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" :
4802 ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" :
4803 ((event == CS_EVENT_PM_RESUME) ? "pm resume" :
4804 ((event == CS_EVENT_CARD_RESET) ? "card reset" :
4810 case CS_EVENT_REGISTRATION_COMPLETE:
4811 #ifdef DEBUG_CONFIG_INFO
4812 printk(KERN_DEBUG "wavelan_cs: registration complete\n");
4816 case CS_EVENT_CARD_REMOVAL:
4817 /* Oups ! The card is no more there */
4818 link->state &= ~DEV_PRESENT;
4819 if(link->state & DEV_CONFIG)
4821 /* Accept no more transmissions */
4822 netif_device_detach(dev);
4824 /* Release the card */
4825 wv_pcmcia_release(link);
4829 case CS_EVENT_CARD_INSERTION:
4830 /* Reset and configure the card */
4831 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
4832 if(wv_pcmcia_config(link) &&
4839 case CS_EVENT_PM_SUSPEND:
4840 /* NB: wavelan_close will be called, but too late, so we are
4841 * obliged to close nicely the wavelan here. David, could you
4842 * close the device before suspending them ? And, by the way,
4843 * could you, on resume, add a "route add -net ..." after the
4844 * ifconfig up ? Thanks... */
4846 /* Stop receiving new messages and wait end of transmission */
4849 /* Power down the module */
4850 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
4852 /* The card is now suspended */
4853 link->state |= DEV_SUSPEND;
4854 /* Fall through... */
4855 case CS_EVENT_RESET_PHYSICAL:
4856 if(link->state & DEV_CONFIG)
4859 netif_device_detach(dev);
4860 pcmcia_release_configuration(link->handle);
4864 case CS_EVENT_PM_RESUME:
4865 link->state &= ~DEV_SUSPEND;
4866 /* Fall through... */
4867 case CS_EVENT_CARD_RESET:
4868 if(link->state & DEV_CONFIG)
4870 pcmcia_request_configuration(link->handle, &link->conf);
4871 if(link->open) /* If RESET -> True, If RESUME -> False ? */
4874 netif_device_attach(dev);
4880 #ifdef DEBUG_CALLBACK_TRACE
4881 printk(KERN_DEBUG "<-wavelan_event()\n");
4886 static struct pcmcia_device_id wavelan_ids[] = {
4887 PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
4888 PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
4889 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/PCMCIA", 0x23eb9949, 0x1bc50975),
4890 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/PCMCIA", 0x24358cd4, 0x1bc50975),
4893 MODULE_DEVICE_TABLE(pcmcia, wavelan_ids);
4895 static struct pcmcia_driver wavelan_driver = {
4896 .owner = THIS_MODULE,
4898 .name = "wavelan_cs",
4900 .attach = wavelan_attach,
4901 .event = wavelan_event,
4902 .detach = wavelan_detach,
4903 .id_table = wavelan_ids,
4907 init_wavelan_cs(void)
4909 return pcmcia_register_driver(&wavelan_driver);
4913 exit_wavelan_cs(void)
4915 pcmcia_unregister_driver(&wavelan_driver);
4918 module_init(init_wavelan_cs);
4919 module_exit(exit_wavelan_cs);