xref: /dpdk/lib/node/node_private.h (revision be4c0cb4901fc0703786e0d3da4e0123306e4539)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2020 Marvell International Ltd.
3  */
4 
5 #ifndef __NODE_PRIVATE_H__
6 #define __NODE_PRIVATE_H__
7 
8 #include <stdalign.h>
9 
10 #include <rte_common.h>
11 #include <rte_log.h>
12 #include <rte_mbuf.h>
13 #include <rte_mbuf_dyn.h>
14 
15 #include <rte_graph_worker_common.h>
16 
17 extern int rte_node_logtype;
18 #define RTE_LOGTYPE_NODE rte_node_logtype
19 
20 #define NODE_LOG(level, node_name, ...)                                        \
21 	RTE_LOG_LINE_PREFIX(level, NODE, "%s: %s():%u ",                       \
22 		node_name RTE_LOG_COMMA __func__ RTE_LOG_COMMA __LINE__,       \
23 		__VA_ARGS__)
24 
25 #define node_err(node_name, ...) NODE_LOG(ERR, node_name, __VA_ARGS__)
26 #define node_info(node_name, ...) NODE_LOG(INFO, node_name, __VA_ARGS__)
27 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
28 
29 /**
30  * Node mbuf private data to store next hop, ttl and checksum.
31  */
32 struct node_mbuf_priv1 {
33 	union {
34 		/* IP4/IP6 rewrite */
35 		struct {
36 			uint16_t nh;
37 			uint16_t ttl;
38 			uint32_t cksum;
39 		};
40 
41 		uint64_t u;
42 	};
43 };
44 
45 static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
46 	.name = "rte_node_dynfield_priv1",
47 	.size = sizeof(struct node_mbuf_priv1),
48 	.align = alignof(struct node_mbuf_priv1),
49 };
50 extern int node_mbuf_priv1_dynfield_offset;
51 
52 /**
53  * Node mbuf private area 2.
54  */
55 struct __rte_cache_aligned node_mbuf_priv2 {
56 	uint64_t priv_data;
57 };
58 
59 #define NODE_MBUF_PRIV2_SIZE sizeof(struct node_mbuf_priv2)
60 
61 #define OBJS_PER_CLINE (RTE_CACHE_LINE_SIZE / sizeof(void *))
62 
63 /**
64  * Get mbuf_priv1 pointer from rte_mbuf.
65  *
66  * @param
67  *   Pointer to the rte_mbuf.
68  *
69  * @return
70  *   Pointer to the mbuf_priv1.
71  */
72 static __rte_always_inline struct node_mbuf_priv1 *
73 node_mbuf_priv1(struct rte_mbuf *m, const int offset)
74 {
75 	return RTE_MBUF_DYNFIELD(m, offset, struct node_mbuf_priv1 *);
76 }
77 
78 /**
79  * Get mbuf_priv2 pointer from rte_mbuf.
80  *
81  * @param
82  *   Pointer to the rte_mbuf.
83  *
84  * @return
85  *   Pointer to the mbuf_priv2.
86  */
87 static __rte_always_inline struct node_mbuf_priv2 *
88 node_mbuf_priv2(struct rte_mbuf *m)
89 {
90 	return (struct node_mbuf_priv2 *)rte_mbuf_to_priv(m);
91 }
92 
93 #define NODE_INCREMENT_XSTAT_ID(node, id, cond, cnt) \
94 do { \
95 	if (unlikely(rte_graph_has_stats_feature() && (cond))) \
96 		((uint64_t *)RTE_PTR_ADD(node, node->xstat_off))[id] += (cnt); \
97 } while (0)
98 
99 #endif /* __NODE_PRIVATE_H__ */
100