~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 6223ff2c84b266e45999df091d6f9dbd67215006 (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
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2018-2022 Marvell International Ltd.
 *
 * Support library for the ILK
 */

#include <time.h>
#include <log.h>
#include <linux/delay.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-agl-defs.h>
#include <mach/cvmx-bgxx-defs.h>
#include <mach/cvmx-ciu-defs.h>
#include <mach/cvmx-gmxx-defs.h>
#include <mach/cvmx-gserx-defs.h>
#include <mach/cvmx-ilk-defs.h>
#include <mach/cvmx-ipd-defs.h>
#include <mach/cvmx-pcsx-defs.h>
#include <mach/cvmx-pcsxx-defs.h>
#include <mach/cvmx-pki-defs.h>
#include <mach/cvmx-pko-defs.h>
#include <mach/cvmx-xcv-defs.h>

#include <mach/cvmx-hwpko.h>
#include <mach/cvmx-ilk.h>
#include <mach/cvmx-pki.h>

#include <mach/cvmx-helper.h>
#include <mach/cvmx-helper-board.h>
#include <mach/cvmx-helper-cfg.h>

/*
 * global configurations.
 *
 * for cn68, the default is {0xf, 0xf0}. to disable the 2nd ILK, set
 * cvmx_ilk_lane_mask[CVMX_NUM_ILK_INTF] = {0xff, 0x0} and
 * cvmx_ilk_chans[CVMX_NUM_ILK_INTF] = {8, 0}
 */
unsigned short cvmx_ilk_lane_mask[CVMX_MAX_NODES][CVMX_NUM_ILK_INTF] = {
	[0 ... CVMX_MAX_NODES - 1] = { 0x000f, 0x00f0 }
};

int cvmx_ilk_chans[CVMX_MAX_NODES][CVMX_NUM_ILK_INTF] = {
	[0 ... CVMX_MAX_NODES - 1] = { 8, 8 }
};

static cvmx_ilk_intf_t cvmx_ilk_intf_cfg[CVMX_MAX_NODES][CVMX_NUM_ILK_INTF];

cvmx_ilk_LA_mode_t cvmx_ilk_LA_mode[CVMX_NUM_ILK_INTF] = { { 0, 0 }, { 0, 0 } };
/**
 * User-overrideable callback function that returns whether or not an interface
 * should use look-aside mode.
 *
 * @param interface - interface being checked
 * @param channel - channel number, can be 0 or 1 or -1 to see if LA mode
 *                  should be enabled for the interface.
 * @return 0 to not use LA-mode, 1 to use LA-mode.
 */
int cvmx_ilk_use_la_mode(int interface, int channel)
{
	if (OCTEON_IS_MODEL(OCTEON_CN68XX_PASS1_0))
		return 0;

	if (interface >= CVMX_NUM_ILK_INTF) {
		debug("ERROR: invalid interface=%d in %s\n",
		      interface, __func__);
		return -1;
	}
	return cvmx_ilk_LA_mode[interface].ilk_LA_mode;
}

/**
 * User-overrideable callback function that returns whether or not an interface
 * in look-aside mode should enable the RX calendar.
 *
 * @param interface - interface to check
 * @return 1 to enable RX calendar, 0 to disable RX calendar.
 *
 * NOTE: For the CN68XX pass 2.0 this will enable the RX calendar for interface
 * 0 and not interface 1.  It is up to the customer to override this behavior.
 */
int cvmx_ilk_la_mode_enable_rx_calendar(int interface)
{
	/* There is an errata in the CN68XX pass 2.0 where if connected
	 * in a loopback configuration or back to back then only one interface
	 * can have the RX calendar enabled.
	 */
	if (interface >= CVMX_NUM_ILK_INTF) {
		debug("ERROR: invalid interface=%d in %s\n",
		      interface, __func__);
		return -1;
	}
	return cvmx_ilk_LA_mode[interface].ilk_LA_mode_cal_ena;
}

/**
 * Initialize and start the ILK interface.
 *
 * @param interface The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param lane_mask the lane group for this interface
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_start_interface(int interface, unsigned short lane_mask)
{
	int res = -1;
	int other_intf, this_qlm, other_qlm;
	unsigned short uni_mask;
	cvmx_ilk_txx_cfg0_t ilk_txx_cfg0;
	cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0;
	cvmx_ilk_ser_cfg_t ilk_ser_cfg;
	int node = (interface >> 4) & 0xf;

	interface &= 0xf;

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	if (lane_mask == 0)
		return res;

	/* check conflicts between 2 ilk interfaces. 1 lane can be assigned to 1
	 * interface only
	 */
	other_intf = !interface;
	if (cvmx_ilk_lane_mask[node][other_intf] & lane_mask) {
		debug("ILK%d:%d: %s: lane assignment conflict\n", node,
		      interface, __func__);
		return res;
	}

	/* check the legality of the lane mask. interface 0 can have 8 lanes,
	 * while interface 1 can have 4 lanes at most
	 */
	uni_mask = lane_mask >> (interface * 4);
	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		cvmx_mio_qlmx_cfg_t mio_qlmx_cfg, other_mio_qlmx_cfg;

		if ((uni_mask != 0x1 && uni_mask != 0x3 && uni_mask != 0xf &&
		     uni_mask != 0xff) ||
		    (interface == 1 && lane_mask > 0xf0)) {
			debug("ILK%d: %s: incorrect lane mask: 0x%x\n",
			      interface, __func__, uni_mask);
			return res;
		}
		/* check the availability of qlms. qlm_cfg = 001 means the chip
		 * is fused to give this qlm to ilk
		 */
		this_qlm = interface + CVMX_ILK_QLM_BASE();
		other_qlm = other_intf + CVMX_ILK_QLM_BASE();
		mio_qlmx_cfg.u64 = csr_rd(CVMX_MIO_QLMX_CFG(this_qlm));
		other_mio_qlmx_cfg.u64 = csr_rd(CVMX_MIO_QLMX_CFG(other_qlm));
		if (mio_qlmx_cfg.s.qlm_cfg != 1 ||
		    (uni_mask == 0xff && other_mio_qlmx_cfg.s.qlm_cfg != 1)) {
			debug("ILK%d: %s: qlm unavailable\n", interface,
			      __func__);
			return res;
		}
		/* Has 8 lanes */
		lane_mask &= 0xff;
	}

	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		int qlm;
		unsigned short lane_mask_all = 0;

		/* QLM 4 - QLM 7 can be configured for ILK. Get the lane mask
		 * of all the qlms that are configured for ilk
		 */
		for (qlm = 4; qlm < 8; qlm++) {
			cvmx_gserx_cfg_t gserx_cfg;
			cvmx_gserx_phy_ctl_t phy_ctl;

			/* Make sure QLM is powered and out of reset */
			phy_ctl.u64 =
				csr_rd_node(node, CVMX_GSERX_PHY_CTL(qlm));
			if (phy_ctl.s.phy_pd || phy_ctl.s.phy_reset)
				continue;

			/* Make sure QLM is in ILK mode */
			gserx_cfg.u64 = csr_rd_node(node, CVMX_GSERX_CFG(qlm));
			if (gserx_cfg.s.ila)
				lane_mask_all |= ((1 << 4) - 1)
						 << (4 * (qlm - 4));
		}

		if ((lane_mask_all & lane_mask) != lane_mask) {
			debug("ILK%d: %s: incorrect lane mask: 0x%x\n",
			      interface, __func__, lane_mask);
			return res;
		}
	}

	/* power up the serdes */
	ilk_ser_cfg.u64 = csr_rd_node(node, CVMX_ILK_SER_CFG);
	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		if (ilk_ser_cfg.cn68xx.ser_pwrup == 0) {
			ilk_ser_cfg.cn68xx.ser_rxpol_auto = 1;
			ilk_ser_cfg.cn68xx.ser_rxpol = 0;
			ilk_ser_cfg.cn68xx.ser_txpol = 0;
			ilk_ser_cfg.cn68xx.ser_reset_n = 0xff;
			ilk_ser_cfg.cn68xx.ser_haul = 0;
		}
		ilk_ser_cfg.cn68xx.ser_pwrup |=
			((interface == 0) && (lane_mask > 0xf)) ?
				0x3 :
				      (1 << interface);
	}
	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		ilk_ser_cfg.cn78xx.ser_rxpol_auto = 1;
		ilk_ser_cfg.cn78xx.ser_rxpol = 0;
		ilk_ser_cfg.cn78xx.ser_txpol = 0;
		ilk_ser_cfg.cn78xx.ser_reset_n = 0xffff;
	}
	csr_wr_node(node, CVMX_ILK_SER_CFG, ilk_ser_cfg.u64);

	if (OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X)) {
		/* Workaround for Errata (G-16467) */
		int qlm = (interface) ? 2 : 1;
		int start_qlm, end_qlm;

		/* Apply the workaround to both the QLMs if configured for x8 lanes */
		if (cvmx_pop(lane_mask) > 4) {
			start_qlm = 1;
			end_qlm = 2;
		} else {
			start_qlm = qlm;
			end_qlm = qlm;
		}

		for (qlm = start_qlm; qlm <= end_qlm; qlm++) {
#ifdef CVMX_QLM_DUMP_STATE
			debug("%s:%d: ILK%d: Applying workaround for Errata G-16467\n",
			      __func__, __LINE__, qlm);
			cvmx_qlm_display_registers(qlm);
			debug("\n");
#endif
			/* This workaround only applies to QLMs running ILK at 6.25Ghz */
			if ((cvmx_qlm_get_gbaud_mhz(qlm) == 6250) &&
			    (cvmx_qlm_jtag_get(qlm, 0, "clkf_byp") != 20)) {
				udelay(100); /* Wait 100us for links to stabalize */
				cvmx_qlm_jtag_set(qlm, -1, "clkf_byp", 20);
				/* Allow the QLM to exit reset */
				cvmx_qlm_jtag_set(qlm, -1, "cfg_rst_n_clr", 0);
				udelay(100); /* Wait 100us for links to stabalize */
				/* Allow TX on QLM */
				cvmx_qlm_jtag_set(qlm, -1, "cfg_tx_idle_set",
						  0);
			}
#ifdef CVMX_QLM_DUMP_STATE
			debug("%s:%d: ILK%d: Done applying workaround for Errata G-16467\n",
			      __func__, __LINE__, qlm);
			cvmx_qlm_display_registers(qlm);
			debug("\n\n");
#endif
		}
	}

	/* Initialize all calendar entries to xoff state */
	__cvmx_ilk_clear_cal((node << 4) | interface);

	/* Enable ILK LA mode if configured. */
	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		if (cvmx_ilk_use_la_mode(interface, 0)) {
			cvmx_ilk_txx_cfg1_t ilk_txx_cfg1;
			cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1;

			ilk_txx_cfg1.u64 = csr_rd(CVMX_ILK_TXX_CFG1(interface));
			ilk_rxx_cfg1.u64 = csr_rd(CVMX_ILK_RXX_CFG1(interface));
			ilk_txx_cfg1.s.la_mode = 1;
			ilk_txx_cfg1.s.tx_link_fc_jam = 1;
			ilk_txx_cfg1.s.rx_link_fc_ign = 1;
			ilk_rxx_cfg1.s.la_mode = 1;
			csr_wr(CVMX_ILK_TXX_CFG1(interface), ilk_txx_cfg1.u64);
			csr_wr(CVMX_ILK_RXX_CFG1(interface), ilk_rxx_cfg1.u64);
			cvmx_ilk_intf_cfg[node][interface].la_mode =
				1; /* Enable look-aside mode */
		} else {
			cvmx_ilk_intf_cfg[node][interface].la_mode =
				0; /* Disable look-aside mode */
		}
	}
	if (OCTEON_IS_MODEL(OCTEON_CN78XX))
		cvmx_ilk_intf_cfg[node][interface].la_mode = 0;

	/* configure the lane enable of the interface */
	ilk_txx_cfg0.u64 = csr_rd_node(node, CVMX_ILK_TXX_CFG0(interface));
	ilk_rxx_cfg0.u64 = csr_rd_node(node, CVMX_ILK_RXX_CFG0(interface));
	ilk_rxx_cfg0.s.lane_ena = lane_mask;
	ilk_txx_cfg0.s.lane_ena = lane_mask;
	csr_wr_node(node, CVMX_ILK_TXX_CFG0(interface), ilk_txx_cfg0.u64);
	csr_wr_node(node, CVMX_ILK_RXX_CFG0(interface), ilk_rxx_cfg0.u64);

	/* For 10.3125Gbs data rate, set SER_LIMIT to 0x3ff for x8 & x12 mode */
	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		cvmx_gserx_lane_mode_t lmode0, lmode1;

		lmode0.u64 = csr_rd_node(node, CVMX_GSERX_LANE_MODE(5));
		lmode1.u64 = csr_rd_node(node, CVMX_GSERX_LANE_MODE(7));
		if ((lmode0.s.lmode == 5 || lmode1.s.lmode == 5) &&
		    (lane_mask == 0xfff || lane_mask == 0xfff0 ||
		     lane_mask == 0xff || lane_mask == 0xff00)) {
			cvmx_ilk_txx_cfg1_t ilk_txx_cfg1;

			ilk_txx_cfg1.u64 =
				csr_rd_node(node, CVMX_ILK_TXX_CFG1(interface));
			ilk_txx_cfg1.s.ser_limit = 0x3ff;
			csr_wr_node(node, CVMX_ILK_TXX_CFG1(interface),
				    ilk_txx_cfg1.u64);
		}
	}

	/* write to local cache. for lane speed, if interface 0 has 8 lanes,
	 * assume both qlms have the same speed
	 */
	cvmx_ilk_intf_cfg[node][interface].intf_en = 1;
	res = 0;

	return res;
}

/**
 * set pipe group base and length for the interface
 *
 * @param xiface    The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param pipe_base the base of the pipe group
 * @param pipe_len  the length of the pipe group
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_set_pipe(int xiface, int pipe_base, unsigned int pipe_len)
{
	int res = -1;
	cvmx_ilk_txx_pipe_t ilk_txx_pipe;
	struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface);
	int interface = xi.interface - CVMX_ILK_GBL_BASE();

	if (!(OCTEON_IS_MODEL(OCTEON_CN68XX)))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	/* set them in ilk tx section */
	ilk_txx_pipe.u64 = csr_rd_node(xi.node, CVMX_ILK_TXX_PIPE(interface));
	ilk_txx_pipe.s.base = pipe_base;
	ilk_txx_pipe.s.nump = pipe_len;
	csr_wr_node(xi.node, CVMX_ILK_TXX_PIPE(interface), ilk_txx_pipe.u64);
	res = 0;

	return res;
}

/**
 * set logical channels for tx
 *
 * @param interface The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param pch     pointer to an array of pipe-channel pair
 * @param num_chs the number of entries in the pipe-channel array
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_tx_set_channel(int interface, cvmx_ilk_pipe_chan_t *pch,
			    unsigned int num_chs)
{
	int res = -1;
	cvmx_ilk_txx_idx_pmap_t ilk_txx_idx_pmap;
	cvmx_ilk_txx_mem_pmap_t ilk_txx_mem_pmap;
	unsigned int i;

	if (!(OCTEON_IS_MODEL(OCTEON_CN68XX)))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	if (!pch || num_chs > CVMX_ILK_MAX_PIPES)
		return res;

	if (cvmx_ilk_use_la_mode(interface, 0)) {
		ilk_txx_idx_pmap.u64 = 0;
		ilk_txx_mem_pmap.u64 = 0;
		for (i = 0; i < num_chs; i++) {
			ilk_txx_idx_pmap.s.index = pch->pipe;
			ilk_txx_mem_pmap.s.channel = pch->chan;
			ilk_txx_mem_pmap.s.remap = 1;
			csr_wr(CVMX_ILK_TXX_IDX_PMAP(interface),
			       ilk_txx_idx_pmap.u64);
			csr_wr(CVMX_ILK_TXX_MEM_PMAP(interface),
			       ilk_txx_mem_pmap.u64);
			pch++;
		}
	} else {
		/* write the pair to ilk tx */
		ilk_txx_mem_pmap.u64 = 0;
		ilk_txx_idx_pmap.u64 = 0;
		for (i = 0; i < num_chs; i++) {
			ilk_txx_idx_pmap.s.index = pch->pipe;
			ilk_txx_mem_pmap.s.channel = pch->chan;
			csr_wr(CVMX_ILK_TXX_IDX_PMAP(interface),
			       ilk_txx_idx_pmap.u64);
			csr_wr(CVMX_ILK_TXX_MEM_PMAP(interface),
			       ilk_txx_mem_pmap.u64);
			pch++;
		}
	}
	res = 0;

	return res;
}

