[CRYPTO]: Use CRYPTO_TFM_REQ_MAY_SLEEP where appropriate
[linux-2.6] / drivers / net / wireless / wavelan.c
1 /*
2  *      WaveLAN ISA driver
3  *
4  *              Jean II - HPLB '96
5  *
6  * Reorganisation and extension of the driver.
7  * Original copyright follows (also see the end of this file).
8  * See wavelan.p.h for details.
9  *
10  *
11  *
12  * AT&T GIS (nee NCR) WaveLAN card:
13  *      An Ethernet-like radio transceiver
14  *      controlled by an Intel 82586 coprocessor.
15  */
16
17 #include "wavelan.p.h"          /* Private header */
18
19 /************************* MISC SUBROUTINES **************************/
20 /*
21  * Subroutines which won't fit in one of the following category
22  * (WaveLAN modem or i82586)
23  */
24
25 /*------------------------------------------------------------------*/
26 /*
27  * Translate irq number to PSA irq parameter
28  */
29 static u8 wv_irq_to_psa(int irq)
30 {
31         if (irq < 0 || irq >= NELS(irqvals))
32                 return 0;
33
34         return irqvals[irq];
35 }
36
37 /*------------------------------------------------------------------*/
38 /*
39  * Translate PSA irq parameter to irq number 
40  */
41 static int __init wv_psa_to_irq(u8 irqval)
42 {
43         int irq;
44
45         for (irq = 0; irq < NELS(irqvals); irq++)
46                 if (irqvals[irq] == irqval)
47                         return irq;
48
49         return -1;
50 }
51
52 #ifdef STRUCT_CHECK
53 /*------------------------------------------------------------------*/
54 /*
55  * Sanity routine to verify the sizes of the various WaveLAN interface
56  * structures.
57  */
58 static char *wv_struct_check(void)
59 {
60 #define SC(t,s,n)       if (sizeof(t) != s) return(n);
61
62         SC(psa_t, PSA_SIZE, "psa_t");
63         SC(mmw_t, MMW_SIZE, "mmw_t");
64         SC(mmr_t, MMR_SIZE, "mmr_t");
65         SC(ha_t, HA_SIZE, "ha_t");
66
67 #undef  SC
68
69         return ((char *) NULL);
70 }                               /* wv_struct_check */
71 #endif                          /* STRUCT_CHECK */
72
73 /********************* HOST ADAPTER SUBROUTINES *********************/
74 /*
75  * Useful subroutines to manage the WaveLAN ISA interface
76  *
77  * One major difference with the PCMCIA hardware (except the port mapping)
78  * is that we have to keep the state of the Host Control Register
79  * because of the interrupt enable & bus size flags.
80  */
81
82 /*------------------------------------------------------------------*/
83 /*
84  * Read from card's Host Adaptor Status Register.
85  */
86 static inline u16 hasr_read(unsigned long ioaddr)
87 {
88         return (inw(HASR(ioaddr)));
89 }                               /* hasr_read */
90
91 /*------------------------------------------------------------------*/
92 /*
93  * Write to card's Host Adapter Command Register.
94  */
95 static inline void hacr_write(unsigned long ioaddr, u16 hacr)
96 {
97         outw(hacr, HACR(ioaddr));
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  */
105 static inline void hacr_write_slow(unsigned long ioaddr, u16 hacr)
106 {
107         hacr_write(ioaddr, hacr);
108         /* delay might only be needed sometimes */
109         mdelay(1);
110 }                               /* hacr_write_slow */
111
112 /*------------------------------------------------------------------*/
113 /*
114  * Set the channel attention bit.
115  */
116 static inline void set_chan_attn(unsigned long ioaddr, u16 hacr)
117 {
118         hacr_write(ioaddr, hacr | HACR_CA);
119 }                               /* set_chan_attn */
120
121 /*------------------------------------------------------------------*/
122 /*
123  * Reset, and then set host adaptor into default mode.
124  */
125 static inline void wv_hacr_reset(unsigned long ioaddr)
126 {
127         hacr_write_slow(ioaddr, HACR_RESET);
128         hacr_write(ioaddr, HACR_DEFAULT);
129 }                               /* wv_hacr_reset */
130
131 /*------------------------------------------------------------------*/
132 /*
133  * Set the I/O transfer over the ISA bus to 8-bit mode
134  */
135 static inline void wv_16_off(unsigned long ioaddr, u16 hacr)
136 {
137         hacr &= ~HACR_16BITS;
138         hacr_write(ioaddr, hacr);
139 }                               /* wv_16_off */
140
141 /*------------------------------------------------------------------*/
142 /*
143  * Set the I/O transfer over the ISA bus to 8-bit mode
144  */
145 static inline void wv_16_on(unsigned long ioaddr, u16 hacr)
146 {
147         hacr |= HACR_16BITS;
148         hacr_write(ioaddr, hacr);
149 }                               /* wv_16_on */
150
151 /*------------------------------------------------------------------*/
152 /*
153  * Disable interrupts on the WaveLAN hardware.
154  * (called by wv_82586_stop())
155  */
156 static inline void wv_ints_off(struct net_device * dev)
157 {
158         net_local *lp = (net_local *) dev->priv;
159         unsigned long ioaddr = dev->base_addr;
160         
161         lp->hacr &= ~HACR_INTRON;
162         hacr_write(ioaddr, lp->hacr);
163 }                               /* wv_ints_off */
164
165 /*------------------------------------------------------------------*/
166 /*
167  * Enable interrupts on the WaveLAN hardware.
168  * (called by wv_hw_reset())
169  */
170 static inline void wv_ints_on(struct net_device * dev)
171 {
172         net_local *lp = (net_local *) dev->priv;
173         unsigned long ioaddr = dev->base_addr;
174
175         lp->hacr |= HACR_INTRON;
176         hacr_write(ioaddr, lp->hacr);
177 }                               /* wv_ints_on */
178
179 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
180 /*
181  * Useful subroutines to manage the modem of the WaveLAN
182  */
183
184 /*------------------------------------------------------------------*/
185 /*
186  * Read the Parameter Storage Area from the WaveLAN card's memory
187  */
188 /*
189  * Read bytes from the PSA.
190  */
191 static void psa_read(unsigned long ioaddr, u16 hacr, int o,     /* offset in PSA */
192                      u8 * b,    /* buffer to fill */
193                      int n)
194 {                               /* size to read */
195         wv_16_off(ioaddr, hacr);
196
197         while (n-- > 0) {
198                 outw(o, PIOR2(ioaddr));
199                 o++;
200                 *b++ = inb(PIOP2(ioaddr));
201         }
202
203         wv_16_on(ioaddr, hacr);
204 }                               /* psa_read */
205
206 /*------------------------------------------------------------------*/
207 /*
208  * Write the Parameter Storage Area to the WaveLAN card's memory.
209  */
210 static void psa_write(unsigned long ioaddr, u16 hacr, int o,    /* Offset in PSA */
211                       u8 * b,   /* Buffer in memory */
212                       int n)
213 {                               /* Length of buffer */
214         int count = 0;
215
216         wv_16_off(ioaddr, hacr);
217
218         while (n-- > 0) {
219                 outw(o, PIOR2(ioaddr));
220                 o++;
221
222                 outb(*b, PIOP2(ioaddr));
223                 b++;
224
225                 /* Wait for the memory to finish its write cycle */
226                 count = 0;
227                 while ((count++ < 100) &&
228                        (hasr_read(ioaddr) & HASR_PSA_BUSY)) mdelay(1);
229         }
230
231         wv_16_on(ioaddr, hacr);
232 }                               /* psa_write */
233
234 #ifdef SET_PSA_CRC
235 /*------------------------------------------------------------------*/
236 /*
237  * Calculate the PSA CRC
238  * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
239  * NOTE: By specifying a length including the CRC position the
240  * returned value should be zero. (i.e. a correct checksum in the PSA)
241  *
242  * The Windows drivers don't use the CRC, but the AP and the PtP tool
243  * depend on it.
244  */
245 static inline u16 psa_crc(u8 * psa,     /* The PSA */
246                               int size)
247 {                               /* Number of short for CRC */
248         int byte_cnt;           /* Loop on the PSA */
249         u16 crc_bytes = 0;      /* Data in the PSA */
250         int bit_cnt;            /* Loop on the bits of the short */
251
252         for (byte_cnt = 0; byte_cnt < size; byte_cnt++) {
253                 crc_bytes ^= psa[byte_cnt];     /* Its an xor */
254
255                 for (bit_cnt = 1; bit_cnt < 9; bit_cnt++) {
256                         if (crc_bytes & 0x0001)
257                                 crc_bytes = (crc_bytes >> 1) ^ 0xA001;
258                         else
259                                 crc_bytes >>= 1;
260                 }
261         }
262
263         return crc_bytes;
264 }                               /* psa_crc */
265 #endif                          /* SET_PSA_CRC */
266
267 /*------------------------------------------------------------------*/
268 /*
269  * update the checksum field in the Wavelan's PSA
270  */
271 static void update_psa_checksum(struct net_device * dev, unsigned long ioaddr, u16 hacr)
272 {
273 #ifdef SET_PSA_CRC
274         psa_t psa;
275         u16 crc;
276
277         /* read the parameter storage area */
278         psa_read(ioaddr, hacr, 0, (unsigned char *) &psa, sizeof(psa));
279
280         /* update the checksum */
281         crc = psa_crc((unsigned char *) &psa,
282                       sizeof(psa) - sizeof(psa.psa_crc[0]) -
283                       sizeof(psa.psa_crc[1])
284                       - sizeof(psa.psa_crc_status));
285
286         psa.psa_crc[0] = crc & 0xFF;
287         psa.psa_crc[1] = (crc & 0xFF00) >> 8;
288
289         /* Write it ! */
290         psa_write(ioaddr, hacr, (char *) &psa.psa_crc - (char *) &psa,
291                   (unsigned char *) &psa.psa_crc, 2);
292
293 #ifdef DEBUG_IOCTL_INFO
294         printk(KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
295                dev->name, psa.psa_crc[0], psa.psa_crc[1]);
296
297         /* Check again (luxury !) */
298         crc = psa_crc((unsigned char *) &psa,
299                       sizeof(psa) - sizeof(psa.psa_crc_status));
300
301         if (crc != 0)
302                 printk(KERN_WARNING
303                        "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n",
304                        dev->name);
305 #endif                          /* DEBUG_IOCTL_INFO */
306 #endif                          /* SET_PSA_CRC */
307 }                               /* update_psa_checksum */
308
309 /*------------------------------------------------------------------*/
310 /*
311  * Write 1 byte to the MMC.
312  */
313 static inline void mmc_out(unsigned long ioaddr, u16 o, u8 d)
314 {
315         int count = 0;
316
317         /* Wait for MMC to go idle */
318         while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
319                 udelay(10);
320
321         outw((u16) (((u16) d << 8) | (o << 1) | 1), MMCR(ioaddr));
322 }
323
324 /*------------------------------------------------------------------*/
325 /*
326  * Routine to write bytes to the Modem Management Controller.
327  * We start at the end because it is the way it should be!
328  */
329 static inline void mmc_write(unsigned long ioaddr, u8 o, u8 * b, int n)
330 {
331         o += n;
332         b += n;
333
334         while (n-- > 0)
335                 mmc_out(ioaddr, --o, *(--b));
336 }                               /* mmc_write */
337
338 /*------------------------------------------------------------------*/
339 /*
340  * Read a byte from the MMC.
341  * Optimised version for 1 byte, avoid using memory.
342  */
343 static inline u8 mmc_in(unsigned long ioaddr, u16 o)
344 {
345         int count = 0;
346
347         while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
348                 udelay(10);
349         outw(o << 1, MMCR(ioaddr));
350
351         while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
352                 udelay(10);
353         return (u8) (inw(MMCR(ioaddr)) >> 8);
354 }
355
356 /*------------------------------------------------------------------*/
357 /*
358  * Routine to read bytes from the Modem Management Controller.
359  * The implementation is complicated by a lack of address lines,
360  * which prevents decoding of the low-order bit.
361  * (code has just been moved in the above function)
362  * We start at the end because it is the way it should be!
363  */
364 static inline void mmc_read(unsigned long ioaddr, u8 o, u8 * b, int n)
365 {
366         o += n;
367         b += n;
368
369         while (n-- > 0)
370                 *(--b) = mmc_in(ioaddr, --o);
371 }                               /* mmc_read */
372
373 /*------------------------------------------------------------------*/
374 /*
375  * Get the type of encryption available.
376  */
377 static inline int mmc_encr(unsigned long ioaddr)
378 {                               /* I/O port of the card */
379         int temp;
380
381         temp = mmc_in(ioaddr, mmroff(0, mmr_des_avail));
382         if ((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
383                 return 0;
384         else
385                 return temp;
386 }
387
388 /*------------------------------------------------------------------*/
389 /*
390  * Wait for the frequency EEPROM to complete a command.
391  * I hope this one will be optimally inlined.
392  */
393 static inline void fee_wait(unsigned long ioaddr,       /* I/O port of the card */
394                             int delay,  /* Base delay to wait for */
395                             int number)
396 {                               /* Number of time to wait */
397         int count = 0;          /* Wait only a limited time */
398
399         while ((count++ < number) &&
400                (mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
401                 MMR_FEE_STATUS_BUSY)) udelay(delay);
402 }
403
404 /*------------------------------------------------------------------*/
405 /*
406  * Read bytes from the Frequency EEPROM (frequency select cards).
407  */
408 static void fee_read(unsigned long ioaddr,      /* I/O port of the card */
409                      u16 o,     /* destination offset */
410                      u16 * b,   /* data buffer */
411                      int n)
412 {                               /* number of registers */
413         b += n;                 /* Position at the end of the area */
414
415         /* Write the address */
416         mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
417
418         /* Loop on all buffer */
419         while (n-- > 0) {
420                 /* Write the read command */
421                 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
422                         MMW_FEE_CTRL_READ);
423
424                 /* Wait until EEPROM is ready (should be quick). */
425                 fee_wait(ioaddr, 10, 100);
426
427                 /* Read the value. */
428                 *--b = ((mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)) << 8) |
429                         mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
430         }
431 }
432
433 #ifdef WIRELESS_EXT             /* if the wireless extension exists in the kernel */
434
435 /*------------------------------------------------------------------*/
436 /*
437  * Write bytes from the Frequency EEPROM (frequency select cards).
438  * This is a bit complicated, because the frequency EEPROM has to
439  * be unprotected and the write enabled.
440  * Jean II
441  */
442 static void fee_write(unsigned long ioaddr,     /* I/O port of the card */
443                       u16 o,    /* destination offset */
444                       u16 * b,  /* data buffer */
445                       int n)
446 {                               /* number of registers */
447         b += n;                 /* Position at the end of the area. */
448
449 #ifdef EEPROM_IS_PROTECTED      /* disabled */
450 #ifdef DOESNT_SEEM_TO_WORK      /* disabled */
451         /* Ask to read the protected register */
452         mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
453
454         fee_wait(ioaddr, 10, 100);
455
456         /* Read the protected register. */
457         printk("Protected 2:  %02X-%02X\n",
458                mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)),
459                mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
460 #endif                          /* DOESNT_SEEM_TO_WORK */
461
462         /* Enable protected register. */
463         mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
464         mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
465
466         fee_wait(ioaddr, 10, 100);
467
468         /* Unprotect area. */
469         mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n);
470         mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
471 #ifdef DOESNT_SEEM_TO_WORK      /* disabled */
472         /* or use: */
473         mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
474 #endif                          /* DOESNT_SEEM_TO_WORK */
475
476         fee_wait(ioaddr, 10, 100);
477 #endif                          /* EEPROM_IS_PROTECTED */
478
479         /* Write enable. */
480         mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
481         mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
482
483         fee_wait(ioaddr, 10, 100);
484
485         /* Write the EEPROM address. */
486         mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
487
488         /* Loop on all buffer */
489         while (n-- > 0) {
490                 /* Write the value. */
491                 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
492                 mmc_out(ioaddr, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
493
494                 /* Write the write command. */
495                 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
496                         MMW_FEE_CTRL_WRITE);
497
498                 /* WaveLAN documentation says to wait at least 10 ms for EEBUSY = 0 */
499                 mdelay(10);
500                 fee_wait(ioaddr, 10, 100);
501         }
502
503         /* Write disable. */
504         mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
505         mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
506
507         fee_wait(ioaddr, 10, 100);
508
509 #ifdef EEPROM_IS_PROTECTED      /* disabled */
510         /* Reprotect EEPROM. */
511         mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x00);
512         mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
513
514         fee_wait(ioaddr, 10, 100);
515 #endif                          /* EEPROM_IS_PROTECTED */
516 }
517 #endif                          /* WIRELESS_EXT */
518
519 /************************ I82586 SUBROUTINES *************************/
520 /*
521  * Useful subroutines to manage the Ethernet controller
522  */
523
524 /*------------------------------------------------------------------*/
525 /*
526  * Read bytes from the on-board RAM.
527  * Why does inlining this function make it fail?
528  */
529 static /*inline */ void obram_read(unsigned long ioaddr,
530                                    u16 o, u8 * b, int n)
531 {
532         outw(o, PIOR1(ioaddr));
533         insw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
534 }
535
536 /*------------------------------------------------------------------*/
537 /*
538  * Write bytes to the on-board RAM.
539  */
540 static inline void obram_write(unsigned long ioaddr, u16 o, u8 * b, int n)
541 {
542         outw(o, PIOR1(ioaddr));
543         outsw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
544 }
545
546 /*------------------------------------------------------------------*/
547 /*
548  * Acknowledge the reading of the status issued by the i82586.
549  */
550 static void wv_ack(struct net_device * dev)
551 {
552         net_local *lp = (net_local *) dev->priv;
553         unsigned long ioaddr = dev->base_addr;
554         u16 scb_cs;
555         int i;
556
557         obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
558                    (unsigned char *) &scb_cs, sizeof(scb_cs));
559         scb_cs &= SCB_ST_INT;
560
561         if (scb_cs == 0)
562                 return;
563
564         obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
565                     (unsigned char *) &scb_cs, sizeof(scb_cs));
566
567         set_chan_attn(ioaddr, lp->hacr);
568
569         for (i = 1000; i > 0; i--) {
570                 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
571                            (unsigned char *) &scb_cs, sizeof(scb_cs));
572                 if (scb_cs == 0)
573                         break;
574
575                 udelay(10);
576         }
577         udelay(100);
578
579 #ifdef DEBUG_CONFIG_ERROR
580         if (i <= 0)
581                 printk(KERN_INFO
582                        "%s: wv_ack(): board not accepting command.\n",
583                        dev->name);
584 #endif
585 }
586
587 /*------------------------------------------------------------------*/
588 /*
589  * Set channel attention bit and busy wait until command has
590  * completed, then acknowledge completion of the command.
591  */
592 static inline int wv_synchronous_cmd(struct net_device * dev, const char *str)
593 {
594         net_local *lp = (net_local *) dev->priv;
595         unsigned long ioaddr = dev->base_addr;
596         u16 scb_cmd;
597         ach_t cb;
598         int i;
599
600         scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO;
601         obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
602                     (unsigned char *) &scb_cmd, sizeof(scb_cmd));
603
604         set_chan_attn(ioaddr, lp->hacr);
605
606         for (i = 1000; i > 0; i--) {
607                 obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb,
608                            sizeof(cb));
609                 if (cb.ac_status & AC_SFLD_C)
610                         break;
611
612                 udelay(10);
613         }
614         udelay(100);
615
616         if (i <= 0 || !(cb.ac_status & AC_SFLD_OK)) {
617 #ifdef DEBUG_CONFIG_ERROR
618                 printk(KERN_INFO "%s: %s failed; status = 0x%x\n",
619                        dev->name, str, cb.ac_status);
620 #endif
621 #ifdef DEBUG_I82586_SHOW
622                 wv_scb_show(ioaddr);
623 #endif
624                 return -1;
625         }
626
627         /* Ack the status */
628         wv_ack(dev);
629
630         return 0;
631 }
632
633 /*------------------------------------------------------------------*/
634 /*
635  * Configuration commands completion interrupt.
636  * Check if done, and if OK.
637  */
638 static inline int
639 wv_config_complete(struct net_device * dev, unsigned long ioaddr, net_local * lp)
640 {
641         unsigned short mcs_addr;
642         unsigned short status;
643         int ret;
644
645 #ifdef DEBUG_INTERRUPT_TRACE
646         printk(KERN_DEBUG "%s: ->wv_config_complete()\n", dev->name);
647 #endif
648
649         mcs_addr = lp->tx_first_in_use + sizeof(ac_tx_t) + sizeof(ac_nop_t)
650             + sizeof(tbd_t) + sizeof(ac_cfg_t) + sizeof(ac_ias_t);
651
652         /* Read the status of the last command (set mc list). */
653         obram_read(ioaddr, acoff(mcs_addr, ac_status),
654                    (unsigned char *) &status, sizeof(status));
655
656         /* If not completed -> exit */
657         if ((status & AC_SFLD_C) == 0)
658                 ret = 0;        /* Not ready to be scrapped */
659         else {
660 #ifdef DEBUG_CONFIG_ERROR
661                 unsigned short cfg_addr;
662                 unsigned short ias_addr;
663
664                 /* Check mc_config command */
665                 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
666                         printk(KERN_INFO
667                                "%s: wv_config_complete(): set_multicast_address failed; status = 0x%x\n",
668                                dev->name, status);
669
670                 /* check ia-config command */
671                 ias_addr = mcs_addr - sizeof(ac_ias_t);
672                 obram_read(ioaddr, acoff(ias_addr, ac_status),
673                            (unsigned char *) &status, sizeof(status));
674                 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
675                         printk(KERN_INFO
676                                "%s: wv_config_complete(): set_MAC_address failed; status = 0x%x\n",
677                                dev->name, status);
678
679                 /* Check config command. */
680                 cfg_addr = ias_addr - sizeof(ac_cfg_t);
681                 obram_read(ioaddr, acoff(cfg_addr, ac_status),
682                            (unsigned char *) &status, sizeof(status));
683                 if ((status & AC_SFLD_OK) != AC_SFLD_OK)
684                         printk(KERN_INFO
685                                "%s: wv_config_complete(): configure failed; status = 0x%x\n",
686                                dev->name, status);
687 #endif  /* DEBUG_CONFIG_ERROR */
688
689                 ret = 1;        /* Ready to be scrapped */
690         }
691
692 #ifdef DEBUG_INTERRUPT_TRACE
693         printk(KERN_DEBUG "%s: <-wv_config_complete() - %d\n", dev->name,
694                ret);
695 #endif
696         return ret;
697 }
698
699 /*------------------------------------------------------------------*/
700 /*
701  * Command completion interrupt.
702  * Reclaim as many freed tx buffers as we can.
703  * (called in wavelan_interrupt()).
704  * Note : the spinlock is already grabbed for us.
705  */
706 static int wv_complete(struct net_device * dev, unsigned long ioaddr, net_local * lp)
707 {
708         int nreaped = 0;
709
710 #ifdef DEBUG_INTERRUPT_TRACE
711         printk(KERN_DEBUG "%s: ->wv_complete()\n", dev->name);
712 #endif
713
714         /* Loop on all the transmit buffers */
715         while (lp->tx_first_in_use != I82586NULL) {
716                 unsigned short tx_status;
717
718                 /* Read the first transmit buffer */
719                 obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status),
720                            (unsigned char *) &tx_status,
721                            sizeof(tx_status));
722
723                 /* If not completed -> exit */
724                 if ((tx_status & AC_SFLD_C) == 0)
725                         break;
726
727                 /* Hack for reconfiguration */
728                 if (tx_status == 0xFFFF)
729                         if (!wv_config_complete(dev, ioaddr, lp))
730                                 break;  /* Not completed */
731
732                 /* We now remove this buffer */
733                 nreaped++;
734                 --lp->tx_n_in_use;
735
736 /*
737 if (lp->tx_n_in_use > 0)
738         printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
739 */
740
741                 /* Was it the last one? */
742                 if (lp->tx_n_in_use <= 0)
743                         lp->tx_first_in_use = I82586NULL;
744                 else {
745                         /* Next one in the chain */
746                         lp->tx_first_in_use += TXBLOCKZ;
747                         if (lp->tx_first_in_use >=
748                             OFFSET_CU +
749                             NTXBLOCKS * TXBLOCKZ) lp->tx_first_in_use -=
750                                     NTXBLOCKS * TXBLOCKZ;
751                 }
752
753                 /* Hack for reconfiguration */
754                 if (tx_status == 0xFFFF)
755                         continue;
756
757                 /* Now, check status of the finished command */
758                 if (tx_status & AC_SFLD_OK) {
759                         int ncollisions;
760
761                         lp->stats.tx_packets++;
762                         ncollisions = tx_status & AC_SFLD_MAXCOL;
763                         lp->stats.collisions += ncollisions;
764 #ifdef DEBUG_TX_INFO
765                         if (ncollisions > 0)
766                                 printk(KERN_DEBUG
767                                        "%s: wv_complete(): tx completed after %d collisions.\n",
768                                        dev->name, ncollisions);
769 #endif
770                 } else {
771                         lp->stats.tx_errors++;
772                         if (tx_status & AC_SFLD_S10) {
773                                 lp->stats.tx_carrier_errors++;
774 #ifdef DEBUG_TX_FAIL
775                                 printk(KERN_DEBUG
776                                        "%s: wv_complete(): tx error: no CS.\n",
777                                        dev->name);
778 #endif
779                         }
780                         if (tx_status & AC_SFLD_S9) {
781                                 lp->stats.tx_carrier_errors++;
782 #ifdef DEBUG_TX_FAIL
783                                 printk(KERN_DEBUG
784                                        "%s: wv_complete(): tx error: lost CTS.\n",
785                                        dev->name);
786 #endif
787                         }
788                         if (tx_status & AC_SFLD_S8) {
789                                 lp->stats.tx_fifo_errors++;
790 #ifdef DEBUG_TX_FAIL
791                                 printk(KERN_DEBUG
792                                        "%s: wv_complete(): tx error: slow DMA.\n",
793                                        dev->name);
794 #endif
795                         }
796                         if (tx_status & AC_SFLD_S6) {
797                                 lp->stats.tx_heartbeat_errors++;
798 #ifdef DEBUG_TX_FAIL
799                                 printk(KERN_DEBUG
800                                        "%s: wv_complete(): tx error: heart beat.\n",
801                                        dev->name);
802 #endif
803                         }
804                         if (tx_status & AC_SFLD_S5) {
805                                 lp->stats.tx_aborted_errors++;
806 #ifdef DEBUG_TX_FAIL
807                                 printk(KERN_DEBUG
808                                        "%s: wv_complete(): tx error: too many collisions.\n",
809                                        dev->name);
810 #endif
811                         }
812                 }
813
814 #ifdef DEBUG_TX_INFO
815                 printk(KERN_DEBUG
816                        "%s: wv_complete(): tx completed, tx_status 0x%04x\n",
817                        dev->name, tx_status);
818 #endif
819         }
820
821 #ifdef DEBUG_INTERRUPT_INFO
822         if (nreaped > 1)
823                 printk(KERN_DEBUG "%s: wv_complete(): reaped %d\n",
824                        dev->name, nreaped);
825 #endif
826
827         /*
828          * Inform upper layers.
829          */
830         if (lp->tx_n_in_use < NTXBLOCKS - 1) {
831                 netif_wake_queue(dev);
832         }
833 #ifdef DEBUG_INTERRUPT_TRACE
834         printk(KERN_DEBUG "%s: <-wv_complete()\n", dev->name);
835 #endif
836         return nreaped;
837 }
838
839 /*------------------------------------------------------------------*/
840 /*
841  * Reconfigure the i82586, or at least ask for it.
842  * Because wv_82586_config uses a transmission buffer, we must do it
843  * when we are sure that there is one left, so we do it now
844  * or in wavelan_packet_xmit() (I can't find any better place,
845  * wavelan_interrupt is not an option), so you may experience
846  * delays sometimes.
847  */
848 static inline void wv_82586_reconfig(struct net_device * dev)
849 {
850         net_local *lp = (net_local *) dev->priv;
851         unsigned long flags;
852
853         /* Arm the flag, will be cleard in wv_82586_config() */
854         lp->reconfig_82586 = 1;
855
856         /* Check if we can do it now ! */
857         if((netif_running(dev)) && !(netif_queue_stopped(dev))) {
858                 spin_lock_irqsave(&lp->spinlock, flags);
859                 /* May fail */
860                 wv_82586_config(dev);
861                 spin_unlock_irqrestore(&lp->spinlock, flags);
862         }
863         else {
864 #ifdef DEBUG_CONFIG_INFO
865                 printk(KERN_DEBUG
866                        "%s: wv_82586_reconfig(): delayed (state = %lX)\n",
867                                dev->name, dev->state);
868 #endif
869         }
870 }
871
872 /********************* DEBUG & INFO SUBROUTINES *********************/
873 /*
874  * This routine is used in the code to show information for debugging.
875  * Most of the time, it dumps the contents of hardware structures.
876  */
877
878 #ifdef DEBUG_PSA_SHOW
879 /*------------------------------------------------------------------*/
880 /*
881  * Print the formatted contents of the Parameter Storage Area.
882  */
883 static void wv_psa_show(psa_t * p)
884 {
885         printk(KERN_DEBUG "##### WaveLAN PSA contents: #####\n");
886         printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
887                p->psa_io_base_addr_1,
888                p->psa_io_base_addr_2,
889                p->psa_io_base_addr_3, p->psa_io_base_addr_4);
890         printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
891                p->psa_rem_boot_addr_1,
892                p->psa_rem_boot_addr_2, p->psa_rem_boot_addr_3);
893         printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
894         printk("psa_int_req_no: %d\n", p->psa_int_req_no);
895 #ifdef DEBUG_SHOW_UNUSED
896         printk(KERN_DEBUG
897                "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
898                p->psa_unused0[0], p->psa_unused0[1], p->psa_unused0[2],
899                p->psa_unused0[3], p->psa_unused0[4], p->psa_unused0[5],
900                p->psa_unused0[6]);
901 #endif                          /* DEBUG_SHOW_UNUSED */
902         printk(KERN_DEBUG
903                "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
904                p->psa_univ_mac_addr[0], p->psa_univ_mac_addr[1],
905                p->psa_univ_mac_addr[2], p->psa_univ_mac_addr[3],
906                p->psa_univ_mac_addr[4], p->psa_univ_mac_addr[5]);
907         printk(KERN_DEBUG
908                "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
909                p->psa_local_mac_addr[0], p->psa_local_mac_addr[1],
910                p->psa_local_mac_addr[2], p->psa_local_mac_addr[3],
911                p->psa_local_mac_addr[4], p->psa_local_mac_addr[5]);
912         printk(KERN_DEBUG "psa_univ_local_sel: %d, ",
913                p->psa_univ_local_sel);
914         printk("psa_comp_number: %d, ", p->psa_comp_number);
915         printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
916         printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
917                p->psa_feature_select);
918         printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
919         printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
920         printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
921         printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0],
922                p->psa_nwid[1]);
923         printk("psa_nwid_select: %d\n", p->psa_nwid_select);
924         printk(KERN_DEBUG "psa_encryption_select: %d, ",
925                p->psa_encryption_select);
926         printk
927             ("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
928              p->psa_encryption_key[0], p->psa_encryption_key[1],
929              p->psa_encryption_key[2], p->psa_encryption_key[3],
930              p->psa_encryption_key[4], p->psa_encryption_key[5],
931              p->psa_encryption_key[6], p->psa_encryption_key[7]);
932         printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
933         printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
934                p->psa_call_code[0]);
935         printk
936             ("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
937              p->psa_call_code[0], p->psa_call_code[1], p->psa_call_code[2],
938              p->psa_call_code[3], p->psa_call_code[4], p->psa_call_code[5],
939              p->psa_call_code[6], p->psa_call_code[7]);
940 #ifdef DEBUG_SHOW_UNUSED
941         printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
942                p->psa_reserved[0],
943                p->psa_reserved[1], p->psa_reserved[2], p->psa_reserved[3]);
944 #endif                          /* DEBUG_SHOW_UNUSED */
945         printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
946         printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
947         printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
948 }                               /* wv_psa_show */
949 #endif                          /* DEBUG_PSA_SHOW */
950
951 #ifdef DEBUG_MMC_SHOW
952 /*------------------------------------------------------------------*/
953 /*
954  * Print the formatted status of the Modem Management Controller.
955  * This function needs to be completed.
956  */
957 static void wv_mmc_show(struct net_device * dev)
958 {
959         unsigned long ioaddr = dev->base_addr;
960         net_local *lp = (net_local *) dev->priv;
961         mmr_t m;
962
963         /* Basic check */
964         if (hasr_read(ioaddr) & HASR_NO_CLK) {
965                 printk(KERN_WARNING
966                        "%s: wv_mmc_show: modem not connected\n",
967                        dev->name);
968                 return;
969         }
970
971         /* Read the mmc */
972         mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
973         mmc_read(ioaddr, 0, (u8 *) & m, sizeof(m));
974         mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
975
976 #ifdef WIRELESS_EXT             /* if wireless extension exists in the kernel */
977         /* Don't forget to update statistics */
978         lp->wstats.discard.nwid +=
979             (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
980 #endif                          /* WIRELESS_EXT */
981
982         printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n");
983 #ifdef DEBUG_SHOW_UNUSED
984         printk(KERN_DEBUG
985                "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
986                m.mmr_unused0[0], m.mmr_unused0[1], m.mmr_unused0[2],
987                m.mmr_unused0[3], m.mmr_unused0[4], m.mmr_unused0[5],
988                m.mmr_unused0[6], m.mmr_unused0[7]);
989 #endif                          /* DEBUG_SHOW_UNUSED */
990         printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
991                m.mmr_des_avail, m.mmr_des_status);
992 #ifdef DEBUG_SHOW_UNUSED
993         printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
994                m.mmr_unused1[0],
995                m.mmr_unused1[1],
996                m.mmr_unused1[2], m.mmr_unused1[3], m.mmr_unused1[4]);
997 #endif                          /* DEBUG_SHOW_UNUSED */
998         printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
999                m.mmr_dce_status,
1000                (m.
1001                 mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ?
1002                "energy detected," : "",
1003                (m.
1004                 mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1005                "loop test indicated," : "",
1006                (m.
1007                 mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ?
1008                "transmitter on," : "",
1009                (m.
1010                 mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1011                "jabber timer expired," : "");
1012         printk(KERN_DEBUG "Dsp ID: %02X\n", m.mmr_dsp_id);
1013 #ifdef DEBUG_SHOW_UNUSED
1014         printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1015                m.mmr_unused2[0], m.mmr_unused2[1]);
1016 #endif                          /* DEBUG_SHOW_UNUSED */
1017         printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1018                (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1019                (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1020         printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1021                m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1022                (m.
1023                 mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" :
1024                "below");
1025         printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1026                m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1027                (m.
1028                 mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" :
1029                "no new msg");
1030         printk("silence_lvl: %d [%s], ",
1031                m.mmr_silence_lvl & MMR_SILENCE_LVL,
1032                (m.
1033                 mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" :
1034                "no new update");
1035         printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1036                (m.
1037                 mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" :
1038                "Antenna 0");
1039 #ifdef DEBUG_SHOW_UNUSED
1040         printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1041 #endif                          /* DEBUG_SHOW_UNUSED */
1042 }                               /* wv_mmc_show */
1043 #endif                          /* DEBUG_MMC_SHOW */
1044
1045 #ifdef DEBUG_I82586_SHOW
1046 /*------------------------------------------------------------------*/
1047 /*
1048  * Print the last block of the i82586 memory.
1049  */
1050 static void wv_scb_show(unsigned long ioaddr)
1051 {
1052         scb_t scb;
1053
1054         obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
1055                    sizeof(scb));
1056
1057         printk(KERN_DEBUG "##### WaveLAN system control block: #####\n");
1058
1059         printk(KERN_DEBUG "status: ");
1060         printk("stat 0x%x[%s%s%s%s] ",
1061                (scb.
1062                 scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA |
1063                               SCB_ST_RNR)) >> 12,
1064                (scb.
1065                 scb_status & SCB_ST_CX) ? "command completion interrupt," :
1066                "", (scb.scb_status & SCB_ST_FR) ? "frame received," : "",
1067                (scb.
1068                 scb_status & SCB_ST_CNA) ? "command unit not active," : "",
1069                (scb.
1070                 scb_status & SCB_ST_RNR) ? "receiving unit not ready," :
1071                "");
1072         printk("cus 0x%x[%s%s%s] ", (scb.scb_status & SCB_ST_CUS) >> 8,
1073                ((scb.scb_status & SCB_ST_CUS) ==
1074                 SCB_ST_CUS_IDLE) ? "idle" : "",
1075                ((scb.scb_status & SCB_ST_CUS) ==
1076                 SCB_ST_CUS_SUSP) ? "suspended" : "",
1077                ((scb.scb_status & SCB_ST_CUS) ==
1078                 SCB_ST_CUS_ACTV) ? "active" : "");
1079         printk("rus 0x%x[%s%s%s%s]\n", (scb.scb_status & SCB_ST_RUS) >> 4,
1080                ((scb.scb_status & SCB_ST_RUS) ==
1081                 SCB_ST_RUS_IDLE) ? "idle" : "",
1082                ((scb.scb_status & SCB_ST_RUS) ==
1083                 SCB_ST_RUS_SUSP) ? "suspended" : "",
1084                ((scb.scb_status & SCB_ST_RUS) ==
1085                 SCB_ST_RUS_NRES) ? "no resources" : "",
1086                ((scb.scb_status & SCB_ST_RUS) ==
1087                 SCB_ST_RUS_RDY) ? "ready" : "");
1088
1089         printk(KERN_DEBUG "command: ");
1090         printk("ack 0x%x[%s%s%s%s] ",
1091                (scb.
1092                 scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR |
1093                                SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12,
1094                (scb.
1095                 scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "",
1096                (scb.
1097                 scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "",
1098                (scb.
1099                 scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "",
1100                (scb.
1101                 scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : "");
1102         printk("cuc 0x%x[%s%s%s%s%s] ",
1103                (scb.scb_command & SCB_CMD_CUC) >> 8,
1104                ((scb.scb_command & SCB_CMD_CUC) ==
1105                 SCB_CMD_CUC_NOP) ? "nop" : "",
1106                ((scb.scb_command & SCB_CMD_CUC) ==
1107                 SCB_CMD_CUC_GO) ? "start cbl_offset" : "",
1108                ((scb.scb_command & SCB_CMD_CUC) ==
1109                 SCB_CMD_CUC_RES) ? "resume execution" : "",
1110                ((scb.scb_command & SCB_CMD_CUC) ==
1111                 SCB_CMD_CUC_SUS) ? "suspend execution" : "",
1112                ((scb.scb_command & SCB_CMD_CUC) ==
1113                 SCB_CMD_CUC_ABT) ? "abort execution" : "");
1114         printk("ruc 0x%x[%s%s%s%s%s]\n",
1115                (scb.scb_command & SCB_CMD_RUC) >> 4,
1116                ((scb.scb_command & SCB_CMD_RUC) ==
1117                 SCB_CMD_RUC_NOP) ? "nop" : "",
1118                ((scb.scb_command & SCB_CMD_RUC) ==
1119                 SCB_CMD_RUC_GO) ? "start rfa_offset" : "",
1120                ((scb.scb_command & SCB_CMD_RUC) ==
1121                 SCB_CMD_RUC_RES) ? "resume reception" : "",
1122                ((scb.scb_command & SCB_CMD_RUC) ==
1123                 SCB_CMD_RUC_SUS) ? "suspend reception" : "",
1124                ((scb.scb_command & SCB_CMD_RUC) ==
1125                 SCB_CMD_RUC_ABT) ? "abort reception" : "");
1126
1127         printk(KERN_DEBUG "cbl_offset 0x%x ", scb.scb_cbl_offset);
1128         printk("rfa_offset 0x%x\n", scb.scb_rfa_offset);
1129
1130         printk(KERN_DEBUG "crcerrs %d ", scb.scb_crcerrs);
1131         printk("alnerrs %d ", scb.scb_alnerrs);
1132         printk("rscerrs %d ", scb.scb_rscerrs);
1133         printk("ovrnerrs %d\n", scb.scb_ovrnerrs);
1134 }
1135
1136 /*------------------------------------------------------------------*/
1137 /*
1138  * Print the formatted status of the i82586's receive unit.
1139  */
1140 static void wv_ru_show(struct net_device * dev)
1141 {
1142         /* net_local *lp = (net_local *) dev->priv; */
1143
1144         printk(KERN_DEBUG
1145                "##### WaveLAN i82586 receiver unit status: #####\n");
1146         printk(KERN_DEBUG "ru:");
1147         /*
1148          * Not implemented yet
1149          */
1150         printk("\n");
1151 }                               /* wv_ru_show */
1152
1153 /*------------------------------------------------------------------*/
1154 /*
1155  * Display info about one control block of the i82586 memory.
1156  */
1157 static void wv_cu_show_one(struct net_device * dev, net_local * lp, int i, u16 p)
1158 {
1159         unsigned long ioaddr;
1160         ac_tx_t actx;
1161
1162         ioaddr = dev->base_addr;
1163
1164         printk("%d: 0x%x:", i, p);
1165
1166         obram_read(ioaddr, p, (unsigned char *) &actx, sizeof(actx));
1167         printk(" status=0x%x,", actx.tx_h.ac_status);
1168         printk(" command=0x%x,", actx.tx_h.ac_command);
1169
1170         /*
1171            {
1172            tbd_t      tbd;
1173
1174            obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
1175            printk(" tbd_status=0x%x,", tbd.tbd_status);
1176            }
1177          */
1178
1179         printk("|");
1180 }
1181
1182 /*------------------------------------------------------------------*/
1183 /*
1184  * Print status of the command unit of the i82586.
1185  */
1186 static void wv_cu_show(struct net_device * dev)
1187 {
1188         net_local *lp = (net_local *) dev->priv;
1189         unsigned int i;
1190         u16 p;
1191
1192         printk(KERN_DEBUG
1193                "##### WaveLAN i82586 command unit status: #####\n");
1194
1195         printk(KERN_DEBUG);
1196         for (i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++) {
1197                 wv_cu_show_one(dev, lp, i, p);
1198
1199                 p += TXBLOCKZ;
1200                 if (p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
1201                         p -= NTXBLOCKS * TXBLOCKZ;
1202         }
1203         printk("\n");
1204 }
1205 #endif                          /* DEBUG_I82586_SHOW */
1206
1207 #ifdef DEBUG_DEVICE_SHOW
1208 /*------------------------------------------------------------------*/
1209 /*
1210  * Print the formatted status of the WaveLAN PCMCIA device driver.
1211  */
1212 static void wv_dev_show(struct net_device * dev)
1213 {
1214         printk(KERN_DEBUG "dev:");
1215         printk(" state=%lX,", dev->state);
1216         printk(" trans_start=%ld,", dev->trans_start);
1217         printk(" flags=0x%x,", dev->flags);
1218         printk("\n");
1219 }                               /* wv_dev_show */
1220
1221 /*------------------------------------------------------------------*/
1222 /*
1223  * Print the formatted status of the WaveLAN PCMCIA device driver's
1224  * private information.
1225  */
1226 static void wv_local_show(struct net_device * dev)
1227 {
1228         net_local *lp;
1229
1230         lp = (net_local *) dev->priv;
1231
1232         printk(KERN_DEBUG "local:");
1233         printk(" tx_n_in_use=%d,", lp->tx_n_in_use);
1234         printk(" hacr=0x%x,", lp->hacr);
1235         printk(" rx_head=0x%x,", lp->rx_head);
1236         printk(" rx_last=0x%x,", lp->rx_last);
1237         printk(" tx_first_free=0x%x,", lp->tx_first_free);
1238         printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use);
1239         printk("\n");
1240 }                               /* wv_local_show */
1241 #endif                          /* DEBUG_DEVICE_SHOW */
1242
1243 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1244 /*------------------------------------------------------------------*/
1245 /*
1246  * Dump packet header (and content if necessary) on the screen
1247  */
1248 static inline void wv_packet_info(u8 * p,       /* Packet to dump */
1249                                   int length,   /* Length of the packet */
1250                                   char *msg1,   /* Name of the device */
1251                                   char *msg2)
1252 {                               /* Name of the function */
1253         int i;
1254         int maxi;
1255
1256         printk(KERN_DEBUG
1257                "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1258                msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1259         printk(KERN_DEBUG
1260                "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1261                msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12],
1262                p[13]);
1263
1264 #ifdef DEBUG_PACKET_DUMP
1265
1266         printk(KERN_DEBUG "data=\"");
1267
1268         if ((maxi = length) > DEBUG_PACKET_DUMP)
1269                 maxi = DEBUG_PACKET_DUMP;
1270         for (i = 14; i < maxi; i++)
1271                 if (p[i] >= ' ' && p[i] <= '~')
1272                         printk(" %c", p[i]);
1273                 else
1274                         printk("%02X", p[i]);
1275         if (maxi < length)
1276                 printk("..");
1277         printk("\"\n");
1278         printk(KERN_DEBUG "\n");
1279 #endif                          /* DEBUG_PACKET_DUMP */
1280 }
1281 #endif                          /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1282
1283 /*------------------------------------------------------------------*/
1284 /*
1285  * This is the information which is displayed by the driver at startup.
1286  * There are lots of flags for configuring it to your liking.
1287  */
1288 static inline void wv_init_info(struct net_device * dev)
1289 {
1290         short ioaddr = dev->base_addr;
1291         net_local *lp = (net_local *) dev->priv;
1292         psa_t psa;
1293         int i;
1294
1295         /* Read the parameter storage area */
1296         psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
1297
1298 #ifdef DEBUG_PSA_SHOW
1299         wv_psa_show(&psa);
1300 #endif
1301 #ifdef DEBUG_MMC_SHOW
1302         wv_mmc_show(dev);
1303 #endif
1304 #ifdef DEBUG_I82586_SHOW
1305         wv_cu_show(dev);
1306 #endif
1307
1308 #ifdef DEBUG_BASIC_SHOW
1309         /* Now, let's go for the basic stuff. */
1310         printk(KERN_NOTICE "%s: WaveLAN at %#x,", dev->name, ioaddr);
1311         for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
1312                 printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1313         printk(", IRQ %d", dev->irq);
1314
1315         /* Print current network ID. */
1316         if (psa.psa_nwid_select)
1317                 printk(", nwid 0x%02X-%02X", psa.psa_nwid[0],
1318                        psa.psa_nwid[1]);
1319         else
1320                 printk(", nwid off");
1321
1322         /* If 2.00 card */
1323         if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1324               (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1325                 unsigned short freq;
1326
1327                 /* Ask the EEPROM to read the frequency from the first area. */
1328                 fee_read(ioaddr, 0x00, &freq, 1);
1329
1330                 /* Print frequency */
1331                 printk(", 2.00, %ld", (freq >> 6) + 2400L);
1332
1333                 /* Hack! */
1334                 if (freq & 0x20)
1335                         printk(".5");
1336         } else {
1337                 printk(", PC");
1338                 switch (psa.psa_comp_number) {
1339                 case PSA_COMP_PC_AT_915:
1340                 case PSA_COMP_PC_AT_2400:
1341                         printk("-AT");
1342                         break;
1343                 case PSA_COMP_PC_MC_915:
1344                 case PSA_COMP_PC_MC_2400:
1345                         printk("-MC");
1346                         break;
1347                 case PSA_COMP_PCMCIA_915:
1348                         printk("MCIA");
1349                         break;
1350                 default:
1351                         printk("?");
1352                 }
1353                 printk(", ");
1354                 switch (psa.psa_subband) {
1355                 case PSA_SUBBAND_915:
1356                         printk("915");
1357                         break;
1358                 case PSA_SUBBAND_2425:
1359                         printk("2425");
1360                         break;
1361                 case PSA_SUBBAND_2460:
1362                         printk("2460");
1363                         break;
1364                 case PSA_SUBBAND_2484:
1365                         printk("2484");
1366                         break;
1367                 case PSA_SUBBAND_2430_5:
1368                         printk("2430.5");
1369                         break;
1370                 default:
1371                         printk("?");
1372                 }
1373         }
1374
1375         printk(" MHz\n");
1376 #endif                          /* DEBUG_BASIC_SHOW */
1377
1378 #ifdef DEBUG_VERSION_SHOW
1379         /* Print version information */
1380         printk(KERN_NOTICE "%s", version);
1381 #endif
1382 }                               /* wv_init_info */
1383
1384 /********************* IOCTL, STATS & RECONFIG *********************/
1385 /*
1386  * We found here routines that are called by Linux on different
1387  * occasions after the configuration and not for transmitting data
1388  * These may be called when the user use ifconfig, /proc/net/dev
1389  * or wireless extensions
1390  */
1391
1392 /*------------------------------------------------------------------*/
1393 /*
1394  * Get the current Ethernet statistics. This may be called with the
1395  * card open or closed.
1396  * Used when the user read /proc/net/dev
1397  */
1398 static en_stats *wavelan_get_stats(struct net_device * dev)
1399 {
1400 #ifdef DEBUG_IOCTL_TRACE
1401         printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1402 #endif
1403
1404         return (&((net_local *) dev->priv)->stats);
1405 }
1406
1407 /*------------------------------------------------------------------*/
1408 /*
1409  * Set or clear the multicast filter for this adaptor.
1410  * num_addrs == -1      Promiscuous mode, receive all packets
1411  * num_addrs == 0       Normal mode, clear multicast list
1412  * num_addrs > 0        Multicast mode, receive normal and MC packets,
1413  *                      and do best-effort filtering.
1414  */
1415 static void wavelan_set_multicast_list(struct net_device * dev)
1416 {
1417         net_local *lp = (net_local *) dev->priv;
1418
1419 #ifdef DEBUG_IOCTL_TRACE
1420         printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n",
1421                dev->name);
1422 #endif
1423
1424 #ifdef DEBUG_IOCTL_INFO
1425         printk(KERN_DEBUG
1426                "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1427                dev->name, dev->flags, dev->mc_count);
1428 #endif
1429
1430         /* Are we asking for promiscuous mode,
1431          * or all multicast addresses (we don't have that!)
1432          * or too many multicast addresses for the hardware filter? */
1433         if ((dev->flags & IFF_PROMISC) ||
1434             (dev->flags & IFF_ALLMULTI) ||
1435             (dev->mc_count > I82586_MAX_MULTICAST_ADDRESSES)) {
1436                 /*
1437                  * Enable promiscuous mode: receive all packets.
1438                  */
1439                 if (!lp->promiscuous) {
1440                         lp->promiscuous = 1;
1441                         lp->mc_count = 0;
1442
1443                         wv_82586_reconfig(dev);
1444
1445                         /* Tell the kernel that we are doing a really bad job. */
1446                         dev->flags |= IFF_PROMISC;
1447                 }
1448         } else
1449                 /* Are there multicast addresses to send? */
1450         if (dev->mc_list != (struct dev_mc_list *) NULL) {
1451                 /*
1452                  * Disable promiscuous mode, but receive all packets
1453                  * in multicast list
1454                  */
1455 #ifdef MULTICAST_AVOID
1456                 if (lp->promiscuous || (dev->mc_count != lp->mc_count))
1457 #endif
1458                 {
1459                         lp->promiscuous = 0;
1460                         lp->mc_count = dev->mc_count;
1461
1462                         wv_82586_reconfig(dev);
1463                 }
1464         } else {
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                         lp->promiscuous = 0;
1471                         lp->mc_count = 0;
1472
1473                         wv_82586_reconfig(dev);
1474                 }
1475         }
1476 #ifdef DEBUG_IOCTL_TRACE
1477         printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n",
1478                dev->name);
1479 #endif
1480 }
1481
1482 /*------------------------------------------------------------------*/
1483 /*
1484  * This function doesn't exist.
1485  * (Note : it was a nice way to test the reconfigure stuff...)
1486  */
1487 #ifdef SET_MAC_ADDRESS
1488 static int wavelan_set_mac_address(struct net_device * dev, void *addr)
1489 {
1490         struct sockaddr *mac = addr;
1491
1492         /* Copy the address. */
1493         memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1494
1495         /* Reconfigure the beast. */
1496         wv_82586_reconfig(dev);
1497
1498         return 0;
1499 }
1500 #endif                          /* SET_MAC_ADDRESS */
1501
1502 #ifdef WIRELESS_EXT             /* if wireless extensions exist in the kernel */
1503
1504 /*------------------------------------------------------------------*/
1505 /*
1506  * Frequency setting (for hardware capable of it)
1507  * It's a bit complicated and you don't really want to look into it.
1508  * (called in wavelan_ioctl)
1509  */
1510 static inline int wv_set_frequency(unsigned long ioaddr,        /* I/O port of the card */
1511                                    iw_freq * frequency)
1512 {
1513         const int BAND_NUM = 10;        /* Number of bands */
1514         long freq = 0L;         /* offset to 2.4 GHz in .5 MHz */
1515 #ifdef DEBUG_IOCTL_INFO
1516         int i;
1517 #endif
1518
1519         /* Setting by frequency */
1520         /* Theoretically, you may set any frequency between
1521          * the two limits with a 0.5 MHz precision. In practice,
1522          * I don't want you to have trouble with local regulations.
1523          */
1524         if ((frequency->e == 1) &&
1525             (frequency->m >= (int) 2.412e8)
1526             && (frequency->m <= (int) 2.487e8)) {
1527                 freq = ((frequency->m / 10000) - 24000L) / 5;
1528         }
1529
1530         /* Setting by channel (same as wfreqsel) */
1531         /* Warning: each channel is 22 MHz wide, so some of the channels
1532          * will interfere. */
1533         if ((frequency->e == 0) && (frequency->m < BAND_NUM)) {
1534                 /* Get frequency offset. */
1535                 freq = channel_bands[frequency->m] >> 1;
1536         }
1537
1538         /* Verify that the frequency is allowed. */
1539         if (freq != 0L) {
1540                 u16 table[10];  /* Authorized frequency table */
1541
1542                 /* Read the frequency table. */
1543                 fee_read(ioaddr, 0x71, table, 10);
1544
1545 #ifdef DEBUG_IOCTL_INFO
1546                 printk(KERN_DEBUG "Frequency table: ");
1547                 for (i = 0; i < 10; i++) {
1548                         printk(" %04X", table[i]);
1549                 }
1550                 printk("\n");
1551 #endif
1552
1553                 /* Look in the table to see whether the frequency is allowed. */
1554                 if (!(table[9 - ((freq - 24) / 16)] &
1555                       (1 << ((freq - 24) % 16)))) return -EINVAL;       /* not allowed */
1556         } else
1557                 return -EINVAL;
1558
1559         /* if we get a usable frequency */
1560         if (freq != 0L) {
1561                 unsigned short area[16];
1562                 unsigned short dac[2];
1563                 unsigned short area_verify[16];
1564                 unsigned short dac_verify[2];
1565                 /* Corresponding gain (in the power adjust value table)
1566                  * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8
1567                  * and WCIN062D.DOC, page 6.2.9. */
1568                 unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1569                 int power_band = 0;     /* Selected band */
1570                 unsigned short power_adjust;    /* Correct value */
1571
1572                 /* Search for the gain. */
1573                 power_band = 0;
1574                 while ((freq > power_limit[power_band]) &&
1575                        (power_limit[++power_band] != 0));
1576
1577                 /* Read the first area. */
1578                 fee_read(ioaddr, 0x00, area, 16);
1579
1580                 /* Read the DAC. */
1581                 fee_read(ioaddr, 0x60, dac, 2);
1582
1583                 /* Read the new power adjust value. */
1584                 fee_read(ioaddr, 0x6B - (power_band >> 1), &power_adjust,
1585                          1);
1586                 if (power_band & 0x1)
1587                         power_adjust >>= 8;
1588                 else
1589                         power_adjust &= 0xFF;
1590
1591 #ifdef DEBUG_IOCTL_INFO
1592                 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1593                 for (i = 0; i < 16; i++) {
1594                         printk(" %04X", area[i]);
1595                 }
1596                 printk("\n");
1597
1598                 printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1599                        dac[0], dac[1]);
1600 #endif
1601
1602                 /* Frequency offset (for info only) */
1603                 area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1604
1605                 /* Receiver Principle main divider coefficient */
1606                 area[3] = (freq >> 1) + 2400L - 352L;
1607                 area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1608
1609                 /* Transmitter Main divider coefficient */
1610                 area[13] = (freq >> 1) + 2400L;
1611                 area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1612
1613                 /* Other parts of the area are flags, bit streams or unused. */
1614
1615                 /* Set the value in the DAC. */
1616                 dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1617                 dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1618
1619                 /* Write the first area. */
1620                 fee_write(ioaddr, 0x00, area, 16);
1621
1622                 /* Write the DAC. */
1623                 fee_write(ioaddr, 0x60, dac, 2);
1624
1625                 /* We now should verify here that the writing of the EEPROM went OK. */
1626
1627                 /* Reread the first area. */
1628                 fee_read(ioaddr, 0x00, area_verify, 16);
1629
1630                 /* Reread the DAC. */
1631                 fee_read(ioaddr, 0x60, dac_verify, 2);
1632
1633                 /* Compare. */
1634                 if (memcmp(area, area_verify, 16 * 2) ||
1635                     memcmp(dac, dac_verify, 2 * 2)) {
1636 #ifdef DEBUG_IOCTL_ERROR
1637                         printk(KERN_INFO
1638                                "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n");
1639 #endif
1640                         return -EOPNOTSUPP;
1641                 }
1642
1643                 /* We must download the frequency parameters to the
1644                  * synthesizers (from the EEPROM - area 1)
1645                  * Note: as the EEPROM is automatically decremented, we set the end
1646                  * if the area... */
1647                 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x0F);
1648                 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1649                         MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1650
1651                 /* Wait until the download is finished. */
1652                 fee_wait(ioaddr, 100, 100);
1653
1654                 /* We must now download the power adjust value (gain) to
1655                  * the synthesizers (from the EEPROM - area 7 - DAC). */
1656                 mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x61);
1657                 mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1658                         MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1659
1660                 /* Wait for the download to finish. */
1661                 fee_wait(ioaddr, 100, 100);
1662
1663 #ifdef DEBUG_IOCTL_INFO
1664                 /* Verification of what we have done */
1665
1666                 printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1667                 for (i = 0; i < 16; i++) {
1668                         printk(" %04X", area_verify[i]);
1669                 }
1670                 printk("\n");
1671
1672                 printk(KERN_DEBUG "WaveLAN EEPROM DAC:  %04X %04X\n",
1673                        dac_verify[0], dac_verify[1]);
1674 #endif
1675
1676                 return 0;
1677         } else
1678                 return -EINVAL; /* Bah, never get there... */
1679 }
1680
1681 /*------------------------------------------------------------------*/
1682 /*
1683  * Give the list of available frequencies.
1684  */
1685 static inline int wv_frequency_list(unsigned long ioaddr,       /* I/O port of the card */
1686                                     iw_freq * list,     /* List of frequencies to fill */
1687                                     int max)
1688 {                               /* Maximum number of frequencies */
1689         u16 table[10];  /* Authorized frequency table */
1690         long freq = 0L;         /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1691         int i;                  /* index in the table */
1692         int c = 0;              /* Channel number */
1693
1694         /* Read the frequency table. */
1695         fee_read(ioaddr, 0x71 /* frequency table */ , table, 10);
1696
1697         /* Check all frequencies. */
1698         i = 0;
1699         for (freq = 0; freq < 150; freq++)
1700                 /* Look in the table if the frequency is allowed */
1701                 if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
1702                         /* Compute approximate channel number */
1703                         while ((((channel_bands[c] >> 1) - 24) < freq) &&
1704                                (c < NELS(channel_bands)))
1705                                 c++;
1706                         list[i].i = c;  /* Set the list index */
1707
1708                         /* put in the list */
1709                         list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1710                         list[i++].e = 1;
1711
1712                         /* Check number. */
1713                         if (i >= max)
1714                                 return (i);
1715                 }
1716
1717         return (i);
1718 }
1719
1720 #ifdef IW_WIRELESS_SPY
1721 /*------------------------------------------------------------------*/
1722 /*
1723  * Gather wireless spy statistics:  for each packet, compare the source
1724  * address with our list, and if they match, get the statistics.
1725  * Sorry, but this function really needs the wireless extensions.
1726  */
1727 static inline void wl_spy_gather(struct net_device * dev,
1728                                  u8 *   mac,    /* MAC address */
1729                                  u8 *   stats)  /* Statistics to gather */
1730 {
1731         struct iw_quality wstats;
1732
1733         wstats.qual = stats[2] & MMR_SGNL_QUAL;
1734         wstats.level = stats[0] & MMR_SIGNAL_LVL;
1735         wstats.noise = stats[1] & MMR_SILENCE_LVL;
1736         wstats.updated = 0x7;
1737
1738         /* Update spy records */
1739         wireless_spy_update(dev, mac, &wstats);
1740 }
1741 #endif /* IW_WIRELESS_SPY */
1742
1743 #ifdef HISTOGRAM
1744 /*------------------------------------------------------------------*/
1745 /*
1746  * This function calculates a histogram of the signal level.
1747  * As the noise is quite constant, it's like doing it on the SNR.
1748  * We have defined a set of interval (lp->his_range), and each time
1749  * the level goes in that interval, we increment the count (lp->his_sum).
1750  * With this histogram you may detect if one WaveLAN is really weak,
1751  * or you may also calculate the mean and standard deviation of the level.
1752  */
1753 static inline void wl_his_gather(struct net_device * dev, u8 * stats)
1754 {                               /* Statistics to gather */
1755         net_local *lp = (net_local *) dev->priv;
1756         u8 level = stats[0] & MMR_SIGNAL_LVL;
1757         int i;
1758
1759         /* Find the correct interval. */
1760         i = 0;
1761         while ((i < (lp->his_number - 1))
1762                && (level >= lp->his_range[i++]));
1763
1764         /* Increment interval counter. */
1765         (lp->his_sum[i])++;
1766 }
1767 #endif /* HISTOGRAM */
1768
1769 /*------------------------------------------------------------------*/
1770 /*
1771  * Wireless Handler : get protocol name
1772  */
1773 static int wavelan_get_name(struct net_device *dev,
1774                             struct iw_request_info *info,
1775                             union iwreq_data *wrqu,
1776                             char *extra)
1777 {
1778         strcpy(wrqu->name, "WaveLAN");
1779         return 0;
1780 }
1781
1782 /*------------------------------------------------------------------*/
1783 /*
1784  * Wireless Handler : set NWID
1785  */
1786 static int wavelan_set_nwid(struct net_device *dev,
1787                             struct iw_request_info *info,
1788                             union iwreq_data *wrqu,
1789                             char *extra)
1790 {
1791         unsigned long ioaddr = dev->base_addr;
1792         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
1793         psa_t psa;
1794         mm_t m;
1795         unsigned long flags;
1796         int ret = 0;
1797
1798         /* Disable interrupts and save flags. */
1799         spin_lock_irqsave(&lp->spinlock, flags);
1800         
1801         /* Set NWID in WaveLAN. */
1802         if (!wrqu->nwid.disabled) {
1803                 /* Set NWID in psa */
1804                 psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
1805                 psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
1806                 psa.psa_nwid_select = 0x01;
1807                 psa_write(ioaddr, lp->hacr,
1808                           (char *) psa.psa_nwid - (char *) &psa,
1809                           (unsigned char *) psa.psa_nwid, 3);
1810
1811                 /* Set NWID in mmc. */
1812                 m.w.mmw_netw_id_l = psa.psa_nwid[1];
1813                 m.w.mmw_netw_id_h = psa.psa_nwid[0];
1814                 mmc_write(ioaddr,
1815                           (char *) &m.w.mmw_netw_id_l -
1816                           (char *) &m,
1817                           (unsigned char *) &m.w.mmw_netw_id_l, 2);
1818                 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), 0x00);
1819         } else {
1820                 /* Disable NWID in the psa. */
1821                 psa.psa_nwid_select = 0x00;
1822                 psa_write(ioaddr, lp->hacr,
1823                           (char *) &psa.psa_nwid_select -
1824                           (char *) &psa,
1825                           (unsigned char *) &psa.psa_nwid_select,
1826                           1);
1827
1828                 /* Disable NWID in the mmc (no filtering). */
1829                 mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel),
1830                         MMW_LOOPT_SEL_DIS_NWID);
1831         }
1832         /* update the Wavelan checksum */
1833         update_psa_checksum(dev, ioaddr, lp->hacr);
1834
1835         /* Enable interrupts and restore flags. */
1836         spin_unlock_irqrestore(&lp->spinlock, flags);
1837
1838         return ret;
1839 }
1840
1841 /*------------------------------------------------------------------*/
1842 /*
1843  * Wireless Handler : get NWID 
1844  */
1845 static int wavelan_get_nwid(struct net_device *dev,
1846                             struct iw_request_info *info,
1847                             union iwreq_data *wrqu,
1848                             char *extra)
1849 {
1850         unsigned long ioaddr = dev->base_addr;
1851         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
1852         psa_t psa;
1853         unsigned long flags;
1854         int ret = 0;
1855
1856         /* Disable interrupts and save flags. */
1857         spin_lock_irqsave(&lp->spinlock, flags);
1858         
1859         /* Read the NWID. */
1860         psa_read(ioaddr, lp->hacr,
1861                  (char *) psa.psa_nwid - (char *) &psa,
1862                  (unsigned char *) psa.psa_nwid, 3);
1863         wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1864         wrqu->nwid.disabled = !(psa.psa_nwid_select);
1865         wrqu->nwid.fixed = 1;   /* Superfluous */
1866
1867         /* Enable interrupts and restore flags. */
1868         spin_unlock_irqrestore(&lp->spinlock, flags);
1869
1870         return ret;
1871 }
1872
1873 /*------------------------------------------------------------------*/
1874 /*
1875  * Wireless Handler : set frequency
1876  */
1877 static int wavelan_set_freq(struct net_device *dev,
1878                             struct iw_request_info *info,
1879                             union iwreq_data *wrqu,
1880                             char *extra)
1881 {
1882         unsigned long ioaddr = dev->base_addr;
1883         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
1884         unsigned long flags;
1885         int ret;
1886
1887         /* Disable interrupts and save flags. */
1888         spin_lock_irqsave(&lp->spinlock, flags);
1889         
1890         /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1891         if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1892               (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1893                 ret = wv_set_frequency(ioaddr, &(wrqu->freq));
1894         else
1895                 ret = -EOPNOTSUPP;
1896
1897         /* Enable interrupts and restore flags. */
1898         spin_unlock_irqrestore(&lp->spinlock, flags);
1899
1900         return ret;
1901 }
1902
1903 /*------------------------------------------------------------------*/
1904 /*
1905  * Wireless Handler : get frequency
1906  */
1907 static int wavelan_get_freq(struct net_device *dev,
1908                             struct iw_request_info *info,
1909                             union iwreq_data *wrqu,
1910                             char *extra)
1911 {
1912         unsigned long ioaddr = dev->base_addr;
1913         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
1914         psa_t psa;
1915         unsigned long flags;
1916         int ret = 0;
1917
1918         /* Disable interrupts and save flags. */
1919         spin_lock_irqsave(&lp->spinlock, flags);
1920         
1921         /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
1922          * Does it work for everybody, especially old cards? */
1923         if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1924               (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1925                 unsigned short freq;
1926
1927                 /* Ask the EEPROM to read the frequency from the first area. */
1928                 fee_read(ioaddr, 0x00, &freq, 1);
1929                 wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
1930                 wrqu->freq.e = 1;
1931         } else {
1932                 psa_read(ioaddr, lp->hacr,
1933                          (char *) &psa.psa_subband - (char *) &psa,
1934                          (unsigned char *) &psa.psa_subband, 1);
1935
1936                 if (psa.psa_subband <= 4) {
1937                         wrqu->freq.m = fixed_bands[psa.psa_subband];
1938                         wrqu->freq.e = (psa.psa_subband != 0);
1939                 } else
1940                         ret = -EOPNOTSUPP;
1941         }
1942
1943         /* Enable interrupts and restore flags. */
1944         spin_unlock_irqrestore(&lp->spinlock, flags);
1945
1946         return ret;
1947 }
1948
1949 /*------------------------------------------------------------------*/
1950 /*
1951  * Wireless Handler : set level threshold
1952  */
1953 static int wavelan_set_sens(struct net_device *dev,
1954                             struct iw_request_info *info,
1955                             union iwreq_data *wrqu,
1956                             char *extra)
1957 {
1958         unsigned long ioaddr = dev->base_addr;
1959         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
1960         psa_t psa;
1961         unsigned long flags;
1962         int ret = 0;
1963
1964         /* Disable interrupts and save flags. */
1965         spin_lock_irqsave(&lp->spinlock, flags);
1966         
1967         /* Set the level threshold. */
1968         /* We should complain loudly if wrqu->sens.fixed = 0, because we
1969          * can't set auto mode... */
1970         psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
1971         psa_write(ioaddr, lp->hacr,
1972                   (char *) &psa.psa_thr_pre_set - (char *) &psa,
1973                   (unsigned char *) &psa.psa_thr_pre_set, 1);
1974         /* update the Wavelan checksum */
1975         update_psa_checksum(dev, ioaddr, lp->hacr);
1976         mmc_out(ioaddr, mmwoff(0, mmw_thr_pre_set),
1977                 psa.psa_thr_pre_set);
1978
1979         /* Enable interrupts and restore flags. */
1980         spin_unlock_irqrestore(&lp->spinlock, flags);
1981
1982         return ret;
1983 }
1984
1985 /*------------------------------------------------------------------*/
1986 /*
1987  * Wireless Handler : get level threshold
1988  */
1989 static int wavelan_get_sens(struct net_device *dev,
1990                             struct iw_request_info *info,
1991                             union iwreq_data *wrqu,
1992                             char *extra)
1993 {
1994         unsigned long ioaddr = dev->base_addr;
1995         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
1996         psa_t psa;
1997         unsigned long flags;
1998         int ret = 0;
1999
2000         /* Disable interrupts and save flags. */
2001         spin_lock_irqsave(&lp->spinlock, flags);
2002         
2003         /* Read the level threshold. */
2004         psa_read(ioaddr, lp->hacr,
2005                  (char *) &psa.psa_thr_pre_set - (char *) &psa,
2006                  (unsigned char *) &psa.psa_thr_pre_set, 1);
2007         wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
2008         wrqu->sens.fixed = 1;
2009
2010         /* Enable interrupts and restore flags. */
2011         spin_unlock_irqrestore(&lp->spinlock, flags);
2012
2013         return ret;
2014 }
2015
2016 /*------------------------------------------------------------------*/
2017 /*
2018  * Wireless Handler : set encryption key
2019  */
2020 static int wavelan_set_encode(struct net_device *dev,
2021                               struct iw_request_info *info,
2022                               union iwreq_data *wrqu,
2023                               char *extra)
2024 {
2025         unsigned long ioaddr = dev->base_addr;
2026         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
2027         unsigned long flags;
2028         psa_t psa;
2029         int ret = 0;
2030
2031         /* Disable interrupts and save flags. */
2032         spin_lock_irqsave(&lp->spinlock, flags);
2033
2034         /* Check if capable of encryption */
2035         if (!mmc_encr(ioaddr)) {
2036                 ret = -EOPNOTSUPP;
2037         }
2038
2039         /* Check the size of the key */
2040         if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
2041                 ret = -EINVAL;
2042         }
2043
2044         if(!ret) {
2045                 /* Basic checking... */
2046                 if (wrqu->encoding.length == 8) {
2047                         /* Copy the key in the driver */
2048                         memcpy(psa.psa_encryption_key, extra,
2049                                wrqu->encoding.length);
2050                         psa.psa_encryption_select = 1;
2051
2052                         psa_write(ioaddr, lp->hacr,
2053                                   (char *) &psa.psa_encryption_select -
2054                                   (char *) &psa,
2055                                   (unsigned char *) &psa.
2056                                   psa_encryption_select, 8 + 1);
2057
2058                         mmc_out(ioaddr, mmwoff(0, mmw_encr_enable),
2059                                 MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
2060                         mmc_write(ioaddr, mmwoff(0, mmw_encr_key),
2061                                   (unsigned char *) &psa.
2062                                   psa_encryption_key, 8);
2063                 }
2064
2065                 /* disable encryption */
2066                 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
2067                         psa.psa_encryption_select = 0;
2068                         psa_write(ioaddr, lp->hacr,
2069                                   (char *) &psa.psa_encryption_select -
2070                                   (char *) &psa,
2071                                   (unsigned char *) &psa.
2072                                   psa_encryption_select, 1);
2073
2074                         mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), 0);
2075                 }
2076                 /* update the Wavelan checksum */
2077                 update_psa_checksum(dev, ioaddr, lp->hacr);
2078         }
2079
2080         /* Enable interrupts and restore flags. */
2081         spin_unlock_irqrestore(&lp->spinlock, flags);
2082
2083         return ret;
2084 }
2085
2086 /*------------------------------------------------------------------*/
2087 /*
2088  * Wireless Handler : get encryption key
2089  */
2090 static int wavelan_get_encode(struct net_device *dev,
2091                               struct iw_request_info *info,
2092                               union iwreq_data *wrqu,
2093                               char *extra)
2094 {
2095         unsigned long ioaddr = dev->base_addr;
2096         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
2097         psa_t psa;
2098         unsigned long flags;
2099         int ret = 0;
2100
2101         /* Disable interrupts and save flags. */
2102         spin_lock_irqsave(&lp->spinlock, flags);
2103         
2104         /* Check if encryption is available */
2105         if (!mmc_encr(ioaddr)) {
2106                 ret = -EOPNOTSUPP;
2107         } else {
2108                 /* Read the encryption key */
2109                 psa_read(ioaddr, lp->hacr,
2110                          (char *) &psa.psa_encryption_select -
2111                          (char *) &psa,
2112                          (unsigned char *) &psa.
2113                          psa_encryption_select, 1 + 8);
2114
2115                 /* encryption is enabled ? */
2116                 if (psa.psa_encryption_select)
2117                         wrqu->encoding.flags = IW_ENCODE_ENABLED;
2118                 else
2119                         wrqu->encoding.flags = IW_ENCODE_DISABLED;
2120                 wrqu->encoding.flags |= mmc_encr(ioaddr);
2121
2122                 /* Copy the key to the user buffer */
2123                 wrqu->encoding.length = 8;
2124                 memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
2125         }
2126
2127         /* Enable interrupts and restore flags. */
2128         spin_unlock_irqrestore(&lp->spinlock, flags);
2129
2130         return ret;
2131 }
2132
2133 /*------------------------------------------------------------------*/
2134 /*
2135  * Wireless Handler : get range info
2136  */
2137 static int wavelan_get_range(struct net_device *dev,
2138                              struct iw_request_info *info,
2139                              union iwreq_data *wrqu,
2140                              char *extra)
2141 {
2142         unsigned long ioaddr = dev->base_addr;
2143         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
2144         struct iw_range *range = (struct iw_range *) extra;
2145         unsigned long flags;
2146         int ret = 0;
2147
2148         /* Set the length (very important for backward compatibility) */
2149         wrqu->data.length = sizeof(struct iw_range);
2150
2151         /* Set all the info we don't care or don't know about to zero */
2152         memset(range, 0, sizeof(struct iw_range));
2153
2154         /* Set the Wireless Extension versions */
2155         range->we_version_compiled = WIRELESS_EXT;
2156         range->we_version_source = 9;
2157
2158         /* Set information in the range struct.  */
2159         range->throughput = 1.6 * 1000 * 1000;  /* don't argue on this ! */
2160         range->min_nwid = 0x0000;
2161         range->max_nwid = 0xFFFF;
2162
2163         range->sensitivity = 0x3F;
2164         range->max_qual.qual = MMR_SGNL_QUAL;
2165         range->max_qual.level = MMR_SIGNAL_LVL;
2166         range->max_qual.noise = MMR_SILENCE_LVL;
2167         range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
2168         /* Need to get better values for those two */
2169         range->avg_qual.level = 30;
2170         range->avg_qual.noise = 8;
2171
2172         range->num_bitrates = 1;
2173         range->bitrate[0] = 2000000;    /* 2 Mb/s */
2174
2175         /* Event capability (kernel + driver) */
2176         range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
2177                                 IW_EVENT_CAPA_MASK(0x8B04));
2178         range->event_capa[1] = IW_EVENT_CAPA_K_1;
2179
2180         /* Disable interrupts and save flags. */
2181         spin_lock_irqsave(&lp->spinlock, flags);
2182         
2183         /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2184         if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2185               (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2186                 range->num_channels = 10;
2187                 range->num_frequency = wv_frequency_list(ioaddr, range->freq,
2188                                                         IW_MAX_FREQUENCIES);
2189         } else
2190                 range->num_channels = range->num_frequency = 0;
2191
2192         /* Encryption supported ? */
2193         if (mmc_encr(ioaddr)) {
2194                 range->encoding_size[0] = 8;    /* DES = 64 bits key */
2195                 range->num_encoding_sizes = 1;
2196                 range->max_encoding_tokens = 1; /* Only one key possible */
2197         } else {
2198                 range->num_encoding_sizes = 0;
2199                 range->max_encoding_tokens = 0;
2200         }
2201
2202         /* Enable interrupts and restore flags. */
2203         spin_unlock_irqrestore(&lp->spinlock, flags);
2204
2205         return ret;
2206 }
2207
2208 /*------------------------------------------------------------------*/
2209 /*
2210  * Wireless Private Handler : set quality threshold
2211  */
2212 static int wavelan_set_qthr(struct net_device *dev,
2213                             struct iw_request_info *info,
2214                             union iwreq_data *wrqu,
2215                             char *extra)
2216 {
2217         unsigned long ioaddr = dev->base_addr;
2218         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
2219         psa_t psa;
2220         unsigned long flags;
2221
2222         /* Disable interrupts and save flags. */
2223         spin_lock_irqsave(&lp->spinlock, flags);
2224         
2225         psa.psa_quality_thr = *(extra) & 0x0F;
2226         psa_write(ioaddr, lp->hacr,
2227                   (char *) &psa.psa_quality_thr - (char *) &psa,
2228                   (unsigned char *) &psa.psa_quality_thr, 1);
2229         /* update the Wavelan checksum */
2230         update_psa_checksum(dev, ioaddr, lp->hacr);
2231         mmc_out(ioaddr, mmwoff(0, mmw_quality_thr),
2232                 psa.psa_quality_thr);
2233
2234         /* Enable interrupts and restore flags. */
2235         spin_unlock_irqrestore(&lp->spinlock, flags);
2236
2237         return 0;
2238 }
2239
2240 /*------------------------------------------------------------------*/
2241 /*
2242  * Wireless Private Handler : get quality threshold
2243  */
2244 static int wavelan_get_qthr(struct net_device *dev,
2245                             struct iw_request_info *info,
2246                             union iwreq_data *wrqu,
2247                             char *extra)
2248 {
2249         unsigned long ioaddr = dev->base_addr;
2250         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
2251         psa_t psa;
2252         unsigned long flags;
2253
2254         /* Disable interrupts and save flags. */
2255         spin_lock_irqsave(&lp->spinlock, flags);
2256         
2257         psa_read(ioaddr, lp->hacr,
2258                  (char *) &psa.psa_quality_thr - (char *) &psa,
2259                  (unsigned char *) &psa.psa_quality_thr, 1);
2260         *(extra) = psa.psa_quality_thr & 0x0F;
2261
2262         /* Enable interrupts and restore flags. */
2263         spin_unlock_irqrestore(&lp->spinlock, flags);
2264
2265         return 0;
2266 }
2267
2268 #ifdef HISTOGRAM
2269 /*------------------------------------------------------------------*/
2270 /*
2271  * Wireless Private Handler : set histogram
2272  */
2273 static int wavelan_set_histo(struct net_device *dev,
2274                              struct iw_request_info *info,
2275                              union iwreq_data *wrqu,
2276                              char *extra)
2277 {
2278         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
2279
2280         /* Check the number of intervals. */
2281         if (wrqu->data.length > 16) {
2282                 return(-E2BIG);
2283         }
2284
2285         /* Disable histo while we copy the addresses.
2286          * As we don't disable interrupts, we need to do this */
2287         lp->his_number = 0;
2288
2289         /* Are there ranges to copy? */
2290         if (wrqu->data.length > 0) {
2291                 /* Copy interval ranges to the driver */
2292                 memcpy(lp->his_range, extra, wrqu->data.length);
2293
2294                 {
2295                   int i;
2296                   printk(KERN_DEBUG "Histo :");
2297                   for(i = 0; i < wrqu->data.length; i++)
2298                     printk(" %d", lp->his_range[i]);
2299                   printk("\n");
2300                 }
2301
2302                 /* Reset result structure. */
2303                 memset(lp->his_sum, 0x00, sizeof(long) * 16);
2304         }
2305
2306         /* Now we can set the number of ranges */
2307         lp->his_number = wrqu->data.length;
2308
2309         return(0);
2310 }
2311
2312 /*------------------------------------------------------------------*/
2313 /*
2314  * Wireless Private Handler : get histogram
2315  */
2316 static int wavelan_get_histo(struct net_device *dev,
2317                              struct iw_request_info *info,
2318                              union iwreq_data *wrqu,
2319                              char *extra)
2320 {
2321         net_local *lp = (net_local *) dev->priv;        /* lp is not unused */
2322
2323         /* Set the number of intervals. */
2324         wrqu->data.length = lp->his_number;
2325
2326         /* Give back the distribution statistics */
2327         if(lp->his_number > 0)
2328                 memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
2329
2330         return(0);
2331 }
2332 #endif                  /* HISTOGRAM */
2333
2334 /*------------------------------------------------------------------*/
2335 /*
2336  * Structures to export the Wireless Handlers
2337  */
2338
2339 static const iw_handler         wavelan_handler[] =
2340 {
2341         NULL,                           /* SIOCSIWNAME */
2342         wavelan_get_name,               /* SIOCGIWNAME */
2343         wavelan_set_nwid,               /* SIOCSIWNWID */
2344         wavelan_get_nwid,               /* SIOCGIWNWID */
2345         wavelan_set_freq,               /* SIOCSIWFREQ */
2346         wavelan_get_freq,               /* SIOCGIWFREQ */
2347         NULL,                           /* SIOCSIWMODE */
2348         NULL,                           /* SIOCGIWMODE */
2349         wavelan_set_sens,               /* SIOCSIWSENS */
2350         wavelan_get_sens,               /* SIOCGIWSENS */
2351         NULL,                           /* SIOCSIWRANGE */
2352         wavelan_get_range,              /* SIOCGIWRANGE */
2353         NULL,                           /* SIOCSIWPRIV */
2354         NULL,                           /* SIOCGIWPRIV */
2355         NULL,                           /* SIOCSIWSTATS */
2356         NULL,                           /* SIOCGIWSTATS */
2357         iw_handler_set_spy,             /* SIOCSIWSPY */
2358         iw_handler_get_spy,             /* SIOCGIWSPY */
2359         iw_handler_set_thrspy,          /* SIOCSIWTHRSPY */
2360         iw_handler_get_thrspy,          /* SIOCGIWTHRSPY */
2361         NULL,                           /* SIOCSIWAP */
2362         NULL,                           /* SIOCGIWAP */
2363         NULL,                           /* -- hole -- */
2364         NULL,                           /* SIOCGIWAPLIST */
2365         NULL,                           /* -- hole -- */
2366         NULL,                           /* -- hole -- */
2367         NULL,                           /* SIOCSIWESSID */
2368         NULL,                           /* SIOCGIWESSID */
2369         NULL,                           /* SIOCSIWNICKN */
2370         NULL,                           /* SIOCGIWNICKN */
2371         NULL,                           /* -- hole -- */
2372         NULL,                           /* -- hole -- */
2373         NULL,                           /* SIOCSIWRATE */
2374         NULL,                           /* SIOCGIWRATE */
2375         NULL,                           /* SIOCSIWRTS */
2376         NULL,                           /* SIOCGIWRTS */
2377         NULL,                           /* SIOCSIWFRAG */
2378         NULL,                           /* SIOCGIWFRAG */
2379         NULL,                           /* SIOCSIWTXPOW */
2380         NULL,                           /* SIOCGIWTXPOW */
2381         NULL,                           /* SIOCSIWRETRY */
2382         NULL,                           /* SIOCGIWRETRY */
2383         /* Bummer ! Why those are only at the end ??? */
2384         wavelan_set_encode,             /* SIOCSIWENCODE */
2385         wavelan_get_encode,             /* SIOCGIWENCODE */
2386 };
2387
2388 static const iw_handler         wavelan_private_handler[] =
2389 {
2390         wavelan_set_qthr,               /* SIOCIWFIRSTPRIV */
2391         wavelan_get_qthr,               /* SIOCIWFIRSTPRIV + 1 */
2392 #ifdef HISTOGRAM
2393         wavelan_set_histo,              /* SIOCIWFIRSTPRIV + 2 */
2394         wavelan_get_histo,              /* SIOCIWFIRSTPRIV + 3 */
2395 #endif  /* HISTOGRAM */
2396 };
2397
2398 static const struct iw_priv_args wavelan_private_args[] = {
2399 /*{ cmd,         set_args,                            get_args, name } */
2400   { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
2401   { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
2402   { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16,                    0, "sethisto" },
2403   { SIOCGIPHISTO, 0,                     IW_PRIV_TYPE_INT | 16, "gethisto" },
2404 };
2405
2406 static const struct iw_handler_def      wavelan_handler_def =
2407 {
2408         .num_standard   = sizeof(wavelan_handler)/sizeof(iw_handler),
2409         .num_private    = sizeof(wavelan_private_handler)/sizeof(iw_handler),
2410         .num_private_args = sizeof(wavelan_private_args)/sizeof(struct iw_priv_args),
2411         .standard       = wavelan_handler,
2412         .private        = wavelan_private_handler,
2413         .private_args   = wavelan_private_args,
2414         .get_wireless_stats = wavelan_get_wireless_stats,
2415 };
2416
2417 /*------------------------------------------------------------------*/
2418 /*
2419  * Get wireless statistics.
2420  * Called by /proc/net/wireless
2421  */
2422 static iw_stats *wavelan_get_wireless_stats(struct net_device * dev)
2423 {
2424         unsigned long ioaddr = dev->base_addr;
2425         net_local *lp = (net_local *) dev->priv;
2426         mmr_t m;
2427         iw_stats *wstats;
2428         unsigned long flags;
2429
2430 #ifdef DEBUG_IOCTL_TRACE
2431         printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n",
2432                dev->name);
2433 #endif
2434
2435         /* Check */
2436         if (lp == (net_local *) NULL)
2437                 return (iw_stats *) NULL;
2438         
2439         /* Disable interrupts and save flags. */
2440         spin_lock_irqsave(&lp->spinlock, flags);
2441         
2442         wstats = &lp->wstats;
2443
2444         /* Get data from the mmc. */
2445         mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2446
2447         mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2448         mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l,
2449                  2);
2450         mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set,
2451                  4);
2452
2453         mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2454
2455         /* Copy data to wireless stuff. */
2456         wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2457         wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2458         wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2459         wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2460         wstats->qual.updated = (((m. mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) 
2461                         | ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) 
2462                         | ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2463         wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2464         wstats->discard.code = 0L;
2465         wstats->discard.misc = 0L;
2466
2467         /* Enable interrupts and restore flags. */
2468         spin_unlock_irqrestore(&lp->spinlock, flags);
2469
2470 #ifdef DEBUG_IOCTL_TRACE
2471         printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n",
2472                dev->name);
2473 #endif
2474         return &lp->wstats;
2475 }
2476 #endif                          /* WIRELESS_EXT */
2477
2478 /************************* PACKET RECEPTION *************************/
2479 /*
2480  * This part deals with receiving the packets.
2481  * The interrupt handler gets an interrupt when a packet has been
2482  * successfully received and calls this part.
2483  */
2484
2485 /*------------------------------------------------------------------*/
2486 /*
2487  * This routine does the actual copying of data (including the Ethernet
2488  * header structure) from the WaveLAN card to an sk_buff chain that
2489  * will be passed up to the network interface layer. NOTE: we
2490  * currently don't handle trailer protocols (neither does the rest of
2491  * the network interface), so if that is needed, it will (at least in
2492  * part) be added here.  The contents of the receive ring buffer are
2493  * copied to a message chain that is then passed to the kernel.
2494  *
2495  * Note: if any errors occur, the packet is "dropped on the floor".
2496  * (called by wv_packet_rcv())
2497  */
2498 static inline void
2499 wv_packet_read(struct net_device * dev, u16 buf_off, int sksize)
2500 {
2501         net_local *lp = (net_local *) dev->priv;
2502         unsigned long ioaddr = dev->base_addr;
2503         struct sk_buff *skb;
2504
2505 #ifdef DEBUG_RX_TRACE
2506         printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2507                dev->name, buf_off, sksize);
2508 #endif
2509
2510         /* Allocate buffer for the data */
2511         if ((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL) {
2512 #ifdef DEBUG_RX_ERROR
2513                 printk(KERN_INFO
2514                        "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
2515                        dev->name, sksize);
2516 #endif
2517                 lp->stats.rx_dropped++;
2518                 return;
2519         }
2520
2521         skb->dev = dev;
2522
2523         /* Copy the packet to the buffer. */
2524         obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize);
2525         skb->protocol = eth_type_trans(skb, dev);
2526
2527 #ifdef DEBUG_RX_INFO
2528         wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2529 #endif                          /* DEBUG_RX_INFO */
2530
2531         /* Statistics-gathering and associated stuff.
2532          * It seem a bit messy with all the define, but it's really
2533          * simple... */
2534         if (
2535 #ifdef IW_WIRELESS_SPY          /* defined in iw_handler.h */
2536                    (lp->spy_data.spy_number > 0) ||
2537 #endif /* IW_WIRELESS_SPY */
2538 #ifdef HISTOGRAM
2539                    (lp->his_number > 0) ||
2540 #endif /* HISTOGRAM */
2541                    0) {
2542                 u8 stats[3];    /* signal level, noise level, signal quality */
2543
2544                 /* Read signal level, silence level and signal quality bytes */
2545                 /* Note: in the PCMCIA hardware, these are part of the frame.
2546                  * It seems that for the ISA hardware, it's nowhere to be
2547                  * found in the frame, so I'm obliged to do this (it has a
2548                  * side effect on /proc/net/wireless).
2549                  * Any ideas?
2550                  */
2551                 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2552                 mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3);
2553                 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2554
2555 #ifdef DEBUG_RX_INFO
2556                 printk(KERN_DEBUG
2557                        "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2558                        dev->name, stats[0] & 0x3F, stats[1] & 0x3F,
2559                        stats[2] & 0x0F);
2560 #endif
2561
2562                 /* Spying stuff */
2563 #ifdef IW_WIRELESS_SPY
2564                 wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE,
2565                               stats);
2566 #endif /* IW_WIRELESS_SPY */
2567 #ifdef HISTOGRAM
2568                 wl_his_gather(dev, stats);
2569 #endif /* HISTOGRAM */
2570         }
2571
2572         /*
2573          * Hand the packet to the network module.
2574          */
2575         netif_rx(skb);
2576
2577         /* Keep statistics up to date */
2578         dev->last_rx = jiffies;
2579         lp->stats.rx_packets++;
2580         lp->stats.rx_bytes += sksize;
2581
2582 #ifdef DEBUG_RX_TRACE
2583         printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2584 #endif
2585 }
2586
2587 /*------------------------------------------------------------------*/
2588 /*
2589  * Transfer as many packets as we can
2590  * from the device RAM.
2591  * (called in wavelan_interrupt()).
2592  * Note : the spinlock is already grabbed for us.
2593  */
2594 static inline void wv_receive(struct net_device * dev)
2595 {
2596         unsigned long ioaddr = dev->base_addr;
2597         net_local *lp = (net_local *) dev->priv;
2598         fd_t fd;
2599         rbd_t rbd;
2600         int nreaped = 0;
2601
2602 #ifdef DEBUG_RX_TRACE
2603         printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name);
2604 #endif
2605
2606         /* Loop on each received packet. */
2607         for (;;) {
2608                 obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd,
2609                            sizeof(fd));
2610
2611                 /* Note about the status :
2612                  * It start up to be 0 (the value we set). Then, when the RU
2613                  * grab the buffer to prepare for reception, it sets the
2614                  * FD_STATUS_B flag. When the RU has finished receiving the
2615                  * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
2616                  * completion and set the other flags to indicate the eventual
2617                  * errors. FD_STATUS_OK indicates that the reception was OK.
2618                  */
2619
2620                 /* If the current frame is not complete, we have reached the end. */
2621                 if ((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
2622                         break;  /* This is how we exit the loop. */
2623
2624                 nreaped++;
2625
2626                 /* Check whether frame was correctly received. */
2627                 if ((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK) {
2628                         /* Does the frame contain a pointer to the data?  Let's check. */
2629                         if (fd.fd_rbd_offset != I82586NULL) {
2630                                 /* Read the receive buffer descriptor */
2631                                 obram_read(ioaddr, fd.fd_rbd_offset,
2632                                            (unsigned char *) &rbd,
2633                                            sizeof(rbd));
2634
2635 #ifdef DEBUG_RX_ERROR
2636                                 if ((rbd.rbd_status & RBD_STATUS_EOF) !=
2637                                     RBD_STATUS_EOF) printk(KERN_INFO
2638                                                            "%s: wv_receive(): missing EOF flag.\n",
2639                                                            dev->name);
2640
2641                                 if ((rbd.rbd_status & RBD_STATUS_F) !=
2642                                     RBD_STATUS_F) printk(KERN_INFO
2643                                                          "%s: wv_receive(): missing F flag.\n",
2644                                                          dev->name);
2645 #endif                          /* DEBUG_RX_ERROR */
2646
2647                                 /* Read the packet and transmit to Linux */
2648                                 wv_packet_read(dev, rbd.rbd_bufl,
2649                                                rbd.
2650                                                rbd_status &
2651                                                RBD_STATUS_ACNT);
2652                         }
2653 #ifdef DEBUG_RX_ERROR
2654                         else    /* if frame has no data */
2655                                 printk(KERN_INFO
2656                                        "%s: wv_receive(): frame has no data.\n",
2657                                        dev->name);
2658 #endif
2659                 } else {        /* If reception was no successful */
2660
2661                         lp->stats.rx_errors++;
2662
2663 #ifdef DEBUG_RX_INFO
2664                         printk(KERN_DEBUG
2665                                "%s: wv_receive(): frame not received successfully (%X).\n",
2666                                dev->name, fd.fd_status);
2667 #endif
2668
2669 #ifdef DEBUG_RX_ERROR
2670                         if ((fd.fd_status & FD_STATUS_S6) != 0)
2671                                 printk(KERN_INFO
2672                                        "%s: wv_receive(): no EOF flag.\n",
2673                                        dev->name);
2674 #endif
2675
2676                         if ((fd.fd_status & FD_STATUS_S7) != 0) {
2677                                 lp->stats.rx_length_errors++;
2678 #ifdef DEBUG_RX_FAIL
2679                                 printk(KERN_DEBUG
2680                                        "%s: wv_receive(): frame too short.\n",
2681                                        dev->name);
2682 #endif
2683                         }
2684
2685                         if ((fd.fd_status & FD_STATUS_S8) != 0) {
2686                                 lp->stats.rx_over_errors++;
2687 #ifdef DEBUG_RX_FAIL
2688                                 printk(KERN_DEBUG
2689                                        "%s: wv_receive(): rx DMA overrun.\n",
2690                                        dev->name);
2691 #endif
2692                         }
2693
2694                         if ((fd.fd_status & FD_STATUS_S9) != 0) {
2695                                 lp->stats.rx_fifo_errors++;
2696 #ifdef DEBUG_RX_FAIL
2697                                 printk(KERN_DEBUG
2698                                        "%s: wv_receive(): ran out of resources.\n",
2699                                        dev->name);
2700 #endif
2701                         }
2702
2703                         if ((fd.fd_status & FD_STATUS_S10) != 0) {
2704                                 lp->stats.rx_frame_errors++;
2705 #ifdef DEBUG_RX_FAIL
2706                                 printk(KERN_DEBUG
2707                                        "%s: wv_receive(): alignment error.\n",
2708                                        dev->name);
2709 #endif
2710                         }
2711
2712                         if ((fd.fd_status & FD_STATUS_S11) != 0) {
2713                                 lp->stats.rx_crc_errors++;
2714 #ifdef DEBUG_RX_FAIL
2715                                 printk(KERN_DEBUG
2716                                        "%s: wv_receive(): CRC error.\n",
2717                                        dev->name);
2718 #endif
2719                         }
2720                 }
2721
2722                 fd.fd_status = 0;
2723                 obram_write(ioaddr, fdoff(lp->rx_head, fd_status),
2724                             (unsigned char *) &fd.fd_status,
2725                             sizeof(fd.fd_status));
2726
2727                 fd.fd_command = FD_COMMAND_EL;
2728                 obram_write(ioaddr, fdoff(lp->rx_head, fd_command),
2729                             (unsigned char *) &fd.fd_command,
2730                             sizeof(fd.fd_command));
2731
2732                 fd.fd_command = 0;
2733                 obram_write(ioaddr, fdoff(lp->rx_last, fd_command),
2734                             (unsigned char *) &fd.fd_command,
2735                             sizeof(fd.fd_command));
2736
2737                 lp->rx_last = lp->rx_head;
2738                 lp->rx_head = fd.fd_link_offset;
2739         }                       /* for(;;) -> loop on all frames */
2740
2741 #ifdef DEBUG_RX_INFO
2742         if (nreaped > 1)
2743                 printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n",
2744                        dev->name, nreaped);
2745 #endif
2746 #ifdef DEBUG_RX_TRACE
2747         printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name);
2748 #endif
2749 }
2750
2751 /*********************** PACKET TRANSMISSION ***********************/
2752 /*
2753  * This part deals with sending packets through the WaveLAN.
2754  *
2755  */
2756
2757 /*------------------------------------------------------------------*/
2758 /*
2759  * This routine fills in the appropriate registers and memory
2760  * locations on the WaveLAN card and starts the card off on
2761  * the transmit.
2762  *
2763  * The principle:
2764  * Each block contains a transmit command, a NOP command,
2765  * a transmit block descriptor and a buffer.
2766  * The CU read the transmit block which point to the tbd,
2767  * read the tbd and the content of the buffer.
2768  * When it has finish with it, it goes to the next command
2769  * which in our case is the NOP. The NOP points on itself,
2770  * so the CU stop here.
2771  * When we add the next block, we modify the previous nop
2772  * to make it point on the new tx command.
2773  * Simple, isn't it ?
2774  *
2775  * (called in wavelan_packet_xmit())
2776  */
2777 static inline int wv_packet_write(struct net_device * dev, void *buf, short length)
2778 {
2779         net_local *lp = (net_local *) dev->priv;
2780         unsigned long ioaddr = dev->base_addr;
2781         unsigned short txblock;
2782         unsigned short txpred;
2783         unsigned short tx_addr;
2784         unsigned short nop_addr;
2785         unsigned short tbd_addr;
2786         unsigned short buf_addr;
2787         ac_tx_t tx;
2788         ac_nop_t nop;
2789         tbd_t tbd;
2790         int clen = length;
2791         unsigned long flags;
2792
2793 #ifdef DEBUG_TX_TRACE
2794         printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name,
2795                length);
2796 #endif
2797
2798         spin_lock_irqsave(&lp->spinlock, flags);
2799
2800         /* Check nothing bad has happened */
2801         if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
2802 #ifdef DEBUG_TX_ERROR
2803                 printk(KERN_INFO "%s: wv_packet_write(): Tx queue full.\n",
2804                        dev->name);
2805 #endif
2806                 spin_unlock_irqrestore(&lp->spinlock, flags);
2807                 return 1;
2808         }
2809
2810         /* Calculate addresses of next block and previous block. */
2811         txblock = lp->tx_first_free;
2812         txpred = txblock - TXBLOCKZ;
2813         if (txpred < OFFSET_CU)
2814                 txpred += NTXBLOCKS * TXBLOCKZ;
2815         lp->tx_first_free += TXBLOCKZ;
2816         if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
2817                 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
2818
2819         lp->tx_n_in_use++;
2820
2821         /* Calculate addresses of the different parts of the block. */
2822         tx_addr = txblock;
2823         nop_addr = tx_addr + sizeof(tx);
2824         tbd_addr = nop_addr + sizeof(nop);
2825         buf_addr = tbd_addr + sizeof(tbd);
2826
2827         /*
2828          * Transmit command
2829          */
2830         tx.tx_h.ac_status = 0;
2831         obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
2832                     (unsigned char *) &tx.tx_h.ac_status,
2833                     sizeof(tx.tx_h.ac_status));
2834
2835         /*
2836          * NOP command
2837          */
2838         nop.nop_h.ac_status = 0;
2839         obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2840                     (unsigned char *) &nop.nop_h.ac_status,
2841                     sizeof(nop.nop_h.ac_status));
2842         nop.nop_h.ac_link = nop_addr;
2843         obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2844                     (unsigned char *) &nop.nop_h.ac_link,
2845                     sizeof(nop.nop_h.ac_link));
2846
2847         /*
2848          * Transmit buffer descriptor
2849          */
2850         tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen);
2851         tbd.tbd_next_bd_offset = I82586NULL;
2852         tbd.tbd_bufl = buf_addr;
2853         tbd.tbd_bufh = 0;
2854         obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd));
2855
2856         /*
2857          * Data
2858          */
2859         obram_write(ioaddr, buf_addr, buf, length);
2860
2861         /*
2862          * Overwrite the predecessor NOP link
2863          * so that it points to this txblock.
2864          */
2865         nop_addr = txpred + sizeof(tx);
2866         nop.nop_h.ac_status = 0;
2867         obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2868                     (unsigned char *) &nop.nop_h.ac_status,
2869                     sizeof(nop.nop_h.ac_status));
2870         nop.nop_h.ac_link = txblock;
2871         obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2872                     (unsigned char *) &nop.nop_h.ac_link,
2873                     sizeof(nop.nop_h.ac_link));
2874
2875         /* Make sure the watchdog will keep quiet for a while */
2876         dev->trans_start = jiffies;
2877
2878         /* Keep stats up to date. */
2879         lp->stats.tx_bytes += length;
2880
2881         if (lp->tx_first_in_use == I82586NULL)
2882                 lp->tx_first_in_use = txblock;
2883
2884         if (lp->tx_n_in_use < NTXBLOCKS - 1)
2885                 netif_wake_queue(dev);
2886
2887         spin_unlock_irqrestore(&lp->spinlock, flags);
2888         
2889 #ifdef DEBUG_TX_INFO
2890         wv_packet_info((u8 *) buf, length, dev->name,
2891                        "wv_packet_write");
2892 #endif                          /* DEBUG_TX_INFO */
2893
2894 #ifdef DEBUG_TX_TRACE
2895         printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
2896 #endif
2897
2898         return 0;
2899 }
2900
2901 /*------------------------------------------------------------------*/
2902 /*
2903  * This routine is called when we want to send a packet (NET3 callback)
2904  * In this routine, we check if the harware is ready to accept
2905  * the packet.  We also prevent reentrance.  Then we call the function
2906  * to send the packet.
2907  */
2908 static int wavelan_packet_xmit(struct sk_buff *skb, struct net_device * dev)
2909 {
2910         net_local *lp = (net_local *) dev->priv;
2911         unsigned long flags;
2912
2913 #ifdef DEBUG_TX_TRACE
2914         printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
2915                (unsigned) skb);
2916 #endif
2917
2918         /*
2919          * Block a timer-based transmit from overlapping.
2920          * In other words, prevent reentering this routine.
2921          */
2922         netif_stop_queue(dev);
2923
2924         /* If somebody has asked to reconfigure the controller, 
2925          * we can do it now.
2926          */
2927         if (lp->reconfig_82586) {
2928                 spin_lock_irqsave(&lp->spinlock, flags);
2929                 wv_82586_config(dev);
2930                 spin_unlock_irqrestore(&lp->spinlock, flags);
2931                 /* Check that we can continue */
2932                 if (lp->tx_n_in_use == (NTXBLOCKS - 1))
2933                         return 1;
2934         }
2935 #ifdef DEBUG_TX_ERROR
2936         if (skb->next)
2937                 printk(KERN_INFO "skb has next\n");
2938 #endif
2939
2940         /* Do we need some padding? */
2941         /* Note : on wireless the propagation time is in the order of 1us,
2942          * and we don't have the Ethernet specific requirement of beeing
2943          * able to detect collisions, therefore in theory we don't really
2944          * need to pad. Jean II */
2945         if (skb->len < ETH_ZLEN) {
2946                 skb = skb_padto(skb, ETH_ZLEN);
2947                 if (skb == NULL)
2948                         return 0;
2949         }
2950
2951         /* Write packet on the card */
2952         if(wv_packet_write(dev, skb->data, skb->len))
2953                 return 1;       /* We failed */
2954
2955         dev_kfree_skb(skb);
2956
2957 #ifdef DEBUG_TX_TRACE
2958         printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
2959 #endif
2960         return 0;
2961 }
2962
2963 /*********************** HARDWARE CONFIGURATION ***********************/
2964 /*
2965  * This part does the real job of starting and configuring the hardware.
2966  */
2967
2968 /*--------------------------------------------------------------------*/
2969 /*
2970  * Routine to initialize the Modem Management Controller.
2971  * (called by wv_hw_reset())
2972  */
2973 static inline int wv_mmc_init(struct net_device * dev)
2974 {
2975         unsigned long ioaddr = dev->base_addr;
2976         net_local *lp = (net_local *) dev->priv;
2977         psa_t psa;
2978         mmw_t m;
2979         int configured;
2980
2981 #ifdef DEBUG_CONFIG_TRACE
2982         printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
2983 #endif
2984
2985         /* Read the parameter storage area. */
2986         psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
2987
2988 #ifdef USE_PSA_CONFIG
2989         configured = psa.psa_conf_status & 1;
2990 #else
2991         configured = 0;
2992 #endif
2993
2994         /* Is the PSA is not configured */
2995         if (!configured) {
2996                 /* User will be able to configure NWID later (with iwconfig). */
2997                 psa.psa_nwid[0] = 0;
2998                 psa.psa_nwid[1] = 0;
2999
3000                 /* no NWID checking since NWID is not set */
3001                 psa.psa_nwid_select = 0;
3002
3003                 /* Disable encryption */
3004                 psa.psa_encryption_select = 0;
3005
3006                 /* Set to standard values:
3007                  * 0x04 for AT,
3008                  * 0x01 for MCA,
3009                  * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
3010                  */
3011                 if (psa.psa_comp_number & 1)
3012                         psa.psa_thr_pre_set = 0x01;
3013                 else
3014                         psa.psa_thr_pre_set = 0x04;
3015                 psa.psa_quality_thr = 0x03;
3016
3017                 /* It is configured */
3018                 psa.psa_conf_status |= 1;
3019
3020 #ifdef USE_PSA_CONFIG
3021                 /* Write the psa. */
3022                 psa_write(ioaddr, lp->hacr,
3023                           (char *) psa.psa_nwid - (char *) &psa,
3024                           (unsigned char *) psa.psa_nwid, 4);
3025                 psa_write(ioaddr, lp->hacr,
3026                           (char *) &psa.psa_thr_pre_set - (char *) &psa,
3027                           (unsigned char *) &psa.psa_thr_pre_set, 1);
3028                 psa_write(ioaddr, lp->hacr,
3029                           (char *) &psa.psa_quality_thr - (char *) &psa,
3030                           (unsigned char *) &psa.psa_quality_thr, 1);
3031                 psa_write(ioaddr, lp->hacr,
3032                           (char *) &psa.psa_conf_status - (char *) &psa,
3033                           (unsigned char *) &psa.psa_conf_status, 1);
3034                 /* update the Wavelan checksum */
3035                 update_psa_checksum(dev, ioaddr, lp->hacr);
3036 #endif
3037         }
3038
3039         /* Zero the mmc structure. */
3040         memset(&m, 0x00, sizeof(m));
3041
3042         /* Copy PSA info to the mmc. */
3043         m.mmw_netw_id_l = psa.psa_nwid[1];
3044         m.mmw_netw_id_h = psa.psa_nwid[0];
3045
3046         if (psa.psa_nwid_select & 1)
3047                 m.mmw_loopt_sel = 0x00;
3048         else
3049                 m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
3050
3051         memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
3052                sizeof(m.mmw_encr_key));
3053
3054         if (psa.psa_encryption_select)
3055                 m.mmw_encr_enable =
3056                     MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
3057         else
3058                 m.mmw_encr_enable = 0;
3059
3060         m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
3061         m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
3062
3063         /*
3064          * Set default modem control parameters.
3065          * See NCR document 407-0024326 Rev. A.
3066          */
3067         m.mmw_jabber_enable = 0x01;
3068         m.mmw_freeze = 0;
3069         m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
3070         m.mmw_ifs = 0x20;
3071         m.mmw_mod_delay = 0x04;
3072         m.mmw_jam_time = 0x38;
3073
3074         m.mmw_des_io_invert = 0;
3075         m.mmw_decay_prm = 0;
3076         m.mmw_decay_updat_prm = 0;
3077
3078         /* Write all info to MMC. */
3079         mmc_write(ioaddr, 0, (u8 *) & m, sizeof(m));
3080
3081         /* The following code starts the modem of the 2.00 frequency
3082          * selectable cards at power on.  It's not strictly needed for the
3083          * following boots.
3084          * The original patch was by Joe Finney for the PCMCIA driver, but
3085          * I've cleaned it up a bit and added documentation.
3086          * Thanks to Loeke Brederveld from Lucent for the info.
3087          */
3088
3089         /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3090          * Does it work for everybody, especially old cards? */
3091         /* Note: WFREQSEL verifies that it is able to read a sensible
3092          * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
3093          * is 0xA (Xilinx version) or 0xB (Ariadne version).
3094          * My test is more crude but does work. */
3095         if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
3096               (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
3097                 /* We must download the frequency parameters to the
3098                  * synthesizers (from the EEPROM - area 1)
3099                  * Note: as the EEPROM is automatically decremented, we set the end
3100                  * if the area... */
3101                 m.mmw_fee_addr = 0x0F;
3102                 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3103                 mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
3104                           (unsigned char *) &m.mmw_fee_ctrl, 2);
3105
3106                 /* Wait until the download is finished. */
3107                 fee_wait(ioaddr, 100, 100);
3108
3109 #ifdef DEBUG_CONFIG_INFO
3110                 /* The frequency was in the last word downloaded. */
3111                 mmc_read(ioaddr, (char *) &m.mmw_fee_data_l - (char *) &m,
3112                          (unsigned char *) &m.mmw_fee_data_l, 2);
3113
3114                 /* Print some info for the user. */
3115                 printk(KERN_DEBUG
3116                        "%s: WaveLAN 2.00 recognised (frequency select).  Current frequency = %ld\n",
3117                        dev->name,
3118                        ((m.
3119                          mmw_fee_data_h << 4) | (m.mmw_fee_data_l >> 4)) *
3120                        5 / 2 + 24000L);
3121 #endif
3122
3123                 /* We must now download the power adjust value (gain) to
3124                  * the synthesizers (from the EEPROM - area 7 - DAC). */
3125                 m.mmw_fee_addr = 0x61;
3126                 m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3127                 mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
3128                           (unsigned char *) &m.mmw_fee_ctrl, 2);
3129
3130                 /* Wait until the download is finished. */
3131         }
3132         /* if 2.00 card */
3133 #ifdef DEBUG_CONFIG_TRACE
3134         printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3135 #endif
3136         return 0;
3137 }
3138
3139 /*------------------------------------------------------------------*/
3140 /*
3141  * Construct the fd and rbd structures.
3142  * Start the receive unit.
3143  * (called by wv_hw_reset())
3144  */
3145 static inline int wv_ru_start(struct net_device * dev)
3146 {
3147         net_local *lp = (net_local *) dev->priv;
3148         unsigned long ioaddr = dev->base_addr;
3149         u16 scb_cs;
3150         fd_t fd;
3151         rbd_t rbd;
3152         u16 rx;
3153         u16 rx_next;
3154         int i;
3155
3156 #ifdef DEBUG_CONFIG_TRACE
3157         printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3158 #endif
3159
3160         obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3161                    (unsigned char *) &scb_cs, sizeof(scb_cs));
3162         if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
3163                 return 0;
3164
3165         lp->rx_head = OFFSET_RU;
3166
3167         for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next) {
3168                 rx_next =
3169                     (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
3170
3171                 fd.fd_status = 0;
3172                 fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
3173                 fd.fd_link_offset = rx_next;
3174                 fd.fd_rbd_offset = rx + sizeof(fd);
3175                 obram_write(ioaddr, rx, (unsigned char *) &fd, sizeof(fd));
3176
3177                 rbd.rbd_status = 0;
3178                 rbd.rbd_next_rbd_offset = I82586NULL;
3179                 rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
3180                 rbd.rbd_bufh = 0;
3181                 rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
3182                 obram_write(ioaddr, rx + sizeof(fd),
3183                             (unsigned char *) &rbd, sizeof(rbd));
3184
3185                 lp->rx_last = rx;
3186         }
3187
3188         obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
3189                     (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
3190
3191         scb_cs = SCB_CMD_RUC_GO;
3192         obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3193                     (unsigned char *) &scb_cs, sizeof(scb_cs));
3194
3195         set_chan_attn(ioaddr, lp->hacr);
3196
3197         for (i = 1000; i > 0; i--) {
3198                 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3199                            (unsigned char *) &scb_cs, sizeof(scb_cs));
3200                 if (scb_cs == 0)
3201                         break;
3202
3203                 udelay(10);
3204         }
3205
3206         if (i <= 0) {
3207 #ifdef DEBUG_CONFIG_ERROR
3208                 printk(KERN_INFO
3209                        "%s: wavelan_ru_start(): board not accepting command.\n",
3210                        dev->name);
3211 #endif
3212                 return -1;
3213         }
3214 #ifdef DEBUG_CONFIG_TRACE
3215         printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3216 #endif
3217         return 0;
3218 }
3219
3220 /*------------------------------------------------------------------*/
3221 /*
3222  * Initialise the transmit blocks.
3223  * Start the command unit executing the NOP
3224  * self-loop of the first transmit block.
3225  *
3226  * Here we create the list of send buffers used to transmit packets
3227  * between the PC and the command unit. For each buffer, we create a
3228  * buffer descriptor (pointing on the buffer), a transmit command
3229  * (pointing to the buffer descriptor) and a NOP command.
3230  * The transmit command is linked to the NOP, and the NOP to itself.
3231  * When we will have finished executing the transmit command, we will
3232  * then loop on the NOP. By releasing the NOP link to a new command,
3233  * we may send another buffer.
3234  *
3235  * (called by wv_hw_reset())
3236  */
3237 static inline int wv_cu_start(struct net_device * dev)
3238 {
3239         net_local *lp = (net_local *) dev->priv;
3240         unsigned long ioaddr = dev->base_addr;
3241         int i;
3242         u16 txblock;
3243         u16 first_nop;
3244         u16 scb_cs;
3245
3246 #ifdef DEBUG_CONFIG_TRACE
3247         printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
3248 #endif
3249
3250         lp->tx_first_free = OFFSET_CU;
3251         lp->tx_first_in_use = I82586NULL;
3252
3253         for (i = 0, txblock = OFFSET_CU;
3254              i < NTXBLOCKS; i++, txblock += TXBLOCKZ) {
3255                 ac_tx_t tx;
3256                 ac_nop_t nop;
3257                 tbd_t tbd;
3258                 unsigned short tx_addr;
3259                 unsigned short nop_addr;
3260                 unsigned short tbd_addr;
3261                 unsigned short buf_addr;
3262
3263                 tx_addr = txblock;
3264                 nop_addr = tx_addr + sizeof(tx);
3265                 tbd_addr = nop_addr + sizeof(nop);
3266                 buf_addr = tbd_addr + sizeof(tbd);
3267
3268                 tx.tx_h.ac_status = 0;
3269                 tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
3270                 tx.tx_h.ac_link = nop_addr;
3271                 tx.tx_tbd_offset = tbd_addr;
3272                 obram_write(ioaddr, tx_addr, (unsigned char *) &tx,
3273                             sizeof(tx));
3274
3275                 nop.nop_h.ac_status = 0;
3276                 nop.nop_h.ac_command = acmd_nop;
3277                 nop.nop_h.ac_link = nop_addr;
3278                 obram_write(ioaddr, nop_addr, (unsigned char *) &nop,
3279                             sizeof(nop));
3280
3281                 tbd.tbd_status = TBD_STATUS_EOF;
3282                 tbd.tbd_next_bd_offset = I82586NULL;
3283                 tbd.tbd_bufl = buf_addr;
3284                 tbd.tbd_bufh = 0;
3285                 obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd,
3286                             sizeof(tbd));
3287         }
3288
3289         first_nop =
3290             OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
3291         obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
3292                     (unsigned char *) &first_nop, sizeof(first_nop));
3293
3294         scb_cs = SCB_CMD_CUC_GO;
3295         obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3296                     (unsigned char *) &scb_cs, sizeof(scb_cs));
3297
3298         set_chan_attn(ioaddr, lp->hacr);
3299
3300         for (i = 1000; i > 0; i--) {
3301                 obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3302                            (unsigned char *) &scb_cs, sizeof(scb_cs));
3303                 if (scb_cs == 0)
3304                         break;
3305
3306                 udelay(10);
3307         }
3308
3309         if (i <= 0) {
3310 #ifdef DEBUG_CONFIG_ERROR
3311                 printk(KERN_INFO
3312                        "%s: wavelan_cu_start(): board not accepting command.\n",
3313                        dev->name);
3314 #endif
3315                 return -1;
3316         }
3317
3318         lp->tx_n_in_use = 0;
3319         netif_start_queue(dev);
3320 #ifdef DEBUG_CONFIG_TRACE
3321         printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
3322 #endif
3323         return 0;
3324 }
3325
3326 /*------------------------------------------------------------------*/
3327 /*
3328  * This routine does a standard configuration of the WaveLAN 
3329  * controller (i82586).
3330  *
3331  * It initialises the scp, iscp and scb structure
3332  * The first two are just pointers to the next.
3333  * The last one is used for basic configuration and for basic
3334  * communication (interrupt status).
3335  *
3336  * (called by wv_hw_reset())
3337  */
3338 static inline int wv_82586_start(struct net_device * dev)
3339 {
3340         net_local *lp = (net_local *) dev->priv;
3341         unsigned long ioaddr = dev->base_addr;
3342         scp_t scp;              /* system configuration pointer */
3343         iscp_t iscp;            /* intermediate scp */
3344         scb_t scb;              /* system control block */
3345         ach_t cb;               /* Action command header */
3346         u8 zeroes[512];
3347         int i;
3348
3349 #ifdef DEBUG_CONFIG_TRACE
3350         printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
3351 #endif
3352
3353         /*
3354          * Clear the onboard RAM.
3355          */
3356         memset(&zeroes[0], 0x00, sizeof(zeroes));
3357         for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
3358                 obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
3359
3360         /*
3361          * Construct the command unit structures:
3362          * scp, iscp, scb, cb.
3363          */
3364         memset(&scp, 0x00, sizeof(scp));
3365         scp.scp_sysbus = SCP_SY_16BBUS;
3366         scp.scp_iscpl = OFFSET_ISCP;
3367         obram_write(ioaddr, OFFSET_SCP, (unsigned char *) &scp,
3368                     sizeof(scp));
3369
3370         memset(&iscp, 0x00, sizeof(iscp));
3371         iscp.iscp_busy = 1;
3372         iscp.iscp_offset = OFFSET_SCB;
3373         obram_write(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3374                     sizeof(iscp));
3375
3376         /* Our first command is to reset the i82586. */
3377         memset(&scb, 0x00, sizeof(scb));
3378         scb.scb_command = SCB_CMD_RESET;
3379         scb.scb_cbl_offset = OFFSET_CU;
3380         scb.scb_rfa_offset = OFFSET_RU;
3381         obram_write(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3382                     sizeof(scb));
3383
3384         set_chan_attn(ioaddr, lp->hacr);
3385
3386         /* Wait for command to finish. */
3387         for (i = 1000; i > 0; i--) {
3388                 obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3389                            sizeof(iscp));
3390
3391                 if (iscp.iscp_busy == (unsigned short) 0)
3392                         break;
3393
3394                 udelay(10);
3395         }
3396
3397         if (i <= 0) {
3398 #ifdef DEBUG_CONFIG_ERROR
3399                 printk(KERN_INFO
3400                        "%s: wv_82586_start(): iscp_busy timeout.\n",
3401                        dev->name);
3402 #endif
3403                 return -1;
3404         }
3405
3406         /* Check command completion. */
3407         for (i = 15; i > 0; i--) {
3408                 obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3409                            sizeof(scb));
3410
3411                 if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
3412                         break;
3413
3414                 udelay(10);
3415         }
3416
3417         if (i <= 0) {
3418 #ifdef DEBUG_CONFIG_ERROR
3419                 printk(KERN_INFO
3420                        "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
3421                        dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
3422 #endif
3423                 return -1;
3424         }
3425
3426         wv_ack(dev);
3427
3428         /* Set the action command header. */
3429         memset(&cb, 0x00, sizeof(cb));
3430         cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
3431         cb.ac_link = OFFSET_CU;
3432         obram_write(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3433
3434         if (wv_synchronous_cmd(dev, "diag()") == -1)
3435                 return -1;
3436
3437         obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3438         if (cb.ac_status & AC_SFLD_FAIL) {
3439 #ifdef DEBUG_CONFIG_ERROR
3440                 printk(KERN_INFO
3441                        "%s: wv_82586_start(): i82586 Self Test failed.\n",
3442                        dev->name);
3443 #endif
3444                 return -1;
3445         }
3446 #ifdef DEBUG_I82586_SHOW
3447         wv_scb_show(ioaddr);
3448 #endif
3449
3450 #ifdef DEBUG_CONFIG_TRACE
3451         printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
3452 #endif
3453         return 0;
3454 }
3455
3456 /*------------------------------------------------------------------*/
3457 /*
3458  * This routine does a standard configuration of the WaveLAN
3459  * controller (i82586).
3460  *
3461  * This routine is a violent hack. We use the first free transmit block
3462  * to make our configuration. In the buffer area, we create the three
3463  * configuration commands (linked). We make the previous NOP point to
3464  * the beginning of the buffer instead of the tx command. After, we go
3465  * as usual to the NOP command.
3466  * Note that only the last command (mc_set) will generate an interrupt.
3467  *
3468  * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit())
3469  */
3470 static void wv_82586_config(struct net_device * dev)
3471 {
3472         net_local *lp = (net_local *) dev->priv;
3473         unsigned long ioaddr = dev->base_addr;
3474         unsigned short txblock;
3475         unsigned short txpred;
3476         unsigned short tx_addr;
3477         unsigned short nop_addr;
3478         unsigned short tbd_addr;
3479         unsigned short cfg_addr;
3480         unsigned short ias_addr;
3481         unsigned short mcs_addr;
3482         ac_tx_t tx;
3483         ac_nop_t nop;
3484         ac_cfg_t cfg;           /* Configure action */
3485         ac_ias_t ias;           /* IA-setup action */
3486         ac_mcs_t mcs;           /* Multicast setup */
3487         struct dev_mc_list *dmi;
3488
3489 #ifdef DEBUG_CONFIG_TRACE
3490         printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
3491 #endif
3492
3493         /* Check nothing bad has happened */
3494         if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
3495 #ifdef DEBUG_CONFIG_ERROR
3496                 printk(KERN_INFO "%s: wv_82586_config(): Tx queue full.\n",
3497                        dev->name);
3498 #endif
3499                 return;
3500         }
3501
3502         /* Calculate addresses of next block and previous block. */
3503         txblock = lp->tx_first_free;
3504         txpred = txblock - TXBLOCKZ;
3505         if (txpred < OFFSET_CU)
3506                 txpred += NTXBLOCKS * TXBLOCKZ;
3507         lp->tx_first_free += TXBLOCKZ;
3508         if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
3509                 lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
3510
3511         lp->tx_n_in_use++;
3512
3513         /* Calculate addresses of the different parts of the block. */
3514         tx_addr = txblock;
3515         nop_addr = tx_addr + sizeof(tx);
3516         tbd_addr = nop_addr + sizeof(nop);
3517         cfg_addr = tbd_addr + sizeof(tbd_t);    /* beginning of the buffer */
3518         ias_addr = cfg_addr + sizeof(cfg);
3519         mcs_addr = ias_addr + sizeof(ias);
3520
3521         /*
3522          * Transmit command
3523          */
3524         tx.tx_h.ac_status = 0xFFFF;     /* Fake completion value */
3525         obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
3526                     (unsigned char *) &tx.tx_h.ac_status,
3527                     sizeof(tx.tx_h.ac_status));
3528
3529         /*
3530          * NOP command
3531          */
3532         nop.nop_h.ac_status = 0;
3533         obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3534                     (unsigned char *) &nop.nop_h.ac_status,
3535                     sizeof(nop.nop_h.ac_status));
3536         nop.nop_h.ac_link = nop_addr;
3537         obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3538                     (unsigned char *) &nop.nop_h.ac_link,
3539                     sizeof(nop.nop_h.ac_link));
3540
3541         /* Create a configure action. */
3542         memset(&cfg, 0x00, sizeof(cfg));
3543
3544         /*
3545          * For Linux we invert AC_CFG_ALOC() so as to conform
3546          * to the way that net packets reach us from above.
3547          * (See also ac_tx_t.)
3548          *
3549          * Updated from Wavelan Manual WCIN085B
3550          */
3551         cfg.cfg_byte_cnt =
3552             AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
3553         cfg.cfg_fifolim = AC_CFG_FIFOLIM(4);
3554         cfg.cfg_byte8 = AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0);
3555         cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
3556             AC_CFG_ILPBCK(0) |
3557             AC_CFG_PRELEN(AC_CFG_PLEN_2) |
3558             AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
3559         cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
3560             AC_CFG_ACR(6) | AC_CFG_LINPRIO(0);
3561         cfg.cfg_ifs = 0x20;
3562         cfg.cfg_slotl = 0x0C;
3563         cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0);
3564         cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
3565             AC_CFG_BTSTF(0) |
3566             AC_CFG_CRC16(0) |
3567             AC_CFG_NCRC(0) |
3568             AC_CFG_TNCRS(1) |
3569             AC_CFG_MANCH(0) |
3570             AC_CFG_BCDIS(0) | AC_CFG_PRM(lp->promiscuous);
3571         cfg.cfg_byte15 = AC_CFG_ICDS(0) |
3572             AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0);
3573 /*
3574   cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
3575 */
3576         cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
3577
3578         cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
3579         cfg.cfg_h.ac_link = ias_addr;
3580         obram_write(ioaddr, cfg_addr, (unsigned char *) &cfg, sizeof(cfg));
3581
3582         /* Set up the MAC address */
3583         memset(&ias, 0x00, sizeof(ias));
3584         ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
3585         ias.ias_h.ac_link = mcs_addr;
3586         memcpy(&ias.ias_addr[0], (unsigned char *) &dev->dev_addr[0],
3587                sizeof(ias.ias_addr));
3588         obram_write(ioaddr, ias_addr, (unsigned char *) &ias, sizeof(ias));
3589
3590         /* Initialize adapter's Ethernet multicast addresses */
3591         memset(&mcs, 0x00, sizeof(mcs));
3592         mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
3593         mcs.mcs_h.ac_link = nop_addr;
3594         mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
3595         obram_write(ioaddr, mcs_addr, (unsigned char *) &mcs, sizeof(mcs));
3596
3597         /* Any address to set? */
3598         if (lp->mc_count) {
3599                 for (dmi = dev->mc_list; dmi; dmi = dmi->next)
3600                         outsw(PIOP1(ioaddr), (u16 *) dmi->dmi_addr,
3601                               WAVELAN_ADDR_SIZE >> 1);
3602
3603 #ifdef DEBUG_CONFIG_INFO
3604                 printk(KERN_DEBUG
3605                        "%s: wv_82586_config(): set %d multicast addresses:\n",
3606                        dev->name, lp->mc_count);
3607                 for (dmi = dev->mc_list; dmi; dmi = dmi->next)
3608                         printk(KERN_DEBUG
3609                                " %02x:%02x:%02x:%02x:%02x:%02x\n",
3610                                dmi->dmi_addr[0], dmi->dmi_addr[1],
3611                                dmi->dmi_addr[2], dmi->dmi_addr[3],
3612                                dmi->dmi_addr[4], dmi->dmi_addr[5]);
3613 #endif
3614         }
3615
3616         /*
3617          * Overwrite the predecessor NOP link
3618          * so that it points to the configure action.
3619          */
3620         nop_addr = txpred + sizeof(tx);
3621         nop.nop_h.ac_status = 0;
3622         obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3623                     (unsigned char *) &nop.nop_h.ac_status,
3624                     sizeof(nop.nop_h.ac_status));
3625         nop.nop_h.ac_link = cfg_addr;
3626         obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3627                     (unsigned char *) &nop.nop_h.ac_link,
3628                     sizeof(nop.nop_h.ac_link));
3629
3630         /* Job done, clear the flag */
3631         lp->reconfig_82586 = 0;
3632
3633         if (lp->tx_first_in_use == I82586NULL)
3634                 lp->tx_first_in_use = txblock;
3635
3636         if (lp->tx_n_in_use == (NTXBLOCKS - 1))
3637                 netif_stop_queue(dev);
3638
3639 #ifdef DEBUG_CONFIG_TRACE
3640         printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
3641 #endif
3642 }
3643
3644 /*------------------------------------------------------------------*/
3645 /*
3646  * This routine, called by wavelan_close(), gracefully stops the 
3647  * WaveLAN controller (i82586).
3648  * (called by wavelan_close())
3649  */
3650 static inline void wv_82586_stop(struct net_device * dev)
3651 {
3652         net_local *lp = (net_local *) dev->priv;
3653         unsigned long ioaddr = dev->base_addr;
3654         u16 scb_cmd;
3655
3656 #ifdef DEBUG_CONFIG_TRACE
3657         printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
3658 #endif
3659
3660         /* Suspend both command unit and receive unit. */
3661         scb_cmd =
3662             (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC &
3663                                                SCB_CMD_RUC_SUS);
3664         obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3665                     (unsigned char *) &scb_cmd, sizeof(scb_cmd));
3666         set_chan_attn(ioaddr, lp->hacr);
3667
3668         /* No more interrupts */
3669         wv_ints_off(dev);
3670
3671 #ifdef DEBUG_CONFIG_TRACE
3672         printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
3673 #endif
3674 }
3675
3676 /*------------------------------------------------------------------*/
3677 /*
3678  * Totally reset the WaveLAN and restart it.
3679  * Performs the following actions:
3680  *      1. A power reset (reset DMA)
3681  *      2. Initialize the radio modem (using wv_mmc_init)
3682  *      3. Reset & Configure LAN controller (using wv_82586_start)
3683  *      4. Start the LAN controller's command unit
3684  *      5. Start the LAN controller's receive unit
3685  * (called by wavelan_interrupt(), wavelan_watchdog() & wavelan_open())
3686  */
3687 static int wv_hw_reset(struct net_device * dev)
3688 {
3689         net_local *lp = (net_local *) dev->priv;
3690         unsigned long ioaddr = dev->base_addr;
3691
3692 #ifdef DEBUG_CONFIG_TRACE
3693         printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
3694                (unsigned int) dev);
3695 #endif
3696
3697         /* Increase the number of resets done. */
3698         lp->nresets++;
3699
3700         wv_hacr_reset(ioaddr);
3701         lp->hacr = HACR_DEFAULT;
3702
3703         if ((wv_mmc_init(dev) < 0) || (wv_82586_start(dev) < 0))
3704                 return -1;
3705
3706         /* Enable the card to send interrupts. */
3707         wv_ints_on(dev);
3708
3709         /* Start card functions */
3710         if (wv_cu_start(dev) < 0)
3711                 return -1;
3712
3713         /* Setup the controller and parameters */
3714         wv_82586_config(dev);
3715
3716         /* Finish configuration with the receive unit */
3717         if (wv_ru_start(dev) < 0)
3718                 return -1;
3719
3720 #ifdef DEBUG_CONFIG_TRACE
3721         printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3722 #endif
3723         return 0;
3724 }
3725
3726 /*------------------------------------------------------------------*/
3727 /*
3728  * Check if there is a WaveLAN at the specific base address.
3729  * As a side effect, this reads the MAC address.
3730  * (called in wavelan_probe() and init_module())
3731  */
3732 static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac)
3733 {
3734         int i;                  /* Loop counter */
3735
3736         /* Check if the base address if available. */
3737         if (!request_region(ioaddr, sizeof(ha_t), "wavelan probe"))
3738                 return -EBUSY;          /* ioaddr already used */
3739
3740         /* Reset host interface */
3741         wv_hacr_reset(ioaddr);
3742
3743         /* Read the MAC address from the parameter storage area. */
3744         psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
3745                  mac, 6);
3746
3747         release_region(ioaddr, sizeof(ha_t));
3748
3749         /*
3750          * Check the first three octets of the address for the manufacturer's code.
3751          * Note: if this can't find your WaveLAN card, you've got a
3752          * non-NCR/AT&T/Lucent ISA card.  See wavelan.p.h for detail on
3753          * how to configure your card.
3754          */
3755         for (i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3756                 if ((mac[0] == MAC_ADDRESSES[i][0]) &&
3757                     (mac[1] == MAC_ADDRESSES[i][1]) &&
3758                     (mac[2] == MAC_ADDRESSES[i][2]))
3759                         return 0;
3760
3761 #ifdef DEBUG_CONFIG_INFO
3762         printk(KERN_WARNING
3763                "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
3764                ioaddr, mac[0], mac[1], mac[2]);
3765 #endif
3766         return -ENODEV;
3767 }
3768
3769 /************************ INTERRUPT HANDLING ************************/
3770
3771 /*
3772  * This function is the interrupt handler for the WaveLAN card. This
3773  * routine will be called whenever: 
3774  */
3775 static irqreturn_t wavelan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3776 {
3777         struct net_device *dev;
3778         unsigned long ioaddr;
3779         net_local *lp;
3780         u16 hasr;
3781         u16 status;
3782         u16 ack_cmd;
3783
3784         dev = dev_id;
3785
3786 #ifdef DEBUG_INTERRUPT_TRACE
3787         printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
3788 #endif
3789
3790         lp = (net_local *) dev->priv;
3791         ioaddr = dev->base_addr;
3792
3793 #ifdef DEBUG_INTERRUPT_INFO
3794         /* Check state of our spinlock */
3795         if(spin_is_locked(&lp->spinlock))
3796                 printk(KERN_DEBUG
3797                        "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
3798                        dev->name);
3799 #endif
3800
3801         /* Prevent reentrancy. We need to do that because we may have
3802          * multiple interrupt handler running concurrently.
3803          * It is safe because interrupts are disabled before acquiring
3804          * the spinlock. */
3805         spin_lock(&lp->spinlock);
3806
3807         /* We always had spurious interrupts at startup, but lately I
3808          * saw them comming *between* the request_irq() and the
3809          * spin_lock_irqsave() in wavelan_open(), so the spinlock
3810          * protection is no enough.
3811          * So, we also check lp->hacr that will tell us is we enabled
3812          * irqs or not (see wv_ints_on()).
3813          * We can't use netif_running(dev) because we depend on the
3814          * proper processing of the irq generated during the config. */
3815
3816         /* Which interrupt it is ? */
3817         hasr = hasr_read(ioaddr);
3818
3819 #ifdef DEBUG_INTERRUPT_INFO
3820         printk(KERN_INFO
3821                "%s: wavelan_interrupt(): hasr 0x%04x; hacr 0x%04x.\n",
3822                dev->name, hasr, lp->hacr);
3823 #endif
3824
3825         /* Check modem interrupt */
3826         if ((hasr & HASR_MMC_INTR) && (lp->hacr & HACR_MMC_INT_ENABLE)) {
3827                 u8 dce_status;
3828
3829                 /*
3830                  * Interrupt from the modem management controller.
3831                  * This will clear it -- ignored for now.
3832                  */
3833                 mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status,
3834                          sizeof(dce_status));
3835
3836 #ifdef DEBUG_INTERRUPT_ERROR
3837                 printk(KERN_INFO
3838                        "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
3839                        dev->name, dce_status);
3840 #endif
3841         }
3842
3843         /* Check if not controller interrupt */
3844         if (((hasr & HASR_82586_INTR) == 0) ||
3845             ((lp->hacr & HACR_82586_INT_ENABLE) == 0)) {
3846 #ifdef DEBUG_INTERRUPT_ERROR
3847                 printk(KERN_INFO
3848                        "%s: wavelan_interrupt(): interrupt not coming from i82586 - hasr 0x%04x.\n",
3849                        dev->name, hasr);
3850 #endif
3851                 spin_unlock (&lp->spinlock);
3852                 return IRQ_NONE;
3853         }
3854
3855         /* Read interrupt data. */
3856         obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3857                    (unsigned char *) &status, sizeof(status));
3858
3859         /*
3860          * Acknowledge the interrupt(s).
3861          */
3862         ack_cmd = status & SCB_ST_INT;
3863         obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3864                     (unsigned char *) &ack_cmd, sizeof(ack_cmd));
3865         set_chan_attn(ioaddr, lp->hacr);
3866
3867 #ifdef DEBUG_INTERRUPT_INFO
3868         printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
3869                dev->name, status);
3870 #endif
3871
3872         /* Command completed. */
3873         if ((status & SCB_ST_CX) == SCB_ST_CX) {
3874 #ifdef DEBUG_INTERRUPT_INFO
3875                 printk(KERN_DEBUG
3876                        "%s: wavelan_interrupt(): command completed.\n",
3877                        dev->name);
3878 #endif
3879                 wv_complete(dev, ioaddr, lp);
3880         }
3881
3882         /* Frame received. */
3883         if ((status & SCB_ST_FR) == SCB_ST_FR) {
3884 #ifdef DEBUG_INTERRUPT_INFO
3885                 printk(KERN_DEBUG
3886                        "%s: wavelan_interrupt(): received packet.\n",
3887                        dev->name);
3888 #endif
3889                 wv_receive(dev);
3890         }
3891
3892         /* Check the state of the command unit. */
3893         if (((status & SCB_ST_CNA) == SCB_ST_CNA) ||
3894             (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) &&
3895              (netif_running(dev)))) {
3896 #ifdef DEBUG_INTERRUPT_ERROR
3897                 printk(KERN_INFO
3898                        "%s: wavelan_interrupt(): CU inactive -- restarting\n",
3899                        dev->name);
3900 #endif
3901                 wv_hw_reset(dev);
3902         }
3903
3904         /* Check the state of the command unit. */
3905         if (((status & SCB_ST_RNR) == SCB_ST_RNR) ||
3906             (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) &&
3907              (netif_running(dev)))) {
3908 #ifdef DEBUG_INTERRUPT_ERROR
3909                 printk(KERN_INFO
3910                        "%s: wavelan_interrupt(): RU not ready -- restarting\n",
3911                        dev->name);
3912 #endif
3913                 wv_hw_reset(dev);
3914         }
3915
3916         /* Release spinlock */
3917         spin_unlock (&lp->spinlock);
3918
3919 #ifdef DEBUG_INTERRUPT_TRACE
3920         printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
3921 #endif
3922         return IRQ_HANDLED;
3923 }
3924
3925 /*------------------------------------------------------------------*/
3926 /*
3927  * Watchdog: when we start a transmission, a timer is set for us in the
3928  * kernel.  If the transmission completes, this timer is disabled. If
3929  * the timer expires, we are called and we try to unlock the hardware.
3930  */
3931 static void wavelan_watchdog(struct net_device *        dev)
3932 {
3933         net_local *     lp = (net_local *)dev->priv;
3934         u_long          ioaddr = dev->base_addr;
3935         unsigned long   flags;
3936         unsigned int    nreaped;
3937
3938 #ifdef DEBUG_INTERRUPT_TRACE
3939         printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
3940 #endif
3941
3942 #ifdef DEBUG_INTERRUPT_ERROR
3943         printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
3944                dev->name);
3945 #endif
3946
3947         /* Check that we came here for something */
3948         if (lp->tx_n_in_use <= 0) {
3949                 return;
3950         }
3951
3952         spin_lock_irqsave(&lp->spinlock, flags);
3953
3954         /* Try to see if some buffers are not free (in case we missed
3955          * an interrupt */
3956         nreaped = wv_complete(dev, ioaddr, lp);
3957
3958 #ifdef DEBUG_INTERRUPT_INFO
3959         printk(KERN_DEBUG
3960                "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
3961                dev->name, nreaped, lp->tx_n_in_use);
3962 #endif
3963
3964 #ifdef DEBUG_PSA_SHOW
3965         {
3966                 psa_t psa;
3967                 psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3968                 wv_psa_show(&psa);
3969         }
3970 #endif
3971 #ifdef DEBUG_MMC_SHOW
3972         wv_mmc_show(dev);
3973 #endif
3974 #ifdef DEBUG_I82586_SHOW
3975         wv_cu_show(dev);
3976 #endif
3977
3978         /* If no buffer has been freed */
3979         if (nreaped == 0) {
3980 #ifdef DEBUG_INTERRUPT_ERROR
3981                 printk(KERN_INFO
3982                        "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
3983                        dev->name);
3984 #endif
3985                 wv_hw_reset(dev);
3986         }
3987
3988         /* At this point, we should have some free Tx buffer ;-) */
3989         if (lp->tx_n_in_use < NTXBLOCKS - 1)
3990                 netif_wake_queue(dev);
3991
3992         spin_unlock_irqrestore(&lp->spinlock, flags);
3993         
3994 #ifdef DEBUG_INTERRUPT_TRACE
3995         printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
3996 #endif
3997 }
3998
3999 /********************* CONFIGURATION CALLBACKS *********************/
4000 /*
4001  * Here are the functions called by the Linux networking code (NET3)
4002  * for initialization, configuration and deinstallations of the 
4003  * WaveLAN ISA hardware.
4004  */
4005
4006 /*------------------------------------------------------------------*/
4007 /*
4008  * Configure and start up the WaveLAN PCMCIA adaptor.
4009  * Called by NET3 when it "opens" the device.
4010  */
4011 static int wavelan_open(struct net_device * dev)
4012 {
4013         net_local *     lp = (net_local *)dev->priv;
4014         unsigned long   flags;
4015
4016 #ifdef DEBUG_CALLBACK_TRACE
4017         printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
4018                (unsigned int) dev);
4019 #endif
4020
4021         /* Check irq */
4022         if (dev->irq == 0) {
4023 #ifdef DEBUG_CONFIG_ERROR
4024                 printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n",
4025                        dev->name);
4026 #endif
4027                 return -ENXIO;
4028         }
4029
4030         if (request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0) 
4031         {
4032 #ifdef DEBUG_CONFIG_ERROR
4033                 printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n",
4034                        dev->name);
4035 #endif
4036                 return -EAGAIN;
4037         }
4038
4039         spin_lock_irqsave(&lp->spinlock, flags);
4040         
4041         if (wv_hw_reset(dev) != -1) {
4042                 netif_start_queue(dev);
4043         } else {
4044                 free_irq(dev->irq, dev);
4045 #ifdef DEBUG_CONFIG_ERROR
4046                 printk(KERN_INFO
4047                        "%s: wavelan_open(): impossible to start the card\n",
4048                        dev->name);
4049 #endif
4050                 spin_unlock_irqrestore(&lp->spinlock, flags);
4051                 return -EAGAIN;
4052         }
4053         spin_unlock_irqrestore(&lp->spinlock, flags);
4054         
4055 #ifdef DEBUG_CALLBACK_TRACE
4056         printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
4057 #endif
4058         return 0;
4059 }
4060
4061 /*------------------------------------------------------------------*/
4062 /*
4063  * Shut down the WaveLAN ISA card.
4064  * Called by NET3 when it "closes" the device.
4065  */
4066 static int wavelan_close(struct net_device * dev)
4067 {
4068         net_local *lp = (net_local *) dev->priv;
4069         unsigned long flags;
4070
4071 #ifdef DEBUG_CALLBACK_TRACE
4072         printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
4073                (unsigned int) dev);
4074 #endif
4075
4076         netif_stop_queue(dev);
4077
4078         /*
4079          * Flush the Tx and disable Rx.
4080          */
4081         spin_lock_irqsave(&lp->spinlock, flags);
4082         wv_82586_stop(dev);
4083         spin_unlock_irqrestore(&lp->spinlock, flags);
4084
4085         free_irq(dev->irq, dev);
4086
4087 #ifdef DEBUG_CALLBACK_TRACE
4088         printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
4089 #endif
4090         return 0;
4091 }
4092
4093 /*------------------------------------------------------------------*/
4094 /*
4095  * Probe an I/O address, and if the WaveLAN is there configure the
4096  * device structure
4097  * (called by wavelan_probe() and via init_module()).
4098  */
4099 static int __init wavelan_config(struct net_device *dev, unsigned short ioaddr)
4100 {
4101         u8 irq_mask;
4102         int irq;
4103         net_local *lp;
4104         mac_addr mac;
4105         int err;
4106
4107         if (!request_region(ioaddr, sizeof(ha_t), "wavelan"))
4108                 return -EADDRINUSE;
4109
4110         err = wv_check_ioaddr(ioaddr, mac);
4111         if (err)
4112                 goto out;
4113
4114         memcpy(dev->dev_addr, mac, 6);
4115
4116         dev->base_addr = ioaddr;
4117
4118 #ifdef DEBUG_CALLBACK_TRACE
4119         printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%lx)\n",
4120                dev->name, (unsigned int) dev, ioaddr);
4121 #endif
4122
4123         /* Check IRQ argument on command line. */
4124         if (dev->irq != 0) {
4125                 irq_mask = wv_irq_to_psa(dev->irq);
4126
4127                 if (irq_mask == 0) {
4128 #ifdef DEBUG_CONFIG_ERROR
4129                         printk(KERN_WARNING
4130                                "%s: wavelan_config(): invalid IRQ %d ignored.\n",
4131                                dev->name, dev->irq);
4132 #endif
4133                         dev->irq = 0;
4134                 } else {
4135 #ifdef DEBUG_CONFIG_INFO
4136                         printk(KERN_DEBUG
4137                                "%s: wavelan_config(): changing IRQ to %d\n",
4138                                dev->name, dev->irq);
4139 #endif
4140                         psa_write(ioaddr, HACR_DEFAULT,
4141                                   psaoff(0, psa_int_req_no), &irq_mask, 1);
4142                         /* update the Wavelan checksum */
4143                         update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
4144                         wv_hacr_reset(ioaddr);
4145                 }
4146         }
4147
4148         psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no),
4149                  &irq_mask, 1);
4150         if ((irq = wv_psa_to_irq(irq_mask)) == -1) {
4151 #ifdef DEBUG_CONFIG_ERROR
4152                 printk(KERN_INFO
4153                        "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
4154                        dev->name, irq_mask);
4155 #endif
4156                 err = -EAGAIN;
4157                 goto out;
4158         }
4159
4160         dev->irq = irq;
4161
4162         dev->mem_start = 0x0000;
4163         dev->mem_end = 0x0000;
4164         dev->if_port = 0;
4165
4166         /* Initialize device structures */
4167         memset(dev->priv, 0, sizeof(net_local));
4168         lp = (net_local *) dev->priv;
4169
4170         /* Back link to the device structure. */
4171         lp->dev = dev;
4172         /* Add the device at the beginning of the linked list. */
4173         lp->next = wavelan_list;
4174         wavelan_list = lp;
4175
4176         lp->hacr = HACR_DEFAULT;
4177
4178         /* Multicast stuff */
4179         lp->promiscuous = 0;
4180         lp->mc_count = 0;
4181
4182         /* Init spinlock */
4183         spin_lock_init(&lp->spinlock);
4184
4185         SET_MODULE_OWNER(dev);
4186         dev->open = wavelan_open;
4187         dev->stop = wavelan_close;
4188         dev->hard_start_xmit = wavelan_packet_xmit;
4189         dev->get_stats = wavelan_get_stats;
4190         dev->set_multicast_list = &wavelan_set_multicast_list;
4191         dev->tx_timeout         = &wavelan_watchdog;
4192         dev->watchdog_timeo     = WATCHDOG_JIFFIES;
4193 #ifdef SET_MAC_ADDRESS
4194         dev->set_mac_address = &wavelan_set_mac_address;
4195 #endif                          /* SET_MAC_ADDRESS */
4196
4197 #ifdef WIRELESS_EXT             /* if wireless extension exists in the kernel */
4198         dev->wireless_handlers = &wavelan_handler_def;
4199         lp->wireless_data.spy_data = &lp->spy_data;
4200         dev->wireless_data = &lp->wireless_data;
4201 #endif
4202
4203         dev->mtu = WAVELAN_MTU;
4204
4205         /* Display nice information. */
4206         wv_init_info(dev);
4207
4208 #ifdef DEBUG_CALLBACK_TRACE
4209         printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
4210 #endif
4211         return 0;
4212 out:
4213         release_region(ioaddr, sizeof(ha_t));
4214         return err;
4215 }
4216
4217 /*------------------------------------------------------------------*/
4218 /*
4219  * Check for a network adaptor of this type.  Return '0' iff one 
4220  * exists.  There seem to be different interpretations of
4221  * the initial value of dev->base_addr.
4222  * We follow the example in drivers/net/ne.c.
4223  * (called in "Space.c")
4224  */
4225 struct net_device * __init wavelan_probe(int unit)
4226 {
4227         struct net_device *dev;
4228         short base_addr;
4229         int def_irq;
4230         int i;
4231         int r = 0;
4232
4233 #ifdef  STRUCT_CHECK
4234         if (wv_struct_check() != (char *) NULL) {
4235                 printk(KERN_WARNING
4236                        "%s: wavelan_probe(): structure/compiler botch: \"%s\"\n",
4237                        dev->name, wv_struct_check());
4238                 return -ENODEV;
4239         }
4240 #endif                          /* STRUCT_CHECK */
4241
4242         dev = alloc_etherdev(sizeof(net_local));
4243         if (!dev)
4244                 return ERR_PTR(-ENOMEM);
4245
4246         sprintf(dev->name, "eth%d", unit);
4247         netdev_boot_setup_check(dev);
4248         base_addr = dev->base_addr;
4249         def_irq = dev->irq;
4250
4251 #ifdef DEBUG_CALLBACK_TRACE
4252         printk(KERN_DEBUG
4253                "%s: ->wavelan_probe(dev=%p (base_addr=0x%x))\n",
4254                dev->name, dev, (unsigned int) dev->base_addr);
4255 #endif
4256
4257         /* Don't probe at all. */
4258         if (base_addr < 0) {
4259 #ifdef DEBUG_CONFIG_ERROR
4260                 printk(KERN_WARNING
4261                        "%s: wavelan_probe(): invalid base address\n",
4262                        dev->name);
4263 #endif
4264                 r = -ENXIO;
4265         } else if (base_addr > 0x100) { /* Check a single specified location. */
4266                 r = wavelan_config(dev, base_addr);
4267 #ifdef DEBUG_CONFIG_INFO
4268                 if (r != 0)
4269                         printk(KERN_DEBUG
4270                                "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
4271                                dev->name, base_addr);
4272 #endif
4273
4274 #ifdef DEBUG_CALLBACK_TRACE
4275                 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4276 #endif
4277         } else { /* Scan all possible addresses of the WaveLAN hardware. */
4278                 for (i = 0; i < NELS(iobase); i++) {
4279                         dev->irq = def_irq;
4280                         if (wavelan_config(dev, iobase[i]) == 0) {
4281 #ifdef DEBUG_CALLBACK_TRACE
4282                                 printk(KERN_DEBUG
4283                                        "%s: <-wavelan_probe()\n",
4284                                        dev->name);
4285 #endif
4286                                 break;
4287                         }
4288                 }
4289                 if (i == NELS(iobase))
4290                         r = -ENODEV;
4291         }
4292         if (r) 
4293                 goto out;
4294         r = register_netdev(dev);
4295         if (r)
4296                 goto out1;
4297         return dev;
4298 out1:
4299         release_region(dev->base_addr, sizeof(ha_t));
4300         wavelan_list = wavelan_list->next;
4301 out:
4302         free_netdev(dev);
4303         return ERR_PTR(r);
4304 }
4305
4306 /****************************** MODULE ******************************/
4307 /*
4308  * Module entry point: insertion and removal
4309  */
4310
4311 #ifdef  MODULE
4312 /*------------------------------------------------------------------*/
4313 /*
4314  * Insertion of the module
4315  * I'm now quite proud of the multi-device support.
4316  */
4317 int init_module(void)
4318 {
4319         int ret = -EIO;         /* Return error if no cards found */
4320         int i;
4321
4322 #ifdef DEBUG_MODULE_TRACE
4323         printk(KERN_DEBUG "-> init_module()\n");
4324 #endif
4325
4326         /* If probing is asked */
4327         if (io[0] == 0) {
4328 #ifdef DEBUG_CONFIG_ERROR
4329                 printk(KERN_WARNING
4330                        "WaveLAN init_module(): doing device probing (bad !)\n");
4331                 printk(KERN_WARNING
4332                        "Specify base addresses while loading module to correct the problem\n");
4333 #endif
4334
4335                 /* Copy the basic set of address to be probed. */
4336                 for (i = 0; i < NELS(iobase); i++)
4337                         io[i] = iobase[i];
4338         }
4339
4340
4341         /* Loop on all possible base addresses. */
4342         i = -1;
4343         while ((io[++i] != 0) && (i < NELS(io))) {
4344                 struct net_device *dev = alloc_etherdev(sizeof(net_local));
4345                 if (!dev)
4346                         break;
4347                 if (name[i])
4348                         strcpy(dev->name, name[i]);     /* Copy name */
4349                 dev->base_addr = io[i];
4350                 dev->irq = irq[i];
4351
4352                 /* Check if there is something at this base address. */
4353                 if (wavelan_config(dev, io[i]) == 0) {
4354                         if (register_netdev(dev) != 0) {
4355                                 release_region(dev->base_addr, sizeof(ha_t));
4356                                 wavelan_list = wavelan_list->next;
4357                         } else {
4358                                 ret = 0;
4359                                 continue;
4360                         }
4361                 }
4362                 free_netdev(dev);
4363         }
4364
4365 #ifdef DEBUG_CONFIG_ERROR
4366         if (!wavelan_list)
4367                 printk(KERN_WARNING
4368                        "WaveLAN init_module(): no device found\n");
4369 #endif
4370
4371 #ifdef DEBUG_MODULE_TRACE
4372         printk(KERN_DEBUG "<- init_module()\n");
4373 #endif
4374         return ret;
4375 }
4376
4377 /*------------------------------------------------------------------*/
4378 /*
4379  * Removal of the module
4380  */
4381 void cleanup_module(void)
4382 {
4383 #ifdef DEBUG_MODULE_TRACE
4384         printk(KERN_DEBUG "-> cleanup_module()\n");
4385 #endif
4386
4387         /* Loop on all devices and release them. */
4388         while (wavelan_list) {
4389                 struct net_device *dev = wavelan_list->dev;
4390
4391 #ifdef DEBUG_CONFIG_INFO
4392                 printk(KERN_DEBUG
4393                        "%s: cleanup_module(): removing device at 0x%x\n",
4394                        dev->name, (unsigned int) dev);
4395 #endif
4396                 unregister_netdev(dev);
4397
4398                 release_region(dev->base_addr, sizeof(ha_t));
4399                 wavelan_list = wavelan_list->next;
4400
4401                 free_netdev(dev);
4402         }
4403
4404 #ifdef DEBUG_MODULE_TRACE
4405         printk(KERN_DEBUG "<- cleanup_module()\n");
4406 #endif
4407 }
4408 #endif                          /* MODULE */
4409 MODULE_LICENSE("GPL");
4410
4411 /*
4412  * This software may only be used and distributed
4413  * according to the terms of the GNU General Public License.
4414  *
4415  * This software was developed as a component of the
4416  * Linux operating system.
4417  * It is based on other device drivers and information
4418  * either written or supplied by:
4419  *      Ajay Bakre (bakre@paul.rutgers.edu),
4420  *      Donald Becker (becker@scyld.com),
4421  *      Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
4422  *      Anders Klemets (klemets@it.kth.se),
4423  *      Vladimir V. Kolpakov (w@stier.koenig.ru),
4424  *      Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
4425  *      Pauline Middelink (middelin@polyware.iaf.nl),
4426  *      Robert Morris (rtm@das.harvard.edu),
4427  *      Jean Tourrilhes (jt@hplb.hpl.hp.com),
4428  *      Girish Welling (welling@paul.rutgers.edu),
4429  *
4430  * Thanks go also to:
4431  *      James Ashton (jaa101@syseng.anu.edu.au),
4432  *      Alan Cox (alan@redhat.com),
4433  *      Allan Creighton (allanc@cs.usyd.edu.au),
4434  *      Matthew Geier (matthew@cs.usyd.edu.au),
4435  *      Remo di Giovanni (remo@cs.usyd.edu.au),
4436  *      Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
4437  *      Vipul Gupta (vgupta@cs.binghamton.edu),
4438  *      Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
4439  *      Tim Nicholson (tim@cs.usyd.edu.au),
4440  *      Ian Parkin (ian@cs.usyd.edu.au),
4441  *      John Rosenberg (johnr@cs.usyd.edu.au),
4442  *      George Rossi (george@phm.gov.au),
4443  *      Arthur Scott (arthur@cs.usyd.edu.au),
4444  *      Peter Storey,
4445  * for their assistance and advice.
4446  *
4447  * Please send bug reports, updates, comments to:
4448  *
4449  * Bruce Janson                                    Email:  bruce@cs.usyd.edu.au
4450  * Basser Department of Computer Science           Phone:  +61-2-9351-3423
4451  * University of Sydney, N.S.W., 2006, AUSTRALIA   Fax:    +61-2-9351-3838
4452  */