Staging: hv: Get rid of vmbus_child_dev_add()
[pandora-kernel.git] / drivers / staging / hv / channel_mgmt.c
index 3e229fa..3368809 100644 (file)
  *   Hank Janssen  <hjanssen@microsoft.com>
  */
 #include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/wait.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/completion.h>
-#include "osd.h"
+#include "hv_api.h"
 #include "logging.h"
 #include "vmbus_private.h"
 #include "utils.h"
@@ -194,7 +196,7 @@ void chn_cb_negotiate(void *context)
 
                vmbus_sendpacket(channel, buf,
                                       recvlen, requestid,
-                                      VmbusPacketTypeDataInBand, 0);
+                                      VM_PKT_DATA_INBAND, 0);
        }
 
        kfree(buf);
@@ -308,7 +310,7 @@ void free_channel(struct vmbus_channel *channel)
         * ie we can't destroy ourselves.
         */
        INIT_WORK(&channel->work, release_channel);
-       queue_work(vmbus_connection.WorkQueue, &channel->work);
+       queue_work(vmbus_connection.work_queue, &channel->work);
 }
 
 
@@ -363,7 +365,7 @@ static void vmbus_process_offer(struct work_struct *work)
        /* Make sure this is a new offer */
        spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
 
-       list_for_each_entry(channel, &vmbus_connection.ChannelList, listentry) {
+       list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
                if (!memcmp(&channel->offermsg.offer.if_type,
                            &newchannel->offermsg.offer.if_type,
                            sizeof(struct hv_guid)) &&
@@ -377,7 +379,7 @@ static void vmbus_process_offer(struct work_struct *work)
 
        if (fnew)
                list_add_tail(&newchannel->listentry,
-                             &vmbus_connection.ChannelList);
+                             &vmbus_connection.chn_list);
 
        spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
 
@@ -406,7 +408,7 @@ static void vmbus_process_offer(struct work_struct *work)
         * binding which eventually invokes the device driver's AddDevice()
         * method.
         */
-       ret = vmbus_child_dev_add(newchannel->device_obj);
+       ret = vmbus_child_device_register(newchannel->device_obj);
        if (ret != 0) {
                DPRINT_ERR(VMBUS,
                           "unable to add child device object (relid %d)",
@@ -565,7 +567,6 @@ static void vmbus_onoffers_delivered(
 static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
 {
        struct vmbus_channel_open_result *result;
-       struct list_head *curr;
        struct vmbus_channel_msginfo *msginfo;
        struct vmbus_channel_message_header *requestheader;
        struct vmbus_channel_open_channel *openmsg;
@@ -579,9 +580,8 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
         */
        spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
 
-       list_for_each(curr, &vmbus_connection.ChannelMsgList) {
-/* FIXME: this should probably use list_entry() instead */
-               msginfo = (struct vmbus_channel_msginfo *)curr;
+       list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
+                               msglistentry) {
                requestheader =
                        (struct vmbus_channel_message_header *)msginfo->msg;
 
@@ -593,7 +593,8 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
                                memcpy(&msginfo->response.open_result,
                                       result,
                                       sizeof(struct vmbus_channel_open_result));
-                               osd_waitevent_set(msginfo->waitevent);
+                               msginfo->wait_condition = 1;
+                               wake_up(&msginfo->waitevent);
                                break;
                        }
                }
@@ -611,7 +612,6 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
 static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
 {
        struct vmbus_channel_gpadl_created *gpadlcreated;
-       struct list_head *curr;
        struct vmbus_channel_msginfo *msginfo;
        struct vmbus_channel_message_header *requestheader;
        struct vmbus_channel_gpadl_header *gpadlheader;
@@ -627,9 +627,8 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
         */
        spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
 
-       list_for_each(curr, &vmbus_connection.ChannelMsgList) {
-/* FIXME: this should probably use list_entry() instead */
-               msginfo = (struct vmbus_channel_msginfo *)curr;
+       list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
+                               msglistentry) {
                requestheader =
                        (struct vmbus_channel_message_header *)msginfo->msg;
 
@@ -643,7 +642,8 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
                                memcpy(&msginfo->response.gpadl_created,
                                       gpadlcreated,
                                       sizeof(struct vmbus_channel_gpadl_created));
-                               osd_waitevent_set(msginfo->waitevent);
+                               msginfo->wait_condition = 1;
+                               wake_up(&msginfo->waitevent);
                                break;
                        }
                }
@@ -662,7 +662,6 @@ static void vmbus_ongpadl_torndown(
                        struct vmbus_channel_message_header *hdr)
 {
        struct vmbus_channel_gpadl_torndown *gpadl_torndown;
-       struct list_head *curr;
        struct vmbus_channel_msginfo *msginfo;
        struct vmbus_channel_message_header *requestheader;
        struct vmbus_channel_gpadl_teardown *gpadl_teardown;
@@ -675,9 +674,8 @@ static void vmbus_ongpadl_torndown(
         */
        spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
 
-       list_for_each(curr, &vmbus_connection.ChannelMsgList) {
-/* FIXME: this should probably use list_entry() instead */
-               msginfo = (struct vmbus_channel_msginfo *)curr;
+       list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
+                               msglistentry) {
                requestheader =
                        (struct vmbus_channel_message_header *)msginfo->msg;
 
@@ -689,7 +687,8 @@ static void vmbus_ongpadl_torndown(
                                memcpy(&msginfo->response.gpadl_torndown,
                                       gpadl_torndown,
                                       sizeof(struct vmbus_channel_gpadl_torndown));
-                               osd_waitevent_set(msginfo->waitevent);
+                               msginfo->wait_condition = 1;
+                               wake_up(&msginfo->waitevent);
                                break;
                        }
                }
@@ -707,7 +706,6 @@ static void vmbus_ongpadl_torndown(
 static void vmbus_onversion_response(
                struct vmbus_channel_message_header *hdr)
 {
-       struct list_head *curr;
        struct vmbus_channel_msginfo *msginfo;
        struct vmbus_channel_message_header *requestheader;
        struct vmbus_channel_initiate_contact *initiate;
@@ -717,9 +715,8 @@ static void vmbus_onversion_response(
        version_response = (struct vmbus_channel_version_response *)hdr;
        spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
 
-       list_for_each(curr, &vmbus_connection.ChannelMsgList) {
-/* FIXME: this should probably use list_entry() instead */
-               msginfo = (struct vmbus_channel_msginfo *)curr;
+       list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
+                               msglistentry) {
                requestheader =
                        (struct vmbus_channel_message_header *)msginfo->msg;
 
@@ -730,7 +727,8 @@ static void vmbus_onversion_response(
                        memcpy(&msginfo->response.version_response,
                              version_response,
                              sizeof(struct vmbus_channel_version_response));
-                       osd_waitevent_set(msginfo->waitevent);
+                       msginfo->wait_condition = 1;
+                       wake_up(&msginfo->waitevent);
                }
        }
        spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
@@ -805,44 +803,34 @@ int vmbus_request_offers(void)
        if (!msginfo)
                return -ENOMEM;
 
-       msginfo->waitevent = osd_waitevent_create();
-       if (!msginfo->waitevent) {
-               kfree(msginfo);
-               return -ENOMEM;
-       }
+       init_waitqueue_head(&msginfo->waitevent);
 
        msg = (struct vmbus_channel_message_header *)msginfo->msg;
 
        msg->msgtype = CHANNELMSG_REQUESTOFFERS;
 
-       /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
-       INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList,
-                        &msgInfo->msgListEntry);
-       SpinlockRelease(gVmbusConnection.channelMsgLock);*/
 
        ret = vmbus_post_msg(msg,
                               sizeof(struct vmbus_channel_message_header));
        if (ret != 0) {
                DPRINT_ERR(VMBUS, "Unable to request offers - %d", ret);
 
-               /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
-               REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
-               SpinlockRelease(gVmbusConnection.channelMsgLock);*/
+               goto cleanup;
+       }
 
-               goto Cleanup;
+       msginfo->wait_condition = 0;
+       wait_event_timeout(msginfo->waitevent, msginfo->wait_condition,
+                       msecs_to_jiffies(1000));
+       if (msginfo->wait_condition == 0) {
+               ret = -ETIMEDOUT;
+               goto cleanup;
        }
-       /* osd_waitevent_wait(msgInfo->waitEvent); */
 
-       /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
-       REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
-       SpinlockRelease(gVmbusConnection.channelMsgLock);*/
 
 
-Cleanup:
-       if (msginfo) {
-               kfree(msginfo->waitevent);
+cleanup:
+       if (msginfo)
                kfree(msginfo);
-       }
 
        return ret;
 }
@@ -859,7 +847,7 @@ void vmbus_release_unattached_channels(void)
 
        spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
 
-       list_for_each_entry_safe(channel, pos, &vmbus_connection.ChannelList,
+       list_for_each_entry_safe(channel, pos, &vmbus_connection.chn_list,
                                 listentry) {
                if (channel == start)
                        break;