/**
 * set pkind for rx
 *
 * @param xiface    The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param chpknd    pointer to an array of channel-pkind pair
 * @param num_pknd the number of entries in the channel-pkind array
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_rx_set_pknd(int xiface, cvmx_ilk_chan_pknd_t *chpknd,
			 unsigned int num_pknd)
{
	int res = -1;
	cvmx_ilk_rxf_idx_pmap_t ilk_rxf_idx_pmap;
	unsigned int i;
	struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface);
	int interface = xi.interface - CVMX_ILK_GBL_BASE();

	if (!(OCTEON_IS_MODEL(OCTEON_CN68XX)))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	if (!chpknd || num_pknd > CVMX_ILK_MAX_PKNDS)
		return res;

	res = 0;

	for (i = 0; i < num_pknd; i++) {
		ilk_rxf_idx_pmap.u64 = 0;
		/* write the pair to ilk rx. note the channels for different
		 * interfaces are given in *chpknd and interface is not used
		 * as a param
		 */
		if (chpknd->chan < 2 &&
		    cvmx_ilk_use_la_mode(interface, chpknd->chan)) {
			ilk_rxf_idx_pmap.s.index =
				interface * 256 + 128 + chpknd->chan;
			csr_wr(CVMX_ILK_RXF_IDX_PMAP, ilk_rxf_idx_pmap.u64);
			csr_wr(CVMX_ILK_RXF_MEM_PMAP, chpknd->pknd);
		}
		ilk_rxf_idx_pmap.s.index = interface * 256 + chpknd->chan;
		csr_wr(CVMX_ILK_RXF_IDX_PMAP, ilk_rxf_idx_pmap.u64);
		csr_wr(CVMX_ILK_RXF_MEM_PMAP, chpknd->pknd);
		chpknd++;
	}

	return res;
}

