1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2020 Intel Corporation
10 * Contains miscellaneous functions/structures/macros used internally
15 * Move bad (unprocessed) mbufs beyond the good (processed) ones.
16 * bad_idx[] contains the indexes of bad mbufs inside the mb[].
19 move_bad_mbufs(struct rte_mbuf *mb[], const uint32_t bad_idx[], uint32_t nb_mb,
23 struct rte_mbuf *drb[nb_bad];
28 /* copy bad ones into a temp place */
29 for (i = 0; i != nb_mb; i++) {
30 if (j != nb_bad && i == bad_idx[j])
36 /* copy bad ones after the good ones */
37 for (i = 0; i != nb_bad; i++)
42 * Find packet's segment for the specified offset.
43 * ofs - at input should contain required offset, at output would contain
44 * offset value within the segment.
46 static inline struct rte_mbuf *
47 mbuf_get_seg_ofs(struct rte_mbuf *mb, uint32_t *ofs)
56 ms = rte_pktmbuf_lastseg(mb);
57 n = n + rte_pktmbuf_data_len(ms) - plen;
60 for (k = rte_pktmbuf_data_len(ms); n >= k;
61 k = rte_pktmbuf_data_len(ms)) {
72 * Trim multi-segment packet at the specified offset, and free
73 * all unused segments.
75 * ms - segment where to cut
76 * ofs - offset within the *ms*
77 * len - length to cut (from given offset to the end of the packet)
78 * Can be used in conjunction with mbuf_get_seg_ofs():
80 * ms = mbuf_get_seg_ofs(mb, &ofs);
81 * mbuf_cut_seg_ofs(mb, ms, ofs, mb->pkt_len - new_len);
84 mbuf_cut_seg_ofs(struct rte_mbuf *mb, struct rte_mbuf *ms, uint32_t ofs,
93 /* tail spawns through multiple segments */
94 if (slen < ofs + len) {
97 for (n = 0; mn != NULL; n++) {
99 rte_pktmbuf_free_seg(mn);
109 * process packets using sync crypto engine.
110 * expects *num* to be greater than zero.
113 cpu_crypto_bulk(const struct rte_ipsec_session *ss,
114 union rte_crypto_sym_ofs ofs, struct rte_mbuf *mb[],
115 void *iv[], void *aad[], void *dgst[], uint32_t l4ofs[],
116 uint32_t clen[], uint32_t num)
121 struct rte_crypto_sgl vecpkt[num];
122 struct rte_crypto_vec vec[UINT8_MAX];
123 struct rte_crypto_sym_vec symvec;
125 const uint32_t vnum = RTE_DIM(vec);
129 for (i = 0; i != num; i++) {
131 vcnt = rte_crypto_mbuf_to_vec(mb[i], l4ofs[i], clen[i],
132 &vec[vofs], vnum - vofs);
134 /* not enough space in vec[] to hold all segments */
136 /* fill the request structure */
137 symvec.sgl = &vecpkt[j];
139 symvec.aad = &aad[j];
140 symvec.digest = &dgst[j];
141 symvec.status = &st[j];
144 /* flush vec array and try again */
145 n += rte_cryptodev_sym_cpu_crypto_process(
146 ss->crypto.dev_id, ss->crypto.ses, ofs,
149 vcnt = rte_crypto_mbuf_to_vec(mb[i], l4ofs[i], clen[i],
151 RTE_ASSERT(vcnt > 0);
155 vecpkt[i].vec = &vec[vofs];
156 vecpkt[i].num = vcnt;
160 /* fill the request structure */
161 symvec.sgl = &vecpkt[j];
163 symvec.aad = &aad[j];
164 symvec.digest = &dgst[j];
165 symvec.status = &st[j];
168 n += rte_cryptodev_sym_cpu_crypto_process(ss->crypto.dev_id,
169 ss->crypto.ses, ofs, &symvec);
172 for (i = 0; j != 0 && i != num; i++) {
174 mb[i]->ol_flags |= PKT_RX_SEC_OFFLOAD_FAILED;
180 #endif /* _MISC_H_ */