-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrt2880_eth.c
More file actions
3651 lines (3156 loc) · 117 KB
/
rt2880_eth.c
File metadata and controls
3651 lines (3156 loc) · 117 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <common.h>
#include <command.h>
#if defined (CONFIG_COMMANDS) && defined(CONFIG_RT2880_ETH)
#include <malloc.h>
#include <net.h>
#include <asm/addrspace.h>
#include <rt_mmap.h>
#undef DEBUG
#define BIT(x) ((1 << x))
/* ====================================== */
//GDMA1 uni-cast frames destination port
#define GDM_UFRC_P_CPU ((u32)(~(0x7 << 12)))
#define GDM_UFRC_P_GDMA1 (1 << 12)
#define GDM_UFRC_P_GDMA2 (2 << 12)
#define GDM_UFRC_P_DROP (7 << 12)
//GDMA1 broad-cast MAC address frames
#define GDM_BFRC_P_CPU ((u32)(~(0x7 << 8)))
#define GDM_BFRC_P_GDMA1 (1 << 8)
#define GDM_BFRC_P_GDMA2 (2 << 8)
#define GDM_BFRC_P_PPE (6 << 8)
#define GDM_BFRC_P_DROP (7 << 8)
//GDMA1 multi-cast MAC address frames
#define GDM_MFRC_P_CPU ((u32)(~(0x7 << 4)))
#define GDM_MFRC_P_GDMA1 (1 << 4)
#define GDM_MFRC_P_GDMA2 (2 << 4)
#define GDM_MFRC_P_PPE (6 << 4)
#define GDM_MFRC_P_DROP (7 << 4)
//GDMA1 other MAC address frames destination port
#define GDM_OFRC_P_CPU ((u32)(~(0x7)))
#define GDM_OFRC_P_GDMA1 1
#define GDM_OFRC_P_GDMA2 2
#define GDM_OFRC_P_PPE 6
#define GDM_OFRC_P_DROP 7
#define RST_DRX_IDX0 BIT(16)
#define RST_DTX_IDX0 BIT(0)
#define TX_WB_DDONE BIT(6)
#define RX_DMA_BUSY BIT(3)
#define TX_DMA_BUSY BIT(1)
#define RX_DMA_EN BIT(2)
#define TX_DMA_EN BIT(0)
#define GP1_FRC_EN BIT(15)
#define GP1_FC_TX BIT(11)
#define GP1_FC_RX BIT(10)
#define GP1_LNK_DWN BIT(9)
#define GP1_AN_OK BIT(8)
/*
* FE_INT_STATUS
*/
#define CNT_PPE_AF BIT(31)
#define CNT_GDM1_AF BIT(29)
#define PSE_P1_FC BIT(22)
#define PSE_P0_FC BIT(21)
#define PSE_FQ_EMPTY BIT(20)
#define GE1_STA_CHG BIT(18)
#define TX_COHERENT BIT(17)
#define RX_COHERENT BIT(16)
#define TX_DONE_INT1 BIT(9)
#define TX_DONE_INT0 BIT(8)
#define RX_DONE_INT0 BIT(2)
#define TX_DLY_INT BIT(1)
#define RX_DLY_INT BIT(0)
/*
* Ethernet chip registers.RT2880
*/
#if defined (RT5350_ASIC_BOARD) || defined (RT5350_FPGA_BOARD) || defined (MT7628_ASIC_BOARD) || defined (MT7628_FPGA_BOARD)
#define PDMA_RELATED 0x0800
/* 1. PDMA */
#define TX_BASE_PTR0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x000)
#define TX_MAX_CNT0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x004)
#define TX_CTX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x008)
#define TX_DTX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x00C)
#define TX_BASE_PTR1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x010)
#define TX_MAX_CNT1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x014)
#define TX_CTX_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x018)
#define TX_DTX_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x01C)
#define TX_BASE_PTR2 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x020)
#define TX_MAX_CNT2 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x024)
#define TX_CTX_IDX2 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x028)
#define TX_DTX_IDX2 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x02C)
#define TX_BASE_PTR3 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x030)
#define TX_MAX_CNT3 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x034)
#define TX_CTX_IDX3 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x038)
#define TX_DTX_IDX3 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x03C)
#define RX_BASE_PTR0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x100)
#define RX_MAX_CNT0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x104)
#define RX_CALC_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x108)
#define RX_DRX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x10C)
#define RX_BASE_PTR1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x110)
#define RX_MAX_CNT1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x114)
#define RX_CALC_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x118)
#define RX_DRX_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x11C)
#define PDMA_INFO (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x200)
#define PDMA_GLO_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x204)
#define PDMA_RST_IDX (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x208)
#define PDMA_RST_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RST_IDX)
#define DLY_INT_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x20C)
#define FREEQ_THRES (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x210)
#define INT_STATUS (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x220)
#define FE_INT_STATUS (INT_STATUS)
#define INT_MASK (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x228)
#define FE_INT_ENABLE (INT_MASK)
#define PDMA_WRR (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x280)
#define PDMA_SCH_CFG (PDMA_WRR)
#define SDM_RELATED 0x0C00
#define SDM_CON (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x00) //Switch DMA configuration
#define SDM_RRING (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x04) //Switch DMA Rx Ring
#define SDM_TRING (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x08) //Switch DMA Tx Ring
#define SDM_MAC_ADRL (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x0C) //Switch MAC address LSB
#define SDM_MAC_ADRH (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x10) //Switch MAC Address MSB
#define SDM_TPCNT (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x100) //Switch DMA Tx packet count
#define SDM_TBCNT (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x104) //Switch DMA Tx byte count
#define SDM_RPCNT (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x108) //Switch DMA rx packet count
#define SDM_RBCNT (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x10C) //Switch DMA rx byte count
#define SDM_CS_ERR (RALINK_FRAME_ENGINE_BASE + SDM_RELATED+0x110) //Switch DMA rx checksum error count
#elif defined (RT6855_ASIC_BOARD) || defined (RT6855_FPGA_BOARD) || \
defined (RT6855A_FPGA_BOARD) || defined (RT6855A_ASIC_BOARD) || \
defined (MT7620_ASIC_BOARD) || defined (MT7620_FPGA_BOARD) || \
defined (MT7621_ASIC_BOARD) || defined (MT7621_FPGA_BOARD)
/* Old FE with New PDMA */
#define PDMA_RELATED 0x0800
/* 1. PDMA */
#define TX_BASE_PTR0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x000)
#define TX_MAX_CNT0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x004)
#define TX_CTX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x008)
#define TX_DTX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x00C)
#define TX_BASE_PTR1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x010)
#define TX_MAX_CNT1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x014)
#define TX_CTX_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x018)
#define TX_DTX_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x01C)
#define TX_BASE_PTR2 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x020)
#define TX_MAX_CNT2 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x024)
#define TX_CTX_IDX2 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x028)
#define TX_DTX_IDX2 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x02C)
#define TX_BASE_PTR3 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x030)
#define TX_MAX_CNT3 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x034)
#define TX_CTX_IDX3 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x038)
#define TX_DTX_IDX3 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x03C)
#define RX_BASE_PTR0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x100)
#define RX_MAX_CNT0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x104)
#define RX_CALC_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x108)
#define RX_DRX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x10C)
#define RX_BASE_PTR1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x110)
#define RX_MAX_CNT1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x114)
#define RX_CALC_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x118)
#define RX_DRX_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x11C)
#define PDMA_INFO (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x200)
#define PDMA_GLO_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x204)
#define PDMA_RST_IDX (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x208)
#define PDMA_RST_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RST_IDX)
#define DLY_INT_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x20C)
#define FREEQ_THRES (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x210)
#define INT_STATUS (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x220) /* FIXME */
#define INT_MASK (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x228) /* FIXME */
#define PDMA_WRR (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED+0x280)
#define PDMA_SCH_CFG (PDMA_WRR)
/* TODO: change FE_INT_STATUS->INT_STATUS
* FE_INT_ENABLE->INT_MASK */
#define MDIO_ACCESS RALINK_FRAME_ENGINE_BASE + 0x00
#define MDIO_CFG RALINK_FRAME_ENGINE_BASE + 0x04
#define FE_DMA_GLO_CFG RALINK_FRAME_ENGINE_BASE + 0x08
#define FE_RST_GLO RALINK_FRAME_ENGINE_BASE + 0x0C
#define FE_INT_STATUS RALINK_FRAME_ENGINE_BASE + 0x10
#define FE_INT_ENABLE RALINK_FRAME_ENGINE_BASE + 0x14
#define FC_DROP_STA RALINK_FRAME_ENGINE_BASE + 0x18
#define FOE_TS_T RALINK_FRAME_ENGINE_BASE + 0x1C
#if defined (MT7620_ASIC_BOARD) || defined (MT7620_FPGA_BOARD)
#define GDMA1_RELATED 0x0600
#define GDMA1_FWD_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x00)
#define GDMA1_SHRP_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x04)
#define GDMA1_MAC_ADRL (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x08)
#define GDMA1_MAC_ADRH (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x0C)
#elif defined (MT7621_ASIC_BOARD) || defined (MT7621_FPGA_BOARD)
#define PAD_RGMII2_MDIO_CFG RALINK_SYSCTL_BASE + 0x58
#define GDMA1_RELATED 0x0500
#define GDMA1_FWD_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x00)
#define GDMA1_SHRP_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x04)
#define GDMA1_MAC_ADRL (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x08)
#define GDMA1_MAC_ADRH (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x0C)
#define GDMA2_RELATED 0x1500
#define GDMA2_FWD_CFG (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x00)
#define GDMA2_SHRP_CFG (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x04)
#define GDMA2_MAC_ADRL (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x08)
#define GDMA2_MAC_ADRH (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x0C)
#else
#define GDMA1_RELATED 0x0020
#define GDMA1_FWD_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x00)
#define GDMA1_SCH_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x04)
#define GDMA1_SHRP_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x08)
#define GDMA1_MAC_ADRL (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x0C)
#define GDMA1_MAC_ADRH (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x10)
#endif
#define PSE_RELATED 0x0040
#define PSE_FQFC_CFG (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x00)
#define CDMA_FC_CFG (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x04)
#define GDMA1_FC_CFG (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x08)
#define GDMA2_FC_CFG (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x0C)
#define CDMA_OQ_STA (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x10)
#define GDMA1_OQ_STA (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x14)
#define GDMA2_OQ_STA (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x18)
#define PSE_IQ_STA (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x1C)
#define CDMA_RELATED 0x0080
#define CDMA_CSG_CFG (RALINK_FRAME_ENGINE_BASE + CDMA_RELATED + 0x00)
#define CDMA_SCH_CFG (RALINK_FRAME_ENGINE_BASE + CDMA_RELATED + 0x04)
#else
#define MDIO_ACCESS RALINK_FRAME_ENGINE_BASE + 0x00
#ifdef RT3883_USE_GE2
#define MDIO_CFG RALINK_FRAME_ENGINE_BASE + 0x18
#else
#define MDIO_CFG RALINK_FRAME_ENGINE_BASE + 0x04
#endif // RT3883_USE_GE2 //
#define FE_DMA_GLO_CFG RALINK_FRAME_ENGINE_BASE + 0x08
#define FE_RST_GLO RALINK_FRAME_ENGINE_BASE + 0x0C
#define FE_INT_STATUS RALINK_FRAME_ENGINE_BASE + 0x10
#define FE_INT_ENABLE RALINK_FRAME_ENGINE_BASE + 0x14
#define FC_DROP_STA RALINK_FRAME_ENGINE_BASE + 0x18
#define FOE_TS_T RALINK_FRAME_ENGINE_BASE + 0x1C
#define GDMA1_RELATED 0x0020
#define GDMA1_FWD_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x00)
#define GDMA1_SCH_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x04)
#define GDMA1_SHRP_CFG (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x08)
#define GDMA1_MAC_ADRL (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x0C)
#define GDMA1_MAC_ADRH (RALINK_FRAME_ENGINE_BASE + GDMA1_RELATED + 0x10)
#define GDMA2_RELATED 0x0060
#define GDMA2_FWD_CFG (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x00)
#define GDMA2_SCH_CFG (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x04)
#define GDMA2_SHRP_CFG (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x08)
#define GDMA2_MAC_ADRL (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x0C)
#define GDMA2_MAC_ADRH (RALINK_FRAME_ENGINE_BASE + GDMA2_RELATED + 0x10)
#define PSE_RELATED 0x0040
#define PSE_FQFC_CFG (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x00)
#define CDMA_FC_CFG (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x04)
#define GDMA1_FC_CFG (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x08)
#define GDMA2_FC_CFG (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x0C)
#define CDMA_OQ_STA (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x10)
#define GDMA1_OQ_STA (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x14)
#define GDMA2_OQ_STA (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x18)
#define PSE_IQ_STA (RALINK_FRAME_ENGINE_BASE + PSE_RELATED + 0x1C)
#define CDMA_RELATED 0x0080
#define CDMA_CSG_CFG (RALINK_FRAME_ENGINE_BASE + CDMA_RELATED + 0x00)
#define CDMA_SCH_CFG (RALINK_FRAME_ENGINE_BASE + CDMA_RELATED + 0x04)
#define PDMA_RELATED 0x0100
#define PDMA_GLO_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x00)
#define PDMA_RST_IDX (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x04)
#define PDMA_SCH_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x08)
#define DELAY_INT_CFG (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x0C)
#define TX_BASE_PTR0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x10)
#define TX_MAX_CNT0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x14)
#define TX_CTX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x18)
#define TX_DTX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x1C)
#define TX_BASE_PTR1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x20)
#define TX_MAX_CNT1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x24)
#define TX_CTX_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x28)
#define TX_DTX_IDX1 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x2C)
#define RX_BASE_PTR0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x30)
#define RX_MAX_CNT0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x34)
#define RX_CALC_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x38)
#define RX_DRX_IDX0 (RALINK_FRAME_ENGINE_BASE + PDMA_RELATED + 0x3C)
#endif
#define INTERNAL_LOOPBACK_ENABLE 1
#define INTERNAL_LOOPBACK_DISABLE 0
//#define CONFIG_UNH_TEST
#define TOUT_LOOP 1000
#define ENABLE 1
#define DISABLE 0
VALID_BUFFER_STRUCT rt2880_free_buf_list;
VALID_BUFFER_STRUCT rt2880_busing_buf_list;
static BUFFER_ELEM rt2880_free_buf[PKTBUFSRX];
/*=========================================
PDMA RX Descriptor Format define
=========================================*/
//-------------------------------------------------
typedef struct _PDMA_RXD_INFO1_ PDMA_RXD_INFO1_T;
struct _PDMA_RXD_INFO1_
{
unsigned int PDP0;
};
//-------------------------------------------------
typedef struct _PDMA_RXD_INFO2_ PDMA_RXD_INFO2_T;
struct _PDMA_RXD_INFO2_
{
unsigned int PLEN1 : 14;
unsigned int LS1 : 1;
unsigned int UN_USED : 1;
unsigned int PLEN0 : 14;
unsigned int LS0 : 1;
unsigned int DDONE_bit : 1;
};
//-------------------------------------------------
typedef struct _PDMA_RXD_INFO3_ PDMA_RXD_INFO3_T;
struct _PDMA_RXD_INFO3_
{
unsigned int PDP1;
};
//-------------------------------------------------
typedef struct _PDMA_RXD_INFO4_ PDMA_RXD_INFO4_T;
struct _PDMA_RXD_INFO4_
{
#if defined (PDMA_NEW)
unsigned int FOE_Entry : 14;
unsigned int CRSN : 5;
unsigned int SP : 3;
unsigned int L4F : 1;
unsigned int L4VLD : 1;
unsigned int TACK : 1;
unsigned int IP4F : 1;
unsigned int IP4 : 1;
unsigned int IP6 : 1;
unsigned int UN_USE1 : 4;
#else
unsigned int FOE_Entry : 14;
unsigned int FVLD : 1;
unsigned int UN_USE1 : 1;
unsigned int AI : 8;
unsigned int SP : 3;
unsigned int AIS : 1;
unsigned int L4F : 1;
unsigned int IPF : 1;
unsigned int L4FVLD_bit : 1;
unsigned int IPFVLD_bit : 1;
#endif
};
struct PDMA_rxdesc {
PDMA_RXD_INFO1_T rxd_info1;
PDMA_RXD_INFO2_T rxd_info2;
PDMA_RXD_INFO3_T rxd_info3;
PDMA_RXD_INFO4_T rxd_info4;
};
/*=========================================
PDMA TX Descriptor Format define
=========================================*/
//-------------------------------------------------
typedef struct _PDMA_TXD_INFO1_ PDMA_TXD_INFO1_T;
struct _PDMA_TXD_INFO1_
{
unsigned int SDP0;
};
//-------------------------------------------------
typedef struct _PDMA_TXD_INFO2_ PDMA_TXD_INFO2_T;
struct _PDMA_TXD_INFO2_
{
unsigned int SDL1 : 14;
unsigned int LS1_bit : 1;
unsigned int BURST_bit : 1;
unsigned int SDL0 : 14;
unsigned int LS0_bit : 1;
unsigned int DDONE_bit : 1;
};
//-------------------------------------------------
typedef struct _PDMA_TXD_INFO3_ PDMA_TXD_INFO3_T;
struct _PDMA_TXD_INFO3_
{
unsigned int SDP1;
};
//-------------------------------------------------
typedef struct _PDMA_TXD_INFO4_ PDMA_TXD_INFO4_T;
struct _PDMA_TXD_INFO4_
{
#if defined (MT7620_ASIC_BOARD) || defined (MT7620_FPGA_BOARD)
unsigned int VPRI_VIDX : 8;
unsigned int SIDX : 4;
unsigned int INSP : 1;
unsigned int RESV : 2;
unsigned int UDF : 5;
unsigned int FP_BMAP : 8;
unsigned int TSO : 1;
unsigned int TUI_CO : 3;
#elif defined (MT7621_ASIC_BOARD) || defined (MT7621_FPGA_BOARD)
unsigned int VLAN_TAG :16;
unsigned int INS : 1;
unsigned int RESV : 2;
unsigned int UDF : 6;
unsigned int FPORT : 3;
unsigned int TSO : 1;
unsigned int TUI_CO : 3;
#else
unsigned int VIDX : 4;
unsigned int VPRI : 3;
unsigned int INSV : 1;
unsigned int SIDX : 4;
unsigned int INSP : 1;
unsigned int UN_USE3 : 3;
unsigned int QN : 3;
unsigned int UN_USE2 : 5;
unsigned int PN : 3;
unsigned int UN_USE1 : 2;
unsigned int TUI_CO : 3;
#endif
};
struct PDMA_txdesc {
PDMA_TXD_INFO1_T txd_info1;
PDMA_TXD_INFO2_T txd_info2;
PDMA_TXD_INFO3_T txd_info3;
PDMA_TXD_INFO4_T txd_info4;
};
static struct PDMA_txdesc tx_ring0_cache[NUM_TX_DESC] __attribute__ ((aligned(32))); /* TX descriptor ring */
static struct PDMA_rxdesc rx_ring_cache[NUM_RX_DESC] __attribute__ ((aligned(32))); /* RX descriptor ring */
static int rx_dma_owner_idx0; /* Point to the next RXD DMA wants to use in RXD Ring#0. */
static int rx_wants_alloc_idx0; /* Point to the next RXD CPU wants to allocate to RXD Ring #0. */
static int tx_cpu_owner_idx0; /* Point to the next TXD in TXD_Ring0 CPU wants to use */
static volatile struct PDMA_rxdesc *rx_ring;
static volatile struct PDMA_txdesc *tx_ring0;
static char rxRingSize;
static char txRingSize;
static int rt2880_eth_init(struct eth_device* dev, bd_t* bis);
static int rt2880_eth_send(struct eth_device* dev, volatile void *packet, int length);
static int rt2880_eth_recv(struct eth_device* dev);
void rt2880_eth_halt(struct eth_device* dev);
#ifdef RALINK_MDIO_ACCESS_FUN
#ifdef RALINK_EPHY_INIT
int mii_mgr_read(u32 phy_addr, u32 phy_register, u32 *read_data);
int mii_mgr_write(u32 phy_addr, u32 phy_register, u32 write_data);
#else
#define mii_mgr_read(x,y,z) do{}while(0)
#define mii_mgr_write(x,y,z) do{}while(0)
#endif // RALINK_EPHY_INIT //
#else
#define mii_mgr_read(x,y,z) do{}while(0)
#define mii_mgr_write(x,y,z) do{}while(0)
#endif // RALINK_MDIO_ACCESS_FUN //
static int rt2880_eth_setup(struct eth_device* dev);
static int rt2880_eth_initd;
char console_buffer[CFG_CBSIZE]; /* console I/O buffer */
#define phys_to_bus(a) (a & 0x1FFFFFFF)
#define PCI_WAIT_INPUT_CHAR(ch) while((ch = getc())== 0)
struct eth_device* rt2880_pdev;
volatile uchar *PKT_HEADER_Buf;// = (uchar *)CFG_EMBEDED_SRAM_SDP0_BUF_START;
static volatile uchar PKT_HEADER_Buf_Pool[(PKTBUFSRX * PKTSIZE_ALIGN) + PKTALIGN];
extern volatile uchar *NetTxPacket; /* THE transmit packet */
extern volatile uchar *PktBuf;
extern volatile uchar Pkt_Buf_Pool[];
extern int rtl8367_gsw_init_post(void);
#define PIODIR_R (RALINK_PIO_BASE + 0X24)
#define PIODATA_R (RALINK_PIO_BASE + 0X20)
#define PIODIR3924_R (RALINK_PIO_BASE + 0x4c)
#define PIODATA3924_R (RALINK_PIO_BASE + 0x48)
#define FREEBUF_OFFSET(CURR) ((int)(((0x0FFFFFFF & (u32)CURR) - (u32) (0x0FFFFFFF & (u32) rt2880_free_buf[0].pbuf)) / 1536))
void START_ETH(struct eth_device *dev ) {
s32 omr;
omr=RALINK_REG(PDMA_GLO_CFG);
udelay(100);
omr |= TX_WB_DDONE | RX_DMA_EN | TX_DMA_EN ;
RALINK_REG(PDMA_GLO_CFG)=omr;
udelay(500);
}
void STOP_ETH(struct eth_device *dev)
{
s32 omr;
omr=RALINK_REG(PDMA_GLO_CFG);
udelay(100);
omr &= ~(TX_WB_DDONE | RX_DMA_EN | TX_DMA_EN) ;
RALINK_REG(PDMA_GLO_CFG)=omr;
udelay(500);
}
BUFFER_ELEM *rt2880_free_buf_entry_dequeue(VALID_BUFFER_STRUCT *hdr)
{
int zero = 0; /* causes most compilers to place this */
/* value in a register only once */
BUFFER_ELEM *node;
/* Make sure we were not passed a null pointer. */
if (!hdr) {
return (NULL);
}
/* If there is a node in the list we want to remove it. */
if (hdr->head) {
/* Get the node to be removed */
node = hdr->head;
/* Make the hdr point the second node in the list */
hdr->head = node->next;
/* If this is the last node the headers tail pointer needs to be nulled
We do not need to clear the node's next since it is already null */
if (!(hdr->head)) {
hdr->tail = (BUFFER_ELEM *)zero;
}
node->next = (BUFFER_ELEM *)zero;
}
else {
node = NULL;
return (node);
}
/* Restore the previous interrupt lockout level. */
/* Return a pointer to the removed node */
//shnat_validation_flow_table_entry[node->index].state = SHNAT_FLOW_TABLE_NODE_USED;
return (node);
}
static BUFFER_ELEM *rt2880_free_buf_entry_enqueue(VALID_BUFFER_STRUCT *hdr, BUFFER_ELEM *item)
{
int zero =0;
if (!hdr) {
return (NULL);
}
if (item != NULL)
{
/* Temporarily lockout interrupts to protect global buffer variables. */
// Sys_Interrupt_Disable_Save_Flags(&cpsr_flags);
/* Set node's next to point at NULL */
item->next = (BUFFER_ELEM *)zero;
/* If there is currently a node in the linked list, we want to add the
new node to the end. */
if (hdr->head) {
/* Make the last node's next point to the new node. */
hdr->tail->next = item;
/* Make the roots tail point to the new node */
hdr->tail = item;
}
else {
/* If the linked list was empty, we want both the root's head and
tial to point to the new node. */
hdr->head = item;
hdr->tail = item;
}
/* Restore the previous interrupt lockout level. */
}
else
{
printf("\n shnat_flow_table_free_entry_enqueue is called,item== NULL \n");
}
return(item);
} /* MEM_Buffer_Enqueue */
int rt2880_eth_initialize(bd_t *bis)
{
struct eth_device* dev;
int i;
u32 regValue;
if (!(dev = (struct eth_device *) malloc (sizeof *dev))) {
printf("Failed to allocate memory\n");
return 0;
}
memset(dev, 0, sizeof(*dev));
sprintf(dev->name, "eth2");
dev->iobase = RALINK_FRAME_ENGINE_BASE;
dev->init = rt2880_eth_init;
dev->halt = rt2880_eth_halt;
dev->send = rt2880_eth_send;
dev->recv = rt2880_eth_recv;
eth_register(dev);
rt2880_pdev = dev;
rt2880_eth_initd =0;
PktBuf = Pkt_Buf_Pool;
PKT_HEADER_Buf = PKT_HEADER_Buf_Pool;
NetTxPacket = NULL;
rx_ring = (struct PDMA_rxdesc *)KSEG1ADDR((ulong)&rx_ring_cache[0]);
tx_ring0 = (struct PDMA_txdesc *)KSEG1ADDR((ulong)&tx_ring0_cache[0]);
rt2880_free_buf_list.head = NULL;
rt2880_free_buf_list.tail = NULL;
rt2880_busing_buf_list.head = NULL;
rt2880_busing_buf_list.tail = NULL;
//2880_free_buf
/*
* Setup packet buffers, aligned correctly.
*/
rt2880_free_buf[0].pbuf = (unsigned char *)(&PktBuf[0] + (PKTALIGN - 1));
rt2880_free_buf[0].pbuf -= (ulong)rt2880_free_buf[0].pbuf % PKTALIGN;
rt2880_free_buf[0].next = NULL;
rt2880_free_buf_entry_enqueue(&rt2880_free_buf_list,&rt2880_free_buf[0]);
#ifdef DEBUG
printf("\n rt2880_free_buf[0].pbuf = 0x%08X \n",rt2880_free_buf[0].pbuf);
#endif
for (i = 1; i < PKTBUFSRX; i++) {
rt2880_free_buf[i].pbuf = rt2880_free_buf[0].pbuf + (i)*PKTSIZE_ALIGN;
rt2880_free_buf[i].next = NULL;
#ifdef DEBUG
printf("\n rt2880_free_buf[%d].pbuf = 0x%08X\n",i,rt2880_free_buf[i].pbuf);
#endif
rt2880_free_buf_entry_enqueue(&rt2880_free_buf_list,&rt2880_free_buf[i]);
}
for (i = 0; i < PKTBUFSRX; i++)
{
rt2880_free_buf[i].tx_idx = NUM_TX_DESC;
#ifdef DEBUG
printf("\n rt2880_free_buf[%d] = 0x%08X,rt2880_free_buf[%d].next=0x%08X \n",i,&rt2880_free_buf[i],i,rt2880_free_buf[i].next);
#endif
}
#if defined (RT3052_ASIC_BOARD) || defined (RT3052_FPGA_BOARD) || \
defined (RT3883_ASIC_BOARD) || defined (RT3883_FPGA_BOARD)
//set clock resolution
extern unsigned long mips_bus_feq;
regValue = le32_to_cpu(*(volatile u_long *)(RALINK_FRAME_ENGINE_BASE + 0x0008));
regValue |= ((mips_bus_feq/1000000) << 8);
*((volatile u_long *)(RALINK_FRAME_ENGINE_BASE + 0x0008)) = cpu_to_le32(regValue);
#endif
return 1;
}
static int rt2880_eth_init(struct eth_device* dev, bd_t* bis)
{
if(rt2880_eth_initd == 0)
{
rt2880_eth_setup(dev);
}
else
{
START_ETH(dev);
}
rt2880_eth_initd = 1;
return (1);
}
#if defined (RT6855A_ASIC_BOARD) || (RT6855A_FPGA_BOARD) ||\
defined (MT7620_ASIC_BOARD) || defined (MT7620_FPGA_BOARD)
void IsSwitchVlanTableBusy(void)
{
int j = 0;
unsigned int value = 0;
for (j = 0; j < 20; j++) {
value = RALINK_REG(RALINK_ETH_SW_BASE+0x90); //VTCR
if ((value & 0x80000000) == 0 ){ //table busy
break;
}
udelay(1000);
}
if (j == 20)
printf("set vlan timeout.\n");
}
#elif defined (MT7621_ASIC_BOARD) || defined (MT7621_FPGA_BOARD)
void IsSwitchVlanTableBusy(void)
{
int j = 0;
unsigned int value = 0;
for (j = 0; j < 20; j++) {
mii_mgr_read(31, 0x90, &value);
if ((value & 0x80000000) == 0 ){ //table busy
break;
}
udelay(70000);
}
if (j == 20)
printf("set vlan timeout value=0x%x.\n", value);
}
#endif
void LANWANPartition(void)
{
unsigned int i;
#ifdef MAC_TO_100SW_MODE
int sw_id = 0;
mii_mgr_read(29, 31, &sw_id);
#ifdef RALINK_DEMO_BOARD_PVLAN
if (sw_id == 0x175c) {
//disable tagged VLAN
mii_mgr_write(29, 23, 0);
//WLLLL, wan at P0, demo board
mii_mgr_write(29, 19, 0x809c);
mii_mgr_write(29, 20, 0x9a96);
mii_mgr_write(29, 21, 0x8e00);
mii_mgr_write(29, 22, 0x8420);
}
else {
mii_mgr_write(20, 13, 0x21);
mii_mgr_write(22, 14, 0x2002);
mii_mgr_write(22, 15, 0x1001);
mii_mgr_write(22, 16, 0x1001);
mii_mgr_write(22, 17, 0x1001);
mii_mgr_write(22, 18, 0x1001);
mii_mgr_write(22, 19, 0x1001);
mii_mgr_write(23, 0, 0x3e21);
mii_mgr_write(23, 1, 0x3e3e);
mii_mgr_write(23, 2, 0x3e3e);
mii_mgr_write(23, 16, 0x3f3f);
mii_mgr_write(23, 17, 0x3f3f);
mii_mgr_write(23, 18, 0x3f3f);
}
#endif
#ifdef RALINK_EV_BOARD_PVLAN
if (sw_id == 0x175c) {
//disable tagged VLAN
mii_mgr_write(29, 23, 0);
//LLLLW, wan at P4, ev board
mii_mgr_write(29, 19, 0x8e8d);
mii_mgr_write(29, 20, 0x8b87);
mii_mgr_write(29, 21, 0x8000);
mii_mgr_write(29, 22, 0x8420);
}
else {
mii_mgr_write(20, 13, 0x21);
mii_mgr_write(22, 14, 0x1001);
mii_mgr_write(22, 15, 0x1001);
mii_mgr_write(22, 16, 0x1001);
mii_mgr_write(22, 17, 0x1001);
mii_mgr_write(22, 18, 0x2002);
mii_mgr_write(22, 19, 0x1001);
mii_mgr_write(23, 0, 0x2f2f);
mii_mgr_write(23, 1, 0x2f2f);
mii_mgr_write(23, 2, 0x2f30);
mii_mgr_write(23, 16, 0x3f3f);
mii_mgr_write(23, 17, 0x3f3f);
mii_mgr_write(23, 18, 0x3f3f);
}
#endif
#endif // MAC_TO_100SW_MODE //
#if defined (RT3052_ASIC_BOARD) || defined (RT3052_FPGA_BOARD) || \
defined (RT3352_ASIC_BOARD) || defined (RT3352_FPGA_BOARD) || \
defined (RT5350_ASIC_BOARD) || defined (RT5350_FPGA_BOARD) || \
defined (MT7628_ASIC_BOARD) || defined (MT7628_FPGA_BOARD)
#ifdef RALINK_DEMO_BOARD_PVLAN
//WLLLL, wan at P0, demo board
*((volatile u32 *)(RALINK_ETH_SW_BASE + 0x40)) = 0x1002; //PVID
*((volatile u32 *)(RALINK_ETH_SW_BASE + 0x44)) = 0x1001; //PVID
*((volatile u32 *)(RALINK_ETH_SW_BASE + 0x48)) = 0x1001; //PVID
*((volatile u32 *)(RALINK_ETH_SW_BASE + 0x70)) = 0xffff417e; //VLAN member
#endif
#ifdef RALINK_EV_BOARD_PVLAN
//LLLLW, wan at P4, ev board
*((volatile u32 *)(RALINK_ETH_SW_BASE + 0x40)) = 0x1001; //PVID
*((volatile u32 *)(RALINK_ETH_SW_BASE + 0x44)) = 0x1001; //PVID
*((volatile u32 *)(RALINK_ETH_SW_BASE + 0x48)) = 0x1002; //PVID
*((volatile u32 *)(RALINK_ETH_SW_BASE + 0x70)) = 0xffff506f; //VLAN member
#endif
#if defined(EPHY_LINK_UP)
// turn on ESW PHY + restart AN
#if defined (ETH_ONE_PORT_ONLY)
mii_mgr_write(0, 0x0, 0x3300);
#else
for(i=0;i<=4;i++)
mii_mgr_write(i, 0x0, 0x3300);
#endif
#endif
#endif // (RT3052_ASIC_BOARD || RT3052_FPGA_BOARD || RT3352_ASIC_BOARD || RT3352_FPGA_BOARD)
#if defined (RT6855A_ASIC_BOARD) || (RT6855A_FPGA_BOARD) ||\
(defined (MT7620_ASIC_BOARD) && !defined(P5_RGMII_TO_MAC_MODE)) || defined (MT7620_FPGA_BOARD)
#ifdef RALINK_DEMO_BOARD_PVLAN
//WLLLL, wan at P0, demo board
//LAN/WAN ports as security mode
RALINK_REG(RALINK_ETH_SW_BASE+0x2004) = 0xff0003; //port0
RALINK_REG(RALINK_ETH_SW_BASE+0x2104) = 0xff0003; //port1
RALINK_REG(RALINK_ETH_SW_BASE+0x2204) = 0xff0003; //port2
RALINK_REG(RALINK_ETH_SW_BASE+0x2304) = 0xff0003; //port3
RALINK_REG(RALINK_ETH_SW_BASE+0x2404) = 0xff0003; //port4
RALINK_REG(RALINK_ETH_SW_BASE+0x2504) = 0xff0003; //port5
//set PVID
RALINK_REG(RALINK_ETH_SW_BASE+0x2014) = 0x10002; //port0
RALINK_REG(RALINK_ETH_SW_BASE+0x2114) = 0x10001; //port1
RALINK_REG(RALINK_ETH_SW_BASE+0x2214) = 0x10001; //port2
RALINK_REG(RALINK_ETH_SW_BASE+0x2314) = 0x10001; //port3
RALINK_REG(RALINK_ETH_SW_BASE+0x2414) = 0x10001; //port4
RALINK_REG(RALINK_ETH_SW_BASE+0x2514) = 0x10001; //port5
//VLAN member
RALINK_REG(RALINK_ETH_SW_BASE+0x94) = 0x40fe0001; //VAWD1
RALINK_REG(RALINK_ETH_SW_BASE+0x90) = 0x80001000; //VTCR
IsSwitchVlanTableBusy();
RALINK_REG(RALINK_ETH_SW_BASE+0x94) = 0x40c10001; //VAWD1
RALINK_REG(RALINK_ETH_SW_BASE+0x90) = 0x80001001; //VTCR
IsSwitchVlanTableBusy();
#endif
#ifdef RALINK_EV_BOARD_PVLAN
//LLLLW, wan at P4, ev board
//LAN/WAN ports as security mode
RALINK_REG(RALINK_ETH_SW_BASE+0x2004) = 0xff0003; //port0
RALINK_REG(RALINK_ETH_SW_BASE+0x2104) = 0xff0003; //port1
RALINK_REG(RALINK_ETH_SW_BASE+0x2204) = 0xff0003; //port2
RALINK_REG(RALINK_ETH_SW_BASE+0x2304) = 0xff0003; //port3
RALINK_REG(RALINK_ETH_SW_BASE+0x2404) = 0xff0003; //port4
RALINK_REG(RALINK_ETH_SW_BASE+0x2504) = 0xff0003; //port5
//set PVID
RALINK_REG(RALINK_ETH_SW_BASE+0x2014) = 0x10001; //port0
RALINK_REG(RALINK_ETH_SW_BASE+0x2114) = 0x10001; //port1
RALINK_REG(RALINK_ETH_SW_BASE+0x2214) = 0x10001; //port2
RALINK_REG(RALINK_ETH_SW_BASE+0x2314) = 0x10001; //port3
#if defined(P5_MAC_TO_PHY_MODE)
RALINK_REG(RALINK_ETH_SW_BASE+0x2414) = 0x10001; //port4
RALINK_REG(RALINK_ETH_SW_BASE+0x2514) = 0x10002; //port5 (WAN)
#else
RALINK_REG(RALINK_ETH_SW_BASE+0x2414) = 0x10002; //port4 (WAN)
RALINK_REG(RALINK_ETH_SW_BASE+0x2514) = 0x10001; //port5
#endif
//VLAN member
#if defined(P5_MAC_TO_PHY_MODE)
RALINK_REG(RALINK_ETH_SW_BASE+0x94) = 0x40df0001; //VAWD1
#else
RALINK_REG(RALINK_ETH_SW_BASE+0x94) = 0x40ef0001; //VAWD1
#endif
RALINK_REG(RALINK_ETH_SW_BASE+0x90) = 0x80001000; //VTCR
IsSwitchVlanTableBusy();
#if defined(P5_MAC_TO_PHY_MODE)
RALINK_REG(RALINK_ETH_SW_BASE+0x94) = 0x40e00001; //VAWD1
#else
RALINK_REG(RALINK_ETH_SW_BASE+0x94) = 0x40d00001; //VAWD1
#endif
RALINK_REG(RALINK_ETH_SW_BASE+0x90) = 0x80001001; //VTCR
IsSwitchVlanTableBusy();
#endif
#if defined(EPHY_LINK_UP)
// turn on ESW PHY + restart AN
#if defined(P4_MAC_TO_NONE_MODE)
for(i=0;i<=4;i++)
#else
for(i=0;i<=3;i++)
#endif
mii_mgr_write(i, 0x0, 0x3300);
#endif
#elif defined (MT7621_ASIC_BOARD) || defined (MT7621_FPGA_BOARD) ||\
(defined(MT7620_ASIC_BOARD) && defined(P5_RGMII_TO_MAC_MODE))
/*Set MT7530 */
#ifdef RALINK_DEMO_BOARD_PVLAN
printf("set LAN/WAN WLLLL\n");
//WLLLL, wan at P0, demo board
//LAN/WAN ports as security mode
mii_mgr_write(31, 0x2004, 0xff0003);//port0
mii_mgr_write(31, 0x2104, 0xff0003);//port1
mii_mgr_write(31, 0x2204, 0xff0003);//port2
mii_mgr_write(31, 0x2304, 0xff0003);//port3
mii_mgr_write(31, 0x2404, 0xff0003);//port4
//mii_mgr_write(31, 0x2504, 0xff0003);//port5
//mii_mgr_write(31, 0x2604, 0xff0003);//port5
//set PVID
mii_mgr_write(31, 0x2014, 0x10002);//port0
mii_mgr_write(31, 0x2114, 0x10001);//port1
mii_mgr_write(31, 0x2214, 0x10001);//port2
mii_mgr_write(31, 0x2314, 0x10001);//port3
mii_mgr_write(31, 0x2414, 0x10001);//port4
//mii_mgr_write(31, 0x2514, 0x10001);//port5
//mii_mgr_write(31, 0x2614, 0x10001);//port6
/*port6 */
//VLAN member
IsSwitchVlanTableBusy();
mii_mgr_write(31, 0x94, 0x407e0001);//VAWD1
mii_mgr_write(31, 0x90, 0x80001001);//VTCR, VID=1
IsSwitchVlanTableBusy();
mii_mgr_write(31, 0x94, 0x40610001);//VAWD1
mii_mgr_write(31, 0x90, 0x80001002);//VTCR, VID=2
IsSwitchVlanTableBusy();
#endif
#ifdef RALINK_EV_BOARD_PVLAN
printf("set LAN/WAN LLLLW\n");
//LLLLW, wan at P4, ev board
//LAN/WAN ports as security mode
mii_mgr_write(31, 0x2004, 0xff0003);//port0
mii_mgr_write(31, 0x2104, 0xff0003);//port1
mii_mgr_write(31, 0x2204, 0xff0003);//port2
mii_mgr_write(31, 0x2304, 0xff0003);//port3
mii_mgr_write(31, 0x2404, 0xff0003);//port4
// mii_mgr_write(31, 0x2504, 0xff0003);//port5
// mii_mgr_write(31, 0x2604, 0xff0003);//port6
//set PVID
mii_mgr_write(31, 0x2014, 0x10001);//port0
mii_mgr_write(31, 0x2114, 0x10001);//port1
mii_mgr_write(31, 0x2214, 0x10001);//port2
mii_mgr_write(31, 0x2314, 0x10001);//port3
mii_mgr_write(31, 0x2414, 0x10002);//port4
// mii_mgr_write(31, 0x2514, 0x10001);//port5
// mii_mgr_write(31, 0x2614, 0x10001);//port6
//VLAN member
IsSwitchVlanTableBusy();
mii_mgr_write(31, 0x94, 0x404f0001);//VAWD1
mii_mgr_write(31, 0x90, 0x80001001);//VTCR, VID=1
IsSwitchVlanTableBusy();
mii_mgr_write(31, 0x94, 0x40500001);//VAWD1
mii_mgr_write(31, 0x90, 0x80001002);//VTCR, VID=2
IsSwitchVlanTableBusy();
#endif
#if defined(EPHY_LINK_UP)
// turn on GSW PHY + restart AN