Re: [PATCH v3] platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver

2020-10-28 Thread Hans de Goede
Hi all,

On 10/28/20 12:03 PM, Hans de Goede wrote:
> Hi,
> 
> On 10/8/20 2:37 PM, Shravan Kumar Ramani wrote:
>> The performance modules in BlueField are present in several hardware
>> blocks and each block provides access to these stats either through
>> counters that can be programmed to monitor supported events or
>> through memory-mapped registers that hold the relevant information.
>> The hardware blocks that include a performance module are:
>>  * Tile (block containing 2 cores and a shared L2 cache)
>>  * TRIO (PCIe root complex)
>>  * MSS (Memory Sub-system containing the Memory Controller and L3 cache)
>>  * GIC (Interrupt controller)
>>  * SMMU (System Memory Management Unit)
>> The mlx_pmc driver provides access to all of these performance modules
>> through a hwmon sysfs interface.
> 
> Thank you for your patch, I've applied this patch to my review-hans 
> branch:
> https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
> 
> Note it will show up there once I've pushed my local branch there,
> which might take a while.
> 
> Once I've run some tests on this branch the patches there will be
> added to the platform-drivers-x86/for-next branch and eventually
> will be included in the pdx86 pull-request to Linus for the next
> merge-window.

Andy I now see that this goes under drivers/platform/mellanox and the
MAINTAINERS entry for this still points to you:

MELLANOX HARDWARE PLATFORM SUPPORT
M:  Andy Shevchenko 
M:  Darren Hart 
M:  Vadim Pasternak 
L:  platform-driver-...@vger.kernel.org
S:  Supported
F:  Documentation/ABI/testing/sysfs-platform-mellanox-bootctl
F:  drivers/platform/mellanox/
F:  include/linux/platform_data/mlxreg.h

But the patches are being send to to the
platform-driver-...@vger.kernel.org list.

Also I assume that you (Andy) do not want to maintain (another)
git tree just for the occasional melanox patch, so I'll just keep
this patch in my review-hans branch (and eventually move it
to pdx86/for-next)

I guess that we should maybe update the MAINTAINERS entry to make me +
Mark the maintainers and add a:

T:  git 
git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git

Entry ?

Regards,

Hans



