Re: [PATCH 5/6] dma: mic_x100_dma: no need to check return value of debugfs_create functions

2019-06-12 Thread Sudeep Dutt
On Wed, 2019-06-12 at 14:25 +0200, Greg Kroah-Hartman wrote:
> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.
> 

Thanks Greg.

Reviewed-by: Sudeep Dutt 

> Cc: Sudeep Dutt 
> Cc: Ashutosh Dixit 
> Cc: Dan Williams 
> Cc: Vinod Koul 
> Cc: dmaeng...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman 
> ---
>  drivers/dma/mic_x100_dma.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dma/mic_x100_dma.c b/drivers/dma/mic_x100_dma.c
> index 6a91e28d537d..584e09661507 100644
> --- a/drivers/dma/mic_x100_dma.c
> +++ b/drivers/dma/mic_x100_dma.c
> @@ -728,10 +728,8 @@ static int mic_dma_driver_probe(struct mbus_device 
> *mbdev)
>   if (mic_dma_dbg) {
>   mic_dma_dev->dbg_dir = debugfs_create_dir(dev_name(>dev),
> mic_dma_dbg);
> - if (mic_dma_dev->dbg_dir)
> - debugfs_create_file("mic_dma_reg", 0444,
> - mic_dma_dev->dbg_dir, mic_dma_dev,
> - _dma_reg_fops);
> + debugfs_create_file("mic_dma_reg", 0444, mic_dma_dev->dbg_dir,
> + mic_dma_dev, _dma_reg_fops);
>   }
>   return 0;
>  }




Re: [PATCH] mic: no need to check return value of debugfs_create functions

2019-06-12 Thread Sudeep Dutt
On Tue, 2019-06-11 at 20:43 +0200, Greg Kroah-Hartman wrote:
> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.
> 

Thanks Greg.

Reviewed-by: Sudeep Dutt 

> Cc: Sudeep Dutt 
> Cc: Ashutosh Dixit 
> Cc: Arnd Bergmann 
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman 
> ---
>  drivers/misc/mic/card/mic_debugfs.c  | 18 ++
>  drivers/misc/mic/cosm/cosm_debugfs.c |  4 
>  drivers/misc/mic/host/mic_debugfs.c  |  4 
>  drivers/misc/mic/scif/scif_debugfs.c |  5 -
>  drivers/misc/mic/vop/vop_debugfs.c   |  4 
>  5 files changed, 2 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/misc/mic/card/mic_debugfs.c 
> b/drivers/misc/mic/card/mic_debugfs.c
> index 7a4140874888..fa2b5fefb791 100644
> --- a/drivers/misc/mic/card/mic_debugfs.c
> +++ b/drivers/misc/mic/card/mic_debugfs.c
> @@ -63,25 +63,13 @@ DEFINE_SHOW_ATTRIBUTE(mic_intr);
>   */
>  void __init mic_create_card_debug_dir(struct mic_driver *mdrv)
>  {
> - struct dentry *d;
> -
>   if (!mic_dbg)
>   return;
>  
>   mdrv->dbg_dir = debugfs_create_dir(mdrv->name, mic_dbg);
> - if (!mdrv->dbg_dir) {
> - dev_err(mdrv->dev, "Cant create dbg_dir %s\n", mdrv->name);
> - return;
> - }
> -
> - d = debugfs_create_file("intr_test", 0444, mdrv->dbg_dir,
> - mdrv, _intr_fops);
>  
> - if (!d) {
> - dev_err(mdrv->dev,
> - "Cant create dbg intr_test %s\n", mdrv->name);
> - return;
> - }
> + debugfs_create_file("intr_test", 0444, mdrv->dbg_dir, mdrv,
> + _intr_fops);
>  }
>  
>  /**
> @@ -101,8 +89,6 @@ void mic_delete_card_debug_dir(struct mic_driver *mdrv)
>  void __init mic_init_card_debugfs(void)
>  {
>   mic_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
> - if (!mic_dbg)
> - pr_err("can't create debugfs dir\n");
>  }
>  
>  /**
> diff --git a/drivers/misc/mic/cosm/cosm_debugfs.c 
> b/drivers/misc/mic/cosm/cosm_debugfs.c
> index 71c216d0504d..340ea7171411 100644
> --- a/drivers/misc/mic/cosm/cosm_debugfs.c
> +++ b/drivers/misc/mic/cosm/cosm_debugfs.c
> @@ -105,8 +105,6 @@ void cosm_create_debug_dir(struct cosm_device *cdev)
>  
>   scnprintf(name, sizeof(name), "mic%d", cdev->index);
>   cdev->dbg_dir = debugfs_create_dir(name, cosm_dbg);
> - if (!cdev->dbg_dir)
> - return;
>  
>   debugfs_create_file("log_buf", 0444, cdev->dbg_dir, cdev,
>   _buf_fops);
> @@ -125,8 +123,6 @@ void cosm_delete_debug_dir(struct cosm_device *cdev)
>  void cosm_init_debugfs(void)
>  {
>   cosm_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
> - if (!cosm_dbg)
> - pr_err("can't create debugfs dir\n");
>  }
>  
>  void cosm_exit_debugfs(void)
> diff --git a/drivers/misc/mic/host/mic_debugfs.c 
> b/drivers/misc/mic/host/mic_debugfs.c
> index c6e3c764699f..370f98c7b752 100644
> --- a/drivers/misc/mic/host/mic_debugfs.c
> +++ b/drivers/misc/mic/host/mic_debugfs.c
> @@ -125,8 +125,6 @@ void mic_create_debug_dir(struct mic_device *mdev)
>  
>   scnprintf(name, sizeof(name), "mic%d", mdev->id);
>   mdev->dbg_dir = debugfs_create_dir(name, mic_dbg);
> - if (!mdev->dbg_dir)
> - return;
>  
>   debugfs_create_file("smpt", 0444, mdev->dbg_dir, mdev,
>   _smpt_fops);
> @@ -155,8 +153,6 @@ void mic_delete_debug_dir(struct mic_device *mdev)
>  void __init mic_init_debugfs(void)
>  {
>   mic_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
> - if (!mic_dbg)
> - pr_err("can't create debugfs dir\n");
>  }
>  
>  /**
> diff --git a/drivers/misc/mic/scif/scif_debugfs.c 
> b/drivers/misc/mic/scif/scif_debugfs.c
> index a6820480105a..8fe38e7ca6e6 100644
> --- a/drivers/misc/mic/scif/scif_debugfs.c
> +++ b/drivers/misc/mic/scif/scif_debugfs.c
> @@ -103,11 +103,6 @@ DEFINE_SHOW_ATTRIBUTE(scif_rma);
>  void __init scif_init_debugfs(void)
>  {
>   scif_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
> - if (!scif_dbg) {
> - dev_err(scif_info.mdev.this_device,
> - "can't create debugfs dir scif\n");
> - return;
> - }
>  
>   debugfs_create_file("scif_dev", 0444, scif_dbg, NULL, _dev_fops);
>   debugfs_create_

Re: scif_insert_vma()

2019-03-17 Thread Sudeep Dutt
On Mon, 2019-03-11 at 08:45 +0200, Jarkko Sakkinen wrote:
> Hi
> 
> Just wondering what will happen if kzalloc() fails in scif_mmap.c. How
> it is recovered? I don't see anything in the VMA callbacks taking care
> of this.

Hi Jarkko,

scif_insert_vma(..) is called from scif_mmap(..) and scif_vma_open(..).
scif_mmap(..) checks for allocation failures but scif_vma_open(..) does
not on purpose.

The vm_operations_struct open(..)/close(..) callbacks do not allow
returning errors. The driver will take a reference to the VMA private
data structure irrespective of whether the allocation during the
open(..) callback succeeds or fails. The close(..) callback cleans up
the data structures from the mmap(..) or open(..) callbacks if any.

Thanks,
Sudeep Dutt



Re: [PATCH] mic: vop: Fix broken virtqueues

2019-01-30 Thread Sudeep Dutt
On Tue, 2019-01-29 at 11:22 +0100, Vincent Whitchurch wrote:
> VOP is broken in mainline since commit 1ce9e6055fa0a9043 ("virtio_ring:
> introduce packed ring support"); attempting to use the virtqueues leads
> to various kernel crashes.  I'm testing it with my not-yet-merged
> loopback patches, but even the in-tree MIC hardware cannot work.
> 
> The problem is not in the referenced commit per se, but is due to the
> following hack in vop_find_vq() which depends on the layout of private
> structures in other source files, which that commit happened to change:
> 
>   /*
>* To reassign the used ring here we are directly accessing
>* struct vring_virtqueue which is a private data structure
>* in virtio_ring.c. At the minimum, a BUILD_BUG_ON() in
>* vring_new_virtqueue() would ensure that
>*  (>vring == (struct vring *) (>vq + 1));
>*/
>   vr = (struct vring *)(vq + 1);
>   vr->used = used;
> 
> Fix vop by using __vring_new_virtqueue() to create the needed vring
> layout from the start, instead of attempting to patch in the used ring
> later.  __vring_new_virtqueue() was added way back in commit
> 2a2d1382fe9dcc ("virtio: Add improved queue allocation API") in order to
> address mic's usecase, according to the commit message.
> 

Thank you for fixing this up Vincent.

Reviewed-by: Sudeep Dutt 

> Signed-off-by: Vincent Whitchurch 
> ---
>  drivers/misc/mic/vop/vop_main.c | 60 +++--
>  1 file changed, 34 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
> index d2b9782eee87..fef45bf6d519 100644
> --- a/drivers/misc/mic/vop/vop_main.c
> +++ b/drivers/misc/mic/vop/vop_main.c
> @@ -284,6 +284,26 @@ static void vop_del_vqs(struct virtio_device *dev)
>   vop_del_vq(vq, idx++);
>  }
>  
> +static struct virtqueue *vop_new_virtqueue(unsigned int index,
> +   unsigned int num,
> +   struct virtio_device *vdev,
> +   bool context,
> +   void *pages,
> +   bool (*notify)(struct virtqueue *vq),
> +   void (*callback)(struct virtqueue *vq),
> +   const char *name,
> +   void *used)
> +{
> + bool weak_barriers = false;
> + struct vring vring;
> +
> + vring_init(, num, pages, MIC_VIRTIO_RING_ALIGN);
> + vring.used = used;
> +
> + return __vring_new_virtqueue(index, vring, vdev, weak_barriers, context,
> +  notify, callback, name);
> +}
> +
>  /*
>   * This routine will assign vring's allocated in host/io memory. Code in
>   * virtio_ring.c however continues to access this io memory as if it were 
> local
> @@ -303,7 +323,6 @@ static struct virtqueue *vop_find_vq(struct virtio_device 
> *dev,
>   struct _mic_vring_info __iomem *info;
>   void *used;
>   int vr_size, _vr_size, err, magic;
> - struct vring *vr;
>   u8 type = ioread8(>desc->type);
>  
>   if (index >= ioread8(>desc->num_vq))
> @@ -322,17 +341,7 @@ static struct virtqueue *vop_find_vq(struct 
> virtio_device *dev,
>   return ERR_PTR(-ENOMEM);
>   vdev->vr[index] = va;
>   memset_io(va, 0x0, _vr_size);
> - vq = vring_new_virtqueue(
> - index,
> - le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN,
> - dev,
> - false,
> - ctx,
> - (void __force *)va, vop_notify, callback, name);
> - if (!vq) {
> - err = -ENOMEM;
> - goto unmap;
> - }
> +
>   info = va + _vr_size;
>   magic = ioread32(>magic);
>  
> @@ -341,7 +350,6 @@ static struct virtqueue *vop_find_vq(struct virtio_device 
> *dev,
>   goto unmap;
>   }
>  
> - /* Allocate and reassign used ring now */
>   vdev->used_size[index] = PAGE_ALIGN(sizeof(__u16) * 3 +
>sizeof(struct vring_used_elem) *
>le16_to_cpu(config.num));
> @@ -351,8 +359,17 @@ static struct virtqueue *vop_find_vq(struct 
> virtio_device *dev,
>   err = -ENOMEM;
>   dev_err(_vop_dev(vdev), "%s %d err %d\n",
>   __func__, __LINE__, err);
> - goto del_vq;
> + goto unmap;
> + }
> +
> + vq = 

Re: [PATCH v2] misc: mic: fix a DMA pool free failure

2019-01-02 Thread Sudeep Dutt
On Tue, 2018-12-04 at 09:16 -0600, Wenwen Wang wrote:
> In _scif_prog_signal(), a DMA pool is allocated if the MIC Coprocessor is
> not X100, i.e., the boolean variable 'x100' is false. This DMA pool will be
> freed eventually through the callback function scif_prog_signal_cb() with
> the parameter of 'status', which actually points to the start of DMA pool.
> Specifically, in scif_prog_signal_cb(), the 'ep' field and the
> 'src_dma_addr' field of 'status' are used to free the DMA pool by invoking
> dma_pool_free(). Given that 'status' points to the start address of the DMA
> pool, both 'status->ep' and 'status->src_dma_addr' are in the DMA pool. And
> so, the device has the permission to access them. Even worse, a malicious
> device can modify them. As a result, dma_pool_free() will not succeed.
> 
> To avoid the above issue, this patch introduces a new data structure, i.e.,
> scif_cb_arg, to store the arguments required by the call back function. A
> variable 'cb_arg' is allocated in _scif_prog_signal() to pass the
> arguments. 'cb_arg' will be freed after dma_pool_free() in
> scif_prog_signal_cb().
> 

Thanks for incorporating the previous feedback Wenwen.

Reviewed-by: Sudeep Dutt 

> Signed-off-by: Wenwen Wang 
> ---
>  drivers/misc/mic/scif/scif_fence.c | 22 +-
>  drivers/misc/mic/scif/scif_rma.h   | 13 +
>  2 files changed, 30 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_fence.c 
> b/drivers/misc/mic/scif/scif_fence.c
> index 7bb929f..2e7ce6a 100644
> --- a/drivers/misc/mic/scif/scif_fence.c
> +++ b/drivers/misc/mic/scif/scif_fence.c
> @@ -195,10 +195,11 @@ static inline void *scif_get_local_va(off_t off, struct 
> scif_window *window)
>  
>  static void scif_prog_signal_cb(void *arg)
>  {
> - struct scif_status *status = arg;
> + struct scif_cb_arg *cb_arg = arg;
>  
> - dma_pool_free(status->ep->remote_dev->signal_pool, status,
> -   status->src_dma_addr);
> + dma_pool_free(cb_arg->ep->remote_dev->signal_pool, cb_arg->status,
> +   cb_arg->src_dma_addr);
> + kfree(cb_arg);
>  }
>  
>  static int _scif_prog_signal(scif_epd_t epd, dma_addr_t dst, u64 val)
> @@ -209,6 +210,7 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t 
> dst, u64 val)
>   bool x100 = !is_dma_copy_aligned(chan->device, 1, 1, 1);
>   struct dma_async_tx_descriptor *tx;
>   struct scif_status *status = NULL;
> + struct scif_cb_arg *cb_arg = NULL;
>   dma_addr_t src;
>   dma_cookie_t cookie;
>   int err;
> @@ -257,8 +259,16 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t 
> dst, u64 val)
>   goto dma_fail;
>   }
>   if (!x100) {
> + cb_arg = kmalloc(sizeof(*cb_arg), GFP_KERNEL);
> + if (!cb_arg) {
> + err = -ENOMEM;
> + goto dma_fail;
> + }
> + cb_arg->src_dma_addr = src;
> + cb_arg->status = status;
> + cb_arg->ep = ep;
>   tx->callback = scif_prog_signal_cb;
> - tx->callback_param = status;
> + tx->callback_param = cb_arg;
>   }
>   cookie = tx->tx_submit(tx);
>   if (dma_submit_error(cookie)) {
> @@ -270,9 +280,11 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t 
> dst, u64 val)
>   dma_async_issue_pending(chan);
>   return 0;
>  dma_fail:
> - if (!x100)
> + if (!x100) {
>   dma_pool_free(ep->remote_dev->signal_pool, status,
> src - offsetof(struct scif_status, val));
> + kfree(cb_arg);
> + }
>  alloc_fail:
>   return err;
>  }
> diff --git a/drivers/misc/mic/scif/scif_rma.h 
> b/drivers/misc/mic/scif/scif_rma.h
> index fa67222..84af303 100644
> --- a/drivers/misc/mic/scif/scif_rma.h
> +++ b/drivers/misc/mic/scif/scif_rma.h
> @@ -206,6 +206,19 @@ struct scif_status {
>  };
>  
>  /*
> + * struct scif_cb_arg - Stores the argument of the callback func
> + *
> + * @src_dma_addr: Source buffer DMA address
> + * @status: DMA status
> + * @ep: SCIF endpoint
> + */
> +struct scif_cb_arg {
> + dma_addr_t src_dma_addr;
> + struct scif_status *status;
> + struct scif_endpt *ep;
> +};
> +
> +/*
>   * struct scif_window - Registration Window for Self and Remote
>   *
>   * @nr_pages: Number of pages which is defined as a s64 instead of an int




Re: [PATCH] misc: mic: fix a DMA pool free failure

2018-11-04 Thread Sudeep Dutt
On Thu, 2018-10-18 at 14:46 -0500, Wenwen Wang wrote:
> In _scif_prog_signal(), a DMA pool is allocated if the MIC Coprocessor is
> not X100, i.e., the boolean variable 'x100' is false. This DMA pool will be
> freed eventually through the callback function scif_prog_signal_cb() with
> the parameter of 'status', which actually points to the start of DMA pool.
> Specifically, in scif_prog_signal_cb(), the 'ep' field and the
> 'src_dma_addr' field of 'status' are used to free the DMA pool by invoking
> dma_pool_free(). Given that 'status' points to the start address of the DMA
> pool, both 'status->ep' and 'status->src_dma_addr' are in the DMA pool. And
> so, the device has the permission to access them. Even worse, a malicious
> device can modify them. As a result, dma_pool_free() will not succeed.
> 
> To avoid the above issue, this patch introduces a new data structure, i.e.,
> scif_cb_arg, to store the arguments required by the call back function. A
> variable 'cb_arg' is allocated in _scif_prog_signal() to pass the
> arguments. 'cb_arg' will be freed after dma_pool_free() in
> scif_prog_signal_cb().
> 
> Signed-off-by: Wenwen Wang 
> ---
>  drivers/misc/mic/scif/scif_fence.c | 17 +
>  drivers/misc/mic/scif/scif_rma.h   | 14 ++
>  2 files changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_fence.c 
> b/drivers/misc/mic/scif/scif_fence.c
> index cac3bcc..30f7d9b 100644
> --- a/drivers/misc/mic/scif/scif_fence.c
> +++ b/drivers/misc/mic/scif/scif_fence.c
> @@ -195,10 +195,11 @@ static inline void *scif_get_local_va(off_t off, struct 
> scif_window *window)
>  
>  static void scif_prog_signal_cb(void *arg)
>  {
> - struct scif_status *status = arg;
> + struct scif_cb_arg *cb_arg = arg;
>  
> - dma_pool_free(status->ep->remote_dev->signal_pool, status,
> -   status->src_dma_addr);
> + dma_pool_free(cb_arg->ep->remote_dev->signal_pool, cb_arg->status,
> +   cb_arg->src_dma_addr);
> + kfree(cb_arg);
>  }
>  
>  static int _scif_prog_signal(scif_epd_t epd, dma_addr_t dst, u64 val)
> @@ -209,6 +210,7 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t 
> dst, u64 val)
>   bool x100 = !is_dma_copy_aligned(chan->device, 1, 1, 1);
>   struct dma_async_tx_descriptor *tx;
>   struct scif_status *status = NULL;
> + struct scif_cb_arg *cb_arg = NULL;
>   dma_addr_t src;
>   dma_cookie_t cookie;
>   int err;
> @@ -257,8 +259,15 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t 
> dst, u64 val)
>   goto dma_fail;
>   }
>   if (!x100) {
> + err = -ENOMEM;

Should err be set to -ENOMEM only if the cb_arg allocation fails?

> + cb_arg = kmalloc(sizeof(*cb_arg), GFP_KERNEL);
> + if (!cb_arg)
> + goto dma_fail;
> + cb_arg->src_dma_addr = src;
> + cb_arg->status = status;
> + cb_arg->ep = ep;
>   tx->callback = scif_prog_signal_cb;
> -         tx->callback_param = status;
> + tx->callback_param = cb_arg;
>   }

cb_arg should be freed if there is a dma_submit_error(..) below in the
dma_fail path.

Wenwen, can you please fix these up and resend the patch?

Thanks,
Sudeep Dutt



Re: [PATCH] misc: mic: fix a DMA pool free failure

2018-11-04 Thread Sudeep Dutt
On Thu, 2018-10-18 at 14:46 -0500, Wenwen Wang wrote:
> In _scif_prog_signal(), a DMA pool is allocated if the MIC Coprocessor is
> not X100, i.e., the boolean variable 'x100' is false. This DMA pool will be
> freed eventually through the callback function scif_prog_signal_cb() with
> the parameter of 'status', which actually points to the start of DMA pool.
> Specifically, in scif_prog_signal_cb(), the 'ep' field and the
> 'src_dma_addr' field of 'status' are used to free the DMA pool by invoking
> dma_pool_free(). Given that 'status' points to the start address of the DMA
> pool, both 'status->ep' and 'status->src_dma_addr' are in the DMA pool. And
> so, the device has the permission to access them. Even worse, a malicious
> device can modify them. As a result, dma_pool_free() will not succeed.
> 
> To avoid the above issue, this patch introduces a new data structure, i.e.,
> scif_cb_arg, to store the arguments required by the call back function. A
> variable 'cb_arg' is allocated in _scif_prog_signal() to pass the
> arguments. 'cb_arg' will be freed after dma_pool_free() in
> scif_prog_signal_cb().
> 
> Signed-off-by: Wenwen Wang 
> ---
>  drivers/misc/mic/scif/scif_fence.c | 17 +
>  drivers/misc/mic/scif/scif_rma.h   | 14 ++
>  2 files changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_fence.c 
> b/drivers/misc/mic/scif/scif_fence.c
> index cac3bcc..30f7d9b 100644
> --- a/drivers/misc/mic/scif/scif_fence.c
> +++ b/drivers/misc/mic/scif/scif_fence.c
> @@ -195,10 +195,11 @@ static inline void *scif_get_local_va(off_t off, struct 
> scif_window *window)
>  
>  static void scif_prog_signal_cb(void *arg)
>  {
> - struct scif_status *status = arg;
> + struct scif_cb_arg *cb_arg = arg;
>  
> - dma_pool_free(status->ep->remote_dev->signal_pool, status,
> -   status->src_dma_addr);
> + dma_pool_free(cb_arg->ep->remote_dev->signal_pool, cb_arg->status,
> +   cb_arg->src_dma_addr);
> + kfree(cb_arg);
>  }
>  
>  static int _scif_prog_signal(scif_epd_t epd, dma_addr_t dst, u64 val)
> @@ -209,6 +210,7 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t 
> dst, u64 val)
>   bool x100 = !is_dma_copy_aligned(chan->device, 1, 1, 1);
>   struct dma_async_tx_descriptor *tx;
>   struct scif_status *status = NULL;
> + struct scif_cb_arg *cb_arg = NULL;
>   dma_addr_t src;
>   dma_cookie_t cookie;
>   int err;
> @@ -257,8 +259,15 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t 
> dst, u64 val)
>   goto dma_fail;
>   }
>   if (!x100) {
> + err = -ENOMEM;

Should err be set to -ENOMEM only if the cb_arg allocation fails?

> + cb_arg = kmalloc(sizeof(*cb_arg), GFP_KERNEL);
> + if (!cb_arg)
> + goto dma_fail;
> + cb_arg->src_dma_addr = src;
> + cb_arg->status = status;
> + cb_arg->ep = ep;
>   tx->callback = scif_prog_signal_cb;
> -         tx->callback_param = status;
> + tx->callback_param = cb_arg;
>   }

cb_arg should be freed if there is a dma_submit_error(..) below in the
dma_fail path.

Wenwen, can you please fix these up and resend the patch?

Thanks,
Sudeep Dutt



Re: rdma-core doesn't install driver.h, broke libibscif

2018-10-18 Thread Sudeep Dutt
On Wed, 2018-10-17 at 01:54 -0700, Christoph Hellwig wrote:
> On Mon, Oct 15, 2018 at 05:53:44PM +, Woodruff, Robert J wrote:
> > James Harvey wrote,
> > 
> > >Short: Is libibscif dead, and should OS repositories remove it?
> > 
> > Libibscif is for an old product,  Intel's KNC, that is no longer sold and 
> > the S/W is frozen. The open source libibscif is no longer maintained. 
> > It has already been removed from the latest community OFED distribution. 
> > The individual package on the OFA downloads is for archive purposed only.
> 
> Does this mean we can kill the kernel scif code as well? 

The MIC COSM drivers are using the kernel SCIF code. These drivers have
been upstream since 2015 and we are not sure who is using them. Our
preference will be to keep these drivers in the kernel for now.

Thanks,
Sudeep Dutt



Re: rdma-core doesn't install driver.h, broke libibscif

2018-10-18 Thread Sudeep Dutt
On Wed, 2018-10-17 at 01:54 -0700, Christoph Hellwig wrote:
> On Mon, Oct 15, 2018 at 05:53:44PM +, Woodruff, Robert J wrote:
> > James Harvey wrote,
> > 
> > >Short: Is libibscif dead, and should OS repositories remove it?
> > 
> > Libibscif is for an old product,  Intel's KNC, that is no longer sold and 
> > the S/W is frozen. The open source libibscif is no longer maintained. 
> > It has already been removed from the latest community OFED distribution. 
> > The individual package on the OFA downloads is for archive purposed only.
> 
> Does this mean we can kill the kernel scif code as well? 

The MIC COSM drivers are using the kernel SCIF code. These drivers have
been upstream since 2015 and we are not sure who is using them. Our
preference will be to keep these drivers in the kernel for now.

Thanks,
Sudeep Dutt



Re: [PATCH] misc: mic: SCIF Fix scif_get_new_port() error handling

2018-08-08 Thread Sudeep Dutt
On Thu, 2018-08-02 at 01:42 -0700, Dan Carpenter wrote:
> There are only 2 callers of scif_get_new_port() and both appear to get
> the error handling wrong.  Both treat zero returns as error, but it
> actually returns negative error codes and >= 0 on success.
> 
> Fixes: e9089f43c9a7 ("misc: mic: SCIF open close bind and listen APIs")
> Signed-off-by: Dan Carpenter 
> ---
> I have not tested this patch.  Please review carefully.

Thanks for the patch Dan.

Reviewed-by: Sudeep Dutt 

> 
> diff --git a/drivers/misc/mic/scif/scif_api.c 
> b/drivers/misc/mic/scif/scif_api.c
> index 463f06d0b4ef..8dd0ccedeb94 100644
> --- a/drivers/misc/mic/scif/scif_api.c
> +++ b/drivers/misc/mic/scif/scif_api.c
> @@ -371,11 +371,10 @@ int scif_bind(scif_epd_t epd, u16 pn)
>   goto scif_bind_exit;
>   }
>   } else {
> - pn = scif_get_new_port();
> - if (!pn) {
> - ret = -ENOSPC;
> + ret = scif_get_new_port();
> + if (ret < 0)
>   goto scif_bind_exit;
> - }
> + pn = ret;
>   }
>  
>   ep->state = SCIFEP_BOUND;
> @@ -649,13 +648,12 @@ int __scif_connect(scif_epd_t epd, struct scif_port_id 
> *dst, bool non_block)
>   err = -EISCONN;
>   break;
>   case SCIFEP_UNBOUND:
> - ep->port.port = scif_get_new_port();
> - if (!ep->port.port) {
> - err = -ENOSPC;
> - } else {
> - ep->port.node = scif_info.nodeid;
> - ep->conn_async_state = ASYNC_CONN_IDLE;
> - }
> + err = scif_get_new_port();
> + if (err < 0)
> + break;
> + ep->port.port = err;
> + ep->port.node = scif_info.nodeid;
> + ep->conn_async_state = ASYNC_CONN_IDLE;
>   /* Fall through */
>   case SCIFEP_BOUND:
>   /*




Re: [PATCH] misc: mic: SCIF Fix scif_get_new_port() error handling

2018-08-08 Thread Sudeep Dutt
On Thu, 2018-08-02 at 01:42 -0700, Dan Carpenter wrote:
> There are only 2 callers of scif_get_new_port() and both appear to get
> the error handling wrong.  Both treat zero returns as error, but it
> actually returns negative error codes and >= 0 on success.
> 
> Fixes: e9089f43c9a7 ("misc: mic: SCIF open close bind and listen APIs")
> Signed-off-by: Dan Carpenter 
> ---
> I have not tested this patch.  Please review carefully.

Thanks for the patch Dan.

Reviewed-by: Sudeep Dutt 

> 
> diff --git a/drivers/misc/mic/scif/scif_api.c 
> b/drivers/misc/mic/scif/scif_api.c
> index 463f06d0b4ef..8dd0ccedeb94 100644
> --- a/drivers/misc/mic/scif/scif_api.c
> +++ b/drivers/misc/mic/scif/scif_api.c
> @@ -371,11 +371,10 @@ int scif_bind(scif_epd_t epd, u16 pn)
>   goto scif_bind_exit;
>   }
>   } else {
> - pn = scif_get_new_port();
> - if (!pn) {
> - ret = -ENOSPC;
> + ret = scif_get_new_port();
> + if (ret < 0)
>   goto scif_bind_exit;
> - }
> + pn = ret;
>   }
>  
>   ep->state = SCIFEP_BOUND;
> @@ -649,13 +648,12 @@ int __scif_connect(scif_epd_t epd, struct scif_port_id 
> *dst, bool non_block)
>   err = -EISCONN;
>   break;
>   case SCIFEP_UNBOUND:
> - ep->port.port = scif_get_new_port();
> - if (!ep->port.port) {
> - err = -ENOSPC;
> - } else {
> - ep->port.node = scif_info.nodeid;
> - ep->conn_async_state = ASYNC_CONN_IDLE;
> - }
> + err = scif_get_new_port();
> + if (err < 0)
> + break;
> + ep->port.port = err;
> + ep->port.node = scif_info.nodeid;
> + ep->conn_async_state = ASYNC_CONN_IDLE;
>   /* Fall through */
>   case SCIFEP_BOUND:
>   /*




Re: ERROR: "vring_del_virtqueue" [drivers/misc/mic/vop/vop.ko] undefined!

2016-04-30 Thread Sudeep Dutt
On Sat, 2016-04-30 at 09:49 -0700, Randy Dunlap wrote:
> On 04/18/16 08:05, kbuild test robot wrote:
> > Hi Sudeep,
> > 
> > FYI, the error/warning still remains.
> 
> and still happens in linux-next-20160428...
> 

The patch to fix this build failure was posted @
https://lkml.org/lkml/2016/4/5/7 
Greg, can you please please apply the patch?

Thanks,
Sudeep Dutt

> 
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
> > master
> > head:   c3b46c73264b03000d1e18b22f5caf63332547c9
> > commit: 8810df37762746657cfe84014a8f30758e8f366a misc: mic: Enable VOP 
> > debugfs and driver build
> > date:   10 weeks ago
> > config: x86_64-randconfig-s2-04182146 (attached as .config)
> > reproduce:
> > git checkout 8810df37762746657cfe84014a8f30758e8f366a
> > # save the attached .config to linux build tree
> > make ARCH=x86_64 
> > 
> > All errors (new ones prefixed by >>):
> > 
> >>> ERROR: "vring_del_virtqueue" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "register_virtio_device" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "unregister_virtio_device" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "vring_new_virtqueue" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "virtio_config_changed" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "vring_interrupt" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "vring_transport_features" [drivers/misc/mic/vop/vop.ko] undefined!
> > 
> > ---
> > 0-DAY kernel test infrastructureOpen Source Technology 
> > Center
> > https://lists.01.org/pipermail/kbuild-all   Intel 
> > Corporation
> > 
> 
> 




Re: ERROR: "vring_del_virtqueue" [drivers/misc/mic/vop/vop.ko] undefined!

2016-04-30 Thread Sudeep Dutt
On Sat, 2016-04-30 at 09:49 -0700, Randy Dunlap wrote:
> On 04/18/16 08:05, kbuild test robot wrote:
> > Hi Sudeep,
> > 
> > FYI, the error/warning still remains.
> 
> and still happens in linux-next-20160428...
> 

The patch to fix this build failure was posted @
https://lkml.org/lkml/2016/4/5/7 
Greg, can you please please apply the patch?

Thanks,
Sudeep Dutt

> 
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
> > master
> > head:   c3b46c73264b03000d1e18b22f5caf63332547c9
> > commit: 8810df37762746657cfe84014a8f30758e8f366a misc: mic: Enable VOP 
> > debugfs and driver build
> > date:   10 weeks ago
> > config: x86_64-randconfig-s2-04182146 (attached as .config)
> > reproduce:
> > git checkout 8810df37762746657cfe84014a8f30758e8f366a
> > # save the attached .config to linux build tree
> > make ARCH=x86_64 
> > 
> > All errors (new ones prefixed by >>):
> > 
> >>> ERROR: "vring_del_virtqueue" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "register_virtio_device" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "unregister_virtio_device" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "vring_new_virtqueue" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "virtio_config_changed" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "vring_interrupt" [drivers/misc/mic/vop/vop.ko] undefined!
> >>> ERROR: "vring_transport_features" [drivers/misc/mic/vop/vop.ko] undefined!
> > 
> > ---
> > 0-DAY kernel test infrastructureOpen Source Technology 
> > Center
> > https://lists.01.org/pipermail/kbuild-all   Intel 
> > Corporation
> > 
> 
> 




Re: [PATCH char-misc-linus] misc: mic: Fix randconfig build error

2016-04-04 Thread Sudeep Dutt
On Mon, 2016-04-04 at 21:41 -0700, Greg Kroah-Hartman wrote:
> On Mon, Apr 04, 2016 at 09:32:30PM -0700, Sudeep Dutt wrote:
> > Fixes randconfig build error reported at
> > https://lkml.org/lkml/2016/4/3/135 by ensuring that
> > the VOP driver selects VIRTIO.
> > 
> > Reported-by: Fengguang Wu <fengguang...@intel.com>
> > Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
> > Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
> > ---
> >  drivers/misc/mic/Kconfig | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
> > index 2e4f3ba..89e5917 100644
> > --- a/drivers/misc/mic/Kconfig
> > +++ b/drivers/misc/mic/Kconfig
> > @@ -132,6 +132,7 @@ config VOP
> > tristate "VOP Driver"
> > depends on 64BIT && PCI && X86 && VOP_BUS
> > select VHOST_RING
> > +   select VIRTIO
> 
> Shouldn't it depend on this instead?

Hi Greg,

The documentation for "config VIRTIO" states that "This option is
selected by any driver which implements the virtio bus". I verified that
this patch fixes the build for the randconfig which was failing earlier.

Thanks,
Sudeep Dutt



Re: [PATCH char-misc-linus] misc: mic: Fix randconfig build error

2016-04-04 Thread Sudeep Dutt
On Mon, 2016-04-04 at 21:41 -0700, Greg Kroah-Hartman wrote:
> On Mon, Apr 04, 2016 at 09:32:30PM -0700, Sudeep Dutt wrote:
> > Fixes randconfig build error reported at
> > https://lkml.org/lkml/2016/4/3/135 by ensuring that
> > the VOP driver selects VIRTIO.
> > 
> > Reported-by: Fengguang Wu 
> > Reviewed-by: Ashutosh Dixit 
> > Signed-off-by: Sudeep Dutt 
> > ---
> >  drivers/misc/mic/Kconfig | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
> > index 2e4f3ba..89e5917 100644
> > --- a/drivers/misc/mic/Kconfig
> > +++ b/drivers/misc/mic/Kconfig
> > @@ -132,6 +132,7 @@ config VOP
> > tristate "VOP Driver"
> > depends on 64BIT && PCI && X86 && VOP_BUS
> > select VHOST_RING
> > +   select VIRTIO
> 
> Shouldn't it depend on this instead?

Hi Greg,

The documentation for "config VIRTIO" states that "This option is
selected by any driver which implements the virtio bus". I verified that
this patch fixes the build for the randconfig which was failing earlier.

Thanks,
Sudeep Dutt



[PATCH char-misc-linus] misc: mic: Fix randconfig build error

2016-04-04 Thread Sudeep Dutt
Fixes randconfig build error reported at
https://lkml.org/lkml/2016/4/3/135 by ensuring that
the VOP driver selects VIRTIO.

Reported-by: Fengguang Wu <fengguang...@intel.com>
Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 2e4f3ba..89e5917 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -132,6 +132,7 @@ config VOP
tristate "VOP Driver"
depends on 64BIT && PCI && X86 && VOP_BUS
select VHOST_RING
+   select VIRTIO
help
  This enables VOP (Virtio over PCIe) Driver support for the Intel
  Many Integrated Core (MIC) family of PCIe form factor coprocessor
-- 
1.8.2.1



[PATCH char-misc-linus] misc: mic: Fix randconfig build error

2016-04-04 Thread Sudeep Dutt
Fixes randconfig build error reported at
https://lkml.org/lkml/2016/4/3/135 by ensuring that
the VOP driver selects VIRTIO.

Reported-by: Fengguang Wu 
Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 2e4f3ba..89e5917 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -132,6 +132,7 @@ config VOP
tristate "VOP Driver"
depends on 64BIT && PCI && X86 && VOP_BUS
select VHOST_RING
+   select VIRTIO
help
  This enables VOP (Virtio over PCIe) Driver support for the Intel
  Many Integrated Core (MIC) family of PCIe form factor coprocessor
-- 
1.8.2.1



[PATCH char-misc-testing v2 2/8] misc: mic: Remove MIC X100 card virtio functionality

2016-02-08 Thread Sudeep Dutt
This patch deletes the virtio functionality from the MIC X100 card
driver. A subsequent patch will re-enable this functionality by
consolidating the hardware independent logic in a new Virtio over PCIe
(VOP) driver.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/card/Makefile |   1 -
 drivers/misc/mic/card/mic_virtio.h |  76 -
 drivers/misc/mic/card/mic_device.c |   9 +-
 drivers/misc/mic/card/mic_virtio.c | 634 -
 4 files changed, 1 insertion(+), 719 deletions(-)
 delete mode 100644 drivers/misc/mic/card/mic_virtio.h
 delete mode 100644 drivers/misc/mic/card/mic_virtio.c

diff --git a/drivers/misc/mic/card/Makefile b/drivers/misc/mic/card/Makefile
index 69d58be..6e9675e 100644
--- a/drivers/misc/mic/card/Makefile
+++ b/drivers/misc/mic/card/Makefile
@@ -8,4 +8,3 @@ obj-$(CONFIG_INTEL_MIC_CARD) += mic_card.o
 mic_card-y += mic_x100.o
 mic_card-y += mic_device.o
 mic_card-y += mic_debugfs.o
-mic_card-y += mic_virtio.o
diff --git a/drivers/misc/mic/card/mic_virtio.h 
b/drivers/misc/mic/card/mic_virtio.h
deleted file mode 100644
index d0407ba..000
--- a/drivers/misc/mic/card/mic_virtio.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Disclaimer: The codes contained in these modules may be specific to
- * the Intel Software Development Platform codenamed: Knights Ferry, and
- * the Intel product codenamed: Knights Corner, and are not backward
- * compatible with other Intel products. Additionally, Intel will NOT
- * support the codes or instruction set in future products.
- *
- * Intel MIC Card driver.
- *
- */
-#ifndef __MIC_CARD_VIRTIO_H
-#define __MIC_CARD_VIRTIO_H
-
-#include 
-#include "mic_device.h"
-
-/*
- * 64 bit I/O access
- */
-#ifndef ioread64
-#define ioread64 readq
-#endif
-#ifndef iowrite64
-#define iowrite64 writeq
-#endif
-
-static inline unsigned mic_desc_size(struct mic_device_desc __iomem *desc)
-{
-   return sizeof(*desc)
-   + ioread8(>num_vq) * sizeof(struct mic_vqconfig)
-   + ioread8(>feature_len) * 2
-   + ioread8(>config_len);
-}
-
-static inline struct mic_vqconfig __iomem *
-mic_vq_config(struct mic_device_desc __iomem *desc)
-{
-   return (struct mic_vqconfig __iomem *)(desc + 1);
-}
-
-static inline __u8 __iomem *
-mic_vq_features(struct mic_device_desc __iomem *desc)
-{
-   return (__u8 __iomem *)(mic_vq_config(desc) + ioread8(>num_vq));
-}
-
-static inline __u8 __iomem *
-mic_vq_configspace(struct mic_device_desc __iomem *desc)
-{
-   return mic_vq_features(desc) + ioread8(>feature_len) * 2;
-}
-static inline unsigned mic_total_desc_size(struct mic_device_desc __iomem 
*desc)
-{
-   return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
-}
-
-int mic_devices_init(struct mic_driver *mdrv);
-void mic_devices_uninit(struct mic_driver *mdrv);
-
-#endif
diff --git a/drivers/misc/mic/card/mic_device.c 
b/drivers/misc/mic/card/mic_device.c
index d0edaf7..ff03c63 100644
--- a/drivers/misc/mic/card/mic_device.c
+++ b/drivers/misc/mic/card/mic_device.c
@@ -34,7 +34,6 @@
 #include 
 #include "../common/mic_dev.h"
 #include "mic_device.h"
