blob: 8e13f7f414151b032c918033186099d7eba36b4c [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
Forest Bond5449c682009-04-25 10:30:44 -040033 * MACvSetLongRetryLimit - Set 802.11 Long Retry limit
Forest Bond5449c682009-04-25 10:30:44 -040034 * MACvSetLoopbackMode - Set MAC Loopback Mode
Forest Bond5449c682009-04-25 10:30:44 -040035 * MACvSaveContext - Save Context of MAC Registers
36 * MACvRestoreContext - Restore Context of MAC Registers
Forest Bond5449c682009-04-25 10:30:44 -040037 * MACbSoftwareReset - Software Reset MAC
38 * MACbSafeRxOff - Turn Off MAC Rx
39 * MACbSafeTxOff - Turn Off MAC Tx
40 * MACbSafeStop - Stop MAC function
41 * MACbShutdown - Shut down MAC
42 * MACvInitialize - Initialize MAC
Justin P. Mattock789d1ae2012-08-20 08:43:13 -070043 * MACvSetCurrRxDescAddr - Set Rx Descriptors Address
44 * MACvSetCurrTx0DescAddr - Set Tx0 Descriptors Address
45 * MACvSetCurrTx1DescAddr - Set Tx1 Descriptors Address
Forest Bond5449c682009-04-25 10:30:44 -040046 * MACvTimer0MicroSDelay - Micro Second Delay Loop by MAC
47 *
48 * Revision History:
49 * 08-22-2003 Kyle Hsu : Porting MAC functions from sim53
Kathryn Hampton5150d012016-03-15 18:16:24 -070050 * 09-03-2003 Bryan YC Fan : Add MACvClearBusSusInd()&
51 * MACvEnableBusSusEn()
Forest Bond5449c682009-04-25 10:30:44 -040052 * 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:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +000065 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -040066 * 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 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +000074bool MACbIsRegBitsOn(struct vnt_private *priv, unsigned char byRegOfs,
Guillaume Brogid4855fe2015-04-26 14:40:23 +020075 unsigned char byTestBits)
Forest Bond5449c682009-04-25 10:30:44 -040076{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +000077 void __iomem *io_base = priv->PortOffset;
Forest Bond5449c682009-04-25 10:30:44 -040078
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +000079 return (ioread8(io_base + byRegOfs) & 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:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +000088 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -040089 * 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 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +000097bool MACbIsRegBitsOff(struct vnt_private *priv, unsigned char byRegOfs,
Guillaume Brogid4855fe2015-04-26 14:40:23 +020098 unsigned char byTestBits)
Forest Bond5449c682009-04-25 10:30:44 -040099{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000100 void __iomem *io_base = priv->PortOffset;
Forest Bond5449c682009-04-25 10:30:44 -0400101
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +0000102 return !(ioread8(io_base + byRegOfs) & byTestBits);
Forest Bond5449c682009-04-25 10:30:44 -0400103}
104
105/*
106 * Description:
107 * Test if MAC interrupt disable
108 *
109 * Parameters:
110 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000111 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400112 * 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 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000118bool MACbIsIntDisable(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400119{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000120 void __iomem *io_base = priv->PortOffset;
Forest Bond5449c682009-04-25 10:30:44 -0400121
Malcolm Priestleye52ab0e2016-02-28 19:02:56 +0000122 if (ioread32(io_base + MAC_REG_IMR))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700123 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400124
Joe Perchesc3504bf2013-03-18 10:44:55 -0700125 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400126}
127
128/*
129 * Description:
Forest Bond5449c682009-04-25 10:30:44 -0400130 * Set 802.11 Short Retry Limit
131 *
132 * Parameters:
133 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000134 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400135 * byRetryLimit- Retry Limit
136 * Out:
137 * none
138 *
139 * Return Value: none
140 *
141 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700142void MACvSetShortRetryLimit(struct vnt_private *priv,
143 unsigned char byRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400144{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000145 void __iomem *io_base = priv->PortOffset;
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100146 /* set SRT */
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000147 iowrite8(byRetryLimit, io_base + MAC_REG_SRT);
Forest Bond5449c682009-04-25 10:30:44 -0400148}
149
Forest Bond5449c682009-04-25 10:30:44 -0400150
151/*
152 * Description:
153 * Set 802.11 Long Retry Limit
154 *
155 * Parameters:
156 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000157 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400158 * byRetryLimit- Retry Limit
159 * Out:
160 * none
161 *
162 * Return Value: none
163 *
164 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700165void MACvSetLongRetryLimit(struct vnt_private *priv,
166 unsigned char byRetryLimit)
Forest Bond5449c682009-04-25 10:30:44 -0400167{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000168 void __iomem *io_base = priv->PortOffset;
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100169 /* set LRT */
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000170 iowrite8(byRetryLimit, io_base + MAC_REG_LRT);
Forest Bond5449c682009-04-25 10:30:44 -0400171}
172
173/*
174 * Description:
Forest Bond5449c682009-04-25 10:30:44 -0400175 * Set MAC Loopback mode
176 *
177 * Parameters:
178 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000179 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400180 * byLoopbackMode - Loopback Mode
181 * Out:
182 * none
183 *
184 * Return Value: none
185 *
186 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000187void MACvSetLoopbackMode(struct vnt_private *priv, unsigned char byLoopbackMode)
Forest Bond5449c682009-04-25 10:30:44 -0400188{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000189 void __iomem *io_base = priv->PortOffset;
Forest Bond5449c682009-04-25 10:30:44 -0400190
Joe Perchesc3504bf2013-03-18 10:44:55 -0700191 byLoopbackMode <<= 6;
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100192 /* set TCR */
Malcolm Priestley58fe2702016-03-06 12:57:07 +0000193 iowrite8((ioread8(io_base + MAC_REG_TEST) & 0x3f) | byLoopbackMode,
194 io_base + MAC_REG_TEST);
Forest Bond5449c682009-04-25 10:30:44 -0400195}
196
197/*
198 * Description:
Forest Bond5449c682009-04-25 10:30:44 -0400199 * Save MAC registers to context buffer
200 *
201 * Parameters:
202 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000203 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400204 * Out:
Malcolm Priestley70715012016-03-06 12:57:00 +0000205 * cxt_buf - Context buffer
Forest Bond5449c682009-04-25 10:30:44 -0400206 *
207 * Return Value: none
208 *
209 */
Malcolm Priestley70715012016-03-06 12:57:00 +0000210void MACvSaveContext(struct vnt_private *priv, unsigned char *cxt_buf)
Forest Bond5449c682009-04-25 10:30:44 -0400211{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000212 void __iomem *io_base = priv->PortOffset;
Forest Bond5449c682009-04-25 10:30:44 -0400213
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100214 /* read page0 register */
Malcolm Priestley70715012016-03-06 12:57:00 +0000215 memcpy_fromio(cxt_buf, io_base, MAC_MAX_CONTEXT_SIZE_PAGE0);
Forest Bond5449c682009-04-25 10:30:44 -0400216
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000217 MACvSelectPage1(io_base);
Forest Bond5449c682009-04-25 10:30:44 -0400218
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100219 /* read page1 register */
Malcolm Priestley70715012016-03-06 12:57:00 +0000220 memcpy_fromio(cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0, io_base,
Malcolm Priestley7e5120e2016-02-28 19:02:57 +0000221 MAC_MAX_CONTEXT_SIZE_PAGE1);
Forest Bond5449c682009-04-25 10:30:44 -0400222
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000223 MACvSelectPage0(io_base);
Forest Bond5449c682009-04-25 10:30:44 -0400224}
225
226/*
227 * Description:
228 * Restore MAC registers from context buffer
229 *
230 * Parameters:
231 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000232 * io_base - Base Address for MAC
Malcolm Priestley70715012016-03-06 12:57:00 +0000233 * cxt_buf - Context buffer
Forest Bond5449c682009-04-25 10:30:44 -0400234 * Out:
235 * none
236 *
237 * Return Value: none
238 *
239 */
Malcolm Priestley70715012016-03-06 12:57:00 +0000240void MACvRestoreContext(struct vnt_private *priv, unsigned char *cxt_buf)
Forest Bond5449c682009-04-25 10:30:44 -0400241{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000242 void __iomem *io_base = priv->PortOffset;
Forest Bond5449c682009-04-25 10:30:44 -0400243
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000244 MACvSelectPage1(io_base);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100245 /* restore page1 */
Malcolm Priestley46331952016-03-06 12:57:01 +0000246 memcpy_toio(io_base, cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0,
247 MAC_MAX_CONTEXT_SIZE_PAGE1);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300248
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000249 MACvSelectPage0(io_base);
Forest Bond5449c682009-04-25 10:30:44 -0400250
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100251 /* restore RCR,TCR,IMR... */
Malcolm Priestley46331952016-03-06 12:57:01 +0000252 memcpy_toio(io_base + MAC_REG_RCR, cxt_buf + MAC_REG_RCR,
253 MAC_REG_ISR - MAC_REG_RCR);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300254
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100255 /* restore MAC Config. */
Malcolm Priestley46331952016-03-06 12:57:01 +0000256 memcpy_toio(io_base + MAC_REG_LRT, cxt_buf + MAC_REG_LRT,
257 MAC_REG_PAGE1SEL - MAC_REG_LRT);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300258
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000259 iowrite8(*(cxt_buf + MAC_REG_CFG), io_base + MAC_REG_CFG);
Forest Bond5449c682009-04-25 10:30:44 -0400260
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100261 /* restore PS Config. */
Malcolm Priestley46331952016-03-06 12:57:01 +0000262 memcpy_toio(io_base + MAC_REG_PSCFG, cxt_buf + MAC_REG_PSCFG,
263 MAC_REG_BBREGCTL - MAC_REG_PSCFG);
Forest Bond5449c682009-04-25 10:30:44 -0400264
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100265 /* restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR */
Malcolm Priestleye2ad8e232016-03-06 12:57:03 +0000266 iowrite32(*(u32 *)(cxt_buf + MAC_REG_TXDMAPTR0),
267 io_base + MAC_REG_TXDMAPTR0);
268 iowrite32(*(u32 *)(cxt_buf + MAC_REG_AC0DMAPTR),
269 io_base + MAC_REG_AC0DMAPTR);
270 iowrite32(*(u32 *)(cxt_buf + MAC_REG_BCNDMAPTR),
271 io_base + MAC_REG_BCNDMAPTR);
272 iowrite32(*(u32 *)(cxt_buf + MAC_REG_RXDMAPTR0),
273 io_base + MAC_REG_RXDMAPTR0);
274 iowrite32(*(u32 *)(cxt_buf + MAC_REG_RXDMAPTR1),
275 io_base + MAC_REG_RXDMAPTR1);
Forest Bond5449c682009-04-25 10:30:44 -0400276}
277
278/*
279 * Description:
Forest Bond5449c682009-04-25 10:30:44 -0400280 * Software Reset MAC
281 *
282 * Parameters:
283 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000284 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400285 * Out:
286 * none
287 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200288 * Return Value: true if Reset Success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400289 *
290 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000291bool MACbSoftwareReset(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400292{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000293 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700294 unsigned short ww;
Forest Bond5449c682009-04-25 10:30:44 -0400295
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100296 /* turn on HOSTCR_SOFTRST, just write 0x01 to reset */
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000297 iowrite8(0x01, io_base + MAC_REG_HOSTCR);
Forest Bond5449c682009-04-25 10:30:44 -0400298
Joe Perchesc3504bf2013-03-18 10:44:55 -0700299 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +0000300 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_SOFTRST))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700301 break;
302 }
303 if (ww == W_MAX_TIMEOUT)
304 return false;
305 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400306}
307
308/*
309 * Description:
Kathryn Hampton5150d012016-03-15 18:16:24 -0700310 * save some important register's value, then do reset, then restore
311 * register's value
Forest Bond5449c682009-04-25 10:30:44 -0400312 *
313 * Parameters:
314 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000315 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400316 * Out:
317 * none
318 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200319 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400320 *
321 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000322bool MACbSafeSoftwareReset(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400323{
Joe Perchesc3504bf2013-03-18 10:44:55 -0700324 unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
325 bool bRetVal;
Forest Bond5449c682009-04-25 10:30:44 -0400326
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100327 /* PATCH....
328 * save some important register's value, then do
329 * reset, then restore register's value
330 */
331 /* save MAC context */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000332 MACvSaveContext(priv, abyTmpRegData);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100333 /* do reset */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000334 bRetVal = MACbSoftwareReset(priv);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100335 /* restore MAC context, except CR0 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000336 MACvRestoreContext(priv, abyTmpRegData);
Forest Bond5449c682009-04-25 10:30:44 -0400337
Joe Perchesc3504bf2013-03-18 10:44:55 -0700338 return bRetVal;
Forest Bond5449c682009-04-25 10:30:44 -0400339}
340
341/*
342 * Description:
Gustavo A. R. Silvab1797df2015-01-11 16:18:00 -0600343 * Turn Off MAC Rx
Forest Bond5449c682009-04-25 10:30:44 -0400344 *
345 * Parameters:
346 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000347 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400348 * Out:
349 * none
350 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200351 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400352 *
353 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000354bool MACbSafeRxOff(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400355{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000356 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700357 unsigned short ww;
Forest Bond5449c682009-04-25 10:30:44 -0400358
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100359 /* turn off wow temp for turn off Rx safely */
Forest Bond5449c682009-04-25 10:30:44 -0400360
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100361 /* Clear RX DMA0,1 */
Malcolm Priestleye2ad8e232016-03-06 12:57:03 +0000362 iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_RXDMACTL0);
363 iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_RXDMACTL1);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700364 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleye52ab0e2016-02-28 19:02:56 +0000365 if (!(ioread32(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700366 break;
367 }
368 if (ww == W_MAX_TIMEOUT) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700369 pr_debug(" DBG_PORT80(0x10)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700370 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700371 }
372 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleye52ab0e2016-02-28 19:02:56 +0000373 if (!(ioread32(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700374 break;
375 }
376 if (ww == W_MAX_TIMEOUT) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700377 pr_debug(" DBG_PORT80(0x11)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700378 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700379 }
Forest Bond5449c682009-04-25 10:30:44 -0400380
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100381 /* try to safe shutdown RX */
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000382 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_RXON);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100383 /* W_MAX_TIMEOUT is the timeout period */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700384 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +0000385 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_RXONST))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700386 break;
387 }
388 if (ww == W_MAX_TIMEOUT) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700389 pr_debug(" DBG_PORT80(0x12)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700390 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700391 }
392 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400393}
394
395/*
396 * Description:
Gustavo A. R. Silvab1797df2015-01-11 16:18:00 -0600397 * Turn Off MAC Tx
Forest Bond5449c682009-04-25 10:30:44 -0400398 *
399 * Parameters:
400 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000401 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400402 * Out:
403 * none
404 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200405 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400406 *
407 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000408bool MACbSafeTxOff(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400409{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000410 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700411 unsigned short ww;
Forest Bond5449c682009-04-25 10:30:44 -0400412
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100413 /* Clear TX DMA */
414 /* Tx0 */
Malcolm Priestleye2ad8e232016-03-06 12:57:03 +0000415 iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_TXDMACTL0);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100416 /* AC0 */
Malcolm Priestleye2ad8e232016-03-06 12:57:03 +0000417 iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_AC0DMACTL);
Forest Bond5449c682009-04-25 10:30:44 -0400418
Joe Perchesc3504bf2013-03-18 10:44:55 -0700419 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleye52ab0e2016-02-28 19:02:56 +0000420 if (!(ioread32(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700421 break;
422 }
423 if (ww == W_MAX_TIMEOUT) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700424 pr_debug(" DBG_PORT80(0x20)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700425 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700426 }
427 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleye52ab0e2016-02-28 19:02:56 +0000428 if (!(ioread32(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700429 break;
430 }
431 if (ww == W_MAX_TIMEOUT) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700432 pr_debug(" DBG_PORT80(0x21)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700433 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700434 }
Forest Bond5449c682009-04-25 10:30:44 -0400435
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100436 /* try to safe shutdown TX */
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000437 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_TXON);
Forest Bond5449c682009-04-25 10:30:44 -0400438
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100439 /* W_MAX_TIMEOUT is the timeout period */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700440 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +0000441 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_TXONST))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700442 break;
443 }
444 if (ww == W_MAX_TIMEOUT) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700445 pr_debug(" DBG_PORT80(0x24)\n");
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700446 return false;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700447 }
448 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400449}
450
451/*
452 * Description:
453 * Stop MAC function
454 *
455 * Parameters:
456 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000457 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400458 * Out:
459 * none
460 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200461 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400462 *
463 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000464bool MACbSafeStop(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400465{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000466 void __iomem *io_base = priv->PortOffset;
Janani Ravichandrane1c484d2016-02-15 00:15:12 -0500467
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000468 MACvRegBitsOff(io_base, MAC_REG_TCR, TCR_AUTOBCNTX);
Forest Bond5449c682009-04-25 10:30:44 -0400469
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000470 if (!MACbSafeRxOff(priv)) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700471 pr_debug(" MACbSafeRxOff == false)\n");
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000472 MACbSafeSoftwareReset(priv);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700473 return false;
474 }
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000475 if (!MACbSafeTxOff(priv)) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700476 pr_debug(" MACbSafeTxOff == false)\n");
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000477 MACbSafeSoftwareReset(priv);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700478 return false;
479 }
Forest Bond5449c682009-04-25 10:30:44 -0400480
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000481 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_MACEN);
Forest Bond5449c682009-04-25 10:30:44 -0400482
Joe Perchesc3504bf2013-03-18 10:44:55 -0700483 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400484}
485
486/*
487 * Description:
488 * Shut Down MAC
489 *
490 * Parameters:
491 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000492 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400493 * Out:
494 * none
495 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200496 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400497 *
498 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000499bool MACbShutdown(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400500{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000501 void __iomem *io_base = priv->PortOffset;
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100502 /* disable MAC IMR */
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000503 MACvIntDisable(io_base);
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000504 MACvSetLoopbackMode(priv, MAC_LB_INTERNAL);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100505 /* stop the adapter */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000506 if (!MACbSafeStop(priv)) {
507 MACvSetLoopbackMode(priv, MAC_LB_NONE);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700508 return false;
509 }
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000510 MACvSetLoopbackMode(priv, MAC_LB_NONE);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700511 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400512}
513
514/*
515 * Description:
516 * Initialize MAC
517 *
518 * Parameters:
519 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000520 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400521 * Out:
522 * none
523 *
524 * Return Value: none
525 *
526 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000527void MACvInitialize(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400528{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000529 void __iomem *io_base = priv->PortOffset;
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100530 /* clear sticky bits */
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000531 MACvClearStckDS(io_base);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100532 /* disable force PME-enable */
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000533 iowrite8(PME_OVR, io_base + MAC_REG_PMC1);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100534 /* only 3253 A */
Forest Bond5449c682009-04-25 10:30:44 -0400535
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100536 /* do reset */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000537 MACbSoftwareReset(priv);
Forest Bond5449c682009-04-25 10:30:44 -0400538
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100539 /* reset TSF counter */
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000540 iowrite8(TFTCTL_TSFCNTRST, io_base + MAC_REG_TFTCTL);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100541 /* enable TSF counter */
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000542 iowrite8(TFTCTL_TSFCNTREN, io_base + MAC_REG_TFTCTL);
Forest Bond5449c682009-04-25 10:30:44 -0400543}
544
545/*
546 * Description:
547 * Set the chip with current rx descriptor address
548 *
549 * Parameters:
550 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000551 * io_base - Base Address for MAC
Malcolm Priestley28029472016-03-06 12:57:09 +0000552 * curr_desc_addr - Descriptor Address
Forest Bond5449c682009-04-25 10:30:44 -0400553 * Out:
554 * none
555 *
556 * Return Value: none
557 *
558 */
Malcolm Priestley28029472016-03-06 12:57:09 +0000559void MACvSetCurrRx0DescAddr(struct vnt_private *priv, u32 curr_desc_addr)
Forest Bond5449c682009-04-25 10:30:44 -0400560{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000561 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700562 unsigned short ww;
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000563 unsigned char org_dma_ctl;
Forest Bond5449c682009-04-25 10:30:44 -0400564
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000565 org_dma_ctl = ioread8(io_base + MAC_REG_RXDMACTL0);
566 if (org_dma_ctl & DMACTL_RUN)
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000567 iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL0 + 2);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300568
Joe Perchesc3504bf2013-03-18 10:44:55 -0700569 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +0000570 if (!(ioread8(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700571 break;
572 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300573
Malcolm Priestley28029472016-03-06 12:57:09 +0000574 iowrite32(curr_desc_addr, io_base + MAC_REG_RXDMAPTR0);
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000575 if (org_dma_ctl & DMACTL_RUN)
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000576 iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL0);
Forest Bond5449c682009-04-25 10:30:44 -0400577}
578
579/*
580 * Description:
581 * Set the chip with current rx descriptor address
582 *
583 * Parameters:
584 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000585 * io_base - Base Address for MAC
Malcolm Priestley28029472016-03-06 12:57:09 +0000586 * curr_desc_addr - Descriptor Address
Forest Bond5449c682009-04-25 10:30:44 -0400587 * Out:
588 * none
589 *
590 * Return Value: none
591 *
592 */
Malcolm Priestley28029472016-03-06 12:57:09 +0000593void MACvSetCurrRx1DescAddr(struct vnt_private *priv, u32 curr_desc_addr)
Forest Bond5449c682009-04-25 10:30:44 -0400594{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000595 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700596 unsigned short ww;
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000597 unsigned char org_dma_ctl;
Forest Bond5449c682009-04-25 10:30:44 -0400598
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000599 org_dma_ctl = ioread8(io_base + MAC_REG_RXDMACTL1);
600 if (org_dma_ctl & DMACTL_RUN)
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000601 iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL1 + 2);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300602
Joe Perchesc3504bf2013-03-18 10:44:55 -0700603 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +0000604 if (!(ioread8(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700605 break;
606 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300607
Malcolm Priestley28029472016-03-06 12:57:09 +0000608 iowrite32(curr_desc_addr, io_base + MAC_REG_RXDMAPTR1);
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000609 if (org_dma_ctl & DMACTL_RUN)
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000610 iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL1);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300611
Forest Bond5449c682009-04-25 10:30:44 -0400612}
613
614/*
615 * Description:
616 * Set the chip with current tx0 descriptor address
617 *
618 * Parameters:
619 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000620 * io_base - Base Address for MAC
Malcolm Priestley28029472016-03-06 12:57:09 +0000621 * curr_desc_addr - Descriptor Address
Forest Bond5449c682009-04-25 10:30:44 -0400622 * Out:
623 * none
624 *
625 * Return Value: none
626 *
627 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000628void MACvSetCurrTx0DescAddrEx(struct vnt_private *priv,
Malcolm Priestley28029472016-03-06 12:57:09 +0000629 u32 curr_desc_addr)
Forest Bond5449c682009-04-25 10:30:44 -0400630{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000631 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700632 unsigned short ww;
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000633 unsigned char org_dma_ctl;
Forest Bond5449c682009-04-25 10:30:44 -0400634
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000635 org_dma_ctl = ioread8(io_base + MAC_REG_TXDMACTL0);
636 if (org_dma_ctl & DMACTL_RUN)
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000637 iowrite8(DMACTL_RUN, io_base + MAC_REG_TXDMACTL0 + 2);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300638
Joe Perchesc3504bf2013-03-18 10:44:55 -0700639 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +0000640 if (!(ioread8(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700641 break;
642 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300643
Malcolm Priestley28029472016-03-06 12:57:09 +0000644 iowrite32(curr_desc_addr, io_base + MAC_REG_TXDMAPTR0);
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000645 if (org_dma_ctl & DMACTL_RUN)
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000646 iowrite8(DMACTL_RUN, io_base + MAC_REG_TXDMACTL0);
Forest Bond5449c682009-04-25 10:30:44 -0400647}
648
649/*
650 * Description:
651 * Set the chip with current AC0 descriptor address
652 *
653 * Parameters:
654 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000655 * io_base - Base Address for MAC
Malcolm Priestley28029472016-03-06 12:57:09 +0000656 * curr_desc_addr - Descriptor Address
Forest Bond5449c682009-04-25 10:30:44 -0400657 * Out:
658 * none
659 *
660 * Return Value: none
661 *
662 */
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100663/* TxDMA1 = AC0DMA */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000664void MACvSetCurrAC0DescAddrEx(struct vnt_private *priv,
Malcolm Priestley28029472016-03-06 12:57:09 +0000665 u32 curr_desc_addr)
Forest Bond5449c682009-04-25 10:30:44 -0400666{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000667 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700668 unsigned short ww;
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000669 unsigned char org_dma_ctl;
Forest Bond5449c682009-04-25 10:30:44 -0400670
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000671 org_dma_ctl = ioread8(io_base + MAC_REG_AC0DMACTL);
672 if (org_dma_ctl & DMACTL_RUN)
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000673 iowrite8(DMACTL_RUN, io_base + MAC_REG_AC0DMACTL + 2);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300674
Joe Perchesc3504bf2013-03-18 10:44:55 -0700675 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleyf205e8d2016-02-28 19:02:55 +0000676 if (!(ioread8(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700677 break;
678 }
Shivani Bhardwaj4188e582015-10-12 23:14:15 +0530679 if (ww == W_MAX_TIMEOUT)
Joe Perches48caf5a2014-08-17 09:17:04 -0700680 pr_debug(" DBG_PORT80(0x26)\n");
Malcolm Priestley28029472016-03-06 12:57:09 +0000681 iowrite32(curr_desc_addr, io_base + MAC_REG_AC0DMAPTR);
Malcolm Priestleyebc9bd82016-03-06 12:57:10 +0000682 if (org_dma_ctl & DMACTL_RUN)
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000683 iowrite8(DMACTL_RUN, io_base + MAC_REG_AC0DMACTL);
Forest Bond5449c682009-04-25 10:30:44 -0400684}
685
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000686void MACvSetCurrTXDescAddr(int iTxType, struct vnt_private *priv,
Malcolm Priestley28029472016-03-06 12:57:09 +0000687 u32 curr_desc_addr)
Forest Bond5449c682009-04-25 10:30:44 -0400688{
Guido Martínezbc5cf652014-04-19 16:45:00 -0300689 if (iTxType == TYPE_AC0DMA)
Malcolm Priestley28029472016-03-06 12:57:09 +0000690 MACvSetCurrAC0DescAddrEx(priv, curr_desc_addr);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300691 else if (iTxType == TYPE_TXDMA0)
Malcolm Priestley28029472016-03-06 12:57:09 +0000692 MACvSetCurrTx0DescAddrEx(priv, curr_desc_addr);
Forest Bond5449c682009-04-25 10:30:44 -0400693}
694
695/*
696 * Description:
697 * Micro Second Delay via MAC
698 *
699 * Parameters:
700 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000701 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400702 * uDelay - Delay time (timer resolution is 4 us)
703 * Out:
704 * none
705 *
706 * Return Value: none
707 *
708 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000709void MACvTimer0MicroSDelay(struct vnt_private *priv, unsigned int uDelay)
Forest Bond5449c682009-04-25 10:30:44 -0400710{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000711 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700712 unsigned char byValue;
713 unsigned int uu, ii;
Forest Bond5449c682009-04-25 10:30:44 -0400714
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000715 iowrite8(0, io_base + MAC_REG_TMCTL0);
Malcolm Priestleye2ad8e232016-03-06 12:57:03 +0000716 iowrite32(uDelay, io_base + MAC_REG_TMDATA0);
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000717 iowrite8((TMCTL_TMD | TMCTL_TE), io_base + MAC_REG_TMCTL0);
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100718 for (ii = 0; ii < 66; ii++) { /* assume max PCI clock is 66Mhz */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700719 for (uu = 0; uu < uDelay; uu++) {
Malcolm Priestley17c4c512016-03-06 12:57:08 +0000720 byValue = ioread8(io_base + MAC_REG_TMCTL0);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700721 if ((byValue == 0) ||
722 (byValue & TMCTL_TSUSP)) {
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000723 iowrite8(0, io_base + MAC_REG_TMCTL0);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700724 return;
725 }
726 }
727 }
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000728 iowrite8(0, io_base + MAC_REG_TMCTL0);
Forest Bond5449c682009-04-25 10:30:44 -0400729}
730
731/*
732 * Description:
733 * Micro Second One shot timer via MAC
734 *
735 * Parameters:
736 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000737 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400738 * uDelay - Delay time
739 * Out:
740 * none
741 *
742 * Return Value: none
743 *
744 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700745void MACvOneShotTimer1MicroSec(struct vnt_private *priv,
746 unsigned int uDelayTime)
Forest Bond5449c682009-04-25 10:30:44 -0400747{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000748 void __iomem *io_base = priv->PortOffset;
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000749
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000750 iowrite8(0, io_base + MAC_REG_TMCTL1);
Malcolm Priestleye2ad8e232016-03-06 12:57:03 +0000751 iowrite32(uDelayTime, io_base + MAC_REG_TMDATA1);
Malcolm Priestley3b8eb642016-03-06 12:57:05 +0000752 iowrite8((TMCTL_TMD | TMCTL_TE), io_base + MAC_REG_TMCTL1);
Forest Bond5449c682009-04-25 10:30:44 -0400753}
754
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000755void MACvSetMISCFifo(struct vnt_private *priv, unsigned short offset,
Malcolm Priestleyefa21f92016-03-06 12:57:12 +0000756 u32 data)
Forest Bond5449c682009-04-25 10:30:44 -0400757{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000758 void __iomem *io_base = priv->PortOffset;
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000759
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000760 if (offset > 273)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700761 return;
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000762 iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
Malcolm Priestleyefa21f92016-03-06 12:57:12 +0000763 iowrite32(data, io_base + MAC_REG_MISCFFDATA);
Malcolm Priestley54a14e62016-03-06 12:57:04 +0000764 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
Forest Bond5449c682009-04-25 10:30:44 -0400765}
766
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000767bool MACbPSWakeup(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400768{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000769 void __iomem *io_base = priv->PortOffset;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700770 unsigned int ww;
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100771 /* Read PSCTL */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000772 if (MACbIsRegBitsOff(priv, MAC_REG_PSCTL, PSCTL_PS))
Joe Perchesc3504bf2013-03-18 10:44:55 -0700773 return true;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300774
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100775 /* Disable PS */
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000776 MACvRegBitsOff(io_base, MAC_REG_PSCTL, PSCTL_PSEN);
Forest Bond5449c682009-04-25 10:30:44 -0400777
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100778 /* Check if SyncFlushOK */
Joe Perchesc3504bf2013-03-18 10:44:55 -0700779 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Malcolm Priestleye2069392016-03-06 12:57:06 +0000780 if (ioread8(io_base + MAC_REG_PSCTL) & PSCTL_WAKEDONE)
Joe Perchesc3504bf2013-03-18 10:44:55 -0700781 break;
782 }
783 if (ww == W_MAX_TIMEOUT) {
Joe Perches48caf5a2014-08-17 09:17:04 -0700784 pr_debug(" DBG_PORT80(0x33)\n");
Joe Perchesc3504bf2013-03-18 10:44:55 -0700785 return false;
786 }
787 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400788}
789
790/*
791 * Description:
792 * Set the Key by MISCFIFO
793 *
794 * Parameters:
795 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000796 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400797 *
798 * Out:
799 * none
800 *
801 * Return Value: none
802 *
803 */
804
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000805void MACvSetKeyEntry(struct vnt_private *priv, unsigned short wKeyCtl,
Guillaume Brogid4855fe2015-04-26 14:40:23 +0200806 unsigned int uEntryIdx, unsigned int uKeyIdx,
807 unsigned char *pbyAddr, u32 *pdwKey,
808 unsigned char byLocalID)
Forest Bond5449c682009-04-25 10:30:44 -0400809{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000810 void __iomem *io_base = priv->PortOffset;
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000811 unsigned short offset;
Malcolm Priestleyefa21f92016-03-06 12:57:12 +0000812 u32 data;
Joe Perchesc3504bf2013-03-18 10:44:55 -0700813 int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400814
Joe Perchesc3504bf2013-03-18 10:44:55 -0700815 if (byLocalID <= 1)
816 return;
Forest Bond5449c682009-04-25 10:30:44 -0400817
Joe Perches48caf5a2014-08-17 09:17:04 -0700818 pr_debug("MACvSetKeyEntry\n");
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000819 offset = MISCFIFO_KEYETRY0;
820 offset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -0400821
Malcolm Priestleyefa21f92016-03-06 12:57:12 +0000822 data = 0;
823 data |= wKeyCtl;
824 data <<= 16;
825 data |= MAKEWORD(*(pbyAddr + 4), *(pbyAddr + 5));
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000826 pr_debug("1. offset: %d, Data: %X, KeyCtl:%X\n",
Malcolm Priestleyefa21f92016-03-06 12:57:12 +0000827 offset, data, wKeyCtl);
Forest Bond5449c682009-04-25 10:30:44 -0400828
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000829 iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
Malcolm Priestleyefa21f92016-03-06 12:57:12 +0000830 iowrite32(data, io_base + MAC_REG_MISCFFDATA);
Malcolm Priestley54a14e62016-03-06 12:57:04 +0000831 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000832 offset++;
Forest Bond5449c682009-04-25 10:30:44 -0400833
Malcolm Priestleyefa21f92016-03-06 12:57:12 +0000834 data = 0;
835 data |= *(pbyAddr + 3);
836 data <<= 8;
837 data |= *(pbyAddr + 2);
838 data <<= 8;
839 data |= *(pbyAddr + 1);
840 data <<= 8;
841 data |= *pbyAddr;
842 pr_debug("2. offset: %d, Data: %X\n", offset, data);
Forest Bond5449c682009-04-25 10:30:44 -0400843
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000844 iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
Malcolm Priestleyefa21f92016-03-06 12:57:12 +0000845 iowrite32(data, io_base + MAC_REG_MISCFFDATA);
Malcolm Priestley54a14e62016-03-06 12:57:04 +0000846 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000847 offset++;
Forest Bond5449c682009-04-25 10:30:44 -0400848
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000849 offset += (uKeyIdx * 4);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700850 for (ii = 0; ii < 4; ii++) {
Matteo Semenzato9ab81fb2015-02-28 15:28:15 +0100851 /* always push 128 bits */
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000852 pr_debug("3.(%d) offset: %d, Data: %X\n",
853 ii, offset + ii, *pdwKey);
854 iowrite16(offset + ii, io_base + MAC_REG_MISCFFNDEX);
Malcolm Priestleye2ad8e232016-03-06 12:57:03 +0000855 iowrite32(*pdwKey++, io_base + MAC_REG_MISCFFDATA);
Malcolm Priestley54a14e62016-03-06 12:57:04 +0000856 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
Joe Perchesc3504bf2013-03-18 10:44:55 -0700857 }
Forest Bond5449c682009-04-25 10:30:44 -0400858}
859
Forest Bond5449c682009-04-25 10:30:44 -0400860/*
861 * Description:
862 * Disable the Key Entry by MISCFIFO
863 *
864 * Parameters:
865 * In:
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000866 * io_base - Base Address for MAC
Forest Bond5449c682009-04-25 10:30:44 -0400867 *
868 * Out:
869 * none
870 *
871 * Return Value: none
872 *
873 */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000874void MACvDisableKeyEntry(struct vnt_private *priv, unsigned int uEntryIdx)
Forest Bond5449c682009-04-25 10:30:44 -0400875{
Malcolm Priestleyc2d845d2016-02-28 19:02:54 +0000876 void __iomem *io_base = priv->PortOffset;
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000877 unsigned short offset;
Forest Bond5449c682009-04-25 10:30:44 -0400878
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000879 offset = MISCFIFO_KEYETRY0;
880 offset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
Forest Bond5449c682009-04-25 10:30:44 -0400881
Malcolm Priestley0e7997c2016-03-06 12:57:11 +0000882 iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
Malcolm Priestleye2ad8e232016-03-06 12:57:03 +0000883 iowrite32(0, io_base + MAC_REG_MISCFFDATA);
Malcolm Priestley54a14e62016-03-06 12:57:04 +0000884 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
Forest Bond5449c682009-04-25 10:30:44 -0400885}