net/mlx5e: Move parameter calculation functions to en/params.c
authorMaxim Mikityanskiy <maximmi@mellanox.com>
Wed, 27 Mar 2019 11:09:27 +0000 (13:09 +0200)
committerSaeed Mahameed <saeedm@mellanox.com>
Tue, 23 Apr 2019 19:09:21 +0000 (12:09 -0700)
This commit moves the parameter calculation functions to a separate file
for better modularity and code sharing with future features.

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/Makefile
drivers/net/ethernet/mellanox/mlx5/core/en/params.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/en/params.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/en_main.c

index 1a16f6d73cbc59a16294b124ceedb68f09796da9..3dbbe3b643b37f6a327ce0864b2fe3dc18156b1d 100644 (file)
@@ -22,7 +22,8 @@ mlx5_core-y :=        main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \
 #
 mlx5_core-$(CONFIG_MLX5_CORE_EN) += en_main.o en_common.o en_fs.o en_ethtool.o \
                en_tx.o en_rx.o en_dim.o en_txrx.o en/xdp.o en_stats.o \
-               en_selftest.o en/port.o en/monitor_stats.o en/reporter_tx.o
+               en_selftest.o en/port.o en/monitor_stats.o en/reporter_tx.o \
+               en/params.o
 
 #
 # Netdev extra
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c
new file mode 100644 (file)
index 0000000..658337c
--- /dev/null
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/* Copyright (c) 2019 Mellanox Technologies. */
+
+#include "en/params.h"
+
+u32 mlx5e_rx_get_linear_frag_sz(struct mlx5e_params *params)
+{
+       u16 hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
+       u16 linear_rq_headroom = params->xdp_prog ?
+               XDP_PACKET_HEADROOM : MLX5_RX_HEADROOM;
+       u32 frag_sz;
+
+       linear_rq_headroom += NET_IP_ALIGN;
+
+       frag_sz = MLX5_SKB_FRAG_SZ(linear_rq_headroom + hw_mtu);
+
+       if (params->xdp_prog && frag_sz < PAGE_SIZE)
+               frag_sz = PAGE_SIZE;
+
+       return frag_sz;
+}
+
+u8 mlx5e_mpwqe_log_pkts_per_wqe(struct mlx5e_params *params)
+{
+       u32 linear_frag_sz = mlx5e_rx_get_linear_frag_sz(params);
+
+       return MLX5_MPWRQ_LOG_WQE_SZ - order_base_2(linear_frag_sz);
+}
+
+bool mlx5e_rx_is_linear_skb(struct mlx5_core_dev *mdev,
+                           struct mlx5e_params *params)
+{
+       u32 frag_sz = mlx5e_rx_get_linear_frag_sz(params);
+
+       return !params->lro_en && frag_sz <= PAGE_SIZE;
+}
+
+#define MLX5_MAX_MPWQE_LOG_WQE_STRIDE_SZ ((BIT(__mlx5_bit_sz(wq, log_wqe_stride_size)) - 1) + \
+                                         MLX5_MPWQE_LOG_STRIDE_SZ_BASE)
+bool mlx5e_rx_mpwqe_is_linear_skb(struct mlx5_core_dev *mdev,
+                                 struct mlx5e_params *params)
+{
+       u32 frag_sz = mlx5e_rx_get_linear_frag_sz(params);
+       s8 signed_log_num_strides_param;
+       u8 log_num_strides;
+
+       if (!mlx5e_rx_is_linear_skb(mdev, params))
+               return false;
+
+       if (order_base_2(frag_sz) > MLX5_MAX_MPWQE_LOG_WQE_STRIDE_SZ)
+               return false;
+
+       if (MLX5_CAP_GEN(mdev, ext_stride_num_range))
+               return true;
+
+       log_num_strides = MLX5_MPWRQ_LOG_WQE_SZ - order_base_2(frag_sz);
+       signed_log_num_strides_param =
+               (s8)log_num_strides - MLX5_MPWQE_LOG_NUM_STRIDES_BASE;
+
+       return signed_log_num_strides_param >= 0;
+}
+
+u8 mlx5e_mpwqe_get_log_rq_size(struct mlx5e_params *params)
+{
+       if (params->log_rq_mtu_frames <
+           mlx5e_mpwqe_log_pkts_per_wqe(params) + MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW)
+               return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW;
+
+       return params->log_rq_mtu_frames - mlx5e_mpwqe_log_pkts_per_wqe(params);
+}
+
+u8 mlx5e_mpwqe_get_log_stride_size(struct mlx5_core_dev *mdev,
+                                  struct mlx5e_params *params)
+{
+       if (mlx5e_rx_mpwqe_is_linear_skb(mdev, params))
+               return order_base_2(mlx5e_rx_get_linear_frag_sz(params));
+
+       return MLX5_MPWRQ_DEF_LOG_STRIDE_SZ(mdev);
+}
+
+u8 mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev *mdev,
+                                  struct mlx5e_params *params)
+{
+       return MLX5_MPWRQ_LOG_WQE_SZ -
+               mlx5e_mpwqe_get_log_stride_size(mdev, params);
+}
+
+u16 mlx5e_get_rq_headroom(struct mlx5_core_dev *mdev,
+                         struct mlx5e_params *params)
+{
+       u16 linear_rq_headroom = params->xdp_prog ?
+               XDP_PACKET_HEADROOM : MLX5_RX_HEADROOM;
+       bool is_linear_skb;
+
+       linear_rq_headroom += NET_IP_ALIGN;
+
+       is_linear_skb = (params->rq_wq_type == MLX5_WQ_TYPE_CYCLIC) ?
+               mlx5e_rx_is_linear_skb(mdev, params) :
+               mlx5e_rx_mpwqe_is_linear_skb(mdev, params);
+
+       return is_linear_skb ? linear_rq_headroom : 0;
+}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/params.h b/drivers/net/ethernet/mellanox/mlx5/core/en/params.h
new file mode 100644 (file)
index 0000000..0ef1436
--- /dev/null
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+/* Copyright (c) 2019 Mellanox Technologies. */
+
+#ifndef __MLX5_EN_PARAMS_H__
+#define __MLX5_EN_PARAMS_H__
+
+#include "en.h"
+
+u32 mlx5e_rx_get_linear_frag_sz(struct mlx5e_params *params);
+u8 mlx5e_mpwqe_log_pkts_per_wqe(struct mlx5e_params *params);
+bool mlx5e_rx_is_linear_skb(struct mlx5_core_dev *mdev,
+                           struct mlx5e_params *params);
+bool mlx5e_rx_mpwqe_is_linear_skb(struct mlx5_core_dev *mdev,
+                                 struct mlx5e_params *params);
+u8 mlx5e_mpwqe_get_log_rq_size(struct mlx5e_params *params);
+u8 mlx5e_mpwqe_get_log_stride_size(struct mlx5_core_dev *mdev,
+                                  struct mlx5e_params *params);
+u8 mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev *mdev,
+                                  struct mlx5e_params *params);
+u16 mlx5e_get_rq_headroom(struct mlx5_core_dev *mdev,
+                         struct mlx5e_params *params);
+
+#endif /* __MLX5_EN_PARAMS_H__ */
index a3397d5bfa76121cc4c8d9f8695899ed696c15a6..8cab86a558ab3892e5f19d9cd54eca23dccc1813 100644 (file)
@@ -55,6 +55,7 @@
 #include "lib/eq.h"
 #include "en/monitor_stats.h"
 #include "en/reporter.h"
