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