/**
 * configure calendar for rx
 *
 * @param intf The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param cal_depth the number of calendar entries
 * @param pent      pointer to calendar entries
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_rx_cal_conf(int intf, int cal_depth, cvmx_ilk_cal_entry_t *pent)
{
	int res = -1, i;
	cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0;
	int num_entries;
	int node = (intf >> 4) & 0xf;
	int interface = intf & 0xf;

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	if (cal_depth < CVMX_ILK_RX_MIN_CAL || cal_depth > CVMX_ILK_MAX_CAL ||
	    (OCTEON_IS_MODEL(OCTEON_CN68XX) && !pent))
		return res;

	/* mandatory link-level fc as workarounds for ILK-15397 and
	 * ILK-15479
	 */
	/* TODO: test effectiveness */

	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		/* Update the calendar for each channel */
		if ((cvmx_ilk_use_la_mode(interface, 0) == 0) ||
		    (cvmx_ilk_use_la_mode(interface, 0) &&
		     cvmx_ilk_la_mode_enable_rx_calendar(interface))) {
			for (i = 0; i < cal_depth; i++) {
				__cvmx_ilk_write_rx_cal_entry(
					interface, i, pent[i].pipe_bpid);
			}
		}

		/* Update the depth */
		ilk_rxx_cfg0.u64 = csr_rd(CVMX_ILK_RXX_CFG0(interface));
		num_entries = 1 + cal_depth + (cal_depth - 1) / 15;
		ilk_rxx_cfg0.s.cal_depth = num_entries;
		if (cvmx_ilk_use_la_mode(interface, 0)) {
			ilk_rxx_cfg0.s.mproto_ign = 1;
			ilk_rxx_cfg0.s.lnk_stats_ena = 1;
			ilk_rxx_cfg0.s.lnk_stats_wrap = 1;
		}
		csr_wr(CVMX_ILK_RXX_CFG0(interface), ilk_rxx_cfg0.u64);
	}

	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		ilk_rxx_cfg0.u64 =
			csr_rd_node(node, CVMX_ILK_RXX_CFG0(interface));
		/*
		 * Make sure cal_ena is 0 for programming the calendar table,
		 * as per Errata ILK-19398
		 */
		ilk_rxx_cfg0.s.cal_ena = 0;
		csr_wr_node(node, CVMX_ILK_RXX_CFG0(interface),
			    ilk_rxx_cfg0.u64);

		for (i = 0; i < cal_depth; i++)
			__cvmx_ilk_write_rx_cal_entry(intf, i, 0);

		ilk_rxx_cfg0.u64 =
			csr_rd_node(node, CVMX_ILK_RXX_CFG0(interface));
		num_entries = 1 + cal_depth + (cal_depth - 1) / 15;
		ilk_rxx_cfg0.s.cal_depth = num_entries;
		csr_wr_node(node, CVMX_ILK_RXX_CFG0(interface),
			    ilk_rxx_cfg0.u64);
	}

	return 0;
}

/**
 * set high water mark for rx
 *
 * @param intf      The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param hi_wm     high water mark for this interface
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_rx_set_hwm(int intf, int hi_wm)
{
	int res = -1;
	cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1;
	int node = (intf >> 4) & 0xf;
	int interface = intf & 0xf;

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	if (hi_wm <= 0)
		return res;

	/* set the hwm */
	ilk_rxx_cfg1.u64 = csr_rd_node(node, CVMX_ILK_RXX_CFG1(interface));
	ilk_rxx_cfg1.s.rx_fifo_hwm = hi_wm;
	csr_wr_node(node, CVMX_ILK_RXX_CFG1(interface), ilk_rxx_cfg1.u64);
	res = 0;

	return res;
}

/**
 * enable calendar for rx
 *
 * @param intf      The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param cal_ena   enable or disable calendar
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_rx_cal_ena(int intf, unsigned char cal_ena)
{
	int res = -1;
	cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0;
	int node = (intf >> 4) & 0xf;
	int interface = intf & 0xf;

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	if (cvmx_ilk_use_la_mode(interface, 0) &&
	    !cvmx_ilk_la_mode_enable_rx_calendar(interface))
		return 0;

	/* set the enable */
	ilk_rxx_cfg0.u64 = csr_rd_node(node, CVMX_ILK_RXX_CFG0(interface));
	ilk_rxx_cfg0.s.cal_ena = cal_ena;
	csr_wr_node(node, CVMX_ILK_RXX_CFG0(interface), ilk_rxx_cfg0.u64);
	csr_rd_node(node, CVMX_ILK_RXX_CFG0(interface));
	res = 0;

	return res;
}

