Btrfs: device_list_add() should not update list when mounted
[linux/fpc-iii.git] / drivers / staging / vt6655 / mac.c
blobaf6876a01ee8f266d60a6dd961c524bccfa176d6
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * File: mac.c
22 * Purpose: MAC routines
24 * Author: Tevin Chen
26 * Date: May 21, 1996
28 * Functions:
29 * MACvReadAllRegs - Read All MAC Registers to buffer
30 * MACbIsRegBitsOn - Test if All test Bits On
31 * MACbIsRegBitsOff - Test if All test Bits Off
32 * MACbIsIntDisable - Test if MAC interrupt disable
33 * MACbyReadMultiAddr - Read Multicast Address Mask Pattern
34 * MACvWriteMultiAddr - Write Multicast Address Mask Pattern
35 * MACvSetMultiAddrByHash - Set Multicast Address Mask by Hash value
36 * MACvResetMultiAddrByHash - Clear Multicast Address Mask by Hash value
37 * MACvSetRxThreshold - Set Rx Threshold value
38 * MACvGetRxThreshold - Get Rx Threshold value
39 * MACvSetTxThreshold - Set Tx Threshold value
40 * MACvGetTxThreshold - Get Tx Threshold value
41 * MACvSetDmaLength - Set Dma Length value
42 * MACvGetDmaLength - Get Dma Length value
43 * MACvSetShortRetryLimit - Set 802.11 Short Retry limit
44 * MACvGetShortRetryLimit - Get 802.11 Short Retry limit
45 * MACvSetLongRetryLimit - Set 802.11 Long Retry limit
46 * MACvGetLongRetryLimit - Get 802.11 Long Retry limit
47 * MACvSetLoopbackMode - Set MAC Loopback Mode
48 * MACbIsInLoopbackMode - Test if MAC in Loopback mode
49 * MACvSetPacketFilter - Set MAC Address Filter
50 * MACvSaveContext - Save Context of MAC Registers
51 * MACvRestoreContext - Restore Context of MAC Registers
52 * MACbCompareContext - Compare if values of MAC Registers same as Context
53 * MACbSoftwareReset - Software Reset MAC
54 * MACbSafeRxOff - Turn Off MAC Rx
55 * MACbSafeTxOff - Turn Off MAC Tx
56 * MACbSafeStop - Stop MAC function
57 * MACbShutdown - Shut down MAC
58 * MACvInitialize - Initialize MAC
59 * MACvSetCurrRxDescAddr - Set Rx Descriptors Address
60 * MACvSetCurrTx0DescAddr - Set Tx0 Descriptors Address
61 * MACvSetCurrTx1DescAddr - Set Tx1 Descriptors Address
62 * MACvTimer0MicroSDelay - Micro Second Delay Loop by MAC
64 * Revision History:
65 * 08-22-2003 Kyle Hsu : Porting MAC functions from sim53
66 * 09-03-2003 Bryan YC Fan : Add MACvClearBusSusInd()& MACvEnableBusSusEn()
67 * 09-18-2003 Jerry Chen : Add MACvSetKeyEntry & MACvDisableKeyEntry
71 #include "tmacro.h"
72 #include "tether.h"
73 #include "mac.h"
75 unsigned short TxRate_iwconfig;//2008-5-8 <add> by chester
76 /*--------------------- Static Definitions -------------------------*/
77 static int msglevel = MSG_LEVEL_INFO;
78 /*--------------------- Static Classes ----------------------------*/
80 /*--------------------- Static Variables --------------------------*/
82 /*--------------------- Static Functions --------------------------*/
84 /*--------------------- Export Variables --------------------------*/
86 /*--------------------- Export Functions --------------------------*/
89 * Description:
90 * Read All MAC Registers to buffer
92 * Parameters:
93 * In:
94 * dwIoBase - Base Address for MAC
95 * Out:
96 * pbyMacRegs - buffer to read
98 * Return Value: none
101 void MACvReadAllRegs(unsigned long dwIoBase, unsigned char *pbyMacRegs)
103 int ii;
105 // read page0 register
106 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
107 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
108 pbyMacRegs++;
111 MACvSelectPage1(dwIoBase);
113 // read page1 register
114 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
115 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
116 pbyMacRegs++;
119 MACvSelectPage0(dwIoBase);
123 * Description:
124 * Test if all test bits on
126 * Parameters:
127 * In:
128 * dwIoBase - Base Address for MAC
129 * byRegOfs - Offset of MAC Register
130 * byTestBits - Test bits
131 * Out:
132 * none
134 * Return Value: true if all test bits On; otherwise false
137 bool MACbIsRegBitsOn(unsigned long dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
139 unsigned char byData;
141 VNSvInPortB(dwIoBase + byRegOfs, &byData);
142 return (byData & byTestBits) == byTestBits;
146 * Description:
147 * Test if all test bits off
149 * Parameters:
150 * In:
151 * dwIoBase - Base Address for MAC
152 * byRegOfs - Offset of MAC Register
153 * byTestBits - Test bits
154 * Out:
155 * none
157 * Return Value: true if all test bits Off; otherwise false
160 bool MACbIsRegBitsOff(unsigned long dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
162 unsigned char byData;
164 VNSvInPortB(dwIoBase + byRegOfs, &byData);
165 return !(byData & byTestBits);
169 * Description:
170 * Test if MAC interrupt disable
172 * Parameters:
173 * In:
174 * dwIoBase - Base Address for MAC
175 * Out:
176 * none
178 * Return Value: true if interrupt is disable; otherwise false
181 bool MACbIsIntDisable(unsigned long dwIoBase)
183 unsigned long dwData;
185 VNSvInPortD(dwIoBase + MAC_REG_IMR, &dwData);
186 if (dwData != 0)
187 return false;
189 return true;
193 * Description:
194 * Read MAC Multicast Address Mask
196 * Parameters:
197 * In:
198 * dwIoBase - Base Address for MAC
199 * uByteidx - Index of Mask
200 * Out:
201 * none
203 * Return Value: Mask Value read
206 unsigned char MACbyReadMultiAddr(unsigned long dwIoBase, unsigned int uByteIdx)
208 unsigned char byData;
210 MACvSelectPage1(dwIoBase);
211 VNSvInPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, &byData);
212 MACvSelectPage0(dwIoBase);
213 return byData;
217 * Description:
218 * Write MAC Multicast Address Mask
220 * Parameters:
221 * In:
222 * dwIoBase - Base Address for MAC
223 * uByteidx - Index of Mask
224 * byData - Mask Value to write
225 * Out:
226 * none
228 * Return Value: none
231 void MACvWriteMultiAddr(unsigned long dwIoBase, unsigned int uByteIdx, unsigned char byData)
233 MACvSelectPage1(dwIoBase);
234 VNSvOutPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, byData);
235 MACvSelectPage0(dwIoBase);
239 * Description:
240 * Set this hash index into multicast address register bit
242 * Parameters:
243 * In:
244 * dwIoBase - Base Address for MAC
245 * byHashIdx - Hash index to set
246 * Out:
247 * none
249 * Return Value: none
252 void MACvSetMultiAddrByHash(unsigned long dwIoBase, unsigned char byHashIdx)
254 unsigned int uByteIdx;
255 unsigned char byBitMask;
256 unsigned char byOrgValue;
258 // calculate byte position
259 uByteIdx = byHashIdx / 8;
260 ASSERT(uByteIdx < 8);
261 // calculate bit position
262 byBitMask = 1;
263 byBitMask <<= (byHashIdx % 8);
264 // turn on the bit
265 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
266 MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue | byBitMask));
270 * Description:
271 * Reset this hash index into multicast address register bit
273 * Parameters:
274 * In:
275 * dwIoBase - Base Address for MAC
276 * byHashIdx - Hash index to clear
277 * Out:
278 * none
280 * Return Value: none
283 void MACvResetMultiAddrByHash(unsigned long dwIoBase, unsigned char byHashIdx)
285 unsigned int uByteIdx;
286 unsigned char byBitMask;
287 unsigned char byOrgValue;
289 // calculate byte position
290 uByteIdx = byHashIdx / 8;
291 ASSERT(uByteIdx < 8);
292 // calculate bit position
293 byBitMask = 1;
294 byBitMask <<= (byHashIdx % 8);
295 // turn off the bit
296 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
297 MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue & (~byBitMask)));
301 * Description:
302 * Set Rx Threshold
304 * Parameters:
305 * In:
306 * dwIoBase - Base Address for MAC
307 * byThreshold - Threshold Value
308 * Out:
309 * none
311 * Return Value: none
314 void MACvSetRxThreshold(unsigned long dwIoBase, unsigned char byThreshold)
316 unsigned char byOrgValue;
318 ASSERT(byThreshold < 4);
320 // set FCR0
321 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
322 byOrgValue = (byOrgValue & 0xCF) | (byThreshold << 4);
323 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
327 * Description:
328 * Get Rx Threshold
330 * Parameters:
331 * In:
332 * dwIoBase - Base Address for MAC
333 * Out:
334 * pbyThreshold- Threshold Value Get
336 * Return Value: none
339 void MACvGetRxThreshold(unsigned long dwIoBase, unsigned char *pbyThreshold)
341 // get FCR0
342 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
343 *pbyThreshold = (*pbyThreshold >> 4) & 0x03;
347 * Description:
348 * Set Tx Threshold
350 * Parameters:
351 * In:
352 * dwIoBase - Base Address for MAC
353 * byThreshold - Threshold Value
354 * Out:
355 * none
357 * Return Value: none
360 void MACvSetTxThreshold(unsigned long dwIoBase, unsigned char byThreshold)
362 unsigned char byOrgValue;
364 ASSERT(byThreshold < 4);
366 // set FCR0
367 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
368 byOrgValue = (byOrgValue & 0xF3) | (byThreshold << 2);
369 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
373 * Description:
374 * Get Tx Threshold
376 * Parameters:
377 * In:
378 * dwIoBase - Base Address for MAC
379 * Out:
380 * pbyThreshold- Threshold Value Get
382 * Return Value: none
385 void MACvGetTxThreshold(unsigned long dwIoBase, unsigned char *pbyThreshold)
387 // get FCR0
388 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
389 *pbyThreshold = (*pbyThreshold >> 2) & 0x03;
393 * Description:
394 * Set Dma Length
396 * Parameters:
397 * In:
398 * dwIoBase - Base Address for MAC
399 * byDmaLength - Dma Length Value
400 * Out:
401 * none
403 * Return Value: none
406 void MACvSetDmaLength(unsigned long dwIoBase, unsigned char byDmaLength)
408 unsigned char byOrgValue;
410 ASSERT(byDmaLength < 4);
412 // set FCR0
413 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
414 byOrgValue = (byOrgValue & 0xFC) | byDmaLength;
415 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
419 * Description:
420 * Get Dma Length
422 * Parameters:
423 * In:
424 * dwIoBase - Base Address for MAC
425 * Out:
426 * pbyDmaLength- Dma Length Value Get
428 * Return Value: none
431 void MACvGetDmaLength(unsigned long dwIoBase, unsigned char *pbyDmaLength)
433 // get FCR0
434 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyDmaLength);
435 *pbyDmaLength &= 0x03;
439 * Description:
440 * Set 802.11 Short Retry Limit
442 * Parameters:
443 * In:
444 * dwIoBase - Base Address for MAC
445 * byRetryLimit- Retry Limit
446 * Out:
447 * none
449 * Return Value: none
452 void MACvSetShortRetryLimit(unsigned long dwIoBase, unsigned char byRetryLimit)
454 // set SRT
455 VNSvOutPortB(dwIoBase + MAC_REG_SRT, byRetryLimit);
459 * Description:
460 * Get 802.11 Short Retry Limit
462 * Parameters:
463 * In:
464 * dwIoBase - Base Address for MAC
465 * Out:
466 * pbyRetryLimit - Retry Limit Get
468 * Return Value: none
471 void MACvGetShortRetryLimit(unsigned long dwIoBase, unsigned char *pbyRetryLimit)
473 // get SRT
474 VNSvInPortB(dwIoBase + MAC_REG_SRT, pbyRetryLimit);
478 * Description:
479 * Set 802.11 Long Retry Limit
481 * Parameters:
482 * In:
483 * dwIoBase - Base Address for MAC
484 * byRetryLimit- Retry Limit
485 * Out:
486 * none
488 * Return Value: none
491 void MACvSetLongRetryLimit(unsigned long dwIoBase, unsigned char byRetryLimit)
493 // set LRT
494 VNSvOutPortB(dwIoBase + MAC_REG_LRT, byRetryLimit);
498 * Description:
499 * Get 802.11 Long Retry Limit
501 * Parameters:
502 * In:
503 * dwIoBase - Base Address for MAC
504 * Out:
505 * pbyRetryLimit - Retry Limit Get
507 * Return Value: none
510 void MACvGetLongRetryLimit(unsigned long dwIoBase, unsigned char *pbyRetryLimit)
512 // get LRT
513 VNSvInPortB(dwIoBase + MAC_REG_LRT, pbyRetryLimit);
517 * Description:
518 * Set MAC Loopback mode
520 * Parameters:
521 * In:
522 * dwIoBase - Base Address for MAC
523 * byLoopbackMode - Loopback Mode
524 * Out:
525 * none
527 * Return Value: none
530 void MACvSetLoopbackMode(unsigned long dwIoBase, unsigned char byLoopbackMode)
532 unsigned char byOrgValue;
534 ASSERT(byLoopbackMode < 3);
535 byLoopbackMode <<= 6;
536 // set TCR
537 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
538 byOrgValue = byOrgValue & 0x3F;
539 byOrgValue = byOrgValue | byLoopbackMode;
540 VNSvOutPortB(dwIoBase + MAC_REG_TEST, byOrgValue);
544 * Description:
545 * Test if MAC in Loopback mode
547 * Parameters:
548 * In:
549 * dwIoBase - Base Address for MAC
550 * Out:
551 * none
553 * Return Value: true if in Loopback mode; otherwise false
556 bool MACbIsInLoopbackMode(unsigned long dwIoBase)
558 unsigned char byOrgValue;
560 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
561 if (byOrgValue & (TEST_LBINT | TEST_LBEXT))
562 return true;
563 return false;
567 * Description:
568 * Set MAC Address filter
570 * Parameters:
571 * In:
572 * dwIoBase - Base Address for MAC
573 * wFilterType - Filter Type
574 * Out:
575 * none
577 * Return Value: none
580 void MACvSetPacketFilter(unsigned long dwIoBase, unsigned short wFilterType)
582 unsigned char byOldRCR;
583 unsigned char byNewRCR = 0;
585 // if only in DIRECTED mode, multicast-address will set to zero,
586 // but if other mode exist (e.g. PROMISCUOUS), multicast-address
587 // will be open
588 if (wFilterType & PKT_TYPE_DIRECTED) {
589 // set multicast address to accept none
590 MACvSelectPage1(dwIoBase);
591 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0L);
592 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0L);
593 MACvSelectPage0(dwIoBase);
596 if (wFilterType & (PKT_TYPE_PROMISCUOUS | PKT_TYPE_ALL_MULTICAST)) {
597 // set multicast address to accept all
598 MACvSelectPage1(dwIoBase);
599 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0xFFFFFFFFL);
600 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0xFFFFFFFFL);
601 MACvSelectPage0(dwIoBase);
604 if (wFilterType & PKT_TYPE_PROMISCUOUS) {
605 byNewRCR |= (RCR_RXALLTYPE | RCR_UNICAST | RCR_MULTICAST | RCR_BROADCAST);
607 byNewRCR &= ~RCR_BSSID;
610 if (wFilterType & (PKT_TYPE_ALL_MULTICAST | PKT_TYPE_MULTICAST))
611 byNewRCR |= RCR_MULTICAST;
613 if (wFilterType & PKT_TYPE_BROADCAST)
614 byNewRCR |= RCR_BROADCAST;
616 if (wFilterType & PKT_TYPE_ERROR_CRC)
617 byNewRCR |= RCR_ERRCRC;
619 VNSvInPortB(dwIoBase + MAC_REG_RCR, &byOldRCR);
620 if (byNewRCR != byOldRCR) {
621 // Modify the Receive Command Register
622 VNSvOutPortB(dwIoBase + MAC_REG_RCR, byNewRCR);
627 * Description:
628 * Save MAC registers to context buffer
630 * Parameters:
631 * In:
632 * dwIoBase - Base Address for MAC
633 * Out:
634 * pbyCxtBuf - Context buffer
636 * Return Value: none
639 void MACvSaveContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
641 int ii;
643 // read page0 register
644 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++)
645 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + ii));
647 MACvSelectPage1(dwIoBase);
649 // read page1 register
650 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++)
651 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
653 MACvSelectPage0(dwIoBase);
657 * Description:
658 * Restore MAC registers from context buffer
660 * Parameters:
661 * In:
662 * dwIoBase - Base Address for MAC
663 * pbyCxtBuf - Context buffer
664 * Out:
665 * none
667 * Return Value: none
670 void MACvRestoreContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
672 int ii;
674 MACvSelectPage1(dwIoBase);
675 // restore page1
676 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++)
677 VNSvOutPortB((dwIoBase + ii), *(pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
679 MACvSelectPage0(dwIoBase);
681 // restore RCR,TCR,IMR...
682 for (ii = MAC_REG_RCR; ii < MAC_REG_ISR; ii++)
683 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
685 // restore MAC Config.
686 for (ii = MAC_REG_LRT; ii < MAC_REG_PAGE1SEL; ii++)
687 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
689 VNSvOutPortB(dwIoBase + MAC_REG_CFG, *(pbyCxtBuf + MAC_REG_CFG));
691 // restore PS Config.
692 for (ii = MAC_REG_PSCFG; ii < MAC_REG_BBREGCTL; ii++)
693 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
695 // restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
696 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0));
697 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR));
698 VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_BCNDMAPTR));
700 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0));
702 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1));
706 * Description:
707 * Compare if MAC registers same as context buffer
709 * Parameters:
710 * In:
711 * dwIoBase - Base Address for MAC
712 * pbyCxtBuf - Context buffer
713 * Out:
714 * none
716 * Return Value: true if all values are the same; otherwise false
719 bool MACbCompareContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
721 unsigned long dwData;
723 // compare MAC context to determine if this is a power lost init,
724 // return true for power remaining init, return false for power lost init
726 // compare CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
727 VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0, &dwData);
728 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0))
729 return false;
731 VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR, &dwData);
732 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR))
733 return false;
735 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0, &dwData);
736 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0))
737 return false;
739 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1, &dwData);
740 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1))
741 return false;
743 return true;
747 * Description:
748 * Software Reset MAC
750 * Parameters:
751 * In:
752 * dwIoBase - Base Address for MAC
753 * Out:
754 * none
756 * Return Value: true if Reset Success; otherwise false
759 bool MACbSoftwareReset(unsigned long dwIoBase)
761 unsigned char byData;
762 unsigned short ww;
764 // turn on HOSTCR_SOFTRST, just write 0x01 to reset
765 VNSvOutPortB(dwIoBase + MAC_REG_HOSTCR, 0x01);
767 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
768 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
769 if (!(byData & HOSTCR_SOFTRST))
770 break;
772 if (ww == W_MAX_TIMEOUT)
773 return false;
774 return true;
778 * Description:
779 * save some important register's value, then do reset, then restore register's value
781 * Parameters:
782 * In:
783 * dwIoBase - Base Address for MAC
784 * Out:
785 * none
787 * Return Value: true if success; otherwise false
790 bool MACbSafeSoftwareReset(unsigned long dwIoBase)
792 unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
793 bool bRetVal;
795 // PATCH....
796 // save some important register's value, then do
797 // reset, then restore register's value
799 // save MAC context
800 MACvSaveContext(dwIoBase, abyTmpRegData);
801 // do reset
802 bRetVal = MACbSoftwareReset(dwIoBase);
803 // restore MAC context, except CR0
804 MACvRestoreContext(dwIoBase, abyTmpRegData);
806 return bRetVal;
810 * Description:
811 * Trun Off MAC Rx
813 * Parameters:
814 * In:
815 * dwIoBase - Base Address for MAC
816 * Out:
817 * none
819 * Return Value: true if success; otherwise false
822 bool MACbSafeRxOff(unsigned long dwIoBase)
824 unsigned short ww;
825 unsigned long dwData;
826 unsigned char byData;
828 // turn off wow temp for turn off Rx safely
830 // Clear RX DMA0,1
831 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
832 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
833 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
834 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);
835 if (!(dwData & DMACTL_RUN))
836 break;
838 if (ww == W_MAX_TIMEOUT) {
839 DBG_PORT80(0x10);
840 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x10)\n");
841 return false;
843 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
844 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);
845 if (!(dwData & DMACTL_RUN))
846 break;
848 if (ww == W_MAX_TIMEOUT) {
849 DBG_PORT80(0x11);
850 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x11)\n");
851 return false;
854 // try to safe shutdown RX
855 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON);
856 // W_MAX_TIMEOUT is the timeout period
857 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
858 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
859 if (!(byData & HOSTCR_RXONST))
860 break;
862 if (ww == W_MAX_TIMEOUT) {
863 DBG_PORT80(0x12);
864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x12)\n");
865 return false;
867 return true;
871 * Description:
872 * Trun Off MAC Tx
874 * Parameters:
875 * In:
876 * dwIoBase - Base Address for MAC
877 * Out:
878 * none
880 * Return Value: true if success; otherwise false
883 bool MACbSafeTxOff(unsigned long dwIoBase)
885 unsigned short ww;
886 unsigned long dwData;
887 unsigned char byData;
889 // Clear TX DMA
890 //Tx0
891 VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
892 //AC0
893 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
895 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
896 VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);
897 if (!(dwData & DMACTL_RUN))
898 break;
900 if (ww == W_MAX_TIMEOUT) {
901 DBG_PORT80(0x20);
902 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x20)\n");
903 return false;
905 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
906 VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);
907 if (!(dwData & DMACTL_RUN))
908 break;
910 if (ww == W_MAX_TIMEOUT) {
911 DBG_PORT80(0x21);
912 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x21)\n");
913 return false;
916 // try to safe shutdown TX
917 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON);
919 // W_MAX_TIMEOUT is the timeout period
920 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
921 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
922 if (!(byData & HOSTCR_TXONST))
923 break;
925 if (ww == W_MAX_TIMEOUT) {
926 DBG_PORT80(0x24);
927 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x24)\n");
928 return false;
930 return true;
934 * Description:
935 * Stop MAC function
937 * Parameters:
938 * In:
939 * dwIoBase - Base Address for MAC
940 * Out:
941 * none
943 * Return Value: true if success; otherwise false
946 bool MACbSafeStop(unsigned long dwIoBase)
948 MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX);
950 if (!MACbSafeRxOff(dwIoBase)) {
951 DBG_PORT80(0xA1);
952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " MACbSafeRxOff == false)\n");
953 MACbSafeSoftwareReset(dwIoBase);
954 return false;
956 if (!MACbSafeTxOff(dwIoBase)) {
957 DBG_PORT80(0xA2);
958 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " MACbSafeTxOff == false)\n");
959 MACbSafeSoftwareReset(dwIoBase);
960 return false;
963 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_MACEN);
965 return true;
969 * Description:
970 * Shut Down MAC
972 * Parameters:
973 * In:
974 * dwIoBase - Base Address for MAC
975 * Out:
976 * none
978 * Return Value: true if success; otherwise false
981 bool MACbShutdown(unsigned long dwIoBase)
983 // disable MAC IMR
984 MACvIntDisable(dwIoBase);
985 MACvSetLoopbackMode(dwIoBase, MAC_LB_INTERNAL);
986 // stop the adapter
987 if (!MACbSafeStop(dwIoBase)) {
988 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
989 return false;
991 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
992 return true;
996 * Description:
997 * Initialize MAC
999 * Parameters:
1000 * In:
1001 * dwIoBase - Base Address for MAC
1002 * Out:
1003 * none
1005 * Return Value: none
1008 void MACvInitialize(unsigned long dwIoBase)
1010 // clear sticky bits
1011 MACvClearStckDS(dwIoBase);
1012 // disable force PME-enable
1013 VNSvOutPortB(dwIoBase + MAC_REG_PMC1, PME_OVR);
1014 // only 3253 A
1016 // do reset
1017 MACbSoftwareReset(dwIoBase);
1019 // reset TSF counter
1020 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1021 // enable TSF counter
1022 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1024 // set packet filter
1025 // receive directed and broadcast address
1027 MACvSetPacketFilter(dwIoBase, PKT_TYPE_DIRECTED | PKT_TYPE_BROADCAST);
1031 * Description:
1032 * Set the chip with current rx descriptor address
1034 * Parameters:
1035 * In:
1036 * dwIoBase - Base Address for MAC
1037 * dwCurrDescAddr - Descriptor Address
1038 * Out:
1039 * none
1041 * Return Value: none
1044 void MACvSetCurrRx0DescAddr(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
1046 unsigned short ww;
1047 unsigned char byData;
1048 unsigned char byOrgDMACtl;
1050 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byOrgDMACtl);
1051 if (byOrgDMACtl & DMACTL_RUN)
1052 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
1054 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1055 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byData);
1056 if (!(byData & DMACTL_RUN))
1057 break;
1060 if (ww == W_MAX_TIMEOUT)
1061 DBG_PORT80(0x13);
1063 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
1064 if (byOrgDMACtl & DMACTL_RUN)
1065 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN);
1069 * Description:
1070 * Set the chip with current rx descriptor address
1072 * Parameters:
1073 * In:
1074 * dwIoBase - Base Address for MAC
1075 * dwCurrDescAddr - Descriptor Address
1076 * Out:
1077 * none
1079 * Return Value: none
1082 void MACvSetCurrRx1DescAddr(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
1084 unsigned short ww;
1085 unsigned char byData;
1086 unsigned char byOrgDMACtl;
1088 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byOrgDMACtl);
1089 if (byOrgDMACtl & DMACTL_RUN)
1090 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
1092 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1093 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byData);
1094 if (!(byData & DMACTL_RUN))
1095 break;
1097 if (ww == W_MAX_TIMEOUT)
1098 DBG_PORT80(0x14);
1100 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
1101 if (byOrgDMACtl & DMACTL_RUN)
1102 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN);
1107 * Description:
1108 * Set the chip with current tx0 descriptor address
1110 * Parameters:
1111 * In:
1112 * dwIoBase - Base Address for MAC
1113 * dwCurrDescAddr - Descriptor Address
1114 * Out:
1115 * none
1117 * Return Value: none
1120 void MACvSetCurrTx0DescAddrEx(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
1122 unsigned short ww;
1123 unsigned char byData;
1124 unsigned char byOrgDMACtl;
1126 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byOrgDMACtl);
1127 if (byOrgDMACtl & DMACTL_RUN)
1128 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1130 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1131 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1132 if (!(byData & DMACTL_RUN))
1133 break;
1135 if (ww == W_MAX_TIMEOUT)
1136 DBG_PORT80(0x25);
1138 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
1139 if (byOrgDMACtl & DMACTL_RUN)
1140 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN);
1144 * Description:
1145 * Set the chip with current AC0 descriptor address
1147 * Parameters:
1148 * In:
1149 * dwIoBase - Base Address for MAC
1150 * dwCurrDescAddr - Descriptor Address
1151 * Out:
1152 * none
1154 * Return Value: none
1157 //TxDMA1 = AC0DMA
1158 void MACvSetCurrAC0DescAddrEx(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
1160 unsigned short ww;
1161 unsigned char byData;
1162 unsigned char byOrgDMACtl;
1164 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byOrgDMACtl);
1165 if (byOrgDMACtl & DMACTL_RUN)
1166 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1168 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1169 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1170 if (!(byData & DMACTL_RUN))
1171 break;
1173 if (ww == W_MAX_TIMEOUT) {
1174 DBG_PORT80(0x26);
1175 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x26)\n");
1177 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
1178 if (byOrgDMACtl & DMACTL_RUN)
1179 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN);
1182 void MACvSetCurrTXDescAddr(int iTxType, unsigned long dwIoBase, unsigned long dwCurrDescAddr)
1184 if (iTxType == TYPE_AC0DMA)
1185 MACvSetCurrAC0DescAddrEx(dwIoBase, dwCurrDescAddr);
1186 else if (iTxType == TYPE_TXDMA0)
1187 MACvSetCurrTx0DescAddrEx(dwIoBase, dwCurrDescAddr);
1191 * Description:
1192 * Micro Second Delay via MAC
1194 * Parameters:
1195 * In:
1196 * dwIoBase - Base Address for MAC
1197 * uDelay - Delay time (timer resolution is 4 us)
1198 * Out:
1199 * none
1201 * Return Value: none
1204 void MACvTimer0MicroSDelay(unsigned long dwIoBase, unsigned int uDelay)
1206 unsigned char byValue;
1207 unsigned int uu, ii;
1209 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1210 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelay);
1211 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
1212 for (ii = 0; ii < 66; ii++) { // assume max PCI clock is 66Mhz
1213 for (uu = 0; uu < uDelay; uu++) {
1214 VNSvInPortB(dwIoBase + MAC_REG_TMCTL0, &byValue);
1215 if ((byValue == 0) ||
1216 (byValue & TMCTL_TSUSP)) {
1217 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1218 return;
1222 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1226 * Description:
1227 * Micro Second One shot timer via MAC
1229 * Parameters:
1230 * In:
1231 * dwIoBase - Base Address for MAC
1232 * uDelay - Delay time
1233 * Out:
1234 * none
1236 * Return Value: none
1239 void MACvOneShotTimer0MicroSec(unsigned long dwIoBase, unsigned int uDelayTime)
1241 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1242 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelayTime);
1243 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
1247 * Description:
1248 * Micro Second One shot timer via MAC
1250 * Parameters:
1251 * In:
1252 * dwIoBase - Base Address for MAC
1253 * uDelay - Delay time
1254 * Out:
1255 * none
1257 * Return Value: none
1260 void MACvOneShotTimer1MicroSec(unsigned long dwIoBase, unsigned int uDelayTime)
1262 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0);
1263 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA1, uDelayTime);
1264 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
1267 void MACvSetMISCFifo(unsigned long dwIoBase, unsigned short wOffset, unsigned long dwData)
1269 if (wOffset > 273)
1270 return;
1271 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1272 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1273 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1276 bool MACbTxDMAOff(unsigned long dwIoBase, unsigned int idx)
1278 unsigned char byData;
1279 unsigned int ww = 0;
1281 if (idx == TYPE_TXDMA0) {
1282 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1283 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1284 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1285 if (!(byData & DMACTL_RUN))
1286 break;
1288 } else if (idx == TYPE_AC0DMA) {
1289 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1290 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1291 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1292 if (!(byData & DMACTL_RUN))
1293 break;
1296 if (ww == W_MAX_TIMEOUT) {
1297 DBG_PORT80(0x29);
1298 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x29)\n");
1299 return false;
1301 return true;
1304 void MACvClearBusSusInd(unsigned long dwIoBase)
1306 unsigned long dwOrgValue;
1307 unsigned int ww;
1308 // check if BcnSusInd enabled
1309 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1310 if (!(dwOrgValue & EnCFG_BcnSusInd))
1311 return;
1312 //Set BcnSusClr
1313 dwOrgValue = dwOrgValue | EnCFG_BcnSusClr;
1314 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);
1315 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1316 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1317 if (!(dwOrgValue & EnCFG_BcnSusInd))
1318 break;
1320 if (ww == W_MAX_TIMEOUT) {
1321 DBG_PORT80(0x33);
1322 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
1326 void MACvEnableBusSusEn(unsigned long dwIoBase)
1328 unsigned char byOrgValue;
1329 unsigned long dwOrgValue;
1330 unsigned int ww;
1331 // check if BcnSusInd enabled
1332 VNSvInPortB(dwIoBase + MAC_REG_CFG , &byOrgValue);
1334 //Set BcnSusEn
1335 byOrgValue = byOrgValue | CFG_BCNSUSEN;
1336 VNSvOutPortB(dwIoBase + MAC_REG_ENCFG, byOrgValue);
1337 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1338 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1339 if (dwOrgValue & EnCFG_BcnSusInd)
1340 break;
1342 if (ww == W_MAX_TIMEOUT) {
1343 DBG_PORT80(0x34);
1344 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x34)\n");
1348 bool MACbFlushSYNCFifo(unsigned long dwIoBase)
1350 unsigned char byOrgValue;
1351 unsigned int ww;
1352 // Read MACCR
1353 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1355 // Set SYNCFLUSH
1356 byOrgValue = byOrgValue | MACCR_SYNCFLUSH;
1357 VNSvOutPortB(dwIoBase + MAC_REG_MACCR, byOrgValue);
1359 // Check if SyncFlushOK
1360 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1361 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1362 if (byOrgValue & MACCR_SYNCFLUSHOK)
1363 break;
1365 if (ww == W_MAX_TIMEOUT) {
1366 DBG_PORT80(0x35);
1367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
1369 return true;
1372 bool MACbPSWakeup(unsigned long dwIoBase)
1374 unsigned char byOrgValue;
1375 unsigned int ww;
1376 // Read PSCTL
1377 if (MACbIsRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PS))
1378 return true;
1380 // Disable PS
1381 MACvRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PSEN);
1383 // Check if SyncFlushOK
1384 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1385 VNSvInPortB(dwIoBase + MAC_REG_PSCTL , &byOrgValue);
1386 if (byOrgValue & PSCTL_WAKEDONE)
1387 break;
1389 if (ww == W_MAX_TIMEOUT) {
1390 DBG_PORT80(0x36);
1391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
1392 return false;
1394 return true;
1398 * Description:
1399 * Set the Key by MISCFIFO
1401 * Parameters:
1402 * In:
1403 * dwIoBase - Base Address for MAC
1405 * Out:
1406 * none
1408 * Return Value: none
1412 void MACvSetKeyEntry(unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx,
1413 unsigned int uKeyIdx, unsigned char *pbyAddr, u32 *pdwKey, unsigned char byLocalID)
1415 unsigned short wOffset;
1416 u32 dwData;
1417 int ii;
1419 if (byLocalID <= 1)
1420 return;
1422 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetKeyEntry\n");
1423 wOffset = MISCFIFO_KEYETRY0;
1424 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1426 dwData = 0;
1427 dwData |= wKeyCtl;
1428 dwData <<= 16;
1429 dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
1430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %X, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
1432 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1433 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1434 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1435 wOffset++;
1437 dwData = 0;
1438 dwData |= *(pbyAddr+3);
1439 dwData <<= 8;
1440 dwData |= *(pbyAddr+2);
1441 dwData <<= 8;
1442 dwData |= *(pbyAddr+1);
1443 dwData <<= 8;
1444 dwData |= *(pbyAddr+0);
1445 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "2. wOffset: %d, Data: %X\n", wOffset, dwData);
1447 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1448 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1449 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1450 wOffset++;
1452 wOffset += (uKeyIdx * 4);
1453 for (ii = 0; ii < 4; ii++) {
1454 // always push 128 bits
1455 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "3.(%d) wOffset: %d, Data: %X\n", ii, wOffset+ii, *pdwKey);
1456 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1457 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1458 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1463 * Description:
1464 * Disable the Key Entry by MISCFIFO
1466 * Parameters:
1467 * In:
1468 * dwIoBase - Base Address for MAC
1470 * Out:
1471 * none
1473 * Return Value: none
1476 void MACvDisableKeyEntry(unsigned long dwIoBase, unsigned int uEntryIdx)
1478 unsigned short wOffset;
1480 wOffset = MISCFIFO_KEYETRY0;
1481 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1483 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1484 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
1485 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1489 * Description:
1490 * Set the default Key (KeyEntry[10]) by MISCFIFO
1492 * Parameters:
1493 * In:
1494 * dwIoBase - Base Address for MAC
1496 * Out:
1497 * none
1499 * Return Value: none
1503 void MACvSetDefaultKeyEntry(unsigned long dwIoBase, unsigned int uKeyLen,
1504 unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
1506 unsigned short wOffset;
1507 unsigned long dwData;
1508 int ii;
1510 if (byLocalID <= 1)
1511 return;
1513 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetDefaultKeyEntry\n");
1514 wOffset = MISCFIFO_KEYETRY0;
1515 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1517 wOffset++;
1518 wOffset++;
1519 wOffset += (uKeyIdx * 4);
1520 // always push 128 bits
1521 for (ii = 0; ii < 3; ii++) {
1522 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1523 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1524 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1525 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1527 dwData = *pdwKey;
1528 if (uKeyLen == WLAN_WEP104_KEYLEN)
1529 dwData |= 0x80000000;
1531 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+3);
1532 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1533 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1534 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "End. wOffset: %d, Data: %lX\n", wOffset+3, dwData);
1538 * Description:
1539 * Enable default Key (KeyEntry[10]) by MISCFIFO
1541 * Parameters:
1542 * In:
1543 * dwIoBase - Base Address for MAC
1545 * Out:
1546 * none
1548 * Return Value: none
1552 void MACvEnableDefaultKey(unsigned long dwIoBase, unsigned char byLocalID)
1554 unsigned short wOffset;
1555 unsigned long dwData;
1557 if (byLocalID <= 1)
1558 return;
1560 wOffset = MISCFIFO_KEYETRY0;
1561 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1563 dwData = 0xC0440000;
1564 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1565 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1566 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvEnableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
1573 * Description:
1574 * Disable default Key (KeyEntry[10]) by MISCFIFO
1576 * Parameters:
1577 * In:
1578 * dwIoBase - Base Address for MAC
1580 * Out:
1581 * none
1583 * Return Value: none
1586 void MACvDisableDefaultKey(unsigned long dwIoBase)
1588 unsigned short wOffset;
1589 unsigned long dwData;
1591 wOffset = MISCFIFO_KEYETRY0;
1592 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1594 dwData = 0x0;
1595 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1596 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1597 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvDisableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
1602 * Description:
1603 * Set the default TKIP Group Key (KeyEntry[10]) by MISCFIFO
1605 * Parameters:
1606 * In:
1607 * dwIoBase - Base Address for MAC
1609 * Out:
1610 * none
1612 * Return Value: none
1615 void MACvSetDefaultTKIPKeyEntry(unsigned long dwIoBase, unsigned int uKeyLen,
1616 unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
1618 unsigned short wOffset;
1619 unsigned long dwData;
1620 int ii;
1622 if (byLocalID <= 1)
1623 return;
1625 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetDefaultTKIPKeyEntry\n");
1626 wOffset = MISCFIFO_KEYETRY0;
1627 // Kyle test : change offset from 10 -> 0
1628 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1630 dwData = 0xC0660000;
1631 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1632 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1633 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1634 wOffset++;
1636 dwData = 0;
1637 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1638 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1639 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1640 wOffset++;
1642 wOffset += (uKeyIdx * 4);
1643 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %lX, idx:%d\n", wOffset, *pdwKey, uKeyIdx);
1644 // always push 128 bits
1645 for (ii = 0; ii < 4; ii++) {
1646 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "2.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1647 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1648 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1649 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1654 * Description:
1655 * Set the Key Control by MISCFIFO
1657 * Parameters:
1658 * In:
1659 * dwIoBase - Base Address for MAC
1661 * Out:
1662 * none
1664 * Return Value: none
1668 void MACvSetDefaultKeyCtl(unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx, unsigned char byLocalID)
1670 unsigned short wOffset;
1671 unsigned long dwData;
1673 if (byLocalID <= 1)
1674 return;
1676 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetKeyEntry\n");
1677 wOffset = MISCFIFO_KEYETRY0;
1678 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1680 dwData = 0;
1681 dwData |= wKeyCtl;
1682 dwData <<= 16;
1683 dwData |= 0xffff;
1684 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
1686 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1687 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1688 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);