summaryrefslogtreecommitdiff
path: root/arch/mips/mach-octeon/include/mach/cvmx-wqe.h
blob: 7244d5d29c01037026eab7f4cd00d5370564f1d6 (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
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2020 Marvell International Ltd.
 *
 * This header file defines the work queue entry (wqe) data structure.
 * Since this is a commonly used structure that depends on structures
 * from several hardware blocks, those definitions have been placed
 * in this file to create a single point of definition of the wqe
 * format.
 * Data structures are still named according to the block that they
 * relate to.
 */

#ifndef __CVMX_WQE_H__
#define __CVMX_WQE_H__

#include "cvmx-packet.h"
#include "cvmx-csr-enums.h"
#include "cvmx-pki-defs.h"
#include "cvmx-pip-defs.h"
#include "octeon-feature.h"

#define OCT_TAG_TYPE_STRING(x)						\
	(((x) == CVMX_POW_TAG_TYPE_ORDERED) ?				\
	 "ORDERED" :							\
	 (((x) == CVMX_POW_TAG_TYPE_ATOMIC) ?				\
	  "ATOMIC" :							\
	  (((x) == CVMX_POW_TAG_TYPE_NULL) ? "NULL" : "NULL_NULL")))

/* Error levels in WQE WORD2 (ERRLEV).*/
#define PKI_ERRLEV_E__RE_M 0x0
#define PKI_ERRLEV_E__LA_M 0x1
#define PKI_ERRLEV_E__LB_M 0x2
#define PKI_ERRLEV_E__LC_M 0x3
#define PKI_ERRLEV_E__LD_M 0x4
#define PKI_ERRLEV_E__LE_M 0x5
#define PKI_ERRLEV_E__LF_M 0x6
#define PKI_ERRLEV_E__LG_M 0x7

enum cvmx_pki_errlevel {
	CVMX_PKI_ERRLEV_E_RE = PKI_ERRLEV_E__RE_M,
	CVMX_PKI_ERRLEV_E_LA = PKI_ERRLEV_E__LA_M,
	CVMX_PKI_ERRLEV_E_LB = PKI_ERRLEV_E__LB_M,
	CVMX_PKI_ERRLEV_E_LC = PKI_ERRLEV_E__LC_M,
	CVMX_PKI_ERRLEV_E_LD = PKI_ERRLEV_E__LD_M,
	CVMX_PKI_ERRLEV_E_LE = PKI_ERRLEV_E__LE_M,
	CVMX_PKI_ERRLEV_E_LF = PKI_ERRLEV_E__LF_M,
	CVMX_PKI_ERRLEV_E_LG = PKI_ERRLEV_E__LG_M
};

#define CVMX_PKI_ERRLEV_MAX BIT(3) /* The size of WORD2:ERRLEV field.*/

/* Error code in WQE WORD2 (OPCODE).*/
#define CVMX_PKI_OPCODE_RE_NONE	      0x0
#define CVMX_PKI_OPCODE_RE_PARTIAL    0x1
#define CVMX_PKI_OPCODE_RE_JABBER     0x2
#define CVMX_PKI_OPCODE_RE_FCS	      0x7
#define CVMX_PKI_OPCODE_RE_FCS_RCV    0x8
#define CVMX_PKI_OPCODE_RE_TERMINATE  0x9
#define CVMX_PKI_OPCODE_RE_RX_CTL     0xb
#define CVMX_PKI_OPCODE_RE_SKIP	      0xc
#define CVMX_PKI_OPCODE_RE_DMAPKT     0xf
#define CVMX_PKI_OPCODE_RE_PKIPAR     0x13
#define CVMX_PKI_OPCODE_RE_PKIPCAM    0x14
#define CVMX_PKI_OPCODE_RE_MEMOUT     0x15
#define CVMX_PKI_OPCODE_RE_BUFS_OFLOW 0x16
#define CVMX_PKI_OPCODE_L2_FRAGMENT   0x20
#define CVMX_PKI_OPCODE_L2_OVERRUN    0x21
#define CVMX_PKI_OPCODE_L2_PFCS	      0x22
#define CVMX_PKI_OPCODE_L2_PUNY	      0x23
#define CVMX_PKI_OPCODE_L2_MAL	      0x24
#define CVMX_PKI_OPCODE_L2_OVERSIZE   0x25
#define CVMX_PKI_OPCODE_L2_UNDERSIZE  0x26
#define CVMX_PKI_OPCODE_L2_LENMISM    0x27
#define CVMX_PKI_OPCODE_IP_NOT	      0x41
#define CVMX_PKI_OPCODE_IP_CHK	      0x42
#define CVMX_PKI_OPCODE_IP_MAL	      0x43
#define CVMX_PKI_OPCODE_IP_MALD	      0x44
#define CVMX_PKI_OPCODE_IP_HOP	      0x45
#define CVMX_PKI_OPCODE_L4_MAL	      0x61
#define CVMX_PKI_OPCODE_L4_CHK	      0x62
#define CVMX_PKI_OPCODE_L4_LEN	      0x63
#define CVMX_PKI_OPCODE_L4_PORT	      0x64
#define CVMX_PKI_OPCODE_TCP_FLAG      0x65

#define CVMX_PKI_OPCODE_MAX BIT(8) /* The size of WORD2:OPCODE field.*/

/* Layer types in pki */
#define CVMX_PKI_LTYPE_E_NONE_M	      0x0
#define CVMX_PKI_LTYPE_E_ENET_M	      0x1
#define CVMX_PKI_LTYPE_E_VLAN_M	      0x2
#define CVMX_PKI_LTYPE_E_SNAP_PAYLD_M 0x5
#define CVMX_PKI_LTYPE_E_ARP_M	      0x6
#define CVMX_PKI_LTYPE_E_RARP_M	      0x7
#define CVMX_PKI_LTYPE_E_IP4_M	      0x8
#define CVMX_PKI_LTYPE_E_IP4_OPT_M    0x9
#define CVMX_PKI_LTYPE_E_IP6_M	      0xA
#define CVMX_PKI_LTYPE_E_IP6_OPT_M    0xB
#define CVMX_PKI_LTYPE_E_IPSEC_ESP_M  0xC
#define CVMX_PKI_LTYPE_E_IPFRAG_M     0xD
#define CVMX_PKI_LTYPE_E_IPCOMP_M     0xE
#define CVMX_PKI_LTYPE_E_TCP_M	      0x10
#define CVMX_PKI_LTYPE_E_UDP_M	      0x11
#define CVMX_PKI_LTYPE_E_SCTP_M	      0x12
#define CVMX_PKI_LTYPE_E_UDP_VXLAN_M  0x13
#define CVMX_PKI_LTYPE_E_GRE_M	      0x14
#define CVMX_PKI_LTYPE_E_NVGRE_M      0x15
#define CVMX_PKI_LTYPE_E_GTP_M	      0x16
#define CVMX_PKI_LTYPE_E_SW28_M	      0x1C
#define CVMX_PKI_LTYPE_E_SW29_M	      0x1D
#define CVMX_PKI_LTYPE_E_SW30_M	      0x1E
#define CVMX_PKI_LTYPE_E_SW31_M	      0x1F

enum cvmx_pki_layer_type {
	CVMX_PKI_LTYPE_E_NONE = CVMX_PKI_LTYPE_E_NONE_M,
	CVMX_PKI_LTYPE_E_ENET = CVMX_PKI_LTYPE_E_ENET_M,
	CVMX_PKI_LTYPE_E_VLAN = CVMX_PKI_LTYPE_E_VLAN_M,
	CVMX_PKI_LTYPE_E_SNAP_PAYLD = CVMX_PKI_LTYPE_E_SNAP_PAYLD_M,
	CVMX_PKI_LTYPE_E_ARP = CVMX_PKI_LTYPE_E_ARP_M,
	CVMX_PKI_LTYPE_E_RARP = CVMX_PKI_LTYPE_E_RARP_M,
	CVMX_PKI_LTYPE_E_IP4 = CVMX_PKI_LTYPE_E_IP4_M,
	CVMX_PKI_LTYPE_E_IP4_OPT = CVMX_PKI_LTYPE_E_IP4_OPT_M,
	CVMX_PKI_LTYPE_E_IP6 = CVMX_PKI_LTYPE_E_IP6_M,
	CVMX_PKI_LTYPE_E_IP6_OPT = CVMX_PKI_LTYPE_E_IP6_OPT_M,
	CVMX_PKI_LTYPE_E_IPSEC_ESP = CVMX_PKI_LTYPE_E_IPSEC_ESP_M,
	CVMX_PKI_LTYPE_E_IPFRAG = CVMX_PKI_LTYPE_E_IPFRAG_M,
	CVMX_PKI_LTYPE_E_IPCOMP = CVMX_PKI_LTYPE_E_IPCOMP_M,
	CVMX_PKI_LTYPE_E_TCP = CVMX_PKI_LTYPE_E_TCP_M,
	CVMX_PKI_LTYPE_E_UDP = CVMX_PKI_LTYPE_E_UDP_M,
	CVMX_PKI_LTYPE_E_SCTP = CVMX_PKI_LTYPE_E_SCTP_M,
	CVMX_PKI_LTYPE_E_UDP_VXLAN = CVMX_PKI_LTYPE_E_UDP_VXLAN_M,
	CVMX_PKI_LTYPE_E_GRE = CVMX_PKI_LTYPE_E_GRE_M,
	CVMX_PKI_LTYPE_E_NVGRE = CVMX_PKI_LTYPE_E_NVGRE_M,
	CVMX_PKI_LTYPE_E_GTP = CVMX_PKI_LTYPE_E_GTP_M,
	CVMX_PKI_LTYPE_E_SW28 = CVMX_PKI_LTYPE_E_SW28_M,
	CVMX_PKI_LTYPE_E_SW29 = CVMX_PKI_LTYPE_E_SW29_M,
	CVMX_PKI_LTYPE_E_SW30 = CVMX_PKI_LTYPE_E_SW30_M,
	CVMX_PKI_LTYPE_E_SW31 = CVMX_PKI_LTYPE_E_SW31_M,
	CVMX_PKI_LTYPE_E_MAX = CVMX_PKI_LTYPE_E_SW31
};

typedef union {
	u64 u64;
	struct {
		u64 ptr_vlan : 8;
		u64 ptr_layer_g : 8;
		u64 ptr_layer_f : 8;
		u64 ptr_layer_e : 8;
		u64 ptr_layer_d : 8;
		u64 ptr_layer_c : 8;
		u64 ptr_layer_b : 8;
		u64 ptr_layer_a : 8;
	};
} cvmx_pki_wqe_word4_t;

/**
 * HW decode / err_code in work queue entry
 */
typedef union {
	u64 u64;
	struct {
		u64 bufs : 8;
		u64 ip_offset : 8;
		u64 vlan_valid : 1;
		u64 vlan_stacked : 1;
		u64 unassigned : 1;
		u64 vlan_cfi : 1;
		u64 vlan_id : 12;
		u64 varies : 12;
		u64 dec_ipcomp : 1;
		u64 tcp_or_udp : 1;
		u64 dec_ipsec : 1;
		u64 is_v6 : 1;
		u64 software : 1;
		u64 L4_error : 1;
		u64 is_frag : 1;
		u64 IP_exc : 1;
		u64 is_bcast : 1;
		u64 is_mcast : 1;
		u64 not_IP : 1;
		u64 rcv_error : 1;
		u64 err_code : 8;
	} s;
	struct {
		u64 bufs : 8;
		u64 ip_offset : 8;
		u64 vlan_valid : 1;
		u64 vlan_stacked : 1;
		u64 unassigned : 1;
		u64 vlan_cfi : 1;
		u64 vlan_id : 12;
		u64 port : 12;
		u64 dec_ipcomp : 1;
		u64 tcp_or_udp : 1;
		u64 dec_ipsec : 1;
		u64 is_v6 : 1;
		u64 software : 1;
		u64 L4_error : 1;
		u64 is_frag : 1;
		u64 IP_exc : 1;
		u64 is_bcast : 1;
		u64 is_mcast : 1;
		u64 not_IP : 1;
		u64 rcv_error : 1;
		u64 err_code : 8;
	} s_cn68xx;
	struct {
		u64 bufs : 8;
		u64 ip_offset : 8;
		u64 vlan_valid : 1;
		u64 vlan_stacked : 1;
		u64 unassigned : 1;
		u64 vlan_cfi : 1;
		u64 vlan_id : 12;
		u64 pr : 4;
		u64 unassigned2a : 4;
		u64 unassigned2 : 4;
		u64 dec_ipcomp : 1;
		u64 tcp_or_udp : 1;
		u64 dec_ipsec : 1;
		u64 is_v6 : 1;
		u64 software : 1;
		u64 L4_error : 1;
		u64 is_frag : 1;
		u64 IP_exc : 1;
		u64 is_bcast : 1;
		u64 is_mcast : 1;
		u64 not_IP : 1;
		u64 rcv_error : 1;
		u64 err_code : 8;
	} s_cn38xx;
	struct {
		u64 unused1 : 16;
		u64 vlan : 16;
		u64 unused2 : 32;
	} svlan;
	struct {
		u64 bufs : 8;
		u64 unused : 8;
		u64 vlan_valid : 1;
		u64 vlan_stacked : 1;
		u64 unassigned : 1;
		u64 vlan_cfi : 1;
		u64 vlan_id : 12;
		u64 varies : 12;
		u64 unassigned2 : 4;
		u64 software : 1;
		u64 unassigned3 : 1;
		u64 is_rarp : 1;
		u64 is_arp : 1;
		u64 is_bcast : 1;
		u64 is_mcast : 1;
		u64 not_IP : 1;
		u64 rcv_error : 1;
		u64 err_code : 8;
	} snoip;
	struct {
		u64 bufs : 8;
		u64 unused : 8;
		u64 vlan_valid : 1;
		u64 vlan_stacked : 1;
		u64 unassigned : 1;
		u64 vlan_cfi : 1;
		u64 vlan_id : 12;
		u64 port : 12;
		u64 unassigned2 : 4;
		u64 software : 1;
		u64 unassigned3 : 1;
		u64 is_rarp : 1;
		u64 is_arp : 1;
		u64 is_bcast : 1;
		u64 is_mcast : 1;
		u64 not_IP : 1;
		u64 rcv_error : 1;
		u64 err_code : 8;
	} snoip_cn68xx;
	struct {
		u64 bufs : 8;
		u64 unused : 8;
		u64 vlan_valid : 1;
		u64 vlan_stacked : 1;
		u64 unassigned : 1;
		u64 vlan_cfi : 1;
		u64 vlan_id : 12;
		u64 pr : 4;
		u64 unassigned2a : 8;
		u64 unassigned2 : 4;
		u64 software : 1;
		u64 unassigned3 : 1;
		u64 is_rarp : 1;
		u64 is_arp : 1;
		u64 is_bcast : 1;
		u64 is_mcast : 1;
		u64 not_IP : 1;
		u64 rcv_error : 1;
		u64 err_code : 8;
	} snoip_cn38xx;
} cvmx_pip_wqe_word2_t;

typedef union {
	u64 u64;
	struct {
		u64 software : 1;
		u64 lg_hdr_type : 5;
		u64 lf_hdr_type : 5;
		u64 le_hdr_type : 5;
		u64 ld_hdr_type : 5;
		u64 lc_hdr_type : 5;
		u64 lb_hdr_type : 5;
		u64 is_la_ether : 1;
		u64 rsvd_0 : 8;
		u64 vlan_valid : 1;
		u64 vlan_stacked : 1;
		u64 stat_inc : 1;
		u64 pcam_flag4 : 1;
		u64 pcam_flag3 : 1;
		u64 pcam_flag2 : 1;
		u64 pcam_flag1 : 1;
		u64 is_frag : 1;
		u64 is_l3_bcast : 1;
		u64 is_l3_mcast : 1;
		u64 is_l2_bcast : 1;
		u64 is_l2_mcast : 1;
		u64 is_raw : 1;
		u64 err_level : 3;
		u64 err_code : 8;
	};
} cvmx_pki_wqe_word2_t;

typedef union {
	u64 u64;
	cvmx_pki_wqe_word2_t pki;
	cvmx_pip_wqe_word2_t pip;
} cvmx_wqe_word2_t;

typedef union {
	u64 u64;
	struct {
		u16 hw_chksum;
		u8 unused;
		u64 next_ptr : 40;
	} cn38xx;
	struct {
		u64 l4ptr : 8;	  /* 56..63 */
		u64 unused0 : 8;  /* 48..55 */
		u64 l3ptr : 8;	  /* 40..47 */
		u64 l2ptr : 8;	  /* 32..39 */
		u64 unused1 : 18; /* 14..31 */
		u64 bpid : 6;	  /* 8..13 */
		u64 unused2 : 2;  /* 6..7 */
		u64 pknd : 6;	  /* 0..5 */
	} cn68xx;
} cvmx_pip_wqe_word0_t;

typedef union {
	u64 u64;
	struct {
		u64 rsvd_0 : 4;
		u64 aura : 12;
		u64 rsvd_1 : 1;
		u64 apad : 3;
		u64 channel : 12;
		u64 bufs : 8;
		u64 style : 8;
		u64 rsvd_2 : 10;
		u64 pknd : 6;
	};
} cvmx_pki_wqe_word0_t;

/* Use reserved bit, set by HW to 0, to indicate buf_ptr legacy translation*/
#define pki_wqe_translated word0.rsvd_1

typedef union {
	u64 u64;
	cvmx_pip_wqe_word0_t pip;
	cvmx_pki_wqe_word0_t pki;
	struct {
		u64 unused : 24;
		u64 next_ptr : 40; /* On cn68xx this is unused as well */
	} raw;
} cvmx_wqe_word0_t;

typedef union {
	u64 u64;
	struct {
		u64 len : 16;
		u64 rsvd_0 : 2;
		u64 rsvd_1 : 2;
		u64 grp : 10;
		cvmx_pow_tag_type_t tag_type : 2;
		u64 tag : 32;
	};
} cvmx_pki_wqe_word1_t;

#define pki_errata20776 word1.rsvd_0

typedef union {
	u64 u64;
	struct {
		u64 len : 16;
		u64 varies : 14;
		cvmx_pow_tag_type_t tag_type : 2;
		u64 tag : 32;
	};
	cvmx_pki_wqe_word1_t cn78xx;
	struct {
		u64 len : 16;
		u64 zero_0 : 1;
		u64 qos : 3;
		u64 zero_1 : 1;
		u64 grp : 6;
		u64 zero_2 : 3;
		cvmx_pow_tag_type_t tag_type : 2;
		u64 tag : 32;
	} cn68xx;
	struct {
		u64 len : 16;
		u64 ipprt : 6;
		u64 qos : 3;
		u64 grp : 4;
		u64 zero_2 : 1;
		cvmx_pow_tag_type_t tag_type : 2;
		u64 tag : 32;
	} cn38xx;
} cvmx_wqe_word1_t;

typedef union {
	u64 u64;
	struct {
		u64 rsvd_0 : 8;
		u64 hwerr : 8;
		u64 rsvd_1 : 24;
		u64 sqid : 8;
		u64 rsvd_2 : 4;
		u64 vfnum : 12;
	};
} cvmx_wqe_word3_t;

typedef union {
	u64 u64;
	struct {
		u64 rsvd_0 : 21;
		u64 sqfc : 11;
		u64 rsvd_1 : 5;
		u64 sqtail : 11;
		u64 rsvd_2 : 3;
		u64 sqhead : 13;
	};
} cvmx_wqe_word4_t;

/**
 * Work queue entry format.
 * Must be 8-byte aligned.
 */
typedef struct cvmx_wqe_s {
	/*-------------------------------------------------------------------*/
	/* WORD 0                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64 bits are filled by HW when a packet
	 * arrives.
	 */
	cvmx_wqe_word0_t word0;

	/*-------------------------------------------------------------------*/
	/* WORD 1                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64 bits are filled by HW when a packet
	 * arrives.
	 */
	cvmx_wqe_word1_t word1;

	/*-------------------------------------------------------------------*/
	/* WORD 2                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64-bits are filled in by hardware when a
	 * packet arrives. This indicates a variety of status and error
	 *conditions.
	 */
	cvmx_pip_wqe_word2_t word2;

	/* Pointer to the first segment of the packet. */
	cvmx_buf_ptr_t packet_ptr;

	/* HW WRITE: OCTEON will fill in a programmable amount from the packet,
	 * up to (at most, but perhaps less) the amount needed to fill the work
	 * queue entry to 128 bytes. If the packet is recognized to be IP, the
	 * hardware starts (except that the IPv4 header is padded for
	 * appropriate alignment) writing here where the IP header starts.
	 * If the packet is not recognized to be IP, the hardware starts
	 * writing the beginning of the packet here.
	 */
	u8 packet_data[96];

	/* If desired, SW can make the work Q entry any length. For the purposes
	 * of discussion here, Assume 128B always, as this is all that the hardware
	 * deals with.
	 */
} CVMX_CACHE_LINE_ALIGNED cvmx_wqe_t;

/**
 * Work queue entry format for NQM
 * Must be 8-byte aligned
 */
typedef struct cvmx_wqe_nqm_s {
	/*-------------------------------------------------------------------*/
	/* WORD 0                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64 bits are filled by HW when a packet
	 * arrives.
	 */
	cvmx_wqe_word0_t word0;

	/*-------------------------------------------------------------------*/
	/* WORD 1                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64 bits are filled by HW when a packet
	 * arrives.
	 */
	cvmx_wqe_word1_t word1;

	/*-------------------------------------------------------------------*/
	/* WORD 2                                                            */
	/*-------------------------------------------------------------------*/
	/* Reserved */
	u64 word2;

	/*-------------------------------------------------------------------*/
	/* WORD 3                                                            */
	/*-------------------------------------------------------------------*/
	/* NVMe specific information.*/
	cvmx_wqe_word3_t word3;

	/*-------------------------------------------------------------------*/
	/* WORD 4                                                            */
	/*-------------------------------------------------------------------*/
	/* NVMe specific information.*/
	cvmx_wqe_word4_t word4;

	/* HW WRITE: OCTEON will fill in a programmable amount from the packet,
	 * up to (at most, but perhaps less) the amount needed to fill the work
	 * queue entry to 128 bytes. If the packet is recognized to be IP, the
	 * hardware starts (except that the IPv4 header is padded for
	 * appropriate alignment) writing here where the IP header starts.
	 * If the packet is not recognized to be IP, the hardware starts
	 * writing the beginning of the packet here.
	 */
	u8 packet_data[88];

	/* If desired, SW can make the work Q entry any length.
	 * For the purposes of discussion here, assume 128B always, as this is
	 * all that the hardware deals with.
	 */
} CVMX_CACHE_LINE_ALIGNED cvmx_wqe_nqm_t;

/**
 * Work queue entry format for 78XX.
 * In 78XX packet data always resides in WQE buffer unless option
 * DIS_WQ_DAT=1 in PKI_STYLE_BUF, which causes packet data to use separate buffer.
 *
 * Must be 8-byte aligned.
 */
typedef struct {
	/*-------------------------------------------------------------------*/
	/* WORD 0                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64 bits are filled by HW when a packet
	 * arrives.
	 */
	cvmx_pki_wqe_word0_t word0;

	/*-------------------------------------------------------------------*/
	/* WORD 1                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64 bits are filled by HW when a packet
	 * arrives.
	 */
	cvmx_pki_wqe_word1_t word1;

	/*-------------------------------------------------------------------*/
	/* WORD 2                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64-bits are filled in by hardware when a
	 * packet arrives. This indicates a variety of status and error
	 * conditions.
	 */
	cvmx_pki_wqe_word2_t word2;

	/*-------------------------------------------------------------------*/
	/* WORD 3                                                            */
	/*-------------------------------------------------------------------*/
	/* Pointer to the first segment of the packet.*/
	cvmx_buf_ptr_pki_t packet_ptr;

	/*-------------------------------------------------------------------*/
	/* WORD 4                                                            */
	/*-------------------------------------------------------------------*/
	/* HW WRITE: the following 64-bits are filled in by hardware when a
	 * packet arrives contains a byte pointer to the start of Layer
	 * A/B/C/D/E/F/G relative of start of packet.
	 */
	cvmx_pki_wqe_word4_t word4;

	/*-------------------------------------------------------------------*/
	/* WORDs 5/6/7 may be extended there, if WQE_HSZ is set.             */
	/*-------------------------------------------------------------------*/
	u64 wqe_data[11];

} CVMX_CACHE_LINE_ALIGNED cvmx_wqe_78xx_t;

/* Node LS-bit position in the WQE[grp] or PKI_QPG_TBL[grp_ok].*/
#define CVMX_WQE_GRP_NODE_SHIFT 8

/*
 * This is an accessor function into the WQE that retreives the
 * ingress port number, which can also be used as a destination
 * port number for the same port.
 *
 * @param work - Work Queue Entrey pointer
 * @returns returns the normalized port number, also known as "ipd" port
 */
static inline int cvmx_wqe_get_port(cvmx_wqe_t *work)
{
	int port;

	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		/* In 78xx wqe entry has channel number not port*/
		port = work->word0.pki.channel;
		/* For BGX interfaces (0x800 - 0xdff) the 4 LSBs indicate
		 * the PFC channel, must be cleared to normalize to "ipd"
		 */
		if (port & 0x800)
			port &= 0xff0;
		/* Node number is in AURA field, make it part of port # */
		port |= (work->word0.pki.aura >> 10) << 12;
	} else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE)) {
		port = work->word2.s_cn68xx.port;
	} else {
		port = work->word1.cn38xx.ipprt;
	}

	return port;
}

