source: mainline/uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.h@ 8064c2f6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8064c2f6 was 8064c2f6, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

uhci: Sanitize headers.

Include what you use.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup drvusbuhcihc
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
34#ifndef DRV_UHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
35#define DRV_UHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
36
37#include <assert.h>
38#include <usb/usb.h>
39#include <stdbool.h>
40#include <sys/types.h>
41
42#include "link_pointer.h"
43
44/** Transfer Descriptor, defined in UHCI design guide p. 26 */
45typedef struct transfer_descriptor {
46 /** Pointer to the next entity (TD or QH) */
47 link_pointer_t next;
48
49 /** Status doubleword */
50 volatile uint32_t status;
51#define TD_STATUS_RESERVED_MASK 0xc000f800
52#define TD_STATUS_SPD_FLAG (1 << 29)
53#define TD_STATUS_ERROR_COUNT_POS 27
54#define TD_STATUS_ERROR_COUNT_MASK 0x3
55#define TD_STATUS_LOW_SPEED_FLAG (1 << 26)
56#define TD_STATUS_ISOCHRONOUS_FLAG (1 << 25)
57#define TD_STATUS_IOC_FLAG (1 << 24)
58
59#define TD_STATUS_ERROR_ACTIVE (1 << 23)
60#define TD_STATUS_ERROR_STALLED (1 << 22)
61#define TD_STATUS_ERROR_BUFFER (1 << 21)
62#define TD_STATUS_ERROR_BABBLE (1 << 20)
63#define TD_STATUS_ERROR_NAK (1 << 19)
64#define TD_STATUS_ERROR_CRC (1 << 18)
65#define TD_STATUS_ERROR_BIT_STUFF (1 << 17)
66#define TD_STATUS_ERROR_RESERVED (1 << 16)
67#define TD_STATUS_ERROR_POS 16
68#define TD_STATUS_ERROR_MASK 0xff
69
70#define TD_STATUS_ACTLEN_POS 0
71#define TD_STATUS_ACTLEN_MASK 0x7ff
72
73 /** Double word with USB device specific info */
74 volatile uint32_t device;
75#define TD_DEVICE_MAXLEN_POS 21
76#define TD_DEVICE_MAXLEN_MASK 0x7ff
77#define TD_DEVICE_RESERVED_FLAG (1 << 20)
78#define TD_DEVICE_DATA_TOGGLE_ONE_FLAG (1 << 19)
79#define TD_DEVICE_ENDPOINT_POS 15
80#define TD_DEVICE_ENDPOINT_MASK 0xf
81#define TD_DEVICE_ADDRESS_POS 8
82#define TD_DEVICE_ADDRESS_MASK 0x7f
83#define TD_DEVICE_PID_POS 0
84#define TD_DEVICE_PID_MASK 0xff
85
86 /** Pointer(physical) to the beginning of the transaction's buffer */
87 volatile uint32_t buffer_ptr;
88
89 /* According to UHCI design guide, there is 16 bytes of
90 * data available here.
91 * According to Linux kernel the hardware does not care,
92 * memory just needs to be aligned. We don't use it anyway.
93 */
94} __attribute__((packed)) td_t;
95
96
97void td_init(td_t *instance, int error_count, size_t size, bool toggle,
98 bool iso, bool low_speed, usb_target_t target, usb_packet_id pid,
99 const void *buffer, const td_t *next);
100
101int td_status(const td_t *instance);
102
103void td_print_status(const td_t *instance);
104
105/** Helper function for parsing actual size out of TD.
106 *
107 * @param[in] instance TD structure to use.
108 * @return Parsed actual size.
109 */
110static inline size_t td_act_size(const td_t *instance)
111{
112 assert(instance);
113 const uint32_t s = instance->status;
114 /* Actual size is encoded as n-1 (UHCI design guide p. 23) */
115 return ((s >> TD_STATUS_ACTLEN_POS) + 1) & TD_STATUS_ACTLEN_MASK;
116}
117
118/** Check whether less than max data were received on SPD marked transfer.
119 *
120 * @param[in] instance TD structure to use.
121 * @return True if data packet is short (less than max bytes and SPD set),
122 * false otherwise.
123 */
124static inline bool td_is_short(const td_t *instance)
125{
126 const size_t act_size = td_act_size(instance);
127 const size_t max_size =
128 ((instance->device >> TD_DEVICE_MAXLEN_POS) + 1)
129 & TD_DEVICE_MAXLEN_MASK;
130 return
131 (instance->status | TD_STATUS_SPD_FLAG) && act_size < max_size;
132}
133
134/** Helper function for parsing value of toggle bit.
135 *
136 * @param[in] instance TD structure to use.
137 * @return Toggle bit value.
138 */
139static inline int td_toggle(const td_t *instance)
140{
141 assert(instance);
142 return (instance->device & TD_DEVICE_DATA_TOGGLE_ONE_FLAG) ? 1 : 0;
143}
144
145/** Helper function for parsing value of active bit
146 *
147 * @param[in] instance TD structure to use.
148 * @return Active bit value.
149 */
150static inline bool td_is_active(const td_t *instance)
151{
152 assert(instance);
153 return (instance->status & TD_STATUS_ERROR_ACTIVE) != 0;
154}
155
156/** Helper function for setting IOC bit.
157 *
158 * @param[in] instance TD structure to use.
159 */
160static inline void td_set_ioc(td_t *instance)
161{
162 assert(instance);
163 instance->status |= TD_STATUS_IOC_FLAG;
164}
165
166#endif
167/**
168 * @}
169 */
Note: See TracBrowser for help on using the repository browser.