summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/drivers/net/igc/base/igc_i225.c
blob: 060b2f8f939633e34fef59d07a9f1dd670ece5e2 (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
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2001-2020 Intel Corporation
 */

#include "igc_api.h"

static s32 igc_init_nvm_params_i225(struct igc_hw *hw);
static s32 igc_init_mac_params_i225(struct igc_hw *hw);
static s32 igc_init_phy_params_i225(struct igc_hw *hw);
static s32 igc_reset_hw_i225(struct igc_hw *hw);
static s32 igc_acquire_nvm_i225(struct igc_hw *hw);
static void igc_release_nvm_i225(struct igc_hw *hw);
static s32 igc_get_hw_semaphore_i225(struct igc_hw *hw);
static s32 __igc_write_nvm_srwr(struct igc_hw *hw, u16 offset, u16 words,
				  u16 *data);
static s32 igc_pool_flash_update_done_i225(struct igc_hw *hw);
static s32 igc_valid_led_default_i225(struct igc_hw *hw, u16 *data);

/**
 *  igc_init_nvm_params_i225 - Init NVM func ptrs.
 *  @hw: pointer to the HW structure
 **/
static s32 igc_init_nvm_params_i225(struct igc_hw *hw)
{
	struct igc_nvm_info *nvm = &hw->nvm;
	u32 eecd = IGC_READ_REG(hw, IGC_EECD);
	u16 size;

	DEBUGFUNC("igc_init_nvm_params_i225");

	size = (u16)((eecd & IGC_EECD_SIZE_EX_MASK) >>
		     IGC_EECD_SIZE_EX_SHIFT);
	/*
	 * Added to a constant, "size" becomes the left-shift value
	 * for setting word_size.
	 */
	size += NVM_WORD_SIZE_BASE_SHIFT;

	/* Just in case size is out of range, cap it to the largest
	 * EEPROM size supported
	 */
	if (size > 15)
		size = 15;

	nvm->word_size = 1 << size;
	nvm->opcode_bits = 8;
	nvm->delay_usec = 1;
	nvm->type = igc_nvm_eeprom_spi;


	nvm->page_size = eecd & IGC_EECD_ADDR_BITS ? 32 : 8;
	nvm->address_bits = eecd & IGC_EECD_ADDR_BITS ?
			    16 : 8;

	if (nvm->word_size == (1 << 15))
		nvm->page_size = 128;

	nvm->ops.acquire = igc_acquire_nvm_i225;
	nvm->ops.release = igc_release_nvm_i225;
	nvm->ops.valid_led_default = igc_valid_led_default_i225;
	if (igc_get_flash_presence_i225(hw)) {
		hw->nvm.type = igc_nvm_flash_hw;
		nvm->ops.read    = igc_read_nvm_srrd_i225;
		nvm->ops.write   = igc_write_nvm_srwr_i225;
		nvm->ops.validate = igc_validate_nvm_checksum_i225;
		nvm->ops.update   = igc_update_nvm_checksum_i225;
	} else {
		hw->nvm.type = igc_nvm_invm;
		nvm->ops.write    = igc_null_write_nvm;
		nvm->ops.validate = igc_null_ops_generic;
		nvm->ops.update   = igc_null_ops_generic;
	}

	return IGC_SUCCESS;
}

/**
 *  igc_init_mac_params_i225 - Init MAC func ptrs.
 *  @hw: pointer to the HW structure
 **/
static s32 igc_init_mac_params_i225(struct igc_hw *hw)
{
	struct igc_mac_info *mac = &hw->mac;
	struct igc_dev_spec_i225 *dev_spec = &hw->dev_spec._i225;

	DEBUGFUNC("igc_init_mac_params_i225");

	/* Initialize function pointer */
	igc_init_mac_ops_generic(hw);

	/* Set media type */
	hw->phy.media_type = igc_media_type_copper;
	/* Set mta register count */
	mac->mta_reg_count = 128;
	/* Set rar entry count */
	mac->rar_entry_count = IGC_RAR_ENTRIES_BASE;

	/* reset */
	mac->ops.reset_hw = igc_reset_hw_i225;
	/* hw initialization */
	mac->ops.init_hw = igc_init_hw_i225;
	/* link setup */
	mac->ops.setup_link = igc_setup_link_generic;
	/* check for link */
	mac->ops.check_for_link = igc_check_for_link_i225;
	/* link info */
	mac->ops.get_link_up_info = igc_get_speed_and_duplex_copper_generic;
	/* acquire SW_FW sync */
	mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
	/* release SW_FW sync */
	mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;

	/* Allow a single clear of the SW semaphore on I225 */
	dev_spec->clear_semaphore_once = true;
	mac->ops.setup_physical_interface = igc_setup_copper_link_i225;

	/* Set if part includes ASF firmware */
	mac->asf_firmware_present = true;

	/* multicast address update */
	mac->ops.update_mc_addr_list = igc_update_mc_addr_list_generic;

	mac->ops.write_vfta = igc_write_vfta_generic;

	return IGC_SUCCESS;
}

/**
 *  igc_init_phy_params_i225 - Init PHY func ptrs.
 *  @hw: pointer to the HW structure
 **/
static s32 igc_init_phy_params_i225(struct igc_hw *hw)
{
	struct igc_phy_info *phy = &hw->phy;
	s32 ret_val = IGC_SUCCESS;
	u32 ctrl_ext;

	DEBUGFUNC("igc_init_phy_params_i225");

	phy->ops.read_i2c_byte = igc_read_i2c_byte_generic;
	phy->ops.write_i2c_byte = igc_write_i2c_byte_generic;

	if (hw->phy.media_type != igc_media_type_copper) {
		phy->type = igc_phy_none;
		goto out;
	}

	phy->ops.power_up   = igc_power_up_phy_copper;
	phy->ops.power_down = igc_power_down_phy_copper_base;

	phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT_2500;

	phy->reset_delay_us	= 100;

	phy->ops.acquire	= igc_acquire_phy_base;
	phy->ops.check_reset_block = igc_check_reset_block_generic;
	phy->ops.commit		= igc_phy_sw_reset_generic;
	phy->ops.release	= igc_release_phy_base;

	ctrl_ext = IGC_READ_REG(hw, IGC_CTRL_EXT);

	/* Make sure the PHY is in a good state. Several people have reported
	 * firmware leaving the PHY's page select register set to something
	 * other than the default of zero, which causes the PHY ID read to
	 * access something other than the intended register.
	 */
	ret_val = hw->phy.ops.reset(hw);
	if (ret_val)
		goto out;

	IGC_WRITE_REG(hw, IGC_CTRL_EXT, ctrl_ext);
	phy->ops.read_reg = igc_read_phy_reg_gpy;
	phy->ops.write_reg = igc_write_phy_reg_gpy;

	ret_val = igc_get_phy_id(hw);
	/* Verify phy id and set remaining function pointers */
	switch (phy->id) {
	case I225_I_PHY_ID:
		phy->type		= igc_phy_i225;
		phy->ops.set_d0_lplu_state = igc_set_d0_lplu_state_i225;
		phy->ops.set_d3_lplu_state = igc_set_d3_lplu_state_i225;
		/* TODO - complete with GPY PHY information */
		break;
	default:
		ret_val = -IGC_ERR_PHY;
		goto out;
	}

out:
	return ret_val;
}

/**
 *  igc_reset_hw_i225 - Reset hardware
 *  @hw: pointer to the HW structure
 *
 *  This resets the hardware into a known state.
 **/
static s32 igc_reset_hw_i225(struct igc_hw *hw)
{
	u32 ctrl;
	s32 ret_val;

	DEBUGFUNC("igc_reset_hw_i225");

	/*
	 * Prevent the PCI-E bus from sticking if there is no TLP connection
	 * on the last TLP read/write transaction when MAC is reset.
	 */
	ret_val = igc_disable_pcie_master_generic(hw);
	if (ret_val)
		DEBUGOUT("PCI-E Master disable polling has failed.\n");

	DEBUGOUT("Masking off all interrupts\n");
	IGC_WRITE_REG(hw, IGC_IMC, 0xffffffff);

	IGC_WRITE_REG(hw, IGC_RCTL, 0);
	IGC_WRITE_REG(hw, IGC_TCTL, IGC_TCTL_PSP);
	IGC_WRITE_FLUSH(hw);

	msec_delay(10);

	ctrl = IGC_READ_REG(hw, IGC_CTRL);

	DEBUGOUT("Issuing a global reset to MAC\n");
	IGC_WRITE_REG(hw, IGC_CTRL, ctrl | IGC_CTRL_RST);

	ret_val = igc_get_auto_rd_done_generic(hw);
	if (ret_val) {
		/*
		 * When auto config read does not complete, do not
		 * return with an error. This can happen in situations
		 * where there is no eeprom and prevents getting link.
		 */
		DEBUGOUT("Auto Read Done did not complete\n");
	}

	/* Clear any pending interrupt events. */
	IGC_WRITE_REG(hw, IGC_IMC, 0xffffffff);
	IGC_READ_REG(hw, IGC_ICR);

	/* Install any alternate MAC address into RAR0 */
	ret_val = igc_check_alt_mac_addr_generic(hw);

	return ret_val;
}

/* igc_acquire_nvm_i225 - Request for access to EEPROM
 * @hw: pointer to the HW structure
 *
 * Acquire the necessary semaphores for exclusive access to the EEPROM.
 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
 * Return successful if access grant bit set, else clear the request for
 * EEPROM access and return -IGC_ERR_NVM (-1).
 */
static s32 igc_acquire_nvm_i225(struct igc_hw *hw)
{
	s32 ret_val;

	DEBUGFUNC("igc_acquire_nvm_i225");

	ret_val = igc_acquire_swfw_sync_i225(hw, IGC_SWFW_EEP_SM);

	return ret_val;
}

/* igc_release_nvm_i225 - Release exclusive access to EEPROM
 * @hw: pointer to the HW structure
 *
 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
 * then release the semaphores acquired.
 */
static void igc_release_nvm_i225(struct igc_hw *hw)
{
	DEBUGFUNC("igc_release_nvm_i225");

	igc_release_swfw_sync_i225(hw, IGC_SWFW_EEP_SM);
}

/* igc_acquire_swfw_sync_i225 - Acquire SW/FW semaphore
 * @hw: pointer to the HW structure
 * @mask: specifies which semaphore to acquire
 *
 * Acquire the SW/FW semaphore to access the PHY or NVM.  The mask
 * will also specify which port we're acquiring the lock for.
 */
s32 igc_acquire_swfw_sync_i225(struct igc_hw *hw, u16 mask)
{
	u32 swfw_sync;
	u32 swmask = mask;
	u32 fwmask = mask << 16;
	s32 ret_val = IGC_SUCCESS;
	s32 i = 0, timeout = 200; /* FIXME: find real value to use here */

	DEBUGFUNC("igc_acquire_swfw_sync_i225");

	while (i < timeout) {
		if (igc_get_hw_semaphore_i225(hw)) {
			ret_val = -IGC_ERR_SWFW_SYNC;
			goto out;
		}

		swfw_sync = IGC_READ_REG(hw, IGC_SW_FW_SYNC);
		if (!(swfw_sync & (fwmask | swmask)))
			break;

		/* Firmware currently using resource (fwmask)
		 * or other software thread using resource (swmask)
		 */
		igc_put_hw_semaphore_generic(hw);
		msec_delay_irq(5);
		i++;
	}

	if (i == timeout) {
		DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
		ret_val = -IGC_ERR_SWFW_SYNC;
		goto out;
	}

	swfw_sync |= swmask;
	IGC_WRITE_REG(hw, IGC_SW_FW_SYNC, swfw_sync);

	igc_put_hw_semaphore_generic(hw);

out:
	return ret_val;
}

/* igc_release_swfw_sync_i225 - Release SW/FW semaphore
 * @hw: pointer to the HW structure
 * @mask: specifies which semaphore to acquire
 *
 * Release the SW/FW semaphore used to access the PHY or NVM.  The mask
 * will also specify which port we're releasing the lock for.
 */
void igc_release_swfw_sync_i225(struct igc_hw *hw, u16 mask)
{
	u32 swfw_sync;

	DEBUGFUNC("igc_release_swfw_sync_i225");

	while (igc_get_hw_semaphore_i225(hw) != IGC_SUCCESS)
		; /* Empty */

	swfw_sync = IGC_READ_REG(hw, IGC_SW_FW_SYNC);
	swfw_sync &= ~mask;
	IGC_WRITE_REG(hw, IGC_SW_FW_SYNC, swfw_sync);

	igc_put_hw_semaphore_generic(hw);
}

/*
 * igc_setup_copper_link_i225 - Configure copper link settings
 * @hw: pointer to the HW structure
 *
 * Configures the link for auto-neg or forced speed and duplex.  Then we check
 * for link, once link is established calls to configure collision distance
 * and flow control are called.
 */
s32 igc_setup_copper_link_i225(struct igc_hw *hw)
{
	u32 phpm_reg;
	s32 ret_val;
	u32 ctrl;

	DEBUGFUNC("igc_setup_copper_link_i225");

	ctrl = IGC_READ_REG(hw, IGC_CTRL);
	ctrl |= IGC_CTRL_SLU;
	ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
	IGC_WRITE_REG(hw, IGC_CTRL, ctrl);

	phpm_reg = IGC_READ_REG(hw, IGC_I225_PHPM);
	phpm_reg &= ~IGC_I225_PHPM_GO_LINKD;
	IGC_WRITE_REG(hw, IGC_I225_PHPM, phpm_reg);

	ret_val = igc_setup_copper_link_generic(hw);

	return ret_val;
}

/* igc_get_hw_semaphore_i225 - Acquire hardware semaphore
 * @hw: pointer to the HW structure
 *
 * Acquire the HW semaphore to access the PHY or NVM
 */
static s32 igc_get_hw_semaphore_i225(struct igc_hw *hw)
{
	u32 swsm;
	s32 timeout = hw->nvm.word_size + 1;
	s32 i = 0;

	DEBUGFUNC("igc_get_hw_semaphore_i225");

	/* Get the SW semaphore */
	while (i < timeout) {
		swsm = IGC_READ_REG(hw, IGC_SWSM);
		if (!(swsm & IGC_SWSM_SMBI))
			break;

		usec_delay(50);
		i++;
	}

	if (i == timeout) {
		/* In rare circumstances, the SW semaphore may already be held
		 * unintentionally. Clear the semaphore once before giving up.
		 */
		if (hw->dev_spec._i225.clear_semaphore_once) {
			hw->dev_spec._i225.clear_semaphore_once = false;
			igc_put_hw_semaphore_generic(hw);
			for (i = 0; i < timeout; i++) {
				swsm = IGC_READ_REG(hw, IGC_SWSM);
				if (!(swsm & IGC_SWSM_SMBI))
					break;

				usec_delay(50);
			}
		}

		/* If we do not have the semaphore here, we have to give up. */
		if (i == timeout) {
			DEBUGOUT("Driver can't access device -\n");
			DEBUGOUT("SMBI bit is set.\n");
			return -IGC_ERR_NVM;
		}
	}

	/* Get the FW semaphore. */
	for (i = 0; i < timeout; i++) {
		swsm = IGC_READ_REG(hw, IGC_SWSM);
		IGC_WRITE_REG(hw, IGC_SWSM, swsm | IGC_SWSM_SWESMBI);

		/* Semaphore acquired if bit latched */
		if (IGC_READ_REG(hw, IGC_SWSM) & IGC_SWSM_SWESMBI)
			break;

		usec_delay(50);
	}

	if (i == timeout) {
		/* Release semaphores */
		igc_put_hw_semaphore_generic(hw);
		DEBUGOUT("Driver can't access the NVM\n");
		return -IGC_ERR_NVM;
	}

	return IGC_SUCCESS;
}

/* igc_read_nvm_srrd_i225 - Reads Shadow Ram using EERD register
 * @hw: pointer to the HW structure
 * @offset: offset of word in the Shadow Ram to read
 * @words: number of words to read
 * @data: word read from the Shadow Ram
 *
 * Reads a 16 bit word from the Shadow Ram using the EERD register.
 * Uses necessary synchronization semaphores.
 */
s32 igc_read_nvm_srrd_i225(struct igc_hw *hw, u16 offset, u16 words,
			     u16 *data)
{
	s32 status = IGC_SUCCESS;
	u16 i, count;

	DEBUGFUNC("igc_read_nvm_srrd_i225");

	/* We cannot hold synchronization semaphores for too long,
	 * because of forceful takeover procedure. However it is more efficient
	 * to read in bursts than synchronizing access for each word.
	 */
	for (i = 0; i < words; i += IGC_EERD_EEWR_MAX_COUNT) {
		count = (words - i) / IGC_EERD_EEWR_MAX_COUNT > 0 ?
			IGC_EERD_EEWR_MAX_COUNT : (words - i);
		if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
			status = igc_read_nvm_eerd(hw, offset, count,
						     data + i);
			hw->nvm.ops.release(hw);
		} else {
			status = IGC_ERR_SWFW_SYNC;
		}

		if (status != IGC_SUCCESS)
			break;
	}

	return status;
}