static inline void cvmx_wqe_set_port(cvmx_wqe_t *work, int port)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		work->word0.pki.channel = port;
	else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE))
		work->word2.s_cn68xx.port = port;
	else
		work->word1.cn38xx.ipprt = port;
}

static inline int cvmx_wqe_get_grp(cvmx_wqe_t *work)
{
	int grp;

	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		/* legacy: GRP[0..2] :=QOS */
		grp = (0xff & work->word1.cn78xx.grp) >> 3;
	else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE))
		grp = work->word1.cn68xx.grp;
	else
		grp = work->word1.cn38xx.grp;

	return grp;
}

static inline void cvmx_wqe_set_xgrp(cvmx_wqe_t *work, int grp)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		work->word1.cn78xx.grp = grp;
	else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE))
		work->word1.cn68xx.grp = grp;
	else
		work->word1.cn38xx.grp = grp;
}

static inline int cvmx_wqe_get_xgrp(cvmx_wqe_t *work)
{
	int grp;

	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		grp = work->word1.cn78xx.grp;
	else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE))
		grp = work->word1.cn68xx.grp;
	else
		grp = work->word1.cn38xx.grp;

	return grp;
}

static inline void cvmx_wqe_set_grp(cvmx_wqe_t *work, int grp)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		unsigned int node = cvmx_get_node_num();
		/* Legacy: GRP[0..2] :=QOS */
		work->word1.cn78xx.grp &= 0x7;
		work->word1.cn78xx.grp |= 0xff & (grp << 3);
		work->word1.cn78xx.grp |= (node << 8);
	} else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE)) {
		work->word1.cn68xx.grp = grp;
	} else {
		work->word1.cn38xx.grp = grp;
	}
}

