Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
[pandora-kernel.git] / drivers / staging / hv / vmbus_drv.c
index 22c80ec..0d9f3a4 100644 (file)
@@ -32,6 +32,7 @@
 #include "osd.h"
 #include "logging.h"
 #include "vmbus.h"
+#include "channel.h"
 
 
 /* FIXME! We need to do this dynamically for PIC and APIC system */
@@ -70,13 +71,11 @@ static void vmbus_bus_release(struct device *device);
 
 static struct hv_device *vmbus_child_device_create(struct hv_guid *type,
                                                   struct hv_guid *instance,
-                                                  void *context);
+                                                  struct vmbus_channel *channel);
 static void vmbus_child_device_destroy(struct hv_device *device_obj);
 static int vmbus_child_device_register(struct hv_device *root_device_obj,
                                       struct hv_device *child_device_obj);
 static void vmbus_child_device_unregister(struct hv_device *child_device_obj);
-static void vmbus_child_device_get_info(struct hv_device *device_obj,
-                                       struct hv_device_info *device_info);
 static ssize_t vmbus_show_device_attr(struct device *dev,
                                      struct device_attribute *dev_attr,
                                      char *buf);
@@ -130,6 +129,47 @@ static struct vmbus_driver_context g_vmbus_drv = {
        .bus.dev_attrs =        vmbus_device_attrs,
 };
 
+static void get_channel_info(struct hv_device *device,
+                            struct hv_device_info *info)
+{
+       struct vmbus_channel_debug_info debug_info;
+
+       if (!device->channel)
+               return;
+
+       vmbus_get_debug_info(device->channel, &debug_info);
+
+       info->ChannelId = debug_info.RelId;
+       info->ChannelState = debug_info.State;
+       memcpy(&info->ChannelType, &debug_info.InterfaceType,
+              sizeof(struct hv_guid));
+       memcpy(&info->ChannelInstance, &debug_info.InterfaceInstance,
+              sizeof(struct hv_guid));
+
+       info->MonitorId = debug_info.MonitorId;
+
+       info->ServerMonitorPending = debug_info.ServerMonitorPending;
+       info->ServerMonitorLatency = debug_info.ServerMonitorLatency;
+       info->ServerMonitorConnectionId = debug_info.ServerMonitorConnectionId;
+
+       info->ClientMonitorPending = debug_info.ClientMonitorPending;
+       info->ClientMonitorLatency = debug_info.ClientMonitorLatency;
+       info->ClientMonitorConnectionId = debug_info.ClientMonitorConnectionId;
+
+       info->Inbound.InterruptMask = debug_info.Inbound.CurrentInterruptMask;
+       info->Inbound.ReadIndex = debug_info.Inbound.CurrentReadIndex;
+       info->Inbound.WriteIndex = debug_info.Inbound.CurrentWriteIndex;
+       info->Inbound.BytesAvailToRead = debug_info.Inbound.BytesAvailToRead;
+       info->Inbound.BytesAvailToWrite = debug_info.Inbound.BytesAvailToWrite;
+
+       info->Outbound.InterruptMask = debug_info.Outbound.CurrentInterruptMask;
+       info->Outbound.ReadIndex = debug_info.Outbound.CurrentReadIndex;
+       info->Outbound.WriteIndex = debug_info.Outbound.CurrentWriteIndex;
+       info->Outbound.BytesAvailToRead = debug_info.Outbound.BytesAvailToRead;
+       info->Outbound.BytesAvailToWrite =
+               debug_info.Outbound.BytesAvailToWrite;
+}
+
 /*
  * vmbus_show_device_attr - Show the device attribute in sysfs.
  *
@@ -145,7 +185,7 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
 
        memset(&device_info, 0, sizeof(struct hv_device_info));
 
-       vmbus_child_device_get_info(&device_ctx->device_obj, &device_info);
+       get_channel_info(&device_ctx->device_obj, &device_info);
 
        if (!strcmp(dev_attr->attr.name, "class_id")) {
                return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-"
@@ -254,8 +294,6 @@ static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv))
        int ret;
        unsigned int vector;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /*
         * Set this up to allow lower layer to callback to add/remove child
         * devices on the bus
@@ -360,8 +398,6 @@ static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv))
        wait_for_completion(&hv_channel_ready);
 
 cleanup:
-       DPRINT_EXIT(VMBUS_DRV);
-
        return ret;
 }
 
@@ -377,8 +413,6 @@ static void vmbus_bus_exit(void)
 
        struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* Remove the root device */
        if (vmbus_drv_obj->Base.OnDeviceRemove)
                vmbus_drv_obj->Base.OnDeviceRemove(&dev_ctx->device_obj);
