net/mlx5e: Make TLS offload independent of wqe and pi
authorMaxim Mikityanskiy <maximmi@mellanox.com>
Fri, 6 Dec 2019 14:42:09 +0000 (16:42 +0200)
committerSaeed Mahameed <saeedm@mellanox.com>
Sat, 9 May 2020 08:05:40 +0000 (01:05 -0700)
TLS offload may write a 32-bit field (tisn) to the cseg of the WQE. To
do that, it receives pi and wqe pointers. As TLS offload may also send
additional WQEs, it has to update pi and wqe, and in many cases it even
doesn't use pi calculated before and wqe zeroed before and does it
itself. Also, mlx5e_sq_xmit has to copy the whole cseg if it goes to the
mlx5e_fill_sq_frag_edge flow. This all is not efficient.

It's more efficient to do the following:

1. Just return tisn from TLS offload and make the caller fill it in a
more appropriate place.

2. Calculate pi and clear wqe after calling TLS offload.

3. If TLS offload has to send WQEs, calculate pi and clear wqe just
before that. It's already done in all places anyway, so this commit
allows to remove some redundant memsets and calls.

Copying of cseg will be eliminated in one of the following commits, and
all other stuff is done here.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c
drivers/net/ethernet/mellanox/mlx5/core/en_accel/tls_rxtx.c
drivers/net/ethernet/mellanox/mlx5/core/en_accel/tls_rxtx.h

index c658c8556863950be027fb0ca02a0bb594771f06..66bfab021d6b86ac224b5e00c92de043e37ca9bc 100644 (file)
@@ -109,10 +109,18 @@ static inline bool mlx5e_accel_handle_tx(struct sk_buff *skb,
                                         u16 *pi)
 {
 #ifdef CONFIG_MLX5_EN_TLS
+       u32 tls_tisn = 0;
+
        if (test_bit(MLX5E_SQ_STATE_TLS, &sq->state)) {
-               if (unlikely(!mlx5e_tls_handle_tx_skb(dev, sq, skb, wqe, pi)))
+               /* May send SKBs and WQEs. */
+               if (unlikely(!mlx5e_tls_handle_tx_skb(dev, sq, skb, &tls_tisn)))
                        return false;
        }
+
+       *pi = mlx5_wq_cyc_ctr2ix(&sq->wq, sq->pc);
+       *wqe = MLX5E_TX_FETCH_WQE(sq, *pi);
+
+       (*wqe)->ctrl.tisn = cpu_to_be32(tls_tisn << 8);
 #endif
 
 #ifdef CONFIG_MLX5_EN_IPSEC
index 81f8b7467569966c2cb773f5f3df676539fe6d02..7d9d9420f19d434b12b8977fd95dff20046afa2b 100644 (file)
@@ -96,8 +96,7 @@ void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv);
 void mlx5e_ktls_tx_offload_set_pending(struct mlx5e_ktls_offload_context_tx *priv_tx);
 
 bool mlx5e_ktls_handle_tx_skb(struct tls_context *tls_ctx, struct mlx5e_txqsq *sq,
-                             struct sk_buff *skb, struct mlx5e_tx_wqe **wqe,
-                             u16 *pi, int datalen);
+                             struct sk_buff *skb, u32 *tisn, int datalen);
 void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
                                           struct mlx5e_tx_wqe_info *wi,
                                           u32 *dma_fifo_cc);
index c61604f3722c50182d0739cbb4f173525b6e08a1..b49d7c1e49dc473e7f643c9def5c918797cde684 100644 (file)
@@ -414,20 +414,16 @@ err_out:
 }
 
 bool mlx5e_ktls_handle_tx_skb(struct tls_context *tls_ctx, struct mlx5e_txqsq *sq,
-                             struct sk_buff *skb, struct mlx5e_tx_wqe **wqe,
-                             u16 *pi, int datalen)
+                             struct sk_buff *skb, u32 *tisn, int datalen)
 {
        struct mlx5e_ktls_offload_context_tx *priv_tx;
        struct mlx5e_sq_stats *stats = sq->stats;
-       struct mlx5_wqe_ctrl_seg *cseg;
        u32 seq;
 
        priv_tx = mlx5e_get_ktls_tx_priv_ctx(tls_ctx);
 
        if (unlikely(mlx5e_ktls_tx_offload_test_and_clear_pending(priv_tx))) {
                mlx5e_ktls_tx_post_param_wqes(sq, priv_tx, false, false);
-               *pi = mlx5_wq_cyc_ctr2ix(&sq->wq, sq->pc);
-               *wqe = MLX5E_TX_FETCH_WQE(sq, *pi);
                stats->tls_ctx++;
        }
 
@@ -438,23 +434,20 @@ bool mlx5e_ktls_handle_tx_skb(struct tls_context *tls_ctx, struct mlx5e_txqsq *s
 
                switch (ret) {
                case MLX5E_KTLS_SYNC_DONE:
-                       *pi = mlx5_wq_cyc_ctr2ix(&sq->wq, sq->pc);
-                       *wqe = MLX5E_TX_FETCH_WQE(sq, *pi);
                        break;
                case MLX5E_KTLS_SYNC_SKIP_NO_DATA:
                        if (likely(!skb->decrypted))
                                goto out;
                        WARN_ON_ONCE(1);
                        /* fall-through */
-               default: /* MLX5E_KTLS_SYNC_FAIL */
+               case MLX5E_KTLS_SYNC_FAIL:
                        goto err_out;
                }
        }
 
        priv_tx->expected_seq = seq + datalen;
 
-       cseg = &(*wqe)->ctrl;
-       cseg->tisn = cpu_to_be32(priv_tx->tisn << 8);
+       *tisn = priv_tx->tisn;
 
        stats->tls_encrypted_packets += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1;
        stats->tls_encrypted_bytes   += datalen;
index 26c59cfbec9b63bda81959f5b47c56f43bf54e06..8e6b0b0ce2e43574948aad0d945a52cc97bd8fb1 100644 (file)
@@ -186,14 +186,15 @@ static void mlx5e_tls_complete_sync_skb(struct sk_buff *skb,
 
 static bool mlx5e_tls_handle_ooo(struct mlx5e_tls_offload_context_tx *context,
                                 struct mlx5e_txqsq *sq, struct sk_buff *skb,
-                                struct mlx5e_tx_wqe **wqe, u16 *pi,
                                 struct mlx5e_tls *tls)
 {
        u32 tcp_seq = ntohl(tcp_hdr(skb)->seq);
+       struct mlx5e_tx_wqe *wqe;
        struct sync_info info;
        struct sk_buff *nskb;
        int linear_len = 0;
        int headln;
+       u16 pi;
        int i;
 
        sq->stats->tls_ooo++;
@@ -245,9 +246,10 @@ static bool mlx5e_tls_handle_ooo(struct mlx5e_tls_offload_context_tx *context,
        sq->stats->tls_resync_bytes += nskb->len;
        mlx5e_tls_complete_sync_skb(skb, nskb, tcp_seq, headln,
                                    cpu_to_be64(info.rcd_sn));
-       mlx5e_sq_xmit(sq, nskb, *wqe, *pi, true);
-       *pi = mlx5_wq_cyc_ctr2ix(&sq->wq, sq->pc);
-       *wqe = MLX5E_TX_FETCH_WQE(sq, *pi);
+       pi = mlx5_wq_cyc_ctr2ix(&sq->wq, sq->pc);
+       wqe = MLX5E_TX_FETCH_WQE(sq, pi);
+       mlx5e_sq_xmit(sq, nskb, wqe, pi, true);
+
        return true;
 
 err_out:
@@ -256,8 +258,7 @@ err_out:
 }
 
 bool mlx5e_tls_handle_tx_skb(struct net_device *netdev, struct mlx5e_txqsq *sq,
-                            struct sk_buff *skb, struct mlx5e_tx_wqe **wqe,
-                            u16 *pi)
+                            struct sk_buff *skb, u32 *tisn)
 {
        struct mlx5e_priv *priv = netdev_priv(netdev);
        struct mlx5e_tls_offload_context_tx *context;
@@ -278,14 +279,14 @@ bool mlx5e_tls_handle_tx_skb(struct net_device *netdev, struct mlx5e_txqsq *sq,
                goto err_out;
 
        if (MLX5_CAP_GEN(sq->channel->mdev, tls_tx))
-               return mlx5e_ktls_handle_tx_skb(tls_ctx, sq, skb, wqe, pi, datalen);
+               return mlx5e_ktls_handle_tx_skb(tls_ctx, sq, skb, tisn, datalen);
 
        skb_seq = ntohl(tcp_hdr(skb)->seq);
        context = mlx5e_get_tls_tx_context(tls_ctx);
        expected_seq = context->expected_seq;
 
        if (unlikely(expected_seq != skb_seq))
-               return mlx5e_tls_handle_ooo(context, sq, skb, wqe, pi, priv->tls);
+               return mlx5e_tls_handle_ooo(context, sq, skb, priv->tls);
 
        if (unlikely(mlx5e_tls_add_metadata(skb, context->swid))) {
                atomic64_inc(&priv->tls->sw_stats.tx_tls_drop_metadata);
index 890d452bf1ae4adb500c742101bdfeaf1b1749ac..3630ed8b1206733482c33c74becd79c7bc1913e9 100644 (file)
@@ -41,8 +41,7 @@
 #include "en/txrx.h"
 
 bool mlx5e_tls_handle_tx_skb(struct net_device *netdev, struct mlx5e_txqsq *sq,
-                            struct sk_buff *skb, struct mlx5e_tx_wqe **wqe,
-                            u16 *pi);
+                            struct sk_buff *skb, u32 *tisn);
 
 void mlx5e_tls_handle_rx_skb(struct net_device *netdev, struct sk_buff *skb,
                             u32 *cqe_bcnt);