Skip to contentSkip to conversation

Enable VAS

PATCH Superseded Sukadev Bhattiprolu 3 participants 13 messages Jan 26, 2017

Subsystems (4)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover Enable VAS

Power9 introduces a hardware subsystem referred to as the Virtual Accelerator Switchboard (VAS). VAS allows kernel subsystems and user space processes to directly access the Nest Accelerator (NX) engines which implement compression and encryption algorithms in the hardware.

NX has been in Power processors since Power7+, but access to the NX engines was through the 'icswx' instruction which is only available to the kernel/hypervisor. Starting with Power9, access to the NX engines is provided to both kernel and user space processes through VAS.

The switchboard (i.e VAS) multiplexes accesses between "receivers" and "senders", where the "receivers" are typically the NX engines and "senders" are the kernel subsystems and user processors that wish to access the receivers (NX engines). Once a sender is "connected" to a receiver through the switchboard, the sender submit compression/ encryption requests to the hardware using the new (PowerISA 3.0) "copy" and "paste" instructions.

In the initial OPAL and PowerNV kernel patchsets, the "senders" can only be kernel subsystems (eg NX-842 driver). A follow-on patch set will allow senders to be user-space processes.

This kernel patch set configures the VAS subsystems and provides kernel interfaces to drivers like NX-842 to open receive and send windows in VAS and to submit requests to the NX engine.

This patch set that has been tested in a Simics Power9 environment using a modified NX-842 kernel driver and a compression self-test module from Power8. The corresponding OPAL patchset for VAS support was posted to skiboot mailing list:

	https://lists.ozlabs.org/pipermail/skiboot/2017-January/006193.html

OPAL and kernel patchsets for NX-842 driver will be posted separately. All four patchsets are needed to effectively use VAS/NX in Power9.

Thanks to input from Ben Herrenschmidt, Michael Neuling, Michael Ellerman and Haren Myneni.

Changelog[v2]
- Use vas-id, HVWC, UWC and paste address, entries from device tree rather than defining/computing them in kernel and reorg code.

Sukadev Bhattiprolu (10):
VAS: Define macros, register fields and structures Move GET_FIELD/SET_FIELD to vas.h
VAS: Define vas_init() and vas_exit()
VAS: Define helpers for access MMIO regions
VAS: Define helpers to init window context
VAS: Define helpers to alloc/free windows
VAS: Define vas_rx_win_open() interface
VAS: Define vas_win_close() interface
VAS: Define vas_tx_win_open()
VAS: Define copy/paste interfaces

 MAINTAINERS                        |   6 +
 arch/powerpc/include/asm/reg.h     |   1 +
 arch/powerpc/include/asm/vas.h     | 141 ++++++
 drivers/crypto/nx/nx-842-powernv.c |   1 +
 drivers/crypto/nx/nx-842.h         |   5 -
 drivers/misc/Kconfig               |   1 +
 drivers/misc/Makefile              |   1 +
 drivers/misc/vas/Kconfig           |  20 +
 drivers/misc/vas/Makefile          |   3 +
 drivers/misc/vas/copy-paste.h      |  74 +++
 drivers/misc/vas/vas-internal.h    | 467 ++++++++++++++++++
 drivers/misc/vas/vas-window.c      | 950 +++++++++++++++++++++++++++++++++++++
 drivers/misc/vas/vas.c             | 156 ++++++
 13 files changed, 1821 insertions(+), 5 deletions(-)
 create mode 100644 arch/powerpc/include/asm/vas.h
 create mode 100644 drivers/misc/vas/Kconfig
 create mode 100644 drivers/misc/vas/Makefile
 create mode 100644 drivers/misc/vas/copy-paste.h
 create mode 100644 drivers/misc/vas/vas-internal.h
 create mode 100644 drivers/misc/vas/vas-window.c
 create mode 100644 drivers/misc/vas/vas.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/10 VAS: Define macros, register fields and structures

Define macros for the VAS hardware registers and bit-fields as well as couple of data structures needed by the VAS driver.

---
Changelog[v2]
- Add an overview of VAS in vas-internal.h
- Get window context parameters from device tree and drop unnecessary macros.

---
 MAINTAINERS                     |   6 +
 arch/powerpc/include/asm/vas.h  |  40 +++++
 drivers/misc/vas/vas-internal.h | 383 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 429 insertions(+)
 create mode 100644 arch/powerpc/include/asm/vas.h
 create mode 100644 drivers/misc/vas/vas-internal.h
MAINTAINERS +6 -0
index 63cefa6..54f015c 100644
@@ -12739,6 +12739,12 @@ S:	Maintained
 F:	Documentation/fb/uvesafb.txt
 F:	drivers/video/fbdev/uvesafb.*
 
