Commit 39b6ee01 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson

vfio/ccw: Pass vfio_ccw_private not mdev_device to various functions

mdev_device should only be used in functions assigned to ops callbacks,
interior functions should use the struct vfio_ccw_private instead of
repeatedly trying to get it from the mdev.
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Reviewed-by: default avatarEric Farman <farman@linux.ibm.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/3-v4-cea4f5bd2c00+b52-ccw_mdev_jgg@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 0972c7dd
...@@ -17,13 +17,11 @@ ...@@ -17,13 +17,11 @@
#include "vfio_ccw_private.h" #include "vfio_ccw_private.h"
static int vfio_ccw_mdev_reset(struct mdev_device *mdev) static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private)
{ {
struct vfio_ccw_private *private;
struct subchannel *sch; struct subchannel *sch;
int ret; int ret;
private = dev_get_drvdata(mdev_parent_dev(mdev));
sch = private->sch; sch = private->sch;
/* /*
* TODO: * TODO:
...@@ -61,7 +59,7 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb, ...@@ -61,7 +59,7 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
if (!cp_iova_pinned(&private->cp, unmap->iova)) if (!cp_iova_pinned(&private->cp, unmap->iova))
return NOTIFY_OK; return NOTIFY_OK;
if (vfio_ccw_mdev_reset(private->mdev)) if (vfio_ccw_mdev_reset(private))
return NOTIFY_BAD; return NOTIFY_BAD;
cp_free(&private->cp); cp_free(&private->cp);
...@@ -201,7 +199,7 @@ static void vfio_ccw_mdev_close_device(struct mdev_device *mdev) ...@@ -201,7 +199,7 @@ static void vfio_ccw_mdev_close_device(struct mdev_device *mdev)
if ((private->state != VFIO_CCW_STATE_NOT_OPER) && if ((private->state != VFIO_CCW_STATE_NOT_OPER) &&
(private->state != VFIO_CCW_STATE_STANDBY)) { (private->state != VFIO_CCW_STATE_STANDBY)) {
if (!vfio_ccw_mdev_reset(mdev)) if (!vfio_ccw_mdev_reset(private))
private->state = VFIO_CCW_STATE_STANDBY; private->state = VFIO_CCW_STATE_STANDBY;
/* The state will be NOT_OPER on error. */ /* The state will be NOT_OPER on error. */
} }
...@@ -311,12 +309,9 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, ...@@ -311,12 +309,9 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,
return -EINVAL; return -EINVAL;
} }
static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info, static int vfio_ccw_mdev_get_device_info(struct vfio_ccw_private *private,
struct mdev_device *mdev) struct vfio_device_info *info)
{ {
struct vfio_ccw_private *private;
private = dev_get_drvdata(mdev_parent_dev(mdev));
info->flags = VFIO_DEVICE_FLAGS_CCW | VFIO_DEVICE_FLAGS_RESET; info->flags = VFIO_DEVICE_FLAGS_CCW | VFIO_DEVICE_FLAGS_RESET;
info->num_regions = VFIO_CCW_NUM_REGIONS + private->num_regions; info->num_regions = VFIO_CCW_NUM_REGIONS + private->num_regions;
info->num_irqs = VFIO_CCW_NUM_IRQS; info->num_irqs = VFIO_CCW_NUM_IRQS;
...@@ -324,14 +319,12 @@ static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info, ...@@ -324,14 +319,12 @@ static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info,
return 0; return 0;
} }
static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info, static int vfio_ccw_mdev_get_region_info(struct vfio_ccw_private *private,
struct mdev_device *mdev, struct vfio_region_info *info,
unsigned long arg) unsigned long arg)
{ {
struct vfio_ccw_private *private;
int i; int i;
private = dev_get_drvdata(mdev_parent_dev(mdev));
switch (info->index) { switch (info->index) {
case VFIO_CCW_CONFIG_REGION_INDEX: case VFIO_CCW_CONFIG_REGION_INDEX:
info->offset = 0; info->offset = 0;
...@@ -406,19 +399,16 @@ static int vfio_ccw_mdev_get_irq_info(struct vfio_irq_info *info) ...@@ -406,19 +399,16 @@ static int vfio_ccw_mdev_get_irq_info(struct vfio_irq_info *info)
return 0; return 0;
} }
static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev, static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private,
uint32_t flags, uint32_t flags,
uint32_t index, uint32_t index,
void __user *data) void __user *data)
{ {
struct vfio_ccw_private *private;
struct eventfd_ctx **ctx; struct eventfd_ctx **ctx;
if (!(flags & VFIO_IRQ_SET_ACTION_TRIGGER)) if (!(flags & VFIO_IRQ_SET_ACTION_TRIGGER))
return -EINVAL; return -EINVAL;
private = dev_get_drvdata(mdev_parent_dev(mdev));
switch (index) { switch (index) {
case VFIO_CCW_IO_IRQ_INDEX: case VFIO_CCW_IO_IRQ_INDEX:
ctx = &private->io_trigger; ctx = &private->io_trigger;
...@@ -524,6 +514,8 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, ...@@ -524,6 +514,8 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
unsigned int cmd, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
struct vfio_ccw_private *private =
dev_get_drvdata(mdev_parent_dev(mdev));
int ret = 0; int ret = 0;
unsigned long minsz; unsigned long minsz;
...@@ -540,7 +532,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, ...@@ -540,7 +532,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
if (info.argsz < minsz) if (info.argsz < minsz)
return -EINVAL; return -EINVAL;
ret = vfio_ccw_mdev_get_device_info(&info, mdev); ret = vfio_ccw_mdev_get_device_info(private, &info);
if (ret) if (ret)
return ret; return ret;
...@@ -558,7 +550,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, ...@@ -558,7 +550,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
if (info.argsz < minsz) if (info.argsz < minsz)
return -EINVAL; return -EINVAL;
ret = vfio_ccw_mdev_get_region_info(&info, mdev, arg); ret = vfio_ccw_mdev_get_region_info(private, &info, arg);
if (ret) if (ret)
return ret; return ret;
...@@ -603,10 +595,11 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, ...@@ -603,10 +595,11 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
return ret; return ret;
data = (void __user *)(arg + minsz); data = (void __user *)(arg + minsz);
return vfio_ccw_mdev_set_irqs(mdev, hdr.flags, hdr.index, data); return vfio_ccw_mdev_set_irqs(private, hdr.flags, hdr.index,
data);
} }
case VFIO_DEVICE_RESET: case VFIO_DEVICE_RESET:
return vfio_ccw_mdev_reset(mdev); return vfio_ccw_mdev_reset(private);
default: default:
return -ENOTTY; return -ENOTTY;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment