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 
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 
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 
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_mpwqe_get_log_stride_size(struct mlx5_core_dev *mdev,
115 				   struct mlx5e_params *params,
116 				   struct mlx5e_xsk_param *xsk);
117 u8 mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev *mdev,
118 				   struct mlx5e_params *params,
119 				   struct mlx5e_xsk_param *xsk);
120 u16 mlx5e_get_rq_headroom(struct mlx5_core_dev *mdev,
121 			  struct mlx5e_params *params,
122 			  struct mlx5e_xsk_param *xsk);
123 
124 /* Build queue parameters */
125 
126 void mlx5e_build_create_cq_param(struct mlx5e_create_cq_param *ccp, struct mlx5e_channel *c);
127 int mlx5e_build_rq_param(struct mlx5_core_dev *mdev,
128 			 struct mlx5e_params *params,
129 			 struct mlx5e_xsk_param *xsk,
130 			 u16 q_counter,
131 			 struct mlx5e_rq_param *param);
132 void mlx5e_build_drop_rq_param(struct mlx5_core_dev *mdev,
133 			       u16 q_counter,
134 			       struct mlx5e_rq_param *param);
135 void mlx5e_build_sq_param_common(struct mlx5_core_dev *mdev,
136 				 struct mlx5e_sq_param *param);
137 void mlx5e_build_sq_param(struct mlx5_core_dev *mdev,
138 			  struct mlx5e_params *params,
139 			  struct mlx5e_sq_param *param);
140 void mlx5e_build_tx_cq_param(struct mlx5_core_dev *mdev,
141 			     struct mlx5e_params *params,
142 			     struct mlx5e_cq_param *param);
143 void mlx5e_build_xdpsq_param(struct mlx5_core_dev *mdev,
144 			     struct mlx5e_params *params,
145 			     struct mlx5e_sq_param *param);
146 int mlx5e_build_channel_param(struct mlx5_core_dev *mdev,
147 			      struct mlx5e_params *params,
148 			      u16 q_counter,
149 			      struct mlx5e_channel_param *cparam);
150 
151 u16 mlx5e_calc_sq_stop_room(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
152 int mlx5e_validate_params(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
153 
154 #endif /* __MLX5_EN_PARAMS_H__ */
155