+VAS (IBM Virtual Accelerator Switchboard) DRIVER
+M:	Sukadev Bhattiprolu <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/misc/vas/*
+
 VF610 NAND DRIVER
 M:	Stefan Agner <[email protected]>
 L:	[email protected]
arch/powerpc/include/asm/vas.h new file +40 -0
new file mode 100644
index 0000000..1c10437
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2016 IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef VAS_H
+#define VAS_H
+
+#define VAS_RX_FIFO_SIZE_MAX	(8 << 20)	/* 8MB */
+/*
+ * Co-processor Engine type.
+ */
+enum vas_cop_type {
+	VAS_COP_TYPE_FAULT,
+	VAS_COP_TYPE_842,
+	VAS_COP_TYPE_842_HIPRI,
+	VAS_COP_TYPE_GZIP,
+	VAS_COP_TYPE_GZIP_HIPRI,
+	VAS_COP_TYPE_MAX,
+};
+
+/*
+ * Threshold Control Mode: Have paste operation fail if the number of
+ * requests in receive FIFO exceeds a threshold.
+ *
+ * NOTE: No special error code yet if paste is rejected because of these
+ *	 limits. So users can't distinguish between this and other errors.
+ */
+enum vas_thresh_ctl {
+	VAS_THRESH_DISABLED,
+	VAS_THRESH_FIFO_GT_HALF_FULL,
+	VAS_THRESH_FIFO_GT_QTR_FULL,
+	VAS_THRESH_FIFO_GT_EIGHTH_FULL,
+};
+
+#endif
drivers/misc/vas/vas-internal.h new file +383 -0

383 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/10 Move GET_FIELD/SET_FIELD to vas.h

In reply to Sukadev Bhattiprolu

Move the GET_FIELD and SET_FIELD macros to vas.h as VAS and other users of VAS, including NX-842 can use those macros.

---
 arch/powerpc/include/asm/vas.h     | 8 ++++++++
 drivers/crypto/nx/nx-842-powernv.c | 1 +
 drivers/crypto/nx/nx-842.h         | 5 -----
 3 files changed, 9 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/vas.h +8 -0
index 1c10437..fef9e87 100644
@@ -37,4 +37,12 @@ enum vas_thresh_ctl {
 	VAS_THRESH_FIFO_GT_EIGHTH_FULL,
 };
 
+/*
+ * Get/Set bit fields
+ */
+#define GET_FIELD(m, v)		(((v) & (m)) >> MASK_LSH(m))
+#define MASK_LSH(m)		(__builtin_ffsl(m) - 1)
+#define SET_FIELD(m, v, val)	\
+		(((v) & ~(m)) | ((((typeof(v))(val)) << MASK_LSH(m)) & (m)))
+
 #endif
drivers/crypto/nx/nx-842-powernv.c +1 -0
index 1710f80..ea6fb6c 100644
@@ -22,6 +22,7 @@
 
 #include <asm/prom.h>
 #include <asm/icswx.h>
+#include <asm/vas.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Dan Streetman <[email protected]>");
drivers/crypto/nx/nx-842.h +0 -5
index a4eee3b..30929bd 100644
@@ -100,11 +100,6 @@ static inline unsigned long nx842_get_pa(void *addr)
 	return page_to_phys(vmalloc_to_page(addr)) + offset_in_page(addr);
 }
 
-/* Get/Set bit fields */
-#define MASK_LSH(m)		(__builtin_ffsl(m) - 1)
-#define GET_FIELD(v, m)		(((v) & (m)) >> MASK_LSH(m))
-#define SET_FIELD(v, m, val)	(((v) & ~(m)) | (((val) << MASK_LSH(m)) & (m)))
-
 /**
  * This provides the driver's constraints.  Different nx842 implementations
  * may have varying requirements.  The constraints are:
Signature · 1 line
2.7.4
Reviewed-by on v2 2/10
#3 lore raw

Re: [PATCH v2 02/10] Move GET_FIELD/SET_FIELD to vas.h

Quoted 5 lines · Sukadev Bhattiprolu

Move the GET_FIELD and SET_FIELD macros to vas.h as VAS and other users of VAS, including NX-842 can use those macros.

Quoted 54 lines
---
 arch/powerpc/include/asm/vas.h     | 8 ++++++++
 drivers/crypto/nx/nx-842-powernv.c | 1 +
 drivers/crypto/nx/nx-842.h         | 5 -----
 3 files changed, 9 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/vas.h +8 -0
index 1c10437..fef9e87 100644
@@ -37,4 +37,12 @@ enum vas_thresh_ctl {
        VAS_THRESH_FIFO_GT_EIGHTH_FULL,
 };
 
+/*
+ * Get/Set bit fields
+ */
+#define GET_FIELD(m, v)                (((v) & (m)) >> MASK_LSH(m))
+#define MASK_LSH(m)            (__builtin_ffsl(m) - 1)
+#define SET_FIELD(m, v, val)   \
+               (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_LSH(m)) & (m)))
+
 #endif