static inline int cvmx_wqe_get_qos(cvmx_wqe_t *work)
{
	int qos;

	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		/* Legacy: GRP[0..2] :=QOS */
		qos = work->word1.cn78xx.grp & 0x7;
	} else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE)) {
		qos = work->word1.cn68xx.qos;
	} else {
		qos = work->word1.cn38xx.qos;
	}

	return qos;
}

static inline void cvmx_wqe_set_qos(cvmx_wqe_t *work, int qos)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		/* legacy: GRP[0..2] :=QOS */
		work->word1.cn78xx.grp &= ~0x7;
		work->word1.cn78xx.grp |= qos & 0x7;
	} else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE)) {
		work->word1.cn68xx.qos = qos;
	} else {
		work->word1.cn38xx.qos = qos;
	}
}

static inline int cvmx_wqe_get_len(cvmx_wqe_t *work)
{
	int len;

	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		len = work->word1.cn78xx.len;
	else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE))
		len = work->word1.cn68xx.len;
	else
		len = work->word1.cn38xx.len;

	return len;
}

static inline void cvmx_wqe_set_len(cvmx_wqe_t *work, int len)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		work->word1.cn78xx.len = len;
	else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE))
		work->word1.cn68xx.len = len;
	else
		work->word1.cn38xx.len = len;
}

