summaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/mellanox/mlx5/core/qos.c
blob: 0777be24a3074a7a078b091cb30b93d4d33df9e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/* Copyright (c) 2020, Mellanox Technologies inc. All rights reserved. */

#include "qos.h"

#define MLX5_QOS_DEFAULT_DWRR_UID 0

bool mlx5_qos_is_supported(struct mlx5_core_dev *mdev)
{
	if (!MLX5_CAP_GEN(mdev, qos))
		return false;
	if (!MLX5_CAP_QOS(mdev, nic_sq_scheduling))
		return false;
	if (!MLX5_CAP_QOS(mdev, nic_bw_share))
		return false;
	if (!MLX5_CAP_QOS(mdev, nic_rate_limit))
		return false;
	return true;
}

int mlx5_qos_max_leaf_nodes(struct mlx5_core_dev *mdev)
{
	return 1 << MLX5_CAP_QOS(mdev, log_max_qos_nic_queue_group);
}

int mlx5_qos_create_leaf_node(struct mlx5_core_dev *mdev, u32 parent_id,
			      u32 bw_share, u32 max_avg_bw, u32 *id)
{
	u32 sched_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {0};

	MLX5_SET(scheduling_context, sched_ctx, parent_element_id, parent_id);
	MLX5_SET(scheduling_context, sched_ctx, element_type,
		 SCHEDULING_CONTEXT_ELEMENT_TYPE_QUEUE_GROUP);
	MLX5_SET(scheduling_context, sched_ctx, bw_share, bw_share);
	MLX5_SET(scheduling_context, sched_ctx, max_average_bw, max_avg_bw);

	return mlx5_create_scheduling_element_cmd(mdev, SCHEDULING_HIERARCHY_NIC,
						  sched_ctx, id);
}

int mlx5_qos_create_inner_node(struct mlx5_core_dev *mdev, u32 parent_id,
			       u32 bw_share, u32 max_avg_bw, u32 *id)
{
	u32 sched_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {0};
	void *attr;

	MLX5_SET(scheduling_context, sched_ctx, parent_element_id, parent_id);
	MLX5_SET(scheduling_context, sched_ctx, element_type,
		 SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR);
	MLX5_SET(scheduling_context, sched_ctx, bw_share, bw_share);
	MLX5_SET(scheduling_context, sched_ctx, max_average_bw, max_avg_bw);

	attr = MLX5_ADDR_OF(scheduling_context, sched_ctx, element_attributes);
	MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR);

	return mlx5_create_scheduling_element_cmd(mdev, SCHEDULING_HIERARCHY_NIC,
						  sched_ctx, id);
}

int mlx5_qos_create_root_node(struct mlx5_core_dev *mdev, u32 *id)
{
	return mlx5_qos_create_inner_node(mdev, MLX5_QOS_DEFAULT_DWRR_UID, 0, 0, id);
}

int mlx5_qos_update_node(struct mlx5_core_dev *mdev, u32 parent_id,
			 u32 bw_share, u32 max_avg_bw, u32 id)
{
	u32 sched_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {0};
	u32 bitmask = 0;

	MLX5_SET(scheduling_context, sched_ctx, parent_element_id, parent_id);
	MLX5_SET(scheduling_context, sched_ctx, bw_share, bw_share);
	MLX5_SET(scheduling_context, sched_ctx, max_average_bw, max_avg_bw);

	bitmask |= MODIFY_SCHEDULING_ELEMENT_IN_MODIFY_BITMASK_BW_SHARE;
	bitmask |= MODIFY_SCHEDULING_ELEMENT_IN_MODIFY_BITMASK_MAX_AVERAGE_BW;

	return mlx5_modify_scheduling_element_cmd(mdev, SCHEDULING_HIERARCHY_NIC,
						  sched_ctx, id, bitmask);
}

int mlx5_qos_destroy_node(struct mlx5_core_dev *mdev, u32 id)
{
	return mlx5_destroy_scheduling_element_cmd(mdev, SCHEDULING_HIERARCHY_NIC, id);
}