/* igc_write_nvm_srwr_i225 - Write to Shadow RAM using EEWR
 * @hw: pointer to the HW structure
 * @offset: offset within the Shadow RAM to be written to
 * @words: number of words to write
 * @data: 16 bit word(s) to be written to the Shadow RAM
 *
 * Writes data to Shadow RAM at offset using EEWR register.
 *
 * If igc_update_nvm_checksum is not called after this function , the
 * data will not be committed to FLASH and also Shadow RAM will most likely
 * contain an invalid checksum.
 *
 * If error code is returned, data and Shadow RAM may be inconsistent - buffer
 * partially written.
 */
s32 igc_write_nvm_srwr_i225(struct igc_hw *hw, u16 offset, u16 words,
			      u16 *data)
{
	s32 status = IGC_SUCCESS;
	u16 i, count;

	DEBUGFUNC("igc_write_nvm_srwr_i225");

	/* We cannot hold synchronization semaphores for too long,
	 * because of forceful takeover procedure. However it is more efficient
	 * to write in bursts than synchronizing access for each word.
	 */
	for (i = 0; i < words; i += IGC_EERD_EEWR_MAX_COUNT) {
		count = (words - i) / IGC_EERD_EEWR_MAX_COUNT > 0 ?
			IGC_EERD_EEWR_MAX_COUNT : (words - i);
		if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
			status = __igc_write_nvm_srwr(hw, offset, count,
							data + i);
			hw->nvm.ops.release(hw);
		} else {
			status = IGC_ERR_SWFW_SYNC;
		}

		if (status != IGC_SUCCESS)
			break;
	}

	return status;
}

