a445a1f17cdaeb2f8aa0069a2a860e39de2ec7e0
[linux-libre-firmware.git] / ath9k_htc / target_firmware / wlan / include / htc.h
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
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:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
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
15  *    distribution.
16  *
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.
20  *
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.
34  */
35 #ifndef __HTC_H__
36 #define __HTC_H__
37
38 #ifndef ATH_TARGET
39 #endif
40
41 #define A_OFFSETOF(type,field) ((int)(&(((type *)NULL)->field)))
42
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)]))
45         
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))
53
54 #define A_SET_UINT16_FIELD(p,type,field,value)                          \
55         {                                                               \
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); \
58         }
59   
60 #define A_GET_UINT8_FIELD(p,type,field) \
61             ((a_uint8_t *)(p))[A_OFFSETOF(type,field)]
62             
63 #define A_SET_UINT8_FIELD(p,type,field,value) \
64     ((a_uint8_t *)(p))[A_OFFSETOF(type,field)] = (value)
65
66 /****** DANGER DANGER ***************
67  * 
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.
71  * 
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
74  *   properly aligned.
75  * 
76  */
77
78 /* endpoint defines */
79 typedef enum
80 {
81         ENDPOINT_UNUSED = -1,
82         ENDPOINT0 = 0, /* this is reserved for the control endpoint */
83         ENDPOINT1 = 1,  
84         ENDPOINT2 = 2,   
85         ENDPOINT3 = 3,
86         ENDPOINT4,
87         ENDPOINT5,
88         ENDPOINT6,
89         ENDPOINT7,
90         ENDPOINT8,
91         ENDPOINT_MAX = 22 /* maximum number of endpoints for this firmware build, max application
92                              endpoints = (ENDPOINT_MAX - 1) */
93 } HTC_ENDPOINT_ID;
94
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 */
99         a_uint8_t   EndpointID;
100         a_uint8_t   Flags;
101         a_uint16_t  PayloadLen;       /* length of data (including trailer) that follows the header */
102     
103         /***** end of 4-byte lookahead ****/
104     
105         a_uint8_t   ControlBytes[4];
106     
107         /* message payload starts after the header */
108     
109 } POSTPACK HTC_FRAME_HDR;
110
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)
115
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))
119
120 /* HTC control message IDs */
121 typedef enum {
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,
128 } HTC_MSG_IDS;
129  
130 #define HTC_MAX_CONTROL_MESSAGE_LENGTH  256
131          
132 /* base message ID header */
133 typedef PREPACK struct {
134         a_uint16_t MessageID;    
135 } POSTPACK HTC_UNKNOWN_MSG;
136                                                      
137 /* HTC ready message
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 */
144         a_uint8_t   _Pad1;
145 } POSTPACK HTC_READY_MSG;
146
147 #define HTC_SERVICE_META_DATA_MAX_LENGTH 128
148
149 /* connect service
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;
157
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
165                                                              
166         a_uint8_t   ServiceMetaLength;   /* length of meta data that follows */
167         a_uint8_t   _Pad1;
168     
169         /* service-specific meta data starts after the header */
170     
171 } POSTPACK HTC_CONNECT_SERVICE_MSG;
172
173 /* connect response
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 */
182         a_uint8_t   _Pad1;               
183     
184         /* service-specific meta data starts after the header */
185     
186 } POSTPACK HTC_CONNECT_SERVICE_RESPONSE_MSG;
187
188 typedef PREPACK struct {
189         a_uint16_t  MessageID;
190         /* currently, no other fields */
191 } POSTPACK HTC_SETUP_COMPLETE_MSG;
192
193 /* config pipe
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 */                                                            
199         //a_uint8_t   _Pad1;        
200 } POSTPACK HTC_CONFIG_PIPE_MSG;
201
202 /* config pipe
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 */                                                            
208         //a_uint8_t   _Pad1;        
209 } POSTPACK HTC_CONFIG_PIPE_RESPONSE_MSG;
210
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 
217                                        endpoints */
218
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
223
224 /* report record IDs */
225 typedef enum {
226         HTC_RECORD_NULL  = 0,
227         HTC_RECORD_CREDITS   = 1,
228         HTC_RECORD_LOOKAHEAD = 2,   
229 } HTC_RPT_IDS;
230
231 typedef PREPACK struct {
232         a_uint8_t RecordID;     /* Record ID */
233         a_uint8_t Length;       /* Length of record */
234 } POSTPACK HTC_RECORD_HDR;
235
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;
240
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 */
245     
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 */
248     
249 } POSTPACK HTC_LOOKAHEAD_REPORT;
250
251 #ifndef ATH_TARGET
252 //#include "athendpack.h"
253 #endif
254
255 #endif /* __HTC_H__ */