Re: [PATCH char-misc-next 2/8] misc: mic: add a bus driver for virtual MIC devices

2014-05-28 Thread Sudeep Dutt
On Wed, 2014-05-28 at 13:50 -0700, Greg Kroah-Hartman wrote: 
> On Tue, May 27, 2014 at 07:36:11PM -0700, Sudeep Dutt wrote:
> > +int register_mbus_driver(struct mbus_driver *driver)
> > +{
> > +   driver->driver.bus = _bus;
> > +   return driver_register(>driver);
> > +}
> > +EXPORT_SYMBOL_GPL(register_mbus_driver);
> 
> mbus_register_driver()?
> 

The idea was to follow the register_virtio_driver(..) naming convention
but will rename as your suggestion is better.

> > +void unregister_mbus_driver(struct mbus_driver *driver)
> > +{
> > +   driver_unregister(>driver);
> > +}
> > +EXPORT_SYMBOL_GPL(unregister_mbus_driver);
> 
> mbus_unregister_driver()?

Will rename.

> 
> > +int register_mbus_device(struct mbus_device *dev)
> 
> mbus_register_device()?
> 
> Trying to keep the kernel namespace sane.

Will rename.

> 
> Why doesn't this function create the device structure?
> 

The mbus_device containing the device structure is allocated by the
driver calling this API. However that creates other issues as you
highlighted below. It is better to allocate mbus_device here so that it
can be freed in the device release callback correctly by the bus driver.

