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 #ifdef WAVELAN_ROAMING
63 static void wl_cell_expiry(unsigned long data);
64 static void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp);
65 static void wv_nwid_filter(unsigned char mode, net_local *lp);
66 #endif /* WAVELAN_ROAMING */
68 /************************* MISC SUBROUTINES **************************/
70 * Subroutines which won't fit in one of the following category
71 * (wavelan modem or i82593)
74 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
76 * Useful subroutines to manage the modem of the wavelan
79 /*------------------------------------------------------------------*/
81 * Read from card's Host Adaptor Status Register.
84 hasr_read(u_long base)
86 return(inb(HASR(base)));
89 /*------------------------------------------------------------------*/
91 * Write to card's Host Adapter Command Register.
94 hacr_write(u_long base,
97 outb(hacr, HACR(base));
100 /*------------------------------------------------------------------*/
102 * Write to card's Host Adapter Command Register. Include a delay for
103 * those times when it is needed.
106 hacr_write_slow(u_long base,
109 hacr_write(base, hacr);
110 /* delay might only be needed sometimes */
112 } /* hacr_write_slow */
114 /*------------------------------------------------------------------*/
116 * Read the Parameter Storage Area from the WaveLAN card's memory
119 psa_read(struct net_device * dev,
120 int o, /* offset in PSA */
121 u_char * b, /* buffer to fill */
122 int n) /* size to read */
124 net_local *lp = netdev_priv(dev);
125 u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
130 /* Due to a lack of address decode pins, the WaveLAN PCMCIA card
131 * only supports reading even memory addresses. That means the
132 * increment here MUST be two.
133 * Because of that, we can't use memcpy_fromio()...
139 /*------------------------------------------------------------------*/
141 * Write the Paramter Storage Area to the WaveLAN card's memory
144 psa_write(struct net_device * dev,
145 int o, /* Offset in psa */
146 u_char * b, /* Buffer in memory */
147 int n) /* Length of buffer */
149 net_local *lp = netdev_priv(dev);
150 u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
152 unsigned int base = dev->base_addr;
153 /* As there seem to have no flag PSA_BUSY as in the ISA model, we are
154 * oblige to verify this address to know when the PSA is ready... */
155 volatile u_char __iomem *verify = lp->mem + PSA_ADDR +
156 (psaoff(0, psa_comp_number) << 1);
158 /* Authorize writing to PSA */
159 hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN);
167 /* I don't have the spec, so I don't know what the correct
168 * sequence to write is. This hack seem to work for me... */
170 while((readb(verify) != PSA_COMP_PCMCIA_915) && (count++ < 100))
174 /* Put the host interface back in standard state */
175 hacr_write(base, HACR_DEFAULT);
179 /*------------------------------------------------------------------*/
181 * Calculate the PSA CRC
182 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
183 * NOTE: By specifying a length including the CRC position the
184 * returned value should be zero. (i.e. a correct checksum in the PSA)
186 * The Windows drivers don't use the CRC, but the AP and the PtP tool
190 psa_crc(unsigned char * psa, /* The PSA */
191 int size) /* Number of short for CRC */
193 int byte_cnt; /* Loop on the PSA */
194 u_short crc_bytes = 0; /* Data in the PSA */
195 int bit_cnt; /* Loop on the bits of the short */
197 for(byte_cnt = 0; byte_cnt < size; byte_cnt++ )
199 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
201 for(bit_cnt = 1; bit_cnt < 9; bit_cnt++ )
203 if(crc_bytes & 0x0001)
204 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
212 #endif /* SET_PSA_CRC */
214 /*------------------------------------------------------------------*/
216 * update the checksum field in the Wavelan's PSA
219 update_psa_checksum(struct net_device * dev)
225 /* read the parameter storage area */
226 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
228 /* update the checksum */
229 crc = psa_crc((unsigned char *) &psa,
230 sizeof(psa) - sizeof(psa.psa_crc[0]) - sizeof(psa.psa_crc[1])
231 - sizeof(psa.psa_crc_status));
233 psa.psa_crc[0] = crc & 0xFF;
234 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
237 psa_write(dev, (char *)&psa.psa_crc - (char *)&psa,
238 (unsigned char *)&psa.psa_crc, 2);
240 #ifdef DEBUG_IOCTL_INFO
241 printk (KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
242 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
244 /* Check again (luxury !) */
245 crc = psa_crc((unsigned char *) &psa,
246 sizeof(psa) - sizeof(psa.psa_crc_status));
249 printk(KERN_WARNING "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", dev->name);
250 #endif /* DEBUG_IOCTL_INFO */
251 #endif /* SET_PSA_CRC */
252 } /* update_psa_checksum */
254 /*------------------------------------------------------------------*/
256 * Write 1 byte to the MMC.
265 /* Wait for MMC to go idle */
266 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
269 outb((u_char)((o << 1) | MMR_MMI_WR), MMR(base));
273 /*------------------------------------------------------------------*/
275 * Routine to write bytes to the Modem Management Controller.
276 * We start by the end because it is the way it should be !
279 mmc_write(u_long base,
288 mmc_out(base, --o, *(--b));
291 /*------------------------------------------------------------------*/
293 * Read 1 byte from the MMC.
294 * Optimised version for 1 byte, avoid using memory...
302 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
304 outb(o << 1, MMR(base)); /* Set the read address */
306 outb(0, MMD(base)); /* Required dummy write */
308 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
310 return (u_char) (inb(MMD(base))); /* Now do the actual read */
313 /*------------------------------------------------------------------*/
315 * Routine to read bytes from the Modem Management Controller.
316 * The implementation is complicated by a lack of address lines,
317 * which prevents decoding of the low-order bit.
318 * (code has just been moved in the above function)
319 * We start by the end because it is the way it should be !
322 mmc_read(u_long base,
331 *(--b) = mmc_in(base, --o);
334 /*------------------------------------------------------------------*/
336 * Get the type of encryption available...
339 mmc_encr(u_long base) /* i/o port of the card */
343 temp = mmc_in(base, mmroff(0, mmr_des_avail));
344 if((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
350 /*------------------------------------------------------------------*/
352 * Wait for the frequency EEprom to complete a command...
355 fee_wait(u_long base, /* i/o port of the card */
356 int delay, /* Base delay to wait for */
357 int number) /* Number of time to wait */
359 int count = 0; /* Wait only a limited time */
361 while((count++ < number) &&
362 (mmc_in(base, mmroff(0, mmr_fee_status)) & MMR_FEE_STATUS_BUSY))
366 /*------------------------------------------------------------------*/
368 * Read bytes from the Frequency EEprom (frequency select cards).
371 fee_read(u_long base, /* i/o port of the card */
372 u_short o, /* destination offset */
373 u_short * b, /* data buffer */
374 int n) /* number of registers */
376 b += n; /* Position at the end of the area */
378 /* Write the address */
379 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
381 /* Loop on all buffer */
384 /* Write the read command */
385 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_READ);
387 /* Wait until EEprom is ready (should be quick !) */
388 fee_wait(base, 10, 100);
391 *--b = ((mmc_in(base, mmroff(0, mmr_fee_data_h)) << 8) |
392 mmc_in(base, mmroff(0, mmr_fee_data_l)));
397 /*------------------------------------------------------------------*/
399 * Write bytes from the Frequency EEprom (frequency select cards).
400 * This is a bit complicated, because the frequency eeprom has to
401 * be unprotected and the write enabled.
405 fee_write(u_long base, /* i/o port of the card */
406 u_short o, /* destination offset */
407 u_short * b, /* data buffer */
408 int n) /* number of registers */
410 b += n; /* Position at the end of the area */
412 #ifdef EEPROM_IS_PROTECTED /* disabled */
413 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
414 /* Ask to read the protected register */
415 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
417 fee_wait(base, 10, 100);
419 /* Read the protected register */
420 printk("Protected 2 : %02X-%02X\n",
421 mmc_in(base, mmroff(0, mmr_fee_data_h)),
422 mmc_in(base, mmroff(0, mmr_fee_data_l)));
423 #endif /* DOESNT_SEEM_TO_WORK */
425 /* Enable protected register */
426 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
427 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
429 fee_wait(base, 10, 100);
432 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n);
433 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
434 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
436 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
437 #endif /* DOESNT_SEEM_TO_WORK */
439 fee_wait(base, 10, 100);
440 #endif /* EEPROM_IS_PROTECTED */
443 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
444 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
446 fee_wait(base, 10, 100);
448 /* Write the EEprom address */
449 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
451 /* Loop on all buffer */
454 /* Write the value */
455 mmc_out(base, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
456 mmc_out(base, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
458 /* Write the write command */
459 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WRITE);
461 /* Wavelan doc says : wait at least 10 ms for EEBUSY = 0 */
463 fee_wait(base, 10, 100);
467 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
468 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
470 fee_wait(base, 10, 100);
472 #ifdef EEPROM_IS_PROTECTED /* disabled */
473 /* Reprotect EEprom */
474 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x00);
475 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
477 fee_wait(base, 10, 100);
478 #endif /* EEPROM_IS_PROTECTED */
481 /******************* WaveLAN Roaming routines... ********************/
483 #ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */
485 static unsigned char WAVELAN_BEACON_ADDRESS[] = {0x09,0x00,0x0e,0x20,0x03,0x00};
487 static void wv_roam_init(struct net_device *dev)
489 net_local *lp= netdev_priv(dev);
491 /* Do not remove this unless you have a good reason */
492 printk(KERN_NOTICE "%s: Warning, you have enabled roaming on"
493 " device %s !\n", dev->name, dev->name);
494 printk(KERN_NOTICE "Roaming is currently an experimental unsupported feature"
495 " of the Wavelan driver.\n");
496 printk(KERN_NOTICE "It may work, but may also make the driver behave in"
497 " erratic ways or crash.\n");
499 lp->wavepoint_table.head=NULL; /* Initialise WavePoint table */
500 lp->wavepoint_table.num_wavepoints=0;
501 lp->wavepoint_table.locked=0;
502 lp->curr_point=NULL; /* No default WavePoint */
505 lp->cell_timer.data=(long)lp; /* Start cell expiry timer */
506 lp->cell_timer.function=wl_cell_expiry;
507 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
508 add_timer(&lp->cell_timer);
510 wv_nwid_filter(NWID_PROMISC,lp) ; /* Enter NWID promiscuous mode */
511 /* to build up a good WavePoint */
513 printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name);
516 static void wv_roam_cleanup(struct net_device *dev)
518 wavepoint_history *ptr,*old_ptr;
519 net_local *lp= netdev_priv(dev);
521 printk(KERN_DEBUG "WaveLAN: Roaming Disabled on device %s\n",dev->name);
523 /* Fixme : maybe we should check that the timer exist before deleting it */
524 del_timer(&lp->cell_timer); /* Remove cell expiry timer */
525 ptr=lp->wavepoint_table.head; /* Clear device's WavePoint table */
530 wl_del_wavepoint(old_ptr,lp);
534 /* Enable/Disable NWID promiscuous mode on a given device */
535 static void wv_nwid_filter(unsigned char mode, net_local *lp)
540 #ifdef WAVELAN_ROAMING_DEBUG
541 printk(KERN_DEBUG "WaveLAN: NWID promisc %s, device %s\n",(mode==NWID_PROMISC) ? "on" : "off", lp->dev->name);
544 /* Disable interrupts & save flags */
545 spin_lock_irqsave(&lp->spinlock, flags);
547 m.w.mmw_loopt_sel = (mode==NWID_PROMISC) ? MMW_LOOPT_SEL_DIS_NWID : 0x00;
548 mmc_write(lp->dev->base_addr, (char *)&m.w.mmw_loopt_sel - (char *)&m, (unsigned char *)&m.w.mmw_loopt_sel, 1);
550 if(mode==NWID_PROMISC)
555 /* ReEnable interrupts & restore flags */
556 spin_unlock_irqrestore(&lp->spinlock, flags);
559 /* Find a record in the WavePoint table matching a given NWID */
560 static wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp)
562 wavepoint_history *ptr=lp->wavepoint_table.head;
572 /* Create a new wavepoint table entry */
573 static wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp)
575 wavepoint_history *new_wavepoint;
577 #ifdef WAVELAN_ROAMING_DEBUG
578 printk(KERN_DEBUG "WaveLAN: New Wavepoint, NWID:%.4X\n",nwid);
581 if(lp->wavepoint_table.num_wavepoints==MAX_WAVEPOINTS)
584 new_wavepoint = kmalloc(sizeof(wavepoint_history),GFP_ATOMIC);
585 if(new_wavepoint==NULL)
588 new_wavepoint->nwid=nwid; /* New WavePoints NWID */
589 new_wavepoint->average_fast=0; /* Running Averages..*/
590 new_wavepoint->average_slow=0;
591 new_wavepoint->qualptr=0; /* Start of ringbuffer */
592 new_wavepoint->last_seq=seq-1; /* Last sequence no.seen */
593 memset(new_wavepoint->sigqual,0,WAVEPOINT_HISTORY);/* Empty ringbuffer */
595 new_wavepoint->next=lp->wavepoint_table.head;/* Add to wavepoint table */
596 new_wavepoint->prev=NULL;
598 if(lp->wavepoint_table.head!=NULL)
599 lp->wavepoint_table.head->prev=new_wavepoint;
601 lp->wavepoint_table.head=new_wavepoint;
603 lp->wavepoint_table.num_wavepoints++; /* no. of visible wavepoints */
605 return new_wavepoint;
608 /* Remove a wavepoint entry from WavePoint table */
609 static void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp)
614 if(lp->curr_point==wavepoint)
617 if(wavepoint->prev!=NULL)
618 wavepoint->prev->next=wavepoint->next;
620 if(wavepoint->next!=NULL)
621 wavepoint->next->prev=wavepoint->prev;
623 if(lp->wavepoint_table.head==wavepoint)
624 lp->wavepoint_table.head=wavepoint->next;
626 lp->wavepoint_table.num_wavepoints--;
630 /* Timer callback function - checks WavePoint table for stale entries */
631 static void wl_cell_expiry(unsigned long data)
633 net_local *lp=(net_local *)data;
634 wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point;
636 #if WAVELAN_ROAMING_DEBUG > 1
637 printk(KERN_DEBUG "WaveLAN: Wavepoint timeout, dev %s\n",lp->dev->name);
640 if(lp->wavepoint_table.locked)
642 #if WAVELAN_ROAMING_DEBUG > 1
643 printk(KERN_DEBUG "WaveLAN: Wavepoint table locked...\n");
646 lp->cell_timer.expires=jiffies+1; /* If table in use, come back later */
647 add_timer(&lp->cell_timer);
651 while(wavepoint!=NULL)
653 if(time_after(jiffies, wavepoint->last_seen + CELL_TIMEOUT))
655 #ifdef WAVELAN_ROAMING_DEBUG
656 printk(KERN_DEBUG "WaveLAN: Bye bye %.4X\n",wavepoint->nwid);
660 wavepoint=wavepoint->next;
661 wl_del_wavepoint(old_point,lp);
664 wavepoint=wavepoint->next;
666 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
667 add_timer(&lp->cell_timer);
670 /* Update SNR history of a wavepoint */
671 static void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq)
673 int i=0,num_missed=0,ptr=0;
674 int average_fast=0,average_slow=0;
676 num_missed=(seq-wavepoint->last_seq)%WAVEPOINT_HISTORY;/* Have we missed
679 for(i=0;i<num_missed;i++)
681 wavepoint->sigqual[wavepoint->qualptr++]=0; /* If so, enter them as 0's */
682 wavepoint->qualptr %=WAVEPOINT_HISTORY; /* in the ringbuffer. */
684 wavepoint->last_seen=jiffies; /* Add beacon to history */
685 wavepoint->last_seq=seq;
686 wavepoint->sigqual[wavepoint->qualptr++]=sigqual;
687 wavepoint->qualptr %=WAVEPOINT_HISTORY;
688 ptr=(wavepoint->qualptr-WAVEPOINT_FAST_HISTORY+WAVEPOINT_HISTORY)%WAVEPOINT_HISTORY;
690 for(i=0;i<WAVEPOINT_FAST_HISTORY;i++) /* Update running averages */
692 average_fast+=wavepoint->sigqual[ptr++];
693 ptr %=WAVEPOINT_HISTORY;
696 average_slow=average_fast;
697 for(i=WAVEPOINT_FAST_HISTORY;i<WAVEPOINT_HISTORY;i++)
699 average_slow+=wavepoint->sigqual[ptr++];
700 ptr %=WAVEPOINT_HISTORY;
703 wavepoint->average_fast=average_fast/WAVEPOINT_FAST_HISTORY;
704 wavepoint->average_slow=average_slow/WAVEPOINT_HISTORY;
707 /* Perform a handover to a new WavePoint */
708 static void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp)
710 unsigned int base = lp->dev->base_addr;
714 if(wavepoint==lp->curr_point) /* Sanity check... */
716 wv_nwid_filter(!NWID_PROMISC,lp);
720 #ifdef WAVELAN_ROAMING_DEBUG
721 printk(KERN_DEBUG "WaveLAN: Doing handover to %.4X, dev %s\n",wavepoint->nwid,lp->dev->name);
724 /* Disable interrupts & save flags */
725 spin_lock_irqsave(&lp->spinlock, flags);
727 m.w.mmw_netw_id_l = wavepoint->nwid & 0xFF;
728 m.w.mmw_netw_id_h = (wavepoint->nwid & 0xFF00) >> 8;
730 mmc_write(base, (char *)&m.w.mmw_netw_id_l - (char *)&m, (unsigned char *)&m.w.mmw_netw_id_l, 2);
732 /* ReEnable interrupts & restore flags */
733 spin_unlock_irqrestore(&lp->spinlock, flags);
735 wv_nwid_filter(!NWID_PROMISC,lp);
736 lp->curr_point=wavepoint;
739 /* Called when a WavePoint beacon is received */
740 static void wl_roam_gather(struct net_device * dev,
741 u_char * hdr, /* Beacon header */
742 u_char * stats) /* SNR, Signal quality
745 wavepoint_beacon *beacon= (wavepoint_beacon *)hdr; /* Rcvd. Beacon */
746 unsigned short nwid=ntohs(beacon->nwid);
747 unsigned short sigqual=stats[2] & MMR_SGNL_QUAL; /* SNR of beacon */
748 wavepoint_history *wavepoint=NULL; /* WavePoint table entry */
749 net_local *lp = netdev_priv(dev); /* Device info */
751 #ifdef I_NEED_THIS_FEATURE
752 /* Some people don't need this, some other may need it */
753 nwid=nwid^ntohs(beacon->domain_id);
756 #if WAVELAN_ROAMING_DEBUG > 1
757 printk(KERN_DEBUG "WaveLAN: beacon, dev %s:\n",dev->name);
758 printk(KERN_DEBUG "Domain: %.4X NWID: %.4X SigQual=%d\n",ntohs(beacon->domain_id),nwid,sigqual);
761 lp->wavepoint_table.locked=1; /* <Mutex> */
763 wavepoint=wl_roam_check(nwid,lp); /* Find WavePoint table entry */
764 if(wavepoint==NULL) /* If no entry, Create a new one... */
766 wavepoint=wl_new_wavepoint(nwid,beacon->seq,lp);
770 if(lp->curr_point==NULL) /* If this is the only WavePoint, */
771 wv_roam_handover(wavepoint, lp); /* Jump on it! */
773 wl_update_history(wavepoint, sigqual, beacon->seq); /* Update SNR history
776 if(lp->curr_point->average_slow < SEARCH_THRESH_LOW) /* If our current */
777 if(!lp->cell_search) /* WavePoint is getting faint, */
778 wv_nwid_filter(NWID_PROMISC,lp); /* start looking for a new one */
780 if(wavepoint->average_slow >
781 lp->curr_point->average_slow + WAVELAN_ROAMING_DELTA)
782 wv_roam_handover(wavepoint, lp); /* Handover to a better WavePoint */
784 if(lp->curr_point->average_slow > SEARCH_THRESH_HIGH) /* If our SNR is */
785 if(lp->cell_search) /* getting better, drop out of cell search mode */
786 wv_nwid_filter(!NWID_PROMISC,lp);
789 lp->wavepoint_table.locked=0; /* </MUTEX> :-) */
792 /* Test this MAC frame a WavePoint beacon */
793 static inline int WAVELAN_BEACON(unsigned char *data)
795 wavepoint_beacon *beacon= (wavepoint_beacon *)data;
796 static const wavepoint_beacon beacon_template={0xaa,0xaa,0x03,0x08,0x00,0x0e,0x20,0x03,0x00};
798 if(memcmp(beacon,&beacon_template,9)==0)
803 #endif /* WAVELAN_ROAMING */
805 /************************ I82593 SUBROUTINES *************************/
807 * Useful subroutines to manage the Ethernet controller
810 /*------------------------------------------------------------------*/
812 * Routine to synchronously send a command to the i82593 chip.
813 * Should be called with interrupts disabled.
814 * (called by wv_packet_write(), wv_ru_stop(), wv_ru_start(),
815 * wv_82593_config() & wv_diag())
818 wv_82593_cmd(struct net_device * dev,
823 unsigned int base = dev->base_addr;
828 /* Spin until the chip finishes executing its current command (if any) */
832 /* Time calibration of the loop */
835 /* Read the interrupt register */
836 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
837 status = inb(LCSR(base));
839 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
841 /* If the interrupt hasn't be posted */
844 #ifdef DEBUG_INTERRUPT_ERROR
845 printk(KERN_INFO "wv_82593_cmd: %s timeout (previous command), status 0x%02x\n",
851 /* Issue the command to the controller */
852 outb(cmd, LCCR(base));
854 /* If we don't have to check the result of the command
855 * Note : this mean that the irq handler will deal with that */
856 if(result == SR0_NO_RESULT)
859 /* We are waiting for command completion */
860 wait_completed = TRUE;
862 /* Busy wait while the LAN controller executes the command. */
866 /* Time calibration of the loop */
869 /* Read the interrupt register */
870 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
871 status = inb(LCSR(base));
873 /* Check if there was an interrupt posted */
874 if((status & SR0_INTERRUPT))
876 /* Acknowledge the interrupt */
877 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
879 /* Check if interrupt is a command completion */
880 if(((status & SR0_BOTH_RX_TX) != SR0_BOTH_RX_TX) &&
881 ((status & SR0_BOTH_RX_TX) != 0x0) &&
882 !(status & SR0_RECEPTION))
884 /* Signal command completion */
885 wait_completed = FALSE;
889 /* Note : Rx interrupts will be handled later, because we can
890 * handle multiple Rx packets at once */
891 #ifdef DEBUG_INTERRUPT_INFO
892 printk(KERN_INFO "wv_82593_cmd: not our interrupt\n");
897 while(wait_completed && (spin-- > 0));
899 /* If the interrupt hasn't be posted */
902 #ifdef DEBUG_INTERRUPT_ERROR
903 printk(KERN_INFO "wv_82593_cmd: %s timeout, status 0x%02x\n",
909 /* Check the return code returned by the card (see above) against
910 * the expected return code provided by the caller */
911 if((status & SR0_EVENT_MASK) != result)
913 #ifdef DEBUG_INTERRUPT_ERROR
914 printk(KERN_INFO "wv_82593_cmd: %s failed, status = 0x%x\n",
923 /*------------------------------------------------------------------*/
925 * This routine does a 593 op-code number 7, and obtains the diagnose
926 * status for the WaveLAN.
929 wv_diag(struct net_device * dev)
931 return(wv_82593_cmd(dev, "wv_diag(): diagnose",
932 OP0_DIAGNOSE, SR0_DIAGNOSE_PASSED));
935 /*------------------------------------------------------------------*/
937 * Routine to read len bytes from the i82593's ring buffer, starting at
938 * chip address addr. The results read from the chip are stored in buf.
939 * The return value is the address to use for next the call.
942 read_ringbuf(struct net_device * dev,
947 unsigned int base = dev->base_addr;
950 char * buf_ptr = buf;
952 /* Get all the buffer */
955 /* Position the Program I/O Register at the ring buffer pointer */
956 outb(ring_ptr & 0xff, PIORL(base));
957 outb(((ring_ptr >> 8) & PIORH_MASK), PIORH(base));
959 /* First, determine how much we can read without wrapping around the
961 if((addr + len) < (RX_BASE + RX_SIZE))
964 chunk_len = RX_BASE + RX_SIZE - addr;
965 insb(PIOP(base), buf_ptr, chunk_len);
966 buf_ptr += chunk_len;
968 ring_ptr = (ring_ptr - RX_BASE + chunk_len) % RX_SIZE + RX_BASE;
973 /*------------------------------------------------------------------*/
975 * Reconfigure the i82593, or at least ask for it...
976 * Because wv_82593_config use the transmission buffer, we must do it
977 * when we are sure that there is no transmission, so we do it now
978 * or in wavelan_packet_xmit() (I can't find any better place,
979 * wavelan_interrupt is not an option...), so you may experience
980 * some delay sometime...
983 wv_82593_reconfig(struct net_device * dev)
985 net_local * lp = netdev_priv(dev);
986 struct pcmcia_device * link = lp->link;
989 /* Arm the flag, will be cleard in wv_82593_config() */
990 lp->reconfig_82593 = TRUE;
992 /* Check if we can do it now ! */
993 if((link->open) && (netif_running(dev)) && !(netif_queue_stopped(dev)))
995 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
996 wv_82593_config(dev);
997 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
1001 #ifdef DEBUG_IOCTL_INFO
1003 "%s: wv_82593_reconfig(): delayed (state = %lX, link = %d)\n",
1004 dev->name, dev->state, link->open);
1009 /********************* DEBUG & INFO SUBROUTINES *********************/
1011 * This routines are used in the code to show debug informations.
1012 * Most of the time, it dump the content of hardware structures...
1015 #ifdef DEBUG_PSA_SHOW
1016 /*------------------------------------------------------------------*/
1018 * Print the formatted contents of the Parameter Storage Area.
1021 wv_psa_show(psa_t * p)
1023 DECLARE_MAC_BUF(mac);
1024 printk(KERN_DEBUG "##### wavelan psa contents: #####\n");
1025 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
1026 p->psa_io_base_addr_1,
1027 p->psa_io_base_addr_2,
1028 p->psa_io_base_addr_3,
1029 p->psa_io_base_addr_4);
1030 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
1031 p->psa_rem_boot_addr_1,
1032 p->psa_rem_boot_addr_2,
1033 p->psa_rem_boot_addr_3);
1034 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
1035 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
1036 #ifdef DEBUG_SHOW_UNUSED
1037 printk(KERN_DEBUG "psa_unused0[]: %s\n",
1038 print_mac(mac, p->psa_unused0));
1039 #endif /* DEBUG_SHOW_UNUSED */
1040 printk(KERN_DEBUG "psa_univ_mac_addr[]: %s\n",
1041 print_mac(mac, p->psa_univ_mac_addr));
1042 printk(KERN_DEBUG "psa_local_mac_addr[]: %s\n",
1043 print_mac(mac, p->psa_local_mac_addr));
1044 printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel);
1045 printk("psa_comp_number: %d, ", p->psa_comp_number);
1046 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
1047 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
1048 p->psa_feature_select);
1049 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
1050 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
1051 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
1052 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]);
1053 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
1054 printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select);
1055 printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1056 p->psa_encryption_key[0],
1057 p->psa_encryption_key[1],
1058 p->psa_encryption_key[2],
1059 p->psa_encryption_key[3],
1060 p->psa_encryption_key[4],
1061 p->psa_encryption_key[5],
1062 p->psa_encryption_key[6],
1063 p->psa_encryption_key[7]);
1064 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
1065 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
1066 p->psa_call_code[0]);
1067 printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1068 p->psa_call_code[0],
1069 p->psa_call_code[1],
1070 p->psa_call_code[2],
1071 p->psa_call_code[3],
1072 p->psa_call_code[4],
1073 p->psa_call_code[5],
1074 p->psa_call_code[6],
1075 p->psa_call_code[7]);
1076 #ifdef DEBUG_SHOW_UNUSED
1077 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X\n",
1079 p->psa_reserved[1]);
1080 #endif /* DEBUG_SHOW_UNUSED */
1081 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
1082 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
1083 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
1085 #endif /* DEBUG_PSA_SHOW */
1087 #ifdef DEBUG_MMC_SHOW
1088 /*------------------------------------------------------------------*/
1090 * Print the formatted status of the Modem Management Controller.
1091 * This function need to be completed...
1094 wv_mmc_show(struct net_device * dev)
1096 unsigned int base = dev->base_addr;
1097 net_local * lp = netdev_priv(dev);
1101 if(hasr_read(base) & HASR_NO_CLK)
1103 printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n",
1108 spin_lock_irqsave(&lp->spinlock, flags);
1111 mmc_out(base, mmwoff(0, mmw_freeze), 1);
1112 mmc_read(base, 0, (u_char *)&m, sizeof(m));
1113 mmc_out(base, mmwoff(0, mmw_freeze), 0);
1115 /* Don't forget to update statistics */
1116 lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
1118 spin_unlock_irqrestore(&lp->spinlock, flags);
1120 printk(KERN_DEBUG "##### wavelan modem status registers: #####\n");
1121 #ifdef DEBUG_SHOW_UNUSED
1122 printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1131 #endif /* DEBUG_SHOW_UNUSED */
1132 printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
1133 m.mmr_des_avail, m.mmr_des_status);
1134 #ifdef DEBUG_SHOW_UNUSED
1135 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1141 #endif /* DEBUG_SHOW_UNUSED */
1142 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1144 (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"",
1145 (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1146 "loop test indicated," : "",
1147 (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "",
1148 (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1149 "jabber timer expired," : "");
1150 printk(KERN_DEBUG "Dsp ID: %02X\n",
1152 #ifdef DEBUG_SHOW_UNUSED
1153 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1156 #endif /* DEBUG_SHOW_UNUSED */
1157 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1158 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1159 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1160 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1161 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1162 (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below");
1163 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1164 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1165 (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg");
1166 printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL,
1167 (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update");
1168 printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1169 (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0");
1170 #ifdef DEBUG_SHOW_UNUSED
1171 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1172 #endif /* DEBUG_SHOW_UNUSED */
1174 #endif /* DEBUG_MMC_SHOW */
1176 #ifdef DEBUG_I82593_SHOW
1177 /*------------------------------------------------------------------*/
1179 * Print the formatted status of the i82593's receive unit.
1182 wv_ru_show(struct net_device * dev)
1184 net_local *lp = netdev_priv(dev);
1186 printk(KERN_DEBUG "##### wavelan i82593 receiver status: #####\n");
1187 printk(KERN_DEBUG "ru: rfp %d stop %d", lp->rfp, lp->stop);
1189 * Not implemented yet...
1193 #endif /* DEBUG_I82593_SHOW */
1195 #ifdef DEBUG_DEVICE_SHOW
1196 /*------------------------------------------------------------------*/
1198 * Print the formatted status of the WaveLAN PCMCIA device driver.
1201 wv_dev_show(struct net_device * dev)
1203 printk(KERN_DEBUG "dev:");
1204 printk(" state=%lX,", dev->state);
1205 printk(" trans_start=%ld,", dev->trans_start);
1206 printk(" flags=0x%x,", dev->flags);
1210 /*------------------------------------------------------------------*/
1212 * Print the formatted status of the WaveLAN PCMCIA device driver's
1213 * private information.
1216 wv_local_show(struct net_device * dev)
1218 net_local *lp = netdev_priv(dev);
1220 printk(KERN_DEBUG "local:");
1222 * Not implemented yet...
1225 } /* wv_local_show */
1226 #endif /* DEBUG_DEVICE_SHOW */
1228 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1229 /*------------------------------------------------------------------*/
1231 * Dump packet header (and content if necessary) on the screen
1234 wv_packet_info(u_char * p, /* Packet to dump */
1235 int length, /* Length of the packet */
1236 char * msg1, /* Name of the device */
1237 char * msg2) /* Name of the function */
1241 DECLARE_MAC_BUF(mac);
1243 printk(KERN_DEBUG "%s: %s(): dest %s, length %d\n",
1244 msg1, msg2, print_mac(mac, p), length);
1245 printk(KERN_DEBUG "%s: %s(): src %s, type 0x%02X%02X\n",
1246 msg1, msg2, print_mac(mac, &p[6]), p[12], p[13]);
1248 #ifdef DEBUG_PACKET_DUMP
1250 printk(KERN_DEBUG "data=\"");
1252 if((maxi = length) > DEBUG_PACKET_DUMP)
1253 maxi = DEBUG_PACKET_DUMP;
1254 for(i = 14; i < maxi; i++)
1255 if(p[i] >= ' ' && p[i] <= '~')
1256 printk(" %c", p[i]);
1258 printk("%02X", p[i]);
1262 printk(KERN_DEBUG "\n");
1263 #endif /* DEBUG_PACKET_DUMP */
1265 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1267 /*------------------------------------------------------------------*/
1269 * This is the information which is displayed by the driver at startup
1270 * There is a lot of flag to configure it at your will...
1273 wv_init_info(struct net_device * dev)
1275 unsigned int base = dev->base_addr;
1277 DECLARE_MAC_BUF(mac);
1279 /* Read the parameter storage area */
1280 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
1282 #ifdef DEBUG_PSA_SHOW
1285 #ifdef DEBUG_MMC_SHOW
1288 #ifdef DEBUG_I82593_SHOW
1292 #ifdef DEBUG_BASIC_SHOW
1293 /* Now, let's go for the basic stuff */
1294 printk(KERN_NOTICE "%s: WaveLAN: port %#x, irq %d, "
1296 dev->name, base, dev->irq,
1297 print_mac(mac, dev->dev_addr));
1299 /* Print current network id */
1300 if(psa.psa_nwid_select)
1301 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
1303 printk(", nwid off");
1306 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1307 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1309 unsigned short freq;
1311 /* Ask the EEprom to read the frequency from the first area */
1312 fee_read(base, 0x00 /* 1st area - frequency... */,
1315 /* Print frequency */
1316 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1324 printk(", PCMCIA, ");
1325 switch (psa.psa_subband)
1327 case PSA_SUBBAND_915:
1330 case PSA_SUBBAND_2425:
1333 case PSA_SUBBAND_2460:
1336 case PSA_SUBBAND_2484:
1339 case PSA_SUBBAND_2430_5:
1348 #endif /* DEBUG_BASIC_SHOW */
1350 #ifdef DEBUG_VERSION_SHOW
1351 /* Print version information */
1352 printk(KERN_NOTICE "%s", version);
1354 } /* wv_init_info */
1356 /********************* IOCTL, STATS & RECONFIG *********************/
1358 * We found here routines that are called by Linux on differents
1359 * occasions after the configuration and not for transmitting data
1360 * These may be called when the user use ifconfig, /proc/net/dev
1361 * or wireless extensions
1364 /*------------------------------------------------------------------*/
1366 * Get the current ethernet statistics. This may be called with the
1367 * card open or closed.
1368 * Used when the user read /proc/net/dev
1371 wavelan_get_stats(struct net_device * dev)
1373 #ifdef DEBUG_IOCTL_TRACE
1374 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1377 return(&((net_local *)netdev_priv(dev))->stats);
1380 /*------------------------------------------------------------------*/
1382 * Set or clear the multicast filter for this adaptor.
1383 * num_addrs == -1 Promiscuous mode, receive all packets
1384 * num_addrs == 0 Normal mode, clear multicast list
1385 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1386 * and do best-effort filtering.
1390 wavelan_set_multicast_list(struct net_device * dev)
1392 net_local * lp = netdev_priv(dev);
1394 #ifdef DEBUG_IOCTL_TRACE
1395 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
1398 #ifdef DEBUG_IOCTL_INFO
1399 printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1400 dev->name, dev->flags, dev->mc_count);
1403 if(dev->flags & IFF_PROMISC)
1406 * Enable promiscuous mode: receive all packets.
1408 if(!lp->promiscuous)
1410 lp->promiscuous = 1;
1411 lp->allmulticast = 0;
1414 wv_82593_reconfig(dev);
1416 /* Tell the kernel that we are doing a really bad job... */
1417 dev->flags |= IFF_PROMISC;
1421 /* If all multicast addresses
1422 * or too much multicast addresses for the hardware filter */
1423 if((dev->flags & IFF_ALLMULTI) ||
1424 (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
1427 * Disable promiscuous mode, but active the all multicast mode
1429 if(!lp->allmulticast)
1431 lp->promiscuous = 0;
1432 lp->allmulticast = 1;
1435 wv_82593_reconfig(dev);
1437 /* Tell the kernel that we are doing a really bad job... */
1438 dev->flags |= IFF_ALLMULTI;
1442 /* If there is some multicast addresses to send */
1443 if(dev->mc_list != (struct dev_mc_list *) NULL)
1446 * Disable promiscuous mode, but receive all packets
1449 #ifdef MULTICAST_AVOID
1450 if(lp->promiscuous || lp->allmulticast ||
1451 (dev->mc_count != lp->mc_count))
1454 lp->promiscuous = 0;
1455 lp->allmulticast = 0;
1456 lp->mc_count = dev->mc_count;
1458 wv_82593_reconfig(dev);
1464 * Switch to normal mode: disable promiscuous mode and
1465 * clear the multicast list.
1467 if(lp->promiscuous || lp->mc_count == 0)
1469 lp->promiscuous = 0;
1470 lp->allmulticast = 0;
1473 wv_82593_reconfig(dev);
1476 #ifdef DEBUG_IOCTL_TRACE
1477 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
1481 /*------------------------------------------------------------------*/
1483 * This function doesn't exist...
1484 * (Note : it was a nice way to test the reconfigure stuff...)
1486 #ifdef SET_MAC_ADDRESS
1488 wavelan_set_mac_address(struct net_device * dev,
1491 struct sockaddr * mac = addr;
1493 /* Copy the address */
1494 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1496 /* Reconfig the beast */
1497 wv_82593_reconfig(dev);
1501 #endif /* SET_MAC_ADDRESS */
1504 /*------------------------------------------------------------------*/
1506 * Frequency setting (for hardware able of it)
1507 * It's a bit complicated and you don't really want to look into it...
1510 wv_set_frequency(u_long base, /* i/o port of the card */
1511 iw_freq * frequency)
1513 const int BAND_NUM = 10; /* Number of bands */
1514 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1515 #ifdef DEBUG_IOCTL_INFO
1519 /* Setting by frequency */
1520 /* Theoritically, you may set any frequency between
1521 * the two limits with a 0.5 MHz precision. In practice,
1522 * I don't want you to have trouble with local
1524 if((frequency->e == 1) &&
1525 (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
1527 freq = ((frequency->m / 10000) - 24000L) / 5;
1530 /* Setting by channel (same as wfreqsel) */
1531 /* Warning : each channel is 22MHz wide, so some of the channels
1532 * will interfere... */
1533 if((frequency->e == 0) &&
1534 (frequency->m >= 0) && (frequency->m < BAND_NUM))
1536 /* Get frequency offset. */
1537 freq = channel_bands[frequency->m] >> 1;
1540 /* Verify if the frequency is allowed */
1543 u_short table[10]; /* Authorized frequency table */
1545 /* Read the frequency table */
1546 fee_read(base, 0x71 /* frequency table */,
1549 #ifdef DEBUG_IOCTL_INFO
1550 printk(KERN_DEBUG "Frequency table :");
1551 for(i = 0; i < 10; i++)
1559 /* Look in the table if the frequency is allowed */
1560 if(!(table[9 - ((freq - 24) / 16)] &
1561 (1 << ((freq - 24) % 16))))
1562 return -EINVAL; /* not allowed */
1567 /* If we get a usable frequency */
1570 unsigned short area[16];
1571 unsigned short dac[2];
1572 unsigned short area_verify[16];
1573 unsigned short dac_verify[2];
1574 /* Corresponding gain (in the power adjust value table)
1575 * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
1576 * & WCIN062D.DOC, page 6.2.9 */
1577 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1578 int power_band = 0; /* Selected band */
1579 unsigned short power_adjust; /* Correct value */
1581 /* Search for the gain */
1583 while((freq > power_limit[power_band]) &&
1584 (power_limit[++power_band] != 0))
1587 /* Read the first area */
1588 fee_read(base, 0x00,
1592 fee_read(base, 0x60,
1595 /* Read the new power adjust value */
1596 fee_read(base, 0x6B - (power_band >> 1),
1598 if(power_band & 0x1)
1601 power_adjust &= 0xFF;
1603 #ifdef DEBUG_IOCTL_INFO
1604 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1605 for(i = 0; i < 16; i++)
1612 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1616 /* Frequency offset (for info only...) */
1617 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1619 /* Receiver Principle main divider coefficient */
1620 area[3] = (freq >> 1) + 2400L - 352L;
1621 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1623 /* Transmitter Main divider coefficient */
1624 area[13] = (freq >> 1) + 2400L;
1625 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1627 /* Others part of the area are flags, bit streams or unused... */
1629 /* Set the value in the DAC */
1630 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1631 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1633 /* Write the first area */
1634 fee_write(base, 0x00,
1638 fee_write(base, 0x60,
1641 /* We now should verify here that the EEprom writing was ok */
1643 /* ReRead the first area */
1644 fee_read(base, 0x00,
1647 /* ReRead the DAC */
1648 fee_read(base, 0x60,
1652 if(memcmp(area, area_verify, 16 * 2) ||
1653 memcmp(dac, dac_verify, 2 * 2))
1655 #ifdef DEBUG_IOCTL_ERROR
1656 printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
1661 /* We must download the frequency parameters to the
1662 * synthetisers (from the EEprom - area 1)
1663 * Note : as the EEprom is auto decremented, we set the end
1665 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
1666 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1667 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1669 /* Wait until the download is finished */
1670 fee_wait(base, 100, 100);
1672 /* We must now download the power adjust value (gain) to
1673 * the synthetisers (from the EEprom - area 7 - DAC) */
1674 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
1675 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1676 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1678 /* Wait until the download is finished */
1679 fee_wait(base, 100, 100);
1681 #ifdef DEBUG_IOCTL_INFO
1682 /* Verification of what we have done... */
1684 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1685 for(i = 0; i < 16; i++)
1692 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1693 dac_verify[0], dac_verify[1]);
1699 return -EINVAL; /* Bah, never get there... */
1702 /*------------------------------------------------------------------*/
1704 * Give the list of available frequencies
1707 wv_frequency_list(u_long base, /* i/o port of the card */
1708 iw_freq * list, /* List of frequency to fill */
1709 int max) /* Maximum number of frequencies */
1711 u_short table[10]; /* Authorized frequency table */
1712 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1713 int i; /* index in the table */
1714 const int BAND_NUM = 10; /* Number of bands */
1715 int c = 0; /* Channel number */
1717 /* Read the frequency table */
1718 fee_read(base, 0x71 /* frequency table */,
1721 /* Look all frequencies */
1723 for(freq = 0; freq < 150; freq++)
1724 /* Look in the table if the frequency is allowed */
1725 if(table[9 - (freq / 16)] & (1 << (freq % 16)))
1727 /* Compute approximate channel number */
1728 while((((channel_bands[c] >> 1) - 24) < freq) &&
1731 list[i].i = c; /* Set the list index */
1733 /* put in the list */
1734 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1745 #ifdef IW_WIRELESS_SPY
1746 /*------------------------------------------------------------------*/
1748 * Gather wireless spy statistics : for each packet, compare the source
1749 * address with out list, and if match, get the stats...
1750 * Sorry, but this function really need wireless extensions...
1753 wl_spy_gather(struct net_device * dev,
1754 u_char * mac, /* MAC address */
1755 u_char * stats) /* Statistics to gather */
1757 struct iw_quality wstats;
1759 wstats.qual = stats[2] & MMR_SGNL_QUAL;
1760 wstats.level = stats[0] & MMR_SIGNAL_LVL;
1761 wstats.noise = stats[1] & MMR_SILENCE_LVL;
1762 wstats.updated = 0x7;
1764 /* Update spy records */
1765 wireless_spy_update(dev, mac, &wstats);
1767 #endif /* IW_WIRELESS_SPY */
1770 /*------------------------------------------------------------------*/
1772 * This function calculate an histogram on the signal level.
1773 * As the noise is quite constant, it's like doing it on the SNR.
1774 * We have defined a set of interval (lp->his_range), and each time
1775 * the level goes in that interval, we increment the count (lp->his_sum).
1776 * With this histogram you may detect if one wavelan is really weak,
1777 * or you may also calculate the mean and standard deviation of the level...
1780 wl_his_gather(struct net_device * dev,
1781 u_char * stats) /* Statistics to gather */
1783 net_local * lp = netdev_priv(dev);
1784 u_char level = stats[0] & MMR_SIGNAL_LVL;
1787 /* Find the correct interval */
1789 while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
1792 /* Increment interval counter */
1795 #endif /* HISTOGRAM */
1797 static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1799 strncpy(info->driver, "wavelan_cs", sizeof(info->driver)-1);
1802 static const struct ethtool_ops ops = {
1803 .get_drvinfo = wl_get_drvinfo
1806 /*------------------------------------------------------------------*/
1808 * Wireless Handler : get protocol name
1810 static int wavelan_get_name(struct net_device *dev,
1811 struct iw_request_info *info,
1812 union iwreq_data *wrqu,
1815 strcpy(wrqu->name, "WaveLAN");
1819 /*------------------------------------------------------------------*/
1821 * Wireless Handler : set NWID
1823 static int wavelan_set_nwid(struct net_device *dev,
1824 struct iw_request_info *info,
1825 union iwreq_data *wrqu,
1828 unsigned int base = dev->base_addr;
1829 net_local *lp = netdev_priv(dev);
1832 unsigned long flags;
1835 /* Disable interrupts and save flags. */
1836 spin_lock_irqsave(&lp->spinlock, flags);
1838 /* Set NWID in WaveLAN. */
1839 if (!wrqu->nwid.disabled) {
1840 /* Set NWID in psa */
1841 psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
1842 psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
1843 psa.psa_nwid_select = 0x01;
1845 (char *) psa.psa_nwid - (char *) &psa,
1846 (unsigned char *) psa.psa_nwid, 3);
1848 /* Set NWID in mmc. */
1849 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1850 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1852 (char *) &m.w.mmw_netw_id_l -
1854 (unsigned char *) &m.w.mmw_netw_id_l, 2);
1855 mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
1857 /* Disable NWID in the psa. */
1858 psa.psa_nwid_select = 0x00;
1860 (char *) &psa.psa_nwid_select -
1862 (unsigned char *) &psa.psa_nwid_select,
1865 /* Disable NWID in the mmc (no filtering). */
1866 mmc_out(base, mmwoff(0, mmw_loopt_sel),
1867 MMW_LOOPT_SEL_DIS_NWID);
1869 /* update the Wavelan checksum */
1870 update_psa_checksum(dev);
1872 /* Enable interrupts and restore flags. */
1873 spin_unlock_irqrestore(&lp->spinlock, flags);
1878 /*------------------------------------------------------------------*/
1880 * Wireless Handler : get NWID
1882 static int wavelan_get_nwid(struct net_device *dev,
1883 struct iw_request_info *info,
1884 union iwreq_data *wrqu,
1887 net_local *lp = netdev_priv(dev);
1889 unsigned long flags;
1892 /* Disable interrupts and save flags. */
1893 spin_lock_irqsave(&lp->spinlock, flags);
1895 /* Read the NWID. */
1897 (char *) psa.psa_nwid - (char *) &psa,
1898 (unsigned char *) psa.psa_nwid, 3);
1899 wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1900 wrqu->nwid.disabled = !(psa.psa_nwid_select);
1901 wrqu->nwid.fixed = 1; /* Superfluous */
1903 /* Enable interrupts and restore flags. */
1904 spin_unlock_irqrestore(&lp->spinlock, flags);
1909 /*------------------------------------------------------------------*/
1911 * Wireless Handler : set frequency
1913 static int wavelan_set_freq(struct net_device *dev,
1914 struct iw_request_info *info,
1915 union iwreq_data *wrqu,
1918 unsigned int base = dev->base_addr;
1919 net_local *lp = netdev_priv(dev);
1920 unsigned long flags;
1923 /* Disable interrupts and save flags. */
1924 spin_lock_irqsave(&lp->spinlock, flags);
1926 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1927 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1928 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1929 ret = wv_set_frequency(base, &(wrqu->freq));
1933 /* Enable interrupts and restore flags. */
1934 spin_unlock_irqrestore(&lp->spinlock, flags);
1939 /*------------------------------------------------------------------*/
1941 * Wireless Handler : get frequency
1943 static int wavelan_get_freq(struct net_device *dev,
1944 struct iw_request_info *info,
1945 union iwreq_data *wrqu,
1948 unsigned int base = dev->base_addr;
1949 net_local *lp = netdev_priv(dev);
1951 unsigned long flags;
1954 /* Disable interrupts and save flags. */
1955 spin_lock_irqsave(&lp->spinlock, flags);
1957 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
1958 * Does it work for everybody, especially old cards? */
1959 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1960 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1961 unsigned short freq;
1963 /* Ask the EEPROM to read the frequency from the first area. */
1964 fee_read(base, 0x00, &freq, 1);
1965 wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
1969 (char *) &psa.psa_subband - (char *) &psa,
1970 (unsigned char *) &psa.psa_subband, 1);
1972 if (psa.psa_subband <= 4) {
1973 wrqu->freq.m = fixed_bands[psa.psa_subband];
1974 wrqu->freq.e = (psa.psa_subband != 0);
1979 /* Enable interrupts and restore flags. */
1980 spin_unlock_irqrestore(&lp->spinlock, flags);
1985 /*------------------------------------------------------------------*/
1987 * Wireless Handler : set level threshold
1989 static int wavelan_set_sens(struct net_device *dev,
1990 struct iw_request_info *info,
1991 union iwreq_data *wrqu,
1994 unsigned int base = dev->base_addr;
1995 net_local *lp = netdev_priv(dev);
1997 unsigned long flags;
2000 /* Disable interrupts and save flags. */
2001 spin_lock_irqsave(&lp->spinlock, flags);
2003 /* Set the level threshold. */
2004 /* We should complain loudly if wrqu->sens.fixed = 0, because we
2005 * can't set auto mode... */
2006 psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
2008 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2009 (unsigned char *) &psa.psa_thr_pre_set, 1);
2010 /* update the Wavelan checksum */
2011 update_psa_checksum(dev);
2012 mmc_out(base, mmwoff(0, mmw_thr_pre_set),
2013 psa.psa_thr_pre_set);
2015 /* Enable interrupts and restore flags. */
2016 spin_unlock_irqrestore(&lp->spinlock, flags);
2021 /*------------------------------------------------------------------*/
2023 * Wireless Handler : get level threshold
2025 static int wavelan_get_sens(struct net_device *dev,
2026 struct iw_request_info *info,
2027 union iwreq_data *wrqu,
2030 net_local *lp = netdev_priv(dev);
2032 unsigned long flags;
2035 /* Disable interrupts and save flags. */
2036 spin_lock_irqsave(&lp->spinlock, flags);
2038 /* Read the level threshold. */
2040 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2041 (unsigned char *) &psa.psa_thr_pre_set, 1);
2042 wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
2043 wrqu->sens.fixed = 1;
2045 /* Enable interrupts and restore flags. */
2046 spin_unlock_irqrestore(&lp->spinlock, flags);
2051 /*------------------------------------------------------------------*/
2053 * Wireless Handler : set encryption key
2055 static int wavelan_set_encode(struct net_device *dev,
2056 struct iw_request_info *info,
2057 union iwreq_data *wrqu,
2060 unsigned int base = dev->base_addr;
2061 net_local *lp = netdev_priv(dev);
2062 unsigned long flags;
2066 /* Disable interrupts and save flags. */
2067 spin_lock_irqsave(&lp->spinlock, flags);
2069 /* Check if capable of encryption */
2070 if (!mmc_encr(base)) {
2074 /* Check the size of the key */
2075 if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
2080 /* Basic checking... */
2081 if (wrqu->encoding.length == 8) {
2082 /* Copy the key in the driver */
2083 memcpy(psa.psa_encryption_key, extra,
2084 wrqu->encoding.length);
2085 psa.psa_encryption_select = 1;
2088 (char *) &psa.psa_encryption_select -
2090 (unsigned char *) &psa.
2091 psa_encryption_select, 8 + 1);
2093 mmc_out(base, mmwoff(0, mmw_encr_enable),
2094 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2095 mmc_write(base, mmwoff(0, mmw_encr_key),
2096 (unsigned char *) &psa.
2097 psa_encryption_key, 8);
2100 /* disable encryption */
2101 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
2102 psa.psa_encryption_select = 0;
2104 (char *) &psa.psa_encryption_select -
2106 (unsigned char *) &psa.
2107 psa_encryption_select, 1);
2109 mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
2111 /* update the Wavelan checksum */
2112 update_psa_checksum(dev);
2115 /* Enable interrupts and restore flags. */
2116 spin_unlock_irqrestore(&lp->spinlock, flags);
2121 /*------------------------------------------------------------------*/
2123 * Wireless Handler : get encryption key
2125 static int wavelan_get_encode(struct net_device *dev,
2126 struct iw_request_info *info,
2127 union iwreq_data *wrqu,
2130 unsigned int base = dev->base_addr;
2131 net_local *lp = netdev_priv(dev);
2133 unsigned long flags;
2136 /* Disable interrupts and save flags. */
2137 spin_lock_irqsave(&lp->spinlock, flags);
2139 /* Check if encryption is available */
2140 if (!mmc_encr(base)) {
2143 /* Read the encryption key */
2145 (char *) &psa.psa_encryption_select -
2147 (unsigned char *) &psa.
2148 psa_encryption_select, 1 + 8);
2150 /* encryption is enabled ? */
2151 if (psa.psa_encryption_select)
2152 wrqu->encoding.flags = IW_ENCODE_ENABLED;
2154 wrqu->encoding.flags = IW_ENCODE_DISABLED;
2155 wrqu->encoding.flags |= mmc_encr(base);
2157 /* Copy the key to the user buffer */
2158 wrqu->encoding.length = 8;
2159 memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
2162 /* Enable interrupts and restore flags. */
2163 spin_unlock_irqrestore(&lp->spinlock, flags);
2168 #ifdef WAVELAN_ROAMING_EXT
2169 /*------------------------------------------------------------------*/
2171 * Wireless Handler : set ESSID (domain)
2173 static int wavelan_set_essid(struct net_device *dev,
2174 struct iw_request_info *info,
2175 union iwreq_data *wrqu,
2178 net_local *lp = netdev_priv(dev);
2179 unsigned long flags;
2182 /* Disable interrupts and save flags. */
2183 spin_lock_irqsave(&lp->spinlock, flags);
2185 /* Check if disable */
2186 if(wrqu->data.flags == 0)
2187 lp->filter_domains = 0;
2189 char essid[IW_ESSID_MAX_SIZE + 1];
2192 /* Terminate the string */
2193 memcpy(essid, extra, wrqu->data.length);
2194 essid[IW_ESSID_MAX_SIZE] = '\0';
2196 #ifdef DEBUG_IOCTL_INFO
2197 printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
2198 #endif /* DEBUG_IOCTL_INFO */
2200 /* Convert to a number (note : Wavelan specific) */
2201 lp->domain_id = simple_strtoul(essid, &endp, 16);
2202 /* Has it worked ? */
2204 lp->filter_domains = 1;
2206 lp->filter_domains = 0;
2211 /* Enable interrupts and restore flags. */
2212 spin_unlock_irqrestore(&lp->spinlock, flags);
2217 /*------------------------------------------------------------------*/
2219 * Wireless Handler : get ESSID (domain)
2221 static int wavelan_get_essid(struct net_device *dev,
2222 struct iw_request_info *info,
2223 union iwreq_data *wrqu,
2226 net_local *lp = netdev_priv(dev);
2228 /* Is the domain ID active ? */
2229 wrqu->data.flags = lp->filter_domains;
2231 /* Copy Domain ID into a string (Wavelan specific) */
2232 /* Sound crazy, be we can't have a snprintf in the kernel !!! */
2233 sprintf(extra, "%lX", lp->domain_id);
2234 extra[IW_ESSID_MAX_SIZE] = '\0';
2236 /* Set the length */
2237 wrqu->data.length = strlen(extra);
2242 /*------------------------------------------------------------------*/
2244 * Wireless Handler : set AP address
2246 static int wavelan_set_wap(struct net_device *dev,
2247 struct iw_request_info *info,
2248 union iwreq_data *wrqu,
2251 #ifdef DEBUG_IOCTL_INFO
2252 printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
2253 wrqu->ap_addr.sa_data[0],
2254 wrqu->ap_addr.sa_data[1],
2255 wrqu->ap_addr.sa_data[2],
2256 wrqu->ap_addr.sa_data[3],
2257 wrqu->ap_addr.sa_data[4],
2258 wrqu->ap_addr.sa_data[5]);
2259 #endif /* DEBUG_IOCTL_INFO */
2264 /*------------------------------------------------------------------*/
2266 * Wireless Handler : get AP address
2268 static int wavelan_get_wap(struct net_device *dev,
2269 struct iw_request_info *info,
2270 union iwreq_data *wrqu,
2273 /* Should get the real McCoy instead of own Ethernet address */
2274 memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
2275 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
2279 #endif /* WAVELAN_ROAMING_EXT */
2281 #ifdef WAVELAN_ROAMING
2282 /*------------------------------------------------------------------*/
2284 * Wireless Handler : set mode
2286 static int wavelan_set_mode(struct net_device *dev,
2287 struct iw_request_info *info,
2288 union iwreq_data *wrqu,
2291 net_local *lp = netdev_priv(dev);
2292 unsigned long flags;
2295 /* Disable interrupts and save flags. */
2296 spin_lock_irqsave(&lp->spinlock, flags);
2299 switch(wrqu->mode) {
2302 wv_roam_cleanup(dev);
2316 /* Enable interrupts and restore flags. */
2317 spin_unlock_irqrestore(&lp->spinlock, flags);
2322 /*------------------------------------------------------------------*/
2324 * Wireless Handler : get mode
2326 static int wavelan_get_mode(struct net_device *dev,
2327 struct iw_request_info *info,
2328 union iwreq_data *wrqu,
2332 wrqu->mode = IW_MODE_INFRA;
2334 wrqu->mode = IW_MODE_ADHOC;
2338 #endif /* WAVELAN_ROAMING */
2340 /*------------------------------------------------------------------*/
2342 * Wireless Handler : get range info
2344 static int wavelan_get_range(struct net_device *dev,
2345 struct iw_request_info *info,
2346 union iwreq_data *wrqu,
2349 unsigned int base = dev->base_addr;
2350 net_local *lp = netdev_priv(dev);
2351 struct iw_range *range = (struct iw_range *) extra;
2352 unsigned long flags;
2355 /* Set the length (very important for backward compatibility) */
2356 wrqu->data.length = sizeof(struct iw_range);
2358 /* Set all the info we don't care or don't know about to zero */
2359 memset(range, 0, sizeof(struct iw_range));
2361 /* Set the Wireless Extension versions */
2362 range->we_version_compiled = WIRELESS_EXT;
2363 range->we_version_source = 9;
2365 /* Set information in the range struct. */
2366 range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
2367 range->min_nwid = 0x0000;
2368 range->max_nwid = 0xFFFF;
2370 range->sensitivity = 0x3F;
2371 range->max_qual.qual = MMR_SGNL_QUAL;
2372 range->max_qual.level = MMR_SIGNAL_LVL;
2373 range->max_qual.noise = MMR_SILENCE_LVL;
2374 range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
2375 /* Need to get better values for those two */
2376 range->avg_qual.level = 30;
2377 range->avg_qual.noise = 8;
2379 range->num_bitrates = 1;
2380 range->bitrate[0] = 2000000; /* 2 Mb/s */
2382 /* Event capability (kernel + driver) */
2383 range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
2384 IW_EVENT_CAPA_MASK(0x8B04) |
2385 IW_EVENT_CAPA_MASK(0x8B06));
2386 range->event_capa[1] = IW_EVENT_CAPA_K_1;
2388 /* Disable interrupts and save flags. */
2389 spin_lock_irqsave(&lp->spinlock, flags);
2391 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2392 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2393 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2394 range->num_channels = 10;
2395 range->num_frequency = wv_frequency_list(base, range->freq,
2396 IW_MAX_FREQUENCIES);
2398 range->num_channels = range->num_frequency = 0;
2400 /* Encryption supported ? */
2401 if (mmc_encr(base)) {
2402 range->encoding_size[0] = 8; /* DES = 64 bits key */
2403 range->num_encoding_sizes = 1;
2404 range->max_encoding_tokens = 1; /* Only one key possible */
2406 range->num_encoding_sizes = 0;
2407 range->max_encoding_tokens = 0;
2410 /* Enable interrupts and restore flags. */
2411 spin_unlock_irqrestore(&lp->spinlock, flags);
2416 /*------------------------------------------------------------------*/
2418 * Wireless Private Handler : set quality threshold
2420 static int wavelan_set_qthr(struct net_device *dev,
2421 struct iw_request_info *info,
2422 union iwreq_data *wrqu,
2425 unsigned int base = dev->base_addr;
2426 net_local *lp = netdev_priv(dev);
2428 unsigned long flags;
2430 /* Disable interrupts and save flags. */
2431 spin_lock_irqsave(&lp->spinlock, flags);
2433 psa.psa_quality_thr = *(extra) & 0x0F;
2435 (char *) &psa.psa_quality_thr - (char *) &psa,
2436 (unsigned char *) &psa.psa_quality_thr, 1);
2437 /* update the Wavelan checksum */
2438 update_psa_checksum(dev);
2439 mmc_out(base, mmwoff(0, mmw_quality_thr),
2440 psa.psa_quality_thr);
2442 /* Enable interrupts and restore flags. */
2443 spin_unlock_irqrestore(&lp->spinlock, flags);
2448 /*------------------------------------------------------------------*/
2450 * Wireless Private Handler : get quality threshold
2452 static int wavelan_get_qthr(struct net_device *dev,
2453 struct iw_request_info *info,
2454 union iwreq_data *wrqu,
2457 net_local *lp = netdev_priv(dev);
2459 unsigned long flags;
2461 /* Disable interrupts and save flags. */
2462 spin_lock_irqsave(&lp->spinlock, flags);
2465 (char *) &psa.psa_quality_thr - (char *) &psa,
2466 (unsigned char *) &psa.psa_quality_thr, 1);
2467 *(extra) = psa.psa_quality_thr & 0x0F;
2469 /* Enable interrupts and restore flags. */
2470 spin_unlock_irqrestore(&lp->spinlock, flags);
2475 #ifdef WAVELAN_ROAMING
2476 /*------------------------------------------------------------------*/
2478 * Wireless Private Handler : set roaming
2480 static int wavelan_set_roam(struct net_device *dev,
2481 struct iw_request_info *info,
2482 union iwreq_data *wrqu,
2485 net_local *lp = netdev_priv(dev);
2486 unsigned long flags;
2488 /* Disable interrupts and save flags. */
2489 spin_lock_irqsave(&lp->spinlock, flags);
2491 /* Note : should check if user == root */
2492 if(do_roaming && (*extra)==0)
2493 wv_roam_cleanup(dev);
2494 else if(do_roaming==0 && (*extra)!=0)
2497 do_roaming = (*extra);
2499 /* Enable interrupts and restore flags. */
2500 spin_unlock_irqrestore(&lp->spinlock, flags);
2505 /*------------------------------------------------------------------*/
2507 * Wireless Private Handler : get quality threshold
2509 static int wavelan_get_roam(struct net_device *dev,
2510 struct iw_request_info *info,
2511 union iwreq_data *wrqu,
2514 *(extra) = do_roaming;
2518 #endif /* WAVELAN_ROAMING */
2521 /*------------------------------------------------------------------*/
2523 * Wireless Private Handler : set histogram
2525 static int wavelan_set_histo(struct net_device *dev,
2526 struct iw_request_info *info,
2527 union iwreq_data *wrqu,
2530 net_local *lp = netdev_priv(dev);
2532 /* Check the number of intervals. */
2533 if (wrqu->data.length > 16) {
2537 /* Disable histo while we copy the addresses.
2538 * As we don't disable interrupts, we need to do this */
2541 /* Are there ranges to copy? */
2542 if (wrqu->data.length > 0) {
2543 /* Copy interval ranges to the driver */
2544 memcpy(lp->his_range, extra, wrqu->data.length);
2548 printk(KERN_DEBUG "Histo :");
2549 for(i = 0; i < wrqu->data.length; i++)
2550 printk(" %d", lp->his_range[i]);
2554 /* Reset result structure. */
2555 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2558 /* Now we can set the number of ranges */
2559 lp->his_number = wrqu->data.length;
2564 /*------------------------------------------------------------------*/
2566 * Wireless Private Handler : get histogram
2568 static int wavelan_get_histo(struct net_device *dev,
2569 struct iw_request_info *info,
2570 union iwreq_data *wrqu,
2573 net_local *lp = netdev_priv(dev);
2575 /* Set the number of intervals. */
2576 wrqu->data.length = lp->his_number;
2578 /* Give back the distribution statistics */
2579 if(lp->his_number > 0)
2580 memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
2584 #endif /* HISTOGRAM */
2586 /*------------------------------------------------------------------*/
2588 * Structures to export the Wireless Handlers
2591 static const struct iw_priv_args wavelan_private_args[] = {
2592 /*{ cmd, set_args, get_args, name } */
2593 { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2594 { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2595 { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" },
2596 { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
2597 { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
2598 { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
2601 static const iw_handler wavelan_handler[] =
2603 NULL, /* SIOCSIWNAME */
2604 wavelan_get_name, /* SIOCGIWNAME */
2605 wavelan_set_nwid, /* SIOCSIWNWID */
2606 wavelan_get_nwid, /* SIOCGIWNWID */
2607 wavelan_set_freq, /* SIOCSIWFREQ */
2608 wavelan_get_freq, /* SIOCGIWFREQ */
2609 #ifdef WAVELAN_ROAMING
2610 wavelan_set_mode, /* SIOCSIWMODE */
2611 wavelan_get_mode, /* SIOCGIWMODE */
2612 #else /* WAVELAN_ROAMING */
2613 NULL, /* SIOCSIWMODE */
2614 NULL, /* SIOCGIWMODE */
2615 #endif /* WAVELAN_ROAMING */
2616 wavelan_set_sens, /* SIOCSIWSENS */
2617 wavelan_get_sens, /* SIOCGIWSENS */
2618 NULL, /* SIOCSIWRANGE */
2619 wavelan_get_range, /* SIOCGIWRANGE */
2620 NULL, /* SIOCSIWPRIV */
2621 NULL, /* SIOCGIWPRIV */
2622 NULL, /* SIOCSIWSTATS */
2623 NULL, /* SIOCGIWSTATS */
2624 iw_handler_set_spy, /* SIOCSIWSPY */
2625 iw_handler_get_spy, /* SIOCGIWSPY */
2626 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2627 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2628 #ifdef WAVELAN_ROAMING_EXT
2629 wavelan_set_wap, /* SIOCSIWAP */
2630 wavelan_get_wap, /* SIOCGIWAP */
2631 NULL, /* -- hole -- */
2632 NULL, /* SIOCGIWAPLIST */
2633 NULL, /* -- hole -- */
2634 NULL, /* -- hole -- */
2635 wavelan_set_essid, /* SIOCSIWESSID */
2636 wavelan_get_essid, /* SIOCGIWESSID */
2637 #else /* WAVELAN_ROAMING_EXT */
2638 NULL, /* SIOCSIWAP */
2639 NULL, /* SIOCGIWAP */
2640 NULL, /* -- hole -- */
2641 NULL, /* SIOCGIWAPLIST */
2642 NULL, /* -- hole -- */
2643 NULL, /* -- hole -- */
2644 NULL, /* SIOCSIWESSID */
2645 NULL, /* SIOCGIWESSID */
2646 #endif /* WAVELAN_ROAMING_EXT */
2647 NULL, /* SIOCSIWNICKN */
2648 NULL, /* SIOCGIWNICKN */
2649 NULL, /* -- hole -- */
2650 NULL, /* -- hole -- */
2651 NULL, /* SIOCSIWRATE */
2652 NULL, /* SIOCGIWRATE */
2653 NULL, /* SIOCSIWRTS */
2654 NULL, /* SIOCGIWRTS */
2655 NULL, /* SIOCSIWFRAG */
2656 NULL, /* SIOCGIWFRAG */
2657 NULL, /* SIOCSIWTXPOW */
2658 NULL, /* SIOCGIWTXPOW */
2659 NULL, /* SIOCSIWRETRY */
2660 NULL, /* SIOCGIWRETRY */
2661 wavelan_set_encode, /* SIOCSIWENCODE */
2662 wavelan_get_encode, /* SIOCGIWENCODE */
2665 static const iw_handler wavelan_private_handler[] =
2667 wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
2668 wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
2669 #ifdef WAVELAN_ROAMING
2670 wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */
2671 wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */
2672 #else /* WAVELAN_ROAMING */
2673 NULL, /* SIOCIWFIRSTPRIV + 2 */
2674 NULL, /* SIOCIWFIRSTPRIV + 3 */
2675 #endif /* WAVELAN_ROAMING */
2677 wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */
2678 wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */
2679 #endif /* HISTOGRAM */
2682 static const struct iw_handler_def wavelan_handler_def =
2684 .num_standard = ARRAY_SIZE(wavelan_handler),
2685 .num_private = ARRAY_SIZE(wavelan_private_handler),
2686 .num_private_args = ARRAY_SIZE(wavelan_private_args),
2687 .standard = wavelan_handler,
2688 .private = wavelan_private_handler,
2689 .private_args = wavelan_private_args,
2690 .get_wireless_stats = wavelan_get_wireless_stats,
2693 /*------------------------------------------------------------------*/
2695 * Get wireless statistics
2696 * Called by /proc/net/wireless...
2699 wavelan_get_wireless_stats(struct net_device * dev)
2701 unsigned int base = dev->base_addr;
2702 net_local * lp = netdev_priv(dev);
2705 unsigned long flags;
2707 #ifdef DEBUG_IOCTL_TRACE
2708 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
2711 /* Disable interrupts & save flags */
2712 spin_lock_irqsave(&lp->spinlock, flags);
2714 wstats = &lp->wstats;
2716 /* Get data from the mmc */
2717 mmc_out(base, mmwoff(0, mmw_freeze), 1);
2719 mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2720 mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
2721 mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
2723 mmc_out(base, mmwoff(0, mmw_freeze), 0);
2725 /* Copy data to wireless stuff */
2726 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2727 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2728 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2729 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2730 wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
2731 ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
2732 ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2733 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2734 wstats->discard.code = 0L;
2735 wstats->discard.misc = 0L;
2737 /* ReEnable interrupts & restore flags */
2738 spin_unlock_irqrestore(&lp->spinlock, flags);
2740 #ifdef DEBUG_IOCTL_TRACE
2741 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
2746 /************************* PACKET RECEPTION *************************/
2748 * This part deal with receiving the packets.
2749 * The interrupt handler get an interrupt when a packet has been
2750 * successfully received and called this part...
2753 /*------------------------------------------------------------------*/
2755 * Calculate the starting address of the frame pointed to by the receive
2756 * frame pointer and verify that the frame seem correct
2757 * (called by wv_packet_rcv())
2760 wv_start_of_frame(struct net_device * dev,
2761 int rfp, /* end of frame */
2762 int wrap) /* start of buffer */
2764 unsigned int base = dev->base_addr;
2768 rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
2769 outb(rp & 0xff, PIORL(base));
2770 outb(((rp >> 8) & PIORH_MASK), PIORH(base));
2771 len = inb(PIOP(base));
2772 len |= inb(PIOP(base)) << 8;
2774 /* Sanity checks on size */
2776 if(len > MAXDATAZ + 100)
2778 #ifdef DEBUG_RX_ERROR
2779 printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
2780 dev->name, rfp, len);
2785 /* Frame too short */
2788 #ifdef DEBUG_RX_ERROR
2789 printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
2790 dev->name, rfp, len);
2795 /* Wrap around buffer */
2796 if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
2798 #ifdef DEBUG_RX_ERROR
2799 printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
2800 dev->name, wrap, rfp, len);
2805 return((rp - len + RX_SIZE) % RX_SIZE);
2806 } /* wv_start_of_frame */
2808 /*------------------------------------------------------------------*/
2810 * This routine does the actual copy of data (including the ethernet
2811 * header structure) from the WaveLAN card to an sk_buff chain that
2812 * will be passed up to the network interface layer. NOTE: We
2813 * currently don't handle trailer protocols (neither does the rest of
2814 * the network interface), so if that is needed, it will (at least in
2815 * part) be added here. The contents of the receive ring buffer are
2816 * copied to a message chain that is then passed to the kernel.
2818 * Note: if any errors occur, the packet is "dropped on the floor"
2819 * (called by wv_packet_rcv())
2822 wv_packet_read(struct net_device * dev,
2826 net_local * lp = netdev_priv(dev);
2827 struct sk_buff * skb;
2829 #ifdef DEBUG_RX_TRACE
2830 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2831 dev->name, fd_p, sksize);
2834 /* Allocate some buffer for the new packet */
2835 if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
2837 #ifdef DEBUG_RX_ERROR
2838 printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
2841 lp->stats.rx_dropped++;
2843 * Not only do we want to return here, but we also need to drop the
2844 * packet on the floor to clear the interrupt.
2849 skb_reserve(skb, 2);
2850 fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
2851 skb->protocol = eth_type_trans(skb, dev);
2853 #ifdef DEBUG_RX_INFO
2854 wv_packet_info(skb_mac_header(skb), sksize, dev->name, "wv_packet_read");
2855 #endif /* DEBUG_RX_INFO */
2857 /* Statistics gathering & stuff associated.
2858 * It seem a bit messy with all the define, but it's really simple... */
2860 #ifdef IW_WIRELESS_SPY
2861 (lp->spy_data.spy_number > 0) ||
2862 #endif /* IW_WIRELESS_SPY */
2864 (lp->his_number > 0) ||
2865 #endif /* HISTOGRAM */
2866 #ifdef WAVELAN_ROAMING
2868 #endif /* WAVELAN_ROAMING */
2871 u_char stats[3]; /* Signal level, Noise level, Signal quality */
2873 /* read signal level, silence level and signal quality bytes */
2874 fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
2876 #ifdef DEBUG_RX_INFO
2877 printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2878 dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
2881 #ifdef WAVELAN_ROAMING
2883 if(WAVELAN_BEACON(skb->data))
2884 wl_roam_gather(dev, skb->data, stats);
2885 #endif /* WAVELAN_ROAMING */
2888 wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE, stats);
2889 #endif /* WIRELESS_SPY */
2891 wl_his_gather(dev, stats);
2892 #endif /* HISTOGRAM */
2896 * Hand the packet to the Network Module
2900 /* Keep stats up to date */
2901 dev->last_rx = jiffies;
2902 lp->stats.rx_packets++;
2903 lp->stats.rx_bytes += sksize;
2905 #ifdef DEBUG_RX_TRACE
2906 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2911 /*------------------------------------------------------------------*/
2913 * This routine is called by the interrupt handler to initiate a
2914 * packet transfer from the card to the network interface layer above
2915 * this driver. This routine checks if a buffer has been successfully
2916 * received by the WaveLAN card. If so, the routine wv_packet_read is
2917 * called to do the actual transfer of the card's data including the
2918 * ethernet header into a packet consisting of an sk_buff chain.
2919 * (called by wavelan_interrupt())
2920 * Note : the spinlock is already grabbed for us and irq are disabled.
2923 wv_packet_rcv(struct net_device * dev)
2925 unsigned int base = dev->base_addr;
2926 net_local * lp = netdev_priv(dev);
2936 #ifdef DEBUG_RX_TRACE
2937 printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
2940 /* Get the new receive frame pointer from the i82593 chip */
2941 outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
2942 i593_rfp = inb(LCSR(base));
2943 i593_rfp |= inb(LCSR(base)) << 8;
2944 i593_rfp %= RX_SIZE;
2946 /* Get the new receive frame pointer from the WaveLAN card.
2947 * It is 3 bytes more than the increment of the i82593 receive
2948 * frame pointer, for each packet. This is because it includes the
2949 * 3 roaming bytes added by the mmc.
2951 newrfp = inb(RPLL(base));
2952 newrfp |= inb(RPLH(base)) << 8;
2955 #ifdef DEBUG_RX_INFO
2956 printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
2957 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
2960 #ifdef DEBUG_RX_ERROR
2961 /* If no new frame pointer... */
2962 if(lp->overrunning || newrfp == lp->rfp)
2963 printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
2964 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
2967 /* Read all frames (packets) received */
2968 while(newrfp != lp->rfp)
2970 /* A frame is composed of the packet, followed by a status word,
2971 * the length of the frame (word) and the mmc info (SNR & qual).
2972 * It's because the length is at the end that we can only scan
2973 * frames backward. */
2975 /* Find the first frame by skipping backwards over the frames */
2976 rp = newrfp; /* End of last frame */
2977 while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
2981 /* If we had a problem */
2984 #ifdef DEBUG_RX_ERROR
2985 printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
2986 printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
2987 i593_rfp, lp->stop, newrfp, lp->rfp);
2989 lp->rfp = rp; /* Get to the last usable frame */
2993 /* f_start point to the beggining of the first frame received
2994 * and rp to the beggining of the next one */
2996 /* Read status & length of the frame */
2997 stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
2998 stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
2999 status = c[0] | (c[1] << 8);
3000 len = c[2] | (c[3] << 8);
3003 if((status & RX_RCV_OK) != RX_RCV_OK)
3005 lp->stats.rx_errors++;
3006 if(status & RX_NO_SFD)
3007 lp->stats.rx_frame_errors++;
3008 if(status & RX_CRC_ERR)
3009 lp->stats.rx_crc_errors++;
3010 if(status & RX_OVRRUN)
3011 lp->stats.rx_over_errors++;
3013 #ifdef DEBUG_RX_FAIL
3014 printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
3019 /* Read the packet and transmit to Linux */
3020 wv_packet_read(dev, f_start, len - 2);
3022 /* One frame has been processed, skip it */
3027 * Update the frame stop register, but set it to less than
3028 * the full 8K to allow space for 3 bytes of signal strength
3031 lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3032 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3033 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3034 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3036 #ifdef DEBUG_RX_TRACE
3037 printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
3041 /*********************** PACKET TRANSMISSION ***********************/
3043 * This part deal with sending packet through the wavelan
3044 * We copy the packet to the send buffer and then issue the send
3045 * command to the i82593. The result of this operation will be
3046 * checked in wavelan_interrupt()
3049 /*------------------------------------------------------------------*/
3051 * This routine fills in the appropriate registers and memory
3052 * locations on the WaveLAN card and starts the card off on
3054 * (called in wavelan_packet_xmit())
3057 wv_packet_write(struct net_device * dev,
3061 net_local * lp = netdev_priv(dev);
3062 unsigned int base = dev->base_addr;
3063 unsigned long flags;
3065 register u_short xmtdata_base = TX_BASE;
3067 #ifdef DEBUG_TX_TRACE
3068 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
3071 spin_lock_irqsave(&lp->spinlock, flags);
3073 /* Write the length of data buffer followed by the buffer */
3074 outb(xmtdata_base & 0xff, PIORL(base));
3075 outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3076 outb(clen & 0xff, PIOP(base)); /* lsb */
3077 outb(clen >> 8, PIOP(base)); /* msb */
3080 outsb(PIOP(base), buf, clen);
3082 /* Indicate end of transmit chain */
3083 outb(OP0_NOP, PIOP(base));
3084 /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
3085 outb(OP0_NOP, PIOP(base));
3087 /* Reset the transmit DMA pointer */
3088 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3089 hacr_write(base, HACR_DEFAULT);
3090 /* Send the transmit command */
3091 wv_82593_cmd(dev, "wv_packet_write(): transmit",
3092 OP0_TRANSMIT, SR0_NO_RESULT);
3094 /* Make sure the watchdog will keep quiet for a while */
3095 dev->trans_start = jiffies;
3097 /* Keep stats up to date */
3098 lp->stats.tx_bytes += length;
3100 spin_unlock_irqrestore(&lp->spinlock, flags);
3102 #ifdef DEBUG_TX_INFO
3103 wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
3104 #endif /* DEBUG_TX_INFO */
3106 #ifdef DEBUG_TX_TRACE
3107 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
3111 /*------------------------------------------------------------------*/
3113 * This routine is called when we want to send a packet (NET3 callback)
3114 * In this routine, we check if the harware is ready to accept
3115 * the packet. We also prevent reentrance. Then, we call the function
3116 * to send the packet...
3119 wavelan_packet_xmit(struct sk_buff * skb,
3120 struct net_device * dev)
3122 net_local * lp = netdev_priv(dev);
3123 unsigned long flags;
3125 #ifdef DEBUG_TX_TRACE
3126 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
3131 * Block a timer-based transmit from overlapping a previous transmit.
3132 * In other words, prevent reentering this routine.
3134 netif_stop_queue(dev);
3136 /* If somebody has asked to reconfigure the controller,
3137 * we can do it now */
3138 if(lp->reconfig_82593)
3140 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
3141 wv_82593_config(dev);
3142 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
3143 /* Note : the configure procedure was totally synchronous,
3144 * so the Tx buffer is now free */
3147 #ifdef DEBUG_TX_ERROR
3149 printk(KERN_INFO "skb has next\n");
3152 /* Check if we need some padding */
3153 /* Note : on wireless the propagation time is in the order of 1us,
3154 * and we don't have the Ethernet specific requirement of beeing
3155 * able to detect collisions, therefore in theory we don't really
3156 * need to pad. Jean II */
3157 if (skb_padto(skb, ETH_ZLEN))
3160 wv_packet_write(dev, skb->data, skb->len);
3164 #ifdef DEBUG_TX_TRACE
3165 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
3170 /********************** HARDWARE CONFIGURATION **********************/
3172 * This part do the real job of starting and configuring the hardware.
3175 /*------------------------------------------------------------------*/
3177 * Routine to initialize the Modem Management Controller.
3178 * (called by wv_hw_config())
3181 wv_mmc_init(struct net_device * dev)
3183 unsigned int base = dev->base_addr;
3187 int i; /* Loop counter */
3189 #ifdef DEBUG_CONFIG_TRACE
3190 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
3193 /* Read the parameter storage area */
3194 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3197 * Check the first three octets of the MAC addr for the manufacturer's code.
3198 * Note: If you get the error message below, you've got a
3199 * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
3200 * how to configure your card...
3202 for (i = 0; i < ARRAY_SIZE(MAC_ADDRESSES); i++)
3203 if ((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
3204 (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
3205 (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
3208 /* If we have not found it... */
3209 if (i == ARRAY_SIZE(MAC_ADDRESSES))
3211 #ifdef DEBUG_CONFIG_ERRORS
3212 printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
3213 dev->name, psa.psa_univ_mac_addr[0],
3214 psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
3219 /* Get the MAC address */
3220 memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
3222 #ifdef USE_PSA_CONFIG
3223 configured = psa.psa_conf_status & 1;
3228 /* Is the PSA is not configured */
3231 /* User will be able to configure NWID after (with iwconfig) */
3232 psa.psa_nwid[0] = 0;
3233 psa.psa_nwid[1] = 0;
3235 /* As NWID is not set : no NWID checking */
3236 psa.psa_nwid_select = 0;
3238 /* Disable encryption */
3239 psa.psa_encryption_select = 0;
3241 /* Set to standard values
3244 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
3246 if (psa.psa_comp_number & 1)
3247 psa.psa_thr_pre_set = 0x01;
3249 psa.psa_thr_pre_set = 0x04;
3250 psa.psa_quality_thr = 0x03;
3252 /* It is configured */
3253 psa.psa_conf_status |= 1;
3255 #ifdef USE_PSA_CONFIG
3257 psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
3258 (unsigned char *)psa.psa_nwid, 4);
3259 psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
3260 (unsigned char *)&psa.psa_thr_pre_set, 1);
3261 psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
3262 (unsigned char *)&psa.psa_quality_thr, 1);
3263 psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
3264 (unsigned char *)&psa.psa_conf_status, 1);
3265 /* update the Wavelan checksum */
3266 update_psa_checksum(dev);
3267 #endif /* USE_PSA_CONFIG */
3270 /* Zero the mmc structure */
3271 memset(&m, 0x00, sizeof(m));
3273 /* Copy PSA info to the mmc */
3274 m.mmw_netw_id_l = psa.psa_nwid[1];
3275 m.mmw_netw_id_h = psa.psa_nwid[0];
3277 if(psa.psa_nwid_select & 1)
3278 m.mmw_loopt_sel = 0x00;
3280 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
3282 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
3283 sizeof(m.mmw_encr_key));
3285 if(psa.psa_encryption_select)
3286 m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
3288 m.mmw_encr_enable = 0;
3290 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
3291 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
3294 * Set default modem control parameters.
3295 * See NCR document 407-0024326 Rev. A.
3297 m.mmw_jabber_enable = 0x01;
3298 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
3300 m.mmw_mod_delay = 0x04;
3301 m.mmw_jam_time = 0x38;
3303 m.mmw_des_io_invert = 0;
3305 m.mmw_decay_prm = 0;
3306 m.mmw_decay_updat_prm = 0;
3308 /* Write all info to mmc */
3309 mmc_write(base, 0, (u_char *)&m, sizeof(m));
3311 /* The following code start the modem of the 2.00 frequency
3312 * selectable cards at power on. It's not strictly needed for the
3313 * following boots...
3314 * The original patch was by Joe Finney for the PCMCIA driver, but
3315 * I've cleaned it a bit and add documentation.
3316 * Thanks to Loeke Brederveld from Lucent for the info.
3319 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3320 * (does it work for everybody ? - especially old cards...) */
3321 /* Note : WFREQSEL verify that it is able to read from EEprom
3322 * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
3323 * is 0xA (Xilinx version) or 0xB (Ariadne version).
3324 * My test is more crude but do work... */
3325 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
3326 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
3328 /* We must download the frequency parameters to the
3329 * synthetisers (from the EEprom - area 1)
3330 * Note : as the EEprom is auto decremented, we set the end
3332 m.mmw_fee_addr = 0x0F;
3333 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3334 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3335 (unsigned char *)&m.mmw_fee_ctrl, 2);
3337 /* Wait until the download is finished */
3338 fee_wait(base, 100, 100);
3340 #ifdef DEBUG_CONFIG_INFO
3341 /* The frequency was in the last word downloaded... */
3342 mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
3343 (unsigned char *)&m.mmw_fee_data_l, 2);
3345 /* Print some info for the user */
3346 printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
3348 ((m.mmw_fee_data_h << 4) |
3349 (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
3352 /* We must now download the power adjust value (gain) to
3353 * the synthetisers (from the EEprom - area 7 - DAC) */
3354 m.mmw_fee_addr = 0x61;
3355 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3356 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3357 (unsigned char *)&m.mmw_fee_ctrl, 2);
3359 /* Wait until the download is finished */
3360 } /* if 2.00 card */
3362 #ifdef DEBUG_CONFIG_TRACE
3363 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3368 /*------------------------------------------------------------------*/
3370 * Routine to gracefully turn off reception, and wait for any commands
3372 * (called in wv_ru_start() and wavelan_close() and wavelan_event())
3375 wv_ru_stop(struct net_device * dev)
3377 unsigned int base = dev->base_addr;
3378 net_local * lp = netdev_priv(dev);
3379 unsigned long flags;
3383 #ifdef DEBUG_CONFIG_TRACE
3384 printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
3387 spin_lock_irqsave(&lp->spinlock, flags);
3389 /* First, send the LAN controller a stop receive command */
3390 wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
3391 OP0_STOP_RCV, SR0_NO_RESULT);
3393 /* Then, spin until the receive unit goes idle */
3398 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3399 status = inb(LCSR(base));
3401 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
3403 /* Now, spin until the chip finishes executing its current command */
3407 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3408 status = inb(LCSR(base));
3410 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
3412 spin_unlock_irqrestore(&lp->spinlock, flags);
3414 /* If there was a problem */
3417 #ifdef DEBUG_CONFIG_ERRORS
3418 printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
3424 #ifdef DEBUG_CONFIG_TRACE
3425 printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
3430 /*------------------------------------------------------------------*/
3432 * This routine starts the receive unit running. First, it checks if
3433 * the card is actually ready. Then the card is instructed to receive
3435 * (called in wv_hw_reset() & wavelan_open())
3438 wv_ru_start(struct net_device * dev)
3440 unsigned int base = dev->base_addr;
3441 net_local * lp = netdev_priv(dev);
3442 unsigned long flags;
3444 #ifdef DEBUG_CONFIG_TRACE
3445 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3449 * We need to start from a quiescent state. To do so, we could check
3450 * if the card is already running, but instead we just try to shut
3451 * it down. First, we disable reception (in case it was already enabled).
3453 if(!wv_ru_stop(dev))
3456 spin_lock_irqsave(&lp->spinlock, flags);
3458 /* Now we know that no command is being executed. */
3460 /* Set the receive frame pointer and stop pointer */
3462 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3464 /* Reset ring management. This sets the receive frame pointer to 1 */
3465 outb(OP1_RESET_RING_MNGMT, LCCR(base));
3468 /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
3469 should be set as below */
3470 /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
3472 /* but I set it 0 instead */
3475 /* but I set it to 3 bytes per packet less than 8K */
3476 lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3478 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3479 outb(OP1_INT_ENABLE, LCCR(base));
3480 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3482 /* Reset receive DMA pointer */
3483 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3484 hacr_write_slow(base, HACR_DEFAULT);
3486 /* Receive DMA on channel 1 */
3487 wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
3488 CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
3490 #ifdef DEBUG_I82593_SHOW
3496 /* spin until the chip starts receiving */
3499 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3500 status = inb(LCSR(base));
3504 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
3505 ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
3506 printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
3507 (status & SR3_RCV_STATE_MASK), i);
3511 spin_unlock_irqrestore(&lp->spinlock, flags);
3513 #ifdef DEBUG_CONFIG_TRACE
3514 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3519 /*------------------------------------------------------------------*/
3521 * This routine does a standard config of the WaveLAN controller (i82593).
3522 * In the ISA driver, this is integrated in wavelan_hardware_reset()
3523 * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
3526 wv_82593_config(struct net_device * dev)
3528 unsigned int base = dev->base_addr;
3529 net_local * lp = netdev_priv(dev);
3530 struct i82593_conf_block cfblk;
3533 #ifdef DEBUG_CONFIG_TRACE
3534 printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
3537 /* Create & fill i82593 config block
3539 * Now conform to Wavelan document WCIN085B
3541 memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
3542 cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
3543 cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
3544 cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
3546 cfblk.throttle_enb = FALSE;
3547 cfblk.contin = TRUE; /* enable continuous mode */
3548 cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
3549 cfblk.addr_len = WAVELAN_ADDR_SIZE;
3550 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
3551 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
3552 cfblk.loopback = FALSE;
3553 cfblk.lin_prio = 0; /* conform to 802.3 backoff algorithm */
3554 cfblk.exp_prio = 5; /* conform to 802.3 backoff algorithm */
3555 cfblk.bof_met = 1; /* conform to 802.3 backoff algorithm */
3556 cfblk.ifrm_spc = 0x20 >> 4; /* 32 bit times interframe spacing */
3557 cfblk.slottim_low = 0x20 >> 5; /* 32 bit times slot time */
3558 cfblk.slottim_hi = 0x0;
3559 cfblk.max_retr = 15;
3560 cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
3561 cfblk.bc_dis = FALSE; /* Enable broadcast reception */
3562 cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
3563 cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
3564 cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
3565 cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
3566 cfblk.cs_filter = 0; /* CS is recognized immediately */
3567 cfblk.crs_src = FALSE; /* External carrier sense */
3568 cfblk.cd_filter = 0; /* CD is recognized immediately */
3569 cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
3570 cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
3571 cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
3572 cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
3573 cfblk.artx = TRUE; /* Disable automatic retransmission */
3574 cfblk.sarec = TRUE; /* Disable source addr trig of CD */
3575 cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
3576 cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
3577 cfblk.lbpkpol = TRUE; /* Loopback pin active high */
3578 cfblk.fdx = FALSE; /* Disable full duplex operation */
3579 cfblk.dummy_6 = 0x3f; /* all ones */
3580 cfblk.mult_ia = FALSE; /* No multiple individual addresses */
3581 cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
3582 cfblk.dummy_1 = TRUE; /* set to 1 */
3583 cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
3584 #ifdef MULTICAST_ALL
3585 cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
3587 cfblk.mc_all = FALSE; /* No multicast all mode */
3589 cfblk.rcv_mon = 0; /* Monitor mode disabled */
3590 cfblk.frag_acpt = TRUE; /* Do not accept fragments */
3591 cfblk.tstrttrs = FALSE; /* No start transmission threshold */
3592 cfblk.fretx = TRUE; /* FIFO automatic retransmission */
3593 cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
3594 cfblk.sttlen = TRUE; /* 6 byte status registers */
3595 cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
3596 cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
3597 cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
3598 cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
3600 #ifdef DEBUG_I82593_SHOW
3602 u_char *c = (u_char *) &cfblk;
3604 printk(KERN_DEBUG "wavelan_cs: config block:");
3605 for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
3607 if((i % 16) == 0) printk("\n" KERN_DEBUG);
3608 printk("%02x ", *c);
3614 /* Copy the config block to the i82593 */
3615 outb(TX_BASE & 0xff, PIORL(base));
3616 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3617 outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
3618 outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
3619 outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
3621 /* reset transmit DMA pointer */
3622 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3623 hacr_write(base, HACR_DEFAULT);
3624 if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
3625 OP0_CONFIGURE, SR0_CONFIGURE_DONE))
3628 /* Initialize adapter's ethernet MAC address */
3629 outb(TX_BASE & 0xff, PIORL(base));
3630 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3631 outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
3632 outb(0, PIOP(base)); /* byte count msb */
3633 outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
3635 /* reset transmit DMA pointer */
3636 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3637 hacr_write(base, HACR_DEFAULT);
3638 if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
3639 OP0_IA_SETUP, SR0_IA_SETUP_DONE))
3642 #ifdef WAVELAN_ROAMING
3643 /* If roaming is enabled, join the "Beacon Request" multicast group... */
3644 /* But only if it's not in there already! */
3646 dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
3647 #endif /* WAVELAN_ROAMING */
3649 /* If any multicast address to set */
3652 struct dev_mc_list * dmi;
3653 int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
3655 #ifdef DEBUG_CONFIG_INFO
3656 DECLARE_MAC_BUF(mac);
3657 printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
3658 dev->name, lp->mc_count);
3659 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3660 printk(KERN_DEBUG " %s\n",
3661 print_mac(mac, dmi->dmi_addr));
3664 /* Initialize adapter's ethernet multicast addresses */
3665 outb(TX_BASE & 0xff, PIORL(base));
3666 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3667 outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
3668 outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
3669 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3670 outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
3672 /* reset transmit DMA pointer */
3673 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3674 hacr_write(base, HACR_DEFAULT);
3675 if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
3676 OP0_MC_SETUP, SR0_MC_SETUP_DONE))
3678 lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
3681 /* Job done, clear the flag */
3682 lp->reconfig_82593 = FALSE;
3684 #ifdef DEBUG_CONFIG_TRACE
3685 printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
3690 /*------------------------------------------------------------------*/
3692 * Read the Access Configuration Register, perform a software reset,
3693 * and then re-enable the card's software.
3695 * If I understand correctly : reset the pcmcia interface of the
3697 * (called by wv_config())
3700 wv_pcmcia_reset(struct net_device * dev)
3703 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
3704 struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
3706 #ifdef DEBUG_CONFIG_TRACE
3707 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
3710 i = pcmcia_access_configuration_register(link, ®);
3713 cs_error(link, AccessConfigurationRegister, i);
3717 #ifdef DEBUG_CONFIG_INFO
3718 printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
3719 dev->name, (u_int) reg.Value);
3722 reg.Action = CS_WRITE;
3723 reg.Value = reg.Value | COR_SW_RESET;
3724 i = pcmcia_access_configuration_register(link, ®);
3727 cs_error(link, AccessConfigurationRegister, i);
3731 reg.Action = CS_WRITE;
3732 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3733 i = pcmcia_access_configuration_register(link, ®);
3736 cs_error(link, AccessConfigurationRegister, i);
3740 #ifdef DEBUG_CONFIG_TRACE
3741 printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
3746 /*------------------------------------------------------------------*/
3748 * wavelan_hw_config() is called after a CARD_INSERTION event is
3749 * received, to configure the wavelan hardware.
3750 * Note that the reception will be enabled in wavelan->open(), so the
3751 * device is configured but idle...
3752 * Performs the following actions:
3753 * 1. A pcmcia software reset (using wv_pcmcia_reset())
3754 * 2. A power reset (reset DMA)
3755 * 3. Reset the LAN controller
3756 * 4. Initialize the radio modem (using wv_mmc_init)
3757 * 5. Configure LAN controller (using wv_82593_config)
3758 * 6. Perform a diagnostic on the LAN controller
3759 * (called by wavelan_event() & wv_hw_reset())
3762 wv_hw_config(struct net_device * dev)
3764 net_local * lp = netdev_priv(dev);
3765 unsigned int base = dev->base_addr;
3766 unsigned long flags;
3769 #ifdef DEBUG_CONFIG_TRACE
3770 printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
3773 /* compile-time check the sizes of structures */
3774 BUILD_BUG_ON(sizeof(psa_t) != PSA_SIZE);
3775 BUILD_BUG_ON(sizeof(mmw_t) != MMW_SIZE);
3776 BUILD_BUG_ON(sizeof(mmr_t) != MMR_SIZE);
3778 /* Reset the pcmcia interface */
3779 if(wv_pcmcia_reset(dev) == FALSE)
3782 /* Disable interrupts */
3783 spin_lock_irqsave(&lp->spinlock, flags);
3785 /* Disguised goto ;-) */
3788 /* Power UP the module + reset the modem + reset host adapter
3789 * (in fact, reset DMA channels) */
3790 hacr_write_slow(base, HACR_RESET);
3791 hacr_write(base, HACR_DEFAULT);
3793 /* Check if the module has been powered up... */
3794 if(hasr_read(base) & HASR_NO_CLK)
3796 #ifdef DEBUG_CONFIG_ERRORS
3797 printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
3803 /* initialize the modem */
3804 if(wv_mmc_init(dev) == FALSE)
3806 #ifdef DEBUG_CONFIG_ERRORS
3807 printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n",
3813 /* reset the LAN controller (i82593) */
3814 outb(OP0_RESET, LCCR(base));
3815 mdelay(1); /* A bit crude ! */
3817 /* Initialize the LAN controller */
3818 if(wv_82593_config(dev) == FALSE)
3820 #ifdef DEBUG_CONFIG_ERRORS
3821 printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n",
3828 if(wv_diag(dev) == FALSE)
3830 #ifdef DEBUG_CONFIG_ERRORS
3831 printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n",
3838 * insert code for loopback test here
3841 /* The device is now configured */
3847 /* Re-enable interrupts */
3848 spin_unlock_irqrestore(&lp->spinlock, flags);
3850 #ifdef DEBUG_CONFIG_TRACE
3851 printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
3856 /*------------------------------------------------------------------*/
3858 * Totally reset the wavelan and restart it.
3859 * Performs the following actions:
3860 * 1. Call wv_hw_config()
3861 * 2. Start the LAN controller's receive unit
3862 * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
3865 wv_hw_reset(struct net_device * dev)
3867 net_local * lp = netdev_priv(dev);
3869 #ifdef DEBUG_CONFIG_TRACE
3870 printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
3876 /* Call wv_hw_config() for most of the reset & init stuff */
3877 if(wv_hw_config(dev) == FALSE)
3880 /* start receive unit */
3883 #ifdef DEBUG_CONFIG_TRACE
3884 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3888 /*------------------------------------------------------------------*/
3890 * wv_pcmcia_config() is called after a CARD_INSERTION event is
3891 * received, to configure the PCMCIA socket, and to make the ethernet
3892 * device available to the system.
3893 * (called by wavelan_event())
3896 wv_pcmcia_config(struct pcmcia_device * link)
3898 struct net_device * dev = (struct net_device *) link->priv;
3902 net_local * lp = netdev_priv(dev);
3905 #ifdef DEBUG_CONFIG_TRACE
3906 printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
3911 i = pcmcia_request_io(link, &link->io);
3914 cs_error(link, RequestIO, i);
3919 * Now allocate an interrupt line. Note that this does not
3920 * actually assign a handler to the interrupt.
3922 i = pcmcia_request_irq(link, &link->irq);
3925 cs_error(link, RequestIRQ, i);
3930 * This actually configures the PCMCIA socket -- setting up
3931 * the I/O windows and the interrupt mapping.
3933 link->conf.ConfigIndex = 1;
3934 i = pcmcia_request_configuration(link, &link->conf);
3937 cs_error(link, RequestConfiguration, i);
3942 * Allocate a small memory window. Note that the struct pcmcia_device
3943 * structure provides space for one window handle -- if your
3944 * device needs several windows, you'll need to keep track of
3945 * the handles in your private data structure, link->priv.
3947 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
3948 req.Base = req.Size = 0;
3949 req.AccessSpeed = mem_speed;
3950 i = pcmcia_request_window(&link, &req, &link->win);
3953 cs_error(link, RequestWindow, i);
3957 lp->mem = ioremap(req.Base, req.Size);
3958 dev->mem_start = (u_long)lp->mem;
3959 dev->mem_end = dev->mem_start + req.Size;
3961 mem.CardOffset = 0; mem.Page = 0;
3962 i = pcmcia_map_mem_page(link->win, &mem);
3965 cs_error(link, MapMemPage, i);
3969 /* Feed device with this info... */
3970 dev->irq = link->irq.AssignedIRQ;
3971 dev->base_addr = link->io.BasePort1;
3972 netif_start_queue(dev);
3974 #ifdef DEBUG_CONFIG_INFO
3975 printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART %p IRQ %d IOPORT 0x%x\n",
3976 lp->mem, dev->irq, (u_int) dev->base_addr);
3979 SET_NETDEV_DEV(dev, &handle_to_dev(link));
3980 i = register_netdev(dev);
3983 #ifdef DEBUG_CONFIG_ERRORS
3984 printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
3989 while(0); /* Humm... Disguised goto !!! */
3991 /* If any step failed, release any partially configured state */
3994 wv_pcmcia_release(link);
3998 strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
3999 link->dev_node = &((net_local *) netdev_priv(dev))->node;
4001 #ifdef DEBUG_CONFIG_TRACE
4002 printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
4007 /*------------------------------------------------------------------*/
4009 * After a card is removed, wv_pcmcia_release() will unregister the net
4010 * device, and release the PCMCIA configuration. If the device is
4011 * still open, this will be postponed until it is closed.
4014 wv_pcmcia_release(struct pcmcia_device *link)
4016 struct net_device * dev = (struct net_device *) link->priv;
4017 net_local * lp = netdev_priv(dev);
4019 #ifdef DEBUG_CONFIG_TRACE
4020 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
4024 pcmcia_disable_device(link);
4026 #ifdef DEBUG_CONFIG_TRACE
4027 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
4031 /************************ INTERRUPT HANDLING ************************/
4034 * This function is the interrupt handler for the WaveLAN card. This
4035 * routine will be called whenever:
4036 * 1. A packet is received.
4037 * 2. A packet has successfully been transferred and the unit is
4038 * ready to transmit another packet.
4039 * 3. A command has completed execution.
4042 wavelan_interrupt(int irq,
4045 struct net_device * dev = dev_id;
4051 #ifdef DEBUG_INTERRUPT_TRACE
4052 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
4055 lp = netdev_priv(dev);
4056 base = dev->base_addr;
4058 #ifdef DEBUG_INTERRUPT_INFO
4059 /* Check state of our spinlock (it should be cleared) */
4060 if(spin_is_locked(&lp->spinlock))
4062 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
4066 /* Prevent reentrancy. We need to do that because we may have
4067 * multiple interrupt handler running concurently.
4068 * It is safe because interrupts are disabled before aquiring
4070 spin_lock(&lp->spinlock);
4072 /* Treat all pending interrupts */
4075 /* ---------------- INTERRUPT CHECKING ---------------- */
4077 * Look for the interrupt and verify the validity
4079 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
4080 status0 = inb(LCSR(base));
4082 #ifdef DEBUG_INTERRUPT_INFO
4083 printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
4084 (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
4085 if(status0&SR0_INTERRUPT)
4087 printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
4088 ((status0 & SR0_EXECUTION) ? "cmd" :
4089 ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
4090 (status0 & SR0_EVENT_MASK));
4096 /* Return if no actual interrupt from i82593 (normal exit) */
4097 if(!(status0 & SR0_INTERRUPT))
4100 /* If interrupt is both Rx and Tx or none...
4101 * This code in fact is there to catch the spurious interrupt
4102 * when you remove the wavelan pcmcia card from the socket */
4103 if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
4104 ((status0 & SR0_BOTH_RX_TX) == 0x0))
4106 #ifdef DEBUG_INTERRUPT_INFO
4107 printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
4108 dev->name, status0);
4110 /* Acknowledge the interrupt */
4111 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4115 /* ----------------- RECEIVING PACKET ----------------- */
4117 * When the wavelan signal the reception of a new packet,
4118 * we call wv_packet_rcv() to copy if from the buffer and
4121 if(status0 & SR0_RECEPTION)
4123 #ifdef DEBUG_INTERRUPT_INFO
4124 printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
4127 if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
4129 #ifdef DEBUG_INTERRUPT_ERROR
4130 printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
4133 lp->stats.rx_over_errors++;
4134 lp->overrunning = 1;
4137 /* Get the packet */
4139 lp->overrunning = 0;
4141 /* Acknowledge the interrupt */
4142 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4146 /* ---------------- COMMAND COMPLETION ---------------- */
4148 * Interrupts issued when the i82593 has completed a command.
4149 * Most likely : transmission done
4152 /* If a transmission has been done */
4153 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
4154 (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
4155 (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4157 #ifdef DEBUG_TX_ERROR
4158 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4159 printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
4163 /* Get transmission status */
4164 tx_status = inb(LCSR(base));
4165 tx_status |= (inb(LCSR(base)) << 8);
4166 #ifdef DEBUG_INTERRUPT_INFO
4167 printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
4172 rcv_bytes = inb(LCSR(base));
4173 rcv_bytes |= (inb(LCSR(base)) << 8);
4174 status3 = inb(LCSR(base));
4175 printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
4176 tx_status, rcv_bytes, (u_int) status3);
4179 /* Check for possible errors */
4180 if((tx_status & TX_OK) != TX_OK)
4182 lp->stats.tx_errors++;
4184 if(tx_status & TX_FRTL)
4186 #ifdef DEBUG_TX_ERROR
4187 printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
4191 if(tx_status & TX_UND_RUN)
4193 #ifdef DEBUG_TX_FAIL
4194 printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
4197 lp->stats.tx_aborted_errors++;
4199 if(tx_status & TX_LOST_CTS)
4201 #ifdef DEBUG_TX_FAIL
4202 printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
4204 lp->stats.tx_carrier_errors++;
4206 if(tx_status & TX_LOST_CRS)
4208 #ifdef DEBUG_TX_FAIL
4209 printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
4212 lp->stats.tx_carrier_errors++;
4214 if(tx_status & TX_HRT_BEAT)
4216 #ifdef DEBUG_TX_FAIL
4217 printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
4219 lp->stats.tx_heartbeat_errors++;
4221 if(tx_status & TX_DEFER)
4223 #ifdef DEBUG_TX_FAIL
4224 printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
4228 /* Ignore late collisions since they're more likely to happen
4229 * here (the WaveLAN design prevents the LAN controller from
4230 * receiving while it is transmitting). We take action only when
4231 * the maximum retransmit attempts is exceeded.
4233 if(tx_status & TX_COLL)
4235 if(tx_status & TX_MAX_COL)
4237 #ifdef DEBUG_TX_FAIL
4238 printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
4241 if(!(tx_status & TX_NCOL_MASK))
4243 lp->stats.collisions += 0x10;
4247 } /* if(!(tx_status & TX_OK)) */
4249 lp->stats.collisions += (tx_status & TX_NCOL_MASK);
4250 lp->stats.tx_packets++;
4252 netif_wake_queue(dev);
4253 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4255 else /* if interrupt = transmit done or retransmit done */
4257 #ifdef DEBUG_INTERRUPT_ERROR
4258 printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
4261 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4265 spin_unlock(&lp->spinlock);
4267 #ifdef DEBUG_INTERRUPT_TRACE
4268 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
4271 /* We always return IRQ_HANDLED, because we will receive empty
4272 * interrupts under normal operations. Anyway, it doesn't matter
4273 * as we are dealing with an ISA interrupt that can't be shared.
4275 * Explanation : under heavy receive, the following happens :
4276 * ->wavelan_interrupt()
4277 * (status0 & SR0_INTERRUPT) != 0
4279 * (status0 & SR0_INTERRUPT) != 0
4281 * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event
4282 * <-wavelan_interrupt()
4283 * ->wavelan_interrupt()
4284 * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt
4285 * <-wavelan_interrupt()
4288 } /* wv_interrupt */
4290 /*------------------------------------------------------------------*/
4292 * Watchdog: when we start a transmission, a timer is set for us in the
4293 * kernel. If the transmission completes, this timer is disabled. If
4294 * the timer expires, we are called and we try to unlock the hardware.
4296 * Note : This watchdog is move clever than the one in the ISA driver,
4297 * because it try to abort the current command before reseting
4299 * On the other hand, it's a bit simpler, because we don't have to
4300 * deal with the multiple Tx buffers...
4303 wavelan_watchdog(struct net_device * dev)
4305 net_local * lp = netdev_priv(dev);
4306 unsigned int base = dev->base_addr;
4307 unsigned long flags;
4308 int aborted = FALSE;
4310 #ifdef DEBUG_INTERRUPT_TRACE
4311 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
4314 #ifdef DEBUG_INTERRUPT_ERROR
4315 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
4319 spin_lock_irqsave(&lp->spinlock, flags);
4321 /* Ask to abort the current command */
4322 outb(OP0_ABORT, LCCR(base));
4324 /* Wait for the end of the command (a bit hackish) */
4325 if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
4326 OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
4329 /* Release spinlock here so that wv_hw_reset() can grab it */
4330 spin_unlock_irqrestore(&lp->spinlock, flags);
4332 /* Check if we were successful in aborting it */
4335 /* It seem that it wasn't enough */
4336 #ifdef DEBUG_INTERRUPT_ERROR
4337 printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
4343 #ifdef DEBUG_PSA_SHOW
4346 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
4350 #ifdef DEBUG_MMC_SHOW
4353 #ifdef DEBUG_I82593_SHOW
4357 /* We are no more waiting for something... */
4358 netif_wake_queue(dev);
4360 #ifdef DEBUG_INTERRUPT_TRACE
4361 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
4365 /********************* CONFIGURATION CALLBACKS *********************/
4367 * Here are the functions called by the pcmcia package (cardmgr) and
4368 * linux networking (NET3) for initialization, configuration and
4369 * deinstallations of the Wavelan Pcmcia Hardware.
4372 /*------------------------------------------------------------------*/
4374 * Configure and start up the WaveLAN PCMCIA adaptor.
4375 * Called by NET3 when it "open" the device.
4378 wavelan_open(struct net_device * dev)
4380 net_local * lp = netdev_priv(dev);
4381 struct pcmcia_device * link = lp->link;
4382 unsigned int base = dev->base_addr;
4384 #ifdef DEBUG_CALLBACK_TRACE
4385 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
4386 (unsigned int) dev);
4389 /* Check if the modem is powered up (wavelan_close() power it down */
4390 if(hasr_read(base) & HASR_NO_CLK)
4392 /* Power up (power up time is 250us) */
4393 hacr_write(base, HACR_DEFAULT);
4395 /* Check if the module has been powered up... */
4396 if(hasr_read(base) & HASR_NO_CLK)
4398 #ifdef DEBUG_CONFIG_ERRORS
4399 printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
4406 /* Start reception and declare the driver ready */
4409 if(!wv_ru_start(dev))
4410 wv_hw_reset(dev); /* If problem : reset */
4411 netif_start_queue(dev);
4413 /* Mark the device as used */
4416 #ifdef WAVELAN_ROAMING
4419 #endif /* WAVELAN_ROAMING */
4421 #ifdef DEBUG_CALLBACK_TRACE
4422 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
4427 /*------------------------------------------------------------------*/
4429 * Shutdown the WaveLAN PCMCIA adaptor.
4430 * Called by NET3 when it "close" the device.
4433 wavelan_close(struct net_device * dev)
4435 struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
4436 unsigned int base = dev->base_addr;
4438 #ifdef DEBUG_CALLBACK_TRACE
4439 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
4440 (unsigned int) dev);
4443 /* If the device isn't open, then nothing to do */
4446 #ifdef DEBUG_CONFIG_INFO
4447 printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
4452 #ifdef WAVELAN_ROAMING
4453 /* Cleanup of roaming stuff... */
4455 wv_roam_cleanup(dev);
4456 #endif /* WAVELAN_ROAMING */
4460 /* If the card is still present */
4461 if(netif_running(dev))
4463 netif_stop_queue(dev);
4465 /* Stop receiving new messages and wait end of transmission */
4468 /* Power down the module */
4469 hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
4472 #ifdef DEBUG_CALLBACK_TRACE
4473 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
4478 /*------------------------------------------------------------------*/
4480 * wavelan_attach() creates an "instance" of the driver, allocating
4481 * local data structures for one device (one interface). The device
4482 * is registered with Card Services.
4484 * The dev_link structure is initialized, but we don't actually
4485 * configure the card at this point -- we wait until we receive a
4486 * card insertion event.
4489 wavelan_probe(struct pcmcia_device *p_dev)
4491 struct net_device * dev; /* Interface generic data */
4492 net_local * lp; /* Interface specific data */
4495 #ifdef DEBUG_CALLBACK_TRACE
4496 printk(KERN_DEBUG "-> wavelan_attach()\n");
4499 /* The io structure describes IO port mapping */
4500 p_dev->io.NumPorts1 = 8;
4501 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
4502 p_dev->io.IOAddrLines = 3;
4504 /* Interrupt setup */
4505 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
4506 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
4507 p_dev->irq.Handler = wavelan_interrupt;
4509 /* General socket configuration */
4510 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
4511 p_dev->conf.IntType = INT_MEMORY_AND_IO;
4513 /* Allocate the generic data structure */
4514 dev = alloc_etherdev(sizeof(net_local));
4518 p_dev->priv = p_dev->irq.Instance = dev;
4520 lp = netdev_priv(dev);
4522 /* Init specific data */
4524 lp->reconfig_82593 = FALSE;
4526 /* Multicast stuff */
4527 lp->promiscuous = 0;
4528 lp->allmulticast = 0;
4532 spin_lock_init(&lp->spinlock);
4537 /* wavelan NET3 callbacks */
4538 dev->open = &wavelan_open;
4539 dev->stop = &wavelan_close;
4540 dev->hard_start_xmit = &wavelan_packet_xmit;
4541 dev->get_stats = &wavelan_get_stats;
4542 dev->set_multicast_list = &wavelan_set_multicast_list;
4543 #ifdef SET_MAC_ADDRESS
4544 dev->set_mac_address = &wavelan_set_mac_address;
4545 #endif /* SET_MAC_ADDRESS */
4547 /* Set the watchdog timer */
4548 dev->tx_timeout = &wavelan_watchdog;
4549 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4550 SET_ETHTOOL_OPS(dev, &ops);
4552 dev->wireless_handlers = &wavelan_handler_def;
4553 lp->wireless_data.spy_data = &lp->spy_data;
4554 dev->wireless_data = &lp->wireless_data;
4556 /* Other specific data */
4557 dev->mtu = WAVELAN_MTU;
4559 ret = wv_pcmcia_config(p_dev);
4563 ret = wv_hw_config(dev);
4566 pcmcia_disable_device(p_dev);
4572 #ifdef DEBUG_CALLBACK_TRACE
4573 printk(KERN_DEBUG "<- wavelan_attach()\n");
4579 /*------------------------------------------------------------------*/
4581 * This deletes a driver "instance". The device is de-registered with
4582 * Card Services. If it has been released, all local data structures
4583 * are freed. Otherwise, the structures will be freed when the device
4587 wavelan_detach(struct pcmcia_device *link)
4589 #ifdef DEBUG_CALLBACK_TRACE
4590 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4593 /* Some others haven't done their job : give them another chance */
4594 wv_pcmcia_release(link);
4599 struct net_device * dev = (struct net_device *) link->priv;
4601 /* Remove ourselves from the kernel list of ethernet devices */
4602 /* Warning : can't be called from interrupt, timer or wavelan_close() */
4604 unregister_netdev(dev);
4605 link->dev_node = NULL;
4606 ((net_local *)netdev_priv(dev))->link = NULL;
4607 ((net_local *)netdev_priv(dev))->dev = NULL;
4611 #ifdef DEBUG_CALLBACK_TRACE
4612 printk(KERN_DEBUG "<- wavelan_detach()\n");
4616 static int wavelan_suspend(struct pcmcia_device *link)
4618 struct net_device * dev = (struct net_device *) link->priv;
4620 /* NB: wavelan_close will be called, but too late, so we are
4621 * obliged to close nicely the wavelan here. David, could you
4622 * close the device before suspending them ? And, by the way,
4623 * could you, on resume, add a "route add -net ..." after the
4624 * ifconfig up ? Thanks... */
4626 /* Stop receiving new messages and wait end of transmission */
4630 netif_device_detach(dev);
4632 /* Power down the module */
4633 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
4638 static int wavelan_resume(struct pcmcia_device *link)
4640 struct net_device * dev = (struct net_device *) link->priv;
4644 netif_device_attach(dev);
4651 static struct pcmcia_device_id wavelan_ids[] = {
4652 PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
4653 PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
4654 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/PCMCIA", 0x23eb9949, 0x1bc50975),
4655 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/PCMCIA", 0x24358cd4, 0x1bc50975),
4658 MODULE_DEVICE_TABLE(pcmcia, wavelan_ids);
4660 static struct pcmcia_driver wavelan_driver = {
4661 .owner = THIS_MODULE,
4663 .name = "wavelan_cs",
4665 .probe = wavelan_probe,
4666 .remove = wavelan_detach,
4667 .id_table = wavelan_ids,
4668 .suspend = wavelan_suspend,
4669 .resume = wavelan_resume,
4673 init_wavelan_cs(void)
4675 return pcmcia_register_driver(&wavelan_driver);
4679 exit_wavelan_cs(void)
4681 pcmcia_unregister_driver(&wavelan_driver);
4684 module_init(init_wavelan_cs);
4685 module_exit(exit_wavelan_cs);