@@ -395,10 +429,6 @@ static void vmbus_bus_exit(void)
 
        tasklet_kill(&vmbus_drv_ctx->msg_dpc);
        tasklet_kill(&vmbus_drv_ctx->event_dpc);
-
-       DPRINT_EXIT(VMBUS_DRV);
-
-       return;
 }
 
 
@@ -419,8 +449,6 @@ int vmbus_child_driver_register(struct driver_context *driver_ctx)
        struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj;
        int ret;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s",
                    driver_ctx, driver_ctx->driver.name);
 
@@ -431,8 +459,6 @@ int vmbus_child_driver_register(struct driver_context *driver_ctx)
 
        vmbus_drv_obj->GetChannelOffers();
 
-       DPRINT_EXIT(VMBUS_DRV);
-
        return ret;
 }
 EXPORT_SYMBOL(vmbus_child_driver_register);
@@ -450,71 +476,31 @@ EXPORT_SYMBOL(vmbus_child_driver_register);
  */
 void vmbus_child_driver_unregister(struct driver_context *driver_ctx)
 {
-       DPRINT_ENTER(VMBUS_DRV);
-
        DPRINT_INFO(VMBUS_DRV, "child driver (%p) unregistering - name %s",
                    driver_ctx, driver_ctx->driver.name);
 
        driver_unregister(&driver_ctx->driver);
 
        driver_ctx->driver.bus = NULL;
-
-       DPRINT_EXIT(VMBUS_DRV);
 }
 EXPORT_SYMBOL(vmbus_child_driver_unregister);
 
-/**
- * vmbus_get_interface() - Get the vmbus channel interface.
- * @interface: Pointer to channel interface structure
- *
- * Get the Hyper-V channel used for the driver.
- *
- * @interface is of type &struct vmbus_channel_interface
- * This is invoked by child/client driver that sits above vmbus.
- *
- * Mainly used by Hyper-V drivers.
- */
-void vmbus_get_interface(struct vmbus_channel_interface *interface)
-{
-       struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj;
-
-       vmbus_drv_obj->GetChannelInterface(interface);
-}
-EXPORT_SYMBOL(vmbus_get_interface);
-
-/*
- * vmbus_child_device_get_info - Get the vmbus child device info.
- *
- * This is invoked to display various device attributes in sysfs.
- */
-static void vmbus_child_device_get_info(struct hv_device *device_obj,
-                                       struct hv_device_info *device_info)
-{
-       struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj;
-
-       vmbus_drv_obj->GetChannelInfo(device_obj, device_info);
-}
-
 /*
  * vmbus_child_device_create - Creates and registers a new child device
  * on the vmbus.
  */
 static struct hv_device *vmbus_child_device_create(struct hv_guid *type,
                                                   struct hv_guid *instance,
-                                                  void *context)
+                                                  struct vmbus_channel *channel)
 {
        struct vm_device *child_device_ctx;
        struct hv_device *child_device_obj;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* Allocate the new child device */
        child_device_ctx = kzalloc(sizeof(struct vm_device), GFP_KERNEL);
        if (!child_device_ctx) {
                DPRINT_ERR(VMBUS_DRV,
                        "unable to allocate device_context for child device");
-               DPRINT_EXIT(VMBUS_DRV);
-
                return NULL;
        }
 
@@ -538,7 +524,7 @@ static struct hv_device *vmbus_child_device_create(struct hv_guid *type,
                instance->data[14], instance->data[15]);
 
        child_device_obj = &child_device_ctx->device_obj;
-       child_device_obj->context = context;
+       child_device_obj->channel = channel;
        memcpy(&child_device_obj->deviceType, type, sizeof(struct hv_guid));
        memcpy(&child_device_obj->deviceInstance, instance,
               sizeof(struct hv_guid));
@@ -546,8 +532,6 @@ static struct hv_device *vmbus_child_device_create(struct hv_guid *type,
        memcpy(&child_device_ctx->class_id, type, sizeof(struct hv_guid));
        memcpy(&child_device_ctx->device_id, instance, sizeof(struct hv_guid));
 
-       DPRINT_EXIT(VMBUS_DRV);
-
        return child_device_obj;
 }
 
@@ -564,8 +548,6 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
                                to_vm_device(child_device_obj);
        static atomic_t device_num = ATOMIC_INIT(0);
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        DPRINT_DBG(VMBUS_DRV, "child device (%p) registering",
                   child_device_ctx);
 
@@ -594,8 +576,6 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
                DPRINT_INFO(VMBUS_DRV, "child device (%p) registered",
                            &child_device_ctx->device);
 
-       DPRINT_EXIT(VMBUS_DRV);
-
        return ret;
 }
 