drivers/crypto/nx/nx-842-powernv.c +1 -0
index 1710f80..ea6fb6c 100644
@@ -22,6 +22,7 @@
 
 #include <asm/prom.h>
 #include <asm/icswx.h>
+#include <asm/vas.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Dan Streetman <[email protected]>");
drivers/crypto/nx/nx-842.h +0 -6
index a4eee3b..30929bd 100644
@@ -100,11 +100,6 @@ static inline unsigned long nx842_get_pa(void *addr)
        return page_to_phys(vmalloc_to_page(addr)) + offset_in_page(addr);
 }
 
-/* Get/Set bit fields */
-#define MASK_LSH(m)            (__builtin_ffsl(m) - 1)
-#define GET_FIELD(v, m)                (((v) & (m)) >> MASK_LSH(m))
-#define SET_FIELD(v, m, val)   (((v) & ~(m)) | (((val) << MASK_LSH(m)) & (m)))
-
 /**
  * This provides the driver's constraints.  Different nx842 implementations
  * may have varying requirements.  The constraints are:
--

2.7.4

#4 lore raw

PATCH v2 3/10 VAS: Define vas_init() and vas_exit()

In reply to Sukadev Bhattiprolu

Implement vas_init() and vas_exit() functions for a new VAS module. This VAS module is essentially a library for other device drivers and kernel users of the NX coprocessors like NX-842 and NX-GZIP.

---
Changelog[v2]:
- Get HVWC, UWC and window address parameters from device tree.

---
 arch/powerpc/include/asm/reg.h  |   1 +
 drivers/misc/Kconfig            |   1 +
 drivers/misc/Makefile           |   1 +
 drivers/misc/vas/Kconfig        |  20 ++++++
 drivers/misc/vas/Makefile       |   3 +
 drivers/misc/vas/vas-internal.h |   3 +
 drivers/misc/vas/vas-window.c   |  19 +++++
 drivers/misc/vas/vas.c          | 156 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 204 insertions(+)
 create mode 100644 drivers/misc/vas/Kconfig
 create mode 100644 drivers/misc/vas/Makefile
 create mode 100644 drivers/misc/vas/vas-window.c
 create mode 100644 drivers/misc/vas/vas.c
arch/powerpc/include/asm/reg.h +1 -0
index 9e1499f..9cba3c18 100644
@@ -1210,6 +1210,7 @@
 #define PVR_POWER8E	0x004B
 #define PVR_POWER8NVL	0x004C
 #define PVR_POWER8	0x004D
+#define PVR_POWER9	0x004E
 #define PVR_BE		0x0070
 #define PVR_PA6T	0x0090
 
drivers/misc/Kconfig +1 -0
index 64971ba..c84ab67 100644
@@ -778,4 +778,5 @@ source "drivers/misc/mic/Kconfig"
 source "drivers/misc/genwqe/Kconfig"
 source "drivers/misc/echo/Kconfig"
 source "drivers/misc/cxl/Kconfig"
+source "drivers/misc/vas/Kconfig"
 endmenu
drivers/misc/Makefile +1 -0
index 3198336..97a076e 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_GENWQE)		+= genwqe/
 obj-$(CONFIG_ECHO)		+= echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)		+= cxl/
+obj-$(CONFIG_VAS)		+= vas/
 obj-$(CONFIG_PANEL)             += panel.o
 
 lkdtm-$(CONFIG_LKDTM)		+= lkdtm_core.o
drivers/misc/vas/Kconfig new file +20 -0
new file mode 100644
index 0000000..c212cea
@@ -0,0 +1,20 @@
+#
+# IBM Virtual Accelarator Switchboard (VAS) compatible devices
+#depends on PPC_POWERNV && PCI_MSI && EEH
+#
+
+config VAS
+	tristate "Support for IBM Virtual Accelerator Switchboard (VAS)"
+	depends on PPC_POWERNV
+	default n
+	help
+	  Select this option to enable driver support for IBM Virtual
+	  Accelerator Switchboard (VAS).
+	  VAS allows accelerators in co processors like NX-842 to be
+	  directly available to a user process.  This driver enables
+	  userspace programs to access these accelerators via
+	  /dev/vas/vas-nxM.N devices.
+
+	  VAS adapters are found in POWER9 based systems.
+
+	  If unsure, say N.
drivers/misc/vas/Makefile new file +3 -0
new file mode 100644
index 0000000..7dd7139
@@ -0,0 +1,3 @@
+ccflags-y			:= $(call cc-disable-warning, unused-const-variable)
+ccflags-$(CONFIG_PPC_WERROR)	+= -Werror
+obj-$(CONFIG_VAS)		+= vas.o vas-window.o
drivers/misc/vas/vas-internal.h +3 -0
index aa4e781..61cfaad 100644
@@ -380,4 +380,7 @@ struct vas_winctx {
 	enum vas_notify_after_count notify_after_count;
 };
 
+extern int vas_initialized;
+extern int vas_window_reset(struct vas_instance *vinst, int winid);
+extern struct vas_instance *find_vas_instance(int vasid);
 #endif
drivers/misc/vas/vas-window.c new file +19 -0
new file mode 100644
index 0000000..468f3bf
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2016 IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/types.h>
+#include <linux/mutex.h>
+#include <asm/vas.h>
+#include "vas-internal.h"
+
+/* stub for now */
+int vas_window_reset(struct vas_instance *vinst, int winid)
+{
+	return 0;
+}
drivers/misc/vas/vas.c new file +156 -0

