sonic-buildimage/platform/mellanox/non-upstream-patches/patches/0261-mlxbf-ptm-power-and-thermal-management-debugfs-drive.patch
Vivek 342604a4bb
[mellanox] Integrate HW-MGMT Version 7.0030.2008 (#17170)
* [Mellanox] Don't populate arm64 Kconfig when integrating hw-mgmt

Signed-off-by: Vivek Reddy <vkarri@nvidia.com>

* Intgerate HW-MGMT 7.0030.2008 Changes

 ## Patch List
* 0285-UBUNTU-SAUCE-mlxbf-gige-Fix-intermittent-no-ip-issue.patch :
* 0286-pinctrl-Introduce-struct-pinfunction-and-PINCTRL_PIN.patch :
* 0287-pinctrl-mlxbf3-Add-pinctrl-driver-support.patch :
* 0288-UBUNTU-SAUCE-gpio-mmio-handle-ngpios-properly-in-bgp.patch :
* 0289-UBUNTU-SAUCE-gpio-mlxbf3-Add-gpio-driver-support.patch :
* 0291-mlxsw-core_hwmon-Align-modules-label-name-assignment.patch :
* 0292-mlxsw-i2c-Limit-single-transaction-buffer-size.patch :
* 0293-mlxsw-reg-Limit-MTBR-register-records-buffer-by-one-.patch :
* 0296-UBUNTU-SAUCE-mmc-sdhci-of-dwcmshc-Add-runtime-PM-ope.patch :
* 0298-UBUNTU-SAUCE-mlxbf-ptm-use-0444-instead-of-S_IRUGO.patch :
* 0299-UBUNTU-SAUCE-mlxbf-ptm-add-atx-debugfs-nodes.patch :
* 0300-UBUNTU-SAUCE-mlxbf-ptm-update-module-version.patch :
* 0301-UBUNTU-SAUCE-mlxbf-gige-Fix-kernel-panic-at-shutdown.patch :
* 0302-UBUNTU-SAUCE-mlxbf-bootctl-support-SMC-call-for-sett.patch :
* 0303-UBUNTU-SAUCE-Add-BF3-related-ACPI-config-and-Ring-de.patch :
* 0306-dt-bindings-trivial-devices-Add-infineon-xdpe1a2g7.patch :
* 0307-leds-mlxreg-Add-support-for-new-flavour-of-capabilit.patch :
* 0308-leds-mlxreg-Remove-code-for-amber-LED-colour.patch :
* 0308-platform_data-mlxreg-Add-capability-bit-and-mask-fie.patch :
* 0309-hwmon-mlxreg-fan-Add-support-for-new-flavour-of-capa.patch :
* 0310-hwmon-mlxreg-fan-Extend-number-of-supporetd-fans.patch :
* 0317-platform-mellanox-Introduce-support-for-switches-equ.patch :
* 0318-mellanox-Relocate-mlx-platform-driver.patch :
* 0319-UBUNTU-SAUCE-mlxbf-tmfifo-fix-potential-race.patch :
* 0320-UBUNTU-SAUCE-mlxbf-tmfifo-Drop-the-Rx-packet-if-no-m.patch :
* 0321-UBUNTU-SAUCE-mlxbf-tmfifo-Drop-jumbo-frames.patch :
* 0322-UBUNTU-SAUCE-mlxbf-tmfifo.c-Amend-previous-tmfifo-pa.patch :
* 0323-mlxbf_gige-add-set_link_ksettings-ethtool-callback.patch :
* 0324-mlxbf_gige-fix-white-space-in-mlxbf_gige_eth_ioctl.patch :
* 0325-UBUNTU-SAUCE-mlxbf-bootctl-Fix-kernel-panic-due-to-b.patch :
* 0326-platform-mellanox-mlxreg-hotplug-Add-support-for-new.patch :
* 0327-platform-mellanox-mlx-platform-Change-register-name.patch :
* 0328-platform-mellanox-mlx-platform-Add-support-for-new-X.patch :

* [Mellanox] Remove thermal zone related code and replace with new one

* Revert "Revert "[Mellanox] Align PSU temperature sysfs node name with hw-management change (#16820)" (#16956)"

This reverts commit c2edc6f9d5.

---------

Signed-off-by: Vivek Reddy <vkarri@nvidia.com>
Co-authored-by: Junchao-Mellanox <junchao@nvidia.com>
Co-authored-by: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com>
2023-11-16 22:49:29 +08:00

257 lines
7.5 KiB
Diff

From 1193879b92e665c100056085385ffdb4ab2715cb Mon Sep 17 00:00:00 2001
From: Jitendra Lanka <jlanka@nvidia.com>
Date: Fri, 13 Jan 2023 15:21:02 -0500
Subject: [PATCH backport 5.10 2/6] mlxbf-ptm: power and thermal management
debugfs driver
mlxbf-ptm driver implements debugfs interface for Bluefield
devices power and thermal management. It provides some parameters
that can be monitored by system software.
Change-Id: I241e1406962548cef9b33c4b3dea925e675c3c88
Signed-off-by: Jitendra Lanka <jlanka@nvidia.com>
---
drivers/platform/mellanox/Kconfig | 10 ++
drivers/platform/mellanox/Makefile | 1 +
drivers/platform/mellanox/mlxbf-ptm.c | 195 ++++++++++++++++++++++++++
3 files changed, 206 insertions(+)
create mode 100644 drivers/platform/mellanox/mlxbf-ptm.c
diff --git a/drivers/platform/mellanox/Kconfig b/drivers/platform/mellanox/Kconfig
index a5231c23a..48bd61f61 100644
--- a/drivers/platform/mellanox/Kconfig
+++ b/drivers/platform/mellanox/Kconfig
@@ -106,6 +106,16 @@ config MLXBF_TRIO
This driver supports the TRIO PCIe root complex interface on
Mellanox BlueField SoCs.
+config MLXBF_PTM
+ tristate "BlueField Power and Thermal Management debugfs interface"
+ depends on ARM64
+ depends on DEBUG_FS
+ help
+ If you say yes to this option, support will be added for the
+ mlxbf-ptm driver. This driver provides debugfs interface
+ to userspace with information related to power and thermal
+ management of the Bluefield device.
+
source "drivers/platform/mellanox/mlxbf_pka/Kconfig"
config NVSW_SN2201
diff --git a/drivers/platform/mellanox/Makefile b/drivers/platform/mellanox/Makefile
index 7a4b90ed5..d30483021 100644
--- a/drivers/platform/mellanox/Makefile
+++ b/drivers/platform/mellanox/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_MLXBF_PMC) += mlxbf-pmc.o
obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o
obj-$(CONFIG_MLXBF_TRIO) += mlx-trio.o
obj-$(CONFIG_MLXBF_LIVEFISH) += mlxbf-livefish.o
+obj-$(CONFIG_MLXBF_PTM) += mlxbf-ptm.o
obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o
obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
obj-$(CONFIG_MLXBF_PKA) += mlxbf_pka/
diff --git a/drivers/platform/mellanox/mlxbf-ptm.c b/drivers/platform/mellanox/mlxbf-ptm.c
new file mode 100644
index 000000000..307ba1f33
--- /dev/null
+++ b/drivers/platform/mellanox/mlxbf-ptm.c
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
+/*
+ * Copyright (C) 2023 NVIDIA Corporation & Affiliates.
+ *
+ * Nvidia Bluefield power and thermal debugfs driver
+ * This driver provides a debugfs interface for systems management
+ * software to monitor power and thermal actions.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/debugfs.h>
+#include <linux/module.h>
+#include <linux/arm-smccc.h>
+
+/* SMC IDs */
+#define MLNX_PTM_GET_VR0_POWER 0x82000101
+#define MLNX_PTM_GET_VR1_POWER 0x82000102
+#define MLNX_PTM_GET_THROTTLE_STATE 0x82000103
+#define MLNX_PTM_GET_DDR_THLD 0x82000104
+#define MLNX_PTM_GET_STATUS_REG 0x82000105
+#define MLNX_PTM_GET_PTHROTTLE 0x82000106
+#define MLNX_PTM_GET_TTHROTTLE 0x82000107
+#define MLNX_PTM_GET_MAX_TEMP 0x82000108
+#define MLNX_PTM_GET_PWR_EVT_CNT 0x82000109
+#define MLNX_PTM_GET_TEMP_EVT_CNT 0x8200010A
+
+#define MLNX_POWER_ERROR 300
+
+struct dentry *monitors;
+
+static int smc_call1(unsigned int smc_op, int smc_arg)
+{
+ struct arm_smccc_res res;
+
+ arm_smccc_smc(smc_op, smc_arg, 0, 0, 0, 0, 0, 0, &res);
+
+ return res.a0;
+}
+
+#define smc_call0(smc_op) smc_call1(smc_op, 0)
+
+static int throttling_state_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_THROTTLE_STATE);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(throttling_state_fops,
+ throttling_state_show, NULL, "%llu\n");
+
+static int pthrottling_state_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_PTHROTTLE);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(pthrottling_state_fops,
+ pthrottling_state_show, NULL, "%llu\n");
+
+static int tthrottling_state_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_TTHROTTLE);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(tthrottling_state_fops,
+ tthrottling_state_show, NULL, "%llu\n");
+
+static int core_temp_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_MAX_TEMP);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(core_temp_fops,
+ core_temp_show, NULL, "%lld\n");
+
+static int pwr_evt_counter_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_PWR_EVT_CNT);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(pwr_evt_counter_fops,
+ pwr_evt_counter_show, NULL, "%llu\n");
+
+static int temp_evt_counter_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_TEMP_EVT_CNT);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(temp_evt_counter_fops,
+ temp_evt_counter_show, NULL, "%llu\n");
+
+static int vr0_power_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_VR0_POWER);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(vr0_power_fops, vr0_power_show, NULL, "%llu\n");
+
+static int vr1_power_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_VR1_POWER);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(vr1_power_fops, vr1_power_show, NULL, "%llu\n");
+
+static int total_power_show(void *data, u64 *val)
+{
+ u64 v0, v1;
+
+ v0 = smc_call0(MLNX_PTM_GET_VR0_POWER);
+ if (v0 > MLNX_POWER_ERROR)
+ v0 = 0;
+ v1 = smc_call0(MLNX_PTM_GET_VR1_POWER);
+ if (v1 > MLNX_POWER_ERROR)
+ v1 = 0;
+ *val = (v0 + v1);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(total_power_fops, total_power_show, NULL, "%llu\n");
+
+static int ddr_thld_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_DDR_THLD);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(ddr_thld_fops, ddr_thld_show, NULL, "%llu\n");
+
+static int error_status_show(void *data, u64 *val)
+{
+ *val = smc_call0(MLNX_PTM_GET_STATUS_REG);
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(error_status_fops,
+ error_status_show, NULL, "%llu\n");
+
+
+static int __init mlxbf_ptm_init(void)
+{
+ struct dentry *ptm_root, *status;
+
+ ptm_root = debugfs_lookup("mlxbf-ptm", NULL);
+ if (!ptm_root)
+ ptm_root = debugfs_create_dir("mlxbf-ptm", NULL);
+
+ monitors = debugfs_create_dir("monitors", ptm_root);
+ status = debugfs_create_dir("status", monitors);
+
+ debugfs_create_file("vr0_power", S_IRUGO, status, NULL,
+ &vr0_power_fops);
+ debugfs_create_file("vr1_power", S_IRUGO, status, NULL,
+ &vr1_power_fops);
+ debugfs_create_file("total_power", S_IRUGO, status, NULL,
+ &total_power_fops);
+ debugfs_create_file("ddr_temp", S_IRUGO, status,
+ NULL, &ddr_thld_fops);
+ debugfs_create_file("core_temp", S_IRUGO, status,
+ NULL, &core_temp_fops);
+ debugfs_create_file("power_throttling_event_count", S_IRUGO, status,
+ NULL, &pwr_evt_counter_fops);
+ debugfs_create_file("thermal_throttling_event_count", S_IRUGO, status,
+ NULL, &temp_evt_counter_fops);
+ debugfs_create_file("throttling_state", S_IRUGO, status,
+ NULL, &throttling_state_fops);
+ debugfs_create_file("power_throttling_state", S_IRUGO, status,
+ NULL, &pthrottling_state_fops);
+ debugfs_create_file("thermal_throttling_state", S_IRUGO, status,
+ NULL, &tthrottling_state_fops);
+ debugfs_create_file("error_state", S_IRUGO, status,
+ NULL, &error_status_fops);
+
+ return 0;
+}
+
+static void __exit mlxbf_ptm_exit(void)
+{
+ debugfs_remove_recursive(monitors);
+}
+
+module_init(mlxbf_ptm_init);
+module_exit(mlxbf_ptm_exit);
+
+MODULE_AUTHOR("Jitendra Lanka <jlanka@nvidia.com>");
+MODULE_DESCRIPTION("Nvidia Bluefield power and thermal debugfs driver");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_VERSION("1.0");
--
2.20.1