ReactOS 0.4.17-dev-1281-g065abb3
devlpm.cpp File Reference
#include "usbhub3.h"
#include "devhcd.h"
#include <debug.h>
Include dependency graph for devlpm.cpp:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define TIMEOUT_DISABLED   0x00
 
#define TIMEOUT_SHORTEST   0x01
 
#define U1_TIMEOUT_LONGEST   0x7F
 
#define U2_TIMEOUT_LONGEST   0xFE
 
#define TIMEOUT_ACCEPT_ONLY   0xFF
 
#define LATENCY_TIMEOUT_FACTOR   5
 
#define U2_TIMEOUT_UNIT   256
 
#define INTERRUPT_USAGE_PERIODIC   0x00
 
#define MICROFRAME_US   125
 
#define TP_DELAY_5GBPS_NS   40
 
#define MAX_PACKET_FORWARD_NS   2100
 
#define PING_RESPONSE_NS   400
 
#define NO_PING_FIRST_PERCENT   10
 
#define NO_PING_LAST_PERCENT   160
 
#define MIN_LINK_SPEED_BPS   50000000ULL
 
#define TP_SYMBOL_NS_SCALE   200000000000ULL
 

Enumerations

enum class  HubU2Verdict { Computed , Off , AcceptOnly }
 

Functions

static BOOLEAN NTAPI HubChildLpmBlocked (_In_ HubChild *Child)
 
static BOOLEAN NTAPI HubChildHasPolicy (_In_ HubChild *Child, _In_ ULONG Bit)
 
static VOID NTAPI HubChildSetLink (_In_ HubChild *Child, _In_ ULONG Bit, _In_ BOOLEAN Set)
 
static BOOLEAN NTAPI HubChildHasNonControlPipe (_In_ HubConfiguration *Config)
 
static BOOLEAN NTAPI HubChildPortKeepsU2Off (_In_ HubChild *Child)
 
BOOLEAN NTAPI HubChildU2ForEnumerated (_In_ HubChild *Child)
 
static BOOLEAN NTAPI HubChildU1FromPipes (_In_ HubChild *Child, _Out_ PUCHAR Timeout)
 
static HubU2Verdict NTAPI HubChildU2FromPipes (_In_ HubChild *Child, _Out_ PUSHORT Longest, _Out_ PBOOLEAN PeriodicInterrupt)
 
static BOOLEAN NTAPI HubLinkStateOff (_In_ UCHAR Timeout, _In_ BOOLEAN Target)
 
static DSM_FEATURE_CHANGE NTAPI HubLinkChange (_In_ BOOLEAN Wanted, _In_ BOOLEAN Enabled)
 
static BOOLEAN NTAPI HubTpDelayFromAttribute (_In_ const USB_DEVICE_CAPABILITY_SUPERSPEEDPLUS_SPEED *Attribute, _In_ ULONG LaneCount, _Out_ PUSHORT Delay)
 
static const USB_DEVICE_CAPABILITY_SUPERSPEEDPLUS_SPEED *NTAPI HubPortFindSpeed (_In_ HubPort *Port, _In_ ULONG SpeedId, _In_ ULONG Direction)
 

Macro Definition Documentation

◆ INTERRUPT_USAGE_PERIODIC

#define INTERRUPT_USAGE_PERIODIC   0x00

Definition at line 28 of file devlpm.cpp.

◆ LATENCY_TIMEOUT_FACTOR

#define LATENCY_TIMEOUT_FACTOR   5

Definition at line 22 of file devlpm.cpp.

◆ MAX_PACKET_FORWARD_NS

#define MAX_PACKET_FORWARD_NS   2100

Definition at line 35 of file devlpm.cpp.

◆ MICROFRAME_US

#define MICROFRAME_US   125

Definition at line 31 of file devlpm.cpp.

◆ MIN_LINK_SPEED_BPS

#define MIN_LINK_SPEED_BPS   50000000ULL

