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