-#include "mic_virtio.h"
 
 static struct mic_driver *g_drv;
 
@@ -309,9 +308,6 @@ int __init mic_driver_init(struct mic_driver *mdrv)
rc = -ENODEV;
goto irq_uninit;
}
-   rc = mic_devices_init(mdrv);
-   if (rc)
-   goto dma_free;
bootparam = mdrv->dp;
node_id = ioread8(>node_id);
mdrv->scdev = scif_register_device(mdrv->dev, MIC_SCIF_DEV,
@@ -321,13 +317,11 @@ int __init mic_driver_init(struct mic_driver *mdrv)
   mdrv->num_dma_ch, true);
if (IS_ERR(mdrv->scdev)) {
rc = PTR_ERR(mdrv->scdev);
-   goto device_uninit;
+   goto dma_free;
}
mic_create_card_debug_dir(mdrv);
 done:
return rc;
-device_uninit:
-   mic_devices_uninit(mdrv);
 dma_free:
mic_free_dma_chans(mdrv);
 irq_uninit:
@@ -348,7 +342,6 @@ void mic_driver_uninit(struct mic_driver *mdrv)
 {
mic_delete_card_debug_dir(mdrv);
scif_unregister_device(mdrv->scdev);
-   mic_devices_uninit(mdrv);
  

[PATCH char-misc-testing v2 1/8] misc: mic: Remove MIC X100 host virtio functionality

2016-02-08 Thread Sudeep Dutt
This patch deletes the virtio functionality from the MIC X100 host
driver. A subsequent patch will re-enable this functionality by
consolidating the hardware independent logic in a new Virtio over PCIe
(VOP) driver.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/host/Makefile  |   2 -
 drivers/misc/mic/host/mic_device.h  |   6 -
 drivers/misc/mic/host/mic_fops.h|  32 --
 drivers/misc/mic/host/mic_virtio.h  | 155 ---
 drivers/misc/mic/host/mic_boot.c|   2 -
 drivers/misc/mic/host/mic_debugfs.c | 190 -
 drivers/misc/mic/host/mic_fops.c| 222 --
 drivers/misc/mic/host/mic_main.c|  48 +--
 drivers/misc/mic/host/mic_virtio.c  | 811 
 9 files changed, 4 insertions(+), 1464 deletions(-)
 delete mode 100644 drivers/misc/mic/host/mic_fops.h
 delete mode 100644 drivers/misc/mic/host/mic_virtio.h
 delete mode 100644 drivers/misc/mic/host/mic_fops.c
 delete mode 100644 drivers/misc/mic/host/mic_virtio.c

diff --git a/drivers/misc/mic/host/Makefile b/drivers/misc/mic/host/Makefile
index 004d3db..f3b5023 100644
--- a/drivers/misc/mic/host/Makefile
+++ b/drivers/misc/mic/host/Makefile
@@ -9,5 +9,3 @@ mic_host-objs += mic_smpt.o
 mic_host-objs += mic_intr.o
 mic_host-objs += mic_boot.o
 mic_host-objs += mic_debugfs.o
-mic_host-objs += mic_fops.o
-mic_host-objs += mic_virtio.o
diff --git a/drivers/misc/mic/host/mic_device.h 
b/drivers/misc/mic/host/mic_device.h
index 461184a..8460de1 100644
--- a/drivers/misc/mic/host/mic_device.h
+++ b/drivers/misc/mic/host/mic_device.h
@@ -64,9 +64,6 @@ extern struct cosm_hw_ops cosm_hw_ops;
  * @bootaddr: MIC boot address.
  * @dp: virtio device page
  * @dp_dma_addr: virtio device page DMA address.
- * @name: name for the misc char device
- * @miscdev: registered misc char device
- * @vdev_list: list of virtio devices.
  * @dma_mbdev: MIC BUS DMA device.
  * @dma_ch - Array of DMA channels
  * @num_dma_ch - Number of DMA channels available
@@ -91,9 +88,6 @@ struct mic_device {
u32 bootaddr;
void *dp;
dma_addr_t dp_dma_addr;
-   char name[16];
-   struct miscdevice miscdev;
-   struct list_head vdev_list;
struct mbus_device *dma_mbdev;
struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN];
int num_dma_ch;
diff --git a/drivers/misc/mic/host/mic_fops.h b/drivers/misc/mic/host/mic_fops.h
deleted file mode 100644
index dc3893d..000
--- a/drivers/misc/mic/host/mic_fops.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Intel MIC Host driver.
- *
- */
-#ifndef _MIC_FOPS_H_
-#define _MIC_FOPS_H_
-
-int mic_open(struct inode *inode, struct file *filp);
-int mic_release(struct inode *inode, struct file *filp);
-ssize_t mic_read(struct file *filp, char __user *buf,
-   size_t count, loff_t *pos);
-long mic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
-int mic_mmap(struct file *f, struct vm_area_struct *vma);
-unsigned int mic_poll(struct file *f, poll_table *wait);
-
-#endif
diff --git a/drivers/misc/mic/host/mic_virtio.h 
b/drivers/misc/mic/host/mic_virtio.h
deleted file mode 100644
index a80631f..000
--- a/drivers/misc/mic/host/mic_virtio.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Intel MIC Host driver.
- *
- */
-#ifndef MIC_VIRTIO_H
-#define MIC_VIRTIO_H
-
-#include 
-#include 
-
-/*
- * Note on endianness.
- * 1. Host can be both BE or LE
- * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
- *rings and ioreadXX/iowriteXX to access used ring.
- * 3. Device page exposed by host to guest contains LE values. Guest
- *accesses these using ioreadXX/iowriteXX etc. This way in ge

[PATCH char-misc-testing v2 7/8] misc: mic: Enable VOP debugfs and driver build

2016-02-08 Thread Sudeep Dutt
This patch moves the virtio specific debugfs hooks previously in
mic_debugfs.c in the MIC host driver into the VOP driver. The
Kconfig/Makefile is also updated to allow building the VOP driver.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/Kconfig   |  20 
 drivers/misc/mic/Makefile  |   1 +
 drivers/misc/mic/vop/Makefile  |   9 ++
 drivers/misc/mic/vop/vop_debugfs.c | 232 +
 4 files changed, 262 insertions(+)
 create mode 100644 drivers/misc/mic/vop/Makefile
 create mode 100644 drivers/misc/mic/vop/vop_debugfs.c

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 840f7ef..b03bb17 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -124,3 +124,23 @@ config MIC_COSM
  More information about the Intel MIC family as well as the Linux
  OS and tools for MIC to use with this driver are available from
  <http://software.intel.com/en-us/mic-developer>.
+
+comment "VOP Driver"
+
+config VOP
+   tristate "VOP Driver"
+   depends on 64BIT && PCI && X86 && VOP_BUS
+   select VHOST_RING
+   help
+ This enables VOP (Virtio over PCIe) Driver support for the Intel
+ Many Integrated Core (MIC) family of PCIe form factor coprocessor
+ devices. The VOP driver allows virtio drivers, e.g. net, console
+ and block drivers, on the card connect to user space virtio
+ devices on the host.
+
+ If you are building a host kernel with an Intel MIC device then
+ say M (recommended) or Y, else say N. If unsure say N.
+
+ More information about the Intel MIC family as well as the Linux
+ OS and tools for MIC to use with this driver are available from
+ <http://software.intel.com/en-us/mic-developer>.
diff --git a/drivers/misc/mic/Makefile b/drivers/misc/mic/Makefile
index e288a11..f2b1323 100644
--- a/drivers/misc/mic/Makefile
+++ b/drivers/misc/mic/Makefile
@@ -8,3 +8,4 @@ obj-y += bus/
 obj-$(CONFIG_SCIF) += scif/
 obj-$(CONFIG_MIC_COSM) += cosm/
 obj-$(CONFIG_MIC_COSM) += cosm_client/
+obj-$(CONFIG_VOP) += vop/
diff --git a/drivers/misc/mic/vop/Makefile b/drivers/misc/mic/vop/Makefile
new file mode 100644
index 000..78819c8
--- /dev/null
+++ b/drivers/misc/mic/vop/Makefile
@@ -0,0 +1,9 @@
+#
+# Makefile - Intel MIC Linux driver.
+# Copyright(c) 2016, Intel Corporation.
+#
+obj-m := vop.o
+
+vop-objs += vop_main.o
+vop-objs += vop_debugfs.o
+vop-objs += vop_vringh.o
diff --git a/drivers/misc/mic/vop/vop_debugfs.c 
b/drivers/misc/mic/vop/vop_debugfs.c
new file mode 100644
index 000..ab43884
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_debugfs.c
@@ -0,0 +1,232 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+
+#include "vop_main.h"
+
+static int vop_dp_show(struct seq_file *s, void *pos)
+{
+   struct mic_device_desc *d;
+   struct mic_device_ctrl *dc;
+   struct mic_vqconfig *vqconfig;
+   __u32 *features;
+   __u8 *config;
+   struct vop_info *vi = s->private;
+   struct vop_device *vpdev = vi->vpdev;
+   struct mic_bootparam *bootparam = vpdev->hw_ops->get_dp(vpdev);
+   int j, k;
+
+   seq_printf(s, "Bootparam: magic 0x%x\n",
+  bootparam->magic);
+   seq_printf(s, "Bootparam: h2c_config_db %d\n",
+  bootparam->h2c_config_db);
+   seq_printf(s, "Bootparam: node_id %d\n",
+  bootparam->node_id);
+   seq_printf(s, "Bootparam: c2h_scif_db %d\n",
+  bootparam->c2h_scif_db);
+   seq_printf(s, "Bootparam: h2c_scif_db %d\n",
+  bootparam->h2c_scif_db);
+   seq_printf(s, "Bootparam: scif_host_dma_addr 0x%llx\n",
+  bootparam->scif_host_dma_addr);
+   seq_printf(s, "Bootparam: scif_card_dma_addr 0x%llx\n",
+  bootparam->scif_card_dma_addr);
+
+   for (j = sizeof(*bootparam);
+   j < MIC_DP_SIZE; j += mic_total_desc_size(d)) {
+   d = (void *)bootparam + j;
+   dc = (void *)d + mic_aligned_desc_size(d);
+
+   

[PATCH char-misc-testing v2 5/8] misc: mic: Enable VOP host side functionality

2016-02-08 Thread Sudeep Dutt
This patch moves virtio functionality from the MIC host driver into a
separate hardware independent Virtio Over PCIe (VOP) driver. This
functionality was introduced in commit f69bcbf3b4c4 ("Intel MIC Host
Driver Changes for Virtio Devices.") in
drivers/misc/mic/host/mic_virtio.c. Apart from being moved into a
separate driver the functionality is essentially unchanged. See the
above mentioned commit for a description of this functionality.

Signed-off-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/vop/vop_vringh.c | 1164 +
 1 file changed, 1164 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_vringh.c

diff --git a/drivers/misc/mic/vop/vop_vringh.c 
b/drivers/misc/mic/vop/vop_vringh.c
new file mode 100644
index 000..c1dd000
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_vringh.c
@@ -0,0 +1,1164 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+#include 
+
+#include 
+#include "../common/mic_dev.h"
+
+#include 
+#include "vop_main.h"
+
+/* Helper API to obtain the VOP PCIe device */
+static inline struct device *vop_dev(struct vop_vdev *vdev)
+{
+   return vdev->vpdev->dev.parent;
+}
+
+/* Helper API to check if a virtio device is initialized */
+static inline int vop_vdev_inited(struct vop_vdev *vdev)
+{
+   if (!vdev)
+   return -EINVAL;
+   /* Device has not been created yet */
+   if (!vdev->dd || !vdev->dd->type) {
+   dev_err(vop_dev(vdev), "%s %d err %d\n",
+   __func__, __LINE__, -EINVAL);
+   return -EINVAL;
+   }
+   /* Device has been removed/deleted */
+   if (vdev->dd->type == -1) {
+   dev_dbg(vop_dev(vdev), "%s %d err %d\n",
+   __func__, __LINE__, -ENODEV);
+   return -ENODEV;
+   }
+   return 0;
+}
+
+static void _vop_notify(struct vringh *vrh)
+{
+   struct vop_vringh *vvrh = container_of(vrh, struct vop_vringh, vrh);
+   struct vop_vdev *vdev = vvrh->vdev;
+   struct vop_device *vpdev = vdev->vpdev;
+   s8 db = vdev->dc->h2c_vdev_db;
+
+   if (db != -1)
+   vpdev->hw_ops->send_intr(vpdev, db);
+}
+
+static void vop_virtio_init_post(struct vop_vdev *vdev)
+{
+   struct mic_vqconfig *vqconfig = mic_vq_config(vdev->dd);
+   struct vop_device *vpdev = vdev->vpdev;
+   int i, used_size;
+
+   for (i = 0; i < vdev->dd->num_vq; i++) {
+   used_size = PAGE_ALIGN(sizeof(u16) * 3 +
+   sizeof(struct vring_used_elem) *
+   le16_to_cpu(vqconfig->num));
+   if (!le64_to_cpu(vqconfig[i].used_address)) {
+   dev_warn(vop_dev(vdev), "used_address zero??\n");
+   continue;
+   }
+   vdev->vvr[i].vrh.vring.used =
+   (void __force *)vpdev->hw_ops->ioremap(
+   vpdev,
+   le64_to_cpu(vqconfig[i].used_address),
+   used_size);
+   }
+
+   vdev->dc->used_address_updated = 0;
+
+   dev_info(vop_dev(vdev), "%s: device type %d LINKUP\n",
+__func__, vdev->virtio_id);
+}
+
+static inline void vop_virtio_device_reset(struct vop_vdev *vdev)
+{
+   int i;
+
+   dev_dbg(vop_dev(vdev), "%s: status %d device type %d RESET\n",
+   __func__, vdev->dd->status, vdev->virtio_id);
+
+   for (i = 0; i < vdev->dd->num_vq; i++)
+   /*
+* Avoid lockdep false positive. The + 1 is for the vop
+* mutex which is held in the reset devices code path.
+*/
+   mutex_lock_nested(>vvr[i].vr_mutex, i + 1);
+
+   /* 0 status means "reset" */
+   vdev->dd->status = 0;
+   vdev->dc->vdev_reset = 0;
+   vdev->dc->host_ack = 1;
+
+   for (i = 0; i < vdev->dd->num_vq; i++) {
+   struct vringh *vrh = >vvr[i].vrh;
+
+   vdev->vvr[i].vring.info->avail_idx = 0;
+   vrh->completed = 0;
+  

[PATCH char-misc-testing v2 6/8] misc: mic: Enable VOP card side functionality

2016-02-08 Thread Sudeep Dutt
From: Ashutosh Dixit 

This patch moves virtio functionality from the MIC card driver into a
separate hardware independent Virtio Over PCIe (VOP) driver. This
functionality was introduced in commit 2141c7c5ee67 ("Intel MIC Card
Driver Changes for Virtio Devices.") in
drivers/misc/mic/card/mic_virtio.c. Apart from being moved into a
separate driver the functionality is essentially unchanged. See the
above mentioned commit for a description of this functionality.

Signed-off-by: Sudeep Dutt 
Signed-off-by: Ashutosh Dixit 
---
 drivers/misc/mic/vop/vop_main.c | 755 
 1 file changed, 755 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_main.c

diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
new file mode 100644
index 000..1a2b67f
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_main.c
@@ -0,0 +1,755 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Adapted from:
+ *
+ * virtio for kvm on s390
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Christian Borntraeger 
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+
+#include "vop_main.h"
+
+#define VOP_MAX_VRINGS 4
+
+/*
+ * _vop_vdev - Allocated per virtio device instance injected by the peer.
+ *
+ * @vdev: Virtio device
+ * @desc: Virtio device page descriptor
+ * @dc: Virtio device control
+ * @vpdev: VOP device which is the parent for this virtio device
+ * @vr: Buffer for accessing the VRING
+ * @used: Buffer for used
+ * @used_size: Size of the used buffer
+ * @reset_done: Track whether VOP reset is complete
+ * @virtio_cookie: Cookie returned upon requesting a interrupt
+ * @c2h_vdev_db: The doorbell used by the guest to interrupt the host
+ * @h2c_vdev_db: The doorbell used by the host to interrupt the guest
+ * @dnode: The destination node
+ */
+struct _vop_vdev {
+   struct virtio_device vdev;
+   struct mic_device_desc __iomem *desc;
+   struct mic_device_ctrl __iomem *dc;
+   struct vop_device *vpdev;
+   void __iomem *vr[VOP_MAX_VRINGS];
+   dma_addr_t used[VOP_MAX_VRINGS];
+   int used_size[VOP_MAX_VRINGS];
+   struct completion reset_done;
+   struct mic_irq *virtio_cookie;
+   int c2h_vdev_db;
+   int h2c_vdev_db;
+   int dnode;
+};
+
+#define to_vopvdev(vd) container_of(vd, struct _vop_vdev, vdev)
+
+#define _vop_aligned_desc_size(d) __mic_align(_vop_desc_size(d), 8)
+
+/* Helper API to obtain the parent of the virtio device */
+static inline struct device *_vop_dev(struct _vop_vdev *vdev)
+{
+   return vdev->vdev.dev.parent;
+}
+
+static inline unsigned _vop_desc_size(struct mic_device_desc __iomem *desc)
+{
+   return sizeof(*desc)
+   + ioread8(>num_vq) * sizeof(struct mic_vqconfig)
+   + ioread8(>feature_len) * 2
+   + ioread8(>config_len);
+}
+
+static inline struct mic_vqconfig __iomem *
+_vop_vq_config(struct mic_device_desc __iomem *desc)
+{
+   return (struct mic_vqconfig __iomem *)(desc + 1);
+}
+
+static inline u8 __iomem *
+_vop_vq_features(struct mic_device_desc __iomem *desc)
+{
+   return (u8 __iomem *)(_vop_vq_config(desc) + ioread8(>num_vq));
+}
+
+static inline u8 __iomem *
+_vop_vq_configspace(struct mic_device_desc __iomem *desc)
+{
+   return _vop_vq_features(desc) + ioread8(>feature_len) * 2;
+}
+
+static inline unsigned
+_vop_total_desc_size(struct mic_device_desc __iomem *desc)
+{
+   return _vop_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
+}
+
+/* This gets the device's feature bits. */
+static u64 vop_get_features(struct virtio_device *vdev)
+{
+   unsigned int i, bits;
+   u32 features = 0;
+   struct mic_device_desc __iomem *desc = to_vopvdev(vdev)->desc;
+   u8 __iomem *in_features = _vop_vq_features(desc);
+   int feature_len = ioread8(>feature_len);
+
+   bits = min_t(unsigned, feature_len, sizeof(vdev->features)) * 8;
+   for (i = 0; i < bits; i++)
+   if (ioread8(_features[i / 8]) & (BIT(i % 8)))
+   features |= BIT(i);
+
+ 

[PATCH char-misc-testing v2 3/8] misc: mic: MIC VOP Bus

2016-02-08 Thread Sudeep Dutt
The Virtio Over PCIe (VOP) bus abstracts the low level hardware
details like interrupts and mapping remote memory so that the same VOP
driver can work without changes with different MIC host or card
drivers as long as the hardware bus operations are implemented. The
VOP driver registers itself on the VOP bus. The base PCIe drivers
implement the bus ops and register VOP devices on the bus, resulting
in the VOP driver being probed with the VOP devices. This allows the
VOP functionality to be shared between multiple generations of Intel
MIC products.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/Kconfig   |  17 
 drivers/misc/mic/bus/Makefile  |   1 +
 drivers/misc/mic/bus/vop_bus.h | 140 
 drivers/misc/mic/bus/vop_bus.c | 203 +
 4 files changed, 361 insertions(+)
 create mode 100644 drivers/misc/mic/bus/vop_bus.h
 create mode 100644 drivers/misc/mic/bus/vop_bus.c

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 40677df..840f7ef 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -32,6 +32,23 @@ config SCIF_BUS
  OS and tools for MIC to use with this driver are available from
  <http://software.intel.com/en-us/mic-developer>.
 
+comment "VOP Bus Driver"
+
+config VOP_BUS
+   tristate "VOP Bus Driver"
+   depends on 64BIT && PCI && X86 && X86_DEV_DMA_OPS
+   help
+ This option is selected by any driver which registers a
+ device or driver on the VOP Bus, such as CONFIG_INTEL_MIC_HOST
+ and CONFIG_INTEL_MIC_CARD.
+
+ If you are building a host/card kernel with an Intel MIC device
+ then say M (recommended) or Y, else say N. If unsure say N.
+
+ More information about the Intel MIC family as well as the Linux
+ OS and tools for MIC to use with this driver are available from
+ <http://software.intel.com/en-us/mic-developer>.
+
 comment "Intel MIC Host Driver"
 
 config INTEL_MIC_HOST
diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
index 761842b..8758a7d 100644
--- a/drivers/misc/mic/bus/Makefile
+++ b/drivers/misc/mic/bus/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
 obj-$(CONFIG_SCIF_BUS) += scif_bus.o
 obj-$(CONFIG_MIC_COSM) += cosm_bus.o
+obj-$(CONFIG_VOP_BUS) += vop_bus.o
diff --git a/drivers/misc/mic/bus/vop_bus.h b/drivers/misc/mic/bus/vop_bus.h
new file mode 100644
index 000..fff7a86
--- /dev/null
+++ b/drivers/misc/mic/bus/vop_bus.h
@@ -0,0 +1,140 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio over PCIe Bus driver.
+ */
+#ifndef _VOP_BUS_H_
+#define _VOP_BUS_H_
+/*
+ * Everything a vop driver needs to work with any particular vop
+ * implementation.
+ */
+#include 
+#include 
+
+#include "../common/mic_dev.h"
+
+struct vop_device_id {
+   u32 device;
+   u32 vendor;
+};
+
+#define VOP_DEV_TRNSP 1
+#define VOP_DEV_ANY_ID 0x
+/*
+ * Size of the internal buffer used during DMA's as an intermediate buffer
+ * for copy to/from user. Must be an integral number of pages.
+ */
+#define VOP_INT_DMA_BUF_SIZE PAGE_ALIGN(64 * 1024ULL)
+
+/**
+ * vop_device - representation of a device using vop
+ * @hw_ops: the hardware ops supported by this device.
+ * @id: the device type identification (used to match it with a driver).
+ * @dev: underlying device.
+ * @dnode - The destination node which this device will communicate with.
+ * @aper: Aperture memory window
+ * @dma_ch - DMA channel
+ * @index: unique position on the vop bus
+ */
+struct vop_device {
+   struct vop_hw_ops *hw_ops;
+   struct vop_device_id id;
+   struct device dev;
+   u8 dnode;
+   struct mic_mw *aper;
+   struct dma_chan *dma_ch;
+   int index;
+};
+
+/**
+ * vop_driver - operations for a vop I/O driver
+ * @driver: underlying device driver (populate name and owner).
+ * @id_table: the ids serviced by this driver.
+ * @probe: the function to call when a device is found.  Returns 0 or -errno.
+ * @remove: the function to call when a device is removed.
+ */
+struct vop_driver {
+   struct device_driver driver;
+   const struct vop_device_id *id_table;
+   int (*probe)(struct vop_device *dev)

[PATCH char-misc-testing v2 4/8] misc: mic: Add data structures for the VOP driver

2016-02-08 Thread Sudeep Dutt
This patch adds VOP driver data structures used in subsequent
patches. These data structures are refactored from similar data
structures used in the virtio parts of previous MIC host and card
drivers.

Signed-off-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/vop/vop_main.h | 170 
 1 file changed, 170 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_main.h

diff --git a/drivers/misc/mic/vop/vop_main.h b/drivers/misc/mic/vop/vop_main.h
new file mode 100644
index 000..ba47ec7
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_main.h
@@ -0,0 +1,170 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#ifndef _VOP_MAIN_H_
+#define _VOP_MAIN_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "../common/mic_dev.h"
+
+#include "../bus/vop_bus.h"
+
+/*
+ * Note on endianness.
+ * 1. Host can be both BE or LE
+ * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
+ *rings and ioreadXX/iowriteXX to access used ring.
+ * 3. Device page exposed by host to guest contains LE values. Guest
+ *accesses these using ioreadXX/iowriteXX etc. This way in general we
+ *obey the virtio spec according to which guest works with native
+ *endianness and host is aware of guest endianness and does all
+ *required endianness conversion.
+ * 4. Data provided from user space to guest (in ADD_DEVICE and
+ *CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
+ *in guest endianness.
+ */
+
+/*
+ * vop_info - Allocated per invocation of VOP probe
+ *
+ * @vpdev: VOP device
+ * @hotplug_work: Handle virtio device creation, deletion and configuration
+ * @cookie: Cookie received upon requesting a virtio configuration interrupt
+ * @h2c_config_db: The doorbell used by the peer to indicate a config change
+ * @vdev_list: List of "active" virtio devices injected in the peer node
+ * @vop_mutex: Synchronize access to the device page as well as serialize
+ * creation/deletion of virtio devices on the peer node
+ * @dp: Peer device page information
+ * @dbg: Debugfs entry
+ * @dma_ch: The DMA channel used by this transport for data transfers.
+ * @name: Name for this transport used in misc device creation.
+ * @miscdev: The misc device registered.
+ */
+struct vop_info {
+   struct vop_device *vpdev;
+   struct work_struct hotplug_work;
+   struct mic_irq *cookie;
+   int h2c_config_db;
+   struct list_head vdev_list;
+   struct mutex vop_mutex;
+   void __iomem *dp;
+   struct dentry *dbg;
+   struct dma_chan *dma_ch;
+   char name[16];
+   struct miscdevice miscdev;
+};
+
+/**
+ * struct vop_vringh - Virtio ring host information.
+ *
+ * @vring: The VOP vring used for setting up user space mappings.
+ * @vrh: The host VRINGH used for accessing the card vrings.
+ * @riov: The VRINGH read kernel IOV.
+ * @wiov: The VRINGH write kernel IOV.
+ * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
+ * @vr_mutex: Mutex for synchronizing access to the VRING.
+ * @buf: Temporary kernel buffer used to copy in/out data
+ * from/to the card via DMA.
+ * @buf_da: dma address of buf.
+ * @vdev: Back pointer to VOP virtio device for vringh_notify(..).
+ */
+struct vop_vringh {
+   struct mic_vring vring;
+   struct vringh vrh;
+   struct vringh_kiov riov;
+   struct vringh_kiov wiov;
+   u16 head;
+   struct mutex vr_mutex;
+   void *buf;
+   dma_addr_t buf_da;
+   struct vop_vdev *vdev;
+};
+
+/**
+ * struct vop_vdev - Host information for a card Virtio device.
+ *
+ * @virtio_id - Virtio device id.
+ * @waitq - Waitqueue to allow ring3 apps to poll.
+ * @vpdev - pointer to VOP bus device.
+ * @poll_wake - Used for waking up threads blocked in poll.
+ * @out_bytes - Debug stats for number of bytes copied from host to card.
+ * @in_bytes - Debug stats for number of bytes copied from card to host.
+ * @out_bytes_dma - Debug stats for number of bytes copied from host to card
+ * using DMA.
+ * @in_bytes_dma - Debug stats for number of bytes copied from card to host
+ * using DMA.
+ * @tx_len_unaligned - Debug stats for number of bytes copied to the card where
+ * the transfer length did not have the required DMA alignm

[PATCH char-misc-testing v2 0/8] Enable Virtio Over PCIe (VOP) driver

2016-02-08 Thread Sudeep Dutt
ChangeLog:
=
v1 => v2:
a) Rebased to latest char-misc-testing
b) Use default private pointer in the device structure instead of adding
   a new priv field as per feedback from Greg Kroah-Hartman

v1: Initial post @ https://lkml.org/lkml/2016/2/1/1015

Description:

This patch series moves virtio functionality from the MIC host/card
driver into a separate hardware independent Virtio Over PCIe (VOP)
driver. Apart from being moved into a separate driver the functionality
is essentially unchanged. This refactoring allows this hardware
independent logic to be shared easily across multiple generations of
MIC devices. The original commits are listed below for reference:
- commit f69bcbf3b4c4 ("Intel MIC Host Driver Changes for Virtio Devices.")
in drivers/misc/mic/host/mic_virtio.c
- commit 2141c7c5ee67 ("Intel MIC Card Driver Changes for Virtio Devices.")
in drivers/misc/mic/card/mic_virtio.c

The patch series is partitioned as follows:
1) Removes MIC X100 host virtio functionality
2) Removes MIC X100 card virtio functionality
3) Enables the Virtio Over PCIe (VOP) bus which abstracts the
   low level hardware details like interrupts and mapping remote
   memory so that the same VOP driver can work without changes
   with different MIC host or card drivers as long as the hardware
   bus operations are implemented.
4) Adds data structures for the VOP driver
5) Enables VOP host side functionality
6) Enables VOP card side functionality
7) Enables VOP debugfs and driver build
8) Implements the MIC host and card driver changes to enable VOP

Ashutosh Dixit (1):
  misc: mic: Enable VOP card side functionality

Sudeep Dutt (7):
  misc: mic: Remove MIC X100 host virtio functionality
  misc: mic: Remove MIC X100 card virtio functionality
  misc: mic: MIC VOP Bus
  misc: mic: Add data structures for the VOP driver
  misc: mic: Enable VOP host side functionality
  misc: mic: Enable VOP debugfs and driver build
  misc: mic: MIC host and card driver changes to enable VOP

 Documentation/mic/mic_overview.txt |   54 +-
 drivers/misc/mic/Kconfig   |   44 +-
 drivers/misc/mic/Makefile  |1 +
 drivers/misc/mic/bus/Makefile  |1 +
 drivers/misc/mic/card/Makefile |1 -
 drivers/misc/mic/host/Makefile |2 -
 drivers/misc/mic/vop/Makefile  |9 +
 drivers/misc/mic/bus/vop_bus.h |  140 +++
 drivers/misc/mic/card/mic_device.h |3 +
 drivers/misc/mic/card/mic_virtio.h |   76 --
 drivers/misc/mic/host/mic_device.h |9 +-
 drivers/misc/mic/host/mic_fops.h   |   32 -
 .../misc/mic/{host/mic_virtio.h => vop/vop_main.h} |  129 ++-
 Documentation/mic/mpssd/mpssd.c|2 +-
 drivers/misc/mic/bus/vop_bus.c |  203 
 drivers/misc/mic/card/mic_device.c |   89 +-
 drivers/misc/mic/card/mic_virtio.c |  634 ---
 drivers/misc/mic/card/mic_x100.c   |1 +
 drivers/misc/mic/host/mic_boot.c   |  125 ++-
 drivers/misc/mic/host/mic_debugfs.c|  190 
 drivers/misc/mic/host/mic_fops.c   |  222 
 drivers/misc/mic/host/mic_main.c   |   49 +-
 drivers/misc/mic/host/mic_virtio.c |  811 --
 drivers/misc/mic/vop/vop_debugfs.c |  232 
 drivers/misc/mic/vop/vop_main.c|  755 +
 drivers/misc/mic/vop/vop_vringh.c  | 1164 
 Documentation/mic/mpssd/mpss   |2 +-
 27 files changed, 2864 insertions(+), 2116 deletions(-)
 create mode 100644 drivers/misc/mic/vop/Makefile
 create mode 100644 drivers/misc/mic/bus/vop_bus.h
 delete mode 100644 drivers/misc/mic/card/mic_virtio.h
 delete mode 100644 drivers/misc/mic/host/mic_fops.h
 rename drivers/misc/mic/{host/mic_virtio.h => vop/vop_main.h} (58%)
 create mode 100644 drivers/misc/mic/bus/vop_bus.c
 delete mode 100644 drivers/misc/mic/card/mic_virtio.c
 delete mode 100644 drivers/misc/mic/host/mic_fops.c
 delete mode 100644 drivers/misc/mic/host/mic_virtio.c
 create mode 100644 drivers/misc/mic/vop/vop_debugfs.c
 create mode 100644 drivers/misc/mic/vop/vop_main.c
 create mode 100644 drivers/misc/mic/vop/vop_vringh.c

-- 
1.8.2.1



[PATCH char-misc-testing v2 8/8] misc: mic: MIC host and card driver changes to enable VOP

2016-02-08 Thread Sudeep Dutt
This patch modifies the MIC host and card drivers to start using the
VOP driver. The MIC host and card drivers now implement the VOP bus
operations and register a VOP device on the VOP bus. MIC driver stack
documentation is also updated to include the new VOP driver.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 Documentation/mic/mic_overview.txt |  54 
 drivers/misc/mic/Kconfig   |   7 ++-
 drivers/misc/mic/card/mic_device.h |   3 +
 drivers/misc/mic/host/mic_device.h |   3 +
 Documentation/mic/mpssd/mpssd.c|   2 +-
 drivers/misc/mic/card/mic_device.c |  84 -
 drivers/misc/mic/card/mic_x100.c   |   1 +
 drivers/misc/mic/host/mic_boot.c   | 123 -
 drivers/misc/mic/host/mic_main.c   |   1 +
 Documentation/mic/mpssd/mpss   |   2 +-
 10 files changed, 247 insertions(+), 33 deletions(-)

diff --git a/Documentation/mic/mic_overview.txt 
b/Documentation/mic/mic_overview.txt
index 73f44fc..074adbd 100644
--- a/Documentation/mic/mic_overview.txt
+++ b/Documentation/mic/mic_overview.txt
@@ -12,10 +12,19 @@ for the X100 devices.
 
 Since it is a PCIe card, it does not have the ability to host hardware
 devices for networking, storage and console. We provide these devices
-on X100 coprocessors thus enabling a self-bootable equivalent environment
-for applications. A key benefit of our solution is that it leverages
-the standard virtio framework for network, disk and console devices,
-though in our case the virtio framework is used across a PCIe bus.
+on X100 coprocessors thus enabling a self-bootable equivalent
+environment for applications. A key benefit of our solution is that it
+leverages the standard virtio framework for network, disk and console
+devices, though in our case the virtio framework is used across a PCIe
+bus. A Virtio Over PCIe (VOP) driver allows creating user space
+backends or devices on the host which are used to probe virtio drivers
+for these devices on the MIC card. The existing VRINGH infrastructure
+in the kernel is used to access virtio rings from the host. The card
+VOP driver allows card virtio drivers to communicate with their user
+space backends on the host via a device page. Ring 3 apps on the host
+can add, remove and configure virtio devices. A thin MIC specific
+virtio_config_ops is implemented which is borrowed heavily from
+previous similar implementations in lguest and s390.
 
 MIC PCIe card has a dma controller with 8 channels. These channels are
 shared between the host s/w and the card s/w. 0 to 3 are used by host
@@ -38,7 +47,6 @@ single threaded performance for the host compared to MIC, the 
ability of
 the host to initiate DMA's to/from the card using the MIC DMA engine and
 the fact that the virtio block storage backend can only be on the host.
 
-  |
+--+   | +--+
| Card OS  |   | | Host OS  |
+--+   | +--+
@@ -47,27 +55,25 @@ the fact that the virtio block storage backend can only be 
on the host.
 | Virtio| |Virtio  | |Virtio| | |Virtio   |  |Virtio  | |Virtio  |
 | Net   | |Console | |Block | | |Net  |  |Console | |Block   |
 | Driver| |Driver  | |Driver| | |backend  |  |backend | |backend |
-+---+ ++ +--+ | +-+  ++ ++
++---+---+ +---++ +--+---+ | +-+  ++---+ ++
 | | | |  || |
 | | | |User  || |
-| | | |--||-|---
-+---+ |Kernel +--+
-  |   |   | Virtio over PCIe IOCTLs  |
-  |   |   +--+
-+---+ |   |   |  +---+
-| MIC DMA   | |  +--+ | +--+ +--+ |  | MIC DMA   |
-| Driver| |  | SCIF | | | SCIF | | COSM | |  | Driver|
-+---+ |  +--+ | +--+ +--+---+ |  +---+
-  |   | | ||| ||
-+---+ |  +--+ | +--+---+ +--+---+ | ++
-|MIC virtual Bus| |  |SCIF  | | |SCIF  | | COSM | | |MIC virtual Bus |
-+---+ |  |HW Bus| | |HW Bus| | Bus  | | ++
-  |   |  +--+ | +--+---+ +--+ |  |
-  |   | | |   | | |  |
-  |   +---+---+ | |   |+---+ |
-  |   |Intel MIC  | | |   ||Intel MIC  | |
-  +---|Card Driver| | |   ||Host Driver

Re: [PATCH char-misc-next 3/8] misc: mic: MIC VOP Bus

2016-02-08 Thread Sudeep Dutt
On Sun, 2016-02-07 at 22:57 -0800, Greg Kroah-Hartman wrote:
> On Mon, Feb 01, 2016 at 08:23:40PM -0800, Sudeep Dutt wrote:
> > The Virtio Over PCIe (VOP) bus abstracts the low level hardware
> > details like interrupts and mapping remote memory so that the same VOP
> > driver can work without changes with different MIC host or card
> > drivers as long as the hardware bus operations are implemented. The
> > VOP driver registers itself on the VOP bus. The base PCIe drivers
> > implement the bus ops and register VOP devices on the bus, resulting
> > in the VOP driver being probed with the VOP devices. This allows the
> > VOP functionality to be shared between multiple generations of Intel
> > MIC products.
> > 
> > Reviewed-by: Ashutosh Dixit 
> > Signed-off-by: Sudeep Dutt 
> > ---
> >  drivers/misc/mic/Kconfig   |  17 
> >  drivers/misc/mic/bus/Makefile  |   1 +
> >  drivers/misc/mic/bus/vop_bus.h | 142 
> >  drivers/misc/mic/bus/vop_bus.c | 204 
> > +
> >  4 files changed, 364 insertions(+)
> >  create mode 100644 drivers/misc/mic/bus/vop_bus.h
> >  create mode 100644 drivers/misc/mic/bus/vop_bus.c
> > 
> > diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
> > index 40677df..840f7ef 100644
> > --- a/drivers/misc/mic/Kconfig
> > +++ b/drivers/misc/mic/Kconfig
> > @@ -32,6 +32,23 @@ config SCIF_BUS
> >   OS and tools for MIC to use with this driver are available from
> >   <http://software.intel.com/en-us/mic-developer>.
> >  
> > +comment "VOP Bus Driver"
> > +
> > +config VOP_BUS
> > +   tristate "VOP Bus Driver"
> > +   depends on 64BIT && PCI && X86 && X86_DEV_DMA_OPS
> > +   help
> > + This option is selected by any driver which registers a
> > + device or driver on the VOP Bus, such as CONFIG_INTEL_MIC_HOST
> > + and CONFIG_INTEL_MIC_CARD.
> > +
> > + If you are building a host/card kernel with an Intel MIC device
> > + then say M (recommended) or Y, else say N. If unsure say N.
> > +
> > + More information about the Intel MIC family as well as the Linux
> > + OS and tools for MIC to use with this driver are available from
> > + <http://software.intel.com/en-us/mic-developer>.
> > +
> >  comment "Intel MIC Host Driver"
> >  
> >  config INTEL_MIC_HOST
> > diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
> > index 761842b..8758a7d 100644
> > --- a/drivers/misc/mic/bus/Makefile
> > +++ b/drivers/misc/mic/bus/Makefile
> > @@ -5,3 +5,4 @@
> >  obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
> >  obj-$(CONFIG_SCIF_BUS) += scif_bus.o
> >  obj-$(CONFIG_MIC_COSM) += cosm_bus.o
> > +obj-$(CONFIG_VOP_BUS) += vop_bus.o
> > diff --git a/drivers/misc/mic/bus/vop_bus.h b/drivers/misc/mic/bus/vop_bus.h
> > new file mode 100644
> > index 000..97fa5d6
> > --- /dev/null
> > +++ b/drivers/misc/mic/bus/vop_bus.h
> > @@ -0,0 +1,142 @@
> > +/*
> > + * Intel MIC Platform Software Stack (MPSS)
> > + *
> > + * Copyright(c) 2016 Intel Corporation.
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License, version 2, as
> > + * published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful, but
> > + * WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > + * General Public License for more details.
> > + *
> > + * The full GNU General Public License is included in this distribution in
> > + * the file called "COPYING".
> > + *
> > + * Intel Virtio over PCIe Bus driver.
> > + */
> > +#ifndef _VOP_BUS_H_
> > +#define _VOP_BUS_H_
> > +/*
> > + * Everything a vop driver needs to work with any particular vop
> > + * implementation.
> > + */
> > +#include 
> > +#include 
> > +
> > +#include "../common/mic_dev.h"
> > +
> > +struct vop_device_id {
> > +   u32 device;
> > +   u32 vendor;
> > +};
> > +
> > +#define VOP_DEV_TRNSP 1
> > +#define VOP_DEV_ANY_ID 0x
> > +/*
> > + * Size of the internal buffer used during DMA's as an intermediate buffer
> > + * for copy to/from user. Must be an integral number of pages.
> > + */
> > +#def

Re: [PATCH char-misc-next 3/8] misc: mic: MIC VOP Bus

2016-02-08 Thread Sudeep Dutt
On Sun, 2016-02-07 at 22:57 -0800, Greg Kroah-Hartman wrote:
> On Mon, Feb 01, 2016 at 08:23:40PM -0800, Sudeep Dutt wrote:
> > The Virtio Over PCIe (VOP) bus abstracts the low level hardware
> > details like interrupts and mapping remote memory so that the same VOP
> > driver can work without changes with different MIC host or card
> > drivers as long as the hardware bus operations are implemented. The
> > VOP driver registers itself on the VOP bus. The base PCIe drivers
> > implement the bus ops and register VOP devices on the bus, resulting
> > in the VOP driver being probed with the VOP devices. This allows the
> > VOP functionality to be shared between multiple generations of Intel
> > MIC products.
> > 
> > Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
> > Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
> > ---
> >  drivers/misc/mic/Kconfig   |  17 
> >  drivers/misc/mic/bus/Makefile  |   1 +
> >  drivers/misc/mic/bus/vop_bus.h | 142 
> >  drivers/misc/mic/bus/vop_bus.c | 204 
> > +
> >  4 files changed, 364 insertions(+)
> >  create mode 100644 drivers/misc/mic/bus/vop_bus.h
> >  create mode 100644 drivers/misc/mic/bus/vop_bus.c
> > 
> > diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
> > index 40677df..840f7ef 100644
> > --- a/drivers/misc/mic/Kconfig
> > +++ b/drivers/misc/mic/Kconfig
> > @@ -32,6 +32,23 @@ config SCIF_BUS
> >   OS and tools for MIC to use with this driver are available from
> >   <http://software.intel.com/en-us/mic-developer>.
> >  
> > +comment "VOP Bus Driver"
> > +
> > +config VOP_BUS
> > +   tristate "VOP Bus Driver"
> > +   depends on 64BIT && PCI && X86 && X86_DEV_DMA_OPS
> > +   help
> > + This option is selected by any driver which registers a
> > + device or driver on the VOP Bus, such as CONFIG_INTEL_MIC_HOST
> > + and CONFIG_INTEL_MIC_CARD.
> > +
> > + If you are building a host/card kernel with an Intel MIC device
> > + then say M (recommended) or Y, else say N. If unsure say N.
> > +
> > + More information about the Intel MIC family as well as the Linux
> > + OS and tools for MIC to use with this driver are available from
> > + <http://software.intel.com/en-us/mic-developer>.
> > +
> >  comment "Intel MIC Host Driver"
> >  
> >  config INTEL_MIC_HOST
> > diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
> > index 761842b..8758a7d 100644
> > --- a/drivers/misc/mic/bus/Makefile
> > +++ b/drivers/misc/mic/bus/Makefile
> > @@ -5,3 +5,4 @@
> >  obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
> >  obj-$(CONFIG_SCIF_BUS) += scif_bus.o
> >  obj-$(CONFIG_MIC_COSM) += cosm_bus.o
> > +obj-$(CONFIG_VOP_BUS) += vop_bus.o
> > diff --git a/drivers/misc/mic/bus/vop_bus.h b/drivers/misc/mic/bus/vop_bus.h
> > new file mode 100644
> > index 000..97fa5d6
> > --- /dev/null
> > +++ b/drivers/misc/mic/bus/vop_bus.h
> > @@ -0,0 +1,142 @@
> > +/*
> > + * Intel MIC Platform Software Stack (MPSS)
> > + *
> > + * Copyright(c) 2016 Intel Corporation.
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License, version 2, as
> > + * published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful, but
> > + * WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > + * General Public License for more details.
> > + *
> > + * The full GNU General Public License is included in this distribution in
> > + * the file called "COPYING".
> > + *
> > + * Intel Virtio over PCIe Bus driver.
> > + */
> > +#ifndef _VOP_BUS_H_
> > +#define _VOP_BUS_H_
> > +/*
> > + * Everything a vop driver needs to work with any particular vop
> > + * implementation.
> > + */
> > +#include 
> > +#include 
> > +
> > +#include "../common/mic_dev.h"
> > +
> > +struct vop_device_id {
> > +   u32 device;
> > +   u32 vendor;
> > +};
> > +
> > +#define VOP_DEV_TRNSP 1
> > +#define VOP_DEV_ANY_ID 0x
> > +/*
> > + * Size of the internal buffer used during DMA's as an intermediate buffer
> > + * for copy to/from user. Must b

[PATCH char-misc-testing v2 1/8] misc: mic: Remove MIC X100 host virtio functionality

2016-02-08 Thread Sudeep Dutt
This patch deletes the virtio functionality from the MIC X100 host
driver. A subsequent patch will re-enable this functionality by
consolidating the hardware independent logic in a new Virtio over PCIe
(VOP) driver.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/host/Makefile  |   2 -
 drivers/misc/mic/host/mic_device.h  |   6 -
 drivers/misc/mic/host/mic_fops.h|  32 --
 drivers/misc/mic/host/mic_virtio.h  | 155 ---
 drivers/misc/mic/host/mic_boot.c|   2 -
 drivers/misc/mic/host/mic_debugfs.c | 190 -
 drivers/misc/mic/host/mic_fops.c| 222 --
 drivers/misc/mic/host/mic_main.c|  48 +--
 drivers/misc/mic/host/mic_virtio.c  | 811 
 9 files changed, 4 insertions(+), 1464 deletions(-)
 delete mode 100644 drivers/misc/mic/host/mic_fops.h
 delete mode 100644 drivers/misc/mic/host/mic_virtio.h
 delete mode 100644 drivers/misc/mic/host/mic_fops.c
 delete mode 100644 drivers/misc/mic/host/mic_virtio.c

diff --git a/drivers/misc/mic/host/Makefile b/drivers/misc/mic/host/Makefile
index 004d3db..f3b5023 100644
--- a/drivers/misc/mic/host/Makefile
+++ b/drivers/misc/mic/host/Makefile
@@ -9,5 +9,3 @@ mic_host-objs += mic_smpt.o
 mic_host-objs += mic_intr.o
 mic_host-objs += mic_boot.o
 mic_host-objs += mic_debugfs.o
-mic_host-objs += mic_fops.o
-mic_host-objs += mic_virtio.o
diff --git a/drivers/misc/mic/host/mic_device.h 
b/drivers/misc/mic/host/mic_device.h
index 461184a..8460de1 100644
--- a/drivers/misc/mic/host/mic_device.h
+++ b/drivers/misc/mic/host/mic_device.h
@@ -64,9 +64,6 @@ extern struct cosm_hw_ops cosm_hw_ops;
  * @bootaddr: MIC boot address.
  * @dp: virtio device page
  * @dp_dma_addr: virtio device page DMA address.
- * @name: name for the misc char device
- * @miscdev: registered misc char device
- * @vdev_list: list of virtio devices.
  * @dma_mbdev: MIC BUS DMA device.
  * @dma_ch - Array of DMA channels
  * @num_dma_ch - Number of DMA channels available
@@ -91,9 +88,6 @@ struct mic_device {
u32 bootaddr;
void *dp;
dma_addr_t dp_dma_addr;
-   char name[16];
-   struct miscdevice miscdev;
-   struct list_head vdev_list;
struct mbus_device *dma_mbdev;
struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN];
int num_dma_ch;
diff --git a/drivers/misc/mic/host/mic_fops.h b/drivers/misc/mic/host/mic_fops.h
deleted file mode 100644
index dc3893d..000
--- a/drivers/misc/mic/host/mic_fops.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Intel MIC Host driver.
- *
- */
-#ifndef _MIC_FOPS_H_
-#define _MIC_FOPS_H_
-
-int mic_open(struct inode *inode, struct file *filp);
-int mic_release(struct inode *inode, struct file *filp);
-ssize_t mic_read(struct file *filp, char __user *buf,
-   size_t count, loff_t *pos);
-long mic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
-int mic_mmap(struct file *f, struct vm_area_struct *vma);
-unsigned int mic_poll(struct file *f, poll_table *wait);
-
-#endif
diff --git a/drivers/misc/mic/host/mic_virtio.h 
b/drivers/misc/mic/host/mic_virtio.h
deleted file mode 100644
index a80631f..000
--- a/drivers/misc/mic/host/mic_virtio.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Intel MIC Host driver.
- *
- */
-#ifndef MIC_VIRTIO_H
-#define MIC_VIRTIO_H
-
-#include 
-#include 
-
-/*
- * Note on endianness.
- * 1. Host can be both BE or LE
- * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
- *rings and ioreadXX/iowriteXX to access used ring.
- * 3. Device page exposed by host to guest contains LE values. Guest
- *accesse

[PATCH char-misc-testing v2 5/8] misc: mic: Enable VOP host side functionality

2016-02-08 Thread Sudeep Dutt
This patch moves virtio functionality from the MIC host driver into a
separate hardware independent Virtio Over PCIe (VOP) driver. This
functionality was introduced in commit f69bcbf3b4c4 ("Intel MIC Host
Driver Changes for Virtio Devices.") in
drivers/misc/mic/host/mic_virtio.c. Apart from being moved into a
separate driver the functionality is essentially unchanged. See the
above mentioned commit for a description of this functionality.

Signed-off-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/vop/vop_vringh.c | 1164 +
 1 file changed, 1164 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_vringh.c

diff --git a/drivers/misc/mic/vop/vop_vringh.c 
b/drivers/misc/mic/vop/vop_vringh.c
new file mode 100644
index 000..c1dd000
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_vringh.c
@@ -0,0 +1,1164 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+#include 
+
+#include 
+#include "../common/mic_dev.h"
+
+#include 
+#include "vop_main.h"
+
+/* Helper API to obtain the VOP PCIe device */
+static inline struct device *vop_dev(struct vop_vdev *vdev)
+{
+   return vdev->vpdev->dev.parent;
+}
+
+/* Helper API to check if a virtio device is initialized */
+static inline int vop_vdev_inited(struct vop_vdev *vdev)
+{
+   if (!vdev)
+   return -EINVAL;
+   /* Device has not been created yet */
+   if (!vdev->dd || !vdev->dd->type) {
+   dev_err(vop_dev(vdev), "%s %d err %d\n",
+   __func__, __LINE__, -EINVAL);
+   return -EINVAL;
+   }
+   /* Device has been removed/deleted */
+   if (vdev->dd->type == -1) {
+   dev_dbg(vop_dev(vdev), "%s %d err %d\n",
+   __func__, __LINE__, -ENODEV);
+   return -ENODEV;
+   }
+   return 0;
+}
+
+static void _vop_notify(struct vringh *vrh)
+{
+   struct vop_vringh *vvrh = container_of(vrh, struct vop_vringh, vrh);
+   struct vop_vdev *vdev = vvrh->vdev;
+   struct vop_device *vpdev = vdev->vpdev;
+   s8 db = vdev->dc->h2c_vdev_db;
+
+   if (db != -1)
+   vpdev->hw_ops->send_intr(vpdev, db);
+}
+
+static void vop_virtio_init_post(struct vop_vdev *vdev)
+{
+   struct mic_vqconfig *vqconfig = mic_vq_config(vdev->dd);
+   struct vop_device *vpdev = vdev->vpdev;
+   int i, used_size;
+
+   for (i = 0; i < vdev->dd->num_vq; i++) {
+   used_size = PAGE_ALIGN(sizeof(u16) * 3 +
+   sizeof(struct vring_used_elem) *
+   le16_to_cpu(vqconfig->num));
+   if (!le64_to_cpu(vqconfig[i].used_address)) {
+   dev_warn(vop_dev(vdev), "used_address zero??\n");
+   continue;
+   }
+   vdev->vvr[i].vrh.vring.used =
+   (void __force *)vpdev->hw_ops->ioremap(
+   vpdev,
+   le64_to_cpu(vqconfig[i].used_address),
+   used_size);
+   }
+
+   vdev->dc->used_address_updated = 0;
+
+   dev_info(vop_dev(vdev), "%s: device type %d LINKUP\n",
+__func__, vdev->virtio_id);
+}
+
+static inline void vop_virtio_device_reset(struct vop_vdev *vdev)
+{
+   int i;
+
+   dev_dbg(vop_dev(vdev), "%s: status %d device type %d RESET\n",
+   __func__, vdev->dd->status, vdev->virtio_id);
+
+   for (i = 0; i < vdev->dd->num_vq; i++)
+   /*
+* Avoid lockdep false positive. The + 1 is for the vop
+* mutex which is held in the reset devices code path.
+*/
+   mutex_lock_nested(>vvr[i].vr_mutex, i + 1);
+
+   /* 0 status means "reset" */
+   vdev->dd->status = 0;
+   vdev->dc->vdev_reset = 0;
+   vdev->dc->host_ack = 1;
+
+   for (i = 0; i < vdev->dd->num_vq; i++) {
+   struct vringh *vrh = >vvr[i].vrh;
+
+   vdev->vvr[i].vring.info->avail_i

[PATCH char-misc-testing v2 6/8] misc: mic: Enable VOP card side functionality

2016-02-08 Thread Sudeep Dutt
From: Ashutosh Dixit <ashutosh.di...@intel.com>

This patch moves virtio functionality from the MIC card driver into a
separate hardware independent Virtio Over PCIe (VOP) driver. This
functionality was introduced in commit 2141c7c5ee67 ("Intel MIC Card
Driver Changes for Virtio Devices.") in
drivers/misc/mic/card/mic_virtio.c. Apart from being moved into a
separate driver the functionality is essentially unchanged. See the
above mentioned commit for a description of this functionality.

Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
Signed-off-by: Ashutosh Dixit <ashutosh.di...@intel.com>
---
 drivers/misc/mic/vop/vop_main.c | 755 
 1 file changed, 755 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_main.c

diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
new file mode 100644
index 000..1a2b67f
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_main.c
@@ -0,0 +1,755 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Adapted from:
+ *
+ * virtio for kvm on s390
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Christian Borntraeger <borntrae...@de.ibm.com>
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+
+#include "vop_main.h"
+
+#define VOP_MAX_VRINGS 4
+
+/*
+ * _vop_vdev - Allocated per virtio device instance injected by the peer.
+ *
+ * @vdev: Virtio device
+ * @desc: Virtio device page descriptor
+ * @dc: Virtio device control
+ * @vpdev: VOP device which is the parent for this virtio device
+ * @vr: Buffer for accessing the VRING
+ * @used: Buffer for used
+ * @used_size: Size of the used buffer
+ * @reset_done: Track whether VOP reset is complete
+ * @virtio_cookie: Cookie returned upon requesting a interrupt
+ * @c2h_vdev_db: The doorbell used by the guest to interrupt the host
+ * @h2c_vdev_db: The doorbell used by the host to interrupt the guest
+ * @dnode: The destination node
+ */
+struct _vop_vdev {
+   struct virtio_device vdev;
+   struct mic_device_desc __iomem *desc;
+   struct mic_device_ctrl __iomem *dc;
+   struct vop_device *vpdev;
+   void __iomem *vr[VOP_MAX_VRINGS];
+   dma_addr_t used[VOP_MAX_VRINGS];
+   int used_size[VOP_MAX_VRINGS];
+   struct completion reset_done;
+   struct mic_irq *virtio_cookie;
+   int c2h_vdev_db;
+   int h2c_vdev_db;
+   int dnode;
+};
+
+#define to_vopvdev(vd) container_of(vd, struct _vop_vdev, vdev)
+
+#define _vop_aligned_desc_size(d) __mic_align(_vop_desc_size(d), 8)
+
+/* Helper API to obtain the parent of the virtio device */
+static inline struct device *_vop_dev(struct _vop_vdev *vdev)
+{
+   return vdev->vdev.dev.parent;
+}
+
+static inline unsigned _vop_desc_size(struct mic_device_desc __iomem *desc)
+{
+   return sizeof(*desc)
+   + ioread8(>num_vq) * sizeof(struct mic_vqconfig)
+   + ioread8(>feature_len) * 2
+   + ioread8(>config_len);
+}
+
+static inline struct mic_vqconfig __iomem *
+_vop_vq_config(struct mic_device_desc __iomem *desc)
+{
+   return (struct mic_vqconfig __iomem *)(desc + 1);
+}
+
+static inline u8 __iomem *
+_vop_vq_features(struct mic_device_desc __iomem *desc)
+{
+   return (u8 __iomem *)(_vop_vq_config(desc) + ioread8(>num_vq));
+}
+
+static inline u8 __iomem *
+_vop_vq_configspace(struct mic_device_desc __iomem *desc)
+{
+   return _vop_vq_features(desc) + ioread8(>feature_len) * 2;
+}
+
+static inline unsigned
+_vop_total_desc_size(struct mic_device_desc __iomem *desc)
+{
+   return _vop_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
+}
+
+/* This gets the device's feature bits. */
+static u64 vop_get_features(struct virtio_device *vdev)
+{
+   unsigned int i, bits;
+   u32 features = 0;
+   struct mic_device_desc __iomem *desc = to_vopvdev(vdev)->desc;
+   u8 __iomem *in_features = _vop_vq_features(desc);
+   int feature_len = ioread8(>feature_len);
+
+   bits = min_t(unsigned, feature_len, sizeof(vdev->features)) * 8;
+   for 

[PATCH char-misc-testing v2 7/8] misc: mic: Enable VOP debugfs and driver build

2016-02-08 Thread Sudeep Dutt
This patch moves the virtio specific debugfs hooks previously in
mic_debugfs.c in the MIC host driver into the VOP driver. The
Kconfig/Makefile is also updated to allow building the VOP driver.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/Kconfig   |  20 
 drivers/misc/mic/Makefile  |   1 +
 drivers/misc/mic/vop/Makefile  |   9 ++
 drivers/misc/mic/vop/vop_debugfs.c | 232 +
 4 files changed, 262 insertions(+)
 create mode 100644 drivers/misc/mic/vop/Makefile
 create mode 100644 drivers/misc/mic/vop/vop_debugfs.c

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 840f7ef..b03bb17 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -124,3 +124,23 @@ config MIC_COSM
  More information about the Intel MIC family as well as the Linux
  OS and tools for MIC to use with this driver are available from
  <http://software.intel.com/en-us/mic-developer>.
+
+comment "VOP Driver"
+
+config VOP
+   tristate "VOP Driver"
+   depends on 64BIT && PCI && X86 && VOP_BUS
+   select VHOST_RING
+   help
+ This enables VOP (Virtio over PCIe) Driver support for the Intel
+ Many Integrated Core (MIC) family of PCIe form factor coprocessor
+ devices. The VOP driver allows virtio drivers, e.g. net, console
+ and block drivers, on the card connect to user space virtio
+ devices on the host.
+
+ If you are building a host kernel with an Intel MIC device then
+ say M (recommended) or Y, else say N. If unsure say N.
+
+ More information about the Intel MIC family as well as the Linux
+ OS and tools for MIC to use with this driver are available from
+ <http://software.intel.com/en-us/mic-developer>.
diff --git a/drivers/misc/mic/Makefile b/drivers/misc/mic/Makefile
index e288a11..f2b1323 100644
--- a/drivers/misc/mic/Makefile
+++ b/drivers/misc/mic/Makefile
@@ -8,3 +8,4 @@ obj-y += bus/
 obj-$(CONFIG_SCIF) += scif/
 obj-$(CONFIG_MIC_COSM) += cosm/
 obj-$(CONFIG_MIC_COSM) += cosm_client/
+obj-$(CONFIG_VOP) += vop/
diff --git a/drivers/misc/mic/vop/Makefile b/drivers/misc/mic/vop/Makefile
new file mode 100644
index 000..78819c8
--- /dev/null
+++ b/drivers/misc/mic/vop/Makefile
@@ -0,0 +1,9 @@
+#
+# Makefile - Intel MIC Linux driver.
+# Copyright(c) 2016, Intel Corporation.
+#
+obj-m := vop.o
+
+vop-objs += vop_main.o
+vop-objs += vop_debugfs.o
+vop-objs += vop_vringh.o
diff --git a/drivers/misc/mic/vop/vop_debugfs.c 
b/drivers/misc/mic/vop/vop_debugfs.c
new file mode 100644
index 000..ab43884
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_debugfs.c
@@ -0,0 +1,232 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+
+#include "vop_main.h"
+
+static int vop_dp_show(struct seq_file *s, void *pos)
+{
+   struct mic_device_desc *d;
+   struct mic_device_ctrl *dc;
+   struct mic_vqconfig *vqconfig;
+   __u32 *features;
+   __u8 *config;
+   struct vop_info *vi = s->private;
+   struct vop_device *vpdev = vi->vpdev;
+   struct mic_bootparam *bootparam = vpdev->hw_ops->get_dp(vpdev);
+   int j, k;
+
+   seq_printf(s, "Bootparam: magic 0x%x\n",
+  bootparam->magic);
+   seq_printf(s, "Bootparam: h2c_config_db %d\n",
+  bootparam->h2c_config_db);
+   seq_printf(s, "Bootparam: node_id %d\n",
+  bootparam->node_id);
+   seq_printf(s, "Bootparam: c2h_scif_db %d\n",
+  bootparam->c2h_scif_db);
+   seq_printf(s, "Bootparam: h2c_scif_db %d\n",
+  bootparam->h2c_scif_db);
+   seq_printf(s, "Bootparam: scif_host_dma_addr 0x%llx\n",
+  bootparam->scif_host_dma_addr);
+   seq_printf(s, "Bootparam: scif_card_dma_addr 0x%llx\n",
+  bootparam->scif_card_dma_addr);
+
+   for (j = sizeof(*bootparam);
+   j < MIC_DP_SIZE; j += mic_total_desc_size(d)) {
+   d = (void *)bootparam + j;
+

[PATCH char-misc-testing v2 8/8] misc: mic: MIC host and card driver changes to enable VOP

2016-02-08 Thread Sudeep Dutt
This patch modifies the MIC host and card drivers to start using the
VOP driver. The MIC host and card drivers now implement the VOP bus
operations and register a VOP device on the VOP bus. MIC driver stack
documentation is also updated to include the new VOP driver.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 Documentation/mic/mic_overview.txt |  54 
 drivers/misc/mic/Kconfig   |   7 ++-
 drivers/misc/mic/card/mic_device.h |   3 +
 drivers/misc/mic/host/mic_device.h |   3 +
 Documentation/mic/mpssd/mpssd.c|   2 +-
 drivers/misc/mic/card/mic_device.c |  84 -
 drivers/misc/mic/card/mic_x100.c   |   1 +
 drivers/misc/mic/host/mic_boot.c   | 123 -
 drivers/misc/mic/host/mic_main.c   |   1 +
 Documentation/mic/mpssd/mpss   |   2 +-
 10 files changed, 247 insertions(+), 33 deletions(-)

diff --git a/Documentation/mic/mic_overview.txt 
b/Documentation/mic/mic_overview.txt
index 73f44fc..074adbd 100644
--- a/Documentation/mic/mic_overview.txt
+++ b/Documentation/mic/mic_overview.txt
@@ -12,10 +12,19 @@ for the X100 devices.
 
 Since it is a PCIe card, it does not have the ability to host hardware
 devices for networking, storage and console. We provide these devices
-on X100 coprocessors thus enabling a self-bootable equivalent environment
-for applications. A key benefit of our solution is that it leverages
-the standard virtio framework for network, disk and console devices,
-though in our case the virtio framework is used across a PCIe bus.
+on X100 coprocessors thus enabling a self-bootable equivalent
+environment for applications. A key benefit of our solution is that it
+leverages the standard virtio framework for network, disk and console
+devices, though in our case the virtio framework is used across a PCIe
+bus. A Virtio Over PCIe (VOP) driver allows creating user space
+backends or devices on the host which are used to probe virtio drivers
+for these devices on the MIC card. The existing VRINGH infrastructure
+in the kernel is used to access virtio rings from the host. The card
+VOP driver allows card virtio drivers to communicate with their user
+space backends on the host via a device page. Ring 3 apps on the host
+can add, remove and configure virtio devices. A thin MIC specific
+virtio_config_ops is implemented which is borrowed heavily from
+previous similar implementations in lguest and s390.
 
 MIC PCIe card has a dma controller with 8 channels. These channels are
 shared between the host s/w and the card s/w. 0 to 3 are used by host
@@ -38,7 +47,6 @@ single threaded performance for the host compared to MIC, the 
ability of
 the host to initiate DMA's to/from the card using the MIC DMA engine and
 the fact that the virtio block storage backend can only be on the host.
 
-  |
+--+   | +--+
| Card OS  |   | | Host OS  |
+--+   | +--+
@@ -47,27 +55,25 @@ the fact that the virtio block storage backend can only be 
on the host.
 | Virtio| |Virtio  | |Virtio| | |Virtio   |  |Virtio  | |Virtio  |
 | Net   | |Console | |Block | | |Net  |  |Console | |Block   |
 | Driver| |Driver  | |Driver| | |backend  |  |backend | |backend |
-+---+ ++ +--+ | +-+  ++ ++
++---+---+ +---++ +--+---+ | +-+  ++---+ ++
 | | | |  || |
 | | | |User  || |
-| | | |--||-|---
-+---+ |Kernel +--+
-  |   |   | Virtio over PCIe IOCTLs  |
-  |   |   +--+
-+---+ |   |   |  +---+
-| MIC DMA   | |  +--+ | +--+ +--+ |  | MIC DMA   |
-| Driver| |  | SCIF | | | SCIF | | COSM | |  | Driver|
-+---+ |  +--+ | +--+ +--+---+ |  +---+
-  |   | | ||| ||
-+---+ |  +--+ | +--+---+ +--+---+ | ++
-|MIC virtual Bus| |  |SCIF  | | |SCIF  | | COSM | | |MIC virtual Bus |
-+---+ |  |HW Bus| | |HW Bus| | Bus  | | ++
-  |   |  +--+ | +--+---+ +--+ |  |
-  |   | | |   | | |  |
-  |   +---+---+ | |   |+---+ |
-  |   |Intel MIC  | | |   ||Intel MIC  | |
-  +---

[PATCH char-misc-testing v2 3/8] misc: mic: MIC VOP Bus

2016-02-08 Thread Sudeep Dutt
The Virtio Over PCIe (VOP) bus abstracts the low level hardware
details like interrupts and mapping remote memory so that the same VOP
driver can work without changes with different MIC host or card
drivers as long as the hardware bus operations are implemented. The
VOP driver registers itself on the VOP bus. The base PCIe drivers
implement the bus ops and register VOP devices on the bus, resulting
in the VOP driver being probed with the VOP devices. This allows the
VOP functionality to be shared between multiple generations of Intel
MIC products.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/Kconfig   |  17 
 drivers/misc/mic/bus/Makefile  |   1 +
 drivers/misc/mic/bus/vop_bus.h | 140 
 drivers/misc/mic/bus/vop_bus.c | 203 +
 4 files changed, 361 insertions(+)
 create mode 100644 drivers/misc/mic/bus/vop_bus.h
 create mode 100644 drivers/misc/mic/bus/vop_bus.c

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 40677df..840f7ef 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -32,6 +32,23 @@ config SCIF_BUS
  OS and tools for MIC to use with this driver are available from
  <http://software.intel.com/en-us/mic-developer>.
 
+comment "VOP Bus Driver"
+
+config VOP_BUS
+   tristate "VOP Bus Driver"
+   depends on 64BIT && PCI && X86 && X86_DEV_DMA_OPS
+   help
+ This option is selected by any driver which registers a
+ device or driver on the VOP Bus, such as CONFIG_INTEL_MIC_HOST
+ and CONFIG_INTEL_MIC_CARD.
+
+ If you are building a host/card kernel with an Intel MIC device
+ then say M (recommended) or Y, else say N. If unsure say N.
+
+ More information about the Intel MIC family as well as the Linux
+ OS and tools for MIC to use with this driver are available from
+ <http://software.intel.com/en-us/mic-developer>.
+
 comment "Intel MIC Host Driver"
 
 config INTEL_MIC_HOST
diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
index 761842b..8758a7d 100644
--- a/drivers/misc/mic/bus/Makefile
+++ b/drivers/misc/mic/bus/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
 obj-$(CONFIG_SCIF_BUS) += scif_bus.o
 obj-$(CONFIG_MIC_COSM) += cosm_bus.o
+obj-$(CONFIG_VOP_BUS) += vop_bus.o
diff --git a/drivers/misc/mic/bus/vop_bus.h b/drivers/misc/mic/bus/vop_bus.h
new file mode 100644
index 000..fff7a86
--- /dev/null
+++ b/drivers/misc/mic/bus/vop_bus.h
@@ -0,0 +1,140 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio over PCIe Bus driver.
+ */
+#ifndef _VOP_BUS_H_
+#define _VOP_BUS_H_
+/*
+ * Everything a vop driver needs to work with any particular vop
+ * implementation.
+ */
+#include 
+#include 
+
+#include "../common/mic_dev.h"
+
+struct vop_device_id {
+   u32 device;
+   u32 vendor;
+};
+
+#define VOP_DEV_TRNSP 1
+#define VOP_DEV_ANY_ID 0x
+/*
+ * Size of the internal buffer used during DMA's as an intermediate buffer
+ * for copy to/from user. Must be an integral number of pages.
+ */
+#define VOP_INT_DMA_BUF_SIZE PAGE_ALIGN(64 * 1024ULL)
+
+/**
+ * vop_device - representation of a device using vop
+ * @hw_ops: the hardware ops supported by this device.
+ * @id: the device type identification (used to match it with a driver).
+ * @dev: underlying device.
+ * @dnode - The destination node which this device will communicate with.
+ * @aper: Aperture memory window
+ * @dma_ch - DMA channel
+ * @index: unique position on the vop bus
+ */
+struct vop_device {
+   struct vop_hw_ops *hw_ops;
+   struct vop_device_id id;
+   struct device dev;
+   u8 dnode;
+   struct mic_mw *aper;
+   struct dma_chan *dma_ch;
+   int index;
+};
+
+/**
+ * vop_driver - operations for a vop I/O driver
+ * @driver: underlying device driver (populate name and owner).
+ * @id_table: the ids serviced by this driver.
+ * @probe: the function to call when a device is found.  Returns 0 or -errno.
+ * @remove: the function to call when a device is removed.
+ */
+struct vop_driver {
+   struct device_driver driver;
+   const struct vop_device_id

[PATCH char-misc-testing v2 4/8] misc: mic: Add data structures for the VOP driver

2016-02-08 Thread Sudeep Dutt
This patch adds VOP driver data structures used in subsequent
patches. These data structures are refactored from similar data
structures used in the virtio parts of previous MIC host and card
drivers.

Signed-off-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/vop/vop_main.h | 170 
 1 file changed, 170 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_main.h

diff --git a/drivers/misc/mic/vop/vop_main.h b/drivers/misc/mic/vop/vop_main.h
new file mode 100644
index 000..ba47ec7
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_main.h
@@ -0,0 +1,170 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#ifndef _VOP_MAIN_H_
+#define _VOP_MAIN_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "../common/mic_dev.h"
+
+#include "../bus/vop_bus.h"
+
+/*
+ * Note on endianness.
+ * 1. Host can be both BE or LE
+ * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
+ *rings and ioreadXX/iowriteXX to access used ring.
+ * 3. Device page exposed by host to guest contains LE values. Guest
+ *accesses these using ioreadXX/iowriteXX etc. This way in general we
+ *obey the virtio spec according to which guest works with native
+ *endianness and host is aware of guest endianness and does all
+ *required endianness conversion.
+ * 4. Data provided from user space to guest (in ADD_DEVICE and
+ *CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
+ *in guest endianness.
+ */
+
+/*
+ * vop_info - Allocated per invocation of VOP probe
+ *
+ * @vpdev: VOP device
+ * @hotplug_work: Handle virtio device creation, deletion and configuration
+ * @cookie: Cookie received upon requesting a virtio configuration interrupt
+ * @h2c_config_db: The doorbell used by the peer to indicate a config change
+ * @vdev_list: List of "active" virtio devices injected in the peer node
+ * @vop_mutex: Synchronize access to the device page as well as serialize
+ * creation/deletion of virtio devices on the peer node
+ * @dp: Peer device page information
+ * @dbg: Debugfs entry
+ * @dma_ch: The DMA channel used by this transport for data transfers.
+ * @name: Name for this transport used in misc device creation.
+ * @miscdev: The misc device registered.
+ */
+struct vop_info {
+   struct vop_device *vpdev;
+   struct work_struct hotplug_work;
+   struct mic_irq *cookie;
+   int h2c_config_db;
+   struct list_head vdev_list;
+   struct mutex vop_mutex;
+   void __iomem *dp;
+   struct dentry *dbg;
+   struct dma_chan *dma_ch;
+   char name[16];
+   struct miscdevice miscdev;
+};
+
+/**
+ * struct vop_vringh - Virtio ring host information.
+ *
+ * @vring: The VOP vring used for setting up user space mappings.
+ * @vrh: The host VRINGH used for accessing the card vrings.
+ * @riov: The VRINGH read kernel IOV.
+ * @wiov: The VRINGH write kernel IOV.
+ * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
+ * @vr_mutex: Mutex for synchronizing access to the VRING.
+ * @buf: Temporary kernel buffer used to copy in/out data
+ * from/to the card via DMA.
+ * @buf_da: dma address of buf.
+ * @vdev: Back pointer to VOP virtio device for vringh_notify(..).
+ */
+struct vop_vringh {
+   struct mic_vring vring;
+   struct vringh vrh;
+   struct vringh_kiov riov;
+   struct vringh_kiov wiov;
+   u16 head;
+   struct mutex vr_mutex;
+   void *buf;
+   dma_addr_t buf_da;
+   struct vop_vdev *vdev;
+};
+
+/**
+ * struct vop_vdev - Host information for a card Virtio device.
+ *
+ * @virtio_id - Virtio device id.
+ * @waitq - Waitqueue to allow ring3 apps to poll.
+ * @vpdev - pointer to VOP bus device.
+ * @poll_wake - Used for waking up threads blocked in poll.
+ * @out_bytes - Debug stats for number of bytes copied from host to card.
+ * @in_bytes - Debug stats for number of bytes copied from card to host.
+ * @out_bytes_dma - Debug stats for number of bytes copied from host to card
+ * using DMA.
+ * @in_bytes_dma - Debug stats for number of bytes copied from card to host
+ * using DMA.
+ * @tx_len_unaligned - Debug stats for number of bytes copied to the card whe

[PATCH char-misc-testing v2 0/8] Enable Virtio Over PCIe (VOP) driver

2016-02-08 Thread Sudeep Dutt
ChangeLog:
=
v1 => v2:
a) Rebased to latest char-misc-testing
b) Use default private pointer in the device structure instead of adding
   a new priv field as per feedback from Greg Kroah-Hartman

v1: Initial post @ https://lkml.org/lkml/2016/2/1/1015

Description:

This patch series moves virtio functionality from the MIC host/card
driver into a separate hardware independent Virtio Over PCIe (VOP)
driver. Apart from being moved into a separate driver the functionality
is essentially unchanged. This refactoring allows this hardware
independent logic to be shared easily across multiple generations of
MIC devices. The original commits are listed below for reference:
- commit f69bcbf3b4c4 ("Intel MIC Host Driver Changes for Virtio Devices.")
in drivers/misc/mic/host/mic_virtio.c
- commit 2141c7c5ee67 ("Intel MIC Card Driver Changes for Virtio Devices.")
in drivers/misc/mic/card/mic_virtio.c

The patch series is partitioned as follows:
1) Removes MIC X100 host virtio functionality
2) Removes MIC X100 card virtio functionality
3) Enables the Virtio Over PCIe (VOP) bus which abstracts the
   low level hardware details like interrupts and mapping remote
   memory so that the same VOP driver can work without changes
   with different MIC host or card drivers as long as the hardware
   bus operations are implemented.
4) Adds data structures for the VOP driver
5) Enables VOP host side functionality
6) Enables VOP card side functionality
7) Enables VOP debugfs and driver build
8) Implements the MIC host and card driver changes to enable VOP

Ashutosh Dixit (1):
  misc: mic: Enable VOP card side functionality

Sudeep Dutt (7):
  misc: mic: Remove MIC X100 host virtio functionality
  misc: mic: Remove MIC X100 card virtio functionality
  misc: mic: MIC VOP Bus
  misc: mic: Add data structures for the VOP driver
  misc: mic: Enable VOP host side functionality
  misc: mic: Enable VOP debugfs and driver build
  misc: mic: MIC host and card driver changes to enable VOP

 Documentation/mic/mic_overview.txt |   54 +-
 drivers/misc/mic/Kconfig   |   44 +-
 drivers/misc/mic/Makefile  |1 +
 drivers/misc/mic/bus/Makefile  |1 +
 drivers/misc/mic/card/Makefile |1 -
 drivers/misc/mic/host/Makefile |2 -
 drivers/misc/mic/vop/Makefile  |9 +
 drivers/misc/mic/bus/vop_bus.h |  140 +++
 drivers/misc/mic/card/mic_device.h |3 +
 drivers/misc/mic/card/mic_virtio.h |   76 --
 drivers/misc/mic/host/mic_device.h |9 +-
 drivers/misc/mic/host/mic_fops.h   |   32 -
 .../misc/mic/{host/mic_virtio.h => vop/vop_main.h} |  129 ++-
 Documentation/mic/mpssd/mpssd.c|2 +-
 drivers/misc/mic/bus/vop_bus.c |  203 
 drivers/misc/mic/card/mic_device.c |   89 +-
 drivers/misc/mic/card/mic_virtio.c |  634 ---
 drivers/misc/mic/card/mic_x100.c   |1 +
 drivers/misc/mic/host/mic_boot.c   |  125 ++-
 drivers/misc/mic/host/mic_debugfs.c|  190 
 drivers/misc/mic/host/mic_fops.c   |  222 
 drivers/misc/mic/host/mic_main.c   |   49 +-
 drivers/misc/mic/host/mic_virtio.c |  811 --
 drivers/misc/mic/vop/vop_debugfs.c |  232 
 drivers/misc/mic/vop/vop_main.c|  755 +
 drivers/misc/mic/vop/vop_vringh.c  | 1164 
 Documentation/mic/mpssd/mpss   |2 +-
 27 files changed, 2864 insertions(+), 2116 deletions(-)
 create mode 100644 drivers/misc/mic/vop/Makefile
 create mode 100644 drivers/misc/mic/bus/vop_bus.h
 delete mode 100644 drivers/misc/mic/card/mic_virtio.h
 delete mode 100644 drivers/misc/mic/host/mic_fops.h
 rename drivers/misc/mic/{host/mic_virtio.h => vop/vop_main.h} (58%)
 create mode 100644 drivers/misc/mic/bus/vop_bus.c
 delete mode 100644 drivers/misc/mic/card/mic_virtio.c
 delete mode 100644 drivers/misc/mic/host/mic_fops.c
 delete mode 100644 drivers/misc/mic/host/mic_virtio.c
 create mode 100644 drivers/misc/mic/vop/vop_debugfs.c
 create mode 100644 drivers/misc/mic/vop/vop_main.c
 create mode 100644 drivers/misc/mic/vop/vop_vringh.c

-- 
1.8.2.1



[PATCH char-misc-testing v2 2/8] misc: mic: Remove MIC X100 card virtio functionality

2016-02-08 Thread Sudeep Dutt
This patch deletes the virtio functionality from the MIC X100 card
driver. A subsequent patch will re-enable this functionality by
consolidating the hardware independent logic in a new Virtio over PCIe
(VOP) driver.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/card/Makefile |   1 -
 drivers/misc/mic/card/mic_virtio.h |  76 -
 drivers/misc/mic/card/mic_device.c |   9 +-
 drivers/misc/mic/card/mic_virtio.c | 634 -
 4 files changed, 1 insertion(+), 719 deletions(-)
 delete mode 100644 drivers/misc/mic/card/mic_virtio.h
 delete mode 100644 drivers/misc/mic/card/mic_virtio.c

diff --git a/drivers/misc/mic/card/Makefile b/drivers/misc/mic/card/Makefile
index 69d58be..6e9675e 100644
--- a/drivers/misc/mic/card/Makefile
+++ b/drivers/misc/mic/card/Makefile
@@ -8,4 +8,3 @@ obj-$(CONFIG_INTEL_MIC_CARD) += mic_card.o
 mic_card-y += mic_x100.o
 mic_card-y += mic_device.o
 mic_card-y += mic_debugfs.o
-mic_card-y += mic_virtio.o
diff --git a/drivers/misc/mic/card/mic_virtio.h 
b/drivers/misc/mic/card/mic_virtio.h
deleted file mode 100644
index d0407ba..000
--- a/drivers/misc/mic/card/mic_virtio.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Disclaimer: The codes contained in these modules may be specific to
- * the Intel Software Development Platform codenamed: Knights Ferry, and
- * the Intel product codenamed: Knights Corner, and are not backward
- * compatible with other Intel products. Additionally, Intel will NOT
- * support the codes or instruction set in future products.
- *
- * Intel MIC Card driver.
- *
- */
-#ifndef __MIC_CARD_VIRTIO_H
-#define __MIC_CARD_VIRTIO_H
-
-#include 
-#include "mic_device.h"
-
-/*
- * 64 bit I/O access
- */
-#ifndef ioread64
-#define ioread64 readq
-#endif
-#ifndef iowrite64
-#define iowrite64 writeq
-#endif
-
-static inline unsigned mic_desc_size(struct mic_device_desc __iomem *desc)
-{
-   return sizeof(*desc)
-   + ioread8(>num_vq) * sizeof(struct mic_vqconfig)
-   + ioread8(>feature_len) * 2
-   + ioread8(>config_len);
-}
-
-static inline struct mic_vqconfig __iomem *
-mic_vq_config(struct mic_device_desc __iomem *desc)
-{
-   return (struct mic_vqconfig __iomem *)(desc + 1);
-}
-
-static inline __u8 __iomem *
-mic_vq_features(struct mic_device_desc __iomem *desc)
-{
-   return (__u8 __iomem *)(mic_vq_config(desc) + ioread8(>num_vq));
-}
-
-static inline __u8 __iomem *
-mic_vq_configspace(struct mic_device_desc __iomem *desc)
-{
-   return mic_vq_features(desc) + ioread8(>feature_len) * 2;
-}
-static inline unsigned mic_total_desc_size(struct mic_device_desc __iomem 
*desc)
-{
-   return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
-}
-
-int mic_devices_init(struct mic_driver *mdrv);
-void mic_devices_uninit(struct mic_driver *mdrv);
-
-#endif
diff --git a/drivers/misc/mic/card/mic_device.c 
b/drivers/misc/mic/card/mic_device.c
index d0edaf7..ff03c63 100644
--- a/drivers/misc/mic/card/mic_device.c
+++ b/drivers/misc/mic/card/mic_device.c
@@ -34,7 +34,6 @@
 #include 
 #include "../common/mic_dev.h"
 #include "mic_device.h"
-#include "mic_virtio.h"
 
 static struct mic_driver *g_drv;
 
@@ -309,9 +308,6 @@ int __init mic_driver_init(struct mic_driver *mdrv)
rc = -ENODEV;
goto irq_uninit;
}
-   rc = mic_devices_init(mdrv);
-   if (rc)
-   goto dma_free;
bootparam = mdrv->dp;
node_id = ioread8(>node_id);
mdrv->scdev = scif_register_device(mdrv->dev, MIC_SCIF_DEV,
@@ -321,13 +317,11 @@ int __init mic_driver_init(struct mic_driver *mdrv)
   mdrv->num_dma_ch, true);
if (IS_ERR(mdrv->scdev)) {
rc = PTR_ERR(mdrv->scdev);
-   goto device_uninit;
+   goto dma_free;
}
mic_create_card_debug_dir(mdrv);
 done:
return rc;
-device_uninit:
-   mic_devices_uninit(mdrv);
 dma_free:
mic_free_dma_chans(mdrv);
 irq_uninit:
@@ -348,7 +342,6 @@ void mic_driver_uninit(struct mic_driver *mdrv)
 {
mic_delete_card_debug_dir(mdrv);
scif

[PATCH char-misc-next 0/8] Enable Virtio Over PCIe (VOP) driver

2016-02-01 Thread Sudeep Dutt
This patch series moves virtio functionality from the MIC host/card
driver into a separate hardware independent Virtio Over PCIe (VOP)
driver. Apart from being moved into a separate driver the functionality
is essentially unchanged. This refactoring allows this hardware
independent logic to be shared easily across multiple generations of
MIC devices. The original commits are listed below for reference:
- commit f69bcbf3b4c4 ("Intel MIC Host Driver Changes for Virtio Devices.")
in drivers/misc/mic/host/mic_virtio.c
- commit 2141c7c5ee67 ("Intel MIC Card Driver Changes for Virtio Devices.")
in drivers/misc/mic/card/mic_virtio.c

The patch series is partitioned as follows:
1) Removes MIC X100 host virtio functionality
2) Removes MIC X100 card virtio functionality
3) Enables the Virtio Over PCIe (VOP) bus which abstracts the
   low level hardware details like interrupts and mapping remote
   memory so that the same VOP driver can work without changes
   with different MIC host or card drivers as long as the hardware
   bus operations are implemented.
4) Adds data structures for the VOP driver
5) Enables VOP host side functionality
6) Enables VOP card side functionality
7) Enables VOP debugfs and driver build
8) Implements the MIC host and card driver changes to enable VOP

Ashutosh Dixit (1):
  misc: mic: Enable VOP card side functionality

Sudeep Dutt (7):
  misc: mic: Remove MIC X100 host virtio functionality
  misc: mic: Remove MIC X100 card virtio functionality
  misc: mic: MIC VOP Bus
  misc: mic: Add data structures for the VOP driver
  misc: mic: Enable VOP host side functionality
  misc: mic: Enable VOP debugfs and driver build
  misc: mic: MIC host and card driver changes to enable VOP

 Documentation/mic/mic_overview.txt |   54 +-
 drivers/misc/mic/Kconfig   |   44 +-
 drivers/misc/mic/Makefile  |1 +
 drivers/misc/mic/bus/Makefile  |1 +
 drivers/misc/mic/card/Makefile |1 -
 drivers/misc/mic/host/Makefile |2 -
 drivers/misc/mic/vop/Makefile  |9 +
 drivers/misc/mic/bus/vop_bus.h |  142 +++
 drivers/misc/mic/card/mic_device.h |3 +
 drivers/misc/mic/card/mic_virtio.h |   76 --
 drivers/misc/mic/host/mic_device.h |9 +-
 drivers/misc/mic/host/mic_fops.h   |   32 -
 .../misc/mic/{host/mic_virtio.h => vop/vop_main.h} |  129 ++-
 Documentation/mic/mpssd/mpssd.c|2 +-
 drivers/misc/mic/bus/vop_bus.c |  204 
 drivers/misc/mic/card/mic_device.c |   89 +-
 drivers/misc/mic/card/mic_virtio.c |  634 ---
 drivers/misc/mic/card/mic_x100.c   |1 +
 drivers/misc/mic/host/mic_boot.c   |  127 ++-
 drivers/misc/mic/host/mic_debugfs.c|  190 
 drivers/misc/mic/host/mic_fops.c   |  222 
 drivers/misc/mic/host/mic_main.c   |   49 +-
 drivers/misc/mic/host/mic_virtio.c |  811 --
 drivers/misc/mic/vop/vop_debugfs.c |  232 
 drivers/misc/mic/vop/vop_main.c|  755 +
 drivers/misc/mic/vop/vop_vringh.c  | 1164 
 Documentation/mic/mpssd/mpss   |2 +-
 27 files changed, 2869 insertions(+), 2116 deletions(-)
 create mode 100644 drivers/misc/mic/vop/Makefile
 create mode 100644 drivers/misc/mic/bus/vop_bus.h
 delete mode 100644 drivers/misc/mic/card/mic_virtio.h
 delete mode 100644 drivers/misc/mic/host/mic_fops.h
 rename drivers/misc/mic/{host/mic_virtio.h => vop/vop_main.h} (58%)
 create mode 100644 drivers/misc/mic/bus/vop_bus.c
 delete mode 100644 drivers/misc/mic/card/mic_virtio.c
 delete mode 100644 drivers/misc/mic/host/mic_fops.c
 delete mode 100644 drivers/misc/mic/host/mic_virtio.c
 create mode 100644 drivers/misc/mic/vop/vop_debugfs.c
 create mode 100644 drivers/misc/mic/vop/vop_main.c
 create mode 100644 drivers/misc/mic/vop/vop_vringh.c

-- 
1.8.2.1



[PATCH char-misc-next 1/8] misc: mic: Remove MIC X100 host virtio functionality

2016-02-01 Thread Sudeep Dutt
This patch deletes the virtio functionality from the MIC X100 host
driver. A subsequent patch will re-enable this functionality by
consolidating the hardware independent logic in a new Virtio over PCIe
(VOP) driver.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/host/Makefile  |   2 -
 drivers/misc/mic/host/mic_device.h  |   6 -
 drivers/misc/mic/host/mic_fops.h|  32 --
 drivers/misc/mic/host/mic_virtio.h  | 155 ---
 drivers/misc/mic/host/mic_boot.c|   2 -
 drivers/misc/mic/host/mic_debugfs.c | 190 -
 drivers/misc/mic/host/mic_fops.c| 222 --
 drivers/misc/mic/host/mic_main.c|  48 +--
 drivers/misc/mic/host/mic_virtio.c  | 811 
 9 files changed, 4 insertions(+), 1464 deletions(-)
 delete mode 100644 drivers/misc/mic/host/mic_fops.h
 delete mode 100644 drivers/misc/mic/host/mic_virtio.h
 delete mode 100644 drivers/misc/mic/host/mic_fops.c
 delete mode 100644 drivers/misc/mic/host/mic_virtio.c

diff --git a/drivers/misc/mic/host/Makefile b/drivers/misc/mic/host/Makefile
index 004d3db..f3b5023 100644
--- a/drivers/misc/mic/host/Makefile
+++ b/drivers/misc/mic/host/Makefile
@@ -9,5 +9,3 @@ mic_host-objs += mic_smpt.o
 mic_host-objs += mic_intr.o
 mic_host-objs += mic_boot.o
 mic_host-objs += mic_debugfs.o
-mic_host-objs += mic_fops.o
-mic_host-objs += mic_virtio.o
diff --git a/drivers/misc/mic/host/mic_device.h 
b/drivers/misc/mic/host/mic_device.h
index 461184a..8460de1 100644
--- a/drivers/misc/mic/host/mic_device.h
+++ b/drivers/misc/mic/host/mic_device.h
@@ -64,9 +64,6 @@ extern struct cosm_hw_ops cosm_hw_ops;
  * @bootaddr: MIC boot address.
  * @dp: virtio device page
  * @dp_dma_addr: virtio device page DMA address.
- * @name: name for the misc char device
- * @miscdev: registered misc char device
- * @vdev_list: list of virtio devices.
  * @dma_mbdev: MIC BUS DMA device.
  * @dma_ch - Array of DMA channels
  * @num_dma_ch - Number of DMA channels available
@@ -91,9 +88,6 @@ struct mic_device {
u32 bootaddr;
void *dp;
dma_addr_t dp_dma_addr;
-   char name[16];
-   struct miscdevice miscdev;
-   struct list_head vdev_list;
struct mbus_device *dma_mbdev;
struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN];
int num_dma_ch;
diff --git a/drivers/misc/mic/host/mic_fops.h b/drivers/misc/mic/host/mic_fops.h
deleted file mode 100644
index dc3893d..000
--- a/drivers/misc/mic/host/mic_fops.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Intel MIC Host driver.
- *
- */
-#ifndef _MIC_FOPS_H_
-#define _MIC_FOPS_H_
-
-int mic_open(struct inode *inode, struct file *filp);
-int mic_release(struct inode *inode, struct file *filp);
-ssize_t mic_read(struct file *filp, char __user *buf,
-   size_t count, loff_t *pos);
-long mic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
-int mic_mmap(struct file *f, struct vm_area_struct *vma);
-unsigned int mic_poll(struct file *f, poll_table *wait);
-
-#endif
diff --git a/drivers/misc/mic/host/mic_virtio.h 
b/drivers/misc/mic/host/mic_virtio.h
deleted file mode 100644
index a80631f..000
--- a/drivers/misc/mic/host/mic_virtio.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Intel MIC Host driver.
- *
- */
-#ifndef MIC_VIRTIO_H
-#define MIC_VIRTIO_H
-
-#include 
-#include 
-
-/*
- * Note on endianness.
- * 1. Host can be both BE or LE
- * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
- *rings and ioreadXX/iowriteXX to access used ring.
- * 3. Device page exposed by host to guest contains LE values. Guest
- *accesses these using ioreadXX/iowriteXX etc. This way in ge

[PATCH char-misc-next 3/8] misc: mic: MIC VOP Bus

2016-02-01 Thread Sudeep Dutt
The Virtio Over PCIe (VOP) bus abstracts the low level hardware
details like interrupts and mapping remote memory so that the same VOP
driver can work without changes with different MIC host or card
drivers as long as the hardware bus operations are implemented. The
VOP driver registers itself on the VOP bus. The base PCIe drivers
implement the bus ops and register VOP devices on the bus, resulting
in the VOP driver being probed with the VOP devices. This allows the
VOP functionality to be shared between multiple generations of Intel
MIC products.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/Kconfig   |  17 
 drivers/misc/mic/bus/Makefile  |   1 +
 drivers/misc/mic/bus/vop_bus.h | 142 
 drivers/misc/mic/bus/vop_bus.c | 204 +
 4 files changed, 364 insertions(+)
 create mode 100644 drivers/misc/mic/bus/vop_bus.h
 create mode 100644 drivers/misc/mic/bus/vop_bus.c

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 40677df..840f7ef 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -32,6 +32,23 @@ config SCIF_BUS
  OS and tools for MIC to use with this driver are available from
  <http://software.intel.com/en-us/mic-developer>.
 
+comment "VOP Bus Driver"
+
+config VOP_BUS
+   tristate "VOP Bus Driver"
+   depends on 64BIT && PCI && X86 && X86_DEV_DMA_OPS
+   help
+ This option is selected by any driver which registers a
+ device or driver on the VOP Bus, such as CONFIG_INTEL_MIC_HOST
+ and CONFIG_INTEL_MIC_CARD.
+
+ If you are building a host/card kernel with an Intel MIC device
+ then say M (recommended) or Y, else say N. If unsure say N.
+
+ More information about the Intel MIC family as well as the Linux
+ OS and tools for MIC to use with this driver are available from
+ <http://software.intel.com/en-us/mic-developer>.
+
 comment "Intel MIC Host Driver"
 
 config INTEL_MIC_HOST
diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
index 761842b..8758a7d 100644
--- a/drivers/misc/mic/bus/Makefile
+++ b/drivers/misc/mic/bus/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
 obj-$(CONFIG_SCIF_BUS) += scif_bus.o
 obj-$(CONFIG_MIC_COSM) += cosm_bus.o
+obj-$(CONFIG_VOP_BUS) += vop_bus.o
diff --git a/drivers/misc/mic/bus/vop_bus.h b/drivers/misc/mic/bus/vop_bus.h
new file mode 100644
index 000..97fa5d6
--- /dev/null
+++ b/drivers/misc/mic/bus/vop_bus.h
@@ -0,0 +1,142 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio over PCIe Bus driver.
+ */
+#ifndef _VOP_BUS_H_
+#define _VOP_BUS_H_
+/*
+ * Everything a vop driver needs to work with any particular vop
+ * implementation.
+ */
+#include 
+#include 
+
+#include "../common/mic_dev.h"
+
+struct vop_device_id {
+   u32 device;
+   u32 vendor;
+};
+
+#define VOP_DEV_TRNSP 1
+#define VOP_DEV_ANY_ID 0x
+/*
+ * Size of the internal buffer used during DMA's as an intermediate buffer
+ * for copy to/from user. Must be an integral number of pages.
+ */
+#define VOP_INT_DMA_BUF_SIZE PAGE_ALIGN(64 * 1024ULL)
+
+/**
+ * vop_device - representation of a device using vop
+ * @priv: private pointer for the driver's use.
+ * @hw_ops: the hardware ops supported by this device.
+ * @id: the device type identification (used to match it with a driver).
+ * @dev: underlying device.
+ * @dnode - The destination node which this device will communicate with.
+ * @aper: Aperture memory window
+ * @dma_ch - DMA channel
+ * @index: unique position on the vop bus
+ */
+struct vop_device {
+   void *priv;
+   struct vop_hw_ops *hw_ops;
+   struct vop_device_id id;
+   struct device dev;
+   u8 dnode;
+   struct mic_mw *aper;
+   struct dma_chan *dma_ch;
+   int index;
+};
+
+/**
+ * vop_driver - operations for a vop I/O driver
+ * @driver: underlying device driver (populate name and owner).
+ * @id_table: the ids serviced by this driver.
+ * @probe: the function to call when a device is found.  Returns 0 or -errno.
+ * @remove: the function to call when a device is removed.
+ */
+struct vop_driver {
+   struct device_driver driver;
+   const struct vop_de

[PATCH char-misc-next 2/8] misc: mic: Remove MIC X100 card virtio functionality

2016-02-01 Thread Sudeep Dutt
This patch deletes the virtio functionality from the MIC X100 card
driver. A subsequent patch will re-enable this functionality by
consolidating the hardware independent logic in a new Virtio over PCIe
(VOP) driver.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/card/Makefile |   1 -
 drivers/misc/mic/card/mic_virtio.h |  76 -
 drivers/misc/mic/card/mic_device.c |   9 +-
 drivers/misc/mic/card/mic_virtio.c | 634 -
 4 files changed, 1 insertion(+), 719 deletions(-)
 delete mode 100644 drivers/misc/mic/card/mic_virtio.h
 delete mode 100644 drivers/misc/mic/card/mic_virtio.c

diff --git a/drivers/misc/mic/card/Makefile b/drivers/misc/mic/card/Makefile
index 69d58be..6e9675e 100644
--- a/drivers/misc/mic/card/Makefile
+++ b/drivers/misc/mic/card/Makefile
@@ -8,4 +8,3 @@ obj-$(CONFIG_INTEL_MIC_CARD) += mic_card.o
 mic_card-y += mic_x100.o
 mic_card-y += mic_device.o
 mic_card-y += mic_debugfs.o
-mic_card-y += mic_virtio.o
diff --git a/drivers/misc/mic/card/mic_virtio.h 
b/drivers/misc/mic/card/mic_virtio.h
deleted file mode 100644
index d0407ba..000
--- a/drivers/misc/mic/card/mic_virtio.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Disclaimer: The codes contained in these modules may be specific to
- * the Intel Software Development Platform codenamed: Knights Ferry, and
- * the Intel product codenamed: Knights Corner, and are not backward
- * compatible with other Intel products. Additionally, Intel will NOT
- * support the codes or instruction set in future products.
- *
- * Intel MIC Card driver.
- *
- */
-#ifndef __MIC_CARD_VIRTIO_H
-#define __MIC_CARD_VIRTIO_H
-
-#include 
-#include "mic_device.h"
-
-/*
- * 64 bit I/O access
- */
-#ifndef ioread64
-#define ioread64 readq
-#endif
-#ifndef iowrite64
-#define iowrite64 writeq
-#endif
-
-static inline unsigned mic_desc_size(struct mic_device_desc __iomem *desc)
-{
-   return sizeof(*desc)
-   + ioread8(>num_vq) * sizeof(struct mic_vqconfig)
-   + ioread8(>feature_len) * 2
-   + ioread8(>config_len);
-}
-
-static inline struct mic_vqconfig __iomem *
-mic_vq_config(struct mic_device_desc __iomem *desc)
-{
-   return (struct mic_vqconfig __iomem *)(desc + 1);
-}
-
-static inline __u8 __iomem *
-mic_vq_features(struct mic_device_desc __iomem *desc)
-{
-   return (__u8 __iomem *)(mic_vq_config(desc) + ioread8(>num_vq));
-}
-
-static inline __u8 __iomem *
-mic_vq_configspace(struct mic_device_desc __iomem *desc)
-{
-   return mic_vq_features(desc) + ioread8(>feature_len) * 2;
-}
-static inline unsigned mic_total_desc_size(struct mic_device_desc __iomem 
*desc)
-{
-   return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
-}
-
-int mic_devices_init(struct mic_driver *mdrv);
-void mic_devices_uninit(struct mic_driver *mdrv);
-
-#endif
diff --git a/drivers/misc/mic/card/mic_device.c 
b/drivers/misc/mic/card/mic_device.c
index d0edaf7..ff03c63 100644
--- a/drivers/misc/mic/card/mic_device.c
+++ b/drivers/misc/mic/card/mic_device.c
@@ -34,7 +34,6 @@
 #include 
 #include "../common/mic_dev.h"
 #include "mic_device.h"
-#include "mic_virtio.h"
 
 static struct mic_driver *g_drv;
 
@@ -309,9 +308,6 @@ int __init mic_driver_init(struct mic_driver *mdrv)
rc = -ENODEV;
goto irq_uninit;
}
-   rc = mic_devices_init(mdrv);
-   if (rc)
-   goto dma_free;
bootparam = mdrv->dp;
node_id = ioread8(>node_id);
mdrv->scdev = scif_register_device(mdrv->dev, MIC_SCIF_DEV,
@@ -321,13 +317,11 @@ int __init mic_driver_init(struct mic_driver *mdrv)
   mdrv->num_dma_ch, true);
if (IS_ERR(mdrv->scdev)) {
rc = PTR_ERR(mdrv->scdev);
-   goto device_uninit;
+   goto dma_free;
}
mic_create_card_debug_dir(mdrv);
 done:
return rc;
-device_uninit:
-   mic_devices_uninit(mdrv);
 dma_free:
mic_free_dma_chans(mdrv);
 irq_uninit:
@@ -348,7 +342,6 @@ void mic_driver_uninit(struct mic_driver *mdrv)
 {
mic_delete_card_debug_dir(mdrv);
scif_unregister_device(mdrv->scdev);
-   mic_devices_uninit(mdrv);
  

[PATCH char-misc-next 8/8] misc: mic: MIC host and card driver changes to enable VOP

2016-02-01 Thread Sudeep Dutt
This patch modifies the MIC host and card drivers to start using the
VOP driver. The MIC host and card drivers now implement the VOP bus
operations and register a VOP device on the VOP bus. MIC driver stack
documentation is also updated to include the new VOP driver.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 Documentation/mic/mic_overview.txt |  54 +---
 drivers/misc/mic/Kconfig   |   7 ++-
 drivers/misc/mic/card/mic_device.h |   3 +
 drivers/misc/mic/host/mic_device.h |   3 +
 Documentation/mic/mpssd/mpssd.c|   2 +-
 drivers/misc/mic/card/mic_device.c |  84 -
 drivers/misc/mic/card/mic_x100.c   |   1 +
 drivers/misc/mic/host/mic_boot.c   | 125 -
 drivers/misc/mic/host/mic_main.c   |   1 +
 Documentation/mic/mpssd/mpss   |   2 +-
 10 files changed, 249 insertions(+), 33 deletions(-)

diff --git a/Documentation/mic/mic_overview.txt 
b/Documentation/mic/mic_overview.txt
index 73f44fc..074adbd 100644
--- a/Documentation/mic/mic_overview.txt
+++ b/Documentation/mic/mic_overview.txt
@@ -12,10 +12,19 @@ for the X100 devices.
 
 Since it is a PCIe card, it does not have the ability to host hardware
 devices for networking, storage and console. We provide these devices
-on X100 coprocessors thus enabling a self-bootable equivalent environment
-for applications. A key benefit of our solution is that it leverages
-the standard virtio framework for network, disk and console devices,
-though in our case the virtio framework is used across a PCIe bus.
+on X100 coprocessors thus enabling a self-bootable equivalent
+environment for applications. A key benefit of our solution is that it
+leverages the standard virtio framework for network, disk and console
+devices, though in our case the virtio framework is used across a PCIe
+bus. A Virtio Over PCIe (VOP) driver allows creating user space
+backends or devices on the host which are used to probe virtio drivers
+for these devices on the MIC card. The existing VRINGH infrastructure
+in the kernel is used to access virtio rings from the host. The card
+VOP driver allows card virtio drivers to communicate with their user
+space backends on the host via a device page. Ring 3 apps on the host
+can add, remove and configure virtio devices. A thin MIC specific
+virtio_config_ops is implemented which is borrowed heavily from
+previous similar implementations in lguest and s390.
 
 MIC PCIe card has a dma controller with 8 channels. These channels are
 shared between the host s/w and the card s/w. 0 to 3 are used by host
@@ -38,7 +47,6 @@ single threaded performance for the host compared to MIC, the 
ability of
 the host to initiate DMA's to/from the card using the MIC DMA engine and
 the fact that the virtio block storage backend can only be on the host.
 
-  |
+--+   | +--+
| Card OS  |   | | Host OS  |
+--+   | +--+
@@ -47,27 +55,25 @@ the fact that the virtio block storage backend can only be 
on the host.
 | Virtio| |Virtio  | |Virtio| | |Virtio   |  |Virtio  | |Virtio  |
 | Net   | |Console | |Block | | |Net  |  |Console | |Block   |
 | Driver| |Driver  | |Driver| | |backend  |  |backend | |backend |
-+---+ ++ +--+ | +-+  ++ ++
++---+---+ +---++ +--+---+ | +-+  ++---+ ++
 | | | |  || |
 | | | |User  || |
-| | | |--||-|---
-+---+ |Kernel +--+
-  |   |   | Virtio over PCIe IOCTLs  |
-  |   |   +--+
-+---+ |   |   |  +---+
-| MIC DMA   | |  +--+ | +--+ +--+ |  | MIC DMA   |
-| Driver| |  | SCIF | | | SCIF | | COSM | |  | Driver|
-+---+ |  +--+ | +--+ +--+---+ |  +---+
-  |   | | ||| ||
-+---+ |  +--+ | +--+---+ +--+---+ | ++
-|MIC virtual Bus| |  |SCIF  | | |SCIF  | | COSM | | |MIC virtual Bus |
-+---+ |  |HW Bus| | |HW Bus| | Bus  | | ++
-  |   |  +--+ | +--+---+ +--+ |  |
-  |   | | |   | | |  |
-  |   +---+---+ | |   |+---+ |
-  |   |Intel MIC  | | |   ||Intel MIC  | |
-  +---|Card Driver| | |   ||Host Driver

[PATCH char-misc-next 6/8] misc: mic: Enable VOP card side functionality

2016-02-01 Thread Sudeep Dutt
From: Ashutosh Dixit 

This patch moves virtio functionality from the MIC card driver into a
separate hardware independent Virtio Over PCIe (VOP) driver. This
functionality was introduced in commit 2141c7c5ee67 ("Intel MIC Card
Driver Changes for Virtio Devices.") in
drivers/misc/mic/card/mic_virtio.c. Apart from being moved into a
separate driver the functionality is essentially unchanged. See the
above mentioned commit for a description of this functionality.

Signed-off-by: Sudeep Dutt 
Signed-off-by: Ashutosh Dixit 
---
 drivers/misc/mic/vop/vop_main.c | 755 
 1 file changed, 755 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_main.c

diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
new file mode 100644
index 000..c86aeeb
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_main.c
@@ -0,0 +1,755 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Adapted from:
+ *
+ * virtio for kvm on s390
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Christian Borntraeger 
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+
+#include "vop_main.h"
+
+#define VOP_MAX_VRINGS 4
+
+/*
+ * _vop_vdev - Allocated per virtio device instance injected by the peer.
+ *
+ * @vdev: Virtio device
+ * @desc: Virtio device page descriptor
+ * @dc: Virtio device control
+ * @vpdev: VOP device which is the parent for this virtio device
+ * @vr: Buffer for accessing the VRING
+ * @used: Buffer for used
+ * @used_size: Size of the used buffer
+ * @reset_done: Track whether VOP reset is complete
+ * @virtio_cookie: Cookie returned upon requesting a interrupt
+ * @c2h_vdev_db: The doorbell used by the guest to interrupt the host
+ * @h2c_vdev_db: The doorbell used by the host to interrupt the guest
+ * @dnode: The destination node
+ */
+struct _vop_vdev {
+   struct virtio_device vdev;
+   struct mic_device_desc __iomem *desc;
+   struct mic_device_ctrl __iomem *dc;
+   struct vop_device *vpdev;
+   void __iomem *vr[VOP_MAX_VRINGS];
+   dma_addr_t used[VOP_MAX_VRINGS];
+   int used_size[VOP_MAX_VRINGS];
+   struct completion reset_done;
+   struct mic_irq *virtio_cookie;
+   int c2h_vdev_db;
+   int h2c_vdev_db;
+   int dnode;
+};
+
+#define to_vopvdev(vd) container_of(vd, struct _vop_vdev, vdev)
+
+#define _vop_aligned_desc_size(d) __mic_align(_vop_desc_size(d), 8)
+
+/* Helper API to obtain the parent of the virtio device */
+static inline struct device *_vop_dev(struct _vop_vdev *vdev)
+{
+   return vdev->vdev.dev.parent;
+}
+
+static inline unsigned _vop_desc_size(struct mic_device_desc __iomem *desc)
+{
+   return sizeof(*desc)
+   + ioread8(>num_vq) * sizeof(struct mic_vqconfig)
+   + ioread8(>feature_len) * 2
+   + ioread8(>config_len);
+}
+
+static inline struct mic_vqconfig __iomem *
+_vop_vq_config(struct mic_device_desc __iomem *desc)
+{
+   return (struct mic_vqconfig __iomem *)(desc + 1);
+}
+
+static inline u8 __iomem *
+_vop_vq_features(struct mic_device_desc __iomem *desc)
+{
+   return (u8 __iomem *)(_vop_vq_config(desc) + ioread8(>num_vq));
+}
+
+static inline u8 __iomem *
+_vop_vq_configspace(struct mic_device_desc __iomem *desc)
+{
+   return _vop_vq_features(desc) + ioread8(>feature_len) * 2;
+}
+
+static inline unsigned
+_vop_total_desc_size(struct mic_device_desc __iomem *desc)
+{
+   return _vop_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
+}
+
+/* This gets the device's feature bits. */
+static u64 vop_get_features(struct virtio_device *vdev)
+{
+   unsigned int i, bits;
+   u32 features = 0;
+   struct mic_device_desc __iomem *desc = to_vopvdev(vdev)->desc;
+   u8 __iomem *in_features = _vop_vq_features(desc);
+   int feature_len = ioread8(>feature_len);
+
+   bits = min_t(unsigned, feature_len, sizeof(vdev->features)) * 8;
+   for (i = 0; i < bits; i++)
+   if (ioread8(_features[i / 8]) & (BIT(i % 8)))
+   features |= BIT(i);
+
+ 

[PATCH char-misc-next 5/8] misc: mic: Enable VOP host side functionality

2016-02-01 Thread Sudeep Dutt
This patch moves virtio functionality from the MIC host driver into a
separate hardware independent Virtio Over PCIe (VOP) driver. This
functionality was introduced in commit f69bcbf3b4c4 ("Intel MIC Host
Driver Changes for Virtio Devices.") in
drivers/misc/mic/host/mic_virtio.c. Apart from being moved into a
separate driver the functionality is essentially unchanged. See the
above mentioned commit for a description of this functionality.

Signed-off-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/vop/vop_vringh.c | 1164 +
 1 file changed, 1164 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_vringh.c

diff --git a/drivers/misc/mic/vop/vop_vringh.c 
b/drivers/misc/mic/vop/vop_vringh.c
new file mode 100644
index 000..6dc41fe
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_vringh.c
@@ -0,0 +1,1164 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+#include 
+
+#include 
+#include "../common/mic_dev.h"
+
+#include 
+#include "vop_main.h"
+
+/* Helper API to obtain the VOP PCIe device */
+static inline struct device *vop_dev(struct vop_vdev *vdev)
+{
+   return vdev->vpdev->dev.parent;
+}
+
+/* Helper API to check if a virtio device is initialized */
+static inline int vop_vdev_inited(struct vop_vdev *vdev)
+{
+   if (!vdev)
+   return -EINVAL;
+   /* Device has not been created yet */
+   if (!vdev->dd || !vdev->dd->type) {
+   dev_err(vop_dev(vdev), "%s %d err %d\n",
+   __func__, __LINE__, -EINVAL);
+   return -EINVAL;
+   }
+   /* Device has been removed/deleted */
+   if (vdev->dd->type == -1) {
+   dev_dbg(vop_dev(vdev), "%s %d err %d\n",
+   __func__, __LINE__, -ENODEV);
+   return -ENODEV;
+   }
+   return 0;
+}
+
+static void _vop_notify(struct vringh *vrh)
+{
+   struct vop_vringh *vvrh = container_of(vrh, struct vop_vringh, vrh);
+   struct vop_vdev *vdev = vvrh->vdev;
+   struct vop_device *vpdev = vdev->vpdev;
+   s8 db = vdev->dc->h2c_vdev_db;
+
+   if (db != -1)
+   vpdev->hw_ops->send_intr(vpdev, db);
+}
+
+static void vop_virtio_init_post(struct vop_vdev *vdev)
+{
+   struct mic_vqconfig *vqconfig = mic_vq_config(vdev->dd);
+   struct vop_device *vpdev = vdev->vpdev;
+   int i, used_size;
+
+   for (i = 0; i < vdev->dd->num_vq; i++) {
+   used_size = PAGE_ALIGN(sizeof(u16) * 3 +
+   sizeof(struct vring_used_elem) *
+   le16_to_cpu(vqconfig->num));
+   if (!le64_to_cpu(vqconfig[i].used_address)) {
+   dev_warn(vop_dev(vdev), "used_address zero??\n");
+   continue;
+   }
+   vdev->vvr[i].vrh.vring.used =
+   (void __force *)vpdev->hw_ops->ioremap(
+   vpdev,
+   le64_to_cpu(vqconfig[i].used_address),
+   used_size);
+   }
+
+   vdev->dc->used_address_updated = 0;
+
+   dev_info(vop_dev(vdev), "%s: device type %d LINKUP\n",
+__func__, vdev->virtio_id);
+}
+
+static inline void vop_virtio_device_reset(struct vop_vdev *vdev)
+{
+   int i;
+
+   dev_dbg(vop_dev(vdev), "%s: status %d device type %d RESET\n",
+   __func__, vdev->dd->status, vdev->virtio_id);
+
+   for (i = 0; i < vdev->dd->num_vq; i++)
+   /*
+* Avoid lockdep false positive. The + 1 is for the vop
+* mutex which is held in the reset devices code path.
+*/
+   mutex_lock_nested(>vvr[i].vr_mutex, i + 1);
+
+   /* 0 status means "reset" */
+   vdev->dd->status = 0;
+   vdev->dc->vdev_reset = 0;
+   vdev->dc->host_ack = 1;
+
+   for (i = 0; i < vdev->dd->num_vq; i++) {
+   struct vringh *vrh = >vvr[i].vrh;
+
+   vdev->vvr[i].vring.info->avail_idx = 0;
+   vrh->completed = 0;
+  

[PATCH char-misc-next 7/8] misc: mic: Enable VOP debugfs and driver build

2016-02-01 Thread Sudeep Dutt
This patch moves the virtio specific debugfs hooks previously in
mic_debugfs.c in the MIC host driver into the VOP driver. The
Kconfig/Makefile is also updated to allow building the VOP driver.

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/Kconfig   |  20 
 drivers/misc/mic/Makefile  |   1 +
 drivers/misc/mic/vop/Makefile  |   9 ++
 drivers/misc/mic/vop/vop_debugfs.c | 232 +
 4 files changed, 262 insertions(+)
 create mode 100644 drivers/misc/mic/vop/Makefile
 create mode 100644 drivers/misc/mic/vop/vop_debugfs.c

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 840f7ef..b03bb17 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -124,3 +124,23 @@ config MIC_COSM
  More information about the Intel MIC family as well as the Linux
  OS and tools for MIC to use with this driver are available from
  <http://software.intel.com/en-us/mic-developer>.
+
+comment "VOP Driver"
+
+config VOP
+   tristate "VOP Driver"
+   depends on 64BIT && PCI && X86 && VOP_BUS
+   select VHOST_RING
+   help
+ This enables VOP (Virtio over PCIe) Driver support for the Intel
+ Many Integrated Core (MIC) family of PCIe form factor coprocessor
+ devices. The VOP driver allows virtio drivers, e.g. net, console
+ and block drivers, on the card connect to user space virtio
+ devices on the host.
+
+ If you are building a host kernel with an Intel MIC device then
+ say M (recommended) or Y, else say N. If unsure say N.
+
+ More information about the Intel MIC family as well as the Linux
+ OS and tools for MIC to use with this driver are available from
+ <http://software.intel.com/en-us/mic-developer>.
diff --git a/drivers/misc/mic/Makefile b/drivers/misc/mic/Makefile
index e288a11..f2b1323 100644
--- a/drivers/misc/mic/Makefile
+++ b/drivers/misc/mic/Makefile
@@ -8,3 +8,4 @@ obj-y += bus/
 obj-$(CONFIG_SCIF) += scif/
 obj-$(CONFIG_MIC_COSM) += cosm/
 obj-$(CONFIG_MIC_COSM) += cosm_client/
+obj-$(CONFIG_VOP) += vop/
diff --git a/drivers/misc/mic/vop/Makefile b/drivers/misc/mic/vop/Makefile
new file mode 100644
index 000..78819c8
--- /dev/null
+++ b/drivers/misc/mic/vop/Makefile
@@ -0,0 +1,9 @@
+#
+# Makefile - Intel MIC Linux driver.
+# Copyright(c) 2016, Intel Corporation.
+#
+obj-m := vop.o
+
+vop-objs += vop_main.o
+vop-objs += vop_debugfs.o
+vop-objs += vop_vringh.o
diff --git a/drivers/misc/mic/vop/vop_debugfs.c 
b/drivers/misc/mic/vop/vop_debugfs.c
new file mode 100644
index 000..ab43884
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_debugfs.c
@@ -0,0 +1,232 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+
+#include "vop_main.h"
+
+static int vop_dp_show(struct seq_file *s, void *pos)
+{
+   struct mic_device_desc *d;
+   struct mic_device_ctrl *dc;
+   struct mic_vqconfig *vqconfig;
+   __u32 *features;
+   __u8 *config;
+   struct vop_info *vi = s->private;
+   struct vop_device *vpdev = vi->vpdev;
+   struct mic_bootparam *bootparam = vpdev->hw_ops->get_dp(vpdev);
+   int j, k;
+
+   seq_printf(s, "Bootparam: magic 0x%x\n",
+  bootparam->magic);
+   seq_printf(s, "Bootparam: h2c_config_db %d\n",
+  bootparam->h2c_config_db);
+   seq_printf(s, "Bootparam: node_id %d\n",
+  bootparam->node_id);
+   seq_printf(s, "Bootparam: c2h_scif_db %d\n",
+  bootparam->c2h_scif_db);
+   seq_printf(s, "Bootparam: h2c_scif_db %d\n",
+  bootparam->h2c_scif_db);
+   seq_printf(s, "Bootparam: scif_host_dma_addr 0x%llx\n",
+  bootparam->scif_host_dma_addr);
+   seq_printf(s, "Bootparam: scif_card_dma_addr 0x%llx\n",
+  bootparam->scif_card_dma_addr);
+
+   for (j = sizeof(*bootparam);
+   j < MIC_DP_SIZE; j += mic_total_desc_size(d)) {
+   d = (void *)bootparam + j;
+   dc = (void *)d + mic_aligned_desc_size(d);
+
+   

[PATCH char-misc-next 4/8] misc: mic: Add data structures for the VOP driver

2016-02-01 Thread Sudeep Dutt
This patch adds VOP driver data structures used in subsequent
patches. These data structures are refactored from similar data
structures used in the virtio parts of previous MIC host and card
drivers.

Signed-off-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/vop/vop_main.h | 170 
 1 file changed, 170 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_main.h

diff --git a/drivers/misc/mic/vop/vop_main.h b/drivers/misc/mic/vop/vop_main.h
new file mode 100644
index 000..ba47ec7
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_main.h
@@ -0,0 +1,170 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#ifndef _VOP_MAIN_H_
+#define _VOP_MAIN_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "../common/mic_dev.h"
+
+#include "../bus/vop_bus.h"
+
+/*
+ * Note on endianness.
+ * 1. Host can be both BE or LE
+ * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
+ *rings and ioreadXX/iowriteXX to access used ring.
+ * 3. Device page exposed by host to guest contains LE values. Guest
+ *accesses these using ioreadXX/iowriteXX etc. This way in general we
+ *obey the virtio spec according to which guest works with native
+ *endianness and host is aware of guest endianness and does all
+ *required endianness conversion.
+ * 4. Data provided from user space to guest (in ADD_DEVICE and
+ *CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
+ *in guest endianness.
+ */
+
+/*
+ * vop_info - Allocated per invocation of VOP probe
+ *
+ * @vpdev: VOP device
+ * @hotplug_work: Handle virtio device creation, deletion and configuration
+ * @cookie: Cookie received upon requesting a virtio configuration interrupt
+ * @h2c_config_db: The doorbell used by the peer to indicate a config change
+ * @vdev_list: List of "active" virtio devices injected in the peer node
+ * @vop_mutex: Synchronize access to the device page as well as serialize
+ * creation/deletion of virtio devices on the peer node
+ * @dp: Peer device page information
+ * @dbg: Debugfs entry
+ * @dma_ch: The DMA channel used by this transport for data transfers.
+ * @name: Name for this transport used in misc device creation.
+ * @miscdev: The misc device registered.
+ */
+struct vop_info {
+   struct vop_device *vpdev;
+   struct work_struct hotplug_work;
+   struct mic_irq *cookie;
+   int h2c_config_db;
+   struct list_head vdev_list;
+   struct mutex vop_mutex;
+   void __iomem *dp;
+   struct dentry *dbg;
+   struct dma_chan *dma_ch;
+   char name[16];
+   struct miscdevice miscdev;
+};
+
+/**
+ * struct vop_vringh - Virtio ring host information.
+ *
+ * @vring: The VOP vring used for setting up user space mappings.
+ * @vrh: The host VRINGH used for accessing the card vrings.
+ * @riov: The VRINGH read kernel IOV.
+ * @wiov: The VRINGH write kernel IOV.
+ * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
+ * @vr_mutex: Mutex for synchronizing access to the VRING.
+ * @buf: Temporary kernel buffer used to copy in/out data
+ * from/to the card via DMA.
+ * @buf_da: dma address of buf.
+ * @vdev: Back pointer to VOP virtio device for vringh_notify(..).
+ */
+struct vop_vringh {
+   struct mic_vring vring;
+   struct vringh vrh;
+   struct vringh_kiov riov;
+   struct vringh_kiov wiov;
+   u16 head;
+   struct mutex vr_mutex;
+   void *buf;
+   dma_addr_t buf_da;
+   struct vop_vdev *vdev;
+};
+
+/**
+ * struct vop_vdev - Host information for a card Virtio device.
+ *
+ * @virtio_id - Virtio device id.
+ * @waitq - Waitqueue to allow ring3 apps to poll.
+ * @vpdev - pointer to VOP bus device.
+ * @poll_wake - Used for waking up threads blocked in poll.
+ * @out_bytes - Debug stats for number of bytes copied from host to card.
+ * @in_bytes - Debug stats for number of bytes copied from card to host.
+ * @out_bytes_dma - Debug stats for number of bytes copied from host to card
+ * using DMA.
+ * @in_bytes_dma - Debug stats for number of bytes copied from card to host
+ * using DMA.
+ * @tx_len_unaligned - Debug stats for number of bytes copied to the card where
+ * the transfer length did not have the required DMA alignm

[PATCH char-misc-next 7/8] misc: mic: Enable VOP debugfs and driver build

2016-02-01 Thread Sudeep Dutt
This patch moves the virtio specific debugfs hooks previously in
mic_debugfs.c in the MIC host driver into the VOP driver. The
Kconfig/Makefile is also updated to allow building the VOP driver.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/Kconfig   |  20 
 drivers/misc/mic/Makefile  |   1 +
 drivers/misc/mic/vop/Makefile  |   9 ++
 drivers/misc/mic/vop/vop_debugfs.c | 232 +
 4 files changed, 262 insertions(+)
 create mode 100644 drivers/misc/mic/vop/Makefile
 create mode 100644 drivers/misc/mic/vop/vop_debugfs.c

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 840f7ef..b03bb17 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -124,3 +124,23 @@ config MIC_COSM
  More information about the Intel MIC family as well as the Linux
  OS and tools for MIC to use with this driver are available from
  <http://software.intel.com/en-us/mic-developer>.
+
+comment "VOP Driver"
+
+config VOP
+   tristate "VOP Driver"
+   depends on 64BIT && PCI && X86 && VOP_BUS
+   select VHOST_RING
+   help
+ This enables VOP (Virtio over PCIe) Driver support for the Intel
+ Many Integrated Core (MIC) family of PCIe form factor coprocessor
+ devices. The VOP driver allows virtio drivers, e.g. net, console
+ and block drivers, on the card connect to user space virtio
+ devices on the host.
+
+ If you are building a host kernel with an Intel MIC device then
+ say M (recommended) or Y, else say N. If unsure say N.
+
+ More information about the Intel MIC family as well as the Linux
+ OS and tools for MIC to use with this driver are available from
+ <http://software.intel.com/en-us/mic-developer>.
diff --git a/drivers/misc/mic/Makefile b/drivers/misc/mic/Makefile
index e288a11..f2b1323 100644
--- a/drivers/misc/mic/Makefile
+++ b/drivers/misc/mic/Makefile
@@ -8,3 +8,4 @@ obj-y += bus/
 obj-$(CONFIG_SCIF) += scif/
 obj-$(CONFIG_MIC_COSM) += cosm/
 obj-$(CONFIG_MIC_COSM) += cosm_client/
+obj-$(CONFIG_VOP) += vop/
diff --git a/drivers/misc/mic/vop/Makefile b/drivers/misc/mic/vop/Makefile
new file mode 100644
index 000..78819c8
--- /dev/null
+++ b/drivers/misc/mic/vop/Makefile
@@ -0,0 +1,9 @@
+#
+# Makefile - Intel MIC Linux driver.
+# Copyright(c) 2016, Intel Corporation.
+#
+obj-m := vop.o
+
+vop-objs += vop_main.o
+vop-objs += vop_debugfs.o
+vop-objs += vop_vringh.o
diff --git a/drivers/misc/mic/vop/vop_debugfs.c 
b/drivers/misc/mic/vop/vop_debugfs.c
new file mode 100644
index 000..ab43884
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_debugfs.c
@@ -0,0 +1,232 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+
+#include "vop_main.h"
+
+static int vop_dp_show(struct seq_file *s, void *pos)
+{
+   struct mic_device_desc *d;
+   struct mic_device_ctrl *dc;
+   struct mic_vqconfig *vqconfig;
+   __u32 *features;
+   __u8 *config;
+   struct vop_info *vi = s->private;
+   struct vop_device *vpdev = vi->vpdev;
+   struct mic_bootparam *bootparam = vpdev->hw_ops->get_dp(vpdev);
+   int j, k;
+
+   seq_printf(s, "Bootparam: magic 0x%x\n",
+  bootparam->magic);
+   seq_printf(s, "Bootparam: h2c_config_db %d\n",
+  bootparam->h2c_config_db);
+   seq_printf(s, "Bootparam: node_id %d\n",
+  bootparam->node_id);
+   seq_printf(s, "Bootparam: c2h_scif_db %d\n",
+  bootparam->c2h_scif_db);
+   seq_printf(s, "Bootparam: h2c_scif_db %d\n",
+  bootparam->h2c_scif_db);
+   seq_printf(s, "Bootparam: scif_host_dma_addr 0x%llx\n",
+  bootparam->scif_host_dma_addr);
+   seq_printf(s, "Bootparam: scif_card_dma_addr 0x%llx\n",
+  bootparam->scif_card_dma_addr);
+
+   for (j = sizeof(*bootparam);
+   j < MIC_DP_SIZE; j += mic_total_desc_size(d)) {
+   d = (void *)bootparam + j;
+

[PATCH char-misc-next 4/8] misc: mic: Add data structures for the VOP driver

2016-02-01 Thread Sudeep Dutt
This patch adds VOP driver data structures used in subsequent
patches. These data structures are refactored from similar data
structures used in the virtio parts of previous MIC host and card
drivers.

Signed-off-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/vop/vop_main.h | 170 
 1 file changed, 170 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_main.h

diff --git a/drivers/misc/mic/vop/vop_main.h b/drivers/misc/mic/vop/vop_main.h
new file mode 100644
index 000..ba47ec7
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_main.h
@@ -0,0 +1,170 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#ifndef _VOP_MAIN_H_
+#define _VOP_MAIN_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "../common/mic_dev.h"
+
+#include "../bus/vop_bus.h"
+
+/*
+ * Note on endianness.
+ * 1. Host can be both BE or LE
+ * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
+ *rings and ioreadXX/iowriteXX to access used ring.
+ * 3. Device page exposed by host to guest contains LE values. Guest
+ *accesses these using ioreadXX/iowriteXX etc. This way in general we
+ *obey the virtio spec according to which guest works with native
+ *endianness and host is aware of guest endianness and does all
+ *required endianness conversion.
+ * 4. Data provided from user space to guest (in ADD_DEVICE and
+ *CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
+ *in guest endianness.
+ */
+
+/*
+ * vop_info - Allocated per invocation of VOP probe
+ *
+ * @vpdev: VOP device
+ * @hotplug_work: Handle virtio device creation, deletion and configuration
+ * @cookie: Cookie received upon requesting a virtio configuration interrupt
+ * @h2c_config_db: The doorbell used by the peer to indicate a config change
+ * @vdev_list: List of "active" virtio devices injected in the peer node
+ * @vop_mutex: Synchronize access to the device page as well as serialize
+ * creation/deletion of virtio devices on the peer node
+ * @dp: Peer device page information
+ * @dbg: Debugfs entry
+ * @dma_ch: The DMA channel used by this transport for data transfers.
+ * @name: Name for this transport used in misc device creation.
+ * @miscdev: The misc device registered.
+ */
+struct vop_info {
+   struct vop_device *vpdev;
+   struct work_struct hotplug_work;
+   struct mic_irq *cookie;
+   int h2c_config_db;
+   struct list_head vdev_list;
+   struct mutex vop_mutex;
+   void __iomem *dp;
+   struct dentry *dbg;
+   struct dma_chan *dma_ch;
+   char name[16];
+   struct miscdevice miscdev;
+};
+
+/**
+ * struct vop_vringh - Virtio ring host information.
+ *
+ * @vring: The VOP vring used for setting up user space mappings.
+ * @vrh: The host VRINGH used for accessing the card vrings.
+ * @riov: The VRINGH read kernel IOV.
+ * @wiov: The VRINGH write kernel IOV.
+ * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
+ * @vr_mutex: Mutex for synchronizing access to the VRING.
+ * @buf: Temporary kernel buffer used to copy in/out data
+ * from/to the card via DMA.
+ * @buf_da: dma address of buf.
+ * @vdev: Back pointer to VOP virtio device for vringh_notify(..).
+ */
+struct vop_vringh {
+   struct mic_vring vring;
+   struct vringh vrh;
+   struct vringh_kiov riov;
+   struct vringh_kiov wiov;
+   u16 head;
+   struct mutex vr_mutex;
+   void *buf;
+   dma_addr_t buf_da;
+   struct vop_vdev *vdev;
+};
+
+/**
+ * struct vop_vdev - Host information for a card Virtio device.
+ *
+ * @virtio_id - Virtio device id.
+ * @waitq - Waitqueue to allow ring3 apps to poll.
+ * @vpdev - pointer to VOP bus device.
+ * @poll_wake - Used for waking up threads blocked in poll.
+ * @out_bytes - Debug stats for number of bytes copied from host to card.
+ * @in_bytes - Debug stats for number of bytes copied from card to host.
+ * @out_bytes_dma - Debug stats for number of bytes copied from host to card
+ * using DMA.
+ * @in_bytes_dma - Debug stats for number of bytes copied from card to host
+ * using DMA.
+ * @tx_len_unaligned - Debug stats for number of bytes copied to the card whe

[PATCH char-misc-next 1/8] misc: mic: Remove MIC X100 host virtio functionality

2016-02-01 Thread Sudeep Dutt
This patch deletes the virtio functionality from the MIC X100 host
driver. A subsequent patch will re-enable this functionality by
consolidating the hardware independent logic in a new Virtio over PCIe
(VOP) driver.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/host/Makefile  |   2 -
 drivers/misc/mic/host/mic_device.h  |   6 -
 drivers/misc/mic/host/mic_fops.h|  32 --
 drivers/misc/mic/host/mic_virtio.h  | 155 ---
 drivers/misc/mic/host/mic_boot.c|   2 -
 drivers/misc/mic/host/mic_debugfs.c | 190 -
 drivers/misc/mic/host/mic_fops.c| 222 --
 drivers/misc/mic/host/mic_main.c|  48 +--
 drivers/misc/mic/host/mic_virtio.c  | 811 
 9 files changed, 4 insertions(+), 1464 deletions(-)
 delete mode 100644 drivers/misc/mic/host/mic_fops.h
 delete mode 100644 drivers/misc/mic/host/mic_virtio.h
 delete mode 100644 drivers/misc/mic/host/mic_fops.c
 delete mode 100644 drivers/misc/mic/host/mic_virtio.c

diff --git a/drivers/misc/mic/host/Makefile b/drivers/misc/mic/host/Makefile
index 004d3db..f3b5023 100644
--- a/drivers/misc/mic/host/Makefile
+++ b/drivers/misc/mic/host/Makefile
@@ -9,5 +9,3 @@ mic_host-objs += mic_smpt.o
 mic_host-objs += mic_intr.o
 mic_host-objs += mic_boot.o
 mic_host-objs += mic_debugfs.o
-mic_host-objs += mic_fops.o
-mic_host-objs += mic_virtio.o
diff --git a/drivers/misc/mic/host/mic_device.h 
b/drivers/misc/mic/host/mic_device.h
index 461184a..8460de1 100644
--- a/drivers/misc/mic/host/mic_device.h
+++ b/drivers/misc/mic/host/mic_device.h
@@ -64,9 +64,6 @@ extern struct cosm_hw_ops cosm_hw_ops;
  * @bootaddr: MIC boot address.
  * @dp: virtio device page
  * @dp_dma_addr: virtio device page DMA address.
- * @name: name for the misc char device
- * @miscdev: registered misc char device
- * @vdev_list: list of virtio devices.
  * @dma_mbdev: MIC BUS DMA device.
  * @dma_ch - Array of DMA channels
  * @num_dma_ch - Number of DMA channels available
@@ -91,9 +88,6 @@ struct mic_device {
u32 bootaddr;
void *dp;
dma_addr_t dp_dma_addr;
-   char name[16];
-   struct miscdevice miscdev;
-   struct list_head vdev_list;
struct mbus_device *dma_mbdev;
struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN];
int num_dma_ch;
diff --git a/drivers/misc/mic/host/mic_fops.h b/drivers/misc/mic/host/mic_fops.h
deleted file mode 100644
index dc3893d..000
--- a/drivers/misc/mic/host/mic_fops.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Intel MIC Host driver.
- *
- */
-#ifndef _MIC_FOPS_H_
-#define _MIC_FOPS_H_
-
-int mic_open(struct inode *inode, struct file *filp);
-int mic_release(struct inode *inode, struct file *filp);
-ssize_t mic_read(struct file *filp, char __user *buf,
-   size_t count, loff_t *pos);
-long mic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
-int mic_mmap(struct file *f, struct vm_area_struct *vma);
-unsigned int mic_poll(struct file *f, poll_table *wait);
-
-#endif
diff --git a/drivers/misc/mic/host/mic_virtio.h 
b/drivers/misc/mic/host/mic_virtio.h
deleted file mode 100644
index a80631f..000
--- a/drivers/misc/mic/host/mic_virtio.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Intel MIC Host driver.
- *
- */
-#ifndef MIC_VIRTIO_H
-#define MIC_VIRTIO_H
-
-#include 
-#include 
-
-/*
- * Note on endianness.
- * 1. Host can be both BE or LE
- * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
- *rings and ioreadXX/iowriteXX to access used ring.
- * 3. Device page exposed by host to guest contains LE values. Guest
- *accesse

[PATCH char-misc-next 3/8] misc: mic: MIC VOP Bus

2016-02-01 Thread Sudeep Dutt
The Virtio Over PCIe (VOP) bus abstracts the low level hardware
details like interrupts and mapping remote memory so that the same VOP
driver can work without changes with different MIC host or card
drivers as long as the hardware bus operations are implemented. The
VOP driver registers itself on the VOP bus. The base PCIe drivers
implement the bus ops and register VOP devices on the bus, resulting
in the VOP driver being probed with the VOP devices. This allows the
VOP functionality to be shared between multiple generations of Intel
MIC products.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/Kconfig   |  17 
 drivers/misc/mic/bus/Makefile  |   1 +
 drivers/misc/mic/bus/vop_bus.h | 142 
 drivers/misc/mic/bus/vop_bus.c | 204 +
 4 files changed, 364 insertions(+)
 create mode 100644 drivers/misc/mic/bus/vop_bus.h
 create mode 100644 drivers/misc/mic/bus/vop_bus.c

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 40677df..840f7ef 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -32,6 +32,23 @@ config SCIF_BUS
  OS and tools for MIC to use with this driver are available from
  <http://software.intel.com/en-us/mic-developer>.
 
+comment "VOP Bus Driver"
+
+config VOP_BUS
+   tristate "VOP Bus Driver"
+   depends on 64BIT && PCI && X86 && X86_DEV_DMA_OPS
+   help
+ This option is selected by any driver which registers a
+ device or driver on the VOP Bus, such as CONFIG_INTEL_MIC_HOST
+ and CONFIG_INTEL_MIC_CARD.
+
+ If you are building a host/card kernel with an Intel MIC device
+ then say M (recommended) or Y, else say N. If unsure say N.
+
+ More information about the Intel MIC family as well as the Linux
+ OS and tools for MIC to use with this driver are available from
+ <http://software.intel.com/en-us/mic-developer>.
+
 comment "Intel MIC Host Driver"
 
 config INTEL_MIC_HOST
diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
index 761842b..8758a7d 100644
--- a/drivers/misc/mic/bus/Makefile
+++ b/drivers/misc/mic/bus/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
 obj-$(CONFIG_SCIF_BUS) += scif_bus.o
 obj-$(CONFIG_MIC_COSM) += cosm_bus.o
+obj-$(CONFIG_VOP_BUS) += vop_bus.o
diff --git a/drivers/misc/mic/bus/vop_bus.h b/drivers/misc/mic/bus/vop_bus.h
new file mode 100644
index 000..97fa5d6
--- /dev/null
+++ b/drivers/misc/mic/bus/vop_bus.h
@@ -0,0 +1,142 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio over PCIe Bus driver.
+ */
+#ifndef _VOP_BUS_H_
+#define _VOP_BUS_H_
+/*
+ * Everything a vop driver needs to work with any particular vop
+ * implementation.
+ */
+#include 
+#include 
+
+#include "../common/mic_dev.h"
+
+struct vop_device_id {
+   u32 device;
+   u32 vendor;
+};
+
+#define VOP_DEV_TRNSP 1
+#define VOP_DEV_ANY_ID 0x
+/*
+ * Size of the internal buffer used during DMA's as an intermediate buffer
+ * for copy to/from user. Must be an integral number of pages.
+ */
+#define VOP_INT_DMA_BUF_SIZE PAGE_ALIGN(64 * 1024ULL)
+
+/**
+ * vop_device - representation of a device using vop
+ * @priv: private pointer for the driver's use.
+ * @hw_ops: the hardware ops supported by this device.
+ * @id: the device type identification (used to match it with a driver).
+ * @dev: underlying device.
+ * @dnode - The destination node which this device will communicate with.
+ * @aper: Aperture memory window
+ * @dma_ch - DMA channel
+ * @index: unique position on the vop bus
+ */
+struct vop_device {
+   void *priv;
+   struct vop_hw_ops *hw_ops;
+   struct vop_device_id id;
+   struct device dev;
+   u8 dnode;
+   struct mic_mw *aper;
+   struct dma_chan *dma_ch;
+   int index;
+};
+
+/**
+ * vop_driver - operations for a vop I/O driver
+ * @driver: underlying device driver (populate name and owner).
+ * @id_table: the ids serviced by this driver.
+ * @probe: the function to call when a device is found.  Returns 0 or -errno.
+ * @remove: the function to call when a device is removed.
+ */
+struct vop_driver {
+   

[PATCH char-misc-next 2/8] misc: mic: Remove MIC X100 card virtio functionality

2016-02-01 Thread Sudeep Dutt
This patch deletes the virtio functionality from the MIC X100 card
driver. A subsequent patch will re-enable this functionality by
consolidating the hardware independent logic in a new Virtio over PCIe
(VOP) driver.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/card/Makefile |   1 -
 drivers/misc/mic/card/mic_virtio.h |  76 -
 drivers/misc/mic/card/mic_device.c |   9 +-
 drivers/misc/mic/card/mic_virtio.c | 634 -
 4 files changed, 1 insertion(+), 719 deletions(-)
 delete mode 100644 drivers/misc/mic/card/mic_virtio.h
 delete mode 100644 drivers/misc/mic/card/mic_virtio.c

diff --git a/drivers/misc/mic/card/Makefile b/drivers/misc/mic/card/Makefile
index 69d58be..6e9675e 100644
--- a/drivers/misc/mic/card/Makefile
+++ b/drivers/misc/mic/card/Makefile
@@ -8,4 +8,3 @@ obj-$(CONFIG_INTEL_MIC_CARD) += mic_card.o
 mic_card-y += mic_x100.o
 mic_card-y += mic_device.o
 mic_card-y += mic_debugfs.o
-mic_card-y += mic_virtio.o
diff --git a/drivers/misc/mic/card/mic_virtio.h 
b/drivers/misc/mic/card/mic_virtio.h
deleted file mode 100644
index d0407ba..000
--- a/drivers/misc/mic/card/mic_virtio.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Intel MIC Platform Software Stack (MPSS)
- *
- * Copyright(c) 2013 Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Disclaimer: The codes contained in these modules may be specific to
- * the Intel Software Development Platform codenamed: Knights Ferry, and
- * the Intel product codenamed: Knights Corner, and are not backward
- * compatible with other Intel products. Additionally, Intel will NOT
- * support the codes or instruction set in future products.
- *
- * Intel MIC Card driver.
- *
- */
-#ifndef __MIC_CARD_VIRTIO_H
-#define __MIC_CARD_VIRTIO_H
-
-#include 
-#include "mic_device.h"
-
-/*
- * 64 bit I/O access
- */
-#ifndef ioread64
-#define ioread64 readq
-#endif
-#ifndef iowrite64
-#define iowrite64 writeq
-#endif
-
-static inline unsigned mic_desc_size(struct mic_device_desc __iomem *desc)
-{
-   return sizeof(*desc)
-   + ioread8(>num_vq) * sizeof(struct mic_vqconfig)
-   + ioread8(>feature_len) * 2
-   + ioread8(>config_len);
-}
-
-static inline struct mic_vqconfig __iomem *
-mic_vq_config(struct mic_device_desc __iomem *desc)
-{
-   return (struct mic_vqconfig __iomem *)(desc + 1);
-}
-
-static inline __u8 __iomem *
-mic_vq_features(struct mic_device_desc __iomem *desc)
-{
-   return (__u8 __iomem *)(mic_vq_config(desc) + ioread8(>num_vq));
-}
-
-static inline __u8 __iomem *
-mic_vq_configspace(struct mic_device_desc __iomem *desc)
-{
-   return mic_vq_features(desc) + ioread8(>feature_len) * 2;
-}
-static inline unsigned mic_total_desc_size(struct mic_device_desc __iomem 
*desc)
-{
-   return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
-}
-
-int mic_devices_init(struct mic_driver *mdrv);
-void mic_devices_uninit(struct mic_driver *mdrv);
-
-#endif
diff --git a/drivers/misc/mic/card/mic_device.c 
b/drivers/misc/mic/card/mic_device.c
index d0edaf7..ff03c63 100644
--- a/drivers/misc/mic/card/mic_device.c
+++ b/drivers/misc/mic/card/mic_device.c
@@ -34,7 +34,6 @@
 #include 
 #include "../common/mic_dev.h"
 #include "mic_device.h"
-#include "mic_virtio.h"
 
 static struct mic_driver *g_drv;
 
@@ -309,9 +308,6 @@ int __init mic_driver_init(struct mic_driver *mdrv)
rc = -ENODEV;
goto irq_uninit;
}
-   rc = mic_devices_init(mdrv);
-   if (rc)
-   goto dma_free;
bootparam = mdrv->dp;
node_id = ioread8(>node_id);
mdrv->scdev = scif_register_device(mdrv->dev, MIC_SCIF_DEV,
@@ -321,13 +317,11 @@ int __init mic_driver_init(struct mic_driver *mdrv)
   mdrv->num_dma_ch, true);
if (IS_ERR(mdrv->scdev)) {
rc = PTR_ERR(mdrv->scdev);
-   goto device_uninit;
+   goto dma_free;
}
mic_create_card_debug_dir(mdrv);
 done:
return rc;
-device_uninit:
-   mic_devices_uninit(mdrv);
 dma_free:
mic_free_dma_chans(mdrv);
 irq_uninit:
@@ -348,7 +342,6 @@ void mic_driver_uninit(struct mic_driver *mdrv)
 {
mic_delete_card_debug_dir(mdrv);
scif

[PATCH char-misc-next 8/8] misc: mic: MIC host and card driver changes to enable VOP

2016-02-01 Thread Sudeep Dutt
This patch modifies the MIC host and card drivers to start using the
VOP driver. The MIC host and card drivers now implement the VOP bus
operations and register a VOP device on the VOP bus. MIC driver stack
documentation is also updated to include the new VOP driver.

Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 Documentation/mic/mic_overview.txt |  54 +---
 drivers/misc/mic/Kconfig   |   7 ++-
 drivers/misc/mic/card/mic_device.h |   3 +
 drivers/misc/mic/host/mic_device.h |   3 +
 Documentation/mic/mpssd/mpssd.c|   2 +-
 drivers/misc/mic/card/mic_device.c |  84 -
 drivers/misc/mic/card/mic_x100.c   |   1 +
 drivers/misc/mic/host/mic_boot.c   | 125 -
 drivers/misc/mic/host/mic_main.c   |   1 +
 Documentation/mic/mpssd/mpss   |   2 +-
 10 files changed, 249 insertions(+), 33 deletions(-)

diff --git a/Documentation/mic/mic_overview.txt 
b/Documentation/mic/mic_overview.txt
index 73f44fc..074adbd 100644
--- a/Documentation/mic/mic_overview.txt
+++ b/Documentation/mic/mic_overview.txt
@@ -12,10 +12,19 @@ for the X100 devices.
 
 Since it is a PCIe card, it does not have the ability to host hardware
 devices for networking, storage and console. We provide these devices
-on X100 coprocessors thus enabling a self-bootable equivalent environment
-for applications. A key benefit of our solution is that it leverages
-the standard virtio framework for network, disk and console devices,
-though in our case the virtio framework is used across a PCIe bus.
+on X100 coprocessors thus enabling a self-bootable equivalent
+environment for applications. A key benefit of our solution is that it
+leverages the standard virtio framework for network, disk and console
+devices, though in our case the virtio framework is used across a PCIe
+bus. A Virtio Over PCIe (VOP) driver allows creating user space
+backends or devices on the host which are used to probe virtio drivers
+for these devices on the MIC card. The existing VRINGH infrastructure
+in the kernel is used to access virtio rings from the host. The card
+VOP driver allows card virtio drivers to communicate with their user
+space backends on the host via a device page. Ring 3 apps on the host
+can add, remove and configure virtio devices. A thin MIC specific
+virtio_config_ops is implemented which is borrowed heavily from
+previous similar implementations in lguest and s390.
 
 MIC PCIe card has a dma controller with 8 channels. These channels are
 shared between the host s/w and the card s/w. 0 to 3 are used by host
@@ -38,7 +47,6 @@ single threaded performance for the host compared to MIC, the 
ability of
 the host to initiate DMA's to/from the card using the MIC DMA engine and
 the fact that the virtio block storage backend can only be on the host.
 
-  |
+--+   | +--+
| Card OS  |   | | Host OS  |
+--+   | +--+
@@ -47,27 +55,25 @@ the fact that the virtio block storage backend can only be 
on the host.
 | Virtio| |Virtio  | |Virtio| | |Virtio   |  |Virtio  | |Virtio  |
 | Net   | |Console | |Block | | |Net  |  |Console | |Block   |
 | Driver| |Driver  | |Driver| | |backend  |  |backend | |backend |
-+---+ ++ +--+ | +-+  ++ ++
++---+---+ +---++ +--+---+ | +-+  ++---+ ++
 | | | |  || |
 | | | |User  || |
-| | | |--||-|---
-+---+ |Kernel +--+
-  |   |   | Virtio over PCIe IOCTLs  |
-  |   |   +--+
-+---+ |   |   |  +---+
-| MIC DMA   | |  +--+ | +--+ +--+ |  | MIC DMA   |
-| Driver| |  | SCIF | | | SCIF | | COSM | |  | Driver|
-+---+ |  +--+ | +--+ +--+---+ |  +---+
-  |   | | ||| ||
-+---+ |  +--+ | +--+---+ +--+---+ | ++
-|MIC virtual Bus| |  |SCIF  | | |SCIF  | | COSM | | |MIC virtual Bus |
-+---+ |  |HW Bus| | |HW Bus| | Bus  | | ++
-  |   |  +--+ | +--+---+ +--+ |  |
-  |   | | |   | | |  |
-  |   +---+---+ | |   |+---+ |
-  |   |Intel MIC  | | |   ||Intel MIC  | |
-  +---

[PATCH char-misc-next 6/8] misc: mic: Enable VOP card side functionality

2016-02-01 Thread Sudeep Dutt
From: Ashutosh Dixit <ashutosh.di...@intel.com>

This patch moves virtio functionality from the MIC card driver into a
separate hardware independent Virtio Over PCIe (VOP) driver. This
functionality was introduced in commit 2141c7c5ee67 ("Intel MIC Card
Driver Changes for Virtio Devices.") in
drivers/misc/mic/card/mic_virtio.c. Apart from being moved into a
separate driver the functionality is essentially unchanged. See the
above mentioned commit for a description of this functionality.

Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
Signed-off-by: Ashutosh Dixit <ashutosh.di...@intel.com>
---
 drivers/misc/mic/vop/vop_main.c | 755 
 1 file changed, 755 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_main.c

diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
new file mode 100644
index 000..c86aeeb
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_main.c
@@ -0,0 +1,755 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Adapted from:
+ *
+ * virtio for kvm on s390
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Christian Borntraeger <borntrae...@de.ibm.com>
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+
+#include "vop_main.h"
+
+#define VOP_MAX_VRINGS 4
+
+/*
+ * _vop_vdev - Allocated per virtio device instance injected by the peer.
+ *
+ * @vdev: Virtio device
+ * @desc: Virtio device page descriptor
+ * @dc: Virtio device control
+ * @vpdev: VOP device which is the parent for this virtio device
+ * @vr: Buffer for accessing the VRING
+ * @used: Buffer for used
+ * @used_size: Size of the used buffer
+ * @reset_done: Track whether VOP reset is complete
+ * @virtio_cookie: Cookie returned upon requesting a interrupt
+ * @c2h_vdev_db: The doorbell used by the guest to interrupt the host
+ * @h2c_vdev_db: The doorbell used by the host to interrupt the guest
+ * @dnode: The destination node
+ */
+struct _vop_vdev {
+   struct virtio_device vdev;
+   struct mic_device_desc __iomem *desc;
+   struct mic_device_ctrl __iomem *dc;
+   struct vop_device *vpdev;
+   void __iomem *vr[VOP_MAX_VRINGS];
+   dma_addr_t used[VOP_MAX_VRINGS];
+   int used_size[VOP_MAX_VRINGS];
+   struct completion reset_done;
+   struct mic_irq *virtio_cookie;
+   int c2h_vdev_db;
+   int h2c_vdev_db;
+   int dnode;
+};
+
+#define to_vopvdev(vd) container_of(vd, struct _vop_vdev, vdev)
+
+#define _vop_aligned_desc_size(d) __mic_align(_vop_desc_size(d), 8)
+
+/* Helper API to obtain the parent of the virtio device */
+static inline struct device *_vop_dev(struct _vop_vdev *vdev)
+{
+   return vdev->vdev.dev.parent;
+}
+
+static inline unsigned _vop_desc_size(struct mic_device_desc __iomem *desc)
+{
+   return sizeof(*desc)
+   + ioread8(>num_vq) * sizeof(struct mic_vqconfig)
+   + ioread8(>feature_len) * 2
+   + ioread8(>config_len);
+}
+
+static inline struct mic_vqconfig __iomem *
+_vop_vq_config(struct mic_device_desc __iomem *desc)
+{
+   return (struct mic_vqconfig __iomem *)(desc + 1);
+}
+
+static inline u8 __iomem *
+_vop_vq_features(struct mic_device_desc __iomem *desc)
+{
+   return (u8 __iomem *)(_vop_vq_config(desc) + ioread8(>num_vq));
+}
+
+static inline u8 __iomem *
+_vop_vq_configspace(struct mic_device_desc __iomem *desc)
+{
+   return _vop_vq_features(desc) + ioread8(>feature_len) * 2;
+}
+
+static inline unsigned
+_vop_total_desc_size(struct mic_device_desc __iomem *desc)
+{
+   return _vop_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
+}
+
+/* This gets the device's feature bits. */
+static u64 vop_get_features(struct virtio_device *vdev)
+{
+   unsigned int i, bits;
+   u32 features = 0;
+   struct mic_device_desc __iomem *desc = to_vopvdev(vdev)->desc;
+   u8 __iomem *in_features = _vop_vq_features(desc);
+   int feature_len = ioread8(>feature_len);
+
+   bits = min_t(unsigned, feature_len, sizeof(vdev->features)) * 8;
+   for 

[PATCH char-misc-next 5/8] misc: mic: Enable VOP host side functionality

2016-02-01 Thread Sudeep Dutt
This patch moves virtio functionality from the MIC host driver into a
separate hardware independent Virtio Over PCIe (VOP) driver. This
functionality was introduced in commit f69bcbf3b4c4 ("Intel MIC Host
Driver Changes for Virtio Devices.") in
drivers/misc/mic/host/mic_virtio.c. Apart from being moved into a
separate driver the functionality is essentially unchanged. See the
above mentioned commit for a description of this functionality.

Signed-off-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/vop/vop_vringh.c | 1164 +
 1 file changed, 1164 insertions(+)
 create mode 100644 drivers/misc/mic/vop/vop_vringh.c

diff --git a/drivers/misc/mic/vop/vop_vringh.c 
b/drivers/misc/mic/vop/vop_vringh.c
new file mode 100644
index 000..6dc41fe
--- /dev/null
+++ b/drivers/misc/mic/vop/vop_vringh.c
@@ -0,0 +1,1164 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ *
+ * Intel Virtio Over PCIe (VOP) driver.
+ *
+ */
+#include 
+#include 
+#include 
+
+#include 
+#include "../common/mic_dev.h"
+
+#include 
+#include "vop_main.h"
+
+/* Helper API to obtain the VOP PCIe device */
+static inline struct device *vop_dev(struct vop_vdev *vdev)
+{
+   return vdev->vpdev->dev.parent;
+}
+
+/* Helper API to check if a virtio device is initialized */
+static inline int vop_vdev_inited(struct vop_vdev *vdev)
+{
+   if (!vdev)
+   return -EINVAL;
+   /* Device has not been created yet */
+   if (!vdev->dd || !vdev->dd->type) {
+   dev_err(vop_dev(vdev), "%s %d err %d\n",
+   __func__, __LINE__, -EINVAL);
+   return -EINVAL;
+   }
+   /* Device has been removed/deleted */
+   if (vdev->dd->type == -1) {
+   dev_dbg(vop_dev(vdev), "%s %d err %d\n",
+   __func__, __LINE__, -ENODEV);
+   return -ENODEV;
+   }
+   return 0;
+}
+
+static void _vop_notify(struct vringh *vrh)
+{
+   struct vop_vringh *vvrh = container_of(vrh, struct vop_vringh, vrh);
+   struct vop_vdev *vdev = vvrh->vdev;
+   struct vop_device *vpdev = vdev->vpdev;
+   s8 db = vdev->dc->h2c_vdev_db;
+
+   if (db != -1)
+   vpdev->hw_ops->send_intr(vpdev, db);
+}
+
+static void vop_virtio_init_post(struct vop_vdev *vdev)
+{
+   struct mic_vqconfig *vqconfig = mic_vq_config(vdev->dd);
+   struct vop_device *vpdev = vdev->vpdev;
+   int i, used_size;
+
+   for (i = 0; i < vdev->dd->num_vq; i++) {
+   used_size = PAGE_ALIGN(sizeof(u16) * 3 +
+   sizeof(struct vring_used_elem) *
+   le16_to_cpu(vqconfig->num));
+   if (!le64_to_cpu(vqconfig[i].used_address)) {
+   dev_warn(vop_dev(vdev), "used_address zero??\n");
+   continue;
+   }
+   vdev->vvr[i].vrh.vring.used =
+   (void __force *)vpdev->hw_ops->ioremap(
+   vpdev,
+   le64_to_cpu(vqconfig[i].used_address),
+   used_size);
+   }
+
+   vdev->dc->used_address_updated = 0;
+
+   dev_info(vop_dev(vdev), "%s: device type %d LINKUP\n",
+__func__, vdev->virtio_id);
+}
+
+static inline void vop_virtio_device_reset(struct vop_vdev *vdev)
+{
+   int i;
+
+   dev_dbg(vop_dev(vdev), "%s: status %d device type %d RESET\n",
+   __func__, vdev->dd->status, vdev->virtio_id);
+
+   for (i = 0; i < vdev->dd->num_vq; i++)
+   /*
+* Avoid lockdep false positive. The + 1 is for the vop
+* mutex which is held in the reset devices code path.
+*/
+   mutex_lock_nested(>vvr[i].vr_mutex, i + 1);
+
+   /* 0 status means "reset" */
+   vdev->dd->status = 0;
+   vdev->dc->vdev_reset = 0;
+   vdev->dc->host_ack = 1;
+
+   for (i = 0; i < vdev->dd->num_vq; i++) {
+   struct vringh *vrh = >vvr[i].vrh;
+
+   vdev->vvr[i].vring.info->avail_i

[PATCH char-misc-next 0/8] Enable Virtio Over PCIe (VOP) driver

2016-02-01 Thread Sudeep Dutt
This patch series moves virtio functionality from the MIC host/card
driver into a separate hardware independent Virtio Over PCIe (VOP)
driver. Apart from being moved into a separate driver the functionality
is essentially unchanged. This refactoring allows this hardware
independent logic to be shared easily across multiple generations of
MIC devices. The original commits are listed below for reference:
- commit f69bcbf3b4c4 ("Intel MIC Host Driver Changes for Virtio Devices.")
in drivers/misc/mic/host/mic_virtio.c
- commit 2141c7c5ee67 ("Intel MIC Card Driver Changes for Virtio Devices.")
in drivers/misc/mic/card/mic_virtio.c

The patch series is partitioned as follows:
1) Removes MIC X100 host virtio functionality
2) Removes MIC X100 card virtio functionality
3) Enables the Virtio Over PCIe (VOP) bus which abstracts the
   low level hardware details like interrupts and mapping remote
   memory so that the same VOP driver can work without changes
   with different MIC host or card drivers as long as the hardware
   bus operations are implemented.
4) Adds data structures for the VOP driver
5) Enables VOP host side functionality
6) Enables VOP card side functionality
7) Enables VOP debugfs and driver build
8) Implements the MIC host and card driver changes to enable VOP

Ashutosh Dixit (1):
  misc: mic: Enable VOP card side functionality

Sudeep Dutt (7):
  misc: mic: Remove MIC X100 host virtio functionality
  misc: mic: Remove MIC X100 card virtio functionality
  misc: mic: MIC VOP Bus
  misc: mic: Add data structures for the VOP driver
  misc: mic: Enable VOP host side functionality
  misc: mic: Enable VOP debugfs and driver build
  misc: mic: MIC host and card driver changes to enable VOP

 Documentation/mic/mic_overview.txt |   54 +-
 drivers/misc/mic/Kconfig   |   44 +-
 drivers/misc/mic/Makefile  |1 +
 drivers/misc/mic/bus/Makefile  |1 +
 drivers/misc/mic/card/Makefile |1 -
 drivers/misc/mic/host/Makefile |2 -
 drivers/misc/mic/vop/Makefile  |9 +
 drivers/misc/mic/bus/vop_bus.h |  142 +++
 drivers/misc/mic/card/mic_device.h |3 +
 drivers/misc/mic/card/mic_virtio.h |   76 --
 drivers/misc/mic/host/mic_device.h |9 +-
 drivers/misc/mic/host/mic_fops.h   |   32 -
 .../misc/mic/{host/mic_virtio.h => vop/vop_main.h} |  129 ++-
 Documentation/mic/mpssd/mpssd.c|2 +-
 drivers/misc/mic/bus/vop_bus.c |  204 
 drivers/misc/mic/card/mic_device.c |   89 +-
 drivers/misc/mic/card/mic_virtio.c |  634 ---
 drivers/misc/mic/card/mic_x100.c   |1 +
 drivers/misc/mic/host/mic_boot.c   |  127 ++-
 drivers/misc/mic/host/mic_debugfs.c|  190 
 drivers/misc/mic/host/mic_fops.c   |  222 
 drivers/misc/mic/host/mic_main.c   |   49 +-
 drivers/misc/mic/host/mic_virtio.c |  811 --
 drivers/misc/mic/vop/vop_debugfs.c |  232 
 drivers/misc/mic/vop/vop_main.c|  755 +
 drivers/misc/mic/vop/vop_vringh.c  | 1164 
 Documentation/mic/mpssd/mpss   |2 +-
 27 files changed, 2869 insertions(+), 2116 deletions(-)
 create mode 100644 drivers/misc/mic/vop/Makefile
 create mode 100644 drivers/misc/mic/bus/vop_bus.h
 delete mode 100644 drivers/misc/mic/card/mic_virtio.h
 delete mode 100644 drivers/misc/mic/host/mic_fops.h
 rename drivers/misc/mic/{host/mic_virtio.h => vop/vop_main.h} (58%)
 create mode 100644 drivers/misc/mic/bus/vop_bus.c
 delete mode 100644 drivers/misc/mic/card/mic_virtio.c
 delete mode 100644 drivers/misc/mic/host/mic_fops.c
 delete mode 100644 drivers/misc/mic/host/mic_virtio.c
 create mode 100644 drivers/misc/mic/vop/vop_debugfs.c
 create mode 100644 drivers/misc/mic/vop/vop_main.c
 create mode 100644 drivers/misc/mic/vop/vop_vringh.c

-- 
1.8.2.1



Re: [PATCH] misc: mic: fix incorrect use of error codes in SCIF DMA driver

2015-12-11 Thread Sudeep Dutt
On Fri, 2015-12-11 at 20:09 -0600, Eric Biggers wrote:
> The error code passed to ERR_PTR() always should be negated.  Also, the
> return value of scif_add_mmu_notifier() was never checked.
> 

Thanks for the patch Eric.

Reviewed-by: Sudeep Dutt 

> Signed-off-by: Eric Biggers 
> ---
>  drivers/misc/mic/scif/scif_dma.c | 14 +-
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_dma.c 
> b/drivers/misc/mic/scif/scif_dma.c
> index 95a13c6..f6aeebd 100644
> --- a/drivers/misc/mic/scif/scif_dma.c
> +++ b/drivers/misc/mic/scif/scif_dma.c
> @@ -276,13 +276,10 @@ static struct scif_mmu_notif *
>  scif_find_mmu_notifier(struct mm_struct *mm, struct scif_endpt_rma_info *rma)
>  {
>   struct scif_mmu_notif *mmn;
> - struct list_head *item;
>  
> - list_for_each(item, >mmn_list) {
> - mmn = list_entry(item, struct scif_mmu_notif, list);
> + list_for_each_entry(mmn, >mmn_list, list)
>   if (mmn->mm == mm)
>   return mmn;
> - }
>   return NULL;
>  }
>  
> @@ -293,13 +290,12 @@ scif_add_mmu_notifier(struct mm_struct *mm, struct 
> scif_endpt *ep)
>= kzalloc(sizeof(*mmn), GFP_KERNEL);
>  
>   if (!mmn)
> - return ERR_PTR(ENOMEM);
> + return ERR_PTR(-ENOMEM);
>  
>   scif_init_mmu_notifier(mmn, current->mm, ep);
> - if (mmu_notifier_register(>ep_mmu_notifier,
> -   current->mm)) {
> + if (mmu_notifier_register(>ep_mmu_notifier, current->mm)) {
>   kfree(mmn);
> - return ERR_PTR(EBUSY);
> + return ERR_PTR(-EBUSY);
>   }
>   list_add(>list, >rma_info.mmn_list);
>   return mmn;
> @@ -1730,7 +1726,7 @@ static int scif_rma_copy(scif_epd_t epd, off_t loffset, 
> unsigned long addr,
>   mutex_lock(>rma_info.mmn_lock);
>   mmn = scif_find_mmu_notifier(current->mm, >rma_info);
>   if (!mmn)
> - scif_add_mmu_notifier(current->mm, ep);
> + mmn = scif_add_mmu_notifier(current->mm, ep);
>   mutex_unlock(>rma_info.mmn_lock);
>   if (IS_ERR(mmn)) {
>   scif_put_peer_dev(spdev);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next 4/4] misc: mic: use common error path

2015-12-11 Thread Sudeep Dutt
On Mon, 2015-11-23 at 17:24 +0530, Sudip Mukherjee wrote:
> Instead of calling release_firmware() on every error and then jumping
> lets have a common release_firmware() in the error path.
> This patch also fixes a memory leak where we missed release_firmware()
> if mic_x100_load_command_line() fails.
> 

Thanks for this patch series Sudip. All 4 patches look good.

Reviewed-by: Sudeep Dutt 


> Signed-off-by: Sudip Mukherjee 
> ---
>  drivers/misc/mic/host/mic_x100.c | 13 +++--
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/misc/mic/host/mic_x100.c 
> b/drivers/misc/mic/host/mic_x100.c
> index 37fa898..82a973c 100644
> --- a/drivers/misc/mic/host/mic_x100.c
> +++ b/drivers/misc/mic/host/mic_x100.c
> @@ -463,8 +463,7 @@ mic_x100_load_firmware(struct mic_device *mdev, const 
> char *buf)
>   rc = -EINVAL;
>   dev_err(>pdev->dev, "%s %d rc %d bootaddr 0x%x\n",
>   __func__, __LINE__, rc, mdev->bootaddr);
> - release_firmware(fw);
> - goto done;
> + goto error;
>   }
>   memcpy_toio(mdev->aper.va + mdev->bootaddr, fw->data, fw->size);
>   mdev->ops->write_spad(mdev, MIC_X100_FW_SIZE, fw->size);
> @@ -472,22 +471,24 @@ mic_x100_load_firmware(struct mic_device *mdev, const 
> char *buf)
>   rc = -EINVAL;
>   dev_err(>pdev->dev, "%s %d rc %d\n",
>   __func__, __LINE__, rc);
> - release_firmware(fw);
> - goto done;
> + goto error;
>   }
>   /* load command line */
>   rc = mic_x100_load_command_line(mdev, fw);
>   if (rc) {
>   dev_err(>pdev->dev, "%s %d rc %d\n",
>   __func__, __LINE__, rc);
> - goto done;
> + goto error;
>   }
>   release_firmware(fw);
>   /* load ramdisk */
>   if (mdev->cosm_dev->ramdisk)
>   rc = mic_x100_load_ramdisk(mdev);
>  
> -done:
> + return rc;
> +
> +error:
> + release_firmware(fw);
>   return rc;
>  }
>  


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next 4/4] misc: mic: use common error path

2015-12-11 Thread Sudeep Dutt
On Mon, 2015-11-23 at 17:24 +0530, Sudip Mukherjee wrote:
> Instead of calling release_firmware() on every error and then jumping
> lets have a common release_firmware() in the error path.
> This patch also fixes a memory leak where we missed release_firmware()
> if mic_x100_load_command_line() fails.
> 

Thanks for this patch series Sudip. All 4 patches look good.

Reviewed-by: Sudeep Dutt <sudeep.d...@intel.com>


> Signed-off-by: Sudip Mukherjee <su...@vectorindia.org>
> ---
>  drivers/misc/mic/host/mic_x100.c | 13 +++--
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/misc/mic/host/mic_x100.c 
> b/drivers/misc/mic/host/mic_x100.c
> index 37fa898..82a973c 100644
> --- a/drivers/misc/mic/host/mic_x100.c
> +++ b/drivers/misc/mic/host/mic_x100.c
> @@ -463,8 +463,7 @@ mic_x100_load_firmware(struct mic_device *mdev, const 
> char *buf)
>   rc = -EINVAL;
>   dev_err(>pdev->dev, "%s %d rc %d bootaddr 0x%x\n",
>   __func__, __LINE__, rc, mdev->bootaddr);
> - release_firmware(fw);
> - goto done;
> + goto error;
>   }
>   memcpy_toio(mdev->aper.va + mdev->bootaddr, fw->data, fw->size);
>   mdev->ops->write_spad(mdev, MIC_X100_FW_SIZE, fw->size);
> @@ -472,22 +471,24 @@ mic_x100_load_firmware(struct mic_device *mdev, const 
> char *buf)
>   rc = -EINVAL;
>   dev_err(>pdev->dev, "%s %d rc %d\n",
>   __func__, __LINE__, rc);
> - release_firmware(fw);
> - goto done;
> + goto error;
>   }
>   /* load command line */
>   rc = mic_x100_load_command_line(mdev, fw);
>   if (rc) {
>   dev_err(>pdev->dev, "%s %d rc %d\n",
>   __func__, __LINE__, rc);
> - goto done;
> + goto error;
>   }
>   release_firmware(fw);
>   /* load ramdisk */
>   if (mdev->cosm_dev->ramdisk)
>   rc = mic_x100_load_ramdisk(mdev);
>  
> -done:
> + return rc;
> +
> +error:
> + release_firmware(fw);
>   return rc;
>  }
>  


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] misc: mic: fix incorrect use of error codes in SCIF DMA driver

2015-12-11 Thread Sudeep Dutt
On Fri, 2015-12-11 at 20:09 -0600, Eric Biggers wrote:
> The error code passed to ERR_PTR() always should be negated.  Also, the
> return value of scif_add_mmu_notifier() was never checked.
> 

Thanks for the patch Eric.

Reviewed-by: Sudeep Dutt <sudeep.d...@intel.com>

> Signed-off-by: Eric Biggers <ebigge...@gmail.com>
> ---
>  drivers/misc/mic/scif/scif_dma.c | 14 +-
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_dma.c 
> b/drivers/misc/mic/scif/scif_dma.c
> index 95a13c6..f6aeebd 100644
> --- a/drivers/misc/mic/scif/scif_dma.c
> +++ b/drivers/misc/mic/scif/scif_dma.c
> @@ -276,13 +276,10 @@ static struct scif_mmu_notif *
>  scif_find_mmu_notifier(struct mm_struct *mm, struct scif_endpt_rma_info *rma)
>  {
>   struct scif_mmu_notif *mmn;
> - struct list_head *item;
>  
> - list_for_each(item, >mmn_list) {
> - mmn = list_entry(item, struct scif_mmu_notif, list);
> + list_for_each_entry(mmn, >mmn_list, list)
>   if (mmn->mm == mm)
>   return mmn;
> - }
>   return NULL;
>  }
>  
> @@ -293,13 +290,12 @@ scif_add_mmu_notifier(struct mm_struct *mm, struct 
> scif_endpt *ep)
>= kzalloc(sizeof(*mmn), GFP_KERNEL);
>  
>   if (!mmn)
> - return ERR_PTR(ENOMEM);
> + return ERR_PTR(-ENOMEM);
>  
>   scif_init_mmu_notifier(mmn, current->mm, ep);
> - if (mmu_notifier_register(>ep_mmu_notifier,
> -   current->mm)) {
> + if (mmu_notifier_register(>ep_mmu_notifier, current->mm)) {
>   kfree(mmn);
> - return ERR_PTR(EBUSY);
> + return ERR_PTR(-EBUSY);
>   }
>   list_add(>list, >rma_info.mmn_list);
>   return mmn;
> @@ -1730,7 +1726,7 @@ static int scif_rma_copy(scif_epd_t epd, off_t loffset, 
> unsigned long addr,
>   mutex_lock(>rma_info.mmn_lock);
>   mmn = scif_find_mmu_notifier(current->mm, >rma_info);
>   if (!mmn)
> - scif_add_mmu_notifier(current->mm, ep);
> + mmn = scif_add_mmu_notifier(current->mm, ep);
>   mutex_unlock(>rma_info.mmn_lock);
>   if (IS_ERR(mmn)) {
>   scif_put_peer_dev(spdev);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/3] misc:scif: do not define list_entry_next

2015-11-18 Thread Sudeep Dutt
On Wed, 2015-11-18 at 21:10 +0900, Sergey Senozhatsky wrote:
> Cosmetic.
> 
> Do not define list_entry_next() and use list_next_entry()
> from list.h.
> 

Hi Sergey,

A similar patch was posted @ https://lkml.org/lkml/2015/11/16/328

Regards,
Sudeep Dutt

> Signed-off-by: Sergey Senozhatsky 
> ---
>  drivers/misc/mic/scif/scif_dma.c  | 27 +++
>  drivers/misc/mic/scif/scif_main.h |  1 +
>  2 files changed, 12 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_dma.c 
> b/drivers/misc/mic/scif/scif_dma.c
> index 95a13c6..8804bcc 100644
> --- a/drivers/misc/mic/scif/scif_dma.c
> +++ b/drivers/misc/mic/scif/scif_dma.c
> @@ -74,11 +74,6 @@ struct scif_copy_work {
>   bool ordered;
>  };
>  
> -#ifndef list_entry_next
> -#define list_entry_next(pos, member) \
> - list_entry(pos->member.next, typeof(*pos), member)
> -#endif
> -
>  /**
>   * scif_reserve_dma_chan:
>   * @ep: Endpoint Descriptor.
> @@ -851,7 +846,7 @@ static void scif_rma_local_cpu_copy(s64 offset, struct 
> scif_window *window,
>   (window->nr_pages << PAGE_SHIFT);
>   while (rem_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -957,7 +952,7 @@ scif_rma_list_dma_copy_unaligned(struct scif_copy_work 
> *work,
>   remaining_len -= tail_len;
>   while (remaining_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -1064,7 +1059,7 @@ scif_rma_list_dma_copy_unaligned(struct scif_copy_work 
> *work,
>   }
>   if (tail_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -1147,13 +1142,13 @@ static int _scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   (dst_window->nr_pages << PAGE_SHIFT);
>   while (remaining_len) {
>   if (src_offset == end_src_offset) {
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   end_src_offset = src_window->offset +
>   (src_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(src_window, _win_iter);
>   }
>   if (dst_offset == end_dst_offset) {
> - dst_window = list_entry_next(dst_window, list);
> + dst_window = list_next_entry(dst_window, list);
>   end_dst_offset = dst_window->offset +
>   (dst_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(dst_window, _win_iter);
> @@ -1314,13 +1309,13 @@ static int scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   remaining_len -= tail_len;
>   while (remaining_len) {
>   if (src_offset == end_src_offset) {
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   end_src_offset = src_window->offset +
>   (src_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(src_window, _win_iter);
>   }
>   if (dst_offset == end_dst_offset) {
> - dst_window = list_entry_next(dst_window, list);
> + dst_window = list_next_entry(dst_window, list);
>   end_dst_offset = dst_window->offset +
>   (dst_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(dst_window, _win_iter);
> @@ -1405,9 +1400,9 @@ static int scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   if (remaining_len) {
>   loop_len = remaining_len;
>   if (src_offset == end_src_offset)
> - src_window = list_entry_ne

Re: [PATCH 1/3] misc:scif: do not define list_entry_next

2015-11-18 Thread Sudeep Dutt
On Wed, 2015-11-18 at 21:10 +0900, Sergey Senozhatsky wrote:
> Cosmetic.
> 
> Do not define list_entry_next() and use list_next_entry()
> from list.h.
> 

Hi Sergey,

A similar patch was posted @ https://lkml.org/lkml/2015/11/16/328

Regards,
Sudeep Dutt

> Signed-off-by: Sergey Senozhatsky <sergey.senozhat...@gmail.com>
> ---
>  drivers/misc/mic/scif/scif_dma.c  | 27 +++
>  drivers/misc/mic/scif/scif_main.h |  1 +
>  2 files changed, 12 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_dma.c 
> b/drivers/misc/mic/scif/scif_dma.c
> index 95a13c6..8804bcc 100644
> --- a/drivers/misc/mic/scif/scif_dma.c
> +++ b/drivers/misc/mic/scif/scif_dma.c
> @@ -74,11 +74,6 @@ struct scif_copy_work {
>   bool ordered;
>  };
>  
> -#ifndef list_entry_next
> -#define list_entry_next(pos, member) \
> - list_entry(pos->member.next, typeof(*pos), member)
> -#endif
> -
>  /**
>   * scif_reserve_dma_chan:
>   * @ep: Endpoint Descriptor.
> @@ -851,7 +846,7 @@ static void scif_rma_local_cpu_copy(s64 offset, struct 
> scif_window *window,
>   (window->nr_pages << PAGE_SHIFT);
>   while (rem_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -957,7 +952,7 @@ scif_rma_list_dma_copy_unaligned(struct scif_copy_work 
> *work,
>   remaining_len -= tail_len;
>   while (remaining_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -1064,7 +1059,7 @@ scif_rma_list_dma_copy_unaligned(struct scif_copy_work 
> *work,
>   }
>   if (tail_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -1147,13 +1142,13 @@ static int _scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   (dst_window->nr_pages << PAGE_SHIFT);
>   while (remaining_len) {
>   if (src_offset == end_src_offset) {
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   end_src_offset = src_window->offset +
>   (src_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(src_window, _win_iter);
>   }
>   if (dst_offset == end_dst_offset) {
> - dst_window = list_entry_next(dst_window, list);
> + dst_window = list_next_entry(dst_window, list);
>   end_dst_offset = dst_window->offset +
>   (dst_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(dst_window, _win_iter);
> @@ -1314,13 +1309,13 @@ static int scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   remaining_len -= tail_len;
>   while (remaining_len) {
>   if (src_offset == end_src_offset) {
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   end_src_offset = src_window->offset +
>   (src_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(src_window, _win_iter);
>   }
>   if (dst_offset == end_dst_offset) {
> - dst_window = list_entry_next(dst_window, list);
> + dst_window = list_next_entry(dst_window, list);
>   end_dst_offset = dst_window->offset +
>   (dst_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(dst_window, _win_iter);
> @@ -1405,9 +1400,9 @@ static int scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   if (remaining_len) {
>   loop_len = remaining_len;
>   if (src_offset == end_src_offset)
> -  

Re: [PATCH 1/3] misc: mic/scif: use list_next_entry instead of list_entry_next

2015-11-16 Thread Sudeep Dutt
On Mon, 2015-11-16 at 21:46 +0800, Geliang Tang wrote:
> list_next_entry has been defined in list.h, so I replace list_entry_next
> with it.
> 

Thanks for the cleanup.

Reviewed-by: Sudeep Dutt 

> Signed-off-by: Geliang Tang 
> ---
>  drivers/misc/mic/scif/scif_dma.c | 27 +++
>  1 file changed, 11 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_dma.c 
> b/drivers/misc/mic/scif/scif_dma.c
> index 95a13c6..8804bcc 100644
> --- a/drivers/misc/mic/scif/scif_dma.c
> +++ b/drivers/misc/mic/scif/scif_dma.c
> @@ -74,11 +74,6 @@ struct scif_copy_work {
>   bool ordered;
>  };
>  
> -#ifndef list_entry_next
> -#define list_entry_next(pos, member) \
> - list_entry(pos->member.next, typeof(*pos), member)
> -#endif
> -
>  /**
>   * scif_reserve_dma_chan:
>   * @ep: Endpoint Descriptor.
> @@ -851,7 +846,7 @@ static void scif_rma_local_cpu_copy(s64 offset, struct 
> scif_window *window,
>   (window->nr_pages << PAGE_SHIFT);
>   while (rem_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -957,7 +952,7 @@ scif_rma_list_dma_copy_unaligned(struct scif_copy_work 
> *work,
>   remaining_len -= tail_len;
>   while (remaining_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -1064,7 +1059,7 @@ scif_rma_list_dma_copy_unaligned(struct scif_copy_work 
> *work,
>   }
>   if (tail_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -1147,13 +1142,13 @@ static int _scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   (dst_window->nr_pages << PAGE_SHIFT);
>   while (remaining_len) {
>   if (src_offset == end_src_offset) {
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   end_src_offset = src_window->offset +
>   (src_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(src_window, _win_iter);
>   }
>   if (dst_offset == end_dst_offset) {
> - dst_window = list_entry_next(dst_window, list);
> + dst_window = list_next_entry(dst_window, list);
>   end_dst_offset = dst_window->offset +
>   (dst_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(dst_window, _win_iter);
> @@ -1314,13 +1309,13 @@ static int scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   remaining_len -= tail_len;
>   while (remaining_len) {
>   if (src_offset == end_src_offset) {
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   end_src_offset = src_window->offset +
>   (src_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(src_window, _win_iter);
>   }
>   if (dst_offset == end_dst_offset) {
> - dst_window = list_entry_next(dst_window, list);
> + dst_window = list_next_entry(dst_window, list);
>   end_dst_offset = dst_window->offset +
>   (dst_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(dst_window, _win_iter);
> @@ -1405,9 +1400,9 @@ static int scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   if (remaining_len) {
>   loop_len = remaining_len;
>   if (src_offset == end_src_offset)
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   if (dst_of

Re: [PATCH 1/3] misc: mic/scif: use list_next_entry instead of list_entry_next

2015-11-16 Thread Sudeep Dutt
On Mon, 2015-11-16 at 21:46 +0800, Geliang Tang wrote:
> list_next_entry has been defined in list.h, so I replace list_entry_next
> with it.
> 

Thanks for the cleanup.

Reviewed-by: Sudeep Dutt <sudeep.d...@intel.com>

> Signed-off-by: Geliang Tang <geliangt...@163.com>
> ---
>  drivers/misc/mic/scif/scif_dma.c | 27 +++
>  1 file changed, 11 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_dma.c 
> b/drivers/misc/mic/scif/scif_dma.c
> index 95a13c6..8804bcc 100644
> --- a/drivers/misc/mic/scif/scif_dma.c
> +++ b/drivers/misc/mic/scif/scif_dma.c
> @@ -74,11 +74,6 @@ struct scif_copy_work {
>   bool ordered;
>  };
>  
> -#ifndef list_entry_next
> -#define list_entry_next(pos, member) \
> - list_entry(pos->member.next, typeof(*pos), member)
> -#endif
> -
>  /**
>   * scif_reserve_dma_chan:
>   * @ep: Endpoint Descriptor.
> @@ -851,7 +846,7 @@ static void scif_rma_local_cpu_copy(s64 offset, struct 
> scif_window *window,
>   (window->nr_pages << PAGE_SHIFT);
>   while (rem_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -957,7 +952,7 @@ scif_rma_list_dma_copy_unaligned(struct scif_copy_work 
> *work,
>   remaining_len -= tail_len;
>   while (remaining_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -1064,7 +1059,7 @@ scif_rma_list_dma_copy_unaligned(struct scif_copy_work 
> *work,
>   }
>   if (tail_len) {
>   if (offset == end_offset) {
> - window = list_entry_next(window, list);
> + window = list_next_entry(window, list);
>   end_offset = window->offset +
>   (window->nr_pages << PAGE_SHIFT);
>   }
> @@ -1147,13 +1142,13 @@ static int _scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   (dst_window->nr_pages << PAGE_SHIFT);
>   while (remaining_len) {
>   if (src_offset == end_src_offset) {
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   end_src_offset = src_window->offset +
>   (src_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(src_window, _win_iter);
>   }
>   if (dst_offset == end_dst_offset) {
> - dst_window = list_entry_next(dst_window, list);
> + dst_window = list_next_entry(dst_window, list);
>   end_dst_offset = dst_window->offset +
>   (dst_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(dst_window, _win_iter);
> @@ -1314,13 +1309,13 @@ static int scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   remaining_len -= tail_len;
>   while (remaining_len) {
>   if (src_offset == end_src_offset) {
> - src_window = list_entry_next(src_window, list);
> + src_window = list_next_entry(src_window, list);
>   end_src_offset = src_window->offset +
>   (src_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(src_window, _win_iter);
>   }
>   if (dst_offset == end_dst_offset) {
> - dst_window = list_entry_next(dst_window, list);
> + dst_window = list_next_entry(dst_window, list);
>   end_dst_offset = dst_window->offset +
>   (dst_window->nr_pages << PAGE_SHIFT);
>   scif_init_window_iter(dst_window, _win_iter);
> @@ -1405,9 +1400,9 @@ static int scif_rma_list_dma_copy_aligned(struct 
> scif_copy_work *work,
>   if (remaining_len) {
>   loop_len = remaining_len;
>   if (src_offset == end_src_offset)
> - src_window = list_entry_next(src_window, list);
> + src_window = list_nex

Re: [patch 2/2] misc: mic/scif: fix wrap around tests

2015-10-13 Thread Sudeep Dutt
On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> Signed integer overflow is undefined.  Also I added a check for
> "(offset < 0)" in scif_unregister() because that makes it match the
> other conditions and because I didn't want to subtract a negative.
> 
> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter 
> ---
> 
> Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> that we truncate it because scif_get_window_offset() takes an integer
> argument.  I don't know if this is an issue.  Maybe I should use
> INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> for these types of issues:
> drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user 
> data 'len >> 12' '0-4503599627370495'
> drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user 
> data 'len >> 12' '0-4503599627370495'
> 
> The other static warnings here are:
> 
> drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: 
> inconsistent returns 'mutex:>rma_info.rma_lock'.
>   Locked on:   line 745
>   Unlocked on: line 687
> drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing 
> __func__ while the format string already contains the name of the function 
> 'scif_unpin_pages'
> 
> diff --git a/drivers/misc/mic/scif/scif_rma.c 
> b/drivers/misc/mic/scif/scif_rma.c
> index bc2dccb..fea7d2c 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
>   if ((map_flags & SCIF_MAP_FIXED) &&
>   ((ALIGN(offset, PAGE_SIZE) != offset) ||
>   (offset < 0) ||
> - (offset + (off_t)len < offset)))
> + (len > LONG_MAX - offset)))
>   return -EINVAL;
>  
>   might_sleep();
> @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t 
> len, off_t offset,
>   if ((map_flags & SCIF_MAP_FIXED) &&
>   ((ALIGN(offset, PAGE_SIZE) != offset) ||
>   (offset < 0) ||
> - (offset + (off_t)len < offset)))
> + (len < LONG_MAX - offset)))

Hi Dan,
Should this be > instead of < like the others?
Thanks,
Sudeep Dutt

>   return -EINVAL;
>  
>   /* Unsupported protection requested */
> @@ -1731,7 +1731,8 @@ scif_unregister(scif_epd_t epd, off_t offset, size_t 
> len)
>  
>   /* Offset is not page aligned or offset+len wraps around */
>   if ((ALIGN(offset, PAGE_SIZE) != offset) ||
> - (offset + (off_t)len < offset))
> + (offset < 0) ||
> + (len > LONG_MAX - offset))
>   return -EINVAL;
>  
>   err = scif_verify_epd(ep);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-next v2 1/1] MAINTAINERS: Add maintainership for MIC drivers

2015-10-13 Thread Sudeep Dutt
Add entry for MIC drivers to the MAINTAINERS file

Signed-off-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 MAINTAINERS | 16 
 1 file changed, 16 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fe5bbfe..994a7ae 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5575,6 +5575,22 @@ F:   include/linux/mei_cl_bus.h
 F: drivers/misc/mei/*
 F: Documentation/misc-devices/mei/*
 
+INTEL MIC DRIVERS (mic)
+M: Sudeep Dutt 
+M: Ashutosh Dixit 
+S: Supported
+W: https://github.com/sudeepdutt/mic
+W: http://software.intel.com/en-us/mic-developer
+F: include/linux/mic_bus.h
+F: include/linux/scif.h
+F: include/uapi/linux/mic_common.h
+F: include/uapi/linux/mic_ioctl.h
+F  include/uapi/linux/scif_ioctl.h
+F: drivers/misc/mic/
+F: drivers/dma/mic_x100_dma.c
+F: drivers/dma/mic_x100_dma.h
+F  Documentation/mic/
+
 INTEL PMC IPC DRIVER
 M: Zha Qipeng
 L: platform-driver-...@vger.kernel.org
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-next 1/1] MAINTAINERS: Add maintainership for MIC drivers

2015-10-13 Thread Sudeep Dutt
Add entry for MIC drivers to the MAINTAINERS file

Signed-off-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 MAINTAINERS | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fe5bbfe..840993b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5575,6 +5575,21 @@ F:   include/linux/mei_cl_bus.h
 F: drivers/misc/mei/*
 F: Documentation/misc-devices/mei/*
 
+INTEL MIC DRIVERS (mic)
+M: Sudeep Dutt 
+M: Ashutosh Dixit 
+S: Supported
+W: https://github.com/sudeepdutt/mic
+W: http://software.intel.com/en-us/mic-developer
+F: include/linux/mic_bus.h
+F: include/linux/scif.h
+F: include/uapi/linux/mic_common.h
+F: include/uapi/linux/mic_ioctl.h
+F  include/uapi/linux/scif_ioctl.h
+F: drivers/misc/mic/*
+F: drivers/dma/mic_x100_dma*
+F  Documentation/mic/*
+
 INTEL PMC IPC DRIVER
 M: Zha Qipeng
 L: platform-driver-...@vger.kernel.org
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] misc: mic: fix memory leak

2015-10-13 Thread Sudeep Dutt
On Tue, 2015-10-13 at 22:46 +0530, Sudip Mukherjee wrote:
> On Tue, Oct 13, 2015 at 09:34:21AM -0700, Sudeep Dutt wrote:
> > On Tue, 2015-10-13 at 14:38 +0530, Sudip Mukherjee wrote:
> 
> > > + struct scif_hw_dev *sdev = scifdev->sdev;
> > > +
> > > + dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_MMIO],
> > > +  p2p->sg_nentries[SCIF_PPI_MMIO], DMA_BIDIRECTIONAL);
> > 
> > Hi Sudip,
> > 
> > You missed unmapping the aperture here:
> > 
> > dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_APER],
> >  p2p->sg_nentries[SCIF_PPI_APER], DMA_BIDIRECTIONAL);
> > 
> > Can you please resubmit this patch with the change above?
> 
> Hi Sudeep,
> v3 sent for your review.   
> > 
> > Also you should mention [PATCH char-misc-next] in the next revision.
> 
> Ohhh... yes, I keep forgetting that Fengguang will need this tag for
> his build bot.
> 
> But I have one more doubt. If scif_nodeqp_send() fails then shouldn't we
> remove these two nodes of the p2p connection from the lists and release
> the resources?

The resources will get cleaned up via scif_destroy_p2p(..) once they are
added to the lists.

Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v3] misc: mic: fix memory leak

2015-10-13 Thread Sudeep Dutt
On Tue, 2015-10-13 at 22:36 +0530, Sudip Mukherjee wrote:
> In scif_node_connect() we were returning if the initialization of p2p_ji
> fails. But at that time p2p_ij has already been initialized and
> resources allocated for it. And since p2p_ij is not added to the list
> till now so we will have a leak.
> Lets deinitialize and release the resources connected to p2p_ij.
> 

Reviewed-by: Sudeep Dutt 

Thanks again for the fix.

> Signed-off-by: Sudip Mukherjee 
> ---
> 
> v3: added unmapping the aperture
> v2: missed making the function as static
> 
>  drivers/misc/mic/scif/scif_nodeqp.c | 19 ++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_nodeqp.c 
> b/drivers/misc/mic/scif/scif_nodeqp.c
> index 7180d56..c66ca1a 100644
> --- a/drivers/misc/mic/scif/scif_nodeqp.c
> +++ b/drivers/misc/mic/scif/scif_nodeqp.c
> @@ -435,6 +435,21 @@ free_p2p:
>   return NULL;
>  }
>  
> +/* Uninitialize and release resources from a p2p mapping */
> +static void scif_deinit_p2p_info(struct scif_dev *scifdev,
> +  struct scif_p2p_info *p2p)
> +{
> + struct scif_hw_dev *sdev = scifdev->sdev;
> +
> + dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_MMIO],
> +  p2p->sg_nentries[SCIF_PPI_MMIO], DMA_BIDIRECTIONAL);
> + dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_APER],
> +  p2p->sg_nentries[SCIF_PPI_APER], DMA_BIDIRECTIONAL);
> + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_MMIO]);
> + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_APER]);
> + kfree(p2p);
> +}
> +
>  /**
>   * scif_node_connect: Respond to SCIF_NODE_CONNECT interrupt message
>   * @dst: Destination node
> @@ -477,8 +492,10 @@ static void scif_node_connect(struct scif_dev *scifdev, 
> int dst)
>   if (!p2p_ij)
>   return;
>   p2p_ji = scif_init_p2p_info(dev_j, dev_i);
> - if (!p2p_ji)
> + if (!p2p_ji) {
> + scif_deinit_p2p_info(dev_i, p2p_ij);
>   return;
> + }
>   list_add_tail(_ij->ppi_list, _i->p2p);
>   list_add_tail(_ji->ppi_list, _j->p2p);
>  


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] misc: mic: fix memory leak

2015-10-13 Thread Sudeep Dutt
On Tue, 2015-10-13 at 14:38 +0530, Sudip Mukherjee wrote:
> In scif_node_connect() we were returning if the initialization of p2p_ji
> fails. But at that time p2p_ij has already been initialized and
> resources allocated for it. And since p2p_ij is not added to the list
> till now so we will have a leak.
> Lets deinitialize and release the resources connected to p2p_ij.
> 
> Signed-off-by: Sudip Mukherjee 
> ---
> 
> One sudip sending patch to another sudeep... :)
> 
>  drivers/misc/mic/scif/scif_nodeqp.c | 16 +++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_nodeqp.c 
> b/drivers/misc/mic/scif/scif_nodeqp.c
> index 7180d56..5e94fac 100644
> --- a/drivers/misc/mic/scif/scif_nodeqp.c
> +++ b/drivers/misc/mic/scif/scif_nodeqp.c
> @@ -435,6 +435,18 @@ free_p2p:
>   return NULL;
>  }
>  
> +/* Uninitialize and release resources from a p2p mapping */
> +void scif_deinit_p2p_info(struct scif_dev *scifdev, struct scif_p2p_info 
> *p2p)
> +{
> + struct scif_hw_dev *sdev = scifdev->sdev;
> +
> + dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_MMIO],
> +  p2p->sg_nentries[SCIF_PPI_MMIO], DMA_BIDIRECTIONAL);