+#include "en/params.h"
 
 struct mlx5e_rq_param {
        u32                     rqc[MLX5_ST_SZ_DW(rqc)];
@@ -103,104 +104,6 @@ bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev)
        return true;
 }
 
-static u32 mlx5e_rx_get_linear_frag_sz(struct mlx5e_params *params)
-{
-       u16 hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
-       u16 linear_rq_headroom = params->xdp_prog ?
-               XDP_PACKET_HEADROOM : MLX5_RX_HEADROOM;
-       u32 frag_sz;
-
-       linear_rq_headroom += NET_IP_ALIGN;
-
-       frag_sz = MLX5_SKB_FRAG_SZ(linear_rq_headroom + hw_mtu);
-
-       if (params->xdp_prog && frag_sz < PAGE_SIZE)
-               frag_sz = PAGE_SIZE;
-
-       return frag_sz;
-}
-
-static u8 mlx5e_mpwqe_log_pkts_per_wqe(struct mlx5e_params *params)
-{
-       u32 linear_frag_sz = mlx5e_rx_get_linear_frag_sz(params);
-
-       return MLX5_MPWRQ_LOG_WQE_SZ - order_base_2(linear_frag_sz);
-}
-
-static bool mlx5e_rx_is_linear_skb(struct mlx5_core_dev *mdev,
-                                  struct mlx5e_params *params)
-{
-       u32 frag_sz = mlx5e_rx_get_linear_frag_sz(params);
-
-       return !params->lro_en && frag_sz <= PAGE_SIZE;
-}
-
-#define MLX5_MAX_MPWQE_LOG_WQE_STRIDE_SZ ((BIT(__mlx5_bit_sz(wq, log_wqe_stride_size)) - 1) + \
-                                         MLX5_MPWQE_LOG_STRIDE_SZ_BASE)
-static bool mlx5e_rx_mpwqe_is_linear_skb(struct mlx5_core_dev *mdev,
-                                        struct mlx5e_params *params)
-{
-       u32 frag_sz = mlx5e_rx_get_linear_frag_sz(params);
-       s8 signed_log_num_strides_param;
-       u8 log_num_strides;
-
-       if (!mlx5e_rx_is_linear_skb(mdev, params))
-               return false;
-
-       if (order_base_2(frag_sz) > MLX5_MAX_MPWQE_LOG_WQE_STRIDE_SZ)
-               return false;
-
-       if (MLX5_CAP_GEN(mdev, ext_stride_num_range))
-               return true;
-
-       log_num_strides = MLX5_MPWRQ_LOG_WQE_SZ - order_base_2(frag_sz);
-       signed_log_num_strides_param =
-               (s8)log_num_strides - MLX5_MPWQE_LOG_NUM_STRIDES_BASE;
-
-       return signed_log_num_strides_param >= 0;
-}
-
-static u8 mlx5e_mpwqe_get_log_rq_size(struct mlx5e_params *params)
-{
-       if (params->log_rq_mtu_frames <
-           mlx5e_mpwqe_log_pkts_per_wqe(params) + MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW)
-               return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW;
-
-       return params->log_rq_mtu_frames - mlx5e_mpwqe_log_pkts_per_wqe(params);
-}
-
-static u8 mlx5e_mpwqe_get_log_stride_size(struct mlx5_core_dev *mdev,
-                                         struct mlx5e_params *params)
-{
-       if (mlx5e_rx_mpwqe_is_linear_skb(mdev, params))
-               return order_base_2(mlx5e_rx_get_linear_frag_sz(params));
-
-       return MLX5_MPWRQ_DEF_LOG_STRIDE_SZ(mdev);
-}
-
-static u8 mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev *mdev,
-                                         struct mlx5e_params *params)
-{
-       return MLX5_MPWRQ_LOG_WQE_SZ -
-               mlx5e_mpwqe_get_log_stride_size(mdev, params);
-}
-
-static u16 mlx5e_get_rq_headroom(struct mlx5_core_dev *mdev,
-                                struct mlx5e_params *params)
-{
-       u16 linear_rq_headroom = params->xdp_prog ?
-               XDP_PACKET_HEADROOM : MLX5_RX_HEADROOM;
-       bool is_linear_skb;
-
-       linear_rq_headroom += NET_IP_ALIGN;
-
-       is_linear_skb = (params->rq_wq_type == MLX5_WQ_TYPE_CYCLIC) ?
-               mlx5e_rx_is_linear_skb(mdev, params) :
-               mlx5e_rx_mpwqe_is_linear_skb(mdev, params);
-
-       return is_linear_skb ? linear_rq_headroom : 0;
-}
-
 void mlx5e_init_rq_type_params(struct mlx5_core_dev *mdev,
                               struct mlx5e_params *params)
 {