@@ -607,8 +587,6 @@ static void vmbus_child_device_unregister(struct hv_device *device_obj)
 {
        struct vm_device *device_ctx = to_vm_device(device_obj);
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)",
                    &device_ctx->device);
 
@@ -620,8 +598,6 @@ static void vmbus_child_device_unregister(struct hv_device *device_obj)
 
        DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered",
                    &device_ctx->device);
-
-       DPRINT_EXIT(VMBUS_DRV);
 }
 
 /*
@@ -629,9 +605,6 @@ static void vmbus_child_device_unregister(struct hv_device *device_obj)
  */
 static void vmbus_child_device_destroy(struct hv_device *device_obj)
 {
-       DPRINT_ENTER(VMBUS_DRV);
-
-       DPRINT_EXIT(VMBUS_DRV);
 }
 
 /*
@@ -646,8 +619,6 @@ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env)
        struct vm_device *device_ctx = device_to_vm_device(device);
        int ret;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        DPRINT_INFO(VMBUS_DRV, "generating uevent - VMBUS_DEVICE_CLASS_GUID={"
                    "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
                    "%02x%02x%02x%02x%02x%02x%02x%02x}",
@@ -708,8 +679,6 @@ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env)
        if (ret)
                return ret;
 
-       DPRINT_EXIT(VMBUS_DRV);
-
        return 0;
 }
 
@@ -722,8 +691,6 @@ static int vmbus_match(struct device *device, struct device_driver *driver)
        struct driver_context *driver_ctx = driver_to_driver_context(driver);
        struct vm_device *device_ctx = device_to_vm_device(device);
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* We found our driver ? */
        if (memcmp(&device_ctx->class_id, &driver_ctx->class_id,
                   sizeof(struct hv_guid)) == 0) {
@@ -742,9 +709,6 @@ static int vmbus_match(struct device *device, struct device_driver *driver)
 
                match = 1;
        }
-
-       DPRINT_EXIT(VMBUS_DRV);
-
        return match;
 }
 
@@ -759,8 +723,6 @@ static void vmbus_probe_failed_cb(struct work_struct *context)
 {
        struct vm_device *device_ctx = (struct vm_device *)context;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /*
         * Kick off the process of unregistering the device.
         * This will call vmbus_remove() and eventually vmbus_device_release()
@@ -768,7 +730,6 @@ static void vmbus_probe_failed_cb(struct work_struct *context)
        device_unregister(&device_ctx->device);
 
        /* put_device(&device_ctx->device); */
-       DPRINT_EXIT(VMBUS_DRV);
 }
 
 /*
@@ -782,8 +743,6 @@ static int vmbus_probe(struct device *child_device)
        struct vm_device *device_ctx =
                        device_to_vm_device(child_device);
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* Let the specific open-source driver handles the probe if it can */
        if (driver_ctx->probe) {
                ret = device_ctx->probe_error = driver_ctx->probe(child_device);
@@ -802,8 +761,6 @@ static int vmbus_probe(struct device *child_device)
                           child_device->driver->name);
                ret = -1;
        }
-
-       DPRINT_EXIT(VMBUS_DRV);
        return ret;
 }
 
@@ -815,15 +772,12 @@ static int vmbus_remove(struct device *child_device)
        int ret;
        struct driver_context *driver_ctx;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* Special case root bus device */
        if (child_device->parent == NULL) {
                /*
                 * No-op since it is statically defined and handle in
                 * vmbus_bus_exit()
                 */
-               DPRINT_EXIT(VMBUS_DRV);
                return 0;
        }
 
@@ -844,8 +798,6 @@ static int vmbus_remove(struct device *child_device)
                }
        }
 
-       DPRINT_EXIT(VMBUS_DRV);
-
        return 0;
 }
 
@@ -856,23 +808,18 @@ static void vmbus_shutdown(struct device *child_device)
 {
        struct driver_context *driver_ctx;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* Special case root bus device */
        if (child_device->parent == NULL) {
                /*
                 * No-op since it is statically defined and handle in
                 * vmbus_bus_exit()
                 */
-               DPRINT_EXIT(VMBUS_DRV);
                return;
        }
 
        /* The device may not be attached yet */
-       if (!child_device->driver) {
-               DPRINT_EXIT(VMBUS_DRV);
+       if (!child_device->driver)
                return;
-       }
 
        driver_ctx = driver_to_driver_context(child_device->driver);
 
@@ -880,8 +827,6 @@ static void vmbus_shutdown(struct device *child_device)
        if (driver_ctx->shutdown)
                driver_ctx->shutdown(child_device);
 
-       DPRINT_EXIT(VMBUS_DRV);
-
        return;
 }
 