Hi Sudip,

You missed unmapping the aperture here:

dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_APER],
 p2p->sg_nentries[SCIF_PPI_APER], DMA_BIDIRECTIONAL);

Can you please resubmit this patch with the change above?

Also you should mention [PATCH char-misc-next] in the next revision.

Thanks for the fix!

Sudeep Dutt

> + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_MMIO]);
> + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_APER]);
> + kfree(p2p);
> +}
> +
>  /**
>   * scif_node_connect: Respond to SCIF_NODE_CONNECT interrupt message
>   * @dst: Destination node
> @@ -477,8 +489,10 @@ static void scif_node_connect(struct scif_dev *scifdev, 
> int dst)
>   if (!p2p_ij)
>   return;
>   p2p_ji = scif_init_p2p_info(dev_j, dev_i);
> - if (!p2p_ji)
> + if (!p2p_ji) {
> + scif_deinit_p2p_info(dev_i, p2p_ij);
>   return;
> + }
>   list_add_tail(_ij->ppi_list, _i->p2p);
>   list_add_tail(_ji->ppi_list, _j->p2p);
>  


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch] misc: mic/scif: re-take a lock on error path

2015-10-13 Thread Sudeep Dutt
On Tue, 2015-10-13 at 15:52 +0300, Dan Carpenter wrote:
> The caller expects that we take this lock again before returning
> otherwise it you get double unlocks and races.
> 

Reviewed-by: Sudeep Dutt 

Thanks for the fix!

> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter 
> 
> diff --git a/drivers/misc/mic/scif/scif_rma.c 
> b/drivers/misc/mic/scif/scif_rma.c
> index e288996..980ef13 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -680,6 +680,7 @@ int scif_unregister_window(struct scif_window *window)
>   }
>   } else {
>   /* Return ENXIO since unregistration is in progress */
> + mutex_lock(>rma_info.rma_lock);
>   return -ENXIO;
>   }
>  retry:


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 2/2] misc: mic/scif: fix wrap around tests

