1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2021, Mellanox Technologies inc. All rights reserved. */
3 
4 #include "channels.h"
5 #include "en.h"
6 #include "en/ptp.h"
7 
mlx5e_channels_get_num(struct mlx5e_channels * chs)8 unsigned int mlx5e_channels_get_num(struct mlx5e_channels *chs)
9 {
10 	return chs->num;
11 }
12 
mlx5e_channels_get(struct mlx5e_channels * chs,unsigned int ix)13 static struct mlx5e_channel *mlx5e_channels_get(struct mlx5e_channels *chs, unsigned int ix)
14 {
15 	WARN_ON_ONCE(ix >= mlx5e_channels_get_num(chs));
16 	return chs->c[ix];
17 }
18 
mlx5e_channels_is_xsk(struct mlx5e_channels * chs,unsigned int ix)19 bool mlx5e_channels_is_xsk(struct mlx5e_channels *chs, unsigned int ix)
20 {
21 	struct mlx5e_channel *c = mlx5e_channels_get(chs, ix);
22 
23 	return test_bit(MLX5E_CHANNEL_STATE_XSK, c->state);
24 }
25 
mlx5e_channels_get_regular_rqn(struct mlx5e_channels * chs,unsigned int ix,u32 * rqn)26 void mlx5e_channels_get_regular_rqn(struct mlx5e_channels *chs, unsigned int ix, u32 *rqn)
27 {
28 	struct mlx5e_channel *c = mlx5e_channels_get(chs, ix);
29 
30 	*rqn = c->rq.rqn;
31 }
32 
mlx5e_channels_get_xsk_rqn(struct mlx5e_channels * chs,unsigned int ix,u32 * rqn)33 void mlx5e_channels_get_xsk_rqn(struct mlx5e_channels *chs, unsigned int ix, u32 *rqn)
34 {
35 	struct mlx5e_channel *c = mlx5e_channels_get(chs, ix);
36 
37 	WARN_ON_ONCE(!test_bit(MLX5E_CHANNEL_STATE_XSK, c->state));
38 
39 	*rqn = c->xskrq.rqn;
40 }
41 
mlx5e_channels_get_ptp_rqn(struct mlx5e_channels * chs,u32 * rqn)42 bool mlx5e_channels_get_ptp_rqn(struct mlx5e_channels *chs, u32 *rqn)
43 {
44 	struct mlx5e_ptp *c = chs->ptp;
45 
46 	if (!c || !test_bit(MLX5E_PTP_STATE_RX, c->state))
47 		return false;
48 
49 	*rqn = c->rq.rqn;
50 	return true;
51 }
52