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