From b9c872f2316d27e2a323ffb410d706d680508093 Mon Sep 17 00:00:00 2001 From: Andy Gospodarek Date: Tue, 9 Jan 2018 16:06:16 -0500 Subject: [PATCH] net/mlx5e: Move generic functions to new file These functions were identified as ones that could be made generic and used by multiple drivers. Most of the contents of en_rx_am.c are moved to net_dim.c. Signed-off-by: Andy Gospodarek Acked-by: Tal Gilboa Acked-by: Saeed Mahameed Signed-off-by: David S. Miller --- drivers/net/ethernet/mellanox/mlx5/core/Makefile | 4 +- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_dim.c | 47 ++++++++++++++++++++++ .../mellanox/mlx5/core/{en_rx_am.c => net_dim.c} | 19 ++------- .../mellanox/mlx5/core/{en_dim.h => net_dim.h} | 3 +- 5 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_dim.c rename drivers/net/ethernet/mellanox/mlx5/core/{en_rx_am.c => net_dim.c} (94%) rename drivers/net/ethernet/mellanox/mlx5/core/{en_dim.h => net_dim.h} (95%) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Makefile b/drivers/net/ethernet/mellanox/mlx5/core/Makefile index 19b21b40ab07..b46b6de2819b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/Makefile +++ b/drivers/net/ethernet/mellanox/mlx5/core/Makefile @@ -14,8 +14,8 @@ mlx5_core-$(CONFIG_MLX5_FPGA) += fpga/cmd.o fpga/core.o fpga/conn.o fpga/sdk.o \ fpga/ipsec.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_rx_am.o en_txrx.o en_stats.o vxlan.o \ - en_arfs.o en_fs_ethtool.o en_selftest.o + en_tx.o en_rx.o en_dim.o en_txrx.o en_stats.o vxlan.o \ + en_arfs.o en_fs_ethtool.o en_selftest.o net_dim.o mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 470dcf5b2cc8..d13fa1e8a40b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -50,7 +50,7 @@ #include "wq.h" #include "mlx5_core.h" #include "en_stats.h" -#include "en_dim.h" +#include "net_dim.h" #define MLX5_SET_CFG(p, f, v) MLX5_SET(create_flow_group_in, p, f, v) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_dim.c b/drivers/net/ethernet/mellanox/mlx5/core/en_dim.c new file mode 100644 index 000000000000..57e7e4c434ef --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_dim.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016, Mellanox Technologies. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "en.h" + +void mlx5e_rx_am_work(struct work_struct *work) +{ + struct mlx5e_rx_am *am = container_of(work, struct mlx5e_rx_am, + work); + struct mlx5e_rq *rq = container_of(am, struct mlx5e_rq, am); + struct mlx5e_cq_moder cur_profile = mlx5e_am_get_profile(am->mode, + am->profile_ix); + + mlx5_core_modify_cq_moderation(rq->mdev, &rq->cq.mcq, + cur_profile.usec, cur_profile.pkts); + + am->state = MLX5E_AM_START_MEASURE; +} diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx_am.c b/drivers/net/ethernet/mellanox/mlx5/core/net_dim.c similarity index 94% rename from drivers/net/ethernet/mellanox/mlx5/core/en_rx_am.c rename to drivers/net/ethernet/mellanox/mlx5/core/net_dim.c index 337dd6024487..9fafe1da78a1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx_am.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/net_dim.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2016, Mellanox Technologies. All rights reserved. + * Copyright (c) 2017-2018, Broadcom Limited. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -32,11 +33,11 @@ #include "en.h" +#define MLX5E_PARAMS_AM_NUM_PROFILES 5 /* Adaptive moderation profiles */ #define MLX5E_AM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE 256 #define MLX5E_RX_AM_DEF_PROFILE_CQE 1 #define MLX5E_RX_AM_DEF_PROFILE_EQE 1 -#define MLX5E_PARAMS_AM_NUM_PROFILES 5 /* All profiles sizes must be MLX5E_PARAMS_AM_NUM_PROFILES */ #define MLX5_AM_EQE_PROFILES { \ @@ -61,7 +62,7 @@ profile[MLX5_CQ_PERIOD_NUM_MODES][MLX5E_PARAMS_AM_NUM_PROFILES] = { MLX5_AM_CQE_PROFILES, }; -static inline struct mlx5e_cq_moder mlx5e_am_get_profile(u8 cq_period_mode, int ix) +struct mlx5e_cq_moder mlx5e_am_get_profile(u8 cq_period_mode, int ix) { struct mlx5e_cq_moder cq_moder; @@ -82,7 +83,6 @@ struct mlx5e_cq_moder mlx5e_am_get_def_profile(u8 rx_cq_period_mode) return mlx5e_am_get_profile(rx_cq_period_mode, default_profile_ix); } - static bool mlx5e_am_on_top(struct mlx5e_rx_am *am) { switch (am->tune_state) { @@ -273,19 +273,6 @@ static void mlx5e_am_calc_stats(struct mlx5e_rx_am_sample *start, delta_us); } -void mlx5e_rx_am_work(struct work_struct *work) -{ - struct mlx5e_rx_am *am = container_of(work, struct mlx5e_rx_am, - work); - struct mlx5e_rq *rq = container_of(am, struct mlx5e_rq, am); - struct mlx5e_cq_moder cur_profile = profile[am->mode][am->profile_ix]; - - mlx5_core_modify_cq_moderation(rq->mdev, &rq->cq.mcq, - cur_profile.usec, cur_profile.pkts); - - am->state = MLX5E_AM_START_MEASURE; -} - void mlx5e_rx_am(struct mlx5e_rx_am *am, u16 event_ctr, u64 packets, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_dim.h b/drivers/net/ethernet/mellanox/mlx5/core/net_dim.h similarity index 95% rename from drivers/net/ethernet/mellanox/mlx5/core/en_dim.h rename to drivers/net/ethernet/mellanox/mlx5/core/net_dim.h index a1497bab7154..b03a48fc1540 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_dim.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/net_dim.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved. - * Copyright (c) 2017-2018, Broadcom Limited + * Copyright (c) 2017-2018, Broadcom Limited. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -98,5 +98,6 @@ void mlx5e_rx_am(struct mlx5e_rx_am *am, u64 bytes); void mlx5e_rx_am_work(struct work_struct *work); struct mlx5e_cq_moder mlx5e_am_get_def_profile(u8 rx_cq_period_mode); +struct mlx5e_cq_moder mlx5e_am_get_profile(u8 cq_period_mode, int ix); #endif /* MLX5_AM_H */ -- 2.11.0