[ARM] Fix arch-realview/system.h to use __io_address()
[linux-2.6/linux-loongson.git] / drivers / net / wireless / wavelan_cs.c
blobc822cad3333f3bba7cff1cd3608cfa8455430132
1 /*
2 * Wavelan Pcmcia driver
4 * Jean II - HPLB '96
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.
25 #endif
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 ****************************************************************************
41 * Copyright 1995
42 * Anthony D. Joseph
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 #ifdef STRUCT_CHECK
75 /*------------------------------------------------------------------*/
77 * Sanity routine to verify the sizes of the various WaveLAN interface
78 * structures.
80 static char *
81 wv_structuct_check(void)
83 #define SC(t,s,n) if (sizeof(t) != s) return(n);
85 SC(psa_t, PSA_SIZE, "psa_t");
86 SC(mmw_t, MMW_SIZE, "mmw_t");
87 SC(mmr_t, MMR_SIZE, "mmr_t");
89 #undef SC
91 return((char *) NULL);
92 } /* wv_structuct_check */
93 #endif /* STRUCT_CHECK */
95 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
97 * Useful subroutines to manage the modem of the wavelan
100 /*------------------------------------------------------------------*/
102 * Read from card's Host Adaptor Status Register.
104 static inline u_char
105 hasr_read(u_long base)
107 return(inb(HASR(base)));
108 } /* hasr_read */
110 /*------------------------------------------------------------------*/
112 * Write to card's Host Adapter Command Register.
114 static inline void
115 hacr_write(u_long base,
116 u_char hacr)
118 outb(hacr, HACR(base));
119 } /* hacr_write */
121 /*------------------------------------------------------------------*/
123 * Write to card's Host Adapter Command Register. Include a delay for
124 * those times when it is needed.
126 static inline void
127 hacr_write_slow(u_long base,
128 u_char hacr)
130 hacr_write(base, hacr);
131 /* delay might only be needed sometimes */
132 mdelay(1);
133 } /* hacr_write_slow */
135 /*------------------------------------------------------------------*/
137 * Read the Parameter Storage Area from the WaveLAN card's memory
139 static void
140 psa_read(struct net_device * dev,
141 int o, /* offset in PSA */
142 u_char * b, /* buffer to fill */
143 int n) /* size to read */
145 net_local *lp = netdev_priv(dev);
146 u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
148 while(n-- > 0)
150 *b++ = readb(ptr);
151 /* Due to a lack of address decode pins, the WaveLAN PCMCIA card
152 * only supports reading even memory addresses. That means the
153 * increment here MUST be two.
154 * Because of that, we can't use memcpy_fromio()...
156 ptr += 2;
158 } /* psa_read */
160 /*------------------------------------------------------------------*/
162 * Write the Paramter Storage Area to the WaveLAN card's memory
164 static void
165 psa_write(struct net_device * dev,
166 int o, /* Offset in psa */
167 u_char * b, /* Buffer in memory */
168 int n) /* Length of buffer */
170 net_local *lp = netdev_priv(dev);
171 u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
172 int count = 0;
173 kio_addr_t base = dev->base_addr;
174 /* As there seem to have no flag PSA_BUSY as in the ISA model, we are
175 * oblige to verify this address to know when the PSA is ready... */
176 volatile u_char __iomem *verify = lp->mem + PSA_ADDR +
177 (psaoff(0, psa_comp_number) << 1);
179 /* Authorize writting to PSA */
180 hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN);
182 while(n-- > 0)
184 /* write to PSA */
185 writeb(*b++, ptr);
186 ptr += 2;
188 /* I don't have the spec, so I don't know what the correct
189 * sequence to write is. This hack seem to work for me... */
190 count = 0;
191 while((readb(verify) != PSA_COMP_PCMCIA_915) && (count++ < 100))
192 mdelay(1);
195 /* Put the host interface back in standard state */
196 hacr_write(base, HACR_DEFAULT);
197 } /* psa_write */
199 #ifdef SET_PSA_CRC
200 /*------------------------------------------------------------------*/
202 * Calculate the PSA CRC
203 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
204 * NOTE: By specifying a length including the CRC position the
205 * returned value should be zero. (i.e. a correct checksum in the PSA)
207 * The Windows drivers don't use the CRC, but the AP and the PtP tool
208 * depend on it.
210 static u_short
211 psa_crc(unsigned char * psa, /* The PSA */
212 int size) /* Number of short for CRC */
214 int byte_cnt; /* Loop on the PSA */
215 u_short crc_bytes = 0; /* Data in the PSA */
216 int bit_cnt; /* Loop on the bits of the short */
218 for(byte_cnt = 0; byte_cnt < size; byte_cnt++ )
220 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
222 for(bit_cnt = 1; bit_cnt < 9; bit_cnt++ )
224 if(crc_bytes & 0x0001)
225 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
226 else
227 crc_bytes >>= 1 ;
231 return crc_bytes;
232 } /* psa_crc */
233 #endif /* SET_PSA_CRC */
235 /*------------------------------------------------------------------*/
237 * update the checksum field in the Wavelan's PSA
239 static void
240 update_psa_checksum(struct net_device * dev)
242 #ifdef SET_PSA_CRC
243 psa_t psa;
244 u_short crc;
246 /* read the parameter storage area */
247 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
249 /* update the checksum */
250 crc = psa_crc((unsigned char *) &psa,
251 sizeof(psa) - sizeof(psa.psa_crc[0]) - sizeof(psa.psa_crc[1])
252 - sizeof(psa.psa_crc_status));
254 psa.psa_crc[0] = crc & 0xFF;
255 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
257 /* Write it ! */
258 psa_write(dev, (char *)&psa.psa_crc - (char *)&psa,
259 (unsigned char *)&psa.psa_crc, 2);
261 #ifdef DEBUG_IOCTL_INFO
262 printk (KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
263 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
265 /* Check again (luxury !) */
266 crc = psa_crc((unsigned char *) &psa,
267 sizeof(psa) - sizeof(psa.psa_crc_status));
269 if(crc != 0)
270 printk(KERN_WARNING "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", dev->name);
271 #endif /* DEBUG_IOCTL_INFO */
272 #endif /* SET_PSA_CRC */
273 } /* update_psa_checksum */
275 /*------------------------------------------------------------------*/
277 * Write 1 byte to the MMC.
279 static inline void
280 mmc_out(u_long base,
281 u_short o,
282 u_char d)
284 int count = 0;
286 /* Wait for MMC to go idle */
287 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
288 udelay(10);
290 outb((u_char)((o << 1) | MMR_MMI_WR), MMR(base));
291 outb(d, MMD(base));
294 /*------------------------------------------------------------------*/
296 * Routine to write bytes to the Modem Management Controller.
297 * We start by the end because it is the way it should be !
299 static inline void
300 mmc_write(u_long base,
301 u_char o,
302 u_char * b,
303 int n)
305 o += n;
306 b += n;
308 while(n-- > 0 )
309 mmc_out(base, --o, *(--b));
310 } /* mmc_write */
312 /*------------------------------------------------------------------*/
314 * Read 1 byte from the MMC.
315 * Optimised version for 1 byte, avoid using memory...
317 static inline u_char
318 mmc_in(u_long base,
319 u_short o)
321 int count = 0;
323 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
324 udelay(10);
325 outb(o << 1, MMR(base)); /* Set the read address */
327 outb(0, MMD(base)); /* Required dummy write */
329 while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
330 udelay(10);
331 return (u_char) (inb(MMD(base))); /* Now do the actual read */
334 /*------------------------------------------------------------------*/
336 * Routine to read bytes from the Modem Management Controller.
337 * The implementation is complicated by a lack of address lines,
338 * which prevents decoding of the low-order bit.
339 * (code has just been moved in the above function)
340 * We start by the end because it is the way it should be !
342 static inline void
343 mmc_read(u_long base,
344 u_char o,
345 u_char * b,
346 int n)
348 o += n;
349 b += n;
351 while(n-- > 0)
352 *(--b) = mmc_in(base, --o);
353 } /* mmc_read */
355 /*------------------------------------------------------------------*/
357 * Get the type of encryption available...
359 static inline int
360 mmc_encr(u_long base) /* i/o port of the card */
362 int temp;
364 temp = mmc_in(base, mmroff(0, mmr_des_avail));
365 if((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
366 return 0;
367 else
368 return temp;
371 /*------------------------------------------------------------------*/
373 * Wait for the frequency EEprom to complete a command...
374 * I hope this one will be optimally inlined...
376 static inline void
377 fee_wait(u_long base, /* i/o port of the card */
378 int delay, /* Base delay to wait for */
379 int number) /* Number of time to wait */
381 int count = 0; /* Wait only a limited time */
383 while((count++ < number) &&
384 (mmc_in(base, mmroff(0, mmr_fee_status)) & MMR_FEE_STATUS_BUSY))
385 udelay(delay);
388 /*------------------------------------------------------------------*/
390 * Read bytes from the Frequency EEprom (frequency select cards).
392 static void
393 fee_read(u_long base, /* i/o port of the card */
394 u_short o, /* destination offset */
395 u_short * b, /* data buffer */
396 int n) /* number of registers */
398 b += n; /* Position at the end of the area */
400 /* Write the address */
401 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
403 /* Loop on all buffer */
404 while(n-- > 0)
406 /* Write the read command */
407 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_READ);
409 /* Wait until EEprom is ready (should be quick !) */
410 fee_wait(base, 10, 100);
412 /* Read the value */
413 *--b = ((mmc_in(base, mmroff(0, mmr_fee_data_h)) << 8) |
414 mmc_in(base, mmroff(0, mmr_fee_data_l)));
419 /*------------------------------------------------------------------*/
421 * Write bytes from the Frequency EEprom (frequency select cards).
422 * This is a bit complicated, because the frequency eeprom has to
423 * be unprotected and the write enabled.
424 * Jean II
426 static void
427 fee_write(u_long base, /* i/o port of the card */
428 u_short o, /* destination offset */
429 u_short * b, /* data buffer */
430 int n) /* number of registers */
432 b += n; /* Position at the end of the area */
434 #ifdef EEPROM_IS_PROTECTED /* disabled */
435 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
436 /* Ask to read the protected register */
437 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
439 fee_wait(base, 10, 100);
441 /* Read the protected register */
442 printk("Protected 2 : %02X-%02X\n",
443 mmc_in(base, mmroff(0, mmr_fee_data_h)),
444 mmc_in(base, mmroff(0, mmr_fee_data_l)));
445 #endif /* DOESNT_SEEM_TO_WORK */
447 /* Enable protected register */
448 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
449 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
451 fee_wait(base, 10, 100);
453 /* Unprotect area */
454 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n);
455 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
456 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
457 /* Or use : */
458 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
459 #endif /* DOESNT_SEEM_TO_WORK */
461 fee_wait(base, 10, 100);
462 #endif /* EEPROM_IS_PROTECTED */
464 /* Write enable */
465 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
466 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
468 fee_wait(base, 10, 100);
470 /* Write the EEprom address */
471 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
473 /* Loop on all buffer */
474 while(n-- > 0)
476 /* Write the value */
477 mmc_out(base, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
478 mmc_out(base, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
480 /* Write the write command */
481 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WRITE);
483 /* Wavelan doc says : wait at least 10 ms for EEBUSY = 0 */
484 mdelay(10);
485 fee_wait(base, 10, 100);
488 /* Write disable */
489 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
490 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
492 fee_wait(base, 10, 100);
494 #ifdef EEPROM_IS_PROTECTED /* disabled */
495 /* Reprotect EEprom */
496 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x00);
497 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
499 fee_wait(base, 10, 100);
500 #endif /* EEPROM_IS_PROTECTED */
503 /******************* WaveLAN Roaming routines... ********************/
505 #ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */
507 static unsigned char WAVELAN_BEACON_ADDRESS[] = {0x09,0x00,0x0e,0x20,0x03,0x00};
509 static void wv_roam_init(struct net_device *dev)
511 net_local *lp= netdev_priv(dev);
513 /* Do not remove this unless you have a good reason */
514 printk(KERN_NOTICE "%s: Warning, you have enabled roaming on"
515 " device %s !\n", dev->name, dev->name);
516 printk(KERN_NOTICE "Roaming is currently an experimental unsupported feature"
517 " of the Wavelan driver.\n");
518 printk(KERN_NOTICE "It may work, but may also make the driver behave in"
519 " erratic ways or crash.\n");
521 lp->wavepoint_table.head=NULL; /* Initialise WavePoint table */
522 lp->wavepoint_table.num_wavepoints=0;
523 lp->wavepoint_table.locked=0;
524 lp->curr_point=NULL; /* No default WavePoint */
525 lp->cell_search=0;
527 lp->cell_timer.data=(long)lp; /* Start cell expiry timer */
528 lp->cell_timer.function=wl_cell_expiry;
529 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
530 add_timer(&lp->cell_timer);
532 wv_nwid_filter(NWID_PROMISC,lp) ; /* Enter NWID promiscuous mode */
533 /* to build up a good WavePoint */
534 /* table... */
535 printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name);
538 static void wv_roam_cleanup(struct net_device *dev)
540 wavepoint_history *ptr,*old_ptr;
541 net_local *lp= netdev_priv(dev);
543 printk(KERN_DEBUG "WaveLAN: Roaming Disabled on device %s\n",dev->name);
545 /* Fixme : maybe we should check that the timer exist before deleting it */
546 del_timer(&lp->cell_timer); /* Remove cell expiry timer */
547 ptr=lp->wavepoint_table.head; /* Clear device's WavePoint table */
548 while(ptr!=NULL)
550 old_ptr=ptr;
551 ptr=ptr->next;
552 wl_del_wavepoint(old_ptr,lp);
556 /* Enable/Disable NWID promiscuous mode on a given device */
557 static void wv_nwid_filter(unsigned char mode, net_local *lp)
559 mm_t m;
560 unsigned long flags;
562 #ifdef WAVELAN_ROAMING_DEBUG
563 printk(KERN_DEBUG "WaveLAN: NWID promisc %s, device %s\n",(mode==NWID_PROMISC) ? "on" : "off", lp->dev->name);
564 #endif
566 /* Disable interrupts & save flags */
567 spin_lock_irqsave(&lp->spinlock, flags);
569 m.w.mmw_loopt_sel = (mode==NWID_PROMISC) ? MMW_LOOPT_SEL_DIS_NWID : 0x00;
570 mmc_write(lp->dev->base_addr, (char *)&m.w.mmw_loopt_sel - (char *)&m, (unsigned char *)&m.w.mmw_loopt_sel, 1);
572 if(mode==NWID_PROMISC)
573 lp->cell_search=1;
574 else
575 lp->cell_search=0;
577 /* ReEnable interrupts & restore flags */
578 spin_unlock_irqrestore(&lp->spinlock, flags);
581 /* Find a record in the WavePoint table matching a given NWID */
582 static wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp)
584 wavepoint_history *ptr=lp->wavepoint_table.head;
586 while(ptr!=NULL){
587 if(ptr->nwid==nwid)
588 return ptr;
589 ptr=ptr->next;
591 return NULL;
594 /* Create a new wavepoint table entry */
595 static wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp)
597 wavepoint_history *new_wavepoint;
599 #ifdef WAVELAN_ROAMING_DEBUG
600 printk(KERN_DEBUG "WaveLAN: New Wavepoint, NWID:%.4X\n",nwid);
601 #endif
603 if(lp->wavepoint_table.num_wavepoints==MAX_WAVEPOINTS)
604 return NULL;
606 new_wavepoint=(wavepoint_history *) kmalloc(sizeof(wavepoint_history),GFP_ATOMIC);
607 if(new_wavepoint==NULL)
608 return NULL;
610 new_wavepoint->nwid=nwid; /* New WavePoints NWID */
611 new_wavepoint->average_fast=0; /* Running Averages..*/
612 new_wavepoint->average_slow=0;
613 new_wavepoint->qualptr=0; /* Start of ringbuffer */
614 new_wavepoint->last_seq=seq-1; /* Last sequence no.seen */
615 memset(new_wavepoint->sigqual,0,WAVEPOINT_HISTORY);/* Empty ringbuffer */
617 new_wavepoint->next=lp->wavepoint_table.head;/* Add to wavepoint table */
618 new_wavepoint->prev=NULL;
620 if(lp->wavepoint_table.head!=NULL)
621 lp->wavepoint_table.head->prev=new_wavepoint;
623 lp->wavepoint_table.head=new_wavepoint;
625 lp->wavepoint_table.num_wavepoints++; /* no. of visible wavepoints */
627 return new_wavepoint;
630 /* Remove a wavepoint entry from WavePoint table */
631 static void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp)
633 if(wavepoint==NULL)
634 return;
636 if(lp->curr_point==wavepoint)
637 lp->curr_point=NULL;
639 if(wavepoint->prev!=NULL)
640 wavepoint->prev->next=wavepoint->next;
642 if(wavepoint->next!=NULL)
643 wavepoint->next->prev=wavepoint->prev;
645 if(lp->wavepoint_table.head==wavepoint)
646 lp->wavepoint_table.head=wavepoint->next;
648 lp->wavepoint_table.num_wavepoints--;
649 kfree(wavepoint);
652 /* Timer callback function - checks WavePoint table for stale entries */
653 static void wl_cell_expiry(unsigned long data)
655 net_local *lp=(net_local *)data;
656 wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point;
658 #if WAVELAN_ROAMING_DEBUG > 1
659 printk(KERN_DEBUG "WaveLAN: Wavepoint timeout, dev %s\n",lp->dev->name);
660 #endif
662 if(lp->wavepoint_table.locked)
664 #if WAVELAN_ROAMING_DEBUG > 1
665 printk(KERN_DEBUG "WaveLAN: Wavepoint table locked...\n");
666 #endif
668 lp->cell_timer.expires=jiffies+1; /* If table in use, come back later */
669 add_timer(&lp->cell_timer);
670 return;
673 while(wavepoint!=NULL)
675 if(time_after(jiffies, wavepoint->last_seen + CELL_TIMEOUT))
677 #ifdef WAVELAN_ROAMING_DEBUG
678 printk(KERN_DEBUG "WaveLAN: Bye bye %.4X\n",wavepoint->nwid);
679 #endif
681 old_point=wavepoint;
682 wavepoint=wavepoint->next;
683 wl_del_wavepoint(old_point,lp);
685 else
686 wavepoint=wavepoint->next;
688 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
689 add_timer(&lp->cell_timer);
692 /* Update SNR history of a wavepoint */
693 static void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq)
695 int i=0,num_missed=0,ptr=0;
696 int average_fast=0,average_slow=0;
698 num_missed=(seq-wavepoint->last_seq)%WAVEPOINT_HISTORY;/* Have we missed
699 any beacons? */
700 if(num_missed)
701 for(i=0;i<num_missed;i++)
703 wavepoint->sigqual[wavepoint->qualptr++]=0; /* If so, enter them as 0's */
704 wavepoint->qualptr %=WAVEPOINT_HISTORY; /* in the ringbuffer. */
706 wavepoint->last_seen=jiffies; /* Add beacon to history */
707 wavepoint->last_seq=seq;
708 wavepoint->sigqual[wavepoint->qualptr++]=sigqual;
709 wavepoint->qualptr %=WAVEPOINT_HISTORY;
710 ptr=(wavepoint->qualptr-WAVEPOINT_FAST_HISTORY+WAVEPOINT_HISTORY)%WAVEPOINT_HISTORY;
712 for(i=0;i<WAVEPOINT_FAST_HISTORY;i++) /* Update running averages */
714 average_fast+=wavepoint->sigqual[ptr++];
715 ptr %=WAVEPOINT_HISTORY;
718 average_slow=average_fast;
719 for(i=WAVEPOINT_FAST_HISTORY;i<WAVEPOINT_HISTORY;i++)
721 average_slow+=wavepoint->sigqual[ptr++];
722 ptr %=WAVEPOINT_HISTORY;
725 wavepoint->average_fast=average_fast/WAVEPOINT_FAST_HISTORY;
726 wavepoint->average_slow=average_slow/WAVEPOINT_HISTORY;
729 /* Perform a handover to a new WavePoint */
730 static void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp)
732 kio_addr_t base = lp->dev->base_addr;
733 mm_t m;
734 unsigned long flags;
736 if(wavepoint==lp->curr_point) /* Sanity check... */
738 wv_nwid_filter(!NWID_PROMISC,lp);
739 return;
742 #ifdef WAVELAN_ROAMING_DEBUG
743 printk(KERN_DEBUG "WaveLAN: Doing handover to %.4X, dev %s\n",wavepoint->nwid,lp->dev->name);
744 #endif
746 /* Disable interrupts & save flags */
747 spin_lock_irqsave(&lp->spinlock, flags);
749 m.w.mmw_netw_id_l = wavepoint->nwid & 0xFF;
750 m.w.mmw_netw_id_h = (wavepoint->nwid & 0xFF00) >> 8;
752 mmc_write(base, (char *)&m.w.mmw_netw_id_l - (char *)&m, (unsigned char *)&m.w.mmw_netw_id_l, 2);
754 /* ReEnable interrupts & restore flags */
755 spin_unlock_irqrestore(&lp->spinlock, flags);
757 wv_nwid_filter(!NWID_PROMISC,lp);
758 lp->curr_point=wavepoint;
761 /* Called when a WavePoint beacon is received */
762 static inline void wl_roam_gather(struct net_device * dev,
763 u_char * hdr, /* Beacon header */
764 u_char * stats) /* SNR, Signal quality
765 of packet */
767 wavepoint_beacon *beacon= (wavepoint_beacon *)hdr; /* Rcvd. Beacon */
768 unsigned short nwid=ntohs(beacon->nwid);
769 unsigned short sigqual=stats[2] & MMR_SGNL_QUAL; /* SNR of beacon */
770 wavepoint_history *wavepoint=NULL; /* WavePoint table entry */
771 net_local *lp = netdev_priv(dev); /* Device info */
773 #ifdef I_NEED_THIS_FEATURE
774 /* Some people don't need this, some other may need it */
775 nwid=nwid^ntohs(beacon->domain_id);
776 #endif
778 #if WAVELAN_ROAMING_DEBUG > 1
779 printk(KERN_DEBUG "WaveLAN: beacon, dev %s:\n",dev->name);
780 printk(KERN_DEBUG "Domain: %.4X NWID: %.4X SigQual=%d\n",ntohs(beacon->domain_id),nwid,sigqual);
781 #endif
783 lp->wavepoint_table.locked=1; /* <Mutex> */
785 wavepoint=wl_roam_check(nwid,lp); /* Find WavePoint table entry */
786 if(wavepoint==NULL) /* If no entry, Create a new one... */
788 wavepoint=wl_new_wavepoint(nwid,beacon->seq,lp);
789 if(wavepoint==NULL)
790 goto out;
792 if(lp->curr_point==NULL) /* If this is the only WavePoint, */
793 wv_roam_handover(wavepoint, lp); /* Jump on it! */
795 wl_update_history(wavepoint, sigqual, beacon->seq); /* Update SNR history
796 stats. */
798 if(lp->curr_point->average_slow < SEARCH_THRESH_LOW) /* If our current */
799 if(!lp->cell_search) /* WavePoint is getting faint, */
800 wv_nwid_filter(NWID_PROMISC,lp); /* start looking for a new one */
802 if(wavepoint->average_slow >
803 lp->curr_point->average_slow + WAVELAN_ROAMING_DELTA)
804 wv_roam_handover(wavepoint, lp); /* Handover to a better WavePoint */
806 if(lp->curr_point->average_slow > SEARCH_THRESH_HIGH) /* If our SNR is */
807 if(lp->cell_search) /* getting better, drop out of cell search mode */
808 wv_nwid_filter(!NWID_PROMISC,lp);
810 out:
811 lp->wavepoint_table.locked=0; /* </MUTEX> :-) */
814 /* Test this MAC frame a WavePoint beacon */
815 static inline int WAVELAN_BEACON(unsigned char *data)
817 wavepoint_beacon *beacon= (wavepoint_beacon *)data;
818 static wavepoint_beacon beacon_template={0xaa,0xaa,0x03,0x08,0x00,0x0e,0x20,0x03,0x00};
820 if(memcmp(beacon,&beacon_template,9)==0)
821 return 1;
822 else
823 return 0;
825 #endif /* WAVELAN_ROAMING */
827 /************************ I82593 SUBROUTINES *************************/
829 * Useful subroutines to manage the Ethernet controller
832 /*------------------------------------------------------------------*/
834 * Routine to synchronously send a command to the i82593 chip.
835 * Should be called with interrupts disabled.
836 * (called by wv_packet_write(), wv_ru_stop(), wv_ru_start(),
837 * wv_82593_config() & wv_diag())
839 static int
840 wv_82593_cmd(struct net_device * dev,
841 char * str,
842 int cmd,
843 int result)
845 kio_addr_t base = dev->base_addr;
846 int status;
847 int wait_completed;
848 long spin;
850 /* Spin until the chip finishes executing its current command (if any) */
851 spin = 1000;
854 /* Time calibration of the loop */
855 udelay(10);
857 /* Read the interrupt register */
858 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
859 status = inb(LCSR(base));
861 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
863 /* If the interrupt hasn't be posted */
864 if(spin <= 0)
866 #ifdef DEBUG_INTERRUPT_ERROR
867 printk(KERN_INFO "wv_82593_cmd: %s timeout (previous command), status 0x%02x\n",
868 str, status);
869 #endif
870 return(FALSE);
873 /* Issue the command to the controller */
874 outb(cmd, LCCR(base));
876 /* If we don't have to check the result of the command
877 * Note : this mean that the irq handler will deal with that */
878 if(result == SR0_NO_RESULT)
879 return(TRUE);
881 /* We are waiting for command completion */
882 wait_completed = TRUE;
884 /* Busy wait while the LAN controller executes the command. */
885 spin = 1000;
888 /* Time calibration of the loop */
889 udelay(10);
891 /* Read the interrupt register */
892 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
893 status = inb(LCSR(base));
895 /* Check if there was an interrupt posted */
896 if((status & SR0_INTERRUPT))
898 /* Acknowledge the interrupt */
899 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
901 /* Check if interrupt is a command completion */
902 if(((status & SR0_BOTH_RX_TX) != SR0_BOTH_RX_TX) &&
903 ((status & SR0_BOTH_RX_TX) != 0x0) &&
904 !(status & SR0_RECEPTION))
906 /* Signal command completion */
907 wait_completed = FALSE;
909 else
911 /* Note : Rx interrupts will be handled later, because we can
912 * handle multiple Rx packets at once */
913 #ifdef DEBUG_INTERRUPT_INFO
914 printk(KERN_INFO "wv_82593_cmd: not our interrupt\n");
915 #endif
919 while(wait_completed && (spin-- > 0));
921 /* If the interrupt hasn't be posted */
922 if(wait_completed)
924 #ifdef DEBUG_INTERRUPT_ERROR
925 printk(KERN_INFO "wv_82593_cmd: %s timeout, status 0x%02x\n",
926 str, status);
927 #endif
928 return(FALSE);
931 /* Check the return code returned by the card (see above) against
932 * the expected return code provided by the caller */
933 if((status & SR0_EVENT_MASK) != result)
935 #ifdef DEBUG_INTERRUPT_ERROR
936 printk(KERN_INFO "wv_82593_cmd: %s failed, status = 0x%x\n",
937 str, status);
938 #endif
939 return(FALSE);
942 return(TRUE);
943 } /* wv_82593_cmd */
945 /*------------------------------------------------------------------*/
947 * This routine does a 593 op-code number 7, and obtains the diagnose
948 * status for the WaveLAN.
950 static inline int
951 wv_diag(struct net_device * dev)
953 int ret = FALSE;
955 if(wv_82593_cmd(dev, "wv_diag(): diagnose",
956 OP0_DIAGNOSE, SR0_DIAGNOSE_PASSED))
957 ret = TRUE;
959 #ifdef DEBUG_CONFIG_ERRORS
960 printk(KERN_INFO "wavelan_cs: i82593 Self Test failed!\n");
961 #endif
962 return(ret);
963 } /* wv_diag */
965 /*------------------------------------------------------------------*/
967 * Routine to read len bytes from the i82593's ring buffer, starting at
968 * chip address addr. The results read from the chip are stored in buf.
969 * The return value is the address to use for next the call.
971 static int
972 read_ringbuf(struct net_device * dev,
973 int addr,
974 char * buf,
975 int len)
977 kio_addr_t base = dev->base_addr;
978 int ring_ptr = addr;
979 int chunk_len;
980 char * buf_ptr = buf;
982 /* Get all the buffer */
983 while(len > 0)
985 /* Position the Program I/O Register at the ring buffer pointer */
986 outb(ring_ptr & 0xff, PIORL(base));
987 outb(((ring_ptr >> 8) & PIORH_MASK), PIORH(base));
989 /* First, determine how much we can read without wrapping around the
990 ring buffer */
991 if((addr + len) < (RX_BASE + RX_SIZE))
992 chunk_len = len;
993 else
994 chunk_len = RX_BASE + RX_SIZE - addr;
995 insb(PIOP(base), buf_ptr, chunk_len);
996 buf_ptr += chunk_len;
997 len -= chunk_len;
998 ring_ptr = (ring_ptr - RX_BASE + chunk_len) % RX_SIZE + RX_BASE;
1000 return(ring_ptr);
1001 } /* read_ringbuf */
1003 /*------------------------------------------------------------------*/
1005 * Reconfigure the i82593, or at least ask for it...
1006 * Because wv_82593_config use the transmission buffer, we must do it
1007 * when we are sure that there is no transmission, so we do it now
1008 * or in wavelan_packet_xmit() (I can't find any better place,
1009 * wavelan_interrupt is not an option...), so you may experience
1010 * some delay sometime...
1012 static inline void
1013 wv_82593_reconfig(struct net_device * dev)
1015 net_local * lp = netdev_priv(dev);
1016 dev_link_t * link = lp->link;
1017 unsigned long flags;
1019 /* Arm the flag, will be cleard in wv_82593_config() */
1020 lp->reconfig_82593 = TRUE;
1022 /* Check if we can do it now ! */
1023 if((link->open) && (netif_running(dev)) && !(netif_queue_stopped(dev)))
1025 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
1026 wv_82593_config(dev);
1027 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
1029 else
1031 #ifdef DEBUG_IOCTL_INFO
1032 printk(KERN_DEBUG
1033 "%s: wv_82593_reconfig(): delayed (state = %lX, link = %d)\n",
1034 dev->name, dev->state, link->open);
1035 #endif
1039 /********************* DEBUG & INFO SUBROUTINES *********************/
1041 * This routines are used in the code to show debug informations.
1042 * Most of the time, it dump the content of hardware structures...
1045 #ifdef DEBUG_PSA_SHOW
1046 /*------------------------------------------------------------------*/
1048 * Print the formatted contents of the Parameter Storage Area.
1050 static void
1051 wv_psa_show(psa_t * p)
1053 printk(KERN_DEBUG "##### wavelan psa contents: #####\n");
1054 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
1055 p->psa_io_base_addr_1,
1056 p->psa_io_base_addr_2,
1057 p->psa_io_base_addr_3,
1058 p->psa_io_base_addr_4);
1059 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
1060 p->psa_rem_boot_addr_1,
1061 p->psa_rem_boot_addr_2,
1062 p->psa_rem_boot_addr_3);
1063 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
1064 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
1065 #ifdef DEBUG_SHOW_UNUSED
1066 printk(KERN_DEBUG "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1067 p->psa_unused0[0],
1068 p->psa_unused0[1],
1069 p->psa_unused0[2],
1070 p->psa_unused0[3],
1071 p->psa_unused0[4],
1072 p->psa_unused0[5],
1073 p->psa_unused0[6]);
1074 #endif /* DEBUG_SHOW_UNUSED */
1075 printk(KERN_DEBUG "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
1076 p->psa_univ_mac_addr[0],
1077 p->psa_univ_mac_addr[1],
1078 p->psa_univ_mac_addr[2],
1079 p->psa_univ_mac_addr[3],
1080 p->psa_univ_mac_addr[4],
1081 p->psa_univ_mac_addr[5]);
1082 printk(KERN_DEBUG "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
1083 p->psa_local_mac_addr[0],
1084 p->psa_local_mac_addr[1],
1085 p->psa_local_mac_addr[2],
1086 p->psa_local_mac_addr[3],
1087 p->psa_local_mac_addr[4],
1088 p->psa_local_mac_addr[5]);
1089 printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel);
1090 printk("psa_comp_number: %d, ", p->psa_comp_number);
1091 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
1092 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
1093 p->psa_feature_select);
1094 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
1095 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
1096 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
1097 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]);
1098 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
1099 printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select);
1100 printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1101 p->psa_encryption_key[0],
1102 p->psa_encryption_key[1],
1103 p->psa_encryption_key[2],
1104 p->psa_encryption_key[3],
1105 p->psa_encryption_key[4],
1106 p->psa_encryption_key[5],
1107 p->psa_encryption_key[6],
1108 p->psa_encryption_key[7]);
1109 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
1110 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
1111 p->psa_call_code[0]);
1112 printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1113 p->psa_call_code[0],
1114 p->psa_call_code[1],
1115 p->psa_call_code[2],
1116 p->psa_call_code[3],
1117 p->psa_call_code[4],
1118 p->psa_call_code[5],
1119 p->psa_call_code[6],
1120 p->psa_call_code[7]);
1121 #ifdef DEBUG_SHOW_UNUSED
1122 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
1123 p->psa_reserved[0],
1124 p->psa_reserved[1],
1125 p->psa_reserved[2],
1126 p->psa_reserved[3]);
1127 #endif /* DEBUG_SHOW_UNUSED */
1128 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
1129 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
1130 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
1131 } /* wv_psa_show */
1132 #endif /* DEBUG_PSA_SHOW */
1134 #ifdef DEBUG_MMC_SHOW
1135 /*------------------------------------------------------------------*/
1137 * Print the formatted status of the Modem Management Controller.
1138 * This function need to be completed...
1140 static void
1141 wv_mmc_show(struct net_device * dev)
1143 kio_addr_t base = dev->base_addr;
1144 net_local * lp = netdev_priv(dev);
1145 mmr_t m;
1147 /* Basic check */
1148 if(hasr_read(base) & HASR_NO_CLK)
1150 printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n",
1151 dev->name);
1152 return;
1155 spin_lock_irqsave(&lp->spinlock, flags);
1157 /* Read the mmc */
1158 mmc_out(base, mmwoff(0, mmw_freeze), 1);
1159 mmc_read(base, 0, (u_char *)&m, sizeof(m));
1160 mmc_out(base, mmwoff(0, mmw_freeze), 0);
1162 /* Don't forget to update statistics */
1163 lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
1165 spin_unlock_irqrestore(&lp->spinlock, flags);
1167 printk(KERN_DEBUG "##### wavelan modem status registers: #####\n");
1168 #ifdef DEBUG_SHOW_UNUSED
1169 printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1170 m.mmr_unused0[0],
1171 m.mmr_unused0[1],
1172 m.mmr_unused0[2],
1173 m.mmr_unused0[3],
1174 m.mmr_unused0[4],
1175 m.mmr_unused0[5],
1176 m.mmr_unused0[6],
1177 m.mmr_unused0[7]);
1178 #endif /* DEBUG_SHOW_UNUSED */
1179 printk(KERN_DEBUG "Encryption algorythm: %02X - Status: %02X\n",
1180 m.mmr_des_avail, m.mmr_des_status);
1181 #ifdef DEBUG_SHOW_UNUSED
1182 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1183 m.mmr_unused1[0],
1184 m.mmr_unused1[1],
1185 m.mmr_unused1[2],
1186 m.mmr_unused1[3],
1187 m.mmr_unused1[4]);
1188 #endif /* DEBUG_SHOW_UNUSED */
1189 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1190 m.mmr_dce_status,
1191 (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"",
1192 (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1193 "loop test indicated," : "",
1194 (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "",
1195 (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1196 "jabber timer expired," : "");
1197 printk(KERN_DEBUG "Dsp ID: %02X\n",
1198 m.mmr_dsp_id);
1199 #ifdef DEBUG_SHOW_UNUSED
1200 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1201 m.mmr_unused2[0],
1202 m.mmr_unused2[1]);
1203 #endif /* DEBUG_SHOW_UNUSED */
1204 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1205 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1206 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1207 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1208 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1209 (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below");
1210 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1211 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1212 (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg");
1213 printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL,
1214 (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update");
1215 printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1216 (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0");
1217 #ifdef DEBUG_SHOW_UNUSED
1218 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1219 #endif /* DEBUG_SHOW_UNUSED */
1220 } /* wv_mmc_show */
1221 #endif /* DEBUG_MMC_SHOW */
1223 #ifdef DEBUG_I82593_SHOW
1224 /*------------------------------------------------------------------*/
1226 * Print the formatted status of the i82593's receive unit.
1228 static void
1229 wv_ru_show(struct net_device * dev)
1231 net_local *lp = netdev_priv(dev);
1233 printk(KERN_DEBUG "##### wavelan i82593 receiver status: #####\n");
1234 printk(KERN_DEBUG "ru: rfp %d stop %d", lp->rfp, lp->stop);
1236 * Not implemented yet...
1238 printk("\n");
1239 } /* wv_ru_show */
1240 #endif /* DEBUG_I82593_SHOW */
1242 #ifdef DEBUG_DEVICE_SHOW
1243 /*------------------------------------------------------------------*/
1245 * Print the formatted status of the WaveLAN PCMCIA device driver.
1247 static void
1248 wv_dev_show(struct net_device * dev)
1250 printk(KERN_DEBUG "dev:");
1251 printk(" state=%lX,", dev->state);
1252 printk(" trans_start=%ld,", dev->trans_start);
1253 printk(" flags=0x%x,", dev->flags);
1254 printk("\n");
1255 } /* wv_dev_show */
1257 /*------------------------------------------------------------------*/
1259 * Print the formatted status of the WaveLAN PCMCIA device driver's
1260 * private information.
1262 static void
1263 wv_local_show(struct net_device * dev)
1265 net_local *lp = netdev_priv(dev);
1267 printk(KERN_DEBUG "local:");
1269 * Not implemented yet...
1271 printk("\n");
1272 } /* wv_local_show */
1273 #endif /* DEBUG_DEVICE_SHOW */
1275 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1276 /*------------------------------------------------------------------*/
1278 * Dump packet header (and content if necessary) on the screen
1280 static inline void
1281 wv_packet_info(u_char * p, /* Packet to dump */
1282 int length, /* Length of the packet */
1283 char * msg1, /* Name of the device */
1284 char * msg2) /* Name of the function */
1286 int i;
1287 int maxi;
1289 printk(KERN_DEBUG "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1290 msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1291 printk(KERN_DEBUG "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1292 msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13]);
1294 #ifdef DEBUG_PACKET_DUMP
1296 printk(KERN_DEBUG "data=\"");
1298 if((maxi = length) > DEBUG_PACKET_DUMP)
1299 maxi = DEBUG_PACKET_DUMP;
1300 for(i = 14; i < maxi; i++)
1301 if(p[i] >= ' ' && p[i] <= '~')
1302 printk(" %c", p[i]);
1303 else
1304 printk("%02X", p[i]);
1305 if(maxi < length)
1306 printk("..");
1307 printk("\"\n");
1308 printk(KERN_DEBUG "\n");
1309 #endif /* DEBUG_PACKET_DUMP */
1311 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1313 /*------------------------------------------------------------------*/
1315 * This is the information which is displayed by the driver at startup
1316 * There is a lot of flag to configure it at your will...
1318 static inline void
1319 wv_init_info(struct net_device * dev)
1321 kio_addr_t base = dev->base_addr;
1322 psa_t psa;
1323 int i;
1325 /* Read the parameter storage area */
1326 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
1328 #ifdef DEBUG_PSA_SHOW
1329 wv_psa_show(&psa);
1330 #endif
1331 #ifdef DEBUG_MMC_SHOW
1332 wv_mmc_show(dev);
1333 #endif
1334 #ifdef DEBUG_I82593_SHOW
1335 wv_ru_show(dev);
1336 #endif
1338 #ifdef DEBUG_BASIC_SHOW
1339 /* Now, let's go for the basic stuff */
1340 printk(KERN_NOTICE "%s: WaveLAN: port %#lx, irq %d, hw_addr",
1341 dev->name, base, dev->irq);
1342 for(i = 0; i < WAVELAN_ADDR_SIZE; i++)
1343 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1345 /* Print current network id */
1346 if(psa.psa_nwid_select)
1347 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
1348 else
1349 printk(", nwid off");
1351 /* If 2.00 card */
1352 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1353 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1355 unsigned short freq;
1357 /* Ask the EEprom to read the frequency from the first area */
1358 fee_read(base, 0x00 /* 1st area - frequency... */,
1359 &freq, 1);
1361 /* Print frequency */
1362 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1364 /* Hack !!! */
1365 if(freq & 0x20)
1366 printk(".5");
1368 else
1370 printk(", PCMCIA, ");
1371 switch (psa.psa_subband)
1373 case PSA_SUBBAND_915:
1374 printk("915");
1375 break;
1376 case PSA_SUBBAND_2425:
1377 printk("2425");
1378 break;
1379 case PSA_SUBBAND_2460:
1380 printk("2460");
1381 break;
1382 case PSA_SUBBAND_2484:
1383 printk("2484");
1384 break;
1385 case PSA_SUBBAND_2430_5:
1386 printk("2430.5");
1387 break;
1388 default:
1389 printk("unknown");
1393 printk(" MHz\n");
1394 #endif /* DEBUG_BASIC_SHOW */
1396 #ifdef DEBUG_VERSION_SHOW
1397 /* Print version information */
1398 printk(KERN_NOTICE "%s", version);
1399 #endif
1400 } /* wv_init_info */
1402 /********************* IOCTL, STATS & RECONFIG *********************/
1404 * We found here routines that are called by Linux on differents
1405 * occasions after the configuration and not for transmitting data
1406 * These may be called when the user use ifconfig, /proc/net/dev
1407 * or wireless extensions
1410 /*------------------------------------------------------------------*/
1412 * Get the current ethernet statistics. This may be called with the
1413 * card open or closed.
1414 * Used when the user read /proc/net/dev
1416 static en_stats *
1417 wavelan_get_stats(struct net_device * dev)
1419 #ifdef DEBUG_IOCTL_TRACE
1420 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1421 #endif
1423 return(&((net_local *)netdev_priv(dev))->stats);
1426 /*------------------------------------------------------------------*/
1428 * Set or clear the multicast filter for this adaptor.
1429 * num_addrs == -1 Promiscuous mode, receive all packets
1430 * num_addrs == 0 Normal mode, clear multicast list
1431 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1432 * and do best-effort filtering.
1435 static void
1436 wavelan_set_multicast_list(struct net_device * dev)
1438 net_local * lp = netdev_priv(dev);
1440 #ifdef DEBUG_IOCTL_TRACE
1441 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
1442 #endif
1444 #ifdef DEBUG_IOCTL_INFO
1445 printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1446 dev->name, dev->flags, dev->mc_count);
1447 #endif
1449 if(dev->flags & IFF_PROMISC)
1452 * Enable promiscuous mode: receive all packets.
1454 if(!lp->promiscuous)
1456 lp->promiscuous = 1;
1457 lp->allmulticast = 0;
1458 lp->mc_count = 0;
1460 wv_82593_reconfig(dev);
1462 /* Tell the kernel that we are doing a really bad job... */
1463 dev->flags |= IFF_PROMISC;
1466 else
1467 /* If all multicast addresses
1468 * or too much multicast addresses for the hardware filter */
1469 if((dev->flags & IFF_ALLMULTI) ||
1470 (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
1473 * Disable promiscuous mode, but active the all multicast mode
1475 if(!lp->allmulticast)
1477 lp->promiscuous = 0;
1478 lp->allmulticast = 1;
1479 lp->mc_count = 0;
1481 wv_82593_reconfig(dev);
1483 /* Tell the kernel that we are doing a really bad job... */
1484 dev->flags |= IFF_ALLMULTI;
1487 else
1488 /* If there is some multicast addresses to send */
1489 if(dev->mc_list != (struct dev_mc_list *) NULL)
1492 * Disable promiscuous mode, but receive all packets
1493 * in multicast list
1495 #ifdef MULTICAST_AVOID
1496 if(lp->promiscuous || lp->allmulticast ||
1497 (dev->mc_count != lp->mc_count))
1498 #endif
1500 lp->promiscuous = 0;
1501 lp->allmulticast = 0;
1502 lp->mc_count = dev->mc_count;
1504 wv_82593_reconfig(dev);
1507 else
1510 * Switch to normal mode: disable promiscuous mode and
1511 * clear the multicast list.
1513 if(lp->promiscuous || lp->mc_count == 0)
1515 lp->promiscuous = 0;
1516 lp->allmulticast = 0;
1517 lp->mc_count = 0;
1519 wv_82593_reconfig(dev);
1522 #ifdef DEBUG_IOCTL_TRACE
1523 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
1524 #endif
1527 /*------------------------------------------------------------------*/
1529 * This function doesn't exist...
1530 * (Note : it was a nice way to test the reconfigure stuff...)
1532 #ifdef SET_MAC_ADDRESS
1533 static int
1534 wavelan_set_mac_address(struct net_device * dev,
1535 void * addr)
1537 struct sockaddr * mac = addr;
1539 /* Copy the address */
1540 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1542 /* Reconfig the beast */
1543 wv_82593_reconfig(dev);
1545 return 0;
1547 #endif /* SET_MAC_ADDRESS */
1550 /*------------------------------------------------------------------*/
1552 * Frequency setting (for hardware able of it)
1553 * It's a bit complicated and you don't really want to look into it...
1555 static inline int
1556 wv_set_frequency(u_long base, /* i/o port of the card */
1557 iw_freq * frequency)
1559 const int BAND_NUM = 10; /* Number of bands */
1560 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1561 #ifdef DEBUG_IOCTL_INFO
1562 int i;
1563 #endif
1565 /* Setting by frequency */
1566 /* Theoritically, you may set any frequency between
1567 * the two limits with a 0.5 MHz precision. In practice,
1568 * I don't want you to have trouble with local
1569 * regulations... */
1570 if((frequency->e == 1) &&
1571 (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
1573 freq = ((frequency->m / 10000) - 24000L) / 5;
1576 /* Setting by channel (same as wfreqsel) */
1577 /* Warning : each channel is 22MHz wide, so some of the channels
1578 * will interfere... */
1579 if((frequency->e == 0) &&
1580 (frequency->m >= 0) && (frequency->m < BAND_NUM))
1582 /* Get frequency offset. */
1583 freq = channel_bands[frequency->m] >> 1;
1586 /* Verify if the frequency is allowed */
1587 if(freq != 0L)
1589 u_short table[10]; /* Authorized frequency table */
1591 /* Read the frequency table */
1592 fee_read(base, 0x71 /* frequency table */,
1593 table, 10);
1595 #ifdef DEBUG_IOCTL_INFO
1596 printk(KERN_DEBUG "Frequency table :");
1597 for(i = 0; i < 10; i++)
1599 printk(" %04X",
1600 table[i]);
1602 printk("\n");
1603 #endif
1605 /* Look in the table if the frequency is allowed */
1606 if(!(table[9 - ((freq - 24) / 16)] &
1607 (1 << ((freq - 24) % 16))))
1608 return -EINVAL; /* not allowed */
1610 else
1611 return -EINVAL;
1613 /* If we get a usable frequency */
1614 if(freq != 0L)
1616 unsigned short area[16];
1617 unsigned short dac[2];
1618 unsigned short area_verify[16];
1619 unsigned short dac_verify[2];
1620 /* Corresponding gain (in the power adjust value table)
1621 * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
1622 * & WCIN062D.DOC, page 6.2.9 */
1623 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1624 int power_band = 0; /* Selected band */
1625 unsigned short power_adjust; /* Correct value */
1627 /* Search for the gain */
1628 power_band = 0;
1629 while((freq > power_limit[power_band]) &&
1630 (power_limit[++power_band] != 0))
1633 /* Read the first area */
1634 fee_read(base, 0x00,
1635 area, 16);
1637 /* Read the DAC */
1638 fee_read(base, 0x60,
1639 dac, 2);
1641 /* Read the new power adjust value */
1642 fee_read(base, 0x6B - (power_band >> 1),
1643 &power_adjust, 1);
1644 if(power_band & 0x1)
1645 power_adjust >>= 8;
1646 else
1647 power_adjust &= 0xFF;
1649 #ifdef DEBUG_IOCTL_INFO
1650 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1651 for(i = 0; i < 16; i++)
1653 printk(" %04X",
1654 area[i]);
1656 printk("\n");
1658 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1659 dac[0], dac[1]);
1660 #endif
1662 /* Frequency offset (for info only...) */
1663 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1665 /* Receiver Principle main divider coefficient */
1666 area[3] = (freq >> 1) + 2400L - 352L;
1667 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1669 /* Transmitter Main divider coefficient */
1670 area[13] = (freq >> 1) + 2400L;
1671 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1673 /* Others part of the area are flags, bit streams or unused... */
1675 /* Set the value in the DAC */
1676 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1677 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1679 /* Write the first area */
1680 fee_write(base, 0x00,
1681 area, 16);
1683 /* Write the DAC */
1684 fee_write(base, 0x60,
1685 dac, 2);
1687 /* We now should verify here that the EEprom writting was ok */
1689 /* ReRead the first area */
1690 fee_read(base, 0x00,
1691 area_verify, 16);
1693 /* ReRead the DAC */
1694 fee_read(base, 0x60,
1695 dac_verify, 2);
1697 /* Compare */
1698 if(memcmp(area, area_verify, 16 * 2) ||
1699 memcmp(dac, dac_verify, 2 * 2))
1701 #ifdef DEBUG_IOCTL_ERROR
1702 printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
1703 #endif
1704 return -EOPNOTSUPP;
1707 /* We must download the frequency parameters to the
1708 * synthetisers (from the EEprom - area 1)
1709 * Note : as the EEprom is auto decremented, we set the end
1710 * if the area... */
1711 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
1712 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1713 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1715 /* Wait until the download is finished */
1716 fee_wait(base, 100, 100);
1718 /* We must now download the power adjust value (gain) to
1719 * the synthetisers (from the EEprom - area 7 - DAC) */
1720 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
1721 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1722 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1724 /* Wait until the download is finished */
1725 fee_wait(base, 100, 100);
1727 #ifdef DEBUG_IOCTL_INFO
1728 /* Verification of what we have done... */
1730 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1731 for(i = 0; i < 16; i++)
1733 printk(" %04X",
1734 area_verify[i]);
1736 printk("\n");
1738 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1739 dac_verify[0], dac_verify[1]);
1740 #endif
1742 return 0;
1744 else
1745 return -EINVAL; /* Bah, never get there... */
1748 /*------------------------------------------------------------------*/
1750 * Give the list of available frequencies
1752 static inline int
1753 wv_frequency_list(u_long base, /* i/o port of the card */
1754 iw_freq * list, /* List of frequency to fill */
1755 int max) /* Maximum number of frequencies */
1757 u_short table[10]; /* Authorized frequency table */
1758 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1759 int i; /* index in the table */
1760 const int BAND_NUM = 10; /* Number of bands */
1761 int c = 0; /* Channel number */
1763 /* Read the frequency table */
1764 fee_read(base, 0x71 /* frequency table */,
1765 table, 10);
1767 /* Look all frequencies */
1768 i = 0;
1769 for(freq = 0; freq < 150; freq++)
1770 /* Look in the table if the frequency is allowed */
1771 if(table[9 - (freq / 16)] & (1 << (freq % 16)))
1773 /* Compute approximate channel number */
1774 while((((channel_bands[c] >> 1) - 24) < freq) &&
1775 (c < BAND_NUM))
1776 c++;
1777 list[i].i = c; /* Set the list index */
1779 /* put in the list */
1780 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1781 list[i++].e = 1;
1783 /* Check number */
1784 if(i >= max)
1785 return(i);
1788 return(i);
1791 #ifdef IW_WIRELESS_SPY
1792 /*------------------------------------------------------------------*/
1794 * Gather wireless spy statistics : for each packet, compare the source
1795 * address with out list, and if match, get the stats...
1796 * Sorry, but this function really need wireless extensions...
1798 static inline void
1799 wl_spy_gather(struct net_device * dev,
1800 u_char * mac, /* MAC address */
1801 u_char * stats) /* Statistics to gather */
1803 struct iw_quality wstats;
1805 wstats.qual = stats[2] & MMR_SGNL_QUAL;
1806 wstats.level = stats[0] & MMR_SIGNAL_LVL;
1807 wstats.noise = stats[1] & MMR_SILENCE_LVL;
1808 wstats.updated = 0x7;
1810 /* Update spy records */
1811 wireless_spy_update(dev, mac, &wstats);
1813 #endif /* IW_WIRELESS_SPY */
1815 #ifdef HISTOGRAM
1816 /*------------------------------------------------------------------*/
1818 * This function calculate an histogram on the signal level.
1819 * As the noise is quite constant, it's like doing it on the SNR.
1820 * We have defined a set of interval (lp->his_range), and each time
1821 * the level goes in that interval, we increment the count (lp->his_sum).
1822 * With this histogram you may detect if one wavelan is really weak,
1823 * or you may also calculate the mean and standard deviation of the level...
1825 static inline void
1826 wl_his_gather(struct net_device * dev,
1827 u_char * stats) /* Statistics to gather */
1829 net_local * lp = netdev_priv(dev);
1830 u_char level = stats[0] & MMR_SIGNAL_LVL;
1831 int i;
1833 /* Find the correct interval */
1834 i = 0;
1835 while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
1838 /* Increment interval counter */
1839 (lp->his_sum[i])++;
1841 #endif /* HISTOGRAM */
1843 static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1845 strncpy(info->driver, "wavelan_cs", sizeof(info->driver)-1);
1848 static struct ethtool_ops ops = {
1849 .get_drvinfo = wl_get_drvinfo
1852 /*------------------------------------------------------------------*/
1854 * Wireless Handler : get protocol name
1856 static int wavelan_get_name(struct net_device *dev,
1857 struct iw_request_info *info,
1858 union iwreq_data *wrqu,
1859 char *extra)
1861 strcpy(wrqu->name, "WaveLAN");
1862 return 0;
1865 /*------------------------------------------------------------------*/
1867 * Wireless Handler : set NWID
1869 static int wavelan_set_nwid(struct net_device *dev,
1870 struct iw_request_info *info,
1871 union iwreq_data *wrqu,
1872 char *extra)
1874 kio_addr_t base = dev->base_addr;
1875 net_local *lp = netdev_priv(dev);
1876 psa_t psa;
1877 mm_t m;
1878 unsigned long flags;
1879 int ret = 0;
1881 /* Disable interrupts and save flags. */
1882 spin_lock_irqsave(&lp->spinlock, flags);
1884 /* Set NWID in WaveLAN. */
1885 if (!wrqu->nwid.disabled) {
1886 /* Set NWID in psa */
1887 psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
1888 psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
1889 psa.psa_nwid_select = 0x01;
1890 psa_write(dev,
1891 (char *) psa.psa_nwid - (char *) &psa,
1892 (unsigned char *) psa.psa_nwid, 3);
1894 /* Set NWID in mmc. */
1895 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1896 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1897 mmc_write(base,
1898 (char *) &m.w.mmw_netw_id_l -
1899 (char *) &m,
1900 (unsigned char *) &m.w.mmw_netw_id_l, 2);
1901 mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
1902 } else {
1903 /* Disable NWID in the psa. */
1904 psa.psa_nwid_select = 0x00;
1905 psa_write(dev,
1906 (char *) &psa.psa_nwid_select -
1907 (char *) &psa,
1908 (unsigned char *) &psa.psa_nwid_select,
1911 /* Disable NWID in the mmc (no filtering). */
1912 mmc_out(base, mmwoff(0, mmw_loopt_sel),
1913 MMW_LOOPT_SEL_DIS_NWID);
1915 /* update the Wavelan checksum */
1916 update_psa_checksum(dev);
1918 /* Enable interrupts and restore flags. */
1919 spin_unlock_irqrestore(&lp->spinlock, flags);
1921 return ret;
1924 /*------------------------------------------------------------------*/
1926 * Wireless Handler : get NWID
1928 static int wavelan_get_nwid(struct net_device *dev,
1929 struct iw_request_info *info,
1930 union iwreq_data *wrqu,
1931 char *extra)
1933 net_local *lp = netdev_priv(dev);
1934 psa_t psa;
1935 unsigned long flags;
1936 int ret = 0;
1938 /* Disable interrupts and save flags. */
1939 spin_lock_irqsave(&lp->spinlock, flags);
1941 /* Read the NWID. */
1942 psa_read(dev,
1943 (char *) psa.psa_nwid - (char *) &psa,
1944 (unsigned char *) psa.psa_nwid, 3);
1945 wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1946 wrqu->nwid.disabled = !(psa.psa_nwid_select);
1947 wrqu->nwid.fixed = 1; /* Superfluous */
1949 /* Enable interrupts and restore flags. */
1950 spin_unlock_irqrestore(&lp->spinlock, flags);
1952 return ret;
1955 /*------------------------------------------------------------------*/
1957 * Wireless Handler : set frequency
1959 static int wavelan_set_freq(struct net_device *dev,
1960 struct iw_request_info *info,
1961 union iwreq_data *wrqu,
1962 char *extra)
1964 kio_addr_t base = dev->base_addr;
1965 net_local *lp = netdev_priv(dev);
1966 unsigned long flags;
1967 int ret;
1969 /* Disable interrupts and save flags. */
1970 spin_lock_irqsave(&lp->spinlock, flags);
1972 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1973 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1974 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1975 ret = wv_set_frequency(base, &(wrqu->freq));
1976 else
1977 ret = -EOPNOTSUPP;
1979 /* Enable interrupts and restore flags. */
1980 spin_unlock_irqrestore(&lp->spinlock, flags);
1982 return ret;
1985 /*------------------------------------------------------------------*/
1987 * Wireless Handler : get frequency
1989 static int wavelan_get_freq(struct net_device *dev,
1990 struct iw_request_info *info,
1991 union iwreq_data *wrqu,
1992 char *extra)
1994 kio_addr_t base = dev->base_addr;
1995 net_local *lp = netdev_priv(dev);
1996 psa_t psa;
1997 unsigned long flags;
1998 int ret = 0;
2000 /* Disable interrupts and save flags. */
2001 spin_lock_irqsave(&lp->spinlock, flags);
2003 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
2004 * Does it work for everybody, especially old cards? */
2005 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2006 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2007 unsigned short freq;
2009 /* Ask the EEPROM to read the frequency from the first area. */
2010 fee_read(base, 0x00, &freq, 1);
2011 wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
2012 wrqu->freq.e = 1;
2013 } else {
2014 psa_read(dev,
2015 (char *) &psa.psa_subband - (char *) &psa,
2016 (unsigned char *) &psa.psa_subband, 1);
2018 if (psa.psa_subband <= 4) {
2019 wrqu->freq.m = fixed_bands[psa.psa_subband];
2020 wrqu->freq.e = (psa.psa_subband != 0);
2021 } else
2022 ret = -EOPNOTSUPP;
2025 /* Enable interrupts and restore flags. */
2026 spin_unlock_irqrestore(&lp->spinlock, flags);
2028 return ret;
2031 /*------------------------------------------------------------------*/
2033 * Wireless Handler : set level threshold
2035 static int wavelan_set_sens(struct net_device *dev,
2036 struct iw_request_info *info,
2037 union iwreq_data *wrqu,
2038 char *extra)
2040 kio_addr_t base = dev->base_addr;
2041 net_local *lp = netdev_priv(dev);
2042 psa_t psa;
2043 unsigned long flags;
2044 int ret = 0;
2046 /* Disable interrupts and save flags. */
2047 spin_lock_irqsave(&lp->spinlock, flags);
2049 /* Set the level threshold. */
2050 /* We should complain loudly if wrqu->sens.fixed = 0, because we
2051 * can't set auto mode... */
2052 psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
2053 psa_write(dev,
2054 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2055 (unsigned char *) &psa.psa_thr_pre_set, 1);
2056 /* update the Wavelan checksum */
2057 update_psa_checksum(dev);
2058 mmc_out(base, mmwoff(0, mmw_thr_pre_set),
2059 psa.psa_thr_pre_set);
2061 /* Enable interrupts and restore flags. */
2062 spin_unlock_irqrestore(&lp->spinlock, flags);
2064 return ret;
2067 /*------------------------------------------------------------------*/
2069 * Wireless Handler : get level threshold
2071 static int wavelan_get_sens(struct net_device *dev,
2072 struct iw_request_info *info,
2073 union iwreq_data *wrqu,
2074 char *extra)
2076 net_local *lp = netdev_priv(dev);
2077 psa_t psa;
2078 unsigned long flags;
2079 int ret = 0;
2081 /* Disable interrupts and save flags. */
2082 spin_lock_irqsave(&lp->spinlock, flags);
2084 /* Read the level threshold. */
2085 psa_read(dev,
2086 (char *) &psa.psa_thr_pre_set - (char *) &psa,
2087 (unsigned char *) &psa.psa_thr_pre_set, 1);
2088 wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
2089 wrqu->sens.fixed = 1;
2091 /* Enable interrupts and restore flags. */
2092 spin_unlock_irqrestore(&lp->spinlock, flags);
2094 return ret;
2097 /*------------------------------------------------------------------*/
2099 * Wireless Handler : set encryption key
2101 static int wavelan_set_encode(struct net_device *dev,
2102 struct iw_request_info *info,
2103 union iwreq_data *wrqu,
2104 char *extra)
2106 kio_addr_t base = dev->base_addr;
2107 net_local *lp = netdev_priv(dev);
2108 unsigned long flags;
2109 psa_t psa;
2110 int ret = 0;
2112 /* Disable interrupts and save flags. */
2113 spin_lock_irqsave(&lp->spinlock, flags);
2115 /* Check if capable of encryption */
2116 if (!mmc_encr(base)) {
2117 ret = -EOPNOTSUPP;
2120 /* Check the size of the key */
2121 if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
2122 ret = -EINVAL;
2125 if(!ret) {
2126 /* Basic checking... */
2127 if (wrqu->encoding.length == 8) {
2128 /* Copy the key in the driver */
2129 memcpy(psa.psa_encryption_key, extra,
2130 wrqu->encoding.length);
2131 psa.psa_encryption_select = 1;
2133 psa_write(dev,
2134 (char *) &psa.psa_encryption_select -
2135 (char *) &psa,
2136 (unsigned char *) &psa.
2137 psa_encryption_select, 8 + 1);
2139 mmc_out(base, mmwoff(0, mmw_encr_enable),
2140 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2141 mmc_write(base, mmwoff(0, mmw_encr_key),
2142 (unsigned char *) &psa.
2143 psa_encryption_key, 8);
2146 /* disable encryption */
2147 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
2148 psa.psa_encryption_select = 0;
2149 psa_write(dev,
2150 (char *) &psa.psa_encryption_select -
2151 (char *) &psa,
2152 (unsigned char *) &psa.
2153 psa_encryption_select, 1);
2155 mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
2157 /* update the Wavelan checksum */
2158 update_psa_checksum(dev);
2161 /* Enable interrupts and restore flags. */
2162 spin_unlock_irqrestore(&lp->spinlock, flags);
2164 return ret;
2167 /*------------------------------------------------------------------*/
2169 * Wireless Handler : get encryption key
2171 static int wavelan_get_encode(struct net_device *dev,
2172 struct iw_request_info *info,
2173 union iwreq_data *wrqu,
2174 char *extra)
2176 kio_addr_t base = dev->base_addr;
2177 net_local *lp = netdev_priv(dev);
2178 psa_t psa;
2179 unsigned long flags;
2180 int ret = 0;
2182 /* Disable interrupts and save flags. */
2183 spin_lock_irqsave(&lp->spinlock, flags);
2185 /* Check if encryption is available */
2186 if (!mmc_encr(base)) {
2187 ret = -EOPNOTSUPP;
2188 } else {
2189 /* Read the encryption key */
2190 psa_read(dev,
2191 (char *) &psa.psa_encryption_select -
2192 (char *) &psa,
2193 (unsigned char *) &psa.
2194 psa_encryption_select, 1 + 8);
2196 /* encryption is enabled ? */
2197 if (psa.psa_encryption_select)
2198 wrqu->encoding.flags = IW_ENCODE_ENABLED;
2199 else
2200 wrqu->encoding.flags = IW_ENCODE_DISABLED;
2201 wrqu->encoding.flags |= mmc_encr(base);
2203 /* Copy the key to the user buffer */
2204 wrqu->encoding.length = 8;
2205 memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
2208 /* Enable interrupts and restore flags. */
2209 spin_unlock_irqrestore(&lp->spinlock, flags);
2211 return ret;
2214 #ifdef WAVELAN_ROAMING_EXT
2215 /*------------------------------------------------------------------*/
2217 * Wireless Handler : set ESSID (domain)
2219 static int wavelan_set_essid(struct net_device *dev,
2220 struct iw_request_info *info,
2221 union iwreq_data *wrqu,
2222 char *extra)
2224 net_local *lp = netdev_priv(dev);
2225 unsigned long flags;
2226 int ret = 0;
2228 /* Disable interrupts and save flags. */
2229 spin_lock_irqsave(&lp->spinlock, flags);
2231 /* Check if disable */
2232 if(wrqu->data.flags == 0)
2233 lp->filter_domains = 0;
2234 else {
2235 char essid[IW_ESSID_MAX_SIZE + 1];
2236 char * endp;
2238 /* Terminate the string */
2239 memcpy(essid, extra, wrqu->data.length);
2240 essid[IW_ESSID_MAX_SIZE] = '\0';
2242 #ifdef DEBUG_IOCTL_INFO
2243 printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
2244 #endif /* DEBUG_IOCTL_INFO */
2246 /* Convert to a number (note : Wavelan specific) */
2247 lp->domain_id = simple_strtoul(essid, &endp, 16);
2248 /* Has it worked ? */
2249 if(endp > essid)
2250 lp->filter_domains = 1;
2251 else {
2252 lp->filter_domains = 0;
2253 ret = -EINVAL;
2257 /* Enable interrupts and restore flags. */
2258 spin_unlock_irqrestore(&lp->spinlock, flags);
2260 return ret;
2263 /*------------------------------------------------------------------*/
2265 * Wireless Handler : get ESSID (domain)
2267 static int wavelan_get_essid(struct net_device *dev,
2268 struct iw_request_info *info,
2269 union iwreq_data *wrqu,
2270 char *extra)
2272 net_local *lp = netdev_priv(dev);
2274 /* Is the domain ID active ? */
2275 wrqu->data.flags = lp->filter_domains;
2277 /* Copy Domain ID into a string (Wavelan specific) */
2278 /* Sound crazy, be we can't have a snprintf in the kernel !!! */
2279 sprintf(extra, "%lX", lp->domain_id);
2280 extra[IW_ESSID_MAX_SIZE] = '\0';
2282 /* Set the length */
2283 wrqu->data.length = strlen(extra) + 1;
2285 return 0;
2288 /*------------------------------------------------------------------*/
2290 * Wireless Handler : set AP address
2292 static int wavelan_set_wap(struct net_device *dev,
2293 struct iw_request_info *info,
2294 union iwreq_data *wrqu,
2295 char *extra)
2297 #ifdef DEBUG_IOCTL_INFO
2298 printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
2299 wrqu->ap_addr.sa_data[0],
2300 wrqu->ap_addr.sa_data[1],
2301 wrqu->ap_addr.sa_data[2],
2302 wrqu->ap_addr.sa_data[3],
2303 wrqu->ap_addr.sa_data[4],
2304 wrqu->ap_addr.sa_data[5]);
2305 #endif /* DEBUG_IOCTL_INFO */
2307 return -EOPNOTSUPP;
2310 /*------------------------------------------------------------------*/
2312 * Wireless Handler : get AP address
2314 static int wavelan_get_wap(struct net_device *dev,
2315 struct iw_request_info *info,
2316 union iwreq_data *wrqu,
2317 char *extra)
2319 /* Should get the real McCoy instead of own Ethernet address */
2320 memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
2321 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
2323 return -EOPNOTSUPP;
2325 #endif /* WAVELAN_ROAMING_EXT */
2327 #ifdef WAVELAN_ROAMING
2328 /*------------------------------------------------------------------*/
2330 * Wireless Handler : set mode
2332 static int wavelan_set_mode(struct net_device *dev,
2333 struct iw_request_info *info,
2334 union iwreq_data *wrqu,
2335 char *extra)
2337 net_local *lp = netdev_priv(dev);
2338 unsigned long flags;
2339 int ret = 0;
2341 /* Disable interrupts and save flags. */
2342 spin_lock_irqsave(&lp->spinlock, flags);
2344 /* Check mode */
2345 switch(wrqu->mode) {
2346 case IW_MODE_ADHOC:
2347 if(do_roaming) {
2348 wv_roam_cleanup(dev);
2349 do_roaming = 0;
2351 break;
2352 case IW_MODE_INFRA:
2353 if(!do_roaming) {
2354 wv_roam_init(dev);
2355 do_roaming = 1;
2357 break;
2358 default:
2359 ret = -EINVAL;
2362 /* Enable interrupts and restore flags. */
2363 spin_unlock_irqrestore(&lp->spinlock, flags);
2365 return ret;
2368 /*------------------------------------------------------------------*/
2370 * Wireless Handler : get mode
2372 static int wavelan_get_mode(struct net_device *dev,
2373 struct iw_request_info *info,
2374 union iwreq_data *wrqu,
2375 char *extra)
2377 if(do_roaming)
2378 wrqu->mode = IW_MODE_INFRA;
2379 else
2380 wrqu->mode = IW_MODE_ADHOC;
2382 return 0;
2384 #endif /* WAVELAN_ROAMING */
2386 /*------------------------------------------------------------------*/
2388 * Wireless Handler : get range info
2390 static int wavelan_get_range(struct net_device *dev,
2391 struct iw_request_info *info,
2392 union iwreq_data *wrqu,
2393 char *extra)
2395 kio_addr_t base = dev->base_addr;
2396 net_local *lp = netdev_priv(dev);
2397 struct iw_range *range = (struct iw_range *) extra;
2398 unsigned long flags;
2399 int ret = 0;
2401 /* Set the length (very important for backward compatibility) */
2402 wrqu->data.length = sizeof(struct iw_range);
2404 /* Set all the info we don't care or don't know about to zero */
2405 memset(range, 0, sizeof(struct iw_range));
2407 /* Set the Wireless Extension versions */
2408 range->we_version_compiled = WIRELESS_EXT;
2409 range->we_version_source = 9;
2411 /* Set information in the range struct. */
2412 range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
2413 range->min_nwid = 0x0000;
2414 range->max_nwid = 0xFFFF;
2416 range->sensitivity = 0x3F;
2417 range->max_qual.qual = MMR_SGNL_QUAL;
2418 range->max_qual.level = MMR_SIGNAL_LVL;
2419 range->max_qual.noise = MMR_SILENCE_LVL;
2420 range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
2421 /* Need to get better values for those two */
2422 range->avg_qual.level = 30;
2423 range->avg_qual.noise = 8;
2425 range->num_bitrates = 1;
2426 range->bitrate[0] = 2000000; /* 2 Mb/s */
2428 /* Event capability (kernel + driver) */
2429 range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
2430 IW_EVENT_CAPA_MASK(0x8B04) |
2431 IW_EVENT_CAPA_MASK(0x8B06));
2432 range->event_capa[1] = IW_EVENT_CAPA_K_1;
2434 /* Disable interrupts and save flags. */
2435 spin_lock_irqsave(&lp->spinlock, flags);
2437 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2438 if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2439 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2440 range->num_channels = 10;
2441 range->num_frequency = wv_frequency_list(base, range->freq,
2442 IW_MAX_FREQUENCIES);
2443 } else
2444 range->num_channels = range->num_frequency = 0;
2446 /* Encryption supported ? */
2447 if (mmc_encr(base)) {
2448 range->encoding_size[0] = 8; /* DES = 64 bits key */
2449 range->num_encoding_sizes = 1;
2450 range->max_encoding_tokens = 1; /* Only one key possible */
2451 } else {
2452 range->num_encoding_sizes = 0;
2453 range->max_encoding_tokens = 0;
2456 /* Enable interrupts and restore flags. */
2457 spin_unlock_irqrestore(&lp->spinlock, flags);
2459 return ret;
2462 /*------------------------------------------------------------------*/
2464 * Wireless Private Handler : set quality threshold
2466 static int wavelan_set_qthr(struct net_device *dev,
2467 struct iw_request_info *info,
2468 union iwreq_data *wrqu,
2469 char *extra)
2471 kio_addr_t base = dev->base_addr;
2472 net_local *lp = netdev_priv(dev);
2473 psa_t psa;
2474 unsigned long flags;
2476 /* Disable interrupts and save flags. */
2477 spin_lock_irqsave(&lp->spinlock, flags);
2479 psa.psa_quality_thr = *(extra) & 0x0F;
2480 psa_write(dev,
2481 (char *) &psa.psa_quality_thr - (char *) &psa,
2482 (unsigned char *) &psa.psa_quality_thr, 1);
2483 /* update the Wavelan checksum */
2484 update_psa_checksum(dev);
2485 mmc_out(base, mmwoff(0, mmw_quality_thr),
2486 psa.psa_quality_thr);
2488 /* Enable interrupts and restore flags. */
2489 spin_unlock_irqrestore(&lp->spinlock, flags);
2491 return 0;
2494 /*------------------------------------------------------------------*/
2496 * Wireless Private Handler : get quality threshold
2498 static int wavelan_get_qthr(struct net_device *dev,
2499 struct iw_request_info *info,
2500 union iwreq_data *wrqu,
2501 char *extra)
2503 net_local *lp = netdev_priv(dev);
2504 psa_t psa;
2505 unsigned long flags;
2507 /* Disable interrupts and save flags. */
2508 spin_lock_irqsave(&lp->spinlock, flags);
2510 psa_read(dev,
2511 (char *) &psa.psa_quality_thr - (char *) &psa,
2512 (unsigned char *) &psa.psa_quality_thr, 1);
2513 *(extra) = psa.psa_quality_thr & 0x0F;
2515 /* Enable interrupts and restore flags. */
2516 spin_unlock_irqrestore(&lp->spinlock, flags);
2518 return 0;
2521 #ifdef WAVELAN_ROAMING
2522 /*------------------------------------------------------------------*/
2524 * Wireless Private Handler : set roaming
2526 static int wavelan_set_roam(struct net_device *dev,
2527 struct iw_request_info *info,
2528 union iwreq_data *wrqu,
2529 char *extra)
2531 net_local *lp = netdev_priv(dev);
2532 unsigned long flags;
2534 /* Disable interrupts and save flags. */
2535 spin_lock_irqsave(&lp->spinlock, flags);
2537 /* Note : should check if user == root */
2538 if(do_roaming && (*extra)==0)
2539 wv_roam_cleanup(dev);
2540 else if(do_roaming==0 && (*extra)!=0)
2541 wv_roam_init(dev);
2543 do_roaming = (*extra);
2545 /* Enable interrupts and restore flags. */
2546 spin_unlock_irqrestore(&lp->spinlock, flags);
2548 return 0;
2551 /*------------------------------------------------------------------*/
2553 * Wireless Private Handler : get quality threshold
2555 static int wavelan_get_roam(struct net_device *dev,
2556 struct iw_request_info *info,
2557 union iwreq_data *wrqu,
2558 char *extra)
2560 *(extra) = do_roaming;
2562 return 0;
2564 #endif /* WAVELAN_ROAMING */
2566 #ifdef HISTOGRAM
2567 /*------------------------------------------------------------------*/
2569 * Wireless Private Handler : set histogram
2571 static int wavelan_set_histo(struct net_device *dev,
2572 struct iw_request_info *info,
2573 union iwreq_data *wrqu,
2574 char *extra)
2576 net_local *lp = netdev_priv(dev);
2578 /* Check the number of intervals. */
2579 if (wrqu->data.length > 16) {
2580 return(-E2BIG);
2583 /* Disable histo while we copy the addresses.
2584 * As we don't disable interrupts, we need to do this */
2585 lp->his_number = 0;
2587 /* Are there ranges to copy? */
2588 if (wrqu->data.length > 0) {
2589 /* Copy interval ranges to the driver */
2590 memcpy(lp->his_range, extra, wrqu->data.length);
2593 int i;
2594 printk(KERN_DEBUG "Histo :");
2595 for(i = 0; i < wrqu->data.length; i++)
2596 printk(" %d", lp->his_range[i]);
2597 printk("\n");
2600 /* Reset result structure. */
2601 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2604 /* Now we can set the number of ranges */
2605 lp->his_number = wrqu->data.length;
2607 return(0);
2610 /*------------------------------------------------------------------*/
2612 * Wireless Private Handler : get histogram
2614 static int wavelan_get_histo(struct net_device *dev,
2615 struct iw_request_info *info,
2616 union iwreq_data *wrqu,
2617 char *extra)
2619 net_local *lp = netdev_priv(dev);
2621 /* Set the number of intervals. */
2622 wrqu->data.length = lp->his_number;
2624 /* Give back the distribution statistics */
2625 if(lp->his_number > 0)
2626 memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
2628 return(0);
2630 #endif /* HISTOGRAM */
2632 /*------------------------------------------------------------------*/
2634 * Structures to export the Wireless Handlers
2637 static const struct iw_priv_args wavelan_private_args[] = {
2638 /*{ cmd, set_args, get_args, name } */
2639 { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2640 { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2641 { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" },
2642 { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
2643 { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
2644 { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
2647 static const iw_handler wavelan_handler[] =
2649 NULL, /* SIOCSIWNAME */
2650 wavelan_get_name, /* SIOCGIWNAME */
2651 wavelan_set_nwid, /* SIOCSIWNWID */
2652 wavelan_get_nwid, /* SIOCGIWNWID */
2653 wavelan_set_freq, /* SIOCSIWFREQ */
2654 wavelan_get_freq, /* SIOCGIWFREQ */
2655 #ifdef WAVELAN_ROAMING
2656 wavelan_set_mode, /* SIOCSIWMODE */
2657 wavelan_get_mode, /* SIOCGIWMODE */
2658 #else /* WAVELAN_ROAMING */
2659 NULL, /* SIOCSIWMODE */
2660 NULL, /* SIOCGIWMODE */
2661 #endif /* WAVELAN_ROAMING */
2662 wavelan_set_sens, /* SIOCSIWSENS */
2663 wavelan_get_sens, /* SIOCGIWSENS */
2664 NULL, /* SIOCSIWRANGE */
2665 wavelan_get_range, /* SIOCGIWRANGE */
2666 NULL, /* SIOCSIWPRIV */
2667 NULL, /* SIOCGIWPRIV */
2668 NULL, /* SIOCSIWSTATS */
2669 NULL, /* SIOCGIWSTATS */
2670 iw_handler_set_spy, /* SIOCSIWSPY */
2671 iw_handler_get_spy, /* SIOCGIWSPY */
2672 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2673 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2674 #ifdef WAVELAN_ROAMING_EXT
2675 wavelan_set_wap, /* SIOCSIWAP */
2676 wavelan_get_wap, /* SIOCGIWAP */
2677 NULL, /* -- hole -- */
2678 NULL, /* SIOCGIWAPLIST */
2679 NULL, /* -- hole -- */
2680 NULL, /* -- hole -- */
2681 wavelan_set_essid, /* SIOCSIWESSID */
2682 wavelan_get_essid, /* SIOCGIWESSID */
2683 #else /* WAVELAN_ROAMING_EXT */
2684 NULL, /* SIOCSIWAP */
2685 NULL, /* SIOCGIWAP */
2686 NULL, /* -- hole -- */
2687 NULL, /* SIOCGIWAPLIST */
2688 NULL, /* -- hole -- */
2689 NULL, /* -- hole -- */
2690 NULL, /* SIOCSIWESSID */
2691 NULL, /* SIOCGIWESSID */
2692 #endif /* WAVELAN_ROAMING_EXT */
2693 NULL, /* SIOCSIWNICKN */
2694 NULL, /* SIOCGIWNICKN */
2695 NULL, /* -- hole -- */
2696 NULL, /* -- hole -- */
2697 NULL, /* SIOCSIWRATE */
2698 NULL, /* SIOCGIWRATE */
2699 NULL, /* SIOCSIWRTS */
2700 NULL, /* SIOCGIWRTS */
2701 NULL, /* SIOCSIWFRAG */
2702 NULL, /* SIOCGIWFRAG */
2703 NULL, /* SIOCSIWTXPOW */
2704 NULL, /* SIOCGIWTXPOW */
2705 NULL, /* SIOCSIWRETRY */
2706 NULL, /* SIOCGIWRETRY */
2707 wavelan_set_encode, /* SIOCSIWENCODE */
2708 wavelan_get_encode, /* SIOCGIWENCODE */
2711 static const iw_handler wavelan_private_handler[] =
2713 wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
2714 wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
2715 #ifdef WAVELAN_ROAMING
2716 wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */
2717 wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */
2718 #else /* WAVELAN_ROAMING */
2719 NULL, /* SIOCIWFIRSTPRIV + 2 */
2720 NULL, /* SIOCIWFIRSTPRIV + 3 */
2721 #endif /* WAVELAN_ROAMING */
2722 #ifdef HISTOGRAM
2723 wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */
2724 wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */
2725 #endif /* HISTOGRAM */
2728 static const struct iw_handler_def wavelan_handler_def =
2730 .num_standard = sizeof(wavelan_handler)/sizeof(iw_handler),
2731 .num_private = sizeof(wavelan_private_handler)/sizeof(iw_handler),
2732 .num_private_args = sizeof(wavelan_private_args)/sizeof(struct iw_priv_args),
2733 .standard = wavelan_handler,
2734 .private = wavelan_private_handler,
2735 .private_args = wavelan_private_args,
2736 .get_wireless_stats = wavelan_get_wireless_stats,
2739 /*------------------------------------------------------------------*/
2741 * Get wireless statistics
2742 * Called by /proc/net/wireless...
2744 static iw_stats *
2745 wavelan_get_wireless_stats(struct net_device * dev)
2747 kio_addr_t base = dev->base_addr;
2748 net_local * lp = netdev_priv(dev);
2749 mmr_t m;
2750 iw_stats * wstats;
2751 unsigned long flags;
2753 #ifdef DEBUG_IOCTL_TRACE
2754 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
2755 #endif
2757 /* Disable interrupts & save flags */
2758 spin_lock_irqsave(&lp->spinlock, flags);
2760 wstats = &lp->wstats;
2762 /* Get data from the mmc */
2763 mmc_out(base, mmwoff(0, mmw_freeze), 1);
2765 mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2766 mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
2767 mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
2769 mmc_out(base, mmwoff(0, mmw_freeze), 0);
2771 /* Copy data to wireless stuff */
2772 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2773 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2774 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2775 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2776 wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
2777 ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
2778 ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2779 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2780 wstats->discard.code = 0L;
2781 wstats->discard.misc = 0L;
2783 /* ReEnable interrupts & restore flags */
2784 spin_unlock_irqrestore(&lp->spinlock, flags);
2786 #ifdef DEBUG_IOCTL_TRACE
2787 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
2788 #endif
2789 return &lp->wstats;
2792 /************************* PACKET RECEPTION *************************/
2794 * This part deal with receiving the packets.
2795 * The interrupt handler get an interrupt when a packet has been
2796 * successfully received and called this part...
2799 /*------------------------------------------------------------------*/
2801 * Calculate the starting address of the frame pointed to by the receive
2802 * frame pointer and verify that the frame seem correct
2803 * (called by wv_packet_rcv())
2805 static inline int
2806 wv_start_of_frame(struct net_device * dev,
2807 int rfp, /* end of frame */
2808 int wrap) /* start of buffer */
2810 kio_addr_t base = dev->base_addr;
2811 int rp;
2812 int len;
2814 rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
2815 outb(rp & 0xff, PIORL(base));
2816 outb(((rp >> 8) & PIORH_MASK), PIORH(base));
2817 len = inb(PIOP(base));
2818 len |= inb(PIOP(base)) << 8;
2820 /* Sanity checks on size */
2821 /* Frame too big */
2822 if(len > MAXDATAZ + 100)
2824 #ifdef DEBUG_RX_ERROR
2825 printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
2826 dev->name, rfp, len);
2827 #endif
2828 return(-1);
2831 /* Frame too short */
2832 if(len < 7)
2834 #ifdef DEBUG_RX_ERROR
2835 printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
2836 dev->name, rfp, len);
2837 #endif
2838 return(-1);
2841 /* Wrap around buffer */
2842 if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
2844 #ifdef DEBUG_RX_ERROR
2845 printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
2846 dev->name, wrap, rfp, len);
2847 #endif
2848 return(-1);
2851 return((rp - len + RX_SIZE) % RX_SIZE);
2852 } /* wv_start_of_frame */
2854 /*------------------------------------------------------------------*/
2856 * This routine does the actual copy of data (including the ethernet
2857 * header structure) from the WaveLAN card to an sk_buff chain that
2858 * will be passed up to the network interface layer. NOTE: We
2859 * currently don't handle trailer protocols (neither does the rest of
2860 * the network interface), so if that is needed, it will (at least in
2861 * part) be added here. The contents of the receive ring buffer are
2862 * copied to a message chain that is then passed to the kernel.
2864 * Note: if any errors occur, the packet is "dropped on the floor"
2865 * (called by wv_packet_rcv())
2867 static inline void
2868 wv_packet_read(struct net_device * dev,
2869 int fd_p,
2870 int sksize)
2872 net_local * lp = netdev_priv(dev);
2873 struct sk_buff * skb;
2875 #ifdef DEBUG_RX_TRACE
2876 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2877 dev->name, fd_p, sksize);
2878 #endif
2880 /* Allocate some buffer for the new packet */
2881 if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
2883 #ifdef DEBUG_RX_ERROR
2884 printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
2885 dev->name, sksize);
2886 #endif
2887 lp->stats.rx_dropped++;
2889 * Not only do we want to return here, but we also need to drop the
2890 * packet on the floor to clear the interrupt.
2892 return;
2895 skb->dev = dev;
2897 skb_reserve(skb, 2);
2898 fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
2899 skb->protocol = eth_type_trans(skb, dev);
2901 #ifdef DEBUG_RX_INFO
2902 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2903 #endif /* DEBUG_RX_INFO */
2905 /* Statistics gathering & stuff associated.
2906 * It seem a bit messy with all the define, but it's really simple... */
2908 #ifdef IW_WIRELESS_SPY
2909 (lp->spy_data.spy_number > 0) ||
2910 #endif /* IW_WIRELESS_SPY */
2911 #ifdef HISTOGRAM
2912 (lp->his_number > 0) ||
2913 #endif /* HISTOGRAM */
2914 #ifdef WAVELAN_ROAMING
2915 (do_roaming) ||
2916 #endif /* WAVELAN_ROAMING */
2919 u_char stats[3]; /* Signal level, Noise level, Signal quality */
2921 /* read signal level, silence level and signal quality bytes */
2922 fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
2923 stats, 3);
2924 #ifdef DEBUG_RX_INFO
2925 printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2926 dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
2927 #endif
2929 #ifdef WAVELAN_ROAMING
2930 if(do_roaming)
2931 if(WAVELAN_BEACON(skb->data))
2932 wl_roam_gather(dev, skb->data, stats);
2933 #endif /* WAVELAN_ROAMING */
2935 #ifdef WIRELESS_SPY
2936 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
2937 #endif /* WIRELESS_SPY */
2938 #ifdef HISTOGRAM
2939 wl_his_gather(dev, stats);
2940 #endif /* HISTOGRAM */
2944 * Hand the packet to the Network Module
2946 netif_rx(skb);
2948 /* Keep stats up to date */
2949 dev->last_rx = jiffies;
2950 lp->stats.rx_packets++;
2951 lp->stats.rx_bytes += sksize;
2953 #ifdef DEBUG_RX_TRACE
2954 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2955 #endif
2956 return;
2959 /*------------------------------------------------------------------*/
2961 * This routine is called by the interrupt handler to initiate a
2962 * packet transfer from the card to the network interface layer above
2963 * this driver. This routine checks if a buffer has been successfully
2964 * received by the WaveLAN card. If so, the routine wv_packet_read is
2965 * called to do the actual transfer of the card's data including the
2966 * ethernet header into a packet consisting of an sk_buff chain.
2967 * (called by wavelan_interrupt())
2968 * Note : the spinlock is already grabbed for us and irq are disabled.
2970 static inline void
2971 wv_packet_rcv(struct net_device * dev)
2973 kio_addr_t base = dev->base_addr;
2974 net_local * lp = netdev_priv(dev);
2975 int newrfp;
2976 int rp;
2977 int len;
2978 int f_start;
2979 int status;
2980 int i593_rfp;
2981 int stat_ptr;
2982 u_char c[4];
2984 #ifdef DEBUG_RX_TRACE
2985 printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
2986 #endif
2988 /* Get the new receive frame pointer from the i82593 chip */
2989 outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
2990 i593_rfp = inb(LCSR(base));
2991 i593_rfp |= inb(LCSR(base)) << 8;
2992 i593_rfp %= RX_SIZE;
2994 /* Get the new receive frame pointer from the WaveLAN card.
2995 * It is 3 bytes more than the increment of the i82593 receive
2996 * frame pointer, for each packet. This is because it includes the
2997 * 3 roaming bytes added by the mmc.
2999 newrfp = inb(RPLL(base));
3000 newrfp |= inb(RPLH(base)) << 8;
3001 newrfp %= RX_SIZE;
3003 #ifdef DEBUG_RX_INFO
3004 printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3005 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
3006 #endif
3008 #ifdef DEBUG_RX_ERROR
3009 /* If no new frame pointer... */
3010 if(lp->overrunning || newrfp == lp->rfp)
3011 printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3012 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
3013 #endif
3015 /* Read all frames (packets) received */
3016 while(newrfp != lp->rfp)
3018 /* A frame is composed of the packet, followed by a status word,
3019 * the length of the frame (word) and the mmc info (SNR & qual).
3020 * It's because the length is at the end that we can only scan
3021 * frames backward. */
3023 /* Find the first frame by skipping backwards over the frames */
3024 rp = newrfp; /* End of last frame */
3025 while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
3026 (f_start != -1))
3027 rp = f_start;
3029 /* If we had a problem */
3030 if(f_start == -1)
3032 #ifdef DEBUG_RX_ERROR
3033 printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
3034 printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
3035 i593_rfp, lp->stop, newrfp, lp->rfp);
3036 #endif
3037 lp->rfp = rp; /* Get to the last usable frame */
3038 continue;
3041 /* f_start point to the beggining of the first frame received
3042 * and rp to the beggining of the next one */
3044 /* Read status & length of the frame */
3045 stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
3046 stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
3047 status = c[0] | (c[1] << 8);
3048 len = c[2] | (c[3] << 8);
3050 /* Check status */
3051 if((status & RX_RCV_OK) != RX_RCV_OK)
3053 lp->stats.rx_errors++;
3054 if(status & RX_NO_SFD)
3055 lp->stats.rx_frame_errors++;
3056 if(status & RX_CRC_ERR)
3057 lp->stats.rx_crc_errors++;
3058 if(status & RX_OVRRUN)
3059 lp->stats.rx_over_errors++;
3061 #ifdef DEBUG_RX_FAIL
3062 printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
3063 dev->name, status);
3064 #endif
3066 else
3067 /* Read the packet and transmit to Linux */
3068 wv_packet_read(dev, f_start, len - 2);
3070 /* One frame has been processed, skip it */
3071 lp->rfp = rp;
3075 * Update the frame stop register, but set it to less than
3076 * the full 8K to allow space for 3 bytes of signal strength
3077 * per packet.
3079 lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3080 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3081 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3082 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3084 #ifdef DEBUG_RX_TRACE
3085 printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
3086 #endif
3089 /*********************** PACKET TRANSMISSION ***********************/
3091 * This part deal with sending packet through the wavelan
3092 * We copy the packet to the send buffer and then issue the send
3093 * command to the i82593. The result of this operation will be
3094 * checked in wavelan_interrupt()
3097 /*------------------------------------------------------------------*/
3099 * This routine fills in the appropriate registers and memory
3100 * locations on the WaveLAN card and starts the card off on
3101 * the transmit.
3102 * (called in wavelan_packet_xmit())
3104 static inline void
3105 wv_packet_write(struct net_device * dev,
3106 void * buf,
3107 short length)
3109 net_local * lp = netdev_priv(dev);
3110 kio_addr_t base = dev->base_addr;
3111 unsigned long flags;
3112 int clen = length;
3113 register u_short xmtdata_base = TX_BASE;
3115 #ifdef DEBUG_TX_TRACE
3116 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
3117 #endif
3119 spin_lock_irqsave(&lp->spinlock, flags);
3121 /* Write the length of data buffer followed by the buffer */
3122 outb(xmtdata_base & 0xff, PIORL(base));
3123 outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3124 outb(clen & 0xff, PIOP(base)); /* lsb */
3125 outb(clen >> 8, PIOP(base)); /* msb */
3127 /* Send the data */
3128 outsb(PIOP(base), buf, clen);
3130 /* Indicate end of transmit chain */
3131 outb(OP0_NOP, PIOP(base));
3132 /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
3133 outb(OP0_NOP, PIOP(base));
3135 /* Reset the transmit DMA pointer */
3136 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3137 hacr_write(base, HACR_DEFAULT);
3138 /* Send the transmit command */
3139 wv_82593_cmd(dev, "wv_packet_write(): transmit",
3140 OP0_TRANSMIT, SR0_NO_RESULT);
3142 /* Make sure the watchdog will keep quiet for a while */
3143 dev->trans_start = jiffies;
3145 /* Keep stats up to date */
3146 lp->stats.tx_bytes += length;
3148 spin_unlock_irqrestore(&lp->spinlock, flags);
3150 #ifdef DEBUG_TX_INFO
3151 wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
3152 #endif /* DEBUG_TX_INFO */
3154 #ifdef DEBUG_TX_TRACE
3155 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
3156 #endif
3159 /*------------------------------------------------------------------*/
3161 * This routine is called when we want to send a packet (NET3 callback)
3162 * In this routine, we check if the harware is ready to accept
3163 * the packet. We also prevent reentrance. Then, we call the function
3164 * to send the packet...
3166 static int
3167 wavelan_packet_xmit(struct sk_buff * skb,
3168 struct net_device * dev)
3170 net_local * lp = netdev_priv(dev);
3171 unsigned long flags;
3173 #ifdef DEBUG_TX_TRACE
3174 printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
3175 (unsigned) skb);
3176 #endif
3179 * Block a timer-based transmit from overlapping a previous transmit.
3180 * In other words, prevent reentering this routine.
3182 netif_stop_queue(dev);
3184 /* If somebody has asked to reconfigure the controller,
3185 * we can do it now */
3186 if(lp->reconfig_82593)
3188 spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
3189 wv_82593_config(dev);
3190 spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
3191 /* Note : the configure procedure was totally synchronous,
3192 * so the Tx buffer is now free */
3195 #ifdef DEBUG_TX_ERROR
3196 if (skb->next)
3197 printk(KERN_INFO "skb has next\n");
3198 #endif
3200 /* Check if we need some padding */
3201 /* Note : on wireless the propagation time is in the order of 1us,
3202 * and we don't have the Ethernet specific requirement of beeing
3203 * able to detect collisions, therefore in theory we don't really
3204 * need to pad. Jean II */
3205 if (skb->len < ETH_ZLEN) {
3206 skb = skb_padto(skb, ETH_ZLEN);
3207 if (skb == NULL)
3208 return 0;
3211 wv_packet_write(dev, skb->data, skb->len);
3213 dev_kfree_skb(skb);
3215 #ifdef DEBUG_TX_TRACE
3216 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
3217 #endif
3218 return(0);
3221 /********************** HARDWARE CONFIGURATION **********************/
3223 * This part do the real job of starting and configuring the hardware.
3226 /*------------------------------------------------------------------*/
3228 * Routine to initialize the Modem Management Controller.
3229 * (called by wv_hw_config())
3231 static inline int
3232 wv_mmc_init(struct net_device * dev)
3234 kio_addr_t base = dev->base_addr;
3235 psa_t psa;
3236 mmw_t m;
3237 int configured;
3238 int i; /* Loop counter */
3240 #ifdef DEBUG_CONFIG_TRACE
3241 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
3242 #endif
3244 /* Read the parameter storage area */
3245 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3248 * Check the first three octets of the MAC addr for the manufacturer's code.
3249 * Note: If you get the error message below, you've got a
3250 * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
3251 * how to configure your card...
3253 for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3254 if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
3255 (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
3256 (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
3257 break;
3259 /* If we have not found it... */
3260 if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
3262 #ifdef DEBUG_CONFIG_ERRORS
3263 printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
3264 dev->name, psa.psa_univ_mac_addr[0],
3265 psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
3266 #endif
3267 return FALSE;
3270 /* Get the MAC address */
3271 memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
3273 #ifdef USE_PSA_CONFIG
3274 configured = psa.psa_conf_status & 1;
3275 #else
3276 configured = 0;
3277 #endif
3279 /* Is the PSA is not configured */
3280 if(!configured)
3282 /* User will be able to configure NWID after (with iwconfig) */
3283 psa.psa_nwid[0] = 0;
3284 psa.psa_nwid[1] = 0;
3286 /* As NWID is not set : no NWID checking */
3287 psa.psa_nwid_select = 0;
3289 /* Disable encryption */
3290 psa.psa_encryption_select = 0;
3292 /* Set to standard values
3293 * 0x04 for AT,
3294 * 0x01 for MCA,
3295 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
3297 if (psa.psa_comp_number & 1)
3298 psa.psa_thr_pre_set = 0x01;
3299 else
3300 psa.psa_thr_pre_set = 0x04;
3301 psa.psa_quality_thr = 0x03;
3303 /* It is configured */
3304 psa.psa_conf_status |= 1;
3306 #ifdef USE_PSA_CONFIG
3307 /* Write the psa */
3308 psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
3309 (unsigned char *)psa.psa_nwid, 4);
3310 psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
3311 (unsigned char *)&psa.psa_thr_pre_set, 1);
3312 psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
3313 (unsigned char *)&psa.psa_quality_thr, 1);
3314 psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
3315 (unsigned char *)&psa.psa_conf_status, 1);
3316 /* update the Wavelan checksum */
3317 update_psa_checksum(dev);
3318 #endif /* USE_PSA_CONFIG */
3321 /* Zero the mmc structure */
3322 memset(&m, 0x00, sizeof(m));
3324 /* Copy PSA info to the mmc */
3325 m.mmw_netw_id_l = psa.psa_nwid[1];
3326 m.mmw_netw_id_h = psa.psa_nwid[0];
3328 if(psa.psa_nwid_select & 1)
3329 m.mmw_loopt_sel = 0x00;
3330 else
3331 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
3333 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
3334 sizeof(m.mmw_encr_key));
3336 if(psa.psa_encryption_select)
3337 m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
3338 else
3339 m.mmw_encr_enable = 0;
3341 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
3342 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
3345 * Set default modem control parameters.
3346 * See NCR document 407-0024326 Rev. A.
3348 m.mmw_jabber_enable = 0x01;
3349 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
3350 m.mmw_ifs = 0x20;
3351 m.mmw_mod_delay = 0x04;
3352 m.mmw_jam_time = 0x38;
3354 m.mmw_des_io_invert = 0;
3355 m.mmw_freeze = 0;
3356 m.mmw_decay_prm = 0;
3357 m.mmw_decay_updat_prm = 0;
3359 /* Write all info to mmc */
3360 mmc_write(base, 0, (u_char *)&m, sizeof(m));
3362 /* The following code start the modem of the 2.00 frequency
3363 * selectable cards at power on. It's not strictly needed for the
3364 * following boots...
3365 * The original patch was by Joe Finney for the PCMCIA driver, but
3366 * I've cleaned it a bit and add documentation.
3367 * Thanks to Loeke Brederveld from Lucent for the info.
3370 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3371 * (does it work for everybody ? - especially old cards...) */
3372 /* Note : WFREQSEL verify that it is able to read from EEprom
3373 * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
3374 * is 0xA (Xilinx version) or 0xB (Ariadne version).
3375 * My test is more crude but do work... */
3376 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
3377 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
3379 /* We must download the frequency parameters to the
3380 * synthetisers (from the EEprom - area 1)
3381 * Note : as the EEprom is auto decremented, we set the end
3382 * if the area... */
3383 m.mmw_fee_addr = 0x0F;
3384 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3385 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3386 (unsigned char *)&m.mmw_fee_ctrl, 2);
3388 /* Wait until the download is finished */
3389 fee_wait(base, 100, 100);
3391 #ifdef DEBUG_CONFIG_INFO
3392 /* The frequency was in the last word downloaded... */
3393 mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
3394 (unsigned char *)&m.mmw_fee_data_l, 2);
3396 /* Print some info for the user */
3397 printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
3398 dev->name,
3399 ((m.mmw_fee_data_h << 4) |
3400 (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
3401 #endif
3403 /* We must now download the power adjust value (gain) to
3404 * the synthetisers (from the EEprom - area 7 - DAC) */
3405 m.mmw_fee_addr = 0x61;
3406 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3407 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3408 (unsigned char *)&m.mmw_fee_ctrl, 2);
3410 /* Wait until the download is finished */
3411 } /* if 2.00 card */
3413 #ifdef DEBUG_CONFIG_TRACE
3414 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3415 #endif
3416 return TRUE;
3419 /*------------------------------------------------------------------*/
3421 * Routine to gracefully turn off reception, and wait for any commands
3422 * to complete.
3423 * (called in wv_ru_start() and wavelan_close() and wavelan_event())
3425 static int
3426 wv_ru_stop(struct net_device * dev)
3428 kio_addr_t base = dev->base_addr;
3429 net_local * lp = netdev_priv(dev);
3430 unsigned long flags;
3431 int status;
3432 int spin;
3434 #ifdef DEBUG_CONFIG_TRACE
3435 printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
3436 #endif
3438 spin_lock_irqsave(&lp->spinlock, flags);
3440 /* First, send the LAN controller a stop receive command */
3441 wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
3442 OP0_STOP_RCV, SR0_NO_RESULT);
3444 /* Then, spin until the receive unit goes idle */
3445 spin = 300;
3448 udelay(10);
3449 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3450 status = inb(LCSR(base));
3452 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
3454 /* Now, spin until the chip finishes executing its current command */
3457 udelay(10);
3458 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3459 status = inb(LCSR(base));
3461 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
3463 spin_unlock_irqrestore(&lp->spinlock, flags);
3465 /* If there was a problem */
3466 if(spin <= 0)
3468 #ifdef DEBUG_CONFIG_ERRORS
3469 printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
3470 dev->name);
3471 #endif
3472 return FALSE;
3475 #ifdef DEBUG_CONFIG_TRACE
3476 printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
3477 #endif
3478 return TRUE;
3479 } /* wv_ru_stop */
3481 /*------------------------------------------------------------------*/
3483 * This routine starts the receive unit running. First, it checks if
3484 * the card is actually ready. Then the card is instructed to receive
3485 * packets again.
3486 * (called in wv_hw_reset() & wavelan_open())
3488 static int
3489 wv_ru_start(struct net_device * dev)
3491 kio_addr_t base = dev->base_addr;
3492 net_local * lp = netdev_priv(dev);
3493 unsigned long flags;
3495 #ifdef DEBUG_CONFIG_TRACE
3496 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3497 #endif
3500 * We need to start from a quiescent state. To do so, we could check
3501 * if the card is already running, but instead we just try to shut
3502 * it down. First, we disable reception (in case it was already enabled).
3504 if(!wv_ru_stop(dev))
3505 return FALSE;
3507 spin_lock_irqsave(&lp->spinlock, flags);
3509 /* Now we know that no command is being executed. */
3511 /* Set the receive frame pointer and stop pointer */
3512 lp->rfp = 0;
3513 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3515 /* Reset ring management. This sets the receive frame pointer to 1 */
3516 outb(OP1_RESET_RING_MNGMT, LCCR(base));
3518 #if 0
3519 /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
3520 should be set as below */
3521 /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
3522 #elif 0
3523 /* but I set it 0 instead */
3524 lp->stop = 0;
3525 #else
3526 /* but I set it to 3 bytes per packet less than 8K */
3527 lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3528 #endif
3529 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3530 outb(OP1_INT_ENABLE, LCCR(base));
3531 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3533 /* Reset receive DMA pointer */
3534 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3535 hacr_write_slow(base, HACR_DEFAULT);
3537 /* Receive DMA on channel 1 */
3538 wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
3539 CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
3541 #ifdef DEBUG_I82593_SHOW
3543 int status;
3544 int opri;
3545 int spin = 10000;
3547 /* spin until the chip starts receiving */
3550 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3551 status = inb(LCSR(base));
3552 if(spin-- <= 0)
3553 break;
3555 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
3556 ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
3557 printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
3558 (status & SR3_RCV_STATE_MASK), i);
3560 #endif
3562 spin_unlock_irqrestore(&lp->spinlock, flags);
3564 #ifdef DEBUG_CONFIG_TRACE
3565 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3566 #endif
3567 return TRUE;
3570 /*------------------------------------------------------------------*/
3572 * This routine does a standard config of the WaveLAN controller (i82593).
3573 * In the ISA driver, this is integrated in wavelan_hardware_reset()
3574 * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
3576 static int
3577 wv_82593_config(struct net_device * dev)
3579 kio_addr_t base = dev->base_addr;
3580 net_local * lp = netdev_priv(dev);
3581 struct i82593_conf_block cfblk;
3582 int ret = TRUE;
3584 #ifdef DEBUG_CONFIG_TRACE
3585 printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
3586 #endif
3588 /* Create & fill i82593 config block
3590 * Now conform to Wavelan document WCIN085B
3592 memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
3593 cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
3594 cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
3595 cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
3596 cfblk.fifo_32 = 1;
3597 cfblk.throttle_enb = FALSE;
3598 cfblk.contin = TRUE; /* enable continuous mode */
3599 cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
3600 cfblk.addr_len = WAVELAN_ADDR_SIZE;
3601 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
3602 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
3603 cfblk.loopback = FALSE;
3604 cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */
3605 cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */
3606 cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */
3607 cfblk.ifrm_spc = 0x20; /* 32 bit times interframe spacing */
3608 cfblk.slottim_low = 0x20; /* 32 bit times slot time */
3609 cfblk.slottim_hi = 0x0;
3610 cfblk.max_retr = 15;
3611 cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
3612 cfblk.bc_dis = FALSE; /* Enable broadcast reception */
3613 cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
3614 cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
3615 cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
3616 cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
3617 cfblk.cs_filter = 0; /* CS is recognized immediately */
3618 cfblk.crs_src = FALSE; /* External carrier sense */
3619 cfblk.cd_filter = 0; /* CD is recognized immediately */
3620 cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
3621 cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
3622 cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
3623 cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
3624 cfblk.artx = TRUE; /* Disable automatic retransmission */
3625 cfblk.sarec = TRUE; /* Disable source addr trig of CD */
3626 cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
3627 cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
3628 cfblk.lbpkpol = TRUE; /* Loopback pin active high */
3629 cfblk.fdx = FALSE; /* Disable full duplex operation */
3630 cfblk.dummy_6 = 0x3f; /* all ones */
3631 cfblk.mult_ia = FALSE; /* No multiple individual addresses */
3632 cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
3633 cfblk.dummy_1 = TRUE; /* set to 1 */
3634 cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
3635 #ifdef MULTICAST_ALL
3636 cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
3637 #else
3638 cfblk.mc_all = FALSE; /* No multicast all mode */
3639 #endif
3640 cfblk.rcv_mon = 0; /* Monitor mode disabled */
3641 cfblk.frag_acpt = TRUE; /* Do not accept fragments */
3642 cfblk.tstrttrs = FALSE; /* No start transmission threshold */
3643 cfblk.fretx = TRUE; /* FIFO automatic retransmission */
3644 cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
3645 cfblk.sttlen = TRUE; /* 6 byte status registers */
3646 cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
3647 cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
3648 cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
3649 cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
3651 #ifdef DEBUG_I82593_SHOW
3653 u_char *c = (u_char *) &cfblk;
3654 int i;
3655 printk(KERN_DEBUG "wavelan_cs: config block:");
3656 for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
3658 if((i % 16) == 0) printk("\n" KERN_DEBUG);
3659 printk("%02x ", *c);
3661 printk("\n");
3663 #endif
3665 /* Copy the config block to the i82593 */
3666 outb(TX_BASE & 0xff, PIORL(base));
3667 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3668 outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
3669 outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
3670 outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
3672 /* reset transmit DMA pointer */
3673 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3674 hacr_write(base, HACR_DEFAULT);
3675 if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
3676 OP0_CONFIGURE, SR0_CONFIGURE_DONE))
3677 ret = FALSE;
3679 /* Initialize adapter's ethernet MAC address */
3680 outb(TX_BASE & 0xff, PIORL(base));
3681 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3682 outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
3683 outb(0, PIOP(base)); /* byte count msb */
3684 outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
3686 /* reset transmit DMA pointer */
3687 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3688 hacr_write(base, HACR_DEFAULT);
3689 if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
3690 OP0_IA_SETUP, SR0_IA_SETUP_DONE))
3691 ret = FALSE;
3693 #ifdef WAVELAN_ROAMING
3694 /* If roaming is enabled, join the "Beacon Request" multicast group... */
3695 /* But only if it's not in there already! */
3696 if(do_roaming)
3697 dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
3698 #endif /* WAVELAN_ROAMING */
3700 /* If any multicast address to set */
3701 if(lp->mc_count)
3703 struct dev_mc_list * dmi;
3704 int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
3706 #ifdef DEBUG_CONFIG_INFO
3707 printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
3708 dev->name, lp->mc_count);
3709 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3710 printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n",
3711 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
3712 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
3713 #endif
3715 /* Initialize adapter's ethernet multicast addresses */
3716 outb(TX_BASE & 0xff, PIORL(base));
3717 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3718 outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
3719 outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
3720 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3721 outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
3723 /* reset transmit DMA pointer */
3724 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3725 hacr_write(base, HACR_DEFAULT);
3726 if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
3727 OP0_MC_SETUP, SR0_MC_SETUP_DONE))
3728 ret = FALSE;
3729 lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
3732 /* Job done, clear the flag */
3733 lp->reconfig_82593 = FALSE;
3735 #ifdef DEBUG_CONFIG_TRACE
3736 printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
3737 #endif
3738 return(ret);
3741 /*------------------------------------------------------------------*/
3743 * Read the Access Configuration Register, perform a software reset,
3744 * and then re-enable the card's software.
3746 * If I understand correctly : reset the pcmcia interface of the
3747 * wavelan.
3748 * (called by wv_config())
3750 static inline int
3751 wv_pcmcia_reset(struct net_device * dev)
3753 int i;
3754 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
3755 dev_link_t * link = ((net_local *)netdev_priv(dev))->link;
3757 #ifdef DEBUG_CONFIG_TRACE
3758 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
3759 #endif
3761 i = pcmcia_access_configuration_register(link->handle, &reg);
3762 if(i != CS_SUCCESS)
3764 cs_error(link->handle, AccessConfigurationRegister, i);
3765 return FALSE;
3768 #ifdef DEBUG_CONFIG_INFO
3769 printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
3770 dev->name, (u_int) reg.Value);
3771 #endif
3773 reg.Action = CS_WRITE;
3774 reg.Value = reg.Value | COR_SW_RESET;
3775 i = pcmcia_access_configuration_register(link->handle, &reg);
3776 if(i != CS_SUCCESS)
3778 cs_error(link->handle, AccessConfigurationRegister, i);
3779 return FALSE;
3782 reg.Action = CS_WRITE;
3783 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3784 i = pcmcia_access_configuration_register(link->handle, &reg);
3785 if(i != CS_SUCCESS)
3787 cs_error(link->handle, AccessConfigurationRegister, i);
3788 return FALSE;
3791 #ifdef DEBUG_CONFIG_TRACE
3792 printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
3793 #endif
3794 return TRUE;
3797 /*------------------------------------------------------------------*/
3799 * wavelan_hw_config() is called after a CARD_INSERTION event is
3800 * received, to configure the wavelan hardware.
3801 * Note that the reception will be enabled in wavelan->open(), so the
3802 * device is configured but idle...
3803 * Performs the following actions:
3804 * 1. A pcmcia software reset (using wv_pcmcia_reset())
3805 * 2. A power reset (reset DMA)
3806 * 3. Reset the LAN controller
3807 * 4. Initialize the radio modem (using wv_mmc_init)
3808 * 5. Configure LAN controller (using wv_82593_config)
3809 * 6. Perform a diagnostic on the LAN controller
3810 * (called by wavelan_event() & wv_hw_reset())
3812 static int
3813 wv_hw_config(struct net_device * dev)
3815 net_local * lp = netdev_priv(dev);
3816 kio_addr_t base = dev->base_addr;
3817 unsigned long flags;
3818 int ret = FALSE;
3820 #ifdef DEBUG_CONFIG_TRACE
3821 printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
3822 #endif
3824 #ifdef STRUCT_CHECK
3825 if(wv_structuct_check() != (char *) NULL)
3827 printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: \"%s\"\n",
3828 dev->name, wv_structuct_check());
3829 return FALSE;
3831 #endif /* STRUCT_CHECK == 1 */
3833 /* Reset the pcmcia interface */
3834 if(wv_pcmcia_reset(dev) == FALSE)
3835 return FALSE;
3837 /* Disable interrupts */
3838 spin_lock_irqsave(&lp->spinlock, flags);
3840 /* Disguised goto ;-) */
3843 /* Power UP the module + reset the modem + reset host adapter
3844 * (in fact, reset DMA channels) */
3845 hacr_write_slow(base, HACR_RESET);
3846 hacr_write(base, HACR_DEFAULT);
3848 /* Check if the module has been powered up... */
3849 if(hasr_read(base) & HASR_NO_CLK)
3851 #ifdef DEBUG_CONFIG_ERRORS
3852 printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
3853 dev->name);
3854 #endif
3855 break;
3858 /* initialize the modem */
3859 if(wv_mmc_init(dev) == FALSE)
3861 #ifdef DEBUG_CONFIG_ERRORS
3862 printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n",
3863 dev->name);
3864 #endif
3865 break;
3868 /* reset the LAN controller (i82593) */
3869 outb(OP0_RESET, LCCR(base));
3870 mdelay(1); /* A bit crude ! */
3872 /* Initialize the LAN controller */
3873 if(wv_82593_config(dev) == FALSE)
3875 #ifdef DEBUG_CONFIG_ERRORS
3876 printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n",
3877 dev->name);
3878 #endif
3879 break;
3882 /* Diagnostic */
3883 if(wv_diag(dev) == FALSE)
3885 #ifdef DEBUG_CONFIG_ERRORS
3886 printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n",
3887 dev->name);
3888 #endif
3889 break;
3893 * insert code for loopback test here
3896 /* The device is now configured */
3897 lp->configured = 1;
3898 ret = TRUE;
3900 while(0);
3902 /* Re-enable interrupts */
3903 spin_unlock_irqrestore(&lp->spinlock, flags);
3905 #ifdef DEBUG_CONFIG_TRACE
3906 printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
3907 #endif
3908 return(ret);
3911 /*------------------------------------------------------------------*/
3913 * Totally reset the wavelan and restart it.
3914 * Performs the following actions:
3915 * 1. Call wv_hw_config()
3916 * 2. Start the LAN controller's receive unit
3917 * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
3919 static inline void
3920 wv_hw_reset(struct net_device * dev)
3922 net_local * lp = netdev_priv(dev);
3924 #ifdef DEBUG_CONFIG_TRACE
3925 printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
3926 #endif
3928 lp->nresets++;
3929 lp->configured = 0;
3931 /* Call wv_hw_config() for most of the reset & init stuff */
3932 if(wv_hw_config(dev) == FALSE)
3933 return;
3935 /* start receive unit */
3936 wv_ru_start(dev);
3938 #ifdef DEBUG_CONFIG_TRACE
3939 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3940 #endif
3943 /*------------------------------------------------------------------*/
3945 * wv_pcmcia_config() is called after a CARD_INSERTION event is
3946 * received, to configure the PCMCIA socket, and to make the ethernet
3947 * device available to the system.
3948 * (called by wavelan_event())
3950 static inline int
3951 wv_pcmcia_config(dev_link_t * link)
3953 client_handle_t handle = link->handle;
3954 tuple_t tuple;
3955 cisparse_t parse;
3956 struct net_device * dev = (struct net_device *) link->priv;
3957 int i;
3958 u_char buf[64];
3959 win_req_t req;
3960 memreq_t mem;
3961 net_local * lp = netdev_priv(dev);
3964 #ifdef DEBUG_CONFIG_TRACE
3965 printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
3966 #endif
3969 * This reads the card's CONFIG tuple to find its configuration
3970 * registers.
3974 tuple.Attributes = 0;
3975 tuple.DesiredTuple = CISTPL_CONFIG;
3976 i = pcmcia_get_first_tuple(handle, &tuple);
3977 if(i != CS_SUCCESS)
3978 break;
3979 tuple.TupleData = (cisdata_t *)buf;
3980 tuple.TupleDataMax = 64;
3981 tuple.TupleOffset = 0;
3982 i = pcmcia_get_tuple_data(handle, &tuple);
3983 if(i != CS_SUCCESS)
3984 break;
3985 i = pcmcia_parse_tuple(handle, &tuple, &parse);
3986 if(i != CS_SUCCESS)
3987 break;
3988 link->conf.ConfigBase = parse.config.base;
3989 link->conf.Present = parse.config.rmask[0];
3991 while(0);
3992 if(i != CS_SUCCESS)
3994 cs_error(link->handle, ParseTuple, i);
3995 link->state &= ~DEV_CONFIG_PENDING;
3996 return FALSE;
3999 /* Configure card */
4000 link->state |= DEV_CONFIG;
4003 i = pcmcia_request_io(link->handle, &link->io);
4004 if(i != CS_SUCCESS)
4006 cs_error(link->handle, RequestIO, i);
4007 break;
4011 * Now allocate an interrupt line. Note that this does not
4012 * actually assign a handler to the interrupt.
4014 i = pcmcia_request_irq(link->handle, &link->irq);
4015 if(i != CS_SUCCESS)
4017 cs_error(link->handle, RequestIRQ, i);
4018 break;
4022 * This actually configures the PCMCIA socket -- setting up
4023 * the I/O windows and the interrupt mapping.
4025 link->conf.ConfigIndex = 1;
4026 i = pcmcia_request_configuration(link->handle, &link->conf);
4027 if(i != CS_SUCCESS)
4029 cs_error(link->handle, RequestConfiguration, i);
4030 break;
4034 * Allocate a small memory window. Note that the dev_link_t
4035 * structure provides space for one window handle -- if your
4036 * device needs several windows, you'll need to keep track of
4037 * the handles in your private data structure, link->priv.
4039 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
4040 req.Base = req.Size = 0;
4041 req.AccessSpeed = mem_speed;
4042 i = pcmcia_request_window(&link->handle, &req, &link->win);
4043 if(i != CS_SUCCESS)
4045 cs_error(link->handle, RequestWindow, i);
4046 break;
4049 lp->mem = ioremap(req.Base, req.Size);
4050 dev->mem_start = (u_long)lp->mem;
4051 dev->mem_end = dev->mem_start + req.Size;
4053 mem.CardOffset = 0; mem.Page = 0;
4054 i = pcmcia_map_mem_page(link->win, &mem);
4055 if(i != CS_SUCCESS)
4057 cs_error(link->handle, MapMemPage, i);
4058 break;
4061 /* Feed device with this info... */
4062 dev->irq = link->irq.AssignedIRQ;
4063 dev->base_addr = link->io.BasePort1;
4064 netif_start_queue(dev);
4066 #ifdef DEBUG_CONFIG_INFO
4067 printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART %p IRQ %d IOPORT 0x%x\n",
4068 lp->mem, dev->irq, (u_int) dev->base_addr);
4069 #endif
4071 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
4072 i = register_netdev(dev);
4073 if(i != 0)
4075 #ifdef DEBUG_CONFIG_ERRORS
4076 printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
4077 #endif
4078 break;
4081 while(0); /* Humm... Disguised goto !!! */
4083 link->state &= ~DEV_CONFIG_PENDING;
4084 /* If any step failed, release any partially configured state */
4085 if(i != 0)
4087 wv_pcmcia_release(link);
4088 return FALSE;
4091 strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
4092 link->dev = &((net_local *) netdev_priv(dev))->node;
4094 #ifdef DEBUG_CONFIG_TRACE
4095 printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
4096 #endif
4097 return TRUE;
4100 /*------------------------------------------------------------------*/
4102 * After a card is removed, wv_pcmcia_release() will unregister the net
4103 * device, and release the PCMCIA configuration. If the device is
4104 * still open, this will be postponed until it is closed.
4106 static void
4107 wv_pcmcia_release(dev_link_t *link)
4109 struct net_device * dev = (struct net_device *) link->priv;
4110 net_local * lp = netdev_priv(dev);
4112 #ifdef DEBUG_CONFIG_TRACE
4113 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
4114 #endif
4116 /* Don't bother checking to see if these succeed or not */
4117 iounmap(lp->mem);
4118 pcmcia_release_window(link->win);
4119 pcmcia_release_configuration(link->handle);
4120 pcmcia_release_io(link->handle, &link->io);
4121 pcmcia_release_irq(link->handle, &link->irq);
4123 link->state &= ~DEV_CONFIG;
4125 #ifdef DEBUG_CONFIG_TRACE
4126 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
4127 #endif
4130 /************************ INTERRUPT HANDLING ************************/
4133 * This function is the interrupt handler for the WaveLAN card. This
4134 * routine will be called whenever:
4135 * 1. A packet is received.
4136 * 2. A packet has successfully been transferred and the unit is
4137 * ready to transmit another packet.
4138 * 3. A command has completed execution.
4140 static irqreturn_t
4141 wavelan_interrupt(int irq,
4142 void * dev_id,
4143 struct pt_regs * regs)
4145 struct net_device * dev;
4146 net_local * lp;
4147 kio_addr_t base;
4148 int status0;
4149 u_int tx_status;
4151 if ((dev = dev_id) == NULL)
4153 #ifdef DEBUG_INTERRUPT_ERROR
4154 printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.\n",
4155 irq);
4156 #endif
4157 return IRQ_NONE;
4160 #ifdef DEBUG_INTERRUPT_TRACE
4161 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
4162 #endif
4164 lp = netdev_priv(dev);
4165 base = dev->base_addr;
4167 #ifdef DEBUG_INTERRUPT_INFO
4168 /* Check state of our spinlock (it should be cleared) */
4169 if(spin_is_locked(&lp->spinlock))
4170 printk(KERN_DEBUG
4171 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
4172 dev->name);
4173 #endif
4175 /* Prevent reentrancy. We need to do that because we may have
4176 * multiple interrupt handler running concurently.
4177 * It is safe because interrupts are disabled before aquiring
4178 * the spinlock. */
4179 spin_lock(&lp->spinlock);
4181 /* Treat all pending interrupts */
4182 while(1)
4184 /* ---------------- INTERRUPT CHECKING ---------------- */
4186 * Look for the interrupt and verify the validity
4188 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
4189 status0 = inb(LCSR(base));
4191 #ifdef DEBUG_INTERRUPT_INFO
4192 printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
4193 (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
4194 if(status0&SR0_INTERRUPT)
4196 printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
4197 ((status0 & SR0_EXECUTION) ? "cmd" :
4198 ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
4199 (status0 & SR0_EVENT_MASK));
4201 else
4202 printk("\n");
4203 #endif
4205 /* Return if no actual interrupt from i82593 (normal exit) */
4206 if(!(status0 & SR0_INTERRUPT))
4207 break;
4209 /* If interrupt is both Rx and Tx or none...
4210 * This code in fact is there to catch the spurious interrupt
4211 * when you remove the wavelan pcmcia card from the socket */
4212 if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
4213 ((status0 & SR0_BOTH_RX_TX) == 0x0))
4215 #ifdef DEBUG_INTERRUPT_INFO
4216 printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
4217 dev->name, status0);
4218 #endif
4219 /* Acknowledge the interrupt */
4220 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4221 break;
4224 /* ----------------- RECEIVING PACKET ----------------- */
4226 * When the wavelan signal the reception of a new packet,
4227 * we call wv_packet_rcv() to copy if from the buffer and
4228 * send it to NET3
4230 if(status0 & SR0_RECEPTION)
4232 #ifdef DEBUG_INTERRUPT_INFO
4233 printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
4234 #endif
4236 if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
4238 #ifdef DEBUG_INTERRUPT_ERROR
4239 printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
4240 dev->name);
4241 #endif
4242 lp->stats.rx_over_errors++;
4243 lp->overrunning = 1;
4246 /* Get the packet */
4247 wv_packet_rcv(dev);
4248 lp->overrunning = 0;
4250 /* Acknowledge the interrupt */
4251 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4252 continue;
4255 /* ---------------- COMMAND COMPLETION ---------------- */
4257 * Interrupts issued when the i82593 has completed a command.
4258 * Most likely : transmission done
4261 /* If a transmission has been done */
4262 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
4263 (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
4264 (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4266 #ifdef DEBUG_TX_ERROR
4267 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4268 printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
4269 dev->name);
4270 #endif
4272 /* Get transmission status */
4273 tx_status = inb(LCSR(base));
4274 tx_status |= (inb(LCSR(base)) << 8);
4275 #ifdef DEBUG_INTERRUPT_INFO
4276 printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
4277 dev->name);
4279 u_int rcv_bytes;
4280 u_char status3;
4281 rcv_bytes = inb(LCSR(base));
4282 rcv_bytes |= (inb(LCSR(base)) << 8);
4283 status3 = inb(LCSR(base));
4284 printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
4285 tx_status, rcv_bytes, (u_int) status3);
4287 #endif
4288 /* Check for possible errors */
4289 if((tx_status & TX_OK) != TX_OK)
4291 lp->stats.tx_errors++;
4293 if(tx_status & TX_FRTL)
4295 #ifdef DEBUG_TX_ERROR
4296 printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
4297 dev->name);
4298 #endif
4300 if(tx_status & TX_UND_RUN)
4302 #ifdef DEBUG_TX_FAIL
4303 printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
4304 dev->name);
4305 #endif
4306 lp->stats.tx_aborted_errors++;
4308 if(tx_status & TX_LOST_CTS)
4310 #ifdef DEBUG_TX_FAIL
4311 printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
4312 #endif
4313 lp->stats.tx_carrier_errors++;
4315 if(tx_status & TX_LOST_CRS)
4317 #ifdef DEBUG_TX_FAIL
4318 printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
4319 dev->name);
4320 #endif
4321 lp->stats.tx_carrier_errors++;
4323 if(tx_status & TX_HRT_BEAT)
4325 #ifdef DEBUG_TX_FAIL
4326 printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
4327 #endif
4328 lp->stats.tx_heartbeat_errors++;
4330 if(tx_status & TX_DEFER)
4332 #ifdef DEBUG_TX_FAIL
4333 printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
4334 dev->name);
4335 #endif
4337 /* Ignore late collisions since they're more likely to happen
4338 * here (the WaveLAN design prevents the LAN controller from
4339 * receiving while it is transmitting). We take action only when
4340 * the maximum retransmit attempts is exceeded.
4342 if(tx_status & TX_COLL)
4344 if(tx_status & TX_MAX_COL)
4346 #ifdef DEBUG_TX_FAIL
4347 printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
4348 dev->name);
4349 #endif
4350 if(!(tx_status & TX_NCOL_MASK))
4352 lp->stats.collisions += 0x10;
4356 } /* if(!(tx_status & TX_OK)) */
4358 lp->stats.collisions += (tx_status & TX_NCOL_MASK);
4359 lp->stats.tx_packets++;
4361 netif_wake_queue(dev);
4362 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4364 else /* if interrupt = transmit done or retransmit done */
4366 #ifdef DEBUG_INTERRUPT_ERROR
4367 printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
4368 status0);
4369 #endif
4370 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4372 } /* while(1) */
4374 spin_unlock(&lp->spinlock);
4376 #ifdef DEBUG_INTERRUPT_TRACE
4377 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
4378 #endif
4380 /* We always return IRQ_HANDLED, because we will receive empty
4381 * interrupts under normal operations. Anyway, it doesn't matter
4382 * as we are dealing with an ISA interrupt that can't be shared.
4384 * Explanation : under heavy receive, the following happens :
4385 * ->wavelan_interrupt()
4386 * (status0 & SR0_INTERRUPT) != 0
4387 * ->wv_packet_rcv()
4388 * (status0 & SR0_INTERRUPT) != 0
4389 * ->wv_packet_rcv()
4390 * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event
4391 * <-wavelan_interrupt()
4392 * ->wavelan_interrupt()
4393 * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt
4394 * <-wavelan_interrupt()
4395 * Jean II */
4396 return IRQ_HANDLED;
4397 } /* wv_interrupt */
4399 /*------------------------------------------------------------------*/
4401 * Watchdog: when we start a transmission, a timer is set for us in the
4402 * kernel. If the transmission completes, this timer is disabled. If
4403 * the timer expires, we are called and we try to unlock the hardware.
4405 * Note : This watchdog is move clever than the one in the ISA driver,
4406 * because it try to abort the current command before reseting
4407 * everything...
4408 * On the other hand, it's a bit simpler, because we don't have to
4409 * deal with the multiple Tx buffers...
4411 static void
4412 wavelan_watchdog(struct net_device * dev)
4414 net_local * lp = netdev_priv(dev);
4415 kio_addr_t base = dev->base_addr;
4416 unsigned long flags;
4417 int aborted = FALSE;
4419 #ifdef DEBUG_INTERRUPT_TRACE
4420 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
4421 #endif
4423 #ifdef DEBUG_INTERRUPT_ERROR
4424 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
4425 dev->name);
4426 #endif
4428 spin_lock_irqsave(&lp->spinlock, flags);
4430 /* Ask to abort the current command */
4431 outb(OP0_ABORT, LCCR(base));
4433 /* Wait for the end of the command (a bit hackish) */
4434 if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
4435 OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
4436 aborted = TRUE;
4438 /* Release spinlock here so that wv_hw_reset() can grab it */
4439 spin_unlock_irqrestore(&lp->spinlock, flags);
4441 /* Check if we were successful in aborting it */
4442 if(!aborted)
4444 /* It seem that it wasn't enough */
4445 #ifdef DEBUG_INTERRUPT_ERROR
4446 printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
4447 dev->name);
4448 #endif
4449 wv_hw_reset(dev);
4452 #ifdef DEBUG_PSA_SHOW
4454 psa_t psa;
4455 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
4456 wv_psa_show(&psa);
4458 #endif
4459 #ifdef DEBUG_MMC_SHOW
4460 wv_mmc_show(dev);
4461 #endif
4462 #ifdef DEBUG_I82593_SHOW
4463 wv_ru_show(dev);
4464 #endif
4466 /* We are no more waiting for something... */
4467 netif_wake_queue(dev);
4469 #ifdef DEBUG_INTERRUPT_TRACE
4470 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
4471 #endif
4474 /********************* CONFIGURATION CALLBACKS *********************/
4476 * Here are the functions called by the pcmcia package (cardmgr) and
4477 * linux networking (NET3) for initialization, configuration and
4478 * deinstallations of the Wavelan Pcmcia Hardware.
4481 /*------------------------------------------------------------------*/
4483 * Configure and start up the WaveLAN PCMCIA adaptor.
4484 * Called by NET3 when it "open" the device.
4486 static int
4487 wavelan_open(struct net_device * dev)
4489 net_local * lp = netdev_priv(dev);
4490 dev_link_t * link = lp->link;
4491 kio_addr_t base = dev->base_addr;
4493 #ifdef DEBUG_CALLBACK_TRACE
4494 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
4495 (unsigned int) dev);
4496 #endif
4498 /* Check if the modem is powered up (wavelan_close() power it down */
4499 if(hasr_read(base) & HASR_NO_CLK)
4501 /* Power up (power up time is 250us) */
4502 hacr_write(base, HACR_DEFAULT);
4504 /* Check if the module has been powered up... */
4505 if(hasr_read(base) & HASR_NO_CLK)
4507 #ifdef DEBUG_CONFIG_ERRORS
4508 printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
4509 dev->name);
4510 #endif
4511 return FALSE;
4515 /* Start reception and declare the driver ready */
4516 if(!lp->configured)
4517 return FALSE;
4518 if(!wv_ru_start(dev))
4519 wv_hw_reset(dev); /* If problem : reset */
4520 netif_start_queue(dev);
4522 /* Mark the device as used */
4523 link->open++;
4525 #ifdef WAVELAN_ROAMING
4526 if(do_roaming)
4527 wv_roam_init(dev);
4528 #endif /* WAVELAN_ROAMING */
4530 #ifdef DEBUG_CALLBACK_TRACE
4531 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
4532 #endif
4533 return 0;
4536 /*------------------------------------------------------------------*/
4538 * Shutdown the WaveLAN PCMCIA adaptor.
4539 * Called by NET3 when it "close" the device.
4541 static int
4542 wavelan_close(struct net_device * dev)
4544 dev_link_t * link = ((net_local *)netdev_priv(dev))->link;
4545 kio_addr_t base = dev->base_addr;
4547 #ifdef DEBUG_CALLBACK_TRACE
4548 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
4549 (unsigned int) dev);
4550 #endif
4552 /* If the device isn't open, then nothing to do */
4553 if(!link->open)
4555 #ifdef DEBUG_CONFIG_INFO
4556 printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
4557 #endif
4558 return 0;
4561 #ifdef WAVELAN_ROAMING
4562 /* Cleanup of roaming stuff... */
4563 if(do_roaming)
4564 wv_roam_cleanup(dev);
4565 #endif /* WAVELAN_ROAMING */
4567 link->open--;
4569 /* If the card is still present */
4570 if(netif_running(dev))
4572 netif_stop_queue(dev);
4574 /* Stop receiving new messages and wait end of transmission */
4575 wv_ru_stop(dev);
4577 /* Power down the module */
4578 hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
4581 #ifdef DEBUG_CALLBACK_TRACE
4582 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
4583 #endif
4584 return 0;
4587 /*------------------------------------------------------------------*/
4589 * wavelan_attach() creates an "instance" of the driver, allocating
4590 * local data structures for one device (one interface). The device
4591 * is registered with Card Services.
4593 * The dev_link structure is initialized, but we don't actually
4594 * configure the card at this point -- we wait until we receive a
4595 * card insertion event.
4597 static dev_link_t *
4598 wavelan_attach(void)
4600 client_reg_t client_reg; /* Register with cardmgr */
4601 dev_link_t * link; /* Info for cardmgr */
4602 struct net_device * dev; /* Interface generic data */
4603 net_local * lp; /* Interface specific data */
4604 int ret;
4606 #ifdef DEBUG_CALLBACK_TRACE
4607 printk(KERN_DEBUG "-> wavelan_attach()\n");
4608 #endif
4610 /* Initialize the dev_link_t structure */
4611 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
4612 if (!link) return NULL;
4614 /* The io structure describes IO port mapping */
4615 link->io.NumPorts1 = 8;
4616 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
4617 link->io.IOAddrLines = 3;
4619 /* Interrupt setup */
4620 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
4621 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
4622 link->irq.Handler = wavelan_interrupt;
4624 /* General socket configuration */
4625 link->conf.Attributes = CONF_ENABLE_IRQ;
4626 link->conf.Vcc = 50;
4627 link->conf.IntType = INT_MEMORY_AND_IO;
4629 /* Chain drivers */
4630 link->next = dev_list;
4631 dev_list = link;
4633 /* Allocate the generic data structure */
4634 dev = alloc_etherdev(sizeof(net_local));
4635 if (!dev) {
4636 kfree(link);
4637 return NULL;
4639 link->priv = link->irq.Instance = dev;
4641 lp = netdev_priv(dev);
4643 /* Init specific data */
4644 lp->configured = 0;
4645 lp->reconfig_82593 = FALSE;
4646 lp->nresets = 0;
4647 /* Multicast stuff */
4648 lp->promiscuous = 0;
4649 lp->allmulticast = 0;
4650 lp->mc_count = 0;
4652 /* Init spinlock */
4653 spin_lock_init(&lp->spinlock);
4655 /* back links */
4656 lp->link = link;
4657 lp->dev = dev;
4659 /* wavelan NET3 callbacks */
4660 SET_MODULE_OWNER(dev);
4661 dev->open = &wavelan_open;
4662 dev->stop = &wavelan_close;
4663 dev->hard_start_xmit = &wavelan_packet_xmit;
4664 dev->get_stats = &wavelan_get_stats;
4665 dev->set_multicast_list = &wavelan_set_multicast_list;
4666 #ifdef SET_MAC_ADDRESS
4667 dev->set_mac_address = &wavelan_set_mac_address;
4668 #endif /* SET_MAC_ADDRESS */
4670 /* Set the watchdog timer */
4671 dev->tx_timeout = &wavelan_watchdog;
4672 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4673 SET_ETHTOOL_OPS(dev, &ops);
4675 dev->wireless_handlers = &wavelan_handler_def;
4676 lp->wireless_data.spy_data = &lp->spy_data;
4677 dev->wireless_data = &lp->wireless_data;
4679 /* Other specific data */
4680 dev->mtu = WAVELAN_MTU;
4682 /* Register with Card Services */
4683 client_reg.dev_info = &dev_info;
4684 client_reg.Version = 0x0210;
4685 client_reg.event_callback_args.client_data = link;
4687 #ifdef DEBUG_CONFIG_INFO
4688 printk(KERN_DEBUG "wavelan_attach(): almost done, calling pcmcia_register_client\n");
4689 #endif
4691 ret = pcmcia_register_client(&link->handle, &client_reg);
4692 if(ret != 0)
4694 cs_error(link->handle, RegisterClient, ret);
4695 wavelan_detach(link);
4696 return NULL;
4699 #ifdef DEBUG_CALLBACK_TRACE
4700 printk(KERN_DEBUG "<- wavelan_attach()\n");
4701 #endif
4703 return link;
4706 /*------------------------------------------------------------------*/
4708 * This deletes a driver "instance". The device is de-registered with
4709 * Card Services. If it has been released, all local data structures
4710 * are freed. Otherwise, the structures will be freed when the device
4711 * is released.
4713 static void
4714 wavelan_detach(dev_link_t * link)
4716 #ifdef DEBUG_CALLBACK_TRACE
4717 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4718 #endif
4721 * If the device is currently configured and active, we won't
4722 * actually delete it yet. Instead, it is marked so that when the
4723 * release() function is called, that will trigger a proper
4724 * detach().
4726 if(link->state & DEV_CONFIG)
4728 /* Some others haven't done their job : give them another chance */
4729 wv_pcmcia_release(link);
4732 /* Break the link with Card Services */
4733 if(link->handle)
4734 pcmcia_deregister_client(link->handle);
4736 /* Remove the interface data from the linked list */
4737 if(dev_list == link)
4738 dev_list = link->next;
4739 else
4741 dev_link_t * prev = dev_list;
4743 while((prev != (dev_link_t *) NULL) && (prev->next != link))
4744 prev = prev->next;
4746 if(prev == (dev_link_t *) NULL)
4748 #ifdef DEBUG_CONFIG_ERRORS
4749 printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.\n");
4750 #endif
4751 return;
4754 prev->next = link->next;
4757 /* Free pieces */
4758 if(link->priv)
4760 struct net_device * dev = (struct net_device *) link->priv;
4762 /* Remove ourselves from the kernel list of ethernet devices */
4763 /* Warning : can't be called from interrupt, timer or wavelan_close() */
4764 if (link->dev)
4765 unregister_netdev(dev);
4766 link->dev = NULL;
4767 ((net_local *)netdev_priv(dev))->link = NULL;
4768 ((net_local *)netdev_priv(dev))->dev = NULL;
4769 free_netdev(dev);
4771 kfree(link);
4773 #ifdef DEBUG_CALLBACK_TRACE
4774 printk(KERN_DEBUG "<- wavelan_detach()\n");
4775 #endif
4778 /*------------------------------------------------------------------*/
4780 * The card status event handler. Mostly, this schedules other stuff
4781 * to run after an event is received. A CARD_REMOVAL event also sets
4782 * some flags to discourage the net drivers from trying to talk to the
4783 * card any more.
4785 static int
4786 wavelan_event(event_t event, /* The event received */
4787 int priority,
4788 event_callback_args_t * args)
4790 dev_link_t * link = (dev_link_t *) args->client_data;
4791 struct net_device * dev = (struct net_device *) link->priv;
4793 #ifdef DEBUG_CALLBACK_TRACE
4794 printk(KERN_DEBUG "->wavelan_event(): %s\n",
4795 ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" :
4796 ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" :
4797 ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" :
4798 ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" :
4799 ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" :
4800 ((event == CS_EVENT_PM_RESUME) ? "pm resume" :
4801 ((event == CS_EVENT_CARD_RESET) ? "card reset" :
4802 "unknown"))))))));
4803 #endif
4805 switch(event)
4807 case CS_EVENT_REGISTRATION_COMPLETE:
4808 #ifdef DEBUG_CONFIG_INFO
4809 printk(KERN_DEBUG "wavelan_cs: registration complete\n");
4810 #endif
4811 break;
4813 case CS_EVENT_CARD_REMOVAL:
4814 /* Oups ! The card is no more there */
4815 link->state &= ~DEV_PRESENT;
4816 if(link->state & DEV_CONFIG)
4818 /* Accept no more transmissions */
4819 netif_device_detach(dev);
4821 /* Release the card */
4822 wv_pcmcia_release(link);
4824 break;
4826 case CS_EVENT_CARD_INSERTION:
4827 /* Reset and configure the card */
4828 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
4829 if(wv_pcmcia_config(link) &&
4830 wv_hw_config(dev))
4831 wv_init_info(dev);
4832 else
4833 dev->irq = 0;
4834 break;
4836 case CS_EVENT_PM_SUSPEND:
4837 /* NB: wavelan_close will be called, but too late, so we are
4838 * obliged to close nicely the wavelan here. David, could you
4839 * close the device before suspending them ? And, by the way,
4840 * could you, on resume, add a "route add -net ..." after the
4841 * ifconfig up ? Thanks... */
4843 /* Stop receiving new messages and wait end of transmission */
4844 wv_ru_stop(dev);
4846 /* Power down the module */
4847 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
4849 /* The card is now suspended */
4850 link->state |= DEV_SUSPEND;
4851 /* Fall through... */
4852 case CS_EVENT_RESET_PHYSICAL:
4853 if(link->state & DEV_CONFIG)
4855 if(link->open)
4856 netif_device_detach(dev);
4857 pcmcia_release_configuration(link->handle);
4859 break;
4861 case CS_EVENT_PM_RESUME:
4862 link->state &= ~DEV_SUSPEND;
4863 /* Fall through... */
4864 case CS_EVENT_CARD_RESET:
4865 if(link->state & DEV_CONFIG)
4867 pcmcia_request_configuration(link->handle, &link->conf);
4868 if(link->open) /* If RESET -> True, If RESUME -> False ? */
4870 wv_hw_reset(dev);
4871 netif_device_attach(dev);
4874 break;
4877 #ifdef DEBUG_CALLBACK_TRACE
4878 printk(KERN_DEBUG "<-wavelan_event()\n");
4879 #endif
4880 return 0;
4883 static struct pcmcia_device_id wavelan_ids[] = {
4884 PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
4885 PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
4886 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/PCMCIA", 0x23eb9949, 0x1bc50975),
4887 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/PCMCIA", 0x24358cd4, 0x1bc50975),
4888 PCMCIA_DEVICE_NULL,
4890 MODULE_DEVICE_TABLE(pcmcia, wavelan_ids);
4892 static struct pcmcia_driver wavelan_driver = {
4893 .owner = THIS_MODULE,
4894 .drv = {
4895 .name = "wavelan_cs",
4897 .attach = wavelan_attach,
4898 .event = wavelan_event,
4899 .detach = wavelan_detach,
4900 .id_table = wavelan_ids,
4903 static int __init
4904 init_wavelan_cs(void)
4906 return pcmcia_register_driver(&wavelan_driver);
4909 static void __exit
4910 exit_wavelan_cs(void)
4912 pcmcia_unregister_driver(&wavelan_driver);
4915 module_init(init_wavelan_cs);
4916 module_exit(exit_wavelan_cs);