summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/mellanox/mlx5/core/diag/reporter_vnic.c
blob: e869c65d8e90f51eca0b5cb51dd7bf49d78bfd59 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. */

#include "reporter_vnic.h"
#include "en_stats.h"
#include "devlink.h"

#define VNIC_ENV_GET64(vnic_env_stats, c) \
	MLX5_GET64(query_vnic_env_out, (vnic_env_stats)->query_vnic_env_out, \
		 vport_env.c)

struct mlx5_vnic_diag_stats {
	__be64 query_vnic_env_out[MLX5_ST_SZ_QW(query_vnic_env_out)];
};

int mlx5_reporter_vnic_diagnose_counters(struct mlx5_core_dev *dev,
					 struct devlink_fmsg *fmsg,
					 u16 vport_num, bool other_vport)
{
	u32 in[MLX5_ST_SZ_DW(query_vnic_env_in)] = {};
	struct mlx5_vnic_diag_stats vnic;
	int err;

	MLX5_SET(query_vnic_env_in, in, opcode, MLX5_CMD_OP_QUERY_VNIC_ENV);
	MLX5_SET(query_vnic_env_in, in, vport_number, vport_num);
	MLX5_SET(query_vnic_env_in, in, other_vport, !!other_vport);

	err = mlx5_cmd_exec_inout(dev, query_vnic_env, in, &vnic.query_vnic_env_out);
	if (err)
		return err;

	err = devlink_fmsg_pair_nest_start(fmsg, "vNIC env counters");
	if (err)
		return err;

	err = devlink_fmsg_obj_nest_start(fmsg);
	if (err)
		return err;

	if (MLX5_CAP_GEN(dev, vnic_env_queue_counters)) {
		err = devlink_fmsg_u32_pair_put(fmsg, "total_error_queues",
						VNIC_ENV_GET(&vnic, total_error_queues));
		if (err)
			return err;

		err = devlink_fmsg_u32_pair_put(fmsg, "send_queue_priority_update_flow",
						VNIC_ENV_GET(&vnic,
							     send_queue_priority_update_flow));
		if (err)
			return err;
	}

	if (MLX5_CAP_GEN(dev, eq_overrun_count)) {
		err = devlink_fmsg_u32_pair_put(fmsg, "comp_eq_overrun",
						VNIC_ENV_GET(&vnic, comp_eq_overrun));
		if (err)
			return err;

		err = devlink_fmsg_u32_pair_put(fmsg, "async_eq_overrun",
						VNIC_ENV_GET(&vnic, async_eq_overrun));
		if (err)
			return err;
	}

	if (MLX5_CAP_GEN(dev, vnic_env_cq_overrun)) {
		err = devlink_fmsg_u32_pair_put(fmsg, "cq_overrun",
						VNIC_ENV_GET(&vnic, cq_overrun));
		if (err)
			return err;
	}

	if (MLX5_CAP_GEN(dev, invalid_command_count)) {
		err = devlink_fmsg_u32_pair_put(fmsg, "invalid_command",
						VNIC_ENV_GET(&vnic, invalid_command));
		if (err)
			return err;
	}

	if (MLX5_CAP_GEN(dev, quota_exceeded_count)) {
		err = devlink_fmsg_u32_pair_put(fmsg, "quota_exceeded_command",
						VNIC_ENV_GET(&vnic, quota_exceeded_command));
		if (err)
			return err;
	}

	if (MLX5_CAP_GEN(dev, nic_receive_steering_discard)) {
		err = devlink_fmsg_u64_pair_put(fmsg, "nic_receive_steering_discard",
						VNIC_ENV_GET64(&vnic,
							       nic_receive_steering_discard));
		if (err)
			return err;
	}

	if (MLX5_CAP_GEN(dev, vnic_env_cnt_steering_fail)) {
		err = devlink_fmsg_u64_pair_put(fmsg, "generated_pkt_steering_fail",
						VNIC_ENV_GET64(&vnic,
							       generated_pkt_steering_fail));
		if (err)
			return err;

		err = devlink_fmsg_u64_pair_put(fmsg, "handled_pkt_steering_fail",
						VNIC_ENV_GET64(&vnic, handled_pkt_steering_fail));
		if (err)
			return err;
	}

	err = devlink_fmsg_obj_nest_end(fmsg);
	if (err)
		return err;

	err = devlink_fmsg_pair_nest_end(fmsg);
	if (err)
		return err;

	return 0;
}

static int mlx5_reporter_vnic_diagnose(struct devlink_health_reporter *reporter,
				       struct devlink_fmsg *fmsg,
				       struct netlink_ext_ack *extack)
{
	struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);

	return mlx5_reporter_vnic_diagnose_counters(dev, fmsg, 0, false);
}

static const struct devlink_health_reporter_ops mlx5_reporter_vnic_ops = {
	.name = "vnic",
	.diagnose = mlx5_reporter_vnic_diagnose,
};

void mlx5_reporter_vnic_create(struct mlx5_core_dev *dev)
{
	struct mlx5_core_health *health = &dev->priv.health;
	struct devlink *devlink = priv_to_devlink(dev);

	health->vnic_reporter =
		devlink_health_reporter_create(devlink,
					       &mlx5_reporter_vnic_ops,
					       0, dev);
	if (IS_ERR(health->vnic_reporter))
		mlx5_core_warn(dev,
			       "Failed to create vnic reporter, err = %ld\n",
			       PTR_ERR(health->vnic_reporter));
}

void mlx5_reporter_vnic_destroy(struct mlx5_core_dev *dev)
{
	struct mlx5_core_health *health = &dev->priv.health;

	if (!IS_ERR_OR_NULL(health->vnic_reporter))
		devlink_health_reporter_destroy(health->vnic_reporter);
}