Skip to contentSkip to conversation

add new features for FPGA DFL drivers

PATCH Superseded Wu Hao 5 participants 63 messages Mar 25, 2019 – Apr 17, 2019

Subsystems (4)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Wu Hao

author
#0 lore raw

cover add new features for FPGA DFL drivers

This patchset adds more features support for FPGA Device Feature List (DFL) drivers, including PR enhancement, virtualization support based on PCIe SRIOV, private features to Port, private features to FME, and enhancement to DFL framework. Please refer to details in below list.

Patch 1: A bug fixing to current dfl-fme-mgr driver.
Patch 2-3: add 512bit data width PR support.
Patch 4-6: add virtualization support based on PCIe SRIOV. Patch 7-8: add new AFU state and userclock related sysfs to dfl-afu. Patch 9-10: enhancement to DFL framework in order to support id_table. Patch 11: add error reporting private feature support to dfl-afu. Patch 12: add STP (SignalTap) private feature support to dfl-afu. Patch 13: add capability sysfs interfaces to dfl-fme.
Patch 14: add thermal management private feature support to dfl-fme. Patch 15: add power management private feature support to dfl-fme. Patch 16: add global error reporitng private feature support to dfl-fme. Patch 17: add performance reporting support to dfl-fme.

Wu Hao (17):
fpga: dfl-fme-mgr: fix FME_PR_INTFC_ID register address.
fpga: dfl: fme: align PR buffer size per PR datawidth
fpga: dfl: fme: support 512bit data width PR
Documentation: fpga: dfl: add descriptions for virtualization and new
interfaces.
fpga: dfl: fme: add DFL_FPGA_FME_PORT_RELEASE/ASSIGN ioctl support.
fpga: dfl: pci: enable SRIOV support.
fpga: dfl: afu: add AFU state related sysfs interfaces
fpga: dfl: afu: add userclock sysfs interfaces.
fpga: dfl: add id_table for dfl private feature driver
fpga: dfl: afu: export __port_enable/disable function.
fpga: dfl: afu: add error reporting support.
fpga: dfl: afu: add STP (SignalTap) support
fpga: dfl: fme: add capability sysfs interfaces
fpga: dfl: fme: add thermal management support
fpga: dfl: fme: add power management support
fpga: dfl: fme: add global error reporting support
fpga: dfl: fme: add performance reporting support

 Documentation/ABI/testing/sysfs-platform-dfl-fme  | 279 +++++++
 Documentation/ABI/testing/sysfs-platform-dfl-port |  94 +++
 Documentation/fpga/dfl.txt                        | 115 +++
 drivers/fpga/Makefile                             |   4 +-
 drivers/fpga/dfl-afu-error.c                      | 225 +++++
 drivers/fpga/dfl-afu-main.c                       | 335 +++++++-
 drivers/fpga/dfl-afu.h                            |   7 +
 drivers/fpga/dfl-fme-error.c                      | 390 +++++++++
 drivers/fpga/dfl-fme-main.c                       | 583 ++++++++++++-
 drivers/fpga/dfl-fme-mgr.c                        |  79 +-
 drivers/fpga/dfl-fme-perf.c                       | 950 ++++++++++++++++++++++
 drivers/fpga/dfl-fme-pr.c                         |  64 +-
 drivers/fpga/dfl-fme.h                            |   9 +-
 drivers/fpga/dfl-pci.c                            |  40 +
 drivers/fpga/dfl.c                                | 170 +++-
 drivers/fpga/dfl.h                                |  56 +-
 include/uapi/linux/fpga-dfl.h                     |  32 +
 17 files changed, 3355 insertions(+), 77 deletions(-)
 create mode 100644 drivers/fpga/dfl-afu-error.c
 create mode 100644 drivers/fpga/dfl-fme-error.c
 create mode 100644 drivers/fpga/dfl-fme-perf.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/17 fpga: dfl-fme-mgr: fix FME_PR_INTFC_ID register address.

FME_PR_INTFC_ID is used as compat_id for fpga manager and region, but high 64 bits and low 64 bits of the compat_id are swapped by mistake. This patch fixes this problem by fixing register address.

---
 drivers/fpga/dfl-fme-mgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/fpga/dfl-fme-mgr.c +2 -2
index 76f3770..b3f7eee 100644
@@ -30,8 +30,8 @@
 #define FME_PR_STS		0x10
 #define FME_PR_DATA		0x18
 #define FME_PR_ERR		0x20
-#define FME_PR_INTFC_ID_H	0xA8
-#define FME_PR_INTFC_ID_L	0xB0
+#define FME_PR_INTFC_ID_L	0xA8
+#define FME_PR_INTFC_ID_H	0xB0
 
 /* FME PR Control Register Bitfield */
 #define FME_PR_CTRL_PR_RST	BIT_ULL(0)  /* Reset PR engine */
Signature · 1 line
2.7.4
Acked-by on v1 1/17
#2 lore raw

Re: [PATCH 01/17] fpga: dfl-fme-mgr: fix FME_PR_INTFC_ID register address.

On Sun, Mar 24, 2019 at 10:23 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 6 lines

FME_PR_INTFC_ID is used as compat_id for fpga manager and region, but high 64 bits and low 64 bits of the compat_id are swapped by mistake. This patch fixes this problem by fixing register address.

Thanks,
Alan

Quoted 22 lines
---
 drivers/fpga/dfl-fme-mgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/fpga/dfl-fme-mgr.c +2 -3
index 76f3770..b3f7eee 100644
@@ -30,8 +30,8 @@
 #define FME_PR_STS             0x10
 #define FME_PR_DATA            0x18
 #define FME_PR_ERR             0x20
-#define FME_PR_INTFC_ID_H      0xA8
-#define FME_PR_INTFC_ID_L      0xB0
+#define FME_PR_INTFC_ID_L      0xA8
+#define FME_PR_INTFC_ID_H      0xB0
 
 /* FME PR Control Register Bitfield */
 #define FME_PR_CTRL_PR_RST     BIT_ULL(0)  /* Reset PR engine */
--

2.7.4

maintainer
#3 lore raw

Re: [PATCH 01/17] fpga: dfl-fme-mgr: fix FME_PR_INTFC_ID register address.

In reply to Wu Hao

Hi Wu,

Quoted 14 lines · Wu Hao

FME_PR_INTFC_ID is used as compat_id for fpga manager and region, but high 64 bits and low 64 bits of the compat_id are swapped by mistake. This patch fixes this problem by fixing register address.

---
 drivers/fpga/dfl-fme-mgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/fpga/dfl-fme-mgr.c +0 -0
index 76f3770..b3f7eee 100644

drivers/fpga/dfl-fme-mgr.c line 34

Quoted 7 lines
drivers/fpga/dfl-fme-mgr.c +2 -2
@@ -30,8 +30,8 @@
 #define FME_PR_STS		0x10
 #define FME_PR_DATA		0x18
 #define FME_PR_ERR		0x20
-#define FME_PR_INTFC_ID_H	0xA8
-#define FME_PR_INTFC_ID_L	0xB0
+#define FME_PR_INTFC_ID_L	0xA8
+#define FME_PR_INTFC_ID_H	0xB0

Does this handle endianess correct?

Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c +0 -0
 /* FME PR Control Register Bitfield */
 #define FME_PR_CTRL_PR_RST	BIT_ULL(0)  /* Reset PR engine */
Signature · 1 line
2.7.4

Cheers,
Moritz

author
#4 lore raw

Re: [PATCH 01/17] fpga: dfl-fme-mgr: fix FME_PR_INTFC_ID register address.

Quoted 12 lines · Moritz Fischer

Hi Wu,

Quoted 9 lines · Wu Hao

FME_PR_INTFC_ID is used as compat_id for fpga manager and region, but high 64 bits and low 64 bits of the compat_id are swapped by mistake. This patch fixes this problem by fixing register address.

---
 drivers/fpga/dfl-fme-mgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

drivers/fpga/dfl-fme-mgr.c line 34

Quoted 12 lines
drivers/fpga/dfl-fme-mgr.c +2 -2
index 76f3770..b3f7eee 100644
@@ -30,8 +30,8 @@
 #define FME_PR_STS		0x10
 #define FME_PR_DATA		0x18
 #define FME_PR_ERR		0x20
-#define FME_PR_INTFC_ID_H	0xA8
-#define FME_PR_INTFC_ID_L	0xB0
+#define FME_PR_INTFC_ID_L	0xA8
+#define FME_PR_INTFC_ID_H	0xB0

Does this handle endianess correct?

Hi Moritz,

This is just a bug fixing for wrong offsets given to these 2 registers according to spec. I think this is not endianess related, and per my understanding we don't need more code on endianess handling as that should be done inside the readq function already. :)

Thanks
Hao

maintainer Acked-by
#5 lore raw

Re: [PATCH 01/17] fpga: dfl-fme-mgr: fix FME_PR_INTFC_ID register address.

Hi Wu,

Quoted 9 lines · Wu Hao
Quoted 8 lines · Moritz Fischer

Hi Wu,

Quoted 5 lines · Wu Hao

FME_PR_INTFC_ID is used as compat_id for fpga manager and region, but high 64 bits and low 64 bits of the compat_id are swapped by mistake. This patch fixes this problem by fixing register address.

Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
---
 drivers/fpga/dfl-fme-mgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

drivers/fpga/dfl-fme-mgr.c line 34

Quoted 12 lines
drivers/fpga/dfl-fme-mgr.c +2 -2
index 76f3770..b3f7eee 100644
@@ -30,8 +30,8 @@
 #define FME_PR_STS		0x10
 #define FME_PR_DATA		0x18
 #define FME_PR_ERR		0x20
-#define FME_PR_INTFC_ID_H	0xA8
-#define FME_PR_INTFC_ID_L	0xB0
+#define FME_PR_INTFC_ID_L	0xA8
+#define FME_PR_INTFC_ID_H	0xB0

Does this handle endianess correct?

Hi Moritz,

Quoted 7 lines

This is just a bug fixing for wrong offsets given to these 2 registers according to spec. I think this is not endianess related, and per my understanding we don't need more code on endianess handling as that should be done inside the readq function already. :)

Thanks
Hao

Thanks for clarifying,

Moritz

author
#6 lore raw

PATCH 2/17 fpga: dfl: fme: align PR buffer size per PR datawidth

In reply to Wu Hao

Current driver checks if input bitstream file size is aligned or not per PR data width (default 32bits). It requires one additional step for end user when they generate the bitstream file, padding extra zeros to bitstream file to align its size per PR data width, but they don't have to as hardware will drop extra padding bytes automatically.

In order to simplify the user steps, this patch aligns PR buffer size per PR data width in driver, to allow user to pass unaligned size bitstream files to driver.

---
 drivers/fpga/dfl-fme-pr.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/fpga/dfl-fme-pr.c +9 -5
index d9ca955..c1fb1fe 100644
@@ -74,6 +74,7 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
 	struct dfl_fme *fme;
 	unsigned long minsz;
 	void *buf = NULL;
+	size_t length;
 	int ret = 0;
 	u64 v;
 
@@ -85,9 +86,6 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
 	if (port_pr.argsz < minsz || port_pr.flags)
 		return -EINVAL;
 
-	if (!IS_ALIGNED(port_pr.buffer_size, 4))
-		return -EINVAL;
-
 	/* get fme header region */
 	fme_hdr = dfl_get_feature_ioaddr_by_id(&pdev->dev,
 					       FME_FEATURE_ID_HEADER);
@@ -103,7 +101,13 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
 		       port_pr.buffer_size))
 		return -EFAULT;
 
-	buf = vmalloc(port_pr.buffer_size);
+	/*
+	 * align PR buffer per PR bandwidth, as HW ignores the extra padding
+	 * data automatically.
+	 */
+	length = ALIGN(port_pr.buffer_size, 4);
+
+	buf = vmalloc(length);
 	if (!buf)
 		return -ENOMEM;
 
@@ -140,7 +144,7 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
 	fpga_image_info_free(region->info);
 
 	info->buf = buf;
-	info->count = port_pr.buffer_size;
+	info->count = length;
 	info->region_id = port_pr.port_id;
 	region->info = info;
 
Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH 02/17] fpga: dfl: fme: align PR buffer size per PR datawidth

On Sun, Mar 24, 2019 at 10:23 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Looks good, one question below.

Quoted 42 lines

Current driver checks if input bitstream file size is aligned or not per PR data width (default 32bits). It requires one additional step for end user when they generate the bitstream file, padding extra zeros to bitstream file to align its size per PR data width, but they don't have to as hardware will drop extra padding bytes automatically.

In order to simplify the user steps, this patch aligns PR buffer size per PR data width in driver, to allow user to pass unaligned size bitstream files to driver.

---
 drivers/fpga/dfl-fme-pr.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/fpga/dfl-fme-pr.c +1 -3
index d9ca955..c1fb1fe 100644
@@ -74,6 +74,7 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
        struct dfl_fme *fme;
        unsigned long minsz;
        void *buf = NULL;
+       size_t length;
        int ret = 0;
        u64 v;
 
@@ -85,9 +86,6 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
        if (port_pr.argsz < minsz || port_pr.flags)
                return -EINVAL;
 
-       if (!IS_ALIGNED(port_pr.buffer_size, 4))
-               return -EINVAL;
-
        /* get fme header region */
        fme_hdr = dfl_get_feature_ioaddr_by_id(&pdev->dev,
                                               FME_FEATURE_ID_HEADER);
@@ -103,7 +101,13 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
                       port_pr.buffer_size))

drivers/fpga/dfl-fme-pr.c static int fme_pr(struct platform_device *pdev, unsigned long arg) · line 110

Quoted 10 lines
drivers/fpga/dfl-fme-pr.c +7 -1
                return -EFAULT;
 
-       buf = vmalloc(port_pr.buffer_size);
+       /*
+        * align PR buffer per PR bandwidth, as HW ignores the extra padding
+        * data automatically.
+        */
+       length = ALIGN(port_pr.buffer_size, 4);
+
+       buf = vmalloc(length);

Since it may not be completely filled, would it be worthwhile to alloc a zero'ed buff?

Alan

Quoted 15 lines
drivers/fpga/dfl-fme-pr.c +1 -2
        if (!buf)
                return -ENOMEM;
 
@@ -140,7 +144,7 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
        fpga_image_info_free(region->info);
 
        info->buf = buf;
-       info->count = port_pr.buffer_size;
+       info->count = length;
        info->region_id = port_pr.port_id;
        region->info = info;
 
--

2.7.4

author
#8 lore raw

Re: [PATCH 02/17] fpga: dfl: fme: align PR buffer size per PR datawidth

Quoted 50 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:23 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Looks good, one question below.

Quoted 44 lines

Current driver checks if input bitstream file size is aligned or not per PR data width (default 32bits). It requires one additional step for end user when they generate the bitstream file, padding extra zeros to bitstream file to align its size per PR data width, but they don't have to as hardware will drop extra padding bytes automatically.

In order to simplify the user steps, this patch aligns PR buffer size per PR data width in driver, to allow user to pass unaligned size bitstream files to driver.

---
 drivers/fpga/dfl-fme-pr.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/fpga/dfl-fme-pr.c +1 -3
index d9ca955..c1fb1fe 100644
@@ -74,6 +74,7 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
        struct dfl_fme *fme;
        unsigned long minsz;
        void *buf = NULL;
+       size_t length;
        int ret = 0;
        u64 v;
 
@@ -85,9 +86,6 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
        if (port_pr.argsz < minsz || port_pr.flags)
                return -EINVAL;
 
-       if (!IS_ALIGNED(port_pr.buffer_size, 4))
-               return -EINVAL;
-
        /* get fme header region */
        fme_hdr = dfl_get_feature_ioaddr_by_id(&pdev->dev,
                                               FME_FEATURE_ID_HEADER);
@@ -103,7 +101,13 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)
                       port_pr.buffer_size))
                return -EFAULT;
 
Quoted 12 lines

drivers/fpga/dfl-fme-pr.c static int fme_pr(struct platform_device *pdev, unsigned long arg) · line 110

Quoted 8 lines
drivers/fpga/dfl-fme-pr.c +7 -1
-       buf = vmalloc(port_pr.buffer_size);
+       /*
+        * align PR buffer per PR bandwidth, as HW ignores the extra padding
+        * data automatically.
+        */
+       length = ALIGN(port_pr.buffer_size, 4);
+
+       buf = vmalloc(length);

Since it may not be completely filled, would it be worthwhile to alloc a zero'ed buff?

Hi Alan,

Thanks for the review, acutally per spec, hw doesn't care about the extra padding data. So for now, i guess we don't need this.

Thanks
Hao

Quoted 2 lines

Alan

Acked-by
#9 lore raw

Re: [PATCH 02/17] fpga: dfl: fme: align PR buffer size per PR datawidth

Quoted 16 lines · Wu Hao
Quoted 14 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:23 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Looks good, one question below.

Quoted 8 lines

Current driver checks if input bitstream file size is aligned or not per PR data width (default 32bits). It requires one additional step for end user when they generate the bitstream file, padding extra zeros to bitstream file to align its size per PR data width, but they don't have to as hardware will drop extra padding bytes automatically.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

In order to simplify the user steps, this patch aligns PR buffer size per PR data width in driver, to allow user to pass unaligned size bitstream files to driver.

Thanks,
Alan

author
#10 lore raw

PATCH 3/17 fpga: dfl: fme: support 512bit data width PR

In reply to Wu Hao

In early partial reconfiguration private feature, it only supports 32bit data width when writing data to hardware for PR. 512bit data width PR support is an important optimization for some specific solutions (e.g. XEON with FPGA integrated), it allows driver to use AVX512 instruction to improve the performance of partial reconfiguration. e.g. programming one 100MB bitstream image via this 512bit data width PR hardware only takes ~300ms, but 32bit revision requires ~3s per test result.

Please note now this optimization is only done on revision 2 of this PR private feature which is only used in integrated solution that AVX512 is always supported.

---
 drivers/fpga/dfl-fme-main.c |  3 ++
 drivers/fpga/dfl-fme-mgr.c  | 75 +++++++++++++++++++++++++++++++++++++--------
 drivers/fpga/dfl-fme-pr.c   | 45 ++++++++++++++++-----------
 drivers/fpga/dfl-fme.h      |  2 ++
 drivers/fpga/dfl.h          |  5 +++
 5 files changed, 99 insertions(+), 31 deletions(-)
drivers/fpga/dfl-fme-main.c +3 -0
index 086ad24..076d74f 100644
@@ -21,6 +21,8 @@
 #include "dfl.h"
 #include "dfl-fme.h"
 
