summaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/mellanox/mlx5/core/en/channels.c
blob: 66e719e88503bdb75da716f5c6ec45d3f01d4fb8 (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
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/* Copyright (c) 2021, Mellanox Technologies inc. All rights reserved. */

#include "channels.h"
#include "en.h"
#include "en/dim.h"
#include "en/ptp.h"

unsigned int mlx5e_channels_get_num(struct mlx5e_channels *chs)
{
	return chs->num;
}

static struct mlx5e_channel *mlx5e_channels_get(struct mlx5e_channels *chs, unsigned int ix)
{
	WARN_ON_ONCE(ix >= mlx5e_channels_get_num(chs));
	return chs->c[ix];
}

bool mlx5e_channels_is_xsk(struct mlx5e_channels *chs, unsigned int ix)
{
	struct mlx5e_channel *c = mlx5e_channels_get(chs, ix);

	return test_bit(MLX5E_CHANNEL_STATE_XSK, c->state);
}

void mlx5e_channels_get_regular_rqn(struct mlx5e_channels *chs, unsigned int ix, u32 *rqn,
				    u32 *vhca_id)
{
	struct mlx5e_channel *c = mlx5e_channels_get(chs, ix);

	*rqn = c->rq.rqn;
	if (vhca_id)
		*vhca_id = MLX5_CAP_GEN(c->mdev, vhca_id);
}

void mlx5e_channels_get_xsk_rqn(struct mlx5e_channels *chs, unsigned int ix, u32 *rqn,
				u32 *vhca_id)
{
	struct mlx5e_channel *c = mlx5e_channels_get(chs, ix);

	WARN_ON_ONCE(!test_bit(MLX5E_CHANNEL_STATE_XSK, c->state));

	*rqn = c->xskrq.rqn;
	if (vhca_id)
		*vhca_id = MLX5_CAP_GEN(c->mdev, vhca_id);
}

bool mlx5e_channels_get_ptp_rqn(struct mlx5e_channels *chs, u32 *rqn)
{
	struct mlx5e_ptp *c = chs->ptp;

	if (!c || !test_bit(MLX5E_PTP_STATE_RX, c->state))
		return false;

	*rqn = c->rq.rqn;
	return true;
}

int mlx5e_channels_rx_change_dim(struct mlx5e_channels *chs, bool enable)
{
	int i;

	for (i = 0; i < chs->num; i++) {
		int err = mlx5e_dim_rx_change(&chs->c[i]->rq, enable);

		if (err)
			return err;
	}

	return 0;
}

int mlx5e_channels_tx_change_dim(struct mlx5e_channels *chs, bool enable)
{
	int i, tc;

	for (i = 0; i < chs->num; i++) {
		for (tc = 0; tc < mlx5e_get_dcb_num_tc(&chs->params); tc++) {
			int err = mlx5e_dim_tx_change(&chs->c[i]->sq[tc], enable);

			if (err)
				return err;
		}
	}

	return 0;
}

int mlx5e_channels_rx_toggle_dim(struct mlx5e_channels *chs)
{
	int i;

	for (i = 0; i < chs->num; i++) {
		/* If dim is enabled for the channel, reset the dim state so the
		 * collected statistics will be reset. This is useful for
		 * supporting legacy interfaces that allow things like changing
		 * the CQ period mode for all channels without disturbing
		 * individual channel configurations.
		 */
		if (chs->c[i]->rq.dim) {
			int err;

			mlx5e_dim_rx_change(&chs->c[i]->rq, false);
			err = mlx5e_dim_rx_change(&chs->c[i]->rq, true);
			if (err)
				return err;
		}
	}

	return 0;
}

int mlx5e_channels_tx_toggle_dim(struct mlx5e_channels *chs)
{
	int i, tc;

	for (i = 0; i < chs->num; i++) {
		for (tc = 0; tc < mlx5e_get_dcb_num_tc(&chs->params); tc++) {
			int err;

			/* If dim is enabled for the channel, reset the dim
			 * state so the collected statistics will be reset. This
			 * is useful for supporting legacy interfaces that allow
			 * things like changing the CQ period mode for all
			 * channels without disturbing individual channel
			 * configurations.
			 */
			if (!chs->c[i]->sq[tc].dim)
				continue;

			mlx5e_dim_tx_change(&chs->c[i]->sq[tc], false);
			err = mlx5e_dim_tx_change(&chs->c[i]->sq[tc], true);
			if (err)
				return err;
		}
	}

	return 0;
}