summaryrefslogtreecommitdiff
path: root/drivers/raw/ifpga/base/ifpga_fme.c
blob: 2bc7c10a766605d91b17b4f8295104d2de7a9095 (plain)
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
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2018 Intel Corporation
 */

#include "ifpga_feature_dev.h"
#include "opae_spi.h"
#include "opae_intel_max10.h"
#include "opae_i2c.h"
#include "opae_at24_eeprom.h"

#define PWR_THRESHOLD_MAX       0x7F

int fme_get_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop)
{
	struct ifpga_feature *feature;

	if (!fme)
		return -ENOENT;

	feature = get_fme_feature_by_id(fme, prop->feature_id);

	if (feature && feature->ops && feature->ops->get_prop)
		return feature->ops->get_prop(feature, prop);

	return -ENOENT;
}

int fme_set_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop)
{
	struct ifpga_feature *feature;

	if (!fme)
		return -ENOENT;

	feature = get_fme_feature_by_id(fme, prop->feature_id);

	if (feature && feature->ops && feature->ops->set_prop)
		return feature->ops->set_prop(feature, prop);

	return -ENOENT;
}

int fme_set_irq(struct ifpga_fme_hw *fme, u32 feature_id, void *irq_set)
{
	struct ifpga_feature *feature;

	if (!fme)
		return -ENOENT;

	feature = get_fme_feature_by_id(fme, feature_id);

	if (feature && feature->ops && feature->ops->set_irq)
		return feature->ops->set_irq(feature, irq_set);

	return -ENOENT;
}

/* fme private feature head */
static int fme_hdr_init(struct ifpga_feature *feature)
{
	struct feature_fme_header *fme_hdr;

	fme_hdr = (struct feature_fme_header *)feature->addr;

	dev_info(NULL, "FME HDR Init.\n");
	dev_info(NULL, "FME cap %llx.\n",
		 (unsigned long long)fme_hdr->capability.csr);

	return 0;
}

static void fme_hdr_uinit(struct ifpga_feature *feature)
{
	UNUSED(feature);

	dev_info(NULL, "FME HDR UInit.\n");
}

static int fme_hdr_get_revision(struct ifpga_fme_hw *fme, u64 *revision)
{
	struct feature_fme_header *fme_hdr
		= get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);
	struct feature_header header;

	header.csr = readq(&fme_hdr->header);
	*revision = header.revision;

	return 0;
}

static int fme_hdr_get_ports_num(struct ifpga_fme_hw *fme, u64 *ports_num)
{
	struct feature_fme_header *fme_hdr
		= get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);
	struct feature_fme_capability fme_capability;

	fme_capability.csr = readq(&fme_hdr->capability);
	*ports_num = fme_capability.num_ports;

	return 0;
}

static int fme_hdr_get_cache_size(struct ifpga_fme_hw *fme, u64 *cache_size)
{
	struct feature_fme_header *fme_hdr
		= get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);
	struct feature_fme_capability fme_capability;

	fme_capability.csr = readq(&fme_hdr->capability);
	*cache_size = fme_capability.cache_size;

	return 0;
}

static int fme_hdr_get_version(struct ifpga_fme_hw *fme, u64 *version)
{
	struct feature_fme_header *fme_hdr
		= get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);
	struct feature_fme_capability fme_capability;

	fme_capability.csr = readq(&fme_hdr->capability);
	*version = fme_capability.fabric_verid;

	return 0;
}

static int fme_hdr_get_socket_id(struct ifpga_fme_hw *fme, u64 *socket_id)
{
	struct feature_fme_header *fme_hdr
		= get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);
	struct feature_fme_capability fme_capability;

	fme_capability.csr = readq(&fme_hdr->capability);
	*socket_id = fme_capability.socket_id;

	return 0;
}

static int fme_hdr_get_bitstream_id(struct ifpga_fme_hw *fme,
				    u64 *bitstream_id)
{
	struct feature_fme_header *fme_hdr
		= get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);

	*bitstream_id = readq(&fme_hdr->bitstream_id);

	return 0;
}

static int fme_hdr_get_bitstream_metadata(struct ifpga_fme_hw *fme,
					  u64 *bitstream_metadata)
{
	struct feature_fme_header *fme_hdr
		= get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);

	*bitstream_metadata = readq(&fme_hdr->bitstream_md);

	return 0;
}