2015-10-13 Thread Sudeep Dutt
On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> Signed integer overflow is undefined.  Also I added a check for
> "(offset < 0)" in scif_unregister() because that makes it match the
> other conditions and because I didn't want to subtract a negative.
> 
> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter <dan.carpen...@oracle.com>
> ---
> 
> Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> that we truncate it because scif_get_window_offset() takes an integer
> argument.  I don't know if this is an issue.  Maybe I should use
> INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> for these types of issues:
> drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user 
> data 'len >> 12' '0-4503599627370495'
> drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user 
> data 'len >> 12' '0-4503599627370495'
> 
> The other static warnings here are:
> 
> drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: 
> inconsistent returns 'mutex:>rma_info.rma_lock'.
>   Locked on:   line 745
>   Unlocked on: line 687
> drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing 
> __func__ while the format string already contains the name of the function 
> 'scif_unpin_pages'
> 
> diff --git a/drivers/misc/mic/scif/scif_rma.c 
> b/drivers/misc/mic/scif/scif_rma.c
> index bc2dccb..fea7d2c 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
>   if ((map_flags & SCIF_MAP_FIXED) &&
>   ((ALIGN(offset, PAGE_SIZE) != offset) ||
>   (offset < 0) ||
> - (offset + (off_t)len < offset)))
> + (len > LONG_MAX - offset)))
>   return -EINVAL;
>  
>   might_sleep();
> @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t 
> len, off_t offset,
>   if ((map_flags & SCIF_MAP_FIXED) &&
>   ((ALIGN(offset, PAGE_SIZE) != offset) ||
>   (offset < 0) ||
> - (offset + (off_t)len < offset)))
> + (len < LONG_MAX - offset)))