+#define DRV_VERSION	"0.8"
+
 static ssize_t ports_num_show(struct device *dev,
 			      struct device_attribute *attr, char *buf)
 {
@@ -277,3 +279,4 @@ MODULE_DESCRIPTION("FPGA Management Engine driver");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL v2");
 MODULE_ALIAS("platform:dfl-fme");
+MODULE_VERSION(DRV_VERSION);
drivers/fpga/dfl-fme-mgr.c +62 -13

137 lines not on this page · raw message

drivers/fpga/dfl-fme-pr.c +27 -18

86 lines not on this page · raw message

drivers/fpga/dfl-fme.h +2 -0
index 5394a21..de20755 100644
@@ -21,12 +21,14 @@
 /**
  * struct dfl_fme - dfl fme private data
  *
+ * @pr_datawidth: data width for partial reconfiguration.
  * @mgr: FME's FPGA manager platform device.
  * @region_list: linked list of FME's FPGA regions.
  * @bridge_list: linked list of FME's FPGA bridges.
  * @pdata: fme platform device's pdata.
  */
 struct dfl_fme {
+	int pr_datawidth;
 	struct platform_device *mgr;
 	struct list_head region_list;
 	struct list_head bridge_list;
drivers/fpga/dfl.h +5 -0
index a8b869e..8851c6c 100644
@@ -331,6 +331,11 @@ static inline bool dfl_feature_is_port(void __iomem *base)
 		(FIELD_GET(DFH_ID, v) == DFH_ID_FIU_PORT);
 }
 
+static inline u8 dfl_feature_revision(void __iomem *base)
+{
+	return (u8)FIELD_GET(DFH_REVISION, readq(base + DFH));
+}
+
 /**
  * struct dfl_fpga_enum_info - DFL FPGA enumeration information
  *
Signature · 1 line
2.7.4
Acked-by on v1 3/17
#11 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

On Sun, Mar 24, 2019 at 10:23 PM Wu Hao <[email protected]> wrote:

Hi Hao,

This looks fine.

Quoted 11 lines

In early partial reconfiguration private feature, it only supports 32bit data width when writing data to hardware for PR. 512bit data width PR support is an important optimization for some specific solutions (e.g. XEON with FPGA integrated), it allows driver to use AVX512 instruction to improve the performance of partial reconfiguration. e.g. programming one 100MB bitstream image via this 512bit data width PR hardware only takes ~300ms, but 32bit revision requires ~3s per test result.

Quoted 7 lines

Please note now this optimization is only done on revision 2 of this PR private feature which is only used in integrated solution that AVX512 is always supported.

#12 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

In reply to Wu Hao
Quoted 31 lines · Wu Hao

In early partial reconfiguration private feature, it only supports 32bit data width when writing data to hardware for PR. 512bit data width PR support is an important optimization for some specific solutions (e.g. XEON with FPGA integrated), it allows driver to use AVX512 instruction to improve the performance of partial reconfiguration. e.g. programming one 100MB bitstream image via this 512bit data width PR hardware only takes ~300ms, but 32bit revision requires ~3s per test result.

Please note now this optimization is only done on revision 2 of this PR private feature which is only used in integrated solution that AVX512 is always supported.

---
 drivers/fpga/dfl-fme-main.c |  3 ++
 drivers/fpga/dfl-fme-mgr.c  | 75 +++++++++++++++++++++++++++++++++++++---
-----
 drivers/fpga/dfl-fme-pr.c   | 45 ++++++++++++++++-----------
 drivers/fpga/dfl-fme.h      |  2 ++
 drivers/fpga/dfl.h          |  5 +++
 5 files changed, 99 insertions(+), 31 deletions(-)
drivers/fpga/dfl-fme-main.c +0 -0
index 086ad24..076d74f 100644

drivers/fpga/dfl-fme-main.c line 24

Quoted 4 lines
drivers/fpga/dfl-fme-main.c +1 -0
@@ -21,6 +21,8 @@
 #include "dfl.h"
 #include "dfl-fme.h"
 
+#define DRV_VERSION	"0.8"

What is this going to be used for? Under what circumstances will the driver version be bumped? What does it have to do with 512-bit writes?

Quoted 5 lines
drivers/fpga/dfl-fme-main.c +5 -0
+#if defined(CONFIG_X86) && defined(CONFIG_AS_AVX512)
+
+#include <asm/fpu/api.h>
+
+static inline void copy512(void *src, void __iomem *dst)

drivers/fpga/dfl-fme-main.c

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+{
+	kernel_fpu_begin();
+
+	asm volatile("vmovdqu64 (%0), %%zmm0;"
+		     "vmovntdq %%zmm0, (%1);"
+		     :
+		     : "r"(src), "r"(dst));
+
+	kernel_fpu_end();
+}

Shouldn't there be some sort of check that AVX512 is actually supported on the running system?

Also, src should be const, and the asm statement should have a memory clobber.

drivers/fpga/dfl-fme-main.c

Quoted 6 lines
drivers/fpga/dfl-fme-main.c +6 -0
+#else
+static inline void copy512(void *src, void __iomem *dst)
+{
+	WARN_ON_ONCE(1);
+}
+#endif

Likewise, this will be called if a revision 2 device is used on non-x86 (or on x86 with an old binutils). The driver should fall back to 32-bit in such cases.

drivers/fpga/dfl-fme-main.c static int fme_mgr_write(struct fpga_manager *mgr, · line 234

Quoted 9 lines
drivers/fpga/dfl-fme-main.c +1 -1
@@ -200,21 +228,32 @@ static int fme_mgr_write(struct fpga_manager *mgr,
 			pr_credit = FIELD_GET(FME_PR_STS_PR_CREDIT,
 pr_status);
 		}
 
-		if (count < 4) {
+		if (count < priv->pr_datawidth) {
 			dev_err(dev, "Invalid PR bitstream size\n");
 			return -EINVAL;

Shouldn't this have become a WARN_ON in patch 2 given that the kernel already pads the buffer?

drivers/fpga/dfl-fme-main.c static int fme_mgr_write(struct fpga_manager *mgr, · line 241

Quoted 12 lines
drivers/fpga/dfl-fme-main.c +5 -5
 		}
 
-		pr_data = 0;
-		pr_data |= FIELD_PREP(FME_PR_DATA_PR_DATA_RAW,
-				      *(((u32 *)buf) + i));
-		writeq(pr_data, fme_pr + FME_PR_DATA);
-		count -= 4;
+		switch (priv->pr_datawidth) {
+		case 4:
+			pr_data = 0;
+			pr_data |= FIELD_PREP(FME_PR_DATA_PR_DATA_RAW,
+					*((u32 *)buf));

I know it's not new, but why not just "pr_data = FIELD..."? Const should also be preserved in the cast, and you can drop one set of parentheses.

drivers/fpga/dfl-fme-main.c static int fme_mgr_write(struct fpga_manager *mgr, · line 246

Quoted 5 lines
drivers/fpga/dfl-fme-main.c +5 -0
+			writeq(pr_data, fme_pr + FME_PR_DATA);
+			break;
+		case 64:
+			copy512((void *)buf, fme_pr + FME_PR_512_DATA);
+			break;

Unnecessary cast.

drivers/fpga/dfl-fme-main.c static int fme_mgr_write(struct fpga_manager *mgr, · line 249

Quoted 3 lines
drivers/fpga/dfl-fme-main.c +3 -0
+		default:
+			ret = -EFAULT;
+			goto done;

How is it EFAULT? Any other value for pr_datawidth should be WARN_ON since it's set by kernel code.

drivers/fpga/dfl-fme-main.c static int fme_pr(struct platform_device *pdev, · line 169

Quoted 12 lines
drivers/fpga/dfl-fme-main.c +0 -5
@@ -159,13 +161,10 @@ static int fme_pr(struct platform_device *pdev,
 unsigned long arg)
 		fpga_bridges_put(&region->bridge_list);
 
 	put_device(&region->dev);
-unlock_exit:
-	mutex_unlock(&pdata->lock);
 free_exit:
 	vfree(buf);
-	if (copy_to_user((void __user *)arg, &port_pr, minsz))
-		return -EFAULT;
-

Why is the copy_to_user being removed?

-Scott

#13 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

Quoted 63 lines · Scott Wood
Quoted 32 lines · Wu Hao

In early partial reconfiguration private feature, it only supports 32bit data width when writing data to hardware for PR. 512bit data width PR support is an important optimization for some specific solutions (e.g. XEON with FPGA integrated), it allows driver to use AVX512 instruction to improve the performance of partial reconfiguration. e.g. programming one 100MB bitstream image via this 512bit data width PR hardware only takes ~300ms, but 32bit revision requires ~3s per test result.

Please note now this optimization is only done on revision 2 of this PR private feature which is only used in integrated solution that AVX512 is always supported.

---
 drivers/fpga/dfl-fme-main.c |  3 ++
 drivers/fpga/dfl-fme-mgr.c  | 75 +++++++++++++++++++++++++++++++++++++-
--
-----
 drivers/fpga/dfl-fme-pr.c   | 45 ++++++++++++++++-----------
 drivers/fpga/dfl-fme.h      |  2 ++
 drivers/fpga/dfl.h          |  5 +++
 5 files changed, 99 insertions(+), 31 deletions(-)
drivers/fpga/dfl-fme-main.c +0 -0
index 086ad24..076d74f 100644

drivers/fpga/dfl-fme-main.c line 24

Quoted 4 lines
drivers/fpga/dfl-fme-main.c +1 -0
@@ -21,6 +21,8 @@
 #include "dfl.h"
 #include "dfl-fme.h"
 
+#define DRV_VERSION	"0.8"

What is this going to be used for? Under what circumstances will the driver version be bumped? What does it have to do with 512-bit writes?

Quoted 5 lines
drivers/fpga/dfl-fme-main.c +5 -0
+#if defined(CONFIG_X86) && defined(CONFIG_AS_AVX512)
+
+#include <asm/fpu/api.h>
+
+static inline void copy512(void *src, void __iomem *dst)

drivers/fpga/dfl-fme-main.c

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+{
+	kernel_fpu_begin();
+
+	asm volatile("vmovdqu64 (%0), %%zmm0;"
+		     "vmovntdq %%zmm0, (%1);"
+		     :
+		     : "r"(src), "r"(dst));
+
+	kernel_fpu_end();
+}

Shouldn't there be some sort of check that AVX512 is actually supported on the running system?

Also, src should be const, and the asm statement should have a memory clobber.

Quoted 10 lines

drivers/fpga/dfl-fme-main.c

Quoted 6 lines
drivers/fpga/dfl-fme-main.c +6 -0
+#else
+static inline void copy512(void *src, void __iomem *dst)
+{
+	WARN_ON_ONCE(1);
+}
+#endif

Likewise, this will be called if a revision 2 device is used on non-x86 (or on x86 with an old binutils). The driver should fall back to 32-bit in such cases.

Sorry, I missed the comment about revision 2 only being on integrated devices -- but will that always be the case? Seems worthwhile to check for AVX512 support anyway. And there's still the possibility of being built with an old binutils such that CONFIG_AS_AVX512 is not set, or running on a kernel where avx512 was disabled via a boot option.

What about future revisions >= 2? Currently the driver will treat them as if they were revision < 2. Is that intended?

-Scott

#14 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

On Mon, Mar 25, 2019 at 5:58 PM Scott Wood <[email protected]> wrote:

Hi Scott,

Quoted 76 lines · Scott Wood
Quoted 63 lines · Wu Hao
Quoted 32 lines

In early partial reconfiguration private feature, it only supports 32bit data width when writing data to hardware for PR. 512bit data width PR support is an important optimization for some specific solutions (e.g. XEON with FPGA integrated), it allows driver to use AVX512 instruction to improve the performance of partial reconfiguration. e.g. programming one 100MB bitstream image via this 512bit data width PR hardware only takes ~300ms, but 32bit revision requires ~3s per test result.

Please note now this optimization is only done on revision 2 of this PR private feature which is only used in integrated solution that AVX512 is always supported.

---
 drivers/fpga/dfl-fme-main.c |  3 ++
 drivers/fpga/dfl-fme-mgr.c  | 75 +++++++++++++++++++++++++++++++++++++-
--
-----
 drivers/fpga/dfl-fme-pr.c   | 45 ++++++++++++++++-----------
 drivers/fpga/dfl-fme.h      |  2 ++
 drivers/fpga/dfl.h          |  5 +++
 5 files changed, 99 insertions(+), 31 deletions(-)
drivers/fpga/dfl-fme-main.c +0 -0
index 086ad24..076d74f 100644

drivers/fpga/dfl-fme-main.c line 24

Quoted 4 lines
drivers/fpga/dfl-fme-main.c +1 -0
@@ -21,6 +21,8 @@
 #include "dfl.h"
 #include "dfl-fme.h"
 
+#define DRV_VERSION        "0.8"

What is this going to be used for? Under what circumstances will the driver version be bumped? What does it have to do with 512-bit writes?

Quoted 5 lines
drivers/fpga/dfl-fme-main.c +5 -0
+#if defined(CONFIG_X86) && defined(CONFIG_AS_AVX512)
+
+#include <asm/fpu/api.h>
+
+static inline void copy512(void *src, void __iomem *dst)

drivers/fpga/dfl-fme-main.c

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+{
+   kernel_fpu_begin();
+
+   asm volatile("vmovdqu64 (%0), %%zmm0;"
+                "vmovntdq %%zmm0, (%1);"
+                :
+                : "r"(src), "r"(dst));
+
+   kernel_fpu_end();
+}

Shouldn't there be some sort of check that AVX512 is actually supported on the running system?

Also, src should be const, and the asm statement should have a memory clobber.

Quoted 10 lines

drivers/fpga/dfl-fme-main.c

Quoted 6 lines
drivers/fpga/dfl-fme-main.c +6 -0
+#else
+static inline void copy512(void *src, void __iomem *dst)
+{
+   WARN_ON_ONCE(1);
+}
+#endif

Likewise, this will be called if a revision 2 device is used on non-x86 (or on x86 with an old binutils). The driver should fall back to 32-bit in such cases.

Quoted 5 lines

Sorry, I missed the comment about revision 2 only being on integrated devices -- but will that always be the case? Seems worthwhile to check for AVX512 support anyway. And there's still the possibility of being built with an old binutils such that CONFIG_AS_AVX512 is not set, or running on a kernel where avx512 was disabled via a boot option.

The code checks for CONFIG_AS_AVX512 above.

What boot option are you referring to?

Alan

Quoted 7 lines

What about future revisions >= 2? Currently the driver will treat them as if they were revision < 2. Is that intended?

-Scott

#15 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

Quoted 50 lines · Alan Tull

On Mon, Mar 25, 2019 at 5:58 PM Scott Wood <[email protected]> wrote:

Hi Scott,

Quoted 38 lines · Scott Wood
Quoted 24 lines · Wu Hao
Quoted 5 lines
drivers/fpga/dfl-fme-mgr.c +5 -0
+#if defined(CONFIG_X86) && defined(CONFIG_AS_AVX512)
+
+#include <asm/fpu/api.h>
+
+static inline void copy512(void *src, void __iomem *dst)

drivers/fpga/dfl-fme-mgr.c line 88

Quoted 10 lines
drivers/fpga/dfl-fme-mgr.c +10 -0
+{
+   kernel_fpu_begin();
+
+   asm volatile("vmovdqu64 (%0), %%zmm0;"
+                "vmovntdq %%zmm0, (%1);"
+                :
+                : "r"(src), "r"(dst));
+
+   kernel_fpu_end();
+}

Shouldn't there be some sort of check that AVX512 is actually supported
on the running system?

Also, src should be const, and the asm statement should have a memory clobber.

Quoted 12 lines

drivers/fpga/dfl-fme-mgr.c line 94

Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c +6 -0
+#else
+static inline void copy512(void *src, void __iomem *dst)
+{
+   WARN_ON_ONCE(1);
+}
+#endif

Likewise, this will be called if a revision 2 device is used on non- x86
(or on x86 with an old binutils). The driver should fall back to 32- bit
in such cases.

Quoted 7 lines

Sorry, I missed the comment about revision 2 only being on integrated devices -- but will that always be the case? Seems worthwhile to check for
AVX512 support anyway. And there's still the possibility of being built with an old binutils such that CONFIG_AS_AVX512 is not set, or running on a
kernel where avx512 was disabled via a boot option.

Quoted 1 line

The code checks for CONFIG_AS_AVX512 above.

That just indicates that binutils supports it. Plus, the code does not check for CONFIG_AS_AVX512 when deciding whether to set pr_datawidth to 64 (and thus call copy512), so you'll get a WARN_ON rather than falling back to 32-bit.

Quoted 1 line

What boot option are you referring to?

clearcpuid=304

-Scott

author
#16 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

Quoted 27 lines · Scott Wood
Quoted 26 lines · Alan Tull

On Mon, Mar 25, 2019 at 5:58 PM Scott Wood <[email protected]> wrote:

Hi Scott,

Quoted 22 lines · Scott Wood
Quoted 21 lines · Wu Hao
Quoted 5 lines
drivers/fpga/dfl-fme-mgr.c +5 -0
+#if defined(CONFIG_X86) && defined(CONFIG_AS_AVX512)
+
+#include <asm/fpu/api.h>
+
+static inline void copy512(void *src, void __iomem *dst)

drivers/fpga/dfl-fme-mgr.c line 88

Quoted 10 lines
drivers/fpga/dfl-fme-mgr.c +10 -0
+{
+   kernel_fpu_begin();
+
+   asm volatile("vmovdqu64 (%0), %%zmm0;"
+                "vmovntdq %%zmm0, (%1);"
+                :
+                : "r"(src), "r"(dst));
+
+   kernel_fpu_end();
+}

Shouldn't there be some sort of check that AVX512 is actually supported
on the running system?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Also, src should be const, and the asm statement should have a memory clobber.

Yes, I will fix this in the next version.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

drivers/fpga/dfl-fme-mgr.c line 94

Quoted 7 lines
drivers/fpga/dfl-fme-mgr.c +6 -0
+#else
+static inline void copy512(void *src, void __iomem *dst)
+{
+   WARN_ON_ONCE(1);
+}
+#endif

Likewise, this will be called if a revision 2 device is used on non- x86
(or on x86 with an old binutils). The driver should fall back to 32- bit
in such cases.

Unfortunately revision 2 is only for integrated FPGA solution, and it doesn't support any fallback solution (original 32bit data partial reconfiguration is not supported any more), so driver has to WARN in such path.

Quoted 11 lines
Quoted 10 lines
Quoted 8 lines

Sorry, I missed the comment about revision 2 only being on integrated devices -- but will that always be the case? Seems worthwhile to check for
AVX512 support anyway. And there's still the possibility of being built with an old binutils such that CONFIG_AS_AVX512 is not set, or running on a
kernel where avx512 was disabled via a boot option.

The code checks for CONFIG_AS_AVX512 above.

Quoted 8 lines

That just indicates that binutils supports it. Plus, the code does not check for CONFIG_AS_AVX512 when deciding whether to set pr_datawidth to 64 (and thus call copy512), so you'll get a WARN_ON rather than falling back to 32-bit.

Quoted 1 line

What boot option are you referring to?

clearcpuid=304

Just tried it, my system was down after running above AVX512 with this option.

I agree that it needs to add some check code to make sure it's safe to run such instructions. I will add some cpu_feature_enabled() check in the next version.

Thanks a lot for the review and comments.

Hao

Quoted 3 lines

-Scott

#17 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

Quoted 7 lines · Wu Hao
Quoted 6 lines · Scott Wood
Quoted 5 lines · Alan Tull
Quoted 1 line · Scott Wood
Quoted 1 line

Hi Scott,

Quoted 1 line · Scott Wood
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Wu Hao

drivers/fpga/dfl-fme-mgr.c line 94

Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c +6 -0
+#else
+static inline void copy512(void *src, void __iomem *dst)
+{
+   WARN_ON_ONCE(1);
+}
+#endif

Likewise, this will be called if a revision 2 device is used on non-

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

x86
(or on x86 with an old binutils). The driver should fall back to 32-
bit
in such cases.

Quoted 7 lines

Unfortunately revision 2 is only for integrated FPGA solution, and it doesn't
support any fallback solution (original 32bit data partial reconfiguration is
not supported any more), so driver has to WARN in such path.

From the commit message it seemed like this was just an optimization, not

something necessary to support revision 2.

If there's no way to program the device without AVX512, then printing an error message and returning an error to userspace would be better than WARN_ON, since it's not actually a kernel bug.

-Scott

author
#18 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

Quoted 29 lines · Scott Wood
Quoted 7 lines · Wu Hao
Quoted 6 lines · Scott Wood
Quoted 5 lines · Alan Tull
Quoted 1 line · Scott Wood
Quoted 1 line

Hi Scott,

Quoted 1 line · Scott Wood
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Wu Hao

Review

Quoted 6 lines
(quoted diff) +6 -0
+#else
+static inline void copy512(void *src, void __iomem *dst)
+{
+   WARN_ON_ONCE(1);
+}
+#endif

Likewise, this will be called if a revision 2 device is used on non-

Quoted 11 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

x86
(or on x86 with an old binutils). The driver should fall back to 32-
bit
in such cases.

Unfortunately revision 2 is only for integrated FPGA solution, and it doesn't
support any fallback solution (original 32bit data partial reconfiguration is
not supported any more), so driver has to WARN in such path.

Quoted 6 lines
Quoted 1 line

From the commit message it seemed like this was just an optimization, not

something necessary to support revision 2.

If there's no way to program the device without AVX512, then printing an error message and returning an error to userspace would be better than WARN_ON, since it's not actually a kernel bug.

Fair enough. Will do. Thanks for the suggestion.

Hao

Quoted 3 lines

-Scott

author
#19 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

In reply to Scott Wood
Quoted 37 lines · Scott Wood
Quoted 36 lines · Scott Wood
Quoted 35 lines · Wu Hao

In early partial reconfiguration private feature, it only supports 32bit data width when writing data to hardware for PR. 512bit data width PR support is an important optimization for some specific solutions (e.g. XEON with FPGA integrated), it allows driver to use AVX512 instruction to improve the performance of partial reconfiguration. e.g. programming one 100MB bitstream image via this 512bit data width PR hardware only takes ~300ms, but 32bit revision requires ~3s per test result.

Please note now this optimization is only done on revision 2 of this PR private feature which is only used in integrated solution that AVX512 is always supported.

---
 drivers/fpga/dfl-fme-main.c |  3 ++
 drivers/fpga/dfl-fme-mgr.c  | 75 +++++++++++++++++++++++++++++++++++++-
--
-----
 drivers/fpga/dfl-fme-pr.c   | 45 ++++++++++++++++-----------
 drivers/fpga/dfl-fme.h      |  2 ++
 drivers/fpga/dfl.h          |  5 +++
 5 files changed, 99 insertions(+), 31 deletions(-)
drivers/fpga/dfl-fme-main.c +0 -0
index 086ad24..076d74f 100644
@@ -21,6 +21,8 @@
 #include "dfl.h"
 #include "dfl-fme.h"
 
Quoted 4 lines
Quoted 4 lines

drivers/fpga/dfl-fme-main.c line 24

Quoted 1 line
drivers/fpga/dfl-fme-main.c +1 -0
+#define DRV_VERSION	"0.8"

What is this going to be used for? Under what circumstances will the driver version be bumped? What does it have to do with 512-bit writes?

This patchset adds more features to this driver, so i would like to add a DRV_VERSION there as an initial one. In the future, if some new features or extensions for existing features (e.g. new revision of a private feature) are added we need to bump this version.

Quoted 34 lines
Quoted 23 lines
Quoted 6 lines
drivers/fpga/dfl-fme-main.c +5 -0
+#if defined(CONFIG_X86) && defined(CONFIG_AS_AVX512)
+
+#include <asm/fpu/api.h>
+
+static inline void copy512(void *src, void __iomem *dst)

drivers/fpga/dfl-fme-main.c

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+{
+	kernel_fpu_begin();
+
+	asm volatile("vmovdqu64 (%0), %%zmm0;"
+		     "vmovntdq %%zmm0, (%1);"
+		     :
+		     : "r"(src), "r"(dst));
+
+	kernel_fpu_end();
+}

Shouldn't there be some sort of check that AVX512 is actually supported on the running system?

Also, src should be const, and the asm statement should have a memory clobber.

Quoted 10 lines

drivers/fpga/dfl-fme-main.c

Quoted 6 lines
drivers/fpga/dfl-fme-main.c +6 -0
+#else
+static inline void copy512(void *src, void __iomem *dst)
+{
+	WARN_ON_ONCE(1);
+}
+#endif

Likewise, this will be called if a revision 2 device is used on non-x86 (or on x86 with an old binutils). The driver should fall back to 32-bit in such cases.

Quoted 8 lines

Sorry, I missed the comment about revision 2 only being on integrated devices -- but will that always be the case? Seems worthwhile to check for AVX512 support anyway. And there's still the possibility of being built with an old binutils such that CONFIG_AS_AVX512 is not set, or running on a kernel where avx512 was disabled via a boot option.

What about future revisions >= 2? Currently the driver will treat them as if they were revision < 2. Is that intended?

Yes, it's intended. Currently we don't have any hardware with revisions > 2, and support new revisions may need new code. :) e.g. currently revision is used to tell 32bit vs 512bit PR, but in future revisions, it may have new capability registers for this purpose.

Thanks
Hao

Quoted 3 lines

-Scott

#20 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

Quoted 46 lines · Wu Hao
Quoted 39 lines · Scott Wood
Quoted 38 lines · Scott Wood
Quoted 37 lines · Wu Hao

In early partial reconfiguration private feature, it only supports 32bit data width when writing data to hardware for PR. 512bit data width PR support is an important optimization for some specific solutions (e.g. XEON with FPGA integrated), it allows driver to use AVX512 instruction to improve the performance of partial reconfiguration. e.g. programming one 100MB bitstream image via this 512bit data width PR hardware only takes ~300ms, but 32bit revision requires ~3s per test result.

Please note now this optimization is only done on revision 2 of this PR private feature which is only used in integrated solution that AVX512 is always supported.

---
 drivers/fpga/dfl-fme-main.c |  3 ++
 drivers/fpga/dfl-fme-mgr.c  | 75
+++++++++++++++++++++++++++++++++++++-
--
-----
 drivers/fpga/dfl-fme-pr.c   | 45 ++++++++++++++++-----------
 drivers/fpga/dfl-fme.h      |  2 ++
 drivers/fpga/dfl.h          |  5 +++
 5 files changed, 99 insertions(+), 31 deletions(-)
drivers/fpga/dfl-fme- renamed from drivers/fpga/dfl-fme-main.c +0 -0

main.c
index 086ad24..076d74f 100644

drivers/fpga/dfl-fme-main.c +0 -0
@@ -21,6 +21,8 @@
 #include "dfl.h"
 #include "dfl-fme.h"
 
Quoted 5 lines
Quoted 5 lines

drivers/fpga/dfl-fme-main.c line 24

Quoted 1 line
drivers/fpga/dfl-fme-main.c +1 -0
+#define DRV_VERSION	"0.8"

What is this going to be used for? Under what circumstances will the driver version be bumped? What does it have to do with 512-bit writes?

Quoted 5 lines

This patchset adds more features to this driver, so i would like to add a DRV_VERSION there as an initial one. In the future, if some new features or extensions for existing features (e.g. new revision of a private feature)
are added we need to bump this version.

This doesn't seem like a good way of advertising API availability... Besides being awkward to query, what happens if a distro kernel has backported some features but not others that came before? What does it advertise?

I'd suggest some sort of feature flag mechanism that can be queried via ioctl (e.g. along the lines of KVM capabilities), if "try the API and fall back if it fails" is unsatisfactory.

Plus, if it's about new APIs being exposed, this doesn't seem like the right patch for it to be in...

Quoted 12 lines
Quoted 11 lines

Sorry, I missed the comment about revision 2 only being on integrated devices -- but will that always be the case? Seems worthwhile to check for
AVX512 support anyway. And there's still the possibility of being built with an old binutils such that CONFIG_AS_AVX512 is not set, or running on a
kernel where avx512 was disabled via a boot option.

What about future revisions >= 2? Currently the driver will treat them as
if they were revision < 2. Is that intended?

Quoted 6 lines

Yes, it's intended. Currently we don't have any hardware with revisions > 2,
and support new revisions may need new code. :) e.g. currently revision is
used to tell 32bit vs 512bit PR, but in future revisions, it may have new capability registers for this purpose.

The driver should refuse to bind to unrecognized revisions, if they're not expected to be compatible.

-Scott

author
#21 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

Quoted 53 lines · Scott Wood
Quoted 46 lines · Wu Hao
Quoted 39 lines · Scott Wood
Quoted 38 lines · Scott Wood
Quoted 37 lines · Wu Hao

In early partial reconfiguration private feature, it only supports 32bit data width when writing data to hardware for PR. 512bit data width PR support is an important optimization for some specific solutions (e.g. XEON with FPGA integrated), it allows driver to use AVX512 instruction to improve the performance of partial reconfiguration. e.g. programming one 100MB bitstream image via this 512bit data width PR hardware only takes ~300ms, but 32bit revision requires ~3s per test result.

Please note now this optimization is only done on revision 2 of this PR private feature which is only used in integrated solution that AVX512 is always supported.

---
 drivers/fpga/dfl-fme-main.c |  3 ++
 drivers/fpga/dfl-fme-mgr.c  | 75
+++++++++++++++++++++++++++++++++++++-
--
-----
 drivers/fpga/dfl-fme-pr.c   | 45 ++++++++++++++++-----------
 drivers/fpga/dfl-fme.h      |  2 ++
 drivers/fpga/dfl.h          |  5 +++
 5 files changed, 99 insertions(+), 31 deletions(-)
drivers/fpga/dfl-fme- renamed from drivers/fpga/dfl-fme-main.c +0 -0

main.c
index 086ad24..076d74f 100644

drivers/fpga/dfl-fme-main.c +0 -0
@@ -21,6 +21,8 @@
 #include "dfl.h"
 #include "dfl-fme.h"
 
Quoted 5 lines
Quoted 5 lines

drivers/fpga/dfl-fme-main.c line 24

Quoted 1 line
drivers/fpga/dfl-fme-main.c +1 -0
+#define DRV_VERSION	"0.8"

What is this going to be used for? Under what circumstances will the driver version be bumped? What does it have to do with 512-bit writes?

Quoted 5 lines

This patchset adds more features to this driver, so i would like to add a DRV_VERSION there as an initial one. In the future, if some new features or extensions for existing features (e.g. new revision of a private feature)
are added we need to bump this version.

Quoted 3 lines

This doesn't seem like a good way of advertising API availability... Besides being awkward to query, what happens if a distro kernel has backported some features but not others that came before? What does it advertise?

DRV_VERSION here is not used for API availablity. :)

Quoted 6 lines

I'd suggest some sort of feature flag mechanism that can be queried via ioctl (e.g. along the lines of KVM capabilities), if "try the API and fall back if it fails" is unsatisfactory.

Plus, if it's about new APIs being exposed, this doesn't seem like the right patch for it to be in...

Actually this patch doesn't introduce new APIs, I am trying to make this transparent to endusers. That means users don't need to know it's a 32bit PR or a faster 512bit one, they still use the same IOCTL interface for PR.

the API_VERSION and CHECK_EXTENSION ioctls have been defined, but I think at least we don't need to bump them for this change. How do you think?

Quoted 20 lines
Quoted 13 lines
Quoted 9 lines

Sorry, I missed the comment about revision 2 only being on integrated devices -- but will that always be the case? Seems worthwhile to check for
AVX512 support anyway. And there's still the possibility of being built with an old binutils such that CONFIG_AS_AVX512 is not set, or running on a
kernel where avx512 was disabled via a boot option.

Quoted 3 lines

What about future revisions >= 2? Currently the driver will treat them as
if they were revision < 2. Is that intended?

Quoted 6 lines

Yes, it's intended. Currently we don't have any hardware with revisions > 2,
and support new revisions may need new code. :) e.g. currently revision is
used to tell 32bit vs 512bit PR, but in future revisions, it may have new capability registers for this purpose.

Quoted 2 lines

The driver should refuse to bind to unrecognized revisions, if they're not expected to be compatible.

Yes, agree.

Thanks
Hao

author
#22 lore raw

Re: [PATCH 03/17] fpga: dfl: fme: support 512bit data width PR

In reply to Scott Wood
Quoted 6 lines · Scott Wood
Quoted 5 lines · Wu Hao
(quoted diff) +0 -0
@@ -200,21 +228,32 @@ static int fme_mgr_write(struct fpga_manager *mgr,
 			pr_credit = FIELD_GET(FME_PR_STS_PR_CREDIT,
 pr_status);
 		}
 
Quoted 7 lines

drivers/fpga/dfl-fme-mgr.c static int fme_mgr_write(struct fpga_manager *mgr, · line 233

Quoted 4 lines
drivers/fpga/dfl-fme-mgr.c +1 -1
-		if (count < 4) {
+		if (count < priv->pr_datawidth) {
 			dev_err(dev, "Invalid PR bitstream size\n");
 			return -EINVAL;

Shouldn't this have become a WARN_ON in patch 2 given that the kernel already pads the buffer?

Thanks a lot for the review and comments.

I agree. it's better to use WARN_ON this place.

Quoted 16 lines

drivers/fpga/dfl-fme-mgr.c static int fme_mgr_write(struct fpga_manager *mgr, · line 240

Quoted 13 lines
drivers/fpga/dfl-fme-mgr.c +5 -5
 		}
 
-		pr_data = 0;
-		pr_data |= FIELD_PREP(FME_PR_DATA_PR_DATA_RAW,
-				      *(((u32 *)buf) + i));
-		writeq(pr_data, fme_pr + FME_PR_DATA);
-		count -= 4;
+		switch (priv->pr_datawidth) {
+		case 4:
+			pr_data = 0;
+			pr_data |= FIELD_PREP(FME_PR_DATA_PR_DATA_RAW,
+					*((u32 *)buf));

I know it's not new, but why not just "pr_data = FIELD..."? Const should also be preserved in the cast, and you can drop one set of parentheses.

Yes, agree, will fix this.

Quoted 8 lines

drivers/fpga/dfl-fme-mgr.c static int fme_mgr_write(struct fpga_manager *mgr, · line 245

Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c +5 -0
+			writeq(pr_data, fme_pr + FME_PR_DATA);
+			break;
+		case 64:
+			copy512((void *)buf, fme_pr + FME_PR_512_DATA);
+			break;

Unnecessary cast.

Will fix this.

Quoted 7 lines

drivers/fpga/dfl-fme-mgr.c static int fme_mgr_write(struct fpga_manager *mgr, · line 248

Quoted 4 lines
drivers/fpga/dfl-fme-mgr.c +3 -0
+		default:
+			ret = -EFAULT;
+			goto done;

How is it EFAULT? Any other value for pr_datawidth should be WARN_ON since it's set by kernel code.

Agree, will fix this in the next version.

Quoted 5 lines
Quoted 5 lines
drivers/fpga/dfl-fme-pr.c +0 -0
@@ -159,13 +161,10 @@ static int fme_pr(struct platform_device *pdev,
 unsigned long arg)
 		fpga_bridges_put(&region->bridge_list);
 
Quoted 10 lines

drivers/fpga/dfl-fme-pr.c static int fme_pr(struct platform_device *pdev, unsigned long arg) · line 168

Quoted 8 lines
drivers/fpga/dfl-fme-pr.c +0 -5
 	put_device(&region->dev);
-unlock_exit:
-	mutex_unlock(&pdata->lock);
 free_exit:
 	vfree(buf);
-	if (copy_to_user((void __user *)arg, &port_pr, minsz))
-		return -EFAULT;
-

Why is the copy_to_user being removed?

This code is not needed at all but added by mistake i think.

Sorry, i should move these code into a separated patch with proper comments to avoid confusion.

Thanks
Hao

Quoted 2 lines

-Scott

author
#23 lore raw

PATCH 4/17 Documentation: fpga: dfl: add descriptions for virtualization and new interfaces.

In reply to Wu Hao

This patch adds virtualization support description for DFL based FPGA devices (based on PCIe SRIOV), and introductions to new interfaces added by new dfl private features.

---
 Documentation/fpga/dfl.txt | 115 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)
Documentation/fpga/dfl.txt +115 -0
index 6df4621..360c1d9 100644
@@ -84,6 +84,8 @@ The following functions are exposed through ioctls:
  Get driver API version (DFL_FPGA_GET_API_VERSION)
  Check for extensions (DFL_FPGA_CHECK_EXTENSION)
  Program bitstream (DFL_FPGA_FME_PORT_PR)
+ Assign port to PF (DFL_FPGA_FME_PORT_ASSIGN)
+ Release port from PF (DFL_FPGA_FME_PORT_RELEASE)
 
 More functions are exposed through sysfs
 (/sys/class/fpga_region/regionX/dfl-fme.n/):
@@ -99,6 +101,24 @@ More functions are exposed through sysfs
      one FPGA device may have more than one port, this sysfs interface indicates
      how many ports the FPGA device has.
 
+ Power management (power_mgmt/)
+     power management sysfs interfaces allow user to read power management
+     information (power consumption, power limits, throttling thresholds,
+     thresholds status, etc) and configure power thresholds for different
+     throttling levels.
+
+ Thermal management (thermal_mgmt/)
+     thermal management sysfs interfaces allow user to read temperature,
+     thresholds, thresholds status and other thermal related information.
+
+ Global error reporting management (errors/)
+     error reporting sysfs interfaces allow user to read errors detected by the
+     hardware, and clear the logged errors.
+
+ Performance counters (perf/)
+     performance counters sysfs interfaces allow user to use different counters
+     to get performance data.
+
 
 FIU - PORT
 ==========
@@ -139,6 +159,10 @@ More functions are exposed through sysfs:
  Read Accelerator GUID (afu_id)
      afu_id indicates which PR bitstream is programmed to this AFU.
 
+ Error reporting (errors/)
+     error reporting sysfs interfaces allow user to read port/afu errors
+     detected by the hardware, and clear the logged errors.
+
 
 DFL Framework Overview
 ======================
@@ -212,6 +236,97 @@ the compat_id exposed by the target FPGA region. This check is usually done by
 userspace before calling the reconfiguration IOCTL.
 
 
+FPGA virtualization - PCIe SRIOV
+================================
+This section describes the virtualization support on DFL based FPGA device to
+enable accessing an accelerator from applications running in a virtual machine
+(VM). This section only describes the PCIe based FPGA device with SRIOV support.
+
+Features supported by the particular FPGA device are exposed through Device
+Feature Lists, as illustrated below:
+
+  +-------------------------------+  +-------------+
+  |              PF               |  |     VF      |
+  +-------------------------------+  +-------------+
+      ^            ^         ^              ^
+      |            |         |              |
++-----|------------|---------|--------------|-------+
+|     |            |         |              |       |
+|  +-----+     +-------+ +-------+      +-------+   |
+|  | FME |     | Port0 | | Port1 |      | Port2 |   |
+|  +-----+     +-------+ +-------+      +-------+   |
+|                  ^         ^              ^       |
+|                  |         |              |       |
+|              +-------+ +------+       +-------+   |
+|              |  AFU  | |  AFU |       |  AFU  |   |
+|              +-------+ +------+       +-------+   |
+|                                                   |
+|            DFL based FPGA PCIe Device             |
++---------------------------------------------------+
+
+FME is always accessed through the physical function (PF).
+
+Ports (and related AFUs) are accessed via PF by default, but could be exposed
+through virtual function (VF) devices via PCIe SRIOV. Each VF only contains
+1 Port and 1 AFU for isolation. Users could assign individual VFs (accelerators)
+created via PCIe SRIOV interface, to virtual machines.
+
+The driver organization in virtualization case is illustrated below:
+
+  +-------++------++------+             |
+  | FME   || FME  || FME  |             |
+  | FPGA  || FPGA || FPGA |             |
+  |Manager||Bridge||Region|             |
+  +-------++------++------+             |
+  +-----------------------+  +--------+ |             +--------+
+  |          FME          |  |  AFU   | |             |  AFU   |
+  |         Module        |  | Module | |             | Module |
+  +-----------------------+  +--------+ |             +--------+
+        +-----------------------+       |       +-----------------------+
+        | FPGA Container Device |       |       | FPGA Container Device |
+        |  (FPGA Base Region)   |       |       |  (FPGA Base Region)   |
+        +-----------------------+       |       +-----------------------+
+          +------------------+          |         +------------------+
+          | FPGA PCIE Module |          | Virtual | FPGA PCIE Module |
+          +------------------+   Host   | Machine +------------------+
+ -------------------------------------- | ------------------------------
+           +---------------+            |          +---------------+
+           | PCI PF Device |            |          | PCI VF Device |
+           +---------------+            |          +---------------+
+
+FPGA PCIe device driver is always loaded first once a FPGA PCIe PF or VF device
+is detected. It:
+
+	a) finish enumeration on both FPGA PCIe PF and VF device using common
+	   interfaces from DFL framework.
+	b) supports SRIOV.
+
+The FME device driver plays a management role in this driver architecture, it
+provides ioctls to release Port from PF and assign Port to PF. After release
+a port from PF, then it's safe to expose this port through a VF via PCIe SRIOV
+sysfs interface.
+
+To enable accessing an accelerator from applications running in a VM, the
+respective AFU's port needs to be assigned to a VF using the following steps:
+
+	a) The PF owns all AFU ports by default. Any port that needs to be
+	   reassigned to a VF must first be released through the
+	   DFL_FPGA_FME_PORT_RELEASE ioctl on the FME device.
+
+	b) Once N ports are released from PF, then user can use command below
+	   to enable SRIOV and VFs. Each VF owns only one Port with AFU.
+
+	   echo N > $PCI_DEVICE_PATH/sriov_numvfs
+
+	c) Pass through the VFs to VMs
+
+	d) The AFU under VF is accessible from applications in VM (using the
+	   same driver inside the VF).
+
+Note that an FME can't be assigned to a VF, thus PR and other management
+functions are only available via the PF.
+
+
 Device enumeration
 ==================
 This section introduces how applications enumerate the fpga device from
Signature · 1 line
2.7.4
author
#24 lore raw

PATCH 5/17 fpga: dfl: fme: add DFL_FPGA_FME_PORT_RELEASE/ASSIGN ioctl support.

In reply to Wu Hao

In order to support virtualization usage via PCIe SRIOV, this patch adds two ioctls under FPGA Management Engine (FME) to release and assign back the port device. In order to safely turn Port from PF into VF and enable PCIe SRIOV, it requires user to invoke this PORT_RELEASE ioctl to release port firstly to remove userspace interfaces, and then configure the PF/VF access register in FME. After disable SRIOV, it requires user to invoke this PORT_ASSIGN ioctl to attach the port back to PF.

Ioctl interfaces:
* DFL_FPGA_FME_PORT_RELEASE
Release platform device of given port, it deletes port platform device to remove related userspace interfaces on PF, then configures PF/VF access mode to VF.

* DFL_FPGA_FME_PORT_ASSIGN
Assign platform device of given port back to PF, it configures PF/VF access mode to PF, then adds port platform device back to re-enable related userspace interfaces on PF.

---
 drivers/fpga/dfl-fme-main.c   |  54 +++++++++++++++++++++
 drivers/fpga/dfl.c            | 107 +++++++++++++++++++++++++++++++++++++-----
 drivers/fpga/dfl.h            |  10 ++++
 include/uapi/linux/fpga-dfl.h |  32 +++++++++++++
 4 files changed, 191 insertions(+), 12 deletions(-)
drivers/fpga/dfl-fme-main.c +54 -0
index 076d74f..8b2a337 100644
@@ -16,6 +16,7 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/uaccess.h>
 #include <linux/fpga-dfl.h>
 
 #include "dfl.h"
@@ -105,9 +106,62 @@ static void fme_hdr_uinit(struct platform_device *pdev,
 	sysfs_remove_files(&pdev->dev.kobj, fme_hdr_attrs);
 }
 
+static long fme_hdr_ioctl_release_port(struct dfl_feature_platform_data *pdata,
+				       void __user *arg)
+{
+	struct dfl_fpga_cdev *cdev = pdata->dfl_cdev;
+	struct dfl_fpga_fme_port_release release;
+	unsigned long minsz;
+
+	minsz = offsetofend(struct dfl_fpga_fme_port_release, port_id);
+
+	if (copy_from_user(&release, arg, minsz))
+		return -EFAULT;
+
+	if (release.argsz < minsz || release.flags)
+		return -EINVAL;
+
+	return dfl_fpga_cdev_config_port(cdev, release.port_id, true);
+}
+
+static long fme_hdr_ioctl_assign_port(struct dfl_feature_platform_data *pdata,
+				      void __user *arg)
+{
+	struct dfl_fpga_cdev *cdev = pdata->dfl_cdev;
+	struct dfl_fpga_fme_port_assign assign;
+	unsigned long minsz;
+
+	minsz = offsetofend(struct dfl_fpga_fme_port_assign, port_id);
+
+	if (copy_from_user(&assign, arg, minsz))
+		return -EFAULT;
+
+	if (assign.argsz < minsz || assign.flags)
+		return -EINVAL;
+
+	return dfl_fpga_cdev_config_port(cdev, assign.port_id, false);
+}
+
+static long fme_hdr_ioctl(struct platform_device *pdev,
+			  struct dfl_feature *feature,
+			  unsigned int cmd, unsigned long arg)
+{
+	struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
+
+	switch (cmd) {
+	case DFL_FPGA_FME_PORT_RELEASE:
+		return fme_hdr_ioctl_release_port(pdata, (void __user *)arg);
+	case DFL_FPGA_FME_PORT_ASSIGN:
+		return fme_hdr_ioctl_assign_port(pdata, (void __user *)arg);
+	}
+
+	return -ENODEV;
+}
+
 static const struct dfl_feature_ops fme_hdr_ops = {
 	.init = fme_hdr_init,
 	.uinit = fme_hdr_uinit,
+	.ioctl = fme_hdr_ioctl,
 };
 
 static struct dfl_feature_driver fme_feature_drvs[] = {
drivers/fpga/dfl.c +95 -12

148 lines not on this page · raw message

drivers/fpga/dfl.h +10 -0
index 8851c6c..63f39ab 100644
@@ -183,6 +183,8 @@ struct dfl_feature {
 
 #define DEV_STATUS_IN_USE	0
 
+#define FEATURE_DEV_ID_UNUSED	(-1)
+
 /**
  * struct dfl_feature_platform_data - platform data for feature devices
  *
@@ -191,6 +193,7 @@ struct dfl_feature {
  * @cdev: cdev of feature dev.
  * @dev: ptr to platform device linked with this platform data.
  * @dfl_cdev: ptr to container device.
+ * @id: id used for this feature device.
  * @disable_count: count for port disable.
  * @num: number for sub features.
  * @dev_status: dev status (e.g. DEV_STATUS_IN_USE).
@@ -203,6 +206,7 @@ struct dfl_feature_platform_data {
 	struct cdev cdev;
 	struct platform_device *dev;
 	struct dfl_fpga_cdev *dfl_cdev;
+	int id;
 	unsigned int disable_count;
 	unsigned long dev_status;
 	void *private;
@@ -378,6 +382,7 @@ void dfl_fpga_enum_info_free(struct dfl_fpga_enum_info *info);
  * @fme_dev: FME feature device under this container device.
  * @lock: mutex lock to protect the port device list.
  * @port_dev_list: list of all port feature devices under this container device.
+ * @released_port_num: released port number under this container device.
  */
 struct dfl_fpga_cdev {
 	struct device *parent;
@@ -385,6 +390,7 @@ struct dfl_fpga_cdev {
 	struct device *fme_dev;
 	struct mutex lock;
 	struct list_head port_dev_list;
+	int released_port_num;
 };
 
 struct dfl_fpga_cdev *
@@ -412,4 +418,8 @@ dfl_fpga_cdev_find_port(struct dfl_fpga_cdev *cdev, void *data,
 
 	return pdev;
 }
+
+int dfl_fpga_cdev_config_port(struct dfl_fpga_cdev *cdev,
+			      u32 port_id, bool release);
+
 #endif /* __FPGA_DFL_H */
include/uapi/linux/fpga-dfl.h +32 -0
index 2e324e5..e9a00e0 100644
@@ -176,4 +176,36 @@ struct dfl_fpga_fme_port_pr {
 
 #define DFL_FPGA_FME_PORT_PR	_IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 0)
 
+/**
+ * DFL_FPGA_FME_PORT_RELEASE - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 1,
+ *					struct dfl_fpga_fme_port_release)
+ *
+ * Driver releases the port per Port ID provided by caller.
+ * Return: 0 on success, -errno on failure.
+ */
+struct dfl_fpga_fme_port_release {
+	/* Input */
+	__u32 argsz;		/* Structure length */
+	__u32 flags;		/* Zero for now */
+	__u32 port_id;
+};
+
+#define DFL_FPGA_FME_PORT_RELEASE	_IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 1)
+
+/**
+ * DFL_FPGA_FME_PORT_ASSIGN - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 2,
+ *					struct dfl_fpga_fme_port_assign)
+ *
+ * Driver assigns the port back per Port ID provided by caller.
+ * Return: 0 on success, -errno on failure.
+ */
+struct dfl_fpga_fme_port_assign {
+	/* Input */
+	__u32 argsz;		/* Structure length */
+	__u32 flags;		/* Zero for now */
+	__u32 port_id;
+};
+
+#define DFL_FPGA_FME_PORT_ASSIGN	_IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 2)
+
 #endif /* _UAPI_LINUX_FPGA_DFL_H */
Signature · 1 line
2.7.4
Acked-by on v1 5/17
#25 lore raw

Re: [PATCH 05/17] fpga: dfl: fme: add DFL_FPGA_FME_PORT_RELEASE/ASSIGN ioctl support.

Quoted 16 lines · Wu Hao

In order to support virtualization usage via PCIe SRIOV, this patch adds two ioctls under FPGA Management Engine (FME) to release and assign back the port device. In order to safely turn Port from PF into VF and enable PCIe SRIOV, it requires user to invoke this PORT_RELEASE ioctl to release port firstly to remove userspace interfaces, and then configure the PF/VF access register in FME. After disable SRIOV, it requires user to invoke this PORT_ASSIGN ioctl to attach the port back to PF.

Ioctl interfaces:
* DFL_FPGA_FME_PORT_RELEASE
Release platform device of given port, it deletes port platform device to remove related userspace interfaces on PF, then configures PF/VF access mode to VF.

Quoted 8 lines

* DFL_FPGA_FME_PORT_ASSIGN
Assign platform device of given port back to PF, it configures PF/VF access mode to PF, then adds port platform device back to re-enable related userspace interfaces on PF.

author
#26 lore raw

PATCH 6/17 fpga: dfl: pci: enable SRIOV support.

In reply to Wu Hao

This patch enables the standard sriov support. It allows user to enable SRIOV (and VFs), then user could pass through accelerators (VFs) into virtual machine or use VFs directly in host.

---
 drivers/fpga/dfl-pci.c | 40 ++++++++++++++++++++++++++++++++++++++++
 drivers/fpga/dfl.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 drivers/fpga/dfl.h     |  1 +
 3 files changed, 82 insertions(+)
drivers/fpga/dfl-pci.c +40 -0
index 66b5720..2fa571b 100644
@@ -223,8 +223,46 @@ int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid)
 	return ret;
 }
 
+static int cci_pci_sriov_configure(struct pci_dev *pcidev, int num_vfs)
+{
+	struct cci_drvdata *drvdata = pci_get_drvdata(pcidev);
+	struct dfl_fpga_cdev *cdev = drvdata->cdev;
+	int ret = 0;
+
+	mutex_lock(&cdev->lock);
+
+	if (!num_vfs) {
+		/*
+		 * disable SRIOV and then put released ports back to default
+		 * PF access mode.
+		 */
+		pci_disable_sriov(pcidev);
+
+		__dfl_fpga_cdev_config_port_vf(cdev, false);
+
+	} else if (cdev->released_port_num == num_vfs) {
+		/*
+		 * only enable SRIOV if cdev has matched released ports, put
+		 * released ports into VF access mode firstly.
+		 */
+		__dfl_fpga_cdev_config_port_vf(cdev, true);
+
+		ret = pci_enable_sriov(pcidev, num_vfs);
+		if (ret)
+			__dfl_fpga_cdev_config_port_vf(cdev, false);
+	} else {
+		ret = -EINVAL;
+	}
+
+	mutex_unlock(&cdev->lock);
+	return ret;
+}
+
 static void cci_pci_remove(struct pci_dev *pcidev)
 {
+	if (dev_is_pf(&pcidev->dev))
+		cci_pci_sriov_configure(pcidev, 0);
+
 	cci_remove_feature_devs(pcidev);
 	pci_disable_pcie_error_reporting(pcidev);
 }
@@ -234,6 +272,7 @@ static struct pci_driver cci_pci_driver = {
 	.id_table = cci_pcie_id_tbl,
 	.probe = cci_pci_probe,
 	.remove = cci_pci_remove,
+	.sriov_configure = cci_pci_sriov_configure,
 };
 
 module_pci_driver(cci_pci_driver);
@@ -241,3 +280,4 @@ module_pci_driver(cci_pci_driver);
 MODULE_DESCRIPTION("FPGA DFL PCIe Device Driver");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL v2");
+MODULE_VERSION(DRV_VERSION);
drivers/fpga/dfl.c +41 -0

47 lines not on this page · raw message

drivers/fpga/dfl.h +1 -0
index 63f39ab..1350e8e 100644
@@ -421,5 +421,6 @@ dfl_fpga_cdev_find_port(struct dfl_fpga_cdev *cdev, void *data,
 
 int dfl_fpga_cdev_config_port(struct dfl_fpga_cdev *cdev,
 			      u32 port_id, bool release);
+void __dfl_fpga_cdev_config_port_vf(struct dfl_fpga_cdev *cdev, bool is_vf);
 
 #endif /* __FPGA_DFL_H */
Signature · 1 line
2.7.4
Acked-by on v1 6/17
#27 lore raw

Re: [PATCH 06/17] fpga: dfl: pci: enable SRIOV support.

Quoted 8 lines · Wu Hao

This patch enables the standard sriov support. It allows user to enable SRIOV (and VFs), then user could pass through accelerators (VFs) into virtual machine or use VFs directly in host.

author
#28 lore raw

PATCH 7/17 fpga: dfl: afu: add AFU state related sysfs interfaces

In reply to Wu Hao

This patch introduces more sysfs interfaces for Accelerated Function Unit (AFU). These interfaces allow users to read current AFU Power State (APx), read / clear AFU Power (APx) events which are sticky to identify transient APx state, and manage AFU's LTR (latency tolerance reporting).

---
 Documentation/ABI/testing/sysfs-platform-dfl-port |  30 +++++
 drivers/fpga/dfl-afu-main.c                       | 144 ++++++++++++++++++++++
 drivers/fpga/dfl.h                                |  11 ++
 3 files changed, 185 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-port +30 -0
index 6a92dda..f0c4e92 100644
@@ -14,3 +14,33 @@ Description:	Read-only. User can program different PR bitstreams to FPGA
 		Accelerator Function Unit (AFU) for different functions. It
 		returns uuid which could be used to identify which PR bitstream
 		is programmed in this AFU.
+
+What:		/sys/bus/platform/devices/dfl-port.0/power_state
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It reports the APx (AFU Power) state, different APx
+		means different throttling level. When reading this file, it
+		returns "0" - Normal / "1" - AP1 / "2" - AP2 / "6" - AP6.
+
+What:		/sys/bus/platform/devices/dfl-port.0/ap1_event
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-write. Read or set 1 to clear AP1 (AFU Power State 1)
+		event. It's used to indicate transient AP1 state.
+
+What:		/sys/bus/platform/devices/dfl-port.0/ap2_event
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-write. Read or set 1 to clear AP2 (AFU Power State 2)
+		event. It's used to indicate transient AP2 state.
+
+What:		/sys/bus/platform/devices/dfl-port.0/ltr
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-write. Read and set AFU latency tolerance reporting value.
+		Set ltr to 1 if the AFU can tolerate latency >= 40us or set it
+		to 0 if it is latency sensitive.
drivers/fpga/dfl-afu-main.c +144 -0

161 lines not on this page · raw message

drivers/fpga/dfl.h +11 -0
index 1350e8e..1525098 100644
@@ -119,6 +119,7 @@
 #define PORT_HDR_NEXT_AFU	NEXT_AFU
 #define PORT_HDR_CAP		0x30
 #define PORT_HDR_CTRL		0x38
+#define PORT_HDR_STS		0x40
 
 /* Port Capability Register Bitfield */
 #define PORT_CAP_PORT_NUM	GENMASK_ULL(1, 0)	/* ID of this port */
@@ -130,6 +131,16 @@
 /* Latency tolerance reporting. '1' >= 40us, '0' < 40us.*/
 #define PORT_CTRL_LATENCY	BIT_ULL(2)
 #define PORT_CTRL_SFTRST_ACK	BIT_ULL(4)		/* HW ack for reset */
+
+/* Port Status Register Bitfield */
+#define PORT_STS_AP2_EVT	BIT_ULL(13)		/* AP2 event detected */
+#define PORT_STS_AP1_EVT	BIT_ULL(12)		/* AP1 event detected */
+#define PORT_STS_PWR_STATE	GENMASK_ULL(11, 8)	/* AFU power states */
+#define PORT_STS_PWR_STATE_NORM 0
+#define PORT_STS_PWR_STATE_AP1	1			/* 50% throttling */
+#define PORT_STS_PWR_STATE_AP2	2			/* 90% throttling */
+#define PORT_STS_PWR_STATE_AP6	6			/* 100% throttling */
+
 /**
  * struct dfl_fpga_port_ops - port ops
  *
Signature · 1 line
2.7.4
Acked-by on v1 7/17
#29 lore raw

Re: [PATCH 07/17] fpga: dfl: afu: add AFU state related sysfs interfaces

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 10 lines

This patch introduces more sysfs interfaces for Accelerated Function Unit (AFU). These interfaces allow users to read current AFU Power State (APx), read / clear AFU Power (APx) events which are sticky to identify transient APx state, and manage AFU's LTR (latency tolerance reporting).

Thanks,
Alan

author
#30 lore raw

PATCH 8/17 fpga: dfl: afu: add userclock sysfs interfaces.

In reply to Wu Hao

This patch introduces userclock sysfs interfaces for AFU, user could use these interfaces for clock setting to AFU.

Please note that, this is only working for port header feature with revision 0, for later revisions, userclock setting is moved to a separated private feature, so one revision sysfs interface is exposed to userspace application for this purpose too.

---
 Documentation/ABI/testing/sysfs-platform-dfl-port |  35 +++++++
 drivers/fpga/dfl-afu-main.c                       | 114 +++++++++++++++++++++-
 drivers/fpga/dfl.h                                |   4 +
 3 files changed, 152 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-platform-dfl-port +35 -0
index f0c4e92..f611e47 100644
@@ -44,3 +44,38 @@ Contact:	Wu Hao <[email protected]>
 Description:	Read-write. Read and set AFU latency tolerance reporting value.
 		Set ltr to 1 if the AFU can tolerate latency >= 40us or set it
 		to 0 if it is latency sensitive.
+
+What:		/sys/bus/platform/devices/dfl-port.0/revision
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the revision of port header
+		feature.
+
+What:		/sys/bus/platform/devices/dfl-port.0/userclk_freqcmd
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Write-only. User writes command to this interface to set
+		userclock to AFU.
+
+What:		/sys/bus/platform/devices/dfl-port.0/userclk_freqsts
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the status of issued command
+		to userclck_freqcmd.
+
+What:		/sys/bus/platform/devices/dfl-port.0/userclk_freqcntrcmd
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Write-only. User writes command to this interface to set
+		userclock counter.
+
+What:		/sys/bus/platform/devices/dfl-port.0/userclk_freqcntrsts
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the status of issued command
+		to userclck_freqcntrcmd.
drivers/fpga/dfl-afu-main.c +113 -1

145 lines not on this page · raw message

drivers/fpga/dfl.h +4 -0
index 1525098..3c5dc3a 100644
@@ -120,6 +120,10 @@
 #define PORT_HDR_CAP		0x30
 #define PORT_HDR_CTRL		0x38
 #define PORT_HDR_STS		0x40
+#define PORT_HDR_USRCLK_CMD0	0x50
+#define PORT_HDR_USRCLK_CMD1	0x58
+#define PORT_HDR_USRCLK_STS0	0x60
+#define PORT_HDR_USRCLK_STS1	0x68
 
 /* Port Capability Register Bitfield */
 #define PORT_CAP_PORT_NUM	GENMASK_ULL(1, 0)	/* ID of this port */
Signature · 1 line
2.7.4
Acked-by on v1 8/17
#31 lore raw

Re: [PATCH 08/17] fpga: dfl: afu: add userclock sysfs interfaces.

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Looks fine.

Quoted 9 lines

This patch introduces userclock sysfs interfaces for AFU, user could use these interfaces for clock setting to AFU.

Please note that, this is only working for port header feature with revision 0, for later revisions, userclock setting is moved to a separated private feature, so one revision sysfs interface is exposed to userspace application for this purpose too.

Quoted 4 lines
author
#32 lore raw

PATCH 9/17 fpga: dfl: add id_table for dfl private feature driver

In reply to Wu Hao

This patch adds id_table for each dfl private feature driver, it allows to reuse same private feature driver to match and support multiple dfl private features.

---
 drivers/fpga/dfl-afu-main.c | 14 ++++++++++++--
 drivers/fpga/dfl-fme-main.c | 11 ++++++++---
 drivers/fpga/dfl-fme-pr.c   |  7 ++++++-
 drivers/fpga/dfl-fme.h      |  3 ++-
 drivers/fpga/dfl.c          | 21 +++++++++++++++++++--
 drivers/fpga/dfl.h          | 21 +++++++++++++++------
 6 files changed, 62 insertions(+), 15 deletions(-)
drivers/fpga/dfl-afu-main.c +12 -2
index 82fd80a..2916876 100644
@@ -440,6 +440,11 @@ port_hdr_ioctl(struct platform_device *pdev, struct dfl_feature *feature,
 	return ret;
 }
 
+static const struct dfl_feature_id port_hdr_id_table[] = {
+	{.id = PORT_FEATURE_ID_HEADER,},
+	{0,}
+};
+
 static const struct dfl_feature_ops port_hdr_ops = {
 	.init = port_hdr_init,
 	.uinit = port_hdr_uinit,
@@ -500,6 +505,11 @@ static void port_afu_uinit(struct platform_device *pdev,
 	sysfs_remove_files(&pdev->dev.kobj, port_afu_attrs);
 }
 
+static const struct dfl_feature_id port_afu_id_table[] = {
+	{.id = PORT_FEATURE_ID_AFU,},
+	{0,}
+};
+
 static const struct dfl_feature_ops port_afu_ops = {
 	.init = port_afu_init,
 	.uinit = port_afu_uinit,
@@ -507,11 +517,11 @@ static const struct dfl_feature_ops port_afu_ops = {
 
 static struct dfl_feature_driver port_feature_drvs[] = {
 	{
-		.id = PORT_FEATURE_ID_HEADER,
+		.id_table = port_hdr_id_table,
 		.ops = &port_hdr_ops,
 	},
 	{
-		.id = PORT_FEATURE_ID_AFU,
+		.id_table = port_afu_id_table,
 		.ops = &port_afu_ops,
 	},
 	{
drivers/fpga/dfl-fme-main.c +8 -3
index 8b2a337..38c6342 100644
@@ -158,6 +158,11 @@ static long fme_hdr_ioctl(struct platform_device *pdev,
 	return -ENODEV;
 }
 
+static const struct dfl_feature_id fme_hdr_id_table[] = {
+	{.id = FME_FEATURE_ID_HEADER,},
+	{0,}
+};
+
 static const struct dfl_feature_ops fme_hdr_ops = {
 	.init = fme_hdr_init,
 	.uinit = fme_hdr_uinit,
@@ -166,12 +171,12 @@ static const struct dfl_feature_ops fme_hdr_ops = {
 
 static struct dfl_feature_driver fme_feature_drvs[] = {
 	{
-		.id = FME_FEATURE_ID_HEADER,
+		.id_table = fme_hdr_id_table,
 		.ops = &fme_hdr_ops,
 	},
 	{
-		.id = FME_FEATURE_ID_PR_MGMT,
-		.ops = &pr_mgmt_ops,
+		.id_table = fme_pr_mgmt_id_table,
+		.ops = &fme_pr_mgmt_ops,
 	},
 	{
 		.ops = NULL,
drivers/fpga/dfl-fme-pr.c +6 -1
index 8a0e46a..b054ac6 100644
@@ -482,7 +482,12 @@ static long fme_pr_ioctl(struct platform_device *pdev,
 	return ret;
 }
 
-const struct dfl_feature_ops pr_mgmt_ops = {
+const struct dfl_feature_id fme_pr_mgmt_id_table[] = {
+	{.id = FME_FEATURE_ID_PR_MGMT,},
+	{0}
+};
+
+const struct dfl_feature_ops fme_pr_mgmt_ops = {
 	.init = pr_mgmt_init,
 	.uinit = pr_mgmt_uinit,
 	.ioctl = fme_pr_ioctl,
drivers/fpga/dfl-fme.h +2 -1
index de20755..7a021c4 100644
@@ -35,6 +35,7 @@ struct dfl_fme {
 	struct dfl_feature_platform_data *pdata;
 };
 
-extern const struct dfl_feature_ops pr_mgmt_ops;
+extern const struct dfl_feature_ops fme_pr_mgmt_ops;
+extern const struct dfl_feature_id fme_pr_mgmt_id_table[];
 
 #endif /* __DFL_FME_H */
drivers/fpga/dfl.c +19 -2
index c5aa287..65f91ef 100644
@@ -14,6 +14,8 @@
 
 #include "dfl.h"
 
+#define DRV_VERSION	"0.8"
+
 static DEFINE_MUTEX(dfl_id_mutex);
 
 /*
@@ -274,6 +276,21 @@ static int dfl_feature_instance_init(struct platform_device *pdev,
 	return ret;
 }
 
+static bool dfl_feature_drv_match(struct dfl_feature *feature,
+				  struct dfl_feature_driver *driver)
+{
+	const struct dfl_feature_id *ids = driver->id_table;
+
+	if (ids) {
+		while (ids->id) {
+			if (ids->id == feature->id)
+				return true;
+			ids++;
+		}
+	}
+	return false;
+}
+
 /**
  * dfl_fpga_dev_feature_init - init for sub features of dfl feature device
  * @pdev: feature device.
@@ -294,8 +311,7 @@ int dfl_fpga_dev_feature_init(struct platform_device *pdev,
 
 	while (drv->ops) {
 		dfl_fpga_dev_for_each_feature(pdata, feature) {
-			/* match feature and drv using id */
-			if (feature->id == drv->id) {
+			if (dfl_feature_drv_match(feature, drv)) {
 				ret = dfl_feature_instance_init(pdev, pdata,
 								feature, drv);
 				if (ret)
@@ -1164,3 +1180,4 @@ module_exit(dfl_fpga_exit);
 MODULE_DESCRIPTION("FPGA Device Feature List (DFL) Support");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL v2");
+MODULE_VERSION(DRV_VERSION);
drivers/fpga/dfl.h +15 -6
index 3c5dc3a..fbc57f0 100644
@@ -30,8 +30,8 @@
 /* plus one for fme device */
 #define MAX_DFL_FEATURE_DEV_NUM    (MAX_DFL_FPGA_PORT_NUM + 1)
 
-/* Reserved 0x0 for Header Group Register and 0xff for AFU */
-#define FEATURE_ID_FIU_HEADER		0x0
+/* Reserved 0xfe for Header Group Register and 0xff for AFU */
+#define FEATURE_ID_FIU_HEADER		0xfe
 #define FEATURE_ID_AFU			0xff
 
 #define FME_FEATURE_ID_HEADER		FEATURE_ID_FIU_HEADER
@@ -169,13 +169,22 @@ void dfl_fpga_port_ops_put(struct dfl_fpga_port_ops *ops);
 int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id);
 
 /**
- * struct dfl_feature_driver - sub feature's driver
+ * struct dfl_feature_id - dfl private feature id
  *
- * @id: sub feature id.
- * @ops: ops of this sub feature.
+ * @id: unique dfl private feature id.
  */
-struct dfl_feature_driver {
+struct dfl_feature_id {
 	u64 id;
+};
+
+/**
+ * struct dfl_feature_driver - dfl private feature driver
+ *
+ * @id_table: id_table for dfl private features supported by this driver.
+ * @ops: ops of this dfl private feature driver.
+ */
+struct dfl_feature_driver {
+	const struct dfl_feature_id *id_table;
 	const struct dfl_feature_ops *ops;
 };
 
Signature · 1 line
2.7.4
maintainer Acked-by on v1 9/17
#33 lore raw

Re: [PATCH 09/17] fpga: dfl: add id_table for dfl private feature driver

Hi Wu,

Quoted 6 lines · Wu Hao

This patch adds id_table for each dfl private feature driver, it allows to reuse same private feature driver to match and support multiple dfl private features.

Quoted 209 lines
---
 drivers/fpga/dfl-afu-main.c | 14 ++++++++++++--
 drivers/fpga/dfl-fme-main.c | 11 ++++++++---
 drivers/fpga/dfl-fme-pr.c   |  7 ++++++-
 drivers/fpga/dfl-fme.h      |  3 ++-
 drivers/fpga/dfl.c          | 21 +++++++++++++++++++--
 drivers/fpga/dfl.h          | 21 +++++++++++++++------
 6 files changed, 62 insertions(+), 15 deletions(-)
drivers/fpga/dfl-afu-main.c +12 -2
index 82fd80a..2916876 100644
@@ -440,6 +440,11 @@ port_hdr_ioctl(struct platform_device *pdev, struct dfl_feature *feature,
 	return ret;
 }
 
+static const struct dfl_feature_id port_hdr_id_table[] = {
+	{.id = PORT_FEATURE_ID_HEADER,},
+	{0,}
+};
+
 static const struct dfl_feature_ops port_hdr_ops = {
 	.init = port_hdr_init,
 	.uinit = port_hdr_uinit,
@@ -500,6 +505,11 @@ static void port_afu_uinit(struct platform_device *pdev,
 	sysfs_remove_files(&pdev->dev.kobj, port_afu_attrs);
 }
 
+static const struct dfl_feature_id port_afu_id_table[] = {
+	{.id = PORT_FEATURE_ID_AFU,},
+	{0,}
+};
+
 static const struct dfl_feature_ops port_afu_ops = {
 	.init = port_afu_init,
 	.uinit = port_afu_uinit,
@@ -507,11 +517,11 @@ static const struct dfl_feature_ops port_afu_ops = {
 
 static struct dfl_feature_driver port_feature_drvs[] = {
 	{
-		.id = PORT_FEATURE_ID_HEADER,
+		.id_table = port_hdr_id_table,
 		.ops = &port_hdr_ops,
 	},
 	{
-		.id = PORT_FEATURE_ID_AFU,
+		.id_table = port_afu_id_table,
 		.ops = &port_afu_ops,
 	},
 	{
drivers/fpga/dfl-fme-main.c +8 -3
index 8b2a337..38c6342 100644
@@ -158,6 +158,11 @@ static long fme_hdr_ioctl(struct platform_device *pdev,
 	return -ENODEV;
 }
 
+static const struct dfl_feature_id fme_hdr_id_table[] = {
+	{.id = FME_FEATURE_ID_HEADER,},
+	{0,}
+};
+
 static const struct dfl_feature_ops fme_hdr_ops = {
 	.init = fme_hdr_init,
 	.uinit = fme_hdr_uinit,
@@ -166,12 +171,12 @@ static const struct dfl_feature_ops fme_hdr_ops = {
 
 static struct dfl_feature_driver fme_feature_drvs[] = {
 	{
-		.id = FME_FEATURE_ID_HEADER,
+		.id_table = fme_hdr_id_table,
 		.ops = &fme_hdr_ops,
 	},
 	{
-		.id = FME_FEATURE_ID_PR_MGMT,
-		.ops = &pr_mgmt_ops,
+		.id_table = fme_pr_mgmt_id_table,
+		.ops = &fme_pr_mgmt_ops,
 	},
 	{
 		.ops = NULL,
drivers/fpga/dfl-fme-pr.c +6 -1
index 8a0e46a..b054ac6 100644
@@ -482,7 +482,12 @@ static long fme_pr_ioctl(struct platform_device *pdev,
 	return ret;
 }
 
-const struct dfl_feature_ops pr_mgmt_ops = {
+const struct dfl_feature_id fme_pr_mgmt_id_table[] = {
+	{.id = FME_FEATURE_ID_PR_MGMT,},
+	{0}
+};
+
+const struct dfl_feature_ops fme_pr_mgmt_ops = {
 	.init = pr_mgmt_init,
 	.uinit = pr_mgmt_uinit,
 	.ioctl = fme_pr_ioctl,
drivers/fpga/dfl-fme.h +2 -1
index de20755..7a021c4 100644
@@ -35,6 +35,7 @@ struct dfl_fme {
 	struct dfl_feature_platform_data *pdata;
 };
 
-extern const struct dfl_feature_ops pr_mgmt_ops;
+extern const struct dfl_feature_ops fme_pr_mgmt_ops;
+extern const struct dfl_feature_id fme_pr_mgmt_id_table[];
 
 #endif /* __DFL_FME_H */
drivers/fpga/dfl.c +19 -2
index c5aa287..65f91ef 100644
@@ -14,6 +14,8 @@
 
 #include "dfl.h"
 
+#define DRV_VERSION	"0.8"
+
 static DEFINE_MUTEX(dfl_id_mutex);
 
 /*
@@ -274,6 +276,21 @@ static int dfl_feature_instance_init(struct platform_device *pdev,
 	return ret;
 }
 
+static bool dfl_feature_drv_match(struct dfl_feature *feature,
+				  struct dfl_feature_driver *driver)
+{
+	const struct dfl_feature_id *ids = driver->id_table;
+
+	if (ids) {
+		while (ids->id) {
+			if (ids->id == feature->id)
+				return true;
+			ids++;
+		}
+	}
+	return false;
+}
+
 /**
  * dfl_fpga_dev_feature_init - init for sub features of dfl feature device
  * @pdev: feature device.
@@ -294,8 +311,7 @@ int dfl_fpga_dev_feature_init(struct platform_device *pdev,
 
 	while (drv->ops) {
 		dfl_fpga_dev_for_each_feature(pdata, feature) {
-			/* match feature and drv using id */
-			if (feature->id == drv->id) {
+			if (dfl_feature_drv_match(feature, drv)) {
 				ret = dfl_feature_instance_init(pdev, pdata,
 								feature, drv);
 				if (ret)
@@ -1164,3 +1180,4 @@ module_exit(dfl_fpga_exit);
 MODULE_DESCRIPTION("FPGA Device Feature List (DFL) Support");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL v2");
+MODULE_VERSION(DRV_VERSION);
drivers/fpga/dfl.h +15 -6
index 3c5dc3a..fbc57f0 100644
@@ -30,8 +30,8 @@
 /* plus one for fme device */
 #define MAX_DFL_FEATURE_DEV_NUM    (MAX_DFL_FPGA_PORT_NUM + 1)
 
-/* Reserved 0x0 for Header Group Register and 0xff for AFU */
-#define FEATURE_ID_FIU_HEADER		0x0
+/* Reserved 0xfe for Header Group Register and 0xff for AFU */
+#define FEATURE_ID_FIU_HEADER		0xfe
 #define FEATURE_ID_AFU			0xff
 
 #define FME_FEATURE_ID_HEADER		FEATURE_ID_FIU_HEADER
@@ -169,13 +169,22 @@ void dfl_fpga_port_ops_put(struct dfl_fpga_port_ops *ops);
 int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id);
 
 /**
- * struct dfl_feature_driver - sub feature's driver
+ * struct dfl_feature_id - dfl private feature id
  *
- * @id: sub feature id.
- * @ops: ops of this sub feature.
+ * @id: unique dfl private feature id.
  */
-struct dfl_feature_driver {
+struct dfl_feature_id {
 	u64 id;
+};
+
+/**
+ * struct dfl_feature_driver - dfl private feature driver
+ *
+ * @id_table: id_table for dfl private features supported by this driver.
+ * @ops: ops of this dfl private feature driver.
+ */
+struct dfl_feature_driver {
+	const struct dfl_feature_id *id_table;
 	const struct dfl_feature_ops *ops;
 };
 
Signature · 1 line
2.7.4
Acked-by
#34 lore raw

Re: [PATCH 09/17] fpga: dfl: add id_table for dfl private feature driver

Quoted 11 lines · Moritz Fischer

Hi Wu,

Quoted 6 lines · Wu Hao

This patch adds id_table for each dfl private feature driver, it allows to reuse same private feature driver to match and support multiple dfl private features.

Thanks,
Alan

author
#35 lore raw

PATCH 10/17 fpga: dfl: afu: export __port_enable/disable function.

In reply to Wu Hao

As these two functions are used by other private features. e.g. in error reporting private feature, it requires to check port status and reset port for error clearing.

---
 drivers/fpga/dfl-afu-main.c | 25 ++++++++++++++-----------
 drivers/fpga/dfl-afu.h      |  3 +++
 2 files changed, 17 insertions(+), 11 deletions(-)
drivers/fpga/dfl-afu-main.c +14 -11
index 2916876..e727d9b 100644
@@ -24,14 +24,16 @@
 #define DRV_VERSION	"0.8"
 
 /**
- * port_enable - enable a port
+ * __port_enable - enable a port
  * @pdev: port platform device.
  *
  * Enable Port by clear the port soft reset bit, which is set by default.
  * The AFU is unable to respond to any MMIO access while in reset.
- * port_enable function should only be used after port_disable function.
+ * __port_enable function should only be used after __port_disable function.
+ *
+ * The caller needs to hold lock for protection.
  */
-static void port_enable(struct platform_device *pdev)
+void __port_enable(struct platform_device *pdev)
 {
 	struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	void __iomem *base;
@@ -54,13 +56,14 @@ static void port_enable(struct platform_device *pdev)
 #define RST_POLL_TIMEOUT 1000 /* us */
 
 /**
- * port_disable - disable a port
+ * __port_disable - disable a port
  * @pdev: port platform device.
  *
- * Disable Port by setting the port soft reset bit, it puts the port into
- * reset.
+ * Disable Port by setting the port soft reset bit, it puts the port into reset.
+ *
+ * The caller needs to hold lock for protection.
  */
-static int port_disable(struct platform_device *pdev)
+int __port_disable(struct platform_device *pdev)
 {
 	struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	void __iomem *base;
@@ -106,9 +109,9 @@ static int __port_reset(struct platform_device *pdev)
 {
 	int ret;
 
-	ret = port_disable(pdev);
+	ret = __port_disable(pdev);
 	if (!ret)
-		port_enable(pdev);
+		__port_enable(pdev);
 
 	return ret;
 }
@@ -810,9 +813,9 @@ static int port_enable_set(struct platform_device *pdev, bool enable)
 
 	mutex_lock(&pdata->lock);
 	if (enable)
-		port_enable(pdev);
+		__port_enable(pdev);
 	else
-		ret = port_disable(pdev);
+		ret = __port_disable(pdev);
 	mutex_unlock(&pdata->lock);
 
 	return ret;
drivers/fpga/dfl-afu.h +3 -0
index 0c7630a..35e60c5 100644
@@ -79,6 +79,9 @@ struct dfl_afu {
 	struct dfl_feature_platform_data *pdata;
 };
 
+void __port_enable(struct platform_device *pdev);
+int __port_disable(struct platform_device *pdev);
+
 void afu_mmio_region_init(struct dfl_feature_platform_data *pdata);
 int afu_mmio_region_add(struct dfl_feature_platform_data *pdata,
 			u32 region_index, u64 region_size, u64 phys, u32 flags);
Signature · 1 line
2.7.4
maintainer Acked-by on v1 10/17
#36 lore raw

Re: [PATCH 10/17] fpga: dfl: afu: export __port_enable/disable function.

Hi Wu,

Quoted 6 lines · Wu Hao

As these two functions are used by other private features. e.g. in error reporting private feature, it requires to check port status and reset port for error clearing.

Quoted 89 lines
---
 drivers/fpga/dfl-afu-main.c | 25 ++++++++++++++-----------
 drivers/fpga/dfl-afu.h      |  3 +++
 2 files changed, 17 insertions(+), 11 deletions(-)
drivers/fpga/dfl-afu-main.c +14 -11
index 2916876..e727d9b 100644
@@ -24,14 +24,16 @@
 #define DRV_VERSION	"0.8"
 
 /**
- * port_enable - enable a port
+ * __port_enable - enable a port
  * @pdev: port platform device.
  *
  * Enable Port by clear the port soft reset bit, which is set by default.
  * The AFU is unable to respond to any MMIO access while in reset.
- * port_enable function should only be used after port_disable function.
+ * __port_enable function should only be used after __port_disable function.
+ *
+ * The caller needs to hold lock for protection.
  */
-static void port_enable(struct platform_device *pdev)
+void __port_enable(struct platform_device *pdev)
 {
 	struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	void __iomem *base;
@@ -54,13 +56,14 @@ static void port_enable(struct platform_device *pdev)
 #define RST_POLL_TIMEOUT 1000 /* us */
 
 /**
- * port_disable - disable a port
+ * __port_disable - disable a port
  * @pdev: port platform device.
  *
- * Disable Port by setting the port soft reset bit, it puts the port into
- * reset.
+ * Disable Port by setting the port soft reset bit, it puts the port into reset.
+ *
+ * The caller needs to hold lock for protection.
  */
-static int port_disable(struct platform_device *pdev)
+int __port_disable(struct platform_device *pdev)
 {
 	struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	void __iomem *base;
@@ -106,9 +109,9 @@ static int __port_reset(struct platform_device *pdev)
 {
 	int ret;
 
-	ret = port_disable(pdev);
+	ret = __port_disable(pdev);
 	if (!ret)
-		port_enable(pdev);
+		__port_enable(pdev);
 
 	return ret;
 }
@@ -810,9 +813,9 @@ static int port_enable_set(struct platform_device *pdev, bool enable)
 
 	mutex_lock(&pdata->lock);
 	if (enable)
-		port_enable(pdev);
+		__port_enable(pdev);
 	else
-		ret = port_disable(pdev);
+		ret = __port_disable(pdev);
 	mutex_unlock(&pdata->lock);
 
 	return ret;
drivers/fpga/dfl-afu.h +3 -0
index 0c7630a..35e60c5 100644
@@ -79,6 +79,9 @@ struct dfl_afu {
 	struct dfl_feature_platform_data *pdata;
 };
 
+void __port_enable(struct platform_device *pdev);
+int __port_disable(struct platform_device *pdev);
+
 void afu_mmio_region_init(struct dfl_feature_platform_data *pdata);
 int afu_mmio_region_add(struct dfl_feature_platform_data *pdata,
 			u32 region_index, u64 region_size, u64 phys, u32 flags);
Signature · 1 line
2.7.4

Thanks,
Moritz

maintainer Acked-by on v1 10/17
#37 lore raw

Re: [PATCH 10/17] fpga: dfl: afu: export __port_enable/disable function.

In reply to Wu Hao
Quoted 6 lines · Wu Hao

As these two functions are used by other private features. e.g. in error reporting private feature, it requires to check port status and reset port for error clearing.

Quoted 89 lines
---
 drivers/fpga/dfl-afu-main.c | 25 ++++++++++++++-----------
 drivers/fpga/dfl-afu.h      |  3 +++
 2 files changed, 17 insertions(+), 11 deletions(-)
drivers/fpga/dfl-afu-main.c +14 -11
index 2916876..e727d9b 100644
@@ -24,14 +24,16 @@
 #define DRV_VERSION	"0.8"
 
 /**
- * port_enable - enable a port
+ * __port_enable - enable a port
  * @pdev: port platform device.
  *
  * Enable Port by clear the port soft reset bit, which is set by default.
  * The AFU is unable to respond to any MMIO access while in reset.
- * port_enable function should only be used after port_disable function.
+ * __port_enable function should only be used after __port_disable function.
+ *
+ * The caller needs to hold lock for protection.
  */
-static void port_enable(struct platform_device *pdev)
+void __port_enable(struct platform_device *pdev)
 {
 	struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	void __iomem *base;
@@ -54,13 +56,14 @@ static void port_enable(struct platform_device *pdev)
 #define RST_POLL_TIMEOUT 1000 /* us */
 
 /**
- * port_disable - disable a port
+ * __port_disable - disable a port
  * @pdev: port platform device.
  *
- * Disable Port by setting the port soft reset bit, it puts the port into
- * reset.
+ * Disable Port by setting the port soft reset bit, it puts the port into reset.
+ *
+ * The caller needs to hold lock for protection.
  */
-static int port_disable(struct platform_device *pdev)
+int __port_disable(struct platform_device *pdev)
 {
 	struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	void __iomem *base;
@@ -106,9 +109,9 @@ static int __port_reset(struct platform_device *pdev)
 {
 	int ret;
 
-	ret = port_disable(pdev);
+	ret = __port_disable(pdev);
 	if (!ret)
-		port_enable(pdev);
+		__port_enable(pdev);
 
 	return ret;
 }
@@ -810,9 +813,9 @@ static int port_enable_set(struct platform_device *pdev, bool enable)
 
 	mutex_lock(&pdata->lock);
 	if (enable)
-		port_enable(pdev);
+		__port_enable(pdev);
 	else
-		ret = port_disable(pdev);
+		ret = __port_disable(pdev);
 	mutex_unlock(&pdata->lock);
 
 	return ret;
drivers/fpga/dfl-afu.h +3 -0
index 0c7630a..35e60c5 100644
@@ -79,6 +79,9 @@ struct dfl_afu {
 	struct dfl_feature_platform_data *pdata;
 };
 
+void __port_enable(struct platform_device *pdev);
+int __port_disable(struct platform_device *pdev);
+
 void afu_mmio_region_init(struct dfl_feature_platform_data *pdata);
 int afu_mmio_region_add(struct dfl_feature_platform_data *pdata,
 			u32 region_index, u64 region_size, u64 phys, u32 flags);
Signature · 1 line
2.7.4
Acked-by
#38 lore raw

Re: [PATCH 10/17] fpga: dfl: afu: export __port_enable/disable function.

On Tue, Apr 2, 2019 at 10:50 AM Moritz Fischer <[email protected]> wrote:

Hi Hao,

Quoted 9 lines · Wu Hao
Quoted 6 lines

As these two functions are used by other private features. e.g. in error reporting private feature, it requires to check port status and reset port for error clearing.

Thanks,
Alan

author
#39 lore raw

PATCH 11/17 fpga: dfl: afu: add error reporting support.

In reply to Wu Hao

Error reporting is one important private feature, it reports error detected on port and accelerated function unit (AFU). It introduces several sysfs interfaces to allow userspace to check and clear errors detected by hardware.

---
 Documentation/ABI/testing/sysfs-platform-dfl-port |  29 +++
 drivers/fpga/Makefile                             |   1 +
 drivers/fpga/dfl-afu-error.c                      | 225 ++++++++++++++++++++++
 drivers/fpga/dfl-afu-main.c                       |   4 +
 drivers/fpga/dfl-afu.h                            |   4 +
 5 files changed, 263 insertions(+)
 create mode 100644 drivers/fpga/dfl-afu-error.c
Documentation/ABI/testing/sysfs-platform-dfl-port +29 -0
index f611e47..e6140aa 100644
@@ -79,3 +79,32 @@ KernelVersion:	5.2
 Contact:	Wu Hao <[email protected]>
 Description:	Read-only. Read this file to get the status of issued command
 		to userclck_freqcntrcmd.
+
+What:		/sys/bus/platform/devices/dfl-port.0/errors/errors
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get errors detected on port and
+		Accelerated Function Unit (AFU).
+
+What:		/sys/bus/platform/devices/dfl-port.0/errors/first_error
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the first error detected by
+		hardware.
+
+What:		/sys/bus/platform/devices/dfl-port.0/errors/first_malformed_req
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the first malformed request
+		captured by hardware.
+
+What:		/sys/bus/platform/devices/dfl-port.0/errors/clear
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Write-only. Write error code to this file to clear errors. If
+		the input error code doesn't match, it returns -EBUSY error
+		code.
drivers/fpga/Makefile +1 -0
index c0dd4c8..f1f0af7 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_FPGA_DFL_AFU)		+= dfl-afu.o
 
 dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
+dfl-afu-objs += dfl-afu-error.o
 
 # Drivers for FPGAs which implement DFL
 obj-$(CONFIG_FPGA_DFL_PCI)		+= dfl-pci.o
drivers/fpga/dfl-afu-error.c new file +225 -0

225 lines not on this page · raw message

drivers/fpga/dfl-afu-main.c +4 -0
index e727d9b..754729e 100644
@@ -528,6 +528,10 @@ static struct dfl_feature_driver port_feature_drvs[] = {
 		.ops = &port_afu_ops,
 	},
 	{
+		.id_table = port_err_id_table,
+		.ops = &port_err_ops,
+	},
+	{
 		.ops = NULL,
 	}
 };
drivers/fpga/dfl-afu.h +4 -0
index 35e60c5..c3182a2 100644
@@ -100,4 +100,8 @@ int afu_dma_unmap_region(struct dfl_feature_platform_data *pdata, u64 iova);
 struct dfl_afu_dma_region *
 afu_dma_region_find(struct dfl_feature_platform_data *pdata,
 		    u64 iova, u64 size);
+
+extern const struct dfl_feature_ops port_err_ops;
+extern const struct dfl_feature_id port_err_id_table[];
+
 #endif /* __DFL_AFU_H */
Signature · 1 line
2.7.4
#40 lore raw

Re: [PATCH 11/17] fpga: dfl: afu: add error reporting support.

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 44 lines

Error reporting is one important private feature, it reports error detected on port and accelerated function unit (AFU). It introduces several sysfs interfaces to allow userspace to check and clear errors detected by hardware.

---
 Documentation/ABI/testing/sysfs-platform-dfl-port |  29 +++
 drivers/fpga/Makefile                             |   1 +
 drivers/fpga/dfl-afu-error.c                      | 225 ++++++++++++++++++++++
 drivers/fpga/dfl-afu-main.c                       |   4 +
 drivers/fpga/dfl-afu.h                            |   4 +
 5 files changed, 263 insertions(+)
 create mode 100644 drivers/fpga/dfl-afu-error.c
Documentation/ABI/testing/sysfs-platform-dfl-port +19 -0
index f611e47..e6140aa 100644
@@ -79,3 +79,32 @@ KernelVersion:       5.2
 Contact:       Wu Hao <[email protected]>
 Description:   Read-only. Read this file to get the status of issued command
                to userclck_freqcntrcmd.
+
+What:          /sys/bus/platform/devices/dfl-port.0/errors/errors
+Date:          March 2019
+KernelVersion: 5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get errors detected on port and
+               Accelerated Function Unit (AFU).
+
+What:          /sys/bus/platform/devices/dfl-port.0/errors/first_error
+Date:          March 2019
+KernelVersion: 5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get the first error detected by
+               hardware.
+
+What:          /sys/bus/platform/devices/dfl-port.0/errors/first_malformed_req
+Date:          March 2019
+KernelVersion: 5.2
+Contact:       Wu Hao <[email protected]>

Documentation/ABI/testing/sysfs-platform-dfl-port KernelVersion: 5.2 · line 110

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-port +10 -0
+Description:   Read-only. Read this file to get the first malformed request
+               captured by hardware.
+
+What:          /sys/bus/platform/devices/dfl-port.0/errors/clear
+Date:          March 2019
+KernelVersion: 5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Write-only. Write error code to this file to clear errors. If
+               the input error code doesn't match, it returns -EBUSY error
+               code.

I understand how -EBUSY could be the right error code for when the hardware is in a state where the error can't be cleared. But if the input error code doesn't match, shouldn't the code be -EINVAL? Also as noted below, the way this is currently coded, -ETIMEDOUT could get returned.

Quoted 80 lines
drivers/fpga/Makefile +1 -0
index c0dd4c8..f1f0af7 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_FPGA_DFL_AFU)            += dfl-afu.o
 
 dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
+dfl-afu-objs += dfl-afu-error.o
 
 # Drivers for FPGAs which implement DFL
 obj-$(CONFIG_FPGA_DFL_PCI)             += dfl-pci.o
drivers/fpga/dfl-afu-error.c new file +62 -0
new file mode 100644
index 0000000..b66bd4a
@@ -0,0 +1,225 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for FPGA Accelerated Function Unit (AFU) Error Reporting
+ *
+ * Copyright 2019 Intel Corporation, Inc.
+ *
+ * Authors:
+ *   Wu Hao <[email protected]>
+ *   Xiao Guangrong <[email protected]>
+ *   Joseph Grecco <[email protected]>
+ *   Enno Luebbers <[email protected]>
+ *   Tim Whisonant <[email protected]>
+ *   Ananda Ravuri <[email protected]>
+ *   Mitchel Henry <[email protected]>
+ */
+
+#include <linux/uaccess.h>
+
+#include "dfl-afu.h"
+
+#define PORT_ERROR_MASK                0x8
+#define PORT_ERROR             0x10
+#define PORT_FIRST_ERROR       0x18
+#define PORT_MALFORMED_REQ0    0x20
+#define PORT_MALFORMED_REQ1    0x28
+
+#define ERROR_MASK             GENMASK_ULL(63, 0)
+
+/* mask or unmask port errors by the error mask register. */
+static void __port_err_mask(struct device *dev, bool mask)
+{
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+
+       writeq(mask ? ERROR_MASK : 0, base + PORT_ERROR_MASK);
+}
+
+/* clear port errors. */
+static int __port_err_clear(struct device *dev, u64 err)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       void __iomem *base_err, *base_hdr;
+       int ret;
+       u64 v;
+
+       base_err = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+       base_hdr = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_HEADER);
+
+       /*
+        * clear Port Errors
+        *
+        * - Check for AP6 State
+        * - Halt Port by keeping Port in reset
+        * - Set PORT Error mask to all 1 to mask errors
+        * - Clear all errors
+        * - Set Port mask to all 0 to enable errors
+        * - All errors start capturing new errors
+        * - Enable Port by pulling the port out of reset
+        */
+
+       /* if device is still in AP6 power state, can not clear any error. */

drivers/fpga/dfl-afu-error.c line 72

Quoted 10 lines
drivers/fpga/dfl-afu-error.c new file +10 -0
+       v = readq(base_hdr + PORT_HDR_STS);
+       if (FIELD_GET(PORT_STS_PWR_STATE, v) == PORT_STS_PWR_STATE_AP6) {
+               dev_err(dev, "Could not clear errors, device in AP6 state.\n");
+               return -EBUSY;
+       }
+
+       /* Halt Port by keeping Port in reset */
+       ret = __port_disable(pdev);
+       if (ret)
+               return ret;

__port_disable can return -ETIMEDOUT which will then get returned from clear_store. The sysfs document only talks about -EBUSY. You could either document -ETIMEDOUT in the sysfs doc or you could change the code to adjust the returned error code.

Quoted 25 lines
drivers/fpga/dfl-afu-error.c new file +25 -0
+
+       /* Mask all errors */
+       __port_err_mask(dev, true);
+
+       /* Clear errors if err input matches with current port errors.*/
+       v = readq(base_err + PORT_ERROR);
+
+       if (v == err) {
+               writeq(v, base_err + PORT_ERROR);
+
+               v = readq(base_err + PORT_FIRST_ERROR);
+               writeq(v, base_err + PORT_FIRST_ERROR);
+       } else {
+               ret = -EBUSY;
+       }
+
+       /* Clear mask */
+       __port_err_mask(dev, false);
+
+       /* Enable the Port by clear the reset */
+       __port_enable(pdev);
+
+       return ret;
+}
+

drivers/fpga/dfl-afu-error.c line 107

Quoted 10 lines
drivers/fpga/dfl-afu-error.c new file +10 -0
+static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", dfl_feature_revision(base));
+}
+static DEVICE_ATTR_RO(revision);

This appears to be adding a /sys/bus/platform/devices/dfl-port.0/errors/revision attribute that isn't documented in the sysfs document.

Quoted 147 lines
drivers/fpga/dfl-afu-error.c new file +118 -0
+
+static ssize_t errors_show(struct device *dev, struct device_attribute *attr,
+                          char *buf)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u64 error;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+
+       mutex_lock(&pdata->lock);
+       error = readq(base + PORT_ERROR);
+       mutex_unlock(&pdata->lock);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n", (unsigned long long)error);
+}
+static DEVICE_ATTR_RO(errors);
+
+static ssize_t first_error_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u64 error;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+
+       mutex_lock(&pdata->lock);
+       error = readq(base + PORT_FIRST_ERROR);
+       mutex_unlock(&pdata->lock);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n", (unsigned long long)error);
+}
+static DEVICE_ATTR_RO(first_error);
+
+static ssize_t first_malformed_req_show(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u64 req0, req1;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+
+       mutex_lock(&pdata->lock);
+       req0 = readq(base + PORT_MALFORMED_REQ0);
+       req1 = readq(base + PORT_MALFORMED_REQ1);
+       mutex_unlock(&pdata->lock);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%016llx%016llx\n",
+                        (unsigned long long)req1, (unsigned long long)req0);
+}
+static DEVICE_ATTR_RO(first_malformed_req);
+
+static ssize_t clear_store(struct device *dev, struct device_attribute *attr,
+                          const char *buff, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       u64 value;
+       int ret;
+
+       if (kstrtou64(buff, 0, &value))
+               return -EINVAL;
+
+       mutex_lock(&pdata->lock);
+       ret = __port_err_clear(dev, value);
+       mutex_unlock(&pdata->lock);
+
+       return ret ? ret : count;
+}
+static DEVICE_ATTR_WO(clear);
+
+static struct attribute *port_err_attrs[] = {
+       &dev_attr_revision.attr,
+       &dev_attr_errors.attr,
+       &dev_attr_first_error.attr,
+       &dev_attr_first_malformed_req.attr,
+       &dev_attr_clear.attr,
+       NULL,
+};
+
+static struct attribute_group port_err_attr_group = {
+       .attrs = port_err_attrs,
+       .name = "errors",
+};
+
+static int port_err_init(struct platform_device *pdev,
+                        struct dfl_feature *feature)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
+
+       dev_dbg(&pdev->dev, "PORT ERR Init.\n");
+
+       mutex_lock(&pdata->lock);
+       __port_err_mask(&pdev->dev, false);
+       mutex_unlock(&pdata->lock);
+
+       return sysfs_create_group(&pdev->dev.kobj, &port_err_attr_group);
+}
+
+static void port_err_uinit(struct platform_device *pdev,
+                          struct dfl_feature *feature)
+{
+       dev_dbg(&pdev->dev, "PORT ERR UInit.\n");
+
+       sysfs_remove_group(&pdev->dev.kobj, &port_err_attr_group);
+}
+
+const struct dfl_feature_id port_err_id_table[] = {
+       {.id = PORT_FEATURE_ID_ERROR,},
+       {0,}
+};
+
+const struct dfl_feature_ops port_err_ops = {
+       .init = port_err_init,
+       .uinit = port_err_uinit,
+};
drivers/fpga/dfl-afu-main.c +4 -0
index e727d9b..754729e 100644
@@ -528,6 +528,10 @@ static struct dfl_feature_driver port_feature_drvs[] = {
                .ops = &port_afu_ops,
        },
        {
+               .id_table = port_err_id_table,
+               .ops = &port_err_ops,
+       },
+       {
                .ops = NULL,
        }
 };
drivers/fpga/dfl-afu.h +4 -1
index 35e60c5..c3182a2 100644
@@ -100,4 +100,8 @@ int afu_dma_unmap_region(struct dfl_feature_platform_data *pdata, u64 iova);
 struct dfl_afu_dma_region *
 afu_dma_region_find(struct dfl_feature_platform_data *pdata,
                    u64 iova, u64 size);
+
+extern const struct dfl_feature_ops port_err_ops;
+extern const struct dfl_feature_id port_err_id_table[];
+
 #endif /* __DFL_AFU_H */
--
Quoted 2 lines

2.7.4

Thanks,
Alan

author
#41 lore raw

Re: [PATCH 11/17] fpga: dfl: afu: add error reporting support.

Quoted 56 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 52 lines

Error reporting is one important private feature, it reports error detected on port and accelerated function unit (AFU). It introduces several sysfs interfaces to allow userspace to check and clear errors detected by hardware.

---
 Documentation/ABI/testing/sysfs-platform-dfl-port |  29 +++
 drivers/fpga/Makefile                             |   1 +
 drivers/fpga/dfl-afu-error.c                      | 225 ++++++++++++++++++++++
 drivers/fpga/dfl-afu-main.c                       |   4 +
 drivers/fpga/dfl-afu.h                            |   4 +
 5 files changed, 263 insertions(+)
 create mode 100644 drivers/fpga/dfl-afu-error.c
Documentation/ABI/testing/sysfs-platform-dfl-port +27 -0
index f611e47..e6140aa 100644
@@ -79,3 +79,32 @@ KernelVersion:       5.2
 Contact:       Wu Hao <[email protected]>
 Description:   Read-only. Read this file to get the status of issued command
                to userclck_freqcntrcmd.
+
+What:          /sys/bus/platform/devices/dfl-port.0/errors/errors
+Date:          March 2019
+KernelVersion: 5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get errors detected on port and
+               Accelerated Function Unit (AFU).
+
+What:          /sys/bus/platform/devices/dfl-port.0/errors/first_error
+Date:          March 2019
+KernelVersion: 5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get the first error detected by
+               hardware.
+
+What:          /sys/bus/platform/devices/dfl-port.0/errors/first_malformed_req
+Date:          March 2019
+KernelVersion: 5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get the first malformed request
+               captured by hardware.
+
+What:          /sys/bus/platform/devices/dfl-port.0/errors/clear
+Date:          March 2019
+KernelVersion: 5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Write-only. Write error code to this file to clear errors. If
Quoted 8 lines

Documentation/ABI/testing/sysfs-platform-dfl-port KernelVersion: 5.2 · line 110

Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-dfl-port +2 -0
+               the input error code doesn't match, it returns -EBUSY error
+               code.

I understand how -EBUSY could be the right error code for when the hardware is in a state where the error can't be cleared. But if the input error code doesn't match, shouldn't the code be -EINVAL? Also as noted below, the way this is currently coded, -ETIMEDOUT could get returned.

Thanks for the comments, let me try to capture all possible error return values in doc in the next version to avoid confusion.

Quoted 88 lines
Quoted 88 lines
drivers/fpga/Makefile +1 -0
index c0dd4c8..f1f0af7 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_FPGA_DFL_AFU)            += dfl-afu.o
 
 dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
+dfl-afu-objs += dfl-afu-error.o
 
 # Drivers for FPGAs which implement DFL
 obj-$(CONFIG_FPGA_DFL_PCI)             += dfl-pci.o
drivers/fpga/dfl-afu-error.c new file +69 -0
new file mode 100644
index 0000000..b66bd4a
@@ -0,0 +1,225 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for FPGA Accelerated Function Unit (AFU) Error Reporting
+ *
+ * Copyright 2019 Intel Corporation, Inc.
+ *
+ * Authors:
+ *   Wu Hao <[email protected]>
+ *   Xiao Guangrong <[email protected]>
+ *   Joseph Grecco <[email protected]>
+ *   Enno Luebbers <[email protected]>
+ *   Tim Whisonant <[email protected]>
+ *   Ananda Ravuri <[email protected]>
+ *   Mitchel Henry <[email protected]>
+ */
+
+#include <linux/uaccess.h>
+
+#include "dfl-afu.h"
+
+#define PORT_ERROR_MASK                0x8
+#define PORT_ERROR             0x10
+#define PORT_FIRST_ERROR       0x18
+#define PORT_MALFORMED_REQ0    0x20
+#define PORT_MALFORMED_REQ1    0x28
+
+#define ERROR_MASK             GENMASK_ULL(63, 0)
+
+/* mask or unmask port errors by the error mask register. */
+static void __port_err_mask(struct device *dev, bool mask)
+{
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+
+       writeq(mask ? ERROR_MASK : 0, base + PORT_ERROR_MASK);
+}
+
+/* clear port errors. */
+static int __port_err_clear(struct device *dev, u64 err)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       void __iomem *base_err, *base_hdr;
+       int ret;
+       u64 v;
+
+       base_err = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+       base_hdr = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_HEADER);
+
+       /*
+        * clear Port Errors
+        *
+        * - Check for AP6 State
+        * - Halt Port by keeping Port in reset
+        * - Set PORT Error mask to all 1 to mask errors
+        * - Clear all errors
+        * - Set Port mask to all 0 to enable errors
+        * - All errors start capturing new errors
+        * - Enable Port by pulling the port out of reset
+        */
+
+       /* if device is still in AP6 power state, can not clear any error. */
+       v = readq(base_hdr + PORT_HDR_STS);
+       if (FIELD_GET(PORT_STS_PWR_STATE, v) == PORT_STS_PWR_STATE_AP6) {
+               dev_err(dev, "Could not clear errors, device in AP6 state.\n");
+               return -EBUSY;
+       }
+
+       /* Halt Port by keeping Port in reset */
Quoted 8 lines

drivers/fpga/dfl-afu-error.c line 72

Quoted 3 lines
drivers/fpga/dfl-afu-error.c new file +3 -0
+       ret = __port_disable(pdev);
+       if (ret)
+               return ret;

__port_disable can return -ETIMEDOUT which will then get returned from clear_store. The sysfs document only talks about -EBUSY. You could either document -ETIMEDOUT in the sysfs doc or you could change the code to adjust the returned error code.

Yes, agree.

Quoted 32 lines
Quoted 32 lines
drivers/fpga/dfl-afu-error.c new file +31 -0
+
+       /* Mask all errors */
+       __port_err_mask(dev, true);
+
+       /* Clear errors if err input matches with current port errors.*/
+       v = readq(base_err + PORT_ERROR);
+
+       if (v == err) {
+               writeq(v, base_err + PORT_ERROR);
+
+               v = readq(base_err + PORT_FIRST_ERROR);
+               writeq(v, base_err + PORT_FIRST_ERROR);
+       } else {
+               ret = -EBUSY;
+       }
+
+       /* Clear mask */
+       __port_err_mask(dev, false);
+
+       /* Enable the Port by clear the reset */
+       __port_enable(pdev);
+
+       return ret;
+}
+
+static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
Quoted 8 lines

drivers/fpga/dfl-afu-error.c line 107

Quoted 4 lines
drivers/fpga/dfl-afu-error.c new file +4 -0
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", dfl_feature_revision(base));
+}
+static DEVICE_ATTR_RO(revision);

This appears to be adding a /sys/bus/platform/devices/dfl-port.0/errors/revision attribute that isn't documented in the sysfs document.

Sorry, will fix all above issues in the next version.

Thanks again for the code review and comments.

Hao

author
#42 lore raw

PATCH 12/17 fpga: dfl: afu: add STP (SignalTap) support

In reply to Wu Hao

STP (SignalTap) is one of the private features under the port for debugging. This patch adds private feature driver support for it to allow userspace applications to mmap related mmio region and provide STP service.

---
 drivers/fpga/dfl-afu-main.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/fpga/dfl-afu-main.c +34 -0
index 754729e..14970a4 100644
@@ -518,6 +518,36 @@ static const struct dfl_feature_ops port_afu_ops = {
 	.uinit = port_afu_uinit,
 };
 
+static int port_stp_init(struct platform_device *pdev,
+			 struct dfl_feature *feature)
+{
+	struct resource *res = &pdev->resource[feature->resource_index];
+
+	dev_dbg(&pdev->dev, "PORT STP Init.\n");
+
+	return afu_mmio_region_add(dev_get_platdata(&pdev->dev),
+				   DFL_PORT_REGION_INDEX_STP,
+				   resource_size(res), res->start,
+				   DFL_PORT_REGION_MMAP | DFL_PORT_REGION_READ |
+				   DFL_PORT_REGION_WRITE);
+}
+
+static void port_stp_uinit(struct platform_device *pdev,
+			   struct dfl_feature *feature)
+{
+	dev_dbg(&pdev->dev, "PORT STP UInit.\n");
+}
+
+static const struct dfl_feature_id port_stp_id_table[] = {
+	{.id = PORT_FEATURE_ID_STP,},
+	{0,}
+};
+
+static const struct dfl_feature_ops port_stp_ops = {
+	.init = port_stp_init,
+	.uinit = port_stp_uinit,
+};
+
 static struct dfl_feature_driver port_feature_drvs[] = {
 	{
 		.id_table = port_hdr_id_table,
@@ -532,6 +562,10 @@ static struct dfl_feature_driver port_feature_drvs[] = {
 		.ops = &port_err_ops,
 	},
 	{
+		.id_table = port_stp_id_table,
+		.ops = &port_stp_ops,
+	},
+	{
 		.ops = NULL,
 	}
 };
Signature · 1 line
2.7.4
maintainer Acked-by on v1 12/17
#43 lore raw

Re: [PATCH 12/17] fpga: dfl: afu: add STP (SignalTap) support

Hi Wu,

Quoted 7 lines · Wu Hao

STP (SignalTap) is one of the private features under the port for debugging. This patch adds private feature driver support for it to allow userspace applications to mmap related mmio region and provide STP service.

Quoted 59 lines
---
 drivers/fpga/dfl-afu-main.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/fpga/dfl-afu-main.c +34 -0
index 754729e..14970a4 100644
@@ -518,6 +518,36 @@ static const struct dfl_feature_ops port_afu_ops = {
 	.uinit = port_afu_uinit,
 };
 
+static int port_stp_init(struct platform_device *pdev,
+			 struct dfl_feature *feature)
+{
+	struct resource *res = &pdev->resource[feature->resource_index];
+
+	dev_dbg(&pdev->dev, "PORT STP Init.\n");
+
+	return afu_mmio_region_add(dev_get_platdata(&pdev->dev),
+				   DFL_PORT_REGION_INDEX_STP,
+				   resource_size(res), res->start,
+				   DFL_PORT_REGION_MMAP | DFL_PORT_REGION_READ |
+				   DFL_PORT_REGION_WRITE);
+}
+
+static void port_stp_uinit(struct platform_device *pdev,
+			   struct dfl_feature *feature)
+{
+	dev_dbg(&pdev->dev, "PORT STP UInit.\n");
+}
+
+static const struct dfl_feature_id port_stp_id_table[] = {
+	{.id = PORT_FEATURE_ID_STP,},
+	{0,}
+};
+
+static const struct dfl_feature_ops port_stp_ops = {
+	.init = port_stp_init,
+	.uinit = port_stp_uinit,
+};
+
 static struct dfl_feature_driver port_feature_drvs[] = {
 	{
 		.id_table = port_hdr_id_table,
@@ -532,6 +562,10 @@ static struct dfl_feature_driver port_feature_drvs[] = {
 		.ops = &port_err_ops,
 	},
 	{
+		.id_table = port_stp_id_table,
+		.ops = &port_stp_ops,
+	},
+	{
 		.ops = NULL,
 	}
 };
Signature · 1 line
2.7.4

Thanks,
Moritz

Acked-by
#44 lore raw

Re: [PATCH 12/17] fpga: dfl: afu: add STP (SignalTap) support

Quoted 4 lines · Moritz Fischer

Hi Wu,

On Mon, Mar 25, 2019 at 11:07:39AM +0800, Wu Hao wrote:

Quoted 8 lines
Quoted 7 lines

STP (SignalTap) is one of the private features under the port for debugging. This patch adds private feature driver support for it to allow userspace applications to mmap related mmio region and provide STP service.

Thanks,
Alan

author
#45 lore raw

PATCH 13/17 fpga: dfl: fme: add capability sysfs interfaces

In reply to Wu Hao

This patch adds 3 read-only sysfs interfaces for FPGA Management Engine (FME) block for capabilities including cache_size, fabric_version and socket_id.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme | 23 ++++++++++++
 drivers/fpga/dfl-fme-main.c                      | 48 ++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +23 -0
index 8fa4feb..b8327e9 100644
@@ -21,3 +21,26 @@ Contact:	Wu Hao <[email protected]>
 Description:	Read-only. It returns Bitstream (static FPGA region) meta
 		data, which includes the synthesis date, seed and other
 		information of this static FPGA region.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/cache_size
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns cache size of this FPGA device.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/fabric_version
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns fabric version of this FPGA device.
+		Userspace applications need this information to select
+		best data channels per different fabric design.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/socket_id
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns socket_id to indicate which socket
+		this FPGA belongs to, only valid for integrated solution.
+		User only needs this information, in case standard numa node
+		can't provide correct information.
drivers/fpga/dfl-fme-main.c +48 -0

58 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v1 13/17
#46 lore raw

Re: [PATCH 13/17] fpga: dfl: fme: add capability sysfs interfaces

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Looks good...

Quoted 8 lines

This patch adds 3 read-only sysfs interfaces for FPGA Management Engine (FME) block for capabilities including cache_size, fabric_version and socket_id.

Thanks,
Alan

Quoted 102 lines
---
 Documentation/ABI/testing/sysfs-platform-dfl-fme | 23 ++++++++++++
 drivers/fpga/dfl-fme-main.c                      | 48 ++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +23 -0
index 8fa4feb..b8327e9 100644
@@ -21,3 +21,26 @@ Contact:     Wu Hao <[email protected]>
 Description:   Read-only. It returns Bitstream (static FPGA region) meta
                data, which includes the synthesis date, seed and other
                information of this static FPGA region.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/cache_size
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns cache size of this FPGA device.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/fabric_version
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns fabric version of this FPGA device.
+               Userspace applications need this information to select
+               best data channels per different fabric design.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/socket_id
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns socket_id to indicate which socket
+               this FPGA belongs to, only valid for integrated solution.
+               User only needs this information, in case standard numa node
+               can't provide correct information.
drivers/fpga/dfl-fme-main.c +48 -1
index 38c6342..8339ee8 100644
@@ -75,10 +75,58 @@ static ssize_t bitstream_metadata_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(bitstream_metadata);
 
+static ssize_t cache_size_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
+
+       v = readq(base + FME_HDR_CAP);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(FME_CAP_CACHE_SIZE, v));
+}
+static DEVICE_ATTR_RO(cache_size);
+
+static ssize_t fabric_version_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
+
+       v = readq(base + FME_HDR_CAP);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(FME_CAP_FABRIC_VERID, v));
+}
+static DEVICE_ATTR_RO(fabric_version);
+
+static ssize_t socket_id_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
+
+       v = readq(base + FME_HDR_CAP);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(FME_CAP_SOCKET_ID, v));
+}
+static DEVICE_ATTR_RO(socket_id);
+
 static const struct attribute *fme_hdr_attrs[] = {
        &dev_attr_ports_num.attr,
        &dev_attr_bitstream_id.attr,
        &dev_attr_bitstream_metadata.attr,
+       &dev_attr_cache_size.attr,
+       &dev_attr_fabric_version.attr,
+       &dev_attr_socket_id.attr,
        NULL,
 };
 
--

2.7.4

author
#47 lore raw

PATCH 14/17 fpga: dfl: fme: add thermal management support

In reply to Wu Hao

This patch adds support to thermal management private feature for DFL FPGA Management Engine (FME). As thermal throttling is handled by hardware automatically per pre-defined thresholds, this private feature driver only provides read-only sysfs interfaces for user to read temperature, thresholds, threshold policy and other info.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++++
 drivers/fpga/dfl-fme-main.c                      | 202 +++++++++++++++++++++++
 2 files changed, 258 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +56 -0
index b8327e9..d3aeb88 100644
@@ -44,3 +44,59 @@ Description:	Read-only. It returns socket_id to indicate which socket
 		this FPGA belongs to, only valid for integrated solution.
 		User only needs this information, in case standard numa node
 		can't provide correct information.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/temperature
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns temperature (in Celsius) of this FPGA
+		device.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold1
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold2
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/trip_threshold
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns trip threshold (in Celsius), once FPGA
+		temperature reaches trip threshold, it triggers a fatal event
+		to board management controller (BMC) to shutdown FPGA.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold1,
+		otherwise 0. Once temperature reaches threshold1, hardware
+		will automatically enter throttling state (AP1 - 50%
+		or AP2 - 90% throttling, see 'threshold1_policy').
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold2,
+		otherwise 0. Once temperature reaches threshold2, hardware
+		will automatically enter the deepest throttling state (AP6
+		- 100% throttling).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_policy
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the policy of temperature
+		threshold1. It only supports two value (policy):
+		    0 - AP2 state (90% throttling)
+		    1 - AP1 state (50% throttling)
drivers/fpga/dfl-fme-main.c +202 -0

220 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#48 lore raw

Re: [PATCH 14/17] fpga: dfl: fme: add thermal management support

Hi Wu,

Quoted 69 lines · Wu Hao

This patch adds support to thermal management private feature for DFL FPGA Management Engine (FME). As thermal throttling is handled by hardware automatically per pre-defined thresholds, this private feature driver only provides read-only sysfs interfaces for user to read temperature, thresholds, threshold policy and other info.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++++
 drivers/fpga/dfl-fme-main.c                      | 202 +++++++++++++++++++++++
 2 files changed, 258 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +46 -0
index b8327e9..d3aeb88 100644
@@ -44,3 +44,59 @@ Description:	Read-only. It returns socket_id to indicate which socket
 		this FPGA belongs to, only valid for integrated solution.
 		User only needs this information, in case standard numa node
 		can't provide correct information.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/temperature
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns temperature (in Celsius) of this FPGA
+		device.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold1
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold2
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/trip_threshold
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns trip threshold (in Celsius), once FPGA
+		temperature reaches trip threshold, it triggers a fatal event
+		to board management controller (BMC) to shutdown FPGA.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold1,
+		otherwise 0. Once temperature reaches threshold1, hardware
+		will automatically enter throttling state (AP1 - 50%
+		or AP2 - 90% throttling, see 'threshold1_policy').
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold2,
+		otherwise 0. Once temperature reaches threshold2, hardware
+		will automatically enter the deepest throttling state (AP6

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. It returns socket_id to indicate which socket · line 102

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+		- 100% throttling).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_policy
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the policy of temperature
+		threshold1. It only supports two value (policy):
+		    0 - AP2 state (90% throttling)
+		    1 - AP1 state (50% throttling)

These look like they could directly map to the linux thermal framework, any reason you can't use the thermal framework?

The trip stuff literally maps 1:1 to what a thermal driver does, I think that's something you'd wanna consider.

Cheers,
Moritz

author
#49 lore raw

Re: [PATCH 14/17] fpga: dfl: fme: add thermal management support

Quoted 86 lines · Moritz Fischer

Hi Wu,

Quoted 69 lines · Wu Hao

This patch adds support to thermal management private feature for DFL FPGA Management Engine (FME). As thermal throttling is handled by hardware automatically per pre-defined thresholds, this private feature driver only provides read-only sysfs interfaces for user to read temperature, thresholds, threshold policy and other info.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++++
 drivers/fpga/dfl-fme-main.c                      | 202 +++++++++++++++++++++++
 2 files changed, 258 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +46 -0
index b8327e9..d3aeb88 100644
@@ -44,3 +44,59 @@ Description:	Read-only. It returns socket_id to indicate which socket
 		this FPGA belongs to, only valid for integrated solution.
 		User only needs this information, in case standard numa node
 		can't provide correct information.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/temperature
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns temperature (in Celsius) of this FPGA
+		device.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold1
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold2
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/trip_threshold
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns trip threshold (in Celsius), once FPGA
+		temperature reaches trip threshold, it triggers a fatal event
+		to board management controller (BMC) to shutdown FPGA.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold1,
+		otherwise 0. Once temperature reaches threshold1, hardware
+		will automatically enter throttling state (AP1 - 50%
+		or AP2 - 90% throttling, see 'threshold1_policy').
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold2,
+		otherwise 0. Once temperature reaches threshold2, hardware
+		will automatically enter the deepest throttling state (AP6

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. It returns socket_id to indicate which socket · line 102

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+		- 100% throttling).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_policy
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the policy of temperature
+		threshold1. It only supports two value (policy):
+		    0 - AP2 state (90% throttling)
+		    1 - AP1 state (50% throttling)

These look like they could directly map to the linux thermal framework, any reason you can't use the thermal framework?

Quoted 3 lines

The trip stuff literally maps 1:1 to what a thermal driver does, I think that's something you'd wanna consider.

Hi Moritz,

Thanks a lot for the suggestion, actually I feel that the trip points in thermal zone are used to indicate cooling actions required for thermal software either in kernel or userspace. But in this case, such FPGA hardware handles cooling automatically (yes, driver only expose Read-only sysfs for information), so software doesn't need to take care of this at all. For this purpose, it seems that we don't have to put these thresholds as trip points. And per my understanding, if people use such FPGA device, then they may need to know what's the current hardware throttling behavior, e.g. 50% vs 90%. These information can't be provided by standard thermal zone sysfs, so anyway user needs these sysfs interfaces to know it. But it seems that we still could create a thermal zone without trip points, it could help if user wants to connect some external cooling devices via userspace thermal daemon, they can define whatever trip points they like to activate the external cooling device. I will consider this further more and come up with a new patch in v2 patchset.

Thanks
Hao

Quoted 2 lines

Cheers,
Moritz

maintainer
#50 lore raw

Re: [PATCH 14/17] fpga: dfl: fme: add thermal management support

Hi Hao,

Quoted 93 lines · Wu Hao
Quoted 86 lines · Moritz Fischer

Hi Wu,

Quoted 69 lines · Wu Hao

This patch adds support to thermal management private feature for DFL FPGA Management Engine (FME). As thermal throttling is handled by hardware automatically per pre-defined thresholds, this private feature driver only provides read-only sysfs interfaces for user to read temperature, thresholds, threshold policy and other info.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++++
 drivers/fpga/dfl-fme-main.c                      | 202 +++++++++++++++++++++++
 2 files changed, 258 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +46 -0
index b8327e9..d3aeb88 100644
@@ -44,3 +44,59 @@ Description:	Read-only. It returns socket_id to indicate which socket
 		this FPGA belongs to, only valid for integrated solution.
 		User only needs this information, in case standard numa node
 		can't provide correct information.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/temperature
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns temperature (in Celsius) of this FPGA
+		device.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold1
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold2
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/trip_threshold
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns trip threshold (in Celsius), once FPGA
+		temperature reaches trip threshold, it triggers a fatal event
+		to board management controller (BMC) to shutdown FPGA.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold1,
+		otherwise 0. Once temperature reaches threshold1, hardware
+		will automatically enter throttling state (AP1 - 50%
+		or AP2 - 90% throttling, see 'threshold1_policy').
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold2,
+		otherwise 0. Once temperature reaches threshold2, hardware
+		will automatically enter the deepest throttling state (AP6

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. It returns socket_id to indicate which socket · line 102

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+		- 100% throttling).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_policy
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the policy of temperature
+		threshold1. It only supports two value (policy):
+		    0 - AP2 state (90% throttling)
+		    1 - AP1 state (50% throttling)

These look like they could directly map to the linux thermal framework, any reason you can't use the thermal framework?

Quoted 3 lines

The trip stuff literally maps 1:1 to what a thermal driver does, I think that's something you'd wanna consider.

Hi Moritz,

Quoted 15 lines

Thanks a lot for the suggestion, actually I feel that the trip points in thermal zone are used to indicate cooling actions required for thermal software either in kernel or userspace. But in this case, such FPGA hardware handles cooling automatically (yes, driver only expose Read-only sysfs for information), so software doesn't need to take care of this at all. For this purpose, it seems that we don't have to put these thresholds as trip points. And per my understanding, if people use such FPGA device, then they may need to know what's the current hardware throttling behavior, e.g. 50% vs 90%. These information can't be provided by standard thermal zone sysfs, so anyway user needs these sysfs interfaces to know it. But it seems that we still could create a thermal zone without trip points, it could help if user wants to connect some external cooling devices via userspace thermal daemon, they can define whatever trip points they like to activate the external cooling device. I will consider this further more and come up with a new patch in v2 patchset.

Generally speaking extending an existing framework with the functionality you want is preferable over rolling 100% your own.

So please look into this.

Thanks,
Moritz

author
#51 lore raw

Re: [PATCH 14/17] fpga: dfl: fme: add thermal management support

Quoted 112 lines · Moritz Fischer

Hi Hao,

Quoted 93 lines · Wu Hao
Quoted 86 lines · Moritz Fischer

Hi Wu,

Quoted 69 lines · Wu Hao

This patch adds support to thermal management private feature for DFL FPGA Management Engine (FME). As thermal throttling is handled by hardware automatically per pre-defined thresholds, this private feature driver only provides read-only sysfs interfaces for user to read temperature, thresholds, threshold policy and other info.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++++
 drivers/fpga/dfl-fme-main.c                      | 202 +++++++++++++++++++++++
 2 files changed, 258 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +46 -0
index b8327e9..d3aeb88 100644
@@ -44,3 +44,59 @@ Description:	Read-only. It returns socket_id to indicate which socket
 		this FPGA belongs to, only valid for integrated solution.
 		User only needs this information, in case standard numa node
 		can't provide correct information.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/temperature
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns temperature (in Celsius) of this FPGA
+		device.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold1
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the temperature threshold2
+		(in Celsius).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/trip_threshold
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns trip threshold (in Celsius), once FPGA
+		temperature reaches trip threshold, it triggers a fatal event
+		to board management controller (BMC) to shutdown FPGA.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold1,
+		otherwise 0. Once temperature reaches threshold1, hardware
+		will automatically enter throttling state (AP1 - 50%
+		or AP2 - 90% throttling, see 'threshold1_policy').
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold2_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if temperature reaches threshold2,
+		otherwise 0. Once temperature reaches threshold2, hardware
+		will automatically enter the deepest throttling state (AP6

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. It returns socket_id to indicate which socket · line 102

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+		- 100% throttling).
+
+What:		/sys/bus/platform/devices/dfl-fme.0/thermal_mgmt/threshold1_policy
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the policy of temperature
+		threshold1. It only supports two value (policy):
+		    0 - AP2 state (90% throttling)
+		    1 - AP1 state (50% throttling)

These look like they could directly map to the linux thermal framework, any reason you can't use the thermal framework?

Quoted 3 lines

The trip stuff literally maps 1:1 to what a thermal driver does, I think that's something you'd wanna consider.

Hi Moritz,

Quoted 15 lines

Thanks a lot for the suggestion, actually I feel that the trip points in thermal zone are used to indicate cooling actions required for thermal software either in kernel or userspace. But in this case, such FPGA hardware handles cooling automatically (yes, driver only expose Read-only sysfs for information), so software doesn't need to take care of this at all. For this purpose, it seems that we don't have to put these thresholds as trip points. And per my understanding, if people use such FPGA device, then they may need to know what's the current hardware throttling behavior, e.g. 50% vs 90%. These information can't be provided by standard thermal zone sysfs, so anyway user needs these sysfs interfaces to know it. But it seems that we still could create a thermal zone without trip points, it could help if user wants to connect some external cooling devices via userspace thermal daemon, they can define whatever trip points they like to activate the external cooling device. I will consider this further more and come up with a new patch in v2 patchset.

Quoted 4 lines

Generally speaking extending an existing framework with the functionality you want is preferable over rolling 100% your own.

So please look into this.

Yes, agree, will look into this and try to fix this in next version.

Thanks for the comments.

Hao

Quoted 3 lines

Thanks,
Moritz

author
#52 lore raw

PATCH 15/17 fpga: dfl: fme: add power management support

In reply to Wu Hao

This patch adds support for power management private feature under FPGA Management Engine (FME), sysfs interfaces are introduced for different power management functions, users could use these sysfs interface to get current number of consumed power, throttling thresholds, threshold status and other information, and configure different value for throttling thresholds too.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++
 drivers/fpga/dfl-fme-main.c                      | 257 +++++++++++++++++++++++
 2 files changed, 313 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +56 -0
index d3aeb88..4b6448f 100644
@@ -100,3 +100,59 @@ Description:	Read-only. Read this file to get the policy of temperature
 		threshold1. It only supports two value (policy):
 		    0 - AP2 state (90% throttling)
 		    1 - AP1 state (50% throttling)
+
+What:		/sys/bus/platform/devices/dfl-fme.0/power_mgmt/consumed
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns current power consumed by FPGA.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Write. Read/Write this file to get/set current power
+		threshold1 in Watts.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Write. Read/Write this file to get/set current power
+		threshold2 in Watts.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if power consumption reaches the
+		threshold1, otherwise 0.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2_status
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns 1 if power consumption reaches the
+		threshold2, otherwise 0.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/power_mgmt/ltr
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get current Latency Tolerance
+		Reporting (ltr) value, it's only valid for integrated
+		solution as it blocks CPU on low power state.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/power_mgmt/xeon_limit
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get power limit for xeon, it
+		is only valid for integrated solution.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/power_mgmt/fpga_limit
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get power limit for fpga, it
+		is only valid for integrated solution.
drivers/fpga/dfl-fme-main.c +257 -0

269 lines not on this page · raw message

Signature · 1 line
2.7.4
#53 lore raw

Re: [PATCH 15/17] fpga: dfl: fme: add power management support

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 5 lines

This patch adds support for power management private feature under FPGA Management Engine (FME), sysfs interfaces are introduced for different power management functions, users could use these sysfs interface to get current number of consumed power, throttling

How about
s/number/measurement/
?

Quoted 16 lines

thresholds, threshold status and other information, and configure different value for throttling thresholds too.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++
 drivers/fpga/dfl-fme-main.c                      | 257 +++++++++++++++++++++++
 2 files changed, 313 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +0 -0
index d3aeb88..4b6448f 100644

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 108

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +6 -0
@@ -100,3 +100,59 @@ Description:       Read-only. Read this file to get the policy of temperature
                threshold1. It only supports two value (policy):
                    0 - AP2 state (90% throttling)
                    1 - AP1 state (50% throttling)
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/consumed
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns current power consumed by FPGA.

What are the units?

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 115

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold1 in Watts.

Perhaps document error codes here and for threshold2 below.

Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +4 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2
+Date:          March 2019
+KernelVersion:  5.2

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 129

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold2 in Watts.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold1, otherwise 0.

I'm used to things like this requiring user to reset the status, so it may be worth making it explicit that it will return to zero if consumption drops below threshold if that's what's happening here. If it's correct, perhaps could just say something like 'returns 1 if power consumption is currently at or above threshold1, otherwise 0'

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 136

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold2, otherwise 0.

Same here.

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 144

Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +8 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/ltr
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get current Latency Tolerance
+               Reporting (ltr) value, it's only valid for integrated
+               solution as it blocks CPU on low power state.

If we're not on the integrated solution, it returns a value but it is not really real?

Quoted 39 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +14 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/xeon_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for xeon, it
+               is only valid for integrated solution.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/fpga_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for fpga, it
+               is only valid for integrated solution.
drivers/fpga/dfl-fme-main.c +17 -0
index 449a17d..dafa6580 100644
@@ -415,6 +415,259 @@ static const struct dfl_feature_ops fme_thermal_mgmt_ops = {
        .uinit = fme_thermal_mgmt_uinit,
 };
 
+#define FME_PWR_STATUS         0x8
+#define FME_LATENCY_TOLERANCE  BIT_ULL(18)
+#define PWR_CONSUMED           GENMASK_ULL(17, 0)
+
+#define FME_PWR_THRESHOLD      0x10
+#define PWR_THRESHOLD1         GENMASK_ULL(6, 0)       /* in Watts */
+#define PWR_THRESHOLD2         GENMASK_ULL(14, 8)      /* in Watts */
+#define PWR_THRESHOLD_MAX      0x7f
+#define PWR_THRESHOLD1_STATUS  BIT_ULL(16)
+#define PWR_THRESHOLD2_STATUS  BIT_ULL(17)
+
+#define FME_PWR_XEON_LIMIT     0x18
+#define XEON_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define XEON_PWR_EN            BIT_ULL(15)
+#define FME_PWR_FPGA_LIMIT     0x20
+#define FPGA_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define FPGA_PWR_EN            BIT_ULL(15)

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 444

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+
+#define POWER_ATTR(_name, _mode, _show, _store)        \
+struct device_attribute power_attr_##_name =           \
+       __ATTR(_name, _mode, _show, _store)
+
+#define POWER_ATTR_RO(_name, _show)                    \
+       POWER_ATTR(_name, 0444, _show, NULL)
+
+#define POWER_ATTR_RW(_name, _show, _store)            \
+       POWER_ATTR(_name, 0644, _show, _store)

Are these #defines necessary? Seems like you could just use DEVICE_ATTR*

Quoted 186 lines
drivers/fpga/dfl-fme-main.c +186 -0
+
+static ssize_t pwr_consumed_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_CONSUMED, v));
+}
+static POWER_ATTR_RO(consumed, pwr_consumed_show);
+
+static ssize_t pwr_threshold1_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1, v));
+}
+
+static ssize_t pwr_threshold1_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD1;
+       v |= FIELD_PREP(PWR_THRESHOLD1, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold1, pwr_threshold1_show, pwr_threshold1_store);
+
+static ssize_t pwr_threshold2_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2, v));
+}
+
+static ssize_t pwr_threshold2_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD2;
+       v |= FIELD_PREP(PWR_THRESHOLD2, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold2, pwr_threshold2_show, pwr_threshold2_store);
+
+static ssize_t pwr_threshold1_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1_STATUS, v));
+}
+static POWER_ATTR_RO(threshold1_status, pwr_threshold1_status_show);
+
+static ssize_t pwr_threshold2_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2_STATUS, v));
+}
+static POWER_ATTR_RO(threshold2_status, pwr_threshold2_status_show);
+
+static ssize_t ltr_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(FME_LATENCY_TOLERANCE, v));
+}
+static POWER_ATTR_RO(ltr, ltr_show);
+
+static ssize_t xeon_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 xeon_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_XEON_LIMIT);
+
+       if (FIELD_GET(XEON_PWR_EN, v))
+               xeon_limit = FIELD_GET(XEON_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", xeon_limit);
+}
+static POWER_ATTR_RO(xeon_limit, xeon_limit_show);
+
+static ssize_t fpga_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 fpga_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_FPGA_LIMIT);
+
+       if (FIELD_GET(FPGA_PWR_EN, v))
+               fpga_limit = FIELD_GET(FPGA_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", fpga_limit);
+}
+static POWER_ATTR_RO(fpga_limit, fpga_limit_show);

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 640

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+
+static struct attribute *power_mgmt_attrs[] = {
+       &power_attr_consumed.attr,
+       &power_attr_threshold1.attr,
+       &power_attr_threshold2.attr,
+       &power_attr_threshold1_status.attr,
+       &power_attr_threshold2_status.attr,
+       &power_attr_xeon_limit.attr,
+       &power_attr_fpga_limit.attr,
+       &power_attr_ltr.attr,

This is a nit, but I would expect to see these listed in the same order as their show/store functions above. So ltr_attr would come between threshold2_status_attr and xeon_limit_attr.

Quoted 45 lines
drivers/fpga/dfl-fme-main.c +34 -1
+       NULL,
+};
+
+static struct attribute_group power_mgmt_attr_group = {
+       .attrs  = power_mgmt_attrs,
+       .name   = "power_mgmt",
+};
+
+static int fme_power_mgmt_init(struct platform_device *pdev,
+                              struct dfl_feature *feature)
+{
+       return sysfs_create_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static void fme_power_mgmt_uinit(struct platform_device *pdev,
+                                struct dfl_feature *feature)
+{
+       sysfs_remove_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static const struct dfl_feature_id fme_power_mgmt_id_table[] = {
+       {.id = FME_FEATURE_ID_POWER_MGMT,},
+       {0,}
+};
+
+static const struct dfl_feature_ops fme_power_mgmt_ops = {
+       .init = fme_power_mgmt_init,
+       .uinit = fme_power_mgmt_uinit,
+};
+
 static struct dfl_feature_driver fme_feature_drvs[] = {
        {
                .id_table = fme_hdr_id_table,
@@ -429,6 +682,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
                .ops = &fme_thermal_mgmt_ops,
        },
        {
+               .id_table = fme_power_mgmt_id_table,
+               .ops = &fme_power_mgmt_ops,
+       },
+       {
                .ops = NULL,
        },
 };
--
Quoted 2 lines

2.7.4

Thanks,
Alan

author
#54 lore raw

Re: [PATCH 15/17] fpga: dfl: fme: add power management support

Quoted 5 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

This patch adds support for power management private feature under FPGA Management Engine (FME), sysfs interfaces are introduced for different power management functions, users could use these sysfs interface to get current number of consumed power, throttling

How about
s/number/measurement/
?

Sounds better. : )

Quoted 60 lines
Quoted 17 lines

thresholds, threshold status and other information, and configure different value for throttling thresholds too.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++
 drivers/fpga/dfl-fme-main.c                      | 257 +++++++++++++++++++++++
 2 files changed, 313 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +0 -0
index d3aeb88..4b6448f 100644

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 108

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +6 -0
@@ -100,3 +100,59 @@ Description:       Read-only. Read this file to get the policy of temperature
                threshold1. It only supports two value (policy):
                    0 - AP2 state (90% throttling)
                    1 - AP1 state (50% throttling)
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/consumed
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns current power consumed by FPGA.

What are the units?

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 115

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold1 in Watts.

Perhaps document error codes here and for threshold2 below.

Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +4 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2
+Date:          March 2019
+KernelVersion:  5.2

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 129

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold2 in Watts.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold1, otherwise 0.

I'm used to things like this requiring user to reset the status, so it may be worth making it explicit that it will return to zero if consumption drops below threshold if that's what's happening here. If it's correct, perhaps could just say something like 'returns 1 if power consumption is currently at or above threshold1, otherwise 0'

Quoted 9 lines

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 136

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold2, otherwise 0.

Same here.

Sure, will fix all above comments in this sysfs doc.

Quoted 12 lines

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 144

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +8 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/ltr
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get current Latency Tolerance
+               Reporting (ltr) value, it's only valid for integrated
+               solution as it blocks CPU on low power state.

If we're not on the integrated solution, it returns a value but it is not really real?

Currently only integrated solution is implementing this private feature, other devices e.g. Intel PAC card is not using this private feature, so user will not see these sysfs interfaces at all.

If in the future, other devices want

Quoted 44 lines
Quoted 44 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +14 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/xeon_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for xeon, it
+               is only valid for integrated solution.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/fpga_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for fpga, it
+               is only valid for integrated solution.
drivers/fpga/dfl-fme-main.c +21 -0
index 449a17d..dafa6580 100644
@@ -415,6 +415,259 @@ static const struct dfl_feature_ops fme_thermal_mgmt_ops = {
        .uinit = fme_thermal_mgmt_uinit,
 };
 
+#define FME_PWR_STATUS         0x8
+#define FME_LATENCY_TOLERANCE  BIT_ULL(18)
+#define PWR_CONSUMED           GENMASK_ULL(17, 0)
+
+#define FME_PWR_THRESHOLD      0x10
+#define PWR_THRESHOLD1         GENMASK_ULL(6, 0)       /* in Watts */
+#define PWR_THRESHOLD2         GENMASK_ULL(14, 8)      /* in Watts */
+#define PWR_THRESHOLD_MAX      0x7f
+#define PWR_THRESHOLD1_STATUS  BIT_ULL(16)
+#define PWR_THRESHOLD2_STATUS  BIT_ULL(17)
+
+#define FME_PWR_XEON_LIMIT     0x18
+#define XEON_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define XEON_PWR_EN            BIT_ULL(15)
+#define FME_PWR_FPGA_LIMIT     0x20
+#define FPGA_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define FPGA_PWR_EN            BIT_ULL(15)
+
+#define POWER_ATTR(_name, _mode, _show, _store)        \
+struct device_attribute power_attr_##_name =           \
+       __ATTR(_name, _mode, _show, _store)
Quoted 8 lines

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 444

Quoted 6 lines
drivers/fpga/dfl-fme-main.c +6 -0
+
+#define POWER_ATTR_RO(_name, _show)                    \
+       POWER_ATTR(_name, 0444, _show, NULL)
+
+#define POWER_ATTR_RW(_name, _show, _store)            \
+       POWER_ATTR(_name, 0644, _show, _store)

Are these #defines necessary? Seems like you could just use DEVICE_ATTR*

Actually it adds a prefix power_attr_xxx there to avoid name conflicts with other ones from different private features, e.g. for the thermal threshold.

Quoted 193 lines
Quoted 193 lines
drivers/fpga/dfl-fme-main.c +192 -0
+
+static ssize_t pwr_consumed_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_CONSUMED, v));
+}
+static POWER_ATTR_RO(consumed, pwr_consumed_show);
+
+static ssize_t pwr_threshold1_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1, v));
+}
+
+static ssize_t pwr_threshold1_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD1;
+       v |= FIELD_PREP(PWR_THRESHOLD1, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold1, pwr_threshold1_show, pwr_threshold1_store);
+
+static ssize_t pwr_threshold2_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2, v));
+}
+
+static ssize_t pwr_threshold2_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD2;
+       v |= FIELD_PREP(PWR_THRESHOLD2, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold2, pwr_threshold2_show, pwr_threshold2_store);
+
+static ssize_t pwr_threshold1_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1_STATUS, v));
+}
+static POWER_ATTR_RO(threshold1_status, pwr_threshold1_status_show);
+
+static ssize_t pwr_threshold2_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2_STATUS, v));
+}
+static POWER_ATTR_RO(threshold2_status, pwr_threshold2_status_show);
+
+static ssize_t ltr_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(FME_LATENCY_TOLERANCE, v));
+}
+static POWER_ATTR_RO(ltr, ltr_show);
+
+static ssize_t xeon_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 xeon_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_XEON_LIMIT);
+
+       if (FIELD_GET(XEON_PWR_EN, v))
+               xeon_limit = FIELD_GET(XEON_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", xeon_limit);
+}
+static POWER_ATTR_RO(xeon_limit, xeon_limit_show);
+
+static ssize_t fpga_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 fpga_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_FPGA_LIMIT);
+
+       if (FIELD_GET(FPGA_PWR_EN, v))
+               fpga_limit = FIELD_GET(FPGA_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", fpga_limit);
+}
+static POWER_ATTR_RO(fpga_limit, fpga_limit_show);
+
+static struct attribute *power_mgmt_attrs[] = {
+       &power_attr_consumed.attr,
+       &power_attr_threshold1.attr,
+       &power_attr_threshold2.attr,
+       &power_attr_threshold1_status.attr,
Quoted 8 lines

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 640

Quoted 4 lines
drivers/fpga/dfl-fme-main.c +4 -0
+       &power_attr_threshold2_status.attr,
+       &power_attr_xeon_limit.attr,
+       &power_attr_fpga_limit.attr,
+       &power_attr_ltr.attr,

This is a nit, but I would expect to see these listed in the same order as their show/store functions above. So ltr_attr would come between threshold2_status_attr and xeon_limit_attr.

Sure, it does make sense.

Quoted 40 lines
Quoted 40 lines
drivers/fpga/dfl-fme-main.c +32 -0
+       NULL,
+};
+
+static struct attribute_group power_mgmt_attr_group = {
+       .attrs  = power_mgmt_attrs,
+       .name   = "power_mgmt",
+};
+
+static int fme_power_mgmt_init(struct platform_device *pdev,
+                              struct dfl_feature *feature)
+{
+       return sysfs_create_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static void fme_power_mgmt_uinit(struct platform_device *pdev,
+                                struct dfl_feature *feature)
+{
+       sysfs_remove_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static const struct dfl_feature_id fme_power_mgmt_id_table[] = {
+       {.id = FME_FEATURE_ID_POWER_MGMT,},
+       {0,}
+};
+
+static const struct dfl_feature_ops fme_power_mgmt_ops = {
+       .init = fme_power_mgmt_init,
+       .uinit = fme_power_mgmt_uinit,
+};
+
 static struct dfl_feature_driver fme_feature_drvs[] = {
        {
                .id_table = fme_hdr_id_table,
@@ -429,6 +682,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
                .ops = &fme_thermal_mgmt_ops,
        },
        {
+               .id_table = fme_power_mgmt_id_table,
+               .ops = &fme_power_mgmt_ops,
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-fme-main.c +2 -1
+       },
+       {
                .ops = NULL,
        },
 };
--

2.7.4

Thanks a lot for the review and comments. :)

Hao

Quoted 3 lines

Thanks,
Alan

#55 lore raw

Re: [PATCH 15/17] fpga: dfl: fme: add power management support

Quoted 103 lines · Wu Hao
Quoted 5 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

This patch adds support for power management private feature under FPGA Management Engine (FME), sysfs interfaces are introduced for different power management functions, users could use these sysfs interface to get current number of consumed power, throttling

How about
s/number/measurement/
?

Sounds better. : )