/**
 * set up calendar for rx
 *
 * @param intf      The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param cal_depth the number of calendar entries
 * @param pent      pointer to calendar entries
 * @param hi_wm     high water mark for this interface
 * @param cal_ena   enable or disable calendar
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_cal_setup_rx(int intf, int cal_depth, cvmx_ilk_cal_entry_t *pent,
			  int hi_wm, unsigned char cal_ena)
{
	int res = -1;

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	res = cvmx_ilk_rx_cal_conf(intf, cal_depth, pent);
	if (res < 0)
		return res;

	res = cvmx_ilk_rx_set_hwm(intf, hi_wm);
	if (res < 0)
		return res;

	res = cvmx_ilk_rx_cal_ena(intf, cal_ena);
	return res;
}

/**
 * configure calendar for tx
 *
 * @param intf      The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param cal_depth the number of calendar entries
 * @param pent      pointer to calendar entries
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_tx_cal_conf(int intf, int cal_depth, cvmx_ilk_cal_entry_t *pent)
{
	int res = -1, i;
	cvmx_ilk_txx_cfg0_t ilk_txx_cfg0;
	int num_entries;
	int node = (intf >> 4) & 0xf;
	int interface = intf & 0xf;

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	if (cal_depth < CVMX_ILK_TX_MIN_CAL || cal_depth > CVMX_ILK_MAX_CAL ||
	    (OCTEON_IS_MODEL(OCTEON_CN68XX) && !pent))
		return res;

	/* mandatory link-level fc as workarounds for ILK-15397 and
	 * ILK-15479
	 */
	/* TODO: test effectiveness */

	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		/* Update the calendar for each channel */
		for (i = 0; i < cal_depth; i++) {
			__cvmx_ilk_write_tx_cal_entry(interface, i,
						      pent[i].pipe_bpid);
		}

		/* Set the depth (must be multiple of 8)*/
		ilk_txx_cfg0.u64 = csr_rd(CVMX_ILK_TXX_CFG0(interface));
		num_entries = 1 + cal_depth + (cal_depth - 1) / 15;
		ilk_txx_cfg0.s.cal_depth = (num_entries + 7) & ~7;
		csr_wr(CVMX_ILK_TXX_CFG0(interface), ilk_txx_cfg0.u64);
	}

	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		ilk_txx_cfg0.u64 =
			csr_rd_node(node, CVMX_ILK_TXX_CFG0(interface));
		/*
		 * Make sure cal_ena is 0 for programming the calendar table,
		 * as per Errata ILK-19398
		 */
		ilk_txx_cfg0.s.cal_ena = 0;
		csr_wr_node(node, CVMX_ILK_TXX_CFG0(interface),
			    ilk_txx_cfg0.u64);

		for (i = 0; i < cal_depth; i++)
			__cvmx_ilk_write_tx_cal_entry(intf, i, 0);

		ilk_txx_cfg0.u64 =
			csr_rd_node(node, CVMX_ILK_TXX_CFG0(interface));
		num_entries = 1 + cal_depth + (cal_depth - 1) / 15;
		/* cal_depth[2:0] needs to be zero, round up */
		ilk_txx_cfg0.s.cal_depth = (num_entries + 7) & 0x1f8;
		csr_wr_node(node, CVMX_ILK_TXX_CFG0(interface),
			    ilk_txx_cfg0.u64);
	}

	return 0;
}

/**
 * enable calendar for tx
 *
 * @param intf	    The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param cal_ena   enable or disable calendar
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_tx_cal_ena(int intf, unsigned char cal_ena)
{
	int res = -1;
	cvmx_ilk_txx_cfg0_t ilk_txx_cfg0;
	int node = (intf >> 4) & 0xf;
	int interface = intf & 0xf;

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	/* set the enable */
	ilk_txx_cfg0.u64 = csr_rd_node(node, CVMX_ILK_TXX_CFG0(interface));
	ilk_txx_cfg0.s.cal_ena = cal_ena;
	csr_wr_node(node, CVMX_ILK_TXX_CFG0(interface), ilk_txx_cfg0.u64);
	csr_rd_node(node, CVMX_ILK_TXX_CFG0(interface));
	res = 0;

	return res;
}

