net/mlx5e: move XDP_REDIRECT sq to dynamic allocation
authorWilliam Tu <witu@nvidia.com>
Thu, 31 Oct 2024 12:58:55 +0000 (14:58 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sun, 3 Nov 2024 23:37:15 +0000 (15:37 -0800)
Dynamically allocating xdpsq, used by egress side XDP_REDIRECT.
mlx5 has multiple XDP sqs. Under struct mlx5e_channel:
1. rx_xdpsq: used for XDP_TX, an XDP prog handles the rx packet and
transmits using the same queue as rx.
2. xdpsq: used by egress side XDP_REDIRECT. This is for another interface
to redirect packet to the mlx5 interface, using ndo_xdp_xmit .
3. xsksq: used by XSK. XSK has its own dedicated channel, and it also
has resources of 1 and 2.

The patch changes only the 2. xdpsq.

Signed-off-by: William Tu <witu@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20241031125856.530927-5-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en.h
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c

index 57b7298a0e793ca14540c1c82b9b0fb7076882a6..58f3df784dedb5eed425382851e969e12b58971e 100644 (file)
@@ -755,7 +755,7 @@ struct mlx5e_channel {
        u8                         lag_port;
 
        /* XDP_REDIRECT */
-       struct mlx5e_xdpsq         xdpsq;
+       struct mlx5e_xdpsq        *xdpsq;
 
        /* AF_XDP zero-copy */
        struct mlx5e_rq            xskrq;
index 4610621a340e50801b91607d44ab6a230117846d..94b2916620873c1312d69dc4285e1b8c89f1cd65 100644 (file)
@@ -865,7 +865,7 @@ int mlx5e_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
        if (unlikely(sq_num >= priv->channels.num))
                return -ENXIO;
 
-       sq = &priv->channels.c[sq_num]->xdpsq;
+       sq = priv->channels.c[sq_num]->xdpsq;
 
        for (i = 0; i < n; i++) {
                struct mlx5e_xmit_data_frags xdptxdf = {};
index f37afa52e2b83e787eb8e210721b48f6f41d55a7..2f609b92d29b08a710c7688844735df10bd0f2dc 100644 (file)
@@ -2086,6 +2086,44 @@ void mlx5e_close_xdpsq(struct mlx5e_xdpsq *sq)
        mlx5e_free_xdpsq(sq);
 }
 
+static struct mlx5e_xdpsq *mlx5e_open_xdpredirect_sq(struct mlx5e_channel *c,
+                                                    struct mlx5e_params *params,
+                                                    struct mlx5e_channel_param *cparam,
+                                                    struct mlx5e_create_cq_param *ccp)
+{
+       struct mlx5e_xdpsq *xdpsq;
+       int err;
+
+       xdpsq = kvzalloc_node(sizeof(*xdpsq), GFP_KERNEL, c->cpu);
+       if (!xdpsq)
+               return ERR_PTR(-ENOMEM);
+
+       err = mlx5e_open_cq(c->mdev, params->tx_cq_moderation,
+                           &cparam->xdp_sq.cqp, ccp, &xdpsq->cq);
+       if (err)
+               goto err_free_xdpsq;
+
+       err = mlx5e_open_xdpsq(c, params, &cparam->xdp_sq, NULL, xdpsq, true);
+       if (err)
+               goto err_close_xdpsq_cq;
+
+       return xdpsq;
+
+err_close_xdpsq_cq:
+       mlx5e_close_cq(&xdpsq->cq);
+err_free_xdpsq:
+       kvfree(xdpsq);
+
+       return ERR_PTR(err);
+}
+
+static void mlx5e_close_xdpredirect_sq(struct mlx5e_xdpsq *xdpsq)
+{
+       mlx5e_close_xdpsq(xdpsq);
+       mlx5e_close_cq(&xdpsq->cq);
+       kvfree(xdpsq);
+}
+
 static int mlx5e_alloc_cq_common(struct mlx5_core_dev *mdev,
                                 struct net_device *netdev,
                                 struct workqueue_struct *workqueue,
@@ -2496,15 +2534,16 @@ static int mlx5e_open_queues(struct mlx5e_channel *c,
        if (err)
                goto err_close_icosq_cq;
 
-       err = mlx5e_open_cq(c->mdev, params->tx_cq_moderation, &cparam->xdp_sq.cqp, &ccp,
-                           &c->xdpsq.cq);
-       if (err)
+       c->xdpsq = mlx5e_open_xdpredirect_sq(c, params, cparam, &ccp);
+       if (IS_ERR(c->xdpsq)) {
+               err = PTR_ERR(c->xdpsq);
                goto err_close_tx_cqs;
+       }
 
        err = mlx5e_open_cq(c->mdev, params->rx_cq_moderation, &cparam->rq.cqp, &ccp,
                            &c->rq.cq);
        if (err)
-               goto err_close_xdp_tx_cqs;
+               goto err_close_xdpredirect_sq;
 
        err = c->xdp ? mlx5e_open_cq(c->mdev, params->tx_cq_moderation, &cparam->xdp_sq.cqp,
                                     &ccp, &c->rq_xdpsq.cq) : 0;
@@ -2516,7 +2555,7 @@ static int mlx5e_open_queues(struct mlx5e_channel *c,
        err = mlx5e_open_icosq(c, params, &cparam->async_icosq, &c->async_icosq,
                               mlx5e_async_icosq_err_cqe_work);
        if (err)
-               goto err_close_xdpsq_cq;
+               goto err_close_rq_xdpsq_cq;
 
        mutex_init(&c->icosq_recovery_lock);
 
@@ -2540,16 +2579,8 @@ static int mlx5e_open_queues(struct mlx5e_channel *c,
                        goto err_close_rq;
        }
 
-       err = mlx5e_open_xdpsq(c, params, &cparam->xdp_sq, NULL, &c->xdpsq, true);
-       if (err)
-               goto err_close_xdp_sq;
-
        return 0;
 
-err_close_xdp_sq:
-       if (c->xdp)
-               mlx5e_close_xdpsq(&c->rq_xdpsq);
-
 err_close_rq:
        mlx5e_close_rq(&c->rq);
 
@@ -2562,15 +2593,15 @@ err_close_icosq:
 err_close_async_icosq:
        mlx5e_close_icosq(&c->async_icosq);
 
-err_close_xdpsq_cq:
+err_close_rq_xdpsq_cq:
        if (c->xdp)
                mlx5e_close_cq(&c->rq_xdpsq.cq);
 
 err_close_rx_cq:
        mlx5e_close_cq(&c->rq.cq);
 
-err_close_xdp_tx_cqs:
-       mlx5e_close_cq(&c->xdpsq.cq);
+err_close_xdpredirect_sq:
+       mlx5e_close_xdpredirect_sq(c->xdpsq);
 
 err_close_tx_cqs:
        mlx5e_close_tx_cqs(c);
@@ -2586,7 +2617,6 @@ err_close_async_icosq_cq:
 
 static void mlx5e_close_queues(struct mlx5e_channel *c)
 {
-       mlx5e_close_xdpsq(&c->xdpsq);
        if (c->xdp)
                mlx5e_close_xdpsq(&c->rq_xdpsq);
        /* The same ICOSQ is used for UMRs for both RQ and XSKRQ. */
@@ -2599,7 +2629,7 @@ static void mlx5e_close_queues(struct mlx5e_channel *c)
        if (c->xdp)
                mlx5e_close_cq(&c->rq_xdpsq.cq);
        mlx5e_close_cq(&c->rq.cq);
-       mlx5e_close_cq(&c->xdpsq.cq);
+       mlx5e_close_xdpredirect_sq(c->xdpsq);
        mlx5e_close_tx_cqs(c);
        mlx5e_close_cq(&c->icosq.cq);
        mlx5e_close_cq(&c->async_icosq.cq);
index 92094bf60d5986a4e6139c123f2a1f26fcb6b93f..554f9cb5b53fd98625b6709e2a849b58ec0ed284 100644 (file)
@@ -600,7 +600,8 @@ mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv)
                        if (c->xdp)
                                sqs[num_sqs++] = c->rq_xdpsq.sqn;
 
-                       sqs[num_sqs++] = c->xdpsq.sqn;
+                       if (c->xdpsq)
+                               sqs[num_sqs++] = c->xdpsq->sqn;
                }
        }
        if (ptp_sq) {
index 417098f0b2bbd1563871755e12ae6714d1f18fc4..76108299ea57deff374bc0cd1ea782c1aa668cea 100644 (file)
@@ -165,7 +165,8 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
        if (unlikely(!budget))
                goto out;
 
-       busy |= mlx5e_poll_xdpsq_cq(&c->xdpsq.cq);
+       if (c->xdpsq)
+               busy |= mlx5e_poll_xdpsq_cq(&c->xdpsq->cq);
 
        if (c->xdp)
                busy |= mlx5e_poll_xdpsq_cq(&c->rq_xdpsq.cq);
@@ -236,7 +237,8 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
        mlx5e_cq_arm(&rq->cq);
        mlx5e_cq_arm(&c->icosq.cq);
        mlx5e_cq_arm(&c->async_icosq.cq);
-       mlx5e_cq_arm(&c->xdpsq.cq);
+       if (c->xdpsq)
+               mlx5e_cq_arm(&c->xdpsq->cq);
 
        if (xsk_open) {
                mlx5e_handle_rx_dim(xskrq);