156 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

Re: [PATCH v2 03/10] VAS: Define vas_init() and vas_exit()

url: https://github.com/0day-ci/linux/commits/Sukadev-Bhattiprolu/Enable-VAS/20170126-095706 config: powerpc-allmodconfig (attached as .config) compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9)…

Hi Sukadev,

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v4.10-rc5 next-20170125]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Sukadev-Bhattiprolu/Enable-VAS/20170126-095706
config: powerpc-allmodconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc

All errors (new ones prefixed by >>):

In file included from drivers/misc/vas/vas.c:17:0:

>> drivers/misc/vas/vas-internal.h:17:3: error: #error "TODO: Compute RMA/Paste-address for 4K pages."
    # error "TODO: Compute RMA/Paste-address for 4K pages."
      ^~~~~

vim +17 drivers/misc/vas/vas-internal.h

061f6cc4 Sukadev Bhattiprolu 2017-01-25  11  #define VAS_INTERNAL_H
061f6cc4 Sukadev Bhattiprolu 2017-01-25  12  #include <linux/atomic.h>
061f6cc4 Sukadev Bhattiprolu 2017-01-25  13  #include <linux/idr.h>
061f6cc4 Sukadev Bhattiprolu 2017-01-25  14  #include <asm/vas.h>
061f6cc4 Sukadev Bhattiprolu 2017-01-25  15  
061f6cc4 Sukadev Bhattiprolu 2017-01-25  16  #ifdef CONFIG_PPC_4K_PAGES
061f6cc4 Sukadev Bhattiprolu 2017-01-25 @17  #	error "TODO: Compute RMA/Paste-address for 4K pages."
061f6cc4 Sukadev Bhattiprolu 2017-01-25  18  #else
061f6cc4 Sukadev Bhattiprolu 2017-01-25  19  #ifndef CONFIG_PPC_64K_PAGES
061f6cc4 Sukadev Bhattiprolu 2017-01-25  20  #	error "Unexpected Page size."

:::::: The code at line 17 was first introduced by commit
:::::: 061f6cc4f9597ef9fe84da3d04937b06f664d0b7 VAS: Define macros, register fields and structures

:::::: TO: Sukadev Bhattiprolu <[email protected]> :::::: CC: 0day robot <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#6 lore raw

PATCH v2 4/10 VAS: Define helpers for access MMIO regions

In reply to Sukadev Bhattiprolu

Define some helper functions to access the MMIO regions. We use these in a follow-on patches to read/write VAS hardware registers. These helpers are also used to later issue 'paste' instructions to submit requests to the NX hardware engines.

Changelog [v2]:
- Get HVWC, UWC and paste addresses from window->vinst (i.e DT) rather than kernel macros.

---
 drivers/misc/vas/vas-window.c | 112 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
drivers/misc/vas/vas-window.c +112 -0
index 468f3bf..cfbd2f4 100644
@@ -9,9 +9,121 @@
 
 #include <linux/types.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/io.h>
 #include <asm/vas.h>
 #include "vas-internal.h"
 