Hi Dan,
Should this be > instead of < like the others?
Thanks,
Sudeep Dutt

>   return -EINVAL;
>  
>   /* Unsupported protection requested */
> @@ -1731,7 +1731,8 @@ scif_unregister(scif_epd_t epd, off_t offset, size_t 
> len)
>  
>   /* Offset is not page aligned or offset+len wraps around */
>   if ((ALIGN(offset, PAGE_SIZE) != offset) ||
> - (offset + (off_t)len < offset))
> + (offset < 0) ||
> + (len > LONG_MAX - offset))
>   return -EINVAL;
>  
>   err = scif_verify_epd(ep);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch] misc: mic/scif: re-take a lock on error path

2015-10-13 Thread Sudeep Dutt
On Tue, 2015-10-13 at 15:52 +0300, Dan Carpenter wrote:
> The caller expects that we take this lock again before returning
> otherwise it you get double unlocks and races.
> 

Reviewed-by: Sudeep Dutt <sudeep.d...@intel.com>

Thanks for the fix!

> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter <dan.carpen...@oracle.com>
> 
> diff --git a/drivers/misc/mic/scif/scif_rma.c 
> b/drivers/misc/mic/scif/scif_rma.c
> index e288996..980ef13 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -680,6 +680,7 @@ int scif_unregister_window(struct scif_window *window)
>   }
>   } else {
>   /* Return ENXIO since unregistration is in progress */
> + mutex_lock(>rma_info.rma_lock);
>   return -ENXIO;
>   }
>  retry:


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] misc: mic: fix memory leak

