linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	michael.neuling@au1.ibm.com, stewart@linux.vnet.ibm.com,
	hbabu@us.ibm.com, linuxppc-dev@ozlabs.org
Subject: [RFC PATCH 11/11] VAS: Define/use interface to setup irq handling.
Date: Fri, 11 Nov 2016 09:02:56 -0800	[thread overview]
Message-ID: <1478883776-11121-12-git-send-email-sukadev@linux.vnet.ibm.com> (raw)
In-Reply-To: <1478883776-11121-1-git-send-email-sukadev@linux.vnet.ibm.com>

When VAS hardware encounters an address translation error it will
post the failing CRB to a fault window and issue an interrupt to
the kernel.

Use OPAL/XIVE to register a IRQ trigger port for each send window
and setup IRQ handling in the kernel for this IRQ. (The existing
init_winctx_regs() call configures the trigger port in the VAS
registers.

When the VAS hardware generates an interrupt, the kernel interrupt
handler wakes up the fault thread (from previous patch) to process
the fault CRB. As mentioned in that patch, this interrupt handling
is needed when we support user space access to VAS/NX. But including
this patch of routing VAS interrupt to kernel handler for review.

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/opal-api.h            |  3 +-
 arch/powerpc/include/asm/opal.h                |  2 +
 arch/powerpc/platforms/powernv/opal-wrappers.S |  2 +
 drivers/misc/vas/vas-window.c                  | 81 ++++++++++++++++++++++++++
 4 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/opal-api.h b/arch/powerpc/include/asm/opal-api.h
index eabe07e..192d430 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -168,7 +168,8 @@
 #define OPAL_INT_SET_MFRR			125
 #define OPAL_PCI_TCE_KILL			126
 #define OPAL_VAS_READ_FIR			128
-#define OPAL_LAST				128
+#define OPAL_VAS_GET_TRIGGER_PORT		129
+#define OPAL_LAST				129
 
 /* Device tree flags */
 
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index b20ec10..30042f9 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -229,6 +229,8 @@ int64_t opal_rm_pci_tce_kill(uint64_t phb_id, uint32_t kill_type,
 			     uint32_t pe_num, uint32_t tce_size,
 			     uint64_t dma_addr, uint32_t npages);
 int64_t opal_vas_read_fir(uint32_t chip_id, int32_t idx, __be64 *fir);
+int64_t opal_vas_get_trigger_port(uint32_t chip_id, int32_t idx, __be32 *girq,
+				 __be64 *port);
 
 /* Internal functions */
 extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S b/arch/powerpc/platforms/powernv/opal-wrappers.S
index acb6396..9b88e22 100644
--- a/arch/powerpc/platforms/powernv/opal-wrappers.S
+++ b/arch/powerpc/platforms/powernv/opal-wrappers.S
@@ -309,3 +309,5 @@ OPAL_CALL(opal_int_set_mfrr,			OPAL_INT_SET_MFRR);
 OPAL_CALL(opal_pci_tce_kill,			OPAL_PCI_TCE_KILL);
 OPAL_CALL_REAL(opal_rm_pci_tce_kill,		OPAL_PCI_TCE_KILL);
 OPAL_CALL(opal_vas_read_fir,			OPAL_VAS_READ_FIR);
+OPAL_CALL(opal_vas_get_trigger_port,		OPAL_VAS_GET_TRIGGER_PORT);
+
diff --git a/drivers/misc/vas/vas-window.c b/drivers/misc/vas/vas-window.c
index f6610de..ba10922 100644
--- a/drivers/misc/vas/vas-window.c
+++ b/drivers/misc/vas/vas-window.c
@@ -10,7 +10,11 @@
 #include <linux/types.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
+#include <linux/irqdomain.h>
+#include <linux/interrupt.h>
 #include <linux/io.h>
+#include <asm/opal.h>
+#include <asm/opal-api.h>
 #include <asm/vas.h>
 #include "vas-internal.h"
 #include "copy-paste.h"
@@ -603,6 +607,72 @@ int vas_window_reset(struct vas_instance *vinst, int winid)
 	return 0;
 }
 
