staging: vt6655: mac.c rename pbyCxtBuf to cxt_buf
[cascardo/linux.git] / drivers / staging / vt6655 / mac.c
1 /*
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  *
19  *
20  * File: mac.c
21  *
22  * Purpose:  MAC routines
23  *
24  * Author: Tevin Chen
25  *
26  * Date: May 21, 1996
27  *
28  * Functions:
29  *      MACbIsRegBitsOn - Test if All test Bits On
30  *      MACbIsRegBitsOff - Test if All test Bits Off
31  *      MACbIsIntDisable - Test if MAC interrupt disable
32  *      MACvSetShortRetryLimit - Set 802.11 Short Retry limit
33  *      MACvSetLongRetryLimit - Set 802.11 Long Retry limit
34  *      MACvSetLoopbackMode - Set MAC Loopback Mode
35  *      MACvSaveContext - Save Context of MAC Registers
36  *      MACvRestoreContext - Restore Context of MAC Registers
37  *      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
43  *      MACvSetCurrRxDescAddr - Set Rx Descriptors Address
44  *      MACvSetCurrTx0DescAddr - Set Tx0 Descriptors Address
45  *      MACvSetCurrTx1DescAddr - Set Tx1 Descriptors Address
46  *      MACvTimer0MicroSDelay - Micro Second Delay Loop by MAC
47  *
48  * Revision History:
49  *      08-22-2003 Kyle Hsu     :  Porting MAC functions from sim53
50  *      09-03-2003 Bryan YC Fan :  Add MACvClearBusSusInd()& MACvEnableBusSusEn()
51  *      09-18-2003 Jerry Chen   :  Add MACvSetKeyEntry & MACvDisableKeyEntry
52  *
53  */
54
55 #include "tmacro.h"
56 #include "mac.h"
57
58 /*
59  * Description:
60  *      Test if all test bits on
61  *
62  * Parameters:
63  *  In:
64  *      io_base    - Base Address for MAC
65  *      byRegOfs    - Offset of MAC Register
66  *      byTestBits  - Test bits
67  *  Out:
68  *      none
69  *
70  * Return Value: true if all test bits On; otherwise false
71  *
72  */
73 bool MACbIsRegBitsOn(struct vnt_private *priv, unsigned char byRegOfs,
74                      unsigned char byTestBits)
75 {
76         void __iomem *io_base = priv->PortOffset;
77
78         return (ioread8(io_base + byRegOfs) & byTestBits) == byTestBits;
79 }
80
81 /*
82  * Description:
83  *      Test if all test bits off
84  *
85  * Parameters:
86  *  In:
87  *      io_base    - Base Address for MAC
88  *      byRegOfs    - Offset of MAC Register
89  *      byTestBits  - Test bits
90  *  Out:
91  *      none
92  *
93  * Return Value: true if all test bits Off; otherwise false
94  *
95  */
96 bool MACbIsRegBitsOff(struct vnt_private *priv, unsigned char byRegOfs,
97                       unsigned char byTestBits)
98 {
99         void __iomem *io_base = priv->PortOffset;
100
101         return !(ioread8(io_base + byRegOfs) & byTestBits);
102 }
103
104 /*
105  * Description:
106  *      Test if MAC interrupt disable
107  *
108  * Parameters:
109  *  In:
110  *      io_base    - Base Address for MAC
111  *  Out:
112  *      none
113  *
114  * Return Value: true if interrupt is disable; otherwise false
115  *
116  */
117 bool MACbIsIntDisable(struct vnt_private *priv)
118 {
119         void __iomem *io_base = priv->PortOffset;
120
121         if (ioread32(io_base + MAC_REG_IMR))
122                 return false;
123
124         return true;
125 }
126
127 /*
128  * Description:
129  *      Set 802.11 Short Retry Limit
130  *
131  * Parameters:
132  *  In:
133  *      io_base    - Base Address for MAC
134  *      byRetryLimit- Retry Limit
135  *  Out:
136  *      none
137  *
138  * Return Value: none
139  *
140  */
141 void MACvSetShortRetryLimit(struct vnt_private *priv, unsigned char byRetryLimit)
142 {
143         void __iomem *io_base = priv->PortOffset;
144         /* set SRT */
145         VNSvOutPortB(io_base + MAC_REG_SRT, byRetryLimit);
146 }
147
148
149 /*
150  * Description:
151  *      Set 802.11 Long Retry Limit
152  *
153  * Parameters:
154  *  In:
155  *      io_base    - Base Address for MAC
156  *      byRetryLimit- Retry Limit
157  *  Out:
158  *      none
159  *
160  * Return Value: none
161  *
162  */
163 void MACvSetLongRetryLimit(struct vnt_private *priv, unsigned char byRetryLimit)
164 {
165         void __iomem *io_base = priv->PortOffset;
166         /* set LRT */
167         VNSvOutPortB(io_base + MAC_REG_LRT, byRetryLimit);
168 }
169
170 /*
171  * Description:
172  *      Set MAC Loopback mode
173  *
174  * Parameters:
175  *  In:
176  *      io_base        - Base Address for MAC
177  *      byLoopbackMode  - Loopback Mode
178  *  Out:
179  *      none
180  *
181  * Return Value: none
182  *
183  */
184 void MACvSetLoopbackMode(struct vnt_private *priv, unsigned char byLoopbackMode)
185 {
186         void __iomem *io_base = priv->PortOffset;
187         unsigned char byOrgValue;
188
189         byLoopbackMode <<= 6;
190         /* set TCR */
191         VNSvInPortB(io_base + MAC_REG_TEST, &byOrgValue);
192         byOrgValue = byOrgValue & 0x3F;
193         byOrgValue = byOrgValue | byLoopbackMode;
194         VNSvOutPortB(io_base + MAC_REG_TEST, byOrgValue);
195 }
196
197 /*
198  * Description:
199  *      Save MAC registers to context buffer
200  *
201  * Parameters:
202  *  In:
203  *      io_base    - Base Address for MAC
204  *  Out:
205  *      cxt_buf   - Context buffer
206  *
207  * Return Value: none
208  *
209  */
210 void MACvSaveContext(struct vnt_private *priv, unsigned char *cxt_buf)
211 {
212         void __iomem *io_base = priv->PortOffset;
213
214         /* read page0 register */
215         memcpy_fromio(cxt_buf, io_base, MAC_MAX_CONTEXT_SIZE_PAGE0);
216
217         MACvSelectPage1(io_base);
218
219         /* read page1 register */
220         memcpy_fromio(cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0, io_base,
221                       MAC_MAX_CONTEXT_SIZE_PAGE1);
222
223         MACvSelectPage0(io_base);
224 }
225
226 /*
227  * Description:
228  *      Restore MAC registers from context buffer
229  *
230  * Parameters:
231  *  In:
232  *      io_base    - Base Address for MAC
233  *      cxt_buf   - Context buffer
234  *  Out:
235  *      none
236  *
237  * Return Value: none
238  *
239  */
240 void MACvRestoreContext(struct vnt_private *priv, unsigned char *cxt_buf)
241 {
242         void __iomem *io_base = priv->PortOffset;
243         int         ii;
244
245         MACvSelectPage1(io_base);
246         /* restore page1 */
247         for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++)
248                 VNSvOutPortB((io_base + ii),
249                              *(cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
250
251         MACvSelectPage0(io_base);
252
253         /* restore RCR,TCR,IMR... */
254         for (ii = MAC_REG_RCR; ii < MAC_REG_ISR; ii++)
255                 VNSvOutPortB(io_base + ii, *(cxt_buf + ii));
256
257         /* restore MAC Config. */
258         for (ii = MAC_REG_LRT; ii < MAC_REG_PAGE1SEL; ii++)
259                 VNSvOutPortB(io_base + ii, *(cxt_buf + ii));
260
261         VNSvOutPortB(io_base + MAC_REG_CFG, *(cxt_buf + MAC_REG_CFG));
262
263         /* restore PS Config. */
264         for (ii = MAC_REG_PSCFG; ii < MAC_REG_BBREGCTL; ii++)
265                 VNSvOutPortB(io_base + ii, *(cxt_buf + ii));
266
267         /* restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR */
268         VNSvOutPortD(io_base + MAC_REG_TXDMAPTR0,
269                      *(unsigned long *)(cxt_buf + MAC_REG_TXDMAPTR0));
270         VNSvOutPortD(io_base + MAC_REG_AC0DMAPTR,
271                      *(unsigned long *)(cxt_buf + MAC_REG_AC0DMAPTR));
272         VNSvOutPortD(io_base + MAC_REG_BCNDMAPTR,
273                      *(unsigned long *)(cxt_buf + MAC_REG_BCNDMAPTR));
274
275         VNSvOutPortD(io_base + MAC_REG_RXDMAPTR0,
276                      *(unsigned long *)(cxt_buf + MAC_REG_RXDMAPTR0));
277
278         VNSvOutPortD(io_base + MAC_REG_RXDMAPTR1,
279                      *(unsigned long *)(cxt_buf + MAC_REG_RXDMAPTR1));
280 }
281
282 /*
283  * Description:
284  *      Software Reset MAC
285  *
286  * Parameters:
287  *  In:
288  *      io_base    - Base Address for MAC
289  *  Out:
290  *      none
291  *
292  * Return Value: true if Reset Success; otherwise false
293  *
294  */
295 bool MACbSoftwareReset(struct vnt_private *priv)
296 {
297         void __iomem *io_base = priv->PortOffset;
298         unsigned short ww;
299
300         /* turn on HOSTCR_SOFTRST, just write 0x01 to reset */
301         VNSvOutPortB(io_base + MAC_REG_HOSTCR, 0x01);
302
303         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
304                 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_SOFTRST))
305                         break;
306         }
307         if (ww == W_MAX_TIMEOUT)
308                 return false;
309         return true;
310 }
311
312 /*
313  * Description:
314  *      save some important register's value, then do reset, then restore register's value
315  *
316  * Parameters:
317  *  In:
318  *      io_base    - Base Address for MAC
319  *  Out:
320  *      none
321  *
322  * Return Value: true if success; otherwise false
323  *
324  */
325 bool MACbSafeSoftwareReset(struct vnt_private *priv)
326 {
327         unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
328         bool bRetVal;
329
330         /* PATCH....
331          * save some important register's value, then do
332          * reset, then restore register's value
333          */
334         /* save MAC context */
335         MACvSaveContext(priv, abyTmpRegData);
336         /* do reset */
337         bRetVal = MACbSoftwareReset(priv);
338         /* restore MAC context, except CR0 */
339         MACvRestoreContext(priv, abyTmpRegData);
340
341         return bRetVal;
342 }
343
344 /*
345  * Description:
346  *      Turn Off MAC Rx
347  *
348  * Parameters:
349  *  In:
350  *      io_base    - Base Address for MAC
351  *  Out:
352  *      none
353  *
354  * Return Value: true if success; otherwise false
355  *
356  */
357 bool MACbSafeRxOff(struct vnt_private *priv)
358 {
359         void __iomem *io_base = priv->PortOffset;
360         unsigned short ww;
361
362         /* turn off wow temp for turn off Rx safely */
363
364         /* Clear RX DMA0,1 */
365         VNSvOutPortD(io_base + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
366         VNSvOutPortD(io_base + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
367         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
368                 if (!(ioread32(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
369                         break;
370         }
371         if (ww == W_MAX_TIMEOUT) {
372                 pr_debug(" DBG_PORT80(0x10)\n");
373                 return false;
374         }
375         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
376                 if (!(ioread32(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
377                         break;
378         }
379         if (ww == W_MAX_TIMEOUT) {
380                 pr_debug(" DBG_PORT80(0x11)\n");
381                 return false;
382         }
383
384         /* try to safe shutdown RX */
385         MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_RXON);
386         /* W_MAX_TIMEOUT is the timeout period */
387         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
388                 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_RXONST))
389                         break;
390         }
391         if (ww == W_MAX_TIMEOUT) {
392                 pr_debug(" DBG_PORT80(0x12)\n");
393                 return false;
394         }
395         return true;
396 }
397
398 /*
399  * Description:
400  *      Turn Off MAC Tx
401  *
402  * Parameters:
403  *  In:
404  *      io_base    - Base Address for MAC
405  *  Out:
406  *      none
407  *
408  * Return Value: true if success; otherwise false
409  *
410  */
411 bool MACbSafeTxOff(struct vnt_private *priv)
412 {
413         void __iomem *io_base = priv->PortOffset;
414         unsigned short ww;
415
416         /* Clear TX DMA */
417         /* Tx0 */
418         VNSvOutPortD(io_base + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
419         /* AC0 */
420         VNSvOutPortD(io_base + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
421
422         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
423                 if (!(ioread32(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
424                         break;
425         }
426         if (ww == W_MAX_TIMEOUT) {
427                 pr_debug(" DBG_PORT80(0x20)\n");
428                 return false;
429         }
430         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
431                 if (!(ioread32(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
432                         break;
433         }
434         if (ww == W_MAX_TIMEOUT) {
435                 pr_debug(" DBG_PORT80(0x21)\n");
436                 return false;
437         }
438
439         /* try to safe shutdown TX */
440         MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_TXON);
441
442         /* W_MAX_TIMEOUT is the timeout period */
443         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
444                 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_TXONST))
445                         break;
446         }
447         if (ww == W_MAX_TIMEOUT) {
448                 pr_debug(" DBG_PORT80(0x24)\n");
449                 return false;
450         }
451         return true;
452 }
453
454 /*
455  * Description:
456  *      Stop MAC function
457  *
458  * Parameters:
459  *  In:
460  *      io_base    - Base Address for MAC
461  *  Out:
462  *      none
463  *
464  * Return Value: true if success; otherwise false
465  *
466  */
467 bool MACbSafeStop(struct vnt_private *priv)
468 {
469         void __iomem *io_base = priv->PortOffset;
470
471         MACvRegBitsOff(io_base, MAC_REG_TCR, TCR_AUTOBCNTX);
472
473         if (!MACbSafeRxOff(priv)) {
474                 pr_debug(" MACbSafeRxOff == false)\n");
475                 MACbSafeSoftwareReset(priv);
476                 return false;
477         }
478         if (!MACbSafeTxOff(priv)) {
479                 pr_debug(" MACbSafeTxOff == false)\n");
480                 MACbSafeSoftwareReset(priv);
481                 return false;
482         }
483
484         MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_MACEN);
485
486         return true;
487 }
488
489 /*
490  * Description:
491  *      Shut Down MAC
492  *
493  * Parameters:
494  *  In:
495  *      io_base    - Base Address for MAC
496  *  Out:
497  *      none
498  *
499  * Return Value: true if success; otherwise false
500  *
501  */
502 bool MACbShutdown(struct vnt_private *priv)
503 {
504         void __iomem *io_base = priv->PortOffset;
505         /* disable MAC IMR */
506         MACvIntDisable(io_base);
507         MACvSetLoopbackMode(priv, MAC_LB_INTERNAL);
508         /* stop the adapter */
509         if (!MACbSafeStop(priv)) {
510                 MACvSetLoopbackMode(priv, MAC_LB_NONE);
511                 return false;
512         }
513         MACvSetLoopbackMode(priv, MAC_LB_NONE);
514         return true;
515 }
516
517 /*
518  * Description:
519  *      Initialize MAC
520  *
521  * Parameters:
522  *  In:
523  *      io_base    - Base Address for MAC
524  *  Out:
525  *      none
526  *
527  * Return Value: none
528  *
529  */
530 void MACvInitialize(struct vnt_private *priv)
531 {
532         void __iomem *io_base = priv->PortOffset;
533         /* clear sticky bits */
534         MACvClearStckDS(io_base);
535         /* disable force PME-enable */
536         VNSvOutPortB(io_base + MAC_REG_PMC1, PME_OVR);
537         /* only 3253 A */
538
539         /* do reset */
540         MACbSoftwareReset(priv);
541
542         /* reset TSF counter */
543         VNSvOutPortB(io_base + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
544         /* enable TSF counter */
545         VNSvOutPortB(io_base + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
546 }
547
548 /*
549  * Description:
550  *      Set the chip with current rx descriptor address
551  *
552  * Parameters:
553  *  In:
554  *      io_base        - Base Address for MAC
555  *      dwCurrDescAddr  - Descriptor Address
556  *  Out:
557  *      none
558  *
559  * Return Value: none
560  *
561  */
562 void MACvSetCurrRx0DescAddr(struct vnt_private *priv, unsigned long dwCurrDescAddr)
563 {
564         void __iomem *io_base = priv->PortOffset;
565         unsigned short ww;
566         unsigned char byOrgDMACtl;
567
568         VNSvInPortB(io_base + MAC_REG_RXDMACTL0, &byOrgDMACtl);
569         if (byOrgDMACtl & DMACTL_RUN)
570                 VNSvOutPortB(io_base + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
571
572         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
573                 if (!(ioread8(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
574                         break;
575         }
576
577         VNSvOutPortD(io_base + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
578         if (byOrgDMACtl & DMACTL_RUN)
579                 VNSvOutPortB(io_base + MAC_REG_RXDMACTL0, DMACTL_RUN);
580 }
581
582 /*
583  * Description:
584  *      Set the chip with current rx descriptor address
585  *
586  * Parameters:
587  *  In:
588  *      io_base        - Base Address for MAC
589  *      dwCurrDescAddr  - Descriptor Address
590  *  Out:
591  *      none
592  *
593  * Return Value: none
594  *
595  */
596 void MACvSetCurrRx1DescAddr(struct vnt_private *priv, unsigned long dwCurrDescAddr)
597 {
598         void __iomem *io_base = priv->PortOffset;
599         unsigned short ww;
600         unsigned char byOrgDMACtl;
601
602         VNSvInPortB(io_base + MAC_REG_RXDMACTL1, &byOrgDMACtl);
603         if (byOrgDMACtl & DMACTL_RUN)
604                 VNSvOutPortB(io_base + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
605
606         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
607                 if (!(ioread8(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
608                         break;
609         }
610
611         VNSvOutPortD(io_base + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
612         if (byOrgDMACtl & DMACTL_RUN)
613                 VNSvOutPortB(io_base + MAC_REG_RXDMACTL1, DMACTL_RUN);
614
615 }
616
617 /*
618  * Description:
619  *      Set the chip with current tx0 descriptor address
620  *
621  * Parameters:
622  *  In:
623  *      io_base        - Base Address for MAC
624  *      dwCurrDescAddr  - Descriptor Address
625  *  Out:
626  *      none
627  *
628  * Return Value: none
629  *
630  */
631 void MACvSetCurrTx0DescAddrEx(struct vnt_private *priv,
632                               unsigned long dwCurrDescAddr)
633 {
634         void __iomem *io_base = priv->PortOffset;
635         unsigned short ww;
636         unsigned char byOrgDMACtl;
637
638         VNSvInPortB(io_base + MAC_REG_TXDMACTL0, &byOrgDMACtl);
639         if (byOrgDMACtl & DMACTL_RUN)
640                 VNSvOutPortB(io_base + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
641
642         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
643                 if (!(ioread8(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
644                         break;
645         }
646
647         VNSvOutPortD(io_base + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
648         if (byOrgDMACtl & DMACTL_RUN)
649                 VNSvOutPortB(io_base + MAC_REG_TXDMACTL0, DMACTL_RUN);
650 }
651
652 /*
653  * Description:
654  *      Set the chip with current AC0 descriptor address
655  *
656  * Parameters:
657  *  In:
658  *      io_base        - Base Address for MAC
659  *      dwCurrDescAddr  - Descriptor Address
660  *  Out:
661  *      none
662  *
663  * Return Value: none
664  *
665  */
666 /* TxDMA1 = AC0DMA */
667 void MACvSetCurrAC0DescAddrEx(struct vnt_private *priv,
668                               unsigned long dwCurrDescAddr)
669 {
670         void __iomem *io_base = priv->PortOffset;
671         unsigned short ww;
672         unsigned char byOrgDMACtl;
673
674         VNSvInPortB(io_base + MAC_REG_AC0DMACTL, &byOrgDMACtl);
675         if (byOrgDMACtl & DMACTL_RUN)
676                 VNSvOutPortB(io_base + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
677
678         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
679                 if (!(ioread8(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
680                         break;
681         }
682         if (ww == W_MAX_TIMEOUT)
683                 pr_debug(" DBG_PORT80(0x26)\n");
684         VNSvOutPortD(io_base + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
685         if (byOrgDMACtl & DMACTL_RUN)
686                 VNSvOutPortB(io_base + MAC_REG_AC0DMACTL, DMACTL_RUN);
687 }
688
689 void MACvSetCurrTXDescAddr(int iTxType, struct vnt_private *priv,
690                            unsigned long dwCurrDescAddr)
691 {
692         if (iTxType == TYPE_AC0DMA)
693                 MACvSetCurrAC0DescAddrEx(priv, dwCurrDescAddr);
694         else if (iTxType == TYPE_TXDMA0)
695                 MACvSetCurrTx0DescAddrEx(priv, dwCurrDescAddr);
696 }
697
698 /*
699  * Description:
700  *      Micro Second Delay via MAC
701  *
702  * Parameters:
703  *  In:
704  *      io_base    - Base Address for MAC
705  *      uDelay      - Delay time (timer resolution is 4 us)
706  *  Out:
707  *      none
708  *
709  * Return Value: none
710  *
711  */
712 void MACvTimer0MicroSDelay(struct vnt_private *priv, unsigned int uDelay)
713 {
714         void __iomem *io_base = priv->PortOffset;
715         unsigned char byValue;
716         unsigned int uu, ii;
717
718         VNSvOutPortB(io_base + MAC_REG_TMCTL0, 0);
719         VNSvOutPortD(io_base + MAC_REG_TMDATA0, uDelay);
720         VNSvOutPortB(io_base + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
721         for (ii = 0; ii < 66; ii++) {  /* assume max PCI clock is 66Mhz */
722                 for (uu = 0; uu < uDelay; uu++) {
723                         VNSvInPortB(io_base + MAC_REG_TMCTL0, &byValue);
724                         if ((byValue == 0) ||
725                             (byValue & TMCTL_TSUSP)) {
726                                 VNSvOutPortB(io_base + MAC_REG_TMCTL0, 0);
727                                 return;
728                         }
729                 }
730         }
731         VNSvOutPortB(io_base + MAC_REG_TMCTL0, 0);
732 }
733
734 /*
735  * Description:
736  *      Micro Second One shot timer via MAC
737  *
738  * Parameters:
739  *  In:
740  *      io_base    - Base Address for MAC
741  *      uDelay      - Delay time
742  *  Out:
743  *      none
744  *
745  * Return Value: none
746  *
747  */
748 void MACvOneShotTimer1MicroSec(struct vnt_private *priv, unsigned int uDelayTime)
749 {
750         void __iomem *io_base = priv->PortOffset;
751
752         VNSvOutPortB(io_base + MAC_REG_TMCTL1, 0);
753         VNSvOutPortD(io_base + MAC_REG_TMDATA1, uDelayTime);
754         VNSvOutPortB(io_base + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
755 }
756
757 void MACvSetMISCFifo(struct vnt_private *priv, unsigned short wOffset,
758                      unsigned long dwData)
759 {
760         void __iomem *io_base = priv->PortOffset;
761
762         if (wOffset > 273)
763                 return;
764         VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset);
765         VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, dwData);
766         VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
767 }
768
769 bool MACbPSWakeup(struct vnt_private *priv)
770 {
771         void __iomem *io_base = priv->PortOffset;
772         unsigned char byOrgValue;
773         unsigned int ww;
774         /* Read PSCTL */
775         if (MACbIsRegBitsOff(priv, MAC_REG_PSCTL, PSCTL_PS))
776                 return true;
777
778         /* Disable PS */
779         MACvRegBitsOff(io_base, MAC_REG_PSCTL, PSCTL_PSEN);
780
781         /* Check if SyncFlushOK */
782         for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
783                 VNSvInPortB(io_base + MAC_REG_PSCTL, &byOrgValue);
784                 if (byOrgValue & PSCTL_WAKEDONE)
785                         break;
786         }
787         if (ww == W_MAX_TIMEOUT) {
788                 pr_debug(" DBG_PORT80(0x33)\n");
789                 return false;
790         }
791         return true;
792 }
793
794 /*
795  * Description:
796  *      Set the Key by MISCFIFO
797  *
798  * Parameters:
799  *  In:
800  *      io_base        - Base Address for MAC
801  *
802  *  Out:
803  *      none
804  *
805  * Return Value: none
806  *
807  */
808
809 void MACvSetKeyEntry(struct vnt_private *priv, unsigned short wKeyCtl,
810                      unsigned int uEntryIdx, unsigned int uKeyIdx,
811                      unsigned char *pbyAddr, u32 *pdwKey,
812                      unsigned char byLocalID)
813 {
814         void __iomem *io_base = priv->PortOffset;
815         unsigned short wOffset;
816         u32 dwData;
817         int     ii;
818
819         if (byLocalID <= 1)
820                 return;
821
822         pr_debug("MACvSetKeyEntry\n");
823         wOffset = MISCFIFO_KEYETRY0;
824         wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
825
826         dwData = 0;
827         dwData |= wKeyCtl;
828         dwData <<= 16;
829         dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
830         pr_debug("1. wOffset: %d, Data: %X, KeyCtl:%X\n",
831                  wOffset, dwData, wKeyCtl);
832
833         VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset);
834         VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, dwData);
835         VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
836         wOffset++;
837
838         dwData = 0;
839         dwData |= *(pbyAddr+3);
840         dwData <<= 8;
841         dwData |= *(pbyAddr+2);
842         dwData <<= 8;
843         dwData |= *(pbyAddr+1);
844         dwData <<= 8;
845         dwData |= *(pbyAddr+0);
846         pr_debug("2. wOffset: %d, Data: %X\n", wOffset, dwData);
847
848         VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset);
849         VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, dwData);
850         VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
851         wOffset++;
852
853         wOffset += (uKeyIdx * 4);
854         for (ii = 0; ii < 4; ii++) {
855                 /* always push 128 bits */
856                 pr_debug("3.(%d) wOffset: %d, Data: %X\n",
857                          ii, wOffset+ii, *pdwKey);
858                 VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset+ii);
859                 VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, *pdwKey++);
860                 VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
861         }
862 }
863
864 /*
865  * Description:
866  *      Disable the Key Entry by MISCFIFO
867  *
868  * Parameters:
869  *  In:
870  *      io_base        - Base Address for MAC
871  *
872  *  Out:
873  *      none
874  *
875  * Return Value: none
876  *
877  */
878 void MACvDisableKeyEntry(struct vnt_private *priv, unsigned int uEntryIdx)
879 {
880         void __iomem *io_base = priv->PortOffset;
881         unsigned short wOffset;
882
883         wOffset = MISCFIFO_KEYETRY0;
884         wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
885
886         VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset);
887         VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, 0);
888         VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
889 }