staging: vt6655: MACvRestoreContext replace for loops with memcpy_toio.
[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
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
244 MACvSelectPage1(io_base);
245 /* restore page1 */
246 memcpy_toio(io_base, cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0,
247 MAC_MAX_CONTEXT_SIZE_PAGE1);
248
249 MACvSelectPage0(io_base);
250
251 /* restore RCR,TCR,IMR... */
252 memcpy_toio(io_base + MAC_REG_RCR, cxt_buf + MAC_REG_RCR,
253 MAC_REG_ISR - MAC_REG_RCR);
254
255 /* restore MAC Config. */
256 memcpy_toio(io_base + MAC_REG_LRT, cxt_buf + MAC_REG_LRT,
257 MAC_REG_PAGE1SEL - MAC_REG_LRT);
258
259 VNSvOutPortB(io_base + MAC_REG_CFG, *(cxt_buf + MAC_REG_CFG));
260
261 /* restore PS Config. */
262 memcpy_toio(io_base + MAC_REG_PSCFG, cxt_buf + MAC_REG_PSCFG,
263 MAC_REG_BBREGCTL - MAC_REG_PSCFG);
264
265 /* restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR */
266 VNSvOutPortD(io_base + MAC_REG_TXDMAPTR0,
267 *(unsigned long *)(cxt_buf + MAC_REG_TXDMAPTR0));
268 VNSvOutPortD(io_base + MAC_REG_AC0DMAPTR,
269 *(unsigned long *)(cxt_buf + MAC_REG_AC0DMAPTR));
270 VNSvOutPortD(io_base + MAC_REG_BCNDMAPTR,
271 *(unsigned long *)(cxt_buf + MAC_REG_BCNDMAPTR));
272
273 VNSvOutPortD(io_base + MAC_REG_RXDMAPTR0,
274 *(unsigned long *)(cxt_buf + MAC_REG_RXDMAPTR0));
275
276 VNSvOutPortD(io_base + MAC_REG_RXDMAPTR1,
277 *(unsigned long *)(cxt_buf + MAC_REG_RXDMAPTR1));
278 }
279
280 /*
281 * Description:
282 * Software Reset MAC
283 *
284 * Parameters:
285 * In:
286 * io_base - Base Address for MAC
287 * Out:
288 * none
289 *
290 * Return Value: true if Reset Success; otherwise false
291 *
292 */
293 bool MACbSoftwareReset(struct vnt_private *priv)
294 {
295 void __iomem *io_base = priv->PortOffset;
296 unsigned short ww;
297
298 /* turn on HOSTCR_SOFTRST, just write 0x01 to reset */
299 VNSvOutPortB(io_base + MAC_REG_HOSTCR, 0x01);
300
301 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
302 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_SOFTRST))
303 break;
304 }
305 if (ww == W_MAX_TIMEOUT)
306 return false;
307 return true;
308 }
309
310 /*
311 * Description:
312 * save some important register's value, then do reset, then restore register's value
313 *
314 * Parameters:
315 * In:
316 * io_base - Base Address for MAC
317 * Out:
318 * none
319 *
320 * Return Value: true if success; otherwise false
321 *
322 */
323 bool MACbSafeSoftwareReset(struct vnt_private *priv)
324 {
325 unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
326 bool bRetVal;
327
328 /* PATCH....
329 * save some important register's value, then do
330 * reset, then restore register's value
331 */
332 /* save MAC context */
333 MACvSaveContext(priv, abyTmpRegData);
334 /* do reset */
335 bRetVal = MACbSoftwareReset(priv);
336 /* restore MAC context, except CR0 */
337 MACvRestoreContext(priv, abyTmpRegData);
338
339 return bRetVal;
340 }
341
342 /*
343 * Description:
344 * Turn Off MAC Rx
345 *
346 * Parameters:
347 * In:
348 * io_base - Base Address for MAC
349 * Out:
350 * none
351 *
352 * Return Value: true if success; otherwise false
353 *
354 */
355 bool MACbSafeRxOff(struct vnt_private *priv)
356 {
357 void __iomem *io_base = priv->PortOffset;
358 unsigned short ww;
359
360 /* turn off wow temp for turn off Rx safely */
361
362 /* Clear RX DMA0,1 */
363 VNSvOutPortD(io_base + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
364 VNSvOutPortD(io_base + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
365 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
366 if (!(ioread32(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
367 break;
368 }
369 if (ww == W_MAX_TIMEOUT) {
370 pr_debug(" DBG_PORT80(0x10)\n");
371 return false;
372 }
373 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
374 if (!(ioread32(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
375 break;
376 }
377 if (ww == W_MAX_TIMEOUT) {
378 pr_debug(" DBG_PORT80(0x11)\n");
379 return false;
380 }
381
382 /* try to safe shutdown RX */
383 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_RXON);
384 /* W_MAX_TIMEOUT is the timeout period */
385 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
386 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_RXONST))
387 break;
388 }
389 if (ww == W_MAX_TIMEOUT) {
390 pr_debug(" DBG_PORT80(0x12)\n");
391 return false;
392 }
393 return true;
394 }
395
396 /*
397 * Description:
398 * Turn Off MAC Tx
399 *
400 * Parameters:
401 * In:
402 * io_base - Base Address for MAC
403 * Out:
404 * none
405 *
406 * Return Value: true if success; otherwise false
407 *
408 */
409 bool MACbSafeTxOff(struct vnt_private *priv)
410 {
411 void __iomem *io_base = priv->PortOffset;
412 unsigned short ww;
413
414 /* Clear TX DMA */
415 /* Tx0 */
416 VNSvOutPortD(io_base + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
417 /* AC0 */
418 VNSvOutPortD(io_base + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
419
420 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
421 if (!(ioread32(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
422 break;
423 }
424 if (ww == W_MAX_TIMEOUT) {
425 pr_debug(" DBG_PORT80(0x20)\n");
426 return false;
427 }
428 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
429 if (!(ioread32(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
430 break;
431 }
432 if (ww == W_MAX_TIMEOUT) {
433 pr_debug(" DBG_PORT80(0x21)\n");
434 return false;
435 }
436
437 /* try to safe shutdown TX */
438 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_TXON);
439
440 /* W_MAX_TIMEOUT is the timeout period */
441 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
442 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_TXONST))
443 break;
444 }
445 if (ww == W_MAX_TIMEOUT) {
446 pr_debug(" DBG_PORT80(0x24)\n");
447 return false;
448 }
449 return true;
450 }
451
452 /*
453 * Description:
454 * Stop MAC function
455 *
456 * Parameters:
457 * In:
458 * io_base - Base Address for MAC
459 * Out:
460 * none
461 *
462 * Return Value: true if success; otherwise false
463 *
464 */
465 bool MACbSafeStop(struct vnt_private *priv)
466 {
467 void __iomem *io_base = priv->PortOffset;
468
469 MACvRegBitsOff(io_base, MAC_REG_TCR, TCR_AUTOBCNTX);
470
471 if (!MACbSafeRxOff(priv)) {
472 pr_debug(" MACbSafeRxOff == false)\n");
473 MACbSafeSoftwareReset(priv);
474 return false;
475 }
476 if (!MACbSafeTxOff(priv)) {
477 pr_debug(" MACbSafeTxOff == false)\n");
478 MACbSafeSoftwareReset(priv);
479 return false;
480 }
481
482 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_MACEN);
483
484 return true;
485 }
486
487 /*
488 * Description:
489 * Shut Down MAC
490 *
491 * Parameters:
492 * In:
493 * io_base - Base Address for MAC
494 * Out:
495 * none
496 *
497 * Return Value: true if success; otherwise false
498 *
499 */
500 bool MACbShutdown(struct vnt_private *priv)
501 {
502 void __iomem *io_base = priv->PortOffset;
503 /* disable MAC IMR */
504 MACvIntDisable(io_base);
505 MACvSetLoopbackMode(priv, MAC_LB_INTERNAL);
506 /* stop the adapter */
507 if (!MACbSafeStop(priv)) {
508 MACvSetLoopbackMode(priv, MAC_LB_NONE);
509 return false;
510 }
511 MACvSetLoopbackMode(priv, MAC_LB_NONE);
512 return true;
513 }
514
515 /*
516 * Description:
517 * Initialize MAC
518 *
519 * Parameters:
520 * In:
521 * io_base - Base Address for MAC
522 * Out:
523 * none
524 *
525 * Return Value: none
526 *
527 */
528 void MACvInitialize(struct vnt_private *priv)
529 {
530 void __iomem *io_base = priv->PortOffset;
531 /* clear sticky bits */
532 MACvClearStckDS(io_base);
533 /* disable force PME-enable */
534 VNSvOutPortB(io_base + MAC_REG_PMC1, PME_OVR);
535 /* only 3253 A */
536
537 /* do reset */
538 MACbSoftwareReset(priv);
539
540 /* reset TSF counter */
541 VNSvOutPortB(io_base + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
542 /* enable TSF counter */
543 VNSvOutPortB(io_base + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
544 }
545
546 /*
547 * Description:
548 * Set the chip with current rx descriptor address
549 *
550 * Parameters:
551 * In:
552 * io_base - Base Address for MAC
553 * dwCurrDescAddr - Descriptor Address
554 * Out:
555 * none
556 *
557 * Return Value: none
558 *
559 */
560 void MACvSetCurrRx0DescAddr(struct vnt_private *priv, unsigned long dwCurrDescAddr)
561 {
562 void __iomem *io_base = priv->PortOffset;
563 unsigned short ww;
564 unsigned char byOrgDMACtl;
565
566 VNSvInPortB(io_base + MAC_REG_RXDMACTL0, &byOrgDMACtl);
567 if (byOrgDMACtl & DMACTL_RUN)
568 VNSvOutPortB(io_base + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
569
570 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
571 if (!(ioread8(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
572 break;
573 }
574
575 VNSvOutPortD(io_base + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
576 if (byOrgDMACtl & DMACTL_RUN)
577 VNSvOutPortB(io_base + MAC_REG_RXDMACTL0, DMACTL_RUN);
578 }
579
580 /*
581 * Description:
582 * Set the chip with current rx descriptor address
583 *
584 * Parameters:
585 * In:
586 * io_base - Base Address for MAC
587 * dwCurrDescAddr - Descriptor Address
588 * Out:
589 * none
590 *
591 * Return Value: none
592 *
593 */
594 void MACvSetCurrRx1DescAddr(struct vnt_private *priv, unsigned long dwCurrDescAddr)
595 {
596 void __iomem *io_base = priv->PortOffset;
597 unsigned short ww;
598 unsigned char byOrgDMACtl;
599
600 VNSvInPortB(io_base + MAC_REG_RXDMACTL1, &byOrgDMACtl);
601 if (byOrgDMACtl & DMACTL_RUN)
602 VNSvOutPortB(io_base + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
603
604 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
605 if (!(ioread8(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
606 break;
607 }
608
609 VNSvOutPortD(io_base + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
610 if (byOrgDMACtl & DMACTL_RUN)
611 VNSvOutPortB(io_base + MAC_REG_RXDMACTL1, DMACTL_RUN);
612
613 }
614
615 /*
616 * Description:
617 * Set the chip with current tx0 descriptor address
618 *
619 * Parameters:
620 * In:
621 * io_base - Base Address for MAC
622 * dwCurrDescAddr - Descriptor Address
623 * Out:
624 * none
625 *
626 * Return Value: none
627 *
628 */
629 void MACvSetCurrTx0DescAddrEx(struct vnt_private *priv,
630 unsigned long dwCurrDescAddr)
631 {
632 void __iomem *io_base = priv->PortOffset;
633 unsigned short ww;
634 unsigned char byOrgDMACtl;
635
636 VNSvInPortB(io_base + MAC_REG_TXDMACTL0, &byOrgDMACtl);
637 if (byOrgDMACtl & DMACTL_RUN)
638 VNSvOutPortB(io_base + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
639
640 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
641 if (!(ioread8(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
642 break;
643 }
644
645 VNSvOutPortD(io_base + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
646 if (byOrgDMACtl & DMACTL_RUN)
647 VNSvOutPortB(io_base + MAC_REG_TXDMACTL0, DMACTL_RUN);
648 }
649
650 /*
651 * Description:
652 * Set the chip with current AC0 descriptor address
653 *
654 * Parameters:
655 * In:
656 * io_base - Base Address for MAC
657 * dwCurrDescAddr - Descriptor Address
658 * Out:
659 * none
660 *
661 * Return Value: none
662 *
663 */
664 /* TxDMA1 = AC0DMA */
665 void MACvSetCurrAC0DescAddrEx(struct vnt_private *priv,
666 unsigned long dwCurrDescAddr)
667 {
668 void __iomem *io_base = priv->PortOffset;
669 unsigned short ww;
670 unsigned char byOrgDMACtl;
671
672 VNSvInPortB(io_base + MAC_REG_AC0DMACTL, &byOrgDMACtl);
673 if (byOrgDMACtl & DMACTL_RUN)
674 VNSvOutPortB(io_base + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
675
676 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
677 if (!(ioread8(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
678 break;
679 }
680 if (ww == W_MAX_TIMEOUT)
681 pr_debug(" DBG_PORT80(0x26)\n");
682 VNSvOutPortD(io_base + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
683 if (byOrgDMACtl & DMACTL_RUN)
684 VNSvOutPortB(io_base + MAC_REG_AC0DMACTL, DMACTL_RUN);
685 }
686
687 void MACvSetCurrTXDescAddr(int iTxType, struct vnt_private *priv,
688 unsigned long dwCurrDescAddr)
689 {
690 if (iTxType == TYPE_AC0DMA)
691 MACvSetCurrAC0DescAddrEx(priv, dwCurrDescAddr);
692 else if (iTxType == TYPE_TXDMA0)
693 MACvSetCurrTx0DescAddrEx(priv, dwCurrDescAddr);
694 }
695
696 /*
697 * Description:
698 * Micro Second Delay via MAC
699 *
700 * Parameters:
701 * In:
702 * io_base - Base Address for MAC
703 * uDelay - Delay time (timer resolution is 4 us)
704 * Out:
705 * none
706 *
707 * Return Value: none
708 *
709 */
710 void MACvTimer0MicroSDelay(struct vnt_private *priv, unsigned int uDelay)
711 {
712 void __iomem *io_base = priv->PortOffset;
713 unsigned char byValue;
714 unsigned int uu, ii;
715
716 VNSvOutPortB(io_base + MAC_REG_TMCTL0, 0);
717 VNSvOutPortD(io_base + MAC_REG_TMDATA0, uDelay);
718 VNSvOutPortB(io_base + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
719 for (ii = 0; ii < 66; ii++) { /* assume max PCI clock is 66Mhz */
720 for (uu = 0; uu < uDelay; uu++) {
721 VNSvInPortB(io_base + MAC_REG_TMCTL0, &byValue);
722 if ((byValue == 0) ||
723 (byValue & TMCTL_TSUSP)) {
724 VNSvOutPortB(io_base + MAC_REG_TMCTL0, 0);
725 return;
726 }
727 }
728 }
729 VNSvOutPortB(io_base + MAC_REG_TMCTL0, 0);
730 }
731
732 /*
733 * Description:
734 * Micro Second One shot timer via MAC
735 *
736 * Parameters:
737 * In:
738 * io_base - Base Address for MAC
739 * uDelay - Delay time
740 * Out:
741 * none
742 *
743 * Return Value: none
744 *
745 */
746 void MACvOneShotTimer1MicroSec(struct vnt_private *priv, unsigned int uDelayTime)
747 {
748 void __iomem *io_base = priv->PortOffset;
749
750 VNSvOutPortB(io_base + MAC_REG_TMCTL1, 0);
751 VNSvOutPortD(io_base + MAC_REG_TMDATA1, uDelayTime);
752 VNSvOutPortB(io_base + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
753 }
754
755 void MACvSetMISCFifo(struct vnt_private *priv, unsigned short wOffset,
756 unsigned long dwData)
757 {
758 void __iomem *io_base = priv->PortOffset;
759
760 if (wOffset > 273)
761 return;
762 VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset);
763 VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, dwData);
764 VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
765 }
766
767 bool MACbPSWakeup(struct vnt_private *priv)
768 {
769 void __iomem *io_base = priv->PortOffset;
770 unsigned char byOrgValue;
771 unsigned int ww;
772 /* Read PSCTL */
773 if (MACbIsRegBitsOff(priv, MAC_REG_PSCTL, PSCTL_PS))
774 return true;
775
776 /* Disable PS */
777 MACvRegBitsOff(io_base, MAC_REG_PSCTL, PSCTL_PSEN);
778
779 /* Check if SyncFlushOK */
780 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
781 VNSvInPortB(io_base + MAC_REG_PSCTL, &byOrgValue);
782 if (byOrgValue & PSCTL_WAKEDONE)
783 break;
784 }
785 if (ww == W_MAX_TIMEOUT) {
786 pr_debug(" DBG_PORT80(0x33)\n");
787 return false;
788 }
789 return true;
790 }
791
792 /*
793 * Description:
794 * Set the Key by MISCFIFO
795 *
796 * Parameters:
797 * In:
798 * io_base - Base Address for MAC
799 *
800 * Out:
801 * none
802 *
803 * Return Value: none
804 *
805 */
806
807 void MACvSetKeyEntry(struct vnt_private *priv, unsigned short wKeyCtl,
808 unsigned int uEntryIdx, unsigned int uKeyIdx,
809 unsigned char *pbyAddr, u32 *pdwKey,
810 unsigned char byLocalID)
811 {
812 void __iomem *io_base = priv->PortOffset;
813 unsigned short wOffset;
814 u32 dwData;
815 int ii;
816
817 if (byLocalID <= 1)
818 return;
819
820 pr_debug("MACvSetKeyEntry\n");
821 wOffset = MISCFIFO_KEYETRY0;
822 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
823
824 dwData = 0;
825 dwData |= wKeyCtl;
826 dwData <<= 16;
827 dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
828 pr_debug("1. wOffset: %d, Data: %X, KeyCtl:%X\n",
829 wOffset, dwData, wKeyCtl);
830
831 VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset);
832 VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, dwData);
833 VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
834 wOffset++;
835
836 dwData = 0;
837 dwData |= *(pbyAddr+3);
838 dwData <<= 8;
839 dwData |= *(pbyAddr+2);
840 dwData <<= 8;
841 dwData |= *(pbyAddr+1);
842 dwData <<= 8;
843 dwData |= *(pbyAddr+0);
844 pr_debug("2. wOffset: %d, Data: %X\n", wOffset, dwData);
845
846 VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset);
847 VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, dwData);
848 VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
849 wOffset++;
850
851 wOffset += (uKeyIdx * 4);
852 for (ii = 0; ii < 4; ii++) {
853 /* always push 128 bits */
854 pr_debug("3.(%d) wOffset: %d, Data: %X\n",
855 ii, wOffset+ii, *pdwKey);
856 VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset+ii);
857 VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, *pdwKey++);
858 VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
859 }
860 }
861
862 /*
863 * Description:
864 * Disable the Key Entry by MISCFIFO
865 *
866 * Parameters:
867 * In:
868 * io_base - Base Address for MAC
869 *
870 * Out:
871 * none
872 *
873 * Return Value: none
874 *
875 */
876 void MACvDisableKeyEntry(struct vnt_private *priv, unsigned int uEntryIdx)
877 {
878 void __iomem *io_base = priv->PortOffset;
879 unsigned short wOffset;
880
881 wOffset = MISCFIFO_KEYETRY0;
882 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
883
884 VNSvOutPortW(io_base + MAC_REG_MISCFFNDEX, wOffset);
885 VNSvOutPortD(io_base + MAC_REG_MISCFFDATA, 0);
886 VNSvOutPortW(io_base + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
887 }
This page took 0.048659 seconds and 6 git commands to generate.