[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / staging / vt6655 / mac.c
blobcdd7cd5e409523321847ed355d0e66b4d0479544
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 Descriptos Address
60 * MACvSetCurrTx0DescAddr - Set Tx0 Descriptos Address
61 * MACvSetCurrTx1DescAddr - Set Tx1 Descriptos 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 WORD TxRate_iwconfig;//2008-5-8 <add> by chester
76 /*--------------------- Static Definitions -------------------------*/
77 //static int msglevel =MSG_LEVEL_DEBUG;
78 static int msglevel =MSG_LEVEL_INFO;
79 /*--------------------- Static Classes ----------------------------*/
81 /*--------------------- Static Variables --------------------------*/
83 /*--------------------- Static Functions --------------------------*/
85 /*--------------------- Export Variables --------------------------*/
87 /*--------------------- Export Functions --------------------------*/
94 * Description:
95 * Read All MAC Registers to buffer
97 * Parameters:
98 * In:
99 * dwIoBase - Base Address for MAC
100 * Out:
101 * pbyMacRegs - buffer to read
103 * Return Value: none
106 VOID MACvReadAllRegs (DWORD_PTR dwIoBase, PBYTE pbyMacRegs)
108 int ii;
110 // read page0 register
111 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
112 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
113 pbyMacRegs++;
116 MACvSelectPage1(dwIoBase);
118 // read page1 register
119 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
120 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
121 pbyMacRegs++;
124 MACvSelectPage0(dwIoBase);
129 * Description:
130 * Test if all test bits on
132 * Parameters:
133 * In:
134 * dwIoBase - Base Address for MAC
135 * byRegOfs - Offset of MAC Register
136 * byTestBits - Test bits
137 * Out:
138 * none
140 * Return Value: TRUE if all test bits On; otherwise FALSE
143 BOOL MACbIsRegBitsOn (DWORD_PTR dwIoBase, BYTE byRegOfs, BYTE byTestBits)
145 BYTE byData;
147 VNSvInPortB(dwIoBase + byRegOfs, &byData);
148 return (byData & byTestBits) == byTestBits;
152 * Description:
153 * Test if all test bits off
155 * Parameters:
156 * In:
157 * dwIoBase - Base Address for MAC
158 * byRegOfs - Offset of MAC Register
159 * byTestBits - Test bits
160 * Out:
161 * none
163 * Return Value: TRUE if all test bits Off; otherwise FALSE
166 BOOL MACbIsRegBitsOff (DWORD_PTR dwIoBase, BYTE byRegOfs, BYTE byTestBits)
168 BYTE byData;
170 VNSvInPortB(dwIoBase + byRegOfs, &byData);
171 return !(byData & byTestBits);
175 * Description:
176 * Test if MAC interrupt disable
178 * Parameters:
179 * In:
180 * dwIoBase - Base Address for MAC
181 * Out:
182 * none
184 * Return Value: TRUE if interrupt is disable; otherwise FALSE
187 BOOL MACbIsIntDisable (DWORD_PTR dwIoBase)
189 DWORD dwData;
191 VNSvInPortD(dwIoBase + MAC_REG_IMR, &dwData);
192 if (dwData != 0)
193 return FALSE;
195 return TRUE;
199 * Description:
200 * Read MAC Multicast Address Mask
202 * Parameters:
203 * In:
204 * dwIoBase - Base Address for MAC
205 * uByteidx - Index of Mask
206 * Out:
207 * none
209 * Return Value: Mask Value read
212 BYTE MACbyReadMultiAddr (DWORD_PTR dwIoBase, UINT uByteIdx)
214 BYTE byData;
216 MACvSelectPage1(dwIoBase);
217 VNSvInPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, &byData);
218 MACvSelectPage0(dwIoBase);
219 return byData;
223 * Description:
224 * Write MAC Multicast Address Mask
226 * Parameters:
227 * In:
228 * dwIoBase - Base Address for MAC
229 * uByteidx - Index of Mask
230 * byData - Mask Value to write
231 * Out:
232 * none
234 * Return Value: none
237 VOID MACvWriteMultiAddr (DWORD_PTR dwIoBase, UINT uByteIdx, BYTE byData)
239 MACvSelectPage1(dwIoBase);
240 VNSvOutPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, byData);
241 MACvSelectPage0(dwIoBase);
245 * Description:
246 * Set this hash index into multicast address register bit
248 * Parameters:
249 * In:
250 * dwIoBase - Base Address for MAC
251 * byHashIdx - Hash index to set
252 * Out:
253 * none
255 * Return Value: none
258 void MACvSetMultiAddrByHash (DWORD_PTR dwIoBase, BYTE byHashIdx)
260 UINT uByteIdx;
261 BYTE byBitMask;
262 BYTE byOrgValue;
264 // calculate byte position
265 uByteIdx = byHashIdx / 8;
266 ASSERT(uByteIdx < 8);
267 // calculate bit position
268 byBitMask = 1;
269 byBitMask <<= (byHashIdx % 8);
270 // turn on the bit
271 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
272 MACvWriteMultiAddr(dwIoBase, uByteIdx, (BYTE)(byOrgValue | byBitMask));
276 * Description:
277 * Reset this hash index into multicast address register bit
279 * Parameters:
280 * In:
281 * dwIoBase - Base Address for MAC
282 * byHashIdx - Hash index to clear
283 * Out:
284 * none
286 * Return Value: none
289 void MACvResetMultiAddrByHash (DWORD_PTR dwIoBase, BYTE byHashIdx)
291 UINT uByteIdx;
292 BYTE byBitMask;
293 BYTE byOrgValue;
295 // calculate byte position
296 uByteIdx = byHashIdx / 8;
297 ASSERT(uByteIdx < 8);
298 // calculate bit position
299 byBitMask = 1;
300 byBitMask <<= (byHashIdx % 8);
301 // turn off the bit
302 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
303 MACvWriteMultiAddr(dwIoBase, uByteIdx, (BYTE)(byOrgValue & (~byBitMask)));
307 * Description:
308 * Set Rx Threshold
310 * Parameters:
311 * In:
312 * dwIoBase - Base Address for MAC
313 * byThreshold - Threshold Value
314 * Out:
315 * none
317 * Return Value: none
320 void MACvSetRxThreshold (DWORD_PTR dwIoBase, BYTE byThreshold)
322 BYTE byOrgValue;
324 ASSERT(byThreshold < 4);
326 // set FCR0
327 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
328 byOrgValue = (byOrgValue & 0xCF) | (byThreshold << 4);
329 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
333 * Description:
334 * Get Rx Threshold
336 * Parameters:
337 * In:
338 * dwIoBase - Base Address for MAC
339 * Out:
340 * pbyThreshold- Threshold Value Get
342 * Return Value: none
345 void MACvGetRxThreshold (DWORD_PTR dwIoBase, PBYTE pbyThreshold)
347 // get FCR0
348 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
349 *pbyThreshold = (*pbyThreshold >> 4) & 0x03;
353 * Description:
354 * Set Tx Threshold
356 * Parameters:
357 * In:
358 * dwIoBase - Base Address for MAC
359 * byThreshold - Threshold Value
360 * Out:
361 * none
363 * Return Value: none
366 void MACvSetTxThreshold (DWORD_PTR dwIoBase, BYTE byThreshold)
368 BYTE byOrgValue;
370 ASSERT(byThreshold < 4);
372 // set FCR0
373 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
374 byOrgValue = (byOrgValue & 0xF3) | (byThreshold << 2);
375 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
379 * Description:
380 * Get Tx Threshold
382 * Parameters:
383 * In:
384 * dwIoBase - Base Address for MAC
385 * Out:
386 * pbyThreshold- Threshold Value Get
388 * Return Value: none
391 void MACvGetTxThreshold (DWORD_PTR dwIoBase, PBYTE pbyThreshold)
393 // get FCR0
394 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
395 *pbyThreshold = (*pbyThreshold >> 2) & 0x03;
399 * Description:
400 * Set Dma Length
402 * Parameters:
403 * In:
404 * dwIoBase - Base Address for MAC
405 * byDmaLength - Dma Length Value
406 * Out:
407 * none
409 * Return Value: none
412 void MACvSetDmaLength (DWORD_PTR dwIoBase, BYTE byDmaLength)
414 BYTE byOrgValue;
416 ASSERT(byDmaLength < 4);
418 // set FCR0
419 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
420 byOrgValue = (byOrgValue & 0xFC) | byDmaLength;
421 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
425 * Description:
426 * Get Dma Length
428 * Parameters:
429 * In:
430 * dwIoBase - Base Address for MAC
431 * Out:
432 * pbyDmaLength- Dma Length Value Get
434 * Return Value: none
437 void MACvGetDmaLength (DWORD_PTR dwIoBase, PBYTE pbyDmaLength)
439 // get FCR0
440 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyDmaLength);
441 *pbyDmaLength &= 0x03;
445 * Description:
446 * Set 802.11 Short Retry Limit
448 * Parameters:
449 * In:
450 * dwIoBase - Base Address for MAC
451 * byRetryLimit- Retry Limit
452 * Out:
453 * none
455 * Return Value: none
458 void MACvSetShortRetryLimit (DWORD_PTR dwIoBase, BYTE byRetryLimit)
460 // set SRT
461 VNSvOutPortB(dwIoBase + MAC_REG_SRT, byRetryLimit);
465 * Description:
466 * Get 802.11 Short Retry Limit
468 * Parameters:
469 * In:
470 * dwIoBase - Base Address for MAC
471 * Out:
472 * pbyRetryLimit - Retry Limit Get
474 * Return Value: none
477 void MACvGetShortRetryLimit (DWORD_PTR dwIoBase, PBYTE pbyRetryLimit)
479 // get SRT
480 VNSvInPortB(dwIoBase + MAC_REG_SRT, pbyRetryLimit);
484 * Description:
485 * Set 802.11 Long Retry Limit
487 * Parameters:
488 * In:
489 * dwIoBase - Base Address for MAC
490 * byRetryLimit- Retry Limit
491 * Out:
492 * none
494 * Return Value: none
497 void MACvSetLongRetryLimit (DWORD_PTR dwIoBase, BYTE byRetryLimit)
499 // set LRT
500 VNSvOutPortB(dwIoBase + MAC_REG_LRT, byRetryLimit);
504 * Description:
505 * Get 802.11 Long Retry Limit
507 * Parameters:
508 * In:
509 * dwIoBase - Base Address for MAC
510 * Out:
511 * pbyRetryLimit - Retry Limit Get
513 * Return Value: none
516 void MACvGetLongRetryLimit (DWORD_PTR dwIoBase, PBYTE pbyRetryLimit)
518 // get LRT
519 VNSvInPortB(dwIoBase + MAC_REG_LRT, pbyRetryLimit);
523 * Description:
524 * Set MAC Loopback mode
526 * Parameters:
527 * In:
528 * dwIoBase - Base Address for MAC
529 * byLoopbackMode - Loopback Mode
530 * Out:
531 * none
533 * Return Value: none
536 void MACvSetLoopbackMode (DWORD_PTR dwIoBase, BYTE byLoopbackMode)
538 BYTE byOrgValue;
540 ASSERT(byLoopbackMode < 3);
541 byLoopbackMode <<= 6;
542 // set TCR
543 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
544 byOrgValue = byOrgValue & 0x3F;
545 byOrgValue = byOrgValue | byLoopbackMode;
546 VNSvOutPortB(dwIoBase + MAC_REG_TEST, byOrgValue);
550 * Description:
551 * Test if MAC in Loopback mode
553 * Parameters:
554 * In:
555 * dwIoBase - Base Address for MAC
556 * Out:
557 * none
559 * Return Value: TRUE if in Loopback mode; otherwise FALSE
562 BOOL MACbIsInLoopbackMode (DWORD_PTR dwIoBase)
564 BYTE byOrgValue;
566 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
567 if (byOrgValue & (TEST_LBINT | TEST_LBEXT))
568 return TRUE;
569 return FALSE;
573 * Description:
574 * Set MAC Address filter
576 * Parameters:
577 * In:
578 * dwIoBase - Base Address for MAC
579 * wFilterType - Filter Type
580 * Out:
581 * none
583 * Return Value: none
586 void MACvSetPacketFilter (DWORD_PTR dwIoBase, WORD wFilterType)
588 BYTE byOldRCR;
589 BYTE byNewRCR = 0;
591 // if only in DIRECTED mode, multicast-address will set to zero,
592 // but if other mode exist (e.g. PROMISCUOUS), multicast-address
593 // will be open
594 if (wFilterType & PKT_TYPE_DIRECTED) {
595 // set multicast address to accept none
596 MACvSelectPage1(dwIoBase);
597 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0L);
598 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(DWORD), 0L);
599 MACvSelectPage0(dwIoBase);
602 if (wFilterType & (PKT_TYPE_PROMISCUOUS | PKT_TYPE_ALL_MULTICAST)) {
603 // set multicast address to accept all
604 MACvSelectPage1(dwIoBase);
605 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0xFFFFFFFFL);
606 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(DWORD), 0xFFFFFFFFL);
607 MACvSelectPage0(dwIoBase);
610 if (wFilterType & PKT_TYPE_PROMISCUOUS) {
612 byNewRCR |= (RCR_RXALLTYPE | RCR_UNICAST | RCR_MULTICAST | RCR_BROADCAST);
614 byNewRCR &= ~RCR_BSSID;
617 if (wFilterType & (PKT_TYPE_ALL_MULTICAST | PKT_TYPE_MULTICAST))
618 byNewRCR |= RCR_MULTICAST;
620 if (wFilterType & PKT_TYPE_BROADCAST)
621 byNewRCR |= RCR_BROADCAST;
623 if (wFilterType & PKT_TYPE_ERROR_CRC)
624 byNewRCR |= RCR_ERRCRC;
626 VNSvInPortB(dwIoBase + MAC_REG_RCR, &byOldRCR);
627 if (byNewRCR != byOldRCR) {
628 // Modify the Receive Command Register
629 VNSvOutPortB(dwIoBase + MAC_REG_RCR, byNewRCR);
634 * Description:
635 * Save MAC registers to context buffer
637 * Parameters:
638 * In:
639 * dwIoBase - Base Address for MAC
640 * Out:
641 * pbyCxtBuf - Context buffer
643 * Return Value: none
646 void MACvSaveContext (DWORD_PTR dwIoBase, PBYTE pbyCxtBuf)
648 int ii;
650 // read page0 register
651 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
652 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + ii));
655 MACvSelectPage1(dwIoBase);
657 // read page1 register
658 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
659 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
662 MACvSelectPage0(dwIoBase);
666 * Description:
667 * Restore MAC registers from context buffer
669 * Parameters:
670 * In:
671 * dwIoBase - Base Address for MAC
672 * pbyCxtBuf - Context buffer
673 * Out:
674 * none
676 * Return Value: none
679 VOID MACvRestoreContext (DWORD_PTR dwIoBase, PBYTE pbyCxtBuf)
681 int ii;
683 MACvSelectPage1(dwIoBase);
684 // restore page1
685 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
686 VNSvOutPortB((dwIoBase + ii), *(pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
688 MACvSelectPage0(dwIoBase);
690 // restore RCR,TCR,IMR...
691 for (ii = MAC_REG_RCR; ii < MAC_REG_ISR; ii++) {
692 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
694 // restore MAC Config.
695 for (ii = MAC_REG_LRT; ii < MAC_REG_PAGE1SEL; ii++) {
696 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
698 VNSvOutPortB(dwIoBase + MAC_REG_CFG, *(pbyCxtBuf + MAC_REG_CFG));
700 // restore PS Config.
701 for (ii = MAC_REG_PSCFG; ii < MAC_REG_BBREGCTL; ii++) {
702 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
705 // restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
706 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, *(PDWORD)(pbyCxtBuf + MAC_REG_TXDMAPTR0));
707 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, *(PDWORD)(pbyCxtBuf + MAC_REG_AC0DMAPTR));
708 VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR, *(PDWORD)(pbyCxtBuf + MAC_REG_BCNDMAPTR));
711 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, *(PDWORD)(pbyCxtBuf + MAC_REG_RXDMAPTR0));
713 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, *(PDWORD)(pbyCxtBuf + MAC_REG_RXDMAPTR1));
718 * Description:
719 * Compare if MAC registers same as context buffer
721 * Parameters:
722 * In:
723 * dwIoBase - Base Address for MAC
724 * pbyCxtBuf - Context buffer
725 * Out:
726 * none
728 * Return Value: TRUE if all values are the same; otherwise FALSE
731 BOOL MACbCompareContext (DWORD_PTR dwIoBase, PBYTE pbyCxtBuf)
733 DWORD dwData;
735 // compare MAC context to determine if this is a power lost init,
736 // return TRUE for power remaining init, return FALSE for power lost init
738 // compare CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
739 VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0, &dwData);
740 if (dwData != *(PDWORD)(pbyCxtBuf + MAC_REG_TXDMAPTR0)) {
741 return FALSE;
744 VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR, &dwData);
745 if (dwData != *(PDWORD)(pbyCxtBuf + MAC_REG_AC0DMAPTR)) {
746 return FALSE;
749 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0, &dwData);
750 if (dwData != *(PDWORD)(pbyCxtBuf + MAC_REG_RXDMAPTR0)) {
751 return FALSE;
754 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1, &dwData);
755 if (dwData != *(PDWORD)(pbyCxtBuf + MAC_REG_RXDMAPTR1)) {
756 return FALSE;
760 return TRUE;
764 * Description:
765 * Software Reset MAC
767 * Parameters:
768 * In:
769 * dwIoBase - Base Address for MAC
770 * Out:
771 * none
773 * Return Value: TRUE if Reset Success; otherwise FALSE
776 BOOL MACbSoftwareReset (DWORD_PTR dwIoBase)
778 BYTE byData;
779 WORD ww;
781 // turn on HOSTCR_SOFTRST, just write 0x01 to reset
782 //MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_SOFTRST);
783 VNSvOutPortB(dwIoBase+ MAC_REG_HOSTCR, 0x01);
785 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
786 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
787 if ( !(byData & HOSTCR_SOFTRST))
788 break;
790 if (ww == W_MAX_TIMEOUT)
791 return FALSE;
792 return TRUE;
797 * Description:
798 * save some important register's value, then do reset, then restore register's value
800 * Parameters:
801 * In:
802 * dwIoBase - Base Address for MAC
803 * Out:
804 * none
806 * Return Value: TRUE if success; otherwise FALSE
809 BOOL MACbSafeSoftwareReset (DWORD_PTR dwIoBase)
811 BYTE abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
812 BOOL bRetVal;
814 // PATCH....
815 // save some important register's value, then do
816 // reset, then restore register's value
818 // save MAC context
819 MACvSaveContext(dwIoBase, abyTmpRegData);
820 // do reset
821 bRetVal = MACbSoftwareReset(dwIoBase);
822 //BBvSoftwareReset(pDevice->PortOffset);
823 // restore MAC context, except CR0
824 MACvRestoreContext(dwIoBase, abyTmpRegData);
826 return bRetVal;
830 * Description:
831 * Trun Off MAC Rx
833 * Parameters:
834 * In:
835 * dwIoBase - Base Address for MAC
836 * Out:
837 * none
839 * Return Value: TRUE if success; otherwise FALSE
842 BOOL MACbSafeRxOff (DWORD_PTR dwIoBase)
844 WORD ww;
845 DWORD dwData;
846 BYTE byData;
848 // turn off wow temp for turn off Rx safely
850 // Clear RX DMA0,1
851 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
852 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
853 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
854 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);
855 if (!(dwData & DMACTL_RUN))
856 break;
858 if (ww == W_MAX_TIMEOUT) {
859 DBG_PORT80(0x10);
860 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x10)\n");
861 return(FALSE);
863 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
864 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);
865 if ( !(dwData & DMACTL_RUN))
866 break;
868 if (ww == W_MAX_TIMEOUT) {
869 DBG_PORT80(0x11);
870 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x11)\n");
871 return(FALSE);
874 // try to safe shutdown RX
875 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON);
876 // W_MAX_TIMEOUT is the timeout period
877 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
878 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
879 if ( !(byData & HOSTCR_RXONST))
880 break;
882 if (ww == W_MAX_TIMEOUT) {
883 DBG_PORT80(0x12);
884 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x12)\n");
885 return(FALSE);
887 return TRUE;
891 * Description:
892 * Trun Off MAC Tx
894 * Parameters:
895 * In:
896 * dwIoBase - Base Address for MAC
897 * Out:
898 * none
900 * Return Value: TRUE if success; otherwise FALSE
903 BOOL MACbSafeTxOff (DWORD_PTR dwIoBase)
905 WORD ww;
906 DWORD dwData;
907 BYTE byData;
909 // Clear TX DMA
910 //Tx0
911 VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
912 //AC0
913 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
916 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
917 VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);
918 if ( !(dwData & DMACTL_RUN))
919 break;
921 if (ww == W_MAX_TIMEOUT) {
922 DBG_PORT80(0x20);
923 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x20)\n");
924 return(FALSE);
926 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
927 VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);
928 if ( !(dwData & DMACTL_RUN))
929 break;
931 if (ww == W_MAX_TIMEOUT) {
932 DBG_PORT80(0x21);
933 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x21)\n");
934 return(FALSE);
937 // try to safe shutdown TX
938 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON);
940 // W_MAX_TIMEOUT is the timeout period
941 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
942 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
943 if ( !(byData & HOSTCR_TXONST))
944 break;
946 if (ww == W_MAX_TIMEOUT) {
947 DBG_PORT80(0x24);
948 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x24)\n");
949 return(FALSE);
951 return TRUE;
955 * Description:
956 * Stop MAC function
958 * Parameters:
959 * In:
960 * dwIoBase - Base Address for MAC
961 * Out:
962 * none
964 * Return Value: TRUE if success; otherwise FALSE
967 BOOL MACbSafeStop (DWORD_PTR dwIoBase)
969 MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX);
971 if (MACbSafeRxOff(dwIoBase) == FALSE) {
972 DBG_PORT80(0xA1);
973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" MACbSafeRxOff == FALSE)\n");
974 MACbSafeSoftwareReset(dwIoBase);
975 return FALSE;
977 if (MACbSafeTxOff(dwIoBase) == FALSE) {
978 DBG_PORT80(0xA2);
979 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" MACbSafeTxOff == FALSE)\n");
980 MACbSafeSoftwareReset(dwIoBase);
981 return FALSE;
984 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_MACEN);
986 return TRUE;
990 * Description:
991 * Shut Down MAC
993 * Parameters:
994 * In:
995 * dwIoBase - Base Address for MAC
996 * Out:
997 * none
999 * Return Value: TRUE if success; otherwise FALSE
1002 BOOL MACbShutdown (DWORD_PTR dwIoBase)
1004 // disable MAC IMR
1005 MACvIntDisable(dwIoBase);
1006 MACvSetLoopbackMode(dwIoBase, MAC_LB_INTERNAL);
1007 // stop the adapter
1008 if (!MACbSafeStop(dwIoBase)) {
1009 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
1010 return FALSE;
1012 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
1013 return TRUE;
1017 * Description:
1018 * Initialize MAC
1020 * Parameters:
1021 * In:
1022 * dwIoBase - Base Address for MAC
1023 * Out:
1024 * none
1026 * Return Value: none
1029 void MACvInitialize (DWORD_PTR dwIoBase)
1031 // clear sticky bits
1032 MACvClearStckDS(dwIoBase);
1033 // disable force PME-enable
1034 VNSvOutPortB(dwIoBase + MAC_REG_PMC1, PME_OVR);
1035 // only 3253 A
1037 MACvPwrEvntDisable(dwIoBase);
1038 // clear power status
1039 VNSvOutPortW(dwIoBase + MAC_REG_WAKEUPSR0, 0x0F0F);
1042 // do reset
1043 MACbSoftwareReset(dwIoBase);
1045 // issue AUTOLD in EECSR to reload eeprom
1046 //MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
1047 // wait until EEPROM loading complete
1048 //while (TRUE) {
1049 // U8 u8Data;
1050 // VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &u8Data);
1051 // if ( !(u8Data & I2MCSR_AUTOLD))
1052 // break;
1055 // reset TSF counter
1056 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1057 // enable TSF counter
1058 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1061 // set packet filter
1062 // receive directed and broadcast address
1064 MACvSetPacketFilter(dwIoBase, PKT_TYPE_DIRECTED | PKT_TYPE_BROADCAST);
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 MACvSetCurrRx0DescAddr (DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1084 WORD ww;
1085 BYTE byData;
1086 BYTE byOrgDMACtl;
1088 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byOrgDMACtl);
1089 if (byOrgDMACtl & DMACTL_RUN) {
1090 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
1092 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1093 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byData);
1094 if ( !(byData & DMACTL_RUN))
1095 break;
1097 if (ww == W_MAX_TIMEOUT) {
1098 DBG_PORT80(0x13);
1100 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
1101 if (byOrgDMACtl & DMACTL_RUN) {
1102 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN);
1107 * Description:
1108 * Set the chip with current rx 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 MACvSetCurrRx1DescAddr (DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1122 WORD ww;
1123 BYTE byData;
1124 BYTE byOrgDMACtl;
1126 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byOrgDMACtl);
1127 if (byOrgDMACtl & DMACTL_RUN) {
1128 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
1130 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1131 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byData);
1132 if ( !(byData & DMACTL_RUN))
1133 break;
1135 if (ww == W_MAX_TIMEOUT) {
1136 DBG_PORT80(0x14);
1138 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
1139 if (byOrgDMACtl & DMACTL_RUN) {
1140 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN);
1145 * Description:
1146 * Set the chip with current tx0 descriptor address
1148 * Parameters:
1149 * In:
1150 * dwIoBase - Base Address for MAC
1151 * dwCurrDescAddr - Descriptor Address
1152 * Out:
1153 * none
1155 * Return Value: none
1158 void MACvSetCurrTx0DescAddrEx (DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1160 WORD ww;
1161 BYTE byData;
1162 BYTE byOrgDMACtl;
1164 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byOrgDMACtl);
1165 if (byOrgDMACtl & DMACTL_RUN) {
1166 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1168 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1169 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1170 if ( !(byData & DMACTL_RUN))
1171 break;
1173 if (ww == W_MAX_TIMEOUT) {
1174 DBG_PORT80(0x25);
1176 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
1177 if (byOrgDMACtl & DMACTL_RUN) {
1178 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN);
1183 * Description:
1184 * Set the chip with current AC0 descriptor address
1186 * Parameters:
1187 * In:
1188 * dwIoBase - Base Address for MAC
1189 * dwCurrDescAddr - Descriptor Address
1190 * Out:
1191 * none
1193 * Return Value: none
1196 //TxDMA1 = AC0DMA
1197 void MACvSetCurrAC0DescAddrEx (DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1199 WORD ww;
1200 BYTE byData;
1201 BYTE byOrgDMACtl;
1203 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byOrgDMACtl);
1204 if (byOrgDMACtl & DMACTL_RUN) {
1205 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1207 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1208 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1209 if (!(byData & DMACTL_RUN))
1210 break;
1212 if (ww == W_MAX_TIMEOUT) {
1213 DBG_PORT80(0x26);
1214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x26)\n");
1216 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
1217 if (byOrgDMACtl & DMACTL_RUN) {
1218 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN);
1224 void MACvSetCurrTXDescAddr (int iTxType, DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1226 if(iTxType == TYPE_AC0DMA){
1227 MACvSetCurrAC0DescAddrEx(dwIoBase, dwCurrDescAddr);
1228 }else if(iTxType == TYPE_TXDMA0){
1229 MACvSetCurrTx0DescAddrEx(dwIoBase, dwCurrDescAddr);
1234 * Description:
1235 * Micro Second Delay via MAC
1237 * Parameters:
1238 * In:
1239 * dwIoBase - Base Address for MAC
1240 * uDelay - Delay time (timer resolution is 4 us)
1241 * Out:
1242 * none
1244 * Return Value: none
1247 VOID MACvTimer0MicroSDelay (DWORD_PTR dwIoBase, UINT uDelay)
1249 BYTE byValue;
1250 UINT uu,ii;
1252 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1253 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelay);
1254 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
1255 for(ii=0;ii<66;ii++) { // assume max PCI clock is 66Mhz
1256 for (uu = 0; uu < uDelay; uu++) {
1257 VNSvInPortB(dwIoBase + MAC_REG_TMCTL0, &byValue);
1258 if ((byValue == 0) ||
1259 (byValue & TMCTL_TSUSP)) {
1260 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1261 return;
1265 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1270 * Description:
1271 * Micro Second One shot timer via MAC
1273 * Parameters:
1274 * In:
1275 * dwIoBase - Base Address for MAC
1276 * uDelay - Delay time
1277 * Out:
1278 * none
1280 * Return Value: none
1283 void MACvOneShotTimer0MicroSec (DWORD_PTR dwIoBase, UINT uDelayTime)
1285 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1286 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelayTime);
1287 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
1291 * Description:
1292 * Micro Second One shot timer via MAC
1294 * Parameters:
1295 * In:
1296 * dwIoBase - Base Address for MAC
1297 * uDelay - Delay time
1298 * Out:
1299 * none
1301 * Return Value: none
1304 void MACvOneShotTimer1MicroSec (DWORD_PTR dwIoBase, UINT uDelayTime)
1306 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0);
1307 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA1, uDelayTime);
1308 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
1312 void MACvSetMISCFifo (DWORD_PTR dwIoBase, WORD wOffset, DWORD dwData)
1314 if (wOffset > 273)
1315 return;
1316 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1317 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1318 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1322 BOOL MACbTxDMAOff (DWORD_PTR dwIoBase, UINT idx)
1324 BYTE byData;
1325 UINT ww = 0;
1327 if (idx == TYPE_TXDMA0) {
1328 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1329 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1330 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1331 if ( !(byData & DMACTL_RUN))
1332 break;
1334 } else if (idx == TYPE_AC0DMA) {
1335 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1336 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1337 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1338 if ( !(byData & DMACTL_RUN))
1339 break;
1342 if (ww == W_MAX_TIMEOUT) {
1343 DBG_PORT80(0x29);
1344 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x29)\n");
1345 return FALSE;
1347 return TRUE;
1350 void MACvClearBusSusInd (DWORD_PTR dwIoBase)
1352 DWORD dwOrgValue;
1353 UINT ww;
1354 // check if BcnSusInd enabled
1355 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1356 if( !(dwOrgValue & EnCFG_BcnSusInd))
1357 return;
1358 //Set BcnSusClr
1359 dwOrgValue = dwOrgValue | EnCFG_BcnSusClr;
1360 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);
1361 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1362 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1363 if( !(dwOrgValue & EnCFG_BcnSusInd))
1364 break;
1366 if (ww == W_MAX_TIMEOUT) {
1367 DBG_PORT80(0x33);
1368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
1372 void MACvEnableBusSusEn (DWORD_PTR dwIoBase)
1374 BYTE byOrgValue;
1375 DWORD dwOrgValue;
1376 UINT ww;
1377 // check if BcnSusInd enabled
1378 VNSvInPortB(dwIoBase + MAC_REG_CFG , &byOrgValue);
1380 //Set BcnSusEn
1381 byOrgValue = byOrgValue | CFG_BCNSUSEN;
1382 VNSvOutPortB(dwIoBase + MAC_REG_ENCFG, byOrgValue);
1383 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1384 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1385 if(dwOrgValue & EnCFG_BcnSusInd)
1386 break;
1388 if (ww == W_MAX_TIMEOUT) {
1389 DBG_PORT80(0x34);
1390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x34)\n");
1394 BOOL MACbFlushSYNCFifo (DWORD_PTR dwIoBase)
1396 BYTE byOrgValue;
1397 UINT ww;
1398 // Read MACCR
1399 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1401 // Set SYNCFLUSH
1402 byOrgValue = byOrgValue | MACCR_SYNCFLUSH;
1403 VNSvOutPortB(dwIoBase + MAC_REG_MACCR, byOrgValue);
1405 // Check if SyncFlushOK
1406 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1407 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1408 if(byOrgValue & MACCR_SYNCFLUSHOK)
1409 break;
1411 if (ww == W_MAX_TIMEOUT) {
1412 DBG_PORT80(0x35);
1413 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
1415 return TRUE;
1418 BOOL MACbPSWakeup (DWORD_PTR dwIoBase)
1420 BYTE byOrgValue;
1421 UINT ww;
1422 // Read PSCTL
1423 if (MACbIsRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PS)) {
1424 return TRUE;
1426 // Disable PS
1427 MACvRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PSEN);
1429 // Check if SyncFlushOK
1430 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1431 VNSvInPortB(dwIoBase + MAC_REG_PSCTL , &byOrgValue);
1432 if(byOrgValue & PSCTL_WAKEDONE)
1433 break;
1435 if (ww == W_MAX_TIMEOUT) {
1436 DBG_PORT80(0x36);
1437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
1438 return FALSE;
1440 return TRUE;
1444 * Description:
1445 * Set the Key by MISCFIFO
1447 * Parameters:
1448 * In:
1449 * dwIoBase - Base Address for MAC
1451 * Out:
1452 * none
1454 * Return Value: none
1458 void MACvSetKeyEntry (DWORD_PTR dwIoBase, WORD wKeyCtl, UINT uEntryIdx, UINT uKeyIdx, PBYTE pbyAddr, PDWORD pdwKey, BYTE byLocalID)
1460 WORD wOffset;
1461 DWORD dwData;
1462 int ii;
1464 if (byLocalID <= 1)
1465 return;
1468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetKeyEntry\n");
1469 wOffset = MISCFIFO_KEYETRY0;
1470 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1472 dwData = 0;
1473 dwData |= wKeyCtl;
1474 dwData <<= 16;
1475 dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
1476 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
1478 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1479 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1480 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1481 wOffset++;
1483 dwData = 0;
1484 dwData |= *(pbyAddr+3);
1485 dwData <<= 8;
1486 dwData |= *(pbyAddr+2);
1487 dwData <<= 8;
1488 dwData |= *(pbyAddr+1);
1489 dwData <<= 8;
1490 dwData |= *(pbyAddr+0);
1491 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2. wOffset: %d, Data: %lX\n", wOffset, dwData);
1493 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1494 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1495 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1496 wOffset++;
1498 wOffset += (uKeyIdx * 4);
1499 for (ii=0;ii<4;ii++) {
1500 // alway push 128 bits
1501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1502 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1503 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1504 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1511 * Description:
1512 * Disable the Key Entry by MISCFIFO
1514 * Parameters:
1515 * In:
1516 * dwIoBase - Base Address for MAC
1518 * Out:
1519 * none
1521 * Return Value: none
1524 void MACvDisableKeyEntry (DWORD_PTR dwIoBase, UINT uEntryIdx)
1526 WORD wOffset;
1528 wOffset = MISCFIFO_KEYETRY0;
1529 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1531 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1532 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
1533 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1538 * Description:
1539 * Set the 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 MACvSetDefaultKeyEntry (DWORD_PTR dwIoBase, UINT uKeyLen, UINT uKeyIdx, PDWORD pdwKey, BYTE byLocalID)
1554 WORD wOffset;
1555 DWORD dwData;
1556 int ii;
1558 if (byLocalID <= 1)
1559 return;
1561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetDefaultKeyEntry\n");
1562 wOffset = MISCFIFO_KEYETRY0;
1563 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1565 wOffset++;
1566 wOffset++;
1567 wOffset += (uKeyIdx * 4);
1568 // alway push 128 bits
1569 for (ii=0; ii<3; ii++) {
1570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1571 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1572 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1573 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1575 dwData = *pdwKey;
1576 if (uKeyLen == WLAN_WEP104_KEYLEN) {
1577 dwData |= 0x80000000;
1579 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+3);
1580 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1581 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1582 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End. wOffset: %d, Data: %lX\n", wOffset+3, dwData);
1588 * Description:
1589 * Enable default Key (KeyEntry[10]) by MISCFIFO
1591 * Parameters:
1592 * In:
1593 * dwIoBase - Base Address for MAC
1595 * Out:
1596 * none
1598 * Return Value: none
1602 void MACvEnableDefaultKey (DWORD_PTR dwIoBase, BYTE byLocalID)
1604 WORD wOffset;
1605 DWORD dwData;
1608 if (byLocalID <= 1)
1609 return;
1611 wOffset = MISCFIFO_KEYETRY0;
1612 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1614 dwData = 0xC0440000;
1615 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1616 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1617 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1618 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvEnableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
1624 * Description:
1625 * Disable default Key (KeyEntry[10]) by MISCFIFO
1627 * Parameters:
1628 * In:
1629 * dwIoBase - Base Address for MAC
1631 * Out:
1632 * none
1634 * Return Value: none
1637 void MACvDisableDefaultKey (DWORD_PTR dwIoBase)
1639 WORD wOffset;
1640 DWORD dwData;
1643 wOffset = MISCFIFO_KEYETRY0;
1644 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1646 dwData = 0x0;
1647 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1648 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1649 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1650 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvDisableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
1654 * Description:
1655 * Set the default TKIP Group Key (KeyEntry[10]) by MISCFIFO
1657 * Parameters:
1658 * In:
1659 * dwIoBase - Base Address for MAC
1661 * Out:
1662 * none
1664 * Return Value: none
1667 void MACvSetDefaultTKIPKeyEntry (DWORD_PTR dwIoBase, UINT uKeyLen, UINT uKeyIdx, PDWORD pdwKey, BYTE byLocalID)
1669 WORD wOffset;
1670 DWORD dwData;
1671 int ii;
1673 if (byLocalID <= 1)
1674 return;
1677 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetDefaultTKIPKeyEntry\n");
1678 wOffset = MISCFIFO_KEYETRY0;
1679 // Kyle test : change offset from 10 -> 0
1680 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1682 dwData = 0xC0660000;
1683 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1684 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1685 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1686 wOffset++;
1688 dwData = 0;
1689 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1690 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1691 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1692 wOffset++;
1694 wOffset += (uKeyIdx * 4);
1695 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, idx:%d\n", wOffset, *pdwKey, uKeyIdx);
1696 // alway push 128 bits
1697 for (ii=0; ii<4; ii++) {
1698 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1699 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1700 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1701 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1709 * Description:
1710 * Set the Key Control by MISCFIFO
1712 * Parameters:
1713 * In:
1714 * dwIoBase - Base Address for MAC
1716 * Out:
1717 * none
1719 * Return Value: none
1723 void MACvSetDefaultKeyCtl (DWORD_PTR dwIoBase, WORD wKeyCtl, UINT uEntryIdx, BYTE byLocalID)
1725 WORD wOffset;
1726 DWORD dwData;
1728 if (byLocalID <= 1)
1729 return;
1732 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetKeyEntry\n");
1733 wOffset = MISCFIFO_KEYETRY0;
1734 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1736 dwData = 0;
1737 dwData |= wKeyCtl;
1738 dwData <<= 16;
1739 dwData |= 0xffff;
1740 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
1742 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1743 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1744 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);