public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "K. Y. Srinivasan" <kys@microsoft.com>
To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com,
	jasowang@redhat.com
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Subject: [PATCH 07/28] Drivers: hv: Support handling multiple VMBUS versions
Date: Sat,  1 Dec 2012 06:46:38 -0800	[thread overview]
Message-ID: <1354373219-31374-7-git-send-email-kys@microsoft.com> (raw)
In-Reply-To: <1354373219-31374-1-git-send-email-kys@microsoft.com>

The current code hard coded the vmbus version independent of the host
it was running on. Add code to dynamically negotiate the most appropriate
version.

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
---
 drivers/hv/connection.c |  165 +++++++++++++++++++++++++++++++---------------
 include/linux/hyperv.h  |    6 --
 2 files changed, 111 insertions(+), 60 deletions(-)

diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index d1019a7..2b56a3f 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -40,15 +40,111 @@ struct vmbus_connection vmbus_connection = {
 };
 
 /*
+ * VMBUS version is 32 bit entity broken up into
+ * two 16 bit quantities: major_number. minor_number.
+ *
+ * 0 . 13 (Windows Server 2008)
+ * 1 . 1  (Windows 7)
+ * 2 . 4  (Windows 8)
+ */
+
+#define VERSION_WS2008	((0 << 16) | (13))
+#define VERSION_WIN7	((1 << 16) | (1))
+#define VERSION_WIN8	((2 << 16) | (4))
+
+#define VERSION_INVAL -1
+
+static __u32 vmbus_get_next_version(__u32 current_version)
+{
+	switch (current_version) {
+	case (VERSION_WIN7):
+		return VERSION_WS2008;
+
+	case (VERSION_WIN8):
+		return VERSION_WIN7;
+
+	case (VERSION_WS2008):
+	default:
+		return VERSION_INVAL;
+	}
+}
+
+static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
+					__u32 version)
+{
+	int ret = 0;
+	struct vmbus_channel_initiate_contact *msg;
+	unsigned long flags;
+	int t;
+
+	init_completion(&msginfo->waitevent);
+
+	msg = (struct vmbus_channel_initiate_contact *)msginfo->msg;
+
+	msg->header.msgtype = CHANNELMSG_INITIATE_CONTACT;
+	msg->vmbus_version_requested = version;
+	msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
+	msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages);
+	msg->monitor_page2 = virt_to_phys(
+			(void *)((unsigned long)vmbus_connection.monitor_pages +
+				 PAGE_SIZE));
+
+	/*
+	 * Add to list before we send the request since we may
+	 * receive the response before returning from this routine
+	 */
+	spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
+	list_add_tail(&msginfo->msglistentry,
+		      &vmbus_connection.chn_msg_list);
+
+	spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
+
+	ret = vmbus_post_msg(msg,
+			       sizeof(struct vmbus_channel_initiate_contact));
+	if (ret != 0) {
+		spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
+		list_del(&msginfo->msglistentry);
+		spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock,
+					flags);
+		return ret;
+	}
+
+	/* Wait for the connection response */
+	t =  wait_for_completion_timeout(&msginfo->waitevent, 5*HZ);
+	if (t == 0) {
+		spin_lock_irqsave(&vmbus_connection.channelmsg_lock,
+				flags);
+		list_del(&msginfo->msglistentry);
+		spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock,
+					flags);
+		return -ETIMEDOUT;
+	}
+
+	spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
+	list_del(&msginfo->msglistentry);
+	spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
+
+	/* Check if successful */
+	if (msginfo->response.version_response.version_supported) {
+		vmbus_connection.conn_state = CONNECTED;
+	} else {
+		pr_err("Unable to connect, "
+			"Version %d not supported by Hyper-V\n",
+			version);
+		return -ECONNREFUSED;
+	}
+
+	return ret;
+}
+
+/*
  * vmbus_connect - Sends a connect request on the partition service connection
  */
 int vmbus_connect(void)
 {
 	int ret = 0;
-	int t;
 	struct vmbus_channel_msginfo *msginfo = NULL;
-	struct vmbus_channel_initiate_contact *msg;
-	unsigned long flags;
+	__u32 version;
 
 	/* Initialize the vmbus connection */
 	vmbus_connection.conn_state = CONNECTING;
@@ -99,64 +195,25 @@ int vmbus_connect(void)
 		goto cleanup;
 	}
 
-	init_completion(&msginfo->waitevent);
-
-	msg = (struct vmbus_channel_initiate_contact *)msginfo->msg;
-
-	msg->header.msgtype = CHANNELMSG_INITIATE_CONTACT;
-	msg->vmbus_version_requested = VMBUS_REVISION_NUMBER;
-	msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
-	msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages);
-	msg->monitor_page2 = virt_to_phys(
-			(void *)((unsigned long)vmbus_connection.monitor_pages +
-				 PAGE_SIZE));
-
 	/*
-	 * Add to list before we send the request since we may
-	 * receive the response before returning from this routine
+	 * Negotiate a compatible VMBUS version number with the
+	 * host. We start with the highest number we can support
+	 * and work our way down until we negotiate a compatible
+	 * version.
 	 */