Quoted 60 lines
Quoted 17 lines

thresholds, threshold status and other information, and configure different value for throttling thresholds too.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++
 drivers/fpga/dfl-fme-main.c                      | 257 +++++++++++++++++++++++
 2 files changed, 313 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +0 -0
index d3aeb88..4b6448f 100644

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 108

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +6 -0
@@ -100,3 +100,59 @@ Description:       Read-only. Read this file to get the policy of temperature
                threshold1. It only supports two value (policy):
                    0 - AP2 state (90% throttling)
                    1 - AP1 state (50% throttling)
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/consumed
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns current power consumed by FPGA.

What are the units?

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 115

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold1 in Watts.

Perhaps document error codes here and for threshold2 below.

Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +4 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2
+Date:          March 2019
+KernelVersion:  5.2

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 129

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold2 in Watts.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold1, otherwise 0.

I'm used to things like this requiring user to reset the status, so it may be worth making it explicit that it will return to zero if consumption drops below threshold if that's what's happening here. If it's correct, perhaps could just say something like 'returns 1 if power consumption is currently at or above threshold1, otherwise 0'

Quoted 9 lines

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 136

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold2, otherwise 0.

Same here.

Sure, will fix all above comments in this sysfs doc.

Quoted 12 lines

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 144

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +8 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/ltr
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get current Latency Tolerance
+               Reporting (ltr) value, it's only valid for integrated
+               solution as it blocks CPU on low power state.

