/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

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