]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
staging: hv: Added heartbeat functionality to hv_utils
authorHank Janssen <hjanssen@microsoft.com>
Sat, 15 May 2010 21:39:58 +0000 (14:39 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 17 May 2010 23:32:30 +0000 (16:32 -0700)
Add heartbeat functionality to hv_utils/Hyper-V

Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/hv/channel_mgmt.c
drivers/staging/hv/hv_utils.c
drivers/staging/hv/utils.h
drivers/staging/hv/version_info.h

index 6877e8e7f71ec4b436ea0409a2bc8b2f891971c4..3f53b4d1e4cffcf09552871b30f5c9d6f98ce8a3 100644 (file)
@@ -33,8 +33,8 @@ struct vmbus_channel_message_table_entry {
        void (*messageHandler)(struct vmbus_channel_message_header *msg);
 };
 
-#define MAX_MSG_TYPES                    2
-#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 6
+#define MAX_MSG_TYPES                    3
+#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 7
 
 static const struct hv_guid
        gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = {
@@ -89,6 +89,14 @@ static const struct hv_guid
                        0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf
                }
        },
+       /* {57164f39-9115-4e78-ab55-382f3bd5422d} */
+       /* Heartbeat */
+       {
+               .data = {
+                       0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
+                       0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d
+               }
+       },
 };
 
 
@@ -211,6 +219,17 @@ struct hyperv_service_callback hv_cb_utils[MAX_MSG_TYPES] = {
                .callback = chn_cb_negotiate,
                .log_msg = "Timesync channel functionality initialized"
        },
+       /* {57164f39-9115-4e78-ab55-382f3bd5422d} */
+       /* Heartbeat */
+       {
+               .msg_type = HV_HEARTBEAT_MSG,
+               .data = {
+                       0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
+                       0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d
+               },
+               .callback = chn_cb_negotiate,
+               .log_msg = "Heartbeat channel functionality initialized"
+       },
 };
 EXPORT_SYMBOL(hv_cb_utils);
 
index db45d97a3a7c60d4b57c2d8c5c23ef85d0a25f44..8a49aafea37a5c7a7f2597e53134530c88331f11 100644 (file)
@@ -194,6 +194,62 @@ static void timesync_onchannelcallback(void *context)
        DPRINT_EXIT(VMBUS);
 }
 
+/*
+ * Heartbeat functionality.
+ * Every two seconds, Hyper-V send us a heartbeat request message.
+ * we respond to this message, and Hyper-V knows we are alive.
+ */
+static void heartbeat_onchannelcallback(void *context)
+{
+       struct vmbus_channel *channel = context;
+       u8 *buf;
+       u32 buflen, recvlen;
+       u64 requestid;
+       struct icmsg_hdr *icmsghdrp;
+       struct heartbeat_msg_data *heartbeat_msg;
+
+       DPRINT_ENTER(VMBUS);
+
+       buflen = PAGE_SIZE;
+       buf = kmalloc(buflen, GFP_ATOMIC);
+
+       VmbusChannelRecvPacket(channel, buf, buflen, &recvlen, &requestid);
+
+       if (recvlen > 0) {
+               DPRINT_DBG(VMBUS, "heartbeat packet: len=%d, requestid=%lld",
+                          recvlen, requestid);
+
+               icmsghdrp = (struct icmsg_hdr *)&buf[
+                       sizeof(struct vmbuspipe_hdr)];
+
+               icmsghdrp = (struct icmsg_hdr *)&buf[
+                               sizeof(struct vmbuspipe_hdr)];
+
+               if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
+                       prep_negotiate_resp(icmsghdrp, NULL, buf);
+               } else {
+                       heartbeat_msg = (struct heartbeat_msg_data *)&buf[
+                               sizeof(struct vmbuspipe_hdr) +
+                               sizeof(struct icmsg_hdr)];
+
+                       DPRINT_DBG(VMBUS, "heartbeat seq = %lld",
+                                  heartbeat_msg->seq_num);
+
+                       heartbeat_msg->seq_num += 1;
+               }
+
+               icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
+                       | ICMSGHDRFLAG_RESPONSE;
+
+               VmbusChannelSendPacket(channel, buf,
+                                      recvlen, requestid,
+                                      VmbusPacketTypeDataInBand, 0);
+       }
+
+       kfree(buf);
+
+       DPRINT_EXIT(VMBUS);
+}
 
 static int __init init_hyperv_utils(void)
 {
@@ -207,6 +263,10 @@ static int __init init_hyperv_utils(void)
                &timesync_onchannelcallback;
        hv_cb_utils[HV_TIMESYNC_MSG].callback = &timesync_onchannelcallback;
 
+       hv_cb_utils[HV_HEARTBEAT_MSG].channel->OnChannelCallback =
+               &heartbeat_onchannelcallback;
+       hv_cb_utils[HV_HEARTBEAT_MSG].callback = &heartbeat_onchannelcallback;
+
        return 0;
 }
 
@@ -221,6 +281,10 @@ static void exit_hyperv_utils(void)
        hv_cb_utils[HV_TIMESYNC_MSG].channel->OnChannelCallback =
                &chn_cb_negotiate;
        hv_cb_utils[HV_TIMESYNC_MSG].callback = &chn_cb_negotiate;
+
+       hv_cb_utils[HV_HEARTBEAT_MSG].channel->OnChannelCallback =
+               &chn_cb_negotiate;
+       hv_cb_utils[HV_HEARTBEAT_MSG].callback = &chn_cb_negotiate;
 }
 
 module_init(init_hyperv_utils);
index a4b9fd06e270b3a8c4a829b5424c997fb3c610be..7c0749999a6fa60809accc3ea463160b20aa61f6 100644 (file)
@@ -75,6 +75,10 @@ struct shutdown_msg_data {
        u8  display_message[2048];
 } __attribute__((packed));
 
+struct heartbeat_msg_data {
+       u64 seq_num;
+       u32 reserved[8];
+} __attribute__((packed));
 
 /* Time Sync IC defs */
 #define ICTIMESYNCFLAG_PROBE   0
@@ -97,6 +101,7 @@ struct ictimesync_data{
 /* Index for each IC struct in array hv_cb_utils[] */
 #define HV_SHUTDOWN_MSG                0
 #define HV_TIMESYNC_MSG                1
+#define HV_HEARTBEAT_MSG       2
 
 struct hyperv_service_callback {
        u8 msg_type;
index 82e74b1ab150d27a103a1035e43f7c1d8871ee85..35178f2c7967e9a270c0f02a9b6ac8d44c556201 100644 (file)
@@ -40,8 +40,9 @@
  *     Minor Number    Changes when new functionality is added
  *                     to the Linux IC's that is not a bug fix.
  *
+ * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
  */
-#define HV_DRV_VERSION           "3.0"
+#define HV_DRV_VERSION           "3.1"
 
 
 #endif