>> v2 --> v3
>> Update copyright info.
>>
>> v1 --> v2
>> Remove unused headers.
>> Add comma to arrays where last line is not a termination.
>> Use kstrtoint in place of sscanf.
>> UUID manipulation follows drivers/platform/mellanox/mlxbf-bootctl.c
>>
>> Signed-off-by: Shravan Kumar Ramani 
>> Reviewed-by: Vadim Pasternak 
>> Reviewed-by: Jiri Pirko 
>> ---
>>  drivers/platform/mellanox/Kconfig |   10 +
>>  drivers/platform/mellanox/Makefile|1 +
>>  drivers/platform/mellanox/mlxbf-pmc.c | 1478 
>> +
>>  3 files changed, 1489 insertions(+)
>>  create mode 100644 drivers/platform/mellanox/mlxbf-pmc.c
>>
>> diff --git a/drivers/platform/mellanox/Kconfig 
>> b/drivers/platform/mellanox/Kconfig
>> index 916b39d..edd17e1 100644
>> --- a/drivers/platform/mellanox/Kconfig
>> +++ b/drivers/platform/mellanox/Kconfig
>> @@ -56,4 +56,14 @@ config MLXBF_BOOTCTL
>>to the userspace tools, to be used in conjunction with the eMMC
>>device driver to do necessary initial swap of the boot partition.
>>  
>> +config MLXBF_PMC
>> +tristate "Mellanox BlueField Performance Monitoring Counters driver"
>> +depends on ARM64
>> +depends on HWMON
>> +depends on ACPI
>> +help
>> +  Say y here to enable PMC support. The PMC driver provides access
>> +  to performance monitoring counters within various blocks in the
>> +  Mellanox BlueField SoC via a sysfs interface.
>> +
>>  endif # MELLANOX_PLATFORM
>> diff --git a/drivers/platform/mellanox/Makefile 
>> b/drivers/platform/mellanox/Makefile
>> index 499623c..000ddaa 100644
>> --- a/drivers/platform/mellanox/Makefile
>> +++ b/drivers/platform/mellanox/Makefile
>> @@ -4,6 +4,7 @@
>>  # Mellanox Platform-Specific Drivers
>>  #
>>  obj-$(CONFIG_MLXBF_BOOTCTL) += mlxbf-bootctl.o
>> +obj-$(CONFIG_MLXBF_PMC) += mlxbf-pmc.o
>>  obj-$(CONFIG_MLXBF_TMFIFO)  += mlxbf-tmfifo.o
>>  obj-$(CONFIG_MLXREG_HOTPLUG)+= mlxreg-hotplug.o
>>  obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
>> diff --git a/drivers/platform/mellanox/mlxbf-pmc.c 
>> b/drivers/platform/mellanox/mlxbf-pmc.c
>> new file mode 100644
>> index 000..3588398
>> --- /dev/null
>> +++ b/drivers/platform/mellanox/mlxbf-pmc.c
>> @@ -0,0 +1,1478 @@
>> +// SPDX-License-Identifier: GPL-2.0-only OR Linux-OpenIB
>> +/*
>> + * Mellanox BlueField Performance Monitoring Counters driver
>> + *
>> + * This driver provides a sysfs interface for monitoring
>> + * performance statistics in BlueField SoC.
>> + *
>> + * Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define 

Re: [PATCH v3] platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver

2020-10-28 Thread Hans de Goede
Hi,

On 10/8/20 2:37 PM, Shravan Kumar Ramani wrote:
> The performance modules in BlueField are present in several hardware
> blocks and each block provides access to these stats either through
> counters that can be programmed to monitor supported events or
> through memory-mapped registers that hold the relevant information.
> The hardware blocks that include a performance module are:
>  * Tile (block containing 2 cores and a shared L2 cache)
>  * TRIO (PCIe root complex)
>  * MSS (Memory Sub-system containing the Memory Controller and L3 cache)
>  * GIC (Interrupt controller)
>  * SMMU (System Memory Management Unit)
> The mlx_pmc driver provides access to all of these performance modules
> through a hwmon sysfs interface.

Thank you for your patch, I've applied this patch to my review-hans 
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up there once I've pushed my local branch there,
which might take a while.

Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.

Regards,

Hans




> 
> v2 --> v3
> Update copyright info.
> 
> v1 --> v2
> Remove unused headers.
> Add comma to arrays where last line is not a termination.
> Use kstrtoint in place of sscanf.
> UUID manipulation follows drivers/platform/mellanox/mlxbf-bootctl.c
> 
> Signed-off-by: Shravan Kumar Ramani 
> Reviewed-by: Vadim Pasternak 
> Reviewed-by: Jiri Pirko 
> ---
>  drivers/platform/mellanox/Kconfig |   10 +
>  drivers/platform/mellanox/Makefile|1 +
>  drivers/platform/mellanox/mlxbf-pmc.c | 1478 
> +
>  3 files changed, 1489 insertions(+)
>  create mode 100644 drivers/platform/mellanox/mlxbf-pmc.c
> 
> diff --git a/drivers/platform/mellanox/Kconfig 
> b/drivers/platform/mellanox/Kconfig
> index 916b39d..edd17e1 100644
> --- a/drivers/platform/mellanox/Kconfig
> +++ b/drivers/platform/mellanox/Kconfig
> @@ -56,4 +56,14 @@ config MLXBF_BOOTCTL
> to the userspace tools, to be used in conjunction with the eMMC
> device driver to do necessary initial swap of the boot partition.
>  
> +config MLXBF_PMC
> + tristate "Mellanox BlueField Performance Monitoring Counters driver"
> + depends on ARM64
> + depends on HWMON
> + depends on ACPI
> + help
> +   Say y here to enable PMC support. The PMC driver provides access
> +   to performance monitoring counters within various blocks in the
> +   Mellanox BlueField SoC via a sysfs interface.
> +
>  endif # MELLANOX_PLATFORM
> diff --git a/drivers/platform/mellanox/Makefile 
> b/drivers/platform/mellanox/Makefile
> index 499623c..000ddaa 100644
> --- a/drivers/platform/mellanox/Makefile
> +++ b/drivers/platform/mellanox/Makefile
> @@ -4,6 +4,7 @@
>  # Mellanox Platform-Specific Drivers
>  #
>  obj-$(CONFIG_MLXBF_BOOTCTL)  += mlxbf-bootctl.o
> +obj-$(CONFIG_MLXBF_PMC)  += mlxbf-pmc.o
>  obj-$(CONFIG_MLXBF_TMFIFO)   += mlxbf-tmfifo.o
>  obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o
>  obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
> diff --git a/drivers/platform/mellanox/mlxbf-pmc.c 
> b/drivers/platform/mellanox/mlxbf-pmc.c
> new file mode 100644
> index 000..3588398
> --- /dev/null
> +++ b/drivers/platform/mellanox/mlxbf-pmc.c
> @@ -0,0 +1,1478 @@
> +// SPDX-License-Identifier: GPL-2.0-only OR Linux-OpenIB
> +/*
> + * Mellanox BlueField Performance Monitoring Counters driver
> + *
> + * This driver provides a sysfs interface for monitoring
> + * performance statistics in BlueField SoC.
> + *
> + * Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MLXBF_PMC_WRITE_REG_32 0x8209
> +#define MLXBF_PMC_READ_REG_32 0x820A
> +#define MLXBF_PMC_WRITE_REG_64 0x820B
> +#define MLXBF_PMC_READ_REG_64 0x820C
> +#define MLXBF_PMC_SIP_SVC_UID 0x8200ff01
> +#define MLXBF_PMC_SIP_SVC_VERSION 0x8200ff03
> +#define MLXBF_PMC_SVC_REQ_MAJOR 0
> +#define MLXBF_PMC_SVC_MIN_MINOR 3
> +
> +#define MLXBF_PMC_SMCCC_ACCESS_VIOLATION -4
> +
> +#define MLXBF_PMC_EVENT_SET_BF1 0
> +#define MLXBF_PMC_EVENT_SET_BF2 1
> +#define MLXBF_PMC_EVENT_INFO_LEN 100
> +
> +#define MLXBF_PMC_MAX_BLOCKS 30
> +#define MLXBF_PMC_MAX_ATTRS 30
> +#define MLXBF_PMC_INFO_SZ 4
> +#define MLXBF_PMC_REG_SIZE 8
> +#define MLXBF_PMC_L3C_REG_SIZE 4
> +
> +#define MLXBF_PMC_TYPE_COUNTER 1
> +#define MLXBF_PMC_TYPE_REGISTER 0
> +
> +#define MLXBF_PMC_PERFCTL 0
> +#define MLXBF_PMC_PERFEVT 1
> +#define MLXBF_PMC_PERFACC0 4
> +
> +#define MLXBF_PMC_PERFMON_CONFIG_WR_R_B BIT(0)
> +#define MLXBF_PMC_PERFMON_CONFIG_STROBE BIT(1)
> +#define MLXBF_PMC_PERFMON_CONFIG_ADDR GENMASK_ULL(4, 2)
> +#define MLXBF_PMC_PERFMON_CONFIG_WDATA GENMASK_ULL(60, 5)
> +
> +#define 

[PATCH v3] platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver

2020-10-08 Thread Shravan Kumar Ramani
The performance modules in BlueField are present in several hardware
blocks and each block provides access to these stats either through
counters that can be programmed to monitor supported events or
through memory-mapped registers that hold the relevant information.
The hardware blocks that include a performance module are:
 * Tile (block containing 2 cores and a shared L2 cache)
 * TRIO (PCIe root complex)
 * MSS (Memory Sub-system containing the Memory Controller and L3 cache)
 * GIC (Interrupt controller)
 * SMMU (System Memory Management Unit)
The mlx_pmc driver provides access to all of these performance modules
through a hwmon sysfs interface.

v2 --> v3
Update copyright info.

v1 --> v2
Remove unused headers.
Add comma to arrays where last line is not a termination.
Use kstrtoint in place of sscanf.
UUID manipulation follows drivers/platform/mellanox/mlxbf-bootctl.c

Signed-off-by: Shravan Kumar Ramani 
Reviewed-by: Vadim Pasternak 
Reviewed-by: Jiri Pirko 
---
 drivers/platform/mellanox/Kconfig |   10 +
 drivers/platform/mellanox/Makefile|1 +
 drivers/platform/mellanox/mlxbf-pmc.c | 1478 +
 3 files changed, 1489 insertions(+)
 create mode 100644 drivers/platform/mellanox/mlxbf-pmc.c

diff --git a/drivers/platform/mellanox/Kconfig 
b/drivers/platform/mellanox/Kconfig
index 916b39d..edd17e1 100644
--- a/drivers/platform/mellanox/Kconfig
+++ b/drivers/platform/mellanox/Kconfig
@@ -56,4 +56,14 @@ config MLXBF_BOOTCTL
  to the userspace tools, to be used in conjunction with the eMMC
  device driver to do necessary initial swap of the boot partition.
 
+config MLXBF_PMC
+   tristate "Mellanox BlueField Performance Monitoring Counters driver"
+   depends on ARM64
+   depends on HWMON
+   depends on ACPI
+   help
+ Say y here to enable PMC support. The PMC driver provides access
+ to performance monitoring counters within various blocks in the
+ Mellanox BlueField SoC via a sysfs interface.
+
 endif # MELLANOX_PLATFORM
diff --git a/drivers/platform/mellanox/Makefile 
b/drivers/platform/mellanox/Makefile
index 499623c..000ddaa 100644
--- a/drivers/platform/mellanox/Makefile
+++ b/drivers/platform/mellanox/Makefile
@@ -4,6 +4,7 @@
 # Mellanox Platform-Specific Drivers
 #
 obj-$(CONFIG_MLXBF_BOOTCTL)+= mlxbf-bootctl.o
+obj-$(CONFIG_MLXBF_PMC)+= mlxbf-pmc.o
 obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o
 obj-$(CONFIG_MLXREG_HOTPLUG)   += mlxreg-hotplug.o
 obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
diff --git a/drivers/platform/mellanox/mlxbf-pmc.c 
b/drivers/platform/mellanox/mlxbf-pmc.c
new file mode 100644
index 000..3588398
--- /dev/null
+++ b/drivers/platform/mellanox/mlxbf-pmc.c
@@ -0,0 +1,1478 @@
+// SPDX-License-Identifier: GPL-2.0-only OR Linux-OpenIB
+/*
+ * Mellanox BlueField Performance Monitoring Counters driver
+ *
+ * This driver provides a sysfs interface for monitoring
+ * performance statistics in BlueField SoC.
+ *
+ * Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MLXBF_PMC_WRITE_REG_32 0x8209
+#define MLXBF_PMC_READ_REG_32 0x820A
+#define MLXBF_PMC_WRITE_REG_64 0x820B
+#define MLXBF_PMC_READ_REG_64 0x820C
+#define MLXBF_PMC_SIP_SVC_UID 0x8200ff01
+#define MLXBF_PMC_SIP_SVC_VERSION 0x8200ff03
+#define MLXBF_PMC_SVC_REQ_MAJOR 0
+#define MLXBF_PMC_SVC_MIN_MINOR 3
+
+#define MLXBF_PMC_SMCCC_ACCESS_VIOLATION -4
+
+#define MLXBF_PMC_EVENT_SET_BF1 0
+#define MLXBF_PMC_EVENT_SET_BF2 1
+#define MLXBF_PMC_EVENT_INFO_LEN 100
+
+#define MLXBF_PMC_MAX_BLOCKS 30
+#define MLXBF_PMC_MAX_ATTRS 30
+#define MLXBF_PMC_INFO_SZ 4
+#define MLXBF_PMC_REG_SIZE 8
+#define MLXBF_PMC_L3C_REG_SIZE 4
+
+#define MLXBF_PMC_TYPE_COUNTER 1
+#define MLXBF_PMC_TYPE_REGISTER 0
+
+#define MLXBF_PMC_PERFCTL 0
+#define MLXBF_PMC_PERFEVT 1
+#define MLXBF_PMC_PERFACC0 4
+
+#define MLXBF_PMC_PERFMON_CONFIG_WR_R_B BIT(0)
+#define MLXBF_PMC_PERFMON_CONFIG_STROBE BIT(1)
+#define MLXBF_PMC_PERFMON_CONFIG_ADDR GENMASK_ULL(4, 2)
+#define MLXBF_PMC_PERFMON_CONFIG_WDATA GENMASK_ULL(60, 5)
+
+#define MLXBF_PMC_PERFCTL_FM0 GENMASK_ULL(18, 16)
+#define MLXBF_PMC_PERFCTL_MS0 GENMASK_ULL(21, 20)
+#define MLXBF_PMC_PERFCTL_ACCM0 GENMASK_ULL(26, 24)
+#define MLXBF_PMC_PERFCTL_AD0 BIT(27)
+#define MLXBF_PMC_PERFCTL_ETRIG0 GENMASK_ULL(29, 28)
+#define MLXBF_PMC_PERFCTL_EB0 BIT(30)
+#define MLXBF_PMC_PERFCTL_EN0 BIT(31)
+
+#define MLXBF_PMC_PERFEVT_EVTSEL GENMASK_ULL(31, 24)
+
+#define MLXBF_PMC_L3C_PERF_CNT_CFG 0x0
+#define MLXBF_PMC_L3C_PERF_CNT_SEL 0x10
+#define MLXBF_PMC_L3C_PERF_CNT_SEL_1 0x14
+#define MLXBF_PMC_L3C_PERF_CNT_LOW 0x40
+#define MLXBF_PMC_L3C_PERF_CNT_HIGH 0x60
+
+#define MLXBF_PMC_L3C_PERF_CNT_CFG_EN BIT(0)
+#define MLXBF_PMC_L3C_PERF_CNT_CFG_RST BIT(1)
+#define MLXBF_PMC_L3C_PERF_CNT_SEL_CNT_0 GENMASK(5, 0)
+#define MLXBF_PMC_L3C_PERF_CNT_SEL_CNT_1 GENMASK(13, 8)