common/octeontx2: add build infrastructure and HW definition
[dpdk.git] / drivers / common / octeontx2 / hw / otx2_npc.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef __OTX2_NPC_HW_H__
6 #define __OTX2_NPC_HW_H__
7
8 /* Register offsets */
9
10 #define NPC_AF_CFG                                   (0x0ull)
11 #define NPC_AF_ACTIVE_PC                             (0x10ull)
12 #define NPC_AF_CONST                                 (0x20ull)
13 #define NPC_AF_CONST1                                (0x30ull)
14 #define NPC_AF_BLK_RST                               (0x40ull)
15 #define NPC_AF_MCAM_SCRUB_CTL                        (0xa0ull)
16 #define NPC_AF_KCAM_SCRUB_CTL                        (0xb0ull)
17 #define NPC_AF_KPUX_CFG(a)                           \
18         (0x500ull | (uint64_t)(a) << 3)
19 #define NPC_AF_PCK_CFG                               (0x600ull)
20 #define NPC_AF_PCK_DEF_OL2                           (0x610ull)
21 #define NPC_AF_PCK_DEF_OIP4                          (0x620ull)
22 #define NPC_AF_PCK_DEF_OIP6                          (0x630ull)
23 #define NPC_AF_PCK_DEF_IIP4                          (0x640ull)
24 #define NPC_AF_KEX_LDATAX_FLAGS_CFG(a)               \
25         (0x800ull | (uint64_t)(a) << 3)
26 #define NPC_AF_INTFX_KEX_CFG(a)                      \
27         (0x1010ull | (uint64_t)(a) << 8)
28 #define NPC_AF_PKINDX_ACTION0(a)                     \
29         (0x80000ull | (uint64_t)(a) << 6)
30 #define NPC_AF_PKINDX_ACTION1(a)                     \
31         (0x80008ull | (uint64_t)(a) << 6)
32 #define NPC_AF_PKINDX_CPI_DEFX(a, b)                 \
33         (0x80020ull | (uint64_t)(a) << 6 | (uint64_t)(b) << 3)
34 #define NPC_AF_KPUX_ENTRYX_CAMX(a, b, c)             \
35         (0x100000ull | (uint64_t)(a) << 14 | (uint64_t)(b) << 6 | \
36         (uint64_t)(c) << 3)
37 #define NPC_AF_KPUX_ENTRYX_ACTION0(a, b)             \
38         (0x100020ull | (uint64_t)(a) << 14 | (uint64_t)(b) << 6)
39 #define NPC_AF_KPUX_ENTRYX_ACTION1(a, b)             \
40         (0x100028ull | (uint64_t)(a) << 14 | (uint64_t)(b) << 6)
41 #define NPC_AF_KPUX_ENTRY_DISX(a, b)                 \
42         (0x180000ull | (uint64_t)(a) << 6 | (uint64_t)(b) << 3)
43 #define NPC_AF_CPIX_CFG(a)                           \
44         (0x200000ull | (uint64_t)(a) << 3)
45 #define NPC_AF_INTFX_LIDX_LTX_LDX_CFG(a, b, c, d)    \
46         (0x900000ull | (uint64_t)(a) << 16 | (uint64_t)(b) << 12 | \
47         (uint64_t)(c) << 5 | (uint64_t)(d) << 3)
48 #define NPC_AF_INTFX_LDATAX_FLAGSX_CFG(a, b, c)      \
49         (0x980000ull | (uint64_t)(a) << 16 | (uint64_t)(b) << 12 | \
50         (uint64_t)(c) << 3)
51 #define NPC_AF_MCAMEX_BANKX_CAMX_INTF(a, b, c)       \
52         (0x1000000ull | (uint64_t)(a) << 10 | (uint64_t)(b) << 6 | \
53         (uint64_t)(c) << 3)
54 #define NPC_AF_MCAMEX_BANKX_CAMX_W0(a, b, c)         \
55         (0x1000010ull | (uint64_t)(a) << 10 | (uint64_t)(b) << 6 | \
56         (uint64_t)(c) << 3)
57 #define NPC_AF_MCAMEX_BANKX_CAMX_W1(a, b, c)         \
58         (0x1000020ull | (uint64_t)(a) << 10 | (uint64_t)(b) << 6 | \
59         (uint64_t)(c) << 3)
60 #define NPC_AF_MCAMEX_BANKX_CFG(a, b)                \
61         (0x1800000ull | (uint64_t)(a) << 8 | (uint64_t)(b) << 4)
62 #define NPC_AF_MCAMEX_BANKX_STAT_ACT(a, b)           \
63         (0x1880000ull | (uint64_t)(a) << 8 | (uint64_t)(b) << 4)
64 #define NPC_AF_MATCH_STATX(a)                        \
65         (0x1880008ull | (uint64_t)(a) << 8)
66 #define NPC_AF_INTFX_MISS_STAT_ACT(a)                \
67         (0x1880040ull + (uint64_t)(a) * 0x8)
68 #define NPC_AF_MCAMEX_BANKX_ACTION(a, b)             \
69         (0x1900000ull | (uint64_t)(a) << 8 | (uint64_t)(b) << 4)
70 #define NPC_AF_MCAMEX_BANKX_TAG_ACT(a, b)            \
71         (0x1900008ull | (uint64_t)(a) << 8 | (uint64_t)(b) << 4)
72 #define NPC_AF_INTFX_MISS_ACT(a)                     \
73         (0x1a00000ull | (uint64_t)(a) << 4)
74 #define NPC_AF_INTFX_MISS_TAG_ACT(a)                 \
75         (0x1b00008ull | (uint64_t)(a) << 4)
76 #define NPC_AF_MCAM_BANKX_HITX(a, b)                 \
77         (0x1c80000ull | (uint64_t)(a) << 8 | (uint64_t)(b) << 4)
78 #define NPC_AF_LKUP_CTL                              (0x2000000ull)
79 #define NPC_AF_LKUP_DATAX(a)                         \
80         (0x2000200ull | (uint64_t)(a) << 4)
81 #define NPC_AF_LKUP_RESULTX(a)                       \
82         (0x2000400ull | (uint64_t)(a) << 4)
83 #define NPC_AF_INTFX_STAT(a)                         \
84         (0x2000800ull | (uint64_t)(a) << 4)
85 #define NPC_AF_DBG_CTL                               (0x3000000ull)
86 #define NPC_AF_DBG_STATUS                            (0x3000010ull)
87 #define NPC_AF_KPUX_DBG(a)                           \
88         (0x3000020ull | (uint64_t)(a) << 8)
89 #define NPC_AF_IKPU_ERR_CTL                          (0x3000080ull)
90 #define NPC_AF_KPUX_ERR_CTL(a)                       \
91         (0x30000a0ull | (uint64_t)(a) << 8)
92 #define NPC_AF_MCAM_DBG                              (0x3001000ull)
93 #define NPC_AF_DBG_DATAX(a)                          \
94         (0x3001400ull | (uint64_t)(a) << 4)
95 #define NPC_AF_DBG_RESULTX(a)                        \
96         (0x3001800ull | (uint64_t)(a) << 4)
97
98
99 /* Enum offsets */
100
101 #define NPC_INTF_NIX0_RX    (0x0ull)
102 #define NPC_INTF_NIX0_TX    (0x1ull)
103
104 #define NPC_LKUPOP_PKT      (0x0ull)
105 #define NPC_LKUPOP_KEY      (0x1ull)
106
107 #define NPC_MCAM_KEY_X1     (0x0ull)
108 #define NPC_MCAM_KEY_X2     (0x1ull)
109 #define NPC_MCAM_KEY_X4     (0x2ull)
110
111 enum NPC_ERRLEV_E {
112         NPC_ERRLEV_RE = 0,
113         NPC_ERRLEV_LA = 1,
114         NPC_ERRLEV_LB = 2,
115         NPC_ERRLEV_LC = 3,
116         NPC_ERRLEV_LD = 4,
117         NPC_ERRLEV_LE = 5,
118         NPC_ERRLEV_LF = 6,
119         NPC_ERRLEV_LG = 7,
120         NPC_ERRLEV_LH = 8,
121         NPC_ERRLEV_R9 = 9,
122         NPC_ERRLEV_R10 = 10,
123         NPC_ERRLEV_R11 = 11,
124         NPC_ERRLEV_R12 = 12,
125         NPC_ERRLEV_R13 = 13,
126         NPC_ERRLEV_R14 = 14,
127         NPC_ERRLEV_NIX = 15,
128         NPC_ERRLEV_ENUM_LAST = 16,
129 };
130
131 enum npc_kpu_err_code {
132         NPC_EC_NOERR = 0, /* has to be zero */
133         NPC_EC_UNK,
134         NPC_EC_IH_LENGTH,
135         NPC_EC_L2_K1,
136         NPC_EC_L2_K2,
137         NPC_EC_L2_K3,
138         NPC_EC_L2_K3_ETYPE_UNK,
139         NPC_EC_L2_K4,
140         NPC_EC_MPLS_2MANY,
141         NPC_EC_MPLS_UNK,
142         NPC_EC_NSH_UNK,
143         NPC_EC_IP_TTL_0,
144         NPC_EC_IP_FRAG_OFFSET_1,
145         NPC_EC_IP_VER,
146         NPC_EC_IP6_HOP_0,
147         NPC_EC_IP6_VER,
148         NPC_EC_TCP_FLAGS_FIN_ONLY,
149         NPC_EC_TCP_FLAGS_ZERO,
150         NPC_EC_TCP_FLAGS_RST_FIN,
151         NPC_EC_TCP_FLAGS_URG_SYN,
152         NPC_EC_TCP_FLAGS_RST_SYN,
153         NPC_EC_TCP_FLAGS_SYN_FIN,
154         NPC_EC_VXLAN,
155         NPC_EC_NVGRE,
156         NPC_EC_GRE,
157         NPC_EC_GRE_VER1,
158         NPC_EC_L4,
159         NPC_EC_OIP4_CSUM,
160         NPC_EC_IIP4_CSUM,
161         NPC_EC_LAST /* has to be the last item */
162 };
163
164 enum NPC_LID_E {
165         NPC_LID_LA = 0,
166         NPC_LID_LB,
167         NPC_LID_LC,
168         NPC_LID_LD,
169         NPC_LID_LE,
170         NPC_LID_LF,
171         NPC_LID_LG,
172         NPC_LID_LH,
173 };
174
175 #define NPC_LT_NA 0
176
177 enum npc_kpu_la_ltype {
178         NPC_LT_LA_8023 = 1,
179         NPC_LT_LA_ETHER,
180         NPC_LT_LA_IH_NIX_ETHER,
181         NPC_LT_LA_IH_8_ETHER,
182         NPC_LT_LA_IH_4_ETHER,
183         NPC_LT_LA_IH_2_ETHER,
184 };
185
186 enum npc_kpu_lb_ltype {
187         NPC_LT_LB_ETAG = 1,
188         NPC_LT_LB_CTAG,
189         NPC_LT_LB_STAG,
190         NPC_LT_LB_BTAG,
191         NPC_LT_LB_QINQ,
192         NPC_LT_LB_ITAG,
193 };
194
195 enum npc_kpu_lc_ltype {
196         NPC_LT_LC_IP = 1,
197         NPC_LT_LC_IP_OPT,
198         NPC_LT_LC_IP6,
199         NPC_LT_LC_IP6_EXT,
200         NPC_LT_LC_ARP,
201         NPC_LT_LC_RARP,
202         NPC_LT_LC_MPLS,
203         NPC_LT_LC_NSH,
204         NPC_LT_LC_PTP,
205         NPC_LT_LC_FCOE,
206 };
207
208 /* Don't modify Ltypes upto SCTP, otherwise it will
209  * effect flow tag calculation and thus RSS.
210  */
211 enum npc_kpu_ld_ltype {
212         NPC_LT_LD_TCP = 1,
213         NPC_LT_LD_UDP,
214         NPC_LT_LD_ICMP,
215         NPC_LT_LD_SCTP,
216         NPC_LT_LD_ICMP6,
217         NPC_LT_LD_IGMP = 8,
218         NPC_LT_LD_ESP,
219         NPC_LT_LD_AH,
220         NPC_LT_LD_GRE,
221         NPC_LT_LD_NVGRE,
222         NPC_LT_LD_NSH,
223         NPC_LT_LD_TU_MPLS_IN_NSH,
224         NPC_LT_LD_TU_MPLS_IN_IP,
225 };
226
227 enum npc_kpu_le_ltype {
228         NPC_LT_LE_VXLAN = 1,
229         NPC_LT_LE_GENEVE,
230         NPC_LT_LE_GTPU = 4,
231         NPC_LT_LE_VXLANGPE,
232         NPC_LT_LE_GTPC,
233         NPC_LT_LE_NSH,
234         NPC_LT_LE_TU_MPLS_IN_GRE,
235         NPC_LT_LE_TU_NSH_IN_GRE,
236         NPC_LT_LE_TU_MPLS_IN_UDP,
237 };
238
239 enum npc_kpu_lf_ltype {
240         NPC_LT_LF_TU_ETHER = 1,
241         NPC_LT_LF_TU_PPP,
242         NPC_LT_LF_TU_MPLS_IN_VXLANGPE,
243         NPC_LT_LF_TU_NSH_IN_VXLANGPE,
244         NPC_LT_LF_TU_MPLS_IN_NSH,
245         NPC_LT_LF_TU_3RD_NSH,
246 };
247
248 /* Don't modify Ltypes upto SCTP, otherwise it will
249  * effect flow tag calculation and thus RSS.
250  */
251 enum npc_kpu_lg_ltype {
252         NPC_LT_LG_TU_IP = 1,
253         NPC_LT_LG_TU_IP6,
254         NPC_LT_LG_TU_ARP,
255         NPC_LT_LG_TU_ETHER_IN_NSH,
256 };
257
258 enum npc_kpu_lh_ltype {
259         NPC_LT_LH_TU_TCP = 1,
260         NPC_LT_LH_TU_UDP,
261         NPC_LT_LH_TU_ICMP,
262         NPC_LT_LH_TU_SCTP,
263         NPC_LT_LH_TU_ICMP6,
264         NPC_LT_LH_TU_IGMP = 8,
265         NPC_LT_LH_TU_ESP,
266         NPC_LT_LH_TU_AH,
267 };
268
269 /* Structures definitions */
270 struct npc_kpu_profile_cam {
271         uint8_t state;
272         uint8_t state_mask;
273         uint16_t dp0;
274         uint16_t dp0_mask;
275         uint16_t dp1;
276         uint16_t dp1_mask;
277         uint16_t dp2;
278         uint16_t dp2_mask;
279 };
280
281 struct npc_kpu_profile_action {
282         uint8_t errlev;
283         uint8_t errcode;
284         uint8_t dp0_offset;
285         uint8_t dp1_offset;
286         uint8_t dp2_offset;
287         uint8_t bypass_count;
288         uint8_t parse_done;
289         uint8_t next_state;
290         uint8_t ptr_advance;
291         uint8_t cap_ena;
292         uint8_t lid;
293         uint8_t ltype;
294         uint8_t flags;
295         uint8_t offset;
296         uint8_t mask;
297         uint8_t right;
298         uint8_t shift;
299 };
300
301 struct npc_kpu_profile {
302         int cam_entries;
303         int action_entries;
304         struct npc_kpu_profile_cam *cam;
305         struct npc_kpu_profile_action *action;
306 };
307
308 /* NPC KPU register formats */
309 struct npc_kpu_cam {
310         uint64_t dp0_data       : 16;
311         uint64_t dp1_data       : 16;
312         uint64_t dp2_data       : 16;
313         uint64_t state          : 8;
314         uint64_t rsvd_63_56     : 8;
315 };
316
317 struct npc_kpu_action0 {
318         uint64_t var_len_shift  : 3;
319         uint64_t var_len_right  : 1;
320         uint64_t var_len_mask   : 8;
321         uint64_t var_len_offset : 8;
322         uint64_t ptr_advance    : 8;
323         uint64_t capture_flags  : 8;
324         uint64_t capture_ltype  : 4;
325         uint64_t capture_lid    : 3;
326         uint64_t rsvd_43        : 1;
327         uint64_t next_state     : 8;
328         uint64_t parse_done     : 1;
329         uint64_t capture_ena    : 1;
330         uint64_t byp_count      : 3;
331         uint64_t rsvd_63_57     : 7;
332 };
333
334 struct npc_kpu_action1 {
335         uint64_t dp0_offset     : 8;
336         uint64_t dp1_offset     : 8;
337         uint64_t dp2_offset     : 8;
338         uint64_t errcode        : 8;
339         uint64_t errlev         : 4;
340         uint64_t rsvd_63_36     : 28;
341 };
342
343 struct npc_kpu_pkind_cpi_def {
344         uint64_t cpi_base       : 10;
345         uint64_t rsvd_11_10     : 2;
346         uint64_t add_shift      : 3;
347         uint64_t rsvd_15        : 1;
348         uint64_t add_mask       : 8;
349         uint64_t add_offset     : 8;
350         uint64_t flags_mask     : 8;
351         uint64_t flags_match    : 8;
352         uint64_t ltype_mask     : 4;
353         uint64_t ltype_match    : 4;
354         uint64_t lid            : 3;
355         uint64_t rsvd_62_59     : 4;
356         uint64_t ena            : 1;
357 };
358
359 struct nix_rx_action {
360         uint64_t op      :4;
361         uint64_t pf_func     :16;
362         uint64_t index       :20;
363         uint64_t match_id    :16;
364         uint64_t flow_key_alg    :5;
365         uint64_t rsvd_63_61  :3;
366 };
367
368 struct nix_tx_action {
369         uint64_t        op              :4;
370         uint64_t        rsvd_11_4       :8;
371         uint64_t        index           :20;
372         uint64_t        match_id        :16;
373         uint64_t        rsvd_63_48      :16;
374 };
375
376 /* NPC layer parse information structure */
377 struct npc_layer_info_s {
378         uint32_t lptr       : 8;
379         uint32_t flags      : 8;
380         uint32_t ltype      : 4;
381         uint32_t rsvd_31_20 : 12;
382 };
383
384 /* NPC layer mcam search key extract structure */
385 struct npc_layer_kex_s {
386         uint16_t flags      : 8;
387         uint16_t ltype      : 4;
388         uint16_t rsvd_15_12 : 4;
389 };
390
391 /* NPC mcam search key x1 structure */
392 struct npc_mcam_key_x1_s {
393         uint64_t intf         : 2;
394         uint64_t rsvd_63_2    : 62;
395         uint64_t kw0          : 64;  /* W1 */
396         uint64_t kw1          : 48;
397         uint64_t rsvd_191_176 : 16;
398 };
399
400 /* NPC mcam search key x2 structure */
401 struct npc_mcam_key_x2_s {
402         uint64_t intf         : 2;
403         uint64_t rsvd_63_2    : 62;
404         uint64_t kw0          : 64;  /* W1 */
405         uint64_t kw1          : 64;  /* W2 */
406         uint64_t kw2          : 64;  /* W3 */
407         uint64_t kw3          : 32;
408         uint64_t rsvd_319_288 : 32;
409 };
410
411 /* NPC mcam search key x4 structure */
412 struct npc_mcam_key_x4_s {
413         uint64_t intf      : 2;
414         uint64_t rsvd_63_2 : 62;
415         uint64_t kw0       : 64;     /* W1 */
416         uint64_t kw1       : 64;     /* W2 */
417         uint64_t kw2       : 64;     /* W3 */
418         uint64_t kw3       : 64;     /* W4 */
419         uint64_t kw4       : 64;     /* W5 */
420         uint64_t kw5       : 64;     /* W6 */
421         uint64_t kw6       : 64;     /* W7 */
422 };
423
424 /* NPC parse key extract structure */
425 struct npc_parse_kex_s {
426         uint64_t chan         : 12;
427         uint64_t errlev       : 4;
428         uint64_t errcode      : 8;
429         uint64_t l2m          : 1;
430         uint64_t l2b          : 1;
431         uint64_t l3m          : 1;
432         uint64_t l3b          : 1;
433         uint64_t la           : 12;
434         uint64_t lb           : 12;
435         uint64_t lc           : 12;
436         uint64_t ld           : 12;
437         uint64_t le           : 12;
438         uint64_t lf           : 12;
439         uint64_t lg           : 12;
440         uint64_t lh           : 12;
441         uint64_t rsvd_127_124 : 4;
442 };
443
444 /* NPC result structure */
445 struct npc_result_s {
446         uint64_t intf         : 2;
447         uint64_t pkind        : 6;
448         uint64_t chan         : 12;
449         uint64_t errlev       : 4;
450         uint64_t errcode      : 8;
451         uint64_t l2m          : 1;
452         uint64_t l2b          : 1;
453         uint64_t l3m          : 1;
454         uint64_t l3b          : 1;
455         uint64_t eoh_ptr      : 8;
456         uint64_t rsvd_63_44   : 20;
457         uint64_t action       : 64;  /* W1 */
458         uint64_t vtag_action  : 64;  /* W2 */
459         uint64_t la           : 20;
460         uint64_t lb           : 20;
461         uint64_t lc           : 20;
462         uint64_t rsvd_255_252 : 4;
463         uint64_t ld           : 20;
464         uint64_t le           : 20;
465         uint64_t lf           : 20;
466         uint64_t rsvd_319_316 : 4;
467         uint64_t lg           : 20;
468         uint64_t lh           : 20;
469         uint64_t rsvd_383_360 : 24;
470 };
471
472 #endif /* __OTX2_NPC_HW_H__ */