/**
 * set up calendar for tx
 *
 * @param intf      The identifier of the packet interface to configure and
 *                  use as a ILK interface. cn68xx has 2 interfaces: ilk0 and
 *                  ilk1.
 *
 * @param cal_depth the number of calendar entries
 * @param pent      pointer to calendar entries
 * @param cal_ena   enable or disable calendar
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_cal_setup_tx(int intf, int cal_depth, cvmx_ilk_cal_entry_t *pent,
			  unsigned char cal_ena)
{
	int res = -1;

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	res = cvmx_ilk_tx_cal_conf(intf, cal_depth, pent);
	if (res < 0)
		return res;

	res = cvmx_ilk_tx_cal_ena(intf, cal_ena);
	return res;
}

/* #define CVMX_ILK_STATS_ENA 1 */
#ifdef CVMX_ILK_STATS_ENA
static void cvmx_ilk_reg_dump_rx(int intf)
{
	int i;
	cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0;
	cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1;
	cvmx_ilk_rxx_int_t ilk_rxx_int;
	cvmx_ilk_rxx_jabber_t ilk_rxx_jabber;
	cvmx_ilk_rx_lnex_cfg_t ilk_rx_lnex_cfg;
	cvmx_ilk_rx_lnex_int_t ilk_rx_lnex_int;
	cvmx_ilk_gbl_cfg_t ilk_gbl_cfg;
	cvmx_ilk_ser_cfg_t ilk_ser_cfg;
	cvmx_ilk_rxf_idx_pmap_t ilk_rxf_idx_pmap;
	cvmx_ilk_rxf_mem_pmap_t ilk_rxf_mem_pmap;
	cvmx_ilk_rxx_idx_cal_t ilk_rxx_idx_cal;
	cvmx_ilk_rxx_mem_cal0_t ilk_rxx_mem_cal0;
	cvmx_ilk_rxx_mem_cal1_t ilk_rxx_mem_cal1;
	int node = (intf >> 4) & 0xf;
	int interface = intf & 0xf;

	ilk_rxx_cfg0.u64 = csr_rd_node(node, CVMX_ILK_RXX_CFG0(interface));
	debug("ilk rxx cfg0: 0x%16lx\n", ilk_rxx_cfg0.u64);

	ilk_rxx_cfg1.u64 = csr_rd_node(node, CVMX_ILK_RXX_CFG1(interface));
	debug("ilk rxx cfg1: 0x%16lx\n", ilk_rxx_cfg1.u64);

	ilk_rxx_int.u64 = csr_rd_node(node, CVMX_ILK_RXX_INT(interface));
	debug("ilk rxx int: 0x%16lx\n", ilk_rxx_int.u64);
	csr_wr_node(node, CVMX_ILK_RXX_INT(interface), ilk_rxx_int.u64);

	ilk_rxx_jabber.u64 = csr_rd_node(node, CVMX_ILK_RXX_JABBER(interface));
	debug("ilk rxx jabber: 0x%16lx\n", ilk_rxx_jabber.u64);

#define LNE_NUM_DBG 4
	for (i = 0; i < LNE_NUM_DBG; i++) {
		ilk_rx_lnex_cfg.u64 =
			csr_rd_node(node, CVMX_ILK_RX_LNEX_CFG(i));
		debug("ilk rx lnex cfg lane: %d  0x%16lx\n", i,
		      ilk_rx_lnex_cfg.u64);
	}

	for (i = 0; i < LNE_NUM_DBG; i++) {
		ilk_rx_lnex_int.u64 =
			csr_rd_node(node, CVMX_ILK_RX_LNEX_INT(i));
		debug("ilk rx lnex int lane: %d  0x%16lx\n", i,
		      ilk_rx_lnex_int.u64);
		csr_wr_node(node, CVMX_ILK_RX_LNEX_INT(i), ilk_rx_lnex_int.u64);
	}

	ilk_gbl_cfg.u64 = csr_rd_node(node, CVMX_ILK_GBL_CFG);
	debug("ilk gbl cfg: 0x%16lx\n", ilk_gbl_cfg.u64);

	ilk_ser_cfg.u64 = csr_rd_node(node, CVMX_ILK_SER_CFG);
	debug("ilk ser cfg: 0x%16lx\n", ilk_ser_cfg.u64);

#define CHAN_NUM_DBG 8
	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		ilk_rxf_idx_pmap.u64 = 0;
		ilk_rxf_idx_pmap.s.index = interface * 256;
		ilk_rxf_idx_pmap.s.inc = 1;
		csr_wr(CVMX_ILK_RXF_IDX_PMAP, ilk_rxf_idx_pmap.u64);
		for (i = 0; i < CHAN_NUM_DBG; i++) {
			ilk_rxf_mem_pmap.u64 = csr_rd(CVMX_ILK_RXF_MEM_PMAP);
			debug("ilk rxf mem pmap chan: %3d  0x%16lx\n", i,
			      ilk_rxf_mem_pmap.u64);
		}
	}
	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		cvmx_ilk_rxx_chax_t rxx_chax;

		for (i = 0; i < CHAN_NUM_DBG; i++) {
			rxx_chax.u64 = csr_rd_node(
				node, CVMX_ILK_RXX_CHAX(i, interface));
			debug("ilk chan: %d  pki chan: 0x%x\n", i,
			      rxx_chax.s.port_kind);
		}
	}

#define CAL_NUM_DBG 2
	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		ilk_rxx_idx_cal.u64 = 0;
		ilk_rxx_idx_cal.s.inc = 1;
		csr_wr(CVMX_ILK_RXX_IDX_CAL(interface), ilk_rxx_idx_cal.u64);
		for (i = 0; i < CAL_NUM_DBG; i++) {
			ilk_rxx_idx_cal.u64 =
				csr_rd(CVMX_ILK_RXX_IDX_CAL(interface));
			debug("ilk rxx idx cal: 0x%16lx\n",
			      ilk_rxx_idx_cal.u64);

			ilk_rxx_mem_cal0.u64 =
				csr_rd(CVMX_ILK_RXX_MEM_CAL0(interface));
			debug("ilk rxx mem cal0: 0x%16lx\n",
			      ilk_rxx_mem_cal0.u64);
			ilk_rxx_mem_cal1.u64 =
				csr_rd(CVMX_ILK_RXX_MEM_CAL1(interface));
			debug("ilk rxx mem cal1: 0x%16lx\n",
			      ilk_rxx_mem_cal1.u64);
		}
	}
	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		cvmx_ilk_rxx_cal_entryx_t rxx_cal_entryx;

		for (i = 0; i < CAL_NUM_DBG; i++) {
			rxx_cal_entryx.u64 = csr_rd_node(
				node, CVMX_ILK_RXX_CAL_ENTRYX(i, interface));
			debug("ilk rxx cal idx: %d\n", i);
			debug("ilk rxx cal ctl: 0x%x\n", rxx_cal_entryx.s.ctl);
			debug("ilk rxx cal pko chan: 0x%x\n",
			      rxx_cal_entryx.s.channel);
		}
	}
}

