Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1995,1996 Microsoft Corporation
  3. :ts=4
  4. Module Name:
  5. control.c
  6. Abstract:
  7. The module contains functions specific to control type
  8. transactions on the USB.
  9. Environment:
  10. kernel mode only
  11. Notes:
  12. Revision History:
  13. 11-01-95 : created
  14. --*/
  15. #include "wdm.h"
  16. #include "stdarg.h"
  17. #include "stdio.h"
  18. #include "usbdi.h"
  19. #include "hcdi.h"
  20. #include "uhcd.h"
  21. // BUBUG inline?
  22. VOID
  23. UHCD_PrepareStatusPacket(
  24. IN PHW_TRANSFER_DESCRIPTOR TransferDescriptor,
  25. IN PUHCD_ENDPOINT Endpoint,
  26. IN PHCD_URB Urb
  27. )
  28. /*++
  29. Routine Description:
  30. Prepare the status phase for an control transfer.
  31. Arguments:
  32. TransferDescriptor - TransferDescriptor for status phase.
  33. Endpoint - endpoint associated with this transfer.
  34. Urb - pointer to URB Request for control transfer.
  35. Return Value:
  36. None.
  37. --*/
  38. {
  39. PHCD_EXTENSION urbWork = HCD_AREA(Urb).HcdExtension;
  40. ASSERT_ENDPOINT(Endpoint);
  41. // since we may be using a recycled TD, we will re-init now
  42. UHCD_InitializeAsyncTD(Endpoint, TransferDescriptor);
  43. //
  44. // tracks the nth packet in this transfer
  45. //
  46. urbWork->PacketsProcessed++;
  47. // Status phase is a null packet
  48. // in the opposite direction
  49. TransferDescriptor->InterruptOnComplete = 1;
  50. //data toggle must be 1 for status phase
  51. Endpoint->DataToggle = 1;
  52. TransferDescriptor->RetryToggle = Endpoint->DataToggle;
  53. Endpoint->DataToggle ^=1;
  54. #if DBG
  55. // bugbug use this field to detect if we
  56. // process the same TD twice
  57. TransferDescriptor->Frame = 0;
  58. #endif
  59. TransferDescriptor->MaxLength = NULL_PACKET_LENGTH;
  60. if (DATA_DIRECTION_IN(Urb))
  61. TransferDescriptor->PID = USB_OUT_PID;
  62. else
  63. TransferDescriptor->PID = USB_IN_PID;
  64. //
  65. // NOTE:
  66. // for status phase -- set the t bit in the HW_Link
  67. // field, this is done by the caller.
  68. //
  69. LOG_TD('stTD', TransferDescriptor);
  70. UHCD_KdPrint((2, "'**TD for STATUS PHASE\n"));
  71. UHCD_Debug_DumpTD(TransferDescriptor);
  72. }
  73. // BUBUG inline?
  74. VOID
  75. UHCD_PrepareSetupPacket(
  76. IN PHW_TRANSFER_DESCRIPTOR TransferDescriptor,
  77. IN PUHCD_ENDPOINT Endpoint,
  78. IN PHCD_URB Urb
  79. )
  80. /*++
  81. Routine Description:
  82. Prepare the status phase for an control transfer.
  83. Arguments:
  84. TransferDescriptor - TransferDescriptor for setup phase.
  85. Endpoint - endpoint associated with this transfer.
  86. Urb - pointer to URB Request for control transfer.
  87. Return Value:
  88. None.
  89. --*/
  90. {
  91. PUHCD_HARDWARE_DESCRIPTOR_LIST hwDescriptorList;
  92. PHCD_EXTENSION urbWork = HCD_AREA(Urb).HcdExtension;
  93. ASSERT_ENDPOINT(Endpoint);
  94. //
  95. // tracks the nth packet in this transfer
  96. //
  97. urbWork->PacketsProcessed++;
  98. // BUGBUG only one request for control
  99. UHCD_ASSERT(Endpoint->MaxRequests == 1);
  100. hwDescriptorList = Endpoint->HardwareDescriptorList[0];
  101. // since we may be using a recycled TD, we will re-init now
  102. UHCD_InitializeAsyncTD(Endpoint, TransferDescriptor);
  103. //data toggle must be 0 for setup
  104. //BUGBUG reset data toggle in ENDPOINT
  105. Endpoint->DataToggle = 0;
  106. TransferDescriptor->RetryToggle = Endpoint->DataToggle;
  107. Endpoint->DataToggle ^=1;
  108. TransferDescriptor->PID = USB_SETUP_PID;
  109. TransferDescriptor->MaxLength =
  110. UHCD_SYSTEM_TO_USB_BUFFER_LENGTH(sizeof(Urb->HcdUrbCommonTransfer.Extension.u.SetupPacket));
  111. // Copy the setup packet in to the scratch buffer
  112. RtlCopyMemory(hwDescriptorList->ScratchBufferVirtualAddress,
  113. &Urb->HcdUrbCommonTransfer.Extension.u.SetupPacket[0],
  114. sizeof(Urb->HcdUrbCommonTransfer.Extension.u.SetupPacket));
  115. TransferDescriptor->PacketBuffer = hwDescriptorList->ScratchBufferLogicalAddress;
  116. LOG_TD('SuTD', TransferDescriptor);
  117. UHCD_KdPrint((2, "'**TD for setup packet\n"));
  118. UHCD_Debug_DumpTD(TransferDescriptor);
  119. }