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: 13353534 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79DF4AD4C for ; Tue, 15 Aug 2023 04:57:28 +0000 (UTC) Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFD54BF for ; Mon, 14 Aug 2023 21:57:26 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-76ad842d12fso339565685a.3 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=InsOVVZt2Zof1bKZ37VujXJEzgNk/U6q/HniJDeFnGc=; b=PWtYfE2GbEn5eFkMP7sUIEEJZxQBN/HlM8EqLMYt1yyRvE3eXgbphTAysjJp6bAAt/ icpuFleMBD35TN+LS+aQPf2V/CNbl7P+mVIm74rH/c0npT61Min9zYxXJ2GybebuHarn +zoUGWdIKo7qBUKZ41tYV4+aRXlj0AXNtTHiM= 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=InsOVVZt2Zof1bKZ37VujXJEzgNk/U6q/HniJDeFnGc=; b=ZkkwLjsDDaMzohnQr8MmVajmrxJEd1lHjKM2+KDFzH2UnSP5NqOjaWLaS2qiGftnBG ScCzeUp4BqE+tBqI/01SH2vgYctsBDmD9DkC7FvYhdDSleBJYbQJB1M14YlGIe6F31HA Bnokn6rvbfRzkE+KNgEuZEQRqj5PnSqgbyKJ56CX1MiGRNScupLsHpUSoI2Uq9CWeGRw 2i7Pnfd6E/KD5F9Z1KbH6hQqmMMd5MlgxXiVgBiCCBjrPV7Myw8pW7k09pwWhG27REQY pk5GAczrl9bb3X0vQ//i1ILdVWL8vAFDk7SOxFocezvMrzEx4L3wtpn9SqaTvfYGg/Vx EyjQ== X-Gm-Message-State: AOJu0Yww7KKwhRoqMvEgdtf8qcWNcGLPWpifJjELLscAUvNP1qjCL354 or06Qvchh8/vfzlXvOwWE8zza5BchrIlWFFw2k0= 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> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@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");