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