[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH xenvif 3/4] Add version 9 of XENVIF_VIF_INTERFACE



From: Paul Durrant <pdurrant@xxxxxxxxxx>

This changes XENVIF_VIF_CALLBACK from a varargs function into function taking
a pointer to a new XENVIF_VIF_CALLBACK_PARAMETERS union which is now used to
pass all the arguments specific to the callback type.
To maintain support for version 8 clients a VifCallbackVersion8() function is
added as a shim to unpack the parameters structure and call the client's
varargs callback function.

Signed-off-by: Paul Durrant <pdurrant@xxxxxxxxxx>
---
 include/revision.h      |   3 +-
 include/vif_interface.h | 125 +++++++++++++++++-----
 src/xenvif/vif.c        | 228 ++++++++++++++++++++++++++++------------
 3 files changed, 264 insertions(+), 92 deletions(-)

diff --git a/include/revision.h b/include/revision.h
index 9920b4c7314d..64e6e34ae14a 100644
--- a/include/revision.h
+++ b/include/revision.h
@@ -41,6 +41,7 @@
 //                    REVISION   C   V   ST  SU
 #define DEFINE_REVISION_TABLE                       \
     DEFINE_REVISION(0x09000000,  1,  8,  2,  1),    \
-    DEFINE_REVISION(0x09000001,  2,  8,  2,  1)
+    DEFINE_REVISION(0x09000001,  2,  8,  2,  1),    \
+    DEFINE_REVISION(0x09000002,  2,  9,  2,  1)
 
 #endif  // _REVISION_H
diff --git a/include/vif_interface.h b/include/vif_interface.h
index 0e5129452413..c157c5ca798e 100644
--- a/include/vif_interface.h
+++ b/include/vif_interface.h
@@ -388,6 +388,49 @@ typedef enum _XENVIF_VIF_CALLBACK_TYPE {
     XENVIF_MAC_STATE_CHANGE
 } XENVIF_VIF_CALLBACK_TYPE, *PXENVIF_VIF_CALLBACK_TYPE;
 
