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