forked from nta/dwusb
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDevice.c
More file actions
2375 lines (1792 loc) · 62.7 KB
/
Copy pathDevice.c
File metadata and controls
2375 lines (1792 loc) · 62.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*++
Module Name:
device.c - Device handling events for example driver.
Abstract:
This file contains the device entry points and callbacks.
Environment:
Kernel-mode Driver Framework
--*/
#include "driver.h"
#include "device.tmh"
// FIXME don't hardcode these! use resources!
//#define DWUSB_BASE 0x3F980000
//#define DWUSB_INT 0x29
#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE, dwusbCreateDevice)
#pragma alloc_text (PAGE, Controller_GetWdfDevice)
#endif
typedef struct _ROOT_HUB_DATA {
dwc_otg_core_global_regs_t* CoreGlobalRegs;
dwc_otg_host_global_regs_t* HostGlobalRegs;
volatile uint32_t* Hprt0;
PEX_TIMER ExTimerResetComplete;
PEX_TIMER ExTimerResumeComplete;
PEX_TIMER ExTimerResetSafeComplete;
UCXROOTHUB UcxRootHub;
BOOLEAN ResetState;
} ROOTHUB_DATA, *PROOTHUB_DATA;
typedef struct _REQUEST_DATA {
int Unused;
} REQUEST_DATA, *PREQUEST_DATA;
typedef struct _INTERRUPT_CONTEXT {
PCONTROLLER_DATA ControllerHandle;
} INTERRUPT_CONTEXT, *PINTERRUPT_CONTEXT;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(ROOTHUB_DATA, RootHubGetData)
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(REQUEST_DATA, RequestGetData)
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(INTERRUPT_CONTEXT, InterruptGetData)
WDFDEVICE
Controller_GetWdfDevice(
_In_ UCXCONTROLLER UcxController
)
{
return ControllerGetData(UcxController)->WdfDevice;
}
VOID
Controller_SetChannelCallback(
_In_ UCXCONTROLLER UcxController,
_In_ int Channel,
_In_ PFN_CHANNEL_CALLBACK Callback,
_In_opt_ PVOID Context
)
{
PCONTROLLER_DATA data = ControllerGetData(UcxController);
if (Channel >= 0 && Channel < NUM_CHANNELS)
{
data->ChannelCallbacks[Channel] = Callback;
data->ChannelCallbackContext[Channel] = Context;
}
}
VOID
RootHub_UcxEvtGetInfo(
UCXROOTHUB UcxRootHub,
WDFREQUEST WdfRequest
)
/*++
Routine Description:
This routine is called by UCX to process an
IOCTL_INTERNAL_USB_GET_ROOTHUB_INFO request and return information
about the root hub in the ROOTHUB_INFO structure attached to the
request.
The main information of interest returned in the ROOTHUB_INFO
structure is the number of 2.0 ports and the number of 3.0 ports
supported by this root hub. That information was collected by
RootHub_PrepareHardware() when it processed the xHCI Supported
Protocol Capability list.
Return Value:
None directly from this routine.
The request completion status in the WdfRequest.
--*/
{
PROOTHUB_DATA rootHubData;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PROOTHUB_INFO roothubInfo;
NTSTATUS status = STATUS_SUCCESS;
KdPrint((__FUNCTION__ ": entry\n"));
__try {
rootHubData = RootHubGetData(UcxRootHub);
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
roothubInfo = (PROOTHUB_INFO)wdfRequestParams.Parameters.Others.Arg1;
if (roothubInfo->Size < sizeof(ROOTHUB_INFO)) {
status = STATUS_INVALID_PARAMETER;
return;
}
roothubInfo->ControllerType = ControllerTypeSoftXhci;
roothubInfo->NumberOf20Ports = 1;
roothubInfo->NumberOf30Ports = 0;
//
// Units here are in microseconds.
//
roothubInfo->MaxU1ExitLatency = 10000;
roothubInfo->MaxU2ExitLatency = 10000;
status = STATUS_SUCCESS;
} __finally {
WdfRequestComplete(WdfRequest, status);
}
return;
}
VOID
RootHub_UcxEvtGet20PortInfo(
UCXROOTHUB UcxRootHub,
WDFREQUEST WdfRequest
)
/*++
Routine Description:
This routine is called by UCX to process an
IOCTL_INTERNAL_USB_ROOTHUB_GET_20PORT_INFO request and return
information about the root hub in the ROOTHUB_20PORTS_INFO structure
attached to the request.
The main information of interest returned in the
ROOTHUB_20PORTS_INFO structure is the list of 2.0 ports supported by
this root hub. That is returned in the PortInfoArray array of
ROOTHUB_20PORT_INFO structures. The list of 2.0 ports supported by
this root hub was collected by RootHub_PrepareHardware() when it
processed the xHCI Supported Protocol Capability list.
Return Value:
None directly from this routine.
The request completion status in the WdfRequest.
--*/
{
PROOTHUB_DATA rootHubData;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PROOTHUB_20PORTS_INFO roothub20PortsInfo;
PROOTHUB_20PORT_INFO* roothub20PortInfo;
USHORT srcPortIndex;
USHORT dstPortIndex;
NTSTATUS status = STATUS_SUCCESS;
KdPrint((__FUNCTION__ ": entry\n"));
__try {
rootHubData = RootHubGetData(UcxRootHub);
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
roothub20PortsInfo = (PROOTHUB_20PORTS_INFO)wdfRequestParams.Parameters.Others.Arg1;
roothub20PortInfo = &roothub20PortsInfo->PortInfoArray[0];
if (roothub20PortsInfo->Size < sizeof(ROOTHUB_20PORTS_INFO)) {
status = STATUS_INVALID_PARAMETER;
return;
}
if (roothub20PortsInfo->NumberOfPorts != 1) {
status = STATUS_INVALID_PARAMETER;
return;
}
if (roothub20PortsInfo->PortInfoSize < sizeof(ROOTHUB_20PORT_INFO)) {
status = STATUS_INVALID_PARAMETER;
return;
}
//
// Return port information for all of the MajorRevision == 2
// ports in the PortData[] array.
//
dstPortIndex = 0;
for (srcPortIndex = 0;
(srcPortIndex < 1 && dstPortIndex < roothub20PortsInfo->NumberOfPorts);
srcPortIndex++) {
//
// The PortData[] array is 0-based indexed while
// port numbers are 1-based indexed.
//
roothub20PortInfo[dstPortIndex]->PortNumber = srcPortIndex + 1;
roothub20PortInfo[dstPortIndex]->Removable = TriStateFalse;
roothub20PortInfo[dstPortIndex]->IntegratedHubImplemented = TriStateFalse;
roothub20PortInfo[dstPortIndex]->MinorRevision = 0;
roothub20PortInfo[dstPortIndex]->HubDepth = 4;
dstPortIndex++;
}
status = STATUS_SUCCESS;
} __finally {
WdfRequestComplete(WdfRequest, status);
}
return;
}
VOID
RootHub_UcxEvtGet30PortInfo(
UCXROOTHUB UcxRootHub,
WDFREQUEST WdfRequest
)
/*++
Routine Description:
This routine is called by UCX to process an
IOCTL_INTERNAL_USB_ROOTHUB_GET_30PORT_INFO request and return
information about the root hub in the ROOTHUB_30PORTS_INFO structure
attached to the request.
The main information of interest returned in the
ROOTHUB_30PORTS_INFO structure is the list of 3.0 ports supported by
this root hub. That is returned in the PortInfoArray array of
ROOTHUB_30PORT_INFO structures. The list of 3.0 ports supported by
this root hub was collected by RootHub_PrepareHardware() when it
processed the xHCI Supported Protocol Capability list.
Return Value:
None directly from this routine.
The request completion status in the WdfRequest.
--*/
{
PROOTHUB_DATA rootHubData;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PROOTHUB_30PORTS_INFO roothub30PortsInfo;
PROOTHUB_30PORT_INFO_EX* roothub30PortInfo;
USHORT dstPortIndex;
NTSTATUS status = STATUS_SUCCESS;
KdPrint((__FUNCTION__ ": entry\n"));
__try {
rootHubData = RootHubGetData(UcxRootHub);
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
roothub30PortsInfo = (PROOTHUB_30PORTS_INFO)wdfRequestParams.Parameters.Others.Arg1;
roothub30PortInfo = (PROOTHUB_30PORT_INFO_EX*)&roothub30PortsInfo->PortInfoArray[0];
if (roothub30PortsInfo->Size < sizeof(ROOTHUB_30PORTS_INFO)) {
status = STATUS_INVALID_PARAMETER;
return;
}
if (roothub30PortsInfo->NumberOfPorts != 0) {
status = STATUS_INVALID_PARAMETER;
return;
}
if (roothub30PortsInfo->PortInfoSize < sizeof(ROOTHUB_30PORT_INFO)) {
status = STATUS_INVALID_PARAMETER;
return;
}
//
// Return port information for all of the MajorRevision == 3
// ports in the PortData[] array.
//
dstPortIndex = 0;
status = STATUS_SUCCESS;
} __finally {
WdfRequestComplete(WdfRequest, status);
}
return;
}
VOID
RootHub_UcxEvtInterruptTransfer(
__in
UCXROOTHUB UcxRootHub,
__in
WDFREQUEST WdfRequest
)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PURB urb;
ULONG transferBufferLength;
PVOID transferBuffer;
KdPrint((__FUNCTION__ ": entry\n"));
UNREFERENCED_PARAMETER(UcxRootHub);
__try
{
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
urb = (PURB)wdfRequestParams.Parameters.Others.Arg1;
transferBuffer = urb->UrbBulkOrInterruptTransfer.TransferBuffer;
transferBufferLength = urb->UrbBulkOrInterruptTransfer.TransferBufferLength;
RtlZeroMemory(transferBuffer, transferBufferLength);
PROOTHUB_DATA rootHubData = RootHubGetData(UcxRootHub);
hprt0_data_t hprt0;
KeMemoryBarrier();
_DataSynchronizationBarrier();
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
KeMemoryBarrier();
_DataSynchronizationBarrier();
if (hprt0.b.prtenchng || hprt0.b.prtovrcurrchng || hprt0.b.prtconndet/* || rootHubData->ResetState*/)
{
// port 1 changed
((PUCHAR)transferBuffer)[0] |= 1 << 1;
}
status = STATUS_SUCCESS;
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
}
__finally
{
WdfRequestComplete(WdfRequest, status);
}
}
VOID
RootHub_UcxEvtClearHubFeature(
UCXROOTHUB UcxRootHub,
WDFREQUEST WdfRequest
)
/*++
Routine Description:
Arguments:
UcxRootHub - The UCX root hub object.
WdfRequest - The WDF request object for the Clear Hub Feature request.
Return Value:
None directly from this routine.
The request completion status in the WdfRequest and the USBD_STATUS
in the urb header.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PROOTHUB_DATA rootHubData;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PURB urb;
PWDF_USB_CONTROL_SETUP_PACKET setupPacket;
ULONG featureSelector;
KdPrint((__FUNCTION__ ": entry\n"));
UNREFERENCED_PARAMETER(UcxRootHub);
__try {
rootHubData = RootHubGetData(UcxRootHub);
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
urb = (PURB)wdfRequestParams.Parameters.Others.Arg1;
setupPacket = (PWDF_USB_CONTROL_SETUP_PACKET)&urb->UrbControlTransferEx.SetupPacket[0];
//
// USB Specification 2.0, 11.24.2.1 Clear Hub Feature
// USB Specification 3.0, 10.14.2.1 Clear Hub Feature
//
featureSelector = setupPacket->Packet.wValue.Value;
if ((setupPacket->Packet.bm.Byte != 0x20) ||
(setupPacket->Packet.bRequest != USB_REQUEST_CLEAR_FEATURE) ||
(setupPacket->Packet.wIndex.Value != 0) ||
(setupPacket->Packet.wLength != 0)) {
urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
status = STATUS_UNSUCCESSFUL;
return;
}
switch (featureSelector) {
case C_HUB_LOCAL_POWER:
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case C_HUB_OVER_CURRENT:
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
default:
urb->UrbHeader.Status = USBD_STATUS_INVALID_PARAMETER;
status = STATUS_UNSUCCESSFUL;
return;
}
} __finally {
NT_ASSERT(status == STATUS_SUCCESS);
WdfRequestComplete(WdfRequest, status);
}
return;
}
VOID
RootHub_UcxEvtClearPortFeature(
UCXROOTHUB UcxRootHub,
WDFREQUEST WdfRequest
)
/*++
Routine Description:
Arguments:
UcxRootHub - The UCX root hub object.
WdfRequest - The WDF request object for the Clear Port Feature request.
Return Value:
None directly from this routine.
The request completion status in the WdfRequest and the USBD_STATUS
in the urb header.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PROOTHUB_DATA rootHubData;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PURB urb;
PWDF_USB_CONTROL_SETUP_PACKET setupPacket;
ULONG portNumber;
ULONG featureSelector;
ULONG featureSpecificValue;
hprt0_data_t hprt0;
KdPrint((__FUNCTION__ ": entry\n"));
__try {
rootHubData = RootHubGetData(UcxRootHub);
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
urb = (PURB)wdfRequestParams.Parameters.Others.Arg1;
setupPacket = (PWDF_USB_CONTROL_SETUP_PACKET)&urb->UrbControlTransferEx.SetupPacket[0];
//
// USB Specification 2.0, 11.24.2.2 Clear Port Feature
// USB Specification 3.0, 10.14.2.2 Clear Port Feature
//
featureSelector = setupPacket->Packet.wValue.Value;
portNumber = setupPacket->Packet.wIndex.Bytes.LowByte;
featureSpecificValue = setupPacket->Packet.wIndex.Bytes.HiByte;
if ((setupPacket->Packet.bm.Byte != 0x23) ||
(setupPacket->Packet.bRequest != USB_REQUEST_CLEAR_FEATURE) ||
(portNumber == 0) ||
(portNumber > 1) ||
(setupPacket->Packet.wLength != 0)) {
urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
status = STATUS_UNSUCCESSFUL;
return;
}
//
// The most significant byte of wIndex is zero, except when
// the feature selector is PORT_INDICATOR.
//
if ((featureSelector != PORT_INDICATOR) &&
(featureSpecificValue != 0)) {
urb->UrbHeader.Status = USBD_STATUS_INVALID_PARAMETER;
status = STATUS_UNSUCCESSFUL;
return;
}
switch (featureSelector) {
case PORT_ENABLE:
//
// Clearing the PORT_ENABLE feature causes the port
// to be placed in the Disabled state.
//
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 1;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
//hprt0.b.prtena = 1;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_SUSPEND:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
hprt0.b.prtres = 1;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
//
// Software shall ensure that resume is signaled for at
// least 20 ms (TDRSMDN). Software shall start timing
// TDRSMDN from the write of '15' (Resume) to PLS.
// After TDRSMDN is complete, software shall write a '0'
// (U0) to the PLS field.
//
ExSetTimer(rootHubData->ExTimerResumeComplete,
WDF_REL_TIMEOUT_IN_MS(150),
0,
NULL);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_OVER_CURRENT:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
hprt0.b.prtovrcurract = 0;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_POWER:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
hprt0.b.prtpwr = 0;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_RESET:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
hprt0.b.prtrst = 0;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_INDICATOR:
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case C_PORT_CONNECTION:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 1;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case C_PORT_RESET:
rootHubData->ResetState = FALSE;
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case C_PORT_ENABLE:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtenchng = 1;
hprt0.b.prtena = 0; // prtena MUST be 0 to not instantly disable the port
hprt0.b.prtovrcurrchng = 0;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case C_PORT_SUSPEND:
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case C_PORT_OVER_CURRENT:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 1;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
default:
urb->UrbHeader.Status = USBD_STATUS_INVALID_PARAMETER;
status = STATUS_UNSUCCESSFUL;
return;
}
} __finally {
WdfRequestComplete(WdfRequest, status);
}
return;
}
VOID
RootHub_UcxEvtSetPortFeature(
UCXROOTHUB UcxRootHub,
WDFREQUEST WdfRequest
)
/*++
Routine Description:
Arguments:
UcxRootHub - The UCX root hub object.
WdfRequest - The WDF request object for the Set Port Feature request.
Return Value:
None directly from this routine.
The request completion status in the WdfRequest and the USBD_STATUS
in the urb header.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PROOTHUB_DATA rootHubData;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PURB urb;
PWDF_USB_CONTROL_SETUP_PACKET setupPacket;
ULONG portNumber;
ULONG featureSelector;
ULONG featureSpecificValue;
KdPrint((__FUNCTION__ ": entry\n"));
hprt0_data_t hprt0;
__try {
rootHubData = RootHubGetData(UcxRootHub);
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
urb = (PURB)wdfRequestParams.Parameters.Others.Arg1;
setupPacket = (PWDF_USB_CONTROL_SETUP_PACKET)&urb->UrbControlTransferEx.SetupPacket[0];
//
// USB Specification 2.0, 11.24.2.13 Set Port Feature
// USB Specification 3.0, 10.14.2.10 Set Port Feature
//
featureSelector = setupPacket->Packet.wValue.Value;
portNumber = setupPacket->Packet.wIndex.Bytes.LowByte;
featureSpecificValue = setupPacket->Packet.wIndex.Bytes.HiByte;
if ((setupPacket->Packet.bm.Byte != 0x23) ||
(setupPacket->Packet.bRequest != USB_REQUEST_SET_FEATURE) ||
(portNumber == 0) ||
(portNumber > 1) ||
(setupPacket->Packet.wLength != 0)) {
urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
status = STATUS_UNSUCCESSFUL;
return;
}
//
// The most significant byte of wIndex is zero, except when
// the feature selector is PORT_TEST or PORT_INDICATOR.
//
if ((featureSelector != PORT_TEST) && (featureSelector != PORT_INDICATOR) &&
(featureSpecificValue != 0)) {
urb->UrbHeader.Status = USBD_STATUS_INVALID_PARAMETER;
status = STATUS_UNSUCCESSFUL;
return;
}
switch (featureSelector) {
case PORT_RESET:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
hprt0.b.prtrst = 1;
_DataSynchronizationBarrier();
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
_DataSynchronizationBarrier();
rootHubData->ResetState = TRUE;
UcxRootHubPortChanged(UcxRootHub);
//
// Software shall ensure that resume is signaled for at
// least 20 ms (TDRSMDN). Software shall start timing
// TDRSMDN from the write of '15' (Resume) to PLS.
// After TDRSMDN is complete, software shall write a '0'
// (U0) to the PLS field.
//
ExSetTimer(rootHubData->ExTimerResetComplete,
WDF_REL_TIMEOUT_IN_MS(50),
0,
NULL);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_SUSPEND:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
hprt0.b.prtsusp = 1;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_POWER:
hprt0.d32 = READ_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0);
hprt0.b.prtconndet = 0;
hprt0.b.prtena = 0;
hprt0.b.prtenchng = 0;
hprt0.b.prtovrcurrchng = 0;
hprt0.b.prtovrcurract = 0;
hprt0.b.prtpwr = 1;
WRITE_REGISTER_ULONG((volatile ULONG*)rootHubData->Hprt0, (ULONG)hprt0.d32);
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_TEST:
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
case PORT_INDICATOR:
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
break;
default:
KdPrint(("Unknown port feature %d\n", featureSelector));
urb->UrbHeader.Status = USBD_STATUS_INVALID_PARAMETER;
status = STATUS_UNSUCCESSFUL;
return;
}
} __finally {
WdfRequestComplete(WdfRequest, status);
}
return;
}
VOID
RootHub_UcxEvtGetPortErrorCount(
UCXROOTHUB UcxRootHub,
WDFREQUEST WdfRequest
)
/*++
Routine Description:
Arguments:
UcxRootHub - The UCX root hub object.
WdfRequest - The WDF request object for the Get Port Error Count request.
Return Value:
None directly from this routine.
The request completion status in the WdfRequest and the USBD_STATUS
in the urb header.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PROOTHUB_DATA rootHubData;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PURB urb;
PWDF_USB_CONTROL_SETUP_PACKET setupPacket;
ULONG portNumber;
KdPrint((__FUNCTION__ ": entry\n"));
__try {
rootHubData = RootHubGetData(UcxRootHub);
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
urb = (PURB)wdfRequestParams.Parameters.Others.Arg1;
setupPacket = (PWDF_USB_CONTROL_SETUP_PACKET)&urb->UrbControlTransferEx.SetupPacket[0];
//
// USB Specification 3.0, 10.14.2.5 Get Port Error Count
// See also: Q1'09 USB 3.0 Errata (Released 05/15/2009)
// Correction: bmRequestype must be 10100011B
//
portNumber = setupPacket->Packet.wIndex.Value;
if ((setupPacket->Packet.bm.Byte != 0xA3) ||
(setupPacket->Packet.bRequest != USB_REQUEST_GET_PORT_ERR_COUNT) ||
(setupPacket->Packet.wValue.Value != 0) ||
(portNumber == 0) ||
(portNumber > 1) ||
(setupPacket->Packet.wLength != 2)) {
urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
status = STATUS_UNSUCCESSFUL;
return;
}
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
*((PUSHORT)urb->UrbControlTransferEx.TransferBuffer) = 0;
} __finally {
NT_ASSERT(status == STATUS_SUCCESS);
WdfRequestComplete(WdfRequest, status);
}
return;
}
VOID
RootHub_UcxEvtSetHubFeature(
UCXROOTHUB UcxRootHub,
WDFREQUEST WdfRequest
)
/*++
Routine Description:
Arguments:
UcxRootHub - The UCX root hub object.
WdfRequest - The WDF request object for the Set Hub Feature request.
Return Value:
None directly from this routine.
The request completion status in the WdfRequest and the USBD_STATUS
in the urb header.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
WDF_REQUEST_PARAMETERS wdfRequestParams;
PURB urb;
UNREFERENCED_PARAMETER(UcxRootHub);
KdPrint((__FUNCTION__ ": entry\n"));
__try {
WDF_REQUEST_PARAMETERS_INIT(&wdfRequestParams);
WdfRequestGetParameters(WdfRequest, &wdfRequestParams);
urb = (PURB)wdfRequestParams.Parameters.Others.Arg1;
//
// USB Specification 2.0, 11.24.2.6 Get Hub Status
// USB Specification 3.0, 10.14.2.4 Get Hub Status
//
// "Hubs may allow setting of these change bits with
// SetHubFeature() requests in order to support diagnostics. If
// the hub does not support setting of these bits, it should
// either treat the SetHubFeature() request as a Request Error
// or as a functional no-operation."
//
urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
status = STATUS_SUCCESS;
} __finally {