xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/en/params.h (revision 91a4855d6c03e770e42f17c798a36a3c46e63de2)
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 	u32 chunk_size;
12 	bool unaligned;
13 };
14 
15 struct mlx5e_rq_opt_param {
16 	struct mlx5e_xsk_param *xsk;
17 	struct netdev_queue_config *qcfg;
18 };
19 
20 struct mlx5e_cq_param {
21 	u32                        cqc[MLX5_ST_SZ_DW(cqc)];
22 	struct mlx5_wq_param       wq;
23 	u16                        eq_ix;
24 	u8                         cq_period_mode;
25 };
26 
27 struct mlx5e_rq_param {
28 	struct mlx5e_cq_param      cqp;
29 	u32                        rqc[MLX5_ST_SZ_DW(rqc)];
30 	struct mlx5_wq_param       wq;
31 	struct mlx5e_rq_frags_info frags_info;
32 	u32                        xdp_frag_size;
33 };
34 
35 struct mlx5e_sq_param {
36 	struct mlx5e_cq_param      cqp;
37 	u32                        sqc[MLX5_ST_SZ_DW(sqc)];
38 	struct mlx5_wq_param       wq;
39 	bool                       is_mpw;
40 	bool                       is_tls;
41 	u16                        stop_room;
42 };
43 
44 struct mlx5e_channel_param {
45 	struct mlx5e_rq_param      rq;
46 	struct mlx5e_rq_opt_param  rq_opt;
47 	struct mlx5e_sq_param      txq_sq;
48 	struct mlx5e_sq_param      xdp_sq;
49 	struct mlx5e_sq_param      icosq;
50 	struct mlx5e_sq_param      async_icosq;
51 };
52 
53 struct mlx5e_create_sq_param {
54 	struct mlx5_wq_ctrl        *wq_ctrl;
55 	u32                         cqn;
56 	u32                         ts_cqe_to_dest_cqn;
57 	u32                         tisn;
58 	u8                          tis_lst_sz;
59 	u8                          min_inline_mode;
60 	u32                         uar_page;
61 };
62 
63 /* Striding RQ dynamic parameters */
64 
65 u8 mlx5e_mpwrq_page_shift(struct mlx5_core_dev *mdev,
66 			  struct mlx5e_rq_opt_param *rqo);
67 enum mlx5e_mpwrq_umr_mode
68 mlx5e_mpwrq_umr_mode(struct mlx5_core_dev *mdev,
69 		     struct mlx5e_rq_opt_param *rqo);
70 u8 mlx5e_mpwrq_umr_entry_size(enum mlx5e_mpwrq_umr_mode mode);
71 u8 mlx5e_mpwrq_log_wqe_sz(struct mlx5_core_dev *mdev, u8 page_shift,
72 			  enum mlx5e_mpwrq_umr_mode umr_mode);
73 u8 mlx5e_mpwrq_pages_per_wqe(struct mlx5_core_dev *mdev, u8 page_shift,
74 			     enum mlx5e_mpwrq_umr_mode umr_mode);
75 u16 mlx5e_mpwrq_umr_wqe_sz(struct mlx5_core_dev *mdev, u8 page_shift,
76 			   enum mlx5e_mpwrq_umr_mode umr_mode);
77 u8 mlx5e_mpwrq_umr_wqebbs(struct mlx5_core_dev *mdev, u8 page_shift,
78 			  enum mlx5e_mpwrq_umr_mode umr_mode);
79 u8 mlx5e_mpwrq_mtts_per_wqe(struct mlx5_core_dev *mdev, u8 page_shift,
80 			    enum mlx5e_mpwrq_umr_mode umr_mode);
81 u32 mlx5e_mpwrq_max_num_entries(struct mlx5_core_dev *mdev,
82 				enum mlx5e_mpwrq_umr_mode umr_mode);
83 u8 mlx5e_mpwrq_max_log_rq_pkts(struct mlx5_core_dev *mdev, u8 page_shift,
84 			       enum mlx5e_mpwrq_umr_mode umr_mode);
85 
86 /* Parameter calculations */
87 
88 bool slow_pci_heuristic(struct mlx5_core_dev *mdev);
89 int mlx5e_mpwrq_validate_regular(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
90 int mlx5e_mpwrq_validate_xsk(struct mlx5_core_dev *mdev, struct mlx5e_params *params,
91 			     struct mlx5e_rq_opt_param *rqo);
92 void mlx5e_build_rq_params(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
93 void mlx5e_set_rq_type(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
94 void mlx5e_init_rq_type_params(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
95 
96 u16 mlx5e_get_linear_rq_headroom(struct mlx5e_params *params,
97 				 struct mlx5e_rq_opt_param *rqo);
98 bool mlx5e_rx_is_linear_skb(struct mlx5_core_dev *mdev,
99 			    struct mlx5e_params *params,
100 			    struct mlx5e_rq_opt_param *rqo);
101 bool mlx5e_rx_mpwqe_is_linear_skb(struct mlx5_core_dev *mdev,
102 				  struct mlx5e_params *params,
103 				  struct mlx5e_rq_opt_param *rqo);
104 u8 mlx5e_mpwqe_get_log_rq_size(struct mlx5_core_dev *mdev,
105 			       struct mlx5e_params *params,
106 			       struct mlx5e_rq_opt_param *rqo);
107 u32 mlx5e_shampo_hd_per_wqe(struct mlx5_core_dev *mdev,
108 			    struct mlx5e_params *params,
109 			    struct mlx5e_rq_param *rq_param);
110 u32 mlx5e_shampo_hd_per_wq(struct mlx5_core_dev *mdev,
111 			   struct mlx5e_params *params,
112 			   struct mlx5e_rq_param *rq_param);
113 u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout);
114 u8 mlx5e_mpwqe_get_log_stride_size(struct mlx5_core_dev *mdev,
115 				   struct mlx5e_params *params,
116 				   struct mlx5e_rq_opt_param *rqo);
117 u8 mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev *mdev,
118 				   struct mlx5e_params *params,
119 				   struct mlx5e_rq_opt_param *rqo);
120 u8 mlx5e_mpwqe_get_min_wqe_bulk(unsigned int wq_sz);
121 u16 mlx5e_get_rq_headroom(struct mlx5_core_dev *mdev,
122 			  struct mlx5e_params *params,
123 			  struct mlx5e_rq_opt_param *rqo);
124 u32 mlx5e_mpwrq_max_page_size(struct mlx5_core_dev *mdev);
125 
126 /* Build queue parameters */
127 
128 void mlx5e_build_create_cq_param(struct mlx5e_create_cq_param *ccp, struct mlx5e_channel *c);
129 int mlx5e_build_rq_param(struct mlx5_core_dev *mdev,
130 			 struct mlx5e_params *params,
131 			 struct mlx5e_rq_opt_param *rqo,
132 			 struct mlx5e_rq_param *param);
133 void mlx5e_build_drop_rq_param(struct mlx5_core_dev *mdev,
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 			      struct netdev_queue_config *qcfg,
149 			      struct mlx5e_channel_param *cparam);
150 
151 void mlx5e_build_xsk_channel_param(struct mlx5_core_dev *mdev,
152 				   struct mlx5e_params *params,
153 				   struct mlx5e_xsk_param *xsk,
154 				   struct mlx5e_channel_param *cparam);
155 
156 u16 mlx5e_calc_sq_stop_room(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
157 int mlx5e_validate_params(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
158 bool mlx5e_verify_params_rx_mpwqe_strides(struct mlx5_core_dev *mdev,
159 					  struct mlx5e_params *params,
160 					  struct mlx5e_rq_opt_param *rqo);
161 
162 static inline void mlx5e_params_print_info(struct mlx5_core_dev *mdev,
163 					   struct mlx5e_params *params)
164 {
165 	mlx5_core_info(mdev, "MLX5E: StrdRq(%d) RqSz(%ld) StrdSz(%ld) RxCqeCmprss(%d %s)\n",
166 		       params->rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ,
167 		       params->rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ ?
168 		       BIT(mlx5e_mpwqe_get_log_rq_size(mdev, params, NULL)) :
169 		       BIT(params->log_rq_mtu_frames),
170 		       BIT(mlx5e_mpwqe_get_log_stride_size(mdev, params, NULL)),
171 		       MLX5E_GET_PFLAG(params, MLX5E_PFLAG_RX_CQE_COMPRESS),
172 		       MLX5_CAP_GEN(mdev, enhanced_cqe_compression) ?
173 				       "enhanced" : "basic");
174 };
175 
176 static inline struct mlx5e_xsk_param *
177 mlx5e_rqo_xsk_param(struct mlx5e_rq_opt_param *rqo)
178 {
179 	return rqo ? rqo->xsk : NULL;
180 }
181 
182 #endif /* __MLX5_EN_PARAMS_H__ */
183