Skip to contentSkip to conversation

selftests/powerpc: Add NX-GZIP engine testcase

PATCH In review Raphael Moreira Zinsly 2 participants 7 messages Apr 20, 2020 – Apr 21, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover selftests/powerpc: Add NX-GZIP engine testcase

This patch series are intended to test the POWER9 Nest Accelerator (NX) GZIP engine that is being introduced by
https://lists.ozlabs.org/pipermail/linuxppc-dev/2020-March/205659.html
More information about how to access the NX can be found in that patch, also a complete userspace library and more documentation can be found at:
https://github.com/libnxz/power-gzip

Changes in V4:
- Removed nx-helpers.h and moved relevant code to copy-paste.h.
- Removed nx-gzip.h and symlinked the vas-api.h uapi instead.
- Renamed inc to include and fixed warnings.
- Proper integrated the code to the selftests Makefile system with help from Michael Ellerman.

Thanks,
Raphael

#1 lore raw

PATCH v4 1/5 selftests/powerpc: Add header files for GZIP engine test

Add files to access the powerpc NX-GZIP engine in user space.

---
 .../selftests/powerpc/nx-gzip/include/crb.h   | 155 ++++++++++++++++++
 .../selftests/powerpc/nx-gzip/include/nx.h    |  38 +++++
 .../powerpc/nx-gzip/include/vas-api.h         |   1 +
 3 files changed, 194 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/include/crb.h
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/include/nx.h
 create mode 120000 tools/testing/selftests/powerpc/nx-gzip/include/vas-api.h