/**
 * This function returns, if there was L2/L1 errors detected in packet.
 *
 * @param work	pointer to work queue entry
 *
 * Return:	0 if packet had no error, non-zero to indicate error code.
 *
 * Please refer to HRM for the specific model for full enumaration of error codes.
 * With Octeon1/Octeon2 models, the returned code indicates L1/L2 errors.
 * On CN73XX/CN78XX, the return code is the value of PKI_OPCODE_E,
 * if it is non-zero, otherwise the returned code will be derived from
 * PKI_ERRLEV_E such that an error indicated in LayerA will return 0x20,
 * LayerB - 0x30, LayerC - 0x40 and so forth.
 */
static inline int cvmx_wqe_get_rcv_err(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (wqe->word2.err_level == CVMX_PKI_ERRLEV_E_RE || wqe->word2.err_code != 0)
			return wqe->word2.err_code;
		else
			return (wqe->word2.err_level << 4) + 0x10;
	} else if (work->word2.snoip.rcv_error) {
		return work->word2.snoip.err_code;
	}

	return 0;
}

static inline u32 cvmx_wqe_get_tag(cvmx_wqe_t *work)
{
	return work->word1.tag;
}

static inline void cvmx_wqe_set_tag(cvmx_wqe_t *work, u32 tag)
{
	work->word1.tag = tag;
}

