10513f0afSPeter Spreadborough /* SPDX-License-Identifier: BSD-3-Clause 20513f0afSPeter Spreadborough * Copyright(c) 2014-2023 Broadcom 30513f0afSPeter Spreadborough * All rights reserved. 40513f0afSPeter Spreadborough */ 50513f0afSPeter Spreadborough 60513f0afSPeter Spreadborough #ifndef _ULP_SC_MGR_H_ 70513f0afSPeter Spreadborough #define _ULP_SC_MGR_H_ 80513f0afSPeter Spreadborough 90513f0afSPeter Spreadborough #include "pthread.h" 100513f0afSPeter Spreadborough #include "bnxt_ulp.h" 110513f0afSPeter Spreadborough #include "ulp_flow_db.h" 120513f0afSPeter Spreadborough 130513f0afSPeter Spreadborough #define ULP_FLAG_SC_THREAD BIT(0) 140513f0afSPeter Spreadborough 150513f0afSPeter Spreadborough #define ULP_SC_ENTRY_FLAG_VALID BIT(0) 16a089734aSShuanglin Wang #define ULP_SC_ENTRY_FLAG_PARENT BIT(1) 17a089734aSShuanglin Wang #define ULP_SC_PC_IDX_MASK 0xFFFFF 180513f0afSPeter Spreadborough 190513f0afSPeter Spreadborough #define ULP_SC_BATCH_SIZE 64 200513f0afSPeter Spreadborough #define ULP_SC_PAGE_SIZE 4096 210513f0afSPeter Spreadborough 220513f0afSPeter Spreadborough struct ulp_sc_tfc_stats_cache_entry { 230513f0afSPeter Spreadborough struct bnxt_ulp_context *ctxt; 24a089734aSShuanglin Wang uint32_t flags : 8; 25a089734aSShuanglin Wang uint32_t pc_idx : 24; 260513f0afSPeter Spreadborough uint64_t timestamp; 270513f0afSPeter Spreadborough uint64_t handle; 280513f0afSPeter Spreadborough uint8_t dir; 290513f0afSPeter Spreadborough uint64_t packet_count; 300513f0afSPeter Spreadborough uint64_t byte_count; 310513f0afSPeter Spreadborough uint64_t count_fields1; 320513f0afSPeter Spreadborough uint64_t count_fields2; 330513f0afSPeter Spreadborough bool reset; 340513f0afSPeter Spreadborough }; 350513f0afSPeter Spreadborough 360513f0afSPeter Spreadborough struct bnxt_ulp_sc_info { 370513f0afSPeter Spreadborough struct ulp_sc_tfc_stats_cache_entry *stats_cache_tbl; 380513f0afSPeter Spreadborough uint8_t *read_data; 39*ca827d42SPeter Spreadborough uint64_t read_data_iova[ULP_SC_BATCH_SIZE]; 400513f0afSPeter Spreadborough uint32_t flags; 410513f0afSPeter Spreadborough uint32_t num_entries; 420513f0afSPeter Spreadborough uint32_t num_counters; 4367ad4000SKishore Padmanabha uint32_t cache_tbl_size; 440513f0afSPeter Spreadborough rte_thread_t tid; 450513f0afSPeter Spreadborough const struct bnxt_ulp_sc_core_ops *sc_ops; 460513f0afSPeter Spreadborough }; 470513f0afSPeter Spreadborough 480513f0afSPeter Spreadborough struct bnxt_ulp_sc_core_ops { 490513f0afSPeter Spreadborough int32_t 500513f0afSPeter Spreadborough (*ulp_stats_cache_update)(struct tfc *tfcp, 510513f0afSPeter Spreadborough int dir, 52*ca827d42SPeter Spreadborough uint64_t *host_address, 530513f0afSPeter Spreadborough uint64_t handle, 540513f0afSPeter Spreadborough uint16_t *words, 550513f0afSPeter Spreadborough struct tfc_mpc_batch_info_t *batch_info, 560513f0afSPeter Spreadborough bool reset); 570513f0afSPeter Spreadborough }; 580513f0afSPeter Spreadborough 590513f0afSPeter Spreadborough /* 600513f0afSPeter Spreadborough * Allocate all resources in the stats cache manager for this ulp context 610513f0afSPeter Spreadborough * 620513f0afSPeter Spreadborough * ctxt [in] The ulp context for the stats cache manager 630513f0afSPeter Spreadborough */ 640513f0afSPeter Spreadborough int32_t 650513f0afSPeter Spreadborough ulp_sc_mgr_init(struct bnxt_ulp_context *ctxt); 660513f0afSPeter Spreadborough 670513f0afSPeter Spreadborough /* 680513f0afSPeter Spreadborough * Release all resources in the stats cache manager for this ulp context 690513f0afSPeter Spreadborough * 700513f0afSPeter Spreadborough * ctxt [in] The ulp context for the stats cache manager 710513f0afSPeter Spreadborough */ 720513f0afSPeter Spreadborough int32_t 730513f0afSPeter Spreadborough ulp_sc_mgr_deinit(struct bnxt_ulp_context *ctxt); 740513f0afSPeter Spreadborough 750513f0afSPeter Spreadborough /* 760513f0afSPeter Spreadborough * Setup the stats cache timer thread that will fetch/accumulate raw counter 770513f0afSPeter Spreadborough * data from the chip's internal stats caches 780513f0afSPeter Spreadborough * 790513f0afSPeter Spreadborough * ctxt [in] The ulp context for the stats cache manager 800513f0afSPeter Spreadborough */ 810513f0afSPeter Spreadborough int32_t 820513f0afSPeter Spreadborough ulp_sc_mgr_thread_start(struct bnxt_ulp_context *ctxt); 830513f0afSPeter Spreadborough 840513f0afSPeter Spreadborough /* 850513f0afSPeter Spreadborough * Alarm handler that will issue the TF-Core API to fetch 860513f0afSPeter Spreadborough * data from the chip's internal stats caches 870513f0afSPeter Spreadborough * 880513f0afSPeter Spreadborough * ctxt [in] The ulp context for the stats cache manager 890513f0afSPeter Spreadborough */ 900513f0afSPeter Spreadborough void 910513f0afSPeter Spreadborough ulp_sc_mgr_alarm_cb(void *arg); 920513f0afSPeter Spreadborough 930513f0afSPeter Spreadborough /* 940513f0afSPeter Spreadborough * Cancel the alarm handler 950513f0afSPeter Spreadborough * 960513f0afSPeter Spreadborough * ctxt [in] The ulp context for the stats cache manager 970513f0afSPeter Spreadborough * 980513f0afSPeter Spreadborough */ 990513f0afSPeter Spreadborough void ulp_sc_mgr_thread_cancel(struct bnxt_ulp_context *ctxt); 1000513f0afSPeter Spreadborough 1010513f0afSPeter Spreadborough /* 1020513f0afSPeter Spreadborough * Check if the thread that walks through the flows is started 1030513f0afSPeter Spreadborough * 1040513f0afSPeter Spreadborough * ctxt [in] The ulp context for the stats cache manager 1050513f0afSPeter Spreadborough * 1060513f0afSPeter Spreadborough */ 1070513f0afSPeter Spreadborough bool ulp_sc_mgr_thread_isstarted(struct bnxt_ulp_context *ctxt); 1080513f0afSPeter Spreadborough 1090513f0afSPeter Spreadborough /* 1100513f0afSPeter Spreadborough * Get the current counts for the given flow id 1110513f0afSPeter Spreadborough * 1120513f0afSPeter Spreadborough * ctxt [in] The ulp context for the stats cache manager 1130513f0afSPeter Spreadborough * flow_id [in] The flow identifier 1140513f0afSPeter Spreadborough * count [out] structure in which the updated counts are passed 1150513f0afSPeter Spreadborough * back to the caller. 1160513f0afSPeter Spreadborough * 1170513f0afSPeter Spreadborough */ 1180513f0afSPeter Spreadborough int ulp_sc_mgr_query_count_get(struct bnxt_ulp_context *ctxt, 1190513f0afSPeter Spreadborough uint32_t flow_id, 1200513f0afSPeter Spreadborough struct rte_flow_query_count *count); 1210513f0afSPeter Spreadborough 1220513f0afSPeter Spreadborough /* 1230513f0afSPeter Spreadborough * Allocate a cache entry for flow 1240513f0afSPeter Spreadborough * 1250513f0afSPeter Spreadborough * parms [in] Various fields used to identify the flow 1260513f0afSPeter Spreadborough * counter_handle [in] This is the action table entry identifier. 1270513f0afSPeter Spreadborough * tbl [in] Various fields used to identify the flow 1280513f0afSPeter Spreadborough * 1290513f0afSPeter Spreadborough */ 1300513f0afSPeter Spreadborough int ulp_sc_mgr_entry_alloc(struct bnxt_ulp_mapper_parms *parms, 1310513f0afSPeter Spreadborough uint64_t counter_handle, 1320513f0afSPeter Spreadborough struct bnxt_ulp_mapper_tbl_info *tbl); 1330513f0afSPeter Spreadborough 1340513f0afSPeter Spreadborough /* 1350513f0afSPeter Spreadborough * Free cache entry 1360513f0afSPeter Spreadborough * 1370513f0afSPeter Spreadborough * ulp [in] The ulp context for the stats cache manager 1380513f0afSPeter Spreadborough * fid [in] The flow identifier 1390513f0afSPeter Spreadborough * 1400513f0afSPeter Spreadborough */ 1410513f0afSPeter Spreadborough void ulp_sc_mgr_entry_free(struct bnxt_ulp_context *ulp, 1420513f0afSPeter Spreadborough uint32_t fid); 1430513f0afSPeter Spreadborough 144a089734aSShuanglin Wang 145a089734aSShuanglin Wang /* 146a089734aSShuanglin Wang * Set pc_idx for the flow if stat cache info is valid 147a089734aSShuanglin Wang * 148a089734aSShuanglin Wang * ctxt [in] The ulp context for the flow counter manager 149a089734aSShuanglin Wang * flow_id [in] The HW flow ID 150a089734aSShuanglin Wang * pc_idx [in] The parent flow entry idx 151a089734aSShuanglin Wang * 152a089734aSShuanglin Wang */ 153a089734aSShuanglin Wang void ulp_sc_mgr_set_pc_idx(struct bnxt_ulp_context *ctxt, 154a089734aSShuanglin Wang uint32_t flow_id, 155a089734aSShuanglin Wang uint32_t pc_idx); 156a089734aSShuanglin Wang 1570513f0afSPeter Spreadborough extern const struct bnxt_ulp_sc_core_ops ulp_sc_tfc_core_ops; 1580513f0afSPeter Spreadborough 1590513f0afSPeter Spreadborough #endif /* _ULP_SC_MGR_H_ */ 160