static int
fme_hdr_get_prop(struct ifpga_feature *feature, struct feature_prop *prop)
{
	struct ifpga_fme_hw *fme = feature->parent;

	switch (prop->prop_id) {
	case FME_HDR_PROP_REVISION:
		return fme_hdr_get_revision(fme, &prop->data);
	case FME_HDR_PROP_PORTS_NUM:
		return fme_hdr_get_ports_num(fme, &prop->data);
	case FME_HDR_PROP_CACHE_SIZE:
		return fme_hdr_get_cache_size(fme, &prop->data);
	case FME_HDR_PROP_VERSION:
		return fme_hdr_get_version(fme, &prop->data);
	case FME_HDR_PROP_SOCKET_ID:
		return fme_hdr_get_socket_id(fme, &prop->data);
	case FME_HDR_PROP_BITSTREAM_ID:
		return fme_hdr_get_bitstream_id(fme, &prop->data);
	case FME_HDR_PROP_BITSTREAM_METADATA:
		return fme_hdr_get_bitstream_metadata(fme, &prop->data);
	}

	return -ENOENT;
}

struct ifpga_feature_ops fme_hdr_ops = {
	.init = fme_hdr_init,
	.uinit = fme_hdr_uinit,
	.get_prop = fme_hdr_get_prop,
};

/* thermal management */
static int fme_thermal_get_threshold1(struct ifpga_fme_hw *fme, u64 *thres1)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_tmp_threshold temp_threshold;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);

	temp_threshold.csr = readq(&thermal->threshold);
	*thres1 = temp_threshold.tmp_thshold1;

	return 0;
}

static int fme_thermal_set_threshold1(struct ifpga_fme_hw *fme, u64 thres1)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_header *fme_hdr;
	struct feature_fme_tmp_threshold tmp_threshold;
	struct feature_fme_capability fme_capability;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);
	fme_hdr = get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);

	spinlock_lock(&fme->lock);
	tmp_threshold.csr = readq(&thermal->threshold);
	fme_capability.csr = readq(&fme_hdr->capability);

	if (fme_capability.lock_bit == 1) {
		spinlock_unlock(&fme->lock);
		return -EBUSY;
	} else if (thres1 > 100) {
		spinlock_unlock(&fme->lock);
		return -EINVAL;
	} else if (thres1 == 0) {
		tmp_threshold.tmp_thshold1_enable = 0;
		tmp_threshold.tmp_thshold1 = thres1;
	} else {
		tmp_threshold.tmp_thshold1_enable = 1;
		tmp_threshold.tmp_thshold1 = thres1;
	}

	writeq(tmp_threshold.csr, &thermal->threshold);
	spinlock_unlock(&fme->lock);

	return 0;
}

static int fme_thermal_get_threshold2(struct ifpga_fme_hw *fme, u64 *thres2)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_tmp_threshold temp_threshold;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);

	temp_threshold.csr = readq(&thermal->threshold);
	*thres2 = temp_threshold.tmp_thshold2;

	return 0;
}

static int fme_thermal_set_threshold2(struct ifpga_fme_hw *fme, u64 thres2)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_header *fme_hdr;
	struct feature_fme_tmp_threshold tmp_threshold;
	struct feature_fme_capability fme_capability;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);
	fme_hdr = get_fme_feature_ioaddr_by_index(fme, FME_FEATURE_ID_HEADER);

	spinlock_lock(&fme->lock);
	tmp_threshold.csr = readq(&thermal->threshold);
	fme_capability.csr = readq(&fme_hdr->capability);

	if (fme_capability.lock_bit == 1) {
		spinlock_unlock(&fme->lock);
		return -EBUSY;
	} else if (thres2 > 100) {
		spinlock_unlock(&fme->lock);
		return -EINVAL;
	} else if (thres2 == 0) {
		tmp_threshold.tmp_thshold2_enable = 0;
		tmp_threshold.tmp_thshold2 = thres2;
	} else {
		tmp_threshold.tmp_thshold2_enable = 1;
		tmp_threshold.tmp_thshold2 = thres2;
	}

	writeq(tmp_threshold.csr, &thermal->threshold);
	spinlock_unlock(&fme->lock);

	return 0;
}

static int fme_thermal_get_threshold_trip(struct ifpga_fme_hw *fme,
					  u64 *thres_trip)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_tmp_threshold temp_threshold;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);

	temp_threshold.csr = readq(&thermal->threshold);
	*thres_trip = temp_threshold.therm_trip_thshold;

	return 0;
}

static int fme_thermal_get_threshold1_reached(struct ifpga_fme_hw *fme,
					      u64 *thres1_reached)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_tmp_threshold temp_threshold;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);

	temp_threshold.csr = readq(&thermal->threshold);
	*thres1_reached = temp_threshold.thshold1_status;

	return 0;
}

static int fme_thermal_get_threshold2_reached(struct ifpga_fme_hw *fme,
					      u64 *thres1_reached)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_tmp_threshold temp_threshold;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);

	temp_threshold.csr = readq(&thermal->threshold);
	*thres1_reached = temp_threshold.thshold2_status;

	return 0;
}

static int fme_thermal_get_threshold1_policy(struct ifpga_fme_hw *fme,
					     u64 *thres1_policy)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_tmp_threshold temp_threshold;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);

	temp_threshold.csr = readq(&thermal->threshold);
	*thres1_policy = temp_threshold.thshold_policy;

	return 0;
}