+/*
+ * Compute the paste address region for the window @window using the
+ * ->win_base_addr and ->win_id_shift we got from device tree.
+ */
+void compute_paste_address(struct vas_window *window, uint64_t *addr, int *len)
+{
+	uint64_t base, shift;
+	int winid;
+
+	base = window->vinst->win_base_addr;
+	shift = window->vinst->win_id_shift;
+	winid = window->winid;
+
+	*addr  = base + (winid << shift);
+	*len = PAGE_SIZE;
+
+	pr_debug("Txwin #%d: Paste addr 0x%llx\n", winid, *addr);
+}
+
+static inline void get_hvwc_mmio_bar(struct vas_window *window,
+			uint64_t *start, int *len)
+{
+	uint64_t pbaddr;
+
+	pbaddr = window->vinst->hvwc_bar_start;
+	*start = pbaddr + window->winid * VAS_HVWC_SIZE;
+	*len = VAS_HVWC_SIZE;
+}
+
+static inline void get_uwc_mmio_bar(struct vas_window *window,
+			uint64_t *start, int *len)
+{
+	uint64_t pbaddr;
+
+	pbaddr = window->vinst->uwc_bar_start;
+	*start = pbaddr + window->winid * VAS_UWC_SIZE;
+	*len = VAS_UWC_SIZE;
+}
+
+static void *map_mmio_region(char *name, uint64_t start, int len)
+{
+	void *map;
+
+	if (!request_mem_region(start, len, name)) {
+		pr_devel("%s(): request_mem_region(0x%llx, %d) failed\n",
+				__func__, start, len);
+		return NULL;
+	}
+
+	map = __ioremap(start, len, pgprot_val(pgprot_cached(__pgprot(0))));
+	if (!map) {
+		pr_devel("%s(): ioremap(0x%llx, %d) failed\n", __func__, start,
+				len);
+		return NULL;
+	}
+
+	return map;
+}
+
+/*
+ * Unmap the MMIO regions for a window.
+ */
+void unmap_wc_mmio_bars(struct vas_window *window)
+{
+	int len;
+	uint64_t busaddr_start;
+
+	if (window->paste_kaddr) {
+		iounmap(window->paste_kaddr);
+		compute_paste_address(window, &busaddr_start, &len);
+		release_mem_region((phys_addr_t)busaddr_start, len);
+	}
+
+	if (window->hvwc_map) {
+		iounmap(window->hvwc_map);
+		get_hvwc_mmio_bar(window, &busaddr_start, &len);
+		release_mem_region((phys_addr_t)busaddr_start, len);
+	}
+
+	if (window->uwc_map) {
+		iounmap(window->uwc_map);
+		get_uwc_mmio_bar(window, &busaddr_start, &len);
+		release_mem_region((phys_addr_t)busaddr_start, len);
+	}
+}
+
+/*
+ * Find the Hypervisor Window Context (HVWC) MMIO Base Address Region and the
+ * OS/User Window Context (UWC) MMIO Base Address Region for the given window.
+ * Map these bus addresses and save the mapped kernel addresses in @window.
+ */
+int map_wc_mmio_bars(struct vas_window *window)
+{
+	int len;
+	uint64_t start;
+
+	window->hvwc_map = window->uwc_map = NULL;
+
+	get_hvwc_mmio_bar(window, &start, &len);
+	window->hvwc_map = map_mmio_region("HVWCM_Window", start, len);
+
+	get_uwc_mmio_bar(window, &start, &len);
+	window->uwc_map = map_mmio_region("UWCM_Window", start, len);
+
+	if (!window->hvwc_map || !window->uwc_map)
+		return -1;
+
+	return 0;
+}
+
 /* stub for now */
 int vas_window_reset(struct vas_instance *vinst, int winid)
 {
Signature · 1 line
2.7.4
#7 lore raw

PATCH v2 5/10 VAS: Define helpers to init window context

In reply to Sukadev Bhattiprolu

Define helpers to initialize window context registers of the VAS hardware. These will be used in follow-on patches when opening/closing VAS windows.

---
 drivers/misc/vas/vas-internal.h |  56 +++++++
 drivers/misc/vas/vas-window.c   | 330 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 386 insertions(+)
drivers/misc/vas/vas-internal.h +56 -0
index 61cfaad..0a396ea 100644
@@ -11,6 +11,7 @@
 #define VAS_INTERNAL_H
 #include <linux/atomic.h>
 #include <linux/idr.h>
+#include <linux/io.h>
 #include <asm/vas.h>
 
 #ifdef CONFIG_PPC_4K_PAGES
@@ -383,4 +384,59 @@ struct vas_winctx {
 extern int vas_initialized;
 extern int vas_window_reset(struct vas_instance *vinst, int winid);
 extern struct vas_instance *find_vas_instance(int vasid);
+
+/*
+ * VREG(x):
+ * Expand a register's short name (eg: LPID) into two parameters:
+ *	- the register's short name in string form ("LPID"), and
+ *	- the name of the macro (eg: VAS_LPID_OFFSET), defining the
+ *	  register's offset in the window context
+ */
+#define VREG_SFX(n, s)	__stringify(n), VAS_##n##s
+#define VREG(r)		VREG_SFX(r, _OFFSET)
+
+#ifndef vas_debug
+static inline void vas_log_write(struct vas_window *win, char *name,
+			void *regptr, uint64_t val)
+{
+	if (val)
+		pr_err("%swin #%d: %s reg %p, val 0x%llx\n",
+				win->tx_win ? "Tx" : "Rx", win->winid, name,
+				regptr, val);
+}
+
+#else	/* vas_debug */
+
+#define vas_log_write(win, name, reg, val)
+
+#endif	/* vas_debug */
+
+static inline void write_uwc_reg(struct vas_window *win, char *name,
+			int32_t reg, uint64_t val)
+{
+	void *regptr;
+
+	regptr = win->uwc_map + reg;
+	vas_log_write(win, name, regptr, val);
+
+	out_be64(regptr, val);
+}
+
+static inline void write_hvwc_reg(struct vas_window *win, char *name,
+			int32_t reg, uint64_t val)
+{
+	void *regptr;
+
+	regptr = win->hvwc_map + reg;
+	vas_log_write(win, name, regptr, val);
+
+	out_be64(regptr, val);
+}
+
+static inline uint64_t read_hvwc_reg(struct vas_window *win,
+			char *name __maybe_unused, int32_t reg)
+{
+	return in_be64(win->hvwc_map+reg);
+}
+
 #endif
drivers/misc/vas/vas-window.c +330 -0

342 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

PATCH v2 6/10 VAS: Define helpers to alloc/free windows

In reply to Sukadev Bhattiprolu

Define helpers to allocate/free VAS window objects. These will be used in follow-on patches when opening/closing windows.

---
 drivers/misc/vas/vas-window.c | 72 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)
drivers/misc/vas/vas-window.c +71 -1
index c2e6b4e..3ea698a 100644
@@ -454,8 +454,78 @@ int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx)
 	return 0;
 }
 
