blob: 8f0d652fea7c4981065e9b5b3153cf810843e114 [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:
Forest Bond5449c682009-04-25 10:30:44 -040029 * MACbIsRegBitsOn - Test if All test Bits On
30 * MACbIsRegBitsOff - Test if All test Bits Off
31 * MACbIsIntDisable - Test if MAC interrupt disable
Forest Bond5449c682009-04-25 10:30:44 -040032 * MACvSetShortRetryLimit - Set 802.11 Short Retry limit
33 * MACvGetShortRetryLimit - Get 802.11 Short Retry limit
34 * MACvSetLongRetryLimit - Set 802.11 Long Retry limit
Forest Bond5449c682009-04-25 10:30:44 -040035 * MACvSetLoopbackMode - Set MAC Loopback Mode
Forest Bond5449c682009-04-25 10:30:44 -040036 * MACvSaveContext - Save Context of MAC Registers
37 * MACvRestoreContext - Restore Context of MAC Registers
Forest Bond5449c682009-04-25 10:30:44 -040038 * MACbSoftwareReset - Software Reset MAC
39 * MACbSafeRxOff - Turn Off MAC Rx
40 * MACbSafeTxOff - Turn Off MAC Tx
41 * MACbSafeStop - Stop MAC function
42 * MACbShutdown - Shut down MAC
43 * MACvInitialize - Initialize MAC
Justin P. Mattock789d1ae2012-08-20 08:43:13 -070044 * MACvSetCurrRxDescAddr - Set Rx Descriptors Address
45 * MACvSetCurrTx0DescAddr - Set Tx0 Descriptors Address
46 * MACvSetCurrTx1DescAddr - Set Tx1 Descriptors Address
Forest Bond5449c682009-04-25 10:30:44 -040047 * MACvTimer0MicroSDelay - Micro Second Delay Loop by MAC
48 *
49 * Revision History:
50 * 08-22-2003 Kyle Hsu : Porting MAC functions from sim53
51 * 09-03-2003 Bryan YC Fan : Add MACvClearBusSusInd()& MACvEnableBusSusEn()
52 * 09-18-2003 Jerry Chen : Add MACvSetKeyEntry & MACvDisableKeyEntry
53 *
54 */
55
Forest Bond5449c682009-04-25 10:30:44 -040056#include "tmacro.h"
Forest Bond5449c682009-04-25 10:30:44 -040057#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040058
Forest Bond5449c682009-04-25 10:30:44 -040059/*
60 * Description:
Forest Bond5449c682009-04-25 10:30:44 -040061 * Test if all test bits on
62 *
63 * Parameters:
64 * In:
65 * dwIoBase - Base Address for MAC
66 * byRegOfs - Offset of MAC Register
67 * byTestBits - Test bits
68 * Out:
69 * none
70 *
Charles Clément5a5a2a62010-08-01 17:15:49 +020071 * Return Value: true if all test bits On; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -040072 *
73 */
Guillaume Clement16834402014-07-22 22:08:26 +020074bool MACbIsRegBitsOn(void __iomem *dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
Forest Bond5449c682009-04-25 10:30:44 -040075{
Joe Perchesc3504bf2013-03-18 10:44:55 -070076 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -040077
Joe Perchesc3504bf2013-03-18 10:44:55 -070078 VNSvInPortB(dwIoBase + byRegOfs, &byData);
79 return (byData & byTestBits) == byTestBits;
Forest Bond5449c682009-04-25 10:30:44 -040080}
81
82/*
83 * Description:
84 * Test if all test bits off
85 *
86 * Parameters:
87 * In:
88 * dwIoBase - Base Address for MAC
89 * byRegOfs - Offset of MAC Register
90 * byTestBits - Test bits
91 * Out:
92 * none
93 *
Charles Clément5a5a2a62010-08-01 17:15:49 +020094 * Return Value: true if all test bits Off; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -040095 *
96 */
Guillaume Clement16834402014-07-22 22:08:26 +020097bool MACbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
Forest Bond5449c682009-04-25 10:30:44 -040098{
Joe Perchesc3504bf2013-03-18 10:44:55 -070099 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400100
Joe Perchesc3504bf2013-03-18 10:44:55 -0700101 VNSvInPortB(dwIoBase + byRegOfs, &byData);
102 return !(byData & byTestBits);
Forest Bond5449c682009-04-25 10:30:44 -0400103}
104
105/*
106 * Description:
107 * Test if MAC interrupt disable
108 *
109 * Parameters:
110 * In:
111 * dwIoBase - Base Address for MAC
112 * Out:
113 * none
114 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200115 * Return Value: true if interrupt is disable; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400116 *
117 */
Guillaume Clement16834402014-07-22 22:08:26 +0200118bool MACbIsIntDisable(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400119{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700120 unsigned long dwData;
Forest Bond5449c682009-04-25 10:30:44 -0400121
Joe Perchesc3504bf2013-03-18 10:44:55 -0700122 VNSvInPortD(dwIoBase + MAC_REG_IMR, &dwData);
123 if (dwData != 0)
124 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400125
Joe Perchesc3504bf2013-03-18 10:44:55 -0700126 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400127}
128
129/*
130 * Description:
Forest Bond5449c682009-04-25 10:30:44 -0400131 * Set 802.11 Short Retry Limit
132 *
133 * Parameters:
134 * In:
135 * dwIoBase - Base Address for MAC
136 * byRetryLimit- Retry Limit
137 * Out:
138 * none
139 *
140 * Return Value: none
141 *
142 */
Guillaume Clement16834402014-07-22 22:08:26 +0200143void MACvSetShortRetryLimit(void __iomem *dwIoBase, unsigned char byRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400144{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700145 // set SRT
146 VNSvOutPortB(dwIoBase + MAC_REG_SRT, byRetryLimit);
Forest Bond5449c682009-04-25 10:30:44 -0400147}
148
149/*
150 * Description:
151 * Get 802.11 Short Retry Limit
152 *
153 * Parameters:
154 * In:
155 * dwIoBase - Base Address for MAC
156 * Out:
157 * pbyRetryLimit - Retry Limit Get
158 *
159 * Return Value: none
160 *
161 */
Guillaume Clement16834402014-07-22 22:08:26 +0200162void MACvGetShortRetryLimit(void __iomem *dwIoBase, unsigned char *pbyRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400163{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700164 // get SRT
165 VNSvInPortB(dwIoBase + MAC_REG_SRT, pbyRetryLimit);
Forest Bond5449c682009-04-25 10:30:44 -0400166}
167
168/*
169 * Description:
170 * Set 802.11 Long Retry Limit
171 *
172 * Parameters:
173 * In:
174 * dwIoBase - Base Address for MAC
175 * byRetryLimit- Retry Limit
176 * Out:
177 * none
178 *
179 * Return Value: none
180 *
181 */
Guillaume Clement16834402014-07-22 22:08:26 +0200182void MACvSetLongRetryLimit(void __iomem *dwIoBase, unsigned char byRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400183{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700184 // set LRT
185 VNSvOutPortB(dwIoBase + MAC_REG_LRT, byRetryLimit);
Forest Bond5449c682009-04-25 10:30:44 -0400186}
187
188/*
189 * Description:
Forest Bond5449c682009-04-25 10:30:44 -0400190 * Set MAC Loopback mode
191 *
192 * Parameters:
193 * In:
194 * dwIoBase - Base Address for MAC
195 * byLoopbackMode - Loopback Mode
196 * Out:
197 * none
198 *
199 * Return Value: none
200 *
201 */
Guillaume Clement16834402014-07-22 22:08:26 +0200202void MACvSetLoopbackMode(void __iomem *dwIoBase, unsigned char byLoopbackMode)
Forest Bond5449c682009-04-25 10:30:44 -0400203{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700204 unsigned char byOrgValue;
Forest Bond5449c682009-04-25 10:30:44 -0400205
Joe Perchesc3504bf2013-03-18 10:44:55 -0700206 ASSERT(byLoopbackMode < 3);
207 byLoopbackMode <<= 6;
208 // set TCR
209 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
210 byOrgValue = byOrgValue & 0x3F;
211 byOrgValue = byOrgValue | byLoopbackMode;
212 VNSvOutPortB(dwIoBase + MAC_REG_TEST, byOrgValue);
Forest Bond5449c682009-04-25 10:30:44 -0400213}
214
215/*
216 * Description:
Forest Bond5449c682009-04-25 10:30:44 -0400217 * Save MAC registers to context buffer
218 *
219 * Parameters:
220 * In:
221 * dwIoBase - Base Address for MAC
222 * Out:
223 * pbyCxtBuf - Context buffer
224 *
225 * Return Value: none
226 *
227 */
Guillaume Clement16834402014-07-22 22:08:26 +0200228void MACvSaveContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf)
Forest Bond5449c682009-04-25 10:30:44 -0400229{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700230 int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400231
Joe Perchesc3504bf2013-03-18 10:44:55 -0700232 // read page0 register
Guido Martínezbc5cf652014-04-19 16:45:00 -0300233 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700234 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + ii));
Forest Bond5449c682009-04-25 10:30:44 -0400235
Joe Perchesc3504bf2013-03-18 10:44:55 -0700236 MACvSelectPage1(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400237
Joe Perchesc3504bf2013-03-18 10:44:55 -0700238 // read page1 register
Guido Martínezbc5cf652014-04-19 16:45:00 -0300239 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700240 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
Forest Bond5449c682009-04-25 10:30:44 -0400241
Joe Perchesc3504bf2013-03-18 10:44:55 -0700242 MACvSelectPage0(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400243}
244
245/*
246 * Description:
247 * Restore MAC registers from context buffer
248 *
249 * Parameters:
250 * In:
251 * dwIoBase - Base Address for MAC
252 * pbyCxtBuf - Context buffer
253 * Out:
254 * none
255 *
256 * Return Value: none
257 *
258 */
Guillaume Clement16834402014-07-22 22:08:26 +0200259void MACvRestoreContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf)
Forest Bond5449c682009-04-25 10:30:44 -0400260{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700261 int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400262
Joe Perchesc3504bf2013-03-18 10:44:55 -0700263 MACvSelectPage1(dwIoBase);
264 // restore page1
Guido Martínezbc5cf652014-04-19 16:45:00 -0300265 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700266 VNSvOutPortB((dwIoBase + ii), *(pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
Guido Martínezbc5cf652014-04-19 16:45:00 -0300267
Joe Perchesc3504bf2013-03-18 10:44:55 -0700268 MACvSelectPage0(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400269
Joe Perchesc3504bf2013-03-18 10:44:55 -0700270 // restore RCR,TCR,IMR...
Guido Martínezbc5cf652014-04-19 16:45:00 -0300271 for (ii = MAC_REG_RCR; ii < MAC_REG_ISR; ii++)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700272 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
Guido Martínezbc5cf652014-04-19 16:45:00 -0300273
Joe Perchesc3504bf2013-03-18 10:44:55 -0700274 // restore MAC Config.
Guido Martínezbc5cf652014-04-19 16:45:00 -0300275 for (ii = MAC_REG_LRT; ii < MAC_REG_PAGE1SEL; ii++)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700276 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
Guido Martínezbc5cf652014-04-19 16:45:00 -0300277
Joe Perchesc3504bf2013-03-18 10:44:55 -0700278 VNSvOutPortB(dwIoBase + MAC_REG_CFG, *(pbyCxtBuf + MAC_REG_CFG));
Forest Bond5449c682009-04-25 10:30:44 -0400279
Joe Perchesc3504bf2013-03-18 10:44:55 -0700280 // restore PS Config.
Guido Martínezbc5cf652014-04-19 16:45:00 -0300281 for (ii = MAC_REG_PSCFG; ii < MAC_REG_BBREGCTL; ii++)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700282 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
Forest Bond5449c682009-04-25 10:30:44 -0400283
Joe Perchesc3504bf2013-03-18 10:44:55 -0700284 // restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
285 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0));
286 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR));
287 VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_BCNDMAPTR));
Forest Bond5449c682009-04-25 10:30:44 -0400288
Joe Perchesc3504bf2013-03-18 10:44:55 -0700289 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0));
Forest Bond5449c682009-04-25 10:30:44 -0400290
Joe Perchesc3504bf2013-03-18 10:44:55 -0700291 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1));
Forest Bond5449c682009-04-25 10:30:44 -0400292}
293
294/*
295 * Description:
Forest Bond5449c682009-04-25 10:30:44 -0400296 * Software Reset MAC
297 *
298 * Parameters:
299 * In:
300 * dwIoBase - Base Address for MAC
301 * Out:
302 * none
303 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200304 * Return Value: true if Reset Success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400305 *
306 */
Guillaume Clement16834402014-07-22 22:08:26 +0200307bool MACbSoftwareReset(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400308{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700309 unsigned char byData;
310 unsigned short ww;
Forest Bond5449c682009-04-25 10:30:44 -0400311
Joe Perchesc3504bf2013-03-18 10:44:55 -0700312 // turn on HOSTCR_SOFTRST, just write 0x01 to reset
Joe Perchesc3504bf2013-03-18 10:44:55 -0700313 VNSvOutPortB(dwIoBase + MAC_REG_HOSTCR, 0x01);
Forest Bond5449c682009-04-25 10:30:44 -0400314
Joe Perchesc3504bf2013-03-18 10:44:55 -0700315 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
316 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
317 if (!(byData & HOSTCR_SOFTRST))
318 break;
319 }
320 if (ww == W_MAX_TIMEOUT)
321 return false;
322 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400323}
324
325/*
326 * Description:
327 * save some important register's value, then do reset, then restore register's value
328 *
329 * Parameters:
330 * In:
331 * dwIoBase - Base Address for MAC
332 * Out:
333 * none
334 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200335 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400336 *
337 */
Guillaume Clement16834402014-07-22 22:08:26 +0200338bool MACbSafeSoftwareReset(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400339{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700340 unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
341 bool bRetVal;
Forest Bond5449c682009-04-25 10:30:44 -0400342
Joe Perchesc3504bf2013-03-18 10:44:55 -0700343 // PATCH....
344 // save some important register's value, then do
345 // reset, then restore register's value
Forest Bond5449c682009-04-25 10:30:44 -0400346
Joe Perchesc3504bf2013-03-18 10:44:55 -0700347 // save MAC context
348 MACvSaveContext(dwIoBase, abyTmpRegData);
349 // do reset
350 bRetVal = MACbSoftwareReset(dwIoBase);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700351 // restore MAC context, except CR0
352 MACvRestoreContext(dwIoBase, abyTmpRegData);
Forest Bond5449c682009-04-25 10:30:44 -0400353
Joe Perchesc3504bf2013-03-18 10:44:55 -0700354 return bRetVal;
Forest Bond5449c682009-04-25 10:30:44 -0400355}
356
357/*
358 * Description:
359 * Trun Off MAC Rx
360 *
361 * Parameters:
362 * In:
363 * dwIoBase - Base Address for MAC
364 * Out:
365 * none
366 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200367 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400368 *
369 */
Guillaume Clement16834402014-07-22 22:08:26 +0200370bool MACbSafeRxOff(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400371{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700372 unsigned short ww;
373 unsigned long dwData;
374 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400375
Joe Perchesc3504bf2013-03-18 10:44:55 -0700376 // turn off wow temp for turn off Rx safely
Forest Bond5449c682009-04-25 10:30:44 -0400377
Joe Perchesc3504bf2013-03-18 10:44:55 -0700378 // Clear RX DMA0,1
379 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
380 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
381 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
382 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);
383 if (!(dwData & DMACTL_RUN))
384 break;
385 }
386 if (ww == W_MAX_TIMEOUT) {
387 DBG_PORT80(0x10);
Joe Perches48caf5a2014-08-17 09:17:04 -0700388 pr_debug(" DBG_PORT80(0x10)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700389 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700390 }
391 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
392 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);
393 if (!(dwData & DMACTL_RUN))
394 break;
395 }
396 if (ww == W_MAX_TIMEOUT) {
397 DBG_PORT80(0x11);
Joe Perches48caf5a2014-08-17 09:17:04 -0700398 pr_debug(" DBG_PORT80(0x11)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700399 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700400 }
Forest Bond5449c682009-04-25 10:30:44 -0400401
Joe Perchesc3504bf2013-03-18 10:44:55 -0700402 // try to safe shutdown RX
403 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON);
404 // W_MAX_TIMEOUT is the timeout period
405 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
406 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
407 if (!(byData & HOSTCR_RXONST))
408 break;
409 }
410 if (ww == W_MAX_TIMEOUT) {
411 DBG_PORT80(0x12);
Joe Perches48caf5a2014-08-17 09:17:04 -0700412 pr_debug(" DBG_PORT80(0x12)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700413 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700414 }
415 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400416}
417
418/*
419 * Description:
420 * Trun Off MAC Tx
421 *
422 * Parameters:
423 * In:
424 * dwIoBase - Base Address for MAC
425 * Out:
426 * none
427 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200428 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400429 *
430 */
Guillaume Clement16834402014-07-22 22:08:26 +0200431bool MACbSafeTxOff(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400432{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700433 unsigned short ww;
434 unsigned long dwData;
435 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400436
Joe Perchesc3504bf2013-03-18 10:44:55 -0700437 // Clear TX DMA
438 //Tx0
439 VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
440 //AC0
441 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
Forest Bond5449c682009-04-25 10:30:44 -0400442
Joe Perchesc3504bf2013-03-18 10:44:55 -0700443 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
444 VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);
445 if (!(dwData & DMACTL_RUN))
446 break;
447 }
448 if (ww == W_MAX_TIMEOUT) {
449 DBG_PORT80(0x20);
Joe Perches48caf5a2014-08-17 09:17:04 -0700450 pr_debug(" DBG_PORT80(0x20)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700451 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700452 }
453 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
454 VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);
455 if (!(dwData & DMACTL_RUN))
456 break;
457 }
458 if (ww == W_MAX_TIMEOUT) {
459 DBG_PORT80(0x21);
Joe Perches48caf5a2014-08-17 09:17:04 -0700460 pr_debug(" DBG_PORT80(0x21)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700461 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700462 }
Forest Bond5449c682009-04-25 10:30:44 -0400463
Joe Perchesc3504bf2013-03-18 10:44:55 -0700464 // try to safe shutdown TX
465 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON);
Forest Bond5449c682009-04-25 10:30:44 -0400466
Joe Perchesc3504bf2013-03-18 10:44:55 -0700467 // W_MAX_TIMEOUT is the timeout period
468 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
469 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
470 if (!(byData & HOSTCR_TXONST))
471 break;
472 }
473 if (ww == W_MAX_TIMEOUT) {
474 DBG_PORT80(0x24);
Joe Perches48caf5a2014-08-17 09:17:04 -0700475 pr_debug(" DBG_PORT80(0x24)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700476 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700477 }
478 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400479}
480
481/*
482 * Description:
483 * Stop MAC function
484 *
485 * Parameters:
486 * In:
487 * dwIoBase - Base Address for MAC
488 * Out:
489 * none
490 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200491 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400492 *
493 */
Guillaume Clement16834402014-07-22 22:08:26 +0200494bool MACbSafeStop(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400495{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700496 MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX);
Forest Bond5449c682009-04-25 10:30:44 -0400497
Teodora Baluta1208f142013-11-10 17:12:42 +0200498 if (!MACbSafeRxOff(dwIoBase)) {
Joe Perchesc3504bf2013-03-18 10:44:55 -0700499 DBG_PORT80(0xA1);
Joe Perches48caf5a2014-08-17 09:17:04 -0700500 pr_debug(" MACbSafeRxOff == false)\n");
Joe Perchesc3504bf2013-03-18 10:44:55 -0700501 MACbSafeSoftwareReset(dwIoBase);
502 return false;
503 }
Teodora Baluta1208f142013-11-10 17:12:42 +0200504 if (!MACbSafeTxOff(dwIoBase)) {
Joe Perchesc3504bf2013-03-18 10:44:55 -0700505 DBG_PORT80(0xA2);
Joe Perches48caf5a2014-08-17 09:17:04 -0700506 pr_debug(" MACbSafeTxOff == false)\n");
Joe Perchesc3504bf2013-03-18 10:44:55 -0700507 MACbSafeSoftwareReset(dwIoBase);
508 return false;
509 }
Forest Bond5449c682009-04-25 10:30:44 -0400510
Joe Perchesc3504bf2013-03-18 10:44:55 -0700511 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_MACEN);
Forest Bond5449c682009-04-25 10:30:44 -0400512
Joe Perchesc3504bf2013-03-18 10:44:55 -0700513 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400514}
515
516/*
517 * Description:
518 * Shut Down MAC
519 *
520 * Parameters:
521 * In:
522 * dwIoBase - Base Address for MAC
523 * Out:
524 * none
525 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200526 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400527 *
528 */
Guillaume Clement16834402014-07-22 22:08:26 +0200529bool MACbShutdown(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400530{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700531 // disable MAC IMR
532 MACvIntDisable(dwIoBase);
533 MACvSetLoopbackMode(dwIoBase, MAC_LB_INTERNAL);
534 // stop the adapter
535 if (!MACbSafeStop(dwIoBase)) {
536 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
537 return false;
538 }
539 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
540 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400541}
542
543/*
544 * Description:
545 * Initialize MAC
546 *
547 * Parameters:
548 * In:
549 * dwIoBase - Base Address for MAC
550 * Out:
551 * none
552 *
553 * Return Value: none
554 *
555 */
Guillaume Clement16834402014-07-22 22:08:26 +0200556void MACvInitialize(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400557{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700558 // clear sticky bits
559 MACvClearStckDS(dwIoBase);
560 // disable force PME-enable
561 VNSvOutPortB(dwIoBase + MAC_REG_PMC1, PME_OVR);
562 // only 3253 A
Forest Bond5449c682009-04-25 10:30:44 -0400563
Joe Perchesc3504bf2013-03-18 10:44:55 -0700564 // do reset
565 MACbSoftwareReset(dwIoBase);
Forest Bond5449c682009-04-25 10:30:44 -0400566
Joe Perchesc3504bf2013-03-18 10:44:55 -0700567 // reset TSF counter
568 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
569 // enable TSF counter
570 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
Forest Bond5449c682009-04-25 10:30:44 -0400571}
572
573/*
574 * Description:
575 * Set the chip with current rx descriptor address
576 *
577 * Parameters:
578 * In:
579 * dwIoBase - Base Address for MAC
580 * dwCurrDescAddr - Descriptor Address
581 * Out:
582 * none
583 *
584 * Return Value: none
585 *
586 */
Guillaume Clement16834402014-07-22 22:08:26 +0200587void MACvSetCurrRx0DescAddr(void __iomem *dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -0400588{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700589 unsigned short ww;
590 unsigned char byData;
591 unsigned char byOrgDMACtl;
Forest Bond5449c682009-04-25 10:30:44 -0400592
Joe Perchesc3504bf2013-03-18 10:44:55 -0700593 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byOrgDMACtl);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300594 if (byOrgDMACtl & DMACTL_RUN)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700595 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300596
Joe Perchesc3504bf2013-03-18 10:44:55 -0700597 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
598 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byData);
599 if (!(byData & DMACTL_RUN))
600 break;
601 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300602
603 if (ww == W_MAX_TIMEOUT)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700604 DBG_PORT80(0x13);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300605
Joe Perchesc3504bf2013-03-18 10:44:55 -0700606 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300607 if (byOrgDMACtl & DMACTL_RUN)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700608 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN);
Forest Bond5449c682009-04-25 10:30:44 -0400609}
610
611/*
612 * Description:
613 * Set the chip with current rx descriptor address
614 *
615 * Parameters:
616 * In:
617 * dwIoBase - Base Address for MAC
618 * dwCurrDescAddr - Descriptor Address
619 * Out:
620 * none
621 *
622 * Return Value: none
623 *
624 */
Guillaume Clement16834402014-07-22 22:08:26 +0200625void MACvSetCurrRx1DescAddr(void __iomem *dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -0400626{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700627 unsigned short ww;
628 unsigned char byData;
629 unsigned char byOrgDMACtl;
Forest Bond5449c682009-04-25 10:30:44 -0400630
Joe Perchesc3504bf2013-03-18 10:44:55 -0700631 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byOrgDMACtl);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300632 if (byOrgDMACtl & DMACTL_RUN)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700633 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300634
Joe Perchesc3504bf2013-03-18 10:44:55 -0700635 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
636 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byData);
637 if (!(byData & DMACTL_RUN))
638 break;
639 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300640 if (ww == W_MAX_TIMEOUT)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700641 DBG_PORT80(0x14);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300642
Joe Perchesc3504bf2013-03-18 10:44:55 -0700643 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300644 if (byOrgDMACtl & DMACTL_RUN)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700645 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300646
Forest Bond5449c682009-04-25 10:30:44 -0400647}
648
649/*
650 * Description:
651 * Set the chip with current tx0 descriptor address
652 *
653 * Parameters:
654 * In:
655 * dwIoBase - Base Address for MAC
656 * dwCurrDescAddr - Descriptor Address
657 * Out:
658 * none
659 *
660 * Return Value: none
661 *
662 */
Guillaume Clement16834402014-07-22 22:08:26 +0200663void MACvSetCurrTx0DescAddrEx(void __iomem *dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -0400664{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700665 unsigned short ww;
666 unsigned char byData;
667 unsigned char byOrgDMACtl;
Forest Bond5449c682009-04-25 10:30:44 -0400668
Joe Perchesc3504bf2013-03-18 10:44:55 -0700669 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byOrgDMACtl);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300670 if (byOrgDMACtl & DMACTL_RUN)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700671 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300672
Joe Perchesc3504bf2013-03-18 10:44:55 -0700673 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
674 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
675 if (!(byData & DMACTL_RUN))
676 break;
677 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300678 if (ww == W_MAX_TIMEOUT)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700679 DBG_PORT80(0x25);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300680
Joe Perchesc3504bf2013-03-18 10:44:55 -0700681 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300682 if (byOrgDMACtl & DMACTL_RUN)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700683 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN);
Forest Bond5449c682009-04-25 10:30:44 -0400684}
685
686/*
687 * Description:
688 * Set the chip with current AC0 descriptor address
689 *
690 * Parameters:
691 * In:
692 * dwIoBase - Base Address for MAC
693 * dwCurrDescAddr - Descriptor Address
694 * Out:
695 * none
696 *
697 * Return Value: none
698 *
699 */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700700//TxDMA1 = AC0DMA
Guillaume Clement16834402014-07-22 22:08:26 +0200701void MACvSetCurrAC0DescAddrEx(void __iomem *dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -0400702{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700703 unsigned short ww;
704 unsigned char byData;
705 unsigned char byOrgDMACtl;
Forest Bond5449c682009-04-25 10:30:44 -0400706
Joe Perchesc3504bf2013-03-18 10:44:55 -0700707 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byOrgDMACtl);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300708 if (byOrgDMACtl & DMACTL_RUN)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700709 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300710
Joe Perchesc3504bf2013-03-18 10:44:55 -0700711 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
712 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
713 if (!(byData & DMACTL_RUN))
714 break;
715 }
716 if (ww == W_MAX_TIMEOUT) {
717 DBG_PORT80(0x26);
Joe Perches48caf5a2014-08-17 09:17:04 -0700718 pr_debug(" DBG_PORT80(0x26)\n");
Joe Perchesc3504bf2013-03-18 10:44:55 -0700719 }
720 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300721 if (byOrgDMACtl & DMACTL_RUN)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700722 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN);
Forest Bond5449c682009-04-25 10:30:44 -0400723}
724
Guillaume Clement16834402014-07-22 22:08:26 +0200725void MACvSetCurrTXDescAddr(int iTxType, void __iomem *dwIoBase, unsigned long dwCurrDescAddr)
Forest Bond5449c682009-04-25 10:30:44 -0400726{
Guido Martínezbc5cf652014-04-19 16:45:00 -0300727 if (iTxType == TYPE_AC0DMA)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700728 MACvSetCurrAC0DescAddrEx(dwIoBase, dwCurrDescAddr);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300729 else if (iTxType == TYPE_TXDMA0)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700730 MACvSetCurrTx0DescAddrEx(dwIoBase, dwCurrDescAddr);
Forest Bond5449c682009-04-25 10:30:44 -0400731}
732
733/*
734 * Description:
735 * Micro Second Delay via MAC
736 *
737 * Parameters:
738 * In:
739 * dwIoBase - Base Address for MAC
740 * uDelay - Delay time (timer resolution is 4 us)
741 * Out:
742 * none
743 *
744 * Return Value: none
745 *
746 */
Guillaume Clement16834402014-07-22 22:08:26 +0200747void MACvTimer0MicroSDelay(void __iomem *dwIoBase, unsigned int uDelay)
Forest Bond5449c682009-04-25 10:30:44 -0400748{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700749 unsigned char byValue;
750 unsigned int uu, ii;
Forest Bond5449c682009-04-25 10:30:44 -0400751
Joe Perchesc3504bf2013-03-18 10:44:55 -0700752 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
753 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelay);
754 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
755 for (ii = 0; ii < 66; ii++) { // assume max PCI clock is 66Mhz
756 for (uu = 0; uu < uDelay; uu++) {
757 VNSvInPortB(dwIoBase + MAC_REG_TMCTL0, &byValue);
758 if ((byValue == 0) ||
759 (byValue & TMCTL_TSUSP)) {
760 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
761 return;
762 }
763 }
764 }
765 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
Forest Bond5449c682009-04-25 10:30:44 -0400766}
767
768/*
769 * Description:
770 * Micro Second One shot timer via MAC
771 *
772 * Parameters:
773 * In:
774 * dwIoBase - Base Address for MAC
775 * uDelay - Delay time
776 * Out:
777 * none
778 *
779 * Return Value: none
780 *
781 */
Guillaume Clement16834402014-07-22 22:08:26 +0200782void MACvOneShotTimer1MicroSec(void __iomem *dwIoBase, unsigned int uDelayTime)
Forest Bond5449c682009-04-25 10:30:44 -0400783{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700784 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0);
785 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA1, uDelayTime);
786 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
Forest Bond5449c682009-04-25 10:30:44 -0400787}
788
Guillaume Clement16834402014-07-22 22:08:26 +0200789void MACvSetMISCFifo(void __iomem *dwIoBase, unsigned short wOffset, unsigned long dwData)
Forest Bond5449c682009-04-25 10:30:44 -0400790{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700791 if (wOffset > 273)
792 return;
793 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
794 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
795 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
Forest Bond5449c682009-04-25 10:30:44 -0400796}
797
Guillaume Clement16834402014-07-22 22:08:26 +0200798bool MACbPSWakeup(void __iomem *dwIoBase)
Forest Bond5449c682009-04-25 10:30:44 -0400799{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700800 unsigned char byOrgValue;
801 unsigned int ww;
802 // Read PSCTL
Guido Martínezbc5cf652014-04-19 16:45:00 -0300803 if (MACbIsRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PS))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700804 return true;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300805
Joe Perchesc3504bf2013-03-18 10:44:55 -0700806 // Disable PS
807 MACvRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond5449c682009-04-25 10:30:44 -0400808
Joe Perchesc3504bf2013-03-18 10:44:55 -0700809 // Check if SyncFlushOK
810 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
811 VNSvInPortB(dwIoBase + MAC_REG_PSCTL , &byOrgValue);
812 if (byOrgValue & PSCTL_WAKEDONE)
813 break;
814 }
815 if (ww == W_MAX_TIMEOUT) {
816 DBG_PORT80(0x36);
Joe Perches48caf5a2014-08-17 09:17:04 -0700817 pr_debug(" DBG_PORT80(0x33)\n");
Joe Perchesc3504bf2013-03-18 10:44:55 -0700818 return false;
819 }
820 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400821}
822
823/*
824 * Description:
825 * Set the Key by MISCFIFO
826 *
827 * Parameters:
828 * In:
829 * dwIoBase - Base Address for MAC
830 *
831 * Out:
832 * none
833 *
834 * Return Value: none
835 *
836 */
837
Guillaume Clement16834402014-07-22 22:08:26 +0200838void MACvSetKeyEntry(void __iomem *dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx,
Malcolm Priestley4dbc77c2014-03-06 22:44:22 +0000839 unsigned int uKeyIdx, unsigned char *pbyAddr, u32 *pdwKey, unsigned char byLocalID)
Forest Bond5449c682009-04-25 10:30:44 -0400840{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700841 unsigned short wOffset;
Malcolm Priestley4dbc77c2014-03-06 22:44:22 +0000842 u32 dwData;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700843 int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400844
Joe Perchesc3504bf2013-03-18 10:44:55 -0700845 if (byLocalID <= 1)
846 return;
Forest Bond5449c682009-04-25 10:30:44 -0400847
Joe Perches48caf5a2014-08-17 09:17:04 -0700848 pr_debug("MACvSetKeyEntry\n");
Joe Perchesc3504bf2013-03-18 10:44:55 -0700849 wOffset = MISCFIFO_KEYETRY0;
850 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -0400851
Joe Perchesc3504bf2013-03-18 10:44:55 -0700852 dwData = 0;
853 dwData |= wKeyCtl;
854 dwData <<= 16;
855 dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
Joe Perches48caf5a2014-08-17 09:17:04 -0700856 pr_debug("1. wOffset: %d, Data: %X, KeyCtl:%X\n",
857 wOffset, dwData, wKeyCtl);
Forest Bond5449c682009-04-25 10:30:44 -0400858
Joe Perchesc3504bf2013-03-18 10:44:55 -0700859 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
860 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
861 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
862 wOffset++;
Forest Bond5449c682009-04-25 10:30:44 -0400863
Joe Perchesc3504bf2013-03-18 10:44:55 -0700864 dwData = 0;
865 dwData |= *(pbyAddr+3);
866 dwData <<= 8;
867 dwData |= *(pbyAddr+2);
868 dwData <<= 8;
869 dwData |= *(pbyAddr+1);
870 dwData <<= 8;
871 dwData |= *(pbyAddr+0);
Joe Perches48caf5a2014-08-17 09:17:04 -0700872 pr_debug("2. wOffset: %d, Data: %X\n", wOffset, dwData);
Forest Bond5449c682009-04-25 10:30:44 -0400873
Joe Perchesc3504bf2013-03-18 10:44:55 -0700874 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
875 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
876 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
877 wOffset++;
Forest Bond5449c682009-04-25 10:30:44 -0400878
Joe Perchesc3504bf2013-03-18 10:44:55 -0700879 wOffset += (uKeyIdx * 4);
880 for (ii = 0; ii < 4; ii++) {
881 // always push 128 bits
Joe Perches48caf5a2014-08-17 09:17:04 -0700882 pr_debug("3.(%d) wOffset: %d, Data: %X\n",
883 ii, wOffset+ii, *pdwKey);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700884 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
885 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
886 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
887 }
Forest Bond5449c682009-04-25 10:30:44 -0400888}
889
Forest Bond5449c682009-04-25 10:30:44 -0400890/*
891 * Description:
892 * Disable the Key Entry by MISCFIFO
893 *
894 * Parameters:
895 * In:
896 * dwIoBase - Base Address for MAC
897 *
898 * Out:
899 * none
900 *
901 * Return Value: none
902 *
903 */
Guillaume Clement16834402014-07-22 22:08:26 +0200904void MACvDisableKeyEntry(void __iomem *dwIoBase, unsigned int uEntryIdx)
Forest Bond5449c682009-04-25 10:30:44 -0400905{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700906 unsigned short wOffset;
Forest Bond5449c682009-04-25 10:30:44 -0400907
Joe Perchesc3504bf2013-03-18 10:44:55 -0700908 wOffset = MISCFIFO_KEYETRY0;
909 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -0400910
Joe Perchesc3504bf2013-03-18 10:44:55 -0700911 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
912 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
913 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
Forest Bond5449c682009-04-25 10:30:44 -0400914}