18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright (c) 2016-2018 Mellanox Technologies. All rights reserved */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _MLXSW_RESOURCES_H 58c2ecf20Sopenharmony_ci#define _MLXSW_RESOURCES_H 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/kernel.h> 88c2ecf20Sopenharmony_ci#include <linux/types.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cienum mlxsw_res_id { 118c2ecf20Sopenharmony_ci MLXSW_RES_ID_KVD_SIZE, 128c2ecf20Sopenharmony_ci MLXSW_RES_ID_KVD_SINGLE_MIN_SIZE, 138c2ecf20Sopenharmony_ci MLXSW_RES_ID_KVD_DOUBLE_MIN_SIZE, 148c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_KVD_LINEAR_RANGE, 158c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_KVD_ACTION_SETS, 168c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_TRAP_GROUPS, 178c2ecf20Sopenharmony_ci MLXSW_RES_ID_CQE_V0, 188c2ecf20Sopenharmony_ci MLXSW_RES_ID_CQE_V1, 198c2ecf20Sopenharmony_ci MLXSW_RES_ID_CQE_V2, 208c2ecf20Sopenharmony_ci MLXSW_RES_ID_COUNTER_POOL_SIZE, 218c2ecf20Sopenharmony_ci MLXSW_RES_ID_COUNTER_BANK_SIZE, 228c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_SPAN, 238c2ecf20Sopenharmony_ci MLXSW_RES_ID_COUNTER_SIZE_PACKETS_BYTES, 248c2ecf20Sopenharmony_ci MLXSW_RES_ID_COUNTER_SIZE_ROUTER_BASIC, 258c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_SYSTEM_PORT, 268c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_LAG, 278c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_LAG_MEMBERS, 288c2ecf20Sopenharmony_ci MLXSW_RES_ID_LOCAL_PORTS_IN_1X, 298c2ecf20Sopenharmony_ci MLXSW_RES_ID_LOCAL_PORTS_IN_2X, 308c2ecf20Sopenharmony_ci MLXSW_RES_ID_LOCAL_PORTS_IN_4X, 318c2ecf20Sopenharmony_ci MLXSW_RES_ID_GUARANTEED_SHARED_BUFFER, 328c2ecf20Sopenharmony_ci MLXSW_RES_ID_CELL_SIZE, 338c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_HEADROOM_SIZE, 348c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_TCAM_REGIONS, 358c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_TCAM_RULES, 368c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_REGIONS, 378c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_GROUPS, 388c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_GROUP_SIZE, 398c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_FLEX_KEYS, 408c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_ACTION_PER_RULE, 418c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_ACTIONS_PER_SET, 428c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_ERPT_BANKS, 438c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_ERPT_BANK_SIZE, 448c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_LARGE_KEY_ID, 458c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_ERPT_ENTRIES_2KB, 468c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_ERPT_ENTRIES_4KB, 478c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_ERPT_ENTRIES_8KB, 488c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_ERPT_ENTRIES_12KB, 498c2ecf20Sopenharmony_ci MLXSW_RES_ID_ACL_MAX_BF_LOG, 508c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_GLOBAL_POLICERS, 518c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_CPU_POLICERS, 528c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_VRS, 538c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_RIFS, 548c2ecf20Sopenharmony_ci MLXSW_RES_ID_MC_ERIF_LIST_ENTRIES, 558c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_LPM_TREES, 568c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_NVE_MC_ENTRIES_IPV4, 578c2ecf20Sopenharmony_ci MLXSW_RES_ID_MAX_NVE_MC_ENTRIES_IPV6, 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* Internal resources. 608c2ecf20Sopenharmony_ci * Determined by the SW, not queried from the HW. 618c2ecf20Sopenharmony_ci */ 628c2ecf20Sopenharmony_ci MLXSW_RES_ID_KVD_SINGLE_SIZE, 638c2ecf20Sopenharmony_ci MLXSW_RES_ID_KVD_DOUBLE_SIZE, 648c2ecf20Sopenharmony_ci MLXSW_RES_ID_KVD_LINEAR_SIZE, 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci __MLXSW_RES_ID_MAX, 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic u16 mlxsw_res_ids[] = { 708c2ecf20Sopenharmony_ci [MLXSW_RES_ID_KVD_SIZE] = 0x1001, 718c2ecf20Sopenharmony_ci [MLXSW_RES_ID_KVD_SINGLE_MIN_SIZE] = 0x1002, 728c2ecf20Sopenharmony_ci [MLXSW_RES_ID_KVD_DOUBLE_MIN_SIZE] = 0x1003, 738c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_KVD_LINEAR_RANGE] = 0x1005, 748c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_KVD_ACTION_SETS] = 0x1007, 758c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_TRAP_GROUPS] = 0x2201, 768c2ecf20Sopenharmony_ci [MLXSW_RES_ID_CQE_V0] = 0x2210, 778c2ecf20Sopenharmony_ci [MLXSW_RES_ID_CQE_V1] = 0x2211, 788c2ecf20Sopenharmony_ci [MLXSW_RES_ID_CQE_V2] = 0x2212, 798c2ecf20Sopenharmony_ci [MLXSW_RES_ID_COUNTER_POOL_SIZE] = 0x2410, 808c2ecf20Sopenharmony_ci [MLXSW_RES_ID_COUNTER_BANK_SIZE] = 0x2411, 818c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_SPAN] = 0x2420, 828c2ecf20Sopenharmony_ci [MLXSW_RES_ID_COUNTER_SIZE_PACKETS_BYTES] = 0x2443, 838c2ecf20Sopenharmony_ci [MLXSW_RES_ID_COUNTER_SIZE_ROUTER_BASIC] = 0x2449, 848c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_SYSTEM_PORT] = 0x2502, 858c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_LAG] = 0x2520, 868c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_LAG_MEMBERS] = 0x2521, 878c2ecf20Sopenharmony_ci [MLXSW_RES_ID_LOCAL_PORTS_IN_1X] = 0x2610, 888c2ecf20Sopenharmony_ci [MLXSW_RES_ID_LOCAL_PORTS_IN_2X] = 0x2611, 898c2ecf20Sopenharmony_ci [MLXSW_RES_ID_LOCAL_PORTS_IN_4X] = 0x2612, 908c2ecf20Sopenharmony_ci [MLXSW_RES_ID_GUARANTEED_SHARED_BUFFER] = 0x2805, /* Bytes */ 918c2ecf20Sopenharmony_ci [MLXSW_RES_ID_CELL_SIZE] = 0x2803, /* Bytes */ 928c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_HEADROOM_SIZE] = 0x2811, /* Bytes */ 938c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_TCAM_REGIONS] = 0x2901, 948c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_TCAM_RULES] = 0x2902, 958c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_REGIONS] = 0x2903, 968c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_GROUPS] = 0x2904, 978c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_GROUP_SIZE] = 0x2905, 988c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_FLEX_KEYS] = 0x2910, 998c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_ACTION_PER_RULE] = 0x2911, 1008c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_ACTIONS_PER_SET] = 0x2912, 1018c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_ERPT_BANKS] = 0x2940, 1028c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_ERPT_BANK_SIZE] = 0x2941, 1038c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_LARGE_KEY_ID] = 0x2942, 1048c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_ERPT_ENTRIES_2KB] = 0x2950, 1058c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_ERPT_ENTRIES_4KB] = 0x2951, 1068c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_ERPT_ENTRIES_8KB] = 0x2952, 1078c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_ERPT_ENTRIES_12KB] = 0x2953, 1088c2ecf20Sopenharmony_ci [MLXSW_RES_ID_ACL_MAX_BF_LOG] = 0x2960, 1098c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_GLOBAL_POLICERS] = 0x2A10, 1108c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_CPU_POLICERS] = 0x2A13, 1118c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_VRS] = 0x2C01, 1128c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_RIFS] = 0x2C02, 1138c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MC_ERIF_LIST_ENTRIES] = 0x2C10, 1148c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_LPM_TREES] = 0x2C30, 1158c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_NVE_MC_ENTRIES_IPV4] = 0x2E02, 1168c2ecf20Sopenharmony_ci [MLXSW_RES_ID_MAX_NVE_MC_ENTRIES_IPV6] = 0x2E03, 1178c2ecf20Sopenharmony_ci}; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistruct mlxsw_res { 1208c2ecf20Sopenharmony_ci bool valid[__MLXSW_RES_ID_MAX]; 1218c2ecf20Sopenharmony_ci u64 values[__MLXSW_RES_ID_MAX]; 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic inline bool mlxsw_res_valid(struct mlxsw_res *res, 1258c2ecf20Sopenharmony_ci enum mlxsw_res_id res_id) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci return res->valid[res_id]; 1288c2ecf20Sopenharmony_ci} 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define MLXSW_RES_VALID(res, short_res_id) \ 1318c2ecf20Sopenharmony_ci mlxsw_res_valid(res, MLXSW_RES_ID_##short_res_id) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic inline u64 mlxsw_res_get(struct mlxsw_res *res, 1348c2ecf20Sopenharmony_ci enum mlxsw_res_id res_id) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci if (WARN_ON(!res->valid[res_id])) 1378c2ecf20Sopenharmony_ci return 0; 1388c2ecf20Sopenharmony_ci return res->values[res_id]; 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci#define MLXSW_RES_GET(res, short_res_id) \ 1428c2ecf20Sopenharmony_ci mlxsw_res_get(res, MLXSW_RES_ID_##short_res_id) 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistatic inline void mlxsw_res_set(struct mlxsw_res *res, 1458c2ecf20Sopenharmony_ci enum mlxsw_res_id res_id, u64 value) 1468c2ecf20Sopenharmony_ci{ 1478c2ecf20Sopenharmony_ci res->valid[res_id] = true; 1488c2ecf20Sopenharmony_ci res->values[res_id] = value; 1498c2ecf20Sopenharmony_ci} 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#define MLXSW_RES_SET(res, short_res_id, value) \ 1528c2ecf20Sopenharmony_ci mlxsw_res_set(res, MLXSW_RES_ID_##short_res_id, value) 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic inline void mlxsw_res_parse(struct mlxsw_res *res, u16 id, u64 value) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci int i; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(mlxsw_res_ids); i++) { 1598c2ecf20Sopenharmony_ci if (mlxsw_res_ids[i] == id) { 1608c2ecf20Sopenharmony_ci mlxsw_res_set(res, i, value); 1618c2ecf20Sopenharmony_ci return; 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci } 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci#endif 167