PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/staging/ath6kl/include/common/htc.h

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t
C Header | 227 lines | 117 code | 46 blank | 64 comment | 0 complexity | e018039fd5964311a638a5f657d8dcdd MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  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#define A_OFFSETOF(type,field) (unsigned long)(&(((type *)NULL)->field))
 28
 29#define ASSEMBLE_UNALIGNED_UINT16(p,highbyte,lowbyte) \
 30        (((u16)(((u8 *)(p))[(highbyte)])) << 8 | (u16)(((u8 *)(p))[(lowbyte)]))
 31        
 32/* alignment independent macros (little-endian) to fetch UINT16s or UINT8s from a 
 33 * structure using only the type and field name.
 34 * Use these macros if there is the potential for unaligned buffer accesses. */
 35#define A_GET_UINT16_FIELD(p,type,field) \
 36    ASSEMBLE_UNALIGNED_UINT16(p,\
 37                              A_OFFSETOF(type,field) + 1, \
 38                              A_OFFSETOF(type,field))
 39
 40#define A_SET_UINT16_FIELD(p,type,field,value) \
 41{                                              \
 42    ((u8 *)(p))[A_OFFSETOF(type,field)] = (u8)(value);        \
 43    ((u8 *)(p))[A_OFFSETOF(type,field) + 1] = (u8)((value) >> 8); \
 44}
 45  
 46#define A_GET_UINT8_FIELD(p,type,field) \
 47            ((u8 *)(p))[A_OFFSETOF(type,field)]
 48            
 49#define A_SET_UINT8_FIELD(p,type,field,value) \
 50    ((u8 *)(p))[A_OFFSETOF(type,field)] = (value)
 51
 52/****** DANGER DANGER ***************
 53 * 
 54 *   The frame header length and message formats defined herein were
 55 *   selected to accommodate optimal alignment for target processing.  This reduces code
 56 *   size and improves performance.
 57 * 
 58 *   Any changes to the header length may alter the alignment and cause exceptions
 59 *   on the target. When adding to the message structures insure that fields are
 60 *   properly aligned.
 61 * 
 62 */
 63
 64/* HTC frame header */
 65PREPACK struct htc_frame_hdr {
 66        /* do not remove or re-arrange these fields, these are minimally required
 67         * to take advantage of 4-byte lookaheads in some hardware implementations */
 68    u8 EndpointID;
 69    u8 Flags;
 70    u16 PayloadLen;       /* length of data (including trailer) that follows the header */
 71    
 72    /***** end of 4-byte lookahead ****/
 73    
 74    u8 ControlBytes[2];
 75    
 76    /* message payload starts after the header */
 77    
 78} POSTPACK;
 79
 80/* frame header flags */
 81
 82    /* send direction */
 83#define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
 84#define HTC_FLAGS_SEND_BUNDLE        (1 << 1)  /* start or part of bundle */
 85    /* receive direction */
 86#define HTC_FLAGS_RECV_UNUSED_0      (1 << 0)  /* bit 0 unused */    
 87#define HTC_FLAGS_RECV_TRAILER       (1 << 1)  /* bit 1 trailer data present */
 88#define HTC_FLAGS_RECV_UNUSED_2      (1 << 0)  /* bit 2 unused */
 89#define HTC_FLAGS_RECV_UNUSED_3      (1 << 0)  /* bit 3 unused */
 90#define HTC_FLAGS_RECV_BUNDLE_CNT_MASK (0xF0)  /* bits 7..4  */
 91#define HTC_FLAGS_RECV_BUNDLE_CNT_SHIFT 4
 92
 93#define HTC_HDR_LENGTH  (sizeof(struct htc_frame_hdr))
 94#define HTC_MAX_TRAILER_LENGTH   255
 95#define HTC_MAX_PAYLOAD_LENGTH   (4096 - sizeof(struct htc_frame_hdr))
 96
 97/* HTC control message IDs */
 98
 99#define HTC_MSG_READY_ID                    1
