1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
3 */
4
5 #ifndef __OCTEONTX_PKI_H__
6 #define __OCTEONTX_PKI_H__
7
8 #include <stdint.h>
9
10 #include <octeontx_mbox.h>
11
12 #define OCTEONTX_PKI_COPROC 5
13
14 /* PKI messages */
15
16 #define MBOX_PKI_PORT_OPEN 1
17 #define MBOX_PKI_PORT_START 2
18 #define MBOX_PKI_PORT_STOP 3
19 #define MBOX_PKI_PORT_CLOSE 4
20 #define MBOX_PKI_PORT_CONFIG 5
21 #define MBOX_PKI_PORT_OPT_PARSER_CONFIG 6
22 #define MBOX_PKI_PORT_CUSTOM_PARSER_CONFIG 7
23 #define MBOX_PKI_PORT_PKTBUF_CONFIG 8
24 #define MBOX_PKI_PORT_HASH_CONFIG 9
25 #define MBOX_PKI_PORT_ERRCHK_CONFIG 10
26 #define MBOX_PKI_PORT_CREATE_QOS 11
27 #define MBOX_PKI_PORT_MODIFY_QOS 12
28 #define MBOX_PKI_PORT_DELETE_QOS 13
29 #define MBOX_PKI_PORT_PKTDROP_CONFIG 14
30 #define MBOX_PKI_PORT_WQE_GEN_CONFIG 15
31 #define MBOX_PKI_BACKPRESSURE_CONFIG 16
32 #define MBOX_PKI_PORT_GET_STATS 17
33 #define MBOX_PKI_PORT_RESET_STATS 18
34 #define MBOX_PKI_GET_PORT_CONFIG 19
35 #define MBOX_PKI_GET_PORT_QOS_CONFIG 20
36 #define MBOX_PKI_PORT_ALLOC_QPG 21
37 #define MBOX_PKI_PORT_FREE_QPG 22
38 #define MBOX_PKI_SET_PORT_CONFIG 23
39 #define MBOX_PKI_PORT_VLAN_FILTER_CONFIG 24
40 #define MBOX_PKI_PORT_VLAN_FILTER_ENTRY_CONFIG 25
41
42 #define MBOX_PKI_MAX_QOS_ENTRY 64
43
44 /* PKI maximum constants */
45 #define PKI_VF_MAX (32)
46 #define PKI_MAX_PKTLEN (32768)
47
48 /* Interface types: */
49 enum {
50 OCTTX_PORT_TYPE_NET, /* Network interface ports */
51 OCTTX_PORT_TYPE_INT, /* CPU internal interface ports */
52 OCTTX_PORT_TYPE_PCI, /* DPI/PCIe interface ports */
53 OCTTX_PORT_TYPE_MAX
54 };
55
56 /* pki pkind parse mode */
57 enum {
58 PKI_PARSE_LA_TO_LG = 0,
59 PKI_PARSE_LB_TO_LG = 1,
60 PKI_PARSE_LC_TO_LG = 3,
61 PKI_PARSE_LG = 0x3f,
62 PKI_PARSE_NOTHING = 0x7f
63 };
64
65 /* CACHE MODE*/
66 enum {
67 PKI_OPC_MODE_STT = 0LL,
68 PKI_OPC_MODE_STF = 1LL,
69 PKI_OPC_MODE_STF1_STT = 2LL,
70 PKI_OPC_MODE_STF2_STT = 3LL
71 };
72
73 /* PKI QPG QOS*/
74 enum {
75 PKI_QPG_QOS_NONE = 0,
76 PKI_QPG_QOS_VLAN,
77 PKI_QPG_QOS_MPLS,
78 PKI_QPG_QOS_DSA_SRC,
79 PKI_QPG_QOS_DIFFSERV,
80 PKI_QPG_QOS_HIGIG,
81 };
82
83 /* pki port config */
84 typedef struct pki_port_type {
85 uint8_t port_type;
86 } pki_port_type_t;
87
88 /* pki port config */
89 typedef struct pki_port_cfg {
90 uint8_t port_type;
91 struct {
92 uint8_t fcs_pres:1;
93 uint8_t fcs_skip:1;
94 uint8_t parse_mode:1;
95 uint8_t mpls_parse:1;
96 uint8_t inst_hdr_parse:1;
97 uint8_t fulc_parse:1;
98 uint8_t dsa_parse:1;
99 uint8_t hg2_parse:1;
100 uint8_t hg_parse:1;
101 } mmask;
102 uint8_t fcs_pres;
103 uint8_t fcs_skip;
104 uint8_t parse_mode;
105 uint8_t mpls_parse;
106 uint8_t inst_hdr_parse;
107 uint8_t fulc_parse;
108 uint8_t dsa_parse;
109 uint8_t hg2_parse;
110 uint8_t hg_parse;
111 } pki_prt_cfg_t;
112
113
114 /* pki Flow/style packet buffer config */
115 typedef struct pki_port_pktbuf_cfg {
116 uint8_t port_type;
117 struct {
118 uint16_t f_mbuff_size:1;
119 uint16_t f_wqe_skip:1;
120 uint16_t f_first_skip:1;
121 uint16_t f_later_skip:1;
122 uint16_t f_pkt_outside_wqe:1;
123 uint16_t f_wqe_endian:1;
124 uint16_t f_cache_mode:1;
125 } mmask;
126 uint16_t mbuff_size;
127 uint16_t wqe_skip;
128 uint16_t first_skip;
129 uint16_t later_skip;
130 uint8_t pkt_outside_wqe;
131 uint8_t wqe_endian;
132 uint8_t cache_mode;
133 } pki_pktbuf_cfg_t;
134
135 /* pki flow/style tag config */
136 typedef struct pki_port_hash_cfg {
137 uint8_t port_type;
138 uint32_t tag_slf:1;
139 uint32_t tag_sle:1;
140 uint32_t tag_sld:1;
141 uint32_t tag_slc:1;
142 uint32_t tag_dlf:1;
143 uint32_t tag_dle:1;
144 uint32_t tag_dld:1;
145 uint32_t tag_dlc:1;
146 uint32_t tag_prt:1;
147 uint32_t tag_vlan0:1;
148 uint32_t tag_vlan1:1;
149 uint32_t tag_ip_pctl:1;
150 uint32_t tag_sync:1;
151 uint32_t tag_spi:1;
152 uint32_t tag_gtp:1;
153 uint32_t tag_vni:1;
154 } pki_hash_cfg_t;
155
156 /* pki flow/style errcheck config */
157 typedef struct pki_port_errcheck_cfg {
158 uint8_t port_type;
159 struct {
160 uint32_t f_ip6_udp_opt:1;
161 uint32_t f_lenerr_en:1;
162 uint32_t f_maxerr_en:1;
163 uint32_t f_minerr_en:1;
164 uint32_t f_fcs_chk:1;
165 uint32_t f_fcs_strip:1;
166 uint32_t f_len_lf:1;
167 uint32_t f_len_le:1;
168 uint32_t f_len_ld:1;
169 uint32_t f_len_lc:1;
170 uint32_t f_csum_lf:1;
171 uint32_t f_csum_le:1;
172 uint32_t f_csum_ld:1;
173 uint32_t f_csum_lc:1;
174 uint32_t f_min_frame_len;
175 uint32_t f_max_frame_len;
176 } mmask;
177 uint64_t ip6_udp_opt:1;
178 uint64_t lenerr_en:1;
179 uint64_t maxerr_en:1;
180 uint64_t minerr_en:1;
181 uint64_t fcs_chk:1;
182 uint64_t fcs_strip:1;
183 uint64_t len_lf:1;
184 uint64_t len_le:1;
185 uint64_t len_ld:1;
186 uint64_t len_lc:1;
187 uint64_t csum_lf:1;
188 uint64_t csum_le:1;
189 uint64_t csum_ld:1;
190 uint64_t csum_lc:1;
191 uint64_t min_frame_len;
192 uint64_t max_frame_len;
193 } pki_errchk_cfg_t;
194
195 struct pki_qos_entry {
196 uint16_t port_add;
197 uint16_t ggrp_ok;
198 uint16_t ggrp_bad;
199 uint16_t gaura;
200 uint8_t grptag_ok;
201 uint8_t grptag_bad;
202 uint8_t ena_red;
203 uint8_t ena_drop;
204 uint8_t tag_type;
205 };
206
207 #define PKO_MAX_QOS_ENTRY 64
208
209 /* pki flow/style enable qos */
210 typedef struct pki_port_create_qos {
211 uint8_t port_type;
212 uint8_t qpg_qos;
213 uint8_t num_entry;
214 uint8_t tag_type;
215 uint8_t drop_policy;
216 struct pki_qos_entry qos_entry[PKO_MAX_QOS_ENTRY];
217 } pki_qos_cfg_t;
218
219 /* pki flow/style enable qos */
220 typedef struct pki_port_delete_qos_entry {
221 uint8_t port_type;
222 uint16_t index;
223 } pki_del_qos_t;
224
225 /* pki flow/style enable qos */
226 typedef struct pki_port_modify_qos_entry {
227 uint8_t port_type;
228 uint16_t index;
229 struct {
230 uint8_t f_port_add:1;
231 uint8_t f_grp_ok:1;
232 uint8_t f_grp_bad:1;
233 uint8_t f_gaura:1;
234 uint8_t f_grptag_ok:1;
235 uint8_t f_grptag_bad:1;
236 uint8_t f_tag_type:1;
237 } mmask;
238 struct pki_qos_entry qos_entry;
239 } pki_mod_qos_t;
240
241 /* pki port VLAN filter config */
242 typedef struct pki_port_vlan_filter_config {
243 uint8_t port_type; /* OCTTX_PORT_TYPE_[NET/INT/PCI] */
244 uint8_t fltr_conf; /* '1' to enable & '0' to disable */
245 } pki_port_vlan_filter_config_t;
246
247 /* pki port VLAN filter entry config */
248 typedef struct pki_port_vlan_filter_entry_config {
249 uint8_t port_type; /* OCTTX_PORT_TYPE_[NET/INT/PCI] */
250 uint8_t entry_conf; /* '1' to add & '0' to remove */
251 uint16_t vlan_tpid; /* in host byte-order */
252 uint16_t vlan_id; /* in host byte-order */
253 } pki_port_vlan_filter_entry_config_t;
254
255 static inline int
octeontx_pki_port_modify_qos(int port,pki_mod_qos_t * qos_cfg)256 octeontx_pki_port_modify_qos(int port, pki_mod_qos_t *qos_cfg)
257 {
258 struct octeontx_mbox_hdr hdr;
259 int res;
260
261 pki_mod_qos_t q_cfg = *(pki_mod_qos_t *)qos_cfg;
262 int len = sizeof(pki_mod_qos_t);
263
264 hdr.coproc = OCTEONTX_PKI_COPROC;
265 hdr.msg = MBOX_PKI_PORT_MODIFY_QOS;
266 hdr.vfid = port;
267
268 res = octeontx_mbox_send(&hdr, &q_cfg, len, NULL, 0);
269 if (res < 0)
270 return -EACCES;
271
272 return res;
273 }
274
275 static inline int
octeontx_pki_port_delete_qos(int port,pki_del_qos_t * qos_cfg)276 octeontx_pki_port_delete_qos(int port, pki_del_qos_t *qos_cfg)
277 {
278 struct octeontx_mbox_hdr hdr;
279 int res;
280
281 pki_del_qos_t q_cfg = *(pki_del_qos_t *)qos_cfg;
282 int len = sizeof(pki_del_qos_t);
283
284 hdr.coproc = OCTEONTX_PKI_COPROC;
285 hdr.msg = MBOX_PKI_PORT_DELETE_QOS;
286 hdr.vfid = port;
287
288 res = octeontx_mbox_send(&hdr, &q_cfg, len, NULL, 0);
289 if (res < 0)
290 return -EACCES;
291
292 return res;
293 }
294
295 static inline int
octeontx_pki_port_close(int port)296 octeontx_pki_port_close(int port)
297 {
298 struct octeontx_mbox_hdr hdr;
299 int res;
300
301 pki_port_type_t ptype;
302 int len = sizeof(pki_port_type_t);
303 memset(&ptype, 0, len);
304 ptype.port_type = OCTTX_PORT_TYPE_NET;
305
306 hdr.coproc = OCTEONTX_PKI_COPROC;
307 hdr.msg = MBOX_PKI_PORT_CLOSE;
308 hdr.vfid = port;
309
310 res = octeontx_mbox_send(&hdr, &ptype, len, NULL, 0);
311 if (res < 0)
312 return -EACCES;
313
314 return res;
315 }
316
317 static inline int
octeontx_pki_port_start(int port)318 octeontx_pki_port_start(int port)
319 {
320 struct octeontx_mbox_hdr hdr;
321 int res;
322
323 pki_port_type_t ptype;
324 int len = sizeof(pki_port_type_t);
325 memset(&ptype, 0, len);
326 ptype.port_type = OCTTX_PORT_TYPE_NET;
327
328 hdr.coproc = OCTEONTX_PKI_COPROC;
329 hdr.msg = MBOX_PKI_PORT_START;
330 hdr.vfid = port;
331
332 res = octeontx_mbox_send(&hdr, &ptype, len, NULL, 0);
333 if (res < 0)
334 return -EACCES;
335
336 return res;
337 }
338
339 static inline int
octeontx_pki_port_stop(int port)340 octeontx_pki_port_stop(int port)
341 {
342 struct octeontx_mbox_hdr hdr;
343 int res;
344
345 pki_port_type_t ptype;
346 int len = sizeof(pki_port_type_t);
347 memset(&ptype, 0, len);
348 ptype.port_type = OCTTX_PORT_TYPE_NET;
349
350 hdr.coproc = OCTEONTX_PKI_COPROC;
351 hdr.msg = MBOX_PKI_PORT_STOP;
352 hdr.vfid = port;
353
354 res = octeontx_mbox_send(&hdr, &ptype, len, NULL, 0);
355 if (res < 0)
356 return -EACCES;
357
358 return res;
359 }
360
361 int octeontx_pki_port_open(int port);
362 int octeontx_pki_port_hash_config(int port, pki_hash_cfg_t *hash_cfg);
363 int octeontx_pki_port_pktbuf_config(int port, pki_pktbuf_cfg_t *buf_cfg);
364 int octeontx_pki_port_create_qos(int port, pki_qos_cfg_t *qos_cfg);
365 int octeontx_pki_port_errchk_config(int port, pki_errchk_cfg_t *cfg);
366 int octeontx_pki_port_vlan_fltr_config(int port,
367 pki_port_vlan_filter_config_t *fltr_cfg);
368 int octeontx_pki_port_vlan_fltr_entry_config(int port,
369 pki_port_vlan_filter_entry_config_t *entry_cfg);
370
371 #endif /* __OCTEONTX_PKI_H__ */
372