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= (net_local *)dev->priv;
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= (net_local *)dev->priv;
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=(net_local *)dev->priv; /* 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 = (net_local *)dev->priv;
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 = (net_local *)dev->priv;
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 = (net_local *) dev->priv;
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)
1263 lp = (net_local *)dev->priv;
1265 printk(KERN_DEBUG "local:");
1267 * Not implemented yet...
1270 } /* wv_local_show */
1271 #endif /* DEBUG_DEVICE_SHOW */
1273 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1274 /*------------------------------------------------------------------*/
1276 * Dump packet header (and content if necessary) on the screen
1279 wv_packet_info(u_char * p, /* Packet to dump */
1280 int length, /* Length of the packet */
1281 char * msg1, /* Name of the device */
1282 char * msg2) /* Name of the function */
1287 printk(KERN_DEBUG "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1288 msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1289 printk(KERN_DEBUG "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1290 msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13]);
1292 #ifdef DEBUG_PACKET_DUMP
1294 printk(KERN_DEBUG "data=\"");
1296 if((maxi = length) > DEBUG_PACKET_DUMP)
1297 maxi = DEBUG_PACKET_DUMP;
1298 for(i = 14; i < maxi; i++)
1299 if(p[i] >= ' ' && p[i] <= '~')
1300 printk(" %c", p[i]);
1302 printk("%02X", p[i]);
1306 printk(KERN_DEBUG "\n");
1307 #endif /* DEBUG_PACKET_DUMP */
1309 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1311 /*------------------------------------------------------------------*/
1313 * This is the information which is displayed by the driver at startup
1314 * There is a lot of flag to configure it at your will...
1317 wv_init_info(struct net_device * dev)
1319 ioaddr_t base = dev->base_addr;
1323 /* Read the parameter storage area */
1324 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
1326 #ifdef DEBUG_PSA_SHOW
1329 #ifdef DEBUG_MMC_SHOW
1332 #ifdef DEBUG_I82593_SHOW
1336 #ifdef DEBUG_BASIC_SHOW
1337 /* Now, let's go for the basic stuff */
1338 printk(KERN_NOTICE "%s: WaveLAN: port %#x, irq %d, hw_addr",
1339 dev->name, base, dev->irq);
1340 for(i = 0; i < WAVELAN_ADDR_SIZE; i++)
1341 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1343 /* Print current network id */
1344 if(psa.psa_nwid_select)
1345 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
1347 printk(", nwid off");
1350 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1351 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1353 unsigned short freq;
1355 /* Ask the EEprom to read the frequency from the first area */
1356 fee_read(base, 0x00 /* 1st area - frequency... */,
1359 /* Print frequency */
1360 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1368 printk(", PCMCIA, ");
1369 switch (psa.psa_subband)
1371 case PSA_SUBBAND_915:
1374 case PSA_SUBBAND_2425:
1377 case PSA_SUBBAND_2460:
1380 case PSA_SUBBAND_2484:
1383 case PSA_SUBBAND_2430_5:
1392 #endif /* DEBUG_BASIC_SHOW */
1394 #ifdef DEBUG_VERSION_SHOW
1395 /* Print version information */
1396 printk(KERN_NOTICE "%s", version);
1398 } /* wv_init_info */
1400 /********************* IOCTL, STATS & RECONFIG *********************/
1402 * We found here routines that are called by Linux on differents
1403 * occasions after the configuration and not for transmitting data
1404 * These may be called when the user use ifconfig, /proc/net/dev
1405 * or wireless extensions
1408 /*------------------------------------------------------------------*/
1410 * Get the current ethernet statistics. This may be called with the
1411 * card open or closed.
1412 * Used when the user read /proc/net/dev
1415 wavelan_get_stats(struct net_device * dev)
1417 #ifdef DEBUG_IOCTL_TRACE
1418 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1421 return(&((net_local *) dev->priv)->stats);
1424 /*------------------------------------------------------------------*/
1426 * Set or clear the multicast filter for this adaptor.
1427 * num_addrs == -1 Promiscuous mode, receive all packets
1428 * num_addrs == 0 Normal mode, clear multicast list
1429 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1430 * and do best-effort filtering.
1434 wavelan_set_multicast_list(struct net_device * dev)
1436 net_local * lp = (net_local *) dev->priv;
1438 #ifdef DEBUG_IOCTL_TRACE
1439 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
1442 #ifdef DEBUG_IOCTL_INFO
1443 printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1444 dev->name, dev->flags, dev->mc_count);
1447 if(dev->flags & IFF_PROMISC)
1450 * Enable promiscuous mode: receive all packets.
1452 if(!lp->promiscuous)
1454 lp->promiscuous = 1;
1455 lp->allmulticast = 0;
1458 wv_82593_reconfig(dev);
1460 /* Tell the kernel that we are doing a really bad job... */
1461 dev->flags |= IFF_PROMISC;
1465 /* If all multicast addresses
1466 * or too much multicast addresses for the hardware filter */
1467 if((dev->flags & IFF_ALLMULTI) ||
1468 (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
1471 * Disable promiscuous mode, but active the all multicast mode
1473 if(!lp->allmulticast)
1475 lp->promiscuous = 0;
1476 lp->allmulticast = 1;
1479 wv_82593_reconfig(dev);
1481 /* Tell the kernel that we are doing a really bad job... */
1482 dev->flags |= IFF_ALLMULTI;
1486 /* If there is some multicast addresses to send */
1487 if(dev->mc_list != (struct dev_mc_list *) NULL)
1490 * Disable promiscuous mode, but receive all packets
1493 #ifdef MULTICAST_AVOID
1494 if(lp->promiscuous || lp->allmulticast ||
1495 (dev->mc_count != lp->mc_count))
1498 lp->promiscuous = 0;
1499 lp->allmulticast = 0;
1500 lp->mc_count = dev->mc_count;
1502 wv_82593_reconfig(dev);
1508 * Switch to normal mode: disable promiscuous mode and
1509 * clear the multicast list.
1511 if(lp->promiscuous || lp->mc_count == 0)
1513 lp->promiscuous = 0;
1514 lp->allmulticast = 0;
1517 wv_82593_reconfig(dev);
1520 #ifdef DEBUG_IOCTL_TRACE
1521 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
1525 /*------------------------------------------------------------------*/
1527 * This function doesn't exist...
1528 * (Note : it was a nice way to test the reconfigure stuff...)
1530 #ifdef SET_MAC_ADDRESS
1532 wavelan_set_mac_address(struct net_device * dev,
1535 struct sockaddr * mac = addr;
1537 /* Copy the address */
1538 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1540 /* Reconfig the beast */
1541 wv_82593_reconfig(dev);
1545 #endif /* SET_MAC_ADDRESS */
1547 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1549 /*------------------------------------------------------------------*/
1551 * Frequency setting (for hardware able of it)
1552 * It's a bit complicated and you don't really want to look into it...
1553 * (called in wavelan_ioctl)
1556 wv_set_frequency(u_long base, /* i/o port of the card */
1557 iw_freq * frequency)
1559 const int BAND_NUM = 10; /* Number of bands */
1560 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1561 #ifdef DEBUG_IOCTL_INFO
1565 /* Setting by frequency */
1566 /* Theoritically, you may set any frequency between
1567 * the two limits with a 0.5 MHz precision. In practice,
1568 * I don't want you to have trouble with local
1570 if((frequency->e == 1) &&
1571 (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
1573 freq = ((frequency->m / 10000) - 24000L) / 5;
1576 /* Setting by channel (same as wfreqsel) */
1577 /* Warning : each channel is 22MHz wide, so some of the channels
1578 * will interfere... */
1579 if((frequency->e == 0) &&
1580 (frequency->m >= 0) && (frequency->m < BAND_NUM))
1582 /* Get frequency offset. */
1583 freq = channel_bands[frequency->m] >> 1;
1586 /* Verify if the frequency is allowed */
1589 u_short table[10]; /* Authorized frequency table */
1591 /* Read the frequency table */
1592 fee_read(base, 0x71 /* frequency table */,
1595 #ifdef DEBUG_IOCTL_INFO
1596 printk(KERN_DEBUG "Frequency table :");
1597 for(i = 0; i < 10; i++)
1605 /* Look in the table if the frequency is allowed */
1606 if(!(table[9 - ((freq - 24) / 16)] &
1607 (1 << ((freq - 24) % 16))))
1608 return -EINVAL; /* not allowed */
1613 /* If we get a usable frequency */
1616 unsigned short area[16];
1617 unsigned short dac[2];
1618 unsigned short area_verify[16];
1619 unsigned short dac_verify[2];
1620 /* Corresponding gain (in the power adjust value table)
1621 * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
1622 * & WCIN062D.DOC, page 6.2.9 */
1623 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1624 int power_band = 0; /* Selected band */
1625 unsigned short power_adjust; /* Correct value */
1627 /* Search for the gain */
1629 while((freq > power_limit[power_band]) &&
1630 (power_limit[++power_band] != 0))
1633 /* Read the first area */
1634 fee_read(base, 0x00,
1638 fee_read(base, 0x60,
1641 /* Read the new power adjust value */
1642 fee_read(base, 0x6B - (power_band >> 1),
1644 if(power_band & 0x1)
1647 power_adjust &= 0xFF;
1649 #ifdef DEBUG_IOCTL_INFO
1650 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1651 for(i = 0; i < 16; i++)
1658 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1662 /* Frequency offset (for info only...) */
1663 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1665 /* Receiver Principle main divider coefficient */
1666 area[3] = (freq >> 1) + 2400L - 352L;
1667 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1669 /* Transmitter Main divider coefficient */
1670 area[13] = (freq >> 1) + 2400L;
1671 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1673 /* Others part of the area are flags, bit streams or unused... */
1675 /* Set the value in the DAC */
1676 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1677 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1679 /* Write the first area */
1680 fee_write(base, 0x00,
1684 fee_write(base, 0x60,
1687 /* We now should verify here that the EEprom writting was ok */
1689 /* ReRead the first area */
1690 fee_read(base, 0x00,
1693 /* ReRead the DAC */
1694 fee_read(base, 0x60,
1698 if(memcmp(area, area_verify, 16 * 2) ||
1699 memcmp(dac, dac_verify, 2 * 2))
1701 #ifdef DEBUG_IOCTL_ERROR
1702 printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
1707 /* We must download the frequency parameters to the
1708 * synthetisers (from the EEprom - area 1)
1709 * Note : as the EEprom is auto decremented, we set the end
1711 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
1712 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1713 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1715 /* Wait until the download is finished */
1716 fee_wait(base, 100, 100);
1718 /* We must now download the power adjust value (gain) to
1719 * the synthetisers (from the EEprom - area 7 - DAC) */
1720 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
1721 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1722 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1724 /* Wait until the download is finished */
1725 fee_wait(base, 100, 100);
1727 #ifdef DEBUG_IOCTL_INFO
1728 /* Verification of what we have done... */
1730 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1731 for(i = 0; i < 16; i++)
1738 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1739 dac_verify[0], dac_verify[1]);
1745 return -EINVAL; /* Bah, never get there... */
1748 /*------------------------------------------------------------------*/
1750 * Give the list of available frequencies
1753 wv_frequency_list(u_long base, /* i/o port of the card */
1754 iw_freq * list, /* List of frequency to fill */
1755 int max) /* Maximum number of frequencies */
1757 u_short table[10]; /* Authorized frequency table */
1758 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1759 int i; /* index in the table */
1760 const int BAND_NUM = 10; /* Number of bands */
1761 int c = 0; /* Channel number */
1763 /* Read the frequency table */
1764 fee_read(base, 0x71 /* frequency table */,
1767 /* Look all frequencies */
1769 for(freq = 0; freq < 150; freq++)
1770 /* Look in the table if the frequency is allowed */
1771 if(table[9 - (freq / 16)] & (1 << (freq % 16)))
1773 /* Compute approximate channel number */
1774 while((((channel_bands[c] >> 1) - 24) < freq) &&
1777 list[i].i = c; /* Set the list index */
1779 /* put in the list */
1780 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1791 #ifdef IW_WIRELESS_SPY
1792 /*------------------------------------------------------------------*/
1794 * Gather wireless spy statistics : for each packet, compare the source
1795 * address with out list, and if match, get the stats...
1796 * Sorry, but this function really need wireless extensions...
1799 wl_spy_gather(struct net_device * dev,
1800 u_char * mac, /* MAC address */
1801 u_char * stats) /* Statistics to gather */
1803 struct iw_quality wstats;
1805 wstats.qual = stats[2] & MMR_SGNL_QUAL;
1806 wstats.level = stats[0] & MMR_SIGNAL_LVL;
1807 wstats.noise = stats[1] & MMR_SILENCE_LVL;
1808 wstats.updated = 0x7;
1810 /* Update spy records */
1811 wireless_spy_update(dev, mac, &wstats);
1813 #endif /* IW_WIRELESS_SPY */
1816 /*------------------------------------------------------------------*/
1818 * This function calculate an histogram on the signal level.
1819 * As the noise is quite constant, it's like doing it on the SNR.
1820 * We have defined a set of interval (lp->his_range), and each time
1821 * the level goes in that interval, we increment the count (lp->his_sum).
1822 * With this histogram you may detect if one wavelan is really weak,
1823 * or you may also calculate the mean and standard deviation of the level...
1826 wl_his_gather(struct net_device * dev,
1827 u_char * stats) /* Statistics to gather */
1829 net_local * lp = (net_local *) dev->priv;
1830 u_char level = stats[0] & MMR_SIGNAL_LVL;
1833 /* Find the correct interval */
1835 while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
1838 /* Increment interval counter */
1841 #endif /* HISTOGRAM */
1844 wl_netdev_ethtool_ioctl(struct net_device *dev, void __user *useraddr)
1848 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
1852 case ETHTOOL_GDRVINFO: {
1853 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
1855 strncpy(info.driver, "wavelan_cs", sizeof(info.driver)-1);
1856 if (copy_to_user(useraddr, &info, sizeof(info)))
1865 /*------------------------------------------------------------------*/
1867 * Wireless Handler : get protocol name
1869 static int wavelan_get_name(struct net_device *dev,
1870 struct iw_request_info *info,
1871 union iwreq_data *wrqu,
1874 strcpy(wrqu->name, "WaveLAN");
1878 /*------------------------------------------------------------------*/
1880 * Wireless Handler : set NWID
1882 static int wavelan_set_nwid(struct net_device *dev,
1883 struct iw_request_info *info,
1884 union iwreq_data *wrqu,
1887 ioaddr_t base = dev->base_addr;
1888 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
1891 unsigned long flags;
1894 /* Disable interrupts and save flags. */
1895 spin_lock_irqsave(&lp->spinlock, flags);
1897 /* Set NWID in WaveLAN. */
1898 if (!wrqu->nwid.disabled) {
1899 /* Set NWID in psa */
1900 psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
1901 psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
1902 psa.psa_nwid_select = 0x01;
1904 (char *) psa.psa_nwid - (char *) &psa,
1905 (unsigned char *) psa.psa_nwid, 3);
1907 /* Set NWID in mmc. */
1908 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1909 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1911 (char *) &m.w.mmw_netw_id_l -
1913 (unsigned char *) &m.w.mmw_netw_id_l, 2);
1914 mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
1916 /* Disable NWID in the psa. */
1917 psa.psa_nwid_select = 0x00;
1919 (char *) &psa.psa_nwid_select -
1921 (unsigned char *) &psa.psa_nwid_select,
1924 /* Disable NWID in the mmc (no filtering). */
1925 mmc_out(base, mmwoff(0, mmw_loopt_sel),
1926 MMW_LOOPT_SEL_DIS_NWID);
1928 /* update the Wavelan checksum */
1929 update_psa_checksum(dev);
1931 /* Enable interrupts and restore flags. */
1932 spin_unlock_irqrestore(&lp->spinlock, flags);
1937 /*------------------------------------------------------------------*/
1939 * Wireless Handler : get NWID
1941 static int wavelan_get_nwid(struct net_device *dev,
1942 struct iw_request_info *info,
1943 union iwreq_data *wrqu,
1946 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
1948 unsigned long flags;
1951 /* Disable interrupts and save flags. */
1952 spin_lock_irqsave(&lp->spinlock, flags);
1954 /* Read the NWID. */
1956 (char *) psa.psa_nwid - (char *) &psa,
1957 (unsigned char *) psa.psa_nwid, 3);
1958 wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1959 wrqu->nwid.disabled = !(psa.psa_nwid_select);
1960 wrqu->nwid.fixed = 1; /* Superfluous */
1962 /* Enable interrupts and restore flags. */
1963 spin_unlock_irqrestore(&lp->spinlock, flags);
1968 /*------------------------------------------------------------------*/
1970 * Wireless Handler : set frequency
1972 static int wavelan_set_freq(struct net_device *dev,
1973 struct iw_request_info *info,
1974 union iwreq_data *wrqu,
1977 ioaddr_t base = dev->base_addr;
1978 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
1979 unsigned long flags;
1982 /* Disable interrupts and save flags. */
1983 spin_lock_irqsave(&lp->spinlock, flags);
1985 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1986 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1987 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1988 ret = wv_set_frequency(base, &(wrqu->freq));
1992 /* Enable interrupts and restore flags. */
1993 spin_unlock_irqrestore(&lp->spinlock, flags);
1998 /*------------------------------------------------------------------*/
2000 * Wireless Handler : get frequency
2002 static int wavelan_get_freq(struct net_device *dev,
2003 struct iw_request_info *info,
2004 union iwreq_data *wrqu,
2007 ioaddr_t base = dev->base_addr;
2008 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2010 unsigned long flags;
2013 /* Disable interrupts and save flags. */
2014 spin_lock_irqsave(&lp->spinlock, flags);
2016 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
2017 * Does it work for everybody, especially old cards? */
2018 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2019 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2020 unsigned short freq;
2022 /* Ask the EEPROM to read the frequency from the first area. */
2023 fee_read(base, 0x00, &freq, 1);
2024 wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
2028 (char *) &psa.psa_subband - (char *) &psa,
2029 (unsigned char *) &psa.psa_subband, 1);
2031 if (psa.psa_subband <= 4) {
2032 wrqu->freq.m = fixed_bands[psa.psa_subband];
2033 wrqu->freq.e = (psa.psa_subband != 0);
2038 /* Enable interrupts and restore flags. */
2039 spin_unlock_irqrestore(&lp->spinlock, flags);
2044 /*------------------------------------------------------------------*/
2046 * Wireless Handler : set level threshold
2048 static int wavelan_set_sens(struct net_device *dev,
2049 struct iw_request_info *info,
2050 union iwreq_data *wrqu,
2053 ioaddr_t base = dev->base_addr;
2054 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2056 unsigned long flags;
2059 /* Disable interrupts and save flags. */
2060 spin_lock_irqsave(&lp->spinlock, flags);
2062 /* Set the level threshold. */
2063 /* We should complain loudly if wrqu->sens.fixed = 0, because we
2064 * can't set auto mode... */
2065 psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
2067 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2068 (unsigned char *) &psa.psa_thr_pre_set, 1);
2069 /* update the Wavelan checksum */
2070 update_psa_checksum(dev);
2071 mmc_out(base, mmwoff(0, mmw_thr_pre_set),
2072 psa.psa_thr_pre_set);
2074 /* Enable interrupts and restore flags. */
2075 spin_unlock_irqrestore(&lp->spinlock, flags);
2080 /*------------------------------------------------------------------*/
2082 * Wireless Handler : get level threshold
2084 static int wavelan_get_sens(struct net_device *dev,
2085 struct iw_request_info *info,
2086 union iwreq_data *wrqu,
2089 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2091 unsigned long flags;
2094 /* Disable interrupts and save flags. */
2095 spin_lock_irqsave(&lp->spinlock, flags);
2097 /* Read the level threshold. */
2099 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2100 (unsigned char *) &psa.psa_thr_pre_set, 1);
2101 wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
2102 wrqu->sens.fixed = 1;
2104 /* Enable interrupts and restore flags. */
2105 spin_unlock_irqrestore(&lp->spinlock, flags);
2110 /*------------------------------------------------------------------*/
2112 * Wireless Handler : set encryption key
2114 static int wavelan_set_encode(struct net_device *dev,
2115 struct iw_request_info *info,
2116 union iwreq_data *wrqu,
2119 ioaddr_t base = dev->base_addr;
2120 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2121 unsigned long flags;
2125 /* Disable interrupts and save flags. */
2126 spin_lock_irqsave(&lp->spinlock, flags);
2128 /* Check if capable of encryption */
2129 if (!mmc_encr(base)) {
2133 /* Check the size of the key */
2134 if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
2139 /* Basic checking... */
2140 if (wrqu->encoding.length == 8) {
2141 /* Copy the key in the driver */
2142 memcpy(psa.psa_encryption_key, extra,
2143 wrqu->encoding.length);
2144 psa.psa_encryption_select = 1;
2147 (char *) &psa.psa_encryption_select -
2149 (unsigned char *) &psa.
2150 psa_encryption_select, 8 + 1);
2152 mmc_out(base, mmwoff(0, mmw_encr_enable),
2153 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2154 mmc_write(base, mmwoff(0, mmw_encr_key),
2155 (unsigned char *) &psa.
2156 psa_encryption_key, 8);
2159 /* disable encryption */
2160 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
2161 psa.psa_encryption_select = 0;
2163 (char *) &psa.psa_encryption_select -
2165 (unsigned char *) &psa.
2166 psa_encryption_select, 1);
2168 mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
2170 /* update the Wavelan checksum */
2171 update_psa_checksum(dev);
2174 /* Enable interrupts and restore flags. */
2175 spin_unlock_irqrestore(&lp->spinlock, flags);
2180 /*------------------------------------------------------------------*/
2182 * Wireless Handler : get encryption key
2184 static int wavelan_get_encode(struct net_device *dev,
2185 struct iw_request_info *info,
2186 union iwreq_data *wrqu,
2189 ioaddr_t base = dev->base_addr;
2190 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2192 unsigned long flags;
2195 /* Disable interrupts and save flags. */
2196 spin_lock_irqsave(&lp->spinlock, flags);
2198 /* Check if encryption is available */
2199 if (!mmc_encr(base)) {
2202 /* Read the encryption key */
2204 (char *) &psa.psa_encryption_select -
2206 (unsigned char *) &psa.
2207 psa_encryption_select, 1 + 8);
2209 /* encryption is enabled ? */
2210 if (psa.psa_encryption_select)
2211 wrqu->encoding.flags = IW_ENCODE_ENABLED;
2213 wrqu->encoding.flags = IW_ENCODE_DISABLED;
2214 wrqu->encoding.flags |= mmc_encr(base);
2216 /* Copy the key to the user buffer */
2217 wrqu->encoding.length = 8;
2218 memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
2221 /* Enable interrupts and restore flags. */
2222 spin_unlock_irqrestore(&lp->spinlock, flags);
2227 #ifdef WAVELAN_ROAMING_EXT
2228 /*------------------------------------------------------------------*/
2230 * Wireless Handler : set ESSID (domain)
2232 static int wavelan_set_essid(struct net_device *dev,
2233 struct iw_request_info *info,
2234 union iwreq_data *wrqu,
2237 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2238 unsigned long flags;
2241 /* Disable interrupts and save flags. */
2242 spin_lock_irqsave(&lp->spinlock, flags);
2244 /* Check if disable */
2245 if(wrqu->data.flags == 0)
2246 lp->filter_domains = 0;
2248 char essid[IW_ESSID_MAX_SIZE + 1];
2251 /* Terminate the string */
2252 memcpy(essid, extra, wrqu->data.length);
2253 essid[IW_ESSID_MAX_SIZE] = '\0';
2255 #ifdef DEBUG_IOCTL_INFO
2256 printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
2257 #endif /* DEBUG_IOCTL_INFO */
2259 /* Convert to a number (note : Wavelan specific) */
2260 lp->domain_id = simple_strtoul(essid, &endp, 16);
2261 /* Has it worked ? */
2263 lp->filter_domains = 1;
2265 lp->filter_domains = 0;
2270 /* Enable interrupts and restore flags. */
2271 spin_unlock_irqrestore(&lp->spinlock, flags);
2276 /*------------------------------------------------------------------*/
2278 * Wireless Handler : get ESSID (domain)
2280 static int wavelan_get_essid(struct net_device *dev,
2281 struct iw_request_info *info,
2282 union iwreq_data *wrqu,
2285 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2287 /* Is the domain ID active ? */
2288 wrqu->data.flags = lp->filter_domains;
2290 /* Copy Domain ID into a string (Wavelan specific) */
2291 /* Sound crazy, be we can't have a snprintf in the kernel !!! */
2292 sprintf(extra, "%lX", lp->domain_id);
2293 extra[IW_ESSID_MAX_SIZE] = '\0';
2295 /* Set the length */
2296 wrqu->data.length = strlen(extra) + 1;
2301 /*------------------------------------------------------------------*/
2303 * Wireless Handler : set AP address
2305 static int wavelan_set_wap(struct net_device *dev,
2306 struct iw_request_info *info,
2307 union iwreq_data *wrqu,
2310 #ifdef DEBUG_IOCTL_INFO
2311 printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
2312 wrqu->ap_addr.sa_data[0],
2313 wrqu->ap_addr.sa_data[1],
2314 wrqu->ap_addr.sa_data[2],
2315 wrqu->ap_addr.sa_data[3],
2316 wrqu->ap_addr.sa_data[4],
2317 wrqu->ap_addr.sa_data[5]);
2318 #endif /* DEBUG_IOCTL_INFO */
2323 /*------------------------------------------------------------------*/
2325 * Wireless Handler : get AP address
2327 static int wavelan_get_wap(struct net_device *dev,
2328 struct iw_request_info *info,
2329 union iwreq_data *wrqu,
2332 /* Should get the real McCoy instead of own Ethernet address */
2333 memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
2334 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
2338 #endif /* WAVELAN_ROAMING_EXT */
2340 #ifdef WAVELAN_ROAMING
2341 /*------------------------------------------------------------------*/
2343 * Wireless Handler : set mode
2345 static int wavelan_set_mode(struct net_device *dev,
2346 struct iw_request_info *info,
2347 union iwreq_data *wrqu,
2350 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2351 unsigned long flags;
2354 /* Disable interrupts and save flags. */
2355 spin_lock_irqsave(&lp->spinlock, flags);
2358 switch(wrqu->mode) {
2361 wv_roam_cleanup(dev);
2375 /* Enable interrupts and restore flags. */
2376 spin_unlock_irqrestore(&lp->spinlock, flags);
2381 /*------------------------------------------------------------------*/
2383 * Wireless Handler : get mode
2385 static int wavelan_get_mode(struct net_device *dev,
2386 struct iw_request_info *info,
2387 union iwreq_data *wrqu,
2391 wrqu->mode = IW_MODE_INFRA;
2393 wrqu->mode = IW_MODE_ADHOC;
2397 #endif /* WAVELAN_ROAMING */
2399 /*------------------------------------------------------------------*/
2401 * Wireless Handler : get range info
2403 static int wavelan_get_range(struct net_device *dev,
2404 struct iw_request_info *info,
2405 union iwreq_data *wrqu,
2408 ioaddr_t base = dev->base_addr;
2409 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2410 struct iw_range *range = (struct iw_range *) extra;
2411 unsigned long flags;
2414 /* Set the length (very important for backward compatibility) */
2415 wrqu->data.length = sizeof(struct iw_range);
2417 /* Set all the info we don't care or don't know about to zero */
2418 memset(range, 0, sizeof(struct iw_range));
2420 /* Set the Wireless Extension versions */
2421 range->we_version_compiled = WIRELESS_EXT;
2422 range->we_version_source = 9;
2424 /* Set information in the range struct. */
2425 range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
2426 range->min_nwid = 0x0000;
2427 range->max_nwid = 0xFFFF;
2429 range->sensitivity = 0x3F;
2430 range->max_qual.qual = MMR_SGNL_QUAL;
2431 range->max_qual.level = MMR_SIGNAL_LVL;
2432 range->max_qual.noise = MMR_SILENCE_LVL;
2433 range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
2434 /* Need to get better values for those two */
2435 range->avg_qual.level = 30;
2436 range->avg_qual.noise = 8;
2438 range->num_bitrates = 1;
2439 range->bitrate[0] = 2000000; /* 2 Mb/s */
2441 /* Disable interrupts and save flags. */
2442 spin_lock_irqsave(&lp->spinlock, flags);
2444 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2445 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2446 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2447 range->num_channels = 10;
2448 range->num_frequency = wv_frequency_list(base, range->freq,
2449 IW_MAX_FREQUENCIES);
2451 range->num_channels = range->num_frequency = 0;
2453 /* Encryption supported ? */
2454 if (mmc_encr(base)) {
2455 range->encoding_size[0] = 8; /* DES = 64 bits key */
2456 range->num_encoding_sizes = 1;
2457 range->max_encoding_tokens = 1; /* Only one key possible */
2459 range->num_encoding_sizes = 0;
2460 range->max_encoding_tokens = 0;
2463 /* Enable interrupts and restore flags. */
2464 spin_unlock_irqrestore(&lp->spinlock, flags);
2469 /*------------------------------------------------------------------*/
2471 * Wireless Private Handler : set quality threshold
2473 static int wavelan_set_qthr(struct net_device *dev,
2474 struct iw_request_info *info,
2475 union iwreq_data *wrqu,
2478 ioaddr_t base = dev->base_addr;
2479 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2481 unsigned long flags;
2483 /* Disable interrupts and save flags. */
2484 spin_lock_irqsave(&lp->spinlock, flags);
2486 psa.psa_quality_thr = *(extra) & 0x0F;
2488 (char *) &psa.psa_quality_thr - (char *) &psa,
2489 (unsigned char *) &psa.psa_quality_thr, 1);
2490 /* update the Wavelan checksum */
2491 update_psa_checksum(dev);
2492 mmc_out(base, mmwoff(0, mmw_quality_thr),
2493 psa.psa_quality_thr);
2495 /* Enable interrupts and restore flags. */
2496 spin_unlock_irqrestore(&lp->spinlock, flags);
2501 /*------------------------------------------------------------------*/
2503 * Wireless Private Handler : get quality threshold
2505 static int wavelan_get_qthr(struct net_device *dev,
2506 struct iw_request_info *info,
2507 union iwreq_data *wrqu,
2510 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2512 unsigned long flags;
2514 /* Disable interrupts and save flags. */
2515 spin_lock_irqsave(&lp->spinlock, flags);
2518 (char *) &psa.psa_quality_thr - (char *) &psa,
2519 (unsigned char *) &psa.psa_quality_thr, 1);
2520 *(extra) = psa.psa_quality_thr & 0x0F;
2522 /* Enable interrupts and restore flags. */
2523 spin_unlock_irqrestore(&lp->spinlock, flags);
2528 #ifdef WAVELAN_ROAMING
2529 /*------------------------------------------------------------------*/
2531 * Wireless Private Handler : set roaming
2533 static int wavelan_set_roam(struct net_device *dev,
2534 struct iw_request_info *info,
2535 union iwreq_data *wrqu,
2538 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2539 unsigned long flags;
2541 /* Disable interrupts and save flags. */
2542 spin_lock_irqsave(&lp->spinlock, flags);
2544 /* Note : should check if user == root */
2545 if(do_roaming && (*extra)==0)
2546 wv_roam_cleanup(dev);
2547 else if(do_roaming==0 && (*extra)!=0)
2550 do_roaming = (*extra);
2552 /* Enable interrupts and restore flags. */
2553 spin_unlock_irqrestore(&lp->spinlock, flags);
2558 /*------------------------------------------------------------------*/
2560 * Wireless Private Handler : get quality threshold
2562 static int wavelan_get_roam(struct net_device *dev,
2563 struct iw_request_info *info,
2564 union iwreq_data *wrqu,
2567 *(extra) = do_roaming;
2571 #endif /* WAVELAN_ROAMING */
2574 /*------------------------------------------------------------------*/
2576 * Wireless Private Handler : set histogram
2578 static int wavelan_set_histo(struct net_device *dev,
2579 struct iw_request_info *info,
2580 union iwreq_data *wrqu,
2583 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2585 /* Check the number of intervals. */
2586 if (wrqu->data.length > 16) {
2590 /* Disable histo while we copy the addresses.
2591 * As we don't disable interrupts, we need to do this */
2594 /* Are there ranges to copy? */
2595 if (wrqu->data.length > 0) {
2596 /* Copy interval ranges to the driver */
2597 memcpy(lp->his_range, extra, wrqu->data.length);
2601 printk(KERN_DEBUG "Histo :");
2602 for(i = 0; i < wrqu->data.length; i++)
2603 printk(" %d", lp->his_range[i]);
2607 /* Reset result structure. */
2608 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2611 /* Now we can set the number of ranges */
2612 lp->his_number = wrqu->data.length;
2617 /*------------------------------------------------------------------*/
2619 * Wireless Private Handler : get histogram
2621 static int wavelan_get_histo(struct net_device *dev,
2622 struct iw_request_info *info,
2623 union iwreq_data *wrqu,
2626 net_local *lp = (net_local *) dev->priv; /* lp is not unused */
2628 /* Set the number of intervals. */
2629 wrqu->data.length = lp->his_number;
2631 /* Give back the distribution statistics */
2632 if(lp->his_number > 0)
2633 memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
2637 #endif /* HISTOGRAM */
2639 /*------------------------------------------------------------------*/
2641 * Structures to export the Wireless Handlers
2644 static const struct iw_priv_args wavelan_private_args[] = {
2645 /*{ cmd, set_args, get_args, name } */
2646 { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2647 { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2648 { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" },
2649 { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
2650 { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
2651 { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
2654 static const iw_handler wavelan_handler[] =
2656 NULL, /* SIOCSIWNAME */
2657 wavelan_get_name, /* SIOCGIWNAME */
2658 wavelan_set_nwid, /* SIOCSIWNWID */
2659 wavelan_get_nwid, /* SIOCGIWNWID */
2660 wavelan_set_freq, /* SIOCSIWFREQ */
2661 wavelan_get_freq, /* SIOCGIWFREQ */
2662 #ifdef WAVELAN_ROAMING
2663 wavelan_set_mode, /* SIOCSIWMODE */
2664 wavelan_get_mode, /* SIOCGIWMODE */
2665 #else /* WAVELAN_ROAMING */
2666 NULL, /* SIOCSIWMODE */
2667 NULL, /* SIOCGIWMODE */
2668 #endif /* WAVELAN_ROAMING */
2669 wavelan_set_sens, /* SIOCSIWSENS */
2670 wavelan_get_sens, /* SIOCGIWSENS */
2671 NULL, /* SIOCSIWRANGE */
2672 wavelan_get_range, /* SIOCGIWRANGE */
2673 NULL, /* SIOCSIWPRIV */
2674 NULL, /* SIOCGIWPRIV */
2675 NULL, /* SIOCSIWSTATS */
2676 NULL, /* SIOCGIWSTATS */
2677 iw_handler_set_spy, /* SIOCSIWSPY */
2678 iw_handler_get_spy, /* SIOCGIWSPY */
2679 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2680 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2681 #ifdef WAVELAN_ROAMING_EXT
2682 wavelan_set_wap, /* SIOCSIWAP */
2683 wavelan_get_wap, /* SIOCGIWAP */
2684 NULL, /* -- hole -- */
2685 NULL, /* SIOCGIWAPLIST */
2686 NULL, /* -- hole -- */
2687 NULL, /* -- hole -- */
2688 wavelan_set_essid, /* SIOCSIWESSID */
2689 wavelan_get_essid, /* SIOCGIWESSID */
2690 #else /* WAVELAN_ROAMING_EXT */
2691 NULL, /* SIOCSIWAP */
2692 NULL, /* SIOCGIWAP */
2693 NULL, /* -- hole -- */
2694 NULL, /* SIOCGIWAPLIST */
2695 NULL, /* -- hole -- */
2696 NULL, /* -- hole -- */
2697 NULL, /* SIOCSIWESSID */
2698 NULL, /* SIOCGIWESSID */
2699 #endif /* WAVELAN_ROAMING_EXT */
2700 NULL, /* SIOCSIWNICKN */
2701 NULL, /* SIOCGIWNICKN */
2702 NULL, /* -- hole -- */
2703 NULL, /* -- hole -- */
2704 NULL, /* SIOCSIWRATE */
2705 NULL, /* SIOCGIWRATE */
2706 NULL, /* SIOCSIWRTS */
2707 NULL, /* SIOCGIWRTS */
2708 NULL, /* SIOCSIWFRAG */
2709 NULL, /* SIOCGIWFRAG */
2710 NULL, /* SIOCSIWTXPOW */
2711 NULL, /* SIOCGIWTXPOW */
2712 NULL, /* SIOCSIWRETRY */
2713 NULL, /* SIOCGIWRETRY */
2714 wavelan_set_encode, /* SIOCSIWENCODE */
2715 wavelan_get_encode, /* SIOCGIWENCODE */
2718 static const iw_handler wavelan_private_handler[] =
2720 wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
2721 wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
2722 #ifdef WAVELAN_ROAMING
2723 wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */
2724 wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */
2725 #else /* WAVELAN_ROAMING */
2726 NULL, /* SIOCIWFIRSTPRIV + 2 */
2727 NULL, /* SIOCIWFIRSTPRIV + 3 */
2728 #endif /* WAVELAN_ROAMING */
2730 wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */
2731 wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */
2732 #endif /* HISTOGRAM */
2735 static const struct iw_handler_def wavelan_handler_def =
2737 .num_standard = sizeof(wavelan_handler)/sizeof(iw_handler),
2738 .num_private = sizeof(wavelan_private_handler)/sizeof(iw_handler),
2739 .num_private_args = sizeof(wavelan_private_args)/sizeof(struct iw_priv_args),
2740 .standard = (iw_handler *) wavelan_handler,
2741 .private = (iw_handler *) wavelan_private_handler,
2742 .private_args = (struct iw_priv_args *) wavelan_private_args,
2743 .spy_offset = ((void *) (&((net_local *) NULL)->spy_data) -
2747 /*------------------------------------------------------------------*/
2749 * Perform ioctl : config & info stuff
2750 * This is here that are treated the wireless extensions (iwconfig)
2753 wavelan_ioctl(struct net_device * dev, /* Device on wich the ioctl apply */
2754 struct ifreq * rq, /* Data passed */
2755 int cmd) /* Ioctl number */
2759 #ifdef DEBUG_IOCTL_TRACE
2760 printk(KERN_DEBUG "%s: ->wavelan_ioctl(cmd=0x%X)\n", dev->name, cmd);
2763 /* Look what is the request */
2767 ret = wl_netdev_ethtool_ioctl(dev, rq->ifr_data);
2770 /* ------------------- OTHER IOCTL ------------------- */
2776 #ifdef DEBUG_IOCTL_TRACE
2777 printk(KERN_DEBUG "%s: <-wavelan_ioctl()\n", dev->name);
2782 /*------------------------------------------------------------------*/
2784 * Get wireless statistics
2785 * Called by /proc/net/wireless...
2788 wavelan_get_wireless_stats(struct net_device * dev)
2790 ioaddr_t base = dev->base_addr;
2791 net_local * lp = (net_local *) dev->priv;
2794 unsigned long flags;
2796 #ifdef DEBUG_IOCTL_TRACE
2797 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
2800 /* Disable interrupts & save flags */
2801 spin_lock_irqsave(&lp->spinlock, flags);
2803 wstats = &lp->wstats;
2805 /* Get data from the mmc */
2806 mmc_out(base, mmwoff(0, mmw_freeze), 1);
2808 mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2809 mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
2810 mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
2812 mmc_out(base, mmwoff(0, mmw_freeze), 0);
2814 /* Copy data to wireless stuff */
2815 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2816 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2817 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2818 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2819 wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
2820 ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
2821 ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2822 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2823 wstats->discard.code = 0L;
2824 wstats->discard.misc = 0L;
2826 /* ReEnable interrupts & restore flags */
2827 spin_unlock_irqrestore(&lp->spinlock, flags);
2829 #ifdef DEBUG_IOCTL_TRACE
2830 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
2834 #endif /* WIRELESS_EXT */
2836 /************************* PACKET RECEPTION *************************/
2838 * This part deal with receiving the packets.
2839 * The interrupt handler get an interrupt when a packet has been
2840 * successfully received and called this part...
2843 /*------------------------------------------------------------------*/
2845 * Calculate the starting address of the frame pointed to by the receive
2846 * frame pointer and verify that the frame seem correct
2847 * (called by wv_packet_rcv())
2850 wv_start_of_frame(struct net_device * dev,
2851 int rfp, /* end of frame */
2852 int wrap) /* start of buffer */
2854 ioaddr_t base = dev->base_addr;
2858 rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
2859 outb(rp & 0xff, PIORL(base));
2860 outb(((rp >> 8) & PIORH_MASK), PIORH(base));
2861 len = inb(PIOP(base));
2862 len |= inb(PIOP(base)) << 8;
2864 /* Sanity checks on size */
2866 if(len > MAXDATAZ + 100)
2868 #ifdef DEBUG_RX_ERROR
2869 printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
2870 dev->name, rfp, len);
2875 /* Frame too short */
2878 #ifdef DEBUG_RX_ERROR
2879 printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
2880 dev->name, rfp, len);
2885 /* Wrap around buffer */
2886 if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
2888 #ifdef DEBUG_RX_ERROR
2889 printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
2890 dev->name, wrap, rfp, len);
2895 return((rp - len + RX_SIZE) % RX_SIZE);
2896 } /* wv_start_of_frame */
2898 /*------------------------------------------------------------------*/
2900 * This routine does the actual copy of data (including the ethernet
2901 * header structure) from the WaveLAN card to an sk_buff chain that
2902 * will be passed up to the network interface layer. NOTE: We
2903 * currently don't handle trailer protocols (neither does the rest of
2904 * the network interface), so if that is needed, it will (at least in
2905 * part) be added here. The contents of the receive ring buffer are
2906 * copied to a message chain that is then passed to the kernel.
2908 * Note: if any errors occur, the packet is "dropped on the floor"
2909 * (called by wv_packet_rcv())
2912 wv_packet_read(struct net_device * dev,
2916 net_local * lp = (net_local *) dev->priv;
2917 struct sk_buff * skb;
2919 #ifdef DEBUG_RX_TRACE
2920 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2921 dev->name, fd_p, sksize);
2924 /* Allocate some buffer for the new packet */
2925 if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
2927 #ifdef DEBUG_RX_ERROR
2928 printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
2931 lp->stats.rx_dropped++;
2933 * Not only do we want to return here, but we also need to drop the
2934 * packet on the floor to clear the interrupt.
2941 skb_reserve(skb, 2);
2942 fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
2943 skb->protocol = eth_type_trans(skb, dev);
2945 #ifdef DEBUG_RX_INFO
2946 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2947 #endif /* DEBUG_RX_INFO */
2949 /* Statistics gathering & stuff associated.
2950 * It seem a bit messy with all the define, but it's really simple... */
2952 #ifdef IW_WIRELESS_SPY
2953 (lp->spy_data.spy_number > 0) ||
2954 #endif /* IW_WIRELESS_SPY */
2956 (lp->his_number > 0) ||
2957 #endif /* HISTOGRAM */
2958 #ifdef WAVELAN_ROAMING
2960 #endif /* WAVELAN_ROAMING */
2963 u_char stats[3]; /* Signal level, Noise level, Signal quality */
2965 /* read signal level, silence level and signal quality bytes */
2966 fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
2968 #ifdef DEBUG_RX_INFO
2969 printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2970 dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
2973 #ifdef WAVELAN_ROAMING
2975 if(WAVELAN_BEACON(skb->data))
2976 wl_roam_gather(dev, skb->data, stats);
2977 #endif /* WAVELAN_ROAMING */
2980 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
2981 #endif /* WIRELESS_SPY */
2983 wl_his_gather(dev, stats);
2984 #endif /* HISTOGRAM */
2988 * Hand the packet to the Network Module
2992 /* Keep stats up to date */
2993 dev->last_rx = jiffies;
2994 lp->stats.rx_packets++;
2995 lp->stats.rx_bytes += sksize;
2997 #ifdef DEBUG_RX_TRACE
2998 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
3003 /*------------------------------------------------------------------*/
3005 * This routine is called by the interrupt handler to initiate a
3006 * packet transfer from the card to the network interface layer above
3007 * this driver. This routine checks if a buffer has been successfully
3008 * received by the WaveLAN card. If so, the routine wv_packet_read is
3009 * called to do the actual transfer of the card's data including the
3010 * ethernet header into a packet consisting of an sk_buff chain.
3011 * (called by wavelan_interrupt())
3012 * Note : the spinlock is already grabbed for us and irq are disabled.
3015 wv_packet_rcv(struct net_device * dev)
3017 ioaddr_t base = dev->base_addr;
3018 net_local * lp = (net_local *) dev->priv;
3028 #ifdef DEBUG_RX_TRACE
3029 printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
3032 /* Get the new receive frame pointer from the i82593 chip */
3033 outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
3034 i593_rfp = inb(LCSR(base));
3035 i593_rfp |= inb(LCSR(base)) << 8;
3036 i593_rfp %= RX_SIZE;
3038 /* Get the new receive frame pointer from the WaveLAN card.
3039 * It is 3 bytes more than the increment of the i82593 receive
3040 * frame pointer, for each packet. This is because it includes the
3041 * 3 roaming bytes added by the mmc.
3043 newrfp = inb(RPLL(base));
3044 newrfp |= inb(RPLH(base)) << 8;
3047 #ifdef DEBUG_RX_INFO
3048 printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3049 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
3052 #ifdef DEBUG_RX_ERROR
3053 /* If no new frame pointer... */
3054 if(lp->overrunning || newrfp == lp->rfp)
3055 printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3056 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
3059 /* Read all frames (packets) received */
3060 while(newrfp != lp->rfp)
3062 /* A frame is composed of the packet, followed by a status word,
3063 * the length of the frame (word) and the mmc info (SNR & qual).
3064 * It's because the length is at the end that we can only scan
3065 * frames backward. */
3067 /* Find the first frame by skipping backwards over the frames */
3068 rp = newrfp; /* End of last frame */
3069 while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
3073 /* If we had a problem */
3076 #ifdef DEBUG_RX_ERROR
3077 printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
3078 printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3079 i593_rfp, lp->stop, newrfp, lp->rfp);
3081 lp->rfp = rp; /* Get to the last usable frame */
3085 /* f_start point to the beggining of the first frame received
3086 * and rp to the beggining of the next one */
3088 /* Read status & length of the frame */
3089 stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
3090 stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
3091 status = c[0] | (c[1] << 8);
3092 len = c[2] | (c[3] << 8);
3095 if((status & RX_RCV_OK) != RX_RCV_OK)
3097 lp->stats.rx_errors++;
3098 if(status & RX_NO_SFD)
3099 lp->stats.rx_frame_errors++;
3100 if(status & RX_CRC_ERR)
3101 lp->stats.rx_crc_errors++;
3102 if(status & RX_OVRRUN)
3103 lp->stats.rx_over_errors++;
3105 #ifdef DEBUG_RX_FAIL
3106 printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
3111 /* Read the packet and transmit to Linux */
3112 wv_packet_read(dev, f_start, len - 2);
3114 /* One frame has been processed, skip it */
3119 * Update the frame stop register, but set it to less than
3120 * the full 8K to allow space for 3 bytes of signal strength
3123 lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3124 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3125 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3126 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3128 #ifdef DEBUG_RX_TRACE
3129 printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
3133 /*********************** PACKET TRANSMISSION ***********************/
3135 * This part deal with sending packet through the wavelan
3136 * We copy the packet to the send buffer and then issue the send
3137 * command to the i82593. The result of this operation will be
3138 * checked in wavelan_interrupt()
3141 /*------------------------------------------------------------------*/
3143 * This routine fills in the appropriate registers and memory
3144 * locations on the WaveLAN card and starts the card off on
3146 * (called in wavelan_packet_xmit())
3149 wv_packet_write(struct net_device * dev,
3153 net_local * lp = (net_local *) dev->priv;
3154 ioaddr_t base = dev->base_addr;
3155 unsigned long flags;
3157 register u_short xmtdata_base = TX_BASE;
3159 #ifdef DEBUG_TX_TRACE
3160 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
3163 spin_lock_irqsave(&lp->spinlock, flags);
3165 /* Write the length of data buffer followed by the buffer */
3166 outb(xmtdata_base & 0xff, PIORL(base));
3167 outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3168 outb(clen & 0xff, PIOP(base)); /* lsb */
3169 outb(clen >> 8, PIOP(base)); /* msb */
3172 outsb(PIOP(base), buf, clen);
3174 /* Indicate end of transmit chain */
3175 outb(OP0_NOP, PIOP(base));
3176 /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
3177 outb(OP0_NOP, PIOP(base));
3179 /* Reset the transmit DMA pointer */
3180 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3181 hacr_write(base, HACR_DEFAULT);
3182 /* Send the transmit command */
3183 wv_82593_cmd(dev, "wv_packet_write(): transmit",
3184 OP0_TRANSMIT, SR0_NO_RESULT);
3186 /* Make sure the watchdog will keep quiet for a while */
3187 dev->trans_start = jiffies;
3189 /* Keep stats up to date */
3190 lp->stats.tx_bytes += length;
3192 spin_unlock_irqrestore(&lp->spinlock, flags);
3194 #ifdef DEBUG_TX_INFO
3195 wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
3196 #endif /* DEBUG_TX_INFO */
3198 #ifdef DEBUG_TX_TRACE
3199 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
3203 /*------------------------------------------------------------------*/
3205 * This routine is called when we want to send a packet (NET3 callback)
3206 * In this routine, we check if the harware is ready to accept
3207 * the packet. We also prevent reentrance. Then, we call the function
3208 * to send the packet...
3211 wavelan_packet_xmit(struct sk_buff * skb,
3212 struct net_device * dev)
3214 net_local * lp = (net_local *)dev->priv;
3215 unsigned long flags;
3217 #ifdef DEBUG_TX_TRACE
3218 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
3223 * Block a timer-based transmit from overlapping a previous transmit.
3224 * In other words, prevent reentering this routine.
3226 netif_stop_queue(dev);
3228 /* If somebody has asked to reconfigure the controller,
3229 * we can do it now */
3230 if(lp->reconfig_82593)
3232 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
3233 wv_82593_config(dev);
3234 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
3235 /* Note : the configure procedure was totally synchronous,
3236 * so the Tx buffer is now free */
3239 #ifdef DEBUG_TX_ERROR
3241 printk(KERN_INFO "skb has next\n");
3244 /* Check if we need some padding */
3245 /* Note : on wireless the propagation time is in the order of 1us,
3246 * and we don't have the Ethernet specific requirement of beeing
3247 * able to detect collisions, therefore in theory we don't really
3248 * need to pad. Jean II */
3249 if (skb->len < ETH_ZLEN) {
3250 skb = skb_padto(skb, ETH_ZLEN);
3255 wv_packet_write(dev, skb->data, skb->len);
3259 #ifdef DEBUG_TX_TRACE
3260 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
3265 /********************** HARDWARE CONFIGURATION **********************/
3267 * This part do the real job of starting and configuring the hardware.
3270 /*------------------------------------------------------------------*/
3272 * Routine to initialize the Modem Management Controller.
3273 * (called by wv_hw_config())
3276 wv_mmc_init(struct net_device * dev)
3278 ioaddr_t base = dev->base_addr;
3282 int i; /* Loop counter */
3284 #ifdef DEBUG_CONFIG_TRACE
3285 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
3288 /* Read the parameter storage area */
3289 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3292 * Check the first three octets of the MAC addr for the manufacturer's code.
3293 * Note: If you get the error message below, you've got a
3294 * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
3295 * how to configure your card...
3297 for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3298 if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
3299 (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
3300 (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
3303 /* If we have not found it... */
3304 if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
3306 #ifdef DEBUG_CONFIG_ERRORS
3307 printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
3308 dev->name, psa.psa_univ_mac_addr[0],
3309 psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
3314 /* Get the MAC address */
3315 memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
3317 #ifdef USE_PSA_CONFIG
3318 configured = psa.psa_conf_status & 1;
3323 /* Is the PSA is not configured */
3326 /* User will be able to configure NWID after (with iwconfig) */
3327 psa.psa_nwid[0] = 0;
3328 psa.psa_nwid[1] = 0;
3330 /* As NWID is not set : no NWID checking */
3331 psa.psa_nwid_select = 0;
3333 /* Disable encryption */
3334 psa.psa_encryption_select = 0;
3336 /* Set to standard values
3339 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
3341 if (psa.psa_comp_number & 1)
3342 psa.psa_thr_pre_set = 0x01;
3344 psa.psa_thr_pre_set = 0x04;
3345 psa.psa_quality_thr = 0x03;
3347 /* It is configured */
3348 psa.psa_conf_status |= 1;
3350 #ifdef USE_PSA_CONFIG
3352 psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
3353 (unsigned char *)psa.psa_nwid, 4);
3354 psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
3355 (unsigned char *)&psa.psa_thr_pre_set, 1);
3356 psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
3357 (unsigned char *)&psa.psa_quality_thr, 1);
3358 psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
3359 (unsigned char *)&psa.psa_conf_status, 1);
3360 /* update the Wavelan checksum */
3361 update_psa_checksum(dev);
3362 #endif /* USE_PSA_CONFIG */
3365 /* Zero the mmc structure */
3366 memset(&m, 0x00, sizeof(m));
3368 /* Copy PSA info to the mmc */
3369 m.mmw_netw_id_l = psa.psa_nwid[1];
3370 m.mmw_netw_id_h = psa.psa_nwid[0];
3372 if(psa.psa_nwid_select & 1)
3373 m.mmw_loopt_sel = 0x00;
3375 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
3377 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
3378 sizeof(m.mmw_encr_key));
3380 if(psa.psa_encryption_select)
3381 m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
3383 m.mmw_encr_enable = 0;
3385 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
3386 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
3389 * Set default modem control parameters.
3390 * See NCR document 407-0024326 Rev. A.
3392 m.mmw_jabber_enable = 0x01;
3393 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
3395 m.mmw_mod_delay = 0x04;
3396 m.mmw_jam_time = 0x38;
3398 m.mmw_des_io_invert = 0;
3400 m.mmw_decay_prm = 0;
3401 m.mmw_decay_updat_prm = 0;
3403 /* Write all info to mmc */
3404 mmc_write(base, 0, (u_char *)&m, sizeof(m));
3406 /* The following code start the modem of the 2.00 frequency
3407 * selectable cards at power on. It's not strictly needed for the
3408 * following boots...
3409 * The original patch was by Joe Finney for the PCMCIA driver, but
3410 * I've cleaned it a bit and add documentation.
3411 * Thanks to Loeke Brederveld from Lucent for the info.
3414 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3415 * (does it work for everybody ? - especially old cards...) */
3416 /* Note : WFREQSEL verify that it is able to read from EEprom
3417 * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
3418 * is 0xA (Xilinx version) or 0xB (Ariadne version).
3419 * My test is more crude but do work... */
3420 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
3421 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
3423 /* We must download the frequency parameters to the
3424 * synthetisers (from the EEprom - area 1)
3425 * Note : as the EEprom is auto decremented, we set the end
3427 m.mmw_fee_addr = 0x0F;
3428 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3429 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3430 (unsigned char *)&m.mmw_fee_ctrl, 2);
3432 /* Wait until the download is finished */
3433 fee_wait(base, 100, 100);
3435 #ifdef DEBUG_CONFIG_INFO
3436 /* The frequency was in the last word downloaded... */
3437 mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
3438 (unsigned char *)&m.mmw_fee_data_l, 2);
3440 /* Print some info for the user */
3441 printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
3443 ((m.mmw_fee_data_h << 4) |
3444 (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
3447 /* We must now download the power adjust value (gain) to
3448 * the synthetisers (from the EEprom - area 7 - DAC) */
3449 m.mmw_fee_addr = 0x61;
3450 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3451 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3452 (unsigned char *)&m.mmw_fee_ctrl, 2);
3454 /* Wait until the download is finished */
3455 } /* if 2.00 card */
3457 #ifdef DEBUG_CONFIG_TRACE
3458 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3463 /*------------------------------------------------------------------*/
3465 * Routine to gracefully turn off reception, and wait for any commands
3467 * (called in wv_ru_start() and wavelan_close() and wavelan_event())
3470 wv_ru_stop(struct net_device * dev)
3472 ioaddr_t base = dev->base_addr;
3473 net_local * lp = (net_local *) dev->priv;
3474 unsigned long flags;
3478 #ifdef DEBUG_CONFIG_TRACE
3479 printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
3482 spin_lock_irqsave(&lp->spinlock, flags);
3484 /* First, send the LAN controller a stop receive command */
3485 wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
3486 OP0_STOP_RCV, SR0_NO_RESULT);
3488 /* Then, spin until the receive unit goes idle */
3493 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3494 status = inb(LCSR(base));
3496 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
3498 /* Now, spin until the chip finishes executing its current command */
3502 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3503 status = inb(LCSR(base));
3505 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
3507 spin_unlock_irqrestore(&lp->spinlock, flags);
3509 /* If there was a problem */
3512 #ifdef DEBUG_CONFIG_ERROR
3513 printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
3519 #ifdef DEBUG_CONFIG_TRACE
3520 printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
3525 /*------------------------------------------------------------------*/
3527 * This routine starts the receive unit running. First, it checks if
3528 * the card is actually ready. Then the card is instructed to receive
3530 * (called in wv_hw_reset() & wavelan_open())
3533 wv_ru_start(struct net_device * dev)
3535 ioaddr_t base = dev->base_addr;
3536 net_local * lp = (net_local *) dev->priv;
3537 unsigned long flags;
3539 #ifdef DEBUG_CONFIG_TRACE
3540 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3544 * We need to start from a quiescent state. To do so, we could check
3545 * if the card is already running, but instead we just try to shut
3546 * it down. First, we disable reception (in case it was already enabled).
3548 if(!wv_ru_stop(dev))
3551 spin_lock_irqsave(&lp->spinlock, flags);
3553 /* Now we know that no command is being executed. */
3555 /* Set the receive frame pointer and stop pointer */
3557 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3559 /* Reset ring management. This sets the receive frame pointer to 1 */
3560 outb(OP1_RESET_RING_MNGMT, LCCR(base));
3563 /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
3564 should be set as below */
3565 /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
3567 /* but I set it 0 instead */
3570 /* but I set it to 3 bytes per packet less than 8K */
3571 lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3573 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3574 outb(OP1_INT_ENABLE, LCCR(base));
3575 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3577 /* Reset receive DMA pointer */
3578 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3579 hacr_write_slow(base, HACR_DEFAULT);
3581 /* Receive DMA on channel 1 */
3582 wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
3583 CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
3585 #ifdef DEBUG_I82593_SHOW
3591 /* spin until the chip starts receiving */
3594 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3595 status = inb(LCSR(base));
3599 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
3600 ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
3601 printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
3602 (status & SR3_RCV_STATE_MASK), i);
3606 spin_unlock_irqrestore(&lp->spinlock, flags);
3608 #ifdef DEBUG_CONFIG_TRACE
3609 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3614 /*------------------------------------------------------------------*/
3616 * This routine does a standard config of the WaveLAN controller (i82593).
3617 * In the ISA driver, this is integrated in wavelan_hardware_reset()
3618 * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
3621 wv_82593_config(struct net_device * dev)
3623 ioaddr_t base = dev->base_addr;
3624 net_local * lp = (net_local *) dev->priv;
3625 struct i82593_conf_block cfblk;
3628 #ifdef DEBUG_CONFIG_TRACE
3629 printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
3632 /* Create & fill i82593 config block
3634 * Now conform to Wavelan document WCIN085B
3636 memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
3637 cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
3638 cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
3639 cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
3641 cfblk.throttle_enb = FALSE;
3642 cfblk.contin = TRUE; /* enable continuous mode */
3643 cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
3644 cfblk.addr_len = WAVELAN_ADDR_SIZE;
3645 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
3646 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
3647 cfblk.loopback = FALSE;
3648 cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */
3649 cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */
3650 cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */
3651 cfblk.ifrm_spc = 0x20; /* 32 bit times interframe spacing */
3652 cfblk.slottim_low = 0x20; /* 32 bit times slot time */
3653 cfblk.slottim_hi = 0x0;
3654 cfblk.max_retr = 15;
3655 cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
3656 cfblk.bc_dis = FALSE; /* Enable broadcast reception */
3657 cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
3658 cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
3659 cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
3660 cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
3661 cfblk.cs_filter = 0; /* CS is recognized immediately */
3662 cfblk.crs_src = FALSE; /* External carrier sense */
3663 cfblk.cd_filter = 0; /* CD is recognized immediately */
3664 cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
3665 cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
3666 cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
3667 cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
3668 cfblk.artx = TRUE; /* Disable automatic retransmission */
3669 cfblk.sarec = TRUE; /* Disable source addr trig of CD */
3670 cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
3671 cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
3672 cfblk.lbpkpol = TRUE; /* Loopback pin active high */
3673 cfblk.fdx = FALSE; /* Disable full duplex operation */
3674 cfblk.dummy_6 = 0x3f; /* all ones */
3675 cfblk.mult_ia = FALSE; /* No multiple individual addresses */
3676 cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
3677 cfblk.dummy_1 = TRUE; /* set to 1 */
3678 cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
3679 #ifdef MULTICAST_ALL
3680 cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
3682 cfblk.mc_all = FALSE; /* No multicast all mode */
3684 cfblk.rcv_mon = 0; /* Monitor mode disabled */
3685 cfblk.frag_acpt = TRUE; /* Do not accept fragments */
3686 cfblk.tstrttrs = FALSE; /* No start transmission threshold */
3687 cfblk.fretx = TRUE; /* FIFO automatic retransmission */
3688 cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
3689 cfblk.sttlen = TRUE; /* 6 byte status registers */
3690 cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
3691 cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
3692 cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
3693 cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
3695 #ifdef DEBUG_I82593_SHOW
3697 u_char *c = (u_char *) &cfblk;
3699 printk(KERN_DEBUG "wavelan_cs: config block:");
3700 for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
3702 if((i % 16) == 0) printk("\n" KERN_DEBUG);
3703 printk("%02x ", *c);
3709 /* Copy the config block to the i82593 */
3710 outb(TX_BASE & 0xff, PIORL(base));
3711 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3712 outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
3713 outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
3714 outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
3716 /* reset transmit DMA pointer */
3717 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3718 hacr_write(base, HACR_DEFAULT);
3719 if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
3720 OP0_CONFIGURE, SR0_CONFIGURE_DONE))
3723 /* Initialize adapter's ethernet MAC address */
3724 outb(TX_BASE & 0xff, PIORL(base));
3725 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3726 outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
3727 outb(0, PIOP(base)); /* byte count msb */
3728 outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
3730 /* reset transmit DMA pointer */
3731 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3732 hacr_write(base, HACR_DEFAULT);
3733 if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
3734 OP0_IA_SETUP, SR0_IA_SETUP_DONE))
3737 #ifdef WAVELAN_ROAMING
3738 /* If roaming is enabled, join the "Beacon Request" multicast group... */
3739 /* But only if it's not in there already! */
3741 dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
3742 #endif /* WAVELAN_ROAMING */
3744 /* If any multicast address to set */
3747 struct dev_mc_list * dmi;
3748 int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
3750 #ifdef DEBUG_CONFIG_INFO
3751 printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
3752 dev->name, lp->mc_count);
3753 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3754 printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n",
3755 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
3756 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
3759 /* Initialize adapter's ethernet multicast addresses */
3760 outb(TX_BASE & 0xff, PIORL(base));
3761 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3762 outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
3763 outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
3764 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3765 outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
3767 /* reset transmit DMA pointer */
3768 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3769 hacr_write(base, HACR_DEFAULT);
3770 if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
3771 OP0_MC_SETUP, SR0_MC_SETUP_DONE))
3773 lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
3776 /* Job done, clear the flag */
3777 lp->reconfig_82593 = FALSE;
3779 #ifdef DEBUG_CONFIG_TRACE
3780 printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
3785 /*------------------------------------------------------------------*/
3787 * Read the Access Configuration Register, perform a software reset,
3788 * and then re-enable the card's software.
3790 * If I understand correctly : reset the pcmcia interface of the
3792 * (called by wv_config())
3795 wv_pcmcia_reset(struct net_device * dev)
3798 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
3799 dev_link_t * link = ((net_local *) dev->priv)->link;
3801 #ifdef DEBUG_CONFIG_TRACE
3802 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
3805 i = pcmcia_access_configuration_register(link->handle, ®);
3808 cs_error(link->handle, AccessConfigurationRegister, i);
3812 #ifdef DEBUG_CONFIG_INFO
3813 printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
3814 dev->name, (u_int) reg.Value);
3817 reg.Action = CS_WRITE;
3818 reg.Value = reg.Value | COR_SW_RESET;
3819 i = pcmcia_access_configuration_register(link->handle, ®);
3822 cs_error(link->handle, AccessConfigurationRegister, i);
3826 reg.Action = CS_WRITE;
3827 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3828 i = pcmcia_access_configuration_register(link->handle, ®);
3831 cs_error(link->handle, AccessConfigurationRegister, i);
3835 #ifdef DEBUG_CONFIG_TRACE
3836 printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
3841 /*------------------------------------------------------------------*/
3843 * wavelan_hw_config() is called after a CARD_INSERTION event is
3844 * received, to configure the wavelan hardware.
3845 * Note that the reception will be enabled in wavelan->open(), so the
3846 * device is configured but idle...
3847 * Performs the following actions:
3848 * 1. A pcmcia software reset (using wv_pcmcia_reset())
3849 * 2. A power reset (reset DMA)
3850 * 3. Reset the LAN controller
3851 * 4. Initialize the radio modem (using wv_mmc_init)
3852 * 5. Configure LAN controller (using wv_82593_config)
3853 * 6. Perform a diagnostic on the LAN controller
3854 * (called by wavelan_event() & wv_hw_reset())
3857 wv_hw_config(struct net_device * dev)
3859 net_local * lp = (net_local *) dev->priv;
3860 ioaddr_t base = dev->base_addr;
3861 unsigned long flags;
3864 #ifdef DEBUG_CONFIG_TRACE
3865 printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
3869 if(wv_structuct_check() != (char *) NULL)
3871 printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: \"%s\"\n",
3872 dev->name, wv_structuct_check());
3875 #endif /* STRUCT_CHECK == 1 */
3877 /* Reset the pcmcia interface */
3878 if(wv_pcmcia_reset(dev) == FALSE)
3881 /* Disable interrupts */
3882 spin_lock_irqsave(&lp->spinlock, flags);
3884 /* Disguised goto ;-) */
3887 /* Power UP the module + reset the modem + reset host adapter
3888 * (in fact, reset DMA channels) */
3889 hacr_write_slow(base, HACR_RESET);
3890 hacr_write(base, HACR_DEFAULT);
3892 /* Check if the module has been powered up... */
3893 if(hasr_read(base) & HASR_NO_CLK)
3895 #ifdef DEBUG_CONFIG_ERRORS
3896 printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
3902 /* initialize the modem */
3903 if(wv_mmc_init(dev) == FALSE)
3905 #ifdef DEBUG_CONFIG_ERRORS
3906 printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n",
3912 /* reset the LAN controller (i82593) */
3913 outb(OP0_RESET, LCCR(base));
3914 mdelay(1); /* A bit crude ! */
3916 /* Initialize the LAN controller */
3917 if(wv_82593_config(dev) == FALSE)
3919 #ifdef DEBUG_CONFIG_ERRORS
3920 printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n",
3927 if(wv_diag(dev) == FALSE)
3929 #ifdef DEBUG_CONFIG_ERRORS
3930 printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n",
3937 * insert code for loopback test here
3940 /* The device is now configured */
3946 /* Re-enable interrupts */
3947 spin_unlock_irqrestore(&lp->spinlock, flags);
3949 #ifdef DEBUG_CONFIG_TRACE
3950 printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
3955 /*------------------------------------------------------------------*/
3957 * Totally reset the wavelan and restart it.
3958 * Performs the following actions:
3959 * 1. Call wv_hw_config()
3960 * 2. Start the LAN controller's receive unit
3961 * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
3964 wv_hw_reset(struct net_device * dev)
3966 net_local * lp = (net_local *) dev->priv;
3968 #ifdef DEBUG_CONFIG_TRACE
3969 printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
3975 /* Call wv_hw_config() for most of the reset & init stuff */
3976 if(wv_hw_config(dev) == FALSE)
3979 /* start receive unit */
3982 #ifdef DEBUG_CONFIG_TRACE
3983 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3987 /*------------------------------------------------------------------*/
3989 * wv_pcmcia_config() is called after a CARD_INSERTION event is
3990 * received, to configure the PCMCIA socket, and to make the ethernet
3991 * device available to the system.
3992 * (called by wavelan_event())
3995 wv_pcmcia_config(dev_link_t * link)
3997 client_handle_t handle;
4000 struct net_device * dev;
4006 handle = link->handle;
4007 dev = (struct net_device *) link->priv;
4009 #ifdef DEBUG_CONFIG_TRACE
4010 printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
4014 * This reads the card's CONFIG tuple to find its configuration
4019 tuple.Attributes = 0;
4020 tuple.DesiredTuple = CISTPL_CONFIG;
4021 i = pcmcia_get_first_tuple(handle, &tuple);
4024 tuple.TupleData = (cisdata_t *)buf;
4025 tuple.TupleDataMax = 64;
4026 tuple.TupleOffset = 0;
4027 i = pcmcia_get_tuple_data(handle, &tuple);
4030 i = pcmcia_parse_tuple(handle, &tuple, &parse);
4033 link->conf.ConfigBase = parse.config.base;
4034 link->conf.Present = parse.config.rmask[0];
4039 cs_error(link->handle, ParseTuple, i);
4040 link->state &= ~DEV_CONFIG_PENDING;
4044 /* Configure card */
4045 link->state |= DEV_CONFIG;
4048 i = pcmcia_request_io(link->handle, &link->io);
4051 cs_error(link->handle, RequestIO, i);
4056 * Now allocate an interrupt line. Note that this does not
4057 * actually assign a handler to the interrupt.
4059 i = pcmcia_request_irq(link->handle, &link->irq);
4062 cs_error(link->handle, RequestIRQ, i);
4067 * This actually configures the PCMCIA socket -- setting up
4068 * the I/O windows and the interrupt mapping.
4070 link->conf.ConfigIndex = 1;
4071 i = pcmcia_request_configuration(link->handle, &link->conf);
4074 cs_error(link->handle, RequestConfiguration, i);
4079 * Allocate a small memory window. Note that the dev_link_t
4080 * structure provides space for one window handle -- if your
4081 * device needs several windows, you'll need to keep track of
4082 * the handles in your private data structure, link->priv.
4084 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
4085 req.Base = req.Size = 0;
4086 req.AccessSpeed = mem_speed;
4087 i = pcmcia_request_window(&link->handle, &req, &link->win);
4090 cs_error(link->handle, RequestWindow, i);
4094 dev->mem_start = (u_long)ioremap(req.Base, req.Size);
4095 dev->mem_end = dev->mem_start + req.Size;
4097 mem.CardOffset = 0; mem.Page = 0;
4098 i = pcmcia_map_mem_page(link->win, &mem);
4101 cs_error(link->handle, MapMemPage, i);
4105 /* Feed device with this info... */
4106 dev->irq = link->irq.AssignedIRQ;
4107 dev->base_addr = link->io.BasePort1;
4108 netif_start_queue(dev);
4110 #ifdef DEBUG_CONFIG_INFO
4111 printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART 0x%x IRQ %d IOPORT 0x%x\n",
4112 (u_int) dev->mem_start, dev->irq, (u_int) dev->base_addr);
4115 i = register_netdev(dev);
4118 #ifdef DEBUG_CONFIG_ERRORS
4119 printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
4124 while(0); /* Humm... Disguised goto !!! */
4126 link->state &= ~DEV_CONFIG_PENDING;
4127 /* If any step failed, release any partially configured state */
4130 wv_pcmcia_release(link);
4134 strcpy(((net_local *) dev->priv)->node.dev_name, dev->name);
4135 link->dev = &((net_local *) dev->priv)->node;
4137 #ifdef DEBUG_CONFIG_TRACE
4138 printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
4143 /*------------------------------------------------------------------*/
4145 * After a card is removed, wv_pcmcia_release() will unregister the net
4146 * device, and release the PCMCIA configuration. If the device is
4147 * still open, this will be postponed until it is closed.
4150 wv_pcmcia_release(dev_link_t *link)
4152 struct net_device * dev = (struct net_device *) link->priv;
4154 #ifdef DEBUG_CONFIG_TRACE
4155 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
4158 /* Don't bother checking to see if these succeed or not */
4159 iounmap((u_char *)dev->mem_start);
4160 pcmcia_release_window(link->win);
4161 pcmcia_release_configuration(link->handle);
4162 pcmcia_release_io(link->handle, &link->io);
4163 pcmcia_release_irq(link->handle, &link->irq);
4165 link->state &= ~DEV_CONFIG;
4167 #ifdef DEBUG_CONFIG_TRACE
4168 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
4172 /************************ INTERRUPT HANDLING ************************/
4175 * This function is the interrupt handler for the WaveLAN card. This
4176 * routine will be called whenever:
4177 * 1. A packet is received.
4178 * 2. A packet has successfully been transferred and the unit is
4179 * ready to transmit another packet.
4180 * 3. A command has completed execution.
4183 wavelan_interrupt(int irq,
4185 struct pt_regs * regs)
4187 struct net_device * dev;
4193 if ((dev = dev_id) == NULL)
4195 #ifdef DEBUG_INTERRUPT_ERROR
4196 printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.\n",
4202 #ifdef DEBUG_INTERRUPT_TRACE
4203 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
4206 lp = (net_local *) dev->priv;
4207 base = dev->base_addr;
4209 #ifdef DEBUG_INTERRUPT_INFO
4210 /* Check state of our spinlock (it should be cleared) */
4211 if(spin_is_locked(&lp->spinlock))
4213 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
4217 /* Prevent reentrancy. We need to do that because we may have
4218 * multiple interrupt handler running concurently.
4219 * It is safe because interrupts are disabled before aquiring
4221 spin_lock(&lp->spinlock);
4223 /* Treat all pending interrupts */
4226 /* ---------------- INTERRUPT CHECKING ---------------- */
4228 * Look for the interrupt and verify the validity
4230 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
4231 status0 = inb(LCSR(base));
4233 #ifdef DEBUG_INTERRUPT_INFO
4234 printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
4235 (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
4236 if(status0&SR0_INTERRUPT)
4238 printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
4239 ((status0 & SR0_EXECUTION) ? "cmd" :
4240 ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
4241 (status0 & SR0_EVENT_MASK));
4247 /* Return if no actual interrupt from i82593 (normal exit) */
4248 if(!(status0 & SR0_INTERRUPT))
4251 /* If interrupt is both Rx and Tx or none...
4252 * This code in fact is there to catch the spurious interrupt
4253 * when you remove the wavelan pcmcia card from the socket */
4254 if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
4255 ((status0 & SR0_BOTH_RX_TX) == 0x0))
4257 #ifdef DEBUG_INTERRUPT_INFO
4258 printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
4259 dev->name, status0);
4261 /* Acknowledge the interrupt */
4262 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4266 /* ----------------- RECEIVING PACKET ----------------- */
4268 * When the wavelan signal the reception of a new packet,
4269 * we call wv_packet_rcv() to copy if from the buffer and
4272 if(status0 & SR0_RECEPTION)
4274 #ifdef DEBUG_INTERRUPT_INFO
4275 printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
4278 if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
4280 #ifdef DEBUG_INTERRUPT_ERROR
4281 printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
4284 lp->stats.rx_over_errors++;
4285 lp->overrunning = 1;
4288 /* Get the packet */
4290 lp->overrunning = 0;
4292 /* Acknowledge the interrupt */
4293 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4297 /* ---------------- COMMAND COMPLETION ---------------- */
4299 * Interrupts issued when the i82593 has completed a command.
4300 * Most likely : transmission done
4303 /* If a transmission has been done */
4304 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
4305 (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
4306 (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4308 #ifdef DEBUG_TX_ERROR
4309 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4310 printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
4314 /* Get transmission status */
4315 tx_status = inb(LCSR(base));
4316 tx_status |= (inb(LCSR(base)) << 8);
4317 #ifdef DEBUG_INTERRUPT_INFO
4318 printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
4323 rcv_bytes = inb(LCSR(base));
4324 rcv_bytes |= (inb(LCSR(base)) << 8);
4325 status3 = inb(LCSR(base));
4326 printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
4327 tx_status, rcv_bytes, (u_int) status3);
4330 /* Check for possible errors */
4331 if((tx_status & TX_OK) != TX_OK)
4333 lp->stats.tx_errors++;
4335 if(tx_status & TX_FRTL)
4337 #ifdef DEBUG_TX_ERROR
4338 printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
4342 if(tx_status & TX_UND_RUN)
4344 #ifdef DEBUG_TX_FAIL
4345 printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
4348 lp->stats.tx_aborted_errors++;
4350 if(tx_status & TX_LOST_CTS)
4352 #ifdef DEBUG_TX_FAIL
4353 printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
4355 lp->stats.tx_carrier_errors++;
4357 if(tx_status & TX_LOST_CRS)
4359 #ifdef DEBUG_TX_FAIL
4360 printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
4363 lp->stats.tx_carrier_errors++;
4365 if(tx_status & TX_HRT_BEAT)
4367 #ifdef DEBUG_TX_FAIL
4368 printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
4370 lp->stats.tx_heartbeat_errors++;
4372 if(tx_status & TX_DEFER)
4374 #ifdef DEBUG_TX_FAIL
4375 printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
4379 /* Ignore late collisions since they're more likely to happen
4380 * here (the WaveLAN design prevents the LAN controller from
4381 * receiving while it is transmitting). We take action only when
4382 * the maximum retransmit attempts is exceeded.
4384 if(tx_status & TX_COLL)
4386 if(tx_status & TX_MAX_COL)
4388 #ifdef DEBUG_TX_FAIL
4389 printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
4392 if(!(tx_status & TX_NCOL_MASK))
4394 lp->stats.collisions += 0x10;
4398 } /* if(!(tx_status & TX_OK)) */
4400 lp->stats.collisions += (tx_status & TX_NCOL_MASK);
4401 lp->stats.tx_packets++;
4403 netif_wake_queue(dev);
4404 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4406 else /* if interrupt = transmit done or retransmit done */
4408 #ifdef DEBUG_INTERRUPT_ERROR
4409 printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
4412 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4416 spin_unlock(&lp->spinlock);
4418 #ifdef DEBUG_INTERRUPT_TRACE
4419 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
4422 /* We always return IRQ_HANDLED, because we will receive empty
4423 * interrupts under normal operations. Anyway, it doesn't matter
4424 * as we are dealing with an ISA interrupt that can't be shared.
4426 * Explanation : under heavy receive, the following happens :
4427 * ->wavelan_interrupt()
4428 * (status0 & SR0_INTERRUPT) != 0
4430 * (status0 & SR0_INTERRUPT) != 0
4432 * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event
4433 * <-wavelan_interrupt()
4434 * ->wavelan_interrupt()
4435 * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt
4436 * <-wavelan_interrupt()
4439 } /* wv_interrupt */
4441 /*------------------------------------------------------------------*/
4443 * Watchdog: when we start a transmission, a timer is set for us in the
4444 * kernel. If the transmission completes, this timer is disabled. If
4445 * the timer expires, we are called and we try to unlock the hardware.
4447 * Note : This watchdog is move clever than the one in the ISA driver,
4448 * because it try to abort the current command before reseting
4450 * On the other hand, it's a bit simpler, because we don't have to
4451 * deal with the multiple Tx buffers...
4454 wavelan_watchdog(struct net_device * dev)
4456 net_local * lp = (net_local *) dev->priv;
4457 ioaddr_t base = dev->base_addr;
4458 unsigned long flags;
4459 int aborted = FALSE;
4461 #ifdef DEBUG_INTERRUPT_TRACE
4462 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
4465 #ifdef DEBUG_INTERRUPT_ERROR
4466 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
4470 spin_lock_irqsave(&lp->spinlock, flags);
4472 /* Ask to abort the current command */
4473 outb(OP0_ABORT, LCCR(base));
4475 /* Wait for the end of the command (a bit hackish) */
4476 if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
4477 OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
4480 /* Release spinlock here so that wv_hw_reset() can grab it */
4481 spin_unlock_irqrestore(&lp->spinlock, flags);
4483 /* Check if we were successful in aborting it */
4486 /* It seem that it wasn't enough */
4487 #ifdef DEBUG_INTERRUPT_ERROR
4488 printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
4494 #ifdef DEBUG_PSA_SHOW
4497 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
4501 #ifdef DEBUG_MMC_SHOW
4504 #ifdef DEBUG_I82593_SHOW
4508 /* We are no more waiting for something... */
4509 netif_wake_queue(dev);
4511 #ifdef DEBUG_INTERRUPT_TRACE
4512 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
4516 /********************* CONFIGURATION CALLBACKS *********************/
4518 * Here are the functions called by the pcmcia package (cardmgr) and
4519 * linux networking (NET3) for initialization, configuration and
4520 * deinstallations of the Wavelan Pcmcia Hardware.
4523 /*------------------------------------------------------------------*/
4525 * Configure and start up the WaveLAN PCMCIA adaptor.
4526 * Called by NET3 when it "open" the device.
4529 wavelan_open(struct net_device * dev)
4531 dev_link_t * link = ((net_local *) dev->priv)->link;
4532 net_local * lp = (net_local *)dev->priv;
4533 ioaddr_t base = dev->base_addr;
4535 #ifdef DEBUG_CALLBACK_TRACE
4536 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
4537 (unsigned int) dev);
4540 /* Check if the modem is powered up (wavelan_close() power it down */
4541 if(hasr_read(base) & HASR_NO_CLK)
4543 /* Power up (power up time is 250us) */
4544 hacr_write(base, HACR_DEFAULT);
4546 /* Check if the module has been powered up... */
4547 if(hasr_read(base) & HASR_NO_CLK)
4549 #ifdef DEBUG_CONFIG_ERRORS
4550 printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
4557 /* Start reception and declare the driver ready */
4560 if(!wv_ru_start(dev))
4561 wv_hw_reset(dev); /* If problem : reset */
4562 netif_start_queue(dev);
4564 /* Mark the device as used */
4567 #ifdef WAVELAN_ROAMING
4570 #endif /* WAVELAN_ROAMING */
4572 #ifdef DEBUG_CALLBACK_TRACE
4573 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
4578 /*------------------------------------------------------------------*/
4580 * Shutdown the WaveLAN PCMCIA adaptor.
4581 * Called by NET3 when it "close" the device.
4584 wavelan_close(struct net_device * dev)
4586 dev_link_t * link = ((net_local *) dev->priv)->link;
4587 ioaddr_t base = dev->base_addr;
4589 #ifdef DEBUG_CALLBACK_TRACE
4590 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
4591 (unsigned int) dev);
4594 /* If the device isn't open, then nothing to do */
4597 #ifdef DEBUG_CONFIG_INFO
4598 printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
4603 #ifdef WAVELAN_ROAMING
4604 /* Cleanup of roaming stuff... */
4606 wv_roam_cleanup(dev);
4607 #endif /* WAVELAN_ROAMING */
4611 /* If the card is still present */
4612 if(netif_running(dev))
4614 netif_stop_queue(dev);
4616 /* Stop receiving new messages and wait end of transmission */
4619 /* Power down the module */
4620 hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
4623 #ifdef DEBUG_CALLBACK_TRACE
4624 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
4629 /*------------------------------------------------------------------*/
4631 * wavelan_attach() creates an "instance" of the driver, allocating
4632 * local data structures for one device (one interface). The device
4633 * is registered with Card Services.
4635 * The dev_link structure is initialized, but we don't actually
4636 * configure the card at this point -- we wait until we receive a
4637 * card insertion event.
4640 wavelan_attach(void)
4642 client_reg_t client_reg; /* Register with cardmgr */
4643 dev_link_t * link; /* Info for cardmgr */
4644 struct net_device * dev; /* Interface generic data */
4645 net_local * lp; /* Interface specific data */
4648 #ifdef DEBUG_CALLBACK_TRACE
4649 printk(KERN_DEBUG "-> wavelan_attach()\n");
4652 /* Initialize the dev_link_t structure */
4653 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
4654 if (!link) return NULL;
4655 memset(link, 0, sizeof(struct dev_link_t));
4657 /* The io structure describes IO port mapping */
4658 link->io.NumPorts1 = 8;
4659 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
4660 link->io.IOAddrLines = 3;
4662 /* Interrupt setup */
4663 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
4664 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
4665 if (irq_list[0] == -1)
4666 link->irq.IRQInfo2 = irq_mask;
4668 for (i = 0; i < 4; i++)
4669 link->irq.IRQInfo2 |= 1 << irq_list[i];
4670 link->irq.Handler = wavelan_interrupt;
4672 /* General socket configuration */
4673 link->conf.Attributes = CONF_ENABLE_IRQ;
4674 link->conf.Vcc = 50;
4675 link->conf.IntType = INT_MEMORY_AND_IO;
4678 link->next = dev_list;
4681 /* Allocate the generic data structure */
4682 dev = alloc_etherdev(sizeof(net_local));
4687 link->priv = link->irq.Instance = dev;
4691 /* Init specific data */
4693 lp->reconfig_82593 = FALSE;
4695 /* Multicast stuff */
4696 lp->promiscuous = 0;
4697 lp->allmulticast = 0;
4701 spin_lock_init(&lp->spinlock);
4707 /* wavelan NET3 callbacks */
4708 SET_MODULE_OWNER(dev);
4709 dev->open = &wavelan_open;
4710 dev->stop = &wavelan_close;
4711 dev->hard_start_xmit = &wavelan_packet_xmit;
4712 dev->get_stats = &wavelan_get_stats;
4713 dev->set_multicast_list = &wavelan_set_multicast_list;
4714 #ifdef SET_MAC_ADDRESS
4715 dev->set_mac_address = &wavelan_set_mac_address;
4716 #endif /* SET_MAC_ADDRESS */
4718 /* Set the watchdog timer */
4719 dev->tx_timeout = &wavelan_watchdog;
4720 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4722 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
4723 dev->wireless_handlers = (struct iw_handler_def *)&wavelan_handler_def;
4724 dev->do_ioctl = wavelan_ioctl; /* old wireless extensions */
4725 dev->get_wireless_stats = wavelan_get_wireless_stats;
4728 /* Other specific data */
4729 dev->mtu = WAVELAN_MTU;
4731 /* Register with Card Services */
4732 client_reg.dev_info = &dev_info;
4733 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
4734 client_reg.EventMask =
4735 CS_EVENT_REGISTRATION_COMPLETE |
4736 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
4737 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
4738 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
4739 client_reg.event_handler = &wavelan_event;
4740 client_reg.Version = 0x0210;
4741 client_reg.event_callback_args.client_data = link;
4743 #ifdef DEBUG_CONFIG_INFO
4744 printk(KERN_DEBUG "wavelan_attach(): almost done, calling pcmcia_register_client\n");
4747 ret = pcmcia_register_client(&link->handle, &client_reg);
4750 cs_error(link->handle, RegisterClient, ret);
4751 wavelan_detach(link);
4755 #ifdef DEBUG_CALLBACK_TRACE
4756 printk(KERN_DEBUG "<- wavelan_attach()\n");
4762 /*------------------------------------------------------------------*/
4764 * This deletes a driver "instance". The device is de-registered with
4765 * Card Services. If it has been released, all local data structures
4766 * are freed. Otherwise, the structures will be freed when the device
4770 wavelan_detach(dev_link_t * link)
4772 #ifdef DEBUG_CALLBACK_TRACE
4773 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4777 * If the device is currently configured and active, we won't
4778 * actually delete it yet. Instead, it is marked so that when the
4779 * release() function is called, that will trigger a proper
4782 if(link->state & DEV_CONFIG)
4784 /* Some others haven't done their job : give them another chance */
4785 wv_pcmcia_release(link);
4788 /* Break the link with Card Services */
4790 pcmcia_deregister_client(link->handle);
4792 /* Remove the interface data from the linked list */
4793 if(dev_list == link)
4794 dev_list = link->next;
4797 dev_link_t * prev = dev_list;
4799 while((prev != (dev_link_t *) NULL) && (prev->next != link))
4802 if(prev == (dev_link_t *) NULL)
4804 #ifdef DEBUG_CONFIG_ERRORS
4805 printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.\n");
4810 prev->next = link->next;
4816 struct net_device * dev = (struct net_device *) link->priv;
4818 /* Remove ourselves from the kernel list of ethernet devices */
4819 /* Warning : can't be called from interrupt, timer or wavelan_close() */
4821 unregister_netdev(dev);
4823 ((net_local *) dev->priv)->link = NULL;
4824 ((net_local *) dev->priv)->dev = NULL;
4829 #ifdef DEBUG_CALLBACK_TRACE
4830 printk(KERN_DEBUG "<- wavelan_detach()\n");
4834 /*------------------------------------------------------------------*/
4836 * The card status event handler. Mostly, this schedules other stuff
4837 * to run after an event is received. A CARD_REMOVAL event also sets
4838 * some flags to discourage the net drivers from trying to talk to the
4842 wavelan_event(event_t event, /* The event received */
4844 event_callback_args_t * args)
4846 dev_link_t * link = (dev_link_t *) args->client_data;
4847 struct net_device * dev = (struct net_device *) link->priv;
4849 #ifdef DEBUG_CALLBACK_TRACE
4850 printk(KERN_DEBUG "->wavelan_event(): %s\n",
4851 ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" :
4852 ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" :
4853 ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" :
4854 ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" :
4855 ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" :
4856 ((event == CS_EVENT_PM_RESUME) ? "pm resume" :
4857 ((event == CS_EVENT_CARD_RESET) ? "card reset" :
4863 case CS_EVENT_REGISTRATION_COMPLETE:
4864 #ifdef DEBUG_CONFIG_INFO
4865 printk(KERN_DEBUG "wavelan_cs: registration complete\n");
4869 case CS_EVENT_CARD_REMOVAL:
4870 /* Oups ! The card is no more there */
4871 link->state &= ~DEV_PRESENT;
4872 if(link->state & DEV_CONFIG)
4874 /* Accept no more transmissions */
4875 netif_device_detach(dev);
4877 /* Release the card */
4878 wv_pcmcia_release(link);
4882 case CS_EVENT_CARD_INSERTION:
4883 /* Reset and configure the card */
4884 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
4885 if(wv_pcmcia_config(link) &&
4892 case CS_EVENT_PM_SUSPEND:
4893 /* NB: wavelan_close will be called, but too late, so we are
4894 * obliged to close nicely the wavelan here. David, could you
4895 * close the device before suspending them ? And, by the way,
4896 * could you, on resume, add a "route add -net ..." after the
4897 * ifconfig up ? Thanks... */
4899 /* Stop receiving new messages and wait end of transmission */
4902 /* Power down the module */
4903 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
4905 /* The card is now suspended */
4906 link->state |= DEV_SUSPEND;
4907 /* Fall through... */
4908 case CS_EVENT_RESET_PHYSICAL:
4909 if(link->state & DEV_CONFIG)
4912 netif_device_detach(dev);
4913 pcmcia_release_configuration(link->handle);
4917 case CS_EVENT_PM_RESUME:
4918 link->state &= ~DEV_SUSPEND;
4919 /* Fall through... */
4920 case CS_EVENT_CARD_RESET:
4921 if(link->state & DEV_CONFIG)
4923 pcmcia_request_configuration(link->handle, &link->conf);
4924 if(link->open) /* If RESET -> True, If RESUME -> False ? */
4927 netif_device_attach(dev);
4933 #ifdef DEBUG_CALLBACK_TRACE
4934 printk(KERN_DEBUG "<-wavelan_event()\n");
4939 static struct pcmcia_driver wavelan_driver = {
4940 .owner = THIS_MODULE,
4942 .name = "wavelan_cs",
4944 .attach = wavelan_attach,
4945 .detach = wavelan_detach,
4949 init_wavelan_cs(void)
4951 return pcmcia_register_driver(&wavelan_driver);
4955 exit_wavelan_cs(void)
4957 pcmcia_unregister_driver(&wavelan_driver);
4960 module_init(init_wavelan_cs);
4961 module_exit(exit_wavelan_cs);