DPDK 22.11.7
rte_mbuf.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright 2014 6WIND S.A.
4 */
5
6#ifndef _RTE_MBUF_H_
7#define _RTE_MBUF_H_
8
34#include <stdint.h>
35#include <rte_compat.h>
36#include <rte_common.h>
37#include <rte_config.h>
38#include <rte_mempool.h>
39#include <rte_prefetch.h>
41#include <rte_mbuf_ptype.h>
42#include <rte_mbuf_core.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
56const char *rte_get_rx_ol_flag_name(uint64_t mask);
57
70int rte_get_rx_ol_flag_list(uint64_t mask, char *buf, size_t buflen);
71
82const char *rte_get_tx_ol_flag_name(uint64_t mask);
83
96int rte_get_tx_ol_flag_list(uint64_t mask, char *buf, size_t buflen);
97
108static inline void
110{
111 rte_prefetch0(&m->cacheline0);
112}
113
125static inline void
127{
128#if RTE_CACHE_LINE_SIZE == 64
129 rte_prefetch0(&m->cacheline1);
130#else
131 RTE_SET_USED(m);
132#endif
133}
134
135
136static inline uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp);
137
146static inline rte_iova_t
148{
149#if RTE_IOVA_AS_PA
150 return m->buf_iova;
151#else
152 return (rte_iova_t)m->buf_addr;
153#endif
154}
155
164static inline void
166{
167#if RTE_IOVA_AS_PA
168 m->buf_iova = iova;
169#else
170 RTE_SET_USED(m);
171 RTE_SET_USED(iova);
172#endif
173}
174
183static inline rte_iova_t
185{
186 return rte_mbuf_iova_get(mb) + mb->data_off;
187}
188
201static inline rte_iova_t
203{
204 return rte_mbuf_iova_get(mb) + RTE_PKTMBUF_HEADROOM;
205}
206
215static inline struct rte_mbuf *
217{
218 return (struct rte_mbuf *)RTE_PTR_SUB(mi->buf_addr, sizeof(*mi) + mi->priv_size);
219}
220
236static inline char *
238{
239 return (char *)mb + sizeof(*mb) + rte_pktmbuf_priv_size(mp);
240}
241
250static inline char *
252{
253 return rte_mbuf_buf_addr(mb, mb->pool) + RTE_PKTMBUF_HEADROOM;
254}
255
269static inline char *
271{
272 return rte_mbuf_buf_addr(md, md->pool);
273}
274
287static inline void *
289{
290 return RTE_PTR_ADD(m, sizeof(struct rte_mbuf));
291}
292
301 uint16_t mbuf_priv_size;
302 uint32_t flags;
303};
304
313static inline uint32_t
315{
316 struct rte_pktmbuf_pool_private *mbp_priv;
317
318 mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
319 return mbp_priv->flags;
320}
321
328#define RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF (1 << 0)
329
337#define RTE_MBUF_HAS_PINNED_EXTBUF(mb) \
338 (rte_pktmbuf_priv_flags(mb->pool) & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)
339
340#ifdef RTE_LIBRTE_MBUF_DEBUG
341
343#define __rte_mbuf_sanity_check(m, is_h) rte_mbuf_sanity_check(m, is_h)
344
345#else /* RTE_LIBRTE_MBUF_DEBUG */
346
348#define __rte_mbuf_sanity_check(m, is_h) do { } while (0)
349
350#endif /* RTE_LIBRTE_MBUF_DEBUG */
351
352#ifdef RTE_MBUF_REFCNT_ATOMIC
353
361static inline uint16_t
362rte_mbuf_refcnt_read(const struct rte_mbuf *m)
363{
364 return __atomic_load_n(&m->refcnt, __ATOMIC_RELAXED);
365}
366
374static inline void
375rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
376{
377 __atomic_store_n(&m->refcnt, new_value, __ATOMIC_RELAXED);
378}
379
380/* internal */
381static inline uint16_t
382__rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
383{
384 return __atomic_add_fetch(&m->refcnt, (uint16_t)value,
385 __ATOMIC_ACQ_REL);
386}
387
397static inline uint16_t
398rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
399{
400 /*
401 * The atomic_add is an expensive operation, so we don't want to
402 * call it in the case where we know we are the unique holder of
403 * this mbuf (i.e. ref_cnt == 1). Otherwise, an atomic
404 * operation has to be used because concurrent accesses on the
405 * reference counter can occur.
406 */
407 if (likely(rte_mbuf_refcnt_read(m) == 1)) {
408 ++value;
409 rte_mbuf_refcnt_set(m, (uint16_t)value);
410 return (uint16_t)value;
411 }
412
413 return __rte_mbuf_refcnt_update(m, value);
414}
415
416#else /* ! RTE_MBUF_REFCNT_ATOMIC */
417
418/* internal */
419static inline uint16_t
420__rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
421{
422 m->refcnt = (uint16_t)(m->refcnt + value);
423 return m->refcnt;
424}
425
429static inline uint16_t
430rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
431{
432 return __rte_mbuf_refcnt_update(m, value);
433}
434
438static inline uint16_t
440{
441 return m->refcnt;
442}
443
447static inline void
448rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
449{
450 m->refcnt = new_value;
451}
452
453#endif /* RTE_MBUF_REFCNT_ATOMIC */
454
463static inline uint16_t
465{
466 return __atomic_load_n(&shinfo->refcnt, __ATOMIC_RELAXED);
467}
468
477static inline void
479 uint16_t new_value)
480{
481 __atomic_store_n(&shinfo->refcnt, new_value, __ATOMIC_RELAXED);
482}
483
495static inline uint16_t
497 int16_t value)
498{
499 if (likely(rte_mbuf_ext_refcnt_read(shinfo) == 1)) {
500 ++value;
501 rte_mbuf_ext_refcnt_set(shinfo, (uint16_t)value);
502 return (uint16_t)value;
503 }
504
505 return __atomic_add_fetch(&shinfo->refcnt, (uint16_t)value,
506 __ATOMIC_ACQ_REL);
507}
508
510#define RTE_MBUF_PREFETCH_TO_FREE(m) do { \
511 if ((m) != NULL) \
512 rte_prefetch0(m); \
513} while (0)
514
515
528void
529rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header);
530
550int rte_mbuf_check(const struct rte_mbuf *m, int is_header,
551 const char **reason);
552
565static __rte_always_inline void
567{
568 RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1);
569 RTE_ASSERT(m->next == NULL);
570 RTE_ASSERT(m->nb_segs == 1);
572}
573
575#define MBUF_RAW_ALLOC_CHECK(m) __rte_mbuf_raw_sanity_check(m)
576
596static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
597{
598 struct rte_mbuf *m;
599
600 if (rte_mempool_get(mp, (void **)&m) < 0)
601 return NULL;
603 return m;
604}
605
620static __rte_always_inline void
622{
623 RTE_ASSERT(!RTE_MBUF_CLONED(m) &&
626 rte_mempool_put(m->pool, m);
627}
628
651void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg,
652 void *m, unsigned i);
653
674void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg);
675
709struct rte_mempool *
710rte_pktmbuf_pool_create(const char *name, unsigned n,
711 unsigned cache_size, uint16_t priv_size, uint16_t data_room_size,
712 int socket_id);
713
750struct rte_mempool *
751rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
752 unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
753 int socket_id, const char *ops_name);
754
757 void *buf_ptr;
759 size_t buf_len;
760 uint16_t elt_size;
761};
762
803__rte_experimental
804struct rte_mempool *
805rte_pktmbuf_pool_create_extbuf(const char *name, unsigned int n,
806 unsigned int cache_size, uint16_t priv_size,
807 uint16_t data_room_size, int socket_id,
808 const struct rte_pktmbuf_extmem *ext_mem,
809 unsigned int ext_num);
810
822static inline uint16_t
824{
825 struct rte_pktmbuf_pool_private *mbp_priv;
826
827 mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
828 return mbp_priv->mbuf_data_room_size;
829}
830
843static inline uint16_t
845{
846 struct rte_pktmbuf_pool_private *mbp_priv;
847
848 mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
849 return mbp_priv->mbuf_priv_size;
850}
851
860static inline void rte_pktmbuf_reset_headroom(struct rte_mbuf *m)
861{
862 m->data_off = (uint16_t)RTE_MIN((uint16_t)RTE_PKTMBUF_HEADROOM,
863 (uint16_t)m->buf_len);
864}
865
874static inline void rte_pktmbuf_reset(struct rte_mbuf *m)
875{
876 m->next = NULL;
877 m->pkt_len = 0;
878 m->tx_offload = 0;
879 m->vlan_tci = 0;
880 m->vlan_tci_outer = 0;
881 m->nb_segs = 1;
883
885 m->packet_type = 0;
887
888 m->data_len = 0;
890}
891
905static inline struct rte_mbuf *rte_pktmbuf_alloc(struct rte_mempool *mp)
906{
907 struct rte_mbuf *m;
908 if ((m = rte_mbuf_raw_alloc(mp)) != NULL)
910 return m;
911}
912
927static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
928 struct rte_mbuf **mbufs, unsigned count)
929{
930 unsigned idx = 0;
931 int rc;
932
933 rc = rte_mempool_get_bulk(pool, (void **)mbufs, count);
934 if (unlikely(rc))
935 return rc;
936
937 /* To understand duff's device on loop unwinding optimization, see
938 * https://en.wikipedia.org/wiki/Duff's_device.
939 * Here while() loop is used rather than do() while{} to avoid extra
940 * check if count is zero.
941 */
942 switch (count % 4) {
943 case 0:
944 while (idx != count) {
945 __rte_mbuf_raw_sanity_check(mbufs[idx]);
946 rte_pktmbuf_reset(mbufs[idx]);
947 idx++;
948 /* fall-through */
949 case 3:
950 __rte_mbuf_raw_sanity_check(mbufs[idx]);
951 rte_pktmbuf_reset(mbufs[idx]);
952 idx++;
953 /* fall-through */
954 case 2:
955 __rte_mbuf_raw_sanity_check(mbufs[idx]);
956 rte_pktmbuf_reset(mbufs[idx]);
957 idx++;
958 /* fall-through */
959 case 1:
960 __rte_mbuf_raw_sanity_check(mbufs[idx]);
961 rte_pktmbuf_reset(mbufs[idx]);
962 idx++;
963 /* fall-through */
964 }
965 }
966 return 0;
967}
968
1001static inline struct rte_mbuf_ext_shared_info *
1002rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
1004{
1005 struct rte_mbuf_ext_shared_info *shinfo;
1006 void *buf_end = RTE_PTR_ADD(buf_addr, *buf_len);
1007 void *addr;
1008
1009 addr = RTE_PTR_ALIGN_FLOOR(RTE_PTR_SUB(buf_end, sizeof(*shinfo)),
1010 sizeof(uintptr_t));
1011 if (addr <= buf_addr)
1012 return NULL;
1013
1014 shinfo = (struct rte_mbuf_ext_shared_info *)addr;
1015 shinfo->free_cb = free_cb;
1016 shinfo->fcb_opaque = fcb_opaque;
1017 rte_mbuf_ext_refcnt_set(shinfo, 1);
1018
1019 *buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
1020 return shinfo;
1021}
1022
1083static inline void
1084rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,
1085 rte_iova_t buf_iova, uint16_t buf_len,
1086 struct rte_mbuf_ext_shared_info *shinfo)
1087{
1088 /* mbuf should not be read-only */
1089 RTE_ASSERT(RTE_MBUF_DIRECT(m) && rte_mbuf_refcnt_read(m) == 1);
1090 RTE_ASSERT(shinfo->free_cb != NULL);
1091
1092 m->buf_addr = buf_addr;
1093 rte_mbuf_iova_set(m, buf_iova);
1094 m->buf_len = buf_len;
1095
1096 m->data_len = 0;
1097 m->data_off = 0;
1098
1100 m->shinfo = shinfo;
1101}
1102
1110#define rte_pktmbuf_detach_extbuf(m) rte_pktmbuf_detach(m)
1111
1120static inline void
1121rte_mbuf_dynfield_copy(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
1122{
1123#if !RTE_IOVA_AS_PA
1124 mdst->dynfield2 = msrc->dynfield2;
1125#endif
1126 memcpy(&mdst->dynfield1, msrc->dynfield1, sizeof(mdst->dynfield1));
1127}
1128
1129/* internal */
1130static inline void
1131__rte_pktmbuf_copy_hdr(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
1132{
1133 mdst->port = msrc->port;
1134 mdst->vlan_tci = msrc->vlan_tci;
1135 mdst->vlan_tci_outer = msrc->vlan_tci_outer;
1136 mdst->tx_offload = msrc->tx_offload;
1137 mdst->hash = msrc->hash;
1138 mdst->packet_type = msrc->packet_type;
1139 rte_mbuf_dynfield_copy(mdst, msrc);
1140}
1141
1163static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m)
1164{
1165 RTE_ASSERT(RTE_MBUF_DIRECT(mi) &&
1166 rte_mbuf_refcnt_read(mi) == 1);
1167
1168 if (RTE_MBUF_HAS_EXTBUF(m)) {
1170 mi->ol_flags = m->ol_flags;
1171 mi->shinfo = m->shinfo;
1172 } else {
1173 /* if m is not direct, get the mbuf that embeds the data */
1175 mi->priv_size = m->priv_size;
1177 }
1178
1179 __rte_pktmbuf_copy_hdr(mi, m);
1180
1181 mi->data_off = m->data_off;
1182 mi->data_len = m->data_len;
1184 mi->buf_addr = m->buf_addr;
1185 mi->buf_len = m->buf_len;
1186
1187 mi->next = NULL;
1188 mi->pkt_len = mi->data_len;
1189 mi->nb_segs = 1;
1190
1193}
1194
1202static inline void
1203__rte_pktmbuf_free_extbuf(struct rte_mbuf *m)
1204{
1205 RTE_ASSERT(RTE_MBUF_HAS_EXTBUF(m));
1206 RTE_ASSERT(m->shinfo != NULL);
1207
1208 if (rte_mbuf_ext_refcnt_update(m->shinfo, -1) == 0)
1210}
1211
1218static inline void
1219__rte_pktmbuf_free_direct(struct rte_mbuf *m)
1220{
1221 struct rte_mbuf *md;
1222
1223 RTE_ASSERT(RTE_MBUF_CLONED(m));
1224
1225 md = rte_mbuf_from_indirect(m);
1226
1227 if (rte_mbuf_refcnt_update(md, -1) == 0) {
1228 md->next = NULL;
1229 md->nb_segs = 1;
1230 rte_mbuf_refcnt_set(md, 1);
1232 }
1233}
1234
1253static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
1254{
1255 struct rte_mempool *mp = m->pool;
1256 uint32_t mbuf_size, buf_len;
1257 uint16_t priv_size;
1258
1259 if (RTE_MBUF_HAS_EXTBUF(m)) {
1260 /*
1261 * The mbuf has the external attached buffer,
1262 * we should check the type of the memory pool where
1263 * the mbuf was allocated from to detect the pinned
1264 * external buffer.
1265 */
1266 uint32_t flags = rte_pktmbuf_priv_flags(mp);
1267
1269 /*
1270 * The pinned external buffer should not be
1271 * detached from its backing mbuf, just exit.
1272 */
1273 return;
1274 }
1275 __rte_pktmbuf_free_extbuf(m);
1276 } else {
1277 __rte_pktmbuf_free_direct(m);
1278 }
1279 priv_size = rte_pktmbuf_priv_size(mp);
1280 mbuf_size = (uint32_t)(sizeof(struct rte_mbuf) + priv_size);
1281 buf_len = rte_pktmbuf_data_room_size(mp);
1282
1283 m->priv_size = priv_size;
1284 m->buf_addr = (char *)m + mbuf_size;
1285 rte_mbuf_iova_set(m, rte_mempool_virt2iova(m) + mbuf_size);
1286 m->buf_len = (uint16_t)buf_len;
1288 m->data_len = 0;
1289 m->ol_flags = 0;
1290}
1291
1305static inline int __rte_pktmbuf_pinned_extbuf_decref(struct rte_mbuf *m)
1306{
1307 struct rte_mbuf_ext_shared_info *shinfo;
1308
1309 /* Clear flags, mbuf is being freed. */
1311 shinfo = m->shinfo;
1312
1313 /* Optimize for performance - do not dec/reinit */
1314 if (likely(rte_mbuf_ext_refcnt_read(shinfo) == 1))
1315 return 0;
1316
1317 /*
1318 * Direct usage of add primitive to avoid
1319 * duplication of comparing with one.
1320 */
1321 if (likely(__atomic_add_fetch(&shinfo->refcnt, (uint16_t)-1,
1322 __ATOMIC_ACQ_REL)))
1323 return 1;
1324
1325 /* Reinitialize counter before mbuf freeing. */
1326 rte_mbuf_ext_refcnt_set(shinfo, 1);
1327 return 0;
1328}
1329
1344static __rte_always_inline struct rte_mbuf *
1346{
1348
1349 if (likely(rte_mbuf_refcnt_read(m) == 1)) {
1350
1351 if (!RTE_MBUF_DIRECT(m)) {
1353 if (RTE_MBUF_HAS_EXTBUF(m) &&
1355 __rte_pktmbuf_pinned_extbuf_decref(m))
1356 return NULL;
1357 }
1358
1359 if (m->next != NULL)
1360 m->next = NULL;
1361 if (m->nb_segs != 1)
1362 m->nb_segs = 1;
1363
1364 return m;
1365
1366 } else if (__rte_mbuf_refcnt_update(m, -1) == 0) {
1367
1368 if (!RTE_MBUF_DIRECT(m)) {
1370 if (RTE_MBUF_HAS_EXTBUF(m) &&
1372 __rte_pktmbuf_pinned_extbuf_decref(m))
1373 return NULL;
1374 }
1375
1376 if (m->next != NULL)
1377 m->next = NULL;
1378 if (m->nb_segs != 1)
1379 m->nb_segs = 1;
1380 rte_mbuf_refcnt_set(m, 1);
1381
1382 return m;
1383 }
1384 return NULL;
1385}
1386
1396static __rte_always_inline void
1398{
1400 if (likely(m != NULL))
1402}
1403
1413static inline void rte_pktmbuf_free(struct rte_mbuf *m)
1414{
1415 struct rte_mbuf *m_next;
1416
1417 if (m != NULL)
1419
1420 while (m != NULL) {
1421 m_next = m->next;
1423 m = m_next;
1424 }
1425}
1426
1439void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count);
1440
1458struct rte_mbuf *
1460
1482struct rte_mbuf *
1483rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp,
1484 uint32_t offset, uint32_t length);
1485
1497static inline void rte_pktmbuf_refcnt_update(struct rte_mbuf *m, int16_t v)
1498{
1500
1501 do {
1503 } while ((m = m->next) != NULL);
1504}
1505
1514static inline uint16_t rte_pktmbuf_headroom(const struct rte_mbuf *m)
1515{
1517 return m->data_off;
1518}
1519
1528static inline uint16_t rte_pktmbuf_tailroom(const struct rte_mbuf *m)
1529{
1531 return (uint16_t)(m->buf_len - rte_pktmbuf_headroom(m) -
1532 m->data_len);
1533}
1534
1543static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m)
1544{
1546 while (m->next != NULL)
1547 m = m->next;
1548 return m;
1549}
1550
1559#define rte_pktmbuf_pkt_len(m) ((m)->pkt_len)
1560
1569#define rte_pktmbuf_data_len(m) ((m)->data_len)
1570
1586static inline char *rte_pktmbuf_prepend(struct rte_mbuf *m,
1587 uint16_t len)
1588{
1590
1591 if (unlikely(len > rte_pktmbuf_headroom(m)))
1592 return NULL;
1593
1594 /* NB: elaborating the subtraction like this instead of using
1595 * -= allows us to ensure the result type is uint16_t
1596 * avoiding compiler warnings on gcc 8.1 at least */
1597 m->data_off = (uint16_t)(m->data_off - len);
1598 m->data_len = (uint16_t)(m->data_len + len);
1599 m->pkt_len = (m->pkt_len + len);
1600
1601 return (char *)m->buf_addr + m->data_off;
1602}
1603
1619static inline char *rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len)
1620{
1621 void *tail;
1622 struct rte_mbuf *m_last;
1623
1625
1626 m_last = rte_pktmbuf_lastseg(m);
1627 if (unlikely(len > rte_pktmbuf_tailroom(m_last)))
1628 return NULL;
1629
1630 tail = (char *)m_last->buf_addr + m_last->data_off + m_last->data_len;
1631 m_last->data_len = (uint16_t)(m_last->data_len + len);
1632 m->pkt_len = (m->pkt_len + len);
1633 return (char*) tail;
1634}
1635
1650static inline char *rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
1651{
1653
1654 if (unlikely(len > m->data_len))
1655 return NULL;
1656
1657 /* NB: elaborating the addition like this instead of using
1658 * += allows us to ensure the result type is uint16_t
1659 * avoiding compiler warnings on gcc 8.1 at least */
1660 m->data_len = (uint16_t)(m->data_len - len);
1661 m->data_off = (uint16_t)(m->data_off + len);
1662 m->pkt_len = (m->pkt_len - len);
1663 return (char *)m->buf_addr + m->data_off;
1664}
1665
1680static inline int rte_pktmbuf_trim(struct rte_mbuf *m, uint16_t len)
1681{
1682 struct rte_mbuf *m_last;
1683
1685
1686 m_last = rte_pktmbuf_lastseg(m);
1687 if (unlikely(len > m_last->data_len))
1688 return -1;
1689
1690 m_last->data_len = (uint16_t)(m_last->data_len - len);
1691 m->pkt_len = (m->pkt_len - len);
1692 return 0;
1693}
1694
1704static inline int rte_pktmbuf_is_contiguous(const struct rte_mbuf *m)
1705{
1707 return m->nb_segs == 1;
1708}
1709
1713const void *__rte_pktmbuf_read(const struct rte_mbuf *m, uint32_t off,
1714 uint32_t len, void *buf);
1715
1736static inline const void *rte_pktmbuf_read(const struct rte_mbuf *m,
1737 uint32_t off, uint32_t len, void *buf)
1738{
1739 if (likely(off + len <= rte_pktmbuf_data_len(m)))
1740 return rte_pktmbuf_mtod_offset(m, char *, off);
1741 else
1742 return __rte_pktmbuf_read(m, off, len, buf);
1743}
1744
1761static inline int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail)
1762{
1763 struct rte_mbuf *cur_tail;
1764
1765 /* Check for number-of-segments-overflow */
1766 if (head->nb_segs + tail->nb_segs > RTE_MBUF_MAX_NB_SEGS)
1767 return -EOVERFLOW;
1768
1769 /* Chain 'tail' onto the old tail */
1770 cur_tail = rte_pktmbuf_lastseg(head);
1771 cur_tail->next = tail;
1772
1773 /* accumulate number of segments and total length.
1774 * NB: elaborating the addition like this instead of using
1775 * -= allows us to ensure the result type is uint16_t
1776 * avoiding compiler warnings on gcc 8.1 at least */
1777 head->nb_segs = (uint16_t)(head->nb_segs + tail->nb_segs);
1778 head->pkt_len += tail->pkt_len;
1779
1780 /* pkt_len is only set in the head */
1781 tail->pkt_len = tail->data_len;
1782
1783 return 0;
1784}
1785
1807static __rte_always_inline uint64_t
1808rte_mbuf_tx_offload(uint64_t il2, uint64_t il3, uint64_t il4, uint64_t tso,
1809 uint64_t ol3, uint64_t ol2, uint64_t unused)
1810{
1811 return il2 << RTE_MBUF_L2_LEN_OFS |
1812 il3 << RTE_MBUF_L3_LEN_OFS |
1813 il4 << RTE_MBUF_L4_LEN_OFS |
1814 tso << RTE_MBUF_TSO_SEGSZ_OFS |
1815 ol3 << RTE_MBUF_OUTL3_LEN_OFS |
1816 ol2 << RTE_MBUF_OUTL2_LEN_OFS |
1817 unused << RTE_MBUF_TXOFLD_UNUSED_OFS;
1818}
1819
1830static inline int
1832{
1833 uint64_t ol_flags = m->ol_flags;
1834
1835 /* Does packet set any of available offloads? */
1837 return 0;
1838
1839 /* IP checksum can be counted only for IPv4 packet */
1841 return -EINVAL;
1842
1843 /* IP type not set when required */
1846 return -EINVAL;
1847
1848 /* Check requirements for TSO packet */
1850 if ((m->tso_segsz == 0) ||
1853 return -EINVAL;
1854
1855 /* RTE_MBUF_F_TX_OUTER_IP_CKSUM set for non outer IPv4 packet. */
1858 return -EINVAL;
1859
1860 return 0;
1861}
1862
1866int __rte_pktmbuf_linearize(struct rte_mbuf *mbuf);
1867
1880static inline int
1882{
1883 if (rte_pktmbuf_is_contiguous(mbuf))
1884 return 0;
1885 return __rte_pktmbuf_linearize(mbuf);
1886}
1887
1902void rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len);
1903
1907static inline uint32_t
1909{
1910 return m->hash.sched.queue_id;
1911}
1912
1916static inline uint8_t
1918{
1919 return m->hash.sched.traffic_class;
1920}
1921
1925static inline uint8_t
1927{
1928 return m->hash.sched.color;
1929}
1930
1943static inline void
1944rte_mbuf_sched_get(const struct rte_mbuf *m, uint32_t *queue_id,
1945 uint8_t *traffic_class,
1946 uint8_t *color)
1947{
1948 struct rte_mbuf_sched sched = m->hash.sched;
1949
1950 *queue_id = sched.queue_id;
1952 *color = sched.color;
1953}
1954
1958static inline void
1960{
1961 m->hash.sched.queue_id = queue_id;
1962}
1963
1967static inline void
1969{
1970 m->hash.sched.traffic_class = traffic_class;
1971}
1972
1976static inline void
1978{
1979 m->hash.sched.color = color;
1980}
1981
1994static inline void
1996 uint8_t traffic_class,
1997 uint8_t color)
1998{
1999 m->hash.sched = (struct rte_mbuf_sched){
2000 .queue_id = queue_id,
2001 .traffic_class = traffic_class,
2002 .color = color,
2003 .reserved = 0,
2004 };
2005}
2006
2007#ifdef __cplusplus
2008}
2009#endif
2010
2011#endif /* _RTE_MBUF_H_ */
#define likely(x)
#define unlikely(x)
#define RTE_PTR_ALIGN_FLOOR(ptr, align)
Definition: rte_common.h:319
#define RTE_MIN(a, b)
Definition: rte_common.h:613
#define RTE_PTR_DIFF(ptr1, ptr2)
Definition: rte_common.h:302
#define RTE_PTR_SUB(ptr, x)
Definition: rte_common.h:295
uint64_t rte_iova_t
Definition: rte_common.h:458
#define RTE_PTR_ADD(ptr, x)
Definition: rte_common.h:290
#define RTE_SET_USED(x)
Definition: rte_common.h:135
#define __rte_unused
Definition: rte_common.h:120
#define __rte_always_inline
Definition: rte_common.h:255
static __rte_always_inline void rte_pktmbuf_free_seg(struct rte_mbuf *m)
Definition: rte_mbuf.h:1397
int rte_get_rx_ol_flag_list(uint64_t mask, char *buf, size_t buflen)
static void rte_mbuf_prefetch_part2(struct rte_mbuf *m)
Definition: rte_mbuf.h:126
static __rte_always_inline uint64_t rte_mbuf_tx_offload(uint64_t il2, uint64_t il3, uint64_t il4, uint64_t tso, uint64_t ol3, uint64_t ol2, uint64_t unused)
Definition: rte_mbuf.h:1808
static void rte_pktmbuf_free(struct rte_mbuf *m)
Definition: rte_mbuf.h:1413
static rte_iova_t rte_mbuf_data_iova_default(const struct rte_mbuf *mb)
Definition: rte_mbuf.h:202
static rte_iova_t rte_mbuf_data_iova(const struct rte_mbuf *mb)
Definition: rte_mbuf.h:184
static uint16_t rte_pktmbuf_tailroom(const struct rte_mbuf *m)
Definition: rte_mbuf.h:1528
int rte_get_tx_ol_flag_list(uint64_t mask, char *buf, size_t buflen)
struct rte_mbuf * rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp)
#define rte_pktmbuf_data_len(m)
Definition: rte_mbuf.h:1569
static uint16_t rte_pktmbuf_headroom(const struct rte_mbuf *m)
Definition: rte_mbuf.h:1514
static uint32_t rte_mbuf_sched_queue_get(const struct rte_mbuf *m)
Definition: rte_mbuf.h:1908
static void rte_mbuf_prefetch_part1(struct rte_mbuf *m)
Definition: rte_mbuf.h:109
static char * rte_pktmbuf_prepend(struct rte_mbuf *m, uint16_t len)
Definition: rte_mbuf.h:1586
static char * rte_mbuf_data_addr_default(struct rte_mbuf *mb)
Definition: rte_mbuf.h:251
struct rte_mempool * rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n, unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id, const char *ops_name)
static void rte_mbuf_sched_set(struct rte_mbuf *m, uint32_t queue_id, uint8_t traffic_class, uint8_t color)
Definition: rte_mbuf.h:1995
static void rte_mbuf_dynfield_copy(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
Definition: rte_mbuf.h:1121
static char * rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
Definition: rte_mbuf.h:1650
static void rte_mbuf_sched_color_set(struct rte_mbuf *m, uint8_t color)
Definition: rte_mbuf.h:1977
static int rte_pktmbuf_is_contiguous(const struct rte_mbuf *m)
Definition: rte_mbuf.h:1704
int rte_mbuf_check(const struct rte_mbuf *m, int is_header, const char **reason)
static char * rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len)
Definition: rte_mbuf.h:1619
const char * rte_get_tx_ol_flag_name(uint64_t mask)
static void rte_mbuf_sched_get(const struct rte_mbuf *m, uint32_t *queue_id, uint8_t *traffic_class, uint8_t *color)
Definition: rte_mbuf.h:1944
static void rte_pktmbuf_detach(struct rte_mbuf *m)
Definition: rte_mbuf.h:1253
static char * rte_mbuf_to_baddr(struct rte_mbuf *md)
Definition: rte_mbuf.h:270
static struct rte_mbuf_ext_shared_info * rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len, rte_mbuf_extbuf_free_callback_t free_cb, void *fcb_opaque)
Definition: rte_mbuf.h:1002
static uint32_t rte_pktmbuf_priv_flags(struct rte_mempool *mp)
Definition: rte_mbuf.h:314
static void rte_pktmbuf_refcnt_update(struct rte_mbuf *m, int16_t v)
Definition: rte_mbuf.h:1497
void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg, void *m, unsigned i)
static void rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
Definition: rte_mbuf.h:448
static struct rte_mbuf * rte_mbuf_raw_alloc(struct rte_mempool *mp)
Definition: rte_mbuf.h:596
static uint16_t rte_mbuf_ext_refcnt_update(struct rte_mbuf_ext_shared_info *shinfo, int16_t value)
Definition: rte_mbuf.h:496
struct rte_mempool * rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id)
void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
void rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)
#define __rte_mbuf_sanity_check(m, is_h)
Definition: rte_mbuf.h:348
static const void * rte_pktmbuf_read(const struct rte_mbuf *m, uint32_t off, uint32_t len, void *buf)
Definition: rte_mbuf.h:1736
static uint16_t rte_mbuf_refcnt_read(const struct rte_mbuf *m)
Definition: rte_mbuf.h:439
static int rte_pktmbuf_linearize(struct rte_mbuf *mbuf)
Definition: rte_mbuf.h:1881
__rte_experimental struct rte_mempool * rte_pktmbuf_pool_create_extbuf(const char *name, unsigned int n, unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id, const struct rte_pktmbuf_extmem *ext_mem, unsigned int ext_num)
static __rte_always_inline void rte_mbuf_raw_free(struct rte_mbuf *m)
Definition: rte_mbuf.h:621
struct rte_mbuf * rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp, uint32_t offset, uint32_t length)
static struct rte_mbuf * rte_pktmbuf_alloc(struct rte_mempool *mp)
Definition: rte_mbuf.h:905
static char * rte_mbuf_buf_addr(struct rte_mbuf *mb, struct rte_mempool *mp)
Definition: rte_mbuf.h:237
static void rte_mbuf_ext_refcnt_set(struct rte_mbuf_ext_shared_info *shinfo, uint16_t new_value)
Definition: rte_mbuf.h:478
void rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
static uint8_t rte_mbuf_sched_traffic_class_get(const struct rte_mbuf *m)
Definition: rte_mbuf.h:1917
static uint16_t rte_mbuf_ext_refcnt_read(const struct rte_mbuf_ext_shared_info *shinfo)
Definition: rte_mbuf.h:464
static uint16_t rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
Definition: rte_mbuf.h:430
static int rte_pktmbuf_trim(struct rte_mbuf *m, uint16_t len)
Definition: rte_mbuf.h:1680
#define RTE_MBUF_HAS_PINNED_EXTBUF(mb)
Definition: rte_mbuf.h:337
static rte_iova_t rte_mbuf_iova_get(const struct rte_mbuf *m)
Definition: rte_mbuf.h:147
static void rte_mbuf_sched_queue_set(struct rte_mbuf *m, uint32_t queue_id)
Definition: rte_mbuf.h:1959
static uint16_t rte_pktmbuf_data_room_size(struct rte_mempool *mp)
Definition: rte_mbuf.h:823
static struct rte_mbuf * rte_pktmbuf_lastseg(struct rte_mbuf *m)
Definition: rte_mbuf.h:1543
static void rte_mbuf_sched_traffic_class_set(struct rte_mbuf *m, uint8_t traffic_class)
Definition: rte_mbuf.h:1968
#define RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF
Definition: rte_mbuf.h:328
static __rte_always_inline struct rte_mbuf * rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
Definition: rte_mbuf.h:1345
static int rte_validate_tx_offload(const struct rte_mbuf *m)
Definition: rte_mbuf.h:1831
static void rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr, rte_iova_t buf_iova, uint16_t buf_len, struct rte_mbuf_ext_shared_info *shinfo)
Definition: rte_mbuf.h:1084
static struct rte_mbuf * rte_mbuf_from_indirect(struct rte_mbuf *mi)
Definition: rte_mbuf.h:216
static int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool, struct rte_mbuf **mbufs, unsigned count)
Definition: rte_mbuf.h:927
static void rte_mbuf_iova_set(struct rte_mbuf *m, rte_iova_t iova)
Definition: rte_mbuf.h:165
static void rte_pktmbuf_reset_headroom(struct rte_mbuf *m)
Definition: rte_mbuf.h:860
static void * rte_mbuf_to_priv(struct rte_mbuf *m)
Definition: rte_mbuf.h:288
static uint8_t rte_mbuf_sched_color_get(const struct rte_mbuf *m)
Definition: rte_mbuf.h:1926
static int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail)
Definition: rte_mbuf.h:1761
static __rte_always_inline void __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m)
Definition: rte_mbuf.h:566
const char * rte_get_rx_ol_flag_name(uint64_t mask)
void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg)
static uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp)
Definition: rte_mbuf.h:844
static void rte_pktmbuf_reset(struct rte_mbuf *m)
Definition: rte_mbuf.h:874
static void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m)
Definition: rte_mbuf.h:1163
#define RTE_MBUF_F_TX_OUTER_IP_CKSUM
#define RTE_MBUF_F_EXTERNAL
#define RTE_MBUF_F_TX_IP_CKSUM
#define RTE_MBUF_MAX_NB_SEGS
#define RTE_MBUF_F_TX_TCP_SEG
#define RTE_MBUF_F_TX_L4_MASK
#define RTE_MBUF_F_TX_OUTER_IPV4
#define RTE_MBUF_HAS_EXTBUF(mb)
#define RTE_MBUF_F_TX_OFFLOAD_MASK
#define RTE_MBUF_CLONED(mb)
#define RTE_MBUF_DIRECT(mb)
#define RTE_MBUF_F_TX_IPV4
void(* rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque)
#define rte_pktmbuf_mtod_offset(m, t, o)
#define RTE_MBUF_F_TX_IPV6
#define RTE_MBUF_F_INDIRECT
#define RTE_MBUF_PORT_INVALID
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:1640
static rte_iova_t rte_mempool_virt2iova(const void *elt)
Definition: rte_mempool.h:1794
static __rte_always_inline int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
Definition: rte_mempool.h:1669
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1477
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1822
static void rte_prefetch0(const volatile void *p)
rte_mbuf_extbuf_free_callback_t free_cb
uint32_t queue_id
uint8_t traffic_class
uint64_t ol_flags
uint16_t nb_segs
uint16_t vlan_tci
uint16_t priv_size
uint32_t pkt_len
uint64_t dynfield2
uint16_t buf_len
struct rte_mbuf_ext_shared_info * shinfo
uint32_t packet_type
uint16_t port
void * buf_addr
struct rte_mempool * pool
uint32_t dynfield1[9]
uint16_t vlan_tci_outer
struct rte_mbuf * next
uint64_t tx_offload
uint16_t data_len
uint64_t tso_segsz
uint16_t refcnt
char name[RTE_MEMPOOL_NAMESIZE]
Definition: rte_mempool.h:220
uint32_t cache_size
Definition: rte_mempool.h:231
unsigned int flags
Definition: rte_mempool.h:228
uint16_t elt_size
Definition: rte_mbuf.h:760
rte_iova_t buf_iova
Definition: rte_mbuf.h:758
uint16_t mbuf_data_room_size
Definition: rte_mbuf.h:300