From: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org
Cc: bjsdjshi@linux.vnet.ibm.com, renxiaof@linux.vnet.ibm.com,
cornelia.huck@de.ibm.com, borntraeger@de.ibm.com, agraf@suse.com,
alex.williamson@redhat.com, pmorel@linux.vnet.ibm.com,
pasic@linux.vnet.ibm.com
Subject: [PATCH v4 08/16] vfio: ccw: handle ccw command request
Date: Fri, 17 Mar 2017 04:17:35 +0100 [thread overview]
Message-ID: <20170317031743.40128-9-bjsdjshi@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170317031743.40128-1-bjsdjshi@linux.vnet.ibm.com>
We implement the basic ccw command handling infrastructure
here:
1. Translate the ccw commands.
2. Issue the translated ccw commands to the device.
3. Once we get the execution result, update the guest SCSW
with it.
Acked-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
---
drivers/s390/cio/vfio_ccw_drv.c | 114 ++++++++++++++++++++++++++++++++++++
drivers/s390/cio/vfio_ccw_ops.c | 24 ++++++--
drivers/s390/cio/vfio_ccw_private.h | 14 +++++
3 files changed, 148 insertions(+), 4 deletions(-)
diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
index b1f430a..b5971d3 100644
--- a/drivers/s390/cio/vfio_ccw_drv.c
+++ b/drivers/s390/cio/vfio_ccw_drv.c
@@ -11,9 +11,13 @@
#include <linux/init.h>
#include <linux/device.h>
#include <linux/slab.h>
+#include <linux/uuid.h>
+#include <linux/mdev.h>
#include <asm/isc.h>
+#include "ioasm.h"
+#include "css.h"
#include "vfio_ccw_private.h"
/*
@@ -59,6 +63,109 @@ int vfio_ccw_sch_quiesce(struct subchannel *sch)
return ret;
}
+static int doing_io(struct vfio_ccw_private *private, u32 intparm)
+{
+ return (private->intparm == intparm);
+}
+
+static int vfio_ccw_sch_io_helper(struct vfio_ccw_private *private)
+{
+ struct subchannel *sch;
+ union orb *orb;
+ int ccode;
+ __u8 lpm;
+ u32 intparm;
+
+ sch = private->sch;
+
+ orb = cp_get_orb(&private->cp, (u32)(addr_t)sch, sch->lpm);
+
+ /* Issue "Start Subchannel" */
+ ccode = ssch(sch->schid, orb);
+
+ switch (ccode) {
+ case 0:
+ /*
+ * Initialize device status information
+ */
+ sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
+ break;
+ case 1: /* Status pending */
+ case 2: /* Busy */
+ return -EBUSY;
+ case 3: /* Device/path not operational */
+ {
+ lpm = orb->cmd.lpm;
+ if (lpm != 0)
+ sch->lpm &= ~lpm;
+ else
+ sch->lpm = 0;
+
+ if (cio_update_schib(sch))
+ return -ENODEV;
+
+ return sch->lpm ? -EACCES : -ENODEV;
+ }
+ default:
+ return ccode;
+ }
+
+ intparm = (u32)(addr_t)sch;
+ private->intparm = 0;
+ wait_event(private->wait_q, doing_io(private, intparm));
+
+ if (scsw_is_solicited(&private->irb.scsw))
+ cp_update_scsw(&private->cp, &private->irb.scsw);
+
+ return 0;
+}
+
+/* Deal with the ccw command request from the userspace. */
+int vfio_ccw_sch_cmd_request(struct vfio_ccw_private *private)
+{
+ struct mdev_device *mdev = private->mdev;
+ union orb *orb;
+ union scsw *scsw = &private->scsw;
+ struct irb *irb = &private->irb;
+ struct ccw_io_region *io_region = &private->io_region;
+ int ret;
+
+ memcpy(scsw, io_region->scsw_area, sizeof(*scsw));
+
+ if (scsw->cmd.fctl & SCSW_FCTL_START_FUNC) {
+ orb = (union orb *)io_region->orb_area;
+
+ ret = cp_init(&private->cp, mdev_dev(mdev), orb);
+ if (ret)
+ return ret;
+
+ ret = cp_prefetch(&private->cp);
+ if (ret) {
+ cp_free(&private->cp);
+ return ret;
+ }
+
+ /* Start channel program and wait for I/O interrupt. */
+ ret = vfio_ccw_sch_io_helper(private);
+ if (!ret) {
+ /* Get irb info and copy it to irb_area. */
+ memcpy(io_region->irb_area, irb, sizeof(*irb));
+ }
+
+ cp_free(&private->cp);
+ } else if (scsw->cmd.fctl & SCSW_FCTL_HALT_FUNC) {
+ /* XXX: Handle halt. */
+ ret = -EOPNOTSUPP;
+ } else if (scsw->cmd.fctl & SCSW_FCTL_CLEAR_FUNC) {
+ /* XXX: Handle clear. */
+ ret = -EOPNOTSUPP;
+ } else {
+ ret = -EOPNOTSUPP;
+ }
+
+ return ret;
+}
+
/*
* Sysfs interfaces
*/
@@ -113,12 +220,18 @@ static struct attribute_group vfio_subchannel_attr_group = {
static void vfio_ccw_sch_irq(struct subchannel *sch)
{
struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev);
+ struct irb *irb;
inc_irq_stat(IRQIO_CIO);
if (!private)
return;
+ irb = this_cpu_ptr(&cio_irb);
+ memcpy(&private->irb, irb, sizeof(*irb));
+ private->intparm = (u32)(addr_t)sch;
+ wake_up(&private->wait_q);
+
if (private->completion)
complete(private->completion);
}
@@ -156,6 +269,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
if (ret)
goto out_rm_group;
+ init_waitqueue_head(&private->wait_q);
atomic_set(&private->avail, 1);
return 0;
diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index 6c06805..878c882 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -23,12 +23,25 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
return NOTIFY_STOP;
/*
- * TODO:
* Vendor drivers MUST unpin pages in response to an
* invalidation.
*/
- if (action == VFIO_IOMMU_NOTIFY_DMA_UNMAP)
- return NOTIFY_BAD;
+ if (action == VFIO_IOMMU_NOTIFY_DMA_UNMAP) {
+ struct vfio_iommu_type1_dma_unmap *unmap = data;
+ struct subchannel *sch = private->sch;
+
+ if (!cp_iova_pinned(&private->cp, unmap->iova))
+ return NOTIFY_OK;
+
+ if (vfio_ccw_sch_quiesce(sch))
+ return NOTIFY_BAD;
+
+ if (cio_enable_subchannel(sch, (u32)(unsigned long)sch))
+ return NOTIFY_BAD;
+
+ cp_free(&private->cp);
+ return NOTIFY_OK;
+ }
return NOTIFY_DONE;
}
@@ -167,7 +180,10 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,
region = &private->io_region;
if (copy_from_user((void *)region + *ppos, buf, count))
return -EFAULT;
- region->ret_code = 0;
+
+ region->ret_code = vfio_ccw_sch_cmd_request(private);
+ if (region->ret_code != 0)
+ return region->ret_code;
return count;
}
diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h
index 359e96b..79e5337 100644
--- a/drivers/s390/cio/vfio_ccw_private.h
+++ b/drivers/s390/cio/vfio_ccw_private.h
@@ -10,9 +10,11 @@
#ifndef _VFIO_CCW_PRIVATE_H_
#define _VFIO_CCW_PRIVATE_H_
+#include <linux/completion.h>
#include <linux/vfio_ccw.h>
#include "css.h"
+#include "vfio_ccw_cp.h"
/**
* struct vfio_ccw_private
@@ -22,6 +24,11 @@
* @mdev: pointer to the mediated device
* @nb: notifier for vfio events
* @io_region: MMIO region to input/output I/O arguments/results
+ * @wait_q: wait for interrupt
+ * @intparm: record current interrupt parameter, used for wait interrupt
+ * @cp: channel program for the current I/O operation
+ * @irb: irb info received from interrupt
+ * @scsw: scsw info
*/
struct vfio_ccw_private {
struct subchannel *sch;
@@ -30,11 +37,18 @@ struct vfio_ccw_private {
struct mdev_device *mdev;
struct notifier_block nb;
struct ccw_io_region io_region;
+
+ wait_queue_head_t wait_q;
+ u32 intparm;
+ struct channel_program cp;
+ struct irb irb;
+ union scsw scsw;
} __aligned(8);
extern int vfio_ccw_mdev_reg(struct subchannel *sch);
extern void vfio_ccw_mdev_unreg(struct subchannel *sch);
extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
+extern int vfio_ccw_sch_cmd_request(struct vfio_ccw_private *private);
#endif
--
2.8.4
next prev parent reply other threads:[~2017-03-17 5:27 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-17 3:17 [PATCH v4 00/16] basic vfio-ccw infrastructure Dong Jia Shi
2017-03-17 3:17 ` [PATCH v4 01/16] s390: cio: introduce cio_cancel_halt_clear Dong Jia Shi
2017-03-17 9:26 ` Sebastian Ott
[not found] ` <20170317093953.GP6839@bjsdjshi@linux.vnet.ibm.com>
2017-03-17 9:51 ` Sebastian Ott
2017-03-23 11:51 ` Sebastian Ott
2017-03-17 3:17 ` [PATCH v4 02/16] s390: cio: export more interfaces Dong Jia Shi
2017-03-17 9:29 ` Sebastian Ott
2017-03-23 12:02 ` Sebastian Ott
2017-03-17 3:17 ` [PATCH v4 03/16] vfio: ccw: define device_api strings Dong Jia Shi
2017-03-21 18:47 ` Alex Williamson
2017-03-17 3:17 ` [PATCH v4 04/16] vfio: ccw: basic implementation for vfio_ccw driver Dong Jia Shi
2017-03-17 3:17 ` [PATCH v4 05/16] vfio: ccw: introduce channel program interfaces Dong Jia Shi
2017-03-17 3:17 ` [PATCH v4 06/16] vfio: ccw: register vfio_ccw to the mediated device framework Dong Jia Shi
2017-03-17 3:17 ` [PATCH v4 07/16] vfio: ccw: introduce ccw_io_region Dong Jia Shi
2017-03-17 3:17 ` Dong Jia Shi [this message]
2017-03-17 3:17 ` [PATCH v4 09/16] vfio: ccw: realize VFIO_DEVICE_GET_REGION_INFO ioctl Dong Jia Shi
2017-03-21 18:47 ` Alex Williamson
2017-03-17 3:17 ` [PATCH v4 10/16] vfio: ccw: realize VFIO_DEVICE_RESET ioctl Dong Jia Shi
2017-03-17 3:17 ` [PATCH v4 11/16] vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls Dong Jia Shi
2017-03-21 18:47 ` Alex Williamson
2017-03-17 3:17 ` [PATCH v4 12/16] vfio: ccw: return I/O results asynchronously Dong Jia Shi
2017-03-17 3:17 ` [PATCH v4 13/16] vfio: ccw: introduce a finite state machine Dong Jia Shi
2017-03-17 3:17 ` [PATCH v4 14/16] docs: add documentation for vfio-ccw Dong Jia Shi
2017-03-21 18:47 ` Alex Williamson
[not found] ` <20170322023422.GP10704@bjsdjshi@linux.vnet.ibm.com>
2017-03-28 8:16 ` Cornelia Huck
2017-03-17 3:17 ` [PATCH v4 15/16] vfio: ccw: introduce support for ccw0 Dong Jia Shi
2017-03-17 3:17 ` [PATCH v4 16/16] MAINTAINERS: Add vfio-ccw maintainers Dong Jia Shi
2017-03-28 8:20 ` [PATCH v4 00/16] basic vfio-ccw infrastructure Cornelia Huck
2017-03-28 8:39 ` Christian Borntraeger
2017-03-28 13:31 ` Cornelia Huck
2017-03-28 15:23 ` Alex Williamson
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=20170317031743.40128-9-bjsdjshi@linux.vnet.ibm.com \
--to=bjsdjshi@linux.vnet.ibm.com \
--cc=agraf@suse.com \
--cc=alex.williamson@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=pasic@linux.vnet.ibm.com \
--cc=pmorel@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=renxiaof@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