Definition at line 43 of file devlpm.cpp.

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file devlpm.cpp.

◆ NO_PING_FIRST_PERCENT

#define NO_PING_FIRST_PERCENT   10

Definition at line 39 of file devlpm.cpp.

◆ NO_PING_LAST_PERCENT

#define NO_PING_LAST_PERCENT   160

Definition at line 40 of file devlpm.cpp.

◆ PING_RESPONSE_NS

#define PING_RESPONSE_NS   400

Definition at line 36 of file devlpm.cpp.

◆ TIMEOUT_ACCEPT_ONLY

#define TIMEOUT_ACCEPT_ONLY   0xFF

Definition at line 19 of file devlpm.cpp.

◆ TIMEOUT_DISABLED

#define TIMEOUT_DISABLED   0x00

Definition at line 15 of file devlpm.cpp.

◆ TIMEOUT_SHORTEST

#define TIMEOUT_SHORTEST   0x01

Definition at line 16 of file devlpm.cpp.

◆ TP_DELAY_5GBPS_NS

#define TP_DELAY_5GBPS_NS   40

Definition at line 34 of file devlpm.cpp.

◆ TP_SYMBOL_NS_SCALE

#define TP_SYMBOL_NS_SCALE   200000000000ULL

Definition at line 46 of file devlpm.cpp.

◆ U1_TIMEOUT_LONGEST

#define U1_TIMEOUT_LONGEST   0x7F

Definition at line 17 of file devlpm.cpp.

◆ U2_TIMEOUT_LONGEST

#define U2_TIMEOUT_LONGEST   0xFE

Definition at line 18 of file devlpm.cpp.

◆ U2_TIMEOUT_UNIT

#define U2_TIMEOUT_UNIT   256

Definition at line 25 of file devlpm.cpp.

Enumeration Type Documentation

◆ HubU2Verdict

Enumerator
Computed 
Off 
AcceptOnly 

Definition at line 260 of file devlpm.cpp.

261{
262 Computed,
263 Off,
265};

Function Documentation

◆ HubChildHasNonControlPipe()

static BOOLEAN NTAPI HubChildHasNonControlPipe ( _In_ HubConfiguration *  Config)
static

Definition at line 85 of file devlpm.cpp.

87{
91
92 for (Entry = Config->Interfaces.Flink; Entry != &Config->Interfaces; Entry = Entry->Flink)
93 {
95
96 for (Index = 0; Index < Interface->PipeCount; Index++)
97 {
98 if ((Interface->Pipes[Index].Descriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK) !=
100 {
101 return TRUE;
102 }
103 }
104 }
105
106 return FALSE;
107}
PLIST_ENTRY Entry
Definition: devhcd.cpp:1262
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG Config
_In_ UCXUSBDEVICE _In_ ULONG Interface
Definition: ucxusbdevice.h:428
#define USB_ENDPOINT_TYPE_CONTROL
Definition: usb100.h:62
#define USB_ENDPOINT_TYPE_MASK
Definition: usb100.h:61
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by HubChildU1FromPipes(), and HubChildU2FromPipes().

◆ HubChildHasPolicy()

static BOOLEAN NTAPI HubChildHasPolicy ( _In_ HubChild *  Child,
_In_ ULONG  Bit 
)
static

Definition at line 60 of file devlpm.cpp.

63{
64 return (Child->m_LpmPolicy & Bit) != 0;
65}
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFDEVICE Child
Definition: wdffdo.h:536

Referenced by DeviceMachine::CalcU1Timeout(), DeviceMachine::CalcU2Timeout(), and HubChildU2ForEnumerated().

◆ HubChildLpmBlocked()

static BOOLEAN NTAPI HubChildLpmBlocked ( _In_ HubChild *  Child)
static

Definition at line 51 of file devlpm.cpp.

53{
54 return Child->HasHack(ChildHack::DisableLpm) || Child->m_Hub->HasFlag(HubFlag::DisableLpm);
55}

Referenced by DeviceMachine::CalcU1Timeout(), DeviceMachine::CalcU2Timeout(), and HubChildU2ForEnumerated().

◆ HubChildPortKeepsU2Off()

static BOOLEAN NTAPI HubChildPortKeepsU2Off ( _In_ HubChild *  Child)
static

Definition at line 122 of file devlpm.cpp.

124{
125 HubPort* Port = Child->m_Port;
126
127 if (!Port->HasFlag(PortFlag::AcpiNoU2))
128 return FALSE;
129
130 return !(Port->HasFlag(PortFlag::Usb4Host) && Child->m_TunnelState == HUB_TUNNEL_STATE_TUNNELED);
131}
CPPORT Port[4]
Definition: headless.c:38
#define HUB_TUNNEL_STATE_TUNNELED
Definition: hubchild.h:52

Referenced by HubChildU2ForEnumerated().

◆ HubChildSetLink()

static VOID NTAPI HubChildSetLink ( _In_ HubChild *  Child,
_In_ ULONG  Bit,
_In_ BOOLEAN  Set 
)
static

Definition at line 70 of file devlpm.cpp.

74{
75 if (Set)
76 Child->m_LinkFlags |= Bit;
77 else
78 Child->m_LinkFlags &= ~Bit;
79}
static BOOL Set
Definition: pageheap.c:10

Referenced by DeviceMachine::CalcU1Timeout(), and DeviceMachine::CalcU2Timeout().

◆ HubChildU1FromPipes()

static BOOLEAN NTAPI HubChildU1FromPipes ( _In_ HubChild *  Child,
_Out_ PUCHAR  Timeout 
)
static

Definition at line 163 of file devlpm.cpp.

166{
167 HubConfiguration* Config = Child->m_CurrentConfig;
171 BOOLEAN NonControl;
172 USHORT Latency;
174 USHORT Longest = 0;
175 ULONG Index;
176
178 if (Config == NULL)
179 return TRUE;
180
181 NonControl = HubChildHasNonControlPipe(Config);
182
183 for (Entry = Config->Interfaces.Flink; Entry != &Config->Interfaces; Entry = Entry->Flink)
184 {
186
187 for (Index = 0; Index < Interface->PipeCount; Index++)
188 {
189 Endpoint = Interface->Pipes[Index].Descriptor;
190 Latency = USB_ENDPOINT_DIRECTION_IN(Endpoint->bEndpointAddress) ? Child->m_Sel.U1Sel
191 : Child->m_HostU1ExitLatency;
192
193 switch (Endpoint->bmAttributes & USB_ENDPOINT_TYPE_MASK)
194 {
196 Value = NonControl ? LATENCY_TIMEOUT_FACTOR : (USHORT)(LATENCY_TIMEOUT_FACTOR * Latency);
197 break;
198
200 if (Latency > Endpoint->bInterval * MICROFRAME_US)
201 return FALSE;
203 break;
204
205 default:
206 Value = (USHORT)(LATENCY_TIMEOUT_FACTOR * Latency);
207 break;
208 }
209
210 Longest = max(Longest, Value);
211 }
212 }
213
214 /* Only the low byte is kept before capping: 0x105 gives 5 */
215 *Timeout = min((UCHAR)Longest, U1_TIMEOUT_LONGEST);
216 return TRUE;
217}
unsigned char BOOLEAN
Definition: actypes.h:127
#define TIMEOUT_SHORTEST
Definition: devlpm.cpp:16
#define MICROFRAME_US
Definition: devlpm.cpp:31
#define TIMEOUT_DISABLED
Definition: devlpm.cpp:15
#define LATENCY_TIMEOUT_FACTOR
Definition: devlpm.cpp:22
#define U1_TIMEOUT_LONGEST
Definition: devlpm.cpp:17
static BOOLEAN NTAPI HubChildHasNonControlPipe(_In_ HubConfiguration *Config)
Definition: devlpm.cpp:85
#define NULL
Definition: types.h:112
_In_ UCXHUB_DEVICE_CONTEXT _In_ UCXENDPOINT Endpoint
Definition: hubucx.h:238
#define min(a, b)
Definition: monoChain.cc:55
unsigned short USHORT
Definition: pedump.c:61
static ULONG Timeout
Definition: ping.c:61
#define max(a, b)
Definition: svc.c:63
unsigned char UCHAR
Definition: typedefs.h:53
#define USB_ENDPOINT_TYPE_ISOCHRONOUS
Definition: usb100.h:63
#define USB_ENDPOINT_DIRECTION_IN(x)
Definition: usb100.h:76
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by DeviceMachine::CalcU1Timeout().

◆ HubChildU2ForEnumerated()

BOOLEAN NTAPI HubChildU2ForEnumerated ( _In_ HubChild *  Child)

TRUE when an enumerated, unconfigured device gets a U2 timeout; sets that timeout.

Definition at line 135 of file devlpm.cpp.

137{
141 {
142 return FALSE;
143 }
144
147 return TRUE;
148}
#define HUB_LPM_POLICY_U2_ACCEPT
Definition: devhcd.h:14
#define HUB_LPM_POLICY_U2_INITIATE
Definition: devhcd.h:16
static BOOLEAN NTAPI HubChildPortKeepsU2Off(_In_ HubChild *Child)
Definition: devlpm.cpp:122
static BOOLEAN NTAPI HubChildLpmBlocked(_In_ HubChild *Child)
Definition: devlpm.cpp:51
static BOOLEAN NTAPI HubChildHasPolicy(_In_ HubChild *Child, _In_ ULONG Bit)
Definition: devlpm.cpp:60
#define U2_TIMEOUT_LONGEST
Definition: devlpm.cpp:18
#define TIMEOUT_ACCEPT_ONLY
Definition: devlpm.cpp:19

Referenced by DeviceMachine::U2NeededForEnumerated(), and DeviceMachine::UpdateDeviceInController().

◆ HubChildU2FromPipes()

static HubU2Verdict NTAPI HubChildU2FromPipes ( _In_ HubChild *  Child,
_Out_ PUSHORT  Longest,
_Out_ PBOOLEAN  PeriodicInterrupt 
)
static

Definition at line 270 of file devlpm.cpp.

274{
275 HubConfiguration* Config = Child->m_CurrentConfig;
279 BOOLEAN NonControl;
280 BOOLEAN NoHostInitiate = FALSE;
281 USHORT Latency;
283 ULONG Index;
284
285 *Longest = 0;
286 *PeriodicInterrupt = FALSE;
287 if (Config == NULL)
289
290 NonControl = HubChildHasNonControlPipe(Config);
291
292 for (Entry = Config->Interfaces.Flink; Entry != &Config->Interfaces; Entry = Entry->Flink)
293 {
295
296 for (Index = 0; Index < Interface->PipeCount; Index++)
297 {
298 Endpoint = Interface->Pipes[Index].Descriptor;
299 Latency = USB_ENDPOINT_DIRECTION_IN(Endpoint->bEndpointAddress) ? Child->m_Sel.U2Sel
300 : Child->m_HostU2ExitLatency;
301 Value = (USHORT)(LATENCY_TIMEOUT_FACTOR * Latency);
302
303 switch (Endpoint->bmAttributes & USB_ENDPOINT_TYPE_MASK)
304 {
306 if (NonControl)
308 break;
309
311 if (Latency > Endpoint->bInterval * MICROFRAME_US)
312 return HubU2Verdict::Off;
314 break;
315
318 break;
319
320 *PeriodicInterrupt = TRUE;
321 if (Latency > Endpoint->bInterval * MICROFRAME_US)
322 {
323 NoHostInitiate = TRUE;
325 }
326 break;
327
328 default:
329 break;
330 }
331
332 *Longest = max(*Longest, Value);
333 }
334 }
335
336 return NoHostInitiate ? HubU2Verdict::AcceptOnly : HubU2Verdict::Computed;
337}
#define INTERRUPT_USAGE_PERIODIC
Definition: devlpm.cpp:28
#define USB_ENDPOINT_TYPE_INTERRUPT
Definition: usb100.h:65
#define USB_30_ENDPOINT_TYPE_INTERRUPT_USAGE_MASK
Definition: usb300.h:69

Referenced by DeviceMachine::CalcU2Timeout().

◆ HubLinkChange()

static DSM_FEATURE_CHANGE NTAPI HubLinkChange ( _In_ BOOLEAN  Wanted,
_In_ BOOLEAN  Enabled 
)
static

Definition at line 485 of file devlpm.cpp.

488{
489 if (Wanted == Enabled)
490 return DsmFeatureKeep;
491
493}
@ DsmFeatureKeep
Definition: devsm.h:108
@ DsmFeatureDisable
Definition: devsm.h:110
@ DsmFeatureEnable
Definition: devsm.h:109
_In_ ULONG Wanted
Definition: intr.cpp:782
@ Enabled
Definition: mountmgr.h:179

Referenced by DeviceMachine::U1Change(), and DeviceMachine::U2Change().

◆ HubLinkStateOff()

static BOOLEAN NTAPI HubLinkStateOff ( _In_ UCHAR  Timeout,
_In_ BOOLEAN  Target 
)
static

Definition at line 421 of file devlpm.cpp.

424{
426}
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306

Referenced by DeviceMachine::ComputeExitLatency().

◆ HubPortFindSpeed()

static const USB_DEVICE_CAPABILITY_SUPERSPEEDPLUS_SPEED *NTAPI HubPortFindSpeed ( _In_ HubPort *  Port,
_In_ ULONG  SpeedId,
_In_ ULONG  Direction 
)
static

Definition at line 620 of file devlpm.cpp.

624{
626 ULONG Index;
627
628 for (Index = 0; Index < Port->m_Info.SublinkSpeedAttrCount; Index++)
629 {
630 Attribute = &Port->m_Info.SublinkSpeedAttr[Index];
631
632 if (Attribute->SublinkSpeedAttrID == SpeedId && Attribute->SublinkTypeDir == Direction)
633 return Attribute;
634 }
635
636 return NULL;
637}
WDF_EXTERN_C_START typedef _In_ WDFDEVICE _In_ WDFCONTEXT _In_ WDF_DMA_DIRECTION Direction

Referenced by DeviceMachine::SetSpeedFor30().

◆ HubTpDelayFromAttribute()

static BOOLEAN NTAPI HubTpDelayFromAttribute ( _In_ const USB_DEVICE_CAPABILITY_SUPERSPEEDPLUS_SPEED *  Attribute,
_In_ ULONG  LaneCount,
_Out_ PUSHORT  Delay 
)
static

Definition at line 600 of file devlpm.cpp.

604{
605 static const ULONG64 Scale[] = { 1, 1000, 1000000, 1000000000 };
606 ULONG64 Speed;
607
608 Speed = Scale[Attribute->LaneSpeedExponent] * Attribute->LaneSpeedMantissa * (LaneCount + 1);
609 if (Speed < MIN_LINK_SPEED_BPS)
610 return FALSE;
611
612 *Delay = (USHORT)(TP_SYMBOL_NS_SCALE / Speed);
613 return TRUE;
614}
#define MIN_LINK_SPEED_BPS
Definition: devlpm.cpp:43
#define TP_SYMBOL_NS_SCALE
Definition: devlpm.cpp:46
unsigned __int64 ULONG64
Definition: imports.h:198

Referenced by DeviceMachine::SetSpeedFor30().