If we're not on the integrated solution, it returns a value but it is not really real?

Quoted 3 lines

Currently only integrated solution is implementing this private feature, other devices e.g. Intel PAC card is not using this private feature, so user will not see these sysfs interfaces at all.

OK then perhaps the "it's only valid for integrated solution as it blocks CPU on low power state" explanation doesn't need to be here and can lead to confusion.

Quoted 56 lines

If in the future, other devices want

Quoted 44 lines
Quoted 44 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +14 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/xeon_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for xeon, it
+               is only valid for integrated solution.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/fpga_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for fpga, it
+               is only valid for integrated solution.
drivers/fpga/dfl-fme-main.c +21 -0
index 449a17d..dafa6580 100644
@@ -415,6 +415,259 @@ static const struct dfl_feature_ops fme_thermal_mgmt_ops = {
        .uinit = fme_thermal_mgmt_uinit,
 };
 
+#define FME_PWR_STATUS         0x8
+#define FME_LATENCY_TOLERANCE  BIT_ULL(18)
+#define PWR_CONSUMED           GENMASK_ULL(17, 0)
+
+#define FME_PWR_THRESHOLD      0x10
+#define PWR_THRESHOLD1         GENMASK_ULL(6, 0)       /* in Watts */
+#define PWR_THRESHOLD2         GENMASK_ULL(14, 8)      /* in Watts */
+#define PWR_THRESHOLD_MAX      0x7f
+#define PWR_THRESHOLD1_STATUS  BIT_ULL(16)
+#define PWR_THRESHOLD2_STATUS  BIT_ULL(17)
+
+#define FME_PWR_XEON_LIMIT     0x18
+#define XEON_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define XEON_PWR_EN            BIT_ULL(15)
+#define FME_PWR_FPGA_LIMIT     0x20
+#define FPGA_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define FPGA_PWR_EN            BIT_ULL(15)
+
+#define POWER_ATTR(_name, _mode, _show, _store)        \
+struct device_attribute power_attr_##_name =           \
+       __ATTR(_name, _mode, _show, _store)
Quoted 8 lines

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 444

