Skip to contentSkip to conversation

Enable VAS

PATCH Superseded Sukadev Bhattiprolu 4 participants 22 messages Mar 31, 2017 – May 25, 2017

Subsystems (3)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 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 senders can 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[v4]
Comments from Michael Neuling:
- Move VAS code from drivers/misc/vas to arch/powerpc/platforms/powernv since VAS only provides interfaces to other drivers like NX-842.
- Drop vas-internal.h and use vas.h in separate dirs for VAS internal, kernel API and user API
- Rather than create 6 separate device tree properties windows and window context, combine them into 6 "reg" properties.
- Drop vas_window_reset() since windows are reset/cleared before being assigned to kernel/users.
- Use ilog2() and radix_enabled() helpers

Changelog[v3]
- Rebase to v4.11-rc1
- Add interfaces to initialize send/receive window attributes to defaults that drivers can use (see arch/powerpc/include/asm/vas.h)
- Modify interface vas_paste() to return 0 or error code
- Fix a bug in setting Translation Control Mode (0b11 not 0x11)
- Enable send-window-credit checking
- Reorg code in vas_win_close()
- Minor reorgs and tweaks to register field settings to make it easier to add support for user space windows.
- Skip writing to read-only registers
- Start window indexing from 0 rather than 1

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 (11):
Add Power9 PVR
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

 arch/powerpc/include/asm/reg.h              |    1 +
 arch/powerpc/include/asm/vas.h              |  141 ++++
 arch/powerpc/include/uapi/asm/vas.h         |   33 +
 arch/powerpc/platforms/powernv/Kconfig      |   14 +
 arch/powerpc/platforms/powernv/Makefile     |    1 +
 arch/powerpc/platforms/powernv/copy-paste.h |   74 ++
 arch/powerpc/platforms/powernv/vas-window.c | 1003 +++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/vas.c        |  145 ++++
 arch/powerpc/platforms/powernv/vas.h        |  470 +++++++++++++
 drivers/crypto/nx/nx-842-powernv.c          |    7 +-
 drivers/crypto/nx/nx-842.h                  |    5 -
 11 files changed, 1886 insertions(+), 8 deletions(-)
 create mode 100644 arch/powerpc/include/asm/vas.h
 create mode 100644 arch/powerpc/include/uapi/asm/vas.h
 create mode 100644 arch/powerpc/platforms/powernv/copy-paste.h
 create mode 100644 arch/powerpc/platforms/powernv/vas-window.c
 create mode 100644 arch/powerpc/platforms/powernv/vas.c
 create mode 100644 arch/powerpc/platforms/powernv/vas.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v4 1/11 Add Power9 PVR

Add Power9 PVR

---
 arch/powerpc/include/asm/reg.h | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/include/asm/reg.h +1 -0
index fc879fd..7a45ff7 100644
@@ -1225,6 +1225,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
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH v4 2/11 VAS: Define macros, register fields and structures

In reply to Sukadev Bhattiprolu

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

---
Changelog[v4]
- [Michael Neuling] Move VAS code to arch/powerpc; Reorg vas.h and vas-internal.h to kernel and uapi versions; rather than creating separate properties for window context/address entries in device tree, combine them into "reg" properties; drop ->hwirq and irq_port fields from vas_window as they are only needed with user space windows.

Changelog[v3]
- Rename winctx->pid to winctx->pidr to reflect that its a value from the PID register (SPRN_PID), not the linux process id.
- Make it easier to split header into kernel/user parts
- To keep user interface simple, use macros rather than enum for the threshold-control modes.
- Add a pid field to struct vas_window - needed for user space send windows.

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

---
 arch/powerpc/include/asm/vas.h       |  34 +++
 arch/powerpc/include/uapi/asm/vas.h  |  25 +++
 arch/powerpc/platforms/powernv/vas.h | 387 +++++++++++++++++++++++++++++++++++
 3 files changed, 446 insertions(+)
 create mode 100644 arch/powerpc/include/asm/vas.h
 create mode 100644 arch/powerpc/include/uapi/asm/vas.h
 create mode 100644 arch/powerpc/platforms/powernv/vas.h
arch/powerpc/include/asm/vas.h new file +34 -0
new file mode 100644
index 0000000..e2575d5
@@ -0,0 +1,34 @@
+/*
+ * 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 _MISC_VAS_H
+#define _MISC_VAS_H
+
+#include <uapi/asm/vas.h>
+
+/*
+ * Min and max FIFO sizes are based on Version 1.05 Section 3.1.4.25
+ * (Local FIFO Size Register) of the VAS workbook.
+ */
+#define VAS_RX_FIFO_SIZE_MIN	(1 << 10)	/* 1KB */
+#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,
+};
+
+#endif /* _MISC_VAS_H */
arch/powerpc/include/uapi/asm/vas.h new file +25 -0
new file mode 100644
index 0000000..ddfe046
@@ -0,0 +1,25 @@
+/*
+ * 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 _UAPI_MISC_VAS_H
+#define _UAPI_MISC_VAS_H
+
+/*
+ * 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.
+ */
+#define VAS_THRESH_DISABLED		0
+#define VAS_THRESH_FIFO_GT_HALF_FULL	1
+#define VAS_THRESH_FIFO_GT_QTR_FULL	2
+#define VAS_THRESH_FIFO_GT_EIGHTH_FULL	3
+
+#endif /* _UAPI_MISC_VAS_H */
arch/powerpc/platforms/powernv/vas.h new file +387 -0

387 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v4 02/11] VAS: Define macros, register fields and structures

Quoted 4 lines · Sukadev Bhattiprolu [sukadevatlinux.vnet.ibm.com]

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

Signed-off-by Sukadev Bhattiprolu <sukadev at linux.vnet.ibm.com>

<snip>

Quoted 14 lines

+++ b/arch/powerpc/platforms/powernv/vas.h

(quoted diff) +12 -0
@@ -0,0 +1,387 @@
+/*
+ * 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
+#include <linux/atomic.h>

Review line 22

Quoted 10 lines
(quoted diff) +10 -0
+#include <linux/idr.h>
+#include <asm/vas.h>
+
+#ifdef CONFIG_PPC_4K_PAGES
+#	error "TODO: Compute RMA/Paste-address for 4K pages."
+#else
+#ifndef CONFIG_PPC_64K_PAGES
+#	error "Unexpected Page size."
+#endif
+#endif

The above "#error" breaks kbuild with some config. Here is the updated patch with the block removed. Instead, [PATCH 4] now includes a "depends on PPC_64K_PAGES".

Thanks,

Sukadev
----

Quoted 1 line

From 45629fa7a233eb35483c0941fb4f0509d369b001 Mon Sep 17 00:00:00 2001

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 10 Nov 2016 16:51:17 -0500
Subject: [PATCH v4 02/11] 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[v4]
- [Michael Neuling] Move VAS code to arch/powerpc; Reorg vas.h and vas-internal.h to kernel and uapi versions; rather than creating separate properties for window context/address entries in device tree, combine them into "reg" properties; drop ->hwirq and irq_port fields from vas_window as they are only needed with user space windows.
- Drop the error check for CONFIG_PPC_4K_PAGES. Instead in a follow-on patch add a "depends on CONFIG_PPC_64K_PAGES".

Changelog[v3]
- Rename winctx->pid to winctx->pidr to reflect that its a value from the PID register (SPRN_PID), not the linux process id.
- Make it easier to split header into kernel/user parts
- To keep user interface simple, use macros rather than enum for the threshold-control modes.
- Add a pid field to struct vas_window - needed for user space send windows.

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

---
 arch/powerpc/include/asm/vas.h       |  34 ++++
 arch/powerpc/include/uapi/asm/vas.h  |  25 +++
 arch/powerpc/platforms/powernv/vas.h | 379 +++++++++++++++++++++++++++++++++++
 3 files changed, 438 insertions(+)
 create mode 100644 arch/powerpc/include/asm/vas.h
 create mode 100644 arch/powerpc/include/uapi/asm/vas.h
 create mode 100644 arch/powerpc/platforms/powernv/vas.h
arch/powerpc/include/asm/vas.h new file +34 -0
new file mode 100644
index 0000000..e2575d5
@@ -0,0 +1,34 @@
+/*
+ * 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 _MISC_VAS_H
+#define _MISC_VAS_H
+
+#include <uapi/asm/vas.h>
+
+/*
+ * Min and max FIFO sizes are based on Version 1.05 Section 3.1.4.25
+ * (Local FIFO Size Register) of the VAS workbook.
+ */
+#define VAS_RX_FIFO_SIZE_MIN	(1 << 10)	/* 1KB */
+#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,
+};
+
+#endif /* _MISC_VAS_H */
arch/powerpc/include/uapi/asm/vas.h new file +25 -0
new file mode 100644
index 0000000..ddfe046
@@ -0,0 +1,25 @@
+/*
+ * 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 _UAPI_MISC_VAS_H
+#define _UAPI_MISC_VAS_H
+
+/*
+ * 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.
+ */
+#define VAS_THRESH_DISABLED		0
+#define VAS_THRESH_FIFO_GT_HALF_FULL	1
+#define VAS_THRESH_FIFO_GT_QTR_FULL	2
+#define VAS_THRESH_FIFO_GT_EIGHTH_FULL	3
+
+#endif /* _UAPI_MISC_VAS_H */
arch/powerpc/platforms/powernv/vas.h new file +379 -0