-/* stub for now */
+DEFINE_SPINLOCK(vas_ida_lock);
+
+void vas_release_window_id(struct ida *ida, int winid)
+{
+	spin_lock(&vas_ida_lock);
+	ida_remove(ida, winid);
+	spin_unlock(&vas_ida_lock);
+}
+
+int vas_assign_window_id(struct ida *ida)
+{
+	int rc, winid;
+
+	rc = ida_pre_get(ida, GFP_KERNEL);
+	if (!rc)
+		return -EAGAIN;
+
+	spin_lock(&vas_ida_lock);
+	rc = ida_get_new_above(ida, 1, &winid);
+	spin_unlock(&vas_ida_lock);
+
+	if (rc)
+		return rc;
+
+	if (winid > VAS_MAX_WINDOWS_PER_CHIP) {
+		pr_err("VAS: Too many (%d) open windows\n", winid);
+		vas_release_window_id(ida, winid);
+		return -EAGAIN;
+	}
+
+	return winid;
+}
+
+static void vas_window_free(struct vas_window *window)
+{
+	unmap_wc_mmio_bars(window);
+	kfree(window->paste_addr_name);
+	kfree(window);
+}
+
+static struct vas_window *vas_window_alloc(struct vas_instance *vinst, int id)
+{
+	struct vas_window *window;
+
+	window = kzalloc(sizeof(*window), GFP_KERNEL);
+	if (!window)
+		return NULL;
+
+	window->vinst = vinst;
+	window->winid = id;
+
+	if (map_wc_mmio_bars(window))
+		goto out_free;
+
+	return window;
+
+out_free:
+	kfree(window);
+	return NULL;
+}
+
 int vas_window_reset(struct vas_instance *vinst, int winid)
 {
+	struct vas_window *window;
+
+	window = vas_window_alloc(vinst, winid);
+	if (!window)
+		return -ENOMEM;
+
+	reset_window_regs(window);
+
+	vas_window_free(window);
+
 	return 0;
 }
Signature · 1 line
2.7.4
#9 lore raw

PATCH v2 7/10 VAS: Define vas_rx_win_open() interface

In reply to Sukadev Bhattiprolu

Define the vas_rx_win_open() interface. This interface is intended to be used by the Nest Accelerator (NX) driver(s) to setup receive windows for one or more NX engines (which implement compression/encryption algorithms in the hardware).

Follow-on patches will provide an interface to close the window and to open a send window that kenrel subsystems can use to access the NX engines.