-	spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
-	list_add_tail(&msginfo->msglistentry,
-		      &vmbus_connection.chn_msg_list);
-
-	spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
 
-	ret = vmbus_post_msg(msg,
-			       sizeof(struct vmbus_channel_initiate_contact));
-	if (ret != 0) {
-		spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
-		list_del(&msginfo->msglistentry);
-		spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock,
-					flags);
-		goto cleanup;
-	}
+	version = VERSION_WS2008;
 
-	/* Wait for the connection response */
-	t =  wait_for_completion_timeout(&msginfo->waitevent, 5*HZ);
-	if (t == 0) {
-		spin_lock_irqsave(&vmbus_connection.channelmsg_lock,
-				flags);
-		list_del(&msginfo->msglistentry);
-		spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock,
-					flags);
-		ret = -ETIMEDOUT;
-		goto cleanup;
-	}
+	do {
+		ret = vmbus_negotiate_version(msginfo, version);
+		if (ret == 0)
+			break;
 
-	spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
-	list_del(&msginfo->msglistentry);
-	spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
+		version = vmbus_get_next_version(version);
+	} while (version != VERSION_INVAL);
 
-	/* Check if successful */
-	if (msginfo->response.version_response.version_supported) {
-		vmbus_connection.conn_state = CONNECTED;
-	} else {
-		pr_err("Unable to connect, "
-			"Version %d not supported by Hyper-V\n",
-			VMBUS_REVISION_NUMBER);
-		ret = -ECONNREFUSED;
+	if (version == VERSION_INVAL)
 		goto cleanup;
-	}
 
 	kfree(msginfo);
 	return 0;
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 1ffe84d..b097bf9 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -406,12 +406,6 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
 #define HV_DRV_VERSION           "3.1"
 
 
-/*
- * A revision number of vmbus that is used for ensuring both ends on a
- * partition are using compatible versions.
- */
-#define VMBUS_REVISION_NUMBER		13
-
 /* Make maximum size of pipe payload of 16K */
 #define MAX_PIPE_DATA_PAYLOAD		(sizeof(u8) * 16384)
 
-- 
1.7.4.1


  parent reply	other threads:[~2012-12-01 14:27 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-01 14:46 [PATCH 00/28] Drivers: hv: Update the Vmbus protocol K. Y. Srinivasan
2012-12-01 14:46 ` [PATCH 01/28] Drivers: hv: Implement routines for read side signaling optimization K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 02/28] Drivers: hv: Add state to manage batched reading K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 03/28] Drivers: hv: Turn off batched reading for util drivers K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 04/28] Drivers: hv: Optimize signaling in the read path K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 05/28] Drivers: hv: Optimize the signaling on the write path K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 06/28] Drivers: hv: Get rid of hv_get_ringbuffer_interrupt_mask() K. Y. Srinivasan
2012-12-01 14:46   ` K. Y. Srinivasan [this message]
2012-12-01 14:46   ` [PATCH 08/28] Drivers: hv: Update the ring buffer structure to match win8 functionality K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 09/28] Drivers: hv: Extend/modify vmbus_channel_offer_channel for win7 and beyond K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 10/28] Drivers: hv: Save and export negotiated vmbus version K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 11/28] Drivers: hv: Change the signature for hv_signal_event() K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 12/28] Drivers: hv: Change the signature of vmbus_set_event() K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 13/28] Drivers: hv: Move vmbus version definitions to hyperv.h K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 14/28] Drivers: hv: Manage signaling state on a per-connection basis K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 15/28] Drivers: hv: Cleanup vmbus_set_event() to support win7 and beyond K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 16/28] Drivers: hv: Setup a mapping for Hyper-V's notion cpu ID K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 17/28] Drivers: hv: Add state to manage incoming channel interrupt load K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 18/28] Drivers: hv: Modify the interrupt handling code to support win8 and beyond K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 19/28] Drivers: hv: Add code to distribute channel interrupt load K. Y. Srinivasan
2013-01-17 19:38     ` Greg KH
2013-01-17 21:28       ` KY Srinivasan
2012-12-01 14:46   ` [PATCH 20/28] Drivers: hv: Get rid of the unused global signaling state K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 21/28] Drivers: hv: Get rid of unnecessary request for offers K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 22/28] Drivers: hv: Manage event tasklets on per-cpu basis K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 23/28] Drivers: hv: Handle vmbus interrupts concurrently on all cpus K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 24/28] Drivers: hv: Add a check to deal with spurious interrupts K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 25/28] Drivers: hv: Enable protocol negotiation with win8 hosts K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 26/28] Drivers: hv: Implement flow management on the send side K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 27/28] Drivers: hv: Capture the host build information K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 28/28] Drivers: hv: Cleanup and consolidate reporting of build/version info K. Y. Srinivasan
2013-01-17 19:42 ` [PATCH 00/28] Drivers: hv: Update the Vmbus protocol Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1354373219-31374-7-git-send-email-kys@microsoft.com \
    --to=kys@microsoft.com \
    --cc=apw@canonical.com \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf@aepfle.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox