1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019-2021 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _BNXT_ULP_H_ 7 #define _BNXT_ULP_H_ 8 9 #include <inttypes.h> 10 #include <stdbool.h> 11 #include <sys/queue.h> 12 13 #include "rte_ethdev.h" 14 15 #include "ulp_template_db_enum.h" 16 #include "ulp_tun.h" 17 #include "bnxt_tf_common.h" 18 19 /* NAT defines to reuse existing inner L2 SMAC and DMAC */ 20 #define BNXT_ULP_NAT_INNER_L2_HEADER_SMAC 0x2000 21 #define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC 0x6000 22 #define BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS 0xc00 23 #define BNXT_ULP_NAT_INNER_L2_HEADER_DMAC 0x100 24 #define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC 0x300 25 #define BNXT_ULP_NAT_OUTER_MOST_FLAGS (BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC |\ 26 BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS |\ 27 BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC) 28 29 /* defines for the ulp_flags */ 30 #define BNXT_ULP_VF_REP_ENABLED 0x1 31 #define ULP_VF_REP_IS_ENABLED(flag) ((flag) & BNXT_ULP_VF_REP_ENABLED) 32 33 enum bnxt_ulp_flow_mem_type { 34 BNXT_ULP_FLOW_MEM_TYPE_INT = 0, 35 BNXT_ULP_FLOW_MEM_TYPE_EXT = 1, 36 BNXT_ULP_FLOW_MEM_TYPE_BOTH = 2, 37 BNXT_ULP_FLOW_MEM_TYPE_LAST = 3 38 }; 39 40 struct bnxt_ulp_df_rule_info { 41 uint32_t port_to_app_flow_id; 42 uint32_t app_to_port_flow_id; 43 uint8_t valid; 44 }; 45 46 struct bnxt_ulp_vfr_rule_info { 47 uint32_t rep2vf_flow_id; 48 uint32_t vf2rep_flow_id; 49 uint16_t parent_port_id; 50 uint8_t valid; 51 }; 52 53 struct bnxt_ulp_data { 54 uint32_t tbl_scope_id; 55 struct bnxt_ulp_mark_tbl *mark_tbl; 56 uint32_t dev_id; /* Hardware device id */ 57 uint32_t ref_cnt; 58 struct bnxt_ulp_flow_db *flow_db; 59 pthread_mutex_t flow_db_lock; 60 void *mapper_data; 61 struct bnxt_ulp_port_db *port_db; 62 struct bnxt_ulp_fc_info *fc_info; 63 uint32_t ulp_flags; 64 struct bnxt_ulp_df_rule_info df_rule_info[RTE_MAX_ETHPORTS]; 65 struct bnxt_ulp_vfr_rule_info vfr_rule_info[RTE_MAX_ETHPORTS]; 66 enum bnxt_ulp_flow_mem_type mem_type; 67 #define BNXT_ULP_TUN_ENTRY_INVALID -1 68 #define BNXT_ULP_MAX_TUN_CACHE_ENTRIES 16 69 struct bnxt_tun_cache_entry tun_tbl[BNXT_ULP_MAX_TUN_CACHE_ENTRIES]; 70 }; 71 72 struct bnxt_ulp_context { 73 struct bnxt_ulp_data *cfg_data; 74 struct tf *g_tfp; 75 }; 76 77 struct bnxt_ulp_pci_info { 78 uint32_t domain; 79 uint8_t bus; 80 }; 81 82 struct bnxt_ulp_session_state { 83 STAILQ_ENTRY(bnxt_ulp_session_state) next; 84 bool bnxt_ulp_init; 85 pthread_mutex_t bnxt_ulp_mutex; 86 struct bnxt_ulp_pci_info pci_info; 87 struct bnxt_ulp_data *cfg_data; 88 struct tf *g_tfp; 89 uint32_t session_opened; 90 }; 91 92 /* ULP flow id structure */ 93 struct rte_tf_flow { 94 uint32_t flow_id; 95 }; 96 97 struct ulp_tlv_param { 98 enum bnxt_ulp_df_param_type type; 99 uint32_t length; 100 uint8_t value[16]; 101 }; 102 103 /* 104 * Allow the deletion of context only for the bnxt device that 105 * created the session 106 */ 107 bool 108 ulp_ctx_deinit_allowed(struct bnxt_ulp_context *ulp_ctx); 109 110 /* Function to set the device id of the hardware. */ 111 int32_t 112 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx, uint32_t dev_id); 113 114 /* Function to get the device id of the hardware. */ 115 int32_t 116 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx, uint32_t *dev_id); 117 118 /* Function to get whether or not ext mem is used for EM */ 119 int32_t 120 bnxt_ulp_cntxt_mem_type_get(struct bnxt_ulp_context *ulp_ctx, 121 enum bnxt_ulp_flow_mem_type *mem_type); 122 123 /* Function to set whether or not ext mem is used for EM */ 124 int32_t 125 bnxt_ulp_cntxt_mem_type_set(struct bnxt_ulp_context *ulp_ctx, 126 enum bnxt_ulp_flow_mem_type mem_type); 127 128 /* Function to set the table scope id of the EEM table. */ 129 int32_t 130 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx, 131 uint32_t tbl_scope_id); 132 133 /* Function to get the table scope id of the EEM table. */ 134 int32_t 135 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx, 136 uint32_t *tbl_scope_id); 137 138 /* Function to set the tfp session details in the ulp context. */ 139 int32_t 140 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp); 141 142 /* Function to get the tfp session details from ulp context. */ 143 struct tf * 144 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp); 145 146 /* Get the device table entry based on the device id. */ 147 struct bnxt_ulp_device_params * 148 bnxt_ulp_device_params_get(uint32_t dev_id); 149 150 int32_t 151 bnxt_ulp_ctxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx, 152 struct bnxt_ulp_mark_tbl *mark_tbl); 153 154 struct bnxt_ulp_mark_tbl * 155 bnxt_ulp_ctxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx); 156 157 /* Function to set the flow database to the ulp context. */ 158 int32_t 159 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx, 160 struct bnxt_ulp_flow_db *flow_db); 161 162 /* Function to get the flow database from the ulp context. */ 163 struct bnxt_ulp_flow_db * 164 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx); 165 166 /* Function to get the tunnel cache table info from the ulp context. */ 167 struct bnxt_tun_cache_entry * 168 bnxt_ulp_cntxt_ptr2_tun_tbl_get(struct bnxt_ulp_context *ulp_ctx); 169 170 /* Function to get the ulp context from eth device. */ 171 struct bnxt_ulp_context * 172 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev); 173 174 /* Function to add the ulp mapper data to the ulp context */ 175 int32_t 176 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx, 177 void *mapper_data); 178 179 /* Function to get the ulp mapper data from the ulp context */ 180 void * 181 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx); 182 183 /* Function to set the port database to the ulp context. */ 184 int32_t 185 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx, 186 struct bnxt_ulp_port_db *port_db); 187 188 /* Function to get the port database from the ulp context. */ 189 struct bnxt_ulp_port_db * 190 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx); 191 192 /* Function to create default flows. */ 193 int32_t 194 ulp_default_flow_create(struct rte_eth_dev *eth_dev, 195 struct ulp_tlv_param *param_list, 196 uint32_t ulp_class_tid, 197 uint32_t *flow_id); 198 199 /* Function to destroy default flows. */ 200 int32_t 201 ulp_default_flow_destroy(struct rte_eth_dev *eth_dev, 202 uint32_t flow_id); 203 204 int 205 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, 206 struct rte_flow_error *error); 207 208 int32_t 209 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx, 210 struct bnxt_ulp_fc_info *ulp_fc_info); 211 212 struct bnxt_ulp_fc_info * 213 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx); 214 215 int32_t 216 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx, 217 uint32_t *flags); 218 219 int32_t 220 bnxt_ulp_get_df_rule_info(uint8_t port_id, struct bnxt_ulp_context *ulp_ctx, 221 struct bnxt_ulp_df_rule_info *info); 222 223 struct bnxt_ulp_vfr_rule_info* 224 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx, 225 uint32_t port_id); 226 227 int32_t 228 bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx); 229 230 void 231 bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx); 232 233 int32_t 234 ulp_post_process_tun_flow(struct ulp_rte_parser_params *params); 235 236 #endif /* _BNXT_ULP_H_ */ 237