The interface to open a receive window is expected to be invoked for each instance of VAS in the system.

---
 arch/powerpc/include/asm/vas.h  |  39 +++++++++
 drivers/misc/vas/vas-internal.h |  11 +++
 drivers/misc/vas/vas-window.c   | 182 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 232 insertions(+)
arch/powerpc/include/asm/vas.h +39 -0
index fef9e87..b6362e9 100644
@@ -38,6 +38,45 @@ enum vas_thresh_ctl {
 };
 
 /*
+ * Receive window attributes specified by the (in-kernel) owner of window.
+ */
+struct vas_rx_win_attr {
+	void *rx_fifo;
+	int rx_fifo_size;
+	int wcreds_max;
+
+	bool pin_win;
+	bool rej_no_credit;
+	bool tx_wcred_mode;
+	bool rx_wcred_mode;
+	bool tx_win_ord_mode;
+	bool rx_win_ord_mode;
+	bool data_stamp;
+	bool nx_win;
+	bool fault_win;
+	bool notify_disable;
+	bool intr_disable;
+	bool notify_early;
+
+	int lnotify_lpid;
+	int lnotify_pid;
+	int lnotify_tid;
+	int pswid;
+
+	enum vas_thresh_ctl tc_mode;
+};
+
+/*
+ * Open a VAS receive window for the instance of VAS identified by @vasid
+ * Use @attr to initialize the attributes of the window.
+ *
+ * Return a handle to the window or ERR_PTR() on error.
+ */
+struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
+			struct vas_rx_win_attr *attr);
+
+
+/*
  * Get/Set bit fields
  */
 #define GET_FIELD(m, v)		(((v) & (m)) >> MASK_LSH(m))
drivers/misc/vas/vas-internal.h +11 -0
index 0a396ea..139d12a 100644
@@ -396,6 +396,16 @@ extern struct vas_instance *find_vas_instance(int vasid);
 #define VREG(r)		VREG_SFX(r, _OFFSET)
 
 #ifndef vas_debug