379 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

PATCH v4 3/11 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.

There is a lot of related code between the VAS/NX kernel drivers and skiboot. For consistency switch the order of parameters in SET_FIELD to match the order in skiboot.

---

Changelog[v3]
- Fix order of parameters in nx-842 driver.

---
 arch/powerpc/include/uapi/asm/vas.h | 8 ++++++++
 drivers/crypto/nx/nx-842-powernv.c  | 7 ++++---
 drivers/crypto/nx/nx-842.h          | 5 -----
 3 files changed, 12 insertions(+), 8 deletions(-)
arch/powerpc/include/uapi/asm/vas.h +8 -0
index ddfe046..21249f5 100644
@@ -22,4 +22,12 @@
 #define VAS_THRESH_FIFO_GT_QTR_FULL	2
 #define VAS_THRESH_FIFO_GT_EIGHTH_FULL	3
 
+/*
+ * 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 /* _UAPI_MISC_VAS_H */
drivers/crypto/nx/nx-842-powernv.c +4 -3
index 1710f80..3abb045 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]>");
@@ -424,9 +425,9 @@ static int nx842_powernv_function(const unsigned char *in, unsigned int inlen,
 
 	/* set up CCW */
 	ccw = 0;
-	ccw = SET_FIELD(ccw, CCW_CT, nx842_ct);
-	ccw = SET_FIELD(ccw, CCW_CI_842, 0); /* use 0 for hw auto-selection */
-	ccw = SET_FIELD(ccw, CCW_FC_842, fc);
+	ccw = SET_FIELD(CCW_CT, ccw, nx842_ct);
+	ccw = SET_FIELD(CCW_CI_842, ccw, 0); /* use 0 for hw auto-selection */
+	ccw = SET_FIELD(CCW_FC_842, ccw, fc);
 
 	/* set up CRB's CSB addr */
 	csb_addr = nx842_get_pa(csb) & CRB_CSB_ADDRESS;
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
#5 lore raw

PATCH v4 4/11 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. In the future this will be extended to add support for user space to access the NX coprocessors.

---
Changelog[v4]:
- [Michael Neuling] Fix some accidental deletions; fix help text in Kconfig; change vas_initialized to a function; move from drivers/misc to arch/powerpc/kernel
- Drop the vas_window_reset() interface. It is not needed as window will be initialized before each use.
Changelog[v3]:
- Zero vas_instances memory on allocation
- [Haren Myneni] Fix description in Kconfig
Changelog[v2]:
- Get HVWC, UWC and window address parameters from device tree.

---
 arch/powerpc/platforms/powernv/Kconfig      |  14 +++
 arch/powerpc/platforms/powernv/Makefile     |   1 +
 arch/powerpc/platforms/powernv/vas-window.c |  19 ++++
 arch/powerpc/platforms/powernv/vas.c        | 145 ++++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/vas.h        |   3 +
 5 files changed, 182 insertions(+)
 create mode 100644 arch/powerpc/platforms/powernv/vas-window.c
 create mode 100644 arch/powerpc/platforms/powernv/vas.c
arch/powerpc/platforms/powernv/Kconfig +14 -0
index 3a07e4d..54e2a4e 100644
@@ -27,3 +27,17 @@ config OPAL_PRD
 	help
 	  This enables the opal-prd driver, a facility to run processor
 	  recovery diagnostics on OpenPower machines
+
+config VAS
+	tristate "IBM Virtual Accelerator Switchboard (VAS)"
+	depends on PPC_POWERNV
+	default n
+	help
+	  This enables support for IBM Virtual Accelerator Switchboard (VAS).
+
+	  VAS allows accelerators in co-processors like NX-GZIP and NX-842
+	  to be accessible to kernel subsystems.
+
+	  VAS adapters are found in POWER9 based systems.
+
+	  If unsure, say N.
arch/powerpc/platforms/powernv/Makefile +1 -0
index b5d98cb..ebef20b 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_PPC_SCOM)	+= opal-xscom.o
 obj-$(CONFIG_MEMORY_FAILURE)	+= opal-memory-errors.o
 obj-$(CONFIG_TRACEPOINTS)	+= opal-tracepoints.o
 obj-$(CONFIG_OPAL_PRD)	+= opal-prd.o
+obj-$(CONFIG_VAS)	+= vas.o vas-window.o
arch/powerpc/platforms/powernv/vas-window.c new file +19 -0
new file mode 100644
index 0000000..6156fbe
@@ -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 "vas.h"
+
+/* stub for now */
+int vas_win_close(struct vas_window *window)
+{
+	return -1;
+}
arch/powerpc/platforms/powernv/vas.c new file +145 -0

145 lines not on this page · raw message

arch/powerpc/platforms/powernv/vas.h +3 -0
index c63395d..46aaa17 100644
@@ -384,4 +384,7 @@ struct vas_winctx {
 	enum vas_notify_after_count notify_after_count;
 };
 
+extern bool vas_initialized(void);
+extern struct vas_instance *find_vas_instance(int vasid);
+
 #endif /* _VAS_H */
Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH v4 04/11] VAS: Define vas_init() and vas_exit()

reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Sukadev,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.11-rc4 next-20170331]
[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/Add-Power9-PVR/20170402-155232
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-allmodconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705

reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/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 arch/powerpc/platforms/powernv/vas.c:17:0:

>> arch/powerpc/platforms/powernv/vas.h:17:3: error: #error "TODO: Compute RMA/Paste-address for 4K pages."
    # error "TODO: Compute RMA/Paste-address for 4K pages."
      ^~~~~

vim +17 arch/powerpc/platforms/powernv/vas.h

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

:::::: The code at line 17 was first introduced by commit
:::::: 8d1d7c159a85bf75ef7b06edf8f27ef56d6b4b3f 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

#7 lore raw

Re: [PATCH v4 04/11] VAS: Define vas_init() and vas_exit()

In reply to Sukadev Bhattiprolu
Quoted 5 lines · Sukadev Bhattiprolu [sukadevatlinux.vnet.ibm.com]

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. In the future this will be extended to add support for user space to access the NX coprocessors.

Add "depends on PPC_64K_PAGES" to the Kconfig for VAS.
---

Quoted 1 line

From ff6fb584282363f6917fd956ccac05822d1912d7 Mon Sep 17 00:00:00 2001

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 12 Jan 2017 02:16:10 -0500
Subject: [PATCH v4 04/11] VAS: Define vas_init() and vas_exit()

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. In the future this will be extended to add support for user space to access the NX coprocessors.

VAS is currently only supported with 64K page size.

---
Changelog[v4]:
- [Michael Neuling] Fix some accidental deletions; fix help text in Kconfig; change vas_initialized to a function; move from drivers/misc to arch/powerpc/kernel
- Drop the vas_window_reset() interface. It is not needed as window will be initialized before each use.
- Add a "depends on PPC_64K_PAGES"
Changelog[v3]:
- Zero vas_instances memory on allocation
- [Haren Myneni] Fix description in Kconfig
Changelog[v2]:
- Get HVWC, UWC and window address parameters from device tree.

---
 arch/powerpc/platforms/powernv/Kconfig      |  14 +++
 arch/powerpc/platforms/powernv/Makefile     |   1 +
 arch/powerpc/platforms/powernv/vas-window.c |  19 ++++
 arch/powerpc/platforms/powernv/vas.c        | 145 ++++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/vas.h        |   3 +
 5 files changed, 182 insertions(+)
 create mode 100644 arch/powerpc/platforms/powernv/vas-window.c
 create mode 100644 arch/powerpc/platforms/powernv/vas.c
arch/powerpc/platforms/powernv/Kconfig +14 -0
index 3a07e4d..34c344c 100644
@@ -27,3 +27,17 @@ config OPAL_PRD
 	help
 	  This enables the opal-prd driver, a facility to run processor
 	  recovery diagnostics on OpenPower machines
+
+config VAS
+	tristate "IBM Virtual Accelerator Switchboard (VAS)"
+	depends on PPC_POWERNV && PPC_64K_PAGES
+	default n
+	help
+	  This enables support for IBM Virtual Accelerator Switchboard (VAS).
+
+	  VAS allows accelerators in co-processors like NX-GZIP and NX-842
+	  to be accessible to kernel subsystems.
+
+	  VAS adapters are found in POWER9 based systems.
+
+	  If unsure, say N.
arch/powerpc/platforms/powernv/Makefile +1 -0
index b5d98cb..ebef20b 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_PPC_SCOM)	+= opal-xscom.o
 obj-$(CONFIG_MEMORY_FAILURE)	+= opal-memory-errors.o
 obj-$(CONFIG_TRACEPOINTS)	+= opal-tracepoints.o
 obj-$(CONFIG_OPAL_PRD)	+= opal-prd.o
+obj-$(CONFIG_VAS)	+= vas.o vas-window.o
arch/powerpc/platforms/powernv/vas-window.c new file +19 -0
new file mode 100644
index 0000000..6156fbe
@@ -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 "vas.h"
+
+/* stub for now */
+int vas_win_close(struct vas_window *window)
+{
+	return -1;
+}
arch/powerpc/platforms/powernv/vas.c new file +145 -0

145 lines not on this page · raw message

arch/powerpc/platforms/powernv/vas.h +3 -0
index 4953856..ba1e5b2 100644
@@ -376,4 +376,7 @@ struct vas_winctx {
 	enum vas_notify_after_count notify_after_count;
 };
 
+extern bool vas_initialized(void);
+extern struct vas_instance *find_vas_instance(int vasid);
+
 #endif /* _VAS_H */
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH v4 04/11] VAS: Define vas_init() and vas_exit()

In reply to Sukadev Bhattiprolu
Quoted 2 lines · Sukadev Bhattiprolu

+config VAS
+       tristate "IBM Virtual Accelerator Switchboard (VAS)"

CONFIG_IBM_VAS or PPC_VAS ... too high risk of collision otherwise

Ben.

#9 lore raw

Re: [PATCH v4 04/11] VAS: Define vas_init() and vas_exit()

In reply to Sukadev Bhattiprolu

arch/powerpc/platforms/powernv/vas.c line 39

Quoted 8 lines · Sukadev Bhattiprolu
arch/powerpc/platforms/powernv/vas.c new file +7 -0
+	p = of_get_property(dn, "vas-id", NULL);
+	if (!p) {
+		pr_err("VAS: NULL vas-id? %p\n", p);
+		return -ENODEV;
+	}
+
+	vinst->vas_id = of_read_number(p, 1);

of_property_read_u32()

Quoted 9 lines
arch/powerpc/platforms/powernv/vas.c new file +5 -0
+	/*
+	 * Hardcoded 6 is tied to corresponding code in
+	 *      skiboot.git/core/vas.c
+	 */
+	rc = of_property_read_variable_u64_array(dn, "reg", values,

6, 6);

(quoted diff) +2 -0
+	if (rc != 6) {
+		pr_err("VAS %d: Unable to read reg properties, rc

%d\n",

arch/powerpc/platforms/powernv/vas.c line 57

Quoted 10 lines
arch/powerpc/platforms/powernv/vas.c new file +10 -0
+				vinst->vas_id, rc);
+		return rc;
+	}
+
+	vinst->hvwc_bar_start = values[0];
+	vinst->hvwc_bar_len = values[1];
+	vinst->uwc_bar_start = values[2];
+	vinst->uwc_bar_len = values[3];
+	vinst->win_base_addr = values[4];
+	vinst->win_id_shift = values[5];

If you make the VAS a proper MMIO device on the powerbus (as explained in my comment to your OPAL patch), and you create this as a platform device based on the DT, the core will parse the reg property for you and will populate the device struct resource array for you.

Quoted 11 lines
arch/powerpc/platforms/powernv/vas.c new file +11 -0
+	return 0;
+}
+
+/*
+ * Although this is read/used multiple times, it is written to only
+ * during initialization.
+ */
+struct vas_instance *find_vas_instance(int vasid)
+{
+	int i;
+	struct vas_instance *vinst;

arch/powerpc/platforms/powernv/vas.c line 79

Quoted 10 lines
arch/powerpc/platforms/powernv/vas.c new file +10 -0
+
+	for (i = 0; i < vas_num_instances; i++) {
+		vinst = &vas_instances[i];
+		if (vinst->vas_id == vasid)
+			return vinst;
+	}
+	pr_err("VAS instance for vas-id %d not found\n", vasid);
+	WARN_ON_ONCE(1);
+	return NULL;
+}

This is gross. What is it needed for ?

Quoted 4 lines
arch/powerpc/platforms/powernv/vas.c new file +4 -0
+
+bool vas_initialized(void)
+{
+	return init_done;

arch/powerpc/platforms/powernv/vas.c line 94

Quoted 10 lines
arch/powerpc/platforms/powernv/vas.c new file +10 -0
+}
+
+int vas_init(void)
+{
+	int rc;
+	struct device_node *dn;
+	struct vas_instance *vinst;
+
+	if (!pvr_version_is(PVR_POWER9))
+		return -ENODEV;

No. Create a platform device that matches the corresponding device-tree node. One per instance.

The resulting VAS "driver" thus becomes a loadable module which you can put elsewhere in the tree, matching on the DT node "compatible" property.

You can then have the copros be chilren of it. The VAS driver can then create additional platform devices for its children, who can have their own module (which *can* depend on symbols exportd by the VAS one) etc...

Quoted 66 lines
arch/powerpc/platforms/powernv/vas.c new file +8 -0
+	vas_num_instances = 0;
+	for_each_node_by_name(dn, "vas")
+		vas_num_instances++;
+
+	if (!vas_num_instances)
+		return -ENODEV;
+
+	vas_instances = kcalloc(vas_num_instances, sizeof(*vinst),

GFP_KERNEL);

arch/powerpc/platforms/powernv/vas.c new file +8 -0
+	if (!vas_instances)
+		return -ENOMEM;
+
+	vinst = &vas_instances[0];
+	for_each_node_by_name(dn, "vas") {
+		rc = init_vas_instance(dn, vinst);
+		if (rc) {
+			pr_err("Error %d initializing VAS instance

%ld\n", rc,

arch/powerpc/platforms/powernv/vas.c new file +14 -0
+					(vinst-&vas_instances[0]));
+			goto cleanup;
+		}
+		vinst++;
+	}
+
+	rc = -ENODEV;
+	if (vinst == &vas_instances[0]) {
+		/* Should not happen as we saw some above. */
+		pr_err("VAS: Did not find any VAS DT nodes now!\n");
+		goto cleanup;
+	}
+
+	pr_devel("VAS: Initialized %d instances\n",

vas_num_instances);

arch/powerpc/platforms/powernv/vas.c new file +20 -0
+	init_done = true;
+
+	return 0;
+
+cleanup:
+	kfree(vas_instances);
+	return rc;
+}
+
+void vas_exit(void)
+{
+	init_done = false;
+	kfree(vas_instances);
+}
+
+module_init(vas_init);
+module_exit(vas_exit);
+MODULE_DESCRIPTION("IBM Virtual Accelerator Switchboard");
+MODULE_AUTHOR("Sukadev Bhattiprolu <[email protected]>");
+MODULE_LICENSE("GPL");
arch/powerpc/platforms/powernv/vas.h +0 -0
index c63395d..46aaa17 100644
@@ -384,4 +384,7 @@ struct vas_winctx {
  	enum vas_notify_after_count notify_after_count;
  };

arch/powerpc/platforms/powernv/vas.h +3 -0
+extern bool vas_initialized(void);
+extern struct vas_instance *find_vas_instance(int vasid);
+

 #endif /* _VAS_H */

#10 lore raw

Re: [PATCH v4 04/11] VAS: Define vas_init() and vas_exit()

In reply to Sukadev Bhattiprolu
Quoted 193 lines · 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. In the future this will be extended to add support for user space to access the NX coprocessors.

---
Changelog[v4]:
- [Michael Neuling] Fix some accidental deletions; fix help text in Kconfig; change vas_initialized to a function; move from drivers/misc to arch/powerpc/kernel
- Drop the vas_window_reset() interface. It is not needed as window will be initialized before each use.
Changelog[v3]:
- Zero vas_instances memory on allocation
- [Haren Myneni] Fix description in Kconfig
Changelog[v2]:
- Get HVWC, UWC and window address parameters from device tree.

---
 arch/powerpc/platforms/powernv/Kconfig      |  14 +++
 arch/powerpc/platforms/powernv/Makefile     |   1 +
 arch/powerpc/platforms/powernv/vas-window.c |  19 ++++
 arch/powerpc/platforms/powernv/vas.c        | 145 ++++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/vas.h        |   3 +
 5 files changed, 182 insertions(+)
 create mode 100644 arch/powerpc/platforms/powernv/vas-window.c
 create mode 100644 arch/powerpc/platforms/powernv/vas.c
arch/powerpc/platforms/powernv/Kconfig +14 -0
index 3a07e4d..54e2a4e 100644
@@ -27,3 +27,17 @@ config OPAL_PRD
 	help
 	  This enables the opal-prd driver, a facility to run processor
 	  recovery diagnostics on OpenPower machines
+
+config VAS
+	tristate "IBM Virtual Accelerator Switchboard (VAS)"
+	depends on PPC_POWERNV
+	default n
+	help
+	  This enables support for IBM Virtual Accelerator Switchboard (VAS).
+
+	  VAS allows accelerators in co-processors like NX-GZIP and NX-842
+	  to be accessible to kernel subsystems.
+
+	  VAS adapters are found in POWER9 based systems.
+
+	  If unsure, say N.
arch/powerpc/platforms/powernv/Makefile +1 -0
index b5d98cb..ebef20b 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_PPC_SCOM)	+= opal-xscom.o
 obj-$(CONFIG_MEMORY_FAILURE)	+= opal-memory-errors.o
 obj-$(CONFIG_TRACEPOINTS)	+= opal-tracepoints.o
 obj-$(CONFIG_OPAL_PRD)	+= opal-prd.o
+obj-$(CONFIG_VAS)	+= vas.o vas-window.o
arch/powerpc/platforms/powernv/vas-window.c new file +19 -0
new file mode 100644
index 0000000..6156fbe
@@ -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 "vas.h"
+
+/* stub for now */
+int vas_win_close(struct vas_window *window)
+{
+	return -1;
+}
arch/powerpc/platforms/powernv/vas.c new file +102 -0
new file mode 100644
index 0000000..9bf8f57
@@ -0,0 +1,145 @@
+/*
+ * 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/module.h>
+#include <linux/kernel.h>
+#include <linux/export.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+
+#include "vas.h"
+
+static bool init_done;
+int vas_num_instances;
+struct vas_instance *vas_instances;
+
+static int init_vas_instance(struct device_node *dn,
+				struct vas_instance *vinst)
+{
+	int rc;
+	const __be32 *p;
+	u64 values[6];
+
+	ida_init(&vinst->ida);
+	mutex_init(&vinst->mutex);
+
+	p = of_get_property(dn, "vas-id", NULL);
+	if (!p) {
+		pr_err("VAS: NULL vas-id? %p\n", p);
+		return -ENODEV;
+	}
+
+	vinst->vas_id = of_read_number(p, 1);
+
+	/*
+	 * Hardcoded 6 is tied to corresponding code in
+	 *      skiboot.git/core/vas.c
+	 */
+	rc = of_property_read_variable_u64_array(dn, "reg", values, 6, 6);
+	if (rc != 6) {
+		pr_err("VAS %d: Unable to read reg properties, rc %d\n",
+				vinst->vas_id, rc);
+		return rc;
+	}
+
+	vinst->hvwc_bar_start = values[0];
+	vinst->hvwc_bar_len = values[1];
+	vinst->uwc_bar_start = values[2];
+	vinst->uwc_bar_len = values[3];
+	vinst->win_base_addr = values[4];
+	vinst->win_id_shift = values[5];
+
+	return 0;
+}
+
+/*
+ * Although this is read/used multiple times, it is written to only
+ * during initialization.
+ */
+struct vas_instance *find_vas_instance(int vasid)
+{
+	int i;
+	struct vas_instance *vinst;
+
+	for (i = 0; i < vas_num_instances; i++) {
+		vinst = &vas_instances[i];
+		if (vinst->vas_id == vasid)
+			return vinst;
+	}
+	pr_err("VAS instance for vas-id %d not found\n", vasid);
+	WARN_ON_ONCE(1);
+	return NULL;
+}
+
+
+bool vas_initialized(void)
+{
+	return init_done;
+}
+
+int vas_init(void)
+{
+	int rc;
+	struct device_node *dn;
+	struct vas_instance *vinst;
+
+	if (!pvr_version_is(PVR_POWER9))
+		return -ENODEV;
+
+	vas_num_instances = 0;
+	for_each_node_by_name(dn, "vas")
+		vas_num_instances++;
+
+	if (!vas_num_instances)
+		return -ENODEV;
+

arch/powerpc/platforms/powernv/vas.c line 112

Quoted 10 lines
arch/powerpc/platforms/powernv/vas.c new file +10 -0
+	vas_instances = kcalloc(vas_num_instances, sizeof(*vinst), GFP_KERNEL);
+	if (!vas_instances)
+		return -ENOMEM;
+
+	vinst = &vas_instances[0];
+	for_each_node_by_name(dn, "vas") {
+		rc = init_vas_instance(dn, vinst);
+		if (rc) {
+			pr_err("Error %d initializing VAS instance %ld\n", rc,
+					(vinst-&vas_instances[0]));

You need a of_node_put(dn) here. The for_each_node_by_name() loop will get/put the references of the device_node for you. However, if you bail out of the loop you are responsible for the of_node_put() on the current *dn reference otherwise you will leak a reference.

-Tyrel

Quoted 46 lines
arch/powerpc/platforms/powernv/vas.c new file +33 -0
+			goto cleanup;
+		}
+		vinst++;
+	}
+
+	rc = -ENODEV;
+	if (vinst == &vas_instances[0]) {
+		/* Should not happen as we saw some above. */
+		pr_err("VAS: Did not find any VAS DT nodes now!\n");
+		goto cleanup;
+	}
+
+	pr_devel("VAS: Initialized %d instances\n", vas_num_instances);
+	init_done = true;
+
+	return 0;
+
+cleanup:
+	kfree(vas_instances);
+	return rc;
+}
+
+void vas_exit(void)
+{
+	init_done = false;
+	kfree(vas_instances);
+}
+
+module_init(vas_init);
+module_exit(vas_exit);
+MODULE_DESCRIPTION("IBM Virtual Accelerator Switchboard");
+MODULE_AUTHOR("Sukadev Bhattiprolu <[email protected]>");
+MODULE_LICENSE("GPL");
arch/powerpc/platforms/powernv/vas.h +3 -0
index c63395d..46aaa17 100644
@@ -384,4 +384,7 @@ struct vas_winctx {
 	enum vas_notify_after_count notify_after_count;
 };
 
+extern bool vas_initialized(void);
+extern struct vas_instance *find_vas_instance(int vasid);
+
 #endif /* _VAS_H */
#11 lore raw

Re: [PATCH v4 04/11] VAS: Define vas_init() and vas_exit()

Quoted 11 lines · Tyrel Datwyler [[email protected]] wrote:

arch/powerpc/platforms/powernv/vas.c line 112

Quoted 6 lines
arch/powerpc/platforms/powernv/vas.c new file +6 -0
+	vinst = &vas_instances[0];
+	for_each_node_by_name(dn, "vas") {
+		rc = init_vas_instance(dn, vinst);
+		if (rc) {
+			pr_err("Error %d initializing VAS instance %ld\n", rc,
+					(vinst-&vas_instances[0]));

You need a of_node_put(dn) here. The for_each_node_by_name() loop will get/put the references of the device_node for you. However, if you bail out of the loop you are responsible for the of_node_put() on the current *dn reference otherwise you will leak a reference.

Thanks for the pointing it out. Based on Ben's comments, I have modified this code and no longer need to break out of the loop.

Sukadev

#12 lore raw

PATCH v4 5/11 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 [v3]:
- Minor reorg/cleanup of map/unmap functions

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

---
 arch/powerpc/platforms/powernv/vas-window.c | 126 ++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)
arch/powerpc/platforms/powernv/vas-window.c +126 -0
index 6156fbe..ec084d2 100644
@@ -9,9 +9,135 @@
 
 #include <linux/types.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/io.h>
 
 #include "vas.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.
+ */
+static void unmap_wc_paste_kaddr(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);
+		window->paste_kaddr = NULL;
+	}
+
+}
+
+static void unmap_wc_mmio_bars(struct vas_window *window)
+{
+	int len;
+	uint64_t busaddr_start;
+
+	unmap_wc_paste_kaddr(window);
+
+	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);
+		window->hvwc_map = NULL;
+	}
+
+	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);
+		window->uwc_map = NULL;
+	}
+}
+
+/*
+ * 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->paste_kaddr = 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) {
+		unmap_wc_mmio_bars(window);
+		return -1;
+	}
+
+	return 0;
+}
+
 /* stub for now */
 int vas_win_close(struct vas_window *window)
 {
Signature · 1 line
2.7.4
#13 lore raw

Re: [PATCH v4 05/11] VAS: Define helpers for access MMIO regions

Quoted 9 lines · Sukadev Bhattiprolu
arch/powerpc/platforms/powernv/vas-window.c +9 -0
+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;
+       }

arch/powerpc/platforms/powernv/vas-window.c line 74

Quoted 10 lines
arch/powerpc/platforms/powernv/vas-window.c +10 -0
+
+       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;
+}

That's very wrong. I assume this never worked right ?

MMIO regions must be mapped non-cachable. Only the paste region requires being mapped cachable. Ask Aneesh for a cleaner way of doing it too while at it.

arch/powerpc/platforms/powernv/vas-window.c line 81

Quoted 6 lines
arch/powerpc/platforms/powernv/vas-window.c +6 -0
+/*
+ * Unmap the MMIO regions for a window.
+ */
+static void unmap_wc_paste_kaddr(struct vas_window *window)
+{
+       int len;

Don't use "wc"... that usually means "write combine".

Cheers,
Ben.

#14 lore raw

Re: [PATCH v4 05/11] VAS: Define helpers for access MMIO regions

Quoted 7 lines · Benjamin Herrenschmidt [[email protected]] wrote:

arch/powerpc/platforms/powernv/vas-window.c

Quoted 6 lines · Sukadev Bhattiprolu
arch/powerpc/platforms/powernv/vas-window.c +6 -0
+static void *map_mmio_region(char *name, uint64_t start, int len)
+{
+=A0=A0=A0=A0=A0=A0=A0void *map;
+
+=A0=A0=A0=A0=A0=A0=A0if (!request_mem_region(start, len, name)) {
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0pr_devel("%s(): request_m=

em_region(0x%llx, %d) failed\n",

Quoted 1 line
Quoted 1 line

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=

=A0=A0=A0=A0=A0=A0=A0=A0__func__, start, len);

Quoted 4 lines
Quoted 4 lines
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0return NULL;
+=A0=A0=A0=A0=A0=A0=A0}

+
+=A0=A0=A0=A0=A0=A0=A0map =3D __ioremap(start, len, pgprot_val(pgprot_c=

ached(__pgprot(0))));

Quoted 2 lines
Quoted 2 lines
+=A0=A0=A0=A0=A0=A0=A0if (!map) {
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0pr_devel("%s(): ioremap(0=

x%llx, %d) failed\n", __func__, start,

Quoted 1 line
Quoted 1 line

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=

=A0=A0=A0=A0=A0=A0=A0=A0len);

Quoted 7 lines

arch/powerpc/platforms/powernv/vas-window.c line 34

Quoted 5 lines
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0return NULL;
+=A0=A0=A0=A0=A0=A0=A0}
arch/powerpc/platforms/powernv/vas-window.c +3 -0
+
+=A0=A0=A0=A0=A0=A0=A0return map;
+}

=20
That's very wrong. I assume this never worked right ?

Untl recently, only tested on simics and has been working there. On the hardware, hitting a crash on the first mmio write...

Quoted 2 lines

=20
MMIO regions must be mapped non-cachable. Only the paste region

which maybe due to this :-) Should I change to pgprot_noncached() for the MMIO writes?

Quoted 2 lines

requires being mapped cachable. Ask Aneesh for a cleaner way of doing it too while at it.

Ok.

Quoted 9 lines

=20

arch/powerpc/platforms/powernv/vas-window.c