static void cvmx_ilk_reg_dump_tx(int intf)
{
	int i;
	cvmx_ilk_txx_cfg0_t ilk_txx_cfg0;
	cvmx_ilk_txx_cfg1_t ilk_txx_cfg1;
	cvmx_ilk_txx_idx_pmap_t ilk_txx_idx_pmap;
	cvmx_ilk_txx_mem_pmap_t ilk_txx_mem_pmap;
	cvmx_ilk_txx_int_t ilk_txx_int;
	cvmx_ilk_txx_pipe_t ilk_txx_pipe;
	cvmx_ilk_txx_idx_cal_t ilk_txx_idx_cal;
	cvmx_ilk_txx_mem_cal0_t ilk_txx_mem_cal0;
	cvmx_ilk_txx_mem_cal1_t ilk_txx_mem_cal1;
	int node = (intf >> 4) & 0xf;
	int interface = intf & 0xf;

	ilk_txx_cfg0.u64 = csr_rd_node(node, CVMX_ILK_TXX_CFG0(interface));
	debug("ilk txx cfg0: 0x%16lx\n", ilk_txx_cfg0.u64);

	ilk_txx_cfg1.u64 = csr_rd_node(node, CVMX_ILK_TXX_CFG1(interface));
	debug("ilk txx cfg1: 0x%16lx\n", ilk_txx_cfg1.u64);

	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		ilk_txx_pipe.u64 = csr_rd(CVMX_ILK_TXX_PIPE(interface));
		debug("ilk txx pipe: 0x%16lx\n", ilk_txx_pipe.u64);

		ilk_txx_idx_pmap.u64 = 0;
		ilk_txx_idx_pmap.s.index = ilk_txx_pipe.s.base;
		ilk_txx_idx_pmap.s.inc = 1;
		csr_wr(CVMX_ILK_TXX_IDX_PMAP(interface), ilk_txx_idx_pmap.u64);
		for (i = 0; i < CHAN_NUM_DBG; i++) {
			ilk_txx_mem_pmap.u64 =
				csr_rd(CVMX_ILK_TXX_MEM_PMAP(interface));
			debug("ilk txx mem pmap pipe: %3d  0x%16lx\n",
			      ilk_txx_pipe.s.base + i, ilk_txx_mem_pmap.u64);
		}
	}

	ilk_txx_int.u64 = csr_rd_node(node, CVMX_ILK_TXX_INT(interface));
	debug("ilk txx int: 0x%16lx\n", ilk_txx_int.u64);

	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		ilk_txx_idx_cal.u64 = 0;
		ilk_txx_idx_cal.s.inc = 1;
		csr_wr(CVMX_ILK_TXX_IDX_CAL(interface), ilk_txx_idx_cal.u64);
		for (i = 0; i < CAL_NUM_DBG; i++) {
			ilk_txx_idx_cal.u64 =
				csr_rd(CVMX_ILK_TXX_IDX_CAL(interface));
			debug("ilk txx idx cal: 0x%16lx\n",
			      ilk_txx_idx_cal.u64);

			ilk_txx_mem_cal0.u64 =
				csr_rd(CVMX_ILK_TXX_MEM_CAL0(interface));
			debug("ilk txx mem cal0: 0x%16lx\n",
			      ilk_txx_mem_cal0.u64);
			ilk_txx_mem_cal1.u64 =
				csr_rd(CVMX_ILK_TXX_MEM_CAL1(interface));
			debug("ilk txx mem cal1: 0x%16lx\n",
			      ilk_txx_mem_cal1.u64);
		}
	}
	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		cvmx_ilk_txx_cal_entryx_t txx_cal_entryx;

		for (i = 0; i < CAL_NUM_DBG; i++) {
			txx_cal_entryx.u64 = csr_rd_node(
				node, CVMX_ILK_TXX_CAL_ENTRYX(i, interface));
			debug("ilk txx cal idx: %d\n", i);
			debug("ilk txx cal ctl: 0x%x\n", txx_cal_entryx.s.ctl);
			debug("ilk txx cal pki chan: 0x%x\n",
			      txx_cal_entryx.s.channel);
		}
	}
}
#endif

/**
 * show run time status
 *
 * @param interface The identifier of the packet interface to enable. cn68xx
 *                  has 2 interfaces: ilk0 and ilk1.
 *
 * @return nothing
 */
#ifdef CVMX_ILK_RUNTIME_DBG
void cvmx_ilk_runtime_status(int interface)
{
	cvmx_ilk_txx_cfg1_t ilk_txx_cfg1;
	cvmx_ilk_txx_flow_ctl0_t ilk_txx_flow_ctl0;
	cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1;
	cvmx_ilk_rxx_int_t ilk_rxx_int;
	cvmx_ilk_rxx_flow_ctl0_t ilk_rxx_flow_ctl0;
	cvmx_ilk_rxx_flow_ctl1_t ilk_rxx_flow_ctl1;
	cvmx_ilk_gbl_int_t ilk_gbl_int;

	debug("\nilk run-time status: interface: %d\n", interface);

	ilk_txx_cfg1.u64 = csr_rd_node(node, CVMX_ILK_TXX_CFG1(interface));
	debug("\nilk txx cfg1: 0x%16lx\n", ilk_txx_cfg1.u64);
	if (ilk_txx_cfg1.s.rx_link_fc)
		debug("link flow control received\n");
	if (ilk_txx_cfg1.s.tx_link_fc)
		debug("link flow control sent\n");

	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		ilk_txx_flow_ctl0.u64 =
			csr_rd(CVMX_ILK_TXX_FLOW_CTL0(interface));
		debug("\nilk txx flow ctl0: 0x%16lx\n", ilk_txx_flow_ctl0.u64);
	}
	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		int i;
		cvmx_ilk_txx_cha_xonx_t txx_cha_xonx;

		for (i = 0; i < 4; i++) {
			txx_cha_xonx.u64 = csr_rd_node(
				node, CVMX_ILK_TXX_CHA_XONX(i, interface));
			debug("\nilk txx cha xon: 0x%16lx\n", txx_cha_xonx.u64);
		}
	}

	ilk_rxx_cfg1.u64 = csr_rd_node(node, CVMX_ILK_RXX_CFG1(interface));
	debug("\nilk rxx cfg1: 0x%16lx\n", ilk_rxx_cfg1.u64);
	debug("rx fifo count: %d\n", ilk_rxx_cfg1.s.rx_fifo_cnt);

	ilk_rxx_int.u64 = csr_rd_node(node, CVMX_ILK_RXX_INT(interface));
	debug("\nilk rxx int: 0x%16lx\n", ilk_rxx_int.u64);
	if (ilk_rxx_int.s.pkt_drop_rxf)
		debug("rx fifo packet drop\n");
	if (ilk_rxx_int.u64)
		csr_wr_node(node, CVMX_ILK_RXX_INT(interface), ilk_rxx_int.u64);

	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		ilk_rxx_flow_ctl0.u64 =
			csr_rd(CVMX_ILK_RXX_FLOW_CTL0(interface));
		debug("\nilk rxx flow ctl0: 0x%16lx\n", ilk_rxx_flow_ctl0.u64);

		ilk_rxx_flow_ctl1.u64 =
			csr_rd(CVMX_ILK_RXX_FLOW_CTL1(interface));
		debug("\nilk rxx flow ctl1: 0x%16lx\n", ilk_rxx_flow_ctl1.u64);
	}
	if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
		int i;
		cvmx_ilk_rxx_cha_xonx_t rxx_cha_xonx;

		for (i = 0; i < 4; i++) {
			rxx_cha_xonx.u64 = csr_rd_node(
				node, CVMX_ILK_RXX_CHA_XONX(i, interface));
			debug("\nilk rxx cha xon: 0x%16lx\n", rxx_cha_xonx.u64);
		}
	}

	ilk_gbl_int.u64 = csr_rd_node(node, CVMX_ILK_GBL_INT);
	debug("\nilk gbl int: 0x%16lx\n", ilk_gbl_int.u64);
	if (ilk_gbl_int.s.rxf_push_full)
		debug("rx fifo overflow\n");
	if (ilk_gbl_int.u64)
		csr_wr_node(node, CVMX_ILK_GBL_INT, ilk_gbl_int.u64);
}
#endif

