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