/* __igc_write_nvm_srwr - Write to Shadow Ram using EEWR
 * @hw: pointer to the HW structure
 * @offset: offset within the Shadow Ram to be written to
 * @words: number of words to write
 * @data: 16 bit word(s) to be written to the Shadow Ram
 *
 * Writes data to Shadow Ram at offset using EEWR register.
 *
 * If igc_update_nvm_checksum is not called after this function , the
 * Shadow Ram will most likely contain an invalid checksum.
 */
static s32 __igc_write_nvm_srwr(struct igc_hw *hw, u16 offset, u16 words,
				  u16 *data)
{
	struct igc_nvm_info *nvm = &hw->nvm;
	u32 i, k, eewr = 0;
	u32 attempts = 100000;
	s32 ret_val = IGC_SUCCESS;

	DEBUGFUNC("__igc_write_nvm_srwr");

	/* A check for invalid values:  offset too large, too many words,
	 * too many words for the offset, and not enough words.
	 */
	if (offset >= nvm->word_size || words > (nvm->word_size - offset) ||
			words == 0) {
		DEBUGOUT("nvm parameter(s) out of bounds\n");
		ret_val = -IGC_ERR_NVM;
		goto out;
	}

	for (i = 0; i < words; i++) {
		eewr = ((offset + i) << IGC_NVM_RW_ADDR_SHIFT) |
			(data[i] << IGC_NVM_RW_REG_DATA) |
			IGC_NVM_RW_REG_START;

		IGC_WRITE_REG(hw, IGC_SRWR, eewr);

		for (k = 0; k < attempts; k++) {
			if (IGC_NVM_RW_REG_DONE &
			    IGC_READ_REG(hw, IGC_SRWR)) {
				ret_val = IGC_SUCCESS;
				break;
			}
			usec_delay(5);
		}

		if (ret_val != IGC_SUCCESS) {
			DEBUGOUT("Shadow RAM write EEWR timed out\n");
			break;
		}
	}

out:
	return ret_val;
}

/* igc_read_invm_version_i225 - Reads iNVM version and image type
 * @hw: pointer to the HW structure
 * @invm_ver: version structure for the version read
 *
 * Reads iNVM version and image type.
 */
s32 igc_read_invm_version_i225(struct igc_hw *hw,
				 struct igc_fw_version *invm_ver)
{
	u32 *record = NULL;
	u32 *next_record = NULL;
	u32 i = 0;
	u32 invm_dword = 0;
	u32 invm_blocks = IGC_INVM_SIZE - (IGC_INVM_ULT_BYTES_SIZE /
					     IGC_INVM_RECORD_SIZE_IN_BYTES);
	u32 buffer[IGC_INVM_SIZE];
	s32 status = -IGC_ERR_INVM_VALUE_NOT_FOUND;
	u16 version = 0;

	DEBUGFUNC("igc_read_invm_version_i225");

	/* Read iNVM memory */
	for (i = 0; i < IGC_INVM_SIZE; i++) {
		invm_dword = IGC_READ_REG(hw, IGC_INVM_DATA_REG(i));
		buffer[i] = invm_dword;
	}

	/* Read version number */
	for (i = 1; i < invm_blocks; i++) {
		record = &buffer[invm_blocks - i];
		next_record = &buffer[invm_blocks - i + 1];

		/* Check if we have first version location used */
		if (i == 1 && (*record & IGC_INVM_VER_FIELD_ONE) == 0) {
			version = 0;
			status = IGC_SUCCESS;
			break;
		}
		/* Check if we have second version location used */
		else if ((i == 1) &&
			 ((*record & IGC_INVM_VER_FIELD_TWO) == 0)) {
			version = (*record & IGC_INVM_VER_FIELD_ONE) >> 3;
			status = IGC_SUCCESS;
			break;
		}
		/* Check if we have odd version location
		 * used and it is the last one used
		 */
		else if ((((*record & IGC_INVM_VER_FIELD_ONE) == 0) &&
			  ((*record & 0x3) == 0)) || (((*record & 0x3) != 0) &&
			   (i != 1))) {
			version = (*next_record & IGC_INVM_VER_FIELD_TWO)
				  >> 13;
			status = IGC_SUCCESS;
			break;
		}
		/* Check if we have even version location
		 * used and it is the last one used
		 */
		else if (((*record & IGC_INVM_VER_FIELD_TWO) == 0) &&
			 ((*record & 0x3) == 0)) {
			version = (*record & IGC_INVM_VER_FIELD_ONE) >> 3;
			status = IGC_SUCCESS;
			break;
		}
	}

	if (status == IGC_SUCCESS) {
		invm_ver->invm_major = (version & IGC_INVM_MAJOR_MASK)
					>> IGC_INVM_MAJOR_SHIFT;
		invm_ver->invm_minor = version & IGC_INVM_MINOR_MASK;
	}
	/* Read Image Type */
	for (i = 1; i < invm_blocks; i++) {
		record = &buffer[invm_blocks - i];
		next_record = &buffer[invm_blocks - i + 1];

		/* Check if we have image type in first location used */
		if (i == 1 && (*record & IGC_INVM_IMGTYPE_FIELD) == 0) {
			invm_ver->invm_img_type = 0;
			status = IGC_SUCCESS;
			break;
		}
		/* Check if we have image type in first location used */
		else if ((((*record & 0x3) == 0) &&
			  ((*record & IGC_INVM_IMGTYPE_FIELD) == 0)) ||
			    ((((*record & 0x3) != 0) && (i != 1)))) {
			invm_ver->invm_img_type =
				(*next_record & IGC_INVM_IMGTYPE_FIELD) >> 23;
			status = IGC_SUCCESS;
			break;
		}
	}
	return status;
}

/* igc_validate_nvm_checksum_i225 - Validate EEPROM checksum
 * @hw: pointer to the HW structure
 *
 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
 */
s32 igc_validate_nvm_checksum_i225(struct igc_hw *hw)
{
	s32 status = IGC_SUCCESS;
	s32 (*read_op_ptr)(struct igc_hw *hw, u16 offset,
			u16 count, u16 *data);

	DEBUGFUNC("igc_validate_nvm_checksum_i225");

	if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
		/* Replace the read function with semaphore grabbing with
		 * the one that skips this for a while.
		 * We have semaphore taken already here.
		 */
		read_op_ptr = hw->nvm.ops.read;
		hw->nvm.ops.read = igc_read_nvm_eerd;

		status = igc_validate_nvm_checksum_generic(hw);

		/* Revert original read operation. */
		hw->nvm.ops.read = read_op_ptr;

		hw->nvm.ops.release(hw);
	} else {
		status = IGC_ERR_SWFW_SYNC;
	}

	return status;
}

/* igc_update_nvm_checksum_i225 - Update EEPROM checksum
 * @hw: pointer to the HW structure
 *
 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
 * up to the checksum.  Then calculates the EEPROM checksum and writes the
 * value to the EEPROM. Next commit EEPROM data onto the Flash.
 */
s32 igc_update_nvm_checksum_i225(struct igc_hw *hw)
{
	s32 ret_val;
	u16 checksum = 0;
	u16 i, nvm_data;

	DEBUGFUNC("igc_update_nvm_checksum_i225");

	/* Read the first word from the EEPROM. If this times out or fails, do
	 * not continue or we could be in for a very long wait while every
	 * EEPROM read fails
	 */
	ret_val = igc_read_nvm_eerd(hw, 0, 1, &nvm_data);
	if (ret_val != IGC_SUCCESS) {
		DEBUGOUT("EEPROM read failed\n");
		goto out;
	}

	if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
		/* Do not use hw->nvm.ops.write, hw->nvm.ops.read
		 * because we do not want to take the synchronization
		 * semaphores twice here.
		 */

		for (i = 0; i < NVM_CHECKSUM_REG; i++) {
			ret_val = igc_read_nvm_eerd(hw, i, 1, &nvm_data);
			if (ret_val) {
				hw->nvm.ops.release(hw);
				DEBUGOUT("NVM Read Error while updating\n");
				DEBUGOUT("checksum.\n");
				goto out;
			}
			checksum += nvm_data;
		}
		checksum = (u16)NVM_SUM - checksum;
		ret_val = __igc_write_nvm_srwr(hw, NVM_CHECKSUM_REG, 1,
						 &checksum);
		if (ret_val != IGC_SUCCESS) {
			hw->nvm.ops.release(hw);
			DEBUGOUT("NVM Write Error while updating checksum.\n");
			goto out;
		}

		hw->nvm.ops.release(hw);

		ret_val = igc_update_flash_i225(hw);
	} else {
		ret_val = IGC_ERR_SWFW_SYNC;
	}
out:
	return ret_val;
}

/* igc_get_flash_presence_i225 - Check if flash device is detected.
 * @hw: pointer to the HW structure
 */
bool igc_get_flash_presence_i225(struct igc_hw *hw)
{
	u32 eec = 0;
	bool ret_val = false;

	DEBUGFUNC("igc_get_flash_presence_i225");

	eec = IGC_READ_REG(hw, IGC_EECD);

	if (eec & IGC_EECD_FLASH_DETECTED_I225)
		ret_val = true;

	return ret_val;
}

/* igc_set_flsw_flash_burst_counter_i225 - sets FLSW NVM Burst
 * Counter in FLSWCNT register.
 *
 * @hw: pointer to the HW structure
 * @burst_counter: size in bytes of the Flash burst to read or write
 */
s32 igc_set_flsw_flash_burst_counter_i225(struct igc_hw *hw,
					    u32 burst_counter)
{
	s32 ret_val = IGC_SUCCESS;

	DEBUGFUNC("igc_set_flsw_flash_burst_counter_i225");

	/* Validate input data */
	if (burst_counter < IGC_I225_SHADOW_RAM_SIZE) {
		/* Write FLSWCNT - burst counter */
		IGC_WRITE_REG(hw, IGC_I225_FLSWCNT, burst_counter);
	} else {
		ret_val = IGC_ERR_INVALID_ARGUMENT;
	}

	return ret_val;
}

/* igc_write_erase_flash_command_i225 - write/erase to a sector
 * region on a given address.
 *
 * @hw: pointer to the HW structure
 * @opcode: opcode to be used for the write command
 * @address: the offset to write into the FLASH image
 */
s32 igc_write_erase_flash_command_i225(struct igc_hw *hw, u32 opcode,
					 u32 address)
{
	u32 flswctl = 0;
	s32 timeout = IGC_NVM_GRANT_ATTEMPTS;
	s32 ret_val = IGC_SUCCESS;

	DEBUGFUNC("igc_write_erase_flash_command_i225");

	flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
	/* Polling done bit on FLSWCTL register */
	while (timeout) {
		if (flswctl & IGC_FLSWCTL_DONE)
			break;
		usec_delay(5);
		flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
		timeout--;
	}

	if (!timeout) {
		DEBUGOUT("Flash transaction was not done\n");
		return -IGC_ERR_NVM;
	}

	/* Build and issue command on FLSWCTL register */
	flswctl = address | opcode;
	IGC_WRITE_REG(hw, IGC_I225_FLSWCTL, flswctl);

	/* Check if issued command is valid on FLSWCTL register */
	flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
	if (!(flswctl & IGC_FLSWCTL_CMDV)) {
		DEBUGOUT("Write flash command failed\n");
		ret_val = IGC_ERR_INVALID_ARGUMENT;
	}

	return ret_val;
}

/* igc_update_flash_i225 - Commit EEPROM to the flash
 * if fw_valid_bit is set, FW is active. setting FLUPD bit in EEC
 * register makes the FW load the internal shadow RAM into the flash.
 * Otherwise, fw_valid_bit is 0. if FL_SECU.block_prtotected_sw = 0
 * then FW is not active so the SW is responsible shadow RAM dump.
 *
 * @hw: pointer to the HW structure
 */