Quoted 6 lines
arch/powerpc/platforms/powernv/vas-window.c +6 -0
+/*
+ * Unmap the MMIO regions for a window.
+ */
+static void unmap_wc_paste_kaddr(struct vas_window *window)
+{
+=A0=A0=A0=A0=A0=A0=A0int len;

=20
Don't use "wc"... that usually means "write combine".

Ok.

Thanks,

Sukadev

#15 lore raw

Re: [PATCH v4 05/11] VAS: Define helpers for access MMIO regions

Quoted 2 lines · Sukadev Bhattiprolu

which maybe due to this :-) Should I change to pgprot_noncached() for the MMIO writes?

Just use normal ioremap().

Quoted 2 lines
Quoted 2 lines

requires being mapped cachable. Ask Aneesh for a cleaner way of doing it too while at it.

#16 lore raw

PATCH v4 6/11 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.

---
Changelog[v4]
- Michael Neuling] Use ilog2(), radix_enabled() helpers; drop warning when 32-bit app uses VAS (a follow-on patch will check and return error). Set MSR_PR state to 0 for kernel (rather than reading from MSR).

Changelog[v3]
- Have caller, rather than init_xlate_regs() reset window regs so we don't reset any settings caller may already have set.
- Translation mode should be 0x3 (0b11) not 0x11.
- Skip initilaizing read-only registers NX_UTIL and NX_UTIL_SE
- Skip initializing adder registers from UWC - they are already initialized from the HVWC.
- Check winctx->user_win when setting translation registers

---
 arch/powerpc/platforms/powernv/vas-window.c | 299 ++++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/vas.h        |  55 +++++
 2 files changed, 354 insertions(+)
arch/powerpc/platforms/powernv/vas-window.c +299 -0
index ec084d2..5ddcb63 100644
@@ -11,9 +11,12 @@
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/io.h>
+#include <linux/log2.h>
 
 #include "vas.h"
 
+static int fault_winid;
+
 /*
  * Compute the paste address region for the window @window using the
  * ->win_base_addr and ->win_id_shift we got from device tree.
@@ -138,6 +141,302 @@ int map_wc_mmio_bars(struct vas_window *window)
 	return 0;
 }
 
+/*
+ * Reset all valid registers in the HV and OS/User Window Contexts for
+ * the window identified by @window.
+ *
+ * NOTE: We cannot really use a for loop to reset window context. Not all
+ *	 offsets in a window context are valid registers and the valid
+ *	 registers are not sequential. And, we can only write to offsets
+ *	 with valid registers (or is that only in Simics?).
+ */
+void reset_window_regs(struct vas_window *window)
+{
+	write_hvwc_reg(window, VREG(LPID), 0ULL);
+	write_hvwc_reg(window, VREG(PID), 0ULL);
+	write_hvwc_reg(window, VREG(XLATE_MSR), 0ULL);
+	write_hvwc_reg(window, VREG(XLATE_LPCR), 0ULL);
+	write_hvwc_reg(window, VREG(XLATE_CTL), 0ULL);
+	write_hvwc_reg(window, VREG(AMR), 0ULL);
+	write_hvwc_reg(window, VREG(SEIDR), 0ULL);
+	write_hvwc_reg(window, VREG(FAULT_TX_WIN), 0ULL);
+	write_hvwc_reg(window, VREG(OSU_INTR_SRC_RA), 0ULL);
+	write_hvwc_reg(window, VREG(HV_INTR_SRC_RA), 0ULL);
+	write_hvwc_reg(window, VREG(PSWID), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE1), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE2), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE3), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE4), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE5), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE6), 0ULL);
+	write_hvwc_reg(window, VREG(LFIFO_BAR), 0ULL);
+	write_hvwc_reg(window, VREG(LDATA_STAMP_CTL), 0ULL);
+	write_hvwc_reg(window, VREG(LDMA_CACHE_CTL), 0ULL);
+	write_hvwc_reg(window, VREG(LRFIFO_PUSH), 0ULL);
+	write_hvwc_reg(window, VREG(CURR_MSG_COUNT), 0ULL);
+	write_hvwc_reg(window, VREG(LNOTIFY_AFTER_COUNT), 0ULL);
+	write_hvwc_reg(window, VREG(LRX_WCRED), 0ULL);
+	write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
+	write_hvwc_reg(window, VREG(TX_WCRED), 0ULL);
+	write_hvwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
+	write_hvwc_reg(window, VREG(LFIFO_SIZE), 0ULL);
+	write_hvwc_reg(window, VREG(WINCTL), 0ULL);
+	write_hvwc_reg(window, VREG(WIN_STATUS), 0ULL);
+	write_hvwc_reg(window, VREG(WIN_CTX_CACHING_CTL), 0ULL);
+	write_hvwc_reg(window, VREG(TX_RSVD_BUF_COUNT), 0ULL);
+	write_hvwc_reg(window, VREG(LRFIFO_WIN_PTR), 0ULL);
+	write_hvwc_reg(window, VREG(LNOTIFY_CTL), 0ULL);
+	write_hvwc_reg(window, VREG(LNOTIFY_PID), 0ULL);
+	write_hvwc_reg(window, VREG(LNOTIFY_LPID), 0ULL);
+	write_hvwc_reg(window, VREG(LNOTIFY_TID), 0ULL);
+	write_hvwc_reg(window, VREG(LNOTIFY_SCOPE), 0ULL);
+	write_hvwc_reg(window, VREG(NX_UTIL_ADDER), 0ULL);
+
+	/* Skip read-only registers: NX_UTIL and NX_UTIL_SE */
+
+	/*
+	 * The send and receive window credit adder registers are also
+	 * accessible from HVWC and have been initialized above. We don't
+	 * need to initialize from the OS/User Window Context, so skip
+	 * following calls:
+	 *
+	 *	write_uwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
+	 *	write_uwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
+	 */
+}
+
+/*
+ * Initialize window context registers related to Address Translation.
+ * These registers are common to send/receive windows although they
+ * differ for user/kernel windows. As we resolve the TODOs we may
+ * want to add fields to vas_winctx and move the initialization to
+ * init_vas_winctx_regs().
+ */
+static void init_xlate_regs(struct vas_window *window, bool user_win)
+{
+	uint64_t lpcr, val;
+
+	/*
+	 * MSR_TA, MSR_US are false for both kernel and user.
+	 * MSR_DR and MSR_PR are false for kernel.
+	 */
+	val = 0ULL;
+	val = SET_FIELD(VAS_XLATE_MSR_HV, val, true);
+	val = SET_FIELD(VAS_XLATE_MSR_SF, val, true);
+	if (user_win) {
+		val = SET_FIELD(VAS_XLATE_MSR_DR, val, true);
+		val = SET_FIELD(VAS_XLATE_MSR_PR, val, true);
+	}
+	write_hvwc_reg(window, VREG(XLATE_MSR), val);
+
+	lpcr = mfspr(SPRN_LPCR);
+	val = 0ULL;
+	/*
+	 * NOTE: From Section 5.7.6.1 Segment Lookaside Buffer of the
+	 *	 Power ISA, v2.07, Page size encoding is 0 = 4KB, 5 = 64KB.
+	 *
+	 * NOTE: From Section 1.3.1, Address Translation Context of the
+	 *	 Nest MMU Workbook, LPCR_SC should be 0 for Power9.
+	 */
+	val = SET_FIELD(VAS_XLATE_LPCR_PAGE_SIZE, val, 5);
+	val = SET_FIELD(VAS_XLATE_LPCR_ISL, val, lpcr & LPCR_ISL);
+	val = SET_FIELD(VAS_XLATE_LPCR_TC, val, lpcr & LPCR_TC);
+	val = SET_FIELD(VAS_XLATE_LPCR_SC, val, 0);
+	write_hvwc_reg(window, VREG(XLATE_LPCR), val);
+
+	/*
+	 * Section 1.3.1 (Address translation Context) of NMMU workbook.
+	 *	0b00	Hashed Page Table mode
+	 *	0b01	Reserved
+	 *	0b10	Radix on HPT
+	 *	0b11	Radix on Radix
+	 */
+	val = 0ULL;
+	val = SET_FIELD(VAS_XLATE_MODE, val, radix_enabled() ? 3 : 2);
+	write_hvwc_reg(window, VREG(XLATE_CTL), val);
+
+	/*
+	 * TODO: Can we mfspr(AMR) even for user windows?
+	 */
+	val = 0ULL;
+	val = SET_FIELD(VAS_AMR, val, mfspr(SPRN_AMR));
+	write_hvwc_reg(window, VREG(AMR), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_SEIDR, val, 0);
+	write_hvwc_reg(window, VREG(SEIDR), val);
+}
+
+/*
+ * Initialize Reserved Send Buffer Count for the send window. It involves
+ * writing to the register, reading it back to confirm that the hardware
+ * has enough buffers to reserve. See section 1.3.1.2.1 of VAS workbook.
+ *
+ * Since we can only make a best-effort attempt to fulfill the request,
+ * we don't return any errors if we cannot.
+ *
+ * TODO: Reserved (aka dedicated) send buffers are not supported yet.
+ */
+static void init_rsvd_tx_buf_count(struct vas_window *txwin,
+				struct vas_winctx *winctx)
+{
+	write_hvwc_reg(txwin, VREG(TX_RSVD_BUF_COUNT), 0ULL);
+}
+
+/*
+ * init_winctx_regs()
+ *	Initialize window context registers for a receive window.
+ *	Except for caching control and marking window open, the registers
+ *	are initialized in the order listed in Section 3.1.4 (Window Context
+ *	Cache Register Details) of the VAS workbook although they don't need
+ *	to be.
+ *
+ * Design note: For NX receive windows, NX allocates the FIFO buffer in OPAL
+ *	(so that it can get a large contiguous area) and passes that buffer
+ *	to kernel via device tree. We now write that buffer address to the
+ *	FIFO BAR. Would it make sense to do this all in OPAL? i.e have OPAL
+ *	write the per-chip RX FIFO addresses to the windows during boot-up
+ *	as a one-time task? That could work for NX but what about other
+ *	receivers?  Let the receivers tell us the rx-fifo buffers for now.
+ */
+int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx)
+{
+	uint64_t val;
+	int fifo_size;
+
+	reset_window_regs(window);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LPID, val, winctx->lpid);
+	write_hvwc_reg(window, VREG(LPID), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_PID_ID, val, winctx->pidr);
+	write_hvwc_reg(window, VREG(PID), val);
+
+	init_xlate_regs(window, winctx->user_win);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_FAULT_TX_WIN, val, fault_winid);
+	write_hvwc_reg(window, VREG(FAULT_TX_WIN), val);
+
+	/* In PowerNV, interrupts go to HV. */
+	write_hvwc_reg(window, VREG(OSU_INTR_SRC_RA), 0ULL);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_HV_INTR_SRC_RA, val, winctx->irq_port);
+	write_hvwc_reg(window, VREG(HV_INTR_SRC_RA), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_PSWID_EA_HANDLE, val, winctx->pswid);
+	write_hvwc_reg(window, VREG(PSWID), val);
+
+	write_hvwc_reg(window, VREG(SPARE1), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE2), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE3), 0ULL);
+
+	/* See also: Design note in function header */
+	val = 0ULL;
+	val = SET_FIELD(VAS_LFIFO_BAR, val, __pa(winctx->rx_fifo));
+	val = SET_FIELD(VAS_PAGE_MIGRATION_SELECT, val, 0);
+	write_hvwc_reg(window, VREG(LFIFO_BAR), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LDATA_STAMP, val, winctx->data_stamp);
+	write_hvwc_reg(window, VREG(LDATA_STAMP_CTL), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LDMA_TYPE, val, winctx->dma_type);
+	write_hvwc_reg(window, VREG(LDMA_CACHE_CTL), val);
+
+	write_hvwc_reg(window, VREG(LRFIFO_PUSH), 0ULL);
+	write_hvwc_reg(window, VREG(CURR_MSG_COUNT), 0ULL);
+	write_hvwc_reg(window, VREG(LNOTIFY_AFTER_COUNT), 0ULL);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LRX_WCRED, val, winctx->wcreds_max);
+	write_hvwc_reg(window, VREG(LRX_WCRED), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_TX_WCRED, val, winctx->wcreds_max);
+	write_hvwc_reg(window, VREG(TX_WCRED), val);
+
+	write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
+	write_hvwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
+
+	fifo_size = winctx->rx_fifo_size / 1024;
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LFIFO_SIZE, val, ilog2(fifo_size));
+	write_hvwc_reg(window, VREG(LFIFO_SIZE), val);
+
+	/* Update window control and caching control registers last so
+	 * we mark the window open only after fully initializing it and
+	 * pushing context to cache.
+	 */
+
+	write_hvwc_reg(window, VREG(WIN_STATUS), 0ULL);
+
+	init_rsvd_tx_buf_count(window, winctx);
+
+	/* for a send window, point to the matching receive window */
+	val = 0ULL;
+	val = SET_FIELD(VAS_LRX_WIN_ID, val, winctx->rx_win_id);
+	write_hvwc_reg(window, VREG(LRFIFO_WIN_PTR), val);
+
+	write_hvwc_reg(window, VREG(SPARE4), 0ULL);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_NOTIFY_DISABLE, val, winctx->notify_disable);
+	val = SET_FIELD(VAS_INTR_DISABLE, val, winctx->intr_disable);
+	val = SET_FIELD(VAS_NOTIFY_EARLY, val, winctx->notify_early);
+	val = SET_FIELD(VAS_NOTIFY_OSU_INTR, val, winctx->notify_os_intr_reg);
+	write_hvwc_reg(window, VREG(LNOTIFY_CTL), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LNOTIFY_PID, val, winctx->lnotify_pid);
+	write_hvwc_reg(window, VREG(LNOTIFY_PID), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LNOTIFY_LPID, val, winctx->lnotify_lpid);
+	write_hvwc_reg(window, VREG(LNOTIFY_LPID), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LNOTIFY_TID, val, winctx->lnotify_tid);
+	write_hvwc_reg(window, VREG(LNOTIFY_TID), val);
+
+	val = 0ULL;
+	val = SET_FIELD(VAS_LNOTIFY_MIN_SCOPE, val, winctx->min_scope);
+	val = SET_FIELD(VAS_LNOTIFY_MAX_SCOPE, val, winctx->max_scope);
+	write_hvwc_reg(window, VREG(LNOTIFY_SCOPE), val);
+
+	/* Skip read-only registers NX_UTIL and NX_UTIL_SE */
+
+	write_hvwc_reg(window, VREG(SPARE5), 0ULL);
+	write_hvwc_reg(window, VREG(NX_UTIL_ADDER), 0ULL);
+	write_hvwc_reg(window, VREG(SPARE6), 0ULL);
+
+	/* Finally, push window context to memory and... */
+	val = 0ULL;
+	val = SET_FIELD(VAS_PUSH_TO_MEM, val, 1);
+	write_hvwc_reg(window, VREG(WIN_CTX_CACHING_CTL), val);
+
+	/* ... mark the window open for business */
+	val = 0ULL;
+	val = SET_FIELD(VAS_WINCTL_REJ_NO_CREDIT, val, winctx->rej_no_credit);
+	val = SET_FIELD(VAS_WINCTL_PIN, val, winctx->pin_win);
+	val = SET_FIELD(VAS_WINCTL_TX_WCRED_MODE, val, winctx->tx_wcred_mode);
+	val = SET_FIELD(VAS_WINCTL_RX_WCRED_MODE, val, winctx->rx_wcred_mode);
+	val = SET_FIELD(VAS_WINCTL_TX_WORD_MODE, val, winctx->tx_word_mode);
+	val = SET_FIELD(VAS_WINCTL_RX_WORD_MODE, val, winctx->rx_word_mode);
+	val = SET_FIELD(VAS_WINCTL_FAULT_WIN, val, winctx->fault_win);
+	val = SET_FIELD(VAS_WINCTL_NX_WIN, val, winctx->nx_win);
+	val = SET_FIELD(VAS_WINCTL_OPEN, val, 1);
+	write_hvwc_reg(window, VREG(WINCTL), val);
+
+	return 0;
+}
+
 /* stub for now */
 int vas_win_close(struct vas_window *window)
 {
arch/powerpc/platforms/powernv/vas.h +55 -0

65 lines not on this page · raw message

Signature · 1 line
2.7.4
#17 lore raw

PATCH v4 7/11 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.

---
 arch/powerpc/platforms/powernv/vas-window.c | 63 ++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/vas-window.c +62 -1
index 5ddcb63..0c178fe 100644
@@ -120,7 +120,7 @@ static void unmap_wc_mmio_bars(struct vas_window *window)
  * 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)
