File: /usr/src/linux/drivers/net/pcmcia/wavelan_cs.c
1 /*
2 * Wavelan Pcmcia driver
3 *
4 * Jean II - HPLB '96
5 *
6 * Reorganisation and extension of the driver.
7 * Original copyright follow. See wavelan_cs.h for details.
8 *
9 * This code is derived from Anthony D. Joseph's code and all the changes here
10 * are also under the original copyright below.
11 *
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
14 *
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.
17 *
18 * Thanks to Alan Cox and Bruce Janson for their advice.
19 *
20 * -- Yunzhou Li (scip4166@nus.sg)
21 *
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 :-)
26 *
27 * Lucent (formerly AT&T GIS, formerly NCR) WaveLAN PCMCIA card: An
28 * Ethernet-like radio transceiver controlled by an Intel 82593 coprocessor.
29 *
30 * A non-shared memory PCMCIA ethernet driver for linux
31 *
32 * ISA version modified to support PCMCIA by Anthony Joseph (adj@lcs.mit.edu)
33 *
34 *
35 * Joseph O'Sullivan & John Langford (josullvn@cs.cmu.edu & jcl@cs.cmu.edu)
36 *
37 * Apr 2 '98 made changes to bring the i82593 control/int handling in line
38 * with offical specs...
39 *
40 * Changes:
41 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
42 * - reorganize kmallocs in wavelan_attach, checking all for failure
43 * and releasing the previous allocations if one fails
44 *
45 *
46 ****************************************************************************
47 * Copyright 1995
48 * Anthony D. Joseph
49 * Massachusetts Institute of Technology
50 *
51 * Permission to use, copy, modify, and distribute this program
52 * for any purpose and without fee is hereby granted, provided
53 * that this copyright and permission notice appear on all copies
54 * and supporting documentation, the name of M.I.T. not be used
55 * in advertising or publicity pertaining to distribution of the
56 * program without specific prior permission, and notice be given
57 * in supporting documentation that copying and distribution is
58 * by permission of M.I.T. M.I.T. makes no representations about
59 * the suitability of this software for any purpose. It is pro-
60 * vided "as is" without express or implied warranty.
61 ****************************************************************************
62 *
63 */
64
65 #include "wavelan_cs.h" /* Private header */
66
67 /************************* MISC SUBROUTINES **************************/
68 /*
69 * Subroutines which won't fit in one of the following category
70 * (wavelan modem or i82593)
71 */
72
73 /*------------------------------------------------------------------*/
74 /*
75 * Wrapper for reporting error to cardservices
76 */
77 static void cs_error(client_handle_t handle, int func, int ret)
78 {
79 error_info_t err = { func, ret };
80 CardServices(ReportError, handle, &err);
81 }
82
83 #ifdef STRUCT_CHECK
84 /*------------------------------------------------------------------*/
85 /*
86 * Sanity routine to verify the sizes of the various WaveLAN interface
87 * structures.
88 */
89 static char *
90 wv_structuct_check(void)
91 {
92 #define SC(t,s,n) if (sizeof(t) != s) return(n);
93
94 SC(psa_t, PSA_SIZE, "psa_t");
95 SC(mmw_t, MMW_SIZE, "mmw_t");
96 SC(mmr_t, MMR_SIZE, "mmr_t");
97
98 #undef SC
99
100 return((char *) NULL);
101 } /* wv_structuct_check */
102 #endif /* STRUCT_CHECK */
103
104 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
105 /*
106 * Usefull subroutines to manage the modem of the wavelan
107 */
108
109 /*------------------------------------------------------------------*/
110 /*
111 * Read from card's Host Adaptor Status Register.
112 */
113 static inline u_char
114 hasr_read(u_long base)
115 {
116 return(inb(HASR(base)));
117 } /* hasr_read */
118
119 /*------------------------------------------------------------------*/
120 /*
121 * Write to card's Host Adapter Command Register.
122 */
123 static inline void
124 hacr_write(u_long base,
125 u_char hacr)
126 {
127 outb(hacr, HACR(base));
128 } /* hacr_write */
129
130 /*------------------------------------------------------------------*/
131 /*
132 * Write to card's Host Adapter Command Register. Include a delay for
133 * those times when it is needed.
134 */
135 static inline void
136 hacr_write_slow(u_long base,
137 u_char hacr)
138 {
139 hacr_write(base, hacr);
140 /* delay might only be needed sometimes */
141 mdelay(1L);
142 } /* hacr_write_slow */
143
144 /*------------------------------------------------------------------*/
145 /*
146 * Read the Parameter Storage Area from the WaveLAN card's memory
147 */
148 static void
149 psa_read(device * dev,
150 int o, /* offset in PSA */
151 u_char * b, /* buffer to fill */
152 int n) /* size to read */
153 {
154 u_char * ptr = ((u_char *)dev->mem_start) + PSA_ADDR + (o << 1);
155
156 while(n-- > 0)
157 {
158 *b++ = readb(ptr);
159 /* Due to a lack of address decode pins, the WaveLAN PCMCIA card
160 * only supports reading even memory addresses. That means the
161 * increment here MUST be two.
162 * Because of that, we can't use memcpy_fromio()...
163 */
164 ptr += 2;
165 }
166 } /* psa_read */
167
168 /*------------------------------------------------------------------*/
169 /*
170 * Write the Paramter Storage Area to the WaveLAN card's memory
171 */
172 static void
173 psa_write(device * dev,
174 int o, /* Offset in psa */
175 u_char * b, /* Buffer in memory */
176 int n) /* Length of buffer */
177 {
178 u_char * ptr = ((u_char *) dev->mem_start) + PSA_ADDR + (o << 1);
179 int count = 0;
180 ioaddr_t base = dev->base_addr;
181 /* As there seem to have no flag PSA_BUSY as in the ISA model, we are
182 * oblige to verify this address to know when the PSA is ready... */
183 volatile u_char * verify = ((u_char *) dev->mem_start) + PSA_ADDR +
184 (psaoff(0, psa_comp_number) << 1);
185
186 /* Authorize writting to PSA */
187 hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN);
188
189 while(n-- > 0)
190 {
191 /* write to PSA */
192 writeb(*b++, ptr);
193 ptr += 2;
194
195 /* I don't have the spec, so I don't know what the correct
196 * sequence to write is. This hack seem to work for me... */
197 count = 0;
198 while((readb(verify) != PSA_COMP_PCMCIA_915) && (count++ < 100))
199 mdelay(1);
200 }
201
202 /* Put the host interface back in standard state */
203 hacr_write(base, HACR_DEFAULT);
204 } /* psa_write */
205
206 #ifdef SET_PSA_CRC
207 /*------------------------------------------------------------------*/
208 /*
209 * Calculate the PSA CRC
210 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
211 * NOTE: By specifying a length including the CRC position the
212 * returned value should be zero. (i.e. a correct checksum in the PSA)
213 *
214 * The Windows drivers don't use the CRC, but the AP and the PtP tool
215 * depend on it.
216 */
217 static u_short
218 psa_crc(unsigned char * psa, /* The PSA */
219 int size) /* Number of short for CRC */
220 {
221 int byte_cnt; /* Loop on the PSA */
222 u_short crc_bytes = 0; /* Data in the PSA */
223 int bit_cnt; /* Loop on the bits of the short */
224
225 for(byte_cnt = 0; byte_cnt < size; byte_cnt++ )
226 {
227 crc_bytes ^= psa[byte_cnt]; /* Its an xor */
228
229 for(bit_cnt = 1; bit_cnt < 9; bit_cnt++ )
230 {
231 if(crc_bytes & 0x0001)
232 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
233 else
234 crc_bytes >>= 1 ;
235 }
236 }
237
238 return crc_bytes;
239 } /* psa_crc */
240 #endif /* SET_PSA_CRC */
241
242 /*------------------------------------------------------------------*/
243 /*
244 * update the checksum field in the Wavelan's PSA
245 */
246 static void
247 update_psa_checksum(device * dev)
248 {
249 #ifdef SET_PSA_CRC
250 psa_t psa;
251 u_short crc;
252
253 /* read the parameter storage area */
254 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
255
256 /* update the checksum */
257 crc = psa_crc((unsigned char *) &psa,
258 sizeof(psa) - sizeof(psa.psa_crc[0]) - sizeof(psa.psa_crc[1])
259 - sizeof(psa.psa_crc_status));
260
261 psa.psa_crc[0] = crc & 0xFF;
262 psa.psa_crc[1] = (crc & 0xFF00) >> 8;
263
264 /* Write it ! */
265 psa_write(dev, (char *)&psa.psa_crc - (char *)&psa,
266 (unsigned char *)&psa.psa_crc, 2);
267
268 #ifdef DEBUG_IOCTL_INFO
269 printk (KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
270 dev->name, psa.psa_crc[0], psa.psa_crc[1]);
271
272 /* Check again (luxury !) */
273 crc = psa_crc((unsigned char *) &psa,
274 sizeof(psa) - sizeof(psa.psa_crc_status));
275
276 if(crc != 0)
277 printk(KERN_WARNING "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", dev->name);
278 #endif /* DEBUG_IOCTL_INFO */
279 #endif /* SET_PSA_CRC */
280 } /* update_psa_checksum */
281
282 /*------------------------------------------------------------------*/
283 /*
284 * Write 1 byte to the MMC.
285 */
286 static inline void
287 mmc_out(u_long base,
288 u_short o,
289 u_char d)
290 {
291 /* Wait for MMC to go idle */
292 while(inb(HASR(base)) & HASR_MMI_BUSY)
293 ;
294
295 outb((u_char)((o << 1) | MMR_MMI_WR), MMR(base));
296 outb(d, MMD(base));
297 }
298
299 /*------------------------------------------------------------------*/
300 /*
301 * Routine to write bytes to the Modem Management Controller.
302 * We start by the end because it is the way it should be !
303 */
304 static inline void
305 mmc_write(u_long base,
306 u_char o,
307 u_char * b,
308 int n)
309 {
310 o += n;
311 b += n;
312
313 while(n-- > 0 )
314 mmc_out(base, --o, *(--b));
315 } /* mmc_write */
316
317 /*------------------------------------------------------------------*/
318 /*
319 * Read 1 byte from the MMC.
320 * Optimised version for 1 byte, avoid using memory...
321 */
322 static inline u_char
323 mmc_in(u_long base,
324 u_short o)
325 {
326 while(inb(HASR(base)) & HASR_MMI_BUSY)
327 ;
328 outb(o << 1, MMR(base)); /* Set the read address */
329
330 outb(0, MMD(base)); /* Required dummy write */
331
332 while(inb(HASR(base)) & HASR_MMI_BUSY)
333 ;
334 return (u_char) (inb(MMD(base))); /* Now do the actual read */
335 }
336
337 /*------------------------------------------------------------------*/
338 /*
339 * Routine to read bytes from the Modem Management Controller.
340 * The implementation is complicated by a lack of address lines,
341 * which prevents decoding of the low-order bit.
342 * (code has just been moved in the above function)
343 * We start by the end because it is the way it should be !
344 */
345 static inline void
346 mmc_read(u_long base,
347 u_char o,
348 u_char * b,
349 int n)
350 {
351 o += n;
352 b += n;
353
354 while(n-- > 0)
355 *(--b) = mmc_in(base, --o);
356 } /* mmc_read */
357
358 /*------------------------------------------------------------------*/
359 /*
360 * Get the type of encryption available...
361 */
362 static inline int
363 mmc_encr(u_long base) /* i/o port of the card */
364 {
365 int temp;
366
367 temp = mmc_in(base, mmroff(0, mmr_des_avail));
368 if((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
369 return 0;
370 else
371 return temp;
372 }
373
374 /*------------------------------------------------------------------*/
375 /*
376 * Wait for the frequency EEprom to complete a command...
377 * I hope this one will be optimally inlined...
378 */
379 static inline void
380 fee_wait(u_long base, /* i/o port of the card */
381 int delay, /* Base delay to wait for */
382 int number) /* Number of time to wait */
383 {
384 int count = 0; /* Wait only a limited time */
385
386 while((count++ < number) &&
387 (mmc_in(base, mmroff(0, mmr_fee_status)) & MMR_FEE_STATUS_BUSY))
388 udelay(delay);
389 }
390
391 /*------------------------------------------------------------------*/
392 /*
393 * Read bytes from the Frequency EEprom (frequency select cards).
394 */
395 static void
396 fee_read(u_long base, /* i/o port of the card */
397 u_short o, /* destination offset */
398 u_short * b, /* data buffer */
399 int n) /* number of registers */
400 {
401 b += n; /* Position at the end of the area */
402
403 /* Write the address */
404 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
405
406 /* Loop on all buffer */
407 while(n-- > 0)
408 {
409 /* Write the read command */
410 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_READ);
411
412 /* Wait until EEprom is ready (should be quick !) */
413 fee_wait(base, 10, 100);
414
415 /* Read the value */
416 *--b = ((mmc_in(base, mmroff(0, mmr_fee_data_h)) << 8) |
417 mmc_in(base, mmroff(0, mmr_fee_data_l)));
418 }
419 }
420
421 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
422
423 /*------------------------------------------------------------------*/
424 /*
425 * Write bytes from the Frequency EEprom (frequency select cards).
426 * This is a bit complicated, because the frequency eeprom has to
427 * be unprotected and the write enabled.
428 * Jean II
429 */
430 static void
431 fee_write(u_long base, /* i/o port of the card */
432 u_short o, /* destination offset */
433 u_short * b, /* data buffer */
434 int n) /* number of registers */
435 {
436 b += n; /* Position at the end of the area */
437
438 #ifdef EEPROM_IS_PROTECTED /* disabled */
439 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
440 /* Ask to read the protected register */
441 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
442
443 fee_wait(base, 10, 100);
444
445 /* Read the protected register */
446 printk("Protected 2 : %02X-%02X\n",
447 mmc_in(base, mmroff(0, mmr_fee_data_h)),
448 mmc_in(base, mmroff(0, mmr_fee_data_l)));
449 #endif /* DOESNT_SEEM_TO_WORK */
450
451 /* Enable protected register */
452 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
453 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
454
455 fee_wait(base, 10, 100);
456
457 /* Unprotect area */
458 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n);
459 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
460 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
461 /* Or use : */
462 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
463 #endif /* DOESNT_SEEM_TO_WORK */
464
465 fee_wait(base, 10, 100);
466 #endif /* EEPROM_IS_PROTECTED */
467
468 /* Write enable */
469 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
470 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
471
472 fee_wait(base, 10, 100);
473
474 /* Write the EEprom address */
475 mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
476
477 /* Loop on all buffer */
478 while(n-- > 0)
479 {
480 /* Write the value */
481 mmc_out(base, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
482 mmc_out(base, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
483
484 /* Write the write command */
485 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WRITE);
486
487 /* Wavelan doc says : wait at least 10 ms for EEBUSY = 0 */
488 mdelay(10);
489 fee_wait(base, 10, 100);
490 }
491
492 /* Write disable */
493 mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
494 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
495
496 fee_wait(base, 10, 100);
497
498 #ifdef EEPROM_IS_PROTECTED /* disabled */
499 /* Reprotect EEprom */
500 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x00);
501 mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
502
503 fee_wait(base, 10, 100);
504 #endif /* EEPROM_IS_PROTECTED */
505 }
506 #endif /* WIRELESS_EXT */
507
508 /******************* WaveLAN Roaming routines... ********************/
509
510 #ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */
511
512 unsigned char WAVELAN_BEACON_ADDRESS[]= {0x09,0x00,0x0e,0x20,0x03,0x00};
513
514 void wv_roam_init(struct net_device *dev)
515 {
516 net_local *lp= (net_local *)dev->priv;
517
518 /* Do not remove this unless you have a good reason */
519 printk(KERN_NOTICE "%s: Warning, you have enabled roaming on"
520 " device %s !\n", dev->name, dev->name);
521 printk(KERN_NOTICE "Roaming is currently an experimental unsupported feature"
522 " of the Wavelan driver.\n");
523 printk(KERN_NOTICE "It may work, but may also make the driver behave in"
524 " erratic ways or crash.\n");
525
526 lp->wavepoint_table.head=NULL; /* Initialise WavePoint table */
527 lp->wavepoint_table.num_wavepoints=0;
528 lp->wavepoint_table.locked=0;
529 lp->curr_point=NULL; /* No default WavePoint */
530 lp->cell_search=0;
531
532 lp->cell_timer.data=(int)lp; /* Start cell expiry timer */
533 lp->cell_timer.function=wl_cell_expiry;
534 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
535 add_timer(&lp->cell_timer);
536
537 wv_nwid_filter(NWID_PROMISC,lp) ; /* Enter NWID promiscuous mode */
538 /* to build up a good WavePoint */
539 /* table... */
540 printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name);
541 }
542
543 void wv_roam_cleanup(struct net_device *dev)
544 {
545 wavepoint_history *ptr,*old_ptr;
546 net_local *lp= (net_local *)dev->priv;
547
548 printk(KERN_DEBUG "WaveLAN: Roaming Disabled on device %s\n",dev->name);
549
550 /* Fixme : maybe we should check that the timer exist before deleting it */
551 del_timer(&lp->cell_timer); /* Remove cell expiry timer */
552 ptr=lp->wavepoint_table.head; /* Clear device's WavePoint table */
553 while(ptr!=NULL)
554 {
555 old_ptr=ptr;
556 ptr=ptr->next;
557 wl_del_wavepoint(old_ptr,lp);
558 }
559 }
560
561 /* Enable/Disable NWID promiscuous mode on a given device */
562 void wv_nwid_filter(unsigned char mode, net_local *lp)
563 {
564 mm_t m;
565 unsigned long flags;
566
567 #ifdef WAVELAN_ROAMING_DEBUG
568 printk(KERN_DEBUG "WaveLAN: NWID promisc %s, device %s\n",(mode==NWID_PROMISC) ? "on" : "off", lp->dev->name);
569 #endif
570
571 /* Disable interrupts & save flags */
572 spin_lock_irqsave (&lp->lock, flags);
573
574 m.w.mmw_loopt_sel = (mode==NWID_PROMISC) ? MMW_LOOPT_SEL_DIS_NWID : 0x00;
575 mmc_write(lp->dev->base_addr, (char *)&m.w.mmw_loopt_sel - (char *)&m, (unsigned char *)&m.w.mmw_loopt_sel, 1);
576
577 /* ReEnable interrupts & restore flags */
578 spin_unlock_irqrestore (&lp->lock, flags);
579
580 if(mode==NWID_PROMISC)
581 lp->cell_search=1;
582 else
583 lp->cell_search=0;
584 }
585
586 /* Find a record in the WavePoint table matching a given NWID */
587 wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp)
588 {
589 wavepoint_history *ptr=lp->wavepoint_table.head;
590
591 while(ptr!=NULL){
592 if(ptr->nwid==nwid)
593 return ptr;
594 ptr=ptr->next;
595 }
596 return NULL;
597 }
598
599 /* Create a new wavepoint table entry */
600 wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp)
601 {
602 wavepoint_history *new_wavepoint;
603
604 #ifdef WAVELAN_ROAMING_DEBUG
605 printk(KERN_DEBUG "WaveLAN: New Wavepoint, NWID:%.4X\n",nwid);
606 #endif
607
608 if(lp->wavepoint_table.num_wavepoints==MAX_WAVEPOINTS)
609 return NULL;
610
611 new_wavepoint=(wavepoint_history *) kmalloc(sizeof(wavepoint_history),GFP_ATOMIC);
612 if(new_wavepoint==NULL)
613 return NULL;
614
615 new_wavepoint->nwid=nwid; /* New WavePoints NWID */
616 new_wavepoint->average_fast=0; /* Running Averages..*/
617 new_wavepoint->average_slow=0;
618 new_wavepoint->qualptr=0; /* Start of ringbuffer */
619 new_wavepoint->last_seq=seq-1; /* Last sequence no.seen */
620 memset(new_wavepoint->sigqual,0,WAVEPOINT_HISTORY);/* Empty ringbuffer */
621
622 new_wavepoint->next=lp->wavepoint_table.head;/* Add to wavepoint table */
623 new_wavepoint->prev=NULL;
624
625 if(lp->wavepoint_table.head!=NULL)
626 lp->wavepoint_table.head->prev=new_wavepoint;
627
628 lp->wavepoint_table.head=new_wavepoint;
629
630 lp->wavepoint_table.num_wavepoints++; /* no. of visible wavepoints */
631
632 return new_wavepoint;
633 }
634
635 /* Remove a wavepoint entry from WavePoint table */
636 void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp)
637 {
638 if(wavepoint==NULL)
639 return;
640
641 if(lp->curr_point==wavepoint)
642 lp->curr_point=NULL;
643
644 if(wavepoint->prev!=NULL)
645 wavepoint->prev->next=wavepoint->next;
646
647 if(wavepoint->next!=NULL)
648 wavepoint->next->prev=wavepoint->prev;
649
650 if(lp->wavepoint_table.head==wavepoint)
651 lp->wavepoint_table.head=wavepoint->next;
652
653 lp->wavepoint_table.num_wavepoints--;
654 kfree(wavepoint);
655 }
656
657 /* Timer callback function - checks WavePoint table for stale entries */
658 void wl_cell_expiry(unsigned long data)
659 {
660 net_local *lp=(net_local *)data;
661 wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point;
662
663 #if WAVELAN_ROAMING_DEBUG > 1
664 printk(KERN_DEBUG "WaveLAN: Wavepoint timeout, dev %s\n",lp->dev->name);
665 #endif
666
667 if(lp->wavepoint_table.locked)
668 {
669 #if WAVELAN_ROAMING_DEBUG > 1
670 printk(KERN_DEBUG "WaveLAN: Wavepoint table locked...\n");
671 #endif
672
673 lp->cell_timer.expires=jiffies+1; /* If table in use, come back later */
674 add_timer(&lp->cell_timer);
675 return;
676 }
677
678 while(wavepoint!=NULL)
679 {
680 if(wavepoint->last_seen < jiffies-CELL_TIMEOUT)
681 {
682 #ifdef WAVELAN_ROAMING_DEBUG
683 printk(KERN_DEBUG "WaveLAN: Bye bye %.4X\n",wavepoint->nwid);
684 #endif
685
686 old_point=wavepoint;
687 wavepoint=wavepoint->next;
688 wl_del_wavepoint(old_point,lp);
689 }
690 else
691 wavepoint=wavepoint->next;
692 }
693 lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
694 add_timer(&lp->cell_timer);
695 }
696
697 /* Update SNR history of a wavepoint */
698 void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq)
699 {
700 int i=0,num_missed=0,ptr=0;
701 int average_fast=0,average_slow=0;
702
703 num_missed=(seq-wavepoint->last_seq)%WAVEPOINT_HISTORY;/* Have we missed
704 any beacons? */
705 if(num_missed)
706 for(i=0;i<num_missed;i++)
707 {
708 wavepoint->sigqual[wavepoint->qualptr++]=0; /* If so, enter them as 0's */
709 wavepoint->qualptr %=WAVEPOINT_HISTORY; /* in the ringbuffer. */
710 }
711 wavepoint->last_seen=jiffies; /* Add beacon to history */
712 wavepoint->last_seq=seq;
713 wavepoint->sigqual[wavepoint->qualptr++]=sigqual;
714 wavepoint->qualptr %=WAVEPOINT_HISTORY;
715 ptr=(wavepoint->qualptr-WAVEPOINT_FAST_HISTORY+WAVEPOINT_HISTORY)%WAVEPOINT_HISTORY;
716
717 for(i=0;i<WAVEPOINT_FAST_HISTORY;i++) /* Update running averages */
718 {
719 average_fast+=wavepoint->sigqual[ptr++];
720 ptr %=WAVEPOINT_HISTORY;
721 }
722
723 average_slow=average_fast;
724 for(i=WAVEPOINT_FAST_HISTORY;i<WAVEPOINT_HISTORY;i++)
725 {
726 average_slow+=wavepoint->sigqual[ptr++];
727 ptr %=WAVEPOINT_HISTORY;
728 }
729
730 wavepoint->average_fast=average_fast/WAVEPOINT_FAST_HISTORY;
731 wavepoint->average_slow=average_slow/WAVEPOINT_HISTORY;
732 }
733
734 /* Perform a handover to a new WavePoint */
735 void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp)
736 {
737 ioaddr_t base = lp->dev->base_addr;
738 mm_t m;
739 unsigned long flags;
740
741 if(wavepoint==lp->curr_point) /* Sanity check... */
742 {
743 wv_nwid_filter(!NWID_PROMISC,lp);
744 return;
745 }
746
747 #ifdef WAVELAN_ROAMING_DEBUG
748 printk(KERN_DEBUG "WaveLAN: Doing handover to %.4X, dev %s\n",wavepoint->nwid,lp->dev->name);
749 #endif
750
751 /* Disable interrupts & save flags */
752 spin_lock_irqsave(&lp->lock, flags);
753
754 m.w.mmw_netw_id_l = wavepoint->nwid & 0xFF;
755 m.w.mmw_netw_id_h = (wavepoint->nwid & 0xFF00) >> 8;
756
757 mmc_write(base, (char *)&m.w.mmw_netw_id_l - (char *)&m, (unsigned char *)&m.w.mmw_netw_id_l, 2);
758
759 /* ReEnable interrupts & restore flags */
760 spin_unlock_irqrestore (&lp->lock, flags);
761
762 wv_nwid_filter(!NWID_PROMISC,lp);
763 lp->curr_point=wavepoint;
764 }
765
766 /* Called when a WavePoint beacon is received */
767 static inline void wl_roam_gather(device * dev,
768 u_char * hdr, /* Beacon header */
769 u_char * stats) /* SNR, Signal quality
770 of packet */
771 {
772 wavepoint_beacon *beacon= (wavepoint_beacon *)hdr; /* Rcvd. Beacon */
773 unsigned short nwid=ntohs(beacon->nwid);
774 unsigned short sigqual=stats[2] & MMR_SGNL_QUAL; /* SNR of beacon */
775 wavepoint_history *wavepoint=NULL; /* WavePoint table entry */
776 net_local *lp=(net_local *)dev->priv; /* Device info */
777
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
782
783 lp->wavepoint_table.locked=1; /* <Mutex> */
784
785 wavepoint=wl_roam_check(nwid,lp); /* Find WavePoint table entry */
786 if(wavepoint==NULL) /* If no entry, Create a new one... */
787 {
788 wavepoint=wl_new_wavepoint(nwid,beacon->seq,lp);
789 if(wavepoint==NULL)
790 goto out;
791 }
792 if(lp->curr_point==NULL) /* If this is the only WavePoint, */
793 wv_roam_handover(wavepoint, lp); /* Jump on it! */
794
795 wl_update_history(wavepoint, sigqual, beacon->seq); /* Update SNR history
796 stats. */
797
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 */
801
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 */
805
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);
809
810 out:
811 lp->wavepoint_table.locked=0; /* </MUTEX> :-) */
812 }
813
814 /* Test this MAC frame a WavePoint beacon */
815 static inline int WAVELAN_BEACON(unsigned char *data)
816 {
817 wavepoint_beacon *beacon= (wavepoint_beacon *)data;
818 static wavepoint_beacon beacon_template={0xaa,0xaa,0x03,0x08,0x00,0x0e,0x20,0x03,0x00};
819
820 if(memcmp(beacon,&beacon_template,9)==0)
821 return 1;
822 else
823 return 0;
824 }
825 #endif /* WAVELAN_ROAMING */
826
827 /************************ I82593 SUBROUTINES *************************/
828 /*
829 * Useful subroutines to manage the Ethernet controller
830 */
831
832 /*------------------------------------------------------------------*/
833 /*
834 * Routine to synchronously send a command to the i82593 chip.
835 * Should be called with interrupts enabled.
836 */
837 static int
838 wv_82593_cmd(device * dev,
839 char * str,
840 int cmd,
841 int result)
842 {
843 ioaddr_t base = dev->base_addr;
844 net_local * lp = (net_local *)dev->priv;
845 int status;
846 long spin;
847 u_long flags;
848
849 /* Spin until the chip finishes executing its current command (if any) */
850 do
851 {
852 spin_lock_irqsave (&lp->lock, flags);
853 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
854 status = inb(LCSR(base));
855 spin_unlock_irqrestore (&lp->lock, flags);
856 }
857 while((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE);
858
859 /* We are waiting for command completion */
860 wv_wait_completed = TRUE;
861
862 /* Issue the command to the controller */
863 outb(cmd, LCCR(base));
864
865 /* If we don't have to check the result of the command */
866 if(result == SR0_NO_RESULT)
867 {
868 wv_wait_completed = FALSE;
869 return(TRUE);
870 }
871
872 /* Busy wait while the LAN controller executes the command.
873 * Note : wv_wait_completed should be volatile */
874 spin = 0;
875 while(wv_wait_completed && (spin++ < 1000))
876 udelay(10);
877
878 /* If the interrupt handler hasn't be called */
879 if(wv_wait_completed)
880 {
881 outb(OP0_NOP, LCCR(base));
882 status = inb(LCSR(base));
883 if(status & SR0_INTERRUPT)
884 {
885 /* There was an interrupt : call the interrupt handler */
886 #ifdef DEBUG_INTERRUPT_ERROR
887 printk(KERN_WARNING "wv_82593_cmd: interrupt handler not installed or interrupt disabled\n");
888 #endif
889
890 wavelan_interrupt(dev->irq, (void *) dev,
891 (struct pt_regs *) NULL);
892 }
893 else
894 {
895 wv_wait_completed = 0; /* XXX */
896 #ifdef DEBUG_INTERRUPT_ERROR
897 printk(KERN_INFO "wv_82593_cmd: %s timeout, status0 0x%02x\n",
898 str, status);
899 #endif
900 /* We probably should reset the controller here */
901 return(FALSE);
902 }
903 }
904
905 /* Check the return code provided by the interrupt handler against
906 * the expected return code provided by the caller */
907 if((lp->status & SR0_EVENT_MASK) != result)
908 {
909 #ifdef DEBUG_INTERRUPT_ERROR
910 printk(KERN_INFO "wv_82593_cmd: %s failed, status0 = 0x%x\n",
911 str, lp->status);
912 #endif
913 return(FALSE);
914 }
915
916 return(TRUE);
917 } /* wv_82593_cmd */
918
919 /*------------------------------------------------------------------*/
920 /*
921 * This routine does a 593 op-code number 7, and obtains the diagnose
922 * status for the WaveLAN.
923 */
924 static inline int
925 wv_diag(device * dev)
926 {
927 if(wv_82593_cmd(dev, "wv_diag(): diagnose",
928 OP0_DIAGNOSE, SR0_DIAGNOSE_PASSED))
929 return(TRUE);
930
931 #ifdef DEBUG_CONFIG_ERROR
932 printk(KERN_INFO "wavelan_cs: i82593 Self Test failed!\n");
933 #endif
934 return(FALSE);
935 } /* wv_diag */
936
937 /*------------------------------------------------------------------*/
938 /*
939 * Routine to read len bytes from the i82593's ring buffer, starting at
940 * chip address addr. The results read from the chip are stored in buf.
941 * The return value is the address to use for next the call.
942 */
943 static int
944 read_ringbuf(device * dev,
945 int addr,
946 char * buf,
947 int len)
948 {
949 ioaddr_t base = dev->base_addr;
950 int ring_ptr = addr;
951 int chunk_len;
952 char * buf_ptr = buf;
953
954 #ifdef OLDIES
955 /* After having check skb_put (net/core/skbuff.c) in the kernel, it seem
956 * quite safe to remove this... */
957
958 /* If buf is NULL, just increment the ring buffer pointer */
959 if(buf == NULL)
960 return((ring_ptr - RX_BASE + len) % RX_SIZE + RX_BASE);
961 #endif
962
963 /* Get all the buffer */
964 while(len > 0)
965 {
966 /* Position the Program I/O Register at the ring buffer pointer */
967 outb(ring_ptr & 0xff, PIORL(base));
968 outb(((ring_ptr >> 8) & PIORH_MASK), PIORH(base));
969
970 /* First, determine how much we can read without wrapping around the
971 ring buffer */
972 if((addr + len) < (RX_BASE + RX_SIZE))
973 chunk_len = len;
974 else
975 chunk_len = RX_BASE + RX_SIZE - addr;
976 insb(PIOP(base), buf_ptr, chunk_len);
977 buf_ptr += chunk_len;
978 len -= chunk_len;
979 ring_ptr = (ring_ptr - RX_BASE + chunk_len) % RX_SIZE + RX_BASE;
980 }
981 return(ring_ptr);
982 } /* read_ringbuf */
983
984 /*------------------------------------------------------------------*/
985 /*
986 * Reconfigure the i82593, or at least ask for it...
987 * Because wv_82593_config use the transmission buffer, we must do it
988 * when we are sure that there is no transmission, so we do it now
989 * or in wavelan_packet_xmit() (I can't find any better place,
990 * wavelan_interrupt is not an option...), so you may experience
991 * some delay sometime...
992 */
993 static inline void wv_82593_reconfig (device * dev)
994 {
995 net_local *lp = (net_local *) dev->priv;
996 dev_link_t *link = ((net_local *) dev->priv)->link;
997
998 /* Check if we can do it now ! */
999 if (!(link->open)) {
1000 lp->reconfig_82593 = TRUE;
1001 #ifdef DEBUG_IOCTL_INFO
1002 printk (KERN_DEBUG "%s: wv_82593_reconfig(): delayed (link = %d)\n",
1003 dev->name, link->open);
1004 #endif
1005 } else {
1006 netif_stop_queue (dev);
1007
1008 lp->reconfig_82593 = FALSE;
1009 wv_82593_config (dev);
1010 netif_wake_queue (dev);
1011 }
1012 }
1013
1014 #ifdef OLDIES
1015 /*------------------------------------------------------------------*/
1016 /*
1017 * Dumps the current i82593 receive buffer to the console.
1018 */
1019 static void wavelan_dump(device *dev)
1020 {
1021 ioaddr_t base = dev->base_addr;
1022 int i, c;
1023
1024 /* disable receiver so we can use channel 1 */
1025 outb(OP0_RCV_DISABLE, LCCR(base));
1026
1027 /* reset receive DMA pointer */
1028 hacr_write_slow(base, HACR_PWR_STAT | HACR_RX_DMA_RESET);
1029 hacr_write(base, HACR_DEFAULT);
1030
1031 /* dump into receive buffer */
1032 wv_82593_cmd(dev, "wavelan_dump(): dump", CR0_CHNL|OP0_DUMP, SR0_DUMP_DONE);
1033
1034 /* set read pointer to start of receive buffer */
1035 outb(0, PIORL(base));
1036 outb(0, PIORH(base));
1037
1038 printk(KERN_DEBUG "wavelan_cs: dump:\n");
1039 printk(KERN_DEBUG " 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
1040 for(i = 0; i < 73; i++){
1041 if((i % 16) == 0) {
1042 printk("\n0x%02x:", i);
1043 if (!i) {
1044 printk(" ");
1045 continue;
1046 }
1047 }
1048 c = inb(PIOP(base));
1049 printk("%02x ", c);
1050 }
1051 printk("\n");
1052
1053 /* enable the receiver again */
1054 wv_ru_start(dev);
1055 }
1056 #endif
1057
1058 /********************* DEBUG & INFO SUBROUTINES *********************/
1059 /*
1060 * This routines are used in the code to show debug informations.
1061 * Most of the time, it dump the content of hardware structures...
1062 */
1063
1064 #ifdef DEBUG_PSA_SHOW
1065 /*------------------------------------------------------------------*/
1066 /*
1067 * Print the formatted contents of the Parameter Storage Area.
1068 */
1069 static void
1070 wv_psa_show(psa_t * p)
1071 {
1072 printk(KERN_DEBUG "##### wavelan psa contents: #####\n");
1073 printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
1074 p->psa_io_base_addr_1,
1075 p->psa_io_base_addr_2,
1076 p->psa_io_base_addr_3,
1077 p->psa_io_base_addr_4);
1078 printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
1079 p->psa_rem_boot_addr_1,
1080 p->psa_rem_boot_addr_2,
1081 p->psa_rem_boot_addr_3);
1082 printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
1083 printk("psa_int_req_no: %d\n", p->psa_int_req_no);
1084 #ifdef DEBUG_SHOW_UNUSED
1085 printk(KERN_DEBUG "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1086 p->psa_unused0[0],
1087 p->psa_unused0[1],
1088 p->psa_unused0[2],
1089 p->psa_unused0[3],
1090 p->psa_unused0[4],
1091 p->psa_unused0[5],
1092 p->psa_unused0[6]);
1093 #endif /* DEBUG_SHOW_UNUSED */
1094 printk(KERN_DEBUG "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
1095 p->psa_univ_mac_addr[0],
1096 p->psa_univ_mac_addr[1],
1097 p->psa_univ_mac_addr[2],
1098 p->psa_univ_mac_addr[3],
1099 p->psa_univ_mac_addr[4],
1100 p->psa_univ_mac_addr[5]);
1101 printk(KERN_DEBUG "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
1102 p->psa_local_mac_addr[0],
1103 p->psa_local_mac_addr[1],
1104 p->psa_local_mac_addr[2],
1105 p->psa_local_mac_addr[3],
1106 p->psa_local_mac_addr[4],
1107 p->psa_local_mac_addr[5]);
1108 printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel);
1109 printk("psa_comp_number: %d, ", p->psa_comp_number);
1110 printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
1111 printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
1112 p->psa_feature_select);
1113 printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
1114 printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
1115 printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
1116 printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]);
1117 printk("psa_nwid_select: %d\n", p->psa_nwid_select);
1118 printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select);
1119 printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1120 p->psa_encryption_key[0],
1121 p->psa_encryption_key[1],
1122 p->psa_encryption_key[2],
1123 p->psa_encryption_key[3],
1124 p->psa_encryption_key[4],
1125 p->psa_encryption_key[5],
1126 p->psa_encryption_key[6],
1127 p->psa_encryption_key[7]);
1128 printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
1129 printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
1130 p->psa_call_code[0]);
1131 printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1132 p->psa_call_code[0],
1133 p->psa_call_code[1],
1134 p->psa_call_code[2],
1135 p->psa_call_code[3],
1136 p->psa_call_code[4],
1137 p->psa_call_code[5],
1138 p->psa_call_code[6],
1139 p->psa_call_code[7]);
1140 #ifdef DEBUG_SHOW_UNUSED
1141 printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
1142 p->psa_reserved[0],
1143 p->psa_reserved[1],
1144 p->psa_reserved[2],
1145 p->psa_reserved[3]);
1146 #endif /* DEBUG_SHOW_UNUSED */
1147 printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
1148 printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
1149 printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
1150 } /* wv_psa_show */
1151 #endif /* DEBUG_PSA_SHOW */
1152
1153 #ifdef DEBUG_MMC_SHOW
1154 /*------------------------------------------------------------------*/
1155 /*
1156 * Print the formatted status of the Modem Management Controller.
1157 * This function need to be completed...
1158 */
1159 static void
1160 wv_mmc_show(device * dev)
1161 {
1162 ioaddr_t base = dev->base_addr;
1163 net_local * lp = (net_local *)dev->priv;
1164 mmr_t m;
1165
1166 /* Basic check */
1167 if(hasr_read(base) & HASR_NO_CLK)
1168 {
1169 printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n",
1170 dev->name);
1171 return;
1172 }
1173
1174 /* Read the mmc */
1175 mmc_out(base, mmwoff(0, mmw_freeze), 1);
1176 mmc_read(base, 0, (u_char *)&m, sizeof(m));
1177 mmc_out(base, mmwoff(0, mmw_freeze), 0);
1178
1179 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1180 /* Don't forget to update statistics */
1181 lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
1182 #endif /* WIRELESS_EXT */
1183
1184 printk(KERN_DEBUG "##### wavelan modem status registers: #####\n");
1185 #ifdef DEBUG_SHOW_UNUSED
1186 printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1187 m.mmr_unused0[0],
1188 m.mmr_unused0[1],
1189 m.mmr_unused0[2],
1190 m.mmr_unused0[3],
1191 m.mmr_unused0[4],
1192 m.mmr_unused0[5],
1193 m.mmr_unused0[6],
1194 m.mmr_unused0[7]);
1195 #endif /* DEBUG_SHOW_UNUSED */
1196 printk(KERN_DEBUG "Encryption algorythm: %02X - Status: %02X\n",
1197 m.mmr_des_avail, m.mmr_des_status);
1198 #ifdef DEBUG_SHOW_UNUSED
1199 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1200 m.mmr_unused1[0],
1201 m.mmr_unused1[1],
1202 m.mmr_unused1[2],
1203 m.mmr_unused1[3],
1204 m.mmr_unused1[4]);
1205 #endif /* DEBUG_SHOW_UNUSED */
1206 printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1207 m.mmr_dce_status,
1208 (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"",
1209 (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1210 "loop test indicated," : "",
1211 (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "",
1212 (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1213 "jabber timer expired," : "");
1214 printk(KERN_DEBUG "Dsp ID: %02X\n",
1215 m.mmr_dsp_id);
1216 #ifdef DEBUG_SHOW_UNUSED
1217 printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1218 m.mmr_unused2[0],
1219 m.mmr_unused2[1]);
1220 #endif /* DEBUG_SHOW_UNUSED */
1221 printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1222 (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1223 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1224 printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1225 m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1226 (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below");
1227 printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1228 m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1229 (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg");
1230 printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL,
1231 (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update");
1232 printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1233 (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0");
1234 #ifdef DEBUG_SHOW_UNUSED
1235 printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1236 #endif /* DEBUG_SHOW_UNUSED */
1237 } /* wv_mmc_show */
1238 #endif /* DEBUG_MMC_SHOW */
1239
1240 #ifdef DEBUG_I82593_SHOW
1241 /*------------------------------------------------------------------*/
1242 /*
1243 * Print the formatted status of the i82593's receive unit.
1244 */
1245 static void
1246 wv_ru_show(device * dev)
1247 {
1248 net_local *lp = (net_local *) dev->priv;
1249
1250 printk(KERN_DEBUG "##### wavelan i82593 receiver status: #####\n");
1251 printk(KERN_DEBUG "ru: rfp %d stop %d", lp->rfp, lp->stop);
1252 /*
1253 * Not implemented yet...
1254 */
1255 printk("\n");
1256 } /* wv_ru_show */
1257 #endif /* DEBUG_I82593_SHOW */
1258
1259 #ifdef DEBUG_DEVICE_SHOW
1260 /*------------------------------------------------------------------*/
1261 /*
1262 * Print the formatted status of the WaveLAN PCMCIA device driver.
1263 */
1264 static void
1265 wv_dev_show(device * dev)
1266 {
1267 printk(KERN_DEBUG "dev:");
1268 printk(" trans_start=%ld,", dev->trans_start);
1269 printk(" flags=0x%x,", dev->flags);
1270 printk("\n");
1271 } /* wv_dev_show */
1272
1273 /*------------------------------------------------------------------*/
1274 /*
1275 * Print the formatted status of the WaveLAN PCMCIA device driver's
1276 * private information.
1277 */
1278 static void
1279 wv_local_show(device * dev)
1280 {
1281 net_local *lp;
1282
1283 lp = (net_local *)dev->priv;
1284
1285 printk(KERN_DEBUG "local:");
1286 /*
1287 * Not implemented yet...
1288 */
1289 printk("\n");
1290 } /* wv_local_show */
1291 #endif /* DEBUG_DEVICE_SHOW */
1292
1293 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1294 /*------------------------------------------------------------------*/
1295 /*
1296 * Dump packet header (and content if necessary) on the screen
1297 */
1298 static inline void
1299 wv_packet_info(u_char * p, /* Packet to dump */
1300 int length, /* Length of the packet */
1301 char * msg1, /* Name of the device */
1302 char * msg2) /* Name of the function */
1303 {
1304 int i;
1305 int maxi;
1306
1307 printk(KERN_DEBUG "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1308 msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1309 printk(KERN_DEBUG "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1310 msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13]);
1311
1312 #ifdef DEBUG_PACKET_DUMP
1313
1314 printk(KERN_DEBUG "data=\"");
1315
1316 if((maxi = length) > DEBUG_PACKET_DUMP)
1317 maxi = DEBUG_PACKET_DUMP;
1318 for(i = 14; i < maxi; i++)
1319 if(p[i] >= ' ' && p[i] <= '~')
1320 printk(" %c", p[i]);
1321 else
1322 printk("%02X", p[i]);
1323 if(maxi < length)
1324 printk("..");
1325 printk("\"\n");
1326 printk(KERN_DEBUG "\n");
1327 #endif /* DEBUG_PACKET_DUMP */
1328 }
1329 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1330
1331 /*------------------------------------------------------------------*/
1332 /*
1333 * This is the information which is displayed by the driver at startup
1334 * There is a lot of flag to configure it at your will...
1335 */
1336 static inline void
1337 wv_init_info(device * dev)
1338 {
1339 ioaddr_t base = dev->base_addr;
1340 psa_t psa;
1341 int i;
1342
1343 /* Read the parameter storage area */
1344 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
1345
1346 #ifdef DEBUG_PSA_SHOW
1347 wv_psa_show(&psa);
1348 #endif
1349 #ifdef DEBUG_MMC_SHOW
1350 wv_mmc_show(dev);
1351 #endif
1352 #ifdef DEBUG_I82593_SHOW
1353 wv_ru_show(dev);
1354 #endif
1355
1356 #ifdef DEBUG_BASIC_SHOW
1357 /* Now, let's go for the basic stuff */
1358 printk(KERN_NOTICE "%s: WaveLAN: port %#x, irq %d, hw_addr",
1359 dev->name, base, dev->irq);
1360 for(i = 0; i < WAVELAN_ADDR_SIZE; i++)
1361 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1362
1363 /* Print current network id */
1364 if(psa.psa_nwid_select)
1365 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
1366 else
1367 printk(", nwid off");
1368
1369 /* If 2.00 card */
1370 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1371 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1372 {
1373 unsigned short freq;
1374
1375 /* Ask the EEprom to read the frequency from the first area */
1376 fee_read(base, 0x00 /* 1st area - frequency... */,
1377 &freq, 1);
1378
1379 /* Print frequency */
1380 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1381
1382 /* Hack !!! */
1383 if(freq & 0x20)
1384 printk(".5");
1385 }
1386 else
1387 {
1388 printk(", PCMCIA, ");
1389 switch (psa.psa_subband)
1390 {
1391 case PSA_SUBBAND_915:
1392 printk("915");
1393 break;
1394 case PSA_SUBBAND_2425:
1395 printk("2425");
1396 break;
1397 case PSA_SUBBAND_2460:
1398 printk("2460");
1399 break;
1400 case PSA_SUBBAND_2484:
1401 printk("2484");
1402 break;
1403 case PSA_SUBBAND_2430_5:
1404 printk("2430.5");
1405 break;
1406 default:
1407 printk("unknown");
1408 }
1409 }
1410
1411 printk(" MHz\n");
1412 #endif /* DEBUG_BASIC_SHOW */
1413
1414 #ifdef DEBUG_VERSION_SHOW
1415 /* Print version information */
1416 printk(KERN_NOTICE "%s", version);
1417 #endif
1418 } /* wv_init_info */
1419
1420 /********************* IOCTL, STATS & RECONFIG *********************/
1421 /*
1422 * We found here routines that are called by Linux on differents
1423 * occasions after the configuration and not for transmitting data
1424 * These may be called when the user use ifconfig, /proc/net/dev
1425 * or wireless extensions
1426 */
1427
1428 /*------------------------------------------------------------------*/
1429 /*
1430 * Get the current ethernet statistics. This may be called with the
1431 * card open or closed.
1432 * Used when the user read /proc/net/dev
1433 */
1434 static en_stats *
1435 wavelan_get_stats(device * dev)
1436 {
1437 #ifdef DEBUG_IOCTL_TRACE
1438 printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1439 #endif
1440
1441 return(&((net_local *) dev->priv)->stats);
1442 }
1443
1444 /*------------------------------------------------------------------*/
1445 /*
1446 * Set or clear the multicast filter for this adaptor.
1447 * num_addrs == -1 Promiscuous mode, receive all packets
1448 * num_addrs == 0 Normal mode, clear multicast list
1449 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1450 * and do best-effort filtering.
1451 */
1452
1453 static void
1454 wavelan_set_multicast_list(device * dev)
1455 {
1456 net_local * lp = (net_local *) dev->priv;
1457
1458 #ifdef DEBUG_IOCTL_TRACE
1459 printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
1460 #endif
1461
1462 #ifdef DEBUG_IOCTL_INFO
1463 printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1464 dev->name, dev->flags, dev->mc_count);
1465 #endif
1466
1467 if(dev->flags & IFF_PROMISC)
1468 {
1469 /*
1470 * Enable promiscuous mode: receive all packets.
1471 */
1472 if(!lp->promiscuous)
1473 {
1474 lp->promiscuous = 1;
1475 lp->allmulticast = 0;
1476 lp->mc_count = 0;
1477
1478 wv_82593_reconfig(dev);
1479
1480 /* Tell the kernel that we are doing a really bad job... */
1481 dev->flags |= IFF_PROMISC;
1482 }
1483 }
1484 else
1485 /* If all multicast addresses
1486 * or too much multicast addresses for the hardware filter */
1487 if((dev->flags & IFF_ALLMULTI) ||
1488 (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
1489 {
1490 /*
1491 * Disable promiscuous mode, but active the all multicast mode
1492 */
1493 if(!lp->allmulticast)
1494 {
1495 lp->promiscuous = 0;
1496 lp->allmulticast = 1;
1497 lp->mc_count = 0;
1498
1499 wv_82593_reconfig(dev);
1500
1501 /* Tell the kernel that we are doing a really bad job... */
1502 dev->flags |= IFF_ALLMULTI;
1503 }
1504 }
1505 else
1506 /* If there is some multicast addresses to send */
1507 if(dev->mc_list != (struct dev_mc_list *) NULL)
1508 {
1509 /*
1510 * Disable promiscuous mode, but receive all packets
1511 * in multicast list
1512 */
1513 #ifdef MULTICAST_AVOID
1514 if(lp->promiscuous || lp->allmulticast ||
1515 (dev->mc_count != lp->mc_count))
1516 #endif
1517 {
1518 lp->promiscuous = 0;
1519 lp->allmulticast = 0;
1520 lp->mc_count = dev->mc_count;
1521
1522 wv_82593_reconfig(dev);
1523 }
1524 }
1525 else
1526 {
1527 /*
1528 * Switch to normal mode: disable promiscuous mode and
1529 * clear the multicast list.
1530 */
1531 if(lp->promiscuous || lp->mc_count == 0)
1532 {
1533 lp->promiscuous = 0;
1534 lp->allmulticast = 0;
1535 lp->mc_count = 0;
1536
1537 wv_82593_reconfig(dev);
1538 }
1539 }
1540 #ifdef DEBUG_IOCTL_TRACE
1541 printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
1542 #endif
1543 }
1544
1545 /*------------------------------------------------------------------*/
1546 /*
1547 * This function doesn't exist...
1548 * (Note : it was a nice way to test the reconfigure stuff...)
1549 */
1550 #ifdef SET_MAC_ADDRESS
1551 static int
1552 wavelan_set_mac_address(device * dev,
1553 void * addr)
1554 {
1555 struct sockaddr * mac = addr;
1556
1557 /* Copy the address */
1558 memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1559
1560 /* Reconfig the beast */
1561 wv_82593_reconfig(dev);
1562
1563 return 0;
1564 }
1565 #endif /* SET_MAC_ADDRESS */
1566
1567 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1568
1569 /*------------------------------------------------------------------*/
1570 /*
1571 * Frequency setting (for hardware able of it)
1572 * It's a bit complicated and you don't really want to look into it...
1573 * (called in wavelan_ioctl)
1574 */
1575 static inline int
1576 wv_set_frequency(u_long base, /* i/o port of the card */
1577 iw_freq * frequency)
1578 {
1579 const int BAND_NUM = 10; /* Number of bands */
1580 long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
1581 #ifdef DEBUG_IOCTL_INFO
1582 int i;
1583 #endif
1584
1585 /* Setting by frequency */
1586 /* Theoritically, you may set any frequency between
1587 * the two limits with a 0.5 MHz precision. In practice,
1588 * I don't want you to have trouble with local
1589 * regulations... */
1590 if((frequency->e == 1) &&
1591 (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
1592 {
1593 freq = ((frequency->m / 10000) - 24000L) / 5;
1594 }
1595
1596 /* Setting by channel (same as wfreqsel) */
1597 /* Warning : each channel is 22MHz wide, so some of the channels
1598 * will interfere... */
1599 if((frequency->e == 0) &&
1600 (frequency->m >= 0) && (frequency->m < BAND_NUM))
1601 {
1602 /* Get frequency offset. */
1603 freq = channel_bands[frequency->m] >> 1;
1604 }
1605
1606 /* Verify if the frequency is allowed */
1607 if(freq != 0L)
1608 {
1609 u_short table[10]; /* Authorized frequency table */
1610
1611 /* Read the frequency table */
1612 fee_read(base, 0x71 /* frequency table */,
1613 table, 10);
1614
1615 #ifdef DEBUG_IOCTL_INFO
1616 printk(KERN_DEBUG "Frequency table :");
1617 for(i = 0; i < 10; i++)
1618 {
1619 printk(" %04X",
1620 table[i]);
1621 }
1622 printk("\n");
1623 #endif
1624
1625 /* Look in the table if the frequency is allowed */
1626 if(!(table[9 - ((freq - 24) / 16)] &
1627 (1 << ((freq - 24) % 16))))
1628 return -EINVAL; /* not allowed */
1629 }
1630 else
1631 return -EINVAL;
1632
1633 /* If we get a usable frequency */
1634 if(freq != 0L)
1635 {
1636 unsigned short area[16];
1637 unsigned short dac[2];
1638 unsigned short area_verify[16];
1639 unsigned short dac_verify[2];
1640 /* Corresponding gain (in the power adjust value table)
1641 * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
1642 * & WCIN062D.DOC, page 6.2.9 */
1643 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1644 int power_band = 0; /* Selected band */
1645 unsigned short power_adjust; /* Correct value */
1646
1647 /* Search for the gain */
1648 power_band = 0;
1649 while((freq > power_limit[power_band]) &&
1650 (power_limit[++power_band] != 0))
1651 ;
1652
1653 /* Read the first area */
1654 fee_read(base, 0x00,
1655 area, 16);
1656
1657 /* Read the DAC */
1658 fee_read(base, 0x60,
1659 dac, 2);
1660
1661 /* Read the new power adjust value */
1662 fee_read(base, 0x6B - (power_band >> 1),
1663 &power_adjust, 1);
1664 if(power_band & 0x1)
1665 power_adjust >>= 8;
1666 else
1667 power_adjust &= 0xFF;
1668
1669 #ifdef DEBUG_IOCTL_INFO
1670 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1671 for(i = 0; i < 16; i++)
1672 {
1673 printk(" %04X",
1674 area[i]);
1675 }
1676 printk("\n");
1677
1678 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1679 dac[0], dac[1]);
1680 #endif
1681
1682 /* Frequency offset (for info only...) */
1683 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1684
1685 /* Receiver Principle main divider coefficient */
1686 area[3] = (freq >> 1) + 2400L - 352L;
1687 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1688
1689 /* Transmitter Main divider coefficient */
1690 area[13] = (freq >> 1) + 2400L;
1691 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1692
1693 /* Others part of the area are flags, bit streams or unused... */
1694
1695 /* Set the value in the DAC */
1696 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1697 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1698
1699 /* Write the first area */
1700 fee_write(base, 0x00,
1701 area, 16);
1702
1703 /* Write the DAC */
1704 fee_write(base, 0x60,
1705 dac, 2);
1706
1707 /* We now should verify here that the EEprom writting was ok */
1708
1709 /* ReRead the first area */
1710 fee_read(base, 0x00,
1711 area_verify, 16);
1712
1713 /* ReRead the DAC */
1714 fee_read(base, 0x60,
1715 dac_verify, 2);
1716
1717 /* Compare */
1718 if(memcmp(area, area_verify, 16 * 2) ||
1719 memcmp(dac, dac_verify, 2 * 2))
1720 {
1721 #ifdef DEBUG_IOCTL_ERROR
1722 printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
1723 #endif
1724 return -EOPNOTSUPP;
1725 }
1726
1727 /* We must download the frequency parameters to the
1728 * synthetisers (from the EEprom - area 1)
1729 * Note : as the EEprom is auto decremented, we set the end
1730 * if the area... */
1731 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
1732 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1733 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1734
1735 /* Wait until the download is finished */
1736 fee_wait(base, 100, 100);
1737
1738 /* We must now download the power adjust value (gain) to
1739 * the synthetisers (from the EEprom - area 7 - DAC) */
1740 mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
1741 mmc_out(base, mmwoff(0, mmw_fee_ctrl),
1742 MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1743
1744 /* Wait until the download is finished */
1745 fee_wait(base, 100, 100);
1746
1747 #ifdef DEBUG_IOCTL_INFO
1748 /* Verification of what we have done... */
1749
1750 printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
1751 for(i = 0; i < 16; i++)
1752 {
1753 printk(" %04X",
1754 area_verify[i]);
1755 }
1756 printk("\n");
1757
1758 printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
1759 dac_verify[0], dac_verify[1]);
1760 #endif
1761
1762 return 0;
1763 }
1764 else
1765 return -EINVAL; /* Bah, never get there... */
1766 }
1767
1768 /*------------------------------------------------------------------*/
1769 /*
1770 * Give the list of available frequencies
1771 */
1772 static inline int
1773 wv_frequency_list(u_long base, /* i/o port of the card */
1774 iw_freq * list, /* List of frequency to fill */
1775 int max) /* Maximum number of frequencies */
1776 {
1777 u_short table[10]; /* Authorized frequency table */
1778 long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1779 int i; /* index in the table */
1780 #if WIRELESS_EXT > 7
1781 const int BAND_NUM = 10; /* Number of bands */
1782 int c = 0; /* Channel number */
1783 #endif /* WIRELESS_EXT */
1784
1785 /* Read the frequency table */
1786 fee_read(base, 0x71 /* frequency table */,
1787 table, 10);
1788
1789 /* Look all frequencies */
1790 i = 0;
1791 for(freq = 0; freq < 150; freq++)
1792 /* Look in the table if the frequency is allowed */
1793 if(table[9 - (freq / 16)] & (1 << (freq % 16)))
1794 {
1795 #if WIRELESS_EXT > 7
1796 /* Compute approximate channel number */
1797 while((((channel_bands[c] >> 1) - 24) < freq) &&
1798 (c < BAND_NUM))
1799 c++;
1800 list[i].i = c; /* Set the list index */
1801 #endif /* WIRELESS_EXT */
1802
1803 /* put in the list */
1804 list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1805 list[i++].e = 1;
1806
1807 /* Check number */
1808 if(i >= max)
1809 return(i);
1810 }
1811
1812 return(i);
1813 }
1814
1815 #ifdef WIRELESS_SPY
1816 /*------------------------------------------------------------------*/
1817 /*
1818 * Gather wireless spy statistics : for each packet, compare the source
1819 * address with out list, and if match, get the stats...
1820 * Sorry, but this function really need wireless extensions...
1821 */
1822 static inline void
1823 wl_spy_gather(device * dev,
1824 u_char * mac, /* MAC address */
1825 u_char * stats) /* Statistics to gather */
1826 {
1827 net_local * lp = (net_local *) dev->priv;
1828 int i;
1829
1830 /* Look all addresses */
1831 for(i = 0; i < lp->spy_number; i++)
1832 /* If match */
1833 if(!memcmp(mac, lp->spy_address[i], WAVELAN_ADDR_SIZE))
1834 {
1835 /* Update statistics */
1836 lp->spy_stat[i].qual = stats[2] & MMR_SGNL_QUAL;
1837 lp->spy_stat[i].level = stats[0] & MMR_SIGNAL_LVL;
1838 lp->spy_stat[i].noise = stats[1] & MMR_SILENCE_LVL;
1839 lp->spy_stat[i].updated = 0x7;
1840 }
1841 }
1842 #endif /* WIRELESS_SPY */
1843
1844 #ifdef HISTOGRAM
1845 /*------------------------------------------------------------------*/
1846 /*
1847 * This function calculate an histogram on the signal level.
1848 * As the noise is quite constant, it's like doing it on the SNR.
1849 * We have defined a set of interval (lp->his_range), and each time
1850 * the level goes in that interval, we increment the count (lp->his_sum).
1851 * With this histogram you may detect if one wavelan is really weak,
1852 * or you may also calculate the mean and standard deviation of the level...
1853 */
1854 static inline void
1855 wl_his_gather(device * dev,
1856 u_char * stats) /* Statistics to gather */
1857 {
1858 net_local * lp = (net_local *) dev->priv;
1859 u_char level = stats[0] & MMR_SIGNAL_LVL;
1860 int i;
1861
1862 /* Find the correct interval */
1863 i = 0;
1864 while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
1865 ;
1866
1867 /* Increment interval counter */
1868 (lp->his_sum[i])++;
1869 }
1870 #endif /* HISTOGRAM */
1871
1872 /*------------------------------------------------------------------*/
1873 /*
1874 * Perform ioctl : config & info stuff
1875 * This is here that are treated the wireless extensions (iwconfig)
1876 */
1877 static int
1878 wavelan_ioctl(struct net_device * dev, /* Device on wich the ioctl apply */
1879 struct ifreq * rq, /* Data passed */
1880 int cmd) /* Ioctl number */
1881 {
1882 ioaddr_t base = dev->base_addr;
1883 net_local * lp = (net_local *)dev->priv; /* lp is not unused */
1884 struct iwreq * wrq = (struct iwreq *) rq;
1885 psa_t psa;
1886 mm_t m;
1887 unsigned long flags;
1888 int ret = 0;
1889
1890 #ifdef DEBUG_IOCTL_TRACE
1891 printk(KERN_DEBUG "%s: ->wavelan_ioctl(cmd=0x%X)\n", dev->name, cmd);
1892 #endif
1893
1894 /* Disable interrupts & save flags */
1895 spin_lock_irqsave (&lp->lock, flags);
1896
1897 /* Look what is the request */
1898 switch(cmd)
1899 {
1900 /* --------------- WIRELESS EXTENSIONS --------------- */
1901
1902 case SIOCGIWNAME:
1903 strcpy(wrq->u.name, "Wavelan");
1904 break;
1905
1906 case SIOCSIWNWID:
1907 /* Set NWID in wavelan */
1908 #if WIRELESS_EXT > 8
1909 if(!wrq->u.nwid.disabled)
1910 {
1911 /* Set NWID in psa */
1912 psa.psa_nwid[0] = (wrq->u.nwid.value & 0xFF00) >> 8;
1913 psa.psa_nwid[1] = wrq->u.nwid.value & 0xFF;
1914 #else /* WIRELESS_EXT > 8 */
1915 if(wrq->u.nwid.on)
1916 {
1917 /* Set NWID in psa */
1918 psa.psa_nwid[0] = (wrq->u.nwid.nwid & 0xFF00) >> 8;
1919 psa.psa_nwid[1] = wrq->u.nwid.nwid & 0xFF;
1920 #endif /* WIRELESS_EXT > 8 */
1921 psa.psa_nwid_select = 0x01;
1922 psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
1923 (unsigned char *)psa.psa_nwid, 3);
1924
1925 /* Set NWID in mmc */
1926 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1927 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1928 mmc_write(base, (char *)&m.w.mmw_netw_id_l - (char *)&m,
1929 (unsigned char *)&m.w.mmw_netw_id_l, 2);
1930 mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
1931 }
1932 else
1933 {
1934 /* Disable nwid in the psa */
1935 psa.psa_nwid_select = 0x00;
1936 psa_write(dev, (char *)&psa.psa_nwid_select - (char *)&psa,
1937 (unsigned char *)&psa.psa_nwid_select, 1);
1938
1939 /* Disable nwid in the mmc (no filtering) */
1940 mmc_out(base, mmwoff(0, mmw_loopt_sel), MMW_LOOPT_SEL_DIS_NWID);
1941 }
1942 /* update the Wavelan checksum */
1943 update_psa_checksum(dev);
1944 break;
1945
1946 case SIOCGIWNWID:
1947 /* Read the NWID */
1948 psa_read(dev, (char *)psa.psa_nwid - (char *)&psa,
1949 (unsigned char *)psa.psa_nwid, 3);
1950 #if WIRELESS_EXT > 8
1951 wrq->u.nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1952 wrq->u.nwid.disabled = !(psa.psa_nwid_select);
1953 wrq->u.nwid.fixed = 1; /* Superfluous */
1954 #else /* WIRELESS_EXT > 8 */
1955 wrq->u.nwid.nwid = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1956 wrq->u.nwid.on = psa.psa_nwid_select;
1957 #endif /* WIRELESS_EXT > 8 */
1958 break;
1959
1960 case SIOCSIWFREQ:
1961 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable) */
1962 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1963 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1964 ret = wv_set_frequency(base, &(wrq->u.freq));
1965 else
1966 ret = -EOPNOTSUPP;
1967 break;
1968
1969 case SIOCGIWFREQ:
1970 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
1971 * (does it work for everybody XXX - especially old cards...) */
1972 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
1973 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1974 {
1975 unsigned short freq;
1976
1977 /* Ask the EEprom to read the frequency from the first area */
1978 fee_read(base, 0x00 /* 1st area - frequency... */,
1979 &freq, 1);
1980 wrq->u.freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
1981 wrq->u.freq.e = 1;
1982 }
1983 else
1984 {
1985 psa_read(dev, (char *)&psa.psa_subband - (char *)&psa,
1986 (unsigned char *)&psa.psa_subband, 1);
1987
1988 if(psa.psa_subband <= 4)
1989 {
1990 wrq->u.freq.m = fixed_bands[psa.psa_subband];
1991 wrq->u.freq.e = (psa.psa_subband != 0);
1992 }
1993 else
1994 ret = -EOPNOTSUPP;
1995 }
1996 break;
1997
1998 case SIOCSIWSENS:
1999 /* Set the level threshold */
2000 #if WIRELESS_EXT > 7
2001 /* We should complain loudly if wrq->u.sens.fixed = 0, because we
2002 * can't set auto mode... */
2003 psa.psa_thr_pre_set = wrq->u.sens.value & 0x3F;
2004 #else /* WIRELESS_EXT > 7 */
2005 psa.psa_thr_pre_set = wrq->u.sensitivity & 0x3F;
2006 #endif /* WIRELESS_EXT > 7 */
2007 psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
2008 (unsigned char *)&psa.psa_thr_pre_set, 1);
2009 /* update the Wavelan checksum */
2010 update_psa_checksum(dev);
2011 mmc_out(base, mmwoff(0, mmw_thr_pre_set), psa.psa_thr_pre_set);
2012 break;
2013
2014 case SIOCGIWSENS:
2015 /* Read the level threshold */
2016 psa_read(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
2017 (unsigned char *)&psa.psa_thr_pre_set, 1);
2018 #if WIRELESS_EXT > 7
2019 wrq->u.sens.value = psa.psa_thr_pre_set & 0x3F;
2020 wrq->u.sens.fixed = 1;
2021 #else /* WIRELESS_EXT > 7 */
2022 wrq->u.sensitivity = psa.psa_thr_pre_set & 0x3F;
2023 #endif /* WIRELESS_EXT > 7 */
2024 break;
2025
2026 #if WIRELESS_EXT > 8
2027 case SIOCSIWENCODE:
2028 /* Set encryption key */
2029 if(!mmc_encr(base))
2030 {
2031 ret = -EOPNOTSUPP;
2032 break;
2033 }
2034
2035 /* Basic checking... */
2036 if(wrq->u.encoding.pointer != (caddr_t) 0)
2037 {
2038 /* Check the size of the key */
2039 if(wrq->u.encoding.length != 8)
2040 {
2041 ret = -EINVAL;
2042 break;
2043 }
2044
2045 /* Copy the key in the driver */
2046 if(copy_from_user(psa.psa_encryption_key, wrq->u.encoding.pointer,
2047 wrq->u.encoding.length))
2048 {
2049 ret = -EFAULT;
2050 break;
2051 }
2052
2053 psa.psa_encryption_select = 1;
2054 psa_write(dev, (char *) &psa.psa_encryption_select - (char *) &psa,
2055 (unsigned char *) &psa.psa_encryption_select, 8+1);
2056
2057 mmc_out(base, mmwoff(0, mmw_encr_enable),
2058 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2059 mmc_write(base, mmwoff(0, mmw_encr_key),
2060 (unsigned char *) &psa.psa_encryption_key, 8);
2061 }
2062
2063 if(wrq->u.encoding.flags & IW_ENCODE_DISABLED)
2064 { /* disable encryption */
2065 psa.psa_encryption_select = 0;
2066 psa_write(dev, (char *) &psa.psa_encryption_select - (char *) &psa,
2067 (unsigned char *) &psa.psa_encryption_select, 1);
2068
2069 mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
2070 }
2071 /* update the Wavelan checksum */
2072 update_psa_checksum(dev);
2073 break;
2074
2075 case SIOCGIWENCODE:
2076 /* Read the encryption key */
2077 if(!mmc_encr(base))
2078 {
2079 ret = -EOPNOTSUPP;
2080 break;
2081 }
2082
2083 /* only super-user can see encryption key */
2084 if(!capable(CAP_NET_ADMIN))
2085 {
2086 ret = -EPERM;
2087 break;
2088 }
2089
2090 /* Basic checking... */
2091 if(wrq->u.encoding.pointer != (caddr_t) 0)
2092 {
2093 psa_read(dev, (char *) &psa.psa_encryption_select - (char *) &psa,
2094 (unsigned char *) &psa.psa_encryption_select, 1+8);
2095
2096 /* encryption is enabled ? */
2097 if(psa.psa_encryption_select)
2098 wrq->u.encoding.flags = IW_ENCODE_ENABLED;
2099 else
2100 wrq->u.encoding.flags = IW_ENCODE_DISABLED;
2101 wrq->u.encoding.flags |= mmc_encr(base);
2102
2103 /* Copy the key to the user buffer */
2104 wrq->u.encoding.length = 8;
2105 if(copy_to_user(wrq->u.encoding.pointer, psa.psa_encryption_key, 8))
2106 ret = -EFAULT;
2107 }
2108 break;
2109 #endif /* WIRELESS_EXT > 8 */
2110
2111 #ifdef WAVELAN_ROAMING_EXT
2112 #if WIRELESS_EXT > 5
2113 case SIOCSIWESSID:
2114 /* Check if disable */
2115 if(wrq->u.data.flags == 0)
2116 lp->filter_domains = 0;
2117 else
2118 /* Basic checking... */
2119 if(wrq->u.data.pointer != (caddr_t) 0)
2120 {
2121 char essid[IW_ESSID_MAX_SIZE + 1];
2122 char * endp;
2123
2124 /* Check the size of the string */
2125 if(wrq->u.data.length > IW_ESSID_MAX_SIZE + 1)
2126 {
2127 ret = -E2BIG;
2128 break;
2129 }
2130
2131 /* Copy the string in the driver */
2132 if(copy_from_user(essid, wrq->u.data.pointer, wrq->u.data.length))
2133 {
2134 ret = -EFAULT;
2135 break;
2136 }
2137 essid[IW_ESSID_MAX_SIZE] = '\0';
2138
2139 #ifdef DEBUG_IOCTL_INFO
2140 printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
2141 #endif /* DEBUG_IOCTL_INFO */
2142
2143 /* Convert to a number (note : Wavelan specific) */
2144 lp->domain_id = simple_strtoul(essid, &endp, 16);
2145 /* Has it worked ? */
2146 if(endp > essid)
2147 lp->filter_domains = 1;
2148 else
2149 {
2150 lp->filter_domains = 0;
2151 ret = -EINVAL;
2152 }
2153 }
2154 break;
2155
2156 case SIOCGIWESSID:
2157 /* Basic checking... */
2158 if(wrq->u.data.pointer != (caddr_t) 0)
2159 {
2160 char essid[IW_ESSID_MAX_SIZE + 1];
2161
2162 /* Is the domain ID active ? */
2163 wrq->u.data.flags = lp->filter_domains;
2164
2165 /* Copy Domain ID into a string (Wavelan specific) */
2166 /* Sound crazy, be we can't have a snprintf in the kernel !!! */
2167 sprintf(essid, "%lX", lp->domain_id);
2168 essid[IW_ESSID_MAX_SIZE] = '\0';
2169
2170 /* Set the length */
2171 wrq->u.data.length = strlen(essid) + 1;
2172
2173 /* Copy structure to the user buffer */
2174 if(copy_to_user(wrq->u.data.pointer, essid, wrq->u.data.length))
2175 ret = -EFAULT;
2176 }
2177 break;
2178
2179 case SIOCSIWAP:
2180 #ifdef DEBUG_IOCTL_INFO
2181 printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
2182 wrq->u.ap_addr.sa_data[0],
2183 wrq->u.ap_addr.sa_data[1],
2184 wrq->u.ap_addr.sa_data[2],
2185 wrq->u.ap_addr.sa_data[3],
2186 wrq->u.ap_addr.sa_data[4],
2187 wrq->u.ap_addr.sa_data[5]);
2188 #endif /* DEBUG_IOCTL_INFO */
2189
2190 ret = -EOPNOTSUPP; /* Not supported yet */
2191 break;
2192
2193 case SIOCGIWAP:
2194 /* Should get the real McCoy instead of own Ethernet address */
2195 memcpy(wrq->u.ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
2196 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
2197
2198 ret = -EOPNOTSUPP; /* Not supported yet */
2199 break;
2200 #endif /* WIRELESS_EXT > 5 */
2201 #endif /* WAVELAN_ROAMING_EXT */
2202
2203 #if WIRELESS_EXT > 8
2204 #ifdef WAVELAN_ROAMING
2205 case SIOCSIWMODE:
2206 switch(wrq->u.mode)
2207 {
2208 case IW_MODE_ADHOC:
2209 if(do_roaming)
2210 {
2211 wv_roam_cleanup(dev);
2212 do_roaming = 0;
2213 }
2214 break;
2215 case IW_MODE_INFRA:
2216 if(!do_roaming)
2217 {
2218 wv_roam_init(dev);
2219 do_roaming = 1;
2220 }
2221 break;
2222 default:
2223 ret = -EINVAL;
2224 }
2225 break;
2226
2227 case SIOCGIWMODE:
2228 if(do_roaming)
2229 wrq->u.mode = IW_MODE_INFRA;
2230 else
2231 wrq->u.mode = IW_MODE_ADHOC;
2232 break;
2233 #endif /* WAVELAN_ROAMING */
2234 #endif /* WIRELESS_EXT > 8 */
2235
2236 case SIOCGIWRANGE:
2237 /* Basic checking... */
2238 if(wrq->u.data.pointer != (caddr_t) 0)
2239 {
2240 struct iw_range range;
2241
2242 /* Set the length (very important for backward compatibility) */
2243 wrq->u.data.length = sizeof(struct iw_range);
2244
2245 /* Set all the info we don't care or don't know about to zero */
2246 memset(&range, 0, sizeof(range));
2247
2248 /* Set the Wireless Extension versions */
2249 range.we_version_compiled = WIRELESS_EXT;
2250 range.we_version_source = 9; /* Nothing for us in v10 and v11 */
2251
2252 /* Set information in the range struct */
2253 range.throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
2254 range.min_nwid = 0x0000;
2255 range.max_nwid = 0xFFFF;
2256
2257 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable) */
2258 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
2259 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
2260 {
2261 range.num_channels = 10;
2262 range.num_frequency = wv_frequency_list(base, range.freq,
2263 IW_MAX_FREQUENCIES);
2264 }
2265 else
2266 range.num_channels = range.num_frequency = 0;
2267
2268 range.sensitivity = 0x3F;
2269 range.max_qual.qual = MMR_SGNL_QUAL;
2270 range.max_qual.level = MMR_SIGNAL_LVL;
2271 range.max_qual.noise = MMR_SILENCE_LVL;
2272
2273 #if WIRELESS_EXT > 7
2274 range.num_bitrates = 1;
2275 range.bitrate[0] = 2000000; /* 2 Mb/s */
2276 #endif /* WIRELESS_EXT > 7 */
2277
2278 #if WIRELESS_EXT > 8
2279 /* Encryption supported ? */
2280 if(mmc_encr(base))
2281 {
2282 range.encoding_size[0] = 8; /* DES = 64 bits key */
2283 range.num_encoding_sizes = 1;
2284 range.max_encoding_tokens = 1; /* Only one key possible */
2285 }
2286 else
2287 {
2288 range.num_encoding_sizes = 0;
2289 range.max_encoding_tokens = 0;
2290 }
2291 #endif /* WIRELESS_EXT > 8 */
2292
2293 /* Copy structure to the user buffer */
2294 if(copy_to_user(wrq->u.data.pointer, &range,
2295 sizeof(struct iw_range)))
2296 ret = -EFAULT;
2297 }
2298 break;
2299
2300 case SIOCGIWPRIV:
2301 /* Basic checking... */
2302 if(wrq->u.data.pointer != (caddr_t) 0)
2303 {
2304 struct iw_priv_args priv[] =
2305 { /* cmd, set_args, get_args, name */
2306 { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2307 { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2308 { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
2309 { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
2310 { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1 , 0, "setroam" },
2311 { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
2312 };
2313
2314 /* Set the number of ioctl available */
2315 wrq->u.data.length = 6;
2316
2317 /* Copy structure to the user buffer */
2318 if(copy_to_user(wrq->u.data.pointer, (u_char *) priv,
2319 sizeof(priv)))
2320 ret = -EFAULT;
2321 }
2322 break;
2323
2324 #ifdef WIRELESS_SPY
2325 case SIOCSIWSPY:
2326 /* Set the spy list */
2327
2328 /* Check the number of addresses */
2329 if(wrq->u.data.length > IW_MAX_SPY)
2330 {
2331 ret = -E2BIG;
2332 break;
2333 }
2334 lp->spy_number = wrq->u.data.length;
2335
2336 /* If there is some addresses to copy */
2337 if(lp->spy_number > 0)
2338 {
2339 struct sockaddr address[IW_MAX_SPY];
2340 int i;
2341
2342 /* Copy addresses to the driver */
2343 if(copy_from_user(address, wrq->u.data.pointer,
2344 sizeof(struct sockaddr) * lp->spy_number))
2345 {
2346 ret = -EFAULT;
2347 break;
2348 }
2349
2350 /* Copy addresses to the lp structure */
2351 for(i = 0; i < lp->spy_number; i++)
2352 {
2353 memcpy(lp->spy_address[i], address[i].sa_data,
2354 WAVELAN_ADDR_SIZE);
2355 }
2356
2357 /* Reset structure... */
2358 memset(lp->spy_stat, 0x00, sizeof(iw_qual) * IW_MAX_SPY);
2359
2360 #ifdef DEBUG_IOCTL_INFO
2361 printk(KERN_DEBUG "SetSpy - Set of new addresses is :\n");
2362 for(i = 0; i < wrq->u.data.length; i++)
2363 printk(KERN_DEBUG "%02X:%02X:%02X:%02X:%02X:%02X\n",
2364 lp->spy_address[i][0],
2365 lp->spy_address[i][1],
2366 lp->spy_address[i][2],
2367 lp->spy_address[i][3],
2368 lp->spy_address[i][4],
2369 lp->spy_address[i][5]);
2370 #endif /* DEBUG_IOCTL_INFO */
2371 }
2372
2373 break;
2374
2375 case SIOCGIWSPY:
2376 /* Get the spy list and spy stats */
2377
2378 /* Set the number of addresses */
2379 wrq->u.data.length = lp->spy_number;
2380
2381 /* If the user want to have the addresses back... */
2382 if((lp->spy_number > 0) && (wrq->u.data.pointer != (caddr_t) 0))
2383 {
2384 struct sockaddr address[IW_MAX_SPY];
2385 int i;
2386
2387 /* Copy addresses from the lp structure */
2388 for(i = 0; i < lp->spy_number; i++)
2389 {
2390 memcpy(address[i].sa_data, lp->spy_address[i],
2391 WAVELAN_ADDR_SIZE);
2392 address[i].sa_family = ARPHRD_ETHER;
2393 }
2394
2395 /* Copy addresses to the user buffer */
2396 if(copy_to_user(wrq->u.data.pointer, address,
2397 sizeof(struct sockaddr) * lp->spy_number))
2398 {
2399 ret = -EFAULT;
2400 break;
2401 }
2402
2403 /* Copy stats to the user buffer (just after) */
2404 if(copy_to_user(wrq->u.data.pointer +
2405 (sizeof(struct sockaddr) * lp->spy_number),
2406 lp->spy_stat, sizeof(iw_qual) * lp->spy_number))
2407 {
2408 ret = -EFAULT;
2409 break;
2410 }
2411
2412 /* Reset updated flags */
2413 for(i = 0; i < lp->spy_number; i++)
2414 lp->spy_stat[i].updated = 0x0;
2415 } /* if(pointer != NULL) */
2416
2417 break;
2418 #endif /* WIRELESS_SPY */
2419
2420 /* ------------------ PRIVATE IOCTL ------------------ */
2421
2422 case SIOCSIPQTHR:
2423 if(!capable(CAP_NET_ADMIN))
2424 {
2425 ret = -EPERM;
2426 break;
2427 }
2428 psa.psa_quality_thr = *(wrq->u.name) & 0x0F;
2429 psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
2430 (unsigned char *)&psa.psa_quality_thr, 1);
2431 /* update the Wavelan checksum */
2432 update_psa_checksum(dev);
2433 mmc_out(base, mmwoff(0, mmw_quality_thr), psa.psa_quality_thr);
2434 break;
2435
2436 case SIOCGIPQTHR:
2437 psa_read(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
2438 (unsigned char *)&psa.psa_quality_thr, 1);
2439 *(wrq->u.name) = psa.psa_quality_thr & 0x0F;
2440 break;
2441
2442 #ifdef WAVELAN_ROAMING
2443 case SIOCSIPROAM:
2444 /* Note : should check if user == root */
2445 if(do_roaming && (*wrq->u.name)==0)
2446 wv_roam_cleanup(dev);
2447 else if(do_roaming==0 && (*wrq->u.name)!=0)
2448 wv_roam_init(dev);
2449
2450 do_roaming = (*wrq->u.name);
2451
2452 break;
2453
2454 case SIOCGIPROAM:
2455 *(wrq->u.name) = do_roaming;
2456 break;
2457 #endif /* WAVELAN_ROAMING */
2458
2459 #ifdef HISTOGRAM
2460 case SIOCSIPHISTO:
2461 /* Verif if the user is root */
2462 if(!capable(CAP_NET_ADMIN))
2463 {
2464 ret = -EPERM;
2465 }
2466
2467 /* Check the number of intervals */
2468 if(wrq->u.data.length > 16)
2469 {
2470 ret = -E2BIG;
2471 break;
2472 }
2473 lp->his_number = wrq->u.data.length;
2474
2475 /* If there is some addresses to copy */
2476 if(lp->his_number > 0)
2477 {
2478 /* Copy interval ranges to the driver */
2479 if(copy_from_user(lp->his_range, wrq->u.data.pointer,
2480 sizeof(char) * lp->his_number))
2481 {
2482 ret = -EFAULT;
2483 break;
2484 }
2485
2486 /* Reset structure... */
2487 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2488 }
2489 break;
2490
2491 case SIOCGIPHISTO:
2492 /* Set the number of intervals */
2493 wrq->u.data.length = lp->his_number;
2494
2495 /* Give back the distribution statistics */
2496 if((lp->his_number > 0) && (wrq->u.data.pointer != (caddr_t) 0))
2497 {
2498 /* Copy data to the user buffer */
2499 if(copy_to_user(wrq->u.data.pointer, lp->his_sum,
2500 sizeof(long) * lp->his_number))
2501 ret = -EFAULT;
2502
2503 } /* if(pointer != NULL) */
2504 break;
2505 #endif /* HISTOGRAM */
2506
2507 /* ------------------- OTHER IOCTL ------------------- */
2508
2509 default:
2510 ret = -EOPNOTSUPP;
2511 }
2512
2513 /* ReEnable interrupts & restore flags */
2514 spin_unlock_irqrestore (&lp->lock, flags);
2515
2516 #ifdef DEBUG_IOCTL_TRACE
2517 printk(KERN_DEBUG "%s: <-wavelan_ioctl()\n", dev->name);
2518 #endif
2519 return ret;
2520 }
2521
2522 /*------------------------------------------------------------------*/
2523 /*
2524 * Get wireless statistics
2525 * Called by /proc/net/wireless...
2526 */
2527 static iw_stats *
2528 wavelan_get_wireless_stats(device * dev)
2529 {
2530 ioaddr_t base = dev->base_addr;
2531 net_local * lp = (net_local *) dev->priv;
2532 mmr_t m;
2533 iw_stats * wstats;
2534 unsigned long flags;
2535
2536 #ifdef DEBUG_IOCTL_TRACE
2537 printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
2538 #endif
2539
2540 if (lp == NULL) /* XXX will this ever occur? */
2541 return NULL;
2542
2543 /* Disable interrupts & save flags */
2544 spin_lock_irqsave (&lp->lock, flags);
2545
2546 wstats = &lp->wstats;
2547
2548 /* Get data from the mmc */
2549 mmc_out(base, mmwoff(0, mmw_freeze), 1);
2550
2551 mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2552 mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
2553 mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
2554
2555 mmc_out(base, mmwoff(0, mmw_freeze), 0);
2556
2557 /* Copy data to wireless stuff */
2558 wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2559 wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2560 wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2561 wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2562 wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
2563 ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
2564 ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2565 wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2566 wstats->discard.code = 0L;
2567 wstats->discard.misc = 0L;
2568
2569 /* ReEnable interrupts & restore flags */
2570 spin_unlock_irqrestore (&lp->lock, flags);
2571
2572 #ifdef DEBUG_IOCTL_TRACE
2573 printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
2574 #endif
2575 return &lp->wstats;
2576 }
2577 #endif /* WIRELESS_EXT */
2578
2579 /************************* PACKET RECEPTION *************************/
2580 /*
2581 * This part deal with receiving the packets.
2582 * The interrupt handler get an interrupt when a packet has been
2583 * successfully received and called this part...
2584 */
2585
2586 /*------------------------------------------------------------------*/
2587 /*
2588 * Calculate the starting address of the frame pointed to by the receive
2589 * frame pointer and verify that the frame seem correct
2590 * (called by wv_packet_rcv())
2591 */
2592 static inline int
2593 wv_start_of_frame(device * dev,
2594 int rfp, /* end of frame */
2595 int wrap) /* start of buffer */
2596 {
2597 ioaddr_t base = dev->base_addr;
2598 int rp;
2599 int len;
2600
2601 rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
2602 outb(rp & 0xff, PIORL(base));
2603 outb(((rp >> 8) & PIORH_MASK), PIORH(base));
2604 len = inb(PIOP(base));
2605 len |= inb(PIOP(base)) << 8;
2606
2607 /* Sanity checks on size */
2608 /* Frame too big */
2609 if(len > MAXDATAZ + 100)
2610 {
2611 #ifdef DEBUG_RX_ERROR
2612 printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
2613 dev->name, rfp, len);
2614 #endif
2615 return(-1);
2616 }
2617
2618 /* Frame too short */
2619 if(len < 7)
2620 {
2621 #ifdef DEBUG_RX_ERROR
2622 printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
2623 dev->name, rfp, len);
2624 #endif
2625 return(-1);
2626 }
2627
2628 /* Wrap around buffer */
2629 if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
2630 {
2631 #ifdef DEBUG_RX_ERROR
2632 printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
2633 dev->name, wrap, rfp, len);
2634 #endif
2635 return(-1);
2636 }
2637
2638 return((rp - len + RX_SIZE) % RX_SIZE);
2639 } /* wv_start_of_frame */
2640
2641 /*------------------------------------------------------------------*/
2642 /*
2643 * This routine does the actual copy of data (including the ethernet
2644 * header structure) from the WaveLAN card to an sk_buff chain that
2645 * will be passed up to the network interface layer. NOTE: We
2646 * currently don't handle trailer protocols (neither does the rest of
2647 * the network interface), so if that is needed, it will (at least in
2648 * part) be added here. The contents of the receive ring buffer are
2649 * copied to a message chain that is then passed to the kernel.
2650 *
2651 * Note: if any errors occur, the packet is "dropped on the floor"
2652 * (called by wv_packet_rcv())
2653 */
2654 static inline void
2655 wv_packet_read(device * dev,
2656 int fd_p,
2657 int sksize)
2658 {
2659 net_local * lp = (net_local *) dev->priv;
2660 struct sk_buff * skb;
2661
2662 #ifdef DEBUG_RX_TRACE
2663 printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2664 dev->name, fd_p, sksize);
2665 #endif
2666
2667 /* Allocate some buffer for the new packet */
2668 if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
2669 {
2670 #ifdef DEBUG_RX_ERROR
2671 printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
2672 dev->name, sksize);
2673 #endif
2674 lp->stats.rx_dropped++;
2675 /*
2676 * Not only do we want to return here, but we also need to drop the
2677 * packet on the floor to clear the interrupt.
2678 */
2679 return;
2680 }
2681
2682 skb->dev = dev;
2683
2684 skb_reserve(skb, 2);
2685 fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
2686 skb->protocol = eth_type_trans(skb, dev);
2687
2688 #ifdef DEBUG_RX_INFO
2689 /* Another glitch : Due to the way the GET_PACKET macro is written,
2690 * we are not sure to have the same thing in skb->data. On the other
2691 * hand, skb->mac.raw is not defined everywhere...
2692 * For versions between 1.2.13 and those where skb->mac.raw appear,
2693 * I don't have a clue...
2694 */
2695 wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2696 #endif /* DEBUG_RX_INFO */
2697
2698 /* Statistics gathering & stuff associated.
2699 * It seem a bit messy with all the define, but it's really simple... */
2700 if(
2701 #ifdef WIRELESS_SPY
2702 (lp->spy_number > 0) ||
2703 #endif /* WIRELESS_SPY */
2704 #ifdef HISTOGRAM
2705 (lp->his_number > 0) ||
2706 #endif /* HISTOGRAM */
2707 #ifdef WAVELAN_ROAMING
2708 (do_roaming) ||
2709 #endif /* WAVELAN_ROAMING */
2710 0)
2711 {
2712 u_char stats[3]; /* Signal level, Noise level, Signal quality */
2713
2714 /* read signal level, silence level and signal quality bytes */
2715 fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
2716 stats, 3);
2717 #ifdef DEBUG_RX_INFO
2718 printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2719 dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
2720 #endif
2721
2722 #ifdef WAVELAN_ROAMING
2723 if(do_roaming)
2724 if(WAVELAN_BEACON(skb->data))
2725 wl_roam_gather(dev, skb->data, stats);
2726 #endif /* WAVELAN_ROAMING */
2727
2728 /* Spying stuff */
2729 #ifdef WIRELESS_SPY
2730 /* Same as above */
2731 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
2732 #endif /* WIRELESS_SPY */
2733 #ifdef HISTOGRAM
2734 wl_his_gather(dev, stats);
2735 #endif /* HISTOGRAM */
2736 }
2737
2738 /*
2739 * Hand the packet to the Network Module
2740 */
2741 netif_rx(skb);
2742
2743 /* Keep stats up to date */
2744 dev->last_rx = jiffies;
2745 lp->stats.rx_packets++;
2746 lp->stats.rx_bytes += sksize;
2747
2748 #ifdef DEBUG_RX_TRACE
2749 printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2750 #endif
2751 return;
2752 }
2753
2754 /*------------------------------------------------------------------*/
2755 /*
2756 * This routine is called by the interrupt handler to initiate a
2757 * packet transfer from the card to the network interface layer above
2758 * this driver. This routine checks if a buffer has been successfully
2759 * received by the WaveLAN card. If so, the routine wv_packet_read is
2760 * called to do the actual transfer of the card's data including the
2761 * ethernet header into a packet consisting of an sk_buff chain.
2762 * (called by wavelan_interrupt())
2763 */
2764 static inline void
2765 wv_packet_rcv(device * dev)
2766 {
2767 ioaddr_t base = dev->base_addr;
2768 net_local * lp = (net_local *) dev->priv;
2769 int newrfp;
2770 int rp;
2771 int len;
2772 int f_start;
2773 int status;
2774 int i593_rfp;
2775 int stat_ptr;
2776 u_char c[4];
2777
2778 #ifdef DEBUG_RX_TRACE
2779 printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
2780 #endif
2781
2782 /* Get the new receive frame pointer from the i82593 chip */
2783 outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
2784 i593_rfp = inb(LCSR(base));
2785 i593_rfp |= inb(LCSR(base)) << 8;
2786 i593_rfp %= RX_SIZE;
2787
2788 /* Get the new receive frame pointer from the WaveLAN card.
2789 * It is 3 bytes more than the increment of the i82593 receive
2790 * frame pointer, for each packet. This is because it includes the
2791 * 3 roaming bytes added by the mmc.
2792 */
2793 newrfp = inb(RPLL(base));
2794 newrfp |= inb(RPLH(base)) << 8;
2795 newrfp %= RX_SIZE;
2796
2797 #ifdef DEBUG_RX_INFO
2798 printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
2799 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
2800 #endif
2801
2802 #ifdef DEBUG_RX_ERROR
2803 /* If no new frame pointer... */
2804 if(lp->overrunning || newrfp == lp->rfp)
2805 printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
2806 dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
2807 #endif
2808
2809 /* Read all frames (packets) received */
2810 while(newrfp != lp->rfp)
2811 {
2812 /* A frame is composed of the packet, followed by a status word,
2813 * the length of the frame (word) and the mmc info (SNR & qual).
2814 * It's because the length is at the end that we can only scan
2815 * frames backward. */
2816
2817 /* Find the first frame by skipping backwards over the frames */
2818 rp = newrfp; /* End of last frame */
2819 while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
2820 (f_start != -1))
2821 rp = f_start;
2822
2823 /* If we had a problem */
2824 if(f_start == -1)
2825 {
2826 #ifdef DEBUG_RX_ERROR
2827 printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
2828 printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
2829 i593_rfp, lp->stop, newrfp, lp->rfp);
2830 #endif
2831 lp->rfp = rp; /* Get to the last usable frame */
2832 continue;
2833 }
2834
2835 /* f_start point to the beggining of the first frame received
2836 * and rp to the beggining of the next one */
2837
2838 /* Read status & length of the frame */
2839 stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
2840 stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
2841 status = c[0] | (c[1] << 8);
2842 len = c[2] | (c[3] << 8);
2843
2844 /* Check status */
2845 if((status & RX_RCV_OK) != RX_RCV_OK)
2846 {
2847 lp->stats.rx_errors++;
2848 if(status & RX_NO_SFD)
2849 lp->stats.rx_frame_errors++;
2850 if(status & RX_CRC_ERR)
2851 lp->stats.rx_crc_errors++;
2852 if(status & RX_OVRRUN)
2853 lp->stats.rx_over_errors++;
2854
2855 #ifdef DEBUG_RX_FAIL
2856 printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
2857 dev->name, status);
2858 #endif
2859 }
2860 else
2861 /* Read the packet and transmit to Linux */
2862 wv_packet_read(dev, f_start, len - 2);
2863
2864 /* One frame has been processed, skip it */
2865 lp->rfp = rp;
2866 }
2867
2868 /*
2869 * Update the frame stop register, but set it to less than
2870 * the full 8K to allow space for 3 bytes of signal strength
2871 * per packet.
2872 */
2873 lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
2874 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
2875 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
2876 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
2877
2878 #ifdef DEBUG_RX_TRACE
2879 printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
2880 #endif
2881 }
2882
2883 /*********************** PACKET TRANSMISSION ***********************/
2884 /*
2885 * This part deal with sending packet through the wavelan
2886 * We copy the packet to the send buffer and then issue the send
2887 * command to the i82593. The result of this operation will be
2888 * checked in wavelan_interrupt()
2889 */
2890
2891 /*------------------------------------------------------------------*/
2892 /*
2893 * This routine fills in the appropriate registers and memory
2894 * locations on the WaveLAN card and starts the card off on
2895 * the transmit.
2896 * (called in wavelan_packet_xmit())
2897 */
2898 static inline void
2899 wv_packet_write(device * dev,
2900 void * buf,
2901 short length)
2902 {
2903 net_local * lp = (net_local *) dev->priv;
2904 ioaddr_t base = dev->base_addr;
2905 unsigned long flags;
2906 int clen = length;
2907 register u_short xmtdata_base = TX_BASE;
2908
2909 #ifdef DEBUG_TX_TRACE
2910 printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
2911 #endif
2912
2913 spin_lock_irqsave (&lp->lock, flags);
2914
2915 /* Check if we need some padding */
2916 if(clen < ETH_ZLEN)
2917 clen = ETH_ZLEN;
2918
2919 /* Write the length of data buffer followed by the buffer */
2920 outb(xmtdata_base & 0xff, PIORL(base));
2921 outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
2922 outb(clen & 0xff, PIOP(base)); /* lsb */
2923 outb(clen >> 8, PIOP(base)); /* msb */
2924
2925 /* Send the data */
2926 outsb(PIOP(base), buf, clen);
2927
2928 /* Indicate end of transmit chain */
2929 outb(OP0_NOP, PIOP(base));
2930 /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
2931 outb(OP0_NOP, PIOP(base));
2932
2933 /* Reset the transmit DMA pointer */
2934 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
2935 hacr_write(base, HACR_DEFAULT);
2936 /* Send the transmit command */
2937 wv_82593_cmd(dev, "wv_packet_write(): transmit",
2938 OP0_TRANSMIT, SR0_NO_RESULT);
2939
2940 /* Keep stats up to date */
2941 lp->stats.tx_bytes += length;
2942
2943 /* If watchdog not already active, activate it... */
2944 if (!timer_pending(&lp->watchdog))
2945 {
2946 /* set timer to expire in WATCHDOG_JIFFIES */
2947 lp->watchdog.expires = jiffies + WATCHDOG_JIFFIES;
2948 add_timer(&lp->watchdog);
2949 }
2950
2951 spin_unlock_irqrestore (&lp->lock, flags);
2952
2953 #ifdef DEBUG_TX_INFO
2954 wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
2955 #endif /* DEBUG_TX_INFO */
2956
2957 #ifdef DEBUG_TX_TRACE
2958 printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
2959 #endif
2960
2961 netif_start_queue (dev);
2962 }
2963
2964 /*------------------------------------------------------------------*/
2965 /*
2966 * This routine is called when we want to send a packet (NET3 callback)
2967 * In this routine, we check if the hardware is ready to accept
2968 * the packet. We also prevent reentrance. Then, we call the function
2969 * to send the packet...
2970 */
2971 static int wavelan_packet_xmit (struct sk_buff *skb,
2972 device * dev)
2973 {
2974 net_local *lp = (net_local *) dev->priv;
2975
2976 #ifdef DEBUG_TX_TRACE
2977 printk (KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
2978 (unsigned) skb);
2979 #endif
2980
2981 /*
2982 * For ethernet, fill in the header.
2983 */
2984
2985 netif_stop_queue (dev);
2986
2987 /*
2988 * Block a timer-based transmit from overlapping a previous transmit.
2989 * In other words, prevent reentering this routine.
2990 */
2991 if (1) {
2992 /* If somebody has asked to reconfigure the controller, we can do it now */
2993 if (lp->reconfig_82593) {
2994 lp->reconfig_82593 = FALSE;
2995 wv_82593_config (dev);
2996 }
2997 #ifdef DEBUG_TX_ERROR
2998 if (skb->next)
2999 printk (KERN_INFO "skb has next\n");
3000 #endif
3001
3002 wv_packet_write (dev, skb->data, skb->len);
3003 }
3004 dev_kfree_skb (skb);
3005
3006 #ifdef DEBUG_TX_TRACE
3007 printk (KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
3008 #endif
3009 return (0);
3010 }
3011
3012 /********************** HARDWARE CONFIGURATION **********************/
3013 /*
3014 * This part do the real job of starting and configuring the hardware.
3015 */
3016
3017 /*------------------------------------------------------------------*/
3018 /*
3019 * Routine to initialize the Modem Management Controller.
3020 * (called by wv_hw_config())
3021 */
3022 static inline int
3023 wv_mmc_init(device * dev)
3024 {
3025 ioaddr_t base = dev->base_addr;
3026 psa_t psa;
3027 mmw_t m;
3028 int configured;
3029 int i; /* Loop counter */
3030
3031 #ifdef DEBUG_CONFIG_TRACE
3032 printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
3033 #endif
3034
3035 /* Read the parameter storage area */
3036 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3037
3038 /*
3039 * Check the first three octets of the MAC addr for the manufacturer's code.
3040 * Note: If you get the error message below, you've got a
3041 * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
3042 * how to configure your card...
3043 */
3044 for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3045 if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
3046 (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
3047 (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
3048 break;
3049
3050 /* If we have not found it... */
3051 if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
3052 {
3053 #ifdef DEBUG_CONFIG_ERRORS
3054 printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
3055 dev->name, psa.psa_univ_mac_addr[0],
3056 psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
3057 #endif
3058 return FALSE;
3059 }
3060
3061 /* Get the MAC address */
3062 memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
3063
3064 #ifdef USE_PSA_CONFIG
3065 configured = psa.psa_conf_status & 1;
3066 #else
3067 configured = 0;
3068 #endif
3069
3070 /* Is the PSA is not configured */
3071 if(!configured)
3072 {
3073 /* User will be able to configure NWID after (with iwconfig) */
3074 psa.psa_nwid[0] = 0;
3075 psa.psa_nwid[1] = 0;
3076
3077 /* As NWID is not set : no NWID checking */
3078 psa.psa_nwid_select = 0;
3079
3080 /* Disable encryption */
3081 psa.psa_encryption_select = 0;
3082
3083 /* Set to standard values
3084 * 0x04 for AT,
3085 * 0x01 for MCA,
3086 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
3087 */
3088 if (psa.psa_comp_number & 1)
3089 psa.psa_thr_pre_set = 0x01;
3090 else
3091 psa.psa_thr_pre_set = 0x04;
3092 psa.psa_quality_thr = 0x03;
3093
3094 /* It is configured */
3095 psa.psa_conf_status |= 1;
3096
3097 #ifdef USE_PSA_CONFIG
3098 /* Write the psa */
3099 psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
3100 (unsigned char *)psa.psa_nwid, 4);
3101 psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
3102 (unsigned char *)&psa.psa_thr_pre_set, 1);
3103 psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
3104 (unsigned char *)&psa.psa_quality_thr, 1);
3105 psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
3106 (unsigned char *)&psa.psa_conf_status, 1);
3107 /* update the Wavelan checksum */
3108 update_psa_checksum(dev);
3109 #endif /* USE_PSA_CONFIG */
3110 }
3111
3112 /* Zero the mmc structure */
3113 memset(&m, 0x00, sizeof(m));
3114
3115 /* Copy PSA info to the mmc */
3116 m.mmw_netw_id_l = psa.psa_nwid[1];
3117 m.mmw_netw_id_h = psa.psa_nwid[0];
3118
3119 if(psa.psa_nwid_select & 1)
3120 m.mmw_loopt_sel = 0x00;
3121 else
3122 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
3123
3124 memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
3125 sizeof(m.mmw_encr_key));
3126
3127 if(psa.psa_encryption_select)
3128 m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
3129 else
3130 m.mmw_encr_enable = 0;
3131
3132 m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
3133 m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
3134
3135 /*
3136 * Set default modem control parameters.
3137 * See NCR document 407-0024326 Rev. A.
3138 */
3139 m.mmw_jabber_enable = 0x01;
3140 m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
3141 m.mmw_ifs = 0x20;
3142 m.mmw_mod_delay = 0x04;
3143 m.mmw_jam_time = 0x38;
3144
3145 m.mmw_des_io_invert = 0;
3146 m.mmw_freeze = 0;
3147 m.mmw_decay_prm = 0;
3148 m.mmw_decay_updat_prm = 0;
3149
3150 /* Write all info to mmc */
3151 mmc_write(base, 0, (u_char *)&m, sizeof(m));
3152
3153 /* The following code start the modem of the 2.00 frequency
3154 * selectable cards at power on. It's not strictly needed for the
3155 * following boots...
3156 * The original patch was by Joe Finney for the PCMCIA driver, but
3157 * I've cleaned it a bit and add documentation.
3158 * Thanks to Loeke Brederveld from Lucent for the info.
3159 */
3160
3161 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3162 * (does it work for everybody XXX - especially old cards...) */
3163 /* Note : WFREQSEL verify that it is able to read from EEprom
3164 * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
3165 * is 0xA (Xilinx version) or 0xB (Ariadne version).
3166 * My test is more crude but do work... */
3167 if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
3168 (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
3169 {
3170 /* We must download the frequency parameters to the
3171 * synthetisers (from the EEprom - area 1)
3172 * Note : as the EEprom is auto decremented, we set the end
3173 * if the area... */
3174 m.mmw_fee_addr = 0x0F;
3175 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3176 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3177 (unsigned char *)&m.mmw_fee_ctrl, 2);
3178
3179 /* Wait until the download is finished */
3180 fee_wait(base, 100, 100);
3181
3182 #ifdef DEBUG_CONFIG_INFO
3183 /* The frequency was in the last word downloaded... */
3184 mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
3185 (unsigned char *)&m.mmw_fee_data_l, 2);
3186
3187 /* Print some info for the user */
3188 printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
3189 dev->name,
3190 ((m.mmw_fee_data_h << 4) |
3191 (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
3192 #endif
3193
3194 /* We must now download the power adjust value (gain) to
3195 * the synthetisers (from the EEprom - area 7 - DAC) */
3196 m.mmw_fee_addr = 0x61;
3197 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3198 mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
3199 (unsigned char *)&m.mmw_fee_ctrl, 2);
3200
3201 /* Wait until the download is finished */
3202 } /* if 2.00 card */
3203
3204 #ifdef DEBUG_CONFIG_TRACE
3205 printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3206 #endif
3207 return TRUE;
3208 }
3209
3210 /*------------------------------------------------------------------*/
3211 /*
3212 * Routine to gracefully turn off reception, and wait for any commands
3213 * to complete.
3214 * (called in wv_ru_start() and wavelan_close() and wavelan_event())
3215 */
3216 static int
3217 wv_ru_stop(device * dev)
3218 {
3219 ioaddr_t base = dev->base_addr;
3220 net_local *lp = (net_local *) dev->priv;
3221 unsigned long flags;
3222 int status;
3223 int spin;
3224
3225 #ifdef DEBUG_CONFIG_TRACE
3226 printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
3227 #endif
3228
3229 /* First, send the LAN controller a stop receive command */
3230 wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
3231 OP0_STOP_RCV, SR0_NO_RESULT);
3232
3233 /* Then, spin until the receive unit goes idle */
3234 spin = 0;
3235 do
3236 {
3237 udelay(10);
3238 spin_lock_irqsave (&lp->lock, flags);
3239 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3240 status = inb(LCSR(base));
3241 spin_unlock_irqrestore (&lp->lock, flags);
3242 }
3243 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin++ < 300));
3244
3245 /* Now, spin until the chip finishes executing its current command */
3246 do
3247 {
3248 udelay(10);
3249 spin_lock_irqsave (&lp->lock, flags);
3250 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3251 status = inb(LCSR(base));
3252 spin_unlock_irqrestore (&lp->lock, flags);
3253 }
3254 while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin++ < 300));
3255
3256 /* If there was a problem */
3257 if(spin > 300)
3258 {
3259 #ifdef DEBUG_CONFIG_ERROR
3260 printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
3261 dev->name);
3262 #endif
3263 return FALSE;
3264 }
3265
3266 #ifdef DEBUG_CONFIG_TRACE
3267 printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
3268 #endif
3269 return TRUE;
3270 } /* wv_ru_stop */
3271
3272 /*------------------------------------------------------------------*/
3273 /*
3274 * This routine starts the receive unit running. First, it checks if
3275 * the card is actually ready. Then the card is instructed to receive
3276 * packets again.
3277 * (called in wv_hw_reset() & wavelan_open())
3278 */
3279 static int
3280 wv_ru_start(device * dev)
3281 {
3282 ioaddr_t base = dev->base_addr;
3283 net_local * lp = (net_local *) dev->priv;
3284
3285 #ifdef DEBUG_CONFIG_TRACE
3286 printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3287 #endif
3288
3289 /*
3290 * We need to start from a quiescent state. To do so, we could check
3291 * if the card is already running, but instead we just try to shut
3292 * it down. First, we disable reception (in case it was already enabled).
3293 */
3294 if(!wv_ru_stop(dev))
3295 return FALSE;
3296
3297 /* Now we know that no command is being executed. */
3298
3299 /* Set the receive frame pointer and stop pointer */
3300 lp->rfp = 0;
3301 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
3302
3303 /* Reset ring management. This sets the receive frame pointer to 1 */
3304 outb(OP1_RESET_RING_MNGMT, LCCR(base));
3305
3306 /* but I set it to 3 bytes per packet less than 8K */
3307 lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
3308 outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
3309 outb(OP1_INT_ENABLE, LCCR(base));
3310 outb(OP1_SWIT_TO_PORT_0, LCCR(base));
3311
3312 /* Reset receive DMA pointer */
3313 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3314 hacr_write_slow(base, HACR_DEFAULT);
3315
3316 /* Receive DMA on channel 1 */
3317 wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
3318 CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
3319
3320 #ifdef DEBUG_I82593_SHOW
3321 {
3322 int status;
3323 unsigned long flags;
3324 int i = 0;
3325
3326 /* spin until the chip starts receiving */
3327 do
3328 {
3329 spin_lock_irqsave (&lp->lock, flags);
3330 outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
3331 status = inb(LCSR(base));
3332 spin_unlock_irqrestore (&lp->lock, flags);
3333 if(i++ > 10000)
3334 break;
3335 }
3336 while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
3337 ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
3338 printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
3339 (status & SR3_RCV_STATE_MASK), i);
3340 }
3341 #endif
3342 #ifdef DEBUG_CONFIG_TRACE
3343 printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3344 #endif
3345 return TRUE;
3346 }
3347
3348 /*------------------------------------------------------------------*/
3349 /*
3350 * This routine does a standard config of the WaveLAN controller (i82593).
3351 * In the ISA driver, this is integrated in wavelan_hardware_reset()
3352 * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
3353 */
3354 static int
3355 wv_82593_config(device * dev)
3356 {
3357 ioaddr_t base = dev->base_addr;
3358 net_local * lp = (net_local *) dev->priv;
3359 struct i82593_conf_block cfblk;
3360
3361 #ifdef DEBUG_CONFIG_TRACE
3362 printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
3363 #endif
3364
3365 /* Create & fill i82593 config block
3366 *
3367 * Now conform to Wavelan document WCIN085B
3368 */
3369 memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
3370 cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
3371 cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
3372 cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
3373 cfblk.fifo_32 = 1;
3374 cfblk.throttle_enb = FALSE;
3375 cfblk.contin = TRUE; /* enable continuous mode */
3376 cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
3377 cfblk.addr_len = WAVELAN_ADDR_SIZE;
3378 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
3379 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
3380 cfblk.loopback = FALSE;
3381 cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */
3382 cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */
3383 cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */
3384 cfblk.ifrm_spc = 0x20; /* 32 bit times interframe spacing */
3385 cfblk.slottim_low = 0x20; /* 32 bit times slot time */
3386 cfblk.slottim_hi = 0x0;
3387 cfblk.max_retr = 15;
3388 cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
3389 cfblk.bc_dis = FALSE; /* Enable broadcast reception */
3390 cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
3391 cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
3392 cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
3393 cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
3394 cfblk.cs_filter = 0; /* CS is recognized immediately */
3395 cfblk.crs_src = FALSE; /* External carrier sense */
3396 cfblk.cd_filter = 0; /* CD is recognized immediately */
3397 cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
3398 cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
3399 cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
3400 cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
3401 cfblk.artx = TRUE; /* Disable automatic retransmission */
3402 cfblk.sarec = TRUE; /* Disable source addr trig of CD */
3403 cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
3404 cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
3405 cfblk.lbpkpol = TRUE; /* Loopback pin active high */
3406 cfblk.fdx = FALSE; /* Disable full duplex operation */
3407 cfblk.dummy_6 = 0x3f; /* all ones */
3408 cfblk.mult_ia = FALSE; /* No multiple individual addresses */
3409 cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
3410 cfblk.dummy_1 = TRUE; /* set to 1 */
3411 cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
3412 #ifdef MULTICAST_ALL
3413 cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
3414 #else
3415 cfblk.mc_all = FALSE; /* No multicast all mode */
3416 #endif
3417 cfblk.rcv_mon = 0; /* Monitor mode disabled */
3418 cfblk.frag_acpt = TRUE; /* Do not accept fragments */
3419 cfblk.tstrttrs = FALSE; /* No start transmission threshold */
3420 cfblk.fretx = TRUE; /* FIFO automatic retransmission */
3421 cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
3422 cfblk.sttlen = TRUE; /* 6 byte status registers */
3423 cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
3424 cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
3425 cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
3426 cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
3427
3428 #ifdef DEBUG_I82593_SHOW
3429 {
3430 u_char *c = (u_char *) &cfblk;
3431 int i;
3432 printk(KERN_DEBUG "wavelan_cs: config block:");
3433 for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
3434 {
3435 if((i % 16) == 0) printk("\n" KERN_DEBUG);
3436 printk("%02x ", *c);
3437 }
3438 printk("\n");
3439 }
3440 #endif
3441
3442 /* Copy the config block to the i82593 */
3443 outb(TX_BASE & 0xff, PIORL(base));
3444 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3445 outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
3446 outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
3447 outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
3448
3449 /* reset transmit DMA pointer */
3450 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3451 hacr_write(base, HACR_DEFAULT);
3452 if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
3453 OP0_CONFIGURE, SR0_CONFIGURE_DONE))
3454 return(FALSE);
3455
3456 /* Initialize adapter's ethernet MAC address */
3457 outb(TX_BASE & 0xff, PIORL(base));
3458 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3459 outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
3460 outb(0, PIOP(base)); /* byte count msb */
3461 outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
3462
3463 /* reset transmit DMA pointer */
3464 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3465 hacr_write(base, HACR_DEFAULT);
3466 if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
3467 OP0_IA_SETUP, SR0_IA_SETUP_DONE))
3468 return(FALSE);
3469
3470 #ifdef WAVELAN_ROAMING
3471 /* If roaming is enabled, join the "Beacon Request" multicast group... */
3472 /* But only if it's not in there already! */
3473 if(do_roaming)
3474 dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
3475 #endif /* WAVELAN_ROAMING */
3476
3477 /* If any multicast address to set */
3478 if(lp->mc_count)
3479 {
3480 struct dev_mc_list * dmi;
3481 int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
3482
3483 #ifdef DEBUG_CONFIG_INFO
3484 printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
3485 dev->name, lp->mc_count);
3486 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3487 printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n",
3488 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
3489 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
3490 #endif
3491
3492 /* Initialize adapter's ethernet multicast addresses */
3493 outb(TX_BASE & 0xff, PIORL(base));
3494 outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
3495 outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
3496 outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
3497 for(dmi=dev->mc_list; dmi; dmi=dmi->next)
3498 outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
3499
3500 /* reset transmit DMA pointer */
3501 hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
3502 hacr_write(base, HACR_DEFAULT);
3503 if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
3504 OP0_MC_SETUP, SR0_MC_SETUP_DONE))
3505 return(FALSE);
3506 lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
3507 }
3508
3509 #ifdef DEBUG_CONFIG_TRACE
3510 printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
3511 #endif
3512 return(TRUE);
3513 }
3514
3515 /*------------------------------------------------------------------*/
3516 /*
3517 * Read the Access Configuration Register, perform a software reset,
3518 * and then re-enable the card's software.
3519 *
3520 * If I understand correctly : reset the pcmcia interface of the
3521 * wavelan.
3522 * (called by wv_config())
3523 */
3524 static inline int
3525 wv_pcmcia_reset(device * dev)
3526 {
3527 int i;
3528 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
3529 dev_link_t * link = ((net_local *) dev->priv)->link;
3530
3531 #ifdef DEBUG_CONFIG_TRACE
3532 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
3533 #endif
3534
3535 i = CardServices(AccessConfigurationRegister, link->handle, ®);
3536 if(i != CS_SUCCESS)
3537 {
3538 cs_error(link->handle, AccessConfigurationRegister, i);
3539 return FALSE;
3540 }
3541
3542 #ifdef DEBUG_CONFIG_INFO
3543 printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
3544 dev->name, (u_int) reg.Value);
3545 #endif
3546
3547 reg.Action = CS_WRITE;
3548 reg.Value = reg.Value | COR_SW_RESET;
3549 i = CardServices(AccessConfigurationRegister, link->handle, ®);
3550 if(i != CS_SUCCESS)
3551 {
3552 cs_error(link->handle, AccessConfigurationRegister, i);
3553 return FALSE;
3554 }
3555
3556 reg.Action = CS_WRITE;
3557 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3558 i = CardServices(AccessConfigurationRegister, link->handle, ®);
3559 if(i != CS_SUCCESS)
3560 {
3561 cs_error(link->handle, AccessConfigurationRegister, i);
3562 return FALSE;
3563 }
3564
3565 #ifdef DEBUG_CONFIG_TRACE
3566 printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
3567 #endif
3568 return TRUE;
3569 }
3570
3571 /*------------------------------------------------------------------*/
3572 /*
3573 * wavelan_hw_config() is called after a CARD_INSERTION event is
3574 * received, to configure the wavelan hardware.
3575 * Note that the reception will be enabled in wavelan->open(), so the
3576 * device is configured but idle...
3577 * Performs the following actions:
3578 * 1. A pcmcia software reset (using wv_pcmcia_reset())
3579 * 2. A power reset (reset DMA)
3580 * 3. Reset the LAN controller
3581 * 4. Initialize the radio modem (using wv_mmc_init)
3582 * 5. Configure LAN controller (using wv_82593_config)
3583 * 6. Perform a diagnostic on the LAN controller
3584 * (called by wavelan_event() & wv_hw_reset())
3585 */
3586 static int
3587 wv_hw_config(device * dev)
3588 {
3589 net_local * lp = (net_local *) dev->priv;
3590 ioaddr_t base = dev->base_addr;
3591
3592 #ifdef DEBUG_CONFIG_TRACE
3593 printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
3594 #endif
3595
3596 #ifdef STRUCT_CHECK
3597 if(wv_structuct_check() != (char *) NULL)
3598 {
3599 printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: \"%s\"\n",
3600 dev->name, wv_structuct_check());
3601 return FALSE;
3602 }
3603 #endif /* STRUCT_CHECK == 1 */
3604
3605 /* Reset the pcmcia interface */
3606 if(wv_pcmcia_reset(dev) == FALSE)
3607 return FALSE;
3608
3609 /* Power UP the module + reset the modem + reset host adapter
3610 * (in fact, reset DMA channels) */
3611 hacr_write_slow(base, HACR_RESET);
3612 hacr_write(base, HACR_DEFAULT);
3613
3614 /* Check if the module has been powered up... */
3615 if(hasr_read(base) & HASR_NO_CLK)
3616 {
3617 #ifdef DEBUG_CONFIG_ERRORS
3618 printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
3619 dev->name);
3620 #endif
3621 return FALSE;
3622 }
3623
3624 /* initialize the modem */
3625 if(wv_mmc_init(dev) == FALSE)
3626 return FALSE;
3627
3628 /* reset the LAN controller (i82593) */
3629 outb(OP0_RESET, LCCR(base));
3630 mdelay(1); /* A bit crude ! */
3631
3632 /* Initialize the LAN controller */
3633 if((wv_82593_config(dev) == FALSE) ||
3634 (wv_diag(dev) == FALSE))
3635 {
3636 #ifdef DEBUG_CONFIG_ERRORS
3637 printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n", dev->name);
3638 #endif
3639 return FALSE;
3640 }
3641
3642 /*
3643 * insert code for loopback test here
3644 */
3645
3646 /* The device is now configured */
3647 lp->configured = 1;
3648
3649 #ifdef DEBUG_CONFIG_TRACE
3650 printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
3651 #endif
3652 return TRUE;
3653 }
3654
3655 /*------------------------------------------------------------------*/
3656 /*
3657 * Totally reset the wavelan and restart it.
3658 * Performs the following actions:
3659 * 1. Call wv_hw_config()
3660 * 2. Start the LAN controller's receive unit
3661 * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
3662 */
3663 static inline void
3664 wv_hw_reset(device * dev)
3665 {
3666 net_local * lp = (net_local *) dev->priv;
3667
3668 #ifdef DEBUG_CONFIG_TRACE
3669 printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
3670 #endif
3671
3672 /* If watchdog was activated, kill it ! */
3673 if (timer_pending(&lp->watchdog))
3674 del_timer(&lp->watchdog);
3675
3676 lp->nresets++;
3677 lp->configured = 0;
3678
3679 /* Call wv_hw_config() for most of the reset & init stuff */
3680 if(wv_hw_config(dev) == FALSE)
3681 return;
3682
3683 /* start receive unit */
3684 wv_ru_start(dev);
3685
3686 #ifdef DEBUG_CONFIG_TRACE
3687 printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3688 #endif
3689 }
3690
3691 /*------------------------------------------------------------------*/
3692 /*
3693 * wv_pcmcia_config() is called after a CARD_INSERTION event is
3694 * received, to configure the PCMCIA socket, and to make the ethernet
3695 * device available to the system.
3696 * (called by wavelan_event())
3697 */
3698 static inline int
3699 wv_pcmcia_config(dev_link_t * link)
3700 {
3701 client_handle_t handle;
3702 tuple_t tuple;
3703 cisparse_t parse;
3704 struct net_device * dev;
3705 int i;
3706 u_char buf[64];
3707 win_req_t req;
3708 memreq_t mem;
3709
3710 handle = link->handle;
3711 dev = (device *) link->priv;
3712
3713 #ifdef DEBUG_CONFIG_TRACE
3714 printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
3715 #endif
3716
3717 /*
3718 * This reads the card's CONFIG tuple to find its configuration
3719 * registers.
3720 */
3721 do
3722 {
3723 tuple.Attributes = 0;
3724 tuple.DesiredTuple = CISTPL_CONFIG;
3725 i = CardServices(GetFirstTuple, handle, &tuple);
3726 if(i != CS_SUCCESS)
3727 break;
3728 tuple.TupleData = (cisdata_t *)buf;
3729 tuple.TupleDataMax = 64;
3730 tuple.TupleOffset = 0;
3731 i = CardServices(GetTupleData, handle, &tuple);
3732 if(i != CS_SUCCESS)
3733 break;
3734 i = CardServices(ParseTuple, handle, &tuple, &parse);
3735 if(i != CS_SUCCESS)
3736 break;
3737 link->conf.ConfigBase = parse.config.base;
3738 link->conf.Present = parse.config.rmask[0];
3739 }
3740 while(0);
3741 if(i != CS_SUCCESS)
3742 {
3743 cs_error(link->handle, ParseTuple, i);
3744 link->state &= ~DEV_CONFIG_PENDING;
3745 return FALSE;
3746 }
3747
3748 /* Configure card */
3749 link->state |= DEV_CONFIG;
3750 do
3751 {
3752 i = CardServices(RequestIO, link->handle, &link->io);
3753 if(i != CS_SUCCESS)
3754 {
3755 cs_error(link->handle, RequestIO, i);
3756 break;
3757 }
3758
3759 /*
3760 * Now allocate an interrupt line. Note that this does not
3761 * actually assign a handler to the interrupt.
3762 */
3763 i = CardServices(RequestIRQ, link->handle, &link->irq);
3764 if(i != CS_SUCCESS)
3765 {
3766 cs_error(link->handle, RequestIRQ, i);
3767 break;
3768 }
3769
3770 /*
3771 * This actually configures the PCMCIA socket -- setting up
3772 * the I/O windows and the interrupt mapping.
3773 */
3774 link->conf.ConfigIndex = 1;
3775 i = CardServices(RequestConfiguration, link->handle, &link->conf);
3776 if(i != CS_SUCCESS)
3777 {
3778 cs_error(link->handle, RequestConfiguration, i);
3779 break;
3780 }
3781
3782 /*
3783 * Allocate a 4K memory window. Note that the dev_link_t
3784 * structure provides space for one window handle -- if your
3785 * device needs several windows, you'll need to keep track of
3786 * the handles in your private data structure, link->priv.
3787 */
3788 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
3789 req.Base = 0; req.Size = 0x1000;
3790 req.AccessSpeed = mem_speed;
3791 link->win = (window_handle_t)link->handle;
3792 i = CardServices(RequestWindow, &link->win, &req);
3793 if(i != CS_SUCCESS)
3794 {
3795 cs_error(link->handle, RequestWindow, i);
3796 break;
3797 }
3798
3799 dev->rmem_start = dev->mem_start =
3800 (u_long)ioremap(req.Base, 0x1000);
3801 dev->rmem_end = dev->mem_end = dev->mem_start + req.Size;
3802
3803 mem.CardOffset = 0; mem.Page = 0;
3804 i = CardServices(MapMemPage, link->win, &mem);
3805 if(i != CS_SUCCESS)
3806 {
3807 cs_error(link->handle, MapMemPage, i);
3808 break;
3809 }
3810
3811 /* Feed device with this info... */
3812 dev->irq = link->irq.AssignedIRQ;
3813 dev->base_addr = link->io.BasePort1;
3814 netif_start_queue (dev);
3815
3816 #ifdef DEBUG_CONFIG_INFO
3817 printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART 0x%x IRQ %d IOPORT 0x%x\n",
3818 (u_int) dev->mem_start, dev->irq, (u_int) dev->base_addr);
3819 #endif
3820
3821 i = register_netdev(dev);
3822 if(i != 0)
3823 {
3824 #ifdef DEBUG_CONFIG_ERRORS
3825 printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
3826 #endif
3827 break;
3828 }
3829 }
3830 while(0); /* Humm... Disguised goto !!! */
3831
3832 link->state &= ~DEV_CONFIG_PENDING;
3833 /* If any step failed, release any partially configured state */
3834 if(i != 0)
3835 {
3836 wv_pcmcia_release((u_long) link);
3837 return FALSE;
3838 }
3839
3840 /* XXX Could you explain me this, Dave ? */
3841 link->dev = &((net_local *) dev->priv)->node;
3842
3843 #ifdef DEBUG_CONFIG_TRACE
3844 printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
3845 #endif
3846 return TRUE;
3847 }
3848
3849 /*------------------------------------------------------------------*/
3850 /*
3851 * After a card is removed, wv_pcmcia_release() will unregister the net
3852 * device, and release the PCMCIA configuration. If the device is
3853 * still open, this will be postponed until it is closed.
3854 */
3855 static void
3856 wv_pcmcia_release(u_long arg) /* Address of the interface struct */
3857 {
3858 dev_link_t * link = (dev_link_t *) arg;
3859 device * dev = (device *) link->priv;
3860
3861 #ifdef DEBUG_CONFIG_TRACE
3862 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
3863 #endif
3864
3865 /* If the device is currently in use, we won't release until it is
3866 * actually closed. */
3867 if(link->open)
3868 {
3869 #ifdef DEBUG_CONFIG_INFO
3870 printk(KERN_DEBUG "%s: wv_pcmcia_release: release postponed, device still open\n",
3871 dev->name);
3872 #endif
3873 link->state |= DEV_STALE_CONFIG;
3874 return;
3875 }
3876
3877 /* Don't bother checking to see if these succeed or not */
3878 iounmap((u_char *)dev->mem_start);
3879 CardServices(ReleaseWindow, link->win);
3880 CardServices(ReleaseConfiguration, link->handle);
3881 CardServices(ReleaseIO, link->handle, &link->io);
3882 CardServices(ReleaseIRQ, link->handle, &link->irq);
3883
3884 link->state &= ~(DEV_CONFIG | DEV_RELEASE_PENDING | DEV_STALE_CONFIG);
3885
3886 #ifdef DEBUG_CONFIG_TRACE
3887 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
3888 #endif
3889 } /* wv_pcmcia_release */
3890
3891 /*------------------------------------------------------------------*/
3892 /*
3893 * Sometimes, netwave_detach can't be performed following a call from
3894 * cardmgr (device still open, pcmcia_release not done) and the device
3895 * is put in a STALE_LINK state and remains in memory.
3896 *
3897 * This function run through our current list of device and attempt
3898 * another time to remove them. We hope that since last time the
3899 * device has properly been closed.
3900 *
3901 * (called by wavelan_attach() & cleanup_module())
3902 */
3903 static void
3904 wv_flush_stale_links(void)
3905 {
3906 dev_link_t * link; /* Current node in linked list */
3907 dev_link_t * next; /* Next node in linked list */
3908
3909 #ifdef DEBUG_CONFIG_TRACE
3910 printk(KERN_DEBUG "-> wv_flush_stale_links(0x%p)\n", dev_list);
3911 #endif
3912
3913 /* Go through the list */
3914 for (link = dev_list; link; link = next)
3915 {
3916 next = link->next;
3917
3918 /* Check if in need of being removed */
3919 if((link->state & DEV_STALE_LINK) ||
3920 (! (link->state & DEV_PRESENT)))
3921 wavelan_detach(link);
3922
3923 }
3924
3925 #ifdef DEBUG_CONFIG_TRACE
3926 printk(KERN_DEBUG "<- wv_flush_stale_links()\n");
3927 #endif
3928 }
3929
3930 /************************ INTERRUPT HANDLING ************************/
3931
3932 /*
3933 * This function is the interrupt handler for the WaveLAN card. This
3934 * routine will be called whenever:
3935 * 1. A packet is received.
3936 * 2. A packet has successfully been transferred and the unit is
3937 * ready to transmit another packet.
3938 * 3. A command has completed execution.
3939 */
3940 static void
3941 wavelan_interrupt(int irq,
3942 void * dev_id,
3943 struct pt_regs * regs)
3944 {
3945 device * dev;
3946 net_local * lp;
3947 ioaddr_t base;
3948 int status0;
3949 u_int tx_status;
3950
3951 if((dev = (device *)dev_id) == (device *) NULL)
3952 {
3953 #ifdef DEBUG_INTERRUPT_ERROR
3954 printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.\n",
3955 irq);
3956 #endif
3957 return;
3958 }
3959
3960 #ifdef DEBUG_INTERRUPT_TRACE
3961 printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
3962 #endif
3963
3964 lp = (net_local *) dev->priv;
3965 base = dev->base_addr;
3966
3967 spin_lock (&lp->lock);
3968
3969 /* Treat all pending interrupts */
3970 while(1)
3971 {
3972 /* ---------------- INTERRUPT CHECKING ---------------- */
3973 /*
3974 * Look for the interrupt and verify the validity
3975 */
3976 outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
3977 status0 = inb(LCSR(base));
3978
3979 #ifdef DEBUG_INTERRUPT_INFO
3980 printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
3981 (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
3982 if(status0&SR0_INTERRUPT)
3983 {
3984 printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
3985 ((status0 & SR0_EXECUTION) ? "cmd" :
3986 ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
3987 (status0 & SR0_EVENT_MASK));
3988 }
3989 else
3990 printk("\n");
3991 #endif
3992
3993 /* Return if no actual interrupt from i82593 (normal exit) */
3994 if(!(status0 & SR0_INTERRUPT))
3995 break;
3996
3997 /* If interrupt is both Rx and Tx or none...
3998 * This code in fact is there to catch the spurious interrupt
3999 * when you remove the wavelan pcmcia card from the socket */
4000 if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
4001 ((status0 & SR0_BOTH_RX_TX) == 0x0))
4002 {
4003 #ifdef DEBUG_INTERRUPT_INFO
4004 printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
4005 dev->name, status0);
4006 #endif
4007 /* Acknowledge the interrupt */
4008 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4009 break;
4010 }
4011
4012 lp->status = status0; /* Save current status (for commands) */
4013
4014 /* ----------------- RECEIVING PACKET ----------------- */
4015 /*
4016 * When the wavelan signal the reception of a new packet,
4017 * we call wv_packet_rcv() to copy if from the buffer and
4018 * send it to NET3
4019 */
4020 if(status0 & SR0_RECEPTION)
4021 {
4022 #ifdef DEBUG_INTERRUPT_INFO
4023 printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
4024 #endif
4025
4026 if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
4027 {
4028 #ifdef DEBUG_INTERRUPT_ERROR
4029 printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
4030 dev->name);
4031 #endif
4032 lp->stats.rx_over_errors++;
4033 lp->overrunning = 1;
4034 }
4035
4036 /* Get the packet */
4037 wv_packet_rcv(dev);
4038 lp->overrunning = 0;
4039
4040 /* Acknowledge the interrupt */
4041 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4042 continue;
4043 }
4044
4045 /* ---------------- COMMAND COMPLETION ---------------- */
4046 /*
4047 * Interrupts issued when the i82593 has completed a command.
4048 * Most likely : transmission done
4049 */
4050
4051 /* If we are already waiting elsewhere for the command to complete */
4052 if(wv_wait_completed)
4053 {
4054 #ifdef DEBUG_INTERRUPT_INFO
4055 printk(KERN_DEBUG "%s: wv_interrupt(): command completed\n",
4056 dev->name);
4057 #endif
4058
4059 /* Signal command completion */
4060 wv_wait_completed = 0;
4061
4062 /* Acknowledge the interrupt */
4063 outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
4064 continue;
4065 }
4066
4067 /* If a transmission has been done */
4068 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
4069 (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
4070 (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4071 {
4072 #ifdef DEBUG_TX_ERROR
4073 if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
4074 printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
4075 dev->name);
4076 #endif
4077
4078 /* If watchdog was activated, kill it ! */
4079 if(timer_pending(&lp->watchdog))
4080 del_timer(&lp->watchdog);
4081
4082 /* Get transmission status */
4083 tx_status = inb(LCSR(base));
4084 tx_status |= (inb(LCSR(base)) << 8);
4085 #ifdef DEBUG_INTERRUPT_INFO
4086 printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
4087 dev->name);
4088 {
4089 u_int rcv_bytes;
4090 u_char status3;
4091 rcv_bytes = inb(LCSR(base));
4092 rcv_bytes |= (inb(LCSR(base)) << 8);
4093 status3 = inb(LCSR(base));
4094 printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
4095 tx_status, rcv_bytes, (u_int) status3);
4096 }
4097 #endif
4098 /* Check for possible errors */
4099 if((tx_status & TX_OK) != TX_OK)
4100 {
4101 lp->stats.tx_errors++;
4102
4103 if(tx_status & TX_FRTL)
4104 {
4105 #ifdef DEBUG_TX_ERROR
4106 printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
4107 dev->name);
4108 #endif
4109 }
4110 if(tx_status & TX_UND_RUN)
4111 {
4112 #ifdef DEBUG_TX_FAIL
4113 printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
4114 dev->name);
4115 #endif
4116 lp->stats.tx_aborted_errors++;
4117 }
4118 if(tx_status & TX_LOST_CTS)
4119 {
4120 #ifdef DEBUG_TX_FAIL
4121 printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
4122 #endif
4123 lp->stats.tx_carrier_errors++;
4124 }
4125 if(tx_status & TX_LOST_CRS)
4126 {
4127 #ifdef DEBUG_TX_FAIL
4128 printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
4129 dev->name);
4130 #endif
4131 lp->stats.tx_carrier_errors++;
4132 }
4133 if(tx_status & TX_HRT_BEAT)
4134 {
4135 #ifdef DEBUG_TX_FAIL
4136 printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
4137 #endif
4138 lp->stats.tx_heartbeat_errors++;
4139 }
4140 if(tx_status & TX_DEFER)
4141 {
4142 #ifdef DEBUG_TX_FAIL
4143 printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
4144 dev->name);
4145 #endif
4146 }
4147 /* Ignore late collisions since they're more likely to happen
4148 * here (the WaveLAN design prevents the LAN controller from
4149 * receiving while it is transmitting). We take action only when
4150 * the maximum retransmit attempts is exceeded.
4151 */
4152 if(tx_status & TX_COLL)
4153 {
4154 if(tx_status & TX_MAX_COL)
4155 {
4156 #ifdef DEBUG_TX_FAIL
4157 printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
4158 dev->name);
4159 #endif
4160 if(!(tx_status & TX_NCOL_MASK))
4161 {
4162 lp->stats.collisions += 0x10;
4163 }
4164 }
4165 }
4166 } /* if(!(tx_status & TX_OK)) */
4167
4168 lp->stats.collisions += (tx_status & TX_NCOL_MASK);
4169 lp->stats.tx_packets++;
4170
4171 netif_wake_queue (dev);
4172 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4173 }
4174 else /* if interrupt = transmit done or retransmit done */
4175 {
4176 #ifdef DEBUG_INTERRUPT_ERROR
4177 printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
4178 status0);
4179 #endif
4180 outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
4181 }
4182 }
4183
4184 spin_unlock_irq (&lp->lock);
4185
4186 #ifdef DEBUG_INTERRUPT_TRACE
4187 printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
4188 #endif
4189 } /* wv_interrupt */
4190
4191 /*------------------------------------------------------------------*/
4192 /*
4193 * Watchdog : when we start a transmission, we set a timer in the
4194 * kernel. If the transmission complete, this timer is disabled. If
4195 * it expire, it try to unlock the hardware.
4196 *
4197 * Note : this watchdog doesn't work on the same principle as the
4198 * watchdog in the ISA driver. I make it this way because the overhead
4199 * of add_timer() and del_timer() is nothing and that it avoid calling
4200 * the watchdog, saving some CPU... If you want to apply the same
4201 * watchdog to the ISA driver, you should be a bit carefull, because
4202 * of the many transmit buffers...
4203 * This watchdog is also move clever, it try to abort the current
4204 * command before reseting everything...
4205 */
4206 static void
4207 wavelan_watchdog(u_long a)
4208 {
4209 device * dev;
4210 net_local * lp;
4211 ioaddr_t base;
4212 int spin;
4213
4214 dev = (device *) a;
4215 base = dev->base_addr;
4216 lp = (net_local *) dev->priv;
4217
4218 #ifdef DEBUG_INTERRUPT_TRACE
4219 printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
4220 #endif
4221
4222 #ifdef DEBUG_INTERRUPT_ERROR
4223 printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
4224 dev->name);
4225 #endif
4226
4227 /* We are waiting for command completion */
4228 wv_wait_completed = TRUE;
4229
4230 /* Ask to abort the current command */
4231 outb(OP0_ABORT, LCCR(base));
4232
4233 /* Busy wait while the LAN controller executes the command.
4234 * Note : wv_wait_completed should be volatile */
4235 spin = 0;
4236 while(wv_wait_completed && (spin++ < 250))
4237 udelay(10);
4238
4239 /* If the interrupt handler hasn't be called or invalid status */
4240 if((wv_wait_completed) ||
4241 ((lp->status & SR0_EVENT_MASK) != SR0_EXECUTION_ABORTED))
4242 {
4243 /* It seem that it wasn't enough */
4244 #ifdef DEBUG_INTERRUPT_ERROR
4245 printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
4246 dev->name);
4247 #endif
4248 wv_hw_reset(dev);
4249 }
4250
4251 #ifdef DEBUG_PSA_SHOW
4252 {
4253 psa_t psa;
4254 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
4255 wv_psa_show(&psa);
4256 }
4257 #endif
4258 #ifdef DEBUG_MMC_SHOW
4259 wv_mmc_show(dev);
4260 #endif
4261 #ifdef DEBUG_I82593_SHOW
4262 wv_ru_show(dev);
4263 #endif
4264
4265 /* We are no more waiting for something... */
4266 netif_start_queue (dev);
4267
4268 #ifdef DEBUG_INTERRUPT_TRACE
4269 printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
4270 #endif
4271 }
4272
4273 /********************* CONFIGURATION CALLBACKS *********************/
4274 /*
4275 * Here are the functions called by the pcmcia package (cardmgr) and
4276 * linux networking (NET3) for initialization, configuration and
4277 * deinstallations of the Wavelan Pcmcia Hardware.
4278 */
4279
4280 /*------------------------------------------------------------------*/
4281 /*
4282 * Configure and start up the WaveLAN PCMCIA adaptor.
4283 * Called by NET3 when it "open" the device.
4284 */
4285 static int
4286 wavelan_open(device * dev)
4287 {
4288 dev_link_t * link = ((net_local *) dev->priv)->link;
4289 net_local * lp = (net_local *)dev->priv;
4290 ioaddr_t base = dev->base_addr;
4291
4292 #ifdef DEBUG_CALLBACK_TRACE
4293 printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
4294 (unsigned int) dev);
4295 #endif
4296
4297 /* Check if the modem is powered up (wavelan_close() power it down */
4298 if(hasr_read(base) & HASR_NO_CLK)
4299 {
4300 /* Power up (power up time is 250us) */
4301 hacr_write(base, HACR_DEFAULT);
4302
4303 /* Check if the module has been powered up... */
4304 if(hasr_read(base) & HASR_NO_CLK)
4305 {
4306 #ifdef DEBUG_CONFIG_ERRORS
4307 printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
4308 dev->name);
4309 #endif
4310 return FALSE;
4311 }
4312 }
4313
4314 /* Start reception and declare the driver ready */
4315 if(!lp->configured)
4316 return FALSE;
4317 if(!wv_ru_start(dev))
4318 wv_hw_reset(dev); /* If problem : reset */
4319 netif_start_queue (dev);
4320
4321 /* Mark the device as used */
4322 link->open++;
4323 MOD_INC_USE_COUNT;
4324
4325 #ifdef WAVELAN_ROAMING
4326 if(do_roaming)
4327 wv_roam_init(dev);
4328 #endif /* WAVELAN_ROAMING */
4329
4330 #ifdef DEBUG_CALLBACK_TRACE
4331 printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
4332 #endif
4333 return 0;
4334 }
4335
4336 /*------------------------------------------------------------------*/
4337 /*
4338 * Shutdown the WaveLAN PCMCIA adaptor.
4339 * Called by NET3 when it "close" the device.
4340 */
4341 static int
4342 wavelan_close(device * dev)
4343 {
4344 dev_link_t * link = ((net_local *) dev->priv)->link;
4345 net_local * lp = (net_local *)dev->priv;
4346 ioaddr_t base = dev->base_addr;
4347
4348 #ifdef DEBUG_CALLBACK_TRACE
4349 printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
4350 (unsigned int) dev);
4351 #endif
4352
4353 netif_stop_queue (dev);
4354
4355 /* If the device isn't open, then nothing to do */
4356 if(!link->open)
4357 {
4358 #ifdef DEBUG_CONFIG_INFO
4359 printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
4360 #endif
4361 return 0;
4362 }
4363
4364 #ifdef WAVELAN_ROAMING
4365 /* Cleanup of roaming stuff... */
4366 if(do_roaming)
4367 wv_roam_cleanup(dev);
4368 #endif /* WAVELAN_ROAMING */
4369
4370 /* If watchdog was activated, kill it ! */
4371 if(timer_pending(&lp->watchdog))
4372 del_timer(&lp->watchdog);
4373
4374 link->open--;
4375 MOD_DEC_USE_COUNT;
4376
4377 /* If the card is still present */
4378 if (netif_device_present(dev))
4379 {
4380 netif_stop_queue (dev);
4381
4382 /* Stop receiving new messages and wait end of transmission */
4383 wv_ru_stop(dev);
4384
4385 /* Power down the module */
4386 hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
4387 }
4388 else
4389 /* The card is no more there (flag is activated in wv_pcmcia_release) */
4390 if(link->state & DEV_STALE_CONFIG)
4391 wv_pcmcia_release((u_long)link);
4392
4393 #ifdef DEBUG_CALLBACK_TRACE
4394 printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
4395 #endif
4396 return 0;
4397 }
4398
4399 /*------------------------------------------------------------------*/
4400 /*
4401 * We never need to do anything when a wavelan device is "initialized"
4402 * by the net software, because we only register already-found cards.
4403 */
4404 static int
4405 wavelan_init(device * dev)
4406 {
4407 #ifdef DEBUG_CALLBACK_TRACE
4408 printk(KERN_DEBUG "<>wavelan_init()\n");
4409 #endif
4410
4411 return(0);
4412 }
4413
4414 /*------------------------------------------------------------------*/
4415 /*
4416 * wavelan_attach() creates an "instance" of the driver, allocating
4417 * local data structures for one device (one interface). The device
4418 * is registered with Card Services.
4419 *
4420 * The dev_link structure is initialized, but we don't actually
4421 * configure the card at this point -- we wait until we receive a
4422 * card insertion event.
4423 */
4424 static dev_link_t *
4425 wavelan_attach(void)
4426 {
4427 client_reg_t client_reg; /* Register with cardmgr */
4428 dev_link_t * link; /* Info for cardmgr */
4429 device * dev; /* Interface generic data */
4430 net_local * lp; /* Interface specific data */
4431 int i, ret;
4432
4433 #ifdef DEBUG_CALLBACK_TRACE
4434 printk(KERN_DEBUG "-> wavelan_attach()\n");
4435 #endif
4436
4437 /* Perform some cleanup */
4438 wv_flush_stale_links();
4439
4440 /* Initialize the dev_link_t structure */
4441 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
4442 if (!link)
4443 return NULL;
4444
4445 /* Allocate the generic data structure */
4446 dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
4447 if (!dev)
4448 goto fail_alloc_dev;
4449
4450 /* Allocate the wavelan-specific data structure. */
4451 lp = (net_local *) kmalloc(sizeof(net_local), GFP_KERNEL);
4452 if (!lp)
4453 goto fail_alloc_dev_priv;
4454
4455 memset(lp, 0, sizeof(net_local));
4456 memset(link, 0, sizeof(struct dev_link_t));
4457 memset(dev, 0, sizeof(struct net_device));
4458
4459 dev->priv = lp;
4460
4461 /* Unused for the Wavelan */
4462 link->release.function = &wv_pcmcia_release;
4463 link->release.data = (u_long) link;
4464
4465 /* The io structure describes IO port mapping */
4466 link->io.NumPorts1 = 8;
4467 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
4468 link->io.IOAddrLines = 3;
4469
4470 /* Interrupt setup */
4471 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
4472 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
4473 if (irq_list[0] == -1)
4474 link->irq.IRQInfo2 = irq_mask;
4475 else
4476 for (i = 0; i < 4; i++)
4477 link->irq.IRQInfo2 |= 1 << irq_list[i];
4478 link->irq.Handler = wavelan_interrupt;
4479
4480 /* General socket configuration */
4481 link->conf.Attributes = CONF_ENABLE_IRQ;
4482 link->conf.Vcc = 50;
4483 link->conf.IntType = INT_MEMORY_AND_IO;
4484
4485 /* Chain drivers */
4486 link->next = dev_list;
4487 dev_list = link;
4488
4489 link->priv = link->irq.Instance = dev;
4490
4491 /* Init specific data */
4492 wv_wait_completed = 0;
4493 lp->status = FALSE;
4494 lp->configured = 0;
4495 lp->reconfig_82593 = FALSE;
4496 lp->nresets = 0;
4497
4498 /* Set the watchdog timer */
4499 lp->watchdog.function = wavelan_watchdog;
4500 lp->watchdog.data = (unsigned long) dev;
4501
4502 /* back links */
4503 lp->link = link;
4504 lp->dev = dev;
4505
4506 /* Standard setup for generic data */
4507 ether_setup(dev);
4508
4509 /* wavelan NET3 callbacks */
4510 dev->init = &wavelan_init;
4511 dev->open = &wavelan_open;
4512 dev->stop = &wavelan_close;
4513 dev->hard_start_xmit = &wavelan_packet_xmit;
4514 dev->get_stats = &wavelan_get_stats;
4515 dev->set_multicast_list = &wavelan_set_multicast_list;
4516 #ifdef SET_MAC_ADDRESS
4517 dev->set_mac_address = &wavelan_set_mac_address;
4518 #endif /* SET_MAC_ADDRESS */
4519
4520 #ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
4521 dev->do_ioctl = wavelan_ioctl; /* wireless extensions */
4522 dev->get_wireless_stats = wavelan_get_wireless_stats;
4523 #endif
4524
4525 /* Other specific data */
4526 strcpy(dev->name, ((net_local *)dev->priv)->node.dev_name);
4527 netif_start_queue (dev);
4528 dev->mtu = WAVELAN_MTU;
4529
4530 /* Register with Card Services */
4531 client_reg.dev_info = &dev_info;
4532 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
4533 client_reg.EventMask =
4534 CS_EVENT_REGISTRATION_COMPLETE |
4535 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
4536 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
4537 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
4538 client_reg.event_handler = &wavelan_event;
4539 client_reg.Version = 0x0210;
4540 client_reg.event_callback_args.client_data = link;
4541
4542 #ifdef DEBUG_CONFIG_INFO
4543 printk(KERN_DEBUG "wavelan_attach(): almost done, calling CardServices\n");
4544 #endif
4545
4546 ret = CardServices(RegisterClient, &link->handle, &client_reg);
4547 if(ret != 0)
4548 {
4549 cs_error(link->handle, RegisterClient, ret);
4550 wavelan_detach(link);
4551 return NULL;
4552 }
4553
4554 #ifdef DEBUG_CALLBACK_TRACE
4555 printk(KERN_DEBUG "<- wavelan_attach()\n");
4556 #endif
4557
4558 return link;
4559
4560 fail_alloc_dev_priv:
4561 kfree(dev);
4562 fail_alloc_dev:
4563 kfree(link);
4564 return NULL;
4565 }
4566
4567 /*------------------------------------------------------------------*/
4568 /*
4569 * This deletes a driver "instance". The device is de-registered with
4570 * Card Services. If it has been released, all local data structures
4571 * are freed. Otherwise, the structures will be freed when the device
4572 * is released.
4573 */
4574 static void
4575 wavelan_detach(dev_link_t * link)
4576 {
4577 #ifdef DEBUG_CALLBACK_TRACE
4578 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4579 #endif
4580
4581 /*
4582 * If the device is currently configured and active, we won't
4583 * actually delete it yet. Instead, it is marked so that when the
4584 * release() function is called, that will trigger a proper
4585 * detach().
4586 */
4587 if(link->state & DEV_CONFIG)
4588 {
4589 /* Some others haven't done their job : give them another chance */
4590 wv_pcmcia_release((u_long) link);
4591 if(link->state & DEV_STALE_CONFIG)
4592 {
4593 #ifdef DEBUG_CONFIG_INFO
4594 printk(KERN_DEBUG "wavelan_detach: detach postponed,"
4595 " '%s' still locked\n", link->dev->dev_name);
4596 #endif
4597 link->state |= DEV_STALE_LINK;
4598 return;
4599 }
4600 }
4601
4602 /* Break the link with Card Services */
4603 if(link->handle)
4604 CardServices(DeregisterClient, link->handle);
4605
4606 /* Remove the interface data from the linked list */
4607 if(dev_list == link)
4608 dev_list = link->next;
4609 else
4610 {
4611 dev_link_t * prev = dev_list;
4612
4613 while((prev != (dev_link_t *) NULL) && (prev->next != link))
4614 prev = prev->next;
4615
4616 if(prev == (dev_link_t *) NULL)
4617 {
4618 #ifdef DEBUG_CONFIG_ERRORS
4619 printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.\n");
4620 #endif
4621 return;
4622 }
4623
4624 prev->next = link->next;
4625 }
4626
4627 /* Free pieces */
4628 if(link->priv)
4629 {
4630 device * dev = (device *) link->priv;
4631
4632 /* Remove ourselves from the kernel list of ethernet devices */
4633 /* Warning : can't be called from interrupt, timer or wavelan_close() */
4634 if(link->dev != NULL)
4635 unregister_netdev(dev);
4636 link->dev = NULL;
4637
4638 if(dev->priv)
4639 {
4640 /* Sound strange, but safe... */
4641 ((net_local *) dev->priv)->link = (dev_link_t *) NULL;
4642 ((net_local *) dev->priv)->dev = (device *) NULL;
4643 kfree(dev->priv);
4644 }
4645 kfree(link->priv);
4646 }
4647 kfree(link);
4648
4649 #ifdef DEBUG_CALLBACK_TRACE
4650 printk(KERN_DEBUG "<- wavelan_detach()\n");
4651 #endif
4652 }
4653
4654 /*------------------------------------------------------------------*/
4655 /*
4656 * The card status event handler. Mostly, this schedules other stuff
4657 * to run after an event is received. A CARD_REMOVAL event also sets
4658 * some flags to discourage the net drivers from trying to talk to the
4659 * card any more.
4660 */
4661 static int
4662 wavelan_event(event_t event, /* The event received */
4663 int priority,
4664 event_callback_args_t * args)
4665 {
4666 dev_link_t * link = (dev_link_t *) args->client_data;
4667 device * dev = (device *) link->priv;
4668
4669 #ifdef DEBUG_CALLBACK_TRACE
4670 printk(KERN_DEBUG "->wavelan_event(): %s\n",
4671 ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" :
4672 ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" :
4673 ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" :
4674 ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" :
4675 ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" :
4676 ((event == CS_EVENT_PM_RESUME) ? "pm resume" :
4677 ((event == CS_EVENT_CARD_RESET) ? "card reset" :
4678 "unknown"))))))));
4679 #endif
4680
4681 switch(event)
4682 {
4683 case CS_EVENT_REGISTRATION_COMPLETE:
4684 #ifdef DEBUG_CONFIG_INFO
4685 printk(KERN_DEBUG "wavelan_cs: registration complete\n");
4686 #endif
4687 break;
4688
4689 case CS_EVENT_CARD_REMOVAL:
4690 /* Oups ! The card is no more there */
4691 link->state &= ~DEV_PRESENT;
4692 if(link->state & DEV_CONFIG)
4693 {
4694 /* Accept no more transmissions */
4695 netif_device_detach(dev);
4696
4697 /* Release the card */
4698 wv_pcmcia_release((u_long) link);
4699 }
4700 break;
4701
4702 case CS_EVENT_CARD_INSERTION:
4703 /* Reset and configure the card */
4704 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
4705 if(wv_pcmcia_config(link) &&
4706 wv_hw_config(dev))
4707 wv_init_info(dev);
4708 else
4709 dev->irq = 0;
4710 break;
4711
4712 case CS_EVENT_PM_SUSPEND:
4713 /* NB: wavelan_close will be called, but too late, so we are
4714 * obliged to close nicely the wavelan here. David, could you
4715 * close the device before suspending them ? And, by the way,
4716 * could you, on resume, add a "route add -net ..." after the
4717 * ifconfig up XXX Thanks... */
4718
4719 /* Stop receiving new messages and wait end of transmission */
4720 wv_ru_stop(dev);
4721
4722 /* Power down the module */
4723 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
4724
4725 /* The card is now suspended */
4726 link->state |= DEV_SUSPEND;
4727 /* Fall through... */
4728 case CS_EVENT_RESET_PHYSICAL:
4729 if(link->state & DEV_CONFIG)
4730 {
4731 if(link->open)
4732 netif_device_detach(dev);
4733
4734 CardServices(ReleaseConfiguration, link->handle);
4735 }
4736 break;
4737
4738 case CS_EVENT_PM_RESUME:
4739 link->state &= ~DEV_SUSPEND;
4740 /* Fall through... */
4741 case CS_EVENT_CARD_RESET:
4742 if(link->state & DEV_CONFIG)
4743 {
4744 CardServices(RequestConfiguration, link->handle, &link->conf);
4745 if(link->open) /* If RESET -> True, If RESUME -> False XXX */
4746 {
4747 wv_hw_reset(dev);
4748 netif_device_attach(dev);
4749 }
4750 }
4751 break;
4752 }
4753
4754 #ifdef DEBUG_CALLBACK_TRACE
4755 printk(KERN_DEBUG "<-wavelan_event()\n");
4756 #endif
4757 return 0;
4758 }
4759
4760 /****************************** MODULE ******************************/
4761 /*
4762 * Module entry points : insertion & removal
4763 */
4764
4765 /*------------------------------------------------------------------*/
4766 /*
4767 * Module insertion : initialisation of the module.
4768 * Register the card with cardmgr...
4769 */
4770 static int __init
4771 init_wavelan_cs(void)
4772 {
4773 servinfo_t serv;
4774
4775 #ifdef DEBUG_MODULE_TRACE
4776 printk(KERN_DEBUG "-> init_wavelan_cs()\n");
4777 #ifdef DEBUG_VERSION_SHOW
4778 printk(KERN_DEBUG "%s", version);
4779 #endif
4780 #endif
4781
4782 CardServices(GetCardServicesInfo, &serv);
4783 if(serv.Revision != CS_RELEASE_CODE)
4784 {
4785 #ifdef DEBUG_CONFIG_ERRORS
4786 printk(KERN_WARNING "init_wavelan_cs: Card Services release does not match!\n");
4787 #endif
4788 return -1;
4789 }
4790
4791 register_pccard_driver(&dev_info, &wavelan_attach, &wavelan_detach);
4792
4793 #ifdef DEBUG_MODULE_TRACE
4794 printk(KERN_DEBUG "<- init_wavelan_cs()\n");
4795 #endif
4796 return 0;
4797 }
4798
4799 /*------------------------------------------------------------------*/
4800 /*
4801 * Module removal
4802 */
4803 static void __exit
4804 exit_wavelan_cs(void)
4805 {
4806 #ifdef DEBUG_MODULE_TRACE
4807 printk(KERN_DEBUG "-> cleanup_module()\n");
4808 #endif
4809 #ifdef DEBUG_BASIC_SHOW
4810 printk(KERN_NOTICE "wavelan_cs: unloading\n");
4811 #endif
4812
4813 /* Do some cleanup of the device list */
4814 wv_flush_stale_links();
4815
4816 /* If there remain some devices... */
4817 #ifdef DEBUG_CONFIG_ERRORS
4818 if(dev_list != NULL)
4819 {
4820 /* Honestly, if this happen we are in a deep s**t */
4821 printk(KERN_INFO "wavelan_cs: devices remaining when removing module\n");
4822 printk(KERN_INFO "Please flush your disks and reboot NOW !\n");
4823 }
4824 #endif
4825
4826 unregister_pccard_driver(&dev_info);
4827
4828 #ifdef DEBUG_MODULE_TRACE
4829 printk(KERN_DEBUG "<- cleanup_module()\n");
4830 #endif
4831 }
4832
4833 module_init(init_wavelan_cs);
4834 module_exit(exit_wavelan_cs);
4835