s32 igc_update_flash_i225(struct igc_hw *hw)
{
	u16 current_offset_data = 0;
	u32 block_sw_protect = 1;
	u16 base_address = 0x0;
	u32 i, fw_valid_bit;
	u16 current_offset;
	s32 ret_val = 0;
	u32 flup;

	DEBUGFUNC("igc_update_flash_i225");

	block_sw_protect = IGC_READ_REG(hw, IGC_I225_FLSECU) &
					  IGC_FLSECU_BLK_SW_ACCESS_I225;
	fw_valid_bit = IGC_READ_REG(hw, IGC_FWSM) &
				      IGC_FWSM_FW_VALID_I225;
	if (fw_valid_bit) {
		ret_val = igc_pool_flash_update_done_i225(hw);
		if (ret_val == -IGC_ERR_NVM) {
			DEBUGOUT("Flash update time out\n");
			goto out;
		}

		flup = IGC_READ_REG(hw, IGC_EECD) | IGC_EECD_FLUPD_I225;
		IGC_WRITE_REG(hw, IGC_EECD, flup);

		ret_val = igc_pool_flash_update_done_i225(hw);
		if (ret_val == IGC_SUCCESS)
			DEBUGOUT("Flash update complete\n");
		else
			DEBUGOUT("Flash update time out\n");
	} else if (!block_sw_protect) {
		/* FW is not active and security protection is disabled.
		 * therefore, SW is in charge of shadow RAM dump.
		 * Check which sector is valid. if sector 0 is valid,
		 * base address remains 0x0. otherwise, sector 1 is
		 * valid and it's base address is 0x1000
		 */
		if (IGC_READ_REG(hw, IGC_EECD) & IGC_EECD_SEC1VAL_I225)
			base_address = 0x1000;

		/* Valid sector erase */
		ret_val = igc_write_erase_flash_command_i225(hw,
						  IGC_I225_ERASE_CMD_OPCODE,
						  base_address);
		if (!ret_val) {
			DEBUGOUT("Sector erase failed\n");
			goto out;
		}

		current_offset = base_address;

		/* Write */
		for (i = 0; i < IGC_I225_SHADOW_RAM_SIZE / 2; i++) {
			/* Set burst write length */
			ret_val = igc_set_flsw_flash_burst_counter_i225(hw,
									  0x2);
			if (ret_val != IGC_SUCCESS)
				break;

			/* Set address and opcode */
			ret_val = igc_write_erase_flash_command_i225(hw,
						IGC_I225_WRITE_CMD_OPCODE,
						2 * current_offset);
			if (ret_val != IGC_SUCCESS)
				break;

			ret_val = igc_read_nvm_eerd(hw, current_offset,
						      1, &current_offset_data);
			if (ret_val) {
				DEBUGOUT("Failed to read from EEPROM\n");
				goto out;
			}

			/* Write CurrentOffseData to FLSWDATA register */
			IGC_WRITE_REG(hw, IGC_I225_FLSWDATA,
					current_offset_data);
			current_offset++;

			/* Wait till operation has finished */
			ret_val = igc_poll_eerd_eewr_done(hw,
						IGC_NVM_POLL_READ);
			if (ret_val)
				break;

			usec_delay(1000);
		}
	}
out:
	return ret_val;
}

/* igc_pool_flash_update_done_i225 - Pool FLUDONE status.
 * @hw: pointer to the HW structure
 */
s32 igc_pool_flash_update_done_i225(struct igc_hw *hw)
{
	s32 ret_val = -IGC_ERR_NVM;
	u32 i, reg;

	DEBUGFUNC("igc_pool_flash_update_done_i225");

	for (i = 0; i < IGC_FLUDONE_ATTEMPTS; i++) {
		reg = IGC_READ_REG(hw, IGC_EECD);
		if (reg & IGC_EECD_FLUDONE_I225) {
			ret_val = IGC_SUCCESS;
			break;
		}
		usec_delay(5);
	}

	return ret_val;
}

/* igc_set_ltr_i225 - Set Latency Tolerance Reporting thresholds.
 * @hw: pointer to the HW structure
 * @link: bool indicating link status
 *
 * Set the LTR thresholds based on the link speed (Mbps), EEE, and DMAC
 * settings, otherwise specify that there is no LTR requirement.
 */