static inline int cvmx_wqe_get_tt(cvmx_wqe_t *work)
{
	return work->word1.tag_type;
}

static inline void cvmx_wqe_set_tt(cvmx_wqe_t *work, int tt)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		work->word1.cn78xx.tag_type = (cvmx_pow_tag_type_t)tt;
	} else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE)) {
		work->word1.cn68xx.tag_type = (cvmx_pow_tag_type_t)tt;
		work->word1.cn68xx.zero_2 = 0;
	} else {
		work->word1.cn38xx.tag_type = (cvmx_pow_tag_type_t)tt;
		work->word1.cn38xx.zero_2 = 0;
	}
}

static inline u8 cvmx_wqe_get_unused8(cvmx_wqe_t *work)
{
	u8 bits;

	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		bits = wqe->word2.rsvd_0;
	} else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE)) {
		bits = work->word0.pip.cn68xx.unused1;
	} else {
		bits = work->word0.pip.cn38xx.unused;
	}

	return bits;
}

static inline void cvmx_wqe_set_unused8(cvmx_wqe_t *work, u8 v)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		wqe->word2.rsvd_0 = v;
	} else if (octeon_has_feature(OCTEON_FEATURE_CN68XX_WQE)) {
		work->word0.pip.cn68xx.unused1 = v;
	} else {
		work->word0.pip.cn38xx.unused = v;
	}
}

