htc.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //------------------------------------------------------------------------------
  2. // <copyright file="htc.h" company="Atheros">
  3. // Copyright (c) 2004-2007 Atheros Corporation. All rights reserved.
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License version 2 as
  7. // published by the Free Software Foundation;
  8. //
  9. // Software distributed under the License is distributed on an "AS
  10. // IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. // implied. See the License for the specific language governing
  12. // rights and limitations under the License.
  13. //
  14. //
  15. //------------------------------------------------------------------------------
  16. //==============================================================================
  17. // Author(s): ="Atheros"
  18. //==============================================================================
  19. #ifndef __HTC_H__
  20. #define __HTC_H__
  21. #ifndef ATH_TARGET
  22. #include "athstartpack.h"
  23. #endif
  24. #define A_OFFSETOF(type,field) (int)(&(((type *)NULL)->field))
  25. #define ASSEMBLE_UNALIGNED_UINT16(p,highbyte,lowbyte) \
  26. (((A_UINT16)(((A_UINT8 *)(p))[(highbyte)])) << 8 | (A_UINT16)(((A_UINT8 *)(p))[(lowbyte)]))
  27. /* alignment independent macros (little-endian) to fetch UINT16s or UINT8s from a
  28. * structure using only the type and field name.
  29. * Use these macros if there is the potential for unaligned buffer accesses. */
  30. #define A_GET_UINT16_FIELD(p,type,field) \
  31. ASSEMBLE_UNALIGNED_UINT16(p,\
  32. A_OFFSETOF(type,field) + 1, \
  33. A_OFFSETOF(type,field))
  34. #define A_SET_UINT16_FIELD(p,type,field,value) \
  35. { \
  36. ((A_UINT8 *)(p))[A_OFFSETOF(type,field)] = (A_UINT8)(value); \
  37. ((A_UINT8 *)(p))[A_OFFSETOF(type,field) + 1] = (A_UINT8)((value) >> 8); \
  38. }
  39. #define A_GET_UINT8_FIELD(p,type,field) \
  40. ((A_UINT8 *)(p))[A_OFFSETOF(type,field)]
  41. #define A_SET_UINT8_FIELD(p,type,field,value) \
  42. ((A_UINT8 *)(p))[A_OFFSETOF(type,field)] = (value)
  43. /****** DANGER DANGER ***************
  44. *
  45. * The frame header length and message formats defined herein were
  46. * selected to accommodate optimal alignment for target processing. This reduces code
  47. * size and improves performance.
  48. *
  49. * Any changes to the header length may alter the alignment and cause exceptions
  50. * on the target. When adding to the message structures insure that fields are
  51. * properly aligned.
  52. *
  53. */
  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 */
  58. A_UINT8 EndpointID;
  59. A_UINT8 Flags;
  60. A_UINT16 PayloadLen; /* length of data (including trailer) that follows the header */
  61. /***** end of 4-byte lookahead ****/
  62. A_UINT8 ControlBytes[2];
  63. /* message payload starts after the header */
  64. } POSTPACK HTC_FRAME_HDR;
  65. /* frame header flags */
  66. #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
  67. #define HTC_FLAGS_RECV_TRAILER (1 << 1)
  68. #define HTC_HDR_LENGTH (sizeof(HTC_FRAME_HDR))
  69. #define HTC_MAX_TRAILER_LENGTH 255
  70. #define HTC_MAX_PAYLOAD_LENGTH (2048 - sizeof(HTC_FRAME_HDR))
  71. /* HTC control message IDs */
  72. typedef enum {
  73. HTC_MSG_READY_ID = 1,
  74. HTC_MSG_CONNECT_SERVICE_ID = 2,
  75. HTC_MSG_CONNECT_SERVICE_RESPONSE_ID = 3,
  76. HTC_MSG_SETUP_COMPLETE_ID = 4,
  77. } HTC_MSG_IDS;
  78. #define HTC_MAX_CONTROL_MESSAGE_LENGTH 256
  79. /* base message ID header */
  80. typedef PREPACK struct {
  81. A_UINT16 MessageID;
  82. } POSTPACK HTC_UNKNOWN_MSG;
  83. /* HTC ready message
  84. * direction : target-to-host */
  85. typedef PREPACK struct {
  86. A_UINT16 MessageID; /* ID */
  87. A_UINT16 CreditCount; /* number of credits the target can offer */
  88. A_UINT16 CreditSize; /* size of each credit */
  89. A_UINT8 MaxEndpoints; /* maximum number of endpoints the target has resources for */
  90. A_UINT8 _Pad1;
  91. } POSTPACK HTC_READY_MSG;
  92. #define HTC_SERVICE_META_DATA_MAX_LENGTH 128
  93. /* connect service
  94. * direction : host-to-target */
  95. typedef PREPACK struct {
  96. A_UINT16 MessageID;
  97. A_UINT16 ServiceID; /* service ID of the service to connect to */
  98. A_UINT16 ConnectionFlags; /* connection flags */
  99. #define HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE (1 << 2) /* reduce credit dribbling when
  100. the host needs credits */
  101. #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK (0x3)
  102. #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH 0x0
  103. #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF 0x1
  104. #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS 0x2
  105. #define HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_UNITY 0x3
  106. A_UINT8 ServiceMetaLength; /* length of meta data that follows */
  107. A_UINT8 _Pad1;
  108. /* service-specific meta data starts after the header */
  109. } POSTPACK HTC_CONNECT_SERVICE_MSG;
  110. /* connect response
  111. * direction : target-to-host */
  112. typedef PREPACK struct {
  113. A_UINT16 MessageID;
  114. A_UINT16 ServiceID; /* service ID that the connection request was made */
  115. A_UINT8 Status; /* service connection status */
  116. A_UINT8 EndpointID; /* assigned endpoint ID */
  117. A_UINT16 MaxMsgSize; /* maximum expected message size on this endpoint */
  118. A_UINT8 ServiceMetaLength; /* length of meta data that follows */
  119. A_UINT8 _Pad1;
  120. /* service-specific meta data starts after the header */
  121. } POSTPACK HTC_CONNECT_SERVICE_RESPONSE_MSG;
  122. typedef PREPACK struct {
  123. A_UINT16 MessageID;
  124. /* currently, no other fields */
  125. } POSTPACK HTC_SETUP_COMPLETE_MSG;
  126. /* connect response status codes */
  127. #define HTC_SERVICE_SUCCESS 0 /* success */
  128. #define HTC_SERVICE_NOT_FOUND 1 /* service could not be found */
  129. #define HTC_SERVICE_FAILED 2 /* specific service failed the connect */
  130. #define HTC_SERVICE_NO_RESOURCES 3 /* no resources (i.e. no more endpoints) */
  131. #define HTC_SERVICE_NO_MORE_EP 4 /* specific service is not allowing any more
  132. endpoints */
  133. /* report record IDs */
  134. typedef enum {
  135. HTC_RECORD_NULL = 0,
  136. HTC_RECORD_CREDITS = 1,
  137. HTC_RECORD_LOOKAHEAD = 2,
  138. } HTC_RPT_IDS;
  139. typedef PREPACK struct {
  140. A_UINT8 RecordID; /* Record ID */
  141. A_UINT8 Length; /* Length of record */
  142. } POSTPACK HTC_RECORD_HDR;
  143. typedef PREPACK struct {
  144. A_UINT8 EndpointID; /* Endpoint that owns these credits */
  145. A_UINT8 Credits; /* credits to report since last report */
  146. } POSTPACK HTC_CREDIT_REPORT;
  147. typedef PREPACK struct {
  148. A_UINT8 PreValid; /* pre valid guard */
  149. A_UINT8 LookAhead[4]; /* 4 byte lookahead */
  150. A_UINT8 PostValid; /* post valid guard */
  151. /* NOTE: the LookAhead array is guarded by a PreValid and Post Valid guard bytes.
  152. * The PreValid bytes must equal the inverse of the PostValid byte */
  153. } POSTPACK HTC_LOOKAHEAD_REPORT;
  154. #ifndef ATH_TARGET
  155. #include "athendpack.h"
  156. #endif
  157. #endif /* __HTC_H__ */