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