Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #ifndef __CN10K_IPSEC_LA_OPS_H__
6 : : #define __CN10K_IPSEC_LA_OPS_H__
7 : :
8 : : #include <rte_crypto_sym.h>
9 : : #include <rte_security.h>
10 : :
11 : : #include "roc_ie.h"
12 : :
13 : : #include "cn10k_cryptodev.h"
14 : : #include "cn10k_ipsec.h"
15 : : #include "cnxk_cryptodev.h"
16 : : #include "cnxk_cryptodev_ops.h"
17 : : #include "cnxk_sg.h"
18 : :
19 : : static inline void
20 : : ipsec_po_sa_iv_set(struct cn10k_sec_session *sess, struct rte_crypto_op *cop)
21 : : {
22 : : uint64_t *iv = &sess->sa.out_sa.iv.u64[0];
23 : : uint64_t *tmp_iv;
24 : :
25 : : memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 16);
26 : : tmp_iv = (uint64_t *)iv;
27 : : *tmp_iv = rte_be_to_cpu_64(*tmp_iv);
28 : :
29 : : tmp_iv = (uint64_t *)(iv + 1);
30 : : *tmp_iv = rte_be_to_cpu_64(*tmp_iv);
31 : : }
32 : :
33 : : static inline void
34 : : ipsec_po_sa_aes_gcm_iv_set(struct cn10k_sec_session *sess, struct rte_crypto_op *cop)
35 : : {
36 : : uint8_t *iv = &sess->sa.out_sa.iv.s.iv_dbg1[0];
37 : : uint32_t *tmp_iv;
38 : :
39 : : memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 4);
40 : : tmp_iv = (uint32_t *)iv;
41 : : *tmp_iv = rte_be_to_cpu_32(*tmp_iv);
42 : :
43 : : iv = &sess->sa.out_sa.iv.s.iv_dbg2[0];
44 : : memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset + 4), 4);
45 : : tmp_iv = (uint32_t *)iv;
46 : : *tmp_iv = rte_be_to_cpu_32(*tmp_iv);
47 : : }
48 : :
49 : : static __rte_always_inline int
50 : : process_outb_sa(struct roc_cpt_lf *lf, struct rte_crypto_op *cop, struct cn10k_sec_session *sess,
51 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
52 : : struct cpt_inst_s *inst, const bool is_sg_ver2)
53 : : {
54 : : struct rte_crypto_sym_op *sym_op = cop->sym;
55 : 0 : struct rte_mbuf *m_src = sym_op->m_src;
56 : 0 : uint64_t inst_w4_u64 = sess->inst.w4;
57 : : uint64_t dptr;
58 : :
59 : : RTE_SET_USED(lf);
60 : :
61 : : #ifdef LA_IPSEC_DEBUG
62 : : if (sess->sa.out_sa.w2.s.iv_src == ROC_IE_OT_SA_IV_SRC_FROM_SA) {
63 : : if (sess->sa.out_sa.w2.s.enc_type == ROC_IE_OT_SA_ENC_AES_GCM ||
64 : : sess->sa.out_sa.w2.s.enc_type == ROC_IE_OT_SA_ENC_AES_CCM ||
65 : : sess->sa.out_sa.w2.s.auth_type == ROC_IE_OT_SA_AUTH_AES_GMAC)
66 : : ipsec_po_sa_aes_gcm_iv_set(sess, cop);
67 : : else
68 : : ipsec_po_sa_iv_set(sess, cop);
69 : : }
70 : :
71 : : /* Trigger CTX reload to fetch new data from DRAM */
72 : : roc_cpt_lf_ctx_reload(lf, &sess->sa.out_sa);
73 : : rte_delay_ms(1);
74 : : #endif
75 : :
76 [ # # ]: 0 : if (m_src->ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
77 : 0 : inst_w4_u64 &= ~BIT_ULL(33);
78 : :
79 [ # # ]: 0 : if (m_src->ol_flags & RTE_MBUF_F_TX_L4_MASK)
80 : 0 : inst_w4_u64 &= ~BIT_ULL(32);
81 : :
82 [ # # ]: 0 : if (likely(m_src->next == NULL)) {
83 [ # # ]: 0 : if (unlikely(rte_pktmbuf_tailroom(m_src) < sess->max_extended_len)) {
84 : 0 : plt_dp_err("Not enough tail room");
85 : 0 : return -ENOMEM;
86 : : }
87 : :
88 : : /* Prepare CPT instruction */
89 : 0 : inst->w4.u64 = inst_w4_u64 | rte_pktmbuf_pkt_len(m_src);
90 : 0 : dptr = rte_pktmbuf_mtod(m_src, uint64_t);
91 : 0 : inst->dptr = dptr;
92 [ # # ]: 0 : } else if (is_sg_ver2 == false) {
93 : : struct roc_sglist_comp *scatter_comp, *gather_comp;
94 : : uint32_t g_size_bytes, s_size_bytes;
95 : : struct rte_mbuf *last_seg;
96 : : uint8_t *in_buffer;
97 : : uint32_t dlen;
98 : : void *m_data;
99 : : int i;
100 : :
101 : 0 : last_seg = rte_pktmbuf_lastseg(m_src);
102 : :
103 [ # # ]: 0 : if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
104 : 0 : plt_dp_err("Not enough tail room (required: %d, available: %d)",
105 : : sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
106 : 0 : return -ENOMEM;
107 : : }
108 : :
109 [ # # ]: 0 : m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
110 [ # # ]: 0 : if (unlikely(m_data == NULL)) {
111 : 0 : plt_dp_err("Error allocating meta buffer for request");
112 : 0 : return -ENOMEM;
113 : : }
114 : :
115 : : in_buffer = m_data;
116 : :
117 : 0 : ((uint16_t *)in_buffer)[0] = 0;
118 : 0 : ((uint16_t *)in_buffer)[1] = 0;
119 : :
120 : : /* Input Gather List */
121 : : i = 0;
122 : 0 : gather_comp = (struct roc_sglist_comp *)((uint8_t *)m_data + 8);
123 : :
124 : 0 : i = fill_ipsec_sg_comp_from_pkt(gather_comp, i, m_src);
125 [ # # ]: 0 : ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
126 : :
127 : 0 : g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
128 : :
129 : : /* Output Scatter List */
130 : 0 : last_seg->data_len += sess->max_extended_len;
131 : :
132 : : i = 0;
133 : 0 : scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
134 : :
135 : 0 : i = fill_ipsec_sg_comp_from_pkt(scatter_comp, i, m_src);
136 [ # # ]: 0 : ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
137 : :
138 : 0 : s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
139 : :
140 : 0 : dlen = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
141 : :
142 : 0 : inst->dptr = (uint64_t)in_buffer;
143 : :
144 : 0 : inst->w4.u64 = sess->inst.w4 | dlen;
145 : 0 : inst->w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
146 : : } else {
147 : : struct roc_sg2list_comp *scatter_comp, *gather_comp;
148 : : union cpt_inst_w5 cpt_inst_w5;
149 : : union cpt_inst_w6 cpt_inst_w6;
150 : : struct rte_mbuf *last_seg;
151 : : uint32_t g_size_bytes;
152 : : void *m_data;
153 : : int i;
154 : :
155 : 0 : last_seg = rte_pktmbuf_lastseg(m_src);
156 : :
157 [ # # ]: 0 : if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
158 : 0 : plt_dp_err("Not enough tail room (required: %d, available: %d)",
159 : : sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
160 : 0 : return -ENOMEM;
161 : : }
162 : :
163 [ # # ]: 0 : m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
164 [ # # ]: 0 : if (unlikely(m_data == NULL)) {
165 : 0 : plt_dp_err("Error allocating meta buffer for request");
166 : 0 : return -ENOMEM;
167 : : }
168 : :
169 : : /* Input Gather List */
170 : : i = 0;
171 : : gather_comp = (struct roc_sg2list_comp *)((uint8_t *)m_data);
172 : :
173 : 0 : i = fill_ipsec_sg2_comp_from_pkt(gather_comp, i, m_src);
174 : :
175 : 0 : cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
176 : 0 : g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
177 : :
178 : : /* Output Scatter List */
179 : 0 : last_seg->data_len += sess->max_extended_len;
180 : :
181 : : i = 0;
182 : 0 : scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
183 : :
184 : 0 : i = fill_ipsec_sg2_comp_from_pkt(scatter_comp, i, m_src);
185 : :
186 : 0 : cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
187 : :
188 : 0 : cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
189 : 0 : cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
190 : :
191 : 0 : inst->w5.u64 = cpt_inst_w5.u64;
192 : 0 : inst->w6.u64 = cpt_inst_w6.u64;
193 : 0 : inst->w4.u64 = sess->inst.w4 | rte_pktmbuf_pkt_len(m_src);
194 : 0 : inst->w4.s.opcode_major &= (~(ROC_IE_OT_INPLACE_BIT));
195 : : }
196 : :
197 : : return 0;
198 : : }
199 : :
200 : : static __rte_always_inline int
201 : : process_inb_sa(struct rte_crypto_op *cop, struct cn10k_sec_session *sess, struct cpt_inst_s *inst,
202 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
203 : : const bool is_sg_ver2)
204 : : {
205 : : struct rte_crypto_sym_op *sym_op = cop->sym;
206 : 0 : struct rte_mbuf *m_src = sym_op->m_src;
207 : : uint64_t dptr;
208 : :
209 [ # # ]: 0 : if (likely(m_src->next == NULL)) {
210 : : /* Prepare CPT instruction */
211 : 0 : inst->w4.u64 = sess->inst.w4 | rte_pktmbuf_pkt_len(m_src);
212 : 0 : dptr = rte_pktmbuf_mtod(m_src, uint64_t);
213 : 0 : inst->dptr = dptr;
214 : 0 : m_src->ol_flags |= (uint64_t)sess->ip_csum;
215 [ # # ]: 0 : } else if (is_sg_ver2 == false) {
216 : : struct roc_sglist_comp *scatter_comp, *gather_comp;
217 : : uint32_t g_size_bytes, s_size_bytes;
218 : : uint8_t *in_buffer;
219 : : uint32_t dlen;
220 : : void *m_data;
221 : : int i;
222 : :
223 [ # # ]: 0 : m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
224 [ # # ]: 0 : if (unlikely(m_data == NULL)) {
225 : 0 : plt_dp_err("Error allocating meta buffer for request");
226 : 0 : return -ENOMEM;
227 : : }
228 : :
229 : : in_buffer = m_data;
230 : :
231 : 0 : ((uint16_t *)in_buffer)[0] = 0;
232 : 0 : ((uint16_t *)in_buffer)[1] = 0;
233 : :
234 : : /* Input Gather List */
235 : : i = 0;
236 : 0 : gather_comp = (struct roc_sglist_comp *)((uint8_t *)m_data + 8);
237 : 0 : i = fill_ipsec_sg_comp_from_pkt(gather_comp, i, m_src);
238 [ # # ]: 0 : ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
239 : :
240 : 0 : g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
241 : :
242 : : /* Output Scatter List */
243 : : i = 0;
244 : 0 : scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
245 : 0 : i = fill_ipsec_sg_comp_from_pkt(scatter_comp, i, m_src);
246 [ # # ]: 0 : ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
247 : :
248 : 0 : s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
249 : :
250 : 0 : dlen = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
251 : :
252 : 0 : inst->dptr = (uint64_t)in_buffer;
253 : 0 : inst->w4.u64 = sess->inst.w4 | dlen;
254 : 0 : inst->w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
255 : : } else {
256 : : struct roc_sg2list_comp *scatter_comp, *gather_comp;
257 : : union cpt_inst_w5 cpt_inst_w5;
258 : : union cpt_inst_w6 cpt_inst_w6;
259 : : uint32_t g_size_bytes;
260 : : void *m_data;
261 : : int i;
262 : :
263 [ # # ]: 0 : m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
264 [ # # ]: 0 : if (unlikely(m_data == NULL)) {
265 : 0 : plt_dp_err("Error allocating meta buffer for request");
266 : 0 : return -ENOMEM;
267 : : }
268 : :
269 : : /* Input Gather List */
270 : : i = 0;
271 : : gather_comp = (struct roc_sg2list_comp *)((uint8_t *)m_data);
272 : :
273 : 0 : i = fill_ipsec_sg2_comp_from_pkt(gather_comp, i, m_src);
274 : :
275 : 0 : cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
276 : 0 : g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
277 : :
278 : : /* Output Scatter List */
279 : : i = 0;
280 : 0 : scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
281 : 0 : i = fill_ipsec_sg2_comp_from_pkt(scatter_comp, i, m_src);
282 : :
283 : 0 : cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
284 : :
285 : 0 : cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
286 : 0 : cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
287 : :
288 : 0 : inst->w5.u64 = cpt_inst_w5.u64;
289 : 0 : inst->w6.u64 = cpt_inst_w6.u64;
290 : 0 : inst->w4.u64 = sess->inst.w4 | rte_pktmbuf_pkt_len(m_src);
291 : 0 : inst->w4.s.opcode_major &= (~(ROC_IE_OT_INPLACE_BIT));
292 : : }
293 : : return 0;
294 : : }
295 : :
296 : : #endif /* __CN10K_IPSEC_LA_OPS_H__ */
|