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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2018-2022 Marvell International Ltd.
*/
#include <errno.h>
#include <i2c.h>
#include <log.h>
#include <malloc.h>
#include <linux/delay.h>
#include <display_options.h>
#include <mach/cvmx-regs.h>
#include <mach/cvmx-csr.h>
#include <mach/cvmx-bootmem.h>
#include <mach/octeon-model.h>
#include <mach/cvmx-fuse.h>
#include <mach/octeon-feature.h>
#include <mach/cvmx-qlm.h>
#include <mach/octeon_qlm.h>
#include <mach/cvmx-pcie.h>
#include <mach/cvmx-coremask.h>
#include <mach/cvmx-helper.h>
#include <mach/cvmx-helper-board.h>
#include <mach/cvmx-helper-fdt.h>
#include <mach/cvmx-helper-cfg.h>
#include <mach/cvmx-helper-gpio.h>
#include <mach/cvmx-helper-util.h>
extern void octeon_i2c_unblock(int bus);
static struct cvmx_fdt_sfp_info *sfp_list;
/**
* Local allocator to handle both SE and U-Boot that also zeroes out memory
*
* @param size number of bytes to allocate
*
* @return pointer to allocated memory or NULL if out of memory.
* Alignment is set to 8-bytes.
*/
static void *cvm_sfp_alloc(size_t size)
{
return calloc(size, 1);
}
/**
* Free allocated memory.
*
* @param ptr pointer to memory to free
*
* NOTE: This only works in U-Boot since SE does not really have a freeing
* mechanism. In SE the memory is zeroed out and not freed so this
* is a memory leak if errors occur.
*/
static inline void cvm_sfp_free(void *ptr, size_t size)
{
free(ptr);
}
/**
* Select a QSFP device before accessing the EEPROM
*
* @param sfp handle for sfp/qsfp connector
* @param enable Set true to select, false to deselect
*
* @return 0 on success or if SFP or no select GPIO, -1 on GPIO error
*/
static int cvmx_qsfp_select(const struct cvmx_fdt_sfp_info *sfp, bool enable)
{
/* Select is only needed for QSFP modules */
if (!sfp->is_qsfp) {
debug("%s(%s, %d): not QSFP\n", __func__, sfp->name, enable);
return 0;
}
if (dm_gpio_is_valid(&sfp->select)) {
/* Note that select is active low */
return dm_gpio_set_value(&sfp->select, !enable);
}
debug("%s: select GPIO unknown\n", __func__);
return 0;
}
static int cvmx_sfp_parse_sfp_buffer(struct cvmx_sfp_mod_info *sfp_info,
const uint8_t *buffer)
{
u8 csum = 0;
bool csum_good = false;
int i;
/* Validate the checksum */
for (i = 0; i < 0x3f; i++)
csum += buffer[i];
csum_good = csum == buffer[0x3f];
debug("%s: Lower checksum: 0x%02x, expected: 0x%02x\n", __func__, csum,
buffer[0x3f]);
csum = 0;
for (i = 0x40; i < 0x5f; i++)
csum += buffer[i];
debug("%s: Upper checksum: 0x%02x, expected: 0x%02x\n", __func__, csum,
buffer[0x5f]);
if (csum != buffer[0x5f] || !csum_good) {
debug("Error: SFP EEPROM checksum information is incorrect\n");
return -1;
}
sfp_info->conn_type = buffer[0];
if (buffer[1] < 1 || buffer[1] > 7) { /* Extended ID */
debug("Error: Unknown SFP extended identifier 0x%x\n",
buffer[1]);
return -1;
}
if (buffer[1] != 4) {
debug("Module is not SFP/SFP+/SFP28/QSFP+\n");
return -1;
}
sfp_info->mod_type = buffer[2];
sfp_info->eth_comp = buffer[3] & 0xf0;
sfp_info->cable_comp = buffer[0x24];
/* There are several ways a cable can be marked as active or
* passive. 8.[2-3] specify the SFP+ cable technology. Some
* modules also use 3.[0-1] for Infiniband, though it's
* redundant.
*/
if ((buffer[8] & 0x0C) == 0x08) {
sfp_info->limiting = true;
sfp_info->active_cable = true;
} else if ((buffer[8] & 0xC) == 0x4) {
sfp_info->limiting = false;
sfp_info->active_cable = false;
}
if ((buffer[3] & 3) == 2) {
sfp_info->active_cable = true;
sfp_info->limiting = true;
}
switch (sfp_info->mod_type) {
case CVMX_SFP_MOD_OPTICAL_LC:
case CVMX_SFP_MOD_OPTICAL_PIGTAIL:
sfp_info->copper_cable = false;
break;
case CVMX_SFP_MOD_COPPER_PIGTAIL:
sfp_info->copper_cable = true;
break;
case CVMX_SFP_MOD_NO_SEP_CONN:
switch (sfp_info->cable_comp) {
case CVMX_SFP_CABLE_100G_25GAUI_C2M_AOC_HIGH_BER:
case CVMX_SFP_CABLE_100G_25GAUI_C2M_AOC_LOW_BER:
case CVMX_SFP_CABLE_100G_25GAUI_C2M_ACC_LOW_BER:
sfp_info->copper_cable = false;
sfp_info->limiting = true;
sfp_info->active_cable = true;
break;
case CVMX_SFP_CABLE_100G_SR4_25G_SR:
case CVMX_SFP_CABLE_100G_LR4_25G_LR:
case CVMX_SFP_CABLE_100G_ER4_25G_ER:
case CVMX_SFP_CABLE_100G_SR10:
case CVMX_SFP_CABLE_100G_CWDM4_MSA:
case CVMX_SFP_CABLE_100G_PSM4:
case CVMX_SFP_CABLE_100G_CWDM4:
case CVMX_SFP_CABLE_40G_ER4:
case CVMX_SFP_CABLE_4X10G_SR:
case CVMX_SFP_CABLE_G959_1_P1I1_2D1:
case CVMX_SFP_CABLE_G959_1_P1S1_2D2:
case CVMX_SFP_CABLE_G959_1_P1L1_2D2:
case CVMX_SFP_CABLE_100G_CLR4:
case CVMX_SFP_CABLE_100G_2_LAMBDA_DWDM:
case CVMX_SFP_CABLE_40G_SWDM4:
case CVMX_SFP_CABLE_100G_SWDM4:
case CVMX_SFP_CABLE_100G_PAM4_BIDI:
sfp_info->copper_cable = false;
break;
case CVMX_SFP_CABLE_100G_25GAUI_C2M_ACC_HIGH_BER:
case CVMX_SFP_CABLE_10GBASE_T:
case CVMX_SFP_CABLE_10GBASE_T_SR:
case CVMX_SFP_CABLE_5GBASE_T:
case CVMX_SFP_CABLE_2_5GBASE_T:
sfp_info->copper_cable = true;
sfp_info->limiting = true;
sfp_info->active_cable = true;
break;
case CVMX_SFP_CABLE_100G_CR4_25G_CR_CA_L:
case CVMX_SFP_CABLE_25G_CR_CA_S:
case CVMX_SFP_CABLE_25G_CR_CA_N:
case CVMX_SFP_CABLE_40G_PSM4:
sfp_info->copper_cable = true;
break;
default:
switch (sfp_info->eth_comp) {
case CVMX_SFP_CABLE_10GBASE_ER:
case CVMX_SFP_CABLE_10GBASE_LRM:
case CVMX_SFP_CABLE_10GBASE_LR:
case CVMX_SFP_CABLE_10GBASE_SR:
sfp_info->copper_cable = false;
break;
}
break;
}
break;
case CVMX_SFP_MOD_RJ45:
debug("%s: RJ45 adapter\n", __func__);
sfp_info->copper_cable = true;
sfp_info->active_cable = true;
sfp_info->limiting = true;
break;
case CVMX_SFP_MOD_UNKNOWN:
/* The Avago 1000Base-X to 1000Base-T module reports that it
* is an unknown module type but the Ethernet compliance code
* says it is 1000Base-T. We'll change the reporting to RJ45.
*/
if (buffer[6] & 8) {
debug("RJ45 gigabit module detected\n");
sfp_info->mod_type = CVMX_SFP_MOD_RJ45;
sfp_info->copper_cable = false;
sfp_info->limiting = true;
sfp_info->active_cable = true;
sfp_info->max_copper_cable_len = buffer[0x12];
sfp_info->rate = CVMX_SFP_RATE_1G;
} else {
debug("Unknown module type 0x%x\n", sfp_info->mod_type);
}
sfp_info->limiting = true;
break;
case CVMX_SFP_MOD_MXC_2X16:
debug("%s: MXC 2X16\n", __func__);
break;
default:
sfp_info->limiting = true;
break;
}
if (sfp_info->copper_cable)
sfp_info->max_copper_cable_len = buffer[0x12];
else
sfp_info->max_50um_om4_cable_length = buffer[0x12] * 10;
if (buffer[0xe])
sfp_info->max_single_mode_cable_length = buffer[0xe] * 1000;
else
sfp_info->max_single_mode_cable_length = buffer[0xf] * 100000;
sfp_info->max_50um_om2_cable_length = buffer[0x10] * 10;
sfp_info->max_62_5um_om1_cable_length = buffer[0x11] * 10;
sfp_info->max_50um_om3_cable_length = buffer[0x13] * 10;
if (buffer[0xc] == 0xff) {
if (buffer[0x42] >= 255)
sfp_info->rate = CVMX_SFP_RATE_100G;
else if (buffer[0x42] >= 160)
sfp_info->rate = CVMX_SFP_RATE_40G;
else if (buffer[0x42] >= 100)
sfp_info->rate = CVMX_SFP_RATE_25G;
else
sfp_info->rate = CVMX_SFP_RATE_UNKNOWN;
} else if (buffer[0xc] >= 100) {
sfp_info->rate = CVMX_SFP_RATE_10G;
} else if (buffer[0xc] >= 10) {
sfp_info->rate = CVMX_SFP_RATE_1G;
} else {
sfp_info->rate = CVMX_SFP_RATE_UNKNOWN;
}
if (sfp_info->rate == CVMX_SFP_RATE_UNKNOWN) {
switch (sfp_info->cable_comp) {
case CVMX_SFP_CABLE_100G_SR10:
case CVMX_SFP_CABLE_100G_CWDM4_MSA:
case CVMX_SFP_CABLE_100G_PSM4:
case CVMX_SFP_CABLE_100G_CWDM4:
case CVMX_SFP_CABLE_100G_CLR4:
case CVMX_SFP_CABLE_100G_2_LAMBDA_DWDM:
case CVMX_SFP_CABLE_100G_SWDM4:
case CVMX_SFP_CABLE_100G_PAM4_BIDI:
sfp_info->rate = CVMX_SFP_RATE_100G;
break;
case CVMX_SFP_CABLE_100G_25GAUI_C2M_AOC_HIGH_BER:
case CVMX_SFP_CABLE_100G_SR4_25G_SR:
case CVMX_SFP_CABLE_100G_LR4_25G_LR:
case CVMX_SFP_CABLE_100G_ER4_25G_ER:
case CVMX_SFP_CABLE_100G_25GAUI_C2M_ACC_HIGH_BER:
case CVMX_SFP_CABLE_100G_CR4_25G_CR_CA_L:
case CVMX_SFP_CABLE_25G_CR_CA_S:
case CVMX_SFP_CABLE_25G_CR_CA_N:
case CVMX_SFP_CABLE_100G_25GAUI_C2M_AOC_LOW_BER:
case CVMX_SFP_CABLE_100G_25GAUI_C2M_ACC_LOW_BER:
sfp_info->rate = CVMX_SFP_RATE_25G;
break;
case CVMX_SFP_CABLE_40G_ER4:
case CVMX_SFP_CABLE_4X10G_SR:
case CVMX_SFP_CABLE_40G_PSM4:
case CVMX_SFP_CABLE_40G_SWDM4:
sfp_info->rate = CVMX_SFP_RATE_40G;
break;
case CVMX_SFP_CABLE_G959_1_P1I1_2D1:
case CVMX_SFP_CABLE_G959_1_P1S1_2D2:
case CVMX_SFP_CABLE_G959_1_P1L1_2D2:
case CVMX_SFP_CABLE_10GBASE_T:
case CVMX_SFP_CABLE_10GBASE_T_SR:
case CVMX_SFP_CABLE_5GBASE_T:
case CVMX_SFP_CABLE_2_5GBASE_T:
sfp_info->rate = CVMX_SFP_RATE_10G;
break;
default:
switch (sfp_info->eth_comp) {
case CVMX_SFP_CABLE_10GBASE_ER:
case CVMX_SFP_CABLE_10GBASE_LRM:
case CVMX_SFP_CABLE_10GBASE_LR:
case CVMX_SFP_CABLE_10GBASE_SR:
sfp_info->rate = CVMX_SFP_RATE_10G;
break;
default:
sfp_info->rate = CVMX_SFP_RATE_UNKNOWN;
break;
}
break;
}
}
if (buffer[0xc] < 0xff)
sfp_info->bitrate_max = buffer[0xc] * 100;
else
sfp_info->bitrate_max = buffer[0x42] * 250;
if ((buffer[8] & 0xc) == 8) {
if (buffer[0x3c] & 0x4)
sfp_info->limiting = true;
}
/* Currently we only set this for 25G. FEC is required for CA-S cables
* and for cable lengths >= 5M as of this writing.
*/
if ((sfp_info->rate == CVMX_SFP_RATE_25G &&
sfp_info->copper_cable) &&
(sfp_info->cable_comp == CVMX_SFP_CABLE_25G_CR_CA_S ||
sfp_info->max_copper_cable_len >= 5))
sfp_info->fec_required = true;
/* copy strings and vendor info, strings will be automatically NUL
* terminated.
*/
memcpy(sfp_info->vendor_name, &buffer[0x14], 16);
memcpy(sfp_info->vendor_oui, &buffer[0x25], 3);
memcpy(sfp_info->vendor_pn, &buffer[0x28], 16);
memcpy(sfp_info->vendor_rev, &buffer[0x38], 4);
memcpy(sfp_info->vendor_sn, &buffer[0x44], 16);
memcpy(sfp_info->date_code, &buffer[0x54], 8);
sfp_info->cooled_laser = !!(buffer[0x40] & 4);
sfp_info->internal_cdr = !!(buffer[0x40] & 8);
if (buffer[0x40] & 0x20)
sfp_info->power_level = 3;
else
sfp_info->power_level = (buffer[0x40] & 2) ? 2 : 1;
sfp_info->diag_paging = !!(buffer[0x40] & 0x10);
sfp_info->linear_rx_output = !(buffer[0x40] & 1);
sfp_info->los_implemented = !!(buffer[0x41] & 2);
sfp_info->los_inverted = !!(buffer[0x41] & 4);
sfp_info->tx_fault_implemented = !!(buffer[0x41] & 8);
sfp_info->tx_disable_implemented = !!(buffer[0x41] & 0x10);
sfp_info->rate_select_implemented = !!(buffer[0x41] & 0x20);
sfp_info->tuneable_transmitter = !!(buffer[0x41] & 0x40);
sfp_info->rx_decision_threshold_implemented = !!(buffer[0x41] & 0x80);
sfp_info->diag_monitoring = !!(buffer[0x5c] & 0x40);
sfp_info->diag_rx_power_averaged = !!(buffer[0x5c] & 0x8);
sfp_info->diag_externally_calibrated = !!(buffer[0x5c] & 0x10);
sfp_info->diag_internally_calibrated = !!(buffer[0x5c] & 0x20);
sfp_info->diag_addr_change_required = !!(buffer[0x5c] & 0x4);
sfp_info->diag_soft_rate_select_control = !!(buffer[0x5d] & 2);
sfp_info->diag_app_select_control = !!(buffer[0x5d] & 4);
sfp_info->diag_soft_rate_select_control = !!(buffer[0x5d] & 8);
sfp_info->diag_soft_rx_los_implemented = !!(buffer[0x5d] & 0x10);
sfp_info->diag_soft_tx_fault_implemented = !!(buffer[0x5d] & 0x20);
sfp_info->diag_soft_tx_disable_implemented = !!(buffer[0x5d] & 0x40);
sfp_info->diag_alarm_warning_flags_implemented =
!!(buffer[0x5d] & 0x80);
sfp_info->diag_rev = buffer[0x5e];
return 0;
}
static int cvmx_sfp_parse_qsfp_buffer(struct cvmx_sfp_mod_info *sfp_info,
const uint8_t *buffer)
{
u8 csum = 0;
bool csum_good = false;
int i;
/* Validate the checksum */
for (i = 0x80; i < 0xbf; i++)
csum += buffer[i];
csum_good = csum == buffer[0xbf];
debug("%s: Lower checksum: 0x%02x, expected: 0x%02x\n", __func__, csum,
buffer[0xbf]);
csum = 0;
for (i = 0xc0; i < 0xdf; i++)
csum += buffer[i];
debug("%s: Upper checksum: 0x%02x, expected: 0x%02x\n", __func__, csum,
buffer[0xdf]);
if (csum != buffer[0xdf] || !csum_good) {
debug("Error: SFP EEPROM checksum information is incorrect\n");
return -1;
}
sfp_info->conn_type = buffer[0x80];
sfp_info->mod_type = buffer[0x82];
sfp_info->eth_comp = buffer[0x83] & 0xf0;
sfp_info->cable_comp = buffer[0xa4];
switch (sfp_info->mod_type) {
case CVMX_SFP_MOD_COPPER_PIGTAIL:
case CVMX_SFP_MOD_NO_SEP_CONN:
debug("%s: copper pigtail or no separable cable\n", __func__);
/* There are several ways a cable can be marked as active or
* passive. 8.[2-3] specify the SFP+ cable technology. Some
* modules also use 3.[0-1] for Infiniband, though it's
* redundant.
*/
sfp_info->copper_cable = true;
if ((buffer[0x88] & 0x0C) == 0x08) {
sfp_info->limiting = true;
sfp_info->active_cable = true;
} else if ((buffer[0x88] & 0xC) == 0x4) {
sfp_info->limiting = false;
sfp_info->active_cable = false;
}
if ((buffer[0x83] & 3) == 2) {
sfp_info->active_cable = true;
sfp_info->limiting = true;
}
break;
case CVMX_SFP_MOD_RJ45:
debug("%s: RJ45 adapter\n", __func__);
sfp_info->copper_cable = true;
sfp_info->active_cable = true;
sfp_info->limiting = true;
break;
case CVMX_SFP_MOD_UNKNOWN:
debug("Unknown module type\n");
/* The Avago 1000Base-X to 1000Base-T module reports that it
* is an unknown module type but the Ethernet compliance code
* says it is 1000Base-T. We'll change the reporting to RJ45.
*/
if (buffer[0x86] & 8) {
sfp_info->mod_type = CVMX_SFP_MOD_RJ45;
sfp_info->copper_cable = false;
sfp_info->limiting = true;
sfp_info->active_cable = true;
sfp_info->max_copper_cable_len = buffer[0x92];
sfp_info->rate = CVMX_SFP_RATE_1G;
}
fallthrough;
default:
sfp_info->limiting = true;
break;
}
if (sfp_info->copper_cable)
sfp_info->max_copper_cable_len = buffer[0x92];
else
sfp_info->max_50um_om4_cable_length = buffer[0x92] * 10;
debug("%s: copper cable: %d, max copper cable len: %d\n", __func__,
sfp_info->copper_cable, sfp_info->max_copper_cable_len);
if (buffer[0xe])
sfp_info->max_single_mode_cable_length = buffer[0x8e] * 1000;
else
sfp_info->max_single_mode_cable_length = buffer[0x8f] * 100000;
sfp_info->max_50um_om2_cable_length = buffer[0x90] * 10;
sfp_info->max_62_5um_om1_cable_length = buffer[0x91] * 10;
sfp_info->max_50um_om3_cable_length = buffer[0x93] * 10;
if (buffer[0x8c] == 12) {
sfp_info->rate = CVMX_SFP_RATE_1G;
} else if (buffer[0x8c] == 103) {
sfp_info->rate = CVMX_SFP_RATE_10G;
} else if (buffer[0x8c] == 0xff) {
if (buffer[0xc2] == 103)
sfp_info->rate = CVMX_SFP_RATE_100G;
}
if (buffer[0x8c] < 0xff)
sfp_info->bitrate_max = buffer[0x8c] * 100;
else
sfp_info->bitrate_max = buffer[0xc2] * 250;
if ((buffer[0x88] & 0xc) == 8) {
if (buffer[0xbc] & 0x4)
sfp_info->limiting = true;
}
/* Currently we only set this for 25G. FEC is required for CA-S cables
* and for cable lengths >= 5M as of this writing.
*/
/* copy strings and vendor info, strings will be automatically NUL
* terminated.
*/
memcpy(sfp_info->vendor_name, &buffer[0x94], 16);
memcpy(sfp_info->vendor_oui, &buffer[0xa5], 3);
memcpy(sfp_info->vendor_pn, &buffer[0xa8], 16);
memcpy(sfp_info->vendor_rev, &buffer[0xb8], 4);
memcpy(sfp_info->vendor_sn, &buffer[0xc4], 16);
memcpy(sfp_info->date_code, &buffer[0xd4], 8);
sfp_info->linear_rx_output = !!(buffer[0xc0] & 1);
sfp_info->cooled_laser = !!(buffer[0xc0] & 4);
sfp_info->internal_cdr = !!(buffer[0xc0] & 8);
if (buffer[0xc0] & 0x20)
sfp_info->power_level = 3;
else
sfp_info->power_level = (buffer[0xc0] & 2) ? 2 : 1;
sfp_info->diag_paging = !!(buffer[0xc0] & 0x10);
sfp_info->los_implemented = !!(buffer[0xc1] & 2);
sfp_info->los_inverted = !!(buffer[0xc1] & 4);
sfp_info->tx_fault_implemented = !!(buffer[0xc1] & 8);
sfp_info->tx_disable_implemented = !!(buffer[0xc1] & 0x10);
sfp_info->rate_select_implemented = !!(buffer[0xc1] & 0x20);
sfp_info->tuneable_transmitter = !!(buffer[0xc1] & 0x40);
sfp_info->rx_decision_threshold_implemented = !!(buffer[0xc1] & 0x80);
sfp_info->diag_monitoring = !!(buffer[0xdc] & 0x40);
sfp_info->diag_rx_power_averaged = !!(buffer[0xdc] & 0x8);
sfp_info->diag_externally_calibrated = !!(buffer[0xdc] & 0x10);
sfp_info->diag_internally_calibrated = !!(buffer[0xdc] & 0x20);
sfp_info->diag_addr_change_required = !!(buffer[0xdc] & 0x4);
sfp_info->diag_soft_rate_select_control = !!(buffer[0xdd] & 2);
sfp_info->diag_app_select_control = !!(buffer[0xdd] & 4);
sfp_info->diag_soft_rate_select_control = !!(buffer[0xdd] & 8);
sfp_info->diag_soft_rx_los_implemented = !!(buffer[0xdd] & 0x10);
sfp_info->diag_soft_tx_fault_implemented = !!(buffer[0xdd] & 0x20);
sfp_info->diag_soft_tx_disable_implemented = !!(buffer[0xdd] & 0x40);
sfp_info->diag_alarm_warning_flags_implemented =
!!(buffer[0xdd] & 0x80);
sfp_info->diag_rev = buffer[0xde];
return 0;
}
static bool sfp_verify_checksum(const uint8_t *buffer)
{
u8 csum = 0;
u8 offset;
bool csum_good = false;
int i;
switch (buffer[0]) {
case CVMX_SFP_CONN_QSFP:
case CVMX_SFP_CONN_QSFPP:
case CVMX_SFP_CONN_QSFP28:
case CVMX_SFP_CONN_MICRO_QSFP:
case CVMX_SFP_CONN_QSFP_DD:
offset = 0x80;
break;
default:
offset = 0;
break;
}
for (i = offset; i < offset + 0x3f; i++)
csum += buffer[i];
csum_good = csum == buffer[offset + 0x3f];
if (!csum_good) {
debug("%s: Lower checksum bad, got 0x%x, expected 0x%x\n",
__func__, csum, buffer[offset + 0x3f]);
return false;
}
csum = 0;
for (i = offset + 0x40; i < offset + 0x5f; i++)
csum += buffer[i];
if (csum != buffer[offset + 0x5f]) {
debug("%s: Upper checksum bad, got 0x%x, expected 0x%x\n",
__func__, csum, buffer[offset + 0x5f]);
return false;
}
return true;
}
/**
* Reads and parses SFP/QSFP EEPROM
*
* @param sfp sfp handle to read
*
* @return 0 for success, -1 on error.
*/
int cvmx_sfp_read_i2c_eeprom(struct cvmx_fdt_sfp_info *sfp)
{
const struct cvmx_fdt_i2c_bus_info *bus = sfp->i2c_bus;
int oct_bus = cvmx_fdt_i2c_get_root_bus(bus);
struct udevice *dev;
u8 buffer[256];
bool is_qsfp;
int retry;
int err;
if (!bus) {
debug("%s(%s): Error: i2c bus undefined for eeprom\n", __func__,
sfp->name);
return -1;
}
is_qsfp = (sfp->sfp_info.conn_type == CVMX_SFP_CONN_QSFP ||
sfp->sfp_info.conn_type == CVMX_SFP_CONN_QSFPP ||
sfp->sfp_info.conn_type == CVMX_SFP_CONN_QSFP28 ||
sfp->sfp_info.conn_type == CVMX_SFP_CONN_MICRO_QSFP) ||
sfp->is_qsfp;
err = cvmx_qsfp_select(sfp, true);
if (err) {
debug("%s: Error selecting SFP/QSFP slot\n", __func__);
return err;
}
debug("%s: Reading eeprom from i2c address %d:0x%x\n", __func__,
oct_bus, sfp->i2c_eeprom_addr);
for (retry = 0; retry < 3; retry++) {
err = i2c_get_chip(bus->i2c_bus, sfp->i2c_eeprom_addr, 1, &dev);
if (err) {
debug("Cannot find I2C device: %d\n", err);
goto error;
}
err = dm_i2c_read(dev, 0, buffer, 256);
if (err || !sfp_verify_checksum(buffer)) {
debug("%s: Error %d reading eeprom at 0x%x, bus %d\n",
__func__, err, sfp->i2c_eeprom_addr, oct_bus);
debug("%s: Retry %d\n", __func__, retry + 1);
mdelay(1000);
} else {
break;
}
}
if (err) {
debug("%s: Error reading eeprom from SFP %s\n", __func__,
sfp->name);
return -1;
}
#ifdef DEBUG
print_buffer(0, buffer, 1, 256, 0);
#endif
memset(&sfp->sfp_info, 0, sizeof(struct cvmx_sfp_mod_info));
switch (buffer[0]) {
case CVMX_SFP_CONN_SFP:
err = cvmx_sfp_parse_sfp_buffer(&sfp->sfp_info, buffer);
break;
case CVMX_SFP_CONN_QSFP:
case CVMX_SFP_CONN_QSFPP:
case CVMX_SFP_CONN_QSFP28:
case CVMX_SFP_CONN_MICRO_QSFP:
err = cvmx_sfp_parse_qsfp_buffer(&sfp->sfp_info, buffer);
break;
default:
debug("%s: Unknown SFP transceiver type 0x%x\n", __func__,
buffer[0]);
err = -1;
break;
}
error:
if (is_qsfp)
err |= cvmx_qsfp_select(sfp, false);
if (!err) {
sfp->valid = true;
sfp->sfp_info.valid = true;
} else {
sfp->valid = false;
sfp->sfp_info.valid = false;
}
return err;
}
/**
* Function called to check and return the status of the mod_abs pin or
* mod_pres pin for QSFPs.
*
* @param sfp Handle to SFP information.
* @param data User-defined data passed to the function
*
* @return 0 if absent, 1 if present, -1 on error
*/
int cvmx_sfp_check_mod_abs(struct cvmx_fdt_sfp_info *sfp, void *data)
{
int val;
int err = 0;
int mode;
if (!dm_gpio_is_valid(&sfp->mod_abs)) {
debug("%s: Error: mod_abs not set for %s\n", __func__,
sfp->name);
return -1;
}
val = dm_gpio_get_value(&sfp->mod_abs);
debug("%s(%s, %p) mod_abs: %d\n", __func__, sfp->name, data, val);
if (val >= 0 && val != sfp->last_mod_abs && sfp->mod_abs_changed) {
err = 0;
if (!val) {
err = cvmx_sfp_read_i2c_eeprom(sfp);
if (err)
debug("%s: Error reading SFP %s EEPROM\n",
__func__, sfp->name);
}
err = sfp->mod_abs_changed(sfp, val, sfp->mod_abs_changed_data);
}
debug("%s(%s (%p)): Last mod_abs: %d, current: %d, changed: %p, rc: %d, next: %p, caller: %p\n",
__func__, sfp->name, sfp, sfp->last_mod_abs, val,
sfp->mod_abs_changed, err, sfp->next_iface_sfp,
__builtin_return_address(0));
if (err >= 0) {
sfp->last_mod_abs = val;
mode = cvmx_helper_interface_get_mode(sfp->xiface);
cvmx_sfp_validate_module(sfp, mode);
} else {
debug("%s: mod_abs_changed for %s returned error\n", __func__,
sfp->name);
}
return err < 0 ? err : val;
}
/**
* Reads the EEPROMs of all SFP modules.
*
* @return 0 for success
*/
int cvmx_sfp_read_all_modules(void)
{
struct cvmx_fdt_sfp_info *sfp;
int val;
bool error = false;
int rc;
for (sfp = sfp_list; sfp; sfp = sfp->next) {
if (dm_gpio_is_valid(&sfp->mod_abs)) {
/* Check if module absent */
val = dm_gpio_get_value(&sfp->mod_abs);
sfp->last_mod_abs = val;
if (val)
continue;
}
rc = cvmx_sfp_read_i2c_eeprom(sfp);
if (rc) {
debug("%s: Error reading eeprom from SFP %s\n",
__func__, sfp->name);
error = true;
}
}
return error ? -1 : 0;
}
/**
* Registers a function to be called whenever the mod_abs/mod_pres signal
* changes.
*
* @param sfp Handle to SFP data structure
* @param mod_abs_changed Function called whenever mod_abs is changed
* or NULL to remove.
* @param mod_abs_changed_data User-defined data passed to
* mod_abs_changed
*
* @return 0 for success
*
* @NOTE: If multiple SFP slots are linked together, all subsequent slots
* will also be registered for the same handler.
*/
int cvmx_sfp_register_mod_abs_changed(struct cvmx_fdt_sfp_info *sfp,
int (*mod_abs_changed)(struct cvmx_fdt_sfp_info *sfp,
int val, void *data),
void *mod_abs_changed_data)
{
sfp->mod_abs_changed = mod_abs_changed;
sfp->mod_abs_changed_data = mod_abs_changed_data;
sfp->last_mod_abs = -2; /* undefined */
return 0;
}
/**
* Parses a SFP slot from the device tree
*
* @param sfp SFP handle to store data in
* @param fdt_addr Address of flat device tree
* @param of_offset Node in device tree for SFP slot
*
* @return 0 on success, -1 on error
*/
static int cvmx_sfp_parse_sfp(struct cvmx_fdt_sfp_info *sfp, ofnode node)
{
struct ofnode_phandle_args phandle;
int err;
sfp->name = ofnode_get_name(node);
sfp->of_offset = ofnode_to_offset(node);
err = gpio_request_by_name_nodev(node, "tx_disable", 0,
&sfp->tx_disable, GPIOD_IS_OUT);
if (err) {
printf("%s: tx_disable not found in DT!\n", __func__);
return -ENODEV;
}
dm_gpio_set_value(&sfp->tx_disable, 0);
err = gpio_request_by_name_nodev(node, "mod_abs", 0,
&sfp->mod_abs, GPIOD_IS_IN);
if (err) {
printf("%s: mod_abs not found in DT!\n", __func__);
return -ENODEV;
}
err = gpio_request_by_name_nodev(node, "tx_error", 0,
&sfp->tx_error, GPIOD_IS_IN);
if (err) {
printf("%s: tx_error not found in DT!\n", __func__);
return -ENODEV;
}
err = gpio_request_by_name_nodev(node, "rx_los", 0,
&sfp->rx_los, GPIOD_IS_IN);
if (err) {
printf("%s: rx_los not found in DT!\n", __func__);
return -ENODEV;
}
err = ofnode_parse_phandle_with_args(node, "eeprom", NULL, 0, 0,
&phandle);
if (!err) {
sfp->i2c_eeprom_addr = ofnode_get_addr(phandle.node);
debug("%s: eeprom address: 0x%x\n", __func__,
sfp->i2c_eeprom_addr);
debug("%s: Getting eeprom i2c bus for %s\n", __func__,
sfp->name);
sfp->i2c_bus = cvmx_ofnode_get_i2c_bus(ofnode_get_parent(phandle.node));
}
err = ofnode_parse_phandle_with_args(node, "diag", NULL, 0, 0,
&phandle);
if (!err) {
sfp->i2c_diag_addr = ofnode_get_addr(phandle.node);
if (!sfp->i2c_bus)
sfp->i2c_bus = cvmx_ofnode_get_i2c_bus(ofnode_get_parent(phandle.node));
}
sfp->last_mod_abs = -2;
sfp->last_rx_los = -2;
if (!sfp->i2c_bus) {
debug("%s(%s): Error: could not get i2c bus from device tree\n",
__func__, sfp->name);
err = -1;
}
if (err) {
dm_gpio_free(sfp->tx_disable.dev, &sfp->tx_disable);
dm_gpio_free(sfp->mod_abs.dev, &sfp->mod_abs);
dm_gpio_free(sfp->tx_error.dev, &sfp->tx_error);
dm_gpio_free(sfp->rx_los.dev, &sfp->rx_los);
} else {
sfp->valid = true;
}
return err;
}
/**
* Parses a QSFP slot from the device tree
*
* @param sfp SFP handle to store data in
* @param fdt_addr Address of flat device tree
* @param of_offset Node in device tree for SFP slot
*
* @return 0 on success, -1 on error
*/
static int cvmx_sfp_parse_qsfp(struct cvmx_fdt_sfp_info *sfp, ofnode node)
{
struct ofnode_phandle_args phandle;
int err;
sfp->is_qsfp = true;
sfp->name = ofnode_get_name(node);
sfp->of_offset = ofnode_to_offset(node);
err = gpio_request_by_name_nodev(node, "lp_mode", 0,
&sfp->lp_mode, GPIOD_IS_OUT);
if (err) {
printf("%s: lp_mode not found in DT!\n", __func__);
return -ENODEV;
}
err = gpio_request_by_name_nodev(node, "mod_prs", 0,
&sfp->mod_abs, GPIOD_IS_IN);
if (err) {
printf("%s: mod_prs not found in DT!\n", __func__);
return -ENODEV;
}
err = gpio_request_by_name_nodev(node, "select", 0,
&sfp->select, GPIOD_IS_IN);
if (err) {
printf("%s: select not found in DT!\n", __func__);
return -ENODEV;
}
err = gpio_request_by_name_nodev(node, "reset", 0,
&sfp->reset, GPIOD_IS_OUT);
if (err) {
printf("%s: reset not found in DT!\n", __func__);
return -ENODEV;
}
err = gpio_request_by_name_nodev(node, "interrupt", 0,
&sfp->interrupt, GPIOD_IS_IN);
if (err) {
printf("%s: interrupt not found in DT!\n", __func__);
return -ENODEV;
}
err = ofnode_parse_phandle_with_args(node, "eeprom", NULL, 0, 0,
&phandle);
if (!err) {
sfp->i2c_eeprom_addr = ofnode_get_addr(phandle.node);
sfp->i2c_bus = cvmx_ofnode_get_i2c_bus(ofnode_get_parent(phandle.node));
}
err = ofnode_parse_phandle_with_args(node, "diag", NULL, 0, 0,
&phandle);
if (!err) {
sfp->i2c_diag_addr = ofnode_get_addr(phandle.node);
if (!sfp->i2c_bus)
sfp->i2c_bus = cvmx_ofnode_get_i2c_bus(ofnode_get_parent(phandle.node));
}
sfp->last_mod_abs = -2;
sfp->last_rx_los = -2;
if (!sfp->i2c_bus) {
cvmx_printf("%s(%s): Error: could not get i2c bus from device tree\n",
__func__, sfp->name);
err = -1;
}
if (err) {
dm_gpio_free(sfp->lp_mode.dev, &sfp->lp_mode);
dm_gpio_free(sfp->mod_abs.dev, &sfp->mod_abs);
dm_gpio_free(sfp->select.dev, &sfp->select);
dm_gpio_free(sfp->reset.dev, &sfp->reset);
dm_gpio_free(sfp->interrupt.dev, &sfp->interrupt);
} else {
sfp->valid = true;
}
return err;
}
/**
* Parses the device tree for SFP and QSFP slots
*
* @param fdt_addr Address of flat device-tree
*
* @return 0 for success, -1 on error
*/
int cvmx_sfp_parse_device_tree(const void *fdt_addr)
{
struct cvmx_fdt_sfp_info *sfp, *first_sfp = NULL, *last_sfp = NULL;
ofnode node;
int err = 0;
int reg;
static bool parsed;
debug("%s(%p): Parsing...\n", __func__, fdt_addr);
if (parsed) {
debug("%s(%p): Already parsed\n", __func__, fdt_addr);
return 0;
}
ofnode_for_each_compatible_node(node, "ethernet,sfp-slot") {
if (!ofnode_valid(node))
continue;
sfp = cvm_sfp_alloc(sizeof(*sfp));
if (!sfp)
return -1;
err = cvmx_sfp_parse_sfp(sfp, node);
if (!err) {
if (!sfp_list)
sfp_list = sfp;
if (last_sfp)
last_sfp->next = sfp;
sfp->prev = last_sfp;
last_sfp = sfp;
debug("%s: parsed %s\n", __func__, sfp->name);
} else {
debug("%s: Error parsing SFP at node %s\n",
__func__, ofnode_get_name(node));
return err;
}
}
ofnode_for_each_compatible_node(node, "ethernet,qsfp-slot") {
if (!ofnode_valid(node))
continue;
sfp = cvm_sfp_alloc(sizeof(*sfp));
if (!sfp)
return -1;
err = cvmx_sfp_parse_qsfp(sfp, node);
if (!err) {
if (!sfp_list)
sfp_list = sfp;
if (last_sfp)
last_sfp->next = sfp;
sfp->prev = last_sfp;
last_sfp = sfp;
debug("%s: parsed %s\n", __func__, sfp->name);
} else {
debug("%s: Error parsing QSFP at node %s\n",
__func__, ofnode_get_name(node));
return err;
}
}
if (!octeon_has_feature(OCTEON_FEATURE_BGX))
return 0;
err = 0;
ofnode_for_each_compatible_node(node, "cavium,octeon-7890-bgx-port") {
int sfp_nodes[4];
ofnode sfp_ofnodes[4];
int num_sfp_nodes;
u64 reg_addr;
struct cvmx_xiface xi;
int xiface, index;
cvmx_helper_interface_mode_t mode;
int i;
int rc;
if (!ofnode_valid(node))
break;
num_sfp_nodes = ARRAY_SIZE(sfp_nodes);
rc = cvmx_ofnode_lookup_phandles(node, "sfp-slot",
&num_sfp_nodes, sfp_ofnodes);
if (rc != 0 || num_sfp_nodes < 1)
rc = cvmx_ofnode_lookup_phandles(node, "qsfp-slot",
&num_sfp_nodes,
sfp_ofnodes);
/* If no SFP or QSFP slot found, go to next port */
if (rc < 0)
continue;
last_sfp = NULL;
for (i = 0; i < num_sfp_nodes; i++) {
sfp = cvmx_sfp_find_slot_by_fdt_node(ofnode_to_offset(sfp_ofnodes[i]));
debug("%s: Adding sfp %s (%p) to BGX port\n",
__func__, sfp->name, sfp);
if (last_sfp)
last_sfp->next_iface_sfp = sfp;
else
first_sfp = sfp;
last_sfp = sfp;
}
if (!first_sfp) {
debug("%s: Error: could not find SFP slot for BGX port %s\n",
__func__,
fdt_get_name(fdt_addr, sfp_nodes[0],
NULL));
err = -1;
break;
}
/* Get the port index */
reg = ofnode_get_addr(node);
if (reg < 0) {
debug("%s: Error: could not get BGX port reg value\n",
__func__);
err = -1;
break;
}
index = reg;
/* Get BGX node and address */
reg_addr = ofnode_get_addr(ofnode_get_parent(node));
/* Extrace node */
xi.node = cvmx_csr_addr_to_node(reg_addr);
/* Extract reg address */
reg_addr = cvmx_csr_addr_strip_node(reg_addr);
if ((reg_addr & 0xFFFFFFFFF0000000) !=
0x00011800E0000000) {
debug("%s: Invalid BGX address 0x%llx\n",
__func__, (unsigned long long)reg_addr);
xi.node = -1;
err = -1;
break;
}
/* Extract interface from address */
xi.interface = (reg_addr >> 24) & 0x0F;
/* Convert to xiface */
xiface = cvmx_helper_node_interface_to_xiface(xi.node,
xi.interface);
debug("%s: Parsed %d SFP slots for interface 0x%x, index %d\n",
__func__, num_sfp_nodes, xiface, index);
mode = cvmx_helper_interface_get_mode(xiface);
for (sfp = first_sfp; sfp; sfp = sfp->next_iface_sfp) {
sfp->xiface = xiface;
sfp->index = index;
/* Convert to IPD port */
sfp->ipd_port[0] =
cvmx_helper_get_ipd_port(xiface, index);
debug("%s: sfp %s (%p) xi: 0x%x, index: 0x%x, node: %d, mode: 0x%x, next: %p\n",
__func__, sfp->name, sfp, sfp->xiface,
sfp->index, xi.node, mode,
sfp->next_iface_sfp);
if (mode == CVMX_HELPER_INTERFACE_MODE_XLAUI ||
mode == CVMX_HELPER_INTERFACE_MODE_40G_KR4)
for (i = 1; i < 4; i++)
sfp->ipd_port[i] = -1;
else
for (i = 1; i < 4; i++)
sfp->ipd_port[i] =
cvmx_helper_get_ipd_port(
xiface, i);
}
cvmx_helper_cfg_set_sfp_info(xiface, index, first_sfp);
}
if (!err) {
parsed = true;
cvmx_sfp_read_all_modules();
}
return err;
}
/**
* Given a fdt node offset find the corresponding SFP or QSFP slot
*
* @param of_offset flat device tree node offset
*
* @return pointer to SFP data structure or NULL if not found
*/
struct cvmx_fdt_sfp_info *cvmx_sfp_find_slot_by_fdt_node(int of_offset)
{
struct cvmx_fdt_sfp_info *sfp = sfp_list;
while (sfp) {
if (sfp->of_offset == of_offset)
return sfp;
sfp = sfp->next;
}
return NULL;
}
static bool cvmx_sfp_validate_quad(struct cvmx_fdt_sfp_info *sfp,
struct cvmx_phy_gpio_leds *leds)
{
bool multi_led = leds && (leds->next);
bool error = false;
int mod_abs;
do {
/* Skip missing modules */
if (dm_gpio_is_valid(&sfp->mod_abs))
mod_abs = dm_gpio_get_value(&sfp->mod_abs);
else
mod_abs = 0;
if (!mod_abs) {
if (cvmx_sfp_read_i2c_eeprom(sfp)) {
debug("%s: Error reading eeprom for %s\n",
__func__, sfp->name);
}
if (sfp->sfp_info.rate < CVMX_SFP_RATE_10G) {
cvmx_helper_leds_show_error(leds, true);
error = true;
} else if (sfp->sfp_info.rate >= CVMX_SFP_RATE_10G) {
/* We don't support 10GBase-T modules in
* this mode.
*/
switch (sfp->sfp_info.cable_comp) {
case CVMX_SFP_CABLE_10GBASE_T:
case CVMX_SFP_CABLE_10GBASE_T_SR:
case CVMX_SFP_CABLE_5GBASE_T:
case CVMX_SFP_CABLE_2_5GBASE_T:
cvmx_helper_leds_show_error(leds, true);
error = true;
break;
default:
break;
}
}
} else if (multi_led) {
cvmx_helper_leds_show_error(leds, false);
}
if (multi_led && leds->next)
leds = leds->next;
sfp = sfp->next_iface_sfp;
} while (sfp);
if (!multi_led)
cvmx_helper_leds_show_error(leds, error);
return error;
}
/**
* Validates if the module is correct for the specified port
*
* @param[in] sfp SFP port to check
* @param xiface interface
* @param index port index
* @param speed link speed, -1 if unknown
* @param mode interface mode
*
* @return true if module is valid, false if invalid
* NOTE: This will also toggle the error LED, if present
*/
bool cvmx_sfp_validate_module(struct cvmx_fdt_sfp_info *sfp, int mode)
{
const struct cvmx_sfp_mod_info *mod_info = &sfp->sfp_info;
int xiface = sfp->xiface;
int index = sfp->index;
struct cvmx_phy_gpio_leds *leds;
bool error = false;
bool quad_mode = false;
debug("%s(%s, 0x%x, 0x%x, 0x%x)\n", __func__, sfp->name, xiface, index,
mode);
if (!sfp) {
debug("%s: Error: sfp is NULL\n", __func__);
return false;
}
/* No module is valid */
leds = cvmx_helper_get_port_phy_leds(xiface, index);
if (!leds)
debug("%s: No leds for 0x%x:0x%x\n", __func__, xiface, index);
if (mode != CVMX_HELPER_INTERFACE_MODE_XLAUI &&
mode != CVMX_HELPER_INTERFACE_MODE_40G_KR4 && !sfp->is_qsfp &&
sfp->last_mod_abs && leds) {
cvmx_helper_leds_show_error(leds, false);
debug("%s: %s: last_mod_abs: %d, no error\n", __func__,
sfp->name, sfp->last_mod_abs);
return true;
}
switch (mode) {
case CVMX_HELPER_INTERFACE_MODE_RGMII:
case CVMX_HELPER_INTERFACE_MODE_GMII:
case CVMX_HELPER_INTERFACE_MODE_SGMII:
case CVMX_HELPER_INTERFACE_MODE_QSGMII:
case CVMX_HELPER_INTERFACE_MODE_AGL:
case CVMX_HELPER_INTERFACE_MODE_SPI:
if ((mod_info->active_cable &&
mod_info->rate != CVMX_SFP_RATE_1G) ||
mod_info->rate < CVMX_SFP_RATE_1G)
error = true;
break;
case CVMX_HELPER_INTERFACE_MODE_RXAUI:
case CVMX_HELPER_INTERFACE_MODE_XAUI:
case CVMX_HELPER_INTERFACE_MODE_10G_KR:
case CVMX_HELPER_INTERFACE_MODE_XFI:
if ((mod_info->active_cable &&
mod_info->rate != CVMX_SFP_RATE_10G) ||
mod_info->rate < CVMX_SFP_RATE_10G)
error = true;
break;
case CVMX_HELPER_INTERFACE_MODE_XLAUI:
case CVMX_HELPER_INTERFACE_MODE_40G_KR4:
if (!sfp->is_qsfp) {
quad_mode = true;
error = cvmx_sfp_validate_quad(sfp, leds);
} else {
if ((mod_info->active_cable &&
mod_info->rate != CVMX_SFP_RATE_40G) ||
mod_info->rate < CVMX_SFP_RATE_25G)
error = true;
}
break;
default:
debug("%s: Unsupported interface mode %d on xiface 0x%x\n",
__func__, mode, xiface);
return false;
}
debug("%s: %s: error: %d\n", __func__, sfp->name, error);
if (leds && !quad_mode)
cvmx_helper_leds_show_error(leds, error);
return !error;
}
|