Bewerken

Delen via


WdfUsbTargetDeviceFormatRequestForCyclePort function (wdfusb.h)

[Applies to KMDF only]

The WdfUsbTargetDeviceFormatRequestForCyclePort method builds a power-cycle request for the port to which a specified device is attached, but it does not send the request.

Syntax

NTSTATUS WdfUsbTargetDeviceFormatRequestForCyclePort(
  [in] WDFUSBDEVICE UsbDevice,
  [in] WDFREQUEST   Request
);

Parameters

[in] UsbDevice

A handle to a USB device object that was obtained from a previous call to WdfUsbTargetDeviceCreateWithParameters.

[in] Request

A handle to a framework request object. For more information, see the following Remarks section.

Return value

WdfUsbTargetDeviceFormatRequestForCyclePort returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method can return one of the following values:

Return code Description
STATUS_INVALID_DEVICE_STATE
The device's USB device was unavailable.
STATUS_INSUFFICIENT_RESOURCES
Insufficient memory was available.
 

This method also might return other NTSTATUS values.

A bug check occurs if the driver supplies an invalid object handle.

Remarks

Use WdfUsbTargetDeviceFormatRequestForCyclePort, followed by WdfRequestSend, to send a power-cycle request either synchronously or asynchronously. Alternatively, use the WdfUsbTargetDeviceCyclePortSynchronously method to send a request synchronously.

Before the driver calls WdfRequestSend, it must call WdfIoTargetStop and it must complete or cancel all I/O requests that it has sent to the I/O target. The driver must not send additional I/O requests to the I/O target until the cycle request completes.

You can forward an I/O request that your driver received in an I/O queue, or you can create and send a new request.

To forward an I/O request that your driver received in an I/O queue, specify the received request's handle for the WdfUsbTargetDeviceFormatRequestForCyclePort method's Request parameter.

To create a new I/O request, call WdfRequestCreate to preallocate a request object. Supply the request handle for the WdfUsbTargetDeviceFormatRequestForCyclePort method's Request parameter. You can reuse the request object by calling WdfRequestReuse. Your driver's EvtDriverDeviceAdd callback function can preallocate request objects for a device.

After calling WdfUsbTargetDeviceFormatRequestForCyclePort to format an I/O request, the driver must call WdfRequestSend to send the request (either synchronously or asynchronously) to an I/O target. This call to WdfRequestSend must be made at IRQL = PASSIVE_LEVEL.

Multiple calls to WdfUsbTargetDeviceFormatRequestForCyclePort that use the same request do not cause additional resource allocations. Therefore, to reduce the chance that WdfRequestCreate will return STATUS_INSUFFICIENT_RESOURCES, your driver's EvtDriverDeviceAdd callback function can call WdfRequestCreate to preallocate one or more request objects for a device. The driver can subsequently reuse (call WdfRequestReuse), reformat (call WdfUsbTargetDeviceFormatRequestForCyclePort), and resend (call WdfRequestSend) each request object without risking a STATUS_INSUFFICIENT_RESOURCES return value from a later call to WdfRequestCreate. All subsequent calls to WdfUsbTargetDeviceFormatRequestForCyclePort for the reused request object will return STATUS_SUCCESS, if parameter values do not change. (If the driver does not call the same request-formatting method each time, additional resources might be allocated.)

For more information about the WdfUsbTargetDeviceFormatRequestForCyclePort method and USB I/O targets, see USB I/O Targets.

Examples

The following code example formats a power-cycle request, registers a CompletionRoutine callback function, and sends the request to an I/O target.

status = WdfUsbTargetDeviceFormatRequestForCyclePort(
                                            UsbDevice,
                                            request
                                            );
if (!NT_SUCCESS(status)){
    return status;
}
WdfRequestSetCompletionRoutine(
                               request,
                               MyCompletionRoutine,
                               NULL
                               );

if (WdfRequestSend(
                   request,
                   WdfUsbTargetDeviceGetIoTarget(UsbDevice),
                   NULL
                   ) == FALSE) {
    status = WdfRequestGetStatus(request);
}

Requirements

Requirement Value
Target Platform Universal
Minimum KMDF version 1.0
Header wdfusb.h (include Wdfusb.h)
Library Wdf01000.sys (see Framework Library Versioning.)
IRQL <=DISPATCH_LEVEL
DDI compliance rules DriverCreate(kmdf), KmdfIrql(kmdf), KmdfIrql2(kmdf), KmdfIrqlExplicit(kmdf), RequestFormattedValid(kmdf), RequestSendAndForgetNoFormatting(kmdf), RequestSendAndForgetNoFormatting2(kmdf), UsbKmdfIrql(kmdf), UsbKmdfIrql2(kmdf), UsbKmdfIrqlExplicit(kmdf)

See also

EvtDriverDeviceAdd

WdfRequestReuse

WdfRequestSend

WdfUsbTargetDeviceCreateWithParameters

WdfUsbTargetDeviceCyclePortSynchronously