2015-10-13 Thread Sudeep Dutt
On Tue, 2015-10-13 at 14:38 +0530, Sudip Mukherjee wrote:
> In scif_node_connect() we were returning if the initialization of p2p_ji
> fails. But at that time p2p_ij has already been initialized and
> resources allocated for it. And since p2p_ij is not added to the list
> till now so we will have a leak.
> Lets deinitialize and release the resources connected to p2p_ij.
> 
> Signed-off-by: Sudip Mukherjee <su...@vectorindia.org>
> ---
> 
> One sudip sending patch to another sudeep... :)
> 
>  drivers/misc/mic/scif/scif_nodeqp.c | 16 +++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_nodeqp.c 
> b/drivers/misc/mic/scif/scif_nodeqp.c
> index 7180d56..5e94fac 100644
> --- a/drivers/misc/mic/scif/scif_nodeqp.c
> +++ b/drivers/misc/mic/scif/scif_nodeqp.c
> @@ -435,6 +435,18 @@ free_p2p:
>   return NULL;
>  }
>  
> +/* Uninitialize and release resources from a p2p mapping */
> +void scif_deinit_p2p_info(struct scif_dev *scifdev, struct scif_p2p_info 
> *p2p)
> +{
> + struct scif_hw_dev *sdev = scifdev->sdev;
> +
> + dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_MMIO],
> +  p2p->sg_nentries[SCIF_PPI_MMIO], DMA_BIDIRECTIONAL);

