1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019 Mellanox Technologies. */
3
4 #ifndef __MLX5_EN_PARAMS_H__
5 #define __MLX5_EN_PARAMS_H__
6
7 #include "en.h"
8
9 struct mlx5e_xsk_param {
10 u16 headroom;
11 u16 chunk_size;
12 };
13
14 struct mlx5e_lro_param {
15 bool enabled;
16 u32 timeout;
17 };
18
19 struct mlx5e_cq_param {
20 u32 cqc[MLX5_ST_SZ_DW(cqc)];
21 struct mlx5_wq_param wq;
22 u16 eq_ix;
23 u8 cq_period_mode;
24 };
25
26 struct mlx5e_rq_param {
27 struct mlx5e_cq_param cqp;
28 u32 rqc[MLX5_ST_SZ_DW(rqc)];
29 struct mlx5_wq_param wq;
30 struct mlx5e_rq_frags_info frags_info;
31 };
32
33 struct mlx5e_sq_param {
34 struct mlx5e_cq_param cqp;
35 u32 sqc[MLX5_ST_SZ_DW(sqc)];
36 struct mlx5_wq_param wq;
37 bool is_mpw;
38 bool is_tls;
39 u16 stop_room;
40 };
41
42 struct mlx5e_channel_param {
43 struct mlx5e_rq_param rq;
44 struct mlx5e_sq_param txq_sq;
45 struct mlx5e_sq_param xdp_sq;
46 struct mlx5e_sq_param icosq;
47 struct mlx5e_sq_param async_icosq;
48 };
49
50 struct mlx5e_create_sq_param {
51 struct mlx5_wq_ctrl *wq_ctrl;
52 u32 cqn;
53 u32 ts_cqe_to_dest_cqn;
54 u32 tisn;
55 u8 tis_lst_sz;
56 u8 min_inline_mode;
57 };
58
mlx5e_qid_get_ch_if_in_group(struct mlx5e_params * params,u16 qid,enum mlx5e_rq_group group,u16 * ix)59 static inline bool mlx5e_qid_get_ch_if_in_group(struct mlx5e_params *params,
60 u16 qid,
61 enum mlx5e_rq_group group,
62 u16 *ix)
63 {
64 int nch = params->num_channels;
65 int ch = qid - nch * group;
66
67 if (ch < 0 || ch >= nch)
68 return false;
69
70 *ix = ch;
71 return true;
72 }
73
mlx5e_qid_get_ch_and_group(struct mlx5e_params * params,u16 qid,u16 * ix,enum mlx5e_rq_group * group)74 static inline void mlx5e_qid_get_ch_and_group(struct mlx5e_params *params,
75 u16 qid,
76 u16 *ix,
77 enum mlx5e_rq_group *group)
78 {
79 u16 nch = params->num_channels;
80
81 *ix = qid % nch;
82 *group = qid / nch;
83 }
84
mlx5e_qid_validate(const struct mlx5e_profile * profile,struct mlx5e_params * params,u64 qid)85 static inline bool mlx5e_qid_validate(const struct mlx5e_profile *profile,
86 struct mlx5e_params *params, u64 qid)
87 {
88 return qid < params->num_channels * profile->rq_groups;
89 }
90
91 /* Parameter calculations */
92
93 void mlx5e_reset_tx_moderation(struct mlx5e_params *params, u8 cq_period_mode);
94 void mlx5e_reset_rx_moderation(struct mlx5e_params *params, u8 cq_period_mode);
95 void mlx5e_set_tx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode);
96 void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode);
97
98 bool slow_pci_heuristic(struct mlx5_core_dev *mdev);
99 bool mlx5e_striding_rq_possible(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
100 void mlx5e_build_rq_params(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
101 void mlx5e_set_rq_type(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
102 void mlx5e_init_rq_type_params(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
103
104 bool mlx5e_verify_rx_mpwqe_strides(struct mlx5_core_dev *mdev,
105 u8 log_stride_sz, u8 log_num_strides);
106 u16 mlx5e_get_linear_rq_headroom(struct mlx5e_params *params,
107 struct mlx5e_xsk_param *xsk);
108 u32 mlx5e_rx_get_min_frag_sz(struct mlx5e_params *params,
109 struct mlx5e_xsk_param *xsk);
110 u8 mlx5e_mpwqe_log_pkts_per_wqe(struct mlx5e_params *params,
111 struct mlx5e_xsk_param *xsk);
112 bool mlx5e_rx_is_linear_skb(struct mlx5e_params *params,
113 struct mlx5e_xsk_param *xsk);
114 bool mlx5e_rx_mpwqe_is_linear_skb(struct mlx5_core_dev *mdev,
115 struct mlx5e_params *params,
116 struct mlx5e_xsk_param *xsk);
117 u8 mlx5e_mpwqe_get_log_rq_size(struct mlx5e_params *params,
118 struct mlx5e_xsk_param *xsk);
119 u8 mlx5e_mpwqe_get_log_stride_size(struct mlx5_core_dev *mdev,
120 struct mlx5e_params *params,
121 struct mlx5e_xsk_param *xsk);
122 u8 mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev *mdev,
123 struct mlx5e_params *params,
124 struct mlx5e_xsk_param *xsk);
125 u16 mlx5e_get_rq_headroom(struct mlx5_core_dev *mdev,
126 struct mlx5e_params *params,
127 struct mlx5e_xsk_param *xsk);
128 struct mlx5e_lro_param mlx5e_get_lro_param(struct mlx5e_params *params);
129
130 /* Build queue parameters */
131
132 void mlx5e_build_create_cq_param(struct mlx5e_create_cq_param *ccp, struct mlx5e_channel *c);
133 int mlx5e_build_rq_param(struct mlx5_core_dev *mdev,
134 struct mlx5e_params *params,
135 struct mlx5e_xsk_param *xsk,
136 u16 q_counter,
137 struct mlx5e_rq_param *param);
138 void mlx5e_build_drop_rq_param(struct mlx5_core_dev *mdev,
139 u16 q_counter,
140 struct mlx5e_rq_param *param);
141 void mlx5e_build_sq_param_common(struct mlx5_core_dev *mdev,
142 struct mlx5e_sq_param *param);
143 void mlx5e_build_sq_param(struct mlx5_core_dev *mdev,
144 struct mlx5e_params *params,
145 struct mlx5e_sq_param *param);
146 void mlx5e_build_tx_cq_param(struct mlx5_core_dev *mdev,
147 struct mlx5e_params *params,
148 struct mlx5e_cq_param *param);
149 void mlx5e_build_xdpsq_param(struct mlx5_core_dev *mdev,
150 struct mlx5e_params *params,
151 struct mlx5e_sq_param *param);
152 int mlx5e_build_channel_param(struct mlx5_core_dev *mdev,
153 struct mlx5e_params *params,
154 u16 q_counter,
155 struct mlx5e_channel_param *cparam);
156
157 u16 mlx5e_calc_sq_stop_room(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
158 int mlx5e_validate_params(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
159
160 #endif /* __MLX5_EN_PARAMS_H__ */
161