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 u_char * ptr = ((u_char *)dev->mem_start) + PSA_ADDR + (o << 1);
144 /* Due to a lack of address decode pins, the WaveLAN PCMCIA card
145 * only supports reading even memory addresses. That means the
146 * increment here MUST be two.
147 * Because of that, we can't use memcpy_fromio()...
153 /*------------------------------------------------------------------*/
155 * Write the Paramter Storage Area to the WaveLAN card's memory
158 psa_write(struct net_device * dev,
159 int o, /* Offset in psa */
160 u_char * b, /* Buffer in memory */
161 int n) /* Length of buffer */
163 u_char * ptr = ((u_char *) dev->mem_start) + PSA_ADDR + (o << 1);
165 ioaddr_t base = dev->base_addr;
166 /* As there seem to have no flag PSA_BUSY as in the ISA model, we are
167 * oblige to verify this address to know when the PSA is ready... */
168 volatile u_char * verify = ((u_char *) dev->mem_start) + PSA_ADDR +
169 (psaoff(0, psa_comp_number) << 1);
171 /* Authorize writting to PSA */
172 hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN);
180 /* I don't have the spec, so I don't know what the correct
181 * sequence to write is. This hack seem to work for me... */
183 while((readb(verify) != PSA_COMP_PCMCIA_915) && (count++ < 100))
187 /* Put the host interface back in standard state */
188 hacr_write(base, HACR_DEFAULT);
192 /*------------------------------------------------------------------*/
194 * Calculate the PSA CRC
195 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
196 * NOTE: By specifying a length including the CRC position the
197 * returned value should be zero. (i.e. a correct checksum in the PSA)
199 * The Windows drivers don't use the CRC, but the AP and the PtP tool
203 psa_crc(unsigned char * psa, /* The PSA */
204 int size) /* Number of short for CRC */
206 int byte_cnt; /* Loop on the PSA */
207 u_short crc_bytes = 0; /* Data in the PSA */
208 int bit_cnt; /* Loop on the bits of the short */
210 for(byte_cnt = 0; byte_cnt < size; byte_cnt++ )
212 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
214 for(bit_cnt = 1; bit_cnt < 9; bit_cnt++ )
216 if(crc_bytes & 0x0001)
217 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
225 #endif /* SET_PSA_CRC */
227 /*------------------------------------------------------------------*/
229 * update the checksum field in the Wavelan's PSA
232 update_psa_checksum(struct net_device * dev)
238 /* read the parameter storage area */
239 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
241 /* update the checksum */
242 crc = psa_crc((unsigned char *) &psa,
243 sizeof(psa) - sizeof(psa.psa_crc[0]) - sizeof(psa.psa_crc[1])
244 - sizeof(psa.psa_crc_status));
246 psa.psa_crc[0] = crc & 0xFF;
247 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
250 psa_write(dev, (char *)&psa.psa_crc - (char *)&psa,
251 (unsigned char *)&psa.psa_crc, 2);
253 #ifdef DEBUG_IOCTL_INFO
254 printk (KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
255 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
257 /* Check again (luxury !) */
258 crc = psa_crc((unsigned char *) &psa,
259 sizeof(psa) - sizeof(psa.psa_crc_status));
262 printk(KERN_WARNING "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", dev->name);
263 #endif /* DEBUG_IOCTL_INFO */
264 #endif /* SET_PSA_CRC */
265 } /* update_psa_checksum */
267 /*------------------------------------------------------------------*/
269 * Write 1 byte to the MMC.
278 /* Wait for MMC to go idle */
279 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
282 outb((u_char)((o << 1) | MMR_MMI_WR), MMR(base));
286 /*------------------------------------------------------------------*/
288 * Routine to write bytes to the Modem Management Controller.
289 * We start by the end because it is the way it should be !
292 mmc_write(u_long base,
301 mmc_out(base, --o, *(--b));
304 /*------------------------------------------------------------------*/
306 * Read 1 byte from the MMC.
307 * Optimised version for 1 byte, avoid using memory...
315 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
317 outb(o << 1, MMR(base)); /* Set the read address */
319 outb(0, MMD(base)); /* Required dummy write */
321 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
323 return (u_char) (inb(MMD(base))); /* Now do the actual read */
326 /*------------------------------------------------------------------*/
328 * Routine to read bytes from the Modem Management Controller.
329 * The implementation is complicated by a lack of address lines,
330 * which prevents decoding of the low-order bit.
331 * (code has just been moved in the above function)
332 * We start by the end because it is the way it should be !
335 mmc_read(u_long base,
344 *(--b) = mmc_in(base, --o);
347 /*------------------------------------------------------------------*/
349 * Get the type of encryption available...
352 mmc_encr(u_long base) /* i/o port of the card */
356 temp = mmc_in(base, mmroff(0, mmr_des_avail));
357 if((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
363 /*------------------------------------------------------------------*/
365 * Wait for the frequency EEprom to complete a command...
366 * I hope this one will be optimally inlined...
369 fee_wait(u_long base, /* i/o port of the card */
370 int delay, /* Base delay to wait for */
371 int number) /* Number of time to wait */
373 int count = 0; /* Wait only a limited time */
375 while((count++ < number) &&
376 (mmc_in(base, mmroff(0, mmr_fee_status)) & MMR_FEE_STATUS_BUSY))
380 /*------------------------------------------------------------------*/
382 * Read bytes from the Frequency EEprom (frequency select cards).
385 fee_read(u_long base, /* i/o port of the card */
386 u_short o, /* destination offset */
387 u_short * b, /* data buffer */
388 int n) /* number of registers */
390 b += n; /* Position at the end of the area */
392 /* Write the address */
393 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
395 /* Loop on all buffer */
398 /* Write the read command */
399 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_READ);
401 /* Wait until EEprom is ready (should be quick !) */
402 fee_wait(base, 10, 100);
405 *--b = ((mmc_in(base, mmroff(0, mmr_fee_data_h)) << 8) |
406 mmc_in(base, mmroff(0, mmr_fee_data_l)));
410 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
412 /*------------------------------------------------------------------*/
414 * Write bytes from the Frequency EEprom (frequency select cards).
415 * This is a bit complicated, because the frequency eeprom has to
416 * be unprotected and the write enabled.
420 fee_write(u_long base, /* i/o port of the card */
421 u_short o, /* destination offset */
422 u_short * b, /* data buffer */
423 int n) /* number of registers */
425 b += n; /* Position at the end of the area */
427 #ifdef EEPROM_IS_PROTECTED /* disabled */
428 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
429 /* Ask to read the protected register */
430 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
432 fee_wait(base, 10, 100);
434 /* Read the protected register */
435 printk("Protected 2 : %02X-%02X\n",
436 mmc_in(base, mmroff(0, mmr_fee_data_h)),
437 mmc_in(base, mmroff(0, mmr_fee_data_l)));
438 #endif /* DOESNT_SEEM_TO_WORK */
440 /* Enable protected register */
441 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
442 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
444 fee_wait(base, 10, 100);
447 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n);
448 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
449 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
451 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
452 #endif /* DOESNT_SEEM_TO_WORK */
454 fee_wait(base, 10, 100);
455 #endif /* EEPROM_IS_PROTECTED */
458 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
459 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
461 fee_wait(base, 10, 100);
463 /* Write the EEprom address */
464 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
466 /* Loop on all buffer */
469 /* Write the value */
470 mmc_out(base, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
471 mmc_out(base, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
473 /* Write the write command */
474 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WRITE);
476 /* Wavelan doc says : wait at least 10 ms for EEBUSY = 0 */
478 fee_wait(base, 10, 100);
482 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
483 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
485 fee_wait(base, 10, 100);
487 #ifdef EEPROM_IS_PROTECTED /* disabled */
488 /* Reprotect EEprom */
489 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x00);
490 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
492 fee_wait(base, 10, 100);
493 #endif /* EEPROM_IS_PROTECTED */
495 #endif /* WIRELESS_EXT */
497 /******************* WaveLAN Roaming routines... ********************/
499 #ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */
501 unsigned char WAVELAN_BEACON_ADDRESS[]= {0x09,0x00,0x0e,0x20,0x03,0x00};
503 void wv_roam_init(struct net_device *dev)
505 net_local *lp= netdev_priv(dev);
507 /* Do not remove this unless you have a good reason */
508 printk(KERN_NOTICE "%s: Warning, you have enabled roaming on"
509 " device %s !\n", dev->name, dev->name);
510 printk(KERN_NOTICE "Roaming is currently an experimental unsupported feature"
511 " of the Wavelan driver.\n");
512 printk(KERN_NOTICE "It may work, but may also make the driver behave in"
513 " erratic ways or crash.\n");
515 lp->wavepoint_table.head=NULL; /* Initialise WavePoint table */
516 lp->wavepoint_table.num_wavepoints=0;
517 lp->wavepoint_table.locked=0;
518 lp->curr_point=NULL; /* No default WavePoint */
521 lp->cell_timer.data=(long)lp; /* Start cell expiry timer */
522 lp->cell_timer.function=wl_cell_expiry;
523 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
524 add_timer(&lp->cell_timer);
526 wv_nwid_filter(NWID_PROMISC,lp) ; /* Enter NWID promiscuous mode */
527 /* to build up a good WavePoint */
529 printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name);
532 void wv_roam_cleanup(struct net_device *dev)
534 wavepoint_history *ptr,*old_ptr;
535 net_local *lp= netdev_priv(dev);
537 printk(KERN_DEBUG "WaveLAN: Roaming Disabled on device %s\n",dev->name);
539 /* Fixme : maybe we should check that the timer exist before deleting it */
540 del_timer(&lp->cell_timer); /* Remove cell expiry timer */
541 ptr=lp->wavepoint_table.head; /* Clear device's WavePoint table */
546 wl_del_wavepoint(old_ptr,lp);
550 /* Enable/Disable NWID promiscuous mode on a given device */
551 void wv_nwid_filter(unsigned char mode, net_local *lp)
556 #ifdef WAVELAN_ROAMING_DEBUG
557 printk(KERN_DEBUG "WaveLAN: NWID promisc %s, device %s\n",(mode==NWID_PROMISC) ? "on" : "off", lp->dev->name);
560 /* Disable interrupts & save flags */
561 spin_lock_irqsave(&lp->spinlock, flags);
563 m.w.mmw_loopt_sel = (mode==NWID_PROMISC) ? MMW_LOOPT_SEL_DIS_NWID : 0x00;
564 mmc_write(lp->dev->base_addr, (char *)&m.w.mmw_loopt_sel - (char *)&m, (unsigned char *)&m.w.mmw_loopt_sel, 1);
566 if(mode==NWID_PROMISC)
571 /* ReEnable interrupts & restore flags */
572 spin_unlock_irqrestore(&lp->spinlock, flags);
575 /* Find a record in the WavePoint table matching a given NWID */
576 wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp)
578 wavepoint_history *ptr=lp->wavepoint_table.head;
588 /* Create a new wavepoint table entry */
589 wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp)
591 wavepoint_history *new_wavepoint;
593 #ifdef WAVELAN_ROAMING_DEBUG
594 printk(KERN_DEBUG "WaveLAN: New Wavepoint, NWID:%.4X\n",nwid);
597 if(lp->wavepoint_table.num_wavepoints==MAX_WAVEPOINTS)
600 new_wavepoint=(wavepoint_history *) kmalloc(sizeof(wavepoint_history),GFP_ATOMIC);
601 if(new_wavepoint==NULL)
604 new_wavepoint->nwid=nwid; /* New WavePoints NWID */
605 new_wavepoint->average_fast=0; /* Running Averages..*/
606 new_wavepoint->average_slow=0;
607 new_wavepoint->qualptr=0; /* Start of ringbuffer */
608 new_wavepoint->last_seq=seq-1; /* Last sequence no.seen */
609 memset(new_wavepoint->sigqual,0,WAVEPOINT_HISTORY);/* Empty ringbuffer */
611 new_wavepoint->next=lp->wavepoint_table.head;/* Add to wavepoint table */
612 new_wavepoint->prev=NULL;
614 if(lp->wavepoint_table.head!=NULL)
615 lp->wavepoint_table.head->prev=new_wavepoint;
617 lp->wavepoint_table.head=new_wavepoint;
619 lp->wavepoint_table.num_wavepoints++; /* no. of visible wavepoints */
621 return new_wavepoint;
624 /* Remove a wavepoint entry from WavePoint table */
625 void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp)
630 if(lp->curr_point==wavepoint)
633 if(wavepoint->prev!=NULL)
634 wavepoint->prev->next=wavepoint->next;
636 if(wavepoint->next!=NULL)
637 wavepoint->next->prev=wavepoint->prev;
639 if(lp->wavepoint_table.head==wavepoint)
640 lp->wavepoint_table.head=wavepoint->next;
642 lp->wavepoint_table.num_wavepoints--;
646 /* Timer callback function - checks WavePoint table for stale entries */
647 void wl_cell_expiry(unsigned long data)
649 net_local *lp=(net_local *)data;
650 wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point;
652 #if WAVELAN_ROAMING_DEBUG > 1
653 printk(KERN_DEBUG "WaveLAN: Wavepoint timeout, dev %s\n",lp->dev->name);
656 if(lp->wavepoint_table.locked)
658 #if WAVELAN_ROAMING_DEBUG > 1
659 printk(KERN_DEBUG "WaveLAN: Wavepoint table locked...\n");
662 lp->cell_timer.expires=jiffies+1; /* If table in use, come back later */
663 add_timer(&lp->cell_timer);
667 while(wavepoint!=NULL)
669 if(time_after(jiffies, wavepoint->last_seen + CELL_TIMEOUT))
671 #ifdef WAVELAN_ROAMING_DEBUG
672 printk(KERN_DEBUG "WaveLAN: Bye bye %.4X\n",wavepoint->nwid);
676 wavepoint=wavepoint->next;
677 wl_del_wavepoint(old_point,lp);
680 wavepoint=wavepoint->next;
682 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
683 add_timer(&lp->cell_timer);
686 /* Update SNR history of a wavepoint */
687 void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq)
689 int i=0,num_missed=0,ptr=0;
690 int average_fast=0,average_slow=0;
692 num_missed=(seq-wavepoint->last_seq)%WAVEPOINT_HISTORY;/* Have we missed
695 for(i=0;i<num_missed;i++)
697 wavepoint->sigqual[wavepoint->qualptr++]=0; /* If so, enter them as 0's */
698 wavepoint->qualptr %=WAVEPOINT_HISTORY; /* in the ringbuffer. */
700 wavepoint->last_seen=jiffies; /* Add beacon to history */
701 wavepoint->last_seq=seq;
702 wavepoint->sigqual[wavepoint->qualptr++]=sigqual;
703 wavepoint->qualptr %=WAVEPOINT_HISTORY;
704 ptr=(wavepoint->qualptr-WAVEPOINT_FAST_HISTORY+WAVEPOINT_HISTORY)%WAVEPOINT_HISTORY;
706 for(i=0;i<WAVEPOINT_FAST_HISTORY;i++) /* Update running averages */
708 average_fast+=wavepoint->sigqual[ptr++];
709 ptr %=WAVEPOINT_HISTORY;
712 average_slow=average_fast;
713 for(i=WAVEPOINT_FAST_HISTORY;i<WAVEPOINT_HISTORY;i++)
715 average_slow+=wavepoint->sigqual[ptr++];
716 ptr %=WAVEPOINT_HISTORY;
719 wavepoint->average_fast=average_fast/WAVEPOINT_FAST_HISTORY;
720 wavepoint->average_slow=average_slow/WAVEPOINT_HISTORY;
723 /* Perform a handover to a new WavePoint */
724 void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp)
726 ioaddr_t base = lp->dev->base_addr;
730 if(wavepoint==lp->curr_point) /* Sanity check... */
732 wv_nwid_filter(!NWID_PROMISC,lp);
736 #ifdef WAVELAN_ROAMING_DEBUG
737 printk(KERN_DEBUG "WaveLAN: Doing handover to %.4X, dev %s\n",wavepoint->nwid,lp->dev->name);
740 /* Disable interrupts & save flags */
741 spin_lock_irqsave(&lp->spinlock, flags);
743 m.w.mmw_netw_id_l = wavepoint->nwid & 0xFF;
744 m.w.mmw_netw_id_h = (wavepoint->nwid & 0xFF00) >> 8;
746 mmc_write(base, (char *)&m.w.mmw_netw_id_l - (char *)&m, (unsigned char *)&m.w.mmw_netw_id_l, 2);
748 /* ReEnable interrupts & restore flags */
749 spin_unlock_irqrestore(&lp->spinlock, flags);
751 wv_nwid_filter(!NWID_PROMISC,lp);
752 lp->curr_point=wavepoint;
755 /* Called when a WavePoint beacon is received */
756 static inline void wl_roam_gather(struct net_device * dev,
757 u_char * hdr, /* Beacon header */
758 u_char * stats) /* SNR, Signal quality
761 wavepoint_beacon *beacon= (wavepoint_beacon *)hdr; /* Rcvd. Beacon */
762 unsigned short nwid=ntohs(beacon->nwid);
763 unsigned short sigqual=stats[2] & MMR_SGNL_QUAL; /* SNR of beacon */
764 wavepoint_history *wavepoint=NULL; /* WavePoint table entry */
765 net_local *lp = netdev_priv(dev); /* Device info */
767 #ifdef I_NEED_THIS_FEATURE
768 /* Some people don't need this, some other may need it */
769 nwid=nwid^ntohs(beacon->domain_id);
772 #if WAVELAN_ROAMING_DEBUG > 1
773 printk(KERN_DEBUG "WaveLAN: beacon, dev %s:\n",dev->name);
774 printk(KERN_DEBUG "Domain: %.4X NWID: %.4X SigQual=%d\n",ntohs(beacon->domain_id),nwid,sigqual);
777 lp->wavepoint_table.locked=1; /* <Mutex> */
779 wavepoint=wl_roam_check(nwid,lp); /* Find WavePoint table entry */
780 if(wavepoint==NULL) /* If no entry, Create a new one... */
782 wavepoint=wl_new_wavepoint(nwid,beacon->seq,lp);
786 if(lp->curr_point==NULL) /* If this is the only WavePoint, */
787 wv_roam_handover(wavepoint, lp); /* Jump on it! */
789 wl_update_history(wavepoint, sigqual, beacon->seq); /* Update SNR history
792 if(lp->curr_point->average_slow < SEARCH_THRESH_LOW) /* If our current */
793 if(!lp->cell_search) /* WavePoint is getting faint, */
794 wv_nwid_filter(NWID_PROMISC,lp); /* start looking for a new one */
796 if(wavepoint->average_slow >
797 lp->curr_point->average_slow + WAVELAN_ROAMING_DELTA)
798 wv_roam_handover(wavepoint, lp); /* Handover to a better WavePoint */
800 if(lp->curr_point->average_slow > SEARCH_THRESH_HIGH) /* If our SNR is */
801 if(lp->cell_search) /* getting better, drop out of cell search mode */
802 wv_nwid_filter(!NWID_PROMISC,lp);
805 lp->wavepoint_table.locked=0; /* </MUTEX> :-) */
808 /* Test this MAC frame a WavePoint beacon */
809 static inline int WAVELAN_BEACON(unsigned char *data)
811 wavepoint_beacon *beacon= (wavepoint_beacon *)data;
812 static wavepoint_beacon beacon_template={0xaa,0xaa,0x03,0x08,0x00,0x0e,0x20,0x03,0x00};
814 if(memcmp(beacon,&beacon_template,9)==0)
819 #endif /* WAVELAN_ROAMING */
821 /************************ I82593 SUBROUTINES *************************/
823 * Useful subroutines to manage the Ethernet controller
826 /*------------------------------------------------------------------*/
828 * Routine to synchronously send a command to the i82593 chip.
829 * Should be called with interrupts disabled.
830 * (called by wv_packet_write(), wv_ru_stop(), wv_ru_start(),
831 * wv_82593_config() & wv_diag())
834 wv_82593_cmd(struct net_device * dev,
839 ioaddr_t base = dev->base_addr;
844 /* Spin until the chip finishes executing its current command (if any) */
848 /* Time calibration of the loop */
851 /* Read the interrupt register */
852 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
853 status = inb(LCSR(base));
855 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
857 /* If the interrupt hasn't be posted */
860 #ifdef DEBUG_INTERRUPT_ERROR
861 printk(KERN_INFO "wv_82593_cmd: %s timeout (previous command), status 0x%02x\n",
867 /* Issue the command to the controller */
868 outb(cmd, LCCR(base));
870 /* If we don't have to check the result of the command
871 * Note : this mean that the irq handler will deal with that */
872 if(result == SR0_NO_RESULT)
875 /* We are waiting for command completion */
876 wait_completed = TRUE;
878 /* Busy wait while the LAN controller executes the command. */
882 /* Time calibration of the loop */
885 /* Read the interrupt register */
886 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
887 status = inb(LCSR(base));
889 /* Check if there was an interrupt posted */
890 if((status & SR0_INTERRUPT))
892 /* Acknowledge the interrupt */
893 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
895 /* Check if interrupt is a command completion */
896 if(((status & SR0_BOTH_RX_TX) != SR0_BOTH_RX_TX) &&
897 ((status & SR0_BOTH_RX_TX) != 0x0) &&
898 !(status & SR0_RECEPTION))
900 /* Signal command completion */
901 wait_completed = FALSE;
905 /* Note : Rx interrupts will be handled later, because we can
906 * handle multiple Rx packets at once */
907 #ifdef DEBUG_INTERRUPT_INFO
908 printk(KERN_INFO "wv_82593_cmd: not our interrupt\n");
913 while(wait_completed && (spin-- > 0));
915 /* If the interrupt hasn't be posted */
918 #ifdef DEBUG_INTERRUPT_ERROR
919 printk(KERN_INFO "wv_82593_cmd: %s timeout, status 0x%02x\n",
925 /* Check the return code returned by the card (see above) against
926 * the expected return code provided by the caller */
927 if((status & SR0_EVENT_MASK) != result)
929 #ifdef DEBUG_INTERRUPT_ERROR
930 printk(KERN_INFO "wv_82593_cmd: %s failed, status = 0x%x\n",
939 /*------------------------------------------------------------------*/
941 * This routine does a 593 op-code number 7, and obtains the diagnose
942 * status for the WaveLAN.
945 wv_diag(struct net_device * dev)
949 if(wv_82593_cmd(dev, "wv_diag(): diagnose",
950 OP0_DIAGNOSE, SR0_DIAGNOSE_PASSED))
953 #ifdef DEBUG_CONFIG_ERROR
954 printk(KERN_INFO "wavelan_cs: i82593 Self Test failed!\n");
959 /*------------------------------------------------------------------*/
961 * Routine to read len bytes from the i82593's ring buffer, starting at
962 * chip address addr. The results read from the chip are stored in buf.
963 * The return value is the address to use for next the call.
966 read_ringbuf(struct net_device * dev,
971 ioaddr_t base = dev->base_addr;
974 char * buf_ptr = buf;
976 /* Get all the buffer */
979 /* Position the Program I/O Register at the ring buffer pointer */
980 outb(ring_ptr & 0xff, PIORL(base));
981 outb(((ring_ptr >> 8) & PIORH_MASK), PIORH(base));
983 /* First, determine how much we can read without wrapping around the
985 if((addr + len) < (RX_BASE + RX_SIZE))
988 chunk_len = RX_BASE + RX_SIZE - addr;
989 insb(PIOP(base), buf_ptr, chunk_len);
990 buf_ptr += chunk_len;
992 ring_ptr = (ring_ptr - RX_BASE + chunk_len) % RX_SIZE + RX_BASE;
997 /*------------------------------------------------------------------*/
999 * Reconfigure the i82593, or at least ask for it...
1000 * Because wv_82593_config use the transmission buffer, we must do it
1001 * when we are sure that there is no transmission, so we do it now
1002 * or in wavelan_packet_xmit() (I can't find any better place,
1003 * wavelan_interrupt is not an option...), so you may experience
1004 * some delay sometime...
1007 wv_82593_reconfig(struct net_device * dev)
1009 net_local * lp = netdev_priv(dev);
1010 dev_link_t * link = lp->link;
1011 unsigned long flags;
1013 /* Arm the flag, will be cleard in wv_82593_config() */
1014 lp->reconfig_82593 = TRUE;
1016 /* Check if we can do it now ! */
1017 if((link->open) && (netif_running(dev)) && !(netif_queue_stopped(dev)))
1019 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
1020 wv_82593_config(dev);
1021 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
1025 #ifdef DEBUG_IOCTL_INFO
1027 "%s: wv_82593_reconfig(): delayed (state = %lX, link = %d)\n",
1028 dev->name, dev->state, link->open);
1033 /********************* DEBUG & INFO SUBROUTINES *********************/
1035 * This routines are used in the code to show debug informations.
1036 * Most of the time, it dump the content of hardware structures...
1039 #ifdef DEBUG_PSA_SHOW
1040 /*------------------------------------------------------------------*/
1042 * Print the formatted contents of the Parameter Storage Area.
1045 wv_psa_show(psa_t * p)
1047 printk(KERN_DEBUG "##### wavelan psa contents: #####\n");
1048 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
1049 p->psa_io_base_addr_1,
1050 p->psa_io_base_addr_2,
1051 p->psa_io_base_addr_3,
1052 p->psa_io_base_addr_4);
1053 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
1054 p->psa_rem_boot_addr_1,
1055 p->psa_rem_boot_addr_2,
1056 p->psa_rem_boot_addr_3);
1057 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
1058 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
1059 #ifdef DEBUG_SHOW_UNUSED
1060 printk(KERN_DEBUG "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1068 #endif /* DEBUG_SHOW_UNUSED */
1069 printk(KERN_DEBUG "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
1070 p->psa_univ_mac_addr[0],
1071 p->psa_univ_mac_addr[1],
1072 p->psa_univ_mac_addr[2],
1073 p->psa_univ_mac_addr[3],
1074 p->psa_univ_mac_addr[4],
1075 p->psa_univ_mac_addr[5]);
1076 printk(KERN_DEBUG "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
1077 p->psa_local_mac_addr[0],
1078 p->psa_local_mac_addr[1],
1079 p->psa_local_mac_addr[2],
1080 p->psa_local_mac_addr[3],
1081 p->psa_local_mac_addr[4],
1082 p->psa_local_mac_addr[5]);
1083 printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel);
1084 printk("psa_comp_number: %d, ", p->psa_comp_number);
1085 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
1086 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
1087 p->psa_feature_select);
1088 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
1089 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
1090 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
1091 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]);
1092 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
1093 printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select);
1094 printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1095 p->psa_encryption_key[0],
1096 p->psa_encryption_key[1],
1097 p->psa_encryption_key[2],
1098 p->psa_encryption_key[3],
1099 p->psa_encryption_key[4],
1100 p->psa_encryption_key[5],
1101 p->psa_encryption_key[6],
1102 p->psa_encryption_key[7]);
1103 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
1104 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
1105 p->psa_call_code[0]);
1106 printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1107 p->psa_call_code[0],
1108 p->psa_call_code[1],
1109 p->psa_call_code[2],
1110 p->psa_call_code[3],
1111 p->psa_call_code[4],
1112 p->psa_call_code[5],
1113 p->psa_call_code[6],
1114 p->psa_call_code[7]);
1115 #ifdef DEBUG_SHOW_UNUSED
1116 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
1120 p->psa_reserved[3]);
1121 #endif /* DEBUG_SHOW_UNUSED */
1122 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
1123 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
1124 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
1126 #endif /* DEBUG_PSA_SHOW */
1128 #ifdef DEBUG_MMC_SHOW
1129 /*------------------------------------------------------------------*/
1131 * Print the formatted status of the Modem Management Controller.
1132 * This function need to be completed...
1135 wv_mmc_show(struct net_device * dev)
1137 ioaddr_t base = dev->base_addr;
1138 net_local * lp = netdev_priv(dev);
1142 if(hasr_read(base) & HASR_NO_CLK)
1144 printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n",
1149 spin_lock_irqsave(&lp->spinlock, flags);
1152 mmc_out(base, mmwoff(0, mmw_freeze), 1);
1153 mmc_read(base, 0, (u_char *)&m, sizeof(m));
1154 mmc_out(base, mmwoff(0, mmw_freeze), 0);
1156 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1157 /* Don't forget to update statistics */
1158 lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
1159 #endif /* WIRELESS_EXT */
1161 spin_unlock_irqrestore(&lp->spinlock, flags);
1163 printk(KERN_DEBUG "##### wavelan modem status registers: #####\n");
1164 #ifdef DEBUG_SHOW_UNUSED
1165 printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1174 #endif /* DEBUG_SHOW_UNUSED */
1175 printk(KERN_DEBUG "Encryption algorythm: %02X - Status: %02X\n",
1176 m.mmr_des_avail, m.mmr_des_status);
1177 #ifdef DEBUG_SHOW_UNUSED
1178 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1184 #endif /* DEBUG_SHOW_UNUSED */
1185 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1187 (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"",
1188 (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1189 "loop test indicated," : "",
1190 (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "",
1191 (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1192 "jabber timer expired," : "");
1193 printk(KERN_DEBUG "Dsp ID: %02X\n",
1195 #ifdef DEBUG_SHOW_UNUSED
1196 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1199 #endif /* DEBUG_SHOW_UNUSED */
1200 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1201 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1202 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1203 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1204 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1205 (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below");
1206 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1207 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1208 (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg");
1209 printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL,
1210 (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update");
1211 printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1212 (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0");
1213 #ifdef DEBUG_SHOW_UNUSED
1214 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1215 #endif /* DEBUG_SHOW_UNUSED */
1217 #endif /* DEBUG_MMC_SHOW */
1219 #ifdef DEBUG_I82593_SHOW
1220 /*------------------------------------------------------------------*/
1222 * Print the formatted status of the i82593's receive unit.
1225 wv_ru_show(struct net_device * dev)
1227 net_local *lp = netdev_priv(dev);
1229 printk(KERN_DEBUG "##### wavelan i82593 receiver status: #####\n");
1230 printk(KERN_DEBUG "ru: rfp %d stop %d", lp->rfp, lp->stop);
1232 * Not implemented yet...
1236 #endif /* DEBUG_I82593_SHOW */
1238 #ifdef DEBUG_DEVICE_SHOW
1239 /*------------------------------------------------------------------*/
1241 * Print the formatted status of the WaveLAN PCMCIA device driver.
1244 wv_dev_show(struct net_device * dev)
1246 printk(KERN_DEBUG "dev:");
1247 printk(" state=%lX,", dev->state);
1248 printk(" trans_start=%ld,", dev->trans_start);
1249 printk(" flags=0x%x,", dev->flags);
1253 /*------------------------------------------------------------------*/
1255 * Print the formatted status of the WaveLAN PCMCIA device driver's
1256 * private information.
1259 wv_local_show(struct net_device * dev)
1261 net_local *lp = netdev_priv(dev);
1263 printk(KERN_DEBUG "local:");
1265 * Not implemented yet...
1268 } /* wv_local_show */
1269 #endif /* DEBUG_DEVICE_SHOW */
1271 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1272 /*------------------------------------------------------------------*/
1274 * Dump packet header (and content if necessary) on the screen
1277 wv_packet_info(u_char * p, /* Packet to dump */
1278 int length, /* Length of the packet */
1279 char * msg1, /* Name of the device */
1280 char * msg2) /* Name of the function */
1285 printk(KERN_DEBUG "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1286 msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1287 printk(KERN_DEBUG "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1288 msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13]);
1290 #ifdef DEBUG_PACKET_DUMP
1292 printk(KERN_DEBUG "data=\"");
1294 if((maxi = length) > DEBUG_PACKET_DUMP)
1295 maxi = DEBUG_PACKET_DUMP;
1296 for(i = 14; i < maxi; i++)
1297 if(p[i] >= ' ' && p[i] <= '~')
1298 printk(" %c", p[i]);
1300 printk("%02X", p[i]);
1304 printk(KERN_DEBUG "\n");
1305 #endif /* DEBUG_PACKET_DUMP */
1307 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1309 /*------------------------------------------------------------------*/
1311 * This is the information which is displayed by the driver at startup
1312 * There is a lot of flag to configure it at your will...
1315 wv_init_info(struct net_device * dev)
1317 ioaddr_t base = dev->base_addr;
1321 /* Read the parameter storage area */
1322 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
1324 #ifdef DEBUG_PSA_SHOW
1327 #ifdef DEBUG_MMC_SHOW
1330 #ifdef DEBUG_I82593_SHOW
1334 #ifdef DEBUG_BASIC_SHOW
1335 /* Now, let's go for the basic stuff */
1336 printk(KERN_NOTICE "%s: WaveLAN: port %#x, irq %d, hw_addr",
1337 dev->name, base, dev->irq);
1338 for(i = 0; i < WAVELAN_ADDR_SIZE; i++)
1339 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1341 /* Print current network id */
1342 if(psa.psa_nwid_select)
1343 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
1345 printk(", nwid off");
1348 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1349 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1351 unsigned short freq;
1353 /* Ask the EEprom to read the frequency from the first area */
1354 fee_read(base, 0x00 /* 1st area - frequency... */,
1357 /* Print frequency */
1358 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1366 printk(", PCMCIA, ");
1367 switch (psa.psa_subband)
1369 case PSA_SUBBAND_915:
1372 case PSA_SUBBAND_2425:
1375 case PSA_SUBBAND_2460:
1378 case PSA_SUBBAND_2484:
1381 case PSA_SUBBAND_2430_5:
1390 #endif /* DEBUG_BASIC_SHOW */
1392 #ifdef DEBUG_VERSION_SHOW
1393 /* Print version information */
1394 printk(KERN_NOTICE "%s", version);
1396 } /* wv_init_info */
1398 /********************* IOCTL, STATS & RECONFIG *********************/
1400 * We found here routines that are called by Linux on differents
1401 * occasions after the configuration and not for transmitting data
1402 * These may be called when the user use ifconfig, /proc/net/dev
1403 * or wireless extensions
1406 /*------------------------------------------------------------------*/
1408 * Get the current ethernet statistics. This may be called with the
1409 * card open or closed.
1410 * Used when the user read /proc/net/dev
1413 wavelan_get_stats(struct net_device * dev)
1415 #ifdef DEBUG_IOCTL_TRACE
1416 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1419 return(&((net_local *)netdev_priv(dev))->stats);
1422 /*------------------------------------------------------------------*/
1424 * Set or clear the multicast filter for this adaptor.
1425 * num_addrs == -1 Promiscuous mode, receive all packets
1426 * num_addrs == 0 Normal mode, clear multicast list
1427 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1428 * and do best-effort filtering.
1432 wavelan_set_multicast_list(struct net_device * dev)
1434 net_local * lp = netdev_priv(dev);
1436 #ifdef DEBUG_IOCTL_TRACE
1437 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
1440 #ifdef DEBUG_IOCTL_INFO
1441 printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1442 dev->name, dev->flags, dev->mc_count);
1445 if(dev->flags & IFF_PROMISC)
1448 * Enable promiscuous mode: receive all packets.
1450 if(!lp->promiscuous)
1452 lp->promiscuous = 1;
1453 lp->allmulticast = 0;
1456 wv_82593_reconfig(dev);
1458 /* Tell the kernel that we are doing a really bad job... */
1459 dev->flags |= IFF_PROMISC;
1463 /* If all multicast addresses
1464 * or too much multicast addresses for the hardware filter */
1465 if((dev->flags & IFF_ALLMULTI) ||
1466 (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
1469 * Disable promiscuous mode, but active the all multicast mode
1471 if(!lp->allmulticast)
1473 lp->promiscuous = 0;
1474 lp->allmulticast = 1;
1477 wv_82593_reconfig(dev);
1479 /* Tell the kernel that we are doing a really bad job... */
1480 dev->flags |= IFF_ALLMULTI;
1484 /* If there is some multicast addresses to send */
1485 if(dev->mc_list != (struct dev_mc_list *) NULL)
1488 * Disable promiscuous mode, but receive all packets
1491 #ifdef MULTICAST_AVOID
1492 if(lp->promiscuous || lp->allmulticast ||
1493 (dev->mc_count != lp->mc_count))
1496 lp->promiscuous = 0;
1497 lp->allmulticast = 0;
1498 lp->mc_count = dev->mc_count;
1500 wv_82593_reconfig(dev);
1506 * Switch to normal mode: disable promiscuous mode and
1507 * clear the multicast list.
1509 if(lp->promiscuous || lp->mc_count == 0)
1511 lp->promiscuous = 0;
1512 lp->allmulticast = 0;
1515 wv_82593_reconfig(dev);
1518 #ifdef DEBUG_IOCTL_TRACE
1519 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
1523 /*------------------------------------------------------------------*/
1525 * This function doesn't exist...
1526 * (Note : it was a nice way to test the reconfigure stuff...)
1528 #ifdef SET_MAC_ADDRESS
1530 wavelan_set_mac_address(struct net_device * dev,
1533 struct sockaddr * mac = addr;
1535 /* Copy the address */
1536 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1538 /* Reconfig the beast */
1539 wv_82593_reconfig(dev);
1543 #endif /* SET_MAC_ADDRESS */
1545 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1547 /*------------------------------------------------------------------*/
1549 * Frequency setting (for hardware able of it)
1550 * It's a bit complicated and you don't really want to look into it...
1553 wv_set_frequency(u_long base, /* i/o port of the card */
1554 iw_freq * frequency)
1556 const int BAND_NUM = 10; /* Number of bands */
1557 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1558 #ifdef DEBUG_IOCTL_INFO
1562 /* Setting by frequency */
1563 /* Theoritically, you may set any frequency between
1564 * the two limits with a 0.5 MHz precision. In practice,
1565 * I don't want you to have trouble with local
1567 if((frequency->e == 1) &&
1568 (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
1570 freq = ((frequency->m / 10000) - 24000L) / 5;
1573 /* Setting by channel (same as wfreqsel) */
1574 /* Warning : each channel is 22MHz wide, so some of the channels
1575 * will interfere... */
1576 if((frequency->e == 0) &&
1577 (frequency->m >= 0) && (frequency->m < BAND_NUM))
1579 /* Get frequency offset. */
1580 freq = channel_bands[frequency->m] >> 1;
1583 /* Verify if the frequency is allowed */
1586 u_short table[10]; /* Authorized frequency table */
1588 /* Read the frequency table */
1589 fee_read(base, 0x71 /* frequency table */,
1592 #ifdef DEBUG_IOCTL_INFO
1593 printk(KERN_DEBUG "Frequency table :");
1594 for(i = 0; i < 10; i++)
1602 /* Look in the table if the frequency is allowed */
1603 if(!(table[9 - ((freq - 24) / 16)] &
1604 (1 << ((freq - 24) % 16))))
1605 return -EINVAL; /* not allowed */
1610 /* If we get a usable frequency */
1613 unsigned short area[16];
1614 unsigned short dac[2];
1615 unsigned short area_verify[16];
1616 unsigned short dac_verify[2];
1617 /* Corresponding gain (in the power adjust value table)
1618 * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
1619 * & WCIN062D.DOC, page 6.2.9 */
1620 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1621 int power_band = 0; /* Selected band */
1622 unsigned short power_adjust; /* Correct value */
1624 /* Search for the gain */
1626 while((freq > power_limit[power_band]) &&
1627 (power_limit[++power_band] != 0))
1630 /* Read the first area */
1631 fee_read(base, 0x00,
1635 fee_read(base, 0x60,
1638 /* Read the new power adjust value */
1639 fee_read(base, 0x6B - (power_band >> 1),
1641 if(power_band & 0x1)
1644 power_adjust &= 0xFF;
1646 #ifdef DEBUG_IOCTL_INFO
1647 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1648 for(i = 0; i < 16; i++)
1655 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1659 /* Frequency offset (for info only...) */
1660 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1662 /* Receiver Principle main divider coefficient */
1663 area[3] = (freq >> 1) + 2400L - 352L;
1664 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1666 /* Transmitter Main divider coefficient */
1667 area[13] = (freq >> 1) + 2400L;
1668 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1670 /* Others part of the area are flags, bit streams or unused... */
1672 /* Set the value in the DAC */
1673 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1674 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1676 /* Write the first area */
1677 fee_write(base, 0x00,
1681 fee_write(base, 0x60,
1684 /* We now should verify here that the EEprom writting was ok */
1686 /* ReRead the first area */
1687 fee_read(base, 0x00,
1690 /* ReRead the DAC */
1691 fee_read(base, 0x60,
1695 if(memcmp(area, area_verify, 16 * 2) ||
1696 memcmp(dac, dac_verify, 2 * 2))
1698 #ifdef DEBUG_IOCTL_ERROR
1699 printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
1704 /* We must download the frequency parameters to the
1705 * synthetisers (from the EEprom - area 1)
1706 * Note : as the EEprom is auto decremented, we set the end
1708 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
1709 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1710 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1712 /* Wait until the download is finished */
1713 fee_wait(base, 100, 100);
1715 /* We must now download the power adjust value (gain) to
1716 * the synthetisers (from the EEprom - area 7 - DAC) */
1717 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
1718 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1719 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1721 /* Wait until the download is finished */
1722 fee_wait(base, 100, 100);
1724 #ifdef DEBUG_IOCTL_INFO
1725 /* Verification of what we have done... */
1727 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1728 for(i = 0; i < 16; i++)
1735 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1736 dac_verify[0], dac_verify[1]);
1742 return -EINVAL; /* Bah, never get there... */
1745 /*------------------------------------------------------------------*/
1747 * Give the list of available frequencies
1750 wv_frequency_list(u_long base, /* i/o port of the card */
1751 iw_freq * list, /* List of frequency to fill */
1752 int max) /* Maximum number of frequencies */
1754 u_short table[10]; /* Authorized frequency table */
1755 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1756 int i; /* index in the table */
1757 const int BAND_NUM = 10; /* Number of bands */
1758 int c = 0; /* Channel number */
1760 /* Read the frequency table */
1761 fee_read(base, 0x71 /* frequency table */,
1764 /* Look all frequencies */
1766 for(freq = 0; freq < 150; freq++)
1767 /* Look in the table if the frequency is allowed */
1768 if(table[9 - (freq / 16)] & (1 << (freq % 16)))
1770 /* Compute approximate channel number */
1771 while((((channel_bands[c] >> 1) - 24) < freq) &&
1774 list[i].i = c; /* Set the list index */
1776 /* put in the list */
1777 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1788 #ifdef IW_WIRELESS_SPY
1789 /*------------------------------------------------------------------*/
1791 * Gather wireless spy statistics : for each packet, compare the source
1792 * address with out list, and if match, get the stats...
1793 * Sorry, but this function really need wireless extensions...
1796 wl_spy_gather(struct net_device * dev,
1797 u_char * mac, /* MAC address */
1798 u_char * stats) /* Statistics to gather */
1800 struct iw_quality wstats;
1802 wstats.qual = stats[2] & MMR_SGNL_QUAL;
1803 wstats.level = stats[0] & MMR_SIGNAL_LVL;
1804 wstats.noise = stats[1] & MMR_SILENCE_LVL;
1805 wstats.updated = 0x7;
1807 /* Update spy records */
1808 wireless_spy_update(dev, mac, &wstats);
1810 #endif /* IW_WIRELESS_SPY */
1813 /*------------------------------------------------------------------*/
1815 * This function calculate an histogram on the signal level.
1816 * As the noise is quite constant, it's like doing it on the SNR.
1817 * We have defined a set of interval (lp->his_range), and each time
1818 * the level goes in that interval, we increment the count (lp->his_sum).
1819 * With this histogram you may detect if one wavelan is really weak,
1820 * or you may also calculate the mean and standard deviation of the level...
1823 wl_his_gather(struct net_device * dev,
1824 u_char * stats) /* Statistics to gather */
1826 net_local * lp = netdev_priv(dev);
1827 u_char level = stats[0] & MMR_SIGNAL_LVL;
1830 /* Find the correct interval */
1832 while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
1835 /* Increment interval counter */
1838 #endif /* HISTOGRAM */
1840 static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1842 strncpy(info->driver, "wavelan_cs", sizeof(info->driver)-1);
1845 static struct ethtool_ops ops = {
1846 .get_drvinfo = wl_get_drvinfo
1849 /*------------------------------------------------------------------*/
1851 * Wireless Handler : get protocol name
1853 static int wavelan_get_name(struct net_device *dev,
1854 struct iw_request_info *info,
1855 union iwreq_data *wrqu,
1858 strcpy(wrqu->name, "WaveLAN");
1862 /*------------------------------------------------------------------*/
1864 * Wireless Handler : set NWID
1866 static int wavelan_set_nwid(struct net_device *dev,
1867 struct iw_request_info *info,
1868 union iwreq_data *wrqu,
1871 ioaddr_t base = dev->base_addr;
1872 net_local *lp = netdev_priv(dev);
1875 unsigned long flags;
1878 /* Disable interrupts and save flags. */
1879 spin_lock_irqsave(&lp->spinlock, flags);
1881 /* Set NWID in WaveLAN. */
1882 if (!wrqu->nwid.disabled) {
1883 /* Set NWID in psa */
1884 psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
1885 psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
1886 psa.psa_nwid_select = 0x01;
1888 (char *) psa.psa_nwid - (char *) &psa,
1889 (unsigned char *) psa.psa_nwid, 3);
1891 /* Set NWID in mmc. */
1892 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1893 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1895 (char *) &m.w.mmw_netw_id_l -
1897 (unsigned char *) &m.w.mmw_netw_id_l, 2);
1898 mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
1900 /* Disable NWID in the psa. */
1901 psa.psa_nwid_select = 0x00;
1903 (char *) &psa.psa_nwid_select -
1905 (unsigned char *) &psa.psa_nwid_select,
1908 /* Disable NWID in the mmc (no filtering). */
1909 mmc_out(base, mmwoff(0, mmw_loopt_sel),
1910 MMW_LOOPT_SEL_DIS_NWID);
1912 /* update the Wavelan checksum */
1913 update_psa_checksum(dev);
1915 /* Enable interrupts and restore flags. */
1916 spin_unlock_irqrestore(&lp->spinlock, flags);
1921 /*------------------------------------------------------------------*/
1923 * Wireless Handler : get NWID
1925 static int wavelan_get_nwid(struct net_device *dev,
1926 struct iw_request_info *info,
1927 union iwreq_data *wrqu,
1930 net_local *lp = netdev_priv(dev);
1932 unsigned long flags;
1935 /* Disable interrupts and save flags. */
1936 spin_lock_irqsave(&lp->spinlock, flags);
1938 /* Read the NWID. */
1940 (char *) psa.psa_nwid - (char *) &psa,
1941 (unsigned char *) psa.psa_nwid, 3);
1942 wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1943 wrqu->nwid.disabled = !(psa.psa_nwid_select);
1944 wrqu->nwid.fixed = 1; /* Superfluous */
1946 /* Enable interrupts and restore flags. */
1947 spin_unlock_irqrestore(&lp->spinlock, flags);
1952 /*------------------------------------------------------------------*/
1954 * Wireless Handler : set frequency
1956 static int wavelan_set_freq(struct net_device *dev,
1957 struct iw_request_info *info,
1958 union iwreq_data *wrqu,
1961 ioaddr_t base = dev->base_addr;
1962 net_local *lp = netdev_priv(dev);
1963 unsigned long flags;
1966 /* Disable interrupts and save flags. */
1967 spin_lock_irqsave(&lp->spinlock, flags);
1969 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1970 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1971 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1972 ret = wv_set_frequency(base, &(wrqu->freq));
1976 /* Enable interrupts and restore flags. */
1977 spin_unlock_irqrestore(&lp->spinlock, flags);
1982 /*------------------------------------------------------------------*/
1984 * Wireless Handler : get frequency
1986 static int wavelan_get_freq(struct net_device *dev,
1987 struct iw_request_info *info,
1988 union iwreq_data *wrqu,
1991 ioaddr_t base = dev->base_addr;
1992 net_local *lp = netdev_priv(dev);
1994 unsigned long flags;
1997 /* Disable interrupts and save flags. */
1998 spin_lock_irqsave(&lp->spinlock, flags);
2000 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
2001 * Does it work for everybody, especially old cards? */
2002 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2003 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2004 unsigned short freq;
2006 /* Ask the EEPROM to read the frequency from the first area. */
2007 fee_read(base, 0x00, &freq, 1);
2008 wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
2012 (char *) &psa.psa_subband - (char *) &psa,
2013 (unsigned char *) &psa.psa_subband, 1);
2015 if (psa.psa_subband <= 4) {
2016 wrqu->freq.m = fixed_bands[psa.psa_subband];
2017 wrqu->freq.e = (psa.psa_subband != 0);
2022 /* Enable interrupts and restore flags. */
2023 spin_unlock_irqrestore(&lp->spinlock, flags);
2028 /*------------------------------------------------------------------*/
2030 * Wireless Handler : set level threshold
2032 static int wavelan_set_sens(struct net_device *dev,
2033 struct iw_request_info *info,
2034 union iwreq_data *wrqu,
2037 ioaddr_t base = dev->base_addr;
2038 net_local *lp = netdev_priv(dev);
2040 unsigned long flags;
2043 /* Disable interrupts and save flags. */
2044 spin_lock_irqsave(&lp->spinlock, flags);
2046 /* Set the level threshold. */
2047 /* We should complain loudly if wrqu->sens.fixed = 0, because we
2048 * can't set auto mode... */
2049 psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
2051 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2052 (unsigned char *) &psa.psa_thr_pre_set, 1);
2053 /* update the Wavelan checksum */
2054 update_psa_checksum(dev);
2055 mmc_out(base, mmwoff(0, mmw_thr_pre_set),
2056 psa.psa_thr_pre_set);
2058 /* Enable interrupts and restore flags. */
2059 spin_unlock_irqrestore(&lp->spinlock, flags);
2064 /*------------------------------------------------------------------*/
2066 * Wireless Handler : get level threshold
2068 static int wavelan_get_sens(struct net_device *dev,
2069 struct iw_request_info *info,
2070 union iwreq_data *wrqu,
2073 net_local *lp = netdev_priv(dev);
2075 unsigned long flags;
2078 /* Disable interrupts and save flags. */
2079 spin_lock_irqsave(&lp->spinlock, flags);
2081 /* Read the level threshold. */
2083 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2084 (unsigned char *) &psa.psa_thr_pre_set, 1);
2085 wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
2086 wrqu->sens.fixed = 1;
2088 /* Enable interrupts and restore flags. */
2089 spin_unlock_irqrestore(&lp->spinlock, flags);
2094 /*------------------------------------------------------------------*/
2096 * Wireless Handler : set encryption key
2098 static int wavelan_set_encode(struct net_device *dev,
2099 struct iw_request_info *info,
2100 union iwreq_data *wrqu,
2103 ioaddr_t base = dev->base_addr;
2104 net_local *lp = netdev_priv(dev);
2105 unsigned long flags;
2109 /* Disable interrupts and save flags. */
2110 spin_lock_irqsave(&lp->spinlock, flags);
2112 /* Check if capable of encryption */
2113 if (!mmc_encr(base)) {
2117 /* Check the size of the key */
2118 if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
2123 /* Basic checking... */
2124 if (wrqu->encoding.length == 8) {
2125 /* Copy the key in the driver */
2126 memcpy(psa.psa_encryption_key, extra,
2127 wrqu->encoding.length);
2128 psa.psa_encryption_select = 1;
2131 (char *) &psa.psa_encryption_select -
2133 (unsigned char *) &psa.
2134 psa_encryption_select, 8 + 1);
2136 mmc_out(base, mmwoff(0, mmw_encr_enable),
2137 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2138 mmc_write(base, mmwoff(0, mmw_encr_key),
2139 (unsigned char *) &psa.
2140 psa_encryption_key, 8);
2143 /* disable encryption */
2144 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
2145 psa.psa_encryption_select = 0;
2147 (char *) &psa.psa_encryption_select -
2149 (unsigned char *) &psa.
2150 psa_encryption_select, 1);
2152 mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
2154 /* update the Wavelan checksum */
2155 update_psa_checksum(dev);
2158 /* Enable interrupts and restore flags. */
2159 spin_unlock_irqrestore(&lp->spinlock, flags);
2164 /*------------------------------------------------------------------*/
2166 * Wireless Handler : get encryption key
2168 static int wavelan_get_encode(struct net_device *dev,
2169 struct iw_request_info *info,
2170 union iwreq_data *wrqu,
2173 ioaddr_t base = dev->base_addr;
2174 net_local *lp = netdev_priv(dev);
2176 unsigned long flags;
2179 /* Disable interrupts and save flags. */
2180 spin_lock_irqsave(&lp->spinlock, flags);
2182 /* Check if encryption is available */
2183 if (!mmc_encr(base)) {
2186 /* Read the encryption key */
2188 (char *) &psa.psa_encryption_select -
2190 (unsigned char *) &psa.
2191 psa_encryption_select, 1 + 8);
2193 /* encryption is enabled ? */
2194 if (psa.psa_encryption_select)
2195 wrqu->encoding.flags = IW_ENCODE_ENABLED;
2197 wrqu->encoding.flags = IW_ENCODE_DISABLED;
2198 wrqu->encoding.flags |= mmc_encr(base);
2200 /* Copy the key to the user buffer */
2201 wrqu->encoding.length = 8;
2202 memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
2205 /* Enable interrupts and restore flags. */
2206 spin_unlock_irqrestore(&lp->spinlock, flags);
2211 #ifdef WAVELAN_ROAMING_EXT
2212 /*------------------------------------------------------------------*/
2214 * Wireless Handler : set ESSID (domain)
2216 static int wavelan_set_essid(struct net_device *dev,
2217 struct iw_request_info *info,
2218 union iwreq_data *wrqu,
2221 net_local *lp = netdev_priv(dev);
2222 unsigned long flags;
2225 /* Disable interrupts and save flags. */
2226 spin_lock_irqsave(&lp->spinlock, flags);
2228 /* Check if disable */
2229 if(wrqu->data.flags == 0)
2230 lp->filter_domains = 0;
2232 char essid[IW_ESSID_MAX_SIZE + 1];
2235 /* Terminate the string */
2236 memcpy(essid, extra, wrqu->data.length);
2237 essid[IW_ESSID_MAX_SIZE] = '\0';
2239 #ifdef DEBUG_IOCTL_INFO
2240 printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
2241 #endif /* DEBUG_IOCTL_INFO */
2243 /* Convert to a number (note : Wavelan specific) */
2244 lp->domain_id = simple_strtoul(essid, &endp, 16);
2245 /* Has it worked ? */
2247 lp->filter_domains = 1;
2249 lp->filter_domains = 0;
2254 /* Enable interrupts and restore flags. */
2255 spin_unlock_irqrestore(&lp->spinlock, flags);
2260 /*------------------------------------------------------------------*/
2262 * Wireless Handler : get ESSID (domain)
2264 static int wavelan_get_essid(struct net_device *dev,
2265 struct iw_request_info *info,
2266 union iwreq_data *wrqu,
2269 net_local *lp = netdev_priv(dev);
2271 /* Is the domain ID active ? */
2272 wrqu->data.flags = lp->filter_domains;
2274 /* Copy Domain ID into a string (Wavelan specific) */
2275 /* Sound crazy, be we can't have a snprintf in the kernel !!! */
2276 sprintf(extra, "%lX", lp->domain_id);
2277 extra[IW_ESSID_MAX_SIZE] = '\0';
2279 /* Set the length */
2280 wrqu->data.length = strlen(extra) + 1;
2285 /*------------------------------------------------------------------*/
2287 * Wireless Handler : set AP address
2289 static int wavelan_set_wap(struct net_device *dev,
2290 struct iw_request_info *info,
2291 union iwreq_data *wrqu,
2294 #ifdef DEBUG_IOCTL_INFO
2295 printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
2296 wrqu->ap_addr.sa_data[0],
2297 wrqu->ap_addr.sa_data[1],
2298 wrqu->ap_addr.sa_data[2],
2299 wrqu->ap_addr.sa_data[3],
2300 wrqu->ap_addr.sa_data[4],
2301 wrqu->ap_addr.sa_data[5]);
2302 #endif /* DEBUG_IOCTL_INFO */
2307 /*------------------------------------------------------------------*/
2309 * Wireless Handler : get AP address
2311 static int wavelan_get_wap(struct net_device *dev,
2312 struct iw_request_info *info,
2313 union iwreq_data *wrqu,
2316 /* Should get the real McCoy instead of own Ethernet address */
2317 memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
2318 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
2322 #endif /* WAVELAN_ROAMING_EXT */
2324 #ifdef WAVELAN_ROAMING
2325 /*------------------------------------------------------------------*/
2327 * Wireless Handler : set mode
2329 static int wavelan_set_mode(struct net_device *dev,
2330 struct iw_request_info *info,
2331 union iwreq_data *wrqu,
2334 net_local *lp = netdev_priv(dev);
2335 unsigned long flags;
2338 /* Disable interrupts and save flags. */
2339 spin_lock_irqsave(&lp->spinlock, flags);
2342 switch(wrqu->mode) {
2345 wv_roam_cleanup(dev);
2359 /* Enable interrupts and restore flags. */
2360 spin_unlock_irqrestore(&lp->spinlock, flags);
2365 /*------------------------------------------------------------------*/
2367 * Wireless Handler : get mode
2369 static int wavelan_get_mode(struct net_device *dev,
2370 struct iw_request_info *info,
2371 union iwreq_data *wrqu,
2375 wrqu->mode = IW_MODE_INFRA;
2377 wrqu->mode = IW_MODE_ADHOC;
2381 #endif /* WAVELAN_ROAMING */
2383 /*------------------------------------------------------------------*/
2385 * Wireless Handler : get range info
2387 static int wavelan_get_range(struct net_device *dev,
2388 struct iw_request_info *info,
2389 union iwreq_data *wrqu,
2392 ioaddr_t base = dev->base_addr;
2393 net_local *lp = netdev_priv(dev);
2394 struct iw_range *range = (struct iw_range *) extra;
2395 unsigned long flags;
2398 /* Set the length (very important for backward compatibility) */
2399 wrqu->data.length = sizeof(struct iw_range);
2401 /* Set all the info we don't care or don't know about to zero */
2402 memset(range, 0, sizeof(struct iw_range));
2404 /* Set the Wireless Extension versions */
2405 range->we_version_compiled = WIRELESS_EXT;
2406 range->we_version_source = 9;
2408 /* Set information in the range struct. */
2409 range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
2410 range->min_nwid = 0x0000;
2411 range->max_nwid = 0xFFFF;
2413 range->sensitivity = 0x3F;
2414 range->max_qual.qual = MMR_SGNL_QUAL;
2415 range->max_qual.level = MMR_SIGNAL_LVL;
2416 range->max_qual.noise = MMR_SILENCE_LVL;
2417 range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
2418 /* Need to get better values for those two */
2419 range->avg_qual.level = 30;
2420 range->avg_qual.noise = 8;
2422 range->num_bitrates = 1;
2423 range->bitrate[0] = 2000000; /* 2 Mb/s */
2425 /* Event capability (kernel + driver) */
2426 range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
2427 IW_EVENT_CAPA_MASK(0x8B04) |
2428 IW_EVENT_CAPA_MASK(0x8B06));
2429 range->event_capa[1] = IW_EVENT_CAPA_K_1;
2431 /* Disable interrupts and save flags. */
2432 spin_lock_irqsave(&lp->spinlock, flags);
2434 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2435 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2436 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2437 range->num_channels = 10;
2438 range->num_frequency = wv_frequency_list(base, range->freq,
2439 IW_MAX_FREQUENCIES);
2441 range->num_channels = range->num_frequency = 0;
2443 /* Encryption supported ? */
2444 if (mmc_encr(base)) {
2445 range->encoding_size[0] = 8; /* DES = 64 bits key */
2446 range->num_encoding_sizes = 1;
2447 range->max_encoding_tokens = 1; /* Only one key possible */
2449 range->num_encoding_sizes = 0;
2450 range->max_encoding_tokens = 0;
2453 /* Enable interrupts and restore flags. */
2454 spin_unlock_irqrestore(&lp->spinlock, flags);
2459 /*------------------------------------------------------------------*/
2461 * Wireless Private Handler : set quality threshold
2463 static int wavelan_set_qthr(struct net_device *dev,
2464 struct iw_request_info *info,
2465 union iwreq_data *wrqu,
2468 ioaddr_t base = dev->base_addr;
2469 net_local *lp = netdev_priv(dev);
2471 unsigned long flags;
2473 /* Disable interrupts and save flags. */
2474 spin_lock_irqsave(&lp->spinlock, flags);
2476 psa.psa_quality_thr = *(extra) & 0x0F;
2478 (char *) &psa.psa_quality_thr - (char *) &psa,
2479 (unsigned char *) &psa.psa_quality_thr, 1);
2480 /* update the Wavelan checksum */
2481 update_psa_checksum(dev);
2482 mmc_out(base, mmwoff(0, mmw_quality_thr),
2483 psa.psa_quality_thr);
2485 /* Enable interrupts and restore flags. */
2486 spin_unlock_irqrestore(&lp->spinlock, flags);
2491 /*------------------------------------------------------------------*/
2493 * Wireless Private Handler : get quality threshold
2495 static int wavelan_get_qthr(struct net_device *dev,
2496 struct iw_request_info *info,
2497 union iwreq_data *wrqu,
2500 net_local *lp = netdev_priv(dev);
2502 unsigned long flags;
2504 /* Disable interrupts and save flags. */
2505 spin_lock_irqsave(&lp->spinlock, flags);
2508 (char *) &psa.psa_quality_thr - (char *) &psa,
2509 (unsigned char *) &psa.psa_quality_thr, 1);
2510 *(extra) = psa.psa_quality_thr & 0x0F;
2512 /* Enable interrupts and restore flags. */
2513 spin_unlock_irqrestore(&lp->spinlock, flags);
2518 #ifdef WAVELAN_ROAMING
2519 /*------------------------------------------------------------------*/
2521 * Wireless Private Handler : set roaming
2523 static int wavelan_set_roam(struct net_device *dev,
2524 struct iw_request_info *info,
2525 union iwreq_data *wrqu,
2528 net_local *lp = netdev_priv(dev);
2529 unsigned long flags;
2531 /* Disable interrupts and save flags. */
2532 spin_lock_irqsave(&lp->spinlock, flags);
2534 /* Note : should check if user == root */
2535 if(do_roaming && (*extra)==0)
2536 wv_roam_cleanup(dev);
2537 else if(do_roaming==0 && (*extra)!=0)
2540 do_roaming = (*extra);
2542 /* Enable interrupts and restore flags. */
2543 spin_unlock_irqrestore(&lp->spinlock, flags);
2548 /*------------------------------------------------------------------*/
2550 * Wireless Private Handler : get quality threshold
2552 static int wavelan_get_roam(struct net_device *dev,
2553 struct iw_request_info *info,
2554 union iwreq_data *wrqu,
2557 *(extra) = do_roaming;
2561 #endif /* WAVELAN_ROAMING */
2564 /*------------------------------------------------------------------*/
2566 * Wireless Private Handler : set histogram
2568 static int wavelan_set_histo(struct net_device *dev,
2569 struct iw_request_info *info,
2570 union iwreq_data *wrqu,
2573 net_local *lp = netdev_priv(dev);
2575 /* Check the number of intervals. */
2576 if (wrqu->data.length > 16) {
2580 /* Disable histo while we copy the addresses.
2581 * As we don't disable interrupts, we need to do this */
2584 /* Are there ranges to copy? */
2585 if (wrqu->data.length > 0) {
2586 /* Copy interval ranges to the driver */
2587 memcpy(lp->his_range, extra, wrqu->data.length);
2591 printk(KERN_DEBUG "Histo :");
2592 for(i = 0; i < wrqu->data.length; i++)
2593 printk(" %d", lp->his_range[i]);
2597 /* Reset result structure. */
2598 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2601 /* Now we can set the number of ranges */
2602 lp->his_number = wrqu->data.length;
2607 /*------------------------------------------------------------------*/
2609 * Wireless Private Handler : get histogram
2611 static int wavelan_get_histo(struct net_device *dev,
2612 struct iw_request_info *info,
2613 union iwreq_data *wrqu,
2616 net_local *lp = netdev_priv(dev);
2618 /* Set the number of intervals. */
2619 wrqu->data.length = lp->his_number;
2621 /* Give back the distribution statistics */
2622 if(lp->his_number > 0)
2623 memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
2627 #endif /* HISTOGRAM */
2629 /*------------------------------------------------------------------*/
2631 * Structures to export the Wireless Handlers
2634 static const struct iw_priv_args wavelan_private_args[] = {
2635 /*{ cmd, set_args, get_args, name } */
2636 { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2637 { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2638 { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" },
2639 { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
2640 { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
2641 { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
2644 static const iw_handler wavelan_handler[] =
2646 NULL, /* SIOCSIWNAME */
2647 wavelan_get_name, /* SIOCGIWNAME */
2648 wavelan_set_nwid, /* SIOCSIWNWID */
2649 wavelan_get_nwid, /* SIOCGIWNWID */
2650 wavelan_set_freq, /* SIOCSIWFREQ */
2651 wavelan_get_freq, /* SIOCGIWFREQ */
2652 #ifdef WAVELAN_ROAMING
2653 wavelan_set_mode, /* SIOCSIWMODE */
2654 wavelan_get_mode, /* SIOCGIWMODE */
2655 #else /* WAVELAN_ROAMING */
2656 NULL, /* SIOCSIWMODE */
2657 NULL, /* SIOCGIWMODE */
2658 #endif /* WAVELAN_ROAMING */
2659 wavelan_set_sens, /* SIOCSIWSENS */
2660 wavelan_get_sens, /* SIOCGIWSENS */
2661 NULL, /* SIOCSIWRANGE */
2662 wavelan_get_range, /* SIOCGIWRANGE */
2663 NULL, /* SIOCSIWPRIV */
2664 NULL, /* SIOCGIWPRIV */
2665 NULL, /* SIOCSIWSTATS */
2666 NULL, /* SIOCGIWSTATS */
2667 iw_handler_set_spy, /* SIOCSIWSPY */
2668 iw_handler_get_spy, /* SIOCGIWSPY */
2669 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2670 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2671 #ifdef WAVELAN_ROAMING_EXT
2672 wavelan_set_wap, /* SIOCSIWAP */
2673 wavelan_get_wap, /* SIOCGIWAP */
2674 NULL, /* -- hole -- */
2675 NULL, /* SIOCGIWAPLIST */
2676 NULL, /* -- hole -- */
2677 NULL, /* -- hole -- */
2678 wavelan_set_essid, /* SIOCSIWESSID */
2679 wavelan_get_essid, /* SIOCGIWESSID */
2680 #else /* WAVELAN_ROAMING_EXT */
2681 NULL, /* SIOCSIWAP */
2682 NULL, /* SIOCGIWAP */
2683 NULL, /* -- hole -- */
2684 NULL, /* SIOCGIWAPLIST */
2685 NULL, /* -- hole -- */
2686 NULL, /* -- hole -- */
2687 NULL, /* SIOCSIWESSID */
2688 NULL, /* SIOCGIWESSID */
2689 #endif /* WAVELAN_ROAMING_EXT */
2690 NULL, /* SIOCSIWNICKN */
2691 NULL, /* SIOCGIWNICKN */
2692 NULL, /* -- hole -- */
2693 NULL, /* -- hole -- */
2694 NULL, /* SIOCSIWRATE */
2695 NULL, /* SIOCGIWRATE */
2696 NULL, /* SIOCSIWRTS */
2697 NULL, /* SIOCGIWRTS */
2698 NULL, /* SIOCSIWFRAG */
2699 NULL, /* SIOCGIWFRAG */
2700 NULL, /* SIOCSIWTXPOW */
2701 NULL, /* SIOCGIWTXPOW */
2702 NULL, /* SIOCSIWRETRY */
2703 NULL, /* SIOCGIWRETRY */
2704 wavelan_set_encode, /* SIOCSIWENCODE */
2705 wavelan_get_encode, /* SIOCGIWENCODE */
2708 static const iw_handler wavelan_private_handler[] =
2710 wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
2711 wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
2712 #ifdef WAVELAN_ROAMING
2713 wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */
2714 wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */
2715 #else /* WAVELAN_ROAMING */
2716 NULL, /* SIOCIWFIRSTPRIV + 2 */
2717 NULL, /* SIOCIWFIRSTPRIV + 3 */
2718 #endif /* WAVELAN_ROAMING */
2720 wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */
2721 wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */
2722 #endif /* HISTOGRAM */
2725 static const struct iw_handler_def wavelan_handler_def =
2727 .num_standard = sizeof(wavelan_handler)/sizeof(iw_handler),
2728 .num_private = sizeof(wavelan_private_handler)/sizeof(iw_handler),
2729 .num_private_args = sizeof(wavelan_private_args)/sizeof(struct iw_priv_args),
2730 .standard = wavelan_handler,
2731 .private = wavelan_private_handler,
2732 .private_args = wavelan_private_args,
2733 .get_wireless_stats = wavelan_get_wireless_stats,
2736 /*------------------------------------------------------------------*/
2738 * Get wireless statistics
2739 * Called by /proc/net/wireless...
2742 wavelan_get_wireless_stats(struct net_device * dev)
2744 ioaddr_t base = dev->base_addr;
2745 net_local * lp = netdev_priv(dev);
2748 unsigned long flags;
2750 #ifdef DEBUG_IOCTL_TRACE
2751 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
2754 /* Disable interrupts & save flags */
2755 spin_lock_irqsave(&lp->spinlock, flags);
2757 wstats = &lp->wstats;
2759 /* Get data from the mmc */
2760 mmc_out(base, mmwoff(0, mmw_freeze), 1);
2762 mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2763 mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
2764 mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
2766 mmc_out(base, mmwoff(0, mmw_freeze), 0);
2768 /* Copy data to wireless stuff */
2769 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2770 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2771 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2772 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2773 wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
2774 ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
2775 ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2776 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2777 wstats->discard.code = 0L;
2778 wstats->discard.misc = 0L;
2780 /* ReEnable interrupts & restore flags */
2781 spin_unlock_irqrestore(&lp->spinlock, flags);
2783 #ifdef DEBUG_IOCTL_TRACE
2784 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
2788 #endif /* WIRELESS_EXT */
2790 /************************* PACKET RECEPTION *************************/
2792 * This part deal with receiving the packets.
2793 * The interrupt handler get an interrupt when a packet has been
2794 * successfully received and called this part...
2797 /*------------------------------------------------------------------*/
2799 * Calculate the starting address of the frame pointed to by the receive
2800 * frame pointer and verify that the frame seem correct
2801 * (called by wv_packet_rcv())
2804 wv_start_of_frame(struct net_device * dev,
2805 int rfp, /* end of frame */
2806 int wrap) /* start of buffer */
2808 ioaddr_t base = dev->base_addr;
2812 rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
2813 outb(rp & 0xff, PIORL(base));
2814 outb(((rp >> 8) & PIORH_MASK), PIORH(base));
2815 len = inb(PIOP(base));
2816 len |= inb(PIOP(base)) << 8;
2818 /* Sanity checks on size */
2820 if(len > MAXDATAZ + 100)
2822 #ifdef DEBUG_RX_ERROR
2823 printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
2824 dev->name, rfp, len);
2829 /* Frame too short */
2832 #ifdef DEBUG_RX_ERROR
2833 printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
2834 dev->name, rfp, len);
2839 /* Wrap around buffer */
2840 if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
2842 #ifdef DEBUG_RX_ERROR
2843 printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
2844 dev->name, wrap, rfp, len);
2849 return((rp - len + RX_SIZE) % RX_SIZE);
2850 } /* wv_start_of_frame */
2852 /*------------------------------------------------------------------*/
2854 * This routine does the actual copy of data (including the ethernet
2855 * header structure) from the WaveLAN card to an sk_buff chain that
2856 * will be passed up to the network interface layer. NOTE: We
2857 * currently don't handle trailer protocols (neither does the rest of
2858 * the network interface), so if that is needed, it will (at least in
2859 * part) be added here. The contents of the receive ring buffer are
2860 * copied to a message chain that is then passed to the kernel.
2862 * Note: if any errors occur, the packet is "dropped on the floor"
2863 * (called by wv_packet_rcv())
2866 wv_packet_read(struct net_device * dev,
2870 net_local * lp = netdev_priv(dev);
2871 struct sk_buff * skb;
2873 #ifdef DEBUG_RX_TRACE
2874 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2875 dev->name, fd_p, sksize);
2878 /* Allocate some buffer for the new packet */
2879 if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
2881 #ifdef DEBUG_RX_ERROR
2882 printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
2885 lp->stats.rx_dropped++;
2887 * Not only do we want to return here, but we also need to drop the
2888 * packet on the floor to clear the interrupt.
2895 skb_reserve(skb, 2);
2896 fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
2897 skb->protocol = eth_type_trans(skb, dev);
2899 #ifdef DEBUG_RX_INFO
2900 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2901 #endif /* DEBUG_RX_INFO */
2903 /* Statistics gathering & stuff associated.
2904 * It seem a bit messy with all the define, but it's really simple... */
2906 #ifdef IW_WIRELESS_SPY
2907 (lp->spy_data.spy_number > 0) ||
2908 #endif /* IW_WIRELESS_SPY */
2910 (lp->his_number > 0) ||
2911 #endif /* HISTOGRAM */
2912 #ifdef WAVELAN_ROAMING
2914 #endif /* WAVELAN_ROAMING */
2917 u_char stats[3]; /* Signal level, Noise level, Signal quality */
2919 /* read signal level, silence level and signal quality bytes */
2920 fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
2922 #ifdef DEBUG_RX_INFO
2923 printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2924 dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
2927 #ifdef WAVELAN_ROAMING
2929 if(WAVELAN_BEACON(skb->data))
2930 wl_roam_gather(dev, skb->data, stats);
2931 #endif /* WAVELAN_ROAMING */
2934 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
2935 #endif /* WIRELESS_SPY */
2937 wl_his_gather(dev, stats);
2938 #endif /* HISTOGRAM */
2942 * Hand the packet to the Network Module
2946 /* Keep stats up to date */
2947 dev->last_rx = jiffies;
2948 lp->stats.rx_packets++;
2949 lp->stats.rx_bytes += sksize;
2951 #ifdef DEBUG_RX_TRACE
2952 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2957 /*------------------------------------------------------------------*/
2959 * This routine is called by the interrupt handler to initiate a
2960 * packet transfer from the card to the network interface layer above
2961 * this driver. This routine checks if a buffer has been successfully
2962 * received by the WaveLAN card. If so, the routine wv_packet_read is
2963 * called to do the actual transfer of the card's data including the
2964 * ethernet header into a packet consisting of an sk_buff chain.
2965 * (called by wavelan_interrupt())
2966 * Note : the spinlock is already grabbed for us and irq are disabled.
2969 wv_packet_rcv(struct net_device * dev)
2971 ioaddr_t base = dev->base_addr;
2972 net_local * lp = netdev_priv(dev);
2982 #ifdef DEBUG_RX_TRACE
2983 printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
2986 /* Get the new receive frame pointer from the i82593 chip */
2987 outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
2988 i593_rfp = inb(LCSR(base));
2989 i593_rfp |= inb(LCSR(base)) << 8;
2990 i593_rfp %= RX_SIZE;
2992 /* Get the new receive frame pointer from the WaveLAN card.
2993 * It is 3 bytes more than the increment of the i82593 receive
2994 * frame pointer, for each packet. This is because it includes the
2995 * 3 roaming bytes added by the mmc.
2997 newrfp = inb(RPLL(base));
2998 newrfp |= inb(RPLH(base)) << 8;
3001 #ifdef DEBUG_RX_INFO
3002 printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3003 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
3006 #ifdef DEBUG_RX_ERROR
3007 /* If no new frame pointer... */
3008 if(lp->overrunning || newrfp == lp->rfp)
3009 printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3010 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
3013 /* Read all frames (packets) received */
3014 while(newrfp != lp->rfp)
3016 /* A frame is composed of the packet, followed by a status word,
3017 * the length of the frame (word) and the mmc info (SNR & qual).
3018 * It's because the length is at the end that we can only scan
3019 * frames backward. */
3021 /* Find the first frame by skipping backwards over the frames */
3022 rp = newrfp; /* End of last frame */
3023 while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
3027 /* If we had a problem */
3030 #ifdef DEBUG_RX_ERROR
3031 printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
3032 printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3033 i593_rfp, lp->stop, newrfp, lp->rfp);
3035 lp->rfp = rp; /* Get to the last usable frame */
3039 /* f_start point to the beggining of the first frame received
3040 * and rp to the beggining of the next one */
3042 /* Read status & length of the frame */
3043 stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
3044 stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
3045 status = c[0] | (c[1] << 8);
3046 len = c[2] | (c[3] << 8);
3049 if((status & RX_RCV_OK) != RX_RCV_OK)
3051 lp->stats.rx_errors++;
3052 if(status & RX_NO_SFD)
3053 lp->stats.rx_frame_errors++;
3054 if(status & RX_CRC_ERR)
3055 lp->stats.rx_crc_errors++;
3056 if(status & RX_OVRRUN)
3057 lp->stats.rx_over_errors++;
3059 #ifdef DEBUG_RX_FAIL
3060 printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
3065 /* Read the packet and transmit to Linux */
3066 wv_packet_read(dev, f_start, len - 2);
3068 /* One frame has been processed, skip it */
3073 * Update the frame stop register, but set it to less than
3074 * the full 8K to allow space for 3 bytes of signal strength
3077 lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3078 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3079 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3080 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3082 #ifdef DEBUG_RX_TRACE
3083 printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
3087 /*********************** PACKET TRANSMISSION ***********************/
3089 * This part deal with sending packet through the wavelan
3090 * We copy the packet to the send buffer and then issue the send
3091 * command to the i82593. The result of this operation will be
3092 * checked in wavelan_interrupt()
3095 /*------------------------------------------------------------------*/
3097 * This routine fills in the appropriate registers and memory
3098 * locations on the WaveLAN card and starts the card off on
3100 * (called in wavelan_packet_xmit())
3103 wv_packet_write(struct net_device * dev,
3107 net_local * lp = netdev_priv(dev);
3108 ioaddr_t base = dev->base_addr;
3109 unsigned long flags;
3111 register u_short xmtdata_base = TX_BASE;
3113 #ifdef DEBUG_TX_TRACE
3114 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
3117 spin_lock_irqsave(&lp->spinlock, flags);
3119 /* Write the length of data buffer followed by the buffer */
3120 outb(xmtdata_base & 0xff, PIORL(base));
3121 outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3122 outb(clen & 0xff, PIOP(base)); /* lsb */
3123 outb(clen >> 8, PIOP(base)); /* msb */
3126 outsb(PIOP(base), buf, clen);
3128 /* Indicate end of transmit chain */
3129 outb(OP0_NOP, PIOP(base));
3130 /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
3131 outb(OP0_NOP, PIOP(base));
3133 /* Reset the transmit DMA pointer */
3134 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3135 hacr_write(base, HACR_DEFAULT);
3136 /* Send the transmit command */
3137 wv_82593_cmd(dev, "wv_packet_write(): transmit",
3138 OP0_TRANSMIT, SR0_NO_RESULT);
3140 /* Make sure the watchdog will keep quiet for a while */
3141 dev->trans_start = jiffies;
3143 /* Keep stats up to date */
3144 lp->stats.tx_bytes += length;
3146 spin_unlock_irqrestore(&lp->spinlock, flags);
3148 #ifdef DEBUG_TX_INFO
3149 wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
3150 #endif /* DEBUG_TX_INFO */
3152 #ifdef DEBUG_TX_TRACE
3153 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
3157 /*------------------------------------------------------------------*/
3159 * This routine is called when we want to send a packet (NET3 callback)
3160 * In this routine, we check if the harware is ready to accept
3161 * the packet. We also prevent reentrance. Then, we call the function
3162 * to send the packet...
3165 wavelan_packet_xmit(struct sk_buff * skb,
3166 struct net_device * dev)
3168 net_local * lp = netdev_priv(dev);
3169 unsigned long flags;
3171 #ifdef DEBUG_TX_TRACE
3172 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
3177 * Block a timer-based transmit from overlapping a previous transmit.
3178 * In other words, prevent reentering this routine.
3180 netif_stop_queue(dev);
3182 /* If somebody has asked to reconfigure the controller,
3183 * we can do it now */
3184 if(lp->reconfig_82593)
3186 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
3187 wv_82593_config(dev);
3188 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
3189 /* Note : the configure procedure was totally synchronous,
3190 * so the Tx buffer is now free */
3193 #ifdef DEBUG_TX_ERROR
3195 printk(KERN_INFO "skb has next\n");
3198 /* Check if we need some padding */
3199 /* Note : on wireless the propagation time is in the order of 1us,
3200 * and we don't have the Ethernet specific requirement of beeing
3201 * able to detect collisions, therefore in theory we don't really
3202 * need to pad. Jean II */
3203 if (skb->len < ETH_ZLEN) {
3204 skb = skb_padto(skb, ETH_ZLEN);
3209 wv_packet_write(dev, skb->data, skb->len);
3213 #ifdef DEBUG_TX_TRACE
3214 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
3219 /********************** HARDWARE CONFIGURATION **********************/
3221 * This part do the real job of starting and configuring the hardware.
3224 /*------------------------------------------------------------------*/
3226 * Routine to initialize the Modem Management Controller.
3227 * (called by wv_hw_config())
3230 wv_mmc_init(struct net_device * dev)
3232 ioaddr_t base = dev->base_addr;
3236 int i; /* Loop counter */
3238 #ifdef DEBUG_CONFIG_TRACE
3239 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
3242 /* Read the parameter storage area */
3243 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3246 * Check the first three octets of the MAC addr for the manufacturer's code.
3247 * Note: If you get the error message below, you've got a
3248 * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
3249 * how to configure your card...
3251 for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3252 if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
3253 (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
3254 (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
3257 /* If we have not found it... */
3258 if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
3260 #ifdef DEBUG_CONFIG_ERRORS
3261 printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
3262 dev->name, psa.psa_univ_mac_addr[0],
3263 psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
3268 /* Get the MAC address */
3269 memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
3271 #ifdef USE_PSA_CONFIG
3272 configured = psa.psa_conf_status & 1;
3277 /* Is the PSA is not configured */
3280 /* User will be able to configure NWID after (with iwconfig) */
3281 psa.psa_nwid[0] = 0;
3282 psa.psa_nwid[1] = 0;
3284 /* As NWID is not set : no NWID checking */
3285 psa.psa_nwid_select = 0;
3287 /* Disable encryption */
3288 psa.psa_encryption_select = 0;
3290 /* Set to standard values
3293 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
3295 if (psa.psa_comp_number & 1)
3296 psa.psa_thr_pre_set = 0x01;
3298 psa.psa_thr_pre_set = 0x04;
3299 psa.psa_quality_thr = 0x03;
3301 /* It is configured */
3302 psa.psa_conf_status |= 1;
3304 #ifdef USE_PSA_CONFIG
3306 psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
3307 (unsigned char *)psa.psa_nwid, 4);
3308 psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
3309 (unsigned char *)&psa.psa_thr_pre_set, 1);
3310 psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
3311 (unsigned char *)&psa.psa_quality_thr, 1);
3312 psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
3313 (unsigned char *)&psa.psa_conf_status, 1);
3314 /* update the Wavelan checksum */
3315 update_psa_checksum(dev);
3316 #endif /* USE_PSA_CONFIG */
3319 /* Zero the mmc structure */
3320 memset(&m, 0x00, sizeof(m));
3322 /* Copy PSA info to the mmc */
3323 m.mmw_netw_id_l = psa.psa_nwid[1];
3324 m.mmw_netw_id_h = psa.psa_nwid[0];
3326 if(psa.psa_nwid_select & 1)
3327 m.mmw_loopt_sel = 0x00;
3329 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
3331 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
3332 sizeof(m.mmw_encr_key));
3334 if(psa.psa_encryption_select)
3335 m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
3337 m.mmw_encr_enable = 0;
3339 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
3340 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
3343 * Set default modem control parameters.
3344 * See NCR document 407-0024326 Rev. A.
3346 m.mmw_jabber_enable = 0x01;
3347 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
3349 m.mmw_mod_delay = 0x04;
3350 m.mmw_jam_time = 0x38;
3352 m.mmw_des_io_invert = 0;
3354 m.mmw_decay_prm = 0;
3355 m.mmw_decay_updat_prm = 0;
3357 /* Write all info to mmc */
3358 mmc_write(base, 0, (u_char *)&m, sizeof(m));
3360 /* The following code start the modem of the 2.00 frequency
3361 * selectable cards at power on. It's not strictly needed for the
3362 * following boots...
3363 * The original patch was by Joe Finney for the PCMCIA driver, but
3364 * I've cleaned it a bit and add documentation.
3365 * Thanks to Loeke Brederveld from Lucent for the info.
3368 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3369 * (does it work for everybody ? - especially old cards...) */
3370 /* Note : WFREQSEL verify that it is able to read from EEprom
3371 * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
3372 * is 0xA (Xilinx version) or 0xB (Ariadne version).
3373 * My test is more crude but do work... */
3374 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
3375 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
3377 /* We must download the frequency parameters to the
3378 * synthetisers (from the EEprom - area 1)
3379 * Note : as the EEprom is auto decremented, we set the end
3381 m.mmw_fee_addr = 0x0F;
3382 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3383 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3384 (unsigned char *)&m.mmw_fee_ctrl, 2);
3386 /* Wait until the download is finished */
3387 fee_wait(base, 100, 100);
3389 #ifdef DEBUG_CONFIG_INFO
3390 /* The frequency was in the last word downloaded... */
3391 mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
3392 (unsigned char *)&m.mmw_fee_data_l, 2);
3394 /* Print some info for the user */
3395 printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
3397 ((m.mmw_fee_data_h << 4) |
3398 (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
3401 /* We must now download the power adjust value (gain) to
3402 * the synthetisers (from the EEprom - area 7 - DAC) */
3403 m.mmw_fee_addr = 0x61;
3404 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3405 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3406 (unsigned char *)&m.mmw_fee_ctrl, 2);
3408 /* Wait until the download is finished */
3409 } /* if 2.00 card */
3411 #ifdef DEBUG_CONFIG_TRACE
3412 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3417 /*------------------------------------------------------------------*/
3419 * Routine to gracefully turn off reception, and wait for any commands
3421 * (called in wv_ru_start() and wavelan_close() and wavelan_event())
3424 wv_ru_stop(struct net_device * dev)
3426 ioaddr_t base = dev->base_addr;
3427 net_local * lp = netdev_priv(dev);
3428 unsigned long flags;
3432 #ifdef DEBUG_CONFIG_TRACE
3433 printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
3436 spin_lock_irqsave(&lp->spinlock, flags);
3438 /* First, send the LAN controller a stop receive command */
3439 wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
3440 OP0_STOP_RCV, SR0_NO_RESULT);
3442 /* Then, spin until the receive unit goes idle */
3447 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3448 status = inb(LCSR(base));
3450 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
3452 /* Now, spin until the chip finishes executing its current command */
3456 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3457 status = inb(LCSR(base));
3459 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
3461 spin_unlock_irqrestore(&lp->spinlock, flags);
3463 /* If there was a problem */
3466 #ifdef DEBUG_CONFIG_ERROR
3467 printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
3473 #ifdef DEBUG_CONFIG_TRACE
3474 printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
3479 /*------------------------------------------------------------------*/
3481 * This routine starts the receive unit running. First, it checks if
3482 * the card is actually ready. Then the card is instructed to receive
3484 * (called in wv_hw_reset() & wavelan_open())
3487 wv_ru_start(struct net_device * dev)
3489 ioaddr_t base = dev->base_addr;
3490 net_local * lp = netdev_priv(dev);
3491 unsigned long flags;
3493 #ifdef DEBUG_CONFIG_TRACE
3494 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3498 * We need to start from a quiescent state. To do so, we could check
3499 * if the card is already running, but instead we just try to shut
3500 * it down. First, we disable reception (in case it was already enabled).
3502 if(!wv_ru_stop(dev))
3505 spin_lock_irqsave(&lp->spinlock, flags);
3507 /* Now we know that no command is being executed. */
3509 /* Set the receive frame pointer and stop pointer */
3511 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3513 /* Reset ring management. This sets the receive frame pointer to 1 */
3514 outb(OP1_RESET_RING_MNGMT, LCCR(base));
3517 /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
3518 should be set as below */
3519 /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
3521 /* but I set it 0 instead */
3524 /* but I set it to 3 bytes per packet less than 8K */
3525 lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3527 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3528 outb(OP1_INT_ENABLE, LCCR(base));
3529 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3531 /* Reset receive DMA pointer */
3532 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3533 hacr_write_slow(base, HACR_DEFAULT);
3535 /* Receive DMA on channel 1 */
3536 wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
3537 CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
3539 #ifdef DEBUG_I82593_SHOW
3545 /* spin until the chip starts receiving */
3548 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3549 status = inb(LCSR(base));
3553 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
3554 ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
3555 printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
3556 (status & SR3_RCV_STATE_MASK), i);
3560 spin_unlock_irqrestore(&lp->spinlock, flags);
3562 #ifdef DEBUG_CONFIG_TRACE
3563 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3568 /*------------------------------------------------------------------*/
3570 * This routine does a standard config of the WaveLAN controller (i82593).
3571 * In the ISA driver, this is integrated in wavelan_hardware_reset()
3572 * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
3575 wv_82593_config(struct net_device * dev)
3577 ioaddr_t base = dev->base_addr;
3578 net_local * lp = netdev_priv(dev);
3579 struct i82593_conf_block cfblk;
3582 #ifdef DEBUG_CONFIG_TRACE
3583 printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
3586 /* Create & fill i82593 config block
3588 * Now conform to Wavelan document WCIN085B
3590 memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
3591 cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
3592 cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
3593 cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
3595 cfblk.throttle_enb = FALSE;
3596 cfblk.contin = TRUE; /* enable continuous mode */
3597 cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
3598 cfblk.addr_len = WAVELAN_ADDR_SIZE;
3599 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
3600 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
3601 cfblk.loopback = FALSE;
3602 cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */
3603 cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */
3604 cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */
3605 cfblk.ifrm_spc = 0x20; /* 32 bit times interframe spacing */
3606 cfblk.slottim_low = 0x20; /* 32 bit times slot time */
3607 cfblk.slottim_hi = 0x0;
3608 cfblk.max_retr = 15;
3609 cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
3610 cfblk.bc_dis = FALSE; /* Enable broadcast reception */
3611 cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
3612 cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
3613 cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
3614 cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
3615 cfblk.cs_filter = 0; /* CS is recognized immediately */
3616 cfblk.crs_src = FALSE; /* External carrier sense */
3617 cfblk.cd_filter = 0; /* CD is recognized immediately */
3618 cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
3619 cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
3620 cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
3621 cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
3622 cfblk.artx = TRUE; /* Disable automatic retransmission */
3623 cfblk.sarec = TRUE; /* Disable source addr trig of CD */
3624 cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
3625 cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
3626 cfblk.lbpkpol = TRUE; /* Loopback pin active high */
3627 cfblk.fdx = FALSE; /* Disable full duplex operation */
3628 cfblk.dummy_6 = 0x3f; /* all ones */
3629 cfblk.mult_ia = FALSE; /* No multiple individual addresses */
3630 cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
3631 cfblk.dummy_1 = TRUE; /* set to 1 */
3632 cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
3633 #ifdef MULTICAST_ALL
3634 cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
3636 cfblk.mc_all = FALSE; /* No multicast all mode */
3638 cfblk.rcv_mon = 0; /* Monitor mode disabled */
3639 cfblk.frag_acpt = TRUE; /* Do not accept fragments */
3640 cfblk.tstrttrs = FALSE; /* No start transmission threshold */
3641 cfblk.fretx = TRUE; /* FIFO automatic retransmission */
3642 cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
3643 cfblk.sttlen = TRUE; /* 6 byte status registers */
3644 cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
3645 cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
3646 cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
3647 cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
3649 #ifdef DEBUG_I82593_SHOW
3651 u_char *c = (u_char *) &cfblk;
3653 printk(KERN_DEBUG "wavelan_cs: config block:");
3654 for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
3656 if((i % 16) == 0) printk("\n" KERN_DEBUG);
3657 printk("%02x ", *c);
3663 /* Copy the config block to the i82593 */
3664 outb(TX_BASE & 0xff, PIORL(base));
3665 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3666 outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
3667 outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
3668 outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
3670 /* reset transmit DMA pointer */
3671 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3672 hacr_write(base, HACR_DEFAULT);
3673 if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
3674 OP0_CONFIGURE, SR0_CONFIGURE_DONE))
3677 /* Initialize adapter's ethernet MAC address */
3678 outb(TX_BASE & 0xff, PIORL(base));
3679 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3680 outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
3681 outb(0, PIOP(base)); /* byte count msb */
3682 outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
3684 /* reset transmit DMA pointer */
3685 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3686 hacr_write(base, HACR_DEFAULT);
3687 if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
3688 OP0_IA_SETUP, SR0_IA_SETUP_DONE))
3691 #ifdef WAVELAN_ROAMING
3692 /* If roaming is enabled, join the "Beacon Request" multicast group... */
3693 /* But only if it's not in there already! */
3695 dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
3696 #endif /* WAVELAN_ROAMING */
3698 /* If any multicast address to set */
3701 struct dev_mc_list * dmi;
3702 int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
3704 #ifdef DEBUG_CONFIG_INFO
3705 printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
3706 dev->name, lp->mc_count);
3707 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3708 printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n",
3709 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
3710 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
3713 /* Initialize adapter's ethernet multicast addresses */
3714 outb(TX_BASE & 0xff, PIORL(base));
3715 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3716 outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
3717 outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
3718 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3719 outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
3721 /* reset transmit DMA pointer */
3722 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3723 hacr_write(base, HACR_DEFAULT);
3724 if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
3725 OP0_MC_SETUP, SR0_MC_SETUP_DONE))
3727 lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
3730 /* Job done, clear the flag */
3731 lp->reconfig_82593 = FALSE;
3733 #ifdef DEBUG_CONFIG_TRACE
3734 printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
3739 /*------------------------------------------------------------------*/
3741 * Read the Access Configuration Register, perform a software reset,
3742 * and then re-enable the card's software.
3744 * If I understand correctly : reset the pcmcia interface of the
3746 * (called by wv_config())
3749 wv_pcmcia_reset(struct net_device * dev)
3752 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
3753 dev_link_t * link = ((net_local *)netdev_priv(dev))->link;
3755 #ifdef DEBUG_CONFIG_TRACE
3756 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
3759 i = pcmcia_access_configuration_register(link->handle, ®);
3762 cs_error(link->handle, AccessConfigurationRegister, i);
3766 #ifdef DEBUG_CONFIG_INFO
3767 printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
3768 dev->name, (u_int) reg.Value);
3771 reg.Action = CS_WRITE;
3772 reg.Value = reg.Value | COR_SW_RESET;
3773 i = pcmcia_access_configuration_register(link->handle, ®);
3776 cs_error(link->handle, AccessConfigurationRegister, i);
3780 reg.Action = CS_WRITE;
3781 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3782 i = pcmcia_access_configuration_register(link->handle, ®);
3785 cs_error(link->handle, AccessConfigurationRegister, i);
3789 #ifdef DEBUG_CONFIG_TRACE
3790 printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
3795 /*------------------------------------------------------------------*/
3797 * wavelan_hw_config() is called after a CARD_INSERTION event is
3798 * received, to configure the wavelan hardware.
3799 * Note that the reception will be enabled in wavelan->open(), so the
3800 * device is configured but idle...
3801 * Performs the following actions:
3802 * 1. A pcmcia software reset (using wv_pcmcia_reset())
3803 * 2. A power reset (reset DMA)
3804 * 3. Reset the LAN controller
3805 * 4. Initialize the radio modem (using wv_mmc_init)
3806 * 5. Configure LAN controller (using wv_82593_config)
3807 * 6. Perform a diagnostic on the LAN controller
3808 * (called by wavelan_event() & wv_hw_reset())
3811 wv_hw_config(struct net_device * dev)
3813 net_local * lp = netdev_priv(dev);
3814 ioaddr_t base = dev->base_addr;
3815 unsigned long flags;
3818 #ifdef DEBUG_CONFIG_TRACE
3819 printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
3823 if(wv_structuct_check() != (char *) NULL)
3825 printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: \"%s\"\n",
3826 dev->name, wv_structuct_check());
3829 #endif /* STRUCT_CHECK == 1 */
3831 /* Reset the pcmcia interface */
3832 if(wv_pcmcia_reset(dev) == FALSE)
3835 /* Disable interrupts */
3836 spin_lock_irqsave(&lp->spinlock, flags);
3838 /* Disguised goto ;-) */
3841 /* Power UP the module + reset the modem + reset host adapter
3842 * (in fact, reset DMA channels) */
3843 hacr_write_slow(base, HACR_RESET);
3844 hacr_write(base, HACR_DEFAULT);
3846 /* Check if the module has been powered up... */
3847 if(hasr_read(base) & HASR_NO_CLK)
3849 #ifdef DEBUG_CONFIG_ERRORS
3850 printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
3856 /* initialize the modem */
3857 if(wv_mmc_init(dev) == FALSE)
3859 #ifdef DEBUG_CONFIG_ERRORS
3860 printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n",
3866 /* reset the LAN controller (i82593) */
3867 outb(OP0_RESET, LCCR(base));
3868 mdelay(1); /* A bit crude ! */
3870 /* Initialize the LAN controller */
3871 if(wv_82593_config(dev) == FALSE)
3873 #ifdef DEBUG_CONFIG_ERRORS
3874 printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n",
3881 if(wv_diag(dev) == FALSE)
3883 #ifdef DEBUG_CONFIG_ERRORS
3884 printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n",
3891 * insert code for loopback test here
3894 /* The device is now configured */
3900 /* Re-enable interrupts */
3901 spin_unlock_irqrestore(&lp->spinlock, flags);
3903 #ifdef DEBUG_CONFIG_TRACE
3904 printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
3909 /*------------------------------------------------------------------*/
3911 * Totally reset the wavelan and restart it.
3912 * Performs the following actions:
3913 * 1. Call wv_hw_config()
3914 * 2. Start the LAN controller's receive unit
3915 * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
3918 wv_hw_reset(struct net_device * dev)
3920 net_local * lp = netdev_priv(dev);
3922 #ifdef DEBUG_CONFIG_TRACE
3923 printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
3929 /* Call wv_hw_config() for most of the reset & init stuff */
3930 if(wv_hw_config(dev) == FALSE)
3933 /* start receive unit */
3936 #ifdef DEBUG_CONFIG_TRACE
3937 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3941 /*------------------------------------------------------------------*/
3943 * wv_pcmcia_config() is called after a CARD_INSERTION event is
3944 * received, to configure the PCMCIA socket, and to make the ethernet
3945 * device available to the system.
3946 * (called by wavelan_event())
3949 wv_pcmcia_config(dev_link_t * link)
3951 client_handle_t handle;
3954 struct net_device * dev;
3960 handle = link->handle;
3961 dev = (struct net_device *) link->priv;
3963 #ifdef DEBUG_CONFIG_TRACE
3964 printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
3968 * This reads the card's CONFIG tuple to find its configuration
3973 tuple.Attributes = 0;
3974 tuple.DesiredTuple = CISTPL_CONFIG;
3975 i = pcmcia_get_first_tuple(handle, &tuple);
3978 tuple.TupleData = (cisdata_t *)buf;
3979 tuple.TupleDataMax = 64;
3980 tuple.TupleOffset = 0;
3981 i = pcmcia_get_tuple_data(handle, &tuple);
3984 i = pcmcia_parse_tuple(handle, &tuple, &parse);
3987 link->conf.ConfigBase = parse.config.base;
3988 link->conf.Present = parse.config.rmask[0];
3993 cs_error(link->handle, ParseTuple, i);
3994 link->state &= ~DEV_CONFIG_PENDING;
3998 /* Configure card */
3999 link->state |= DEV_CONFIG;
4002 i = pcmcia_request_io(link->handle, &link->io);
4005 cs_error(link->handle, RequestIO, i);
4010 * Now allocate an interrupt line. Note that this does not
4011 * actually assign a handler to the interrupt.
4013 i = pcmcia_request_irq(link->handle, &link->irq);
4016 cs_error(link->handle, RequestIRQ, i);
4021 * This actually configures the PCMCIA socket -- setting up
4022 * the I/O windows and the interrupt mapping.
4024 link->conf.ConfigIndex = 1;
4025 i = pcmcia_request_configuration(link->handle, &link->conf);
4028 cs_error(link->handle, RequestConfiguration, i);
4033 * Allocate a small memory window. Note that the dev_link_t
4034 * structure provides space for one window handle -- if your
4035 * device needs several windows, you'll need to keep track of
4036 * the handles in your private data structure, link->priv.
4038 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
4039 req.Base = req.Size = 0;
4040 req.AccessSpeed = mem_speed;
4041 i = pcmcia_request_window(&link->handle, &req, &link->win);
4044 cs_error(link->handle, RequestWindow, i);
4048 dev->mem_start = (u_long)ioremap(req.Base, req.Size);
4049 dev->mem_end = dev->mem_start + req.Size;
4051 mem.CardOffset = 0; mem.Page = 0;
4052 i = pcmcia_map_mem_page(link->win, &mem);
4055 cs_error(link->handle, MapMemPage, i);
4059 /* Feed device with this info... */
4060 dev->irq = link->irq.AssignedIRQ;
4061 dev->base_addr = link->io.BasePort1;
4062 netif_start_queue(dev);
4064 #ifdef DEBUG_CONFIG_INFO
4065 printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART 0x%x IRQ %d IOPORT 0x%x\n",
4066 (u_int) dev->mem_start, dev->irq, (u_int) dev->base_addr);
4069 i = register_netdev(dev);
4072 #ifdef DEBUG_CONFIG_ERRORS
4073 printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
4078 while(0); /* Humm... Disguised goto !!! */
4080 link->state &= ~DEV_CONFIG_PENDING;
4081 /* If any step failed, release any partially configured state */
4084 wv_pcmcia_release(link);
4088 strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
4089 link->dev = &((net_local *) netdev_priv(dev))->node;
4091 #ifdef DEBUG_CONFIG_TRACE
4092 printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
4097 /*------------------------------------------------------------------*/
4099 * After a card is removed, wv_pcmcia_release() will unregister the net
4100 * device, and release the PCMCIA configuration. If the device is
4101 * still open, this will be postponed until it is closed.
4104 wv_pcmcia_release(dev_link_t *link)
4106 struct net_device * dev = (struct net_device *) link->priv;
4108 #ifdef DEBUG_CONFIG_TRACE
4109 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
4112 /* Don't bother checking to see if these succeed or not */
4113 iounmap((u_char *)dev->mem_start);
4114 pcmcia_release_window(link->win);
4115 pcmcia_release_configuration(link->handle);
4116 pcmcia_release_io(link->handle, &link->io);
4117 pcmcia_release_irq(link->handle, &link->irq);
4119 link->state &= ~DEV_CONFIG;
4121 #ifdef DEBUG_CONFIG_TRACE
4122 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
4126 /************************ INTERRUPT HANDLING ************************/
4129 * This function is the interrupt handler for the WaveLAN card. This
4130 * routine will be called whenever:
4131 * 1. A packet is received.
4132 * 2. A packet has successfully been transferred and the unit is
4133 * ready to transmit another packet.
4134 * 3. A command has completed execution.
4137 wavelan_interrupt(int irq,
4139 struct pt_regs * regs)
4141 struct net_device * dev;
4147 if ((dev = dev_id) == NULL)
4149 #ifdef DEBUG_INTERRUPT_ERROR
4150 printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.\n",
4156 #ifdef DEBUG_INTERRUPT_TRACE
4157 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
4160 lp = netdev_priv(dev);
4161 base = dev->base_addr;
4163 #ifdef DEBUG_INTERRUPT_INFO
4164 /* Check state of our spinlock (it should be cleared) */
4165 if(spin_is_locked(&lp->spinlock))
4167 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
4171 /* Prevent reentrancy. We need to do that because we may have
4172 * multiple interrupt handler running concurently.
4173 * It is safe because interrupts are disabled before aquiring
4175 spin_lock(&lp->spinlock);
4177 /* Treat all pending interrupts */
4180 /* ---------------- INTERRUPT CHECKING ---------------- */
4182 * Look for the interrupt and verify the validity
4184 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
4185 status0 = inb(LCSR(base));
4187 #ifdef DEBUG_INTERRUPT_INFO
4188 printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
4189 (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
4190 if(status0&SR0_INTERRUPT)
4192 printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
4193 ((status0 & SR0_EXECUTION) ? "cmd" :
4194 ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
4195 (status0 & SR0_EVENT_MASK));
4201 /* Return if no actual interrupt from i82593 (normal exit) */
4202 if(!(status0 & SR0_INTERRUPT))
4205 /* If interrupt is both Rx and Tx or none...
4206 * This code in fact is there to catch the spurious interrupt
4207 * when you remove the wavelan pcmcia card from the socket */
4208 if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
4209 ((status0 & SR0_BOTH_RX_TX) == 0x0))
4211 #ifdef DEBUG_INTERRUPT_INFO
4212 printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
4213 dev->name, status0);
4215 /* Acknowledge the interrupt */
4216 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4220 /* ----------------- RECEIVING PACKET ----------------- */
4222 * When the wavelan signal the reception of a new packet,
4223 * we call wv_packet_rcv() to copy if from the buffer and
4226 if(status0 & SR0_RECEPTION)
4228 #ifdef DEBUG_INTERRUPT_INFO
4229 printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
4232 if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
4234 #ifdef DEBUG_INTERRUPT_ERROR
4235 printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
4238 lp->stats.rx_over_errors++;
4239 lp->overrunning = 1;
4242 /* Get the packet */
4244 lp->overrunning = 0;
4246 /* Acknowledge the interrupt */
4247 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4251 /* ---------------- COMMAND COMPLETION ---------------- */
4253 * Interrupts issued when the i82593 has completed a command.
4254 * Most likely : transmission done
4257 /* If a transmission has been done */
4258 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
4259 (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
4260 (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4262 #ifdef DEBUG_TX_ERROR
4263 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4264 printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
4268 /* Get transmission status */
4269 tx_status = inb(LCSR(base));
4270 tx_status |= (inb(LCSR(base)) << 8);
4271 #ifdef DEBUG_INTERRUPT_INFO
4272 printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
4277 rcv_bytes = inb(LCSR(base));
4278 rcv_bytes |= (inb(LCSR(base)) << 8);
4279 status3 = inb(LCSR(base));
4280 printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
4281 tx_status, rcv_bytes, (u_int) status3);
4284 /* Check for possible errors */
4285 if((tx_status & TX_OK) != TX_OK)
4287 lp->stats.tx_errors++;
4289 if(tx_status & TX_FRTL)
4291 #ifdef DEBUG_TX_ERROR
4292 printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
4296 if(tx_status & TX_UND_RUN)
4298 #ifdef DEBUG_TX_FAIL
4299 printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
4302 lp->stats.tx_aborted_errors++;
4304 if(tx_status & TX_LOST_CTS)
4306 #ifdef DEBUG_TX_FAIL
4307 printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
4309 lp->stats.tx_carrier_errors++;
4311 if(tx_status & TX_LOST_CRS)
4313 #ifdef DEBUG_TX_FAIL
4314 printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
4317 lp->stats.tx_carrier_errors++;
4319 if(tx_status & TX_HRT_BEAT)
4321 #ifdef DEBUG_TX_FAIL
4322 printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
4324 lp->stats.tx_heartbeat_errors++;
4326 if(tx_status & TX_DEFER)
4328 #ifdef DEBUG_TX_FAIL
4329 printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
4333 /* Ignore late collisions since they're more likely to happen
4334 * here (the WaveLAN design prevents the LAN controller from
4335 * receiving while it is transmitting). We take action only when
4336 * the maximum retransmit attempts is exceeded.
4338 if(tx_status & TX_COLL)
4340 if(tx_status & TX_MAX_COL)
4342 #ifdef DEBUG_TX_FAIL
4343 printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
4346 if(!(tx_status & TX_NCOL_MASK))
4348 lp->stats.collisions += 0x10;
4352 } /* if(!(tx_status & TX_OK)) */
4354 lp->stats.collisions += (tx_status & TX_NCOL_MASK);
4355 lp->stats.tx_packets++;
4357 netif_wake_queue(dev);
4358 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4360 else /* if interrupt = transmit done or retransmit done */
4362 #ifdef DEBUG_INTERRUPT_ERROR
4363 printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
4366 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4370 spin_unlock(&lp->spinlock);
4372 #ifdef DEBUG_INTERRUPT_TRACE
4373 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
4376 /* We always return IRQ_HANDLED, because we will receive empty
4377 * interrupts under normal operations. Anyway, it doesn't matter
4378 * as we are dealing with an ISA interrupt that can't be shared.
4380 * Explanation : under heavy receive, the following happens :
4381 * ->wavelan_interrupt()
4382 * (status0 & SR0_INTERRUPT) != 0
4384 * (status0 & SR0_INTERRUPT) != 0
4386 * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event
4387 * <-wavelan_interrupt()
4388 * ->wavelan_interrupt()
4389 * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt
4390 * <-wavelan_interrupt()
4393 } /* wv_interrupt */
4395 /*------------------------------------------------------------------*/
4397 * Watchdog: when we start a transmission, a timer is set for us in the
4398 * kernel. If the transmission completes, this timer is disabled. If
4399 * the timer expires, we are called and we try to unlock the hardware.
4401 * Note : This watchdog is move clever than the one in the ISA driver,
4402 * because it try to abort the current command before reseting
4404 * On the other hand, it's a bit simpler, because we don't have to
4405 * deal with the multiple Tx buffers...
4408 wavelan_watchdog(struct net_device * dev)
4410 net_local * lp = netdev_priv(dev);
4411 ioaddr_t base = dev->base_addr;
4412 unsigned long flags;
4413 int aborted = FALSE;
4415 #ifdef DEBUG_INTERRUPT_TRACE
4416 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
4419 #ifdef DEBUG_INTERRUPT_ERROR
4420 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
4424 spin_lock_irqsave(&lp->spinlock, flags);
4426 /* Ask to abort the current command */
4427 outb(OP0_ABORT, LCCR(base));
4429 /* Wait for the end of the command (a bit hackish) */
4430 if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
4431 OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
4434 /* Release spinlock here so that wv_hw_reset() can grab it */
4435 spin_unlock_irqrestore(&lp->spinlock, flags);
4437 /* Check if we were successful in aborting it */
4440 /* It seem that it wasn't enough */
4441 #ifdef DEBUG_INTERRUPT_ERROR
4442 printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
4448 #ifdef DEBUG_PSA_SHOW
4451 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
4455 #ifdef DEBUG_MMC_SHOW
4458 #ifdef DEBUG_I82593_SHOW
4462 /* We are no more waiting for something... */
4463 netif_wake_queue(dev);
4465 #ifdef DEBUG_INTERRUPT_TRACE
4466 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
4470 /********************* CONFIGURATION CALLBACKS *********************/
4472 * Here are the functions called by the pcmcia package (cardmgr) and
4473 * linux networking (NET3) for initialization, configuration and
4474 * deinstallations of the Wavelan Pcmcia Hardware.
4477 /*------------------------------------------------------------------*/
4479 * Configure and start up the WaveLAN PCMCIA adaptor.
4480 * Called by NET3 when it "open" the device.
4483 wavelan_open(struct net_device * dev)
4485 net_local * lp = netdev_priv(dev);
4486 dev_link_t * link = lp->link;
4487 ioaddr_t base = dev->base_addr;
4489 #ifdef DEBUG_CALLBACK_TRACE
4490 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
4491 (unsigned int) dev);
4494 /* Check if the modem is powered up (wavelan_close() power it down */
4495 if(hasr_read(base) & HASR_NO_CLK)
4497 /* Power up (power up time is 250us) */
4498 hacr_write(base, HACR_DEFAULT);
4500 /* Check if the module has been powered up... */
4501 if(hasr_read(base) & HASR_NO_CLK)
4503 #ifdef DEBUG_CONFIG_ERRORS
4504 printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
4511 /* Start reception and declare the driver ready */
4514 if(!wv_ru_start(dev))
4515 wv_hw_reset(dev); /* If problem : reset */
4516 netif_start_queue(dev);
4518 /* Mark the device as used */
4521 #ifdef WAVELAN_ROAMING
4524 #endif /* WAVELAN_ROAMING */
4526 #ifdef DEBUG_CALLBACK_TRACE
4527 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
4532 /*------------------------------------------------------------------*/
4534 * Shutdown the WaveLAN PCMCIA adaptor.
4535 * Called by NET3 when it "close" the device.
4538 wavelan_close(struct net_device * dev)
4540 dev_link_t * link = ((net_local *)netdev_priv(dev))->link;
4541 ioaddr_t base = dev->base_addr;
4543 #ifdef DEBUG_CALLBACK_TRACE
4544 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
4545 (unsigned int) dev);
4548 /* If the device isn't open, then nothing to do */
4551 #ifdef DEBUG_CONFIG_INFO
4552 printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
4557 #ifdef WAVELAN_ROAMING
4558 /* Cleanup of roaming stuff... */
4560 wv_roam_cleanup(dev);
4561 #endif /* WAVELAN_ROAMING */
4565 /* If the card is still present */
4566 if(netif_running(dev))
4568 netif_stop_queue(dev);
4570 /* Stop receiving new messages and wait end of transmission */
4573 /* Power down the module */
4574 hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
4577 #ifdef DEBUG_CALLBACK_TRACE
4578 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
4583 /*------------------------------------------------------------------*/
4585 * wavelan_attach() creates an "instance" of the driver, allocating
4586 * local data structures for one device (one interface). The device
4587 * is registered with Card Services.
4589 * The dev_link structure is initialized, but we don't actually
4590 * configure the card at this point -- we wait until we receive a
4591 * card insertion event.
4594 wavelan_attach(void)
4596 client_reg_t client_reg; /* Register with cardmgr */
4597 dev_link_t * link; /* Info for cardmgr */
4598 struct net_device * dev; /* Interface generic data */
4599 net_local * lp; /* Interface specific data */
4602 #ifdef DEBUG_CALLBACK_TRACE
4603 printk(KERN_DEBUG "-> wavelan_attach()\n");
4606 /* Initialize the dev_link_t structure */
4607 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
4608 if (!link) return NULL;
4609 memset(link, 0, sizeof(struct dev_link_t));
4611 /* The io structure describes IO port mapping */
4612 link->io.NumPorts1 = 8;
4613 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
4614 link->io.IOAddrLines = 3;
4616 /* Interrupt setup */
4617 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
4618 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
4619 if (irq_list[0] == -1)
4620 link->irq.IRQInfo2 = irq_mask;
4622 for (i = 0; i < 4; i++)
4623 link->irq.IRQInfo2 |= 1 << irq_list[i];
4624 link->irq.Handler = wavelan_interrupt;
4626 /* General socket configuration */
4627 link->conf.Attributes = CONF_ENABLE_IRQ;
4628 link->conf.Vcc = 50;
4629 link->conf.IntType = INT_MEMORY_AND_IO;
4632 link->next = dev_list;
4635 /* Allocate the generic data structure */
4636 dev = alloc_etherdev(sizeof(net_local));
4641 link->priv = link->irq.Instance = dev;
4643 lp = netdev_priv(dev);
4645 /* Init specific data */
4647 lp->reconfig_82593 = FALSE;
4649 /* Multicast stuff */
4650 lp->promiscuous = 0;
4651 lp->allmulticast = 0;
4655 spin_lock_init(&lp->spinlock);
4661 /* wavelan NET3 callbacks */
4662 SET_MODULE_OWNER(dev);
4663 dev->open = &wavelan_open;
4664 dev->stop = &wavelan_close;
4665 dev->hard_start_xmit = &wavelan_packet_xmit;
4666 dev->get_stats = &wavelan_get_stats;
4667 dev->set_multicast_list = &wavelan_set_multicast_list;
4668 #ifdef SET_MAC_ADDRESS
4669 dev->set_mac_address = &wavelan_set_mac_address;
4670 #endif /* SET_MAC_ADDRESS */
4672 /* Set the watchdog timer */
4673 dev->tx_timeout = &wavelan_watchdog;
4674 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4675 SET_ETHTOOL_OPS(dev, &ops);
4677 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
4678 dev->wireless_handlers = &wavelan_handler_def;
4679 lp->wireless_data.spy_data = &lp->spy_data;
4680 dev->wireless_data = &lp->wireless_data;
4683 /* Other specific data */
4684 dev->mtu = WAVELAN_MTU;
4686 /* Register with Card Services */
4687 client_reg.dev_info = &dev_info;
4688 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
4689 client_reg.EventMask =
4690 CS_EVENT_REGISTRATION_COMPLETE |
4691 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
4692 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
4693 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
4694 client_reg.event_handler = &wavelan_event;
4695 client_reg.Version = 0x0210;
4696 client_reg.event_callback_args.client_data = link;
4698 #ifdef DEBUG_CONFIG_INFO
4699 printk(KERN_DEBUG "wavelan_attach(): almost done, calling pcmcia_register_client\n");
4702 ret = pcmcia_register_client(&link->handle, &client_reg);
4705 cs_error(link->handle, RegisterClient, ret);
4706 wavelan_detach(link);
4710 #ifdef DEBUG_CALLBACK_TRACE
4711 printk(KERN_DEBUG "<- wavelan_attach()\n");
4717 /*------------------------------------------------------------------*/
4719 * This deletes a driver "instance". The device is de-registered with
4720 * Card Services. If it has been released, all local data structures
4721 * are freed. Otherwise, the structures will be freed when the device
4725 wavelan_detach(dev_link_t * link)
4727 #ifdef DEBUG_CALLBACK_TRACE
4728 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4732 * If the device is currently configured and active, we won't
4733 * actually delete it yet. Instead, it is marked so that when the
4734 * release() function is called, that will trigger a proper
4737 if(link->state & DEV_CONFIG)
4739 /* Some others haven't done their job : give them another chance */
4740 wv_pcmcia_release(link);
4743 /* Break the link with Card Services */
4745 pcmcia_deregister_client(link->handle);
4747 /* Remove the interface data from the linked list */
4748 if(dev_list == link)
4749 dev_list = link->next;
4752 dev_link_t * prev = dev_list;
4754 while((prev != (dev_link_t *) NULL) && (prev->next != link))
4757 if(prev == (dev_link_t *) NULL)
4759 #ifdef DEBUG_CONFIG_ERRORS
4760 printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.\n");
4765 prev->next = link->next;
4771 struct net_device * dev = (struct net_device *) link->priv;
4773 /* Remove ourselves from the kernel list of ethernet devices */
4774 /* Warning : can't be called from interrupt, timer or wavelan_close() */
4776 unregister_netdev(dev);
4778 ((net_local *)netdev_priv(dev))->link = NULL;
4779 ((net_local *)netdev_priv(dev))->dev = NULL;
4784 #ifdef DEBUG_CALLBACK_TRACE
4785 printk(KERN_DEBUG "<- wavelan_detach()\n");
4789 /*------------------------------------------------------------------*/
4791 * The card status event handler. Mostly, this schedules other stuff
4792 * to run after an event is received. A CARD_REMOVAL event also sets
4793 * some flags to discourage the net drivers from trying to talk to the
4797 wavelan_event(event_t event, /* The event received */
4799 event_callback_args_t * args)
4801 dev_link_t * link = (dev_link_t *) args->client_data;
4802 struct net_device * dev = (struct net_device *) link->priv;
4804 #ifdef DEBUG_CALLBACK_TRACE
4805 printk(KERN_DEBUG "->wavelan_event(): %s\n",
4806 ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" :
4807 ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" :
4808 ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" :
4809 ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" :
4810 ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" :
4811 ((event == CS_EVENT_PM_RESUME) ? "pm resume" :
4812 ((event == CS_EVENT_CARD_RESET) ? "card reset" :
4818 case CS_EVENT_REGISTRATION_COMPLETE:
4819 #ifdef DEBUG_CONFIG_INFO
4820 printk(KERN_DEBUG "wavelan_cs: registration complete\n");
4824 case CS_EVENT_CARD_REMOVAL:
4825 /* Oups ! The card is no more there */
4826 link->state &= ~DEV_PRESENT;
4827 if(link->state & DEV_CONFIG)
4829 /* Accept no more transmissions */
4830 netif_device_detach(dev);
4832 /* Release the card */
4833 wv_pcmcia_release(link);
4837 case CS_EVENT_CARD_INSERTION:
4838 /* Reset and configure the card */
4839 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
4840 if(wv_pcmcia_config(link) &&
4847 case CS_EVENT_PM_SUSPEND:
4848 /* NB: wavelan_close will be called, but too late, so we are
4849 * obliged to close nicely the wavelan here. David, could you
4850 * close the device before suspending them ? And, by the way,
4851 * could you, on resume, add a "route add -net ..." after the
4852 * ifconfig up ? Thanks... */
4854 /* Stop receiving new messages and wait end of transmission */
4857 /* Power down the module */
4858 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
4860 /* The card is now suspended */
4861 link->state |= DEV_SUSPEND;
4862 /* Fall through... */
4863 case CS_EVENT_RESET_PHYSICAL:
4864 if(link->state & DEV_CONFIG)
4867 netif_device_detach(dev);
4868 pcmcia_release_configuration(link->handle);
4872 case CS_EVENT_PM_RESUME:
4873 link->state &= ~DEV_SUSPEND;
4874 /* Fall through... */
4875 case CS_EVENT_CARD_RESET:
4876 if(link->state & DEV_CONFIG)
4878 pcmcia_request_configuration(link->handle, &link->conf);
4879 if(link->open) /* If RESET -> True, If RESUME -> False ? */
4882 netif_device_attach(dev);
4888 #ifdef DEBUG_CALLBACK_TRACE
4889 printk(KERN_DEBUG "<-wavelan_event()\n");
4894 static struct pcmcia_driver wavelan_driver = {
4895 .owner = THIS_MODULE,
4897 .name = "wavelan_cs",
4899 .attach = wavelan_attach,
4900 .detach = wavelan_detach,
4904 init_wavelan_cs(void)
4906 return pcmcia_register_driver(&wavelan_driver);
4910 exit_wavelan_cs(void)
4912 pcmcia_unregister_driver(&wavelan_driver);
4915 module_init(init_wavelan_cs);
4916 module_exit(exit_wavelan_cs);