DPDK  2.2.0
rte_mbuf_offload.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2015 Intel Corporation. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Intel Corporation nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _RTE_MBUF_OFFLOAD_H_
34 #define _RTE_MBUF_OFFLOAD_H_
35 
59 #include <rte_mbuf.h>
60 #include <rte_crypto.h>
61 
62 
69 };
70 
79  struct rte_mbuf *m;
80  struct rte_mempool *mp;
83  union {
85  } op;
86 };
87 
89 struct rte_pktmbuf_offload_pool_private {
90  uint16_t offload_priv_size;
92 };
93 
94 
111 extern struct rte_mempool *
112 rte_pktmbuf_offload_pool_create(const char *name, unsigned size,
113  unsigned cache_size, uint16_t priv_size, int socket_id);
114 
115 
124 static inline uint16_t
126 {
127  struct rte_pktmbuf_offload_pool_private *priv =
128  rte_mempool_get_priv(mpool);
129 
130  return priv->offload_priv_size;
131 }
132 
144 static inline struct rte_mbuf_offload *
146 {
147  struct rte_mbuf_offload *ol;
148 
149  for (ol = m->offload_ops; ol != NULL; ol = ol->next)
150  if (ol->type == type)
151  return ol;
152 
153  return ol;
154 }
155 
167 static inline struct rte_mbuf_offload *
169 {
170  struct rte_mbuf_offload **ol_last;
171 
172  for (ol_last = &m->offload_ops; ol_last[0] != NULL;
173  ol_last = &ol_last[0]->next)
174  if (ol_last[0]->type == ol->type)
175  return NULL;
176 
177  ol_last[0] = ol;
178  ol_last[0]->m = m;
179  ol_last[0]->next = NULL;
180 
181  return ol_last[0];
182 }
183 
184 
186 static inline void
189 {
190  ol->m = NULL;
191  ol->type = type;
192 
193  switch (type) {
195  __rte_crypto_op_reset(&ol->op.crypto); break;
196  default:
197  break;
198  }
199 }
200 
202 static inline struct rte_mbuf_offload *
204 {
205  void *buf = NULL;
206 
207  if (rte_mempool_get(mp, &buf) < 0)
208  return NULL;
209 
210  return (struct rte_mbuf_offload *)buf;
211 }
212 
224 static inline struct rte_mbuf_offload *
227 {
229 
230  if (ol != NULL)
231  __rte_pktmbuf_offload_reset(ol, type);
232 
233  return ol;
234 }
235 
239 static inline void
241 {
242  if (ol != NULL && ol->mp != NULL)
243  rte_mempool_put(ol->mp, ol);
244 }
245 
254 static inline void *
256  uint16_t size)
257 {
258  uint16_t priv_size;
259 
260  if (likely(ol->mp != NULL)) {
261  priv_size = __rte_pktmbuf_offload_priv_size(ol->mp);
262 
263  if (likely(priv_size >= size))
264  return (void *)(ol + 1);
265  }
266  return NULL;
267 }
268 
278 static inline struct rte_crypto_xform *
280  unsigned nb_xforms)
281 {
282  struct rte_crypto_xform *xform;
283  void *priv_data;
284  uint16_t size;
285 
286  size = sizeof(struct rte_crypto_xform) * nb_xforms;
287  priv_data = __rte_pktmbuf_offload_check_priv_data_size(ol, size);
288 
289  if (priv_data == NULL)
290  return NULL;
291 
292  ol->op.crypto.xform = xform = (struct rte_crypto_xform *)priv_data;
293 
294  do {
296  xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
297  } while (xform);
298 
299  return ol->op.crypto.xform;
300 }
301 
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 
307 #endif /* _RTE_MBUF_OFFLOAD_H_ */