static inline u8 cvmx_wqe_get_user_flags(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		return work->word0.pki.rsvd_2;
	else
		return 0;
}

static inline void cvmx_wqe_set_user_flags(cvmx_wqe_t *work, u8 v)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		work->word0.pki.rsvd_2 = v;
}

static inline int cvmx_wqe_get_channel(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		return (work->word0.pki.channel);
	else
		return cvmx_wqe_get_port(work);
}

static inline void cvmx_wqe_set_channel(cvmx_wqe_t *work, int channel)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		work->word0.pki.channel = channel;
	else
		debug("%s: ERROR: not supported for model\n", __func__);
}

static inline int cvmx_wqe_get_aura(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		return (work->word0.pki.aura);
	else
		return (work->packet_ptr.s.pool);
}

static inline void cvmx_wqe_set_aura(cvmx_wqe_t *work, int aura)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		work->word0.pki.aura = aura;
	else
		work->packet_ptr.s.pool = aura;
}

static inline int cvmx_wqe_get_style(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		return (work->word0.pki.style);
	return 0;
}

static inline void cvmx_wqe_set_style(cvmx_wqe_t *work, int style)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE))
		work->word0.pki.style = style;
}

static inline int cvmx_wqe_is_l3_ip(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;
		/* Match all 4 values for v4/v6 with.without options */
		if ((wqe->word2.lc_hdr_type & 0x1c) == CVMX_PKI_LTYPE_E_IP4)
			return 1;
		if ((wqe->word2.le_hdr_type & 0x1c) == CVMX_PKI_LTYPE_E_IP4)
			return 1;
		return 0;
	} else {
		return !work->word2.s_cn38xx.not_IP;
	}
}

static inline int cvmx_wqe_is_l3_ipv4(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;
		/* Match 2 values - with/wotuout options */
		if ((wqe->word2.lc_hdr_type & 0x1e) == CVMX_PKI_LTYPE_E_IP4)
			return 1;
		if ((wqe->word2.le_hdr_type & 0x1e) == CVMX_PKI_LTYPE_E_IP4)
			return 1;
		return 0;
	} else {
		return (!work->word2.s_cn38xx.not_IP &&
			!work->word2.s_cn38xx.is_v6);
	}
}

static inline int cvmx_wqe_is_l3_ipv6(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;
		/* Match 2 values - with/wotuout options */
		if ((wqe->word2.lc_hdr_type & 0x1e) == CVMX_PKI_LTYPE_E_IP6)
			return 1;
		if ((wqe->word2.le_hdr_type & 0x1e) == CVMX_PKI_LTYPE_E_IP6)
			return 1;
		return 0;
	} else {
		return (!work->word2.s_cn38xx.not_IP &&
			work->word2.s_cn38xx.is_v6);
	}
}

static inline bool cvmx_wqe_is_l4_udp_or_tcp(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (wqe->word2.lf_hdr_type == CVMX_PKI_LTYPE_E_TCP)
			return true;
		if (wqe->word2.lf_hdr_type == CVMX_PKI_LTYPE_E_UDP)
			return true;
		return false;
	}

	if (work->word2.s_cn38xx.not_IP)
		return false;

	return (work->word2.s_cn38xx.tcp_or_udp != 0);
}

static inline int cvmx_wqe_is_l2_bcast(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return wqe->word2.is_l2_bcast;
	} else {
		return work->word2.s_cn38xx.is_bcast;
	}
}

static inline int cvmx_wqe_is_l2_mcast(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return wqe->word2.is_l2_mcast;
	} else {
		return work->word2.s_cn38xx.is_mcast;
	}
}

static inline void cvmx_wqe_set_l2_bcast(cvmx_wqe_t *work, bool bcast)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		wqe->word2.is_l2_bcast = bcast;
	} else {
		work->word2.s_cn38xx.is_bcast = bcast;
	}
}