Hi Sudip,

You missed unmapping the aperture here:

dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_APER],
 p2p->sg_nentries[SCIF_PPI_APER], DMA_BIDIRECTIONAL);

Can you please resubmit this patch with the change above?

Also you should mention [PATCH char-misc-next] in the next revision.

Thanks for the fix!

Sudeep Dutt

> + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_MMIO]);
> + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_APER]);
> + kfree(p2p);
> +}
> +
>  /**
>   * scif_node_connect: Respond to SCIF_NODE_CONNECT interrupt message
>   * @dst: Destination node
> @@ -477,8 +489,10 @@ static void scif_node_connect(struct scif_dev *scifdev, 
> int dst)
>   if (!p2p_ij)
>   return;
>   p2p_ji = scif_init_p2p_info(dev_j, dev_i);
> - if (!p2p_ji)
> + if (!p2p_ji) {
> + scif_deinit_p2p_info(dev_i, p2p_ij);
>   return;
> + }
>   list_add_tail(_ij->ppi_list, _i->p2p);
>   list_add_tail(_ji->ppi_list, _j->p2p);
>  


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v3] misc: mic: fix memory leak

2015-10-13 Thread Sudeep Dutt
On Tue, 2015-10-13 at 22:36 +0530, Sudip Mukherjee wrote:
> In scif_node_connect() we were returning if the initialization of p2p_ji
> fails. But at that time p2p_ij has already been initialized and
> resources allocated for it. And since p2p_ij is not added to the list
> till now so we will have a leak.
> Lets deinitialize and release the resources connected to p2p_ij.
> 

Reviewed-by: Sudeep Dutt <sudeep.d...@intel.com>

Thanks again for the fix.

> Signed-off-by: Sudip Mukherjee <su...@vectorindia.org>
> ---
> 
> v3: added unmapping the aperture
> v2: missed making the function as static
> 
>  drivers/misc/mic/scif/scif_nodeqp.c | 19 ++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_nodeqp.c 
> b/drivers/misc/mic/scif/scif_nodeqp.c
> index 7180d56..c66ca1a 100644
> --- a/drivers/misc/mic/scif/scif_nodeqp.c
> +++ b/drivers/misc/mic/scif/scif_nodeqp.c
> @@ -435,6 +435,21 @@ free_p2p:
>   return NULL;
>  }
>  
> +/* Uninitialize and release resources from a p2p mapping */
> +static void scif_deinit_p2p_info(struct scif_dev *scifdev,
> +  struct scif_p2p_info *p2p)
> +{
> + struct scif_hw_dev *sdev = scifdev->sdev;
> +
> + dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_MMIO],
> +  p2p->sg_nentries[SCIF_PPI_MMIO], DMA_BIDIRECTIONAL);
> + dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_APER],
> +  p2p->sg_nentries[SCIF_PPI_APER], DMA_BIDIRECTIONAL);
> + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_MMIO]);
> + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_APER]);
> + kfree(p2p);
> +}
> +
>  /**
>   * scif_node_connect: Respond to SCIF_NODE_CONNECT interrupt message
>   * @dst: Destination node
> @@ -477,8 +492,10 @@ static void scif_node_connect(struct scif_dev *scifdev, 
> int dst)
>   if (!p2p_ij)
>   return;
>   p2p_ji = scif_init_p2p_info(dev_j, dev_i);
> - if (!p2p_ji)
> + if (!p2p_ji) {
> + scif_deinit_p2p_info(dev_i, p2p_ij);
>   return;
> + }
>   list_add_tail(_ij->ppi_list, _i->p2p);
>   list_add_tail(_ji->ppi_list, _j->p2p);
>  


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] misc: mic: fix memory leak

2015-10-13 Thread Sudeep Dutt
On Tue, 2015-10-13 at 22:46 +0530, Sudip Mukherjee wrote:
> On Tue, Oct 13, 2015 at 09:34:21AM -0700, Sudeep Dutt wrote:
> > On Tue, 2015-10-13 at 14:38 +0530, Sudip Mukherjee wrote:
> 
> > > + struct scif_hw_dev *sdev = scifdev->sdev;
> > > +
> > > + dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_MMIO],
> > > +  p2p->sg_nentries[SCIF_PPI_MMIO], DMA_BIDIRECTIONAL);
> > 
> > Hi Sudip,
> > 
> > You missed unmapping the aperture here:
> > 
> > dma_unmap_sg(>dev, p2p->ppi_sg[SCIF_PPI_APER],
> >  p2p->sg_nentries[SCIF_PPI_APER], DMA_BIDIRECTIONAL);
> > 
> > Can you please resubmit this patch with the change above?
> 
> Hi Sudeep,
> v3 sent for your review.   
> > 
> > Also you should mention [PATCH char-misc-next] in the next revision.
> 
> Ohhh... yes, I keep forgetting that Fengguang will need this tag for
> his build bot.
> 
> But I have one more doubt. If scif_nodeqp_send() fails then shouldn't we
> remove these two nodes of the p2p connection from the lists and release
> the resources?

The resources will get cleaned up via scif_destroy_p2p(..) once they are
added to the lists.

Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-next v2 1/1] MAINTAINERS: Add maintainership for MIC drivers

2015-10-13 Thread Sudeep Dutt
Add entry for MIC drivers to the MAINTAINERS file

Signed-off-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 MAINTAINERS | 16 
 1 file changed, 16 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fe5bbfe..994a7ae 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5575,6 +5575,22 @@ F:   include/linux/mei_cl_bus.h
 F: drivers/misc/mei/*
 F: Documentation/misc-devices/mei/*
 
+INTEL MIC DRIVERS (mic)
+M: Sudeep Dutt <sudeep.d...@intel.com>
+M: Ashutosh Dixit <ashutosh.di...@intel.com>
+S: Supported
+W: https://github.com/sudeepdutt/mic
+W: http://software.intel.com/en-us/mic-developer
+F: include/linux/mic_bus.h
+F: include/linux/scif.h
+F: include/uapi/linux/mic_common.h
+F: include/uapi/linux/mic_ioctl.h
+F  include/uapi/linux/scif_ioctl.h
+F: drivers/misc/mic/
+F: drivers/dma/mic_x100_dma.c
+F: drivers/dma/mic_x100_dma.h
+F  Documentation/mic/
+
 INTEL PMC IPC DRIVER
 M: Zha Qipeng<qipeng@intel.com>
 L: platform-driver-...@vger.kernel.org
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-next 1/1] MAINTAINERS: Add maintainership for MIC drivers

2015-10-13 Thread Sudeep Dutt
Add entry for MIC drivers to the MAINTAINERS file

Signed-off-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 MAINTAINERS | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fe5bbfe..840993b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5575,6 +5575,21 @@ F:   include/linux/mei_cl_bus.h
 F: drivers/misc/mei/*
 F: Documentation/misc-devices/mei/*
 
+INTEL MIC DRIVERS (mic)
+M: Sudeep Dutt <sudeep.d...@intel.com>
+M: Ashutosh Dixit <ashutosh.di...@intel.com>
+S: Supported
+W: https://github.com/sudeepdutt/mic
+W: http://software.intel.com/en-us/mic-developer
+F: include/linux/mic_bus.h
+F: include/linux/scif.h
+F: include/uapi/linux/mic_common.h
+F: include/uapi/linux/mic_ioctl.h
+F  include/uapi/linux/scif_ioctl.h
+F: drivers/misc/mic/*
+F: drivers/dma/mic_x100_dma*
+F  Documentation/mic/*
+
 INTEL PMC IPC DRIVER
 M: Zha Qipeng<qipeng@intel.com>
 L: platform-driver-...@vger.kernel.org
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 1/2] misc: mic/scif: fix error code in scif_create_remote_lookup()

2015-10-11 Thread Sudeep Dutt
On Fri, 2015-10-09 at 09:41 +0300, Dan Carpenter wrote:
> We should be returning -ENOMEM here instead of success.
> 

Reviewed-by: Sudeep Dutt 

Thanks for the fix!

> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter 
> 
> diff --git a/drivers/misc/mic/scif/scif_rma.c 
> b/drivers/misc/mic/scif/scif_rma.c
> index e288996..bc2dccb 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -386,16 +386,20 @@ static int scif_create_remote_lookup(struct scif_dev 
> *remote_dev,
>   remote_dev, window->nr_lookup *
>   sizeof(*window->dma_addr_lookup.lookup),
>   GFP_KERNEL | __GFP_ZERO);
> - if (!window->dma_addr_lookup.lookup)
> + if (!window->dma_addr_lookup.lookup) {
> + err = -ENOMEM;
>   goto error_window;
> + }
>  
>   window->num_pages_lookup.lookup =
>   scif_alloc_coherent(>num_pages_lookup.offset,
>   remote_dev, window->nr_lookup *
>   sizeof(*window->num_pages_lookup.lookup),
>   GFP_KERNEL | __GFP_ZERO);
> - if (!window->num_pages_lookup.lookup)
> + if (!window->num_pages_lookup.lookup) {
> + err = -ENOMEM;
>   goto error_window;
> + }
>  
>   vmalloc_dma_phys = is_vmalloc_addr(>dma_addr[0]);
>   vmalloc_num_pages = is_vmalloc_addr(>num_pages[0]);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 2/2] misc: mic/scif: fix wrap around tests

2015-10-11 Thread Sudeep Dutt
On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> Signed integer overflow is undefined.  Also I added a check for
> "(offset < 0)" in scif_unregister() because that makes it match the
> other conditions and because I didn't want to subtract a negative.
> 
> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter 
> ---
> 
> Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> that we truncate it because scif_get_window_offset() takes an integer
> argument.  I don't know if this is an issue. 

scif_get_window_offset(..) takes an integer argument for the number of
pages. We believe that an int for number of 4K pages is sufficient for
current systems. I don't think there is an issue here.

>  Maybe I should use
> INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> for these types of issues:
> drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user 
> data 'len >> 12' '0-4503599627370495'
> drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user 
> data 'len >> 12' '0-4503599627370495'
> 
> The other static warnings here are:
> 
> drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: 
> inconsistent returns 'mutex:>rma_info.rma_lock'.
>   Locked on:   line 745
>   Unlocked on: line 687

The function expects the lock to be held by the caller so there is no
issue here.

> drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing 
> __func__ while the format string already contains the name of the function 
> 'scif_unpin_pages'
> 

It might be useful to enhance checkpatch to catch such issues.

> diff --git a/drivers/misc/mic/scif/scif_rma.c 
> b/drivers/misc/mic/scif/scif_rma.c
> index bc2dccb..fea7d2c 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
>   if ((map_flags & SCIF_MAP_FIXED) &&
>   ((ALIGN(offset, PAGE_SIZE) != offset) ||
>   (offset < 0) ||
> - (offset + (off_t)len < offset)))
> + (len > LONG_MAX - offset)))
>   return -EINVAL;
>  
>   might_sleep();
> @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t 
> len, off_t offset,
>   if ((map_flags & SCIF_MAP_FIXED) &&
>   ((ALIGN(offset, PAGE_SIZE) != offset) ||
>   (offset < 0) ||
> - (offset + (off_t)len < offset)))
> + (len < LONG_MAX - offset)))

Why is this change required? The earlier code was being used to detect
wraparound and I think it works fine.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 2/2] misc: mic/scif: fix wrap around tests

2015-10-11 Thread Sudeep Dutt
On Fri, 2015-10-09 at 09:40 +0300, Dan Carpenter wrote:
> Signed integer overflow is undefined.  Also I added a check for
> "(offset < 0)" in scif_unregister() because that makes it match the
> other conditions and because I didn't want to subtract a negative.
> 
> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter <dan.carpen...@oracle.com>
> ---
> 
> Imagine you are on 64 bit and len is larger than INT_MAX << 12, it means
> that we truncate it because scif_get_window_offset() takes an integer
> argument.  I don't know if this is an issue. 

scif_get_window_offset(..) takes an integer argument for the number of
pages. We believe that an int for number of 4K pages is sufficient for
current systems. I don't think there is an issue here.

>  Maybe I should use
> INT_MAX instead of LONG_MAX?  I am working on a static checker warning
> for these types of issues:
> drivers/misc/mic/scif/scif_rma.c:1631 scif_register() warn: truncating user 
> data 'len >> 12' '0-4503599627370495'
> drivers/misc/mic/scif/scif_rma.c:1643 scif_register() warn: truncating user 
> data 'len >> 12' '0-4503599627370495'
> 
> The other static warnings here are:
> 
> drivers/misc/mic/scif/scif_rma.c:745 scif_unregister_window() warn: 
> inconsistent returns 'mutex:>rma_info.rma_lock'.
>   Locked on:   line 745
>   Unlocked on: line 687

The function expects the lock to be held by the caller so there is no
issue here.

> drivers/misc/mic/scif/scif_rma.c:1463 scif_unpin_pages() warn: passing 
> __func__ while the format string already contains the name of the function 
> 'scif_unpin_pages'
> 

It might be useful to enhance checkpatch to catch such issues.

> diff --git a/drivers/misc/mic/scif/scif_rma.c 
> b/drivers/misc/mic/scif/scif_rma.c
> index bc2dccb..fea7d2c 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -1510,7 +1510,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
>   if ((map_flags & SCIF_MAP_FIXED) &&
>   ((ALIGN(offset, PAGE_SIZE) != offset) ||
>   (offset < 0) ||
> - (offset + (off_t)len < offset)))
> + (len > LONG_MAX - offset)))
>   return -EINVAL;
>  
>   might_sleep();
> @@ -1613,7 +1613,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t 
> len, off_t offset,
>   if ((map_flags & SCIF_MAP_FIXED) &&
>   ((ALIGN(offset, PAGE_SIZE) != offset) ||
>   (offset < 0) ||
> - (offset + (off_t)len < offset)))
> + (len < LONG_MAX - offset)))

Why is this change required? The earlier code was being used to detect
wraparound and I think it works fine.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 1/2] misc: mic/scif: fix error code in scif_create_remote_lookup()

2015-10-11 Thread Sudeep Dutt
On Fri, 2015-10-09 at 09:41 +0300, Dan Carpenter wrote:
> We should be returning -ENOMEM here instead of success.
> 

Reviewed-by: Sudeep Dutt <sudeep.d...@intel.com>

Thanks for the fix!

> Fixes: ba612aa8b487 ('misc: mic: SCIF memory registration and unregistration')
> Signed-off-by: Dan Carpenter <dan.carpen...@oracle.com>
> 
> diff --git a/drivers/misc/mic/scif/scif_rma.c 
> b/drivers/misc/mic/scif/scif_rma.c
> index e288996..bc2dccb 100644
> --- a/drivers/misc/mic/scif/scif_rma.c
> +++ b/drivers/misc/mic/scif/scif_rma.c
> @@ -386,16 +386,20 @@ static int scif_create_remote_lookup(struct scif_dev 
> *remote_dev,
>   remote_dev, window->nr_lookup *
>   sizeof(*window->dma_addr_lookup.lookup),
>   GFP_KERNEL | __GFP_ZERO);
> - if (!window->dma_addr_lookup.lookup)
> + if (!window->dma_addr_lookup.lookup) {
> + err = -ENOMEM;
>   goto error_window;
> + }
>  
>   window->num_pages_lookup.lookup =
>   scif_alloc_coherent(>num_pages_lookup.offset,
>   remote_dev, window->nr_lookup *
>   sizeof(*window->num_pages_lookup.lookup),
>   GFP_KERNEL | __GFP_ZERO);
> - if (!window->num_pages_lookup.lookup)
> + if (!window->num_pages_lookup.lookup) {
> + err = -ENOMEM;
>   goto error_window;
> + }
>  
>   vmalloc_dma_phys = is_vmalloc_addr(>dma_addr[0]);
>   vmalloc_num_pages = is_vmalloc_addr(>num_pages[0]);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT

2015-10-06 Thread Sudeep Dutt
On Tue, 2015-10-06 at 09:33 +0100, gre...@linuxfoundation.org wrote:
> On Tue, Oct 06, 2015 at 01:05:27AM -0700, Sudeep Dutt wrote:
> > On Tue, 2015-10-06 at 08:56 +0100, gre...@linuxfoundation.org wrote:
> > > On Mon, Oct 05, 2015 at 10:23:38PM -0700, Sudeep Dutt wrote:
> > > > On Tue, 2015-10-06 at 06:20 +0100, gre...@linuxfoundation.org wrote:
> > > > > On Tue, Oct 06, 2015 at 06:12:40AM +0100, gre...@linuxfoundation.org 
> > > > > wrote:
> > > > > > On Mon, Oct 05, 2015 at 10:38:43AM -0700, Sudeep Dutt wrote:
> > > > > > > On Mon, 2015-10-05 at 03:50 -0700, Woodhouse, David wrote:
> > > > > > > > On Tue, 2015-09-29 at 18:09 -0700, Ashutosh Dixit wrote:
> > > > > > > > > From: Sudeep Dutt 
> > > > > > > > > 
> > > > > > > > > iova is a library which can be built without IOMMU_SUPPORT
> > > > > > > > > 
> > > > > > > > > Signed-off-by: Sudeep Dutt 
> > > > > > > > 
> > > > > > > > The first three of these patches are in 4.3-rc4 already. 
> > > > > > > > Apologies for
> > > > > > > > the delay in pushing them out.
> > > > > > > > 
> > > > > > > > This one looks sane enough too, but perhaps in that case we 
> > > > > > > > should move
> > > > > > > > the code *out* of drivers/iommu/ and into lib/iova/ ?
> > > > > > > > 
> > > > > > > 
> > > > > > > Yes, moving the code into lib/iova is the correct long term 
> > > > > > > solution. I
> > > > > > > have sent Greg a patch which reverts this commit since it is no 
> > > > > > > longer
> > > > > > > required and will create a merge conflict for him unnecessarily 
> > > > > > > as well
> > > > > > > d3bd-0010
> > > > > > 
> > > > > > I can handle merge issues, that's trivial.  Reverting the patch
> > > > > > shoulnd't really be needed, right?  Let me see what happens when I 
> > > > > > merge
> > > > > > to see if your patch is necessary...
> > > > > 
> > > > > Ok, I don't think it is needed, the merge was pretty trivial.
> > > > > 
> > > > > Can you test out my char-misc-testing branch right now to see if it's
> > > > > all ok with the merge?  If so, I'll move it all over to the "real" 
> > > > > place
> > > > > for it to start showing up in linux-next, i.e. my char-misc-next 
> > > > > branch.
> > > > > 
> > > > 
> > > > Hi Greg,
> > > > 
> > > > I think it is best to revert this patch as it is incorrect. The iommu
> > > > folder gets compiled only if IOMMU_SUPPORT is enabled so IOMMU_IOVA
> > > > should indeed be included only when IOMMU_SUPPORT is enabled.
> > > > 
> > > > Sincere apologies for the mess here but I believe it will all get fixed
> > > > up if you accept the revert of 353649e5da I sent across earlier today.
> > > 
> > > Again, look at the merge, I think I already handled this in that manner.
> > > If not, let me know.
> > > 
> > 
> > Hi Greg,
> > 
> > I took a look at your latest char-misc-testing tree and it needs to be
> > fixed up. IOMMU_IOVA should be inside the "if IOMMU_SUPPORT" block
> > instead of above it.
> > 
> > git revert 353649e5da in the char-misc-testing tree will fix everything
> > up or you could also apply the patch I sent earlier today which has the
> > same revert.
> 
> Ok, I've applied your patch, rolled back the merge, and that should be
> good, right?  If so, I'll push this branch out to char-misc-next and
> then merge in 4.3-rc4 just to keep everything up to date.

Yes, it looks good now.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT

2015-10-06 Thread Sudeep Dutt
On Tue, 2015-10-06 at 08:56 +0100, gre...@linuxfoundation.org wrote:
> On Mon, Oct 05, 2015 at 10:23:38PM -0700, Sudeep Dutt wrote:
> > On Tue, 2015-10-06 at 06:20 +0100, gre...@linuxfoundation.org wrote:
> > > On Tue, Oct 06, 2015 at 06:12:40AM +0100, gre...@linuxfoundation.org 
> > > wrote:
> > > > On Mon, Oct 05, 2015 at 10:38:43AM -0700, Sudeep Dutt wrote:
> > > > > On Mon, 2015-10-05 at 03:50 -0700, Woodhouse, David wrote:
> > > > > > On Tue, 2015-09-29 at 18:09 -0700, Ashutosh Dixit wrote:
> > > > > > > From: Sudeep Dutt 
> > > > > > > 
> > > > > > > iova is a library which can be built without IOMMU_SUPPORT
> > > > > > > 
> > > > > > > Signed-off-by: Sudeep Dutt 
> > > > > > 
> > > > > > The first three of these patches are in 4.3-rc4 already. Apologies 
> > > > > > for
> > > > > > the delay in pushing them out.
> > > > > > 
> > > > > > This one looks sane enough too, but perhaps in that case we should 
> > > > > > move
> > > > > > the code *out* of drivers/iommu/ and into lib/iova/ ?
> > > > > > 
> > > > > 
> > > > > Yes, moving the code into lib/iova is the correct long term solution. 
> > > > > I
> > > > > have sent Greg a patch which reverts this commit since it is no longer
> > > > > required and will create a merge conflict for him unnecessarily as 
> > > > > well
> > > > > with 4.3-rc4.
> > > > 
> > > > I can handle merge issues, that's trivial.  Reverting the patch
> > > > shoulnd't really be needed, right?  Let me see what happens when I merge
> > > > to see if your patch is necessary...
> > > 
> > > Ok, I don't think it is needed, the merge was pretty trivial.
> > > 
> > > Can you test out my char-misc-testing branch right now to see if it's
> > > all ok with the merge?  If so, I'll move it all over to the "real" place
> > > for it to start showing up in linux-next, i.e. my char-misc-next branch.
> > > 
> > 
> > Hi Greg,
> > 
> > I think it is best to revert this patch as it is incorrect. The iommu
> > folder gets compiled only if IOMMU_SUPPORT is enabled so IOMMU_IOVA
> > should indeed be included only when IOMMU_SUPPORT is enabled.
> > 
> > Sincere apologies for the mess here but I believe it will all get fixed
> > up if you accept the revert of 353649e5da I sent across earlier today.
> 
> Again, look at the merge, I think I already handled this in that manner.
> If not, let me know.
> 

Hi Greg,

I took a look at your latest char-misc-testing tree and it needs to be
fixed up. IOMMU_IOVA should be inside the "if IOMMU_SUPPORT" block
instead of above it.

git revert 353649e5da in the char-misc-testing tree will fix everything
up or you could also apply the patch I sent earlier today which has the
same revert.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT

2015-10-06 Thread Sudeep Dutt
On Tue, 2015-10-06 at 08:56 +0100, gre...@linuxfoundation.org wrote:
> On Mon, Oct 05, 2015 at 10:23:38PM -0700, Sudeep Dutt wrote:
> > On Tue, 2015-10-06 at 06:20 +0100, gre...@linuxfoundation.org wrote:
> > > On Tue, Oct 06, 2015 at 06:12:40AM +0100, gre...@linuxfoundation.org 
> > > wrote:
> > > > On Mon, Oct 05, 2015 at 10:38:43AM -0700, Sudeep Dutt wrote:
> > > > > On Mon, 2015-10-05 at 03:50 -0700, Woodhouse, David wrote:
> > > > > > On Tue, 2015-09-29 at 18:09 -0700, Ashutosh Dixit wrote:
> > > > > > > From: Sudeep Dutt <sudeep.d...@intel.com>
> > > > > > > 
> > > > > > > iova is a library which can be built without IOMMU_SUPPORT
> > > > > > > 
> > > > > > > Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
> > > > > > 
> > > > > > The first three of these patches are in 4.3-rc4 already. Apologies 
> > > > > > for
> > > > > > the delay in pushing them out.
> > > > > > 
> > > > > > This one looks sane enough too, but perhaps in that case we should 
> > > > > > move
> > > > > > the code *out* of drivers/iommu/ and into lib/iova/ ?
> > > > > > 
> > > > > 
> > > > > Yes, moving the code into lib/iova is the correct long term solution. 
> > > > > I
> > > > > have sent Greg a patch which reverts this commit since it is no longer
> > > > > required and will create a merge conflict for him unnecessarily as 
> > > > > well
> > > > > with 4.3-rc4.
> > > > 
> > > > I can handle merge issues, that's trivial.  Reverting the patch
> > > > shoulnd't really be needed, right?  Let me see what happens when I merge
> > > > to see if your patch is necessary...
> > > 
> > > Ok, I don't think it is needed, the merge was pretty trivial.
> > > 
> > > Can you test out my char-misc-testing branch right now to see if it's
> > > all ok with the merge?  If so, I'll move it all over to the "real" place
> > > for it to start showing up in linux-next, i.e. my char-misc-next branch.
> > > 
> > 
> > Hi Greg,
> > 
> > I think it is best to revert this patch as it is incorrect. The iommu
> > folder gets compiled only if IOMMU_SUPPORT is enabled so IOMMU_IOVA
> > should indeed be included only when IOMMU_SUPPORT is enabled.
> > 
> > Sincere apologies for the mess here but I believe it will all get fixed
> > up if you accept the revert of 353649e5da I sent across earlier today.
> 
> Again, look at the merge, I think I already handled this in that manner.
> If not, let me know.
> 

Hi Greg,

I took a look at your latest char-misc-testing tree and it needs to be
fixed up. IOMMU_IOVA should be inside the "if IOMMU_SUPPORT" block
instead of above it.

git revert 353649e5da in the char-misc-testing tree will fix everything
up or you could also apply the patch I sent earlier today which has the
same revert.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT

2015-10-06 Thread Sudeep Dutt
On Tue, 2015-10-06 at 09:33 +0100, gre...@linuxfoundation.org wrote:
> On Tue, Oct 06, 2015 at 01:05:27AM -0700, Sudeep Dutt wrote:
> > On Tue, 2015-10-06 at 08:56 +0100, gre...@linuxfoundation.org wrote:
> > > On Mon, Oct 05, 2015 at 10:23:38PM -0700, Sudeep Dutt wrote:
> > > > On Tue, 2015-10-06 at 06:20 +0100, gre...@linuxfoundation.org wrote:
> > > > > On Tue, Oct 06, 2015 at 06:12:40AM +0100, gre...@linuxfoundation.org 
> > > > > wrote:
> > > > > > On Mon, Oct 05, 2015 at 10:38:43AM -0700, Sudeep Dutt wrote:
> > > > > > > On Mon, 2015-10-05 at 03:50 -0700, Woodhouse, David wrote:
> > > > > > > > On Tue, 2015-09-29 at 18:09 -0700, Ashutosh Dixit wrote:
> > > > > > > > > From: Sudeep Dutt <sudeep.d...@intel.com>
> > > > > > > > > 
> > > > > > > > > iova is a library which can be built without IOMMU_SUPPORT
> > > > > > > > > 
> > > > > > > > > Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
> > > > > > > > 
> > > > > > > > The first three of these patches are in 4.3-rc4 already. 
> > > > > > > > Apologies for
> > > > > > > > the delay in pushing them out.
> > > > > > > > 
> > > > > > > > This one looks sane enough too, but perhaps in that case we 
> > > > > > > > should move
> > > > > > > > the code *out* of drivers/iommu/ and into lib/iova/ ?
> > > > > > > > 
> > > > > > > 
> > > > > > > Yes, moving the code into lib/iova is the correct long term 
> > > > > > > solution. I
> > > > > > > have sent Greg a patch which reverts this commit since it is no 
> > > > > > > longer
> > > > > > > required and will create a merge conflict for him unnecessarily 
> > > > > > > as well
> > > > > > > d3bd-0010
> > > > > > 
> > > > > > I can handle merge issues, that's trivial.  Reverting the patch
> > > > > > shoulnd't really be needed, right?  Let me see what happens when I 
> > > > > > merge
> > > > > > to see if your patch is necessary...
> > > > > 
> > > > > Ok, I don't think it is needed, the merge was pretty trivial.
> > > > > 
> > > > > Can you test out my char-misc-testing branch right now to see if it's
> > > > > all ok with the merge?  If so, I'll move it all over to the "real" 
> > > > > place
> > > > > for it to start showing up in linux-next, i.e. my char-misc-next 
> > > > > branch.
> > > > > 
> > > > 
> > > > Hi Greg,
> > > > 
> > > > I think it is best to revert this patch as it is incorrect. The iommu
> > > > folder gets compiled only if IOMMU_SUPPORT is enabled so IOMMU_IOVA
> > > > should indeed be included only when IOMMU_SUPPORT is enabled.
> > > > 
> > > > Sincere apologies for the mess here but I believe it will all get fixed
> > > > up if you accept the revert of 353649e5da I sent across earlier today.
> > > 
> > > Again, look at the merge, I think I already handled this in that manner.
> > > If not, let me know.
> > > 
> > 
> > Hi Greg,
> > 
> > I took a look at your latest char-misc-testing tree and it needs to be
> > fixed up. IOMMU_IOVA should be inside the "if IOMMU_SUPPORT" block
> > instead of above it.
> > 
> > git revert 353649e5da in the char-misc-testing tree will fix everything
> > up or you could also apply the patch I sent earlier today which has the
> > same revert.
> 
> Ok, I've applied your patch, rolled back the merge, and that should be
> good, right?  If so, I'll push this branch out to char-misc-next and
> then merge in 4.3-rc4 just to keep everything up to date.

Yes, it looks good now.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT

2015-10-05 Thread Sudeep Dutt
On Tue, 2015-10-06 at 06:20 +0100, gre...@linuxfoundation.org wrote:
> On Tue, Oct 06, 2015 at 06:12:40AM +0100, gre...@linuxfoundation.org wrote:
> > On Mon, Oct 05, 2015 at 10:38:43AM -0700, Sudeep Dutt wrote:
> > > On Mon, 2015-10-05 at 03:50 -0700, Woodhouse, David wrote:
> > > > On Tue, 2015-09-29 at 18:09 -0700, Ashutosh Dixit wrote:
> > > > > From: Sudeep Dutt 
> > > > > 
> > > > > iova is a library which can be built without IOMMU_SUPPORT
> > > > > 
> > > > > Signed-off-by: Sudeep Dutt 
> > > > 
> > > > The first three of these patches are in 4.3-rc4 already. Apologies for
> > > > the delay in pushing them out.
> > > > 
> > > > This one looks sane enough too, but perhaps in that case we should move
> > > > the code *out* of drivers/iommu/ and into lib/iova/ ?
> > > > 
> > > 
> > > Yes, moving the code into lib/iova is the correct long term solution. I
> > > have sent Greg a patch which reverts this commit since it is no longer
> > > required and will create a merge conflict for him unnecessarily as well
> > > with 4.3-rc4.
> > 
> > I can handle merge issues, that's trivial.  Reverting the patch
> > shoulnd't really be needed, right?  Let me see what happens when I merge
> > to see if your patch is necessary...
> 
> Ok, I don't think it is needed, the merge was pretty trivial.
> 
> Can you test out my char-misc-testing branch right now to see if it's
> all ok with the merge?  If so, I'll move it all over to the "real" place
> for it to start showing up in linux-next, i.e. my char-misc-next branch.
> 

Hi Greg,

I think it is best to revert this patch as it is incorrect. The iommu
folder gets compiled only if IOMMU_SUPPORT is enabled so IOMMU_IOVA
should indeed be included only when IOMMU_SUPPORT is enabled.

Sincere apologies for the mess here but I believe it will all get fixed
up if you accept the revert of 353649e5da I sent across earlier today.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT

2015-10-05 Thread Sudeep Dutt
On Mon, 2015-10-05 at 03:50 -0700, Woodhouse, David wrote:
> On Tue, 2015-09-29 at 18:09 -0700, Ashutosh Dixit wrote:
> > From: Sudeep Dutt 
> > 
> > iova is a library which can be built without IOMMU_SUPPORT
> > 
> > Signed-off-by: Sudeep Dutt 
> 
> The first three of these patches are in 4.3-rc4 already. Apologies for
> the delay in pushing them out.
> 
> This one looks sane enough too, but perhaps in that case we should move
> the code *out* of drivers/iommu/ and into lib/iova/ ?
> 

Yes, moving the code into lib/iova is the correct long term solution. I
have sent Greg a patch which reverts this commit since it is no longer
required and will create a merge conflict for him unnecessarily as well
with 4.3-rc4.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-testing 1/1] Revert "iommu: Allow iova to be used without requiring IOMMU_SUPPORT"

2015-10-05 Thread Sudeep Dutt
Revert 'commit 353649e5da90 ("iommu: Allow iova to be used without
requiring IOMMU_SUPPORT"). This commit is made unnecessary by
'commit ac6d83ccd9c5 ("misc: mic: Fix SCIF build failure with
IOMMU_SUPPORT disabled") and will create a conflict upon merging
with 4.3-rc4. The correct long term solution is to move the iova
library from drivers/iommu into lib/iova which will be done in
a future patch.

Cc: David Woodhouse 
Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/iommu/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 71d1c46..d9da766 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -12,9 +12,6 @@ menuconfig IOMMU_SUPPORT
  remap DMA requests and/or remap interrupts from other devices on the
  system.
 
-config IOMMU_IOVA
-   tristate
-
 if IOMMU_SUPPORT
 
 menu "Generic IOMMU Pagetable Support"
@@ -45,6 +42,9 @@ config IOMMU_IO_PGTABLE_LPAE_SELFTEST
 
 endmenu
 
+config IOMMU_IOVA
+   tristate
+
 config OF_IOMMU
def_bool y
depends on OF && IOMMU_API
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-testing 1/1] Revert "iommu: Allow iova to be used without requiring IOMMU_SUPPORT"

2015-10-05 Thread Sudeep Dutt
Revert 'commit 353649e5da90 ("iommu: Allow iova to be used without
requiring IOMMU_SUPPORT"). This commit is made unnecessary by
'commit ac6d83ccd9c5 ("misc: mic: Fix SCIF build failure with
IOMMU_SUPPORT disabled") and will create a conflict upon merging
with 4.3-rc4. The correct long term solution is to move the iova
library from drivers/iommu into lib/iova which will be done in
a future patch.

Cc: David Woodhouse <david.woodho...@intel.com>
Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/iommu/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 71d1c46..d9da766 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -12,9 +12,6 @@ menuconfig IOMMU_SUPPORT
  remap DMA requests and/or remap interrupts from other devices on the
  system.
 
-config IOMMU_IOVA
-   tristate
-
 if IOMMU_SUPPORT
 
 menu "Generic IOMMU Pagetable Support"
@@ -45,6 +42,9 @@ config IOMMU_IO_PGTABLE_LPAE_SELFTEST
 
 endmenu
 
+config IOMMU_IOVA
+   tristate
+
 config OF_IOMMU
def_bool y
depends on OF && IOMMU_API
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT

2015-10-05 Thread Sudeep Dutt
On Mon, 2015-10-05 at 03:50 -0700, Woodhouse, David wrote:
> On Tue, 2015-09-29 at 18:09 -0700, Ashutosh Dixit wrote:
> > From: Sudeep Dutt <sudeep.d...@intel.com>
> > 
> > iova is a library which can be built without IOMMU_SUPPORT
> > 
> > Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
> 
> The first three of these patches are in 4.3-rc4 already. Apologies for
> the delay in pushing them out.
> 
> This one looks sane enough too, but perhaps in that case we should move
> the code *out* of drivers/iommu/ and into lib/iova/ ?
> 

Yes, moving the code into lib/iova is the correct long term solution. I
have sent Greg a patch which reverts this commit since it is no longer
required and will create a merge conflict for him unnecessarily as well
with 4.3-rc4.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT

2015-10-05 Thread Sudeep Dutt
On Tue, 2015-10-06 at 06:20 +0100, gre...@linuxfoundation.org wrote:
> On Tue, Oct 06, 2015 at 06:12:40AM +0100, gre...@linuxfoundation.org wrote:
> > On Mon, Oct 05, 2015 at 10:38:43AM -0700, Sudeep Dutt wrote:
> > > On Mon, 2015-10-05 at 03:50 -0700, Woodhouse, David wrote:
> > > > On Tue, 2015-09-29 at 18:09 -0700, Ashutosh Dixit wrote:
> > > > > From: Sudeep Dutt <sudeep.d...@intel.com>
> > > > > 
> > > > > iova is a library which can be built without IOMMU_SUPPORT
> > > > > 
> > > > > Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
> > > > 
> > > > The first three of these patches are in 4.3-rc4 already. Apologies for
> > > > the delay in pushing them out.
> > > > 
> > > > This one looks sane enough too, but perhaps in that case we should move
> > > > the code *out* of drivers/iommu/ and into lib/iova/ ?
> > > > 
> > > 
> > > Yes, moving the code into lib/iova is the correct long term solution. I
> > > have sent Greg a patch which reverts this commit since it is no longer
> > > required and will create a merge conflict for him unnecessarily as well
> > > with 4.3-rc4.
> > 
> > I can handle merge issues, that's trivial.  Reverting the patch
> > shoulnd't really be needed, right?  Let me see what happens when I merge
> > to see if your patch is necessary...
> 
> Ok, I don't think it is needed, the merge was pretty trivial.
> 
> Can you test out my char-misc-testing branch right now to see if it's
> all ok with the merge?  If so, I'll move it all over to the "real" place
> for it to start showing up in linux-next, i.e. my char-misc-next branch.
> 

Hi Greg,

I think it is best to revert this patch as it is incorrect. The iommu
folder gets compiled only if IOMMU_SUPPORT is enabled so IOMMU_IOVA
should indeed be included only when IOMMU_SUPPORT is enabled.

Sincere apologies for the mess here but I believe it will all get fixed
up if you accept the revert of 353649e5da I sent across earlier today.

Thanks,
Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-next 1/1] misc: mic: Fix SCIF build failure with IOMMU_SUPPORT disabled

2015-10-04 Thread Sudeep Dutt
SCIF depends on IOVA which requires IOMMU_SUPPORT to be enabled.
The long term fix is to move IOVA from drivers/iommu to lib/
but this current patch should fix the reported issue.

Reported-by: Fengguang Wu 
Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 60376fb..40677df 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -74,7 +74,7 @@ comment "SCIF Driver"
 
 config SCIF
tristate "SCIF Driver"
-   depends on 64BIT && PCI && X86 && SCIF_BUS
+   depends on 64BIT && PCI && X86 && SCIF_BUS && IOMMU_SUPPORT
select IOMMU_IOVA
help
  This enables SCIF Driver support for the Intel Many Integrated
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-next 1/1] misc: mic: Fix SCIF build failure with IOMMU_SUPPORT disabled

2015-10-04 Thread Sudeep Dutt
SCIF depends on IOVA which requires IOMMU_SUPPORT to be enabled.
The long term fix is to move IOVA from drivers/iommu to lib/
but this current patch should fix the reported issue.

Reported-by: Fengguang Wu <fengguang...@intel.com>
Reviewed-by: Ashutosh Dixit <ashutosh.di...@intel.com>
Signed-off-by: Sudeep Dutt <sudeep.d...@intel.com>
---
 drivers/misc/mic/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 60376fb..40677df 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -74,7 +74,7 @@ comment "SCIF Driver"
 
 config SCIF
tristate "SCIF Driver"
-   depends on 64BIT && PCI && X86 && SCIF_BUS
+   depends on 64BIT && PCI && X86 && SCIF_BUS && IOMMU_SUPPORT
select IOMMU_IOVA
help
  This enables SCIF Driver support for the Intel Many Integrated
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next 11/19] dma: Add support to program MIC x100 status descriptiors

2015-08-21 Thread Sudeep Dutt
On Fri, 2015-08-21 at 13:59 +0530, Vinod Koul wrote:
> On Thu, Aug 20, 2015 at 10:30:50AM -0700, Sudeep Dutt wrote:
> > On Thu, 2015-08-20 at 10:50 +0530, Vinod Koul wrote:
> > > On Mon, Jul 27, 2015 at 04:58:17PM -0700, Ashutosh Dixit wrote:
> 
> > > > +   /*
> > > > +* This is a hack to program status descriptor since
> > > > +* DMA engine API doesn't have support for this.
> > > > +*/
> > > what do you mean by programming status descriptor, what do you need to
> > > program?
> > > 
> > 
> > The MIC X100 DMA engine has a special status descriptor which writes an
> > 8 byte immediate data value to a destination address. It is used to
> > signal completion of all DMA descriptors prior to the status descriptor.
> > The DMA engine API does not allow drivers to pass a 8 byte value. We are
> > allowed to pass a source physical address but we cannot determine the
> > source value within the DMA driver using that information specifically
> > with the IOMMU enabled. We have added this workaround so that we can
> > program this special status update descriptor without making any changes
> > to the DMA engine API.
> I think this is a special case so you should export an API and let client
> program using that API.
> 

