All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 01/54] Staging: hv: add the Hyper-V api header files
  2009-07-20 16:00   ` Greg Kroah-Hartman
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-api-header-files.patch --]
[-- Type: text/plain, Size: 121145 bytes --]

From: Hank Janssen <hjanssen@microsoft.com>

These are the header files for the API to talk to the Hyper-V
core.

Signed-off-by: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/include/ChannelMessages.h       |  312 +++++++
 drivers/staging/hv/include/HvHalApi.h              |   32 
 drivers/staging/hv/include/HvHcApi.h               |   60 +
 drivers/staging/hv/include/HvPtApi.h               |   86 ++
 drivers/staging/hv/include/HvStatus.h              |  718 ++++++++++++++++++
 drivers/staging/hv/include/HvSynicApi.h            |  490 ++++++++++++
 drivers/staging/hv/include/HvTypes.h               |   31 
 drivers/staging/hv/include/HvVpApi.h               |   51 +
 drivers/staging/hv/include/List.h                  |  269 ++++++
 drivers/staging/hv/include/VmbusChannelInterface.h |  131 +++
 drivers/staging/hv/include/VmbusPacketFormat.h     |  322 ++++++++
 drivers/staging/hv/include/nvspprotocol.h          |  306 +++++++
 drivers/staging/hv/include/rndis.h                 |  836 +++++++++++++++++++++
 drivers/staging/hv/include/vstorage.h              |  309 +++++++
 14 files changed, 3953 insertions(+)
 create mode 100644 drivers/staging/hv/include/ChannelMessages.h
 create mode 100644 drivers/staging/hv/include/HvHalApi.h
 create mode 100644 drivers/staging/hv/include/HvHcApi.h
 create mode 100644 drivers/staging/hv/include/HvPtApi.h
 create mode 100644 drivers/staging/hv/include/HvStatus.h
 create mode 100644 drivers/staging/hv/include/HvSynicApi.h
 create mode 100644 drivers/staging/hv/include/HvTypes.h
 create mode 100644 drivers/staging/hv/include/HvVpApi.h
 create mode 100644 drivers/staging/hv/include/List.h
 create mode 100644 drivers/staging/hv/include/VmbusChannelInterface.h
 create mode 100644 drivers/staging/hv/include/VmbusPacketFormat.h
 create mode 100644 drivers/staging/hv/include/nvspprotocol.h
 create mode 100644 drivers/staging/hv/include/rndis.h
 create mode 100644 drivers/staging/hv/include/vstorage.h

--- /dev/null
+++ b/drivers/staging/hv/include/ChannelMessages.h
@@ -0,0 +1,312 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+#include <VmbusPacketFormat.h>
+
+#define C_ASSERT(x)
+typedef UINT32 NTSTATUS;
+
+#pragma pack(push,1)
+
+//
+// Version 1 messages
+//
+
+typedef enum _VMBUS_CHANNEL_MESSAGE_TYPE
+{
+    ChannelMessageInvalid                   =  0,
+    ChannelMessageOfferChannel              =  1,
+    ChannelMessageRescindChannelOffer       =  2,
+    ChannelMessageRequestOffers             =  3,
+    ChannelMessageAllOffersDelivered        =  4,
+    ChannelMessageOpenChannel               =  5,
+    ChannelMessageOpenChannelResult         =  6,
+    ChannelMessageCloseChannel              =  7,
+    ChannelMessageGpadlHeader               =  8,
+    ChannelMessageGpadlBody                 =  9,
+    ChannelMessageGpadlCreated              = 10,
+    ChannelMessageGpadlTeardown             = 11,
+    ChannelMessageGpadlTorndown             = 12,
+    ChannelMessageRelIdReleased             = 13,
+    ChannelMessageInitiateContact           = 14,
+    ChannelMessageVersionResponse           = 15,
+    ChannelMessageUnload                    = 16,
+#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
+    ChannelMessageViewRangeAdd              = 17,
+    ChannelMessageViewRangeRemove           = 18,
+#endif
+    ChannelMessageCount
+} VMBUS_CHANNEL_MESSAGE_TYPE, *PVMBUS_CHANNEL_MESSAGE_TYPE;
+
+// begin_wpp config
+// CUSTOM_TYPE(ChannelMessageType, ItemEnum(_VMBUS_CHANNEL_MESSAGE_TYPE));
+// end_wpp
+
+typedef struct _VMBUS_CHANNEL_MESSAGE_HEADER
+{
+    VMBUS_CHANNEL_MESSAGE_TYPE  MessageType;
+    UINT32                      Padding;
+} VMBUS_CHANNEL_MESSAGE_HEADER, *PVMBUS_CHANNEL_MESSAGE_HEADER;
+
+// Query VMBus Version parameters
+typedef struct _VMBUS_CHANNEL_QUERY_VMBUS_VERSION
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32 Version;
+} VMBUS_CHANNEL_QUERY_VMBUS_VERSION, *PVMBUS_CHANNEL_QUERY_VMBUS_VERSION;
+
+// VMBus Version Supported parameters
+typedef struct _VMBUS_CHANNEL_VERSION_SUPPORTED
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    BOOLEAN VersionSupported;
+} VMBUS_CHANNEL_VERSION_SUPPORTED, *PVMBUS_CHANNEL_VERSION_SUPPORTED;
+
+// Offer Channel parameters
+typedef struct _VMBUS_CHANNEL_OFFER_CHANNEL
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    VMBUS_CHANNEL_OFFER Offer;
+    UINT32  ChildRelId;
+    UINT8   MonitorId;
+    BOOLEAN MonitorAllocated;
+} VMBUS_CHANNEL_OFFER_CHANNEL, *PVMBUS_CHANNEL_OFFER_CHANNEL;
+
+//
+// Make sure VMBUS_CHANNEL_OFFER_CHANNEL fits into Synic message.
+//
+C_ASSERT(sizeof(VMBUS_CHANNEL_OFFER_CHANNEL) <= MAXIMUM_SYNIC_MESSAGE_BYTES);
+
+// Rescind Offer parameters
+typedef struct _VMBUS_CHANNEL_RESCIND_OFFER
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32          ChildRelId;
+} VMBUS_CHANNEL_RESCIND_OFFER, *PVMBUS_CHANNEL_RESCIND_OFFER;
+
+// Request Offer -- no parameters, SynIC message contains the partition ID
+// Set Snoop -- no parameters, SynIC message contains the partition ID
+// Clear Snoop -- no parameters, SynIC message contains the partition ID
+// All Offers Delivered -- no parameters, SynIC message contains the partition ID
+// Flush Client -- no parameters, SynIC message contains the partition ID
+
+// Open Channel parameters
+typedef struct _VMBUS_CHANNEL_OPEN_CHANNEL
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+
+    //
+    // Identifies the specific VMBus channel that is being opened.
+    //
+    UINT32          ChildRelId;
+
+    //
+    // ID making a particular open request at a channel offer unique.
+    //
+    UINT32          OpenId;
+
+    //
+    // GPADL for the channel's ring buffer.
+    //
+    GPADL_HANDLE    RingBufferGpadlHandle;
+
+    //
+    // GPADL for the channel's server context save area.
+    //
+    GPADL_HANDLE    ServerContextAreaGpadlHandle;
+
+    //
+    // The upstream ring buffer begins at offset zero in the memory described
+    // by RingBufferGpadlHandle. The downstream ring buffer follows it at this
+    // offset (in pages).
+    //
+    UINT32          DownstreamRingBufferPageOffset;
+
+    //
+    // User-specific data to be passed along to the server endpoint.
+    //
+    UCHAR           UserData[MAX_USER_DEFINED_BYTES];
+
+} VMBUS_CHANNEL_OPEN_CHANNEL, *PVMBUS_CHANNEL_OPEN_CHANNEL;
+
+// Reopen Channel parameters;
+typedef VMBUS_CHANNEL_OPEN_CHANNEL VMBUS_CHANNEL_REOPEN_CHANNEL, *PVMBUS_CHANNEL_REOPEN_CHANNEL;
+
+// Open Channel Result parameters
+typedef struct _VMBUS_CHANNEL_OPEN_RESULT
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32      ChildRelId;
+    UINT32      OpenId;
+    NTSTATUS    Status;
+} VMBUS_CHANNEL_OPEN_RESULT, *PVMBUS_CHANNEL_OPEN_RESULT;
+
+// Close channel parameters;
+typedef struct _VMBUS_CHANNEL_CLOSE_CHANNEL
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32      ChildRelId;
+} VMBUS_CHANNEL_CLOSE_CHANNEL, *PVMBUS_CHANNEL_CLOSE_CHANNEL;
+
+// Channel Message GPADL
+#define GPADL_TYPE_RING_BUFFER          1
+#define GPADL_TYPE_SERVER_SAVE_AREA     2
+#define GPADL_TYPE_TRANSACTION          8
+
+//
+// The number of PFNs in a GPADL message is defined by the number of pages
+// that would be spanned by ByteCount and ByteOffset.  If the implied number
+// of PFNs won't fit in this packet, there will be a follow-up packet that
+// contains more.
+//
+
+typedef struct _VMBUS_CHANNEL_GPADL_HEADER
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32      ChildRelId;
+    UINT32      Gpadl;
+    UINT16      RangeBufLen;
+    UINT16      RangeCount;
+    GPA_RANGE   Range[0];
+} VMBUS_CHANNEL_GPADL_HEADER, *PVMBUS_CHANNEL_GPADL_HEADER;
+
+
+//
+// This is the followup packet that contains more PFNs.
+//
+
+typedef struct _VMBUS_CHANNEL_GPADL_BODY
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32              MessageNumber;
+    UINT32              Gpadl;
+    UINT64              Pfn[0];
+} VMBUS_CHANNEL_GPADL_BODY, *PVMBUS_CHANNEL_GPADL_BODY;
+
+
+typedef struct _VMBUS_CHANNEL_GPADL_CREATED
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32              ChildRelId;
+    UINT32              Gpadl;
+    UINT32              CreationStatus;
+} VMBUS_CHANNEL_GPADL_CREATED, *PVMBUS_CHANNEL_GPADL_CREATED;
+
+typedef struct _VMBUS_CHANNEL_GPADL_TEARDOWN
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32              ChildRelId;
+    UINT32              Gpadl;
+} VMBUS_CHANNEL_GPADL_TEARDOWN, *PVMBUS_CHANNEL_GPADL_TEARDOWN;
+
+typedef struct _VMBUS_CHANNEL_GPADL_TORNDOWN
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32              Gpadl;
+} VMBUS_CHANNEL_GPADL_TORNDOWN, *PVMBUS_CHANNEL_GPADL_TORNDOWN;
+
+#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
+typedef struct _VMBUS_CHANNEL_VIEW_RANGE_ADD
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    PHYSICAL_ADDRESS    ViewRangeBase;
+    UINT64              ViewRangeLength;
+    UINT32              ChildRelId;
+} VMBUS_CHANNEL_VIEW_RANGE_ADD, *PVMBUS_CHANNEL_VIEW_RANGE_ADD;
+
+typedef struct _VMBUS_CHANNEL_VIEW_RANGE_REMOVE
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    PHYSICAL_ADDRESS    ViewRangeBase;
+    UINT32              ChildRelId;
+} VMBUS_CHANNEL_VIEW_RANGE_REMOVE, *PVMBUS_CHANNEL_VIEW_RANGE_REMOVE;
+#endif
+
+typedef struct _VMBUS_CHANNEL_RELID_RELEASED
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32              ChildRelId;
+} VMBUS_CHANNEL_RELID_RELEASED, *PVMBUS_CHANNEL_RELID_RELEASED;
+
+typedef struct _VMBUS_CHANNEL_INITIATE_CONTACT
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    UINT32              VMBusVersionRequested;
+    UINT32              Padding2;
+    UINT64              InterruptPage;
+    UINT64              MonitorPage1;
+    UINT64              MonitorPage2;
+} VMBUS_CHANNEL_INITIATE_CONTACT, *PVMBUS_CHANNEL_INITIATE_CONTACT;
+
+typedef struct _VMBUS_CHANNEL_VERSION_RESPONSE
+{
+    VMBUS_CHANNEL_MESSAGE_HEADER Header;
+    BOOLEAN     VersionSupported;
+} VMBUS_CHANNEL_VERSION_RESPONSE, *PVMBUS_CHANNEL_VERSION_RESPONSE;
+
+typedef VMBUS_CHANNEL_MESSAGE_HEADER VMBUS_CHANNEL_UNLOAD, *PVMBUS_CHANNEL_UNLOAD;
+
+//
+// Kind of a table to use the preprocessor to get us the right type for a
+// specified message ID. Used with ChAllocateSendMessage()
+//
+#define ChannelMessageQueryVmbusVersion_TYPE    VMBUS_CHANNEL_MESSAGE_HEADER
+#define ChannelMessageVmbusVersionSupported_TYPE VMBUS_CHANNEL_VERSION_SUPPORTED
+#define ChannelMessageOfferChannel_TYPE         VMBUS_CHANNEL_OFFER_CHANNEL
+#define ChannelMessageRescindChannelOffer_TYPE  VMBUS_CHANNEL_RESCIND_OFFER
+#define ChannelMessageRequestOffers_TYPE        VMBUS_CHANNEL_MESSAGE_HEADER
+#define ChannelMessageAllOffersDelivered_TYPE   VMBUS_CHANNEL_MESSAGE_HEADER
+#define ChannelMessageOpenChannel_TYPE          VMBUS_CHANNEL_OPEN_CHANNEL
+#define ChannelMessageOpenChannelResult_TYPE    VMBUS_CHANNEL_OPEN_RESULT
+#define ChannelMessageCloseChannel_TYPE         VMBUS_CHANNEL_CLOSE_CHANNEL
+#define ChannelMessageAllGpadlsUnmapped_TYPE    VMBUS_CHANNEL_CLOSE_CHANNEL
+#define ChannelMessageGpadlHeader_TYPE          VMBUS_CHANNEL_GPADL_HEADER
+#define ChannelMessageGpadlBody_TYPE            VMBUS_CHANNEL_GPADL_BODY
+#define ChannelMessageGpadlCreated_TYPE         VMBUS_CHANNEL_GPADL_CREATED
+#define ChannelMessageGpadlTeardown_TYPE        VMBUS_CHANNEL_GPADL_TEARDOWN
+#define ChannelMessageGpadlTorndown_TYPE        VMBUS_CHANNEL_GPADL_TORNDOWN
+#define ChannelMessageViewRangeAdd_TYPE         VMBUS_CHANNEL_VIEW_RANGE_ADD
+#define ChannelMessageViewRangeRemove_TYPE      VMBUS_CHANNEL_VIEW_RANGE_REMOVE
+#define ChannelMessageRelIdReleased_TYPE        VMBUS_CHANNEL_RELID_RELEASED
+#define ChannelMessageInitiateContact_TYPE      VMBUS_CHANNEL_INITIATE_CONTACT
+#define ChannelMessageVersionResponse_TYPE      VMBUS_CHANNEL_VERSION_RESPONSE
+#define ChannelMessageUnload_TYPE               VMBUS_CHANNEL_UNLOAD
+
+//
+// Preprocessor wrapper to ChAllocateSendMessageSize() converting the return
+// value to the correct pointer and calculate the needed size.
+//
+// Argument:
+//
+//  Id - the numberic ID (type VMBUS_CHANNEL_MESSAGE_TYPE) of the message to
+//       send.
+//
+#define ChAllocateSendMessage(Id, Fn, Context)   \
+    (Id##_TYPE*)ChAllocateSendMessageSized(sizeof(Id##_TYPE), Id, Fn, Context)
+
+
+#pragma pack(pop)
+
--- /dev/null
+++ b/drivers/staging/hv/include/HvHalApi.h
@@ -0,0 +1,32 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+
+//
+// Time in the hypervisor is measured in 100 nanosecond units
+//
+typedef UINT64 HV_NANO100_TIME,     *PHV_NANO100_TIME;
+typedef UINT64 HV_NANO100_DURATION, *PHV_NANO100_DURATION;
--- /dev/null
+++ b/drivers/staging/hv/include/HvHcApi.h
@@ -0,0 +1,60 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+//
+// Declare the various hypercall operations.
+//
+typedef enum _HV_CALL_CODE
+{
+
+    HvCallPostMessage                   = 0x005c,
+    HvCallSignalEvent                   = 0x005d,
+
+} HV_CALL_CODE, *PHV_CALL_CODE;
+//
+// Definition of the HvPostMessage hypercall input structure.
+//
+
+typedef struct _HV_INPUT_POST_MESSAGE
+{
+    HV_CONNECTION_ID    ConnectionId;
+    UINT32              Reserved;
+    HV_MESSAGE_TYPE     MessageType;
+    UINT32              PayloadSize;
+    UINT64              Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
+} HV_INPUT_POST_MESSAGE, *PHV_INPUT_POST_MESSAGE;
+
+
+//
+// Definition of the HvSignalEvent hypercall input structure.
+//
+
+typedef struct _HV_INPUT_SIGNAL_EVENT
+{
+    HV_CONNECTION_ID ConnectionId;
+    UINT16           FlagNumber;
+    UINT16           RsvdZ;
+} HV_INPUT_SIGNAL_EVENT, *PHV_INPUT_SIGNAL_EVENT;
--- /dev/null
+++ b/drivers/staging/hv/include/HvPtApi.h
@@ -0,0 +1,86 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+//
+// Versioning definitions used for guests reporting themselves to the
+// hypervisor, and visa versa.
+// ==================================================================
+//
+
+//
+// Version info reported by guest OS's
+//
+typedef enum _HV_GUEST_OS_VENDOR
+{
+    HvGuestOsVendorMicrosoft        = 0x0001
+
+} HV_GUEST_OS_VENDOR, *PHV_GUEST_OS_VENDOR;
+
+typedef enum _HV_GUEST_OS_MICROSOFT_IDS
+{
+    HvGuestOsMicrosoftUndefined     = 0x00,
+    HvGuestOsMicrosoftMSDOS         = 0x01,
+    HvGuestOsMicrosoftWindows3x     = 0x02,
+    HvGuestOsMicrosoftWindows9x     = 0x03,
+    HvGuestOsMicrosoftWindowsNT     = 0x04,
+    HvGuestOsMicrosoftWindowsCE     = 0x05
+
+} HV_GUEST_OS_MICROSOFT_IDS, *PHV_GUEST_OS_MICROSOFT_IDS;
+
+//
+// Declare the MSR used to identify the guest OS.
+//
+#define HV_X64_MSR_GUEST_OS_ID 0x40000000
+
+typedef union _HV_X64_MSR_GUEST_OS_ID_CONTENTS
+{
+    UINT64 AsUINT64;
+    struct
+    {
+        UINT64 BuildNumber    : 16;
+        UINT64 ServiceVersion : 8; // Service Pack, etc.
+        UINT64 MinorVersion   : 8;
+        UINT64 MajorVersion   : 8;
+        UINT64 OsId           : 8; // HV_GUEST_OS_MICROSOFT_IDS (If Vendor=MS)
+        UINT64 VendorId       : 16; // HV_GUEST_OS_VENDOR
+    };
+} HV_X64_MSR_GUEST_OS_ID_CONTENTS, *PHV_X64_MSR_GUEST_OS_ID_CONTENTS;
+
+//
+// Declare the MSR used to setup pages used to communicate with the hypervisor.
+//
+#define HV_X64_MSR_HYPERCALL 0x40000001
+
+typedef union _HV_X64_MSR_HYPERCALL_CONTENTS
+{
+    UINT64 AsUINT64;
+    struct
+    {
+        UINT64 Enable               : 1;
+        UINT64 Reserved             : 11;
+        UINT64 GuestPhysicalAddress : 52;
+    };
+} HV_X64_MSR_HYPERCALL_CONTENTS, *PHV_X64_MSR_HYPERCALL_CONTENTS;
--- /dev/null
+++ b/drivers/staging/hv/include/HvStatus.h
@@ -0,0 +1,718 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+// begin_hvgdk
+//
+// Status codes for hypervisor operations.
+//
+typedef UINT16 HV_STATUS, *PHV_STATUS;
+
+//
+// MessageId: HV_STATUS_SUCCESS
+//
+// MessageText:
+//
+// The specified hypercall succeeded
+//
+#define HV_STATUS_SUCCESS                ((HV_STATUS)0x0000)
+
+//
+// MessageId: HV_STATUS_INVALID_HYPERCALL_CODE
+//
+// MessageText:
+//
+// The hypervisor does not support the operation because the specified hypercall code is not supported.
+//
+#define HV_STATUS_INVALID_HYPERCALL_CODE ((HV_STATUS)0x0002)
+
+//
+// MessageId: HV_STATUS_INVALID_HYPERCALL_INPUT
+//
+// MessageText:
+//
+// The hypervisor does not support the operation because the encoding for the hypercall input register is not supported.
+//
+#define HV_STATUS_INVALID_HYPERCALL_INPUT ((HV_STATUS)0x0003)
+
+//
+// MessageId: HV_STATUS_INVALID_ALIGNMENT
+//
+// MessageText:
+//
+// The hypervisor could not perform the operation beacuse a parameter has an invalid alignment.
+//
+#define HV_STATUS_INVALID_ALIGNMENT      ((HV_STATUS)0x0004)
+
+//
+// MessageId: HV_STATUS_INVALID_PARAMETER
+//
+// MessageText:
+//
+// The hypervisor could not perform the operation beacuse an invalid parameter was specified.
+//
+#define HV_STATUS_INVALID_PARAMETER      ((HV_STATUS)0x0005)
+
+//
+// MessageId: HV_STATUS_ACCESS_DENIED
+//
+// MessageText:
+//
+// Access to the specified object was denied.
+//
+#define HV_STATUS_ACCESS_DENIED          ((HV_STATUS)0x0006)
+
+//
+// MessageId: HV_STATUS_INVALID_PARTITION_STATE
+//
+// MessageText:
+//
+// The hypervisor could not perform the operation because the partition is entering or in an invalid state.
+//
+#define HV_STATUS_INVALID_PARTITION_STATE ((HV_STATUS)0x0007)
+
+//
+// MessageId: HV_STATUS_OPERATION_DENIED
+//
+// MessageText:
+//
+// The operation is not allowed in the current state.
+//
+#define HV_STATUS_OPERATION_DENIED       ((HV_STATUS)0x0008)
+
+//
+// MessageId: HV_STATUS_UNKNOWN_PROPERTY
+//
+// MessageText:
+//
+// The hypervisor does not recognize the specified partition property.
+//
+#define HV_STATUS_UNKNOWN_PROPERTY       ((HV_STATUS)0x0009)
+
+//
+// MessageId: HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE
+//
+// MessageText:
+//
+// The specified value of a partition property is out of range or violates an invariant.
+//
+#define HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE ((HV_STATUS)0x000A)
+
+//
+// MessageId: HV_STATUS_INSUFFICIENT_MEMORY
+//
+// MessageText:
+//
+// There is not enough memory in the hypervisor pool to complete the operation.
+//
+#define HV_STATUS_INSUFFICIENT_MEMORY    ((HV_STATUS)0x000B)
+
+//
+// MessageId: HV_STATUS_PARTITION_TOO_DEEP
+//
+// MessageText:
+//
+// The maximum partition depth has been exceeded for the partition hierarchy.
+//
+#define HV_STATUS_PARTITION_TOO_DEEP     ((HV_STATUS)0x000C)
+
+//
+// MessageId: HV_STATUS_INVALID_PARTITION_ID
+//
+// MessageText:
+//
+// A partition with the specified partition Id does not exist.
+//
+#define HV_STATUS_INVALID_PARTITION_ID   ((HV_STATUS)0x000D)
+
+//
+// MessageId: HV_STATUS_INVALID_VP_INDEX
+//
+// MessageText:
+//
+// The hypervisor could not perform the operation because the specified VP index is invalid.
+//
+#define HV_STATUS_INVALID_VP_INDEX       ((HV_STATUS)0x000E)
+
+//
+// MessageId: HV_STATUS_NOT_FOUND
+//
+// MessageText:
+//
+// The iteration is complete; no addition items in the iteration could be found.
+//
+#define HV_STATUS_NOT_FOUND              ((HV_STATUS)0x0010)
+
+//
+// MessageId: HV_STATUS_INVALID_PORT_ID
+//
+// MessageText:
+//
+// The hypervisor could not perform the operation because the specified port identifier is invalid.
+//
+#define HV_STATUS_INVALID_PORT_ID        ((HV_STATUS)0x0011)
+
+//
+// MessageId: HV_STATUS_INVALID_CONNECTION_ID
+//
+// MessageText:
+//
+// The hypervisor could not perform the operation because the specified connection identifier is invalid.
+//
+#define HV_STATUS_INVALID_CONNECTION_ID  ((HV_STATUS)0x0012)
+
+//
+// MessageId: HV_STATUS_INSUFFICIENT_BUFFERS
+//
+// MessageText:
+//
+// You did not supply enough message buffers to send a message.
+//
+#define HV_STATUS_INSUFFICIENT_BUFFERS   ((HV_STATUS)0x0013)
+
+//
+// MessageId: HV_STATUS_NOT_ACKNOWLEDGED
+//
+// MessageText:
+//
+// The previous virtual interrupt has not been acknowledged.
+//
+#define HV_STATUS_NOT_ACKNOWLEDGED       ((HV_STATUS)0x0014)
+
+//
+// MessageId: HV_STATUS_INVALID_VP_STATE
+//
+// MessageText:
+//
+// A virtual processor is not in the correct state for the performance of the indicated operation.
+//
+#define HV_STATUS_INVALID_VP_STATE       ((HV_STATUS)0x0015)
+
+//
+// MessageId: HV_STATUS_ACKNOWLEDGED
+//
+// MessageText:
+//
+// The previous virtual interrupt has already been acknowledged.
+//
+#define HV_STATUS_ACKNOWLEDGED           ((HV_STATUS)0x0016)
+
+//
+// MessageId: HV_STATUS_INVALID_SAVE_RESTORE_STATE
+//
+// MessageText:
+//
+// The indicated partition is not in a valid state for saving or restoring.
+//
+#define HV_STATUS_INVALID_SAVE_RESTORE_STATE ((HV_STATUS)0x0017)
+
+//
+// MessageId: HV_STATUS_INVALID_SYNIC_STATE
+//
+// MessageText:
+//
+// The hypervisor could not complete the operation because a required feature of the synthetic interrupt controller (SynIC) was disabled.
+//
+#define HV_STATUS_INVALID_SYNIC_STATE    ((HV_STATUS)0x0018)
+
+//
+// MessageId: HV_STATUS_OBJECT_IN_USE
+//
+// MessageText:
+//
+// The hypervisor could not perform the operation because the object or value was either already in use or being used for a purpose that would not permit completing the operation.
+//
+#define HV_STATUS_OBJECT_IN_USE          ((HV_STATUS)0x0019)
+
+//
+// MessageId: HV_STATUS_INVALID_PROXIMITY_DOMAIN_INFO
+//
+// MessageText:
+//
+// The proximity domain information is invalid.
+//
+#define HV_STATUS_INVALID_PROXIMITY_DOMAIN_INFO ((HV_STATUS)0x001A)
+
+//
+// MessageId: HV_STATUS_NO_DATA
+//
+// MessageText:
+//
+// An attempt to retrieve debugging data failed because none was available.
+//
+#define HV_STATUS_NO_DATA                ((HV_STATUS)0x001B)
+
+//
+// MessageId: HV_STATUS_INACTIVE
+//
+// MessageText:
+//
+// The physical connection being used for debuggging has not recorded any receive activity since the last operation.
+//
+#define HV_STATUS_INACTIVE               ((HV_STATUS)0x001C)
+
+//
+// MessageId: HV_STATUS_NO_RESOURCES
+//
+// MessageText:
+//
+// There are not enough resources to complete the operation.
+//
+#define HV_STATUS_NO_RESOURCES           ((HV_STATUS)0x001D)
+
+//
+// MessageId: HV_STATUS_FEATURE_UNAVAILABLE
+//
+// MessageText:
+//
+// A hypervisor feature is not available to the user.
+//
+#define HV_STATUS_FEATURE_UNAVAILABLE    ((HV_STATUS)0x001E)
+
+// end_hvgdk
+
+//
+// MessageId: HV_STATUS_UNSUCCESSFUL
+//
+// MessageText:
+//
+// {Operation Failed}
+// The requested operation was unsuccessful.
+//
+#define HV_STATUS_UNSUCCESSFUL           ((HV_STATUS)0x1001)
+
+//
+// MessageId: HV_STATUS_INSUFFICIENT_BUFFER
+//
+// MessageText:
+//
+// The specified buffer was too small to contain all of the requested data.
+//
+#define HV_STATUS_INSUFFICIENT_BUFFER    ((HV_STATUS)0x1002)
+
+//
+// MessageId: HV_STATUS_GPA_NOT_PRESENT
+//
+// MessageText:
+//
+// The guest physical address is not currently associated with a system physical address.
+//
+#define HV_STATUS_GPA_NOT_PRESENT        ((HV_STATUS)0x1003)
+
+//
+// MessageId: HV_STATUS_GUEST_PAGE_FAULT
+//
+// MessageText:
+//
+// The operation would have resulted in a page fault in the guest.
+//
+#define HV_STATUS_GUEST_PAGE_FAULT       ((HV_STATUS)0x1004)
+
+//
+// MessageId: HV_STATUS_RUNDOWN_DISABLED
+//
+// MessageText:
+//
+// The operation cannot proceed as the rundown object was marked disabled.
+//
+#define HV_STATUS_RUNDOWN_DISABLED       ((HV_STATUS)0x1005)
+
+//
+// MessageId: HV_STATUS_KEY_ALREADY_EXISTS
+//
+// MessageText:
+//
+// The entry cannot be added as another entry with the same key already exists.
+//
+#define HV_STATUS_KEY_ALREADY_EXISTS     ((HV_STATUS)0x1006)
+
+//
+// MessageId: HV_STATUS_GPA_INTERCEPT
+//
+// MessageText:
+//
+// The operation resulted an intercept on a region of guest physical memory.
+//
+#define HV_STATUS_GPA_INTERCEPT          ((HV_STATUS)0x1007)
+
+//
+// MessageId: HV_STATUS_GUEST_GENERAL_PROTECTION_FAULT
+//
+// MessageText:
+//
+// The operation would have resulted in a general protection fault in the guest.
+//
+#define HV_STATUS_GUEST_GENERAL_PROTECTION_FAULT ((HV_STATUS)0x1008)
+
+//
+// MessageId: HV_STATUS_GUEST_STACK_FAULT
+//
+// MessageText:
+//
+// The operation would have resulted in a stack fault in the guest.
+//
+#define HV_STATUS_GUEST_STACK_FAULT      ((HV_STATUS)0x1009)
+
+//
+// MessageId: HV_STATUS_GUEST_INVALID_OPCODE_FAULT
+//
+// MessageText:
+//
+// The operation would have resulted in an invalid opcode fault in the guest.
+//
+#define HV_STATUS_GUEST_INVALID_OPCODE_FAULT ((HV_STATUS)0x100A)
+
+//
+// MessageId: HV_STATUS_FINALIZE_INCOMPLETE
+//
+// MessageText:
+//
+// The partition is not completely finalized.
+//
+#define HV_STATUS_FINALIZE_INCOMPLETE    ((HV_STATUS)0x100B)
+
+//
+// MessageId: HV_STATUS_GUEST_MACHINE_CHECK_ABORT
+//
+// MessageText:
+//
+// The operation would have resulted in an machine check abort in the guest.
+//
+#define HV_STATUS_GUEST_MACHINE_CHECK_ABORT ((HV_STATUS)0x100C)
+
+//
+// MessageId: HV_STATUS_ILLEGAL_OVERLAY_ACCESS
+//
+// MessageText:
+//
+// An illegal access was attempted to an overlay page.
+//
+#define HV_STATUS_ILLEGAL_OVERLAY_ACCESS ((HV_STATUS)0x100D)
+
+//
+// MessageId: HV_STATUS_INSUFFICIENT_SYSTEM_VA
+//
+// MessageText:
+//
+// There is not enough system VA space available to satisfy the request,
+//
+#define HV_STATUS_INSUFFICIENT_SYSTEM_VA ((HV_STATUS)0x100E)
+
+//
+// MessageId: HV_STATUS_VIRTUAL_ADDRESS_NOT_MAPPED
+//
+// MessageText:
+//
+// The passed virtual address was not mapped in the hypervisor address space.
+//
+#define HV_STATUS_VIRTUAL_ADDRESS_NOT_MAPPED ((HV_STATUS)0x100F)
+
+//
+// MessageId: HV_STATUS_NOT_IMPLEMENTED
+//
+// MessageText:
+//
+// The requested operation is not implemented in this version of the hypervisor.
+//
+#define HV_STATUS_NOT_IMPLEMENTED        ((HV_STATUS)0x1010)
+
+//
+// MessageId: HV_STATUS_VMX_INSTRUCTION_FAILED
+//
+// MessageText:
+//
+// The requested VMX instruction failed to complete succesfully.
+//
+#define HV_STATUS_VMX_INSTRUCTION_FAILED ((HV_STATUS)0x1011)
+
+//
+// MessageId: HV_STATUS_VMX_INSTRUCTION_FAILED_WITH_STATUS
+//
+// MessageText:
+//
+// The requested VMX instruction failed to complete succesfully indicating status.
+//
+#define HV_STATUS_VMX_INSTRUCTION_FAILED_WITH_STATUS ((HV_STATUS)0x1012)
+
+//
+// MessageId: HV_STATUS_MSR_ACCESS_FAILED
+//
+// MessageText:
+//
+// The requested access to the model specific register failed.
+//
+#define HV_STATUS_MSR_ACCESS_FAILED      ((HV_STATUS)0x1013)
+
+//
+// MessageId: HV_STATUS_CR_ACCESS_FAILED
+//
+// MessageText:
+//
+// The requested access to the control register failed.
+//
+#define HV_STATUS_CR_ACCESS_FAILED       ((HV_STATUS)0x1014)
+
+//
+// MessageId: HV_STATUS_TIMEOUT
+//
+// MessageText:
+//
+// The specified timeout expired before the operation completed.
+//
+#define HV_STATUS_TIMEOUT                ((HV_STATUS)0x1016)
+
+//
+// MessageId: HV_STATUS_MSR_INTERCEPT
+//
+// MessageText:
+//
+// The requested access to the model specific register generated an intercept.
+//
+#define HV_STATUS_MSR_INTERCEPT          ((HV_STATUS)0x1017)
+
+//
+// MessageId: HV_STATUS_CPUID_INTERCEPT
+//
+// MessageText:
+//
+// The CPUID instruction generated an intercept.
+//
+#define HV_STATUS_CPUID_INTERCEPT        ((HV_STATUS)0x1018)
+
+//
+// MessageId: HV_STATUS_REPEAT_INSTRUCTION
+//
+// MessageText:
+//
+// The current instruction should be repeated and the instruction pointer not advanced.
+//
+#define HV_STATUS_REPEAT_INSTRUCTION     ((HV_STATUS)0x1019)
+
+//
+// MessageId: HV_STATUS_PAGE_PROTECTION_VIOLATION
+//
+// MessageText:
+//
+// The current instruction should be repeated and the instruction pointer not advanced.
+//
+#define HV_STATUS_PAGE_PROTECTION_VIOLATION ((HV_STATUS)0x101A)
+
+//
+// MessageId: HV_STATUS_PAGE_TABLE_INVALID
+//
+// MessageText:
+//
+// The current instruction should be repeated and the instruction pointer not advanced.
+//
+#define HV_STATUS_PAGE_TABLE_INVALID     ((HV_STATUS)0x101B)
+
+//
+// MessageId: HV_STATUS_PAGE_NOT_PRESENT
+//
+// MessageText:
+//
+// The current instruction should be repeated and the instruction pointer not advanced.
+//
+#define HV_STATUS_PAGE_NOT_PRESENT       ((HV_STATUS)0x101C)
+
+//
+// MessageId: HV_STATUS_IO_INTERCEPT
+//
+// MessageText:
+//
+// The requested access to the I/O port generated an intercept.
+//
+#define HV_STATUS_IO_INTERCEPT           ((HV_STATUS)0x101D)
+
+//
+// MessageId: HV_STATUS_NOTHING_TO_DO
+//
+// MessageText:
+//
+// There is nothing to do.
+//
+#define HV_STATUS_NOTHING_TO_DO          ((HV_STATUS)0x101E)
+
+//
+// MessageId: HV_STATUS_THREAD_TERMINATING
+//
+// MessageText:
+//
+// The requested thread is terminating.
+//
+#define HV_STATUS_THREAD_TERMINATING     ((HV_STATUS)0x101F)
+
+//
+// MessageId: HV_STATUS_SECTION_ALREADY_CONSTRUCTED
+//
+// MessageText:
+//
+// The specified section was already constructed.
+//
+#define HV_STATUS_SECTION_ALREADY_CONSTRUCTED ((HV_STATUS)0x1020)
+
+//
+// MessageId: HV_STATUS_SECTION_NOT_ALREADY_CONSTRUCTED
+//
+// MessageText:
+//
+// The specified section was not already constructed.
+//
+#define HV_STATUS_SECTION_NOT_ALREADY_CONSTRUCTED ((HV_STATUS)0x1021)
+
+//
+// MessageId: HV_STATUS_PAGE_ALREADY_COMMITTED
+//
+// MessageText:
+//
+// The specified virtual address was already backed by physical memory.
+//
+#define HV_STATUS_PAGE_ALREADY_COMMITTED ((HV_STATUS)0x1022)
+
+//
+// MessageId: HV_STATUS_PAGE_NOT_ALREADY_COMMITTED
+//
+// MessageText:
+//
+// The specified virtual address was not already backed by physical memory.
+//
+#define HV_STATUS_PAGE_NOT_ALREADY_COMMITTED ((HV_STATUS)0x1023)
+
+//
+// MessageId: HV_STATUS_COMMITTED_PAGES_REMAIN
+//
+// MessageText:
+//
+// Committed pages remain in the section.
+//
+#define HV_STATUS_COMMITTED_PAGES_REMAIN ((HV_STATUS)0x1024)
+
+//
+// MessageId: HV_STATUS_NO_REMAINING_COMMITTED_PAGES
+//
+// MessageText:
+//
+// No additional committed pages beyond the specified page exist in the section.
+//
+#define HV_STATUS_NO_REMAINING_COMMITTED_PAGES ((HV_STATUS)0x1025)
+
+//
+// MessageId: HV_STATUS_INSUFFICIENT_COMPARTMENT_VA
+//
+// MessageText:
+//
+// The VA space of the compartment is exhausted.
+//
+#define HV_STATUS_INSUFFICIENT_COMPARTMENT_VA ((HV_STATUS)0x1026)
+
+//
+// MessageId: HV_STATUS_DEREF_SPA_LIST_FULL
+//
+// MessageText:
+//
+// The SPA dereference list is full, and there are additional entries
+// to be added to it.
+//
+#define HV_STATUS_DEREF_SPA_LIST_FULL ((HV_STATUS)0x1027)
+
+//
+// MessageId: HV_STATUS_GPA_OUT_OF_RANGE
+//
+// MessageText:
+//
+// The supplied GPA is out of range.
+//
+#define HV_STATUS_GPA_OUT_OF_RANGE ((HV_STATUS)0x1027)
+
+//
+// MessageId: HV_STATUS_NONVOLATILE_XMM_STALE
+//
+// MessageText:
+//
+// The XMM register that was being accessed is stale.
+//
+#define HV_STATUS_NONVOLATILE_XMM_STALE ((HV_STATUS)0x1028)
+
+//
+// MessageId: HV_STATUS_UNSUPPORTED_PROCESSOR
+//
+// MessageText:
+//
+// The hypervisor does not support the processors in this system.
+//
+#define HV_STATUS_UNSUPPORTED_PROCESSOR ((HV_STATUS)0x1029)
+
+//
+// MessageId: HV_STATUS_INSUFFICIENT_CROM_SPACE
+//
+// MessageText:
+//
+// Insufficient space existed for copying over the CROM contents.
+//
+#define HV_STATUS_INSUFFICIENT_CROM_SPACE ((HV_STATUS)0x2000)
+
+//
+// MessageId: HV_STATUS_BAD_CROM_FORMAT
+//
+// MessageText:
+//
+// The contents of the CROM failed validation attempts.
+//
+#define HV_STATUS_BAD_CROM_FORMAT        ((HV_STATUS)0x2001)
+
+//
+// MessageId: HV_STATUS_UNSUPPORTED_CROM_FORMAT
+//
+// MessageText:
+//
+// The contents of the CROM contain contents the parser doesn't support.
+//
+#define HV_STATUS_UNSUPPORTED_CROM_FORMAT ((HV_STATUS)0x2002)
+
+//
+// MessageId: HV_STATUS_UNSUPPORTED_CONTROLLER
+//
+// MessageText:
+//
+// The register format of the OHCI controller specified for debugging is not supported.
+//
+#define HV_STATUS_UNSUPPORTED_CONTROLLER ((HV_STATUS)0x2003)
+
+//
+// MessageId: HV_STATUS_CROM_TOO_LARGE
+//
+// MessageText:
+//
+// The CROM contents were to large to copy over.
+//
+#define HV_STATUS_CROM_TOO_LARGE         ((HV_STATUS)0x2004)
+
+//
+// MessageId: HV_STATUS_CONTROLLER_IN_USE
+//
+// MessageText:
+//
+// The OHCI controller specified for debugging cannot be used as it is already in use.
+//
+#define HV_STATUS_CONTROLLER_IN_USE      ((HV_STATUS)0x2005)
+
--- /dev/null
+++ b/drivers/staging/hv/include/HvSynicApi.h
@@ -0,0 +1,490 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+#pragma once
+
+//
+// Define the virtual APIC registers
+//
+#define HV_X64_MSR_EOI                  (0x40000070)
+#define HV_X64_MSR_ICR                  (0x40000071)
+#define HV_X64_MSR_TPR                  (0x40000072)
+#define HV_X64_MSR_APIC_ASSIST_PAGE     (0x40000073)
+
+//
+// Define version of the synthetic interrupt controller.
+//
+
+#define HV_SYNIC_VERSION        (1)
+
+
+//
+// Define synthetic interrupt controller model specific registers.
+//
+
+#define HV_X64_MSR_SCONTROL   (0x40000080)
+#define HV_X64_MSR_SVERSION   (0x40000081)
+#define HV_X64_MSR_SIEFP      (0x40000082)
+#define HV_X64_MSR_SIMP       (0x40000083)
+#define HV_X64_MSR_EOM        (0x40000084)
+#define HV_X64_MSR_SINT0      (0x40000090)
+#define HV_X64_MSR_SINT1      (0x40000091)
+#define HV_X64_MSR_SINT2      (0x40000092)
+#define HV_X64_MSR_SINT3      (0x40000093)
+#define HV_X64_MSR_SINT4      (0x40000094)
+#define HV_X64_MSR_SINT5      (0x40000095)
+#define HV_X64_MSR_SINT6      (0x40000096)
+#define HV_X64_MSR_SINT7      (0x40000097)
+#define HV_X64_MSR_SINT8      (0x40000098)
+#define HV_X64_MSR_SINT9      (0x40000099)
+#define HV_X64_MSR_SINT10     (0x4000009A)
+#define HV_X64_MSR_SINT11     (0x4000009B)
+#define HV_X64_MSR_SINT12     (0x4000009C)
+#define HV_X64_MSR_SINT13     (0x4000009D)
+#define HV_X64_MSR_SINT14     (0x4000009E)
+#define HV_X64_MSR_SINT15     (0x4000009F)
+
+//
+// Define the expected SynIC version.
+//
+#define HV_SYNIC_VERSION_1 (0x1)
+
+//
+// Define synthetic interrupt controller message constants.
+//
+
+#define HV_MESSAGE_SIZE                 (256)
+#define HV_MESSAGE_PAYLOAD_BYTE_COUNT   (240)
+#define HV_MESSAGE_PAYLOAD_QWORD_COUNT  (30)
+#define HV_ANY_VP                       (0xFFFFFFFF)
+
+//
+// Define synthetic interrupt controller flag constants.
+//
+
+#define HV_EVENT_FLAGS_COUNT        (256 * 8)
+#define HV_EVENT_FLAGS_BYTE_COUNT   (256)
+#define HV_EVENT_FLAGS_DWORD_COUNT  (256 / sizeof(UINT32))
+
+//
+// Define hypervisor message types.
+//
+typedef enum _HV_MESSAGE_TYPE
+{
+    HvMessageTypeNone = 0x00000000,
+
+    //
+    // Memory access messages.
+    //
+    HvMessageTypeUnmappedGpa = 0x80000000,
+    HvMessageTypeGpaIntercept = 0x80000001,
+
+    //
+    // Timer notification messages.
+    //
+    HvMessageTimerExpired = 0x80000010,
+
+    //
+    // Error messages.
+    //
+    HvMessageTypeInvalidVpRegisterValue = 0x80000020,
+    HvMessageTypeUnrecoverableException = 0x80000021,
+    HvMessageTypeUnsupportedFeature = 0x80000022,
+
+    //
+    // Trace buffer complete messages.
+    //
+    HvMessageTypeEventLogBufferComplete = 0x80000040,
+
+    //
+    // Platform-specific processor intercept messages.
+    //
+    HvMessageTypeX64IoPortIntercept = 0x80010000,
+    HvMessageTypeX64MsrIntercept = 0x80010001,
+    HvMessageTypeX64CpuidIntercept = 0x80010002,
+    HvMessageTypeX64ExceptionIntercept = 0x80010003,
+    HvMessageTypeX64ApicEoi = 0x80010004,
+    HvMessageTypeX64LegacyFpError = 0x80010005
+
+} HV_MESSAGE_TYPE, *PHV_MESSAGE_TYPE;
+
+//
+// Define the number of synthetic interrupt sources.
+//
+
+#define HV_SYNIC_SINT_COUNT (16)
+#define HV_SYNIC_STIMER_COUNT (4)
+
+//
+// Define the synthetic interrupt source index type.
+//
+
+typedef UINT32 HV_SYNIC_SINT_INDEX, *PHV_SYNIC_SINT_INDEX;
+
+//
+// Define partition identifier type.
+//
+
+typedef UINT64 HV_PARTITION_ID, *PHV_PARTITION_ID;
+
+//
+// Define invalid partition identifier.
+//
+#define HV_PARTITION_ID_INVALID ((HV_PARTITION_ID) 0x0)
+
+//
+// Define connection identifier type.
+//
+
+typedef union _HV_CONNECTION_ID
+{
+    UINT32 AsUINT32;
+
+    struct
+    {
+        UINT32 Id:24;
+        UINT32 Reserved:8;
+    } u;
+
+} HV_CONNECTION_ID, *PHV_CONNECTION_ID;
+
+//
+// Define port identifier type.
+//
+
+typedef union _HV_PORT_ID
+{
+    UINT32 AsUINT32;
+
+    struct
+    {
+        UINT32 Id:24;
+        UINT32 Reserved:8;
+    } u ;
+
+} HV_PORT_ID, *PHV_PORT_ID;
+
+//
+// Define port type.
+//
+
+typedef enum _HV_PORT_TYPE
+{
+    HvPortTypeMessage   = 1,
+    HvPortTypeEvent     = 2,
+    HvPortTypeMonitor   = 3
+} HV_PORT_TYPE, *PHV_PORT_TYPE;
+
+//
+// Define port information structure.
+//
+
+typedef struct _HV_PORT_INFO
+{
+    HV_PORT_TYPE PortType;
+    UINT32 Padding;
+
+    union
+    {
+        struct
+        {
+            HV_SYNIC_SINT_INDEX TargetSint;
+            HV_VP_INDEX TargetVp;
+            UINT64 RsvdZ;
+        } MessagePortInfo;
+
+        struct
+        {
+            HV_SYNIC_SINT_INDEX TargetSint;
+            HV_VP_INDEX TargetVp;
+            UINT16 BaseFlagNumber;
+            UINT16 FlagCount;
+            UINT32 RsvdZ;
+        } EventPortInfo;
+
+        struct
+        {
+            HV_GPA MonitorAddress;
+            UINT64 RsvdZ;
+        } MonitorPortInfo;
+    };
+} HV_PORT_INFO, *PHV_PORT_INFO;
+
+typedef const HV_PORT_INFO *PCHV_PORT_INFO;
+
+typedef struct _HV_CONNECTION_INFO
+{
+    HV_PORT_TYPE PortType;
+    UINT32 Padding;
+
+    union
+    {
+        struct
+        {
+            UINT64 RsvdZ;
+        } MessageConnectionInfo;
+
+        struct
+        {
+            UINT64 RsvdZ;
+        } EventConnectionInfo;
+
+        struct
+        {
+            HV_GPA MonitorAddress;
+        } MonitorConnectionInfo;
+    };
+} HV_CONNECTION_INFO, *PHV_CONNECTION_INFO;
+
+typedef const HV_CONNECTION_INFO *PCHV_CONNECTION_INFO;
+
+//
+// Define synthetic interrupt controller message flags.
+//
+
+typedef union _HV_MESSAGE_FLAGS
+{
+    UINT8 AsUINT8;
+    struct
+    {
+        UINT8 MessagePending:1;
+        UINT8 Reserved:7;
+    };
+} HV_MESSAGE_FLAGS, *PHV_MESSAGE_FLAGS;
+
+
+//
+// Define synthetic interrupt controller message header.
+//
+
+typedef struct _HV_MESSAGE_HEADER
+{
+    HV_MESSAGE_TYPE     MessageType;
+    UINT8               PayloadSize;
+    HV_MESSAGE_FLAGS    MessageFlags;
+    UINT8               Reserved[2];
+    union
+    {
+        HV_PARTITION_ID Sender;
+        HV_PORT_ID      Port;
+    };
+
+} HV_MESSAGE_HEADER, *PHV_MESSAGE_HEADER;
+
+//
+// Define timer message payload structure.
+//
+typedef struct _HV_TIMER_MESSAGE_PAYLOAD
+{
+    UINT32          TimerIndex;
+    UINT32          Reserved;
+    HV_NANO100_TIME ExpirationTime;     // When the timer expired
+    HV_NANO100_TIME DeliveryTime;       // When the message was delivered
+} HV_TIMER_MESSAGE_PAYLOAD, *PHV_TIMER_MESSAGE_PAYLOAD;
+
+//
+// Define synthetic interrupt controller message format.
+//
+
+typedef struct _HV_MESSAGE
+{
+    HV_MESSAGE_HEADER Header;
+    union
+    {
+        UINT64 Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
+    } u ;
+} HV_MESSAGE, *PHV_MESSAGE;
+
+//
+// Define the number of message buffers associated with each port.
+//
+
+#define HV_PORT_MESSAGE_BUFFER_COUNT (16)
+
+//
+// Define the synthetic interrupt message page layout.
+//
+
+typedef struct _HV_MESSAGE_PAGE
+{
+    volatile HV_MESSAGE SintMessage[HV_SYNIC_SINT_COUNT];
+} HV_MESSAGE_PAGE, *PHV_MESSAGE_PAGE;
+
+
+//
+// Define the synthetic interrupt controller event flags format.
+//
+
+typedef union _HV_SYNIC_EVENT_FLAGS
+{
+    UINT8 Flags8[HV_EVENT_FLAGS_BYTE_COUNT];
+    UINT32 Flags32[HV_EVENT_FLAGS_DWORD_COUNT];
+} HV_SYNIC_EVENT_FLAGS, *PHV_SYNIC_EVENT_FLAGS;
+
+
+//
+// Define the synthetic interrupt flags page layout.
+//
+
+typedef struct _HV_SYNIC_EVENT_FLAGS_PAGE
+{
+    volatile HV_SYNIC_EVENT_FLAGS SintEventFlags[HV_SYNIC_SINT_COUNT];
+} HV_SYNIC_EVENT_FLAGS_PAGE, *PHV_SYNIC_EVENT_FLAGS_PAGE;
+
+
+//
+// Define SynIC control register.
+//
+typedef union _HV_SYNIC_SCONTROL
+{
+    UINT64 AsUINT64;
+    struct
+    {
+        UINT64 Enable:1;
+        UINT64 Reserved:63;
+    };
+} HV_SYNIC_SCONTROL, *PHV_SYNIC_SCONTROL;
+
+//
+// Define synthetic interrupt source.
+//
+
+typedef union _HV_SYNIC_SINT
+{
+    UINT64 AsUINT64;
+    struct
+    {
+        UINT64 Vector    :8;
+        UINT64 Reserved1 :8;
+        UINT64 Masked    :1;
+        UINT64 AutoEoi   :1;
+        UINT64 Reserved2 :46;
+    };
+} HV_SYNIC_SINT, *PHV_SYNIC_SINT;
+
+//
+// Define the format of the SIMP register
+//
+
+typedef union _HV_SYNIC_SIMP
+{
+    UINT64 AsUINT64;
+    struct
+    {
+        UINT64 SimpEnabled : 1;
+        UINT64 Preserved   : 11;
+        UINT64 BaseSimpGpa : 52;
+    };
+} HV_SYNIC_SIMP, *PHV_SYNIC_SIMP;
+
+//
+// Define the format of the SIEFP register
+//
+
+typedef union _HV_SYNIC_SIEFP
+{
+    UINT64 AsUINT64;
+    struct
+    {
+        UINT64 SiefpEnabled : 1;
+        UINT64 Preserved   : 11;
+        UINT64 BaseSiefpGpa : 52;
+    };
+} HV_SYNIC_SIEFP, *PHV_SYNIC_SIEFP;
+
+//
+// Definitions for the monitored notification facility
+//
+
+typedef union _HV_MONITOR_TRIGGER_GROUP
+{
+    UINT64 AsUINT64;
+
+    struct
+    {
+        UINT32 Pending;
+        UINT32 Armed;
+    };
+
+} HV_MONITOR_TRIGGER_GROUP, *PHV_MONITOR_TRIGGER_GROUP;
+
+typedef struct _HV_MONITOR_PARAMETER
+{
+    HV_CONNECTION_ID    ConnectionId;
+    UINT16              FlagNumber;
+    UINT16              RsvdZ;
+} HV_MONITOR_PARAMETER, *PHV_MONITOR_PARAMETER;
+
+typedef union _HV_MONITOR_TRIGGER_STATE
+{
+    UINT32 AsUINT32;
+
+    struct
+    {
+        UINT32 GroupEnable : 4;
+        UINT32 RsvdZ       : 28;
+    };
+
+} HV_MONITOR_TRIGGER_STATE, *PHV_MONITOR_TRIGGER_STATE;
+
+//
+// HV_MONITOR_PAGE Layout
+// ------------------------------------------------------
+// | 0   | TriggerState (4 bytes) | Rsvd1 (4 bytes)     |
+// | 8   | TriggerGroup[0]                              |
+// | 10  | TriggerGroup[1]                              |
+// | 18  | TriggerGroup[2]                              |
+// | 20  | TriggerGroup[3]                              |
+// | 28  | Rsvd2[0]                                     |
+// | 30  | Rsvd2[1]                                     |
+// | 38  | Rsvd2[2]                                     |
+// | 40  | NextCheckTime[0][0]    | NextCheckTime[0][1] |
+// | ...                                                |
+// | 240 | Latency[0][0..3]                             |
+// | 340 | Rsvz3[0]                                     |
+// | 440 | Parameter[0][0]                              |
+// | 448 | Parameter[0][1]                              |
+// | ...                                                |
+// | 840 | Rsvd4[0]                                     |
+// ------------------------------------------------------
+
+typedef struct _HV_MONITOR_PAGE
+{
+    HV_MONITOR_TRIGGER_STATE TriggerState;
+    UINT32                   RsvdZ1;
+
+    HV_MONITOR_TRIGGER_GROUP TriggerGroup[4];
+    UINT64                   RsvdZ2[3];
+
+    INT32                    NextCheckTime[4][32];
+
+    UINT16                   Latency[4][32];
+    UINT64                   RsvdZ3[32];
+
+    HV_MONITOR_PARAMETER     Parameter[4][32];
+
+    UINT8                    RsvdZ4[1984];
+
+} HV_MONITOR_PAGE, *PHV_MONITOR_PAGE;
+
+typedef volatile HV_MONITOR_PAGE* PVHV_MONITOR_PAGE;
--- /dev/null
+++ b/drivers/staging/hv/include/HvTypes.h
@@ -0,0 +1,31 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+typedef UINT64 HV_GPA, *PHV_GPA;
+
+#define HV_X64_PAGE_SIZE (4096)
+#define HV_PAGE_SIZE HV_X64_PAGE_SIZE
+
--- /dev/null
+++ b/drivers/staging/hv/include/HvVpApi.h
@@ -0,0 +1,51 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+//
+// Virtual Processor Indices
+//
+typedef UINT32 HV_VP_INDEX, *PHV_VP_INDEX;
+
+//
+// The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
+// is set by CPUID(HvCpuIdFunctionVersionAndFeatures).
+// ==========================================================================
+//
+
+typedef enum _HV_CPUID_FUNCTION
+{
+    HvCpuIdFunctionVersionAndFeatures           = 0x00000001,
+    HvCpuIdFunctionHvVendorAndMaxFunction       = 0x40000000,
+    HvCpuIdFunctionHvInterface                  = 0x40000001,
+
+    //
+    // The remaining functions depend on the value of HvCpuIdFunctionInterface
+    //
+    HvCpuIdFunctionMsHvVersion                  = 0x40000002,
+    HvCpuIdFunctionMsHvFeatures                 = 0x40000003,
+    HvCpuIdFunctionMsHvEnlightenmentInformation = 0x40000004,
+    HvCpuIdFunctionMsHvImplementationLimits     = 0x40000005
+
+} HV_CPUID_FUNCTION, *PHV_CPUID_FUNCTION;
--- /dev/null
+++ b/drivers/staging/hv/include/List.h
@@ -0,0 +1,269 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _LIST_H_
+#define _LIST_H_
+
+#include "osd.h"
+/*
+ *
+ *  Doubly-linked list manipulation routines.  Implemented as macros
+ *  but logically these are procedures.
+ *
+ */
+
+typedef DLIST_ENTRY LIST_ENTRY;
+typedef DLIST_ENTRY *PLIST_ENTRY;
+
+//typedef struct LIST_ENTRY {
+//   struct LIST_ENTRY * volatile Flink;
+//   struct LIST_ENTRY * volatile Blink;
+//} LIST_ENTRY, *PLIST_ENTRY;
+
+
+
+/*
+ *  VOID
+ *  InitializeListHead(
+ *      PLIST_ENTRY ListHead
+ *      );
+ */
+#define INITIALIZE_LIST_HEAD	InitializeListHead
+
+#define InitializeListHead(ListHead) (\
+    (ListHead)->Flink = (ListHead)->Blink = (ListHead))
+
+
+/*
+ *  BOOLEAN
+ *  IsListEmpty(
+ *      PLIST_ENTRY ListHead
+ *      );
+ */
+#define IS_LIST_EMPTY			IsListEmpty
+
+#define IsListEmpty(ListHead) \
+    ((ListHead)->Flink == (ListHead))
+
+
+/*
+ *  PLIST_ENTRY
+ *  NextListEntry(
+ *      PLIST_ENTRY Entry
+ *      );
+ */
+#define	NEXT_LIST_ENTRY			NextListEntry
+
+#define NextListEntry(Entry) \
+    (Entry)->Flink
+
+
+/*
+ *  PLIST_ENTRY
+ *  PrevListEntry(
+ *      PLIST_ENTRY Entry
+ *      );
+ */
+#define	PREV_LIST_ENTRY			PrevListEntry
+
+#define PrevListEntry(Entry) \
+    (Entry)->Blink
+
+
+/*
+ *  PLIST_ENTRY
+ *  TopListEntry(
+ *      PLIST_ENTRY ListHead
+ *      );
+ */
+#define	TOP_LIST_ENTRY			TopListEntry
+
+#define TopListEntry(ListHead) \
+    (ListHead)->Flink
+
+
+
+/*
+ *  PLIST_ENTRY
+ *  RemoveHeadList(
+ *      PLIST_ENTRY ListHead
+ *      );
+ */
+
+#define	REMOVE_HEAD_LIST		RemoveHeadList
+
+#define RemoveHeadList(ListHead) \
+    (ListHead)->Flink;\
+    {RemoveEntryList((ListHead)->Flink)}
+
+
+/*
+ *  PLIST_ENTRY
+ *  RemoveTailList(
+ *      PLIST_ENTRY ListHead
+ *      );
+ */
+#define	REMOVE_TAIL_LIST		RemoveTailList
+
+#define RemoveTailList(ListHead) \
+    (ListHead)->Blink;\
+    {RemoveEntryList((ListHead)->Blink)}
+
+
+/*
+ *  VOID
+ *  RemoveEntryList(
+ *      PLIST_ENTRY Entry
+ *      );
+ */
+#define	REMOVE_ENTRY_LIST		RemoveEntryList
+
+#define RemoveEntryList(Entry) {\
+    PLIST_ENTRY _EX_Flink = (Entry)->Flink;\
+    PLIST_ENTRY _EX_Blink = (Entry)->Blink;\
+    _EX_Blink->Flink = _EX_Flink;\
+    _EX_Flink->Blink = _EX_Blink;\
+	}
+
+
+/*
+ *  VOID
+ *  AttachList(
+ *      PLIST_ENTRY ListHead,
+ *      PLIST_ENTRY ListEntry
+ *      );
+ */
+#define	ATTACH_LIST		AttachList
+
+#define AttachList(ListHead,ListEntry) {\
+    PLIST_ENTRY _EX_ListHead = (ListHead);\
+    PLIST_ENTRY _EX_Blink = (ListHead)->Blink;\
+    (ListEntry)->Blink->Flink = _EX_ListHead;\
+    _EX_Blink->Flink = (ListEntry);\
+    _EX_ListHead->Blink = (ListEntry)->Blink;\
+    (ListEntry)->Blink = _EX_Blink;\
+    }
+
+
+
+/*
+ *  VOID
+ *  InsertTailList(
+ *      PLIST_ENTRY ListHead,
+ *      PLIST_ENTRY Entry
+ *      );
+ */
+
+#define	INSERT_TAIL_LIST		InsertTailList
+
+#define InsertTailList(ListHead,Entry) {\
+    PLIST_ENTRY _EX_ListHead = (ListHead);\
+    PLIST_ENTRY _EX_Blink = (ListHead)->Blink;\
+    (Entry)->Flink = _EX_ListHead;\
+    (Entry)->Blink = _EX_Blink;\
+    _EX_Blink->Flink = (Entry);\
+    _EX_ListHead->Blink = (Entry);\
+    }
+
+
+/*
+ *  VOID
+ *  InsertHeadList(
+ *      PLIST_ENTRY ListHead,
+ *      PLIST_ENTRY Entry
+ *      );
+ */
+#define	INSERT_HEAD_LIST		InsertHeadList
+
+#define InsertHeadList(ListHead,Entry) {\
+    PLIST_ENTRY _EX_ListHead = (ListHead);\
+    PLIST_ENTRY _EX_Flink = (ListHead)->Flink;\
+    (Entry)->Flink = _EX_Flink;\
+    (Entry)->Blink = _EX_ListHead;\
+    _EX_Flink->Blink = (Entry);\
+    _EX_ListHead->Flink = (Entry);\
+    }
+
+
+/*
+ *  VOID
+ *  IterateListEntries(
+ *      PLIST_ENTRY anchor,
+ *      PLIST_ENTRY index,
+ *		PLIST_ENTRY listp
+ *      );
+ */
+
+#define	ITERATE_LIST_ENTRIES	IterateListEntries
+
+#define IterateListEntries(anchor, index, listp) \
+	(anchor) = (LIST_ENTRY *)(listp); \
+	for((index) = (anchor)->Flink; (index) != (anchor); (index) = (index)->Flink)
+
+
+
+/*
+ *  PSINGLE_LIST_ENTRY
+ *  PopEntryList(
+ *      PSINGLE_LIST_ENTRY ListHead
+ *      );
+ */
+
+#define	POP_ENTRY_LIST		PopEntryList
+
+#define PopEntryList(ListHead) \
+    (ListHead)->Next;\
+    {\
+        PSINGLE_LIST_ENTRY FirstEntry;\
+        FirstEntry = (ListHead)->Next;\
+        if (FirstEntry != NULL) {     \
+            (ListHead)->Next = FirstEntry->Next;\
+        }                             \
+    }
+
+
+
+/*
+ *  VOID
+ *  PushEntryList(
+ *      PSINGLE_LIST_ENTRY ListHead,
+ *		PSINGLE_LIST_ENTRY Entry
+ *      );
+ */
+
+#define	PUSH_ENTRY_LIST			PushEntryList
+
+#define PushEntryList(ListHead,Entry) \
+    (Entry)->Next = (ListHead)->Next; \
+    (ListHead)->Next = (Entry)
+
+#ifndef CONTAINING_RECORD
+#define CONTAINING_RECORD(address, type, field) ((type *)( \
+                                                  (PCHAR)(address) - \
+                                                  (PCHAR)(&((type *)0)->field)))
+#endif /* CONTAINING_RECORD */
+
+#endif /* _LIST_H_ */
+
+/* EOF */
--- /dev/null
+++ b/drivers/staging/hv/include/nvspprotocol.h
@@ -0,0 +1,306 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+#include <VmbusChannelInterface.h>
+
+#define NVSP_INVALID_PROTOCOL_VERSION           ((UINT32)0xFFFFFFFF)
+
+#define NVSP_PROTOCOL_VERSION_1                 2
+#define NVSP_MIN_PROTOCOL_VERSION               NVSP_PROTOCOL_VERSION_1
+#define NVSP_MAX_PROTOCOL_VERSION               NVSP_PROTOCOL_VERSION_1
+
+typedef enum _NVSP_MESSAGE_TYPE
+{
+    NvspMessageTypeNone = 0,
+
+    //
+    // Init Messages
+    //
+    NvspMessageTypeInit                         = 1,
+    NvspMessageTypeInitComplete                 = 2,
+
+    NvspVersionMessageStart                     = 100,
+
+    //
+    // Version 1 Messages
+    //
+    NvspMessage1TypeSendNdisVersion             = NvspVersionMessageStart,
+
+    NvspMessage1TypeSendReceiveBuffer,
+    NvspMessage1TypeSendReceiveBufferComplete,
+    NvspMessage1TypeRevokeReceiveBuffer,
+
+    NvspMessage1TypeSendSendBuffer,
+    NvspMessage1TypeSendSendBufferComplete,
+    NvspMessage1TypeRevokeSendBuffer,
+
+    NvspMessage1TypeSendRNDISPacket,
+    NvspMessage1TypeSendRNDISPacketComplete,
+
+    //
+    // This should be set to the number of messages for the version
+    // with the maximum number of messages.
+    //
+    NvspNumMessagePerVersion                    = 9,
+
+} NVSP_MESSAGE_TYPE, *PNVSP_MESSAGE_TYPE;
+
+typedef enum _NVSP_STATUS
+{
+    NvspStatusNone = 0,
+    NvspStatusSuccess,
+    NvspStatusFailure,
+    NvspStatusProtocolVersionRangeTooNew,
+    NvspStatusProtocolVersionRangeTooOld,
+    NvspStatusInvalidRndisPacket,
+    NvspStatusBusy,
+    NvspStatusMax,
+} NVSP_STATUS, *PNVSP_STATUS;
+
+#pragma pack(push, 1)
+
+typedef struct _NVSP_MESSAGE_HEADER
+{
+    UINT32                                  MessageType;
+} NVSP_MESSAGE_HEADER, *PNVSP_MESSAGE_HEADER;
+
+//
+// Init Messages
+//
+
+//
+// This message is used by the VSC to initialize the channel
+// after the channels has been opened. This message should
+// never include anything other then versioning (i.e. this
+// message will be the same for ever).
+//
+typedef struct _NVSP_MESSAGE_INIT
+{
+    UINT32                                  MinProtocolVersion;
+    UINT32                                  MaxProtocolVersion;
+} NVSP_MESSAGE_INIT, *PNVSP_MESSAGE_INIT;
+
+//
+// This message is used by the VSP to complete the initialization
+// of the channel. This message should never include anything other
+// then versioning (i.e. this message will be the same for ever).
+//
+typedef struct _NVSP_MESSAGE_INIT_COMPLETE
+{
+    UINT32                                  NegotiatedProtocolVersion;
+    UINT32                                  MaximumMdlChainLength;
+    UINT32                                  Status;
+} NVSP_MESSAGE_INIT_COMPLETE, *PNVSP_MESSAGE_INIT_COMPLETE;
+
+typedef union _NVSP_MESSAGE_INIT_UBER
+{
+    NVSP_MESSAGE_INIT                       Init;
+    NVSP_MESSAGE_INIT_COMPLETE              InitComplete;
+} NVSP_MESSAGE_INIT_UBER;
+
+//
+// Version 1 Messages
+//
+
+//
+// This message is used by the VSC to send the NDIS version
+// to the VSP. The VSP can use this information when handling
+// OIDs sent by the VSC.
+//
+typedef struct _NVSP_1_MESSAGE_SEND_NDIS_VERSION
+{
+    UINT32                                  NdisMajorVersion;
+    UINT32                                  NdisMinorVersion;
+} NVSP_1_MESSAGE_SEND_NDIS_VERSION, *PNVSP_1_MESSAGE_SEND_NDIS_VERSION;
+
+//
+// This message is used by the VSC to send a receive buffer
+// to the VSP. The VSP can then use the receive buffer to
+// send data to the VSC.
+//
+typedef struct _NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER
+{
+    GPADL_HANDLE                            GpadlHandle;
+    UINT16                                  Id;
+} NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER, *PNVSP_1_MESSAGE_SEND_RECEIVE_BUFFER;
+
+typedef struct _NVSP_1_RECEIVE_BUFFER_SECTION
+{
+    UINT32                                  Offset;
+    UINT32                                  SubAllocationSize;
+    UINT32                                  NumSubAllocations;
+    UINT32                                  EndOffset;
+} NVSP_1_RECEIVE_BUFFER_SECTION, *PNVSP_1_RECEIVE_BUFFER_SECTION;
+
+//
+// This message is used by the VSP to acknowledge a receive
+// buffer send by the VSC. This message must be sent by the
+// VSP before the VSP uses the receive buffer.
+//
+typedef struct _NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER_COMPLETE
+{
+    UINT32                                  Status;
+    UINT32                                  NumSections;
+
+    //
+    // The receive buffer is split into two parts, a large
+    // suballocation section and a small suballocation
+    // section. These sections are then suballocated by a
+    // certain size.
+    //
+    // For example, the following break up of the receive
+    // buffer has 6 large suballocations and 10 small
+    // suballocations.
+    //
+    // |            Large Section          |  |   Small Section   |
+    // ------------------------------------------------------------
+    // |     |     |     |     |     |     |  | | | | | | | | | | |
+    // |                                      |
+    // LargeOffset                            SmallOffset
+    //
+    NVSP_1_RECEIVE_BUFFER_SECTION           Sections[1];
+
+} NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER_COMPLETE, *PNVSP_1_MESSAGE_SEND_RECEIVE_BUFFER_COMPLETE;
+
+//
+// This message is sent by the VSC to revoke the receive buffer.
+// After the VSP completes this transaction, the vsp should never
+// use the receive buffer again.
+//
+typedef struct _NVSP_1_MESSAGE_REVOKE_RECEIVE_BUFFER
+{
+    UINT16                                  Id;
+} NVSP_1_MESSAGE_REVOKE_RECEIVE_BUFFER, *PNVSP_1_MESSAGE_REVOKE_RECEIVE_BUFFER;
+
+//
+// This message is used by the VSC to send a send buffer
+// to the VSP. The VSC can then use the send buffer to
+// send data to the VSP.
+//
+typedef struct _NVSP_1_MESSAGE_SEND_SEND_BUFFER
+{
+    GPADL_HANDLE                            GpadlHandle;
+    UINT16                                  Id;
+} NVSP_1_MESSAGE_SEND_SEND_BUFFER, *PNVSP_1_MESSAGE_SEND_SEND_BUFFER;
+
+//
+// This message is used by the VSP to acknowledge a send
+// buffer sent by the VSC. This message must be sent by the
+// VSP before the VSP uses the sent buffer.
+//
+typedef struct _NVSP_1_MESSAGE_SEND_SEND_BUFFER_COMPLETE
+{
+    UINT32                                  Status;
+
+    //
+    // The VSC gets to choose the size of the send buffer and
+    // the VSP gets to choose the sections size of the buffer.
+    // This was done to enable dynamic reconfigurations when
+    // the cost of GPA-direct buffers decreases.
+    //
+    UINT32                                  SectionSize;
+} NVSP_1_MESSAGE_SEND_SEND_BUFFER_COMPLETE, *PNVSP_1_MESSAGE_SEND_SEND_BUFFER_COMPLETE;
+
+//
+// This message is sent by the VSC to revoke the send buffer.
+// After the VSP completes this transaction, the vsp should never
+// use the send buffer again.
+//
+typedef struct _NVSP_1_MESSAGE_REVOKE_SEND_BUFFER
+{
+    UINT16                                  Id;
+} NVSP_1_MESSAGE_REVOKE_SEND_BUFFER, *PNVSP_1_MESSAGE_REVOKE_SEND_BUFFER;
+
+//
+// This message is used by both the VSP and the VSC to send
+// a RNDIS message to the opposite channel endpoint.
+//
+typedef struct _NVSP_1_MESSAGE_SEND_RNDIS_PACKET
+{
+    //
+    // This field is specified by RNIDS. They assume there's
+    // two different channels of communication. However,
+    // the Network VSP only has one. Therefore, the channel
+    // travels with the RNDIS packet.
+    //
+    UINT32                                  ChannelType;
+
+    //
+    // This field is used to send part or all of the data
+    // through a send buffer. This values specifies an
+    // index into the send buffer. If the index is
+    // 0xFFFFFFFF, then the send buffer is not being used
+    // and all of the data was sent through other VMBus
+    // mechanisms.
+    //
+    UINT32                                  SendBufferSectionIndex;
+    UINT32                                  SendBufferSectionSize;
+} NVSP_1_MESSAGE_SEND_RNDIS_PACKET, *PNVSP_1_MESSAGE_SEND_RNDIS_PACKET;
+
+//
+// This message is used by both the VSP and the VSC to complete
+// a RNDIS message to the opposite channel endpoint. At this
+// point, the initiator of this message cannot use any resources
+// associated with the original RNDIS packet.
+//
+typedef struct _NVSP_1_MESSAGE_SEND_RNDIS_PACKET_COMPLETE
+{
+    UINT32                                  Status;
+} NVSP_1_MESSAGE_SEND_RNDIS_PACKET_COMPLETE, *PNVSP_1_MESSAGE_SEND_RNDIS_PACKET_COMPLETE;
+
+typedef union _NVSP_MESSAGE_1_UBER
+{
+    NVSP_1_MESSAGE_SEND_NDIS_VERSION            SendNdisVersion;
+
+    NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER          SendReceiveBuffer;
+    NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER_COMPLETE SendReceiveBufferComplete;
+    NVSP_1_MESSAGE_REVOKE_RECEIVE_BUFFER        RevokeReceiveBuffer;
+
+    NVSP_1_MESSAGE_SEND_SEND_BUFFER             SendSendBuffer;
+    NVSP_1_MESSAGE_SEND_SEND_BUFFER_COMPLETE    SendSendBufferComplete;
+    NVSP_1_MESSAGE_REVOKE_SEND_BUFFER           RevokeSendBuffer;
+
+    NVSP_1_MESSAGE_SEND_RNDIS_PACKET            SendRNDISPacket;
+    NVSP_1_MESSAGE_SEND_RNDIS_PACKET_COMPLETE   SendRNDISPacketComplete;
+} NVSP_1_MESSAGE_UBER;
+
+typedef union _NVSP_ALL_MESSAGES
+{
+    NVSP_MESSAGE_INIT_UBER                  InitMessages;
+    NVSP_1_MESSAGE_UBER                     Version1Messages;
+
+} NVSP_ALL_MESSAGES;
+
+//
+// ALL Messages
+//
+typedef struct _NVSP_MESSAGE
+{
+    NVSP_MESSAGE_HEADER                     Header;
+    NVSP_ALL_MESSAGES                       Messages;
+} NVSP_MESSAGE, *PNVSP_MESSAGE;
+
+#pragma pack(pop)
--- /dev/null
+++ b/drivers/staging/hv/include/rndis.h
@@ -0,0 +1,836 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _RNDIS_H_
+#define _RNDIS_H_
+
+//
+//  Basic types
+//
+typedef UINT32                                  RNDIS_REQUEST_ID;
+typedef UINT32                                  RNDIS_HANDLE;
+typedef UINT32                                  RNDIS_STATUS;
+typedef UINT32                                  RNDIS_REQUEST_TYPE;
+typedef UINT32                                  RNDIS_OID;
+typedef UINT32                                  RNDIS_CLASS_ID;
+typedef UINT32                                  RNDIS_MEDIUM;
+typedef UINT32                                  *PRNDIS_REQUEST_ID;
+typedef UINT32                                  *PRNDIS_HANDLE;
+typedef UINT32                                  *PRNDIS_STATUS;
+typedef UINT32                                  *PRNDIS_REQUEST_TYPE;
+typedef UINT32                                  *PRNDIS_OID;
+typedef UINT32                                  *PRNDIS_CLASS_ID;
+typedef UINT32                                  *PRNDIS_MEDIUM;
+typedef UINT32                                  RNDIS_AF;
+
+//
+//  Status codes
+//
+
+#ifndef STATUS_SUCCESS
+#define STATUS_SUCCESS                          (0x00000000L)
+#endif
+
+#ifndef STATUS_UNSUCCESSFUL
+#define STATUS_UNSUCCESSFUL                     (0xC0000001L)
+#endif
+
+#ifndef STATUS_PENDING
+#define STATUS_PENDING                          (0x00000103L)
+#endif
+
+#ifndef STATUS_INSUFFICIENT_RESOURCES
+#define STATUS_INSUFFICIENT_RESOURCES           (0xC000009AL)
+#endif
+
+#ifndef STATUS_BUFFER_OVERFLOW
+#define STATUS_BUFFER_OVERFLOW                  (0x80000005L)
+#endif
+
+#ifndef STATUS_NOT_SUPPORTED
+#define STATUS_NOT_SUPPORTED                    (0xC00000BBL)
+#endif
+
+#define RNDIS_STATUS_SUCCESS                    ((RNDIS_STATUS)STATUS_SUCCESS)
+#define RNDIS_STATUS_PENDING                    ((RNDIS_STATUS)STATUS_PENDING)
+#define RNDIS_STATUS_NOT_RECOGNIZED             ((RNDIS_STATUS)0x00010001L)
+#define RNDIS_STATUS_NOT_COPIED                 ((RNDIS_STATUS)0x00010002L)
+#define RNDIS_STATUS_NOT_ACCEPTED               ((RNDIS_STATUS)0x00010003L)
+#define RNDIS_STATUS_CALL_ACTIVE                ((RNDIS_STATUS)0x00010007L)
+
+#define RNDIS_STATUS_ONLINE                     ((RNDIS_STATUS)0x40010003L)
+#define RNDIS_STATUS_RESET_START                ((RNDIS_STATUS)0x40010004L)
+#define RNDIS_STATUS_RESET_END                  ((RNDIS_STATUS)0x40010005L)
+#define RNDIS_STATUS_RING_STATUS                ((RNDIS_STATUS)0x40010006L)
+#define RNDIS_STATUS_CLOSED                     ((RNDIS_STATUS)0x40010007L)
+#define RNDIS_STATUS_WAN_LINE_UP                ((RNDIS_STATUS)0x40010008L)
+#define RNDIS_STATUS_WAN_LINE_DOWN              ((RNDIS_STATUS)0x40010009L)
+#define RNDIS_STATUS_WAN_FRAGMENT               ((RNDIS_STATUS)0x4001000AL)
+#define RNDIS_STATUS_MEDIA_CONNECT              ((RNDIS_STATUS)0x4001000BL)
+#define RNDIS_STATUS_MEDIA_DISCONNECT           ((RNDIS_STATUS)0x4001000CL)
+#define RNDIS_STATUS_HARDWARE_LINE_UP           ((RNDIS_STATUS)0x4001000DL)
+#define RNDIS_STATUS_HARDWARE_LINE_DOWN         ((RNDIS_STATUS)0x4001000EL)
+#define RNDIS_STATUS_INTERFACE_UP               ((RNDIS_STATUS)0x4001000FL)
+#define RNDIS_STATUS_INTERFACE_DOWN             ((RNDIS_STATUS)0x40010010L)
+#define RNDIS_STATUS_MEDIA_BUSY                 ((RNDIS_STATUS)0x40010011L)
+#define RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION  ((RNDIS_STATUS)0x40010012L)
+#define RNDIS_STATUS_WW_INDICATION              RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION
+#define RNDIS_STATUS_LINK_SPEED_CHANGE          ((RNDIS_STATUS)0x40010013L)
+
+#define RNDIS_STATUS_NOT_RESETTABLE             ((RNDIS_STATUS)0x80010001L)
+#define RNDIS_STATUS_SOFT_ERRORS                ((RNDIS_STATUS)0x80010003L)
+#define RNDIS_STATUS_HARD_ERRORS                ((RNDIS_STATUS)0x80010004L)
+#define RNDIS_STATUS_BUFFER_OVERFLOW            ((RNDIS_STATUS)STATUS_BUFFER_OVERFLOW)
+
+#define RNDIS_STATUS_FAILURE                    ((RNDIS_STATUS)STATUS_UNSUCCESSFUL)
+#define RNDIS_STATUS_RESOURCES                  ((RNDIS_STATUS)STATUS_INSUFFICIENT_RESOURCES)
+#define RNDIS_STATUS_CLOSING                    ((RNDIS_STATUS)0xC0010002L)
+#define RNDIS_STATUS_BAD_VERSION                ((RNDIS_STATUS)0xC0010004L)
+#define RNDIS_STATUS_BAD_CHARACTERISTICS        ((RNDIS_STATUS)0xC0010005L)
+#define RNDIS_STATUS_ADAPTER_NOT_FOUND          ((RNDIS_STATUS)0xC0010006L)
+#define RNDIS_STATUS_OPEN_FAILED                ((RNDIS_STATUS)0xC0010007L)
+#define RNDIS_STATUS_DEVICE_FAILED              ((RNDIS_STATUS)0xC0010008L)
+#define RNDIS_STATUS_MULTICAST_FULL             ((RNDIS_STATUS)0xC0010009L)
+#define RNDIS_STATUS_MULTICAST_EXISTS           ((RNDIS_STATUS)0xC001000AL)
+#define RNDIS_STATUS_MULTICAST_NOT_FOUND        ((RNDIS_STATUS)0xC001000BL)
+#define RNDIS_STATUS_REQUEST_ABORTED            ((RNDIS_STATUS)0xC001000CL)
+#define RNDIS_STATUS_RESET_IN_PROGRESS          ((RNDIS_STATUS)0xC001000DL)
+#define RNDIS_STATUS_CLOSING_INDICATING         ((RNDIS_STATUS)0xC001000EL)
+#define RNDIS_STATUS_NOT_SUPPORTED              ((RNDIS_STATUS)STATUS_NOT_SUPPORTED)
+#define RNDIS_STATUS_INVALID_PACKET             ((RNDIS_STATUS)0xC001000FL)
+#define RNDIS_STATUS_OPEN_LIST_FULL             ((RNDIS_STATUS)0xC0010010L)
+#define RNDIS_STATUS_ADAPTER_NOT_READY          ((RNDIS_STATUS)0xC0010011L)
+#define RNDIS_STATUS_ADAPTER_NOT_OPEN           ((RNDIS_STATUS)0xC0010012L)
+#define RNDIS_STATUS_NOT_INDICATING             ((RNDIS_STATUS)0xC0010013L)
+#define RNDIS_STATUS_INVALID_LENGTH             ((RNDIS_STATUS)0xC0010014L)
+#define RNDIS_STATUS_INVALID_DATA               ((RNDIS_STATUS)0xC0010015L)
+#define RNDIS_STATUS_BUFFER_TOO_SHORT           ((RNDIS_STATUS)0xC0010016L)
+#define RNDIS_STATUS_INVALID_OID                ((RNDIS_STATUS)0xC0010017L)
+#define RNDIS_STATUS_ADAPTER_REMOVED            ((RNDIS_STATUS)0xC0010018L)
+#define RNDIS_STATUS_UNSUPPORTED_MEDIA          ((RNDIS_STATUS)0xC0010019L)
+#define RNDIS_STATUS_GROUP_ADDRESS_IN_USE       ((RNDIS_STATUS)0xC001001AL)
+#define RNDIS_STATUS_FILE_NOT_FOUND             ((RNDIS_STATUS)0xC001001BL)
+#define RNDIS_STATUS_ERROR_READING_FILE         ((RNDIS_STATUS)0xC001001CL)
+#define RNDIS_STATUS_ALREADY_MAPPED             ((RNDIS_STATUS)0xC001001DL)
+#define RNDIS_STATUS_RESOURCE_CONFLICT          ((RNDIS_STATUS)0xC001001EL)
+#define RNDIS_STATUS_NO_CABLE                   ((RNDIS_STATUS)0xC001001FL)
+
+#define RNDIS_STATUS_INVALID_SAP                ((RNDIS_STATUS)0xC0010020L)
+#define RNDIS_STATUS_SAP_IN_USE                 ((RNDIS_STATUS)0xC0010021L)
+#define RNDIS_STATUS_INVALID_ADDRESS            ((RNDIS_STATUS)0xC0010022L)
+#define RNDIS_STATUS_VC_NOT_ACTIVATED           ((RNDIS_STATUS)0xC0010023L)
+#define RNDIS_STATUS_DEST_OUT_OF_ORDER          ((RNDIS_STATUS)0xC0010024L)
+#define RNDIS_STATUS_VC_NOT_AVAILABLE           ((RNDIS_STATUS)0xC0010025L)
+#define RNDIS_STATUS_CELLRATE_NOT_AVAILABLE     ((RNDIS_STATUS)0xC0010026L)
+#define RNDIS_STATUS_INCOMPATABLE_QOS           ((RNDIS_STATUS)0xC0010027L)
+#define RNDIS_STATUS_AAL_PARAMS_UNSUPPORTED     ((RNDIS_STATUS)0xC0010028L)
+#define RNDIS_STATUS_NO_ROUTE_TO_DESTINATION    ((RNDIS_STATUS)0xC0010029L)
+
+#define RNDIS_STATUS_TOKEN_RING_OPEN_ERROR      ((RNDIS_STATUS)0xC0011000L)
+
+
+//
+// Object Identifiers used by NdisRequest Query/Set Information
+//
+
+//
+// General Objects
+//
+
+#define RNDIS_OID_GEN_SUPPORTED_LIST                    0x00010101
+#define RNDIS_OID_GEN_HARDWARE_STATUS                   0x00010102
+#define RNDIS_OID_GEN_MEDIA_SUPPORTED                   0x00010103
+#define RNDIS_OID_GEN_MEDIA_IN_USE                      0x00010104
+#define RNDIS_OID_GEN_MAXIMUM_LOOKAHEAD                 0x00010105
+#define RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE                0x00010106
+#define RNDIS_OID_GEN_LINK_SPEED                        0x00010107
+#define RNDIS_OID_GEN_TRANSMIT_BUFFER_SPACE             0x00010108
+#define RNDIS_OID_GEN_RECEIVE_BUFFER_SPACE              0x00010109
+#define RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE               0x0001010A
+#define RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE                0x0001010B
+#define RNDIS_OID_GEN_VENDOR_ID                         0x0001010C
+#define RNDIS_OID_GEN_VENDOR_DESCRIPTION                0x0001010D
+#define RNDIS_OID_GEN_CURRENT_PACKET_FILTER             0x0001010E
+#define RNDIS_OID_GEN_CURRENT_LOOKAHEAD                 0x0001010F
+#define RNDIS_OID_GEN_DRIVER_VERSION                    0x00010110
+#define RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE                0x00010111
+#define RNDIS_OID_GEN_PROTOCOL_OPTIONS                  0x00010112
+#define RNDIS_OID_GEN_MAC_OPTIONS                       0x00010113
+#define RNDIS_OID_GEN_MEDIA_CONNECT_STATUS              0x00010114
+#define RNDIS_OID_GEN_MAXIMUM_SEND_PACKETS              0x00010115
+#define RNDIS_OID_GEN_VENDOR_DRIVER_VERSION             0x00010116
+#define RNDIS_OID_GEN_NETWORK_LAYER_ADDRESSES           0x00010118
+#define RNDIS_OID_GEN_TRANSPORT_HEADER_OFFSET           0x00010119
+#define RNDIS_OID_GEN_MACHINE_NAME                      0x0001021A
+#define RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER            0x0001021B
+
+#define RNDIS_OID_GEN_XMIT_OK                           0x00020101
+#define RNDIS_OID_GEN_RCV_OK                            0x00020102
+#define RNDIS_OID_GEN_XMIT_ERROR                        0x00020103
+#define RNDIS_OID_GEN_RCV_ERROR                         0x00020104
+#define RNDIS_OID_GEN_RCV_NO_BUFFER                     0x00020105
+
+#define RNDIS_OID_GEN_DIRECTED_BYTES_XMIT               0x00020201
+#define RNDIS_OID_GEN_DIRECTED_FRAMES_XMIT              0x00020202
+#define RNDIS_OID_GEN_MULTICAST_BYTES_XMIT              0x00020203
+#define RNDIS_OID_GEN_MULTICAST_FRAMES_XMIT             0x00020204
+#define RNDIS_OID_GEN_BROADCAST_BYTES_XMIT              0x00020205
+#define RNDIS_OID_GEN_BROADCAST_FRAMES_XMIT             0x00020206
+#define RNDIS_OID_GEN_DIRECTED_BYTES_RCV                0x00020207
+#define RNDIS_OID_GEN_DIRECTED_FRAMES_RCV               0x00020208
+#define RNDIS_OID_GEN_MULTICAST_BYTES_RCV               0x00020209
+#define RNDIS_OID_GEN_MULTICAST_FRAMES_RCV              0x0002020A
+#define RNDIS_OID_GEN_BROADCAST_BYTES_RCV               0x0002020B
+#define RNDIS_OID_GEN_BROADCAST_FRAMES_RCV              0x0002020C
+
+#define RNDIS_OID_GEN_RCV_CRC_ERROR                     0x0002020D
+#define RNDIS_OID_GEN_TRANSMIT_QUEUE_LENGTH             0x0002020E
+
+#define RNDIS_OID_GEN_GET_TIME_CAPS                     0x0002020F
+#define RNDIS_OID_GEN_GET_NETCARD_TIME                  0x00020210
+
+//
+// These are connection-oriented general OIDs.
+// These replace the above OIDs for connection-oriented media.
+//
+#define RNDIS_OID_GEN_CO_SUPPORTED_LIST                 0x00010101
+#define RNDIS_OID_GEN_CO_HARDWARE_STATUS                0x00010102
+#define RNDIS_OID_GEN_CO_MEDIA_SUPPORTED                0x00010103
+#define RNDIS_OID_GEN_CO_MEDIA_IN_USE                   0x00010104
+#define RNDIS_OID_GEN_CO_LINK_SPEED                     0x00010105
+#define RNDIS_OID_GEN_CO_VENDOR_ID                      0x00010106
+#define RNDIS_OID_GEN_CO_VENDOR_DESCRIPTION             0x00010107
+#define RNDIS_OID_GEN_CO_DRIVER_VERSION                 0x00010108
+#define RNDIS_OID_GEN_CO_PROTOCOL_OPTIONS               0x00010109
+#define RNDIS_OID_GEN_CO_MAC_OPTIONS                    0x0001010A
+#define RNDIS_OID_GEN_CO_MEDIA_CONNECT_STATUS           0x0001010B
+#define RNDIS_OID_GEN_CO_VENDOR_DRIVER_VERSION          0x0001010C
+#define RNDIS_OID_GEN_CO_MINIMUM_LINK_SPEED             0x0001010D
+
+#define RNDIS_OID_GEN_CO_GET_TIME_CAPS                  0x00010201
+#define RNDIS_OID_GEN_CO_GET_NETCARD_TIME               0x00010202
+
+//
+// These are connection-oriented statistics OIDs.
+//
+#define RNDIS_OID_GEN_CO_XMIT_PDUS_OK                   0x00020101
+#define RNDIS_OID_GEN_CO_RCV_PDUS_OK                    0x00020102
+#define RNDIS_OID_GEN_CO_XMIT_PDUS_ERROR                0x00020103
+#define RNDIS_OID_GEN_CO_RCV_PDUS_ERROR                 0x00020104
+#define RNDIS_OID_GEN_CO_RCV_PDUS_NO_BUFFER             0x00020105
+
+
+#define RNDIS_OID_GEN_CO_RCV_CRC_ERROR                  0x00020201
+#define RNDIS_OID_GEN_CO_TRANSMIT_QUEUE_LENGTH          0x00020202
+#define RNDIS_OID_GEN_CO_BYTES_XMIT                     0x00020203
+#define RNDIS_OID_GEN_CO_BYTES_RCV                      0x00020204
+#define RNDIS_OID_GEN_CO_BYTES_XMIT_OUTSTANDING         0x00020205
+#define RNDIS_OID_GEN_CO_NETCARD_LOAD                   0x00020206
+
+//
+// These are objects for Connection-oriented media call-managers.
+//
+#define RNDIS_OID_CO_ADD_PVC                            0xFF000001
+#define RNDIS_OID_CO_DELETE_PVC                         0xFF000002
+#define RNDIS_OID_CO_GET_CALL_INFORMATION               0xFF000003
+#define RNDIS_OID_CO_ADD_ADDRESS                        0xFF000004
+#define RNDIS_OID_CO_DELETE_ADDRESS                     0xFF000005
+#define RNDIS_OID_CO_GET_ADDRESSES                      0xFF000006
+#define RNDIS_OID_CO_ADDRESS_CHANGE                     0xFF000007
+#define RNDIS_OID_CO_SIGNALING_ENABLED                  0xFF000008
+#define RNDIS_OID_CO_SIGNALING_DISABLED                 0xFF000009
+
+
+//
+// 802.3 Objects (Ethernet)
+//
+
+#define RNDIS_OID_802_3_PERMANENT_ADDRESS               0x01010101
+#define RNDIS_OID_802_3_CURRENT_ADDRESS                 0x01010102
+#define RNDIS_OID_802_3_MULTICAST_LIST                  0x01010103
+#define RNDIS_OID_802_3_MAXIMUM_LIST_SIZE               0x01010104
+#define RNDIS_OID_802_3_MAC_OPTIONS                     0x01010105
+
+//
+//
+#define NDIS_802_3_MAC_OPTION_PRIORITY                  0x00000001
+
+#define RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT             0x01020101
+#define RNDIS_OID_802_3_XMIT_ONE_COLLISION              0x01020102
+#define RNDIS_OID_802_3_XMIT_MORE_COLLISIONS            0x01020103
+
+#define RNDIS_OID_802_3_XMIT_DEFERRED                   0x01020201
+#define RNDIS_OID_802_3_XMIT_MAX_COLLISIONS             0x01020202
+#define RNDIS_OID_802_3_RCV_OVERRUN                     0x01020203
+#define RNDIS_OID_802_3_XMIT_UNDERRUN                   0x01020204
+#define RNDIS_OID_802_3_XMIT_HEARTBEAT_FAILURE          0x01020205
+#define RNDIS_OID_802_3_XMIT_TIMES_CRS_LOST             0x01020206
+#define RNDIS_OID_802_3_XMIT_LATE_COLLISIONS            0x01020207
+
+
+//
+// Remote NDIS message types
+//
+#define REMOTE_NDIS_PACKET_MSG                  0x00000001
+#define REMOTE_NDIS_INITIALIZE_MSG              0x00000002
+#define REMOTE_NDIS_HALT_MSG                    0x00000003
+#define REMOTE_NDIS_QUERY_MSG                   0x00000004
+#define REMOTE_NDIS_SET_MSG                     0x00000005
+#define REMOTE_NDIS_RESET_MSG                   0x00000006
+#define REMOTE_NDIS_INDICATE_STATUS_MSG         0x00000007
+#define REMOTE_NDIS_KEEPALIVE_MSG               0x00000008
+
+#define REMOTE_CONDIS_MP_CREATE_VC_MSG          0x00008001
+#define REMOTE_CONDIS_MP_DELETE_VC_MSG          0x00008002
+#define REMOTE_CONDIS_MP_ACTIVATE_VC_MSG        0x00008005
+#define REMOTE_CONDIS_MP_DEACTIVATE_VC_MSG      0x00008006
+#define REMOTE_CONDIS_INDICATE_STATUS_MSG       0x00008007
+
+
+// Remote NDIS message completion types
+#define REMOTE_NDIS_INITIALIZE_CMPLT            0x80000002
+#define REMOTE_NDIS_QUERY_CMPLT                 0x80000004
+#define REMOTE_NDIS_SET_CMPLT                   0x80000005
+#define REMOTE_NDIS_RESET_CMPLT                 0x80000006
+#define REMOTE_NDIS_KEEPALIVE_CMPLT             0x80000008
+
+#define REMOTE_CONDIS_MP_CREATE_VC_CMPLT        0x80008001
+#define REMOTE_CONDIS_MP_DELETE_VC_CMPLT        0x80008002
+#define REMOTE_CONDIS_MP_ACTIVATE_VC_CMPLT      0x80008005
+#define REMOTE_CONDIS_MP_DEACTIVATE_VC_CMPLT    0x80008006
+
+//
+// Reserved message type for private communication between lower-layer
+// host driver and remote device, if necessary.
+//
+#define REMOTE_NDIS_BUS_MSG                     0xff000001
+
+
+
+//
+//  Defines for DeviceFlags in RNDIS_INITIALIZE_COMPLETE
+//
+#define RNDIS_DF_CONNECTIONLESS             0x00000001
+#define RNDIS_DF_CONNECTION_ORIENTED        0x00000002
+#define RNDIS_DF_RAW_DATA                   0x00000004
+
+//
+//  Remote NDIS medium types.
+//
+#define RNdisMedium802_3                    0x00000000
+#define RNdisMedium802_5                    0x00000001
+#define RNdisMediumFddi                     0x00000002
+#define RNdisMediumWan                      0x00000003
+#define RNdisMediumLocalTalk                0x00000004
+#define RNdisMediumArcnetRaw                0x00000006
+#define RNdisMediumArcnet878_2              0x00000007
+#define RNdisMediumAtm                      0x00000008
+#define RNdisMediumWirelessWan              0x00000009
+#define RNdisMediumIrda                     0x0000000a
+#define RNdisMediumCoWan                    0x0000000b
+#define RNdisMediumMax                      0x0000000d     // Not a real medium, defined as an upper-bound
+
+//
+// Remote NDIS medium connection states.
+//
+#define RNdisMediaStateConnected            0x00000000
+#define RNdisMediaStateDisconnected         0x00000001
+
+//
+//  Remote NDIS version numbers
+//
+#define RNDIS_MAJOR_VERSION                 0x00000001
+#define RNDIS_MINOR_VERSION                 0x00000000
+
+//
+//  NdisInitialize message
+//
+typedef struct _RNDIS_INITIALIZE_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    UINT32                                  MajorVersion;
+    UINT32                                  MinorVersion;
+    UINT32                                  MaxTransferSize;
+} RNDIS_INITIALIZE_REQUEST, *PRNDIS_INITIALIZE_REQUEST;
+
+
+//
+//  Response to NdisInitialize
+//
+typedef struct _RNDIS_INITIALIZE_COMPLETE
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_STATUS                            Status;
+    UINT32                                  MajorVersion;
+    UINT32                                  MinorVersion;
+    UINT32                                  DeviceFlags;
+    RNDIS_MEDIUM                            Medium;
+    UINT32                                  MaxPacketsPerMessage;
+    UINT32                                  MaxTransferSize;
+    UINT32                                  PacketAlignmentFactor;
+    UINT32                                  AFListOffset;
+    UINT32                                  AFListSize;
+} RNDIS_INITIALIZE_COMPLETE, *PRNDIS_INITIALIZE_COMPLETE;
+
+
+//
+//  Call manager devices only: Information about an address family
+//  supported by the device is appended to the response to NdisInitialize.
+//
+typedef struct _RNDIS_CO_ADDRESS_FAMILY
+{
+    RNDIS_AF                                AddressFamily;
+    UINT32                                  MajorVersion;
+    UINT32                                  MinorVersion;
+} RNDIS_CO_ADDRESS_FAMILY, *PRNDIS_CO_ADDRESS_FAMILY;
+
+
+//
+//  NdisHalt message
+//
+typedef struct _RNDIS_HALT_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+} RNDIS_HALT_REQUEST, *PRNDIS_HALT_REQUEST;
+
+
+//
+// NdisQueryRequest message
+//
+typedef struct _RNDIS_QUERY_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_OID                               Oid;
+    UINT32                                  InformationBufferLength;
+    UINT32                                  InformationBufferOffset;
+    RNDIS_HANDLE                            DeviceVcHandle;
+} RNDIS_QUERY_REQUEST, *PRNDIS_QUERY_REQUEST;
+
+
+//
+//  Response to NdisQueryRequest
+//
+typedef struct _RNDIS_QUERY_COMPLETE
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_STATUS                            Status;
+    UINT32                                  InformationBufferLength;
+    UINT32                                  InformationBufferOffset;
+} RNDIS_QUERY_COMPLETE, *PRNDIS_QUERY_COMPLETE;
+
+
+//
+//  NdisSetRequest message
+//
+typedef struct _RNDIS_SET_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_OID                               Oid;
+    UINT32                                  InformationBufferLength;
+    UINT32                                  InformationBufferOffset;
+    RNDIS_HANDLE                            DeviceVcHandle;
+} RNDIS_SET_REQUEST, *PRNDIS_SET_REQUEST;
+
+
+//
+//  Response to NdisSetRequest
+//
+typedef struct _RNDIS_SET_COMPLETE
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_STATUS                            Status;
+} RNDIS_SET_COMPLETE, *PRNDIS_SET_COMPLETE;
+
+
+//
+//  NdisReset message
+//
+typedef struct _RNDIS_RESET_REQUEST
+{
+    UINT32                                  Reserved;
+} RNDIS_RESET_REQUEST, *PRNDIS_RESET_REQUEST;
+
+//
+//  Response to NdisReset
+//
+typedef struct _RNDIS_RESET_COMPLETE
+{
+    RNDIS_STATUS                            Status;
+    UINT32                                  AddressingReset;
+} RNDIS_RESET_COMPLETE, *PRNDIS_RESET_COMPLETE;
+
+
+//
+//  NdisMIndicateStatus message
+//
+typedef struct _RNDIS_INDICATE_STATUS
+{
+    RNDIS_STATUS                            Status;
+    UINT32                                  StatusBufferLength;
+    UINT32                                  StatusBufferOffset;
+} RNDIS_INDICATE_STATUS, *PRNDIS_INDICATE_STATUS;
+
+
+//
+//  Diagnostic information passed as the status buffer in
+//  RNDIS_INDICATE_STATUS messages signifying error conditions.
+//
+typedef struct _RNDIS_DIAGNOSTIC_INFO
+{
+    RNDIS_STATUS                            DiagStatus;
+    UINT32                                  ErrorOffset;
+} RNDIS_DIAGNOSTIC_INFO, *PRNDIS_DIAGNOSTIC_INFO;
+
+
+
+//
+//  NdisKeepAlive message
+//
+typedef struct _RNDIS_KEEPALIVE_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+} RNDIS_KEEPALIVE_REQUEST, *PRNDIS_KEEPALIVE_REQUEST;
+
+
+//
+// Response to NdisKeepAlive
+//
+typedef struct _RNDIS_KEEPALIVE_COMPLETE
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_STATUS                            Status;
+} RNDIS_KEEPALIVE_COMPLETE, *PRNDIS_KEEPALIVE_COMPLETE;
+
+
+//
+//  Data message. All Offset fields contain byte offsets from the beginning
+//  of the RNDIS_PACKET structure. All Length fields are in bytes.
+//  VcHandle is set to 0 for connectionless data, otherwise it
+//  contains the VC handle.
+//
+typedef struct _RNDIS_PACKET
+{
+    UINT32                                  DataOffset;
+    UINT32                                  DataLength;
+    UINT32                                  OOBDataOffset;
+    UINT32                                  OOBDataLength;
+    UINT32                                  NumOOBDataElements;
+    UINT32                                  PerPacketInfoOffset;
+    UINT32                                  PerPacketInfoLength;
+    RNDIS_HANDLE                            VcHandle;
+    UINT32                                  Reserved;
+} RNDIS_PACKET, *PRNDIS_PACKET;
+
+//
+//  Optional Out of Band data associated with a Data message.
+//
+typedef struct _RNDIS_OOBD
+{
+    UINT32                                  Size;
+    RNDIS_CLASS_ID                          Type;
+    UINT32                                  ClassInformationOffset;
+} RNDIS_OOBD, *PRNDIS_OOBD;
+
+//
+//  Packet extension field contents associated with a Data message.
+//
+typedef struct _RNDIS_PER_PACKET_INFO
+{
+    UINT32                                  Size;
+    UINT32                                  Type;
+    UINT32                                  PerPacketInformationOffset;
+} RNDIS_PER_PACKET_INFO, *PRNDIS_PER_PACKET_INFO;
+
+
+//
+//  Format of Information buffer passed in a SetRequest for the OID
+//  OID_GEN_RNDIS_CONFIG_PARAMETER.
+//
+typedef struct _RNDIS_CONFIG_PARAMETER_INFO
+{
+    UINT32                                  ParameterNameOffset;
+    UINT32                                  ParameterNameLength;
+    UINT32                                  ParameterType;
+    UINT32                                  ParameterValueOffset;
+    UINT32                                  ParameterValueLength;
+} RNDIS_CONFIG_PARAMETER_INFO, *PRNDIS_CONFIG_PARAMETER_INFO;
+
+//
+//  Values for ParameterType in RNDIS_CONFIG_PARAMETER_INFO
+//
+#define RNDIS_CONFIG_PARAM_TYPE_INTEGER     0
+#define RNDIS_CONFIG_PARAM_TYPE_STRING      2
+
+
+//
+//  CONDIS Miniport messages for connection oriented devices
+//  that do not implement a call manager.
+//
+
+//
+//  CoNdisMiniportCreateVc message
+//
+typedef struct _RCONDIS_MP_CREATE_VC
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_HANDLE                            NdisVcHandle;
+} RCONDIS_MP_CREATE_VC, *PRCONDIS_MP_CREATE_VC;
+
+//
+//  Response to CoNdisMiniportCreateVc
+//
+typedef struct _RCONDIS_MP_CREATE_VC_COMPLETE
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_HANDLE                            DeviceVcHandle;
+    RNDIS_STATUS                            Status;
+} RCONDIS_MP_CREATE_VC_COMPLETE, *PRCONDIS_MP_CREATE_VC_COMPLETE;
+
+
+//
+//  CoNdisMiniportDeleteVc message
+//
+typedef struct _RCONDIS_MP_DELETE_VC
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_HANDLE                            DeviceVcHandle;
+} RCONDIS_MP_DELETE_VC, *PRCONDIS_MP_DELETE_VC;
+
+//
+//  Response to CoNdisMiniportDeleteVc
+//
+typedef struct _RCONDIS_MP_DELETE_VC_COMPLETE
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_STATUS                            Status;
+} RCONDIS_MP_DELETE_VC_COMPLETE, *PRCONDIS_MP_DELETE_VC_COMPLETE;
+
+
+//
+//  CoNdisMiniportQueryRequest message
+//
+typedef struct _RCONDIS_MP_QUERY_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_REQUEST_TYPE                      RequestType;
+    RNDIS_OID                               Oid;
+    RNDIS_HANDLE                            DeviceVcHandle;
+    UINT32                                  InformationBufferLength;
+    UINT32                                  InformationBufferOffset;
+} RCONDIS_MP_QUERY_REQUEST, *PRCONDIS_MP_QUERY_REQUEST;
+
+
+//
+//  CoNdisMiniportSetRequest message
+//
+typedef struct _RCONDIS_MP_SET_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_REQUEST_TYPE                      RequestType;
+    RNDIS_OID                               Oid;
+    RNDIS_HANDLE                            DeviceVcHandle;
+    UINT32                                  InformationBufferLength;
+    UINT32                                  InformationBufferOffset;
+} RCONDIS_MP_SET_REQUEST, *PRCONDIS_MP_SET_REQUEST;
+
+
+//
+//  CoNdisIndicateStatus message
+//
+typedef struct _RCONDIS_INDICATE_STATUS
+{
+    RNDIS_HANDLE                            NdisVcHandle;
+    RNDIS_STATUS                            Status;
+    UINT32                                  StatusBufferLength;
+    UINT32                                  StatusBufferOffset;
+} RCONDIS_INDICATE_STATUS, *PRCONDIS_INDICATE_STATUS;
+
+
+//
+//  CONDIS Call/VC parameters
+//
+
+typedef struct _RCONDIS_SPECIFIC_PARAMETERS
+{
+    UINT32                                  ParameterType;
+    UINT32                                  ParameterLength;
+    UINT32                                  ParameterOffset;
+} RCONDIS_SPECIFIC_PARAMETERS, *PRCONDIS_SPECIFIC_PARAMETERS;
+
+typedef struct _RCONDIS_MEDIA_PARAMETERS
+{
+    UINT32                                  Flags;
+    UINT32                                  Reserved1;
+    UINT32                                  Reserved2;
+    RCONDIS_SPECIFIC_PARAMETERS             MediaSpecific;
+} RCONDIS_MEDIA_PARAMETERS, *PRCONDIS_MEDIA_PARAMETERS;
+
+
+typedef struct _RNDIS_FLOWSPEC
+{
+    UINT32                                  TokenRate;
+    UINT32                                  TokenBucketSize;
+    UINT32                                  PeakBandwidth;
+    UINT32                                  Latency;
+    UINT32                                  DelayVariation;
+    UINT32                                  ServiceType;
+    UINT32                                  MaxSduSize;
+    UINT32                                  MinimumPolicedSize;
+} RNDIS_FLOWSPEC, *PRNDIS_FLOWSPEC;
+
+typedef struct _RCONDIS_CALL_MANAGER_PARAMETERS
+{
+    RNDIS_FLOWSPEC                          Transmit;
+    RNDIS_FLOWSPEC                          Receive;
+    RCONDIS_SPECIFIC_PARAMETERS             CallMgrSpecific;
+} RCONDIS_CALL_MANAGER_PARAMETERS, *PRCONDIS_CALL_MANAGER_PARAMETERS;
+
+//
+//  CoNdisMiniportActivateVc message
+//
+typedef struct _RCONDIS_MP_ACTIVATE_VC_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    UINT32                                  Flags;
+    RNDIS_HANDLE                            DeviceVcHandle;
+    UINT32                                  MediaParamsOffset;
+    UINT32                                  MediaParamsLength;
+    UINT32                                  CallMgrParamsOffset;
+    UINT32                                  CallMgrParamsLength;
+} RCONDIS_MP_ACTIVATE_VC_REQUEST, *PRCONDIS_MP_ACTIVATE_VC_REQUEST;
+
+//
+//  Response to CoNdisMiniportActivateVc
+//
+typedef struct _RCONDIS_MP_ACTIVATE_VC_COMPLETE
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_STATUS                            Status;
+} RCONDIS_MP_ACTIVATE_VC_COMPLETE, *PRCONDIS_MP_ACTIVATE_VC_COMPLETE;
+
+
+//
+//  CoNdisMiniportDeactivateVc message
+//
+typedef struct _RCONDIS_MP_DEACTIVATE_VC_REQUEST
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    UINT32                                  Flags;
+    RNDIS_HANDLE                            DeviceVcHandle;
+} RCONDIS_MP_DEACTIVATE_VC_REQUEST, *PRCONDIS_MP_DEACTIVATE_VC_REQUEST;
+
+//
+//  Response to CoNdisMiniportDeactivateVc
+//
+typedef struct _RCONDIS_MP_DEACTIVATE_VC_COMPLETE
+{
+    RNDIS_REQUEST_ID                        RequestId;
+    RNDIS_STATUS                            Status;
+} RCONDIS_MP_DEACTIVATE_VC_COMPLETE, *PRCONDIS_MP_DEACTIVATE_VC_COMPLETE;
+
+
+//
+// union with all of the RNDIS messages
+//
+typedef union _RNDIS_MESSAGE_CONTAINER
+{
+    RNDIS_PACKET                        Packet;
+    RNDIS_INITIALIZE_REQUEST            InitializeRequest;
+    RNDIS_HALT_REQUEST                  HaltRequest;
+    RNDIS_QUERY_REQUEST                 QueryRequest;
+    RNDIS_SET_REQUEST                   SetRequest;
+    RNDIS_RESET_REQUEST                 ResetRequest;
+    RNDIS_KEEPALIVE_REQUEST             KeepaliveRequest;
+    RNDIS_INDICATE_STATUS               IndicateStatus;
+    RNDIS_INITIALIZE_COMPLETE           InitializeComplete;
+    RNDIS_QUERY_COMPLETE                QueryComplete;
+    RNDIS_SET_COMPLETE                  SetComplete;
+    RNDIS_RESET_COMPLETE                ResetComplete;
+    RNDIS_KEEPALIVE_COMPLETE            KeepaliveComplete;
+    RCONDIS_MP_CREATE_VC                CoMiniportCreateVc;
+    RCONDIS_MP_DELETE_VC                CoMiniportDeleteVc;
+    RCONDIS_INDICATE_STATUS             CoIndicateStatus;
+    RCONDIS_MP_ACTIVATE_VC_REQUEST      CoMiniportActivateVc;
+    RCONDIS_MP_DEACTIVATE_VC_REQUEST    CoMiniportDeactivateVc;
+    RCONDIS_MP_CREATE_VC_COMPLETE       CoMiniportCreateVcComplete;
+    RCONDIS_MP_DELETE_VC_COMPLETE       CoMiniportDeleteVcComplete;
+    RCONDIS_MP_ACTIVATE_VC_COMPLETE     CoMiniportActivateVcComplete;
+    RCONDIS_MP_DEACTIVATE_VC_COMPLETE   CoMiniportDeactivateVcComplete;
+
+
+} RNDIS_MESSAGE_CONTAINER, *PRNDIS_MESSAGE_CONTAINER;
+
+//
+// Remote NDIS message format
+//
+typedef __struct_bcount(MessageLength) struct _RNDIS_MESSAGE
+{
+    UINT32                                  NdisMessageType;
+
+    //
+    // Total length of this message, from the beginning
+    // of the RNDIS_MESSAGE struct, in bytes.
+    //
+    UINT32                                  MessageLength;
+
+    // Actual message
+    RNDIS_MESSAGE_CONTAINER                 Message;
+
+} RNDIS_MESSAGE, *PRNDIS_MESSAGE;
+
+
+
+//
+// Handy macros
+
+// get the size of an RNDIS message. Pass in the message type,
+// RNDIS_SET_REQUEST, RNDIS_PACKET for example
+#define RNDIS_MESSAGE_SIZE(Message)                             \
+    (sizeof(Message) + (sizeof(RNDIS_MESSAGE) - sizeof(RNDIS_MESSAGE_CONTAINER)))
+
+// get pointer to info buffer with message pointer
+#define MESSAGE_TO_INFO_BUFFER(Message)                         \
+    (((PUCHAR)(Message)) + Message->InformationBufferOffset)
+
+// get pointer to status buffer with message pointer
+#define MESSAGE_TO_STATUS_BUFFER(Message)                       \
+    (((PUCHAR)(Message)) + Message->StatusBufferOffset)
+
+// get pointer to OOBD buffer with message pointer
+#define MESSAGE_TO_OOBD_BUFFER(Message)                         \
+    (((PUCHAR)(Message)) + Message->OOBDataOffset)
+
+// get pointer to data buffer with message pointer
+#define MESSAGE_TO_DATA_BUFFER(Message)                         \
+    (((PUCHAR)(Message)) + Message->PerPacketInfoOffset)
+
+// get pointer to contained message from NDIS_MESSAGE pointer
+#define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(RndisMessage)          \
+    ((PVOID) &RndisMessage->Message)
+
+// get pointer to contained message from NDIS_MESSAGE pointer
+#define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(RndisMessage)      \
+    ((PVOID) RndisMessage)
+
+#endif // _RNDIS_H_
--- /dev/null
+++ b/drivers/staging/hv/include/VmbusChannelInterface.h
@@ -0,0 +1,131 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+// allow nameless unions
+//#pragma warning(disable : 4201)
+
+//
+// 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(BYTE) * 16384)
+
+//
+// Define PipeMode values.
+//
+#define VMBUS_PIPE_TYPE_BYTE                    0x00000000
+#define VMBUS_PIPE_TYPE_MESSAGE                 0x00000004
+
+//
+// The size of the user defined data buffer for non-pipe offers.
+//
+#define MAX_USER_DEFINED_BYTES                  120
+
+//
+// The size of the user defined data buffer for pipe offers.
+//
+#define MAX_PIPE_USER_DEFINED_BYTES             116
+
+
+//
+// At the center of the Channel Management library is
+// the Channel Offer. This struct contains the
+// fundamental information about an offer.
+//
+#pragma pack(push,1)
+
+typedef struct
+{
+
+    GUID    InterfaceType;
+    GUID    InterfaceInstance;
+    UINT64  InterruptLatencyIn100nsUnits;
+    UINT32  InterfaceRevision;
+    UINT32  ServerContextAreaSize;  // in bytes
+    UINT16  ChannelFlags;
+    UINT16  MmioMegabytes;          // in bytes * 1024 * 1024
+
+    union
+    {
+        //
+        // Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes.
+        //
+        struct
+        {
+            UCHAR   UserDefined[MAX_USER_DEFINED_BYTES];
+        } Standard;
+
+        //
+        // Pipes: The following sructure is an integrated pipe protocol, which
+        //        is implemented on top of standard user-defined data. Pipe clients
+        //        have MAX_PIPE_USER_DEFINED_BYTES left for their own use.
+        //
+        struct
+        {
+            UINT32  PipeMode;
+            UCHAR   UserDefined[MAX_PIPE_USER_DEFINED_BYTES];
+        } Pipe;
+    } u;
+	UINT32	Padding;
+} VMBUS_CHANNEL_OFFER, *PVMBUS_CHANNEL_OFFER;
+#pragma pack(pop)
+
+
+//
+// Verify the MAX_PIPE_USER_DEFINED_BYTES value.
+//
+//C_ASSERT(MAX_PIPE_USER_DEFINED_BYTES ==
+//         MAX_USER_DEFINED_BYTES -
+//         (FIELD_OFFSET(VMBUS_CHANNEL_OFFER, u.Pipe.UserDefined) -
+//          FIELD_OFFSET(VMBUS_CHANNEL_OFFER, u.Standard.UserDefined)));
+//
+
+typedef UINT32 GPADL_HANDLE;
+
+//
+// Server Flags
+//
+
+#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE           1
+#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES       2
+#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS               4
+#define VMBUS_CHANNEL_NAMED_PIPE_MODE                   0x10
+#define VMBUS_CHANNEL_LOOPBACK_OFFER                   0x100
+#define VMBUS_CHANNEL_PARENT_OFFER                     0x200
+#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION   0x400
+
+//
+// TEMPTEMP -- move this next define to devioctl.h some day
+//
+
+#ifndef FILE_DEVICE_VMBUS
+#define FILE_DEVICE_VMBUS   0x0000003E
+#endif
+
--- /dev/null
+++ b/drivers/staging/hv/include/VmbusPacketFormat.h
@@ -0,0 +1,322 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+//#ifndef PAGE_SIZE
+//#if defined(_IA64_)
+//#error This does not work for IA64
+//#else
+//#define PAGE_SIZE 0x1000
+//#endif
+//#endif
+
+// allow nameless unions
+//#pragma warning(disable : 4201)
+
+typedef struct
+{
+    union
+    {
+        struct
+        {
+            volatile UINT32  In;        // Offset in bytes from the ring base
+            volatile UINT32  Out;       // Offset in bytes from the ring base
+        };
+        volatile LONGLONG    InOut;
+    };
+
+    //
+    // If the receiving endpoint sets this to some non-zero value, the sending
+    // endpoint should not send any interrupts.
+    //
+
+    volatile UINT32 InterruptMask;
+
+} VMRCB, *PVMRCB;
+
+typedef struct
+{
+    union
+    {
+        struct
+        {
+            VMRCB Control;
+        };
+
+        UINT8 Reserved[PAGE_SIZE];
+    };
+
+    //
+    // Beginning of the ring data.  Note: It must be guaranteed that
+    // this data does not share a page with the control structure.
+    //
+    UINT8 Data[1];
+} VMRING, *PVMRING;
+
+#pragma pack(push, 1)
+
+typedef struct
+{
+    UINT16 Type;
+    UINT16 DataOffset8;
+    UINT16 Length8;
+    UINT16 Flags;
+    UINT64 TransactionId;
+} VMPACKET_DESCRIPTOR, *PVMPACKET_DESCRIPTOR;
+
+typedef UINT32 PREVIOUS_PACKET_OFFSET, *PPREVIOUS_PACKET_OFFSET;
+
+typedef struct
+{
+    PREVIOUS_PACKET_OFFSET  PreviousPacketStartOffset;
+    VMPACKET_DESCRIPTOR     Descriptor;
+} VMPACKET_HEADER, *PVMPACKET_HEADER;
+
+typedef struct
+{
+    UINT32  ByteCount;
+    UINT32  ByteOffset;
+} VMTRANSFER_PAGE_RANGE, *PVMTRANSFER_PAGE_RANGE;
+
+#ifdef __cplusplus
+
+typedef struct _VMTRANSFER_PAGE_PACKET_HEADER : VMPACKET_DESCRIPTOR {
+
+#else
+
+typedef struct VMTRANSFER_PAGE_PACKET_HEADER {
+
+    VMPACKET_DESCRIPTOR d;
+
+#endif
+
+    UINT16                  TransferPageSetId;
+    BOOLEAN                 SenderOwnsSet;
+    UINT8                   Reserved;
+    UINT32                  RangeCount;
+    VMTRANSFER_PAGE_RANGE   Ranges[1];
+
+} VMTRANSFER_PAGE_PACKET_HEADER, *PVMTRANSFER_PAGE_PACKET_HEADER;
+
+
+#ifdef __cplusplus
+
+typedef struct _VMGPADL_PACKET_HEADER : VMPACKET_DESCRIPTOR {
+
+#else
+
+typedef struct _VMGPADL_PACKET_HEADER {
+
+    VMPACKET_DESCRIPTOR d;
+
+#endif
+
+
+    UINT32  Gpadl;
+    UINT32  Reserved;
+
+} VMGPADL_PACKET_HEADER, *PVMGPADL_PACKET_HEADER;
+
+#ifdef __cplusplus
+
+typedef struct _VMADD_REMOVE_TRANSFER_PAGE_SET : VMPACKET_DESCRIPTOR {
+
+#else
+
+typedef struct _VMADD_REMOVE_TRANSFER_PAGE_SET {
+
+    VMPACKET_DESCRIPTOR d;
+
+#endif
+
+    UINT32  Gpadl;
+    UINT16  TransferPageSetId;
+    UINT16  Reserved;
+
+} VMADD_REMOVE_TRANSFER_PAGE_SET, *PVMADD_REMOVE_TRANSFER_PAGE_SET;
+
+#pragma pack(pop)
+
+//
+// This structure defines a range in guest physical space that can be made
+// to look virtually contiguous.
+//
+
+typedef struct _GPA_RANGE {
+
+    UINT32  ByteCount;
+    UINT32  ByteOffset;
+    UINT64  PfnArray[0];
+
+} GPA_RANGE, *PGPA_RANGE;
+
+
+
+#pragma pack(push, 1)
+
+//
+// This is the format for an Establish Gpadl packet, which contains a handle
+// by which this GPADL will be known and a set of GPA ranges associated with
+// it.  This can be converted to a MDL by the guest OS.  If there are multiple
+// GPA ranges, then the resulting MDL will be "chained," representing multiple
+// VA ranges.
+//
+
+#ifdef __cplusplus
+
+typedef struct _VMESTABLISH_GPADL : VMPACKET_DESCRIPTOR {
+
+#else
+
+typedef struct _VMESTABLISH_GPADL {
+
+    VMPACKET_DESCRIPTOR d;
+
+#endif
+
+    UINT32      Gpadl;
+    UINT32      RangeCount;
+    GPA_RANGE   Range[1];
+
+} VMESTABLISH_GPADL, *PVMESTABLISH_GPADL;
+
+
+//
+// This is the format for a Teardown Gpadl packet, which indicates that the
+// GPADL handle in the Establish Gpadl packet will never be referenced again.
+//
+
+#ifdef __cplusplus
+
+typedef struct _VMTEARDOWN_GPADL : VMPACKET_DESCRIPTOR {
+
+#else
+
+typedef struct _VMTEARDOWN_GPADL {
+
+    VMPACKET_DESCRIPTOR d;
+
+#endif
+
+    UINT32  Gpadl;
+    UINT32  Reserved; // for alignment to a 8-byte boundary
+} VMTEARDOWN_GPADL, *PVMTEARDOWN_GPADL;
+
+
+//
+// This is the format for a GPA-Direct packet, which contains a set of GPA
+// ranges, in addition to commands and/or data.
+//
+
+#ifdef __cplusplus
+
+typedef struct _VMDATA_GPA_DIRECT : VMPACKET_DESCRIPTOR {
+
+#else
+
+typedef struct _VMDATA_GPA_DIRECT {
+
+    VMPACKET_DESCRIPTOR d;
+
+#endif
+
+    UINT32      Reserved;
+    UINT32      RangeCount;
+    GPA_RANGE   Range[1];
+
+} VMDATA_GPA_DIRECT, *PVMDATA_GPA_DIRECT;
+
+
+
+//
+// This is the format for a Additional Data Packet.
+//
+
+#ifdef __cplusplus
+
+typedef struct _VMADDITIONAL_DATA : VMPACKET_DESCRIPTOR {
+
+#else
+
+typedef struct _VMADDITIONAL_DATA {
+
+    VMPACKET_DESCRIPTOR d;
+
+#endif
+
+    UINT64  TotalBytes;
+    UINT32  ByteOffset;
+    UINT32  ByteCount;
+    UCHAR   Data[1];
+
+} VMADDITIONAL_DATA, *PVMADDITIONAL_DATA;
+
+
+#pragma pack(pop)
+
+typedef union {
+    VMPACKET_DESCRIPTOR             SimpleHeader;
+    VMTRANSFER_PAGE_PACKET_HEADER   TransferPageHeader;
+    VMGPADL_PACKET_HEADER           GpadlHeader;
+    VMADD_REMOVE_TRANSFER_PAGE_SET  AddRemoveTransferPageHeader;
+    VMESTABLISH_GPADL               EstablishGpadlHeader;
+    VMTEARDOWN_GPADL                TeardownGpadlHeader;
+    VMDATA_GPA_DIRECT               DataGpaDirectHeader;
+} VMPACKET_LARGEST_POSSIBLE_HEADER, *PVMPACKET_LARGEST_POSSIBLE_HEADER;
+
+#define VMPACKET_DATA_START_ADDRESS(__packet)                           \
+    (PVOID)(((PUCHAR)__packet) + ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8 * 8)
+
+#define VMPACKET_DATA_LENGTH(__packet)                                  \
+    ((((PVMPACKET_DESCRIPTOR)__packet)->Length8 - ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8) * 8)
+
+#define VMPACKET_TRANSFER_MODE(__packet) ((PVMPACKET_DESCRIPTOR)__packet)->Type
+
+typedef enum {
+    VmbusServerEndpoint = 0,
+    VmbusClientEndpoint,
+    VmbusEndpointMaximum
+} ENDPOINT_TYPE, *PENDPOINT_TYPE;
+
+typedef enum {
+    VmbusPacketTypeInvalid                      = 0x0,
+    VmbusPacketTypeSynch                        = 0x1,
+    VmbusPacketTypeAddTransferPageSet           = 0x2,
+    VmbusPacketTypeRemoveTransferPageSet        = 0x3,
+    VmbusPacketTypeEstablishGpadl               = 0x4,
+    VmbusPacketTypeTearDownGpadl                = 0x5,
+    VmbusPacketTypeDataInBand                   = 0x6,
+    VmbusPacketTypeDataUsingTransferPages       = 0x7,
+    VmbusPacketTypeDataUsingGpadl               = 0x8,
+    VmbusPacketTypeDataUsingGpaDirect           = 0x9,
+    VmbusPacketTypeCancelRequest                = 0xa,
+    VmbusPacketTypeCompletion                   = 0xb,
+    VmbusPacketTypeDataUsingAdditionalPackets   = 0xc,
+    VmbusPacketTypeAdditionalData               = 0xd
+} VMBUS_PACKET_TYPE, *PVMBUS_PACKET_TYPE;
+
+#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED    1
+
+
--- /dev/null
+++ b/drivers/staging/hv/include/vstorage.h
@@ -0,0 +1,309 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+//#include <vmbuspacketformat.h>
+//#include <ntddscsi.h>
+
+#define C_ASSERT(x)
+//
+//  public interface to the server
+//
+
+//
+//  Storvsp device interface guid
+//
+
+
+//
+//  Protocol versions.
+//
+
+//
+// vstorage.w revision number.  This is used in the case of a version match,
+// to alert the user that structure sizes may be mismatched even though the
+// protocol versions match.
+//
+
+#define REVISION_STRING(REVISION_) #REVISION_
+#define FILL_VMSTOR_REVISION(RESULT_LVALUE_)                     \
+{                                                                \
+    char *revisionString = REVISION_STRING($Revision: 6 $) + 11; \
+    RESULT_LVALUE_ = 0;                                          \
+    while (*revisionString >= '0' && *revisionString <= '9')     \
+    {                                                            \
+        RESULT_LVALUE_ *= 10;                                    \
+        RESULT_LVALUE_ += *revisionString - '0';                 \
+        revisionString++;                                        \
+    }                                                            \
+}
+
+//
+// Major/minor macros.  Minor version is in LSB, meaning that earlier flat
+// version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1).
+//
+
+#define VMSTOR_PROTOCOL_MAJOR(VERSION_)         (((VERSION_) >> 8) & 0xff)
+#define VMSTOR_PROTOCOL_MINOR(VERSION_)         (((VERSION_)     ) & 0xff)
+#define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
+                                                 (((MINOR_) & 0xff)     ))
+
+//
+// Invalid version.
+//
+
+#define VMSTOR_INVALID_PROTOCOL_VERSION  -1
+
+//
+// Version history:
+// V1 Beta                    0.1
+// V1 RC < 2008/1/31          1.0
+// V1 RC > 2008/1/31          2.0
+//
+#define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0)
+
+
+//
+//  This will get replaced with the max transfer length that is possible on
+//  the host adapter.
+//  The max transfer length will be published when we offer a vmbus channel.
+//
+
+#define MAX_TRANSFER_LENGTH 0x40000
+#define DEFAULT_PACKET_SIZE (sizeof(VMDATA_GPA_DIRECT) +                            \
+                             sizeof(VSTOR_PACKET) +                                 \
+                             (sizeof(UINT64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
+
+
+
+//
+//  Packet structure describing virtual storage requests.
+//
+
+typedef enum
+{
+    VStorOperationCompleteIo            = 1,
+    VStorOperationRemoveDevice          = 2,
+    VStorOperationExecuteSRB            = 3,
+    VStorOperationResetLun              = 4,
+    VStorOperationResetAdapter          = 5,
+    VStorOperationResetBus              = 6,
+    VStorOperationBeginInitialization   = 7,
+    VStorOperationEndInitialization     = 8,
+    VStorOperationQueryProtocolVersion  = 9,
+    VStorOperationQueryProperties       = 10,
+    VStorOperationMaximum               = 10
+
+} VSTOR_PACKET_OPERATION;
+
+
+//
+//  Platform neutral description of a scsi request -
+//  this remains the same across the write regardless of 32/64 bit
+//  note: it's patterned off the SCSI_PASS_THROUGH structure
+//
+
+
+#pragma pack(push,1)
+
+
+#define CDB16GENERIC_LENGTH 0x10
+
+#ifndef SENSE_BUFFER_SIZE
+#define SENSE_BUFFER_SIZE 0x12
+#endif
+C_ASSERT(SENSE_BUFFER_SIZE == 0x12);
+
+#define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14
+
+
+typedef struct
+{
+    USHORT Length;
+    UCHAR SrbStatus;
+    UCHAR ScsiStatus;
+
+    UCHAR PortNumber;
+    UCHAR PathId;
+    UCHAR TargetId;
+    UCHAR Lun;
+
+    UCHAR CdbLength;
+    UCHAR SenseInfoLength;
+    UCHAR DataIn;
+    UCHAR Reserved;
+
+    ULONG DataTransferLength;
+
+    union
+    {
+        UCHAR Cdb[CDB16GENERIC_LENGTH];
+
+        UCHAR SenseData[SENSE_BUFFER_SIZE];
+
+        UCHAR ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
+    };
+
+} VMSCSI_REQUEST, *PVMSCSI_REQUEST;
+
+C_ASSERT((sizeof(VMSCSI_REQUEST) % 4) == 0);
+
+
+//
+//  This structure is sent during the intialization phase to get the different
+//  properties of the channel.
+//
+
+typedef struct
+{
+    USHORT ProtocolVersion;
+    UCHAR  PathId;
+    UCHAR  TargetId;
+
+    //
+    // Note: port number is only really known on the client side
+    //
+    ULONG  PortNumber;
+
+    ULONG  Flags;
+
+    ULONG  MaxTransferBytes;
+
+    //
+    //  This id is unique for each channel and will correspond with
+    //  vendor specific data in the inquirydata
+    //
+
+    ULONGLONG UniqueId;
+
+} VMSTORAGE_CHANNEL_PROPERTIES, *PVMSTORAGE_CHANNEL_PROPERTIES;
+
+C_ASSERT((sizeof(VMSTORAGE_CHANNEL_PROPERTIES) % 4) == 0);
+
+
+//
+//  This structure is sent during the storage protocol negotiations.
+//
+
+typedef struct
+{
+    //
+    // Major (MSW) and minor (LSW) version numbers.
+    //
+
+    USHORT MajorMinor;
+
+
+    //
+    // Revision number is auto-incremented whenever this file is changed
+    // (See FILL_VMSTOR_REVISION macro above).  Mismatch does not definitely
+    // indicate incompatibility--but it does indicate mismatched builds.
+    //
+
+    USHORT Revision;
+
+} VMSTORAGE_PROTOCOL_VERSION, *PVMSTORAGE_PROTOCOL_VERSION;
+
+C_ASSERT((sizeof(VMSTORAGE_PROTOCOL_VERSION) % 4) == 0);
+
+
+//
+// Channel Property Flags
+//
+
+#define STORAGE_CHANNEL_REMOVABLE_FLAG                  0x1
+#define STORAGE_CHANNEL_EMULATED_IDE_FLAG               0x2
+
+
+typedef struct _VSTOR_PACKET
+{
+    //
+    // Requested operation type
+    //
+
+    VSTOR_PACKET_OPERATION Operation;
+
+    //
+    //  Flags - see below for values
+    //
+
+    ULONG     Flags;
+
+    //
+    // Status of the request returned from the server side.
+    //
+
+    ULONG     Status;
+
+    //
+    // Data payload area
+    //
+
+    union
+    {
+        //
+        //  Structure used to forward SCSI commands from the client to the server.
+        //
+
+        VMSCSI_REQUEST VmSrb;
+
+        //
+        // Structure used to query channel properties.
+        //
+
+        VMSTORAGE_CHANNEL_PROPERTIES StorageChannelProperties;
+
+        //
+        // Used during version negotiations.
+        //
+
+        VMSTORAGE_PROTOCOL_VERSION Version;
+    };
+
+} VSTOR_PACKET, *PVSTOR_PACKET;
+
+C_ASSERT((sizeof(VSTOR_PACKET) % 4) == 0);
+
+//
+//  Packet flags
+//
+
+//
+//  This flag indicates that the server should send back a completion for this
+//  packet.
+//
+
+#define REQUEST_COMPLETION_FLAG 0x1
+
+//
+//  This is the set of flags that the vsc can set in any packets it sends
+//
+
+#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)
+
+
+#pragma pack(pop)
+
+

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 02/54] Staging: hv: add the Hyper-V driver header files
  2009-07-20 16:00   ` Greg Kroah-Hartman
  (?)
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-driver-header-files.patch --]
[-- Type: text/plain, Size: 30311 bytes --]

From: Hank Janssen <hjanssen@microsoft.com>

These are the header files for the different Linux Hyper-V drivers to
use.

Signed-off-by: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/include/NetVscApi.h  |  145 +++++++++++++++++
 drivers/staging/hv/include/StorVscApi.h |  137 ++++++++++++++++
 drivers/staging/hv/include/VmbusApi.h   |  262 +++++++++++++++++++++++++++++++
 drivers/staging/hv/include/logging.h    |  134 ++++++++++++++++
 drivers/staging/hv/include/osd.h        |  263 ++++++++++++++++++++++++++++++++
 drivers/staging/hv/include/vmbus.h      |  111 +++++++++++++
 6 files changed, 1052 insertions(+)
 create mode 100644 drivers/staging/hv/include/NetVscApi.h
 create mode 100644 drivers/staging/hv/include/StorVscApi.h
 create mode 100644 drivers/staging/hv/include/VmbusApi.h
 create mode 100644 drivers/staging/hv/include/logging.h
 create mode 100644 drivers/staging/hv/include/osd.h
 create mode 100644 drivers/staging/hv/include/vmbus.h

--- /dev/null
+++ b/drivers/staging/hv/include/logging.h
@@ -0,0 +1,134 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _LOGGING_H_
+#define _LOGGING_H_
+
+//#include <linux/init.h>
+//#include <linux/module.h>
+
+#include "osd.h"
+
+#define VMBUS				0x0001
+#define STORVSC				0x0002
+#define NETVSC				0x0004
+#define INPUTVSC			0x0008
+#define BLKVSC				0x0010
+#define VMBUS_DRV			0x0100
+#define STORVSC_DRV			0x0200
+#define NETVSC_DRV			0x0400
+#define INPUTVSC_DRV		0x0800
+#define BLKVSC_DRV			0x1000
+
+#define ALL_MODULES			(VMBUS		|\
+							STORVSC		|\
+							NETVSC		|\
+							INPUTVSC	|\
+							BLKVSC		|\
+							VMBUS_DRV	|\
+							STORVSC_DRV	|\
+							NETVSC_DRV	|\
+							INPUTVSC_DRV|\
+							BLKVSC_DRV)
+
+// Logging Level
+#define CRITICAL_LVL				2
+#define ERROR_LVL					3
+#define WARNING_LVL					4
+#define INFO_LVL					6
+#define DEBUG_LVL					7
+#define DEBUG_LVL_ENTEREXIT			8
+#define DEBUG_RING_LVL				9
+
+extern unsigned int vmbus_loglevel;
+
+#define ASSERT(expr)	\
+        if (!(expr)) {	\
+		LogMsg("<%d>Assertion failed! %s,%s,%s,line=%d\n", CRITICAL_LVL, #expr,__FILE__,__FUNCTION__,__LINE__);	\
+		__asm__ __volatile__("int3");	\
+        }
+
+#define DPRINT(mod, lvl, fmt, args...) do {\
+	if (mod & (HIWORD(vmbus_loglevel))) \
+		(lvl <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() " fmt "\n", DEBUG_LVL, __FUNCTION__, ## args)):(0);\
+	} while (0)
+
+#define DPRINT_DBG(mod, fmt, args...) do {\
+	if (mod & (HIWORD(vmbus_loglevel))) \
+		(DEBUG_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() " fmt "\n", DEBUG_LVL, __FUNCTION__, ## args)):(0);\
+	} while (0)
+
+#define DPRINT_INFO(mod, fmt, args...) do {\
+	if (mod & (HIWORD(vmbus_loglevel))) \
+		(INFO_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": " fmt "\n", INFO_LVL, ## args)):(0);\
+	} while (0)
+
+#define DPRINT_WARN(mod, fmt, args...) do {\
+	if (mod & (HIWORD(vmbus_loglevel))) \
+		(WARNING_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": WARNING! " fmt "\n", WARNING_LVL, ## args)):(0);\
+	} while (0)
+
+#define DPRINT_ERR(mod, fmt, args...) do {\
+	if (mod & (HIWORD(vmbus_loglevel))) \
+		(ERROR_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() ERROR!! " fmt "\n", ERROR_LVL, __FUNCTION__, ## args)):(0);\
+	} while (0)
+
+#ifdef DEBUG
+#define DPRINT_ENTER(mod) do {\
+	if (mod & (HIWORD(vmbus_loglevel))) \
+		(DEBUG_LVL_ENTEREXIT <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" "["#mod"]: %s() enter\n", DEBUG_LVL, __FUNCTION__)):(0);\
+	} while (0)
+
+#define DPRINT_EXIT(mod) do {\
+	if (mod & (HIWORD(vmbus_loglevel))) \
+		(DEBUG_LVL_ENTEREXIT <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" "["#mod"]: %s() exit\n", DEBUG_LVL, __FUNCTION__)):(0);\
+	} while (0)
+#else
+#define DPRINT_ENTER(mod)
+#define DPRINT_EXIT(mod)
+#endif
+
+static inline void PrintBytes(const unsigned char* bytes, int len)
+{
+	int i=0;
+
+	LogMsg("\n<< ");
+	for (i=0; i< len; i++)
+	{
+		LogMsg("0x%x ", bytes[i]);
+	}
+	LogMsg(">>\n");
+}
+
+//
+// Inline
+//
+//static inline void GuidToStr(const GUID g, char *str)
+//{
+//	sprintf(str, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
+//	g[3], g[2], g[1], g[0], g[5], g[4], g[7], g[6], g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15]);
+//
+//}
+
+#endif //_LOGGING_H_
--- /dev/null
+++ b/drivers/staging/hv/include/NetVscApi.h
@@ -0,0 +1,145 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _NETVSC_API_H_
+#define _NETVSC_API_H_
+
+#include "VmbusApi.h"
+
+//
+// Defines
+//
+#define NETVSC_DEVICE_RING_BUFFER_SIZE			64*PAGE_SIZE
+
+#define HW_MACADDR_LEN		6
+
+//
+// Fwd declaration
+//
+typedef struct _NETVSC_PACKET	*PNETVSC_PACKET;
+
+
+//
+// Data types
+//
+
+typedef int (*PFN_ON_OPEN)(DEVICE_OBJECT *Device);
+typedef int (*PFN_ON_CLOSE)(DEVICE_OBJECT *Device);
+
+typedef void (*PFN_QUERY_LINKSTATUS)(DEVICE_OBJECT *Device);
+typedef int (*PFN_ON_SEND)(DEVICE_OBJECT *dev, PNETVSC_PACKET packet);
+typedef void (*PFN_ON_SENDRECVCOMPLETION)(PVOID Context);
+
+typedef int (*PFN_ON_RECVCALLBACK)(DEVICE_OBJECT *dev, PNETVSC_PACKET packet);
+typedef void (*PFN_ON_LINKSTATUS_CHANGED)(DEVICE_OBJECT *dev, UINT32 Status);
+
+// Represent the xfer page packet which contains 1 or more netvsc packet
+typedef struct _XFERPAGE_PACKET {
+	DLIST_ENTRY			ListEntry;
+
+	// # of netvsc packets this xfer packet contains
+	UINT32				Count;
+} XFERPAGE_PACKET;
+
+
+// The number of pages which are enough to cover jumbo frame buffer.
+#define NETVSC_PACKET_MAXPAGE  4
+
+// Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame within the RNDIS
+typedef struct _NETVSC_PACKET {
+	// Bookkeeping stuff
+	DLIST_ENTRY				ListEntry;
+
+	DEVICE_OBJECT			*Device;
+	BOOL					IsDataPacket;
+
+	// Valid only for receives when we break a xfer page packet into multiple netvsc packets
+	XFERPAGE_PACKET		*XferPagePacket;
+
+	union {
+		struct{
+			UINT64						ReceiveCompletionTid;
+			PVOID						ReceiveCompletionContext;
+			PFN_ON_SENDRECVCOMPLETION	OnReceiveCompletion;
+		} Recv;
+		struct{
+			UINT64						SendCompletionTid;
+			PVOID						SendCompletionContext;
+			PFN_ON_SENDRECVCOMPLETION	OnSendCompletion;
+		} Send;
+	} Completion;
+
+	// This points to the memory after PageBuffers
+	PVOID					Extension;
+
+	UINT32					TotalDataBufferLength;
+	// Points to the send/receive buffer where the ethernet frame is
+	UINT32					PageBufferCount;
+	PAGE_BUFFER				PageBuffers[NETVSC_PACKET_MAXPAGE];
+
+} NETVSC_PACKET;
+
+
+// Represents the net vsc driver
+typedef struct _NETVSC_DRIVER_OBJECT {
+	DRIVER_OBJECT				Base; // Must be the first field
+
+	UINT32						RingBufferSize;
+	UINT32						RequestExtSize;
+
+	// Additional num  of page buffers to allocate
+	UINT32						AdditionalRequestPageBufferCount;
+
+	// This is set by the caller to allow us to callback when we receive a packet
+	// from the "wire"
+	PFN_ON_RECVCALLBACK			OnReceiveCallback;
+
+	PFN_ON_LINKSTATUS_CHANGED	OnLinkStatusChanged;
+
+	// Specific to this driver
+	PFN_ON_OPEN					OnOpen;
+	PFN_ON_CLOSE				OnClose;
+	PFN_ON_SEND					OnSend;
+	//PFN_ON_RECVCOMPLETION	OnReceiveCompletion;
+
+	//PFN_QUERY_LINKSTATUS		QueryLinkStatus;
+
+	void*						Context;
+} NETVSC_DRIVER_OBJECT;
+
+
+typedef struct _NETVSC_DEVICE_INFO {
+    UCHAR	MacAddr[6];
+    BOOL	LinkState;	// 0 - link up, 1 - link down
+} NETVSC_DEVICE_INFO;
+
+//
+// Interface
+//
+int
+NetVscInitialize(
+	DRIVER_OBJECT* drv
+	);
+
+#endif // _NETVSC_API_H_
--- /dev/null
+++ b/drivers/staging/hv/include/osd.h
@@ -0,0 +1,263 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _OSD_H_
+#define _OSD_H_
+
+//
+// Defines
+//
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 0x1000
+#endif
+
+#ifndef PAGE_SHIFT
+#define PAGE_SHIFT 12
+#endif
+
+#ifndef memcpy
+#define memcpy		__builtin_memcpy
+#endif
+
+#ifndef memset
+#define memset		__builtin_memset
+#endif
+
+#ifndef memcmp
+#define memcmp		__builtin_memcmp
+#endif
+
+#ifndef strcpy
+#define strcpy		__builtin_strcpy
+#endif
+
+//
+//#ifndef sprintf
+//#define sprintf				__builtin_sprintf
+//#endif
+
+#define STRUCT_PACKED		__attribute__((__packed__))
+#define STRUCT_ALIGNED(x)	__attribute__((__aligned__(x)))
+
+#define UNUSED_VAR(v)		v  __attribute__((__unused__))
+
+#define ALIGN_UP(value, align)			( ((value) & (align-1))? ( ((value) + (align-1)) & ~(align-1) ): (value) )
+#define ALIGN_DOWN(value, align)		( (value) & ~(align-1) )
+#define NUM_PAGES_SPANNED(addr, len)	( (ALIGN_UP(addr+len, PAGE_SIZE) - ALIGN_DOWN(addr, PAGE_SIZE)) >> PAGE_SHIFT )
+
+#define MIN(a, b)       ((a) < (b)? (a): (b))
+#define MAX(a, b)       ((a) > (b)? (a): (b))
+
+#define LOWORD(dw)		((unsigned short) (dw))
+#define HIWORD(dw)		((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
+
+#define FIELD_OFFSET(t, f)    ((unsigned int)(unsigned long)&(((t *)0)->f))
+
+#ifdef FALSE
+#undef FALSE
+#endif
+#define FALSE 0
+
+#ifdef TRUE
+#undef TRUE
+#endif
+#define TRUE  1
+
+#ifndef NULL
+#define NULL  (void *)0
+#endif
+
+typedef struct _DLIST_ENTRY {
+   struct _DLIST_ENTRY *Flink;
+   struct _DLIST_ENTRY *Blink;
+} DLIST_ENTRY;
+
+//
+// unsigned types
+//
+typedef unsigned char		UINT8;
+typedef unsigned short		UINT16;
+typedef unsigned int		UINT32;
+#ifdef __x86_64__
+typedef unsigned long		UINT64;
+#else
+typedef unsigned long long	UINT64;
+#endif
+
+typedef unsigned long long	ULONGLONG;
+typedef unsigned int		ULONG;
+typedef unsigned short		USHORT;
+typedef unsigned char		UCHAR;
+
+//
+// signed types
+//
+typedef char				INT8;
+typedef short				INT16;
+typedef int					INT32;
+#ifdef __x86_64__
+typedef long				INT64;
+#else
+typedef long long		INT64;
+#endif
+
+typedef int					LONG;
+typedef char				CHAR;
+typedef long long			LONGLONG;
+
+//
+// Other types
+//
+typedef unsigned long		SIZE_T;
+typedef void				VOID;
+//typedef unsigned char		GUID[16];
+typedef void*				PVOID;
+typedef unsigned char		BOOL;
+typedef unsigned char		BOOLEAN;
+typedef void*				HANDLE;
+typedef UINT32				DWORD;
+typedef char*				PCHAR;
+typedef unsigned char		BYTE;
+
+typedef unsigned long		ULONG_PTR;
+
+typedef struct {
+	unsigned char	Data[16];
+} GUID;
+
+typedef void (*PFN_WORKITEM_CALLBACK)(void* context);
+typedef void (*PFN_TIMER_CALLBACK)(void* context);
+
+
+#ifdef __x86_64__
+
+#define RDMSR(reg, v) {                                                        \
+    UINT32 h, l;                                                                 \
+     __asm__ __volatile__("rdmsr"                                                               \
+    : "=a" (l), "=d" (h)                                                       \
+    : "c" (reg));                                                              \
+    v = (((UINT64)h) << 32) | l;                                                         \
+}
+
+#define WRMSR(reg, v) {                                                        \
+    UINT32 h, l;                                                               \
+    l = (UINT32)(((UINT64)(v)) & 0xFFFFFFFF);                                  \
+    h = (UINT32)((((UINT64)(v)) >> 32) & 0xFFFFFFFF);                          \
+     __asm__ __volatile__("wrmsr"                                              \
+    : /* no outputs */                                                         \
+    : "c" (reg), "a" (l), "d" (h));                                            \
+}
+
+#else
+
+#define RDMSR(reg, v) 			                                               \
+     __asm__ __volatile__("rdmsr" 	                                           \
+    : "=A" (v) 			                                                       \
+    : "c" (reg))
+
+#define WRMSR(reg, v) 			                                               \
+     __asm__ __volatile__("wrmsr" 	                                           \
+    : /* no outputs */ 				                                           \
+    : "c" (reg), "A" ((UINT64)v))
+
+#endif
+
+
+static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
+{
+	__asm__ __volatile__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "c" (ecx));
+}
+
+//
+// Osd routines
+//
+extern void LogMsg(const char *fmt, ...);
+
+extern void BitSet(unsigned int* addr, int value);
+extern void BitClear(unsigned int* addr, int value);
+extern int BitTest(unsigned int* addr, int value);
+extern int BitTestAndClear(unsigned int* addr, int value);
+extern int BitTestAndSet(unsigned int* addr, int value);
+
+extern int InterlockedIncrement(int *val);
+extern int InterlockedDecrement(int *val);
+extern int InterlockedCompareExchange(int *val, int new, int curr);
+
+extern void Sleep(unsigned long usecs);
+
+extern void* VirtualAllocExec(unsigned int size);
+extern void VirtualFree(void* VirtAddr);
+
+extern void* PageAlloc(unsigned int count);
+extern void PageFree(void* page, unsigned int count);
+
+extern void* MemMapIO(unsigned long phys, unsigned long size);
+extern void MemUnmapIO(void* virt);
+
+extern void* MemAlloc(unsigned int size);
+extern void* MemAllocZeroed(unsigned int size);
+extern void* MemAllocAtomic(unsigned int size);
+extern void MemFree(void* buf);
+extern void MemoryFence(VOID);
+
+extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
+extern void TimerClose(HANDLE hTimer);
+extern int TimerStop(HANDLE hTimer);
+extern void TimerStart(HANDLE hTimer, UINT32 expirationInUs);
+extern SIZE_T GetTickCount(void);
+
+extern HANDLE WaitEventCreate(void);
+extern void WaitEventClose(HANDLE hWait);
+extern void WaitEventSet(HANDLE hWait);
+extern int	WaitEventWait(HANDLE hWait);
+
+// If >0, hWait got signaled. If ==0, timeout. If < 0, error
+extern int	WaitEventWaitEx(HANDLE hWait, UINT32 TimeoutInMs);
+
+extern HANDLE SpinlockCreate(void);
+extern void SpinlockClose(HANDLE hSpin);
+extern void SpinlockAcquire(HANDLE hSpin);
+extern void	SpinlockRelease(HANDLE hSpin);
+
+
+#define GetVirtualAddress Physical2LogicalAddr
+void* Physical2LogicalAddr(ULONG_PTR PhysAddr);
+
+#define GetPhysicalAddress Logical2PhysicalAddr
+ULONG_PTR Logical2PhysicalAddr(PVOID LogicalAddr);
+
+ULONG_PTR Virtual2Physical(PVOID VirtAddr);
+
+void* PageMapVirtualAddress(unsigned long Pfn);
+void PageUnmapVirtualAddress(void* VirtAddr);
+
+
+extern HANDLE WorkQueueCreate(char* name);
+extern void WorkQueueClose(HANDLE hWorkQueue);
+extern int WorkQueueQueueWorkItem(HANDLE hWorkQueue, PFN_WORKITEM_CALLBACK workItem, void* context);
+
+extern void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void* context);
+
+#endif // _OSD_H_
--- /dev/null
+++ b/drivers/staging/hv/include/StorVscApi.h
@@ -0,0 +1,137 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _STORVSC_API_H_
+#define _STORVSC_API_H_
+
+#include "VmbusApi.h"
+
+//
+// Defines
+//
+
+#define STORVSC_RING_BUFFER_SIZE			10*PAGE_SIZE
+#define BLKVSC_RING_BUFFER_SIZE				20*PAGE_SIZE
+
+#define STORVSC_MAX_IO_REQUESTS				64
+
+// In Hyper-V, each port/path/target maps to 1 scsi host adapter.
+// In reality, the path/target is not used (ie always set to 0) so
+// our scsi host adapter essentially has 1 bus with 1 target that contains
+// up to 256 luns.
+
+#define STORVSC_MAX_LUNS_PER_TARGET			64
+#define STORVSC_MAX_TARGETS					1
+#define STORVSC_MAX_CHANNELS				1
+
+
+// Fwd decl
+//
+//struct VMBUS_CHANNEL;
+typedef struct _STORVSC_REQUEST* PSTORVSC_REQUEST;
+
+//
+// Data types
+//
+typedef int (*PFN_ON_IO_REQUEST)(PDEVICE_OBJECT Device, PSTORVSC_REQUEST Request);
+typedef void (*PFN_ON_IO_REQUEST_COMPLTN)(PSTORVSC_REQUEST Request);
+
+typedef int (*PFN_ON_HOST_RESET)(PDEVICE_OBJECT Device);
+typedef void (*PFN_ON_HOST_RESCAN)(PDEVICE_OBJECT Device);
+
+
+// Matches Windows-end
+typedef enum _STORVSC_REQUEST_TYPE{
+	WRITE_TYPE,
+	READ_TYPE,
+	UNKNOWN_TYPE,
+} STORVSC_REQUEST_TYPE;
+
+
+typedef struct _STORVSC_REQUEST {
+	STORVSC_REQUEST_TYPE		Type;
+	UINT32					Host;
+	UINT32					Bus;
+	UINT32					TargetId;
+	UINT32					LunId;
+	UINT8*					Cdb;
+	UINT32					CdbLen;
+	UINT32					Status;
+	UINT32					BytesXfer;
+
+	UCHAR*					SenseBuffer;
+	UINT32					SenseBufferSize;
+
+	PVOID					Context;
+
+	PFN_ON_IO_REQUEST_COMPLTN	OnIOCompletion;
+
+	// This points to the memory after DataBuffer
+	PVOID					Extension;
+
+	MULTIPAGE_BUFFER		DataBuffer;
+} STORVSC_REQUEST;
+
+
+// Represents the block vsc driver
+typedef struct _STORVSC_DRIVER_OBJECT {
+	DRIVER_OBJECT			Base; // Must be the first field
+
+	// Set by caller (in bytes)
+	UINT32					RingBufferSize;
+
+	// Allocate this much private extension for each I/O request
+	UINT32					RequestExtSize;
+
+	// Maximum # of requests in flight per channel/device
+	UINT32					MaxOutstandingRequestsPerChannel;
+
+	// Set by the caller to allow us to re-enumerate the bus on the host
+	PFN_ON_HOST_RESCAN		OnHostRescan;
+
+	// Specific to this driver
+	PFN_ON_IO_REQUEST		OnIORequest;
+	PFN_ON_HOST_RESET		OnHostReset;
+
+} STORVSC_DRIVER_OBJECT;
+
+typedef struct _STORVSC_DEVICE_INFO {
+	ULONG	PortNumber;
+    UCHAR	PathId;
+    UCHAR	TargetId;
+} STORVSC_DEVICE_INFO;
+
+//
+// Interface
+//
+int
+StorVscInitialize(
+	DRIVER_OBJECT	*Driver
+	);
+
+int
+BlkVscInitialize(
+	DRIVER_OBJECT	*Driver
+	);
+#endif // _STORVSC_API_H_
--- /dev/null
+++ b/drivers/staging/hv/include/VmbusApi.h
@@ -0,0 +1,262 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _VMBUS_API_H_
+#define _VMBUS_API_H_
+
+#include "osd.h"
+
+//
+// Defines
+//
+
+#define MAX_PAGE_BUFFER_COUNT				16
+#define MAX_MULTIPAGE_BUFFER_COUNT			32 // 128K
+
+
+//
+// Fwd declarations
+//
+typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
+typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT;
+
+//
+// Data types
+//
+
+#pragma pack(push,1)
+
+// Single-page buffer
+typedef struct _PAGE_BUFFER {
+	UINT32	Length;
+	UINT32	Offset;
+	UINT64	Pfn;
+} PAGE_BUFFER;
+
+// Multiple-page buffer
+typedef struct _MULTIPAGE_BUFFER {
+	// Length and Offset determines the # of pfns in the array
+	UINT32	Length;
+	UINT32	Offset;
+	UINT64	PfnArray[MAX_MULTIPAGE_BUFFER_COUNT];
+}MULTIPAGE_BUFFER;
+
+//0x18 includes the proprietary packet header
+#define MAX_PAGE_BUFFER_PACKET			(0x18 + (sizeof(PAGE_BUFFER) * MAX_PAGE_BUFFER_COUNT))
+#define MAX_MULTIPAGE_BUFFER_PACKET		(0x18 + sizeof(MULTIPAGE_BUFFER))
+
+
+#pragma pack(pop)
+
+// All drivers
+typedef int (*PFN_ON_DEVICEADD)(PDEVICE_OBJECT Device, void* AdditionalInfo);
+typedef int (*PFN_ON_DEVICEREMOVE)(PDEVICE_OBJECT Device);
+typedef char** (*PFN_ON_GETDEVICEIDS)(void);
+typedef void (*PFN_ON_CLEANUP)(PDRIVER_OBJECT Driver);
+
+// Vmbus extensions
+//typedef int (*PFN_ON_MATCH)(PDEVICE_OBJECT dev, PDRIVER_OBJECT drv);
+//typedef int (*PFN_ON_PROBE)(PDEVICE_OBJECT dev);
+typedef int	(*PFN_ON_ISR)(PDRIVER_OBJECT drv);
+typedef void (*PFN_ON_DPC)(PDRIVER_OBJECT drv);
+typedef void (*PFN_GET_CHANNEL_OFFERS)(void);
+
+typedef PDEVICE_OBJECT (*PFN_ON_CHILDDEVICE_CREATE)(GUID DeviceType, GUID DeviceInstance, void *Context);
+typedef void (*PFN_ON_CHILDDEVICE_DESTROY)(PDEVICE_OBJECT Device);
+typedef int (*PFN_ON_CHILDDEVICE_ADD)(PDEVICE_OBJECT RootDevice, PDEVICE_OBJECT ChildDevice);
+typedef void (*PFN_ON_CHILDDEVICE_REMOVE)(PDEVICE_OBJECT Device);
+
+// Vmbus channel interface
+typedef void (*VMBUS_CHANNEL_CALLBACK)(PVOID context);
+
+typedef int	(*VMBUS_CHANNEL_OPEN)(
+	PDEVICE_OBJECT		Device,
+	UINT32				SendBufferSize,
+	UINT32				RecvRingBufferSize,
+	PVOID				UserData,
+	UINT32				UserDataLen,
+	VMBUS_CHANNEL_CALLBACK ChannelCallback,
+	PVOID				Context
+	);
+
+typedef void (*VMBUS_CHANNEL_CLOSE)(
+	PDEVICE_OBJECT		Device
+	);
+
+typedef int	(*VMBUS_CHANNEL_SEND_PACKET)(
+	PDEVICE_OBJECT		Device,
+	const PVOID			Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId,
+	UINT32				Type,
+	UINT32				Flags
+);
+
+typedef int	(*VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER)(
+	PDEVICE_OBJECT		Device,
+	PAGE_BUFFER			PageBuffers[],
+	UINT32				PageCount,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId
+	);
+
+typedef int	(*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER)(
+	PDEVICE_OBJECT		Device,
+	MULTIPAGE_BUFFER	*MultiPageBuffer,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId
+);
+
+typedef int	(*VMBUS_CHANNEL_RECV_PACKET)(
+	PDEVICE_OBJECT		Device,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				BufferActualLen,
+	UINT64*				RequestId
+	);
+
+typedef int	(*VMBUS_CHANNEL_RECV_PACKET_PAW)(
+	PDEVICE_OBJECT		Device,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				BufferActualLen,
+	UINT64*				RequestId
+	);
+
+typedef int	(*VMBUS_CHANNEL_ESTABLISH_GPADL)(
+	PDEVICE_OBJECT		Device,
+	PVOID				Buffer,	// from kmalloc()
+	UINT32				BufferLen,		// page-size multiple
+	UINT32*				GpadlHandle
+	);
+
+typedef int	(*VMBUS_CHANNEL_TEARDOWN_GPADL)(
+	PDEVICE_OBJECT		Device,
+	UINT32				GpadlHandle
+	);
+
+
+typedef struct _PORT_INFO {
+	UINT32		InterruptMask;
+	UINT32		ReadIndex;
+	UINT32		WriteIndex;
+	UINT32		BytesAvailToRead;
+	UINT32		BytesAvailToWrite;
+} PORT_INFO;
+
+
+typedef struct _DEVICE_INFO {
+	UINT32		ChannelId;
+	UINT32		ChannelState;
+	GUID		ChannelType;
+	GUID		ChannelInstance;
+
+	UINT32						MonitorId;
+	UINT32						ServerMonitorPending;
+	UINT32						ServerMonitorLatency;
+	UINT32						ServerMonitorConnectionId;
+	UINT32						ClientMonitorPending;
+	UINT32						ClientMonitorLatency;
+	UINT32						ClientMonitorConnectionId;
+
+	PORT_INFO	Inbound;
+	PORT_INFO	Outbound;
+} DEVICE_INFO;
+
+typedef void (*VMBUS_GET_CHANNEL_INFO)(PDEVICE_OBJECT Device, DEVICE_INFO* DeviceInfo);
+
+typedef struct _VMBUS_CHANNEL_INTERFACE {
+	VMBUS_CHANNEL_OPEN							Open;
+	VMBUS_CHANNEL_CLOSE							Close;
+	VMBUS_CHANNEL_SEND_PACKET					SendPacket;
+	VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER		SendPacketPageBuffer;
+	VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER	SendPacketMultiPageBuffer;
+	VMBUS_CHANNEL_RECV_PACKET					RecvPacket;
+	VMBUS_CHANNEL_RECV_PACKET_PAW				RecvPacketRaw;
+	VMBUS_CHANNEL_ESTABLISH_GPADL				EstablishGpadl;
+	VMBUS_CHANNEL_TEARDOWN_GPADL				TeardownGpadl;
+	VMBUS_GET_CHANNEL_INFO						GetInfo;
+} VMBUS_CHANNEL_INTERFACE;
+
+typedef void (*VMBUS_GET_CHANNEL_INTERFACE)(VMBUS_CHANNEL_INTERFACE *Interface);
+
+// Base driver object
+typedef struct _DRIVER_OBJECT {
+	const char*				name;
+	GUID					deviceType; // the device type supported by this driver
+
+	PFN_ON_DEVICEADD		OnDeviceAdd;
+	PFN_ON_DEVICEREMOVE		OnDeviceRemove;
+	PFN_ON_GETDEVICEIDS		OnGetDeviceIds; // device ids supported by this driver
+	PFN_ON_CLEANUP			OnCleanup;
+
+	VMBUS_CHANNEL_INTERFACE VmbusChannelInterface;
+} DRIVER_OBJECT;
+
+
+// Base device object
+typedef struct _DEVICE_OBJECT {
+	DRIVER_OBJECT*		Driver;		// the driver for this device
+	char				name[64];
+	GUID				deviceType; // the device type id of this device
+	GUID				deviceInstance; // the device instance id of this device
+	void*				context;
+	void*				Extension;		// Device extension;
+} DEVICE_OBJECT;
+
+
+// Vmbus driver object
+typedef struct _VMBUS_DRIVER_OBJECT {
+	DRIVER_OBJECT		Base; // !! Must be the 1st field !!
+
+	// Set by the caller
+	PFN_ON_CHILDDEVICE_CREATE	OnChildDeviceCreate;
+	PFN_ON_CHILDDEVICE_DESTROY	OnChildDeviceDestroy;
+	PFN_ON_CHILDDEVICE_ADD		OnChildDeviceAdd;
+	PFN_ON_CHILDDEVICE_REMOVE	OnChildDeviceRemove;
+
+	// Set by the callee
+	//PFN_ON_MATCH		OnMatch;
+	//PFN_ON_PROBE		OnProbe;
+	PFN_ON_ISR				OnIsr;
+	PFN_ON_DPC				OnMsgDpc;
+	PFN_ON_DPC				OnEventDpc;
+	PFN_GET_CHANNEL_OFFERS	GetChannelOffers;
+
+	VMBUS_GET_CHANNEL_INTERFACE GetChannelInterface;
+	VMBUS_GET_CHANNEL_INFO		GetChannelInfo;
+} VMBUS_DRIVER_OBJECT;
+
+
+//
+// Interface
+//
+int
+VmbusInitialize(
+	DRIVER_OBJECT* drv
+	);
+
+#endif // _VMBUS_API_H_
--- /dev/null
+++ b/drivers/staging/hv/include/vmbus.h
@@ -0,0 +1,111 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _VMBUS_H_
+#define _VMBUS_H_
+
+#include <linux/device.h>
+
+#include "VmbusApi.h"
+
+//
+// Data types
+//
+
+typedef int (*PFN_DRIVERINITIALIZE)(DRIVER_OBJECT *drv);
+typedef int (*PFN_DRIVEREXIT)(DRIVER_OBJECT *drv);
+
+struct driver_context {
+	GUID					class_id;
+
+	struct device_driver	driver;
+
+	// Use these methods instead of the struct device_driver so 2.6 kernel stops complaining
+	int (*probe)(struct device *);
+	int (*remove)(struct device *);
+	void (*shutdown)(struct device *);
+};
+
+struct device_context {
+	struct work_struct              probe_failed_work_item;
+	GUID					class_id;
+	GUID					device_id;
+	int						probe_error;
+	struct device			device;
+	DEVICE_OBJECT			device_obj;
+};
+
+
+//
+// Global
+//
+
+//
+// Inlines
+//
+static inline struct device_context *to_device_context(DEVICE_OBJECT *device_obj)
+{
+	return container_of(device_obj, struct device_context, device_obj);
+}
+
+static inline struct device_context *device_to_device_context(struct device *device)
+{
+	return container_of(device, struct device_context, device);
+}
+
+static inline struct driver_context *driver_to_driver_context(struct device_driver *driver)
+{
+	return container_of(driver, struct driver_context, driver);
+}
+
+#if defined(KERNEL_2_6_5)
+static inline void* kzalloc(int size, int flags)
+{
+	void *p;
+	p = kmalloc(size, flags);
+	if (p) memset(p, 0, size);
+
+	return p;
+}
+#endif // KERNEL_2_6_5
+
+//
+// Vmbus interface
+//
+void
+vmbus_child_driver_register(
+	struct driver_context* driver_ctx
+	);
+
+void
+vmbus_child_driver_unregister(
+	struct driver_context *driver_ctx
+	);
+
+void
+vmbus_get_interface(
+	VMBUS_CHANNEL_INTERFACE *interface
+	);
+
+#endif // _VMBUS_H_

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 03/54] Staging: hv: add the Hyper-V virtual bus
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (2 preceding siblings ...)
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-virtual-bus.patch --]
[-- Type: text/plain, Size: 175325 bytes --]

From: Hank Janssen <hjanssen@microsoft.com>

This is the virtual bus that all of the Linux Hyper-V drivers use.

Signed-off-by: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Channel.c          | 1199 +++++++++++++++++++++++++++++++++
 drivers/staging/hv/Channel.h          |  157 ++++
 drivers/staging/hv/ChannelInterface.c |  222 ++++++
 drivers/staging/hv/ChannelInterface.h |   41 +
 drivers/staging/hv/ChannelMgmt.c      |  826 ++++++++++++++++++++++
 drivers/staging/hv/ChannelMgmt.h      |  156 ++++
 drivers/staging/hv/Connection.c       |  432 +++++++++++
 drivers/staging/hv/Hv.c               |  672 ++++++++++++++++++
 drivers/staging/hv/Hv.h               |  184 +++++
 drivers/staging/hv/RingBuffer.c       |  630 +++++++++++++++++
 drivers/staging/hv/RingBuffer.h       |  123 +++
 drivers/staging/hv/Sources.c          |   31 
 drivers/staging/hv/VersionInfo.h      |   29 
 drivers/staging/hv/Vmbus.c            |  508 ++++++++++++++
 drivers/staging/hv/VmbusPrivate.h     |  170 ++++
 drivers/staging/hv/osd.c              |  500 +++++++++++++
 drivers/staging/hv/vmbus_drv.c        | 1228 ++++++++++++++++++++++++++++++++++
 17 files changed, 7108 insertions(+)

--- /dev/null
+++ b/drivers/staging/hv/Channel.c
@@ -0,0 +1,1199 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "osd.h"
+#include "logging.h"
+
+#include "VmbusPrivate.h"
+
+//
+// Internal routines
+//
+static int
+VmbusChannelCreateGpadlHeader(
+	PVOID					Kbuffer,	// must be phys and virt contiguous
+	UINT32					Size,		// page-size multiple
+	VMBUS_CHANNEL_MSGINFO	**msgInfo,
+	UINT32					*MessageCount
+	);
+
+static void
+DumpVmbusChannel(
+	VMBUS_CHANNEL			*Channel
+	);
+
+
+static void
+VmbusChannelSetEvent(
+	VMBUS_CHANNEL			*Channel
+	);
+
+
+#if 0
+static void
+DumpMonitorPage(
+	HV_MONITOR_PAGE *MonitorPage
+	)
+{
+	int i=0;
+	int j=0;
+
+	DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d", MonitorPage, MonitorPage->TriggerState);
+
+	for (i=0; i<4; i++)
+	{
+		DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, MonitorPage->TriggerGroup[i].AsUINT64);
+	}
+
+	for (i=0; i<4; i++)
+	{
+		for (j=0; j<32; j++)
+		{
+			DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, MonitorPage->Latency[i][j]);
+		}
+	}
+	for (i=0; i<4; i++)
+	{
+		for (j=0; j<32; j++)
+		{
+			DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].ConnectionId.AsUINT32);
+			DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].FlagNumber);
+
+		}
+	}
+}
+#endif
+
+/*++
+
+Name:
+	VmbusChannelSetEvent()
+
+Description:
+	Trigger an event notification on the specified channel.
+
+--*/
+static void
+VmbusChannelSetEvent(
+	VMBUS_CHANNEL			*Channel
+	)
+{
+	HV_MONITOR_PAGE *monitorPage;
+
+	DPRINT_ENTER(VMBUS);
+
+	if (Channel->OfferMsg.MonitorAllocated)
+	{
+		// Each UINT32 represents 32 channels
+		BitSet((UINT32*)gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5), Channel->OfferMsg.ChildRelId & 31);
+
+		monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages;
+		monitorPage++; // Get the child to parent monitor page
+
+		BitSet((UINT32*) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending, Channel->MonitorBit);
+	}
+	else
+	{
+		VmbusSetEvent(Channel->OfferMsg.ChildRelId);
+	}
+
+	DPRINT_EXIT(VMBUS);
+}
+
+#if 0
+static void
+VmbusChannelClearEvent(
+	VMBUS_CHANNEL			*Channel
+	)
+{
+	HV_MONITOR_PAGE *monitorPage;
+
+	DPRINT_ENTER(VMBUS);
+
+	if (Channel->OfferMsg.MonitorAllocated)
+	{
+		// Each UINT32 represents 32 channels
+		BitClear((UINT32*)gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5), Channel->OfferMsg.ChildRelId & 31);
+
+		monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages;
+		monitorPage++; // Get the child to parent monitor page
+
+		BitClear((UINT32*) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending, Channel->MonitorBit);
+	}
+
+	DPRINT_EXIT(VMBUS);
+}
+
+#endif
+/*++;
+
+Name:
+	VmbusChannelGetDebugInfo()
+
+Description:
+	Retrieve various channel debug info
+
+--*/
+void
+VmbusChannelGetDebugInfo(
+	VMBUS_CHANNEL				*Channel,
+	VMBUS_CHANNEL_DEBUG_INFO	*DebugInfo
+	)
+{
+	HV_MONITOR_PAGE *monitorPage;
+    UINT8 monitorGroup    = (UINT8)Channel->OfferMsg.MonitorId / 32;
+    UINT8 monitorOffset   = (UINT8)Channel->OfferMsg.MonitorId % 32;
+	//UINT32 monitorBit	= 1 << monitorOffset;
+
+	DebugInfo->RelId = Channel->OfferMsg.ChildRelId;
+	DebugInfo->State = Channel->State;
+	memcpy(&DebugInfo->InterfaceType, &Channel->OfferMsg.Offer.InterfaceType, sizeof(GUID));
+	memcpy(&DebugInfo->InterfaceInstance, &Channel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID));
+
+	monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages;
+
+	DebugInfo->MonitorId = Channel->OfferMsg.MonitorId;
+
+	DebugInfo->ServerMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending;
+	DebugInfo->ServerMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset];
+	DebugInfo->ServerMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id;
+
+	monitorPage++;
+
+	DebugInfo->ClientMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending;
+	DebugInfo->ClientMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset];
+	DebugInfo->ClientMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id;
+
+	RingBufferGetDebugInfo(&Channel->Inbound, &DebugInfo->Inbound);
+	RingBufferGetDebugInfo(&Channel->Outbound, &DebugInfo->Outbound);
+}
+
+
+/*++;
+
+Name:
+	VmbusChannelOpen()
+
+Description:
+	Open the specified channel.
+
+--*/
+int
+VmbusChannelOpen(
+	VMBUS_CHANNEL			*NewChannel,
+	UINT32					SendRingBufferSize,
+	UINT32					RecvRingBufferSize,
+	PVOID					UserData,
+	UINT32					UserDataLen,
+	PFN_CHANNEL_CALLBACK	pfnOnChannelCallback,
+	PVOID					Context
+	)
+{
+	int ret=0;
+	VMBUS_CHANNEL_OPEN_CHANNEL* openMsg;
+	VMBUS_CHANNEL_MSGINFO* openInfo;
+	void *in, *out;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Aligned to page size
+	ASSERT(!(SendRingBufferSize & (PAGE_SIZE -1)));
+	ASSERT(!(RecvRingBufferSize & (PAGE_SIZE -1)));
+
+	NewChannel->OnChannelCallback = pfnOnChannelCallback;
+	NewChannel->ChannelCallbackContext = Context;
+
+	// Allocate the ring buffer
+	out = PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT);
+	//out = MemAllocZeroed(sendRingBufferSize + recvRingBufferSize);
+	ASSERT(out);
+	ASSERT(((ULONG_PTR)out & (PAGE_SIZE-1)) == 0);
+
+	in = (void*)((ULONG_PTR)out + SendRingBufferSize);
+
+	NewChannel->RingBufferPages = out;
+	NewChannel->RingBufferPageCount = (SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT;
+
+	RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize);
+
+	RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize);
+
+	// Establish the gpadl for the ring buffer
+	DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", NewChannel);
+
+	NewChannel->RingBufferGpadlHandle = 0;
+
+	ret = VmbusChannelEstablishGpadl(NewChannel,
+		NewChannel->Outbound.RingBuffer,
+		SendRingBufferSize + RecvRingBufferSize,
+		&NewChannel->RingBufferGpadlHandle);
+
+	DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p size %d recv ring %p size %d, downstreamoffset %d>",
+		NewChannel,
+		NewChannel->OfferMsg.ChildRelId,
+		NewChannel->RingBufferGpadlHandle,
+		NewChannel->Outbound.RingBuffer,
+		NewChannel->Outbound.RingSize,
+		NewChannel->Inbound.RingBuffer,
+		NewChannel->Inbound.RingSize,
+		SendRingBufferSize);
+
+	// Create and init the channel open message
+	openInfo =
+		(VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_OPEN_CHANNEL));
+	ASSERT(openInfo != NULL);
+
+	openInfo->WaitEvent = WaitEventCreate();
+
+	openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL*)openInfo->Msg;
+	openMsg->Header.MessageType				= ChannelMessageOpenChannel;
+	openMsg->OpenId							= NewChannel->OfferMsg.ChildRelId; // FIXME
+    openMsg->ChildRelId						= NewChannel->OfferMsg.ChildRelId;
+    openMsg->RingBufferGpadlHandle			= NewChannel->RingBufferGpadlHandle;
+    ASSERT(openMsg->RingBufferGpadlHandle);
+    openMsg->DownstreamRingBufferPageOffset		= SendRingBufferSize >> PAGE_SHIFT;
+    openMsg->ServerContextAreaGpadlHandle	= 0; // TODO
+
+	ASSERT(UserDataLen <= MAX_USER_DEFINED_BYTES);
+	if (UserDataLen)
+	{
+		memcpy(openMsg->UserData, UserData, UserDataLen);
+	}
+
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &openInfo->MsgListEntry);
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	DPRINT_DBG(VMBUS, "Sending channel open msg...");
+
+	ret = VmbusPostMessage(openMsg, sizeof(VMBUS_CHANNEL_OPEN_CHANNEL));
+	if (ret != 0)
+	{
+		DPRINT_ERR(VMBUS, "unable to open channel - %d", ret);
+		goto Cleanup;
+	}
+
+	// FIXME: Need to time-out here
+	WaitEventWait(openInfo->WaitEvent);
+
+	if (openInfo->Response.OpenResult.Status == 0)
+	{
+		DPRINT_INFO(VMBUS, "channel <%p> open success!!", NewChannel);
+	}
+	else
+	{
+		DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", NewChannel, openInfo->Response.OpenResult.Status);
+	}
+
+Cleanup:
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	REMOVE_ENTRY_LIST(&openInfo->MsgListEntry);
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	WaitEventClose(openInfo->WaitEvent);
+	MemFree(openInfo);
+
+	DPRINT_EXIT(VMBUS);
+
+	return 0;
+}
+
+/*++;
+
+Name:
+	DumpGpadlBody()
+
+Description:
+	Dump the gpadl body message to the console for debugging purposes.
+
+--*/
+static void DumpGpadlBody(
+	VMBUS_CHANNEL_GPADL_BODY	*Gpadl,
+	UINT32						Len)
+{
+	int i=0;
+	int pfnCount=0;
+
+	pfnCount = (Len - sizeof(VMBUS_CHANNEL_GPADL_BODY))/ sizeof(UINT64);
+	DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount);
+
+	for (i=0; i< pfnCount; i++)
+	{
+		DPRINT_DBG(VMBUS, "gpadl body  - %d) pfn %llu", i, Gpadl->Pfn[i]);
+	}
+}
+
+
+/*++;
+
+Name:
+	DumpGpadlHeader()
+
+Description:
+	Dump the gpadl header message to the console for debugging purposes.
+
+--*/
+static void DumpGpadlHeader(
+	VMBUS_CHANNEL_GPADL_HEADER	*Gpadl
+	)
+{
+	int i=0,j=0;
+	int pageCount=0;
+
+
+	DPRINT_DBG(VMBUS, "gpadl header - relid %d, range count %d, range buflen %d",
+				Gpadl->ChildRelId,
+				Gpadl->RangeCount,
+				Gpadl->RangeBufLen);
+	for (i=0; i< Gpadl->RangeCount; i++)
+	{
+		pageCount = Gpadl->Range[i].ByteCount >> PAGE_SHIFT;
+		pageCount = (pageCount > 26)? 26 : pageCount;
+
+		DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d page count %d",
+			i, Gpadl->Range[i].ByteCount, Gpadl->Range[i].ByteOffset, pageCount);
+
+		for (j=0; j< pageCount; j++)
+		{
+			DPRINT_DBG(VMBUS, "%d) pfn %llu", j, Gpadl->Range[i].PfnArray[j]);
+		}
+	}
+}
+
+/*++;
+
+Name:
+	VmbusChannelCreateGpadlHeader()
+
+Description:
+	Creates a gpadl for the specified buffer
+
+--*/
+static int
+VmbusChannelCreateGpadlHeader(
+	PVOID					Kbuffer,	// from kmalloc()
+	UINT32					Size,		// page-size multiple
+	VMBUS_CHANNEL_MSGINFO	**MsgInfo,
+	UINT32					*MessageCount)
+{
+	int i;
+	int pageCount;
+    unsigned long long pfn;
+	VMBUS_CHANNEL_GPADL_HEADER* gpaHeader;
+	VMBUS_CHANNEL_GPADL_BODY* gpadlBody;
+	VMBUS_CHANNEL_MSGINFO* msgHeader;
+	VMBUS_CHANNEL_MSGINFO* msgBody;
+	UINT32				msgSize;
+
+	int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize;
+
+	//ASSERT( (kbuffer & (PAGE_SIZE-1)) == 0);
+	ASSERT( (Size & (PAGE_SIZE-1)) == 0);
+
+	pageCount = Size >> PAGE_SHIFT;
+	pfn = GetPhysicalAddress(Kbuffer) >> PAGE_SHIFT;
+
+	// do we need a gpadl body msg
+	pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_HEADER) - sizeof(GPA_RANGE);
+	pfnCount = pfnSize / sizeof(UINT64);
+
+	if (pageCount > pfnCount) // we need a gpadl body
+	{
+		// fill in the header
+		msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pfnCount*sizeof(UINT64);
+		msgHeader =  MemAllocZeroed(msgSize);
+
+		INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList);
+		msgHeader->MessageSize=msgSize;
+
+		gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg;
+		gpaHeader->RangeCount = 1;
+		gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(UINT64);
+		gpaHeader->Range[0].ByteOffset = 0;
+		gpaHeader->Range[0].ByteCount = Size;
+		for (i=0; i<pfnCount; i++)
+		{
+			gpaHeader->Range[0].PfnArray[i] = pfn+i;
+		}
+		*MsgInfo = msgHeader;
+		*MessageCount = 1;
+
+		pfnSum = pfnCount;
+		pfnLeft = pageCount - pfnCount;
+
+		// how many pfns can we fit
+		pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_BODY);
+		pfnCount = pfnSize / sizeof(UINT64);
+
+		// fill in the body
+		while (pfnLeft)
+		{
+			if (pfnLeft > pfnCount)
+			{
+				pfnCurr = pfnCount;
+			}
+			else
+			{
+				pfnCurr = pfnLeft;
+			}
+
+			msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_BODY) + pfnCurr*sizeof(UINT64);
+			msgBody =  MemAllocZeroed(msgSize);
+			ASSERT(msgBody);
+			msgBody->MessageSize = msgSize;
+			(*MessageCount)++;
+			gpadlBody = (VMBUS_CHANNEL_GPADL_BODY*)msgBody->Msg;
+
+			// FIXME: Gpadl is UINT32 and we are using a pointer which could be 64-bit
+			//gpadlBody->Gpadl = kbuffer;
+			for (i=0; i<pfnCurr; i++)
+			{
+				gpadlBody->Pfn[i] = pfn + pfnSum + i;
+			}
+
+			// add to msg header
+			INSERT_TAIL_LIST(&msgHeader->SubMsgList, &msgBody->MsgListEntry);
+			pfnSum += pfnCurr;
+			pfnLeft -= pfnCurr;
+		}
+	}
+	else
+	{
+		// everything fits in a header
+		msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pageCount*sizeof(UINT64);
+		msgHeader =  MemAllocZeroed(msgSize);
+		msgHeader->MessageSize=msgSize;
+
+		gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg;
+		gpaHeader->RangeCount = 1;
+		gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(UINT64);
+		gpaHeader->Range[0].ByteOffset = 0;
+		gpaHeader->Range[0].ByteCount = Size;
+		for (i=0; i<pageCount; i++)
+		{
+			gpaHeader->Range[0].PfnArray[i] = pfn+i;
+		}
+
+		*MsgInfo = msgHeader;
+		*MessageCount = 1;
+	}
+
+	return 0;
+}
+
+
+/*++;
+
+Name:
+	VmbusChannelEstablishGpadl()
+
+Description:
+	Estabish a GPADL for the specified buffer
+
+--*/
+int
+VmbusChannelEstablishGpadl(
+	VMBUS_CHANNEL	*Channel,
+	PVOID			Kbuffer,	// from kmalloc()
+	UINT32			Size,		// page-size multiple
+	UINT32			*GpadlHandle
+	)
+{
+	int ret=0;
+	VMBUS_CHANNEL_GPADL_HEADER* gpadlMsg;
+	VMBUS_CHANNEL_GPADL_BODY* gpadlBody;
+	//VMBUS_CHANNEL_GPADL_CREATED* gpadlCreated;
+
+	VMBUS_CHANNEL_MSGINFO *msgInfo;
+	VMBUS_CHANNEL_MSGINFO *subMsgInfo;
+
+	UINT32 msgCount;
+	LIST_ENTRY* anchor;
+	LIST_ENTRY* curr;
+	UINT32 nextGpadlHandle;
+
+	DPRINT_ENTER(VMBUS);
+
+	nextGpadlHandle = gVmbusConnection.NextGpadlHandle;
+	InterlockedIncrement((int*)&gVmbusConnection.NextGpadlHandle);
+
+	VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
+	ASSERT(msgInfo != NULL);
+	ASSERT(msgCount >0);
+
+	msgInfo->WaitEvent = WaitEventCreate();
+	gpadlMsg = (VMBUS_CHANNEL_GPADL_HEADER*)msgInfo->Msg;
+	gpadlMsg->Header.MessageType = ChannelMessageGpadlHeader;
+	gpadlMsg->ChildRelId = Channel->OfferMsg.ChildRelId;
+	gpadlMsg->Gpadl = nextGpadlHandle;
+
+	DumpGpadlHeader(gpadlMsg);
+
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry);
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", Kbuffer, Size, msgCount);
+
+	DPRINT_DBG(VMBUS, "Sending GPADL Header - len %d", msgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
+
+	ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
+	if (ret != 0)
+	{
+		DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret);
+		goto Cleanup;
+	}
+
+	if (msgCount>1)
+	{
+		ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList)
+		{
+			subMsgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
+			gpadlBody = (VMBUS_CHANNEL_GPADL_BODY*)subMsgInfo->Msg;
+
+			gpadlBody->Header.MessageType = ChannelMessageGpadlBody;
+			gpadlBody->Gpadl = nextGpadlHandle;
+
+			DPRINT_DBG(VMBUS, "Sending GPADL Body - len %d", subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
+
+			DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
+			ret = VmbusPostMessage(gpadlBody, subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO));
+			ASSERT(ret == 0);
+		}
+	}
+	WaitEventWait(msgInfo->WaitEvent);
+
+	// At this point, we received the gpadl created msg
+	DPRINT_DBG(VMBUS, "Received GPADL created (relid %d, status %d handle %x)",
+		Channel->OfferMsg.ChildRelId,
+		msgInfo->Response.GpadlCreated.CreationStatus,
+		gpadlMsg->Gpadl);
+
+	*GpadlHandle = gpadlMsg->Gpadl;
+
+Cleanup:
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	WaitEventClose(msgInfo->WaitEvent);
+	MemFree(msgInfo);
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+
+/*++;
+
+Name:
+	VmbusChannelTeardownGpadl()
+
+Description:
+	Teardown the specified GPADL handle
+
+--*/
+int
+VmbusChannelTeardownGpadl(
+	VMBUS_CHANNEL	*Channel,
+	UINT32			GpadlHandle
+	)
+{
+	int ret=0;
+	VMBUS_CHANNEL_GPADL_TEARDOWN *msg;
+	VMBUS_CHANNEL_MSGINFO* info;
+
+	DPRINT_ENTER(VMBUS);
+
+	ASSERT(GpadlHandle != 0);
+
+	info =
+		(VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN));
+	ASSERT(info != NULL);
+
+	info->WaitEvent = WaitEventCreate();
+
+	msg = (VMBUS_CHANNEL_GPADL_TEARDOWN*)info->Msg;
+
+	msg->Header.MessageType = ChannelMessageGpadlTeardown;
+    msg->ChildRelId  = Channel->OfferMsg.ChildRelId;
+    msg->Gpadl       = GpadlHandle;
+
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &info->MsgListEntry);
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN));
+	if (ret != 0)
+	{
+		// TODO:
+	}
+
+	WaitEventWait(info->WaitEvent);
+
+	// Received a torndown response
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	REMOVE_ENTRY_LIST(&info->MsgListEntry);
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	WaitEventClose(info->WaitEvent);
+	MemFree(info);
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	VmbusChannelClose()
+
+Description:
+	Close the specified channel
+
+--*/
+VOID
+VmbusChannelClose(
+	VMBUS_CHANNEL	*Channel
+	)
+{
+	int ret=0;
+	VMBUS_CHANNEL_CLOSE_CHANNEL* msg;
+	VMBUS_CHANNEL_MSGINFO* info;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Stop callback and cancel the timer asap
+	Channel->OnChannelCallback = NULL;
+	TimerStop(Channel->PollTimer);
+
+	// Send a closing message
+	info =
+		(VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL));
+	ASSERT(info != NULL);
+
+	//info->waitEvent = WaitEventCreate();
+
+	msg = (VMBUS_CHANNEL_CLOSE_CHANNEL*)info->Msg;
+	msg->Header.MessageType				= ChannelMessageCloseChannel;
+    msg->ChildRelId						= Channel->OfferMsg.ChildRelId;
+
+	ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL));
+	if (ret != 0)
+	{
+		// TODO:
+	}
+
+	// Tear down the gpadl for the channel's ring buffer
+	if (Channel->RingBufferGpadlHandle)
+	{
+		VmbusChannelTeardownGpadl(Channel, Channel->RingBufferGpadlHandle);
+	}
+
+	// TODO: Send a msg to release the childRelId
+
+	// Cleanup the ring buffers for this channel
+	RingBufferCleanup(&Channel->Outbound);
+	RingBufferCleanup(&Channel->Inbound);
+
+	PageFree(Channel->RingBufferPages, Channel->RingBufferPageCount);
+
+	MemFree(info);
+
+	// If we are closing the channel during an error path in opening the channel, don't free the channel
+	// since the caller will free the channel
+	if (Channel->State == CHANNEL_OPEN_STATE)
+	{
+		SpinlockAcquire(gVmbusConnection.ChannelLock);
+		REMOVE_ENTRY_LIST(&Channel->ListEntry);
+		SpinlockRelease(gVmbusConnection.ChannelLock);
+
+		FreeVmbusChannel(Channel);
+	}
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelSendPacket()
+
+Description:
+	Send the specified buffer on the given channel
+
+--*/
+int
+VmbusChannelSendPacket(
+	VMBUS_CHANNEL		*Channel,
+	const PVOID			Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId,
+	VMBUS_PACKET_TYPE	Type,
+	UINT32				Flags
+)
+{
+	int ret=0;
+	VMPACKET_DESCRIPTOR desc;
+	UINT32 packetLen = sizeof(VMPACKET_DESCRIPTOR) + BufferLen;
+	UINT32 packetLenAligned = ALIGN_UP(packetLen, sizeof(UINT64));
+	SG_BUFFER_LIST bufferList[3];
+	UINT64 alignedData=0;
+
+	DPRINT_ENTER(VMBUS);
+	DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", Channel, Buffer, BufferLen);
+
+	DumpVmbusChannel(Channel);
+
+	ASSERT((packetLenAligned - packetLen) < sizeof(UINT64));
+
+	// Setup the descriptor
+	desc.Type = Type;//VmbusPacketTypeDataInBand;
+	desc.Flags = Flags;//VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
+    desc.DataOffset8 = sizeof(VMPACKET_DESCRIPTOR) >> 3; // in 8-bytes granularity
+    desc.Length8 = (UINT16)(packetLenAligned >> 3);
+    desc.TransactionId = RequestId;
+
+	bufferList[0].Data = &desc;
+	bufferList[0].Length = sizeof(VMPACKET_DESCRIPTOR);
+
+	bufferList[1].Data = Buffer;
+	bufferList[1].Length = BufferLen;
+
+	bufferList[2].Data = &alignedData;
+	bufferList[2].Length = packetLenAligned - packetLen;
+
+	ret = RingBufferWrite(
+		&Channel->Outbound,
+		bufferList,
+		3);
+
+	// TODO: We should determine if this is optional
+	if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
+	{
+		VmbusChannelSetEvent(Channel);
+	}
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	VmbusChannelSendPacketPageBuffer()
+
+Description:
+	Send a range of single-page buffer packets using a GPADL Direct packet type.
+
+--*/
+int
+VmbusChannelSendPacketPageBuffer(
+	VMBUS_CHANNEL		*Channel,
+	PAGE_BUFFER			PageBuffers[],
+	UINT32				PageCount,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId
+)
+{
+	int ret=0;
+	int i=0;
+	VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc;
+	UINT32 descSize;
+	UINT32 packetLen;
+	UINT32 packetLenAligned;
+	SG_BUFFER_LIST bufferList[3];
+	UINT64 alignedData=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	ASSERT(PageCount <= MAX_PAGE_BUFFER_COUNT);
+
+	DumpVmbusChannel(Channel);
+
+	// Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the largest size we support
+	descSize = sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - ((MAX_PAGE_BUFFER_COUNT - PageCount)*sizeof(PAGE_BUFFER));
+	packetLen = descSize + BufferLen;
+	packetLenAligned = ALIGN_UP(packetLen, sizeof(UINT64));
+
+	ASSERT((packetLenAligned - packetLen) < sizeof(UINT64));
+
+	// Setup the descriptor
+	desc.Type = VmbusPacketTypeDataUsingGpaDirect;
+	desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
+    desc.DataOffset8 = descSize >> 3; // in 8-bytes grandularity
+    desc.Length8 = (UINT16)(packetLenAligned >> 3);
+    desc.TransactionId = RequestId;
+	desc.RangeCount = PageCount;
+
+	for (i=0; i<PageCount; i++)
+	{
+		desc.Range[i].Length = PageBuffers[i].Length;
+		desc.Range[i].Offset = PageBuffers[i].Offset;
+		desc.Range[i].Pfn	 = PageBuffers[i].Pfn;
+	}
+
+	bufferList[0].Data = &desc;
+	bufferList[0].Length = descSize;
+
+	bufferList[1].Data = Buffer;
+	bufferList[1].Length = BufferLen;
+
+	bufferList[2].Data = &alignedData;
+	bufferList[2].Length = packetLenAligned - packetLen;
+
+	ret = RingBufferWrite(
+		&Channel->Outbound,
+		bufferList,
+		3);
+
+	// TODO: We should determine if this is optional
+	if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
+	{
+		VmbusChannelSetEvent(Channel);
+	}
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+
+/*++
+
+Name:
+	VmbusChannelSendPacketMultiPageBuffer()
+
+Description:
+	Send a multi-page buffer packet using a GPADL Direct packet type.
+
+--*/
+int
+VmbusChannelSendPacketMultiPageBuffer(
+	VMBUS_CHANNEL		*Channel,
+	MULTIPAGE_BUFFER	*MultiPageBuffer,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId
+)
+{
+	int ret=0;
+	VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc;
+	UINT32 descSize;
+	UINT32 packetLen;
+	UINT32 packetLenAligned;
+	SG_BUFFER_LIST bufferList[3];
+	UINT64 alignedData=0;
+	UINT32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length);
+
+	DPRINT_ENTER(VMBUS);
+
+	DumpVmbusChannel(Channel);
+
+	DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount);
+
+	ASSERT(PfnCount > 0);
+	ASSERT(PfnCount <= MAX_MULTIPAGE_BUFFER_COUNT);
+
+	// Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is the largest size we support
+	descSize = sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount)*sizeof(UINT64));
+	packetLen = descSize + BufferLen;
+	packetLenAligned = ALIGN_UP(packetLen, sizeof(UINT64));
+
+	ASSERT((packetLenAligned - packetLen) < sizeof(UINT64));
+
+	// Setup the descriptor
+	desc.Type = VmbusPacketTypeDataUsingGpaDirect;
+	desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
+    desc.DataOffset8 = descSize >> 3; // in 8-bytes grandularity
+    desc.Length8 = (UINT16)(packetLenAligned >> 3);
+    desc.TransactionId = RequestId;
+	desc.RangeCount = 1;
+
+	desc.Range.Length = MultiPageBuffer->Length;
+	desc.Range.Offset = MultiPageBuffer->Offset;
+
+	memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(UINT64));
+
+	bufferList[0].Data = &desc;
+	bufferList[0].Length = descSize;
+
+	bufferList[1].Data = Buffer;
+	bufferList[1].Length = BufferLen;
+
+	bufferList[2].Data = &alignedData;
+	bufferList[2].Length = packetLenAligned - packetLen;
+
+	ret = RingBufferWrite(
+		&Channel->Outbound,
+		bufferList,
+		3);
+
+	// TODO: We should determine if this is optional
+	if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
+	{
+		VmbusChannelSetEvent(Channel);
+	}
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	VmbusChannelRecvPacket()
+
+Description:
+	Retrieve the user packet on the specified channel
+
+--*/
+// TODO: Do we ever receive a gpa direct packet other than the ones we send ?
+int
+VmbusChannelRecvPacket(
+	VMBUS_CHANNEL		*Channel,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				BufferActualLen,
+	UINT64*				RequestId
+	)
+{
+	VMPACKET_DESCRIPTOR desc;
+	UINT32 packetLen;
+	UINT32 userLen;
+	int ret;
+
+	DPRINT_ENTER(VMBUS);
+
+	*BufferActualLen = 0;
+	*RequestId = 0;
+
+	SpinlockAcquire(Channel->InboundLock);
+
+	ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
+	if (ret != 0)
+	{
+		SpinlockRelease(Channel->InboundLock);
+
+		//DPRINT_DBG(VMBUS, "nothing to read!!");
+		DPRINT_EXIT(VMBUS);
+		return 0;
+	}
+
+	//VmbusChannelClearEvent(Channel);
+
+	packetLen = desc.Length8 << 3;
+	userLen = packetLen - (desc.DataOffset8 << 3);
+	//ASSERT(userLen > 0);
+
+	DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
+		Channel,
+		Channel->OfferMsg.ChildRelId,
+		desc.Type,
+		desc.Flags,
+		desc.TransactionId, packetLen, userLen);
+
+	*BufferActualLen = userLen;
+
+	if (userLen > BufferLen)
+	{
+		SpinlockRelease(Channel->InboundLock);
+
+		DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", BufferLen, userLen);
+		DPRINT_EXIT(VMBUS);
+
+		return -1;
+	}
+
+	*RequestId = desc.TransactionId;
+
+	// Copy over the packet to the user buffer
+	ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, (desc.DataOffset8 << 3));
+
+	SpinlockRelease(Channel->InboundLock);
+
+	DPRINT_EXIT(VMBUS);
+
+	return 0;
+}
+
+/*++
+
+Name:
+	VmbusChannelRecvPacketRaw()
+
+Description:
+	Retrieve the raw packet on the specified channel
+
+--*/
+int
+VmbusChannelRecvPacketRaw(
+	VMBUS_CHANNEL		*Channel,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				BufferActualLen,
+	UINT64*				RequestId
+	)
+{
+	VMPACKET_DESCRIPTOR desc;
+	UINT32 packetLen;
+	UINT32 userLen;
+	int ret;
+
+	DPRINT_ENTER(VMBUS);
+
+	*BufferActualLen = 0;
+	*RequestId = 0;
+
+	SpinlockAcquire(Channel->InboundLock);
+
+	ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
+	if (ret != 0)
+	{
+		SpinlockRelease(Channel->InboundLock);
+
+		//DPRINT_DBG(VMBUS, "nothing to read!!");
+		DPRINT_EXIT(VMBUS);
+		return 0;
+	}
+
+	//VmbusChannelClearEvent(Channel);
+
+	packetLen = desc.Length8 << 3;
+	userLen = packetLen - (desc.DataOffset8 << 3);
+
+	DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
+		Channel,
+		Channel->OfferMsg.ChildRelId,
+		desc.Type,
+		desc.Flags,
+		desc.TransactionId, packetLen, userLen);
+
+	*BufferActualLen = packetLen;
+
+	if (packetLen > BufferLen)
+	{
+		SpinlockRelease(Channel->InboundLock);
+
+		DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but got space for only %d bytes", packetLen, BufferLen);
+		DPRINT_EXIT(VMBUS);
+		return -2;
+	}
+
+	*RequestId = desc.TransactionId;
+
+	// Copy over the entire packet to the user buffer
+	ret = RingBufferRead(&Channel->Inbound, Buffer, packetLen, 0);
+
+	SpinlockRelease(Channel->InboundLock);
+
+	DPRINT_EXIT(VMBUS);
+
+	return 0;
+}
+
+
+/*++
+
+Name:
+	VmbusChannelOnChannelEvent()
+
+Description:
+	Channel event callback
+
+--*/
+void
+VmbusChannelOnChannelEvent(
+	VMBUS_CHANNEL		*Channel
+	)
+{
+	DumpVmbusChannel(Channel);
+	ASSERT(Channel->OnChannelCallback);
+#ifdef ENABLE_POLLING
+	TimerStop(Channel->PollTimer);
+	Channel->OnChannelCallback(Channel->ChannelCallbackContext);
+	TimerStart(Channel->PollTimer, 100 /* 100us */);
+#else
+	Channel->OnChannelCallback(Channel->ChannelCallbackContext);
+#endif
+}
+
+/*++
+
+Name:
+	VmbusChannelOnTimer()
+
+Description:
+	Timer event callback
+
+--*/
+void
+VmbusChannelOnTimer(
+	void		*Context
+	)
+{
+	VMBUS_CHANNEL *channel = (VMBUS_CHANNEL*)Context;
+
+	if (channel->OnChannelCallback)
+	{
+		channel->OnChannelCallback(channel->ChannelCallbackContext);
+#ifdef ENABLE_POLLING
+		TimerStart(channel->PollTimer, 100 /* 100us */);
+#endif
+	}
+}
+
+
+/*++
+
+Name:
+	DumpVmbusChannel()
+
+Description:
+	Dump vmbus channel info to the console
+
+--*/
+static void
+DumpVmbusChannel(
+	VMBUS_CHANNEL		*Channel
+	)
+{
+	DPRINT_DBG(VMBUS, "Channel (%d)", Channel->OfferMsg.ChildRelId);
+	DumpRingInfo(&Channel->Outbound, "Outbound ");
+	DumpRingInfo(&Channel->Inbound, "Inbound ");
+}
+
+
+// eof
--- /dev/null
+++ b/drivers/staging/hv/Channel.h
@@ -0,0 +1,157 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _CHANNEL_H_
+#define _CHANNEL_H_
+
+#include "osd.h"
+#include "ChannelMgmt.h"
+
+#pragma pack(push,1)
+
+
+// The format must be the same as VMDATA_GPA_DIRECT
+typedef struct _VMBUS_CHANNEL_PACKET_PAGE_BUFFER {
+    UINT16				Type;
+    UINT16				DataOffset8;
+    UINT16				Length8;
+    UINT16				Flags;
+    UINT64				TransactionId;
+	UINT32				Reserved;
+	UINT32				RangeCount;
+    PAGE_BUFFER			Range[MAX_PAGE_BUFFER_COUNT];
+} VMBUS_CHANNEL_PACKET_PAGE_BUFFER;
+
+
+// The format must be the same as VMDATA_GPA_DIRECT
+typedef struct _VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER {
+    UINT16				Type;
+    UINT16				DataOffset8;
+    UINT16				Length8;
+    UINT16				Flags;
+    UINT64				TransactionId;
+	UINT32				Reserved;
+	UINT32				RangeCount;		// Always 1 in this case
+	MULTIPAGE_BUFFER	Range;
+} VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER;
+
+#pragma pack(pop)
+
+//
+// Routines
+//
+
+INTERNAL int
+VmbusChannelOpen(
+	VMBUS_CHANNEL			*Channel,
+	UINT32					SendRingBufferSize,
+	UINT32					RecvRingBufferSize,
+	PVOID					UserData,
+	UINT32					UserDataLen,
+	PFN_CHANNEL_CALLBACK	pfnOnChannelCallback,
+	PVOID					Context
+	);
+
+INTERNAL void
+VmbusChannelClose(
+	VMBUS_CHANNEL		*Channel
+	);
+
+INTERNAL int
+VmbusChannelSendPacket(
+	VMBUS_CHANNEL		*Channel,
+	const PVOID			Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId,
+	VMBUS_PACKET_TYPE	Type,
+	UINT32				Flags
+);
+
+INTERNAL int
+VmbusChannelSendPacketPageBuffer(
+	VMBUS_CHANNEL		*Channel,
+	PAGE_BUFFER			PageBuffers[],
+	UINT32				PageCount,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId
+	);
+
+INTERNAL int
+VmbusChannelSendPacketMultiPageBuffer(
+	VMBUS_CHANNEL		*Channel,
+	MULTIPAGE_BUFFER	*MultiPageBuffer,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId
+);
+
+INTERNAL int
+VmbusChannelEstablishGpadl(
+	VMBUS_CHANNEL		*Channel,
+	PVOID				Kbuffer,	// from kmalloc()
+	UINT32				Size,		// page-size multiple
+	UINT32				*GpadlHandle
+	);
+
+INTERNAL int
+VmbusChannelTeardownGpadl(
+	VMBUS_CHANNEL	*Channel,
+	UINT32			GpadlHandle
+	);
+
+INTERNAL int
+VmbusChannelRecvPacket(
+	VMBUS_CHANNEL		*Channel,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				BufferActualLen,
+	UINT64*				RequestId
+	);
+
+INTERNAL int
+VmbusChannelRecvPacketRaw(
+	VMBUS_CHANNEL		*Channel,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				BufferActualLen,
+	UINT64*				RequestId
+	);
+
+INTERNAL void
+VmbusChannelOnChannelEvent(
+	VMBUS_CHANNEL		*Channel
+	);
+
+INTERNAL void
+VmbusChannelGetDebugInfo(
+	VMBUS_CHANNEL				*Channel,
+	VMBUS_CHANNEL_DEBUG_INFO	*DebugInfo
+	);
+
+INTERNAL void
+VmbusChannelOnTimer(
+	void		*Context
+	);
+#endif //_CHANNEL_H_
--- /dev/null
+++ b/drivers/staging/hv/ChannelInterface.c
@@ -0,0 +1,222 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+#include "VmbusPrivate.h"
+
+INTERNAL int
+IVmbusChannelOpen(
+	PDEVICE_OBJECT		Device,
+	UINT32				SendBufferSize,
+	UINT32				RecvRingBufferSize,
+	PVOID				UserData,
+	UINT32				UserDataLen,
+	VMBUS_CHANNEL_CALLBACK ChannelCallback,
+	PVOID				Context
+	)
+{
+	return VmbusChannelOpen( (VMBUS_CHANNEL*)Device->context,
+								SendBufferSize,
+								RecvRingBufferSize,
+								UserData,
+								UserDataLen,
+								ChannelCallback,
+								Context);
+}
+
+
+INTERNAL void
+IVmbusChannelClose(
+	PDEVICE_OBJECT		Device
+	)
+{
+	VmbusChannelClose((VMBUS_CHANNEL*)Device->context);
+}
+
+
+INTERNAL int
+IVmbusChannelSendPacket(
+	PDEVICE_OBJECT		Device,
+	const PVOID			Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId,
+	UINT32				Type,
+	UINT32				Flags
+	)
+{
+	return VmbusChannelSendPacket((VMBUS_CHANNEL*)Device->context,
+									Buffer,
+									BufferLen,
+									RequestId,
+									Type,
+									Flags);
+}
+
+INTERNAL int
+IVmbusChannelSendPacketPageBuffer(
+	PDEVICE_OBJECT		Device,
+	PAGE_BUFFER			PageBuffers[],
+	UINT32				PageCount,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId
+	)
+{
+	return VmbusChannelSendPacketPageBuffer((VMBUS_CHANNEL*)Device->context,
+												PageBuffers,
+												PageCount,
+												Buffer,
+												BufferLen,
+												RequestId);
+}
+
+INTERNAL int
+IVmbusChannelSendPacketMultiPageBuffer(
+	PDEVICE_OBJECT		Device,
+	MULTIPAGE_BUFFER	*MultiPageBuffer,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT64				RequestId
+	)
+{
+	return VmbusChannelSendPacketMultiPageBuffer((VMBUS_CHANNEL*)Device->context,
+													MultiPageBuffer,
+													Buffer,
+													BufferLen,
+													RequestId);
+}
+
+INTERNAL int
+IVmbusChannelRecvPacket (
+	PDEVICE_OBJECT		Device,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				BufferActualLen,
+	UINT64*				RequestId
+	)
+{
+	return VmbusChannelRecvPacket((VMBUS_CHANNEL*)Device->context,
+									Buffer,
+									BufferLen,
+									BufferActualLen,
+									RequestId);
+}
+
+INTERNAL int
+IVmbusChannelRecvPacketRaw(
+	PDEVICE_OBJECT		Device,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				BufferActualLen,
+	UINT64*				RequestId
+	)
+{
+	return VmbusChannelRecvPacketRaw((VMBUS_CHANNEL*)Device->context,
+										Buffer,
+										BufferLen,
+										BufferActualLen,
+										RequestId);
+}
+
+INTERNAL int
+IVmbusChannelEstablishGpadl(
+	PDEVICE_OBJECT		Device,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32*				GpadlHandle
+	)
+{
+	return VmbusChannelEstablishGpadl((VMBUS_CHANNEL*)Device->context,
+										Buffer,
+										BufferLen,
+										GpadlHandle);
+}
+
+INTERNAL int
+IVmbusChannelTeardownGpadl(
+   PDEVICE_OBJECT		Device,
+   UINT32				GpadlHandle
+	)
+{
+	return VmbusChannelTeardownGpadl((VMBUS_CHANNEL*)Device->context,
+										GpadlHandle);
+
+}
+
+INTERNAL void
+GetChannelInterface(
+	VMBUS_CHANNEL_INTERFACE *ChannelInterface
+	)
+{
+	ChannelInterface->Open						= IVmbusChannelOpen;
+	ChannelInterface->Close						= IVmbusChannelClose;
+	ChannelInterface->SendPacket				= IVmbusChannelSendPacket;
+	ChannelInterface->SendPacketPageBuffer		= IVmbusChannelSendPacketPageBuffer;
+	ChannelInterface->SendPacketMultiPageBuffer = IVmbusChannelSendPacketMultiPageBuffer;
+	ChannelInterface->RecvPacket				= IVmbusChannelRecvPacket;
+	ChannelInterface->RecvPacketRaw				= IVmbusChannelRecvPacketRaw;
+	ChannelInterface->EstablishGpadl			= IVmbusChannelEstablishGpadl;
+	ChannelInterface->TeardownGpadl				= IVmbusChannelTeardownGpadl;
+	ChannelInterface->GetInfo					= GetChannelInfo;
+}
+
+
+INTERNAL void
+GetChannelInfo(
+	PDEVICE_OBJECT		Device,
+	DEVICE_INFO			*DeviceInfo
+			   )
+{
+	VMBUS_CHANNEL_DEBUG_INFO debugInfo;
+
+	if (Device->context)
+	{
+		VmbusChannelGetDebugInfo((VMBUS_CHANNEL*)Device->context, &debugInfo);
+
+		DeviceInfo->ChannelId = debugInfo.RelId;
+		DeviceInfo->ChannelState = debugInfo.State;
+		memcpy(&DeviceInfo->ChannelType, &debugInfo.InterfaceType, sizeof(GUID));
+		memcpy(&DeviceInfo->ChannelInstance, &debugInfo.InterfaceInstance, sizeof(GUID));
+
+		DeviceInfo->MonitorId = debugInfo.MonitorId;
+
+		DeviceInfo->ServerMonitorPending = debugInfo.ServerMonitorPending;
+		DeviceInfo->ServerMonitorLatency = debugInfo.ServerMonitorLatency;
+		DeviceInfo->ServerMonitorConnectionId = debugInfo.ServerMonitorConnectionId;
+
+		DeviceInfo->ClientMonitorPending = debugInfo.ClientMonitorPending;
+		DeviceInfo->ClientMonitorLatency = debugInfo.ClientMonitorLatency;
+		DeviceInfo->ClientMonitorConnectionId = debugInfo.ClientMonitorConnectionId;
+
+		DeviceInfo->Inbound.InterruptMask = debugInfo.Inbound.CurrentInterruptMask;
+		DeviceInfo->Inbound.ReadIndex = debugInfo.Inbound.CurrentReadIndex;
+		DeviceInfo->Inbound.WriteIndex = debugInfo.Inbound.CurrentWriteIndex;
+		DeviceInfo->Inbound.BytesAvailToRead = debugInfo.Inbound.BytesAvailToRead;
+		DeviceInfo->Inbound.BytesAvailToWrite = debugInfo.Inbound.BytesAvailToWrite;
+
+		DeviceInfo->Outbound.InterruptMask = debugInfo.Outbound.CurrentInterruptMask;
+		DeviceInfo->Outbound.ReadIndex = debugInfo.Outbound.CurrentReadIndex;
+		DeviceInfo->Outbound.WriteIndex = debugInfo.Outbound.CurrentWriteIndex;
+		DeviceInfo->Outbound.BytesAvailToRead = debugInfo.Outbound.BytesAvailToRead;
+		DeviceInfo->Outbound.BytesAvailToWrite = debugInfo.Outbound.BytesAvailToWrite;
+	}
+}
--- /dev/null
+++ b/drivers/staging/hv/ChannelInterface.h
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _CHANNEL_INTERFACE_H_
+#define _CHANNEL_INTERFACE_H_
+
+#include "VmbusApi.h"
+
+INTERNAL void
+GetChannelInterface(
+	VMBUS_CHANNEL_INTERFACE *ChannelInterface
+	);
+
+INTERNAL void
+GetChannelInfo(
+	PDEVICE_OBJECT		Device,
+	DEVICE_INFO			*DeviceInfo
+	);
+
+#endif // _CHANNEL_INTERFACE_H_
--- /dev/null
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -0,0 +1,826 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "osd.h"
+#include "logging.h"
+
+#include "VmbusPrivate.h"
+
+//
+// Defines
+//
+
+//
+// Data types
+//
+
+typedef void (*PFN_CHANNEL_MESSAGE_HANDLER)(VMBUS_CHANNEL_MESSAGE_HEADER* msg);
+
+typedef struct _VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY {
+	VMBUS_CHANNEL_MESSAGE_TYPE	messageType;
+	PFN_CHANNEL_MESSAGE_HANDLER messageHandler;
+} VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY;
+
+//
+// Internal routines
+//
+
+static void
+VmbusChannelOnOffer(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	);
+static void
+VmbusChannelOnOpenResult(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	);
+
+static void
+VmbusChannelOnOfferRescind(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	);
+
+static void
+VmbusChannelOnGpadlCreated(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	);
+
+static void
+VmbusChannelOnGpadlTorndown(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	);
+
+static void
+VmbusChannelOnOffersDelivered(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	);
+
+static void
+VmbusChannelOnVersionResponse(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	);
+
+static void
+VmbusChannelProcessOffer(
+	PVOID context
+	);
+
+static void
+VmbusChannelProcessRescindOffer(
+	PVOID context
+	);
+
+
+//
+// Globals
+//
+
+#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 4
+
+const GUID gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED]= {
+	//{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
+	{.Data  = {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f}},// Storage - SCSI
+	//{F8615163-DF3E-46c5-913F-F2D2F965ED0E}
+	{.Data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}},	// Network
+	//{CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A}
+	{.Data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c, 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}}, // Input
+	//{32412632-86cb-44a2-9b5c-50d1417354f5}
+	{.Data = {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5}}, // IDE
+
+};
+
+// Channel message dispatch table
+VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY gChannelMessageTable[ChannelMessageCount]= {
+    {ChannelMessageInvalid,					NULL},
+    {ChannelMessageOfferChannel,            VmbusChannelOnOffer},
+    {ChannelMessageRescindChannelOffer,     VmbusChannelOnOfferRescind},
+    {ChannelMessageRequestOffers,           NULL},
+    {ChannelMessageAllOffersDelivered,      VmbusChannelOnOffersDelivered},
+    {ChannelMessageOpenChannel,             NULL},
+    {ChannelMessageOpenChannelResult,       VmbusChannelOnOpenResult},
+    {ChannelMessageCloseChannel,            NULL},
+    {ChannelMessageGpadlHeader,             NULL},
+    {ChannelMessageGpadlBody,               NULL},
+	{ChannelMessageGpadlCreated,			VmbusChannelOnGpadlCreated},
+    {ChannelMessageGpadlTeardown,           NULL},
+    {ChannelMessageGpadlTorndown,           VmbusChannelOnGpadlTorndown},
+    {ChannelMessageRelIdReleased,           NULL},
+	{ChannelMessageInitiateContact,			NULL},
+	{ChannelMessageVersionResponse,			VmbusChannelOnVersionResponse},
+	{ChannelMessageUnload,					NULL},
+};
+
+/*++
+
+Name:
+	AllocVmbusChannel()
+
+Description:
+	Allocate and initialize a vmbus channel object
+
+--*/
+VMBUS_CHANNEL* AllocVmbusChannel(void)
+{
+	VMBUS_CHANNEL* channel;
+
+	channel = (VMBUS_CHANNEL*) MemAllocAtomic(sizeof(VMBUS_CHANNEL));
+	if (!channel)
+	{
+		return NULL;
+	}
+
+	memset(channel, 0,sizeof(VMBUS_CHANNEL));
+	channel->InboundLock = SpinlockCreate();
+	if (!channel->InboundLock)
+	{
+		MemFree(channel);
+		return NULL;
+	}
+
+	channel->PollTimer = TimerCreate(VmbusChannelOnTimer, channel);
+	if (!channel->PollTimer)
+	{
+		SpinlockClose(channel->InboundLock);
+		MemFree(channel);
+		return NULL;
+	}
+
+	//channel->dataWorkQueue = WorkQueueCreate("data");
+	channel->ControlWQ = WorkQueueCreate("control");
+	if (!channel->ControlWQ)
+	{
+		TimerClose(channel->PollTimer);
+		SpinlockClose(channel->InboundLock);
+		MemFree(channel);
+		return NULL;
+	}
+
+	return channel;
+}
+
+/*++
+
+Name:
+	ReleaseVmbusChannel()
+
+Description:
+	Release the vmbus channel object itself
+
+--*/
+static inline void ReleaseVmbusChannel(void* Context)
+{
+	VMBUS_CHANNEL* channel = (VMBUS_CHANNEL*)Context;
+
+	DPRINT_ENTER(VMBUS);
+
+	DPRINT_DBG(VMBUS, "releasing channel (%p)", channel);
+	WorkQueueClose(channel->ControlWQ);
+	DPRINT_DBG(VMBUS, "channel released (%p)", channel);
+
+	MemFree(channel);
+
+	DPRINT_EXIT(VMBUS);
+}
+
+/*++
+
+Name:
+	FreeVmbusChannel()
+
+Description:
+	Release the resources used by the vmbus channel object
+
+--*/
+void FreeVmbusChannel(VMBUS_CHANNEL* Channel)
+{
+	SpinlockClose(Channel->InboundLock);
+	TimerClose(Channel->PollTimer);
+
+	// We have to release the channel's workqueue/thread in the vmbus's workqueue/thread context
+	// ie we can't destroy ourselves.
+	WorkQueueQueueWorkItem(gVmbusConnection.WorkQueue, ReleaseVmbusChannel, (void*)Channel);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelProcessOffer()
+
+Description:
+	Process the offer by creating a channel/device associated with this offer
+
+--*/
+static void
+VmbusChannelProcessOffer(
+	PVOID context
+	)
+{
+	int ret=0;
+	VMBUS_CHANNEL* newChannel=(VMBUS_CHANNEL*)context;
+	LIST_ENTRY* anchor;
+	LIST_ENTRY* curr;
+	BOOL fNew=TRUE;
+	VMBUS_CHANNEL* channel;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Make sure this is a new offer
+	SpinlockAcquire(gVmbusConnection.ChannelLock);
+
+	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList)
+	{
+		channel = CONTAINING_RECORD(curr, VMBUS_CHANNEL, ListEntry);
+
+		if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, &newChannel->OfferMsg.Offer.InterfaceType,sizeof(GUID)) &&
+			!memcmp(&channel->OfferMsg.Offer.InterfaceInstance, &newChannel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID)))
+		{
+			fNew = FALSE;
+			break;
+		}
+	}
+
+	if (fNew)
+	{
+		INSERT_TAIL_LIST(&gVmbusConnection.ChannelList, &newChannel->ListEntry);
+	}
+	SpinlockRelease(gVmbusConnection.ChannelLock);
+
+	if (!fNew)
+	{
+		DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", newChannel->OfferMsg.ChildRelId);
+		FreeVmbusChannel(newChannel);
+		DPRINT_EXIT(VMBUS);
+		return;
+	}
+
+	// Start the process of binding this offer to the driver
+	// We need to set the DeviceObject field before calling VmbusChildDeviceAdd()
+	newChannel->DeviceObject = VmbusChildDeviceCreate(
+		newChannel->OfferMsg.Offer.InterfaceType,
+		newChannel->OfferMsg.Offer.InterfaceInstance,
+		newChannel);
+
+	DPRINT_DBG(VMBUS, "child device object allocated - %p", newChannel->DeviceObject);
+
+	// Add the new device to the bus. This will kick off device-driver binding
+	// which eventually invokes the device driver's AddDevice() method.
+	ret = VmbusChildDeviceAdd(newChannel->DeviceObject);
+	if (ret != 0)
+	{
+		DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)",
+			newChannel->OfferMsg.ChildRelId);
+
+		SpinlockAcquire(gVmbusConnection.ChannelLock);
+		REMOVE_ENTRY_LIST(&newChannel->ListEntry);
+		SpinlockRelease(gVmbusConnection.ChannelLock);
+
+		FreeVmbusChannel(newChannel);
+	}
+	else
+	{
+		// This state is used to indicate a successful open so that when we do close the channel normally,
+		// we can cleanup properly
+		newChannel->State = CHANNEL_OPEN_STATE;
+	}
+	DPRINT_EXIT(VMBUS);
+}
+
+/*++
+
+Name:
+	VmbusChannelProcessRescindOffer()
+
+Description:
+	Rescind the offer by initiating a device removal
+
+--*/
+static void
+VmbusChannelProcessRescindOffer(
+	PVOID context
+	)
+{
+	VMBUS_CHANNEL* channel=(VMBUS_CHANNEL*)context;
+
+	DPRINT_ENTER(VMBUS);
+
+	VmbusChildDeviceRemove(channel->DeviceObject);
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelOnOffer()
+
+Description:
+	Handler for channel offers from vmbus in parent partition. We ignore all offers except
+	network and storage offers. For each network and storage offers, we create a channel object
+	and queue a work item to the channel object to process the offer synchronously
+
+--*/
+static void
+VmbusChannelOnOffer(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	)
+{
+	VMBUS_CHANNEL_OFFER_CHANNEL* offer = (VMBUS_CHANNEL_OFFER_CHANNEL*)hdr;
+	VMBUS_CHANNEL* newChannel;
+
+	GUID *guidType;
+	GUID *guidInstance;
+	int i;
+	int fSupported=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	for (i=0; i<MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++)
+	{
+		if (memcmp(&offer->Offer.InterfaceType, &gSupportedDeviceClasses[i], sizeof(GUID)) == 0)
+		{
+			fSupported = 1;
+			break;
+		}
+	}
+
+	if (!fSupported)
+	{
+		DPRINT_DBG(VMBUS, "Ignoring channel offer notification for child relid %d", offer->ChildRelId);
+		DPRINT_EXIT(VMBUS);
+
+		return;
+	}
+
+	guidType = &offer->Offer.InterfaceType;
+	guidInstance = &offer->Offer.InterfaceInstance;
+
+	DPRINT_INFO(VMBUS, "Channel offer notification - child relid %d monitor id %d allocated %d, "
+		"type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x} "
+		"instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
+		offer->ChildRelId,
+		offer->MonitorId,
+		offer->MonitorAllocated,
+		guidType->Data[3], guidType->Data[2], guidType->Data[1], guidType->Data[0], guidType->Data[5], guidType->Data[4], guidType->Data[7], guidType->Data[6], guidType->Data[8], guidType->Data[9], guidType->Data[10], guidType->Data[11], guidType->Data[12], guidType->Data[13], guidType->Data[14], guidType->Data[15],
+		guidInstance->Data[3], guidInstance->Data[2], guidInstance->Data[1], guidInstance->Data[0], guidInstance->Data[5], guidInstance->Data[4], guidInstance->Data[7], guidInstance->Data[6], guidInstance->Data[8], guidInstance->Data[9], guidInstance->Data[10], guidInstance->Data[11], guidInstance->Data[12], guidInstance->Data[13], guidInstance->Data[14], guidInstance->Data[15]);
+
+	// Allocate the channel object and save this offer.
+	newChannel = AllocVmbusChannel();
+	if (!newChannel)
+	{
+		DPRINT_ERR(VMBUS, "unable to allocate channel object");
+		return;
+	}
+
+	DPRINT_DBG(VMBUS, "channel object allocated - %p", newChannel);
+
+	memcpy(&newChannel->OfferMsg, offer, sizeof(VMBUS_CHANNEL_OFFER_CHANNEL));
+	newChannel->MonitorGroup = (UINT8)offer->MonitorId / 32;
+	newChannel->MonitorBit = (UINT8)offer->MonitorId % 32;
+
+	// TODO: Make sure the offer comes from our parent partition
+	WorkQueueQueueWorkItem(newChannel->ControlWQ, VmbusChannelProcessOffer, newChannel);
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelOnOfferRescind()
+
+Description:
+	Rescind offer handler. We queue a work item to process this offer
+	synchronously
+
+--*/
+static void
+VmbusChannelOnOfferRescind(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	)
+{
+	VMBUS_CHANNEL_RESCIND_OFFER* rescind = (VMBUS_CHANNEL_RESCIND_OFFER*)hdr;
+	VMBUS_CHANNEL* channel;
+
+	DPRINT_ENTER(VMBUS);
+
+	channel = GetChannelFromRelId(rescind->ChildRelId);
+	if (channel == NULL)
+	{
+		DPRINT_DBG(VMBUS, "channel not found for relId %d", rescind->ChildRelId);
+		return;
+	}
+
+	WorkQueueQueueWorkItem(channel->ControlWQ, VmbusChannelProcessRescindOffer, channel);
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelOnOffersDelivered()
+
+Description:
+	This is invoked when all offers have been delivered.
+	Nothing to do here.
+
+--*/
+static void
+VmbusChannelOnOffersDelivered(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	)
+{
+	DPRINT_ENTER(VMBUS);
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelOnOpenResult()
+
+Description:
+	Open result handler. This is invoked when we received a response
+	to our channel open request. Find the matching request, copy the
+	response and signal the requesting thread.
+
+--*/
+static void
+VmbusChannelOnOpenResult(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	)
+{
+	VMBUS_CHANNEL_OPEN_RESULT* result = (VMBUS_CHANNEL_OPEN_RESULT*)hdr;
+	LIST_ENTRY* anchor;
+	LIST_ENTRY* curr;
+	VMBUS_CHANNEL_MSGINFO* msgInfo;
+	VMBUS_CHANNEL_MESSAGE_HEADER* requestHeader;
+	VMBUS_CHANNEL_OPEN_CHANNEL* openMsg;
+
+	DPRINT_ENTER(VMBUS);
+
+	DPRINT_DBG(VMBUS, "vmbus open result - %d", result->Status);
+
+	// Find the open msg, copy the result and signal/unblock the wait event
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+
+	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
+	{
+		msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
+		requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+
+		if (requestHeader->MessageType == ChannelMessageOpenChannel)
+		{
+			openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL*)msgInfo->Msg;
+			if (openMsg->ChildRelId == result->ChildRelId &&
+				openMsg->OpenId == result->OpenId)
+			{
+				memcpy(&msgInfo->Response.OpenResult, result, sizeof(VMBUS_CHANNEL_OPEN_RESULT));
+				WaitEventSet(msgInfo->WaitEvent);
+				break;
+			}
+		}
+	}
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelOnGpadlCreated()
+
+Description:
+	GPADL created handler. This is invoked when we received a response
+	to our gpadl create request. Find the matching request, copy the
+	response and signal the requesting thread.
+
+--*/
+static void
+VmbusChannelOnGpadlCreated(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	)
+{
+	VMBUS_CHANNEL_GPADL_CREATED *gpadlCreated = (VMBUS_CHANNEL_GPADL_CREATED*)hdr;
+	LIST_ENTRY *anchor;
+	LIST_ENTRY *curr;
+	VMBUS_CHANNEL_MSGINFO *msgInfo;
+	VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
+	VMBUS_CHANNEL_GPADL_HEADER *gpadlHeader;
+
+	DPRINT_ENTER(VMBUS);
+
+	DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", gpadlCreated->CreationStatus);
+
+	// Find the establish msg, copy the result and signal/unblock the wait event
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+
+	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
+	{
+		msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
+		requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+
+		if (requestHeader->MessageType == ChannelMessageGpadlHeader)
+		{
+			gpadlHeader = (VMBUS_CHANNEL_GPADL_HEADER*)requestHeader;
+
+			if ((gpadlCreated->ChildRelId == gpadlHeader->ChildRelId) &&
+					(gpadlCreated->Gpadl == gpadlHeader->Gpadl))
+			{
+				memcpy(&msgInfo->Response.GpadlCreated, gpadlCreated, sizeof(VMBUS_CHANNEL_GPADL_CREATED));
+				WaitEventSet(msgInfo->WaitEvent);
+				break;
+			}
+		}
+	}
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelOnGpadlTorndown()
+
+Description:
+	GPADL torndown handler. This is invoked when we received a response
+	to our gpadl teardown request. Find the matching request, copy the
+	response and signal the requesting thread.
+
+--*/
+static void
+VmbusChannelOnGpadlTorndown(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	)
+{
+	VMBUS_CHANNEL_GPADL_TORNDOWN* gpadlTorndown  = (VMBUS_CHANNEL_GPADL_TORNDOWN*)hdr;
+	LIST_ENTRY* anchor;
+	LIST_ENTRY* curr;
+	VMBUS_CHANNEL_MSGINFO* msgInfo;
+	VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
+	VMBUS_CHANNEL_GPADL_TEARDOWN *gpadlTeardown;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Find the open msg, copy the result and signal/unblock the wait event
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+
+	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
+	{
+		msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
+		requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+
+		if (requestHeader->MessageType == ChannelMessageGpadlTeardown)
+		{
+			gpadlTeardown = (VMBUS_CHANNEL_GPADL_TEARDOWN*)requestHeader;
+
+			if (gpadlTorndown->Gpadl == gpadlTeardown->Gpadl)
+			{
+				memcpy(&msgInfo->Response.GpadlTorndown, gpadlTorndown, sizeof(VMBUS_CHANNEL_GPADL_TORNDOWN));
+				WaitEventSet(msgInfo->WaitEvent);
+				break;
+			}
+		}
+	}
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelOnVersionResponse()
+
+Description:
+	Version response handler. This is invoked when we received a response
+	to our initiate contact request. Find the matching request, copy the
+	response and signal the requesting thread.
+
+--*/
+static void
+VmbusChannelOnVersionResponse(
+	PVMBUS_CHANNEL_MESSAGE_HEADER hdr
+	)
+{
+	LIST_ENTRY* anchor;
+	LIST_ENTRY* curr;
+	VMBUS_CHANNEL_MSGINFO *msgInfo;
+	VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
+	VMBUS_CHANNEL_INITIATE_CONTACT *initiate;
+	VMBUS_CHANNEL_VERSION_RESPONSE *versionResponse  = (VMBUS_CHANNEL_VERSION_RESPONSE*)hdr;
+
+	DPRINT_ENTER(VMBUS);
+
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+
+	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
+	{
+		msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
+		requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+
+		if (requestHeader->MessageType == ChannelMessageInitiateContact)
+		{
+			initiate = (VMBUS_CHANNEL_INITIATE_CONTACT*)requestHeader;
+			memcpy(&msgInfo->Response.VersionResponse, versionResponse, sizeof(VMBUS_CHANNEL_VERSION_RESPONSE));
+			WaitEventSet(msgInfo->WaitEvent);
+		}
+	}
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusOnChannelMessage()
+
+Description:
+	Handler for channel protocol messages.
+	This is invoked in the vmbus worker thread context.
+
+--*/
+VOID
+VmbusOnChannelMessage(
+	void *Context
+	)
+{
+	HV_MESSAGE *msg=(HV_MESSAGE*)Context;
+	VMBUS_CHANNEL_MESSAGE_HEADER* hdr;
+	int size;
+
+	DPRINT_ENTER(VMBUS);
+
+	hdr = (VMBUS_CHANNEL_MESSAGE_HEADER*)msg->u.Payload;
+	size=msg->Header.PayloadSize;
+
+	DPRINT_DBG(VMBUS, "message type %d size %d", hdr->MessageType, size);
+
+	if (hdr->MessageType >= ChannelMessageCount)
+	{
+		DPRINT_ERR(VMBUS, "Received invalid channel message type %d size %d", hdr->MessageType, size);
+		PrintBytes((unsigned char *)msg->u.Payload, size);
+		MemFree(msg);
+		return;
+	}
+
+	if (gChannelMessageTable[hdr->MessageType].messageHandler)
+	{
+		gChannelMessageTable[hdr->MessageType].messageHandler(hdr);
+	}
+	else
+	{
+		DPRINT_ERR(VMBUS, "Unhandled channel message type %d", hdr->MessageType);
+	}
+
+	// Free the msg that was allocated in VmbusOnMsgDPC()
+	MemFree(msg);
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusChannelRequestOffers()
+
+Description:
+	Send a request to get all our pending offers.
+
+--*/
+int
+VmbusChannelRequestOffers(
+	VOID
+	)
+{
+	int ret=0;
+	VMBUS_CHANNEL_MESSAGE_HEADER* msg;
+	VMBUS_CHANNEL_MSGINFO* msgInfo;
+
+	DPRINT_ENTER(VMBUS);
+
+	msgInfo =
+		(VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_MESSAGE_HEADER));
+	ASSERT(msgInfo != NULL);
+
+	msgInfo->WaitEvent = WaitEventCreate();
+	msg = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+
+	msg->MessageType = ChannelMessageRequestOffers;
+
+	/*SpinlockAcquire(gVmbusConnection.channelMsgLock);
+	INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, &msgInfo->msgListEntry);
+	SpinlockRelease(gVmbusConnection.channelMsgLock);*/
+
+	ret = VmbusPostMessage(msg, sizeof(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;
+	}
+	//WaitEventWait(msgInfo->waitEvent);
+
+	/*SpinlockAcquire(gVmbusConnection.channelMsgLock);
+	REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
+	SpinlockRelease(gVmbusConnection.channelMsgLock);*/
+
+
+Cleanup:
+	if (msgInfo)
+	{
+		WaitEventClose(msgInfo->WaitEvent);
+		MemFree(msgInfo);
+	}
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+/*++
+
+Name:
+	VmbusChannelReleaseUnattachedChannels()
+
+Description:
+	Release channels that are unattached/unconnected ie (no drivers associated)
+
+--*/
+void
+VmbusChannelReleaseUnattachedChannels(
+	VOID
+	)
+{
+	LIST_ENTRY *entry;
+	VMBUS_CHANNEL *channel;
+	VMBUS_CHANNEL *start=NULL;
+
+	SpinlockAcquire(gVmbusConnection.ChannelLock);
+
+	while (!IsListEmpty(&gVmbusConnection.ChannelList))
+	{
+		entry = TOP_LIST_ENTRY(&gVmbusConnection.ChannelList);
+		channel = CONTAINING_RECORD(entry, VMBUS_CHANNEL, ListEntry);
+
+		if (channel == start)
+			break;
+
+		if (!channel->DeviceObject->Driver)
+		{
+			REMOVE_ENTRY_LIST(&channel->ListEntry);
+			DPRINT_INFO(VMBUS, "Releasing unattached device object %p", channel->DeviceObject);
+
+			VmbusChildDeviceRemove(channel->DeviceObject);
+			FreeVmbusChannel(channel);
+		}
+		else
+		{
+			if (!start)
+			{
+				start = channel;
+			}
+		}
+	}
+
+	SpinlockRelease(gVmbusConnection.ChannelLock);
+}
+
+// eof
+
--- /dev/null
+++ b/drivers/staging/hv/ChannelMgmt.h
@@ -0,0 +1,156 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _CHANNEL_MGMT_H_
+#define _CHANNEL_MGMT_H_
+
+#include "osd.h"
+#include "List.h"
+#include "RingBuffer.h"
+
+#include "VmbusChannelInterface.h"
+#include "ChannelMessages.h"
+
+
+
+typedef void (*PFN_CHANNEL_CALLBACK)(PVOID context);
+
+typedef enum {
+	CHANNEL_OFFER_STATE,
+	CHANNEL_OPENING_STATE,
+	CHANNEL_OPEN_STATE,
+} VMBUS_CHANNEL_STATE;
+
+typedef struct _VMBUS_CHANNEL {
+	LIST_ENTRY					ListEntry;
+
+	DEVICE_OBJECT*				DeviceObject;
+
+	HANDLE						PollTimer; // SA-111 workaround
+
+	VMBUS_CHANNEL_STATE			State;
+
+	VMBUS_CHANNEL_OFFER_CHANNEL OfferMsg;
+	// These are based on the OfferMsg.MonitorId. Save it here for easy access.
+	UINT8						MonitorGroup;
+	UINT8						MonitorBit;
+
+	UINT32						RingBufferGpadlHandle;
+
+	// Allocated memory for ring buffer
+	VOID*						RingBufferPages;
+	UINT32						RingBufferPageCount;
+	RING_BUFFER_INFO			Outbound;	// send to parent
+	RING_BUFFER_INFO			Inbound;	// receive from parent
+	HANDLE						InboundLock;
+	HANDLE						ControlWQ;
+
+	// Channel callback are invoked in this workqueue context
+	//HANDLE						dataWorkQueue;
+
+	PFN_CHANNEL_CALLBACK		OnChannelCallback;
+	PVOID						ChannelCallbackContext;
+
+} VMBUS_CHANNEL;
+
+
+typedef struct _VMBUS_CHANNEL_DEBUG_INFO {
+	UINT32						RelId;
+	VMBUS_CHANNEL_STATE			State;
+	GUID						InterfaceType;
+    GUID						InterfaceInstance;
+	UINT32						MonitorId;
+	UINT32						ServerMonitorPending;
+	UINT32						ServerMonitorLatency;
+	UINT32						ServerMonitorConnectionId;
+	UINT32						ClientMonitorPending;
+	UINT32						ClientMonitorLatency;
+	UINT32						ClientMonitorConnectionId;
+
+	RING_BUFFER_DEBUG_INFO		Inbound;
+	RING_BUFFER_DEBUG_INFO		Outbound;
+} VMBUS_CHANNEL_DEBUG_INFO;
+
+
+typedef union {
+	VMBUS_CHANNEL_VERSION_SUPPORTED		VersionSupported;
+	VMBUS_CHANNEL_OPEN_RESULT			OpenResult;
+	VMBUS_CHANNEL_GPADL_TORNDOWN		GpadlTorndown;
+	VMBUS_CHANNEL_GPADL_CREATED			GpadlCreated;
+	VMBUS_CHANNEL_VERSION_RESPONSE		VersionResponse;
+} VMBUS_CHANNEL_MESSAGE_RESPONSE;
+
+
+// Represents each channel msg on the vmbus connection
+// This is a variable-size data structure depending on
+// the msg type itself
+typedef struct _VMBUS_CHANNEL_MSGINFO {
+	// Bookkeeping stuff
+	LIST_ENTRY		MsgListEntry;
+
+	// So far, this is only used to handle gpadl body message
+	LIST_ENTRY		SubMsgList;
+
+	// Synchronize the request/response if needed
+	HANDLE			WaitEvent;
+
+	VMBUS_CHANNEL_MESSAGE_RESPONSE Response;
+
+	UINT32			MessageSize;
+	// The channel message that goes out on the "wire".
+	// It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
+	unsigned char	Msg[0];
+} VMBUS_CHANNEL_MSGINFO;
+
+
+//
+// Routines
+//
+
+INTERNAL VMBUS_CHANNEL*
+AllocVmbusChannel(
+	void
+	);
+
+INTERNAL void
+FreeVmbusChannel(
+	VMBUS_CHANNEL *Channel
+	);
+
+INTERNAL void
+VmbusOnChannelMessage(
+	void *Context
+	);
+
+INTERNAL int
+VmbusChannelRequestOffers(
+	void
+	);
+
+INTERNAL void
+VmbusChannelReleaseUnattachedChannels(
+	void
+	);
+
+#endif //_CHANNEL_MGMT_H_
--- /dev/null
+++ b/drivers/staging/hv/Connection.c
@@ -0,0 +1,432 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "logging.h"
+
+#include "VmbusPrivate.h"
+
+//
+// Globals
+//
+
+
+VMBUS_CONNECTION gVmbusConnection = {
+	.ConnectState		= Disconnected,
+	.NextGpadlHandle	= 0xE1E10,
+};
+
+
+/*++
+
+Name:
+	VmbusConnect()
+
+Description:
+	Sends a connect request on the partition service connection
+
+--*/
+int
+VmbusConnect(
+	)
+{
+	int ret=0;
+	VMBUS_CHANNEL_MSGINFO *msgInfo=NULL;
+	VMBUS_CHANNEL_INITIATE_CONTACT *msg;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Make sure we are not connecting or connected
+	if (gVmbusConnection.ConnectState != Disconnected)
+		return -1;
+
+	// Initialize the vmbus connection
+	gVmbusConnection.ConnectState = Connecting;
+	gVmbusConnection.WorkQueue = WorkQueueCreate("vmbusQ");
+
+	INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelMsgList);
+	gVmbusConnection.ChannelMsgLock = SpinlockCreate();
+
+	INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelList);
+	gVmbusConnection.ChannelLock = SpinlockCreate();
+
+	// Setup the vmbus event connection for channel interrupt abstraction stuff
+	gVmbusConnection.InterruptPage = PageAlloc(1);
+	if (gVmbusConnection.InterruptPage == NULL)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	gVmbusConnection.RecvInterruptPage = gVmbusConnection.InterruptPage;
+	gVmbusConnection.SendInterruptPage = (void*)((ULONG_PTR)gVmbusConnection.InterruptPage + (PAGE_SIZE >> 1));
+
+	// Setup the monitor notification facility. The 1st page for parent->child and the 2nd page for child->parent
+	gVmbusConnection.MonitorPages = PageAlloc(2);
+	if (gVmbusConnection.MonitorPages == NULL)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	msgInfo = (VMBUS_CHANNEL_MSGINFO*)MemAllocZeroed(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_INITIATE_CONTACT));
+	if (msgInfo == NULL)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	msgInfo->WaitEvent = WaitEventCreate();
+	msg = (VMBUS_CHANNEL_INITIATE_CONTACT*)msgInfo->Msg;
+
+	msg->Header.MessageType = ChannelMessageInitiateContact;
+	msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER;
+	msg->InterruptPage = GetPhysicalAddress(gVmbusConnection.InterruptPage);
+	msg->MonitorPage1 = GetPhysicalAddress(gVmbusConnection.MonitorPages);
+	msg->MonitorPage2 = GetPhysicalAddress((PVOID)((ULONG_PTR)gVmbusConnection.MonitorPages + PAGE_SIZE));
+
+	// Add to list before we send the request since we may receive the response
+	// before returning from this routine
+	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry);
+	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+
+	DPRINT_DBG(VMBUS, "Vmbus connection -  interrupt pfn %llx, monitor1 pfn %llx,, monitor2 pfn %llx",
+		msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2);
+
+	DPRINT_DBG(VMBUS, "Sending channel initiate msg...");
+
+	ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_INITIATE_CONTACT));
+	if (ret != 0)
+	{
+		REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
+		goto Cleanup;
+	}
+
+	// Wait for the connection response
+	WaitEventWait(msgInfo->WaitEvent);
+
+	REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
+
+	// Check if successful
+	if (msgInfo->Response.VersionResponse.VersionSupported)
+	{
+		DPRINT_INFO(VMBUS, "Vmbus connected!!");
+		gVmbusConnection.ConnectState = Connected;
+
+	}
+	else
+	{
+		DPRINT_ERR(VMBUS, "Vmbus connection failed!!...current version (%d) not supported", VMBUS_REVISION_NUMBER);
+		ret = -1;
+
+		goto Cleanup;
+	}
+
+
+	WaitEventClose(msgInfo->WaitEvent);
+	MemFree(msgInfo);
+	DPRINT_EXIT(VMBUS);
+
+	return 0;
+
+Cleanup:
+
+	gVmbusConnection.ConnectState = Disconnected;
+
+	WorkQueueClose(gVmbusConnection.WorkQueue);
+	SpinlockClose(gVmbusConnection.ChannelLock);
+	SpinlockClose(gVmbusConnection.ChannelMsgLock);
+
+	if (gVmbusConnection.InterruptPage)
+	{
+		PageFree(gVmbusConnection.InterruptPage, 1);
+		gVmbusConnection.InterruptPage = NULL;
+	}
+
+	if (gVmbusConnection.MonitorPages)
+	{
+		PageFree(gVmbusConnection.MonitorPages, 2);
+		gVmbusConnection.MonitorPages = NULL;
+	}
+
+	if (msgInfo)
+	{
+		if (msgInfo->WaitEvent)
+			WaitEventClose(msgInfo->WaitEvent);
+
+		MemFree(msgInfo);
+	}
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	VmbusDisconnect()
+
+Description:
+	Sends a disconnect request on the partition service connection
+
+--*/
+int
+VmbusDisconnect(
+	VOID
+	)
+{
+	int ret=0;
+	VMBUS_CHANNEL_UNLOAD *msg;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Make sure we are connected
+	if (gVmbusConnection.ConnectState != Connected)
+		return -1;
+
+	msg = MemAllocZeroed(sizeof(VMBUS_CHANNEL_UNLOAD));
+
+	msg->MessageType = ChannelMessageUnload;
+
+	ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_UNLOAD));
+
+	if (ret != 0)
+	{
+		goto Cleanup;
+	}
+
+	PageFree(gVmbusConnection.InterruptPage, 1);
+
+	// TODO: iterate thru the msg list and free up
+
+	SpinlockClose(gVmbusConnection.ChannelMsgLock);
+
+	WorkQueueClose(gVmbusConnection.WorkQueue);
+
+	gVmbusConnection.ConnectState = Disconnected;
+
+	DPRINT_INFO(VMBUS, "Vmbus disconnected!!");
+
+Cleanup:
+	if (msg)
+	{
+		MemFree(msg);
+	}
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	GetChannelFromRelId()
+
+Description:
+	Get the channel object given its child relative id (ie channel id)
+
+--*/
+VMBUS_CHANNEL*
+GetChannelFromRelId(
+	UINT32 relId
+	)
+{
+	VMBUS_CHANNEL* channel;
+	VMBUS_CHANNEL* foundChannel=NULL;
+	LIST_ENTRY* anchor;
+	LIST_ENTRY* curr;
+
+	SpinlockAcquire(gVmbusConnection.ChannelLock);
+	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList)
+	{
+		channel = CONTAINING_RECORD(curr, VMBUS_CHANNEL, ListEntry);
+
+		if (channel->OfferMsg.ChildRelId == relId)
+		{
+			foundChannel = channel;
+			break;
+		}
+	}
+	SpinlockRelease(gVmbusConnection.ChannelLock);
+
+	return foundChannel;
+}
+
+
+
+/*++
+
+Name:
+	VmbusProcessChannelEvent()
+
+Description:
+	Process a channel event notification
+
+--*/
+static void
+VmbusProcessChannelEvent(
+	PVOID context
+	)
+{
+	VMBUS_CHANNEL* channel;
+	UINT32 relId = (UINT32)(ULONG_PTR)context;
+
+	ASSERT(relId > 0);
+
+	// Find the channel based on this relid and invokes
+	// the channel callback to process the event
+	channel = GetChannelFromRelId(relId);
+
+	if (channel)
+	{
+		VmbusChannelOnChannelEvent(channel);
+		//WorkQueueQueueWorkItem(channel->dataWorkQueue, VmbusChannelOnChannelEvent, (void*)channel);
+	}
+	else
+	{
+        DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId);
+	}
+}
+
+
+/*++
+
+Name:
+	VmbusOnEvents()
+
+Description:
+	Handler for events
+
+--*/
+VOID
+VmbusOnEvents(
+  VOID
+	)
+{
+	int dword;
+	//int maxdword = PAGE_SIZE >> 3; // receive size is 1/2 page and divide that by 4 bytes
+	int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5;
+	int bit;
+	int relid;
+	UINT32* recvInterruptPage = gVmbusConnection.RecvInterruptPage;
+	//VMBUS_CHANNEL_MESSAGE* receiveMsg;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Check events
+	if (recvInterruptPage)
+	{
+		for (dword = 0; dword < maxdword; dword++)
+		{
+			if (recvInterruptPage[dword])
+			{
+				for (bit = 0; bit < 32; bit++)
+				{
+					if (BitTestAndClear(&recvInterruptPage[dword], bit))
+					{
+						relid = (dword << 5) + bit;
+
+						DPRINT_DBG(VMBUS, "event detected for relid - %d", relid);
+
+						if (relid == 0) // special case - vmbus channel protocol msg
+						{
+							DPRINT_DBG(VMBUS, "invalid relid - %d", relid);
+
+							continue;						}
+						else
+						{
+							//QueueWorkItem(VmbusProcessEvent, (void*)relid);
+							//ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid);
+							VmbusProcessChannelEvent((void*)(ULONG_PTR)relid);
+						}
+					}
+				}
+			}
+		 }
+	}
+	DPRINT_EXIT(VMBUS);
+
+	return;
+}
+
+/*++
+
+Name:
+	VmbusPostMessage()
+
+Description:
+	Send a msg on the vmbus's message connection
+
+--*/
+int
+VmbusPostMessage(
+	PVOID			buffer,
+	SIZE_T			bufferLen
+	)
+{
+	int ret=0;
+	HV_CONNECTION_ID connId;
+
+
+	connId.AsUINT32 =0;
+	connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID;
+	ret = HvPostMessage(
+			connId,
+			1,
+			buffer,
+			bufferLen);
+
+	return  ret;
+}
+
+/*++
+
+Name:
+	VmbusSetEvent()
+
+Description:
+	Send an event notification to the parent
+
+--*/
+int
+VmbusSetEvent(UINT32 childRelId)
+{
+	int ret=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Each UINT32 represents 32 channels
+	BitSet((UINT32*)gVmbusConnection.SendInterruptPage + (childRelId >> 5), childRelId & 31);
+	ret = HvSignalEvent();
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+// EOF
--- /dev/null
+++ b/drivers/staging/hv/Hv.c
@@ -0,0 +1,672 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "logging.h"
+#include "VmbusPrivate.h"
+
+//
+// Globals
+//
+
+// The one and only
+HV_CONTEXT gHvContext={
+	.SynICInitialized = FALSE,
+	.HypercallPage = NULL,
+	.SignalEventParam = NULL,
+	.SignalEventBuffer = NULL,
+};
+
+
+/*++
+
+Name:
+	HvQueryHypervisorPresence()
+
+Description:
+	Query the cpuid for presense of windows hypervisor
+
+--*/
+static int
+HvQueryHypervisorPresence (
+    void
+    )
+{
+    unsigned int eax;
+    unsigned int ebx;
+    unsigned int ecx;
+    unsigned int edx;
+    unsigned int op;
+
+    eax = 0;
+    ebx = 0;
+    ecx = 0;
+    edx = 0;
+    op = HvCpuIdFunctionVersionAndFeatures;
+    do_cpuid(op, &eax, &ebx, &ecx, &edx);
+
+	return (ecx & HV_PRESENT_BIT);
+}
+
+
+/*++
+
+Name:
+	HvQueryHypervisorInfo()
+
+Description:
+	Get version info of the windows hypervisor
+
+--*/
+static int
+HvQueryHypervisorInfo (
+    void
+    )
+{
+    unsigned int eax;
+    unsigned int ebx;
+    unsigned int ecx;
+    unsigned int edx;
+    unsigned int maxLeaf;
+    unsigned int op;
+
+    //
+    // Its assumed that this is called after confirming that Viridian is present.
+    // Query id and revision.
+    //
+
+    eax = 0;
+    ebx = 0;
+    ecx = 0;
+    edx = 0;
+    op = HvCpuIdFunctionHvVendorAndMaxFunction;
+    do_cpuid(op, &eax, &ebx, &ecx, &edx);
+
+    DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c",
+           (ebx & 0xFF),
+           ((ebx >> 8) & 0xFF),
+           ((ebx >> 16) & 0xFF),
+           ((ebx >> 24) & 0xFF),
+           (ecx & 0xFF),
+           ((ecx >> 8) & 0xFF),
+           ((ecx >> 16) & 0xFF),
+           ((ecx >> 24) & 0xFF),
+           (edx & 0xFF),
+           ((edx >> 8) & 0xFF),
+           ((edx >> 16) & 0xFF),
+           ((edx >> 24) & 0xFF));
+
+    maxLeaf = eax;
+    eax = 0;
+    ebx = 0;
+    ecx = 0;
+    edx = 0;
+    op = HvCpuIdFunctionHvInterface;
+    do_cpuid(op, &eax, &ebx, &ecx, &edx);
+
+    DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c",
+           (eax & 0xFF),
+           ((eax >> 8) & 0xFF),
+           ((eax >> 16) & 0xFF),
+           ((eax >> 24) & 0xFF));
+
+	 if (maxLeaf >= HvCpuIdFunctionMsHvVersion) {
+        eax = 0;
+        ebx = 0;
+        ecx = 0;
+        edx = 0;
+        op = HvCpuIdFunctionMsHvVersion;
+        do_cpuid(op, &eax, &ebx, &ecx, &edx);
+        DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d",
+               eax,
+               ebx >> 16,
+               ebx & 0xFFFF,
+               ecx,
+               edx >> 24,
+               edx & 0xFFFFFF);
+    }
+    return maxLeaf;
+}
+
+
+/*++
+
+Name:
+	HvDoHypercall()
+
+Description:
+	Invoke the specified hypercall
+
+--*/
+static UINT64
+HvDoHypercall (
+    UINT64  Control,
+    void*   Input,
+    void*   Output
+    )
+{
+#ifdef x86_64
+    UINT64 hvStatus=0;
+    UINT64 inputAddress = (Input)? GetPhysicalAddress(Input) : 0;
+	UINT64 outputAddress = (Output)? GetPhysicalAddress(Output) : 0;
+    volatile void* hypercallPage = gHvContext.HypercallPage;
+
+    DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p output phys %llx virt %p hypercall %p>",
+		Control,
+		inputAddress,
+		Input,
+		outputAddress,
+		Output,
+		hypercallPage);
+
+	__asm__ __volatile__ ("mov %0, %%r8" : : "r" (outputAddress):  "r8");
+	__asm__ __volatile__ ("call *%3" : "=a"(hvStatus): "c" (Control), "d" (inputAddress), "m" (hypercallPage));
+
+    DPRINT_DBG(VMBUS, "Hypercall <return %llx>",  hvStatus);
+
+    return hvStatus;
+
+#else
+
+    UINT32 controlHi = Control >> 32;
+    UINT32 controlLo = Control & 0xFFFFFFFF;
+    UINT32 hvStatusHi = 1;
+    UINT32 hvStatusLo = 1;
+    UINT64 inputAddress = (Input) ? GetPhysicalAddress(Input) : 0;
+    UINT32 inputAddressHi = inputAddress >> 32;
+    UINT32 inputAddressLo = inputAddress & 0xFFFFFFFF;
+	UINT64 outputAddress = (Output) ?GetPhysicalAddress(Output) : 0;
+    UINT32 outputAddressHi = outputAddress >> 32;
+    UINT32 outputAddressLo = outputAddress & 0xFFFFFFFF;
+    volatile void* hypercallPage = gHvContext.HypercallPage;
+
+    DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
+		Control,
+		Input,
+		Output);
+
+	__asm__ __volatile__ ("call *%8" : "=d"(hvStatusHi), "=a"(hvStatusLo) : "d" (controlHi), "a" (controlLo), "b" (inputAddressHi), "c" (inputAddressLo), "D"(outputAddressHi), "S"(outputAddressLo), "m" (hypercallPage));
+
+
+    DPRINT_DBG(VMBUS, "Hypercall <return %llx>",  hvStatusLo | ((UINT64)hvStatusHi << 32));
+
+    return (hvStatusLo | ((UINT64)hvStatusHi << 32));
+#endif // x86_64
+}
+
+/*++
+
+Name:
+	HvInit()
+
+Description:
+	Main initialization routine. This routine must be called
+	before any other routines in here are called
+
+--*/
+static int
+HvInit (
+    void
+    )
+{
+	int ret=0;
+    int maxLeaf;
+	HV_X64_MSR_HYPERCALL_CONTENTS hypercallMsr;
+	void* virtAddr=0;
+	ULONG_PTR physAddr=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	memset(gHvContext.synICEventPage, 0, sizeof(HANDLE)*MAX_NUM_CPUS);
+	memset(gHvContext.synICMessagePage, 0, sizeof(HANDLE)*MAX_NUM_CPUS);
+
+	if (!HvQueryHypervisorPresence())
+	{
+		DPRINT_ERR(VMBUS, "No Windows hypervisor detected!!");
+		goto Cleanup;
+	}
+
+	DPRINT_INFO(VMBUS, "Windows hypervisor detected! Retrieving more info...");
+
+    maxLeaf = HvQueryHypervisorInfo();
+    //HvQueryHypervisorFeatures(maxLeaf);
+
+	// Determine if we are running on xenlinux (ie x2v shim) or native linux
+	gHvContext.GuestId = ReadMsr(HV_X64_MSR_GUEST_OS_ID);
+
+	if (gHvContext.GuestId == 0)
+	{
+		// Write our OS info
+		WriteMsr(HV_X64_MSR_GUEST_OS_ID, HV_LINUX_GUEST_ID);
+
+		gHvContext.GuestId = HV_LINUX_GUEST_ID;
+	}
+
+	// See if the hypercall page is already set
+	hypercallMsr.AsUINT64 = ReadMsr(HV_X64_MSR_HYPERCALL);
+
+	if (gHvContext.GuestId == HV_LINUX_GUEST_ID)
+	{
+		// Allocate the hypercall page memory
+		//virtAddr = PageAlloc(1);
+		virtAddr = VirtualAllocExec(PAGE_SIZE);
+
+		if (!virtAddr)
+		{
+			DPRINT_ERR(VMBUS, "unable to allocate hypercall page!!");
+			goto Cleanup;
+		}
+
+		hypercallMsr.Enable = 1;
+		//hypercallMsr.GuestPhysicalAddress = Logical2PhysicalAddr(virtAddr) >> PAGE_SHIFT;
+		hypercallMsr.GuestPhysicalAddress = Virtual2Physical(virtAddr) >> PAGE_SHIFT;
+		WriteMsr(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64);
+
+        // Confirm that hypercall page did get setup.
+		hypercallMsr.AsUINT64 = 0;
+		hypercallMsr.AsUINT64 = ReadMsr(HV_X64_MSR_HYPERCALL);
+
+		if (!hypercallMsr.Enable)
+		{
+			DPRINT_ERR(VMBUS, "unable to set hypercall page!!");
+			goto Cleanup;
+		}
+
+		gHvContext.HypercallPage = virtAddr;
+	}
+	else
+	{
+		DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", gHvContext.GuestId);
+		goto Cleanup;
+	}
+
+    DPRINT_INFO(VMBUS, "Hypercall page VA=0x%08x, PA=0x%08x",
+               (unsigned long)gHvContext.HypercallPage,
+               (unsigned long)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT);
+
+	// Setup the global signal event param for the signal event hypercall
+	gHvContext.SignalEventBuffer = MemAlloc(sizeof(HV_INPUT_SIGNAL_EVENT_BUFFER));
+	if (!gHvContext.SignalEventBuffer)
+	{
+		goto Cleanup;
+	}
+
+	gHvContext.SignalEventParam = (PHV_INPUT_SIGNAL_EVENT)(ALIGN_UP((ULONG_PTR)gHvContext.SignalEventBuffer, HV_HYPERCALL_PARAM_ALIGN));
+	gHvContext.SignalEventParam->ConnectionId.AsUINT32 = 0;
+	gHvContext.SignalEventParam->ConnectionId.u.Id = VMBUS_EVENT_CONNECTION_ID;
+	gHvContext.SignalEventParam->FlagNumber = 0;
+	gHvContext.SignalEventParam->RsvdZ = 0;
+
+    //DPRINT_DBG(VMBUS, "My id %llu", HvGetCurrentPartitionId());
+
+	DPRINT_EXIT(VMBUS);
+
+    return ret;
+
+Cleanup:
+	if (virtAddr)
+	{
+		if (hypercallMsr.Enable)
+		{
+			hypercallMsr.AsUINT64 = 0;
+			WriteMsr(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64);
+		}
+
+		VirtualFree(virtAddr);
+	}
+	ret = -1;
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	HvCleanup()
+
+Description:
+	Cleanup routine. This routine is called normally during driver unloading or exiting.
+
+--*/
+void
+HvCleanup (
+    void
+    )
+{
+	HV_X64_MSR_HYPERCALL_CONTENTS hypercallMsr;
+
+	DPRINT_ENTER(VMBUS);
+
+	if (gHvContext.SignalEventBuffer)
+	{
+		MemFree(gHvContext.SignalEventBuffer);
+		gHvContext.SignalEventBuffer = NULL;
+		gHvContext.SignalEventParam = NULL;
+	}
+
+	if (gHvContext.GuestId == HV_LINUX_GUEST_ID)
+	{
+		if (gHvContext.HypercallPage)
+		{
+			hypercallMsr.AsUINT64 = 0;
+			WriteMsr(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64);
+			VirtualFree(gHvContext.HypercallPage);
+			gHvContext.HypercallPage = NULL;
+		}
+	}
+
+	DPRINT_EXIT(VMBUS);
+
+}
+
+
+/*++
+
+Name:
+	HvPostMessage()
+
+Description:
+	Post a message using the hypervisor message IPC. This
+	involves a hypercall.
+
+--*/
+HV_STATUS
+HvPostMessage(
+	HV_CONNECTION_ID connectionId,
+	HV_MESSAGE_TYPE  messageType,
+	PVOID            payload,
+	SIZE_T           payloadSize
+	)
+{
+	struct alignedInput {
+		UINT64					alignment8;
+		HV_INPUT_POST_MESSAGE	msg;
+	};
+
+	PHV_INPUT_POST_MESSAGE alignedMsg;
+	HV_STATUS status;
+	ULONG_PTR addr;
+
+	if (payloadSize > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
+	{
+		return -1;
+	}
+
+	addr = (ULONG_PTR)MemAllocAtomic(sizeof(struct alignedInput));
+
+	if (!addr)
+	{
+		return -1;
+	}
+
+	alignedMsg = (PHV_INPUT_POST_MESSAGE)(ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN));
+
+	alignedMsg->ConnectionId = connectionId;
+	alignedMsg->MessageType = messageType;
+	alignedMsg->PayloadSize = payloadSize;
+	memcpy((void*)alignedMsg->Payload, payload, payloadSize);
+
+	status = HvDoHypercall(HvCallPostMessage, alignedMsg, 0) & 0xFFFF;
+
+	MemFree((void*)addr);
+
+	return status;
+}
+
+
+/*++
+
+Name:
+	HvSignalEvent()
+
+Description:
+	Signal an event on the specified connection using the hypervisor event IPC. This
+	involves a hypercall.
+
+--*/
+HV_STATUS
+HvSignalEvent(
+	)
+{
+	HV_STATUS status;
+
+	status = HvDoHypercall(HvCallSignalEvent, gHvContext.SignalEventParam, 0) & 0xFFFF;
+
+	return status;
+}
+
+
+/*++
+
+Name:
+	HvSynicInit()
+
+Description:
+	Initialize the Synthethic Interrupt Controller. If it is already initialized by
+	another entity (ie x2v shim), we need to retrieve the initialized message and event pages.
+	Otherwise, we create and initialize the message and event pages.
+
+--*/
+int
+HvSynicInit (
+	UINT32 irqVector
+	)
+{
+	UINT64			version;
+	HV_SYNIC_SIMP	simp;
+	HV_SYNIC_SIEFP	siefp;
+    HV_SYNIC_SINT	sharedSint;
+	HV_SYNIC_SCONTROL sctrl;
+	UINT64			guestID;
+	int ret=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	if (!gHvContext.HypercallPage)
+	{
+		DPRINT_EXIT(VMBUS);
+		return ret;
+	}
+
+	// Check the version
+	version = ReadMsr(HV_X64_MSR_SVERSION);
+
+	DPRINT_INFO(VMBUS, "SynIC version: %llx", version);
+
+	// TODO: Handle SMP
+	if (gHvContext.GuestId == HV_XENLINUX_GUEST_ID)
+	{
+		DPRINT_INFO(VMBUS, "Skipping SIMP and SIEFP setup since it is already set.");
+
+		simp.AsUINT64 = ReadMsr(HV_X64_MSR_SIMP);
+		siefp.AsUINT64 = ReadMsr(HV_X64_MSR_SIEFP);
+
+		DPRINT_DBG(VMBUS, "Simp: %llx, Sifep: %llx", simp.AsUINT64, siefp.AsUINT64);
+
+		// Determine if we are running on xenlinux (ie x2v shim) or native linux
+		guestID = ReadMsr(HV_X64_MSR_GUEST_OS_ID);
+
+		if (guestID == HV_LINUX_GUEST_ID)
+		{
+			gHvContext.synICMessagePage[0] = GetVirtualAddress(simp.BaseSimpGpa << PAGE_SHIFT);
+			gHvContext.synICEventPage[0] = GetVirtualAddress(siefp.BaseSiefpGpa << PAGE_SHIFT);
+		}
+		else
+		{
+			DPRINT_ERR(VMBUS, "unknown guest id!!");
+			goto Cleanup;
+		}
+		DPRINT_DBG(VMBUS, "MAPPED: Simp: %p, Sifep: %p", gHvContext.synICMessagePage[0], gHvContext.synICEventPage[0]);
+	}
+	else
+	{
+		gHvContext.synICMessagePage[0] = PageAlloc(1);
+		if (gHvContext.synICMessagePage[0] == NULL)
+		{
+			DPRINT_ERR(VMBUS, "unable to allocate SYNIC message page!!");
+			goto Cleanup;
+		}
+
+		gHvContext.synICEventPage[0] = PageAlloc(1);
+		if (gHvContext.synICEventPage[0] == NULL)
+		{
+			DPRINT_ERR(VMBUS, "unable to allocate SYNIC event page!!");
+			goto Cleanup;
+		}
+
+		//
+		// Setup the Synic's message page
+		//
+		simp.AsUINT64 = ReadMsr(HV_X64_MSR_SIMP);
+		simp.SimpEnabled = 1;
+		simp.BaseSimpGpa = GetPhysicalAddress(gHvContext.synICMessagePage[0]) >> PAGE_SHIFT;
+
+		DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.AsUINT64);
+
+		WriteMsr(HV_X64_MSR_SIMP, simp.AsUINT64);
+
+		//
+		// Setup the Synic's event page
+		//
+		siefp.AsUINT64 = ReadMsr(HV_X64_MSR_SIEFP);
+		siefp.SiefpEnabled = 1;
+		siefp.BaseSiefpGpa = GetPhysicalAddress(gHvContext.synICEventPage[0]) >> PAGE_SHIFT;
+
+		DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.AsUINT64);
+
+		WriteMsr(HV_X64_MSR_SIEFP, siefp.AsUINT64);
+	}
+	//
+    // Setup the interception SINT.
+    //
+	//WriteMsr((HV_X64_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX),
+    //             interceptionSint.AsUINT64);
+
+    //
+    // Setup the shared SINT.
+    //
+	sharedSint.AsUINT64 = ReadMsr(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT);
+
+	sharedSint.AsUINT64 = 0;
+    sharedSint.Vector = irqVector; //HV_SHARED_SINT_IDT_VECTOR + 0x20;
+    sharedSint.Masked = FALSE;
+    sharedSint.AutoEoi = TRUE;
+
+	DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", sharedSint.AsUINT64);
+
+	WriteMsr(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64);
+
+	// Enable the global synic bit
+	sctrl.AsUINT64 = ReadMsr(HV_X64_MSR_SCONTROL);
+	sctrl.Enable = 1;
+
+    WriteMsr(HV_X64_MSR_SCONTROL, sctrl.AsUINT64);
+
+	gHvContext.SynICInitialized = TRUE;
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+
+Cleanup:
+	ret = -1;
+
+	if (gHvContext.GuestId == HV_LINUX_GUEST_ID)
+	{
+		if (gHvContext.synICEventPage[0])
+		{
+			PageFree(gHvContext.synICEventPage[0],1);
+		}
+
+		if (gHvContext.synICMessagePage[0])
+		{
+			PageFree(gHvContext.synICMessagePage[0], 1);
+		}
+	}
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+
+}
+
+/*++
+
+Name:
+	HvSynicCleanup()
+
+Description:
+	Cleanup routine for HvSynicInit().
+
+--*/
+VOID
+HvSynicCleanup(
+	VOID
+	)
+{
+    HV_SYNIC_SINT	sharedSint;
+	HV_SYNIC_SIMP	simp;
+	HV_SYNIC_SIEFP	siefp;
+
+	DPRINT_ENTER(VMBUS);
+
+	if (!gHvContext.SynICInitialized)
+	{
+		DPRINT_EXIT(VMBUS);
+		return;
+	}
+
+	sharedSint.AsUINT64 = ReadMsr(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT);
+
+	sharedSint.Masked = 1;
+
+	// Disable the interrupt
+    WriteMsr(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64);
+
+	// Disable and free the resources only if we are running as native linux
+	// since in xenlinux, we are sharing the resources with the x2v shim
+	if (gHvContext.GuestId == HV_LINUX_GUEST_ID)
+	{
+		simp.AsUINT64 = ReadMsr(HV_X64_MSR_SIMP);
+		simp.SimpEnabled = 0;
+		simp.BaseSimpGpa = 0;
+
+		WriteMsr(HV_X64_MSR_SIMP, simp.AsUINT64);
+
+		siefp.AsUINT64 = ReadMsr(HV_X64_MSR_SIEFP);
+		siefp.SiefpEnabled = 0;
+		siefp.BaseSiefpGpa = 0;
+
+		WriteMsr(HV_X64_MSR_SIEFP, siefp.AsUINT64);
+
+		PageFree(gHvContext.synICMessagePage[0], 1);
+		PageFree(gHvContext.synICEventPage[0], 1);
+	}
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+// eof
--- /dev/null
+++ b/drivers/staging/hv/Hv.h
@@ -0,0 +1,184 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef __HV_H__
+#define __HV_H__
+
+#include "osd.h"
+
+#include "HvTypes.h"
+#include "HvStatus.h"
+//#include "HvVmApi.h"
+//#include "HvKeApi.h"
+//#include "HvMmApi.h"
+//#include "HvCpuApi.h"
+#include "HvHalApi.h"
+#include "HvVpApi.h"
+//#include "HvTrApi.h"
+#include "HvSynicApi.h"
+//#include "HvAmApi.h"
+//#include "HvHkApi.h"
+//#include "HvValApi.h"
+#include "HvHcApi.h"
+#include "HvPtApi.h"
+
+enum
+{
+    VMBUS_MESSAGE_CONNECTION_ID = 1,
+    VMBUS_MESSAGE_PORT_ID       = 1,
+    VMBUS_EVENT_CONNECTION_ID   = 2,
+    VMBUS_EVENT_PORT_ID         = 2,
+    VMBUS_MONITOR_CONNECTION_ID = 3,
+    VMBUS_MONITOR_PORT_ID       = 3,
+    VMBUS_MESSAGE_SINT          = 2
+};
+//
+// #defines
+//
+#define HV_PRESENT_BIT				0x80000000
+
+#define HV_XENLINUX_GUEST_ID_LO     0x00000000
+#define HV_XENLINUX_GUEST_ID_HI		0x0B00B135
+#define HV_XENLINUX_GUEST_ID		(((UINT64)HV_XENLINUX_GUEST_ID_HI << 32) | HV_XENLINUX_GUEST_ID_LO)
+
+#define HV_LINUX_GUEST_ID_LO		0x00000000
+#define HV_LINUX_GUEST_ID_HI		0xB16B00B5
+#define HV_LINUX_GUEST_ID			(((UINT64)HV_LINUX_GUEST_ID_HI << 32) | HV_LINUX_GUEST_ID_LO)
+
+#define HV_CPU_POWER_MANAGEMENT     (1 << 0)
+#define HV_RECOMMENDATIONS_MAX      4
+
+#define HV_X64_MAX                  5
+#define HV_CAPS_MAX                 8
+
+
+#define HV_HYPERCALL_PARAM_ALIGN	sizeof(UINT64)
+
+//
+// Service definitions
+//
+#define HV_SERVICE_PARENT_PORT (0)
+#define HV_SERVICE_PARENT_CONNECTION (0)
+
+#define HV_SERVICE_CONNECT_RESPONSE_SUCCESS             (0)
+#define HV_SERVICE_CONNECT_RESPONSE_INVALID_PARAMETER   (1)
+#define HV_SERVICE_CONNECT_RESPONSE_UNKNOWN_SERVICE     (2)
+#define HV_SERVICE_CONNECT_RESPONSE_CONNECTION_REJECTED (3)
+
+#define HV_SERVICE_CONNECT_REQUEST_MESSAGE_ID		(1)
+#define HV_SERVICE_CONNECT_RESPONSE_MESSAGE_ID		(2)
+#define HV_SERVICE_DISCONNECT_REQUEST_MESSAGE_ID	(3)
+#define HV_SERVICE_DISCONNECT_RESPONSE_MESSAGE_ID	(4)
+#define HV_SERVICE_MAX_MESSAGE_ID					(4)
+
+#define HV_SERVICE_PROTOCOL_VERSION (0x0010)
+#define HV_CONNECT_PAYLOAD_BYTE_COUNT 64
+
+//#define VMBUS_REVISION_NUMBER	6
+//#define VMBUS_PORT_ID			11		// Our local vmbus's port and connection id. Anything >0 is fine
+
+// 628180B8-308D-4c5e-B7DB-1BEB62E62EF4
+static const GUID VMBUS_SERVICE_ID = {.Data = {0xb8, 0x80, 0x81, 0x62, 0x8d, 0x30, 0x5e, 0x4c, 0xb7, 0xdb, 0x1b, 0xeb, 0x62, 0xe6, 0x2e, 0xf4} };
+
+#define MAX_NUM_CPUS	1
+
+
+typedef struct {
+	UINT64					Align8;
+	HV_INPUT_SIGNAL_EVENT	Event;
+} HV_INPUT_SIGNAL_EVENT_BUFFER;
+
+typedef struct {
+	UINT64	GuestId;			// XenLinux or native Linux. If XenLinux, the hypercall and synic pages has already been initialized
+	void*	HypercallPage;
+
+	BOOL	SynICInitialized;
+	// This is used as an input param to HvCallSignalEvent hypercall. The input param is immutable
+	// in our usage and must be dynamic mem (vs stack or global).
+	HV_INPUT_SIGNAL_EVENT_BUFFER *SignalEventBuffer;
+	HV_INPUT_SIGNAL_EVENT *SignalEventParam; // 8-bytes aligned of the buffer above
+
+	HANDLE	synICMessagePage[MAX_NUM_CPUS];
+	HANDLE	synICEventPage[MAX_NUM_CPUS];
+} HV_CONTEXT;
+
+extern HV_CONTEXT gHvContext;
+
+
+//
+// Inline routines
+//
+static inline unsigned long long ReadMsr(int msr)
+{
+	unsigned long long val;
+
+	RDMSR(msr, val);
+
+	return val;
+}
+
+static inline void WriteMsr(int msr, UINT64 val)
+{
+	WRMSR(msr, val);
+
+	return;
+}
+
+//
+// Hv Interface
+//
+INTERNAL int
+HvInit(
+    VOID
+    );
+
+INTERNAL VOID
+HvCleanup(
+    VOID
+    );
+
+INTERNAL HV_STATUS
+HvPostMessage(
+	HV_CONNECTION_ID connectionId,
+	HV_MESSAGE_TYPE  messageType,
+	PVOID            payload,
+	SIZE_T           payloadSize
+	);
+
+INTERNAL HV_STATUS
+HvSignalEvent(
+	VOID
+	);
+
+INTERNAL int
+HvSynicInit(
+	UINT32		irqVector
+	);
+
+INTERNAL VOID
+HvSynicCleanup(
+	VOID
+	);
+
+#endif // __HV_H__
--- /dev/null
+++ b/drivers/staging/hv/osd.c
@@ -0,0 +1,500 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/mm.h>
+#include <linux/highmem.h>
+#include <linux/vmalloc.h>
+//#include <linux/config.h>
+#include <linux/ioport.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/wait.h>
+#include <linux/spinlock.h>
+#include <linux/workqueue.h>
+#include <linux/kernel.h>
+#include <linux/timer.h>
+#include <linux/jiffies.h>
+#include <linux/delay.h>
+#include <linux/time.h>
+
+#include <asm/io.h>
+#include <asm/bitops.h>
+#include <asm/kmap_types.h>
+#include <asm/atomic.h>
+
+#include "osd.h"
+
+//
+// Data types
+//
+typedef struct _TIMER {
+	struct timer_list timer;
+	PFN_TIMER_CALLBACK callback;
+	void* context;
+}TIMER;
+
+
+typedef struct _WAITEVENT {
+	int	condition;
+	wait_queue_head_t event;
+} WAITEVENT;
+
+typedef struct _SPINLOCK {
+	spinlock_t		lock;
+	unsigned long	flags;
+} SPINLOCK;
+
+typedef struct _WORKQUEUE {
+	struct workqueue_struct *queue;
+} WORKQUEUE;
+
+typedef struct _WORKITEM {
+	struct work_struct work;
+	PFN_WORKITEM_CALLBACK callback;
+	void* context;
+} WORKITEM;
+
+
+//
+// Global
+//
+
+void LogMsg(const char *fmt, ...)
+{
+#ifdef KERNEL_2_6_5
+	char buf[1024];
+#endif
+	va_list args;
+
+	va_start(args, fmt);
+#ifdef KERNEL_2_6_5
+	vsnprintf(buf, 1024, fmt, args);
+	va_end(args);
+	printk(buf);
+#else
+	vprintk(fmt, args);
+	va_end(args);
+#endif
+}
+
+void BitSet(unsigned int* addr, int bit)
+{
+	set_bit(bit, (unsigned long*)addr);
+}
+
+int BitTest(unsigned int* addr, int bit)
+{
+	return test_bit(bit, (unsigned long*)addr);
+}
+
+void BitClear(unsigned int* addr, int bit)
+{
+	clear_bit(bit, (unsigned long*)addr);
+}
+
+int BitTestAndClear(unsigned int* addr, int bit)
+{
+	return test_and_clear_bit(bit, (unsigned long*)addr);
+}
+
+int BitTestAndSet(unsigned int* addr, int bit)
+{
+	return test_and_set_bit(bit, (unsigned long*)addr);
+}
+
+
+int InterlockedIncrement(int *val)
+{
+#ifdef KERNEL_2_6_5
+	int i;
+	local_irq_disable();
+	i = atomic_read((atomic_t*)val);
+	atomic_set((atomic_t*)val, i+1);
+	local_irq_enable();
+	return i+1;
+#else
+	return atomic_inc_return((atomic_t*)val);
+#endif
+}
+
+int InterlockedDecrement(int *val)
+{
+#ifdef KERNEL_2_6_5
+	int i;
+	local_irq_disable();
+	i = atomic_read((atomic_t*)val);
+	atomic_set((atomic_t*)val, i-1);
+	local_irq_enable();
+	return i-1;
+#else
+	return atomic_dec_return((atomic_t*)val);
+#endif
+}
+
+#ifndef atomic_cmpxchg
+#define atomic_cmpxchg(v, old, new) ((int)cmpxchg(&((v)->counter), old, new))
+#endif
+int InterlockedCompareExchange(int *val, int new, int curr)
+{
+	//return ((int)cmpxchg(((atomic_t*)val), curr, new));
+	return atomic_cmpxchg((atomic_t*)val, curr, new);
+
+}
+
+void Sleep(unsigned long usecs)
+{
+	udelay(usecs);
+}
+
+void* VirtualAllocExec(unsigned int size)
+{
+#ifdef __x86_64__
+	return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL_EXEC);
+#else
+	return __vmalloc(size, GFP_KERNEL, __pgprot(__PAGE_KERNEL & (~_PAGE_NX)));
+#endif
+}
+
+void VirtualFree(void* VirtAddr)
+{
+	return vfree(VirtAddr);
+}
+
+void* PageAlloc(unsigned int count)
+{
+	void *p;
+	p = (void *)__get_free_pages(GFP_KERNEL, get_order(count * PAGE_SIZE));
+	if (p) memset(p, 0, count * PAGE_SIZE);
+	return p;
+
+	//struct page* page = alloc_page(GFP_KERNEL|__GFP_ZERO);
+	//void *p;
+
+	////BUGBUG: We need to use kmap in case we are in HIMEM region
+	//p = page_address(page);
+	//if (p) memset(p, 0, PAGE_SIZE);
+	//return p;
+}
+
+void PageFree(void* page, unsigned int count)
+{
+	free_pages((unsigned long)page, get_order(count * PAGE_SIZE));
+	/*struct page* p = virt_to_page(page);
+	__free_page(p);*/
+}
+
+
+void* PageMapVirtualAddress(unsigned long Pfn)
+{
+	return kmap_atomic(pfn_to_page(Pfn), KM_IRQ0);
+}
+
+void PageUnmapVirtualAddress(void* VirtAddr)
+{
+	kunmap_atomic(VirtAddr, KM_IRQ0);
+}
+
+void* MemAlloc(unsigned int size)
+{
+	return kmalloc(size, GFP_KERNEL);
+}
+
+void* MemAllocZeroed(unsigned int size)
+{
+	void *p = kmalloc(size, GFP_KERNEL);
+	if (p) memset(p, 0, size);
+	return p;
+}
+
+void* MemAllocAtomic(unsigned int size)
+{
+	return kmalloc(size, GFP_ATOMIC);
+}
+
+void MemFree(void* buf)
+{
+	kfree(buf);
+}
+
+void *MemMapIO(unsigned long phys, unsigned long size)
+{
+#if X2V_LINUX
+#ifdef __x86_64__
+	return (void*)(phys + 0xFFFF83000C000000);
+#else // i386
+	return (void*)(phys + 0xfb000000);
+#endif
+#else
+	return (void*)GetVirtualAddress(phys); //return ioremap_nocache(phys, size);
+#endif
+}
+
+void MemUnmapIO(void *virt)
+{
+	//iounmap(virt);
+}
+
+void MemoryFence()
+{
+	mb();
+}
+
+void TimerCallback(unsigned long data)
+{
+	TIMER* t = (TIMER*)data;
+
+	t->callback(t->context);
+}
+
+HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context)
+{
+	TIMER* t = kmalloc(sizeof(TIMER), GFP_KERNEL);
+	if (!t)
+	{
+		return NULL;
+	}
+
+	t->callback = pfnTimerCB;
+	t->context = context;
+
+	init_timer(&t->timer);
+	t->timer.data = (unsigned long)t;
+	t->timer.function = TimerCallback;
+
+	return t;
+}
+
+void TimerStart(HANDLE hTimer, UINT32 expirationInUs)
+{
+	TIMER* t  = (TIMER* )hTimer;
+
+	t->timer.expires = jiffies + usecs_to_jiffies(expirationInUs);
+	add_timer(&t->timer);
+}
+
+int TimerStop(HANDLE hTimer)
+{
+	TIMER* t  = (TIMER* )hTimer;
+
+	return del_timer(&t->timer);
+}
+
+void TimerClose(HANDLE hTimer)
+{
+	TIMER* t  = (TIMER* )hTimer;
+
+	del_timer(&t->timer);
+	kfree(t);
+}
+
+SIZE_T GetTickCount(void)
+{
+	return jiffies;
+}
+
+signed long long GetTimestamp(void)
+{
+	struct timeval t;
+
+	do_gettimeofday(&t);
+
+	return  timeval_to_ns(&t);
+}
+
+HANDLE WaitEventCreate(void)
+{
+	WAITEVENT* wait = kmalloc(sizeof(WAITEVENT), GFP_KERNEL);
+	if (!wait)
+	{
+		return NULL;
+	}
+
+	wait->condition = 0;
+	init_waitqueue_head(&wait->event);
+	return wait;
+}
+
+void WaitEventClose(HANDLE hWait)
+{
+	WAITEVENT* waitEvent = (WAITEVENT* )hWait;
+	kfree(waitEvent);
+}
+
+void WaitEventSet(HANDLE hWait)
+{
+	WAITEVENT* waitEvent = (WAITEVENT* )hWait;
+	waitEvent->condition = 1;
+	wake_up_interruptible(&waitEvent->event);
+}
+
+int WaitEventWait(HANDLE hWait)
+{
+	int ret=0;
+	WAITEVENT* waitEvent = (WAITEVENT* )hWait;
+
+	ret= wait_event_interruptible(waitEvent->event,
+		waitEvent->condition);
+	waitEvent->condition = 0;
+	return ret;
+}
+
+int WaitEventWaitEx(HANDLE hWait, UINT32 TimeoutInMs)
+{
+	int ret=0;
+	WAITEVENT* waitEvent = (WAITEVENT* )hWait;
+
+	ret= wait_event_interruptible_timeout(waitEvent->event,
+											waitEvent->condition,
+											msecs_to_jiffies(TimeoutInMs));
+	waitEvent->condition = 0;
+	return ret;
+}
+
+HANDLE SpinlockCreate(VOID)
+{
+	SPINLOCK* spin = kmalloc(sizeof(SPINLOCK), GFP_KERNEL);
+	if (!spin)
+	{
+		return NULL;
+	}
+	spin_lock_init(&spin->lock);
+
+	return spin;
+}
+
+VOID SpinlockAcquire(HANDLE hSpin)
+{
+	SPINLOCK* spin = (SPINLOCK* )hSpin;
+
+	spin_lock_irqsave(&spin->lock, spin->flags);
+}
+
+VOID SpinlockRelease(HANDLE hSpin)
+{
+	SPINLOCK* spin = (SPINLOCK* )hSpin;
+
+	spin_unlock_irqrestore(&spin->lock, spin->flags);
+}
+
+VOID SpinlockClose(HANDLE hSpin)
+{
+	SPINLOCK* spin = (SPINLOCK* )hSpin;
+	kfree(spin);
+}
+
+void* Physical2LogicalAddr(ULONG_PTR PhysAddr)
+{
+	void* logicalAddr = phys_to_virt(PhysAddr);
+	BUG_ON(!virt_addr_valid(logicalAddr));
+	return logicalAddr;
+}
+
+ULONG_PTR Logical2PhysicalAddr(PVOID LogicalAddr)
+{
+	BUG_ON(!virt_addr_valid(LogicalAddr));
+	return virt_to_phys(LogicalAddr);
+}
+
+
+ULONG_PTR Virtual2Physical(PVOID VirtAddr)
+{
+	ULONG_PTR pfn = vmalloc_to_pfn(VirtAddr);
+
+	return pfn << PAGE_SHIFT;
+}
+
+#ifdef KERNEL_2_6_27
+void WorkItemCallback(struct work_struct *work)
+#else
+void WorkItemCallback(void* work)
+#endif
+{
+	WORKITEM* w = (WORKITEM*)work;
+
+	w->callback(w->context);
+
+	kfree(w);
+}
+
+HANDLE WorkQueueCreate(char* name)
+{
+	WORKQUEUE *wq = kmalloc(sizeof(WORKQUEUE), GFP_KERNEL);
+	if (!wq)
+	{
+		return NULL;
+	}
+	wq->queue = create_workqueue(name);
+
+	return wq;
+}
+
+void WorkQueueClose(HANDLE hWorkQueue)
+{
+	WORKQUEUE *wq = (WORKQUEUE *)hWorkQueue;
+
+	destroy_workqueue(wq->queue);
+
+	return;
+}
+
+int WorkQueueQueueWorkItem(HANDLE hWorkQueue, PFN_WORKITEM_CALLBACK workItem, void* context)
+{
+	WORKQUEUE *wq = (WORKQUEUE *)hWorkQueue;
+
+	WORKITEM* w = kmalloc(sizeof(WORKITEM), GFP_ATOMIC);
+	if (!w)
+	{
+		return -1;
+	}
+
+	w->callback = workItem,
+	w->context = context;
+#ifdef KERNEL_2_6_27
+	INIT_WORK(&w->work, WorkItemCallback);
+#else
+	INIT_WORK(&w->work, WorkItemCallback, w);
+#endif
+	return queue_work(wq->queue, &w->work);
+}
+
+void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void* context)
+{
+	WORKITEM* w = kmalloc(sizeof(WORKITEM), GFP_ATOMIC);
+	if (!w)
+	{
+		return;
+	}
+
+	w->callback = workItem,
+	w->context = context;
+#ifdef KERNEL_2_6_27
+	INIT_WORK(&w->work, WorkItemCallback);
+#else
+	INIT_WORK(&w->work, WorkItemCallback, w);
+#endif
+	schedule_work(&w->work);
+}
--- /dev/null
+++ b/drivers/staging/hv/RingBuffer.c
@@ -0,0 +1,630 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "logging.h"
+#include "RingBuffer.h"
+
+//
+// #defines
+//
+
+// Amount of space to write to
+#define BYTES_AVAIL_TO_WRITE(r, w, z) ((w) >= (r))?((z) - ((w) - (r))):((r) - (w))
+
+
+/*++
+
+Name:
+	GetRingBufferAvailBytes()
+
+Description:
+	Get number of bytes available to read and to write to
+	for the specified ring buffer
+
+--*/
+static inline void
+GetRingBufferAvailBytes(RING_BUFFER_INFO *rbi, UINT32 *read, UINT32 *write)
+{
+	UINT32 read_loc,write_loc;
+
+	// Capture the read/write indices before they changed
+	read_loc = rbi->RingBuffer->ReadIndex;
+	write_loc = rbi->RingBuffer->WriteIndex;
+
+	*write = BYTES_AVAIL_TO_WRITE(read_loc, write_loc, rbi->RingDataSize);
+	*read = rbi->RingDataSize - *write;
+}
+
+/*++
+
+Name:
+	GetNextWriteLocation()
+
+Description:
+	Get the next write location for the specified ring buffer
+
+--*/
+static inline UINT32
+GetNextWriteLocation(RING_BUFFER_INFO* RingInfo)
+{
+	UINT32 next = RingInfo->RingBuffer->WriteIndex;
+
+	ASSERT(next < RingInfo->RingDataSize);
+
+	return next;
+}
+
+/*++
+
+Name:
+	SetNextWriteLocation()
+
+Description:
+	Set the next write location for the specified ring buffer
+
+--*/
+static inline void
+SetNextWriteLocation(RING_BUFFER_INFO* RingInfo, UINT32 NextWriteLocation)
+{
+	RingInfo->RingBuffer->WriteIndex = NextWriteLocation;
+}
+
+/*++
+
+Name:
+	GetNextReadLocation()
+
+Description:
+	Get the next read location for the specified ring buffer
+
+--*/
+static inline UINT32
+GetNextReadLocation(RING_BUFFER_INFO* RingInfo)
+{
+	UINT32 next = RingInfo->RingBuffer->ReadIndex;
+
+	ASSERT(next < RingInfo->RingDataSize);
+
+	return next;
+}
+
+/*++
+
+Name:
+	GetNextReadLocationWithOffset()
+
+Description:
+	Get the next read location + offset for the specified ring buffer.
+	This allows the caller to skip
+
+--*/
+static inline UINT32
+GetNextReadLocationWithOffset(RING_BUFFER_INFO* RingInfo, UINT32 Offset)
+{
+	UINT32 next = RingInfo->RingBuffer->ReadIndex;
+
+	ASSERT(next < RingInfo->RingDataSize);
+	next += Offset;
+	next %= RingInfo->RingDataSize;
+
+	return next;
+}
+
+/*++
+
+Name:
+	SetNextReadLocation()
+
+Description:
+	Set the next read location for the specified ring buffer
+
+--*/
+static inline void
+SetNextReadLocation(RING_BUFFER_INFO* RingInfo, UINT32 NextReadLocation)
+{
+	RingInfo->RingBuffer->ReadIndex = NextReadLocation;
+}
+
+
+/*++
+
+Name:
+	GetRingBuffer()
+
+Description:
+	Get the start of the ring buffer
+
+--*/
+static inline PVOID
+GetRingBuffer(RING_BUFFER_INFO* RingInfo)
+{
+	return (PVOID)RingInfo->RingBuffer->Buffer;
+}
+
+
+/*++
+
+Name:
+	GetRingBufferSize()
+
+Description:
+	Get the size of the ring buffer
+
+--*/
+static inline UINT32
+GetRingBufferSize(RING_BUFFER_INFO* RingInfo)
+{
+	return RingInfo->RingDataSize;
+}
+
+/*++
+
+Name:
+	GetRingBufferIndices()
+
+Description:
+	Get the read and write indices as UINT64 of the specified ring buffer
+
+--*/
+static inline UINT64
+GetRingBufferIndices(RING_BUFFER_INFO* RingInfo)
+{
+	return ((UINT64)RingInfo->RingBuffer->WriteIndex << 32) || RingInfo->RingBuffer->ReadIndex;
+}
+
+
+/*++
+
+Name:
+	DumpRingInfo()
+
+Description:
+	Dump out to console the ring buffer info
+
+--*/
+void
+DumpRingInfo(RING_BUFFER_INFO* RingInfo, char *Prefix)
+{
+	UINT32 bytesAvailToWrite;
+	UINT32 bytesAvailToRead;
+
+	GetRingBufferAvailBytes(RingInfo, &bytesAvailToRead, &bytesAvailToWrite);
+
+	DPRINT(VMBUS, DEBUG_RING_LVL, "%s <<ringinfo %p buffer %p avail write %u avail read %u read idx %u write idx %u>>",
+		Prefix,
+		RingInfo,
+		RingInfo->RingBuffer->Buffer,
+		bytesAvailToWrite,
+		bytesAvailToRead,
+		RingInfo->RingBuffer->ReadIndex,
+		RingInfo->RingBuffer->WriteIndex);
+}
+
+//
+// Internal routines
+//
+static UINT32
+CopyToRingBuffer(
+	RING_BUFFER_INFO	*RingInfo,
+	UINT32				StartWriteOffset,
+	PVOID				Src,
+	UINT32				SrcLen);
+
+static UINT32
+CopyFromRingBuffer(
+	RING_BUFFER_INFO	*RingInfo,
+	PVOID				Dest,
+	UINT32				DestLen,
+	UINT32				StartReadOffset);
+
+
+
+/*++
+
+Name:
+	RingBufferGetDebugInfo()
+
+Description:
+	Get various debug metrics for the specified ring buffer
+
+--*/
+void
+RingBufferGetDebugInfo(
+	RING_BUFFER_INFO		*RingInfo,
+	RING_BUFFER_DEBUG_INFO	*DebugInfo
+	)
+{
+	UINT32 bytesAvailToWrite;
+	UINT32 bytesAvailToRead;
+
+	if (RingInfo->RingBuffer)
+	{
+		GetRingBufferAvailBytes(RingInfo, &bytesAvailToRead, &bytesAvailToWrite);
+
+		DebugInfo->BytesAvailToRead = bytesAvailToRead;
+		DebugInfo->BytesAvailToWrite = bytesAvailToWrite;
+		DebugInfo->CurrentReadIndex = RingInfo->RingBuffer->ReadIndex;
+		DebugInfo->CurrentWriteIndex = RingInfo->RingBuffer->WriteIndex;
+
+		DebugInfo->CurrentInterruptMask = RingInfo->RingBuffer->InterruptMask;
+	}
+}
+
+
+/*++
+
+Name:
+	GetRingBufferInterruptMask()
+
+Description:
+	Get the interrupt mask for the specified ring buffer
+
+--*/
+UINT32
+GetRingBufferInterruptMask(
+	RING_BUFFER_INFO *rbi
+	)
+{
+	return rbi->RingBuffer->InterruptMask;
+}
+
+/*++
+
+Name:
+	RingBufferInit()
+
+Description:
+	Initialize the ring buffer
+
+--*/
+int
+RingBufferInit(
+	RING_BUFFER_INFO	*RingInfo,
+	VOID				*Buffer,
+	UINT32				BufferLen
+	)
+{
+	ASSERT(sizeof(RING_BUFFER) == PAGE_SIZE);
+
+	memset(RingInfo, 0, sizeof(RING_BUFFER_INFO));
+
+	RingInfo->RingBuffer = (RING_BUFFER*)Buffer;
+	RingInfo->RingBuffer->ReadIndex = RingInfo->RingBuffer->WriteIndex = 0;
+
+	RingInfo->RingSize = BufferLen;
+	RingInfo->RingDataSize = BufferLen - sizeof(RING_BUFFER);
+
+	RingInfo->RingLock = SpinlockCreate();
+
+	return 0;
+}
+
+/*++
+
+Name:
+	RingBufferCleanup()
+
+Description:
+	Cleanup the ring buffer
+
+--*/
+void
+RingBufferCleanup(
+	RING_BUFFER_INFO* RingInfo
+	)
+{
+	SpinlockClose(RingInfo->RingLock);
+}
+
+/*++
+
+Name:
+	RingBufferWrite()
+
+Description:
+	Write to the ring buffer
+
+--*/
+int
+RingBufferWrite(
+	RING_BUFFER_INFO*	OutRingInfo,
+	SG_BUFFER_LIST		SgBuffers[],
+	UINT32				SgBufferCount
+	)
+{
+	int i=0;
+	UINT32 byteAvailToWrite;
+	UINT32 byteAvailToRead;
+	UINT32 totalBytesToWrite=0;
+
+	volatile UINT32 nextWriteLocation;
+	UINT64 prevIndices=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	for (i=0; i < SgBufferCount; i++)
+	{
+		totalBytesToWrite += SgBuffers[i].Length;
+	}
+
+	totalBytesToWrite += sizeof(UINT64);
+
+	SpinlockAcquire(OutRingInfo->RingLock);
+
+	GetRingBufferAvailBytes(OutRingInfo, &byteAvailToRead, &byteAvailToWrite);
+
+	DPRINT_DBG(VMBUS, "Writing %u bytes...", totalBytesToWrite);
+
+	//DumpRingInfo(OutRingInfo, "BEFORE ");
+
+	// If there is only room for the packet, assume it is full. Otherwise, the next time around, we think the ring buffer
+	// is empty since the read index == write index
+	if (byteAvailToWrite <= totalBytesToWrite)
+	{
+		DPRINT_DBG(VMBUS, "No more space left on outbound ring buffer (needed %u, avail %u)", totalBytesToWrite, byteAvailToWrite);
+
+		SpinlockRelease(OutRingInfo->RingLock);
+
+		DPRINT_EXIT(VMBUS);
+
+		return -1;
+	}
+
+	// Write to the ring buffer
+	nextWriteLocation = GetNextWriteLocation(OutRingInfo);
+
+	for (i=0; i < SgBufferCount; i++)
+	{
+		 nextWriteLocation = CopyToRingBuffer(OutRingInfo,
+												nextWriteLocation,
+												SgBuffers[i].Data,
+												SgBuffers[i].Length);
+	}
+
+	// Set previous packet start
+	prevIndices = GetRingBufferIndices(OutRingInfo);
+
+	nextWriteLocation = CopyToRingBuffer(OutRingInfo,
+												nextWriteLocation,
+												&prevIndices,
+												sizeof(UINT64));
+
+	// Make sure we flush all writes before updating the writeIndex
+	MemoryFence();
+
+	// Now, update the write location
+	SetNextWriteLocation(OutRingInfo, nextWriteLocation);
+
+	//DumpRingInfo(OutRingInfo, "AFTER ");
+
+	SpinlockRelease(OutRingInfo->RingLock);
+
+	DPRINT_EXIT(VMBUS);
+
+	return 0;
+}
+
+
+/*++
+
+Name:
+	RingBufferPeek()
+
+Description:
+	Read without advancing the read index
+
+--*/
+int
+RingBufferPeek(
+	RING_BUFFER_INFO*	InRingInfo,
+	void*				Buffer,
+	UINT32				BufferLen
+	)
+{
+	UINT32 bytesAvailToWrite;
+	UINT32 bytesAvailToRead;
+	UINT32 nextReadLocation=0;
+
+	SpinlockAcquire(InRingInfo->RingLock);
+
+	GetRingBufferAvailBytes(InRingInfo, &bytesAvailToRead, &bytesAvailToWrite);
+
+	// Make sure there is something to read
+	if (bytesAvailToRead < BufferLen )
+	{
+		//DPRINT_DBG(VMBUS, "got callback but not enough to read <avail to read %d read size %d>!!", bytesAvailToRead, BufferLen);
+
+		SpinlockRelease(InRingInfo->RingLock);
+
+		return -1;
+	}
+
+	// Convert to byte offset
+	nextReadLocation = GetNextReadLocation(InRingInfo);
+
+	nextReadLocation = CopyFromRingBuffer(InRingInfo,
+											Buffer,
+											BufferLen,
+											nextReadLocation);
+
+	SpinlockRelease(InRingInfo->RingLock);
+
+	return 0;
+}
+
+
+/*++
+
+Name:
+	RingBufferRead()
+
+Description:
+	Read and advance the read index
+
+--*/
+int
+RingBufferRead(
+	RING_BUFFER_INFO*	InRingInfo,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32				Offset
+	)
+{
+	UINT32 bytesAvailToWrite;
+	UINT32 bytesAvailToRead;
+	UINT32 nextReadLocation=0;
+	UINT64 prevIndices=0;
+
+	ASSERT(BufferLen > 0);
+
+	SpinlockAcquire(InRingInfo->RingLock);
+
+	GetRingBufferAvailBytes(InRingInfo, &bytesAvailToRead, &bytesAvailToWrite);
+
+	DPRINT_DBG(VMBUS, "Reading %u bytes...", BufferLen);
+
+	//DumpRingInfo(InRingInfo, "BEFORE ");
+
+	// Make sure there is something to read
+	if (bytesAvailToRead < BufferLen )
+	{
+		DPRINT_DBG(VMBUS, "got callback but not enough to read <avail to read %d read size %d>!!", bytesAvailToRead, BufferLen);
+
+		SpinlockRelease(InRingInfo->RingLock);
+
+		return -1;
+	}
+
+	nextReadLocation = GetNextReadLocationWithOffset(InRingInfo, Offset);
+
+	nextReadLocation = CopyFromRingBuffer(InRingInfo,
+											Buffer,
+											BufferLen,
+											nextReadLocation);
+
+	nextReadLocation = CopyFromRingBuffer(InRingInfo,
+											&prevIndices,
+											sizeof(UINT64),
+											nextReadLocation);
+
+	// Make sure all reads are done before we update the read index since
+	// the writer may start writing to the read area once the read index is updated
+	MemoryFence();
+
+	// Update the read index
+	SetNextReadLocation(InRingInfo, nextReadLocation);
+
+	//DumpRingInfo(InRingInfo, "AFTER ");
+
+	SpinlockRelease(InRingInfo->RingLock);
+
+	return 0;
+}
+
+
+/*++
+
+Name:
+	CopyToRingBuffer()
+
+Description:
+	Helper routine to copy from source to ring buffer.
+	Assume there is enough room. Handles wrap-around in dest case only!!
+
+--*/
+UINT32
+CopyToRingBuffer(
+	RING_BUFFER_INFO	*RingInfo,
+	UINT32				StartWriteOffset,
+	PVOID				Src,
+	UINT32				SrcLen)
+{
+	PVOID ringBuffer=GetRingBuffer(RingInfo);
+	UINT32 ringBufferSize=GetRingBufferSize(RingInfo);
+	UINT32 fragLen;
+
+	if (SrcLen > ringBufferSize - StartWriteOffset) // wrap-around detected!
+	{
+		DPRINT_DBG(VMBUS, "wrap-around detected!");
+
+		fragLen = ringBufferSize - StartWriteOffset;
+		memcpy(ringBuffer + StartWriteOffset, Src, fragLen);
+		memcpy(ringBuffer, Src + fragLen, SrcLen - fragLen);
+	}
+	else
+	{
+		memcpy(ringBuffer + StartWriteOffset, Src, SrcLen);
+	}
+
+	StartWriteOffset += SrcLen;
+	StartWriteOffset %= ringBufferSize;
+
+	return StartWriteOffset;
+}
+
+
+/*++
+
+Name:
+	CopyFromRingBuffer()
+
+Description:
+	Helper routine to copy to source from ring buffer.
+	Assume there is enough room. Handles wrap-around in src case only!!
+
+--*/
+UINT32
+CopyFromRingBuffer(
+	RING_BUFFER_INFO	*RingInfo,
+	PVOID				Dest,
+	UINT32				DestLen,
+	UINT32				StartReadOffset)
+{
+	PVOID ringBuffer=GetRingBuffer(RingInfo);
+	UINT32 ringBufferSize=GetRingBufferSize(RingInfo);
+
+	UINT32 fragLen;
+
+	if (DestLen > ringBufferSize - StartReadOffset) // wrap-around detected at the src
+	{
+		DPRINT_DBG(VMBUS, "src wrap-around detected!");
+
+		fragLen = ringBufferSize - StartReadOffset;
+
+		memcpy(Dest, ringBuffer + StartReadOffset, fragLen);
+		memcpy(Dest + fragLen, ringBuffer, DestLen - fragLen);
+	}
+	else
+	{
+		memcpy(Dest, ringBuffer + StartReadOffset, DestLen);
+	}
+
+	StartReadOffset += DestLen;
+	StartReadOffset %= ringBufferSize;
+
+	return StartReadOffset;
+}
+
+
+// eof
--- /dev/null
+++ b/drivers/staging/hv/RingBuffer.h
@@ -0,0 +1,123 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _RING_BUFFER_H_
+#define _RING_BUFFER_H_
+
+#include "osd.h"
+
+typedef struct _SG_BUFFER_LIST {
+	PVOID	Data;
+	UINT32	Length;
+} SG_BUFFER_LIST;
+
+typedef struct _RING_BUFFER {
+    volatile UINT32	WriteIndex;     // Offset in bytes from the start of ring data below
+    volatile UINT32	ReadIndex;      // Offset in bytes from the start of ring data below
+
+	volatile UINT32 InterruptMask;
+	UINT8	Reserved[4084];			// Pad it to PAGE_SIZE so that data starts on page boundary
+	// NOTE: The InterruptMask field is used only for channels but since our vmbus connection
+	// also uses this data structure and its data starts here, we commented out this field.
+	// volatile UINT32 InterruptMask;
+	// Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
+    UINT8		Buffer[0];
+} STRUCT_PACKED RING_BUFFER;
+
+typedef struct _RING_BUFFER_INFO {
+    RING_BUFFER*	RingBuffer;
+    UINT32			RingSize;			// Include the shared header
+	HANDLE			RingLock;
+
+    UINT32			RingDataSize;		// < ringSize
+	UINT32			RingDataStartOffset;
+
+} RING_BUFFER_INFO;
+
+
+typedef struct _RING_BUFFER_DEBUG_INFO {
+	UINT32		CurrentInterruptMask;
+	UINT32		CurrentReadIndex;
+	UINT32		CurrentWriteIndex;
+	UINT32		BytesAvailToRead;
+	UINT32		BytesAvailToWrite;
+}RING_BUFFER_DEBUG_INFO;
+
+
+//
+// Interface
+//
+
+INTERNAL int
+RingBufferInit(
+	RING_BUFFER_INFO	*RingInfo,
+	PVOID				Buffer,
+	UINT32				BufferLen
+	);
+
+INTERNAL void
+RingBufferCleanup(
+	RING_BUFFER_INFO	*RingInfo
+	);
+
+INTERNAL int
+RingBufferWrite(
+	RING_BUFFER_INFO	*RingInfo,
+	SG_BUFFER_LIST		SgBuffers[],
+	UINT32				SgBufferCount
+	);
+
+INTERNAL int
+RingBufferPeek(
+	RING_BUFFER_INFO	*RingInfo,
+	PVOID				Buffer,
+	UINT32				BufferLen
+	);
+
+INTERNAL int
+RingBufferRead(
+	RING_BUFFER_INFO	*RingInfo,
+	PVOID				Buffer,
+	UINT32				BufferLen,
+	UINT32				Offset
+	);
+
+INTERNAL UINT32
+GetRingBufferInterruptMask(
+	RING_BUFFER_INFO *RingInfo
+	);
+
+INTERNAL void
+DumpRingInfo(
+	RING_BUFFER_INFO* RingInfo,
+	char *Prefix
+	);
+
+INTERNAL void
+RingBufferGetDebugInfo(
+	RING_BUFFER_INFO		*RingInfo,
+	RING_BUFFER_DEBUG_INFO	*DebugInfo
+	);
+
+#endif // _RING_BUFFER_H_
--- /dev/null
+++ b/drivers/staging/hv/Sources.c
@@ -0,0 +1,31 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "Vmbus.c"
+#include "Hv.c"
+#include "Connection.c"
+#include "Channel.c"
+#include "ChannelMgmt.c"
+#include "ChannelInterface.c"
+#include "RingBuffer.c"
--- /dev/null
+++ b/drivers/staging/hv/VersionInfo.h
@@ -0,0 +1,29 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#pragma once
+
+const char VersionDate[]=__DATE__;
+const char VersionTime[]=__TIME__;
+const char VersionDesc[]= "Version 2.0";
--- /dev/null
+++ b/drivers/staging/hv/Vmbus.c
@@ -0,0 +1,508 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "logging.h"
+#include "VersionInfo.h"
+#include "VmbusPrivate.h"
+
+//
+// Globals
+//
+static const char* gDriverName="vmbus";
+
+// Windows vmbus does not defined this. We defined this to be consistent with other devices
+//{c5295816-f63a-4d5f-8d1a-4daf999ca185}
+static const GUID gVmbusDeviceType={
+	.Data = {0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d, 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85}
+};
+
+//{ac3760fc-9adf-40aa-9427-a70ed6de95c5}
+static const GUID gVmbusDeviceId={
+	.Data = {0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40, 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5}
+};
+
+static DRIVER_OBJECT* gDriver; // vmbus driver object
+static DEVICE_OBJECT* gDevice; // vmbus root device
+
+
+//
+// Internal routines
+//
+
+static void
+VmbusGetChannelInterface(
+	VMBUS_CHANNEL_INTERFACE *Interface
+	);
+
+static void
+VmbusGetChannelInfo(
+	DEVICE_OBJECT	*DeviceObject,
+	DEVICE_INFO		*DeviceInfo
+	);
+
+static void
+VmbusGetChannelOffers(
+	void
+	);
+
+static int
+VmbusOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	);
+
+static int
+VmbusOnDeviceRemove(
+	DEVICE_OBJECT* dev
+	);
+
+static void
+VmbusOnCleanup(
+	DRIVER_OBJECT* drv
+	);
+
+static int
+VmbusOnISR(
+	DRIVER_OBJECT* drv
+	);
+
+static void
+VmbusOnMsgDPC(
+	DRIVER_OBJECT* drv
+	);
+
+static void
+VmbusOnEventDPC(
+	DRIVER_OBJECT* drv
+	);
+
+/*++;
+
+Name:
+	VmbusInitialize()
+
+Description:
+	Main entry point
+
+--*/
+int
+VmbusInitialize(
+	DRIVER_OBJECT* drv
+	)
+{
+	VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv;
+	int ret=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	DPRINT_INFO(VMBUS, "+++++++ Build Date=%s %s +++++++", VersionDate, VersionTime);
+	DPRINT_INFO(VMBUS, "+++++++ Build Description=%s +++++++", VersionDesc);
+
+	DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++", VMBUS_REVISION_NUMBER);
+	DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++", VMBUS_MESSAGE_SINT);
+
+	DPRINT_DBG(VMBUS, "sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER)=%d, sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%d",
+		sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER), sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER));
+
+	drv->name = gDriverName;
+	memcpy(&drv->deviceType, &gVmbusDeviceType, sizeof(GUID));
+
+	// Setup dispatch table
+	driver->Base.OnDeviceAdd		= VmbusOnDeviceAdd;
+	driver->Base.OnDeviceRemove		= VmbusOnDeviceRemove;
+	driver->Base.OnCleanup			= VmbusOnCleanup;
+	driver->OnIsr					= VmbusOnISR;
+	driver->OnMsgDpc				= VmbusOnMsgDPC;
+	driver->OnEventDpc				= VmbusOnEventDPC;
+	driver->GetChannelOffers		= VmbusGetChannelOffers;
+	driver->GetChannelInterface		= VmbusGetChannelInterface;
+	driver->GetChannelInfo			= VmbusGetChannelInfo;
+
+	// Hypervisor initialization...setup hypercall page..etc
+	ret = HvInit();
+	if (ret != 0)
+	{
+		DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x", ret);
+	}
+
+	gDriver = drv;
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++;
+
+Name:
+	VmbusGetChannelOffers()
+
+Description:
+	Retrieve the channel offers from the parent partition
+
+--*/
+
+static void
+VmbusGetChannelOffers(void)
+{
+	DPRINT_ENTER(VMBUS);
+	VmbusChannelRequestOffers();
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++;
+
+Name:
+	VmbusGetChannelInterface()
+
+Description:
+	Get the channel interface
+
+--*/
+static void
+VmbusGetChannelInterface(
+	VMBUS_CHANNEL_INTERFACE *Interface
+	)
+{
+	GetChannelInterface(Interface);
+}
+
+
+/*++;
+
+Name:
+	VmbusGetChannelInterface()
+
+Description:
+	Get the device info for the specified device object
+
+--*/
+static void
+VmbusGetChannelInfo(
+	DEVICE_OBJECT	*DeviceObject,
+	DEVICE_INFO		*DeviceInfo
+	)
+{
+	GetChannelInfo(DeviceObject, DeviceInfo);
+}
+
+
+
+/*++
+
+Name:
+	VmbusCreateChildDevice()
+
+Description:
+	Creates the child device on the bus that represents the channel offer
+
+--*/
+
+DEVICE_OBJECT*
+VmbusChildDeviceCreate(
+	GUID DeviceType,
+	GUID DeviceInstance,
+	void *Context)
+{
+	VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver;
+
+	return vmbusDriver->OnChildDeviceCreate(
+		DeviceType,
+		DeviceInstance,
+		Context);
+}
+
+
+/*++
+
+Name:
+	VmbusChildDeviceAdd()
+
+Description:
+	Registers the child device with the vmbus
+
+--*/
+int
+VmbusChildDeviceAdd(
+   DEVICE_OBJECT* ChildDevice)
+{
+	VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver;
+
+	return vmbusDriver->OnChildDeviceAdd(gDevice, ChildDevice);
+}
+
+
+/*++
+
+Name:
+	VmbusChildDeviceRemove()
+
+Description:
+	Unregisters the child device from the vmbus
+
+--*/
+void
+VmbusChildDeviceRemove(
+   DEVICE_OBJECT* ChildDevice)
+{
+	VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver;
+
+	vmbusDriver->OnChildDeviceRemove(ChildDevice);
+}
+
+/*++
+
+Name:
+	VmbusChildDeviceDestroy()
+
+Description:
+	Release the child device from the vmbus
+
+--*/
+//void
+//VmbusChildDeviceDestroy(
+//	DEVICE_OBJECT* ChildDevice
+//	)
+//{
+//	VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver;
+//
+//	vmbusDriver->OnChildDeviceDestroy(ChildDevice);
+//}
+
+/*++
+
+Name:
+	VmbusOnDeviceAdd()
+
+Description:
+	Callback when the root bus device is added
+
+--*/
+static int
+VmbusOnDeviceAdd(
+	DEVICE_OBJECT	*dev,
+	void			*AdditionalInfo
+	)
+{
+	UINT32 *irqvector = (UINT32*) AdditionalInfo;
+	int ret=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	gDevice = dev;
+
+	memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(GUID));
+	memcpy(&gDevice->deviceInstance, &gVmbusDeviceId, sizeof(GUID));
+
+	//strcpy(dev->name, "vmbus");
+	// SynIC setup...
+	ret = HvSynicInit(*irqvector);
+
+	// Connect to VMBus in the root partition
+	ret = VmbusConnect();
+
+	//VmbusSendEvent(device->localPortId+1);
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	VmbusOnDeviceRemove()
+
+Description:
+	Callback when the root bus device is removed
+
+--*/
+int VmbusOnDeviceRemove(
+	DEVICE_OBJECT* dev
+	)
+{
+	int ret=0;
+
+	DPRINT_ENTER(VMBUS);
+
+	VmbusChannelReleaseUnattachedChannels();
+
+	VmbusDisconnect();
+
+	HvSynicCleanup();
+
+	DPRINT_EXIT(VMBUS);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	VmbusOnCleanup()
+
+Description:
+	Perform any cleanup when the driver is removed
+
+--*/
+void
+VmbusOnCleanup(
+	DRIVER_OBJECT* drv
+	)
+{
+	//VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv;
+
+	DPRINT_ENTER(VMBUS);
+
+	HvCleanup();
+
+	DPRINT_EXIT(VMBUS);
+}
+
+
+/*++
+
+Name:
+	VmbusOnMsgDPC()
+
+Description:
+	DPC routine to handle messages from the hypervisior
+
+--*/
+void
+VmbusOnMsgDPC(
+	DRIVER_OBJECT* drv
+	)
+{
+	void *page_addr = gHvContext.synICMessagePage[0];
+
+	HV_MESSAGE* msg = (HV_MESSAGE*)page_addr + VMBUS_MESSAGE_SINT;
+	HV_MESSAGE *copied;
+	while (1)
+	{
+		if (msg->Header.MessageType == HvMessageTypeNone) // no msg
+		{
+			break;
+		}
+		else
+		{
+			copied = MemAllocAtomic(sizeof(HV_MESSAGE));
+			if (copied == NULL)
+			{
+				continue;
+			}
+
+			memcpy(copied, msg, sizeof(HV_MESSAGE));
+			WorkQueueQueueWorkItem(gVmbusConnection.WorkQueue, VmbusOnChannelMessage, (void*)copied);
+		}
+
+		msg->Header.MessageType = HvMessageTypeNone;
+
+		// Make sure the write to MessageType (ie set to HvMessageTypeNone) happens
+		// before we read the MessagePending and EOMing. Otherwise, the EOMing will not deliver
+		// any more messages since there is no empty slot
+		MemoryFence();
+
+		if (msg->Header.MessageFlags.MessagePending)
+		{
+			// This will cause message queue rescan to possibly deliver another msg from the hypervisor
+			WriteMsr(HV_X64_MSR_EOM, 0);
+		}
+	}
+}
+
+/*++
+
+Name:
+	VmbusOnEventDPC()
+
+Description:
+	DPC routine to handle events from the hypervisior
+
+--*/
+void
+VmbusOnEventDPC(
+	DRIVER_OBJECT* drv
+	)
+{
+	// TODO: Process any events
+	VmbusOnEvents();
+}
+
+
+/*++
+
+Name:
+	VmbusOnISR()
+
+Description:
+	ISR routine
+
+--*/
+int
+VmbusOnISR(
+	DRIVER_OBJECT* drv
+	)
+{
+	//VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv;
+
+	int ret=0;
+	//struct page* page;
+	void *page_addr;
+	HV_MESSAGE* msg;
+	HV_SYNIC_EVENT_FLAGS* event;
+
+	//page = SynICMessagePage[0];
+	//page_addr = page_address(page);
+	page_addr = gHvContext.synICMessagePage[0];
+	msg = (HV_MESSAGE*)page_addr + VMBUS_MESSAGE_SINT;
+
+	DPRINT_ENTER(VMBUS);
+
+	// Check if there are actual msgs to be process
+	if (msg->Header.MessageType != HvMessageTypeNone)
+    {
+		DPRINT_DBG(VMBUS, "received msg type %d size %d", msg->Header.MessageType, msg->Header.PayloadSize);
+		ret |= 0x1;
+    }
+
+	// TODO: Check if there are events to be process
+	page_addr = gHvContext.synICEventPage[0];
+	event = (HV_SYNIC_EVENT_FLAGS*)page_addr + VMBUS_MESSAGE_SINT;
+
+	// Since we are a child, we only need to check bit 0
+	if (BitTestAndClear(&event->Flags32[0], 0))
+	{
+		DPRINT_DBG(VMBUS, "received event %d", event->Flags32[0]);
+		ret |= 0x2;
+	}
+
+	DPRINT_EXIT(VMBUS);
+	return ret;
+}
+
+// eof
--- /dev/null
+++ b/drivers/staging/hv/vmbus_drv.c
@@ -0,0 +1,1228 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/sysctl.h>
+
+#include "logging.h"
+#include "vmbus.h"
+
+//
+// Defines
+//
+
+// FIXME! We need to do this dynamically for PIC and APIC system
+#define VMBUS_IRQ				0x5
+#ifdef KERNEL_2_6_27
+#define VMBUS_IRQ_VECTOR     IRQ5_VECTOR
+#endif
+//
+// Data types
+//
+
+// Main vmbus driver data structure
+struct vmbus_driver_context {
+	// !! These must be the first 2 fields !!
+	// The driver field is not used in here. Instead, the bus field is
+	// used to represent the driver
+	struct driver_context	drv_ctx;
+	VMBUS_DRIVER_OBJECT		drv_obj;
+
+	struct bus_type			bus;
+	struct tasklet_struct	msg_dpc;
+	struct tasklet_struct	event_dpc;
+
+	// The bus root device
+	struct device_context	device_ctx;
+};
+
+//
+// Static decl
+//
+static int vmbus_match(struct device *device, struct device_driver *driver);
+static int vmbus_probe(struct device *device);
+static int vmbus_remove(struct device *device);
+static void vmbus_shutdown(struct device *device);
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#elif defined(KERNEL_2_6_27)
+static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env);
+#else
+static int vmbus_uevent(struct device *device, char **envp, int num_envp, char *buffer, int buffer_size);
+#endif
+static void vmbus_msg_dpc(unsigned long data);
+static void vmbus_event_dpc(unsigned long data);
+
+#ifdef KERNEL_2_6_27
+static irqreturn_t vmbus_isr(int irq, void* dev_id);
+#else
+static int vmbus_isr(int irq, void* dev_id, struct pt_regs *regs);
+#endif
+
+static void vmbus_device_release(struct device *device);
+static void vmbus_bus_release(struct device *device);
+
+static DEVICE_OBJECT* vmbus_child_device_create(GUID type, GUID instance, void* context);
+static void vmbus_child_device_destroy(DEVICE_OBJECT* device_obj);
+static int vmbus_child_device_register(DEVICE_OBJECT* root_device_obj, DEVICE_OBJECT* child_device_obj);
+static void vmbus_child_device_unregister(DEVICE_OBJECT* child_device_obj);
+static void vmbus_child_device_get_info(DEVICE_OBJECT *device_obj, DEVICE_INFO *device_info);
+
+//static ssize_t vmbus_show_class_id(struct device *dev, struct device_attribute *attr, char *buf);
+//static ssize_t vmbus_show_device_id(struct device *dev, struct device_attribute *attr, char *buf);
+
+static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf);
+
+//
+// Global
+//
+
+// Global logging setting
+
+//unsigned int vmbus_loglevel= (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT);
+//unsigned int vmbus_loglevel= (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT);
+unsigned int vmbus_loglevel= (ALL_MODULES << 16 | INFO_LVL);
+EXPORT_SYMBOL(vmbus_loglevel);
+
+static int vmbus_irq = VMBUS_IRQ;
+
+// Setup /proc/sys/bus/vmbus/vmbus_loglevel
+// Allow usage of sysctl cmd to set the logging level
+static struct ctl_table_header *vmbus_ctl_table_hdr;
+
+static ctl_table vmbus_dev_ctl_table[] = {
+	{ .ctl_name	= 8461,
+	  .procname	= "vmbus_loglevel",
+	  .data		= &vmbus_loglevel,
+	  .maxlen	= sizeof(vmbus_loglevel),
+	  .mode		= 0644,
+	  .proc_handler	= &proc_dointvec },
+	{ }
+};
+
+static ctl_table vmbus_ctl_table[] = {
+	{ .ctl_name	= CTL_DEV,
+	  .procname	= "vmbus",
+	  .mode		= 0555,
+	  .child	= vmbus_dev_ctl_table },
+	{ }
+};
+
+static ctl_table vmus_root_ctl_table[] = {
+	{ .ctl_name	= CTL_BUS,
+	  .procname	= "bus",
+	  .mode		= 0555,
+	  .child	= vmbus_ctl_table },
+	{ }
+};
+
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#else
+//
+// Set up per device attributes in /sys/bus/vmbus/devices/<bus device>
+//
+static struct device_attribute vmbus_device_attrs[] = {
+	__ATTR(id, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(state, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(class_id, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(monitor_id, S_IRUGO, vmbus_show_device_attr, NULL),
+
+	__ATTR(server_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(server_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(server_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
+
+	__ATTR(client_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(client_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(client_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
+
+	__ATTR(out_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(out_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(out_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(out_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(out_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
+
+	__ATTR(in_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(in_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(in_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(in_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR(in_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
+	__ATTR_NULL
+};
+#endif
+
+// The one and only one
+static struct vmbus_driver_context g_vmbus_drv={
+	.bus.name	= "vmbus",
+	.bus.match	= vmbus_match,
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#else
+	.bus.shutdown = vmbus_shutdown,
+	.bus.remove = vmbus_remove,
+	.bus.probe	= vmbus_probe,
+	.bus.uevent = vmbus_uevent,
+	.bus.dev_attrs = vmbus_device_attrs,
+#endif
+};
+
+//
+// Routines
+//
+
+
+/*++
+
+Name:	vmbus_show_device_attr()
+
+Desc:	Show the device attribute in sysfs. This is invoked when user does a "cat /sys/bus/vmbus/devices/<bus device>/<attr name>"
+
+--*/
+static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf)
+{
+	struct device_context *device_ctx = device_to_device_context(dev);
+	DEVICE_INFO device_info;
+
+	memset(&device_info, 0, sizeof(DEVICE_INFO));
+
+	vmbus_child_device_get_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-%02x%02x%02x%02x%02x%02x%02x%02x}\n",
+			device_info.ChannelType.Data[3], device_info.ChannelType.Data[2], device_info.ChannelType.Data[1], device_info.ChannelType.Data[0],
+			device_info.ChannelType.Data[5], device_info.ChannelType.Data[4],
+			device_info.ChannelType.Data[7], device_info.ChannelType.Data[6],
+			device_info.ChannelType.Data[8], device_info.ChannelType.Data[9], device_info.ChannelType.Data[10], device_info.ChannelType.Data[11], device_info.ChannelType.Data[12], device_info.ChannelType.Data[13], device_info.ChannelType.Data[14], device_info.ChannelType.Data[15]);
+
+	}
+	else if (!strcmp(dev_attr->attr.name, "device_id"))
+	{
+		return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n",
+			device_info.ChannelInstance.Data[3], device_info.ChannelInstance.Data[2], device_info.ChannelInstance.Data[1], device_info.ChannelInstance.Data[0],
+			device_info.ChannelInstance.Data[5], device_info.ChannelInstance.Data[4],
+			device_info.ChannelInstance.Data[7], device_info.ChannelInstance.Data[6],
+			device_info.ChannelInstance.Data[8], device_info.ChannelInstance.Data[9], device_info.ChannelInstance.Data[10], device_info.ChannelInstance.Data[11], device_info.ChannelInstance.Data[12], device_info.ChannelInstance.Data[13], device_info.ChannelInstance.Data[14], device_info.ChannelInstance.Data[15]);
+	}
+	else if (!strcmp(dev_attr->attr.name, "state"))
+	{
+		return sprintf(buf, "%d\n", device_info.ChannelState);
+	}
+	else if (!strcmp(dev_attr->attr.name, "id"))
+	{
+		return sprintf(buf, "%d\n", device_info.ChannelId);
+	}
+	else if (!strcmp(dev_attr->attr.name, "out_intr_mask"))
+	{
+		return sprintf(buf, "%d\n", device_info.Outbound.InterruptMask);
+	}
+	else if (!strcmp(dev_attr->attr.name, "out_read_index"))
+	{
+		return sprintf(buf, "%d\n", device_info.Outbound.ReadIndex);
+	}
+	else if (!strcmp(dev_attr->attr.name, "out_write_index"))
+	{
+		return sprintf(buf, "%d\n", device_info.Outbound.WriteIndex);
+	}
+	else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail"))
+	{
+		return sprintf(buf, "%d\n", device_info.Outbound.BytesAvailToRead);
+	}
+	else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail"))
+	{
+		return sprintf(buf, "%d\n", device_info.Outbound.BytesAvailToWrite);
+	}
+	else if (!strcmp(dev_attr->attr.name, "in_intr_mask"))
+	{
+		return sprintf(buf, "%d\n", device_info.Inbound.InterruptMask);
+	}
+	else if (!strcmp(dev_attr->attr.name, "in_read_index"))
+	{
+		return sprintf(buf, "%d\n", device_info.Inbound.ReadIndex);
+	}
+	else if (!strcmp(dev_attr->attr.name, "in_write_index"))
+	{
+		return sprintf(buf, "%d\n", device_info.Inbound.WriteIndex);
+	}
+	else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail"))
+	{
+		return sprintf(buf, "%d\n", device_info.Inbound.BytesAvailToRead);
+	}
+	else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail"))
+	{
+		return sprintf(buf, "%d\n", device_info.Inbound.BytesAvailToWrite);
+	}
+	else if (!strcmp(dev_attr->attr.name, "monitor_id"))
+	{
+		return sprintf(buf, "%d\n", device_info.MonitorId);
+	}
+	else if (!strcmp(dev_attr->attr.name, "server_monitor_pending"))
+	{
+		return sprintf(buf, "%d\n", device_info.ServerMonitorPending);
+	}
+	else if (!strcmp(dev_attr->attr.name, "server_monitor_latency"))
+	{
+		return sprintf(buf, "%d\n", device_info.ServerMonitorLatency);
+	}
+	else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id"))
+	{
+		return sprintf(buf, "%d\n", device_info.ServerMonitorConnectionId);
+	}
+	else if (!strcmp(dev_attr->attr.name, "client_monitor_pending"))
+	{
+		return sprintf(buf, "%d\n", device_info.ClientMonitorPending);
+	}
+	else if (!strcmp(dev_attr->attr.name, "client_monitor_latency"))
+	{
+		return sprintf(buf, "%d\n", device_info.ClientMonitorLatency);
+	}
+	else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id"))
+	{
+		return sprintf(buf, "%d\n", device_info.ClientMonitorConnectionId);
+	}
+	else
+	{
+		return 0;
+	}
+}
+
+/*++
+
+Name:	vmbus_show_class_id()
+
+Desc:	Show the device class id in sysfs
+
+--*/
+//static ssize_t vmbus_show_class_id(struct device *dev, struct device_attribute *attr, char *buf)
+//{
+//	struct device_context *device_ctx = device_to_device_context(dev);
+//	return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n",
+//		device_ctx->class_id[3], device_ctx->class_id[2], device_ctx->class_id[1], device_ctx->class_id[0],
+//		device_ctx->class_id[5], device_ctx->class_id[4],
+//		device_ctx->class_id[7], device_ctx->class_id[6],
+//		device_ctx->class_id[8], device_ctx->class_id[9], device_ctx->class_id[10], device_ctx->class_id[11], device_ctx->class_id[12], device_ctx->class_id[13], device_ctx->class_id[14], device_ctx->class_id[15]);
+//}
+
+/*++
+
+Name:	vmbus_show_device_id()
+
+Desc:	Show the device instance id in sysfs
+
+--*/
+//static ssize_t vmbus_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
+//{
+//	struct device_context *device_ctx = device_to_device_context(dev);
+//	return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n",
+//		device_ctx->device_id[3], device_ctx->device_id[2], device_ctx->device_id[1], device_ctx->device_id[0],
+//		device_ctx->device_id[5], device_ctx->device_id[4],
+//		device_ctx->device_id[7], device_ctx->device_id[6],
+//		device_ctx->device_id[8], device_ctx->device_id[9], device_ctx->device_id[10], device_ctx->device_id[11], device_ctx->device_id[12], device_ctx->device_id[13], device_ctx->device_id[14], device_ctx->device_id[15]);
+//}
+
+/*++
+
+Name:	vmbus_bus_init()
+
+Desc:	Main vmbus driver initialization routine. Here, we
+		- initialize the vmbus driver context
+		- setup various driver entry points
+		- invoke the vmbus hv main init routine
+		- get the irq resource
+		- invoke the vmbus to add the vmbus root device
+		- setup the vmbus root device
+		- retrieve the channel offers
+--*/
+int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init)
+{
+	int ret=0;
+	unsigned int vector=0;
+
+	struct vmbus_driver_context *vmbus_drv_ctx=&g_vmbus_drv;
+	VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj;
+
+	struct device_context *dev_ctx=&g_vmbus_drv.device_ctx;
+
+	DPRINT_ENTER(VMBUS_DRV);
+
+	// Set this up to allow lower layer to callback to add/remove child devices on the bus
+	vmbus_drv_obj->OnChildDeviceCreate = vmbus_child_device_create;
+	vmbus_drv_obj->OnChildDeviceDestroy = vmbus_child_device_destroy;
+	vmbus_drv_obj->OnChildDeviceAdd = vmbus_child_device_register;
+	vmbus_drv_obj->OnChildDeviceRemove = vmbus_child_device_unregister;
+
+	// Call to bus driver to initialize
+	ret = pfn_drv_init(&vmbus_drv_obj->Base);
+	if (ret != 0)
+	{
+		DPRINT_ERR(VMBUS_DRV, "Unable to initialize vmbus (%d)", ret);
+		goto cleanup;
+	}
+
+	// Sanity checks
+	if (!vmbus_drv_obj->Base.OnDeviceAdd)
+	{
+		DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set");
+		ret = -1;
+		goto cleanup;
+	}
+
+	vmbus_drv_ctx->bus.name = vmbus_drv_obj->Base.name;
+
+	// Initialize the bus context
+	tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, (unsigned long)vmbus_drv_obj);
+	tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, (unsigned long)vmbus_drv_obj);
+
+	// Now, register the bus driver with LDM
+	bus_register(&vmbus_drv_ctx->bus);
+
+	// Get the interrupt resource
+#ifdef KERNEL_2_6_27
+	ret = request_irq(vmbus_irq,
+			  vmbus_isr,
+			  IRQF_SAMPLE_RANDOM,
+			  vmbus_drv_obj->Base.name,
+			  NULL);
+#else
+	ret = request_irq(vmbus_irq,
+			  vmbus_isr,
+			  SA_SAMPLE_RANDOM,
+			  vmbus_drv_obj->Base.name,
+			  NULL);
+#endif
+
+	if (ret != 0)
+	{
+		DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", vmbus_irq);
+
+		bus_unregister(&vmbus_drv_ctx->bus);
+
+		ret = -1;
+		goto cleanup;
+	}
+#ifdef KERNEL_2_6_27
+	vector = VMBUS_IRQ_VECTOR;
+#else
+#if X2V_LINUX
+	vector = vmbus_irq + FIRST_DEVICE_VECTOR - 2;
+#else
+	vector = vmbus_irq + FIRST_EXTERNAL_VECTOR;
+#endif
+#endif
+
+	DPRINT_INFO(VMBUS_DRV, "irq 0x%x vector 0x%x", vmbus_irq, vector);
+
+	// Call to bus driver to add the root device
+	memset(dev_ctx, 0, sizeof(struct device_context));
+
+	ret = vmbus_drv_obj->Base.OnDeviceAdd(&dev_ctx->device_obj, &vector);
+	if (ret != 0)
+	{
+		DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to add vmbus root device");
+
+		free_irq(vmbus_irq, NULL);
+
+		bus_unregister(&vmbus_drv_ctx->bus);
+
+		ret = -1;
+		goto cleanup;
+	}
+	//strcpy(dev_ctx->device.bus_id, dev_ctx->device_obj.name);
+	sprintf(dev_ctx->device.bus_id, "vmbus_0_0");
+	memcpy(&dev_ctx->class_id, &dev_ctx->device_obj.deviceType, sizeof(GUID));
+	memcpy(&dev_ctx->device_id, &dev_ctx->device_obj.deviceInstance, sizeof(GUID));
+
+	// No need to bind a driver to the root device.
+	dev_ctx->device.parent = NULL;
+	dev_ctx->device.bus = &vmbus_drv_ctx->bus; //NULL; // vmbus_remove() does not get invoked
+
+	// Setup the device dispatch table
+	dev_ctx->device.release = vmbus_bus_release;
+
+	// Setup the bus as root device
+	device_register(&dev_ctx->device);
+
+	vmbus_drv_obj->GetChannelOffers();
+
+cleanup:
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return ret;
+}
+
+
+/*++
+
+Name:	vmbus_bus_exit()
+
+Desc:	Terminate the vmbus driver. This routine is opposite of vmbus_bus_init()
+
+--*/
+void vmbus_bus_exit(void)
+{
+	VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj;
+	struct vmbus_driver_context *vmbus_drv_ctx=&g_vmbus_drv;
+
+	struct device_context *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);
+
+	if (vmbus_drv_obj->Base.OnCleanup)
+		vmbus_drv_obj->Base.OnCleanup(&vmbus_drv_obj->Base);
+
+	// Unregister the root bus device
+	device_unregister(&dev_ctx->device);
+
+	bus_unregister(&vmbus_drv_ctx->bus);
+
+	free_irq(vmbus_irq, NULL);
+
+	tasklet_kill(&vmbus_drv_ctx->msg_dpc);
+	tasklet_kill(&vmbus_drv_ctx->event_dpc);
+
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return;
+}
+
+/*++
+
+Name:	vmbus_child_driver_register()
+
+Desc:	Register a vmbus's child driver
+
+--*/
+void vmbus_child_driver_register(struct driver_context* driver_ctx)
+{
+	VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj;
+
+	DPRINT_ENTER(VMBUS_DRV);
+
+	DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", driver_ctx, driver_ctx->driver.name);
+
+	// The child driver on this vmbus
+	driver_ctx->driver.bus = &g_vmbus_drv.bus;
+
+	driver_register(&driver_ctx->driver);
+
+	vmbus_drv_obj->GetChannelOffers();
+
+	DPRINT_EXIT(VMBUS_DRV);
+}
+
+EXPORT_SYMBOL(vmbus_child_driver_register);
+
+/*++
+
+Name:	vmbus_child_driver_unregister()
+
+Desc:	Unregister a vmbus's child driver
+
+--*/
+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);
+
+/*++
+
+Name:	vmbus_get_interface()
+
+Desc:	Get the vmbus channel interface. This is invoked by child/client driver that sits
+		above vmbus
+--*/
+void vmbus_get_interface(VMBUS_CHANNEL_INTERFACE *interface)
+{
+	VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj;
+
+	vmbus_drv_obj->GetChannelInterface(interface);
+}
+
+EXPORT_SYMBOL(vmbus_get_interface);
+
+
+/*++
+
+Name:	vmbus_child_device_get_info()
+
+Desc:	Get the vmbus child device info. This is invoked to display various device attributes in sysfs.
+--*/
+static void vmbus_child_device_get_info(DEVICE_OBJECT *device_obj, DEVICE_INFO *device_info)
+{
+	VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj;
+
+	vmbus_drv_obj->GetChannelInfo(device_obj, device_info);
+}
+
+
+/*++
+
+Name:	vmbus_child_device_create()
+
+Desc:	Creates and registers a new child device on the vmbus.
+
+--*/
+static DEVICE_OBJECT* vmbus_child_device_create(GUID type, GUID instance, void* context)
+{
+	struct device_context *child_device_ctx;
+	DEVICE_OBJECT* child_device_obj;
+
+	DPRINT_ENTER(VMBUS_DRV);
+
+	// Allocate the new child device
+	child_device_ctx = kzalloc(sizeof(struct device_context), GFP_KERNEL);
+	if (!child_device_ctx)
+	{
+		DPRINT_ERR(VMBUS_DRV, "unable to allocate device_context for child device");
+		DPRINT_EXIT(VMBUS_DRV);
+
+		return NULL;
+	}
+
+	DPRINT_DBG(VMBUS_DRV, "child device (%p) allocated - "
+		"type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x},"
+		"id {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
+		&child_device_ctx->device,
+		type.Data[3], type.Data[2], type.Data[1], type.Data[0], type.Data[5], type.Data[4], type.Data[7], type.Data[6], type.Data[8], type.Data[9], type.Data[10], type.Data[11], type.Data[12], type.Data[13], type.Data[14], type.Data[15],
+		instance.Data[3], instance.Data[2], instance.Data[1], instance.Data[0], instance.Data[5], instance.Data[4], instance.Data[7], instance.Data[6], instance.Data[8], instance.Data[9], instance.Data[10], instance.Data[11], instance.Data[12], instance.Data[13], instance.Data[14], instance.Data[15]);
+
+	child_device_obj = &child_device_ctx->device_obj;
+	child_device_obj->context = context;
+	memcpy(&child_device_obj->deviceType, &type, sizeof(GUID));
+	memcpy(&child_device_obj->deviceInstance, &instance, sizeof(GUID));
+
+	memcpy(&child_device_ctx->class_id, &type, sizeof(GUID));
+	memcpy(&child_device_ctx->device_id, &instance, sizeof(GUID));
+
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return child_device_obj;
+}
+
+/*++
+
+Name:	vmbus_child_device_register()
+
+Desc:	Register the child device on the specified bus
+
+--*/
+static int vmbus_child_device_register(DEVICE_OBJECT* root_device_obj, DEVICE_OBJECT* child_device_obj)
+{
+	int ret=0;
+	struct device_context *root_device_ctx = to_device_context(root_device_obj);
+	struct device_context *child_device_ctx = to_device_context(child_device_obj);
+	static int device_num=0;
+
+	DPRINT_ENTER(VMBUS_DRV);
+
+	DPRINT_DBG(VMBUS_DRV, "child device (%p) registering", child_device_ctx);
+	//
+	// Make sure we are not registered already
+	//
+	if (child_device_ctx->device.bus_id[0] != '\0')
+	{
+		DPRINT_ERR(VMBUS_DRV, "child device (%p) already registered - busid %s", child_device_ctx, child_device_ctx->device.bus_id);
+
+		ret = -1;
+		goto Cleanup;
+	}
+
+	// Set the device bus id. Otherwise, device_register()will fail.
+	sprintf(child_device_ctx->device.bus_id, "vmbus_0_%d", InterlockedIncrement(&device_num));
+
+	// The new device belongs to this bus
+	child_device_ctx->device.bus = &g_vmbus_drv.bus; //device->dev.bus;
+	child_device_ctx->device.parent = &root_device_ctx->device;
+	child_device_ctx->device.release = vmbus_device_release;
+
+	// Register with the LDM. This will kick off the driver/device binding...which will
+	// eventually call vmbus_match() and vmbus_probe()
+	ret = device_register(&child_device_ctx->device);
+
+	// vmbus_probe() error does not get propergate to device_register().
+	ret = child_device_ctx->probe_error;
+
+	if (ret)
+		DPRINT_ERR(VMBUS_DRV, "unable to register child device (%p) (%d)", &child_device_ctx->device);
+	else
+		DPRINT_INFO(VMBUS_DRV, "child device (%p) registered", &child_device_ctx->device);
+
+Cleanup:
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return ret;
+}
+
+/*++
+
+Name:	vmbus_child_device_unregister()
+
+Desc:	Remove the specified child device from the vmbus.
+
+--*/
+static void vmbus_child_device_unregister(DEVICE_OBJECT* device_obj)
+{
+	struct device_context *device_ctx = to_device_context(device_obj);
+
+	DPRINT_ENTER(VMBUS_DRV);
+
+	DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)", &device_ctx->device);
+
+	// Kick off the process of unregistering the device.
+	// This will call vmbus_remove() and eventually vmbus_device_release()
+	device_unregister(&device_ctx->device);
+
+	DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered", &device_ctx->device);
+
+	DPRINT_EXIT(VMBUS_DRV);
+}
+
+
+/*++
+
+Name:	vmbus_child_device_destroy()
+
+Desc:	Destroy the specified child device on the vmbus.
+
+--*/
+static void vmbus_child_device_destroy(DEVICE_OBJECT* device_obj)
+{
+	DPRINT_ENTER(VMBUS_DRV);
+
+	DPRINT_EXIT(VMBUS_DRV);
+}
+
+/*++
+
+Name:	vmbus_uevent()
+
+Desc:	This routine is invoked when a device is added or removed on the vmbus to generate a uevent to udev in the
+		userspace. The udev will then look at its rule and the uevent generated here to load the appropriate driver
+
+--*/
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#elif defined(KERNEL_2_6_27)
+static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env)
+{
+	struct device_context *device_ctx = device_to_device_context(device);
+	int i=0;
+	int len=0;
+	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}",
+		device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], device_ctx->class_id.Data[1], device_ctx->class_id.Data[0],
+		device_ctx->class_id.Data[5], device_ctx->class_id.Data[4],
+		device_ctx->class_id.Data[7], device_ctx->class_id.Data[6],
+		device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], device_ctx->class_id.Data[10], device_ctx->class_id.Data[11],
+		device_ctx->class_id.Data[12], device_ctx->class_id.Data[13], device_ctx->class_id.Data[14], device_ctx->class_id.Data[15]);
+
+	env->envp_idx = i;
+	env->buflen = len;
+	ret = add_uevent_var(env,
+		"VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
+		device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], device_ctx->class_id.Data[1], device_ctx->class_id.Data[0],
+		device_ctx->class_id.Data[5], device_ctx->class_id.Data[4],
+		device_ctx->class_id.Data[7], device_ctx->class_id.Data[6],
+		device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], device_ctx->class_id.Data[10], device_ctx->class_id.Data[11],
+		device_ctx->class_id.Data[12], device_ctx->class_id.Data[13], device_ctx->class_id.Data[14], device_ctx->class_id.Data[15]);
+
+	if (ret)
+	{
+		return ret;
+	}
+
+	ret = add_uevent_var(env,
+		"VMBUS_DEVICE_DEVICE_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
+		device_ctx->device_id.Data[3], device_ctx->device_id.Data[2], device_ctx->device_id.Data[1], device_ctx->device_id.Data[0],
+		device_ctx->device_id.Data[5], device_ctx->device_id.Data[4],
+		device_ctx->device_id.Data[7], device_ctx->device_id.Data[6],
+		device_ctx->device_id.Data[8], device_ctx->device_id.Data[9], device_ctx->device_id.Data[10], device_ctx->device_id.Data[11],
+		device_ctx->device_id.Data[12], device_ctx->device_id.Data[13], device_ctx->device_id.Data[14], device_ctx->device_id.Data[15]);
+
+	if (ret)
+	{
+		return ret;
+	}
+
+	env->envp[env->envp_idx] = NULL;
+
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return 0;
+}
+
+#else
+static int vmbus_uevent(struct device *device, char **envp, int num_envp, char *buffer, int buffer_size)
+{
+	struct device_context *device_ctx = device_to_device_context(device);
+	int i=0;
+	int len=0;
+	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}",
+		device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], device_ctx->class_id.Data[1], device_ctx->class_id.Data[0],
+		device_ctx->class_id.Data[5], device_ctx->class_id.Data[4],
+		device_ctx->class_id.Data[7], device_ctx->class_id.Data[6],
+		device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], device_ctx->class_id.Data[10], device_ctx->class_id.Data[11],
+		device_ctx->class_id.Data[12], device_ctx->class_id.Data[13], device_ctx->class_id.Data[14], device_ctx->class_id.Data[15]);
+
+	ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
+		"VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
+		device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], device_ctx->class_id.Data[1], device_ctx->class_id.Data[0],
+		device_ctx->class_id.Data[5], device_ctx->class_id.Data[4],
+		device_ctx->class_id.Data[7], device_ctx->class_id.Data[6],
+		device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], device_ctx->class_id.Data[10], device_ctx->class_id.Data[11],
+		device_ctx->class_id.Data[12], device_ctx->class_id.Data[13], device_ctx->class_id.Data[14], device_ctx->class_id.Data[15]);
+
+	if (ret)
+	{
+		return ret;
+	}
+
+	ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
+		"VMBUS_DEVICE_DEVICE_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
+		device_ctx->device_id.Data[3], device_ctx->device_id.Data[2], device_ctx->device_id.Data[1], device_ctx->device_id.Data[0],
+		device_ctx->device_id.Data[5], device_ctx->device_id.Data[4],
+		device_ctx->device_id.Data[7], device_ctx->device_id.Data[6],
+		device_ctx->device_id.Data[8], device_ctx->device_id.Data[9], device_ctx->device_id.Data[10], device_ctx->device_id.Data[11],
+		device_ctx->device_id.Data[12], device_ctx->device_id.Data[13], device_ctx->device_id.Data[14], device_ctx->device_id.Data[15]);
+
+	if (ret)
+	{
+		return ret;
+	}
+
+	envp[i] = NULL;
+
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return 0;
+}
+#endif
+
+/*++
+
+Name:	vmbus_match()
+
+Desc:	Attempt to match the specified device to the specified driver
+
+--*/
+static int vmbus_match(struct device *device, struct device_driver *driver)
+{
+	int match=0;
+	struct driver_context *driver_ctx = driver_to_driver_context(driver);
+	struct device_context *device_ctx = device_to_device_context(device);
+
+	DPRINT_ENTER(VMBUS_DRV);
+
+	// We found our driver ?
+	if (memcmp(&device_ctx->class_id, &driver_ctx->class_id, sizeof(GUID)) == 0)
+	{
+		// !! NOTE: The driver_ctx is not a vmbus_drv_ctx. We typecast it here to access the
+		// DRIVER_OBJECT field
+		struct vmbus_driver_context *vmbus_drv_ctx = (struct vmbus_driver_context*)driver_ctx;
+		device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj.Base;
+		DPRINT_INFO(VMBUS_DRV, "device object (%p) set to driver object (%p)", &device_ctx->device_obj, device_ctx->device_obj.Driver);
+
+		match = 1;
+	}
+
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return match;
+}
+
+
+/*++
+
+Name:	vmbus_probe_failed_cb()
+
+Desc:	Callback when a driver probe failed in vmbus_probe(). We need a callback because
+		we cannot invoked device_unregister() inside vmbus_probe() since vmbus_probe() may be
+		invoked inside device_register() i.e. we cannot call device_unregister() inside
+		device_register()
+--*/
+#ifdef KERNEL_2_6_27
+static void vmbus_probe_failed_cb(struct work_struct *context)
+#else
+static void vmbus_probe_failed_cb(void* context)
+#endif
+{
+	struct device_context *device_ctx = (struct device_context*)context;
+
+
+	DPRINT_ENTER(VMBUS_DRV);
+
+	// Kick off the process of unregistering the device.
+	// This will call vmbus_remove() and eventually vmbus_device_release()
+	device_unregister(&device_ctx->device);
+
+	//put_device(&device_ctx->device);
+	DPRINT_EXIT(VMBUS_DRV);
+}
+
+
+/*++
+
+Name:	vmbus_probe()
+
+Desc:	Add the new vmbus's child device
+
+--*/
+static int vmbus_probe(struct device *child_device)
+{
+	int ret=0;
+	struct driver_context *driver_ctx = driver_to_driver_context(child_device->driver);
+	struct device_context *device_ctx = device_to_device_context(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);
+		if (ret != 0)
+		{
+			DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s (%p) on driver %s (%d)...", child_device->bus_id, child_device, child_device->driver->name, ret);
+
+#ifdef KERNEL_2_6_27
+			INIT_WORK(&device_ctx->probe_failed_work_item, vmbus_probe_failed_cb);
+#else
+			INIT_WORK(&device_ctx->probe_failed_work_item, vmbus_probe_failed_cb, device_ctx);
+#endif
+			schedule_work(&device_ctx->probe_failed_work_item);
+		}
+	}
+	else
+	{
+		DPRINT_ERR(VMBUS_DRV, "probe() method not set for driver - %s", child_device->driver->name);
+		ret = -1;
+	}
+
+	DPRINT_EXIT(VMBUS_DRV);
+	return ret;
+}
+
+
+/*++
+
+Name:	vmbus_remove()
+
+Desc:	Remove a vmbus device
+
+--*/
+static int vmbus_remove(struct device *child_device)
+{
+	int ret=0;
+	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;
+	}
+
+	if (child_device->driver)
+	{
+		driver_ctx = driver_to_driver_context(child_device->driver);
+
+		// Let the specific open-source driver handles the removal if it can
+		if (driver_ctx->remove)
+		{
+			ret = driver_ctx->remove(child_device);
+		}
+		else
+		{
+			DPRINT_ERR(VMBUS_DRV, "remove() method not set for driver - %s", child_device->driver->name);
+			ret = -1;
+		}
+	}
+	else
+	{
+
+	}
+
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return 0;
+}
+
+/*++
+
+Name:	vmbus_shutdown()
+
+Desc:	Shutdown a vmbus device
+
+--*/
+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);
+		return;
+	}
+
+	driver_ctx = driver_to_driver_context(child_device->driver);
+
+	// Let the specific open-source driver handles the removal if it can
+	if (driver_ctx->shutdown)
+	{
+		driver_ctx->shutdown(child_device);
+	}
+
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return;
+}
+
+/*++
+
+Name:	vmbus_bus_release()
+
+Desc:	Final callback release of the vmbus root device
+
+--*/
+static void vmbus_bus_release(struct device *device)
+{
+	DPRINT_ENTER(VMBUS_DRV);
+	DPRINT_EXIT(VMBUS_DRV);
+}
+
+/*++
+
+Name:	vmbus_device_release()
+
+Desc:	Final callback release of the vmbus child device
+
+--*/
+static void vmbus_device_release(struct device *device)
+{
+	struct device_context *device_ctx = device_to_device_context(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;
+}
+
+/*++
+
+Name:	vmbus_msg_dpc()
+
+Desc:	Tasklet routine to handle hypervisor messages
+
+--*/
+static void vmbus_msg_dpc(unsigned long data)
+{
+	VMBUS_DRIVER_OBJECT* vmbus_drv_obj = (VMBUS_DRIVER_OBJECT*)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);
+}
+
+/*++
+
+Name:	vmbus_msg_dpc()
+
+Desc:	Tasklet routine to handle hypervisor events
+
+--*/
+static void vmbus_event_dpc(unsigned long data)
+{
+	VMBUS_DRIVER_OBJECT* vmbus_drv_obj = (VMBUS_DRIVER_OBJECT*)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);
+}
+
+/*++
+
+Name:	vmbus_msg_dpc()
+
+Desc:	ISR routine
+
+--*/
+#ifdef KERNEL_2_6_27
+static irqreturn_t vmbus_isr(int irq, void* dev_id)
+#else
+static int vmbus_isr(int irq, void* dev_id, struct pt_regs *regs)
+#endif
+{
+	int ret=0;
+	VMBUS_DRIVER_OBJECT* vmbus_driver_obj = &g_vmbus_drv.drv_obj;
+
+	DPRINT_ENTER(VMBUS_DRV);
+
+	ASSERT(vmbus_driver_obj->OnIsr != NULL);
+
+	// Call to bus driver to handle interrupt
+	ret = vmbus_driver_obj->OnIsr(&vmbus_driver_obj->Base);
+
+	// Schedules a dpc if necessary
+	if (ret > 0)
+	{
+		if (test_bit(0, (unsigned long*)&ret))
+		{
+			tasklet_schedule(&g_vmbus_drv.msg_dpc);
+		}
+
+		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;
+	}
+}
+
+MODULE_LICENSE("GPL");
+
+
+/*++
+
+Name:	vmbus_init()
+
+Desc:	Main vmbus driver entry routine
+
+--*/
+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));
+#ifdef KERNEL_2_6_27
+//Todo: it is used for loglevel, to be ported to new kernel.
+#else
+	vmbus_ctl_table_hdr = register_sysctl_table(vmus_root_ctl_table, 0);
+	if (!vmbus_ctl_table_hdr)
+	{
+		DPRINT_EXIT(VMBUS_DRV);
+		return -ENOMEM;
+	}
+#endif
+
+	ret = vmbus_bus_init(VmbusInitialize);
+
+	DPRINT_EXIT(VMBUS_DRV);
+	return ret;
+}
+
+
+
+/*++
+
+Name:	vmbus_init()
+
+Desc:	Main vmbus driver exit routine
+
+--*/
+static void __exit vmbus_exit(void)
+{
+	DPRINT_ENTER(VMBUS_DRV);
+
+	vmbus_bus_exit();
+#ifdef KERNEL_2_6_27
+//Todo: it is used for loglevel, to be ported to new kernel.
+#else
+	unregister_sysctl_table(vmbus_ctl_table_hdr);
+#endif
+	DPRINT_EXIT(VMBUS_DRV);
+
+	return;
+}
+
+#if defined(KERNEL_2_6_5)
+#else
+module_param(vmbus_irq, int, S_IRUGO);
+module_param(vmbus_loglevel, int, S_IRUGO);
+#endif
+
+module_init(vmbus_init);
+module_exit(vmbus_exit);
+// eof
--- /dev/null
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -0,0 +1,170 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _VMBUS_PRIVATE_H_
+#define _VMBUS_PRIVATE_H_
+
+#ifndef INTERNAL
+#define INTERNAL static
+#endif
+
+#include "Hv.h"
+#include "VmbusApi.h"
+#include "Channel.h"
+#include "ChannelMgmt.h"
+#include "ChannelInterface.h"
+//#include "ChannelMessages.h"
+#include "RingBuffer.h"
+//#include "Packet.h"
+#include "List.h"
+
+//
+// Defines
+//
+
+// Maximum channels is determined by the size of the interrupt page which is PAGE_SIZE. 1/2 of PAGE_SIZE is for
+// send endpoint interrupt and the other is receive endpoint interrupt
+#define MAX_NUM_CHANNELS				(PAGE_SIZE >> 1) << 3  // 16348 channels
+
+// The value here must be in multiple of 32
+// TODO: Need to make this configurable
+#define MAX_NUM_CHANNELS_SUPPORTED		256
+
+//
+// Data types
+//
+
+typedef enum {
+	Disconnected,
+	Connecting,
+	Connected,
+	Disconnecting
+} VMBUS_CONNECT_STATE;
+
+#define MAX_SIZE_CHANNEL_MESSAGE			HV_MESSAGE_PAYLOAD_BYTE_COUNT
+
+typedef struct _VMBUS_CONNECTION {
+
+	VMBUS_CONNECT_STATE					ConnectState;
+
+	UINT32								NextGpadlHandle;
+
+	// Represents channel interrupts. Each bit position
+	// represents a channel.
+	// When a channel sends an interrupt via VMBUS, it
+	// finds its bit in the sendInterruptPage, set it and
+	// calls Hv to generate a port event. The other end
+	// receives the port event and parse the recvInterruptPage
+	// to see which bit is set
+	VOID*								InterruptPage;
+	VOID*								SendInterruptPage;
+	VOID*								RecvInterruptPage;
+
+	// 2 pages - 1st page for parent->child notification and 2nd is child->parent notification
+	VOID*								MonitorPages;
+	LIST_ENTRY							ChannelMsgList;
+	HANDLE								ChannelMsgLock;
+
+	// List of channels
+	LIST_ENTRY							ChannelList;
+	HANDLE								ChannelLock;
+
+	HANDLE								WorkQueue;
+} VMBUS_CONNECTION;
+
+
+typedef struct _VMBUS_MSGINFO {
+	// Bookkeeping stuff
+	LIST_ENTRY			MsgListEntry;
+
+	// Synchronize the request/response if needed
+	HANDLE				WaitEvent;
+
+	// The message itself
+	unsigned char		Msg[0];
+} VMBUS_MSGINFO;
+
+
+//
+// Externs
+//
+extern VMBUS_CONNECTION gVmbusConnection;
+
+//
+// General vmbus interface
+//
+INTERNAL DEVICE_OBJECT*
+VmbusChildDeviceCreate(
+	GUID deviceType,
+	GUID deviceInstance,
+	void *context);
+
+INTERNAL int
+VmbusChildDeviceAdd(
+	DEVICE_OBJECT* Device);
+
+INTERNAL void
+VmbusChildDeviceRemove(
+   DEVICE_OBJECT* Device);
+
+//INTERNAL void
+//VmbusChildDeviceDestroy(
+//	DEVICE_OBJECT*);
+
+INTERNAL VMBUS_CHANNEL*
+GetChannelFromRelId(
+	UINT32 relId
+	);
+
+//
+// Connection interface
+//
+INTERNAL int
+VmbusConnect(
+	VOID
+	);
+
+INTERNAL int
+VmbusDisconnect(
+	VOID
+	);
+
+INTERNAL int
+VmbusPostMessage(
+	PVOID			buffer,
+	SIZE_T			bufSize
+	);
+
+INTERNAL int
+VmbusSetEvent(
+	UINT32 childRelId
+	);
+
+INTERNAL VOID
+VmbusOnEvents(
+  VOID
+	);
+
+
+#endif // _VMBUS_PRIVATE_H_

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 04/54] Staging: hv: add the Hyper-V virtual block driver
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (3 preceding siblings ...)
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-virtual-block-driver.patch --]
[-- Type: text/plain, Size: 45789 bytes --]

From: Hank Janssen <hjanssen@microsoft.com>

This is the virtual block driver when running Linux on top of Hyper-V.

Signed-off-by: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/BlkVsc.c     |  107 ++
 drivers/staging/hv/blkvsc_drv.c | 1547 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1654 insertions(+)
 create mode 100644 drivers/staging/hv/blkvsc.c

--- /dev/null
+++ b/drivers/staging/hv/BlkVsc.c
@@ -0,0 +1,107 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "../storvsc/StorVsc.c"
+
+static const char* gBlkDriverName="blkvsc";
+
+//{32412632-86cb-44a2-9b5c-50d1417354f5}
+static const GUID gBlkVscDeviceType={
+	.Data = {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5}
+};
+
+// Static routines
+static int
+BlkVscOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	);
+
+
+int
+BlkVscInitialize(
+	DRIVER_OBJECT *Driver
+	)
+{
+	STORVSC_DRIVER_OBJECT* storDriver = (STORVSC_DRIVER_OBJECT*)Driver;
+	int ret=0;
+
+	DPRINT_ENTER(BLKVSC);
+
+	// Make sure we are at least 2 pages since 1 page is used for control
+	ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1));
+
+	Driver->name = gBlkDriverName;
+	memcpy(&Driver->deviceType, &gBlkVscDeviceType, sizeof(GUID));
+
+	storDriver->RequestExtSize			= sizeof(STORVSC_REQUEST_EXTENSION);
+	// Divide the ring buffer data size (which is 1 page less than the ring buffer size since that page is reserved for the ring buffer indices)
+	// by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + UINT64)
+	storDriver->MaxOutstandingRequestsPerChannel =
+		((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(UINT64),sizeof(UINT64)));
+
+	DPRINT_INFO(BLKVSC, "max io outstd %u", storDriver->MaxOutstandingRequestsPerChannel);
+
+	// Setup the dispatch table
+	storDriver->Base.OnDeviceAdd		= BlkVscOnDeviceAdd;
+	storDriver->Base.OnDeviceRemove		= StorVscOnDeviceRemove;
+	storDriver->Base.OnCleanup			= StorVscOnCleanup;
+
+	storDriver->OnIORequest				= StorVscOnIORequest;
+
+	DPRINT_EXIT(BLKVSC);
+
+	return ret;
+}
+
+int
+BlkVscOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	)
+{
+	int ret=0;
+	STORVSC_DEVICE_INFO *deviceInfo = (STORVSC_DEVICE_INFO*)AdditionalInfo;
+
+	DPRINT_ENTER(BLKVSC);
+
+	ret = StorVscOnDeviceAdd(Device, AdditionalInfo);
+
+	if (ret != 0)
+	{
+		DPRINT_EXIT(BLKVSC);
+
+		return ret;
+	}
+
+	// We need to use the device instance guid to set the path and target id. For IDE devices, the
+	// device instance id is formatted as <bus id> - <device id> - 8899 - 000000000000.
+	deviceInfo->PathId = Device->deviceInstance.Data[3] << 24 | Device->deviceInstance.Data[2] << 16 |
+		Device->deviceInstance.Data[1] << 8 |Device->deviceInstance.Data[0];
+
+	deviceInfo->TargetId = Device->deviceInstance.Data[5] << 8 | Device->deviceInstance.Data[4];
+
+	DPRINT_EXIT(BLKVSC);
+
+	return ret;
+}
--- /dev/null
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -0,0 +1,1547 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/blkdev.h>
+#include <linux/major.h>
+#include <linux/delay.h>
+#include <linux/hdreg.h>
+
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_eh.h>
+#include <scsi/scsi_dbg.h>
+
+#include "logging.h"
+#include "vmbus.h"
+
+#include "StorVscApi.h"
+
+//
+// #defines
+//
+#define BLKVSC_MINORS	64
+
+//
+// Data types
+//
+enum blkvsc_device_type {
+	UNKNOWN_DEV_TYPE,
+	HARDDISK_TYPE,
+	DVD_TYPE,
+};
+
+// This request ties the struct request and struct blkvsc_request/STORVSC_REQUEST together
+// A struct request may be represented by 1 or more struct blkvsc_request
+struct blkvsc_request_group {
+	int					outstanding;
+	int					status;
+
+	struct list_head	blkvsc_req_list;	// list of blkvsc_requests
+};
+
+
+struct blkvsc_request {
+	struct list_head	req_entry;			// blkvsc_request_group.blkvsc_req_list
+
+	struct list_head	pend_entry;			// block_device_context.pending_list
+
+	struct request		*req;				// This may be null if we generate a request internally
+	struct block_device_context	*dev;
+	struct blkvsc_request_group	*group;		// The group this request is part of. Maybe null
+
+	wait_queue_head_t	wevent;
+	int cond;
+
+	int					write;
+	sector_t			sector_start;
+	unsigned long		sector_count;
+
+	unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE];
+	unsigned char cmd_len;
+	unsigned char cmnd[MAX_COMMAND_SIZE];
+
+	STORVSC_REQUEST		request;
+	// !!!DO NOT ADD ANYTHING BELOW HERE!!! Otherwise, memory can overlap, because -
+	// The extension buffer falls right here and is pointed to by request.Extension;
+};
+
+// Per device structure
+struct block_device_context {
+	struct device_context	*device_ctx; // point back to our device context
+	struct kmem_cache	*request_pool;
+	spinlock_t				lock;
+	struct gendisk			*gd;
+	enum blkvsc_device_type	device_type;
+	struct list_head		pending_list;
+
+	unsigned char			device_id[64];
+	unsigned int			device_id_len;
+	int						num_outstanding_reqs;
+	int						shutting_down;
+	int						media_not_present;
+	unsigned int			sector_size;
+	sector_t				capacity;
+	unsigned int			port;
+	unsigned char			path;
+	unsigned char			target;
+	int						users;
+};
+
+// Per driver
+struct blkvsc_driver_context {
+	// !! These must be the first 2 fields !!
+	struct driver_context	drv_ctx;
+	STORVSC_DRIVER_OBJECT	drv_obj;
+};
+
+// Static decl
+static int blkvsc_probe(struct device *dev);
+static int blkvsc_remove(struct device *device);
+static void blkvsc_shutdown(struct device *device);
+
+static int blkvsc_open(struct inode *inode, struct file *filep);
+static int blkvsc_release(struct inode *inode, struct file *filep);
+static int blkvsc_media_changed(struct gendisk *gd);
+static int blkvsc_revalidate_disk(struct gendisk *gd);
+static int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg);
+static int blkvsc_ioctl(struct inode *inode, struct file *filep, unsigned cmd, unsigned long arg);
+
+static void blkvsc_request(struct request_queue *queue);
+static void blkvsc_request_completion(STORVSC_REQUEST* request);
+static int blkvsc_do_request(struct block_device_context *blkdev, struct request *req);
+static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*request_completion)(STORVSC_REQUEST*) );
+static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req);
+static void blkvsc_cmd_completion(STORVSC_REQUEST* request);
+static int blkvsc_do_inquiry(struct block_device_context *blkdev);
+static int blkvsc_do_read_capacity(struct block_device_context *blkdev);
+static int blkvsc_do_read_capacity16(struct block_device_context *blkdev);
+static int blkvsc_do_flush(struct block_device_context *blkdev);
+static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev);
+static int blkvsc_do_pending_reqs(struct block_device_context *blkdev);
+
+
+static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
+
+// The one and only one
+static struct blkvsc_driver_context g_blkvsc_drv;
+
+
+static struct block_device_operations block_ops =
+{
+	.owner = THIS_MODULE,
+	.open = blkvsc_open,
+	.release = blkvsc_release,
+	.media_changed = blkvsc_media_changed,
+	.revalidate_disk = blkvsc_revalidate_disk,
+	.getgeo = blkvsc_getgeo,
+	.ioctl  = blkvsc_ioctl,
+};
+
+/*++
+
+Name:	blkvsc_drv_init()
+
+Desc:	BlkVsc driver initialization.
+
+--*/
+int blkvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init)
+{
+	int ret=0;
+	STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_blkvsc_drv.drv_obj;
+	struct driver_context *drv_ctx=&g_blkvsc_drv.drv_ctx;
+
+	DPRINT_ENTER(BLKVSC_DRV);
+
+	vmbus_get_interface(&storvsc_drv_obj->Base.VmbusChannelInterface);
+
+	storvsc_drv_obj->RingBufferSize = blkvsc_ringbuffer_size;
+
+	// Callback to client driver to complete the initialization
+	pfn_drv_init(&storvsc_drv_obj->Base);
+
+	drv_ctx->driver.name = storvsc_drv_obj->Base.name;
+	memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, sizeof(GUID));
+
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+	drv_ctx->driver.probe = blkvsc_probe;
+	drv_ctx->driver.remove = blkvsc_remove;
+#else
+	drv_ctx->probe = blkvsc_probe;
+	drv_ctx->remove = blkvsc_remove;
+	drv_ctx->shutdown = blkvsc_shutdown;
+#endif
+
+	// The driver belongs to vmbus
+	vmbus_child_driver_register(drv_ctx);
+
+	DPRINT_EXIT(BLKVSC_DRV);
+
+	return ret;
+}
+
+
+static int blkvsc_drv_exit_cb(struct device *dev, void *data)
+{
+	struct device **curr = (struct device **)data;
+	*curr = dev;
+	return 1; // stop iterating
+}
+
+/*++
+
+Name:	blkvsc_drv_exit()
+
+Desc:
+
+--*/
+void blkvsc_drv_exit(void)
+{
+	STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_blkvsc_drv.drv_obj;
+	struct driver_context *drv_ctx=&g_blkvsc_drv.drv_ctx;
+
+	struct device *current_dev=NULL;
+
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#define driver_for_each_device(drv, start, data, fn) \
+	struct list_head *ptr, *n; \
+	list_for_each_safe(ptr, n, &((drv)->devices)) {\
+		struct device *curr_dev;\
+		curr_dev = list_entry(ptr, struct device, driver_list);\
+		fn(curr_dev, data);\
+	}
+#endif // KERNEL_2_6_9
+
+	DPRINT_ENTER(BLKVSC_DRV);
+
+	while (1)
+	{
+		current_dev = NULL;
+
+		// Get the device
+		driver_for_each_device(&drv_ctx->driver, NULL, (void*)&current_dev, blkvsc_drv_exit_cb);
+
+		if (current_dev == NULL)
+			break;
+
+		// Initiate removal from the top-down
+		device_unregister(current_dev);
+	}
+
+	if (storvsc_drv_obj->Base.OnCleanup)
+		storvsc_drv_obj->Base.OnCleanup(&storvsc_drv_obj->Base);
+
+	vmbus_child_driver_unregister(drv_ctx);
+
+	DPRINT_EXIT(BLKVSC_DRV);
+
+	return;
+}
+
+/*++
+
+Name:	blkvsc_probe()
+
+Desc:	Add a new device for this driver
+
+--*/
+static int blkvsc_probe(struct device *device)
+{
+	int ret=0;
+
+	struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
+	struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx;
+	STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+
+	struct device_context *device_ctx = device_to_device_context(device);
+	DEVICE_OBJECT* device_obj = &device_ctx->device_obj;
+
+	struct block_device_context *blkdev=NULL;
+	STORVSC_DEVICE_INFO device_info;
+	int major=0;
+	int devnum=0;
+
+	static int ide0_registered=0;
+	static int ide1_registered=0;
+
+	DPRINT_ENTER(BLKVSC_DRV);
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_probe - enter");
+
+	if (!storvsc_drv_obj->Base.OnDeviceAdd)
+	{
+		DPRINT_ERR(BLKVSC_DRV, "OnDeviceAdd() not set");
+
+		ret = -1;
+		goto Cleanup;
+	}
+
+	blkdev = kzalloc(sizeof(struct block_device_context), GFP_KERNEL);
+	if (!blkdev)
+	{
+		ret = -ENOMEM;
+		goto Cleanup;
+	}
+
+	INIT_LIST_HEAD(&blkdev->pending_list);
+
+	// Initialize what we can here
+	spin_lock_init(&blkdev->lock);
+
+	ASSERT(sizeof(struct blkvsc_request_group) <= sizeof(struct blkvsc_request));
+
+#ifdef KERNEL_2_6_27
+        blkdev->request_pool = kmem_cache_create(device_ctx->device.bus_id,
+                sizeof(struct blkvsc_request) + storvsc_drv_obj->RequestExtSize, 0,
+                SLAB_HWCACHE_ALIGN, NULL);
+#else
+	blkdev->request_pool = kmem_cache_create(device_ctx->device.bus_id,
+		sizeof(struct blkvsc_request) + storvsc_drv_obj->RequestExtSize, 0,
+		SLAB_HWCACHE_ALIGN, NULL, NULL);
+#endif
+	if (!blkdev->request_pool)
+	{
+		ret = -ENOMEM;
+		goto Cleanup;
+	}
+
+
+	// Call to the vsc driver to add the device
+	ret = storvsc_drv_obj->Base.OnDeviceAdd(device_obj, &device_info);
+	if (ret != 0)
+	{
+		DPRINT_ERR(BLKVSC_DRV, "unable to add blkvsc device");
+		goto Cleanup;
+	}
+
+	blkdev->device_ctx = device_ctx;
+	blkdev->target = device_info.TargetId; // this identified the device 0 or 1
+	blkdev->path = device_info.PathId; // this identified the ide ctrl 0 or 1
+
+	device->driver_data = blkdev;
+
+	// Calculate the major and device num
+	if (blkdev->path == 0)
+	{
+		major = IDE0_MAJOR;
+		devnum = blkdev->path + blkdev->target;		// 0 or 1
+
+		if (!ide0_registered)
+		{
+			ret = register_blkdev(major, "ide");
+			if (ret != 0)
+			{
+				DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret);
+				goto Remove;
+			}
+
+			ide0_registered = 1;
+		}
+	}
+	else if (blkdev->path == 1)
+	{
+		major = IDE1_MAJOR;
+		devnum = blkdev->path + blkdev->target + 1; // 2 or 3
+
+		if (!ide1_registered)
+		{
+			ret = register_blkdev(major, "ide");
+			if (ret != 0)
+			{
+				DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret);
+				goto Remove;
+			}
+
+			ide1_registered = 1;
+		}
+
+	}
+	else
+	{
+		DPRINT_ERR(BLKVSC_DRV, "invalid pathid");
+		ret = -1;
+		goto Cleanup;
+	}
+
+	DPRINT_INFO(BLKVSC_DRV, "blkvsc registered for major %d!!", major);
+
+	blkdev->gd = alloc_disk(BLKVSC_MINORS);
+	if (!blkdev->gd)
+	{
+		DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret);
+		ret = -1;
+		goto Cleanup;
+	}
+
+	blkdev->gd->queue = blk_init_queue(blkvsc_request, &blkdev->lock);
+
+	blk_queue_max_segment_size(blkdev->gd->queue, PAGE_SIZE);
+	blk_queue_max_phys_segments(blkdev->gd->queue, MAX_MULTIPAGE_BUFFER_COUNT);
+	blk_queue_max_hw_segments(blkdev->gd->queue, MAX_MULTIPAGE_BUFFER_COUNT);
+	blk_queue_segment_boundary(blkdev->gd->queue, PAGE_SIZE-1);
+	blk_queue_bounce_limit(blkdev->gd->queue, BLK_BOUNCE_ANY);
+	blk_queue_dma_alignment(blkdev->gd->queue, 511);
+
+	blkdev->gd->major = major;
+	if (devnum == 1 || devnum == 3)
+		blkdev->gd->first_minor = BLKVSC_MINORS;
+	else
+		blkdev->gd->first_minor = 0;
+	blkdev->gd->fops = &block_ops;
+	blkdev->gd->private_data = blkdev;
+	sprintf(blkdev->gd->disk_name, "hd%c", 'a'+ devnum);
+
+	blkvsc_do_inquiry(blkdev);
+	if (blkdev->device_type == DVD_TYPE)
+	{
+		set_disk_ro(blkdev->gd, 1);
+		blkdev->gd->flags |= GENHD_FL_REMOVABLE;
+		blkvsc_do_read_capacity(blkdev);
+	}
+	else
+	{
+		blkvsc_do_read_capacity16(blkdev);
+	}
+
+	set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512));
+	blk_queue_hardsect_size(blkdev->gd->queue, blkdev->sector_size);
+	// go!
+	add_disk(blkdev->gd);
+
+	DPRINT_INFO(BLKVSC_DRV, "%s added!! capacity %llu sector_size %d", blkdev->gd->disk_name, blkdev->capacity, blkdev->sector_size);
+
+	return ret;
+
+Remove:
+	storvsc_drv_obj->Base.OnDeviceRemove(device_obj);
+
+Cleanup:
+	if (blkdev)
+	{
+		if (blkdev->request_pool)
+		{
+			kmem_cache_destroy(blkdev->request_pool);
+			blkdev->request_pool = NULL;
+		}
+		kfree(blkdev);
+		blkdev = NULL;
+	}
+
+	DPRINT_EXIT(BLKVSC_DRV);
+
+	return ret;
+}
+
+static void blkvsc_shutdown(struct device *device)
+{
+	struct block_device_context *blkdev = (struct block_device_context*)device->driver_data;
+	unsigned long flags;
+
+	if (!blkdev)
+		return;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_shutdown - users %d disk %s\n", blkdev->users, blkdev->gd->disk_name);
+
+	spin_lock_irqsave(&blkdev->lock, flags);
+
+	blkdev->shutting_down = 1;
+
+	blk_stop_queue(blkdev->gd->queue);
+
+	spin_unlock_irqrestore(&blkdev->lock, flags);
+
+	while (blkdev->num_outstanding_reqs)
+	{
+		DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", blkdev->num_outstanding_reqs);
+
+		udelay(100);
+	}
+
+	blkvsc_do_flush(blkdev);
+
+	spin_lock_irqsave(&blkdev->lock, flags);
+
+	blkvsc_cancel_pending_reqs(blkdev);
+
+	spin_unlock_irqrestore(&blkdev->lock, flags);
+}
+
+static int blkvsc_do_flush(struct block_device_context *blkdev)
+{
+	struct blkvsc_request *blkvsc_req=NULL;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_flush()\n");
+
+	if (blkdev->device_type != HARDDISK_TYPE)
+		return 0;
+
+	blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
+	if (!blkvsc_req)
+	{
+		return -ENOMEM;
+	}
+
+	memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+	init_waitqueue_head(&blkvsc_req->wevent);
+	blkvsc_req->dev = blkdev;
+	blkvsc_req->req = NULL;
+	blkvsc_req->write = 0;
+
+	blkvsc_req->request.DataBuffer.PfnArray[0] = 0;
+	blkvsc_req->request.DataBuffer.Offset = 0;
+	blkvsc_req->request.DataBuffer.Length = 0;
+
+	blkvsc_req->cmnd[0] = SYNCHRONIZE_CACHE;
+	blkvsc_req->cmd_len = 10;
+
+	// Set this here since the completion routine may be invoked and completed before we return
+	blkvsc_req->cond =0;
+	blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+	wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
+
+	kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+
+	return 0;
+}
+
+// Do a scsi INQUIRY cmd here to get the device type (ie disk or dvd)
+static int blkvsc_do_inquiry(struct block_device_context *blkdev)
+{
+	struct blkvsc_request *blkvsc_req=NULL;
+	struct page *page_buf;
+	unsigned char *buf;
+	unsigned char device_type;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_inquiry()\n");
+
+	blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
+	if (!blkvsc_req)
+	{
+		return -ENOMEM;
+	}
+
+	memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+	page_buf = alloc_page(GFP_KERNEL);
+	if (!page_buf)
+	{
+		kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+		return -ENOMEM;
+	}
+
+	init_waitqueue_head(&blkvsc_req->wevent);
+	blkvsc_req->dev = blkdev;
+	blkvsc_req->req = NULL;
+	blkvsc_req->write = 0;
+
+	blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf);
+	blkvsc_req->request.DataBuffer.Offset = 0;
+	blkvsc_req->request.DataBuffer.Length = 64;
+
+	blkvsc_req->cmnd[0] = INQUIRY;
+	blkvsc_req->cmnd[1] = 0x1;		// Get product data
+	blkvsc_req->cmnd[2] = 0x83;		// mode page 83
+	blkvsc_req->cmnd[4] = 64;
+	blkvsc_req->cmd_len = 6;
+
+	// Set this here since the completion routine may be invoked and completed before we return
+	blkvsc_req->cond =0;
+
+	blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+	DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond);
+
+	wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
+
+	buf = kmap(page_buf);
+
+	//PrintBytes(buf, 64);
+	// be to le
+	device_type = buf[0] & 0x1F;
+
+	if (device_type == 0x0)
+	{
+		blkdev->device_type = HARDDISK_TYPE;
+	}
+	else if (device_type == 0x5)
+	{
+		blkdev->device_type = DVD_TYPE;
+	}
+	else
+	{
+		// TODO: this is currently unsupported device type
+		blkdev->device_type = UNKNOWN_DEV_TYPE;
+	}
+
+	DPRINT_DBG(BLKVSC_DRV, "device type %d \n", device_type);
+
+	blkdev->device_id_len = buf[7];
+	if (blkdev->device_id_len > 64)
+		blkdev->device_id_len = 64;
+
+	memcpy(blkdev->device_id, &buf[8], blkdev->device_id_len);
+	//PrintBytes(blkdev->device_id, blkdev->device_id_len);
+
+	kunmap(page_buf);
+
+	__free_page(page_buf);
+
+	kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+
+	return 0;
+}
+
+// Do a scsi READ_CAPACITY cmd here to get the size of the disk
+static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
+{
+	struct blkvsc_request *blkvsc_req=NULL;
+	struct page *page_buf;
+	unsigned char *buf;
+	struct scsi_sense_hdr sense_hdr;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_read_capacity()\n");
+
+	blkdev->sector_size = 0;
+	blkdev->capacity = 0;
+	blkdev->media_not_present = 0; // assume a disk is present
+
+	blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
+	if (!blkvsc_req)
+	{
+		return -ENOMEM;
+	}
+
+	memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+	page_buf = alloc_page(GFP_KERNEL);
+	if (!page_buf)
+	{
+		kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+		return -ENOMEM;
+	}
+
+	init_waitqueue_head(&blkvsc_req->wevent);
+	blkvsc_req->dev = blkdev;
+	blkvsc_req->req = NULL;
+	blkvsc_req->write = 0;
+
+	blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf);
+	blkvsc_req->request.DataBuffer.Offset = 0;
+	blkvsc_req->request.DataBuffer.Length = 8;
+
+	blkvsc_req->cmnd[0] = READ_CAPACITY;
+	blkvsc_req->cmd_len = 16;
+
+	// Set this here since the completion routine may be invoked and completed before we return
+	blkvsc_req->cond =0;
+
+	blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+	DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond);
+
+	wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
+
+	// check error
+	if (blkvsc_req->request.Status)
+	{
+		scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
+
+		if (sense_hdr.asc == 0x3A) // Medium not present
+		{
+			blkdev->media_not_present = 1;
+		}
+
+		return 0;
+	}
+	buf = kmap(page_buf);
+
+	// be to le
+	blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 1;
+	blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
+
+	kunmap(page_buf);
+
+	__free_page(page_buf);
+
+	kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+
+	return 0;
+}
+
+
+static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
+{
+	struct blkvsc_request *blkvsc_req=NULL;
+	struct page *page_buf;
+	unsigned char *buf;
+	struct scsi_sense_hdr sense_hdr;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_read_capacity16()\n");
+
+	blkdev->sector_size = 0;
+	blkdev->capacity = 0;
+	blkdev->media_not_present = 0; // assume a disk is present
+
+	blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
+	if (!blkvsc_req)
+	{
+		return -ENOMEM;
+	}
+
+	memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+	page_buf = alloc_page(GFP_KERNEL);
+	if (!page_buf)
+	{
+		kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+		return -ENOMEM;
+	}
+
+	init_waitqueue_head(&blkvsc_req->wevent);
+	blkvsc_req->dev = blkdev;
+	blkvsc_req->req = NULL;
+	blkvsc_req->write = 0;
+
+	blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf);
+	blkvsc_req->request.DataBuffer.Offset = 0;
+	blkvsc_req->request.DataBuffer.Length = 12;
+
+	blkvsc_req->cmnd[0] = 0x9E; //READ_CAPACITY16;
+	blkvsc_req->cmd_len = 16;
+
+	// Set this here since the completion routine may be invoked and completed before we return
+	blkvsc_req->cond =0;
+
+	blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+	DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond);
+
+	wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
+
+	// check error
+	if (blkvsc_req->request.Status)
+	{
+		scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
+
+		if (sense_hdr.asc == 0x3A) // Medium not present
+		{
+			blkdev->media_not_present = 1;
+		}
+
+		return 0;
+	}
+	buf = kmap(page_buf);
+
+	// be to le
+	blkdev->capacity = be64_to_cpu(*(unsigned long long*) &buf[0]) + 1;
+	blkdev->sector_size = be32_to_cpu(*(unsigned int*)&buf[8]);
+
+	//blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 1;
+	//blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
+
+	kunmap(page_buf);
+
+	__free_page(page_buf);
+
+	kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+
+	return 0;
+}
+
+/*++
+
+Name:	blkvsc_remove()
+
+Desc:	Callback when our device is removed
+
+--*/
+static int blkvsc_remove(struct device *device)
+{
+	int ret=0;
+
+	struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
+	struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx;
+	STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+
+	struct device_context *device_ctx = device_to_device_context(device);
+	DEVICE_OBJECT* device_obj = &device_ctx->device_obj;
+	struct block_device_context *blkdev = (struct block_device_context*)device->driver_data;
+	unsigned long flags;
+
+	DPRINT_ENTER(BLKVSC_DRV);
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_remove()\n");
+
+	if (!storvsc_drv_obj->Base.OnDeviceRemove)
+	{
+		DPRINT_EXIT(BLKVSC_DRV);
+		return -1;
+	}
+
+	// Call to the vsc driver to let it know that the device is being removed
+	ret = storvsc_drv_obj->Base.OnDeviceRemove(device_obj);
+	if (ret != 0)
+	{
+		// TODO:
+		DPRINT_ERR(BLKVSC_DRV, "unable to remove blkvsc device (ret %d)", ret);
+	}
+
+	// Get to a known state
+	spin_lock_irqsave(&blkdev->lock, flags);
+
+	blkdev->shutting_down = 1;
+
+	blk_stop_queue(blkdev->gd->queue);
+
+	spin_unlock_irqrestore(&blkdev->lock, flags);
+
+	while (blkdev->num_outstanding_reqs)
+	{
+		DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", blkdev->num_outstanding_reqs);
+
+		udelay(100);
+	}
+
+	blkvsc_do_flush(blkdev);
+
+	spin_lock_irqsave(&blkdev->lock, flags);
+
+	blkvsc_cancel_pending_reqs(blkdev);
+
+	spin_unlock_irqrestore(&blkdev->lock, flags);
+
+	blk_cleanup_queue(blkdev->gd->queue);
+
+	del_gendisk(blkdev->gd);
+
+	kmem_cache_destroy(blkdev->request_pool);
+
+	kfree(blkdev);
+
+	DPRINT_EXIT(BLKVSC_DRV);
+
+	return ret;
+}
+
+static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req)
+{
+	ASSERT(blkvsc_req->req);
+	ASSERT(blkvsc_req->sector_count <= (MAX_MULTIPAGE_BUFFER_COUNT*8));
+
+	blkvsc_req->cmd_len = 16;
+
+	if (blkvsc_req->sector_start > 0xffffffff)
+	{
+		if (rq_data_dir(blkvsc_req->req))
+		{
+			blkvsc_req->write = 1;
+			blkvsc_req->cmnd[0] = WRITE_16;
+		}
+		else
+		{
+			blkvsc_req->write = 0;
+			blkvsc_req->cmnd[0] = READ_16;
+		}
+
+		blkvsc_req->cmnd[1] |= blk_fua_rq(blkvsc_req->req) ? 0x8 : 0;
+
+		*(unsigned long long*)&blkvsc_req->cmnd[2] = cpu_to_be64(blkvsc_req->sector_start);
+		*(unsigned int*)&blkvsc_req->cmnd[10] = cpu_to_be32(blkvsc_req->sector_count);
+	}
+	else if ((blkvsc_req->sector_count > 0xff) || (blkvsc_req->sector_start > 0x1fffff))
+	{
+		if (rq_data_dir(blkvsc_req->req))
+		{
+			blkvsc_req->write = 1;
+			blkvsc_req->cmnd[0] = WRITE_10;
+		}
+		else
+		{
+			blkvsc_req->write = 0;
+			blkvsc_req->cmnd[0] = READ_10;
+		}
+
+		blkvsc_req->cmnd[1] |= blk_fua_rq(blkvsc_req->req) ? 0x8 : 0;
+
+		*(unsigned int *)&blkvsc_req->cmnd[2] = cpu_to_be32(blkvsc_req->sector_start);
+		*(unsigned short*)&blkvsc_req->cmnd[7] = cpu_to_be16(blkvsc_req->sector_count);
+    }
+	else
+	{
+		if (rq_data_dir(blkvsc_req->req))
+		{
+			blkvsc_req->write = 1;
+			blkvsc_req->cmnd[0] = WRITE_6;
+		}
+		else
+		{
+			blkvsc_req->write = 0;
+			blkvsc_req->cmnd[0] = READ_6;
+		}
+
+		*(unsigned int *)&blkvsc_req->cmnd[1] = cpu_to_be32(blkvsc_req->sector_start) >> 8;
+		blkvsc_req->cmnd[1] &= 0x1f;
+		blkvsc_req->cmnd[4] = (unsigned char) blkvsc_req->sector_count;
+	}
+}
+
+static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*request_completion)(STORVSC_REQUEST*) )
+{
+	struct block_device_context *blkdev = blkvsc_req->dev;
+	struct device_context *device_ctx=blkdev->device_ctx;
+	struct driver_context *driver_ctx = driver_to_driver_context(device_ctx->device.driver);
+	struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx;
+	STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+	int ret =0;
+
+	STORVSC_REQUEST *storvsc_req;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p type %s start_sector %llu count %d offset %d len %d\n",
+		blkvsc_req,
+		(blkvsc_req->write)?"WRITE":"READ",
+		blkvsc_req->sector_start,
+		blkvsc_req->sector_count,
+		blkvsc_req->request.DataBuffer.Offset,
+		blkvsc_req->request.DataBuffer.Length);
+
+	/*for (i=0; i < (blkvsc_req->request.DataBuffer.Length >> 12); i++)
+	{
+		DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p pfn[%d] %llx\n",
+		blkvsc_req,
+		i,
+		blkvsc_req->request.DataBuffer.PfnArray[i]);
+	}*/
+
+	storvsc_req = &blkvsc_req->request;
+	storvsc_req->Extension = (void*)((unsigned long)blkvsc_req + sizeof(struct blkvsc_request));
+
+	storvsc_req->Type = blkvsc_req->write? WRITE_TYPE : READ_TYPE;
+
+	storvsc_req->OnIOCompletion = request_completion;
+	storvsc_req->Context = blkvsc_req;
+
+	storvsc_req->Host = blkdev->port;
+	storvsc_req->Bus = blkdev->path;
+	storvsc_req->TargetId = blkdev->target;
+	storvsc_req->LunId = 0;	 // this is not really used at all
+
+	storvsc_req->CdbLen = blkvsc_req->cmd_len;
+	storvsc_req->Cdb = blkvsc_req->cmnd;
+
+	storvsc_req->SenseBuffer = blkvsc_req->sense_buffer;
+	storvsc_req->SenseBufferSize = SCSI_SENSE_BUFFERSIZE;
+
+	ret = storvsc_drv_obj->OnIORequest(&blkdev->device_ctx->device_obj, &blkvsc_req->request);
+	if (ret == 0)
+	{
+		blkdev->num_outstanding_reqs++;
+	}
+
+	return ret;
+}
+
+//
+// We break the request into 1 or more blkvsc_requests and submit them.
+// If we cant submit them all, we put them on the pending_list. The
+// blkvsc_request() will work on the pending_list.
+//
+static int blkvsc_do_request(struct block_device_context *blkdev, struct request *req)
+{
+	struct bio *bio=NULL;
+	struct bio_vec *bvec=NULL;
+	struct bio_vec *prev_bvec=NULL;
+
+	struct blkvsc_request *blkvsc_req=NULL;
+	struct blkvsc_request *tmp;
+	int databuf_idx=0;
+	int seg_idx=0;
+
+	sector_t start_sector;
+	unsigned long num_sectors = 0;
+	int ret=0;
+	int pending=0;
+	struct blkvsc_request_group *group=NULL;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %llu \n", blkdev, req, req->sector);
+
+	// Create a group to tie req to list of blkvsc_reqs
+	group = (struct blkvsc_request_group*)kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC);
+	if (!group)
+	{
+		return -ENOMEM;
+	}
+
+	INIT_LIST_HEAD(&group->blkvsc_req_list);
+	group->outstanding = group->status = 0;
+
+	start_sector = req->sector;
+
+	// foreach bio in the request
+	if (req->bio)
+	 for (bio = req->bio; bio; bio = bio->bi_next)
+	{
+		// Map this bio into an existing or new storvsc request
+		bio_for_each_segment (bvec, bio, seg_idx)
+		{
+			DPRINT_DBG(BLKVSC_DRV, "bio_for_each_segment() - req %p bio %p bvec %p seg_idx %d databuf_idx %d\n",
+							req, bio, bvec, seg_idx, databuf_idx);
+
+			// Get a new storvsc request
+			if ( (!blkvsc_req) ||									// 1st-time
+				 (databuf_idx >= MAX_MULTIPAGE_BUFFER_COUNT) ||
+				 (bvec->bv_offset != 0) ||							// hole at the begin of page
+				 (prev_bvec && (prev_bvec->bv_len != PAGE_SIZE)) )	// hold at the end of page
+			{
+				// submit the prev one
+				if (blkvsc_req)
+				{
+					blkvsc_req->sector_start = start_sector;
+					sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9));
+
+					blkvsc_req->sector_count = num_sectors / (blkdev->sector_size >> 9);
+
+					blkvsc_init_rw(blkvsc_req);
+				}
+
+				// Create new blkvsc_req to represent the current bvec
+				blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC);
+				if (!blkvsc_req)
+				{
+					// free up everything
+					list_for_each_entry_safe(blkvsc_req, tmp, &group->blkvsc_req_list, req_entry)
+					{
+						list_del(&blkvsc_req->req_entry);
+						kmem_cache_free(blkdev->request_pool, blkvsc_req);
+					}
+
+					kmem_cache_free(blkdev->request_pool, group);
+					return -ENOMEM;
+				}
+
+				memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+
+				blkvsc_req->dev = blkdev;
+				blkvsc_req->req = req;
+				blkvsc_req->request.DataBuffer.Offset = bvec->bv_offset;
+				blkvsc_req->request.DataBuffer.Length = 0;
+
+				// Add to the group
+				blkvsc_req->group = group;
+				blkvsc_req->group->outstanding++;
+				list_add_tail(&blkvsc_req->req_entry, &blkvsc_req->group->blkvsc_req_list);
+
+				start_sector += num_sectors;
+				num_sectors = 0;
+				databuf_idx = 0;
+			}
+
+			// Add the curr bvec/segment to the curr blkvsc_req
+			blkvsc_req->request.DataBuffer.PfnArray[databuf_idx] = page_to_pfn(bvec->bv_page);
+			blkvsc_req->request.DataBuffer.Length += bvec->bv_len;
+
+			prev_bvec = bvec;
+
+			databuf_idx++;
+			num_sectors += bvec->bv_len >> 9;
+
+		} // bio_for_each_segment
+
+	} // rq_for_each_bio
+
+	// Handle the last one
+	if (blkvsc_req)
+	{
+		DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p group %p count %d\n", blkdev, req, blkvsc_req->group, blkvsc_req->group->outstanding);
+
+		blkvsc_req->sector_start = start_sector;
+		sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9));
+
+		blkvsc_req->sector_count = num_sectors / (blkdev->sector_size >> 9);
+
+		blkvsc_init_rw(blkvsc_req);
+	}
+
+	list_for_each_entry(blkvsc_req, &group->blkvsc_req_list, req_entry)
+	{
+		if (pending)
+		{
+			DPRINT_DBG(BLKVSC_DRV, "adding blkvsc_req to pending_list - blkvsc_req %p start_sect %llu sect_count %d (%llu %d)\n",
+				blkvsc_req, blkvsc_req->sector_start, blkvsc_req->sector_count, start_sector, num_sectors);
+
+			list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list);
+		}
+		else
+		{
+			ret = blkvsc_submit_request(blkvsc_req, blkvsc_request_completion);
+			if (ret == -1)
+			{
+				pending = 1;
+				list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list);
+			}
+
+			DPRINT_DBG(BLKVSC_DRV, "submitted blkvsc_req %p start_sect %llu sect_count %d (%llu %d) ret %d\n",
+				blkvsc_req, blkvsc_req->sector_start, blkvsc_req->sector_count, start_sector, num_sectors, ret);
+		}
+	}
+
+	return pending;
+}
+
+static void blkvsc_cmd_completion(STORVSC_REQUEST* request)
+{
+	struct blkvsc_request *blkvsc_req=(struct blkvsc_request*)request->Context;
+	struct block_device_context *blkdev = (struct block_device_context*)blkvsc_req->dev;
+
+	struct scsi_sense_hdr sense_hdr;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_cmd_completion() - req %p\n", blkvsc_req);
+
+	blkdev->num_outstanding_reqs--;
+
+	if (blkvsc_req->request.Status)
+	{
+		if (scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr))
+		{
+			scsi_print_sense_hdr("blkvsc", &sense_hdr);
+		}
+	}
+
+	blkvsc_req->cond =1;
+	wake_up_interruptible(&blkvsc_req->wevent);
+}
+
+static void blkvsc_request_completion(STORVSC_REQUEST* request)
+{
+	struct blkvsc_request *blkvsc_req=(struct blkvsc_request*)request->Context;
+	struct block_device_context *blkdev = (struct block_device_context*)blkvsc_req->dev;
+	unsigned long flags;
+	struct blkvsc_request *comp_req, *tmp;
+
+	ASSERT(blkvsc_req->group);
+
+	DPRINT_DBG(BLKVSC_DRV, "blkdev %p blkvsc_req %p group %p type %s sect_start %llu sect_count %d len %d group outstd %d total outstd %d\n",
+		blkdev,
+		blkvsc_req,
+		blkvsc_req->group,
+		(blkvsc_req->write)?"WRITE":"READ",
+		blkvsc_req->sector_start,
+		blkvsc_req->sector_count,
+		blkvsc_req->request.DataBuffer.Length,
+		blkvsc_req->group->outstanding,
+		blkdev->num_outstanding_reqs);
+
+	spin_lock_irqsave(&blkdev->lock, flags);
+
+	blkdev->num_outstanding_reqs--;
+	blkvsc_req->group->outstanding--;
+
+	// Only start processing when all the blkvsc_reqs are completed. This guarantees no out-of-order
+	// blkvsc_req completion when calling end_that_request_first()
+	if (blkvsc_req->group->outstanding == 0)
+	{
+		list_for_each_entry_safe(comp_req, tmp, &blkvsc_req->group->blkvsc_req_list, req_entry)
+		{
+			DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %llu sect_count %d \n",
+				comp_req,
+				comp_req->sector_start,
+				comp_req->sector_count);
+
+			list_del(&comp_req->req_entry);
+
+#ifdef KERNEL_2_6_27
+			if (!__blk_end_request(
+				comp_req->req,
+				(!comp_req->request.Status ? 0: -EIO),
+				comp_req->sector_count * blkdev->sector_size))
+			{
+				//All the sectors have been xferred ie the request is done
+				DPRINT_DBG(BLKVSC_DRV, "req %p COMPLETED\n", comp_req->req);
+				kmem_cache_free(blkdev->request_pool, comp_req->group);
+			}
+#else
+			if (!end_that_request_first(comp_req->req, !comp_req->request.Status,  (comp_req->sector_count * (blkdev->sector_size >> 9))))
+			{
+				//All the sectors have been xferred ie the request is done
+				DPRINT_DBG(BLKVSC_DRV, "req %p COMPLETED\n", comp_req->req);
+
+				end_that_request_last(comp_req->req, !comp_req->request.Status);
+
+				kmem_cache_free(blkdev->request_pool, comp_req->group);
+			}
+#endif
+
+			kmem_cache_free(blkdev->request_pool, comp_req);
+		}
+
+		if (!blkdev->shutting_down)
+		{
+			blkvsc_do_pending_reqs(blkdev);
+			blk_start_queue(blkdev->gd->queue);
+			blkvsc_request(blkdev->gd->queue);
+		}
+	}
+
+	spin_unlock_irqrestore(&blkdev->lock, flags);
+}
+
+static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev)
+{
+	struct blkvsc_request *pend_req, *tmp;
+	struct blkvsc_request *comp_req, *tmp2;
+
+	int ret=0;
+
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs()");
+
+	// Flush the pending list first
+	list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, pend_entry)
+	{
+		// The pend_req could be part of a partially completed request. If so, complete those req first
+		// until we hit the pend_req
+		list_for_each_entry_safe(comp_req, tmp2, &pend_req->group->blkvsc_req_list, req_entry)
+		{
+			DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %llu sect_count %d \n",
+				comp_req,
+				comp_req->sector_start,
+				comp_req->sector_count);
+
+			if (comp_req == pend_req)
+				break;
+
+			list_del(&comp_req->req_entry);
+
+			if (comp_req->req)
+			{
+#ifdef KERNEL_2_6_27
+			ret = __blk_end_request(
+			    comp_req->req,
+			    (!comp_req->request.Status ? 0 : -EIO),
+			    comp_req->sector_count * blkdev->sector_size);
+#else
+			ret = end_that_request_first(comp_req->req, !comp_req->request.Status,  (comp_req->sector_count * (blkdev->sector_size >> 9)));
+#endif
+			ASSERT(ret != 0);
+			}
+
+			kmem_cache_free(blkdev->request_pool, comp_req);
+		}
+
+		DPRINT_DBG(BLKVSC_DRV, "cancelling pending request - %p\n", pend_req);
+
+		list_del(&pend_req->pend_entry);
+
+		list_del(&pend_req->req_entry);
+
+		if (comp_req->req)
+		{
+#ifdef KERNEL_2_6_27
+		if (!__blk_end_request(
+			pend_req->req,
+			-EIO,
+			pend_req->sector_count * blkdev->sector_size))
+		{
+			//All the sectors have been xferred ie the request is done
+			DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs() - req %p COMPLETED\n", pend_req->req);
+			kmem_cache_free(blkdev->request_pool, pend_req->group);
+		}
+#else
+		if (!end_that_request_first(pend_req->req, 0,  (pend_req->sector_count * (blkdev->sector_size >> 9))))
+		{
+			//All the sectors have been xferred ie the request is done
+			DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs() - req %p COMPLETED\n", pend_req->req);
+
+			end_that_request_last(pend_req->req, 0);
+
+			kmem_cache_free(blkdev->request_pool, pend_req->group);
+		}
+#endif
+		}
+
+		kmem_cache_free(blkdev->request_pool, pend_req);
+	}
+
+	return ret;
+}
+
+static int blkvsc_do_pending_reqs(struct block_device_context *blkdev)
+{
+	struct blkvsc_request *pend_req, *tmp;
+	int ret=0;
+
+	// Flush the pending list first
+	list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, pend_entry)
+	{
+		DPRINT_DBG(BLKVSC_DRV, "working off pending_list - %p\n", pend_req);
+
+		ret = blkvsc_submit_request(pend_req, blkvsc_request_completion);
+		if (ret != 0)
+		{
+			break;
+		}
+		else
+		{
+			list_del(&pend_req->pend_entry);
+		}
+	}
+
+	return ret;
+}
+
+static void blkvsc_request(struct request_queue *queue)
+{
+	struct block_device_context *blkdev = NULL;
+	struct request *req;
+	int ret=0;
+
+	DPRINT_DBG(BLKVSC_DRV, "- enter \n");
+	while ((req = elv_next_request(queue)) != NULL)
+	{
+		DPRINT_DBG(BLKVSC_DRV, "- req %p\n", req);
+
+		blkdev = req->rq_disk->private_data;
+		if (blkdev->shutting_down || !blk_fs_request(req) || blkdev->media_not_present) {
+			end_request(req, 0);
+			continue;
+		}
+
+		ret = blkvsc_do_pending_reqs(blkdev);
+
+		if (ret != 0)
+		{
+			DPRINT_DBG(BLKVSC_DRV, "- stop queue - pending_list not empty\n");
+			blk_stop_queue(queue);
+			break;
+		}
+
+		blkdev_dequeue_request(req);
+
+		ret = blkvsc_do_request(blkdev, req);
+		if (ret > 0)
+		{
+			DPRINT_DBG(BLKVSC_DRV, "- stop queue - no room\n");
+			blk_stop_queue(queue);
+			break;
+		}
+		else if (ret < 0)
+		{
+			DPRINT_DBG(BLKVSC_DRV, "- stop queue - no mem\n");
+			blk_requeue_request(queue, req);
+			blk_stop_queue(queue);
+			break;
+		}
+	}
+}
+
+static int blkvsc_open(struct inode *inode, struct file *filep)
+{
+	struct block_device_context *blkdev = inode->i_bdev->bd_disk->private_data;
+
+	DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, blkdev->gd->disk_name);
+
+	spin_lock(&blkdev->lock);
+
+	if (!blkdev->users && blkdev->device_type == DVD_TYPE)
+	{
+		spin_unlock(&blkdev->lock);
+		check_disk_change(inode->i_bdev);
+		spin_lock(&blkdev->lock);
+	}
+
+	blkdev->users++;
+
+	spin_unlock(&blkdev->lock);
+	return 0;
+}
+
+static int blkvsc_release(struct inode *inode, struct file *filep)
+{
+	struct block_device_context *blkdev = inode->i_bdev->bd_disk->private_data;
+
+	DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, blkdev->gd->disk_name);
+
+	spin_lock(&blkdev->lock);
+	if (blkdev->users == 1)
+	{
+		spin_unlock(&blkdev->lock);
+		blkvsc_do_flush(blkdev);
+		spin_lock(&blkdev->lock);
+	}
+
+	blkdev->users--;
+
+	spin_unlock(&blkdev->lock);
+	return 0;
+}
+
+static int blkvsc_media_changed(struct gendisk *gd)
+{
+	DPRINT_DBG(BLKVSC_DRV, "- enter\n");
+
+	return 1;
+}
+
+static int blkvsc_revalidate_disk(struct gendisk *gd)
+{
+	struct block_device_context *blkdev = gd->private_data;
+
+	DPRINT_DBG(BLKVSC_DRV, "- enter\n");
+
+	if (blkdev->device_type == DVD_TYPE)
+	{
+		blkvsc_do_read_capacity(blkdev);
+		set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512));
+		blk_queue_hardsect_size(gd->queue, blkdev->sector_size);
+	}
+	return 0;
+}
+
+int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg)
+{
+	sector_t total_sectors = get_capacity(bd->bd_disk);
+	sector_t cylinder_times_heads=0;
+	sector_t temp=0;
+
+	int sectors_per_track=0;
+	int heads=0;
+	int cylinders=0;
+	int rem=0;
+
+    if (total_sectors > (65535 * 16 * 255)) {
+        total_sectors = (65535 * 16 * 255);
+    }
+
+    if (total_sectors >= (65535 * 16 * 63)) {
+        sectors_per_track = 255;
+        heads = 16;
+
+		cylinder_times_heads = total_sectors;
+		rem = sector_div(cylinder_times_heads, sectors_per_track); // sector_div stores the quotient in cylinder_times_heads
+    }
+	else
+	{
+        sectors_per_track = 17;
+
+		cylinder_times_heads = total_sectors;
+        rem = sector_div(cylinder_times_heads, sectors_per_track); 	// sector_div stores the quotient in cylinder_times_heads
+
+		temp = cylinder_times_heads + 1023;
+		rem = sector_div(temp, 1024); 	// sector_div stores the quotient in temp
+
+		heads = temp;
+
+        if (heads < 4) {
+            heads = 4;
+        }
+
+        if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) {
+            sectors_per_track = 31;
+            heads = 16;
+
+			cylinder_times_heads = total_sectors;
+            rem = sector_div(cylinder_times_heads, sectors_per_track); // sector_div stores the quotient in cylinder_times_heads
+        }
+
+        if (cylinder_times_heads >= (heads * 1024)) {
+            sectors_per_track = 63;
+            heads = 16;
+
+			cylinder_times_heads = total_sectors;
+            rem = sector_div(cylinder_times_heads, sectors_per_track); // sector_div stores the quotient in cylinder_times_heads
+        }
+    }
+
+	temp = cylinder_times_heads;
+    rem = sector_div(temp, heads); // sector_div stores the quotient in temp
+	cylinders = temp;
+
+	hg->heads = heads;
+    hg->sectors = sectors_per_track;
+    hg->cylinders = cylinders;
+
+	DPRINT_INFO(BLKVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads, sectors_per_track);
+
+    return 0;
+}
+
+static int blkvsc_ioctl(struct inode *inode, struct file *filep, unsigned cmd, unsigned long arg)
+{
+	struct block_device *bd = inode->i_bdev;
+	struct block_device_context *blkdev = bd->bd_disk->private_data;
+	int ret=0;
+
+	switch (cmd)
+	{
+	// TODO: I think there is certain format for HDIO_GET_IDENTITY rather than just
+	// a GUID. Commented it out for now.
+	/*case HDIO_GET_IDENTITY:
+		DPRINT_INFO(BLKVSC_DRV, "HDIO_GET_IDENTITY\n");
+
+		if (copy_to_user((void __user *)arg, blkdev->device_id, blkdev->device_id_len))
+		{
+			ret = -EFAULT;
+		}
+
+		break;*/
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+
+
+MODULE_LICENSE("GPL");
+
+static int __init blkvsc_init(void)
+{
+	int ret;
+
+	ASSERT(sizeof(sector_t) == 8); // Make sure CONFIG_LBD is set
+
+	DPRINT_ENTER(BLKVSC_DRV);
+
+	DPRINT_INFO(BLKVSC_DRV, "Blkvsc initializing....");
+
+	ret = blkvsc_drv_init(BlkVscInitialize);
+
+	DPRINT_EXIT(BLKVSC_DRV);
+
+	return ret;
+}
+
+static void __exit blkvsc_exit(void)
+{
+	DPRINT_ENTER(BLKVSC_DRV);
+
+	blkvsc_drv_exit();
+
+	DPRINT_ENTER(BLKVSC_DRV);
+}
+
+module_param(blkvsc_ringbuffer_size, int, S_IRUGO);
+
+module_init(blkvsc_init);
+module_exit(blkvsc_exit);
+
+// eof

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 05/54] Staging: hv: add the Hyper-V virtual network driver
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (4 preceding siblings ...)
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-virtual-network-driver.patch --]
[-- Type: text/plain, Size: 92738 bytes --]

From: Hank Janssen <hjanssen@microsoft.com>

This is the virtual network driver when running Linux on top of Hyper-V.

Signed-off-by: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/NetVsc.c      | 1499 +++++++++++++++++++++++++++++++++++++++
 drivers/staging/hv/NetVsc.h      |   91 ++
 drivers/staging/hv/RndisFilter.c | 1162 ++++++++++++++++++++++++++++++
 drivers/staging/hv/RndisFilter.h |   61 +
 drivers/staging/hv/netvsc_drv.c  |  720 ++++++++++++++++++
 5 files changed, 3533 insertions(+)
 create mode 100644 drivers/staging/hv/netvsc.c

--- /dev/null
+++ b/drivers/staging/hv/NetVsc.c
@@ -0,0 +1,1499 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "logging.h"
+#include "NetVsc.h"
+#include "RndisFilter.h"
+
+
+//
+// Globals
+//
+static const char* gDriverName="netvsc";
+
+// {F8615163-DF3E-46c5-913F-F2D2F965ED0E}
+static const GUID gNetVscDeviceType={
+	.Data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}
+};
+
+
+//
+// Internal routines
+//
+static int
+NetVscOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	);
+
+static int
+NetVscOnDeviceRemove(
+	DEVICE_OBJECT *Device
+	);
+
+static void
+NetVscOnCleanup(
+	DRIVER_OBJECT *Driver
+	);
+
+static void
+NetVscOnChannelCallback(
+	PVOID context
+	);
+
+static int
+NetVscInitializeSendBufferWithNetVsp(
+	DEVICE_OBJECT			*Device
+	);
+
+static int
+NetVscInitializeReceiveBufferWithNetVsp(
+	DEVICE_OBJECT			*Device
+	);
+
+static int
+NetVscDestroySendBuffer(
+	NETVSC_DEVICE	*NetDevice
+	);
+
+static int
+NetVscDestroyReceiveBuffer(
+	NETVSC_DEVICE	*NetDevice
+	);
+
+static int
+NetVscConnectToVsp(
+	DEVICE_OBJECT		*Device
+	);
+
+static void
+NetVscOnSendCompletion(
+	DEVICE_OBJECT		*Device,
+	VMPACKET_DESCRIPTOR *Packet
+	);
+
+static int
+NetVscOnSend(
+	DEVICE_OBJECT	*Device,
+	NETVSC_PACKET	*Packet
+	);
+
+static void
+NetVscOnReceive(
+	DEVICE_OBJECT		*Device,
+	VMPACKET_DESCRIPTOR *Packet
+	);
+
+static void
+NetVscOnReceiveCompletion(
+	PVOID Context
+	);
+
+static void
+NetVscSendReceiveCompletion(
+	DEVICE_OBJECT	*Device,
+	UINT64			TransactionId
+	);
+
+static inline NETVSC_DEVICE* AllocNetDevice(DEVICE_OBJECT *Device)
+{
+	NETVSC_DEVICE *netDevice;
+
+	netDevice = MemAllocZeroed(sizeof(NETVSC_DEVICE));
+	if (!netDevice)
+		return NULL;
+
+	// Set to 2 to allow both inbound and outbound traffic
+	InterlockedCompareExchange(&netDevice->RefCount, 2, 0);
+
+	netDevice->Device = Device;
+	Device->Extension = netDevice;
+
+	return netDevice;
+}
+
+static inline void FreeNetDevice(NETVSC_DEVICE *Device)
+{
+	ASSERT(Device->RefCount == 0);
+	Device->Device->Extension = NULL;
+	MemFree(Device);
+}
+
+
+// Get the net device object iff exists and its refcount > 1
+static inline NETVSC_DEVICE* GetOutboundNetDevice(DEVICE_OBJECT	*Device)
+{
+	NETVSC_DEVICE *netDevice;
+
+	netDevice = (NETVSC_DEVICE*)Device->Extension;
+	if (netDevice && netDevice->RefCount > 1)
+	{
+		InterlockedIncrement(&netDevice->RefCount);
+	}
+	else
+	{
+		netDevice = NULL;
+	}
+
+	return netDevice;
+}
+
+// Get the net device object iff exists and its refcount > 0
+static inline NETVSC_DEVICE* GetInboundNetDevice(DEVICE_OBJECT	*Device)
+{
+	NETVSC_DEVICE *netDevice;
+
+	netDevice = (NETVSC_DEVICE*)Device->Extension;
+	if (netDevice && netDevice->RefCount)
+	{
+		InterlockedIncrement(&netDevice->RefCount);
+	}
+	else
+	{
+		netDevice = NULL;
+	}
+
+	return netDevice;
+}
+
+static inline void PutNetDevice(DEVICE_OBJECT *Device)
+{
+	NETVSC_DEVICE *netDevice;
+
+	netDevice = (NETVSC_DEVICE*)Device->Extension;
+	ASSERT(netDevice);
+
+	InterlockedDecrement(&netDevice->RefCount);
+}
+
+static inline NETVSC_DEVICE* ReleaseOutboundNetDevice(DEVICE_OBJECT *Device)
+{
+	NETVSC_DEVICE *netDevice;
+
+	netDevice = (NETVSC_DEVICE*)Device->Extension;
+	if (netDevice == NULL)
+		return NULL;
+
+	// Busy wait until the ref drop to 2, then set it to 1
+	while (InterlockedCompareExchange(&netDevice->RefCount, 1, 2) != 2)
+	{
+		Sleep(100);
+	}
+
+	return netDevice;
+}
+
+static inline NETVSC_DEVICE* ReleaseInboundNetDevice(DEVICE_OBJECT *Device)
+{
+	NETVSC_DEVICE *netDevice;
+
+	netDevice = (NETVSC_DEVICE*)Device->Extension;
+	if (netDevice == NULL)
+		return NULL;
+
+	// Busy wait until the ref drop to 1, then set it to 0
+	while (InterlockedCompareExchange(&netDevice->RefCount, 0, 1) != 1)
+	{
+		Sleep(100);
+	}
+
+	Device->Extension = NULL;
+	return netDevice;
+}
+
+/*++;
+
+
+Name:
+	NetVscInitialize()
+
+Description:
+	Main entry point
+
+--*/
+int
+NetVscInitialize(
+	DRIVER_OBJECT *drv
+	)
+{
+	NETVSC_DRIVER_OBJECT* driver = (NETVSC_DRIVER_OBJECT*)drv;
+	int ret=0;
+
+	DPRINT_ENTER(NETVSC);
+
+	DPRINT_DBG(NETVSC, "sizeof(NETVSC_PACKET)=%d, sizeof(NVSP_MESSAGE)=%d, sizeof(VMTRANSFER_PAGE_PACKET_HEADER)=%d",
+		sizeof(NETVSC_PACKET), sizeof(NVSP_MESSAGE), sizeof(VMTRANSFER_PAGE_PACKET_HEADER));
+
+	// Make sure we are at least 2 pages since 1 page is used for control
+	ASSERT(driver->RingBufferSize >= (PAGE_SIZE << 1));
+
+	drv->name = gDriverName;
+	memcpy(&drv->deviceType, &gNetVscDeviceType, sizeof(GUID));
+
+	// Make sure it is set by the caller
+	ASSERT(driver->OnReceiveCallback);
+	ASSERT(driver->OnLinkStatusChanged);
+
+	// Setup the dispatch table
+	driver->Base.OnDeviceAdd		= NetVscOnDeviceAdd;
+	driver->Base.OnDeviceRemove		= NetVscOnDeviceRemove;
+	driver->Base.OnCleanup			= NetVscOnCleanup;
+
+	driver->OnSend					= NetVscOnSend;
+
+	RndisFilterInit(driver);
+
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+static int
+NetVscInitializeReceiveBufferWithNetVsp(
+	DEVICE_OBJECT	*Device
+	)
+{
+	int ret=0;
+	NETVSC_DEVICE *netDevice;
+	NVSP_MESSAGE *initPacket;
+
+	DPRINT_ENTER(NETVSC);
+
+	netDevice = GetOutboundNetDevice(Device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?");
+		DPRINT_EXIT(NETVSC);
+		return -1;
+	}
+	ASSERT(netDevice->ReceiveBufferSize > 0);
+	ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE-1)) == 0); // page-size grandularity
+
+	netDevice->ReceiveBuffer = PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT);
+	if (!netDevice->ReceiveBuffer)
+	{
+		DPRINT_ERR(NETVSC, "unable to allocate receive buffer of size %d", netDevice->ReceiveBufferSize);
+		ret = -1;
+		goto Cleanup;
+	}
+	ASSERT(((ULONG_PTR)netDevice->ReceiveBuffer & (PAGE_SIZE-1)) == 0); // page-aligned buffer
+
+	DPRINT_INFO(NETVSC, "Establishing receive buffer's GPADL...");
+
+	// Establish the gpadl handle for this buffer on this channel.
+	// Note: This call uses the vmbus connection rather than the channel to establish
+	// the gpadl handle.
+	ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device,
+																netDevice->ReceiveBuffer,
+																netDevice->ReceiveBufferSize,
+																&netDevice->ReceiveBufferGpadlHandle);
+
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "unable to establish receive buffer's gpadl");
+		goto Cleanup;
+	}
+
+	//WaitEventWait(ext->ChannelInitEvent);
+
+	// Notify the NetVsp of the gpadl handle
+	DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer...");
+
+	initPacket = &netDevice->ChannelInitPacket;
+
+	memset(initPacket, 0, sizeof(NVSP_MESSAGE));
+
+    initPacket->Header.MessageType = NvspMessage1TypeSendReceiveBuffer;
+    initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->ReceiveBufferGpadlHandle;
+    initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID;
+
+	// Send the gpadl notification request
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															initPacket,
+															sizeof(NVSP_MESSAGE),
+															(ULONG_PTR)initPacket,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp");
+		goto Cleanup;
+	}
+
+	WaitEventWait(netDevice->ChannelInitEvent);
+
+	// Check the response
+	if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess)
+	{
+		DPRINT_ERR(NETVSC,
+			"Unable to complete receive buffer initialzation with NetVsp - status %d",
+			initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status);
+		ret = -1;
+		goto Cleanup;
+	}
+
+	// Parse the response
+	ASSERT(netDevice->ReceiveSectionCount == 0);
+	ASSERT(netDevice->ReceiveSections == NULL);
+
+	netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections;
+
+	netDevice->ReceiveSections = MemAlloc(netDevice->ReceiveSectionCount * sizeof(NVSP_1_RECEIVE_BUFFER_SECTION));
+	if (netDevice->ReceiveSections == NULL)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	memcpy(netDevice->ReceiveSections,
+		initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Sections,
+		netDevice->ReceiveSectionCount * sizeof(NVSP_1_RECEIVE_BUFFER_SECTION));
+
+	DPRINT_INFO(NETVSC,
+		"Receive sections info (count %d, offset %d, endoffset %d, suballoc size %d, num suballocs %d)",
+		netDevice->ReceiveSectionCount, netDevice->ReceiveSections[0].Offset, netDevice->ReceiveSections[0].EndOffset,
+		netDevice->ReceiveSections[0].SubAllocationSize, netDevice->ReceiveSections[0].NumSubAllocations);
+
+
+	//For 1st release, there should only be 1 section that represents the entire receive buffer
+	if (netDevice->ReceiveSectionCount != 1 ||
+		netDevice->ReceiveSections->Offset != 0 )
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	goto Exit;
+
+Cleanup:
+	NetVscDestroyReceiveBuffer(netDevice);
+
+Exit:
+	PutNetDevice(Device);
+	DPRINT_EXIT(NETVSC);
+	return ret;
+}
+
+
+static int
+NetVscInitializeSendBufferWithNetVsp(
+	DEVICE_OBJECT	*Device
+	)
+{
+	int ret=0;
+	NETVSC_DEVICE *netDevice;
+	NVSP_MESSAGE *initPacket;
+
+	DPRINT_ENTER(NETVSC);
+
+	netDevice = GetOutboundNetDevice(Device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?");
+		DPRINT_EXIT(NETVSC);
+		return -1;
+	}
+	ASSERT(netDevice->SendBufferSize > 0);
+	ASSERT((netDevice->SendBufferSize & (PAGE_SIZE-1)) == 0); // page-size grandularity
+
+	netDevice->SendBuffer = PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT);
+	if (!netDevice->SendBuffer)
+	{
+		DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", netDevice->SendBufferSize);
+		ret = -1;
+		goto Cleanup;
+	}
+	ASSERT(((ULONG_PTR)netDevice->SendBuffer & (PAGE_SIZE-1)) == 0); // page-aligned buffer
+
+	DPRINT_INFO(NETVSC, "Establishing send buffer's GPADL...");
+
+	// Establish the gpadl handle for this buffer on this channel.
+	// Note: This call uses the vmbus connection rather than the channel to establish
+	// the gpadl handle.
+	ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device,
+																netDevice->SendBuffer,
+																netDevice->SendBufferSize,
+																&netDevice->SendBufferGpadlHandle);
+
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl");
+		goto Cleanup;
+	}
+
+	//WaitEventWait(ext->ChannelInitEvent);
+
+	// Notify the NetVsp of the gpadl handle
+	DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer...");
+
+	initPacket = &netDevice->ChannelInitPacket;
+
+	memset(initPacket, 0, sizeof(NVSP_MESSAGE));
+
+    initPacket->Header.MessageType = NvspMessage1TypeSendSendBuffer;
+    initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->SendBufferGpadlHandle;
+    initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_SEND_BUFFER_ID;
+
+	// Send the gpadl notification request
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															initPacket,
+															sizeof(NVSP_MESSAGE),
+															(ULONG_PTR)initPacket,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp");
+		goto Cleanup;
+	}
+
+	WaitEventWait(netDevice->ChannelInitEvent);
+
+	// Check the response
+	if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess)
+	{
+		DPRINT_ERR(NETVSC,
+			"Unable to complete send buffer initialzation with NetVsp - status %d",
+			initPacket->Messages.Version1Messages.SendSendBufferComplete.Status);
+		ret = -1;
+		goto Cleanup;
+	}
+
+	netDevice->SendSectionSize = initPacket->Messages.Version1Messages.SendSendBufferComplete.SectionSize;
+
+	goto Exit;
+
+Cleanup:
+	NetVscDestroySendBuffer(netDevice);
+
+Exit:
+	PutNetDevice(Device);
+	DPRINT_EXIT(NETVSC);
+	return ret;
+}
+
+static int
+NetVscDestroyReceiveBuffer(
+	NETVSC_DEVICE	*NetDevice
+	)
+{
+	NVSP_MESSAGE *revokePacket;
+	int ret=0;
+
+
+	DPRINT_ENTER(NETVSC);
+
+	// If we got a section count, it means we received a SendReceiveBufferComplete msg
+	// (ie sent NvspMessage1TypeSendReceiveBuffer msg) therefore, we need to send a revoke msg here
+	if (NetDevice->ReceiveSectionCount)
+	{
+		DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeRevokeReceiveBuffer...");
+
+		// Send the revoke receive buffer
+		revokePacket = &NetDevice->RevokePacket;
+		memset(revokePacket, 0, sizeof(NVSP_MESSAGE));
+
+		revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer;
+		revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID;
+
+		ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device,
+																			revokePacket,
+																			sizeof(NVSP_MESSAGE),
+																			(ULONG_PTR)revokePacket,
+																			VmbusPacketTypeDataInBand,
+																			0);
+		// If we failed here, we might as well return and have a leak rather than continue and a bugchk
+		if (ret != 0)
+		{
+			DPRINT_ERR(NETVSC, "unable to send revoke receive buffer to netvsp");
+			DPRINT_EXIT(NETVSC);
+			return -1;
+		}
+	}
+
+	// Teardown the gpadl on the vsp end
+	if (NetDevice->ReceiveBufferGpadlHandle)
+	{
+		DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL...");
+
+		ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device,
+																				NetDevice->ReceiveBufferGpadlHandle);
+
+		// If we failed here, we might as well return and have a leak rather than continue and a bugchk
+		if (ret != 0)
+		{
+			DPRINT_ERR(NETVSC, "unable to teardown receive buffer's gpadl");
+			DPRINT_EXIT(NETVSC);
+			return -1;
+		}
+		NetDevice->ReceiveBufferGpadlHandle = 0;
+	}
+
+	if (NetDevice->ReceiveBuffer)
+	{
+		DPRINT_INFO(NETVSC, "Freeing up receive buffer...");
+
+		// Free up the receive buffer
+		PageFree(NetDevice->ReceiveBuffer, NetDevice->ReceiveBufferSize >> PAGE_SHIFT);
+		NetDevice->ReceiveBuffer = NULL;
+	}
+
+	if (NetDevice->ReceiveSections)
+	{
+		MemFree(NetDevice->ReceiveSections);
+		NetDevice->ReceiveSections = NULL;
+		NetDevice->ReceiveSectionCount = 0;
+	}
+
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+
+
+
+static int
+NetVscDestroySendBuffer(
+	NETVSC_DEVICE	*NetDevice
+	)
+{
+	NVSP_MESSAGE *revokePacket;
+	int ret=0;
+
+
+	DPRINT_ENTER(NETVSC);
+
+	// If we got a section count, it means we received a SendReceiveBufferComplete msg
+	// (ie sent NvspMessage1TypeSendReceiveBuffer msg) therefore, we need to send a revoke msg here
+	if (NetDevice->SendSectionSize)
+	{
+		DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeRevokeSendBuffer...");
+
+		// Send the revoke send buffer
+		revokePacket = &NetDevice->RevokePacket;
+		memset(revokePacket, 0, sizeof(NVSP_MESSAGE));
+
+		revokePacket->Header.MessageType = NvspMessage1TypeRevokeSendBuffer;
+		revokePacket->Messages.Version1Messages.RevokeSendBuffer.Id = NETVSC_SEND_BUFFER_ID;
+
+		ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device,
+																			revokePacket,
+																			sizeof(NVSP_MESSAGE),
+																			(ULONG_PTR)revokePacket,
+																			VmbusPacketTypeDataInBand,
+																			0);
+		// If we failed here, we might as well return and have a leak rather than continue and a bugchk
+		if (ret != 0)
+		{
+			DPRINT_ERR(NETVSC, "unable to send revoke send buffer to netvsp");
+			DPRINT_EXIT(NETVSC);
+			return -1;
+		}
+	}
+
+	// Teardown the gpadl on the vsp end
+	if (NetDevice->SendBufferGpadlHandle)
+	{
+		DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL...");
+
+		ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device,
+																				NetDevice->SendBufferGpadlHandle);
+
+		// If we failed here, we might as well return and have a leak rather than continue and a bugchk
+		if (ret != 0)
+		{
+			DPRINT_ERR(NETVSC, "unable to teardown send buffer's gpadl");
+			DPRINT_EXIT(NETVSC);
+			return -1;
+		}
+		NetDevice->SendBufferGpadlHandle = 0;
+	}
+
+	if (NetDevice->SendBuffer)
+	{
+		DPRINT_INFO(NETVSC, "Freeing up send buffer...");
+
+		// Free up the receive buffer
+		PageFree(NetDevice->SendBuffer, NetDevice->SendBufferSize >> PAGE_SHIFT);
+		NetDevice->SendBuffer = NULL;
+	}
+
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+
+
+static int
+NetVscConnectToVsp(
+	DEVICE_OBJECT	*Device
+	)
+{
+	int ret=0;
+	NETVSC_DEVICE *netDevice;
+	NVSP_MESSAGE *initPacket;
+	int ndisVersion;
+
+	DPRINT_ENTER(NETVSC);
+
+	netDevice = GetOutboundNetDevice(Device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?");
+		DPRINT_EXIT(NETVSC);
+		return -1;
+	}
+
+	initPacket = &netDevice->ChannelInitPacket;
+
+	memset(initPacket, 0, sizeof(NVSP_MESSAGE));
+	initPacket->Header.MessageType = NvspMessageTypeInit;
+    initPacket->Messages.InitMessages.Init.MinProtocolVersion = NVSP_MIN_PROTOCOL_VERSION;
+    initPacket->Messages.InitMessages.Init.MaxProtocolVersion = NVSP_MAX_PROTOCOL_VERSION;
+
+	DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit...");
+
+	// Send the init request
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															initPacket,
+															sizeof(NVSP_MESSAGE),
+															(ULONG_PTR)initPacket,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+
+	if( ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "unable to send NvspMessageTypeInit");
+		goto Cleanup;
+	}
+
+	WaitEventWait(netDevice->ChannelInitEvent);
+
+	// Now, check the response
+	//ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT);
+	DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)",
+		initPacket->Messages.InitMessages.InitComplete.Status,
+		initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength);
+
+	if (initPacket->Messages.InitMessages.InitComplete.Status != NvspStatusSuccess)
+	{
+		DPRINT_ERR(NETVSC, "unable to initialize with netvsp (status 0x%x)", initPacket->Messages.InitMessages.InitComplete.Status);
+		ret = -1;
+		goto Cleanup;
+	}
+
+	if (initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion != NVSP_PROTOCOL_VERSION_1)
+	{
+		DPRINT_ERR(NETVSC, "unable to initialize with netvsp (version expected 1 got %d)",
+			initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion);
+		ret = -1;
+		goto Cleanup;
+	}
+	DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion...");
+
+	// Send the ndis version
+	memset(initPacket, 0, sizeof(NVSP_MESSAGE));
+
+    ndisVersion = 0x00050000;
+
+    initPacket->Header.MessageType = NvspMessage1TypeSendNdisVersion;
+    initPacket->Messages.Version1Messages.SendNdisVersion.NdisMajorVersion = (ndisVersion & 0xFFFF0000) >> 16;
+    initPacket->Messages.Version1Messages.SendNdisVersion.NdisMinorVersion = ndisVersion & 0xFFFF;
+
+	// Send the init request
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															initPacket,
+															sizeof(NVSP_MESSAGE),
+															(ULONG_PTR)initPacket,
+															VmbusPacketTypeDataInBand,
+															0);
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "unable to send NvspMessage1TypeSendNdisVersion");
+		ret = -1;
+		goto Cleanup;
+	}
+	//
+	// BUGBUG - We have to wait for the above msg since the netvsp uses KMCL which acknowledges packet (completion packet)
+	// since our Vmbus always set the VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag
+	//WaitEventWait(NetVscChannel->ChannelInitEvent);
+
+	// Post the big receive buffer to NetVSP
+	ret = NetVscInitializeReceiveBufferWithNetVsp(Device);
+	if (ret == 0)
+	{
+		ret = NetVscInitializeSendBufferWithNetVsp(Device);
+	}
+
+Cleanup:
+	PutNetDevice(Device);
+	DPRINT_EXIT(NETVSC);
+	return ret;
+}
+
+static void
+NetVscDisconnectFromVsp(
+	NETVSC_DEVICE	*NetDevice
+	)
+{
+	DPRINT_ENTER(NETVSC);
+
+	NetVscDestroyReceiveBuffer(NetDevice);
+	NetVscDestroySendBuffer(NetDevice);
+
+	DPRINT_EXIT(NETVSC);
+}
+
+
+/*++
+
+Name:
+	NetVscOnDeviceAdd()
+
+Description:
+	Callback when the device belonging to this driver is added
+
+--*/
+int
+NetVscOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	)
+{
+	int ret=0;
+	int i;
+
+	NETVSC_DEVICE* netDevice;
+	NETVSC_PACKET* packet;
+	LIST_ENTRY *entry;
+
+	NETVSC_DRIVER_OBJECT *netDriver = (NETVSC_DRIVER_OBJECT*) Device->Driver;;
+
+	DPRINT_ENTER(NETVSC);
+
+	netDevice = AllocNetDevice(Device);
+	if (!netDevice)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", netDevice);
+
+	// Initialize the NetVSC channel extension
+	netDevice->ReceiveBufferSize = NETVSC_RECEIVE_BUFFER_SIZE;
+	netDevice->ReceivePacketListLock = SpinlockCreate();
+
+	netDevice->SendBufferSize = NETVSC_SEND_BUFFER_SIZE;
+
+	INITIALIZE_LIST_HEAD(&netDevice->ReceivePacketList);
+
+	for (i=0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++)
+	{
+		packet = MemAllocZeroed(sizeof(NETVSC_PACKET) + (NETVSC_RECEIVE_SG_COUNT* sizeof(PAGE_BUFFER)));
+		if (!packet)
+		{
+			DPRINT_DBG(NETVSC, "unable to allocate netvsc pkts for receive pool (wanted %d got %d)", NETVSC_RECEIVE_PACKETLIST_COUNT, i);
+			break;
+		}
+
+		INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry);
+	}
+	netDevice->ChannelInitEvent = WaitEventCreate();
+
+	// Open the channel
+	ret = Device->Driver->VmbusChannelInterface.Open(Device,
+														netDriver->RingBufferSize,
+														netDriver->RingBufferSize,
+														NULL, 0,
+														NetVscOnChannelCallback,
+														Device
+														);
+
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "unable to open channel: %d", ret);
+		ret = -1;
+		goto Cleanup;
+	}
+
+	// Channel is opened
+	DPRINT_INFO(NETVSC, "*** NetVSC channel opened successfully! ***");
+
+	// Connect with the NetVsp
+	ret = NetVscConnectToVsp(Device);
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret);
+		ret = -1;
+		goto Close;
+	}
+
+	DPRINT_INFO(NETVSC, "*** NetVSC channel handshake result - %d ***", ret);
+
+	DPRINT_EXIT(NETVSC);
+	return ret;
+
+Close:
+	// Now, we can close the channel safely
+	Device->Driver->VmbusChannelInterface.Close(Device);
+
+Cleanup:
+
+	if (netDevice)
+	{
+		WaitEventClose(netDevice->ChannelInitEvent);
+
+		while (!IsListEmpty(&netDevice->ReceivePacketList))
+		{
+			entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
+			packet = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+			MemFree(packet);
+		}
+
+		SpinlockClose(netDevice->ReceivePacketListLock);
+
+		ReleaseOutboundNetDevice(Device);
+		ReleaseInboundNetDevice(Device);
+
+		FreeNetDevice(netDevice);
+	}
+
+	DPRINT_EXIT(NETVSC);
+	return ret;
+}
+
+
+/*++
+
+Name:
+	NetVscOnDeviceRemove()
+
+Description:
+	Callback when the root bus device is removed
+
+--*/
+int
+NetVscOnDeviceRemove(
+	DEVICE_OBJECT *Device
+	)
+{
+	NETVSC_DEVICE *netDevice;
+	NETVSC_PACKET *netvscPacket;
+	int ret=0;
+	LIST_ENTRY *entry;
+
+	DPRINT_ENTER(NETVSC);
+
+	DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", Device->Extension);
+
+	// Stop outbound traffic ie sends and receives completions
+	netDevice = ReleaseOutboundNetDevice(Device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "No net device present!!");
+		return -1;
+	}
+
+	// Wait for all send completions
+	while (netDevice->NumOutstandingSends)
+	{
+		DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", netDevice->NumOutstandingSends);
+
+		Sleep(100);
+	}
+
+	DPRINT_INFO(NETVSC, "Disconnecting from netvsp...");
+
+	NetVscDisconnectFromVsp(netDevice);
+
+	DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", Device->Extension);
+
+	// Stop inbound traffic ie receives and sends completions
+	netDevice = ReleaseInboundNetDevice(Device);
+
+	// At this point, no one should be accessing netDevice except in here
+	DPRINT_INFO(NETVSC, "net device (%p) safe to remove", netDevice);
+
+	// Now, we can close the channel safely
+	Device->Driver->VmbusChannelInterface.Close(Device);
+
+	// Release all resources
+	while (!IsListEmpty(&netDevice->ReceivePacketList))
+	{
+		entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
+		netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+
+		MemFree(netvscPacket);
+	}
+
+	SpinlockClose(netDevice->ReceivePacketListLock);
+	WaitEventClose(netDevice->ChannelInitEvent);
+	FreeNetDevice(netDevice);
+
+	DPRINT_EXIT(NETVSC);
+	return ret;
+}
+
+
+
+/*++
+
+Name:
+	NetVscOnCleanup()
+
+Description:
+	Perform any cleanup when the driver is removed
+
+--*/
+void
+NetVscOnCleanup(
+	DRIVER_OBJECT *drv
+	)
+{
+	DPRINT_ENTER(NETVSC);
+
+	DPRINT_EXIT(NETVSC);
+}
+
+static void
+NetVscOnSendCompletion(
+	DEVICE_OBJECT		*Device,
+	VMPACKET_DESCRIPTOR *Packet
+	)
+{
+	NETVSC_DEVICE* netDevice;
+	NVSP_MESSAGE *nvspPacket;
+	NETVSC_PACKET *nvscPacket;
+
+	DPRINT_ENTER(NETVSC);
+
+	netDevice = GetInboundNetDevice(Device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?");
+		DPRINT_EXIT(NETVSC);
+		return;
+	}
+
+	nvspPacket = (NVSP_MESSAGE*)((ULONG_PTR)Packet + (Packet->DataOffset8 << 3));
+
+	DPRINT_DBG(NETVSC, "send completion packet - type %d", nvspPacket->Header.MessageType);
+
+	if (nvspPacket->Header.MessageType == NvspMessageTypeInitComplete ||
+		nvspPacket->Header.MessageType == NvspMessage1TypeSendReceiveBufferComplete ||
+		nvspPacket->Header.MessageType == NvspMessage1TypeSendSendBufferComplete)
+	{
+		// Copy the response back
+		memcpy(&netDevice->ChannelInitPacket, nvspPacket, sizeof(NVSP_MESSAGE));
+		WaitEventSet(netDevice->ChannelInitEvent);
+	}
+	else if (nvspPacket->Header.MessageType == NvspMessage1TypeSendRNDISPacketComplete)
+	{
+		// Get the send context
+		nvscPacket = (NETVSC_PACKET *)(ULONG_PTR)Packet->TransactionId;
+		ASSERT(nvscPacket);
+
+		// Notify the layer above us
+		nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext);
+
+		InterlockedDecrement(&netDevice->NumOutstandingSends);
+	}
+	else
+	{
+		DPRINT_ERR(NETVSC, "Unknown send completion packet type - %d received!!", nvspPacket->Header.MessageType);
+	}
+
+	PutNetDevice(Device);
+	DPRINT_EXIT(NETVSC);
+}
+
+
+
+static int
+NetVscOnSend(
+	DEVICE_OBJECT *Device,
+	NETVSC_PACKET *Packet
+	)
+{
+	NETVSC_DEVICE* netDevice;
+	int ret=0;
+
+	NVSP_MESSAGE sendMessage;
+
+	DPRINT_ENTER(NETVSC);
+
+	netDevice = GetOutboundNetDevice(Device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "net device (%p) shutting down...ignoring outbound packets", netDevice);
+		DPRINT_EXIT(NETVSC);
+		return -2;
+	}
+
+	sendMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacket;
+	if (Packet->IsDataPacket)
+	    sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 0;// 0 is RMC_DATA;
+	else
+		sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 1;// 1 is RMC_CONTROL;
+
+	// Not using send buffer section
+    sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionIndex = 0xFFFFFFFF;
+    sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionSize = 0;
+
+	if (Packet->PageBufferCount)
+	{
+		ret = Device->Driver->VmbusChannelInterface.SendPacketPageBuffer(Device,
+																			Packet->PageBuffers,
+																			Packet->PageBufferCount,
+																			&sendMessage,
+																			sizeof(NVSP_MESSAGE),
+																			(ULONG_PTR)Packet);
+	}
+	else
+	{
+		ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+																&sendMessage,
+																sizeof(NVSP_MESSAGE),
+																(ULONG_PTR)Packet,
+																VmbusPacketTypeDataInBand,
+																VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+
+	}
+
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", Packet, ret);
+	}
+
+	InterlockedIncrement(&netDevice->NumOutstandingSends);
+	PutNetDevice(Device);
+
+	DPRINT_EXIT(NETVSC);
+	return ret;
+}
+
+
+static void
+NetVscOnReceive(
+	DEVICE_OBJECT		*Device,
+	VMPACKET_DESCRIPTOR *Packet
+	)
+{
+	NETVSC_DEVICE* netDevice;
+	VMTRANSFER_PAGE_PACKET_HEADER *vmxferpagePacket;
+	NVSP_MESSAGE *nvspPacket;
+	NETVSC_PACKET *netvscPacket=NULL;
+	LIST_ENTRY* entry;
+	ULONG_PTR start;
+	ULONG_PTR end, endVirtual;
+	//NETVSC_DRIVER_OBJECT *netvscDriver;
+	XFERPAGE_PACKET *xferpagePacket=NULL;
+	LIST_ENTRY listHead;
+
+	int i=0, j=0;
+	int count=0, bytesRemain=0;
+
+	DPRINT_ENTER(NETVSC);
+
+	netDevice = GetInboundNetDevice(Device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?");
+		DPRINT_EXIT(NETVSC);
+		return;
+	}
+
+	// All inbound packets other than send completion should be xfer page packet
+	if (Packet->Type != VmbusPacketTypeDataUsingTransferPages)
+	{
+		DPRINT_ERR(NETVSC, "Unknown packet type received - %d", Packet->Type);
+		PutNetDevice(Device);
+		return;
+	}
+
+	nvspPacket = (NVSP_MESSAGE*)((ULONG_PTR)Packet + (Packet->DataOffset8 << 3));
+
+	// Make sure this is a valid nvsp packet
+	if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket )
+	{
+		DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d", nvspPacket->Header.MessageType);
+		PutNetDevice(Device);
+		return;
+	}
+
+	DPRINT_DBG(NETVSC, "NVSP packet received - type %d", nvspPacket->Header.MessageType);
+
+	vmxferpagePacket = (VMTRANSFER_PAGE_PACKET_HEADER*)Packet;
+
+	if (vmxferpagePacket->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID)
+	{
+		DPRINT_ERR(NETVSC, "Invalid xfer page set id - expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID, vmxferpagePacket->TransferPageSetId);
+		PutNetDevice(Device);
+		return;
+	}
+
+	DPRINT_DBG(NETVSC, "xfer page - range count %d", vmxferpagePacket->RangeCount);
+
+	INITIALIZE_LIST_HEAD(&listHead);
+
+	// Grab free packets (range count + 1) to represent this xfer page packet. +1 to represent
+	// the xfer page packet itself. We grab it here so that we know exactly how many we can fulfil
+	SpinlockAcquire(netDevice->ReceivePacketListLock);
+	while (!IsListEmpty(&netDevice->ReceivePacketList))
+	{
+		entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
+		netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+
+		INSERT_TAIL_LIST(&listHead, &netvscPacket->ListEntry);
+
+		if (++count == vmxferpagePacket->RangeCount + 1)
+			break;
+	}
+	SpinlockRelease(netDevice->ReceivePacketListLock);
+
+	// We need at least 2 netvsc pkts (1 to represent the xfer page and at least 1 for the range)
+	// i.e. we can handled some of the xfer page packet ranges...
+	if (count < 2)
+	{
+		DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. Dropping this xfer page packet completely!", count, vmxferpagePacket->RangeCount+1);
+
+		// Return it to the freelist
+		SpinlockAcquire(netDevice->ReceivePacketListLock);
+		for (i=count; i != 0; i--)
+		{
+			entry = REMOVE_HEAD_LIST(&listHead);
+			netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+
+			INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &netvscPacket->ListEntry);
+		}
+		SpinlockRelease(netDevice->ReceivePacketListLock);
+
+		NetVscSendReceiveCompletion(Device, vmxferpagePacket->d.TransactionId);
+
+		PutNetDevice(Device);
+		return;
+	}
+
+	// Remove the 1st packet to represent the xfer page packet itself
+	entry = REMOVE_HEAD_LIST(&listHead);
+	xferpagePacket = CONTAINING_RECORD(entry, XFERPAGE_PACKET, ListEntry);
+	xferpagePacket->Count = count - 1; // This is how much we can satisfy
+	ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <= vmxferpagePacket->RangeCount);
+
+	if (xferpagePacket->Count != vmxferpagePacket->RangeCount)
+	{
+		DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer page...got %d", vmxferpagePacket->RangeCount, xferpagePacket->Count);
+	}
+
+	// Each range represents 1 RNDIS pkt that contains 1 ethernet frame
+	for (i=0; i < (count - 1); i++)
+	{
+		entry = REMOVE_HEAD_LIST(&listHead);
+		netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+
+		// Initialize the netvsc packet
+		netvscPacket->XferPagePacket = xferpagePacket;
+		netvscPacket->Completion.Recv.OnReceiveCompletion = NetVscOnReceiveCompletion;
+		netvscPacket->Completion.Recv.ReceiveCompletionContext = netvscPacket;
+		netvscPacket->Device = Device;
+		netvscPacket->Completion.Recv.ReceiveCompletionTid = vmxferpagePacket->d.TransactionId; // Save this so that we can send it back
+
+		netvscPacket->TotalDataBufferLength = vmxferpagePacket->Ranges[i].ByteCount;
+		netvscPacket->PageBufferCount = 1;
+
+		ASSERT(vmxferpagePacket->Ranges[i].ByteOffset + vmxferpagePacket->Ranges[i].ByteCount < netDevice->ReceiveBufferSize);
+
+		netvscPacket->PageBuffers[0].Length = vmxferpagePacket->Ranges[i].ByteCount;
+
+		start = GetPhysicalAddress((void*)((ULONG_PTR)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset));
+
+		netvscPacket->PageBuffers[0].Pfn = start >> PAGE_SHIFT;
+		endVirtual = (ULONG_PTR)netDevice->ReceiveBuffer
+		    + vmxferpagePacket->Ranges[i].ByteOffset
+		    + vmxferpagePacket->Ranges[i].ByteCount -1;
+		end = GetPhysicalAddress((void*)endVirtual);
+
+		// Calculate the page relative offset
+		netvscPacket->PageBuffers[0].Offset = vmxferpagePacket->Ranges[i].ByteOffset & (PAGE_SIZE -1);
+		if ((end >> PAGE_SHIFT) != (start>>PAGE_SHIFT)) {
+		    //Handle frame across multiple pages:
+		    netvscPacket->PageBuffers[0].Length =
+			(netvscPacket->PageBuffers[0].Pfn <<PAGE_SHIFT) + PAGE_SIZE - start;
+		    bytesRemain = netvscPacket->TotalDataBufferLength - netvscPacket->PageBuffers[0].Length;
+		    for (j=1; j<NETVSC_PACKET_MAXPAGE; j++) {
+			netvscPacket->PageBuffers[j].Offset = 0;
+			if (bytesRemain <= PAGE_SIZE) {
+			    netvscPacket->PageBuffers[j].Length = bytesRemain;
+			    bytesRemain = 0;
+			} else {
+			    netvscPacket->PageBuffers[j].Length = PAGE_SIZE;
+			    bytesRemain -= PAGE_SIZE;
+			}
+			netvscPacket->PageBuffers[j].Pfn =
+			    GetPhysicalAddress((void*)(endVirtual - bytesRemain)) >> PAGE_SHIFT;
+			netvscPacket->PageBufferCount++;
+			if (bytesRemain == 0)
+			    break;
+		    }
+		    ASSERT(bytesRemain == 0);
+		}
+		DPRINT_DBG(NETVSC, "[%d] - (abs offset %u len %u) => (pfn %llx, offset %u, len %u)",
+			i,
+			vmxferpagePacket->Ranges[i].ByteOffset,
+			vmxferpagePacket->Ranges[i].ByteCount,
+			netvscPacket->PageBuffers[0].Pfn,
+			netvscPacket->PageBuffers[0].Offset,
+			netvscPacket->PageBuffers[0].Length);
+
+		// Pass it to the upper layer
+		((NETVSC_DRIVER_OBJECT*)Device->Driver)->OnReceiveCallback(Device, netvscPacket);
+
+		NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext);
+	}
+
+	ASSERT(IsListEmpty(&listHead));
+
+	PutNetDevice(Device);
+	DPRINT_EXIT(NETVSC);
+}
+
+
+static void
+NetVscSendReceiveCompletion(
+	DEVICE_OBJECT	*Device,
+	UINT64			TransactionId
+	)
+{
+	NVSP_MESSAGE recvcompMessage;
+	int retries=0;
+	int ret=0;
+
+	DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx", TransactionId);
+
+	recvcompMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacketComplete;
+
+	// FIXME: Pass in the status
+	recvcompMessage.Messages.Version1Messages.SendRNDISPacketComplete.Status = NvspStatusSuccess;
+
+retry_send_cmplt:
+	// Send the completion
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															&recvcompMessage,
+															sizeof(NVSP_MESSAGE),
+															TransactionId,
+															VmbusPacketTypeCompletion,
+															0);
+	if (ret == 0) // success
+	{
+		// no-op
+	}
+	else if (ret == -1) // no more room...wait a bit and attempt to retry 3 times
+	{
+		retries++;
+		DPRINT_ERR(NETVSC, "unable to send receive completion pkt (tid %llx)...retrying %d", TransactionId, retries);
+
+		if (retries < 4)
+		{
+			Sleep(100);
+			goto retry_send_cmplt;
+		}
+		else
+		{
+			DPRINT_ERR(NETVSC, "unable to send receive completion pkt (tid %llx)...give up retrying", TransactionId);
+		}
+	}
+	else
+	{
+		DPRINT_ERR(NETVSC, "unable to send receive completion pkt - %llx", TransactionId);
+	}
+}
+
+//
+// Send a receive completion packet to RNDIS device (ie NetVsp)
+//
+static void
+NetVscOnReceiveCompletion(
+	PVOID Context)
+{
+	NETVSC_PACKET *packet = (NETVSC_PACKET*)Context;
+	DEVICE_OBJECT *device = (DEVICE_OBJECT*)packet->Device;
+	NETVSC_DEVICE* netDevice;
+	UINT64	transactionId=0;
+	BOOL fSendReceiveComp = FALSE;
+
+	DPRINT_ENTER(NETVSC);
+
+	ASSERT(packet->XferPagePacket);
+
+	// Even though it seems logical to do a GetOutboundNetDevice() here to send out receive completion,
+	// we are using GetInboundNetDevice() since we may have disable outbound traffic already.
+	netDevice = GetInboundNetDevice(device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?");
+		DPRINT_EXIT(NETVSC);
+		return;
+	}
+
+	// Overloading use of the lock.
+	SpinlockAcquire(netDevice->ReceivePacketListLock);
+
+	ASSERT(packet->XferPagePacket->Count > 0);
+	packet->XferPagePacket->Count--;
+
+	// Last one in the line that represent 1 xfer page packet.
+	// Return the xfer page packet itself to the freelist
+	if (packet->XferPagePacket->Count == 0)
+	{
+		fSendReceiveComp = TRUE;
+		transactionId = packet->Completion.Recv.ReceiveCompletionTid;
+
+		INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->XferPagePacket->ListEntry);
+	}
+
+	// Put the packet back
+	INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry);
+	SpinlockRelease(netDevice->ReceivePacketListLock);
+
+	// Send a receive completion for the xfer page packet
+	if (fSendReceiveComp)
+	{
+		NetVscSendReceiveCompletion(device, transactionId);
+	}
+
+	PutNetDevice(device);
+	DPRINT_EXIT(NETVSC);
+}
+
+
+
+void
+NetVscOnChannelCallback(
+	PVOID Context
+	)
+{
+	const int netPacketSize=2048;
+	int ret=0;
+	DEVICE_OBJECT *device=(DEVICE_OBJECT*)Context;
+	NETVSC_DEVICE *netDevice;
+
+	UINT32 bytesRecvd;
+	UINT64 requestId;
+	UCHAR packet[netPacketSize];
+	VMPACKET_DESCRIPTOR *desc;
+	UCHAR	*buffer=packet;
+	int		bufferlen=netPacketSize;
+
+
+	DPRINT_ENTER(NETVSC);
+
+	ASSERT(device);
+
+	netDevice = GetInboundNetDevice(device);
+	if (!netDevice)
+	{
+		DPRINT_ERR(NETVSC, "net device (%p) shutting down...ignoring inbound packets", netDevice);
+		DPRINT_EXIT(NETVSC);
+		return;
+	}
+
+	do
+	{
+		ret = device->Driver->VmbusChannelInterface.RecvPacketRaw(device,
+																	buffer,
+																	bufferlen,
+																	&bytesRecvd,
+																	&requestId);
+
+		if (ret == 0)
+		{
+			if (bytesRecvd > 0)
+			{
+				DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", bytesRecvd, requestId);
+
+				desc = (VMPACKET_DESCRIPTOR*)buffer;
+				switch (desc->Type)
+				{
+					case VmbusPacketTypeCompletion:
+						NetVscOnSendCompletion(device, desc);
+						break;
+
+					case VmbusPacketTypeDataUsingTransferPages:
+						NetVscOnReceive(device, desc);
+						break;
+
+					default:
+						DPRINT_ERR(NETVSC, "unhandled packet type %d, tid %llx len %d\n", desc->Type, requestId, bytesRecvd);
+						break;
+				}
+
+				// reset
+				if (bufferlen > netPacketSize)
+				{
+					MemFree(buffer);
+
+					buffer = packet;
+					bufferlen = netPacketSize;
+				}
+			}
+			else
+			{
+				//DPRINT_DBG(NETVSC, "nothing else to read...");
+
+				// reset
+				if (bufferlen > netPacketSize)
+				{
+					MemFree(buffer);
+
+					buffer = packet;
+					bufferlen = netPacketSize;
+				}
+
+				break;
+			}
+		}
+		else if (ret == -2) // Handle large packet
+		{
+			buffer = MemAllocAtomic(bytesRecvd);
+			if (buffer == NULL)
+			{
+				// Try again next time around
+				DPRINT_ERR(NETVSC, "unable to allocate buffer of size (%d)!!", bytesRecvd);
+				break;
+			}
+
+			bufferlen = bytesRecvd;
+		}
+		else
+		{
+			ASSERT(0);
+		}
+	} while (1);
+
+	PutNetDevice(device);
+	DPRINT_EXIT(NETVSC);
+	return;
+}
--- /dev/null
+++ b/drivers/staging/hv/netvsc_drv.c
@@ -0,0 +1,720 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/highmem.h>
+#include <linux/device.h>
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#include <asm/io.h>
+#else
+#include <linux/io.h>
+#endif
+#include <linux/delay.h>
+#include <linux/netdevice.h>
+#include <linux/inetdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/skbuff.h>
+#include <linux/in.h>
+#include <net/arp.h>
+#include <net/route.h>
+#include <net/sock.h>
+#include <net/pkt_sched.h>
+
+#include "logging.h"
+#include "vmbus.h"
+
+#include "NetVscApi.h"
+
+MODULE_LICENSE("GPL");
+
+//
+// Static decl
+//
+static int netvsc_probe(struct device *device);
+static int netvsc_remove(struct device *device);
+static int netvsc_open(struct net_device *net);
+static void netvsc_xmit_completion(void *context);
+static int netvsc_start_xmit (struct sk_buff *skb, struct net_device *net);
+static int netvsc_recv_callback(DEVICE_OBJECT *device_obj, NETVSC_PACKET* Packet);
+static int netvsc_close(struct net_device *net);
+static struct net_device_stats *netvsc_get_stats(struct net_device *net);
+static void netvsc_linkstatus_callback(DEVICE_OBJECT *device_obj, unsigned int status);
+
+//
+// Data types
+//
+struct net_device_context {
+	struct device_context	*device_ctx; // point back to our device context
+	struct net_device_stats stats;
+};
+
+struct netvsc_driver_context {
+	// !! These must be the first 2 fields !!
+	struct driver_context	drv_ctx;
+	NETVSC_DRIVER_OBJECT	drv_obj;
+};
+
+//
+// Globals
+//
+
+static int netvsc_ringbuffer_size = NETVSC_DEVICE_RING_BUFFER_SIZE;
+
+// The one and only one
+static struct netvsc_driver_context g_netvsc_drv;
+
+//
+// Routines
+//
+
+/*++
+
+Name:	netvsc_drv_init()
+
+Desc:	NetVsc driver initialization
+
+--*/
+int netvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init)
+{
+	int ret=0;
+	NETVSC_DRIVER_OBJECT *net_drv_obj=&g_netvsc_drv.drv_obj;
+	struct driver_context *drv_ctx=&g_netvsc_drv.drv_ctx;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	vmbus_get_interface(&net_drv_obj->Base.VmbusChannelInterface);
+
+	net_drv_obj->RingBufferSize = netvsc_ringbuffer_size;
+	net_drv_obj->OnReceiveCallback = netvsc_recv_callback;
+	net_drv_obj->OnLinkStatusChanged = netvsc_linkstatus_callback;
+
+	// Callback to client driver to complete the initialization
+	pfn_drv_init(&net_drv_obj->Base);
+
+	drv_ctx->driver.name = net_drv_obj->Base.name;
+	memcpy(&drv_ctx->class_id, &net_drv_obj->Base.deviceType, sizeof(GUID));
+
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+	drv_ctx->driver.probe = netvsc_probe;
+	drv_ctx->driver.remove = netvsc_remove;
+#else
+	drv_ctx->probe = netvsc_probe;
+	drv_ctx->remove = netvsc_remove;
+#endif
+
+	// The driver belongs to vmbus
+	vmbus_child_driver_register(drv_ctx);
+
+	DPRINT_EXIT(NETVSC_DRV);
+
+	return ret;
+}
+
+/*++
+
+Name:	netvsc_get_stats()
+
+Desc:	Get the network stats
+
+--*/
+static struct net_device_stats *netvsc_get_stats(struct net_device *net)
+{
+	struct net_device_context *net_device_ctx = netdev_priv(net);
+
+	return &net_device_ctx->stats;
+}
+
+/*++
+
+Name:	netvsc_set_multicast_list()
+
+Desc:	Set the multicast list
+
+Remark:	No-op here
+--*/
+static void netvsc_set_multicast_list(UNUSED_VAR(struct net_device *net))
+{
+}
+
+
+/*++
+
+Name:	netvsc_probe()
+
+Desc:	Add the specified new device to this driver
+
+--*/
+static int netvsc_probe(struct device *device)
+{
+	int ret=0;
+
+	struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
+	struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx;
+	NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj;
+
+	struct device_context *device_ctx = device_to_device_context(device);
+	DEVICE_OBJECT *device_obj = &device_ctx->device_obj;
+
+	struct net_device *net = NULL;
+	struct net_device_context *net_device_ctx;
+	NETVSC_DEVICE_INFO device_info;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	if (!net_drv_obj->Base.OnDeviceAdd)
+	{
+		return -1;
+	}
+
+	net = alloc_netdev(sizeof(struct net_device_context), "seth%d", ether_setup);
+	//net = alloc_etherdev(sizeof(struct net_device_context));
+	if (!net)
+	{
+		return -1;
+	}
+
+	// Set initial state
+	netif_carrier_off(net);
+	netif_stop_queue(net);
+
+	net_device_ctx = netdev_priv(net);
+	net_device_ctx->device_ctx = device_ctx;
+	device->driver_data = net;
+
+	// Notify the netvsc driver of the new device
+	ret = net_drv_obj->Base.OnDeviceAdd(device_obj, (void*)&device_info);
+	if (ret != 0)
+	{
+		free_netdev(net);
+		device->driver_data = NULL;
+
+		DPRINT_ERR(NETVSC_DRV, "unable to add netvsc device (ret %d)", ret);
+		return ret;
+	}
+
+	// If carrier is still off ie we did not get a link status callback, update it if necessary
+	// FIXME: We should use a atomic or test/set instead to avoid getting out of sync with the device's link status
+	if (!netif_carrier_ok(net))
+	{
+		if (!device_info.LinkState)
+		{
+			netif_carrier_on(net);
+		}
+	}
+
+	memcpy(net->dev_addr, device_info.MacAddr, ETH_ALEN);
+
+	net->open				= netvsc_open;
+	net->hard_start_xmit	= netvsc_start_xmit;
+	net->stop				= netvsc_close;
+	net->get_stats			= netvsc_get_stats;
+	net->set_multicast_list = netvsc_set_multicast_list;
+
+#if !defined(KERNEL_2_6_27)
+	SET_MODULE_OWNER(net);
+#endif
+	SET_NETDEV_DEV(net, device);
+
+	ret = register_netdev(net);
+	if (ret != 0)
+	{
+		// Remove the device and release the resource
+		net_drv_obj->Base.OnDeviceRemove(device_obj);
+		free_netdev(net);
+	}
+
+	DPRINT_EXIT(NETVSC_DRV);
+
+	return ret;
+}
+
+static int netvsc_remove(struct device *device)
+{
+	int ret=0;
+	struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
+	struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx;
+	NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj;
+
+	struct device_context *device_ctx = device_to_device_context(device);
+	struct net_device *net = (struct net_device *)device_ctx->device.driver_data;
+	DEVICE_OBJECT *device_obj = &device_ctx->device_obj;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	if (net == NULL)
+	{
+		DPRINT_INFO(NETVSC, "no net device to remove");
+		DPRINT_EXIT(NETVSC_DRV);
+		return 0;
+	}
+
+	if (!net_drv_obj->Base.OnDeviceRemove)
+	{
+		DPRINT_EXIT(NETVSC_DRV);
+		return -1;
+	}
+
+	// Stop outbound asap
+	netif_stop_queue(net);
+	//netif_carrier_off(net);
+
+	unregister_netdev(net);
+
+	// Call to the vsc driver to let it know that the device is being removed
+	ret = net_drv_obj->Base.OnDeviceRemove(device_obj);
+	if (ret != 0)
+	{
+		// TODO:
+		DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret);
+	}
+
+	free_netdev(net);
+
+	DPRINT_EXIT(NETVSC_DRV);
+
+	return ret;
+}
+
+/*++
+
+Name:	netvsc_open()
+
+Desc:	Open the specified interface device
+
+--*/
+static int netvsc_open(struct net_device *net)
+{
+	int ret=0;
+	struct net_device_context *net_device_ctx = netdev_priv(net);
+	struct driver_context *driver_ctx = driver_to_driver_context(net_device_ctx->device_ctx->device.driver);
+	struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx;
+	NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj;
+
+	DEVICE_OBJECT *device_obj = &net_device_ctx->device_ctx->device_obj;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	if (netif_carrier_ok(net))
+	{
+		memset(&net_device_ctx->stats, 0 , sizeof(struct net_device_stats));
+
+		// Open up the device
+		ret = net_drv_obj->OnOpen(device_obj);
+		if (ret != 0)
+		{
+			DPRINT_ERR(NETVSC_DRV, "unable to open device (ret %d).", ret);
+			return ret;
+		}
+
+		netif_start_queue(net);
+	}
+	else
+	{
+		DPRINT_ERR(NETVSC_DRV, "unable to open device...link is down.");
+	}
+
+	DPRINT_EXIT(NETVSC_DRV);
+	return ret;
+}
+
+/*++
+
+Name:	netvsc_close()
+
+Desc:	Close the specified interface device
+
+--*/
+static int netvsc_close(struct net_device *net)
+{
+	int ret=0;
+	struct net_device_context *net_device_ctx = netdev_priv(net);
+	struct driver_context *driver_ctx = driver_to_driver_context(net_device_ctx->device_ctx->device.driver);
+	struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx;
+	NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj;
+
+	DEVICE_OBJECT *device_obj = &net_device_ctx->device_ctx->device_obj;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	netif_stop_queue(net);
+
+	ret = net_drv_obj->OnClose(device_obj);
+	if (ret != 0)
+	{
+		DPRINT_ERR(NETVSC_DRV, "unable to close device (ret %d).", ret);
+	}
+
+	DPRINT_EXIT(NETVSC_DRV);
+
+	return ret;
+}
+
+
+/*++
+
+Name:	netvsc_xmit_completion()
+
+Desc:	Send completion processing
+
+--*/
+static void netvsc_xmit_completion(void *context)
+{
+	NETVSC_PACKET *packet = (NETVSC_PACKET *)context;
+	struct sk_buff *skb = (struct sk_buff *)(ULONG_PTR)packet->Completion.Send.SendCompletionTid;
+	struct net_device* net;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	kfree(packet);
+
+	if (skb)
+	{
+		net = skb->dev;
+
+		dev_kfree_skb_any(skb);
+
+		if (netif_queue_stopped(net))
+		{
+			DPRINT_INFO(NETVSC_DRV, "net device (%p) waking up...", net);
+
+			netif_wake_queue(net);
+		}
+	}
+
+	DPRINT_EXIT(NETVSC_DRV);
+}
+
+/*++
+
+Name:	netvsc_start_xmit()
+
+Desc:	Start a send
+
+--*/
+static int netvsc_start_xmit (struct sk_buff *skb, struct net_device *net)
+{
+	int ret=0;
+	struct net_device_context *net_device_ctx = netdev_priv(net);
+	struct driver_context *driver_ctx = driver_to_driver_context(net_device_ctx->device_ctx->device.driver);
+	struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx;
+	NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj;
+
+	int i=0;
+	NETVSC_PACKET* packet;
+	int num_frags;
+	int retries=0;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	// Support only 1 chain of frags
+	ASSERT(skb_shinfo(skb)->frag_list == NULL);
+	ASSERT(skb->dev == net);
+
+	DPRINT_DBG(NETVSC_DRV, "xmit packet - len %d data_len %d", skb->len, skb->data_len);
+
+	// Add 1 for skb->data and any additional ones requested
+	num_frags = skb_shinfo(skb)->nr_frags + 1 + net_drv_obj->AdditionalRequestPageBufferCount;
+
+	// Allocate a netvsc packet based on # of frags.
+	packet = kzalloc(sizeof(NETVSC_PACKET) + (num_frags * sizeof(PAGE_BUFFER)) + net_drv_obj->RequestExtSize, GFP_ATOMIC);
+	if (!packet)
+	{
+		DPRINT_ERR(NETVSC_DRV, "unable to allocate NETVSC_PACKET");
+		return -1;
+	}
+
+	packet->Extension = (void*)(unsigned long)packet + sizeof(NETVSC_PACKET) + (num_frags * sizeof(PAGE_BUFFER)) ;
+
+	// Setup the rndis header
+	packet->PageBufferCount = num_frags;
+
+	// TODO: Flush all write buffers/ memory fence ???
+	//wmb();
+
+	// Initialize it from the skb
+	ASSERT(skb->data);
+	packet->TotalDataBufferLength	= skb->len;
+
+	// Start filling in the page buffers starting at AdditionalRequestPageBufferCount offset
+	packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount].Pfn		= virt_to_phys(skb->data) >> PAGE_SHIFT;
+	packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount].Offset	= (unsigned long)skb->data & (PAGE_SIZE -1);
+	packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount].Length	= skb->len - skb->data_len;
+
+	ASSERT((skb->len - skb->data_len) <= PAGE_SIZE);
+
+	for (i=net_drv_obj->AdditionalRequestPageBufferCount+1; i<num_frags; i++)
+	{
+		packet->PageBuffers[i].Pfn		= page_to_pfn(skb_shinfo(skb)->frags[i-(net_drv_obj->AdditionalRequestPageBufferCount+1)].page);
+		packet->PageBuffers[i].Offset	= skb_shinfo(skb)->frags[i-(net_drv_obj->AdditionalRequestPageBufferCount+1)].page_offset;
+		packet->PageBuffers[i].Length	= skb_shinfo(skb)->frags[i-(net_drv_obj->AdditionalRequestPageBufferCount+1)].size;
+	}
+
+	// Set the completion routine
+	packet->Completion.Send.OnSendCompletion = netvsc_xmit_completion;
+	packet->Completion.Send.SendCompletionContext = packet;
+	packet->Completion.Send.SendCompletionTid = (ULONG_PTR)skb;
+
+retry_send:
+	ret = net_drv_obj->OnSend(&net_device_ctx->device_ctx->device_obj, packet);
+
+	if (ret == 0)
+	{
+#ifdef KERNEL_2_6_5
+#define NETDEV_TX_OK	0
+#define NETDEV_TX_BUSY	0
+#endif
+		ret = NETDEV_TX_OK;
+		net_device_ctx->stats.tx_bytes += skb->len;
+		net_device_ctx->stats.tx_packets++;
+	}
+	else
+	{
+		retries++;
+		if (retries < 4)
+		{
+			DPRINT_ERR(NETVSC_DRV, "unable to send...retrying %d...", retries);
+			udelay(100);
+			goto retry_send;
+		}
+
+		// no more room or we are shutting down
+		DPRINT_ERR(NETVSC_DRV, "unable to send (%d)...marking net device (%p) busy", ret, net);
+		DPRINT_INFO(NETVSC_DRV, "net device (%p) stopping", net);
+
+		ret = NETDEV_TX_BUSY;
+		net_device_ctx->stats.tx_dropped++;
+
+		netif_stop_queue(net);
+
+		// Null it since the caller will free it instead of the completion routine
+		packet->Completion.Send.SendCompletionTid = 0;
+
+		// Release the resources since we will not get any send completion
+		netvsc_xmit_completion((void*)packet);
+	}
+
+	DPRINT_DBG(NETVSC_DRV, "# of xmits %lu total size %lu", net_device_ctx->stats.tx_packets, net_device_ctx->stats.tx_bytes);
+
+	DPRINT_EXIT(NETVSC_DRV);
+	return ret;
+}
+
+
+/*++
+
+Name:	netvsc_linkstatus_callback()
+
+Desc:	Link up/down notification
+
+--*/
+static void netvsc_linkstatus_callback(DEVICE_OBJECT *device_obj, unsigned int status)
+{
+	struct device_context* device_ctx = to_device_context(device_obj);
+	struct net_device* net = (struct net_device *)device_ctx->device.driver_data;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	if (!net)
+	{
+		DPRINT_ERR(NETVSC_DRV, "got link status but net device not initialized yet");
+		return;
+	}
+
+	if (status == 1)
+	{
+		netif_carrier_on(net);
+		netif_wake_queue(net);
+	}
+	else
+	{
+		netif_carrier_off(net);
+		netif_stop_queue(net);
+	}
+	DPRINT_EXIT(NETVSC_DRV);
+}
+
+
+/*++
+
+Name:	netvsc_recv_callback()
+
+Desc:	Callback when we receive a packet from the "wire" on the specify device
+
+--*/
+static int netvsc_recv_callback(DEVICE_OBJECT *device_obj, NETVSC_PACKET* packet)
+{
+	int ret=0;
+	struct device_context *device_ctx = to_device_context(device_obj);
+	struct net_device *net = (struct net_device *)device_ctx->device.driver_data;
+	struct net_device_context *net_device_ctx;
+
+	struct sk_buff *skb;
+	void *data;
+	int i=0;
+	unsigned long flags;
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	if (!net)
+	{
+		DPRINT_ERR(NETVSC_DRV, "got receive callback but net device not initialized yet");
+		return 0;
+	}
+
+	net_device_ctx = netdev_priv(net);
+
+	// Allocate a skb - TODO preallocate this
+	//skb = alloc_skb(packet->TotalDataBufferLength, GFP_ATOMIC);
+	skb = dev_alloc_skb(packet->TotalDataBufferLength + 2); // Pad 2-bytes to align IP header to 16 bytes
+	ASSERT(skb);
+	skb_reserve(skb, 2);
+	skb->dev = net;
+
+	// for kmap_atomic
+	local_irq_save(flags);
+
+	// Copy to skb. This copy is needed here since the memory pointed by NETVSC_PACKET
+	// cannot be deallocated
+	for (i=0; i<packet->PageBufferCount; i++)
+	{
+	    data = kmap_atomic(pfn_to_page(packet->PageBuffers[i].Pfn), KM_IRQ1);
+	    data = (void*)(unsigned long)data + packet->PageBuffers[i].Offset;
+
+	    memcpy(skb_put(skb, packet->PageBuffers[i].Length), data, packet->PageBuffers[i].Length);
+
+	    kunmap_atomic((void*)((unsigned long)data - packet->PageBuffers[i].Offset), KM_IRQ1);
+	}
+
+	local_irq_restore(flags);
+
+	skb->protocol = eth_type_trans(skb, net);
+
+	skb->ip_summed = CHECKSUM_NONE;
+
+	// Pass the skb back up. Network stack will deallocate the skb when it is done
+	ret = netif_rx(skb);
+
+	switch (ret)
+	{
+	case NET_RX_DROP:
+		net_device_ctx->stats.rx_dropped++;
+		break;
+	default:
+		net_device_ctx->stats.rx_packets++;
+		net_device_ctx->stats.rx_bytes += skb->len;
+		break;
+
+	}
+	DPRINT_DBG(NETVSC_DRV, "# of recvs %lu total size %lu", net_device_ctx->stats.rx_packets, net_device_ctx->stats.rx_bytes);
+
+	DPRINT_EXIT(NETVSC_DRV);
+
+	return 0;
+}
+
+static int netvsc_drv_exit_cb(struct device *dev, void *data)
+{
+	struct device **curr = (struct device **)data;
+	*curr = dev;
+	return 1; // stop iterating
+}
+
+/*++
+
+Name:	netvsc_drv_exit()
+
+Desc:
+
+--*/
+void netvsc_drv_exit(void)
+{
+	NETVSC_DRIVER_OBJECT *netvsc_drv_obj=&g_netvsc_drv.drv_obj;
+	struct driver_context *drv_ctx=&g_netvsc_drv.drv_ctx;
+
+	struct device *current_dev=NULL;
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#define driver_for_each_device(drv, start, data, fn) \
+	struct list_head *ptr, *n; \
+	list_for_each_safe(ptr, n, &((drv)->devices)) {\
+		struct device *curr_dev;\
+		curr_dev = list_entry(ptr, struct device, driver_list);\
+		fn(curr_dev, data);\
+	}
+#endif
+
+	DPRINT_ENTER(NETVSC_DRV);
+
+	while (1)
+	{
+		current_dev = NULL;
+
+		// Get the device
+		driver_for_each_device(&drv_ctx->driver, NULL, (void*)&current_dev, netvsc_drv_exit_cb);
+
+		if (current_dev == NULL)
+			break;
+
+		// Initiate removal from the top-down
+		DPRINT_INFO(NETVSC_DRV, "unregistering device (%p)...", current_dev);
+
+		device_unregister(current_dev);
+	}
+
+	if (netvsc_drv_obj->Base.OnCleanup)
+		netvsc_drv_obj->Base.OnCleanup(&netvsc_drv_obj->Base);
+
+	vmbus_child_driver_unregister(drv_ctx);
+
+	DPRINT_EXIT(NETVSC_DRV);
+
+	return;
+}
+
+static int __init netvsc_init(void)
+{
+	int ret;
+
+	DPRINT_ENTER(NETVSC_DRV);
+	DPRINT_INFO(NETVSC_DRV, "Netvsc initializing....");
+
+	ret = netvsc_drv_init(NetVscInitialize);
+
+	DPRINT_EXIT(NETVSC_DRV);
+
+	return ret;
+}
+
+static void __exit netvsc_exit(void)
+{
+	DPRINT_ENTER(NETVSC_DRV);
+
+	netvsc_drv_exit();
+
+	DPRINT_EXIT(NETVSC_DRV);
+}
+
+module_param(netvsc_ringbuffer_size, int, S_IRUGO);
+
+module_init(netvsc_init);
+module_exit(netvsc_exit);
--- /dev/null
+++ b/drivers/staging/hv/NetVsc.h
@@ -0,0 +1,91 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _NETVSC_H_
+#define _NETVSC_H_
+
+#include "VmbusPacketFormat.h"
+#include "nvspprotocol.h"
+
+#include "List.h"
+
+#include "NetVscApi.h"
+//
+// #defines
+//
+//#define NVSC_MIN_PROTOCOL_VERSION                       1
+//#define NVSC_MAX_PROTOCOL_VERSION                       1
+
+#define NETVSC_SEND_BUFFER_SIZE				64*1024 // 64K
+#define NETVSC_SEND_BUFFER_ID				0xface
+
+
+#define NETVSC_RECEIVE_BUFFER_SIZE			1024*1024 // 1MB
+
+#define NETVSC_RECEIVE_BUFFER_ID			0xcafe
+
+#define NETVSC_RECEIVE_SG_COUNT				1
+
+// Preallocated receive packets
+#define NETVSC_RECEIVE_PACKETLIST_COUNT		256
+
+//
+// Data types
+//
+
+// Per netvsc channel-specific
+typedef struct _NETVSC_DEVICE {
+	DEVICE_OBJECT					*Device;
+
+	int								RefCount;
+
+	int								NumOutstandingSends;
+	// List of free preallocated NETVSC_PACKET to represent receive packet
+	LIST_ENTRY						ReceivePacketList;
+	HANDLE							ReceivePacketListLock;
+
+	// Send buffer allocated by us but manages by NetVSP
+	PVOID							SendBuffer;
+	UINT32							SendBufferSize;
+	UINT32							SendBufferGpadlHandle;
+	UINT32							SendSectionSize;
+
+	// Receive buffer allocated by us but manages by NetVSP
+	PVOID							ReceiveBuffer;
+	UINT32							ReceiveBufferSize;
+	UINT32							ReceiveBufferGpadlHandle;
+	UINT32							ReceiveSectionCount;
+	PNVSP_1_RECEIVE_BUFFER_SECTION	ReceiveSections;
+
+	// Used for NetVSP initialization protocol
+	HANDLE							ChannelInitEvent;
+	NVSP_MESSAGE					ChannelInitPacket;
+
+	NVSP_MESSAGE					RevokePacket;
+	//UCHAR							HwMacAddr[HW_MACADDR_LEN];
+
+	// Holds rndis device info
+	void							*Extension;
+} NETVSC_DEVICE;
+
+#endif // _NETVSC_H_
--- /dev/null
+++ b/drivers/staging/hv/RndisFilter.c
@@ -0,0 +1,1162 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "logging.h"
+
+#include "NetVscApi.h"
+#include "RndisFilter.h"
+
+//
+// Data types
+//
+
+typedef struct _RNDIS_FILTER_DRIVER_OBJECT {
+	// The original driver
+	NETVSC_DRIVER_OBJECT		InnerDriver;
+
+} RNDIS_FILTER_DRIVER_OBJECT;
+
+typedef enum {
+	RNDIS_DEV_UNINITIALIZED = 0,
+	RNDIS_DEV_INITIALIZING,
+	RNDIS_DEV_INITIALIZED,
+	RNDIS_DEV_DATAINITIALIZED,
+} RNDIS_DEVICE_STATE;
+
+typedef struct _RNDIS_DEVICE {
+	NETVSC_DEVICE			*NetDevice;
+
+	RNDIS_DEVICE_STATE		State;
+	UINT32					LinkStatus;
+	UINT32					NewRequestId;
+
+	HANDLE					RequestLock;
+	LIST_ENTRY				RequestList;
+
+	UCHAR					HwMacAddr[HW_MACADDR_LEN];
+} RNDIS_DEVICE;
+
+
+typedef struct _RNDIS_REQUEST {
+	LIST_ENTRY					ListEntry;
+	HANDLE						WaitEvent;
+
+	// FIXME: We assumed a fixed size response here. If we do ever need to handle a bigger response,
+	// we can either define a max response message or add a response buffer variable above this field
+	RNDIS_MESSAGE				ResponseMessage;
+
+	// Simplify allocation by having a netvsc packet inline
+	NETVSC_PACKET				Packet;
+	PAGE_BUFFER					Buffer;
+	// FIXME: We assumed a fixed size request here.
+	RNDIS_MESSAGE				RequestMessage;
+} RNDIS_REQUEST;
+
+
+typedef struct _RNDIS_FILTER_PACKET {
+	void						*CompletionContext;
+	PFN_ON_SENDRECVCOMPLETION	OnCompletion;
+
+	RNDIS_MESSAGE				Message;
+} RNDIS_FILTER_PACKET;
+
+//
+// Internal routines
+//
+static int
+RndisFilterSendRequest(
+	RNDIS_DEVICE	*Device,
+	RNDIS_REQUEST	*Request
+	);
+
+static void
+RndisFilterReceiveResponse(
+	RNDIS_DEVICE	*Device,
+	RNDIS_MESSAGE	*Response
+	);
+
+static void
+RndisFilterReceiveIndicateStatus(
+	RNDIS_DEVICE	*Device,
+	RNDIS_MESSAGE	*Response
+	);
+
+static void
+RndisFilterReceiveData(
+	RNDIS_DEVICE	*Device,
+	RNDIS_MESSAGE	*Message,
+	NETVSC_PACKET	*Packet
+	);
+
+static int
+RndisFilterOnReceive(
+	DEVICE_OBJECT		*Device,
+	NETVSC_PACKET		*Packet
+	);
+
+static int
+RndisFilterQueryDevice(
+	RNDIS_DEVICE	*Device,
+	UINT32			Oid,
+	VOID			*Result,
+	UINT32			*ResultSize
+	);
+
+static inline int
+RndisFilterQueryDeviceMac(
+	RNDIS_DEVICE	*Device
+	);
+
+static inline int
+RndisFilterQueryDeviceLinkStatus(
+	RNDIS_DEVICE	*Device
+	);
+
+static int
+RndisFilterSetPacketFilter(
+	RNDIS_DEVICE	*Device,
+	UINT32			NewFilter
+	);
+
+static int
+RndisFilterInitDevice(
+	RNDIS_DEVICE		*Device
+	);
+
+static int
+RndisFilterOpenDevice(
+	RNDIS_DEVICE		*Device
+	);
+
+static int
+RndisFilterCloseDevice(
+	RNDIS_DEVICE		*Device
+	);
+
+static int
+RndisFilterOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	);
+
+static int
+RndisFilterOnDeviceRemove(
+	DEVICE_OBJECT *Device
+	);
+
+static void
+RndisFilterOnCleanup(
+	DRIVER_OBJECT *Driver
+	);
+
+static int
+RndisFilterOnOpen(
+	DEVICE_OBJECT		*Device
+	);
+
+static int
+RndisFilterOnClose(
+	DEVICE_OBJECT		*Device
+	);
+
+static int
+RndisFilterOnSend(
+	DEVICE_OBJECT		*Device,
+	NETVSC_PACKET		*Packet
+	);
+
+static void
+RndisFilterOnSendCompletion(
+   void *Context
+	);
+
+static void
+RndisFilterOnSendRequestCompletion(
+   void *Context
+	);
+
+//
+// Global var
+//
+
+// The one and only
+RNDIS_FILTER_DRIVER_OBJECT gRndisFilter;
+
+static inline RNDIS_DEVICE* GetRndisDevice(void)
+{
+	RNDIS_DEVICE *device;
+
+	device = MemAllocZeroed(sizeof(RNDIS_DEVICE));
+	if (!device)
+	{
+		return NULL;
+	}
+
+	device->RequestLock = SpinlockCreate();
+	if (!device->RequestLock)
+	{
+		MemFree(device);
+		return NULL;
+	}
+
+	INITIALIZE_LIST_HEAD(&device->RequestList);
+
+	device->State = RNDIS_DEV_UNINITIALIZED;
+
+	return device;
+}
+
+static inline void PutRndisDevice(RNDIS_DEVICE *Device)
+{
+	SpinlockClose(Device->RequestLock);
+	MemFree(Device);
+}
+
+static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, UINT32 MessageType, UINT32 MessageLength)
+{
+	RNDIS_REQUEST *request;
+	RNDIS_MESSAGE *rndisMessage;
+	RNDIS_SET_REQUEST *set;
+
+	request = MemAllocZeroed(sizeof(RNDIS_REQUEST));
+	if (!request)
+	{
+		return NULL;
+	}
+
+	request->WaitEvent = WaitEventCreate();
+	if (!request->WaitEvent)
+	{
+		MemFree(request);
+		return NULL;
+	}
+
+	rndisMessage = &request->RequestMessage;
+	rndisMessage->NdisMessageType = MessageType;
+	rndisMessage->MessageLength = MessageLength;
+
+	// Set the request id. This field is always after the rndis header for request/response packet types so
+	// we just used the SetRequest as a template
+	set = &rndisMessage->Message.SetRequest;
+	set->RequestId = InterlockedIncrement((int*)&Device->NewRequestId);
+
+	// Add to the request list
+	SpinlockAcquire(Device->RequestLock);
+	INSERT_TAIL_LIST(&Device->RequestList, &request->ListEntry);
+	SpinlockRelease(Device->RequestLock);
+
+	return request;
+}
+
+static inline void PutRndisRequest(RNDIS_DEVICE *Device, RNDIS_REQUEST *Request)
+{
+	SpinlockAcquire(Device->RequestLock);
+	REMOVE_ENTRY_LIST(&Request->ListEntry);
+	SpinlockRelease(Device->RequestLock);
+
+	WaitEventClose(Request->WaitEvent);
+	MemFree(Request);
+}
+
+static inline void DumpRndisMessage(RNDIS_MESSAGE *RndisMessage)
+{
+	switch (RndisMessage->NdisMessageType)
+	{
+	case REMOTE_NDIS_PACKET_MSG:
+		DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, data offset %u data len %u, # oob %u, oob offset %u, oob len %u, pkt offset %u, pkt len %u",
+			RndisMessage->MessageLength,
+			RndisMessage->Message.Packet.DataOffset,
+			RndisMessage->Message.Packet.DataLength,
+			RndisMessage->Message.Packet.NumOOBDataElements,
+			RndisMessage->Message.Packet.OOBDataOffset,
+			RndisMessage->Message.Packet.OOBDataLength,
+			RndisMessage->Message.Packet.PerPacketInfoOffset,
+			RndisMessage->Message.Packet.PerPacketInfoLength);
+		break;
+
+	case REMOTE_NDIS_INITIALIZE_CMPLT:
+		DPRINT_DBG(NETVSC, "REMOTE_NDIS_INITIALIZE_CMPLT (len %u, id 0x%x, status 0x%x, major %d, minor %d, device flags %d, max xfer size 0x%x, max pkts %u, pkt aligned %u)",
+			RndisMessage->MessageLength,
+			RndisMessage->Message.InitializeComplete.RequestId,
+			RndisMessage->Message.InitializeComplete.Status,
+			RndisMessage->Message.InitializeComplete.MajorVersion,
+			RndisMessage->Message.InitializeComplete.MinorVersion,
+			RndisMessage->Message.InitializeComplete.DeviceFlags,
+			RndisMessage->Message.InitializeComplete.MaxTransferSize,
+			RndisMessage->Message.InitializeComplete.MaxPacketsPerMessage,
+			RndisMessage->Message.InitializeComplete.PacketAlignmentFactor);
+		break;
+
+	case REMOTE_NDIS_QUERY_CMPLT:
+		DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT (len %u, id 0x%x, status 0x%x, buf len %u, buf offset %u)",
+			RndisMessage->MessageLength,
+			RndisMessage->Message.QueryComplete.RequestId,
+			RndisMessage->Message.QueryComplete.Status,
+			RndisMessage->Message.QueryComplete.InformationBufferLength,
+			RndisMessage->Message.QueryComplete.InformationBufferOffset);
+		break;
+
+	case REMOTE_NDIS_SET_CMPLT:
+		DPRINT_DBG(NETVSC, "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)",
+			RndisMessage->MessageLength,
+			RndisMessage->Message.SetComplete.RequestId,
+			RndisMessage->Message.SetComplete.Status);
+		break;
+
+	case REMOTE_NDIS_INDICATE_STATUS_MSG:
+		DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG (len %u, status 0x%x, buf len %u, buf offset %u)",
+			RndisMessage->MessageLength,
+			RndisMessage->Message.IndicateStatus.Status,
+			RndisMessage->Message.IndicateStatus.StatusBufferLength,
+			RndisMessage->Message.IndicateStatus.StatusBufferOffset);
+		break;
+
+	default:
+		DPRINT_DBG(NETVSC, "0x%x (len %u)",
+			RndisMessage->NdisMessageType,
+			RndisMessage->MessageLength);
+		break;
+	}
+}
+
+static int
+RndisFilterSendRequest(
+	RNDIS_DEVICE	*Device,
+	RNDIS_REQUEST	*Request
+	)
+{
+	int ret=0;
+	NETVSC_PACKET *packet;
+
+	DPRINT_ENTER(NETVSC);
+
+	// Setup the packet to send it
+	packet = &Request->Packet;
+
+	packet->IsDataPacket = FALSE;
+	packet->TotalDataBufferLength = Request->RequestMessage.MessageLength;
+	packet->PageBufferCount = 1;
+
+	packet->PageBuffers[0].Pfn = GetPhysicalAddress(&Request->RequestMessage) >> PAGE_SHIFT;
+	packet->PageBuffers[0].Length = Request->RequestMessage.MessageLength;
+	packet->PageBuffers[0].Offset = (ULONG_PTR)&Request->RequestMessage & (PAGE_SIZE -1);
+
+	packet->Completion.Send.SendCompletionContext = Request;//packet;
+	packet->Completion.Send.OnSendCompletion = RndisFilterOnSendRequestCompletion;
+	packet->Completion.Send.SendCompletionTid = (ULONG_PTR)Device;
+
+	ret = gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet);
+	DPRINT_EXIT(NETVSC);
+	return ret;
+}
+
+
+static void
+RndisFilterReceiveResponse(
+	RNDIS_DEVICE	*Device,
+	RNDIS_MESSAGE	*Response
+	)
+{
+	LIST_ENTRY *anchor;
+	LIST_ENTRY *curr;
+	RNDIS_REQUEST *request=NULL;
+	BOOL found=FALSE;
+
+	DPRINT_ENTER(NETVSC);
+
+	SpinlockAcquire(Device->RequestLock);
+	ITERATE_LIST_ENTRIES(anchor, curr, &Device->RequestList)
+	{
+		request = CONTAINING_RECORD(curr, RNDIS_REQUEST, ListEntry);
+
+		// All request/response message contains RequestId as the 1st field
+		if (request->RequestMessage.Message.InitializeRequest.RequestId == Response->Message.InitializeComplete.RequestId)
+		{
+			DPRINT_DBG(NETVSC, "found rndis request for this response (id 0x%x req type 0x%x res type 0x%x)",
+				request->RequestMessage.Message.InitializeRequest.RequestId, request->RequestMessage.NdisMessageType, Response->NdisMessageType);
+
+			found = TRUE;
+			break;
+		}
+	}
+	SpinlockRelease(Device->RequestLock);
+
+	if (found)
+	{
+		if (Response->MessageLength <= sizeof(RNDIS_MESSAGE))
+		{
+			memcpy(&request->ResponseMessage, Response, Response->MessageLength);
+		}
+		else
+		{
+			DPRINT_ERR(NETVSC, "rndis response buffer overflow detected (size %u max %u)", Response->MessageLength, sizeof(RNDIS_FILTER_PACKET));
+
+			if (Response->NdisMessageType == REMOTE_NDIS_RESET_CMPLT) // does not have a request id field
+			{
+				request->ResponseMessage.Message.ResetComplete.Status = STATUS_BUFFER_OVERFLOW;
+			}
+			else
+			{
+				request->ResponseMessage.Message.InitializeComplete.Status = STATUS_BUFFER_OVERFLOW;
+			}
+		}
+
+		WaitEventSet(request->WaitEvent);
+	}
+	else
+	{
+		DPRINT_ERR(NETVSC, "no rndis request found for this response (id 0x%x res type 0x%x)",
+				Response->Message.InitializeComplete.RequestId, Response->NdisMessageType);
+	}
+
+	DPRINT_EXIT(NETVSC);
+}
+
+static void
+RndisFilterReceiveIndicateStatus(
+	RNDIS_DEVICE	*Device,
+	RNDIS_MESSAGE	*Response
+	)
+{
+	RNDIS_INDICATE_STATUS *indicate = &Response->Message.IndicateStatus;
+
+	if (indicate->Status == RNDIS_STATUS_MEDIA_CONNECT)
+	{
+		gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 1);
+	}
+	else if (indicate->Status == RNDIS_STATUS_MEDIA_DISCONNECT)
+	{
+		gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 0);
+	}
+	else
+	{
+		// TODO:
+	}
+}
+
+static void
+RndisFilterReceiveData(
+	RNDIS_DEVICE	*Device,
+	RNDIS_MESSAGE	*Message,
+	NETVSC_PACKET	*Packet
+	)
+{
+	RNDIS_PACKET *rndisPacket;
+	UINT32 dataOffset;
+
+	DPRINT_ENTER(NETVSC);
+
+	// empty ethernet frame ??
+	ASSERT(Packet->PageBuffers[0].Length > RNDIS_MESSAGE_SIZE(RNDIS_PACKET));
+
+	rndisPacket = &Message->Message.Packet;
+
+	// FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
+	// netvsc packet (ie TotalDataBufferLength != MessageLength)
+
+	// Remove the rndis header and pass it back up the stack
+	dataOffset = RNDIS_HEADER_SIZE + rndisPacket->DataOffset;
+
+	Packet->TotalDataBufferLength -= dataOffset;
+	Packet->PageBuffers[0].Offset += dataOffset;
+	Packet->PageBuffers[0].Length -= dataOffset;
+
+	Packet->IsDataPacket = TRUE;
+
+	gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device, Packet);
+
+	DPRINT_EXIT(NETVSC);
+}
+
+static int
+RndisFilterOnReceive(
+	DEVICE_OBJECT		*Device,
+	NETVSC_PACKET		*Packet
+	)
+{
+	NETVSC_DEVICE *netDevice = (NETVSC_DEVICE*)Device->Extension;
+	RNDIS_DEVICE *rndisDevice;
+	RNDIS_MESSAGE rndisMessage;
+	RNDIS_MESSAGE *rndisHeader;
+
+	DPRINT_ENTER(NETVSC);
+
+	ASSERT(netDevice);
+	//Make sure the rndis device state is initialized
+	if (!netDevice->Extension)
+	{
+		DPRINT_ERR(NETVSC, "got rndis message but no rndis device...dropping this message!");
+		DPRINT_EXIT(NETVSC);
+		return -1;
+	}
+
+	rndisDevice = (RNDIS_DEVICE*)netDevice->Extension;
+	if (rndisDevice->State == RNDIS_DEV_UNINITIALIZED)
+	{
+		DPRINT_ERR(NETVSC, "got rndis message but rndis device uninitialized...dropping this message!");
+		DPRINT_EXIT(NETVSC);
+		return -1;
+	}
+
+	rndisHeader = (RNDIS_MESSAGE*)PageMapVirtualAddress(Packet->PageBuffers[0].Pfn);
+
+	rndisHeader = (void*)((ULONG_PTR)rndisHeader + Packet->PageBuffers[0].Offset);
+
+	// Make sure we got a valid rndis message
+	// FIXME: There seems to be a bug in set completion msg where its MessageLength is 16 bytes but
+	// the ByteCount field in the xfer page range shows 52 bytes
+#if 0
+	if ( Packet->TotalDataBufferLength != rndisHeader->MessageLength )
+	{
+		PageUnmapVirtualAddress((void*)(ULONG_PTR)rndisHeader - Packet->PageBuffers[0].Offset);
+
+		DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u bytes got %u)...dropping this message!",
+			rndisHeader->MessageLength, Packet->TotalDataBufferLength);
+		DPRINT_EXIT(NETVSC);
+		return -1;
+	}
+#endif
+
+	if ((rndisHeader->NdisMessageType != REMOTE_NDIS_PACKET_MSG) && (rndisHeader->MessageLength > sizeof(RNDIS_MESSAGE)))
+	{
+		DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow detected (got %u, max %u)...marking it an error!",
+			rndisHeader->MessageLength, sizeof(RNDIS_MESSAGE));
+	}
+
+	memcpy(&rndisMessage, rndisHeader, (rndisHeader->MessageLength > sizeof(RNDIS_MESSAGE))?sizeof(RNDIS_MESSAGE):rndisHeader->MessageLength);
+
+	PageUnmapVirtualAddress((void*)(ULONG_PTR)rndisHeader - Packet->PageBuffers[0].Offset);
+
+	DumpRndisMessage(&rndisMessage);
+
+	switch (rndisMessage.NdisMessageType)
+	{
+		// data msg
+	case REMOTE_NDIS_PACKET_MSG:
+		RndisFilterReceiveData(rndisDevice, &rndisMessage, Packet);
+		break;
+
+		// completion msgs
+	case REMOTE_NDIS_INITIALIZE_CMPLT:
+	case REMOTE_NDIS_QUERY_CMPLT:
+	case REMOTE_NDIS_SET_CMPLT:
+	//case REMOTE_NDIS_RESET_CMPLT:
+	//case REMOTE_NDIS_KEEPALIVE_CMPLT:
+		RndisFilterReceiveResponse(rndisDevice, &rndisMessage);
+		break;
+
+		// notification msgs
+	case REMOTE_NDIS_INDICATE_STATUS_MSG:
+		RndisFilterReceiveIndicateStatus(rndisDevice, &rndisMessage);
+		break;
+	default:
+		DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", rndisMessage.NdisMessageType, rndisMessage.MessageLength);
+		break;
+	}
+
+	DPRINT_EXIT(NETVSC);
+	return 0;
+}
+
+
+static int
+RndisFilterQueryDevice(
+	RNDIS_DEVICE	*Device,
+	UINT32			Oid,
+	VOID			*Result,
+	UINT32			*ResultSize
+	)
+{
+	RNDIS_REQUEST *request;
+	UINT32 inresultSize = *ResultSize;
+	RNDIS_QUERY_REQUEST *query;
+	RNDIS_QUERY_COMPLETE *queryComplete;
+	int ret=0;
+
+	DPRINT_ENTER(NETVSC);
+
+	ASSERT(Result);
+
+	*ResultSize = 0;
+	request = GetRndisRequest(Device, REMOTE_NDIS_QUERY_MSG, RNDIS_MESSAGE_SIZE(RNDIS_QUERY_REQUEST));
+	if (!request)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	// Setup the rndis query
+	query = &request->RequestMessage.Message.QueryRequest;
+	query->Oid = Oid;
+	query->InformationBufferOffset = sizeof(RNDIS_QUERY_REQUEST);
+	query->InformationBufferLength = 0;
+	query->DeviceVcHandle = 0;
+
+	ret = RndisFilterSendRequest(Device, request);
+	if (ret != 0)
+	{
+		goto Cleanup;
+	}
+
+	WaitEventWait(request->WaitEvent);
+
+	// Copy the response back
+	queryComplete = &request->ResponseMessage.Message.QueryComplete;
+
+	if (queryComplete->InformationBufferLength > inresultSize)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	memcpy(Result,
+			(void*)((ULONG_PTR)queryComplete + queryComplete->InformationBufferOffset),
+			queryComplete->InformationBufferLength);
+
+	*ResultSize = queryComplete->InformationBufferLength;
+
+Cleanup:
+	if (request)
+	{
+		PutRndisRequest(Device, request);
+	}
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+static inline int
+RndisFilterQueryDeviceMac(
+	RNDIS_DEVICE	*Device
+	)
+{
+	UINT32 size=HW_MACADDR_LEN;
+
+	return RndisFilterQueryDevice(Device,
+									RNDIS_OID_802_3_PERMANENT_ADDRESS,
+									Device->HwMacAddr,
+									&size);
+}
+
+static inline int
+RndisFilterQueryDeviceLinkStatus(
+	RNDIS_DEVICE	*Device
+	)
+{
+	UINT32 size=sizeof(UINT32);
+
+	return RndisFilterQueryDevice(Device,
+									RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
+									&Device->LinkStatus,
+									&size);
+}
+
+static int
+RndisFilterSetPacketFilter(
+	RNDIS_DEVICE	*Device,
+	UINT32			NewFilter
+	)
+{
+	RNDIS_REQUEST *request;
+	RNDIS_SET_REQUEST *set;
+	RNDIS_SET_COMPLETE *setComplete;
+	UINT32 status;
+	int ret;
+
+	DPRINT_ENTER(NETVSC);
+
+	ASSERT(RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(UINT32) <= sizeof(RNDIS_MESSAGE));
+
+	request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(UINT32));
+	if (!request)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	// Setup the rndis set
+	set = &request->RequestMessage.Message.SetRequest;
+	set->Oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER;
+	set->InformationBufferLength = sizeof(UINT32);
+	set->InformationBufferOffset = sizeof(RNDIS_SET_REQUEST);
+
+	memcpy((void*)(ULONG_PTR)set + sizeof(RNDIS_SET_REQUEST), &NewFilter, sizeof(UINT32));
+
+	ret = RndisFilterSendRequest(Device, request);
+	if (ret != 0)
+	{
+		goto Cleanup;
+	}
+
+	ret = WaitEventWaitEx(request->WaitEvent, 2000/*2sec*/);
+	if (!ret)
+	{
+		ret = -1;
+		DPRINT_ERR(NETVSC, "timeout before we got a set response...");
+		// We cant deallocate the request since we may still receive a send completion for it.
+		goto Exit;
+	}
+	else
+	{
+		if (ret > 0)
+		{
+			ret = 0;
+		}
+		setComplete = &request->ResponseMessage.Message.SetComplete;
+		status = setComplete->Status;
+	}
+
+Cleanup:
+	if (request)
+	{
+		PutRndisRequest(Device, request);
+	}
+Exit:
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+int
+RndisFilterInit(
+	NETVSC_DRIVER_OBJECT	*Driver
+	)
+{
+	DPRINT_ENTER(NETVSC);
+
+	DPRINT_DBG(NETVSC, "sizeof(RNDIS_FILTER_PACKET) == %d", sizeof(RNDIS_FILTER_PACKET));
+
+	Driver->RequestExtSize = sizeof(RNDIS_FILTER_PACKET);
+	Driver->AdditionalRequestPageBufferCount = 1; // For rndis header
+
+	//Driver->Context = rndisDriver;
+
+	memset(&gRndisFilter, 0, sizeof(RNDIS_FILTER_DRIVER_OBJECT));
+
+	/*rndisDriver->Driver = Driver;
+
+	ASSERT(Driver->OnLinkStatusChanged);
+	rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/
+
+	// Save the original dispatch handlers before we override it
+	gRndisFilter.InnerDriver.Base.OnDeviceAdd = Driver->Base.OnDeviceAdd;
+	gRndisFilter.InnerDriver.Base.OnDeviceRemove = Driver->Base.OnDeviceRemove;
+	gRndisFilter.InnerDriver.Base.OnCleanup = Driver->Base.OnCleanup;
+
+	ASSERT(Driver->OnSend);
+	ASSERT(Driver->OnReceiveCallback);
+	gRndisFilter.InnerDriver.OnSend = Driver->OnSend;
+	gRndisFilter.InnerDriver.OnReceiveCallback = Driver->OnReceiveCallback;
+	gRndisFilter.InnerDriver.OnLinkStatusChanged = Driver->OnLinkStatusChanged;
+
+	// Override
+	Driver->Base.OnDeviceAdd = RndisFilterOnDeviceAdd;
+	Driver->Base.OnDeviceRemove = RndisFilterOnDeviceRemove;
+	Driver->Base.OnCleanup = RndisFilterOnCleanup;
+	Driver->OnSend = RndisFilterOnSend;
+	Driver->OnOpen = RndisFilterOnOpen;
+	Driver->OnClose = RndisFilterOnClose;
+	//Driver->QueryLinkStatus = RndisFilterQueryDeviceLinkStatus;
+	Driver->OnReceiveCallback = RndisFilterOnReceive;
+
+	DPRINT_EXIT(NETVSC);
+
+	return 0;
+}
+
+static int
+RndisFilterInitDevice(
+	RNDIS_DEVICE	*Device
+	)
+{
+	RNDIS_REQUEST *request;
+	RNDIS_INITIALIZE_REQUEST *init;
+	RNDIS_INITIALIZE_COMPLETE *initComplete;
+	UINT32 status;
+	int ret;
+
+	DPRINT_ENTER(NETVSC);
+
+	request = GetRndisRequest(Device, REMOTE_NDIS_INITIALIZE_MSG, RNDIS_MESSAGE_SIZE(RNDIS_INITIALIZE_REQUEST));
+	if (!request)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	// Setup the rndis set
+	init = &request->RequestMessage.Message.InitializeRequest;
+	init->MajorVersion = RNDIS_MAJOR_VERSION;
+	init->MinorVersion = RNDIS_MINOR_VERSION;
+	init->MaxTransferSize = 2048; // FIXME: Use 1536 - rounded ethernet frame size
+
+	Device->State = RNDIS_DEV_INITIALIZING;
+
+	ret = RndisFilterSendRequest(Device, request);
+	if (ret != 0)
+	{
+		Device->State = RNDIS_DEV_UNINITIALIZED;
+		goto Cleanup;
+	}
+
+	WaitEventWait(request->WaitEvent);
+
+	initComplete = &request->ResponseMessage.Message.InitializeComplete;
+	status = initComplete->Status;
+	if (status == RNDIS_STATUS_SUCCESS)
+	{
+		Device->State = RNDIS_DEV_INITIALIZED;
+		ret = 0;
+	}
+	else
+	{
+		Device->State = RNDIS_DEV_UNINITIALIZED;
+		ret = -1;
+	}
+
+Cleanup:
+	if (request)
+	{
+		PutRndisRequest(Device, request);
+	}
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+static void
+RndisFilterHaltDevice(
+	RNDIS_DEVICE	*Device
+	)
+{
+	RNDIS_REQUEST *request;
+	RNDIS_HALT_REQUEST *halt;
+
+	DPRINT_ENTER(NETVSC);
+
+	// Attempt to do a rndis device halt
+	request = GetRndisRequest(Device, REMOTE_NDIS_HALT_MSG, RNDIS_MESSAGE_SIZE(RNDIS_HALT_REQUEST));
+	if (!request)
+	{
+		goto Cleanup;
+	}
+
+	// Setup the rndis set
+	halt = &request->RequestMessage.Message.HaltRequest;
+	halt->RequestId = InterlockedIncrement((int*)&Device->NewRequestId);
+
+	// Ignore return since this msg is optional.
+	RndisFilterSendRequest(Device, request);
+
+	Device->State = RNDIS_DEV_UNINITIALIZED;
+
+Cleanup:
+	if (request)
+	{
+		PutRndisRequest(Device, request);
+	}
+	DPRINT_EXIT(NETVSC);
+	return;
+}
+
+
+static int
+RndisFilterOpenDevice(
+	RNDIS_DEVICE	*Device
+	)
+{
+	int ret=0;
+
+	DPRINT_ENTER(NETVSC);
+
+	if (Device->State != RNDIS_DEV_INITIALIZED)
+		return 0;
+
+	ret = RndisFilterSetPacketFilter(Device, NDIS_PACKET_TYPE_BROADCAST|NDIS_PACKET_TYPE_DIRECTED);
+	if (ret == 0)
+	{
+		Device->State = RNDIS_DEV_DATAINITIALIZED;
+	}
+
+	DPRINT_EXIT(NETVSC);
+	return ret;
+}
+
+static int
+RndisFilterCloseDevice(
+	RNDIS_DEVICE		*Device
+	)
+{
+	int ret;
+
+	DPRINT_ENTER(NETVSC);
+
+	if (Device->State != RNDIS_DEV_DATAINITIALIZED)
+		return 0;
+
+	ret = RndisFilterSetPacketFilter(Device, 0);
+	if (ret == 0)
+	{
+		Device->State = RNDIS_DEV_INITIALIZED;
+	}
+
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+
+int
+RndisFilterOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	)
+{
+	int ret;
+	NETVSC_DEVICE *netDevice;
+	RNDIS_DEVICE *rndisDevice;
+	NETVSC_DEVICE_INFO *deviceInfo = (NETVSC_DEVICE_INFO*)AdditionalInfo;
+
+	DPRINT_ENTER(NETVSC);
+
+	//rndisDevice = MemAlloc(sizeof(RNDIS_DEVICE));
+	rndisDevice = GetRndisDevice();
+	if (!rndisDevice)
+	{
+		DPRINT_EXIT(NETVSC);
+		return -1;
+	}
+
+	DPRINT_DBG(NETVSC, "rndis device object allocated - %p", rndisDevice);
+
+	// Let the inner driver handle this first to create the netvsc channel
+	// NOTE! Once the channel is created, we may get a receive callback
+	// (RndisFilterOnReceive()) before this call is completed
+	ret = gRndisFilter.InnerDriver.Base.OnDeviceAdd(Device, AdditionalInfo);
+	if (ret != 0)
+	{
+		PutRndisDevice(rndisDevice);
+		DPRINT_EXIT(NETVSC);
+		return ret;
+	}
+
+	//
+	// Initialize the rndis device
+	//
+	netDevice = (NETVSC_DEVICE*)Device->Extension;
+	ASSERT(netDevice);
+	ASSERT(netDevice->Device);
+
+	netDevice->Extension = rndisDevice;
+	rndisDevice->NetDevice = netDevice;
+
+	// Send the rndis initialization message
+	ret = RndisFilterInitDevice(rndisDevice);
+	if (ret != 0)
+	{
+		// TODO: If rndis init failed, we will need to shut down the channel
+	}
+
+	// Get the mac address
+	ret = RndisFilterQueryDeviceMac(rndisDevice);
+	if (ret != 0)
+	{
+		// TODO: shutdown rndis device and the channel
+	}
+
+	DPRINT_INFO(NETVSC, "Device 0x%p mac addr %02x%02x%02x%02x%02x%02x",
+				rndisDevice,
+				rndisDevice->HwMacAddr[0],
+				rndisDevice->HwMacAddr[1],
+				rndisDevice->HwMacAddr[2],
+				rndisDevice->HwMacAddr[3],
+				rndisDevice->HwMacAddr[4],
+				rndisDevice->HwMacAddr[5]);
+
+	memcpy(deviceInfo->MacAddr, rndisDevice->HwMacAddr, HW_MACADDR_LEN);
+
+	RndisFilterQueryDeviceLinkStatus(rndisDevice);
+
+	deviceInfo->LinkState = rndisDevice->LinkStatus;
+	DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, ((deviceInfo->LinkState)?("down"):("up")));
+
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+
+static int
+RndisFilterOnDeviceRemove(
+	DEVICE_OBJECT *Device
+	)
+{
+	NETVSC_DEVICE *netDevice = (NETVSC_DEVICE*)Device->Extension;
+	RNDIS_DEVICE *rndisDevice = (RNDIS_DEVICE*)netDevice->Extension;
+
+	DPRINT_ENTER(NETVSC);
+
+	// Halt and release the rndis device
+	RndisFilterHaltDevice(rndisDevice);
+
+	PutRndisDevice(rndisDevice);
+	netDevice->Extension = NULL;
+
+	// Pass control to inner driver to remove the device
+	gRndisFilter.InnerDriver.Base.OnDeviceRemove(Device);
+
+	DPRINT_EXIT(NETVSC);
+
+	return 0;
+}
+
+
+static void
+RndisFilterOnCleanup(
+	DRIVER_OBJECT *Driver
+	)
+{
+	DPRINT_ENTER(NETVSC);
+
+	DPRINT_EXIT(NETVSC);
+}
+
+static int
+RndisFilterOnOpen(
+	DEVICE_OBJECT		*Device
+	)
+{
+	int ret;
+	NETVSC_DEVICE *netDevice = (NETVSC_DEVICE*)Device->Extension;
+
+	DPRINT_ENTER(NETVSC);
+
+	ASSERT(netDevice);
+	ret = RndisFilterOpenDevice((RNDIS_DEVICE*)netDevice->Extension);
+
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+static int
+RndisFilterOnClose(
+	DEVICE_OBJECT		*Device
+	)
+{
+	int ret;
+	NETVSC_DEVICE *netDevice = (NETVSC_DEVICE*)Device->Extension;
+
+	DPRINT_ENTER(NETVSC);
+
+	ASSERT(netDevice);
+	ret = RndisFilterCloseDevice((RNDIS_DEVICE*)netDevice->Extension);
+
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+
+static int
+RndisFilterOnSend(
+	DEVICE_OBJECT		*Device,
+	NETVSC_PACKET		*Packet
+	)
+{
+	int ret=0;
+	RNDIS_FILTER_PACKET *filterPacket;
+	RNDIS_MESSAGE *rndisMessage;
+	RNDIS_PACKET *rndisPacket;
+	UINT32 rndisMessageSize;
+
+	DPRINT_ENTER(NETVSC);
+
+	// Add the rndis header
+	filterPacket = (RNDIS_FILTER_PACKET*)Packet->Extension;
+	ASSERT(filterPacket);
+
+	memset(filterPacket, 0, sizeof(RNDIS_FILTER_PACKET));
+
+	rndisMessage = &filterPacket->Message;
+	rndisMessageSize = RNDIS_MESSAGE_SIZE(RNDIS_PACKET);
+
+	rndisMessage->NdisMessageType = REMOTE_NDIS_PACKET_MSG;
+	rndisMessage->MessageLength = Packet->TotalDataBufferLength + rndisMessageSize;
+
+	rndisPacket = &rndisMessage->Message.Packet;
+	rndisPacket->DataOffset = sizeof(RNDIS_PACKET);
+	rndisPacket->DataLength = Packet->TotalDataBufferLength;
+
+	Packet->IsDataPacket = TRUE;
+	Packet->PageBuffers[0].Pfn		= GetPhysicalAddress(rndisMessage) >> PAGE_SHIFT;
+	Packet->PageBuffers[0].Offset	= (ULONG_PTR)rndisMessage & (PAGE_SIZE-1);
+	Packet->PageBuffers[0].Length	= rndisMessageSize;
+
+	// Save the packet send completion and context
+	filterPacket->OnCompletion = Packet->Completion.Send.OnSendCompletion;
+	filterPacket->CompletionContext = Packet->Completion.Send.SendCompletionContext;
+
+	// Use ours
+	Packet->Completion.Send.OnSendCompletion = RndisFilterOnSendCompletion;
+	Packet->Completion.Send.SendCompletionContext = filterPacket;
+
+	ret = gRndisFilter.InnerDriver.OnSend(Device, Packet);
+	if (ret != 0)
+	{
+		// Reset the completion to originals to allow retries from above
+		Packet->Completion.Send.OnSendCompletion = filterPacket->OnCompletion;
+		Packet->Completion.Send.SendCompletionContext = filterPacket->CompletionContext;
+	}
+
+	DPRINT_EXIT(NETVSC);
+
+	return ret;
+}
+
+static void
+RndisFilterOnSendCompletion(
+   void *Context)
+{
+	RNDIS_FILTER_PACKET *filterPacket = (RNDIS_FILTER_PACKET *)Context;
+
+	DPRINT_ENTER(NETVSC);
+
+	// Pass it back to the original handler
+	filterPacket->OnCompletion(filterPacket->CompletionContext);
+
+	DPRINT_EXIT(NETVSC);
+}
+
+
+static void
+RndisFilterOnSendRequestCompletion(
+   void *Context
+   )
+{
+	DPRINT_ENTER(NETVSC);
+
+	// Noop
+	DPRINT_EXIT(NETVSC);
+}
--- /dev/null
+++ b/drivers/staging/hv/RndisFilter.h
@@ -0,0 +1,61 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#ifndef _RNDISFILTER_H_
+#define _RNDISFILTER_H_
+
+#define __struct_bcount(x)
+
+#include "osd.h"
+#include "NetVsc.h"
+
+#include "rndis.h"
+
+#define RNDIS_HEADER_SIZE	(sizeof(RNDIS_MESSAGE) - sizeof(RNDIS_MESSAGE_CONTAINER))
+
+#define NDIS_PACKET_TYPE_DIRECTED	0x00000001
+#define NDIS_PACKET_TYPE_MULTICAST	0x00000002
+#define NDIS_PACKET_TYPE_ALL_MULTICAST	0x00000004
+#define NDIS_PACKET_TYPE_BROADCAST	0x00000008
+#define NDIS_PACKET_TYPE_SOURCE_ROUTING	0x00000010
+#define NDIS_PACKET_TYPE_PROMISCUOUS	0x00000020
+#define NDIS_PACKET_TYPE_SMT		0x00000040
+#define NDIS_PACKET_TYPE_ALL_LOCAL	0x00000080
+#define NDIS_PACKET_TYPE_GROUP		0x00000100
+#define NDIS_PACKET_TYPE_ALL_FUNCTIONAL	0x00000200
+#define NDIS_PACKET_TYPE_FUNCTIONAL	0x00000400
+#define NDIS_PACKET_TYPE_MAC_FRAME	0x00000800
+
+
+
+//
+// Interface
+//
+int
+RndisFilterInit(
+	NETVSC_DRIVER_OBJECT *Driver
+	);
+
+
+#endif // _RNDISFILTER_H_

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 06/54] Staging: hv: add the Hyper-V virtual storage driver
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (5 preceding siblings ...)
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-virtual-storage-driver.patch --]
[-- Type: text/plain, Size: 65373 bytes --]

From: Hank Janssen <hjanssen@microsoft.com>

This is the virtual storage driver when running Linux on top of Hyper-V.

Signed-off-by: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/StorVsc.c     |  967 ++++++++++++++++++++++++++
 drivers/staging/hv/storvsc_drv.c | 1413 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 2380 insertions(+)

--- /dev/null
+++ b/drivers/staging/hv/StorVsc.c
@@ -0,0 +1,967 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include "logging.h"
+
+#include "StorVscApi.h"
+#include "VmbusPacketFormat.h"
+#include "vstorage.h"
+
+
+//
+// #defines
+//
+
+//
+// Data types
+//
+
+typedef struct _STORVSC_REQUEST_EXTENSION {
+	//LIST_ENTRY						ListEntry;
+
+	STORVSC_REQUEST					*Request;
+	DEVICE_OBJECT					*Device;
+
+	// Synchronize the request/response if needed
+	HANDLE							WaitEvent;
+
+	VSTOR_PACKET					VStorPacket;
+} STORVSC_REQUEST_EXTENSION;
+
+
+// A storvsc device is a device object that contains a vmbus channel
+typedef struct _STORVSC_DEVICE{
+	DEVICE_OBJECT				*Device;
+
+	int							RefCount; // 0 indicates the device is being destroyed
+
+	int							NumOutstandingRequests;
+
+	//  Each unique Port/Path/Target represents 1 channel ie scsi controller. In reality, the pathid, targetid is always 0
+	// and the port is set by us
+	ULONG						PortNumber;
+    UCHAR						PathId;
+    UCHAR						TargetId;
+
+	//LIST_ENTRY					OutstandingRequestList;
+	//HANDLE						OutstandingRequestLock;
+
+	// Used for vsc/vsp channel reset process
+	STORVSC_REQUEST_EXTENSION	InitRequest;
+
+	STORVSC_REQUEST_EXTENSION	ResetRequest;
+
+} STORVSC_DEVICE;
+
+
+//
+// Globals
+//
+static const char* gDriverName="storvsc";
+
+//{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
+static const GUID gStorVscDeviceType={
+	.Data = {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f}
+};
+
+//
+// Internal routines
+//
+static int
+StorVscOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	);
+
+static int
+StorVscOnDeviceRemove(
+	DEVICE_OBJECT	*Device
+	);
+
+static int
+StorVscOnIORequest(
+	DEVICE_OBJECT	*Device,
+	STORVSC_REQUEST	*Request
+	);
+
+static int
+StorVscOnHostReset(
+	DEVICE_OBJECT	*Device
+	);
+
+static void
+StorVscOnCleanup(
+	DRIVER_OBJECT	*Device
+	);
+
+static void
+StorVscOnChannelCallback(
+	PVOID Context
+	);
+
+static void
+StorVscOnIOCompletion(
+	DEVICE_OBJECT	*Device,
+	VSTOR_PACKET	*VStorPacket,
+	STORVSC_REQUEST_EXTENSION *RequestExt
+	);
+
+static void
+StorVscOnReceive(
+	DEVICE_OBJECT	*Device,
+	VSTOR_PACKET	*VStorPacket,
+	STORVSC_REQUEST_EXTENSION *RequestExt
+	);
+
+static int
+StorVscConnectToVsp(
+	DEVICE_OBJECT	*Device
+	);
+
+static inline STORVSC_DEVICE* AllocStorDevice(DEVICE_OBJECT *Device)
+{
+	STORVSC_DEVICE *storDevice;
+
+	storDevice = MemAllocZeroed(sizeof(STORVSC_DEVICE));
+	if (!storDevice)
+		return NULL;
+
+	// Set to 2 to allow both inbound and outbound traffics
+	// (ie GetStorDevice() and MustGetStorDevice()) to proceed.
+	InterlockedCompareExchange(&storDevice->RefCount, 2, 0);
+
+	storDevice->Device = Device;
+	Device->Extension = storDevice;
+
+	return storDevice;
+}
+
+static inline void FreeStorDevice(STORVSC_DEVICE *Device)
+{
+	ASSERT(Device->RefCount == 0);
+	MemFree(Device);
+}
+
+// Get the stordevice object iff exists and its refcount > 1
+static inline STORVSC_DEVICE* GetStorDevice(DEVICE_OBJECT *Device)
+{
+	STORVSC_DEVICE *storDevice;
+
+	storDevice = (STORVSC_DEVICE*)Device->Extension;
+	if (storDevice && storDevice->RefCount > 1)
+	{
+		InterlockedIncrement(&storDevice->RefCount);
+	}
+	else
+	{
+		storDevice = NULL;
+	}
+
+	return storDevice;
+}
+
+// Get the stordevice object iff exists and its refcount > 0
+static inline STORVSC_DEVICE* MustGetStorDevice(DEVICE_OBJECT *Device)
+{
+	STORVSC_DEVICE *storDevice;
+
+	storDevice = (STORVSC_DEVICE*)Device->Extension;
+	if (storDevice && storDevice->RefCount)
+	{
+		InterlockedIncrement(&storDevice->RefCount);
+	}
+	else
+	{
+		storDevice = NULL;
+	}
+
+	return storDevice;
+}
+
+static inline void PutStorDevice(DEVICE_OBJECT *Device)
+{
+	STORVSC_DEVICE *storDevice;
+
+	storDevice = (STORVSC_DEVICE*)Device->Extension;
+	ASSERT(storDevice);
+
+	InterlockedDecrement(&storDevice->RefCount);
+	ASSERT(storDevice->RefCount);
+}
+
+// Drop ref count to 1 to effectively disable GetStorDevice()
+static inline STORVSC_DEVICE* ReleaseStorDevice(DEVICE_OBJECT *Device)
+{
+	STORVSC_DEVICE *storDevice;
+
+	storDevice = (STORVSC_DEVICE*)Device->Extension;
+	ASSERT(storDevice);
+
+	// Busy wait until the ref drop to 2, then set it to 1
+	while (InterlockedCompareExchange(&storDevice->RefCount, 1, 2) != 2)
+	{
+		Sleep(100);
+	}
+
+	return storDevice;
+}
+
+// Drop ref count to 0. No one can use StorDevice object.
+static inline STORVSC_DEVICE* FinalReleaseStorDevice(DEVICE_OBJECT *Device)
+{
+	STORVSC_DEVICE *storDevice;
+
+	storDevice = (STORVSC_DEVICE*)Device->Extension;
+	ASSERT(storDevice);
+
+	// Busy wait until the ref drop to 1, then set it to 0
+	while (InterlockedCompareExchange(&storDevice->RefCount, 0, 1) != 1)
+	{
+		Sleep(100);
+	}
+
+	Device->Extension = NULL;
+	return storDevice;
+}
+
+/*++;
+
+
+Name:
+	StorVscInitialize()
+
+Description:
+	Main entry point
+
+--*/
+int
+StorVscInitialize(
+	DRIVER_OBJECT *Driver
+	)
+{
+	STORVSC_DRIVER_OBJECT* storDriver = (STORVSC_DRIVER_OBJECT*)Driver;
+	int ret=0;
+
+	DPRINT_ENTER(STORVSC);
+
+	DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%d sizeof(STORVSC_REQUEST_EXTENSION)=%d sizeof(VSTOR_PACKET)=%d, sizeof(VMSCSI_REQUEST)=%d",
+		sizeof(STORVSC_REQUEST), sizeof(STORVSC_REQUEST_EXTENSION), sizeof(VSTOR_PACKET), sizeof(VMSCSI_REQUEST));
+
+	// Make sure we are at least 2 pages since 1 page is used for control
+	ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1));
+
+	Driver->name = gDriverName;
+	memcpy(&Driver->deviceType, &gStorVscDeviceType, sizeof(GUID));
+
+	storDriver->RequestExtSize			= sizeof(STORVSC_REQUEST_EXTENSION);
+
+	// Divide the ring buffer data size (which is 1 page less than the ring buffer size since that page is reserved for the ring buffer indices)
+	// by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + UINT64)
+	storDriver->MaxOutstandingRequestsPerChannel =
+		((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(UINT64),sizeof(UINT64)));
+
+	DPRINT_INFO(STORVSC, "max io %u, currently %u\n", storDriver->MaxOutstandingRequestsPerChannel, STORVSC_MAX_IO_REQUESTS);
+
+	// Setup the dispatch table
+	storDriver->Base.OnDeviceAdd			= StorVscOnDeviceAdd;
+	storDriver->Base.OnDeviceRemove		= StorVscOnDeviceRemove;
+	storDriver->Base.OnCleanup			= StorVscOnCleanup;
+
+	storDriver->OnIORequest				= StorVscOnIORequest;
+	storDriver->OnHostReset				= StorVscOnHostReset;
+
+	DPRINT_EXIT(STORVSC);
+
+	return ret;
+}
+
+/*++
+
+Name:
+	StorVscOnDeviceAdd()
+
+Description:
+	Callback when the device belonging to this driver is added
+
+--*/
+int
+StorVscOnDeviceAdd(
+	DEVICE_OBJECT	*Device,
+	void			*AdditionalInfo
+	)
+{
+	int ret=0;
+	STORVSC_DEVICE *storDevice;
+	//VMSTORAGE_CHANNEL_PROPERTIES *props;
+	STORVSC_DEVICE_INFO *deviceInfo = (STORVSC_DEVICE_INFO*)AdditionalInfo;
+
+	DPRINT_ENTER(STORVSC);
+
+	storDevice = AllocStorDevice(Device);
+	if (!storDevice)
+	{
+		ret = -1;
+		goto Cleanup;
+	}
+
+	// Save the channel properties to our storvsc channel
+	//props = (VMSTORAGE_CHANNEL_PROPERTIES*) channel->offerMsg.Offer.u.Standard.UserDefined;
+
+	// FIXME:
+	// If we support more than 1 scsi channel, we need to set the port number here
+	// to the scsi channel but how do we get the scsi channel prior to the bus scan
+	/*storChannel->PortNumber = 0;
+	storChannel->PathId = props->PathId;
+	storChannel->TargetId = props->TargetId;*/
+
+	storDevice->PortNumber = deviceInfo->PortNumber;
+	// Send it back up
+	ret = StorVscConnectToVsp(Device);
+
+	//deviceInfo->PortNumber = storDevice->PortNumber;
+	deviceInfo->PathId = storDevice->PathId;
+	deviceInfo->TargetId = storDevice->TargetId;
+
+	DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", storDevice->PortNumber, storDevice->PathId, storDevice->TargetId);
+
+Cleanup:
+	DPRINT_EXIT(STORVSC);
+
+	return ret;
+}
+
+static int StorVscChannelInit(DEVICE_OBJECT *Device)
+{
+	int ret=0;
+	STORVSC_DEVICE *storDevice;
+	STORVSC_REQUEST_EXTENSION *request;
+	VSTOR_PACKET *vstorPacket;
+
+	storDevice = GetStorDevice(Device);
+	if (!storDevice)
+	{
+		DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
+		DPRINT_EXIT(STORVSC);
+		return -1;
+	}
+
+	request = &storDevice->InitRequest;
+	vstorPacket = &request->VStorPacket;
+
+	// Now, initiate the vsc/vsp initialization protocol on the open channel
+
+	memset(request, sizeof(STORVSC_REQUEST_EXTENSION), 0);
+	request->WaitEvent = WaitEventCreate();
+
+	vstorPacket->Operation = VStorOperationBeginInitialization;
+	vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
+
+	/*SpinlockAcquire(gDriverExt.packetListLock);
+	INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry);
+	SpinlockRelease(gDriverExt.packetListLock);*/
+
+	DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
+
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															vstorPacket,
+															sizeof(VSTOR_PACKET),
+															(ULONG_PTR)request,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+	if ( ret != 0)
+	{
+		DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION");
+		goto Cleanup;
+	}
+
+	WaitEventWait(request->WaitEvent);
+
+	if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
+	{
+		DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
+		goto Cleanup;
+	}
+
+	DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
+
+	// reuse the packet for version range supported
+	memset(vstorPacket, sizeof(VSTOR_PACKET), 0);
+	vstorPacket->Operation = VStorOperationQueryProtocolVersion;
+	vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
+
+    vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT;
+    FILL_VMSTOR_REVISION(vstorPacket->Version.Revision);
+
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															vstorPacket,
+															sizeof(VSTOR_PACKET),
+															(ULONG_PTR)request,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+	if ( ret != 0)
+	{
+		DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION");
+		goto Cleanup;
+	}
+
+	WaitEventWait(request->WaitEvent);
+
+	// TODO: Check returned version
+	if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
+	{
+		DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
+		goto Cleanup;
+	}
+
+	// Query channel properties
+	DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
+
+	memset(vstorPacket, sizeof(VSTOR_PACKET), 0);
+    vstorPacket->Operation = VStorOperationQueryProperties;
+	vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
+    vstorPacket->StorageChannelProperties.PortNumber = storDevice->PortNumber;
+
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															vstorPacket,
+															sizeof(VSTOR_PACKET),
+															(ULONG_PTR)request,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+
+	if ( ret != 0)
+	{
+		DPRINT_ERR(STORVSC, "unable to send QUERY_PROPERTIES_OPERATION");
+		goto Cleanup;
+	}
+
+	WaitEventWait(request->WaitEvent);
+
+	// TODO: Check returned version
+	if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
+	{
+		DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
+		goto Cleanup;
+	}
+
+	//storDevice->PortNumber = vstorPacket->StorageChannelProperties.PortNumber;
+	storDevice->PathId = vstorPacket->StorageChannelProperties.PathId;
+	storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId;
+
+	DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", vstorPacket->StorageChannelProperties.Flags, vstorPacket->StorageChannelProperties.MaxTransferBytes);
+
+	DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
+
+	memset(vstorPacket, sizeof(VSTOR_PACKET), 0);
+    vstorPacket->Operation = VStorOperationEndInitialization;
+	vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
+
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															vstorPacket,
+															sizeof(VSTOR_PACKET),
+															(ULONG_PTR)request,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+
+	if ( ret != 0)
+	{
+		DPRINT_ERR(STORVSC, "unable to send END_INITIALIZATION_OPERATION");
+		goto Cleanup;
+	}
+
+	WaitEventWait(request->WaitEvent);
+
+	if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
+	{
+		DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
+		goto Cleanup;
+	}
+
+	DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
+
+Cleanup:
+	if (request->WaitEvent)
+	{
+		WaitEventClose(request->WaitEvent);
+		request->WaitEvent = NULL;
+	}
+
+	PutStorDevice(Device);
+
+	DPRINT_EXIT(STORVSC);
+	return ret;
+}
+
+
+int
+StorVscConnectToVsp(
+	DEVICE_OBJECT	*Device
+	)
+{
+	int ret=0;
+    VMSTORAGE_CHANNEL_PROPERTIES props;
+
+	STORVSC_DRIVER_OBJECT *storDriver = (STORVSC_DRIVER_OBJECT*) Device->Driver;;
+
+	memset(&props, sizeof(VMSTORAGE_CHANNEL_PROPERTIES), 0);
+
+	// Open the channel
+	ret = Device->Driver->VmbusChannelInterface.Open(Device,
+		storDriver->RingBufferSize,
+		storDriver->RingBufferSize,
+		(PVOID)&props,
+		sizeof(VMSTORAGE_CHANNEL_PROPERTIES),
+		StorVscOnChannelCallback,
+		Device
+		);
+
+	DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", props.PathId, props.TargetId, props.MaxTransferBytes);
+
+	if (ret != 0)
+	{
+		DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
+		return -1;
+	}
+
+	ret = StorVscChannelInit(Device);
+
+	return ret;
+}
+
+
+/*++
+
+Name:
+	StorVscOnDeviceRemove()
+
+Description:
+	Callback when the our device is being removed
+
+--*/
+int
+StorVscOnDeviceRemove(
+	DEVICE_OBJECT *Device
+	)
+{
+	STORVSC_DEVICE *storDevice;
+	int ret=0;
+
+	DPRINT_ENTER(STORVSC);
+
+	DPRINT_INFO(STORVSC, "disabling storage device (%p)...", Device->Extension);
+
+	storDevice = ReleaseStorDevice(Device);
+
+	// At this point, all outbound traffic should be disable. We only allow inbound traffic (responses) to proceed
+	// so that outstanding requests can be completed.
+	while (storDevice->NumOutstandingRequests)
+	{
+		DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", storDevice->NumOutstandingRequests);
+
+		Sleep(100);
+	}
+
+	DPRINT_INFO(STORVSC, "removing storage device (%p)...", Device->Extension);
+
+	storDevice = FinalReleaseStorDevice(Device);
+
+	DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice);
+
+	// Close the channel
+	Device->Driver->VmbusChannelInterface.Close(Device);
+
+	FreeStorDevice(storDevice);
+
+	DPRINT_EXIT(STORVSC);
+	return ret;
+}
+
+
+//static void
+//StorVscOnTargetRescan(
+//	void *Context
+//	)
+//{
+//	DEVICE_OBJECT *device=(DEVICE_OBJECT*)Context;
+//	STORVSC_DRIVER_OBJECT *storDriver;
+//
+//	DPRINT_ENTER(STORVSC);
+//
+//	storDriver = (STORVSC_DRIVER_OBJECT*) device->Driver;
+//	storDriver->OnHostRescan(device);
+//
+//	DPRINT_EXIT(STORVSC);
+//}
+
+int
+StorVscOnHostReset(
+	DEVICE_OBJECT *Device
+	)
+{
+	int ret=0;
+
+	STORVSC_DEVICE *storDevice;
+	STORVSC_REQUEST_EXTENSION *request;
+	VSTOR_PACKET *vstorPacket;
+
+	DPRINT_ENTER(STORVSC);
+
+	DPRINT_INFO(STORVSC, "resetting host adapter...");
+
+	storDevice = GetStorDevice(Device);
+	if (!storDevice)
+	{
+		DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
+		DPRINT_EXIT(STORVSC);
+		return -1;
+	}
+
+	request = &storDevice->ResetRequest;
+	vstorPacket = &request->VStorPacket;
+
+	request->WaitEvent = WaitEventCreate();
+
+    vstorPacket->Operation = VStorOperationResetBus;
+    vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
+    vstorPacket->VmSrb.PathId = storDevice->PathId;
+
+	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															vstorPacket,
+															sizeof(VSTOR_PACKET),
+															(ULONG_PTR)&storDevice->ResetRequest,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+	if (ret != 0)
+	{
+		DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", vstorPacket, ret);
+		goto Cleanup;
+	}
+
+	// FIXME: Add a timeout
+	WaitEventWait(request->WaitEvent);
+
+	WaitEventClose(request->WaitEvent);
+	DPRINT_INFO(STORVSC, "host adapter reset completed");
+
+	// At this point, all outstanding requests in the adapter should have been flushed out and return to us
+
+Cleanup:
+	PutStorDevice(Device);
+	DPRINT_EXIT(STORVSC);
+	return ret;
+}
+
+/*++
+
+Name:
+	StorVscOnIORequest()
+
+Description:
+	Callback to initiate an I/O request
+
+--*/
+int
+StorVscOnIORequest(
+	DEVICE_OBJECT	*Device,
+	STORVSC_REQUEST	*Request
+	)
+{
+	STORVSC_DEVICE *storDevice;
+	STORVSC_REQUEST_EXTENSION* requestExtension = (STORVSC_REQUEST_EXTENSION*) Request->Extension;
+	VSTOR_PACKET* vstorPacket =&requestExtension->VStorPacket;
+	int ret=0;
+
+	DPRINT_ENTER(STORVSC);
+
+	storDevice = GetStorDevice(Device);
+
+	DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, Extension %p",
+		Device, storDevice, Request, requestExtension);
+
+	DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
+		Request, Request->DataBuffer.Length, Request->Bus, Request->TargetId, Request->LunId, Request->CdbLen);
+
+	if (!storDevice)
+	{
+		DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
+		DPRINT_EXIT(STORVSC);
+		return -2;
+	}
+
+	//PrintBytes(Request->Cdb, Request->CdbLen);
+
+	requestExtension->Request = Request;
+	requestExtension->Device  = Device;
+
+	memset(vstorPacket, 0 , sizeof(VSTOR_PACKET));
+
+	vstorPacket->Flags |= REQUEST_COMPLETION_FLAG;
+
+    vstorPacket->VmSrb.Length = sizeof(VMSCSI_REQUEST);
+
+	vstorPacket->VmSrb.PortNumber = Request->Host;
+    vstorPacket->VmSrb.PathId = Request->Bus;
+    vstorPacket->VmSrb.TargetId = Request->TargetId;
+    vstorPacket->VmSrb.Lun = Request->LunId;
+
+	vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE;
+
+	// Copy over the scsi command descriptor block
+    vstorPacket->VmSrb.CdbLength = Request->CdbLen;
+	memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen);
+
+	vstorPacket->VmSrb.DataIn = Request->Type;
+	vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length;
+
+	vstorPacket->Operation = VStorOperationExecuteSRB;
+
+	DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, lun %d senselen %d cdblen %d",
+		vstorPacket->VmSrb.Length,
+		vstorPacket->VmSrb.PortNumber,
+		vstorPacket->VmSrb.PathId,
+		vstorPacket->VmSrb.TargetId,
+		vstorPacket->VmSrb.Lun,
+		vstorPacket->VmSrb.SenseInfoLength,
+		vstorPacket->VmSrb.CdbLength);
+
+	if (requestExtension->Request->DataBuffer.Length)
+	{
+		ret = Device->Driver->VmbusChannelInterface.SendPacketMultiPageBuffer(Device,
+				&requestExtension->Request->DataBuffer,
+				vstorPacket,
+				sizeof(VSTOR_PACKET),
+				(ULONG_PTR)requestExtension);
+	}
+	else
+	{
+		ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
+															vstorPacket,
+															sizeof(VSTOR_PACKET),
+															(ULONG_PTR)requestExtension,
+															VmbusPacketTypeDataInBand,
+															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+	}
+
+	if (ret != 0)
+	{
+		DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", vstorPacket, ret);
+	}
+
+	InterlockedIncrement(&storDevice->NumOutstandingRequests);
+
+	PutStorDevice(Device);
+
+	DPRINT_EXIT(STORVSC);
+	return ret;
+}
+
+/*++
+
+Name:
+	StorVscOnCleanup()
+
+Description:
+	Perform any cleanup when the driver is removed
+
+--*/
+void
+StorVscOnCleanup(
+	DRIVER_OBJECT *Driver
+	)
+{
+	DPRINT_ENTER(STORVSC);
+	DPRINT_EXIT(STORVSC);
+}
+
+
+static void
+StorVscOnIOCompletion(
+	DEVICE_OBJECT	*Device,
+	VSTOR_PACKET	*VStorPacket,
+	STORVSC_REQUEST_EXTENSION *RequestExt
+	)
+{
+	STORVSC_REQUEST *request;
+	STORVSC_DEVICE *storDevice;
+
+	DPRINT_ENTER(STORVSC);
+
+	storDevice = MustGetStorDevice(Device);
+	if (!storDevice)
+	{
+		DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
+		DPRINT_EXIT(STORVSC);
+		return;
+	}
+
+	DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p completed bytes xfer %u",
+		RequestExt, VStorPacket->VmSrb.DataTransferLength);
+
+	ASSERT(RequestExt != NULL);
+	ASSERT(RequestExt->Request != NULL);
+
+	request = RequestExt->Request;
+
+	ASSERT(request->OnIOCompletion != NULL);
+
+	// Copy over the status...etc
+	request->Status = VStorPacket->VmSrb.ScsiStatus;
+
+	if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1)
+	{
+		DPRINT_WARN(STORVSC, "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
+			request->Cdb[0],
+			VStorPacket->VmSrb.ScsiStatus,
+			VStorPacket->VmSrb.SrbStatus);
+	}
+
+	if ((request->Status & 0xFF) == 0x02) // CHECK_CONDITION
+	{
+		if (VStorPacket->VmSrb.SrbStatus & 0x80) // autosense data available
+		{
+			DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data valid - len %d\n",
+				RequestExt, VStorPacket->VmSrb.SenseInfoLength);
+
+			ASSERT(VStorPacket->VmSrb.SenseInfoLength <=  request->SenseBufferSize);
+			memcpy(request->SenseBuffer,
+				VStorPacket->VmSrb.SenseData,
+				VStorPacket->VmSrb.SenseInfoLength);
+
+			request->SenseBufferSize = VStorPacket->VmSrb.SenseInfoLength;
+		}
+	}
+
+	// TODO:
+	request->BytesXfer = VStorPacket->VmSrb.DataTransferLength;
+
+	request->OnIOCompletion(request);
+
+	InterlockedDecrement(&storDevice->NumOutstandingRequests);
+
+	PutStorDevice(Device);
+
+	DPRINT_EXIT(STORVSC);
+}
+
+
+static void
+StorVscOnReceive(
+	DEVICE_OBJECT	*Device,
+	VSTOR_PACKET	*VStorPacket,
+	STORVSC_REQUEST_EXTENSION *RequestExt
+	)
+{
+	switch(VStorPacket->Operation)
+	{
+		case VStorOperationCompleteIo:
+
+			DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
+			StorVscOnIOCompletion(Device, VStorPacket, RequestExt);
+			break;
+
+		//case ENUMERATE_DEVICE_OPERATION:
+
+		//	DPRINT_INFO(STORVSC, "ENUMERATE_DEVICE_OPERATION");
+
+		//	StorVscOnTargetRescan(Device);
+		//	break;
+
+        case VStorOperationRemoveDevice:
+
+			DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
+			// TODO:
+			break;
+
+		default:
+			DPRINT_INFO(STORVSC, "Unknown operation received - %d", VStorPacket->Operation);
+			break;
+	}
+}
+
+void
+StorVscOnChannelCallback(
+	PVOID Context
+	)
+{
+	int ret=0;
+	DEVICE_OBJECT *device = (DEVICE_OBJECT*)Context;
+	STORVSC_DEVICE *storDevice;
+	UINT32 bytesRecvd;
+	UINT64 requestId;
+	UCHAR packet[ALIGN_UP(sizeof(VSTOR_PACKET),8)];
+	STORVSC_REQUEST_EXTENSION *request;
+
+	DPRINT_ENTER(STORVSC);
+
+	ASSERT(device);
+
+	storDevice = MustGetStorDevice(device);
+	if (!storDevice)
+	{
+		DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
+		DPRINT_EXIT(STORVSC);
+		return;
+	}
+
+	do
+	{
+		ret = device->Driver->VmbusChannelInterface.RecvPacket(device,
+																packet,
+																ALIGN_UP(sizeof(VSTOR_PACKET),8),
+																&bytesRecvd,
+																&requestId);
+		if (ret == 0 && bytesRecvd > 0)
+		{
+			DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", bytesRecvd, requestId);
+
+			//ASSERT(bytesRecvd == sizeof(VSTOR_PACKET));
+
+			request = (STORVSC_REQUEST_EXTENSION*)(ULONG_PTR)requestId;
+			ASSERT(request);
+
+			//if (vstorPacket.Flags & SYNTHETIC_FLAG)
+			if ((request == &storDevice->InitRequest) || (request == &storDevice->ResetRequest))
+			{
+				//DPRINT_INFO(STORVSC, "reset completion - operation %u status %u", vstorPacket.Operation, vstorPacket.Status);
+
+				memcpy(&request->VStorPacket, packet, sizeof(VSTOR_PACKET));
+
+				WaitEventSet(request->WaitEvent);
+			}
+			else
+			{
+				StorVscOnReceive(device, (VSTOR_PACKET*)packet, request);
+			}
+		}
+		else
+		{
+			//DPRINT_DBG(STORVSC, "nothing else to read...");
+			break;
+		}
+	} while (1);
+
+	PutStorDevice(device);
+
+	DPRINT_EXIT(STORVSC);
+	return;
+}
--- /dev/null
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -0,0 +1,1413 @@
+/*
+ *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Authors:
+ *   Haiyang Zhang <haiyangz@microsoft.com>
+ *   Hank Janssen  <hjanssen@microsoft.com>
+ *
+ */
+
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/blkdev.h>
+
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_tcq.h>
+#include <scsi/scsi_eh.h>
+#include <scsi/scsi_devinfo.h>
+
+#ifdef KERNEL_2_6_5
+#else
+#include <scsi/scsi_dbg.h>
+#endif
+
+#include "logging.h"
+#include "vmbus.h"
+
+#include "StorVscApi.h"
+
+//
+// #defines
+//
+
+//
+// Data types
+//
+struct host_device_context {
+    struct work_struct		host_rescan_work;  //must be 1st field
+    struct device_context	*device_ctx; // point back to our device context
+#ifdef KERNEL_2_6_27
+    struct kmem_cache               *request_pool;
+#else
+    kmem_cache_t			*request_pool;
+#endif
+    unsigned int			port;
+    unsigned char			path;
+    unsigned char			target;
+};
+
+struct storvsc_cmd_request {
+	struct list_head	entry;
+	struct scsi_cmnd	*cmd;
+
+	unsigned int bounce_sgl_count;
+	struct scatterlist	*bounce_sgl;
+
+	STORVSC_REQUEST		request;
+	// !!!DO NOT ADD ANYTHING BELOW HERE!!!
+	// The extension buffer falls right here and is pointed to by request.Extension;
+};
+
+struct storvsc_driver_context {
+	// !! These must be the first 2 fields !!
+	struct driver_context	drv_ctx;
+	STORVSC_DRIVER_OBJECT	drv_obj;
+};
+
+// Static decl
+static int storvsc_probe(struct device *dev);
+static int storvsc_queuecommand(struct scsi_cmnd *scmnd, void (*done)(struct scsi_cmnd *));
+static int storvsc_device_alloc(struct scsi_device *);
+static int storvsc_device_configure(struct scsi_device *);
+static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd);
+#ifdef KERNEL_2_6_27
+static void storvsc_host_rescan_callback(struct work_struct *work);
+#else
+static void storvsc_host_rescan_callback(void* context);
+#endif
+static void storvsc_host_rescan(DEVICE_OBJECT* device_obj);
+static int storvsc_remove(struct device *dev);
+
+static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count, unsigned int len);
+static void destroy_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count);
+static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count);
+static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, struct scatterlist *bounce_sgl, unsigned int orig_sgl_count);
+static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, struct scatterlist *bounce_sgl, unsigned int orig_sgl_count);
+
+static int storvsc_report_luns(struct scsi_device *sdev, unsigned int luns[], unsigned int *lun_count);
+static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev, sector_t capacity, int *info);
+
+
+static int storvsc_ringbuffer_size = STORVSC_RING_BUFFER_SIZE;
+
+// The one and only one
+static struct storvsc_driver_context g_storvsc_drv;
+
+// Scsi driver
+static struct scsi_host_template scsi_driver = {
+	.module						= THIS_MODULE,
+	.name						= "storvsc_host_t",
+	.bios_param					= storvsc_get_chs,
+	.queuecommand				= storvsc_queuecommand,
+	.eh_host_reset_handler		= storvsc_host_reset_handler,
+	.slave_alloc				= storvsc_device_alloc,
+	.slave_configure			= storvsc_device_configure,
+	.cmd_per_lun				= 1,
+	.can_queue					= STORVSC_MAX_IO_REQUESTS*STORVSC_MAX_TARGETS, // 64 max_queue * 1 target
+	.this_id					= -1,
+	// no use setting to 0 since ll_blk_rw reset it to 1
+	.sg_tablesize				= MAX_MULTIPAGE_BUFFER_COUNT,// currently 32
+	// ENABLE_CLUSTERING allows mutiple physically contig bio_vecs to merge into 1 sg element. If set, we must
+	// limit the max_segment_size to PAGE_SIZE, otherwise we may get 1 sg element that represents multiple
+	// physically contig pfns (ie sg[x].length > PAGE_SIZE).
+	.use_clustering				= ENABLE_CLUSTERING,
+	// Make sure we dont get a sg segment crosses a page boundary
+	.dma_boundary				= PAGE_SIZE-1,
+};
+
+
+/*++
+
+Name:	storvsc_drv_init()
+
+Desc:	StorVsc driver initialization.
+
+--*/
+int storvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init)
+{
+	int ret=0;
+	STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_storvsc_drv.drv_obj;
+	struct driver_context *drv_ctx=&g_storvsc_drv.drv_ctx;
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+	vmbus_get_interface(&storvsc_drv_obj->Base.VmbusChannelInterface);
+
+	storvsc_drv_obj->RingBufferSize = storvsc_ringbuffer_size;
+	storvsc_drv_obj->OnHostRescan = storvsc_host_rescan;
+
+	// Callback to client driver to complete the initialization
+	pfn_drv_init(&storvsc_drv_obj->Base);
+
+	DPRINT_INFO(STORVSC_DRV, "request extension size %u, max outstanding reqs %u", storvsc_drv_obj->RequestExtSize, storvsc_drv_obj->MaxOutstandingRequestsPerChannel);
+
+	if (storvsc_drv_obj->MaxOutstandingRequestsPerChannel < STORVSC_MAX_IO_REQUESTS)
+	{
+		DPRINT_ERR(STORVSC_DRV, "The number of outstanding io requests (%d) is larger than that supported (%d) internally.",
+			STORVSC_MAX_IO_REQUESTS, storvsc_drv_obj->MaxOutstandingRequestsPerChannel);
+		return -1;
+	}
+
+	drv_ctx->driver.name = storvsc_drv_obj->Base.name;
+	memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, sizeof(GUID));
+
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+	drv_ctx->driver.probe = storvsc_probe;
+	drv_ctx->driver.remove = storvsc_remove;
+#else
+	drv_ctx->probe = storvsc_probe;
+	drv_ctx->remove = storvsc_remove;
+#endif
+
+	// The driver belongs to vmbus
+	vmbus_child_driver_register(drv_ctx);
+
+	DPRINT_EXIT(STORVSC_DRV);
+
+	return ret;
+}
+
+
+static int storvsc_drv_exit_cb(struct device *dev, void *data)
+{
+	struct device **curr = (struct device **)data;
+	*curr = dev;
+	return 1; // stop iterating
+}
+
+/*++
+
+Name:	storvsc_drv_exit()
+
+Desc:
+
+--*/
+void storvsc_drv_exit(void)
+{
+	STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_storvsc_drv.drv_obj;
+	struct driver_context *drv_ctx=&g_storvsc_drv.drv_ctx;
+
+	struct device *current_dev=NULL;
+
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#define driver_for_each_device(drv, start, data, fn) \
+	struct list_head *ptr, *n; \
+	list_for_each_safe(ptr, n, &((drv)->devices)) {\
+		struct device *curr_dev;\
+		curr_dev = list_entry(ptr, struct device, driver_list);\
+		fn(curr_dev, data);\
+	}
+#endif // KERNEL_2_6_9
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+	while (1)
+	{
+		current_dev = NULL;
+
+		// Get the device
+		driver_for_each_device(&drv_ctx->driver, NULL, (void*)&current_dev, storvsc_drv_exit_cb);
+
+		if (current_dev == NULL)
+			break;
+
+		// Initiate removal from the top-down
+		device_unregister(current_dev);
+	}
+
+	if (storvsc_drv_obj->Base.OnCleanup)
+		storvsc_drv_obj->Base.OnCleanup(&storvsc_drv_obj->Base);
+
+	vmbus_child_driver_unregister(drv_ctx);
+
+	DPRINT_EXIT(STORVSC_DRV);
+
+	return;
+}
+
+/*++
+
+Name:	storvsc_probe()
+
+Desc:	Add a new device for this driver
+
+--*/
+static int storvsc_probe(struct device *device)
+{
+	int ret=0;
+
+	struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
+	struct storvsc_driver_context *storvsc_drv_ctx = (struct storvsc_driver_context*)driver_ctx;
+	STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &storvsc_drv_ctx->drv_obj;
+
+	struct device_context *device_ctx = device_to_device_context(device);
+	DEVICE_OBJECT* device_obj = &device_ctx->device_obj;
+
+	struct Scsi_Host *host;
+	struct host_device_context *host_device_ctx;
+	STORVSC_DEVICE_INFO device_info;
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+	if (!storvsc_drv_obj->Base.OnDeviceAdd)
+		return -1;
+
+	host = scsi_host_alloc(&scsi_driver, sizeof(struct host_device_context));
+	if (!host)
+	{
+		DPRINT_ERR(STORVSC_DRV, "unable to allocate scsi host object");
+		return -ENOMEM;
+	}
+
+	device->driver_data = host;
+
+	host_device_ctx = (struct host_device_context*)host->hostdata;
+	memset(host_device_ctx, 0, sizeof(struct host_device_context));
+
+	host_device_ctx->port = host->host_no;
+	host_device_ctx->device_ctx = device_ctx;
+
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#elif defined(KERNEL_2_6_27)
+	INIT_WORK(&host_device_ctx->host_rescan_work, storvsc_host_rescan_callback);
+#else
+	INIT_WORK(&host_device_ctx->host_rescan_work, storvsc_host_rescan_callback, device_obj);
+#endif
+
+#if defined(KERNEL_2_6_27)
+	host_device_ctx->request_pool =
+	    kmem_cache_create
+	    (device_ctx->device.bus_id,
+	     sizeof(struct storvsc_cmd_request) + storvsc_drv_obj->RequestExtSize,
+	     0,
+	     SLAB_HWCACHE_ALIGN, NULL);
+#else
+	host_device_ctx->request_pool =
+	    kmem_cache_create
+	    (device_ctx->device.bus_id,
+	     sizeof(struct storvsc_cmd_request) + storvsc_drv_obj->RequestExtSize,
+	     0,
+	     SLAB_HWCACHE_ALIGN, NULL, NULL);
+#endif
+
+	if (!host_device_ctx->request_pool)
+	{
+		scsi_host_put(host);
+		DPRINT_EXIT(STORVSC_DRV);
+
+		return -ENOMEM;
+	}
+
+	device_info.PortNumber = host->host_no;
+	// Call to the vsc driver to add the device
+	ret = storvsc_drv_obj->Base.OnDeviceAdd(device_obj, (void*)&device_info);
+	if (ret != 0)
+	{
+		DPRINT_ERR(STORVSC_DRV, "unable to add scsi vsc device");
+		kmem_cache_destroy(host_device_ctx->request_pool);
+		scsi_host_put(host);
+		DPRINT_EXIT(STORVSC_DRV);
+
+		return -1;
+	}
+
+	//host_device_ctx->port = device_info.PortNumber;
+	host_device_ctx->path = device_info.PathId;
+	host_device_ctx->target = device_info.TargetId;
+
+	host->max_lun = STORVSC_MAX_LUNS_PER_TARGET;	// max # of devices per target
+	host->max_id = STORVSC_MAX_TARGETS;			// max # of targets per channel
+	host->max_channel = STORVSC_MAX_CHANNELS -1;	// max # of channels
+
+	// Register the HBA and start the scsi bus scan
+	ret = scsi_add_host(host, device);
+	if (ret != 0)
+	{
+		DPRINT_ERR(STORVSC_DRV, "unable to add scsi host device");
+
+		storvsc_drv_obj->Base.OnDeviceRemove(device_obj);
+
+		kmem_cache_destroy(host_device_ctx->request_pool);
+		scsi_host_put(host);
+		DPRINT_EXIT(STORVSC_DRV);
+
+		return -1;
+	}
+
+	scsi_scan_host(host);
+
+	DPRINT_EXIT(STORVSC_DRV);
+
+	return ret;
+}
+
+
+/*++
+
+Name:	storvsc_remove()
+
+Desc:	Callback when our device is removed
+
+--*/
+static int storvsc_remove(struct device *device)
+{
+	int ret=0;
+
+	struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
+	struct storvsc_driver_context *storvsc_drv_ctx = (struct storvsc_driver_context*)driver_ctx;
+	STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &storvsc_drv_ctx->drv_obj;
+
+	struct device_context *device_ctx = device_to_device_context(device);
+	DEVICE_OBJECT* device_obj = &device_ctx->device_obj;
+
+	struct Scsi_Host *host = (struct Scsi_Host *)device->driver_data;
+	struct host_device_context *host_device_ctx=(struct host_device_context*)host->hostdata;
+
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+	if (!storvsc_drv_obj->Base.OnDeviceRemove)
+	{
+		DPRINT_EXIT(STORVSC_DRV);
+		return -1;
+	}
+
+	// Call to the vsc driver to let it know that the device is being removed
+	ret = storvsc_drv_obj->Base.OnDeviceRemove(device_obj);
+	if (ret != 0)
+	{
+		// TODO:
+		DPRINT_ERR(STORVSC, "unable to remove vsc device (ret %d)", ret);
+	}
+
+	if (host_device_ctx->request_pool)
+	{
+		kmem_cache_destroy(host_device_ctx->request_pool);
+		host_device_ctx->request_pool = NULL;
+	}
+
+	DPRINT_INFO(STORVSC, "removing host adapter (%p)...", host);
+	scsi_remove_host(host);
+
+	DPRINT_INFO(STORVSC, "releasing host adapter (%p)...", host);
+	scsi_host_put(host);
+
+	DPRINT_EXIT(STORVSC_DRV);
+
+	return ret;
+}
+
+/*++
+
+Name:	storvsc_commmand_completion()
+
+Desc:	Command completion processing
+
+--*/
+static void storvsc_commmand_completion(STORVSC_REQUEST* request)
+{
+	struct storvsc_cmd_request *cmd_request = (struct storvsc_cmd_request*)request->Context;
+	struct scsi_cmnd *scmnd = cmd_request->cmd;
+	struct host_device_context *host_device_ctx = (struct host_device_context*)scmnd->device->host->hostdata;
+	void (*scsi_done_fn)(struct scsi_cmnd *);
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#else
+	struct scsi_sense_hdr sense_hdr;
+#endif
+
+	ASSERT(request == &cmd_request->request);
+	ASSERT((unsigned long)scmnd->host_scribble == (unsigned long)cmd_request);
+	ASSERT(scmnd);
+	ASSERT(scmnd->scsi_done);
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+	if (cmd_request->bounce_sgl_count)// using bounce buffer
+	{
+		//printk("copy_from_bounce_buffer\n");
+
+		// FIXME: We can optimize on writes by just skipping this
+#ifdef KERNEL_2_6_27
+		copy_from_bounce_buffer(scsi_sglist(scmnd), cmd_request->bounce_sgl, scsi_sg_count(scmnd));
+#else
+		copy_from_bounce_buffer(scmnd->request_buffer, cmd_request->bounce_sgl, scmnd->use_sg);
+#endif
+		destroy_bounce_buffer(cmd_request->bounce_sgl, cmd_request->bounce_sgl_count);
+	}
+
+	scmnd->result = request->Status;
+
+	if (scmnd->result)
+	{
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+		DPRINT_INFO(STORVSC_DRV, "scsi result nonzero - %d", scmnd->result);
+#else
+		if (scsi_normalize_sense(scmnd->sense_buffer, request->SenseBufferSize, &sense_hdr))
+		{
+			scsi_print_sense_hdr("storvsc", &sense_hdr);
+		}
+#endif
+	}
+
+	ASSERT(request->BytesXfer <= request->DataBuffer.Length);
+#ifdef KERNEL_2_6_27
+	scsi_set_resid(scmnd, request->DataBuffer.Length - request->BytesXfer);
+#else
+	scmnd->resid = request->DataBuffer.Length - request->BytesXfer;
+#endif
+
+	scsi_done_fn = scmnd->scsi_done;
+
+	scmnd->host_scribble = NULL;
+	scmnd->scsi_done = NULL;
+
+	// !!DO NOT MODIFY the scmnd after this call
+	scsi_done_fn(scmnd);
+
+	kmem_cache_free(host_device_ctx->request_pool, cmd_request);
+
+	DPRINT_EXIT(STORVSC_DRV);
+}
+
+static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count)
+{
+	int i=0;
+
+	// No need to check
+	if (sg_count < 2)
+		return -1;
+
+	// We have at least 2 sg entries
+	for ( i=0; i<sg_count; i++ )
+	{
+		if (i == 0) // make sure 1st one does not have hole
+		{
+			if (sgl[i].offset + sgl[i].length != PAGE_SIZE)
+				return i;
+		}
+		else if (i == sg_count - 1) // make sure last one does not have hole
+		{
+			if (sgl[i].offset != 0)
+				return i;
+		}
+		else // make sure no hole in the middle
+		{
+			if (sgl[i].length != PAGE_SIZE || sgl[i].offset != 0)
+			{
+				return i;
+			}
+		}
+	}
+	return -1;
+}
+
+static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count, unsigned int len)
+{
+	int i;
+	int num_pages=0;
+	struct scatterlist* bounce_sgl;
+	struct page *page_buf;
+
+	num_pages = ALIGN_UP(len, PAGE_SIZE) >> PAGE_SHIFT;
+
+	bounce_sgl = kzalloc(num_pages * sizeof(struct scatterlist), GFP_ATOMIC);
+	if (!bounce_sgl)
+	{
+		return NULL;
+	}
+
+	for(i=0; i<num_pages; i++)
+	{
+		page_buf = alloc_page(GFP_ATOMIC);
+		if (!page_buf)
+		{
+			goto cleanup;
+		}
+#ifdef KERNEL_2_6_27
+		sg_set_page(&bounce_sgl[i], page_buf, 0, 0);
+#else
+		bounce_sgl[i].page = page_buf;
+		bounce_sgl[i].offset = 0;
+		bounce_sgl[i].length = 0;
+#endif
+	}
+
+	return bounce_sgl;
+
+cleanup:
+	destroy_bounce_buffer(bounce_sgl, num_pages);
+	return NULL;
+}
+
+static void destroy_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count)
+{
+	int i;
+	struct page *page_buf;
+
+	for (i=0; i<sg_count; i++)
+	{
+#ifdef KERNEL_2_6_27
+		if ((page_buf = sg_page((&sgl[i]))) != NULL)
+#else
+		if ((page_buf = sgl[i].page) != NULL)
+#endif
+
+		{
+			__free_page(page_buf);
+		}
+	}
+
+	kfree(sgl);
+}
+
+// Assume the bounce_sgl has enough room ie using the create_bounce_buffer()
+static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, struct scatterlist *bounce_sgl, unsigned int orig_sgl_count)
+{
+	int i=0,j=0;
+	unsigned long src, dest;
+	unsigned int srclen, destlen, copylen;
+	unsigned int total_copied=0;
+	unsigned long bounce_addr=0;
+	unsigned long src_addr=0;
+	unsigned long flags;
+
+	local_irq_save(flags);
+
+	for (i=0; i<orig_sgl_count; i++)
+	{
+#ifdef KERNEL_2_6_27
+		src_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])), KM_IRQ0) + orig_sgl[i].offset;
+#else
+		src_addr = (unsigned long)kmap_atomic(orig_sgl[i].page, KM_IRQ0) + orig_sgl[i].offset;
+#endif
+		src = src_addr;
+		srclen = orig_sgl[i].length;
+
+		//if (PageHighMem(orig_sgl[i].page))
+		//	printk("HighMem page detected - addr %p", (void*)src);
+
+		ASSERT(orig_sgl[i].offset + orig_sgl[i].length <= PAGE_SIZE);
+
+		if (j == 0)
+		{
+#ifdef KERNEL_2_6_27
+			bounce_addr = (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0);
+#else
+			bounce_addr = (unsigned long)kmap_atomic(bounce_sgl[j].page, KM_IRQ0);
+#endif
+		}
+
+		while (srclen)
+		{
+			// assume bounce offset always == 0
+			dest = bounce_addr + bounce_sgl[j].length;
+			destlen = PAGE_SIZE - bounce_sgl[j].length;
+
+			copylen = MIN(srclen, destlen);
+			memcpy((void*)dest, (void*)src, copylen);
+
+			total_copied += copylen;
+			bounce_sgl[j].length += copylen;
+			srclen -= copylen;
+			src += copylen;
+
+			if (bounce_sgl[j].length == PAGE_SIZE) // full..move to next entry
+			{
+				kunmap_atomic((void*)bounce_addr, KM_IRQ0);
+				j++;
+
+				// if we need to use another bounce buffer
+				if (srclen || i != orig_sgl_count -1)
+				{
+#ifdef KERNEL_2_6_27
+					bounce_addr = (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0);
+#else
+					bounce_addr = (unsigned long)kmap_atomic(bounce_sgl[j].page, KM_IRQ0);
+#endif
+				}
+			}
+			else if (srclen == 0 && i == orig_sgl_count -1) // // unmap the last bounce that is < PAGE_SIZE
+			{
+				kunmap_atomic((void*)bounce_addr, KM_IRQ0);
+			}
+		}
+
+		kunmap_atomic((void*)(src_addr - orig_sgl[i].offset), KM_IRQ0);
+	}
+
+	local_irq_restore(flags);
+
+	return total_copied;
+}
+
+// Assume the original sgl has enough room
+static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, struct scatterlist *bounce_sgl, unsigned int orig_sgl_count)
+{
+	int i=0,j=0;
+	unsigned long src, dest;
+	unsigned int srclen, destlen, copylen;
+	unsigned int total_copied=0;
+	unsigned long bounce_addr=0;
+	unsigned long dest_addr=0;
+	unsigned long flags;
+
+	local_irq_save(flags);
+
+	for (i=0; i<orig_sgl_count; i++)
+	{
+#ifdef KERNEL_2_6_27
+		dest_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])), KM_IRQ0) + orig_sgl[i].offset;
+#else
+		dest_addr = (unsigned long)kmap_atomic(orig_sgl[i].page, KM_IRQ0) + orig_sgl[i].offset;
+#endif
+		dest = dest_addr;
+		destlen = orig_sgl[i].length;
+		ASSERT(orig_sgl[i].offset + orig_sgl[i].length <= PAGE_SIZE);
+
+		if (j == 0)
+		{
+#ifdef KERNEL_2_6_27
+			bounce_addr = (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0);
+#else
+			bounce_addr = (unsigned long)kmap_atomic(bounce_sgl[j].page, KM_IRQ0);
+#endif
+		}
+
+		while (destlen)
+		{
+			src = bounce_addr + bounce_sgl[j].offset;
+			srclen = bounce_sgl[j].length - bounce_sgl[j].offset;
+
+			copylen = MIN(srclen, destlen);
+			memcpy((void*)dest, (void*)src, copylen);
+
+			total_copied += copylen;
+			bounce_sgl[j].offset += copylen;
+			destlen -= copylen;
+			dest += copylen;
+
+			if (bounce_sgl[j].offset == bounce_sgl[j].length) // full
+			{
+				kunmap_atomic((void*)bounce_addr, KM_IRQ0);
+				j++;
+
+				// if we need to use another bounce buffer
+				if (destlen || i != orig_sgl_count -1)
+				{
+#ifdef KERNEL_2_6_27
+					bounce_addr = (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0);
+#else
+					bounce_addr = (unsigned long)kmap_atomic(bounce_sgl[j].page, KM_IRQ0);
+#endif
+				}
+			}
+			else if (destlen == 0 && i == orig_sgl_count -1) // unmap the last bounce that is < PAGE_SIZE
+			{
+				kunmap_atomic((void*)bounce_addr, KM_IRQ0);
+			}
+		}
+
+		kunmap_atomic((void*)(dest_addr - orig_sgl[i].offset), KM_IRQ0);
+	}
+
+	local_irq_restore(flags);
+
+	return total_copied;
+}
+
+
+/*++
+
+Name:	storvsc_queuecommand()
+
+Desc:	Initiate command processing
+
+--*/
+static int storvsc_queuecommand(struct scsi_cmnd *scmnd, void (*done)(struct scsi_cmnd *))
+{
+	int ret=0;
+	struct host_device_context *host_device_ctx = (struct host_device_context*)scmnd->device->host->hostdata;
+	struct device_context *device_ctx=host_device_ctx->device_ctx;
+	struct driver_context *driver_ctx = driver_to_driver_context(device_ctx->device.driver);
+	struct storvsc_driver_context *storvsc_drv_ctx = (struct storvsc_driver_context*)driver_ctx;
+	STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &storvsc_drv_ctx->drv_obj;
+
+	STORVSC_REQUEST *request;
+	struct storvsc_cmd_request *cmd_request;
+	unsigned int request_size=0;
+	int i;
+	struct scatterlist *sgl;
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+#ifdef KERNEL_2_6_27
+	DPRINT_DBG(STORVSC_DRV, "scmnd %p dir %d, use_sg %d buf %p len %d queue depth %d tagged %d",
+		scmnd,
+		scmnd->sc_data_direction,
+		scsi_sg_count(scmnd),
+		scsi_sglist(scmnd),
+		scsi_bufflen(scmnd),
+		scmnd->device->queue_depth,
+		scmnd->device->tagged_supported);
+#else
+	DPRINT_DBG(STORVSC_DRV, "scmnd %p dir %d, use_sg %d buf %p len %d queue depth %d tagged %d",
+		scmnd,
+		scmnd->sc_data_direction,
+		scmnd->use_sg,
+		scmnd->request_buffer,
+		scmnd->request_bufflen,
+		scmnd->device->queue_depth,
+		scmnd->device->tagged_supported);
+#endif
+
+	// If retrying, no need to prep the cmd
+	if (scmnd->host_scribble)
+	{
+		ASSERT(scmnd->scsi_done != NULL);
+
+		cmd_request = (struct storvsc_cmd_request* )scmnd->host_scribble;
+		DPRINT_INFO(STORVSC_DRV, "retrying scmnd %p cmd_request %p", scmnd, cmd_request);
+
+		goto retry_request;
+	}
+
+	ASSERT(scmnd->scsi_done == NULL);
+	ASSERT(scmnd->host_scribble == NULL);
+
+	scmnd->scsi_done = done;
+
+	request_size = sizeof(struct storvsc_cmd_request);
+
+	cmd_request = kmem_cache_alloc(host_device_ctx->request_pool, GFP_ATOMIC);
+	if (!cmd_request)
+	{
+		DPRINT_ERR(STORVSC_DRV, "scmnd (%p) - unable to allocate storvsc_cmd_request...marking queue busy", scmnd);
+
+		scmnd->scsi_done = NULL;
+		return SCSI_MLQUEUE_DEVICE_BUSY;
+	}
+
+	// Setup the cmd request
+	cmd_request->bounce_sgl_count = 0;
+	cmd_request->bounce_sgl = NULL;
+	cmd_request->cmd = scmnd;
+
+	scmnd->host_scribble = (unsigned char*)cmd_request;
+
+	request = &cmd_request->request;
+
+	request->Extension = (void*)((unsigned long)cmd_request + request_size);
+	DPRINT_DBG(STORVSC_DRV, "req %p size %d ext %d", request, request_size, storvsc_drv_obj->RequestExtSize);
+
+	// Build the SRB
+	switch(scmnd->sc_data_direction)
+	{
+	case DMA_TO_DEVICE:
+		request->Type = WRITE_TYPE;
+		break;
+	case DMA_FROM_DEVICE:
+		request->Type = READ_TYPE;
+		break;
+	default:
+		request->Type = UNKNOWN_TYPE;
+		break;
+	}
+
+	request->OnIOCompletion = storvsc_commmand_completion;
+	request->Context = cmd_request;//scmnd;
+
+	//request->PortId = scmnd->device->channel;
+	request->Host = host_device_ctx->port;
+	request->Bus = scmnd->device->channel;
+	request->TargetId = scmnd->device->id;
+	request->LunId = scmnd->device->lun;
+
+	ASSERT(scmnd->cmd_len <= 16);
+	request->CdbLen = scmnd->cmd_len;
+	request->Cdb = scmnd->cmnd;
+
+	request->SenseBuffer = scmnd->sense_buffer;
+	request->SenseBufferSize = SCSI_SENSE_BUFFERSIZE;
+
+
+#ifdef KERNEL_2_6_27
+	request->DataBuffer.Length = scsi_bufflen(scmnd);
+	if (scsi_sg_count(scmnd))
+#else
+	request->DataBuffer.Length = scmnd->request_bufflen;
+	if (scmnd->use_sg)
+#endif
+	{
+#ifdef KERNEL_2_6_27
+		sgl = (struct scatterlist*)scsi_sglist(scmnd);
+#else
+		sgl = (struct scatterlist*)(scmnd->request_buffer);
+#endif
+
+		// check if we need to bounce the sgl
+#ifdef KERNEL_2_6_27
+		if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1)
+#else
+		if (do_bounce_buffer(sgl, scmnd->use_sg) != -1)
+#endif
+		{
+			DPRINT_INFO(STORVSC_DRV, "need to bounce buffer for this scmnd %p", scmnd);
+#ifdef KERNEL_2_6_27
+			cmd_request->bounce_sgl = create_bounce_buffer(sgl, scsi_sg_count(scmnd), scsi_bufflen(scmnd));
+#else
+			cmd_request->bounce_sgl = create_bounce_buffer(
+			    sgl,
+			    scmnd->use_sg, scmnd->request_bufflen);
+#endif
+			if (!cmd_request->bounce_sgl)
+			{
+				DPRINT_ERR(STORVSC_DRV, "unable to create bounce buffer for this scmnd %p", scmnd);
+
+				scmnd->scsi_done = NULL;
+				scmnd->host_scribble = NULL;
+				kmem_cache_free(host_device_ctx->request_pool, cmd_request);
+
+				return SCSI_MLQUEUE_HOST_BUSY;
+			}
+
+#ifdef KERNEL_2_6_27
+			cmd_request->bounce_sgl_count = ALIGN_UP(scsi_bufflen(scmnd), PAGE_SIZE) >> PAGE_SHIFT;
+#else
+			cmd_request->bounce_sgl_count = ALIGN_UP(scmnd->request_bufflen, PAGE_SIZE) >> PAGE_SHIFT;
+#endif
+
+			//printk("bouncing buffer allocated %p original buffer %p\n", bounce_sgl, sgl);
+			//printk("copy_to_bounce_buffer\n");
+			// FIXME: We can optimize on reads by just skipping this
+#ifdef KERNEL_2_6_27
+			copy_to_bounce_buffer(sgl, cmd_request->bounce_sgl, scsi_sg_count(scmnd));
+#else
+			copy_to_bounce_buffer(sgl, cmd_request->bounce_sgl, scmnd->use_sg);
+#endif
+
+			sgl = cmd_request->bounce_sgl;
+		}
+
+		request->DataBuffer.Offset = sgl[0].offset;
+
+#ifdef KERNEL_2_6_27
+		for (i = 0; i < scsi_sg_count(scmnd); i++ )
+#else
+		for (i = 0; i < scmnd->use_sg; i++ )
+#endif
+		{
+			DPRINT_DBG(STORVSC_DRV, "sgl[%d] len %d offset %d \n", i, sgl[i].length, sgl[i].offset);
+#ifdef KERNEL_2_6_27
+			request->DataBuffer.PfnArray[i] = page_to_pfn(sg_page((&sgl[i])));
+#else
+			request->DataBuffer.PfnArray[i] = page_to_pfn(sgl[i].page);
+#endif
+		}
+	}
+
+#ifdef KERNEL_2_6_27
+	else if (scsi_sglist(scmnd))
+	{
+		ASSERT(scsi_bufflen(scmnd) <= PAGE_SIZE);
+		request->DataBuffer.Offset = virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1);
+		request->DataBuffer.PfnArray[0] = virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT;
+	}
+	else
+	{
+		ASSERT(scsi_bufflen(scmnd) == 0);
+	}
+#else
+	else if (scmnd->request_buffer)
+	{
+		ASSERT(scmnd->request_bufflen <= PAGE_SIZE);
+		request->DataBuffer.Offset = virt_to_phys(scmnd->request_buffer) & (PAGE_SIZE-1);
+		request->DataBuffer.PfnArray[0] = virt_to_phys(scmnd->request_buffer) >> PAGE_SHIFT;
+	}
+	else
+	{
+		ASSERT(scmnd->request_bufflen == 0);
+	}
+#endif
+
+retry_request:
+
+	// Invokes the vsc to start an IO
+	ret = storvsc_drv_obj->OnIORequest(&device_ctx->device_obj, &cmd_request->request);
+	if (ret == -1) // no more space
+	{
+		DPRINT_ERR(STORVSC_DRV, "scmnd (%p) - queue FULL...marking queue busy", scmnd);
+
+		if (cmd_request->bounce_sgl_count)
+		{
+			// FIXME: We can optimize on writes by just skipping this
+#ifdef KERNEL_2_6_27
+			copy_from_bounce_buffer(scsi_sglist(scmnd), cmd_request->bounce_sgl, scsi_sg_count(scmnd));
+#else
+			copy_from_bounce_buffer(
+			    scmnd->request_buffer,
+			    cmd_request->bounce_sgl,
+			    scmnd->use_sg);
+#endif
+			destroy_bounce_buffer(cmd_request->bounce_sgl, cmd_request->bounce_sgl_count);
+		}
+
+		kmem_cache_free(host_device_ctx->request_pool, cmd_request);
+
+		scmnd->scsi_done = NULL;
+		scmnd->host_scribble = NULL;
+
+		ret = SCSI_MLQUEUE_DEVICE_BUSY;
+	}
+
+	DPRINT_EXIT(STORVSC_DRV);
+
+	return ret;
+}
+
+#ifdef KERNEL_2_6_27
+static int storvsc_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd, struct bio_vec *bvec)
+{
+	return bvec->bv_len; //checking done by caller.
+}
+#else
+static int storvsc_merge_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *bvec)
+{
+	// Check if we are adding a new bvec
+	if (bio->bi_vcnt > 0)
+	{
+		//printk("storvsc_merge_bvec() - cnt %u offset %u len %u\n", bio->bi_vcnt, bvec->bv_offset, bvec->bv_len);
+
+		struct bio_vec *prev = &bio->bi_io_vec[bio->bi_vcnt - 1];
+		if (bvec == prev)
+			return bvec->bv_len; // success
+
+		// Adding new bvec. Make sure the prev one is a complete page
+		if (prev->bv_len == PAGE_SIZE && prev->bv_offset == 0)
+		{
+			return bvec->bv_len; // success
+		}
+		else
+		{
+			// Dont reject if the new bvec starts off from the prev one since
+			// they will be merge into 1 bvec or blk_rq_map_sg() will merge them into 1 sg element
+			if ((bvec->bv_page == prev->bv_page) &&
+				(bvec->bv_offset == prev->bv_offset + prev->bv_len))
+			{
+				return bvec->bv_len; // success
+			}
+			else
+			{
+				DPRINT_INFO(STORVSC_DRV, "detected holes in bio request (%p) - cnt %u offset %u len %u", bio, bio->bi_vcnt, bvec->bv_offset, bvec->bv_len);
+				return 0; // dont add the bvec to this bio since we dont allow holes in the middle of a multi-pages bio
+			}
+		}
+	}
+
+	return bvec->bv_len; // success
+
+}
+
+#endif
+
+/*++
+
+Name:	storvsc_device_configure()
+
+Desc:	Configure the specified scsi device
+
+--*/
+static int storvsc_device_alloc(struct scsi_device *sdevice)
+{
+#ifdef KERNEL_2_6_5
+#else
+	DPRINT_DBG(STORVSC_DRV, "sdev (%p) - setting device flag to %d", sdevice, BLIST_SPARSELUN);
+	// This enables luns to be located sparsely. Otherwise, we may not discovered them.
+	sdevice->sdev_bflags |= BLIST_SPARSELUN | BLIST_LARGELUN;
+#endif
+	return 0;
+}
+
+static int storvsc_device_configure(struct scsi_device *sdevice)
+{
+	DPRINT_INFO(STORVSC_DRV, "sdev (%p) - curr queue depth %d", sdevice, sdevice->queue_depth);
+
+	DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting queue depth to %d", sdevice, STORVSC_MAX_IO_REQUESTS);
+	scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG, STORVSC_MAX_IO_REQUESTS);
+
+	DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting max segment size to %d", sdevice, PAGE_SIZE);
+	blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
+
+	DPRINT_INFO(STORVSC_DRV, "sdev (%p) - adding merge bio vec routine", sdevice);
+	blk_queue_merge_bvec(sdevice->request_queue, storvsc_merge_bvec);
+
+	blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY);
+	//sdevice->timeout = (2000 * HZ);//(75 * HZ);
+
+	return 0;
+}
+
+/*++
+
+Name:	storvsc_host_reset_handler()
+
+Desc:	Reset the scsi HBA
+
+--*/
+static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
+{
+	int ret=SUCCESS;
+	struct host_device_context *host_device_ctx = (struct host_device_context*)scmnd->device->host->hostdata;
+	struct device_context *device_ctx = host_device_ctx->device_ctx;
+	struct driver_context *driver_ctx = driver_to_driver_context(device_ctx->device.driver);
+	struct storvsc_driver_context *storvsc_drv_ctx = (struct storvsc_driver_context*)driver_ctx;
+
+	STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &storvsc_drv_ctx->drv_obj;
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+	DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host resetting...", scmnd->device, &device_ctx->device_obj);
+
+	// Invokes the vsc to reset the host/bus
+	ASSERT(storvsc_drv_obj->OnHostReset);
+	ret = storvsc_drv_obj->OnHostReset(&device_ctx->device_obj);
+	if (ret != 0)
+	{
+		DPRINT_EXIT(STORVSC_DRV);
+		return ret;
+	}
+
+	DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host reseted", scmnd->device, &device_ctx->device_obj);
+
+	DPRINT_EXIT(STORVSC_DRV);
+
+	return ret;
+}
+
+/*++
+
+Name:	storvsc_host_rescan
+
+Desc:	Rescan the scsi HBA
+
+--*/
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#else
+
+#ifdef KERNEL_2_6_27
+static void storvsc_host_rescan_callback(struct work_struct *work)
+{
+	DEVICE_OBJECT* device_obj =
+	    &((struct host_device_context*)work)->device_ctx->device_obj;
+#else
+static void storvsc_host_rescan_callback(void* context)
+{
+
+	DEVICE_OBJECT* device_obj = (DEVICE_OBJECT*)context;
+#endif
+	struct device_context* device_ctx = to_device_context(device_obj);
+	struct Scsi_Host *host = (struct Scsi_Host *)device_ctx->device.driver_data;
+	struct scsi_device *sdev;
+	struct host_device_context *host_device_ctx;
+	struct scsi_device **sdevs_remove_list;
+	unsigned int sdevs_count=0;
+	unsigned int found;
+	unsigned int i;
+	unsigned int lun_count=0;
+	unsigned int *lun_list;
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+	host_device_ctx = (struct host_device_context*)host->hostdata;
+	lun_list = kzalloc(sizeof(unsigned int)*STORVSC_MAX_LUNS_PER_TARGET, GFP_ATOMIC);
+	if (!lun_list)
+	{
+		DPRINT_ERR(STORVSC_DRV, "unable to allocate lun list");
+		return;
+	}
+
+	sdevs_remove_list = kzalloc(sizeof(void*)*STORVSC_MAX_LUNS_PER_TARGET, GFP_ATOMIC);
+	if (!sdevs_remove_list)
+	{
+		kfree(lun_list);
+		DPRINT_ERR(STORVSC_DRV, "unable to allocate lun remove list");
+		return;
+	}
+
+	DPRINT_INFO(STORVSC_DRV, "rescanning host for new scsi devices...", device_obj, host_device_ctx->target, host_device_ctx->path);
+
+	// Rescan for new device
+	scsi_scan_target(&host->shost_gendev, host_device_ctx->path, host_device_ctx->target, SCAN_WILD_CARD, 1);
+
+	DPRINT_INFO(STORVSC_DRV, "rescanning host for removed scsi device...");
+
+	// Use the 1st device to send the report luns cmd
+	shost_for_each_device(sdev, host)
+	{
+		lun_count=STORVSC_MAX_LUNS_PER_TARGET;
+		storvsc_report_luns(sdev, lun_list, &lun_count);
+
+		DPRINT_INFO(STORVSC_DRV, "report luns on scsi device (%p) found %u luns ", sdev, lun_count);
+		DPRINT_INFO(STORVSC_DRV, "existing luns on scsi device (%p) host (%d)", sdev, host->host_no);
+
+		scsi_device_put(sdev);
+		break;
+	}
+
+	for (i=0; i<lun_count; i++)
+	{
+		DPRINT_INFO(STORVSC_DRV, "%d) lun %u", i, lun_list[i]);
+	}
+
+	// Rescan for devices that may have been removed.
+	// We do not have to worry that new devices may have been added since
+	// this callback is serialized by the workqueue ie add/remove are done here.
+	shost_for_each_device(sdev, host)
+	{
+		// See if this device is still here
+		found = 0;
+		for (i=0; i<lun_count; i++)
+		{
+			if (sdev->lun == lun_list[i])
+			{
+				found = 1;
+				break;
+			}
+		}
+		if (!found)
+		{
+			DPRINT_INFO(STORVSC_DRV, "lun (%u) does not exists", sdev->lun);
+			sdevs_remove_list[sdevs_count++] = sdev;
+		}
+	}
+
+	// Now remove the devices
+	for (i=0; i< sdevs_count; i++)
+	{
+		DPRINT_INFO(STORVSC_DRV, "removing scsi device (%p) lun (%u)...",
+					sdevs_remove_list[i], sdevs_remove_list[i]->lun);
+
+		// make sure it is not removed from underneath us
+		if (!scsi_device_get(sdevs_remove_list[i]))
+		{
+			scsi_remove_device(sdevs_remove_list[i]);
+			scsi_device_put(sdevs_remove_list[i]);
+		}
+	}
+
+	DPRINT_INFO(STORVSC_DRV, "rescan completed on dev obj (%p) target (%u) bus (%u)", device_obj, host_device_ctx->target, host_device_ctx->path);
+
+	kfree(lun_list);
+	kfree(sdevs_remove_list);
+
+	DPRINT_EXIT(STORVSC_DRV);
+}
+
+static int storvsc_report_luns(struct scsi_device *sdev, unsigned int luns[], unsigned int *lun_count)
+{
+	int i,j;
+	unsigned int lun=0;
+	unsigned int num_luns;
+	int result;
+	unsigned char *data;
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+#else
+	struct scsi_sense_hdr sshdr;
+#endif
+	unsigned char cmd[16]={0};
+	unsigned int report_len = 8*(STORVSC_MAX_LUNS_PER_TARGET+1); // Add 1 to cover the report_lun header
+	unsigned long long *report_luns;
+	const unsigned int in_lun_count = *lun_count;
+
+	*lun_count = 0;
+
+	report_luns = kzalloc(report_len, GFP_ATOMIC);
+	if (!report_luns)
+	{
+		return -ENOMEM;
+	}
+
+	cmd[0] = REPORT_LUNS;
+
+	// cmd length
+	*(unsigned int*)&cmd[6] = cpu_to_be32(report_len);
+
+	result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, (unsigned char*)report_luns, report_len, &sshdr, 30*HZ, 3);
+	if (result != 0)
+	{
+		kfree(report_luns);
+		return -EBUSY;
+	}
+
+	// get the length from the first four bytes
+	report_len = be32_to_cpu(*(unsigned int*)&report_luns[0]);
+
+	num_luns = (report_len / sizeof(unsigned long long));
+	if (num_luns > in_lun_count)
+	{
+		kfree(report_luns);
+		return -EINVAL;
+	}
+
+	*lun_count = num_luns;
+
+	DPRINT_DBG(STORVSC_DRV, "report luns on scsi device (%p) found %u luns ", sdev, num_luns);
+
+	// lun id starts at 1
+	for (i=1; i< num_luns+1; i++)
+	{
+		lun = 0;
+		data = (unsigned char*)&report_luns[i];
+		for (j = 0; j < sizeof(lun); j += 2)
+		 {
+			 lun = lun | (((data[j] << 8) | data[j + 1]) << (j * 8));
+		 }
+
+		luns[i-1] = lun;
+	}
+
+	kfree(report_luns);
+	return 0;
+}
+#endif // KERNEL_2_6_9
+
+static void storvsc_host_rescan(DEVICE_OBJECT* device_obj)
+{
+	struct device_context* device_ctx = to_device_context(device_obj);
+	struct Scsi_Host *host = (struct Scsi_Host *)device_ctx->device.driver_data;
+	struct host_device_context *host_device_ctx;
+
+	DPRINT_ENTER(STORVSC_DRV);
+#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
+	DPRINT_ERR(STORVSC_DRV, "rescan not supported on 2.6.9 kernels!! You will need to reboot if you have added or removed the scsi lun device");
+#else
+
+	host_device_ctx = (struct host_device_context*)host->hostdata;
+
+	DPRINT_INFO(STORVSC_DRV, "initiating rescan on dev obj (%p) target (%u) bus (%u)...", device_obj, host_device_ctx->target, host_device_ctx->path);
+
+	// We need to queue this since the scanning may block and the caller may be in an intr context
+	//scsi_queue_work(host, &host_device_ctx->host_rescan_work);
+	schedule_work(&host_device_ctx->host_rescan_work);
+#endif // KERNEL_2_6_9
+	DPRINT_EXIT(STORVSC_DRV);
+}
+
+static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev, sector_t capacity, int *info)
+{
+	sector_t total_sectors = capacity;
+	sector_t cylinder_times_heads=0;
+	sector_t temp=0;
+
+	int sectors_per_track=0;
+	int heads=0;
+	int cylinders=0;
+	int rem=0;
+
+    if (total_sectors > (65535 * 16 * 255)) {
+        total_sectors = (65535 * 16 * 255);
+    }
+
+    if (total_sectors >= (65535 * 16 * 63)) {
+        sectors_per_track = 255;
+        heads = 16;
+
+		cylinder_times_heads = total_sectors;
+		rem = sector_div(cylinder_times_heads, sectors_per_track); // sector_div stores the quotient in cylinder_times_heads
+    }
+	else
+	{
+        sectors_per_track = 17;
+
+		cylinder_times_heads = total_sectors;
+        rem = sector_div(cylinder_times_heads, sectors_per_track); 	// sector_div stores the quotient in cylinder_times_heads
+
+		temp = cylinder_times_heads + 1023;
+		rem = sector_div(temp, 1024); 	// sector_div stores the quotient in temp
+
+		heads = temp;
+
+        if (heads < 4) {
+            heads = 4;
+        }
+
+        if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) {
+            sectors_per_track = 31;
+            heads = 16;
+
+			cylinder_times_heads = total_sectors;
+            rem = sector_div(cylinder_times_heads, sectors_per_track); // sector_div stores the quotient in cylinder_times_heads
+        }
+
+        if (cylinder_times_heads >= (heads * 1024)) {
+            sectors_per_track = 63;
+            heads = 16;
+
+			cylinder_times_heads = total_sectors;
+            rem = sector_div(cylinder_times_heads, sectors_per_track); // sector_div stores the quotient in cylinder_times_heads
+        }
+    }
+
+	temp = cylinder_times_heads;
+    rem = sector_div(temp, heads); // sector_div stores the quotient in temp
+	cylinders = temp;
+
+	info[0] = heads;
+    info[1] = sectors_per_track;
+    info[2] = cylinders;
+
+	DPRINT_INFO(STORVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads, sectors_per_track);
+
+    return 0;
+}
+
+MODULE_LICENSE("GPL");
+
+static int __init storvsc_init(void)
+{
+	int ret;
+
+	DPRINT_ENTER(STORVSC_DRV);
+
+	DPRINT_INFO(STORVSC_DRV, "Storvsc initializing....");
+
+	ret = storvsc_drv_init(StorVscInitialize);
+
+	DPRINT_EXIT(STORVSC_DRV);
+
+	return ret;
+}
+
+static void __exit storvsc_exit(void)
+{
+	DPRINT_ENTER(STORVSC_DRV);
+
+	storvsc_drv_exit();
+
+	DPRINT_ENTER(STORVSC_DRV);
+}
+
+module_param(storvsc_ringbuffer_size, int, S_IRUGO);
+
+module_init(storvsc_init);
+module_exit(storvsc_exit);
+
+// eof

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 07/54] Staging: hv: add a TODO file
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (6 preceding siblings ...)
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-a-todo-file.patch --]
[-- Type: text/plain, Size: 883 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

First cut at what needs to be done to this codebase.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/TODO |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

--- /dev/null
+++ b/drivers/staging/hv/TODO
@@ -0,0 +1,15 @@
+TODO:
+	- fix checkpatch warnings/errors
+	- fix sparse issues
+	- remove compatibility layer
+	- fix HANDLE usage to be "real" pointers
+	- audit the vmbus to verify it is working properly with the
+	  driver model
+	- see if the vmbus can be merged with the other virtual busses
+	  in the kernel
+	- audit the network driver
+	- audit the block driver
+	- audit the scsi driver
+
+Please send patches for this code to Greg Kroah-Hartman <gregkh@suse.de>
+and Hank Janssen <hjanssen@microsoft.com>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 08/54] Staging: hv: make the Hyper-V virtual bus code build
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (7 preceding siblings ...)
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-the-hyper-v-virtual-bus-code-build.patch --]
[-- Type: text/plain, Size: 7873 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The #define KERNEL_2_6_27 needs to be set, and I adjusted the include
directories a bit to get things to build properly.

I also fixed up the direct access of bus_id, as that field is now gone.

The hv_vmbus code should now build properly, with no errors.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Channel.c                 |    4 ++--
 drivers/staging/hv/Channel.h                 |    2 +-
 drivers/staging/hv/ChannelInterface.h        |    2 +-
 drivers/staging/hv/ChannelMgmt.c             |    4 ++--
 drivers/staging/hv/ChannelMgmt.h             |    8 ++++----
 drivers/staging/hv/Connection.c              |    2 +-
 drivers/staging/hv/Hv.c                      |    2 +-
 drivers/staging/hv/Hv.h                      |   16 ++++++++--------
 drivers/staging/hv/RingBuffer.c              |    2 +-
 drivers/staging/hv/RingBuffer.h              |    2 +-
 drivers/staging/hv/Sources.c                 |    1 +
 drivers/staging/hv/Vmbus.c                   |    2 +-
 drivers/staging/hv/VmbusPrivate.h            |    4 ++--
 drivers/staging/hv/include/ChannelMessages.h |    2 +-
 drivers/staging/hv/osd.c                     |    3 ++-
 drivers/staging/hv/vmbus_drv.c               |   15 ++++++++-------
 16 files changed, 37 insertions(+), 34 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -22,8 +22,8 @@
  */
 
 
-#include "osd.h"
-#include "logging.h"
+#include "include/osd.h"
+#include "include/logging.h"
 
 #include "VmbusPrivate.h"
 
--- a/drivers/staging/hv/Channel.h
+++ b/drivers/staging/hv/Channel.h
@@ -25,7 +25,7 @@
 #ifndef _CHANNEL_H_
 #define _CHANNEL_H_
 
-#include "osd.h"
+#include "include/osd.h"
 #include "ChannelMgmt.h"
 
 #pragma pack(push,1)
--- a/drivers/staging/hv/ChannelInterface.h
+++ b/drivers/staging/hv/ChannelInterface.h
@@ -25,7 +25,7 @@
 #ifndef _CHANNEL_INTERFACE_H_
 #define _CHANNEL_INTERFACE_H_
 
-#include "VmbusApi.h"
+#include "include/VmbusApi.h"
 
 INTERNAL void
 GetChannelInterface(
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -22,8 +22,8 @@
  */
 
 
-#include "osd.h"
-#include "logging.h"
+#include "include/osd.h"
+#include "include/logging.h"
 
 #include "VmbusPrivate.h"
 
--- a/drivers/staging/hv/ChannelMgmt.h
+++ b/drivers/staging/hv/ChannelMgmt.h
@@ -25,12 +25,12 @@
 #ifndef _CHANNEL_MGMT_H_
 #define _CHANNEL_MGMT_H_
 
-#include "osd.h"
-#include "List.h"
+#include "include/osd.h"
+#include "include/List.h"
 #include "RingBuffer.h"
 
-#include "VmbusChannelInterface.h"
-#include "ChannelMessages.h"
+#include "include/VmbusChannelInterface.h"
+#include "include/ChannelMessages.h"
 
 
 
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -22,7 +22,7 @@
  */
 
 
-#include "logging.h"
+#include "include/logging.h"
 
 #include "VmbusPrivate.h"
 
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -22,7 +22,7 @@
  */
 
 
-#include "logging.h"
+#include "include/logging.h"
 #include "VmbusPrivate.h"
 
 //
--- a/drivers/staging/hv/Hv.h
+++ b/drivers/staging/hv/Hv.h
@@ -25,23 +25,23 @@
 #ifndef __HV_H__
 #define __HV_H__
 
-#include "osd.h"
+#include "include/osd.h"
 
-#include "HvTypes.h"
-#include "HvStatus.h"
+#include "include/HvTypes.h"
+#include "include/HvStatus.h"
 //#include "HvVmApi.h"
 //#include "HvKeApi.h"
 //#include "HvMmApi.h"
 //#include "HvCpuApi.h"
-#include "HvHalApi.h"
-#include "HvVpApi.h"
+#include "include/HvHalApi.h"
+#include "include/HvVpApi.h"
 //#include "HvTrApi.h"
-#include "HvSynicApi.h"
+#include "include/HvSynicApi.h"
 //#include "HvAmApi.h"
 //#include "HvHkApi.h"
 //#include "HvValApi.h"
-#include "HvHcApi.h"
-#include "HvPtApi.h"
+#include "include/HvHcApi.h"
+#include "include/HvPtApi.h"
 
 enum
 {
--- a/drivers/staging/hv/include/ChannelMessages.h
+++ b/drivers/staging/hv/include/ChannelMessages.h
@@ -24,7 +24,7 @@
 
 #pragma once
 
-#include <VmbusPacketFormat.h>
+#include "VmbusPacketFormat.h"
 
 #define C_ASSERT(x)
 typedef UINT32 NTSTATUS;
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -21,6 +21,7 @@
  *
  */
 
+#define KERNEL_2_6_27
 
 #include <linux/module.h>
 #include <linux/init.h>
@@ -46,7 +47,7 @@
 #include <asm/kmap_types.h>
 #include <asm/atomic.h>
 
-#include "osd.h"
+#include "include/osd.h"
 
 //
 // Data types
--- a/drivers/staging/hv/RingBuffer.c
+++ b/drivers/staging/hv/RingBuffer.c
@@ -22,7 +22,7 @@
  */
 
 
-#include "logging.h"
+#include "include/logging.h"
 #include "RingBuffer.h"
 
 //
--- a/drivers/staging/hv/RingBuffer.h
+++ b/drivers/staging/hv/RingBuffer.h
@@ -25,7 +25,7 @@
 #ifndef _RING_BUFFER_H_
 #define _RING_BUFFER_H_
 
-#include "osd.h"
+#include "include/osd.h"
 
 typedef struct _SG_BUFFER_LIST {
 	PVOID	Data;
--- a/drivers/staging/hv/Sources.c
+++ b/drivers/staging/hv/Sources.c
@@ -21,6 +21,7 @@
  *
  */
 
+#define KERNEL_2_6_27
 
 #include "Vmbus.c"
 #include "Hv.c"
--- a/drivers/staging/hv/Vmbus.c
+++ b/drivers/staging/hv/Vmbus.c
@@ -22,7 +22,7 @@
  */
 
 
-#include "logging.h"
+#include "include/logging.h"
 #include "VersionInfo.h"
 #include "VmbusPrivate.h"
 
--- a/drivers/staging/hv/vmbus_drv.c
+++ b/drivers/staging/hv/vmbus_drv.c
@@ -21,6 +21,7 @@
  *
  */
 
+#define KERNEL_2_6_27
 
 #include <linux/init.h>
 #include <linux/module.h>
@@ -29,8 +30,8 @@
 #include <linux/interrupt.h>
 #include <linux/sysctl.h>
 
-#include "logging.h"
-#include "vmbus.h"
+#include "include/logging.h"
+#include "include/vmbus.h"
 
 //
 // Defines
@@ -451,7 +452,7 @@ int vmbus_bus_init(PFN_DRIVERINITIALIZE 
 		goto cleanup;
 	}
 	//strcpy(dev_ctx->device.bus_id, dev_ctx->device_obj.name);
-	sprintf(dev_ctx->device.bus_id, "vmbus_0_0");
+	dev_set_name(&dev_ctx->device, "vmbus_0_0");
 	memcpy(&dev_ctx->class_id, &dev_ctx->device_obj.deviceType, sizeof(GUID));
 	memcpy(&dev_ctx->device_id, &dev_ctx->device_obj.deviceInstance, sizeof(GUID));
 
@@ -656,16 +657,16 @@ static int vmbus_child_device_register(D
 	//
 	// Make sure we are not registered already
 	//
-	if (child_device_ctx->device.bus_id[0] != '\0')
+	if (strlen(dev_name(&child_device_ctx->device)) != 0)
 	{
-		DPRINT_ERR(VMBUS_DRV, "child device (%p) already registered - busid %s", child_device_ctx, child_device_ctx->device.bus_id);
+		DPRINT_ERR(VMBUS_DRV, "child device (%p) already registered - busid %s", child_device_ctx, dev_name(&child_device_ctx->device));
 
 		ret = -1;
 		goto Cleanup;
 	}
 
 	// Set the device bus id. Otherwise, device_register()will fail.
-	sprintf(child_device_ctx->device.bus_id, "vmbus_0_%d", InterlockedIncrement(&device_num));
+	dev_set_name(&child_device_ctx->device, "vmbus_0_%d", InterlockedIncrement(&device_num));
 
 	// The new device belongs to this bus
 	child_device_ctx->device.bus = &g_vmbus_drv.bus; //device->dev.bus;
@@ -924,7 +925,7 @@ static int vmbus_probe(struct device *ch
 		ret = device_ctx->probe_error = driver_ctx->probe(child_device);
 		if (ret != 0)
 		{
-			DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s (%p) on driver %s (%d)...", child_device->bus_id, child_device, child_device->driver->name, ret);
+			DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s (%p) on driver %s (%d)...", dev_name(child_device), child_device, child_device->driver->name, ret);
 
 #ifdef KERNEL_2_6_27
 			INIT_WORK(&device_ctx->probe_failed_work_item, vmbus_probe_failed_cb);
--- a/drivers/staging/hv/VmbusPrivate.h
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -30,14 +30,14 @@
 #endif
 
 #include "Hv.h"
-#include "VmbusApi.h"
+#include "include/VmbusApi.h"
 #include "Channel.h"
 #include "ChannelMgmt.h"
 #include "ChannelInterface.h"
 //#include "ChannelMessages.h"
 #include "RingBuffer.h"
 //#include "Packet.h"
-#include "List.h"
+#include "include/List.h"
 
 //
 // Defines

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 09/54] Staging: hv: use the correct #ifdef for x86-64
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (8 preceding siblings ...)
  (?)
@ 2009-07-17 18:08   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:08 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-use-the-correct-ifdef-for-x86-64.patch --]
[-- Type: text/plain, Size: 693 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

x86-64 needs a different config check.  Thanks to Hank for the debugging
to determine the fix for this.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Hv.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -165,7 +165,7 @@ HvDoHypercall (
     void*   Output
     )
 {
-#ifdef x86_64
+#ifdef CONFIG_X86_64
     UINT64 hvStatus=0;
     UINT64 inputAddress = (Input)? GetPhysicalAddress(Input) : 0;
 	UINT64 outputAddress = (Output)? GetPhysicalAddress(Output) : 0;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 10/54] Staging: hv: add the Hyper-V virtual bus to the build
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (9 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-virtual-bus-to-the-build.patch --]
[-- Type: text/plain, Size: 1334 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Add the Hyper-V virtual bus to the kernel build system.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/Kconfig     |    2 ++
 drivers/staging/Makefile    |    1 +
 drivers/staging/hv/Kconfig  |    8 ++++++++
 drivers/staging/hv/Makefile |    3 +++
 4 files changed, 14 insertions(+)

--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -129,5 +129,7 @@ source "drivers/staging/pata_rdc/Kconfig
 
 source "drivers/staging/udlfb/Kconfig"
 
+source "drivers/staging/hv/Kconfig"
+
 endif # !STAGING_EXCLUDE_BUILD
 endif # STAGING
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -46,3 +46,4 @@ obj-$(CONFIG_VT6655)		+= vt6655/
 obj-$(CONFIG_USB_CPC)		+= cpc-usb/
 obj-$(CONFIG_RDC_17F3101X)	+= pata_rdc/
 obj-$(CONFIG_FB_UDL)		+= udlfb/
+obj-$(CONFIG_HYPERV)		+= hv/
--- /dev/null
+++ b/drivers/staging/hv/Kconfig
@@ -0,0 +1,8 @@
+config HYPERV
+	tristate "Microsoft Hyper-V client drivers"
+	depends on X86
+	default n
+	help
+	  Select this option to run Linux as a Hyper-V client operating
+	  system.
+
--- /dev/null
+++ b/drivers/staging/hv/Makefile
@@ -0,0 +1,3 @@
+obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
+
+hv_vmbus-objs := vmbus_drv.o osd.o Sources.o

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 11/54] Staging: hv: make the Hyper-V virtual storage driver build
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (10 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-the-hyper-v-virtual-storage-driver-build.patch --]
[-- Type: text/plain, Size: 2199 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The #define KERNEL_2_6_27 needs to be set, and I adjusted the include
directories a bit to get things to build properly.

I also fixed up the direct access of bus_id, as that field is now gone.
Some minor scsi api changes were needed as well.

The hv_storvsc code should now build properly, with no errors.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/StorVsc.c     |    9 +++++----
 drivers/staging/hv/storvsc_drv.c |   11 ++++++-----
 2 files changed, 11 insertions(+), 9 deletions(-)

--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -21,12 +21,13 @@
  *
  */
 
+#define KERNEL_2_6_27
 
-#include "logging.h"
+#include "include/logging.h"
 
-#include "StorVscApi.h"
-#include "VmbusPacketFormat.h"
-#include "vstorage.h"
+#include "include/StorVscApi.h"
+#include "include/VmbusPacketFormat.h"
+#include "include/vstorage.h"
 
 
 //
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -21,6 +21,7 @@
  *
  */
 
+#define KERNEL_2_6_27
 
 #include <linux/init.h>
 #include <linux/module.h>
@@ -40,10 +41,10 @@
 #include <scsi/scsi_dbg.h>
 #endif
 
-#include "logging.h"
-#include "vmbus.h"
+#include "include/logging.h"
+#include "include/vmbus.h"
 
-#include "StorVscApi.h"
+#include "include/StorVscApi.h"
 
 //
 // #defines
@@ -296,7 +297,7 @@ static int storvsc_probe(struct device *
 #if defined(KERNEL_2_6_27)
 	host_device_ctx->request_pool =
 	    kmem_cache_create
-	    (device_ctx->device.bus_id,
+	    (dev_name(&device_ctx->device),
 	     sizeof(struct storvsc_cmd_request) + storvsc_drv_obj->RequestExtSize,
 	     0,
 	     SLAB_HWCACHE_ALIGN, NULL);
@@ -1250,7 +1251,7 @@ static int storvsc_report_luns(struct sc
 	// cmd length
 	*(unsigned int*)&cmd[6] = cpu_to_be32(report_len);
 
-	result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, (unsigned char*)report_luns, report_len, &sshdr, 30*HZ, 3);
+	result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, (unsigned char*)report_luns, report_len, &sshdr, 30*HZ, 3, NULL);
 	if (result != 0)
 	{
 		kfree(report_luns);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 12/54] Staging: hv: add the Hyper-V virtual scsi driver to the build
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (11 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-virtual-scsi-driver-to-the-build.patch --]
[-- Type: text/plain, Size: 989 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Add the Hyper-V virtual scsi driver to the kernel build system.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Kconfig  |    6 ++++++
 drivers/staging/hv/Makefile |    2 ++
 2 files changed, 8 insertions(+)

--- a/drivers/staging/hv/Kconfig
+++ b/drivers/staging/hv/Kconfig
@@ -6,3 +6,9 @@ config HYPERV
 	  Select this option to run Linux as a Hyper-V client operating
 	  system.
 
+config HYPERV_STORAGE
+	tristate "Microsoft Hyper-V virtual storage driver"
+	depends on SCSI
+	default n
+	help
+	 Select this option to enable the Hyper-V virtual storage driver.
--- a/drivers/staging/hv/Makefile
+++ b/drivers/staging/hv/Makefile
@@ -1,3 +1,5 @@
 obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
+obj-$(CONFIG_HYPERV_STORAGE)	+= hv_storvsc.o
 
 hv_vmbus-objs := vmbus_drv.o osd.o Sources.o
+hv_storvsc-objs := storvsc_drv.o osd.o StorVsc.o

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 13/54] Staging: hv: make the Hyper-V virtual block driver build
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (12 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-the-hyper-v-virtual-block-driver-build.patch --]
[-- Type: text/plain, Size: 3868 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The #define KERNEL_2_6_27 needs to be set, and I adjusted the include
directories a bit to get things to build properly.

I also fixed up the direct access of bus_id, as that field is now gone.
Lots of block api changes were needed, and I don't think I got it
all correct.  It would be great of someone who knows the block api better
could review it.

The hv_blkvsc code should now build, with no errors.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


---
 drivers/staging/hv/BlkVsc.c     |    2 +-
 drivers/staging/hv/blkvsc_drv.c |   23 ++++++++++++-----------
 2 files changed, 13 insertions(+), 12 deletions(-)

--- a/drivers/staging/hv/BlkVsc.c
+++ b/drivers/staging/hv/BlkVsc.c
@@ -21,7 +21,7 @@
  */
 
 
-#include "../storvsc/StorVsc.c"
+#include "StorVsc.c"
 
 static const char* gBlkDriverName="blkvsc";
 
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -20,6 +20,7 @@
  *
  */
 
+#define KERNEL_2_6_27
 
 #include <linux/init.h>
 #include <linux/module.h>
@@ -34,10 +35,10 @@
 #include <scsi/scsi_eh.h>
 #include <scsi/scsi_dbg.h>
 
-#include "logging.h"
-#include "vmbus.h"
+#include "include/logging.h"
+#include "include/vmbus.h"
 
-#include "StorVscApi.h"
+#include "include/StorVscApi.h"
 
 //
 // #defines
@@ -313,7 +314,7 @@ static int blkvsc_probe(struct device *d
 	ASSERT(sizeof(struct blkvsc_request_group) <= sizeof(struct blkvsc_request));
 
 #ifdef KERNEL_2_6_27
-        blkdev->request_pool = kmem_cache_create(device_ctx->device.bus_id,
+        blkdev->request_pool = kmem_cache_create(dev_name(&device_ctx->device),
                 sizeof(struct blkvsc_request) + storvsc_drv_obj->RequestExtSize, 0,
                 SLAB_HWCACHE_ALIGN, NULL);
 #else
@@ -426,7 +427,7 @@ static int blkvsc_probe(struct device *d
 	}
 
 	set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512));
-	blk_queue_hardsect_size(blkdev->gd->queue, blkdev->sector_size);
+	blk_queue_logical_block_size(blkdev->gd->queue, blkdev->sector_size);
 	// go!
 	add_disk(blkdev->gd);
 
@@ -982,7 +983,7 @@ static int blkvsc_do_request(struct bloc
 	int pending=0;
 	struct blkvsc_request_group *group=NULL;
 
-	DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %llu \n", blkdev, req, req->sector);
+	DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %llu \n", blkdev, req, blk_rq_pos(req));
 
 	// Create a group to tie req to list of blkvsc_reqs
 	group = (struct blkvsc_request_group*)kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC);
@@ -994,7 +995,7 @@ static int blkvsc_do_request(struct bloc
 	INIT_LIST_HEAD(&group->blkvsc_req_list);
 	group->outstanding = group->status = 0;
 
-	start_sector = req->sector;
+	start_sector = blk_rq_pos(req);
 
 	// foreach bio in the request
 	if (req->bio)
@@ -1314,13 +1315,13 @@ static void blkvsc_request(struct reques
 	int ret=0;
 
 	DPRINT_DBG(BLKVSC_DRV, "- enter \n");
-	while ((req = elv_next_request(queue)) != NULL)
+	while ((req = blk_peek_request(queue)) != NULL)
 	{
 		DPRINT_DBG(BLKVSC_DRV, "- req %p\n", req);
 
 		blkdev = req->rq_disk->private_data;
 		if (blkdev->shutting_down || !blk_fs_request(req) || blkdev->media_not_present) {
-			end_request(req, 0);
+			__blk_end_request_cur(req, 0);
 			continue;
 		}
 
@@ -1333,7 +1334,7 @@ static void blkvsc_request(struct reques
 			break;
 		}
 
-		blkdev_dequeue_request(req);
+		blk_start_request(req);
 
 		ret = blkvsc_do_request(blkdev, req);
 		if (ret > 0)
@@ -1410,7 +1411,7 @@ static int blkvsc_revalidate_disk(struct
 	{
 		blkvsc_do_read_capacity(blkdev);
 		set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512));
-		blk_queue_hardsect_size(gd->queue, blkdev->sector_size);
+		blk_queue_logical_block_size(gd->queue, blkdev->sector_size);
 	}
 	return 0;
 }

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 14/54] Staging: hv: add the Hyper-V virtual block driver to the build
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (13 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-virtual-block-driver-to-the-build.patch --]
[-- Type: text/plain, Size: 1098 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Add the Hyper-V virtual block driver to the kernel build system.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


---
 drivers/staging/hv/Kconfig  |    7 +++++++
 drivers/staging/hv/Makefile |    2 ++
 2 files changed, 9 insertions(+)

--- a/drivers/staging/hv/Kconfig
+++ b/drivers/staging/hv/Kconfig
@@ -12,3 +12,10 @@ config HYPERV_STORAGE
 	default n
 	help
 	 Select this option to enable the Hyper-V virtual storage driver.
+
+config HYPERV_BLOCK
+	tristate "Microsoft Hyper-V virtual block driver"
+	depends on BLOCK
+	default n
+	help
+	  Select this option to enable the Hyper-V virtual block driver.
--- a/drivers/staging/hv/Makefile
+++ b/drivers/staging/hv/Makefile
@@ -1,5 +1,7 @@
 obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
 obj-$(CONFIG_HYPERV_STORAGE)	+= hv_storvsc.o
+obj-$(CONFIG_HYPERV_BLOCK)	+= hv_blkvsc.o
 
 hv_vmbus-objs := vmbus_drv.o osd.o Sources.o
 hv_storvsc-objs := storvsc_drv.o osd.o StorVsc.o
+hv_blkvsc-objs := blkvsc_drv.o osd.o BlkVsc.o

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 15/54] Staging: hv: make the Hyper-V virtual network driver build
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (14 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-the-hyper-v-virtual-network-driver-build.patch --]
[-- Type: text/plain, Size: 3554 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The #define KERNEL_2_6_27 needs to be set, and I adjusted the include
directories a bit to get things to build properly.

The driver was changed to use net_device_ops, as that is needed to build
and operate properly now.

The hv_netvsc code should now build with no errors.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/NetVsc.c               |    3 ++-
 drivers/staging/hv/NetVsc.h               |    8 ++++----
 drivers/staging/hv/RndisFilter.c          |    5 +++--
 drivers/staging/hv/RndisFilter.h          |    4 ++--
 drivers/staging/hv/include/nvspprotocol.h |    2 +-
 drivers/staging/hv/netvsc_drv.c           |   21 +++++++++++++--------
 6 files changed, 25 insertions(+), 18 deletions(-)

--- a/drivers/staging/hv/include/nvspprotocol.h
+++ b/drivers/staging/hv/include/nvspprotocol.h
@@ -24,7 +24,7 @@
 
 #pragma once
 
-#include <VmbusChannelInterface.h>
+#include "VmbusChannelInterface.h"
 
 #define NVSP_INVALID_PROTOCOL_VERSION           ((UINT32)0xFFFFFFFF)
 
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -20,8 +20,9 @@
  *
  */
 
+#define KERNEL_2_6_27
 
-#include "logging.h"
+#include "include/logging.h"
 #include "NetVsc.h"
 #include "RndisFilter.h"
 
--- a/drivers/staging/hv/netvsc_drv.c
+++ b/drivers/staging/hv/netvsc_drv.c
@@ -20,6 +20,7 @@
  *
  */
 
+#define KERNEL_2_6_27
 
 #include <linux/init.h>
 #include <linux/module.h>
@@ -41,10 +42,10 @@
 #include <net/sock.h>
 #include <net/pkt_sched.h>
 
-#include "logging.h"
-#include "vmbus.h"
+#include "include/logging.h"
+#include "include/vmbus.h"
 
-#include "NetVscApi.h"
+#include "include/NetVscApi.h"
 
 MODULE_LICENSE("GPL");
 
@@ -158,6 +159,14 @@ static void netvsc_set_multicast_list(UN
 }
 
 
+static const struct net_device_ops device_ops = {
+	.ndo_open = netvsc_open,
+	.ndo_stop = netvsc_close,
+	.ndo_start_xmit	= netvsc_start_xmit,
+	.ndo_get_stats = netvsc_get_stats,
+	.ndo_set_multicast_list = netvsc_set_multicast_list,
+};
+
 /*++
 
 Name:	netvsc_probe()
@@ -225,11 +234,7 @@ static int netvsc_probe(struct device *d
 
 	memcpy(net->dev_addr, device_info.MacAddr, ETH_ALEN);
 
-	net->open				= netvsc_open;
-	net->hard_start_xmit	= netvsc_start_xmit;
-	net->stop				= netvsc_close;
-	net->get_stats			= netvsc_get_stats;
-	net->set_multicast_list = netvsc_set_multicast_list;
+	net->netdev_ops = &device_ops;
 
 #if !defined(KERNEL_2_6_27)
 	SET_MODULE_OWNER(net);
--- a/drivers/staging/hv/NetVsc.h
+++ b/drivers/staging/hv/NetVsc.h
@@ -24,12 +24,12 @@
 #ifndef _NETVSC_H_
 #define _NETVSC_H_
 
-#include "VmbusPacketFormat.h"
-#include "nvspprotocol.h"
+#include "include/VmbusPacketFormat.h"
+#include "include/nvspprotocol.h"
 
-#include "List.h"
+#include "include/List.h"
 
-#include "NetVscApi.h"
+#include "include/NetVscApi.h"
 //
 // #defines
 //
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -21,10 +21,11 @@
  *
  */
 
+#define KERNEL_2_6_27
 
-#include "logging.h"
+#include "include/logging.h"
 
-#include "NetVscApi.h"
+#include "include/NetVscApi.h"
 #include "RndisFilter.h"
 
 //
--- a/drivers/staging/hv/RndisFilter.h
+++ b/drivers/staging/hv/RndisFilter.h
@@ -27,10 +27,10 @@
 
 #define __struct_bcount(x)
 
-#include "osd.h"
+#include "include/osd.h"
 #include "NetVsc.h"
 
-#include "rndis.h"
+#include "include/rndis.h"
 
 #define RNDIS_HEADER_SIZE	(sizeof(RNDIS_MESSAGE) - sizeof(RNDIS_MESSAGE_CONTAINER))

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 16/54] Staging: hv: add the Hyper-V virtual network driver to the build
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (15 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-add-the-hyper-v-virtual-network-driver-to-the-build.patch --]
[-- Type: text/plain, Size: 1198 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Add the Hyper-V virtual network driver to the kernel build system.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Kconfig  |    7 +++++++
 drivers/staging/hv/Makefile |    2 ++
 2 files changed, 9 insertions(+)

--- a/drivers/staging/hv/Kconfig
+++ b/drivers/staging/hv/Kconfig
@@ -19,3 +19,10 @@ config HYPERV_BLOCK
 	default n
 	help
 	  Select this option to enable the Hyper-V virtual block driver.
+
+config HYPERV_NET
+	tristate "Microsoft Hyper-V virtual network driver"
+	depends on NET
+	default n
+	help
+	  Select this option to enable the Hyper-V virtual network driver.
--- a/drivers/staging/hv/Makefile
+++ b/drivers/staging/hv/Makefile
@@ -1,7 +1,9 @@
 obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
 obj-$(CONFIG_HYPERV_STORAGE)	+= hv_storvsc.o
 obj-$(CONFIG_HYPERV_BLOCK)	+= hv_blkvsc.o
+obj-$(CONFIG_HYPERV_NET)	+= hv_netvsc.o
 
 hv_vmbus-objs := vmbus_drv.o osd.o Sources.o
 hv_storvsc-objs := storvsc_drv.o osd.o StorVsc.o
 hv_blkvsc-objs := blkvsc_drv.o osd.o BlkVsc.o
+hv_netvsc-objs := netvsc_drv.o osd.o NetVsc.o RndisFilter.o

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 17/54] Staging: hv: remove INTERNAL typedef
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (16 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-internal-typedef.patch --]
[-- Type: text/plain, Size: 8486 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The INTERNAL typedef is now removed from the Hyper-V driver code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Channel.h          |   24 ++++++++++++------------
 drivers/staging/hv/ChannelInterface.c |   22 +++++++++++-----------
 drivers/staging/hv/ChannelInterface.h |    4 ++--
 drivers/staging/hv/ChannelMgmt.h      |   10 +++++-----
 drivers/staging/hv/Hv.h               |   12 ++++++------
 drivers/staging/hv/RingBuffer.h       |   16 ++++++++--------
 drivers/staging/hv/VmbusPrivate.h     |   24 ++++++++++--------------
 7 files changed, 54 insertions(+), 58 deletions(-)

--- a/drivers/staging/hv/Channel.h
+++ b/drivers/staging/hv/Channel.h
@@ -62,7 +62,7 @@ typedef struct _VMBUS_CHANNEL_PACKET_MUL
 // Routines
 //
 
-INTERNAL int
+static int
 VmbusChannelOpen(
 	VMBUS_CHANNEL			*Channel,
 	UINT32					SendRingBufferSize,
@@ -73,12 +73,12 @@ VmbusChannelOpen(
 	PVOID					Context
 	);
 
-INTERNAL void
+static void
 VmbusChannelClose(
 	VMBUS_CHANNEL		*Channel
 	);
 
-INTERNAL int
+static int
 VmbusChannelSendPacket(
 	VMBUS_CHANNEL		*Channel,
 	const PVOID			Buffer,
@@ -88,7 +88,7 @@ VmbusChannelSendPacket(
 	UINT32				Flags
 );
 
-INTERNAL int
+static int
 VmbusChannelSendPacketPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	PAGE_BUFFER			PageBuffers[],
@@ -98,7 +98,7 @@ VmbusChannelSendPacketPageBuffer(
 	UINT64				RequestId
 	);
 
-INTERNAL int
+static int
 VmbusChannelSendPacketMultiPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
@@ -107,7 +107,7 @@ VmbusChannelSendPacketMultiPageBuffer(
 	UINT64				RequestId
 );
 
-INTERNAL int
+static int
 VmbusChannelEstablishGpadl(
 	VMBUS_CHANNEL		*Channel,
 	PVOID				Kbuffer,	// from kmalloc()
@@ -115,13 +115,13 @@ VmbusChannelEstablishGpadl(
 	UINT32				*GpadlHandle
 	);
 
-INTERNAL int
+static int
 VmbusChannelTeardownGpadl(
 	VMBUS_CHANNEL	*Channel,
 	UINT32			GpadlHandle
 	);
 
-INTERNAL int
+static int
 VmbusChannelRecvPacket(
 	VMBUS_CHANNEL		*Channel,
 	PVOID				Buffer,
@@ -130,7 +130,7 @@ VmbusChannelRecvPacket(
 	UINT64*				RequestId
 	);
 
-INTERNAL int
+static int
 VmbusChannelRecvPacketRaw(
 	VMBUS_CHANNEL		*Channel,
 	PVOID				Buffer,
@@ -139,18 +139,18 @@ VmbusChannelRecvPacketRaw(
 	UINT64*				RequestId
 	);
 
-INTERNAL void
+static void
 VmbusChannelOnChannelEvent(
 	VMBUS_CHANNEL		*Channel
 	);
 
-INTERNAL void
+static void
 VmbusChannelGetDebugInfo(
 	VMBUS_CHANNEL				*Channel,
 	VMBUS_CHANNEL_DEBUG_INFO	*DebugInfo
 	);
 
-INTERNAL void
+static void
 VmbusChannelOnTimer(
 	void		*Context
 	);
--- a/drivers/staging/hv/ChannelInterface.c
+++ b/drivers/staging/hv/ChannelInterface.c
@@ -23,7 +23,7 @@
 
 #include "VmbusPrivate.h"
 
-INTERNAL int
+static int
 IVmbusChannelOpen(
 	PDEVICE_OBJECT		Device,
 	UINT32				SendBufferSize,
@@ -44,7 +44,7 @@ IVmbusChannelOpen(
 }
 
 
-INTERNAL void
+static void
 IVmbusChannelClose(
 	PDEVICE_OBJECT		Device
 	)
@@ -53,7 +53,7 @@ IVmbusChannelClose(
 }
 
 
-INTERNAL int
+static int
 IVmbusChannelSendPacket(
 	PDEVICE_OBJECT		Device,
 	const PVOID			Buffer,
@@ -71,7 +71,7 @@ IVmbusChannelSendPacket(
 									Flags);
 }
 
-INTERNAL int
+static int
 IVmbusChannelSendPacketPageBuffer(
 	PDEVICE_OBJECT		Device,
 	PAGE_BUFFER			PageBuffers[],
@@ -89,7 +89,7 @@ IVmbusChannelSendPacketPageBuffer(
 												RequestId);
 }
 
-INTERNAL int
+static int
 IVmbusChannelSendPacketMultiPageBuffer(
 	PDEVICE_OBJECT		Device,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
@@ -105,7 +105,7 @@ IVmbusChannelSendPacketMultiPageBuffer(
 													RequestId);
 }
 
-INTERNAL int
+static int
 IVmbusChannelRecvPacket (
 	PDEVICE_OBJECT		Device,
 	PVOID				Buffer,
@@ -121,7 +121,7 @@ IVmbusChannelRecvPacket (
 									RequestId);
 }
 
-INTERNAL int
+static int
 IVmbusChannelRecvPacketRaw(
 	PDEVICE_OBJECT		Device,
 	PVOID				Buffer,
@@ -137,7 +137,7 @@ IVmbusChannelRecvPacketRaw(
 										RequestId);
 }
 
-INTERNAL int
+static int
 IVmbusChannelEstablishGpadl(
 	PDEVICE_OBJECT		Device,
 	PVOID				Buffer,
@@ -151,7 +151,7 @@ IVmbusChannelEstablishGpadl(
 										GpadlHandle);
 }
 
-INTERNAL int
+static int
 IVmbusChannelTeardownGpadl(
    PDEVICE_OBJECT		Device,
    UINT32				GpadlHandle
@@ -162,7 +162,7 @@ IVmbusChannelTeardownGpadl(
 
 }
 
-INTERNAL void
+static void
 GetChannelInterface(
 	VMBUS_CHANNEL_INTERFACE *ChannelInterface
 	)
@@ -180,7 +180,7 @@ GetChannelInterface(
 }
 
 
-INTERNAL void
+static void
 GetChannelInfo(
 	PDEVICE_OBJECT		Device,
 	DEVICE_INFO			*DeviceInfo
--- a/drivers/staging/hv/ChannelInterface.h
+++ b/drivers/staging/hv/ChannelInterface.h
@@ -27,12 +27,12 @@
 
 #include "include/VmbusApi.h"
 
-INTERNAL void
+static void
 GetChannelInterface(
 	VMBUS_CHANNEL_INTERFACE *ChannelInterface
 	);
 
-INTERNAL void
+static void
 GetChannelInfo(
 	PDEVICE_OBJECT		Device,
 	DEVICE_INFO			*DeviceInfo
--- a/drivers/staging/hv/ChannelMgmt.h
+++ b/drivers/staging/hv/ChannelMgmt.h
@@ -128,27 +128,27 @@ typedef struct _VMBUS_CHANNEL_MSGINFO {
 // Routines
 //
 
-INTERNAL VMBUS_CHANNEL*
+static VMBUS_CHANNEL*
 AllocVmbusChannel(
 	void
 	);
 
-INTERNAL void
+static void
 FreeVmbusChannel(
 	VMBUS_CHANNEL *Channel
 	);
 
-INTERNAL void
+static void
 VmbusOnChannelMessage(
 	void *Context
 	);
 
-INTERNAL int
+static int
 VmbusChannelRequestOffers(
 	void
 	);
 
-INTERNAL void
+static void
 VmbusChannelReleaseUnattachedChannels(
 	void
 	);
--- a/drivers/staging/hv/Hv.h
+++ b/drivers/staging/hv/Hv.h
@@ -148,17 +148,17 @@ static inline void WriteMsr(int msr, UIN
 //
 // Hv Interface
 //
-INTERNAL int
+static int
 HvInit(
     VOID
     );
 
-INTERNAL VOID
+static VOID
 HvCleanup(
     VOID
     );
 
-INTERNAL HV_STATUS
+static HV_STATUS
 HvPostMessage(
 	HV_CONNECTION_ID connectionId,
 	HV_MESSAGE_TYPE  messageType,
@@ -166,17 +166,17 @@ HvPostMessage(
 	SIZE_T           payloadSize
 	);
 
-INTERNAL HV_STATUS
+static HV_STATUS
 HvSignalEvent(
 	VOID
 	);
 
-INTERNAL int
+static int
 HvSynicInit(
 	UINT32		irqVector
 	);
 
-INTERNAL VOID
+static VOID
 HvSynicCleanup(
 	VOID
 	);
--- a/drivers/staging/hv/RingBuffer.h
+++ b/drivers/staging/hv/RingBuffer.h
@@ -69,33 +69,33 @@ typedef struct _RING_BUFFER_DEBUG_INFO {
 // Interface
 //
 
-INTERNAL int
+static int
 RingBufferInit(
 	RING_BUFFER_INFO	*RingInfo,
 	PVOID				Buffer,
 	UINT32				BufferLen
 	);
 
-INTERNAL void
+static void
 RingBufferCleanup(
 	RING_BUFFER_INFO	*RingInfo
 	);
 
-INTERNAL int
+static int
 RingBufferWrite(
 	RING_BUFFER_INFO	*RingInfo,
 	SG_BUFFER_LIST		SgBuffers[],
 	UINT32				SgBufferCount
 	);
 
-INTERNAL int
+static int
 RingBufferPeek(
 	RING_BUFFER_INFO	*RingInfo,
 	PVOID				Buffer,
 	UINT32				BufferLen
 	);
 
-INTERNAL int
+static int
 RingBufferRead(
 	RING_BUFFER_INFO	*RingInfo,
 	PVOID				Buffer,
@@ -103,18 +103,18 @@ RingBufferRead(
 	UINT32				Offset
 	);
 
-INTERNAL UINT32
+static UINT32
 GetRingBufferInterruptMask(
 	RING_BUFFER_INFO *RingInfo
 	);
 
-INTERNAL void
+static void
 DumpRingInfo(
 	RING_BUFFER_INFO* RingInfo,
 	char *Prefix
 	);
 
-INTERNAL void
+static void
 RingBufferGetDebugInfo(
 	RING_BUFFER_INFO		*RingInfo,
 	RING_BUFFER_DEBUG_INFO	*DebugInfo
--- a/drivers/staging/hv/VmbusPrivate.h
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -25,10 +25,6 @@
 #ifndef _VMBUS_PRIVATE_H_
 #define _VMBUS_PRIVATE_H_
 
-#ifndef INTERNAL
-#define INTERNAL static
-#endif
-
 #include "Hv.h"
 #include "include/VmbusApi.h"
 #include "Channel.h"
@@ -114,25 +110,25 @@ extern VMBUS_CONNECTION gVmbusConnection
 //
 // General vmbus interface
 //
-INTERNAL DEVICE_OBJECT*
+static DEVICE_OBJECT*
 VmbusChildDeviceCreate(
 	GUID deviceType,
 	GUID deviceInstance,
 	void *context);
 
-INTERNAL int
+static int
 VmbusChildDeviceAdd(
 	DEVICE_OBJECT* Device);
 
-INTERNAL void
+static void
 VmbusChildDeviceRemove(
    DEVICE_OBJECT* Device);
 
-//INTERNAL void
+//static void
 //VmbusChildDeviceDestroy(
 //	DEVICE_OBJECT*);
 
-INTERNAL VMBUS_CHANNEL*
+static VMBUS_CHANNEL*
 GetChannelFromRelId(
 	UINT32 relId
 	);
@@ -140,28 +136,28 @@ GetChannelFromRelId(
 //
 // Connection interface
 //
-INTERNAL int
+static int
 VmbusConnect(
 	VOID
 	);
 
-INTERNAL int
+static int
 VmbusDisconnect(
 	VOID
 	);
 
-INTERNAL int
+static int
 VmbusPostMessage(
 	PVOID			buffer,
 	SIZE_T			bufSize
 	);
 
-INTERNAL int
+static int
 VmbusSetEvent(
 	UINT32 childRelId
 	);
 
-INTERNAL VOID
+static VOID
 VmbusOnEvents(
   VOID
 	);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 18/54] Staging: hv: remove PVOID typedef
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (17 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-pvoid-typedef.patch --]
[-- Type: text/plain, Size: 20602 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The PVOID typedef is now removed from the Hyper-V driver code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Channel.c                   |   20 ++++++++++----------
 drivers/staging/hv/Channel.h                   |   16 ++++++++--------
 drivers/staging/hv/ChannelInterface.c          |   16 ++++++++--------
 drivers/staging/hv/ChannelMgmt.c               |    8 ++++----
 drivers/staging/hv/ChannelMgmt.h               |    4 ++--
 drivers/staging/hv/Connection.c                |    6 +++---
 drivers/staging/hv/Hv.c                        |    2 +-
 drivers/staging/hv/Hv.h                        |    2 +-
 drivers/staging/hv/NetVsc.c                    |    8 ++++----
 drivers/staging/hv/NetVsc.h                    |    4 ++--
 drivers/staging/hv/RingBuffer.c                |   18 +++++++++---------
 drivers/staging/hv/RingBuffer.h                |    8 ++++----
 drivers/staging/hv/StorVsc.c                   |    6 +++---
 drivers/staging/hv/VmbusPrivate.h              |    2 +-
 drivers/staging/hv/include/NetVscApi.h         |    8 ++++----
 drivers/staging/hv/include/StorVscApi.h        |    4 ++--
 drivers/staging/hv/include/VmbusApi.h          |   18 +++++++++---------
 drivers/staging/hv/include/VmbusPacketFormat.h |    2 +-
 drivers/staging/hv/include/osd.h               |    5 ++---
 drivers/staging/hv/include/rndis.h             |    4 ++--
 drivers/staging/hv/osd.c                       |    4 ++--
 21 files changed, 82 insertions(+), 83 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -32,7 +32,7 @@
 //
 static int
 VmbusChannelCreateGpadlHeader(
-	PVOID					Kbuffer,	// must be phys and virt contiguous
+	void *					Kbuffer,	// must be phys and virt contiguous
 	UINT32					Size,		// page-size multiple
 	VMBUS_CHANNEL_MSGINFO	**msgInfo,
 	UINT32					*MessageCount
@@ -204,10 +204,10 @@ VmbusChannelOpen(
 	VMBUS_CHANNEL			*NewChannel,
 	UINT32					SendRingBufferSize,
 	UINT32					RecvRingBufferSize,
-	PVOID					UserData,
+	void *					UserData,
 	UINT32					UserDataLen,
 	PFN_CHANNEL_CALLBACK	pfnOnChannelCallback,
-	PVOID					Context
+	void *					Context
 	)
 {
 	int ret=0;
@@ -392,7 +392,7 @@ Description:
 --*/
 static int
 VmbusChannelCreateGpadlHeader(
-	PVOID					Kbuffer,	// from kmalloc()
+	void *					Kbuffer,	// from kmalloc()
 	UINT32					Size,		// page-size multiple
 	VMBUS_CHANNEL_MSGINFO	**MsgInfo,
 	UINT32					*MessageCount)
@@ -515,7 +515,7 @@ Description:
 int
 VmbusChannelEstablishGpadl(
 	VMBUS_CHANNEL	*Channel,
-	PVOID			Kbuffer,	// from kmalloc()
+	void *			Kbuffer,	// from kmalloc()
 	UINT32			Size,		// page-size multiple
 	UINT32			*GpadlHandle
 	)
@@ -752,7 +752,7 @@ Description:
 int
 VmbusChannelSendPacket(
 	VMBUS_CHANNEL		*Channel,
-	const PVOID			Buffer,
+	const void *			Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId,
 	VMBUS_PACKET_TYPE	Type,
@@ -820,7 +820,7 @@ VmbusChannelSendPacketPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	PAGE_BUFFER			PageBuffers[],
 	UINT32				PageCount,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId
 )
@@ -902,7 +902,7 @@ int
 VmbusChannelSendPacketMultiPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId
 )
@@ -984,7 +984,7 @@ Description:
 int
 VmbusChannelRecvPacket(
 	VMBUS_CHANNEL		*Channel,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				BufferActualLen,
 	UINT64*				RequestId
@@ -1061,7 +1061,7 @@ Description:
 int
 VmbusChannelRecvPacketRaw(
 	VMBUS_CHANNEL		*Channel,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				BufferActualLen,
 	UINT64*				RequestId
--- a/drivers/staging/hv/Channel.h
+++ b/drivers/staging/hv/Channel.h
@@ -67,10 +67,10 @@ VmbusChannelOpen(
 	VMBUS_CHANNEL			*Channel,
 	UINT32					SendRingBufferSize,
 	UINT32					RecvRingBufferSize,
-	PVOID					UserData,
+	void *					UserData,
 	UINT32					UserDataLen,
 	PFN_CHANNEL_CALLBACK	pfnOnChannelCallback,
-	PVOID					Context
+	void *					Context
 	);
 
 static void
@@ -81,7 +81,7 @@ VmbusChannelClose(
 static int
 VmbusChannelSendPacket(
 	VMBUS_CHANNEL		*Channel,
-	const PVOID			Buffer,
+	const void *			Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId,
 	VMBUS_PACKET_TYPE	Type,
@@ -93,7 +93,7 @@ VmbusChannelSendPacketPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	PAGE_BUFFER			PageBuffers[],
 	UINT32				PageCount,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId
 	);
@@ -102,7 +102,7 @@ static int
 VmbusChannelSendPacketMultiPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId
 );
@@ -110,7 +110,7 @@ VmbusChannelSendPacketMultiPageBuffer(
 static int
 VmbusChannelEstablishGpadl(
 	VMBUS_CHANNEL		*Channel,
-	PVOID				Kbuffer,	// from kmalloc()
+	void *				Kbuffer,	// from kmalloc()
 	UINT32				Size,		// page-size multiple
 	UINT32				*GpadlHandle
 	);
@@ -124,7 +124,7 @@ VmbusChannelTeardownGpadl(
 static int
 VmbusChannelRecvPacket(
 	VMBUS_CHANNEL		*Channel,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				BufferActualLen,
 	UINT64*				RequestId
@@ -133,7 +133,7 @@ VmbusChannelRecvPacket(
 static int
 VmbusChannelRecvPacketRaw(
 	VMBUS_CHANNEL		*Channel,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				BufferActualLen,
 	UINT64*				RequestId
--- a/drivers/staging/hv/ChannelInterface.c
+++ b/drivers/staging/hv/ChannelInterface.c
@@ -28,10 +28,10 @@ IVmbusChannelOpen(
 	PDEVICE_OBJECT		Device,
 	UINT32				SendBufferSize,
 	UINT32				RecvRingBufferSize,
-	PVOID				UserData,
+	void *				UserData,
 	UINT32				UserDataLen,
 	VMBUS_CHANNEL_CALLBACK ChannelCallback,
-	PVOID				Context
+	void *				Context
 	)
 {
 	return VmbusChannelOpen( (VMBUS_CHANNEL*)Device->context,
@@ -56,7 +56,7 @@ IVmbusChannelClose(
 static int
 IVmbusChannelSendPacket(
 	PDEVICE_OBJECT		Device,
-	const PVOID			Buffer,
+	const void *			Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId,
 	UINT32				Type,
@@ -76,7 +76,7 @@ IVmbusChannelSendPacketPageBuffer(
 	PDEVICE_OBJECT		Device,
 	PAGE_BUFFER			PageBuffers[],
 	UINT32				PageCount,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId
 	)
@@ -93,7 +93,7 @@ static int
 IVmbusChannelSendPacketMultiPageBuffer(
 	PDEVICE_OBJECT		Device,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId
 	)
@@ -108,7 +108,7 @@ IVmbusChannelSendPacketMultiPageBuffer(
 static int
 IVmbusChannelRecvPacket (
 	PDEVICE_OBJECT		Device,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				BufferActualLen,
 	UINT64*				RequestId
@@ -124,7 +124,7 @@ IVmbusChannelRecvPacket (
 static int
 IVmbusChannelRecvPacketRaw(
 	PDEVICE_OBJECT		Device,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				BufferActualLen,
 	UINT64*				RequestId
@@ -140,7 +140,7 @@ IVmbusChannelRecvPacketRaw(
 static int
 IVmbusChannelEstablishGpadl(
 	PDEVICE_OBJECT		Device,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				GpadlHandle
 	)
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -82,12 +82,12 @@ VmbusChannelOnVersionResponse(
 
 static void
 VmbusChannelProcessOffer(
-	PVOID context
+	void * context
 	);
 
 static void
 VmbusChannelProcessRescindOffer(
-	PVOID context
+	void * context
 	);
 
 
@@ -233,7 +233,7 @@ Description:
 --*/
 static void
 VmbusChannelProcessOffer(
-	PVOID context
+	void * context
 	)
 {
 	int ret=0;
@@ -317,7 +317,7 @@ Description:
 --*/
 static void
 VmbusChannelProcessRescindOffer(
-	PVOID context
+	void * context
 	)
 {
 	VMBUS_CHANNEL* channel=(VMBUS_CHANNEL*)context;
--- a/drivers/staging/hv/ChannelMgmt.h
+++ b/drivers/staging/hv/ChannelMgmt.h
@@ -34,7 +34,7 @@
 
 
 
-typedef void (*PFN_CHANNEL_CALLBACK)(PVOID context);
+typedef void (*PFN_CHANNEL_CALLBACK)(void * context);
 
 typedef enum {
 	CHANNEL_OFFER_STATE,
@@ -70,7 +70,7 @@ typedef struct _VMBUS_CHANNEL {
 	//HANDLE						dataWorkQueue;
 
 	PFN_CHANNEL_CALLBACK		OnChannelCallback;
-	PVOID						ChannelCallbackContext;
+	void *						ChannelCallbackContext;
 
 } VMBUS_CHANNEL;
 
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -103,7 +103,7 @@ VmbusConnect(
 	msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER;
 	msg->InterruptPage = GetPhysicalAddress(gVmbusConnection.InterruptPage);
 	msg->MonitorPage1 = GetPhysicalAddress(gVmbusConnection.MonitorPages);
-	msg->MonitorPage2 = GetPhysicalAddress((PVOID)((ULONG_PTR)gVmbusConnection.MonitorPages + PAGE_SIZE));
+	msg->MonitorPage2 = GetPhysicalAddress((void *)((ULONG_PTR)gVmbusConnection.MonitorPages + PAGE_SIZE));
 
 	// Add to list before we send the request since we may receive the response
 	// before returning from this routine
@@ -290,7 +290,7 @@ Description:
 --*/
 static void
 VmbusProcessChannelEvent(
-	PVOID context
+	void * context
 	)
 {
 	VMBUS_CHANNEL* channel;
@@ -385,7 +385,7 @@ Description:
 --*/
 int
 VmbusPostMessage(
-	PVOID			buffer,
+	void *			buffer,
 	SIZE_T			bufferLen
 	)
 {
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -396,7 +396,7 @@ HV_STATUS
 HvPostMessage(
 	HV_CONNECTION_ID connectionId,
 	HV_MESSAGE_TYPE  messageType,
-	PVOID            payload,
+	void *            payload,
 	SIZE_T           payloadSize
 	)
 {
--- a/drivers/staging/hv/Hv.h
+++ b/drivers/staging/hv/Hv.h
@@ -162,7 +162,7 @@ static HV_STATUS
 HvPostMessage(
 	HV_CONNECTION_ID connectionId,
 	HV_MESSAGE_TYPE  messageType,
-	PVOID            payload,
+	void *            payload,
 	SIZE_T           payloadSize
 	);
 
--- a/drivers/staging/hv/include/NetVscApi.h
+++ b/drivers/staging/hv/include/NetVscApi.h
@@ -49,7 +49,7 @@ typedef int (*PFN_ON_CLOSE)(DEVICE_OBJEC
 
 typedef void (*PFN_QUERY_LINKSTATUS)(DEVICE_OBJECT *Device);
 typedef int (*PFN_ON_SEND)(DEVICE_OBJECT *dev, PNETVSC_PACKET packet);
-typedef void (*PFN_ON_SENDRECVCOMPLETION)(PVOID Context);
+typedef void (*PFN_ON_SENDRECVCOMPLETION)(void * Context);
 
 typedef int (*PFN_ON_RECVCALLBACK)(DEVICE_OBJECT *dev, PNETVSC_PACKET packet);
 typedef void (*PFN_ON_LINKSTATUS_CHANGED)(DEVICE_OBJECT *dev, UINT32 Status);
@@ -80,18 +80,18 @@ typedef struct _NETVSC_PACKET {
 	union {
 		struct{
 			UINT64						ReceiveCompletionTid;
-			PVOID						ReceiveCompletionContext;
+			void *						ReceiveCompletionContext;
 			PFN_ON_SENDRECVCOMPLETION	OnReceiveCompletion;
 		} Recv;
 		struct{
 			UINT64						SendCompletionTid;
-			PVOID						SendCompletionContext;
+			void *						SendCompletionContext;
 			PFN_ON_SENDRECVCOMPLETION	OnSendCompletion;
 		} Send;
 	} Completion;
 
 	// This points to the memory after PageBuffers
-	PVOID					Extension;
+	void *					Extension;
 
 	UINT32					TotalDataBufferLength;
 	// Points to the send/receive buffer where the ethernet frame is
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -133,7 +133,6 @@ typedef long long			LONGLONG;
 typedef unsigned long		SIZE_T;
 typedef void				VOID;
 //typedef unsigned char		GUID[16];
-typedef void*				PVOID;
 typedef unsigned char		BOOL;
 typedef unsigned char		BOOLEAN;
 typedef void*				HANDLE;
@@ -246,9 +245,9 @@ extern void	SpinlockRelease(HANDLE hSpin
 void* Physical2LogicalAddr(ULONG_PTR PhysAddr);
 
 #define GetPhysicalAddress Logical2PhysicalAddr
-ULONG_PTR Logical2PhysicalAddr(PVOID LogicalAddr);
+ULONG_PTR Logical2PhysicalAddr(void * LogicalAddr);
 
-ULONG_PTR Virtual2Physical(PVOID VirtAddr);
+ULONG_PTR Virtual2Physical(void * VirtAddr);
 
 void* PageMapVirtualAddress(unsigned long Pfn);
 void PageUnmapVirtualAddress(void* VirtAddr);
--- a/drivers/staging/hv/include/rndis.h
+++ b/drivers/staging/hv/include/rndis.h
@@ -827,10 +827,10 @@ typedef __struct_bcount(MessageLength) s
 
 // get pointer to contained message from NDIS_MESSAGE pointer
 #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(RndisMessage)          \
-    ((PVOID) &RndisMessage->Message)
+    ((void *) &RndisMessage->Message)
 
 // get pointer to contained message from NDIS_MESSAGE pointer
 #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(RndisMessage)      \
-    ((PVOID) RndisMessage)
+    ((void *) RndisMessage)
 
 #endif // _RNDIS_H_
--- a/drivers/staging/hv/include/StorVscApi.h
+++ b/drivers/staging/hv/include/StorVscApi.h
@@ -83,12 +83,12 @@ typedef struct _STORVSC_REQUEST {
 	UCHAR*					SenseBuffer;
 	UINT32					SenseBufferSize;
 
-	PVOID					Context;
+	void *					Context;
 
 	PFN_ON_IO_REQUEST_COMPLTN	OnIOCompletion;
 
 	// This points to the memory after DataBuffer
-	PVOID					Extension;
+	void *					Extension;
 
 	MULTIPAGE_BUFFER		DataBuffer;
 } STORVSC_REQUEST;
--- a/drivers/staging/hv/include/VmbusApi.h
+++ b/drivers/staging/hv/include/VmbusApi.h
@@ -88,16 +88,16 @@ typedef int (*PFN_ON_CHILDDEVICE_ADD)(PD
 typedef void (*PFN_ON_CHILDDEVICE_REMOVE)(PDEVICE_OBJECT Device);
 
 // Vmbus channel interface
-typedef void (*VMBUS_CHANNEL_CALLBACK)(PVOID context);
+typedef void (*VMBUS_CHANNEL_CALLBACK)(void * context);
 
 typedef int	(*VMBUS_CHANNEL_OPEN)(
 	PDEVICE_OBJECT		Device,
 	UINT32				SendBufferSize,
 	UINT32				RecvRingBufferSize,
-	PVOID				UserData,
+	void *				UserData,
 	UINT32				UserDataLen,
 	VMBUS_CHANNEL_CALLBACK ChannelCallback,
-	PVOID				Context
+	void *				Context
 	);
 
 typedef void (*VMBUS_CHANNEL_CLOSE)(
@@ -106,7 +106,7 @@ typedef void (*VMBUS_CHANNEL_CLOSE)(
 
 typedef int	(*VMBUS_CHANNEL_SEND_PACKET)(
 	PDEVICE_OBJECT		Device,
-	const PVOID			Buffer,
+	const void *			Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId,
 	UINT32				Type,
@@ -117,7 +117,7 @@ typedef int	(*VMBUS_CHANNEL_SEND_PACKET_
 	PDEVICE_OBJECT		Device,
 	PAGE_BUFFER			PageBuffers[],
 	UINT32				PageCount,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId
 	);
@@ -125,14 +125,14 @@ typedef int	(*VMBUS_CHANNEL_SEND_PACKET_
 typedef int	(*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER)(
 	PDEVICE_OBJECT		Device,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT64				RequestId
 );
 
 typedef int	(*VMBUS_CHANNEL_RECV_PACKET)(
 	PDEVICE_OBJECT		Device,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				BufferActualLen,
 	UINT64*				RequestId
@@ -140,7 +140,7 @@ typedef int	(*VMBUS_CHANNEL_RECV_PACKET)
 
 typedef int	(*VMBUS_CHANNEL_RECV_PACKET_PAW)(
 	PDEVICE_OBJECT		Device,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32*				BufferActualLen,
 	UINT64*				RequestId
@@ -148,7 +148,7 @@ typedef int	(*VMBUS_CHANNEL_RECV_PACKET_
 
 typedef int	(*VMBUS_CHANNEL_ESTABLISH_GPADL)(
 	PDEVICE_OBJECT		Device,
-	PVOID				Buffer,	// from kmalloc()
+	void *				Buffer,	// from kmalloc()
 	UINT32				BufferLen,		// page-size multiple
 	UINT32*				GpadlHandle
 	);
--- a/drivers/staging/hv/include/VmbusPacketFormat.h
+++ b/drivers/staging/hv/include/VmbusPacketFormat.h
@@ -287,7 +287,7 @@ typedef union {
 } VMPACKET_LARGEST_POSSIBLE_HEADER, *PVMPACKET_LARGEST_POSSIBLE_HEADER;
 
 #define VMPACKET_DATA_START_ADDRESS(__packet)                           \
-    (PVOID)(((PUCHAR)__packet) + ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8 * 8)
+    (void *)(((PUCHAR)__packet) + ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8 * 8)
 
 #define VMPACKET_DATA_LENGTH(__packet)                                  \
     ((((PVMPACKET_DESCRIPTOR)__packet)->Length8 - ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8) * 8)
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -59,7 +59,7 @@ NetVscOnCleanup(
 
 static void
 NetVscOnChannelCallback(
-	PVOID context
+	void * context
 	);
 
 static int
@@ -107,7 +107,7 @@ NetVscOnReceive(
 
 static void
 NetVscOnReceiveCompletion(
-	PVOID Context
+	void * Context
 	);
 
 static void
@@ -1337,7 +1337,7 @@ retry_send_cmplt:
 //
 static void
 NetVscOnReceiveCompletion(
-	PVOID Context)
+	void * Context)
 {
 	NETVSC_PACKET *packet = (NETVSC_PACKET*)Context;
 	DEVICE_OBJECT *device = (DEVICE_OBJECT*)packet->Device;
@@ -1393,7 +1393,7 @@ NetVscOnReceiveCompletion(
 
 void
 NetVscOnChannelCallback(
-	PVOID Context
+	void * Context
 	)
 {
 	const int netPacketSize=2048;
--- a/drivers/staging/hv/NetVsc.h
+++ b/drivers/staging/hv/NetVsc.h
@@ -65,13 +65,13 @@ typedef struct _NETVSC_DEVICE {
 	HANDLE							ReceivePacketListLock;
 
 	// Send buffer allocated by us but manages by NetVSP
-	PVOID							SendBuffer;
+	void *							SendBuffer;
 	UINT32							SendBufferSize;
 	UINT32							SendBufferGpadlHandle;
 	UINT32							SendSectionSize;
 
 	// Receive buffer allocated by us but manages by NetVSP
-	PVOID							ReceiveBuffer;
+	void *							ReceiveBuffer;
 	UINT32							ReceiveBufferSize;
 	UINT32							ReceiveBufferGpadlHandle;
 	UINT32							ReceiveSectionCount;
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -414,14 +414,14 @@ void* Physical2LogicalAddr(ULONG_PTR Phy
 	return logicalAddr;
 }
 
-ULONG_PTR Logical2PhysicalAddr(PVOID LogicalAddr)
+ULONG_PTR Logical2PhysicalAddr(void * LogicalAddr)
 {
 	BUG_ON(!virt_addr_valid(LogicalAddr));
 	return virt_to_phys(LogicalAddr);
 }
 
 
-ULONG_PTR Virtual2Physical(PVOID VirtAddr)
+ULONG_PTR Virtual2Physical(void * VirtAddr)
 {
 	ULONG_PTR pfn = vmalloc_to_pfn(VirtAddr);
 
--- a/drivers/staging/hv/RingBuffer.c
+++ b/drivers/staging/hv/RingBuffer.c
@@ -156,10 +156,10 @@ Description:
 	Get the start of the ring buffer
 
 --*/
-static inline PVOID
+static inline void *
 GetRingBuffer(RING_BUFFER_INFO* RingInfo)
 {
-	return (PVOID)RingInfo->RingBuffer->Buffer;
+	return (void *)RingInfo->RingBuffer->Buffer;
 }
 
 
@@ -228,13 +228,13 @@ static UINT32
 CopyToRingBuffer(
 	RING_BUFFER_INFO	*RingInfo,
 	UINT32				StartWriteOffset,
-	PVOID				Src,
+	void *				Src,
 	UINT32				SrcLen);
 
 static UINT32
 CopyFromRingBuffer(
 	RING_BUFFER_INFO	*RingInfo,
-	PVOID				Dest,
+	void *				Dest,
 	UINT32				DestLen,
 	UINT32				StartReadOffset);
 
@@ -486,7 +486,7 @@ Description:
 int
 RingBufferRead(
 	RING_BUFFER_INFO*	InRingInfo,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32				Offset
 	)
@@ -557,10 +557,10 @@ UINT32
 CopyToRingBuffer(
 	RING_BUFFER_INFO	*RingInfo,
 	UINT32				StartWriteOffset,
-	PVOID				Src,
+	void *				Src,
 	UINT32				SrcLen)
 {
-	PVOID ringBuffer=GetRingBuffer(RingInfo);
+	void * ringBuffer=GetRingBuffer(RingInfo);
 	UINT32 ringBufferSize=GetRingBufferSize(RingInfo);
 	UINT32 fragLen;
 
@@ -597,11 +597,11 @@ Description:
 UINT32
 CopyFromRingBuffer(
 	RING_BUFFER_INFO	*RingInfo,
-	PVOID				Dest,
+	void *				Dest,
 	UINT32				DestLen,
 	UINT32				StartReadOffset)
 {
-	PVOID ringBuffer=GetRingBuffer(RingInfo);
+	void * ringBuffer=GetRingBuffer(RingInfo);
 	UINT32 ringBufferSize=GetRingBufferSize(RingInfo);
 
 	UINT32 fragLen;
--- a/drivers/staging/hv/RingBuffer.h
+++ b/drivers/staging/hv/RingBuffer.h
@@ -28,7 +28,7 @@
 #include "include/osd.h"
 
 typedef struct _SG_BUFFER_LIST {
-	PVOID	Data;
+	void *	Data;
 	UINT32	Length;
 } SG_BUFFER_LIST;
 
@@ -72,7 +72,7 @@ typedef struct _RING_BUFFER_DEBUG_INFO {
 static int
 RingBufferInit(
 	RING_BUFFER_INFO	*RingInfo,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen
 	);
 
@@ -91,14 +91,14 @@ RingBufferWrite(
 static int
 RingBufferPeek(
 	RING_BUFFER_INFO	*RingInfo,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen
 	);
 
 static int
 RingBufferRead(
 	RING_BUFFER_INFO	*RingInfo,
-	PVOID				Buffer,
+	void *				Buffer,
 	UINT32				BufferLen,
 	UINT32				Offset
 	);
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -118,7 +118,7 @@ StorVscOnCleanup(
 
 static void
 StorVscOnChannelCallback(
-	PVOID Context
+	void * Context
 	);
 
 static void
@@ -530,7 +530,7 @@ StorVscConnectToVsp(
 	ret = Device->Driver->VmbusChannelInterface.Open(Device,
 		storDriver->RingBufferSize,
 		storDriver->RingBufferSize,
-		(PVOID)&props,
+		(void *)&props,
 		sizeof(VMSTORAGE_CHANNEL_PROPERTIES),
 		StorVscOnChannelCallback,
 		Device
@@ -901,7 +901,7 @@ StorVscOnReceive(
 
 void
 StorVscOnChannelCallback(
-	PVOID Context
+	void * Context
 	)
 {
 	int ret=0;
--- a/drivers/staging/hv/VmbusPrivate.h
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -148,7 +148,7 @@ VmbusDisconnect(
 
 static int
 VmbusPostMessage(
-	PVOID			buffer,
+	void *			buffer,
 	SIZE_T			bufSize
 	);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 19/54] Staging: hv: remove VOID typedef
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (18 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-void-typedef.patch --]
[-- Type: text/plain, Size: 7274 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The VOID typedef is now removed from the Hyper-V driver code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Channel.c      |    2 +-
 drivers/staging/hv/ChannelMgmt.c  |    6 +++---
 drivers/staging/hv/ChannelMgmt.h  |    2 +-
 drivers/staging/hv/Connection.c   |    6 +++---
 drivers/staging/hv/Hv.c           |    4 ++--
 drivers/staging/hv/Hv.h           |   12 ++++++------
 drivers/staging/hv/RingBuffer.c   |    2 +-
 drivers/staging/hv/RndisFilter.c  |    4 ++--
 drivers/staging/hv/VmbusPrivate.h |   16 ++++++++--------
 drivers/staging/hv/include/List.h |   14 +++++++-------
 drivers/staging/hv/include/osd.h  |    3 +--
 drivers/staging/hv/osd.c          |    8 ++++----
 12 files changed, 39 insertions(+), 40 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -677,7 +677,7 @@ Description:
 	Close the specified channel
 
 --*/
-VOID
+void
 VmbusChannelClose(
 	VMBUS_CHANNEL	*Channel
 	)
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -672,7 +672,7 @@ Description:
 	This is invoked in the vmbus worker thread context.
 
 --*/
-VOID
+void
 VmbusOnChannelMessage(
 	void *Context
 	)
@@ -722,7 +722,7 @@ Description:
 --*/
 int
 VmbusChannelRequestOffers(
-	VOID
+	void
 	)
 {
 	int ret=0;
@@ -785,7 +785,7 @@ Description:
 --*/
 void
 VmbusChannelReleaseUnattachedChannels(
-	VOID
+	void
 	)
 {
 	LIST_ENTRY *entry;
--- a/drivers/staging/hv/ChannelMgmt.h
+++ b/drivers/staging/hv/ChannelMgmt.h
@@ -59,7 +59,7 @@ typedef struct _VMBUS_CHANNEL {
 	UINT32						RingBufferGpadlHandle;
 
 	// Allocated memory for ring buffer
-	VOID*						RingBufferPages;
+	void *						RingBufferPages;
 	UINT32						RingBufferPageCount;
 	RING_BUFFER_INFO			Outbound;	// send to parent
 	RING_BUFFER_INFO			Inbound;	// receive from parent
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -195,7 +195,7 @@ Description:
 --*/
 int
 VmbusDisconnect(
-	VOID
+	void
 	)
 {
 	int ret=0;
@@ -323,9 +323,9 @@ Description:
 	Handler for events
 
 --*/
-VOID
+void
 VmbusOnEvents(
-  VOID
+  void
 	)
 {
 	int dword;
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -621,9 +621,9 @@ Description:
 	Cleanup routine for HvSynicInit().
 
 --*/
-VOID
+void
 HvSynicCleanup(
-	VOID
+	void
 	)
 {
     HV_SYNIC_SINT	sharedSint;
--- a/drivers/staging/hv/Hv.h
+++ b/drivers/staging/hv/Hv.h
@@ -150,12 +150,12 @@ static inline void WriteMsr(int msr, UIN
 //
 static int
 HvInit(
-    VOID
+    void
     );
 
-static VOID
+static void
 HvCleanup(
-    VOID
+    void
     );
 
 static HV_STATUS
@@ -168,7 +168,7 @@ HvPostMessage(
 
 static HV_STATUS
 HvSignalEvent(
-	VOID
+	void
 	);
 
 static int
@@ -176,9 +176,9 @@ HvSynicInit(
 	UINT32		irqVector
 	);
 
-static VOID
+static void
 HvSynicCleanup(
-	VOID
+	void
 	);
 
 #endif // __HV_H__
--- a/drivers/staging/hv/include/List.h
+++ b/drivers/staging/hv/include/List.h
@@ -44,7 +44,7 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 
 /*
- *  VOID
+ *  void
  *  InitializeListHead(
  *      PLIST_ENTRY ListHead
  *      );
@@ -132,7 +132,7 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 
 /*
- *  VOID
+ *  void
  *  RemoveEntryList(
  *      PLIST_ENTRY Entry
  *      );
@@ -148,7 +148,7 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 
 /*
- *  VOID
+ *  void
  *  AttachList(
  *      PLIST_ENTRY ListHead,
  *      PLIST_ENTRY ListEntry
@@ -168,7 +168,7 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 
 /*
- *  VOID
+ *  void
  *  InsertTailList(
  *      PLIST_ENTRY ListHead,
  *      PLIST_ENTRY Entry
@@ -188,7 +188,7 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 
 /*
- *  VOID
+ *  void
  *  InsertHeadList(
  *      PLIST_ENTRY ListHead,
  *      PLIST_ENTRY Entry
@@ -207,7 +207,7 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 
 /*
- *  VOID
+ *  void
  *  IterateListEntries(
  *      PLIST_ENTRY anchor,
  *      PLIST_ENTRY index,
@@ -245,7 +245,7 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 
 /*
- *  VOID
+ *  void
  *  PushEntryList(
  *      PSINGLE_LIST_ENTRY ListHead,
  *		PSINGLE_LIST_ENTRY Entry
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -131,7 +131,6 @@ typedef long long			LONGLONG;
 // Other types
 //
 typedef unsigned long		SIZE_T;
-typedef void				VOID;
 //typedef unsigned char		GUID[16];
 typedef unsigned char		BOOL;
 typedef unsigned char		BOOLEAN;
@@ -219,7 +218,7 @@ extern void* MemAlloc(unsigned int size)
 extern void* MemAllocZeroed(unsigned int size);
 extern void* MemAllocAtomic(unsigned int size);
 extern void MemFree(void* buf);
-extern void MemoryFence(VOID);
+extern void MemoryFence(void);
 
 extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
 extern void TimerClose(HANDLE hTimer);
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -375,7 +375,7 @@ int WaitEventWaitEx(HANDLE hWait, UINT32
 	return ret;
 }
 
-HANDLE SpinlockCreate(VOID)
+HANDLE SpinlockCreate(void)
 {
 	SPINLOCK* spin = kmalloc(sizeof(SPINLOCK), GFP_KERNEL);
 	if (!spin)
@@ -387,21 +387,21 @@ HANDLE SpinlockCreate(VOID)
 	return spin;
 }
 
-VOID SpinlockAcquire(HANDLE hSpin)
+void SpinlockAcquire(HANDLE hSpin)
 {
 	SPINLOCK* spin = (SPINLOCK* )hSpin;
 
 	spin_lock_irqsave(&spin->lock, spin->flags);
 }
 
-VOID SpinlockRelease(HANDLE hSpin)
+void SpinlockRelease(HANDLE hSpin)
 {
 	SPINLOCK* spin = (SPINLOCK* )hSpin;
 
 	spin_unlock_irqrestore(&spin->lock, spin->flags);
 }
 
-VOID SpinlockClose(HANDLE hSpin)
+void SpinlockClose(HANDLE hSpin)
 {
 	SPINLOCK* spin = (SPINLOCK* )hSpin;
 	kfree(spin);
--- a/drivers/staging/hv/RingBuffer.c
+++ b/drivers/staging/hv/RingBuffer.c
@@ -301,7 +301,7 @@ Description:
 int
 RingBufferInit(
 	RING_BUFFER_INFO	*RingInfo,
-	VOID				*Buffer,
+	void				*Buffer,
 	UINT32				BufferLen
 	)
 {
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -120,7 +120,7 @@ static int
 RndisFilterQueryDevice(
 	RNDIS_DEVICE	*Device,
 	UINT32			Oid,
-	VOID			*Result,
+	void			*Result,
 	UINT32			*ResultSize
 	);
 
@@ -585,7 +585,7 @@ static int
 RndisFilterQueryDevice(
 	RNDIS_DEVICE	*Device,
 	UINT32			Oid,
-	VOID			*Result,
+	void			*Result,
 	UINT32			*ResultSize
 	)
 {
--- a/drivers/staging/hv/VmbusPrivate.h
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -73,12 +73,12 @@ typedef struct _VMBUS_CONNECTION {
 	// calls Hv to generate a port event. The other end
 	// receives the port event and parse the recvInterruptPage
 	// to see which bit is set
-	VOID*								InterruptPage;
-	VOID*								SendInterruptPage;
-	VOID*								RecvInterruptPage;
+	void *								InterruptPage;
+	void *								SendInterruptPage;
+	void *								RecvInterruptPage;
 
 	// 2 pages - 1st page for parent->child notification and 2nd is child->parent notification
-	VOID*								MonitorPages;
+	void *								MonitorPages;
 	LIST_ENTRY							ChannelMsgList;
 	HANDLE								ChannelMsgLock;
 
@@ -138,12 +138,12 @@ GetChannelFromRelId(
 //
 static int
 VmbusConnect(
-	VOID
+	void
 	);
 
 static int
 VmbusDisconnect(
-	VOID
+	void
 	);
 
 static int
@@ -157,9 +157,9 @@ VmbusSetEvent(
 	UINT32 childRelId
 	);
 
-static VOID
+static void
 VmbusOnEvents(
-  VOID
+  void
 	);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 20/54] Staging: hv: remove UINT8 and INT8 typedefs
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (19 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-uint8-and-int8-typedefs.patch --]
[-- Type: text/plain, Size: 8027 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The UINT8 and INT8 typedefs are now removed from the Hyper-V driver
code.

Had to include <linux/kernel.h> in a few places to get the
build to work properly as well.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/BlkVsc.c                    |    2 +-
 drivers/staging/hv/Channel.c                   |    6 +++---
 drivers/staging/hv/ChannelMgmt.c               |    4 ++--
 drivers/staging/hv/ChannelMgmt.h               |    4 ++--
 drivers/staging/hv/NetVsc.c                    |    1 +
 drivers/staging/hv/RingBuffer.h                |    4 ++--
 drivers/staging/hv/RndisFilter.c               |    1 +
 drivers/staging/hv/StorVsc.c                   |    1 +
 drivers/staging/hv/Vmbus.c                     |    2 +-
 drivers/staging/hv/include/ChannelMessages.h   |    2 +-
 drivers/staging/hv/include/HvSynicApi.h        |   14 +++++++-------
 drivers/staging/hv/include/StorVscApi.h        |    2 +-
 drivers/staging/hv/include/VmbusPacketFormat.h |    6 +++---
 drivers/staging/hv/include/osd.h               |    2 --
 14 files changed, 26 insertions(+), 25 deletions(-)

--- a/drivers/staging/hv/BlkVsc.c
+++ b/drivers/staging/hv/BlkVsc.c
@@ -20,7 +20,7 @@
  *
  */
 
-
+#include <linux/kernel.h>
 #include "StorVsc.c"
 
 static const char* gBlkDriverName="blkvsc";
--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -21,7 +21,7 @@
  *
  */
 
-
+#include <linux/kernel.h>
 #include "include/osd.h"
 #include "include/logging.h"
 
@@ -162,8 +162,8 @@ VmbusChannelGetDebugInfo(
 	)
 {
 	HV_MONITOR_PAGE *monitorPage;
-    UINT8 monitorGroup    = (UINT8)Channel->OfferMsg.MonitorId / 32;
-    UINT8 monitorOffset   = (UINT8)Channel->OfferMsg.MonitorId % 32;
+    u8 monitorGroup    = (u8)Channel->OfferMsg.MonitorId / 32;
+    u8 monitorOffset   = (u8)Channel->OfferMsg.MonitorId % 32;
 	//UINT32 monitorBit	= 1 << monitorOffset;
 
 	DebugInfo->RelId = Channel->OfferMsg.ChildRelId;
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -396,8 +396,8 @@ VmbusChannelOnOffer(
 	DPRINT_DBG(VMBUS, "channel object allocated - %p", newChannel);
 
 	memcpy(&newChannel->OfferMsg, offer, sizeof(VMBUS_CHANNEL_OFFER_CHANNEL));
-	newChannel->MonitorGroup = (UINT8)offer->MonitorId / 32;
-	newChannel->MonitorBit = (UINT8)offer->MonitorId % 32;
+	newChannel->MonitorGroup = (u8)offer->MonitorId / 32;
+	newChannel->MonitorBit = (u8)offer->MonitorId % 32;
 
 	// TODO: Make sure the offer comes from our parent partition
 	WorkQueueQueueWorkItem(newChannel->ControlWQ, VmbusChannelProcessOffer, newChannel);
--- a/drivers/staging/hv/ChannelMgmt.h
+++ b/drivers/staging/hv/ChannelMgmt.h
@@ -53,8 +53,8 @@ typedef struct _VMBUS_CHANNEL {
 
 	VMBUS_CHANNEL_OFFER_CHANNEL OfferMsg;
 	// These are based on the OfferMsg.MonitorId. Save it here for easy access.
-	UINT8						MonitorGroup;
-	UINT8						MonitorBit;
+	u8						MonitorGroup;
+	u8						MonitorBit;
 
 	UINT32						RingBufferGpadlHandle;
 
--- a/drivers/staging/hv/include/ChannelMessages.h
+++ b/drivers/staging/hv/include/ChannelMessages.h
@@ -91,7 +91,7 @@ typedef struct _VMBUS_CHANNEL_OFFER_CHAN
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
     VMBUS_CHANNEL_OFFER Offer;
     UINT32  ChildRelId;
-    UINT8   MonitorId;
+    u8   MonitorId;
     BOOLEAN MonitorAllocated;
 } VMBUS_CHANNEL_OFFER_CHANNEL, *PVMBUS_CHANNEL_OFFER_CHANNEL;
 
--- a/drivers/staging/hv/include/HvSynicApi.h
+++ b/drivers/staging/hv/include/HvSynicApi.h
@@ -264,11 +264,11 @@ typedef const HV_CONNECTION_INFO *PCHV_C
 
 typedef union _HV_MESSAGE_FLAGS
 {
-    UINT8 AsUINT8;
+    u8 Asu8;
     struct
     {
-        UINT8 MessagePending:1;
-        UINT8 Reserved:7;
+        u8 MessagePending:1;
+        u8 Reserved:7;
     };
 } HV_MESSAGE_FLAGS, *PHV_MESSAGE_FLAGS;
 
@@ -280,9 +280,9 @@ typedef union _HV_MESSAGE_FLAGS
 typedef struct _HV_MESSAGE_HEADER
 {
     HV_MESSAGE_TYPE     MessageType;
-    UINT8               PayloadSize;
+    u8               PayloadSize;
     HV_MESSAGE_FLAGS    MessageFlags;
-    UINT8               Reserved[2];
+    u8               Reserved[2];
     union
     {
         HV_PARTITION_ID Sender;
@@ -337,7 +337,7 @@ typedef struct _HV_MESSAGE_PAGE
 
 typedef union _HV_SYNIC_EVENT_FLAGS
 {
-    UINT8 Flags8[HV_EVENT_FLAGS_BYTE_COUNT];
+    u8 Flags8[HV_EVENT_FLAGS_BYTE_COUNT];
     UINT32 Flags32[HV_EVENT_FLAGS_DWORD_COUNT];
 } HV_SYNIC_EVENT_FLAGS, *PHV_SYNIC_EVENT_FLAGS;
 
@@ -483,7 +483,7 @@ typedef struct _HV_MONITOR_PAGE
 
     HV_MONITOR_PARAMETER     Parameter[4][32];
 
-    UINT8                    RsvdZ4[1984];
+    u8                    RsvdZ4[1984];
 
 } HV_MONITOR_PAGE, *PHV_MONITOR_PAGE;
 
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -97,7 +97,6 @@ typedef struct _DLIST_ENTRY {
 //
 // unsigned types
 //
-typedef unsigned char		UINT8;
 typedef unsigned short		UINT16;
 typedef unsigned int		UINT32;
 #ifdef __x86_64__
@@ -114,7 +113,6 @@ typedef unsigned char		UCHAR;
 //
 // signed types
 //
-typedef char				INT8;
 typedef short				INT16;
 typedef int					INT32;
 #ifdef __x86_64__
--- a/drivers/staging/hv/include/StorVscApi.h
+++ b/drivers/staging/hv/include/StorVscApi.h
@@ -75,7 +75,7 @@ typedef struct _STORVSC_REQUEST {
 	UINT32					Bus;
 	UINT32					TargetId;
 	UINT32					LunId;
-	UINT8*					Cdb;
+	u8 *					Cdb;
 	UINT32					CdbLen;
 	UINT32					Status;
 	UINT32					BytesXfer;
--- a/drivers/staging/hv/include/VmbusPacketFormat.h
+++ b/drivers/staging/hv/include/VmbusPacketFormat.h
@@ -65,14 +65,14 @@ typedef struct
             VMRCB Control;
         };
 
-        UINT8 Reserved[PAGE_SIZE];
+        u8 Reserved[PAGE_SIZE];
     };
 
     //
     // Beginning of the ring data.  Note: It must be guaranteed that
     // this data does not share a page with the control structure.
     //
-    UINT8 Data[1];
+    u8 Data[1];
 } VMRING, *PVMRING;
 
 #pragma pack(push, 1)
@@ -114,7 +114,7 @@ typedef struct VMTRANSFER_PAGE_PACKET_HE
 
     UINT16                  TransferPageSetId;
     BOOLEAN                 SenderOwnsSet;
-    UINT8                   Reserved;
+    u8                   Reserved;
     UINT32                  RangeCount;
     VMTRANSFER_PAGE_RANGE   Ranges[1];
 
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -22,6 +22,7 @@
 
 #define KERNEL_2_6_27
 
+#include <linux/kernel.h>
 #include "include/logging.h"
 #include "NetVsc.h"
 #include "RndisFilter.h"
--- a/drivers/staging/hv/RingBuffer.h
+++ b/drivers/staging/hv/RingBuffer.h
@@ -37,12 +37,12 @@ typedef struct _RING_BUFFER {
     volatile UINT32	ReadIndex;      // Offset in bytes from the start of ring data below
 
 	volatile UINT32 InterruptMask;
-	UINT8	Reserved[4084];			// Pad it to PAGE_SIZE so that data starts on page boundary
+	u8	Reserved[4084];			// Pad it to PAGE_SIZE so that data starts on page boundary
 	// NOTE: The InterruptMask field is used only for channels but since our vmbus connection
 	// also uses this data structure and its data starts here, we commented out this field.
 	// volatile UINT32 InterruptMask;
 	// Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
-    UINT8		Buffer[0];
+    u8		Buffer[0];
 } STRUCT_PACKED RING_BUFFER;
 
 typedef struct _RING_BUFFER_INFO {
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -23,6 +23,7 @@
 
 #define KERNEL_2_6_27
 
+#include <linux/kernel.h>
 #include "include/logging.h"
 
 #include "include/NetVscApi.h"
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -23,6 +23,7 @@
 
 #define KERNEL_2_6_27
 
+#include <linux/kernel.h>
 #include "include/logging.h"
 
 #include "include/StorVscApi.h"
--- a/drivers/staging/hv/Vmbus.c
+++ b/drivers/staging/hv/Vmbus.c
@@ -21,7 +21,7 @@
  *
  */
 
-
+#include <linux/kernel.h>
 #include "include/logging.h"
 #include "VersionInfo.h"
 #include "VmbusPrivate.h"

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 21/54] Staging: hv: remove UINT16 and INT16 typedefs
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (20 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-uint16-and-int16-typedefs.patch --]
[-- Type: text/plain, Size: 8647 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The UINT16 and INT16 typedefs are now removed from the Hyper-V driver
code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Channel.c                       |    6 +++---
 drivers/staging/hv/Channel.h                       |   16 ++++++++--------
 drivers/staging/hv/include/ChannelMessages.h       |    4 ++--
 drivers/staging/hv/include/HvHcApi.h               |    4 ++--
 drivers/staging/hv/include/HvStatus.h              |    2 +-
 drivers/staging/hv/include/HvSynicApi.h            |   10 +++++-----
 drivers/staging/hv/include/VmbusChannelInterface.h |    4 ++--
 drivers/staging/hv/include/VmbusPacketFormat.h     |   14 +++++++-------
 drivers/staging/hv/include/nvspprotocol.h          |    8 ++++----
 drivers/staging/hv/include/osd.h                   |    2 --
 10 files changed, 34 insertions(+), 36 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -777,7 +777,7 @@ VmbusChannelSendPacket(
 	desc.Type = Type;//VmbusPacketTypeDataInBand;
 	desc.Flags = Flags;//VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
     desc.DataOffset8 = sizeof(VMPACKET_DESCRIPTOR) >> 3; // in 8-bytes granularity
-    desc.Length8 = (UINT16)(packetLenAligned >> 3);
+    desc.Length8 = (u16)(packetLenAligned >> 3);
     desc.TransactionId = RequestId;
 
 	bufferList[0].Data = &desc;
@@ -851,7 +851,7 @@ VmbusChannelSendPacketPageBuffer(
 	desc.Type = VmbusPacketTypeDataUsingGpaDirect;
 	desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
     desc.DataOffset8 = descSize >> 3; // in 8-bytes grandularity
-    desc.Length8 = (UINT16)(packetLenAligned >> 3);
+    desc.Length8 = (u16)(packetLenAligned >> 3);
     desc.TransactionId = RequestId;
 	desc.RangeCount = PageCount;
 
@@ -936,7 +936,7 @@ VmbusChannelSendPacketMultiPageBuffer(
 	desc.Type = VmbusPacketTypeDataUsingGpaDirect;
 	desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
     desc.DataOffset8 = descSize >> 3; // in 8-bytes grandularity
-    desc.Length8 = (UINT16)(packetLenAligned >> 3);
+    desc.Length8 = (u16)(packetLenAligned >> 3);
     desc.TransactionId = RequestId;
 	desc.RangeCount = 1;
 
--- a/drivers/staging/hv/Channel.h
+++ b/drivers/staging/hv/Channel.h
@@ -33,10 +33,10 @@
 
 // The format must be the same as VMDATA_GPA_DIRECT
 typedef struct _VMBUS_CHANNEL_PACKET_PAGE_BUFFER {
-    UINT16				Type;
-    UINT16				DataOffset8;
-    UINT16				Length8;
-    UINT16				Flags;
+    u16				Type;
+    u16				DataOffset8;
+    u16				Length8;
+    u16				Flags;
     UINT64				TransactionId;
 	UINT32				Reserved;
 	UINT32				RangeCount;
@@ -46,10 +46,10 @@ typedef struct _VMBUS_CHANNEL_PACKET_PAG
 
 // The format must be the same as VMDATA_GPA_DIRECT
 typedef struct _VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER {
-    UINT16				Type;
-    UINT16				DataOffset8;
-    UINT16				Length8;
-    UINT16				Flags;
+    u16				Type;
+    u16				DataOffset8;
+    u16				Length8;
+    u16				Flags;
     UINT64				TransactionId;
 	UINT32				Reserved;
 	UINT32				RangeCount;		// Always 1 in this case
--- a/drivers/staging/hv/include/ChannelMessages.h
+++ b/drivers/staging/hv/include/ChannelMessages.h
@@ -188,8 +188,8 @@ typedef struct _VMBUS_CHANNEL_GPADL_HEAD
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
     UINT32      ChildRelId;
     UINT32      Gpadl;
-    UINT16      RangeBufLen;
-    UINT16      RangeCount;
+    u16      RangeBufLen;
+    u16      RangeCount;
     GPA_RANGE   Range[0];
 } VMBUS_CHANNEL_GPADL_HEADER, *PVMBUS_CHANNEL_GPADL_HEADER;
 
--- a/drivers/staging/hv/include/HvHcApi.h
+++ b/drivers/staging/hv/include/HvHcApi.h
@@ -55,6 +55,6 @@ typedef struct _HV_INPUT_POST_MESSAGE
 typedef struct _HV_INPUT_SIGNAL_EVENT
 {
     HV_CONNECTION_ID ConnectionId;
-    UINT16           FlagNumber;
-    UINT16           RsvdZ;
+    u16           FlagNumber;
+    u16           RsvdZ;
 } HV_INPUT_SIGNAL_EVENT, *PHV_INPUT_SIGNAL_EVENT;
--- a/drivers/staging/hv/include/HvStatus.h
+++ b/drivers/staging/hv/include/HvStatus.h
@@ -26,7 +26,7 @@
 //
 // Status codes for hypervisor operations.
 //
-typedef UINT16 HV_STATUS, *PHV_STATUS;
+typedef u16 HV_STATUS, *PHV_STATUS;
 
 //
 // MessageId: HV_STATUS_SUCCESS
--- a/drivers/staging/hv/include/HvSynicApi.h
+++ b/drivers/staging/hv/include/HvSynicApi.h
@@ -217,8 +217,8 @@ typedef struct _HV_PORT_INFO
         {
             HV_SYNIC_SINT_INDEX TargetSint;
             HV_VP_INDEX TargetVp;
-            UINT16 BaseFlagNumber;
-            UINT16 FlagCount;
+            u16 BaseFlagNumber;
+            u16 FlagCount;
             UINT32 RsvdZ;
         } EventPortInfo;
 
@@ -431,8 +431,8 @@ typedef union _HV_MONITOR_TRIGGER_GROUP
 typedef struct _HV_MONITOR_PARAMETER
 {
     HV_CONNECTION_ID    ConnectionId;
-    UINT16              FlagNumber;
-    UINT16              RsvdZ;
+    u16              FlagNumber;
+    u16              RsvdZ;
 } HV_MONITOR_PARAMETER, *PHV_MONITOR_PARAMETER;
 
 typedef union _HV_MONITOR_TRIGGER_STATE
@@ -478,7 +478,7 @@ typedef struct _HV_MONITOR_PAGE
 
     INT32                    NextCheckTime[4][32];
 
-    UINT16                   Latency[4][32];
+    u16                   Latency[4][32];
     UINT64                   RsvdZ3[32];
 
     HV_MONITOR_PARAMETER     Parameter[4][32];
--- a/drivers/staging/hv/include/nvspprotocol.h
+++ b/drivers/staging/hv/include/nvspprotocol.h
@@ -144,7 +144,7 @@ typedef struct _NVSP_1_MESSAGE_SEND_NDIS
 typedef struct _NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER
 {
     GPADL_HANDLE                            GpadlHandle;
-    UINT16                                  Id;
+    u16                                  Id;
 } NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER, *PNVSP_1_MESSAGE_SEND_RECEIVE_BUFFER;
 
 typedef struct _NVSP_1_RECEIVE_BUFFER_SECTION
@@ -192,7 +192,7 @@ typedef struct _NVSP_1_MESSAGE_SEND_RECE
 //
 typedef struct _NVSP_1_MESSAGE_REVOKE_RECEIVE_BUFFER
 {
-    UINT16                                  Id;
+    u16                                  Id;
 } NVSP_1_MESSAGE_REVOKE_RECEIVE_BUFFER, *PNVSP_1_MESSAGE_REVOKE_RECEIVE_BUFFER;
 
 //
@@ -203,7 +203,7 @@ typedef struct _NVSP_1_MESSAGE_REVOKE_RE
 typedef struct _NVSP_1_MESSAGE_SEND_SEND_BUFFER
 {
     GPADL_HANDLE                            GpadlHandle;
-    UINT16                                  Id;
+    u16                                  Id;
 } NVSP_1_MESSAGE_SEND_SEND_BUFFER, *PNVSP_1_MESSAGE_SEND_SEND_BUFFER;
 
 //
@@ -231,7 +231,7 @@ typedef struct _NVSP_1_MESSAGE_SEND_SEND
 //
 typedef struct _NVSP_1_MESSAGE_REVOKE_SEND_BUFFER
 {
-    UINT16                                  Id;
+    u16                                  Id;
 } NVSP_1_MESSAGE_REVOKE_SEND_BUFFER, *PNVSP_1_MESSAGE_REVOKE_SEND_BUFFER;
 
 //
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -97,7 +97,6 @@ typedef struct _DLIST_ENTRY {
 //
 // unsigned types
 //
-typedef unsigned short		UINT16;
 typedef unsigned int		UINT32;
 #ifdef __x86_64__
 typedef unsigned long		UINT64;
@@ -113,7 +112,6 @@ typedef unsigned char		UCHAR;
 //
 // signed types
 //
-typedef short				INT16;
 typedef int					INT32;
 #ifdef __x86_64__
 typedef long				INT64;
--- a/drivers/staging/hv/include/VmbusChannelInterface.h
+++ b/drivers/staging/hv/include/VmbusChannelInterface.h
@@ -69,8 +69,8 @@ typedef struct
     UINT64  InterruptLatencyIn100nsUnits;
     UINT32  InterfaceRevision;
     UINT32  ServerContextAreaSize;  // in bytes
-    UINT16  ChannelFlags;
-    UINT16  MmioMegabytes;          // in bytes * 1024 * 1024
+    u16  ChannelFlags;
+    u16  MmioMegabytes;          // in bytes * 1024 * 1024
 
     union
     {
--- a/drivers/staging/hv/include/VmbusPacketFormat.h
+++ b/drivers/staging/hv/include/VmbusPacketFormat.h
@@ -79,10 +79,10 @@ typedef struct
 
 typedef struct
 {
-    UINT16 Type;
-    UINT16 DataOffset8;
-    UINT16 Length8;
-    UINT16 Flags;
+    u16 Type;
+    u16 DataOffset8;
+    u16 Length8;
+    u16 Flags;
     UINT64 TransactionId;
 } VMPACKET_DESCRIPTOR, *PVMPACKET_DESCRIPTOR;
 
@@ -112,7 +112,7 @@ typedef struct VMTRANSFER_PAGE_PACKET_HE
 
 #endif
 
-    UINT16                  TransferPageSetId;
+    u16                  TransferPageSetId;
     BOOLEAN                 SenderOwnsSet;
     u8                   Reserved;
     UINT32                  RangeCount;
@@ -152,8 +152,8 @@ typedef struct _VMADD_REMOVE_TRANSFER_PA
 #endif
 
     UINT32  Gpadl;
-    UINT16  TransferPageSetId;
-    UINT16  Reserved;
+    u16  TransferPageSetId;
+    u16  Reserved;
 
 } VMADD_REMOVE_TRANSFER_PAGE_SET, *PVMADD_REMOVE_TRANSFER_PAGE_SET;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 22/54] Staging: hv: remove UINT32 and INT32 typedefs
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (21 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-uint32-and-int32-typedefs.patch --]
[-- Type: text/plain, Size: 78469 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The UINT32 and INT32 typedefs are now removed from the Hyper-V driver
code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Channel.c                       |   90 +++++------
 drivers/staging/hv/Channel.h                       |   38 ++--
 drivers/staging/hv/ChannelInterface.c              |   32 +--
 drivers/staging/hv/ChannelMgmt.h                   |   22 +-
 drivers/staging/hv/Connection.c                    |   14 -
 drivers/staging/hv/Hv.c                            |   20 +-
 drivers/staging/hv/Hv.h                            |    2 
 drivers/staging/hv/NetVsc.c                        |    2 
 drivers/staging/hv/NetVsc.h                        |   12 -
 drivers/staging/hv/RingBuffer.c                    |   96 +++++------
 drivers/staging/hv/RingBuffer.h                    |   38 ++--
 drivers/staging/hv/RndisFilter.c                   |   40 ++--
 drivers/staging/hv/StorVsc.c                       |    2 
 drivers/staging/hv/Vmbus.c                         |    2 
 drivers/staging/hv/VmbusPrivate.h                  |    6 
 drivers/staging/hv/include/ChannelMessages.h       |   52 +++---
 drivers/staging/hv/include/HvHcApi.h               |    4 
 drivers/staging/hv/include/HvSynicApi.h            |   42 ++---
 drivers/staging/hv/include/HvVpApi.h               |    2 
 drivers/staging/hv/include/NetVscApi.h             |   14 -
 drivers/staging/hv/include/StorVscApi.h            |   22 +-
 drivers/staging/hv/include/VmbusApi.h              |   68 ++++----
 drivers/staging/hv/include/VmbusChannelInterface.h |   10 -
 drivers/staging/hv/include/VmbusPacketFormat.h     |   40 ++--
 drivers/staging/hv/include/nvspprotocol.h          |   42 ++---
 drivers/staging/hv/include/osd.h                   |   16 -
 drivers/staging/hv/include/rndis.h                 |  170 ++++++++++-----------
 drivers/staging/hv/osd.c                           |    4 
 28 files changed, 450 insertions(+), 452 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -33,9 +33,9 @@
 static int
 VmbusChannelCreateGpadlHeader(
 	void *					Kbuffer,	// must be phys and virt contiguous
-	UINT32					Size,		// page-size multiple
+	u32					Size,		// page-size multiple
 	VMBUS_CHANNEL_MSGINFO	**msgInfo,
-	UINT32					*MessageCount
+	u32					*MessageCount
 	);
 
 static void
@@ -77,7 +77,7 @@ DumpMonitorPage(
 	{
 		for (j=0; j<32; j++)
 		{
-			DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].ConnectionId.AsUINT32);
+			DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].ConnectionId.Asu32);
 			DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].FlagNumber);
 
 		}
@@ -105,13 +105,13 @@ VmbusChannelSetEvent(
 
 	if (Channel->OfferMsg.MonitorAllocated)
 	{
-		// Each UINT32 represents 32 channels
-		BitSet((UINT32*)gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5), Channel->OfferMsg.ChildRelId & 31);
+		// Each u32 represents 32 channels
+		BitSet((u32*)gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5), Channel->OfferMsg.ChildRelId & 31);
 
 		monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages;
 		monitorPage++; // Get the child to parent monitor page
 
-		BitSet((UINT32*) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending, Channel->MonitorBit);
+		BitSet((u32*) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending, Channel->MonitorBit);
 	}
 	else
 	{
@@ -133,13 +133,13 @@ VmbusChannelClearEvent(
 
 	if (Channel->OfferMsg.MonitorAllocated)
 	{
-		// Each UINT32 represents 32 channels
-		BitClear((UINT32*)gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5), Channel->OfferMsg.ChildRelId & 31);
+		// Each u32 represents 32 channels
+		BitClear((u32*)gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5), Channel->OfferMsg.ChildRelId & 31);
 
 		monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages;
 		monitorPage++; // Get the child to parent monitor page
 
-		BitClear((UINT32*) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending, Channel->MonitorBit);
+		BitClear((u32*) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending, Channel->MonitorBit);
 	}
 
 	DPRINT_EXIT(VMBUS);
@@ -164,7 +164,7 @@ VmbusChannelGetDebugInfo(
 	HV_MONITOR_PAGE *monitorPage;
     u8 monitorGroup    = (u8)Channel->OfferMsg.MonitorId / 32;
     u8 monitorOffset   = (u8)Channel->OfferMsg.MonitorId % 32;
-	//UINT32 monitorBit	= 1 << monitorOffset;
+	//u32 monitorBit	= 1 << monitorOffset;
 
 	DebugInfo->RelId = Channel->OfferMsg.ChildRelId;
 	DebugInfo->State = Channel->State;
@@ -202,10 +202,10 @@ Description:
 int
 VmbusChannelOpen(
 	VMBUS_CHANNEL			*NewChannel,
-	UINT32					SendRingBufferSize,
-	UINT32					RecvRingBufferSize,
+	u32					SendRingBufferSize,
+	u32					RecvRingBufferSize,
 	void *					UserData,
-	UINT32					UserDataLen,
+	u32					UserDataLen,
 	PFN_CHANNEL_CALLBACK	pfnOnChannelCallback,
 	void *					Context
 	)
@@ -330,7 +330,7 @@ Description:
 --*/
 static void DumpGpadlBody(
 	VMBUS_CHANNEL_GPADL_BODY	*Gpadl,
-	UINT32						Len)
+	u32						Len)
 {
 	int i=0;
 	int pfnCount=0;
@@ -393,9 +393,9 @@ Description:
 static int
 VmbusChannelCreateGpadlHeader(
 	void *					Kbuffer,	// from kmalloc()
-	UINT32					Size,		// page-size multiple
+	u32					Size,		// page-size multiple
 	VMBUS_CHANNEL_MSGINFO	**MsgInfo,
-	UINT32					*MessageCount)
+	u32					*MessageCount)
 {
 	int i;
 	int pageCount;
@@ -404,7 +404,7 @@ VmbusChannelCreateGpadlHeader(
 	VMBUS_CHANNEL_GPADL_BODY* gpadlBody;
 	VMBUS_CHANNEL_MSGINFO* msgHeader;
 	VMBUS_CHANNEL_MSGINFO* msgBody;
-	UINT32				msgSize;
+	u32				msgSize;
 
 	int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize;
 
@@ -465,7 +465,7 @@ VmbusChannelCreateGpadlHeader(
 			(*MessageCount)++;
 			gpadlBody = (VMBUS_CHANNEL_GPADL_BODY*)msgBody->Msg;
 
-			// FIXME: Gpadl is UINT32 and we are using a pointer which could be 64-bit
+			// FIXME: Gpadl is u32 and we are using a pointer which could be 64-bit
 			//gpadlBody->Gpadl = kbuffer;
 			for (i=0; i<pfnCurr; i++)
 			{
@@ -516,8 +516,8 @@ int
 VmbusChannelEstablishGpadl(
 	VMBUS_CHANNEL	*Channel,
 	void *			Kbuffer,	// from kmalloc()
-	UINT32			Size,		// page-size multiple
-	UINT32			*GpadlHandle
+	u32			Size,		// page-size multiple
+	u32			*GpadlHandle
 	)
 {
 	int ret=0;
@@ -528,10 +528,10 @@ VmbusChannelEstablishGpadl(
 	VMBUS_CHANNEL_MSGINFO *msgInfo;
 	VMBUS_CHANNEL_MSGINFO *subMsgInfo;
 
-	UINT32 msgCount;
+	u32 msgCount;
 	LIST_ENTRY* anchor;
 	LIST_ENTRY* curr;
-	UINT32 nextGpadlHandle;
+	u32 nextGpadlHandle;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -619,7 +619,7 @@ Description:
 int
 VmbusChannelTeardownGpadl(
 	VMBUS_CHANNEL	*Channel,
-	UINT32			GpadlHandle
+	u32			GpadlHandle
 	)
 {
 	int ret=0;
@@ -753,16 +753,16 @@ int
 VmbusChannelSendPacket(
 	VMBUS_CHANNEL		*Channel,
 	const void *			Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId,
 	VMBUS_PACKET_TYPE	Type,
-	UINT32				Flags
+	u32				Flags
 )
 {
 	int ret=0;
 	VMPACKET_DESCRIPTOR desc;
-	UINT32 packetLen = sizeof(VMPACKET_DESCRIPTOR) + BufferLen;
-	UINT32 packetLenAligned = ALIGN_UP(packetLen, sizeof(UINT64));
+	u32 packetLen = sizeof(VMPACKET_DESCRIPTOR) + BufferLen;
+	u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(UINT64));
 	SG_BUFFER_LIST bufferList[3];
 	UINT64 alignedData=0;
 
@@ -819,18 +819,18 @@ int
 VmbusChannelSendPacketPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	PAGE_BUFFER			PageBuffers[],
-	UINT32				PageCount,
+	u32				PageCount,
 	void *				Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId
 )
 {
 	int ret=0;
 	int i=0;
 	VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc;
-	UINT32 descSize;
-	UINT32 packetLen;
-	UINT32 packetLenAligned;
+	u32 descSize;
+	u32 packetLen;
+	u32 packetLenAligned;
 	SG_BUFFER_LIST bufferList[3];
 	UINT64 alignedData=0;
 
@@ -903,18 +903,18 @@ VmbusChannelSendPacketMultiPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
 	void *				Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId
 )
 {
 	int ret=0;
 	VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc;
-	UINT32 descSize;
-	UINT32 packetLen;
-	UINT32 packetLenAligned;
+	u32 descSize;
+	u32 packetLen;
+	u32 packetLenAligned;
 	SG_BUFFER_LIST bufferList[3];
 	UINT64 alignedData=0;
-	UINT32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length);
+	u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length);
 
 	DPRINT_ENTER(VMBUS);
 
@@ -985,14 +985,14 @@ int
 VmbusChannelRecvPacket(
 	VMBUS_CHANNEL		*Channel,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				BufferActualLen,
+	u32				BufferLen,
+	u32*				BufferActualLen,
 	UINT64*				RequestId
 	)
 {
 	VMPACKET_DESCRIPTOR desc;
-	UINT32 packetLen;
-	UINT32 userLen;
+	u32 packetLen;
+	u32 userLen;
 	int ret;
 
 	DPRINT_ENTER(VMBUS);
@@ -1062,14 +1062,14 @@ int
 VmbusChannelRecvPacketRaw(
 	VMBUS_CHANNEL		*Channel,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				BufferActualLen,
+	u32				BufferLen,
+	u32*				BufferActualLen,
 	UINT64*				RequestId
 	)
 {
 	VMPACKET_DESCRIPTOR desc;
-	UINT32 packetLen;
-	UINT32 userLen;
+	u32 packetLen;
+	u32 userLen;
 	int ret;
 
 	DPRINT_ENTER(VMBUS);
--- a/drivers/staging/hv/Channel.h
+++ b/drivers/staging/hv/Channel.h
@@ -38,8 +38,8 @@ typedef struct _VMBUS_CHANNEL_PACKET_PAG
     u16				Length8;
     u16				Flags;
     UINT64				TransactionId;
-	UINT32				Reserved;
-	UINT32				RangeCount;
+	u32				Reserved;
+	u32				RangeCount;
     PAGE_BUFFER			Range[MAX_PAGE_BUFFER_COUNT];
 } VMBUS_CHANNEL_PACKET_PAGE_BUFFER;
 
@@ -51,8 +51,8 @@ typedef struct _VMBUS_CHANNEL_PACKET_MUL
     u16				Length8;
     u16				Flags;
     UINT64				TransactionId;
-	UINT32				Reserved;
-	UINT32				RangeCount;		// Always 1 in this case
+	u32				Reserved;
+	u32				RangeCount;		// Always 1 in this case
 	MULTIPAGE_BUFFER	Range;
 } VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER;
 
@@ -65,10 +65,10 @@ typedef struct _VMBUS_CHANNEL_PACKET_MUL
 static int
 VmbusChannelOpen(
 	VMBUS_CHANNEL			*Channel,
-	UINT32					SendRingBufferSize,
-	UINT32					RecvRingBufferSize,
+	u32					SendRingBufferSize,
+	u32					RecvRingBufferSize,
 	void *					UserData,
-	UINT32					UserDataLen,
+	u32					UserDataLen,
 	PFN_CHANNEL_CALLBACK	pfnOnChannelCallback,
 	void *					Context
 	);
@@ -82,19 +82,19 @@ static int
 VmbusChannelSendPacket(
 	VMBUS_CHANNEL		*Channel,
 	const void *			Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId,
 	VMBUS_PACKET_TYPE	Type,
-	UINT32				Flags
+	u32				Flags
 );
 
 static int
 VmbusChannelSendPacketPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	PAGE_BUFFER			PageBuffers[],
-	UINT32				PageCount,
+	u32				PageCount,
 	void *				Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId
 	);
 
@@ -103,7 +103,7 @@ VmbusChannelSendPacketMultiPageBuffer(
 	VMBUS_CHANNEL		*Channel,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
 	void *				Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId
 );
 
@@ -111,22 +111,22 @@ static int
 VmbusChannelEstablishGpadl(
 	VMBUS_CHANNEL		*Channel,
 	void *				Kbuffer,	// from kmalloc()
-	UINT32				Size,		// page-size multiple
-	UINT32				*GpadlHandle
+	u32				Size,		// page-size multiple
+	u32				*GpadlHandle
 	);
 
 static int
 VmbusChannelTeardownGpadl(
 	VMBUS_CHANNEL	*Channel,
-	UINT32			GpadlHandle
+	u32			GpadlHandle
 	);
 
 static int
 VmbusChannelRecvPacket(
 	VMBUS_CHANNEL		*Channel,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				BufferActualLen,
+	u32				BufferLen,
+	u32*				BufferActualLen,
 	UINT64*				RequestId
 	);
 
@@ -134,8 +134,8 @@ static int
 VmbusChannelRecvPacketRaw(
 	VMBUS_CHANNEL		*Channel,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				BufferActualLen,
+	u32				BufferLen,
+	u32*				BufferActualLen,
 	UINT64*				RequestId
 	);
 
--- a/drivers/staging/hv/ChannelInterface.c
+++ b/drivers/staging/hv/ChannelInterface.c
@@ -26,10 +26,10 @@
 static int
 IVmbusChannelOpen(
 	PDEVICE_OBJECT		Device,
-	UINT32				SendBufferSize,
-	UINT32				RecvRingBufferSize,
+	u32				SendBufferSize,
+	u32				RecvRingBufferSize,
 	void *				UserData,
-	UINT32				UserDataLen,
+	u32				UserDataLen,
 	VMBUS_CHANNEL_CALLBACK ChannelCallback,
 	void *				Context
 	)
@@ -57,10 +57,10 @@ static int
 IVmbusChannelSendPacket(
 	PDEVICE_OBJECT		Device,
 	const void *			Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId,
-	UINT32				Type,
-	UINT32				Flags
+	u32				Type,
+	u32				Flags
 	)
 {
 	return VmbusChannelSendPacket((VMBUS_CHANNEL*)Device->context,
@@ -75,9 +75,9 @@ static int
 IVmbusChannelSendPacketPageBuffer(
 	PDEVICE_OBJECT		Device,
 	PAGE_BUFFER			PageBuffers[],
-	UINT32				PageCount,
+	u32				PageCount,
 	void *				Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId
 	)
 {
@@ -94,7 +94,7 @@ IVmbusChannelSendPacketMultiPageBuffer(
 	PDEVICE_OBJECT		Device,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
 	void *				Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId
 	)
 {
@@ -109,8 +109,8 @@ static int
 IVmbusChannelRecvPacket (
 	PDEVICE_OBJECT		Device,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				BufferActualLen,
+	u32				BufferLen,
+	u32*				BufferActualLen,
 	UINT64*				RequestId
 	)
 {
@@ -125,8 +125,8 @@ static int
 IVmbusChannelRecvPacketRaw(
 	PDEVICE_OBJECT		Device,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				BufferActualLen,
+	u32				BufferLen,
+	u32*				BufferActualLen,
 	UINT64*				RequestId
 	)
 {
@@ -141,8 +141,8 @@ static int
 IVmbusChannelEstablishGpadl(
 	PDEVICE_OBJECT		Device,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				GpadlHandle
+	u32				BufferLen,
+	u32*				GpadlHandle
 	)
 {
 	return VmbusChannelEstablishGpadl((VMBUS_CHANNEL*)Device->context,
@@ -154,7 +154,7 @@ IVmbusChannelEstablishGpadl(
 static int
 IVmbusChannelTeardownGpadl(
    PDEVICE_OBJECT		Device,
-   UINT32				GpadlHandle
+   u32				GpadlHandle
 	)
 {
 	return VmbusChannelTeardownGpadl((VMBUS_CHANNEL*)Device->context,
--- a/drivers/staging/hv/ChannelMgmt.h
+++ b/drivers/staging/hv/ChannelMgmt.h
@@ -56,11 +56,11 @@ typedef struct _VMBUS_CHANNEL {
 	u8						MonitorGroup;
 	u8						MonitorBit;
 
-	UINT32						RingBufferGpadlHandle;
+	u32						RingBufferGpadlHandle;
 
 	// Allocated memory for ring buffer
 	void *						RingBufferPages;
-	UINT32						RingBufferPageCount;
+	u32						RingBufferPageCount;
 	RING_BUFFER_INFO			Outbound;	// send to parent
 	RING_BUFFER_INFO			Inbound;	// receive from parent
 	HANDLE						InboundLock;
@@ -76,17 +76,17 @@ typedef struct _VMBUS_CHANNEL {
 
 
 typedef struct _VMBUS_CHANNEL_DEBUG_INFO {
-	UINT32						RelId;
+	u32						RelId;
 	VMBUS_CHANNEL_STATE			State;
 	GUID						InterfaceType;
     GUID						InterfaceInstance;
-	UINT32						MonitorId;
-	UINT32						ServerMonitorPending;
-	UINT32						ServerMonitorLatency;
-	UINT32						ServerMonitorConnectionId;
-	UINT32						ClientMonitorPending;
-	UINT32						ClientMonitorLatency;
-	UINT32						ClientMonitorConnectionId;
+	u32						MonitorId;
+	u32						ServerMonitorPending;
+	u32						ServerMonitorLatency;
+	u32						ServerMonitorConnectionId;
+	u32						ClientMonitorPending;
+	u32						ClientMonitorLatency;
+	u32						ClientMonitorConnectionId;
 
 	RING_BUFFER_DEBUG_INFO		Inbound;
 	RING_BUFFER_DEBUG_INFO		Outbound;
@@ -117,7 +117,7 @@ typedef struct _VMBUS_CHANNEL_MSGINFO {
 
 	VMBUS_CHANNEL_MESSAGE_RESPONSE Response;
 
-	UINT32			MessageSize;
+	u32			MessageSize;
 	// The channel message that goes out on the "wire".
 	// It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
 	unsigned char	Msg[0];
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -253,7 +253,7 @@ Description:
 --*/
 VMBUS_CHANNEL*
 GetChannelFromRelId(
-	UINT32 relId
+	u32 relId
 	)
 {
 	VMBUS_CHANNEL* channel;
@@ -294,7 +294,7 @@ VmbusProcessChannelEvent(
 	)
 {
 	VMBUS_CHANNEL* channel;
-	UINT32 relId = (UINT32)(ULONG_PTR)context;
+	u32 relId = (u32)(ULONG_PTR)context;
 
 	ASSERT(relId > 0);
 
@@ -333,7 +333,7 @@ VmbusOnEvents(
 	int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5;
 	int bit;
 	int relid;
-	UINT32* recvInterruptPage = gVmbusConnection.RecvInterruptPage;
+	u32* recvInterruptPage = gVmbusConnection.RecvInterruptPage;
 	//VMBUS_CHANNEL_MESSAGE* receiveMsg;
 
 	DPRINT_ENTER(VMBUS);
@@ -393,7 +393,7 @@ VmbusPostMessage(
 	HV_CONNECTION_ID connId;
 
 
-	connId.AsUINT32 =0;
+	connId.Asu32 =0;
 	connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID;
 	ret = HvPostMessage(
 			connId,
@@ -414,14 +414,14 @@ Description:
 
 --*/
 int
-VmbusSetEvent(UINT32 childRelId)
+VmbusSetEvent(u32 childRelId)
 {
 	int ret=0;
 
 	DPRINT_ENTER(VMBUS);
 
-	// Each UINT32 represents 32 channels
-	BitSet((UINT32*)gVmbusConnection.SendInterruptPage + (childRelId >> 5), childRelId & 31);
+	// Each u32 represents 32 channels
+	BitSet((u32*)gVmbusConnection.SendInterruptPage + (childRelId >> 5), childRelId & 31);
 	ret = HvSignalEvent();
 
 	DPRINT_EXIT(VMBUS);
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -188,16 +188,16 @@ HvDoHypercall (
 
 #else
 
-    UINT32 controlHi = Control >> 32;
-    UINT32 controlLo = Control & 0xFFFFFFFF;
-    UINT32 hvStatusHi = 1;
-    UINT32 hvStatusLo = 1;
+    u32 controlHi = Control >> 32;
+    u32 controlLo = Control & 0xFFFFFFFF;
+    u32 hvStatusHi = 1;
+    u32 hvStatusLo = 1;
     UINT64 inputAddress = (Input) ? GetPhysicalAddress(Input) : 0;
-    UINT32 inputAddressHi = inputAddress >> 32;
-    UINT32 inputAddressLo = inputAddress & 0xFFFFFFFF;
+    u32 inputAddressHi = inputAddress >> 32;
+    u32 inputAddressLo = inputAddress & 0xFFFFFFFF;
 	UINT64 outputAddress = (Output) ?GetPhysicalAddress(Output) : 0;
-    UINT32 outputAddressHi = outputAddress >> 32;
-    UINT32 outputAddressLo = outputAddress & 0xFFFFFFFF;
+    u32 outputAddressHi = outputAddress >> 32;
+    u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
     volatile void* hypercallPage = gHvContext.HypercallPage;
 
     DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
@@ -312,7 +312,7 @@ HvInit (
 	}
 
 	gHvContext.SignalEventParam = (PHV_INPUT_SIGNAL_EVENT)(ALIGN_UP((ULONG_PTR)gHvContext.SignalEventBuffer, HV_HYPERCALL_PARAM_ALIGN));
-	gHvContext.SignalEventParam->ConnectionId.AsUINT32 = 0;
+	gHvContext.SignalEventParam->ConnectionId.Asu32 = 0;
 	gHvContext.SignalEventParam->ConnectionId.u.Id = VMBUS_EVENT_CONNECTION_ID;
 	gHvContext.SignalEventParam->FlagNumber = 0;
 	gHvContext.SignalEventParam->RsvdZ = 0;
@@ -471,7 +471,7 @@ Description:
 --*/
 int
 HvSynicInit (
-	UINT32 irqVector
+	u32 irqVector
 	)
 {
 	UINT64			version;
--- a/drivers/staging/hv/Hv.h
+++ b/drivers/staging/hv/Hv.h
@@ -173,7 +173,7 @@ HvSignalEvent(
 
 static int
 HvSynicInit(
-	UINT32		irqVector
+	u32		irqVector
 	);
 
 static void
--- a/drivers/staging/hv/include/ChannelMessages.h
+++ b/drivers/staging/hv/include/ChannelMessages.h
@@ -27,7 +27,7 @@
 #include "VmbusPacketFormat.h"
 
 #define C_ASSERT(x)
-typedef UINT32 NTSTATUS;
+typedef u32 NTSTATUS;
 
 #pragma pack(push,1)
 
@@ -68,14 +68,14 @@ typedef enum _VMBUS_CHANNEL_MESSAGE_TYPE
 typedef struct _VMBUS_CHANNEL_MESSAGE_HEADER
 {
     VMBUS_CHANNEL_MESSAGE_TYPE  MessageType;
-    UINT32                      Padding;
+    u32                      Padding;
 } VMBUS_CHANNEL_MESSAGE_HEADER, *PVMBUS_CHANNEL_MESSAGE_HEADER;
 
 // Query VMBus Version parameters
 typedef struct _VMBUS_CHANNEL_QUERY_VMBUS_VERSION
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32 Version;
+    u32 Version;
 } VMBUS_CHANNEL_QUERY_VMBUS_VERSION, *PVMBUS_CHANNEL_QUERY_VMBUS_VERSION;
 
 // VMBus Version Supported parameters
@@ -90,7 +90,7 @@ typedef struct _VMBUS_CHANNEL_OFFER_CHAN
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
     VMBUS_CHANNEL_OFFER Offer;
-    UINT32  ChildRelId;
+    u32  ChildRelId;
     u8   MonitorId;
     BOOLEAN MonitorAllocated;
 } VMBUS_CHANNEL_OFFER_CHANNEL, *PVMBUS_CHANNEL_OFFER_CHANNEL;
@@ -104,7 +104,7 @@ C_ASSERT(sizeof(VMBUS_CHANNEL_OFFER_CHAN
 typedef struct _VMBUS_CHANNEL_RESCIND_OFFER
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32          ChildRelId;
+    u32          ChildRelId;
 } VMBUS_CHANNEL_RESCIND_OFFER, *PVMBUS_CHANNEL_RESCIND_OFFER;
 
 // Request Offer -- no parameters, SynIC message contains the partition ID
@@ -121,12 +121,12 @@ typedef struct _VMBUS_CHANNEL_OPEN_CHANN
     //
     // Identifies the specific VMBus channel that is being opened.
     //
-    UINT32          ChildRelId;
+    u32          ChildRelId;
 
     //
     // ID making a particular open request at a channel offer unique.
     //
-    UINT32          OpenId;
+    u32          OpenId;
 
     //
     // GPADL for the channel's ring buffer.
@@ -143,7 +143,7 @@ typedef struct _VMBUS_CHANNEL_OPEN_CHANN
     // by RingBufferGpadlHandle. The downstream ring buffer follows it at this
     // offset (in pages).
     //
-    UINT32          DownstreamRingBufferPageOffset;
+    u32          DownstreamRingBufferPageOffset;
 
     //
     // User-specific data to be passed along to the server endpoint.
@@ -159,8 +159,8 @@ typedef VMBUS_CHANNEL_OPEN_CHANNEL VMBUS
 typedef struct _VMBUS_CHANNEL_OPEN_RESULT
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32      ChildRelId;
-    UINT32      OpenId;
+    u32      ChildRelId;
+    u32      OpenId;
     NTSTATUS    Status;
 } VMBUS_CHANNEL_OPEN_RESULT, *PVMBUS_CHANNEL_OPEN_RESULT;
 
@@ -168,7 +168,7 @@ typedef struct _VMBUS_CHANNEL_OPEN_RESUL
 typedef struct _VMBUS_CHANNEL_CLOSE_CHANNEL
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32      ChildRelId;
+    u32      ChildRelId;
 } VMBUS_CHANNEL_CLOSE_CHANNEL, *PVMBUS_CHANNEL_CLOSE_CHANNEL;
 
 // Channel Message GPADL
@@ -186,8 +186,8 @@ typedef struct _VMBUS_CHANNEL_CLOSE_CHAN
 typedef struct _VMBUS_CHANNEL_GPADL_HEADER
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32      ChildRelId;
-    UINT32      Gpadl;
+    u32      ChildRelId;
+    u32      Gpadl;
     u16      RangeBufLen;
     u16      RangeCount;
     GPA_RANGE   Range[0];
@@ -201,8 +201,8 @@ typedef struct _VMBUS_CHANNEL_GPADL_HEAD
 typedef struct _VMBUS_CHANNEL_GPADL_BODY
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32              MessageNumber;
-    UINT32              Gpadl;
+    u32              MessageNumber;
+    u32              Gpadl;
     UINT64              Pfn[0];
 } VMBUS_CHANNEL_GPADL_BODY, *PVMBUS_CHANNEL_GPADL_BODY;
 
@@ -210,22 +210,22 @@ typedef struct _VMBUS_CHANNEL_GPADL_BODY
 typedef struct _VMBUS_CHANNEL_GPADL_CREATED
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32              ChildRelId;
-    UINT32              Gpadl;
-    UINT32              CreationStatus;
+    u32              ChildRelId;
+    u32              Gpadl;
+    u32              CreationStatus;
 } VMBUS_CHANNEL_GPADL_CREATED, *PVMBUS_CHANNEL_GPADL_CREATED;
 
 typedef struct _VMBUS_CHANNEL_GPADL_TEARDOWN
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32              ChildRelId;
-    UINT32              Gpadl;
+    u32              ChildRelId;
+    u32              Gpadl;
 } VMBUS_CHANNEL_GPADL_TEARDOWN, *PVMBUS_CHANNEL_GPADL_TEARDOWN;
 
 typedef struct _VMBUS_CHANNEL_GPADL_TORNDOWN
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32              Gpadl;
+    u32              Gpadl;
 } VMBUS_CHANNEL_GPADL_TORNDOWN, *PVMBUS_CHANNEL_GPADL_TORNDOWN;
 
 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
@@ -234,28 +234,28 @@ typedef struct _VMBUS_CHANNEL_VIEW_RANGE
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
     PHYSICAL_ADDRESS    ViewRangeBase;
     UINT64              ViewRangeLength;
-    UINT32              ChildRelId;
+    u32              ChildRelId;
 } VMBUS_CHANNEL_VIEW_RANGE_ADD, *PVMBUS_CHANNEL_VIEW_RANGE_ADD;
 
 typedef struct _VMBUS_CHANNEL_VIEW_RANGE_REMOVE
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
     PHYSICAL_ADDRESS    ViewRangeBase;
-    UINT32              ChildRelId;
+    u32              ChildRelId;
 } VMBUS_CHANNEL_VIEW_RANGE_REMOVE, *PVMBUS_CHANNEL_VIEW_RANGE_REMOVE;
 #endif
 
 typedef struct _VMBUS_CHANNEL_RELID_RELEASED
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32              ChildRelId;
+    u32              ChildRelId;
 } VMBUS_CHANNEL_RELID_RELEASED, *PVMBUS_CHANNEL_RELID_RELEASED;
 
 typedef struct _VMBUS_CHANNEL_INITIATE_CONTACT
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    UINT32              VMBusVersionRequested;
-    UINT32              Padding2;
+    u32              VMBusVersionRequested;
+    u32              Padding2;
     UINT64              InterruptPage;
     UINT64              MonitorPage1;
     UINT64              MonitorPage2;
--- a/drivers/staging/hv/include/HvHcApi.h
+++ b/drivers/staging/hv/include/HvHcApi.h
@@ -41,9 +41,9 @@ typedef enum _HV_CALL_CODE
 typedef struct _HV_INPUT_POST_MESSAGE
 {
     HV_CONNECTION_ID    ConnectionId;
-    UINT32              Reserved;
+    u32              Reserved;
     HV_MESSAGE_TYPE     MessageType;
-    UINT32              PayloadSize;
+    u32              PayloadSize;
     UINT64              Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
 } HV_INPUT_POST_MESSAGE, *PHV_INPUT_POST_MESSAGE;
 
--- a/drivers/staging/hv/include/HvSynicApi.h
+++ b/drivers/staging/hv/include/HvSynicApi.h
@@ -84,7 +84,7 @@
 
 #define HV_EVENT_FLAGS_COUNT        (256 * 8)
 #define HV_EVENT_FLAGS_BYTE_COUNT   (256)
-#define HV_EVENT_FLAGS_DWORD_COUNT  (256 / sizeof(UINT32))
+#define HV_EVENT_FLAGS_DWORD_COUNT  (256 / sizeof(u32))
 
 //
 // Define hypervisor message types.
@@ -139,7 +139,7 @@ typedef enum _HV_MESSAGE_TYPE
 // Define the synthetic interrupt source index type.
 //
 
-typedef UINT32 HV_SYNIC_SINT_INDEX, *PHV_SYNIC_SINT_INDEX;
+typedef u32 HV_SYNIC_SINT_INDEX, *PHV_SYNIC_SINT_INDEX;
 
 //
 // Define partition identifier type.
@@ -158,12 +158,12 @@ typedef UINT64 HV_PARTITION_ID, *PHV_PAR
 
 typedef union _HV_CONNECTION_ID
 {
-    UINT32 AsUINT32;
+    u32 Asu32;
 
     struct
     {
-        UINT32 Id:24;
-        UINT32 Reserved:8;
+        u32 Id:24;
+        u32 Reserved:8;
     } u;
 
 } HV_CONNECTION_ID, *PHV_CONNECTION_ID;
@@ -174,12 +174,12 @@ typedef union _HV_CONNECTION_ID
 
 typedef union _HV_PORT_ID
 {
-    UINT32 AsUINT32;
+    u32 Asu32;
 
     struct
     {
-        UINT32 Id:24;
-        UINT32 Reserved:8;
+        u32 Id:24;
+        u32 Reserved:8;
     } u ;
 
 } HV_PORT_ID, *PHV_PORT_ID;
@@ -202,7 +202,7 @@ typedef enum _HV_PORT_TYPE
 typedef struct _HV_PORT_INFO
 {
     HV_PORT_TYPE PortType;
-    UINT32 Padding;
+    u32 Padding;
 
     union
     {
@@ -219,7 +219,7 @@ typedef struct _HV_PORT_INFO
             HV_VP_INDEX TargetVp;
             u16 BaseFlagNumber;
             u16 FlagCount;
-            UINT32 RsvdZ;
+            u32 RsvdZ;
         } EventPortInfo;
 
         struct
@@ -235,7 +235,7 @@ typedef const HV_PORT_INFO *PCHV_PORT_IN
 typedef struct _HV_CONNECTION_INFO
 {
     HV_PORT_TYPE PortType;
-    UINT32 Padding;
+    u32 Padding;
 
     union
     {
@@ -296,8 +296,8 @@ typedef struct _HV_MESSAGE_HEADER
 //
 typedef struct _HV_TIMER_MESSAGE_PAYLOAD
 {
-    UINT32          TimerIndex;
-    UINT32          Reserved;
+    u32          TimerIndex;
+    u32          Reserved;
     HV_NANO100_TIME ExpirationTime;     // When the timer expired
     HV_NANO100_TIME DeliveryTime;       // When the message was delivered
 } HV_TIMER_MESSAGE_PAYLOAD, *PHV_TIMER_MESSAGE_PAYLOAD;
@@ -338,7 +338,7 @@ typedef struct _HV_MESSAGE_PAGE
 typedef union _HV_SYNIC_EVENT_FLAGS
 {
     u8 Flags8[HV_EVENT_FLAGS_BYTE_COUNT];
-    UINT32 Flags32[HV_EVENT_FLAGS_DWORD_COUNT];
+    u32 Flags32[HV_EVENT_FLAGS_DWORD_COUNT];
 } HV_SYNIC_EVENT_FLAGS, *PHV_SYNIC_EVENT_FLAGS;
 
 
@@ -422,8 +422,8 @@ typedef union _HV_MONITOR_TRIGGER_GROUP
 
     struct
     {
-        UINT32 Pending;
-        UINT32 Armed;
+        u32 Pending;
+        u32 Armed;
     };
 
 } HV_MONITOR_TRIGGER_GROUP, *PHV_MONITOR_TRIGGER_GROUP;
@@ -437,12 +437,12 @@ typedef struct _HV_MONITOR_PARAMETER
 
 typedef union _HV_MONITOR_TRIGGER_STATE
 {
-    UINT32 AsUINT32;
+    u32 Asu32;
 
     struct
     {
-        UINT32 GroupEnable : 4;
-        UINT32 RsvdZ       : 28;
+        u32 GroupEnable : 4;
+        u32 RsvdZ       : 28;
     };
 
 } HV_MONITOR_TRIGGER_STATE, *PHV_MONITOR_TRIGGER_STATE;
@@ -471,12 +471,12 @@ typedef union _HV_MONITOR_TRIGGER_STATE
 typedef struct _HV_MONITOR_PAGE
 {
     HV_MONITOR_TRIGGER_STATE TriggerState;
-    UINT32                   RsvdZ1;
+    u32                   RsvdZ1;
 
     HV_MONITOR_TRIGGER_GROUP TriggerGroup[4];
     UINT64                   RsvdZ2[3];
 
-    INT32                    NextCheckTime[4][32];
+    s32                    NextCheckTime[4][32];
 
     u16                   Latency[4][32];
     UINT64                   RsvdZ3[32];
--- a/drivers/staging/hv/include/HvVpApi.h
+++ b/drivers/staging/hv/include/HvVpApi.h
@@ -26,7 +26,7 @@
 //
 // Virtual Processor Indices
 //
-typedef UINT32 HV_VP_INDEX, *PHV_VP_INDEX;
+typedef u32 HV_VP_INDEX, *PHV_VP_INDEX;
 
 //
 // The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
--- a/drivers/staging/hv/include/NetVscApi.h
+++ b/drivers/staging/hv/include/NetVscApi.h
@@ -52,14 +52,14 @@ typedef int (*PFN_ON_SEND)(DEVICE_OBJECT
 typedef void (*PFN_ON_SENDRECVCOMPLETION)(void * Context);
 
 typedef int (*PFN_ON_RECVCALLBACK)(DEVICE_OBJECT *dev, PNETVSC_PACKET packet);
-typedef void (*PFN_ON_LINKSTATUS_CHANGED)(DEVICE_OBJECT *dev, UINT32 Status);
+typedef void (*PFN_ON_LINKSTATUS_CHANGED)(DEVICE_OBJECT *dev, u32 Status);
 
 // Represent the xfer page packet which contains 1 or more netvsc packet
 typedef struct _XFERPAGE_PACKET {
 	DLIST_ENTRY			ListEntry;
 
 	// # of netvsc packets this xfer packet contains
-	UINT32				Count;
+	u32				Count;
 } XFERPAGE_PACKET;
 
 
@@ -93,9 +93,9 @@ typedef struct _NETVSC_PACKET {
 	// This points to the memory after PageBuffers
 	void *					Extension;
 
-	UINT32					TotalDataBufferLength;
+	u32					TotalDataBufferLength;
 	// Points to the send/receive buffer where the ethernet frame is
-	UINT32					PageBufferCount;
+	u32					PageBufferCount;
 	PAGE_BUFFER				PageBuffers[NETVSC_PACKET_MAXPAGE];
 
 } NETVSC_PACKET;
@@ -105,11 +105,11 @@ typedef struct _NETVSC_PACKET {
 typedef struct _NETVSC_DRIVER_OBJECT {
 	DRIVER_OBJECT				Base; // Must be the first field
 
-	UINT32						RingBufferSize;
-	UINT32						RequestExtSize;
+	u32						RingBufferSize;
+	u32						RequestExtSize;
 
 	// Additional num  of page buffers to allocate
-	UINT32						AdditionalRequestPageBufferCount;
+	u32						AdditionalRequestPageBufferCount;
 
 	// This is set by the caller to allow us to callback when we receive a packet
 	// from the "wire"
--- a/drivers/staging/hv/include/nvspprotocol.h
+++ b/drivers/staging/hv/include/nvspprotocol.h
@@ -26,7 +26,7 @@
 
 #include "VmbusChannelInterface.h"
 
-#define NVSP_INVALID_PROTOCOL_VERSION           ((UINT32)0xFFFFFFFF)
+#define NVSP_INVALID_PROTOCOL_VERSION           ((u32)0xFFFFFFFF)
 
 #define NVSP_PROTOCOL_VERSION_1                 2
 #define NVSP_MIN_PROTOCOL_VERSION               NVSP_PROTOCOL_VERSION_1
@@ -84,7 +84,7 @@ typedef enum _NVSP_STATUS
 
 typedef struct _NVSP_MESSAGE_HEADER
 {
-    UINT32                                  MessageType;
+    u32                                  MessageType;
 } NVSP_MESSAGE_HEADER, *PNVSP_MESSAGE_HEADER;
 
 //
@@ -99,8 +99,8 @@ typedef struct _NVSP_MESSAGE_HEADER
 //
 typedef struct _NVSP_MESSAGE_INIT
 {
-    UINT32                                  MinProtocolVersion;
-    UINT32                                  MaxProtocolVersion;
+    u32                                  MinProtocolVersion;
+    u32                                  MaxProtocolVersion;
 } NVSP_MESSAGE_INIT, *PNVSP_MESSAGE_INIT;
 
 //
@@ -110,9 +110,9 @@ typedef struct _NVSP_MESSAGE_INIT
 //
 typedef struct _NVSP_MESSAGE_INIT_COMPLETE
 {
-    UINT32                                  NegotiatedProtocolVersion;
-    UINT32                                  MaximumMdlChainLength;
-    UINT32                                  Status;
+    u32                                  NegotiatedProtocolVersion;
+    u32                                  MaximumMdlChainLength;
+    u32                                  Status;
 } NVSP_MESSAGE_INIT_COMPLETE, *PNVSP_MESSAGE_INIT_COMPLETE;
 
 typedef union _NVSP_MESSAGE_INIT_UBER
@@ -132,8 +132,8 @@ typedef union _NVSP_MESSAGE_INIT_UBER
 //
 typedef struct _NVSP_1_MESSAGE_SEND_NDIS_VERSION
 {
-    UINT32                                  NdisMajorVersion;
-    UINT32                                  NdisMinorVersion;
+    u32                                  NdisMajorVersion;
+    u32                                  NdisMinorVersion;
 } NVSP_1_MESSAGE_SEND_NDIS_VERSION, *PNVSP_1_MESSAGE_SEND_NDIS_VERSION;
 
 //
@@ -149,10 +149,10 @@ typedef struct _NVSP_1_MESSAGE_SEND_RECE
 
 typedef struct _NVSP_1_RECEIVE_BUFFER_SECTION
 {
-    UINT32                                  Offset;
-    UINT32                                  SubAllocationSize;
-    UINT32                                  NumSubAllocations;
-    UINT32                                  EndOffset;
+    u32                                  Offset;
+    u32                                  SubAllocationSize;
+    u32                                  NumSubAllocations;
+    u32                                  EndOffset;
 } NVSP_1_RECEIVE_BUFFER_SECTION, *PNVSP_1_RECEIVE_BUFFER_SECTION;
 
 //
@@ -162,8 +162,8 @@ typedef struct _NVSP_1_RECEIVE_BUFFER_SE
 //
 typedef struct _NVSP_1_MESSAGE_SEND_RECEIVE_BUFFER_COMPLETE
 {
-    UINT32                                  Status;
-    UINT32                                  NumSections;
+    u32                                  Status;
+    u32                                  NumSections;
 
     //
     // The receive buffer is split into two parts, a large
@@ -213,7 +213,7 @@ typedef struct _NVSP_1_MESSAGE_SEND_SEND
 //
 typedef struct _NVSP_1_MESSAGE_SEND_SEND_BUFFER_COMPLETE
 {
-    UINT32                                  Status;
+    u32                                  Status;
 
     //
     // The VSC gets to choose the size of the send buffer and
@@ -221,7 +221,7 @@ typedef struct _NVSP_1_MESSAGE_SEND_SEND
     // This was done to enable dynamic reconfigurations when
     // the cost of GPA-direct buffers decreases.
     //
-    UINT32                                  SectionSize;
+    u32                                  SectionSize;
 } NVSP_1_MESSAGE_SEND_SEND_BUFFER_COMPLETE, *PNVSP_1_MESSAGE_SEND_SEND_BUFFER_COMPLETE;
 
 //
@@ -246,7 +246,7 @@ typedef struct _NVSP_1_MESSAGE_SEND_RNDI
     // the Network VSP only has one. Therefore, the channel
     // travels with the RNDIS packet.
     //
-    UINT32                                  ChannelType;
+    u32                                  ChannelType;
 
     //
     // This field is used to send part or all of the data
@@ -256,8 +256,8 @@ typedef struct _NVSP_1_MESSAGE_SEND_RNDI
     // and all of the data was sent through other VMBus
     // mechanisms.
     //
-    UINT32                                  SendBufferSectionIndex;
-    UINT32                                  SendBufferSectionSize;
+    u32                                  SendBufferSectionIndex;
+    u32                                  SendBufferSectionSize;
 } NVSP_1_MESSAGE_SEND_RNDIS_PACKET, *PNVSP_1_MESSAGE_SEND_RNDIS_PACKET;
 
 //
@@ -268,7 +268,7 @@ typedef struct _NVSP_1_MESSAGE_SEND_RNDI
 //
 typedef struct _NVSP_1_MESSAGE_SEND_RNDIS_PACKET_COMPLETE
 {
-    UINT32                                  Status;
+    u32                                  Status;
 } NVSP_1_MESSAGE_SEND_RNDIS_PACKET_COMPLETE, *PNVSP_1_MESSAGE_SEND_RNDIS_PACKET_COMPLETE;
 
 typedef union _NVSP_MESSAGE_1_UBER
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -97,7 +97,6 @@ typedef struct _DLIST_ENTRY {
 //
 // unsigned types
 //
-typedef unsigned int		UINT32;
 #ifdef __x86_64__
 typedef unsigned long		UINT64;
 #else
@@ -112,7 +111,6 @@ typedef unsigned char		UCHAR;
 //
 // signed types
 //
-typedef int					INT32;
 #ifdef __x86_64__
 typedef long				INT64;
 #else
@@ -131,7 +129,7 @@ typedef unsigned long		SIZE_T;
 typedef unsigned char		BOOL;
 typedef unsigned char		BOOLEAN;
 typedef void*				HANDLE;
-typedef UINT32				DWORD;
+typedef u32				DWORD;
 typedef char*				PCHAR;
 typedef unsigned char		BYTE;
 
@@ -148,7 +146,7 @@ typedef void (*PFN_TIMER_CALLBACK)(void*
 #ifdef __x86_64__
 
 #define RDMSR(reg, v) {                                                        \
-    UINT32 h, l;                                                                 \
+    u32 h, l;                                                                 \
      __asm__ __volatile__("rdmsr"                                                               \
     : "=a" (l), "=d" (h)                                                       \
     : "c" (reg));                                                              \
@@ -156,9 +154,9 @@ typedef void (*PFN_TIMER_CALLBACK)(void*
 }
 
 #define WRMSR(reg, v) {                                                        \
-    UINT32 h, l;                                                               \
-    l = (UINT32)(((UINT64)(v)) & 0xFFFFFFFF);                                  \
-    h = (UINT32)((((UINT64)(v)) >> 32) & 0xFFFFFFFF);                          \
+    u32 h, l;                                                               \
+    l = (u32)(((UINT64)(v)) & 0xFFFFFFFF);                                  \
+    h = (u32)((((UINT64)(v)) >> 32) & 0xFFFFFFFF);                          \
      __asm__ __volatile__("wrmsr"                                              \
     : /* no outputs */                                                         \
     : "c" (reg), "a" (l), "d" (h));                                            \
@@ -219,7 +217,7 @@ extern void MemoryFence(void);
 extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
 extern void TimerClose(HANDLE hTimer);
 extern int TimerStop(HANDLE hTimer);
-extern void TimerStart(HANDLE hTimer, UINT32 expirationInUs);
+extern void TimerStart(HANDLE hTimer, u32 expirationInUs);
 extern SIZE_T GetTickCount(void);
 
 extern HANDLE WaitEventCreate(void);
@@ -228,7 +226,7 @@ extern void WaitEventSet(HANDLE hWait);
 extern int	WaitEventWait(HANDLE hWait);
 
 // If >0, hWait got signaled. If ==0, timeout. If < 0, error
-extern int	WaitEventWaitEx(HANDLE hWait, UINT32 TimeoutInMs);
+extern int	WaitEventWaitEx(HANDLE hWait, u32 TimeoutInMs);
 
 extern HANDLE SpinlockCreate(void);
 extern void SpinlockClose(HANDLE hSpin);
--- a/drivers/staging/hv/include/rndis.h
+++ b/drivers/staging/hv/include/rndis.h
@@ -28,21 +28,21 @@
 //
 //  Basic types
 //
-typedef UINT32                                  RNDIS_REQUEST_ID;
-typedef UINT32                                  RNDIS_HANDLE;
-typedef UINT32                                  RNDIS_STATUS;
-typedef UINT32                                  RNDIS_REQUEST_TYPE;
-typedef UINT32                                  RNDIS_OID;
-typedef UINT32                                  RNDIS_CLASS_ID;
-typedef UINT32                                  RNDIS_MEDIUM;
-typedef UINT32                                  *PRNDIS_REQUEST_ID;
-typedef UINT32                                  *PRNDIS_HANDLE;
-typedef UINT32                                  *PRNDIS_STATUS;
-typedef UINT32                                  *PRNDIS_REQUEST_TYPE;
-typedef UINT32                                  *PRNDIS_OID;
-typedef UINT32                                  *PRNDIS_CLASS_ID;
-typedef UINT32                                  *PRNDIS_MEDIUM;
-typedef UINT32                                  RNDIS_AF;
+typedef u32                                  RNDIS_REQUEST_ID;
+typedef u32                                  RNDIS_HANDLE;
+typedef u32                                  RNDIS_STATUS;
+typedef u32                                  RNDIS_REQUEST_TYPE;
+typedef u32                                  RNDIS_OID;
+typedef u32                                  RNDIS_CLASS_ID;
+typedef u32                                  RNDIS_MEDIUM;
+typedef u32                                  *PRNDIS_REQUEST_ID;
+typedef u32                                  *PRNDIS_HANDLE;
+typedef u32                                  *PRNDIS_STATUS;
+typedef u32                                  *PRNDIS_REQUEST_TYPE;
+typedef u32                                  *PRNDIS_OID;
+typedef u32                                  *PRNDIS_CLASS_ID;
+typedef u32                                  *PRNDIS_MEDIUM;
+typedef u32                                  RNDIS_AF;
 
 //
 //  Status codes
@@ -369,9 +369,9 @@ typedef UINT32                          
 typedef struct _RNDIS_INITIALIZE_REQUEST
 {
     RNDIS_REQUEST_ID                        RequestId;
-    UINT32                                  MajorVersion;
-    UINT32                                  MinorVersion;
-    UINT32                                  MaxTransferSize;
+    u32                                  MajorVersion;
+    u32                                  MinorVersion;
+    u32                                  MaxTransferSize;
 } RNDIS_INITIALIZE_REQUEST, *PRNDIS_INITIALIZE_REQUEST;
 
 
@@ -382,15 +382,15 @@ typedef struct _RNDIS_INITIALIZE_COMPLET
 {
     RNDIS_REQUEST_ID                        RequestId;
     RNDIS_STATUS                            Status;
-    UINT32                                  MajorVersion;
-    UINT32                                  MinorVersion;
-    UINT32                                  DeviceFlags;
+    u32                                  MajorVersion;
+    u32                                  MinorVersion;
+    u32                                  DeviceFlags;
     RNDIS_MEDIUM                            Medium;
-    UINT32                                  MaxPacketsPerMessage;
-    UINT32                                  MaxTransferSize;
-    UINT32                                  PacketAlignmentFactor;
-    UINT32                                  AFListOffset;
-    UINT32                                  AFListSize;
+    u32                                  MaxPacketsPerMessage;
+    u32                                  MaxTransferSize;
+    u32                                  PacketAlignmentFactor;
+    u32                                  AFListOffset;
+    u32                                  AFListSize;
 } RNDIS_INITIALIZE_COMPLETE, *PRNDIS_INITIALIZE_COMPLETE;
 
 
@@ -401,8 +401,8 @@ typedef struct _RNDIS_INITIALIZE_COMPLET
 typedef struct _RNDIS_CO_ADDRESS_FAMILY
 {
     RNDIS_AF                                AddressFamily;
-    UINT32                                  MajorVersion;
-    UINT32                                  MinorVersion;
+    u32                                  MajorVersion;
+    u32                                  MinorVersion;
 } RNDIS_CO_ADDRESS_FAMILY, *PRNDIS_CO_ADDRESS_FAMILY;
 
 
@@ -422,8 +422,8 @@ typedef struct _RNDIS_QUERY_REQUEST
 {
     RNDIS_REQUEST_ID                        RequestId;
     RNDIS_OID                               Oid;
-    UINT32                                  InformationBufferLength;
-    UINT32                                  InformationBufferOffset;
+    u32                                  InformationBufferLength;
+    u32                                  InformationBufferOffset;
     RNDIS_HANDLE                            DeviceVcHandle;
 } RNDIS_QUERY_REQUEST, *PRNDIS_QUERY_REQUEST;
 
@@ -435,8 +435,8 @@ typedef struct _RNDIS_QUERY_COMPLETE
 {
     RNDIS_REQUEST_ID                        RequestId;
     RNDIS_STATUS                            Status;
-    UINT32                                  InformationBufferLength;
-    UINT32                                  InformationBufferOffset;
+    u32                                  InformationBufferLength;
+    u32                                  InformationBufferOffset;
 } RNDIS_QUERY_COMPLETE, *PRNDIS_QUERY_COMPLETE;
 
 
@@ -447,8 +447,8 @@ typedef struct _RNDIS_SET_REQUEST
 {
     RNDIS_REQUEST_ID                        RequestId;
     RNDIS_OID                               Oid;
-    UINT32                                  InformationBufferLength;
-    UINT32                                  InformationBufferOffset;
+    u32                                  InformationBufferLength;
+    u32                                  InformationBufferOffset;
     RNDIS_HANDLE                            DeviceVcHandle;
 } RNDIS_SET_REQUEST, *PRNDIS_SET_REQUEST;
 
@@ -468,7 +468,7 @@ typedef struct _RNDIS_SET_COMPLETE
 //
 typedef struct _RNDIS_RESET_REQUEST
 {
-    UINT32                                  Reserved;
+    u32                                  Reserved;
 } RNDIS_RESET_REQUEST, *PRNDIS_RESET_REQUEST;
 
 //
@@ -477,7 +477,7 @@ typedef struct _RNDIS_RESET_REQUEST
 typedef struct _RNDIS_RESET_COMPLETE
 {
     RNDIS_STATUS                            Status;
-    UINT32                                  AddressingReset;
+    u32                                  AddressingReset;
 } RNDIS_RESET_COMPLETE, *PRNDIS_RESET_COMPLETE;
 
 
@@ -487,8 +487,8 @@ typedef struct _RNDIS_RESET_COMPLETE
 typedef struct _RNDIS_INDICATE_STATUS
 {
     RNDIS_STATUS                            Status;
-    UINT32                                  StatusBufferLength;
-    UINT32                                  StatusBufferOffset;
+    u32                                  StatusBufferLength;
+    u32                                  StatusBufferOffset;
 } RNDIS_INDICATE_STATUS, *PRNDIS_INDICATE_STATUS;
 
 
@@ -499,7 +499,7 @@ typedef struct _RNDIS_INDICATE_STATUS
 typedef struct _RNDIS_DIAGNOSTIC_INFO
 {
     RNDIS_STATUS                            DiagStatus;
-    UINT32                                  ErrorOffset;
+    u32                                  ErrorOffset;
 } RNDIS_DIAGNOSTIC_INFO, *PRNDIS_DIAGNOSTIC_INFO;
 
 
@@ -531,15 +531,15 @@ typedef struct _RNDIS_KEEPALIVE_COMPLETE
 //
 typedef struct _RNDIS_PACKET
 {
-    UINT32                                  DataOffset;
-    UINT32                                  DataLength;
-    UINT32                                  OOBDataOffset;
-    UINT32                                  OOBDataLength;
-    UINT32                                  NumOOBDataElements;
-    UINT32                                  PerPacketInfoOffset;
-    UINT32                                  PerPacketInfoLength;
+    u32                                  DataOffset;
+    u32                                  DataLength;
+    u32                                  OOBDataOffset;
+    u32                                  OOBDataLength;
+    u32                                  NumOOBDataElements;
+    u32                                  PerPacketInfoOffset;
+    u32                                  PerPacketInfoLength;
     RNDIS_HANDLE                            VcHandle;
-    UINT32                                  Reserved;
+    u32                                  Reserved;
 } RNDIS_PACKET, *PRNDIS_PACKET;
 
 //
@@ -547,9 +547,9 @@ typedef struct _RNDIS_PACKET
 //
 typedef struct _RNDIS_OOBD
 {
-    UINT32                                  Size;
+    u32                                  Size;
     RNDIS_CLASS_ID                          Type;
-    UINT32                                  ClassInformationOffset;
+    u32                                  ClassInformationOffset;
 } RNDIS_OOBD, *PRNDIS_OOBD;
 
 //
@@ -557,9 +557,9 @@ typedef struct _RNDIS_OOBD
 //
 typedef struct _RNDIS_PER_PACKET_INFO
 {
-    UINT32                                  Size;
-    UINT32                                  Type;
-    UINT32                                  PerPacketInformationOffset;
+    u32                                  Size;
+    u32                                  Type;
+    u32                                  PerPacketInformationOffset;
 } RNDIS_PER_PACKET_INFO, *PRNDIS_PER_PACKET_INFO;
 
 
@@ -569,11 +569,11 @@ typedef struct _RNDIS_PER_PACKET_INFO
 //
 typedef struct _RNDIS_CONFIG_PARAMETER_INFO
 {
-    UINT32                                  ParameterNameOffset;
-    UINT32                                  ParameterNameLength;
-    UINT32                                  ParameterType;
-    UINT32                                  ParameterValueOffset;
-    UINT32                                  ParameterValueLength;
+    u32                                  ParameterNameOffset;
+    u32                                  ParameterNameLength;
+    u32                                  ParameterType;
+    u32                                  ParameterValueOffset;
+    u32                                  ParameterValueLength;
 } RNDIS_CONFIG_PARAMETER_INFO, *PRNDIS_CONFIG_PARAMETER_INFO;
 
 //
@@ -636,8 +636,8 @@ typedef struct _RCONDIS_MP_QUERY_REQUEST
     RNDIS_REQUEST_TYPE                      RequestType;
     RNDIS_OID                               Oid;
     RNDIS_HANDLE                            DeviceVcHandle;
-    UINT32                                  InformationBufferLength;
-    UINT32                                  InformationBufferOffset;
+    u32                                  InformationBufferLength;
+    u32                                  InformationBufferOffset;
 } RCONDIS_MP_QUERY_REQUEST, *PRCONDIS_MP_QUERY_REQUEST;
 
 
@@ -650,8 +650,8 @@ typedef struct _RCONDIS_MP_SET_REQUEST
     RNDIS_REQUEST_TYPE                      RequestType;
     RNDIS_OID                               Oid;
     RNDIS_HANDLE                            DeviceVcHandle;
-    UINT32                                  InformationBufferLength;
-    UINT32                                  InformationBufferOffset;
+    u32                                  InformationBufferLength;
+    u32                                  InformationBufferOffset;
 } RCONDIS_MP_SET_REQUEST, *PRCONDIS_MP_SET_REQUEST;
 
 
@@ -662,8 +662,8 @@ typedef struct _RCONDIS_INDICATE_STATUS
 {
     RNDIS_HANDLE                            NdisVcHandle;
     RNDIS_STATUS                            Status;
-    UINT32                                  StatusBufferLength;
-    UINT32                                  StatusBufferOffset;
+    u32                                  StatusBufferLength;
+    u32                                  StatusBufferOffset;
 } RCONDIS_INDICATE_STATUS, *PRCONDIS_INDICATE_STATUS;
 
 
@@ -673,30 +673,30 @@ typedef struct _RCONDIS_INDICATE_STATUS
 
 typedef struct _RCONDIS_SPECIFIC_PARAMETERS
 {
-    UINT32                                  ParameterType;
-    UINT32                                  ParameterLength;
-    UINT32                                  ParameterOffset;
+    u32                                  ParameterType;
+    u32                                  ParameterLength;
+    u32                                  ParameterOffset;
 } RCONDIS_SPECIFIC_PARAMETERS, *PRCONDIS_SPECIFIC_PARAMETERS;
 
 typedef struct _RCONDIS_MEDIA_PARAMETERS
 {
-    UINT32                                  Flags;
-    UINT32                                  Reserved1;
-    UINT32                                  Reserved2;
+    u32                                  Flags;
+    u32                                  Reserved1;
+    u32                                  Reserved2;
     RCONDIS_SPECIFIC_PARAMETERS             MediaSpecific;
 } RCONDIS_MEDIA_PARAMETERS, *PRCONDIS_MEDIA_PARAMETERS;
 
 
 typedef struct _RNDIS_FLOWSPEC
 {
-    UINT32                                  TokenRate;
-    UINT32                                  TokenBucketSize;
-    UINT32                                  PeakBandwidth;
-    UINT32                                  Latency;
-    UINT32                                  DelayVariation;
-    UINT32                                  ServiceType;
-    UINT32                                  MaxSduSize;
-    UINT32                                  MinimumPolicedSize;
+    u32                                  TokenRate;
+    u32                                  TokenBucketSize;
+    u32                                  PeakBandwidth;
+    u32                                  Latency;
+    u32                                  DelayVariation;
+    u32                                  ServiceType;
+    u32                                  MaxSduSize;
+    u32                                  MinimumPolicedSize;
 } RNDIS_FLOWSPEC, *PRNDIS_FLOWSPEC;
 
 typedef struct _RCONDIS_CALL_MANAGER_PARAMETERS
@@ -712,12 +712,12 @@ typedef struct _RCONDIS_CALL_MANAGER_PAR
 typedef struct _RCONDIS_MP_ACTIVATE_VC_REQUEST
 {
     RNDIS_REQUEST_ID                        RequestId;
-    UINT32                                  Flags;
+    u32                                  Flags;
     RNDIS_HANDLE                            DeviceVcHandle;
-    UINT32                                  MediaParamsOffset;
-    UINT32                                  MediaParamsLength;
-    UINT32                                  CallMgrParamsOffset;
-    UINT32                                  CallMgrParamsLength;
+    u32                                  MediaParamsOffset;
+    u32                                  MediaParamsLength;
+    u32                                  CallMgrParamsOffset;
+    u32                                  CallMgrParamsLength;
 } RCONDIS_MP_ACTIVATE_VC_REQUEST, *PRCONDIS_MP_ACTIVATE_VC_REQUEST;
 
 //
@@ -736,7 +736,7 @@ typedef struct _RCONDIS_MP_ACTIVATE_VC_C
 typedef struct _RCONDIS_MP_DEACTIVATE_VC_REQUEST
 {
     RNDIS_REQUEST_ID                        RequestId;
-    UINT32                                  Flags;
+    u32                                  Flags;
     RNDIS_HANDLE                            DeviceVcHandle;
 } RCONDIS_MP_DEACTIVATE_VC_REQUEST, *PRCONDIS_MP_DEACTIVATE_VC_REQUEST;
 
@@ -786,13 +786,13 @@ typedef union _RNDIS_MESSAGE_CONTAINER
 //
 typedef __struct_bcount(MessageLength) struct _RNDIS_MESSAGE
 {
-    UINT32                                  NdisMessageType;
+    u32                                  NdisMessageType;
 
     //
     // Total length of this message, from the beginning
     // of the RNDIS_MESSAGE struct, in bytes.
     //
-    UINT32                                  MessageLength;
+    u32                                  MessageLength;
 
     // Actual message
     RNDIS_MESSAGE_CONTAINER                 Message;
--- a/drivers/staging/hv/include/StorVscApi.h
+++ b/drivers/staging/hv/include/StorVscApi.h
@@ -71,17 +71,17 @@ typedef enum _STORVSC_REQUEST_TYPE{
 
 typedef struct _STORVSC_REQUEST {
 	STORVSC_REQUEST_TYPE		Type;
-	UINT32					Host;
-	UINT32					Bus;
-	UINT32					TargetId;
-	UINT32					LunId;
+	u32					Host;
+	u32					Bus;
+	u32					TargetId;
+	u32					LunId;
 	u8 *					Cdb;
-	UINT32					CdbLen;
-	UINT32					Status;
-	UINT32					BytesXfer;
+	u32					CdbLen;
+	u32					Status;
+	u32					BytesXfer;
 
 	UCHAR*					SenseBuffer;
-	UINT32					SenseBufferSize;
+	u32					SenseBufferSize;
 
 	void *					Context;
 
@@ -99,13 +99,13 @@ typedef struct _STORVSC_DRIVER_OBJECT {
 	DRIVER_OBJECT			Base; // Must be the first field
 
 	// Set by caller (in bytes)
-	UINT32					RingBufferSize;
+	u32					RingBufferSize;
 
 	// Allocate this much private extension for each I/O request
-	UINT32					RequestExtSize;
+	u32					RequestExtSize;
 
 	// Maximum # of requests in flight per channel/device
-	UINT32					MaxOutstandingRequestsPerChannel;
+	u32					MaxOutstandingRequestsPerChannel;
 
 	// Set by the caller to allow us to re-enumerate the bus on the host
 	PFN_ON_HOST_RESCAN		OnHostRescan;
--- a/drivers/staging/hv/include/VmbusApi.h
+++ b/drivers/staging/hv/include/VmbusApi.h
@@ -49,16 +49,16 @@ typedef struct _DEVICE_OBJECT *PDEVICE_O
 
 // Single-page buffer
 typedef struct _PAGE_BUFFER {
-	UINT32	Length;
-	UINT32	Offset;
+	u32	Length;
+	u32	Offset;
 	UINT64	Pfn;
 } PAGE_BUFFER;
 
 // Multiple-page buffer
 typedef struct _MULTIPAGE_BUFFER {
 	// Length and Offset determines the # of pfns in the array
-	UINT32	Length;
-	UINT32	Offset;
+	u32	Length;
+	u32	Offset;
 	UINT64	PfnArray[MAX_MULTIPAGE_BUFFER_COUNT];
 }MULTIPAGE_BUFFER;
 
@@ -92,10 +92,10 @@ typedef void (*VMBUS_CHANNEL_CALLBACK)(v
 
 typedef int	(*VMBUS_CHANNEL_OPEN)(
 	PDEVICE_OBJECT		Device,
-	UINT32				SendBufferSize,
-	UINT32				RecvRingBufferSize,
+	u32				SendBufferSize,
+	u32				RecvRingBufferSize,
 	void *				UserData,
-	UINT32				UserDataLen,
+	u32				UserDataLen,
 	VMBUS_CHANNEL_CALLBACK ChannelCallback,
 	void *				Context
 	);
@@ -107,18 +107,18 @@ typedef void (*VMBUS_CHANNEL_CLOSE)(
 typedef int	(*VMBUS_CHANNEL_SEND_PACKET)(
 	PDEVICE_OBJECT		Device,
 	const void *			Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId,
-	UINT32				Type,
-	UINT32				Flags
+	u32				Type,
+	u32				Flags
 );
 
 typedef int	(*VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER)(
 	PDEVICE_OBJECT		Device,
 	PAGE_BUFFER			PageBuffers[],
-	UINT32				PageCount,
+	u32				PageCount,
 	void *				Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId
 	);
 
@@ -126,61 +126,61 @@ typedef int	(*VMBUS_CHANNEL_SEND_PACKET_
 	PDEVICE_OBJECT		Device,
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
 	void *				Buffer,
-	UINT32				BufferLen,
+	u32				BufferLen,
 	UINT64				RequestId
 );
 
 typedef int	(*VMBUS_CHANNEL_RECV_PACKET)(
 	PDEVICE_OBJECT		Device,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				BufferActualLen,
+	u32				BufferLen,
+	u32*				BufferActualLen,
 	UINT64*				RequestId
 	);
 
 typedef int	(*VMBUS_CHANNEL_RECV_PACKET_PAW)(
 	PDEVICE_OBJECT		Device,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32*				BufferActualLen,
+	u32				BufferLen,
+	u32*				BufferActualLen,
 	UINT64*				RequestId
 	);
 
 typedef int	(*VMBUS_CHANNEL_ESTABLISH_GPADL)(
 	PDEVICE_OBJECT		Device,
 	void *				Buffer,	// from kmalloc()
-	UINT32				BufferLen,		// page-size multiple
-	UINT32*				GpadlHandle
+	u32				BufferLen,		// page-size multiple
+	u32*				GpadlHandle
 	);
 
 typedef int	(*VMBUS_CHANNEL_TEARDOWN_GPADL)(
 	PDEVICE_OBJECT		Device,
-	UINT32				GpadlHandle
+	u32				GpadlHandle
 	);
 
 
 typedef struct _PORT_INFO {
-	UINT32		InterruptMask;
-	UINT32		ReadIndex;
-	UINT32		WriteIndex;
-	UINT32		BytesAvailToRead;
-	UINT32		BytesAvailToWrite;
+	u32		InterruptMask;
+	u32		ReadIndex;
+	u32		WriteIndex;
+	u32		BytesAvailToRead;
+	u32		BytesAvailToWrite;
 } PORT_INFO;
 
 
 typedef struct _DEVICE_INFO {
-	UINT32		ChannelId;
-	UINT32		ChannelState;
+	u32		ChannelId;
+	u32		ChannelState;
 	GUID		ChannelType;
 	GUID		ChannelInstance;
 
-	UINT32						MonitorId;
-	UINT32						ServerMonitorPending;
-	UINT32						ServerMonitorLatency;
-	UINT32						ServerMonitorConnectionId;
-	UINT32						ClientMonitorPending;
-	UINT32						ClientMonitorLatency;
-	UINT32						ClientMonitorConnectionId;
+	u32						MonitorId;
+	u32						ServerMonitorPending;
+	u32						ServerMonitorLatency;
+	u32						ServerMonitorConnectionId;
+	u32						ClientMonitorPending;
+	u32						ClientMonitorLatency;
+	u32						ClientMonitorConnectionId;
 
 	PORT_INFO	Inbound;
 	PORT_INFO	Outbound;
--- a/drivers/staging/hv/include/VmbusChannelInterface.h
+++ b/drivers/staging/hv/include/VmbusChannelInterface.h
@@ -67,8 +67,8 @@ typedef struct
     GUID    InterfaceType;
     GUID    InterfaceInstance;
     UINT64  InterruptLatencyIn100nsUnits;
-    UINT32  InterfaceRevision;
-    UINT32  ServerContextAreaSize;  // in bytes
+    u32  InterfaceRevision;
+    u32  ServerContextAreaSize;  // in bytes
     u16  ChannelFlags;
     u16  MmioMegabytes;          // in bytes * 1024 * 1024
 
@@ -89,11 +89,11 @@ typedef struct
         //
         struct
         {
-            UINT32  PipeMode;
+            u32  PipeMode;
             UCHAR   UserDefined[MAX_PIPE_USER_DEFINED_BYTES];
         } Pipe;
     } u;
-	UINT32	Padding;
+	u32	Padding;
 } VMBUS_CHANNEL_OFFER, *PVMBUS_CHANNEL_OFFER;
 #pragma pack(pop)
 
@@ -107,7 +107,7 @@ typedef struct
 //          FIELD_OFFSET(VMBUS_CHANNEL_OFFER, u.Standard.UserDefined)));
 //
 
-typedef UINT32 GPADL_HANDLE;
+typedef u32 GPADL_HANDLE;
 
 //
 // Server Flags
--- a/drivers/staging/hv/include/VmbusPacketFormat.h
+++ b/drivers/staging/hv/include/VmbusPacketFormat.h
@@ -41,8 +41,8 @@ typedef struct
     {
         struct
         {
-            volatile UINT32  In;        // Offset in bytes from the ring base
-            volatile UINT32  Out;       // Offset in bytes from the ring base
+            volatile u32  In;        // Offset in bytes from the ring base
+            volatile u32  Out;       // Offset in bytes from the ring base
         };
         volatile LONGLONG    InOut;
     };
@@ -52,7 +52,7 @@ typedef struct
     // endpoint should not send any interrupts.
     //
 
-    volatile UINT32 InterruptMask;
+    volatile u32 InterruptMask;
 
 } VMRCB, *PVMRCB;
 
@@ -86,7 +86,7 @@ typedef struct
     UINT64 TransactionId;
 } VMPACKET_DESCRIPTOR, *PVMPACKET_DESCRIPTOR;
 
-typedef UINT32 PREVIOUS_PACKET_OFFSET, *PPREVIOUS_PACKET_OFFSET;
+typedef u32 PREVIOUS_PACKET_OFFSET, *PPREVIOUS_PACKET_OFFSET;
 
 typedef struct
 {
@@ -96,8 +96,8 @@ typedef struct
 
 typedef struct
 {
-    UINT32  ByteCount;
-    UINT32  ByteOffset;
+    u32  ByteCount;
+    u32  ByteOffset;
 } VMTRANSFER_PAGE_RANGE, *PVMTRANSFER_PAGE_RANGE;
 
 #ifdef __cplusplus
@@ -115,7 +115,7 @@ typedef struct VMTRANSFER_PAGE_PACKET_HE
     u16                  TransferPageSetId;
     BOOLEAN                 SenderOwnsSet;
     u8                   Reserved;
-    UINT32                  RangeCount;
+    u32                  RangeCount;
     VMTRANSFER_PAGE_RANGE   Ranges[1];
 
 } VMTRANSFER_PAGE_PACKET_HEADER, *PVMTRANSFER_PAGE_PACKET_HEADER;
@@ -134,8 +134,8 @@ typedef struct _VMGPADL_PACKET_HEADER {
 #endif
 
 
-    UINT32  Gpadl;
-    UINT32  Reserved;
+    u32  Gpadl;
+    u32  Reserved;
 
 } VMGPADL_PACKET_HEADER, *PVMGPADL_PACKET_HEADER;
 
@@ -151,7 +151,7 @@ typedef struct _VMADD_REMOVE_TRANSFER_PA
 
 #endif
 
-    UINT32  Gpadl;
+    u32  Gpadl;
     u16  TransferPageSetId;
     u16  Reserved;
 
@@ -166,8 +166,8 @@ typedef struct _VMADD_REMOVE_TRANSFER_PA
 
 typedef struct _GPA_RANGE {
 
-    UINT32  ByteCount;
-    UINT32  ByteOffset;
+    u32  ByteCount;
+    u32  ByteOffset;
     UINT64  PfnArray[0];
 
 } GPA_RANGE, *PGPA_RANGE;
@@ -196,8 +196,8 @@ typedef struct _VMESTABLISH_GPADL {
 
 #endif
 
-    UINT32      Gpadl;
-    UINT32      RangeCount;
+    u32      Gpadl;
+    u32      RangeCount;
     GPA_RANGE   Range[1];
 
 } VMESTABLISH_GPADL, *PVMESTABLISH_GPADL;
@@ -220,8 +220,8 @@ typedef struct _VMTEARDOWN_GPADL {
 
 #endif
 
-    UINT32  Gpadl;
-    UINT32  Reserved; // for alignment to a 8-byte boundary
+    u32  Gpadl;
+    u32  Reserved; // for alignment to a 8-byte boundary
 } VMTEARDOWN_GPADL, *PVMTEARDOWN_GPADL;
 
 
@@ -242,8 +242,8 @@ typedef struct _VMDATA_GPA_DIRECT {
 
 #endif
 
-    UINT32      Reserved;
-    UINT32      RangeCount;
+    u32      Reserved;
+    u32      RangeCount;
     GPA_RANGE   Range[1];
 
 } VMDATA_GPA_DIRECT, *PVMDATA_GPA_DIRECT;
@@ -267,8 +267,8 @@ typedef struct _VMADDITIONAL_DATA {
 #endif
 
     UINT64  TotalBytes;
-    UINT32  ByteOffset;
-    UINT32  ByteCount;
+    u32  ByteOffset;
+    u32  ByteCount;
     UCHAR   Data[1];
 
 } VMADDITIONAL_DATA, *PVMADDITIONAL_DATA;
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -1402,7 +1402,7 @@ NetVscOnChannelCallback(
 	DEVICE_OBJECT *device=(DEVICE_OBJECT*)Context;
 	NETVSC_DEVICE *netDevice;
 
-	UINT32 bytesRecvd;
+	u32 bytesRecvd;
 	UINT64 requestId;
 	UCHAR packet[netPacketSize];
 	VMPACKET_DESCRIPTOR *desc;
--- a/drivers/staging/hv/NetVsc.h
+++ b/drivers/staging/hv/NetVsc.h
@@ -66,15 +66,15 @@ typedef struct _NETVSC_DEVICE {
 
 	// Send buffer allocated by us but manages by NetVSP
 	void *							SendBuffer;
-	UINT32							SendBufferSize;
-	UINT32							SendBufferGpadlHandle;
-	UINT32							SendSectionSize;
+	u32							SendBufferSize;
+	u32							SendBufferGpadlHandle;
+	u32							SendSectionSize;
 
 	// Receive buffer allocated by us but manages by NetVSP
 	void *							ReceiveBuffer;
-	UINT32							ReceiveBufferSize;
-	UINT32							ReceiveBufferGpadlHandle;
-	UINT32							ReceiveSectionCount;
+	u32							ReceiveBufferSize;
+	u32							ReceiveBufferGpadlHandle;
+	u32							ReceiveSectionCount;
 	PNVSP_1_RECEIVE_BUFFER_SECTION	ReceiveSections;
 
 	// Used for NetVSP initialization protocol
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -289,7 +289,7 @@ HANDLE TimerCreate(PFN_TIMER_CALLBACK pf
 	return t;
 }
 
-void TimerStart(HANDLE hTimer, UINT32 expirationInUs)
+void TimerStart(HANDLE hTimer, u32 expirationInUs)
 {
 	TIMER* t  = (TIMER* )hTimer;
 
@@ -363,7 +363,7 @@ int WaitEventWait(HANDLE hWait)
 	return ret;
 }
 
-int WaitEventWaitEx(HANDLE hWait, UINT32 TimeoutInMs)
+int WaitEventWaitEx(HANDLE hWait, u32 TimeoutInMs)
 {
 	int ret=0;
 	WAITEVENT* waitEvent = (WAITEVENT* )hWait;
--- a/drivers/staging/hv/RingBuffer.c
+++ b/drivers/staging/hv/RingBuffer.c
@@ -44,9 +44,9 @@ Description:
 
 --*/
 static inline void
-GetRingBufferAvailBytes(RING_BUFFER_INFO *rbi, UINT32 *read, UINT32 *write)
+GetRingBufferAvailBytes(RING_BUFFER_INFO *rbi, u32 *read, u32 *write)
 {
-	UINT32 read_loc,write_loc;
+	u32 read_loc,write_loc;
 
 	// Capture the read/write indices before they changed
 	read_loc = rbi->RingBuffer->ReadIndex;
@@ -65,10 +65,10 @@ Description:
 	Get the next write location for the specified ring buffer
 
 --*/
-static inline UINT32
+static inline u32
 GetNextWriteLocation(RING_BUFFER_INFO* RingInfo)
 {
-	UINT32 next = RingInfo->RingBuffer->WriteIndex;
+	u32 next = RingInfo->RingBuffer->WriteIndex;
 
 	ASSERT(next < RingInfo->RingDataSize);
 
@@ -85,7 +85,7 @@ Description:
 
 --*/
 static inline void
-SetNextWriteLocation(RING_BUFFER_INFO* RingInfo, UINT32 NextWriteLocation)
+SetNextWriteLocation(RING_BUFFER_INFO* RingInfo, u32 NextWriteLocation)
 {
 	RingInfo->RingBuffer->WriteIndex = NextWriteLocation;
 }
@@ -99,10 +99,10 @@ Description:
 	Get the next read location for the specified ring buffer
 
 --*/
-static inline UINT32
+static inline u32
 GetNextReadLocation(RING_BUFFER_INFO* RingInfo)
 {
-	UINT32 next = RingInfo->RingBuffer->ReadIndex;
+	u32 next = RingInfo->RingBuffer->ReadIndex;
 
 	ASSERT(next < RingInfo->RingDataSize);
 
@@ -119,10 +119,10 @@ Description:
 	This allows the caller to skip
 
 --*/
-static inline UINT32
-GetNextReadLocationWithOffset(RING_BUFFER_INFO* RingInfo, UINT32 Offset)
+static inline u32
+GetNextReadLocationWithOffset(RING_BUFFER_INFO* RingInfo, u32 Offset)
 {
-	UINT32 next = RingInfo->RingBuffer->ReadIndex;
+	u32 next = RingInfo->RingBuffer->ReadIndex;
 
 	ASSERT(next < RingInfo->RingDataSize);
 	next += Offset;
@@ -141,7 +141,7 @@ Description:
 
 --*/
 static inline void
-SetNextReadLocation(RING_BUFFER_INFO* RingInfo, UINT32 NextReadLocation)
+SetNextReadLocation(RING_BUFFER_INFO* RingInfo, u32 NextReadLocation)
 {
 	RingInfo->RingBuffer->ReadIndex = NextReadLocation;
 }
@@ -172,7 +172,7 @@ Description:
 	Get the size of the ring buffer
 
 --*/
-static inline UINT32
+static inline u32
 GetRingBufferSize(RING_BUFFER_INFO* RingInfo)
 {
 	return RingInfo->RingDataSize;
@@ -206,8 +206,8 @@ Description:
 void
 DumpRingInfo(RING_BUFFER_INFO* RingInfo, char *Prefix)
 {
-	UINT32 bytesAvailToWrite;
-	UINT32 bytesAvailToRead;
+	u32 bytesAvailToWrite;
+	u32 bytesAvailToRead;
 
 	GetRingBufferAvailBytes(RingInfo, &bytesAvailToRead, &bytesAvailToWrite);
 
@@ -224,19 +224,19 @@ DumpRingInfo(RING_BUFFER_INFO* RingInfo,
 //
 // Internal routines
 //
-static UINT32
+static u32
 CopyToRingBuffer(
 	RING_BUFFER_INFO	*RingInfo,
-	UINT32				StartWriteOffset,
+	u32				StartWriteOffset,
 	void *				Src,
-	UINT32				SrcLen);
+	u32				SrcLen);
 
-static UINT32
+static u32
 CopyFromRingBuffer(
 	RING_BUFFER_INFO	*RingInfo,
 	void *				Dest,
-	UINT32				DestLen,
-	UINT32				StartReadOffset);
+	u32				DestLen,
+	u32				StartReadOffset);
 
 
 
@@ -255,8 +255,8 @@ RingBufferGetDebugInfo(
 	RING_BUFFER_DEBUG_INFO	*DebugInfo
 	)
 {
-	UINT32 bytesAvailToWrite;
-	UINT32 bytesAvailToRead;
+	u32 bytesAvailToWrite;
+	u32 bytesAvailToRead;
 
 	if (RingInfo->RingBuffer)
 	{
@@ -281,7 +281,7 @@ Description:
 	Get the interrupt mask for the specified ring buffer
 
 --*/
-UINT32
+u32
 GetRingBufferInterruptMask(
 	RING_BUFFER_INFO *rbi
 	)
@@ -302,7 +302,7 @@ int
 RingBufferInit(
 	RING_BUFFER_INFO	*RingInfo,
 	void				*Buffer,
-	UINT32				BufferLen
+	u32				BufferLen
 	)
 {
 	ASSERT(sizeof(RING_BUFFER) == PAGE_SIZE);
@@ -350,15 +350,15 @@ int
 RingBufferWrite(
 	RING_BUFFER_INFO*	OutRingInfo,
 	SG_BUFFER_LIST		SgBuffers[],
-	UINT32				SgBufferCount
+	u32				SgBufferCount
 	)
 {
 	int i=0;
-	UINT32 byteAvailToWrite;
-	UINT32 byteAvailToRead;
-	UINT32 totalBytesToWrite=0;
+	u32 byteAvailToWrite;
+	u32 byteAvailToRead;
+	u32 totalBytesToWrite=0;
 
-	volatile UINT32 nextWriteLocation;
+	volatile u32 nextWriteLocation;
 	UINT64 prevIndices=0;
 
 	DPRINT_ENTER(VMBUS);
@@ -439,12 +439,12 @@ int
 RingBufferPeek(
 	RING_BUFFER_INFO*	InRingInfo,
 	void*				Buffer,
-	UINT32				BufferLen
+	u32				BufferLen
 	)
 {
-	UINT32 bytesAvailToWrite;
-	UINT32 bytesAvailToRead;
-	UINT32 nextReadLocation=0;
+	u32 bytesAvailToWrite;
+	u32 bytesAvailToRead;
+	u32 nextReadLocation=0;
 
 	SpinlockAcquire(InRingInfo->RingLock);
 
@@ -487,13 +487,13 @@ int
 RingBufferRead(
 	RING_BUFFER_INFO*	InRingInfo,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32				Offset
+	u32				BufferLen,
+	u32				Offset
 	)
 {
-	UINT32 bytesAvailToWrite;
-	UINT32 bytesAvailToRead;
-	UINT32 nextReadLocation=0;
+	u32 bytesAvailToWrite;
+	u32 bytesAvailToRead;
+	u32 nextReadLocation=0;
 	UINT64 prevIndices=0;
 
 	ASSERT(BufferLen > 0);
@@ -553,16 +553,16 @@ Description:
 	Assume there is enough room. Handles wrap-around in dest case only!!
 
 --*/
-UINT32
+u32
 CopyToRingBuffer(
 	RING_BUFFER_INFO	*RingInfo,
-	UINT32				StartWriteOffset,
+	u32				StartWriteOffset,
 	void *				Src,
-	UINT32				SrcLen)
+	u32				SrcLen)
 {
 	void * ringBuffer=GetRingBuffer(RingInfo);
-	UINT32 ringBufferSize=GetRingBufferSize(RingInfo);
-	UINT32 fragLen;
+	u32 ringBufferSize=GetRingBufferSize(RingInfo);
+	u32 fragLen;
 
 	if (SrcLen > ringBufferSize - StartWriteOffset) // wrap-around detected!
 	{
@@ -594,17 +594,17 @@ Description:
 	Assume there is enough room. Handles wrap-around in src case only!!
 
 --*/
-UINT32
+u32
 CopyFromRingBuffer(
 	RING_BUFFER_INFO	*RingInfo,
 	void *				Dest,
-	UINT32				DestLen,
-	UINT32				StartReadOffset)
+	u32				DestLen,
+	u32				StartReadOffset)
 {
 	void * ringBuffer=GetRingBuffer(RingInfo);
-	UINT32 ringBufferSize=GetRingBufferSize(RingInfo);
+	u32 ringBufferSize=GetRingBufferSize(RingInfo);
 
-	UINT32 fragLen;
+	u32 fragLen;
 
 	if (DestLen > ringBufferSize - StartReadOffset) // wrap-around detected at the src
 	{
--- a/drivers/staging/hv/RingBuffer.h
+++ b/drivers/staging/hv/RingBuffer.h
@@ -29,39 +29,39 @@
 
 typedef struct _SG_BUFFER_LIST {
 	void *	Data;
-	UINT32	Length;
+	u32	Length;
 } SG_BUFFER_LIST;
 
 typedef struct _RING_BUFFER {
-    volatile UINT32	WriteIndex;     // Offset in bytes from the start of ring data below
-    volatile UINT32	ReadIndex;      // Offset in bytes from the start of ring data below
+    volatile u32	WriteIndex;     // Offset in bytes from the start of ring data below
+    volatile u32	ReadIndex;      // Offset in bytes from the start of ring data below
 
-	volatile UINT32 InterruptMask;
+	volatile u32 InterruptMask;
 	u8	Reserved[4084];			// Pad it to PAGE_SIZE so that data starts on page boundary
 	// NOTE: The InterruptMask field is used only for channels but since our vmbus connection
 	// also uses this data structure and its data starts here, we commented out this field.
-	// volatile UINT32 InterruptMask;
+	// volatile u32 InterruptMask;
 	// Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
     u8		Buffer[0];
 } STRUCT_PACKED RING_BUFFER;
 
 typedef struct _RING_BUFFER_INFO {
     RING_BUFFER*	RingBuffer;
-    UINT32			RingSize;			// Include the shared header
+    u32			RingSize;			// Include the shared header
 	HANDLE			RingLock;
 
-    UINT32			RingDataSize;		// < ringSize
-	UINT32			RingDataStartOffset;
+    u32			RingDataSize;		// < ringSize
+	u32			RingDataStartOffset;
 
 } RING_BUFFER_INFO;
 
 
 typedef struct _RING_BUFFER_DEBUG_INFO {
-	UINT32		CurrentInterruptMask;
-	UINT32		CurrentReadIndex;
-	UINT32		CurrentWriteIndex;
-	UINT32		BytesAvailToRead;
-	UINT32		BytesAvailToWrite;
+	u32		CurrentInterruptMask;
+	u32		CurrentReadIndex;
+	u32		CurrentWriteIndex;
+	u32		BytesAvailToRead;
+	u32		BytesAvailToWrite;
 }RING_BUFFER_DEBUG_INFO;
 
 
@@ -73,7 +73,7 @@ static int
 RingBufferInit(
 	RING_BUFFER_INFO	*RingInfo,
 	void *				Buffer,
-	UINT32				BufferLen
+	u32				BufferLen
 	);
 
 static void
@@ -85,25 +85,25 @@ static int
 RingBufferWrite(
 	RING_BUFFER_INFO	*RingInfo,
 	SG_BUFFER_LIST		SgBuffers[],
-	UINT32				SgBufferCount
+	u32				SgBufferCount
 	);
 
 static int
 RingBufferPeek(
 	RING_BUFFER_INFO	*RingInfo,
 	void *				Buffer,
-	UINT32				BufferLen
+	u32				BufferLen
 	);
 
 static int
 RingBufferRead(
 	RING_BUFFER_INFO	*RingInfo,
 	void *				Buffer,
-	UINT32				BufferLen,
-	UINT32				Offset
+	u32				BufferLen,
+	u32				Offset
 	);
 
-static UINT32
+static u32
 GetRingBufferInterruptMask(
 	RING_BUFFER_INFO *RingInfo
 	);
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -50,8 +50,8 @@ typedef struct _RNDIS_DEVICE {
 	NETVSC_DEVICE			*NetDevice;
 
 	RNDIS_DEVICE_STATE		State;
-	UINT32					LinkStatus;
-	UINT32					NewRequestId;
+	u32					LinkStatus;
+	u32					NewRequestId;
 
 	HANDLE					RequestLock;
 	LIST_ENTRY				RequestList;
@@ -120,9 +120,9 @@ RndisFilterOnReceive(
 static int
 RndisFilterQueryDevice(
 	RNDIS_DEVICE	*Device,
-	UINT32			Oid,
+	u32			Oid,
 	void			*Result,
-	UINT32			*ResultSize
+	u32			*ResultSize
 	);
 
 static inline int
@@ -138,7 +138,7 @@ RndisFilterQueryDeviceLinkStatus(
 static int
 RndisFilterSetPacketFilter(
 	RNDIS_DEVICE	*Device,
-	UINT32			NewFilter
+	u32			NewFilter
 	);
 
 static int
@@ -235,7 +235,7 @@ static inline void PutRndisDevice(RNDIS_
 	MemFree(Device);
 }
 
-static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, UINT32 MessageType, UINT32 MessageLength)
+static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageType, u32 MessageLength)
 {
 	RNDIS_REQUEST *request;
 	RNDIS_MESSAGE *rndisMessage;
@@ -465,7 +465,7 @@ RndisFilterReceiveData(
 	)
 {
 	RNDIS_PACKET *rndisPacket;
-	UINT32 dataOffset;
+	u32 dataOffset;
 
 	DPRINT_ENTER(NETVSC);
 
@@ -585,13 +585,13 @@ RndisFilterOnReceive(
 static int
 RndisFilterQueryDevice(
 	RNDIS_DEVICE	*Device,
-	UINT32			Oid,
+	u32			Oid,
 	void			*Result,
-	UINT32			*ResultSize
+	u32			*ResultSize
 	)
 {
 	RNDIS_REQUEST *request;
-	UINT32 inresultSize = *ResultSize;
+	u32 inresultSize = *ResultSize;
 	RNDIS_QUERY_REQUEST *query;
 	RNDIS_QUERY_COMPLETE *queryComplete;
 	int ret=0;
@@ -653,7 +653,7 @@ RndisFilterQueryDeviceMac(
 	RNDIS_DEVICE	*Device
 	)
 {
-	UINT32 size=HW_MACADDR_LEN;
+	u32 size=HW_MACADDR_LEN;
 
 	return RndisFilterQueryDevice(Device,
 									RNDIS_OID_802_3_PERMANENT_ADDRESS,
@@ -666,7 +666,7 @@ RndisFilterQueryDeviceLinkStatus(
 	RNDIS_DEVICE	*Device
 	)
 {
-	UINT32 size=sizeof(UINT32);
+	u32 size=sizeof(u32);
 
 	return RndisFilterQueryDevice(Device,
 									RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
@@ -677,20 +677,20 @@ RndisFilterQueryDeviceLinkStatus(
 static int
 RndisFilterSetPacketFilter(
 	RNDIS_DEVICE	*Device,
-	UINT32			NewFilter
+	u32			NewFilter
 	)
 {
 	RNDIS_REQUEST *request;
 	RNDIS_SET_REQUEST *set;
 	RNDIS_SET_COMPLETE *setComplete;
-	UINT32 status;
+	u32 status;
 	int ret;
 
 	DPRINT_ENTER(NETVSC);
 
-	ASSERT(RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(UINT32) <= sizeof(RNDIS_MESSAGE));
+	ASSERT(RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(u32) <= sizeof(RNDIS_MESSAGE));
 
-	request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(UINT32));
+	request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(u32));
 	if (!request)
 	{
 		ret = -1;
@@ -700,10 +700,10 @@ RndisFilterSetPacketFilter(
 	// Setup the rndis set
 	set = &request->RequestMessage.Message.SetRequest;
 	set->Oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER;
-	set->InformationBufferLength = sizeof(UINT32);
+	set->InformationBufferLength = sizeof(u32);
 	set->InformationBufferOffset = sizeof(RNDIS_SET_REQUEST);
 
-	memcpy((void*)(ULONG_PTR)set + sizeof(RNDIS_SET_REQUEST), &NewFilter, sizeof(UINT32));
+	memcpy((void*)(ULONG_PTR)set + sizeof(RNDIS_SET_REQUEST), &NewFilter, sizeof(u32));
 
 	ret = RndisFilterSendRequest(Device, request);
 	if (ret != 0)
@@ -795,7 +795,7 @@ RndisFilterInitDevice(
 	RNDIS_REQUEST *request;
 	RNDIS_INITIALIZE_REQUEST *init;
 	RNDIS_INITIALIZE_COMPLETE *initComplete;
-	UINT32 status;
+	u32 status;
 	int ret;
 
 	DPRINT_ENTER(NETVSC);
@@ -1091,7 +1091,7 @@ RndisFilterOnSend(
 	RNDIS_FILTER_PACKET *filterPacket;
 	RNDIS_MESSAGE *rndisMessage;
 	RNDIS_PACKET *rndisPacket;
-	UINT32 rndisMessageSize;
+	u32 rndisMessageSize;
 
 	DPRINT_ENTER(NETVSC);
 
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -908,7 +908,7 @@ StorVscOnChannelCallback(
 	int ret=0;
 	DEVICE_OBJECT *device = (DEVICE_OBJECT*)Context;
 	STORVSC_DEVICE *storDevice;
-	UINT32 bytesRecvd;
+	u32 bytesRecvd;
 	UINT64 requestId;
 	UCHAR packet[ALIGN_UP(sizeof(VSTOR_PACKET),8)];
 	STORVSC_REQUEST_EXTENSION *request;
--- a/drivers/staging/hv/Vmbus.c
+++ b/drivers/staging/hv/Vmbus.c
@@ -307,7 +307,7 @@ VmbusOnDeviceAdd(
 	void			*AdditionalInfo
 	)
 {
-	UINT32 *irqvector = (UINT32*) AdditionalInfo;
+	u32 *irqvector = (u32*) AdditionalInfo;
 	int ret=0;
 
 	DPRINT_ENTER(VMBUS);
--- a/drivers/staging/hv/VmbusPrivate.h
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -64,7 +64,7 @@ typedef struct _VMBUS_CONNECTION {
 
 	VMBUS_CONNECT_STATE					ConnectState;
 
-	UINT32								NextGpadlHandle;
+	u32								NextGpadlHandle;
 
 	// Represents channel interrupts. Each bit position
 	// represents a channel.
@@ -130,7 +130,7 @@ VmbusChildDeviceRemove(
 
 static VMBUS_CHANNEL*
 GetChannelFromRelId(
-	UINT32 relId
+	u32 relId
 	);
 
 //
@@ -154,7 +154,7 @@ VmbusPostMessage(
 
 static int
 VmbusSetEvent(
-	UINT32 childRelId
+	u32 childRelId
 	);
 
 static void

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 23/54] Staging: hv: remove UINT64 and INT64 and UCHAR typedefs
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (22 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-uint64-and-int64-and-uchar-typedefs.patch --]
[-- Type: text/plain, Size: 40751 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The UINT64 and INT64 and UCHAR typedefs are now removed from the Hyper-V
driver code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/BlkVsc.c                        |    4 -
 drivers/staging/hv/Channel.c                       |   48 +++++++++----------
 drivers/staging/hv/Channel.h                       |   14 ++---
 drivers/staging/hv/ChannelInterface.c              |   10 ++--
 drivers/staging/hv/Hv.c                            |   24 ++++-----
 drivers/staging/hv/Hv.h                            |   12 ++--
 drivers/staging/hv/NetVsc.c                        |   12 ++--
 drivers/staging/hv/NetVsc.h                        |    2 
 drivers/staging/hv/RingBuffer.c                    |   16 +++---
 drivers/staging/hv/RndisFilter.c                   |    2 
 drivers/staging/hv/StorVsc.c                       |   12 ++--
 drivers/staging/hv/include/ChannelMessages.h       |   12 ++--
 drivers/staging/hv/include/HvHalApi.h              |    4 -
 drivers/staging/hv/include/HvHcApi.h               |    2 
 drivers/staging/hv/include/HvPtApi.h               |   22 ++++----
 drivers/staging/hv/include/HvSynicApi.h            |   52 ++++++++++-----------
 drivers/staging/hv/include/HvTypes.h               |    2 
 drivers/staging/hv/include/List.h                  |    4 -
 drivers/staging/hv/include/NetVscApi.h             |    6 +-
 drivers/staging/hv/include/StorVscApi.h            |    6 +-
 drivers/staging/hv/include/VmbusApi.h              |   14 ++---
 drivers/staging/hv/include/VmbusChannelInterface.h |    6 +-
 drivers/staging/hv/include/VmbusPacketFormat.h     |   10 ++--
 drivers/staging/hv/include/osd.h                   |   22 +-------
 drivers/staging/hv/include/rndis.h                 |    8 +--
 drivers/staging/hv/include/vstorage.h              |   34 ++++++-------
 26 files changed, 173 insertions(+), 187 deletions(-)

--- a/drivers/staging/hv/BlkVsc.c
+++ b/drivers/staging/hv/BlkVsc.c
@@ -56,9 +56,9 @@ BlkVscInitialize(
 
 	storDriver->RequestExtSize			= sizeof(STORVSC_REQUEST_EXTENSION);
 	// Divide the ring buffer data size (which is 1 page less than the ring buffer size since that page is reserved for the ring buffer indices)
-	// by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + UINT64)
+	// by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + u64)
 	storDriver->MaxOutstandingRequestsPerChannel =
-		((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(UINT64),sizeof(UINT64)));
+		((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(u64),sizeof(u64)));
 
 	DPRINT_INFO(BLKVSC, "max io outstd %u", storDriver->MaxOutstandingRequestsPerChannel);
 
--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -335,7 +335,7 @@ static void DumpGpadlBody(
 	int i=0;
 	int pfnCount=0;
 
-	pfnCount = (Len - sizeof(VMBUS_CHANNEL_GPADL_BODY))/ sizeof(UINT64);
+	pfnCount = (Len - sizeof(VMBUS_CHANNEL_GPADL_BODY))/ sizeof(u64);
 	DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount);
 
 	for (i=0; i< pfnCount; i++)
@@ -416,12 +416,12 @@ VmbusChannelCreateGpadlHeader(
 
 	// do we need a gpadl body msg
 	pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_HEADER) - sizeof(GPA_RANGE);
-	pfnCount = pfnSize / sizeof(UINT64);
+	pfnCount = pfnSize / sizeof(u64);
 
 	if (pageCount > pfnCount) // we need a gpadl body
 	{
 		// fill in the header
-		msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pfnCount*sizeof(UINT64);
+		msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pfnCount*sizeof(u64);
 		msgHeader =  MemAllocZeroed(msgSize);
 
 		INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList);
@@ -429,7 +429,7 @@ VmbusChannelCreateGpadlHeader(
 
 		gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg;
 		gpaHeader->RangeCount = 1;
-		gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(UINT64);
+		gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(u64);
 		gpaHeader->Range[0].ByteOffset = 0;
 		gpaHeader->Range[0].ByteCount = Size;
 		for (i=0; i<pfnCount; i++)
@@ -444,7 +444,7 @@ VmbusChannelCreateGpadlHeader(
 
 		// how many pfns can we fit
 		pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_BODY);
-		pfnCount = pfnSize / sizeof(UINT64);
+		pfnCount = pfnSize / sizeof(u64);
 
 		// fill in the body
 		while (pfnLeft)
@@ -458,7 +458,7 @@ VmbusChannelCreateGpadlHeader(
 				pfnCurr = pfnLeft;
 			}
 
-			msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_BODY) + pfnCurr*sizeof(UINT64);
+			msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_BODY) + pfnCurr*sizeof(u64);
 			msgBody =  MemAllocZeroed(msgSize);
 			ASSERT(msgBody);
 			msgBody->MessageSize = msgSize;
@@ -481,13 +481,13 @@ VmbusChannelCreateGpadlHeader(
 	else
 	{
 		// everything fits in a header
-		msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pageCount*sizeof(UINT64);
+		msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pageCount*sizeof(u64);
 		msgHeader =  MemAllocZeroed(msgSize);
 		msgHeader->MessageSize=msgSize;
 
 		gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg;
 		gpaHeader->RangeCount = 1;
-		gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(UINT64);
+		gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(u64);
 		gpaHeader->Range[0].ByteOffset = 0;
 		gpaHeader->Range[0].ByteCount = Size;
 		for (i=0; i<pageCount; i++)
@@ -754,7 +754,7 @@ VmbusChannelSendPacket(
 	VMBUS_CHANNEL		*Channel,
 	const void *			Buffer,
 	u32				BufferLen,
-	UINT64				RequestId,
+	u64				RequestId,
 	VMBUS_PACKET_TYPE	Type,
 	u32				Flags
 )
@@ -762,16 +762,16 @@ VmbusChannelSendPacket(
 	int ret=0;
 	VMPACKET_DESCRIPTOR desc;
 	u32 packetLen = sizeof(VMPACKET_DESCRIPTOR) + BufferLen;
-	u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(UINT64));
+	u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
 	SG_BUFFER_LIST bufferList[3];
-	UINT64 alignedData=0;
+	u64 alignedData=0;
 
 	DPRINT_ENTER(VMBUS);
 	DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", Channel, Buffer, BufferLen);
 
 	DumpVmbusChannel(Channel);
 
-	ASSERT((packetLenAligned - packetLen) < sizeof(UINT64));
+	ASSERT((packetLenAligned - packetLen) < sizeof(u64));
 
 	// Setup the descriptor
 	desc.Type = Type;//VmbusPacketTypeDataInBand;
@@ -822,7 +822,7 @@ VmbusChannelSendPacketPageBuffer(
 	u32				PageCount,
 	void *				Buffer,
 	u32				BufferLen,
-	UINT64				RequestId
+	u64				RequestId
 )
 {
 	int ret=0;
@@ -832,7 +832,7 @@ VmbusChannelSendPacketPageBuffer(
 	u32 packetLen;
 	u32 packetLenAligned;
 	SG_BUFFER_LIST bufferList[3];
-	UINT64 alignedData=0;
+	u64 alignedData=0;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -843,9 +843,9 @@ VmbusChannelSendPacketPageBuffer(
 	// Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the largest size we support
 	descSize = sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - ((MAX_PAGE_BUFFER_COUNT - PageCount)*sizeof(PAGE_BUFFER));
 	packetLen = descSize + BufferLen;
-	packetLenAligned = ALIGN_UP(packetLen, sizeof(UINT64));
+	packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
 
-	ASSERT((packetLenAligned - packetLen) < sizeof(UINT64));
+	ASSERT((packetLenAligned - packetLen) < sizeof(u64));
 
 	// Setup the descriptor
 	desc.Type = VmbusPacketTypeDataUsingGpaDirect;
@@ -904,7 +904,7 @@ VmbusChannelSendPacketMultiPageBuffer(
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
 	void *				Buffer,
 	u32				BufferLen,
-	UINT64				RequestId
+	u64				RequestId
 )
 {
 	int ret=0;
@@ -913,7 +913,7 @@ VmbusChannelSendPacketMultiPageBuffer(
 	u32 packetLen;
 	u32 packetLenAligned;
 	SG_BUFFER_LIST bufferList[3];
-	UINT64 alignedData=0;
+	u64 alignedData=0;
 	u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length);
 
 	DPRINT_ENTER(VMBUS);
@@ -926,11 +926,11 @@ VmbusChannelSendPacketMultiPageBuffer(
 	ASSERT(PfnCount <= MAX_MULTIPAGE_BUFFER_COUNT);
 
 	// Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is the largest size we support
-	descSize = sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount)*sizeof(UINT64));
+	descSize = sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount)*sizeof(u64));
 	packetLen = descSize + BufferLen;
-	packetLenAligned = ALIGN_UP(packetLen, sizeof(UINT64));
+	packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
 
-	ASSERT((packetLenAligned - packetLen) < sizeof(UINT64));
+	ASSERT((packetLenAligned - packetLen) < sizeof(u64));
 
 	// Setup the descriptor
 	desc.Type = VmbusPacketTypeDataUsingGpaDirect;
@@ -943,7 +943,7 @@ VmbusChannelSendPacketMultiPageBuffer(
 	desc.Range.Length = MultiPageBuffer->Length;
 	desc.Range.Offset = MultiPageBuffer->Offset;
 
-	memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(UINT64));
+	memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(u64));
 
 	bufferList[0].Data = &desc;
 	bufferList[0].Length = descSize;
@@ -987,7 +987,7 @@ VmbusChannelRecvPacket(
 	void *				Buffer,
 	u32				BufferLen,
 	u32*				BufferActualLen,
-	UINT64*				RequestId
+	u64*				RequestId
 	)
 {
 	VMPACKET_DESCRIPTOR desc;
@@ -1064,7 +1064,7 @@ VmbusChannelRecvPacketRaw(
 	void *				Buffer,
 	u32				BufferLen,
 	u32*				BufferActualLen,
-	UINT64*				RequestId
+	u64*				RequestId
 	)
 {
 	VMPACKET_DESCRIPTOR desc;
--- a/drivers/staging/hv/Channel.h
+++ b/drivers/staging/hv/Channel.h
@@ -37,7 +37,7 @@ typedef struct _VMBUS_CHANNEL_PACKET_PAG
     u16				DataOffset8;
     u16				Length8;
     u16				Flags;
-    UINT64				TransactionId;
+    u64				TransactionId;
 	u32				Reserved;
 	u32				RangeCount;
     PAGE_BUFFER			Range[MAX_PAGE_BUFFER_COUNT];
@@ -50,7 +50,7 @@ typedef struct _VMBUS_CHANNEL_PACKET_MUL
     u16				DataOffset8;
     u16				Length8;
     u16				Flags;
-    UINT64				TransactionId;
+    u64				TransactionId;
 	u32				Reserved;
 	u32				RangeCount;		// Always 1 in this case
 	MULTIPAGE_BUFFER	Range;
@@ -83,7 +83,7 @@ VmbusChannelSendPacket(
 	VMBUS_CHANNEL		*Channel,
 	const void *			Buffer,
 	u32				BufferLen,
-	UINT64				RequestId,
+	u64				RequestId,
 	VMBUS_PACKET_TYPE	Type,
 	u32				Flags
 );
@@ -95,7 +95,7 @@ VmbusChannelSendPacketPageBuffer(
 	u32				PageCount,
 	void *				Buffer,
 	u32				BufferLen,
-	UINT64				RequestId
+	u64				RequestId
 	);
 
 static int
@@ -104,7 +104,7 @@ VmbusChannelSendPacketMultiPageBuffer(
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
 	void *				Buffer,
 	u32				BufferLen,
-	UINT64				RequestId
+	u64				RequestId
 );
 
 static int
@@ -127,7 +127,7 @@ VmbusChannelRecvPacket(
 	void *				Buffer,
 	u32				BufferLen,
 	u32*				BufferActualLen,
-	UINT64*				RequestId
+	u64*				RequestId
 	);
 
 static int
@@ -136,7 +136,7 @@ VmbusChannelRecvPacketRaw(
 	void *				Buffer,
 	u32				BufferLen,
 	u32*				BufferActualLen,
-	UINT64*				RequestId
+	u64*				RequestId
 	);
 
 static void
--- a/drivers/staging/hv/ChannelInterface.c
+++ b/drivers/staging/hv/ChannelInterface.c
@@ -58,7 +58,7 @@ IVmbusChannelSendPacket(
 	PDEVICE_OBJECT		Device,
 	const void *			Buffer,
 	u32				BufferLen,
-	UINT64				RequestId,
+	u64				RequestId,
 	u32				Type,
 	u32				Flags
 	)
@@ -78,7 +78,7 @@ IVmbusChannelSendPacketPageBuffer(
 	u32				PageCount,
 	void *				Buffer,
 	u32				BufferLen,
-	UINT64				RequestId
+	u64				RequestId
 	)
 {
 	return VmbusChannelSendPacketPageBuffer((VMBUS_CHANNEL*)Device->context,
@@ -95,7 +95,7 @@ IVmbusChannelSendPacketMultiPageBuffer(
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
 	void *				Buffer,
 	u32				BufferLen,
-	UINT64				RequestId
+	u64				RequestId
 	)
 {
 	return VmbusChannelSendPacketMultiPageBuffer((VMBUS_CHANNEL*)Device->context,
@@ -111,7 +111,7 @@ IVmbusChannelRecvPacket (
 	void *				Buffer,
 	u32				BufferLen,
 	u32*				BufferActualLen,
-	UINT64*				RequestId
+	u64*				RequestId
 	)
 {
 	return VmbusChannelRecvPacket((VMBUS_CHANNEL*)Device->context,
@@ -127,7 +127,7 @@ IVmbusChannelRecvPacketRaw(
 	void *				Buffer,
 	u32				BufferLen,
 	u32*				BufferActualLen,
-	UINT64*				RequestId
+	u64*				RequestId
 	)
 {
 	return VmbusChannelRecvPacketRaw((VMBUS_CHANNEL*)Device->context,
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -158,17 +158,17 @@ Description:
 	Invoke the specified hypercall
 
 --*/
-static UINT64
+static u64
 HvDoHypercall (
-    UINT64  Control,
+    u64  Control,
     void*   Input,
     void*   Output
     )
 {
 #ifdef CONFIG_X86_64
-    UINT64 hvStatus=0;
-    UINT64 inputAddress = (Input)? GetPhysicalAddress(Input) : 0;
-	UINT64 outputAddress = (Output)? GetPhysicalAddress(Output) : 0;
+    u64 hvStatus=0;
+    u64 inputAddress = (Input)? GetPhysicalAddress(Input) : 0;
+	u64 outputAddress = (Output)? GetPhysicalAddress(Output) : 0;
     volatile void* hypercallPage = gHvContext.HypercallPage;
 
     DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p output phys %llx virt %p hypercall %p>",
@@ -192,10 +192,10 @@ HvDoHypercall (
     u32 controlLo = Control & 0xFFFFFFFF;
     u32 hvStatusHi = 1;
     u32 hvStatusLo = 1;
-    UINT64 inputAddress = (Input) ? GetPhysicalAddress(Input) : 0;
+    u64 inputAddress = (Input) ? GetPhysicalAddress(Input) : 0;
     u32 inputAddressHi = inputAddress >> 32;
     u32 inputAddressLo = inputAddress & 0xFFFFFFFF;
-	UINT64 outputAddress = (Output) ?GetPhysicalAddress(Output) : 0;
+	u64 outputAddress = (Output) ?GetPhysicalAddress(Output) : 0;
     u32 outputAddressHi = outputAddress >> 32;
     u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
     volatile void* hypercallPage = gHvContext.HypercallPage;
@@ -208,9 +208,9 @@ HvDoHypercall (
 	__asm__ __volatile__ ("call *%8" : "=d"(hvStatusHi), "=a"(hvStatusLo) : "d" (controlHi), "a" (controlLo), "b" (inputAddressHi), "c" (inputAddressLo), "D"(outputAddressHi), "S"(outputAddressLo), "m" (hypercallPage));
 
 
-    DPRINT_DBG(VMBUS, "Hypercall <return %llx>",  hvStatusLo | ((UINT64)hvStatusHi << 32));
+    DPRINT_DBG(VMBUS, "Hypercall <return %llx>",  hvStatusLo | ((u64)hvStatusHi << 32));
 
-    return (hvStatusLo | ((UINT64)hvStatusHi << 32));
+    return (hvStatusLo | ((u64)hvStatusHi << 32));
 #endif // x86_64
 }
 
@@ -401,7 +401,7 @@ HvPostMessage(
 	)
 {
 	struct alignedInput {
-		UINT64					alignment8;
+		u64					alignment8;
 		HV_INPUT_POST_MESSAGE	msg;
 	};
 
@@ -474,12 +474,12 @@ HvSynicInit (
 	u32 irqVector
 	)
 {
-	UINT64			version;
+	u64			version;
 	HV_SYNIC_SIMP	simp;
 	HV_SYNIC_SIEFP	siefp;
     HV_SYNIC_SINT	sharedSint;
 	HV_SYNIC_SCONTROL sctrl;
-	UINT64			guestID;
+	u64			guestID;
 	int ret=0;
 
 	DPRINT_ENTER(VMBUS);
--- a/drivers/staging/hv/Hv.h
+++ b/drivers/staging/hv/Hv.h
@@ -60,11 +60,11 @@ enum
 
 #define HV_XENLINUX_GUEST_ID_LO     0x00000000
 #define HV_XENLINUX_GUEST_ID_HI		0x0B00B135
-#define HV_XENLINUX_GUEST_ID		(((UINT64)HV_XENLINUX_GUEST_ID_HI << 32) | HV_XENLINUX_GUEST_ID_LO)
+#define HV_XENLINUX_GUEST_ID		(((u64)HV_XENLINUX_GUEST_ID_HI << 32) | HV_XENLINUX_GUEST_ID_LO)
 
 #define HV_LINUX_GUEST_ID_LO		0x00000000
 #define HV_LINUX_GUEST_ID_HI		0xB16B00B5
-#define HV_LINUX_GUEST_ID			(((UINT64)HV_LINUX_GUEST_ID_HI << 32) | HV_LINUX_GUEST_ID_LO)
+#define HV_LINUX_GUEST_ID			(((u64)HV_LINUX_GUEST_ID_HI << 32) | HV_LINUX_GUEST_ID_LO)
 
 #define HV_CPU_POWER_MANAGEMENT     (1 << 0)
 #define HV_RECOMMENDATIONS_MAX      4
@@ -73,7 +73,7 @@ enum
 #define HV_CAPS_MAX                 8
 
 
-#define HV_HYPERCALL_PARAM_ALIGN	sizeof(UINT64)
+#define HV_HYPERCALL_PARAM_ALIGN	sizeof(u64)
 
 //
 // Service definitions
@@ -105,12 +105,12 @@ static const GUID VMBUS_SERVICE_ID = {.D
 
 
 typedef struct {
-	UINT64					Align8;
+	u64					Align8;
 	HV_INPUT_SIGNAL_EVENT	Event;
 } HV_INPUT_SIGNAL_EVENT_BUFFER;
 
 typedef struct {
-	UINT64	GuestId;			// XenLinux or native Linux. If XenLinux, the hypercall and synic pages has already been initialized
+	u64	GuestId;			// XenLinux or native Linux. If XenLinux, the hypercall and synic pages has already been initialized
 	void*	HypercallPage;
 
 	BOOL	SynICInitialized;
@@ -138,7 +138,7 @@ static inline unsigned long long ReadMsr
 	return val;
 }
 
-static inline void WriteMsr(int msr, UINT64 val)
+static inline void WriteMsr(int msr, u64 val)
 {
 	WRMSR(msr, val);
 
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -114,7 +114,7 @@ NetVscOnReceiveCompletion(
 static void
 NetVscSendReceiveCompletion(
 	DEVICE_OBJECT	*Device,
-	UINT64			TransactionId
+	u64			TransactionId
 	);
 
 static inline NETVSC_DEVICE* AllocNetDevice(DEVICE_OBJECT *Device)
@@ -1286,7 +1286,7 @@ NetVscOnReceive(
 static void
 NetVscSendReceiveCompletion(
 	DEVICE_OBJECT	*Device,
-	UINT64			TransactionId
+	u64			TransactionId
 	)
 {
 	NVSP_MESSAGE recvcompMessage;
@@ -1343,7 +1343,7 @@ NetVscOnReceiveCompletion(
 	NETVSC_PACKET *packet = (NETVSC_PACKET*)Context;
 	DEVICE_OBJECT *device = (DEVICE_OBJECT*)packet->Device;
 	NETVSC_DEVICE* netDevice;
-	UINT64	transactionId=0;
+	u64	transactionId=0;
 	BOOL fSendReceiveComp = FALSE;
 
 	DPRINT_ENTER(NETVSC);
@@ -1403,10 +1403,10 @@ NetVscOnChannelCallback(
 	NETVSC_DEVICE *netDevice;
 
 	u32 bytesRecvd;
-	UINT64 requestId;
-	UCHAR packet[netPacketSize];
+	u64 requestId;
+	unsigned char packet[netPacketSize];
 	VMPACKET_DESCRIPTOR *desc;
-	UCHAR	*buffer=packet;
+	unsigned char	*buffer=packet;
 	int		bufferlen=netPacketSize;
 
 
--- a/drivers/staging/hv/NetVsc.h
+++ b/drivers/staging/hv/NetVsc.h
@@ -82,7 +82,7 @@ typedef struct _NETVSC_DEVICE {
 	NVSP_MESSAGE					ChannelInitPacket;
 
 	NVSP_MESSAGE					RevokePacket;
-	//UCHAR							HwMacAddr[HW_MACADDR_LEN];
+	//unsigned char							HwMacAddr[HW_MACADDR_LEN];
 
 	// Holds rndis device info
 	void							*Extension;
--- a/drivers/staging/hv/RingBuffer.c
+++ b/drivers/staging/hv/RingBuffer.c
@@ -184,13 +184,13 @@ Name:
 	GetRingBufferIndices()
 
 Description:
-	Get the read and write indices as UINT64 of the specified ring buffer
+	Get the read and write indices as u64 of the specified ring buffer
 
 --*/
-static inline UINT64
+static inline u64
 GetRingBufferIndices(RING_BUFFER_INFO* RingInfo)
 {
-	return ((UINT64)RingInfo->RingBuffer->WriteIndex << 32) || RingInfo->RingBuffer->ReadIndex;
+	return ((u64)RingInfo->RingBuffer->WriteIndex << 32) || RingInfo->RingBuffer->ReadIndex;
 }
 
 
@@ -359,7 +359,7 @@ RingBufferWrite(
 	u32 totalBytesToWrite=0;
 
 	volatile u32 nextWriteLocation;
-	UINT64 prevIndices=0;
+	u64 prevIndices=0;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -368,7 +368,7 @@ RingBufferWrite(
 		totalBytesToWrite += SgBuffers[i].Length;
 	}
 
-	totalBytesToWrite += sizeof(UINT64);
+	totalBytesToWrite += sizeof(u64);
 
 	SpinlockAcquire(OutRingInfo->RingLock);
 
@@ -408,7 +408,7 @@ RingBufferWrite(
 	nextWriteLocation = CopyToRingBuffer(OutRingInfo,
 												nextWriteLocation,
 												&prevIndices,
-												sizeof(UINT64));
+												sizeof(u64));
 
 	// Make sure we flush all writes before updating the writeIndex
 	MemoryFence();
@@ -494,7 +494,7 @@ RingBufferRead(
 	u32 bytesAvailToWrite;
 	u32 bytesAvailToRead;
 	u32 nextReadLocation=0;
-	UINT64 prevIndices=0;
+	u64 prevIndices=0;
 
 	ASSERT(BufferLen > 0);
 
@@ -525,7 +525,7 @@ RingBufferRead(
 
 	nextReadLocation = CopyFromRingBuffer(InRingInfo,
 											&prevIndices,
-											sizeof(UINT64),
+											sizeof(u64),
 											nextReadLocation);
 
 	// Make sure all reads are done before we update the read index since
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -56,7 +56,7 @@ typedef struct _RNDIS_DEVICE {
 	HANDLE					RequestLock;
 	LIST_ENTRY				RequestList;
 
-	UCHAR					HwMacAddr[HW_MACADDR_LEN];
+	unsigned char					HwMacAddr[HW_MACADDR_LEN];
 } RNDIS_DEVICE;
 
 
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -63,8 +63,8 @@ typedef struct _STORVSC_DEVICE{
 	//  Each unique Port/Path/Target represents 1 channel ie scsi controller. In reality, the pathid, targetid is always 0
 	// and the port is set by us
 	ULONG						PortNumber;
-    UCHAR						PathId;
-    UCHAR						TargetId;
+    unsigned char						PathId;
+    unsigned char						TargetId;
 
 	//LIST_ENTRY					OutstandingRequestList;
 	//HANDLE						OutstandingRequestLock;
@@ -279,9 +279,9 @@ StorVscInitialize(
 	storDriver->RequestExtSize			= sizeof(STORVSC_REQUEST_EXTENSION);
 
 	// Divide the ring buffer data size (which is 1 page less than the ring buffer size since that page is reserved for the ring buffer indices)
-	// by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + UINT64)
+	// by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + u64)
 	storDriver->MaxOutstandingRequestsPerChannel =
-		((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(UINT64),sizeof(UINT64)));
+		((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(u64),sizeof(u64)));
 
 	DPRINT_INFO(STORVSC, "max io %u, currently %u\n", storDriver->MaxOutstandingRequestsPerChannel, STORVSC_MAX_IO_REQUESTS);
 
@@ -909,8 +909,8 @@ StorVscOnChannelCallback(
 	DEVICE_OBJECT *device = (DEVICE_OBJECT*)Context;
 	STORVSC_DEVICE *storDevice;
 	u32 bytesRecvd;
-	UINT64 requestId;
-	UCHAR packet[ALIGN_UP(sizeof(VSTOR_PACKET),8)];
+	u64 requestId;
+	unsigned char packet[ALIGN_UP(sizeof(VSTOR_PACKET),8)];
 	STORVSC_REQUEST_EXTENSION *request;
 
 	DPRINT_ENTER(STORVSC);
--- a/drivers/staging/hv/include/ChannelMessages.h
+++ b/drivers/staging/hv/include/ChannelMessages.h
@@ -148,7 +148,7 @@ typedef struct _VMBUS_CHANNEL_OPEN_CHANN
     //
     // User-specific data to be passed along to the server endpoint.
     //
-    UCHAR           UserData[MAX_USER_DEFINED_BYTES];
+    unsigned char           UserData[MAX_USER_DEFINED_BYTES];
 
 } VMBUS_CHANNEL_OPEN_CHANNEL, *PVMBUS_CHANNEL_OPEN_CHANNEL;
 
@@ -203,7 +203,7 @@ typedef struct _VMBUS_CHANNEL_GPADL_BODY
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
     u32              MessageNumber;
     u32              Gpadl;
-    UINT64              Pfn[0];
+    u64              Pfn[0];
 } VMBUS_CHANNEL_GPADL_BODY, *PVMBUS_CHANNEL_GPADL_BODY;
 
 
@@ -233,7 +233,7 @@ typedef struct _VMBUS_CHANNEL_VIEW_RANGE
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
     PHYSICAL_ADDRESS    ViewRangeBase;
-    UINT64              ViewRangeLength;
+    u64              ViewRangeLength;
     u32              ChildRelId;
 } VMBUS_CHANNEL_VIEW_RANGE_ADD, *PVMBUS_CHANNEL_VIEW_RANGE_ADD;
 
@@ -256,9 +256,9 @@ typedef struct _VMBUS_CHANNEL_INITIATE_C
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
     u32              VMBusVersionRequested;
     u32              Padding2;
-    UINT64              InterruptPage;
-    UINT64              MonitorPage1;
-    UINT64              MonitorPage2;
+    u64              InterruptPage;
+    u64              MonitorPage1;
+    u64              MonitorPage2;
 } VMBUS_CHANNEL_INITIATE_CONTACT, *PVMBUS_CHANNEL_INITIATE_CONTACT;
 
 typedef struct _VMBUS_CHANNEL_VERSION_RESPONSE
--- a/drivers/staging/hv/include/HvHalApi.h
+++ b/drivers/staging/hv/include/HvHalApi.h
@@ -28,5 +28,5 @@
 //
 // Time in the hypervisor is measured in 100 nanosecond units
 //
-typedef UINT64 HV_NANO100_TIME,     *PHV_NANO100_TIME;
-typedef UINT64 HV_NANO100_DURATION, *PHV_NANO100_DURATION;
+typedef u64 HV_NANO100_TIME,     *PHV_NANO100_TIME;
+typedef u64 HV_NANO100_DURATION, *PHV_NANO100_DURATION;
--- a/drivers/staging/hv/include/HvHcApi.h
+++ b/drivers/staging/hv/include/HvHcApi.h
@@ -44,7 +44,7 @@ typedef struct _HV_INPUT_POST_MESSAGE
     u32              Reserved;
     HV_MESSAGE_TYPE     MessageType;
     u32              PayloadSize;
-    UINT64              Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
+    u64              Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
 } HV_INPUT_POST_MESSAGE, *PHV_INPUT_POST_MESSAGE;
 
 
--- a/drivers/staging/hv/include/HvPtApi.h
+++ b/drivers/staging/hv/include/HvPtApi.h
@@ -57,15 +57,15 @@ typedef enum _HV_GUEST_OS_MICROSOFT_IDS
 
 typedef union _HV_X64_MSR_GUEST_OS_ID_CONTENTS
 {
-    UINT64 AsUINT64;
+    u64 AsUINT64;
     struct
     {
-        UINT64 BuildNumber    : 16;
-        UINT64 ServiceVersion : 8; // Service Pack, etc.
-        UINT64 MinorVersion   : 8;
-        UINT64 MajorVersion   : 8;
-        UINT64 OsId           : 8; // HV_GUEST_OS_MICROSOFT_IDS (If Vendor=MS)
-        UINT64 VendorId       : 16; // HV_GUEST_OS_VENDOR
+        u64 BuildNumber    : 16;
+        u64 ServiceVersion : 8; // Service Pack, etc.
+        u64 MinorVersion   : 8;
+        u64 MajorVersion   : 8;
+        u64 OsId           : 8; // HV_GUEST_OS_MICROSOFT_IDS (If Vendor=MS)
+        u64 VendorId       : 16; // HV_GUEST_OS_VENDOR
     };
 } HV_X64_MSR_GUEST_OS_ID_CONTENTS, *PHV_X64_MSR_GUEST_OS_ID_CONTENTS;
 
@@ -76,11 +76,11 @@ typedef union _HV_X64_MSR_GUEST_OS_ID_CO
 
 typedef union _HV_X64_MSR_HYPERCALL_CONTENTS
 {
-    UINT64 AsUINT64;
+    u64 AsUINT64;
     struct
     {
-        UINT64 Enable               : 1;
-        UINT64 Reserved             : 11;
-        UINT64 GuestPhysicalAddress : 52;
+        u64 Enable               : 1;
+        u64 Reserved             : 11;
+        u64 GuestPhysicalAddress : 52;
     };
 } HV_X64_MSR_HYPERCALL_CONTENTS, *PHV_X64_MSR_HYPERCALL_CONTENTS;
--- a/drivers/staging/hv/include/HvSynicApi.h
+++ b/drivers/staging/hv/include/HvSynicApi.h
@@ -145,7 +145,7 @@ typedef u32 HV_SYNIC_SINT_INDEX, *PHV_SY
 // Define partition identifier type.
 //
 
-typedef UINT64 HV_PARTITION_ID, *PHV_PARTITION_ID;
+typedef u64 HV_PARTITION_ID, *PHV_PARTITION_ID;
 
 //
 // Define invalid partition identifier.
@@ -210,7 +210,7 @@ typedef struct _HV_PORT_INFO
         {
             HV_SYNIC_SINT_INDEX TargetSint;
             HV_VP_INDEX TargetVp;
-            UINT64 RsvdZ;
+            u64 RsvdZ;
         } MessagePortInfo;
 
         struct
@@ -225,7 +225,7 @@ typedef struct _HV_PORT_INFO
         struct
         {
             HV_GPA MonitorAddress;
-            UINT64 RsvdZ;
+            u64 RsvdZ;
         } MonitorPortInfo;
     };
 } HV_PORT_INFO, *PHV_PORT_INFO;
@@ -241,12 +241,12 @@ typedef struct _HV_CONNECTION_INFO
     {
         struct
         {
-            UINT64 RsvdZ;
+            u64 RsvdZ;
         } MessageConnectionInfo;
 
         struct
         {
-            UINT64 RsvdZ;
+            u64 RsvdZ;
         } EventConnectionInfo;
 
         struct
@@ -311,7 +311,7 @@ typedef struct _HV_MESSAGE
     HV_MESSAGE_HEADER Header;
     union
     {
-        UINT64 Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
+        u64 Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
     } u ;
 } HV_MESSAGE, *PHV_MESSAGE;
 
@@ -357,11 +357,11 @@ typedef struct _HV_SYNIC_EVENT_FLAGS_PAG
 //
 typedef union _HV_SYNIC_SCONTROL
 {
-    UINT64 AsUINT64;
+    u64 AsUINT64;
     struct
     {
-        UINT64 Enable:1;
-        UINT64 Reserved:63;
+        u64 Enable:1;
+        u64 Reserved:63;
     };
 } HV_SYNIC_SCONTROL, *PHV_SYNIC_SCONTROL;
 
@@ -371,14 +371,14 @@ typedef union _HV_SYNIC_SCONTROL
 
 typedef union _HV_SYNIC_SINT
 {
-    UINT64 AsUINT64;
+    u64 AsUINT64;
     struct
     {
-        UINT64 Vector    :8;
-        UINT64 Reserved1 :8;
-        UINT64 Masked    :1;
-        UINT64 AutoEoi   :1;
-        UINT64 Reserved2 :46;
+        u64 Vector    :8;
+        u64 Reserved1 :8;
+        u64 Masked    :1;
+        u64 AutoEoi   :1;
+        u64 Reserved2 :46;
     };
 } HV_SYNIC_SINT, *PHV_SYNIC_SINT;
 
@@ -388,12 +388,12 @@ typedef union _HV_SYNIC_SINT
 
 typedef union _HV_SYNIC_SIMP
 {
-    UINT64 AsUINT64;
+    u64 AsUINT64;
     struct
     {
-        UINT64 SimpEnabled : 1;
-        UINT64 Preserved   : 11;
-        UINT64 BaseSimpGpa : 52;
+        u64 SimpEnabled : 1;
+        u64 Preserved   : 11;
+        u64 BaseSimpGpa : 52;
     };
 } HV_SYNIC_SIMP, *PHV_SYNIC_SIMP;
 
@@ -403,12 +403,12 @@ typedef union _HV_SYNIC_SIMP
 
 typedef union _HV_SYNIC_SIEFP
 {
-    UINT64 AsUINT64;
+    u64 AsUINT64;
     struct
     {
-        UINT64 SiefpEnabled : 1;
-        UINT64 Preserved   : 11;
-        UINT64 BaseSiefpGpa : 52;
+        u64 SiefpEnabled : 1;
+        u64 Preserved   : 11;
+        u64 BaseSiefpGpa : 52;
     };
 } HV_SYNIC_SIEFP, *PHV_SYNIC_SIEFP;
 
@@ -418,7 +418,7 @@ typedef union _HV_SYNIC_SIEFP
 
 typedef union _HV_MONITOR_TRIGGER_GROUP
 {
-    UINT64 AsUINT64;
+    u64 AsUINT64;
 
     struct
     {
@@ -474,12 +474,12 @@ typedef struct _HV_MONITOR_PAGE
     u32                   RsvdZ1;
 
     HV_MONITOR_TRIGGER_GROUP TriggerGroup[4];
-    UINT64                   RsvdZ2[3];
+    u64                   RsvdZ2[3];
 
     s32                    NextCheckTime[4][32];
 
     u16                   Latency[4][32];
-    UINT64                   RsvdZ3[32];
+    u64                   RsvdZ3[32];
 
     HV_MONITOR_PARAMETER     Parameter[4][32];
 
--- a/drivers/staging/hv/include/HvTypes.h
+++ b/drivers/staging/hv/include/HvTypes.h
@@ -24,7 +24,7 @@
 
 #pragma once
 
-typedef UINT64 HV_GPA, *PHV_GPA;
+typedef u64 HV_GPA, *PHV_GPA;
 
 #define HV_X64_PAGE_SIZE (4096)
 #define HV_PAGE_SIZE HV_X64_PAGE_SIZE
--- a/drivers/staging/hv/include/List.h
+++ b/drivers/staging/hv/include/List.h
@@ -260,8 +260,8 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 #ifndef CONTAINING_RECORD
 #define CONTAINING_RECORD(address, type, field) ((type *)( \
-                                                  (PCHAR)(address) - \
-                                                  (PCHAR)(&((type *)0)->field)))
+                                                  (char *)(address) - \
+                                                  (char *)(&((type *)0)->field)))
 #endif /* CONTAINING_RECORD */
 
 #endif /* _LIST_H_ */
--- a/drivers/staging/hv/include/NetVscApi.h
+++ b/drivers/staging/hv/include/NetVscApi.h
@@ -79,12 +79,12 @@ typedef struct _NETVSC_PACKET {
 
 	union {
 		struct{
-			UINT64						ReceiveCompletionTid;
+			u64						ReceiveCompletionTid;
 			void *						ReceiveCompletionContext;
 			PFN_ON_SENDRECVCOMPLETION	OnReceiveCompletion;
 		} Recv;
 		struct{
-			UINT64						SendCompletionTid;
+			u64						SendCompletionTid;
 			void *						SendCompletionContext;
 			PFN_ON_SENDRECVCOMPLETION	OnSendCompletion;
 		} Send;
@@ -130,7 +130,7 @@ typedef struct _NETVSC_DRIVER_OBJECT {
 
 
 typedef struct _NETVSC_DEVICE_INFO {
-    UCHAR	MacAddr[6];
+    unsigned char	MacAddr[6];
     BOOL	LinkState;	// 0 - link up, 1 - link down
 } NETVSC_DEVICE_INFO;
 
--- a/drivers/staging/hv/include/StorVscApi.h
+++ b/drivers/staging/hv/include/StorVscApi.h
@@ -80,7 +80,7 @@ typedef struct _STORVSC_REQUEST {
 	u32					Status;
 	u32					BytesXfer;
 
-	UCHAR*					SenseBuffer;
+	unsigned char*					SenseBuffer;
 	u32					SenseBufferSize;
 
 	void *					Context;
@@ -118,8 +118,8 @@ typedef struct _STORVSC_DRIVER_OBJECT {
 
 typedef struct _STORVSC_DEVICE_INFO {
 	ULONG	PortNumber;
-    UCHAR	PathId;
-    UCHAR	TargetId;
+    unsigned char	PathId;
+    unsigned char	TargetId;
 } STORVSC_DEVICE_INFO;
 
 //
--- a/drivers/staging/hv/include/VmbusApi.h
+++ b/drivers/staging/hv/include/VmbusApi.h
@@ -51,7 +51,7 @@ typedef struct _DEVICE_OBJECT *PDEVICE_O
 typedef struct _PAGE_BUFFER {
 	u32	Length;
 	u32	Offset;
-	UINT64	Pfn;
+	u64	Pfn;
 } PAGE_BUFFER;
 
 // Multiple-page buffer
@@ -59,7 +59,7 @@ typedef struct _MULTIPAGE_BUFFER {
 	// Length and Offset determines the # of pfns in the array
 	u32	Length;
 	u32	Offset;
-	UINT64	PfnArray[MAX_MULTIPAGE_BUFFER_COUNT];
+	u64	PfnArray[MAX_MULTIPAGE_BUFFER_COUNT];
 }MULTIPAGE_BUFFER;
 
 //0x18 includes the proprietary packet header
@@ -108,7 +108,7 @@ typedef int	(*VMBUS_CHANNEL_SEND_PACKET)
 	PDEVICE_OBJECT		Device,
 	const void *			Buffer,
 	u32				BufferLen,
-	UINT64				RequestId,
+	u64				RequestId,
 	u32				Type,
 	u32				Flags
 );
@@ -119,7 +119,7 @@ typedef int	(*VMBUS_CHANNEL_SEND_PACKET_
 	u32				PageCount,
 	void *				Buffer,
 	u32				BufferLen,
-	UINT64				RequestId
+	u64				RequestId
 	);
 
 typedef int	(*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER)(
@@ -127,7 +127,7 @@ typedef int	(*VMBUS_CHANNEL_SEND_PACKET_
 	MULTIPAGE_BUFFER	*MultiPageBuffer,
 	void *				Buffer,
 	u32				BufferLen,
-	UINT64				RequestId
+	u64				RequestId
 );
 
 typedef int	(*VMBUS_CHANNEL_RECV_PACKET)(
@@ -135,7 +135,7 @@ typedef int	(*VMBUS_CHANNEL_RECV_PACKET)
 	void *				Buffer,
 	u32				BufferLen,
 	u32*				BufferActualLen,
-	UINT64*				RequestId
+	u64*				RequestId
 	);
 
 typedef int	(*VMBUS_CHANNEL_RECV_PACKET_PAW)(
@@ -143,7 +143,7 @@ typedef int	(*VMBUS_CHANNEL_RECV_PACKET_
 	void *				Buffer,
 	u32				BufferLen,
 	u32*				BufferActualLen,
-	UINT64*				RequestId
+	u64*				RequestId
 	);
 
 typedef int	(*VMBUS_CHANNEL_ESTABLISH_GPADL)(
--- a/drivers/staging/hv/include/VmbusChannelInterface.h
+++ b/drivers/staging/hv/include/VmbusChannelInterface.h
@@ -66,7 +66,7 @@ typedef struct
 
     GUID    InterfaceType;
     GUID    InterfaceInstance;
-    UINT64  InterruptLatencyIn100nsUnits;
+    u64  InterruptLatencyIn100nsUnits;
     u32  InterfaceRevision;
     u32  ServerContextAreaSize;  // in bytes
     u16  ChannelFlags;
@@ -79,7 +79,7 @@ typedef struct
         //
         struct
         {
-            UCHAR   UserDefined[MAX_USER_DEFINED_BYTES];
+            unsigned char   UserDefined[MAX_USER_DEFINED_BYTES];
         } Standard;
 
         //
@@ -90,7 +90,7 @@ typedef struct
         struct
         {
             u32  PipeMode;
-            UCHAR   UserDefined[MAX_PIPE_USER_DEFINED_BYTES];
+            unsigned char   UserDefined[MAX_PIPE_USER_DEFINED_BYTES];
         } Pipe;
     } u;
 	u32	Padding;
--- a/drivers/staging/hv/include/VmbusPacketFormat.h
+++ b/drivers/staging/hv/include/VmbusPacketFormat.h
@@ -83,7 +83,7 @@ typedef struct
     u16 DataOffset8;
     u16 Length8;
     u16 Flags;
-    UINT64 TransactionId;
+    u64 TransactionId;
 } VMPACKET_DESCRIPTOR, *PVMPACKET_DESCRIPTOR;
 
 typedef u32 PREVIOUS_PACKET_OFFSET, *PPREVIOUS_PACKET_OFFSET;
@@ -168,7 +168,7 @@ typedef struct _GPA_RANGE {
 
     u32  ByteCount;
     u32  ByteOffset;
-    UINT64  PfnArray[0];
+    u64  PfnArray[0];
 
 } GPA_RANGE, *PGPA_RANGE;
 
@@ -266,10 +266,10 @@ typedef struct _VMADDITIONAL_DATA {
 
 #endif
 
-    UINT64  TotalBytes;
+    u64  TotalBytes;
     u32  ByteOffset;
     u32  ByteCount;
-    UCHAR   Data[1];
+    unsigned char   Data[1];
 
 } VMADDITIONAL_DATA, *PVMADDITIONAL_DATA;
 
@@ -287,7 +287,7 @@ typedef union {
 } VMPACKET_LARGEST_POSSIBLE_HEADER, *PVMPACKET_LARGEST_POSSIBLE_HEADER;
 
 #define VMPACKET_DATA_START_ADDRESS(__packet)                           \
-    (void *)(((PUCHAR)__packet) + ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8 * 8)
+    (void *)(((unsigned char *)__packet) + ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8 * 8)
 
 #define VMPACKET_DATA_LENGTH(__packet)                                  \
     ((((PVMPACKET_DESCRIPTOR)__packet)->Length8 - ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8) * 8)
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -97,28 +97,15 @@ typedef struct _DLIST_ENTRY {
 //
 // unsigned types
 //
-#ifdef __x86_64__
-typedef unsigned long		UINT64;
-#else
-typedef unsigned long long	UINT64;
-#endif
 
 typedef unsigned long long	ULONGLONG;
 typedef unsigned int		ULONG;
 typedef unsigned short		USHORT;
-typedef unsigned char		UCHAR;
 
 //
 // signed types
 //
-#ifdef __x86_64__
-typedef long				INT64;
-#else
-typedef long long		INT64;
-#endif
-
 typedef int					LONG;
-typedef char				CHAR;
 typedef long long			LONGLONG;
 
 //
@@ -130,7 +117,6 @@ typedef unsigned char		BOOL;
 typedef unsigned char		BOOLEAN;
 typedef void*				HANDLE;
 typedef u32				DWORD;
-typedef char*				PCHAR;
 typedef unsigned char		BYTE;
 
 typedef unsigned long		ULONG_PTR;
@@ -150,13 +136,13 @@ typedef void (*PFN_TIMER_CALLBACK)(void*
      __asm__ __volatile__("rdmsr"                                                               \
     : "=a" (l), "=d" (h)                                                       \
     : "c" (reg));                                                              \
-    v = (((UINT64)h) << 32) | l;                                                         \
+    v = (((u64)h) << 32) | l;                                                         \
 }
 
 #define WRMSR(reg, v) {                                                        \
     u32 h, l;                                                               \
-    l = (u32)(((UINT64)(v)) & 0xFFFFFFFF);                                  \
-    h = (u32)((((UINT64)(v)) >> 32) & 0xFFFFFFFF);                          \
+    l = (u32)(((u64)(v)) & 0xFFFFFFFF);                                  \
+    h = (u32)((((u64)(v)) >> 32) & 0xFFFFFFFF);                          \
      __asm__ __volatile__("wrmsr"                                              \
     : /* no outputs */                                                         \
     : "c" (reg), "a" (l), "d" (h));                                            \
@@ -172,7 +158,7 @@ typedef void (*PFN_TIMER_CALLBACK)(void*
 #define WRMSR(reg, v) 			                                               \
      __asm__ __volatile__("wrmsr" 	                                           \
     : /* no outputs */ 				                                           \
-    : "c" (reg), "A" ((UINT64)v))
+    : "c" (reg), "A" ((u64)v))
 
 #endif
 
--- a/drivers/staging/hv/include/rndis.h
+++ b/drivers/staging/hv/include/rndis.h
@@ -811,19 +811,19 @@ typedef __struct_bcount(MessageLength) s
 
 // get pointer to info buffer with message pointer
 #define MESSAGE_TO_INFO_BUFFER(Message)                         \
-    (((PUCHAR)(Message)) + Message->InformationBufferOffset)
+    (((unsigned char *)(Message)) + Message->InformationBufferOffset)
 
 // get pointer to status buffer with message pointer
 #define MESSAGE_TO_STATUS_BUFFER(Message)                       \
-    (((PUCHAR)(Message)) + Message->StatusBufferOffset)
+    (((unsigned char *)(Message)) + Message->StatusBufferOffset)
 
 // get pointer to OOBD buffer with message pointer
 #define MESSAGE_TO_OOBD_BUFFER(Message)                         \
-    (((PUCHAR)(Message)) + Message->OOBDataOffset)
+    (((unsigned char *)(Message)) + Message->OOBDataOffset)
 
 // get pointer to data buffer with message pointer
 #define MESSAGE_TO_DATA_BUFFER(Message)                         \
-    (((PUCHAR)(Message)) + Message->PerPacketInfoOffset)
+    (((unsigned char *)(Message)) + Message->PerPacketInfoOffset)
 
 // get pointer to contained message from NDIS_MESSAGE pointer
 #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(RndisMessage)          \
--- a/drivers/staging/hv/include/vstorage.h
+++ b/drivers/staging/hv/include/vstorage.h
@@ -94,7 +94,7 @@
 #define MAX_TRANSFER_LENGTH 0x40000
 #define DEFAULT_PACKET_SIZE (sizeof(VMDATA_GPA_DIRECT) +                            \
                              sizeof(VSTOR_PACKET) +                                 \
-                             (sizeof(UINT64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
+                             (sizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
 
 
 
@@ -142,28 +142,28 @@ C_ASSERT(SENSE_BUFFER_SIZE == 0x12);
 typedef struct
 {
     USHORT Length;
-    UCHAR SrbStatus;
-    UCHAR ScsiStatus;
+    unsigned char SrbStatus;
+    unsigned char ScsiStatus;
 
-    UCHAR PortNumber;
-    UCHAR PathId;
-    UCHAR TargetId;
-    UCHAR Lun;
-
-    UCHAR CdbLength;
-    UCHAR SenseInfoLength;
-    UCHAR DataIn;
-    UCHAR Reserved;
+    unsigned char PortNumber;
+    unsigned char PathId;
+    unsigned char TargetId;
+    unsigned char Lun;
+
+    unsigned char CdbLength;
+    unsigned char SenseInfoLength;
+    unsigned char DataIn;
+    unsigned char Reserved;
 
     ULONG DataTransferLength;
 
     union
     {
-        UCHAR Cdb[CDB16GENERIC_LENGTH];
+        unsigned char Cdb[CDB16GENERIC_LENGTH];
 
-        UCHAR SenseData[SENSE_BUFFER_SIZE];
+        unsigned char SenseData[SENSE_BUFFER_SIZE];
 
-        UCHAR ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
+        unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
     };
 
 } VMSCSI_REQUEST, *PVMSCSI_REQUEST;
@@ -179,8 +179,8 @@ C_ASSERT((sizeof(VMSCSI_REQUEST) % 4) ==
 typedef struct
 {
     USHORT ProtocolVersion;
-    UCHAR  PathId;
-    UCHAR  TargetId;
+    unsigned char  PathId;
+    unsigned char  TargetId;
 
     //
     // Note: port number is only really known on the client side

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 24/54] Staging: hv: remove USHORT typedef
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (23 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-ushort-typedef.patch --]
[-- Type: text/plain, Size: 1543 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The USHORT typedef is now removed from the Hyper-V driver code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/include/osd.h      |    1 -
 drivers/staging/hv/include/vstorage.h |    8 ++++----
 2 files changed, 4 insertions(+), 5 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -100,7 +100,6 @@ typedef struct _DLIST_ENTRY {
 
 typedef unsigned long long	ULONGLONG;
 typedef unsigned int		ULONG;
-typedef unsigned short		USHORT;
 
 //
 // signed types
--- a/drivers/staging/hv/include/vstorage.h
+++ b/drivers/staging/hv/include/vstorage.h
@@ -141,7 +141,7 @@ C_ASSERT(SENSE_BUFFER_SIZE == 0x12);
 
 typedef struct
 {
-    USHORT Length;
+    unsigned short Length;
     unsigned char SrbStatus;
     unsigned char ScsiStatus;
 
@@ -178,7 +178,7 @@ C_ASSERT((sizeof(VMSCSI_REQUEST) % 4) ==
 
 typedef struct
 {
-    USHORT ProtocolVersion;
+    unsigned short ProtocolVersion;
     unsigned char  PathId;
     unsigned char  TargetId;
 
@@ -213,7 +213,7 @@ typedef struct
     // Major (MSW) and minor (LSW) version numbers.
     //
 
-    USHORT MajorMinor;
+    unsigned short MajorMinor;
 
 
     //
@@ -222,7 +222,7 @@ typedef struct
     // indicate incompatibility--but it does indicate mismatched builds.
     //
 
-    USHORT Revision;
+    unsigned short Revision;
 
 } VMSTORAGE_PROTOCOL_VERSION, *PVMSTORAGE_PROTOCOL_VERSION;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 25/54] Staging: hv: remove ULONGLONG and LONGLONG typedefs
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (24 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-ulonglong-and-longlong-typedefs.patch --]
[-- Type: text/plain, Size: 1523 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The ULONGLONG and LONGLONG typedefs are now removed from the Hyper-V
driver code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/include/VmbusPacketFormat.h |    2 +-
 drivers/staging/hv/include/osd.h               |    3 ---
 drivers/staging/hv/include/vstorage.h          |    2 +-
 3 files changed, 2 insertions(+), 5 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -97,15 +97,12 @@ typedef struct _DLIST_ENTRY {
 //
 // unsigned types
 //
-
-typedef unsigned long long	ULONGLONG;
 typedef unsigned int		ULONG;
 
 //
 // signed types
 //
 typedef int					LONG;
-typedef long long			LONGLONG;
 
 //
 // Other types
--- a/drivers/staging/hv/include/VmbusPacketFormat.h
+++ b/drivers/staging/hv/include/VmbusPacketFormat.h
@@ -44,7 +44,7 @@ typedef struct
             volatile u32  In;        // Offset in bytes from the ring base
             volatile u32  Out;       // Offset in bytes from the ring base
         };
-        volatile LONGLONG    InOut;
+        volatile long long InOut;
     };
 
     //
--- a/drivers/staging/hv/include/vstorage.h
+++ b/drivers/staging/hv/include/vstorage.h
@@ -196,7 +196,7 @@ typedef struct
     //  vendor specific data in the inquirydata
     //
 
-    ULONGLONG UniqueId;
+    unsigned long long UniqueId;
 
 } VMSTORAGE_CHANNEL_PROPERTIES, *PVMSTORAGE_CHANNEL_PROPERTIES;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 26/54] Staging: hv: remove ULONG_PTR typedef
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (25 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-ulong_ptr-typedef.patch --]
[-- Type: text/plain, Size: 18742 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The ULONG_PTR typedef is now removed from the Hyper-V driver code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Channel.c     |    4 ++--
 drivers/staging/hv/Connection.c  |    8 ++++----
 drivers/staging/hv/Hv.c          |    8 ++++----
 drivers/staging/hv/NetVsc.c      |   34 +++++++++++++++++-----------------
 drivers/staging/hv/RndisFilter.c |   16 ++++++++--------
 drivers/staging/hv/StorVsc.c     |   16 ++++++++--------
 drivers/staging/hv/include/osd.h |    8 +++-----
 drivers/staging/hv/netvsc_drv.c  |    4 ++--
 drivers/staging/hv/osd.c         |    8 ++++----
 9 files changed, 52 insertions(+), 54 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -228,9 +228,9 @@ VmbusChannelOpen(
 	out = PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT);
 	//out = MemAllocZeroed(sendRingBufferSize + recvRingBufferSize);
 	ASSERT(out);
-	ASSERT(((ULONG_PTR)out & (PAGE_SIZE-1)) == 0);
+	ASSERT(((unsigned long)out & (PAGE_SIZE-1)) == 0);
 
-	in = (void*)((ULONG_PTR)out + SendRingBufferSize);
+	in = (void*)((unsigned long)out + SendRingBufferSize);
 
 	NewChannel->RingBufferPages = out;
 	NewChannel->RingBufferPageCount = (SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT;
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -79,7 +79,7 @@ VmbusConnect(
 	}
 
 	gVmbusConnection.RecvInterruptPage = gVmbusConnection.InterruptPage;
-	gVmbusConnection.SendInterruptPage = (void*)((ULONG_PTR)gVmbusConnection.InterruptPage + (PAGE_SIZE >> 1));
+	gVmbusConnection.SendInterruptPage = (void*)((unsigned long)gVmbusConnection.InterruptPage + (PAGE_SIZE >> 1));
 
 	// Setup the monitor notification facility. The 1st page for parent->child and the 2nd page for child->parent
 	gVmbusConnection.MonitorPages = PageAlloc(2);
@@ -103,7 +103,7 @@ VmbusConnect(
 	msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER;
 	msg->InterruptPage = GetPhysicalAddress(gVmbusConnection.InterruptPage);
 	msg->MonitorPage1 = GetPhysicalAddress(gVmbusConnection.MonitorPages);
-	msg->MonitorPage2 = GetPhysicalAddress((void *)((ULONG_PTR)gVmbusConnection.MonitorPages + PAGE_SIZE));
+	msg->MonitorPage2 = GetPhysicalAddress((void *)((unsigned long)gVmbusConnection.MonitorPages + PAGE_SIZE));
 
 	// Add to list before we send the request since we may receive the response
 	// before returning from this routine
@@ -294,7 +294,7 @@ VmbusProcessChannelEvent(
 	)
 {
 	VMBUS_CHANNEL* channel;
-	u32 relId = (u32)(ULONG_PTR)context;
+	u32 relId = (u32)(unsigned long)context;
 
 	ASSERT(relId > 0);
 
@@ -362,7 +362,7 @@ VmbusOnEvents(
 						{
 							//QueueWorkItem(VmbusProcessEvent, (void*)relid);
 							//ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid);
-							VmbusProcessChannelEvent((void*)(ULONG_PTR)relid);
+							VmbusProcessChannelEvent((void*)(unsigned long)relid);
 						}
 					}
 				}
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -233,7 +233,7 @@ HvInit (
     int maxLeaf;
 	HV_X64_MSR_HYPERCALL_CONTENTS hypercallMsr;
 	void* virtAddr=0;
-	ULONG_PTR physAddr=0;
+	unsigned long physAddr=0;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -311,7 +311,7 @@ HvInit (
 		goto Cleanup;
 	}
 
-	gHvContext.SignalEventParam = (PHV_INPUT_SIGNAL_EVENT)(ALIGN_UP((ULONG_PTR)gHvContext.SignalEventBuffer, HV_HYPERCALL_PARAM_ALIGN));
+	gHvContext.SignalEventParam = (PHV_INPUT_SIGNAL_EVENT)(ALIGN_UP((unsigned long)gHvContext.SignalEventBuffer, HV_HYPERCALL_PARAM_ALIGN));
 	gHvContext.SignalEventParam->ConnectionId.Asu32 = 0;
 	gHvContext.SignalEventParam->ConnectionId.u.Id = VMBUS_EVENT_CONNECTION_ID;
 	gHvContext.SignalEventParam->FlagNumber = 0;
@@ -407,14 +407,14 @@ HvPostMessage(
 
 	PHV_INPUT_POST_MESSAGE alignedMsg;
 	HV_STATUS status;
-	ULONG_PTR addr;
+	unsigned long addr;
 
 	if (payloadSize > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
 	{
 		return -1;
 	}
 
-	addr = (ULONG_PTR)MemAllocAtomic(sizeof(struct alignedInput));
+	addr = (unsigned long)MemAllocAtomic(sizeof(struct alignedInput));
 
 	if (!addr)
 	{
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -115,8 +115,6 @@ typedef void*				HANDLE;
 typedef u32				DWORD;
 typedef unsigned char		BYTE;
 
-typedef unsigned long		ULONG_PTR;
-
 typedef struct {
 	unsigned char	Data[16];
 } GUID;
@@ -217,12 +215,12 @@ extern void	SpinlockRelease(HANDLE hSpin
 
 
 #define GetVirtualAddress Physical2LogicalAddr
-void* Physical2LogicalAddr(ULONG_PTR PhysAddr);
+void* Physical2LogicalAddr(unsigned long PhysAddr);
 
 #define GetPhysicalAddress Logical2PhysicalAddr
-ULONG_PTR Logical2PhysicalAddr(void * LogicalAddr);
+unsigned long Logical2PhysicalAddr(void * LogicalAddr);
 
-ULONG_PTR Virtual2Physical(void * VirtAddr);
+unsigned long Virtual2Physical(void * VirtAddr);
 
 void* PageMapVirtualAddress(unsigned long Pfn);
 void PageUnmapVirtualAddress(void* VirtAddr);
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -298,7 +298,7 @@ NetVscInitializeReceiveBufferWithNetVsp(
 		ret = -1;
 		goto Cleanup;
 	}
-	ASSERT(((ULONG_PTR)netDevice->ReceiveBuffer & (PAGE_SIZE-1)) == 0); // page-aligned buffer
+	ASSERT(((unsigned long)netDevice->ReceiveBuffer & (PAGE_SIZE-1)) == 0); // page-aligned buffer
 
 	DPRINT_INFO(NETVSC, "Establishing receive buffer's GPADL...");
 
@@ -333,7 +333,7 @@ NetVscInitializeReceiveBufferWithNetVsp(
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															initPacket,
 															sizeof(NVSP_MESSAGE),
-															(ULONG_PTR)initPacket,
+															(unsigned long)initPacket,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 	if (ret != 0)
@@ -425,7 +425,7 @@ NetVscInitializeSendBufferWithNetVsp(
 		ret = -1;
 		goto Cleanup;
 	}
-	ASSERT(((ULONG_PTR)netDevice->SendBuffer & (PAGE_SIZE-1)) == 0); // page-aligned buffer
+	ASSERT(((unsigned long)netDevice->SendBuffer & (PAGE_SIZE-1)) == 0); // page-aligned buffer
 
 	DPRINT_INFO(NETVSC, "Establishing send buffer's GPADL...");
 
@@ -460,7 +460,7 @@ NetVscInitializeSendBufferWithNetVsp(
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															initPacket,
 															sizeof(NVSP_MESSAGE),
-															(ULONG_PTR)initPacket,
+															(unsigned long)initPacket,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 	if (ret != 0)
@@ -521,7 +521,7 @@ NetVscDestroyReceiveBuffer(
 		ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device,
 																			revokePacket,
 																			sizeof(NVSP_MESSAGE),
-																			(ULONG_PTR)revokePacket,
+																			(unsigned long)revokePacket,
 																			VmbusPacketTypeDataInBand,
 																			0);
 		// If we failed here, we might as well return and have a leak rather than continue and a bugchk
@@ -602,7 +602,7 @@ NetVscDestroySendBuffer(
 		ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device,
 																			revokePacket,
 																			sizeof(NVSP_MESSAGE),
-																			(ULONG_PTR)revokePacket,
+																			(unsigned long)revokePacket,
 																			VmbusPacketTypeDataInBand,
 																			0);
 		// If we failed here, we might as well return and have a leak rather than continue and a bugchk
@@ -681,7 +681,7 @@ NetVscConnectToVsp(
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															initPacket,
 															sizeof(NVSP_MESSAGE),
-															(ULONG_PTR)initPacket,
+															(unsigned long)initPacket,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 
@@ -728,7 +728,7 @@ NetVscConnectToVsp(
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															initPacket,
 															sizeof(NVSP_MESSAGE),
-															(ULONG_PTR)initPacket,
+															(unsigned long)initPacket,
 															VmbusPacketTypeDataInBand,
 															0);
 	if (ret != 0)
@@ -1000,7 +1000,7 @@ NetVscOnSendCompletion(
 		return;
 	}
 
-	nvspPacket = (NVSP_MESSAGE*)((ULONG_PTR)Packet + (Packet->DataOffset8 << 3));
+	nvspPacket = (NVSP_MESSAGE*)((unsigned long)Packet + (Packet->DataOffset8 << 3));
 
 	DPRINT_DBG(NETVSC, "send completion packet - type %d", nvspPacket->Header.MessageType);
 
@@ -1015,7 +1015,7 @@ NetVscOnSendCompletion(
 	else if (nvspPacket->Header.MessageType == NvspMessage1TypeSendRNDISPacketComplete)
 	{
 		// Get the send context
-		nvscPacket = (NETVSC_PACKET *)(ULONG_PTR)Packet->TransactionId;
+		nvscPacket = (NETVSC_PACKET *)(unsigned long)Packet->TransactionId;
 		ASSERT(nvscPacket);
 
 		// Notify the layer above us
@@ -1072,14 +1072,14 @@ NetVscOnSend(
 																			Packet->PageBufferCount,
 																			&sendMessage,
 																			sizeof(NVSP_MESSAGE),
-																			(ULONG_PTR)Packet);
+																			(unsigned long)Packet);
 	}
 	else
 	{
 		ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 																&sendMessage,
 																sizeof(NVSP_MESSAGE),
-																(ULONG_PTR)Packet,
+																(unsigned long)Packet,
 																VmbusPacketTypeDataInBand,
 																VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 
@@ -1109,8 +1109,8 @@ NetVscOnReceive(
 	NVSP_MESSAGE *nvspPacket;
 	NETVSC_PACKET *netvscPacket=NULL;
 	LIST_ENTRY* entry;
-	ULONG_PTR start;
-	ULONG_PTR end, endVirtual;
+	unsigned long start;
+	unsigned long end, endVirtual;
 	//NETVSC_DRIVER_OBJECT *netvscDriver;
 	XFERPAGE_PACKET *xferpagePacket=NULL;
 	LIST_ENTRY listHead;
@@ -1136,7 +1136,7 @@ NetVscOnReceive(
 		return;
 	}
 
-	nvspPacket = (NVSP_MESSAGE*)((ULONG_PTR)Packet + (Packet->DataOffset8 << 3));
+	nvspPacket = (NVSP_MESSAGE*)((unsigned long)Packet + (Packet->DataOffset8 << 3));
 
 	// Make sure this is a valid nvsp packet
 	if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket )
@@ -1230,10 +1230,10 @@ NetVscOnReceive(
 
 		netvscPacket->PageBuffers[0].Length = vmxferpagePacket->Ranges[i].ByteCount;
 
-		start = GetPhysicalAddress((void*)((ULONG_PTR)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset));
+		start = GetPhysicalAddress((void*)((unsigned long)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset));
 
 		netvscPacket->PageBuffers[0].Pfn = start >> PAGE_SHIFT;
-		endVirtual = (ULONG_PTR)netDevice->ReceiveBuffer
+		endVirtual = (unsigned long)netDevice->ReceiveBuffer
 		    + vmxferpagePacket->Ranges[i].ByteOffset
 		    + vmxferpagePacket->Ranges[i].ByteCount -1;
 		end = GetPhysicalAddress((void*)endVirtual);
--- a/drivers/staging/hv/netvsc_drv.c
+++ b/drivers/staging/hv/netvsc_drv.c
@@ -386,7 +386,7 @@ Desc:	Send completion processing
 static void netvsc_xmit_completion(void *context)
 {
 	NETVSC_PACKET *packet = (NETVSC_PACKET *)context;
-	struct sk_buff *skb = (struct sk_buff *)(ULONG_PTR)packet->Completion.Send.SendCompletionTid;
+	struct sk_buff *skb = (struct sk_buff *)(unsigned long)packet->Completion.Send.SendCompletionTid;
 	struct net_device* net;
 
 	DPRINT_ENTER(NETVSC_DRV);
@@ -478,7 +478,7 @@ static int netvsc_start_xmit (struct sk_
 	// Set the completion routine
 	packet->Completion.Send.OnSendCompletion = netvsc_xmit_completion;
 	packet->Completion.Send.SendCompletionContext = packet;
-	packet->Completion.Send.SendCompletionTid = (ULONG_PTR)skb;
+	packet->Completion.Send.SendCompletionTid = (unsigned long)skb;
 
 retry_send:
 	ret = net_drv_obj->OnSend(&net_device_ctx->device_ctx->device_obj, packet);
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -407,23 +407,23 @@ void SpinlockClose(HANDLE hSpin)
 	kfree(spin);
 }
 
-void* Physical2LogicalAddr(ULONG_PTR PhysAddr)
+void* Physical2LogicalAddr(unsigned long PhysAddr)
 {
 	void* logicalAddr = phys_to_virt(PhysAddr);
 	BUG_ON(!virt_addr_valid(logicalAddr));
 	return logicalAddr;
 }
 
-ULONG_PTR Logical2PhysicalAddr(void * LogicalAddr)
+unsigned long Logical2PhysicalAddr(void * LogicalAddr)
 {
 	BUG_ON(!virt_addr_valid(LogicalAddr));
 	return virt_to_phys(LogicalAddr);
 }
 
 
-ULONG_PTR Virtual2Physical(void * VirtAddr)
+unsigned long Virtual2Physical(void * VirtAddr)
 {
-	ULONG_PTR pfn = vmalloc_to_pfn(VirtAddr);
+	unsigned long pfn = vmalloc_to_pfn(VirtAddr);
 
 	return pfn << PAGE_SHIFT;
 }
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -362,11 +362,11 @@ RndisFilterSendRequest(
 
 	packet->PageBuffers[0].Pfn = GetPhysicalAddress(&Request->RequestMessage) >> PAGE_SHIFT;
 	packet->PageBuffers[0].Length = Request->RequestMessage.MessageLength;
-	packet->PageBuffers[0].Offset = (ULONG_PTR)&Request->RequestMessage & (PAGE_SIZE -1);
+	packet->PageBuffers[0].Offset = (unsigned long)&Request->RequestMessage & (PAGE_SIZE -1);
 
 	packet->Completion.Send.SendCompletionContext = Request;//packet;
 	packet->Completion.Send.OnSendCompletion = RndisFilterOnSendRequestCompletion;
-	packet->Completion.Send.SendCompletionTid = (ULONG_PTR)Device;
+	packet->Completion.Send.SendCompletionTid = (unsigned long)Device;
 
 	ret = gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet);
 	DPRINT_EXIT(NETVSC);
@@ -523,7 +523,7 @@ RndisFilterOnReceive(
 
 	rndisHeader = (RNDIS_MESSAGE*)PageMapVirtualAddress(Packet->PageBuffers[0].Pfn);
 
-	rndisHeader = (void*)((ULONG_PTR)rndisHeader + Packet->PageBuffers[0].Offset);
+	rndisHeader = (void*)((unsigned long)rndisHeader + Packet->PageBuffers[0].Offset);
 
 	// Make sure we got a valid rndis message
 	// FIXME: There seems to be a bug in set completion msg where its MessageLength is 16 bytes but
@@ -531,7 +531,7 @@ RndisFilterOnReceive(
 #if 0
 	if ( Packet->TotalDataBufferLength != rndisHeader->MessageLength )
 	{
-		PageUnmapVirtualAddress((void*)(ULONG_PTR)rndisHeader - Packet->PageBuffers[0].Offset);
+		PageUnmapVirtualAddress((void*)(unsigned long)rndisHeader - Packet->PageBuffers[0].Offset);
 
 		DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u bytes got %u)...dropping this message!",
 			rndisHeader->MessageLength, Packet->TotalDataBufferLength);
@@ -548,7 +548,7 @@ RndisFilterOnReceive(
 
 	memcpy(&rndisMessage, rndisHeader, (rndisHeader->MessageLength > sizeof(RNDIS_MESSAGE))?sizeof(RNDIS_MESSAGE):rndisHeader->MessageLength);
 
-	PageUnmapVirtualAddress((void*)(ULONG_PTR)rndisHeader - Packet->PageBuffers[0].Offset);
+	PageUnmapVirtualAddress((void*)(unsigned long)rndisHeader - Packet->PageBuffers[0].Offset);
 
 	DumpRndisMessage(&rndisMessage);
 
@@ -633,7 +633,7 @@ RndisFilterQueryDevice(
 	}
 
 	memcpy(Result,
-			(void*)((ULONG_PTR)queryComplete + queryComplete->InformationBufferOffset),
+			(void*)((unsigned long)queryComplete + queryComplete->InformationBufferOffset),
 			queryComplete->InformationBufferLength);
 
 	*ResultSize = queryComplete->InformationBufferLength;
@@ -703,7 +703,7 @@ RndisFilterSetPacketFilter(
 	set->InformationBufferLength = sizeof(u32);
 	set->InformationBufferOffset = sizeof(RNDIS_SET_REQUEST);
 
-	memcpy((void*)(ULONG_PTR)set + sizeof(RNDIS_SET_REQUEST), &NewFilter, sizeof(u32));
+	memcpy((void*)(unsigned long)set + sizeof(RNDIS_SET_REQUEST), &NewFilter, sizeof(u32));
 
 	ret = RndisFilterSendRequest(Device, request);
 	if (ret != 0)
@@ -1113,7 +1113,7 @@ RndisFilterOnSend(
 
 	Packet->IsDataPacket = TRUE;
 	Packet->PageBuffers[0].Pfn		= GetPhysicalAddress(rndisMessage) >> PAGE_SHIFT;
-	Packet->PageBuffers[0].Offset	= (ULONG_PTR)rndisMessage & (PAGE_SIZE-1);
+	Packet->PageBuffers[0].Offset	= (unsigned long)rndisMessage & (PAGE_SIZE-1);
 	Packet->PageBuffers[0].Length	= rndisMessageSize;
 
 	// Save the packet send completion and context
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -388,7 +388,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															vstorPacket,
 															sizeof(VSTOR_PACKET),
-															(ULONG_PTR)request,
+															(unsigned long)request,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 	if ( ret != 0)
@@ -418,7 +418,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															vstorPacket,
 															sizeof(VSTOR_PACKET),
-															(ULONG_PTR)request,
+															(unsigned long)request,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 	if ( ret != 0)
@@ -447,7 +447,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															vstorPacket,
 															sizeof(VSTOR_PACKET),
-															(ULONG_PTR)request,
+															(unsigned long)request,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 
@@ -481,7 +481,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															vstorPacket,
 															sizeof(VSTOR_PACKET),
-															(ULONG_PTR)request,
+															(unsigned long)request,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 
@@ -650,7 +650,7 @@ StorVscOnHostReset(
 	ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															vstorPacket,
 															sizeof(VSTOR_PACKET),
-															(ULONG_PTR)&storDevice->ResetRequest,
+															(unsigned long)&storDevice->ResetRequest,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 	if (ret != 0)
@@ -752,14 +752,14 @@ StorVscOnIORequest(
 				&requestExtension->Request->DataBuffer,
 				vstorPacket,
 				sizeof(VSTOR_PACKET),
-				(ULONG_PTR)requestExtension);
+				(unsigned long)requestExtension);
 	}
 	else
 	{
 		ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
 															vstorPacket,
 															sizeof(VSTOR_PACKET),
-															(ULONG_PTR)requestExtension,
+															(unsigned long)requestExtension,
 															VmbusPacketTypeDataInBand,
 															VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
 	}
@@ -938,7 +938,7 @@ StorVscOnChannelCallback(
 
 			//ASSERT(bytesRecvd == sizeof(VSTOR_PACKET));
 
-			request = (STORVSC_REQUEST_EXTENSION*)(ULONG_PTR)requestId;
+			request = (STORVSC_REQUEST_EXTENSION*)(unsigned long)requestId;
 			ASSERT(request);
 
 			//if (vstorPacket.Flags & SYNTHETIC_FLAG)

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 27/54] Staging: hv: remove ULONG and LONG typedefs
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (26 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  2009-07-21  0:00     ` Arnd Bergmann
  -1 siblings, 1 reply; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-ulong-and-long-typedefs.patch --]
[-- Type: text/plain, Size: 2553 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The ULONG and LONG typedefs are now removed from the Hyper-V driver
code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/StorVsc.c            |    2 +-
 drivers/staging/hv/include/StorVscApi.h |    2 +-
 drivers/staging/hv/include/osd.h        |   10 ----------
 drivers/staging/hv/include/vstorage.h   |   12 ++++++------
 4 files changed, 8 insertions(+), 18 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -95,16 +95,6 @@ typedef struct _DLIST_ENTRY {
 } DLIST_ENTRY;
 
 //
-// unsigned types
-//
-typedef unsigned int		ULONG;
-
-//
-// signed types
-//
-typedef int					LONG;
-
-//
 // Other types
 //
 typedef unsigned long		SIZE_T;
--- a/drivers/staging/hv/include/StorVscApi.h
+++ b/drivers/staging/hv/include/StorVscApi.h
@@ -117,7 +117,7 @@ typedef struct _STORVSC_DRIVER_OBJECT {
 } STORVSC_DRIVER_OBJECT;
 
 typedef struct _STORVSC_DEVICE_INFO {
-	ULONG	PortNumber;
+	unsigned long	PortNumber;
     unsigned char	PathId;
     unsigned char	TargetId;
 } STORVSC_DEVICE_INFO;
--- a/drivers/staging/hv/include/vstorage.h
+++ b/drivers/staging/hv/include/vstorage.h
@@ -155,7 +155,7 @@ typedef struct
     unsigned char DataIn;
     unsigned char Reserved;
 
-    ULONG DataTransferLength;
+    unsigned long DataTransferLength;
 
     union
     {
@@ -185,11 +185,11 @@ typedef struct
     //
     // Note: port number is only really known on the client side
     //
-    ULONG  PortNumber;
+    unsigned long  PortNumber;
 
-    ULONG  Flags;
+    unsigned long  Flags;
 
-    ULONG  MaxTransferBytes;
+    unsigned long  MaxTransferBytes;
 
     //
     //  This id is unique for each channel and will correspond with
@@ -249,13 +249,13 @@ typedef struct _VSTOR_PACKET
     //  Flags - see below for values
     //
 
-    ULONG     Flags;
+    unsigned long     Flags;
 
     //
     // Status of the request returned from the server side.
     //
 
-    ULONG     Status;
+    unsigned long     Status;
 
     //
     // Data payload area
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -62,7 +62,7 @@ typedef struct _STORVSC_DEVICE{
 
 	//  Each unique Port/Path/Target represents 1 channel ie scsi controller. In reality, the pathid, targetid is always 0
 	// and the port is set by us
-	ULONG						PortNumber;
+	unsigned long						PortNumber;
     unsigned char						PathId;
     unsigned char						TargetId;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 28/54] Staging: hv: remove SIZE_T typedef
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (27 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-size_t-typedef.patch --]
[-- Type: text/plain, Size: 2408 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The SIZE_T typedef is now removed from the Hyper-V driver code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/Connection.c   |    2 +-
 drivers/staging/hv/Hv.c           |    2 +-
 drivers/staging/hv/Hv.h           |    2 +-
 drivers/staging/hv/VmbusPrivate.h |    2 +-
 drivers/staging/hv/include/osd.h  |    3 +--
 drivers/staging/hv/osd.c          |    2 +-
 6 files changed, 6 insertions(+), 7 deletions(-)

--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -386,7 +386,7 @@ Description:
 int
 VmbusPostMessage(
 	void *			buffer,
-	SIZE_T			bufferLen
+	size_t			bufferLen
 	)
 {
 	int ret=0;
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -397,7 +397,7 @@ HvPostMessage(
 	HV_CONNECTION_ID connectionId,
 	HV_MESSAGE_TYPE  messageType,
 	void *            payload,
-	SIZE_T           payloadSize
+	size_t           payloadSize
 	)
 {
 	struct alignedInput {
--- a/drivers/staging/hv/Hv.h
+++ b/drivers/staging/hv/Hv.h
@@ -163,7 +163,7 @@ HvPostMessage(
 	HV_CONNECTION_ID connectionId,
 	HV_MESSAGE_TYPE  messageType,
 	void *            payload,
-	SIZE_T           payloadSize
+	size_t           payloadSize
 	);
 
 static HV_STATUS
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -97,7 +97,6 @@ typedef struct _DLIST_ENTRY {
 //
 // Other types
 //
-typedef unsigned long		SIZE_T;
 //typedef unsigned char		GUID[16];
 typedef unsigned char		BOOL;
 typedef unsigned char		BOOLEAN;
@@ -188,7 +187,7 @@ extern HANDLE TimerCreate(PFN_TIMER_CALL
 extern void TimerClose(HANDLE hTimer);
 extern int TimerStop(HANDLE hTimer);
 extern void TimerStart(HANDLE hTimer, u32 expirationInUs);
-extern SIZE_T GetTickCount(void);
+extern size_t GetTickCount(void);
 
 extern HANDLE WaitEventCreate(void);
 extern void WaitEventClose(HANDLE hWait);
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -312,7 +312,7 @@ void TimerClose(HANDLE hTimer)
 	kfree(t);
 }
 
-SIZE_T GetTickCount(void)
+size_t GetTickCount(void)
 {
 	return jiffies;
 }
--- a/drivers/staging/hv/VmbusPrivate.h
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -149,7 +149,7 @@ VmbusDisconnect(
 static int
 VmbusPostMessage(
 	void *			buffer,
-	SIZE_T			bufSize
+	size_t			bufSize
 	);
 
 static int

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 29/54] Staging: hv: remove DWORD and BYTE typedefs
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (28 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-dword-and-byte-typedefs.patch --]
[-- Type: text/plain, Size: 608 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

No one was even using them...

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/include/osd.h |    2 --
 1 file changed, 2 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -101,8 +101,6 @@ typedef struct _DLIST_ENTRY {
 typedef unsigned char		BOOL;
 typedef unsigned char		BOOLEAN;
 typedef void*				HANDLE;
-typedef u32				DWORD;
-typedef unsigned char		BYTE;
 
 typedef struct {
 	unsigned char	Data[16];

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 30/54] Staging: hv: remove BOOL and BOOLEAN typedefs
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (29 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization, Greg KH
  Cc: Sam Ramji, Haiyang Zhang, shemminger

[-- Attachment #1: staging-hv-remove-bool-and-boolean-typedefs.patch --]
[-- Type: text/plain, Size: 4861 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The BOOL and BOOLEAN typedefs are now removed from the Hyper-V driver
code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/ChannelMgmt.c               |    2 +-
 drivers/staging/hv/Hv.h                        |    2 +-
 drivers/staging/hv/NetVsc.c                    |    2 +-
 drivers/staging/hv/RndisFilter.c               |    2 +-
 drivers/staging/hv/include/ChannelMessages.h   |    6 +++---
 drivers/staging/hv/include/List.h              |    2 +-
 drivers/staging/hv/include/NetVscApi.h         |    4 ++--
 drivers/staging/hv/include/VmbusPacketFormat.h |    2 +-
 drivers/staging/hv/include/osd.h               |    2 --
 9 files changed, 11 insertions(+), 13 deletions(-)

--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -240,7 +240,7 @@ VmbusChannelProcessOffer(
 	VMBUS_CHANNEL* newChannel=(VMBUS_CHANNEL*)context;
 	LIST_ENTRY* anchor;
 	LIST_ENTRY* curr;
-	BOOL fNew=TRUE;
+	bool fNew=TRUE;
 	VMBUS_CHANNEL* channel;
 
 	DPRINT_ENTER(VMBUS);
--- a/drivers/staging/hv/Hv.h
+++ b/drivers/staging/hv/Hv.h
@@ -113,7 +113,7 @@ typedef struct {
 	u64	GuestId;			// XenLinux or native Linux. If XenLinux, the hypercall and synic pages has already been initialized
 	void*	HypercallPage;
 
-	BOOL	SynICInitialized;
+	bool	SynICInitialized;
 	// This is used as an input param to HvCallSignalEvent hypercall. The input param is immutable
 	// in our usage and must be dynamic mem (vs stack or global).
 	HV_INPUT_SIGNAL_EVENT_BUFFER *SignalEventBuffer;
--- a/drivers/staging/hv/include/ChannelMessages.h
+++ b/drivers/staging/hv/include/ChannelMessages.h
@@ -82,7 +82,7 @@ typedef struct _VMBUS_CHANNEL_QUERY_VMBU
 typedef struct _VMBUS_CHANNEL_VERSION_SUPPORTED
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    BOOLEAN VersionSupported;
+    bool VersionSupported;
 } VMBUS_CHANNEL_VERSION_SUPPORTED, *PVMBUS_CHANNEL_VERSION_SUPPORTED;
 
 // Offer Channel parameters
@@ -92,7 +92,7 @@ typedef struct _VMBUS_CHANNEL_OFFER_CHAN
     VMBUS_CHANNEL_OFFER Offer;
     u32  ChildRelId;
     u8   MonitorId;
-    BOOLEAN MonitorAllocated;
+    bool MonitorAllocated;
 } VMBUS_CHANNEL_OFFER_CHANNEL, *PVMBUS_CHANNEL_OFFER_CHANNEL;
 
 //
@@ -264,7 +264,7 @@ typedef struct _VMBUS_CHANNEL_INITIATE_C
 typedef struct _VMBUS_CHANNEL_VERSION_RESPONSE
 {
     VMBUS_CHANNEL_MESSAGE_HEADER Header;
-    BOOLEAN     VersionSupported;
+    bool     VersionSupported;
 } VMBUS_CHANNEL_VERSION_RESPONSE, *PVMBUS_CHANNEL_VERSION_RESPONSE;
 
 typedef VMBUS_CHANNEL_MESSAGE_HEADER VMBUS_CHANNEL_UNLOAD, *PVMBUS_CHANNEL_UNLOAD;
--- a/drivers/staging/hv/include/List.h
+++ b/drivers/staging/hv/include/List.h
@@ -56,7 +56,7 @@ typedef DLIST_ENTRY *PLIST_ENTRY;
 
 
 /*
- *  BOOLEAN
+ *  bool
  *  IsListEmpty(
  *      PLIST_ENTRY ListHead
  *      );
--- a/drivers/staging/hv/include/NetVscApi.h
+++ b/drivers/staging/hv/include/NetVscApi.h
@@ -72,7 +72,7 @@ typedef struct _NETVSC_PACKET {
 	DLIST_ENTRY				ListEntry;
 
 	DEVICE_OBJECT			*Device;
-	BOOL					IsDataPacket;
+	bool					IsDataPacket;
 
 	// Valid only for receives when we break a xfer page packet into multiple netvsc packets
 	XFERPAGE_PACKET		*XferPagePacket;
@@ -131,7 +131,7 @@ typedef struct _NETVSC_DRIVER_OBJECT {
 
 typedef struct _NETVSC_DEVICE_INFO {
     unsigned char	MacAddr[6];
-    BOOL	LinkState;	// 0 - link up, 1 - link down
+    bool	LinkState;	// 0 - link up, 1 - link down
 } NETVSC_DEVICE_INFO;
 
 //
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -98,8 +98,6 @@ typedef struct _DLIST_ENTRY {
 // Other types
 //
 //typedef unsigned char		GUID[16];
-typedef unsigned char		BOOL;
-typedef unsigned char		BOOLEAN;
 typedef void*				HANDLE;
 
 typedef struct {
--- a/drivers/staging/hv/include/VmbusPacketFormat.h
+++ b/drivers/staging/hv/include/VmbusPacketFormat.h
@@ -113,7 +113,7 @@ typedef struct VMTRANSFER_PAGE_PACKET_HE
 #endif
 
     u16                  TransferPageSetId;
-    BOOLEAN                 SenderOwnsSet;
+    bool                 SenderOwnsSet;
     u8                   Reserved;
     u32                  RangeCount;
     VMTRANSFER_PAGE_RANGE   Ranges[1];
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -1344,7 +1344,7 @@ NetVscOnReceiveCompletion(
 	DEVICE_OBJECT *device = (DEVICE_OBJECT*)packet->Device;
 	NETVSC_DEVICE* netDevice;
 	u64	transactionId=0;
-	BOOL fSendReceiveComp = FALSE;
+	bool fSendReceiveComp = FALSE;
 
 	DPRINT_ENTER(NETVSC);
 
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -383,7 +383,7 @@ RndisFilterReceiveResponse(
 	LIST_ENTRY *anchor;
 	LIST_ENTRY *curr;
 	RNDIS_REQUEST *request=NULL;
-	BOOL found=FALSE;
+	bool found=FALSE;
 
 	DPRINT_ENTER(NETVSC);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 31/54] Staging: hv: remove #defines from osd.c
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (30 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-defines-from-osd.c.patch --]
[-- Type: text/plain, Size: 2497 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Remove the unneeded #defines from osd.c

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/osd.c |   42 ------------------------------------------
 1 file changed, 42 deletions(-)

--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -21,15 +21,12 @@
  *
  */
 
-#define KERNEL_2_6_27
-
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/mm.h>
 #include <linux/highmem.h>
 #include <linux/vmalloc.h>
-//#include <linux/config.h>
 #include <linux/ioport.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
@@ -86,20 +83,11 @@ typedef struct _WORKITEM {
 
 void LogMsg(const char *fmt, ...)
 {
-#ifdef KERNEL_2_6_5
-	char buf[1024];
-#endif
 	va_list args;
 
 	va_start(args, fmt);
-#ifdef KERNEL_2_6_5
-	vsnprintf(buf, 1024, fmt, args);
-	va_end(args);
-	printk(buf);
-#else
 	vprintk(fmt, args);
 	va_end(args);
-#endif
 }
 
 void BitSet(unsigned int* addr, int bit)
@@ -130,30 +118,12 @@ int BitTestAndSet(unsigned int* addr, in
 
 int InterlockedIncrement(int *val)
 {
-#ifdef KERNEL_2_6_5
-	int i;
-	local_irq_disable();
-	i = atomic_read((atomic_t*)val);
-	atomic_set((atomic_t*)val, i+1);
-	local_irq_enable();
-	return i+1;
-#else
 	return atomic_inc_return((atomic_t*)val);
-#endif
 }
 
 int InterlockedDecrement(int *val)
 {
-#ifdef KERNEL_2_6_5
-	int i;
-	local_irq_disable();
-	i = atomic_read((atomic_t*)val);
-	atomic_set((atomic_t*)val, i-1);
-	local_irq_enable();
-	return i-1;
-#else
 	return atomic_dec_return((atomic_t*)val);
-#endif
 }
 
 #ifndef atomic_cmpxchg
@@ -428,11 +398,7 @@ unsigned long Virtual2Physical(void * Vi
 	return pfn << PAGE_SHIFT;
 }
 
-#ifdef KERNEL_2_6_27
 void WorkItemCallback(struct work_struct *work)
-#else
-void WorkItemCallback(void* work)
-#endif
 {
 	WORKITEM* w = (WORKITEM*)work;
 
@@ -474,11 +440,7 @@ int WorkQueueQueueWorkItem(HANDLE hWorkQ
 
 	w->callback = workItem,
 	w->context = context;
-#ifdef KERNEL_2_6_27
 	INIT_WORK(&w->work, WorkItemCallback);
-#else
-	INIT_WORK(&w->work, WorkItemCallback, w);
-#endif
 	return queue_work(wq->queue, &w->work);
 }
 
@@ -492,10 +454,6 @@ void QueueWorkItem(PFN_WORKITEM_CALLBACK
 
 	w->callback = workItem,
 	w->context = context;
-#ifdef KERNEL_2_6_27
 	INIT_WORK(&w->work, WorkItemCallback);
-#else
-	INIT_WORK(&w->work, WorkItemCallback, w);
-#endif
 	schedule_work(&w->work);
 }

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 32/54] Staging: hv: remove MIN and MAX usages
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (31 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-min-and-max-usages.patch --]
[-- Type: text/plain, Size: 1595 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The kernel has the "correct" min() and max() functions, so use those.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/include/osd.h |    3 ---
 drivers/staging/hv/storvsc_drv.c |    4 ++--
 2 files changed, 2 insertions(+), 5 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -67,9 +67,6 @@
 #define ALIGN_DOWN(value, align)		( (value) & ~(align-1) )
 #define NUM_PAGES_SPANNED(addr, len)	( (ALIGN_UP(addr+len, PAGE_SIZE) - ALIGN_DOWN(addr, PAGE_SIZE)) >> PAGE_SHIFT )
 
-#define MIN(a, b)       ((a) < (b)? (a): (b))
-#define MAX(a, b)       ((a) > (b)? (a): (b))
-
 #define LOWORD(dw)		((unsigned short) (dw))
 #define HIWORD(dw)		((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
 
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -623,7 +623,7 @@ static unsigned int copy_to_bounce_buffe
 			dest = bounce_addr + bounce_sgl[j].length;
 			destlen = PAGE_SIZE - bounce_sgl[j].length;
 
-			copylen = MIN(srclen, destlen);
+			copylen = min(srclen, destlen);
 			memcpy((void*)dest, (void*)src, copylen);
 
 			total_copied += copylen;
@@ -698,7 +698,7 @@ static unsigned int copy_from_bounce_buf
 			src = bounce_addr + bounce_sgl[j].offset;
 			srclen = bounce_sgl[j].length - bounce_sgl[j].offset;
 
-			copylen = MIN(srclen, destlen);
+			copylen = min(srclen, destlen);
 			memcpy((void*)dest, (void*)src, copylen);
 
 			total_copied += copylen;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 33/54] Staging: hv: remove PAGE_SIZE and PAGE_SHIFT and __builtin functions
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (32 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-page_size-and-page_shift-and-__builtin-functions.patch --]
[-- Type: text/plain, Size: 2446 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

The kernel provides all of this, and actually gets it correct, so don't
try to redefine these types of things.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/BlkVsc.c      |    1 +
 drivers/staging/hv/NetVsc.c      |    1 +
 drivers/staging/hv/RndisFilter.c |    1 +
 drivers/staging/hv/StorVsc.c     |    2 ++
 drivers/staging/hv/Vmbus.c       |    1 +
 drivers/staging/hv/include/osd.h |   28 ----------------------------
 6 files changed, 6 insertions(+), 28 deletions(-)

--- a/drivers/staging/hv/BlkVsc.c
+++ b/drivers/staging/hv/BlkVsc.c
@@ -21,6 +21,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/mm.h>
 #include "StorVsc.c"
 
 static const char* gBlkDriverName="blkvsc";
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -29,34 +29,6 @@
 // Defines
 //
 
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 0x1000
-#endif
-
-#ifndef PAGE_SHIFT
-#define PAGE_SHIFT 12
-#endif
-
-#ifndef memcpy
-#define memcpy		__builtin_memcpy
-#endif
-
-#ifndef memset
-#define memset		__builtin_memset
-#endif
-
-#ifndef memcmp
-#define memcmp		__builtin_memcmp
-#endif
-
-#ifndef strcpy
-#define strcpy		__builtin_strcpy
-#endif
-
-//
-//#ifndef sprintf
-//#define sprintf				__builtin_sprintf
-//#endif
 
 #define STRUCT_PACKED		__attribute__((__packed__))
 #define STRUCT_ALIGNED(x)	__attribute__((__aligned__(x)))
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -23,6 +23,7 @@
 #define KERNEL_2_6_27
 
 #include <linux/kernel.h>
+#include <linux/mm.h>
 #include "include/logging.h"
 #include "NetVsc.h"
 #include "RndisFilter.h"
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -24,6 +24,7 @@
 #define KERNEL_2_6_27
 
 #include <linux/kernel.h>
+#include <linux/mm.h>
 #include "include/logging.h"
 
 #include "include/NetVscApi.h"
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -24,6 +24,8 @@
 #define KERNEL_2_6_27
 
 #include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/mm.h>
 #include "include/logging.h"
 
 #include "include/StorVscApi.h"
--- a/drivers/staging/hv/Vmbus.c
+++ b/drivers/staging/hv/Vmbus.c
@@ -22,6 +22,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/mm.h>
 #include "include/logging.h"
 #include "VersionInfo.h"
 #include "VmbusPrivate.h"

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (33 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  2009-07-20 23:46     ` Arnd Bergmann
  -1 siblings, 1 reply; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-struct_packed-and-struct_aligned-defines.patch --]
[-- Type: text/plain, Size: 1180 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the correct __attribute__((packed)) one if it's really needed.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/RingBuffer.h  |    2 +-
 drivers/staging/hv/include/osd.h |    3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -30,9 +30,6 @@
 //
 
 
-#define STRUCT_PACKED		__attribute__((__packed__))
-#define STRUCT_ALIGNED(x)	__attribute__((__aligned__(x)))
-
 #define UNUSED_VAR(v)		v  __attribute__((__unused__))
 
 #define ALIGN_UP(value, align)			( ((value) & (align-1))? ( ((value) + (align-1)) & ~(align-1) ): (value) )
--- a/drivers/staging/hv/RingBuffer.h
+++ b/drivers/staging/hv/RingBuffer.h
@@ -43,7 +43,7 @@ typedef struct _RING_BUFFER {
 	// volatile u32 InterruptMask;
 	// Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
     u8		Buffer[0];
-} STRUCT_PACKED RING_BUFFER;
+} __attribute__((packed)) RING_BUFFER;
 
 typedef struct _RING_BUFFER_INFO {
     RING_BUFFER*	RingBuffer;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 35/54] Staging: hv: remove UNUSED_VAR usage
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (34 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-unused_var-usage.patch --]
[-- Type: text/plain, Size: 1093 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

This isn't needed at all.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/include/osd.h |    2 --
 drivers/staging/hv/netvsc_drv.c  |    2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -30,8 +30,6 @@
 //
 
 
-#define UNUSED_VAR(v)		v  __attribute__((__unused__))
-
 #define ALIGN_UP(value, align)			( ((value) & (align-1))? ( ((value) + (align-1)) & ~(align-1) ): (value) )
 #define ALIGN_DOWN(value, align)		( (value) & ~(align-1) )
 #define NUM_PAGES_SPANNED(addr, len)	( (ALIGN_UP(addr+len, PAGE_SIZE) - ALIGN_DOWN(addr, PAGE_SIZE)) >> PAGE_SHIFT )
--- a/drivers/staging/hv/netvsc_drv.c
+++ b/drivers/staging/hv/netvsc_drv.c
@@ -154,7 +154,7 @@ Desc:	Set the multicast list
 
 Remark:	No-op here
 --*/
-static void netvsc_set_multicast_list(UNUSED_VAR(struct net_device *net))
+static void netvsc_set_multicast_list(struct net_device *net)
 {
 }

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 36/54] Staging: hv: remove FIELD_OFFSET usage
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (35 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-field_offset-usage.patch --]
[-- Type: text/plain, Size: 1219 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

This isn't needed, or even used, at all.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/include/VmbusChannelInterface.h |    9 ---------
 drivers/staging/hv/include/osd.h                   |    2 --
 2 files changed, 11 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -37,8 +37,6 @@
 #define LOWORD(dw)		((unsigned short) (dw))
 #define HIWORD(dw)		((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
 
-#define FIELD_OFFSET(t, f)    ((unsigned int)(unsigned long)&(((t *)0)->f))
-
 #ifdef FALSE
 #undef FALSE
 #endif
--- a/drivers/staging/hv/include/VmbusChannelInterface.h
+++ b/drivers/staging/hv/include/VmbusChannelInterface.h
@@ -98,15 +98,6 @@ typedef struct
 #pragma pack(pop)
 
 
-//
-// Verify the MAX_PIPE_USER_DEFINED_BYTES value.
-//
-//C_ASSERT(MAX_PIPE_USER_DEFINED_BYTES ==
-//         MAX_USER_DEFINED_BYTES -
-//         (FIELD_OFFSET(VMBUS_CHANNEL_OFFER, u.Pipe.UserDefined) -
-//          FIELD_OFFSET(VMBUS_CHANNEL_OFFER, u.Standard.UserDefined)));
-//
-
 typedef u32 GPADL_HANDLE;
 
 //

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 37/54] Staging: hv: remove TRUE, FALSE, and NULL usage
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (36 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-remove-true-false-and-null-usage.patch --]
[-- Type: text/plain, Size: 4807 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Don't define things that are either already provided (like NULL), or you
shouldn't use (like TRUE and FALSE).

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/ChannelMgmt.c |    4 ++--
 drivers/staging/hv/Hv.c          |    8 ++++----
 drivers/staging/hv/NetVsc.c      |    4 ++--
 drivers/staging/hv/RndisFilter.c |   10 +++++-----
 drivers/staging/hv/include/osd.h |   14 --------------
 5 files changed, 13 insertions(+), 27 deletions(-)

--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -240,7 +240,7 @@ VmbusChannelProcessOffer(
 	VMBUS_CHANNEL* newChannel=(VMBUS_CHANNEL*)context;
 	LIST_ENTRY* anchor;
 	LIST_ENTRY* curr;
-	bool fNew=TRUE;
+	bool fNew = true;
 	VMBUS_CHANNEL* channel;
 
 	DPRINT_ENTER(VMBUS);
@@ -255,7 +255,7 @@ VmbusChannelProcessOffer(
 		if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, &newChannel->OfferMsg.Offer.InterfaceType,sizeof(GUID)) &&
 			!memcmp(&channel->OfferMsg.Offer.InterfaceInstance, &newChannel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID)))
 		{
-			fNew = FALSE;
+			fNew = false;
 			break;
 		}
 	}
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -31,7 +31,7 @@
 
 // The one and only
 HV_CONTEXT gHvContext={
-	.SynICInitialized = FALSE,
+	.SynICInitialized = false,
 	.HypercallPage = NULL,
 	.SignalEventParam = NULL,
 	.SignalEventBuffer = NULL,
@@ -571,8 +571,8 @@ HvSynicInit (
 
 	sharedSint.AsUINT64 = 0;
     sharedSint.Vector = irqVector; //HV_SHARED_SINT_IDT_VECTOR + 0x20;
-    sharedSint.Masked = FALSE;
-    sharedSint.AutoEoi = TRUE;
+    sharedSint.Masked = false;
+    sharedSint.AutoEoi = true;
 
 	DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", sharedSint.AsUINT64);
 
@@ -584,7 +584,7 @@ HvSynicInit (
 
     WriteMsr(HV_X64_MSR_SCONTROL, sctrl.AsUINT64);
 
-	gHvContext.SynICInitialized = TRUE;
+	gHvContext.SynICInitialized = true;
 
 	DPRINT_EXIT(VMBUS);
 
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -37,20 +37,6 @@
 #define LOWORD(dw)		((unsigned short) (dw))
 #define HIWORD(dw)		((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
 
-#ifdef FALSE
-#undef FALSE
-#endif
-#define FALSE 0
-
-#ifdef TRUE
-#undef TRUE
-#endif
-#define TRUE  1
-
-#ifndef NULL
-#define NULL  (void *)0
-#endif
-
 typedef struct _DLIST_ENTRY {
    struct _DLIST_ENTRY *Flink;
    struct _DLIST_ENTRY *Blink;
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -1345,7 +1345,7 @@ NetVscOnReceiveCompletion(
 	DEVICE_OBJECT *device = (DEVICE_OBJECT*)packet->Device;
 	NETVSC_DEVICE* netDevice;
 	u64	transactionId=0;
-	bool fSendReceiveComp = FALSE;
+	bool fSendReceiveComp = false;
 
 	DPRINT_ENTER(NETVSC);
 
@@ -1371,7 +1371,7 @@ NetVscOnReceiveCompletion(
 	// Return the xfer page packet itself to the freelist
 	if (packet->XferPagePacket->Count == 0)
 	{
-		fSendReceiveComp = TRUE;
+		fSendReceiveComp = true;
 		transactionId = packet->Completion.Recv.ReceiveCompletionTid;
 
 		INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->XferPagePacket->ListEntry);
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -357,7 +357,7 @@ RndisFilterSendRequest(
 	// Setup the packet to send it
 	packet = &Request->Packet;
 
-	packet->IsDataPacket = FALSE;
+	packet->IsDataPacket = false;
 	packet->TotalDataBufferLength = Request->RequestMessage.MessageLength;
 	packet->PageBufferCount = 1;
 
@@ -384,7 +384,7 @@ RndisFilterReceiveResponse(
 	LIST_ENTRY *anchor;
 	LIST_ENTRY *curr;
 	RNDIS_REQUEST *request=NULL;
-	bool found=FALSE;
+	bool found = false;
 
 	DPRINT_ENTER(NETVSC);
 
@@ -399,7 +399,7 @@ RndisFilterReceiveResponse(
 			DPRINT_DBG(NETVSC, "found rndis request for this response (id 0x%x req type 0x%x res type 0x%x)",
 				request->RequestMessage.Message.InitializeRequest.RequestId, request->RequestMessage.NdisMessageType, Response->NdisMessageType);
 
-			found = TRUE;
+			found = true;
 			break;
 		}
 	}
@@ -485,7 +485,7 @@ RndisFilterReceiveData(
 	Packet->PageBuffers[0].Offset += dataOffset;
 	Packet->PageBuffers[0].Length -= dataOffset;
 
-	Packet->IsDataPacket = TRUE;
+	Packet->IsDataPacket = true;
 
 	gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device, Packet);
 
@@ -1112,7 +1112,7 @@ RndisFilterOnSend(
 	rndisPacket->DataOffset = sizeof(RNDIS_PACKET);
 	rndisPacket->DataLength = Packet->TotalDataBufferLength;
 
-	Packet->IsDataPacket = TRUE;
+	Packet->IsDataPacket = true;
 	Packet->PageBuffers[0].Pfn		= GetPhysicalAddress(rndisMessage) >> PAGE_SHIFT;
 	Packet->PageBuffers[0].Offset	= (unsigned long)rndisMessage & (PAGE_SIZE-1);
 	Packet->PageBuffers[0].Length	= rndisMessageSize;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 38/54] Staging: hv: osd: remove MemAlloc wrapper
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (37 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-memalloc-wrapper.patch --]
[-- Type: text/plain, Size: 4290 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the "real" kmalloc call instead of a wrapper function.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/Channel.c     |    9 +++------
 drivers/staging/hv/ChannelMgmt.c |    3 +--
 drivers/staging/hv/Hv.c          |    2 +-
 drivers/staging/hv/NetVsc.c      |    2 +-
 drivers/staging/hv/RndisFilter.c |    1 -
 drivers/staging/hv/include/osd.h |    1 -
 drivers/staging/hv/osd.c         |    5 -----
 7 files changed, 6 insertions(+), 17 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -260,8 +260,7 @@ VmbusChannelOpen(
 		SendRingBufferSize);
 
 	// Create and init the channel open message
-	openInfo =
-		(VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_OPEN_CHANNEL));
+	openInfo = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_OPEN_CHANNEL), GFP_KERNEL);
 	ASSERT(openInfo != NULL);
 
 	openInfo->WaitEvent = WaitEventCreate();
@@ -630,8 +629,7 @@ VmbusChannelTeardownGpadl(
 
 	ASSERT(GpadlHandle != 0);
 
-	info =
-		(VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN));
+	info = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN), GFP_KERNEL);
 	ASSERT(info != NULL);
 
 	info->WaitEvent = WaitEventCreate();
@@ -693,8 +691,7 @@ VmbusChannelClose(
 	TimerStop(Channel->PollTimer);
 
 	// Send a closing message
-	info =
-		(VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL));
+	info = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL), GFP_KERNEL);
 	ASSERT(info != NULL);
 
 	//info->waitEvent = WaitEventCreate();
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -731,8 +731,7 @@ VmbusChannelRequestOffers(
 
 	DPRINT_ENTER(VMBUS);
 
-	msgInfo =
-		(VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_MESSAGE_HEADER));
+	msgInfo = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_MESSAGE_HEADER), GFP_KERNEL);
 	ASSERT(msgInfo != NULL);
 
 	msgInfo->WaitEvent = WaitEventCreate();
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -305,7 +305,7 @@ HvInit (
                (unsigned long)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT);
 
 	// Setup the global signal event param for the signal event hypercall
-	gHvContext.SignalEventBuffer = MemAlloc(sizeof(HV_INPUT_SIGNAL_EVENT_BUFFER));
+	gHvContext.SignalEventBuffer = kmalloc(sizeof(HV_INPUT_SIGNAL_EVENT_BUFFER), GFP_KERNEL);
 	if (!gHvContext.SignalEventBuffer)
 	{
 		goto Cleanup;
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -121,7 +121,6 @@ extern void PageFree(void* page, unsigne
 extern void* MemMapIO(unsigned long phys, unsigned long size);
 extern void MemUnmapIO(void* virt);
 
-extern void* MemAlloc(unsigned int size);
 extern void* MemAllocZeroed(unsigned int size);
 extern void* MemAllocAtomic(unsigned int size);
 extern void MemFree(void* buf);
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -361,7 +361,7 @@ NetVscInitializeReceiveBufferWithNetVsp(
 
 	netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections;
 
-	netDevice->ReceiveSections = MemAlloc(netDevice->ReceiveSectionCount * sizeof(NVSP_1_RECEIVE_BUFFER_SECTION));
+	netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(NVSP_1_RECEIVE_BUFFER_SECTION), GFP_KERNEL);
 	if (netDevice->ReceiveSections == NULL)
 	{
 		ret = -1;
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -189,11 +189,6 @@ void PageUnmapVirtualAddress(void* VirtA
 	kunmap_atomic(VirtAddr, KM_IRQ0);
 }
 
-void* MemAlloc(unsigned int size)
-{
-	return kmalloc(size, GFP_KERNEL);
-}
-
 void* MemAllocZeroed(unsigned int size)
 {
 	void *p = kmalloc(size, GFP_KERNEL);
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -943,7 +943,6 @@ RndisFilterOnDeviceAdd(
 
 	DPRINT_ENTER(NETVSC);
 
-	//rndisDevice = MemAlloc(sizeof(RNDIS_DEVICE));
 	rndisDevice = GetRndisDevice();
 	if (!rndisDevice)
 	{

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 39/54] Staging: hv: osd: remove MemAllocZeroed wrapper
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (38 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-memalloczeroed-wrapper.patch --]
[-- Type: text/plain, Size: 5235 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the "real" kzalloc call instead of a wrapper function.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/Channel.c     |    8 ++++----
 drivers/staging/hv/Connection.c  |    4 ++--
 drivers/staging/hv/NetVsc.c      |    4 ++--
 drivers/staging/hv/RndisFilter.c |    4 ++--
 drivers/staging/hv/StorVsc.c     |    2 +-
 drivers/staging/hv/include/osd.h |    1 -
 drivers/staging/hv/osd.c         |    7 -------
 7 files changed, 11 insertions(+), 19 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -226,7 +226,7 @@ VmbusChannelOpen(
 
 	// Allocate the ring buffer
 	out = PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT);
-	//out = MemAllocZeroed(sendRingBufferSize + recvRingBufferSize);
+	//out = kzalloc(sendRingBufferSize + recvRingBufferSize, GFP_KERNEL);
 	ASSERT(out);
 	ASSERT(((unsigned long)out & (PAGE_SIZE-1)) == 0);
 
@@ -421,7 +421,7 @@ VmbusChannelCreateGpadlHeader(
 	{
 		// fill in the header
 		msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pfnCount*sizeof(u64);
-		msgHeader =  MemAllocZeroed(msgSize);
+		msgHeader =  kzalloc(msgSize, GFP_KERNEL);
 
 		INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList);
 		msgHeader->MessageSize=msgSize;
@@ -458,7 +458,7 @@ VmbusChannelCreateGpadlHeader(
 			}
 
 			msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_BODY) + pfnCurr*sizeof(u64);
-			msgBody =  MemAllocZeroed(msgSize);
+			msgBody = kzalloc(msgSize, GFP_KERNEL);
 			ASSERT(msgBody);
 			msgBody->MessageSize = msgSize;
 			(*MessageCount)++;
@@ -481,7 +481,7 @@ VmbusChannelCreateGpadlHeader(
 	{
 		// everything fits in a header
 		msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pageCount*sizeof(u64);
-		msgHeader =  MemAllocZeroed(msgSize);
+		msgHeader = kzalloc(msgSize, GFP_KERNEL);
 		msgHeader->MessageSize=msgSize;
 
 		gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg;
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -89,7 +89,7 @@ VmbusConnect(
 		goto Cleanup;
 	}
 
-	msgInfo = (VMBUS_CHANNEL_MSGINFO*)MemAllocZeroed(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_INITIATE_CONTACT));
+	msgInfo = kzalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_INITIATE_CONTACT), GFP_KERNEL);
 	if (msgInfo == NULL)
 	{
 		ret = -1;
@@ -207,7 +207,7 @@ VmbusDisconnect(
 	if (gVmbusConnection.ConnectState != Connected)
 		return -1;
 
-	msg = MemAllocZeroed(sizeof(VMBUS_CHANNEL_UNLOAD));
+	msg = kzalloc(sizeof(VMBUS_CHANNEL_UNLOAD), GFP_KERNEL);
 
 	msg->MessageType = ChannelMessageUnload;
 
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -121,7 +121,6 @@ extern void PageFree(void* page, unsigne
 extern void* MemMapIO(unsigned long phys, unsigned long size);
 extern void MemUnmapIO(void* virt);
 
-extern void* MemAllocZeroed(unsigned int size);
 extern void* MemAllocAtomic(unsigned int size);
 extern void MemFree(void* buf);
 extern void MemoryFence(void);
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -122,7 +122,7 @@ static inline NETVSC_DEVICE* AllocNetDev
 {
 	NETVSC_DEVICE *netDevice;
 
-	netDevice = MemAllocZeroed(sizeof(NETVSC_DEVICE));
+	netDevice = kzalloc(sizeof(NETVSC_DEVICE), GFP_KERNEL);
 	if (!netDevice)
 		return NULL;
 
@@ -815,7 +815,7 @@ NetVscOnDeviceAdd(
 
 	for (i=0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++)
 	{
-		packet = MemAllocZeroed(sizeof(NETVSC_PACKET) + (NETVSC_RECEIVE_SG_COUNT* sizeof(PAGE_BUFFER)));
+		packet = kzalloc(sizeof(NETVSC_PACKET) + (NETVSC_RECEIVE_SG_COUNT* sizeof(PAGE_BUFFER)), GFP_KERNEL);
 		if (!packet)
 		{
 			DPRINT_DBG(NETVSC, "unable to allocate netvsc pkts for receive pool (wanted %d got %d)", NETVSC_RECEIVE_PACKETLIST_COUNT, i);
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -189,13 +189,6 @@ void PageUnmapVirtualAddress(void* VirtA
 	kunmap_atomic(VirtAddr, KM_IRQ0);
 }
 
-void* MemAllocZeroed(unsigned int size)
-{
-	void *p = kmalloc(size, GFP_KERNEL);
-	if (p) memset(p, 0, size);
-	return p;
-}
-
 void* MemAllocAtomic(unsigned int size)
 {
 	return kmalloc(size, GFP_ATOMIC);
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -210,7 +210,7 @@ static inline RNDIS_DEVICE* GetRndisDevi
 {
 	RNDIS_DEVICE *device;
 
-	device = MemAllocZeroed(sizeof(RNDIS_DEVICE));
+	device = kzalloc(sizeof(RNDIS_DEVICE), GFP_KERNEL);
 	if (!device)
 	{
 		return NULL;
@@ -242,7 +242,7 @@ static inline RNDIS_REQUEST* GetRndisReq
 	RNDIS_MESSAGE *rndisMessage;
 	RNDIS_SET_REQUEST *set;
 
-	request = MemAllocZeroed(sizeof(RNDIS_REQUEST));
+	request = kzalloc(sizeof(RNDIS_REQUEST), GFP_KERNEL);
 	if (!request)
 	{
 		return NULL;
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -147,7 +147,7 @@ static inline STORVSC_DEVICE* AllocStorD
 {
 	STORVSC_DEVICE *storDevice;
 
-	storDevice = MemAllocZeroed(sizeof(STORVSC_DEVICE));
+	storDevice = kzalloc(sizeof(STORVSC_DEVICE), GFP_KERNEL);
 	if (!storDevice)
 		return NULL;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 40/54] Staging: hv: osd: remove MemAllocAtomic wrapper
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (39 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-memallocatomic-wrapper.patch --]
[-- Type: text/plain, Size: 2535 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the "real" kmalloc call instead of a wrapper function.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/ChannelMgmt.c |    3 +--
 drivers/staging/hv/Hv.c          |    2 +-
 drivers/staging/hv/NetVsc.c      |    2 +-
 drivers/staging/hv/Vmbus.c       |    2 +-
 drivers/staging/hv/include/osd.h |    1 -
 drivers/staging/hv/osd.c         |    5 -----
 6 files changed, 4 insertions(+), 11 deletions(-)

--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -143,13 +143,12 @@ VMBUS_CHANNEL* AllocVmbusChannel(void)
 {
 	VMBUS_CHANNEL* channel;
 
-	channel = (VMBUS_CHANNEL*) MemAllocAtomic(sizeof(VMBUS_CHANNEL));
+	channel = kzalloc(sizeof(VMBUS_CHANNEL), GFP_ATOMIC);
 	if (!channel)
 	{
 		return NULL;
 	}
 
-	memset(channel, 0,sizeof(VMBUS_CHANNEL));
 	channel->InboundLock = SpinlockCreate();
 	if (!channel->InboundLock)
 	{
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -414,7 +414,7 @@ HvPostMessage(
 		return -1;
 	}
 
-	addr = (unsigned long)MemAllocAtomic(sizeof(struct alignedInput));
+	addr = (unsigned long)kmalloc(sizeof(struct alignedInput), GFP_ATOMIC);
 
 	if (!addr)
 	{
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -121,7 +121,6 @@ extern void PageFree(void* page, unsigne
 extern void* MemMapIO(unsigned long phys, unsigned long size);
 extern void MemUnmapIO(void* virt);
 
-extern void* MemAllocAtomic(unsigned int size);
 extern void MemFree(void* buf);
 extern void MemoryFence(void);
 
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -1480,7 +1480,7 @@ NetVscOnChannelCallback(
 		}
 		else if (ret == -2) // Handle large packet
 		{
-			buffer = MemAllocAtomic(bytesRecvd);
+			buffer = kmalloc(bytesRecvd, GFP_ATOMIC);
 			if (buffer == NULL)
 			{
 				// Try again next time around
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -189,11 +189,6 @@ void PageUnmapVirtualAddress(void* VirtA
 	kunmap_atomic(VirtAddr, KM_IRQ0);
 }
 
-void* MemAllocAtomic(unsigned int size)
-{
-	return kmalloc(size, GFP_ATOMIC);
-}
-
 void MemFree(void* buf)
 {
 	kfree(buf);
--- a/drivers/staging/hv/Vmbus.c
+++ b/drivers/staging/hv/Vmbus.c
@@ -411,7 +411,7 @@ VmbusOnMsgDPC(
 		}
 		else
 		{
-			copied = MemAllocAtomic(sizeof(HV_MESSAGE));
+			copied = kmalloc(sizeof(HV_MESSAGE), GFP_ATOMIC);
 			if (copied == NULL)
 			{
 				continue;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 41/54] Staging: hv: osd: remove MemFree wrapper
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (40 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization; +Cc: Sam Ramji, Haiyang Zhang, shemminger

[-- Attachment #1: staging-hv-osd-remove-memfree-wrapper.patch --]
[-- Type: text/plain, Size: 7567 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the "real" kfree call instead of a wrapper function.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/Channel.c     |    8 ++++----
 drivers/staging/hv/ChannelMgmt.c |   14 +++++++-------
 drivers/staging/hv/Connection.c  |    6 +++---
 drivers/staging/hv/Hv.c          |    4 ++--
 drivers/staging/hv/NetVsc.c      |   12 ++++++------
 drivers/staging/hv/RndisFilter.c |    8 ++++----
 drivers/staging/hv/StorVsc.c     |    2 +-
 drivers/staging/hv/include/osd.h |    1 -
 drivers/staging/hv/osd.c         |    5 -----
 9 files changed, 27 insertions(+), 33 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -311,7 +311,7 @@ Cleanup:
 	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
 
 	WaitEventClose(openInfo->WaitEvent);
-	MemFree(openInfo);
+	kfree(openInfo);
 
 	DPRINT_EXIT(VMBUS);
 
@@ -597,7 +597,7 @@ Cleanup:
 	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
 
 	WaitEventClose(msgInfo->WaitEvent);
-	MemFree(msgInfo);
+	kfree(msgInfo);
 
 	DPRINT_EXIT(VMBUS);
 
@@ -658,7 +658,7 @@ VmbusChannelTeardownGpadl(
 	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
 
 	WaitEventClose(info->WaitEvent);
-	MemFree(info);
+	kfree(info);
 
 	DPRINT_EXIT(VMBUS);
 
@@ -720,7 +720,7 @@ VmbusChannelClose(
 
 	PageFree(Channel->RingBufferPages, Channel->RingBufferPageCount);
 
-	MemFree(info);
+	kfree(info);
 
 	// If we are closing the channel during an error path in opening the channel, don't free the channel
 	// since the caller will free the channel
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -152,7 +152,7 @@ VMBUS_CHANNEL* AllocVmbusChannel(void)
 	channel->InboundLock = SpinlockCreate();
 	if (!channel->InboundLock)
 	{
-		MemFree(channel);
+		kfree(channel);
 		return NULL;
 	}
 
@@ -160,7 +160,7 @@ VMBUS_CHANNEL* AllocVmbusChannel(void)
 	if (!channel->PollTimer)
 	{
 		SpinlockClose(channel->InboundLock);
-		MemFree(channel);
+		kfree(channel);
 		return NULL;
 	}
 
@@ -170,7 +170,7 @@ VMBUS_CHANNEL* AllocVmbusChannel(void)
 	{
 		TimerClose(channel->PollTimer);
 		SpinlockClose(channel->InboundLock);
-		MemFree(channel);
+		kfree(channel);
 		return NULL;
 	}
 
@@ -196,7 +196,7 @@ static inline void ReleaseVmbusChannel(v
 	WorkQueueClose(channel->ControlWQ);
 	DPRINT_DBG(VMBUS, "channel released (%p)", channel);
 
-	MemFree(channel);
+	kfree(channel);
 
 	DPRINT_EXIT(VMBUS);
 }
@@ -691,7 +691,7 @@ VmbusOnChannelMessage(
 	{
 		DPRINT_ERR(VMBUS, "Received invalid channel message type %d size %d", hdr->MessageType, size);
 		PrintBytes((unsigned char *)msg->u.Payload, size);
-		MemFree(msg);
+		kfree(msg);
 		return;
 	}
 
@@ -705,7 +705,7 @@ VmbusOnChannelMessage(
 	}
 
 	// Free the msg that was allocated in VmbusOnMsgDPC()
-	MemFree(msg);
+	kfree(msg);
 	DPRINT_EXIT(VMBUS);
 }
 
@@ -764,7 +764,7 @@ Cleanup:
 	if (msgInfo)
 	{
 		WaitEventClose(msgInfo->WaitEvent);
-		MemFree(msgInfo);
+		kfree(msgInfo);
 	}
 
 	DPRINT_EXIT(VMBUS);
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -145,7 +145,7 @@ VmbusConnect(
 
 
 	WaitEventClose(msgInfo->WaitEvent);
-	MemFree(msgInfo);
+	kfree(msgInfo);
 	DPRINT_EXIT(VMBUS);
 
 	return 0;
@@ -175,7 +175,7 @@ Cleanup:
 		if (msgInfo->WaitEvent)
 			WaitEventClose(msgInfo->WaitEvent);
 
-		MemFree(msgInfo);
+		kfree(msgInfo);
 	}
 
 	DPRINT_EXIT(VMBUS);
@@ -233,7 +233,7 @@ VmbusDisconnect(
 Cleanup:
 	if (msg)
 	{
-		MemFree(msg);
+		kfree(msg);
 	}
 
 	DPRINT_EXIT(VMBUS);
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -361,7 +361,7 @@ HvCleanup (
 
 	if (gHvContext.SignalEventBuffer)
 	{
-		MemFree(gHvContext.SignalEventBuffer);
+		kfree(gHvContext.SignalEventBuffer);
 		gHvContext.SignalEventBuffer = NULL;
 		gHvContext.SignalEventParam = NULL;
 	}
@@ -430,7 +430,7 @@ HvPostMessage(
 
 	status = HvDoHypercall(HvCallPostMessage, alignedMsg, 0) & 0xFFFF;
 
-	MemFree((void*)addr);
+	kfree((void*)addr);
 
 	return status;
 }
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -121,7 +121,6 @@ extern void PageFree(void* page, unsigne
 extern void* MemMapIO(unsigned long phys, unsigned long size);
 extern void MemUnmapIO(void* virt);
 
-extern void MemFree(void* buf);
 extern void MemoryFence(void);
 
 extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -139,7 +139,7 @@ static inline void FreeNetDevice(NETVSC_
 {
 	ASSERT(Device->RefCount == 0);
 	Device->Device->Extension = NULL;
-	MemFree(Device);
+	kfree(Device);
 }
 
 
@@ -563,7 +563,7 @@ NetVscDestroyReceiveBuffer(
 
 	if (NetDevice->ReceiveSections)
 	{
-		MemFree(NetDevice->ReceiveSections);
+		kfree(NetDevice->ReceiveSections);
 		NetDevice->ReceiveSections = NULL;
 		NetDevice->ReceiveSectionCount = 0;
 	}
@@ -873,7 +873,7 @@ Cleanup:
 		{
 			entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
 			packet = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
-			MemFree(packet);
+			kfree(packet);
 		}
 
 		SpinlockClose(netDevice->ReceivePacketListLock);
@@ -949,7 +949,7 @@ NetVscOnDeviceRemove(
 		entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
 		netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
 
-		MemFree(netvscPacket);
+		kfree(netvscPacket);
 	}
 
 	SpinlockClose(netDevice->ReceivePacketListLock);
@@ -1456,7 +1456,7 @@ NetVscOnChannelCallback(
 				// reset
 				if (bufferlen > netPacketSize)
 				{
-					MemFree(buffer);
+					kfree(buffer);
 
 					buffer = packet;
 					bufferlen = netPacketSize;
@@ -1469,7 +1469,7 @@ NetVscOnChannelCallback(
 				// reset
 				if (bufferlen > netPacketSize)
 				{
-					MemFree(buffer);
+					kfree(buffer);
 
 					buffer = packet;
 					bufferlen = netPacketSize;
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -189,11 +189,6 @@ void PageUnmapVirtualAddress(void* VirtA
 	kunmap_atomic(VirtAddr, KM_IRQ0);
 }
 
-void MemFree(void* buf)
-{
-	kfree(buf);
-}
-
 void *MemMapIO(unsigned long phys, unsigned long size)
 {
 #if X2V_LINUX
--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -219,7 +219,7 @@ static inline RNDIS_DEVICE* GetRndisDevi
 	device->RequestLock = SpinlockCreate();
 	if (!device->RequestLock)
 	{
-		MemFree(device);
+		kfree(device);
 		return NULL;
 	}
 
@@ -233,7 +233,7 @@ static inline RNDIS_DEVICE* GetRndisDevi
 static inline void PutRndisDevice(RNDIS_DEVICE *Device)
 {
 	SpinlockClose(Device->RequestLock);
-	MemFree(Device);
+	kfree(Device);
 }
 
 static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageType, u32 MessageLength)
@@ -251,7 +251,7 @@ static inline RNDIS_REQUEST* GetRndisReq
 	request->WaitEvent = WaitEventCreate();
 	if (!request->WaitEvent)
 	{
-		MemFree(request);
+		kfree(request);
 		return NULL;
 	}
 
@@ -279,7 +279,7 @@ static inline void PutRndisRequest(RNDIS
 	SpinlockRelease(Device->RequestLock);
 
 	WaitEventClose(Request->WaitEvent);
-	MemFree(Request);
+	kfree(Request);
 }
 
 static inline void DumpRndisMessage(RNDIS_MESSAGE *RndisMessage)
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -164,7 +164,7 @@ static inline STORVSC_DEVICE* AllocStorD
 static inline void FreeStorDevice(STORVSC_DEVICE *Device)
 {
 	ASSERT(Device->RefCount == 0);
-	MemFree(Device);
+	kfree(Device);
 }
 
 // Get the stordevice object iff exists and its refcount > 1

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 42/54] Staging: hv: make Channel->InboundLock a real spinlock
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (41 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-channel-inboundlock-a-real-spinlock.patch --]
[-- Type: text/plain, Size: 4378 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Don't use the wrapper functions for this lock, make it a real
lock so that we know what is going on.

I don't think we really want to be doing a irqsave for this code, but I
left it alone to preserve the original codepath.  It should be reviewed
later.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/Channel.c     |   18 ++++++++++--------
 drivers/staging/hv/ChannelMgmt.c |   10 +---------
 drivers/staging/hv/ChannelMgmt.h |    2 +-
 3 files changed, 12 insertions(+), 18 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -991,18 +991,19 @@ VmbusChannelRecvPacket(
 	u32 packetLen;
 	u32 userLen;
 	int ret;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
 	*BufferActualLen = 0;
 	*RequestId = 0;
 
-	SpinlockAcquire(Channel->InboundLock);
+	spin_lock_irqsave(&Channel->inbound_lock, flags);
 
 	ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
 	if (ret != 0)
 	{
-		SpinlockRelease(Channel->InboundLock);
+		spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
 		//DPRINT_DBG(VMBUS, "nothing to read!!");
 		DPRINT_EXIT(VMBUS);
@@ -1026,7 +1027,7 @@ VmbusChannelRecvPacket(
 
 	if (userLen > BufferLen)
 	{
-		SpinlockRelease(Channel->InboundLock);
+		spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
 		DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", BufferLen, userLen);
 		DPRINT_EXIT(VMBUS);
@@ -1039,7 +1040,7 @@ VmbusChannelRecvPacket(
 	// Copy over the packet to the user buffer
 	ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, (desc.DataOffset8 << 3));
 
-	SpinlockRelease(Channel->InboundLock);
+	spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
 	DPRINT_EXIT(VMBUS);
 
@@ -1068,18 +1069,19 @@ VmbusChannelRecvPacketRaw(
 	u32 packetLen;
 	u32 userLen;
 	int ret;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
 	*BufferActualLen = 0;
 	*RequestId = 0;
 
-	SpinlockAcquire(Channel->InboundLock);
+	spin_lock_irqsave(&Channel->inbound_lock, flags);
 
 	ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
 	if (ret != 0)
 	{
-		SpinlockRelease(Channel->InboundLock);
+		spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
 		//DPRINT_DBG(VMBUS, "nothing to read!!");
 		DPRINT_EXIT(VMBUS);
@@ -1102,7 +1104,7 @@ VmbusChannelRecvPacketRaw(
 
 	if (packetLen > BufferLen)
 	{
-		SpinlockRelease(Channel->InboundLock);
+		spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
 		DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but got space for only %d bytes", packetLen, BufferLen);
 		DPRINT_EXIT(VMBUS);
@@ -1114,7 +1116,7 @@ VmbusChannelRecvPacketRaw(
 	// Copy over the entire packet to the user buffer
 	ret = RingBufferRead(&Channel->Inbound, Buffer, packetLen, 0);
 
-	SpinlockRelease(Channel->InboundLock);
+	spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
 	DPRINT_EXIT(VMBUS);
 
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -149,17 +149,11 @@ VMBUS_CHANNEL* AllocVmbusChannel(void)
 		return NULL;
 	}
 
-	channel->InboundLock = SpinlockCreate();
-	if (!channel->InboundLock)
-	{
-		kfree(channel);
-		return NULL;
-	}
+	spin_lock_init(&channel->inbound_lock);
 
 	channel->PollTimer = TimerCreate(VmbusChannelOnTimer, channel);
 	if (!channel->PollTimer)
 	{
-		SpinlockClose(channel->InboundLock);
 		kfree(channel);
 		return NULL;
 	}
@@ -169,7 +163,6 @@ VMBUS_CHANNEL* AllocVmbusChannel(void)
 	if (!channel->ControlWQ)
 	{
 		TimerClose(channel->PollTimer);
-		SpinlockClose(channel->InboundLock);
 		kfree(channel);
 		return NULL;
 	}
@@ -212,7 +205,6 @@ Description:
 --*/
 void FreeVmbusChannel(VMBUS_CHANNEL* Channel)
 {
-	SpinlockClose(Channel->InboundLock);
 	TimerClose(Channel->PollTimer);
 
 	// We have to release the channel's workqueue/thread in the vmbus's workqueue/thread context
--- a/drivers/staging/hv/ChannelMgmt.h
+++ b/drivers/staging/hv/ChannelMgmt.h
@@ -63,7 +63,7 @@ typedef struct _VMBUS_CHANNEL {
 	u32						RingBufferPageCount;
 	RING_BUFFER_INFO			Outbound;	// send to parent
 	RING_BUFFER_INFO			Inbound;	// receive from parent
-	HANDLE						InboundLock;
+	spinlock_t inbound_lock;
 	HANDLE						ControlWQ;
 
 	// Channel callback are invoked in this workqueue context

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 43/54] Staging: hv: make RingInfo->RingLock a real spinlock
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (42 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization; +Cc: Sam Ramji, Haiyang Zhang, shemminger

[-- Attachment #1: staging-hv-make-ringinfo-ringlock-a-real-spinlock.patch --]
[-- Type: text/plain, Size: 3912 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Don't use the wrapper functions for this lock, make it a real
lock so that we know what is going on.

I don't think we really want to be doing a irqsave for this code, but I
left it alone to preserve the original codepath.  It should be reviewed
later.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/RingBuffer.c |   24 +++++++++++++-----------
 drivers/staging/hv/RingBuffer.h |    2 +-
 2 files changed, 14 insertions(+), 12 deletions(-)

--- a/drivers/staging/hv/RingBuffer.c
+++ b/drivers/staging/hv/RingBuffer.c
@@ -315,7 +315,7 @@ RingBufferInit(
 	RingInfo->RingSize = BufferLen;
 	RingInfo->RingDataSize = BufferLen - sizeof(RING_BUFFER);
 
-	RingInfo->RingLock = SpinlockCreate();
+	spin_lock_init(&RingInfo->ring_lock);
 
 	return 0;
 }
@@ -334,7 +334,6 @@ RingBufferCleanup(
 	RING_BUFFER_INFO* RingInfo
 	)
 {
-	SpinlockClose(RingInfo->RingLock);
 }
 
 /*++
@@ -360,6 +359,7 @@ RingBufferWrite(
 
 	volatile u32 nextWriteLocation;
 	u64 prevIndices=0;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -370,7 +370,7 @@ RingBufferWrite(
 
 	totalBytesToWrite += sizeof(u64);
 
-	SpinlockAcquire(OutRingInfo->RingLock);
+	spin_lock_irqsave(&OutRingInfo->ring_lock, flags);
 
 	GetRingBufferAvailBytes(OutRingInfo, &byteAvailToRead, &byteAvailToWrite);
 
@@ -384,7 +384,7 @@ RingBufferWrite(
 	{
 		DPRINT_DBG(VMBUS, "No more space left on outbound ring buffer (needed %u, avail %u)", totalBytesToWrite, byteAvailToWrite);
 
-		SpinlockRelease(OutRingInfo->RingLock);
+		spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags);
 
 		DPRINT_EXIT(VMBUS);
 
@@ -418,7 +418,7 @@ RingBufferWrite(
 
 	//DumpRingInfo(OutRingInfo, "AFTER ");
 
-	SpinlockRelease(OutRingInfo->RingLock);
+	spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags);
 
 	DPRINT_EXIT(VMBUS);
 
@@ -445,8 +445,9 @@ RingBufferPeek(
 	u32 bytesAvailToWrite;
 	u32 bytesAvailToRead;
 	u32 nextReadLocation=0;
+	unsigned long flags;
 
-	SpinlockAcquire(InRingInfo->RingLock);
+	spin_lock_irqsave(&InRingInfo->ring_lock, flags);
 
 	GetRingBufferAvailBytes(InRingInfo, &bytesAvailToRead, &bytesAvailToWrite);
 
@@ -455,7 +456,7 @@ RingBufferPeek(
 	{
 		//DPRINT_DBG(VMBUS, "got callback but not enough to read <avail to read %d read size %d>!!", bytesAvailToRead, BufferLen);
 
-		SpinlockRelease(InRingInfo->RingLock);
+		spin_unlock_irqrestore(&InRingInfo->ring_lock, flags);
 
 		return -1;
 	}
@@ -468,7 +469,7 @@ RingBufferPeek(
 											BufferLen,
 											nextReadLocation);
 
-	SpinlockRelease(InRingInfo->RingLock);
+	spin_unlock_irqrestore(&InRingInfo->ring_lock, flags);
 
 	return 0;
 }
@@ -495,10 +496,11 @@ RingBufferRead(
 	u32 bytesAvailToRead;
 	u32 nextReadLocation=0;
 	u64 prevIndices=0;
+	unsigned long flags;
 
 	ASSERT(BufferLen > 0);
 
-	SpinlockAcquire(InRingInfo->RingLock);
+	spin_lock_irqsave(&InRingInfo->ring_lock, flags);
 
 	GetRingBufferAvailBytes(InRingInfo, &bytesAvailToRead, &bytesAvailToWrite);
 
@@ -511,7 +513,7 @@ RingBufferRead(
 	{
 		DPRINT_DBG(VMBUS, "got callback but not enough to read <avail to read %d read size %d>!!", bytesAvailToRead, BufferLen);
 
-		SpinlockRelease(InRingInfo->RingLock);
+		spin_unlock_irqrestore(&InRingInfo->ring_lock, flags);
 
 		return -1;
 	}
@@ -537,7 +539,7 @@ RingBufferRead(
 
 	//DumpRingInfo(InRingInfo, "AFTER ");
 
-	SpinlockRelease(InRingInfo->RingLock);
+	spin_unlock_irqrestore(&InRingInfo->ring_lock, flags);
 
 	return 0;
 }
--- a/drivers/staging/hv/RingBuffer.h
+++ b/drivers/staging/hv/RingBuffer.h
@@ -48,7 +48,7 @@ typedef struct _RING_BUFFER {
 typedef struct _RING_BUFFER_INFO {
     RING_BUFFER*	RingBuffer;
     u32			RingSize;			// Include the shared header
-	HANDLE			RingLock;
+	spinlock_t ring_lock;
 
     u32			RingDataSize;		// < ringSize
 	u32			RingDataStartOffset;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 44/54] Staging: hv: make Device->RequestLock a real spinlock
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (43 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-device-requestlock-a-real-spinlock.patch --]
[-- Type: text/plain, Size: 2985 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Don't use the wrapper functions for this lock, make it a real
lock so that we know what is going on.

I don't think we really want to be doing a irqsave for this code, but I
left it alone to preserve the original codepath.  It should be reviewed
later.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/RndisFilter.c |   26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

--- a/drivers/staging/hv/RndisFilter.c
+++ b/drivers/staging/hv/RndisFilter.c
@@ -54,7 +54,7 @@ typedef struct _RNDIS_DEVICE {
 	u32					LinkStatus;
 	u32					NewRequestId;
 
-	HANDLE					RequestLock;
+	spinlock_t request_lock;
 	LIST_ENTRY				RequestList;
 
 	unsigned char					HwMacAddr[HW_MACADDR_LEN];
@@ -216,12 +216,7 @@ static inline RNDIS_DEVICE* GetRndisDevi
 		return NULL;
 	}
 
-	device->RequestLock = SpinlockCreate();
-	if (!device->RequestLock)
-	{
-		kfree(device);
-		return NULL;
-	}
+	spin_lock_init(&device->request_lock);
 
 	INITIALIZE_LIST_HEAD(&device->RequestList);
 
@@ -232,7 +227,6 @@ static inline RNDIS_DEVICE* GetRndisDevi
 
 static inline void PutRndisDevice(RNDIS_DEVICE *Device)
 {
-	SpinlockClose(Device->RequestLock);
 	kfree(Device);
 }
 
@@ -241,6 +235,7 @@ static inline RNDIS_REQUEST* GetRndisReq
 	RNDIS_REQUEST *request;
 	RNDIS_MESSAGE *rndisMessage;
 	RNDIS_SET_REQUEST *set;
+	unsigned long flags;
 
 	request = kzalloc(sizeof(RNDIS_REQUEST), GFP_KERNEL);
 	if (!request)
@@ -265,18 +260,20 @@ static inline RNDIS_REQUEST* GetRndisReq
 	set->RequestId = InterlockedIncrement((int*)&Device->NewRequestId);
 
 	// Add to the request list
-	SpinlockAcquire(Device->RequestLock);
+	spin_lock_irqsave(&Device->request_lock, flags);
 	INSERT_TAIL_LIST(&Device->RequestList, &request->ListEntry);
-	SpinlockRelease(Device->RequestLock);
+	spin_unlock_irqrestore(&Device->request_lock, flags);
 
 	return request;
 }
 
 static inline void PutRndisRequest(RNDIS_DEVICE *Device, RNDIS_REQUEST *Request)
 {
-	SpinlockAcquire(Device->RequestLock);
+	unsigned long flags;
+
+	spin_lock_irqsave(&Device->request_lock, flags);
 	REMOVE_ENTRY_LIST(&Request->ListEntry);
-	SpinlockRelease(Device->RequestLock);
+	spin_unlock_irqrestore(&Device->request_lock, flags);
 
 	WaitEventClose(Request->WaitEvent);
 	kfree(Request);
@@ -385,10 +382,11 @@ RndisFilterReceiveResponse(
 	LIST_ENTRY *curr;
 	RNDIS_REQUEST *request=NULL;
 	bool found = false;
+	unsigned long flags;
 
 	DPRINT_ENTER(NETVSC);
 
-	SpinlockAcquire(Device->RequestLock);
+	spin_lock_irqsave(&Device->request_lock, flags);
 	ITERATE_LIST_ENTRIES(anchor, curr, &Device->RequestList)
 	{
 		request = CONTAINING_RECORD(curr, RNDIS_REQUEST, ListEntry);
@@ -403,7 +401,7 @@ RndisFilterReceiveResponse(
 			break;
 		}
 	}
-	SpinlockRelease(Device->RequestLock);
+	spin_unlock_irqrestore(&Device->request_lock, flags);
 
 	if (found)
 	{

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 45/54] Staging: hv: make netDevice->ReceivePacketListLock a real spinlock
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (44 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-netdevice-receivepacketlistlock-a-real-spinlock.patch --]
[-- Type: text/plain, Size: 4351 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Don't use the wrapper functions for this lock, make it a real
lock so that we know what is going on.

I don't think we really want to be doing a irqsave for this code, but I
left it alone to preserve the original codepath.  It should be reviewed
later.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/NetVsc.c |   19 +++++++++----------
 drivers/staging/hv/NetVsc.h |    2 +-
 2 files changed, 10 insertions(+), 11 deletions(-)

--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -807,7 +807,7 @@ NetVscOnDeviceAdd(
 
 	// Initialize the NetVSC channel extension
 	netDevice->ReceiveBufferSize = NETVSC_RECEIVE_BUFFER_SIZE;
-	netDevice->ReceivePacketListLock = SpinlockCreate();
+	spin_lock_init(&netDevice->receive_packet_list_lock);
 
 	netDevice->SendBufferSize = NETVSC_SEND_BUFFER_SIZE;
 
@@ -876,8 +876,6 @@ Cleanup:
 			kfree(packet);
 		}
 
-		SpinlockClose(netDevice->ReceivePacketListLock);
-
 		ReleaseOutboundNetDevice(Device);
 		ReleaseInboundNetDevice(Device);
 
@@ -952,7 +950,6 @@ NetVscOnDeviceRemove(
 		kfree(netvscPacket);
 	}
 
-	SpinlockClose(netDevice->ReceivePacketListLock);
 	WaitEventClose(netDevice->ChannelInitEvent);
 	FreeNetDevice(netDevice);
 
@@ -1118,6 +1115,7 @@ NetVscOnReceive(
 
 	int i=0, j=0;
 	int count=0, bytesRemain=0;
+	unsigned long flags;
 
 	DPRINT_ENTER(NETVSC);
 
@@ -1164,7 +1162,7 @@ NetVscOnReceive(
 
 	// Grab free packets (range count + 1) to represent this xfer page packet. +1 to represent
 	// the xfer page packet itself. We grab it here so that we know exactly how many we can fulfil
-	SpinlockAcquire(netDevice->ReceivePacketListLock);
+	spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
 	while (!IsListEmpty(&netDevice->ReceivePacketList))
 	{
 		entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
@@ -1175,7 +1173,7 @@ NetVscOnReceive(
 		if (++count == vmxferpagePacket->RangeCount + 1)
 			break;
 	}
-	SpinlockRelease(netDevice->ReceivePacketListLock);
+	spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
 
 	// We need at least 2 netvsc pkts (1 to represent the xfer page and at least 1 for the range)
 	// i.e. we can handled some of the xfer page packet ranges...
@@ -1184,7 +1182,7 @@ NetVscOnReceive(
 		DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. Dropping this xfer page packet completely!", count, vmxferpagePacket->RangeCount+1);
 
 		// Return it to the freelist
-		SpinlockAcquire(netDevice->ReceivePacketListLock);
+		spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
 		for (i=count; i != 0; i--)
 		{
 			entry = REMOVE_HEAD_LIST(&listHead);
@@ -1192,7 +1190,7 @@ NetVscOnReceive(
 
 			INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &netvscPacket->ListEntry);
 		}
-		SpinlockRelease(netDevice->ReceivePacketListLock);
+		spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
 
 		NetVscSendReceiveCompletion(Device, vmxferpagePacket->d.TransactionId);
 
@@ -1346,6 +1344,7 @@ NetVscOnReceiveCompletion(
 	NETVSC_DEVICE* netDevice;
 	u64	transactionId=0;
 	bool fSendReceiveComp = false;
+	unsigned long flags;
 
 	DPRINT_ENTER(NETVSC);
 
@@ -1362,7 +1361,7 @@ NetVscOnReceiveCompletion(
 	}
 
 	// Overloading use of the lock.
-	SpinlockAcquire(netDevice->ReceivePacketListLock);
+	spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
 
 	ASSERT(packet->XferPagePacket->Count > 0);
 	packet->XferPagePacket->Count--;
@@ -1379,7 +1378,7 @@ NetVscOnReceiveCompletion(
 
 	// Put the packet back
 	INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry);
-	SpinlockRelease(netDevice->ReceivePacketListLock);
+	spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
 
 	// Send a receive completion for the xfer page packet
 	if (fSendReceiveComp)
--- a/drivers/staging/hv/NetVsc.h
+++ b/drivers/staging/hv/NetVsc.h
@@ -62,7 +62,7 @@ typedef struct _NETVSC_DEVICE {
 	int								NumOutstandingSends;
 	// List of free preallocated NETVSC_PACKET to represent receive packet
 	LIST_ENTRY						ReceivePacketList;
-	HANDLE							ReceivePacketListLock;
+	spinlock_t receive_packet_list_lock;
 
 	// Send buffer allocated by us but manages by NetVSP
 	void *							SendBuffer;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 46/54] Staging: hv: make gVmbusConnection.ChannelMsgLock a real spinlock
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (45 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-gvmbusconnection.channelmsglock-a-real-spinlock.patch --]
[-- Type: text/plain, Size: 9233 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Don't use the wrapper functions for this lock, make it a real
lock so that we know what is going on.

I don't think we really want to be doing a irqsave for this code, but I
left it alone to preserve the original codepath.  It should be reviewed
later.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/Channel.c      |   27 +++++++++++++++------------
 drivers/staging/hv/ChannelMgmt.c  |   20 ++++++++++++--------
 drivers/staging/hv/Connection.c   |   10 ++++------
 drivers/staging/hv/VmbusPrivate.h |    2 +-
 4 files changed, 32 insertions(+), 27 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -214,6 +214,7 @@ VmbusChannelOpen(
 	VMBUS_CHANNEL_OPEN_CHANNEL* openMsg;
 	VMBUS_CHANNEL_MSGINFO* openInfo;
 	void *in, *out;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -280,9 +281,9 @@ VmbusChannelOpen(
 		memcpy(openMsg->UserData, UserData, UserDataLen);
 	}
 
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 	INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &openInfo->MsgListEntry);
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	DPRINT_DBG(VMBUS, "Sending channel open msg...");
 
@@ -306,9 +307,9 @@ VmbusChannelOpen(
 	}
 
 Cleanup:
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 	REMOVE_ENTRY_LIST(&openInfo->MsgListEntry);
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	WaitEventClose(openInfo->WaitEvent);
 	kfree(openInfo);
@@ -531,6 +532,7 @@ VmbusChannelEstablishGpadl(
 	LIST_ENTRY* anchor;
 	LIST_ENTRY* curr;
 	u32 nextGpadlHandle;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -549,9 +551,9 @@ VmbusChannelEstablishGpadl(
 
 	DumpGpadlHeader(gpadlMsg);
 
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 	INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry);
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", Kbuffer, Size, msgCount);
 
@@ -592,9 +594,9 @@ VmbusChannelEstablishGpadl(
 	*GpadlHandle = gpadlMsg->Gpadl;
 
 Cleanup:
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 	REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	WaitEventClose(msgInfo->WaitEvent);
 	kfree(msgInfo);
@@ -624,6 +626,7 @@ VmbusChannelTeardownGpadl(
 	int ret=0;
 	VMBUS_CHANNEL_GPADL_TEARDOWN *msg;
 	VMBUS_CHANNEL_MSGINFO* info;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -640,9 +643,9 @@ VmbusChannelTeardownGpadl(
     msg->ChildRelId  = Channel->OfferMsg.ChildRelId;
     msg->Gpadl       = GpadlHandle;
 
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 	INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &info->MsgListEntry);
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN));
 	if (ret != 0)
@@ -653,9 +656,9 @@ VmbusChannelTeardownGpadl(
 	WaitEventWait(info->WaitEvent);
 
 	// Received a torndown response
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 	REMOVE_ENTRY_LIST(&info->MsgListEntry);
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	WaitEventClose(info->WaitEvent);
 	kfree(info);
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -472,13 +472,14 @@ VmbusChannelOnOpenResult(
 	VMBUS_CHANNEL_MSGINFO* msgInfo;
 	VMBUS_CHANNEL_MESSAGE_HEADER* requestHeader;
 	VMBUS_CHANNEL_OPEN_CHANNEL* openMsg;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
 	DPRINT_DBG(VMBUS, "vmbus open result - %d", result->Status);
 
 	// Find the open msg, copy the result and signal/unblock the wait event
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 
 	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
 	{
@@ -497,7 +498,7 @@ VmbusChannelOnOpenResult(
 			}
 		}
 	}
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	DPRINT_EXIT(VMBUS);
 }
@@ -525,13 +526,14 @@ VmbusChannelOnGpadlCreated(
 	VMBUS_CHANNEL_MSGINFO *msgInfo;
 	VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
 	VMBUS_CHANNEL_GPADL_HEADER *gpadlHeader;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
 	DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", gpadlCreated->CreationStatus);
 
 	// Find the establish msg, copy the result and signal/unblock the wait event
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 
 	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
 	{
@@ -551,7 +553,7 @@ VmbusChannelOnGpadlCreated(
 			}
 		}
 	}
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	DPRINT_EXIT(VMBUS);
 }
@@ -579,11 +581,12 @@ VmbusChannelOnGpadlTorndown(
 	VMBUS_CHANNEL_MSGINFO* msgInfo;
 	VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
 	VMBUS_CHANNEL_GPADL_TEARDOWN *gpadlTeardown;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
 	// Find the open msg, copy the result and signal/unblock the wait event
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 
 	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
 	{
@@ -602,7 +605,7 @@ VmbusChannelOnGpadlTorndown(
 			}
 		}
 	}
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	DPRINT_EXIT(VMBUS);
 }
@@ -630,10 +633,11 @@ VmbusChannelOnVersionResponse(
 	VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
 	VMBUS_CHANNEL_INITIATE_CONTACT *initiate;
 	VMBUS_CHANNEL_VERSION_RESPONSE *versionResponse  = (VMBUS_CHANNEL_VERSION_RESPONSE*)hdr;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 
 	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
 	{
@@ -647,7 +651,7 @@ VmbusChannelOnVersionResponse(
 			WaitEventSet(msgInfo->WaitEvent);
 		}
 	}
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	DPRINT_EXIT(VMBUS);
 }
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -53,6 +53,7 @@ VmbusConnect(
 	int ret=0;
 	VMBUS_CHANNEL_MSGINFO *msgInfo=NULL;
 	VMBUS_CHANNEL_INITIATE_CONTACT *msg;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -65,7 +66,7 @@ VmbusConnect(
 	gVmbusConnection.WorkQueue = WorkQueueCreate("vmbusQ");
 
 	INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelMsgList);
-	gVmbusConnection.ChannelMsgLock = SpinlockCreate();
+	spin_lock_init(&gVmbusConnection.channelmsg_lock);
 
 	INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelList);
 	gVmbusConnection.ChannelLock = SpinlockCreate();
@@ -107,9 +108,9 @@ VmbusConnect(
 
 	// Add to list before we send the request since we may receive the response
 	// before returning from this routine
-	SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+	spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 	INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry);
-	SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
 	DPRINT_DBG(VMBUS, "Vmbus connection -  interrupt pfn %llx, monitor1 pfn %llx,, monitor2 pfn %llx",
 		msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2);
@@ -156,7 +157,6 @@ Cleanup:
 
 	WorkQueueClose(gVmbusConnection.WorkQueue);
 	SpinlockClose(gVmbusConnection.ChannelLock);
-	SpinlockClose(gVmbusConnection.ChannelMsgLock);
 
 	if (gVmbusConnection.InterruptPage)
 	{
@@ -222,8 +222,6 @@ VmbusDisconnect(
 
 	// TODO: iterate thru the msg list and free up
 
-	SpinlockClose(gVmbusConnection.ChannelMsgLock);
-
 	WorkQueueClose(gVmbusConnection.WorkQueue);
 
 	gVmbusConnection.ConnectState = Disconnected;
--- a/drivers/staging/hv/VmbusPrivate.h
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -80,7 +80,7 @@ typedef struct _VMBUS_CONNECTION {
 	// 2 pages - 1st page for parent->child notification and 2nd is child->parent notification
 	void *								MonitorPages;
 	LIST_ENTRY							ChannelMsgList;
-	HANDLE								ChannelMsgLock;
+	spinlock_t channelmsg_lock;
 
 	// List of channels
 	LIST_ENTRY							ChannelList;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 47/54] Staging: hv: make gVmbusConnection.ChannelLock a real spinlock
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (46 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  2009-07-20 23:39     ` Arnd Bergmann
  -1 siblings, 1 reply; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-make-gvmbusconnection.channellock-a-real-spinlock.patch --]
[-- Type: text/plain, Size: 4634 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Don't use the wrapper functions for this lock, make it a real
lock so that we know what is going on.

I don't think we really want to be doing a irqsave for this code, but I
left it alone to preserve the original codepath.  It should be reviewed
later.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/Channel.c      |    5 +++--
 drivers/staging/hv/ChannelMgmt.c  |   14 ++++++++------
 drivers/staging/hv/Connection.c   |    8 ++++----
 drivers/staging/hv/VmbusPrivate.h |    2 +-
 4 files changed, 16 insertions(+), 13 deletions(-)

--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -686,6 +686,7 @@ VmbusChannelClose(
 	int ret=0;
 	VMBUS_CHANNEL_CLOSE_CHANNEL* msg;
 	VMBUS_CHANNEL_MSGINFO* info;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
@@ -729,9 +730,9 @@ VmbusChannelClose(
 	// since the caller will free the channel
 	if (Channel->State == CHANNEL_OPEN_STATE)
 	{
-		SpinlockAcquire(gVmbusConnection.ChannelLock);
+		spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
 		REMOVE_ENTRY_LIST(&Channel->ListEntry);
-		SpinlockRelease(gVmbusConnection.ChannelLock);
+		spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
 
 		FreeVmbusChannel(Channel);
 	}
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -233,11 +233,12 @@ VmbusChannelProcessOffer(
 	LIST_ENTRY* curr;
 	bool fNew = true;
 	VMBUS_CHANNEL* channel;
+	unsigned long flags;
 
 	DPRINT_ENTER(VMBUS);
 
 	// Make sure this is a new offer
-	SpinlockAcquire(gVmbusConnection.ChannelLock);
+	spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
 
 	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList)
 	{
@@ -255,7 +256,7 @@ VmbusChannelProcessOffer(
 	{
 		INSERT_TAIL_LIST(&gVmbusConnection.ChannelList, &newChannel->ListEntry);
 	}
-	SpinlockRelease(gVmbusConnection.ChannelLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
 
 	if (!fNew)
 	{
@@ -282,9 +283,9 @@ VmbusChannelProcessOffer(
 		DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)",
 			newChannel->OfferMsg.ChildRelId);
 
-		SpinlockAcquire(gVmbusConnection.ChannelLock);
+		spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
 		REMOVE_ENTRY_LIST(&newChannel->ListEntry);
-		SpinlockRelease(gVmbusConnection.ChannelLock);
+		spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
 
 		FreeVmbusChannel(newChannel);
 	}
@@ -785,8 +786,9 @@ VmbusChannelReleaseUnattachedChannels(
 	LIST_ENTRY *entry;
 	VMBUS_CHANNEL *channel;
 	VMBUS_CHANNEL *start=NULL;
+	unsigned long flags;
 
-	SpinlockAcquire(gVmbusConnection.ChannelLock);
+	spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
 
 	while (!IsListEmpty(&gVmbusConnection.ChannelList))
 	{
@@ -813,7 +815,7 @@ VmbusChannelReleaseUnattachedChannels(
 		}
 	}
 
-	SpinlockRelease(gVmbusConnection.ChannelLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
 }
 
 // eof
--- a/drivers/staging/hv/Connection.c
+++ b/drivers/staging/hv/Connection.c
@@ -69,7 +69,7 @@ VmbusConnect(
 	spin_lock_init(&gVmbusConnection.channelmsg_lock);
 
 	INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelList);
-	gVmbusConnection.ChannelLock = SpinlockCreate();
+	spin_lock_init(&gVmbusConnection.channel_lock);
 
 	// Setup the vmbus event connection for channel interrupt abstraction stuff
 	gVmbusConnection.InterruptPage = PageAlloc(1);
@@ -156,7 +156,6 @@ Cleanup:
 	gVmbusConnection.ConnectState = Disconnected;
 
 	WorkQueueClose(gVmbusConnection.WorkQueue);
-	SpinlockClose(gVmbusConnection.ChannelLock);
 
 	if (gVmbusConnection.InterruptPage)
 	{
@@ -258,8 +257,9 @@ GetChannelFromRelId(
 	VMBUS_CHANNEL* foundChannel=NULL;
 	LIST_ENTRY* anchor;
 	LIST_ENTRY* curr;
+	unsigned long flags;
 
-	SpinlockAcquire(gVmbusConnection.ChannelLock);
+	spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
 	ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList)
 	{
 		channel = CONTAINING_RECORD(curr, VMBUS_CHANNEL, ListEntry);
@@ -270,7 +270,7 @@ GetChannelFromRelId(
 			break;
 		}
 	}
-	SpinlockRelease(gVmbusConnection.ChannelLock);
+	spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
 
 	return foundChannel;
 }
--- a/drivers/staging/hv/VmbusPrivate.h
+++ b/drivers/staging/hv/VmbusPrivate.h
@@ -84,7 +84,7 @@ typedef struct _VMBUS_CONNECTION {
 
 	// List of channels
 	LIST_ENTRY							ChannelList;
-	HANDLE								ChannelLock;
+	spinlock_t channel_lock;
 
 	HANDLE								WorkQueue;
 } VMBUS_CONNECTION;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 48/54] Staging: hv: osd: remove spinlock wrapper functions
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (47 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-spinlock-wrapper-functions.patch --]
[-- Type: text/plain, Size: 2000 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Now that there are no users of the wrapper functions for spinlocks,
remove them.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/include/osd.h |    5 -----
 drivers/staging/hv/osd.c         |   37 -------------------------------------
 2 files changed, 42 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -137,11 +137,6 @@ extern int	WaitEventWait(HANDLE hWait);
 // If >0, hWait got signaled. If ==0, timeout. If < 0, error
 extern int	WaitEventWaitEx(HANDLE hWait, u32 TimeoutInMs);
 
-extern HANDLE SpinlockCreate(void);
-extern void SpinlockClose(HANDLE hSpin);
-extern void SpinlockAcquire(HANDLE hSpin);
-extern void	SpinlockRelease(HANDLE hSpin);
-
 
 #define GetVirtualAddress Physical2LogicalAddr
 void* Physical2LogicalAddr(unsigned long PhysAddr);
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -61,11 +61,6 @@ typedef struct _WAITEVENT {
 	wait_queue_head_t event;
 } WAITEVENT;
 
-typedef struct _SPINLOCK {
-	spinlock_t		lock;
-	unsigned long	flags;
-} SPINLOCK;
-
 typedef struct _WORKQUEUE {
 	struct workqueue_struct *queue;
 } WORKQUEUE;
@@ -323,38 +318,6 @@ int WaitEventWaitEx(HANDLE hWait, u32 Ti
 	return ret;
 }
 
-HANDLE SpinlockCreate(void)
-{
-	SPINLOCK* spin = kmalloc(sizeof(SPINLOCK), GFP_KERNEL);
-	if (!spin)
-	{
-		return NULL;
-	}
-	spin_lock_init(&spin->lock);
-
-	return spin;
-}
-
-void SpinlockAcquire(HANDLE hSpin)
-{
-	SPINLOCK* spin = (SPINLOCK* )hSpin;
-
-	spin_lock_irqsave(&spin->lock, spin->flags);
-}
-
-void SpinlockRelease(HANDLE hSpin)
-{
-	SPINLOCK* spin = (SPINLOCK* )hSpin;
-
-	spin_unlock_irqrestore(&spin->lock, spin->flags);
-}
-
-void SpinlockClose(HANDLE hSpin)
-{
-	SPINLOCK* spin = (SPINLOCK* )hSpin;
-	kfree(spin);
-}
-
 void* Physical2LogicalAddr(unsigned long PhysAddr)
 {
 	void* logicalAddr = phys_to_virt(PhysAddr);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 49/54] Staging: hv: osd: remove Sleep wrapper
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (48 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-sleep-wrapper.patch --]
[-- Type: text/plain, Size: 3289 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the "real" udelay call instead of a wrapper function.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/NetVsc.c      |    9 +++++----
 drivers/staging/hv/StorVsc.c     |    7 ++++---
 drivers/staging/hv/include/osd.h |    2 --
 drivers/staging/hv/osd.c         |    5 -----
 4 files changed, 9 insertions(+), 14 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -110,8 +110,6 @@ extern int InterlockedIncrement(int *val
 extern int InterlockedDecrement(int *val);
 extern int InterlockedCompareExchange(int *val, int new, int curr);
 
-extern void Sleep(unsigned long usecs);
-
 extern void* VirtualAllocExec(unsigned int size);
 extern void VirtualFree(void* VirtAddr);
 
--- a/drivers/staging/hv/NetVsc.c
+++ b/drivers/staging/hv/NetVsc.c
@@ -24,6 +24,7 @@
 
 #include <linux/kernel.h>
 #include <linux/mm.h>
+#include <linux/delay.h>
 #include "include/logging.h"
 #include "NetVsc.h"
 #include "RndisFilter.h"
@@ -200,7 +201,7 @@ static inline NETVSC_DEVICE* ReleaseOutb
 	// Busy wait until the ref drop to 2, then set it to 1
 	while (InterlockedCompareExchange(&netDevice->RefCount, 1, 2) != 2)
 	{
-		Sleep(100);
+		udelay(100);
 	}
 
 	return netDevice;
@@ -217,7 +218,7 @@ static inline NETVSC_DEVICE* ReleaseInbo
 	// Busy wait until the ref drop to 1, then set it to 0
 	while (InterlockedCompareExchange(&netDevice->RefCount, 0, 1) != 1)
 	{
-		Sleep(100);
+		udelay(100);
 	}
 
 	Device->Extension = NULL;
@@ -923,7 +924,7 @@ NetVscOnDeviceRemove(
 	{
 		DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", netDevice->NumOutstandingSends);
 
-		Sleep(100);
+		udelay(100);
 	}
 
 	DPRINT_INFO(NETVSC, "Disconnecting from netvsp...");
@@ -1318,7 +1319,7 @@ retry_send_cmplt:
 
 		if (retries < 4)
 		{
-			Sleep(100);
+			udelay(100);
 			goto retry_send_cmplt;
 		}
 		else
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -131,11 +131,6 @@ int InterlockedCompareExchange(int *val,
 
 }
 
-void Sleep(unsigned long usecs)
-{
-	udelay(usecs);
-}
-
 void* VirtualAllocExec(unsigned int size)
 {
 #ifdef __x86_64__
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -26,6 +26,7 @@
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/mm.h>
+#include <linux/delay.h>
 #include "include/logging.h"
 
 #include "include/StorVscApi.h"
@@ -225,7 +226,7 @@ static inline STORVSC_DEVICE* ReleaseSto
 	// Busy wait until the ref drop to 2, then set it to 1
 	while (InterlockedCompareExchange(&storDevice->RefCount, 1, 2) != 2)
 	{
-		Sleep(100);
+		udelay(100);
 	}
 
 	return storDevice;
@@ -242,7 +243,7 @@ static inline STORVSC_DEVICE* FinalRelea
 	// Busy wait until the ref drop to 1, then set it to 0
 	while (InterlockedCompareExchange(&storDevice->RefCount, 0, 1) != 1)
 	{
-		Sleep(100);
+		udelay(100);
 	}
 
 	Device->Extension = NULL;
@@ -582,7 +583,7 @@ StorVscOnDeviceRemove(
 	{
 		DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", storDevice->NumOutstandingRequests);
 
-		Sleep(100);
+		udelay(100);
 	}
 
 	DPRINT_INFO(STORVSC, "removing storage device (%p)...", Device->Extension);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 50/54] Staging: hv: osd: remove MemoryFence wrapper
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (49 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-memoryfence-wrapper.patch --]
[-- Type: text/plain, Size: 2172 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the "real" mb call instead of a wrapper function.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/RingBuffer.c  |    4 ++--
 drivers/staging/hv/Vmbus.c       |    2 +-
 drivers/staging/hv/include/osd.h |    2 --
 drivers/staging/hv/osd.c         |    5 -----
 4 files changed, 3 insertions(+), 10 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -119,8 +119,6 @@ extern void PageFree(void* page, unsigne
 extern void* MemMapIO(unsigned long phys, unsigned long size);
 extern void MemUnmapIO(void* virt);
 
-extern void MemoryFence(void);
-
 extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
 extern void TimerClose(HANDLE hTimer);
 extern int TimerStop(HANDLE hTimer);
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -197,11 +197,6 @@ void MemUnmapIO(void *virt)
 	//iounmap(virt);
 }
 
-void MemoryFence()
-{
-	mb();
-}
-
 void TimerCallback(unsigned long data)
 {
 	TIMER* t = (TIMER*)data;
--- a/drivers/staging/hv/RingBuffer.c
+++ b/drivers/staging/hv/RingBuffer.c
@@ -411,7 +411,7 @@ RingBufferWrite(
 												sizeof(u64));
 
 	// Make sure we flush all writes before updating the writeIndex
-	MemoryFence();
+	mb();
 
 	// Now, update the write location
 	SetNextWriteLocation(OutRingInfo, nextWriteLocation);
@@ -532,7 +532,7 @@ RingBufferRead(
 
 	// Make sure all reads are done before we update the read index since
 	// the writer may start writing to the read area once the read index is updated
-	MemoryFence();
+	mb();
 
 	// Update the read index
 	SetNextReadLocation(InRingInfo, nextReadLocation);
--- a/drivers/staging/hv/Vmbus.c
+++ b/drivers/staging/hv/Vmbus.c
@@ -426,7 +426,7 @@ VmbusOnMsgDPC(
 		// Make sure the write to MessageType (ie set to HvMessageTypeNone) happens
 		// before we read the MessagePending and EOMing. Otherwise, the EOMing will not deliver
 		// any more messages since there is no empty slot
-		MemoryFence();
+		mb();
 
 		if (msg->Header.MessageFlags.MessagePending)
 		{

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 51/54] Staging: hv: osd: remove LogMsg wrapper
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (50 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-logmsg-wrapper.patch --]
[-- Type: text/plain, Size: 4925 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the "real" printk call instead of a wrapper function.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/include/logging.h |   54 ++++++++++++++++++++---------------
 drivers/staging/hv/include/osd.h     |    2 -
 drivers/staging/hv/osd.c             |   13 --------
 3 files changed, 31 insertions(+), 38 deletions(-)

--- a/drivers/staging/hv/include/logging.h
+++ b/drivers/staging/hv/include/logging.h
@@ -53,11 +53,10 @@
 							BLKVSC_DRV)
 
 // Logging Level
-#define CRITICAL_LVL				2
-#define ERROR_LVL					3
-#define WARNING_LVL					4
-#define INFO_LVL					6
-#define DEBUG_LVL					7
+#define ERROR_LVL				3
+#define WARNING_LVL				4
+#define INFO_LVL				6
+#define DEBUG_LVL				7
 #define DEBUG_LVL_ENTEREXIT			8
 #define DEBUG_RING_LVL				9
 
@@ -65,44 +64,53 @@ extern unsigned int vmbus_loglevel;
 
 #define ASSERT(expr)	\
         if (!(expr)) {	\
-		LogMsg("<%d>Assertion failed! %s,%s,%s,line=%d\n", CRITICAL_LVL, #expr,__FILE__,__FUNCTION__,__LINE__);	\
+		printk(KERN_CRIT "Assertion failed! %s,%s,%s,line=%d\n", \
+		       #expr, __FILE__, __func__, __LINE__);	\
 		__asm__ __volatile__("int3");	\
         }
 
 #define DPRINT(mod, lvl, fmt, args...) do {\
-	if (mod & (HIWORD(vmbus_loglevel))) \
-		(lvl <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() " fmt "\n", DEBUG_LVL, __FUNCTION__, ## args)):(0);\
+	if ((mod & (HIWORD(vmbus_loglevel))) &&	\
+	    (lvl <= LOWORD(vmbus_loglevel)))	\
+		printk(KERN_DEBUG #mod": %s() " fmt "\n", __func__, ## args);\
 	} while (0)
 
 #define DPRINT_DBG(mod, fmt, args...) do {\
-	if (mod & (HIWORD(vmbus_loglevel))) \
-		(DEBUG_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() " fmt "\n", DEBUG_LVL, __FUNCTION__, ## args)):(0);\
+	if ((mod & (HIWORD(vmbus_loglevel))) &&		\
+	    (DEBUG_LVL <= LOWORD(vmbus_loglevel)))	\
+		printk(KERN_DEBUG #mod": %s() " fmt "\n", __func__, ## args);\
 	} while (0)
 
 #define DPRINT_INFO(mod, fmt, args...) do {\
-	if (mod & (HIWORD(vmbus_loglevel))) \
-		(INFO_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": " fmt "\n", INFO_LVL, ## args)):(0);\
+	if ((mod & (HIWORD(vmbus_loglevel))) &&		\
+	    (INFO_LVL <= LOWORD(vmbus_loglevel)))	\
+		printk(KERN_INFO #mod": " fmt "\n", ## args);\
 	} while (0)
 
 #define DPRINT_WARN(mod, fmt, args...) do {\
-	if (mod & (HIWORD(vmbus_loglevel))) \
-		(WARNING_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": WARNING! " fmt "\n", WARNING_LVL, ## args)):(0);\
+	if ((mod & (HIWORD(vmbus_loglevel))) &&		\
+	    (WARNING_LVL <= LOWORD(vmbus_loglevel)))	\
+	    printk(KERN_WARNING #mod": WARNING! " fmt "\n", ## args);\
 	} while (0)
 
 #define DPRINT_ERR(mod, fmt, args...) do {\
-	if (mod & (HIWORD(vmbus_loglevel))) \
-		(ERROR_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() ERROR!! " fmt "\n", ERROR_LVL, __FUNCTION__, ## args)):(0);\
+	if ((mod & (HIWORD(vmbus_loglevel))) &&		\
+	    (ERROR_LVL <= LOWORD(vmbus_loglevel)))	\
+		printk(KERN_ERR #mod": %s() ERROR!! " fmt "\n",	\
+		       __func__, ## args);\
 	} while (0)
 
 #ifdef DEBUG
 #define DPRINT_ENTER(mod) do {\
-	if (mod & (HIWORD(vmbus_loglevel))) \
-		(DEBUG_LVL_ENTEREXIT <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" "["#mod"]: %s() enter\n", DEBUG_LVL, __FUNCTION__)):(0);\
+	if ((mod & (HIWORD(vmbus_loglevel))) && \
+	    (DEBUG_LVL_ENTEREXIT <= LOWORD(vmbus_loglevel)))	\
+	    printk(KERN_DEBUG "["#mod"]: %s() enter\n", __func__);\
 	} while (0)
 
 #define DPRINT_EXIT(mod) do {\
-	if (mod & (HIWORD(vmbus_loglevel))) \
-		(DEBUG_LVL_ENTEREXIT <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" "["#mod"]: %s() exit\n", DEBUG_LVL, __FUNCTION__)):(0);\
+	if ((mod & (HIWORD(vmbus_loglevel))) && \
+	    (DEBUG_LVL_ENTEREXIT <= LOWORD(vmbus_loglevel)))	\
+		printk(KERN_DEBUG "["#mod"]: %s() exit\n", __func__);\
 	} while (0)
 #else
 #define DPRINT_ENTER(mod)
@@ -113,12 +121,12 @@ static inline void PrintBytes(const unsi
 {
 	int i=0;
 
-	LogMsg("\n<< ");
+	printk("\n<< ");
 	for (i=0; i< len; i++)
 	{
-		LogMsg("0x%x ", bytes[i]);
+		printk("0x%x ", bytes[i]);
 	}
-	LogMsg(">>\n");
+	printk(">>\n");
 }
 
 //
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -98,8 +98,6 @@ static inline void do_cpuid(unsigned int
 //
 // Osd routines
 //
-extern void LogMsg(const char *fmt, ...);
-
 extern void BitSet(unsigned int* addr, int value);
 extern void BitClear(unsigned int* addr, int value);
 extern int BitTest(unsigned int* addr, int value);
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -72,19 +72,6 @@ typedef struct _WORKITEM {
 } WORKITEM;
 
 
-//
-// Global
-//
-
-void LogMsg(const char *fmt, ...)
-{
-	va_list args;
-
-	va_start(args, fmt);
-	vprintk(fmt, args);
-	va_end(args);
-}
-
 void BitSet(unsigned int* addr, int bit)
 {
 	set_bit(bit, (unsigned long*)addr);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 52/54] Staging: hv: osd: remove PrintBytes wrapper
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (51 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-printbytes-wrapper.patch --]
[-- Type: text/plain, Size: 2631 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

Use the "real" print_hex_dump_bytes call instead of a wrapper function.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/ChannelMgmt.c     |    3 ++-
 drivers/staging/hv/StorVsc.c         |    2 +-
 drivers/staging/hv/blkvsc_drv.c      |    5 +++--
 drivers/staging/hv/include/logging.h |   22 ----------------------
 4 files changed, 6 insertions(+), 26 deletions(-)

--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -578,7 +578,7 @@ static int blkvsc_do_inquiry(struct bloc
 
 	buf = kmap(page_buf);
 
-	//PrintBytes(buf, 64);
+	/* print_hex_dump_bytes("", DUMP_PREFIX_NONE, buf, 64); */
 	// be to le
 	device_type = buf[0] & 0x1F;
 
@@ -603,7 +603,8 @@ static int blkvsc_do_inquiry(struct bloc
 		blkdev->device_id_len = 64;
 
 	memcpy(blkdev->device_id, &buf[8], blkdev->device_id_len);
-	//PrintBytes(blkdev->device_id, blkdev->device_id_len);
+	/* printk_hex_dump_bytes("", DUMP_PREFIX_NONE, blkdev->device_id,
+	 * 			 blkdev->device_id_len); */
 
 	kunmap(page_buf);
 
--- a/drivers/staging/hv/ChannelMgmt.c
+++ b/drivers/staging/hv/ChannelMgmt.c
@@ -687,7 +687,8 @@ VmbusOnChannelMessage(
 	if (hdr->MessageType >= ChannelMessageCount)
 	{
 		DPRINT_ERR(VMBUS, "Received invalid channel message type %d size %d", hdr->MessageType, size);
-		PrintBytes((unsigned char *)msg->u.Payload, size);
+		print_hex_dump_bytes("", DUMP_PREFIX_NONE,
+				     (unsigned char *)msg->u.Payload, size);
 		kfree(msg);
 		return;
 	}
--- a/drivers/staging/hv/include/logging.h
+++ b/drivers/staging/hv/include/logging.h
@@ -117,26 +117,4 @@ extern unsigned int vmbus_loglevel;
 #define DPRINT_EXIT(mod)
 #endif
 
-static inline void PrintBytes(const unsigned char* bytes, int len)
-{
-	int i=0;
-
-	printk("\n<< ");
-	for (i=0; i< len; i++)
-	{
-		printk("0x%x ", bytes[i]);
-	}
-	printk(">>\n");
-}
-
-//
-// Inline
-//
-//static inline void GuidToStr(const GUID g, char *str)
-//{
-//	sprintf(str, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
-//	g[3], g[2], g[1], g[0], g[5], g[4], g[7], g[6], g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15]);
-//
-//}
-
 #endif //_LOGGING_H_
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -713,7 +713,7 @@ StorVscOnIORequest(
 		return -2;
 	}
 
-	//PrintBytes(Request->Cdb, Request->CdbLen);
+	/* print_hex_dump_bytes("", DUMP_PREFIX_NONE, Request->Cdb, Request->CdbLen); */
 
 	requestExtension->Request = Request;
 	requestExtension->Device  = Device;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 53/54] Staging: hv: fix up printk warnings
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (52 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-fix-up-printk-warnings.patch --]
[-- Type: text/plain, Size: 8183 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

After LogMsg was converted to printk, lots of build warnings showed up
as no one was checking the arguments to LogMsg.  This patch fixes them
all.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/Hv.c          |    6 +++---
 drivers/staging/hv/StorVsc.c     |   16 ++++++++--------
 drivers/staging/hv/blkvsc_drv.c  |   12 ++++++------
 drivers/staging/hv/storvsc_drv.c |    2 +-
 4 files changed, 18 insertions(+), 18 deletions(-)

--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -918,7 +918,7 @@ static int blkvsc_submit_request(struct 
 
 	STORVSC_REQUEST *storvsc_req;
 
-	DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p type %s start_sector %llu count %d offset %d len %d\n",
+	DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p type %s start_sector %llu count %ld offset %d len %d\n",
 		blkvsc_req,
 		(blkvsc_req->write)?"WRITE":"READ",
 		blkvsc_req->sector_start,
@@ -1087,7 +1087,7 @@ static int blkvsc_do_request(struct bloc
 	{
 		if (pending)
 		{
-			DPRINT_DBG(BLKVSC_DRV, "adding blkvsc_req to pending_list - blkvsc_req %p start_sect %llu sect_count %d (%llu %d)\n",
+			DPRINT_DBG(BLKVSC_DRV, "adding blkvsc_req to pending_list - blkvsc_req %p start_sect %llu sect_count %ld (%llu %ld)\n",
 				blkvsc_req, blkvsc_req->sector_start, blkvsc_req->sector_count, start_sector, num_sectors);
 
 			list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list);
@@ -1101,7 +1101,7 @@ static int blkvsc_do_request(struct bloc
 				list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list);
 			}
 
-			DPRINT_DBG(BLKVSC_DRV, "submitted blkvsc_req %p start_sect %llu sect_count %d (%llu %d) ret %d\n",
+			DPRINT_DBG(BLKVSC_DRV, "submitted blkvsc_req %p start_sect %llu sect_count %ld (%llu %ld) ret %d\n",
 				blkvsc_req, blkvsc_req->sector_start, blkvsc_req->sector_count, start_sector, num_sectors, ret);
 		}
 	}
@@ -1141,7 +1141,7 @@ static void blkvsc_request_completion(ST
 
 	ASSERT(blkvsc_req->group);
 
-	DPRINT_DBG(BLKVSC_DRV, "blkdev %p blkvsc_req %p group %p type %s sect_start %llu sect_count %d len %d group outstd %d total outstd %d\n",
+	DPRINT_DBG(BLKVSC_DRV, "blkdev %p blkvsc_req %p group %p type %s sect_start %llu sect_count %ld len %d group outstd %d total outstd %d\n",
 		blkdev,
 		blkvsc_req,
 		blkvsc_req->group,
@@ -1163,7 +1163,7 @@ static void blkvsc_request_completion(ST
 	{
 		list_for_each_entry_safe(comp_req, tmp, &blkvsc_req->group->blkvsc_req_list, req_entry)
 		{
-			DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %llu sect_count %d \n",
+			DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %llu sect_count %ld \n",
 				comp_req,
 				comp_req->sector_start,
 				comp_req->sector_count);
@@ -1222,7 +1222,7 @@ static int blkvsc_cancel_pending_reqs(st
 		// until we hit the pend_req
 		list_for_each_entry_safe(comp_req, tmp2, &pend_req->group->blkvsc_req_list, req_entry)
 		{
-			DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %llu sect_count %d \n",
+			DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %llu sect_count %ld \n",
 				comp_req,
 				comp_req->sector_start,
 				comp_req->sector_count);
--- a/drivers/staging/hv/Hv.c
+++ b/drivers/staging/hv/Hv.c
@@ -300,9 +300,9 @@ HvInit (
 		goto Cleanup;
 	}
 
-    DPRINT_INFO(VMBUS, "Hypercall page VA=0x%08x, PA=0x%08x",
-               (unsigned long)gHvContext.HypercallPage,
-               (unsigned long)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT);
+	DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx",
+		    gHvContext.HypercallPage,
+		    (u64)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT);
 
 	// Setup the global signal event param for the signal event hypercall
 	gHvContext.SignalEventBuffer = kmalloc(sizeof(HV_INPUT_SIGNAL_EVENT_BUFFER), GFP_KERNEL);
--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -348,7 +348,7 @@ StorVscOnDeviceAdd(
 	deviceInfo->PathId = storDevice->PathId;
 	deviceInfo->TargetId = storDevice->TargetId;
 
-	DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", storDevice->PortNumber, storDevice->PathId, storDevice->TargetId);
+	DPRINT_DBG(STORVSC, "assigned port %lu, path %u target %u\n", storDevice->PortNumber, storDevice->PathId, storDevice->TargetId);
 
 Cleanup:
 	DPRINT_EXIT(STORVSC);
@@ -404,7 +404,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 
 	if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
 	{
-		DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
+		DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed (op %d status 0x%lx)", vstorPacket->Operation, vstorPacket->Status);
 		goto Cleanup;
 	}
 
@@ -435,7 +435,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 	// TODO: Check returned version
 	if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
 	{
-		DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
+		DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed (op %d status 0x%lx)", vstorPacket->Operation, vstorPacket->Status);
 		goto Cleanup;
 	}
 
@@ -465,7 +465,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 	// TODO: Check returned version
 	if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
 	{
-		DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
+		DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed (op %d status 0x%lx)", vstorPacket->Operation, vstorPacket->Status);
 		goto Cleanup;
 	}
 
@@ -473,7 +473,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 	storDevice->PathId = vstorPacket->StorageChannelProperties.PathId;
 	storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId;
 
-	DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", vstorPacket->StorageChannelProperties.Flags, vstorPacket->StorageChannelProperties.MaxTransferBytes);
+	DPRINT_DBG(STORVSC, "channel flag 0x%lx, max xfer len 0x%lx", vstorPacket->StorageChannelProperties.Flags, vstorPacket->StorageChannelProperties.MaxTransferBytes);
 
 	DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
 
@@ -498,7 +498,7 @@ static int StorVscChannelInit(DEVICE_OBJ
 
 	if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
 	{
-		DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
+		DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed (op %d status 0x%lx)", vstorPacket->Operation, vstorPacket->Status);
 		goto Cleanup;
 	}
 
@@ -540,7 +540,7 @@ StorVscConnectToVsp(
 		Device
 		);
 
-	DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", props.PathId, props.TargetId, props.MaxTransferBytes);
+	DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %ld", props.PathId, props.TargetId, props.MaxTransferBytes);
 
 	if (ret != 0)
 	{
@@ -819,7 +819,7 @@ StorVscOnIOCompletion(
 		return;
 	}
 
-	DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p completed bytes xfer %u",
+	DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p completed bytes xfer %lu",
 		RequestExt, VStorPacket->VmSrb.DataTransferLength);
 
 	ASSERT(RequestExt != NULL);
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -1054,7 +1054,7 @@ static int storvsc_device_configure(stru
 	DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting queue depth to %d", sdevice, STORVSC_MAX_IO_REQUESTS);
 	scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG, STORVSC_MAX_IO_REQUESTS);
 
-	DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting max segment size to %d", sdevice, PAGE_SIZE);
+	DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting max segment size to %ld", sdevice, PAGE_SIZE);
 	blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
 
 	DPRINT_INFO(STORVSC_DRV, "sdev (%p) - adding merge bio vec routine", sdevice);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 54/54] Staging: hv: osd: remove GetTickCount and GetTimestamp wrappers
  2009-07-20 16:00   ` Greg Kroah-Hartman
                     ` (53 preceding siblings ...)
  (?)
@ 2009-07-17 18:09   ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-17 18:09 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

[-- Attachment #1: staging-hv-osd-remove-gettickcount-and-gettimestamp-wrappers.patch --]
[-- Type: text/plain, Size: 1139 bytes --]

From: Greg Kroah-Hartman <gregkh@suse.de>

No one was even using them.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/staging/hv/include/osd.h |    1 -
 drivers/staging/hv/osd.c         |   14 --------------
 2 files changed, 15 deletions(-)

--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -121,7 +121,6 @@ extern HANDLE TimerCreate(PFN_TIMER_CALL
 extern void TimerClose(HANDLE hTimer);
 extern int TimerStop(HANDLE hTimer);
 extern void TimerStart(HANDLE hTimer, u32 expirationInUs);
-extern size_t GetTickCount(void);
 
 extern HANDLE WaitEventCreate(void);
 extern void WaitEventClose(HANDLE hWait);
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -232,20 +232,6 @@ void TimerClose(HANDLE hTimer)
 	kfree(t);
 }
 
-size_t GetTickCount(void)
-{
-	return jiffies;
-}
-
-signed long long GetTimestamp(void)
-{
-	struct timeval t;
-
-	do_gettimeofday(&t);
-
-	return  timeval_to_ns(&t);
-}
-
 HANDLE WaitEventCreate(void)
 {
 	WAITEVENT* wait = kmalloc(sizeof(WAITEVENT), GFP_KERNEL);

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 16:00   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-20 16:00 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Hank Janssen, Haiyang Zhang, Sam Ramji, shemminger


Hi all,

I'm happy to announce, that after many months of discussions, Microsoft
has released their Hyper-V Linux drivers under the GPLv2.  Following
this message, will be the patches that add the drivers to the
drivers/staging/ tree, and a whole bunch of cleanups.

It's taken a long road to get here, and I'd like to thank the following
people who made this possible:
  - Steve Hemminger for the initial prodding and extreme patience
  - Hank Janssen for providing the code and working with me to get it
    into a workable and semi-mergable state.  His involvement within
    Microsoft was also invaluable.
  - Sam Ramji for his push within Microsoft to make this happen in a
    manner that works with the Linux community.
  - Novell for sponsoring my work on the Linux Driver project, without
    which, this would not have even been possible.
And there are many others both within Novell and Microsoft, who I do not
want to slight by not naming, but the list would be too long to go into.

These drivers are to enable Linux to work better when running as a guest
on top of the Hyper-V system.  There is still a lot of work to do in
getting this into "proper" mergable state, and moving it out of the
staging directory, but Hank and I will be undertaking this task.  See
the TODO file in the drivers/staging/hv/ directory if anyone wishes to
help out with this task.

The code should be showing up in the linux-next tree soon, as the
patches are now in my public tree.

If anyone has any questions about this code, please let me and Hank know
about it.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 16:00   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 97+ messages in thread
From: Greg Kroah-Hartman @ 2009-07-20 16:00 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Hank Janssen, Haiyang Zhang, Sam Ramji, shemminger


Hi all,

I'm happy to announce, that after many months of discussions, Microsoft
has released their Hyper-V Linux drivers under the GPLv2.  Following
this message, will be the patches that add the drivers to the
drivers/staging/ tree, and a whole bunch of cleanups.

It's taken a long road to get here, and I'd like to thank the following
people who made this possible:
  - Steve Hemminger for the initial prodding and extreme patience
  - Hank Janssen for providing the code and working with me to get it
    into a workable and semi-mergable state.  His involvement within
    Microsoft was also invaluable.
  - Sam Ramji for his push within Microsoft to make this happen in a
    manner that works with the Linux community.
  - Novell for sponsoring my work on the Linux Driver project, without
    which, this would not have even been possible.
And there are many others both within Novell and Microsoft, who I do not
want to slight by not naming, but the list would be too long to go into.

These drivers are to enable Linux to work better when running as a guest
on top of the Hyper-V system.  There is still a lot of work to do in
getting this into "proper" mergable state, and moving it out of the
staging directory, but Hank and I will be undertaking this task.  See
the TODO file in the drivers/staging/hv/ directory if anyone wishes to
help out with this task.

The code should be showing up in the linux-next tree soon, as the
patches are now in my public tree.

If anyone has any questions about this code, please let me and Hank know
about it.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 16:00   ` Greg Kroah-Hartman
@ 2009-07-20 16:28     ` Greg KH
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 16:28 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Hank Janssen, Haiyang Zhang, Sam Ramji, shemminger

On Mon, Jul 20, 2009 at 09:00:25AM -0700, Greg Kroah-Hartman wrote:
> 
> Hi all,
> 
> I'm happy to announce, that after many months of discussions, Microsoft
> has released their Hyper-V Linux drivers under the GPLv2.  Following
> this message, will be the patches that add the drivers to the
> drivers/staging/ tree, and a whole bunch of cleanups.

Hm, for some reason my scripts to send patches out caused them to get
eaten by the very good lkml filters.  (note, it was my fault, not
lkml's).

So instead of trying to send them again, and spaming everyone who
already got them, you can find them in my staging tree at:
	http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/gregkh-05-staging/

If anyone wants me to post any of the individual 54 patches to them,
please let me know.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 16:28     ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 16:28 UTC (permalink / raw)
  To: linux-kernel, devel, virtualization
  Cc: Hank Janssen, Haiyang Zhang, Sam Ramji, shemminger

On Mon, Jul 20, 2009 at 09:00:25AM -0700, Greg Kroah-Hartman wrote:
> 
> Hi all,
> 
> I'm happy to announce, that after many months of discussions, Microsoft
> has released their Hyper-V Linux drivers under the GPLv2.  Following
> this message, will be the patches that add the drivers to the
> drivers/staging/ tree, and a whole bunch of cleanups.

Hm, for some reason my scripts to send patches out caused them to get
eaten by the very good lkml filters.  (note, it was my fault, not
lkml's).

So instead of trying to send them again, and spaming everyone who
already got them, you can find them in my staging tree at:
	http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/gregkh-05-staging/

If anyone wants me to post any of the individual 54 patches to them,
please let me know.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 16:28     ` Greg KH
  (?)
@ 2009-07-20 16:59     ` Dave Jones
  2009-07-20 17:03         ` Greg KH
  2009-07-20 17:09         ` Matthias Urlichs
  -1 siblings, 2 replies; 97+ messages in thread
From: Dave Jones @ 2009-07-20 16:59 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-kernel, devel, virtualization, Hank Janssen, Haiyang Zhang,
	Sam Ramji, shemminger

On Mon, Jul 20, 2009 at 09:28:10AM -0700, Greg KH wrote:
 > On Mon, Jul 20, 2009 at 09:00:25AM -0700, Greg Kroah-Hartman wrote:
 > > 
 > > Hi all,
 > > 
 > > I'm happy to announce, that after many months of discussions, Microsoft
 > > has released their Hyper-V Linux drivers under the GPLv2.  Following
 > > this message, will be the patches that add the drivers to the
 > > drivers/staging/ tree, and a whole bunch of cleanups.
 > 
 > Hm, for some reason my scripts to send patches out caused them to get
 > eaten by the very good lkml filters.  (note, it was my fault, not
 > lkml's).
 > 
 > So instead of trying to send them again, and spaming everyone who
 > already got them, you can find them in my staging tree at:
 > 	http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/gregkh-05-staging/
 > 
 > If anyone wants me to post any of the individual 54 patches to them,
 > please let me know.

Given the numerous cleanup patches that already exist, is there any reason
to not just post the cleaned up drivers ?  It would certainly be more
reviewable than the current pile.

Come to think of it, is there any value in merging the pre-cleaned up
patches ? Why merge 54 patches to mainline when a half dozen will do ?

	Dave


^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 16:59     ` Dave Jones
@ 2009-07-20 17:03         ` Greg KH
  2009-07-20 17:09         ` Matthias Urlichs
  1 sibling, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 17:03 UTC (permalink / raw)
  To: Dave Jones, linux-kernel, devel, virtualization, Hank Janssen,
	Haiyang Zhang, Sam Ramji, shemminger

On Mon, Jul 20, 2009 at 12:59:41PM -0400, Dave Jones wrote:
> On Mon, Jul 20, 2009 at 09:28:10AM -0700, Greg KH wrote:
>  > On Mon, Jul 20, 2009 at 09:00:25AM -0700, Greg Kroah-Hartman wrote:
>  > > 
>  > > Hi all,
>  > > 
>  > > I'm happy to announce, that after many months of discussions, Microsoft
>  > > has released their Hyper-V Linux drivers under the GPLv2.  Following
>  > > this message, will be the patches that add the drivers to the
>  > > drivers/staging/ tree, and a whole bunch of cleanups.
>  > 
>  > Hm, for some reason my scripts to send patches out caused them to get
>  > eaten by the very good lkml filters.  (note, it was my fault, not
>  > lkml's).
>  > 
>  > So instead of trying to send them again, and spaming everyone who
>  > already got them, you can find them in my staging tree at:
>  > 	http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/gregkh-05-staging/
>  > 
>  > If anyone wants me to post any of the individual 54 patches to them,
>  > please let me know.
> 
> Given the numerous cleanup patches that already exist, is there any reason
> to not just post the cleaned up drivers ?  It would certainly be more
> reviewable than the current pile.
> 
> Come to think of it, is there any value in merging the pre-cleaned up
> patches ? Why merge 54 patches to mainline when a half dozen will do ?

It's the "normal" way of cleaning up code.  Start with a known-working
piece of stuff, and incrementally clean it up.  This way if I mess any
of the individual steps up, it's easy to find the problem.  This has
already paid off in the past week working with the Microsoft developers
to get this into a buildable / workable state.

The code still needs lots of cleanup, and review, as is evident by the
TODO file.  It looks like the patches did get sent to the driver-devel
and virtualization lists, so you can see them there if you want to.

But if you want, I can post the 4 individual drivers as of right now,
what they will show up in the linux-next tree tomorrow if you want me
to.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 17:03         ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 17:03 UTC (permalink / raw)
  To: Dave Jones, linux-kernel, devel, virtualization, Hank Janssen,
	Haiyang Zhang

On Mon, Jul 20, 2009 at 12:59:41PM -0400, Dave Jones wrote:
> On Mon, Jul 20, 2009 at 09:28:10AM -0700, Greg KH wrote:
>  > On Mon, Jul 20, 2009 at 09:00:25AM -0700, Greg Kroah-Hartman wrote:
>  > > 
>  > > Hi all,
>  > > 
>  > > I'm happy to announce, that after many months of discussions, Microsoft
>  > > has released their Hyper-V Linux drivers under the GPLv2.  Following
>  > > this message, will be the patches that add the drivers to the
>  > > drivers/staging/ tree, and a whole bunch of cleanups.
>  > 
>  > Hm, for some reason my scripts to send patches out caused them to get
>  > eaten by the very good lkml filters.  (note, it was my fault, not
>  > lkml's).
>  > 
>  > So instead of trying to send them again, and spaming everyone who
>  > already got them, you can find them in my staging tree at:
>  > 	http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/gregkh-05-staging/
>  > 
>  > If anyone wants me to post any of the individual 54 patches to them,
>  > please let me know.
> 
> Given the numerous cleanup patches that already exist, is there any reason
> to not just post the cleaned up drivers ?  It would certainly be more
> reviewable than the current pile.
> 
> Come to think of it, is there any value in merging the pre-cleaned up
> patches ? Why merge 54 patches to mainline when a half dozen will do ?

It's the "normal" way of cleaning up code.  Start with a known-working
piece of stuff, and incrementally clean it up.  This way if I mess any
of the individual steps up, it's easy to find the problem.  This has
already paid off in the past week working with the Microsoft developers
to get this into a buildable / workable state.

The code still needs lots of cleanup, and review, as is evident by the
TODO file.  It looks like the patches did get sent to the driver-devel
and virtualization lists, so you can see them there if you want to.

But if you want, I can post the 4 individual drivers as of right now,
what they will show up in the linux-next tree tomorrow if you want me
to.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 16:59     ` Dave Jones
@ 2009-07-20 17:09         ` Matthias Urlichs
  2009-07-20 17:09         ` Matthias Urlichs
  1 sibling, 0 replies; 97+ messages in thread
From: Matthias Urlichs @ 2009-07-20 17:09 UTC (permalink / raw)
  To: Dave Jones, Greg KH, linux-kernel, devel, virtualization,
	Hank Janssen, Haiyang Zhang, Sam Ramji, shemminger

Hi,

Dave Jones:
> Given the numerous cleanup patches that already exist, is there any reason
> to not just post the cleaned up drivers ?  It would certainly be more
> reviewable than the current pile.
> 
Feel free to apply / combinediff these patches before reviewing. :-P

Personally, I don't want to ever see another patch where substantial
changes (for some nontrivial value of "substantial") are intermixed
with distracting s/\<BOOLEAN\>/bool/g cleanups.

-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de
v4sw7$Yhw6+8ln7ma7u7L!wl7DUi2e6t3TMWb8HAGen6g3a4s6Mr1p-3/-6 hackerkey.com
 - -
You can never do merely one thing.
					-- Garrett Hardin

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 17:09         ` Matthias Urlichs
  0 siblings, 0 replies; 97+ messages in thread
From: Matthias Urlichs @ 2009-07-20 17:09 UTC (permalink / raw)
  To: Dave Jones, Greg KH, linux-kernel, devel, virtualization, Hank Janssen

Hi,

Dave Jones:
> Given the numerous cleanup patches that already exist, is there any reason
> to not just post the cleaned up drivers ?  It would certainly be more
> reviewable than the current pile.
> 
Feel free to apply / combinediff these patches before reviewing. :-P

Personally, I don't want to ever see another patch where substantial
changes (for some nontrivial value of "substantial") are intermixed
with distracting s/\<BOOLEAN\>/bool/g cleanups.

-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de
v4sw7$Yhw6+8ln7ma7u7L!wl7DUi2e6t3TMWb8HAGen6g3a4s6Mr1p-3/-6 hackerkey.com
 - -
You can never do merely one thing.
					-- Garrett Hardin

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 17:09         ` Matthias Urlichs
  (?)
@ 2009-07-20 17:15         ` Dave Jones
  2009-07-20 17:36             ` Greg KH
  -1 siblings, 1 reply; 97+ messages in thread
From: Dave Jones @ 2009-07-20 17:15 UTC (permalink / raw)
  To: Matthias Urlichs
  Cc: Greg KH, linux-kernel, devel, virtualization, Hank Janssen,
	Haiyang Zhang, Sam Ramji, shemminger

On Mon, Jul 20, 2009 at 07:09:11PM +0200, Matthias Urlichs wrote:
 > Hi,
 > 
 > Dave Jones:
 > > Given the numerous cleanup patches that already exist, is there any reason
 > > to not just post the cleaned up drivers ?  It would certainly be more
 > > reviewable than the current pile.
 > > 
 > Feel free to apply / combinediff these patches before reviewing. :-P
 > 
 > Personally, I don't want to ever see another patch where substantial
 > changes (for some nontrivial value of "substantial") are intermixed
 > with distracting s/\<BOOLEAN\>/bool/g cleanups.

'Substantial changes' doesn't matter when it's an initial submission.
By its nature, it's a substantial change.

	Dave

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 17:03         ` Greg KH
  (?)
@ 2009-07-20 17:22         ` Dave Jones
  -1 siblings, 0 replies; 97+ messages in thread
From: Dave Jones @ 2009-07-20 17:22 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-kernel, devel, virtualization, Hank Janssen, Haiyang Zhang,
	Sam Ramji, shemminger

On Mon, Jul 20, 2009 at 10:03:45AM -0700, Greg KH wrote:
 > The code still needs lots of cleanup, and review, as is evident by the
 > TODO file.  It looks like the patches did get sent to the driver-devel
 > and virtualization lists, so you can see them there if you want to.
 > 
 > But if you want, I can post the 4 individual drivers as of right now,
 > what they will show up in the linux-next tree tomorrow if you want me
 > to.

I already patched a copy of all 54 patches while I was waiting.
(For those playing along at home: http://codemonkey.org.uk/junk/hv.diff)

	Dave


^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 17:15         ` Dave Jones
@ 2009-07-20 17:36             ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 17:36 UTC (permalink / raw)
  To: Dave Jones, Matthias Urlichs, linux-kernel, devel,
	virtualization, Hank Janssen, Haiyang Zhang, Sam Ramji,
	shemminger

On Mon, Jul 20, 2009 at 01:15:23PM -0400, Dave Jones wrote:
> On Mon, Jul 20, 2009 at 07:09:11PM +0200, Matthias Urlichs wrote:
>  > Hi,
>  > 
>  > Dave Jones:
>  > > Given the numerous cleanup patches that already exist, is there any reason
>  > > to not just post the cleaned up drivers ?  It would certainly be more
>  > > reviewable than the current pile.
>  > > 
>  > Feel free to apply / combinediff these patches before reviewing. :-P
>  > 
>  > Personally, I don't want to ever see another patch where substantial
>  > changes (for some nontrivial value of "substantial") are intermixed
>  > with distracting s/\<BOOLEAN\>/bool/g cleanups.
> 
> 'Substantial changes' doesn't matter when it's an initial submission.
> By its nature, it's a substantial change.

Note, to keep the proper authorship information, for a lot of drivers in
the staging tree, we commit the original driver with the correct Author:
and signed-off-by lines, and then we do cleanups after that to properly
attribute the developers doing that work.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 17:36             ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 17:36 UTC (permalink / raw)
  To: Dave Jones, Matthias Urlichs, linux-kernel, devel,
	virtualization, Hank Janssen

On Mon, Jul 20, 2009 at 01:15:23PM -0400, Dave Jones wrote:
> On Mon, Jul 20, 2009 at 07:09:11PM +0200, Matthias Urlichs wrote:
>  > Hi,
>  > 
>  > Dave Jones:
>  > > Given the numerous cleanup patches that already exist, is there any reason
>  > > to not just post the cleaned up drivers ?  It would certainly be more
>  > > reviewable than the current pile.
>  > > 
>  > Feel free to apply / combinediff these patches before reviewing. :-P
>  > 
>  > Personally, I don't want to ever see another patch where substantial
>  > changes (for some nontrivial value of "substantial") are intermixed
>  > with distracting s/\<BOOLEAN\>/bool/g cleanups.
> 
> 'Substantial changes' doesn't matter when it's an initial submission.
> By its nature, it's a substantial change.

Note, to keep the proper authorship information, for a lot of drivers in
the staging tree, we commit the original driver with the correct Author:
and signed-off-by lines, and then we do cleanups after that to properly
attribute the developers doing that work.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 17:03         ` Greg KH
  (?)
  (?)
@ 2009-07-20 19:37         ` Andi Kleen
  2009-07-20 19:57             ` Greg KH
  -1 siblings, 1 reply; 97+ messages in thread
From: Andi Kleen @ 2009-07-20 19:37 UTC (permalink / raw)
  To: Greg KH; +Cc: devel, virtualization, linux-kernel, Haiyang, Dave Jones

Greg KH <gregkh@suse.de> writes:
>
> It's the "normal" way of cleaning up code.  Start with a known-working
> piece of stuff, and incrementally clean it up. 

I have to agree with David. This is essentially unreviewable
in the original state. It would be good if you could
do all the obvious cleanups first and then post a consolidated
series.

Most "obvious" cleanups should not change the binary, so
you can easily check they are correct by comparing the assembler
code.

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 19:37         ` Andi Kleen
@ 2009-07-20 19:57             ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 19:57 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Dave Jones, linux-kernel, devel, virtualization, Hank Janssen

On Mon, Jul 20, 2009 at 09:37:12PM +0200, Andi Kleen wrote:
> Greg KH <gregkh@suse.de> writes:
> >
> > It's the "normal" way of cleaning up code.  Start with a known-working
> > piece of stuff, and incrementally clean it up. 
> 
> I have to agree with David. This is essentially unreviewable
> in the original state. It would be good if you could
> do all the obvious cleanups first and then post a consolidated
> series.
> 
> Most "obvious" cleanups should not change the binary, so
> you can easily check they are correct by comparing the assembler
> code.

Unfortunatly, some of these cleanups do change the binary, as they are
removing wrapper functions.

Anyway, I agree, for a "proper" review, I will show the final, cleaned
up version, like normal.  But we aren't there just yet, that is why this
code is going to live in the staging tree for a while.  Give us some
time to get it fixed up.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 19:57             ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 19:57 UTC (permalink / raw)
  To: Andi Kleen; +Cc: devel, Dave Jones, linux-kernel, virtualization

On Mon, Jul 20, 2009 at 09:37:12PM +0200, Andi Kleen wrote:
> Greg KH <gregkh@suse.de> writes:
> >
> > It's the "normal" way of cleaning up code.  Start with a known-working
> > piece of stuff, and incrementally clean it up. 
> 
> I have to agree with David. This is essentially unreviewable
> in the original state. It would be good if you could
> do all the obvious cleanups first and then post a consolidated
> series.
> 
> Most "obvious" cleanups should not change the binary, so
> you can easily check they are correct by comparing the assembler
> code.

Unfortunatly, some of these cleanups do change the binary, as they are
removing wrapper functions.

Anyway, I agree, for a "proper" review, I will show the final, cleaned
up version, like normal.  But we aren't there just yet, that is why this
code is going to live in the staging tree for a while.  Give us some
time to get it fixed up.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 16:00   ` Greg Kroah-Hartman
@ 2009-07-20 21:24     ` Jan Engelhardt
  -1 siblings, 0 replies; 97+ messages in thread
From: Jan Engelhardt @ 2009-07-20 21:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, virtualization, Hank Janssen, Haiyang Zhang,
	Sam Ramji, shemminger


On Monday 2009-07-20 18:00, Greg Kroah-Hartman wrote:
>
>I'm happy to announce, that after many months of discussions, Microsoft
>has released their Hyper-V Linux drivers under the GPLv2.  Following
>this message, will be the patches that add the drivers to the
>drivers/staging/ tree, and a whole bunch of cleanups.
>
>It's taken a long road to get here, and I'd like to thank the following
>people who made this possible:
>  - Steve Hemminger for the initial prodding and extreme patience
>  - Hank Janssen for providing the code and working with me to get it
>    into a workable and semi-mergable state.  His involvement within
>    Microsoft was also invaluable.
>  - Sam Ramji for his push within Microsoft to make this happen in a
>    manner that works with the Linux community.
>  - Novell for sponsoring my work on the Linux Driver project, without
>    which, this would not have even been possible.

(Your title as Maintainer of Crap has been well earned. But crap
should not be maintained, it should be improved.)


I took a random patch to look at
(add-the-hyper-v-virtual-network-driver.patch to be precise). I think
the /hv/ subdirectory name should be expanded a little (to, say,
/hyper-v/); we're not in the Unix days anymore where space is at such
a premium that people even strip the last e off /usr. Our wireless
drivers also don't live in /wl/. And since hv does not seem to be
related to a hypervisor — cf. sunhv.c.


As for the code… I was immediately greeted by the screaming-uppercase
typedef crap jungle that is so redundant[1] yet typical in many
commercial products. One may hope that the evolution of the posted
hyper-v code brings a coding strategy breeze into the house of
Microsoft.

[1] DWORD they could have replaced by uint32_t once it became
available via C99's stdint.h. The LPCSTR crap only makes sense if you
are a lazy typist, but I would not call code doing things like LPCSTR
clean. At least it's one thing - consistent. Consistently hard to
read, though.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 21:24     ` Jan Engelhardt
  0 siblings, 0 replies; 97+ messages in thread
From: Jan Engelhardt @ 2009-07-20 21:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, virtualization, Hank Janssen, Haiyang Zhang,
	Sam Ramji, shemminger


On Monday 2009-07-20 18:00, Greg Kroah-Hartman wrote:
>
>I'm happy to announce, that after many months of discussions, Microsoft
>has released their Hyper-V Linux drivers under the GPLv2.  Following
>this message, will be the patches that add the drivers to the
>drivers/staging/ tree, and a whole bunch of cleanups.
>
>It's taken a long road to get here, and I'd like to thank the following
>people who made this possible:
>  - Steve Hemminger for the initial prodding and extreme patience
>  - Hank Janssen for providing the code and working with me to get it
>    into a workable and semi-mergable state.  His involvement within
>    Microsoft was also invaluable.
>  - Sam Ramji for his push within Microsoft to make this happen in a
>    manner that works with the Linux community.
>  - Novell for sponsoring my work on the Linux Driver project, without
>    which, this would not have even been possible.

(Your title as Maintainer of Crap has been well earned. But crap
should not be maintained, it should be improved.)


I took a random patch to look at
(add-the-hyper-v-virtual-network-driver.patch to be precise). I think
the /hv/ subdirectory name should be expanded a little (to, say,
/hyper-v/); we're not in the Unix days anymore where space is at such
a premium that people even strip the last e off /usr. Our wireless
drivers also don't live in /wl/. And since hv does not seem to be
related to a hypervisor — cf. sunhv.c.


As for the code… I was immediately greeted by the screaming-uppercase
typedef crap jungle that is so redundant[1] yet typical in many
commercial products. One may hope that the evolution of the posted
hyper-v code brings a coding strategy breeze into the house of
Microsoft.

[1] DWORD they could have replaced by uint32_t once it became
available via C99's stdint.h. The LPCSTR crap only makes sense if you
are a lazy typist, but I would not call code doing things like LPCSTR
clean. At least it's one thing - consistent. Consistently hard to
read, though.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 21:24     ` Jan Engelhardt
@ 2009-07-20 21:33       ` Greg KH
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 21:33 UTC (permalink / raw)
  To: Jan Engelhardt
  Cc: Sam Ramji, Haiyang Zhang, linux-kernel, virtualization, devel,
	shemminger

On Mon, Jul 20, 2009 at 11:24:24PM +0200, Jan Engelhardt wrote:
> 
> On Monday 2009-07-20 18:00, Greg Kroah-Hartman wrote:
> >
> >I'm happy to announce, that after many months of discussions, Microsoft
> >has released their Hyper-V Linux drivers under the GPLv2.  Following
> >this message, will be the patches that add the drivers to the
> >drivers/staging/ tree, and a whole bunch of cleanups.
> >
> >It's taken a long road to get here, and I'd like to thank the following
> >people who made this possible:
> >  - Steve Hemminger for the initial prodding and extreme patience
> >  - Hank Janssen for providing the code and working with me to get it
> >    into a workable and semi-mergable state.  His involvement within
> >    Microsoft was also invaluable.
> >  - Sam Ramji for his push within Microsoft to make this happen in a
> >    manner that works with the Linux community.
> >  - Novell for sponsoring my work on the Linux Driver project, without
> >    which, this would not have even been possible.
> 
> (Your title as Maintainer of Crap has been well earned. But crap
> should not be maintained, it should be improved.)

Hey, we've been working on this, if you look at the .31 merge, we got
rid of more code than we added in the staging directory, and I have a
patch to remove another driver queued up to go to Linus before the final
.31 release as well.

So don't think it's just crap coming in and nothing coming out :)

> I took a random patch to look at
> (add-the-hyper-v-virtual-network-driver.patch to be precise). I think
> the /hv/ subdirectory name should be expanded a little (to, say,
> /hyper-v/); we're not in the Unix days anymore where space is at such
> a premium that people even strip the last e off /usr. Our wireless
> drivers also don't live in /wl/. And since hv does not seem to be
> related to a hypervisor — cf. sunhv.c.

Sure, names are just names, I don't really care about this, I just
picked 'hv' as it was easy to type...

> As for the code… I was immediately greeted by the screaming-uppercase
> typedef crap jungle that is so redundant[1] yet typical in many
> commercial products. One may hope that the evolution of the posted
> hyper-v code brings a coding strategy breeze into the house of
> Microsoft.
> 
> [1] DWORD they could have replaced by uint32_t once it became
> available via C99's stdint.h. The LPCSTR crap only makes sense if you
> are a lazy typist, but I would not call code doing things like LPCSTR
> clean. At least it's one thing - consistent. Consistently hard to
> read, though.

Look at the further patches in the series, I get rid of that typedef.

And yes, there's lots left to do, see the TODO file for details if you
are interested in helping out.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-20 21:33       ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-20 21:33 UTC (permalink / raw)
  To: Jan Engelhardt
  Cc: Sam Ramji, Haiyang Zhang, linux-kernel, virtualization, devel,
	shemminger

On Mon, Jul 20, 2009 at 11:24:24PM +0200, Jan Engelhardt wrote:
> 
> On Monday 2009-07-20 18:00, Greg Kroah-Hartman wrote:
> >
> >I'm happy to announce, that after many months of discussions, Microsoft
> >has released their Hyper-V Linux drivers under the GPLv2.  Following
> >this message, will be the patches that add the drivers to the
> >drivers/staging/ tree, and a whole bunch of cleanups.
> >
> >It's taken a long road to get here, and I'd like to thank the following
> >people who made this possible:
> >  - Steve Hemminger for the initial prodding and extreme patience
> >  - Hank Janssen for providing the code and working with me to get it
> >    into a workable and semi-mergable state.  His involvement within
> >    Microsoft was also invaluable.
> >  - Sam Ramji for his push within Microsoft to make this happen in a
> >    manner that works with the Linux community.
> >  - Novell for sponsoring my work on the Linux Driver project, without
> >    which, this would not have even been possible.
> 
> (Your title as Maintainer of Crap has been well earned. But crap
> should not be maintained, it should be improved.)

Hey, we've been working on this, if you look at the .31 merge, we got
rid of more code than we added in the staging directory, and I have a
patch to remove another driver queued up to go to Linus before the final
.31 release as well.

So don't think it's just crap coming in and nothing coming out :)

> I took a random patch to look at
> (add-the-hyper-v-virtual-network-driver.patch to be precise). I think
> the /hv/ subdirectory name should be expanded a little (to, say,
> /hyper-v/); we're not in the Unix days anymore where space is at such
> a premium that people even strip the last e off /usr. Our wireless
> drivers also don't live in /wl/. And since hv does not seem to be
> related to a hypervisor — cf. sunhv.c.

Sure, names are just names, I don't really care about this, I just
picked 'hv' as it was easy to type...

> As for the code… I was immediately greeted by the screaming-uppercase
> typedef crap jungle that is so redundant[1] yet typical in many
> commercial products. One may hope that the evolution of the posted
> hyper-v code brings a coding strategy breeze into the house of
> Microsoft.
> 
> [1] DWORD they could have replaced by uint32_t once it became
> available via C99's stdint.h. The LPCSTR crap only makes sense if you
> are a lazy typist, but I would not call code doing things like LPCSTR
> clean. At least it's one thing - consistent. Consistently hard to
> read, though.

Look at the further patches in the series, I get rid of that typedef.

And yes, there's lots left to do, see the TODO file for details if you
are interested in helping out.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 47/54] Staging: hv: make gVmbusConnection.ChannelLock a real spinlock
  2009-07-17 18:09   ` [patch 47/54] Staging: hv: make gVmbusConnection.ChannelLock " Greg Kroah-Hartman
@ 2009-07-20 23:39     ` Arnd Bergmann
  2009-07-21  2:11       ` Greg KH
  0 siblings, 1 reply; 97+ messages in thread
From: Arnd Bergmann @ 2009-07-20 23:39 UTC (permalink / raw)
  To: virtualization
  Cc: Greg Kroah-Hartman, linux-kernel, devel, virtualization,
	Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> I don't think we really want to be doing a irqsave for this code, but I
> left it alone to preserve the original codepath.  It should be reviewed
> later.

This patch does not preserve the original code path if any of the
callers has a different irq state from the others. When flags is
shared, releasing the lock actually sets the irq state to whatever
another thread was using when failing to acquire the lock while
it was held.

The patch of course looks good, but the comment is misleading.

	Arnd <><

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines
  2009-07-17 18:09   ` [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines Greg Kroah-Hartman
@ 2009-07-20 23:46     ` Arnd Bergmann
  2009-07-24 21:32       ` Jörn Engel
  0 siblings, 1 reply; 97+ messages in thread
From: Arnd Bergmann @ 2009-07-20 23:46 UTC (permalink / raw)
  To: virtualization
  Cc: Greg Kroah-Hartman, linux-kernel, devel, virtualization,
	Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> @@ -43,7 +43,7 @@ typedef struct _RING_BUFFER {
>         // volatile u32 InterruptMask;
>         // Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
>      u8         Buffer[0];
> -} STRUCT_PACKED RING_BUFFER;
> +} __attribute__((packed)) RING_BUFFER;
>  

The data structure is actually packed already, the attribute does not make it better
and could be removed. We also have __packed as a shortcut for __attribute__((packed)).

	Arnd <><

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 27/54] Staging: hv: remove ULONG and LONG typedefs
  2009-07-17 18:09   ` [patch 27/54] Staging: hv: remove ULONG and LONG typedefs Greg Kroah-Hartman
@ 2009-07-21  0:00     ` Arnd Bergmann
  2009-07-21  0:44         ` Hank Janssen
                         ` (2 more replies)
  0 siblings, 3 replies; 97+ messages in thread
From: Arnd Bergmann @ 2009-07-21  0:00 UTC (permalink / raw)
  To: virtualization
  Cc: Greg Kroah-Hartman, linux-kernel, devel, virtualization, Greg KH,
	Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> From: Greg Kroah-Hartman <gregkh@suse.de>
> 
> The ULONG and LONG typedefs are now removed from the Hyper-V driver
> code
> 

This conversion is not equivalent:

>  //
> -// unsigned types
> -//
> -typedef unsigned int		ULONG;
> -
> -//
> -// signed types
> -//
> -typedef int					LONG;

- // redefine the world, because we can
- extern char *i;
- void abs(unsigned u);
- #define FALSE (2)

;-)

> --- a/drivers/staging/hv/include/StorVscApi.h
> +++ b/drivers/staging/hv/include/StorVscApi.h
> @@ -117,7 +117,7 @@ typedef struct _STORVSC_DRIVER_OBJECT {
>  } STORVSC_DRIVER_OBJECT;
>  
>  typedef struct _STORVSC_DEVICE_INFO {
> -	ULONG	PortNumber;
> +	unsigned long	PortNumber;
>      unsigned char	PathId;
>      unsigned char	TargetId;
>  } STORVSC_DEVICE_INFO;

If this is an API (as the header file name suggests), you just changed it.
Same for the other hunks in this patch.

	Arnd <><

^ permalink raw reply	[flat|nested] 97+ messages in thread

* RE: [patch 27/54] Staging: hv: remove ULONG and LONG typedefs
  2009-07-21  0:00     ` Arnd Bergmann
@ 2009-07-21  0:44         ` Hank Janssen
  2009-07-21  2:38       ` Greg KH
  2009-07-21  8:26       ` Bernd Petrovitsch
  2 siblings, 0 replies; 97+ messages in thread
From: Hank Janssen @ 2009-07-21  0:44 UTC (permalink / raw)
  To: Arnd Bergmann, virtualization
  Cc: Greg Kroah-Hartman, linux-kernel, devel, virtualization, Greg KH,
	Sam Ramji, Haiyang Zhang, shemminger



Arnd,

Thanks for this and the other mails reviewing the code.

My TODO list keeps on getting bigger :). I will check into all of these and correct them.

Keep them coming!

Thanks!

Hank.


-----Original Message-----
From: Arnd Bergmann [mailto:arnd@arndb.de]
Sent: Monday, July 20, 2009 5:00 PM
To: virtualization@lists.linux-foundation.org
Cc: Greg Kroah-Hartman; linux-kernel@vger.kernel.org; devel@driverdev.osuosl.org; virtualization@lists.osdl.org; Greg KH; Sam Ramji; Haiyang Zhang; Hank Janssen; shemminger@linux-foundation.org
Subject: Re: [patch 27/54] Staging: hv: remove ULONG and LONG typedefs

On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> From: Greg Kroah-Hartman <gregkh@suse.de>
>
> The ULONG and LONG typedefs are now removed from the Hyper-V driver
> code
>

This conversion is not equivalent:

>  //
> -// unsigned types
> -//
> -typedef unsigned int         ULONG;
> -
> -//
> -// signed types
> -//
> -typedef int                                  LONG;

- // redefine the world, because we can
- extern char *i;
- void abs(unsigned u);
- #define FALSE (2)

;-)

> --- a/drivers/staging/hv/include/StorVscApi.h
> +++ b/drivers/staging/hv/include/StorVscApi.h
> @@ -117,7 +117,7 @@ typedef struct _STORVSC_DRIVER_OBJECT {
>  } STORVSC_DRIVER_OBJECT;
>
>  typedef struct _STORVSC_DEVICE_INFO {
> -     ULONG   PortNumber;
> +     unsigned long   PortNumber;
>      unsigned char    PathId;
>      unsigned char    TargetId;
>  } STORVSC_DEVICE_INFO;

If this is an API (as the header file name suggests), you just changed it.
Same for the other hunks in this patch.

        Arnd <><


^ permalink raw reply	[flat|nested] 97+ messages in thread

* RE: [patch 27/54] Staging: hv: remove ULONG and LONG typedefs
@ 2009-07-21  0:44         ` Hank Janssen
  0 siblings, 0 replies; 97+ messages in thread
From: Hank Janssen @ 2009-07-21  0:44 UTC (permalink / raw)
  To: Arnd Bergmann, virtualization
  Cc: devel, Greg KH, Haiyang Zhang, Greg Kroah-Hartman, linux-kernel,
	virtualization, Sam Ramji, shemminger



Arnd,

Thanks for this and the other mails reviewing the code.

My TODO list keeps on getting bigger :). I will check into all of these and correct them.

Keep them coming!

Thanks!

Hank.


-----Original Message-----
From: Arnd Bergmann [mailto:arnd@arndb.de]
Sent: Monday, July 20, 2009 5:00 PM
To: virtualization@lists.linux-foundation.org
Cc: Greg Kroah-Hartman; linux-kernel@vger.kernel.org; devel@driverdev.osuosl.org; virtualization@lists.osdl.org; Greg KH; Sam Ramji; Haiyang Zhang; Hank Janssen; shemminger@linux-foundation.org
Subject: Re: [patch 27/54] Staging: hv: remove ULONG and LONG typedefs

On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> From: Greg Kroah-Hartman <gregkh@suse.de>
>
> The ULONG and LONG typedefs are now removed from the Hyper-V driver
> code
>

This conversion is not equivalent:

>  //
> -// unsigned types
> -//
> -typedef unsigned int         ULONG;
> -
> -//
> -// signed types
> -//
> -typedef int                                  LONG;

- // redefine the world, because we can
- extern char *i;
- void abs(unsigned u);
- #define FALSE (2)

;-)

> --- a/drivers/staging/hv/include/StorVscApi.h
> +++ b/drivers/staging/hv/include/StorVscApi.h
> @@ -117,7 +117,7 @@ typedef struct _STORVSC_DRIVER_OBJECT {
>  } STORVSC_DRIVER_OBJECT;
>
>  typedef struct _STORVSC_DEVICE_INFO {
> -     ULONG   PortNumber;
> +     unsigned long   PortNumber;
>      unsigned char    PathId;
>      unsigned char    TargetId;
>  } STORVSC_DEVICE_INFO;

If this is an API (as the header file name suggests), you just changed it.
Same for the other hunks in this patch.

        Arnd <><

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 47/54] Staging: hv: make gVmbusConnection.ChannelLock a real spinlock
  2009-07-20 23:39     ` Arnd Bergmann
@ 2009-07-21  2:11       ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-21  2:11 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: virtualization, linux-kernel, devel, virtualization, Sam Ramji,
	Haiyang Zhang, Hank Janssen, shemminger

On Tue, Jul 21, 2009 at 01:39:19AM +0200, Arnd Bergmann wrote:
> On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> > I don't think we really want to be doing a irqsave for this code, but I
> > left it alone to preserve the original codepath.  It should be reviewed
> > later.
> 
> This patch does not preserve the original code path if any of the
> callers has a different irq state from the others. When flags is
> shared, releasing the lock actually sets the irq state to whatever
> another thread was using when failing to acquire the lock while
> it was held.
> 
> The patch of course looks good, but the comment is misleading.

Good point, sorry for the misleading comment.

I'll let Hank work out the details as to if the irqsave mode is needed
or not :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 27/54] Staging: hv: remove ULONG and LONG typedefs
  2009-07-21  0:00     ` Arnd Bergmann
  2009-07-21  0:44         ` Hank Janssen
@ 2009-07-21  2:38       ` Greg KH
  2009-07-21  2:45         ` Greg KH
  2009-07-21  8:26       ` Bernd Petrovitsch
  2 siblings, 1 reply; 97+ messages in thread
From: Greg KH @ 2009-07-21  2:38 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: virtualization, linux-kernel, devel, virtualization, Greg KH,
	Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

On Tue, Jul 21, 2009 at 02:00:16AM +0200, Arnd Bergmann wrote:
> On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> > From: Greg Kroah-Hartman <gregkh@suse.de>
> > 
> > The ULONG and LONG typedefs are now removed from the Hyper-V driver
> > code
> > 
> 
> This conversion is not equivalent:
> 
> >  //
> > -// unsigned types
> > -//
> > -typedef unsigned int		ULONG;
> > -
> > -//
> > -// signed types
> > -//
> > -typedef int					LONG;
> 
> - // redefine the world, because we can
> - extern char *i;
> - void abs(unsigned u);
> - #define FALSE (2)
> 
> ;-)
> 
> > --- a/drivers/staging/hv/include/StorVscApi.h
> > +++ b/drivers/staging/hv/include/StorVscApi.h
> > @@ -117,7 +117,7 @@ typedef struct _STORVSC_DRIVER_OBJECT {
> >  } STORVSC_DRIVER_OBJECT;
> >  
> >  typedef struct _STORVSC_DEVICE_INFO {
> > -	ULONG	PortNumber;
> > +	unsigned long	PortNumber;
> >      unsigned char	PathId;
> >      unsigned char	TargetId;
> >  } STORVSC_DEVICE_INFO;
> 
> If this is an API (as the header file name suggests), you just changed it.
> Same for the other hunks in this patch.

Ah crap, you're right, that's all wrong, nice catch.

I'll go redo it to be "unsigned int", but for some reason, the code
still seems to work properly :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 27/54] Staging: hv: remove ULONG and LONG typedefs
  2009-07-21  2:38       ` Greg KH
@ 2009-07-21  2:45         ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-21  2:45 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: virtualization, linux-kernel, devel, virtualization, Greg KH,
	Sam Ramji, Haiyang Zhang, Hank Janssen, shemminger

On Mon, Jul 20, 2009 at 07:38:23PM -0700, Greg KH wrote:
> On Tue, Jul 21, 2009 at 02:00:16AM +0200, Arnd Bergmann wrote:
> > On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> > > From: Greg Kroah-Hartman <gregkh@suse.de>
> > > 
> > > The ULONG and LONG typedefs are now removed from the Hyper-V driver
> > > code
> > > 
> > 
> > This conversion is not equivalent:
> > 
> > >  //
> > > -// unsigned types
> > > -//
> > > -typedef unsigned int		ULONG;
> > > -
> > > -//
> > > -// signed types
> > > -//
> > > -typedef int					LONG;
> > 
> > - // redefine the world, because we can
> > - extern char *i;
> > - void abs(unsigned u);
> > - #define FALSE (2)
> > 
> > ;-)
> > 
> > > --- a/drivers/staging/hv/include/StorVscApi.h
> > > +++ b/drivers/staging/hv/include/StorVscApi.h
> > > @@ -117,7 +117,7 @@ typedef struct _STORVSC_DRIVER_OBJECT {
> > >  } STORVSC_DRIVER_OBJECT;
> > >  
> > >  typedef struct _STORVSC_DEVICE_INFO {
> > > -	ULONG	PortNumber;
> > > +	unsigned long	PortNumber;
> > >      unsigned char	PathId;
> > >      unsigned char	TargetId;
> > >  } STORVSC_DEVICE_INFO;
> > 
> > If this is an API (as the header file name suggests), you just changed it.
> > Same for the other hunks in this patch.
> 
> Ah crap, you're right, that's all wrong, nice catch.
> 
> I'll go redo it to be "unsigned int", but for some reason, the code
> still seems to work properly :)

Ok, here's the updated version.  Thanks for the review.

Hank, a lot of these should probably be converted to "real" kernel
types, like u32, or u64 if it's really needed.  Especially if they are
crossing the kernel/hypervisor boundry.

thanks,

greg k-h

-------------
From: Greg Kroah-Hartman <gregkh@suse.de>
Subject: Staging: hv: remove ULONG and LONG typedefs

From: Greg Kroah-Hartman <gregkh@suse.de>

The ULONG and LONG typedefs are now removed from the Hyper-V driver
code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/staging/hv/StorVsc.c            |    2 +-
 drivers/staging/hv/include/StorVscApi.h |    2 +-
 drivers/staging/hv/include/osd.h        |   10 ----------
 drivers/staging/hv/include/vstorage.h   |   12 ++++++------
 4 files changed, 8 insertions(+), 18 deletions(-)

--- a/drivers/staging/hv/StorVsc.c
+++ b/drivers/staging/hv/StorVsc.c
@@ -62,7 +62,7 @@ typedef struct _STORVSC_DEVICE{
 
 	//  Each unique Port/Path/Target represents 1 channel ie scsi controller. In reality, the pathid, targetid is always 0
 	// and the port is set by us
-	ULONG						PortNumber;
+	unsigned int						PortNumber;
     unsigned char						PathId;
     unsigned char						TargetId;
 
--- a/drivers/staging/hv/include/StorVscApi.h
+++ b/drivers/staging/hv/include/StorVscApi.h
@@ -117,7 +117,7 @@ typedef struct _STORVSC_DRIVER_OBJECT {
 } STORVSC_DRIVER_OBJECT;
 
 typedef struct _STORVSC_DEVICE_INFO {
-	ULONG	PortNumber;
+	unsigned int	PortNumber;
     unsigned char	PathId;
     unsigned char	TargetId;
 } STORVSC_DEVICE_INFO;
--- a/drivers/staging/hv/include/osd.h
+++ b/drivers/staging/hv/include/osd.h
@@ -95,16 +95,6 @@ typedef struct _DLIST_ENTRY {
 } DLIST_ENTRY;
 
 //
-// unsigned types
-//
-typedef unsigned int		ULONG;
-
-//
-// signed types
-//
-typedef int					LONG;
-
-//
 // Other types
 //
 typedef unsigned long		SIZE_T;
--- a/drivers/staging/hv/include/vstorage.h
+++ b/drivers/staging/hv/include/vstorage.h
@@ -155,7 +155,7 @@ typedef struct
     unsigned char DataIn;
     unsigned char Reserved;
 
-    ULONG DataTransferLength;
+    unsigned int DataTransferLength;
 
     union
     {
@@ -185,11 +185,11 @@ typedef struct
     //
     // Note: port number is only really known on the client side
     //
-    ULONG  PortNumber;
+    unsigned int  PortNumber;
 
-    ULONG  Flags;
+    unsigned int  Flags;
 
-    ULONG  MaxTransferBytes;
+    unsigned int  MaxTransferBytes;
 
     //
     //  This id is unique for each channel and will correspond with
@@ -249,13 +249,13 @@ typedef struct _VSTOR_PACKET
     //  Flags - see below for values
     //
 
-    ULONG     Flags;
+    unsigned int     Flags;
 
     //
     // Status of the request returned from the server side.
     //
 
-    ULONG     Status;
+    unsigned int     Status;
 
     //
     // Data payload area

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 27/54] Staging: hv: remove ULONG and LONG typedefs
  2009-07-21  0:00     ` Arnd Bergmann
  2009-07-21  0:44         ` Hank Janssen
  2009-07-21  2:38       ` Greg KH
@ 2009-07-21  8:26       ` Bernd Petrovitsch
  2 siblings, 0 replies; 97+ messages in thread
From: Bernd Petrovitsch @ 2009-07-21  8:26 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: virtualization, devel, Haiyang Zhang, Greg Kroah-Hartman,
	linux-kernel, virtualization, Sam Ramji, shemminger

On Tue, 2009-07-21 at 02:00 +0200, Arnd Bergmann wrote:
> On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> > From: Greg Kroah-Hartman <gregkh@suse.de>
> > 
> > The ULONG and LONG typedefs are now removed from the Hyper-V driver
> > code
> 
> This conversion is not equivalent:
[...]
> - // redefine the world, because we can
[...]
> - #define FALSE (2)
That has been done already by the SNMP folks - see
http://www.faqs.org/rfcs/rfc1903.html under "TruthValue".
S,CNR and for off-topic ...

> ;-)
;-) either ....

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services



^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 16:00   ` Greg Kroah-Hartman
@ 2009-07-21 11:06     ` Balbir Singh
  -1 siblings, 0 replies; 97+ messages in thread
From: Balbir Singh @ 2009-07-21 11:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, virtualization, Hank Janssen, Haiyang Zhang,
	Sam Ramji, shemminger

* Greg Kroah-Hartman <gregkh@suse.de> [2009-07-20 09:00:25]:

> 
> Hi all,
> 
> I'm happy to announce, that after many months of discussions, Microsoft
> has released their Hyper-V Linux drivers under the GPLv2.  Following
> this message, will be the patches that add the drivers to the
> drivers/staging/ tree, and a whole bunch of cleanups.
> 
> It's taken a long road to get here, and I'd like to thank the following
> people who made this possible:
>   - Steve Hemminger for the initial prodding and extreme patience
>   - Hank Janssen for providing the code and working with me to get it
>     into a workable and semi-mergable state.  His involvement within
>     Microsoft was also invaluable.
>   - Sam Ramji for his push within Microsoft to make this happen in a
>     manner that works with the Linux community.
>   - Novell for sponsoring my work on the Linux Driver project, without
>     which, this would not have even been possible.
> And there are many others both within Novell and Microsoft, who I do not
> want to slight by not naming, but the list would be too long to go into.
> 
> These drivers are to enable Linux to work better when running as a guest
> on top of the Hyper-V system.  There is still a lot of work to do in
> getting this into "proper" mergable state, and moving it out of the
> staging directory, but Hank and I will be undertaking this task.  See
> the TODO file in the drivers/staging/hv/ directory if anyone wishes to
> help out with this task.
>

What is the long term strategy to keep the sources in sync? Is there
one? Do you expect to get updates for these sources? 

-- 
	Balbir

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-21 11:06     ` Balbir Singh
  0 siblings, 0 replies; 97+ messages in thread
From: Balbir Singh @ 2009-07-21 11:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, virtualization, Hank Janssen, Haiyang Zhang,
	Sam Ramji, shemminger

* Greg Kroah-Hartman <gregkh@suse.de> [2009-07-20 09:00:25]:

> 
> Hi all,
> 
> I'm happy to announce, that after many months of discussions, Microsoft
> has released their Hyper-V Linux drivers under the GPLv2.  Following
> this message, will be the patches that add the drivers to the
> drivers/staging/ tree, and a whole bunch of cleanups.
> 
> It's taken a long road to get here, and I'd like to thank the following
> people who made this possible:
>   - Steve Hemminger for the initial prodding and extreme patience
>   - Hank Janssen for providing the code and working with me to get it
>     into a workable and semi-mergable state.  His involvement within
>     Microsoft was also invaluable.
>   - Sam Ramji for his push within Microsoft to make this happen in a
>     manner that works with the Linux community.
>   - Novell for sponsoring my work on the Linux Driver project, without
>     which, this would not have even been possible.
> And there are many others both within Novell and Microsoft, who I do not
> want to slight by not naming, but the list would be too long to go into.
> 
> These drivers are to enable Linux to work better when running as a guest
> on top of the Hyper-V system.  There is still a lot of work to do in
> getting this into "proper" mergable state, and moving it out of the
> staging directory, but Hank and I will be undertaking this task.  See
> the TODO file in the drivers/staging/hv/ directory if anyone wishes to
> help out with this task.
>

What is the long term strategy to keep the sources in sync? Is there
one? Do you expect to get updates for these sources? 

-- 
	Balbir

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-20 19:57             ` Greg KH
  (?)
@ 2009-07-21 12:07             ` Arnd Bergmann
  2009-07-21 13:38               ` Belisko Marek
  2009-07-21 16:51               ` Greg KH
  -1 siblings, 2 replies; 97+ messages in thread
From: Arnd Bergmann @ 2009-07-21 12:07 UTC (permalink / raw)
  To: virtualization
  Cc: Greg KH, Andi Kleen, devel, Dave Jones, linux-kernel, virtualization

On Monday 20 July 2009, Greg KH wrote:
> Anyway, I agree, for a "proper" review, I will show the final, cleaned
> up version, like normal.  But we aren't there just yet, that is why this
> code is going to live in the staging tree for a while.  Give us some
> time to get it fixed up.

I would find it helpful to have them in a git tree (or a branch) that
I can pull, so I can look at both the original code and the cleaned up
state.

Any reason why the patches are not yet in your staging.git?

	Arnd <><

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-21 12:07             ` Arnd Bergmann
@ 2009-07-21 13:38               ` Belisko Marek
  2009-07-21 16:51               ` Greg KH
  1 sibling, 0 replies; 97+ messages in thread
From: Belisko Marek @ 2009-07-21 13:38 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: virtualization, devel, Greg KH, linux-kernel, virtualization,
	Andi Kleen, Dave Jones

On Tue, Jul 21, 2009 at 2:07 PM, Arnd Bergmann<arnd@arndb.de> wrote:
> On Monday 20 July 2009, Greg KH wrote:
>> Anyway, I agree, for a "proper" review, I will show the final, cleaned
>> up version, like normal.  But we aren't there just yet, that is why this
>> code is going to live in the staging tree for a while.  Give us some
>> time to get it fixed up.
>
> I would find it helpful to have them in a git tree (or a branch) that
> I can pull, so I can look at both the original code and the cleaned up
> state.
You can find sources in linux-next tree in /drivers/staging/hv directory.
(git://git.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git)
>
> Any reason why the patches are not yet in your staging.git?
>
>        Arnd <><
> _______________________________________________
> devel mailing list
> devel@linuxdriverproject.org
> http://driverdev.linuxdriverproject.org/mailman/listinfo/devel
>

Marek

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-21 12:07             ` Arnd Bergmann
  2009-07-21 13:38               ` Belisko Marek
@ 2009-07-21 16:51               ` Greg KH
  1 sibling, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-21 16:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: virtualization, devel, linux-kernel, virtualization, Andi Kleen,
	Dave Jones

On Tue, Jul 21, 2009 at 02:07:40PM +0200, Arnd Bergmann wrote:
> On Monday 20 July 2009, Greg KH wrote:
> > Anyway, I agree, for a "proper" review, I will show the final, cleaned
> > up version, like normal.  But we aren't there just yet, that is why this
> > code is going to live in the staging tree for a while.  Give us some
> > time to get it fixed up.
> 
> I would find it helpful to have them in a git tree (or a branch) that
> I can pull, so I can look at both the original code and the cleaned up
> state.
> 
> Any reason why the patches are not yet in your staging.git?

staging.git is for sending patches to Linus only.  Look in the
MAINTAINERS file for a location of my tree of patches for staging.

If you like git, I'd recommend just using the linux-next tree, as that
always has the latest staging patches in it.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-21 11:06     ` Balbir Singh
@ 2009-07-21 16:51       ` Greg KH
  -1 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-21 16:51 UTC (permalink / raw)
  To: Balbir Singh
  Cc: Sam Ramji, Haiyang Zhang, linux-kernel, virtualization, devel,
	shemminger

On Tue, Jul 21, 2009 at 04:36:07PM +0530, Balbir Singh wrote:
> * Greg Kroah-Hartman <gregkh@suse.de> [2009-07-20 09:00:25]:
> 
> > 
> > Hi all,
> > 
> > I'm happy to announce, that after many months of discussions, Microsoft
> > has released their Hyper-V Linux drivers under the GPLv2.  Following
> > this message, will be the patches that add the drivers to the
> > drivers/staging/ tree, and a whole bunch of cleanups.
> > 
> > It's taken a long road to get here, and I'd like to thank the following
> > people who made this possible:
> >   - Steve Hemminger for the initial prodding and extreme patience
> >   - Hank Janssen for providing the code and working with me to get it
> >     into a workable and semi-mergable state.  His involvement within
> >     Microsoft was also invaluable.
> >   - Sam Ramji for his push within Microsoft to make this happen in a
> >     manner that works with the Linux community.
> >   - Novell for sponsoring my work on the Linux Driver project, without
> >     which, this would not have even been possible.
> > And there are many others both within Novell and Microsoft, who I do not
> > want to slight by not naming, but the list would be too long to go into.
> > 
> > These drivers are to enable Linux to work better when running as a guest
> > on top of the Hyper-V system.  There is still a lot of work to do in
> > getting this into "proper" mergable state, and moving it out of the
> > staging directory, but Hank and I will be undertaking this task.  See
> > the TODO file in the drivers/staging/hv/ directory if anyone wishes to
> > help out with this task.
> >
> 
> What is the long term strategy to keep the sources in sync? Is there
> one? Do you expect to get updates for these sources? 

The in-kernel version will be the only source for the drivers in the
long run.  Eventually they will take the drivers off their web site when
the distros pick them up in their new releases.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-21 16:51       ` Greg KH
  0 siblings, 0 replies; 97+ messages in thread
From: Greg KH @ 2009-07-21 16:51 UTC (permalink / raw)
  To: Balbir Singh
  Cc: Sam Ramji, Haiyang Zhang, linux-kernel, virtualization, devel,
	shemminger

On Tue, Jul 21, 2009 at 04:36:07PM +0530, Balbir Singh wrote:
> * Greg Kroah-Hartman <gregkh@suse.de> [2009-07-20 09:00:25]:
> 
> > 
> > Hi all,
> > 
> > I'm happy to announce, that after many months of discussions, Microsoft
> > has released their Hyper-V Linux drivers under the GPLv2.  Following
> > this message, will be the patches that add the drivers to the
> > drivers/staging/ tree, and a whole bunch of cleanups.
> > 
> > It's taken a long road to get here, and I'd like to thank the following
> > people who made this possible:
> >   - Steve Hemminger for the initial prodding and extreme patience
> >   - Hank Janssen for providing the code and working with me to get it
> >     into a workable and semi-mergable state.  His involvement within
> >     Microsoft was also invaluable.
> >   - Sam Ramji for his push within Microsoft to make this happen in a
> >     manner that works with the Linux community.
> >   - Novell for sponsoring my work on the Linux Driver project, without
> >     which, this would not have even been possible.
> > And there are many others both within Novell and Microsoft, who I do not
> > want to slight by not naming, but the list would be too long to go into.
> > 
> > These drivers are to enable Linux to work better when running as a guest
> > on top of the Hyper-V system.  There is still a lot of work to do in
> > getting this into "proper" mergable state, and moving it out of the
> > staging directory, but Hank and I will be undertaking this task.  See
> > the TODO file in the drivers/staging/hv/ directory if anyone wishes to
> > help out with this task.
> >
> 
> What is the long term strategy to keep the sources in sync? Is there
> one? Do you expect to get updates for these sources? 

The in-kernel version will be the only source for the drivers in the
long run.  Eventually they will take the drivers off their web site when
the distros pick them up in their new releases.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 97+ messages in thread

* RE: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-21 11:06     ` Balbir Singh
@ 2009-07-21 18:00       ` Hank Janssen
  -1 siblings, 0 replies; 97+ messages in thread
From: Hank Janssen @ 2009-07-21 18:00 UTC (permalink / raw)
  To: balbir, Greg Kroah-Hartman
  Cc: linux-kernel, devel@linuxdriverproject.org, virtualization,
	Haiyang Zhang, shemminger



>What is the long term strategy to keep the sources in sync? Is there
>one? Do you expect to get updates for these sources?
>
>        Balbir


Balbir,

I think you are asking me if we plan to continue contributing?

It is my plan to use the kernel as my primary development area, and I will
Continue to provide Greg with updates. First step is to clean up the code
To make sure if fulfills all Kernel coding standards and requirements.

Then I will start contributing new functionality.

Thanks,

Hank.


^ permalink raw reply	[flat|nested] 97+ messages in thread

* RE: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-21 18:00       ` Hank Janssen
  0 siblings, 0 replies; 97+ messages in thread
From: Hank Janssen @ 2009-07-21 18:00 UTC (permalink / raw)
  To: balbir, Greg Kroah-Hartman
  Cc: linux-kernel, devel, virtualization, Haiyang Zhang, shemminger



>What is the long term strategy to keep the sources in sync? Is there
>one? Do you expect to get updates for these sources?
>
>        Balbir


Balbir,

I think you are asking me if we plan to continue contributing?

It is my plan to use the kernel as my primary development area, and I will
Continue to provide Greg with updates. First step is to clean up the code
To make sure if fulfills all Kernel coding standards and requirements.

Then I will start contributing new functionality.

Thanks,

Hank.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
  2009-07-21 18:00       ` Hank Janssen
@ 2009-07-21 18:22         ` Balbir Singh
  -1 siblings, 0 replies; 97+ messages in thread
From: Balbir Singh @ 2009-07-21 18:22 UTC (permalink / raw)
  To: Hank Janssen
  Cc: Greg Kroah-Hartman, linux-kernel, devel@linuxdriverproject.org,
	virtualization, Haiyang Zhang, shemminger

* Hank Janssen <hjanssen@microsoft.com> [2009-07-21 18:00:10]:

> 
> 
> >What is the long term strategy to keep the sources in sync? Is there
> >one? Do you expect to get updates for these sources?
> >
> >        Balbir
> 
> 
> Balbir,
> 
> I think you are asking me if we plan to continue contributing?
> 
> It is my plan to use the kernel as my primary development area, and I will
> Continue to provide Greg with updates. First step is to clean up the code
> To make sure if fulfills all Kernel coding standards and requirements.
> 
> Then I will start contributing new functionality.
>

Good to know. Thanks for the clarification! 

-- 
	Balbir

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux
@ 2009-07-21 18:22         ` Balbir Singh
  0 siblings, 0 replies; 97+ messages in thread
From: Balbir Singh @ 2009-07-21 18:22 UTC (permalink / raw)
  To: Hank Janssen
  Cc: devel@linuxdriverproject.org, Haiyang Zhang, Greg Kroah-Hartman,
	linux-kernel, virtualization, shemminger

* Hank Janssen <hjanssen@microsoft.com> [2009-07-21 18:00:10]:

> 
> 
> >What is the long term strategy to keep the sources in sync? Is there
> >one? Do you expect to get updates for these sources?
> >
> >        Balbir
> 
> 
> Balbir,
> 
> I think you are asking me if we plan to continue contributing?
> 
> It is my plan to use the kernel as my primary development area, and I will
> Continue to provide Greg with updates. First step is to clean up the code
> To make sure if fulfills all Kernel coding standards and requirements.
> 
> Then I will start contributing new functionality.
>

Good to know. Thanks for the clarification! 

-- 
	Balbir

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines
  2009-07-20 23:46     ` Arnd Bergmann
@ 2009-07-24 21:32       ` Jörn Engel
  2009-07-24 21:50         ` Stephen Hemminger
  0 siblings, 1 reply; 97+ messages in thread
From: Jörn Engel @ 2009-07-24 21:32 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: virtualization, Greg Kroah-Hartman, linux-kernel, devel,
	virtualization, Sam Ramji, Haiyang Zhang, Hank Janssen,
	shemminger

On Tue, 21 July 2009 01:46:41 +0200, Arnd Bergmann wrote:
> On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> > @@ -43,7 +43,7 @@ typedef struct _RING_BUFFER {
> >         // volatile u32 InterruptMask;
> >         // Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
> >      u8         Buffer[0];
> > -} STRUCT_PACKED RING_BUFFER;
> > +} __attribute__((packed)) RING_BUFFER;
> >  
> 
> The data structure is actually packed already, the attribute does not make it better
> and could be removed. We also have __packed as a shortcut for __attribute__((packed)).

Honestly, I don't know how useful __packed really is.  In a shared
kernel/userspace header, it is only defined for the kernel.

Jörn

-- 
Do not stop an army on its way home.
-- Sun Tzu

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines
  2009-07-24 21:32       ` Jörn Engel
@ 2009-07-24 21:50         ` Stephen Hemminger
  2009-07-24 23:06           ` Jörn Engel
  0 siblings, 1 reply; 97+ messages in thread
From: Stephen Hemminger @ 2009-07-24 21:50 UTC (permalink / raw)
  To: Jörn Engel
  Cc: Arnd Bergmann, virtualization, Greg Kroah-Hartman, linux-kernel,
	devel, virtualization, Sam Ramji, Haiyang Zhang, Hank Janssen

On Fri, 24 Jul 2009 23:32:19 +0200
Jörn Engel <joern@logfs.org> wrote:

> On Tue, 21 July 2009 01:46:41 +0200, Arnd Bergmann wrote:
> > On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> > > @@ -43,7 +43,7 @@ typedef struct _RING_BUFFER {
> > >         // volatile u32 InterruptMask;
> > >         // Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
> > >      u8         Buffer[0];
> > > -} STRUCT_PACKED RING_BUFFER;
> > > +} __attribute__((packed)) RING_BUFFER;
> > >  
> > 
> > The data structure is actually packed already, the attribute does not make it better
> > and could be removed. We also have __packed as a shortcut for __attribute__((packed)).
> 
> Honestly, I don't know how useful __packed really is.  In a shared
> kernel/userspace header, it is only defined for the kernel.
> 

As I remember, gcc generates worse code for packed structures on many architectures
since it may have to do byte fetchs/recombining to avoid unaligned
accesses.

-- 

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines
  2009-07-24 21:50         ` Stephen Hemminger
@ 2009-07-24 23:06           ` Jörn Engel
  0 siblings, 0 replies; 97+ messages in thread
From: Jörn Engel @ 2009-07-24 23:06 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Arnd Bergmann, virtualization, Greg Kroah-Hartman, linux-kernel,
	devel, virtualization, Sam Ramji, Haiyang Zhang, Hank Janssen

On Fri, 24 July 2009 14:50:25 -0700, Stephen Hemminger wrote:
> On Fri, 24 Jul 2009 23:32:19 +0200
> Jörn Engel <joern@logfs.org> wrote:
> 
> > On Tue, 21 July 2009 01:46:41 +0200, Arnd Bergmann wrote:
> > > 
> > > The data structure is actually packed already, the attribute does not make it better
> > > and could be removed. We also have __packed as a shortcut for __attribute__((packed)).
> > 
> > Honestly, I don't know how useful __packed really is.  In a shared
> > kernel/userspace header, it is only defined for the kernel.
> 
> As I remember, gcc generates worse code for packed structures on many architectures
> since it may have to do byte fetchs/recombining to avoid unaligned
> accesses.

I was talking about "__packed" vs. "__attribute__((packed))".  But yes,
avoiding packed structures where possible is a good idea.

Jörn

-- 
"[One] doesn't need to know [...] how to cause a headache in order
to take an aspirin."
-- Scott Culp, Manager of the Microsoft Security Response Center, 2001

^ permalink raw reply	[flat|nested] 97+ messages in thread

end of thread, other threads:[~2009-07-24 23:06 UTC | newest]

Thread overview: 97+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20090717180850.873962925@mini.kroah.org>
2009-07-20 16:00 ` [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux Greg Kroah-Hartman
2009-07-20 16:00   ` Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 01/54] Staging: hv: add the Hyper-V api header files Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 02/54] Staging: hv: add the Hyper-V driver " Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 03/54] Staging: hv: add the Hyper-V virtual bus Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 04/54] Staging: hv: add the Hyper-V virtual block driver Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 05/54] Staging: hv: add the Hyper-V virtual network driver Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 06/54] Staging: hv: add the Hyper-V virtual storage driver Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 07/54] Staging: hv: add a TODO file Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 08/54] Staging: hv: make the Hyper-V virtual bus code build Greg Kroah-Hartman
2009-07-17 18:08   ` [patch 09/54] Staging: hv: use the correct #ifdef for x86-64 Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 10/54] Staging: hv: add the Hyper-V virtual bus to the build Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 11/54] Staging: hv: make the Hyper-V virtual storage driver build Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 12/54] Staging: hv: add the Hyper-V virtual scsi driver to the build Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 13/54] Staging: hv: make the Hyper-V virtual block driver build Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 14/54] Staging: hv: add the Hyper-V virtual block driver to the build Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 15/54] Staging: hv: make the Hyper-V virtual network driver build Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 16/54] Staging: hv: add the Hyper-V virtual network driver to the build Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 17/54] Staging: hv: remove INTERNAL typedef Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 18/54] Staging: hv: remove PVOID typedef Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 19/54] Staging: hv: remove VOID typedef Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 20/54] Staging: hv: remove UINT8 and INT8 typedefs Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 21/54] Staging: hv: remove UINT16 and INT16 typedefs Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 22/54] Staging: hv: remove UINT32 and INT32 typedefs Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 23/54] Staging: hv: remove UINT64 and INT64 and UCHAR typedefs Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 24/54] Staging: hv: remove USHORT typedef Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 25/54] Staging: hv: remove ULONGLONG and LONGLONG typedefs Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 26/54] Staging: hv: remove ULONG_PTR typedef Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 27/54] Staging: hv: remove ULONG and LONG typedefs Greg Kroah-Hartman
2009-07-21  0:00     ` Arnd Bergmann
2009-07-21  0:44       ` Hank Janssen
2009-07-21  0:44         ` Hank Janssen
2009-07-21  2:38       ` Greg KH
2009-07-21  2:45         ` Greg KH
2009-07-21  8:26       ` Bernd Petrovitsch
2009-07-17 18:09   ` [patch 28/54] Staging: hv: remove SIZE_T typedef Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 29/54] Staging: hv: remove DWORD and BYTE typedefs Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 30/54] Staging: hv: remove BOOL and BOOLEAN typedefs Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 31/54] Staging: hv: remove #defines from osd.c Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 32/54] Staging: hv: remove MIN and MAX usages Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 33/54] Staging: hv: remove PAGE_SIZE and PAGE_SHIFT and __builtin functions Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines Greg Kroah-Hartman
2009-07-20 23:46     ` Arnd Bergmann
2009-07-24 21:32       ` Jörn Engel
2009-07-24 21:50         ` Stephen Hemminger
2009-07-24 23:06           ` Jörn Engel
2009-07-17 18:09   ` [patch 35/54] Staging: hv: remove UNUSED_VAR usage Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 36/54] Staging: hv: remove FIELD_OFFSET usage Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 37/54] Staging: hv: remove TRUE, FALSE, and NULL usage Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 38/54] Staging: hv: osd: remove MemAlloc wrapper Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 39/54] Staging: hv: osd: remove MemAllocZeroed wrapper Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 40/54] Staging: hv: osd: remove MemAllocAtomic wrapper Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 41/54] Staging: hv: osd: remove MemFree wrapper Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 42/54] Staging: hv: make Channel->InboundLock a real spinlock Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 43/54] Staging: hv: make RingInfo->RingLock " Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 44/54] Staging: hv: make Device->RequestLock " Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 45/54] Staging: hv: make netDevice->ReceivePacketListLock " Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 46/54] Staging: hv: make gVmbusConnection.ChannelMsgLock " Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 47/54] Staging: hv: make gVmbusConnection.ChannelLock " Greg Kroah-Hartman
2009-07-20 23:39     ` Arnd Bergmann
2009-07-21  2:11       ` Greg KH
2009-07-17 18:09   ` [patch 48/54] Staging: hv: osd: remove spinlock wrapper functions Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 49/54] Staging: hv: osd: remove Sleep wrapper Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 50/54] Staging: hv: osd: remove MemoryFence wrapper Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 51/54] Staging: hv: osd: remove LogMsg wrapper Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 52/54] Staging: hv: osd: remove PrintBytes wrapper Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 53/54] Staging: hv: fix up printk warnings Greg Kroah-Hartman
2009-07-17 18:09   ` [patch 54/54] Staging: hv: osd: remove GetTickCount and GetTimestamp wrappers Greg Kroah-Hartman
2009-07-20 16:28   ` [patch 00/54] [Announce] Microsoft Hyper-V drivers for Linux Greg KH
2009-07-20 16:28     ` Greg KH
2009-07-20 16:59     ` Dave Jones
2009-07-20 17:03       ` Greg KH
2009-07-20 17:03         ` Greg KH
2009-07-20 17:22         ` Dave Jones
2009-07-20 19:37         ` Andi Kleen
2009-07-20 19:57           ` Greg KH
2009-07-20 19:57             ` Greg KH
2009-07-21 12:07             ` Arnd Bergmann
2009-07-21 13:38               ` Belisko Marek
2009-07-21 16:51               ` Greg KH
2009-07-20 17:09       ` Matthias Urlichs
2009-07-20 17:09         ` Matthias Urlichs
2009-07-20 17:15         ` Dave Jones
2009-07-20 17:36           ` Greg KH
2009-07-20 17:36             ` Greg KH
2009-07-20 21:24   ` Jan Engelhardt
2009-07-20 21:24     ` Jan Engelhardt
2009-07-20 21:33     ` Greg KH
2009-07-20 21:33       ` Greg KH
2009-07-21 11:06   ` Balbir Singh
2009-07-21 11:06     ` Balbir Singh
2009-07-21 16:51     ` Greg KH
2009-07-21 16:51       ` Greg KH
2009-07-21 18:00     ` Hank Janssen
2009-07-21 18:00       ` Hank Janssen
2009-07-21 18:22       ` Balbir Singh
2009-07-21 18:22         ` Balbir Singh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.