2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * 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
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #define A_OFFSETOF(type,field) ((int)(&(((type *)NULL)->field)))
43 #define ASSEMBLE_UNALIGNED_UINT16(p,highbyte,lowbyte) \
44 (((a_uint16_t)(((a_uint8_t *)(p))[(highbyte)])) << 8 | (a_uint16_t)(((a_uint8_t *)(p))[(lowbyte)]))
46 /* alignment independent macros (little-endian) to fetch UINT16s or UINT8s from a
47 * structure using only the type and field name.
48 * Use these macros if there is the potential for unaligned buffer accesses. */
49 #define A_GET_UINT16_FIELD(p,type,field) \
50 ASSEMBLE_UNALIGNED_UINT16(p, \
51 A_OFFSETOF(type,field) + 1, \
52 A_OFFSETOF(type,field))
54 #define A_SET_UINT16_FIELD(p,type,field,value) \
56 ((a_uint8_t *)(p))[A_OFFSETOF(type,field)] = (a_uint8_t)((value) >> 8); \
57 ((a_uint8_t *)(p))[A_OFFSETOF(type,field) + 1] = (a_uint8_t)(value); \
60 #define A_GET_UINT8_FIELD(p,type,field) \
61 ((a_uint8_t *)(p))[A_OFFSETOF(type,field)]
63 #define A_SET_UINT8_FIELD(p,type,field,value) \
64 ((a_uint8_t *)(p))[A_OFFSETOF(type,field)] = (value)
66 /****** DANGER DANGER ***************
68 * The frame header length and message formats defined herein were
69 * selected to accommodate optimal alignment for target processing. This reduces code
70 * size and improves performance.
72 * Any changes to the header length may alter the alignment and cause exceptions
73 * on the target. When adding to the message structures insure that fields are
78 /* endpoint defines */
82 ENDPOINT0 = 0, /* this is reserved for the control endpoint */
91 ENDPOINT_MAX = 22 /* maximum number of endpoints for this firmware build, max application
92 endpoints = (ENDPOINT_MAX - 1) */
95 /* HTC frame header */
96 typedef PREPACK struct _HTC_FRAME_HDR{
97 /* do not remove or re-arrange these fields, these are minimally required
98 * to take advantage of 4-byte lookaheads in some hardware implementations */
101 a_uint16_t PayloadLen; /* length of data (including trailer) that follows the header */
103 /***** end of 4-byte lookahead ****/
105 a_uint8_t ControlBytes[4];
107 /* message payload starts after the header */
109 } POSTPACK HTC_FRAME_HDR;
111 /* frame header flags */
112 #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
113 #define HTC_FLAGS_RECV_TRAILER (1 << 1)
114 #define HTC_FLAGS_CREDIT_REDISTRIBUTION (1 << 2)
116 #define HTC_HDR_LENGTH (sizeof(HTC_FRAME_HDR))
117 #define HTC_MAX_TRAILER_LENGTH 255
118 #define HTC_MAX_PAYLOAD_LENGTH (2048 - sizeof(HTC_FRAME_HDR))
120 /* HTC control message IDs */
122 HTC_MSG_READY_ID = 1,
123 HTC_MSG_CONNECT_SERVICE_ID = 2,
124 HTC_MSG_CONNECT_SERVICE_RESPONSE_ID = 3,
125 HTC_MSG_SETUP_COMPLETE_ID = 4,
126 HTC_MSG_CONFIG_PIPE_ID = 5,
127 HTC_MSG_CONFIG_PIPE_RESPONSE_ID = 6,
130 #define HTC_MAX_CONTROL_MESSAGE_LENGTH 256
132 /* base message ID header */
133 typedef PREPACK struct {
134 a_uint16_t MessageID;
135 } POSTPACK HTC_UNKNOWN_MSG;
138 * direction : target-to-host */
139 typedef PREPACK struct {
140 a_uint16_t MessageID; /* ID */
141 a_uint16_t CreditCount; /* number of credits the target can offer */
142 a_uint16_t CreditSize; /* size of each credit */
143 a_uint8_t MaxEndpoints; /* maximum number of endpoints the target has resources for */
145 } POSTPACK HTC_READY_MSG;
147 #define HTC_SERVICE_META_DATA_MAX_LENGTH 128
150 * direction : host-to-target */
151 typedef PREPACK struct {
152 a_uint16_t MessageID;
153 a_uint16_t ServiceID; /* service ID of the service to connect to */
154 a_uint16_t ConnectionFlags; /* connection flags */
155 a_uint8_t DownLinkPipeID;
156 a_uint8_t UpLinkPipeID;
158 #define HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE (1 << 2) /* reduce credit dribbling when
159 the host needs credits */
160 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK (0x3)
161 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH 0x0
162 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF 0x1
163 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS 0x2
164 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_UNITY 0x3
166 a_uint8_t ServiceMetaLength; /* length of meta data that follows */
169 /* service-specific meta data starts after the header */
171 } POSTPACK HTC_CONNECT_SERVICE_MSG;
174 * direction : target-to-host */
175 typedef PREPACK struct {
176 a_uint16_t MessageID;
177 a_uint16_t ServiceID; /* service ID that the connection request was made */
178 a_uint8_t Status; /* service connection status */
179 a_uint8_t EndpointID; /* assigned endpoint ID */
180 a_uint16_t MaxMsgSize; /* maximum expected message size on this endpoint */
181 a_uint8_t ServiceMetaLength; /* length of meta data that follows */
184 /* service-specific meta data starts after the header */
186 } POSTPACK HTC_CONNECT_SERVICE_RESPONSE_MSG;
188 typedef PREPACK struct {
189 a_uint16_t MessageID;
190 /* currently, no other fields */
191 } POSTPACK HTC_SETUP_COMPLETE_MSG;
194 * direction : host-to-target */
195 typedef PREPACK struct {
196 a_uint16_t MessageID;
197 a_uint8_t PipeID; /* Pipe ID of the service to connect to */
198 a_uint8_t CreditCount; /* CreditCount */
200 } POSTPACK HTC_CONFIG_PIPE_MSG;
203 * direction : host-to-target */
204 typedef PREPACK struct {
205 a_uint16_t MessageID;
206 a_uint8_t PipeID; /* Pipe ID of the service to connect to */
207 a_uint8_t Status; /* status */
209 } POSTPACK HTC_CONFIG_PIPE_RESPONSE_MSG;
211 /* connect response status codes */
212 #define HTC_SERVICE_SUCCESS 0 /* success */
213 #define HTC_SERVICE_NOT_FOUND 1 /* service could not be found */
214 #define HTC_SERVICE_FAILED 2 /* specific service failed the connect */
215 #define HTC_SERVICE_NO_RESOURCES 3 /* no resources (i.e. no more endpoints) */
216 #define HTC_SERVICE_NO_MORE_EP 4 /* specific service is not allowing any more
219 /* shihhung: config pipe response status code */
220 #define HTC_CONFIGPIPE_SUCCESS 0
221 #define HTC_CONFIGPIPE_NOSUCHPIPE 1
222 #define HTC_CONFIGPIPE_NORESOURCE 2
224 /* report record IDs */
227 HTC_RECORD_CREDITS = 1,
228 HTC_RECORD_LOOKAHEAD = 2,
231 typedef PREPACK struct {
232 a_uint8_t RecordID; /* Record ID */
233 a_uint8_t Length; /* Length of record */
234 } POSTPACK HTC_RECORD_HDR;
236 typedef PREPACK struct {
237 a_uint8_t EndpointID; /* Endpoint that owns these credits */
238 a_uint8_t Credits; /* credits to report since last report */
239 } POSTPACK HTC_CREDIT_REPORT;
241 typedef PREPACK struct {
242 a_uint8_t PreValid; /* pre valid guard */
243 a_uint8_t LookAhead[4]; /* 4 byte lookahead */
244 a_uint8_t PostValid; /* post valid guard */
246 /* NOTE: the LookAhead array is guarded by a PreValid and Post Valid guard bytes.
247 * The PreValid bytes must equal the inverse of the PostValid byte */
249 } POSTPACK HTC_LOOKAHEAD_REPORT;
252 //#include "athendpack.h"
255 #endif /* __HTC_H__ */