tools/testing/selftests/powerpc/nx-gzip/include/crb.h new file +155 -0
new file mode 100644
index 000000000000..ab101085fa7e
@@ -0,0 +1,155 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __CRB_H
+#define __CRB_H
+#include <linux/types.h>
+#include "nx.h"
+
+/* CCW 842 CI/FC masks
+ * NX P8 workbook, section 4.3.1, figure 4-6
+ * "CI/FC Boundary by NX CT type"
+ */
+#define CCW_CI_842              (0x00003ff8)
+#define CCW_FC_842              (0x00000007)
+
+/* Chapter 6.5.8 Coprocessor-Completion Block (CCB) */
+
+#define CCB_VALUE		(0x3fffffffffffffff)
+#define CCB_ADDRESS		(0xfffffffffffffff8)
+#define CCB_CM			(0x0000000000000007)
+#define CCB_CM0			(0x0000000000000004)
+#define CCB_CM12		(0x0000000000000003)
+
+#define CCB_CM0_ALL_COMPLETIONS	(0x0)
+#define CCB_CM0_LAST_IN_CHAIN	(0x4)
+#define CCB_CM12_STORE		(0x0)
+#define CCB_CM12_INTERRUPT	(0x1)
+
+#define CCB_SIZE		(0x10)
+#define CCB_ALIGN		CCB_SIZE
+
+struct coprocessor_completion_block {
+	__be64 value;
+	__be64 address;
+} __aligned(CCB_ALIGN);
+
+
+/* Chapter 6.5.7 Coprocessor-Status Block (CSB) */
+
+#define CSB_V			(0x80)
+#define CSB_F			(0x04)
+#define CSB_CH			(0x03)
+#define CSB_CE_INCOMPLETE	(0x80)
+#define CSB_CE_TERMINATION	(0x40)
+#define CSB_CE_TPBC		(0x20)
+
+#define CSB_CC_SUCCESS		(0)
+#define CSB_CC_INVALID_ALIGN	(1)
+#define CSB_CC_OPERAND_OVERLAP	(2)
+#define CSB_CC_DATA_LENGTH	(3)
+#define CSB_CC_TRANSLATION	(5)
+#define CSB_CC_PROTECTION	(6)
+#define CSB_CC_RD_EXTERNAL	(7)
+#define CSB_CC_INVALID_OPERAND	(8)
+#define CSB_CC_PRIVILEGE	(9)
+#define CSB_CC_INTERNAL		(10)
+#define CSB_CC_WR_EXTERNAL	(12)
+#define CSB_CC_NOSPC		(13)
+#define CSB_CC_EXCESSIVE_DDE	(14)
+#define CSB_CC_WR_TRANSLATION	(15)
+#define CSB_CC_WR_PROTECTION	(16)
+#define CSB_CC_UNKNOWN_CODE	(17)
+#define CSB_CC_ABORT		(18)
+#define CSB_CC_TRANSPORT	(20)
+#define CSB_CC_SEGMENTED_DDL	(31)
+#define CSB_CC_PROGRESS_POINT	(32)
+#define CSB_CC_DDE_OVERFLOW	(33)
+#define CSB_CC_SESSION		(34)
+#define CSB_CC_PROVISION	(36)
+#define CSB_CC_CHAIN		(37)
+#define CSB_CC_SEQUENCE		(38)
+#define CSB_CC_HW		(39)
+
+#define CSB_SIZE		(0x10)
+#define CSB_ALIGN		CSB_SIZE
+
+struct coprocessor_status_block {
+	__u8 flags;
+	__u8 cs;
+	__u8 cc;
+	__u8 ce;
+	__be32 count;
+	__be64 address;
+} __aligned(CSB_ALIGN);
+
+
+/* Chapter 6.5.10 Data-Descriptor List (DDL)
+ * each list contains one or more Data-Descriptor Entries (DDE)
+ */
+
+#define DDE_P			(0x8000)
+
+#define DDE_SIZE		(0x10)
+#define DDE_ALIGN		DDE_SIZE
+
+struct data_descriptor_entry {
+	__be16 flags;
+	__u8 count;
+	__u8 index;
+	__be32 length;
+	__be64 address;
+} __aligned(DDE_ALIGN);
+
+
+/* Chapter 6.5.2 Coprocessor-Request Block (CRB) */
+
+#define CRB_SIZE		(0x80)
+#define CRB_ALIGN		(0x100) /* Errata: requires 256 alignment */
+
+
+/* Coprocessor Status Block field
+ *   ADDRESS	address of CSB
+ *   C		CCB is valid
+ *   AT		0 = addrs are virtual, 1 = addrs are phys
+ *   M		enable perf monitor
+ */
+#define CRB_CSB_ADDRESS		(0xfffffffffffffff0)
+#define CRB_CSB_C		(0x0000000000000008)
+#define CRB_CSB_AT		(0x0000000000000002)
+#define CRB_CSB_M		(0x0000000000000001)
+
+struct coprocessor_request_block {
+	__be32 ccw;
+	__be32 flags;
+	__be64 csb_addr;
+
+	struct data_descriptor_entry source;
+	struct data_descriptor_entry target;
+
+	struct coprocessor_completion_block ccb;
+
+	__u8 reserved[48];
+
+	struct coprocessor_status_block csb;
+} __aligned(CRB_ALIGN);
+
+#define crb_csb_addr(c)         __be64_to_cpu(c->csb_addr)
+#define crb_nx_fault_addr(c)    __be64_to_cpu(c->stamp.nx.fault_storage_addr)
+#define crb_nx_flags(c)         c->stamp.nx.flags
+#define crb_nx_fault_status(c)  c->stamp.nx.fault_status
+#define crb_nx_pswid(c)		c->stamp.nx.pswid
+
+
+/* RFC02167 Initiate Coprocessor Instructions document
+ * Chapter 8.2.1.1.1 RS
+ * Chapter 8.2.3 Coprocessor Directive
+ * Chapter 8.2.4 Execution
+ *
+ * The CCW must be converted to BE before passing to icswx()
+ */
+
+#define CCW_PS                  (0xff000000)
+#define CCW_CT                  (0x00ff0000)
+#define CCW_CD                  (0x0000ffff)
+#define CCW_CL                  (0x0000c000)
+
+#endif
tools/testing/selftests/powerpc/nx-gzip/include/nx.h new file +38 -0
new file mode 100644
index 000000000000..78171b43464d
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright 2020 IBM Corp.
+ *
+ */
+#ifndef _NX_H
+#define _NX_H
+
+#include <stdbool.h>
+
+#define	NX_FUNC_COMP_842	1
+#define NX_FUNC_COMP_GZIP	2
+
+#ifndef __aligned
+#define __aligned(x)	__attribute__((aligned(x)))
+#endif
+
+struct nx842_func_args {
+	bool use_crc;
+	bool decompress;		/* true decompress; false compress */
+	bool move_data;
+	int timeout;			/* seconds */
+};
+
+struct nxbuf_t {
+	int len;
+	char *buf;
+};
+
+/* @function should be EFT (aka 842), GZIP etc */
+void *nx_function_begin(int function, int pri);
+
+int nx_function(void *handle, struct nxbuf_t *in, struct nxbuf_t *out,
+		void *arg);
+
+int nx_function_end(void *handle);
+
+#endif	/* _NX_H */
tools/testing/selftests/powerpc/nx-gzip/include/vas-api.h new file +1 -0
new file mode 120000
index 000000000000..77fb4c7236d0
@@ -0,0 +1 @@
+../../../../../../arch/powerpc/include/uapi/asm/vas-api.h
\ No newline at end of file
Signature · 1 line
2.21.0
#3 lore raw