> > +{
> > +   int err;
> > +
> > +   dev->dev.bus = _bus;
> > +
> > +   /* Assign a unique device index and hence name. */
> > +   err = ida_simple_get(_index_ida, 0, 0, GFP_KERNEL);
> > +   if (err < 0)
> > +   return err;
> > +
> > +   dev->index = err;
> > +   dev_set_name(>dev, "mbus-dev%u", dev->index);
> > +   /*
> > +* device_register() causes the bus infrastructure to look for a
> > +* matching driver.
> > +*/
> > +   err = device_register(>dev);
> > +   return err;
> > +}
> > +EXPORT_SYMBOL_GPL(register_mbus_device);
> > +
> > +void unregister_mbus_device(struct mbus_device *dev)
> > +{
> > +   int index = dev->index; /* save for after device release */
> > +
> > +   device_unregister(>dev);
> > +   ida_simple_remove(_index_ida, index);
> > +}
> > +EXPORT_SYMBOL_GPL(unregister_mbus_device);
> > +
> > +static int __init mbus_init(void)
> > +{
> > +   return bus_register(_bus);
> > +}
> > +
> > +static void __exit mbus_exit(void)
> > +{
> > +   bus_unregister(_bus);
> > +}
> > +
> > +core_initcall(mbus_init);
> > +module_exit(mbus_exit);
> > +
> > +MODULE_AUTHOR("Intel Corporation");
> > +MODULE_DESCRIPTION("Intel(R) MIC Bus driver");
> > +MODULE_LICENSE("GPL v2");
> > diff --git a/include/linux/mic_bus.h b/include/linux/mic_bus.h
> > new file mode 100644
> > index 000..8297573
> > --- /dev/null
> > +++ b/include/linux/mic_bus.h
> > @@ -0,0 +1,148 @@
> > +/*
> > + * Intel MIC Platform Software Stack (MPSS)
> > + *
> > + * Copyright(c) 2014 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 Bus driver.
> > + *
> > + * This implementation is very similar to the the virtio bus driver
> > + * implementation @ include/linux/virtio.h.
> > + */
> > +#ifndef _MIC_BUS_H_
> > +#define _MIC_BUS_H_
> > +/*
> > + * Everything a mbus driver needs to work with any particular mbus
> > + * implementation.
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +struct mbus_device_id {
> > +   __u32 device;
> > +   __u32 vendor;
> > +};
> > +
> > +#define MBUS_DEV_DMA_HOST 2
> > +#define MBUS_DEV_DMA_MIC 3
> > +#define MBUS_DEV_ANY_ID 0x
> > +
> > +/**
> > + * mbus_device - representation of a device using mbus
> > + * @priv: private pointer for the driver's use.
> > + * @mmio_va: virtual address of mmio space
> > + * @hw_ops: the hardware ops supported by this device.
> > + * @id: the device type identification (used to match it with a driver).
> > + * @dev: underlying device.
> > + * be used to communicate with.
> > + * @index: unique position on the mbus bus
> > + */
> > +struct mbus_device {
> > +   void *priv;
> > +   void __iomem *mmio_va;
> > +   struct mbus_hw_ops *hw_ops;
> > +   struct mbus_device_id id;
> > +   struct device dev;
> > +   int index;
> > +};
> > +
> > +/**
> > + * mbus_driver - operations for a mbus 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 mbus_driver {
> > +   struct device_driver driver;
> > +   const struct mbus_device_id 

Re: [PATCH char-misc-next 2/8] misc: mic: add a bus driver for virtual MIC devices

2014-05-28 Thread Greg Kroah-Hartman
On Tue, May 27, 2014 at 07:36:11PM -0700, Sudeep Dutt wrote:
> +int register_mbus_driver(struct mbus_driver *driver)
> +{
> + driver->driver.bus = _bus;
> + return driver_register(>driver);
> +}
> +EXPORT_SYMBOL_GPL(register_mbus_driver);

mbus_register_driver()?

> +void unregister_mbus_driver(struct mbus_driver *driver)
> +{
> + driver_unregister(>driver);
> +}
> +EXPORT_SYMBOL_GPL(unregister_mbus_driver);

mbus_unregister_driver()?

> +int register_mbus_device(struct mbus_device *dev)

mbus_register_device()?

Trying to keep the kernel namespace sane.

Why doesn't this function create the device structure?

> +{
> + int err;
> +
> + dev->dev.bus = _bus;
> +
> + /* Assign a unique device index and hence name. */
> + err = ida_simple_get(_index_ida, 0, 0, GFP_KERNEL);
> + if (err < 0)
> + return err;
> +
> + dev->index = err;
> + dev_set_name(>dev, "mbus-dev%u", dev->index);
> + /*
> +  * device_register() causes the bus infrastructure to look for a
> +  * matching driver.
> +  */
> + err = device_register(>dev);
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(register_mbus_device);
> +
> +void unregister_mbus_device(struct mbus_device *dev)
> +{
> + int index = dev->index; /* save for after device release */
> +
> + device_unregister(>dev);
> + ida_simple_remove(_index_ida, index);
> +}
> +EXPORT_SYMBOL_GPL(unregister_mbus_device);
> +
> +static int __init mbus_init(void)
> +{
> + return bus_register(_bus);
> +}
> +
> +static void __exit mbus_exit(void)
> +{
> + bus_unregister(_bus);
> +}
> +
> +core_initcall(mbus_init);
> +module_exit(mbus_exit);
> +
> +MODULE_AUTHOR("Intel Corporation");
> +MODULE_DESCRIPTION("Intel(R) MIC Bus driver");
> +MODULE_LICENSE("GPL v2");
> diff --git a/include/linux/mic_bus.h b/include/linux/mic_bus.h
> new file mode 100644
> index 000..8297573
> --- /dev/null
> +++ b/include/linux/mic_bus.h
> @@ -0,0 +1,148 @@
> +/*
> + * Intel MIC Platform Software Stack (MPSS)
> + *
> + * Copyright(c) 2014 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 Bus driver.
> + *
> + * This implementation is very similar to the the virtio bus driver
> + * implementation @ include/linux/virtio.h.
> + */
> +#ifndef _MIC_BUS_H_
> +#define _MIC_BUS_H_
> +/*
> + * Everything a mbus driver needs to work with any particular mbus
> + * implementation.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +struct mbus_device_id {
> + __u32 device;
> + __u32 vendor;
> +};
> +
> +#define MBUS_DEV_DMA_HOST 2
> +#define MBUS_DEV_DMA_MIC 3
> +#define MBUS_DEV_ANY_ID 0x
> +
> +/**
> + * mbus_device - representation of a device using mbus
> + * @priv: private pointer for the driver's use.
> + * @mmio_va: virtual address of mmio space
> + * @hw_ops: the hardware ops supported by this device.
> + * @id: the device type identification (used to match it with a driver).
> + * @dev: underlying device.
> + * be used to communicate with.
> + * @index: unique position on the mbus bus
> + */
> +struct mbus_device {
> + void *priv;
> + void __iomem *mmio_va;
> + struct mbus_hw_ops *hw_ops;
> + struct mbus_device_id id;
> + struct device dev;
> + int index;
> +};
> +
> +/**
> + * mbus_driver - operations for a mbus 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 mbus_driver {
> + struct device_driver driver;
> + const struct mbus_device_id *id_table;
> + int (*probe)(struct mbus_device *dev);
> + void (*scan)(struct mbus_device *dev);
> + void (*remove)(struct mbus_device *dev);
> +};
> +
> +/**
> + * struct mic_irq - opaque pointer used as cookie
> + */
> +struct mic_irq;
> +
> +/**
> + * mbus_hw_ops - Hardware operations for accessing a MIC device on the MIC 
> bus.
> + */
> +struct mbus_hw_ops {
> + struct mic_irq* (*request_threaded_irq)(struct mbus_device *mbdev,
> + irq_handler_t handler, irq_handler_t thread_fn,
> + const char *name, void *data, int intr_src);
> + void (*free_irq)(struct mbus_device *mbdev,
> + struct mic_irq *cookie, void *data);
> + void 

Re: [PATCH char-misc-next 2/8] misc: mic: add a bus driver for virtual MIC devices

2014-05-28 Thread Greg Kroah-Hartman
On Tue, May 27, 2014 at 07:36:11PM -0700, Sudeep Dutt wrote:
 +int register_mbus_driver(struct mbus_driver *driver)
 +{
 + driver-driver.bus = mic_bus;
 + return driver_register(driver-driver);
 +}
 +EXPORT_SYMBOL_GPL(register_mbus_driver);

mbus_register_driver()?

 +void unregister_mbus_driver(struct mbus_driver *driver)
 +{
 + driver_unregister(driver-driver);
 +}
 +EXPORT_SYMBOL_GPL(unregister_mbus_driver);

mbus_unregister_driver()?

 +int register_mbus_device(struct mbus_device *dev)

mbus_register_device()?

Trying to keep the kernel namespace sane.

Why doesn't this function create the device structure?

 +{
 + int err;
 +
 + dev-dev.bus = mic_bus;
 +
 + /* Assign a unique device index and hence name. */
 + err = ida_simple_get(mbus_index_ida, 0, 0, GFP_KERNEL);
 + if (err  0)
 + return err;
 +
 + dev-index = err;
 + dev_set_name(dev-dev, mbus-dev%u, dev-index);
 + /*
 +  * device_register() causes the bus infrastructure to look for a
 +  * matching driver.
 +  */
 + err = device_register(dev-dev);
 + return err;
 +}
 +EXPORT_SYMBOL_GPL(register_mbus_device);
 +
 +void unregister_mbus_device(struct mbus_device *dev)
 +{
 + int index = dev-index; /* save for after device release */
 +
 + device_unregister(dev-dev);
 + ida_simple_remove(mbus_index_ida, index);
 +}
 +EXPORT_SYMBOL_GPL(unregister_mbus_device);
 +
 +static int __init mbus_init(void)
 +{
 + return bus_register(mic_bus);
 +}
 +
 +static void __exit mbus_exit(void)
 +{
 + bus_unregister(mic_bus);
 +}
 +
 +core_initcall(mbus_init);
 +module_exit(mbus_exit);
 +
 +MODULE_AUTHOR(Intel Corporation);
 +MODULE_DESCRIPTION(Intel(R) MIC Bus driver);
 +MODULE_LICENSE(GPL v2);
 diff --git a/include/linux/mic_bus.h b/include/linux/mic_bus.h
 new file mode 100644
 index 000..8297573
 --- /dev/null
 +++ b/include/linux/mic_bus.h
 @@ -0,0 +1,148 @@
 +/*
 + * Intel MIC Platform Software Stack (MPSS)
 + *
 + * Copyright(c) 2014 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 Bus driver.
 + *
 + * This implementation is very similar to the the virtio bus driver
 + * implementation @ include/linux/virtio.h.
 + */
 +#ifndef _MIC_BUS_H_
 +#define _MIC_BUS_H_
 +/*
 + * Everything a mbus driver needs to work with any particular mbus
 + * implementation.
 + */
 +#include linux/types.h
 +#include linux/device.h
 +#include linux/mod_devicetable.h
 +#include linux/interrupt.h
 +#include linux/dma-mapping.h
 +
 +struct mbus_device_id {
 + __u32 device;
 + __u32 vendor;
 +};
 +
 +#define MBUS_DEV_DMA_HOST 2
 +#define MBUS_DEV_DMA_MIC 3
 +#define MBUS_DEV_ANY_ID 0x
 +
 +/**
 + * mbus_device - representation of a device using mbus
 + * @priv: private pointer for the driver's use.
 + * @mmio_va: virtual address of mmio space
 + * @hw_ops: the hardware ops supported by this device.
 + * @id: the device type identification (used to match it with a driver).
 + * @dev: underlying device.
 + * be used to communicate with.
 + * @index: unique position on the mbus bus
 + */
 +struct mbus_device {
 + void *priv;
 + void __iomem *mmio_va;
 + struct mbus_hw_ops *hw_ops;
 + struct mbus_device_id id;
 + struct device dev;
 + int index;
 +};
 +
 +/**
 + * mbus_driver - operations for a mbus 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 mbus_driver {
 + struct device_driver driver;
 + const struct mbus_device_id *id_table;
 + int (*probe)(struct mbus_device *dev);
 + void (*scan)(struct mbus_device *dev);
 + void (*remove)(struct mbus_device *dev);
 +};
 +
 +/**
 + * struct mic_irq - opaque pointer used as cookie
 + */
 +struct mic_irq;
 +
 +/**
 + * mbus_hw_ops - Hardware operations for accessing a MIC device on the MIC 
 bus.
 + */
 +struct mbus_hw_ops {
 + struct mic_irq* (*request_threaded_irq)(struct mbus_device *mbdev,
 + irq_handler_t handler, irq_handler_t thread_fn,
 + const char *name, void *data, int intr_src);
 + void (*free_irq)(struct mbus_device *mbdev,
 + struct mic_irq *cookie, void *data);
 + void (*ack_interrupt)(struct mbus_device *mbdev, int num);
 +};
 

Re: [PATCH char-misc-next 2/8] misc: mic: add a bus driver for virtual MIC devices

2014-05-28 Thread Sudeep Dutt
On Wed, 2014-05-28 at 13:50 -0700, Greg Kroah-Hartman wrote: 
 On Tue, May 27, 2014 at 07:36:11PM -0700, Sudeep Dutt wrote:
  +int register_mbus_driver(struct mbus_driver *driver)
  +{
  +   driver-driver.bus = mic_bus;
  +   return driver_register(driver-driver);
  +}
  +EXPORT_SYMBOL_GPL(register_mbus_driver);
 
 mbus_register_driver()?
 

The idea was to follow the register_virtio_driver(..) naming convention
but will rename as your suggestion is better.

  +void unregister_mbus_driver(struct mbus_driver *driver)
  +{
  +   driver_unregister(driver-driver);
  +}
  +EXPORT_SYMBOL_GPL(unregister_mbus_driver);
 
 mbus_unregister_driver()?

Will rename.

 
  +int register_mbus_device(struct mbus_device *dev)
 
 mbus_register_device()?
 
 Trying to keep the kernel namespace sane.

Will rename.

 
 Why doesn't this function create the device structure?
 

The mbus_device containing the device structure is allocated by the
driver calling this API. However that creates other issues as you
highlighted below. It is better to allocate mbus_device here so that it
can be freed in the device release callback correctly by the bus driver.

  +{
  +   int err;
  +
  +   dev-dev.bus = mic_bus;
  +
  +   /* Assign a unique device index and hence name. */
  +   err = ida_simple_get(mbus_index_ida, 0, 0, GFP_KERNEL);
  +   if (err  0)
  +   return err;
  +
  +   dev-index = err;
  +   dev_set_name(dev-dev, mbus-dev%u, dev-index);
  +   /*
  +* device_register() causes the bus infrastructure to look for a
  +* matching driver.
  +*/
  +   err = device_register(dev-dev);
  +   return err;
  +}
  +EXPORT_SYMBOL_GPL(register_mbus_device);
  +
  +void unregister_mbus_device(struct mbus_device *dev)
  +{
  +   int index = dev-index; /* save for after device release */
  +
  +   device_unregister(dev-dev);
  +   ida_simple_remove(mbus_index_ida, index);
  +}
  +EXPORT_SYMBOL_GPL(unregister_mbus_device);
  +
  +static int __init mbus_init(void)
  +{
  +   return bus_register(mic_bus);
  +}
  +
  +static void __exit mbus_exit(void)
  +{
  +   bus_unregister(mic_bus);
  +}
  +
  +core_initcall(mbus_init);
  +module_exit(mbus_exit);
  +
  +MODULE_AUTHOR(Intel Corporation);
  +MODULE_DESCRIPTION(Intel(R) MIC Bus driver);
  +MODULE_LICENSE(GPL v2);
  diff --git a/include/linux/mic_bus.h b/include/linux/mic_bus.h
  new file mode 100644
  index 000..8297573
  --- /dev/null
  +++ b/include/linux/mic_bus.h
  @@ -0,0 +1,148 @@
  +/*
  + * Intel MIC Platform Software Stack (MPSS)
  + *
  + * Copyright(c) 2014 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 Bus driver.
  + *
  + * This implementation is very similar to the the virtio bus driver
  + * implementation @ include/linux/virtio.h.
  + */
  +#ifndef _MIC_BUS_H_
  +#define _MIC_BUS_H_
  +/*
  + * Everything a mbus driver needs to work with any particular mbus
  + * implementation.
  + */
  +#include linux/types.h
  +#include linux/device.h
  +#include linux/mod_devicetable.h
  +#include linux/interrupt.h
  +#include linux/dma-mapping.h
  +
  +struct mbus_device_id {
  +   __u32 device;
  +   __u32 vendor;
  +};
  +
  +#define MBUS_DEV_DMA_HOST 2
  +#define MBUS_DEV_DMA_MIC 3
  +#define MBUS_DEV_ANY_ID 0x
  +
  +/**
  + * mbus_device - representation of a device using mbus
  + * @priv: private pointer for the driver's use.
  + * @mmio_va: virtual address of mmio space
  + * @hw_ops: the hardware ops supported by this device.
  + * @id: the device type identification (used to match it with a driver).
  + * @dev: underlying device.
  + * be used to communicate with.
  + * @index: unique position on the mbus bus
  + */
  +struct mbus_device {
  +   void *priv;
  +   void __iomem *mmio_va;
  +   struct mbus_hw_ops *hw_ops;
  +   struct mbus_device_id id;
  +   struct device dev;
  +   int index;
  +};
  +
  +/**
  + * mbus_driver - operations for a mbus 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 mbus_driver {
  +   struct device_driver driver;
  +   const struct mbus_device_id *id_table;
  +   int (*probe)(struct mbus_device *dev);
  +   void (*scan)(struct mbus_device *dev);
  +   void (*remove)(struct mbus_device *dev);
  +};
  +
  +/**
  + * struct 

[PATCH char-misc-next 2/8] misc: mic: add a bus driver for virtual MIC devices

2014-05-27 Thread Sudeep Dutt
From: Siva Yerramreddy 

This MIC virtual bus driver takes the responsibility of creating all
the virtual devices connected to the PCIe device on the host and the
platform device on the card. The MIC bus hardware operations provide
a way to abstract certain hardware details from the base physical devices.
Examples of devices added on the MIC virtual bus include host DMA and card DMA.
This abstraction enables using a common DMA driver on host and card.

Reviewed-by: Ashutosh Dixit 
Reviewed-by: Nikhil Rao 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Siva Yerramreddy 
---
 drivers/misc/mic/Kconfig   |  17 
 drivers/misc/mic/Makefile  |   1 +
 drivers/misc/mic/bus/Makefile  |   5 ++
 drivers/misc/mic/bus/mic_bus.c | 188 +
 include/linux/mic_bus.h| 148 
 5 files changed, 359 insertions(+)
 create mode 100644 drivers/misc/mic/bus/Makefile
 create mode 100644 drivers/misc/mic/bus/mic_bus.c
 create mode 100644 include/linux/mic_bus.h

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 462a5b1..ee1d2ac 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -1,3 +1,20 @@
+comment "Intel MIC Bus Driver"
+
+config INTEL_MIC_BUS
+   tristate "Intel MIC 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 MIC Bus, such as CONFIG_INTEL_MIC_HOST,
+ CONFIG_INTEL_MIC_CARD, CONFIG_INTEL_MIC_X100_DMA etc.
+
+ 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
+ .
+
 comment "Intel MIC Host Driver"
 
 config INTEL_MIC_HOST
diff --git a/drivers/misc/mic/Makefile b/drivers/misc/mic/Makefile
index 05b34d6..e9bf148 100644
--- a/drivers/misc/mic/Makefile
+++ b/drivers/misc/mic/Makefile
@@ -4,3 +4,4 @@
 #
 obj-$(CONFIG_INTEL_MIC_HOST) += host/
 obj-$(CONFIG_INTEL_MIC_CARD) += card/
+obj-$(CONFIG_INTEL_MIC_BUS) += bus/
diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
new file mode 100644
index 000..d85c7f2
--- /dev/null
+++ b/drivers/misc/mic/bus/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile - Intel MIC Linux driver.
+# Copyright(c) 2014, Intel Corporation.
+#
+obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
diff --git a/drivers/misc/mic/bus/mic_bus.c b/drivers/misc/mic/bus/mic_bus.c
new file mode 100644
index 000..39253b5
--- /dev/null
+++ b/drivers/misc/mic/bus/mic_bus.c
@@ -0,0 +1,188 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2014 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 Bus driver.
+ *
+ * This implementation is very similar to the the virtio bus driver
+ * implementation @ drivers/virtio/virtio.c
+ */
+#include 
+#include 
+#include 
+#include 
+
+/* Unique numbering for mbus devices. */
+static DEFINE_IDA(mbus_index_ida);
+
+static ssize_t device_show(struct device *d,
+  struct device_attribute *attr, char *buf)
+{
+   struct mbus_device *dev = dev_to_mbus(d);
+   return sprintf(buf, "0x%04x\n", dev->id.device);
+}
+static DEVICE_ATTR_RO(device);
+
+static ssize_t vendor_show(struct device *d,
+  struct device_attribute *attr, char *buf)
+{
+   struct mbus_device *dev = dev_to_mbus(d);
+   return sprintf(buf, "0x%04x\n", dev->id.vendor);
+}
+static DEVICE_ATTR_RO(vendor);
+
+static ssize_t modalias_show(struct device *d,
+struct device_attribute *attr, char *buf)
+{
+   struct mbus_device *dev = dev_to_mbus(d);
+   return sprintf(buf, "mbus:d%08Xv%08X\n",
+  dev->id.device, dev->id.vendor);
+}
+static DEVICE_ATTR_RO(modalias);
+
+static struct attribute *mbus_dev_attrs[] = {
+   _attr_device.attr,
+   _attr_vendor.attr,
+   _attr_modalias.attr,
+   NULL,
+};
+ATTRIBUTE_GROUPS(mbus_dev);
+
+static inline int mbus_id_match(const struct mbus_device *dev,
+ const struct mbus_device_id *id)
+{
+   if (id->device != dev->id.device && id->device != MBUS_DEV_ANY_ID)
+   return 0;
+
+   return 

[PATCH char-misc-next 2/8] misc: mic: add a bus driver for virtual MIC devices

2014-05-27 Thread Sudeep Dutt
From: Siva Yerramreddy yshivakris...@gmail.com

This MIC virtual bus driver takes the responsibility of creating all
the virtual devices connected to the PCIe device on the host and the
platform device on the card. The MIC bus hardware operations provide
a way to abstract certain hardware details from the base physical devices.
Examples of devices added on the MIC virtual bus include host DMA and card DMA.
This abstraction enables using a common DMA driver on host and card.

Reviewed-by: Ashutosh Dixit ashutosh.di...@intel.com
Reviewed-by: Nikhil Rao nikhil@intel.com
Signed-off-by: Sudeep Dutt sudeep.d...@intel.com
Signed-off-by: Siva Yerramreddy yshivakris...@gmail.com
---
 drivers/misc/mic/Kconfig   |  17 
 drivers/misc/mic/Makefile  |   1 +
 drivers/misc/mic/bus/Makefile  |   5 ++
 drivers/misc/mic/bus/mic_bus.c | 188 +
 include/linux/mic_bus.h| 148 
 5 files changed, 359 insertions(+)
 create mode 100644 drivers/misc/mic/bus/Makefile
 create mode 100644 drivers/misc/mic/bus/mic_bus.c
 create mode 100644 include/linux/mic_bus.h

diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index 462a5b1..ee1d2ac 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -1,3 +1,20 @@
+comment Intel MIC Bus Driver
+
+config INTEL_MIC_BUS
+   tristate Intel MIC 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 MIC Bus, such as CONFIG_INTEL_MIC_HOST,
+ CONFIG_INTEL_MIC_CARD, CONFIG_INTEL_MIC_X100_DMA etc.
+
+ 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/Makefile b/drivers/misc/mic/Makefile
index 05b34d6..e9bf148 100644
--- a/drivers/misc/mic/Makefile
+++ b/drivers/misc/mic/Makefile
@@ -4,3 +4,4 @@
 #
 obj-$(CONFIG_INTEL_MIC_HOST) += host/
 obj-$(CONFIG_INTEL_MIC_CARD) += card/
+obj-$(CONFIG_INTEL_MIC_BUS) += bus/
diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
new file mode 100644
index 000..d85c7f2
--- /dev/null
+++ b/drivers/misc/mic/bus/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile - Intel MIC Linux driver.
+# Copyright(c) 2014, Intel Corporation.
+#
+obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
diff --git a/drivers/misc/mic/bus/mic_bus.c b/drivers/misc/mic/bus/mic_bus.c
new file mode 100644
index 000..39253b5
--- /dev/null
+++ b/drivers/misc/mic/bus/mic_bus.c
@@ -0,0 +1,188 @@
+/*
+ * Intel MIC Platform Software Stack (MPSS)
+ *
+ * Copyright(c) 2014 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 Bus driver.
+ *
+ * This implementation is very similar to the the virtio bus driver
+ * implementation @ drivers/virtio/virtio.c
+ */
+#include linux/spinlock.h
+#include linux/module.h
+#include linux/idr.h
+#include linux/mic_bus.h
+
+/* Unique numbering for mbus devices. */
+static DEFINE_IDA(mbus_index_ida);
+
+static ssize_t device_show(struct device *d,
+  struct device_attribute *attr, char *buf)
+{
+   struct mbus_device *dev = dev_to_mbus(d);
+   return sprintf(buf, 0x%04x\n, dev-id.device);
+}
+static DEVICE_ATTR_RO(device);
+
+static ssize_t vendor_show(struct device *d,
+  struct device_attribute *attr, char *buf)
+{
+   struct mbus_device *dev = dev_to_mbus(d);
+   return sprintf(buf, 0x%04x\n, dev-id.vendor);
+}
+static DEVICE_ATTR_RO(vendor);
+
+static ssize_t modalias_show(struct device *d,
+struct device_attribute *attr, char *buf)
+{
+   struct mbus_device *dev = dev_to_mbus(d);
+   return sprintf(buf, mbus:d%08Xv%08X\n,
+  dev-id.device, dev-id.vendor);
+}
+static DEVICE_ATTR_RO(modalias);
+
+static struct attribute *mbus_dev_attrs[] = {
+   dev_attr_device.attr,
+   dev_attr_vendor.attr,
+   dev_attr_modalias.attr,
+   NULL,
+};
+ATTRIBUTE_GROUPS(mbus_dev);
+
+static inline int mbus_id_match(const struct mbus_device *dev,
+ const