-
Notifications
You must be signed in to change notification settings - Fork 79
/
ksz_sw_9897.c
18735 lines (17028 loc) · 451 KB
/
ksz_sw_9897.c
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
/**
* Microchip gigabit switch common code
*
* Copyright (c) 2015-2019 Microchip Technology Inc.
* Tristram Ha <Tristram.Ha@microchip.com>
*
* Copyright (c) 2010-2015 Micrel, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* -------------------------------------------------------------------------- */
/* (288 - 24 - 4) / (8 * 3) */
#define MAX_IBA_MIB_ENTRIES 10
#define READ_MIB_ENTRY_SIZE 2
/* (288 - 24 - 4) / (8 * 6) */
#define MAX_IBA_MAC_ENTRIES 5
/* (288 - 24 - 4) / (8 * 6) */
#define MAX_IBA_VLAN_ENTRIES 5
#define READ_VLAN_ENTRY_SIZE 3
#define WRITE_VLAN_ENTRY_SIZE 4
#define MAX_SYSFS_BUF_SIZE (4080 - 80)
#if 1
#define USE_LOG_MASK
#endif
enum {
PROC_SW_INFO,
PROC_SW_VERSION,
PROC_SET_SW_DUPLEX,
PROC_SET_SW_SPEED,
PROC_SET_SW_FORCE,
PROC_SET_SW_FLOW_CTRL,
PROC_SET_SW_FEATURES,
PROC_SET_SW_OVERRIDES,
PROC_SET_SW_MIB,
PROC_SET_SW_REG,
PROC_SET_SW_VID,
PROC_DYNAMIC,
PROC_STATIC,
PROC_VLAN,
PROC_HSR,
PROC_SET_AGING,
PROC_SET_FAST_AGING,
PROC_SET_LINK_AGING,
PROC_SET_BROADCAST_STORM,
PROC_SET_MULTICAST_STORM,
PROC_SET_TX_RATE_QUEUE_BASED,
PROC_SET_DIFFSERV,
PROC_SET_802_1P,
PROC_ENABLE_VLAN,
PROC_SET_REPLACE_NULL_VID,
PROC_SET_DROP_INVALID_VID,
PROC_SET_MAC_ADDR,
PROC_SET_MIRROR_MODE,
PROC_SET_IGMP_SNOOP,
PROC_SET_IPV6_MLD_SNOOP,
PROC_SET_IPV6_MLD_OPTION,
PROC_SET_AGGR_BACKOFF,
PROC_SET_NO_EXC_DROP,
PROC_SET_JUMBO_PACKET,
PROC_SET_LEGAL_PACKET,
PROC_SET_LENGTH_CHECK,
PROC_SET_BACK_PRESSURE_MODE,
PROC_SET_SWITCH_FLOW_CTRL,
PROC_SET_SWITCH_HALF_DUPLEX,
PROC_SET_SWITCH_10_MBIT,
PROC_SET_FAIR_FLOW_CTRL,
PROC_SET_VLAN_BOUNDARY,
PROC_SET_DOUBLE_TAG,
PROC_SET_ISP_TAG,
PROC_SET_HSR_TAG,
PROC_SET_HSR_REDBOX_ID,
PROC_SET_HSR_NET_ID,
PROC_SET_MTU,
PROC_SET_FORWARD_UNKNOWN_UNICAST,
PROC_SET_UNKNOWN_UNICAST_PORTS,
PROC_SET_FORWARD_UNKNOWN_MULTICAST,
PROC_SET_UNKNOWN_MULTICAST_PORTS,
PROC_SET_FORWARD_UNKNOWN_VID,
PROC_SET_UNKNOWN_VID_PORTS,
PROC_SET_PASS_PAUSE,
PROC_ENABLE_PME,
PROC_ENABLE_PME_POLARITY,
PROC_GET_HOST_PORT,
PROC_GET_PORTS,
PROC_GET_DEV_START,
PROC_GET_VLAN_START,
PROC_GET_AVB,
PROC_GET_STP,
PROC_GET_TWO_DEV,
PROC_SET_AUTHEN,
PROC_SET_STATIC_FID,
PROC_SET_STATIC_USE_FID,
PROC_SET_STATIC_OVERRIDE,
PROC_SET_STATIC_VALID,
PROC_SET_STATIC_MSTP,
PROC_SET_STATIC_PRIO,
PROC_SET_STATIC_SRC,
PROC_SET_STATIC_DST,
PROC_SET_STATIC_PORTS,
PROC_SET_STATIC_MAC_ADDR,
PROC_SET_STATIC_TYPE,
PROC_SET_STATIC_INDEX,
PROC_SET_STATIC_INFO,
PROC_SET_VLAN_VALID,
PROC_SET_VLAN_PORTS,
PROC_SET_VLAN_UNTAG,
PROC_SET_VLAN_FID,
PROC_SET_VLAN_MSTP,
PROC_SET_VLAN_PRIO,
PROC_SET_VLAN_OPTION,
PROC_SET_VLAN_VID,
PROC_SET_VLAN_INFO,
PROC_SET_VID_2_FID,
PROC_SET_FID_2_MSTID,
#ifdef CONFIG_KSZ_STP
PROC_GET_STP_BR_INFO,
PROC_SET_STP_BR_ON,
PROC_SET_STP_BR_PRIO,
PROC_SET_STP_BR_FWD_DELAY,
PROC_SET_STP_BR_MAX_AGE,
PROC_SET_STP_BR_HELLO_TIME,
PROC_SET_STP_BR_TX_HOLD,
PROC_SET_STP_VERSION,
#ifdef CONFIG_KSZ_MSTP
PROC_SET_STP_BR_MAX_HOPS,
PROC_SET_STP_MSTI,
PROC_SET_STP_MSTI_VID,
PROC_SET_STP_MSTP_CFG,
PROC_SET_STP_MSTP_NAME,
#endif
#endif
#ifdef CONFIG_KSZ_MRP
#ifdef CONFIG_KSZ_MSRP
PROC_GET_MSRP_INFO,
PROC_SET_MSRP_ENABLED,
PROC_SET_MSRP_SR_A,
#endif
#endif
#ifdef CONFIG_KSZ_HSR
PROC_SET_HSR_VALID,
PROC_SET_HSR_AGE_CNT,
PROC_SET_HSR_PATH_ID,
PROC_SET_HSR_SRC_MAC_ADDR,
PROC_SET_HSR_INDEX,
PROC_SET_HSR_INFO,
PROC_GET_HSR_STATE,
#endif
PROC_SET_NO_COLOR,
PROC_SET_COLOR_RED,
PROC_SET_COLOR_YELLOW,
PROC_SET_COLOR_GREEN,
PROC_SET_VLAN_FILTERING_DYNAMIC,
PROC_SET_VLAN_FILTERING_STATIC,
};
enum {
PROC_SET_PORT_MIB,
PROC_SET_DEF_VID,
PROC_SET_MEMBER,
PROC_ENABLE_BROADCAST_STORM,
PROC_ENABLE_DIFFSERV,
PROC_ENABLE_802_1P,
PROC_ENABLE_VLAN_PRIO,
PROC_ENABLE_MAC_PRIO,
PROC_ENABLE_ACL_PRIO,
PROC_SET_HIGHEST_PRIO,
PROC_SET_OR_PRIO,
PROC_SET_PORT_BASED,
PROC_SET_DIS_NON_VID,
PROC_SET_INGRESS,
PROC_SET_DROP_NON_VLAN,
PROC_SET_DROP_TAG,
PROC_SET_REPLACE_VID,
PROC_SET_REPLACE_PRIO,
PROC_SET_MAC_BASED_802_1X,
PROC_SET_SRC_ADDR_FILTER,
PROC_SET_VLAN_LOOKUP_0,
PROC_SET_MSTP,
PROC_SET_RX,
PROC_SET_TX,
PROC_SET_LEARN,
PROC_SET_POWER,
PROC_ENABLE_PRIO_QUEUE,
PROC_ENABLE_RX_PRIO_RATE,
PROC_ENABLE_TX_PRIO_RATE,
PROC_SET_LIMIT,
PROC_SET_LIMIT_PORT_BASED,
PROC_SET_LIMIT_PACKET_BASED,
PROC_SET_LIMIT_FLOW_CTRL,
PROC_SET_LIMIT_CNT_IFG,
PROC_SET_LIMIT_CNT_PRE,
PROC_SET_RX_P0_RATE,
PROC_SET_RX_P1_RATE,
PROC_SET_RX_P2_RATE,
PROC_SET_RX_P3_RATE,
PROC_SET_RX_P4_RATE,
PROC_SET_RX_P5_RATE,
PROC_SET_RX_P6_RATE,
PROC_SET_RX_P7_RATE,
PROC_SET_TX_Q0_RATE,
PROC_SET_TX_Q1_RATE,
PROC_SET_TX_Q2_RATE,
PROC_SET_TX_Q3_RATE,
PROC_SET_COLOR_MAP,
PROC_SET_TC_MAP,
PROC_SET_MIRROR_PORT,
PROC_SET_MIRROR_RX,
PROC_SET_MIRROR_TX,
PROC_SET_BACK_PRESSURE,
PROC_SET_FORCE_FLOW_CTRL,
PROC_SET_PASS_ALL,
PROC_SET_TAIL_TAG,
PROC_SET_CUSTOM_VID,
PROC_SET_SR_1_VID,
PROC_SET_SR_2_VID,
PROC_SET_SR_1_TYPE,
PROC_SET_SR_2_TYPE,
PROC_SET_PME_CTRL,
PROC_SET_PME_STATUS,
PROC_SET_AUTHEN_MODE,
PROC_SET_ACL,
PROC_SET_ACL_FIRST_RULE,
PROC_SET_ACL_RULESET,
PROC_SET_ACL_MODE,
PROC_SET_ACL_ENABLE,
PROC_SET_ACL_SRC,
PROC_SET_ACL_EQUAL,
PROC_SET_ACL_MAC_ADDR,
PROC_SET_ACL_TYPE,
PROC_SET_ACL_CNT,
PROC_SET_ACL_MSEC,
PROC_SET_ACL_INTR_MODE,
PROC_SET_ACL_IP_ADDR,
PROC_SET_ACL_IP_MASK,
PROC_SET_ACL_PROTOCOL,
PROC_SET_ACL_SEQNUM,
PROC_SET_ACL_PORT_MODE,
PROC_SET_ACL_MAX_PORT,
PROC_SET_ACL_MIN_PORT,
PROC_SET_ACL_TCP_FLAG_ENABLE,
PROC_SET_ACL_TCP_FLAG,
PROC_SET_ACL_TCP_FLAG_MASK,
PROC_SET_ACL_PRIO_MODE,
PROC_SET_ACL_PRIO,
PROC_SET_ACL_VLAN_PRIO_REPLACE,
PROC_SET_ACL_VLAN_PRIO,
PROC_SET_ACL_MAP_MODE,
PROC_SET_ACL_PORTS,
PROC_SET_ACL_INDEX,
PROC_SET_ACL_ACTION_INDEX,
PROC_SET_ACL_ACTION,
PROC_SET_ACL_RULE_INDEX,
PROC_SET_ACL_INFO,
PROC_GET_ACL_TABLE,
PROC_SET_P_INDEX,
PROC_SET_Q_INDEX,
PROC_SET_POLICE_PACKET_TYPE,
PROC_SET_NON_DSCP_COLOR,
PROC_ENABLE_POLICE_DROP_ALL,
PROC_ENABLE_PORT_BASED_POLICING,
PROC_ENABLE_COLOR_MARK,
PROC_ENABLE_COLOR_REMAP,
PROC_ENABLE_DROP_SRP,
PROC_ENABLE_COLOR_AWARE,
PROC_ENABLE_POLICE,
PROC_SET_Q_CIR,
PROC_SET_Q_PIR,
PROC_SET_Q_CBS,
PROC_SET_Q_PBS,
PROC_SET_WRED_MAX_THRESHOLD,
PROC_SET_WRED_MIN_THRESHOLD,
PROC_SET_WRED_MULTIPLIER,
PROC_GET_WRED_AVG_SIZE,
PROC_SET_WRED_Q_MAX_THRESHOLD,
PROC_SET_WRED_Q_MIN_THRESHOLD,
PROC_SET_WRED_Q_MULTIPLIER,
PROC_GET_WRED_Q_AVG_SIZE,
PROC_SET_WRED_RANDOM_DROP,
PROC_SET_WRED_DROP_GYR,
PROC_SET_WRED_DROP_YR,
PROC_SET_WRED_DROP_R,
PROC_SET_WRED_DROP_ALL,
PROC_GET_WRED_PMON,
PROC_SET_QUEUE_SCHEDULING,
PROC_SET_QUEUE_SHAPING,
#ifdef MTI_PREEMPT_ENABLE
PROC_SET_PREEMPT,
#endif
PROC_SET_TX_RATIO,
PROC_SET_CREDIT_HI_WATER_MARK,
PROC_SET_CREDIT_LO_WATER_MARK,
PROC_SET_CREDIT_INCREMENT,
PROC_SET_SRP,
PROC_SET_QM_DROP,
PROC_SET_QM_BURST_SIZE,
PROC_SET_QM_RESV_SPACE,
PROC_SET_QM_HI_WATER_MARK,
PROC_SET_QM_LO_WATER_MARK,
PROC_GET_QM_TX_USED,
PROC_GET_QM_TX_AVAIL,
PROC_GET_QM_TX_CALCULATED,
PROC_SET_MMD_ID,
PROC_SET_MMD_REG,
PROC_SET_MMD_VAL,
PROC_GET_RX_FLOW_CTRL,
PROC_GET_TX_FLOW_CTRL,
PROC_SET_PORT_DUPLEX,
PROC_SET_PORT_SPEED,
PROC_SET_MAC_OPERATIONAL,
PROC_SET_VLAN_RESTRICTED,
PROC_SET_VLAN_UNTAGGED,
#ifdef CONFIG_KSZ_STP
PROC_GET_STP_INFO,
PROC_SET_STP_ON,
PROC_SET_STP_PRIO,
PROC_SET_STP_ADMIN_PATH_COST,
PROC_SET_STP_PATH_COST,
PROC_SET_STP_ADMIN_EDGE,
PROC_SET_STP_AUTO_EDGE,
PROC_SET_STP_MCHECK,
PROC_SET_STP_ADMIN_P2P,
PROC_SET_STP_AUTO_ISOLATE,
#endif
#ifdef CONFIG_KSZ_MRP
PROC_SET_PORT_MMRP_ENABLED,
PROC_SET_PORT_MMRP_MAC,
PROC_SET_PORT_MMRP_SVC,
PROC_SET_PORT_MMRP_REG,
PROC_SET_PORT_MVRP_ENABLED,
PROC_SET_PORT_MVRP_VID,
PROC_SET_PORT_MVRP_REG,
#ifdef CONFIG_KSZ_MSRP
PROC_SET_PORT_ASCAPABLE,
PROC_SET_PORT_MSRP_ENABLED,
PROC_SET_TC_DELTA_BANDWIDTH,
PROC_SET_TC_ADMIN_IDLE_MBPS,
PROC_SET_TC_ADMIN_IDLE_SLOPE,
PROC_GET_TC_OPER_IDLE_SLOPE,
PROC_SET_TC_ALGORITHM,
PROC_GET_SR_0_RX_PRIO,
PROC_SET_SR_0_TX_PRIO,
PROC_GET_SR_0_SRP_DOMAIN_BOUNDARY,
PROC_SET_SR_0_LATENCY,
PROC_GET_SR_1_RX_PRIO,
PROC_SET_SR_1_TX_PRIO,
PROC_GET_SR_1_SRP_DOMAIN_BOUNDARY,
PROC_SET_SR_1_LATENCY,
#endif
#endif
PROC_SET_LINK_MD,
PROC_SET_SQI,
PROC_SET_MAC_LOOPBACK,
PROC_SET_PHY_LOOPBACK,
PROC_SET_REMOTE_LOOPBACK,
};
/* -------------------------------------------------------------------------- */
static uint get_phy_port(struct ksz_sw *sw, uint n)
{
if (n > sw->mib_port_cnt + 1)
dbg_msg(" !!! %s %d\n", __func__, n);
if (n >= sw->mib_port_cnt + 1)
n = 0;
return sw->port_info[n].phy_p;
}
static uint get_log_port(struct ksz_sw *sw, uint p)
{
if (p >= sw->port_cnt)
dbg_msg(" !!! %s %d\n", __func__, p);
if (!sw->port_info[p].log_m)
dbg_msg(" ??? %s %d\n", __func__, p);
return sw->port_info[p].log_p;
}
static uint get_log_port_zero(struct ksz_sw *sw, uint p)
{
uint n;
n = get_log_port(sw, p);
if (n)
n--;
else
n = sw->mib_port_cnt;
return n;
}
static u16 get_phy_mask(struct ksz_sw *sw, uint n)
{
if (n > sw->mib_port_cnt + 1)
dbg_msg(" !!! %s %d\n", __func__, n);
if (n >= sw->mib_port_cnt + 1)
n = 0;
return sw->port_info[n].phy_m;
}
static uint get_phy_mask_from_log(struct ksz_sw *sw, uint log_m)
{
struct ksz_port_info *info;
uint n;
uint p;
uint phy_m = 0;
for (n = 0; n <= sw->mib_port_cnt; n++) {
info = &sw->port_info[n];
p = info->phy_p;
if (log_m & sw->port_info[p].log_m)
phy_m |= info->phy_m;
}
return phy_m;
}
static uint get_log_mask_from_phy(struct ksz_sw *sw, uint phy_m)
{
struct ksz_port_info *info;
uint n;
uint p;
uint log_m = 0;
for (n = 0; n <= sw->mib_port_cnt; n++) {
info = &sw->port_info[n];
p = info->phy_p;
if (phy_m & info->phy_m)
log_m |= sw->port_info[p].log_m;
}
return log_m;
}
static uint get_sysfs_port(struct ksz_sw *sw, uint n)
{
uint p = n;
if (!(sw->overrides & SYSFS_PHY_PORT)) {
n++;
if (n > sw->mib_port_cnt)
n = 0;
p = get_phy_port(sw, n);
}
return p;
}
static inline struct ksz_port_cfg *get_port_cfg(struct ksz_sw *sw, uint p)
{
return &sw->info->port_cfg[p];
}
static inline struct ksz_port_info *get_port_info(struct ksz_sw *sw, uint p)
{
return &sw->port_info[p];
}
static inline struct ksz_port_mib *get_port_mib(struct ksz_sw *sw, uint p)
{
return &sw->port_mib[p];
}
static void sw_acquire(struct ksz_sw *sw)
{
mutex_lock(&sw->lock);
sw->reg->lock(sw);
mutex_unlock(&sw->lock);
} /* sw_acquire */
static void sw_release(struct ksz_sw *sw)
{
sw->reg->unlock(sw);
} /* sw_release */
/* -------------------------------------------------------------------------- */
/* Common routines used by both SPI and IBA accesses. */
/**
* get_mac_table_info - Get MAC table information
* @mac: Buffer to store the MAC table entry.
* @data: Buffer holding MAC table information.
*
* This helper routine retrieves information from MAC table entry data.
*/
static void get_mac_table_info(struct ksz_mac_table *mac, u32 data[])
{
mac->valid = !!(data[0] & ALU_V_STATIC_VALID);
mac->src = !!(data[0] & ALU_V_SRC_FILTER);
mac->dst = !!(data[0] & ALU_V_DST_FILTER);
mac->prio = (data[0] >> ALU_V_PRIO_AGE_CNT_S) &
ALU_V_PRIO_AGE_CNT_M;
mac->mstp = data[0] & ALU_V_MSTP_M;
mac->override = !!(data[1] & ALU_V_OVERRIDE);
mac->use_fid = !!(data[1] & ALU_V_USE_FID);
mac->ports = data[1] & ALU_V_PORT_MAP;
mac->fid = data[2] >> ALU_V_FID_S;
mac->addr[1] = (u8) data[2];
mac->addr[0] = (u8)(data[2] >> 8);
mac->addr[5] = (u8) data[3];
mac->addr[4] = (u8)(data[3] >> 8);
mac->addr[3] = (u8)(data[3] >> 16);
mac->addr[2] = (u8)(data[3] >> 24);
} /* get_mac_table_info */
/**
* set_mac_table_info - Set MAC table information
* @mac: The MAC table entry.
* @data: Buffer to hold MAC table information.
*
* This helper routine puts information to MAC table entry.
*/
static void set_mac_table_info(struct ksz_mac_table *mac, u32 data[])
{
data[0] = (u32)(mac->prio & ALU_V_PRIO_AGE_CNT_M) <<
ALU_V_PRIO_AGE_CNT_S;
data[0] |= mac->mstp & ALU_V_MSTP_M;
if (mac->src)
data[0] |= ALU_V_SRC_FILTER;
if (mac->dst)
data[0] |= ALU_V_DST_FILTER;
if (mac->valid)
data[0] |= ALU_V_STATIC_VALID;
data[1] = mac->ports & ALU_V_PORT_MAP;
if (mac->override)
data[1] |= ALU_V_OVERRIDE;
if (mac->use_fid)
data[1] |= ALU_V_USE_FID;
data[2] = (u32) mac->fid << ALU_V_FID_S;
data[2] |= ((u32) mac->addr[0] << 8) | mac->addr[1];
data[3] = ((u32) mac->addr[2] << 24) |
((u32) mac->addr[3] << 16) |
((u32) mac->addr[4] << 8) | mac->addr[5];
} /* set_mac_table_info */
/**
* wait_for_dyn_mac_table - Wait for dynamic MAC table to be ready
* @sw: The switch instance.
*
* This helper function waits for dynamic MAC table to be ready for access.
*/
static int wait_for_dyn_mac_table(struct ksz_sw *sw)
{
u32 ctrl;
int timeout = 100;
do {
--timeout;
if (!timeout)
return 1;
ctrl = sw->reg->r32(sw, REG_SW_ALU_CTRL__4);
} while ((ctrl & ALU_START) || ALU_SEARCH == (ctrl & ALU_ACTION));
return 0;
} /* wait_for_dyn_mac_table */
/**
* wait_for_sta_mac_table - Wait for static MAC table to be ready
* @sw: The switch instance.
*
* This helper function waits for static MAC table to be ready for access.
*/
static int wait_for_sta_mac_table(struct ksz_sw *sw)
{
u32 ctrl;
int timeout = 100;
do {
--timeout;
if (!timeout)
return 1;
ctrl = sw->reg->r32(sw, REG_SW_ALU_STAT_CTRL__4);
} while (ctrl & ALU_STAT_START);
return 0;
} /* wait_for_sta_mac_table */
/**
* get_vlan_table_info - Get VLAN table information
* @vlan: Buffer to store the VLAN table entry.
* @data: Buffer holding VLAN table information.
*
* This helper routine retrieves information from VLAN table entry data.
*/
static void get_vlan_table_info(struct ksz_vlan_table *vlan, u32 data[])
{
vlan->valid = !!(data[0] & VLAN_VALID);
vlan->fid = (data[0] & VLAN_FID_M);
vlan->mstp = (data[0] >> VLAN_MSTP_S) & VLAN_MSTP_M;
vlan->prio = (data[0] >> VLAN_PRIO_S) & VLAN_PRIO_M;
vlan->option = !!(data[0] & VLAN_FORWARD_OPTION);
vlan->untag = data[1];
vlan->ports = data[2];
} /* get_vlan_table_info */
/**
* set_vlan_table_info - set VLAN table information
* @vlan: The VLAN table entry.
* @data: Buffer to hold VLAN table information.
*
* This helper routine puts information to VLAN table entry.
*/
static void set_vlan_table_info(struct ksz_vlan_table *vlan, u32 data[])
{
data[0] = vlan->fid & VLAN_FID_M;
data[0] |= (u32)(vlan->mstp & VLAN_MSTP_M) << VLAN_MSTP_S;
data[0] |= (u32)(vlan->prio & VLAN_PRIO_M) << VLAN_PRIO_S;
if (vlan->option)
data[0] |= VLAN_FORWARD_OPTION;
if (vlan->valid)
data[0] |= VLAN_VALID;
data[1] = vlan->untag;
data[2] = vlan->ports;
} /* set_vlan_table_info */
/**
* wait_for_vlan_table - Wait for VLAN table to be ready
* @sw: The switch instance.
*
* This helper function waits for VLAN table to be ready for access.
*/
static int wait_for_vlan_table(struct ksz_sw *sw)
{
u32 ctrl;
int timeout = 100;
do {
--timeout;
if (!timeout)
return 1;
ctrl = sw->reg->r8(sw, REG_SW_VLAN_CTRL);
} while (ctrl & VLAN_START);
return 0;
} /* wait_for_vlan_table */
#ifdef CONFIG_KSZ_HSR
/**
* get_hsr_table_info - Get HSR table information
* @hsr: Buffer to store the HSR table entry.
* @data: Buffer holding HSR table information.
*
* This helper routine retrieves information from HSR table entry data.
*/
static void get_hsr_table_info(struct ksz_hsr_table *hsr, u32 data[])
{
u8 *byte;
u16 *word;
hsr->valid = !!(data[0] & HSR_V_STATIC_VALID);
hsr->age_cnt = (data[0] >> HSR_V_AGE_CNT_S) & HSR_V_AGE_CNT_M;
hsr->path_id = (data[0] & HSR_V_PATH_ID_M);
data[1] = htonl(data[1]);
memcpy(hsr->dst_mac, &data[1], 4);
byte = (u8 *) &data[2];
data[2] = htonl(data[2]);
memcpy(&hsr->dst_mac[4], &byte[0], 2);
memcpy(&hsr->src_mac[0], &byte[2], 2);
data[3] = htonl(data[3]);
memcpy(&hsr->src_mac[2], &data[3], 4);
word = (u16 *) &data[4];
memcpy(&hsr->start_seq[1], word, 2);
word++;
memcpy(&hsr->start_seq[0], word, 2);
word++;
memcpy(&hsr->exp_seq[1], word, 2);
word++;
memcpy(&hsr->exp_seq[0], word, 2);
word++;
memcpy(&hsr->seq_cnt[1], word, 2);
word++;
memcpy(&hsr->seq_cnt[0], word, 2);
word++;
} /* get_hsr_table_info */
/**
* set_hsr_table_info - Set HSR table information
* @hsr: The HSR table entry.
* @data: Buffer to hold HSR table information.
*
* This helper routine puts information to HSR table entry.
*/
static void set_hsr_table_info(struct ksz_hsr_table *hsr, u32 data[])
{
u8 *byte;
u16 *word;
data[0] = (u32)(hsr->age_cnt & HSR_V_AGE_CNT_M) << HSR_V_AGE_CNT_S;
data[0] |= hsr->path_id & HSR_V_PATH_ID_M;
if (hsr->valid)
data[0] |= HSR_V_STATIC_VALID;
memcpy(&data[1], hsr->dst_mac, 4);
data[1] = htonl(data[1]);
byte = (u8 *) &data[2];
memcpy(&byte[0], &hsr->dst_mac[4], 2);
memcpy(&byte[2], &hsr->src_mac[0], 2);
data[2] = htonl(data[2]);
memcpy(&data[3], &hsr->src_mac[2], 4);
data[3] = htonl(data[3]);
word = (u16 *) &data[4];
memcpy(word, &hsr->start_seq[1], 2);
word++;
memcpy(word, &hsr->start_seq[0], 2);
word++;
memcpy(word, &hsr->exp_seq[1], 2);
word++;
memcpy(word, &hsr->exp_seq[0], 2);
word++;
memcpy(word, &hsr->seq_cnt[1], 2);
word++;
memcpy(word, &hsr->seq_cnt[0], 2);
word++;
} /* set_hsr_table_info */
/**
* wait_for_hsr_table - Wait for HSR table to be ready
* @sw: The switch instance.
*
* This helper function waits for HSR table to be ready for access.
*/
static int wait_for_hsr_table(struct ksz_sw *sw)
{
u32 ctrl;
int timeout = 100;
do {
--timeout;
if (!timeout)
return 1;
ctrl = sw->reg->r32(sw, REG_HSR_ALU_CTRL__4);
} while ((ctrl & HSR_START) || HSR_SEARCH == (ctrl & HSR_ACTION));
return 0;
} /* wait_for_hsr_table */
#endif
/* -------------------------------------------------------------------------- */
#define contain_reg(addr, len, reg) \
(addr <= (reg) && (reg) <= (addr + len - 1))
#ifdef CONFIG_1588_PTP
#include "ksz_ptp_9897.c"
#endif
#ifdef CONFIG_KSZ_IBA
static void sw_set_spi(struct ksz_sw *sw, struct ksz_iba_info *iba);
#include "ksz_iba.c"
#endif
/* -------------------------------------------------------------------------- */
/* Switch functions */
/**
* sw_r_mac_table - read from MAC table
* @sw: The switch instance.
* @mac: Buffer to store the MAC table entry.
*
* This helper function reads an entry of the MAC table of the switch.
*/
static void sw_r_mac_table(struct ksz_sw *sw, struct ksz_mac_table *mac)
{
u32 data[4];
sw_r(sw, REG_SW_ALU_VAL_A, data, 4 * 4);
data[0] = be32_to_cpu(data[0]);
data[1] = be32_to_cpu(data[1]);
data[2] = be32_to_cpu(data[2]);
data[3] = be32_to_cpu(data[3]);
get_mac_table_info(mac, data);
} /* sw_r_mac_table */
/**
* sw_w_mac_table - write to MAC table
* @sw: The switch instance.
* @mac: The MAC table entry.
*
* This helper function writes an entry of the MAC table of the switch.
*/
static void sw_w_mac_table(struct ksz_sw *sw, struct ksz_mac_table *mac)
{
u32 data[4];
set_mac_table_info(mac, data);
data[0] = cpu_to_be32(data[0]);
data[1] = cpu_to_be32(data[1]);
data[2] = cpu_to_be32(data[2]);
data[3] = cpu_to_be32(data[3]);
sw_w(sw, REG_SW_ALU_VAL_A, data, 4 * 4);
} /* sw_w_mac_table */
/**
* sw_s_dyn_mac_table - prepare dynmaic MAC table for access
* @sw: The switch instance.
* @addr: The address of the table entry.
* @src_addr: The source address.
* @src_fid: The source FID.
*
* This helper function prepares dynmaic MAC table for access.
*/
static u32 sw_s_dyn_mac_table(struct ksz_sw *sw, u16 addr, u8 *src_addr,
u16 src_fid)
{
u32 ctrl;
u32 data;
ctrl = 0;
if (addr) {
data = (addr - 1) & ALU_DIRECT_INDEX_M;
sw->reg->w32(sw, REG_SW_ALU_INDEX_1, data);
ctrl |= ALU_DIRECT;
} else {
data = (u32) src_fid << ALU_FID_INDEX_S;
data |= ((u32) src_addr[0] << 8) | src_addr[1];
sw->reg->w32(sw, REG_SW_ALU_INDEX_0, data);
data = ((u32) src_addr[2] << 24) |
((u32) src_addr[3] << 16) |
((u32) src_addr[4] << 8) | src_addr[5];
sw->reg->w32(sw, REG_SW_ALU_INDEX_1, data);
}
ctrl |= ALU_START;
return ctrl;
} /* sw_s_dyn_mac_table */
/**
* sw_r_dyn_mac_hw - read from dynamic MAC table using default access
* @sw: The switch instance.
* @addr: The address of the table entry.
* @src_addr: The source address.
* @src_fid: The source FID.
* @mac: Buffer to store the MAC table entry.
* @entry: Buffer to store the actual entry if available.
*
* This function reads an entry of the dynamic MAC table using default access.
*/
static int sw_r_dyn_mac_hw(struct ksz_sw *sw, u16 addr, u8 *src_addr,
u16 src_fid, struct ksz_mac_table *mac, u16 *entry)
{
u32 ctrl;
ctrl = sw_s_dyn_mac_table(sw, addr, src_addr, src_fid);
ctrl |= ALU_READ;
/* Dynamic MAC table does not use USE_FID bit and does not clear it. */
sw->reg->w32(sw, REG_SW_ALU_VAL_B, 0);
sw->reg->w32(sw, REG_SW_ALU_CTRL__4, ctrl);
do {
ctrl = sw->reg->r32(sw, REG_SW_ALU_CTRL__4);
} while (ctrl & ALU_START);
sw_r_mac_table(sw, mac);
/* Hash read. */
if (!addr && entry)
*entry = (sw->reg->r16(sw, REG_SW_LUE_INDEX_0__2) &
ENTRY_INDEX_M) + 1;
return 1;
} /* sw_r_dyn_mac_hw */
/**
* sw_r_dyn_mac_table - read from dynamic MAC table
* @sw: The switch instance.
* @addr: The address of the table entry.
* @src_addr: The source address.
* @src_fid: The source FID.
* @mac: Buffer to store the MAC table entry.
* @entry: Buffer to store the actual entry if available.
*
* This routine reads an entry of the dynamic MAC table of the switch.
* ALU table is locked to prevent corruption of read data.
*/
static void sw_r_dyn_mac_table(struct ksz_sw *sw, u16 addr, u8 *src_addr,
u16 src_fid, struct ksz_mac_table *mac, u16 *entry)
{
if (entry)
*entry = 0;
mutex_lock(&sw->alulock);
sw->ops->acquire(sw);
if (wait_for_dyn_mac_table(sw))
goto r_dyn_exit;
sw->reg->r_dyn_mac_hw(sw, addr, src_addr, src_fid, mac, entry);
r_dyn_exit:
sw->ops->release(sw);
mutex_unlock(&sw->alulock);
mac->dirty = 0;
} /* sw_r_dyn_mac_table */
/**
* sw_w_dyn_mac_hw - write to dynamic MAC table using default access
* @sw: The switch instance.
* @addr: The address of the table entry.
* @src_addr: The source address.
* @src_fid: The source FID.
* @mac: The MAC table entry.
*
* This function writes an entry of the dynamic MAC table using default access.
*/
static int sw_w_dyn_mac_hw(struct ksz_sw *sw, u16 addr, u8 *src_addr,
u16 src_fid, struct ksz_mac_table *mac)
{
u32 ctrl;
ctrl = sw_s_dyn_mac_table(sw, addr, src_addr, src_fid);
ctrl |= ALU_WRITE;
sw_w_mac_table(sw, mac);
sw->reg->w32(sw, REG_SW_ALU_CTRL__4, ctrl);
return 1;
} /* sw_w_dyn_mac_hw */
/**
* sw_w_dyn_mac_table - write to dynamic MAC table
* @sw: The switch instance.
* @addr: The address of the table entry.
* @src_addr: The source address.
* @src_fid: The source FID.
* @mac: The MAC table entry.
*
* This routine writes an entry of the dynamic MAC table of the switch.
* ALU table is locked to prevent corruption of read data.
*/
static void sw_w_dyn_mac_table(struct ksz_sw *sw, u16 addr, u8 *src_addr,
u16 src_fid, struct ksz_mac_table *mac)
{
mutex_lock(&sw->alulock);
sw->ops->acquire(sw);
if (wait_for_dyn_mac_table(sw))
goto w_dyn_exit;
/* Dynamic MAC table does not use USE_FID bit. */
mac->use_fid = 0;
sw->reg->w_dyn_mac_hw(sw, addr, src_addr, src_fid, mac);
w_dyn_exit:
sw->ops->release(sw);
mutex_unlock(&sw->alulock);
mac->dirty = 0;
} /* sw_w_dyn_mac_table */
/**
* sw_start_dyn_mac_hw - start dynamic MAC table search using default access
* @sw: The switch instance.