1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2020 Marvell International Ltd. 3 */ 4 #ifndef _IPSEC_SECGW_H_ 5 #define _IPSEC_SECGW_H_ 6 7 #include <stdbool.h> 8 9 #ifndef STATS_INTERVAL 10 #define STATS_INTERVAL 0 11 #endif 12 13 #define NB_SOCKETS 4 14 15 #define MAX_PKT_BURST 32 16 17 #define RTE_LOGTYPE_IPSEC RTE_LOGTYPE_USER1 18 19 #if RTE_BYTE_ORDER != RTE_LITTLE_ENDIAN 20 #define __BYTES_TO_UINT64(a, b, c, d, e, f, g, h) \ 21 (((uint64_t)((a) & 0xff) << 56) | \ 22 ((uint64_t)((b) & 0xff) << 48) | \ 23 ((uint64_t)((c) & 0xff) << 40) | \ 24 ((uint64_t)((d) & 0xff) << 32) | \ 25 ((uint64_t)((e) & 0xff) << 24) | \ 26 ((uint64_t)((f) & 0xff) << 16) | \ 27 ((uint64_t)((g) & 0xff) << 8) | \ 28 ((uint64_t)(h) & 0xff)) 29 #else 30 #define __BYTES_TO_UINT64(a, b, c, d, e, f, g, h) \ 31 (((uint64_t)((h) & 0xff) << 56) | \ 32 ((uint64_t)((g) & 0xff) << 48) | \ 33 ((uint64_t)((f) & 0xff) << 40) | \ 34 ((uint64_t)((e) & 0xff) << 32) | \ 35 ((uint64_t)((d) & 0xff) << 24) | \ 36 ((uint64_t)((c) & 0xff) << 16) | \ 37 ((uint64_t)((b) & 0xff) << 8) | \ 38 ((uint64_t)(a) & 0xff)) 39 #endif 40 41 #define ETHADDR(a, b, c, d, e, f) (__BYTES_TO_UINT64(a, b, c, d, e, f, 0, 0)) 42 43 struct traffic_type { 44 const uint8_t *data[MAX_PKT_BURST * 2]; 45 struct rte_mbuf *pkts[MAX_PKT_BURST * 2]; 46 void *saptr[MAX_PKT_BURST * 2]; 47 uint32_t res[MAX_PKT_BURST * 2]; 48 uint32_t num; 49 }; 50 51 struct ipsec_traffic { 52 struct traffic_type ipsec; 53 struct traffic_type ip4; 54 struct traffic_type ip6; 55 }; 56 57 /* Fields optimized for devices without burst */ 58 struct traffic_type_nb { 59 const uint8_t *data; 60 struct rte_mbuf *pkt; 61 uint32_t res; 62 uint32_t num; 63 }; 64 65 struct ipsec_traffic_nb { 66 struct traffic_type_nb ipsec; 67 struct traffic_type_nb ip4; 68 struct traffic_type_nb ip6; 69 }; 70 71 /* port/source ethernet addr and destination ethernet addr */ 72 struct ethaddr_info { 73 uint64_t src, dst; 74 }; 75 76 #if (STATS_INTERVAL > 0) 77 struct ipsec_core_statistics { 78 uint64_t tx; 79 uint64_t rx; 80 uint64_t rx_call; 81 uint64_t tx_call; 82 uint64_t dropped; 83 uint64_t burst_rx; 84 } __rte_cache_aligned; 85 86 struct ipsec_core_statistics core_statistics[RTE_MAX_LCORE]; 87 #endif /* STATS_INTERVAL */ 88 89 extern struct ethaddr_info ethaddr_tbl[RTE_MAX_ETHPORTS]; 90 91 /* Port mask to identify the unprotected ports */ 92 extern uint32_t unprotected_port_mask; 93 94 /* Index of SA in single mode */ 95 extern uint32_t single_sa_idx; 96 97 extern volatile bool force_quit; 98 99 static inline uint8_t 100 is_unprotected_port(uint16_t port_id) 101 { 102 return unprotected_port_mask & (1 << port_id); 103 } 104 105 static inline void 106 core_stats_update_rx(int n) 107 { 108 #if (STATS_INTERVAL > 0) 109 int lcore_id = rte_lcore_id(); 110 core_statistics[lcore_id].rx += n; 111 core_statistics[lcore_id].rx_call++; 112 if (n == MAX_PKT_BURST) 113 core_statistics[lcore_id].burst_rx += n; 114 #else 115 RTE_SET_USED(n); 116 #endif /* STATS_INTERVAL */ 117 } 118 119 static inline void 120 core_stats_update_tx(int n) 121 { 122 #if (STATS_INTERVAL > 0) 123 int lcore_id = rte_lcore_id(); 124 core_statistics[lcore_id].tx += n; 125 core_statistics[lcore_id].tx_call++; 126 #else 127 RTE_SET_USED(n); 128 #endif /* STATS_INTERVAL */ 129 } 130 131 static inline void 132 core_stats_update_drop(int n) 133 { 134 #if (STATS_INTERVAL > 0) 135 int lcore_id = rte_lcore_id(); 136 core_statistics[lcore_id].dropped += n; 137 #else 138 RTE_SET_USED(n); 139 #endif /* STATS_INTERVAL */ 140 } 141 142 /* helper routine to free bulk of packets */ 143 static inline void 144 free_pkts(struct rte_mbuf *mb[], uint32_t n) 145 { 146 uint32_t i; 147 148 for (i = 0; i != n; i++) 149 rte_pktmbuf_free(mb[i]); 150 151 core_stats_update_drop(n); 152 } 153 154 #endif /* _IPSEC_SECGW_H_ */ 155