source: mainline/uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h

Last change on this file was 498ced1, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Unify reference counting and remove some unnecessary instances of <atomic.h>

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * Copyright (c) 2018 Ondrej Hlavaty
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 */
29
30/** @addtogroup libusbhost
31 * @{
32 */
33/** @file
34 * USB transfer transaction structures.
35 */
36
37#ifndef LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
38#define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
39
40#include <errno.h>
41#include <refcount.h>
42#include <stddef.h>
43#include <stdint.h>
44#include <usb/dma_buffer.h>
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>
52
53typedef struct endpoint endpoint_t;
54typedef struct bus bus_t;
55
56/** Structure stores additional data needed for communication with EP */
57typedef struct usb_transfer_batch {
58 /** Target for communication */
59 usb_target_t target;
60 /** Direction of the transfer */
61 usb_direction_t dir;
62
63 /** Endpoint used for communication */
64 endpoint_t *ep;
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
73 /** DMA buffer with enforced policy */
74 dma_buffer_t dma_buffer;
75 /** Size of memory buffer */
76 size_t offset, size;
77
78 /**
79 * In case a bounce buffer is allocated, the original buffer must to be
80 * stored to be filled after the IN transaction is finished.
81 */
82 char *original_buffer;
83 bool is_bounced;
84
85 /** Indicates success/failure of the communication */
86 errno_t error;
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;
94} usb_transfer_batch_t;
95
96/**
97 * Printf formatting string for dumping usb_transfer_batch_t.
98 * [address:endpoint speed transfer_type-direction buffer_sizeB/max_packet_size]
99 */
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) \
106 ((batch).ep->device->address), ((batch).ep->endpoint), \
107 usb_str_speed((batch).ep->device->speed), \
108 usb_str_transfer_type_short((batch).ep->transfer_type), \
109 usb_str_direction((batch).dir), \
110 (batch).size, (batch).ep->max_packet_size
111
112/** Wrapper for bus operation. */
113usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *);
114
115/** Batch initializer. */
116void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *);
117
118/** Buffer handling */
119bool usb_transfer_batch_bounce_required(usb_transfer_batch_t *);
120errno_t usb_transfer_batch_bounce(usb_transfer_batch_t *);
121
122/** Batch finalization. */
123void usb_transfer_batch_finish(usb_transfer_batch_t *);
124
125/** To be called from outside only when the transfer is not going to be finished
126 * (i.o.w. until successfuly scheduling)
127 */
128void usb_transfer_batch_destroy(usb_transfer_batch_t *);
129
130#endif
131
132/**
133 * @}
134 */
Note: See TracBrowser for help on using the repository browser.