https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c6ca2a8f027e22091fd08b1825a9298ec63ee5d8

commit c6ca2a8f027e22091fd08b1825a9298ec63ee5d8
Author:     Vadim Galyant <v...@rambler.ru>
AuthorDate: Tue Nov 28 14:41:05 2017 +0900
Commit:     Amine Khaldi <amine.kha...@reactos.org>
CommitDate: Sun Jan 21 19:35:40 2018 +0100

    [USBPORT] Add support for transaction translators in USBPORT_OpenPipe() and 
USBPORT_ClosePipe().
---
 drivers/usb/usbport/device.c   |  2 +-
 drivers/usb/usbport/endpoint.c | 44 +++++++++++++++++++++++++++++++++++-------
 drivers/usb/usbport/usbport.h  |  4 +++-
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/usbport/device.c b/drivers/usb/usbport/device.c
index fdeac97846..f1cb04eb47 100644
--- a/drivers/usb/usbport/device.c
+++ b/drivers/usb/usbport/device.c
@@ -1914,7 +1914,7 @@ USBPORT_InitializeTT(IN PDEVICE_OBJECT FdoDevice,
     TtExtension->RootHubPdo = FdoExtension->RootHubPdo;
     TtExtension->BusBandwidth = TOTAL_USB11_BUS_BANDWIDTH;
 
-    InitializeListHead(&TtExtension->TtList);
+    InitializeListHead(&TtExtension->EndpointList);
 
     /* 90% maximum allowed for periodic endpoints */
     for (ix = 0; ix < USB2_FRAMES; ix++)
diff --git a/drivers/usb/usbport/endpoint.c b/drivers/usb/usbport/endpoint.c
index 2479cf9dea..49124ae763 100644
--- a/drivers/usb/usbport/endpoint.c
+++ b/drivers/usb/usbport/endpoint.c
@@ -471,6 +471,9 @@ USBPORT_ClosePipe(IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
     PUSBPORT_DEVICE_EXTENSION FdoExtension;
     PUSBPORT_RHDEVICE_EXTENSION PdoExtension;
     PUSBPORT_ENDPOINT Endpoint;
+    PUSBPORT_REGISTRATION_PACKET Packet;
+    PUSB2_TT_EXTENSION TtExtension;
+    ULONG ix;
     BOOLEAN IsReady;
     KIRQL OldIrql;
 
@@ -492,7 +495,6 @@ USBPORT_ClosePipe(IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
     }
 
     Endpoint = PipeHandle->Endpoint;
-    DPRINT("USBPORT_ClosePipe: Endpoint - %p\n", Endpoint);
 
     KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
 
@@ -543,16 +545,44 @@ USBPORT_ClosePipe(IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
     }
 
     Endpoint->DeviceHandle = NULL;
+    Packet = &FdoExtension->MiniPortInterface->Packet;
 
-    if (FdoExtension->MiniPortInterface->Packet.MiniPortFlags & 
USB_MINIPORT_FLAGS_USB2)
+    if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
     {
-        DPRINT("USBPORT_ClosePipe: FIXME USBPORT_FreeBandwidthUSB20\n");
-        //USBPORT_FreeBandwidthUSB20();
+        USBPORT_FreeBandwidthUSB2(FdoDevice, Endpoint);
+
+        KeAcquireSpinLock(&FdoExtension->TtSpinLock, &OldIrql);
+
+        TtExtension = Endpoint->TtExtension;
+
+        if (TtExtension)
+        {
+            RemoveEntryList(&Endpoint->TtLink);
+
+            Endpoint->TtLink.Flink = NULL;
+            Endpoint->TtLink.Blink = NULL;
+
+            if (TtExtension->Flags & USB2_TT_EXTENSION_FLAG_DELETED)
+            {
+                if (IsListEmpty(&TtExtension->EndpointList))
+                {
+                    USBPORT_UpdateAllocatedBwTt(TtExtension);
+
+                    for (ix = 0; ix < USB2_FRAMES; ix++)
+                    {
+                        FdoExtension->Bandwidth[ix] += 
TtExtension->MaxBandwidth;
+                    }
+
+                    ExFreePool(TtExtension);
+                }
+            }
+        }
+
+        KeReleaseSpinLock(&FdoExtension->TtSpinLock, OldIrql);
     }
     else
     {
-        DPRINT("USBPORT_ClosePipe: FIXME USBPORT_FreeBandwidthUSB11\n");
-        //USBPORT_FreeBandwidthUSB11();
+        USBPORT_FreeBandwidth(FdoDevice, Endpoint);
     }
 
     KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
@@ -676,7 +706,7 @@ USBPORT_OpenPipe(IN PDEVICE_OBJECT FdoDevice,
 
     if (DeviceHandle->TtExtension)
     {
-        ExInterlockedInsertTailList(&DeviceHandle->TtExtension->TtList,
+        ExInterlockedInsertTailList(&DeviceHandle->TtExtension->EndpointList,
                                     &Endpoint->TtLink,
                                     &FdoExtension->TtSpinLock);
     }
diff --git a/drivers/usb/usbport/usbport.h b/drivers/usb/usbport/usbport.h
index 2f37634468..3bba591f06 100644
--- a/drivers/usb/usbport/usbport.h
+++ b/drivers/usb/usbport/usbport.h
@@ -528,6 +528,8 @@ typedef struct _USB2_TT {
   ULONG TimeCS[USB2_FRAMES][USB2_MICROFRAMES];
 } USB2_TT, *PUSB2_TT;
 
+#define USB2_TT_EXTENSION_FLAG_DELETED  1
+
 typedef struct _USB2_TT_EXTENSION {
   PDEVICE_OBJECT RootHubPdo;
   ULONG Flags;
@@ -537,7 +539,7 @@ typedef struct _USB2_TT_EXTENSION {
   ULONG MinBandwidth;
   USHORT DeviceAddress;
   USHORT TtNumber;
-  LIST_ENTRY TtList;
+  LIST_ENTRY EndpointList;
   LIST_ENTRY Link;
   USB2_TT Tt;
 } USB2_TT_EXTENSION, *PUSB2_TT_EXTENSION;

Reply via email to