From patchwork Tue Aug 15 04:56:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13353524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6884C001DE for ; Tue, 15 Aug 2023 04:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234449AbjHOE6E (ORCPT ); Tue, 15 Aug 2023 00:58:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234326AbjHOE52 (ORCPT ); Tue, 15 Aug 2023 00:57:28 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76C6AE65 for ; Mon, 14 Aug 2023 21:57:24 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-76ce66110edso310865285a.0 for ; Mon, 14 Aug 2023 21:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1692075443; x=1692680243; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=om0xtsozw2G06RTwu5GlBYykUblaKHXQ0Gcti45D2UY=; b=L1mAS0K0rQ6RWKmofVi8xNZaFGwNnEIOdX9Zs0SbGwZyrNl3JK8EWEaY1Qe4xcKOZJ 6s78kC73hCQesXQX9usUY/7q8/Fk2sQCqiniJTRVh33pBVpRKlRs0S7l1OS1/1ivPEFf ZxuSIgfdiJMOFmF0PfDsA+cBbOFl1GDAKMOyw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692075443; x=1692680243; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=om0xtsozw2G06RTwu5GlBYykUblaKHXQ0Gcti45D2UY=; b=WXFXtL4mOxgziSxf5gIuM7A4fS2mBWM0bymtptfcwQncX7vCyQdJ8UrLMcFwxLzWKo 5IXrAFlNAdaAXI35UqtrnWxWzwN7nl4AhwbrNF43o8gvz7OCWD3BKUQICDZ4sp8j4EKp 9JJjlskXhzQUIXjbG6X8LNYtS8hDO9g07jojtSeEnnlPDXKqWpVoRmTfxRFphQbIPVR+ PblyKTQeqxdjc2xGyQuHt2MH/Rxl1OcY1ZnmXOmEQ7+2ANjV7Fz0x8AsFibmuLiYwcoH wRVZORHv1Nq+XkdumLKMBF7vhYh0v5Yn3Wf9EQsDVs9J0b8CHpofG5GDZFtRMpqlM3mg rKYA== X-Gm-Message-State: AOJu0Yxo43G2svSfADwdj2y0ThswJMepDHSl2Me1qBeV83e6mV1nTeIO HtzRH7QnaLHWyOC5EMS8ZtY10A== X-Google-Smtp-Source: AGHT+IFYpLJlooEWviCQCF+XqQIspXkrMVeOfeUHDa2n/OP0B2Zemidqo27TdpU67YyP6KhKa6e6Mg== X-Received: by 2002:a05:620a:668:b0:76c:ddf8:522b with SMTP id a8-20020a05620a066800b0076cddf8522bmr11017280qkh.37.1692075443379; Mon, 14 Aug 2023 21:57:23 -0700 (PDT) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id k28-20020a05620a143c00b00767cbd5e942sm3516575qkj.72.2023.08.14.21.57.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2023 21:57:22 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, gospo@broadcom.com, Kalesh AP , Andy Gospodarek , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [PATCH net-next 09/12] bnxt_en: Move hwmon functions into a dedicated file Date: Mon, 14 Aug 2023 21:56:55 -0700 Message-Id: <20230815045658.80494-10-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230815045658.80494-1-michael.chan@broadcom.com> References: <20230815045658.80494-1-michael.chan@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Kalesh AP This is in preparation for upcoming patches in the series. Driver has to expose more threshold temperatures through the hwmon sysfs interface. More code will be added and do not want to overload bnxt.c. Reviewed-by: Andy Gospodarek Cc: Jean Delvare Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Signed-off-by: Kalesh AP Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/Makefile | 1 + drivers/net/ethernet/broadcom/bnxt/bnxt.c | 75 +---------------- .../net/ethernet/broadcom/bnxt/bnxt_hwmon.c | 82 +++++++++++++++++++ .../net/ethernet/broadcom/bnxt/bnxt_hwmon.h | 25 ++++++ 4 files changed, 109 insertions(+), 74 deletions(-) create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h diff --git a/drivers/net/ethernet/broadcom/bnxt/Makefile b/drivers/net/ethernet/broadcom/bnxt/Makefile index 2bc2b707d6ee..ba6c239d52fa 100644 --- a/drivers/net/ethernet/broadcom/bnxt/Makefile +++ b/drivers/net/ethernet/broadcom/bnxt/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_BNXT) += bnxt_en.o bnxt_en-y := bnxt.o bnxt_hwrm.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o bnxt_xdp.o bnxt_ptp.o bnxt_vfr.o bnxt_devlink.o bnxt_dim.o bnxt_coredump.o bnxt_en-$(CONFIG_BNXT_FLOWER_OFFLOAD) += bnxt_tc.o bnxt_en-$(CONFIG_DEBUG_FS) += bnxt_debugfs.o +bnxt_en-$(CONFIG_BNXT_HWMON) += bnxt_hwmon.o diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index f9bb66525d77..5e97a3d93e87 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -71,6 +70,7 @@ #include "bnxt_tc.h" #include "bnxt_devlink.h" #include "bnxt_debugfs.h" +#include "bnxt_hwmon.h" #define BNXT_TX_TIMEOUT (5 * HZ) #define BNXT_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_HW | \ @@ -10245,79 +10245,6 @@ static void bnxt_get_wol_settings(struct bnxt *bp) } while (handle && handle != 0xffff); } -#ifdef CONFIG_BNXT_HWMON -static ssize_t bnxt_show_temp(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct hwrm_temp_monitor_query_output *resp; - struct hwrm_temp_monitor_query_input *req; - struct bnxt *bp = dev_get_drvdata(dev); - u32 len = 0; - int rc; - - rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY); - if (rc) - return rc; - resp = hwrm_req_hold(bp, req); - rc = hwrm_req_send(bp, req); - if (!rc) - len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */ - hwrm_req_drop(bp, req); - if (rc) - return rc; - return len; -} -static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0); - -static struct attribute *bnxt_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, - NULL -}; -ATTRIBUTE_GROUPS(bnxt); - -static void bnxt_hwmon_uninit(struct bnxt *bp) -{ - if (bp->hwmon_dev) { - hwmon_device_unregister(bp->hwmon_dev); - bp->hwmon_dev = NULL; - } -} - -static void bnxt_hwmon_init(struct bnxt *bp) -{ - struct hwrm_temp_monitor_query_input *req; - struct pci_dev *pdev = bp->pdev; - int rc; - - rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY); - if (!rc) - rc = hwrm_req_send_silent(bp, req); - if (rc == -EACCES || rc == -EOPNOTSUPP) { - bnxt_hwmon_uninit(bp); - return; - } - - if (bp->hwmon_dev) - return; - - bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, - DRV_MODULE_NAME, bp, - bnxt_groups); - if (IS_ERR(bp->hwmon_dev)) { - bp->hwmon_dev = NULL; - dev_warn(&pdev->dev, "Cannot register hwmon device\n"); - } -} -#else -static void bnxt_hwmon_uninit(struct bnxt *bp) -{ -} - -static void bnxt_hwmon_init(struct bnxt *bp) -{ -} -#endif - static bool bnxt_eee_config_ok(struct bnxt *bp) { struct ethtool_eee *eee = &bp->eee; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c new file mode 100644 index 000000000000..476616d97071 --- /dev/null +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c @@ -0,0 +1,82 @@ +/* Broadcom NetXtreme-C/E network driver. + * + * Copyright (c) 2023 Broadcom Limited + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +#include "bnxt_hsi.h" +#include "bnxt.h" +#include "bnxt_hwrm.h" +#include "bnxt_hwmon.h" + +static ssize_t bnxt_show_temp(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + struct hwrm_temp_monitor_query_output *resp; + struct hwrm_temp_monitor_query_input *req; + struct bnxt *bp = dev_get_drvdata(dev); + u32 len = 0; + int rc; + + rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY); + if (rc) + return rc; + resp = hwrm_req_hold(bp, req); + rc = hwrm_req_send(bp, req); + if (!rc) + len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */ + hwrm_req_drop(bp, req); + if (rc) + return rc; + return len; +} +static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0); + +static struct attribute *bnxt_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + NULL +}; +ATTRIBUTE_GROUPS(bnxt); + +void bnxt_hwmon_uninit(struct bnxt *bp) +{ + if (bp->hwmon_dev) { + hwmon_device_unregister(bp->hwmon_dev); + bp->hwmon_dev = NULL; + } +} + +void bnxt_hwmon_init(struct bnxt *bp) +{ + struct hwrm_temp_monitor_query_input *req; + struct pci_dev *pdev = bp->pdev; + int rc; + + rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY); + if (!rc) + rc = hwrm_req_send_silent(bp, req); + if (rc == -EACCES || rc == -EOPNOTSUPP) { + bnxt_hwmon_uninit(bp); + return; + } + + if (bp->hwmon_dev) + return; + + bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, + DRV_MODULE_NAME, bp, + bnxt_groups); + if (IS_ERR(bp->hwmon_dev)) { + bp->hwmon_dev = NULL; + dev_warn(&pdev->dev, "Cannot register hwmon device\n"); + } +} diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h new file mode 100644 index 000000000000..af310066687c --- /dev/null +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h @@ -0,0 +1,25 @@ +/* Broadcom NetXtreme-C/E network driver. + * + * Copyright (c) 2023 Broadcom Limited + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + */ + +#ifndef BNXT_HWMON_H +#define BNXT_HWMON_H + +#ifdef CONFIG_BNXT_HWMON +void bnxt_hwmon_uninit(struct bnxt *bp); +void bnxt_hwmon_init(struct bnxt *bp); +#else +static inline void bnxt_hwmon_uninit(struct bnxt *bp) +{ +} + +static inline void bnxt_hwmon_init(struct bnxt *bp) +{ +} +#endif +#endif From patchwork Tue Aug 15 04:56:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13353523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0744C001B0 for ; Tue, 15 Aug 2023 04:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234521AbjHOE6A (ORCPT ); Tue, 15 Aug 2023 00:58:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234449AbjHOE52 (ORCPT ); Tue, 15 Aug 2023 00:57:28 -0400 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C00B2107 for ; Mon, 14 Aug 2023 21:57:26 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-76754b9eac0so341126885a.0 for ; Mon, 14 Aug 2023 21:57:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1692075446; x=1692680246; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=VbhEpCyeq249kaOr5uO5P2KyhnYUq4A1aqtnBehGNjE=; b=AfIO20CoNo/5R4UqVDxtUyCBV3P0nbWbllm9kfbdXHsc7A5kyP/TJ1rkJHtVSi9gnX MFI7xyAia5WkVsVJbfFXJpbea4su5kuGilgU2lpgrzpgoMb9aczGQ5JHcdtxMykkbLul vVDdWVC8+s5Ti3j3WXMdyyoNd+NymsfZl4fL0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692075446; x=1692680246; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VbhEpCyeq249kaOr5uO5P2KyhnYUq4A1aqtnBehGNjE=; b=gdrshijhj/PRiGemHloVzvB9hL6orNMfMY92QqNDQ3ibAp5znpS3S8qml/Wbiz5OVK FISznwUkSIoWrp87jIjKSaBH5Wjo4CM6CEBSOf0iVLXqhMtKKGu7kCPTgnMe+RZBFndV GZ8F7m5+GqV+0HEDU0A2TJ6YbPvR/PQ/NRXgqXV7VmXGHUaz11aoCQ+K2UqYAIxAE3ho jEif7xxD4aGwY9KGkpgMtAQwN0BFCjTHSLemTMBE+G+JDX5N7Y+uFHd6zlA0kt2IvFGM AggHBWs4MmYyjs9OmYgZd+y/MoFcwIiTZ3LVSFe3qW/Z4yS9utKfR1eQ4VyefFPotXM9 DCvA== X-Gm-Message-State: AOJu0Yx65dv+EMRVLA5cE1eCPndaVA7Rp22Mg5pvq0aeJbYvK6GnBgqw M4xJdYqNxTX2tChs9BGmy4LxYg== X-Google-Smtp-Source: AGHT+IG2k4bBElh/8j4O0JVjBOPeNVlChbOdZ6io4Knd6qQwqwQ+Un8S8OO3BFupxCg3uTizPptwBQ== X-Received: by 2002:a05:620a:d95:b0:76d:1232:3731 with SMTP id q21-20020a05620a0d9500b0076d12323731mr13965392qkl.27.1692075445045; Mon, 14 Aug 2023 21:57:25 -0700 (PDT) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id k28-20020a05620a143c00b00767cbd5e942sm3516575qkj.72.2023.08.14.21.57.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2023 21:57:24 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, gospo@broadcom.com, Kalesh AP , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [PATCH net-next 10/12] bnxt_en: Modify the driver to use hwmon_device_register_with_info Date: Mon, 14 Aug 2023 21:56:56 -0700 Message-Id: <20230815045658.80494-11-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230815045658.80494-1-michael.chan@broadcom.com> References: <20230815045658.80494-1-michael.chan@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Kalesh AP The use of hwmon_device_register_with_groups() is deprecated. Modified the driver to use hwmon_device_register_with_info(). Driver currently exports only temp1_input through hwmon sysfs interface. But FW has been modified to report more threshold temperatures and driver want to report them through the hwmon interface. Cc: Jean Delvare Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Signed-off-by: Kalesh AP Signed-off-by: Michael Chan --- .../net/ethernet/broadcom/bnxt/bnxt_hwmon.c | 72 ++++++++++++++----- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c index 476616d97071..20381b7b1d78 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c @@ -18,34 +18,74 @@ #include "bnxt_hwrm.h" #include "bnxt_hwmon.h" -static ssize_t bnxt_show_temp(struct device *dev, - struct device_attribute *devattr, char *buf) +static int bnxt_hwrm_temp_query(struct bnxt *bp, u8 *temp) { struct hwrm_temp_monitor_query_output *resp; struct hwrm_temp_monitor_query_input *req; - struct bnxt *bp = dev_get_drvdata(dev); - u32 len = 0; int rc; rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY); if (rc) return rc; resp = hwrm_req_hold(bp, req); - rc = hwrm_req_send(bp, req); - if (!rc) - len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */ - hwrm_req_drop(bp, req); + rc = hwrm_req_send_silent(bp, req); if (rc) + goto err; + + if (temp) + *temp = resp->temp; +err: + hwrm_req_drop(bp, req); + return rc; +} + +static umode_t bnxt_hwmon_is_visible(const void *_data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + if (type != hwmon_temp) + return 0; + + switch (attr) { + case hwmon_temp_input: + return 0444; + default: + return 0; + } +} + +static int bnxt_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, + int channel, long *val) +{ + struct bnxt *bp = dev_get_drvdata(dev); + u8 temp = 0; + int rc; + + switch (attr) { + case hwmon_temp_input: + rc = bnxt_hwrm_temp_query(bp, &temp); + if (!rc) + *val = temp * 1000; return rc; - return len; + default: + return -EOPNOTSUPP; + } } -static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0); -static struct attribute *bnxt_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, +static const struct hwmon_channel_info *bnxt_hwmon_info[] = { + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT), NULL }; -ATTRIBUTE_GROUPS(bnxt); + +static const struct hwmon_ops bnxt_hwmon_ops = { + .is_visible = bnxt_hwmon_is_visible, + .read = bnxt_hwmon_read, +}; + +static const struct hwmon_chip_info bnxt_hwmon_chip_info = { + .ops = &bnxt_hwmon_ops, + .info = bnxt_hwmon_info, +}; void bnxt_hwmon_uninit(struct bnxt *bp) { @@ -72,9 +112,9 @@ void bnxt_hwmon_init(struct bnxt *bp) if (bp->hwmon_dev) return; - bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, - DRV_MODULE_NAME, bp, - bnxt_groups); + bp->hwmon_dev = hwmon_device_register_with_info(&pdev->dev, + DRV_MODULE_NAME, bp, + &bnxt_hwmon_chip_info, NULL); if (IS_ERR(bp->hwmon_dev)) { bp->hwmon_dev = NULL; dev_warn(&pdev->dev, "Cannot register hwmon device\n"); From patchwork Tue Aug 15 04:56:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13353526 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02B68C41513 for ; Tue, 15 Aug 2023 04:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234326AbjHOE6K (ORCPT ); Tue, 15 Aug 2023 00:58:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234469AbjHOE5a (ORCPT ); Tue, 15 Aug 2023 00:57:30 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FF59127 for ; Mon, 14 Aug 2023 21:57:27 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-7659cb9c42aso334836485a.3 for ; Mon, 14 Aug 2023 21:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1692075447; x=1692680247; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=mgJ2q0SuKzngBgeOTGAr78clseqxlSR5jZWB2Ms4jrI=; b=DbD0gMOk5CdBBvqVTmS5CN6Ax5ClWraRJ6nWWzqjTpyRbBEncD2QhVi2PO4sHLPxij X9RDGZaIStLZq7qaYBmmXtZ1lOrVsbyejIr+6y0mbWnMC74/kWUDRe+JI0K4EUo0HyW+ bEyXJE6gpXEX2ZxtqArRM9xRCOsH039g8vnAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692075447; x=1692680247; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mgJ2q0SuKzngBgeOTGAr78clseqxlSR5jZWB2Ms4jrI=; b=dpGUwOk9+kCc0mPyZRTcmWwCbJeQnNGeYAMO4rsXiPRGBcEQ6Qm+nflhtCaN+BNfDD hefGmqNihZ31xr9gxzwNuT5DBbCQkbf3X9k0S3OMwsRTBclc/P6foulnxwSPkB7Jxsoo xwYjEgm9ND/ChC+mUmo7shBq5B2ykFYS9idenDOl/zIq9b49tzq7lHznmvDmkNagayN4 kLnNAVggj2DTpE1D0G3TLMqe4cdoGVY8CH+tN5rkW1UEFW0S9AczIO8kLFULnw5gUUdQ rvAdJZzB7ubUo/DjiXuK9G49A5Vpp6VdxoKCid/EMxWDNfb118S27XZ/hdElnH6dkgZg snLw== X-Gm-Message-State: AOJu0Ywz8IzyZVIzBZ8rRx9wn6AYLQ9NuNWVQuDDU252J4mOC07qCkn7 vkv5ZnihK6yF9DT+EedsWvW35g== X-Google-Smtp-Source: AGHT+IEDCu7rmxNzJJkCYPPRnnGmiNw2b8lskJpSEnSDj1bsFO+rGrUIfrMuc5hzEBT/Dojn/waO8g== X-Received: by 2002:a05:620a:850:b0:768:efd:2685 with SMTP id u16-20020a05620a085000b007680efd2685mr12167630qku.33.1692075446789; Mon, 14 Aug 2023 21:57:26 -0700 (PDT) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id k28-20020a05620a143c00b00767cbd5e942sm3516575qkj.72.2023.08.14.21.57.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2023 21:57:26 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, gospo@broadcom.com, Kalesh AP , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [PATCH net-next 11/12] bnxt_en: Expose threshold temperatures through hwmon Date: Mon, 14 Aug 2023 21:56:57 -0700 Message-Id: <20230815045658.80494-12-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230815045658.80494-1-michael.chan@broadcom.com> References: <20230815045658.80494-1-michael.chan@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Kalesh AP HWRM_TEMP_MONITOR_QUERY response now indicates various threshold temperatures. Expose these threshold temperatures through the hwmon sysfs. Also, provide temp1_max_alarm through which the user can check whether the threshold temperature has been reached or not. Example: cat /sys/class/hwmon/hwmon3/temp1_input 75000 cat /sys/class/hwmon/hwmon3/temp1_max 105000 cat /sys/class/hwmon/hwmon3/temp1_max_alarm 0 Cc: Jean Delvare Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Signed-off-by: Kalesh AP Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 7 ++ .../net/ethernet/broadcom/bnxt/bnxt_hwmon.c | 71 +++++++++++++++++-- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h index 84cbcfa61bc1..43a07d84f815 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h @@ -2013,6 +2013,7 @@ struct bnxt { #define BNXT_FW_CAP_RING_MONITOR BIT_ULL(30) #define BNXT_FW_CAP_DBG_QCAPS BIT_ULL(31) #define BNXT_FW_CAP_PTP BIT_ULL(32) + #define BNXT_FW_CAP_THRESHOLD_TEMP_SUPPORTED BIT_ULL(33) u32 fw_dbg_cap; @@ -2185,7 +2186,13 @@ struct bnxt { struct bnxt_tc_info *tc_info; struct list_head tc_indr_block_list; struct dentry *debugfs_pdev; +#ifdef CONFIG_BNXT_HWMON struct device *hwmon_dev; + u8 warn_thresh_temp; + u8 crit_thresh_temp; + u8 fatal_thresh_temp; + u8 shutdown_thresh_temp; +#endif enum board_idx board_idx; }; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c index 20381b7b1d78..f5affac1169a 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c @@ -34,6 +34,15 @@ static int bnxt_hwrm_temp_query(struct bnxt *bp, u8 *temp) if (temp) *temp = resp->temp; + + if (resp->flags & TEMP_MONITOR_QUERY_RESP_FLAGS_THRESHOLD_VALUES_AVAILABLE) { + if (!temp) + bp->fw_cap |= BNXT_FW_CAP_THRESHOLD_TEMP_SUPPORTED; + bp->warn_thresh_temp = resp->warn_threshold; + bp->crit_thresh_temp = resp->critical_threshold; + bp->fatal_thresh_temp = resp->fatal_threshold; + bp->shutdown_thresh_temp = resp->shutdown_threshold; + } err: hwrm_req_drop(bp, req); return rc; @@ -42,12 +51,30 @@ static int bnxt_hwrm_temp_query(struct bnxt *bp, u8 *temp) static umode_t bnxt_hwmon_is_visible(const void *_data, enum hwmon_sensor_types type, u32 attr, int channel) { + const struct bnxt *bp = _data; + if (type != hwmon_temp) return 0; switch (attr) { case hwmon_temp_input: return 0444; + case hwmon_temp_lcrit: + case hwmon_temp_crit: + case hwmon_temp_emergency: + case hwmon_temp_lcrit_alarm: + case hwmon_temp_crit_alarm: + case hwmon_temp_emergency_alarm: + if (~bp->fw_cap & BNXT_FW_CAP_THRESHOLD_TEMP_SUPPORTED) + return 0; + return 0444; + /* Max temperature setting in NVM is optional */ + case hwmon_temp_max: + case hwmon_temp_max_alarm: + if (~bp->fw_cap & BNXT_FW_CAP_THRESHOLD_TEMP_SUPPORTED || + !bp->shutdown_thresh_temp) + return 0; + return 0444; default: return 0; } @@ -66,6 +93,38 @@ static int bnxt_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 if (!rc) *val = temp * 1000; return rc; + case hwmon_temp_lcrit: + *val = bp->warn_thresh_temp * 1000; + return 0; + case hwmon_temp_crit: + *val = bp->crit_thresh_temp * 1000; + return 0; + case hwmon_temp_emergency: + *val = bp->fatal_thresh_temp * 1000; + return 0; + case hwmon_temp_max: + *val = bp->shutdown_thresh_temp * 1000; + return 0; + case hwmon_temp_lcrit_alarm: + rc = bnxt_hwrm_temp_query(bp, &temp); + if (!rc) + *val = temp >= bp->warn_thresh_temp; + return rc; + case hwmon_temp_crit_alarm: + rc = bnxt_hwrm_temp_query(bp, &temp); + if (!rc) + *val = temp >= bp->crit_thresh_temp; + return rc; + case hwmon_temp_emergency_alarm: + rc = bnxt_hwrm_temp_query(bp, &temp); + if (!rc) + *val = temp >= bp->fatal_thresh_temp; + return rc; + case hwmon_temp_max_alarm: + rc = bnxt_hwrm_temp_query(bp, &temp); + if (!rc) + *val = temp >= bp->shutdown_thresh_temp; + return rc; default: return -EOPNOTSUPP; } @@ -73,7 +132,11 @@ static int bnxt_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 static const struct hwmon_channel_info *bnxt_hwmon_info[] = { HWMON_CHANNEL_INFO(temp, - HWMON_T_INPUT), + HWMON_T_INPUT | + HWMON_T_MAX | HWMON_T_LCRIT | + HWMON_T_CRIT | HWMON_T_EMERGENCY | + HWMON_T_CRIT_ALARM | HWMON_T_LCRIT_ALARM | + HWMON_T_MAX_ALARM | HWMON_T_EMERGENCY_ALARM), NULL }; @@ -97,13 +160,11 @@ void bnxt_hwmon_uninit(struct bnxt *bp) void bnxt_hwmon_init(struct bnxt *bp) { - struct hwrm_temp_monitor_query_input *req; struct pci_dev *pdev = bp->pdev; int rc; - rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY); - if (!rc) - rc = hwrm_req_send_silent(bp, req); + /* temp1_xxx is only sensor, ensure not registered if it will fail */ + rc = bnxt_hwrm_temp_query(bp, NULL); if (rc == -EACCES || rc == -EOPNOTSUPP) { bnxt_hwmon_uninit(bp); return; From patchwork Tue Aug 15 04:56:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13353525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1165EC001DB for ; Tue, 15 Aug 2023 04:58:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234469AbjHOE6P (ORCPT ); Tue, 15 Aug 2023 00:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234470AbjHOE5d (ORCPT ); Tue, 15 Aug 2023 00:57:33 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03318133 for ; Mon, 14 Aug 2023 21:57:30 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-76ce59842c1so308941285a.3 for ; Mon, 14 Aug 2023 21:57:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1692075449; x=1692680249; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=3YKVvaqJEV7IIu6DihHjSX80Ubcju3i+t9QT5eFzbdA=; b=A5gzICyyERiOeLTEsjciDiGqggdRrUi2th/IY+47NRb/iTwEHkDucfbeXiFQcSrjsG TjOq+vV19PYQsPpvQDLxV0TTZYxdqOlgJ7jji0iDC7pkX8nDns5N2vGiZy3BAnKzedP4 +J2Z53/ogBbfy9SyWh1nPV9ckpadJwcrpaRCE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692075449; x=1692680249; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3YKVvaqJEV7IIu6DihHjSX80Ubcju3i+t9QT5eFzbdA=; b=IKXExC0XMcxQR5Lk5Iz2uQGyAJwphVqo9RhzhlrqddZnMPiZgtno8sUTG3+IjSedyj RJxskDXvt66gaAdXP2uOpsuit00hSg6OGC88RGyz0WKruE29fbD8DNT8rse9CVk50u6S akzwHnU7d3RPpBOxTrt64wcJ9NMlFYyrkCMEQHjFVMCNra+oQ1nN32DP2k+Wk6wsQw+/ Rkd5LD5DNg9hx2VZzU5jT3ifpMCU8URB9afvCm1x7IKRhlX+TpL0kLTzRHkQQqZrBVk6 WTRJwJiNrrckYGptuJo+G4vn6TqPHI6VXWJjdxchJwS0DPuBvROEznoOk0/mVC40Kpjl +z6A== X-Gm-Message-State: AOJu0YxSw5y5YIoQryZkMlJWx9qO+bKzhjLGolDTn2TEHydlFSvHhvJs TdcsBT0s7QljQ/EXfTi9rww5ww== X-Google-Smtp-Source: AGHT+IFxERCkUGDxFTT/vKVeRwmahoXOIEyiSMop6ckEzy1zcXfj8pQ4d6Zrfai6WT+lWm+DGVTKdw== X-Received: by 2002:a05:620a:668:b0:76c:ddf8:522b with SMTP id a8-20020a05620a066800b0076cddf8522bmr11017372qkh.37.1692075448575; Mon, 14 Aug 2023 21:57:28 -0700 (PDT) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id k28-20020a05620a143c00b00767cbd5e942sm3516575qkj.72.2023.08.14.21.57.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2023 21:57:28 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, gospo@broadcom.com, Kalesh AP , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [PATCH net-next 12/12] bnxt_en: Event handler for Thermal event Date: Mon, 14 Aug 2023 21:56:58 -0700 Message-Id: <20230815045658.80494-13-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230815045658.80494-1-michael.chan@broadcom.com> References: <20230815045658.80494-1-michael.chan@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Kalesh AP Newer FW will send a new async event when it detects that the chip's temperature has crossed the configured threshold value. The driver will now notify hwmon and will log a warning message. Cc: Jean Delvare Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Signed-off-by: Kalesh AP Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 44 +++++++++++++++++++ .../net/ethernet/broadcom/bnxt/bnxt_hwmon.c | 8 ++++ .../net/ethernet/broadcom/bnxt/bnxt_hwmon.h | 5 +++ 3 files changed, 57 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 5e97a3d93e87..c8e04c9501ee 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -2130,6 +2130,17 @@ static u16 bnxt_agg_ring_id_to_grp_idx(struct bnxt *bp, u16 ring_id) return INVALID_HW_RING_ID; } +#define BNXT_EVENT_THERMAL_CURRENT_TEMP(data2) \ + ((data2) & ASYNC_EVENT_CMPL_ERROR_REPORT_THERMAL_EVENT_DATA2_CURRENT_TEMP_MASK) + +#define BNXT_EVENT_THERMAL_THRESHOLD_TEMP(data2) \ + (((data2) & \ + ASYNC_EVENT_CMPL_ERROR_REPORT_THERMAL_EVENT_DATA2_THRESHOLD_TEMP_MASK) >> \ + ASYNC_EVENT_CMPL_ERROR_REPORT_THERMAL_EVENT_DATA2_THRESHOLD_TEMP_SFT) + +#define EVENT_DATA1_THERMAL_THRESHOLD_TYPE(data1) \ + ((data1) & ASYNC_EVENT_CMPL_ERROR_REPORT_THERMAL_EVENT_DATA1_THRESHOLD_TYPE_MASK) + static void bnxt_event_error_report(struct bnxt *bp, u32 data1, u32 data2) { u32 err_type = BNXT_EVENT_ERROR_REPORT_TYPE(data1); @@ -2145,6 +2156,39 @@ static void bnxt_event_error_report(struct bnxt *bp, u32 data1, u32 data2) case ASYNC_EVENT_CMPL_ERROR_REPORT_BASE_EVENT_DATA1_ERROR_TYPE_DOORBELL_DROP_THRESHOLD: netdev_warn(bp->dev, "One or more MMIO doorbells dropped by the device!\n"); break; + case ASYNC_EVENT_CMPL_ERROR_REPORT_BASE_EVENT_DATA1_ERROR_TYPE_THERMAL_THRESHOLD: { + char *threshold_type; + u32 attr; + + switch (EVENT_DATA1_THERMAL_THRESHOLD_TYPE(data1)) { + case ASYNC_EVENT_CMPL_ERROR_REPORT_THERMAL_EVENT_DATA1_THRESHOLD_TYPE_WARN: + attr = hwmon_temp_lcrit_alarm; + threshold_type = "warning"; + break; + case ASYNC_EVENT_CMPL_ERROR_REPORT_THERMAL_EVENT_DATA1_THRESHOLD_TYPE_CRITICAL: + attr = hwmon_temp_crit_alarm; + threshold_type = "critical"; + break; + case ASYNC_EVENT_CMPL_ERROR_REPORT_THERMAL_EVENT_DATA1_THRESHOLD_TYPE_FATAL: + attr = hwmon_temp_emergency_alarm; + threshold_type = "fatal"; + break; + case ASYNC_EVENT_CMPL_ERROR_REPORT_THERMAL_EVENT_DATA1_THRESHOLD_TYPE_SHUTDOWN: + attr = hwmon_temp_max_alarm; + threshold_type = "shutdown"; + break; + default: + netdev_err(bp->dev, "Unknown Thermal threshold type event\n"); + return; + } + netdev_warn(bp->dev, "Chip temperature has crossed the %s thermal threshold!\n", + threshold_type); + netdev_warn(bp->dev, "Temperature (In Celsius), Current: %lu, threshold: %lu\n", + BNXT_EVENT_THERMAL_CURRENT_TEMP(data2), + BNXT_EVENT_THERMAL_THRESHOLD_TEMP(data2)); + bnxt_hwmon_notify_event(bp, attr); + break; + } default: netdev_err(bp->dev, "FW reported unknown error type %u\n", err_type); diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c index f5affac1169a..483571264276 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c @@ -18,6 +18,14 @@ #include "bnxt_hwrm.h" #include "bnxt_hwmon.h" +void bnxt_hwmon_notify_event(struct bnxt *bp, u32 attr) +{ + if (!bp->hwmon_dev) + return; + + hwmon_notify_event(&bp->pdev->dev, hwmon_temp, attr, 0); +} + static int bnxt_hwrm_temp_query(struct bnxt *bp, u8 *temp) { struct hwrm_temp_monitor_query_output *resp; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h index af310066687c..5cf127702764 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h @@ -11,9 +11,14 @@ #define BNXT_HWMON_H #ifdef CONFIG_BNXT_HWMON +void bnxt_hwmon_notify_event(struct bnxt *bp, u32 attr); void bnxt_hwmon_uninit(struct bnxt *bp); void bnxt_hwmon_init(struct bnxt *bp); #else +static inline void bnxt_hwmon_notify_event(struct bnxt *bp, u32 attr) +{ +} + static inline void bnxt_hwmon_uninit(struct bnxt *bp) { }