blob: 21bd8a1126d794056f87a397d708fd0236c7e755 [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
Jim Lieb612822f2009-08-12 14:54:03 -070019 *
Forest Bond5449c682009-04-25 10:30:44 -040020 * File: mac.c
21 *
22 * Purpose: MAC routines
23 *
24 * Author: Tevin Chen
25 *
26 * Date: May 21, 1996
27 *
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
Justin P. Mattock789d1ae2012-08-20 08:43:13 -070059 * MACvSetCurrRxDescAddr - Set Rx Descriptors Address
60 * MACvSetCurrTx0DescAddr - Set Tx0 Descriptors Address
61 * MACvSetCurrTx1DescAddr - Set Tx1 Descriptors Address
Forest Bond5449c682009-04-25 10:30:44 -040062 * MACvTimer0MicroSDelay - Micro Second Delay Loop by MAC
63 *
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
68 *
69 */
70
Forest Bond5449c682009-04-25 10:30:44 -040071#include "tmacro.h"
Forest Bond5449c682009-04-25 10:30:44 -040072#include "tether.h"
Forest Bond5449c682009-04-25 10:30:44 -040073#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040074
Charles Clément2986db52010-06-24 11:02:26 -070075unsigned short TxRate_iwconfig;//2008-5-8 <add> by chester
Forest Bond5449c682009-04-25 10:30:44 -040076/*--------------------- Static Definitions -------------------------*/
77//static int msglevel =MSG_LEVEL_DEBUG;
Joe Perchesc3504bf2013-03-18 10:44:55 -070078static int msglevel = MSG_LEVEL_INFO;
Forest Bond5449c682009-04-25 10:30:44 -040079/*--------------------- Static Classes ----------------------------*/
80
81/*--------------------- Static Variables --------------------------*/
82
83/*--------------------- Static Functions --------------------------*/
84
85/*--------------------- Export Variables --------------------------*/
86
87/*--------------------- Export Functions --------------------------*/
88
89/*
90 * Description:
91 * Read All MAC Registers to buffer
92 *
93 * Parameters:
94 * In:
95 * dwIoBase - Base Address for MAC
96 * Out:
97 * pbyMacRegs - buffer to read
98 *
99 * Return Value: none
100 *
101 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700102void MACvReadAllRegs(unsigned long dwIoBase, unsigned char *pbyMacRegs)
Forest Bond5449c682009-04-25 10:30:44 -0400103{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700104 int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400105
Joe Perchesc3504bf2013-03-18 10:44:55 -0700106 // read page0 register
107 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
108 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
109 pbyMacRegs++;
110 }
Forest Bond5449c682009-04-25 10:30:44 -0400111
Joe Perchesc3504bf2013-03-18 10:44:55 -0700112 MACvSelectPage1(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400113
Joe Perchesc3504bf2013-03-18 10:44:55 -0700114 // read page1 register
115 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
116 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
117 pbyMacRegs++;
118 }
Forest Bond5449c682009-04-25 10:30:44 -0400119
Joe Perchesc3504bf2013-03-18 10:44:55 -0700120 MACvSelectPage0(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400121}
122
123/*
124 * Description:
125 * Test if all test bits on
126 *
127 * Parameters:
128 * In:
129 * dwIoBase - Base Address for MAC
130 * byRegOfs - Offset of MAC Register
131 * byTestBits - Test bits
132 * Out:
133 * none
134 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200135 * Return Value: true if all test bits On; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400136 *
137 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700138bool MACbIsRegBitsOn(unsigned long dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
Forest Bond5449c682009-04-25 10:30:44 -0400139{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700140 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400141
Joe Perchesc3504bf2013-03-18 10:44:55 -0700142 VNSvInPortB(dwIoBase + byRegOfs, &byData);
143 return (byData & byTestBits) == byTestBits;
Forest Bond5449c682009-04-25 10:30:44 -0400144}
145
146/*
147 * Description:
148 * Test if all test bits off
149 *
150 * Parameters:
151 * In:
152 * dwIoBase - Base Address for MAC
153 * byRegOfs - Offset of MAC Register
154 * byTestBits - Test bits
155 * Out:
156 * none
157 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200158 * Return Value: true if all test bits Off; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400159 *
160 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700161bool MACbIsRegBitsOff(unsigned long dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
Forest Bond5449c682009-04-25 10:30:44 -0400162{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700163 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400164
Joe Perchesc3504bf2013-03-18 10:44:55 -0700165 VNSvInPortB(dwIoBase + byRegOfs, &byData);
166 return !(byData & byTestBits);
Forest Bond5449c682009-04-25 10:30:44 -0400167}
168
169/*
170 * Description:
171 * Test if MAC interrupt disable
172 *
173 * Parameters:
174 * In:
175 * dwIoBase - Base Address for MAC
176 * Out:
177 * none
178 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200179 * Return Value: true if interrupt is disable; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400180 *
181 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700182bool MACbIsIntDisable(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400183{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700184 unsigned long dwData;
Forest Bond5449c682009-04-25 10:30:44 -0400185
Joe Perchesc3504bf2013-03-18 10:44:55 -0700186 VNSvInPortD(dwIoBase + MAC_REG_IMR, &dwData);
187 if (dwData != 0)
188 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400189
Joe Perchesc3504bf2013-03-18 10:44:55 -0700190 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400191}
192
193/*
194 * Description:
195 * Read MAC Multicast Address Mask
196 *
197 * Parameters:
198 * In:
199 * dwIoBase - Base Address for MAC
200 * uByteidx - Index of Mask
201 * Out:
202 * none
203 *
204 * Return Value: Mask Value read
205 *
206 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700207unsigned char MACbyReadMultiAddr(unsigned long dwIoBase, unsigned int uByteIdx)
Forest Bond5449c682009-04-25 10:30:44 -0400208{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700209 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400210
Joe Perchesc3504bf2013-03-18 10:44:55 -0700211 MACvSelectPage1(dwIoBase);
212 VNSvInPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, &byData);
213 MACvSelectPage0(dwIoBase);
214 return byData;
Forest Bond5449c682009-04-25 10:30:44 -0400215}
216
217/*
218 * Description:
219 * Write MAC Multicast Address Mask
220 *
221 * Parameters:
222 * In:
223 * dwIoBase - Base Address for MAC
224 * uByteidx - Index of Mask
225 * byData - Mask Value to write
226 * Out:
227 * none
228 *
229 * Return Value: none
230 *
231 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700232void MACvWriteMultiAddr(unsigned long dwIoBase, unsigned int uByteIdx, unsigned char byData)
Forest Bond5449c682009-04-25 10:30:44 -0400233{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700234 MACvSelectPage1(dwIoBase);
235 VNSvOutPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, byData);
236 MACvSelectPage0(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400237}
238
239/*
240 * Description:
241 * Set this hash index into multicast address register bit
242 *
243 * Parameters:
244 * In:
245 * dwIoBase - Base Address for MAC
246 * byHashIdx - Hash index to set
247 * Out:
248 * none
249 *
250 * Return Value: none
251 *
252 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700253void MACvSetMultiAddrByHash(unsigned long dwIoBase, unsigned char byHashIdx)
Forest Bond5449c682009-04-25 10:30:44 -0400254{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700255 unsigned int uByteIdx;
256 unsigned char byBitMask;
257 unsigned char byOrgValue;
Forest Bond5449c682009-04-25 10:30:44 -0400258
Joe Perchesc3504bf2013-03-18 10:44:55 -0700259 // calculate byte position
260 uByteIdx = byHashIdx / 8;
261 ASSERT(uByteIdx < 8);
262 // calculate bit position
263 byBitMask = 1;
264 byBitMask <<= (byHashIdx % 8);
265 // turn on the bit
266 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
267 MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue | byBitMask));
Forest Bond5449c682009-04-25 10:30:44 -0400268}
269
270/*
271 * Description:
272 * Reset this hash index into multicast address register bit
273 *
274 * Parameters:
275 * In:
276 * dwIoBase - Base Address for MAC
277 * byHashIdx - Hash index to clear
278 * Out:
279 * none
280 *
281 * Return Value: none
282 *
283 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700284void MACvResetMultiAddrByHash(unsigned long dwIoBase, unsigned char byHashIdx)
Forest Bond5449c682009-04-25 10:30:44 -0400285{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700286 unsigned int uByteIdx;
287 unsigned char byBitMask;
288 unsigned char byOrgValue;
Forest Bond5449c682009-04-25 10:30:44 -0400289
Joe Perchesc3504bf2013-03-18 10:44:55 -0700290 // calculate byte position
291 uByteIdx = byHashIdx / 8;
292 ASSERT(uByteIdx < 8);
293 // calculate bit position
294 byBitMask = 1;
295 byBitMask <<= (byHashIdx % 8);
296 // turn off the bit
297 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
298 MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue & (~byBitMask)));
Forest Bond5449c682009-04-25 10:30:44 -0400299}
300
301/*
302 * Description:
303 * Set Rx Threshold
304 *
305 * Parameters:
306 * In:
307 * dwIoBase - Base Address for MAC
308 * byThreshold - Threshold Value
309 * Out:
310 * none
311 *
312 * Return Value: none
313 *
314 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700315void MACvSetRxThreshold(unsigned long dwIoBase, unsigned char byThreshold)
Forest Bond5449c682009-04-25 10:30:44 -0400316{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700317 unsigned char byOrgValue;
Forest Bond5449c682009-04-25 10:30:44 -0400318
Joe Perchesc3504bf2013-03-18 10:44:55 -0700319 ASSERT(byThreshold < 4);
Forest Bond5449c682009-04-25 10:30:44 -0400320
Joe Perchesc3504bf2013-03-18 10:44:55 -0700321 // set FCR0
322 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
323 byOrgValue = (byOrgValue & 0xCF) | (byThreshold << 4);
324 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
Forest Bond5449c682009-04-25 10:30:44 -0400325}
326
327/*
328 * Description:
329 * Get Rx Threshold
330 *
331 * Parameters:
332 * In:
333 * dwIoBase - Base Address for MAC
334 * Out:
335 * pbyThreshold- Threshold Value Get
336 *
337 * Return Value: none
338 *
339 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700340void MACvGetRxThreshold(unsigned long dwIoBase, unsigned char *pbyThreshold)
Forest Bond5449c682009-04-25 10:30:44 -0400341{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700342 // get FCR0
343 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
344 *pbyThreshold = (*pbyThreshold >> 4) & 0x03;
Forest Bond5449c682009-04-25 10:30:44 -0400345}
346
347/*
348 * Description:
349 * Set Tx Threshold
350 *
351 * Parameters:
352 * In:
353 * dwIoBase - Base Address for MAC
354 * byThreshold - Threshold Value
355 * Out:
356 * none
357 *
358 * Return Value: none
359 *
360 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700361void MACvSetTxThreshold(unsigned long dwIoBase, unsigned char byThreshold)
Forest Bond5449c682009-04-25 10:30:44 -0400362{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700363 unsigned char byOrgValue;
Forest Bond5449c682009-04-25 10:30:44 -0400364
Joe Perchesc3504bf2013-03-18 10:44:55 -0700365 ASSERT(byThreshold < 4);
Forest Bond5449c682009-04-25 10:30:44 -0400366
Joe Perchesc3504bf2013-03-18 10:44:55 -0700367 // set FCR0
368 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
369 byOrgValue = (byOrgValue & 0xF3) | (byThreshold << 2);
370 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
Forest Bond5449c682009-04-25 10:30:44 -0400371}
372
373/*
374 * Description:
375 * Get Tx Threshold
376 *
377 * Parameters:
378 * In:
379 * dwIoBase - Base Address for MAC
380 * Out:
381 * pbyThreshold- Threshold Value Get
382 *
383 * Return Value: none
384 *
385 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700386void MACvGetTxThreshold(unsigned long dwIoBase, unsigned char *pbyThreshold)
Forest Bond5449c682009-04-25 10:30:44 -0400387{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700388 // get FCR0
389 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
390 *pbyThreshold = (*pbyThreshold >> 2) & 0x03;
Forest Bond5449c682009-04-25 10:30:44 -0400391}
392
393/*
394 * Description:
395 * Set Dma Length
396 *
397 * Parameters:
398 * In:
399 * dwIoBase - Base Address for MAC
400 * byDmaLength - Dma Length Value
401 * Out:
402 * none
403 *
404 * Return Value: none
405 *
406 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700407void MACvSetDmaLength(unsigned long dwIoBase, unsigned char byDmaLength)
Forest Bond5449c682009-04-25 10:30:44 -0400408{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700409 unsigned char byOrgValue;
Forest Bond5449c682009-04-25 10:30:44 -0400410
Joe Perchesc3504bf2013-03-18 10:44:55 -0700411 ASSERT(byDmaLength < 4);
Forest Bond5449c682009-04-25 10:30:44 -0400412
Joe Perchesc3504bf2013-03-18 10:44:55 -0700413 // set FCR0
414 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
415 byOrgValue = (byOrgValue & 0xFC) | byDmaLength;
416 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
Forest Bond5449c682009-04-25 10:30:44 -0400417}
418
419/*
420 * Description:
421 * Get Dma Length
422 *
423 * Parameters:
424 * In:
425 * dwIoBase - Base Address for MAC
426 * Out:
427 * pbyDmaLength- Dma Length Value Get
428 *
429 * Return Value: none
430 *
431 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700432void MACvGetDmaLength(unsigned long dwIoBase, unsigned char *pbyDmaLength)
Forest Bond5449c682009-04-25 10:30:44 -0400433{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700434 // get FCR0
435 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyDmaLength);
436 *pbyDmaLength &= 0x03;
Forest Bond5449c682009-04-25 10:30:44 -0400437}
438
439/*
440 * Description:
441 * Set 802.11 Short Retry Limit
442 *
443 * Parameters:
444 * In:
445 * dwIoBase - Base Address for MAC
446 * byRetryLimit- Retry Limit
447 * Out:
448 * none
449 *
450 * Return Value: none
451 *
452 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700453void MACvSetShortRetryLimit(unsigned long dwIoBase, unsigned char byRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400454{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700455 // set SRT
456 VNSvOutPortB(dwIoBase + MAC_REG_SRT, byRetryLimit);
Forest Bond5449c682009-04-25 10:30:44 -0400457}
458
459/*
460 * Description:
461 * Get 802.11 Short Retry Limit
462 *
463 * Parameters:
464 * In:
465 * dwIoBase - Base Address for MAC
466 * Out:
467 * pbyRetryLimit - Retry Limit Get
468 *
469 * Return Value: none
470 *
471 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700472void MACvGetShortRetryLimit(unsigned long dwIoBase, unsigned char *pbyRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400473{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700474 // get SRT
475 VNSvInPortB(dwIoBase + MAC_REG_SRT, pbyRetryLimit);
Forest Bond5449c682009-04-25 10:30:44 -0400476}
477
478/*
479 * Description:
480 * Set 802.11 Long Retry Limit
481 *
482 * Parameters:
483 * In:
484 * dwIoBase - Base Address for MAC
485 * byRetryLimit- Retry Limit
486 * Out:
487 * none
488 *
489 * Return Value: none
490 *
491 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700492void MACvSetLongRetryLimit(unsigned long dwIoBase, unsigned char byRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400493{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700494 // set LRT
495 VNSvOutPortB(dwIoBase + MAC_REG_LRT, byRetryLimit);
Forest Bond5449c682009-04-25 10:30:44 -0400496}
497
498/*
499 * Description:
500 * Get 802.11 Long Retry Limit
501 *
502 * Parameters:
503 * In:
504 * dwIoBase - Base Address for MAC
505 * Out:
506 * pbyRetryLimit - Retry Limit Get
507 *
508 * Return Value: none
509 *
510 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700511void MACvGetLongRetryLimit(unsigned long dwIoBase, unsigned char *pbyRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400512{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700513 // get LRT
514 VNSvInPortB(dwIoBase + MAC_REG_LRT, pbyRetryLimit);
Forest Bond5449c682009-04-25 10:30:44 -0400515}
516
517/*
518 * Description:
519 * Set MAC Loopback mode
520 *
521 * Parameters:
522 * In:
523 * dwIoBase - Base Address for MAC
524 * byLoopbackMode - Loopback Mode
525 * Out:
526 * none
527 *
528 * Return Value: none
529 *
530 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700531void MACvSetLoopbackMode(unsigned long dwIoBase, unsigned char byLoopbackMode)
Forest Bond5449c682009-04-25 10:30:44 -0400532{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700533 unsigned char byOrgValue;
Forest Bond5449c682009-04-25 10:30:44 -0400534
Joe Perchesc3504bf2013-03-18 10:44:55 -0700535 ASSERT(byLoopbackMode < 3);
536 byLoopbackMode <<= 6;
537 // set TCR
538 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
539 byOrgValue = byOrgValue & 0x3F;
540 byOrgValue = byOrgValue | byLoopbackMode;
541 VNSvOutPortB(dwIoBase + MAC_REG_TEST, byOrgValue);
Forest Bond5449c682009-04-25 10:30:44 -0400542}
543
544/*
545 * Description:
546 * Test if MAC in Loopback mode
547 *
548 * Parameters:
549 * In:
550 * dwIoBase - Base Address for MAC
551 * Out:
552 * none
553 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200554 * Return Value: true if in Loopback mode; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400555 *
556 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700557bool MACbIsInLoopbackMode(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400558{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700559 unsigned char byOrgValue;
Forest Bond5449c682009-04-25 10:30:44 -0400560
Joe Perchesc3504bf2013-03-18 10:44:55 -0700561 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
562 if (byOrgValue & (TEST_LBINT | TEST_LBEXT))
563 return true;
564 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400565}
566
567/*
568 * Description:
569 * Set MAC Address filter
570 *
571 * Parameters:
572 * In:
573 * dwIoBase - Base Address for MAC
574 * wFilterType - Filter Type
575 * Out:
576 * none
577 *
578 * Return Value: none
579 *
580 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700581void MACvSetPacketFilter(unsigned long dwIoBase, unsigned short wFilterType)
Forest Bond5449c682009-04-25 10:30:44 -0400582{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700583 unsigned char byOldRCR;
584 unsigned char byNewRCR = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400585
Joe Perchesc3504bf2013-03-18 10:44:55 -0700586 // if only in DIRECTED mode, multicast-address will set to zero,
587 // but if other mode exist (e.g. PROMISCUOUS), multicast-address
588 // will be open
589 if (wFilterType & PKT_TYPE_DIRECTED) {
590 // set multicast address to accept none
591 MACvSelectPage1(dwIoBase);
592 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0L);
593 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0L);
594 MACvSelectPage0(dwIoBase);
595 }
Forest Bond5449c682009-04-25 10:30:44 -0400596
Joe Perchesc3504bf2013-03-18 10:44:55 -0700597 if (wFilterType & (PKT_TYPE_PROMISCUOUS | PKT_TYPE_ALL_MULTICAST)) {
598 // set multicast address to accept all
599 MACvSelectPage1(dwIoBase);
600 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0xFFFFFFFFL);
601 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0xFFFFFFFFL);
602 MACvSelectPage0(dwIoBase);
603 }
Forest Bond5449c682009-04-25 10:30:44 -0400604
Joe Perchesc3504bf2013-03-18 10:44:55 -0700605 if (wFilterType & PKT_TYPE_PROMISCUOUS) {
Joe Perchesc3504bf2013-03-18 10:44:55 -0700606 byNewRCR |= (RCR_RXALLTYPE | RCR_UNICAST | RCR_MULTICAST | RCR_BROADCAST);
Forest Bond5449c682009-04-25 10:30:44 -0400607
Joe Perchesc3504bf2013-03-18 10:44:55 -0700608 byNewRCR &= ~RCR_BSSID;
609 }
Forest Bond5449c682009-04-25 10:30:44 -0400610
Joe Perchesc3504bf2013-03-18 10:44:55 -0700611 if (wFilterType & (PKT_TYPE_ALL_MULTICAST | PKT_TYPE_MULTICAST))
612 byNewRCR |= RCR_MULTICAST;
Forest Bond5449c682009-04-25 10:30:44 -0400613
Joe Perchesc3504bf2013-03-18 10:44:55 -0700614 if (wFilterType & PKT_TYPE_BROADCAST)
615 byNewRCR |= RCR_BROADCAST;
Forest Bond5449c682009-04-25 10:30:44 -0400616
Joe Perchesc3504bf2013-03-18 10:44:55 -0700617 if (wFilterType & PKT_TYPE_ERROR_CRC)
618 byNewRCR |= RCR_ERRCRC;
Forest Bond5449c682009-04-25 10:30:44 -0400619
Joe Perchesc3504bf2013-03-18 10:44:55 -0700620 VNSvInPortB(dwIoBase + MAC_REG_RCR, &byOldRCR);
621 if (byNewRCR != byOldRCR) {
622 // Modify the Receive Command Register
623 VNSvOutPortB(dwIoBase + MAC_REG_RCR, byNewRCR);
624 }
Forest Bond5449c682009-04-25 10:30:44 -0400625}
626
627/*
628 * Description:
629 * Save MAC registers to context buffer
630 *
631 * Parameters:
632 * In:
633 * dwIoBase - Base Address for MAC
634 * Out:
635 * pbyCxtBuf - Context buffer
636 *
637 * Return Value: none
638 *
639 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700640void MACvSaveContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
Forest Bond5449c682009-04-25 10:30:44 -0400641{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700642 int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400643
Joe Perchesc3504bf2013-03-18 10:44:55 -0700644 // read page0 register
645 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
646 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + ii));
647 }
Forest Bond5449c682009-04-25 10:30:44 -0400648
Joe Perchesc3504bf2013-03-18 10:44:55 -0700649 MACvSelectPage1(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400650
Joe Perchesc3504bf2013-03-18 10:44:55 -0700651 // read page1 register
652 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
653 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
654 }
Forest Bond5449c682009-04-25 10:30:44 -0400655
Joe Perchesc3504bf2013-03-18 10:44:55 -0700656 MACvSelectPage0(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400657}
658
659/*
660 * Description:
661 * Restore MAC registers from context buffer
662 *
663 * Parameters:
664 * In:
665 * dwIoBase - Base Address for MAC
666 * pbyCxtBuf - Context buffer
667 * Out:
668 * none
669 *
670 * Return Value: none
671 *
672 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700673void MACvRestoreContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
Forest Bond5449c682009-04-25 10:30:44 -0400674{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700675 int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400676
Joe Perchesc3504bf2013-03-18 10:44:55 -0700677 MACvSelectPage1(dwIoBase);
678 // restore page1
679 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
680 VNSvOutPortB((dwIoBase + ii), *(pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
681 }
682 MACvSelectPage0(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400683
Joe Perchesc3504bf2013-03-18 10:44:55 -0700684 // restore RCR,TCR,IMR...
685 for (ii = MAC_REG_RCR; ii < MAC_REG_ISR; ii++) {
686 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
687 }
688 // restore MAC Config.
689 for (ii = MAC_REG_LRT; ii < MAC_REG_PAGE1SEL; ii++) {
690 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
691 }
692 VNSvOutPortB(dwIoBase + MAC_REG_CFG, *(pbyCxtBuf + MAC_REG_CFG));
Forest Bond5449c682009-04-25 10:30:44 -0400693
Joe Perchesc3504bf2013-03-18 10:44:55 -0700694 // restore PS Config.
695 for (ii = MAC_REG_PSCFG; ii < MAC_REG_BBREGCTL; ii++) {
696 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
697 }
Forest Bond5449c682009-04-25 10:30:44 -0400698
Joe Perchesc3504bf2013-03-18 10:44:55 -0700699 // restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
700 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0));
701 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR));
702 VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_BCNDMAPTR));
Forest Bond5449c682009-04-25 10:30:44 -0400703
Joe Perchesc3504bf2013-03-18 10:44:55 -0700704 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0));
Forest Bond5449c682009-04-25 10:30:44 -0400705
Joe Perchesc3504bf2013-03-18 10:44:55 -0700706 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1));
Forest Bond5449c682009-04-25 10:30:44 -0400707}
708
709/*
710 * Description:
711 * Compare if MAC registers same as context buffer
712 *
713 * Parameters:
714 * In:
715 * dwIoBase - Base Address for MAC
716 * pbyCxtBuf - Context buffer
717 * Out:
718 * none
719 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200720 * Return Value: true if all values are the same; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400721 *
722 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700723bool MACbCompareContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
Forest Bond5449c682009-04-25 10:30:44 -0400724{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700725 unsigned long dwData;
Forest Bond5449c682009-04-25 10:30:44 -0400726
Joe Perchesc3504bf2013-03-18 10:44:55 -0700727 // compare MAC context to determine if this is a power lost init,
728 // return true for power remaining init, return false for power lost init
Forest Bond5449c682009-04-25 10:30:44 -0400729
Joe Perchesc3504bf2013-03-18 10:44:55 -0700730 // compare CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
731 VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0, &dwData);
732 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0)) {
733 return false;
734 }
Forest Bond5449c682009-04-25 10:30:44 -0400735
Joe Perchesc3504bf2013-03-18 10:44:55 -0700736 VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR, &dwData);
737 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR)) {
738 return false;
739 }
Forest Bond5449c682009-04-25 10:30:44 -0400740
Joe Perchesc3504bf2013-03-18 10:44:55 -0700741 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0, &dwData);
742 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0)) {
743 return false;
744 }
Forest Bond5449c682009-04-25 10:30:44 -0400745
Joe Perchesc3504bf2013-03-18 10:44:55 -0700746 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1, &dwData);
747 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1)) {
748 return false;
749 }
Forest Bond5449c682009-04-25 10:30:44 -0400750
Joe Perchesc3504bf2013-03-18 10:44:55 -0700751 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400752}
753
754/*
755 * Description:
756 * Software Reset MAC
757 *
758 * Parameters:
759 * In:
760 * dwIoBase - Base Address for MAC
761 * Out:
762 * none
763 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200764 * Return Value: true if Reset Success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400765 *
766 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700767bool MACbSoftwareReset(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400768{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700769 unsigned char byData;
770 unsigned short ww;
Forest Bond5449c682009-04-25 10:30:44 -0400771
Joe Perchesc3504bf2013-03-18 10:44:55 -0700772 // turn on HOSTCR_SOFTRST, just write 0x01 to reset
773 //MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_SOFTRST);
774 VNSvOutPortB(dwIoBase + MAC_REG_HOSTCR, 0x01);
Forest Bond5449c682009-04-25 10:30:44 -0400775
Joe Perchesc3504bf2013-03-18 10:44:55 -0700776 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
777 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
778 if (!(byData & HOSTCR_SOFTRST))
779 break;
780 }
781 if (ww == W_MAX_TIMEOUT)
782 return false;
783 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400784}
785
786/*
787 * Description:
788 * save some important register's value, then do reset, then restore register's value
789 *
790 * Parameters:
791 * In:
792 * dwIoBase - Base Address for MAC
793 * Out:
794 * none
795 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200796 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400797 *
798 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700799bool MACbSafeSoftwareReset(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400800{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700801 unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
802 bool bRetVal;
Forest Bond5449c682009-04-25 10:30:44 -0400803
Joe Perchesc3504bf2013-03-18 10:44:55 -0700804 // PATCH....
805 // save some important register's value, then do
806 // reset, then restore register's value
Forest Bond5449c682009-04-25 10:30:44 -0400807
Joe Perchesc3504bf2013-03-18 10:44:55 -0700808 // save MAC context
809 MACvSaveContext(dwIoBase, abyTmpRegData);
810 // do reset
811 bRetVal = MACbSoftwareReset(dwIoBase);
812 //BBvSoftwareReset(pDevice->PortOffset);
813 // restore MAC context, except CR0
814 MACvRestoreContext(dwIoBase, abyTmpRegData);
Forest Bond5449c682009-04-25 10:30:44 -0400815
Joe Perchesc3504bf2013-03-18 10:44:55 -0700816 return bRetVal;
Forest Bond5449c682009-04-25 10:30:44 -0400817}
818
819/*
820 * Description:
821 * Trun Off MAC Rx
822 *
823 * Parameters:
824 * In:
825 * dwIoBase - Base Address for MAC
826 * Out:
827 * none
828 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200829 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400830 *
831 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700832bool MACbSafeRxOff(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400833{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700834 unsigned short ww;
835 unsigned long dwData;
836 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400837
Joe Perchesc3504bf2013-03-18 10:44:55 -0700838 // turn off wow temp for turn off Rx safely
Forest Bond5449c682009-04-25 10:30:44 -0400839
Joe Perchesc3504bf2013-03-18 10:44:55 -0700840 // Clear RX DMA0,1
841 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
842 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
843 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
844 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);
845 if (!(dwData & DMACTL_RUN))
846 break;
847 }
848 if (ww == W_MAX_TIMEOUT) {
849 DBG_PORT80(0x10);
850 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x10)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700851 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700852 }
853 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
854 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);
855 if (!(dwData & DMACTL_RUN))
856 break;
857 }
858 if (ww == W_MAX_TIMEOUT) {
859 DBG_PORT80(0x11);
860 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x11)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700861 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700862 }
Forest Bond5449c682009-04-25 10:30:44 -0400863
Joe Perchesc3504bf2013-03-18 10:44:55 -0700864 // try to safe shutdown RX
865 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON);
866 // W_MAX_TIMEOUT is the timeout period
867 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
868 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
869 if (!(byData & HOSTCR_RXONST))
870 break;
871 }
872 if (ww == W_MAX_TIMEOUT) {
873 DBG_PORT80(0x12);
874 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x12)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700875 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700876 }
877 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400878}
879
880/*
881 * Description:
882 * Trun Off MAC Tx
883 *
884 * Parameters:
885 * In:
886 * dwIoBase - Base Address for MAC
887 * Out:
888 * none
889 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200890 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400891 *
892 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700893bool MACbSafeTxOff(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400894{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700895 unsigned short ww;
896 unsigned long dwData;
897 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400898
Joe Perchesc3504bf2013-03-18 10:44:55 -0700899 // Clear TX DMA
900 //Tx0
901 VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
902 //AC0
903 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
Forest Bond5449c682009-04-25 10:30:44 -0400904
Joe Perchesc3504bf2013-03-18 10:44:55 -0700905 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
906 VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);
907 if (!(dwData & DMACTL_RUN))
908 break;
909 }
910 if (ww == W_MAX_TIMEOUT) {
911 DBG_PORT80(0x20);
912 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x20)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700913 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700914 }
915 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
916 VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);
917 if (!(dwData & DMACTL_RUN))
918 break;
919 }
920 if (ww == W_MAX_TIMEOUT) {
921 DBG_PORT80(0x21);
922 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x21)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700923 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700924 }
Forest Bond5449c682009-04-25 10:30:44 -0400925
Joe Perchesc3504bf2013-03-18 10:44:55 -0700926 // try to safe shutdown TX
927 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON);
Forest Bond5449c682009-04-25 10:30:44 -0400928
Joe Perchesc3504bf2013-03-18 10:44:55 -0700929 // W_MAX_TIMEOUT is the timeout period
930 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
931 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
932 if (!(byData & HOSTCR_TXONST))
933 break;
934 }
935 if (ww == W_MAX_TIMEOUT) {
936 DBG_PORT80(0x24);
937 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x24)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700938 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700939 }
940 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400941}
942
943/*
944 * Description:
945 * Stop MAC function
946 *
947 * Parameters:
948 * In:
949 * dwIoBase - Base Address for MAC
950 * Out:
951 * none
952 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200953 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400954 *
955 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700956bool MACbSafeStop(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400957{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700958 MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX);
Forest Bond5449c682009-04-25 10:30:44 -0400959
Teodora Baluta1208f142013-11-10 17:12:42 +0200960 if (!MACbSafeRxOff(dwIoBase)) {
Joe Perchesc3504bf2013-03-18 10:44:55 -0700961 DBG_PORT80(0xA1);
962 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " MACbSafeRxOff == false)\n");
963 MACbSafeSoftwareReset(dwIoBase);
964 return false;
965 }
Teodora Baluta1208f142013-11-10 17:12:42 +0200966 if (!MACbSafeTxOff(dwIoBase)) {
Joe Perchesc3504bf2013-03-18 10:44:55 -0700967 DBG_PORT80(0xA2);
968 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " MACbSafeTxOff == false)\n");
969 MACbSafeSoftwareReset(dwIoBase);
970 return false;
971 }
Forest Bond5449c682009-04-25 10:30:44 -0400972
Joe Perchesc3504bf2013-03-18 10:44:55 -0700973 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_MACEN);
Forest Bond5449c682009-04-25 10:30:44 -0400974
Joe Perchesc3504bf2013-03-18 10:44:55 -0700975 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400976}
977
978/*
979 * Description:
980 * Shut Down MAC
981 *
982 * Parameters:
983 * In:
984 * dwIoBase - Base Address for MAC
985 * Out:
986 * none
987 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200988 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400989 *
990 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700991bool MACbShutdown(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400992{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700993 // disable MAC IMR
994 MACvIntDisable(dwIoBase);
995 MACvSetLoopbackMode(dwIoBase, MAC_LB_INTERNAL);
996 // stop the adapter
997 if (!MACbSafeStop(dwIoBase)) {
998 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
999 return false;
1000 }
1001 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
1002 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001003}
1004
1005/*
1006 * Description:
1007 * Initialize MAC
1008 *
1009 * Parameters:
1010 * In:
1011 * dwIoBase - Base Address for MAC
1012 * Out:
1013 * none
1014 *
1015 * Return Value: none
1016 *
1017 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001018void MACvInitialize(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -04001019{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001020 // clear sticky bits
1021 MACvClearStckDS(dwIoBase);
1022 // disable force PME-enable
1023 VNSvOutPortB(dwIoBase + MAC_REG_PMC1, PME_OVR);
1024 // only 3253 A
1025 /*
1026 MACvPwrEvntDisable(dwIoBase);
1027 // clear power status
1028 VNSvOutPortW(dwIoBase + MAC_REG_WAKEUPSR0, 0x0F0F);
1029 */
Forest Bond5449c682009-04-25 10:30:44 -04001030
Joe Perchesc3504bf2013-03-18 10:44:55 -07001031 // do reset
1032 MACbSoftwareReset(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -04001033
Joe Perchesc3504bf2013-03-18 10:44:55 -07001034 // reset TSF counter
1035 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1036 // enable TSF counter
1037 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
Forest Bond5449c682009-04-25 10:30:44 -04001038
Joe Perchesc3504bf2013-03-18 10:44:55 -07001039 // set packet filter
1040 // receive directed and broadcast address
Forest Bond5449c682009-04-25 10:30:44 -04001041
Joe Perchesc3504bf2013-03-18 10:44:55 -07001042 MACvSetPacketFilter(dwIoBase, PKT_TYPE_DIRECTED | PKT_TYPE_BROADCAST);
Forest Bond5449c682009-04-25 10:30:44 -04001043}
1044
1045/*
1046 * Description:
1047 * Set the chip with current rx descriptor address
1048 *
1049 * Parameters:
1050 * In:
1051 * dwIoBase - Base Address for MAC
1052 * dwCurrDescAddr - Descriptor Address
1053 * Out:
1054 * none
1055 *
1056 * Return Value: none
1057 *
1058 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001059void MACvSetCurrRx0DescAddr(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -04001060{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001061 unsigned short ww;
1062 unsigned char byData;
1063 unsigned char byOrgDMACtl;
Forest Bond5449c682009-04-25 10:30:44 -04001064
Joe Perchesc3504bf2013-03-18 10:44:55 -07001065 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byOrgDMACtl);
1066 if (byOrgDMACtl & DMACTL_RUN) {
1067 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
1068 }
1069 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1070 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byData);
1071 if (!(byData & DMACTL_RUN))
1072 break;
1073 }
1074 if (ww == W_MAX_TIMEOUT) {
1075 DBG_PORT80(0x13);
1076 }
1077 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
1078 if (byOrgDMACtl & DMACTL_RUN) {
1079 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN);
1080 }
Forest Bond5449c682009-04-25 10:30:44 -04001081}
1082
1083/*
1084 * Description:
1085 * Set the chip with current rx descriptor address
1086 *
1087 * Parameters:
1088 * In:
1089 * dwIoBase - Base Address for MAC
1090 * dwCurrDescAddr - Descriptor Address
1091 * Out:
1092 * none
1093 *
1094 * Return Value: none
1095 *
1096 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001097void MACvSetCurrRx1DescAddr(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -04001098{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001099 unsigned short ww;
1100 unsigned char byData;
1101 unsigned char byOrgDMACtl;
Forest Bond5449c682009-04-25 10:30:44 -04001102
Joe Perchesc3504bf2013-03-18 10:44:55 -07001103 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byOrgDMACtl);
1104 if (byOrgDMACtl & DMACTL_RUN) {
1105 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
1106 }
1107 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1108 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byData);
1109 if (!(byData & DMACTL_RUN))
1110 break;
1111 }
1112 if (ww == W_MAX_TIMEOUT) {
1113 DBG_PORT80(0x14);
1114 }
1115 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
1116 if (byOrgDMACtl & DMACTL_RUN) {
1117 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN);
1118 }
Forest Bond5449c682009-04-25 10:30:44 -04001119}
1120
1121/*
1122 * Description:
1123 * Set the chip with current tx0 descriptor address
1124 *
1125 * Parameters:
1126 * In:
1127 * dwIoBase - Base Address for MAC
1128 * dwCurrDescAddr - Descriptor Address
1129 * Out:
1130 * none
1131 *
1132 * Return Value: none
1133 *
1134 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001135void MACvSetCurrTx0DescAddrEx(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -04001136{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001137 unsigned short ww;
1138 unsigned char byData;
1139 unsigned char byOrgDMACtl;
Forest Bond5449c682009-04-25 10:30:44 -04001140
Joe Perchesc3504bf2013-03-18 10:44:55 -07001141 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byOrgDMACtl);
1142 if (byOrgDMACtl & DMACTL_RUN) {
1143 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1144 }
1145 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1146 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1147 if (!(byData & DMACTL_RUN))
1148 break;
1149 }
1150 if (ww == W_MAX_TIMEOUT) {
1151 DBG_PORT80(0x25);
1152 }
1153 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
1154 if (byOrgDMACtl & DMACTL_RUN) {
1155 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN);
1156 }
Forest Bond5449c682009-04-25 10:30:44 -04001157}
1158
1159/*
1160 * Description:
1161 * Set the chip with current AC0 descriptor address
1162 *
1163 * Parameters:
1164 * In:
1165 * dwIoBase - Base Address for MAC
1166 * dwCurrDescAddr - Descriptor Address
1167 * Out:
1168 * none
1169 *
1170 * Return Value: none
1171 *
1172 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001173//TxDMA1 = AC0DMA
1174void MACvSetCurrAC0DescAddrEx(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -04001175{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001176 unsigned short ww;
1177 unsigned char byData;
1178 unsigned char byOrgDMACtl;
Forest Bond5449c682009-04-25 10:30:44 -04001179
Joe Perchesc3504bf2013-03-18 10:44:55 -07001180 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byOrgDMACtl);
1181 if (byOrgDMACtl & DMACTL_RUN) {
1182 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1183 }
1184 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1185 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1186 if (!(byData & DMACTL_RUN))
1187 break;
1188 }
1189 if (ww == W_MAX_TIMEOUT) {
1190 DBG_PORT80(0x26);
1191 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x26)\n");
1192 }
1193 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
1194 if (byOrgDMACtl & DMACTL_RUN) {
1195 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN);
1196 }
Forest Bond5449c682009-04-25 10:30:44 -04001197}
1198
Joe Perchesc3504bf2013-03-18 10:44:55 -07001199void MACvSetCurrTXDescAddr(int iTxType, unsigned long dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -04001200{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001201 if (iTxType == TYPE_AC0DMA) {
1202 MACvSetCurrAC0DescAddrEx(dwIoBase, dwCurrDescAddr);
1203 } else if (iTxType == TYPE_TXDMA0) {
1204 MACvSetCurrTx0DescAddrEx(dwIoBase, dwCurrDescAddr);
1205 }
Forest Bond5449c682009-04-25 10:30:44 -04001206}
1207
1208/*
1209 * Description:
1210 * Micro Second Delay via MAC
1211 *
1212 * Parameters:
1213 * In:
1214 * dwIoBase - Base Address for MAC
1215 * uDelay - Delay time (timer resolution is 4 us)
1216 * Out:
1217 * none
1218 *
1219 * Return Value: none
1220 *
1221 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001222void MACvTimer0MicroSDelay(unsigned long dwIoBase, unsigned int uDelay)
Forest Bond5449c682009-04-25 10:30:44 -04001223{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001224 unsigned char byValue;
1225 unsigned int uu, ii;
Forest Bond5449c682009-04-25 10:30:44 -04001226
Joe Perchesc3504bf2013-03-18 10:44:55 -07001227 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1228 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelay);
1229 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
1230 for (ii = 0; ii < 66; ii++) { // assume max PCI clock is 66Mhz
1231 for (uu = 0; uu < uDelay; uu++) {
1232 VNSvInPortB(dwIoBase + MAC_REG_TMCTL0, &byValue);
1233 if ((byValue == 0) ||
1234 (byValue & TMCTL_TSUSP)) {
1235 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1236 return;
1237 }
1238 }
1239 }
1240 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
Forest Bond5449c682009-04-25 10:30:44 -04001241}
1242
1243/*
1244 * Description:
1245 * Micro Second One shot timer via MAC
1246 *
1247 * Parameters:
1248 * In:
1249 * dwIoBase - Base Address for MAC
1250 * uDelay - Delay time
1251 * Out:
1252 * none
1253 *
1254 * Return Value: none
1255 *
1256 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001257void MACvOneShotTimer0MicroSec(unsigned long dwIoBase, unsigned int uDelayTime)
Forest Bond5449c682009-04-25 10:30:44 -04001258{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001259 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1260 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelayTime);
1261 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
Forest Bond5449c682009-04-25 10:30:44 -04001262}
1263
1264/*
1265 * Description:
1266 * Micro Second One shot timer via MAC
1267 *
1268 * Parameters:
1269 * In:
1270 * dwIoBase - Base Address for MAC
1271 * uDelay - Delay time
1272 * Out:
1273 * none
1274 *
1275 * Return Value: none
1276 *
1277 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001278void MACvOneShotTimer1MicroSec(unsigned long dwIoBase, unsigned int uDelayTime)
Forest Bond5449c682009-04-25 10:30:44 -04001279{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001280 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0);
1281 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA1, uDelayTime);
1282 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
Forest Bond5449c682009-04-25 10:30:44 -04001283}
1284
Joe Perchesc3504bf2013-03-18 10:44:55 -07001285void MACvSetMISCFifo(unsigned long dwIoBase, unsigned short wOffset, unsigned long dwData)
Forest Bond5449c682009-04-25 10:30:44 -04001286{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001287 if (wOffset > 273)
1288 return;
1289 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1290 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1291 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
Forest Bond5449c682009-04-25 10:30:44 -04001292}
1293
Joe Perchesc3504bf2013-03-18 10:44:55 -07001294bool MACbTxDMAOff(unsigned long dwIoBase, unsigned int idx)
Forest Bond5449c682009-04-25 10:30:44 -04001295{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001296 unsigned char byData;
1297 unsigned int ww = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001298
Joe Perchesc3504bf2013-03-18 10:44:55 -07001299 if (idx == TYPE_TXDMA0) {
1300 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1301 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1302 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1303 if (!(byData & DMACTL_RUN))
1304 break;
1305 }
1306 } else if (idx == TYPE_AC0DMA) {
1307 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1308 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1309 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1310 if (!(byData & DMACTL_RUN))
1311 break;
1312 }
1313 }
1314 if (ww == W_MAX_TIMEOUT) {
1315 DBG_PORT80(0x29);
1316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x29)\n");
1317 return false;
1318 }
1319 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001320}
1321
Joe Perchesc3504bf2013-03-18 10:44:55 -07001322void MACvClearBusSusInd(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -04001323{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001324 unsigned long dwOrgValue;
1325 unsigned int ww;
1326 // check if BcnSusInd enabled
1327 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1328 if (!(dwOrgValue & EnCFG_BcnSusInd))
1329 return;
1330 //Set BcnSusClr
1331 dwOrgValue = dwOrgValue | EnCFG_BcnSusClr;
1332 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);
1333 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1334 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1335 if (!(dwOrgValue & EnCFG_BcnSusInd))
1336 break;
1337 }
1338 if (ww == W_MAX_TIMEOUT) {
1339 DBG_PORT80(0x33);
1340 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
1341 }
Forest Bond5449c682009-04-25 10:30:44 -04001342}
1343
Joe Perchesc3504bf2013-03-18 10:44:55 -07001344void MACvEnableBusSusEn(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -04001345{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001346 unsigned char byOrgValue;
1347 unsigned long dwOrgValue;
1348 unsigned int ww;
1349 // check if BcnSusInd enabled
1350 VNSvInPortB(dwIoBase + MAC_REG_CFG , &byOrgValue);
Forest Bond5449c682009-04-25 10:30:44 -04001351
Joe Perchesc3504bf2013-03-18 10:44:55 -07001352 //Set BcnSusEn
1353 byOrgValue = byOrgValue | CFG_BCNSUSEN;
1354 VNSvOutPortB(dwIoBase + MAC_REG_ENCFG, byOrgValue);
1355 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1356 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1357 if (dwOrgValue & EnCFG_BcnSusInd)
1358 break;
1359 }
1360 if (ww == W_MAX_TIMEOUT) {
1361 DBG_PORT80(0x34);
1362 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x34)\n");
1363 }
Forest Bond5449c682009-04-25 10:30:44 -04001364}
1365
Joe Perchesc3504bf2013-03-18 10:44:55 -07001366bool MACbFlushSYNCFifo(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -04001367{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001368 unsigned char byOrgValue;
1369 unsigned int ww;
1370 // Read MACCR
1371 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
Forest Bond5449c682009-04-25 10:30:44 -04001372
Joe Perchesc3504bf2013-03-18 10:44:55 -07001373 // Set SYNCFLUSH
1374 byOrgValue = byOrgValue | MACCR_SYNCFLUSH;
1375 VNSvOutPortB(dwIoBase + MAC_REG_MACCR, byOrgValue);
Forest Bond5449c682009-04-25 10:30:44 -04001376
Joe Perchesc3504bf2013-03-18 10:44:55 -07001377 // Check if SyncFlushOK
1378 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1379 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1380 if (byOrgValue & MACCR_SYNCFLUSHOK)
1381 break;
1382 }
1383 if (ww == W_MAX_TIMEOUT) {
1384 DBG_PORT80(0x35);
1385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
1386 }
1387 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001388}
1389
Joe Perchesc3504bf2013-03-18 10:44:55 -07001390bool MACbPSWakeup(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -04001391{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001392 unsigned char byOrgValue;
1393 unsigned int ww;
1394 // Read PSCTL
1395 if (MACbIsRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PS)) {
1396 return true;
1397 }
1398 // Disable PS
1399 MACvRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond5449c682009-04-25 10:30:44 -04001400
Joe Perchesc3504bf2013-03-18 10:44:55 -07001401 // Check if SyncFlushOK
1402 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1403 VNSvInPortB(dwIoBase + MAC_REG_PSCTL , &byOrgValue);
1404 if (byOrgValue & PSCTL_WAKEDONE)
1405 break;
1406 }
1407 if (ww == W_MAX_TIMEOUT) {
1408 DBG_PORT80(0x36);
1409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
1410 return false;
1411 }
1412 return true;
Forest Bond5449c682009-04-25 10:30:44 -04001413}
1414
1415/*
1416 * Description:
1417 * Set the Key by MISCFIFO
1418 *
1419 * Parameters:
1420 * In:
1421 * dwIoBase - Base Address for MAC
1422 *
1423 * Out:
1424 * none
1425 *
1426 * Return Value: none
1427 *
1428 */
1429
Joe Perchesc3504bf2013-03-18 10:44:55 -07001430void MACvSetKeyEntry(unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx,
1431 unsigned int uKeyIdx, unsigned char *pbyAddr, unsigned long *pdwKey, unsigned char byLocalID)
Forest Bond5449c682009-04-25 10:30:44 -04001432{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001433 unsigned short wOffset;
1434 unsigned long dwData;
1435 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001436
Joe Perchesc3504bf2013-03-18 10:44:55 -07001437 if (byLocalID <= 1)
1438 return;
Forest Bond5449c682009-04-25 10:30:44 -04001439
Joe Perchesc3504bf2013-03-18 10:44:55 -07001440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetKeyEntry\n");
1441 wOffset = MISCFIFO_KEYETRY0;
1442 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -04001443
Joe Perchesc3504bf2013-03-18 10:44:55 -07001444 dwData = 0;
1445 dwData |= wKeyCtl;
1446 dwData <<= 16;
1447 dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
1448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
Forest Bond5449c682009-04-25 10:30:44 -04001449
Joe Perchesc3504bf2013-03-18 10:44:55 -07001450 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1451 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1452 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1453 wOffset++;
Forest Bond5449c682009-04-25 10:30:44 -04001454
Joe Perchesc3504bf2013-03-18 10:44:55 -07001455 dwData = 0;
1456 dwData |= *(pbyAddr+3);
1457 dwData <<= 8;
1458 dwData |= *(pbyAddr+2);
1459 dwData <<= 8;
1460 dwData |= *(pbyAddr+1);
1461 dwData <<= 8;
1462 dwData |= *(pbyAddr+0);
1463 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "2. wOffset: %d, Data: %lX\n", wOffset, dwData);
Forest Bond5449c682009-04-25 10:30:44 -04001464
Joe Perchesc3504bf2013-03-18 10:44:55 -07001465 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1466 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1467 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1468 wOffset++;
Forest Bond5449c682009-04-25 10:30:44 -04001469
Joe Perchesc3504bf2013-03-18 10:44:55 -07001470 wOffset += (uKeyIdx * 4);
1471 for (ii = 0; ii < 4; ii++) {
1472 // always push 128 bits
1473 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1474 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1475 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1476 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1477 }
Forest Bond5449c682009-04-25 10:30:44 -04001478}
1479
Forest Bond5449c682009-04-25 10:30:44 -04001480/*
1481 * Description:
1482 * Disable the Key Entry by MISCFIFO
1483 *
1484 * Parameters:
1485 * In:
1486 * dwIoBase - Base Address for MAC
1487 *
1488 * Out:
1489 * none
1490 *
1491 * Return Value: none
1492 *
1493 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001494void MACvDisableKeyEntry(unsigned long dwIoBase, unsigned int uEntryIdx)
Forest Bond5449c682009-04-25 10:30:44 -04001495{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001496 unsigned short wOffset;
Forest Bond5449c682009-04-25 10:30:44 -04001497
Joe Perchesc3504bf2013-03-18 10:44:55 -07001498 wOffset = MISCFIFO_KEYETRY0;
1499 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -04001500
Joe Perchesc3504bf2013-03-18 10:44:55 -07001501 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1502 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
1503 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
Forest Bond5449c682009-04-25 10:30:44 -04001504}
1505
Forest Bond5449c682009-04-25 10:30:44 -04001506/*
1507 * Description:
1508 * Set the default Key (KeyEntry[10]) by MISCFIFO
1509 *
1510 * Parameters:
1511 * In:
1512 * dwIoBase - Base Address for MAC
1513 *
1514 * Out:
1515 * none
1516 *
1517 * Return Value: none
1518 *
1519 */
1520
Joe Perchesc3504bf2013-03-18 10:44:55 -07001521void MACvSetDefaultKeyEntry(unsigned long dwIoBase, unsigned int uKeyLen,
1522 unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
Forest Bond5449c682009-04-25 10:30:44 -04001523{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001524 unsigned short wOffset;
1525 unsigned long dwData;
1526 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001527
Joe Perchesc3504bf2013-03-18 10:44:55 -07001528 if (byLocalID <= 1)
1529 return;
Forest Bond5449c682009-04-25 10:30:44 -04001530
Joe Perchesc3504bf2013-03-18 10:44:55 -07001531 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetDefaultKeyEntry\n");
1532 wOffset = MISCFIFO_KEYETRY0;
1533 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -04001534
Joe Perchesc3504bf2013-03-18 10:44:55 -07001535 wOffset++;
1536 wOffset++;
1537 wOffset += (uKeyIdx * 4);
1538 // always push 128 bits
1539 for (ii = 0; ii < 3; ii++) {
1540 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1541 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1542 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1543 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1544 }
1545 dwData = *pdwKey;
1546 if (uKeyLen == WLAN_WEP104_KEYLEN) {
1547 dwData |= 0x80000000;
1548 }
1549 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+3);
1550 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1551 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "End. wOffset: %d, Data: %lX\n", wOffset+3, dwData);
Forest Bond5449c682009-04-25 10:30:44 -04001553}
1554
Forest Bond5449c682009-04-25 10:30:44 -04001555/*
1556 * Description:
1557 * Enable default Key (KeyEntry[10]) by MISCFIFO
1558 *
1559 * Parameters:
1560 * In:
1561 * dwIoBase - Base Address for MAC
1562 *
1563 * Out:
1564 * none
1565 *
1566 * Return Value: none
1567 *
1568 */
1569/*
Joe Perchesc3504bf2013-03-18 10:44:55 -07001570 void MACvEnableDefaultKey(unsigned long dwIoBase, unsigned char byLocalID)
1571 {
1572 unsigned short wOffset;
1573 unsigned long dwData;
Forest Bond5449c682009-04-25 10:30:44 -04001574
Joe Perchesc3504bf2013-03-18 10:44:55 -07001575 if (byLocalID <= 1)
1576 return;
Forest Bond5449c682009-04-25 10:30:44 -04001577
Joe Perchesc3504bf2013-03-18 10:44:55 -07001578 wOffset = MISCFIFO_KEYETRY0;
1579 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -04001580
Joe Perchesc3504bf2013-03-18 10:44:55 -07001581 dwData = 0xC0440000;
1582 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1583 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1584 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1585 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvEnableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
Forest Bond5449c682009-04-25 10:30:44 -04001586
Joe Perchesc3504bf2013-03-18 10:44:55 -07001587 }
Forest Bond5449c682009-04-25 10:30:44 -04001588*/
1589
1590/*
1591 * Description:
1592 * Disable default Key (KeyEntry[10]) by MISCFIFO
1593 *
1594 * Parameters:
1595 * In:
1596 * dwIoBase - Base Address for MAC
1597 *
1598 * Out:
1599 * none
1600 *
1601 * Return Value: none
1602 *
1603 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001604void MACvDisableDefaultKey(unsigned long dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -04001605{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001606 unsigned short wOffset;
1607 unsigned long dwData;
Forest Bond5449c682009-04-25 10:30:44 -04001608
Joe Perchesc3504bf2013-03-18 10:44:55 -07001609 wOffset = MISCFIFO_KEYETRY0;
1610 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -04001611
Joe Perchesc3504bf2013-03-18 10:44:55 -07001612 dwData = 0x0;
1613 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1614 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1615 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1616 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvDisableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
Forest Bond5449c682009-04-25 10:30:44 -04001617}
1618
1619/*
1620 * Description:
1621 * Set the default TKIP Group Key (KeyEntry[10]) by MISCFIFO
1622 *
1623 * Parameters:
1624 * In:
1625 * dwIoBase - Base Address for MAC
1626 *
1627 * Out:
1628 * none
1629 *
1630 * Return Value: none
1631 *
1632 */
Joe Perchesc3504bf2013-03-18 10:44:55 -07001633void MACvSetDefaultTKIPKeyEntry(unsigned long dwIoBase, unsigned int uKeyLen,
1634 unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
Forest Bond5449c682009-04-25 10:30:44 -04001635{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001636 unsigned short wOffset;
1637 unsigned long dwData;
1638 int ii;
Forest Bond5449c682009-04-25 10:30:44 -04001639
Joe Perchesc3504bf2013-03-18 10:44:55 -07001640 if (byLocalID <= 1)
1641 return;
Forest Bond5449c682009-04-25 10:30:44 -04001642
Joe Perchesc3504bf2013-03-18 10:44:55 -07001643 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetDefaultTKIPKeyEntry\n");
1644 wOffset = MISCFIFO_KEYETRY0;
1645 // Kyle test : change offset from 10 -> 0
1646 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -04001647
Joe Perchesc3504bf2013-03-18 10:44:55 -07001648 dwData = 0xC0660000;
1649 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1650 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1651 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1652 wOffset++;
Forest Bond5449c682009-04-25 10:30:44 -04001653
Joe Perchesc3504bf2013-03-18 10:44:55 -07001654 dwData = 0;
1655 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1656 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1657 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1658 wOffset++;
Forest Bond5449c682009-04-25 10:30:44 -04001659
Joe Perchesc3504bf2013-03-18 10:44:55 -07001660 wOffset += (uKeyIdx * 4);
1661 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %lX, idx:%d\n", wOffset, *pdwKey, uKeyIdx);
1662 // always push 128 bits
1663 for (ii = 0; ii < 4; ii++) {
1664 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "2.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1665 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1666 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1667 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1668 }
Forest Bond5449c682009-04-25 10:30:44 -04001669}
1670
Forest Bond5449c682009-04-25 10:30:44 -04001671/*
1672 * Description:
1673 * Set the Key Control by MISCFIFO
1674 *
1675 * Parameters:
1676 * In:
1677 * dwIoBase - Base Address for MAC
1678 *
1679 * Out:
1680 * none
1681 *
1682 * Return Value: none
1683 *
1684 */
1685
Joe Perchesc3504bf2013-03-18 10:44:55 -07001686void MACvSetDefaultKeyCtl(unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx, unsigned char byLocalID)
Forest Bond5449c682009-04-25 10:30:44 -04001687{
Joe Perchesc3504bf2013-03-18 10:44:55 -07001688 unsigned short wOffset;
1689 unsigned long dwData;
Forest Bond5449c682009-04-25 10:30:44 -04001690
Joe Perchesc3504bf2013-03-18 10:44:55 -07001691 if (byLocalID <= 1)
1692 return;
Forest Bond5449c682009-04-25 10:30:44 -04001693
Joe Perchesc3504bf2013-03-18 10:44:55 -07001694 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetKeyEntry\n");
1695 wOffset = MISCFIFO_KEYETRY0;
1696 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -04001697
Joe Perchesc3504bf2013-03-18 10:44:55 -07001698 dwData = 0;
1699 dwData |= wKeyCtl;
1700 dwData <<= 16;
1701 dwData |= 0xffff;
1702 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
Forest Bond5449c682009-04-25 10:30:44 -04001703
Joe Perchesc3504bf2013-03-18 10:44:55 -07001704 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1705 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1706 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
Forest Bond5449c682009-04-25 10:30:44 -04001707}