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