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.
12 * AT&T GIS (nee NCR) WaveLAN card:
13 * An Ethernet-like radio transceiver
14 * controlled by an Intel 82586 coprocessor.
17 #include "wavelan.p.h" /* Private header */
19 /************************* MISC SUBROUTINES **************************/
21 * Subroutines which won't fit in one of the following category
22 * (WaveLAN modem or i82586)
25 /*------------------------------------------------------------------*/
27 * Translate irq number to PSA irq parameter
29 static u8
wv_irq_to_psa(int irq
)
31 if (irq
< 0 || irq
>= NELS(irqvals
))
37 /*------------------------------------------------------------------*/
39 * Translate PSA irq parameter to irq number
41 static int __init
wv_psa_to_irq(u8 irqval
)
45 for (irq
= 0; irq
< NELS(irqvals
); irq
++)
46 if (irqvals
[irq
] == irqval
)
53 /*------------------------------------------------------------------*/
55 * Sanity routine to verify the sizes of the various WaveLAN interface
58 static char *wv_struct_check(void)
60 #define SC(t,s,n) if (sizeof(t) != s) return(n);
62 SC(psa_t
, PSA_SIZE
, "psa_t");
63 SC(mmw_t
, MMW_SIZE
, "mmw_t");
64 SC(mmr_t
, MMR_SIZE
, "mmr_t");
65 SC(ha_t
, HA_SIZE
, "ha_t");
69 return ((char *) NULL
);
70 } /* wv_struct_check */
71 #endif /* STRUCT_CHECK */
73 /********************* HOST ADAPTER SUBROUTINES *********************/
75 * Useful subroutines to manage the WaveLAN ISA interface
77 * One major difference with the PCMCIA hardware (except the port mapping)
78 * is that we have to keep the state of the Host Control Register
79 * because of the interrupt enable & bus size flags.
82 /*------------------------------------------------------------------*/
84 * Read from card's Host Adaptor Status Register.
86 static inline u16
hasr_read(unsigned long ioaddr
)
88 return (inw(HASR(ioaddr
)));
91 /*------------------------------------------------------------------*/
93 * Write to card's Host Adapter Command Register.
95 static inline void hacr_write(unsigned long ioaddr
, u16 hacr
)
97 outw(hacr
, HACR(ioaddr
));
100 /*------------------------------------------------------------------*/
102 * Write to card's Host Adapter Command Register. Include a delay for
103 * those times when it is needed.
105 static inline void hacr_write_slow(unsigned long ioaddr
, u16 hacr
)
107 hacr_write(ioaddr
, hacr
);
108 /* delay might only be needed sometimes */
110 } /* hacr_write_slow */
112 /*------------------------------------------------------------------*/
114 * Set the channel attention bit.
116 static inline void set_chan_attn(unsigned long ioaddr
, u16 hacr
)
118 hacr_write(ioaddr
, hacr
| HACR_CA
);
119 } /* set_chan_attn */
121 /*------------------------------------------------------------------*/
123 * Reset, and then set host adaptor into default mode.
125 static inline void wv_hacr_reset(unsigned long ioaddr
)
127 hacr_write_slow(ioaddr
, HACR_RESET
);
128 hacr_write(ioaddr
, HACR_DEFAULT
);
129 } /* wv_hacr_reset */
131 /*------------------------------------------------------------------*/
133 * Set the I/O transfer over the ISA bus to 8-bit mode
135 static inline void wv_16_off(unsigned long ioaddr
, u16 hacr
)
137 hacr
&= ~HACR_16BITS
;
138 hacr_write(ioaddr
, hacr
);
141 /*------------------------------------------------------------------*/
143 * Set the I/O transfer over the ISA bus to 8-bit mode
145 static inline void wv_16_on(unsigned long ioaddr
, u16 hacr
)
148 hacr_write(ioaddr
, hacr
);
151 /*------------------------------------------------------------------*/
153 * Disable interrupts on the WaveLAN hardware.
154 * (called by wv_82586_stop())
156 static inline void wv_ints_off(struct net_device
* dev
)
158 net_local
*lp
= (net_local
*) dev
->priv
;
159 unsigned long ioaddr
= dev
->base_addr
;
161 lp
->hacr
&= ~HACR_INTRON
;
162 hacr_write(ioaddr
, lp
->hacr
);
165 /*------------------------------------------------------------------*/
167 * Enable interrupts on the WaveLAN hardware.
168 * (called by wv_hw_reset())
170 static inline void wv_ints_on(struct net_device
* dev
)
172 net_local
*lp
= (net_local
*) dev
->priv
;
173 unsigned long ioaddr
= dev
->base_addr
;
175 lp
->hacr
|= HACR_INTRON
;
176 hacr_write(ioaddr
, lp
->hacr
);
179 /******************* MODEM MANAGEMENT SUBROUTINES *******************/
181 * Useful subroutines to manage the modem of the WaveLAN
184 /*------------------------------------------------------------------*/
186 * Read the Parameter Storage Area from the WaveLAN card's memory
189 * Read bytes from the PSA.
191 static void psa_read(unsigned long ioaddr
, u16 hacr
, int o
, /* offset in PSA */
192 u8
* b
, /* buffer to fill */
195 wv_16_off(ioaddr
, hacr
);
198 outw(o
, PIOR2(ioaddr
));
200 *b
++ = inb(PIOP2(ioaddr
));
203 wv_16_on(ioaddr
, hacr
);
206 /*------------------------------------------------------------------*/
208 * Write the Parameter Storage Area to the WaveLAN card's memory.
210 static void psa_write(unsigned long ioaddr
, u16 hacr
, int o
, /* Offset in PSA */
211 u8
* b
, /* Buffer in memory */
213 { /* Length of buffer */
216 wv_16_off(ioaddr
, hacr
);
219 outw(o
, PIOR2(ioaddr
));
222 outb(*b
, PIOP2(ioaddr
));
225 /* Wait for the memory to finish its write cycle */
227 while ((count
++ < 100) &&
228 (hasr_read(ioaddr
) & HASR_PSA_BUSY
)) mdelay(1);
231 wv_16_on(ioaddr
, hacr
);
235 /*------------------------------------------------------------------*/
237 * Calculate the PSA CRC
238 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
239 * NOTE: By specifying a length including the CRC position the
240 * returned value should be zero. (i.e. a correct checksum in the PSA)
242 * The Windows drivers don't use the CRC, but the AP and the PtP tool
245 static inline u16
psa_crc(u8
* psa
, /* The PSA */
247 { /* Number of short for CRC */
248 int byte_cnt
; /* Loop on the PSA */
249 u16 crc_bytes
= 0; /* Data in the PSA */
250 int bit_cnt
; /* Loop on the bits of the short */
252 for (byte_cnt
= 0; byte_cnt
< size
; byte_cnt
++) {
253 crc_bytes
^= psa
[byte_cnt
]; /* Its an xor */
255 for (bit_cnt
= 1; bit_cnt
< 9; bit_cnt
++) {
256 if (crc_bytes
& 0x0001)
257 crc_bytes
= (crc_bytes
>> 1) ^ 0xA001;
265 #endif /* SET_PSA_CRC */
267 /*------------------------------------------------------------------*/
269 * update the checksum field in the Wavelan's PSA
271 static void update_psa_checksum(struct net_device
* dev
, unsigned long ioaddr
, u16 hacr
)
277 /* read the parameter storage area */
278 psa_read(ioaddr
, hacr
, 0, (unsigned char *) &psa
, sizeof(psa
));
280 /* update the checksum */
281 crc
= psa_crc((unsigned char *) &psa
,
282 sizeof(psa
) - sizeof(psa
.psa_crc
[0]) -
283 sizeof(psa
.psa_crc
[1])
284 - sizeof(psa
.psa_crc_status
));
286 psa
.psa_crc
[0] = crc
& 0xFF;
287 psa
.psa_crc
[1] = (crc
& 0xFF00) >> 8;
290 psa_write(ioaddr
, hacr
, (char *) &psa
.psa_crc
- (char *) &psa
,
291 (unsigned char *) &psa
.psa_crc
, 2);
293 #ifdef DEBUG_IOCTL_INFO
294 printk(KERN_DEBUG
"%s: update_psa_checksum(): crc = 0x%02x%02x\n",
295 dev
->name
, psa
.psa_crc
[0], psa
.psa_crc
[1]);
297 /* Check again (luxury !) */
298 crc
= psa_crc((unsigned char *) &psa
,
299 sizeof(psa
) - sizeof(psa
.psa_crc_status
));
303 "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n",
305 #endif /* DEBUG_IOCTL_INFO */
306 #endif /* SET_PSA_CRC */
307 } /* update_psa_checksum */
309 /*------------------------------------------------------------------*/
311 * Write 1 byte to the MMC.
313 static inline void mmc_out(unsigned long ioaddr
, u16 o
, u8 d
)
317 /* Wait for MMC to go idle */
318 while ((count
++ < 100) && (inw(HASR(ioaddr
)) & HASR_MMC_BUSY
))
321 outw((u16
) (((u16
) d
<< 8) | (o
<< 1) | 1), MMCR(ioaddr
));
324 /*------------------------------------------------------------------*/
326 * Routine to write bytes to the Modem Management Controller.
327 * We start at the end because it is the way it should be!
329 static inline void mmc_write(unsigned long ioaddr
, u8 o
, u8
* b
, int n
)
335 mmc_out(ioaddr
, --o
, *(--b
));
338 /*------------------------------------------------------------------*/
340 * Read a byte from the MMC.
341 * Optimised version for 1 byte, avoid using memory.
343 static inline u8
mmc_in(unsigned long ioaddr
, u16 o
)
347 while ((count
++ < 100) && (inw(HASR(ioaddr
)) & HASR_MMC_BUSY
))
349 outw(o
<< 1, MMCR(ioaddr
));
351 while ((count
++ < 100) && (inw(HASR(ioaddr
)) & HASR_MMC_BUSY
))
353 return (u8
) (inw(MMCR(ioaddr
)) >> 8);
356 /*------------------------------------------------------------------*/
358 * Routine to read bytes from the Modem Management Controller.
359 * The implementation is complicated by a lack of address lines,
360 * which prevents decoding of the low-order bit.
361 * (code has just been moved in the above function)
362 * We start at the end because it is the way it should be!
364 static inline void mmc_read(unsigned long ioaddr
, u8 o
, u8
* b
, int n
)
370 *(--b
) = mmc_in(ioaddr
, --o
);
373 /*------------------------------------------------------------------*/
375 * Get the type of encryption available.
377 static inline int mmc_encr(unsigned long ioaddr
)
378 { /* I/O port of the card */
381 temp
= mmc_in(ioaddr
, mmroff(0, mmr_des_avail
));
382 if ((temp
!= MMR_DES_AVAIL_DES
) && (temp
!= MMR_DES_AVAIL_AES
))
388 /*------------------------------------------------------------------*/
390 * Wait for the frequency EEPROM to complete a command.
391 * I hope this one will be optimally inlined.
393 static inline void fee_wait(unsigned long ioaddr
, /* I/O port of the card */
394 int delay
, /* Base delay to wait for */
396 { /* Number of time to wait */
397 int count
= 0; /* Wait only a limited time */
399 while ((count
++ < number
) &&
400 (mmc_in(ioaddr
, mmroff(0, mmr_fee_status
)) &
401 MMR_FEE_STATUS_BUSY
)) udelay(delay
);
404 /*------------------------------------------------------------------*/
406 * Read bytes from the Frequency EEPROM (frequency select cards).
408 static void fee_read(unsigned long ioaddr
, /* I/O port of the card */
409 u16 o
, /* destination offset */
410 u16
* b
, /* data buffer */
412 { /* number of registers */
413 b
+= n
; /* Position at the end of the area */
415 /* Write the address */
416 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), o
+ n
- 1);
418 /* Loop on all buffer */
420 /* Write the read command */
421 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
),
424 /* Wait until EEPROM is ready (should be quick). */
425 fee_wait(ioaddr
, 10, 100);
427 /* Read the value. */
428 *--b
= ((mmc_in(ioaddr
, mmroff(0, mmr_fee_data_h
)) << 8) |
429 mmc_in(ioaddr
, mmroff(0, mmr_fee_data_l
)));
433 #ifdef WIRELESS_EXT /* if the wireless extension exists in the kernel */
435 /*------------------------------------------------------------------*/
437 * Write bytes from the Frequency EEPROM (frequency select cards).
438 * This is a bit complicated, because the frequency EEPROM has to
439 * be unprotected and the write enabled.
442 static void fee_write(unsigned long ioaddr
, /* I/O port of the card */
443 u16 o
, /* destination offset */
444 u16
* b
, /* data buffer */
446 { /* number of registers */
447 b
+= n
; /* Position at the end of the area. */
449 #ifdef EEPROM_IS_PROTECTED /* disabled */
450 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
451 /* Ask to read the protected register */
452 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
), MMW_FEE_CTRL_PRREAD
);
454 fee_wait(ioaddr
, 10, 100);
456 /* Read the protected register. */
457 printk("Protected 2: %02X-%02X\n",
458 mmc_in(ioaddr
, mmroff(0, mmr_fee_data_h
)),
459 mmc_in(ioaddr
, mmroff(0, mmr_fee_data_l
)));
460 #endif /* DOESNT_SEEM_TO_WORK */
462 /* Enable protected register. */
463 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), MMW_FEE_ADDR_EN
);
464 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
), MMW_FEE_CTRL_PREN
);
466 fee_wait(ioaddr
, 10, 100);
468 /* Unprotect area. */
469 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), o
+ n
);
470 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
), MMW_FEE_CTRL_PRWRITE
);
471 #ifdef DOESNT_SEEM_TO_WORK /* disabled */
473 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
), MMW_FEE_CTRL_PRCLEAR
);
474 #endif /* DOESNT_SEEM_TO_WORK */
476 fee_wait(ioaddr
, 10, 100);
477 #endif /* EEPROM_IS_PROTECTED */
480 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), MMW_FEE_ADDR_EN
);
481 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
), MMW_FEE_CTRL_WREN
);
483 fee_wait(ioaddr
, 10, 100);
485 /* Write the EEPROM address. */
486 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), o
+ n
- 1);
488 /* Loop on all buffer */
490 /* Write the value. */
491 mmc_out(ioaddr
, mmwoff(0, mmw_fee_data_h
), (*--b
) >> 8);
492 mmc_out(ioaddr
, mmwoff(0, mmw_fee_data_l
), *b
& 0xFF);
494 /* Write the write command. */
495 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
),
498 /* WaveLAN documentation says to wait at least 10 ms for EEBUSY = 0 */
500 fee_wait(ioaddr
, 10, 100);
504 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), MMW_FEE_ADDR_DS
);
505 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
), MMW_FEE_CTRL_WDS
);
507 fee_wait(ioaddr
, 10, 100);
509 #ifdef EEPROM_IS_PROTECTED /* disabled */
510 /* Reprotect EEPROM. */
511 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), 0x00);
512 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
), MMW_FEE_CTRL_PRWRITE
);
514 fee_wait(ioaddr
, 10, 100);
515 #endif /* EEPROM_IS_PROTECTED */
517 #endif /* WIRELESS_EXT */
519 /************************ I82586 SUBROUTINES *************************/
521 * Useful subroutines to manage the Ethernet controller
524 /*------------------------------------------------------------------*/
526 * Read bytes from the on-board RAM.
527 * Why does inlining this function make it fail?
529 static /*inline */ void obram_read(unsigned long ioaddr
,
530 u16 o
, u8
* b
, int n
)
532 outw(o
, PIOR1(ioaddr
));
533 insw(PIOP1(ioaddr
), (unsigned short *) b
, (n
+ 1) >> 1);
536 /*------------------------------------------------------------------*/
538 * Write bytes to the on-board RAM.
540 static inline void obram_write(unsigned long ioaddr
, u16 o
, u8
* b
, int n
)
542 outw(o
, PIOR1(ioaddr
));
543 outsw(PIOP1(ioaddr
), (unsigned short *) b
, (n
+ 1) >> 1);
546 /*------------------------------------------------------------------*/
548 * Acknowledge the reading of the status issued by the i82586.
550 static void wv_ack(struct net_device
* dev
)
552 net_local
*lp
= (net_local
*) dev
->priv
;
553 unsigned long ioaddr
= dev
->base_addr
;
557 obram_read(ioaddr
, scboff(OFFSET_SCB
, scb_status
),
558 (unsigned char *) &scb_cs
, sizeof(scb_cs
));
559 scb_cs
&= SCB_ST_INT
;
564 obram_write(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
565 (unsigned char *) &scb_cs
, sizeof(scb_cs
));
567 set_chan_attn(ioaddr
, lp
->hacr
);
569 for (i
= 1000; i
> 0; i
--) {
570 obram_read(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
571 (unsigned char *) &scb_cs
, sizeof(scb_cs
));
579 #ifdef DEBUG_CONFIG_ERROR
582 "%s: wv_ack(): board not accepting command.\n",
587 /*------------------------------------------------------------------*/
589 * Set channel attention bit and busy wait until command has
590 * completed, then acknowledge completion of the command.
592 static inline int wv_synchronous_cmd(struct net_device
* dev
, const char *str
)
594 net_local
*lp
= (net_local
*) dev
->priv
;
595 unsigned long ioaddr
= dev
->base_addr
;
600 scb_cmd
= SCB_CMD_CUC
& SCB_CMD_CUC_GO
;
601 obram_write(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
602 (unsigned char *) &scb_cmd
, sizeof(scb_cmd
));
604 set_chan_attn(ioaddr
, lp
->hacr
);
606 for (i
= 1000; i
> 0; i
--) {
607 obram_read(ioaddr
, OFFSET_CU
, (unsigned char *) &cb
,
609 if (cb
.ac_status
& AC_SFLD_C
)
616 if (i
<= 0 || !(cb
.ac_status
& AC_SFLD_OK
)) {
617 #ifdef DEBUG_CONFIG_ERROR
618 printk(KERN_INFO
"%s: %s failed; status = 0x%x\n",
619 dev
->name
, str
, cb
.ac_status
);
621 #ifdef DEBUG_I82586_SHOW
633 /*------------------------------------------------------------------*/
635 * Configuration commands completion interrupt.
636 * Check if done, and if OK.
639 wv_config_complete(struct net_device
* dev
, unsigned long ioaddr
, net_local
* lp
)
641 unsigned short mcs_addr
;
642 unsigned short status
;
645 #ifdef DEBUG_INTERRUPT_TRACE
646 printk(KERN_DEBUG
"%s: ->wv_config_complete()\n", dev
->name
);
649 mcs_addr
= lp
->tx_first_in_use
+ sizeof(ac_tx_t
) + sizeof(ac_nop_t
)
650 + sizeof(tbd_t
) + sizeof(ac_cfg_t
) + sizeof(ac_ias_t
);
652 /* Read the status of the last command (set mc list). */
653 obram_read(ioaddr
, acoff(mcs_addr
, ac_status
),
654 (unsigned char *) &status
, sizeof(status
));
656 /* If not completed -> exit */
657 if ((status
& AC_SFLD_C
) == 0)
658 ret
= 0; /* Not ready to be scrapped */
660 #ifdef DEBUG_CONFIG_ERROR
661 unsigned short cfg_addr
;
662 unsigned short ias_addr
;
664 /* Check mc_config command */
665 if ((status
& AC_SFLD_OK
) != AC_SFLD_OK
)
667 "%s: wv_config_complete(): set_multicast_address failed; status = 0x%x\n",
670 /* check ia-config command */
671 ias_addr
= mcs_addr
- sizeof(ac_ias_t
);
672 obram_read(ioaddr
, acoff(ias_addr
, ac_status
),
673 (unsigned char *) &status
, sizeof(status
));
674 if ((status
& AC_SFLD_OK
) != AC_SFLD_OK
)
676 "%s: wv_config_complete(): set_MAC_address failed; status = 0x%x\n",
679 /* Check config command. */
680 cfg_addr
= ias_addr
- sizeof(ac_cfg_t
);
681 obram_read(ioaddr
, acoff(cfg_addr
, ac_status
),
682 (unsigned char *) &status
, sizeof(status
));
683 if ((status
& AC_SFLD_OK
) != AC_SFLD_OK
)
685 "%s: wv_config_complete(): configure failed; status = 0x%x\n",
687 #endif /* DEBUG_CONFIG_ERROR */
689 ret
= 1; /* Ready to be scrapped */
692 #ifdef DEBUG_INTERRUPT_TRACE
693 printk(KERN_DEBUG
"%s: <-wv_config_complete() - %d\n", dev
->name
,
699 /*------------------------------------------------------------------*/
701 * Command completion interrupt.
702 * Reclaim as many freed tx buffers as we can.
703 * (called in wavelan_interrupt()).
704 * Note : the spinlock is already grabbed for us.
706 static int wv_complete(struct net_device
* dev
, unsigned long ioaddr
, net_local
* lp
)
710 #ifdef DEBUG_INTERRUPT_TRACE
711 printk(KERN_DEBUG
"%s: ->wv_complete()\n", dev
->name
);
714 /* Loop on all the transmit buffers */
715 while (lp
->tx_first_in_use
!= I82586NULL
) {
716 unsigned short tx_status
;
718 /* Read the first transmit buffer */
719 obram_read(ioaddr
, acoff(lp
->tx_first_in_use
, ac_status
),
720 (unsigned char *) &tx_status
,
723 /* If not completed -> exit */
724 if ((tx_status
& AC_SFLD_C
) == 0)
727 /* Hack for reconfiguration */
728 if (tx_status
== 0xFFFF)
729 if (!wv_config_complete(dev
, ioaddr
, lp
))
730 break; /* Not completed */
732 /* We now remove this buffer */
737 if (lp->tx_n_in_use > 0)
738 printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
741 /* Was it the last one? */
742 if (lp
->tx_n_in_use
<= 0)
743 lp
->tx_first_in_use
= I82586NULL
;
745 /* Next one in the chain */
746 lp
->tx_first_in_use
+= TXBLOCKZ
;
747 if (lp
->tx_first_in_use
>=
749 NTXBLOCKS
* TXBLOCKZ
) lp
->tx_first_in_use
-=
750 NTXBLOCKS
* TXBLOCKZ
;
753 /* Hack for reconfiguration */
754 if (tx_status
== 0xFFFF)
757 /* Now, check status of the finished command */
758 if (tx_status
& AC_SFLD_OK
) {
761 lp
->stats
.tx_packets
++;
762 ncollisions
= tx_status
& AC_SFLD_MAXCOL
;
763 lp
->stats
.collisions
+= ncollisions
;
767 "%s: wv_complete(): tx completed after %d collisions.\n",
768 dev
->name
, ncollisions
);
771 lp
->stats
.tx_errors
++;
772 if (tx_status
& AC_SFLD_S10
) {
773 lp
->stats
.tx_carrier_errors
++;
776 "%s: wv_complete(): tx error: no CS.\n",
780 if (tx_status
& AC_SFLD_S9
) {
781 lp
->stats
.tx_carrier_errors
++;
784 "%s: wv_complete(): tx error: lost CTS.\n",
788 if (tx_status
& AC_SFLD_S8
) {
789 lp
->stats
.tx_fifo_errors
++;
792 "%s: wv_complete(): tx error: slow DMA.\n",
796 if (tx_status
& AC_SFLD_S6
) {
797 lp
->stats
.tx_heartbeat_errors
++;
800 "%s: wv_complete(): tx error: heart beat.\n",
804 if (tx_status
& AC_SFLD_S5
) {
805 lp
->stats
.tx_aborted_errors
++;
808 "%s: wv_complete(): tx error: too many collisions.\n",
816 "%s: wv_complete(): tx completed, tx_status 0x%04x\n",
817 dev
->name
, tx_status
);
821 #ifdef DEBUG_INTERRUPT_INFO
823 printk(KERN_DEBUG
"%s: wv_complete(): reaped %d\n",
828 * Inform upper layers.
830 if (lp
->tx_n_in_use
< NTXBLOCKS
- 1) {
831 netif_wake_queue(dev
);
833 #ifdef DEBUG_INTERRUPT_TRACE
834 printk(KERN_DEBUG
"%s: <-wv_complete()\n", dev
->name
);
839 /*------------------------------------------------------------------*/
841 * Reconfigure the i82586, or at least ask for it.
842 * Because wv_82586_config uses a transmission buffer, we must do it
843 * when we are sure that there is one left, so we do it now
844 * or in wavelan_packet_xmit() (I can't find any better place,
845 * wavelan_interrupt is not an option), so you may experience
848 static inline void wv_82586_reconfig(struct net_device
* dev
)
850 net_local
*lp
= (net_local
*) dev
->priv
;
853 /* Arm the flag, will be cleard in wv_82586_config() */
854 lp
->reconfig_82586
= 1;
856 /* Check if we can do it now ! */
857 if((netif_running(dev
)) && !(netif_queue_stopped(dev
))) {
858 spin_lock_irqsave(&lp
->spinlock
, flags
);
860 wv_82586_config(dev
);
861 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
864 #ifdef DEBUG_CONFIG_INFO
866 "%s: wv_82586_reconfig(): delayed (state = %lX)\n",
867 dev
->name
, dev
->state
);
872 /********************* DEBUG & INFO SUBROUTINES *********************/
874 * This routine is used in the code to show information for debugging.
875 * Most of the time, it dumps the contents of hardware structures.
878 #ifdef DEBUG_PSA_SHOW
879 /*------------------------------------------------------------------*/
881 * Print the formatted contents of the Parameter Storage Area.
883 static void wv_psa_show(psa_t
* p
)
885 printk(KERN_DEBUG
"##### WaveLAN PSA contents: #####\n");
886 printk(KERN_DEBUG
"psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
887 p
->psa_io_base_addr_1
,
888 p
->psa_io_base_addr_2
,
889 p
->psa_io_base_addr_3
, p
->psa_io_base_addr_4
);
890 printk(KERN_DEBUG
"psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
891 p
->psa_rem_boot_addr_1
,
892 p
->psa_rem_boot_addr_2
, p
->psa_rem_boot_addr_3
);
893 printk(KERN_DEBUG
"psa_holi_params: 0x%02x, ", p
->psa_holi_params
);
894 printk("psa_int_req_no: %d\n", p
->psa_int_req_no
);
895 #ifdef DEBUG_SHOW_UNUSED
897 "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
898 p
->psa_unused0
[0], p
->psa_unused0
[1], p
->psa_unused0
[2],
899 p
->psa_unused0
[3], p
->psa_unused0
[4], p
->psa_unused0
[5],
901 #endif /* DEBUG_SHOW_UNUSED */
903 "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
904 p
->psa_univ_mac_addr
[0], p
->psa_univ_mac_addr
[1],
905 p
->psa_univ_mac_addr
[2], p
->psa_univ_mac_addr
[3],
906 p
->psa_univ_mac_addr
[4], p
->psa_univ_mac_addr
[5]);
908 "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
909 p
->psa_local_mac_addr
[0], p
->psa_local_mac_addr
[1],
910 p
->psa_local_mac_addr
[2], p
->psa_local_mac_addr
[3],
911 p
->psa_local_mac_addr
[4], p
->psa_local_mac_addr
[5]);
912 printk(KERN_DEBUG
"psa_univ_local_sel: %d, ",
913 p
->psa_univ_local_sel
);
914 printk("psa_comp_number: %d, ", p
->psa_comp_number
);
915 printk("psa_thr_pre_set: 0x%02x\n", p
->psa_thr_pre_set
);
916 printk(KERN_DEBUG
"psa_feature_select/decay_prm: 0x%02x, ",
917 p
->psa_feature_select
);
918 printk("psa_subband/decay_update_prm: %d\n", p
->psa_subband
);
919 printk(KERN_DEBUG
"psa_quality_thr: 0x%02x, ", p
->psa_quality_thr
);
920 printk("psa_mod_delay: 0x%02x\n", p
->psa_mod_delay
);
921 printk(KERN_DEBUG
"psa_nwid: 0x%02x%02x, ", p
->psa_nwid
[0],
923 printk("psa_nwid_select: %d\n", p
->psa_nwid_select
);
924 printk(KERN_DEBUG
"psa_encryption_select: %d, ",
925 p
->psa_encryption_select
);
927 ("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
928 p
->psa_encryption_key
[0], p
->psa_encryption_key
[1],
929 p
->psa_encryption_key
[2], p
->psa_encryption_key
[3],
930 p
->psa_encryption_key
[4], p
->psa_encryption_key
[5],
931 p
->psa_encryption_key
[6], p
->psa_encryption_key
[7]);
932 printk(KERN_DEBUG
"psa_databus_width: %d\n", p
->psa_databus_width
);
933 printk(KERN_DEBUG
"psa_call_code/auto_squelch: 0x%02x, ",
934 p
->psa_call_code
[0]);
936 ("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
937 p
->psa_call_code
[0], p
->psa_call_code
[1], p
->psa_call_code
[2],
938 p
->psa_call_code
[3], p
->psa_call_code
[4], p
->psa_call_code
[5],
939 p
->psa_call_code
[6], p
->psa_call_code
[7]);
940 #ifdef DEBUG_SHOW_UNUSED
941 printk(KERN_DEBUG
"psa_reserved[]: %02X:%02X:%02X:%02X\n",
943 p
->psa_reserved
[1], p
->psa_reserved
[2], p
->psa_reserved
[3]);
944 #endif /* DEBUG_SHOW_UNUSED */
945 printk(KERN_DEBUG
"psa_conf_status: %d, ", p
->psa_conf_status
);
946 printk("psa_crc: 0x%02x%02x, ", p
->psa_crc
[0], p
->psa_crc
[1]);
947 printk("psa_crc_status: 0x%02x\n", p
->psa_crc_status
);
949 #endif /* DEBUG_PSA_SHOW */
951 #ifdef DEBUG_MMC_SHOW
952 /*------------------------------------------------------------------*/
954 * Print the formatted status of the Modem Management Controller.
955 * This function needs to be completed.
957 static void wv_mmc_show(struct net_device
* dev
)
959 unsigned long ioaddr
= dev
->base_addr
;
960 net_local
*lp
= (net_local
*) dev
->priv
;
964 if (hasr_read(ioaddr
) & HASR_NO_CLK
) {
966 "%s: wv_mmc_show: modem not connected\n",
972 mmc_out(ioaddr
, mmwoff(0, mmw_freeze
), 1);
973 mmc_read(ioaddr
, 0, (u8
*) & m
, sizeof(m
));
974 mmc_out(ioaddr
, mmwoff(0, mmw_freeze
), 0);
976 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
977 /* Don't forget to update statistics */
978 lp
->wstats
.discard
.nwid
+=
979 (m
.mmr_wrong_nwid_h
<< 8) | m
.mmr_wrong_nwid_l
;
980 #endif /* WIRELESS_EXT */
982 printk(KERN_DEBUG
"##### WaveLAN modem status registers: #####\n");
983 #ifdef DEBUG_SHOW_UNUSED
985 "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
986 m
.mmr_unused0
[0], m
.mmr_unused0
[1], m
.mmr_unused0
[2],
987 m
.mmr_unused0
[3], m
.mmr_unused0
[4], m
.mmr_unused0
[5],
988 m
.mmr_unused0
[6], m
.mmr_unused0
[7]);
989 #endif /* DEBUG_SHOW_UNUSED */
990 printk(KERN_DEBUG
"Encryption algorithm: %02X - Status: %02X\n",
991 m
.mmr_des_avail
, m
.mmr_des_status
);
992 #ifdef DEBUG_SHOW_UNUSED
993 printk(KERN_DEBUG
"mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
996 m
.mmr_unused1
[2], m
.mmr_unused1
[3], m
.mmr_unused1
[4]);
997 #endif /* DEBUG_SHOW_UNUSED */
998 printk(KERN_DEBUG
"dce_status: 0x%x [%s%s%s%s]\n",
1001 mmr_dce_status
& MMR_DCE_STATUS_RX_BUSY
) ?
1002 "energy detected," : "",
1004 mmr_dce_status
& MMR_DCE_STATUS_LOOPT_IND
) ?
1005 "loop test indicated," : "",
1007 mmr_dce_status
& MMR_DCE_STATUS_TX_BUSY
) ?
1008 "transmitter on," : "",
1010 mmr_dce_status
& MMR_DCE_STATUS_JBR_EXPIRED
) ?
1011 "jabber timer expired," : "");
1012 printk(KERN_DEBUG
"Dsp ID: %02X\n", m
.mmr_dsp_id
);
1013 #ifdef DEBUG_SHOW_UNUSED
1014 printk(KERN_DEBUG
"mmc_unused2[]: %02X:%02X\n",
1015 m
.mmr_unused2
[0], m
.mmr_unused2
[1]);
1016 #endif /* DEBUG_SHOW_UNUSED */
1017 printk(KERN_DEBUG
"# correct_nwid: %d, # wrong_nwid: %d\n",
1018 (m
.mmr_correct_nwid_h
<< 8) | m
.mmr_correct_nwid_l
,
1019 (m
.mmr_wrong_nwid_h
<< 8) | m
.mmr_wrong_nwid_l
);
1020 printk(KERN_DEBUG
"thr_pre_set: 0x%x [current signal %s]\n",
1021 m
.mmr_thr_pre_set
& MMR_THR_PRE_SET
,
1023 mmr_thr_pre_set
& MMR_THR_PRE_SET_CUR
) ? "above" :
1025 printk(KERN_DEBUG
"signal_lvl: %d [%s], ",
1026 m
.mmr_signal_lvl
& MMR_SIGNAL_LVL
,
1028 mmr_signal_lvl
& MMR_SIGNAL_LVL_VALID
) ? "new msg" :
1030 printk("silence_lvl: %d [%s], ",
1031 m
.mmr_silence_lvl
& MMR_SILENCE_LVL
,
1033 mmr_silence_lvl
& MMR_SILENCE_LVL_VALID
) ? "update done" :
1035 printk("sgnl_qual: 0x%x [%s]\n", m
.mmr_sgnl_qual
& MMR_SGNL_QUAL
,
1037 mmr_sgnl_qual
& MMR_SGNL_QUAL_ANT
) ? "Antenna 1" :
1039 #ifdef DEBUG_SHOW_UNUSED
1040 printk(KERN_DEBUG
"netw_id_l: %x\n", m
.mmr_netw_id_l
);
1041 #endif /* DEBUG_SHOW_UNUSED */
1043 #endif /* DEBUG_MMC_SHOW */
1045 #ifdef DEBUG_I82586_SHOW
1046 /*------------------------------------------------------------------*/
1048 * Print the last block of the i82586 memory.
1050 static void wv_scb_show(unsigned long ioaddr
)
1054 obram_read(ioaddr
, OFFSET_SCB
, (unsigned char *) &scb
,
1057 printk(KERN_DEBUG
"##### WaveLAN system control block: #####\n");
1059 printk(KERN_DEBUG
"status: ");
1060 printk("stat 0x%x[%s%s%s%s] ",
1062 scb_status
& (SCB_ST_CX
| SCB_ST_FR
| SCB_ST_CNA
|
1065 scb_status
& SCB_ST_CX
) ? "command completion interrupt," :
1066 "", (scb
.scb_status
& SCB_ST_FR
) ? "frame received," : "",
1068 scb_status
& SCB_ST_CNA
) ? "command unit not active," : "",
1070 scb_status
& SCB_ST_RNR
) ? "receiving unit not ready," :
1072 printk("cus 0x%x[%s%s%s] ", (scb
.scb_status
& SCB_ST_CUS
) >> 8,
1073 ((scb
.scb_status
& SCB_ST_CUS
) ==
1074 SCB_ST_CUS_IDLE
) ? "idle" : "",
1075 ((scb
.scb_status
& SCB_ST_CUS
) ==
1076 SCB_ST_CUS_SUSP
) ? "suspended" : "",
1077 ((scb
.scb_status
& SCB_ST_CUS
) ==
1078 SCB_ST_CUS_ACTV
) ? "active" : "");
1079 printk("rus 0x%x[%s%s%s%s]\n", (scb
.scb_status
& SCB_ST_RUS
) >> 4,
1080 ((scb
.scb_status
& SCB_ST_RUS
) ==
1081 SCB_ST_RUS_IDLE
) ? "idle" : "",
1082 ((scb
.scb_status
& SCB_ST_RUS
) ==
1083 SCB_ST_RUS_SUSP
) ? "suspended" : "",
1084 ((scb
.scb_status
& SCB_ST_RUS
) ==
1085 SCB_ST_RUS_NRES
) ? "no resources" : "",
1086 ((scb
.scb_status
& SCB_ST_RUS
) ==
1087 SCB_ST_RUS_RDY
) ? "ready" : "");
1089 printk(KERN_DEBUG
"command: ");
1090 printk("ack 0x%x[%s%s%s%s] ",
1092 scb_command
& (SCB_CMD_ACK_CX
| SCB_CMD_ACK_FR
|
1093 SCB_CMD_ACK_CNA
| SCB_CMD_ACK_RNR
)) >> 12,
1095 scb_command
& SCB_CMD_ACK_CX
) ? "ack cmd completion," : "",
1097 scb_command
& SCB_CMD_ACK_FR
) ? "ack frame received," : "",
1099 scb_command
& SCB_CMD_ACK_CNA
) ? "ack CU not active," : "",
1101 scb_command
& SCB_CMD_ACK_RNR
) ? "ack RU not ready," : "");
1102 printk("cuc 0x%x[%s%s%s%s%s] ",
1103 (scb
.scb_command
& SCB_CMD_CUC
) >> 8,
1104 ((scb
.scb_command
& SCB_CMD_CUC
) ==
1105 SCB_CMD_CUC_NOP
) ? "nop" : "",
1106 ((scb
.scb_command
& SCB_CMD_CUC
) ==
1107 SCB_CMD_CUC_GO
) ? "start cbl_offset" : "",
1108 ((scb
.scb_command
& SCB_CMD_CUC
) ==
1109 SCB_CMD_CUC_RES
) ? "resume execution" : "",
1110 ((scb
.scb_command
& SCB_CMD_CUC
) ==
1111 SCB_CMD_CUC_SUS
) ? "suspend execution" : "",
1112 ((scb
.scb_command
& SCB_CMD_CUC
) ==
1113 SCB_CMD_CUC_ABT
) ? "abort execution" : "");
1114 printk("ruc 0x%x[%s%s%s%s%s]\n",
1115 (scb
.scb_command
& SCB_CMD_RUC
) >> 4,
1116 ((scb
.scb_command
& SCB_CMD_RUC
) ==
1117 SCB_CMD_RUC_NOP
) ? "nop" : "",
1118 ((scb
.scb_command
& SCB_CMD_RUC
) ==
1119 SCB_CMD_RUC_GO
) ? "start rfa_offset" : "",
1120 ((scb
.scb_command
& SCB_CMD_RUC
) ==
1121 SCB_CMD_RUC_RES
) ? "resume reception" : "",
1122 ((scb
.scb_command
& SCB_CMD_RUC
) ==
1123 SCB_CMD_RUC_SUS
) ? "suspend reception" : "",
1124 ((scb
.scb_command
& SCB_CMD_RUC
) ==
1125 SCB_CMD_RUC_ABT
) ? "abort reception" : "");
1127 printk(KERN_DEBUG
"cbl_offset 0x%x ", scb
.scb_cbl_offset
);
1128 printk("rfa_offset 0x%x\n", scb
.scb_rfa_offset
);
1130 printk(KERN_DEBUG
"crcerrs %d ", scb
.scb_crcerrs
);
1131 printk("alnerrs %d ", scb
.scb_alnerrs
);
1132 printk("rscerrs %d ", scb
.scb_rscerrs
);
1133 printk("ovrnerrs %d\n", scb
.scb_ovrnerrs
);
1136 /*------------------------------------------------------------------*/
1138 * Print the formatted status of the i82586's receive unit.
1140 static void wv_ru_show(struct net_device
* dev
)
1142 /* net_local *lp = (net_local *) dev->priv; */
1145 "##### WaveLAN i82586 receiver unit status: #####\n");
1146 printk(KERN_DEBUG
"ru:");
1148 * Not implemented yet
1153 /*------------------------------------------------------------------*/
1155 * Display info about one control block of the i82586 memory.
1157 static void wv_cu_show_one(struct net_device
* dev
, net_local
* lp
, int i
, u16 p
)
1159 unsigned long ioaddr
;
1162 ioaddr
= dev
->base_addr
;
1164 printk("%d: 0x%x:", i
, p
);
1166 obram_read(ioaddr
, p
, (unsigned char *) &actx
, sizeof(actx
));
1167 printk(" status=0x%x,", actx
.tx_h
.ac_status
);
1168 printk(" command=0x%x,", actx
.tx_h
.ac_command
);
1174 obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
1175 printk(" tbd_status=0x%x,", tbd.tbd_status);
1182 /*------------------------------------------------------------------*/
1184 * Print status of the command unit of the i82586.
1186 static void wv_cu_show(struct net_device
* dev
)
1188 net_local
*lp
= (net_local
*) dev
->priv
;
1193 "##### WaveLAN i82586 command unit status: #####\n");
1196 for (i
= 0, p
= lp
->tx_first_in_use
; i
< NTXBLOCKS
; i
++) {
1197 wv_cu_show_one(dev
, lp
, i
, p
);
1200 if (p
>= OFFSET_CU
+ NTXBLOCKS
* TXBLOCKZ
)
1201 p
-= NTXBLOCKS
* TXBLOCKZ
;
1205 #endif /* DEBUG_I82586_SHOW */
1207 #ifdef DEBUG_DEVICE_SHOW
1208 /*------------------------------------------------------------------*/
1210 * Print the formatted status of the WaveLAN PCMCIA device driver.
1212 static void wv_dev_show(struct net_device
* dev
)
1214 printk(KERN_DEBUG
"dev:");
1215 printk(" state=%lX,", dev
->state
);
1216 printk(" trans_start=%ld,", dev
->trans_start
);
1217 printk(" flags=0x%x,", dev
->flags
);
1221 /*------------------------------------------------------------------*/
1223 * Print the formatted status of the WaveLAN PCMCIA device driver's
1224 * private information.
1226 static void wv_local_show(struct net_device
* dev
)
1230 lp
= (net_local
*) dev
->priv
;
1232 printk(KERN_DEBUG
"local:");
1233 printk(" tx_n_in_use=%d,", lp
->tx_n_in_use
);
1234 printk(" hacr=0x%x,", lp
->hacr
);
1235 printk(" rx_head=0x%x,", lp
->rx_head
);
1236 printk(" rx_last=0x%x,", lp
->rx_last
);
1237 printk(" tx_first_free=0x%x,", lp
->tx_first_free
);
1238 printk(" tx_first_in_use=0x%x,", lp
->tx_first_in_use
);
1240 } /* wv_local_show */
1241 #endif /* DEBUG_DEVICE_SHOW */
1243 #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1244 /*------------------------------------------------------------------*/
1246 * Dump packet header (and content if necessary) on the screen
1248 static inline void wv_packet_info(u8
* p
, /* Packet to dump */
1249 int length
, /* Length of the packet */
1250 char *msg1
, /* Name of the device */
1252 { /* Name of the function */
1257 "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1258 msg1
, msg2
, p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], length
);
1260 "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1261 msg1
, msg2
, p
[6], p
[7], p
[8], p
[9], p
[10], p
[11], p
[12],
1264 #ifdef DEBUG_PACKET_DUMP
1266 printk(KERN_DEBUG
"data=\"");
1268 if ((maxi
= length
) > DEBUG_PACKET_DUMP
)
1269 maxi
= DEBUG_PACKET_DUMP
;
1270 for (i
= 14; i
< maxi
; i
++)
1271 if (p
[i
] >= ' ' && p
[i
] <= '~')
1272 printk(" %c", p
[i
]);
1274 printk("%02X", p
[i
]);
1278 printk(KERN_DEBUG
"\n");
1279 #endif /* DEBUG_PACKET_DUMP */
1281 #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1283 /*------------------------------------------------------------------*/
1285 * This is the information which is displayed by the driver at startup.
1286 * There are lots of flags for configuring it to your liking.
1288 static inline void wv_init_info(struct net_device
* dev
)
1290 short ioaddr
= dev
->base_addr
;
1291 net_local
*lp
= (net_local
*) dev
->priv
;
1295 /* Read the parameter storage area */
1296 psa_read(ioaddr
, lp
->hacr
, 0, (unsigned char *) &psa
, sizeof(psa
));
1298 #ifdef DEBUG_PSA_SHOW
1301 #ifdef DEBUG_MMC_SHOW
1304 #ifdef DEBUG_I82586_SHOW
1308 #ifdef DEBUG_BASIC_SHOW
1309 /* Now, let's go for the basic stuff. */
1310 printk(KERN_NOTICE
"%s: WaveLAN at %#x,", dev
->name
, ioaddr
);
1311 for (i
= 0; i
< WAVELAN_ADDR_SIZE
; i
++)
1312 printk("%s%02X", (i
== 0) ? " " : ":", dev
->dev_addr
[i
]);
1313 printk(", IRQ %d", dev
->irq
);
1315 /* Print current network ID. */
1316 if (psa
.psa_nwid_select
)
1317 printk(", nwid 0x%02X-%02X", psa
.psa_nwid
[0],
1320 printk(", nwid off");
1323 if (!(mmc_in(ioaddr
, mmroff(0, mmr_fee_status
)) &
1324 (MMR_FEE_STATUS_DWLD
| MMR_FEE_STATUS_BUSY
))) {
1325 unsigned short freq
;
1327 /* Ask the EEPROM to read the frequency from the first area. */
1328 fee_read(ioaddr
, 0x00, &freq
, 1);
1330 /* Print frequency */
1331 printk(", 2.00, %ld", (freq
>> 6) + 2400L);
1338 switch (psa
.psa_comp_number
) {
1339 case PSA_COMP_PC_AT_915
:
1340 case PSA_COMP_PC_AT_2400
:
1343 case PSA_COMP_PC_MC_915
:
1344 case PSA_COMP_PC_MC_2400
:
1347 case PSA_COMP_PCMCIA_915
:
1354 switch (psa
.psa_subband
) {
1355 case PSA_SUBBAND_915
:
1358 case PSA_SUBBAND_2425
:
1361 case PSA_SUBBAND_2460
:
1364 case PSA_SUBBAND_2484
:
1367 case PSA_SUBBAND_2430_5
:
1376 #endif /* DEBUG_BASIC_SHOW */
1378 #ifdef DEBUG_VERSION_SHOW
1379 /* Print version information */
1380 printk(KERN_NOTICE
"%s", version
);
1382 } /* wv_init_info */
1384 /********************* IOCTL, STATS & RECONFIG *********************/
1386 * We found here routines that are called by Linux on different
1387 * occasions after the configuration and not for transmitting data
1388 * These may be called when the user use ifconfig, /proc/net/dev
1389 * or wireless extensions
1392 /*------------------------------------------------------------------*/
1394 * Get the current Ethernet statistics. This may be called with the
1395 * card open or closed.
1396 * Used when the user read /proc/net/dev
1398 static en_stats
*wavelan_get_stats(struct net_device
* dev
)
1400 #ifdef DEBUG_IOCTL_TRACE
1401 printk(KERN_DEBUG
"%s: <>wavelan_get_stats()\n", dev
->name
);
1404 return (&((net_local
*) dev
->priv
)->stats
);
1407 /*------------------------------------------------------------------*/
1409 * Set or clear the multicast filter for this adaptor.
1410 * num_addrs == -1 Promiscuous mode, receive all packets
1411 * num_addrs == 0 Normal mode, clear multicast list
1412 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1413 * and do best-effort filtering.
1415 static void wavelan_set_multicast_list(struct net_device
* dev
)
1417 net_local
*lp
= (net_local
*) dev
->priv
;
1419 #ifdef DEBUG_IOCTL_TRACE
1420 printk(KERN_DEBUG
"%s: ->wavelan_set_multicast_list()\n",
1424 #ifdef DEBUG_IOCTL_INFO
1426 "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1427 dev
->name
, dev
->flags
, dev
->mc_count
);
1430 /* Are we asking for promiscuous mode,
1431 * or all multicast addresses (we don't have that!)
1432 * or too many multicast addresses for the hardware filter? */
1433 if ((dev
->flags
& IFF_PROMISC
) ||
1434 (dev
->flags
& IFF_ALLMULTI
) ||
1435 (dev
->mc_count
> I82586_MAX_MULTICAST_ADDRESSES
)) {
1437 * Enable promiscuous mode: receive all packets.
1439 if (!lp
->promiscuous
) {
1440 lp
->promiscuous
= 1;
1443 wv_82586_reconfig(dev
);
1445 /* Tell the kernel that we are doing a really bad job. */
1446 dev
->flags
|= IFF_PROMISC
;
1449 /* Are there multicast addresses to send? */
1450 if (dev
->mc_list
!= (struct dev_mc_list
*) NULL
) {
1452 * Disable promiscuous mode, but receive all packets
1455 #ifdef MULTICAST_AVOID
1456 if (lp
->promiscuous
|| (dev
->mc_count
!= lp
->mc_count
))
1459 lp
->promiscuous
= 0;
1460 lp
->mc_count
= dev
->mc_count
;
1462 wv_82586_reconfig(dev
);
1466 * Switch to normal mode: disable promiscuous mode and
1467 * clear the multicast list.
1469 if (lp
->promiscuous
|| lp
->mc_count
== 0) {
1470 lp
->promiscuous
= 0;
1473 wv_82586_reconfig(dev
);
1476 #ifdef DEBUG_IOCTL_TRACE
1477 printk(KERN_DEBUG
"%s: <-wavelan_set_multicast_list()\n",
1482 /*------------------------------------------------------------------*/
1484 * This function doesn't exist.
1485 * (Note : it was a nice way to test the reconfigure stuff...)
1487 #ifdef SET_MAC_ADDRESS
1488 static int wavelan_set_mac_address(struct net_device
* dev
, void *addr
)
1490 struct sockaddr
*mac
= addr
;
1492 /* Copy the address. */
1493 memcpy(dev
->dev_addr
, mac
->sa_data
, WAVELAN_ADDR_SIZE
);
1495 /* Reconfigure the beast. */
1496 wv_82586_reconfig(dev
);
1500 #endif /* SET_MAC_ADDRESS */
1502 #ifdef WIRELESS_EXT /* if wireless extensions exist in the kernel */
1504 /*------------------------------------------------------------------*/
1506 * Frequency setting (for hardware capable of it)
1507 * It's a bit complicated and you don't really want to look into it.
1508 * (called in wavelan_ioctl)
1510 static inline int wv_set_frequency(unsigned long ioaddr
, /* I/O port of the card */
1511 iw_freq
* frequency
)
1513 const int BAND_NUM
= 10; /* Number of bands */
1514 long freq
= 0L; /* offset to 2.4 GHz in .5 MHz */
1515 #ifdef DEBUG_IOCTL_INFO
1519 /* Setting by frequency */
1520 /* Theoretically, you may set any frequency between
1521 * the two limits with a 0.5 MHz precision. In practice,
1522 * I don't want you to have trouble with local regulations.
1524 if ((frequency
->e
== 1) &&
1525 (frequency
->m
>= (int) 2.412e8
)
1526 && (frequency
->m
<= (int) 2.487e8
)) {
1527 freq
= ((frequency
->m
/ 10000) - 24000L) / 5;
1530 /* Setting by channel (same as wfreqsel) */
1531 /* Warning: each channel is 22 MHz wide, so some of the channels
1532 * will interfere. */
1533 if ((frequency
->e
== 0) && (frequency
->m
< BAND_NUM
)) {
1534 /* Get frequency offset. */
1535 freq
= channel_bands
[frequency
->m
] >> 1;
1538 /* Verify that the frequency is allowed. */
1540 u16 table
[10]; /* Authorized frequency table */
1542 /* Read the frequency table. */
1543 fee_read(ioaddr
, 0x71, table
, 10);
1545 #ifdef DEBUG_IOCTL_INFO
1546 printk(KERN_DEBUG
"Frequency table: ");
1547 for (i
= 0; i
< 10; i
++) {
1548 printk(" %04X", table
[i
]);
1553 /* Look in the table to see whether the frequency is allowed. */
1554 if (!(table
[9 - ((freq
- 24) / 16)] &
1555 (1 << ((freq
- 24) % 16)))) return -EINVAL
; /* not allowed */
1559 /* if we get a usable frequency */
1561 unsigned short area
[16];
1562 unsigned short dac
[2];
1563 unsigned short area_verify
[16];
1564 unsigned short dac_verify
[2];
1565 /* Corresponding gain (in the power adjust value table)
1566 * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8
1567 * and WCIN062D.DOC, page 6.2.9. */
1568 unsigned short power_limit
[] = { 40, 80, 120, 160, 0 };
1569 int power_band
= 0; /* Selected band */
1570 unsigned short power_adjust
; /* Correct value */
1572 /* Search for the gain. */
1574 while ((freq
> power_limit
[power_band
]) &&
1575 (power_limit
[++power_band
] != 0));
1577 /* Read the first area. */
1578 fee_read(ioaddr
, 0x00, area
, 16);
1581 fee_read(ioaddr
, 0x60, dac
, 2);
1583 /* Read the new power adjust value. */
1584 fee_read(ioaddr
, 0x6B - (power_band
>> 1), &power_adjust
,
1586 if (power_band
& 0x1)
1589 power_adjust
&= 0xFF;
1591 #ifdef DEBUG_IOCTL_INFO
1592 printk(KERN_DEBUG
"WaveLAN EEPROM Area 1: ");
1593 for (i
= 0; i
< 16; i
++) {
1594 printk(" %04X", area
[i
]);
1598 printk(KERN_DEBUG
"WaveLAN EEPROM DAC: %04X %04X\n",
1602 /* Frequency offset (for info only) */
1603 area
[0] = ((freq
<< 5) & 0xFFE0) | (area
[0] & 0x1F);
1605 /* Receiver Principle main divider coefficient */
1606 area
[3] = (freq
>> 1) + 2400L - 352L;
1607 area
[2] = ((freq
& 0x1) << 4) | (area
[2] & 0xFFEF);
1609 /* Transmitter Main divider coefficient */
1610 area
[13] = (freq
>> 1) + 2400L;
1611 area
[12] = ((freq
& 0x1) << 4) | (area
[2] & 0xFFEF);
1613 /* Other parts of the area are flags, bit streams or unused. */
1615 /* Set the value in the DAC. */
1616 dac
[1] = ((power_adjust
>> 1) & 0x7F) | (dac
[1] & 0xFF80);
1617 dac
[0] = ((power_adjust
& 0x1) << 4) | (dac
[0] & 0xFFEF);
1619 /* Write the first area. */
1620 fee_write(ioaddr
, 0x00, area
, 16);
1622 /* Write the DAC. */
1623 fee_write(ioaddr
, 0x60, dac
, 2);
1625 /* We now should verify here that the writing of the EEPROM went OK. */
1627 /* Reread the first area. */
1628 fee_read(ioaddr
, 0x00, area_verify
, 16);
1630 /* Reread the DAC. */
1631 fee_read(ioaddr
, 0x60, dac_verify
, 2);
1634 if (memcmp(area
, area_verify
, 16 * 2) ||
1635 memcmp(dac
, dac_verify
, 2 * 2)) {
1636 #ifdef DEBUG_IOCTL_ERROR
1638 "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n");
1643 /* We must download the frequency parameters to the
1644 * synthesizers (from the EEPROM - area 1)
1645 * Note: as the EEPROM is automatically decremented, we set the end
1647 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), 0x0F);
1648 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
),
1649 MMW_FEE_CTRL_READ
| MMW_FEE_CTRL_DWLD
);
1651 /* Wait until the download is finished. */
1652 fee_wait(ioaddr
, 100, 100);
1654 /* We must now download the power adjust value (gain) to
1655 * the synthesizers (from the EEPROM - area 7 - DAC). */
1656 mmc_out(ioaddr
, mmwoff(0, mmw_fee_addr
), 0x61);
1657 mmc_out(ioaddr
, mmwoff(0, mmw_fee_ctrl
),
1658 MMW_FEE_CTRL_READ
| MMW_FEE_CTRL_DWLD
);
1660 /* Wait for the download to finish. */
1661 fee_wait(ioaddr
, 100, 100);
1663 #ifdef DEBUG_IOCTL_INFO
1664 /* Verification of what we have done */
1666 printk(KERN_DEBUG
"WaveLAN EEPROM Area 1: ");
1667 for (i
= 0; i
< 16; i
++) {
1668 printk(" %04X", area_verify
[i
]);
1672 printk(KERN_DEBUG
"WaveLAN EEPROM DAC: %04X %04X\n",
1673 dac_verify
[0], dac_verify
[1]);
1678 return -EINVAL
; /* Bah, never get there... */
1681 /*------------------------------------------------------------------*/
1683 * Give the list of available frequencies.
1685 static inline int wv_frequency_list(unsigned long ioaddr
, /* I/O port of the card */
1686 iw_freq
* list
, /* List of frequencies to fill */
1688 { /* Maximum number of frequencies */
1689 u16 table
[10]; /* Authorized frequency table */
1690 long freq
= 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
1691 int i
; /* index in the table */
1692 int c
= 0; /* Channel number */
1694 /* Read the frequency table. */
1695 fee_read(ioaddr
, 0x71 /* frequency table */ , table
, 10);
1697 /* Check all frequencies. */
1699 for (freq
= 0; freq
< 150; freq
++)
1700 /* Look in the table if the frequency is allowed */
1701 if (table
[9 - (freq
/ 16)] & (1 << (freq
% 16))) {
1702 /* Compute approximate channel number */
1703 while ((((channel_bands
[c
] >> 1) - 24) < freq
) &&
1704 (c
< NELS(channel_bands
)))
1706 list
[i
].i
= c
; /* Set the list index */
1708 /* put in the list */
1709 list
[i
].m
= (((freq
+ 24) * 5) + 24000L) * 10000;
1720 #ifdef IW_WIRELESS_SPY
1721 /*------------------------------------------------------------------*/
1723 * Gather wireless spy statistics: for each packet, compare the source
1724 * address with our list, and if they match, get the statistics.
1725 * Sorry, but this function really needs the wireless extensions.
1727 static inline void wl_spy_gather(struct net_device
* dev
,
1728 u8
* mac
, /* MAC address */
1729 u8
* stats
) /* Statistics to gather */
1731 struct iw_quality wstats
;
1733 wstats
.qual
= stats
[2] & MMR_SGNL_QUAL
;
1734 wstats
.level
= stats
[0] & MMR_SIGNAL_LVL
;
1735 wstats
.noise
= stats
[1] & MMR_SILENCE_LVL
;
1736 wstats
.updated
= 0x7;
1738 /* Update spy records */
1739 wireless_spy_update(dev
, mac
, &wstats
);
1741 #endif /* IW_WIRELESS_SPY */
1744 /*------------------------------------------------------------------*/
1746 * This function calculates a histogram of the signal level.
1747 * As the noise is quite constant, it's like doing it on the SNR.
1748 * We have defined a set of interval (lp->his_range), and each time
1749 * the level goes in that interval, we increment the count (lp->his_sum).
1750 * With this histogram you may detect if one WaveLAN is really weak,
1751 * or you may also calculate the mean and standard deviation of the level.
1753 static inline void wl_his_gather(struct net_device
* dev
, u8
* stats
)
1754 { /* Statistics to gather */
1755 net_local
*lp
= (net_local
*) dev
->priv
;
1756 u8 level
= stats
[0] & MMR_SIGNAL_LVL
;
1759 /* Find the correct interval. */
1761 while ((i
< (lp
->his_number
- 1))
1762 && (level
>= lp
->his_range
[i
++]));
1764 /* Increment interval counter. */
1767 #endif /* HISTOGRAM */
1769 /*------------------------------------------------------------------*/
1771 * Wireless Handler : get protocol name
1773 static int wavelan_get_name(struct net_device
*dev
,
1774 struct iw_request_info
*info
,
1775 union iwreq_data
*wrqu
,
1778 strcpy(wrqu
->name
, "WaveLAN");
1782 /*------------------------------------------------------------------*/
1784 * Wireless Handler : set NWID
1786 static int wavelan_set_nwid(struct net_device
*dev
,
1787 struct iw_request_info
*info
,
1788 union iwreq_data
*wrqu
,
1791 unsigned long ioaddr
= dev
->base_addr
;
1792 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
1795 unsigned long flags
;
1798 /* Disable interrupts and save flags. */
1799 spin_lock_irqsave(&lp
->spinlock
, flags
);
1801 /* Set NWID in WaveLAN. */
1802 if (!wrqu
->nwid
.disabled
) {
1803 /* Set NWID in psa */
1804 psa
.psa_nwid
[0] = (wrqu
->nwid
.value
& 0xFF00) >> 8;
1805 psa
.psa_nwid
[1] = wrqu
->nwid
.value
& 0xFF;
1806 psa
.psa_nwid_select
= 0x01;
1807 psa_write(ioaddr
, lp
->hacr
,
1808 (char *) psa
.psa_nwid
- (char *) &psa
,
1809 (unsigned char *) psa
.psa_nwid
, 3);
1811 /* Set NWID in mmc. */
1812 m
.w
.mmw_netw_id_l
= psa
.psa_nwid
[1];
1813 m
.w
.mmw_netw_id_h
= psa
.psa_nwid
[0];
1815 (char *) &m
.w
.mmw_netw_id_l
-
1817 (unsigned char *) &m
.w
.mmw_netw_id_l
, 2);
1818 mmc_out(ioaddr
, mmwoff(0, mmw_loopt_sel
), 0x00);
1820 /* Disable NWID in the psa. */
1821 psa
.psa_nwid_select
= 0x00;
1822 psa_write(ioaddr
, lp
->hacr
,
1823 (char *) &psa
.psa_nwid_select
-
1825 (unsigned char *) &psa
.psa_nwid_select
,
1828 /* Disable NWID in the mmc (no filtering). */
1829 mmc_out(ioaddr
, mmwoff(0, mmw_loopt_sel
),
1830 MMW_LOOPT_SEL_DIS_NWID
);
1832 /* update the Wavelan checksum */
1833 update_psa_checksum(dev
, ioaddr
, lp
->hacr
);
1835 /* Enable interrupts and restore flags. */
1836 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
1841 /*------------------------------------------------------------------*/
1843 * Wireless Handler : get NWID
1845 static int wavelan_get_nwid(struct net_device
*dev
,
1846 struct iw_request_info
*info
,
1847 union iwreq_data
*wrqu
,
1850 unsigned long ioaddr
= dev
->base_addr
;
1851 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
1853 unsigned long flags
;
1856 /* Disable interrupts and save flags. */
1857 spin_lock_irqsave(&lp
->spinlock
, flags
);
1859 /* Read the NWID. */
1860 psa_read(ioaddr
, lp
->hacr
,
1861 (char *) psa
.psa_nwid
- (char *) &psa
,
1862 (unsigned char *) psa
.psa_nwid
, 3);
1863 wrqu
->nwid
.value
= (psa
.psa_nwid
[0] << 8) + psa
.psa_nwid
[1];
1864 wrqu
->nwid
.disabled
= !(psa
.psa_nwid_select
);
1865 wrqu
->nwid
.fixed
= 1; /* Superfluous */
1867 /* Enable interrupts and restore flags. */
1868 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
1873 /*------------------------------------------------------------------*/
1875 * Wireless Handler : set frequency
1877 static int wavelan_set_freq(struct net_device
*dev
,
1878 struct iw_request_info
*info
,
1879 union iwreq_data
*wrqu
,
1882 unsigned long ioaddr
= dev
->base_addr
;
1883 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
1884 unsigned long flags
;
1887 /* Disable interrupts and save flags. */
1888 spin_lock_irqsave(&lp
->spinlock
, flags
);
1890 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1891 if (!(mmc_in(ioaddr
, mmroff(0, mmr_fee_status
)) &
1892 (MMR_FEE_STATUS_DWLD
| MMR_FEE_STATUS_BUSY
)))
1893 ret
= wv_set_frequency(ioaddr
, &(wrqu
->freq
));
1897 /* Enable interrupts and restore flags. */
1898 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
1903 /*------------------------------------------------------------------*/
1905 * Wireless Handler : get frequency
1907 static int wavelan_get_freq(struct net_device
*dev
,
1908 struct iw_request_info
*info
,
1909 union iwreq_data
*wrqu
,
1912 unsigned long ioaddr
= dev
->base_addr
;
1913 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
1915 unsigned long flags
;
1918 /* Disable interrupts and save flags. */
1919 spin_lock_irqsave(&lp
->spinlock
, flags
);
1921 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
1922 * Does it work for everybody, especially old cards? */
1923 if (!(mmc_in(ioaddr
, mmroff(0, mmr_fee_status
)) &
1924 (MMR_FEE_STATUS_DWLD
| MMR_FEE_STATUS_BUSY
))) {
1925 unsigned short freq
;
1927 /* Ask the EEPROM to read the frequency from the first area. */
1928 fee_read(ioaddr
, 0x00, &freq
, 1);
1929 wrqu
->freq
.m
= ((freq
>> 5) * 5 + 24000L) * 10000;
1932 psa_read(ioaddr
, lp
->hacr
,
1933 (char *) &psa
.psa_subband
- (char *) &psa
,
1934 (unsigned char *) &psa
.psa_subband
, 1);
1936 if (psa
.psa_subband
<= 4) {
1937 wrqu
->freq
.m
= fixed_bands
[psa
.psa_subband
];
1938 wrqu
->freq
.e
= (psa
.psa_subband
!= 0);
1943 /* Enable interrupts and restore flags. */
1944 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
1949 /*------------------------------------------------------------------*/
1951 * Wireless Handler : set level threshold
1953 static int wavelan_set_sens(struct net_device
*dev
,
1954 struct iw_request_info
*info
,
1955 union iwreq_data
*wrqu
,
1958 unsigned long ioaddr
= dev
->base_addr
;
1959 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
1961 unsigned long flags
;
1964 /* Disable interrupts and save flags. */
1965 spin_lock_irqsave(&lp
->spinlock
, flags
);
1967 /* Set the level threshold. */
1968 /* We should complain loudly if wrqu->sens.fixed = 0, because we
1969 * can't set auto mode... */
1970 psa
.psa_thr_pre_set
= wrqu
->sens
.value
& 0x3F;
1971 psa_write(ioaddr
, lp
->hacr
,
1972 (char *) &psa
.psa_thr_pre_set
- (char *) &psa
,
1973 (unsigned char *) &psa
.psa_thr_pre_set
, 1);
1974 /* update the Wavelan checksum */
1975 update_psa_checksum(dev
, ioaddr
, lp
->hacr
);
1976 mmc_out(ioaddr
, mmwoff(0, mmw_thr_pre_set
),
1977 psa
.psa_thr_pre_set
);
1979 /* Enable interrupts and restore flags. */
1980 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
1985 /*------------------------------------------------------------------*/
1987 * Wireless Handler : get level threshold
1989 static int wavelan_get_sens(struct net_device
*dev
,
1990 struct iw_request_info
*info
,
1991 union iwreq_data
*wrqu
,
1994 unsigned long ioaddr
= dev
->base_addr
;
1995 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
1997 unsigned long flags
;
2000 /* Disable interrupts and save flags. */
2001 spin_lock_irqsave(&lp
->spinlock
, flags
);
2003 /* Read the level threshold. */
2004 psa_read(ioaddr
, lp
->hacr
,
2005 (char *) &psa
.psa_thr_pre_set
- (char *) &psa
,
2006 (unsigned char *) &psa
.psa_thr_pre_set
, 1);
2007 wrqu
->sens
.value
= psa
.psa_thr_pre_set
& 0x3F;
2008 wrqu
->sens
.fixed
= 1;
2010 /* Enable interrupts and restore flags. */
2011 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2016 /*------------------------------------------------------------------*/
2018 * Wireless Handler : set encryption key
2020 static int wavelan_set_encode(struct net_device
*dev
,
2021 struct iw_request_info
*info
,
2022 union iwreq_data
*wrqu
,
2025 unsigned long ioaddr
= dev
->base_addr
;
2026 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
2027 unsigned long flags
;
2031 /* Disable interrupts and save flags. */
2032 spin_lock_irqsave(&lp
->spinlock
, flags
);
2034 /* Check if capable of encryption */
2035 if (!mmc_encr(ioaddr
)) {
2039 /* Check the size of the key */
2040 if((wrqu
->encoding
.length
!= 8) && (wrqu
->encoding
.length
!= 0)) {
2045 /* Basic checking... */
2046 if (wrqu
->encoding
.length
== 8) {
2047 /* Copy the key in the driver */
2048 memcpy(psa
.psa_encryption_key
, extra
,
2049 wrqu
->encoding
.length
);
2050 psa
.psa_encryption_select
= 1;
2052 psa_write(ioaddr
, lp
->hacr
,
2053 (char *) &psa
.psa_encryption_select
-
2055 (unsigned char *) &psa
.
2056 psa_encryption_select
, 8 + 1);
2058 mmc_out(ioaddr
, mmwoff(0, mmw_encr_enable
),
2059 MMW_ENCR_ENABLE_EN
| MMW_ENCR_ENABLE_MODE
);
2060 mmc_write(ioaddr
, mmwoff(0, mmw_encr_key
),
2061 (unsigned char *) &psa
.
2062 psa_encryption_key
, 8);
2065 /* disable encryption */
2066 if (wrqu
->encoding
.flags
& IW_ENCODE_DISABLED
) {
2067 psa
.psa_encryption_select
= 0;
2068 psa_write(ioaddr
, lp
->hacr
,
2069 (char *) &psa
.psa_encryption_select
-
2071 (unsigned char *) &psa
.
2072 psa_encryption_select
, 1);
2074 mmc_out(ioaddr
, mmwoff(0, mmw_encr_enable
), 0);
2076 /* update the Wavelan checksum */
2077 update_psa_checksum(dev
, ioaddr
, lp
->hacr
);
2080 /* Enable interrupts and restore flags. */
2081 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2086 /*------------------------------------------------------------------*/
2088 * Wireless Handler : get encryption key
2090 static int wavelan_get_encode(struct net_device
*dev
,
2091 struct iw_request_info
*info
,
2092 union iwreq_data
*wrqu
,
2095 unsigned long ioaddr
= dev
->base_addr
;
2096 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
2098 unsigned long flags
;
2101 /* Disable interrupts and save flags. */
2102 spin_lock_irqsave(&lp
->spinlock
, flags
);
2104 /* Check if encryption is available */
2105 if (!mmc_encr(ioaddr
)) {
2108 /* Read the encryption key */
2109 psa_read(ioaddr
, lp
->hacr
,
2110 (char *) &psa
.psa_encryption_select
-
2112 (unsigned char *) &psa
.
2113 psa_encryption_select
, 1 + 8);
2115 /* encryption is enabled ? */
2116 if (psa
.psa_encryption_select
)
2117 wrqu
->encoding
.flags
= IW_ENCODE_ENABLED
;
2119 wrqu
->encoding
.flags
= IW_ENCODE_DISABLED
;
2120 wrqu
->encoding
.flags
|= mmc_encr(ioaddr
);
2122 /* Copy the key to the user buffer */
2123 wrqu
->encoding
.length
= 8;
2124 memcpy(extra
, psa
.psa_encryption_key
, wrqu
->encoding
.length
);
2127 /* Enable interrupts and restore flags. */
2128 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2133 /*------------------------------------------------------------------*/
2135 * Wireless Handler : get range info
2137 static int wavelan_get_range(struct net_device
*dev
,
2138 struct iw_request_info
*info
,
2139 union iwreq_data
*wrqu
,
2142 unsigned long ioaddr
= dev
->base_addr
;
2143 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
2144 struct iw_range
*range
= (struct iw_range
*) extra
;
2145 unsigned long flags
;
2148 /* Set the length (very important for backward compatibility) */
2149 wrqu
->data
.length
= sizeof(struct iw_range
);
2151 /* Set all the info we don't care or don't know about to zero */
2152 memset(range
, 0, sizeof(struct iw_range
));
2154 /* Set the Wireless Extension versions */
2155 range
->we_version_compiled
= WIRELESS_EXT
;
2156 range
->we_version_source
= 9;
2158 /* Set information in the range struct. */
2159 range
->throughput
= 1.6 * 1000 * 1000; /* don't argue on this ! */
2160 range
->min_nwid
= 0x0000;
2161 range
->max_nwid
= 0xFFFF;
2163 range
->sensitivity
= 0x3F;
2164 range
->max_qual
.qual
= MMR_SGNL_QUAL
;
2165 range
->max_qual
.level
= MMR_SIGNAL_LVL
;
2166 range
->max_qual
.noise
= MMR_SILENCE_LVL
;
2167 range
->avg_qual
.qual
= MMR_SGNL_QUAL
; /* Always max */
2168 /* Need to get better values for those two */
2169 range
->avg_qual
.level
= 30;
2170 range
->avg_qual
.noise
= 8;
2172 range
->num_bitrates
= 1;
2173 range
->bitrate
[0] = 2000000; /* 2 Mb/s */
2175 /* Event capability (kernel + driver) */
2176 range
->event_capa
[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
2177 IW_EVENT_CAPA_MASK(0x8B04));
2178 range
->event_capa
[1] = IW_EVENT_CAPA_K_1
;
2180 /* Disable interrupts and save flags. */
2181 spin_lock_irqsave(&lp
->spinlock
, flags
);
2183 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2184 if (!(mmc_in(ioaddr
, mmroff(0, mmr_fee_status
)) &
2185 (MMR_FEE_STATUS_DWLD
| MMR_FEE_STATUS_BUSY
))) {
2186 range
->num_channels
= 10;
2187 range
->num_frequency
= wv_frequency_list(ioaddr
, range
->freq
,
2188 IW_MAX_FREQUENCIES
);
2190 range
->num_channels
= range
->num_frequency
= 0;
2192 /* Encryption supported ? */
2193 if (mmc_encr(ioaddr
)) {
2194 range
->encoding_size
[0] = 8; /* DES = 64 bits key */
2195 range
->num_encoding_sizes
= 1;
2196 range
->max_encoding_tokens
= 1; /* Only one key possible */
2198 range
->num_encoding_sizes
= 0;
2199 range
->max_encoding_tokens
= 0;
2202 /* Enable interrupts and restore flags. */
2203 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2208 /*------------------------------------------------------------------*/
2210 * Wireless Private Handler : set quality threshold
2212 static int wavelan_set_qthr(struct net_device
*dev
,
2213 struct iw_request_info
*info
,
2214 union iwreq_data
*wrqu
,
2217 unsigned long ioaddr
= dev
->base_addr
;
2218 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
2220 unsigned long flags
;
2222 /* Disable interrupts and save flags. */
2223 spin_lock_irqsave(&lp
->spinlock
, flags
);
2225 psa
.psa_quality_thr
= *(extra
) & 0x0F;
2226 psa_write(ioaddr
, lp
->hacr
,
2227 (char *) &psa
.psa_quality_thr
- (char *) &psa
,
2228 (unsigned char *) &psa
.psa_quality_thr
, 1);
2229 /* update the Wavelan checksum */
2230 update_psa_checksum(dev
, ioaddr
, lp
->hacr
);
2231 mmc_out(ioaddr
, mmwoff(0, mmw_quality_thr
),
2232 psa
.psa_quality_thr
);
2234 /* Enable interrupts and restore flags. */
2235 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2240 /*------------------------------------------------------------------*/
2242 * Wireless Private Handler : get quality threshold
2244 static int wavelan_get_qthr(struct net_device
*dev
,
2245 struct iw_request_info
*info
,
2246 union iwreq_data
*wrqu
,
2249 unsigned long ioaddr
= dev
->base_addr
;
2250 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
2252 unsigned long flags
;
2254 /* Disable interrupts and save flags. */
2255 spin_lock_irqsave(&lp
->spinlock
, flags
);
2257 psa_read(ioaddr
, lp
->hacr
,
2258 (char *) &psa
.psa_quality_thr
- (char *) &psa
,
2259 (unsigned char *) &psa
.psa_quality_thr
, 1);
2260 *(extra
) = psa
.psa_quality_thr
& 0x0F;
2262 /* Enable interrupts and restore flags. */
2263 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2269 /*------------------------------------------------------------------*/
2271 * Wireless Private Handler : set histogram
2273 static int wavelan_set_histo(struct net_device
*dev
,
2274 struct iw_request_info
*info
,
2275 union iwreq_data
*wrqu
,
2278 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
2280 /* Check the number of intervals. */
2281 if (wrqu
->data
.length
> 16) {
2285 /* Disable histo while we copy the addresses.
2286 * As we don't disable interrupts, we need to do this */
2289 /* Are there ranges to copy? */
2290 if (wrqu
->data
.length
> 0) {
2291 /* Copy interval ranges to the driver */
2292 memcpy(lp
->his_range
, extra
, wrqu
->data
.length
);
2296 printk(KERN_DEBUG
"Histo :");
2297 for(i
= 0; i
< wrqu
->data
.length
; i
++)
2298 printk(" %d", lp
->his_range
[i
]);
2302 /* Reset result structure. */
2303 memset(lp
->his_sum
, 0x00, sizeof(long) * 16);
2306 /* Now we can set the number of ranges */
2307 lp
->his_number
= wrqu
->data
.length
;
2312 /*------------------------------------------------------------------*/
2314 * Wireless Private Handler : get histogram
2316 static int wavelan_get_histo(struct net_device
*dev
,
2317 struct iw_request_info
*info
,
2318 union iwreq_data
*wrqu
,
2321 net_local
*lp
= (net_local
*) dev
->priv
; /* lp is not unused */
2323 /* Set the number of intervals. */
2324 wrqu
->data
.length
= lp
->his_number
;
2326 /* Give back the distribution statistics */
2327 if(lp
->his_number
> 0)
2328 memcpy(extra
, lp
->his_sum
, sizeof(long) * lp
->his_number
);
2332 #endif /* HISTOGRAM */
2334 /*------------------------------------------------------------------*/
2336 * Structures to export the Wireless Handlers
2339 static const iw_handler wavelan_handler
[] =
2341 NULL
, /* SIOCSIWNAME */
2342 wavelan_get_name
, /* SIOCGIWNAME */
2343 wavelan_set_nwid
, /* SIOCSIWNWID */
2344 wavelan_get_nwid
, /* SIOCGIWNWID */
2345 wavelan_set_freq
, /* SIOCSIWFREQ */
2346 wavelan_get_freq
, /* SIOCGIWFREQ */
2347 NULL
, /* SIOCSIWMODE */
2348 NULL
, /* SIOCGIWMODE */
2349 wavelan_set_sens
, /* SIOCSIWSENS */
2350 wavelan_get_sens
, /* SIOCGIWSENS */
2351 NULL
, /* SIOCSIWRANGE */
2352 wavelan_get_range
, /* SIOCGIWRANGE */
2353 NULL
, /* SIOCSIWPRIV */
2354 NULL
, /* SIOCGIWPRIV */
2355 NULL
, /* SIOCSIWSTATS */
2356 NULL
, /* SIOCGIWSTATS */
2357 iw_handler_set_spy
, /* SIOCSIWSPY */
2358 iw_handler_get_spy
, /* SIOCGIWSPY */
2359 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
2360 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
2361 NULL
, /* SIOCSIWAP */
2362 NULL
, /* SIOCGIWAP */
2363 NULL
, /* -- hole -- */
2364 NULL
, /* SIOCGIWAPLIST */
2365 NULL
, /* -- hole -- */
2366 NULL
, /* -- hole -- */
2367 NULL
, /* SIOCSIWESSID */
2368 NULL
, /* SIOCGIWESSID */
2369 NULL
, /* SIOCSIWNICKN */
2370 NULL
, /* SIOCGIWNICKN */
2371 NULL
, /* -- hole -- */
2372 NULL
, /* -- hole -- */
2373 NULL
, /* SIOCSIWRATE */
2374 NULL
, /* SIOCGIWRATE */
2375 NULL
, /* SIOCSIWRTS */
2376 NULL
, /* SIOCGIWRTS */
2377 NULL
, /* SIOCSIWFRAG */
2378 NULL
, /* SIOCGIWFRAG */
2379 NULL
, /* SIOCSIWTXPOW */
2380 NULL
, /* SIOCGIWTXPOW */
2381 NULL
, /* SIOCSIWRETRY */
2382 NULL
, /* SIOCGIWRETRY */
2383 /* Bummer ! Why those are only at the end ??? */
2384 wavelan_set_encode
, /* SIOCSIWENCODE */
2385 wavelan_get_encode
, /* SIOCGIWENCODE */
2388 static const iw_handler wavelan_private_handler
[] =
2390 wavelan_set_qthr
, /* SIOCIWFIRSTPRIV */
2391 wavelan_get_qthr
, /* SIOCIWFIRSTPRIV + 1 */
2393 wavelan_set_histo
, /* SIOCIWFIRSTPRIV + 2 */
2394 wavelan_get_histo
, /* SIOCIWFIRSTPRIV + 3 */
2395 #endif /* HISTOGRAM */
2398 static const struct iw_priv_args wavelan_private_args
[] = {
2399 /*{ cmd, set_args, get_args, name } */
2400 { SIOCSIPQTHR
, IW_PRIV_TYPE_BYTE
| IW_PRIV_SIZE_FIXED
| 1, 0, "setqualthr" },
2401 { SIOCGIPQTHR
, 0, IW_PRIV_TYPE_BYTE
| IW_PRIV_SIZE_FIXED
| 1, "getqualthr" },
2402 { SIOCSIPHISTO
, IW_PRIV_TYPE_BYTE
| 16, 0, "sethisto" },
2403 { SIOCGIPHISTO
, 0, IW_PRIV_TYPE_INT
| 16, "gethisto" },
2406 static const struct iw_handler_def wavelan_handler_def
=
2408 .num_standard
= sizeof(wavelan_handler
)/sizeof(iw_handler
),
2409 .num_private
= sizeof(wavelan_private_handler
)/sizeof(iw_handler
),
2410 .num_private_args
= sizeof(wavelan_private_args
)/sizeof(struct iw_priv_args
),
2411 .standard
= wavelan_handler
,
2412 .private = wavelan_private_handler
,
2413 .private_args
= wavelan_private_args
,
2414 .get_wireless_stats
= wavelan_get_wireless_stats
,
2417 /*------------------------------------------------------------------*/
2419 * Get wireless statistics.
2420 * Called by /proc/net/wireless
2422 static iw_stats
*wavelan_get_wireless_stats(struct net_device
* dev
)
2424 unsigned long ioaddr
= dev
->base_addr
;
2425 net_local
*lp
= (net_local
*) dev
->priv
;
2428 unsigned long flags
;
2430 #ifdef DEBUG_IOCTL_TRACE
2431 printk(KERN_DEBUG
"%s: ->wavelan_get_wireless_stats()\n",
2436 if (lp
== (net_local
*) NULL
)
2437 return (iw_stats
*) NULL
;
2439 /* Disable interrupts and save flags. */
2440 spin_lock_irqsave(&lp
->spinlock
, flags
);
2442 wstats
= &lp
->wstats
;
2444 /* Get data from the mmc. */
2445 mmc_out(ioaddr
, mmwoff(0, mmw_freeze
), 1);
2447 mmc_read(ioaddr
, mmroff(0, mmr_dce_status
), &m
.mmr_dce_status
, 1);
2448 mmc_read(ioaddr
, mmroff(0, mmr_wrong_nwid_l
), &m
.mmr_wrong_nwid_l
,
2450 mmc_read(ioaddr
, mmroff(0, mmr_thr_pre_set
), &m
.mmr_thr_pre_set
,
2453 mmc_out(ioaddr
, mmwoff(0, mmw_freeze
), 0);
2455 /* Copy data to wireless stuff. */
2456 wstats
->status
= m
.mmr_dce_status
& MMR_DCE_STATUS
;
2457 wstats
->qual
.qual
= m
.mmr_sgnl_qual
& MMR_SGNL_QUAL
;
2458 wstats
->qual
.level
= m
.mmr_signal_lvl
& MMR_SIGNAL_LVL
;
2459 wstats
->qual
.noise
= m
.mmr_silence_lvl
& MMR_SILENCE_LVL
;
2460 wstats
->qual
.updated
= (((m
. mmr_signal_lvl
& MMR_SIGNAL_LVL_VALID
) >> 7)
2461 | ((m
.mmr_signal_lvl
& MMR_SIGNAL_LVL_VALID
) >> 6)
2462 | ((m
.mmr_silence_lvl
& MMR_SILENCE_LVL_VALID
) >> 5));
2463 wstats
->discard
.nwid
+= (m
.mmr_wrong_nwid_h
<< 8) | m
.mmr_wrong_nwid_l
;
2464 wstats
->discard
.code
= 0L;
2465 wstats
->discard
.misc
= 0L;
2467 /* Enable interrupts and restore flags. */
2468 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2470 #ifdef DEBUG_IOCTL_TRACE
2471 printk(KERN_DEBUG
"%s: <-wavelan_get_wireless_stats()\n",
2476 #endif /* WIRELESS_EXT */
2478 /************************* PACKET RECEPTION *************************/
2480 * This part deals with receiving the packets.
2481 * The interrupt handler gets an interrupt when a packet has been
2482 * successfully received and calls this part.
2485 /*------------------------------------------------------------------*/
2487 * This routine does the actual copying of data (including the Ethernet
2488 * header structure) from the WaveLAN card to an sk_buff chain that
2489 * will be passed up to the network interface layer. NOTE: we
2490 * currently don't handle trailer protocols (neither does the rest of
2491 * the network interface), so if that is needed, it will (at least in
2492 * part) be added here. The contents of the receive ring buffer are
2493 * copied to a message chain that is then passed to the kernel.
2495 * Note: if any errors occur, the packet is "dropped on the floor".
2496 * (called by wv_packet_rcv())
2499 wv_packet_read(struct net_device
* dev
, u16 buf_off
, int sksize
)
2501 net_local
*lp
= (net_local
*) dev
->priv
;
2502 unsigned long ioaddr
= dev
->base_addr
;
2503 struct sk_buff
*skb
;
2505 #ifdef DEBUG_RX_TRACE
2506 printk(KERN_DEBUG
"%s: ->wv_packet_read(0x%X, %d)\n",
2507 dev
->name
, buf_off
, sksize
);
2510 /* Allocate buffer for the data */
2511 if ((skb
= dev_alloc_skb(sksize
)) == (struct sk_buff
*) NULL
) {
2512 #ifdef DEBUG_RX_ERROR
2514 "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
2517 lp
->stats
.rx_dropped
++;
2523 /* Copy the packet to the buffer. */
2524 obram_read(ioaddr
, buf_off
, skb_put(skb
, sksize
), sksize
);
2525 skb
->protocol
= eth_type_trans(skb
, dev
);
2527 #ifdef DEBUG_RX_INFO
2528 wv_packet_info(skb
->mac
.raw
, sksize
, dev
->name
, "wv_packet_read");
2529 #endif /* DEBUG_RX_INFO */
2531 /* Statistics-gathering and associated stuff.
2532 * It seem a bit messy with all the define, but it's really
2535 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
2536 (lp
->spy_data
.spy_number
> 0) ||
2537 #endif /* IW_WIRELESS_SPY */
2539 (lp
->his_number
> 0) ||
2540 #endif /* HISTOGRAM */
2542 u8 stats
[3]; /* signal level, noise level, signal quality */
2544 /* Read signal level, silence level and signal quality bytes */
2545 /* Note: in the PCMCIA hardware, these are part of the frame.
2546 * It seems that for the ISA hardware, it's nowhere to be
2547 * found in the frame, so I'm obliged to do this (it has a
2548 * side effect on /proc/net/wireless).
2551 mmc_out(ioaddr
, mmwoff(0, mmw_freeze
), 1);
2552 mmc_read(ioaddr
, mmroff(0, mmr_signal_lvl
), stats
, 3);
2553 mmc_out(ioaddr
, mmwoff(0, mmw_freeze
), 0);
2555 #ifdef DEBUG_RX_INFO
2557 "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2558 dev
->name
, stats
[0] & 0x3F, stats
[1] & 0x3F,
2563 #ifdef IW_WIRELESS_SPY
2564 wl_spy_gather(dev
, skb
->mac
.raw
+ WAVELAN_ADDR_SIZE
,
2566 #endif /* IW_WIRELESS_SPY */
2568 wl_his_gather(dev
, stats
);
2569 #endif /* HISTOGRAM */
2573 * Hand the packet to the network module.
2577 /* Keep statistics up to date */
2578 dev
->last_rx
= jiffies
;
2579 lp
->stats
.rx_packets
++;
2580 lp
->stats
.rx_bytes
+= sksize
;
2582 #ifdef DEBUG_RX_TRACE
2583 printk(KERN_DEBUG
"%s: <-wv_packet_read()\n", dev
->name
);
2587 /*------------------------------------------------------------------*/
2589 * Transfer as many packets as we can
2590 * from the device RAM.
2591 * (called in wavelan_interrupt()).
2592 * Note : the spinlock is already grabbed for us.
2594 static inline void wv_receive(struct net_device
* dev
)
2596 unsigned long ioaddr
= dev
->base_addr
;
2597 net_local
*lp
= (net_local
*) dev
->priv
;
2602 #ifdef DEBUG_RX_TRACE
2603 printk(KERN_DEBUG
"%s: ->wv_receive()\n", dev
->name
);
2606 /* Loop on each received packet. */
2608 obram_read(ioaddr
, lp
->rx_head
, (unsigned char *) &fd
,
2611 /* Note about the status :
2612 * It start up to be 0 (the value we set). Then, when the RU
2613 * grab the buffer to prepare for reception, it sets the
2614 * FD_STATUS_B flag. When the RU has finished receiving the
2615 * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
2616 * completion and set the other flags to indicate the eventual
2617 * errors. FD_STATUS_OK indicates that the reception was OK.
2620 /* If the current frame is not complete, we have reached the end. */
2621 if ((fd
.fd_status
& FD_STATUS_C
) != FD_STATUS_C
)
2622 break; /* This is how we exit the loop. */
2626 /* Check whether frame was correctly received. */
2627 if ((fd
.fd_status
& FD_STATUS_OK
) == FD_STATUS_OK
) {
2628 /* Does the frame contain a pointer to the data? Let's check. */
2629 if (fd
.fd_rbd_offset
!= I82586NULL
) {
2630 /* Read the receive buffer descriptor */
2631 obram_read(ioaddr
, fd
.fd_rbd_offset
,
2632 (unsigned char *) &rbd
,
2635 #ifdef DEBUG_RX_ERROR
2636 if ((rbd
.rbd_status
& RBD_STATUS_EOF
) !=
2637 RBD_STATUS_EOF
) printk(KERN_INFO
2638 "%s: wv_receive(): missing EOF flag.\n",
2641 if ((rbd
.rbd_status
& RBD_STATUS_F
) !=
2642 RBD_STATUS_F
) printk(KERN_INFO
2643 "%s: wv_receive(): missing F flag.\n",
2645 #endif /* DEBUG_RX_ERROR */
2647 /* Read the packet and transmit to Linux */
2648 wv_packet_read(dev
, rbd
.rbd_bufl
,
2653 #ifdef DEBUG_RX_ERROR
2654 else /* if frame has no data */
2656 "%s: wv_receive(): frame has no data.\n",
2659 } else { /* If reception was no successful */
2661 lp
->stats
.rx_errors
++;
2663 #ifdef DEBUG_RX_INFO
2665 "%s: wv_receive(): frame not received successfully (%X).\n",
2666 dev
->name
, fd
.fd_status
);
2669 #ifdef DEBUG_RX_ERROR
2670 if ((fd
.fd_status
& FD_STATUS_S6
) != 0)
2672 "%s: wv_receive(): no EOF flag.\n",
2676 if ((fd
.fd_status
& FD_STATUS_S7
) != 0) {
2677 lp
->stats
.rx_length_errors
++;
2678 #ifdef DEBUG_RX_FAIL
2680 "%s: wv_receive(): frame too short.\n",
2685 if ((fd
.fd_status
& FD_STATUS_S8
) != 0) {
2686 lp
->stats
.rx_over_errors
++;
2687 #ifdef DEBUG_RX_FAIL
2689 "%s: wv_receive(): rx DMA overrun.\n",
2694 if ((fd
.fd_status
& FD_STATUS_S9
) != 0) {
2695 lp
->stats
.rx_fifo_errors
++;
2696 #ifdef DEBUG_RX_FAIL
2698 "%s: wv_receive(): ran out of resources.\n",
2703 if ((fd
.fd_status
& FD_STATUS_S10
) != 0) {
2704 lp
->stats
.rx_frame_errors
++;
2705 #ifdef DEBUG_RX_FAIL
2707 "%s: wv_receive(): alignment error.\n",
2712 if ((fd
.fd_status
& FD_STATUS_S11
) != 0) {
2713 lp
->stats
.rx_crc_errors
++;
2714 #ifdef DEBUG_RX_FAIL
2716 "%s: wv_receive(): CRC error.\n",
2723 obram_write(ioaddr
, fdoff(lp
->rx_head
, fd_status
),
2724 (unsigned char *) &fd
.fd_status
,
2725 sizeof(fd
.fd_status
));
2727 fd
.fd_command
= FD_COMMAND_EL
;
2728 obram_write(ioaddr
, fdoff(lp
->rx_head
, fd_command
),
2729 (unsigned char *) &fd
.fd_command
,
2730 sizeof(fd
.fd_command
));
2733 obram_write(ioaddr
, fdoff(lp
->rx_last
, fd_command
),
2734 (unsigned char *) &fd
.fd_command
,
2735 sizeof(fd
.fd_command
));
2737 lp
->rx_last
= lp
->rx_head
;
2738 lp
->rx_head
= fd
.fd_link_offset
;
2739 } /* for(;;) -> loop on all frames */
2741 #ifdef DEBUG_RX_INFO
2743 printk(KERN_DEBUG
"%s: wv_receive(): reaped %d\n",
2744 dev
->name
, nreaped
);
2746 #ifdef DEBUG_RX_TRACE
2747 printk(KERN_DEBUG
"%s: <-wv_receive()\n", dev
->name
);
2751 /*********************** PACKET TRANSMISSION ***********************/
2753 * This part deals with sending packets through the WaveLAN.
2757 /*------------------------------------------------------------------*/
2759 * This routine fills in the appropriate registers and memory
2760 * locations on the WaveLAN card and starts the card off on
2764 * Each block contains a transmit command, a NOP command,
2765 * a transmit block descriptor and a buffer.
2766 * The CU read the transmit block which point to the tbd,
2767 * read the tbd and the content of the buffer.
2768 * When it has finish with it, it goes to the next command
2769 * which in our case is the NOP. The NOP points on itself,
2770 * so the CU stop here.
2771 * When we add the next block, we modify the previous nop
2772 * to make it point on the new tx command.
2773 * Simple, isn't it ?
2775 * (called in wavelan_packet_xmit())
2777 static inline int wv_packet_write(struct net_device
* dev
, void *buf
, short length
)
2779 net_local
*lp
= (net_local
*) dev
->priv
;
2780 unsigned long ioaddr
= dev
->base_addr
;
2781 unsigned short txblock
;
2782 unsigned short txpred
;
2783 unsigned short tx_addr
;
2784 unsigned short nop_addr
;
2785 unsigned short tbd_addr
;
2786 unsigned short buf_addr
;
2791 unsigned long flags
;
2793 #ifdef DEBUG_TX_TRACE
2794 printk(KERN_DEBUG
"%s: ->wv_packet_write(%d)\n", dev
->name
,
2798 spin_lock_irqsave(&lp
->spinlock
, flags
);
2800 /* Check nothing bad has happened */
2801 if (lp
->tx_n_in_use
== (NTXBLOCKS
- 1)) {
2802 #ifdef DEBUG_TX_ERROR
2803 printk(KERN_INFO
"%s: wv_packet_write(): Tx queue full.\n",
2806 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2810 /* Calculate addresses of next block and previous block. */
2811 txblock
= lp
->tx_first_free
;
2812 txpred
= txblock
- TXBLOCKZ
;
2813 if (txpred
< OFFSET_CU
)
2814 txpred
+= NTXBLOCKS
* TXBLOCKZ
;
2815 lp
->tx_first_free
+= TXBLOCKZ
;
2816 if (lp
->tx_first_free
>= OFFSET_CU
+ NTXBLOCKS
* TXBLOCKZ
)
2817 lp
->tx_first_free
-= NTXBLOCKS
* TXBLOCKZ
;
2821 /* Calculate addresses of the different parts of the block. */
2823 nop_addr
= tx_addr
+ sizeof(tx
);
2824 tbd_addr
= nop_addr
+ sizeof(nop
);
2825 buf_addr
= tbd_addr
+ sizeof(tbd
);
2830 tx
.tx_h
.ac_status
= 0;
2831 obram_write(ioaddr
, toff(ac_tx_t
, tx_addr
, tx_h
.ac_status
),
2832 (unsigned char *) &tx
.tx_h
.ac_status
,
2833 sizeof(tx
.tx_h
.ac_status
));
2838 nop
.nop_h
.ac_status
= 0;
2839 obram_write(ioaddr
, toff(ac_nop_t
, nop_addr
, nop_h
.ac_status
),
2840 (unsigned char *) &nop
.nop_h
.ac_status
,
2841 sizeof(nop
.nop_h
.ac_status
));
2842 nop
.nop_h
.ac_link
= nop_addr
;
2843 obram_write(ioaddr
, toff(ac_nop_t
, nop_addr
, nop_h
.ac_link
),
2844 (unsigned char *) &nop
.nop_h
.ac_link
,
2845 sizeof(nop
.nop_h
.ac_link
));
2848 * Transmit buffer descriptor
2850 tbd
.tbd_status
= TBD_STATUS_EOF
| (TBD_STATUS_ACNT
& clen
);
2851 tbd
.tbd_next_bd_offset
= I82586NULL
;
2852 tbd
.tbd_bufl
= buf_addr
;
2854 obram_write(ioaddr
, tbd_addr
, (unsigned char *) &tbd
, sizeof(tbd
));
2859 obram_write(ioaddr
, buf_addr
, buf
, length
);
2862 * Overwrite the predecessor NOP link
2863 * so that it points to this txblock.
2865 nop_addr
= txpred
+ sizeof(tx
);
2866 nop
.nop_h
.ac_status
= 0;
2867 obram_write(ioaddr
, toff(ac_nop_t
, nop_addr
, nop_h
.ac_status
),
2868 (unsigned char *) &nop
.nop_h
.ac_status
,
2869 sizeof(nop
.nop_h
.ac_status
));
2870 nop
.nop_h
.ac_link
= txblock
;
2871 obram_write(ioaddr
, toff(ac_nop_t
, nop_addr
, nop_h
.ac_link
),
2872 (unsigned char *) &nop
.nop_h
.ac_link
,
2873 sizeof(nop
.nop_h
.ac_link
));
2875 /* Make sure the watchdog will keep quiet for a while */
2876 dev
->trans_start
= jiffies
;
2878 /* Keep stats up to date. */
2879 lp
->stats
.tx_bytes
+= length
;
2881 if (lp
->tx_first_in_use
== I82586NULL
)
2882 lp
->tx_first_in_use
= txblock
;
2884 if (lp
->tx_n_in_use
< NTXBLOCKS
- 1)
2885 netif_wake_queue(dev
);
2887 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2889 #ifdef DEBUG_TX_INFO
2890 wv_packet_info((u8
*) buf
, length
, dev
->name
,
2892 #endif /* DEBUG_TX_INFO */
2894 #ifdef DEBUG_TX_TRACE
2895 printk(KERN_DEBUG
"%s: <-wv_packet_write()\n", dev
->name
);
2901 /*------------------------------------------------------------------*/
2903 * This routine is called when we want to send a packet (NET3 callback)
2904 * In this routine, we check if the harware is ready to accept
2905 * the packet. We also prevent reentrance. Then we call the function
2906 * to send the packet.
2908 static int wavelan_packet_xmit(struct sk_buff
*skb
, struct net_device
* dev
)
2910 net_local
*lp
= (net_local
*) dev
->priv
;
2911 unsigned long flags
;
2913 #ifdef DEBUG_TX_TRACE
2914 printk(KERN_DEBUG
"%s: ->wavelan_packet_xmit(0x%X)\n", dev
->name
,
2919 * Block a timer-based transmit from overlapping.
2920 * In other words, prevent reentering this routine.
2922 netif_stop_queue(dev
);
2924 /* If somebody has asked to reconfigure the controller,
2927 if (lp
->reconfig_82586
) {
2928 spin_lock_irqsave(&lp
->spinlock
, flags
);
2929 wv_82586_config(dev
);
2930 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
2931 /* Check that we can continue */
2932 if (lp
->tx_n_in_use
== (NTXBLOCKS
- 1))
2935 #ifdef DEBUG_TX_ERROR
2937 printk(KERN_INFO
"skb has next\n");
2940 /* Do we need some padding? */
2941 /* Note : on wireless the propagation time is in the order of 1us,
2942 * and we don't have the Ethernet specific requirement of beeing
2943 * able to detect collisions, therefore in theory we don't really
2944 * need to pad. Jean II */
2945 if (skb
->len
< ETH_ZLEN
) {
2946 skb
= skb_padto(skb
, ETH_ZLEN
);
2951 /* Write packet on the card */
2952 if(wv_packet_write(dev
, skb
->data
, skb
->len
))
2953 return 1; /* We failed */
2957 #ifdef DEBUG_TX_TRACE
2958 printk(KERN_DEBUG
"%s: <-wavelan_packet_xmit()\n", dev
->name
);
2963 /*********************** HARDWARE CONFIGURATION ***********************/
2965 * This part does the real job of starting and configuring the hardware.
2968 /*--------------------------------------------------------------------*/
2970 * Routine to initialize the Modem Management Controller.
2971 * (called by wv_hw_reset())
2973 static inline int wv_mmc_init(struct net_device
* dev
)
2975 unsigned long ioaddr
= dev
->base_addr
;
2976 net_local
*lp
= (net_local
*) dev
->priv
;
2981 #ifdef DEBUG_CONFIG_TRACE
2982 printk(KERN_DEBUG
"%s: ->wv_mmc_init()\n", dev
->name
);
2985 /* Read the parameter storage area. */
2986 psa_read(ioaddr
, lp
->hacr
, 0, (unsigned char *) &psa
, sizeof(psa
));
2988 #ifdef USE_PSA_CONFIG
2989 configured
= psa
.psa_conf_status
& 1;
2994 /* Is the PSA is not configured */
2996 /* User will be able to configure NWID later (with iwconfig). */
2997 psa
.psa_nwid
[0] = 0;
2998 psa
.psa_nwid
[1] = 0;
3000 /* no NWID checking since NWID is not set */
3001 psa
.psa_nwid_select
= 0;
3003 /* Disable encryption */
3004 psa
.psa_encryption_select
= 0;
3006 /* Set to standard values:
3009 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
3011 if (psa
.psa_comp_number
& 1)
3012 psa
.psa_thr_pre_set
= 0x01;
3014 psa
.psa_thr_pre_set
= 0x04;
3015 psa
.psa_quality_thr
= 0x03;
3017 /* It is configured */
3018 psa
.psa_conf_status
|= 1;
3020 #ifdef USE_PSA_CONFIG
3021 /* Write the psa. */
3022 psa_write(ioaddr
, lp
->hacr
,
3023 (char *) psa
.psa_nwid
- (char *) &psa
,
3024 (unsigned char *) psa
.psa_nwid
, 4);
3025 psa_write(ioaddr
, lp
->hacr
,
3026 (char *) &psa
.psa_thr_pre_set
- (char *) &psa
,
3027 (unsigned char *) &psa
.psa_thr_pre_set
, 1);
3028 psa_write(ioaddr
, lp
->hacr
,
3029 (char *) &psa
.psa_quality_thr
- (char *) &psa
,
3030 (unsigned char *) &psa
.psa_quality_thr
, 1);
3031 psa_write(ioaddr
, lp
->hacr
,
3032 (char *) &psa
.psa_conf_status
- (char *) &psa
,
3033 (unsigned char *) &psa
.psa_conf_status
, 1);
3034 /* update the Wavelan checksum */
3035 update_psa_checksum(dev
, ioaddr
, lp
->hacr
);
3039 /* Zero the mmc structure. */
3040 memset(&m
, 0x00, sizeof(m
));
3042 /* Copy PSA info to the mmc. */
3043 m
.mmw_netw_id_l
= psa
.psa_nwid
[1];
3044 m
.mmw_netw_id_h
= psa
.psa_nwid
[0];
3046 if (psa
.psa_nwid_select
& 1)
3047 m
.mmw_loopt_sel
= 0x00;
3049 m
.mmw_loopt_sel
= MMW_LOOPT_SEL_DIS_NWID
;
3051 memcpy(&m
.mmw_encr_key
, &psa
.psa_encryption_key
,
3052 sizeof(m
.mmw_encr_key
));
3054 if (psa
.psa_encryption_select
)
3056 MMW_ENCR_ENABLE_EN
| MMW_ENCR_ENABLE_MODE
;
3058 m
.mmw_encr_enable
= 0;
3060 m
.mmw_thr_pre_set
= psa
.psa_thr_pre_set
& 0x3F;
3061 m
.mmw_quality_thr
= psa
.psa_quality_thr
& 0x0F;
3064 * Set default modem control parameters.
3065 * See NCR document 407-0024326 Rev. A.
3067 m
.mmw_jabber_enable
= 0x01;
3069 m
.mmw_anten_sel
= MMW_ANTEN_SEL_ALG_EN
;
3071 m
.mmw_mod_delay
= 0x04;
3072 m
.mmw_jam_time
= 0x38;
3074 m
.mmw_des_io_invert
= 0;
3075 m
.mmw_decay_prm
= 0;
3076 m
.mmw_decay_updat_prm
= 0;
3078 /* Write all info to MMC. */
3079 mmc_write(ioaddr
, 0, (u8
*) & m
, sizeof(m
));
3081 /* The following code starts the modem of the 2.00 frequency
3082 * selectable cards at power on. It's not strictly needed for the
3084 * The original patch was by Joe Finney for the PCMCIA driver, but
3085 * I've cleaned it up a bit and added documentation.
3086 * Thanks to Loeke Brederveld from Lucent for the info.
3089 /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
3090 * Does it work for everybody, especially old cards? */
3091 /* Note: WFREQSEL verifies that it is able to read a sensible
3092 * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
3093 * is 0xA (Xilinx version) or 0xB (Ariadne version).
3094 * My test is more crude but does work. */
3095 if (!(mmc_in(ioaddr
, mmroff(0, mmr_fee_status
)) &
3096 (MMR_FEE_STATUS_DWLD
| MMR_FEE_STATUS_BUSY
))) {
3097 /* We must download the frequency parameters to the
3098 * synthesizers (from the EEPROM - area 1)
3099 * Note: as the EEPROM is automatically decremented, we set the end
3101 m
.mmw_fee_addr
= 0x0F;
3102 m
.mmw_fee_ctrl
= MMW_FEE_CTRL_READ
| MMW_FEE_CTRL_DWLD
;
3103 mmc_write(ioaddr
, (char *) &m
.mmw_fee_ctrl
- (char *) &m
,
3104 (unsigned char *) &m
.mmw_fee_ctrl
, 2);
3106 /* Wait until the download is finished. */
3107 fee_wait(ioaddr
, 100, 100);
3109 #ifdef DEBUG_CONFIG_INFO
3110 /* The frequency was in the last word downloaded. */
3111 mmc_read(ioaddr
, (char *) &m
.mmw_fee_data_l
- (char *) &m
,
3112 (unsigned char *) &m
.mmw_fee_data_l
, 2);
3114 /* Print some info for the user. */
3116 "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n",
3119 mmw_fee_data_h
<< 4) | (m
.mmw_fee_data_l
>> 4)) *
3123 /* We must now download the power adjust value (gain) to
3124 * the synthesizers (from the EEPROM - area 7 - DAC). */
3125 m
.mmw_fee_addr
= 0x61;
3126 m
.mmw_fee_ctrl
= MMW_FEE_CTRL_READ
| MMW_FEE_CTRL_DWLD
;
3127 mmc_write(ioaddr
, (char *) &m
.mmw_fee_ctrl
- (char *) &m
,
3128 (unsigned char *) &m
.mmw_fee_ctrl
, 2);
3130 /* Wait until the download is finished. */
3133 #ifdef DEBUG_CONFIG_TRACE
3134 printk(KERN_DEBUG
"%s: <-wv_mmc_init()\n", dev
->name
);
3139 /*------------------------------------------------------------------*/
3141 * Construct the fd and rbd structures.
3142 * Start the receive unit.
3143 * (called by wv_hw_reset())
3145 static inline int wv_ru_start(struct net_device
* dev
)
3147 net_local
*lp
= (net_local
*) dev
->priv
;
3148 unsigned long ioaddr
= dev
->base_addr
;
3156 #ifdef DEBUG_CONFIG_TRACE
3157 printk(KERN_DEBUG
"%s: ->wv_ru_start()\n", dev
->name
);
3160 obram_read(ioaddr
, scboff(OFFSET_SCB
, scb_status
),
3161 (unsigned char *) &scb_cs
, sizeof(scb_cs
));
3162 if ((scb_cs
& SCB_ST_RUS
) == SCB_ST_RUS_RDY
)
3165 lp
->rx_head
= OFFSET_RU
;
3167 for (i
= 0, rx
= lp
->rx_head
; i
< NRXBLOCKS
; i
++, rx
= rx_next
) {
3169 (i
== NRXBLOCKS
- 1) ? lp
->rx_head
: rx
+ RXBLOCKZ
;
3172 fd
.fd_command
= (i
== NRXBLOCKS
- 1) ? FD_COMMAND_EL
: 0;
3173 fd
.fd_link_offset
= rx_next
;
3174 fd
.fd_rbd_offset
= rx
+ sizeof(fd
);
3175 obram_write(ioaddr
, rx
, (unsigned char *) &fd
, sizeof(fd
));
3178 rbd
.rbd_next_rbd_offset
= I82586NULL
;
3179 rbd
.rbd_bufl
= rx
+ sizeof(fd
) + sizeof(rbd
);
3181 rbd
.rbd_el_size
= RBD_EL
| (RBD_SIZE
& MAXDATAZ
);
3182 obram_write(ioaddr
, rx
+ sizeof(fd
),
3183 (unsigned char *) &rbd
, sizeof(rbd
));
3188 obram_write(ioaddr
, scboff(OFFSET_SCB
, scb_rfa_offset
),
3189 (unsigned char *) &lp
->rx_head
, sizeof(lp
->rx_head
));
3191 scb_cs
= SCB_CMD_RUC_GO
;
3192 obram_write(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
3193 (unsigned char *) &scb_cs
, sizeof(scb_cs
));
3195 set_chan_attn(ioaddr
, lp
->hacr
);
3197 for (i
= 1000; i
> 0; i
--) {
3198 obram_read(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
3199 (unsigned char *) &scb_cs
, sizeof(scb_cs
));
3207 #ifdef DEBUG_CONFIG_ERROR
3209 "%s: wavelan_ru_start(): board not accepting command.\n",
3214 #ifdef DEBUG_CONFIG_TRACE
3215 printk(KERN_DEBUG
"%s: <-wv_ru_start()\n", dev
->name
);
3220 /*------------------------------------------------------------------*/
3222 * Initialise the transmit blocks.
3223 * Start the command unit executing the NOP
3224 * self-loop of the first transmit block.
3226 * Here we create the list of send buffers used to transmit packets
3227 * between the PC and the command unit. For each buffer, we create a
3228 * buffer descriptor (pointing on the buffer), a transmit command
3229 * (pointing to the buffer descriptor) and a NOP command.
3230 * The transmit command is linked to the NOP, and the NOP to itself.
3231 * When we will have finished executing the transmit command, we will
3232 * then loop on the NOP. By releasing the NOP link to a new command,
3233 * we may send another buffer.
3235 * (called by wv_hw_reset())
3237 static inline int wv_cu_start(struct net_device
* dev
)
3239 net_local
*lp
= (net_local
*) dev
->priv
;
3240 unsigned long ioaddr
= dev
->base_addr
;
3246 #ifdef DEBUG_CONFIG_TRACE
3247 printk(KERN_DEBUG
"%s: ->wv_cu_start()\n", dev
->name
);
3250 lp
->tx_first_free
= OFFSET_CU
;
3251 lp
->tx_first_in_use
= I82586NULL
;
3253 for (i
= 0, txblock
= OFFSET_CU
;
3254 i
< NTXBLOCKS
; i
++, txblock
+= TXBLOCKZ
) {
3258 unsigned short tx_addr
;
3259 unsigned short nop_addr
;
3260 unsigned short tbd_addr
;
3261 unsigned short buf_addr
;
3264 nop_addr
= tx_addr
+ sizeof(tx
);
3265 tbd_addr
= nop_addr
+ sizeof(nop
);
3266 buf_addr
= tbd_addr
+ sizeof(tbd
);
3268 tx
.tx_h
.ac_status
= 0;
3269 tx
.tx_h
.ac_command
= acmd_transmit
| AC_CFLD_I
;
3270 tx
.tx_h
.ac_link
= nop_addr
;
3271 tx
.tx_tbd_offset
= tbd_addr
;
3272 obram_write(ioaddr
, tx_addr
, (unsigned char *) &tx
,
3275 nop
.nop_h
.ac_status
= 0;
3276 nop
.nop_h
.ac_command
= acmd_nop
;
3277 nop
.nop_h
.ac_link
= nop_addr
;
3278 obram_write(ioaddr
, nop_addr
, (unsigned char *) &nop
,
3281 tbd
.tbd_status
= TBD_STATUS_EOF
;
3282 tbd
.tbd_next_bd_offset
= I82586NULL
;
3283 tbd
.tbd_bufl
= buf_addr
;
3285 obram_write(ioaddr
, tbd_addr
, (unsigned char *) &tbd
,
3290 OFFSET_CU
+ (NTXBLOCKS
- 1) * TXBLOCKZ
+ sizeof(ac_tx_t
);
3291 obram_write(ioaddr
, scboff(OFFSET_SCB
, scb_cbl_offset
),
3292 (unsigned char *) &first_nop
, sizeof(first_nop
));
3294 scb_cs
= SCB_CMD_CUC_GO
;
3295 obram_write(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
3296 (unsigned char *) &scb_cs
, sizeof(scb_cs
));
3298 set_chan_attn(ioaddr
, lp
->hacr
);
3300 for (i
= 1000; i
> 0; i
--) {
3301 obram_read(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
3302 (unsigned char *) &scb_cs
, sizeof(scb_cs
));
3310 #ifdef DEBUG_CONFIG_ERROR
3312 "%s: wavelan_cu_start(): board not accepting command.\n",
3318 lp
->tx_n_in_use
= 0;
3319 netif_start_queue(dev
);
3320 #ifdef DEBUG_CONFIG_TRACE
3321 printk(KERN_DEBUG
"%s: <-wv_cu_start()\n", dev
->name
);
3326 /*------------------------------------------------------------------*/
3328 * This routine does a standard configuration of the WaveLAN
3329 * controller (i82586).
3331 * It initialises the scp, iscp and scb structure
3332 * The first two are just pointers to the next.
3333 * The last one is used for basic configuration and for basic
3334 * communication (interrupt status).
3336 * (called by wv_hw_reset())
3338 static inline int wv_82586_start(struct net_device
* dev
)
3340 net_local
*lp
= (net_local
*) dev
->priv
;
3341 unsigned long ioaddr
= dev
->base_addr
;
3342 scp_t scp
; /* system configuration pointer */
3343 iscp_t iscp
; /* intermediate scp */
3344 scb_t scb
; /* system control block */
3345 ach_t cb
; /* Action command header */
3349 #ifdef DEBUG_CONFIG_TRACE
3350 printk(KERN_DEBUG
"%s: ->wv_82586_start()\n", dev
->name
);
3354 * Clear the onboard RAM.
3356 memset(&zeroes
[0], 0x00, sizeof(zeroes
));
3357 for (i
= 0; i
< I82586_MEMZ
; i
+= sizeof(zeroes
))
3358 obram_write(ioaddr
, i
, &zeroes
[0], sizeof(zeroes
));
3361 * Construct the command unit structures:
3362 * scp, iscp, scb, cb.
3364 memset(&scp
, 0x00, sizeof(scp
));
3365 scp
.scp_sysbus
= SCP_SY_16BBUS
;
3366 scp
.scp_iscpl
= OFFSET_ISCP
;
3367 obram_write(ioaddr
, OFFSET_SCP
, (unsigned char *) &scp
,
3370 memset(&iscp
, 0x00, sizeof(iscp
));
3372 iscp
.iscp_offset
= OFFSET_SCB
;
3373 obram_write(ioaddr
, OFFSET_ISCP
, (unsigned char *) &iscp
,
3376 /* Our first command is to reset the i82586. */
3377 memset(&scb
, 0x00, sizeof(scb
));
3378 scb
.scb_command
= SCB_CMD_RESET
;
3379 scb
.scb_cbl_offset
= OFFSET_CU
;
3380 scb
.scb_rfa_offset
= OFFSET_RU
;
3381 obram_write(ioaddr
, OFFSET_SCB
, (unsigned char *) &scb
,
3384 set_chan_attn(ioaddr
, lp
->hacr
);
3386 /* Wait for command to finish. */
3387 for (i
= 1000; i
> 0; i
--) {
3388 obram_read(ioaddr
, OFFSET_ISCP
, (unsigned char *) &iscp
,
3391 if (iscp
.iscp_busy
== (unsigned short) 0)
3398 #ifdef DEBUG_CONFIG_ERROR
3400 "%s: wv_82586_start(): iscp_busy timeout.\n",
3406 /* Check command completion. */
3407 for (i
= 15; i
> 0; i
--) {
3408 obram_read(ioaddr
, OFFSET_SCB
, (unsigned char *) &scb
,
3411 if (scb
.scb_status
== (SCB_ST_CX
| SCB_ST_CNA
))
3418 #ifdef DEBUG_CONFIG_ERROR
3420 "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
3421 dev
->name
, SCB_ST_CX
| SCB_ST_CNA
, scb
.scb_status
);
3428 /* Set the action command header. */
3429 memset(&cb
, 0x00, sizeof(cb
));
3430 cb
.ac_command
= AC_CFLD_EL
| (AC_CFLD_CMD
& acmd_diagnose
);
3431 cb
.ac_link
= OFFSET_CU
;
3432 obram_write(ioaddr
, OFFSET_CU
, (unsigned char *) &cb
, sizeof(cb
));
3434 if (wv_synchronous_cmd(dev
, "diag()") == -1)
3437 obram_read(ioaddr
, OFFSET_CU
, (unsigned char *) &cb
, sizeof(cb
));
3438 if (cb
.ac_status
& AC_SFLD_FAIL
) {
3439 #ifdef DEBUG_CONFIG_ERROR
3441 "%s: wv_82586_start(): i82586 Self Test failed.\n",
3446 #ifdef DEBUG_I82586_SHOW
3447 wv_scb_show(ioaddr
);
3450 #ifdef DEBUG_CONFIG_TRACE
3451 printk(KERN_DEBUG
"%s: <-wv_82586_start()\n", dev
->name
);
3456 /*------------------------------------------------------------------*/
3458 * This routine does a standard configuration of the WaveLAN
3459 * controller (i82586).
3461 * This routine is a violent hack. We use the first free transmit block
3462 * to make our configuration. In the buffer area, we create the three
3463 * configuration commands (linked). We make the previous NOP point to
3464 * the beginning of the buffer instead of the tx command. After, we go
3465 * as usual to the NOP command.
3466 * Note that only the last command (mc_set) will generate an interrupt.
3468 * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit())
3470 static void wv_82586_config(struct net_device
* dev
)
3472 net_local
*lp
= (net_local
*) dev
->priv
;
3473 unsigned long ioaddr
= dev
->base_addr
;
3474 unsigned short txblock
;
3475 unsigned short txpred
;
3476 unsigned short tx_addr
;
3477 unsigned short nop_addr
;
3478 unsigned short tbd_addr
;
3479 unsigned short cfg_addr
;
3480 unsigned short ias_addr
;
3481 unsigned short mcs_addr
;
3484 ac_cfg_t cfg
; /* Configure action */
3485 ac_ias_t ias
; /* IA-setup action */
3486 ac_mcs_t mcs
; /* Multicast setup */
3487 struct dev_mc_list
*dmi
;
3489 #ifdef DEBUG_CONFIG_TRACE
3490 printk(KERN_DEBUG
"%s: ->wv_82586_config()\n", dev
->name
);
3493 /* Check nothing bad has happened */
3494 if (lp
->tx_n_in_use
== (NTXBLOCKS
- 1)) {
3495 #ifdef DEBUG_CONFIG_ERROR
3496 printk(KERN_INFO
"%s: wv_82586_config(): Tx queue full.\n",
3502 /* Calculate addresses of next block and previous block. */
3503 txblock
= lp
->tx_first_free
;
3504 txpred
= txblock
- TXBLOCKZ
;
3505 if (txpred
< OFFSET_CU
)
3506 txpred
+= NTXBLOCKS
* TXBLOCKZ
;
3507 lp
->tx_first_free
+= TXBLOCKZ
;
3508 if (lp
->tx_first_free
>= OFFSET_CU
+ NTXBLOCKS
* TXBLOCKZ
)
3509 lp
->tx_first_free
-= NTXBLOCKS
* TXBLOCKZ
;
3513 /* Calculate addresses of the different parts of the block. */
3515 nop_addr
= tx_addr
+ sizeof(tx
);
3516 tbd_addr
= nop_addr
+ sizeof(nop
);
3517 cfg_addr
= tbd_addr
+ sizeof(tbd_t
); /* beginning of the buffer */
3518 ias_addr
= cfg_addr
+ sizeof(cfg
);
3519 mcs_addr
= ias_addr
+ sizeof(ias
);
3524 tx
.tx_h
.ac_status
= 0xFFFF; /* Fake completion value */
3525 obram_write(ioaddr
, toff(ac_tx_t
, tx_addr
, tx_h
.ac_status
),
3526 (unsigned char *) &tx
.tx_h
.ac_status
,
3527 sizeof(tx
.tx_h
.ac_status
));
3532 nop
.nop_h
.ac_status
= 0;
3533 obram_write(ioaddr
, toff(ac_nop_t
, nop_addr
, nop_h
.ac_status
),
3534 (unsigned char *) &nop
.nop_h
.ac_status
,
3535 sizeof(nop
.nop_h
.ac_status
));
3536 nop
.nop_h
.ac_link
= nop_addr
;
3537 obram_write(ioaddr
, toff(ac_nop_t
, nop_addr
, nop_h
.ac_link
),
3538 (unsigned char *) &nop
.nop_h
.ac_link
,
3539 sizeof(nop
.nop_h
.ac_link
));
3541 /* Create a configure action. */
3542 memset(&cfg
, 0x00, sizeof(cfg
));
3545 * For Linux we invert AC_CFG_ALOC() so as to conform
3546 * to the way that net packets reach us from above.
3547 * (See also ac_tx_t.)
3549 * Updated from Wavelan Manual WCIN085B
3552 AC_CFG_BYTE_CNT(sizeof(ac_cfg_t
) - sizeof(ach_t
));
3553 cfg
.cfg_fifolim
= AC_CFG_FIFOLIM(4);
3554 cfg
.cfg_byte8
= AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0);
3555 cfg
.cfg_byte9
= AC_CFG_ELPBCK(0) |
3557 AC_CFG_PRELEN(AC_CFG_PLEN_2
) |
3558 AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE
);
3559 cfg
.cfg_byte10
= AC_CFG_BOFMET(1) |
3560 AC_CFG_ACR(6) | AC_CFG_LINPRIO(0);
3562 cfg
.cfg_slotl
= 0x0C;
3563 cfg
.cfg_byte13
= AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0);
3564 cfg
.cfg_byte14
= AC_CFG_FLGPAD(0) |
3570 AC_CFG_BCDIS(0) | AC_CFG_PRM(lp
->promiscuous
);
3571 cfg
.cfg_byte15
= AC_CFG_ICDS(0) |
3572 AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0);
3574 cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
3576 cfg
.cfg_min_frm_len
= AC_CFG_MNFRM(8);
3578 cfg
.cfg_h
.ac_command
= (AC_CFLD_CMD
& acmd_configure
);
3579 cfg
.cfg_h
.ac_link
= ias_addr
;
3580 obram_write(ioaddr
, cfg_addr
, (unsigned char *) &cfg
, sizeof(cfg
));
3582 /* Set up the MAC address */
3583 memset(&ias
, 0x00, sizeof(ias
));
3584 ias
.ias_h
.ac_command
= (AC_CFLD_CMD
& acmd_ia_setup
);
3585 ias
.ias_h
.ac_link
= mcs_addr
;
3586 memcpy(&ias
.ias_addr
[0], (unsigned char *) &dev
->dev_addr
[0],
3587 sizeof(ias
.ias_addr
));
3588 obram_write(ioaddr
, ias_addr
, (unsigned char *) &ias
, sizeof(ias
));
3590 /* Initialize adapter's Ethernet multicast addresses */
3591 memset(&mcs
, 0x00, sizeof(mcs
));
3592 mcs
.mcs_h
.ac_command
= AC_CFLD_I
| (AC_CFLD_CMD
& acmd_mc_setup
);
3593 mcs
.mcs_h
.ac_link
= nop_addr
;
3594 mcs
.mcs_cnt
= WAVELAN_ADDR_SIZE
* lp
->mc_count
;
3595 obram_write(ioaddr
, mcs_addr
, (unsigned char *) &mcs
, sizeof(mcs
));
3597 /* Any address to set? */
3599 for (dmi
= dev
->mc_list
; dmi
; dmi
= dmi
->next
)
3600 outsw(PIOP1(ioaddr
), (u16
*) dmi
->dmi_addr
,
3601 WAVELAN_ADDR_SIZE
>> 1);
3603 #ifdef DEBUG_CONFIG_INFO
3605 "%s: wv_82586_config(): set %d multicast addresses:\n",
3606 dev
->name
, lp
->mc_count
);
3607 for (dmi
= dev
->mc_list
; dmi
; dmi
= dmi
->next
)
3609 " %02x:%02x:%02x:%02x:%02x:%02x\n",
3610 dmi
->dmi_addr
[0], dmi
->dmi_addr
[1],
3611 dmi
->dmi_addr
[2], dmi
->dmi_addr
[3],
3612 dmi
->dmi_addr
[4], dmi
->dmi_addr
[5]);
3617 * Overwrite the predecessor NOP link
3618 * so that it points to the configure action.
3620 nop_addr
= txpred
+ sizeof(tx
);
3621 nop
.nop_h
.ac_status
= 0;
3622 obram_write(ioaddr
, toff(ac_nop_t
, nop_addr
, nop_h
.ac_status
),
3623 (unsigned char *) &nop
.nop_h
.ac_status
,
3624 sizeof(nop
.nop_h
.ac_status
));
3625 nop
.nop_h
.ac_link
= cfg_addr
;
3626 obram_write(ioaddr
, toff(ac_nop_t
, nop_addr
, nop_h
.ac_link
),
3627 (unsigned char *) &nop
.nop_h
.ac_link
,
3628 sizeof(nop
.nop_h
.ac_link
));
3630 /* Job done, clear the flag */
3631 lp
->reconfig_82586
= 0;
3633 if (lp
->tx_first_in_use
== I82586NULL
)
3634 lp
->tx_first_in_use
= txblock
;
3636 if (lp
->tx_n_in_use
== (NTXBLOCKS
- 1))
3637 netif_stop_queue(dev
);
3639 #ifdef DEBUG_CONFIG_TRACE
3640 printk(KERN_DEBUG
"%s: <-wv_82586_config()\n", dev
->name
);
3644 /*------------------------------------------------------------------*/
3646 * This routine, called by wavelan_close(), gracefully stops the
3647 * WaveLAN controller (i82586).
3648 * (called by wavelan_close())
3650 static inline void wv_82586_stop(struct net_device
* dev
)
3652 net_local
*lp
= (net_local
*) dev
->priv
;
3653 unsigned long ioaddr
= dev
->base_addr
;
3656 #ifdef DEBUG_CONFIG_TRACE
3657 printk(KERN_DEBUG
"%s: ->wv_82586_stop()\n", dev
->name
);
3660 /* Suspend both command unit and receive unit. */
3662 (SCB_CMD_CUC
& SCB_CMD_CUC_SUS
) | (SCB_CMD_RUC
&
3664 obram_write(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
3665 (unsigned char *) &scb_cmd
, sizeof(scb_cmd
));
3666 set_chan_attn(ioaddr
, lp
->hacr
);
3668 /* No more interrupts */
3671 #ifdef DEBUG_CONFIG_TRACE
3672 printk(KERN_DEBUG
"%s: <-wv_82586_stop()\n", dev
->name
);
3676 /*------------------------------------------------------------------*/
3678 * Totally reset the WaveLAN and restart it.
3679 * Performs the following actions:
3680 * 1. A power reset (reset DMA)
3681 * 2. Initialize the radio modem (using wv_mmc_init)
3682 * 3. Reset & Configure LAN controller (using wv_82586_start)
3683 * 4. Start the LAN controller's command unit
3684 * 5. Start the LAN controller's receive unit
3685 * (called by wavelan_interrupt(), wavelan_watchdog() & wavelan_open())
3687 static int wv_hw_reset(struct net_device
* dev
)
3689 net_local
*lp
= (net_local
*) dev
->priv
;
3690 unsigned long ioaddr
= dev
->base_addr
;
3692 #ifdef DEBUG_CONFIG_TRACE
3693 printk(KERN_DEBUG
"%s: ->wv_hw_reset(dev=0x%x)\n", dev
->name
,
3694 (unsigned int) dev
);
3697 /* Increase the number of resets done. */
3700 wv_hacr_reset(ioaddr
);
3701 lp
->hacr
= HACR_DEFAULT
;
3703 if ((wv_mmc_init(dev
) < 0) || (wv_82586_start(dev
) < 0))
3706 /* Enable the card to send interrupts. */
3709 /* Start card functions */
3710 if (wv_cu_start(dev
) < 0)
3713 /* Setup the controller and parameters */
3714 wv_82586_config(dev
);
3716 /* Finish configuration with the receive unit */
3717 if (wv_ru_start(dev
) < 0)
3720 #ifdef DEBUG_CONFIG_TRACE
3721 printk(KERN_DEBUG
"%s: <-wv_hw_reset()\n", dev
->name
);
3726 /*------------------------------------------------------------------*/
3728 * Check if there is a WaveLAN at the specific base address.
3729 * As a side effect, this reads the MAC address.
3730 * (called in wavelan_probe() and init_module())
3732 static int wv_check_ioaddr(unsigned long ioaddr
, u8
* mac
)
3734 int i
; /* Loop counter */
3736 /* Check if the base address if available. */
3737 if (!request_region(ioaddr
, sizeof(ha_t
), "wavelan probe"))
3738 return -EBUSY
; /* ioaddr already used */
3740 /* Reset host interface */
3741 wv_hacr_reset(ioaddr
);
3743 /* Read the MAC address from the parameter storage area. */
3744 psa_read(ioaddr
, HACR_DEFAULT
, psaoff(0, psa_univ_mac_addr
),
3747 release_region(ioaddr
, sizeof(ha_t
));
3750 * Check the first three octets of the address for the manufacturer's code.
3751 * Note: if this can't find your WaveLAN card, you've got a
3752 * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on
3753 * how to configure your card.
3755 for (i
= 0; i
< (sizeof(MAC_ADDRESSES
) / sizeof(char) / 3); i
++)
3756 if ((mac
[0] == MAC_ADDRESSES
[i
][0]) &&
3757 (mac
[1] == MAC_ADDRESSES
[i
][1]) &&
3758 (mac
[2] == MAC_ADDRESSES
[i
][2]))
3761 #ifdef DEBUG_CONFIG_INFO
3763 "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
3764 ioaddr
, mac
[0], mac
[1], mac
[2]);
3769 /************************ INTERRUPT HANDLING ************************/
3772 * This function is the interrupt handler for the WaveLAN card. This
3773 * routine will be called whenever:
3775 static irqreturn_t
wavelan_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
3777 struct net_device
*dev
;
3778 unsigned long ioaddr
;
3786 #ifdef DEBUG_INTERRUPT_TRACE
3787 printk(KERN_DEBUG
"%s: ->wavelan_interrupt()\n", dev
->name
);
3790 lp
= (net_local
*) dev
->priv
;
3791 ioaddr
= dev
->base_addr
;
3793 #ifdef DEBUG_INTERRUPT_INFO
3794 /* Check state of our spinlock */
3795 if(spin_is_locked(&lp
->spinlock
))
3797 "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
3801 /* Prevent reentrancy. We need to do that because we may have
3802 * multiple interrupt handler running concurrently.
3803 * It is safe because interrupts are disabled before acquiring
3805 spin_lock(&lp
->spinlock
);
3807 /* We always had spurious interrupts at startup, but lately I
3808 * saw them comming *between* the request_irq() and the
3809 * spin_lock_irqsave() in wavelan_open(), so the spinlock
3810 * protection is no enough.
3811 * So, we also check lp->hacr that will tell us is we enabled
3812 * irqs or not (see wv_ints_on()).
3813 * We can't use netif_running(dev) because we depend on the
3814 * proper processing of the irq generated during the config. */
3816 /* Which interrupt it is ? */
3817 hasr
= hasr_read(ioaddr
);
3819 #ifdef DEBUG_INTERRUPT_INFO
3821 "%s: wavelan_interrupt(): hasr 0x%04x; hacr 0x%04x.\n",
3822 dev
->name
, hasr
, lp
->hacr
);
3825 /* Check modem interrupt */
3826 if ((hasr
& HASR_MMC_INTR
) && (lp
->hacr
& HACR_MMC_INT_ENABLE
)) {
3830 * Interrupt from the modem management controller.
3831 * This will clear it -- ignored for now.
3833 mmc_read(ioaddr
, mmroff(0, mmr_dce_status
), &dce_status
,
3834 sizeof(dce_status
));
3836 #ifdef DEBUG_INTERRUPT_ERROR
3838 "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
3839 dev
->name
, dce_status
);
3843 /* Check if not controller interrupt */
3844 if (((hasr
& HASR_82586_INTR
) == 0) ||
3845 ((lp
->hacr
& HACR_82586_INT_ENABLE
) == 0)) {
3846 #ifdef DEBUG_INTERRUPT_ERROR
3848 "%s: wavelan_interrupt(): interrupt not coming from i82586 - hasr 0x%04x.\n",
3851 spin_unlock (&lp
->spinlock
);
3855 /* Read interrupt data. */
3856 obram_read(ioaddr
, scboff(OFFSET_SCB
, scb_status
),
3857 (unsigned char *) &status
, sizeof(status
));
3860 * Acknowledge the interrupt(s).
3862 ack_cmd
= status
& SCB_ST_INT
;
3863 obram_write(ioaddr
, scboff(OFFSET_SCB
, scb_command
),
3864 (unsigned char *) &ack_cmd
, sizeof(ack_cmd
));
3865 set_chan_attn(ioaddr
, lp
->hacr
);
3867 #ifdef DEBUG_INTERRUPT_INFO
3868 printk(KERN_DEBUG
"%s: wavelan_interrupt(): status 0x%04x.\n",
3872 /* Command completed. */
3873 if ((status
& SCB_ST_CX
) == SCB_ST_CX
) {
3874 #ifdef DEBUG_INTERRUPT_INFO
3876 "%s: wavelan_interrupt(): command completed.\n",
3879 wv_complete(dev
, ioaddr
, lp
);
3882 /* Frame received. */
3883 if ((status
& SCB_ST_FR
) == SCB_ST_FR
) {
3884 #ifdef DEBUG_INTERRUPT_INFO
3886 "%s: wavelan_interrupt(): received packet.\n",
3892 /* Check the state of the command unit. */
3893 if (((status
& SCB_ST_CNA
) == SCB_ST_CNA
) ||
3894 (((status
& SCB_ST_CUS
) != SCB_ST_CUS_ACTV
) &&
3895 (netif_running(dev
)))) {
3896 #ifdef DEBUG_INTERRUPT_ERROR
3898 "%s: wavelan_interrupt(): CU inactive -- restarting\n",
3904 /* Check the state of the command unit. */
3905 if (((status
& SCB_ST_RNR
) == SCB_ST_RNR
) ||
3906 (((status
& SCB_ST_RUS
) != SCB_ST_RUS_RDY
) &&
3907 (netif_running(dev
)))) {
3908 #ifdef DEBUG_INTERRUPT_ERROR
3910 "%s: wavelan_interrupt(): RU not ready -- restarting\n",
3916 /* Release spinlock */
3917 spin_unlock (&lp
->spinlock
);
3919 #ifdef DEBUG_INTERRUPT_TRACE
3920 printk(KERN_DEBUG
"%s: <-wavelan_interrupt()\n", dev
->name
);
3925 /*------------------------------------------------------------------*/
3927 * Watchdog: when we start a transmission, a timer is set for us in the
3928 * kernel. If the transmission completes, this timer is disabled. If
3929 * the timer expires, we are called and we try to unlock the hardware.
3931 static void wavelan_watchdog(struct net_device
* dev
)
3933 net_local
* lp
= (net_local
*)dev
->priv
;
3934 u_long ioaddr
= dev
->base_addr
;
3935 unsigned long flags
;
3936 unsigned int nreaped
;
3938 #ifdef DEBUG_INTERRUPT_TRACE
3939 printk(KERN_DEBUG
"%s: ->wavelan_watchdog()\n", dev
->name
);
3942 #ifdef DEBUG_INTERRUPT_ERROR
3943 printk(KERN_INFO
"%s: wavelan_watchdog: watchdog timer expired\n",
3947 /* Check that we came here for something */
3948 if (lp
->tx_n_in_use
<= 0) {
3952 spin_lock_irqsave(&lp
->spinlock
, flags
);
3954 /* Try to see if some buffers are not free (in case we missed
3956 nreaped
= wv_complete(dev
, ioaddr
, lp
);
3958 #ifdef DEBUG_INTERRUPT_INFO
3960 "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
3961 dev
->name
, nreaped
, lp
->tx_n_in_use
);
3964 #ifdef DEBUG_PSA_SHOW
3967 psa_read(dev
, 0, (unsigned char *) &psa
, sizeof(psa
));
3971 #ifdef DEBUG_MMC_SHOW
3974 #ifdef DEBUG_I82586_SHOW
3978 /* If no buffer has been freed */
3980 #ifdef DEBUG_INTERRUPT_ERROR
3982 "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
3988 /* At this point, we should have some free Tx buffer ;-) */
3989 if (lp
->tx_n_in_use
< NTXBLOCKS
- 1)
3990 netif_wake_queue(dev
);
3992 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
3994 #ifdef DEBUG_INTERRUPT_TRACE
3995 printk(KERN_DEBUG
"%s: <-wavelan_watchdog()\n", dev
->name
);
3999 /********************* CONFIGURATION CALLBACKS *********************/
4001 * Here are the functions called by the Linux networking code (NET3)
4002 * for initialization, configuration and deinstallations of the
4003 * WaveLAN ISA hardware.
4006 /*------------------------------------------------------------------*/
4008 * Configure and start up the WaveLAN PCMCIA adaptor.
4009 * Called by NET3 when it "opens" the device.
4011 static int wavelan_open(struct net_device
* dev
)
4013 net_local
* lp
= (net_local
*)dev
->priv
;
4014 unsigned long flags
;
4016 #ifdef DEBUG_CALLBACK_TRACE
4017 printk(KERN_DEBUG
"%s: ->wavelan_open(dev=0x%x)\n", dev
->name
,
4018 (unsigned int) dev
);
4022 if (dev
->irq
== 0) {
4023 #ifdef DEBUG_CONFIG_ERROR
4024 printk(KERN_WARNING
"%s: wavelan_open(): no IRQ\n",
4030 if (request_irq(dev
->irq
, &wavelan_interrupt
, 0, "WaveLAN", dev
) != 0)
4032 #ifdef DEBUG_CONFIG_ERROR
4033 printk(KERN_WARNING
"%s: wavelan_open(): invalid IRQ\n",
4039 spin_lock_irqsave(&lp
->spinlock
, flags
);
4041 if (wv_hw_reset(dev
) != -1) {
4042 netif_start_queue(dev
);
4044 free_irq(dev
->irq
, dev
);
4045 #ifdef DEBUG_CONFIG_ERROR
4047 "%s: wavelan_open(): impossible to start the card\n",
4050 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
4053 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
4055 #ifdef DEBUG_CALLBACK_TRACE
4056 printk(KERN_DEBUG
"%s: <-wavelan_open()\n", dev
->name
);
4061 /*------------------------------------------------------------------*/
4063 * Shut down the WaveLAN ISA card.
4064 * Called by NET3 when it "closes" the device.
4066 static int wavelan_close(struct net_device
* dev
)
4068 net_local
*lp
= (net_local
*) dev
->priv
;
4069 unsigned long flags
;
4071 #ifdef DEBUG_CALLBACK_TRACE
4072 printk(KERN_DEBUG
"%s: ->wavelan_close(dev=0x%x)\n", dev
->name
,
4073 (unsigned int) dev
);
4076 netif_stop_queue(dev
);
4079 * Flush the Tx and disable Rx.
4081 spin_lock_irqsave(&lp
->spinlock
, flags
);
4083 spin_unlock_irqrestore(&lp
->spinlock
, flags
);
4085 free_irq(dev
->irq
, dev
);
4087 #ifdef DEBUG_CALLBACK_TRACE
4088 printk(KERN_DEBUG
"%s: <-wavelan_close()\n", dev
->name
);
4093 /*------------------------------------------------------------------*/
4095 * Probe an I/O address, and if the WaveLAN is there configure the
4097 * (called by wavelan_probe() and via init_module()).
4099 static int __init
wavelan_config(struct net_device
*dev
, unsigned short ioaddr
)
4107 if (!request_region(ioaddr
, sizeof(ha_t
), "wavelan"))
4110 err
= wv_check_ioaddr(ioaddr
, mac
);
4114 memcpy(dev
->dev_addr
, mac
, 6);
4116 dev
->base_addr
= ioaddr
;
4118 #ifdef DEBUG_CALLBACK_TRACE
4119 printk(KERN_DEBUG
"%s: ->wavelan_config(dev=0x%x, ioaddr=0x%lx)\n",
4120 dev
->name
, (unsigned int) dev
, ioaddr
);
4123 /* Check IRQ argument on command line. */
4124 if (dev
->irq
!= 0) {
4125 irq_mask
= wv_irq_to_psa(dev
->irq
);
4127 if (irq_mask
== 0) {
4128 #ifdef DEBUG_CONFIG_ERROR
4130 "%s: wavelan_config(): invalid IRQ %d ignored.\n",
4131 dev
->name
, dev
->irq
);
4135 #ifdef DEBUG_CONFIG_INFO
4137 "%s: wavelan_config(): changing IRQ to %d\n",
4138 dev
->name
, dev
->irq
);
4140 psa_write(ioaddr
, HACR_DEFAULT
,
4141 psaoff(0, psa_int_req_no
), &irq_mask
, 1);
4142 /* update the Wavelan checksum */
4143 update_psa_checksum(dev
, ioaddr
, HACR_DEFAULT
);
4144 wv_hacr_reset(ioaddr
);
4148 psa_read(ioaddr
, HACR_DEFAULT
, psaoff(0, psa_int_req_no
),
4150 if ((irq
= wv_psa_to_irq(irq_mask
)) == -1) {
4151 #ifdef DEBUG_CONFIG_ERROR
4153 "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
4154 dev
->name
, irq_mask
);
4162 dev
->mem_start
= 0x0000;
4163 dev
->mem_end
= 0x0000;
4166 /* Initialize device structures */
4167 memset(dev
->priv
, 0, sizeof(net_local
));
4168 lp
= (net_local
*) dev
->priv
;
4170 /* Back link to the device structure. */
4172 /* Add the device at the beginning of the linked list. */
4173 lp
->next
= wavelan_list
;
4176 lp
->hacr
= HACR_DEFAULT
;
4178 /* Multicast stuff */
4179 lp
->promiscuous
= 0;
4183 spin_lock_init(&lp
->spinlock
);
4185 SET_MODULE_OWNER(dev
);
4186 dev
->open
= wavelan_open
;
4187 dev
->stop
= wavelan_close
;
4188 dev
->hard_start_xmit
= wavelan_packet_xmit
;
4189 dev
->get_stats
= wavelan_get_stats
;
4190 dev
->set_multicast_list
= &wavelan_set_multicast_list
;
4191 dev
->tx_timeout
= &wavelan_watchdog
;
4192 dev
->watchdog_timeo
= WATCHDOG_JIFFIES
;
4193 #ifdef SET_MAC_ADDRESS
4194 dev
->set_mac_address
= &wavelan_set_mac_address
;
4195 #endif /* SET_MAC_ADDRESS */
4197 #ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
4198 dev
->wireless_handlers
= &wavelan_handler_def
;
4199 lp
->wireless_data
.spy_data
= &lp
->spy_data
;
4200 dev
->wireless_data
= &lp
->wireless_data
;
4203 dev
->mtu
= WAVELAN_MTU
;
4205 /* Display nice information. */
4208 #ifdef DEBUG_CALLBACK_TRACE
4209 printk(KERN_DEBUG
"%s: <-wavelan_config()\n", dev
->name
);
4213 release_region(ioaddr
, sizeof(ha_t
));
4217 /*------------------------------------------------------------------*/
4219 * Check for a network adaptor of this type. Return '0' iff one
4220 * exists. There seem to be different interpretations of
4221 * the initial value of dev->base_addr.
4222 * We follow the example in drivers/net/ne.c.
4223 * (called in "Space.c")
4225 struct net_device
* __init
wavelan_probe(int unit
)
4227 struct net_device
*dev
;
4234 if (wv_struct_check() != (char *) NULL
) {
4236 "%s: wavelan_probe(): structure/compiler botch: \"%s\"\n",
4237 dev
->name
, wv_struct_check());
4240 #endif /* STRUCT_CHECK */
4242 dev
= alloc_etherdev(sizeof(net_local
));
4244 return ERR_PTR(-ENOMEM
);
4246 sprintf(dev
->name
, "eth%d", unit
);
4247 netdev_boot_setup_check(dev
);
4248 base_addr
= dev
->base_addr
;
4251 #ifdef DEBUG_CALLBACK_TRACE
4253 "%s: ->wavelan_probe(dev=%p (base_addr=0x%x))\n",
4254 dev
->name
, dev
, (unsigned int) dev
->base_addr
);
4257 /* Don't probe at all. */
4258 if (base_addr
< 0) {
4259 #ifdef DEBUG_CONFIG_ERROR
4261 "%s: wavelan_probe(): invalid base address\n",
4265 } else if (base_addr
> 0x100) { /* Check a single specified location. */
4266 r
= wavelan_config(dev
, base_addr
);
4267 #ifdef DEBUG_CONFIG_INFO
4270 "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
4271 dev
->name
, base_addr
);
4274 #ifdef DEBUG_CALLBACK_TRACE
4275 printk(KERN_DEBUG
"%s: <-wavelan_probe()\n", dev
->name
);
4277 } else { /* Scan all possible addresses of the WaveLAN hardware. */
4278 for (i
= 0; i
< NELS(iobase
); i
++) {
4280 if (wavelan_config(dev
, iobase
[i
]) == 0) {
4281 #ifdef DEBUG_CALLBACK_TRACE
4283 "%s: <-wavelan_probe()\n",
4289 if (i
== NELS(iobase
))
4294 r
= register_netdev(dev
);
4299 release_region(dev
->base_addr
, sizeof(ha_t
));
4300 wavelan_list
= wavelan_list
->next
;
4306 /****************************** MODULE ******************************/
4308 * Module entry point: insertion and removal
4312 /*------------------------------------------------------------------*/
4314 * Insertion of the module
4315 * I'm now quite proud of the multi-device support.
4317 int init_module(void)
4319 int ret
= -EIO
; /* Return error if no cards found */
4322 #ifdef DEBUG_MODULE_TRACE
4323 printk(KERN_DEBUG
"-> init_module()\n");
4326 /* If probing is asked */
4328 #ifdef DEBUG_CONFIG_ERROR
4330 "WaveLAN init_module(): doing device probing (bad !)\n");
4332 "Specify base addresses while loading module to correct the problem\n");
4335 /* Copy the basic set of address to be probed. */
4336 for (i
= 0; i
< NELS(iobase
); i
++)
4341 /* Loop on all possible base addresses. */
4343 while ((io
[++i
] != 0) && (i
< NELS(io
))) {
4344 struct net_device
*dev
= alloc_etherdev(sizeof(net_local
));
4348 strcpy(dev
->name
, name
[i
]); /* Copy name */
4349 dev
->base_addr
= io
[i
];
4352 /* Check if there is something at this base address. */
4353 if (wavelan_config(dev
, io
[i
]) == 0) {
4354 if (register_netdev(dev
) != 0) {
4355 release_region(dev
->base_addr
, sizeof(ha_t
));
4356 wavelan_list
= wavelan_list
->next
;
4365 #ifdef DEBUG_CONFIG_ERROR
4368 "WaveLAN init_module(): no device found\n");
4371 #ifdef DEBUG_MODULE_TRACE
4372 printk(KERN_DEBUG
"<- init_module()\n");
4377 /*------------------------------------------------------------------*/
4379 * Removal of the module
4381 void cleanup_module(void)
4383 #ifdef DEBUG_MODULE_TRACE
4384 printk(KERN_DEBUG
"-> cleanup_module()\n");
4387 /* Loop on all devices and release them. */
4388 while (wavelan_list
) {
4389 struct net_device
*dev
= wavelan_list
->dev
;
4391 #ifdef DEBUG_CONFIG_INFO
4393 "%s: cleanup_module(): removing device at 0x%x\n",
4394 dev
->name
, (unsigned int) dev
);
4396 unregister_netdev(dev
);
4398 release_region(dev
->base_addr
, sizeof(ha_t
));
4399 wavelan_list
= wavelan_list
->next
;
4404 #ifdef DEBUG_MODULE_TRACE
4405 printk(KERN_DEBUG
"<- cleanup_module()\n");
4409 MODULE_LICENSE("GPL");
4412 * This software may only be used and distributed
4413 * according to the terms of the GNU General Public License.
4415 * This software was developed as a component of the
4416 * Linux operating system.
4417 * It is based on other device drivers and information
4418 * either written or supplied by:
4419 * Ajay Bakre (bakre@paul.rutgers.edu),
4420 * Donald Becker (becker@scyld.com),
4421 * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
4422 * Anders Klemets (klemets@it.kth.se),
4423 * Vladimir V. Kolpakov (w@stier.koenig.ru),
4424 * Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
4425 * Pauline Middelink (middelin@polyware.iaf.nl),
4426 * Robert Morris (rtm@das.harvard.edu),
4427 * Jean Tourrilhes (jt@hplb.hpl.hp.com),
4428 * Girish Welling (welling@paul.rutgers.edu),
4430 * Thanks go also to:
4431 * James Ashton (jaa101@syseng.anu.edu.au),
4432 * Alan Cox (alan@redhat.com),
4433 * Allan Creighton (allanc@cs.usyd.edu.au),
4434 * Matthew Geier (matthew@cs.usyd.edu.au),
4435 * Remo di Giovanni (remo@cs.usyd.edu.au),
4436 * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
4437 * Vipul Gupta (vgupta@cs.binghamton.edu),
4438 * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
4439 * Tim Nicholson (tim@cs.usyd.edu.au),
4440 * Ian Parkin (ian@cs.usyd.edu.au),
4441 * John Rosenberg (johnr@cs.usyd.edu.au),
4442 * George Rossi (george@phm.gov.au),
4443 * Arthur Scott (arthur@cs.usyd.edu.au),
4445 * for their assistance and advice.
4447 * Please send bug reports, updates, comments to:
4449 * Bruce Janson Email: bruce@cs.usyd.edu.au
4450 * Basser Department of Computer Science Phone: +61-2-9351-3423
4451 * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838