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