PATCH v4 2/5 selftests/powerpc: Add header files for NX compresion/decompression

In reply to Raphael Moreira Zinsly

Add files to be able to compress and decompress files using the powerpc NX-GZIP engine.

---
 .../powerpc/nx-gzip/include/copy-paste.h      |  56 ++
 .../powerpc/nx-gzip/include/nx_dbg.h          |  95 +++
 .../selftests/powerpc/nx-gzip/include/nxu.h   | 650 ++++++++++++++++++
 3 files changed, 801 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/include/copy-paste.h
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/include/nx_dbg.h
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/include/nxu.h
tools/testing/selftests/powerpc/nx-gzip/include/copy-paste.h new file +56 -0
new file mode 100644
index 000000000000..0db2d6485037
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* From asm-compat.h */
+#define __stringify_in_c(...)	#__VA_ARGS__
+#define stringify_in_c(...)	__stringify_in_c(__VA_ARGS__) " "
+
+/*
+ * Macros taken from arch/powerpc/include/asm/ppc-opcode.h and other
+ * header files.
+ */
+#define ___PPC_RA(a)    (((a) & 0x1f) << 16)
+#define ___PPC_RB(b)    (((b) & 0x1f) << 11)
+
+#define PPC_INST_COPY                   0x7c20060c
+#define PPC_INST_PASTE                  0x7c20070d
+
+#define PPC_COPY(a, b)          stringify_in_c(.long PPC_INST_COPY | \
+						___PPC_RA(a) | ___PPC_RB(b))
+#define PPC_PASTE(a, b)         stringify_in_c(.long PPC_INST_PASTE | \
+						___PPC_RA(a) | ___PPC_RB(b))
+#define CR0_SHIFT	28
+#define CR0_MASK	0xF
+/*
+ * Copy/paste instructions:
+ *
+ *	copy RA,RB
+ *		Copy contents of address (RA) + effective_address(RB)
+ *		to internal copy-buffer.
+ *
+ *	paste RA,RB
+ *		Paste contents of internal copy-buffer to the address
+ *		(RA) + effective_address(RB)
+ */
+static inline int vas_copy(void *crb, int offset)
+{
+	asm volatile(PPC_COPY(%0, %1)";"
+		:
+		: "b" (offset), "b" (crb)
+		: "memory");
+
+	return 0;
+}
+
+static inline int vas_paste(void *paste_address, int offset)
+{
+	__u32 cr;
+
+	cr = 0;
+	asm volatile(PPC_PASTE(%1, %2)";"
+		"mfocrf %0, 0x80;"
+		: "=r" (cr)
+		: "b" (offset), "b" (paste_address)
+		: "memory", "cr0");
+
+	return (cr >> CR0_SHIFT) & CR0_MASK;
+}
tools/testing/selftests/powerpc/nx-gzip/include/nx_dbg.h new file +95 -0

95 lines not on this page · raw message

tools/testing/selftests/powerpc/nx-gzip/include/nxu.h new file +650 -0

650 lines not on this page · raw message

Signature · 1 line
2.21.0
#4 lore raw

PATCH v4 3/5 selftests/powerpc: Add NX-GZIP engine compress testcase

In reply to Raphael Moreira Zinsly

Add a compression testcase for the powerpc NX-GZIP engine.

