18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2013-2017, Mellanox Technologies. All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
58c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
118c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
128c2ecf20Sopenharmony_ci *     conditions are met:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
158c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
168c2ecf20Sopenharmony_ci *        disclaimer.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
198c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
208c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
218c2ecf20Sopenharmony_ci *        provided with the distribution.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
308c2ecf20Sopenharmony_ci * SOFTWARE.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include "mlx5_ib.h"
368c2ecf20Sopenharmony_ci#include "cmd.h"
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cienum mlx5_ib_cong_node_type {
398c2ecf20Sopenharmony_ci	MLX5_IB_RROCE_ECN_RP = 1,
408c2ecf20Sopenharmony_ci	MLX5_IB_RROCE_ECN_NP = 2,
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic const char * const mlx5_ib_dbg_cc_name[] = {
448c2ecf20Sopenharmony_ci	"rp_clamp_tgt_rate",
458c2ecf20Sopenharmony_ci	"rp_clamp_tgt_rate_ati",
468c2ecf20Sopenharmony_ci	"rp_time_reset",
478c2ecf20Sopenharmony_ci	"rp_byte_reset",
488c2ecf20Sopenharmony_ci	"rp_threshold",
498c2ecf20Sopenharmony_ci	"rp_ai_rate",
508c2ecf20Sopenharmony_ci	"rp_max_rate",
518c2ecf20Sopenharmony_ci	"rp_hai_rate",
528c2ecf20Sopenharmony_ci	"rp_min_dec_fac",
538c2ecf20Sopenharmony_ci	"rp_min_rate",
548c2ecf20Sopenharmony_ci	"rp_rate_to_set_on_first_cnp",
558c2ecf20Sopenharmony_ci	"rp_dce_tcp_g",
568c2ecf20Sopenharmony_ci	"rp_dce_tcp_rtt",
578c2ecf20Sopenharmony_ci	"rp_rate_reduce_monitor_period",
588c2ecf20Sopenharmony_ci	"rp_initial_alpha_value",
598c2ecf20Sopenharmony_ci	"rp_gd",
608c2ecf20Sopenharmony_ci	"np_min_time_between_cnps",
618c2ecf20Sopenharmony_ci	"np_cnp_dscp",
628c2ecf20Sopenharmony_ci	"np_cnp_prio_mode",
638c2ecf20Sopenharmony_ci	"np_cnp_prio",
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define MLX5_IB_RP_CLAMP_TGT_RATE_ATTR			BIT(1)
678c2ecf20Sopenharmony_ci#define MLX5_IB_RP_CLAMP_TGT_RATE_ATI_ATTR		BIT(2)
688c2ecf20Sopenharmony_ci#define MLX5_IB_RP_TIME_RESET_ATTR			BIT(3)
698c2ecf20Sopenharmony_ci#define MLX5_IB_RP_BYTE_RESET_ATTR			BIT(4)
708c2ecf20Sopenharmony_ci#define MLX5_IB_RP_THRESHOLD_ATTR			BIT(5)
718c2ecf20Sopenharmony_ci#define MLX5_IB_RP_MAX_RATE_ATTR			BIT(6)
728c2ecf20Sopenharmony_ci#define MLX5_IB_RP_AI_RATE_ATTR				BIT(7)
738c2ecf20Sopenharmony_ci#define MLX5_IB_RP_HAI_RATE_ATTR			BIT(8)
748c2ecf20Sopenharmony_ci#define MLX5_IB_RP_MIN_DEC_FAC_ATTR			BIT(9)
758c2ecf20Sopenharmony_ci#define MLX5_IB_RP_MIN_RATE_ATTR			BIT(10)
768c2ecf20Sopenharmony_ci#define MLX5_IB_RP_RATE_TO_SET_ON_FIRST_CNP_ATTR	BIT(11)
778c2ecf20Sopenharmony_ci#define MLX5_IB_RP_DCE_TCP_G_ATTR			BIT(12)
788c2ecf20Sopenharmony_ci#define MLX5_IB_RP_DCE_TCP_RTT_ATTR			BIT(13)
798c2ecf20Sopenharmony_ci#define MLX5_IB_RP_RATE_REDUCE_MONITOR_PERIOD_ATTR	BIT(14)
808c2ecf20Sopenharmony_ci#define MLX5_IB_RP_INITIAL_ALPHA_VALUE_ATTR		BIT(15)
818c2ecf20Sopenharmony_ci#define MLX5_IB_RP_GD_ATTR				BIT(16)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define MLX5_IB_NP_MIN_TIME_BETWEEN_CNPS_ATTR		BIT(2)
848c2ecf20Sopenharmony_ci#define MLX5_IB_NP_CNP_DSCP_ATTR			BIT(3)
858c2ecf20Sopenharmony_ci#define MLX5_IB_NP_CNP_PRIO_MODE_ATTR			BIT(4)
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistatic enum mlx5_ib_cong_node_type
888c2ecf20Sopenharmony_cimlx5_ib_param_to_node(enum mlx5_ib_dbg_cc_types param_offset)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	if (param_offset >= MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE &&
918c2ecf20Sopenharmony_ci	    param_offset <= MLX5_IB_DBG_CC_RP_GD)
928c2ecf20Sopenharmony_ci		return MLX5_IB_RROCE_ECN_RP;
938c2ecf20Sopenharmony_ci	else
948c2ecf20Sopenharmony_ci		return MLX5_IB_RROCE_ECN_NP;
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistatic u32 mlx5_get_cc_param_val(void *field, int offset)
988c2ecf20Sopenharmony_ci{
998c2ecf20Sopenharmony_ci	switch (offset) {
1008c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE:
1018c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1028c2ecf20Sopenharmony_ci				clamp_tgt_rate);
1038c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE_ATI:
1048c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1058c2ecf20Sopenharmony_ci				clamp_tgt_rate_after_time_inc);
1068c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_TIME_RESET:
1078c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1088c2ecf20Sopenharmony_ci				rpg_time_reset);
1098c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_BYTE_RESET:
1108c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1118c2ecf20Sopenharmony_ci				rpg_byte_reset);
1128c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_THRESHOLD:
1138c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1148c2ecf20Sopenharmony_ci				rpg_threshold);
1158c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_AI_RATE:
1168c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1178c2ecf20Sopenharmony_ci				rpg_ai_rate);
1188c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_MAX_RATE:
1198c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1208c2ecf20Sopenharmony_ci				rpg_max_rate);
1218c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_HAI_RATE:
1228c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1238c2ecf20Sopenharmony_ci				rpg_hai_rate);
1248c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_MIN_DEC_FAC:
1258c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1268c2ecf20Sopenharmony_ci				rpg_min_dec_fac);
1278c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_MIN_RATE:
1288c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1298c2ecf20Sopenharmony_ci				rpg_min_rate);
1308c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_RATE_TO_SET_ON_FIRST_CNP:
1318c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1328c2ecf20Sopenharmony_ci				rate_to_set_on_first_cnp);
1338c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_DCE_TCP_G:
1348c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1358c2ecf20Sopenharmony_ci				dce_tcp_g);
1368c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_DCE_TCP_RTT:
1378c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1388c2ecf20Sopenharmony_ci				dce_tcp_rtt);
1398c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_RATE_REDUCE_MONITOR_PERIOD:
1408c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1418c2ecf20Sopenharmony_ci				rate_reduce_monitor_period);
1428c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_INITIAL_ALPHA_VALUE:
1438c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1448c2ecf20Sopenharmony_ci				initial_alpha_value);
1458c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_GD:
1468c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_rp, field,
1478c2ecf20Sopenharmony_ci				rpg_gd);
1488c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_NP_MIN_TIME_BETWEEN_CNPS:
1498c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_np, field,
1508c2ecf20Sopenharmony_ci				min_time_between_cnps);
1518c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_NP_CNP_DSCP:
1528c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_np, field,
1538c2ecf20Sopenharmony_ci				cnp_dscp);
1548c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_NP_CNP_PRIO_MODE:
1558c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_np, field,
1568c2ecf20Sopenharmony_ci				cnp_prio_mode);
1578c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_NP_CNP_PRIO:
1588c2ecf20Sopenharmony_ci		return MLX5_GET(cong_control_r_roce_ecn_np, field,
1598c2ecf20Sopenharmony_ci				cnp_802p_prio);
1608c2ecf20Sopenharmony_ci	default:
1618c2ecf20Sopenharmony_ci		return 0;
1628c2ecf20Sopenharmony_ci	}
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic void mlx5_ib_set_cc_param_mask_val(void *field, int offset,
1668c2ecf20Sopenharmony_ci					  u32 var, u32 *attr_mask)
1678c2ecf20Sopenharmony_ci{
1688c2ecf20Sopenharmony_ci	switch (offset) {
1698c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE:
1708c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_CLAMP_TGT_RATE_ATTR;
1718c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
1728c2ecf20Sopenharmony_ci			 clamp_tgt_rate, var);
1738c2ecf20Sopenharmony_ci		break;
1748c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE_ATI:
1758c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_CLAMP_TGT_RATE_ATI_ATTR;
1768c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
1778c2ecf20Sopenharmony_ci			 clamp_tgt_rate_after_time_inc, var);
1788c2ecf20Sopenharmony_ci		break;
1798c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_TIME_RESET:
1808c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_TIME_RESET_ATTR;
1818c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
1828c2ecf20Sopenharmony_ci			 rpg_time_reset, var);
1838c2ecf20Sopenharmony_ci		break;
1848c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_BYTE_RESET:
1858c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_BYTE_RESET_ATTR;
1868c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
1878c2ecf20Sopenharmony_ci			 rpg_byte_reset, var);
1888c2ecf20Sopenharmony_ci		break;
1898c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_THRESHOLD:
1908c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_THRESHOLD_ATTR;
1918c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
1928c2ecf20Sopenharmony_ci			 rpg_threshold, var);
1938c2ecf20Sopenharmony_ci		break;
1948c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_AI_RATE:
1958c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_AI_RATE_ATTR;
1968c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
1978c2ecf20Sopenharmony_ci			 rpg_ai_rate, var);
1988c2ecf20Sopenharmony_ci		break;
1998c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_MAX_RATE:
2008c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_MAX_RATE_ATTR;
2018c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2028c2ecf20Sopenharmony_ci			 rpg_max_rate, var);
2038c2ecf20Sopenharmony_ci		break;
2048c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_HAI_RATE:
2058c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_HAI_RATE_ATTR;
2068c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2078c2ecf20Sopenharmony_ci			 rpg_hai_rate, var);
2088c2ecf20Sopenharmony_ci		break;
2098c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_MIN_DEC_FAC:
2108c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_MIN_DEC_FAC_ATTR;
2118c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2128c2ecf20Sopenharmony_ci			 rpg_min_dec_fac, var);
2138c2ecf20Sopenharmony_ci		break;
2148c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_MIN_RATE:
2158c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_MIN_RATE_ATTR;
2168c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2178c2ecf20Sopenharmony_ci			 rpg_min_rate, var);
2188c2ecf20Sopenharmony_ci		break;
2198c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_RATE_TO_SET_ON_FIRST_CNP:
2208c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_RATE_TO_SET_ON_FIRST_CNP_ATTR;
2218c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2228c2ecf20Sopenharmony_ci			 rate_to_set_on_first_cnp, var);
2238c2ecf20Sopenharmony_ci		break;
2248c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_DCE_TCP_G:
2258c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_DCE_TCP_G_ATTR;
2268c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2278c2ecf20Sopenharmony_ci			 dce_tcp_g, var);
2288c2ecf20Sopenharmony_ci		break;
2298c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_DCE_TCP_RTT:
2308c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_DCE_TCP_RTT_ATTR;
2318c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2328c2ecf20Sopenharmony_ci			 dce_tcp_rtt, var);
2338c2ecf20Sopenharmony_ci		break;
2348c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_RATE_REDUCE_MONITOR_PERIOD:
2358c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_RATE_REDUCE_MONITOR_PERIOD_ATTR;
2368c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2378c2ecf20Sopenharmony_ci			 rate_reduce_monitor_period, var);
2388c2ecf20Sopenharmony_ci		break;
2398c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_INITIAL_ALPHA_VALUE:
2408c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_INITIAL_ALPHA_VALUE_ATTR;
2418c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2428c2ecf20Sopenharmony_ci			 initial_alpha_value, var);
2438c2ecf20Sopenharmony_ci		break;
2448c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_RP_GD:
2458c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_RP_GD_ATTR;
2468c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_rp, field,
2478c2ecf20Sopenharmony_ci			 rpg_gd, var);
2488c2ecf20Sopenharmony_ci		break;
2498c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_NP_MIN_TIME_BETWEEN_CNPS:
2508c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_NP_MIN_TIME_BETWEEN_CNPS_ATTR;
2518c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_np, field,
2528c2ecf20Sopenharmony_ci			 min_time_between_cnps, var);
2538c2ecf20Sopenharmony_ci		break;
2548c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_NP_CNP_DSCP:
2558c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_NP_CNP_DSCP_ATTR;
2568c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_np, field, cnp_dscp, var);
2578c2ecf20Sopenharmony_ci		break;
2588c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_NP_CNP_PRIO_MODE:
2598c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_NP_CNP_PRIO_MODE_ATTR;
2608c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_np, field, cnp_prio_mode, var);
2618c2ecf20Sopenharmony_ci		break;
2628c2ecf20Sopenharmony_ci	case MLX5_IB_DBG_CC_NP_CNP_PRIO:
2638c2ecf20Sopenharmony_ci		*attr_mask |= MLX5_IB_NP_CNP_PRIO_MODE_ATTR;
2648c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_np, field, cnp_prio_mode, 0);
2658c2ecf20Sopenharmony_ci		MLX5_SET(cong_control_r_roce_ecn_np, field, cnp_802p_prio, var);
2668c2ecf20Sopenharmony_ci		break;
2678c2ecf20Sopenharmony_ci	}
2688c2ecf20Sopenharmony_ci}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic int mlx5_ib_get_cc_params(struct mlx5_ib_dev *dev, u8 port_num,
2718c2ecf20Sopenharmony_ci				 int offset, u32 *var)
2728c2ecf20Sopenharmony_ci{
2738c2ecf20Sopenharmony_ci	int outlen = MLX5_ST_SZ_BYTES(query_cong_params_out);
2748c2ecf20Sopenharmony_ci	void *out;
2758c2ecf20Sopenharmony_ci	void *field;
2768c2ecf20Sopenharmony_ci	int err;
2778c2ecf20Sopenharmony_ci	enum mlx5_ib_cong_node_type node;
2788c2ecf20Sopenharmony_ci	struct mlx5_core_dev *mdev;
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci	/* Takes a 1-based port number */
2818c2ecf20Sopenharmony_ci	mdev = mlx5_ib_get_native_port_mdev(dev, port_num + 1, NULL);
2828c2ecf20Sopenharmony_ci	if (!mdev)
2838c2ecf20Sopenharmony_ci		return -ENODEV;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	out = kvzalloc(outlen, GFP_KERNEL);
2868c2ecf20Sopenharmony_ci	if (!out) {
2878c2ecf20Sopenharmony_ci		err = -ENOMEM;
2888c2ecf20Sopenharmony_ci		goto alloc_err;
2898c2ecf20Sopenharmony_ci	}
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	node = mlx5_ib_param_to_node(offset);
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	err = mlx5_cmd_query_cong_params(mdev, node, out);
2948c2ecf20Sopenharmony_ci	if (err)
2958c2ecf20Sopenharmony_ci		goto free;
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	field = MLX5_ADDR_OF(query_cong_params_out, out, congestion_parameters);
2988c2ecf20Sopenharmony_ci	*var = mlx5_get_cc_param_val(field, offset);
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_cifree:
3018c2ecf20Sopenharmony_ci	kvfree(out);
3028c2ecf20Sopenharmony_cialloc_err:
3038c2ecf20Sopenharmony_ci	mlx5_ib_put_native_port_mdev(dev, port_num + 1);
3048c2ecf20Sopenharmony_ci	return err;
3058c2ecf20Sopenharmony_ci}
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_cistatic int mlx5_ib_set_cc_params(struct mlx5_ib_dev *dev, u8 port_num,
3088c2ecf20Sopenharmony_ci				 int offset, u32 var)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	int inlen = MLX5_ST_SZ_BYTES(modify_cong_params_in);
3118c2ecf20Sopenharmony_ci	void *in;
3128c2ecf20Sopenharmony_ci	void *field;
3138c2ecf20Sopenharmony_ci	enum mlx5_ib_cong_node_type node;
3148c2ecf20Sopenharmony_ci	struct mlx5_core_dev *mdev;
3158c2ecf20Sopenharmony_ci	u32 attr_mask = 0;
3168c2ecf20Sopenharmony_ci	int err;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	/* Takes a 1-based port number */
3198c2ecf20Sopenharmony_ci	mdev = mlx5_ib_get_native_port_mdev(dev, port_num + 1, NULL);
3208c2ecf20Sopenharmony_ci	if (!mdev)
3218c2ecf20Sopenharmony_ci		return -ENODEV;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	in = kvzalloc(inlen, GFP_KERNEL);
3248c2ecf20Sopenharmony_ci	if (!in) {
3258c2ecf20Sopenharmony_ci		err = -ENOMEM;
3268c2ecf20Sopenharmony_ci		goto alloc_err;
3278c2ecf20Sopenharmony_ci	}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	MLX5_SET(modify_cong_params_in, in, opcode,
3308c2ecf20Sopenharmony_ci		 MLX5_CMD_OP_MODIFY_CONG_PARAMS);
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	node = mlx5_ib_param_to_node(offset);
3338c2ecf20Sopenharmony_ci	MLX5_SET(modify_cong_params_in, in, cong_protocol, node);
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	field = MLX5_ADDR_OF(modify_cong_params_in, in, congestion_parameters);
3368c2ecf20Sopenharmony_ci	mlx5_ib_set_cc_param_mask_val(field, offset, var, &attr_mask);
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	field = MLX5_ADDR_OF(modify_cong_params_in, in, field_select);
3398c2ecf20Sopenharmony_ci	MLX5_SET(field_select_r_roce_rp, field, field_select_r_roce_rp,
3408c2ecf20Sopenharmony_ci		 attr_mask);
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	err = mlx5_cmd_exec_in(dev->mdev, modify_cong_params, in);
3438c2ecf20Sopenharmony_ci	kvfree(in);
3448c2ecf20Sopenharmony_cialloc_err:
3458c2ecf20Sopenharmony_ci	mlx5_ib_put_native_port_mdev(dev, port_num + 1);
3468c2ecf20Sopenharmony_ci	return err;
3478c2ecf20Sopenharmony_ci}
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_cistatic ssize_t set_param(struct file *filp, const char __user *buf,
3508c2ecf20Sopenharmony_ci			 size_t count, loff_t *pos)
3518c2ecf20Sopenharmony_ci{
3528c2ecf20Sopenharmony_ci	struct mlx5_ib_dbg_param *param = filp->private_data;
3538c2ecf20Sopenharmony_ci	int offset = param->offset;
3548c2ecf20Sopenharmony_ci	char lbuf[11] = { };
3558c2ecf20Sopenharmony_ci	u32 var;
3568c2ecf20Sopenharmony_ci	int ret;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	if (count > sizeof(lbuf))
3598c2ecf20Sopenharmony_ci		return -EINVAL;
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	if (copy_from_user(lbuf, buf, count))
3628c2ecf20Sopenharmony_ci		return -EFAULT;
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	lbuf[sizeof(lbuf) - 1] = '\0';
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	if (kstrtou32(lbuf, 0, &var))
3678c2ecf20Sopenharmony_ci		return -EINVAL;
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	ret = mlx5_ib_set_cc_params(param->dev, param->port_num, offset, var);
3708c2ecf20Sopenharmony_ci	return ret ? ret : count;
3718c2ecf20Sopenharmony_ci}
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_cistatic ssize_t get_param(struct file *filp, char __user *buf, size_t count,
3748c2ecf20Sopenharmony_ci			 loff_t *pos)
3758c2ecf20Sopenharmony_ci{
3768c2ecf20Sopenharmony_ci	struct mlx5_ib_dbg_param *param = filp->private_data;
3778c2ecf20Sopenharmony_ci	int offset = param->offset;
3788c2ecf20Sopenharmony_ci	u32 var = 0;
3798c2ecf20Sopenharmony_ci	int ret;
3808c2ecf20Sopenharmony_ci	char lbuf[11];
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	ret = mlx5_ib_get_cc_params(param->dev, param->port_num, offset, &var);
3838c2ecf20Sopenharmony_ci	if (ret)
3848c2ecf20Sopenharmony_ci		return ret;
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	ret = snprintf(lbuf, sizeof(lbuf), "%d\n", var);
3878c2ecf20Sopenharmony_ci	if (ret < 0)
3888c2ecf20Sopenharmony_ci		return ret;
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	return simple_read_from_buffer(buf, count, pos, lbuf, ret);
3918c2ecf20Sopenharmony_ci}
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_cistatic const struct file_operations dbg_cc_fops = {
3948c2ecf20Sopenharmony_ci	.owner	= THIS_MODULE,
3958c2ecf20Sopenharmony_ci	.open	= simple_open,
3968c2ecf20Sopenharmony_ci	.write	= set_param,
3978c2ecf20Sopenharmony_ci	.read	= get_param,
3988c2ecf20Sopenharmony_ci};
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_civoid mlx5_ib_cleanup_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num)
4018c2ecf20Sopenharmony_ci{
4028c2ecf20Sopenharmony_ci	if (!mlx5_debugfs_root ||
4038c2ecf20Sopenharmony_ci	    !dev->port[port_num].dbg_cc_params ||
4048c2ecf20Sopenharmony_ci	    !dev->port[port_num].dbg_cc_params->root)
4058c2ecf20Sopenharmony_ci		return;
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci	debugfs_remove_recursive(dev->port[port_num].dbg_cc_params->root);
4088c2ecf20Sopenharmony_ci	kfree(dev->port[port_num].dbg_cc_params);
4098c2ecf20Sopenharmony_ci	dev->port[port_num].dbg_cc_params = NULL;
4108c2ecf20Sopenharmony_ci}
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_civoid mlx5_ib_init_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num)
4138c2ecf20Sopenharmony_ci{
4148c2ecf20Sopenharmony_ci	struct mlx5_ib_dbg_cc_params *dbg_cc_params;
4158c2ecf20Sopenharmony_ci	struct mlx5_core_dev *mdev;
4168c2ecf20Sopenharmony_ci	int i;
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	if (!mlx5_debugfs_root)
4198c2ecf20Sopenharmony_ci		return;
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	/* Takes a 1-based port number */
4228c2ecf20Sopenharmony_ci	mdev = mlx5_ib_get_native_port_mdev(dev, port_num + 1, NULL);
4238c2ecf20Sopenharmony_ci	if (!mdev)
4248c2ecf20Sopenharmony_ci		return;
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	if (!MLX5_CAP_GEN(mdev, cc_query_allowed) ||
4278c2ecf20Sopenharmony_ci	    !MLX5_CAP_GEN(mdev, cc_modify_allowed))
4288c2ecf20Sopenharmony_ci		goto put_mdev;
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	dbg_cc_params = kzalloc(sizeof(*dbg_cc_params), GFP_KERNEL);
4318c2ecf20Sopenharmony_ci	if (!dbg_cc_params)
4328c2ecf20Sopenharmony_ci		goto err;
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci	dev->port[port_num].dbg_cc_params = dbg_cc_params;
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	dbg_cc_params->root = debugfs_create_dir("cc_params",
4378c2ecf20Sopenharmony_ci						 mdev->priv.dbg_root);
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	for (i = 0; i < MLX5_IB_DBG_CC_MAX; i++) {
4408c2ecf20Sopenharmony_ci		dbg_cc_params->params[i].offset = i;
4418c2ecf20Sopenharmony_ci		dbg_cc_params->params[i].dev = dev;
4428c2ecf20Sopenharmony_ci		dbg_cc_params->params[i].port_num = port_num;
4438c2ecf20Sopenharmony_ci		dbg_cc_params->params[i].dentry =
4448c2ecf20Sopenharmony_ci			debugfs_create_file(mlx5_ib_dbg_cc_name[i],
4458c2ecf20Sopenharmony_ci					    0600, dbg_cc_params->root,
4468c2ecf20Sopenharmony_ci					    &dbg_cc_params->params[i],
4478c2ecf20Sopenharmony_ci					    &dbg_cc_fops);
4488c2ecf20Sopenharmony_ci	}
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ciput_mdev:
4518c2ecf20Sopenharmony_ci	mlx5_ib_put_native_port_mdev(dev, port_num + 1);
4528c2ecf20Sopenharmony_ci	return;
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_cierr:
4558c2ecf20Sopenharmony_ci	mlx5_ib_warn(dev, "cong debugfs failure\n");
4568c2ecf20Sopenharmony_ci	mlx5_ib_cleanup_cong_debugfs(dev, port_num);
4578c2ecf20Sopenharmony_ci	mlx5_ib_put_native_port_mdev(dev, port_num + 1);
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci	/*
4608c2ecf20Sopenharmony_ci	 * We don't want to fail driver if debugfs failed to initialize,
4618c2ecf20Sopenharmony_ci	 * so we are not forwarding error to the user.
4628c2ecf20Sopenharmony_ci	 */
4638c2ecf20Sopenharmony_ci	return;
4648c2ecf20Sopenharmony_ci}
465