1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#include "tmacro.h"
42#include "mac.h"
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59bool MACbIsRegBitsOff(struct vnt_private *priv, unsigned char byRegOfs,
60 unsigned char byTestBits)
61{
62 void __iomem *io_base = priv->PortOffset;
63
64 return !(ioread8(io_base + byRegOfs) & byTestBits);
65}
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80bool MACbIsIntDisable(struct vnt_private *priv)
81{
82 void __iomem *io_base = priv->PortOffset;
83
84 if (ioread32(io_base + MAC_REG_IMR))
85 return false;
86
87 return true;
88}
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104void MACvSetShortRetryLimit(struct vnt_private *priv,
105 unsigned char byRetryLimit)
106{
107 void __iomem *io_base = priv->PortOffset;
108
109 iowrite8(byRetryLimit, io_base + MAC_REG_SRT);
110}
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126void MACvSetLongRetryLimit(struct vnt_private *priv,
127 unsigned char byRetryLimit)
128{
129 void __iomem *io_base = priv->PortOffset;
130
131 iowrite8(byRetryLimit, io_base + MAC_REG_LRT);
132}
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148void MACvSetLoopbackMode(struct vnt_private *priv, unsigned char byLoopbackMode)
149{
150 void __iomem *io_base = priv->PortOffset;
151
152 byLoopbackMode <<= 6;
153
154 iowrite8((ioread8(io_base + MAC_REG_TEST) & 0x3f) | byLoopbackMode,
155 io_base + MAC_REG_TEST);
156}
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171void MACvSaveContext(struct vnt_private *priv, unsigned char *cxt_buf)
172{
173 void __iomem *io_base = priv->PortOffset;
174
175
176 memcpy_fromio(cxt_buf, io_base, MAC_MAX_CONTEXT_SIZE_PAGE0);
177
178 MACvSelectPage1(io_base);
179
180
181 memcpy_fromio(cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0, io_base,
182 MAC_MAX_CONTEXT_SIZE_PAGE1);
183
184 MACvSelectPage0(io_base);
185}
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201void MACvRestoreContext(struct vnt_private *priv, unsigned char *cxt_buf)
202{
203 void __iomem *io_base = priv->PortOffset;
204
205 MACvSelectPage1(io_base);
206
207 memcpy_toio(io_base, cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0,
208 MAC_MAX_CONTEXT_SIZE_PAGE1);
209
210 MACvSelectPage0(io_base);
211
212
213 memcpy_toio(io_base + MAC_REG_RCR, cxt_buf + MAC_REG_RCR,
214 MAC_REG_ISR - MAC_REG_RCR);
215
216
217 memcpy_toio(io_base + MAC_REG_LRT, cxt_buf + MAC_REG_LRT,
218 MAC_REG_PAGE1SEL - MAC_REG_LRT);
219
220 iowrite8(*(cxt_buf + MAC_REG_CFG), io_base + MAC_REG_CFG);
221
222
223 memcpy_toio(io_base + MAC_REG_PSCFG, cxt_buf + MAC_REG_PSCFG,
224 MAC_REG_BBREGCTL - MAC_REG_PSCFG);
225
226
227 iowrite32(*(u32 *)(cxt_buf + MAC_REG_TXDMAPTR0),
228 io_base + MAC_REG_TXDMAPTR0);
229 iowrite32(*(u32 *)(cxt_buf + MAC_REG_AC0DMAPTR),
230 io_base + MAC_REG_AC0DMAPTR);
231 iowrite32(*(u32 *)(cxt_buf + MAC_REG_BCNDMAPTR),
232 io_base + MAC_REG_BCNDMAPTR);
233 iowrite32(*(u32 *)(cxt_buf + MAC_REG_RXDMAPTR0),
234 io_base + MAC_REG_RXDMAPTR0);
235 iowrite32(*(u32 *)(cxt_buf + MAC_REG_RXDMAPTR1),
236 io_base + MAC_REG_RXDMAPTR1);
237}
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252bool MACbSoftwareReset(struct vnt_private *priv)
253{
254 void __iomem *io_base = priv->PortOffset;
255 unsigned short ww;
256
257
258 iowrite8(0x01, io_base + MAC_REG_HOSTCR);
259
260 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
261 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_SOFTRST))
262 break;
263 }
264 if (ww == W_MAX_TIMEOUT)
265 return false;
266 return true;
267}
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283bool MACbSafeSoftwareReset(struct vnt_private *priv)
284{
285 unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0 + MAC_MAX_CONTEXT_SIZE_PAGE1];
286 bool bRetVal;
287
288
289
290
291
292
293 MACvSaveContext(priv, abyTmpRegData);
294
295 bRetVal = MACbSoftwareReset(priv);
296
297 MACvRestoreContext(priv, abyTmpRegData);
298
299 return bRetVal;
300}
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315bool MACbSafeRxOff(struct vnt_private *priv)
316{
317 void __iomem *io_base = priv->PortOffset;
318 unsigned short ww;
319
320
321
322
323 iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_RXDMACTL0);
324 iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_RXDMACTL1);
325 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
326 if (!(ioread32(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
327 break;
328 }
329 if (ww == W_MAX_TIMEOUT) {
330 pr_debug(" DBG_PORT80(0x10)\n");
331 return false;
332 }
333 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
334 if (!(ioread32(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
335 break;
336 }
337 if (ww == W_MAX_TIMEOUT) {
338 pr_debug(" DBG_PORT80(0x11)\n");
339 return false;
340 }
341
342
343 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_RXON);
344
345 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
346 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_RXONST))
347 break;
348 }
349 if (ww == W_MAX_TIMEOUT) {
350 pr_debug(" DBG_PORT80(0x12)\n");
351 return false;
352 }
353 return true;
354}
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369bool MACbSafeTxOff(struct vnt_private *priv)
370{
371 void __iomem *io_base = priv->PortOffset;
372 unsigned short ww;
373
374
375
376 iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_TXDMACTL0);
377
378 iowrite32(DMACTL_CLRRUN, io_base + MAC_REG_AC0DMACTL);
379
380 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
381 if (!(ioread32(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
382 break;
383 }
384 if (ww == W_MAX_TIMEOUT) {
385 pr_debug(" DBG_PORT80(0x20)\n");
386 return false;
387 }
388 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
389 if (!(ioread32(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
390 break;
391 }
392 if (ww == W_MAX_TIMEOUT) {
393 pr_debug(" DBG_PORT80(0x21)\n");
394 return false;
395 }
396
397
398 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_TXON);
399
400
401 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
402 if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_TXONST))
403 break;
404 }
405 if (ww == W_MAX_TIMEOUT) {
406 pr_debug(" DBG_PORT80(0x24)\n");
407 return false;
408 }
409 return true;
410}
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425bool MACbSafeStop(struct vnt_private *priv)
426{
427 void __iomem *io_base = priv->PortOffset;
428
429 MACvRegBitsOff(io_base, MAC_REG_TCR, TCR_AUTOBCNTX);
430
431 if (!MACbSafeRxOff(priv)) {
432 pr_debug(" MACbSafeRxOff == false)\n");
433 MACbSafeSoftwareReset(priv);
434 return false;
435 }
436 if (!MACbSafeTxOff(priv)) {
437 pr_debug(" MACbSafeTxOff == false)\n");
438 MACbSafeSoftwareReset(priv);
439 return false;
440 }
441
442 MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_MACEN);
443
444 return true;
445}
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460bool MACbShutdown(struct vnt_private *priv)
461{
462 void __iomem *io_base = priv->PortOffset;
463
464 MACvIntDisable(io_base);
465 MACvSetLoopbackMode(priv, MAC_LB_INTERNAL);
466
467 if (!MACbSafeStop(priv)) {
468 MACvSetLoopbackMode(priv, MAC_LB_NONE);
469 return false;
470 }
471 MACvSetLoopbackMode(priv, MAC_LB_NONE);
472 return true;
473}
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488void MACvInitialize(struct vnt_private *priv)
489{
490 void __iomem *io_base = priv->PortOffset;
491
492 MACvClearStckDS(io_base);
493
494 iowrite8(PME_OVR, io_base + MAC_REG_PMC1);
495
496
497
498 MACbSoftwareReset(priv);
499
500
501 iowrite8(TFTCTL_TSFCNTRST, io_base + MAC_REG_TFTCTL);
502
503 iowrite8(TFTCTL_TSFCNTREN, io_base + MAC_REG_TFTCTL);
504}
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520void MACvSetCurrRx0DescAddr(struct vnt_private *priv, u32 curr_desc_addr)
521{
522 void __iomem *io_base = priv->PortOffset;
523 unsigned short ww;
524 unsigned char org_dma_ctl;
525
526 org_dma_ctl = ioread8(io_base + MAC_REG_RXDMACTL0);
527 if (org_dma_ctl & DMACTL_RUN)
528 iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL0 + 2);
529
530 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
531 if (!(ioread8(io_base + MAC_REG_RXDMACTL0) & DMACTL_RUN))
532 break;
533 }
534
535 iowrite32(curr_desc_addr, io_base + MAC_REG_RXDMAPTR0);
536 if (org_dma_ctl & DMACTL_RUN)
537 iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL0);
538}
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554void MACvSetCurrRx1DescAddr(struct vnt_private *priv, u32 curr_desc_addr)
555{
556 void __iomem *io_base = priv->PortOffset;
557 unsigned short ww;
558 unsigned char org_dma_ctl;
559
560 org_dma_ctl = ioread8(io_base + MAC_REG_RXDMACTL1);
561 if (org_dma_ctl & DMACTL_RUN)
562 iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL1 + 2);
563
564 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
565 if (!(ioread8(io_base + MAC_REG_RXDMACTL1) & DMACTL_RUN))
566 break;
567 }
568
569 iowrite32(curr_desc_addr, io_base + MAC_REG_RXDMAPTR1);
570 if (org_dma_ctl & DMACTL_RUN)
571 iowrite8(DMACTL_RUN, io_base + MAC_REG_RXDMACTL1);
572}
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588void MACvSetCurrTx0DescAddrEx(struct vnt_private *priv,
589 u32 curr_desc_addr)
590{
591 void __iomem *io_base = priv->PortOffset;
592 unsigned short ww;
593 unsigned char org_dma_ctl;
594
595 org_dma_ctl = ioread8(io_base + MAC_REG_TXDMACTL0);
596 if (org_dma_ctl & DMACTL_RUN)
597 iowrite8(DMACTL_RUN, io_base + MAC_REG_TXDMACTL0 + 2);
598
599 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
600 if (!(ioread8(io_base + MAC_REG_TXDMACTL0) & DMACTL_RUN))
601 break;
602 }
603
604 iowrite32(curr_desc_addr, io_base + MAC_REG_TXDMAPTR0);
605 if (org_dma_ctl & DMACTL_RUN)
606 iowrite8(DMACTL_RUN, io_base + MAC_REG_TXDMACTL0);
607}
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624void MACvSetCurrAC0DescAddrEx(struct vnt_private *priv,
625 u32 curr_desc_addr)
626{
627 void __iomem *io_base = priv->PortOffset;
628 unsigned short ww;
629 unsigned char org_dma_ctl;
630
631 org_dma_ctl = ioread8(io_base + MAC_REG_AC0DMACTL);
632 if (org_dma_ctl & DMACTL_RUN)
633 iowrite8(DMACTL_RUN, io_base + MAC_REG_AC0DMACTL + 2);
634
635 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
636 if (!(ioread8(io_base + MAC_REG_AC0DMACTL) & DMACTL_RUN))
637 break;
638 }
639 if (ww == W_MAX_TIMEOUT)
640 pr_debug(" DBG_PORT80(0x26)\n");
641 iowrite32(curr_desc_addr, io_base + MAC_REG_AC0DMAPTR);
642 if (org_dma_ctl & DMACTL_RUN)
643 iowrite8(DMACTL_RUN, io_base + MAC_REG_AC0DMACTL);
644}
645
646void MACvSetCurrTXDescAddr(int iTxType, struct vnt_private *priv,
647 u32 curr_desc_addr)
648{
649 if (iTxType == TYPE_AC0DMA)
650 MACvSetCurrAC0DescAddrEx(priv, curr_desc_addr);
651 else if (iTxType == TYPE_TXDMA0)
652 MACvSetCurrTx0DescAddrEx(priv, curr_desc_addr);
653}
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669void MACvTimer0MicroSDelay(struct vnt_private *priv, unsigned int uDelay)
670{
671 void __iomem *io_base = priv->PortOffset;
672 unsigned char byValue;
673 unsigned int uu, ii;
674
675 iowrite8(0, io_base + MAC_REG_TMCTL0);
676 iowrite32(uDelay, io_base + MAC_REG_TMDATA0);
677 iowrite8((TMCTL_TMD | TMCTL_TE), io_base + MAC_REG_TMCTL0);
678 for (ii = 0; ii < 66; ii++) {
679 for (uu = 0; uu < uDelay; uu++) {
680 byValue = ioread8(io_base + MAC_REG_TMCTL0);
681 if ((byValue == 0) ||
682 (byValue & TMCTL_TSUSP)) {
683 iowrite8(0, io_base + MAC_REG_TMCTL0);
684 return;
685 }
686 }
687 }
688 iowrite8(0, io_base + MAC_REG_TMCTL0);
689}
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705void MACvOneShotTimer1MicroSec(struct vnt_private *priv,
706 unsigned int uDelayTime)
707{
708 void __iomem *io_base = priv->PortOffset;
709
710 iowrite8(0, io_base + MAC_REG_TMCTL1);
711 iowrite32(uDelayTime, io_base + MAC_REG_TMDATA1);
712 iowrite8((TMCTL_TMD | TMCTL_TE), io_base + MAC_REG_TMCTL1);
713}
714
715void MACvSetMISCFifo(struct vnt_private *priv, unsigned short offset,
716 u32 data)
717{
718 void __iomem *io_base = priv->PortOffset;
719
720 if (offset > 273)
721 return;
722 iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
723 iowrite32(data, io_base + MAC_REG_MISCFFDATA);
724 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
725}
726
727bool MACbPSWakeup(struct vnt_private *priv)
728{
729 void __iomem *io_base = priv->PortOffset;
730 unsigned int ww;
731
732 if (MACbIsRegBitsOff(priv, MAC_REG_PSCTL, PSCTL_PS))
733 return true;
734
735
736 MACvRegBitsOff(io_base, MAC_REG_PSCTL, PSCTL_PSEN);
737
738
739 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
740 if (ioread8(io_base + MAC_REG_PSCTL) & PSCTL_WAKEDONE)
741 break;
742 }
743 if (ww == W_MAX_TIMEOUT) {
744 pr_debug(" DBG_PORT80(0x33)\n");
745 return false;
746 }
747 return true;
748}
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765void MACvSetKeyEntry(struct vnt_private *priv, unsigned short wKeyCtl,
766 unsigned int uEntryIdx, unsigned int uKeyIdx,
767 unsigned char *pbyAddr, u32 *pdwKey,
768 unsigned char byLocalID)
769{
770 void __iomem *io_base = priv->PortOffset;
771 unsigned short offset;
772 u32 data;
773 int ii;
774
775 if (byLocalID <= 1)
776 return;
777
778 pr_debug("%s\n", __func__);
779 offset = MISCFIFO_KEYETRY0;
780 offset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
781
782 data = 0;
783 data |= wKeyCtl;
784 data <<= 16;
785 data |= MAKEWORD(*(pbyAddr + 4), *(pbyAddr + 5));
786 pr_debug("1. offset: %d, Data: %X, KeyCtl:%X\n",
787 offset, data, wKeyCtl);
788
789 iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
790 iowrite32(data, io_base + MAC_REG_MISCFFDATA);
791 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
792 offset++;
793
794 data = 0;
795 data |= *(pbyAddr + 3);
796 data <<= 8;
797 data |= *(pbyAddr + 2);
798 data <<= 8;
799 data |= *(pbyAddr + 1);
800 data <<= 8;
801 data |= *pbyAddr;
802 pr_debug("2. offset: %d, Data: %X\n", offset, data);
803
804 iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
805 iowrite32(data, io_base + MAC_REG_MISCFFDATA);
806 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
807 offset++;
808
809 offset += (uKeyIdx * 4);
810 for (ii = 0; ii < 4; ii++) {
811
812 pr_debug("3.(%d) offset: %d, Data: %X\n",
813 ii, offset + ii, *pdwKey);
814 iowrite16(offset + ii, io_base + MAC_REG_MISCFFNDEX);
815 iowrite32(*pdwKey++, io_base + MAC_REG_MISCFFDATA);
816 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
817 }
818}
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834void MACvDisableKeyEntry(struct vnt_private *priv, unsigned int uEntryIdx)
835{
836 void __iomem *io_base = priv->PortOffset;
837 unsigned short offset;
838
839 offset = MISCFIFO_KEYETRY0;
840 offset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
841
842 iowrite16(offset, io_base + MAC_REG_MISCFFNDEX);
843 iowrite32(0, io_base + MAC_REG_MISCFFDATA);
844 iowrite16(MISCFFCTL_WRITE, io_base + MAC_REG_MISCFFCTL);
845}
846