Quoted 6 lines
drivers/fpga/dfl-fme-main.c +6 -0
+
+#define POWER_ATTR_RO(_name, _show)                    \
+       POWER_ATTR(_name, 0444, _show, NULL)
+
+#define POWER_ATTR_RW(_name, _show, _store)            \
+       POWER_ATTR(_name, 0644, _show, _store)

Are these #defines necessary? Seems like you could just use DEVICE_ATTR*

Quoted 2 lines

Actually it adds a prefix power_attr_xxx there to avoid name conflicts with other ones from different private features, e.g. for the thermal threshold.

Ah yes, I see it now, thanks.

Quoted 261 lines
Quoted 194 lines
Quoted 194 lines
drivers/fpga/dfl-fme-main.c +192 -0
+
+static ssize_t pwr_consumed_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_CONSUMED, v));
+}
+static POWER_ATTR_RO(consumed, pwr_consumed_show);
+
+static ssize_t pwr_threshold1_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1, v));
+}
+
+static ssize_t pwr_threshold1_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD1;
+       v |= FIELD_PREP(PWR_THRESHOLD1, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold1, pwr_threshold1_show, pwr_threshold1_store);
+
+static ssize_t pwr_threshold2_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2, v));
+}
+
+static ssize_t pwr_threshold2_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD2;
+       v |= FIELD_PREP(PWR_THRESHOLD2, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold2, pwr_threshold2_show, pwr_threshold2_store);
+
+static ssize_t pwr_threshold1_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1_STATUS, v));
+}
+static POWER_ATTR_RO(threshold1_status, pwr_threshold1_status_show);
+
+static ssize_t pwr_threshold2_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2_STATUS, v));
+}
+static POWER_ATTR_RO(threshold2_status, pwr_threshold2_status_show);
+
+static ssize_t ltr_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(FME_LATENCY_TOLERANCE, v));
+}
+static POWER_ATTR_RO(ltr, ltr_show);
+
+static ssize_t xeon_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 xeon_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_XEON_LIMIT);
+
+       if (FIELD_GET(XEON_PWR_EN, v))
+               xeon_limit = FIELD_GET(XEON_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", xeon_limit);
+}
+static POWER_ATTR_RO(xeon_limit, xeon_limit_show);
+
+static ssize_t fpga_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 fpga_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_FPGA_LIMIT);
+
+       if (FIELD_GET(FPGA_PWR_EN, v))
+               fpga_limit = FIELD_GET(FPGA_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", fpga_limit);
+}
+static POWER_ATTR_RO(fpga_limit, fpga_limit_show);
+
+static struct attribute *power_mgmt_attrs[] = {
+       &power_attr_consumed.attr,
+       &power_attr_threshold1.attr,
+       &power_attr_threshold2.attr,
+       &power_attr_threshold1_status.attr,
Quoted 8 lines

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 640

Quoted 4 lines
drivers/fpga/dfl-fme-main.c +4 -0
+       &power_attr_threshold2_status.attr,
+       &power_attr_xeon_limit.attr,
+       &power_attr_fpga_limit.attr,
+       &power_attr_ltr.attr,

This is a nit, but I would expect to see these listed in the same order as their show/store functions above. So ltr_attr would come between threshold2_status_attr and xeon_limit_attr.

Sure, it does make sense.

Quoted 40 lines
Quoted 40 lines
drivers/fpga/dfl-fme-main.c +32 -0
+       NULL,
+};
+
+static struct attribute_group power_mgmt_attr_group = {
+       .attrs  = power_mgmt_attrs,
+       .name   = "power_mgmt",
+};
+
+static int fme_power_mgmt_init(struct platform_device *pdev,
+                              struct dfl_feature *feature)
+{
+       return sysfs_create_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static void fme_power_mgmt_uinit(struct platform_device *pdev,
+                                struct dfl_feature *feature)
+{
+       sysfs_remove_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static const struct dfl_feature_id fme_power_mgmt_id_table[] = {
+       {.id = FME_FEATURE_ID_POWER_MGMT,},
+       {0,}
+};
+
+static const struct dfl_feature_ops fme_power_mgmt_ops = {
+       .init = fme_power_mgmt_init,
+       .uinit = fme_power_mgmt_uinit,
+};
+
 static struct dfl_feature_driver fme_feature_drvs[] = {
        {
                .id_table = fme_hdr_id_table,
@@ -429,6 +682,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
                .ops = &fme_thermal_mgmt_ops,
        },
        {
+               .id_table = fme_power_mgmt_id_table,
+               .ops = &fme_power_mgmt_ops,
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-fme-main.c +2 -1
+       },
+       {
                .ops = NULL,
        },
 };
--

2.7.4

Thanks a lot for the review and comments. :)

Hao

Quoted 3 lines

Thanks,
Alan

author
#56 lore raw

Re: [PATCH 15/17] fpga: dfl: fme: add power management support

Quoted 104 lines · Alan Tull
Quoted 103 lines · Wu Hao
Quoted 5 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

This patch adds support for power management private feature under FPGA Management Engine (FME), sysfs interfaces are introduced for different power management functions, users could use these sysfs interface to get current number of consumed power, throttling

How about
s/number/measurement/
?

Sounds better. : )