static s32 igc_set_ltr_i225(struct igc_hw *hw, bool link)
{
	u16 speed, duplex;
	u32 tw_system, ltrc, ltrv, ltr_min, ltr_max, scale_min, scale_max;
	s32 size;

	DEBUGFUNC("igc_set_ltr_i225");

	/* If we do not have link, LTR thresholds are zero. */
	if (link) {
		hw->mac.ops.get_link_up_info(hw, &speed, &duplex);

		/* Check if using copper interface with EEE enabled or if the
		 * link speed is 10 Mbps.
		 */
		if (hw->phy.media_type == igc_media_type_copper &&
				!hw->dev_spec._i225.eee_disable &&
				speed != SPEED_10) {
			/* EEE enabled, so send LTRMAX threshold. */
			ltrc = IGC_READ_REG(hw, IGC_LTRC) |
				IGC_LTRC_EEEMS_EN;
			IGC_WRITE_REG(hw, IGC_LTRC, ltrc);

			/* Calculate tw_system (nsec). */
			if (speed == SPEED_100)
				tw_system = ((IGC_READ_REG(hw, IGC_EEE_SU) &
					IGC_TW_SYSTEM_100_MASK) >>
					IGC_TW_SYSTEM_100_SHIFT) * 500;
			else
				tw_system = (IGC_READ_REG(hw, IGC_EEE_SU) &
					IGC_TW_SYSTEM_1000_MASK) * 500;
		} else {
			tw_system = 0;
		}

		/* Get the Rx packet buffer size. */
		size = IGC_READ_REG(hw, IGC_RXPBS) &
			IGC_RXPBS_SIZE_I225_MASK;

		/* Calculations vary based on DMAC settings. */
		if (IGC_READ_REG(hw, IGC_DMACR) & IGC_DMACR_DMAC_EN) {
			size -= (IGC_READ_REG(hw, IGC_DMACR) &
				 IGC_DMACR_DMACTHR_MASK) >>
				 IGC_DMACR_DMACTHR_SHIFT;
			/* Convert size to bits. */
			size *= 1024 * 8;
		} else {
			/* Convert size to bytes, subtract the MTU, and then
			 * convert the size to bits.
			 */
			size *= 1024;
			size -= hw->dev_spec._i225.mtu;
			size *= 8;
		}

		if (size < 0) {
			DEBUGOUT1("Invalid effective Rx buffer size %d\n",
				  size);
			return -IGC_ERR_CONFIG;
		}

		/* Calculate the thresholds. Since speed is in Mbps, simplify
		 * the calculation by multiplying size/speed by 1000 for result
		 * to be in nsec before dividing by the scale in nsec. Set the
		 * scale such that the LTR threshold fits in the register.
		 */
		ltr_min = (1000 * size) / speed;
		ltr_max = ltr_min + tw_system;
		scale_min = (ltr_min / 1024) < 1024 ? IGC_LTRMINV_SCALE_1024 :
			    IGC_LTRMINV_SCALE_32768;
		scale_max = (ltr_max / 1024) < 1024 ? IGC_LTRMAXV_SCALE_1024 :
			    IGC_LTRMAXV_SCALE_32768;
		ltr_min /= scale_min == IGC_LTRMINV_SCALE_1024 ? 1024 : 32768;
		ltr_max /= scale_max == IGC_LTRMAXV_SCALE_1024 ? 1024 : 32768;

		/* Only write the LTR thresholds if they differ from before. */
		ltrv = IGC_READ_REG(hw, IGC_LTRMINV);
		if (ltr_min != (ltrv & IGC_LTRMINV_LTRV_MASK)) {
			ltrv = IGC_LTRMINV_LSNP_REQ | ltr_min |
			      (scale_min << IGC_LTRMINV_SCALE_SHIFT);
			IGC_WRITE_REG(hw, IGC_LTRMINV, ltrv);
		}

		ltrv = IGC_READ_REG(hw, IGC_LTRMAXV);
		if (ltr_max != (ltrv & IGC_LTRMAXV_LTRV_MASK)) {
			ltrv = IGC_LTRMAXV_LSNP_REQ | ltr_max |
			      (scale_min << IGC_LTRMAXV_SCALE_SHIFT);
			IGC_WRITE_REG(hw, IGC_LTRMAXV, ltrv);
		}
	}

	return IGC_SUCCESS;
}

/* igc_check_for_link_i225 - Check for link
 * @hw: pointer to the HW structure
 *
 * Checks to see of the link status of the hardware has changed.  If a
 * change in link status has been detected, then we read the PHY registers
 * to get the current speed/duplex if link exists.
 */
s32 igc_check_for_link_i225(struct igc_hw *hw)
{
	struct igc_mac_info *mac = &hw->mac;
	s32 ret_val;
	bool link = false;

	DEBUGFUNC("igc_check_for_link_i225");

	/* We only want to go out to the PHY registers to see if
	 * Auto-Neg has completed and/or if our link status has
	 * changed.  The get_link_status flag is set upon receiving
	 * a Link Status Change or Rx Sequence Error interrupt.
	 */
	if (!mac->get_link_status) {
		ret_val = IGC_SUCCESS;
		goto out;
	}

	/* First we want to see if the MII Status Register reports
	 * link.  If so, then we want to get the current speed/duplex
	 * of the PHY.
	 */
	ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
	if (ret_val)
		goto out;

	if (!link)
		goto out; /* No link detected */

	mac->get_link_status = false;

	/* Check if there was DownShift, must be checked
	 * immediately after link-up
	 */
	igc_check_downshift_generic(hw);

	/* If we are forcing speed/duplex, then we simply return since
	 * we have already determined whether we have link or not.
	 */
	if (!mac->autoneg)
		goto out;

	/* Auto-Neg is enabled.  Auto Speed Detection takes care
	 * of MAC speed/duplex configuration.  So we only need to
	 * configure Collision Distance in the MAC.
	 */
	mac->ops.config_collision_dist(hw);

	/* Configure Flow Control now that Auto-Neg has completed.
	 * First, we need to restore the desired flow control
	 * settings because we may have had to re-autoneg with a
	 * different link partner.
	 */
	ret_val = igc_config_fc_after_link_up_generic(hw);
	if (ret_val)
		DEBUGOUT("Error configuring flow control\n");
out:
	/* Now that we are aware of our link settings, we can set the LTR
	 * thresholds.
	 */
	ret_val = igc_set_ltr_i225(hw, link);

	return ret_val;
}

/* igc_init_function_pointers_i225 - Init func ptrs.
 * @hw: pointer to the HW structure
 *
 * Called to initialize all function pointers and parameters.
 */
void igc_init_function_pointers_i225(struct igc_hw *hw)
{
	igc_init_mac_ops_generic(hw);
	igc_init_phy_ops_generic(hw);
	igc_init_nvm_ops_generic(hw);
	hw->mac.ops.init_params = igc_init_mac_params_i225;
	hw->nvm.ops.init_params = igc_init_nvm_params_i225;
	hw->phy.ops.init_params = igc_init_phy_params_i225;
}

/* igc_valid_led_default_i225 - Verify a valid default LED config
 * @hw: pointer to the HW structure
 * @data: pointer to the NVM (EEPROM)
 *
 * Read the EEPROM for the current default LED configuration.  If the
 * LED configuration is not valid, set to a valid LED configuration.
 */
static s32 igc_valid_led_default_i225(struct igc_hw *hw, u16 *data)
{
	s32 ret_val;

	DEBUGFUNC("igc_valid_led_default_i225");

	ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
	if (ret_val) {
		DEBUGOUT("NVM Read Error\n");
		goto out;
	}

	if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
		switch (hw->phy.media_type) {
		case igc_media_type_internal_serdes:
			*data = ID_LED_DEFAULT_I225_SERDES;
			break;
		case igc_media_type_copper:
		default:
			*data = ID_LED_DEFAULT_I225;
			break;
		}
	}
out:
	return ret_val;
}

