From patchwork Tue Jun 26 12:10:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Pasternak X-Patchwork-Id: 934776 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41FMPH1KGtz9ry1 for ; Tue, 26 Jun 2018 20:15:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934379AbeFZKPU (ORCPT ); Tue, 26 Jun 2018 06:15:20 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:37428 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934233AbeFZKPN (ORCPT ); Tue, 26 Jun 2018 06:15:13 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from vadimp@mellanox.com) with ESMTPS (AES256-SHA encrypted); 26 Jun 2018 13:17:48 +0300 Received: from r-mgtswh-226.mtr.labs.mlnx. (r-mgtswh-226.mtr.labs.mlnx [10.209.1.51]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w5QAEt1Q011163; Tue, 26 Jun 2018 13:15:09 +0300 From: Vadim Pasternak To: davem@davemloft.net Cc: netdev@vger.kernel.org, linux@roeck-us.net, rui.zhang@intel.com, edubezval@gmail.com, jiri@resnulli.us, mlxsw@mellanox.com, michaelsh@mellanox.com, Vadim Pasternak Subject: [patch net-next RFC 10/12] mlxsw: core: Add ports temperature measurement to thermal algorithm Date: Tue, 26 Jun 2018 12:10:35 +0000 Message-Id: <1530015037-67361-11-git-send-email-vadimp@mellanox.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1530015037-67361-1-git-send-email-vadimp@mellanox.com> References: <1530015037-67361-1-git-send-email-vadimp@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Ports temperature has most significant impact on system thermal state and should be considered by the thermal algorithm. The thermal zone temperature is extended for reading ports temperatures along with a chip temperature. The temperature value, provided to the core thermal algorithm will be accumulated value of a chip and ports temperature sensing, normalized according to the basic constant thresholds. Signed-off-by: Vadim Pasternak Acked-by: Jiri Pirko --- drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 66 ++++++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 65962ed..23d6197 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -109,6 +109,8 @@ struct mlxsw_thermal { u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; enum thermal_device_mode mode; + int count; + int *ports_temp_cache; }; static inline u8 mlxsw_state_to_duty(int state) @@ -213,10 +215,11 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, - int *p_temp) +static int mlxsw_thermal_init_temp(struct mlxsw_thermal *thermal, + struct mlxsw_env_temp_thresh *delta, + struct mlxsw_env_temp_multi *multi, + int *p_temp, bool *p_crit) { - struct mlxsw_thermal *thermal = tzdev->devdata; struct device *dev = thermal->bus_info->dev; char mtmp_pl[MLXSW_REG_MTMP_LEN]; unsigned int temp; @@ -231,10 +234,58 @@ static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, } mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL); - *p_temp = (int) temp; + if (temp >= MLXSW_ENV_TEMP_CRIT) { + *p_crit = true; + } else if (temp < MLXSW_ENV_TEMP_NORM) { + multi->thresh.normal = temp; + delta->normal = MLXSW_ENV_TEMP_NORM - temp; + } else if (temp >= MLXSW_ENV_TEMP_HOT) { + multi->thresh.crit = temp; + delta->crit = temp - MLXSW_ENV_TEMP_HOT; + multi->mask |= MLXSW_ENV_CRIT_MASK; + } else { + multi->thresh.hot = temp; + delta->hot = temp - MLXSW_ENV_TEMP_NORM; + multi->mask |= MLXSW_ENV_HOT_MASK; + } + *p_temp = temp; + return 0; } +static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, + int *p_temp) +{ + struct mlxsw_thermal *thermal = tzdev->devdata; + struct device *dev = thermal->bus_info->dev; + struct mlxsw_env_temp_multi multi; + struct mlxsw_env_temp_thresh delta; + bool crit = false; + int err; + + memset(&multi, 0, sizeof(struct mlxsw_env_temp_multi)); + memset(&delta, 0, sizeof(struct mlxsw_env_temp_thresh)); + /* Read ASIC temperature */ + err = mlxsw_thermal_init_temp(thermal, &delta, &multi, + p_temp, &crit); + if (err) { + dev_err(dev, "Failed to query ASIC temp sensor\n"); + return err; + } + + /* No need to proceed ports temperature reading, since ASIC temperature + * should be resulted in system shutdown. + */ + if (crit) + return 0; + + /* Collect ports temperature */ + return mlxsw_env_collect_port_temp(thermal->core, + thermal->ports_temp_cache, + thermal->count, &multi, &delta, + NULL, p_temp); +} + static int mlxsw_thermal_get_trip_type(struct thermal_zone_device *tzdev, int trip, enum thermal_trip_type *p_type) @@ -436,6 +487,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, const struct mlxsw_bus_info *bus_info, struct mlxsw_thermal **p_thermal) { + unsigned int max_ports = mlxsw_core_max_ports(core); char mfcr_pl[MLXSW_REG_MFCR_LEN] = { 0 }; enum mlxsw_reg_mfcr_pwm_frequency freq; struct device *dev = bus_info->dev; @@ -452,6 +504,12 @@ int mlxsw_thermal_init(struct mlxsw_core *core, thermal->core = core; thermal->bus_info = bus_info; memcpy(thermal->trips, default_thermal_trips, sizeof(thermal->trips)); + thermal->ports_temp_cache = devm_kmalloc_array(dev, max_ports, + sizeof(int), + GFP_KERNEL); + if (!thermal->ports_temp_cache) + return -ENOMEM; + thermal->count = max_ports; err = mlxsw_reg_query(thermal->core, MLXSW_REG(mfcr), mfcr_pl); if (err) {