+static irqreturn_t vas_irq_handler(int virq, void *data)
+{
+	struct vas_window *win = data;
+
+	pr_devel("VAS: virq %d, window %d\n", virq, win->winid);
+	vas_wakeup_fault_win_thread();
+
+	return IRQ_HANDLED;
+}
+
+static int setup_irq_mapping(struct vas_window *win)
+{
+	int rc;
+	int winid;
+	uint32_t virq;
+	int32_t girq;
+	uint64_t port;
+	char devname[64];
+
+	winid = win->winid;
+	snprintf(devname, sizeof(devname), "vas-window-%d", winid);
+
+	girq = 0;
+	port = 0ULL;
+	rc = opal_vas_get_trigger_port(win->vinst->chip, winid, &girq, &port);
+
+	pr_devel("VAS: %swin #%d: IRQ trigger %d, port 0x%llx, rc %d\n",
+			win->txwin ? "Tx" : "Rx", winid, girq, port, rc);
+	if (rc)
+		return -EINVAL;
+
+	virq = irq_create_mapping(NULL, girq);
+	if (!virq) {
+		pr_devel("VAS: %swin #%d: Unable to map global irq %d\n",
+				win->txwin ? "Tx" : "Rx", winid, girq);
+		return -EINVAL;
+	}
+
+	rc = request_irq(virq, vas_irq_handler, 0, devname, win);
+	if (rc) {
+		pr_devel("VAS: %swin #%d: request_irq() returns %d\n",
+				win->txwin ? "Tx" : "Rx", winid, rc);
+		return rc;
+	}
+
+	win->hwirq = girq;
+	win->irq_port = port;
+
+	return 0;
+}
+
+static void free_irq_mapping(struct vas_window *win)
+{
+	unsigned int irq;
+
+	irq = irq_find_mapping(NULL, win->hwirq);
+	if (!irq) {
+		pr_devel("VAS: Receieved unknown hwirq %d\n", win->hwirq);
+		WARN_ON_ONCE(true);
+		return;
+	}
+
+	free_irq(irq, win);
+}
+
+
 static void put_rx_win(struct vas_window *rxwin)
 {
 	/* Better not be a send window! */
@@ -897,6 +967,15 @@ struct vas_window *vas_tx_win_open(int node, int chip, enum vas_cop_type cop,
 	txwin->rxwin = rxwin;
 	txwin->nx_win = txwin->rxwin->nx_win;
 
+	if (setup_irq_mapping(txwin)) {
+		/*
+		 * TODO: IRQ mapping is essential for user space send windows.
+		 *	 We only support in-kernel initially, so ignore errors
+		 *	 in setting up IRQ mappings for now.
+		 */
+		WARN_ON_ONCE(1);
+	}
+
 	init_winctx_for_txwin(txwin, attr, &winctx);
 
 	init_winctx_regs(txwin, &winctx);
@@ -1014,6 +1093,8 @@ retry:
 	if (window->txwin)
 		put_rx_win(window->rxwin);
 
+	free_irq_mapping(window);
+
 	vas_release_window_id(&window->vinst->ida, window->winid);
 
 	vas_window_free(window);
-- 
1.8.3.1

      parent reply	other threads:[~2016-11-11 17:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-11 17:02 [RFC PATCH 00/11] Enable VAS Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 01/11] VAS: Define macros and register fields Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 02/11] VAS: Define vas_dev_init() and vas_dev_exit() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 03/11] VAS: Define helpers for access MMIO regions Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 04/11] VAS: Define helpers to init window context Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 05/11] VAS: Define helpers to alloc/free windows Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 06/11] VAS: Define vas_rx_win_open() and vas_win_close() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 07/11] VAS: Define vas_tx_win_open() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 08/11] VAS: Define vas_copy_crb() and vas_paste_crb() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 09/11] VAS: Define/use vas_print_regs() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 10/11] VAS: Create a thread to monitor fault-window Sukadev Bhattiprolu
2016-11-11 17:02 ` Sukadev Bhattiprolu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478883776-11121-12-git-send-email-sukadev@linux.vnet.ibm.com \
    --to=sukadev@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=hbabu@us.ibm.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=michael.neuling@au1.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=stewart@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).