+static inline void dump_rx_win_attr(struct vas_rx_win_attr *attr)
+{
+	pr_err("VAS: fault %d, notify %d, intr %d early %d\n",
+			attr->fault_win, attr->notify_disable,
+			attr->intr_disable, attr->notify_early);
+
+	pr_err("VAS: rx_fifo_size %d, max value %d\n",
+				attr->rx_fifo_size, VAS_RX_FIFO_SIZE_MAX);
+}
+
 static inline void vas_log_write(struct vas_window *win, char *name,
 			void *regptr, uint64_t val)
 {
@@ -408,6 +418,7 @@ static inline void vas_log_write(struct vas_window *win, char *name,
 #else	/* vas_debug */
 
 #define vas_log_write(win, name, reg, val)
+#define dump_rx_win_attr(attr)
 
 #endif	/* vas_debug */
 
drivers/misc/vas/vas-window.c +182 -0

185 lines not on this page · raw message

Signature · 1 line
2.7.4
#10 lore raw

PATCH v2 8/10 VAS: Define vas_win_close() interface

In reply to Sukadev Bhattiprolu

Define the vas_win_close() interface which should be used to close a send or receive windows.

While the hardware configurations required to open send and receive windows differ, the configuration to close a window is the same for both. So we use a single interface to close the window.

---
 arch/powerpc/include/asm/vas.h |  6 +++++
 drivers/misc/vas/vas-window.c  | 52 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
arch/powerpc/include/asm/vas.h +6 -0
index b6362e9..bda851a 100644
@@ -75,6 +75,12 @@ struct vas_rx_win_attr {
 struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
 			struct vas_rx_win_attr *attr);
 
+/*
+ * Close the send or receive window identified by @win. For receive windows
+ * return -EAGAIN if there are active send windows attached to this receive
+ * window.
+ */
+int vas_win_close(struct vas_window *win);
 
 /*
  * Get/Set bit fields
drivers/misc/vas/vas-window.c +52 -0

55 lines not on this page · raw message

Signature · 1 line
2.7.4
#11 lore raw

PATCH v2 9/10 VAS: Define vas_tx_win_open()

In reply to Sukadev Bhattiprolu

Define an interface to open a VAS send window. This interface is intended to be used the Nest Accelerator (NX) driver(s) to open a send window and use it to submit compression/encryption requests to a VAS receive window.

The receive window, identified by the [node, chip, cop] parameters, must already be open in VAS (i.e connected to an NX engine).

---
 arch/powerpc/include/asm/vas.h |  33 ++++++++++
 drivers/misc/vas/vas-window.c  | 142 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 175 insertions(+)
arch/powerpc/include/asm/vas.h +33 -0
index bda851a..a841084 100644
@@ -67,6 +67,26 @@ struct vas_rx_win_attr {
 };
 
 /*
+ * Window attributes specified by the in-kernel owner of a send window.
+ */
+struct vas_tx_win_attr {
+	enum vas_cop_type cop;
+	int wcreds_max;
+	int lpid;
+	int pid;
+	int pswid;
+	int rsvd_txbuf_count;
+
+	bool user_win;
+	bool pin_win;
+	bool rej_no_credit;
+	bool rsvd_txbuf_enable;
+	bool tx_win_ord_mode;
+	bool rx_win_ord_mode;
+	enum vas_thresh_ctl tc_mode;
+};
+
+/*
  * Open a VAS receive window for the instance of VAS identified by @vasid
  * Use @attr to initialize the attributes of the window.
  *
@@ -76,6 +96,19 @@ struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
 			struct vas_rx_win_attr *attr);
 
 /*
+ * Open a VAS send window for the instance of VAS identified by @vasid
+ * and the co-processor type @cop. Use @attr to initialize attributes
+ * of the window.
+ *
+ * Note: The instance of VAS must already have an open receive window for
+ * the coprocessor type @cop.
+ *
+ * Return a handle to the send window or ERR_PTR() on error.
+ */
+struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop,
+			struct vas_tx_win_attr *attr);
+
+/*
  * Close the send or receive window identified by @win. For receive windows
  * return -EAGAIN if there are active send windows attached to this receive
  * window.
drivers/misc/vas/vas-window.c +142 -0

148 lines not on this page · raw message

Signature · 1 line
2.7.4
#12 lore raw

PATCH v2 10/10 VAS: Define copy/paste interfaces

In reply to Sukadev Bhattiprolu

Define interfaces (wrappers) to the 'copy' and 'paste' instructions (which are new in PowerISA 3.0). These are intended to be used to by NX driver(s) to submit Coprocessor Request Blocks (CRBs) to the NX hardware engines.

---
 arch/powerpc/include/asm/vas.h  | 17 +++++++++-
 drivers/misc/vas/copy-paste.h   | 74 +++++++++++++++++++++++++++++++++++++++++
 drivers/misc/vas/vas-internal.h | 14 ++++++++
 drivers/misc/vas/vas-window.c   | 43 ++++++++++++++++++++++++
 4 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100644 drivers/misc/vas/copy-paste.h
arch/powerpc/include/asm/vas.h +16 -1
index a841084..27710d1 100644
@@ -116,11 +116,26 @@ struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop,
 int vas_win_close(struct vas_window *win);
 
 /*
+ * Copy the co-processor request block (CRB) @crb into the local L2 cache.
+ * For now, @offset must be 0 and @first must be true.
+ */
+extern int vas_copy_crb(void *crb, int offset, bool first);
+
+/*
+ * Paste a previously copied CRB (see vas_copy_crb()) from the L2 cache to
+ * the hardware address associated with the window @win. For now, @off must
+ * 0 and @last must be true. @re is expected/assumed to be true for NX windows.
+ */
+extern int vas_paste_crb(struct vas_window *win, int off, bool last, bool re);
+
+
+
+
+/*
  * Get/Set bit fields
  */
 #define GET_FIELD(m, v)		(((v) & (m)) >> MASK_LSH(m))
 #define MASK_LSH(m)		(__builtin_ffsl(m) - 1)
 #define SET_FIELD(m, v, val)	\
 		(((v) & ~(m)) | ((((typeof(v))(val)) << MASK_LSH(m)) & (m)))
-
 #endif
drivers/misc/vas/copy-paste.h new file +74 -0

74 lines not on this page · raw message

drivers/misc/vas/vas-internal.h +14 -0
index 139d12a..d1c2b90 100644
@@ -450,4 +450,18 @@ static inline uint64_t read_hvwc_reg(struct vas_window *win,
 	return in_be64(win->hvwc_map+reg);
 }
 
+#ifdef vas_debug
+
+static void print_fifo_msg_count(struct vas_window *txwin)
+{
+	uint64_t read_hvwc_reg(struct vas_window *w, char *n, uint64_t o);
+	pr_devel("Winid %d, Msg count %llu\n", txwin->winid,
+			(uint64_t)read_hvwc_reg(txwin, VREG(LRFIFO_PUSH)));
+}
+#else	/* vas_debug */
+
+#define print_fifo_msg_count(window)
+
+#endif	/* vas_debug */
+
 #endif
drivers/misc/vas/vas-window.c +43 -0

55 lines not on this page · raw message

Signature · 1 line
2.7.4