From patchwork Thu Jun 21 15:28: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: 932728 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 41BN1W6KyTz9s2R for ; Thu, 21 Jun 2018 23:33:03 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933465AbeFUNdB (ORCPT ); Thu, 21 Jun 2018 09:33:01 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:54827 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932902AbeFUNc7 (ORCPT ); Thu, 21 Jun 2018 09:32:59 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from vadimp@mellanox.com) with ESMTPS (AES256-SHA encrypted); 21 Jun 2018 16:35:27 +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 w5LDWqVl020478; Thu, 21 Jun 2018 16:32:54 +0300 From: Vadim Pasternak To: davem@davemloft.net Cc: netdev@vger.kernel.org, jiri@resnulli.us, Vadim Pasternak Subject: [PATCH v0 12/12] mlxsw: core: Add ports temperature measurement to thermal algorithm Date: Thu, 21 Jun 2018 15:28:35 +0000 Message-Id: <1529594915-20741-3-git-send-email-vadimp@mellanox.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1529594915-20741-1-git-send-email-vadimp@mellanox.com> References: <1529594915-20741-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) {