2 * Copyright (c) 2007 Atheros Communications Inc.
5 * $ATH_LICENSE_HOSTSDK0_C$
14 #include "athstartpack.h"
17 #define A_OFFSETOF(type,field) (int)(&(((type *)NULL)->field))
19 #define ASSEMBLE_UNALIGNED_UINT16(p,highbyte,lowbyte) \
20 (((A_UINT16)(((A_UINT8 *)(p))[(highbyte)])) << 8 | (A_UINT16)(((A_UINT8 *)(p))[(lowbyte)]))
22 /* alignment independent macros (little-endian) to fetch UINT16s or UINT8s from a
23 * structure using only the type and field name.
24 * Use these macros if there is the potential for unaligned buffer accesses. */
25 #define A_GET_UINT16_FIELD(p,type,field) \
26 ASSEMBLE_UNALIGNED_UINT16(p,\
27 A_OFFSETOF(type,field) + 1, \
28 A_OFFSETOF(type,field))
30 #define A_SET_UINT16_FIELD(p,type,field,value) \
32 ((A_UINT8 *)(p))[A_OFFSETOF(type,field)] = (A_UINT8)(value); \
33 ((A_UINT8 *)(p))[A_OFFSETOF(type,field) + 1] = (A_UINT8)((value) >> 8); \
36 #define A_GET_UINT8_FIELD(p,type,field) \
37 ((A_UINT8 *)(p))[A_OFFSETOF(type,field)]
39 #define A_SET_UINT8_FIELD(p,type,field,value) \
40 ((A_UINT8 *)(p))[A_OFFSETOF(type,field)] = (value)
42 /****** DANGER DANGER ***************
44 * The frame header length and message formats defined herein were
45 * selected to accommodate optimal alignment for target processing. This reduces code
46 * size and improves performance.
48 * Any changes to the header length may alter the alignment and cause exceptions
49 * on the target. When adding to the message structures insure that fields are
54 /* HTC frame header */
55 typedef PREPACK
struct _HTC_FRAME_HDR
{
56 /* do not remove or re-arrange these fields, these are minimally required
57 * to take advantage of 4-byte lookaheads in some hardware implementations */
60 A_UINT16 PayloadLen
; /* length of data (including trailer) that follows the header */
62 /***** end of 4-byte lookahead ****/
64 A_UINT8 ControlBytes
[2];
66 /* message payload starts after the header */
68 } POSTPACK HTC_FRAME_HDR
;
70 /* frame header flags */
71 #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
72 #define HTC_FLAGS_RECV_TRAILER (1 << 1)
75 #define HTC_HDR_LENGTH (sizeof(HTC_FRAME_HDR))
76 #define HTC_MAX_TRAILER_LENGTH 255
77 #define HTC_MAX_PAYLOAD_LENGTH (2048 - sizeof(HTC_FRAME_HDR))
79 /* HTC control message IDs */
82 HTC_MSG_CONNECT_SERVICE_ID
= 2,
83 HTC_MSG_CONNECT_SERVICE_RESPONSE_ID
= 3,
84 HTC_MSG_SETUP_COMPLETE_ID
= 4,
87 #define HTC_MAX_CONTROL_MESSAGE_LENGTH 256
89 /* base message ID header */
90 typedef PREPACK
struct {
92 } POSTPACK HTC_UNKNOWN_MSG
;
95 * direction : target-to-host */
96 typedef PREPACK
struct {
97 A_UINT16 MessageID
; /* ID */
98 A_UINT16 CreditCount
; /* number of credits the target can offer */
99 A_UINT16 CreditSize
; /* size of each credit */
100 A_UINT8 MaxEndpoints
; /* maximum number of endpoints the target has resources for */
102 } POSTPACK HTC_READY_MSG
;
104 #define HTC_SERVICE_META_DATA_MAX_LENGTH 128
107 * direction : host-to-target */
108 typedef PREPACK
struct {
110 A_UINT16 ServiceID
; /* service ID of the service to connect to */
111 A_UINT16 ConnectionFlags
; /* connection flags */
113 #define HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE (1 << 2) /* reduce credit dribbling when
114 the host needs credits */
115 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK (0x3)
116 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH 0x0
117 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF 0x1
118 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS 0x2
119 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_UNITY 0x3
121 A_UINT8 ServiceMetaLength
; /* length of meta data that follows */
124 /* service-specific meta data starts after the header */
126 } POSTPACK HTC_CONNECT_SERVICE_MSG
;
129 * direction : target-to-host */
130 typedef PREPACK
struct {
132 A_UINT16 ServiceID
; /* service ID that the connection request was made */
133 A_UINT8 Status
; /* service connection status */
134 A_UINT8 EndpointID
; /* assigned endpoint ID */
135 A_UINT16 MaxMsgSize
; /* maximum expected message size on this endpoint */
136 A_UINT8 ServiceMetaLength
; /* length of meta data that follows */
139 /* service-specific meta data starts after the header */
141 } POSTPACK HTC_CONNECT_SERVICE_RESPONSE_MSG
;
143 typedef PREPACK
struct {
145 /* currently, no other fields */
146 } POSTPACK HTC_SETUP_COMPLETE_MSG
;
149 /* connect response status codes */
150 #define HTC_SERVICE_SUCCESS 0 /* success */
151 #define HTC_SERVICE_NOT_FOUND 1 /* service could not be found */
152 #define HTC_SERVICE_FAILED 2 /* specific service failed the connect */
153 #define HTC_SERVICE_NO_RESOURCES 3 /* no resources (i.e. no more endpoints) */
154 #define HTC_SERVICE_NO_MORE_EP 4 /* specific service is not allowing any more
157 /* report record IDs */
160 HTC_RECORD_CREDITS
= 1,
161 HTC_RECORD_LOOKAHEAD
= 2,
164 typedef PREPACK
struct {
165 A_UINT8 RecordID
; /* Record ID */
166 A_UINT8 Length
; /* Length of record */
167 } POSTPACK HTC_RECORD_HDR
;
169 typedef PREPACK
struct {
170 A_UINT8 EndpointID
; /* Endpoint that owns these credits */
171 A_UINT8 Credits
; /* credits to report since last report */
172 } POSTPACK HTC_CREDIT_REPORT
;
174 typedef PREPACK
struct {
175 A_UINT8 PreValid
; /* pre valid guard */
176 A_UINT8 LookAhead
[4]; /* 4 byte lookahead */
177 A_UINT8 PostValid
; /* post valid guard */
179 /* NOTE: the LookAhead array is guarded by a PreValid and Post Valid guard bytes.
180 * The PreValid bytes must equal the inverse of the PostValid byte */
182 } POSTPACK HTC_LOOKAHEAD_REPORT
;
185 #include "athendpack.h"
189 #endif /* __HTC_H__ */