/* igc_get_cfg_done_i225 - Read config done bit
 * @hw: pointer to the HW structure
 *
 * Read the management control register for the config done bit for
 * completion status.  NOTE: silicon which is EEPROM-less will fail trying
 * to read the config done bit, so an error is *ONLY* logged and returns
 * IGC_SUCCESS.  If we were to return with error, EEPROM-less silicon
 * would not be able to be reset or change link.
 */
static s32 igc_get_cfg_done_i225(struct igc_hw *hw)
{
	s32 timeout = PHY_CFG_TIMEOUT;
	u32 mask = IGC_NVM_CFG_DONE_PORT_0;

	DEBUGFUNC("igc_get_cfg_done_i225");

	while (timeout) {
		if (IGC_READ_REG(hw, IGC_EEMNGCTL_I225) & mask)
			break;
		msec_delay(1);
		timeout--;
	}
	if (!timeout)
		DEBUGOUT("MNG configuration cycle has not completed.\n");

	return IGC_SUCCESS;
}

/* igc_init_hw_i225 - Init hw for I225
 * @hw: pointer to the HW structure
 *
 * Called to initialize hw for i225 hw family.
 */
s32 igc_init_hw_i225(struct igc_hw *hw)
{
	s32 ret_val;

	DEBUGFUNC("igc_init_hw_i225");

	hw->phy.ops.get_cfg_done = igc_get_cfg_done_i225;
	ret_val = igc_init_hw_base(hw);
	return ret_val;
}

/*
 * igc_set_d0_lplu_state_i225 - Set Low-Power-Link-Up (LPLU) D0 state
 * @hw: pointer to the HW structure
 * @active: true to enable LPLU, false to disable
 *
 * Note: since I225 does not actually support LPLU, this function
 * simply enables/disables 1G and 2.5G speeds in D0.
 */
s32 igc_set_d0_lplu_state_i225(struct igc_hw *hw, bool active)
{
	u32 data;

	DEBUGFUNC("igc_set_d0_lplu_state_i225");

	data = IGC_READ_REG(hw, IGC_I225_PHPM);

	if (active) {
		data |= IGC_I225_PHPM_DIS_1000;
		data |= IGC_I225_PHPM_DIS_2500;
	} else {
		data &= ~IGC_I225_PHPM_DIS_1000;
		data &= ~IGC_I225_PHPM_DIS_2500;
	}

	IGC_WRITE_REG(hw, IGC_I225_PHPM, data);
	return IGC_SUCCESS;
}

/*
 * igc_set_d3_lplu_state_i225 - Set Low-Power-Link-Up (LPLU) D3 state
 * @hw: pointer to the HW structure
 * @active: true to enable LPLU, false to disable
 *
 * Note: since I225 does not actually support LPLU, this function
 * simply enables/disables 100M, 1G and 2.5G speeds in D3.
 */
s32 igc_set_d3_lplu_state_i225(struct igc_hw *hw, bool active)
{
	u32 data;

	DEBUGFUNC("igc_set_d3_lplu_state_i225");

	data = IGC_READ_REG(hw, IGC_I225_PHPM);

	if (active) {
		data |= IGC_I225_PHPM_DIS_100_D3;
		data |= IGC_I225_PHPM_DIS_1000_D3;
		data |= IGC_I225_PHPM_DIS_2500_D3;
	} else {
		data &= ~IGC_I225_PHPM_DIS_100_D3;
		data &= ~IGC_I225_PHPM_DIS_1000_D3;
		data &= ~IGC_I225_PHPM_DIS_2500_D3;
	}

	IGC_WRITE_REG(hw, IGC_I225_PHPM, data);
	return IGC_SUCCESS;
}

/**
 *  igc_set_eee_i225 - Enable/disable EEE support
 *  @hw: pointer to the HW structure
 *  @adv2p5G: boolean flag enabling 2.5G EEE advertisement
 *  @adv1G: boolean flag enabling 1G EEE advertisement
 *  @adv100M: boolean flag enabling 100M EEE advertisement
 *
 *  Enable/disable EEE based on setting in dev_spec structure.
 *
 **/
s32 igc_set_eee_i225(struct igc_hw *hw, bool adv2p5G, bool adv1G,
		       bool adv100M)
{
	u32 ipcnfg, eeer;

	DEBUGFUNC("igc_set_eee_i225");

	if (hw->mac.type != igc_i225 ||
	    hw->phy.media_type != igc_media_type_copper)
		goto out;
	ipcnfg = IGC_READ_REG(hw, IGC_IPCNFG);
	eeer = IGC_READ_REG(hw, IGC_EEER);

	/* enable or disable per user setting */
	if (!(hw->dev_spec._i225.eee_disable)) {
		u32 eee_su = IGC_READ_REG(hw, IGC_EEE_SU);

		if (adv100M)
			ipcnfg |= IGC_IPCNFG_EEE_100M_AN;
		else
			ipcnfg &= ~IGC_IPCNFG_EEE_100M_AN;

		if (adv1G)
			ipcnfg |= IGC_IPCNFG_EEE_1G_AN;
		else
			ipcnfg &= ~IGC_IPCNFG_EEE_1G_AN;

		if (adv2p5G)
			ipcnfg |= IGC_IPCNFG_EEE_2_5G_AN;
		else
			ipcnfg &= ~IGC_IPCNFG_EEE_2_5G_AN;

		eeer |= (IGC_EEER_TX_LPI_EN | IGC_EEER_RX_LPI_EN |
			IGC_EEER_LPI_FC);

		/* This bit should not be set in normal operation. */
		if (eee_su & IGC_EEE_SU_LPI_CLK_STP)
			DEBUGOUT("LPI Clock Stop Bit should not be set!\n");
	} else {
		ipcnfg &= ~(IGC_IPCNFG_EEE_2_5G_AN | IGC_IPCNFG_EEE_1G_AN |
			IGC_IPCNFG_EEE_100M_AN);
		eeer &= ~(IGC_EEER_TX_LPI_EN | IGC_EEER_RX_LPI_EN |
			IGC_EEER_LPI_FC);
	}
	IGC_WRITE_REG(hw, IGC_IPCNFG, ipcnfg);
	IGC_WRITE_REG(hw, IGC_EEER, eeer);
	IGC_READ_REG(hw, IGC_IPCNFG);
	IGC_READ_REG(hw, IGC_EEER);
out:

	return IGC_SUCCESS;
}