10c036a14SPeter Spreadborough /* SPDX-License-Identifier: BSD-3-Clause 20c036a14SPeter Spreadborough * Copyright(c) 2019-2023 Broadcom 30c036a14SPeter Spreadborough * All rights reserved. 40c036a14SPeter Spreadborough */ 50c036a14SPeter Spreadborough 60c036a14SPeter Spreadborough #ifndef _BNXT_ULP_UTILS_H_ 70c036a14SPeter Spreadborough #define _BNXT_ULP_UTILS_H_ 80c036a14SPeter Spreadborough 90c036a14SPeter Spreadborough #include <rte_log.h> 100c036a14SPeter Spreadborough #include <rte_malloc.h> 110c036a14SPeter Spreadborough #include <rte_flow.h> 120c036a14SPeter Spreadborough #include <rte_flow_driver.h> 130c036a14SPeter Spreadborough #include <rte_tailq.h> 140c036a14SPeter Spreadborough #include <rte_spinlock.h> 150c036a14SPeter Spreadborough 160c036a14SPeter Spreadborough #include "bnxt.h" 170c036a14SPeter Spreadborough #include "bnxt_ulp.h" 180c036a14SPeter Spreadborough #include "bnxt_tf_common.h" 190c036a14SPeter Spreadborough #include "bnxt_hwrm.h" 200c036a14SPeter Spreadborough #include "hsi_struct_def_dpdk.h" 210c036a14SPeter Spreadborough #include "tf_core.h" 220c036a14SPeter Spreadborough #include "tf_ext_flow_handle.h" 230c036a14SPeter Spreadborough 240c036a14SPeter Spreadborough #include "ulp_template_db_enum.h" 250c036a14SPeter Spreadborough #include "ulp_template_struct.h" 260c036a14SPeter Spreadborough #include "ulp_mark_mgr.h" 270c036a14SPeter Spreadborough #include "ulp_fc_mgr.h" 28*0513f0afSPeter Spreadborough #include "ulp_sc_mgr.h" 290c036a14SPeter Spreadborough #include "ulp_flow_db.h" 300c036a14SPeter Spreadborough #include "ulp_mapper.h" 310c036a14SPeter Spreadborough #include "ulp_matcher.h" 320c036a14SPeter Spreadborough #include "ulp_port_db.h" 330c036a14SPeter Spreadborough #include "ulp_tun.h" 340c036a14SPeter Spreadborough #include "ulp_ha_mgr.h" 350c036a14SPeter Spreadborough #include "bnxt_tf_pmd_shim.h" 360c036a14SPeter Spreadborough #include "ulp_template_db_tbl.h" 370c036a14SPeter Spreadborough 380c036a14SPeter Spreadborough static inline int32_t 390c036a14SPeter Spreadborough bnxt_ulp_devid_get(struct bnxt *bp, 400c036a14SPeter Spreadborough enum bnxt_ulp_device_id *ulp_dev_id) 410c036a14SPeter Spreadborough { 420c036a14SPeter Spreadborough if (BNXT_CHIP_P7(bp)) { 430c036a14SPeter Spreadborough *ulp_dev_id = BNXT_ULP_DEVICE_ID_THOR2; 440c036a14SPeter Spreadborough return 0; 450c036a14SPeter Spreadborough } 460c036a14SPeter Spreadborough 470c036a14SPeter Spreadborough if (BNXT_CHIP_P5(bp)) { 480c036a14SPeter Spreadborough *ulp_dev_id = BNXT_ULP_DEVICE_ID_THOR; 490c036a14SPeter Spreadborough return 0; 500c036a14SPeter Spreadborough } 510c036a14SPeter Spreadborough 520c036a14SPeter Spreadborough if (BNXT_STINGRAY(bp)) 530c036a14SPeter Spreadborough *ulp_dev_id = BNXT_ULP_DEVICE_ID_STINGRAY; 540c036a14SPeter Spreadborough else 550c036a14SPeter Spreadborough /* Assuming Whitney */ 560c036a14SPeter Spreadborough *ulp_dev_id = BNXT_ULP_DEVICE_ID_WH_PLUS; 570c036a14SPeter Spreadborough 580c036a14SPeter Spreadborough return 0; 590c036a14SPeter Spreadborough } 600c036a14SPeter Spreadborough 610c036a14SPeter Spreadborough static inline struct bnxt_ulp_app_capabilities_info * 620c036a14SPeter Spreadborough bnxt_ulp_app_cap_list_get(uint32_t *num_entries) 630c036a14SPeter Spreadborough { 640c036a14SPeter Spreadborough if (unlikely(!num_entries)) 650c036a14SPeter Spreadborough return NULL; 660c036a14SPeter Spreadborough *num_entries = BNXT_ULP_APP_CAP_TBL_MAX_SZ; 670c036a14SPeter Spreadborough return ulp_app_cap_info_list; 680c036a14SPeter Spreadborough } 690c036a14SPeter Spreadborough 700c036a14SPeter Spreadborough static inline struct bnxt_ulp_shared_act_info * 710c036a14SPeter Spreadborough bnxt_ulp_shared_act_info_get(uint32_t *num_entries) 720c036a14SPeter Spreadborough { 730c036a14SPeter Spreadborough if (unlikely(!num_entries)) 740c036a14SPeter Spreadborough return NULL; 750c036a14SPeter Spreadborough 760c036a14SPeter Spreadborough *num_entries = BNXT_ULP_GEN_TBL_MAX_SZ; 770c036a14SPeter Spreadborough 780c036a14SPeter Spreadborough return ulp_shared_act_info; 790c036a14SPeter Spreadborough } 800c036a14SPeter Spreadborough 810c036a14SPeter Spreadborough static inline struct bnxt_ulp_resource_resv_info * 820c036a14SPeter Spreadborough bnxt_ulp_app_resource_resv_list_get(uint32_t *num_entries) 830c036a14SPeter Spreadborough { 840c036a14SPeter Spreadborough if (unlikely(num_entries == NULL)) 850c036a14SPeter Spreadborough return NULL; 860c036a14SPeter Spreadborough *num_entries = BNXT_ULP_APP_RESOURCE_RESV_LIST_MAX_SZ; 870c036a14SPeter Spreadborough return ulp_app_resource_resv_list; 880c036a14SPeter Spreadborough } 890c036a14SPeter Spreadborough 900c036a14SPeter Spreadborough static inline struct bnxt_ulp_resource_resv_info * 910c036a14SPeter Spreadborough bnxt_ulp_resource_resv_list_get(uint32_t *num_entries) 920c036a14SPeter Spreadborough { 930c036a14SPeter Spreadborough if (unlikely(!num_entries)) 940c036a14SPeter Spreadborough return NULL; 950c036a14SPeter Spreadborough *num_entries = BNXT_ULP_RESOURCE_RESV_LIST_MAX_SZ; 960c036a14SPeter Spreadborough return ulp_resource_resv_list; 970c036a14SPeter Spreadborough } 980c036a14SPeter Spreadborough 990c036a14SPeter Spreadborough static inline struct bnxt_ulp_glb_resource_info * 1000c036a14SPeter Spreadborough bnxt_ulp_app_glb_resource_info_list_get(uint32_t *num_entries) 1010c036a14SPeter Spreadborough { 1020c036a14SPeter Spreadborough if (unlikely(!num_entries)) 1030c036a14SPeter Spreadborough return NULL; 1040c036a14SPeter Spreadborough *num_entries = BNXT_ULP_APP_GLB_RESOURCE_TBL_MAX_SZ; 1050c036a14SPeter Spreadborough return ulp_app_glb_resource_tbl; 1060c036a14SPeter Spreadborough } 1070c036a14SPeter Spreadborough 1080c036a14SPeter Spreadborough /* Function to set the number for vxlan_ip (custom vxlan) port into the context */ 1090c036a14SPeter Spreadborough static inline int 1100c036a14SPeter Spreadborough bnxt_ulp_cntxt_ecpri_udp_port_set(struct bnxt_ulp_context *ulp_ctx, 1110c036a14SPeter Spreadborough uint32_t ecpri_udp_port) 1120c036a14SPeter Spreadborough { 1130c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1140c036a14SPeter Spreadborough return -EINVAL; 1150c036a14SPeter Spreadborough 1160c036a14SPeter Spreadborough ulp_ctx->cfg_data->ecpri_udp_port = ecpri_udp_port; 1170c036a14SPeter Spreadborough 1180c036a14SPeter Spreadborough return 0; 1190c036a14SPeter Spreadborough } 1200c036a14SPeter Spreadborough 1210c036a14SPeter Spreadborough /* Function to retrieve the vxlan_ip (custom vxlan) port from the context. */ 1220c036a14SPeter Spreadborough static inline unsigned int 1230c036a14SPeter Spreadborough bnxt_ulp_cntxt_ecpri_udp_port_get(struct bnxt_ulp_context *ulp_ctx) 1240c036a14SPeter Spreadborough { 1250c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1260c036a14SPeter Spreadborough return 0; 1270c036a14SPeter Spreadborough 1280c036a14SPeter Spreadborough return (unsigned int)ulp_ctx->cfg_data->ecpri_udp_port; 1290c036a14SPeter Spreadborough } 1300c036a14SPeter Spreadborough 1310c036a14SPeter Spreadborough /* Function to set the number for vxlan_ip (custom vxlan) port into the context */ 1320c036a14SPeter Spreadborough static inline int 1330c036a14SPeter Spreadborough bnxt_ulp_cntxt_vxlan_ip_port_set(struct bnxt_ulp_context *ulp_ctx, 1340c036a14SPeter Spreadborough uint32_t vxlan_ip_port) 1350c036a14SPeter Spreadborough { 1360c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1370c036a14SPeter Spreadborough return -EINVAL; 1380c036a14SPeter Spreadborough 1390c036a14SPeter Spreadborough ulp_ctx->cfg_data->vxlan_ip_port = vxlan_ip_port; 1400c036a14SPeter Spreadborough if (vxlan_ip_port) 1410c036a14SPeter Spreadborough ulp_ctx->cfg_data->ulp_flags |= BNXT_ULP_STATIC_VXLAN_SUPPORT; 1420c036a14SPeter Spreadborough return 0; 1430c036a14SPeter Spreadborough } 1440c036a14SPeter Spreadborough 1450c036a14SPeter Spreadborough /* Function to retrieve the vxlan_ip (custom vxlan) port from the context. */ 1460c036a14SPeter Spreadborough static inline unsigned int 1470c036a14SPeter Spreadborough bnxt_ulp_cntxt_vxlan_ip_port_get(struct bnxt_ulp_context *ulp_ctx) 1480c036a14SPeter Spreadborough { 1490c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1500c036a14SPeter Spreadborough return 0; 1510c036a14SPeter Spreadborough 1520c036a14SPeter Spreadborough return (unsigned int)ulp_ctx->cfg_data->vxlan_ip_port; 1530c036a14SPeter Spreadborough } 1540c036a14SPeter Spreadborough 1550c036a14SPeter Spreadborough /* Function to set the number for vxlan_gpe next_proto into the context */ 1560c036a14SPeter Spreadborough static inline uint32_t 1570c036a14SPeter Spreadborough bnxt_ulp_vxlan_gpe_next_proto_set(struct bnxt_ulp_context *ulp_ctx, 1580c036a14SPeter Spreadborough uint8_t tunnel_next_proto) 1590c036a14SPeter Spreadborough { 1600c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1610c036a14SPeter Spreadborough return -EINVAL; 1620c036a14SPeter Spreadborough 1630c036a14SPeter Spreadborough ulp_ctx->cfg_data->tunnel_next_proto = tunnel_next_proto; 1640c036a14SPeter Spreadborough 1650c036a14SPeter Spreadborough return 0; 1660c036a14SPeter Spreadborough } 1670c036a14SPeter Spreadborough 1680c036a14SPeter Spreadborough /* Function to retrieve the vxlan_gpe next_proto from the context. */ 1690c036a14SPeter Spreadborough static inline uint8_t 1700c036a14SPeter Spreadborough bnxt_ulp_vxlan_gpe_next_proto_get(struct bnxt_ulp_context *ulp_ctx) 1710c036a14SPeter Spreadborough { 1720c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1730c036a14SPeter Spreadborough return 0; 1740c036a14SPeter Spreadborough 1750c036a14SPeter Spreadborough return ulp_ctx->cfg_data->tunnel_next_proto; 1760c036a14SPeter Spreadborough } 1770c036a14SPeter Spreadborough 1780c036a14SPeter Spreadborough /* Function to set the number for vxlan port into the context */ 1790c036a14SPeter Spreadborough static inline int 1800c036a14SPeter Spreadborough bnxt_ulp_cntxt_vxlan_port_set(struct bnxt_ulp_context *ulp_ctx, 1810c036a14SPeter Spreadborough uint32_t vxlan_port) 1820c036a14SPeter Spreadborough { 1830c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1840c036a14SPeter Spreadborough return -EINVAL; 1850c036a14SPeter Spreadborough 1860c036a14SPeter Spreadborough ulp_ctx->cfg_data->vxlan_port = vxlan_port; 1870c036a14SPeter Spreadborough if (vxlan_port) 1880c036a14SPeter Spreadborough ulp_ctx->cfg_data->ulp_flags |= BNXT_ULP_STATIC_VXLAN_SUPPORT; 1890c036a14SPeter Spreadborough 1900c036a14SPeter Spreadborough return 0; 1910c036a14SPeter Spreadborough } 1920c036a14SPeter Spreadborough 1930c036a14SPeter Spreadborough /* Function to retrieve the vxlan port from the context. */ 1940c036a14SPeter Spreadborough static inline unsigned int 1950c036a14SPeter Spreadborough bnxt_ulp_cntxt_vxlan_port_get(struct bnxt_ulp_context *ulp_ctx) 1960c036a14SPeter Spreadborough { 1970c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1980c036a14SPeter Spreadborough return 0; 1990c036a14SPeter Spreadborough 2000c036a14SPeter Spreadborough return (unsigned int)ulp_ctx->cfg_data->vxlan_port; 2010c036a14SPeter Spreadborough } 2020c036a14SPeter Spreadborough 2030c036a14SPeter Spreadborough static inline int 2040c036a14SPeter Spreadborough bnxt_ulp_default_app_priority_set(struct bnxt_ulp_context *ulp_ctx, 2050c036a14SPeter Spreadborough uint32_t prio) 2060c036a14SPeter Spreadborough { 2070c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 2080c036a14SPeter Spreadborough return -EINVAL; 2090c036a14SPeter Spreadborough 2100c036a14SPeter Spreadborough ulp_ctx->cfg_data->default_priority = prio; 2110c036a14SPeter Spreadborough return 0; 2120c036a14SPeter Spreadborough } 2130c036a14SPeter Spreadborough 2140c036a14SPeter Spreadborough static inline unsigned int 2150c036a14SPeter Spreadborough bnxt_ulp_default_app_priority_get(struct bnxt_ulp_context *ulp_ctx) 2160c036a14SPeter Spreadborough { 2170c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 2180c036a14SPeter Spreadborough return 0; 2190c036a14SPeter Spreadborough 2200c036a14SPeter Spreadborough return (unsigned int)ulp_ctx->cfg_data->default_priority; 2210c036a14SPeter Spreadborough } 2220c036a14SPeter Spreadborough 2230c036a14SPeter Spreadborough static inline int 2240c036a14SPeter Spreadborough bnxt_ulp_max_def_priority_set(struct bnxt_ulp_context *ulp_ctx, 2250c036a14SPeter Spreadborough uint32_t prio) 2260c036a14SPeter Spreadborough { 2270c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 2280c036a14SPeter Spreadborough return -EINVAL; 2290c036a14SPeter Spreadborough 2300c036a14SPeter Spreadborough ulp_ctx->cfg_data->max_def_priority = prio; 2310c036a14SPeter Spreadborough return 0; 2320c036a14SPeter Spreadborough } 2330c036a14SPeter Spreadborough 2340c036a14SPeter Spreadborough static inline unsigned int 2350c036a14SPeter Spreadborough bnxt_ulp_max_def_priority_get(struct bnxt_ulp_context *ulp_ctx) 2360c036a14SPeter Spreadborough { 2370c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 2380c036a14SPeter Spreadborough return 0; 2390c036a14SPeter Spreadborough 2400c036a14SPeter Spreadborough return (unsigned int)ulp_ctx->cfg_data->max_def_priority; 2410c036a14SPeter Spreadborough } 2420c036a14SPeter Spreadborough 2430c036a14SPeter Spreadborough static inline int 2440c036a14SPeter Spreadborough bnxt_ulp_min_flow_priority_set(struct bnxt_ulp_context *ulp_ctx, uint32_t prio) 2450c036a14SPeter Spreadborough { 2460c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 2470c036a14SPeter Spreadborough return -EINVAL; 2480c036a14SPeter Spreadborough 2490c036a14SPeter Spreadborough ulp_ctx->cfg_data->min_flow_priority = prio; 2500c036a14SPeter Spreadborough return 0; 2510c036a14SPeter Spreadborough } 2520c036a14SPeter Spreadborough 2530c036a14SPeter Spreadborough static inline unsigned int 2540c036a14SPeter Spreadborough bnxt_ulp_min_flow_priority_get(struct bnxt_ulp_context *ulp_ctx) 2550c036a14SPeter Spreadborough { 2560c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 2570c036a14SPeter Spreadborough return 0; 2580c036a14SPeter Spreadborough 2590c036a14SPeter Spreadborough return ulp_ctx->cfg_data->min_flow_priority; 2600c036a14SPeter Spreadborough } 2610c036a14SPeter Spreadborough 2620c036a14SPeter Spreadborough static inline int 2630c036a14SPeter Spreadborough bnxt_ulp_max_flow_priority_set(struct bnxt_ulp_context *ulp_ctx, uint32_t prio) 2640c036a14SPeter Spreadborough { 2650c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 2660c036a14SPeter Spreadborough return -EINVAL; 2670c036a14SPeter Spreadborough 2680c036a14SPeter Spreadborough ulp_ctx->cfg_data->max_flow_priority = prio; 2690c036a14SPeter Spreadborough return 0; 2700c036a14SPeter Spreadborough } 2710c036a14SPeter Spreadborough 2720c036a14SPeter Spreadborough static inline unsigned int 2730c036a14SPeter Spreadborough bnxt_ulp_max_flow_priority_get(struct bnxt_ulp_context *ulp_ctx) 2740c036a14SPeter Spreadborough { 2750c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 2760c036a14SPeter Spreadborough return 0; 2770c036a14SPeter Spreadborough 2780c036a14SPeter Spreadborough return ulp_ctx->cfg_data->max_flow_priority; 2790c036a14SPeter Spreadborough } 2800c036a14SPeter Spreadborough 2810c036a14SPeter Spreadborough /* Below are the access functions to access internal data of ulp context. */ 2820c036a14SPeter Spreadborough /* Function to set the Mark DB into the context */ 2830c036a14SPeter Spreadborough static inline int32_t 2840c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx, 2850c036a14SPeter Spreadborough struct bnxt_ulp_mark_tbl *mark_tbl) 2860c036a14SPeter Spreadborough { 2870c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 2880c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 2890c036a14SPeter Spreadborough return -EINVAL; 2900c036a14SPeter Spreadborough } 2910c036a14SPeter Spreadborough 2920c036a14SPeter Spreadborough ulp_ctx->cfg_data->mark_tbl = mark_tbl; 2930c036a14SPeter Spreadborough 2940c036a14SPeter Spreadborough return 0; 2950c036a14SPeter Spreadborough } 2960c036a14SPeter Spreadborough 2970c036a14SPeter Spreadborough /* Function to retrieve the Mark DB from the context. */ 2980c036a14SPeter Spreadborough static inline struct bnxt_ulp_mark_tbl * 2990c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx) 3000c036a14SPeter Spreadborough { 3010c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 3020c036a14SPeter Spreadborough return NULL; 3030c036a14SPeter Spreadborough 3040c036a14SPeter Spreadborough return ulp_ctx->cfg_data->mark_tbl; 3050c036a14SPeter Spreadborough } 3060c036a14SPeter Spreadborough 3070c036a14SPeter Spreadborough static inline bool 3080c036a14SPeter Spreadborough bnxt_ulp_cntxt_shared_session_enabled(struct bnxt_ulp_context *ulp_ctx) 3090c036a14SPeter Spreadborough { 3100c036a14SPeter Spreadborough return ULP_SHARED_SESSION_IS_ENABLED(ulp_ctx->cfg_data->ulp_flags); 3110c036a14SPeter Spreadborough } 3120c036a14SPeter Spreadborough 3130c036a14SPeter Spreadborough static inline bool 3140c036a14SPeter Spreadborough bnxt_ulp_cntxt_multi_shared_session_enabled(struct bnxt_ulp_context *ulp_ctx) 3150c036a14SPeter Spreadborough { 3160c036a14SPeter Spreadborough return ULP_MULTI_SHARED_IS_SUPPORTED(ulp_ctx); 3170c036a14SPeter Spreadborough } 3180c036a14SPeter Spreadborough 3190c036a14SPeter Spreadborough static inline int32_t 3200c036a14SPeter Spreadborough bnxt_ulp_cntxt_app_id_set(struct bnxt_ulp_context *ulp_ctx, uint8_t app_id) 3210c036a14SPeter Spreadborough { 3220c036a14SPeter Spreadborough if (unlikely(!ulp_ctx)) 3230c036a14SPeter Spreadborough return -EINVAL; 3240c036a14SPeter Spreadborough ulp_ctx->cfg_data->app_id = app_id; 3250c036a14SPeter Spreadborough return 0; 3260c036a14SPeter Spreadborough } 3270c036a14SPeter Spreadborough 3280c036a14SPeter Spreadborough static inline int32_t 3290c036a14SPeter Spreadborough bnxt_ulp_cntxt_app_id_get(struct bnxt_ulp_context *ulp_ctx, uint8_t *app_id) 3300c036a14SPeter Spreadborough { 3310c036a14SPeter Spreadborough /* Default APP id is zero */ 3320c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !app_id)) 3330c036a14SPeter Spreadborough return -EINVAL; 3340c036a14SPeter Spreadborough *app_id = ulp_ctx->cfg_data->app_id; 3350c036a14SPeter Spreadborough return 0; 3360c036a14SPeter Spreadborough } 3370c036a14SPeter Spreadborough 3380c036a14SPeter Spreadborough /* Function to set the device id of the hardware. */ 3390c036a14SPeter Spreadborough static inline int32_t 3400c036a14SPeter Spreadborough bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx, 3410c036a14SPeter Spreadborough uint32_t dev_id) 3420c036a14SPeter Spreadborough { 3430c036a14SPeter Spreadborough if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 3440c036a14SPeter Spreadborough ulp_ctx->cfg_data->dev_id = dev_id; 3450c036a14SPeter Spreadborough return 0; 3460c036a14SPeter Spreadborough } 3470c036a14SPeter Spreadborough 3480c036a14SPeter Spreadborough return -EINVAL; 3490c036a14SPeter Spreadborough } 3500c036a14SPeter Spreadborough 3510c036a14SPeter Spreadborough /* Function to get the device id of the hardware. */ 3520c036a14SPeter Spreadborough static inline int32_t 3530c036a14SPeter Spreadborough bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx, 3540c036a14SPeter Spreadborough uint32_t *dev_id) 3550c036a14SPeter Spreadborough { 3560c036a14SPeter Spreadborough if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 3570c036a14SPeter Spreadborough *dev_id = ulp_ctx->cfg_data->dev_id; 3580c036a14SPeter Spreadborough return 0; 3590c036a14SPeter Spreadborough } 3600c036a14SPeter Spreadborough *dev_id = BNXT_ULP_DEVICE_ID_LAST; 3610c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Failed to read dev_id from ulp ctxt\n"); 3620c036a14SPeter Spreadborough return -EINVAL; 3630c036a14SPeter Spreadborough } 3640c036a14SPeter Spreadborough 3650c036a14SPeter Spreadborough static inline int32_t 3660c036a14SPeter Spreadborough bnxt_ulp_cntxt_mem_type_set(struct bnxt_ulp_context *ulp_ctx, 3670c036a14SPeter Spreadborough enum bnxt_ulp_flow_mem_type mem_type) 3680c036a14SPeter Spreadborough { 3690c036a14SPeter Spreadborough if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 3700c036a14SPeter Spreadborough ulp_ctx->cfg_data->mem_type = mem_type; 3710c036a14SPeter Spreadborough return 0; 3720c036a14SPeter Spreadborough } 3730c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Failed to write mem_type in ulp ctxt\n"); 3740c036a14SPeter Spreadborough return -EINVAL; 3750c036a14SPeter Spreadborough } 3760c036a14SPeter Spreadborough 3770c036a14SPeter Spreadborough static inline int32_t 3780c036a14SPeter Spreadborough bnxt_ulp_cntxt_mem_type_get(struct bnxt_ulp_context *ulp_ctx, 3790c036a14SPeter Spreadborough enum bnxt_ulp_flow_mem_type *mem_type) 3800c036a14SPeter Spreadborough { 3810c036a14SPeter Spreadborough if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 3820c036a14SPeter Spreadborough *mem_type = ulp_ctx->cfg_data->mem_type; 3830c036a14SPeter Spreadborough return 0; 3840c036a14SPeter Spreadborough } 3850c036a14SPeter Spreadborough *mem_type = BNXT_ULP_FLOW_MEM_TYPE_LAST; 3860c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Failed to read mem_type in ulp ctxt\n"); 3870c036a14SPeter Spreadborough return -EINVAL; 3880c036a14SPeter Spreadborough } 3890c036a14SPeter Spreadborough 3900c036a14SPeter Spreadborough /* Function to get the table scope id of the EEM table. */ 3910c036a14SPeter Spreadborough static inline int32_t 3920c036a14SPeter Spreadborough bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx, 3930c036a14SPeter Spreadborough uint32_t *tbl_scope_id) 3940c036a14SPeter Spreadborough { 3950c036a14SPeter Spreadborough if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 3960c036a14SPeter Spreadborough *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id; 3970c036a14SPeter Spreadborough return 0; 3980c036a14SPeter Spreadborough } 3990c036a14SPeter Spreadborough 4000c036a14SPeter Spreadborough return -EINVAL; 4010c036a14SPeter Spreadborough } 4020c036a14SPeter Spreadborough 4030c036a14SPeter Spreadborough /* Function to set the table scope id of the EEM table. */ 4040c036a14SPeter Spreadborough static inline int32_t 4050c036a14SPeter Spreadborough bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx, 4060c036a14SPeter Spreadborough uint32_t tbl_scope_id) 4070c036a14SPeter Spreadborough { 4080c036a14SPeter Spreadborough if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 4090c036a14SPeter Spreadborough ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id; 4100c036a14SPeter Spreadborough return 0; 4110c036a14SPeter Spreadborough } 4120c036a14SPeter Spreadborough 4130c036a14SPeter Spreadborough return -EINVAL; 4140c036a14SPeter Spreadborough } 4150c036a14SPeter Spreadborough 4160c036a14SPeter Spreadborough /* Function to set the v3 table scope id, only works for tfc objects */ 4170c036a14SPeter Spreadborough static inline int32_t 4180c036a14SPeter Spreadborough bnxt_ulp_cntxt_tsid_set(struct bnxt_ulp_context *ulp_ctx, uint8_t tsid) 4190c036a14SPeter Spreadborough { 4200c036a14SPeter Spreadborough if (likely(ulp_ctx && ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC)) { 4210c036a14SPeter Spreadborough ulp_ctx->tsid = tsid; 4220c036a14SPeter Spreadborough ULP_BITMAP_SET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_TSID_FLAG); 4230c036a14SPeter Spreadborough return 0; 4240c036a14SPeter Spreadborough } 4250c036a14SPeter Spreadborough return -EINVAL; 4260c036a14SPeter Spreadborough } 4270c036a14SPeter Spreadborough 4280c036a14SPeter Spreadborough /* Function to reset the v3 table scope id, only works for tfc objects */ 4290c036a14SPeter Spreadborough static inline void 4300c036a14SPeter Spreadborough bnxt_ulp_cntxt_tsid_reset(struct bnxt_ulp_context *ulp_ctx) 4310c036a14SPeter Spreadborough { 4320c036a14SPeter Spreadborough if (ulp_ctx && ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC) 4330c036a14SPeter Spreadborough ULP_BITMAP_RESET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_TSID_FLAG); 4340c036a14SPeter Spreadborough } 4350c036a14SPeter Spreadborough 4360c036a14SPeter Spreadborough /* Function to set the v3 table scope id, only works for tfc objects */ 4370c036a14SPeter Spreadborough static inline int32_t 4380c036a14SPeter Spreadborough bnxt_ulp_cntxt_tsid_get(struct bnxt_ulp_context *ulp_ctx, uint8_t *tsid) 4390c036a14SPeter Spreadborough { 4400c036a14SPeter Spreadborough if (likely(ulp_ctx && tsid && 4410c036a14SPeter Spreadborough ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC && 4420c036a14SPeter Spreadborough ULP_BITMAP_ISSET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_TSID_FLAG))) { 4430c036a14SPeter Spreadborough *tsid = ulp_ctx->tsid; 4440c036a14SPeter Spreadborough return 0; 4450c036a14SPeter Spreadborough } 4460c036a14SPeter Spreadborough return -EINVAL; 4470c036a14SPeter Spreadborough } 4480c036a14SPeter Spreadborough 4490c036a14SPeter Spreadborough /* Function to set the v3 session id, only works for tfc objects */ 4500c036a14SPeter Spreadborough static inline int32_t 4510c036a14SPeter Spreadborough bnxt_ulp_cntxt_sid_set(struct bnxt_ulp_context *ulp_ctx, 4520c036a14SPeter Spreadborough uint16_t sid) 4530c036a14SPeter Spreadborough { 4540c036a14SPeter Spreadborough if (likely(ulp_ctx && ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC)) { 4550c036a14SPeter Spreadborough ulp_ctx->sid = sid; 4560c036a14SPeter Spreadborough ULP_BITMAP_SET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_SID_FLAG); 4570c036a14SPeter Spreadborough return 0; 4580c036a14SPeter Spreadborough } 4590c036a14SPeter Spreadborough return -EINVAL; 4600c036a14SPeter Spreadborough } 4610c036a14SPeter Spreadborough 4620c036a14SPeter Spreadborough /* 4630c036a14SPeter Spreadborough * Function to reset the v3 session id, only works for tfc objects 4640c036a14SPeter Spreadborough * There isn't a known invalid value for sid, so this is necessary 4650c036a14SPeter Spreadborough */ 4660c036a14SPeter Spreadborough static inline void 4670c036a14SPeter Spreadborough bnxt_ulp_cntxt_sid_reset(struct bnxt_ulp_context *ulp_ctx) 4680c036a14SPeter Spreadborough { 4690c036a14SPeter Spreadborough if (ulp_ctx && ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC) 4700c036a14SPeter Spreadborough ULP_BITMAP_RESET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_SID_FLAG); 4710c036a14SPeter Spreadborough } 4720c036a14SPeter Spreadborough 4730c036a14SPeter Spreadborough /* Function to get the v3 session id, only works for tfc objects */ 4740c036a14SPeter Spreadborough static inline int32_t 4750c036a14SPeter Spreadborough bnxt_ulp_cntxt_sid_get(struct bnxt_ulp_context *ulp_ctx, 4760c036a14SPeter Spreadborough uint16_t *sid) 4770c036a14SPeter Spreadborough { 4780c036a14SPeter Spreadborough if (likely(ulp_ctx && sid && 4790c036a14SPeter Spreadborough ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC && 4800c036a14SPeter Spreadborough ULP_BITMAP_ISSET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_SID_FLAG))) { 4810c036a14SPeter Spreadborough *sid = ulp_ctx->sid; 4820c036a14SPeter Spreadborough return 0; 4830c036a14SPeter Spreadborough } 4840c036a14SPeter Spreadborough return -EINVAL; 4850c036a14SPeter Spreadborough } 4860c036a14SPeter Spreadborough 4870c036a14SPeter Spreadborough /* Function to get the number of shared clients attached */ 4880c036a14SPeter Spreadborough static inline uint8_t 4890c036a14SPeter Spreadborough bnxt_ulp_cntxt_num_shared_clients_get(struct bnxt_ulp_context *ulp) 4900c036a14SPeter Spreadborough { 4910c036a14SPeter Spreadborough if (likely(ulp == NULL || ulp->cfg_data == NULL)) { 4920c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid arguments\n"); 4930c036a14SPeter Spreadborough return 0; 4940c036a14SPeter Spreadborough } 4950c036a14SPeter Spreadborough return ulp->cfg_data->num_shared_clients; 4960c036a14SPeter Spreadborough } 4970c036a14SPeter Spreadborough 4980c036a14SPeter Spreadborough /* Function to set the number of shared clients */ 4990c036a14SPeter Spreadborough static inline int 5000c036a14SPeter Spreadborough bnxt_ulp_cntxt_num_shared_clients_set(struct bnxt_ulp_context *ulp, bool incr) 5010c036a14SPeter Spreadborough { 5020c036a14SPeter Spreadborough if (unlikely(ulp == NULL || ulp->cfg_data == NULL)) { 5030c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid arguments\n"); 5040c036a14SPeter Spreadborough return 0; 5050c036a14SPeter Spreadborough } 5060c036a14SPeter Spreadborough if (incr) 5070c036a14SPeter Spreadborough ulp->cfg_data->num_shared_clients++; 5080c036a14SPeter Spreadborough else if (ulp->cfg_data->num_shared_clients) 5090c036a14SPeter Spreadborough ulp->cfg_data->num_shared_clients--; 5100c036a14SPeter Spreadborough 5110c036a14SPeter Spreadborough BNXT_DRV_DBG(DEBUG, "%d:clients(%d)\n", incr, 5120c036a14SPeter Spreadborough ulp->cfg_data->num_shared_clients); 5130c036a14SPeter Spreadborough 5140c036a14SPeter Spreadborough return 0; 5150c036a14SPeter Spreadborough } 5160c036a14SPeter Spreadborough 5170c036a14SPeter Spreadborough static inline int32_t 5180c036a14SPeter Spreadborough bnxt_ulp_cntxt_bp_set(struct bnxt_ulp_context *ulp, struct bnxt *bp) 5190c036a14SPeter Spreadborough { 5200c036a14SPeter Spreadborough if (unlikely(ulp == NULL)) { 5210c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid arguments\n"); 5220c036a14SPeter Spreadborough return -EINVAL; 5230c036a14SPeter Spreadborough } 5240c036a14SPeter Spreadborough ulp->bp = bp; 5250c036a14SPeter Spreadborough return 0; 5260c036a14SPeter Spreadborough } 5270c036a14SPeter Spreadborough 5280c036a14SPeter Spreadborough static inline struct bnxt* 5290c036a14SPeter Spreadborough bnxt_ulp_cntxt_bp_get(struct bnxt_ulp_context *ulp) 5300c036a14SPeter Spreadborough { 5310c036a14SPeter Spreadborough if (unlikely(ulp == NULL)) { 5320c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid arguments\n"); 5330c036a14SPeter Spreadborough return NULL; 5340c036a14SPeter Spreadborough } 5350c036a14SPeter Spreadborough return ulp->bp; 5360c036a14SPeter Spreadborough } 5370c036a14SPeter Spreadborough 5380c036a14SPeter Spreadborough static inline int32_t 5390c036a14SPeter Spreadborough bnxt_ulp_cntxt_fid_get(struct bnxt_ulp_context *ulp, uint16_t *fid) 5400c036a14SPeter Spreadborough { 5410c036a14SPeter Spreadborough if (unlikely(ulp == NULL || fid == NULL)) 5420c036a14SPeter Spreadborough return -EINVAL; 5430c036a14SPeter Spreadborough 5440c036a14SPeter Spreadborough *fid = ulp->bp->fw_fid; 5450c036a14SPeter Spreadborough return 0; 5460c036a14SPeter Spreadborough } 5470c036a14SPeter Spreadborough 5480c036a14SPeter Spreadborough static inline void 5490c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_default_class_bits_set(struct bnxt_ulp_context *ulp_ctx, 5500c036a14SPeter Spreadborough uint64_t bits) 5510c036a14SPeter Spreadborough { 5520c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 5530c036a14SPeter Spreadborough return; 5540c036a14SPeter Spreadborough ulp_ctx->cfg_data->default_class_bits = bits; 5550c036a14SPeter Spreadborough } 5560c036a14SPeter Spreadborough 5570c036a14SPeter Spreadborough static inline uint64_t 5580c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_default_class_bits_get(struct bnxt_ulp_context *ulp_ctx) 5590c036a14SPeter Spreadborough { 5600c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 5610c036a14SPeter Spreadborough return 0; 5620c036a14SPeter Spreadborough return ulp_ctx->cfg_data->default_class_bits; 5630c036a14SPeter Spreadborough } 5640c036a14SPeter Spreadborough 5650c036a14SPeter Spreadborough static inline void 5660c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_default_act_bits_set(struct bnxt_ulp_context *ulp_ctx, 5670c036a14SPeter Spreadborough uint64_t bits) 5680c036a14SPeter Spreadborough { 5690c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 5700c036a14SPeter Spreadborough return; 5710c036a14SPeter Spreadborough ulp_ctx->cfg_data->default_act_bits = bits; 5720c036a14SPeter Spreadborough } 5730c036a14SPeter Spreadborough 5740c036a14SPeter Spreadborough static inline uint64_t 5750c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_default_act_bits_get(struct bnxt_ulp_context *ulp_ctx) 5760c036a14SPeter Spreadborough { 5770c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 5780c036a14SPeter Spreadborough return 0; 5790c036a14SPeter Spreadborough return ulp_ctx->cfg_data->default_act_bits; 5800c036a14SPeter Spreadborough } 5810c036a14SPeter Spreadborough 5820c036a14SPeter Spreadborough /* 5830c036a14SPeter Spreadborough * Get the device table entry based on the device id. 5840c036a14SPeter Spreadborough * 5850c036a14SPeter Spreadborough * dev_id [in] The device id of the hardware 5860c036a14SPeter Spreadborough * 5870c036a14SPeter Spreadborough * Returns the pointer to the device parameters. 5880c036a14SPeter Spreadborough */ 5890c036a14SPeter Spreadborough static inline struct bnxt_ulp_device_params * 5900c036a14SPeter Spreadborough bnxt_ulp_device_params_get(uint32_t dev_id) 5910c036a14SPeter Spreadborough { 5920c036a14SPeter Spreadborough if (dev_id < BNXT_ULP_MAX_NUM_DEVICES) 5930c036a14SPeter Spreadborough return &ulp_device_params[dev_id]; 5940c036a14SPeter Spreadborough return NULL; 5950c036a14SPeter Spreadborough } 5960c036a14SPeter Spreadborough 5970c036a14SPeter Spreadborough /* Function to set the flow database to the ulp context. */ 5980c036a14SPeter Spreadborough static inline int32_t 5990c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx, 6000c036a14SPeter Spreadborough struct bnxt_ulp_flow_db *flow_db) 6010c036a14SPeter Spreadborough { 6020c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 6030c036a14SPeter Spreadborough return -EINVAL; 6040c036a14SPeter Spreadborough 6050c036a14SPeter Spreadborough ulp_ctx->cfg_data->flow_db = flow_db; 6060c036a14SPeter Spreadborough return 0; 6070c036a14SPeter Spreadborough } 6080c036a14SPeter Spreadborough 6090c036a14SPeter Spreadborough /* Function to get the flow database from the ulp context. */ 6100c036a14SPeter Spreadborough static inline struct bnxt_ulp_flow_db * 6110c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx) 6120c036a14SPeter Spreadborough { 6130c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 6140c036a14SPeter Spreadborough return NULL; 6150c036a14SPeter Spreadborough 6160c036a14SPeter Spreadborough return ulp_ctx->cfg_data->flow_db; 6170c036a14SPeter Spreadborough } 6180c036a14SPeter Spreadborough 6190c036a14SPeter Spreadborough /* Function to get the tunnel cache table info from the ulp context. */ 6200c036a14SPeter Spreadborough static inline struct bnxt_tun_cache_entry * 6210c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_tun_tbl_get(struct bnxt_ulp_context *ulp_ctx) 6220c036a14SPeter Spreadborough { 6230c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 6240c036a14SPeter Spreadborough return NULL; 6250c036a14SPeter Spreadborough 6260c036a14SPeter Spreadborough return ulp_ctx->cfg_data->tun_tbl; 6270c036a14SPeter Spreadborough } 6280c036a14SPeter Spreadborough 6290c036a14SPeter Spreadborough /* Function to get the ulp context from eth device. */ 6300c036a14SPeter Spreadborough static inline struct bnxt_ulp_context * 6310c036a14SPeter Spreadborough bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev) 6320c036a14SPeter Spreadborough { 6330c036a14SPeter Spreadborough struct bnxt *bp = (struct bnxt *)dev->data->dev_private; 6340c036a14SPeter Spreadborough 6350c036a14SPeter Spreadborough if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) { 6360c036a14SPeter Spreadborough struct bnxt_representor *vfr = dev->data->dev_private; 6370c036a14SPeter Spreadborough 6380c036a14SPeter Spreadborough bp = vfr->parent_dev->data->dev_private; 6390c036a14SPeter Spreadborough } 6400c036a14SPeter Spreadborough 6410c036a14SPeter Spreadborough if (unlikely(!bp)) { 6420c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Bnxt private data is not initialized\n"); 6430c036a14SPeter Spreadborough return NULL; 6440c036a14SPeter Spreadborough } 6450c036a14SPeter Spreadborough return bp->ulp_ctx; 6460c036a14SPeter Spreadborough } 6470c036a14SPeter Spreadborough 6480c036a14SPeter Spreadborough static inline int32_t 6490c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx, 6500c036a14SPeter Spreadborough void *mapper_data) 6510c036a14SPeter Spreadborough { 6520c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 6530c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 6540c036a14SPeter Spreadborough return -EINVAL; 6550c036a14SPeter Spreadborough } 6560c036a14SPeter Spreadborough 6570c036a14SPeter Spreadborough ulp_ctx->cfg_data->mapper_data = mapper_data; 6580c036a14SPeter Spreadborough return 0; 6590c036a14SPeter Spreadborough } 6600c036a14SPeter Spreadborough 6610c036a14SPeter Spreadborough static inline void * 6620c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx) 6630c036a14SPeter Spreadborough { 6640c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 6650c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 6660c036a14SPeter Spreadborough return NULL; 6670c036a14SPeter Spreadborough } 6680c036a14SPeter Spreadborough 6690c036a14SPeter Spreadborough return ulp_ctx->cfg_data->mapper_data; 6700c036a14SPeter Spreadborough } 6710c036a14SPeter Spreadborough 6720c036a14SPeter Spreadborough static inline int32_t 6730c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_matcher_data_set(struct bnxt_ulp_context *ulp_ctx, 6740c036a14SPeter Spreadborough void *matcher_data) 6750c036a14SPeter Spreadborough { 6760c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 6770c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 6780c036a14SPeter Spreadborough return -EINVAL; 6790c036a14SPeter Spreadborough } 6800c036a14SPeter Spreadborough 6810c036a14SPeter Spreadborough ulp_ctx->cfg_data->matcher_data = matcher_data; 6820c036a14SPeter Spreadborough return 0; 6830c036a14SPeter Spreadborough } 6840c036a14SPeter Spreadborough 6850c036a14SPeter Spreadborough static inline void * 6860c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_matcher_data_get(struct bnxt_ulp_context *ulp_ctx) 6870c036a14SPeter Spreadborough { 6880c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 6890c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 6900c036a14SPeter Spreadborough return NULL; 6910c036a14SPeter Spreadborough } 6920c036a14SPeter Spreadborough 6930c036a14SPeter Spreadborough return ulp_ctx->cfg_data->matcher_data; 6940c036a14SPeter Spreadborough } 6950c036a14SPeter Spreadborough 6960c036a14SPeter Spreadborough /* Function to set the port database to the ulp context. */ 6970c036a14SPeter Spreadborough static inline int32_t 6980c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx, 6990c036a14SPeter Spreadborough struct bnxt_ulp_port_db *port_db) 7000c036a14SPeter Spreadborough { 7010c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 7020c036a14SPeter Spreadborough return -EINVAL; 7030c036a14SPeter Spreadborough 7040c036a14SPeter Spreadborough ulp_ctx->cfg_data->port_db = port_db; 7050c036a14SPeter Spreadborough return 0; 7060c036a14SPeter Spreadborough } 7070c036a14SPeter Spreadborough 7080c036a14SPeter Spreadborough /* Function to get the port database from the ulp context. */ 7090c036a14SPeter Spreadborough static inline struct bnxt_ulp_port_db * 7100c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx) 7110c036a14SPeter Spreadborough { 7120c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 7130c036a14SPeter Spreadborough return NULL; 7140c036a14SPeter Spreadborough 7150c036a14SPeter Spreadborough return ulp_ctx->cfg_data->port_db; 7160c036a14SPeter Spreadborough } 7170c036a14SPeter Spreadborough 7180c036a14SPeter Spreadborough /* Function to set the flow counter info into the context */ 7190c036a14SPeter Spreadborough static inline int32_t 7200c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx, 7210c036a14SPeter Spreadborough struct bnxt_ulp_fc_info *ulp_fc_info) 7220c036a14SPeter Spreadborough { 7230c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 7240c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 7250c036a14SPeter Spreadborough return -EINVAL; 7260c036a14SPeter Spreadborough } 7270c036a14SPeter Spreadborough 7280c036a14SPeter Spreadborough ulp_ctx->cfg_data->fc_info = ulp_fc_info; 7290c036a14SPeter Spreadborough 7300c036a14SPeter Spreadborough return 0; 7310c036a14SPeter Spreadborough } 7320c036a14SPeter Spreadborough 7330c036a14SPeter Spreadborough /* Function to retrieve the flow counter info from the context. */ 7340c036a14SPeter Spreadborough static inline struct bnxt_ulp_fc_info * 7350c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx) 7360c036a14SPeter Spreadborough { 7370c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 7380c036a14SPeter Spreadborough return NULL; 7390c036a14SPeter Spreadborough 7400c036a14SPeter Spreadborough return ulp_ctx->cfg_data->fc_info; 7410c036a14SPeter Spreadborough } 7420c036a14SPeter Spreadborough 743*0513f0afSPeter Spreadborough /* Function to set the flow counter info into the context */ 744*0513f0afSPeter Spreadborough static inline int32_t 745*0513f0afSPeter Spreadborough bnxt_ulp_cntxt_ptr2_sc_info_set(struct bnxt_ulp_context *ulp_ctx, 746*0513f0afSPeter Spreadborough struct bnxt_ulp_sc_info *ulp_sc_info) 747*0513f0afSPeter Spreadborough { 748*0513f0afSPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 749*0513f0afSPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 750*0513f0afSPeter Spreadborough return -EINVAL; 751*0513f0afSPeter Spreadborough } 752*0513f0afSPeter Spreadborough 753*0513f0afSPeter Spreadborough ulp_ctx->cfg_data->sc_info = ulp_sc_info; 754*0513f0afSPeter Spreadborough 755*0513f0afSPeter Spreadborough return 0; 756*0513f0afSPeter Spreadborough } 757*0513f0afSPeter Spreadborough 758*0513f0afSPeter Spreadborough /* Function to retrieve the flow counter info from the context. */ 759*0513f0afSPeter Spreadborough static inline struct bnxt_ulp_sc_info * 760*0513f0afSPeter Spreadborough bnxt_ulp_cntxt_ptr2_sc_info_get(struct bnxt_ulp_context *ulp_ctx) 761*0513f0afSPeter Spreadborough { 762*0513f0afSPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 763*0513f0afSPeter Spreadborough return NULL; 764*0513f0afSPeter Spreadborough 765*0513f0afSPeter Spreadborough return ulp_ctx->cfg_data->sc_info; 766*0513f0afSPeter Spreadborough } 767*0513f0afSPeter Spreadborough 7680c036a14SPeter Spreadborough /* Function to get the ulp flags from the ulp context. */ 7690c036a14SPeter Spreadborough static inline int32_t 7700c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx, 7710c036a14SPeter Spreadborough uint32_t *flags) 7720c036a14SPeter Spreadborough { 7730c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 7740c036a14SPeter Spreadborough return -1; 7750c036a14SPeter Spreadborough 7760c036a14SPeter Spreadborough *flags = ulp_ctx->cfg_data->ulp_flags; 7770c036a14SPeter Spreadborough return 0; 7780c036a14SPeter Spreadborough } 7790c036a14SPeter Spreadborough 7800c036a14SPeter Spreadborough /* Function to get the ulp vfr info from the ulp context. */ 7810c036a14SPeter Spreadborough static inline struct bnxt_ulp_vfr_rule_info* 7820c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx, 7830c036a14SPeter Spreadborough uint32_t port_id) 7840c036a14SPeter Spreadborough { 7850c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || 7860c036a14SPeter Spreadborough !ulp_ctx->cfg_data || 7870c036a14SPeter Spreadborough port_id >= RTE_MAX_ETHPORTS)) 7880c036a14SPeter Spreadborough return NULL; 7890c036a14SPeter Spreadborough 7900c036a14SPeter Spreadborough return &ulp_ctx->cfg_data->vfr_rule_info[port_id]; 7910c036a14SPeter Spreadborough } 7920c036a14SPeter Spreadborough 7930c036a14SPeter Spreadborough /* Function to acquire the flow database lock from the ulp context. */ 7940c036a14SPeter Spreadborough static inline int32_t 7950c036a14SPeter Spreadborough bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx) 7960c036a14SPeter Spreadborough { 7970c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 7980c036a14SPeter Spreadborough return -1; 7990c036a14SPeter Spreadborough 8000c036a14SPeter Spreadborough if (pthread_mutex_lock(&ulp_ctx->cfg_data->flow_db_lock)) { 8010c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "unable to acquire fdb lock\n"); 8020c036a14SPeter Spreadborough return -1; 8030c036a14SPeter Spreadborough } 8040c036a14SPeter Spreadborough return 0; 8050c036a14SPeter Spreadborough } 8060c036a14SPeter Spreadborough 8070c036a14SPeter Spreadborough /* Function to release the flow database lock from the ulp context. */ 8080c036a14SPeter Spreadborough static inline void 8090c036a14SPeter Spreadborough bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx) 8100c036a14SPeter Spreadborough { 8110c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 8120c036a14SPeter Spreadborough return; 8130c036a14SPeter Spreadborough 8140c036a14SPeter Spreadborough pthread_mutex_unlock(&ulp_ctx->cfg_data->flow_db_lock); 8150c036a14SPeter Spreadborough } 8160c036a14SPeter Spreadborough 8170c036a14SPeter Spreadborough #if (RTE_VERSION_NUM(21, 05, 0, 0) > RTE_VERSION) 8180c036a14SPeter Spreadborough 8190c036a14SPeter Spreadborough /* Function to extract the action type from the shared action handle. */ 8200c036a14SPeter Spreadborough static inline uint32_t 8210c036a14SPeter Spreadborough bnxt_get_shared_action_type(const struct rte_flow_shared_action *handle) 8220c036a14SPeter Spreadborough { 8230c036a14SPeter Spreadborough return (uint32_t)(((uint64_t)handle >> 32) & 0xffffffff); 8240c036a14SPeter Spreadborough } 8250c036a14SPeter Spreadborough 8260c036a14SPeter Spreadborough /* Function to extract the direction from the shared action handle. */ 8270c036a14SPeter Spreadborough static inline uint32_t 8280c036a14SPeter Spreadborough bnxt_get_shared_action_direction(const struct rte_flow_shared_action *handle) 8290c036a14SPeter Spreadborough { 8300c036a14SPeter Spreadborough uint32_t shared_type; 8310c036a14SPeter Spreadborough 8320c036a14SPeter Spreadborough shared_type = bnxt_get_shared_action_type(handle); 8330c036a14SPeter Spreadborough return shared_type & 0x1 ? BNXT_ULP_FLOW_ATTR_EGRESS : 8340c036a14SPeter Spreadborough BNXT_ULP_FLOW_ATTR_INGRESS; 8350c036a14SPeter Spreadborough } 8360c036a14SPeter Spreadborough 8370c036a14SPeter Spreadborough /* Function to extract the action index from the shared action handle. */ 8380c036a14SPeter Spreadborough static inline uint32_t 8390c036a14SPeter Spreadborough bnxt_get_shared_action_index(const struct rte_flow_shared_action *handle) 8400c036a14SPeter Spreadborough { 8410c036a14SPeter Spreadborough return (uint32_t)((uint64_t)handle & 0xffffffff); 8420c036a14SPeter Spreadborough } 8430c036a14SPeter Spreadborough 8440c036a14SPeter Spreadborough #else /* (RTE_VERSION >= RTE_VERSION_NUM(21,05,0,0)) */ 8450c036a14SPeter Spreadborough 8460c036a14SPeter Spreadborough /* Function to extract the action type from the shared action handle. */ 8470c036a14SPeter Spreadborough static inline int32_t 8480c036a14SPeter Spreadborough bnxt_get_action_handle_type(const struct rte_flow_action_handle *handle, 8490c036a14SPeter Spreadborough uint32_t *action_handle_type) 8500c036a14SPeter Spreadborough { 8510c036a14SPeter Spreadborough if (unlikely(!action_handle_type)) 8520c036a14SPeter Spreadborough return -EINVAL; 8530c036a14SPeter Spreadborough 8540c036a14SPeter Spreadborough *action_handle_type = (uint32_t)(((uint64_t)handle >> 32) & 0xffffffff); 8550c036a14SPeter Spreadborough if (*action_handle_type >= BNXT_ULP_GEN_TBL_MAX_SZ) 8560c036a14SPeter Spreadborough return -EINVAL; 8570c036a14SPeter Spreadborough 8580c036a14SPeter Spreadborough return 0; 8590c036a14SPeter Spreadborough } 8600c036a14SPeter Spreadborough 8610c036a14SPeter Spreadborough /* Function to extract the direction from the shared action handle. */ 8620c036a14SPeter Spreadborough static inline int32_t 8630c036a14SPeter Spreadborough bnxt_get_action_handle_direction(const struct rte_flow_action_handle *handle, 8640c036a14SPeter Spreadborough uint32_t *dir) 8650c036a14SPeter Spreadborough { 8660c036a14SPeter Spreadborough uint32_t shared_type; 8670c036a14SPeter Spreadborough int32_t ret = 0; 8680c036a14SPeter Spreadborough 8690c036a14SPeter Spreadborough ret = bnxt_get_action_handle_type(handle, &shared_type); 8700c036a14SPeter Spreadborough if (unlikely(ret)) 8710c036a14SPeter Spreadborough return ret; 8720c036a14SPeter Spreadborough 8730c036a14SPeter Spreadborough *dir = shared_type & 0x1 ? BNXT_ULP_DIR_EGRESS : BNXT_ULP_DIR_INGRESS; 8740c036a14SPeter Spreadborough 8750c036a14SPeter Spreadborough return ret; 8760c036a14SPeter Spreadborough } 8770c036a14SPeter Spreadborough 8780c036a14SPeter Spreadborough /* Function to extract the action index from the shared action handle. */ 8790c036a14SPeter Spreadborough static inline uint32_t 8800c036a14SPeter Spreadborough bnxt_get_action_handle_index(const struct rte_flow_action_handle *handle) 8810c036a14SPeter Spreadborough { 8820c036a14SPeter Spreadborough return (uint32_t)((uint64_t)handle & 0xffffffff); 8830c036a14SPeter Spreadborough } 8840c036a14SPeter Spreadborough 8850c036a14SPeter Spreadborough #endif /* RTE_VERSION < RTE_VERSION_NUM(21,05,0,0) */ 8860c036a14SPeter Spreadborough 8870c036a14SPeter Spreadborough /* Function to set the ha info into the context */ 8880c036a14SPeter Spreadborough static inline int32_t 8890c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_ha_info_set(struct bnxt_ulp_context *ulp_ctx, 8900c036a14SPeter Spreadborough struct bnxt_ulp_ha_mgr_info *ulp_ha_info) 8910c036a14SPeter Spreadborough { 8920c036a14SPeter Spreadborough if (unlikely(ulp_ctx == NULL || ulp_ctx->cfg_data == NULL)) { 8930c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 8940c036a14SPeter Spreadborough return -EINVAL; 8950c036a14SPeter Spreadborough } 8960c036a14SPeter Spreadborough ulp_ctx->cfg_data->ha_info = ulp_ha_info; 8970c036a14SPeter Spreadborough return 0; 8980c036a14SPeter Spreadborough } 8990c036a14SPeter Spreadborough 9000c036a14SPeter Spreadborough /* Function to retrieve the ha info from the context. */ 9010c036a14SPeter Spreadborough static inline struct bnxt_ulp_ha_mgr_info * 9020c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_ha_info_get(struct bnxt_ulp_context *ulp_ctx) 9030c036a14SPeter Spreadborough { 9040c036a14SPeter Spreadborough if (unlikely(ulp_ctx == NULL || ulp_ctx->cfg_data == NULL)) 9050c036a14SPeter Spreadborough return NULL; 9060c036a14SPeter Spreadborough return ulp_ctx->cfg_data->ha_info; 9070c036a14SPeter Spreadborough } 9080c036a14SPeter Spreadborough 9090c036a14SPeter Spreadborough static inline bool 9100c036a14SPeter Spreadborough bnxt_ulp_cntxt_ha_enabled(struct bnxt_ulp_context *ulp_ctx) 9110c036a14SPeter Spreadborough { 9120c036a14SPeter Spreadborough if (unlikely(ulp_ctx == NULL || ulp_ctx->cfg_data == NULL)) 9130c036a14SPeter Spreadborough return false; 9140c036a14SPeter Spreadborough return !!ULP_HIGH_AVAIL_IS_ENABLED(ulp_ctx->cfg_data->ulp_flags); 9150c036a14SPeter Spreadborough } 9160c036a14SPeter Spreadborough 9170c036a14SPeter Spreadborough /* Function to get the app tunnel details from the ulp context. */ 9180c036a14SPeter Spreadborough static inline struct bnxt_flow_app_tun_ent * 9190c036a14SPeter Spreadborough bnxt_ulp_cntxt_ptr2_app_tun_list_get(struct bnxt_ulp_context *ulp) 9200c036a14SPeter Spreadborough { 9210c036a14SPeter Spreadborough if (unlikely(!ulp || !ulp->cfg_data)) 9220c036a14SPeter Spreadborough return NULL; 9230c036a14SPeter Spreadborough 9240c036a14SPeter Spreadborough return ulp->cfg_data->app_tun; 9250c036a14SPeter Spreadborough } 9260c036a14SPeter Spreadborough 9270c036a14SPeter Spreadborough /* Function to get the truflow app id. This defined in the build file */ 9280c036a14SPeter Spreadborough static inline uint32_t 9290c036a14SPeter Spreadborough bnxt_ulp_default_app_id_get(void) 9300c036a14SPeter Spreadborough { 9310c036a14SPeter Spreadborough return BNXT_TF_APP_ID; 9320c036a14SPeter Spreadborough } 9330c036a14SPeter Spreadborough 9340c036a14SPeter Spreadborough /* Function to convert ulp dev id to regular dev id. */ 9350c036a14SPeter Spreadborough static inline uint32_t 9360c036a14SPeter Spreadborough bnxt_ulp_cntxt_convert_dev_id(uint32_t ulp_dev_id) 9370c036a14SPeter Spreadborough { 9380c036a14SPeter Spreadborough enum tf_device_type type = 0; 9390c036a14SPeter Spreadborough 9400c036a14SPeter Spreadborough switch (ulp_dev_id) { 9410c036a14SPeter Spreadborough case BNXT_ULP_DEVICE_ID_WH_PLUS: 9420c036a14SPeter Spreadborough type = TF_DEVICE_TYPE_P4; 9430c036a14SPeter Spreadborough break; 9440c036a14SPeter Spreadborough case BNXT_ULP_DEVICE_ID_STINGRAY: 9450c036a14SPeter Spreadborough type = TF_DEVICE_TYPE_SR; 9460c036a14SPeter Spreadborough break; 9470c036a14SPeter Spreadborough case BNXT_ULP_DEVICE_ID_THOR: 9480c036a14SPeter Spreadborough type = TF_DEVICE_TYPE_P5; 9490c036a14SPeter Spreadborough break; 9500c036a14SPeter Spreadborough default: 9510c036a14SPeter Spreadborough BNXT_DRV_DBG(ERR, "Invalid device id\n"); 9520c036a14SPeter Spreadborough break; 9530c036a14SPeter Spreadborough } 9540c036a14SPeter Spreadborough return type; 9550c036a14SPeter Spreadborough } 9560c036a14SPeter Spreadborough 9570c036a14SPeter Spreadborough /* This function sets the IF table index for the 9580c036a14SPeter Spreadborough * Application to poll to get the hot upgrade state and count details from 9590c036a14SPeter Spreadborough * the firmware. 9600c036a14SPeter Spreadborough */ 9610c036a14SPeter Spreadborough static inline int32_t 9620c036a14SPeter Spreadborough bnxt_ulp_cntxt_ha_reg_set(struct bnxt_ulp_context *ulp_ctx, 9630c036a14SPeter Spreadborough uint8_t state, uint8_t cnt) 9640c036a14SPeter Spreadborough { 9650c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 9660c036a14SPeter Spreadborough return -EINVAL; 9670c036a14SPeter Spreadborough 9680c036a14SPeter Spreadborough if (ULP_MULTI_SHARED_IS_SUPPORTED(ulp_ctx)) { 9690c036a14SPeter Spreadborough ulp_ctx->cfg_data->hu_reg_state = state; 9700c036a14SPeter Spreadborough ulp_ctx->cfg_data->hu_reg_cnt = cnt; 9710c036a14SPeter Spreadborough } else { 9720c036a14SPeter Spreadborough ulp_ctx->cfg_data->hu_reg_state = ULP_HA_IF_TBL_IDX; 9730c036a14SPeter Spreadborough ulp_ctx->cfg_data->hu_reg_cnt = ULP_HA_CLIENT_CNT_IF_TBL_IDX; 9740c036a14SPeter Spreadborough } 9750c036a14SPeter Spreadborough return 0; 9760c036a14SPeter Spreadborough } 9770c036a14SPeter Spreadborough 9780c036a14SPeter Spreadborough /* This function gets the IF table index for the 9790c036a14SPeter Spreadborough * Application to poll to get the application hot upgrade state from 9800c036a14SPeter Spreadborough * the firmware. 9810c036a14SPeter Spreadborough */ 9820c036a14SPeter Spreadborough static inline uint32_t 9830c036a14SPeter Spreadborough bnxt_ulp_cntxt_ha_reg_state_get(struct bnxt_ulp_context *ulp_ctx) 9840c036a14SPeter Spreadborough { 9850c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 9860c036a14SPeter Spreadborough return 0; 9870c036a14SPeter Spreadborough 9880c036a14SPeter Spreadborough return (uint32_t)ulp_ctx->cfg_data->hu_reg_state; 9890c036a14SPeter Spreadborough } 9900c036a14SPeter Spreadborough 9910c036a14SPeter Spreadborough /* This function gets the IF table index for the 9920c036a14SPeter Spreadborough * Application to poll to get the application count from 9930c036a14SPeter Spreadborough * the firmware. 9940c036a14SPeter Spreadborough */ 9950c036a14SPeter Spreadborough static inline uint32_t 9960c036a14SPeter Spreadborough bnxt_ulp_cntxt_ha_reg_cnt_get(struct bnxt_ulp_context *ulp_ctx) 9970c036a14SPeter Spreadborough { 9980c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 9990c036a14SPeter Spreadborough return 0; 10000c036a14SPeter Spreadborough 10010c036a14SPeter Spreadborough return (uint32_t)ulp_ctx->cfg_data->hu_reg_cnt; 10020c036a14SPeter Spreadborough } 10030c036a14SPeter Spreadborough 10040c036a14SPeter Spreadborough /* This function sets the number of key recipes supported 10050c036a14SPeter Spreadborough * Generally, this should be set to the number of flexible keys 10060c036a14SPeter Spreadborough * supported 10070c036a14SPeter Spreadborough */ 10080c036a14SPeter Spreadborough static inline void 10090c036a14SPeter Spreadborough bnxt_ulp_num_key_recipes_set(struct bnxt_ulp_context *ulp_ctx, 10100c036a14SPeter Spreadborough uint16_t num_recipes) 10110c036a14SPeter Spreadborough { 10120c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 10130c036a14SPeter Spreadborough return; 10140c036a14SPeter Spreadborough ulp_ctx->cfg_data->num_key_recipes_per_dir = num_recipes; 10150c036a14SPeter Spreadborough } 10160c036a14SPeter Spreadborough 10170c036a14SPeter Spreadborough /* This function gets the number of key recipes supported */ 10180c036a14SPeter Spreadborough static inline int32_t 10190c036a14SPeter Spreadborough bnxt_ulp_num_key_recipes_get(struct bnxt_ulp_context *ulp_ctx) 10200c036a14SPeter Spreadborough { 10210c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 10220c036a14SPeter Spreadborough return 0; 10230c036a14SPeter Spreadborough return ulp_ctx->cfg_data->num_key_recipes_per_dir; 10240c036a14SPeter Spreadborough } 10250c036a14SPeter Spreadborough 10260c036a14SPeter Spreadborough /* This function gets the feature bits */ 10270c036a14SPeter Spreadborough static inline uint64_t 10280c036a14SPeter Spreadborough bnxt_ulp_feature_bits_get(struct bnxt_ulp_context *ulp_ctx) 10290c036a14SPeter Spreadborough { 10300c036a14SPeter Spreadborough if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 10310c036a14SPeter Spreadborough return 0; 10320c036a14SPeter Spreadborough return ulp_ctx->cfg_data->feature_bits; 10330c036a14SPeter Spreadborough } 10340c036a14SPeter Spreadborough 10350c036a14SPeter Spreadborough /* Add the VF Rep endpoint to the session */ 10360c036a14SPeter Spreadborough static inline int32_t 10370c036a14SPeter Spreadborough bnxt_ulp_vfr_session_fid_add(struct bnxt_ulp_context *ulp_ctx, 10380c036a14SPeter Spreadborough uint16_t vfr_fid) 10390c036a14SPeter Spreadborough { 10400c036a14SPeter Spreadborough int32_t rc = 0; 10410c036a14SPeter Spreadborough 10420c036a14SPeter Spreadborough if (unlikely(ulp_ctx == NULL || ulp_ctx->ops == NULL)) 10430c036a14SPeter Spreadborough return -EINVAL; 10440c036a14SPeter Spreadborough if (ulp_ctx->ops->ulp_vfr_session_fid_add) 10450c036a14SPeter Spreadborough rc = ulp_ctx->ops->ulp_vfr_session_fid_add(ulp_ctx, vfr_fid); 10460c036a14SPeter Spreadborough 10470c036a14SPeter Spreadborough return rc; 10480c036a14SPeter Spreadborough } 10490c036a14SPeter Spreadborough 10500c036a14SPeter Spreadborough /* Remove the VF Rep endpoint from the session */ 10510c036a14SPeter Spreadborough static inline int32_t 10520c036a14SPeter Spreadborough bnxt_ulp_vfr_session_fid_rem(struct bnxt_ulp_context *ulp_ctx, 10530c036a14SPeter Spreadborough uint16_t vfr_fid) 10540c036a14SPeter Spreadborough { 10550c036a14SPeter Spreadborough int32_t rc = 0; 10560c036a14SPeter Spreadborough 10570c036a14SPeter Spreadborough if (unlikely(ulp_ctx == NULL || ulp_ctx->ops == NULL)) 10580c036a14SPeter Spreadborough return -EINVAL; 10590c036a14SPeter Spreadborough if (ulp_ctx->ops->ulp_vfr_session_fid_rem) 10600c036a14SPeter Spreadborough rc = ulp_ctx->ops->ulp_vfr_session_fid_rem(ulp_ctx, vfr_fid); 10610c036a14SPeter Spreadborough return rc; 10620c036a14SPeter Spreadborough } 10630c036a14SPeter Spreadborough 1064b413ab0aSKishore Padmanabha static inline int32_t 1065b413ab0aSKishore Padmanabha bnxt_ulp_cap_feat_process(uint64_t feat_bits, uint64_t *out_bits) 1066b413ab0aSKishore Padmanabha { 1067b413ab0aSKishore Padmanabha #ifdef RTE_BNXT_TF_FEAT_BITS 1068b413ab0aSKishore Padmanabha uint64_t bit = RTE_BNXT_TF_FEAT_BITS; 1069b413ab0aSKishore Padmanabha #else 1070b413ab0aSKishore Padmanabha uint64_t bit = 0; 1071b413ab0aSKishore Padmanabha #endif 1072b413ab0aSKishore Padmanabha 1073b413ab0aSKishore Padmanabha *out_bits = 0; 1074b413ab0aSKishore Padmanabha if ((feat_bits | bit) != feat_bits) { 1075b413ab0aSKishore Padmanabha BNXT_DRV_DBG(ERR, "Invalid TF feature bit is set %" PRIu64 "\n", 1076b413ab0aSKishore Padmanabha bit); 1077b413ab0aSKishore Padmanabha return -EINVAL; 1078b413ab0aSKishore Padmanabha } 1079b413ab0aSKishore Padmanabha if ((bit & BNXT_ULP_FEATURE_BIT_PARENT_DMAC) && 1080b413ab0aSKishore Padmanabha (bit & BNXT_ULP_FEATURE_BIT_PORT_DMAC)) { 1081b413ab0aSKishore Padmanabha BNXT_DRV_DBG(ERR, "Invalid both Port and Parent Mac set\n"); 1082b413ab0aSKishore Padmanabha return -EINVAL; 1083b413ab0aSKishore Padmanabha } 1084b413ab0aSKishore Padmanabha 1085b413ab0aSKishore Padmanabha if (bit & BNXT_ULP_FEATURE_BIT_PARENT_DMAC) 1086b413ab0aSKishore Padmanabha BNXT_DRV_DBG(ERR, "Parent Mac Address Feature is enabled\n"); 1087b413ab0aSKishore Padmanabha if (bit & BNXT_ULP_FEATURE_BIT_PORT_DMAC) 1088b413ab0aSKishore Padmanabha BNXT_DRV_DBG(ERR, "Port Mac Address Feature is enabled\n"); 1089b413ab0aSKishore Padmanabha if (bit & BNXT_ULP_FEATURE_BIT_MULTI_TUNNEL_FLOW) 1090b413ab0aSKishore Padmanabha BNXT_DRV_DBG(ERR, "Multi Tunnel Flow Feature is enabled\n"); 1091b413ab0aSKishore Padmanabha 1092b413ab0aSKishore Padmanabha *out_bits = bit; 1093b413ab0aSKishore Padmanabha return 0; 1094b413ab0aSKishore Padmanabha } 1095b413ab0aSKishore Padmanabha 10960c036a14SPeter Spreadborough #endif /* _BNXT_ULP_UTILS_H_ */ 1097