199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(C) 2020 Marvell International Ltd. 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef __NODE_PRIVATE_H__ 699a2dd95SBruce Richardson #define __NODE_PRIVATE_H__ 799a2dd95SBruce Richardson 808966fe7STyler Retzlaff #include <stdalign.h> 908966fe7STyler Retzlaff 1099a2dd95SBruce Richardson #include <rte_common.h> 1199a2dd95SBruce Richardson #include <rte_log.h> 1299a2dd95SBruce Richardson #include <rte_mbuf.h> 1399a2dd95SBruce Richardson #include <rte_mbuf_dyn.h> 1499a2dd95SBruce Richardson 15*be4c0cb4SPavan Nikhilesh #include <rte_graph_worker_common.h> 16*be4c0cb4SPavan Nikhilesh 1799a2dd95SBruce Richardson extern int rte_node_logtype; 1897433132SDavid Marchand #define RTE_LOGTYPE_NODE rte_node_logtype 1997433132SDavid Marchand 2099a2dd95SBruce Richardson #define NODE_LOG(level, node_name, ...) \ 210f1dc8cbSTyler Retzlaff RTE_LOG_LINE_PREFIX(level, NODE, "%s: %s():%u ", \ 220f1dc8cbSTyler Retzlaff node_name RTE_LOG_COMMA __func__ RTE_LOG_COMMA __LINE__, \ 230f1dc8cbSTyler Retzlaff __VA_ARGS__) 2499a2dd95SBruce Richardson 2599a2dd95SBruce Richardson #define node_err(node_name, ...) NODE_LOG(ERR, node_name, __VA_ARGS__) 2699a2dd95SBruce Richardson #define node_info(node_name, ...) NODE_LOG(INFO, node_name, __VA_ARGS__) 2799a2dd95SBruce Richardson #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__) 2899a2dd95SBruce Richardson 2999a2dd95SBruce Richardson /** 3099a2dd95SBruce Richardson * Node mbuf private data to store next hop, ttl and checksum. 3199a2dd95SBruce Richardson */ 3299a2dd95SBruce Richardson struct node_mbuf_priv1 { 3399a2dd95SBruce Richardson union { 3420365d79SSunil Kumar Kori /* IP4/IP6 rewrite */ 3599a2dd95SBruce Richardson struct { 3699a2dd95SBruce Richardson uint16_t nh; 3799a2dd95SBruce Richardson uint16_t ttl; 3899a2dd95SBruce Richardson uint32_t cksum; 3999a2dd95SBruce Richardson }; 4099a2dd95SBruce Richardson 4199a2dd95SBruce Richardson uint64_t u; 4299a2dd95SBruce Richardson }; 4399a2dd95SBruce Richardson }; 4499a2dd95SBruce Richardson 4599a2dd95SBruce Richardson static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = { 4699a2dd95SBruce Richardson .name = "rte_node_dynfield_priv1", 4799a2dd95SBruce Richardson .size = sizeof(struct node_mbuf_priv1), 4808966fe7STyler Retzlaff .align = alignof(struct node_mbuf_priv1), 4999a2dd95SBruce Richardson }; 5099a2dd95SBruce Richardson extern int node_mbuf_priv1_dynfield_offset; 5199a2dd95SBruce Richardson 5299a2dd95SBruce Richardson /** 5399a2dd95SBruce Richardson * Node mbuf private area 2. 5499a2dd95SBruce Richardson */ 55c6552d9aSTyler Retzlaff struct __rte_cache_aligned node_mbuf_priv2 { 5699a2dd95SBruce Richardson uint64_t priv_data; 57c6552d9aSTyler Retzlaff }; 5899a2dd95SBruce Richardson 5999a2dd95SBruce Richardson #define NODE_MBUF_PRIV2_SIZE sizeof(struct node_mbuf_priv2) 6099a2dd95SBruce Richardson 6199a2dd95SBruce Richardson #define OBJS_PER_CLINE (RTE_CACHE_LINE_SIZE / sizeof(void *)) 6299a2dd95SBruce Richardson 6399a2dd95SBruce Richardson /** 6499a2dd95SBruce Richardson * Get mbuf_priv1 pointer from rte_mbuf. 6599a2dd95SBruce Richardson * 6699a2dd95SBruce Richardson * @param 6799a2dd95SBruce Richardson * Pointer to the rte_mbuf. 6899a2dd95SBruce Richardson * 6999a2dd95SBruce Richardson * @return 7099a2dd95SBruce Richardson * Pointer to the mbuf_priv1. 7199a2dd95SBruce Richardson */ 7299a2dd95SBruce Richardson static __rte_always_inline struct node_mbuf_priv1 * 7399a2dd95SBruce Richardson node_mbuf_priv1(struct rte_mbuf *m, const int offset) 7499a2dd95SBruce Richardson { 7599a2dd95SBruce Richardson return RTE_MBUF_DYNFIELD(m, offset, struct node_mbuf_priv1 *); 7699a2dd95SBruce Richardson } 7799a2dd95SBruce Richardson 7899a2dd95SBruce Richardson /** 7999a2dd95SBruce Richardson * Get mbuf_priv2 pointer from rte_mbuf. 8099a2dd95SBruce Richardson * 8199a2dd95SBruce Richardson * @param 8299a2dd95SBruce Richardson * Pointer to the rte_mbuf. 8399a2dd95SBruce Richardson * 8499a2dd95SBruce Richardson * @return 8599a2dd95SBruce Richardson * Pointer to the mbuf_priv2. 8699a2dd95SBruce Richardson */ 8799a2dd95SBruce Richardson static __rte_always_inline struct node_mbuf_priv2 * 8899a2dd95SBruce Richardson node_mbuf_priv2(struct rte_mbuf *m) 8999a2dd95SBruce Richardson { 9099a2dd95SBruce Richardson return (struct node_mbuf_priv2 *)rte_mbuf_to_priv(m); 9199a2dd95SBruce Richardson } 9299a2dd95SBruce Richardson 93*be4c0cb4SPavan Nikhilesh #define NODE_INCREMENT_XSTAT_ID(node, id, cond, cnt) \ 94*be4c0cb4SPavan Nikhilesh do { \ 95*be4c0cb4SPavan Nikhilesh if (unlikely(rte_graph_has_stats_feature() && (cond))) \ 96*be4c0cb4SPavan Nikhilesh ((uint64_t *)RTE_PTR_ADD(node, node->xstat_off))[id] += (cnt); \ 97*be4c0cb4SPavan Nikhilesh } while (0) 98*be4c0cb4SPavan Nikhilesh 9999a2dd95SBruce Richardson #endif /* __NODE_PRIVATE_H__ */ 100