Sounds good. We will export a new API from the MIC X100 DMA driver in
the next revision of this patch series.

Thanks for the review!

Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next 11/19] dma: Add support to program MIC x100 status descriptiors

2015-08-21 Thread Sudeep Dutt
On Fri, 2015-08-21 at 13:59 +0530, Vinod Koul wrote:
 On Thu, Aug 20, 2015 at 10:30:50AM -0700, Sudeep Dutt wrote:
  On Thu, 2015-08-20 at 10:50 +0530, Vinod Koul wrote:
   On Mon, Jul 27, 2015 at 04:58:17PM -0700, Ashutosh Dixit wrote:
 
+   /*
+* This is a hack to program status descriptor since
+* DMA engine API doesn't have support for this.
+*/
   what do you mean by programming status descriptor, what do you need to
   program?
   
  
  The MIC X100 DMA engine has a special status descriptor which writes an
  8 byte immediate data value to a destination address. It is used to
  signal completion of all DMA descriptors prior to the status descriptor.
  The DMA engine API does not allow drivers to pass a 8 byte value. We are
  allowed to pass a source physical address but we cannot determine the
  source value within the DMA driver using that information specifically
  with the IOMMU enabled. We have added this workaround so that we can
  program this special status update descriptor without making any changes
  to the DMA engine API.
 I think this is a special case so you should export an API and let client
 program using that API.
 

Sounds good. We will export a new API from the MIC X100 DMA driver in
the next revision of this patch series.

Thanks for the review!

Sudeep Dutt

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next 11/19] dma: Add support to program MIC x100 status descriptiors

2015-08-20 Thread Sudeep Dutt
On Thu, 2015-08-20 at 10:50 +0530, Vinod Koul wrote:
> On Mon, Jul 27, 2015 at 04:58:17PM -0700, Ashutosh Dixit wrote:
> > +/* Program a status descriptor with phys as address and value to be 
> > written */
> > +static int mic_dma_do_status_update(struct mic_dma_chan *ch, dma_addr_t 
> > phys,
> > +   u64 value)
> > +{
> > +   int ret = mic_dma_avail_desc_ring_space(ch, 4);
> > +
> > +   if (ret < 0)
> > +   return ret;
> > +   ret = 0;
> ?
> > +   mic_dma_prep_status_desc(>desc_ring[ch->head],
> > +value, phys, false);
> > +   mic_dma_hw_ring_inc_head(ch);
> > +   return ret;
> 
> return 0 then?
> 

Sounds good. We will change this in the next revision of the patch
series which will be posted after the 4.3 merge window closes.

> > +}
> > +
> >  static inline void mic_dma_issue_pending(struct dma_chan *ch)
> >  {
> > struct mic_dma_chan *mic_ch = to_mic_dma_chan(ch);
> > @@ -287,9 +310,28 @@ mic_dma_prep_memcpy_lock(struct dma_chan *ch, 
> > dma_addr_t dma_dest,
> > return NULL;
> >  
> > spin_lock(_ch->prep_lock);
> > +   if (len == 8) {
> magic number?
> 

The MIC X100 DMA engine requires cache line (64 bytes) aligned
src/dst/len. We use the length of 8 bytes as a special case for
programming the status descriptor since it writes an 8 byte value. We
will use a macro in the next revision of the patch series.

> > +   /*
> > +* This is a hack to program status descriptor since
> > +* DMA engine API doesn't have support for this.
> > +*/
> what do you mean by programming status descriptor, what do you need to
> program?
> 

The MIC X100 DMA engine has a special status descriptor which writes an
8 byte immediate data value to a destination address. It is used to
signal completion of all DMA descriptors prior to the status descriptor.
The DMA engine API does not allow drivers to pass a 8 byte value. We are
allowed to pass a source physical address but we cannot determine the
source value within the DMA driver using that information specifically
with the IOMMU enabled. We have added this workaround so that we can
program this special status update descriptor without making any changes
to the DMA engine API.

Thanks for the review!

Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next 11/19] dma: Add support to program MIC x100 status descriptiors

2015-08-20 Thread Sudeep Dutt
On Thu, 2015-08-20 at 10:50 +0530, Vinod Koul wrote:
 On Mon, Jul 27, 2015 at 04:58:17PM -0700, Ashutosh Dixit wrote:
  +/* Program a status descriptor with phys as address and value to be 
  written */
  +static int mic_dma_do_status_update(struct mic_dma_chan *ch, dma_addr_t 
  phys,
  +   u64 value)
  +{
  +   int ret = mic_dma_avail_desc_ring_space(ch, 4);
  +
  +   if (ret  0)
  +   return ret;
  +   ret = 0;
 ?
  +   mic_dma_prep_status_desc(ch-desc_ring[ch-head],
  +value, phys, false);
  +   mic_dma_hw_ring_inc_head(ch);
  +   return ret;
 
 return 0 then?
 

Sounds good. We will change this in the next revision of the patch
series which will be posted after the 4.3 merge window closes.

  +}
  +
   static inline void mic_dma_issue_pending(struct dma_chan *ch)
   {
  struct mic_dma_chan *mic_ch = to_mic_dma_chan(ch);
  @@ -287,9 +310,28 @@ mic_dma_prep_memcpy_lock(struct dma_chan *ch, 
  dma_addr_t dma_dest,
  return NULL;
   
  spin_lock(mic_ch-prep_lock);
  +   if (len == 8) {
 magic number?
 

The MIC X100 DMA engine requires cache line (64 bytes) aligned
src/dst/len. We use the length of 8 bytes as a special case for
programming the status descriptor since it writes an 8 byte value. We
will use a macro in the next revision of the patch series.

  +   /*
  +* This is a hack to program status descriptor since
  +* DMA engine API doesn't have support for this.
  +*/
 what do you mean by programming status descriptor, what do you need to
 program?
 

The MIC X100 DMA engine has a special status descriptor which writes an
8 byte immediate data value to a destination address. It is used to
signal completion of all DMA descriptors prior to the status descriptor.
The DMA engine API does not allow drivers to pass a 8 byte value. We are
allowed to pass a source physical address but we cannot determine the
source value within the DMA driver using that information specifically
with the IOMMU enabled. We have added this workaround so that we can
program this special status update descriptor without making any changes
to the DMA engine API.

Thanks for the review!

Sudeep Dutt

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next 10/19] lib: convert iova.c into a library

2015-07-28 Thread Sudeep Dutt
On Tue, 2015-07-28 at 15:38 +0100, David Woodhouse wrote:
> On Tue, 2015-07-28 at 11:41 +0100, Robin Murphy wrote:
> > On 28/07/15 11:03, Joerg Roedel wrote:
> > > On Mon, Jul 27, 2015 at 04:57:32PM -0700, Ashutosh Dixit wrote:
> > > > From: Harish Chegondi 
> > > > 
> > > > This patch converts iova.c into a library, moving it from
> > > > drivers/iommu/ to lib/, and exports its virtual address 
> > > > allocation and
> > > > management functions so that other modules can reuse them.
> > > > 
> > > > Cc: Joerg Roedel 
> > > > Reviewed-by: Anil S Keshavamurthy  > > > >
> > > > Reviewed-by: Sudeep Dutt 
> > > > Signed-off-by: Harish Chegondi 
> > > 
> > > Where is this going to be used outside of the IOMMU world?
> > > 

We are using the IOVA generator in the SCIF driver posted @
http://thread.gmane.org/gmane.linux.kernel/2005895 under
drivers/misc/mic/scif

> > 
> > ...and how does it relate to the patches from Sakari (+CC) doing much 
> > the same thing[1]?
> 

The patch series from Sakari does the right thing by moving the IOVA
cache management to the IOVA library. We will simply drop this current
patch as it is incorrect.

> I merged Sakari's patches into the intel-iommu git tree today, FWIW.
> 
> If there's really a need to move it from drivers/iommu/ to lib/ then we
> could feasibly do that too.
> 

The patch series from Sakari should work perfectly for us. We will post
a v2 of the current SCIF patch series without this IOVA patch and modify
the SCIF driver to use the newly added iova_cache_get(..) and
iova_cache_put(..) APIs once it is available in Linus's tree. It would
make it easier for us to integrate if Sakari's patches reach mainline
soon.

It might be cleaner to move IOVA to lib/ in the longer term since we
will have multiple driver subsystems using it, but it should work just
fine for now.

Thanks for the review!

Sudeep Dutt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH char-misc-next 10/19] lib: convert iova.c into a library

2015-07-28 Thread Sudeep Dutt
On Tue, 2015-07-28 at 15:38 +0100, David Woodhouse wrote:
 On Tue, 2015-07-28 at 11:41 +0100, Robin Murphy wrote:
  On 28/07/15 11:03, Joerg Roedel wrote:
   On Mon, Jul 27, 2015 at 04:57:32PM -0700, Ashutosh Dixit wrote:
From: Harish Chegondi harish.chego...@intel.com

This patch converts iova.c into a library, moving it from
drivers/iommu/ to lib/, and exports its virtual address 
allocation and
management functions so that other modules can reuse them.

Cc: Joerg Roedel j...@8bytes.org
Reviewed-by: Anil S Keshavamurthy anil.s.keshavamur...@intel.com

Reviewed-by: Sudeep Dutt sudeep.d...@intel.com
Signed-off-by: Harish Chegondi harish.chego...@intel.com
   
   Where is this going to be used outside of the IOMMU world?
   

We are using the IOVA generator in the SCIF driver posted @
http://thread.gmane.org/gmane.linux.kernel/2005895 under
drivers/misc/mic/scif

  
  ...and how does it relate to the patches from Sakari (+CC) doing much 
  the same thing[1]?
 

The patch series from Sakari does the right thing by moving the IOVA
cache management to the IOVA library. We will simply drop this current
patch as it is incorrect.

 I merged Sakari's patches into the intel-iommu git tree today, FWIW.
 
 If there's really a need to move it from drivers/iommu/ to lib/ then we
 could feasibly do that too.
 

The patch series from Sakari should work perfectly for us. We will post
a v2 of the current SCIF patch series without this IOVA patch and modify
the SCIF driver to use the newly added iova_cache_get(..) and
iova_cache_put(..) APIs once it is available in Linus's tree. It would
make it easier for us to integrate if Sakari's patches reach mainline
soon.

It might be cleaner to move IOVA to lib/ in the longer term since we
will have multiple driver subsystems using it, but it should work just
fine for now.

Thanks for the review!

Sudeep Dutt

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH char-misc-next 2/2] misc: mic: Fix reported static checker warning

2015-06-09 Thread Sudeep Dutt
Delete unnecessary prints resulting in an "spdev could be null"
warning from a static checker in scif_peer_remove(..).

Reported-by: Dan Carpenter 
Reviewed-by: Ashutosh Dixit 
Signed-off-by: Sudeep Dutt 
---
 drivers/misc/mic/scif/scif_main.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/misc/mic/scif/scif_main.c 
b/drivers/misc/mic/scif/scif_main.c
index f7187dc..6ce851f 100644
--- a/drivers/misc/mic/scif/scif_main.c
+++ b/drivers/misc/mic/scif/scif_main.c
@@ -91,8 +91,6 @@ static int scif_peer_probe(struct scif_peer_dev *spdev)
rcu_assign_pointer(scifdev->spdev, spdev);
 
/* In the future SCIF kernel client devices will be added here */
-   dev_info(>dev, "Peer added dnode %d\n",
-spdev->dnode);
return 0;
 }
 
@@ -109,8 +107,6 @@ static void scif_peer_remove(struct scif_peer_dev *spdev)
mutex_lock(_info.conflock);
scif_info.total--;
mutex_unlock(_info.conflock);
-   dev_info(>dev, "Peer removed dnode %d\n",
-spdev->dnode);
 }
 
 static void scif_qp_setup_handler(struct work_struct *work)
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   3   4   5   >