git: 2657d38625cf - stable/14 - mlx5en: move runtime capabilities checks into helper functions

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 03 Dec 2024 00:51:31 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=2657d38625cff8c16dfbb7e8ca80d895f988d840

commit 2657d38625cff8c16dfbb7e8ca80d895f988d840
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-11-21 05:51:18 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-12-03 00:39:23 +0000

    mlx5en: move runtime capabilities checks into helper functions
    
    (cherry picked from commit cca0dc49e0ca66f7696920266ea6340b05e3e455)
---
 sys/dev/mlx5/mlx5_en/mlx5_en_main.c | 56 +++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 14 deletions(-)

diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
index 4399af43b93b..58d305dd43f3 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
@@ -3399,6 +3399,41 @@ mlx5e_set_rx_mode(if_t ifp)
 	queue_work(priv->wq, &priv->set_rx_mode_work);
 }
 
+static bool
+mlx5e_is_ratelimit_capable(struct mlx5_core_dev *mdev)
+{
+#ifdef RATELIMIT
+	if (MLX5_CAP_GEN(mdev, qos) &&
+	    MLX5_CAP_QOS(mdev, packet_pacing))
+		return (true);
+#endif
+	return (false);
+}
+
+static bool
+mlx5e_is_tlstx_capable(struct mlx5_core_dev *mdev)
+{
+#ifdef KERN_TLS
+	if (MLX5_CAP_GEN(mdev, tls_tx) != 0 &&
+	    MLX5_CAP_GEN(mdev, log_max_dek) != 0)
+		return (true);
+#endif
+	return (false);
+}
+
+static bool
+mlx5e_is_tlsrx_capable(struct mlx5_core_dev *mdev)
+{
+#ifdef KERN_TLS
+	if (MLX5_CAP_GEN(mdev, tls_rx) != 0 &&
+	    MLX5_CAP_GEN(mdev, log_max_dek) != 0 &&
+	    MLX5_CAP_FLOWTABLE_NIC_RX(mdev,
+	    ft_field_support.outer_ip_version) != 0)
+		return (true);
+#endif
+	return (false);
+}
+
 static int
 mlx5e_ioctl(if_t ifp, u_long command, caddr_t data)
 {
@@ -4518,23 +4553,16 @@ mlx5e_create_ifp(struct mlx5_core_dev *mdev)
 	if_setcapabilitiesbit(ifp, IFCAP_TSO | IFCAP_VLAN_HWTSO, 0);
 	if_setcapabilitiesbit(ifp, IFCAP_HWSTATS | IFCAP_HWRXTSTMP, 0);
 	if_setcapabilitiesbit(ifp, IFCAP_MEXTPG, 0);
-#ifdef KERN_TLS
-	if (MLX5_CAP_GEN(mdev, tls_tx) != 0 &&
-	    MLX5_CAP_GEN(mdev, log_max_dek) != 0)
+	if (mlx5e_is_tlstx_capable(mdev))
 		if_setcapabilitiesbit(ifp, IFCAP_TXTLS4 | IFCAP_TXTLS6, 0);
-	if (MLX5_CAP_GEN(mdev, tls_rx) != 0 &&
-	    MLX5_CAP_GEN(mdev, log_max_dek) != 0 &&
-	    MLX5_CAP_FLOWTABLE_NIC_RX(mdev,
-	    ft_field_support.outer_ip_version) != 0)
+	if (mlx5e_is_tlsrx_capable(mdev))
 		if_setcapabilities2bit(ifp, IFCAP2_BIT(IFCAP2_RXTLS4) |
 		    IFCAP2_BIT(IFCAP2_RXTLS6), 0);
-#endif
-#ifdef RATELIMIT
-	if (MLX5_CAP_GEN(mdev, qos) &&
-	    MLX5_CAP_QOS(mdev, packet_pacing))
-		if_setcapabilitiesbit(ifp, IFCAP_TXRTLMT | IFCAP_TXTLS_RTLMT,
-		    0);
-#endif
+	if (mlx5e_is_ratelimit_capable(mdev)) {
+		if_setcapabilitiesbit(ifp, IFCAP_TXRTLMT, 0);
+		if (mlx5e_is_tlstx_capable(mdev))
+			if_setcapabilitiesbit(ifp, IFCAP_TXTLS_RTLMT, 0);
+	}
 	if_setcapabilitiesbit(ifp, IFCAP_VXLAN_HWCSUM | IFCAP_VXLAN_HWTSO, 0);
 
 	if_setsndtagallocfn(ifp, mlx5e_snd_tag_alloc);