2 * Copyright (c) 2007 Atheros Communications Inc.
12 #define A_OFFSETOF(type,field) ((int)(&(((type *)NULL)->field)))
14 #define ASSEMBLE_UNALIGNED_UINT16(p,highbyte,lowbyte) \
15 (((a_uint16_t)(((a_uint8_t *)(p))[(highbyte)])) << 8 | (a_uint16_t)(((a_uint8_t *)(p))[(lowbyte)]))
17 /* alignment independent macros (little-endian) to fetch UINT16s or UINT8s from a
18 * structure using only the type and field name.
19 * Use these macros if there is the potential for unaligned buffer accesses. */
20 #define A_GET_UINT16_FIELD(p,type,field) \
21 ASSEMBLE_UNALIGNED_UINT16(p, \
22 A_OFFSETOF(type,field) + 1, \
23 A_OFFSETOF(type,field))
25 #define A_SET_UINT16_FIELD(p,type,field,value) \
27 ((a_uint8_t *)(p))[A_OFFSETOF(type,field)] = (a_uint8_t)((value) >> 8); \
28 ((a_uint8_t *)(p))[A_OFFSETOF(type,field) + 1] = (a_uint8_t)(value); \
31 #define A_GET_UINT8_FIELD(p,type,field) \
32 ((a_uint8_t *)(p))[A_OFFSETOF(type,field)]
34 #define A_SET_UINT8_FIELD(p,type,field,value) \
35 ((a_uint8_t *)(p))[A_OFFSETOF(type,field)] = (value)
37 /****** DANGER DANGER ***************
39 * The frame header length and message formats defined herein were
40 * selected to accommodate optimal alignment for target processing. This reduces code
41 * size and improves performance.
43 * Any changes to the header length may alter the alignment and cause exceptions
44 * on the target. When adding to the message structures insure that fields are
49 /* endpoint defines */
53 ENDPOINT0 = 0, /* this is reserved for the control endpoint */
62 ENDPOINT_MAX = 22 /* maximum number of endpoints for this firmware build, max application
63 endpoints = (ENDPOINT_MAX - 1) */
66 /* HTC frame header */
67 typedef PREPACK struct _HTC_FRAME_HDR{
68 /* do not remove or re-arrange these fields, these are minimally required
69 * to take advantage of 4-byte lookaheads in some hardware implementations */
72 a_uint16_t PayloadLen; /* length of data (including trailer) that follows the header */
74 /***** end of 4-byte lookahead ****/
76 a_uint8_t ControlBytes[4];
78 /* message payload starts after the header */
80 } POSTPACK HTC_FRAME_HDR;
82 /* frame header flags */
83 #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
84 #define HTC_FLAGS_RECV_TRAILER (1 << 1)
85 #define HTC_FLAGS_CREDIT_REDISTRIBUTION (1 << 2)
87 #define HTC_HDR_LENGTH (sizeof(HTC_FRAME_HDR))
88 #define HTC_MAX_TRAILER_LENGTH 255
89 #define HTC_MAX_PAYLOAD_LENGTH (2048 - sizeof(HTC_FRAME_HDR))
91 /* HTC control message IDs */
94 HTC_MSG_CONNECT_SERVICE_ID = 2,
95 HTC_MSG_CONNECT_SERVICE_RESPONSE_ID = 3,
96 HTC_MSG_SETUP_COMPLETE_ID = 4,
97 HTC_MSG_CONFIG_PIPE_ID = 5,
98 HTC_MSG_CONFIG_PIPE_RESPONSE_ID = 6,
101 #define HTC_MAX_CONTROL_MESSAGE_LENGTH 256
103 /* base message ID header */
104 typedef PREPACK struct {
105 a_uint16_t MessageID;
106 } POSTPACK HTC_UNKNOWN_MSG;
109 * direction : target-to-host */
110 typedef PREPACK struct {
111 a_uint16_t MessageID; /* ID */
112 a_uint16_t CreditCount; /* number of credits the target can offer */
113 a_uint16_t CreditSize; /* size of each credit */
114 a_uint8_t MaxEndpoints; /* maximum number of endpoints the target has resources for */
116 } POSTPACK HTC_READY_MSG;
118 #define HTC_SERVICE_META_DATA_MAX_LENGTH 128
121 * direction : host-to-target */
122 typedef PREPACK struct {
123 a_uint16_t MessageID;
124 a_uint16_t ServiceID; /* service ID of the service to connect to */
125 a_uint16_t ConnectionFlags; /* connection flags */
126 a_uint8_t DownLinkPipeID;
127 a_uint8_t UpLinkPipeID;
129 #define HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE (1 << 2) /* reduce credit dribbling when
130 the host needs credits */
131 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK (0x3)
132 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH 0x0
133 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF 0x1
134 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS 0x2
135 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_UNITY 0x3
137 a_uint8_t ServiceMetaLength; /* length of meta data that follows */
140 /* service-specific meta data starts after the header */
142 } POSTPACK HTC_CONNECT_SERVICE_MSG;
145 * direction : target-to-host */
146 typedef PREPACK struct {
147 a_uint16_t MessageID;
148 a_uint16_t ServiceID; /* service ID that the connection request was made */
149 a_uint8_t Status; /* service connection status */
150 a_uint8_t EndpointID; /* assigned endpoint ID */
151 a_uint16_t MaxMsgSize; /* maximum expected message size on this endpoint */
152 a_uint8_t ServiceMetaLength; /* length of meta data that follows */
155 /* service-specific meta data starts after the header */
157 } POSTPACK HTC_CONNECT_SERVICE_RESPONSE_MSG;
159 typedef PREPACK struct {
160 a_uint16_t MessageID;
161 /* currently, no other fields */
162 } POSTPACK HTC_SETUP_COMPLETE_MSG;
165 * direction : host-to-target */
166 typedef PREPACK struct {
167 a_uint16_t MessageID;
168 a_uint8_t PipeID; /* Pipe ID of the service to connect to */
169 a_uint8_t CreditCount; /* CreditCount */
171 } POSTPACK HTC_CONFIG_PIPE_MSG;
174 * direction : host-to-target */
175 typedef PREPACK struct {
176 a_uint16_t MessageID;
177 a_uint8_t PipeID; /* Pipe ID of the service to connect to */
178 a_uint8_t Status; /* status */
180 } POSTPACK HTC_CONFIG_PIPE_RESPONSE_MSG;
182 /* connect response status codes */
183 #define HTC_SERVICE_SUCCESS 0 /* success */
184 #define HTC_SERVICE_NOT_FOUND 1 /* service could not be found */
185 #define HTC_SERVICE_FAILED 2 /* specific service failed the connect */
186 #define HTC_SERVICE_NO_RESOURCES 3 /* no resources (i.e. no more endpoints) */
187 #define HTC_SERVICE_NO_MORE_EP 4 /* specific service is not allowing any more
190 /* shihhung: config pipe response status code */
191 #define HTC_CONFIGPIPE_SUCCESS 0
192 #define HTC_CONFIGPIPE_NOSUCHPIPE 1
193 #define HTC_CONFIGPIPE_NORESOURCE 2
195 /* report record IDs */
198 HTC_RECORD_CREDITS = 1,
199 HTC_RECORD_LOOKAHEAD = 2,
202 typedef PREPACK struct {
203 a_uint8_t RecordID; /* Record ID */
204 a_uint8_t Length; /* Length of record */
205 } POSTPACK HTC_RECORD_HDR;
207 typedef PREPACK struct {
208 a_uint8_t EndpointID; /* Endpoint that owns these credits */
209 a_uint8_t Credits; /* credits to report since last report */
210 } POSTPACK HTC_CREDIT_REPORT;
212 typedef PREPACK struct {
213 a_uint8_t PreValid; /* pre valid guard */
214 a_uint8_t LookAhead[4]; /* 4 byte lookahead */
215 a_uint8_t PostValid; /* post valid guard */
217 /* NOTE: the LookAhead array is guarded by a PreValid and Post Valid guard bytes.
218 * The PreValid bytes must equal the inverse of the PostValid byte */
220 } POSTPACK HTC_LOOKAHEAD_REPORT;
223 //#include "athendpack.h"
226 #endif /* __HTC_H__ */