/**
 * enable interface
 *
 * @param xiface    The identifier of the packet interface to enable. cn68xx
 *                  has 2 interfaces: ilk0 and ilk1.
 *
 * @return Zero on success, negative on failure.
 */
int cvmx_ilk_enable(int xiface)
{
	int res = -1;
	int retry_count = 0;
	cvmx_helper_link_info_t result;
	cvmx_ilk_txx_cfg1_t ilk_txx_cfg1;
	cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1;
#ifdef CVMX_ILK_STATS_ENA
	cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0;
	cvmx_ilk_txx_cfg0_t ilk_txx_cfg0;
#endif
	struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface);
	int node = xi.node;
	int interface = xi.interface - CVMX_ILK_GBL_BASE();

	if (!octeon_has_feature(OCTEON_FEATURE_ILK))
		return res;

	if (interface >= CVMX_NUM_ILK_INTF)
		return res;

	result.u64 = 0;

#ifdef CVMX_ILK_STATS_ENA
	debug("\n");
	debug("<<<< ILK%d: Before enabling ilk\n", interface);
	cvmx_ilk_reg_dump_rx(intf);
	cvmx_ilk_reg_dump_tx(intf);
#endif

	/* RX packet will be enabled only if link is up */

	/* TX side */
	ilk_txx_cfg1.u64 = csr_rd_node(node, CVMX_ILK_TXX_CFG1(interface));
	ilk_txx_cfg1.s.pkt_ena = 1;
	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
		if (cvmx_ilk_use_la_mode(interface, 0)) {
			ilk_txx_cfg1.s.la_mode = 1;
			ilk_txx_cfg1.s.tx_link_fc_jam = 1;
		}
	}
	csr_wr_node(node, CVMX_ILK_TXX_CFG1(interface), ilk_txx_cfg1.u64);
	csr_rd_node(node, CVMX_ILK_TXX_CFG1(interface));

#ifdef CVMX_ILK_STATS_ENA
	/* RX side stats */
	ilk_rxx_cfg0.u64 = csr_rd_node(node, CVMX_ILK_RXX_CFG0(interface));
	ilk_rxx_cfg0.s.lnk_stats_ena = 1;
	csr_wr_node(node, CVMX_ILK_RXX_CFG0(interface), ilk_rxx_cfg0.u64);

	/* TX side stats */
	ilk_txx_cfg0.u64 = csr_rd_node(node, CVMX_ILK_TXX_CFG0(interface));
	ilk_txx_cfg0.s.lnk_stats_ena = 1;
	csr_wr_node(node, CVMX_ILK_TXX_CFG0(interface), ilk_txx_cfg0.u64);
#endif

retry:
	retry_count++;
	if (retry_count > 10)
		goto out;

	/* Make sure the link is up, so that packets can be sent. */
	result = __cvmx_helper_ilk_link_get(
		cvmx_helper_get_ipd_port((interface + CVMX_ILK_GBL_BASE()), 0));

	/* Small delay before another retry. */
	udelay(100);

	ilk_rxx_cfg1.u64 = csr_rd_node(node, CVMX_ILK_RXX_CFG1(interface));
	if (ilk_rxx_cfg1.s.pkt_ena == 0)
		goto retry;

out:

#ifdef CVMX_ILK_STATS_ENA
	debug(">>>> ILK%d: After ILK is enabled\n", interface);
	cvmx_ilk_reg_dump_rx(intf);
	cvmx_ilk_reg_dump_tx(intf);
#endif

	if (result.s.link_up)
		return 0;

	return -1;
}

/**
 * Provide interface enable status
 *
 * @param xiface The identifier of the packet xiface to disable. cn68xx
 *                  has 2 interfaces: ilk0 and ilk1.
 *
 * @return Zero, not enabled; One, enabled.
 */
int cvmx_ilk_get_intf_ena(int xiface)
{
	struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface);
	int interface = xi.interface - CVMX_ILK_GBL_BASE();
	return cvmx_ilk_intf_cfg[xi.node][interface].intf_en;
}