1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2019 Mellanox Technologies. */
7 bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
8 struct mlx5e_xsk_param *xsk,
9 struct mlx5_core_dev *mdev)
11 /* AF_XDP doesn't support frames larger than PAGE_SIZE, and the current
12 * mlx5e XDP implementation doesn't support multiple packets per page.
14 if (xsk->chunk_size != PAGE_SIZE)
17 /* Current MTU and XSK headroom don't allow packets to fit the frames. */
18 if (mlx5e_rx_get_linear_frag_sz(params, xsk) > xsk->chunk_size)
21 /* frag_sz is different for regular and XSK RQs, so ensure that linear
22 * SKB mode is possible.
24 switch (params->rq_wq_type) {
25 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
26 return mlx5e_rx_mpwqe_is_linear_skb(mdev, params, xsk);
27 default: /* MLX5_WQ_TYPE_CYCLIC */
28 return mlx5e_rx_is_linear_skb(params, xsk);
32 static void mlx5e_build_xskicosq_param(struct mlx5e_priv *priv,
34 struct mlx5e_sq_param *param)
36 void *sqc = param->sqc;
37 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
39 mlx5e_build_sq_param_common(priv, param);
41 MLX5_SET(wq, wq, log_wq_sz, log_wq_size);
44 static void mlx5e_build_xsk_cparam(struct mlx5e_priv *priv,
45 struct mlx5e_params *params,
46 struct mlx5e_xsk_param *xsk,
47 struct mlx5e_channel_param *cparam)
49 const u8 xskicosq_size = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
51 mlx5e_build_rq_param(priv, params, xsk, &cparam->rq);
52 mlx5e_build_xdpsq_param(priv, params, &cparam->xdp_sq);
53 mlx5e_build_xskicosq_param(priv, xskicosq_size, &cparam->icosq);
54 mlx5e_build_rx_cq_param(priv, params, xsk, &cparam->rx_cq);
55 mlx5e_build_tx_cq_param(priv, params, &cparam->tx_cq);
56 mlx5e_build_ico_cq_param(priv, xskicosq_size, &cparam->icosq_cq);
59 int mlx5e_open_xsk(struct mlx5e_priv *priv, struct mlx5e_params *params,
60 struct mlx5e_xsk_param *xsk, struct xdp_umem *umem,
61 struct mlx5e_channel *c)
63 struct mlx5e_channel_param *cparam;
64 struct dim_cq_moder icocq_moder = {};
67 if (!mlx5e_validate_xsk_param(params, xsk, priv->mdev))
70 cparam = kvzalloc(sizeof(*cparam), GFP_KERNEL);
74 mlx5e_build_xsk_cparam(priv, params, xsk, cparam);
76 err = mlx5e_open_cq(c, params->rx_cq_moderation, &cparam->rx_cq, &c->xskrq.cq);
80 err = mlx5e_open_rq(c, params, &cparam->rq, xsk, umem, &c->xskrq);
84 err = mlx5e_open_cq(c, params->tx_cq_moderation, &cparam->tx_cq, &c->xsksq.cq);
88 /* Create a separate SQ, so that when the UMEM is disabled, we could
89 * close this SQ safely and stop receiving CQEs. In other case, e.g., if
90 * the XDPSQ was used instead, we might run into trouble when the UMEM
91 * is disabled and then reenabled, but the SQ continues receiving CQEs
94 err = mlx5e_open_xdpsq(c, params, &cparam->xdp_sq, umem, &c->xsksq, true);
98 err = mlx5e_open_cq(c, icocq_moder, &cparam->icosq_cq, &c->xskicosq.cq);
102 /* Create a dedicated SQ for posting NOPs whenever we need an IRQ to be
103 * triggered and NAPI to be called on the correct CPU.
105 err = mlx5e_open_icosq(c, params, &cparam->icosq, &c->xskicosq);
107 goto err_close_icocq;
111 spin_lock_init(&c->xskicosq_lock);
113 set_bit(MLX5E_CHANNEL_STATE_XSK, c->state);
118 mlx5e_close_cq(&c->xskicosq.cq);
121 mlx5e_close_xdpsq(&c->xsksq);
124 mlx5e_close_cq(&c->xsksq.cq);
127 mlx5e_close_rq(&c->xskrq);
130 mlx5e_close_cq(&c->xskrq.cq);
138 void mlx5e_close_xsk(struct mlx5e_channel *c)
140 clear_bit(MLX5E_CHANNEL_STATE_XSK, c->state);
141 napi_synchronize(&c->napi);
143 mlx5e_close_rq(&c->xskrq);
144 mlx5e_close_cq(&c->xskrq.cq);
145 mlx5e_close_icosq(&c->xskicosq);
146 mlx5e_close_cq(&c->xskicosq.cq);
147 mlx5e_close_xdpsq(&c->xsksq);
148 mlx5e_close_cq(&c->xsksq.cq);
151 void mlx5e_activate_xsk(struct mlx5e_channel *c)
153 set_bit(MLX5E_RQ_STATE_ENABLED, &c->xskrq.state);
154 /* TX queue is created active. */
156 spin_lock(&c->xskicosq_lock);
157 mlx5e_trigger_irq(&c->xskicosq);
158 spin_unlock(&c->xskicosq_lock);
161 void mlx5e_deactivate_xsk(struct mlx5e_channel *c)
163 mlx5e_deactivate_rq(&c->xskrq);
164 /* TX queue is disabled on close. */
167 static int mlx5e_redirect_xsk_rqt(struct mlx5e_priv *priv, u16 ix, u32 rqn)
169 struct mlx5e_redirect_rqt_param direct_rrp = {
176 u32 rqtn = priv->xsk_tir[ix].rqt.rqtn;
178 return mlx5e_redirect_rqt(priv, rqtn, 1, direct_rrp);
181 int mlx5e_xsk_redirect_rqt_to_channel(struct mlx5e_priv *priv, struct mlx5e_channel *c)
183 return mlx5e_redirect_xsk_rqt(priv, c->ix, c->xskrq.rqn);
186 int mlx5e_xsk_redirect_rqt_to_drop(struct mlx5e_priv *priv, u16 ix)
188 return mlx5e_redirect_xsk_rqt(priv, ix, priv->drop_rq.rqn);
191 int mlx5e_xsk_redirect_rqts_to_channels(struct mlx5e_priv *priv, struct mlx5e_channels *chs)
195 if (!priv->xsk.refcnt)
198 for (i = 0; i < chs->num; i++) {
199 struct mlx5e_channel *c = chs->c[i];
201 if (!test_bit(MLX5E_CHANNEL_STATE_XSK, c->state))
204 err = mlx5e_xsk_redirect_rqt_to_channel(priv, c);
212 for (i--; i >= 0; i--) {
213 if (!test_bit(MLX5E_CHANNEL_STATE_XSK, chs->c[i]->state))
216 mlx5e_xsk_redirect_rqt_to_drop(priv, i);
222 void mlx5e_xsk_redirect_rqts_to_drop(struct mlx5e_priv *priv, struct mlx5e_channels *chs)
226 if (!priv->xsk.refcnt)
229 for (i = 0; i < chs->num; i++) {
230 if (!test_bit(MLX5E_CHANNEL_STATE_XSK, chs->c[i]->state))
233 mlx5e_xsk_redirect_rqt_to_drop(priv, i);