1 //------------------------------------------------------------------------------ 2 // <copyright file="htc.h" company="Atheros"> 3 // Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. 4 // 5 // 6 // Permission to use, copy, modify, and/or distribute this software for any 7 // purpose with or without fee is hereby granted, provided that the above 8 // copyright notice and this permission notice appear in all copies. 9 // 10 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 // 18 // 19 //------------------------------------------------------------------------------ 20 //============================================================================== 21 // Author(s): ="Atheros" 22 //============================================================================== 23 24 #ifndef __HTC_H__ 25 #define __HTC_H__ 26 27 #ifndef ATH_TARGET 28 #include "athstartpack.h" 29 #endif 30 31 #define A_OFFSETOF(type,field) (unsigned long)(&(((type *)NULL)->field)) 32 33 #define ASSEMBLE_UNALIGNED_UINT16(p,highbyte,lowbyte) \ 34 (((u16)(((u8 *)(p))[(highbyte)])) << 8 | (u16)(((u8 *)(p))[(lowbyte)])) 35 36 /* alignment independent macros (little-endian) to fetch UINT16s or UINT8s from a 37 * structure using only the type and field name. 38 * Use these macros if there is the potential for unaligned buffer accesses. */ 39 #define A_GET_UINT16_FIELD(p,type,field) \ 40 ASSEMBLE_UNALIGNED_UINT16(p,\ 41 A_OFFSETOF(type,field) + 1, \ 42 A_OFFSETOF(type,field)) 43 44 #define A_SET_UINT16_FIELD(p,type,field,value) \ 45 { \ 46 ((u8 *)(p))[A_OFFSETOF(type,field)] = (u8)(value); \ 47 ((u8 *)(p))[A_OFFSETOF(type,field) + 1] = (u8)((value) >> 8); \ 48 } 49 50 #define A_GET_UINT8_FIELD(p,type,field) \ 51 ((u8 *)(p))[A_OFFSETOF(type,field)] 52 53 #define A_SET_UINT8_FIELD(p,type,field,value) \ 54 ((u8 *)(p))[A_OFFSETOF(type,field)] = (value) 55 56 /****** DANGER DANGER *************** 57 * 58 * The frame header length and message formats defined herein were 59 * selected to accommodate optimal alignment for target processing. This reduces code 60 * size and improves performance. 61 * 62 * Any changes to the header length may alter the alignment and cause exceptions 63 * on the target. When adding to the message structures insure that fields are 64 * properly aligned. 65 * 66 */ 67 68 /* HTC frame header */ 69 PREPACK struct htc_frame_hdr { 70 /* do not remove or re-arrange these fields, these are minimally required 71 * to take advantage of 4-byte lookaheads in some hardware implementations */ 72 u8 EndpointID; 73 u8 Flags; 74 u16 PayloadLen; /* length of data (including trailer) that follows the header */ 75 76 /***** end of 4-byte lookahead ****/ 77 78 u8 ControlBytes[2]; 79 80 /* message payload starts after the header */ 81 82 } POSTPACK; 83 84 /* frame header flags */ 85 86 /* send direction */ 87 #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0) 88 #define HTC_FLAGS_SEND_BUNDLE (1 << 1) /* start or part of bundle */ 89 /* receive direction */ 90 #define HTC_FLAGS_RECV_UNUSED_0 (1 << 0) /* bit 0 unused */ 91 #define HTC_FLAGS_RECV_TRAILER (1 << 1) /* bit 1 trailer data present */ 92 #define HTC_FLAGS_RECV_UNUSED_2 (1 << 0) /* bit 2 unused */ 93 #define HTC_FLAGS_RECV_UNUSED_3 (1 << 0) /* bit 3 unused */ 94 #define HTC_FLAGS_RECV_BUNDLE_CNT_MASK (0xF0) /* bits 7..4 */ 95 #define HTC_FLAGS_RECV_BUNDLE_CNT_SHIFT 4 96 97 #define HTC_HDR_LENGTH (sizeof(struct htc_frame_hdr)) 98 #define HTC_MAX_TRAILER_LENGTH 255 99 #define HTC_MAX_PAYLOAD_LENGTH (4096 - sizeof(struct htc_frame_hdr)) 100 101 /* HTC control message IDs */ 102 103 #define HTC_MSG_READY_ID 1 104 #define HTC_MSG_CONNECT_SERVICE_ID 2 105 #define HTC_MSG_CONNECT_SERVICE_RESPONSE_ID 3 106 #define HTC_MSG_SETUP_COMPLETE_ID 4 107 #define HTC_MSG_SETUP_COMPLETE_EX_ID 5 108 109 #define HTC_MAX_CONTROL_MESSAGE_LENGTH 256 110 111 /* base message ID header */ 112 typedef PREPACK struct { 113 u16 MessageID; 114 } POSTPACK HTC_UNKNOWN_MSG; 115 116 /* HTC ready message 117 * direction : target-to-host */ 118 typedef PREPACK struct { 119 u16 MessageID; /* ID */ 120 u16 CreditCount; /* number of credits the target can offer */ 121 u16 CreditSize; /* size of each credit */ 122 u8 MaxEndpoints; /* maximum number of endpoints the target has resources for */ 123 u8 _Pad1; 124 } POSTPACK HTC_READY_MSG; 125 126 /* extended HTC ready message */ 127 typedef PREPACK struct { 128 HTC_READY_MSG Version2_0_Info; /* legacy version 2.0 information at the front... */ 129 /* extended information */ 130 u8 HTCVersion; 131 u8 MaxMsgsPerHTCBundle; 132 } POSTPACK HTC_READY_EX_MSG; 133 134 #define HTC_VERSION_2P0 0x00 135 #define HTC_VERSION_2P1 0x01 /* HTC 2.1 */ 136 137 #define HTC_SERVICE_META_DATA_MAX_LENGTH 128 138 139 /* connect service 140 * direction : host-to-target */ 141 typedef PREPACK struct { 142 u16 MessageID; 143 u16 ServiceID; /* service ID of the service to connect to */ 144 u16 ConnectionFlags; /* connection flags */ 145 146 #define HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE (1 << 2) /* reduce credit dribbling when 147 the host needs credits */ 148 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK (0x3) 149 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH 0x0 150 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF 0x1 151 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS 0x2 152 #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_UNITY 0x3 153 154 u8 ServiceMetaLength; /* length of meta data that follows */ 155 u8 _Pad1; 156 157 /* service-specific meta data starts after the header */ 158 159 } POSTPACK HTC_CONNECT_SERVICE_MSG; 160 161 /* connect response 162 * direction : target-to-host */ 163 typedef PREPACK struct { 164 u16 MessageID; 165 u16 ServiceID; /* service ID that the connection request was made */ 166 u8 Status; /* service connection status */ 167 u8 EndpointID; /* assigned endpoint ID */ 168 u16 MaxMsgSize; /* maximum expected message size on this endpoint */ 169 u8 ServiceMetaLength; /* length of meta data that follows */ 170 u8 _Pad1; 171 172 /* service-specific meta data starts after the header */ 173 174 } POSTPACK HTC_CONNECT_SERVICE_RESPONSE_MSG; 175 176 typedef PREPACK struct { 177 u16 MessageID; 178 /* currently, no other fields */ 179 } POSTPACK HTC_SETUP_COMPLETE_MSG; 180 181 /* extended setup completion message */ 182 typedef PREPACK struct { 183 u16 MessageID; 184 u32 SetupFlags; 185 u8 MaxMsgsPerBundledRecv; 186 u8 Rsvd[3]; 187 } POSTPACK HTC_SETUP_COMPLETE_EX_MSG; 188 189 #define HTC_SETUP_COMPLETE_FLAGS_ENABLE_BUNDLE_RECV (1 << 0) 190 191 /* connect response status codes */ 192 #define HTC_SERVICE_SUCCESS 0 /* success */ 193 #define HTC_SERVICE_NOT_FOUND 1 /* service could not be found */ 194 #define HTC_SERVICE_FAILED 2 /* specific service failed the connect */ 195 #define HTC_SERVICE_NO_RESOURCES 3 /* no resources (i.e. no more endpoints) */ 196 #define HTC_SERVICE_NO_MORE_EP 4 /* specific service is not allowing any more 197 endpoints */ 198 199 /* report record IDs */ 200 201 #define HTC_RECORD_NULL 0 202 #define HTC_RECORD_CREDITS 1 203 #define HTC_RECORD_LOOKAHEAD 2 204 #define HTC_RECORD_LOOKAHEAD_BUNDLE 3 205 206 typedef PREPACK struct { 207 u8 RecordID; /* Record ID */ 208 u8 Length; /* Length of record */ 209 } POSTPACK HTC_RECORD_HDR; 210 211 typedef PREPACK struct { 212 u8 EndpointID; /* Endpoint that owns these credits */ 213 u8 Credits; /* credits to report since last report */ 214 } POSTPACK HTC_CREDIT_REPORT; 215 216 typedef PREPACK struct { 217 u8 PreValid; /* pre valid guard */ 218 u8 LookAhead[4]; /* 4 byte lookahead */ 219 u8 PostValid; /* post valid guard */ 220 221 /* NOTE: the LookAhead array is guarded by a PreValid and Post Valid guard bytes. 222 * The PreValid bytes must equal the inverse of the PostValid byte */ 223 224 } POSTPACK HTC_LOOKAHEAD_REPORT; 225 226 typedef PREPACK struct { 227 u8 LookAhead[4]; /* 4 byte lookahead */ 228 } POSTPACK HTC_BUNDLED_LOOKAHEAD_REPORT; 229 230 #ifndef ATH_TARGET 231 #include "athendpack.h" 232 #endif 233 234 235 #endif /* __HTC_H__ */ 236 237