+/*! \typedef XENVIF_VIF_CALLBACK_PARAMETERS_V9
+    \brief VIF interface version 9 parameters for provider to subscriber 
callback function
+
+    \b XENVIF_TRANSMITTER_RETURN_PACKET:
+    \param Cookie Cookie supplied to XENVIF_TRANSMITTER_QUEUE_PACKET
+    \param Completion Packet completion information
+
+    \b XENVIF_RECEIVER_QUEUE_PACKET:
+    \param Index The index of the queue on which the packet was received
+    \param Mdl The initial MDL of the packet
+    \param Offset The offset of the packet data in the initial MDL
+    \param Length The total length of the packet
+    \param Flags Packet checksum flags
+    \param MaximumSegmentSize The TCP MSS (used only if 
OffloadOptions.OffloadIpVersion[4|6]LargePacket is set)
+    \param TagControlInformation The VLAN TCI (used only if 
OffloadOptions.OffloadTagManipulation is set)
+    \param Info Header information for the packet
+    \param Hash Hash information for the packet
+    \param More A flag to indicate whether more packets will be queued for the 
same CPU
+    \param Cookie Cookie that should be passed to 
XENVIF_RECEIVER_RETURN_PACKET method
+
+    \b XENVIF_MAC_STATE_CHANGE:
+    No additional arguments
+*/
+union _XENVIF_VIF_CALLBACK_PARAMETERS_V9 {
+    struct {
+        PVOID                                       Cookie;
+        PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO  Completion;
+    } TransmitterReturnPacket;
+    struct {
+        ULONG                           Index;
+        PMDL                            Mdl;
+        ULONG                           Offset;
+        ULONG                           Length;
+        XENVIF_PACKET_CHECKSUM_FLAGS    Flags;
+        USHORT                          MaximumSegmentSize;
+        USHORT                          TagControlInformation;
+        PXENVIF_PACKET_INFO             Info;
+        PXENVIF_PACKET_HASH             Hash;
+        BOOLEAN                         More;
+        PVOID                           Cookie;
+    } ReceiverQueuePacket;
+};
+
 /*! \typedef XENVIF_VIF_ACQUIRE
     \brief Acquire a reference to the VIF interface
 
@@ -408,38 +451,34 @@ typedef VOID
     IN  PINTERFACE  Interface
     );
 
+typedef VOID
+(*XENVIF_VIF_CALLBACK_V8)(
+    IN  PVOID                       Argument OPTIONAL,
+    IN  XENVIF_VIF_CALLBACK_TYPE    Type,
+    ...
+    );
+
+typedef union _XENVIF_VIF_CALLBACK_PARAMETERS_V9 
XENVIF_VIF_CALLBACK_PARAMETERS, *PXENVIF_VIF_CALLBACK_PARAMETERS;
+
 /*! \typedef XENVIF_VIF_CALLBACK
     \brief Provider to subscriber callback function
 
     \param Argument An optional context argument passed to the callback
     \param Type The callback type
-    \param ... Additional paramaters required by \a Type
-
-    \b XENVIF_TRANSMITTER_RETURN_PACKET:
-    \param Cookie Cookie supplied to XENVIF_TRANSMITTER_QUEUE_PACKET
-    \param Completion Packet completion information
-
-    \b XENVIF_RECEIVER_QUEUE_PACKET:
-    \param Index The index of the queue on which the packet was received
-    \param Mdl The initial MDL of the packet
-    \param Offset The offset of the packet data in the initial MDL
-    \param Length The total length of the packet
-    \param Flags Packet checksum flags
-    \param MaximumSegmentSize The TCP MSS (used only if 
OffloadOptions.OffloadIpVersion[4|6]LargePacket is set)
-    \param TagControlInformation The VLAN TCI (used only if 
OffloadOptions.OffloadTagManipulation is set)
-    \param Info Header information for the packet
-    \param Hash Hash information for the packet
-    \param More A flag to indicate whether more packets will be queued for the 
same CPU
-    \param Cookie Cookie that should be passed to 
XENVIF_RECEIVER_RETURN_PACKET method
-
-    \b XENVIF_MAC_STATE_CHANGE:
-    No additional arguments
+    \param Parameters The callback parameters
 */
 typedef VOID
 (*XENVIF_VIF_CALLBACK)(
-    IN  PVOID                       Argument OPTIONAL,
-    IN  XENVIF_VIF_CALLBACK_TYPE    Type,
-    ...
+    IN  PVOID                           Argument OPTIONAL,
+    IN  XENVIF_VIF_CALLBACK_TYPE        Type,
+    IN  PXENVIF_VIF_CALLBACK_PARAMETERS Parameters
+    );
+
+typedef NTSTATUS
+(*XENVIF_VIF_ENABLE_V8)(
+    IN  PINTERFACE              Interface,
+    IN  XENVIF_VIF_CALLBACK_V8  Callback,
+    IN  PVOID                   Argument OPTIONAL
     );
 
 /*! \typedef XENVIF_VIF_ENABLE
@@ -818,6 +857,40 @@ DEFINE_GUID(GUID_XENVIF_VIF_INTERFACE,
     \ingroup interfaces
 */
 struct _XENVIF_VIF_INTERFACE_V8 {
+    INTERFACE                                       Interface;
+    XENVIF_VIF_ACQUIRE                              Acquire;
+    XENVIF_VIF_RELEASE                              Release;
+    XENVIF_VIF_ENABLE_V8                            EnableVersion8;
+    XENVIF_VIF_DISABLE                              Disable;
+    XENVIF_VIF_QUERY_STATISTIC                      QueryStatistic;
+    XENVIF_VIF_QUERY_RING_COUNT                     QueryRingCount;
+    XENVIF_VIF_UPDATE_HASH_MAPPING                  UpdateHashMapping;
+    XENVIF_VIF_RECEIVER_RETURN_PACKET               ReceiverReturnPacket;
+    XENVIF_VIF_RECEIVER_SET_OFFLOAD_OPTIONS         ReceiverSetOffloadOptions;
+    XENVIF_VIF_RECEIVER_SET_BACKFILL_SIZE           ReceiverSetBackfillSize;
+    XENVIF_VIF_RECEIVER_QUERY_RING_SIZE             ReceiverQueryRingSize;
+    XENVIF_VIF_RECEIVER_SET_HASH_ALGORITHM          ReceiverSetHashAlgorithm;
+    XENVIF_VIF_RECEIVER_QUERY_HASH_CAPABILITIES     
ReceiverQueryHashCapabilities;
+    XENVIF_VIF_RECEIVER_UPDATE_HASH_PARAMETERS      
ReceiverUpdateHashParameters;
+    XENVIF_VIF_TRANSMITTER_QUEUE_PACKET             TransmitterQueuePacket;
+    XENVIF_VIF_TRANSMITTER_QUERY_OFFLOAD_OPTIONS    
TransmitterQueryOffloadOptions;
+    XENVIF_VIF_TRANSMITTER_QUERY_LARGE_PACKET_SIZE  
TransmitterQueryLargePacketSize;
+    XENVIF_VIF_TRANSMITTER_QUERY_RING_SIZE          TransmitterQueryRingSize;
+    XENVIF_VIF_MAC_QUERY_STATE                      MacQueryState;
+    XENVIF_VIF_MAC_QUERY_MAXIMUM_FRAME_SIZE         MacQueryMaximumFrameSize;
+    XENVIF_VIF_MAC_QUERY_PERMANENT_ADDRESS          MacQueryPermanentAddress;
+    XENVIF_VIF_MAC_QUERY_CURRENT_ADDRESS            MacQueryCurrentAddress;
+    XENVIF_VIF_MAC_QUERY_MULTICAST_ADDRESSES        MacQueryMulticastAddresses;
+    XENVIF_VIF_MAC_SET_MULTICAST_ADDRESSES          MacSetMulticastAddresses;
+    XENVIF_VIF_MAC_SET_FILTER_LEVEL                 MacSetFilterLevel;
+    XENVIF_VIF_MAC_QUERY_FILTER_LEVEL               MacQueryFilterLevel;
+};
+
+/*! \struct _XENVIF_VIF_INTERFACE_V9
+    \brief VIF interface version 9
+    \ingroup interfaces
+*/
+struct _XENVIF_VIF_INTERFACE_V9 {
     INTERFACE                                       Interface;
     XENVIF_VIF_ACQUIRE                              Acquire;
     XENVIF_VIF_RELEASE                              Release;
@@ -847,7 +920,7 @@ struct _XENVIF_VIF_INTERFACE_V8 {
     XENVIF_VIF_MAC_QUERY_FILTER_LEVEL               MacQueryFilterLevel;
 };
 
-typedef struct _XENVIF_VIF_INTERFACE_V8 XENVIF_VIF_INTERFACE, 
*PXENVIF_VIF_INTERFACE;
+typedef struct _XENVIF_VIF_INTERFACE_V9 XENVIF_VIF_INTERFACE, 
*PXENVIF_VIF_INTERFACE;
 
 /*! \def XENVIF_VIF
     \brief Macro at assist in method invocation
@@ -858,6 +931,6 @@ typedef struct _XENVIF_VIF_INTERFACE_V8 
XENVIF_VIF_INTERFACE, *PXENVIF_VIF_INTER
 #endif  // _WINDLL
 
 #define XENVIF_VIF_INTERFACE_VERSION_MIN    8
-#define XENVIF_VIF_INTERFACE_VERSION_MAX    8
+#define XENVIF_VIF_INTERFACE_VERSION_MAX    9
 
 #endif  // _XENVIF_INTERFACE_H
diff --git a/src/xenvif/vif.c b/src/xenvif/vif.c
index 33aceed5bba8..102f24d12888 100644
--- a/src/xenvif/vif.c
+++ b/src/xenvif/vif.c
@@ -53,6 +53,8 @@ struct _XENVIF_VIF_CONTEXT {
     ULONG                       Version;
     XENVIF_VIF_CALLBACK         Callback;
     PVOID                       Argument;
+    XENVIF_VIF_CALLBACK_V8      CallbackVersion8;
+    PVOID                       ArgumentVersion8;
     PXENVIF_THREAD              MacThread;
     KEVENT                      MacEvent;
     XENBUS_SUSPEND_INTERFACE    SuspendInterface;
@@ -104,10 +106,9 @@ VifMac(
 
         if (ThreadIsAlerted(Self))
             break;
-        
+
         if (Context->Enabled)
-            Context->Callback(Context->Argument,
-                              XENVIF_MAC_STATE_CHANGE);
+            Context->Callback(Context->Argument, XENVIF_MAC_STATE_CHANGE, 
NULL);
 
         KeSetEvent(&Context->MacEvent, IO_NO_INCREMENT, FALSE);
     }
@@ -236,6 +237,93 @@ fail1:
     return status;
 }
 
+static VOID
+VifCallbackVersion8(
+    IN  PVOID                           _Argument OPTIONAL,
+    IN  XENVIF_VIF_CALLBACK_TYPE        Type,
+    IN  PXENVIF_VIF_CALLBACK_PARAMETERS Parameters
+    )
+{
+    PXENVIF_VIF_CONTEXT                 Context = _Argument;
+    XENVIF_VIF_CALLBACK_V8              Callback = Context->CallbackVersion8;
+    PVOID                               Argument = Context->ArgumentVersion8;
+
+    switch (Type) {
+    case XENVIF_TRANSMITTER_RETURN_PACKET: {
+        PVOID                                       Cookie = 
Parameters->TransmitterReturnPacket.Cookie;
+        PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO  Completion = 
Parameters->TransmitterReturnPacket.Completion;
+
+        Callback(Argument,
+                 XENVIF_TRANSMITTER_RETURN_PACKET,
+                 Cookie,
+                 Completion);
+        break;
+    }
+    case XENVIF_RECEIVER_QUEUE_PACKET: {
+        ULONG                           Index = 
Parameters->ReceiverQueuePacket.Index;
+        PMDL                            Mdl = 
Parameters->ReceiverQueuePacket.Mdl;
+        ULONG                           Offset = 
Parameters->ReceiverQueuePacket.Offset;
+        ULONG                           Length=  
Parameters->ReceiverQueuePacket.Length;
+        XENVIF_PACKET_CHECKSUM_FLAGS    Flags = 
Parameters->ReceiverQueuePacket.Flags;
+        USHORT                          MaximumSegmentSize = 
Parameters->ReceiverQueuePacket.MaximumSegmentSize;
+        USHORT                          TagControlInformation = 
Parameters->ReceiverQueuePacket.TagControlInformation;
+        PXENVIF_PACKET_INFO             Info = 
Parameters->ReceiverQueuePacket.Info;
+        PXENVIF_PACKET_HASH             Hash = 
Parameters->ReceiverQueuePacket.Hash;
+        BOOLEAN                         More = 
Parameters->ReceiverQueuePacket.More;
+        PVOID                           Cookie = 
Parameters->ReceiverQueuePacket.Cookie;
+
+        Callback(Argument,
+                 XENVIF_RECEIVER_QUEUE_PACKET,
+                 Index,
+                 Mdl,
+                 Offset,
+                 Length,
+                 Flags,
+                 MaximumSegmentSize,
+                 TagControlInformation,
+                 Info,
+                 Hash,
+                 More,
+                 Cookie);
+        break;
+    }
+    case XENVIF_MAC_STATE_CHANGE:
+        Callback(Argument, XENVIF_MAC_STATE_CHANGE);
+        break;
+
+    default:
+        ASSERT(FALSE);
+        break;
+    }
+}
+
+static NTSTATUS
+VifEnableVersion8(
+    IN  PINTERFACE                  Interface,
+    IN  XENVIF_VIF_CALLBACK_V8      Callback,
+    IN  PVOID                       Argument
+    )
+{
+    PXENVIF_VIF_CONTEXT             Context = Interface->Context;
+    KIRQL                           Irql;
+    NTSTATUS                        status;
+
+    Trace("====>\n");
+
+    AcquireMrswLockExclusive(&Context->Lock, &Irql);
+
+    Context->CallbackVersion8 = Callback;
+    Context->ArgumentVersion8 = Argument;
+
+    ReleaseMrswLockExclusive(&Context->Lock, Irql, FALSE);
+
+    status = VifEnable(Interface, VifCallbackVersion8, Context);
+
+    Trace("<====\n");
+
+    return status;
+}
+
 static VOID
 VifDisable(
     IN  PINTERFACE      Interface
@@ -287,6 +375,9 @@ VifDisable(
     Context->Argument = NULL;
     Context->Callback = NULL;
 
+    Context->ArgumentVersion8 = NULL;
+    Context->CallbackVersion8 = NULL;
+
     ReleaseMrswLockShared(&Context->Lock);
 
 done:
@@ -793,6 +884,36 @@ static struct _XENVIF_VIF_INTERFACE_V8 
VifInterfaceVersion8 = {
     { sizeof (struct _XENVIF_VIF_INTERFACE_V8), 8, NULL, NULL, NULL },
     VifAcquire,
     VifRelease,
+    VifEnableVersion8,
+    VifDisable,
+    VifQueryStatistic,
+    VifQueryRingCount,
+    VifUpdateHashMapping,
+    VifReceiverReturnPacket,
+    VifReceiverSetOffloadOptions,
+    VifReceiverSetBackfillSize,
+    VifReceiverQueryRingSize,
+    VifReceiverSetHashAlgorithm,
+    VifReceiverQueryHashCapabilities,
+    VifReceiverUpdateHashParameters,
+    VifTransmitterQueuePacket,
+    VifTransmitterQueryOffloadOptions,
+    VifTransmitterQueryLargePacketSize,
+    VifTransmitterQueryRingSize,
+    VifMacQueryState,
+    VifMacQueryMaximumFrameSize,
+    VifMacQueryPermanentAddress,
+    VifMacQueryCurrentAddress,
+    VifMacQueryMulticastAddresses,
+    VifMacSetMulticastAddresses,
+    VifMacSetFilterLevel,
+    VifMacQueryFilterLevel
+};
+
+static struct _XENVIF_VIF_INTERFACE_V9 VifInterfaceVersion9 = {
+    { sizeof (struct _XENVIF_VIF_INTERFACE_V9), 9, NULL, NULL, NULL },
+    VifAcquire,
+    VifRelease,
     VifEnable,
     VifDisable,
     VifQueryStatistic,
@@ -900,6 +1021,23 @@ VifGetInterface(
         status = STATUS_SUCCESS;
         break;
     }
+    case 9: {
+        struct _XENVIF_VIF_INTERFACE_V9 *VifInterface;
+
+        VifInterface = (struct _XENVIF_VIF_INTERFACE_V9 *)Interface;
+
+        status = STATUS_BUFFER_OVERFLOW;
+        if (Size < sizeof (struct _XENVIF_VIF_INTERFACE_V9))
+            break;
+
+        *VifInterface = VifInterfaceVersion9;
+
+        ASSERT3U(Interface->Version, ==, Version);
+        Interface->Context = Context;
+
+        status = STATUS_SUCCESS;
+        break;
+    }
     default:
         status = STATUS_NOT_SUPPORTED;
         break;
@@ -935,38 +1073,6 @@ VifTeardown(
     Trace("<====\n");
 }
 
-static FORCEINLINE VOID
-__VifReceiverQueuePacket(
-    IN  PXENVIF_VIF_CONTEXT             Context,
-    IN  ULONG                           Index,
-    IN  PMDL                            Mdl,
-    IN  ULONG                           Offset,
-    IN  ULONG                           Length,
-    IN  XENVIF_PACKET_CHECKSUM_FLAGS    Flags,
-    IN  USHORT                          MaximumSegmentSize,
-    IN  USHORT                          TagControlInformation,
-    IN  PXENVIF_PACKET_INFO             Info,
-    IN  PXENVIF_PACKET_HASH             Hash,
-    IN  BOOLEAN                         More,
-    IN  PVOID                           Cookie
-    )
-{
-    Context->Callback(Context->Argument,
-                      XENVIF_RECEIVER_QUEUE_PACKET,
-                      Index,
-                      Mdl,
-                      Offset,
-                      Length,
-                      Flags,
-                      MaximumSegmentSize,
-                      TagControlInformation,
-                      Info,
-                      Hash,
-                      More,
-                      Cookie);
-
-}
-
 VOID
 VifReceiverQueuePacket(
     IN  PXENVIF_VIF_CONTEXT             Context,
@@ -984,29 +1090,25 @@ VifReceiverQueuePacket(
     )
 {
     KIRQL                               Irql;
+    XENVIF_VIF_CALLBACK_PARAMETERS      Parameters;
+
+    RtlZeroMemory(&Parameters, sizeof (XENVIF_VIF_CALLBACK_PARAMETERS));
 
     KeRaiseIrql(DISPATCH_LEVEL, &Irql);
 
-    switch (Context->Version) {
-    case 8:
-        __VifReceiverQueuePacket(Context,
-                                 Index,
-                                 Mdl,
-                                 Offset,
-                                 Length,
-                                 Flags,
-                                 MaximumSegmentSize,
-                                 TagControlInformation,
-                                 Info,
-                                 Hash,
-                                 More,
-                                 Cookie);
-        break;
+    Parameters.ReceiverQueuePacket.Index = Index;
+    Parameters.ReceiverQueuePacket.Mdl = Mdl;
+    Parameters.ReceiverQueuePacket.Offset = Offset;
+    Parameters.ReceiverQueuePacket.Length = Length;
+    Parameters.ReceiverQueuePacket.Flags = Flags;
+    Parameters.ReceiverQueuePacket.MaximumSegmentSize = MaximumSegmentSize;
+    Parameters.ReceiverQueuePacket.TagControlInformation = 
TagControlInformation;
+    Parameters.ReceiverQueuePacket.Info = Info;
+    Parameters.ReceiverQueuePacket.Hash = Hash;
+    Parameters.ReceiverQueuePacket.More = More;
+    Parameters.ReceiverQueuePacket.Cookie = Cookie;
 
-    default:
-        ASSERT(FALSE);
-        break;
-    }
+    Context->Callback(Context->Argument, XENVIF_RECEIVER_QUEUE_PACKET, 
&Parameters);
 
     KeLowerIrql(Irql);
 }
@@ -1018,18 +1120,14 @@ VifTransmitterReturnPacket(
     IN  PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO  Completion
     )
 {
-    switch (Context->Version) {
-    case 8:
-        Context->Callback(Context->Argument,
-                          XENVIF_TRANSMITTER_RETURN_PACKET,
-                          Cookie,
-                          Completion);
-        break;
+    XENVIF_VIF_CALLBACK_PARAMETERS                  Parameters;
 
-    default:
-        ASSERT(FALSE);
-        break;
-    }
+    RtlZeroMemory(&Parameters, sizeof (XENVIF_VIF_CALLBACK_PARAMETERS));
+
+    Parameters.TransmitterReturnPacket.Cookie = Cookie;
+    Parameters.TransmitterReturnPacket.Completion = Completion;
+
+    Context->Callback(Context->Argument, XENVIF_TRANSMITTER_RETURN_PACKET, 
&Parameters);
 }
 
 PXENVIF_THREAD
-- 
2.17.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.