static int fme_thermal_set_threshold1_policy(struct ifpga_fme_hw *fme,
					     u64 thres1_policy)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_tmp_threshold tmp_threshold;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);

	spinlock_lock(&fme->lock);
	tmp_threshold.csr = readq(&thermal->threshold);

	if (thres1_policy == 0) {
		tmp_threshold.thshold_policy = 0;
	} else if (thres1_policy == 1) {
		tmp_threshold.thshold_policy = 1;
	} else {
		spinlock_unlock(&fme->lock);
		return -EINVAL;
	}

	writeq(tmp_threshold.csr, &thermal->threshold);
	spinlock_unlock(&fme->lock);

	return 0;
}

static int fme_thermal_get_temperature(struct ifpga_fme_hw *fme, u64 *temp)
{
	struct feature_fme_thermal *thermal;
	struct feature_fme_temp_rdsensor_fmt1 temp_rdsensor_fmt1;

	thermal = get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);

	temp_rdsensor_fmt1.csr = readq(&thermal->rdsensor_fm1);
	*temp = temp_rdsensor_fmt1.fpga_temp;

	return 0;
}

static int fme_thermal_get_revision(struct ifpga_fme_hw *fme, u64 *revision)
{
	struct feature_fme_thermal *fme_thermal
		= get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_THERMAL_MGMT);
	struct feature_header header;

	header.csr = readq(&fme_thermal->header);
	*revision = header.revision;

	return 0;
}

#define FME_THERMAL_CAP_NO_TMP_THRESHOLD	0x1

static int fme_thermal_mgmt_init(struct ifpga_feature *feature)
{
	struct feature_fme_thermal *fme_thermal;
	struct feature_fme_tmp_threshold_cap thermal_cap;

	UNUSED(feature);

	dev_info(NULL, "FME thermal mgmt Init.\n");

	fme_thermal = (struct feature_fme_thermal *)feature->addr;
	thermal_cap.csr = readq(&fme_thermal->threshold_cap);

	dev_info(NULL, "FME thermal cap %llx.\n",
		 (unsigned long long)fme_thermal->threshold_cap.csr);

	if (thermal_cap.tmp_thshold_disabled)
		feature->cap |= FME_THERMAL_CAP_NO_TMP_THRESHOLD;

	return 0;
}

static void fme_thermal_mgmt_uinit(struct ifpga_feature *feature)
{
	UNUSED(feature);

	dev_info(NULL, "FME thermal mgmt UInit.\n");
}

static int
fme_thermal_set_prop(struct ifpga_feature *feature, struct feature_prop *prop)
{
	struct ifpga_fme_hw *fme = feature->parent;

	if (feature->cap & FME_THERMAL_CAP_NO_TMP_THRESHOLD)
		return -ENOENT;

	switch (prop->prop_id) {
	case FME_THERMAL_PROP_THRESHOLD1:
		return fme_thermal_set_threshold1(fme, prop->data);
	case FME_THERMAL_PROP_THRESHOLD2:
		return fme_thermal_set_threshold2(fme, prop->data);
	case FME_THERMAL_PROP_THRESHOLD1_POLICY:
		return fme_thermal_set_threshold1_policy(fme, prop->data);
	}

	return -ENOENT;
}

static int
fme_thermal_get_prop(struct ifpga_feature *feature, struct feature_prop *prop)
{
	struct ifpga_fme_hw *fme = feature->parent;

	if (feature->cap & FME_THERMAL_CAP_NO_TMP_THRESHOLD &&
	    prop->prop_id != FME_THERMAL_PROP_TEMPERATURE &&
	    prop->prop_id != FME_THERMAL_PROP_REVISION)
		return -ENOENT;

	switch (prop->prop_id) {
	case FME_THERMAL_PROP_THRESHOLD1:
		return fme_thermal_get_threshold1(fme, &prop->data);
	case FME_THERMAL_PROP_THRESHOLD2:
		return fme_thermal_get_threshold2(fme, &prop->data);
	case FME_THERMAL_PROP_THRESHOLD_TRIP:
		return fme_thermal_get_threshold_trip(fme, &prop->data);
	case FME_THERMAL_PROP_THRESHOLD1_REACHED:
		return fme_thermal_get_threshold1_reached(fme, &prop->data);
	case FME_THERMAL_PROP_THRESHOLD2_REACHED:
		return fme_thermal_get_threshold2_reached(fme, &prop->data);
	case FME_THERMAL_PROP_THRESHOLD1_POLICY:
		return fme_thermal_get_threshold1_policy(fme, &prop->data);
	case FME_THERMAL_PROP_TEMPERATURE:
		return fme_thermal_get_temperature(fme, &prop->data);
	case FME_THERMAL_PROP_REVISION:
		return fme_thermal_get_revision(fme, &prop->data);
	}

	return -ENOENT;
}

struct ifpga_feature_ops fme_thermal_mgmt_ops = {
	.init = fme_thermal_mgmt_init,
	.uinit = fme_thermal_mgmt_uinit,
	.get_prop = fme_thermal_get_prop,
	.set_prop = fme_thermal_set_prop,
};

static int fme_pwr_get_consumed(struct ifpga_fme_hw *fme, u64 *consumed)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_status pm_status;

	pm_status.csr = readq(&fme_power->status);

	*consumed = pm_status.pwr_consumed;

	return 0;
}

static int fme_pwr_get_threshold1(struct ifpga_fme_hw *fme, u64 *threshold)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_ap_threshold pm_ap_threshold;

	pm_ap_threshold.csr = readq(&fme_power->threshold);

	*threshold = pm_ap_threshold.threshold1;

	return 0;
}

static int fme_pwr_set_threshold1(struct ifpga_fme_hw *fme, u64 threshold)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_ap_threshold pm_ap_threshold;

	spinlock_lock(&fme->lock);
	pm_ap_threshold.csr = readq(&fme_power->threshold);

	if (threshold <= PWR_THRESHOLD_MAX) {
		pm_ap_threshold.threshold1 = threshold;
	} else {
		spinlock_unlock(&fme->lock);
		return -EINVAL;
	}

	writeq(pm_ap_threshold.csr, &fme_power->threshold);
	spinlock_unlock(&fme->lock);

	return 0;
}

static int fme_pwr_get_threshold2(struct ifpga_fme_hw *fme, u64 *threshold)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_ap_threshold pm_ap_threshold;

	pm_ap_threshold.csr = readq(&fme_power->threshold);

	*threshold = pm_ap_threshold.threshold2;

	return 0;
}

static int fme_pwr_set_threshold2(struct ifpga_fme_hw *fme, u64 threshold)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_ap_threshold pm_ap_threshold;

	spinlock_lock(&fme->lock);
	pm_ap_threshold.csr = readq(&fme_power->threshold);

	if (threshold <= PWR_THRESHOLD_MAX) {
		pm_ap_threshold.threshold2 = threshold;
	} else {
		spinlock_unlock(&fme->lock);
		return -EINVAL;
	}

	writeq(pm_ap_threshold.csr, &fme_power->threshold);
	spinlock_unlock(&fme->lock);

	return 0;
}

static int fme_pwr_get_threshold1_status(struct ifpga_fme_hw *fme,
					 u64 *threshold_status)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_ap_threshold pm_ap_threshold;

	pm_ap_threshold.csr = readq(&fme_power->threshold);

	*threshold_status = pm_ap_threshold.threshold1_status;

	return 0;
}

static int fme_pwr_get_threshold2_status(struct ifpga_fme_hw *fme,
					 u64 *threshold_status)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_ap_threshold pm_ap_threshold;

	pm_ap_threshold.csr = readq(&fme_power->threshold);

	*threshold_status = pm_ap_threshold.threshold2_status;

	return 0;
}

static int fme_pwr_get_rtl(struct ifpga_fme_hw *fme, u64 *rtl)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_status pm_status;

	pm_status.csr = readq(&fme_power->status);

	*rtl = pm_status.fpga_latency_report;

	return 0;
}

static int fme_pwr_get_xeon_limit(struct ifpga_fme_hw *fme, u64 *limit)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_xeon_limit xeon_limit;

	xeon_limit.csr = readq(&fme_power->xeon_limit);

	if (!xeon_limit.enable)
		xeon_limit.pwr_limit = 0;

	*limit = xeon_limit.pwr_limit;

	return 0;
}

static int fme_pwr_get_fpga_limit(struct ifpga_fme_hw *fme, u64 *limit)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
				FME_FEATURE_ID_POWER_MGMT);
	struct feature_fme_pm_fpga_limit fpga_limit;

	fpga_limit.csr = readq(&fme_power->fpga_limit);

	if (!fpga_limit.enable)
		fpga_limit.pwr_limit = 0;

	*limit = fpga_limit.pwr_limit;

	return 0;
}

static int fme_pwr_get_revision(struct ifpga_fme_hw *fme, u64 *revision)
{
	struct feature_fme_power *fme_power
		= get_fme_feature_ioaddr_by_index(fme,
						  FME_FEATURE_ID_POWER_MGMT);
	struct feature_header header;

	header.csr = readq(&fme_power->header);
	*revision = header.revision;

	return 0;
}

static int fme_power_mgmt_init(struct ifpga_feature *feature)
{
	UNUSED(feature);

	dev_info(NULL, "FME power mgmt Init.\n");

	return 0;
}

static void fme_power_mgmt_uinit(struct ifpga_feature *feature)
{
	UNUSED(feature);

	dev_info(NULL, "FME power mgmt UInit.\n");
}