100#define HTC_MSG_CONNECT_SERVICE_ID          2
101#define HTC_MSG_CONNECT_SERVICE_RESPONSE_ID 3   
102#define HTC_MSG_SETUP_COMPLETE_ID           4
103#define HTC_MSG_SETUP_COMPLETE_EX_ID        5
104
105#define HTC_MAX_CONTROL_MESSAGE_LENGTH  256
106         
107/* base message ID header */
108typedef PREPACK struct {
109    u16 MessageID;
110} POSTPACK HTC_UNKNOWN_MSG;
111                                                     
112/* HTC ready message
113 * direction : target-to-host  */
114typedef PREPACK struct {
115    u16 MessageID;    /* ID */
116    u16 CreditCount;  /* number of credits the target can offer */
117    u16 CreditSize;   /* size of each credit */
118    u8 MaxEndpoints; /* maximum number of endpoints the target has resources for */
119    u8 _Pad1;
120} POSTPACK HTC_READY_MSG;
121
122    /* extended HTC ready message */
123typedef PREPACK struct {
124    HTC_READY_MSG   Version2_0_Info;   /* legacy version 2.0 information at the front... */
125    /* extended information */
126    u8 HTCVersion;
127    u8 MaxMsgsPerHTCBundle;
128} POSTPACK HTC_READY_EX_MSG;
129
130#define HTC_VERSION_2P0  0x00  
131#define HTC_VERSION_2P1  0x01  /* HTC 2.1 */
132
133#define HTC_SERVICE_META_DATA_MAX_LENGTH 128
134
135/* connect service
136 * direction : host-to-target */
137typedef PREPACK struct {
138    u16 MessageID;
139    u16 ServiceID;           /* service ID of the service to connect to */
140    u16 ConnectionFlags;     /* connection flags */
141
142#define HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE (1 << 2)  /* reduce credit dribbling when 
143                                                             the host needs credits */  
144#define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK             (0x3)  
145#define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH        0x0
146#define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF          0x1
147#define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS     0x2
148#define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_UNITY             0x3
149                                                             
150    u8 ServiceMetaLength;   /* length of meta data that follows */
151    u8 _Pad1;
152    
153    /* service-specific meta data starts after the header */
154    
155} POSTPACK HTC_CONNECT_SERVICE_MSG;
156
157/* connect response
158 * direction : target-to-host */
159typedef PREPACK struct {
160    u16 MessageID;
161    u16 ServiceID;            /* service ID that the connection request was made */
162    u8 Status;               /* service connection status */
163    u8 EndpointID;           /* assigned endpoint ID */
164    u16 MaxMsgSize;           /* maximum expected message size on this endpoint */
165    u8 ServiceMetaLength;    /* length of meta data that follows */
166    u8 _Pad1;
167    
168    /* service-specific meta data starts after the header */
169    
170} POSTPACK HTC_CONNECT_SERVICE_RESPONSE_MSG;
171
172typedef PREPACK struct {
173    u16 MessageID;
174    /* currently, no other fields */
175} POSTPACK HTC_SETUP_COMPLETE_MSG;
176
177    /* extended setup completion message */
178typedef PREPACK struct {
179    u16 MessageID;
180    u32 SetupFlags;
181    u8 MaxMsgsPerBundledRecv;
182    u8 Rsvd[3];
183} POSTPACK HTC_SETUP_COMPLETE_EX_MSG;
184
185#define HTC_SETUP_COMPLETE_FLAGS_ENABLE_BUNDLE_RECV     (1 << 0)
186
187/* connect response status codes */
188#define HTC_SERVICE_SUCCESS      0  /* success */
189#define HTC_SERVICE_NOT_FOUND    1  /* service could not be found */
190#define HTC_SERVICE_FAILED       2  /* specific service failed the connect */
191#define HTC_SERVICE_NO_RESOURCES 3  /* no resources (i.e. no more endpoints) */  
192#define HTC_SERVICE_NO_MORE_EP   4  /* specific service is not allowing any more 
193                                       endpoints */
194
195/* report record IDs */
196
197#define HTC_RECORD_NULL             0
198#define HTC_RECORD_CREDITS          1
199#define HTC_RECORD_LOOKAHEAD        2
200#define HTC_RECORD_LOOKAHEAD_BUNDLE 3
201
202typedef PREPACK struct {
203    u8 RecordID;     /* Record ID */
204    u8 Length;       /* Length of record */
205} POSTPACK HTC_RECORD_HDR;
206
207typedef PREPACK struct {
208    u8 EndpointID;     /* Endpoint that owns these credits */
209    u8 Credits;        /* credits to report since last report */
210} POSTPACK HTC_CREDIT_REPORT;
211
212typedef PREPACK struct {    
213    u8 PreValid;         /* pre valid guard */
214    u8 LookAhead[4];     /* 4 byte lookahead */
215    u8 PostValid;        /* post valid guard */
216    
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 */
219    
220} POSTPACK HTC_LOOKAHEAD_REPORT;
221
222typedef PREPACK struct {    
223    u8 LookAhead[4];     /* 4 byte lookahead */
224} POSTPACK HTC_BUNDLED_LOOKAHEAD_REPORT;
225
226#endif /* __HTC_H__ */
227