@@ -890,13 +835,11 @@ static void vmbus_shutdown(struct device *child_device)
  */
 static void vmbus_bus_release(struct device *device)
 {
-       DPRINT_ENTER(VMBUS_DRV);
        /* FIXME */
        /* Empty release functions are a bug, or a major sign
         * of a problem design, this MUST BE FIXED! */
        dev_err(device, "%s needs to be fixed!\n", __func__);
        WARN_ON(1);
-       DPRINT_EXIT(VMBUS_DRV);
 }
 
 /*
@@ -906,15 +849,10 @@ static void vmbus_device_release(struct device *device)
 {
        struct vm_device *device_ctx = device_to_vm_device(device);
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* vmbus_child_device_destroy(&device_ctx->device_obj); */
        kfree(device_ctx);
 
        /* !!DO NOT REFERENCE device_ctx anymore at this point!! */
-       DPRINT_EXIT(VMBUS_DRV);
-
-       return;
 }
 
 /*
@@ -924,14 +862,10 @@ static void vmbus_msg_dpc(unsigned long data)
 {
        struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* ASSERT(vmbus_drv_obj->OnMsgDpc != NULL); */
 
        /* Call to bus driver to handle interrupt */
        vmbus_drv_obj->OnMsgDpc(&vmbus_drv_obj->Base);
-
-       DPRINT_EXIT(VMBUS_DRV);
 }
 
 /*
@@ -941,14 +875,10 @@ static void vmbus_event_dpc(unsigned long data)
 {
        struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* ASSERT(vmbus_drv_obj->OnEventDpc != NULL); */
 
        /* Call to bus driver to handle interrupt */
        vmbus_drv_obj->OnEventDpc(&vmbus_drv_obj->Base);
-
-       DPRINT_EXIT(VMBUS_DRV);
 }
 
 static irqreturn_t vmbus_isr(int irq, void *dev_id)
@@ -956,8 +886,6 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id)
        struct vmbus_driver *vmbus_driver_obj = &g_vmbus_drv.drv_obj;
        int ret;
 
-       DPRINT_ENTER(VMBUS_DRV);
-
        /* ASSERT(vmbus_driver_obj->OnIsr != NULL); */
 
        /* Call to bus driver to handle interrupt */
@@ -971,10 +899,8 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id)
                if (test_bit(1, (unsigned long *)&ret))
                        tasklet_schedule(&g_vmbus_drv.event_dpc);
 
-               DPRINT_EXIT(VMBUS_DRV);
                return IRQ_HANDLED;
        } else {
-               DPRINT_EXIT(VMBUS_DRV);
                return IRQ_NONE;
        }
 }
@@ -994,10 +920,6 @@ MODULE_DEVICE_TABLE(dmi, microsoft_hv_dmi_table);
 
 static int __init vmbus_init(void)
 {
-       int ret = 0;
-
-       DPRINT_ENTER(VMBUS_DRV);
-
        DPRINT_INFO(VMBUS_DRV,
                "Vmbus initializing.... current log level 0x%x (%x,%x)",
                vmbus_loglevel, HIWORD(vmbus_loglevel), LOWORD(vmbus_loglevel));
@@ -1006,20 +928,13 @@ static int __init vmbus_init(void)
        if (!dmi_check_system(microsoft_hv_dmi_table))
                return -ENODEV;
 
-       ret = vmbus_bus_init(VmbusInitialize);
-
-       DPRINT_EXIT(VMBUS_DRV);
-       return ret;
+       return vmbus_bus_init(VmbusInitialize);
 }
 
 static void __exit vmbus_exit(void)
 {
-       DPRINT_ENTER(VMBUS_DRV);
-
        vmbus_bus_exit();
        /* Todo: it is used for loglevel, to be ported to new kernel. */
-       DPRINT_EXIT(VMBUS_DRV);
-       return;
 }
 
 /*
@@ -1028,7 +943,7 @@ static void __exit vmbus_exit(void)
  * installed and/or configured.  We don't do anything else with the table, but
  * it needs to be present.
  */
-const static struct pci_device_id microsoft_hv_pci_table[] = {
+static const struct pci_device_id microsoft_hv_pci_table[] = {
        { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
        { 0 }
 };