+static int map_wc_mmio_bars(struct vas_window *window)
 {
 	int len;
 	uint64_t start;
@@ -437,6 +437,67 @@ int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx)
 	return 0;
 }
 
+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, 0, &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;
+}
+
+void vas_window_free(struct vas_window *window)
+{
+	unmap_wc_mmio_bars(window);
+	kfree(window->paste_addr_name);
+	kfree(window);
+}
+
+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;
+}
+
 /* stub for now */
 int vas_win_close(struct vas_window *window)
 {
Signature · 1 line
2.7.4
#18 lore raw

PATCH v4 8/11 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.

---

Changelog[v3]:
- Fault receive windows must enable interrupts and disable notifications. NX Windows are opposite.
- Use macros rather than enum for threshold-control mode
- Ignore irq_ports for in-kernel windows. They are needed for user space windows and will be added later

---
 arch/powerpc/include/asm/vas.h              |  45 ++++++
 arch/powerpc/platforms/powernv/vas-window.c | 205 +++++++++++++++++++++++++++-
 arch/powerpc/platforms/powernv/vas.h        |  11 ++
 3 files changed, 260 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/vas.h +45 -0
index e2575d5..09ea6f7 100644
@@ -31,4 +31,49 @@ enum vas_cop_type {
 	VAS_COP_TYPE_MAX,
 };
 
+/*
+ * 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;
+
+	int tc_mode;
+};
+
+/*
+ * Helper to initialize receive window attributes to defaults for an
+ * NX window.
+ */
+extern void vas_init_rx_win_attr(struct vas_rx_win_attr *rxattr,
+				enum vas_cop_type cop);
+
+/*
+ * 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.
+ */
+extern struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
+			struct vas_rx_win_attr *attr);
+
 #endif /* _MISC_VAS_H */
arch/powerpc/platforms/powernv/vas-window.c +204 -1

214 lines not on this page · raw message

arch/powerpc/platforms/powernv/vas.h +11 -0
index bb7908b..86ed526 100644
@@ -399,6 +399,16 @@ extern struct vas_instance *find_vas_instance(int vasid);
 #define VREG(r)		VREG_SFX(r, _OFFSET)
 
 #ifdef 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)
 {
@@ -411,6 +421,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 */
 
Signature · 1 line
2.7.4
#19 lore raw

PATCH v4 9/11 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.

---
Changelog[v4]:
- Drop the poll for credits return (we can set the required credit, but cannot really find the available credit at a point in time)

Changelog[v3]:
- Fix order of parameters in GET_FIELD().
- Update references and sequence for closing/quiescing a window.

---
 arch/powerpc/include/asm/vas.h              |  7 +++
 arch/powerpc/platforms/powernv/vas-window.c | 96 +++++++++++++++++++++++++++--
 2 files changed, 99 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/vas.h +7 -0
index 09ea6f7..c923b8f 100644
@@ -76,4 +76,11 @@ extern void vas_init_rx_win_attr(struct vas_rx_win_attr *rxattr,
 extern 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);
+
 #endif /* _MISC_VAS_H */
arch/powerpc/platforms/powernv/vas-window.c +92 -4

112 lines not on this page · raw message

Signature · 1 line
2.7.4
#20 lore raw

PATCH v4 10/11 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 [vasid, cop] parameters, must already be open in VAS (i.e connected to an NX engine).

---
Changelog [v3]:
- Distinguish between hardware PID (SPRN_PID) and Linux pid.
- Use macros rather than enum for threshold-control mode
- Set the pid of send window from attr (needed for user space send windows).
- Ignore irq port setting for now. They are needed for user space windows and will be added later

---
 arch/powerpc/include/asm/vas.h              |  42 ++++++++
 arch/powerpc/platforms/powernv/vas-window.c | 157 ++++++++++++++++++++++++++++
 2 files changed, 199 insertions(+)
arch/powerpc/include/asm/vas.h +42 -0
index c923b8f..944bb4b 100644
@@ -61,6 +61,29 @@ 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 pidr;		/* hardware PID (from SPRN_PID) */
+	int pid;		/* linux process id */
+	int pswid;
+	int rsvd_txbuf_count;
+	int tc_mode;
+
+	bool user_win;
+	bool pin_win;
+	bool rej_no_credit;
+	bool rsvd_txbuf_enable;
+	bool tx_wcred_mode;
+	bool rx_wcred_mode;
+	bool tx_win_ord_mode;
+	bool rx_win_ord_mode;
+};
+
+/*
  * Helper to initialize receive window attributes to defaults for an
  * NX window.
  */
@@ -77,6 +100,25 @@ extern struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
 			struct vas_rx_win_attr *attr);
 
 /*
+ * Helper to initialize send window attributes to defaults for an NX window.
+ */
+extern void vas_init_tx_win_attr(struct vas_tx_win_attr *txattr,
+			enum vas_cop_type cop);
+
+/*
+ * 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.
arch/powerpc/platforms/powernv/vas-window.c +157 -0

163 lines not on this page · raw message

Signature · 1 line
2.7.4
#21 lore raw

PATCH v4 11/11 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.

---
Changelog[v3]
- Map raw CR value from paste instruction into an error code.

---
 arch/powerpc/include/asm/vas.h              | 13 +++++
 arch/powerpc/platforms/powernv/copy-paste.h | 74 +++++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/vas-window.c | 50 +++++++++++++++++++
 arch/powerpc/platforms/powernv/vas.h        | 14 ++++++
 4 files changed, 151 insertions(+)
 create mode 100644 arch/powerpc/platforms/powernv/copy-paste.h
arch/powerpc/include/asm/vas.h +13 -0
index 944bb4b..4e5a470 100644
@@ -125,4 +125,17 @@ 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);
+
 #endif /* _MISC_VAS_H */
arch/powerpc/platforms/powernv/copy-paste.h new file +74 -0

74 lines not on this page · raw message

arch/powerpc/platforms/powernv/vas-window.c +50 -0

62 lines not on this page · raw message

arch/powerpc/platforms/powernv/vas.h +14 -0
index 86ed526..83c2559 100644
@@ -453,4 +453,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 /* _VAS_H */
Signature · 1 line
2.7.4