1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5library ddk.protocol.usb.request;
6
7using ddk.physiter;
8using zircon.hw.usb;
9using zx;
10
11/// Should be set by the requestor.
12struct UsbHeader {
13    /// Frame number for scheduling isochronous transfers.
14    uint64 frame;
15    uint32 device_id;
16    /// bEndpointAddress from endpoint descriptor.
17    uint8 ep_address;
18    /// Number of bytes to transfer.
19    zx.off length;
20    /// Send zero length packet if length is multiple of max packet size.
21    bool send_zlp;
22};
23
24/// Response data.
25/// (Filled in by processor before |UsbRequestComplete()| is called)
26struct UsbResponse {
27    /// Status of transaction.
28    zx.status status;
29    /// Number of bytes actually transferred (on success).
30    zx.off actual;
31};
32
33struct UsbRequest {
34    UsbHeader header;
35
36    /// For control transactions.
37    zircon.hw.usb.UsbSetup setup;
38
39    /// VMO handle for payload.
40    handle<vmo> vmo_handle;
41    usize size;
42    /// Offset of the start of data from first page address of the vmo.
43    zx.off offset;
44    /// Mapped address of the first page of the vmo.
45    /// Add offset to get actual data.
46    uint64 virt;
47
48    handle pmt;
49    /// Phys addresses of the payload.
50    vector<zx.paddr>? phys;
51
52    vector<ddk.physiter.PhysIterSgEntry>? sg;
53
54    UsbResponse response;
55
56    /// usb_request_release() frees the request if this is true.
57    bool release_frees;
58
59    usize alloc_size;
60
61    /// For requests queued on endpoints which have batching enabled via
62    /// usb_configure_batch_callback().
63    /// Set by the requester if a callback is required on this request's completion.
64    /// This is useful for isochronous requests, where the requester does not care about
65    /// most callbacks.
66    /// The requester should ensure the last request has this set to true.
67    bool require_batch_cb;
68};
69
70[Layout="ddk-callback"]
71interface UsbRequestComplete {
72    Callback(UsbRequest? req) -> ();
73};
74