static int fme_power_mgmt_get_prop(struct ifpga_feature *feature,
				   struct feature_prop *prop)
{
	struct ifpga_fme_hw *fme = feature->parent;

	switch (prop->prop_id) {
	case FME_PWR_PROP_CONSUMED:
		return fme_pwr_get_consumed(fme, &prop->data);
	case FME_PWR_PROP_THRESHOLD1:
		return fme_pwr_get_threshold1(fme, &prop->data);
	case FME_PWR_PROP_THRESHOLD2:
		return fme_pwr_get_threshold2(fme, &prop->data);
	case FME_PWR_PROP_THRESHOLD1_STATUS:
		return fme_pwr_get_threshold1_status(fme, &prop->data);
	case FME_PWR_PROP_THRESHOLD2_STATUS:
		return fme_pwr_get_threshold2_status(fme, &prop->data);
	case FME_PWR_PROP_RTL:
		return fme_pwr_get_rtl(fme, &prop->data);
	case FME_PWR_PROP_XEON_LIMIT:
		return fme_pwr_get_xeon_limit(fme, &prop->data);
	case FME_PWR_PROP_FPGA_LIMIT:
		return fme_pwr_get_fpga_limit(fme, &prop->data);
	case FME_PWR_PROP_REVISION:
		return fme_pwr_get_revision(fme, &prop->data);
	}

	return -ENOENT;
}

static int fme_power_mgmt_set_prop(struct ifpga_feature *feature,
				   struct feature_prop *prop)
{
	struct ifpga_fme_hw *fme = feature->parent;

	switch (prop->prop_id) {
	case FME_PWR_PROP_THRESHOLD1:
		return fme_pwr_set_threshold1(fme, prop->data);
	case FME_PWR_PROP_THRESHOLD2:
		return fme_pwr_set_threshold2(fme, prop->data);
	}

	return -ENOENT;
}

struct ifpga_feature_ops fme_power_mgmt_ops = {
	.init = fme_power_mgmt_init,
	.uinit = fme_power_mgmt_uinit,
	.get_prop = fme_power_mgmt_get_prop,
	.set_prop = fme_power_mgmt_set_prop,
};

static int fme_hssi_eth_init(struct ifpga_feature *feature)
{
	UNUSED(feature);
	return 0;
}

static void fme_hssi_eth_uinit(struct ifpga_feature *feature)
{
	UNUSED(feature);
}

struct ifpga_feature_ops fme_hssi_eth_ops = {
	.init = fme_hssi_eth_init,
	.uinit = fme_hssi_eth_uinit,
};

static int fme_emif_init(struct ifpga_feature *feature)
{
	UNUSED(feature);
	return 0;
}

static void fme_emif_uinit(struct ifpga_feature *feature)
{
	UNUSED(feature);
}

struct ifpga_feature_ops fme_emif_ops = {
	.init = fme_emif_init,
	.uinit = fme_emif_uinit,
};

static const char *board_type_to_string(u32 type)
{
	switch (type) {
	case VC_8_10G:
		return "VC_8x10G";
	case VC_4_25G:
		return "VC_4x25G";
	case VC_2_1_25:
		return "VC_2x1x25G";
	case VC_4_25G_2_25G:
		return "VC_4x25G+2x25G";
	case VC_2_2_25G:
		return "VC_2x2x25G";
	}

	return "unknown";
}

static int board_type_to_info(u32 type,
		struct ifpga_fme_board_info *info)
{
	switch (type) {
	case VC_8_10G:
		info->nums_of_retimer = 2;
		info->ports_per_retimer = 4;
		info->nums_of_fvl = 2;
		info->ports_per_fvl = 4;
		break;
	case VC_4_25G:
		info->nums_of_retimer = 1;
		info->ports_per_retimer = 4;
		info->nums_of_fvl = 2;
		info->ports_per_fvl = 2;
		break;
	case VC_2_1_25:
		info->nums_of_retimer = 2;
		info->ports_per_retimer = 1;
		info->nums_of_fvl = 1;
		info->ports_per_fvl = 2;
		break;
	case VC_2_2_25G:
		info->nums_of_retimer = 2;
		info->ports_per_retimer = 2;
		info->nums_of_fvl = 2;
		info->ports_per_fvl = 2;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int fme_get_board_interface(struct ifpga_fme_hw *fme)
{
	struct fme_bitstream_id id;
	u32 val;

	if (fme_hdr_get_bitstream_id(fme, &id.id))
		return -EINVAL;

	fme->board_info.type = id.interface;
	fme->board_info.build_hash = id.hash;
	fme->board_info.debug_version = id.debug;
	fme->board_info.major_version = id.major;
	fme->board_info.minor_version = id.minor;

	dev_info(fme, "board type: %s major_version:%u minor_version:%u build_hash:%u\n",
			board_type_to_string(fme->board_info.type),
			fme->board_info.major_version,
			fme->board_info.minor_version,
			fme->board_info.build_hash);

	if (board_type_to_info(fme->board_info.type, &fme->board_info))
		return -EINVAL;

	dev_info(fme, "get board info: nums_retimers %d ports_per_retimer %d nums_fvl %d ports_per_fvl %d\n",
			fme->board_info.nums_of_retimer,
			fme->board_info.ports_per_retimer,
			fme->board_info.nums_of_fvl,
			fme->board_info.ports_per_fvl);

	if (max10_sys_read(MAX10_BUILD_VER, &val))
		return -EINVAL;
	fme->board_info.max10_version = val & 0xffffff;

	if (max10_sys_read(NIOS2_FW_VERSION, &val))
		return -EINVAL;
	fme->board_info.nios_fw_version = val & 0xffffff;

	dev_info(fme, "max10 version 0x%x, nios fw version 0x%x\n",
		fme->board_info.max10_version,
		fme->board_info.nios_fw_version);

	return 0;
}

static int spi_self_checking(void)
{
	u32 val;
	int ret;

	ret = max10_sys_read(MAX10_TEST_REG, &val);
	if (ret)
		return -EIO;

	dev_info(NULL, "Read MAX10 test register 0x%x\n", val);

	return 0;
}

static int fme_spi_init(struct ifpga_feature *feature)
{
	struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
	struct altera_spi_device *spi_master;
	struct intel_max10_device *max10;
	int ret = 0;

	dev_info(fme, "FME SPI Master (Max10) Init.\n");
	dev_debug(fme, "FME SPI base addr %p.\n",
			feature->addr);
	dev_debug(fme, "spi param=0x%llx\n",
			(unsigned long long)opae_readq(feature->addr + 0x8));

	spi_master = altera_spi_alloc(feature->addr, TYPE_SPI);
	if (!spi_master)
		return -ENODEV;

	altera_spi_init(spi_master);

	max10 = intel_max10_device_probe(spi_master, 0);
	if (!max10) {
		ret = -ENODEV;
		dev_err(fme, "max10 init fail\n");
		goto spi_fail;
	}

	fme->max10_dev = max10;

	/* SPI self test */
	if (spi_self_checking()) {
		ret = -EIO;
		goto max10_fail;
	}

	return ret;

max10_fail:
	intel_max10_device_remove(fme->max10_dev);
spi_fail:
	altera_spi_release(spi_master);
	return ret;
}

static void fme_spi_uinit(struct ifpga_feature *feature)
{
	struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;

	if (fme->max10_dev)
		intel_max10_device_remove(fme->max10_dev);
}

struct ifpga_feature_ops fme_spi_master_ops = {
	.init = fme_spi_init,
	.uinit = fme_spi_uinit,
};

static int nios_spi_wait_init_done(struct altera_spi_device *dev)
{
	u32 val = 0;
	unsigned long timeout = msecs_to_timer_cycles(10000);
	unsigned long ticks;
	int major_version;

	if (spi_reg_read(dev, NIOS_VERSION, &val))
		return -EIO;

	major_version = (val >> NIOS_VERSION_MAJOR_SHIFT) &
		NIOS_VERSION_MAJOR;
	dev_debug(dev, "A10 NIOS FW version %d\n", major_version);

	if (major_version >= 3) {
		/* read NIOS_INIT to check if PKVL INIT done or not */
		if (spi_reg_read(dev, NIOS_INIT, &val))
			return -EIO;

		/* check if PKVLs are initialized already */
		if (val & NIOS_INIT_DONE || val & NIOS_INIT_START)
			goto nios_init_done;

		/* start to config the default FEC mode */
		val = NIOS_INIT_START;

		if (spi_reg_write(dev, NIOS_INIT, val))
			return -EIO;
	}

nios_init_done:
	do {
		if (spi_reg_read(dev, NIOS_INIT, &val))
			return -EIO;
		if (val)
			break;

		ticks = rte_get_timer_cycles();
		if (time_after(ticks, timeout))
			return -ETIMEDOUT;
		msleep(100);
	} while (!val);

	return 0;
}

static int nios_spi_check_error(struct altera_spi_device *dev)
{
	u32 value = 0;

	if (spi_reg_read(dev, PKVL_A_MODE_STS, &value))
		return -EIO;

	dev_debug(dev, "PKVL A Mode Status 0x%x\n", value);

	if (value >= 0x100)
		return -EINVAL;

	if (spi_reg_read(dev, PKVL_B_MODE_STS, &value))
		return -EIO;

	dev_debug(dev, "PKVL B Mode Status 0x%x\n", value);

	if (value >= 0x100)
		return -EINVAL;

	return 0;
}

static int fme_nios_spi_init(struct ifpga_feature *feature)
{
	struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
	struct altera_spi_device *spi_master;
	struct intel_max10_device *max10;
	int ret = 0;

	dev_info(fme, "FME SPI Master (NIOS) Init.\n");
	dev_debug(fme, "FME SPI base addr %p.\n",
			feature->addr);
	dev_debug(fme, "spi param=0x%llx\n",
			(unsigned long long)opae_readq(feature->addr + 0x8));

	spi_master = altera_spi_alloc(feature->addr, TYPE_NIOS_SPI);
	if (!spi_master)
		return -ENODEV;

	/**
	 * 1. wait A10 NIOS initial finished and
	 * release the SPI master to Host
	 */
	ret = nios_spi_wait_init_done(spi_master);
	if (ret != 0) {
		dev_err(fme, "FME NIOS_SPI init fail\n");
		goto release_dev;
	}

	dev_info(fme, "FME NIOS_SPI initial done\n");

	/* 2. check if error occur? */
	if (nios_spi_check_error(spi_master))
		dev_info(fme, "NIOS_SPI INIT done, but found some error\n");

	/* 3. init the spi master*/
	altera_spi_init(spi_master);

	/* init the max10 device */
	max10 = intel_max10_device_probe(spi_master, 0);
	if (!max10) {
		ret = -ENODEV;
		dev_err(fme, "max10 init fail\n");
		goto release_dev;
	}

	fme_get_board_interface(fme);

	fme->max10_dev = max10;

	/* SPI self test */
	if (spi_self_checking())
		goto spi_fail;

	return ret;

spi_fail:
	intel_max10_device_remove(fme->max10_dev);
release_dev:
	altera_spi_release(spi_master);
	return -ENODEV;
}

static void fme_nios_spi_uinit(struct ifpga_feature *feature)
{
	struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;

	if (fme->max10_dev)
		intel_max10_device_remove(fme->max10_dev);
}

struct ifpga_feature_ops fme_nios_spi_master_ops = {
	.init = fme_nios_spi_init,
	.uinit = fme_nios_spi_uinit,
};

static int i2c_mac_rom_test(struct altera_i2c_dev *dev)
{
	char buf[20];
	int ret;
	char read_buf[20] = {0,};
	const char *string = "1a2b3c4d5e";

	opae_memcpy(buf, string, strlen(string));

	ret = at24_eeprom_write(dev, AT24512_SLAVE_ADDR, 0,
			(u8 *)buf, strlen(string));
	if (ret < 0) {
		dev_err(NULL, "write i2c error:%d\n", ret);
		return ret;
	}

	ret = at24_eeprom_read(dev, AT24512_SLAVE_ADDR, 0,
			(u8 *)read_buf, strlen(string));
	if (ret < 0) {
		dev_err(NULL, "read i2c error:%d\n", ret);
		return ret;
	}

	if (memcmp(buf, read_buf, strlen(string))) {
		dev_err(NULL, "%s test fail!\n", __func__);
		return -EFAULT;
	}

	dev_info(NULL, "%s test successful\n", __func__);

	return 0;
}

static int fme_i2c_init(struct ifpga_feature *feature)
{
	struct feature_fme_i2c *i2c;
	struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;

	i2c = (struct feature_fme_i2c *)feature->addr;

	dev_info(NULL, "FME I2C Master Init.\n");

	fme->i2c_master = altera_i2c_probe(i2c);
	if (!fme->i2c_master)
		return -ENODEV;

	/* MAC ROM self test */
	i2c_mac_rom_test(fme->i2c_master);

	return 0;
}

static void fme_i2c_uninit(struct ifpga_feature *feature)
{
	struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;

	altera_i2c_remove(fme->i2c_master);
}

struct ifpga_feature_ops fme_i2c_master_ops = {
	.init = fme_i2c_init,
	.uinit = fme_i2c_uninit,
};

static int fme_eth_group_init(struct ifpga_feature *feature)
{
	struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
	struct eth_group_device *dev;

	dev = (struct eth_group_device *)eth_group_probe(feature->addr);
	if (!dev)
		return -ENODEV;

	fme->eth_dev[dev->group_id] = dev;

	fme->eth_group_region[dev->group_id].addr =
		feature->addr;
	fme->eth_group_region[dev->group_id].phys_addr =
		feature->phys_addr;
	fme->eth_group_region[dev->group_id].len =
		feature->size;

	fme->nums_eth_dev++;

	dev_info(NULL, "FME PHY Group %d Init.\n", dev->group_id);
	dev_info(NULL, "found %d eth group, addr %p phys_addr 0x%llx len %u\n",
			dev->group_id, feature->addr,
			(unsigned long long)feature->phys_addr,
			feature->size);

	return 0;
}

static void fme_eth_group_uinit(struct ifpga_feature *feature)
{
	UNUSED(feature);
}

struct ifpga_feature_ops fme_eth_group_ops = {
	.init = fme_eth_group_init,
	.uinit = fme_eth_group_uinit,
};

int fme_mgr_read_mac_rom(struct ifpga_fme_hw *fme, int offset,
		void *buf, int size)
{
	struct altera_i2c_dev *dev;

	dev = fme->i2c_master;
	if (!dev)
		return -ENODEV;

	return at24_eeprom_read(dev, AT24512_SLAVE_ADDR, offset, buf, size);
}

int fme_mgr_write_mac_rom(struct ifpga_fme_hw *fme, int offset,
		void *buf, int size)
{
	struct altera_i2c_dev *dev;

	dev = fme->i2c_master;
	if (!dev)
		return -ENODEV;

	return at24_eeprom_write(dev, AT24512_SLAVE_ADDR, offset, buf, size);
}

static struct eth_group_device *get_eth_group_dev(struct ifpga_fme_hw *fme,
		u8 group_id)
{
	struct eth_group_device *dev;

	if (group_id > (MAX_ETH_GROUP_DEVICES - 1))
		return NULL;

	dev = (struct eth_group_device *)fme->eth_dev[group_id];
	if (!dev)
		return NULL;

	if (dev->status != ETH_GROUP_DEV_ATTACHED)
		return NULL;

	return dev;
}

int fme_mgr_get_eth_group_nums(struct ifpga_fme_hw *fme)
{
	return fme->nums_eth_dev;
}

int fme_mgr_get_eth_group_info(struct ifpga_fme_hw *fme,
		u8 group_id, struct opae_eth_group_info *info)
{
	struct eth_group_device *dev;

	dev = get_eth_group_dev(fme, group_id);
	if (!dev)
		return -ENODEV;

	info->group_id = group_id;
	info->speed = dev->speed;
	info->nums_of_mac = dev->mac_num;
	info->nums_of_phy = dev->phy_num;

	return 0;
}

int fme_mgr_eth_group_read_reg(struct ifpga_fme_hw *fme, u8 group_id,
		u8 type, u8 index, u16 addr, u32 *data)
{
	struct eth_group_device *dev;

	dev = get_eth_group_dev(fme, group_id);
	if (!dev)
		return -ENODEV;

	return eth_group_read_reg(dev, type, index, addr, data);
}

int fme_mgr_eth_group_write_reg(struct ifpga_fme_hw *fme, u8 group_id,
		u8 type, u8 index, u16 addr, u32 data)
{
	struct eth_group_device *dev;

	dev = get_eth_group_dev(fme, group_id);
	if (!dev)
		return -ENODEV;

	return eth_group_write_reg(dev, type, index, addr, data);
}

static int fme_get_eth_group_speed(struct ifpga_fme_hw *fme,
		u8 group_id)
{
	struct eth_group_device *dev;

	dev = get_eth_group_dev(fme, group_id);
	if (!dev)
		return -ENODEV;

	return dev->speed;
}

int fme_mgr_get_retimer_info(struct ifpga_fme_hw *fme,
		struct opae_retimer_info *info)
{
	struct intel_max10_device *dev;

	dev = (struct intel_max10_device *)fme->max10_dev;
	if (!dev)
		return -ENODEV;

	info->nums_retimer = fme->board_info.nums_of_retimer;
	info->ports_per_retimer = fme->board_info.ports_per_retimer;
	info->nums_fvl = fme->board_info.nums_of_fvl;
	info->ports_per_fvl = fme->board_info.ports_per_fvl;

	/* The speed of PKVL is identical the eth group's speed */
	info->support_speed = fme_get_eth_group_speed(fme,
			LINE_SIDE_GROUP_ID);

	return 0;
}

int fme_mgr_get_retimer_status(struct ifpga_fme_hw *fme,
		struct opae_retimer_status *status)
{
	struct intel_max10_device *dev;
	unsigned int val;

	dev = (struct intel_max10_device *)fme->max10_dev;
	if (!dev)
		return -ENODEV;

	if (max10_sys_read(PKVL_LINK_STATUS, &val)) {
		dev_err(dev, "%s: read pkvl status fail\n", __func__);
		return -EINVAL;
	}

	/* The speed of PKVL is identical the eth group's speed */
	status->speed = fme_get_eth_group_speed(fme,
			LINE_SIDE_GROUP_ID);

	status->line_link_bitmap = val;

	dev_debug(dev, "get retimer status: speed:%d. line_link_bitmap:0x%x\n",
			status->speed,
			status->line_link_bitmap);

	return 0;
}

int fme_mgr_get_sensor_value(struct ifpga_fme_hw *fme,
		struct opae_sensor_info *sensor,
		unsigned int *value)
{
	struct intel_max10_device *dev;

	dev = (struct intel_max10_device *)fme->max10_dev;
	if (!dev)
		return -ENODEV;

	if (max10_sys_read(sensor->value_reg, value)) {
		dev_err(dev, "%s: read sensor value register 0x%x fail\n",
				__func__, sensor->value_reg);
		return -EINVAL;
	}

	*value *= sensor->multiplier;

	return 0;
}