---
 tools/testing/selftests/powerpc/Makefile      |   1 +
 .../selftests/powerpc/nx-gzip/Makefile        |   8 +
 .../selftests/powerpc/nx-gzip/gzfht_test.c    | 433 ++++++++++++++++++
 .../selftests/powerpc/nx-gzip/gzip_vas.c      | 315 +++++++++++++
 .../selftests/powerpc/nx-gzip/nx-gzip-test.sh |  45 ++
 5 files changed, 802 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/Makefile
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/gzip_vas.c
 create mode 100755 tools/testing/selftests/powerpc/nx-gzip/nx-gzip-test.sh
tools/testing/selftests/powerpc/Makefile +1 -0
index 644770c3b754..0830e63818c1 100644
@@ -19,6 +19,7 @@ SUB_DIRS = alignment		\
 	   copyloops		\
 	   dscr			\
 	   mm			\
+	   nx-gzip		\
 	   pmu			\
 	   signal		\
 	   primitives		\
tools/testing/selftests/powerpc/nx-gzip/Makefile new file +8 -0
new file mode 100644
index 000000000000..016e528a0a94
@@ -0,0 +1,8 @@
+CFLAGS = -O3 -m64 -I./include
+
+TEST_GEN_FILES := gzfht_test
+TEST_PROGS := nx-gzip-test.sh
+
+include ../../lib.mk
+
+$(TEST_GEN_FILES): gzip_vas.c
tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c new file +433 -0

433 lines not on this page · raw message

tools/testing/selftests/powerpc/nx-gzip/gzip_vas.c new file +315 -0

315 lines not on this page · raw message

tools/testing/selftests/powerpc/nx-gzip/nx-gzip-test.sh new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.21.0
#5 lore raw

PATCH v4 4/5 selftests/powerpc: Add NX-GZIP engine decompress testcase

In reply to Raphael Moreira Zinsly

Include a decompression testcase for the powerpc NX-GZIP engine.

---
 .../selftests/powerpc/nx-gzip/Makefile        |    2 +-
 .../selftests/powerpc/nx-gzip/gunz_test.c     | 1028 +++++++++++++++++
 .../selftests/powerpc/nx-gzip/nx-gzip-test.sh |    1 +
 3 files changed, 1030 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/gunz_test.c
tools/testing/selftests/powerpc/nx-gzip/Makefile +1 -1
index 016e528a0a94..640fad6cc2c7 100644
@@ -1,6 +1,6 @@
 CFLAGS = -O3 -m64 -I./include
 
-TEST_GEN_FILES := gzfht_test
+TEST_GEN_FILES := gzfht_test gunz_test
 TEST_PROGS := nx-gzip-test.sh
 
 include ../../lib.mk
tools/testing/selftests/powerpc/nx-gzip/gunz_test.c new file +1028 -0

1,028 lines not on this page · raw message

tools/testing/selftests/powerpc/nx-gzip/nx-gzip-test.sh +1 -0
index 18949237a001..8d336cdf75c0 100755
@@ -25,6 +25,7 @@ function test_sizes
 		echo "Testing $size ($n) ..."
 		dd if=/dev/urandom of=$fname bs=$size count=1
 		./gzfht_test $fname
+		./gunz_test ${fname}.nx.gz
 	done
 }
 
Signature · 1 line
2.21.0
#6 lore raw

PATCH v4 5/5 selftests/powerpc: Add README for GZIP engine tests

In reply to Raphael Moreira Zinsly

Include a README file with the instructions to use the testcases at selftests/powerpc/nx-gzip.

---
 .../powerpc/nx-gzip/99-nx-gzip.rules          |  1 +
 .../testing/selftests/powerpc/nx-gzip/README  | 45 +++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/99-nx-gzip.rules
 create mode 100644 tools/testing/selftests/powerpc/nx-gzip/README
tools/testing/selftests/powerpc/nx-gzip/99-nx-gzip.rules new file +1 -0
new file mode 100644
index 000000000000..5a7118495cb3
@@ -0,0 +1 @@
+SUBSYSTEM=="nxgzip", KERNEL=="nx-gzip", MODE="0666"
tools/testing/selftests/powerpc/nx-gzip/README new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.21.0