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