static inline void cvmx_wqe_set_l2_mcast(cvmx_wqe_t *work, bool mcast)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		wqe->word2.is_l2_mcast = mcast;
	} else {
		work->word2.s_cn38xx.is_mcast = mcast;
	}
}

static inline int cvmx_wqe_is_l3_bcast(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return wqe->word2.is_l3_bcast;
	}
	debug("%s: ERROR: not supported for model\n", __func__);
	return 0;
}

static inline int cvmx_wqe_is_l3_mcast(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return wqe->word2.is_l3_mcast;
	}
	debug("%s: ERROR: not supported for model\n", __func__);
	return 0;
}

/**
 * This function returns is there was IP error detected in packet.
 * For 78XX it does not flag ipv4 options and ipv6 extensions.
 * For older chips if PIP_GBL_CTL was proviosned to flag ip4_otions and
 * ipv6 extension, it will be flag them.
 * @param work	pointer to work queue entry
 * Return:	1 -- If IP error was found in packet
 *          0 -- If no IP error was found in packet.
 */
static inline int cvmx_wqe_is_ip_exception(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (wqe->word2.err_level == CVMX_PKI_ERRLEV_E_LC)
			return 1;
		else
			return 0;
	}

	return work->word2.s.IP_exc;
}

static inline int cvmx_wqe_is_l4_error(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (wqe->word2.err_level == CVMX_PKI_ERRLEV_E_LF)
			return 1;
		else
			return 0;
	} else {
		return work->word2.s.L4_error;
	}
}

static inline void cvmx_wqe_set_vlan(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		wqe->word2.vlan_valid = set;
	} else {
		work->word2.s.vlan_valid = set;
	}
}

static inline int cvmx_wqe_is_vlan(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return wqe->word2.vlan_valid;
	} else {
		return work->word2.s.vlan_valid;
	}
}

static inline int cvmx_wqe_is_vlan_stacked(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return wqe->word2.vlan_stacked;
	} else {
		return work->word2.s.vlan_stacked;
	}
}

/**
 * Extract packet data buffer pointer from work queue entry.
 *
 * Returns the legacy (Octeon1/Octeon2) buffer pointer structure
 * for the linked buffer list.
 * On CN78XX, the native buffer pointer structure is converted into
 * the legacy format.
 * The legacy buf_ptr is then stored in the WQE, and word0 reserved
 * field is set to indicate that the buffer pointers were translated.
 * If the packet data is only found inside the work queue entry,
 * a standard buffer pointer structure is created for it.
 */
cvmx_buf_ptr_t cvmx_wqe_get_packet_ptr(cvmx_wqe_t *work);

static inline int cvmx_wqe_get_bufs(cvmx_wqe_t *work)
{
	int bufs;

	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		bufs = work->word0.pki.bufs;
	} else {
		/* Adjust for packet-in-WQE cases */
		if (cvmx_unlikely(work->word2.s_cn38xx.bufs == 0 && !work->word2.s.software))
			(void)cvmx_wqe_get_packet_ptr(work);
		bufs = work->word2.s_cn38xx.bufs;
	}
	return bufs;
}

/**
 * Free Work Queue Entry memory
 *
 * Will return the WQE buffer to its pool, unless the WQE contains
 * non-redundant packet data.
 * This function is intended to be called AFTER the packet data
 * has been passed along to PKO for transmission and release.
 * It can also follow a call to cvmx_helper_free_packet_data()
 * to release the WQE after associated data was released.
 */
void cvmx_wqe_free(cvmx_wqe_t *work);

/**
 * Check if a work entry has been intiated by software
 *
 */
static inline bool cvmx_wqe_is_soft(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return wqe->word2.software;
	} else {
		return work->word2.s.software;
	}
}

/**
 * Allocate a work-queue entry for delivering software-initiated
 * event notifications.
 * The application data is copied into the work-queue entry,
 * if the space is sufficient.
 */
cvmx_wqe_t *cvmx_wqe_soft_create(void *data_p, unsigned int data_sz);

/* Errata (PKI-20776) PKI_BUFLINK_S's are endian-swapped
 * CN78XX pass 1.x has a bug where the packet pointer in each segment is
 * written in the opposite endianness of the configured mode. Fix these here.
 */
static inline void cvmx_wqe_pki_errata_20776(cvmx_wqe_t *work)
{
	cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

	if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) && !wqe->pki_errata20776) {
		u64 bufs;
		cvmx_buf_ptr_pki_t buffer_next;

		bufs = wqe->word0.bufs;
		buffer_next = wqe->packet_ptr;
		while (bufs > 1) {
			cvmx_buf_ptr_pki_t next;
			void *nextaddr = cvmx_phys_to_ptr(buffer_next.addr - 8);

			memcpy(&next, nextaddr, sizeof(next));
			next.u64 = __builtin_bswap64(next.u64);
			memcpy(nextaddr, &next, sizeof(next));
			buffer_next = next;
			bufs--;
		}
		wqe->pki_errata20776 = 1;
	}
}

/**
 * @INTERNAL
 *
 * Extract the native PKI-specific buffer pointer from WQE.
 *
 * NOTE: Provisional, may be superceded.
 */
static inline cvmx_buf_ptr_pki_t cvmx_wqe_get_pki_pkt_ptr(cvmx_wqe_t *work)
{
	cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

	if (!octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_buf_ptr_pki_t x = { 0 };
		return x;
	}

	cvmx_wqe_pki_errata_20776(work);
	return wqe->packet_ptr;
}

/**
 * Set the buffer segment count for a packet.
 *
 * Return: Returns the actual resulting value in the WQE fielda
 *
 */
static inline unsigned int cvmx_wqe_set_bufs(cvmx_wqe_t *work, unsigned int bufs)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		work->word0.pki.bufs = bufs;
		return work->word0.pki.bufs;
	}

	work->word2.s.bufs = bufs;
	return work->word2.s.bufs;
}

