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

[win-pv-devel] [PATCH] Centralize compatibility code



This patch moves the code that maintains compatibility with older
VIF interface versions into the vif.c module, rather than having it
distributed amongst vif.c, transmitter.c and receiver.c.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvif/receiver.c    | 130 ++------------------
 src/xenvif/receiver.h    |   6 -
 src/xenvif/transmitter.c | 183 +---------------------------
 src/xenvif/transmitter.h |  14 ---
 src/xenvif/vif.c         | 310 ++++++++++++++++++++++++++++++++++++++++-------
 src/xenvif/vif.h         |   5 -
 6 files changed, 277 insertions(+), 371 deletions(-)

diff --git a/src/xenvif/receiver.c b/src/xenvif/receiver.c
index d3073e1..bfc5ff9 100644
--- a/src/xenvif/receiver.c
+++ b/src/xenvif/receiver.c
@@ -1373,79 +1373,6 @@ __ReceiverRingAcquireLock(
     KeAcquireSpinLockAtDpcLevel(&Ring->Lock);
 }
 
-static FORCEINLINE VOID
-__ReceiverQueuePacketVersion1(
-    IN  PXENVIF_RECEIVER                Receiver,
-    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  PVOID                           Cookie
-    )
-{
-    struct _XENVIF_PACKET_INFO_V1       *InfoVersion1;
-    struct _XENVIF_RECEIVER_PACKET_V1   *PacketVersion1;
-    PXENVIF_FRONTEND                    Frontend;
-    PXENVIF_VIF_CONTEXT                 Context;
-    LIST_ENTRY                          List;
-    NTSTATUS                            status;
-
-    InfoVersion1 = __ReceiverAllocate(sizeof (struct _XENVIF_PACKET_INFO_V1));
-
-    status = STATUS_NO_MEMORY;
-    if (InfoVersion1 == NULL)
-        goto fail1;
-
-    InfoVersion1->Length = Info->Length;
-    InfoVersion1->TagControlInformation = TagControlInformation;
-    InfoVersion1->IsAFragment = Info->IsAFragment;
-    InfoVersion1->EthernetHeader = Info->EthernetHeader;
-    InfoVersion1->LLCSnapHeader = Info->LLCSnapHeader;
-    InfoVersion1->IpHeader = Info->IpHeader;
-    InfoVersion1->IpOptions = Info->IpOptions;
-    InfoVersion1->TcpHeader = Info->TcpHeader;
-    InfoVersion1->TcpOptions = Info->TcpOptions;
-    InfoVersion1->UdpHeader = Info->UdpHeader;
-
-    PacketVersion1 = __ReceiverAllocate(sizeof (struct 
_XENVIF_RECEIVER_PACKET_V1));
-
-    status = STATUS_NO_MEMORY;
-    if (PacketVersion1 == NULL)
-        goto fail2;
-
-    PacketVersion1->Info = InfoVersion1;
-    PacketVersion1->Offset = Offset;
-    PacketVersion1->Length = Length;
-    PacketVersion1->Flags = Flags;
-    PacketVersion1->MaximumSegmentSize = MaximumSegmentSize;
-    PacketVersion1->Cookie = Cookie;
-    PacketVersion1->Mdl = *Mdl;
-    PacketVersion1->__Pfn = MmGetMdlPfnArray(Mdl)[0];
-
-    Frontend = Receiver->Frontend;
-    Context = PdoGetVifContext(FrontendGetPdo(Frontend));
-
-    InitializeListHead(&List);
-
-    InsertTailList(&List, &PacketVersion1->ListEntry);
-
-    VifReceiverQueuePacketsVersion1(Context, &List);
-    ASSERT(IsListEmpty(&List));
-
-    return;
-
-fail2:
-    Error("fail2\n");
-
-fail1:
-    Error("fail1 (%08x)\n", status);
-
-    ReceiverReturnPacket(Receiver, Cookie);
-}
-
 static DECLSPEC_NOINLINE VOID
 ReceiverRingAcquireLock(
     IN  PXENVIF_RECEIVER_RING   Ring
@@ -1463,7 +1390,6 @@ __ReceiverRingReleaseLock(
     PXENVIF_RECEIVER            Receiver;
     PXENVIF_FRONTEND            Frontend;
     PXENVIF_VIF_CONTEXT         Context;
-    ULONG                       Version;
     LIST_ENTRY                  List;
     ULONG                       Count;
 
@@ -1472,7 +1398,6 @@ __ReceiverRingReleaseLock(
     Receiver = Ring->Receiver;
     Frontend = Receiver->Frontend;
     Context = PdoGetVifContext(FrontendGetPdo(Frontend));
-    Version = VifGetVersion(Context);
 
     InitializeListHead(&List);
     Count = 0;
@@ -1502,26 +1427,15 @@ __ReceiverRingReleaseLock(
                                    XENVIF_RECEIVER_PACKET,
                                    ListEntry);
 
-        if (Version < 4)
-            __ReceiverQueuePacketVersion1(Receiver,
-                                          &Packet->Mdl,
-                                          Packet->Offset,
-                                          Packet->Length,
-                                          Packet->Flags,
-                                          Packet->MaximumSegmentSize,
-                                          Packet->TagControlInformation,
-                                          &Packet->Info,
-                                          Packet);
-        else
-            VifReceiverQueuePacket(Context,
-                                   &Packet->Mdl,
-                                   Packet->Offset,
-                                   Packet->Length,
-                                   Packet->Flags,
-                                   Packet->MaximumSegmentSize,
-                                   Packet->TagControlInformation,
-                                   &Packet->Info,
-                                   Packet);
+        VifReceiverQueuePacket(Context,
+                               &Packet->Mdl,
+                               Packet->Offset,
+                               Packet->Length,
+                               Packet->Flags,
+                               Packet->MaximumSegmentSize,
+                               Packet->TagControlInformation,
+                               &Packet->Info,
+                               Packet);
     }
 
     ASSERT(IsListEmpty(&List));
@@ -3471,32 +3385,6 @@ ReceiverReturnPacket(
 }
 
 VOID
-ReceiverReturnPacketsVersion1(
-    IN  PXENVIF_RECEIVER    Receiver,
-    IN  PLIST_ENTRY         List
-    )
-{
-    while (!IsListEmpty(List)) {
-        PLIST_ENTRY                         ListEntry;
-        struct _XENVIF_RECEIVER_PACKET_V1   *PacketVersion1;
-
-        ListEntry = RemoveHeadList(List);
-        ASSERT3P(ListEntry, !=, List);
-
-        RtlZeroMemory(ListEntry, sizeof (LIST_ENTRY));
-
-        PacketVersion1 = CONTAINING_RECORD(ListEntry,
-                                           struct _XENVIF_RECEIVER_PACKET_V1,
-                                           ListEntry);
-
-        ReceiverReturnPacket(Receiver, PacketVersion1->Cookie);
-
-        __ReceiverFree(PacketVersion1->Info);
-        __ReceiverFree(PacketVersion1);
-    }
-}
-
-VOID
 ReceiverWaitForPackets(
     IN  PXENVIF_RECEIVER    Receiver
     )
diff --git a/src/xenvif/receiver.h b/src/xenvif/receiver.h
index 042e1da..7188dfa 100644
--- a/src/xenvif/receiver.h
+++ b/src/xenvif/receiver.h
@@ -101,12 +101,6 @@ ReceiverSetBackfillSize(
     );
 
 extern VOID
-ReceiverReturnPacketsVersion1(
-    IN  PXENVIF_RECEIVER    Receiver,
-    IN  PLIST_ENTRY         List
-    );
-
-extern VOID
 ReceiverReturnPacket(
     IN  PXENVIF_RECEIVER    Receiver,
     IN  PVOID               Cookie
diff --git a/src/xenvif/transmitter.c b/src/xenvif/transmitter.c
index a8b0162..a5bcf82 100644
--- a/src/xenvif/transmitter.c
+++ b/src/xenvif/transmitter.c
@@ -2736,33 +2736,6 @@ TransmitterRingSchedule(
 }
 
 static FORCEINLINE VOID
-__TransmitterReturnPacketVersion2(
-    IN  PXENVIF_TRANSMITTER                         Transmitter,
-    IN  PVOID                                       Cookie,
-    IN  PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO  Completion
-    )
-{
-    struct _XENVIF_TRANSMITTER_PACKET_V2            *PacketVersion2;
-    PXENVIF_FRONTEND                                Frontend;
-    PXENVIF_VIF_CONTEXT                             Context;
-    LIST_ENTRY                                      List;
-
-    PacketVersion2 = Cookie;
-    PacketVersion2->Completion = *Completion;
-
-    Frontend = Transmitter->Frontend;
-    Context = PdoGetVifContext(FrontendGetPdo(Frontend));
-
-    InitializeListHead(&List);
-
-    ASSERT(IsZeroMemory(&PacketVersion2->ListEntry, sizeof (LIST_ENTRY)));
-    InsertTailList(&List, &PacketVersion2->ListEntry);
-
-    VifTransmitterReturnPacketsVersion2(Context, &List);
-    ASSERT(IsListEmpty(&List));
-}
-
-static FORCEINLINE VOID
 __TransmitterReturnPackets(
     IN  PXENVIF_TRANSMITTER Transmitter,
     IN  PLIST_ENTRY         List
@@ -2770,11 +2743,9 @@ __TransmitterReturnPackets(
 {
     PXENVIF_FRONTEND        Frontend;
     PXENVIF_VIF_CONTEXT     Context;
-    ULONG                   Version;
 
     Frontend = Transmitter->Frontend;
     Context = PdoGetVifContext(FrontendGetPdo(Frontend));
-    Version = VifGetVersion(Context);
 
     while (!IsListEmpty(List)) {
         PLIST_ENTRY                 ListEntry;
@@ -2789,14 +2760,9 @@ __TransmitterReturnPackets(
                                    XENVIF_TRANSMITTER_PACKET,
                                    ListEntry);
 
-        if  (Version < 4)
-            __TransmitterReturnPacketVersion2(Transmitter,
-                                              Packet->Cookie,
-                                              &Packet->Completion);
-        else
-            VifTransmitterReturnPacket(Context,
-                                       Packet->Cookie,
-                                       &Packet->Completion);
+        VifTransmitterReturnPacket(Context,
+                                   Packet->Cookie,
+                                   &Packet->Completion);
 
         __TransmitterPutPacket(Transmitter, Packet);
     }
@@ -4560,96 +4526,6 @@ TransmitterTeardown(
     __TransmitterFree(Transmitter);
 }
 
-static BOOLEAN
-TransmitterGetPacketHeadersVersion2Pullup(
-    IN      PVOID                   Argument,
-    IN      PUCHAR                  DestinationVa,
-    IN OUT  PXENVIF_PACKET_PAYLOAD  Payload,
-    IN      ULONG                   Length
-    )
-{
-    PMDL                            Mdl;
-    ULONG                           Offset;
-
-    UNREFERENCED_PARAMETER(Argument);
-
-    Mdl = Payload->Mdl;
-    Offset = Payload->Offset;
-
-    if (Payload->Length < Length)
-        goto fail1;
-
-    Payload->Length -= Length;
-
-    while (Length != 0) {
-        PUCHAR  MdlMappedSystemVa;
-        ULONG   MdlByteCount;
-        ULONG   CopyLength;
-
-        ASSERT(Mdl != NULL);
-
-        MdlMappedSystemVa = MmGetSystemAddressForMdlSafe(Mdl, 
NormalPagePriority);
-        ASSERT(MdlMappedSystemVa != NULL);
-
-        MdlMappedSystemVa += Offset;
-
-        MdlByteCount = Mdl->ByteCount - Offset;
-
-        CopyLength = __min(MdlByteCount, Length);
-
-        RtlCopyMemory(DestinationVa, MdlMappedSystemVa, CopyLength);
-        DestinationVa += CopyLength;
-
-        Offset += CopyLength;
-        Length -= CopyLength;
-
-        MdlByteCount -= CopyLength;
-        if (MdlByteCount == 0) {
-            Mdl = Mdl->Next;
-            Offset = 0;
-        }
-    }
-
-    Payload->Mdl = Mdl;
-    Payload->Offset = Offset;
-
-    return TRUE;
-
-fail1:
-    Error("fail1\n");
-
-    return FALSE;
-}
-
-NTSTATUS
-TransmitterGetPacketHeadersVersion2(
-    IN  PXENVIF_TRANSMITTER                     Transmitter,
-    IN  struct _XENVIF_TRANSMITTER_PACKET_V2    *PacketVersion2,
-    OUT PVOID                                   Headers,
-    OUT PXENVIF_PACKET_INFO                     Info
-    )
-{
-    XENVIF_PACKET_PAYLOAD                       Payload;
-    NTSTATUS                                    status;
-
-    Payload.Mdl = PacketVersion2->Mdl;
-    Payload.Offset = PacketVersion2->Offset;
-    Payload.Length = PacketVersion2->Length;
-
-    status = ParsePacket(Headers,
-                         TransmitterGetPacketHeadersVersion2Pullup,
-                         Transmitter,
-                         &Payload,
-                         Info);
-    if (!NT_SUCCESS(status))
-        goto fail1;
-
-    return STATUS_SUCCESS;
-
-fail1:
-    return status;
-}
-
 static FORCEINLINE VOID
 __TransmitterHashAccumulate(
     IN OUT  PULONG  Accumulator,
@@ -4834,59 +4710,6 @@ fail1:
     return status;
 }
 
-NTSTATUS
-TransmitterQueuePacketsVersion2(
-    IN  PXENVIF_TRANSMITTER     Transmitter,
-    IN  PLIST_ENTRY             List
-    )
-{
-    LIST_ENTRY                  Reject;
-
-    InitializeListHead(&Reject);
-
-    while (!IsListEmpty(List)) {
-        PLIST_ENTRY                             ListEntry;
-        struct _XENVIF_TRANSMITTER_PACKET_V2    *PacketVersion2;
-        XENVIF_PACKET_HASH                      Hash;
-        NTSTATUS                                status;
-
-        ListEntry = RemoveHeadList(List);
-        ASSERT3P(ListEntry, !=, List);
-
-        RtlZeroMemory(ListEntry, sizeof (LIST_ENTRY));
-
-        PacketVersion2 = CONTAINING_RECORD(ListEntry,
-                                           struct 
_XENVIF_TRANSMITTER_PACKET_V2,
-                                           ListEntry);
-
-        Hash.Algorithm = XENVIF_PACKET_HASH_ALGORITHM_UNSPECIFIED;
-        Hash.Value = PacketVersion2->Value;
-
-        status = TransmitterQueuePacket(Transmitter,
-                                        PacketVersion2->Mdl,
-                                        PacketVersion2->Offset,
-                                        PacketVersion2->Length,
-                                        PacketVersion2->Send.OffloadOptions,
-                                        
PacketVersion2->Send.MaximumSegmentSize,
-                                        
PacketVersion2->Send.TagControlInformation,
-                                        &Hash,
-                                        PacketVersion2);
-        if (!NT_SUCCESS(status))
-            InsertTailList(&Reject, &PacketVersion2->ListEntry);
-    }
-
-    ASSERT(IsListEmpty(List));
-
-    if (!IsListEmpty(&Reject)) {
-        PLIST_ENTRY ListEntry = Reject.Flink;
-
-        RemoveEntryList(&Reject);
-        AppendTailList(List, ListEntry);
-    }
-
-    return (IsListEmpty(List)) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
-}
-
 VOID
 TransmitterAbortPackets(
     IN  PXENVIF_TRANSMITTER Transmitter
diff --git a/src/xenvif/transmitter.h b/src/xenvif/transmitter.h
index 0b7f654..31198fb 100644
--- a/src/xenvif/transmitter.h
+++ b/src/xenvif/transmitter.h
@@ -128,12 +128,6 @@ TransmitterQueuePacket(
     IN  PVOID                       Cookie
     );
 
-extern NTSTATUS
-TransmitterQueuePacketsVersion2(
-    IN  PXENVIF_TRANSMITTER Transmitter,
-    IN  PLIST_ENTRY         List
-    );
-
 extern VOID
 TransmitterQueryOffloadOptions(
     IN  PXENVIF_TRANSMITTER         Transmitter,
@@ -147,12 +141,4 @@ TransmitterQueryLargePacketSize(
     OUT PULONG                  Size
     );
 
-extern NTSTATUS
-TransmitterGetPacketHeadersVersion2(
-    IN  PXENVIF_TRANSMITTER                     Transmitter,
-    IN  struct _XENVIF_TRANSMITTER_PACKET_V2    *Packet,
-    OUT PVOID                                   Headers,
-    OUT PXENVIF_PACKET_INFO                     Info
-    );
-
 #endif  // _XENVIF_TRANSMITTER_H
diff --git a/src/xenvif/vif.c b/src/xenvif/vif.c
index 3d40ad0..2288561 100644
--- a/src/xenvif/vif.c
+++ b/src/xenvif/vif.c
@@ -32,9 +32,11 @@
 #include <ntddk.h>
 #include <ntstrsafe.h>
 #include <stdarg.h>
+#include <stdlib.h>
 #include <xen.h>
 
 #include "pdo.h"
+#include "parse.h"
 #include "vif.h"
 #include "mrsw.h"
 #include "thread.h"
@@ -326,8 +328,25 @@ VifReceiverReturnPacketsVersion1(
 
     AcquireMrswLockShared(&Context->Lock);
 
-    ReceiverReturnPacketsVersion1(FrontendGetReceiver(Context->Frontend),
-                                  List);
+    while (!IsListEmpty(List)) {
+        PLIST_ENTRY                         ListEntry;
+        struct _XENVIF_RECEIVER_PACKET_V1   *PacketVersion1;
+
+        ListEntry = RemoveHeadList(List);
+        ASSERT3P(ListEntry, !=, List);
+
+        RtlZeroMemory(ListEntry, sizeof (LIST_ENTRY));
+
+        PacketVersion1 = CONTAINING_RECORD(ListEntry,
+                                           struct _XENVIF_RECEIVER_PACKET_V1,
+                                           ListEntry);
+
+        ReceiverReturnPacket(FrontendGetReceiver(Context->Frontend),
+                             PacketVersion1->Cookie);
+
+        __VifFree(PacketVersion1->Info);
+        __VifFree(PacketVersion1);
+    }
 
     ReleaseMrswLockShared(&Context->Lock);
 }
@@ -348,6 +367,67 @@ VifReceiverReturnPacket(
     ReleaseMrswLockShared(&Context->Lock);
 }
 
+static BOOLEAN
+VifTransmitterGetPacketHeadersVersion2Pullup(
+    IN      PVOID                   Argument,
+    IN      PUCHAR                  DestinationVa,
+    IN OUT  PXENVIF_PACKET_PAYLOAD  Payload,
+    IN      ULONG                   Length
+    )
+{
+    PMDL                            Mdl;
+    ULONG                           Offset;
+
+    UNREFERENCED_PARAMETER(Argument);
+
+    Mdl = Payload->Mdl;
+    Offset = Payload->Offset;
+
+    if (Payload->Length < Length)
+        goto fail1;
+
+    Payload->Length -= Length;
+
+    while (Length != 0) {
+        PUCHAR  MdlMappedSystemVa;
+        ULONG   MdlByteCount;
+        ULONG   CopyLength;
+
+        ASSERT(Mdl != NULL);
+
+        MdlMappedSystemVa = MmGetSystemAddressForMdlSafe(Mdl, 
NormalPagePriority);
+        ASSERT(MdlMappedSystemVa != NULL);
+
+        MdlMappedSystemVa += Offset;
+
+        MdlByteCount = Mdl->ByteCount - Offset;
+
+        CopyLength = __min(MdlByteCount, Length);
+
+        RtlCopyMemory(DestinationVa, MdlMappedSystemVa, CopyLength);
+        DestinationVa += CopyLength;
+
+        Offset += CopyLength;
+        Length -= CopyLength;
+
+        MdlByteCount -= CopyLength;
+        if (MdlByteCount == 0) {
+            Mdl = Mdl->Next;
+            Offset = 0;
+        }
+    }
+
+    Payload->Mdl = Mdl;
+    Payload->Offset = Offset;
+
+    return TRUE;
+
+fail1:
+    Error("fail1\n");
+
+    return FALSE;
+}
+
 static NTSTATUS
 VifTransmitterGetPacketHeadersVersion2(
     IN  PINTERFACE                              Interface,
@@ -357,14 +437,20 @@ VifTransmitterGetPacketHeadersVersion2(
     )
 {
     PXENVIF_VIF_CONTEXT                         Context = Interface->Context;
+    XENVIF_PACKET_PAYLOAD                       Payload;
     NTSTATUS                                    status;
 
     AcquireMrswLockShared(&Context->Lock);
 
-    status = 
TransmitterGetPacketHeadersVersion2(FrontendGetTransmitter(Context->Frontend),
-                                                 Packet,
-                                                 Headers,
-                                                 Info);
+    Payload.Mdl = Packet->Mdl;
+    Payload.Offset = Packet->Offset;
+    Payload.Length = Packet->Length;
+
+    status = ParsePacket(Headers,
+                         VifTransmitterGetPacketHeadersVersion2Pullup,
+                         Context,
+                         &Payload,
+                         Info);
 
     ReleaseMrswLockShared(&Context->Lock);
 
@@ -378,21 +464,59 @@ VifTransmitterQueuePacketsVersion2(
     )
 {
     PXENVIF_VIF_CONTEXT Context = Interface->Context;
-    NTSTATUS            status;
+    LIST_ENTRY          Reject;
 
     AcquireMrswLockShared(&Context->Lock);
 
-    status = STATUS_UNSUCCESSFUL;
     if (Context->Enabled == FALSE)
         goto done;
 
-    status = 
TransmitterQueuePacketsVersion2(FrontendGetTransmitter(Context->Frontend),
-                                             List);
+    InitializeListHead(&Reject);
+
+    while (!IsListEmpty(List)) {
+        PLIST_ENTRY                             ListEntry;
+        struct _XENVIF_TRANSMITTER_PACKET_V2    *PacketVersion2;
+        XENVIF_PACKET_HASH                      Hash;
+        NTSTATUS                                status;
+
+        ListEntry = RemoveHeadList(List);
+        ASSERT3P(ListEntry, !=, List);
+
+        RtlZeroMemory(ListEntry, sizeof (LIST_ENTRY));
+
+        PacketVersion2 = CONTAINING_RECORD(ListEntry,
+                                           struct 
_XENVIF_TRANSMITTER_PACKET_V2,
+                                           ListEntry);
+
+        Hash.Algorithm = XENVIF_PACKET_HASH_ALGORITHM_UNSPECIFIED;
+        Hash.Value = PacketVersion2->Value;
+
+        status = 
TransmitterQueuePacket(FrontendGetTransmitter(Context->Frontend),
+                                        PacketVersion2->Mdl,
+                                        PacketVersion2->Offset,
+                                        PacketVersion2->Length,
+                                        PacketVersion2->Send.OffloadOptions,
+                                        
PacketVersion2->Send.MaximumSegmentSize,
+                                        
PacketVersion2->Send.TagControlInformation,
+                                        &Hash,
+                                        PacketVersion2);
+        if (!NT_SUCCESS(status))
+            InsertTailList(&Reject, &PacketVersion2->ListEntry);
+    }
+
+    ASSERT(IsListEmpty(List));
+
+    if (!IsListEmpty(&Reject)) {
+        PLIST_ENTRY ListEntry = Reject.Flink;
+
+        RemoveEntryList(&Reject);
+        AppendTailList(List, ListEntry);
+    }
 
 done:
     ReleaseMrswLockShared(&Context->Lock);
 
-    return status;
+    return (IsListEmpty(List)) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
 }
 
 static VOID
@@ -417,7 +541,6 @@ VifTransmitterQueuePacketVersion4(
     if (Context->Enabled == FALSE)
         goto done;
 
-    ASSERT3U(VifGetVersion(Context), >=, 4);
     status = TransmitterQueuePacket(FrontendGetTransmitter(Context->Frontend),
                                     Mdl,
                                     Offset,
@@ -466,7 +589,6 @@ VifTransmitterQueuePacket(
     if (Context->Enabled == FALSE)
         goto done;
 
-    ASSERT3U(VifGetVersion(Context), >=, 5);
     status = TransmitterQueuePacket(FrontendGetTransmitter(Context->Frontend),
                                     Mdl,
                                     Offset,
@@ -1054,15 +1176,75 @@ VifTeardown(
     Trace("<====\n");
 }
 
-VOID
-VifReceiverQueuePacketsVersion1(
-    IN  PXENVIF_VIF_CONTEXT Context,
-    IN  PLIST_ENTRY         List
+static FORCEINLINE VOID
+__VifReceiverQueuePacketVersion1(
+    IN  PXENVIF_VIF_CONTEXT             Context,
+    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  PVOID                           Cookie
     )
 {
+    struct _XENVIF_PACKET_INFO_V1       *InfoVersion1;
+    struct _XENVIF_RECEIVER_PACKET_V1   *PacketVersion1;
+    LIST_ENTRY                          List;
+    NTSTATUS                            status;
+
+    InfoVersion1 = __VifAllocate(sizeof (struct _XENVIF_PACKET_INFO_V1));
+
+    status = STATUS_NO_MEMORY;
+    if (InfoVersion1 == NULL)
+        goto fail1;
+
+    InfoVersion1->Length = Info->Length;
+    InfoVersion1->TagControlInformation = TagControlInformation;
+    InfoVersion1->IsAFragment = Info->IsAFragment;
+    InfoVersion1->EthernetHeader = Info->EthernetHeader;
+    InfoVersion1->LLCSnapHeader = Info->LLCSnapHeader;
+    InfoVersion1->IpHeader = Info->IpHeader;
+    InfoVersion1->IpOptions = Info->IpOptions;
+    InfoVersion1->TcpHeader = Info->TcpHeader;
+    InfoVersion1->TcpOptions = Info->TcpOptions;
+    InfoVersion1->UdpHeader = Info->UdpHeader;
+
+    PacketVersion1 = __VifAllocate(sizeof (struct _XENVIF_RECEIVER_PACKET_V1));
+
+    status = STATUS_NO_MEMORY;
+    if (PacketVersion1 == NULL)
+        goto fail2;
+
+    PacketVersion1->Info = InfoVersion1;
+    PacketVersion1->Offset = Offset;
+    PacketVersion1->Length = Length;
+    PacketVersion1->Flags = Flags;
+    PacketVersion1->MaximumSegmentSize = MaximumSegmentSize;
+    PacketVersion1->Cookie = Cookie;
+    PacketVersion1->Mdl = *Mdl;
+    PacketVersion1->__Pfn = MmGetMdlPfnArray(Mdl)[0];
+
+    InitializeListHead(&List);
+    InsertTailList(&List, &PacketVersion1->ListEntry);
+
     Context->Callback(Context->Argument,
                       XENVIF_RECEIVER_QUEUE_PACKET,
                       List);
+
+    ASSERT(IsListEmpty(&List));
+
+    return;
+
+fail2:
+    Error("fail2\n");
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    ReceiverReturnPacket(FrontendGetReceiver(Context->Frontend),
+                         Cookie);
 }
 
 VOID
@@ -1078,29 +1260,61 @@ VifReceiverQueuePacket(
     IN  PVOID                           Cookie
     )
 {
-    Context->Callback(Context->Argument,
-                      XENVIF_RECEIVER_QUEUE_PACKET,
-                      Mdl,
-                      Offset,
-                      Length,
-                      Flags,
-                      MaximumSegmentSize,
-                      TagControlInformation,
-                      Info,
-                      Cookie);
+    switch (Context->Version) {
+    case 2:
+    case 3:
+        __VifReceiverQueuePacketVersion1(Context,
+                                         Mdl,
+                                         Offset,
+                                         Length,
+                                         Flags,
+                                         MaximumSegmentSize,
+                                         TagControlInformation,
+                                         Info,
+                                         Cookie);
+        break;
+
+    case 4:
+    case 5:
+        Context->Callback(Context->Argument,
+                          XENVIF_RECEIVER_QUEUE_PACKET,
+                          Mdl,
+                          Offset,
+                          Length,
+                          Flags,
+                          MaximumSegmentSize,
+                          TagControlInformation,
+                          Info,
+                          Cookie);
+        break;
+
+    default:
+        ASSERT(FALSE);
+        break;
+    }
 }
 
-VOID
-VifTransmitterReturnPacketsVersion2(
-    IN  PXENVIF_VIF_CONTEXT Context,
-    IN  PLIST_ENTRY         List
+static FORCEINLINE VOID
+__VifTransmitterReturnPacketVersion2(
+    IN  PXENVIF_VIF_CONTEXT                         Context,
+    IN  PVOID                                       Cookie,
+    IN  PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO  Completion
     )
 {
-    ASSERT3U(VifGetVersion(Context), >=, 2);
+    struct _XENVIF_TRANSMITTER_PACKET_V2            *PacketVersion2;
+    LIST_ENTRY                                      List;
+
+    PacketVersion2 = Cookie;
+    PacketVersion2->Completion = *Completion;
+
+    InitializeListHead(&List);
+    InsertTailList(&List, &PacketVersion2->ListEntry);
 
     Context->Callback(Context->Argument,
                       XENVIF_TRANSMITTER_RETURN_PACKET,
                       List);
+
+    ASSERT(IsListEmpty(&List));
 }
 
 VOID
@@ -1110,12 +1324,26 @@ VifTransmitterReturnPacket(
     IN  PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO  Completion
     )
 {
-    ASSERT3U(VifGetVersion(Context), >=, 4);
+    switch (Context->Version) {
+    case 2:
+    case 3:
+        __VifTransmitterReturnPacketVersion2(Context,
+                                             Cookie,
+                                             Completion);
+        break;
 
-    Context->Callback(Context->Argument,
-                      XENVIF_TRANSMITTER_RETURN_PACKET,
-                      Cookie,
-                      Completion);
+    case 4:
+    case 5:
+        Context->Callback(Context->Argument,
+                          XENVIF_TRANSMITTER_RETURN_PACKET,
+                          Cookie,
+                          Completion);
+        break;
+
+    default:
+        ASSERT(FALSE);
+        break;
+    }
 }
 
 PXENVIF_THREAD
@@ -1125,11 +1353,3 @@ VifGetMacThread(
 {
     return Context->MacThread;
 }
-
-ULONG
-VifGetVersion(
-    IN  PXENVIF_VIF_CONTEXT Context
-    )
-{
-    return Context->Version;
-}
diff --git a/src/xenvif/vif.h b/src/xenvif/vif.h
index ebb4337..6cda4b7 100644
--- a/src/xenvif/vif.h
+++ b/src/xenvif/vif.h
@@ -99,10 +99,5 @@ VifGetMacThread(
     IN  PXENVIF_VIF_CONTEXT Context
     );
 
-extern ULONG
-VifGetVersion(
-    IN  PXENVIF_VIF_CONTEXT Context
-    );
-
 #endif  // _XENVIF_VIF_H
 
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

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