Quoted 60 lines
Quoted 17 lines

thresholds, threshold status and other information, and configure different value for throttling thresholds too.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++
 drivers/fpga/dfl-fme-main.c                      | 257 +++++++++++++++++++++++
 2 files changed, 313 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +0 -0
index d3aeb88..4b6448f 100644

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 108

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +6 -0
@@ -100,3 +100,59 @@ Description:       Read-only. Read this file to get the policy of temperature
                threshold1. It only supports two value (policy):
                    0 - AP2 state (90% throttling)
                    1 - AP1 state (50% throttling)
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/consumed
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns current power consumed by FPGA.

What are the units?

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 115

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold1 in Watts.

Perhaps document error codes here and for threshold2 below.

Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +4 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2
+Date:          March 2019
+KernelVersion:  5.2

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 129

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold2 in Watts.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold1, otherwise 0.

I'm used to things like this requiring user to reset the status, so it may be worth making it explicit that it will return to zero if consumption drops below threshold if that's what's happening here. If it's correct, perhaps could just say something like 'returns 1 if power consumption is currently at or above threshold1, otherwise 0'

Quoted 9 lines

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 136

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold2, otherwise 0.

Same here.

Sure, will fix all above comments in this sysfs doc.

Quoted 12 lines

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 144

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +8 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/ltr
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get current Latency Tolerance
+               Reporting (ltr) value, it's only valid for integrated
+               solution as it blocks CPU on low power state.

If we're not on the integrated solution, it returns a value but it is not really real?

Quoted 8 lines
Quoted 3 lines

Currently only integrated solution is implementing this private feature, other devices e.g. Intel PAC card is not using this private feature, so user will not see these sysfs interfaces at all.

OK then perhaps the "it's only valid for integrated solution as it blocks CPU on low power state" explanation doesn't need to be here and can lead to confusion.

Sure, will fix it in the next version. Thanks!

Hao

#57 lore raw

Re: [PATCH 15/17] fpga: dfl: fme: add power management support

In reply to Alan Tull

Hi Hao,

this looks suspiciously like a hwmon driver ;-)

https://www.kernel.org/doc/Documentation/hwmon/hwmon-kernel-api.txt

Cheers,
Moritz

Quoted 399 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 5 lines

This patch adds support for power management private feature under FPGA Management Engine (FME), sysfs interfaces are introduced for different power management functions, users could use these sysfs interface to get current number of consumed power, throttling

How about
s/number/measurement/
?

Quoted 16 lines

thresholds, threshold status and other information, and configure different value for throttling thresholds too.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++
 drivers/fpga/dfl-fme-main.c                      | 257 +++++++++++++++++++++++
 2 files changed, 313 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +0 -0
index d3aeb88..4b6448f 100644

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 108

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +6 -0
@@ -100,3 +100,59 @@ Description:       Read-only. Read this file to get the policy of temperature
                threshold1. It only supports two value (policy):
                    0 - AP2 state (90% throttling)
                    1 - AP1 state (50% throttling)
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/consumed
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns current power consumed by FPGA.

What are the units?

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 115

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold1 in Watts.

Perhaps document error codes here and for threshold2 below.

Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +4 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2
+Date:          March 2019
+KernelVersion:  5.2

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 129

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold2 in Watts.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold1, otherwise 0.

I'm used to things like this requiring user to reset the status, so it may be worth making it explicit that it will return to zero if consumption drops below threshold if that's what's happening here. If it's correct, perhaps could just say something like 'returns 1 if power consumption is currently at or above threshold1, otherwise 0'

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 136

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold2, otherwise 0.

Same here.

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 144

Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +8 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/ltr
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get current Latency Tolerance
+               Reporting (ltr) value, it's only valid for integrated
+               solution as it blocks CPU on low power state.

If we're not on the integrated solution, it returns a value but it is not really real?

Quoted 39 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +14 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/xeon_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for xeon, it
+               is only valid for integrated solution.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/fpga_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for fpga, it
+               is only valid for integrated solution.
drivers/fpga/dfl-fme-main.c +17 -0
index 449a17d..dafa6580 100644
@@ -415,6 +415,259 @@ static const struct dfl_feature_ops fme_thermal_mgmt_ops = {
        .uinit = fme_thermal_mgmt_uinit,
 };
 
+#define FME_PWR_STATUS         0x8
+#define FME_LATENCY_TOLERANCE  BIT_ULL(18)
+#define PWR_CONSUMED           GENMASK_ULL(17, 0)
+
+#define FME_PWR_THRESHOLD      0x10
+#define PWR_THRESHOLD1         GENMASK_ULL(6, 0)       /* in Watts */
+#define PWR_THRESHOLD2         GENMASK_ULL(14, 8)      /* in Watts */
+#define PWR_THRESHOLD_MAX      0x7f
+#define PWR_THRESHOLD1_STATUS  BIT_ULL(16)
+#define PWR_THRESHOLD2_STATUS  BIT_ULL(17)
+
+#define FME_PWR_XEON_LIMIT     0x18
+#define XEON_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define XEON_PWR_EN            BIT_ULL(15)
+#define FME_PWR_FPGA_LIMIT     0x20
+#define FPGA_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define FPGA_PWR_EN            BIT_ULL(15)

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 444

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+
+#define POWER_ATTR(_name, _mode, _show, _store)        \
+struct device_attribute power_attr_##_name =           \
+       __ATTR(_name, _mode, _show, _store)
+
+#define POWER_ATTR_RO(_name, _show)                    \
+       POWER_ATTR(_name, 0444, _show, NULL)
+
+#define POWER_ATTR_RW(_name, _show, _store)            \
+       POWER_ATTR(_name, 0644, _show, _store)

Are these #defines necessary? Seems like you could just use DEVICE_ATTR*

Quoted 186 lines
drivers/fpga/dfl-fme-main.c +186 -0
+
+static ssize_t pwr_consumed_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_CONSUMED, v));
+}
+static POWER_ATTR_RO(consumed, pwr_consumed_show);
+
+static ssize_t pwr_threshold1_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1, v));
+}
+
+static ssize_t pwr_threshold1_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD1;
+       v |= FIELD_PREP(PWR_THRESHOLD1, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold1, pwr_threshold1_show, pwr_threshold1_store);
+
+static ssize_t pwr_threshold2_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2, v));
+}
+
+static ssize_t pwr_threshold2_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD2;
+       v |= FIELD_PREP(PWR_THRESHOLD2, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold2, pwr_threshold2_show, pwr_threshold2_store);
+
+static ssize_t pwr_threshold1_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1_STATUS, v));
+}
+static POWER_ATTR_RO(threshold1_status, pwr_threshold1_status_show);
+
+static ssize_t pwr_threshold2_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2_STATUS, v));
+}
+static POWER_ATTR_RO(threshold2_status, pwr_threshold2_status_show);
+
+static ssize_t ltr_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(FME_LATENCY_TOLERANCE, v));
+}
+static POWER_ATTR_RO(ltr, ltr_show);
+
+static ssize_t xeon_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 xeon_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_XEON_LIMIT);
+
+       if (FIELD_GET(XEON_PWR_EN, v))
+               xeon_limit = FIELD_GET(XEON_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", xeon_limit);
+}
+static POWER_ATTR_RO(xeon_limit, xeon_limit_show);
+
+static ssize_t fpga_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 fpga_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_FPGA_LIMIT);
+
+       if (FIELD_GET(FPGA_PWR_EN, v))
+               fpga_limit = FIELD_GET(FPGA_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", fpga_limit);
+}
+static POWER_ATTR_RO(fpga_limit, fpga_limit_show);

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 640

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+
+static struct attribute *power_mgmt_attrs[] = {
+       &power_attr_consumed.attr,
+       &power_attr_threshold1.attr,
+       &power_attr_threshold2.attr,
+       &power_attr_threshold1_status.attr,
+       &power_attr_threshold2_status.attr,
+       &power_attr_xeon_limit.attr,
+       &power_attr_fpga_limit.attr,
+       &power_attr_ltr.attr,

This is a nit, but I would expect to see these listed in the same order as their show/store functions above. So ltr_attr would come between threshold2_status_attr and xeon_limit_attr.

Quoted 45 lines
drivers/fpga/dfl-fme-main.c +34 -1
+       NULL,
+};
+
+static struct attribute_group power_mgmt_attr_group = {
+       .attrs  = power_mgmt_attrs,
+       .name   = "power_mgmt",
+};
+
+static int fme_power_mgmt_init(struct platform_device *pdev,
+                              struct dfl_feature *feature)
+{
+       return sysfs_create_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static void fme_power_mgmt_uinit(struct platform_device *pdev,
+                                struct dfl_feature *feature)
+{
+       sysfs_remove_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static const struct dfl_feature_id fme_power_mgmt_id_table[] = {
+       {.id = FME_FEATURE_ID_POWER_MGMT,},
+       {0,}
+};
+
+static const struct dfl_feature_ops fme_power_mgmt_ops = {
+       .init = fme_power_mgmt_init,
+       .uinit = fme_power_mgmt_uinit,
+};
+
 static struct dfl_feature_driver fme_feature_drvs[] = {
        {
                .id_table = fme_hdr_id_table,
@@ -429,6 +682,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
                .ops = &fme_thermal_mgmt_ops,
        },
        {
+               .id_table = fme_power_mgmt_id_table,
+               .ops = &fme_power_mgmt_ops,
+       },
+       {
                .ops = NULL,
        },
 };
--
Quoted 2 lines

2.7.4

Thanks,
Alan

author
#58 lore raw

Re: [PATCH 15/17] fpga: dfl: fme: add power management support

Quoted 5 lines · Moritz Fischer

Hi Hao,

this looks suspiciously like a hwmon driver ;-)

https://www.kernel.org/doc/Documentation/hwmon/hwmon-kernel-api.txt

Hi Moritz,

Thanks a lot for the suggestion, yes, agree, and patch for thermal management should be the similar case too. Let me see if i can make thermal / power management code to hwmon in the next version. : )

Hao

Quoted 405 lines

Cheers,
Moritz

Quoted 399 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 5 lines

This patch adds support for power management private feature under FPGA Management Engine (FME), sysfs interfaces are introduced for different power management functions, users could use these sysfs interface to get current number of consumed power, throttling

How about
s/number/measurement/
?

Quoted 16 lines

thresholds, threshold status and other information, and configure different value for throttling thresholds too.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  56 +++++
 drivers/fpga/dfl-fme-main.c                      | 257 +++++++++++++++++++++++
 2 files changed, 313 insertions(+)
Documentation/ABI/testing/sysfs-platform-dfl-fme +0 -0
index d3aeb88..4b6448f 100644

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 108

Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +6 -0
@@ -100,3 +100,59 @@ Description:       Read-only. Read this file to get the policy of temperature
                threshold1. It only supports two value (policy):
                    0 - AP2 state (90% throttling)
                    1 - AP1 state (50% throttling)
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/consumed
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns current power consumed by FPGA.

What are the units?

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 115

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold1 in Watts.

Perhaps document error codes here and for threshold2 below.

Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +4 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2
+Date:          March 2019
+KernelVersion:  5.2

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 129

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Read/Write this file to get/set current power
+               threshold2 in Watts.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold1_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold1, otherwise 0.

I'm used to things like this requiring user to reset the status, so it may be worth making it explicit that it will return to zero if consumption drops below threshold if that's what's happening here. If it's correct, perhaps could just say something like 'returns 1 if power consumption is currently at or above threshold1, otherwise 0'

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 136

Quoted 7 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +7 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/threshold2_status
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns 1 if power consumption reaches the
+               threshold2, otherwise 0.

Same here.

Documentation/ABI/testing/sysfs-platform-dfl-fme Description: Read-only. Read this file to get the policy of temperature · line 144

Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +8 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/ltr
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get current Latency Tolerance
+               Reporting (ltr) value, it's only valid for integrated
+               solution as it blocks CPU on low power state.

If we're not on the integrated solution, it returns a value but it is not really real?

Quoted 39 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +14 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/xeon_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for xeon, it
+               is only valid for integrated solution.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/power_mgmt/fpga_limit
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get power limit for fpga, it
+               is only valid for integrated solution.
drivers/fpga/dfl-fme-main.c +17 -0
index 449a17d..dafa6580 100644
@@ -415,6 +415,259 @@ static const struct dfl_feature_ops fme_thermal_mgmt_ops = {
        .uinit = fme_thermal_mgmt_uinit,
 };
 
+#define FME_PWR_STATUS         0x8
+#define FME_LATENCY_TOLERANCE  BIT_ULL(18)
+#define PWR_CONSUMED           GENMASK_ULL(17, 0)
+
+#define FME_PWR_THRESHOLD      0x10
+#define PWR_THRESHOLD1         GENMASK_ULL(6, 0)       /* in Watts */
+#define PWR_THRESHOLD2         GENMASK_ULL(14, 8)      /* in Watts */
+#define PWR_THRESHOLD_MAX      0x7f
+#define PWR_THRESHOLD1_STATUS  BIT_ULL(16)
+#define PWR_THRESHOLD2_STATUS  BIT_ULL(17)
+
+#define FME_PWR_XEON_LIMIT     0x18
+#define XEON_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define XEON_PWR_EN            BIT_ULL(15)
+#define FME_PWR_FPGA_LIMIT     0x20
+#define FPGA_PWR_LIMIT         GENMASK_ULL(14, 0)
+#define FPGA_PWR_EN            BIT_ULL(15)

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 444

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+
+#define POWER_ATTR(_name, _mode, _show, _store)        \
+struct device_attribute power_attr_##_name =           \
+       __ATTR(_name, _mode, _show, _store)
+
+#define POWER_ATTR_RO(_name, _show)                    \
+       POWER_ATTR(_name, 0444, _show, NULL)
+
+#define POWER_ATTR_RW(_name, _show, _store)            \
+       POWER_ATTR(_name, 0644, _show, _store)

Are these #defines necessary? Seems like you could just use DEVICE_ATTR*

Quoted 186 lines
drivers/fpga/dfl-fme-main.c +186 -0
+
+static ssize_t pwr_consumed_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_CONSUMED, v));
+}
+static POWER_ATTR_RO(consumed, pwr_consumed_show);
+
+static ssize_t pwr_threshold1_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1, v));
+}
+
+static ssize_t pwr_threshold1_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD1;
+       v |= FIELD_PREP(PWR_THRESHOLD1, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold1, pwr_threshold1_show, pwr_threshold1_store);
+
+static ssize_t pwr_threshold2_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2, v));
+}
+
+static ssize_t pwr_threshold2_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+       void __iomem *base;
+       u8 threshold;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &threshold);
+       if (ret)
+               return ret;
+
+       if (threshold > PWR_THRESHOLD_MAX)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + FME_PWR_THRESHOLD);
+       v &= ~PWR_THRESHOLD2;
+       v |= FIELD_PREP(PWR_THRESHOLD2, threshold);
+       writeq(v, base + FME_PWR_THRESHOLD);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static POWER_ATTR_RW(threshold2, pwr_threshold2_show, pwr_threshold2_store);
+
+static ssize_t pwr_threshold1_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD1_STATUS, v));
+}
+static POWER_ATTR_RO(threshold1_status, pwr_threshold1_status_show);
+
+static ssize_t pwr_threshold2_status_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_THRESHOLD);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(PWR_THRESHOLD2_STATUS, v));
+}
+static POWER_ATTR_RO(threshold2_status, pwr_threshold2_status_show);
+
+static ssize_t ltr_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_STATUS);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (unsigned int)FIELD_GET(FME_LATENCY_TOLERANCE, v));
+}
+static POWER_ATTR_RO(ltr, ltr_show);
+
+static ssize_t xeon_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 xeon_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_XEON_LIMIT);
+
+       if (FIELD_GET(XEON_PWR_EN, v))
+               xeon_limit = FIELD_GET(XEON_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", xeon_limit);
+}
+static POWER_ATTR_RO(xeon_limit, xeon_limit_show);
+
+static ssize_t fpga_limit_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       void __iomem *base;
+       u16 fpga_limit = 0;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_POWER_MGMT);
+
+       v = readq(base + FME_PWR_FPGA_LIMIT);
+
+       if (FIELD_GET(FPGA_PWR_EN, v))
+               fpga_limit = FIELD_GET(FPGA_PWR_LIMIT, v);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", fpga_limit);
+}
+static POWER_ATTR_RO(fpga_limit, fpga_limit_show);

drivers/fpga/dfl-fme-main.c static const struct dfl_feature_ops fme_thermal_mgmt_ops = { · line 640

Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10 -0
+
+static struct attribute *power_mgmt_attrs[] = {
+       &power_attr_consumed.attr,
+       &power_attr_threshold1.attr,
+       &power_attr_threshold2.attr,
+       &power_attr_threshold1_status.attr,
+       &power_attr_threshold2_status.attr,
+       &power_attr_xeon_limit.attr,
+       &power_attr_fpga_limit.attr,
+       &power_attr_ltr.attr,

This is a nit, but I would expect to see these listed in the same order as their show/store functions above. So ltr_attr would come between threshold2_status_attr and xeon_limit_attr.

Quoted 45 lines
drivers/fpga/dfl-fme-main.c +34 -1
+       NULL,
+};
+
+static struct attribute_group power_mgmt_attr_group = {
+       .attrs  = power_mgmt_attrs,
+       .name   = "power_mgmt",
+};
+
+static int fme_power_mgmt_init(struct platform_device *pdev,
+                              struct dfl_feature *feature)
+{
+       return sysfs_create_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static void fme_power_mgmt_uinit(struct platform_device *pdev,
+                                struct dfl_feature *feature)
+{
+       sysfs_remove_group(&pdev->dev.kobj, &power_mgmt_attr_group);
+}
+
+static const struct dfl_feature_id fme_power_mgmt_id_table[] = {
+       {.id = FME_FEATURE_ID_POWER_MGMT,},
+       {0,}
+};
+
+static const struct dfl_feature_ops fme_power_mgmt_ops = {
+       .init = fme_power_mgmt_init,
+       .uinit = fme_power_mgmt_uinit,
+};
+
 static struct dfl_feature_driver fme_feature_drvs[] = {
        {
                .id_table = fme_hdr_id_table,
@@ -429,6 +682,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
                .ops = &fme_thermal_mgmt_ops,
        },
        {
+               .id_table = fme_power_mgmt_id_table,
+               .ops = &fme_power_mgmt_ops,
+       },
+       {
                .ops = NULL,
        },
 };
--
Quoted 2 lines

2.7.4

Thanks,
Alan

author
#59 lore raw

PATCH 16/17 fpga: dfl: fme: add global error reporting support

In reply to Wu Hao

This patch adds support for global error reporting for FPGA Management Engine (FME), it introduces sysfs interfaces to report different error detected by the hardware, and allow user to clear errors or inject error for testing purpose.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  58 ++++
 drivers/fpga/Makefile                            |   2 +-
 drivers/fpga/dfl-fme-error.c                     | 390 +++++++++++++++++++++++
 drivers/fpga/dfl-fme-main.c                      |   4 +
 drivers/fpga/dfl-fme.h                           |   2 +
 drivers/fpga/dfl.h                               |   2 +
 6 files changed, 457 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fpga/dfl-fme-error.c
Documentation/ABI/testing/sysfs-platform-dfl-fme +58 -0
index 4b6448f..38f9cdd 100644
@@ -156,3 +156,61 @@ KernelVersion:  5.2
 Contact:	Wu Hao <[email protected]>
 Description:	Read-only. Read this file to get power limit for fpga, it
 		is only valid for integrated solution.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/errors
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get errors detected by hardware.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/first_error
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the first error detected by
+		hardware.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/next_error
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. Read this file to get the second error detected by
+		hardware.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/clear
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Write-only. Write error code to this file to clear errors. If
+		the input error code doesn't match, it returns -EBUSY.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/pcie0_errors
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns errors detected on pcie0 link.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/pcie1_errors
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns errors detected on pcie1 link.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/nonfatal_errors
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns non-fatal errors detected.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/catfatal_errors
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-only. It returns catastrophic and fatal errors detected.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/errors/inject_error
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Write. Write this file to inject errors for testing
+		purpose. Read this file to check errors injected.
drivers/fpga/Makefile +1 -1
index f1f0af7..1a9fa3d 100644
@@ -38,7 +38,7 @@ obj-$(CONFIG_FPGA_DFL_FME_BRIDGE)	+= dfl-fme-br.o
 obj-$(CONFIG_FPGA_DFL_FME_REGION)	+= dfl-fme-region.o
 obj-$(CONFIG_FPGA_DFL_AFU)		+= dfl-afu.o
 
-dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
+dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o dfl-fme-error.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
 dfl-afu-objs += dfl-afu-error.o
 
drivers/fpga/dfl-fme-error.c new file +390 -0

390 lines not on this page · raw message

drivers/fpga/dfl-fme-main.c +4 -0
index dafa6580..76cb112 100644
@@ -686,6 +686,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
 		.ops = &fme_power_mgmt_ops,
 	},
 	{
+		.id_table = fme_global_err_id_table,
+		.ops = &fme_global_err_ops,
+	},
+	{
 		.ops = NULL,
 	},
 };
drivers/fpga/dfl-fme.h +2 -0
index 7a021c4..5fbe3f5 100644
@@ -37,5 +37,7 @@ struct dfl_fme {
 
 extern const struct dfl_feature_ops fme_pr_mgmt_ops;
 extern const struct dfl_feature_id fme_pr_mgmt_id_table[];
+extern const struct dfl_feature_ops fme_global_err_ops;
+extern const struct dfl_feature_id fme_global_err_id_table[];
 
 #endif /* __DFL_FME_H */
drivers/fpga/dfl.h +2 -0
index fbc57f0..6c32080 100644
@@ -197,12 +197,14 @@ struct dfl_feature_driver {
  *		    feature dev (platform device)'s reources.
  * @ioaddr: mapped mmio resource address.
  * @ops: ops of this sub feature.
+ * @priv: priv data of this feature.
  */
 struct dfl_feature {
 	u64 id;
 	int resource_index;
 	void __iomem *ioaddr;
 	const struct dfl_feature_ops *ops;
+	void *priv;
 };
 
 #define DEV_STATUS_IN_USE	0
Signature · 1 line
2.7.4
#60 lore raw

Re: [PATCH 16/17] fpga: dfl: fme: add global error reporting support

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 45 lines

This patch adds support for global error reporting for FPGA Management Engine (FME), it introduces sysfs interfaces to report different error detected by the hardware, and allow user to clear errors or inject error for testing purpose.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  58 ++++
 drivers/fpga/Makefile                            |   2 +-
 drivers/fpga/dfl-fme-error.c                     | 390 +++++++++++++++++++++++
 drivers/fpga/dfl-fme-main.c                      |   4 +
 drivers/fpga/dfl-fme.h                           |   2 +
 drivers/fpga/dfl.h                               |   2 +
 6 files changed, 457 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fpga/dfl-fme-error.c
Documentation/ABI/testing/sysfs-platform-dfl-fme +17 -0
index 4b6448f..38f9cdd 100644
@@ -156,3 +156,61 @@ KernelVersion:  5.2
 Contact:       Wu Hao <[email protected]>
 Description:   Read-only. Read this file to get power limit for fpga, it
                is only valid for integrated solution.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get errors detected by hardware.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/first_error
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get the first error detected by
+               hardware.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/next_error
+Date:          March 2019
+KernelVersion:  5.2

Documentation/ABI/testing/sysfs-platform-dfl-fme KernelVersion: 5.2 · line 185

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get the second error detected by
+               hardware.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/clear
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Write-only. Write error code to this file to clear errors. If
+               the input error code doesn't match, it returns -EBUSY.

As with the afu errors patch, seems like -EINVAL would be better.

Quoted 130 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +31 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/pcie0_errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns errors detected on pcie0 link.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/pcie1_errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns errors detected on pcie1 link.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/nonfatal_errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns non-fatal errors detected.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/catfatal_errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns catastrophic and fatal errors detected.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/inject_error
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Write this file to inject errors for testing
+               purpose. Read this file to check errors injected.
drivers/fpga/Makefile +1 -1
index f1f0af7..1a9fa3d 100644
@@ -38,7 +38,7 @@ obj-$(CONFIG_FPGA_DFL_FME_BRIDGE)     += dfl-fme-br.o
 obj-$(CONFIG_FPGA_DFL_FME_REGION)      += dfl-fme-region.o
 obj-$(CONFIG_FPGA_DFL_AFU)             += dfl-afu.o
 
-dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
+dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o dfl-fme-error.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
 dfl-afu-objs += dfl-afu-error.o
 
drivers/fpga/dfl-fme-error.c new file +80 -0
new file mode 100644
index 0000000..f2bd5f8
@@ -0,0 +1,390 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for FPGA Management Engine Error Management
+ *
+ * Copyright 2019 Intel Corporation, Inc.
+ *
+ * Authors:
+ *   Kang Luwei <[email protected]>
+ *   Xiao Guangrong <[email protected]>
+ *   Wu Hao <[email protected]>
+ *   Joseph Grecco <[email protected]>
+ *   Enno Luebbers <[email protected]>
+ *   Tim Whisonant <[email protected]>
+ *   Ananda Ravuri <[email protected]>
+ *   Mitchel, Henry <[email protected]>
+ */
+
+#include <linux/uaccess.h>
+
+#include "dfl.h"
+#include "dfl-fme.h"
+
+#define FME_ERROR_MASK         0x8
+#define FME_ERROR              0x10
+#define MBP_ERROR              BIT_ULL(6)
+#define PCIE0_ERROR_MASK       0x18
+#define PCIE0_ERROR            0x20
+#define PCIE1_ERROR_MASK       0x28
+#define PCIE1_ERROR            0x30
+#define FME_FIRST_ERROR                0x38
+#define FME_NEXT_ERROR         0x40
+#define RAS_NONFAT_ERROR_MASK  0x48
+#define RAS_NONFAT_ERROR       0x50
+#define RAS_CATFAT_ERROR_MASK  0x58
+#define RAS_CATFAT_ERROR       0x60
+#define RAS_ERROR_INJECT       0x68
+#define INJECT_ERROR_MASK      GENMASK_ULL(2, 0)
+
+static ssize_t errors_show(struct device *dev,
+                          struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + FME_ERROR));
+}
+static DEVICE_ATTR_RO(errors);
+
+static ssize_t first_error_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + FME_FIRST_ERROR));
+}
+static DEVICE_ATTR_RO(first_error);
+
+static ssize_t next_error_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + FME_NEXT_ERROR));
+}
+static DEVICE_ATTR_RO(next_error);
+
+static ssize_t clear_store(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
+{

drivers/fpga/dfl-fme-error.c line 90

Quoted 10 lines
drivers/fpga/dfl-fme-error.c new file +10 -0
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
+       struct device *err_dev = dev->parent;
+       struct dfl_feature *feature;
+       void __iomem *base;
+       u64 v, val;
+       int ret;
+
+       ret = kstrtou64(buf, 0, &val);
+       if (ret)
+               return ret;

from kstrtox.c:
* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.

Your sysfs doc could be updated to explain these return codes.

drivers/fpga/dfl-fme-error.c line 100

Quoted 10 lines
drivers/fpga/dfl-fme-error.c new file +10 -0
+
+       feature = dfl_get_feature_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+       base = feature->ioaddr;
+
+       mutex_lock(&pdata->lock);
+       writeq(GENMASK_ULL(63, 0), base + FME_ERROR_MASK);
+
+       v = readq(base + FME_ERROR);
+       if (val != v) {
+               ret = -EINVAL;

Oh wait, that's what I thought it should be ;) so the doc just needs to change.

drivers/fpga/dfl-fme-error.c line 101

Quoted 1 line
drivers/fpga/dfl-fme-error.c new file +1 -0
+               goto done;

It would be easy to avoid using 'goto' here.

Quoted 18 lines
drivers/fpga/dfl-fme-error.c new file +18 -0
+       }
+
+       writeq(v, base + FME_ERROR);
+       v = readq(base + FME_FIRST_ERROR);
+       writeq(v, base + FME_FIRST_ERROR);
+       v = readq(base + FME_NEXT_ERROR);
+       writeq(v, base + FME_NEXT_ERROR);
+
+done:
+       /* Workaround: disable MBP_ERROR if feature revision is 0 */
+       writeq(dfl_feature_revision(feature->ioaddr) ? 0ULL : MBP_ERROR,
+              base + FME_ERROR_MASK);
+       mutex_unlock(&pdata->lock);
+       return ret ? ret : count;
+}
+static DEVICE_ATTR_WO(clear);
+
+static ssize_t revision_show(struct device *dev, struct device_attribute *attr,

drivers/fpga/dfl-fme-error.c line 129

Quoted 10 lines
drivers/fpga/dfl-fme-error.c new file +10 -0
+                            char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", dfl_feature_revision(base));
+}
+static DEVICE_ATTR_RO(revision);

The revision attr to be documented in the sysfs doc.

Quoted 4 lines
drivers/fpga/dfl-fme-error.c new file +4 -0
+
+static ssize_t pcie0_errors_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{

drivers/fpga/dfl-fme-error.c line 143

Quoted 10 lines
drivers/fpga/dfl-fme-error.c new file +10 -0
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + PCIE0_ERROR));
+}
+
+static ssize_t pcie0_errors_store(struct device *dev,

The sysfs doc shows this as read-only.

Quoted 35 lines
drivers/fpga/dfl-fme-error.c new file +35 -0
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+       u64 v, val;
+       int ret;
+
+       ret = kstrtou64(buf, 0, &val);
+       if (ret)
+               return ret;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       mutex_lock(&pdata->lock);
+       writeq(GENMASK_ULL(63, 0), base + PCIE0_ERROR_MASK);
+
+       v = readq(base + PCIE0_ERROR);
+       if (val != v)
+               ret = -EBUSY;
+       else
+               writeq(v, base + PCIE0_ERROR);
+
+       writeq(0ULL, base + PCIE0_ERROR_MASK);
+       mutex_unlock(&pdata->lock);
+       return ret ? ret : count;
+}
+static DEVICE_ATTR_RW(pcie0_errors);
+
+static ssize_t pcie1_errors_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;

drivers/fpga/dfl-fme-error.c line 188

Quoted 10 lines
drivers/fpga/dfl-fme-error.c new file +10 -0
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + PCIE1_ERROR));
+}
+
+static ssize_t pcie1_errors_store(struct device *dev,
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)

Same here, documentation needs to show as R/W and explain what happens when written.

Quoted 249 lines
drivers/fpga/dfl-fme-error.c new file +202 -0
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+       u64 v, val;
+       int ret;
+
+       ret = kstrtou64(buf, 0, &val);
+       if (ret)
+               return ret;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       mutex_lock(&pdata->lock);
+       writeq(GENMASK_ULL(63, 0), base + PCIE1_ERROR_MASK);
+
+       v = readq(base + PCIE1_ERROR);
+       if (val != v)
+               ret = -EBUSY;
+       else
+               writeq(v, base + PCIE1_ERROR);
+
+       writeq(0ULL, base + PCIE1_ERROR_MASK);
+       mutex_unlock(&pdata->lock);
+       return ret ? ret : count;
+}
+static DEVICE_ATTR_RW(pcie1_errors);
+
+static ssize_t nonfatal_errors_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + RAS_NONFAT_ERROR));
+}
+static DEVICE_ATTR_RO(nonfatal_errors);
+
+static ssize_t catfatal_errors_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + RAS_CATFAT_ERROR));
+}
+static DEVICE_ATTR_RO(catfatal_errors);
+
+static ssize_t inject_error_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       v = readq(base + RAS_ERROR_INJECT);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)FIELD_GET(INJECT_ERROR_MASK, v));
+}
+
+static ssize_t inject_error_store(struct device *dev,
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+       u8 inject_error;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &inject_error);
+       if (ret)
+               return ret;
+
+       if (inject_error & ~INJECT_ERROR_MASK)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + RAS_ERROR_INJECT);
+       v &= ~INJECT_ERROR_MASK;
+       v |= FIELD_PREP(INJECT_ERROR_MASK, inject_error);
+       writeq(v, base + RAS_ERROR_INJECT);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static DEVICE_ATTR_RW(inject_error);
+
+static struct attribute *fme_errors_attrs[] = {
+       &dev_attr_errors.attr,
+       &dev_attr_first_error.attr,
+       &dev_attr_next_error.attr,
+       &dev_attr_clear.attr,
+       NULL,
+};
+
+static struct attribute_group fme_errors_attr_group = {
+       .attrs  = fme_errors_attrs,
+       .name   = "fme-errors",
+};
+
+static struct attribute *errors_attrs[] = {
+       &dev_attr_revision.attr,
+       &dev_attr_pcie0_errors.attr,
+       &dev_attr_pcie1_errors.attr,
+       &dev_attr_nonfatal_errors.attr,
+       &dev_attr_catfatal_errors.attr,
+       &dev_attr_inject_error.attr,
+       NULL,
+};
+
+static struct attribute_group errors_attr_group = {
+       .attrs  = errors_attrs,
+};
+
+static const struct attribute_group *error_groups[] = {
+       &fme_errors_attr_group,
+       &errors_attr_group,
+       NULL
+};
+
+static void fme_error_enable(struct dfl_feature *feature)
+{
+       void __iomem *base = feature->ioaddr;
+
+       /* Workaround: disable MBP_ERROR if revision is 0 */
+       writeq(dfl_feature_revision(feature->ioaddr) ? 0ULL : MBP_ERROR,
+              base + FME_ERROR_MASK);
+       writeq(0ULL, base + PCIE0_ERROR_MASK);
+       writeq(0ULL, base + PCIE1_ERROR_MASK);
+       writeq(0ULL, base + RAS_NONFAT_ERROR_MASK);
+       writeq(0ULL, base + RAS_CATFAT_ERROR_MASK);
+}
+
+static void err_dev_release(struct device *dev)
+{
+       kfree(dev);
+}
+
+static int fme_global_err_init(struct platform_device *pdev,
+                              struct dfl_feature *feature)
+{
+       struct device *dev;
+       int ret = 0;
+
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (!dev)
+               return -ENOMEM;
+
+       dev->parent = &pdev->dev;
+       dev->release = err_dev_release;
+       dev_set_name(dev, "errors");
+
+       fme_error_enable(feature);
+
+       ret = device_register(dev);
+       if (ret) {
+               put_device(dev);
+               return ret;
+       }
+
+       ret = sysfs_create_groups(&dev->kobj, error_groups);
+       if (ret) {
+               device_unregister(dev);
+               return ret;
+       }
+
+       feature->priv = dev;
+
+       return ret;
+}
+
+static void fme_global_err_uinit(struct platform_device *pdev,
+                                struct dfl_feature *feature)
+{
+       struct device *dev = feature->priv;
+
+       sysfs_remove_groups(&dev->kobj, error_groups);
+       device_unregister(dev);
+}
+
+const struct dfl_feature_id fme_global_err_id_table[] = {
+       {.id = FME_FEATURE_ID_GLOBAL_ERR,},
+       {0,}
+};
+
+const struct dfl_feature_ops fme_global_err_ops = {
+       .init = fme_global_err_init,
+       .uinit = fme_global_err_uinit,
+};
drivers/fpga/dfl-fme-main.c +4 -0
index dafa6580..76cb112 100644
@@ -686,6 +686,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
                .ops = &fme_power_mgmt_ops,
        },
        {
+               .id_table = fme_global_err_id_table,
+               .ops = &fme_global_err_ops,
+       },
+       {
                .ops = NULL,
        },
 };
drivers/fpga/dfl-fme.h +2 -0
index 7a021c4..5fbe3f5 100644
@@ -37,5 +37,7 @@ struct dfl_fme {
 
 extern const struct dfl_feature_ops fme_pr_mgmt_ops;
 extern const struct dfl_feature_id fme_pr_mgmt_id_table[];
+extern const struct dfl_feature_ops fme_global_err_ops;
+extern const struct dfl_feature_id fme_global_err_id_table[];
 
 #endif /* __DFL_FME_H */
drivers/fpga/dfl.h +2 -1
index fbc57f0..6c32080 100644
@@ -197,12 +197,14 @@ struct dfl_feature_driver {
  *                 feature dev (platform device)'s reources.
  * @ioaddr: mapped mmio resource address.
  * @ops: ops of this sub feature.
+ * @priv: priv data of this feature.
  */
 struct dfl_feature {
        u64 id;
        int resource_index;
        void __iomem *ioaddr;
        const struct dfl_feature_ops *ops;
+       void *priv;
 };
 
 #define DEV_STATUS_IN_USE      0
--
Quoted 2 lines

2.7.4

Thanks,
Alan

author
#61 lore raw

Re: [PATCH 16/17] fpga: dfl: fme: add global error reporting support

Quoted 206 lines · Alan Tull

On Sun, Mar 24, 2019 at 10:24 PM Wu Hao <[email protected]> wrote:

Hi Hao,

Quoted 45 lines

This patch adds support for global error reporting for FPGA Management Engine (FME), it introduces sysfs interfaces to report different error detected by the hardware, and allow user to clear errors or inject error for testing purpose.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  58 ++++
 drivers/fpga/Makefile                            |   2 +-
 drivers/fpga/dfl-fme-error.c                     | 390 +++++++++++++++++++++++
 drivers/fpga/dfl-fme-main.c                      |   4 +
 drivers/fpga/dfl-fme.h                           |   2 +
 drivers/fpga/dfl.h                               |   2 +
 6 files changed, 457 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fpga/dfl-fme-error.c
Documentation/ABI/testing/sysfs-platform-dfl-fme +17 -0
index 4b6448f..38f9cdd 100644
@@ -156,3 +156,61 @@ KernelVersion:  5.2
 Contact:       Wu Hao <[email protected]>
 Description:   Read-only. Read this file to get power limit for fpga, it
                is only valid for integrated solution.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get errors detected by hardware.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/first_error
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get the first error detected by
+               hardware.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/next_error
+Date:          March 2019
+KernelVersion:  5.2

Documentation/ABI/testing/sysfs-platform-dfl-fme KernelVersion: 5.2 · line 185

Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +10 -0
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. Read this file to get the second error detected by
+               hardware.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/fme-errors/clear
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Write-only. Write error code to this file to clear errors. If
+               the input error code doesn't match, it returns -EBUSY.

As with the afu errors patch, seems like -EINVAL would be better.

Quoted 130 lines
Documentation/ABI/testing/sysfs-platform-dfl-fme +31 -0
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/pcie0_errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns errors detected on pcie0 link.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/pcie1_errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns errors detected on pcie1 link.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/nonfatal_errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns non-fatal errors detected.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/catfatal_errors
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-only. It returns catastrophic and fatal errors detected.
+
+What:          /sys/bus/platform/devices/dfl-fme.0/errors/inject_error
+Date:          March 2019
+KernelVersion:  5.2
+Contact:       Wu Hao <[email protected]>
+Description:   Read-Write. Write this file to inject errors for testing
+               purpose. Read this file to check errors injected.
drivers/fpga/Makefile +1 -1
index f1f0af7..1a9fa3d 100644
@@ -38,7 +38,7 @@ obj-$(CONFIG_FPGA_DFL_FME_BRIDGE)     += dfl-fme-br.o
 obj-$(CONFIG_FPGA_DFL_FME_REGION)      += dfl-fme-region.o
 obj-$(CONFIG_FPGA_DFL_AFU)             += dfl-afu.o
 
-dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
+dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o dfl-fme-error.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
 dfl-afu-objs += dfl-afu-error.o
 
drivers/fpga/dfl-fme-error.c new file +80 -0
new file mode 100644
index 0000000..f2bd5f8
@@ -0,0 +1,390 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for FPGA Management Engine Error Management
+ *
+ * Copyright 2019 Intel Corporation, Inc.
+ *
+ * Authors:
+ *   Kang Luwei <[email protected]>
+ *   Xiao Guangrong <[email protected]>
+ *   Wu Hao <[email protected]>
+ *   Joseph Grecco <[email protected]>
+ *   Enno Luebbers <[email protected]>
+ *   Tim Whisonant <[email protected]>
+ *   Ananda Ravuri <[email protected]>
+ *   Mitchel, Henry <[email protected]>
+ */
+
+#include <linux/uaccess.h>
+
+#include "dfl.h"
+#include "dfl-fme.h"
+
+#define FME_ERROR_MASK         0x8
+#define FME_ERROR              0x10
+#define MBP_ERROR              BIT_ULL(6)
+#define PCIE0_ERROR_MASK       0x18
+#define PCIE0_ERROR            0x20
+#define PCIE1_ERROR_MASK       0x28
+#define PCIE1_ERROR            0x30
+#define FME_FIRST_ERROR                0x38
+#define FME_NEXT_ERROR         0x40
+#define RAS_NONFAT_ERROR_MASK  0x48
+#define RAS_NONFAT_ERROR       0x50
+#define RAS_CATFAT_ERROR_MASK  0x58
+#define RAS_CATFAT_ERROR       0x60
+#define RAS_ERROR_INJECT       0x68
+#define INJECT_ERROR_MASK      GENMASK_ULL(2, 0)
+
+static ssize_t errors_show(struct device *dev,
+                          struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + FME_ERROR));
+}
+static DEVICE_ATTR_RO(errors);
+
+static ssize_t first_error_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + FME_FIRST_ERROR));
+}
+static DEVICE_ATTR_RO(first_error);
+
+static ssize_t next_error_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + FME_NEXT_ERROR));
+}
+static DEVICE_ATTR_RO(next_error);
+
+static ssize_t clear_store(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
+{

drivers/fpga/dfl-fme-error.c line 90

Quoted 10 lines
drivers/fpga/dfl-fme-error.c new file +10 -0
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
+       struct device *err_dev = dev->parent;
+       struct dfl_feature *feature;
+       void __iomem *base;
+       u64 v, val;
+       int ret;
+
+       ret = kstrtou64(buf, 0, &val);
+       if (ret)
+               return ret;

from kstrtox.c:
* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.

Quoted 1 line

Your sysfs doc could be updated to explain these return codes.

Sure, will fix this.

Quoted 13 lines

drivers/fpga/dfl-fme-error.c line 100

Quoted 11 lines
drivers/fpga/dfl-fme-error.c new file +10 -0
+
+       feature = dfl_get_feature_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+       base = feature->ioaddr;
+
+       mutex_lock(&pdata->lock);
+       writeq(GENMASK_ULL(63, 0), base + FME_ERROR_MASK);
+
+       v = readq(base + FME_ERROR);
+       if (val != v) {
+               ret = -EINVAL;

Oh wait, that's what I thought it should be ;) so the doc just needs to change.

Sure, will capture the detailed return values in doc.

Quoted 4 lines

drivers/fpga/dfl-fme-error.c line 101

Quoted 2 lines
drivers/fpga/dfl-fme-error.c new file +1 -0
+               goto done;

It would be easy to avoid using 'goto' here.

Yes, agree.

Quoted 23 lines
Quoted 23 lines
drivers/fpga/dfl-fme-error.c new file +22 -0
+       }
+
+       writeq(v, base + FME_ERROR);
+       v = readq(base + FME_FIRST_ERROR);
+       writeq(v, base + FME_FIRST_ERROR);
+       v = readq(base + FME_NEXT_ERROR);
+       writeq(v, base + FME_NEXT_ERROR);
+
+done:
+       /* Workaround: disable MBP_ERROR if feature revision is 0 */
+       writeq(dfl_feature_revision(feature->ioaddr) ? 0ULL : MBP_ERROR,
+              base + FME_ERROR_MASK);
+       mutex_unlock(&pdata->lock);
+       return ret ? ret : count;
+}
+static DEVICE_ATTR_WO(clear);
+
+static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
Quoted 8 lines

drivers/fpga/dfl-fme-error.c line 129

Quoted 6 lines
drivers/fpga/dfl-fme-error.c new file +6 -0
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "%u\n", dfl_feature_revision(base));
+}
+static DEVICE_ATTR_RO(revision);

The revision attr to be documented in the sysfs doc.

Will fix this.

Quoted 58 lines
Quoted 5 lines
drivers/fpga/dfl-fme-error.c new file +4 -0
+
+static ssize_t pcie0_errors_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{

drivers/fpga/dfl-fme-error.c line 143

Quoted 10 lines
drivers/fpga/dfl-fme-error.c new file +10 -0
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + PCIE0_ERROR));
+}
+
+static ssize_t pcie0_errors_store(struct device *dev,

The sysfs doc shows this as read-only.

Quoted 40 lines
drivers/fpga/dfl-fme-error.c new file +40 -0
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+       u64 v, val;
+       int ret;
+
+       ret = kstrtou64(buf, 0, &val);
+       if (ret)
+               return ret;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       mutex_lock(&pdata->lock);
+       writeq(GENMASK_ULL(63, 0), base + PCIE0_ERROR_MASK);
+
+       v = readq(base + PCIE0_ERROR);
+       if (val != v)
+               ret = -EBUSY;
+       else
+               writeq(v, base + PCIE0_ERROR);
+
+       writeq(0ULL, base + PCIE0_ERROR_MASK);
+       mutex_unlock(&pdata->lock);
+       return ret ? ret : count;
+}
+static DEVICE_ATTR_RW(pcie0_errors);
+
+static ssize_t pcie1_errors_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + PCIE1_ERROR));
Quoted 8 lines

drivers/fpga/dfl-fme-error.c line 188

Quoted 5 lines
drivers/fpga/dfl-fme-error.c new file +5 -0
+}
+
+static ssize_t pcie1_errors_store(struct device *dev,
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)

Same here, documentation needs to show as R/W and explain what happens when written.

Sorry, will fix them in doc.

Quoted 248 lines
Quoted 248 lines
drivers/fpga/dfl-fme-error.c new file +202 -0
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+       u64 v, val;
+       int ret;
+
+       ret = kstrtou64(buf, 0, &val);
+       if (ret)
+               return ret;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       mutex_lock(&pdata->lock);
+       writeq(GENMASK_ULL(63, 0), base + PCIE1_ERROR_MASK);
+
+       v = readq(base + PCIE1_ERROR);
+       if (val != v)
+               ret = -EBUSY;
+       else
+               writeq(v, base + PCIE1_ERROR);
+
+       writeq(0ULL, base + PCIE1_ERROR_MASK);
+       mutex_unlock(&pdata->lock);
+       return ret ? ret : count;
+}
+static DEVICE_ATTR_RW(pcie1_errors);
+
+static ssize_t nonfatal_errors_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + RAS_NONFAT_ERROR));
+}
+static DEVICE_ATTR_RO(nonfatal_errors);
+
+static ssize_t catfatal_errors_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)readq(base + RAS_CATFAT_ERROR));
+}
+static DEVICE_ATTR_RO(catfatal_errors);
+
+static ssize_t inject_error_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+       u64 v;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       v = readq(base + RAS_ERROR_INJECT);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
+                        (unsigned long long)FIELD_GET(INJECT_ERROR_MASK, v));
+}
+
+static ssize_t inject_error_store(struct device *dev,
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
+       struct device *err_dev = dev->parent;
+       void __iomem *base;
+       u8 inject_error;
+       int ret;
+       u64 v;
+
+       ret = kstrtou8(buf, 0, &inject_error);
+       if (ret)
+               return ret;
+
+       if (inject_error & ~INJECT_ERROR_MASK)
+               return -EINVAL;
+
+       base = dfl_get_feature_ioaddr_by_id(err_dev, FME_FEATURE_ID_GLOBAL_ERR);
+
+       mutex_lock(&pdata->lock);
+       v = readq(base + RAS_ERROR_INJECT);
+       v &= ~INJECT_ERROR_MASK;
+       v |= FIELD_PREP(INJECT_ERROR_MASK, inject_error);
+       writeq(v, base + RAS_ERROR_INJECT);
+       mutex_unlock(&pdata->lock);
+
+       return count;
+}
+static DEVICE_ATTR_RW(inject_error);
+
+static struct attribute *fme_errors_attrs[] = {
+       &dev_attr_errors.attr,
+       &dev_attr_first_error.attr,
+       &dev_attr_next_error.attr,
+       &dev_attr_clear.attr,
+       NULL,
+};
+
+static struct attribute_group fme_errors_attr_group = {
+       .attrs  = fme_errors_attrs,
+       .name   = "fme-errors",
+};
+
+static struct attribute *errors_attrs[] = {
+       &dev_attr_revision.attr,
+       &dev_attr_pcie0_errors.attr,
+       &dev_attr_pcie1_errors.attr,
+       &dev_attr_nonfatal_errors.attr,
+       &dev_attr_catfatal_errors.attr,
+       &dev_attr_inject_error.attr,
+       NULL,
+};
+
+static struct attribute_group errors_attr_group = {
+       .attrs  = errors_attrs,
+};
+
+static const struct attribute_group *error_groups[] = {
+       &fme_errors_attr_group,
+       &errors_attr_group,
+       NULL
+};
+
+static void fme_error_enable(struct dfl_feature *feature)
+{
+       void __iomem *base = feature->ioaddr;
+
+       /* Workaround: disable MBP_ERROR if revision is 0 */
+       writeq(dfl_feature_revision(feature->ioaddr) ? 0ULL : MBP_ERROR,
+              base + FME_ERROR_MASK);
+       writeq(0ULL, base + PCIE0_ERROR_MASK);
+       writeq(0ULL, base + PCIE1_ERROR_MASK);
+       writeq(0ULL, base + RAS_NONFAT_ERROR_MASK);
+       writeq(0ULL, base + RAS_CATFAT_ERROR_MASK);
+}
+
+static void err_dev_release(struct device *dev)
+{
+       kfree(dev);
+}
+
+static int fme_global_err_init(struct platform_device *pdev,
+                              struct dfl_feature *feature)
+{
+       struct device *dev;
+       int ret = 0;
+
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (!dev)
+               return -ENOMEM;
+
+       dev->parent = &pdev->dev;
+       dev->release = err_dev_release;
+       dev_set_name(dev, "errors");
+
+       fme_error_enable(feature);
+
+       ret = device_register(dev);
+       if (ret) {
+               put_device(dev);
+               return ret;
+       }
+
+       ret = sysfs_create_groups(&dev->kobj, error_groups);
+       if (ret) {
+               device_unregister(dev);
+               return ret;
+       }
+
+       feature->priv = dev;
+
+       return ret;
+}
+
+static void fme_global_err_uinit(struct platform_device *pdev,
+                                struct dfl_feature *feature)
+{
+       struct device *dev = feature->priv;
+
+       sysfs_remove_groups(&dev->kobj, error_groups);
+       device_unregister(dev);
+}
+
+const struct dfl_feature_id fme_global_err_id_table[] = {
+       {.id = FME_FEATURE_ID_GLOBAL_ERR,},
+       {0,}
+};
+
+const struct dfl_feature_ops fme_global_err_ops = {
+       .init = fme_global_err_init,
+       .uinit = fme_global_err_uinit,
+};
drivers/fpga/dfl-fme-main.c +4 -0
index dafa6580..76cb112 100644
@@ -686,6 +686,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
                .ops = &fme_power_mgmt_ops,
        },
        {
+               .id_table = fme_global_err_id_table,
+               .ops = &fme_global_err_ops,
+       },
+       {
                .ops = NULL,
        },
 };
drivers/fpga/dfl-fme.h +2 -0
index 7a021c4..5fbe3f5 100644
@@ -37,5 +37,7 @@ struct dfl_fme {
 
 extern const struct dfl_feature_ops fme_pr_mgmt_ops;
 extern const struct dfl_feature_id fme_pr_mgmt_id_table[];
+extern const struct dfl_feature_ops fme_global_err_ops;
+extern const struct dfl_feature_id fme_global_err_id_table[];
 
 #endif /* __DFL_FME_H */
drivers/fpga/dfl.h +2 -0
index fbc57f0..6c32080 100644
@@ -197,12 +197,14 @@ struct dfl_feature_driver {
  *                 feature dev (platform device)'s reources.
  * @ioaddr: mapped mmio resource address.
  * @ops: ops of this sub feature.
+ * @priv: priv data of this feature.
  */
 struct dfl_feature {
        u64 id;
        int resource_index;
        void __iomem *ioaddr;
        const struct dfl_feature_ops *ops;
+       void *priv;
 };
 
Quoted 4 lines
Quoted 4 lines
drivers/fpga/dfl.h +0 -1
 #define DEV_STATUS_IN_USE      0
--

2.7.4

Thanks for the review, will fix these things in the next version.

Hao

Quoted 3 lines

Thanks,
Alan

author
#62 lore raw

PATCH 17/17 fpga: dfl: fme: add performance reporting support

In reply to Wu Hao

This patch adds support for performance reporting private feature for FPGA Management Engine (FME). Actually it supports 4 categories performance counters, 'clock', 'cache', 'iommu' and 'fabric', user could read the performance counter via exposed sysfs interfaces. Please refer to sysfs doc for more details.

---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  86 ++
 drivers/fpga/Makefile                            |   1 +
 drivers/fpga/dfl-fme-main.c                      |   4 +
 drivers/fpga/dfl-fme-perf.c                      | 950 +++++++++++++++++++++++
 drivers/fpga/dfl-fme.h                           |   2 +
 drivers/fpga/dfl.c                               |   1 +
 drivers/fpga/dfl.h                               |   2 +
 7 files changed, 1046 insertions(+)
 create mode 100644 drivers/fpga/dfl-fme-perf.c
Documentation/ABI/testing/sysfs-platform-dfl-fme +86 -0
index 38f9cdd..12f9449 100644
@@ -214,3 +214,89 @@ KernelVersion:  5.2
 Contact:	Wu Hao <[email protected]>
 Description:	Read-Write. Write this file to inject errors for testing
 		purpose. Read this file to check errors injected.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/clock
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Only. Read for Accelerator Function Unit (AFU) clock
+		counter.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/cache/freeze
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Write. Read and Write this file to freeze or unfreeze
+		the 'cache' category performance counters.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/cache/<counter>
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Only. Read 'cache' category performance counters:
+		read_hit, read_miss, write_hit, write_miss, hold_request,
+		data_write_port_contention, tag_write_port_contention,
+		tx_req_stall, rx_req_stall and rx_eviction.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/iommu/freeze
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Write. Read and Write this file to freeze or unfreeze
+		the 'iommu' category performance counters.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/iommu/<sip_counter>
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Only. Read 'iommu' category 'sip' sub category
+		performance counters: iotlb_4k_hit, iotlb_2m_hit,
+		iotlb_1g_hit, slpwc_l3_hit, slpwc_l4_hit, rcc_hit,
+		rcc_miss, iotlb_4k_miss, iotlb_2m_miss, iotlb_1g_miss,
+		slpwc_l3_miss and slpwc_l4_miss.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/iommu/afu0/<counter>
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Only. Read 'iommu' category 'afuX' sub category
+		performance counters: read_transaction, write_transaction,
+		devtlb_read_hit, devtlb_write_hit, devtlb_4k_fill,
+		devtlb_2m_fill and devtlb_1g_fill.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/fabric/freeze
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Write. Read and Write this file to freeze or unfreeze
+		the 'fabric' category performance counters.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/fabric/<counter>
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Only. Read 'fabric' category performance counters:
+		pcie0_read, pcie0_write, pcie1_read, pcie1_write,
+		upi_read, upi_write and mmio_read.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/fabric/enable
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Write. Read and write this file to enable device
+		level fabric counters sysfs interfaces in the same folder.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/fabric/port0/<counter>
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Only. Read 'fabric' category "portX" sub category
+		performance counters: pcie0_read, pcie0_write, pcie1_read,
+		pcie1_write, upi_read, upi_write and mmio_read.
+
+What:		/sys/bus/platform/devices/dfl-fme.0/perf/fabric/port0/enable
+Date:		March 2019
+KernelVersion:  5.2
+Contact:	Wu Hao <[email protected]>
+Description:	Read-Write. Read and write this file to enable port level
+		fabric counters sysfs interfaces in the same folder.
drivers/fpga/Makefile +1 -0
index 1a9fa3d..7df3971 100644
@@ -39,6 +39,7 @@ obj-$(CONFIG_FPGA_DFL_FME_REGION)	+= dfl-fme-region.o
 obj-$(CONFIG_FPGA_DFL_AFU)		+= dfl-afu.o
 
 dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o dfl-fme-error.o
+dfl-fme-objs += dfl-fme-perf.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
 dfl-afu-objs += dfl-afu-error.o
 
drivers/fpga/dfl-fme-main.c +4 -0
index 76cb112..3abcb56 100644
@@ -690,6 +690,10 @@ static struct dfl_feature_driver fme_feature_drvs[] = {
 		.ops = &fme_global_err_ops,
 	},
 	{
+		.id_table = fme_perf_id_table,
+		.ops = &fme_perf_ops,
+	},
+	{
 		.ops = NULL,
 	},
 };
drivers/fpga/dfl-fme-perf.c new file +950 -0

950 lines not on this page · raw message

drivers/fpga/dfl-fme.h +2 -0
index 5fbe3f5..dc71048 100644
@@ -39,5 +39,7 @@ extern const struct dfl_feature_ops fme_pr_mgmt_ops;
 extern const struct dfl_feature_id fme_pr_mgmt_id_table[];
 extern const struct dfl_feature_ops fme_global_err_ops;
 extern const struct dfl_feature_id fme_global_err_id_table[];
+extern const struct dfl_feature_ops fme_perf_ops;
+extern const struct dfl_feature_id fme_perf_id_table[];
 
 #endif /* __DFL_FME_H */
drivers/fpga/dfl.c +1 -0
index 65f91ef..637692a 100644
@@ -507,6 +507,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 		struct dfl_feature *feature = &pdata->features[index];
 
 		/* save resource information for each feature */
+		feature->pdev = fdev;
 		feature->id = finfo->fid;
 		feature->resource_index = index;
 		feature->ioaddr = finfo->ioaddr;
drivers/fpga/dfl.h +2 -0
index 6c32080..bf23436 100644
@@ -191,6 +191,7 @@ struct dfl_feature_driver {
 /**
  * struct dfl_feature - sub feature of the feature devices
  *
+ * @pdev: parent platform device.
  * @id: sub feature id.
  * @resource_index: each sub feature has one mmio resource for its registers.
  *		    this index is used to find its mmio resource from the
@@ -200,6 +201,7 @@ struct dfl_feature_driver {
  * @priv: priv data of this feature.
  */
 struct dfl_feature {
+	struct platform_device *pdev;
 	u64 id;
 	int resource_index;
 	void __iomem *ioaddr;
Signature · 1 line
2.7.4