/**
 * Get the offset of Layer-3 header,
 * only supported when Layer-3 protocol is IPv4 or IPv6.
 *
 * Return: Returns the offset, or 0 if the offset is not known or unsupported.
 *
 * FIXME: Assuming word4 is present.
 */
static inline unsigned int cvmx_wqe_get_l3_offset(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;
		/* Match 4 values: IPv4/v6 w/wo options */
		if ((wqe->word2.lc_hdr_type & 0x1c) == CVMX_PKI_LTYPE_E_IP4)
			return wqe->word4.ptr_layer_c;
	} else {
		return work->word2.s.ip_offset;
	}

	return 0;
}

/**
 * Set the offset of Layer-3 header in a packet.
 * Typically used when an IP packet is generated by software
 * or when the Layer-2 header length is modified, and
 * a subsequent recalculation of checksums is anticipated.
 *
 * Return: Returns the actual value of the work entry offset field.
 *
 * FIXME: Assuming word4 is present.
 */
static inline unsigned int cvmx_wqe_set_l3_offset(cvmx_wqe_t *work, unsigned int ip_off)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;
		/* Match 4 values: IPv4/v6 w/wo options */
		if ((wqe->word2.lc_hdr_type & 0x1c) == CVMX_PKI_LTYPE_E_IP4)
			wqe->word4.ptr_layer_c = ip_off;
	} else {
		work->word2.s.ip_offset = ip_off;
	}

	return cvmx_wqe_get_l3_offset(work);
}

/**
 * Set the indication that the packet contains a IPv4 Layer-3 * header.
 * Use 'cvmx_wqe_set_l3_ipv6()' if the protocol is IPv6.
 * When 'set' is false, the call will result in an indication
 * that the Layer-3 protocol is neither IPv4 nor IPv6.
 *
 * FIXME: Add IPV4_OPT handling based on L3 header length.
 */
static inline void cvmx_wqe_set_l3_ipv4(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (set)
			wqe->word2.lc_hdr_type = CVMX_PKI_LTYPE_E_IP4;
		else
			wqe->word2.lc_hdr_type = CVMX_PKI_LTYPE_E_NONE;
	} else {
		work->word2.s.not_IP = !set;
		if (set)
			work->word2.s_cn38xx.is_v6 = 0;
	}
}

/**
 * Set packet Layer-3 protocol to IPv6.
 *
 * FIXME: Add IPV6_OPT handling based on presence of extended headers.
 */
static inline void cvmx_wqe_set_l3_ipv6(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (set)
			wqe->word2.lc_hdr_type = CVMX_PKI_LTYPE_E_IP6;
		else
			wqe->word2.lc_hdr_type = CVMX_PKI_LTYPE_E_NONE;
	} else {
		work->word2.s_cn38xx.not_IP = !set;
		if (set)
			work->word2.s_cn38xx.is_v6 = 1;
	}
}

/**
 * Set a packet Layer-4 protocol type to UDP.
 */
static inline void cvmx_wqe_set_l4_udp(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (set)
			wqe->word2.lf_hdr_type = CVMX_PKI_LTYPE_E_UDP;
		else
			wqe->word2.lf_hdr_type = CVMX_PKI_LTYPE_E_NONE;
	} else {
		if (!work->word2.s_cn38xx.not_IP)
			work->word2.s_cn38xx.tcp_or_udp = set;
	}
}

/**
 * Set a packet Layer-4 protocol type to TCP.
 */
static inline void cvmx_wqe_set_l4_tcp(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (set)
			wqe->word2.lf_hdr_type = CVMX_PKI_LTYPE_E_TCP;
		else
			wqe->word2.lf_hdr_type = CVMX_PKI_LTYPE_E_NONE;
	} else {
		if (!work->word2.s_cn38xx.not_IP)
			work->word2.s_cn38xx.tcp_or_udp = set;
	}
}

/**
 * Set the "software" flag in a work entry.
 */
static inline void cvmx_wqe_set_soft(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		wqe->word2.software = set;
	} else {
		work->word2.s.software = set;
	}
}

/**
 * Return true if the packet is an IP fragment.
 */
static inline bool cvmx_wqe_is_l3_frag(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return (wqe->word2.is_frag != 0);
	}

	if (!work->word2.s_cn38xx.not_IP)
		return (work->word2.s.is_frag != 0);

	return false;
}

/**
 * Set the indicator that the packet is an fragmented IP packet.
 */
static inline void cvmx_wqe_set_l3_frag(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		wqe->word2.is_frag = set;
	} else {
		if (!work->word2.s_cn38xx.not_IP)
			work->word2.s.is_frag = set;
	}
}

/**
 * Set the packet Layer-3 protocol to RARP.
 */
static inline void cvmx_wqe_set_l3_rarp(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (set)
			wqe->word2.lc_hdr_type = CVMX_PKI_LTYPE_E_RARP;
		else
			wqe->word2.lc_hdr_type = CVMX_PKI_LTYPE_E_NONE;
	} else {
		work->word2.snoip.is_rarp = set;
	}
}

/**
 * Set the packet Layer-3 protocol to ARP.
 */
static inline void cvmx_wqe_set_l3_arp(cvmx_wqe_t *work, bool set)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		if (set)
			wqe->word2.lc_hdr_type = CVMX_PKI_LTYPE_E_ARP;
		else
			wqe->word2.lc_hdr_type = CVMX_PKI_LTYPE_E_NONE;
	} else {
		work->word2.snoip.is_arp = set;
	}
}

/**
 * Return true if the packet Layer-3 protocol is ARP.
 */
static inline bool cvmx_wqe_is_l3_arp(cvmx_wqe_t *work)
{
	if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) {
		cvmx_wqe_78xx_t *wqe = (cvmx_wqe_78xx_t *)work;

		return (wqe->word2.lc_hdr_type == CVMX_PKI_LTYPE_E_ARP);
	}

	if (work->word2.s_cn38xx.not_IP)
		return (work->word2.snoip.is_arp != 0);

	return false;
}

#endif /* __CVMX_WQE_H__ */