linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Uma Krishnan <ukrishn@linux.vnet.ibm.com>
To: linux-scsi@vger.kernel.org,
	James Bottomley <jejb@linux.vnet.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Matthew R. Ochs" <mrochs@linux.vnet.ibm.com>,
	"Manoj N. Kumar" <manoj@linux.vnet.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org,
	Andrew Donnellan <andrew.donnellan@au1.ibm.com>,
	Frederic Barrat <fbarrat@linux.vnet.ibm.com>,
	Christophe Lombard <clombard@linux.vnet.ibm.com>
Subject: [PATCH 26/38] cxlflash: Support starting user contexts
Date: Thu, 22 Feb 2018 16:26:56 -0600	[thread overview]
Message-ID: <1519338416-52723-1-git-send-email-ukrishn@linux.vnet.ibm.com> (raw)
In-Reply-To: <1519338010-51782-1-git-send-email-ukrishn@linux.vnet.ibm.com>

User contexts request interrupts and are started using the "start work"
interface. Populate the start_work() fop to allocate and map interrupts
before starting the user context. As part of starting the context, update
the user process identification logic to properly derive the data required
by the SPA. Also, introduce a skeleton interrupt handler using a bitmap,
flag, and spinlock to track interrupts. This handler will be expanded in
future commits.

Signed-off-by: Uma Krishnan <ukrishn@linux.vnet.ibm.com>
---
 drivers/scsi/cxlflash/ocxl_hw.c | 99 ++++++++++++++++++++++++++++++++++++++++-
 drivers/scsi/cxlflash/ocxl_hw.h |  3 ++
 2 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/cxlflash/ocxl_hw.c b/drivers/scsi/cxlflash/ocxl_hw.c
index 3b28c2a..4ca4a72 100644
--- a/drivers/scsi/cxlflash/ocxl_hw.c
+++ b/drivers/scsi/cxlflash/ocxl_hw.c
@@ -318,7 +318,9 @@ static int start_context(struct ocxlflash_context *ctx)
 	void *link_token = afu->link_token;
 	struct device *dev = afu->dev;
 	bool master = ctx->master;
+	struct mm_struct *mm;
 	int rc = 0;
+	u32 pid;
 
 	if (master) {
 		ctx->psn_size = acfg->global_mmio_size;
@@ -328,9 +330,16 @@ static int start_context(struct ocxlflash_context *ctx)
 		ctx->psn_phys = afu->ppmmio_phys + (ctx->pe * ctx->psn_size);
 	}
 
+	/* pid and mm not set for master contexts */
+	if (master) {
+		pid = 0;
+		mm = NULL;
+	} else {
+		pid = current->mm->context.id;
+		mm = current->mm;
+	}
 
-	/* pid, tid, amr and mm are zeroes/NULL for a kernel context */
-	rc = ocxl_link_add_pe(link_token, ctx->pe, 0, 0, 0, NULL, NULL, NULL);
+	rc = ocxl_link_add_pe(link_token, ctx->pe, pid, 0, 0, mm, NULL, NULL);
 	if (unlikely(rc)) {
 		dev_err(dev, "%s: ocxl_link_add_pe failed rc=%d\n",
 			__func__, rc);
@@ -442,10 +451,14 @@ static void *ocxlflash_dev_context_init(struct pci_dev *pdev, void *afu_cookie)
 		goto err2;
 	}
 
+	spin_lock_init(&ctx->slock);
+
 	ctx->pe = rc;
 	ctx->master = false;
 	ctx->mapping = NULL;
 	ctx->hw_afu = afu;
+	ctx->irq_bitmap = 0;
+	ctx->pending_irq = false;
 out:
 	return ctx;
 err2:
@@ -948,6 +961,87 @@ static void *ocxlflash_fops_get_context(struct file *file)
 	return file->private_data;
 }
 
+/**
+ * ocxlflash_afu_irq() - interrupt handler for user contexts
+ * @irq:	Interrupt number.
+ * @data:	Private data provided at interrupt registration, the context.
+ *
+ * Return: Always return IRQ_HANDLED.
+ */
+static irqreturn_t ocxlflash_afu_irq(int irq, void *data)
+{
+	struct ocxlflash_context *ctx = data;
+	struct device *dev = ctx->hw_afu->dev;
+	int i;
+
+	dev_dbg(dev, "%s: Interrupt raised for pe %i virq %i\n",
+		__func__, ctx->pe, irq);
+
+	for (i = 0; i < ctx->num_irqs; i++) {
+		if (ctx->irqs[i].virq == irq)
+			break;
+	}
+	if (unlikely(i >= ctx->num_irqs)) {
+		dev_err(dev, "%s: Received AFU IRQ out of range\n", __func__);
+		goto out;
+	}
+
+	spin_lock(&ctx->slock);
+	set_bit(i - 1, &ctx->irq_bitmap);
+	ctx->pending_irq = true;
+	spin_unlock(&ctx->slock);
+out:
+	return IRQ_HANDLED;
+}
+
+/**
+ * ocxlflash_start_work() - start a user context
+ * @ctx_cookie:	Context to be started.
+ * @num_irqs:	Number of interrupts requested.
+ *
+ * Return: 0 on success, -errno on failure
+ */
+static int ocxlflash_start_work(void *ctx_cookie, u64 num_irqs)
+{
+	struct ocxlflash_context *ctx = ctx_cookie;
+	struct ocxl_hw_afu *afu = ctx->hw_afu;
+	struct device *dev = afu->dev;
+	char *name;
+	int rc = 0;
+	int i;
+
+	rc = alloc_afu_irqs(ctx, num_irqs);
+	if (unlikely(rc < 0)) {
+		dev_err(dev, "%s: alloc_afu_irqs failed rc=%d\n", __func__, rc);
+		goto out;
+	}
+
+	for (i = 0; i < num_irqs; i++) {
+		name = kasprintf(GFP_KERNEL, "ocxlflash-%s-pe%i-%i",
+				 dev_name(dev), ctx->pe, i);
+		rc = afu_map_irq(0, ctx, i, ocxlflash_afu_irq, ctx, name);
+		kfree(name);
+		if (unlikely(rc < 0)) {
+			dev_err(dev, "%s: afu_map_irq failed rc=%d\n",
+				__func__, rc);
+			goto err;
+		}
+	}
+
+	rc = start_context(ctx);
+	if (unlikely(rc)) {
+		dev_err(dev, "%s: start_context failed rc=%d\n", __func__, rc);
+		goto err;
+	}
+out:
+	return rc;
+err:
+	for (i = i-1; i >= 0; i--)
+		afu_unmap_irq(0, ctx, i, ctx);
+	free_afu_irqs(ctx);
+	goto out;
+}
+
 /* Backend ops to ocxlflash services */
 const struct cxlflash_backend_ops cxlflash_ocxl_ops = {
 	.module			= THIS_MODULE,
@@ -970,4 +1064,5 @@ const struct cxlflash_backend_ops cxlflash_ocxl_ops = {
 	.destroy_afu		= ocxlflash_destroy_afu,
 	.get_fd			= ocxlflash_get_fd,
 	.fops_get_context	= ocxlflash_fops_get_context,
+	.start_work		= ocxlflash_start_work,
 };
diff --git a/drivers/scsi/cxlflash/ocxl_hw.h b/drivers/scsi/cxlflash/ocxl_hw.h
index 53c2d33..c7cbf67 100644
--- a/drivers/scsi/cxlflash/ocxl_hw.h
+++ b/drivers/scsi/cxlflash/ocxl_hw.h
@@ -54,6 +54,9 @@ struct ocxlflash_context {
 	phys_addr_t psn_phys;		/* Process mapping */
 	u64 psn_size;			/* Process mapping size */
 
+	spinlock_t slock;		/* Protects irq/fault/event updates */
 	struct ocxlflash_irqs *irqs;	/* Pointer to array of structures */
 	int num_irqs;			/* Number of interrupts */
+	bool pending_irq;		/* Pending interrupt on the context */
+	ulong irq_bitmap;		/* Bits indicating pending irq num */
 };
-- 
2.1.0

  parent reply	other threads:[~2018-02-22 22:27 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-22 22:20 [PATCH 00/38] cxlflash: OpenCXL transport support Uma Krishnan
2018-02-22 22:21 ` [PATCH 01/38] cxlflash: Preserve number of interrupts for master contexts Uma Krishnan
2018-02-22 22:22 ` [PATCH 02/38] cxlflash: Avoid clobbering context control register value Uma Krishnan
2018-02-22 22:22 ` [PATCH 03/38] cxlflash: Add argument identifier names Uma Krishnan
2018-02-22 22:22 ` [PATCH 04/38] cxlflash: Introduce OpenCXL backend Uma Krishnan
2018-02-23  4:28   ` Andrew Donnellan
2018-02-23 19:36     ` Uma Krishnan
2018-02-22 22:23 ` [PATCH 05/38] cxlflash: Hardware AFU for OpenCXL Uma Krishnan
2018-02-22 22:23 ` [PATCH 06/38] cxlflash: Read host function configuration Uma Krishnan
2018-02-22 22:23 ` [PATCH 07/38] cxlflash: Setup function acTag range Uma Krishnan
2018-02-22 22:23 ` [PATCH 08/38] cxlflash: Read host AFU configuration Uma Krishnan
2018-02-22 22:23 ` [PATCH 09/38] cxlflash: Setup AFU acTag range Uma Krishnan
2018-02-22 22:24 ` [PATCH 10/38] cxlflash: Setup AFU PASID Uma Krishnan
2018-02-22 22:24 ` [PATCH 11/38] cxlflash: Adapter context support for OpenCXL Uma Krishnan
2018-02-22 22:24 ` [PATCH 12/38] cxlflash: Use IDR to manage adapter contexts Uma Krishnan
2018-02-22 22:24 ` [PATCH 13/38] cxlflash: Support adapter file descriptors for OpenCXL Uma Krishnan
2018-02-22 22:24 ` [PATCH 14/38] cxlflash: Support adapter context discovery Uma Krishnan
2018-02-22 22:24 ` [PATCH 15/38] cxlflash: Support image reload policy modification Uma Krishnan
2018-02-22 22:24 ` [PATCH 16/38] cxlflash: MMIO map the AFU Uma Krishnan
2018-02-22 22:25 ` [PATCH 17/38] cxlflash: Support starting an adapter context Uma Krishnan
2018-02-22 22:25 ` [PATCH 18/38] cxlflash: Support process specific mappings Uma Krishnan
2018-02-22 22:25 ` [PATCH 19/38] cxlflash: Support AFU state toggling Uma Krishnan
2018-02-22 22:25 ` [PATCH 20/38] cxlflash: Support reading adapter VPD data Uma Krishnan
2018-02-22 22:25 ` [PATCH 21/38] cxlflash: Setup function OpenCXL link Uma Krishnan
2018-02-22 22:26 ` [PATCH 22/38] cxlflash: Setup OpenCXL transaction layer Uma Krishnan
2018-02-22 22:26 ` [PATCH 23/38] cxlflash: Support process element lifecycle Uma Krishnan
2018-02-22 22:26 ` [PATCH 24/38] cxlflash: Support AFU interrupt management Uma Krishnan
2018-02-22 22:26 ` [PATCH 25/38] cxlflash: Support AFU interrupt mapping and registration Uma Krishnan
2018-02-22 22:26 ` Uma Krishnan [this message]
2018-02-22 22:27 ` [PATCH 27/38] cxlflash: Support adapter context polling Uma Krishnan
2018-02-22 22:27 ` [PATCH 28/38] cxlflash: Support adapter context reading Uma Krishnan
2018-02-22 22:27 ` [PATCH 29/38] cxlflash: Support adapter context mmap and release Uma Krishnan
2018-02-22 22:27 ` [PATCH 30/38] cxlflash: Support file descriptor mapping Uma Krishnan
2018-02-22 22:27 ` [PATCH 31/38] cxlflash: Introduce object handle fop Uma Krishnan
2018-02-22 22:27 ` [PATCH 32/38] cxlflash: Setup LISNs for user contexts Uma Krishnan
2018-02-22 22:27 ` [PATCH 33/38] cxlflash: Setup LISNs for master contexts Uma Krishnan
2018-02-22 22:28 ` [PATCH 34/38] cxlflash: Update synchronous interrupt status bits Uma Krishnan
2018-02-22 22:28 ` [PATCH 35/38] cxlflash: Introduce OCXL context state machine Uma Krishnan
2018-02-22 22:28 ` [PATCH 36/38] cxlflash: Register for translation errors Uma Krishnan
2018-02-22 22:28 ` [PATCH 37/38] cxlflash: Support AFU reset Uma Krishnan
2018-02-22 22:28 ` [PATCH 38/38] cxlflash: Enable OpenCXL operations Uma Krishnan
2018-02-23  4:13 ` [PATCH 00/38] cxlflash: OpenCXL transport support Andrew Donnellan
2018-02-23 18:05   ` Uma Krishnan
2018-02-23 19:38   ` Uma Krishnan
2018-02-26 14:43 ` Matthew R. Ochs

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=1519338416-52723-1-git-send-email-ukrishn@linux.vnet.ibm.com \
    --to=ukrishn@linux.vnet.ibm.com \
    --cc=andrew.donnellan@au1.ibm.com \
    --cc=clombard@linux.vnet.ibm.com \
    --cc=fbarrat@linux.vnet.ibm.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=manoj@linux.vnet.ibm.com \
    --cc=martin.petersen@oracle.com \
    --cc=mrochs@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).