[81dce9f] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
---|
[e0a5d4c] | 3 | * Copyright (c) 2018 Ondrej Hlavaty
|
---|
[81dce9f] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
[77ad86c] | 29 |
|
---|
[160b75e] | 30 | /** @addtogroup libusbhost
|
---|
[81dce9f] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
[c92c13f] | 34 | * USB transfer transaction structures.
|
---|
[81dce9f] | 35 | */
|
---|
[77ad86c] | 36 |
|
---|
[f58ef61] | 37 | #ifndef LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
|
---|
| 38 | #define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
|
---|
[81dce9f] | 39 |
|
---|
[17873ac7] | 40 | #include <errno.h>
|
---|
[498ced1] | 41 | #include <refcount.h>
|
---|
[64fea02] | 42 | #include <stddef.h>
|
---|
[8d2dd7f2] | 43 | #include <stdint.h>
|
---|
[c21e6a5] | 44 | #include <usb/dma_buffer.h>
|
---|
[64fea02] | 45 | #include <usb/request.h>
|
---|
| 46 | #include <usb/usb.h>
|
---|
| 47 | #include <usbhc_iface.h>
|
---|
| 48 |
|
---|
| 49 | #include <usb/host/hcd.h>
|
---|
| 50 | #include <usb/host/endpoint.h>
|
---|
| 51 | #include <usb/host/bus.h>
|
---|
[81dce9f] | 52 |
|
---|
[5fd9c30] | 53 | typedef struct endpoint endpoint_t;
|
---|
| 54 | typedef struct bus bus_t;
|
---|
| 55 |
|
---|
[db2cb04] | 56 | /** Structure stores additional data needed for communication with EP */
|
---|
[549ff23] | 57 | typedef struct usb_transfer_batch {
|
---|
[a5b3de6] | 58 | /** Target for communication */
|
---|
| 59 | usb_target_t target;
|
---|
[5fd9c30] | 60 | /** Direction of the transfer */
|
---|
| 61 | usb_direction_t dir;
|
---|
| 62 |
|
---|
[c21e6a5] | 63 | /** Endpoint used for communication */
|
---|
| 64 | endpoint_t *ep;
|
---|
[5fd9c30] | 65 |
|
---|
| 66 | /** Place to store SETUP data needed by control transfers */
|
---|
| 67 | union {
|
---|
| 68 | char buffer [USB_SETUP_PACKET_SIZE];
|
---|
| 69 | usb_device_request_setup_packet_t packet;
|
---|
| 70 | uint64_t packed;
|
---|
| 71 | } setup;
|
---|
| 72 |
|
---|
[1d758fc] | 73 | /** DMA buffer with enforced policy */
|
---|
| 74 | dma_buffer_t dma_buffer;
|
---|
| 75 | /** Size of memory buffer */
|
---|
| 76 | size_t offset, size;
|
---|
| 77 |
|
---|
[c21e6a5] | 78 | /**
|
---|
[2f762a7] | 79 | * In case a bounce buffer is allocated, the original buffer must to be
|
---|
[c21e6a5] | 80 | * stored to be filled after the IN transaction is finished.
|
---|
| 81 | */
|
---|
[1d758fc] | 82 | char *original_buffer;
|
---|
[2f762a7] | 83 | bool is_bounced;
|
---|
[17873ac7] | 84 |
|
---|
[5fd9c30] | 85 | /** Indicates success/failure of the communication */
|
---|
[5a6cc679] | 86 | errno_t error;
|
---|
[c21e6a5] | 87 | /** Actually used portion of the buffer */
|
---|
| 88 | size_t transferred_size;
|
---|
| 89 |
|
---|
| 90 | /** Function called on completion */
|
---|
| 91 | usbhc_iface_transfer_callback_t on_complete;
|
---|
| 92 | /** Arbitrary data for the handler */
|
---|
| 93 | void *on_complete_data;
|
---|
[549ff23] | 94 | } usb_transfer_batch_t;
|
---|
[81dce9f] | 95 |
|
---|
[64fea02] | 96 | /**
|
---|
| 97 | * Printf formatting string for dumping usb_transfer_batch_t.
|
---|
| 98 | * [address:endpoint speed transfer_type-direction buffer_sizeB/max_packet_size]
|
---|
[7c3fb9b] | 99 | */
|
---|
[c4fb5ecd] | 100 | #define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
|
---|
| 101 |
|
---|
| 102 | /** Printf arguments for dumping usb_transfer_batch_t.
|
---|
| 103 | * @param batch USB transfer batch to be dumped.
|
---|
| 104 | */
|
---|
| 105 | #define USB_TRANSFER_BATCH_ARGS(batch) \
|
---|
[64fea02] | 106 | ((batch).ep->device->address), ((batch).ep->endpoint), \
|
---|
[888238e9] | 107 | usb_str_speed((batch).ep->device->speed), \
|
---|
[c4fb5ecd] | 108 | usb_str_transfer_type_short((batch).ep->transfer_type), \
|
---|
[64fea02] | 109 | usb_str_direction((batch).dir), \
|
---|
[1d758fc] | 110 | (batch).size, (batch).ep->max_packet_size
|
---|
[c4fb5ecd] | 111 |
|
---|
[17873ac7] | 112 | /** Wrapper for bus operation. */
|
---|
| 113 | usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *);
|
---|
| 114 |
|
---|
| 115 | /** Batch initializer. */
|
---|
[5fd9c30] | 116 | void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *);
|
---|
[17873ac7] | 117 |
|
---|
[1d758fc] | 118 | /** Buffer handling */
|
---|
| 119 | bool usb_transfer_batch_bounce_required(usb_transfer_batch_t *);
|
---|
[2f762a7] | 120 | errno_t usb_transfer_batch_bounce(usb_transfer_batch_t *);
|
---|
[c21e6a5] | 121 |
|
---|
[17873ac7] | 122 | /** Batch finalization. */
|
---|
[5fd9c30] | 123 | void usb_transfer_batch_finish(usb_transfer_batch_t *);
|
---|
[c4fb5ecd] | 124 |
|
---|
[17873ac7] | 125 | /** To be called from outside only when the transfer is not going to be finished
|
---|
| 126 | * (i.o.w. until successfuly scheduling)
|
---|
| 127 | */
|
---|
[5fd9c30] | 128 | void usb_transfer_batch_destroy(usb_transfer_batch_t *);
|
---|
[81dce9f] | 129 |
|
---|
| 130 | #endif
|
---|
[77ad86c] | 131 |
|
---|
[81dce9f] | 132 | /**
|
---|
| 133 | * @}
|
---|
| 134 | */
|
---|