htc_packet.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright (c) 2013-2014, 2016-2017, 2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef HTC_PACKET_H_
  19. #define HTC_PACKET_H_
  20. #include <osdep.h>
  21. #include "dl_list.h"
  22. /* ------ Endpoint IDS ------ */
  23. typedef enum {
  24. ENDPOINT_UNUSED = -1,
  25. ENDPOINT_0 = 0,
  26. ENDPOINT_1 = 1,
  27. ENDPOINT_2 = 2,
  28. ENDPOINT_3,
  29. ENDPOINT_4,
  30. ENDPOINT_5,
  31. ENDPOINT_6,
  32. ENDPOINT_7,
  33. ENDPOINT_8,
  34. ENDPOINT_MAX,
  35. } HTC_ENDPOINT_ID;
  36. struct _HTC_PACKET;
  37. typedef void (*HTC_PACKET_COMPLETION)(void *, struct _HTC_PACKET *);
  38. typedef uint16_t HTC_TX_TAG;
  39. /**
  40. * struct htc_tx_packet_info - HTC TX packet information
  41. * @Tag: tag used to selective flush packets
  42. * @CreditsUsed: number of credits used for this TX packet (HTC internal)
  43. * @SendFlags: send flags (HTC internal)
  44. * @SeqNo: internal seq no for debugging (HTC internal)
  45. * @Flags: Internal use
  46. */
  47. struct htc_tx_packet_info {
  48. HTC_TX_TAG Tag;
  49. int CreditsUsed;
  50. uint8_t SendFlags;
  51. int SeqNo;
  52. uint32_t Flags;
  53. };
  54. /**
  55. * HTC_TX_PACKET_TAG_XXX - #defines for tagging packets for special handling
  56. * HTC_TX_PACKET_TAG_ALL: zero is reserved and used to flush ALL packets
  57. * HTC_TX_PACKET_TAG_INTERNAL: internal tags start here
  58. * HTC_TX_PACKET_TAG_USER_DEFINED: user-defined tags start here
  59. * HTC_TX_PACKET_TAG_BUNDLED: indicate this is a bundled tx packet
  60. * HTC_TX_PACKET_TAG_AUTO_PM: indicate a power management wmi command
  61. */
  62. #define HTC_TX_PACKET_TAG_ALL 0
  63. #define HTC_TX_PACKET_TAG_INTERNAL 1
  64. #define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_TX_PACKET_TAG_INTERNAL + 9)
  65. #define HTC_TX_PACKET_TAG_BUNDLED (HTC_TX_PACKET_TAG_USER_DEFINED + 1)
  66. #define HTC_TX_PACKET_TAG_AUTO_PM (HTC_TX_PACKET_TAG_USER_DEFINED + 2)
  67. /* Tag packet for runtime put after sending */
  68. #define HTC_TX_PACKET_TAG_RUNTIME_PUT (HTC_TX_PACKET_TAG_USER_DEFINED + 3)
  69. #define HTC_TX_PACKET_FLAG_FIXUP_NETBUF (1 << 0)
  70. /**
  71. * struct htc_rx_packet_info - HTC RX Packet information
  72. * @ExpectedHdr: HTC Internal use
  73. * @HTCRxFlags: HTC Internal use
  74. * @IndicationFlags: indication flags set on each RX packet indication
  75. */
  76. struct htc_rx_packet_info {
  77. uint32_t ExpectedHdr;
  78. uint32_t HTCRxFlags;
  79. uint32_t IndicationFlags;
  80. };
  81. /* more packets on this endpoint are being fetched */
  82. #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0)
  83. #define HTC_PACKET_MAGIC_COOKIE 0xdeadbeef
  84. /* wrapper around endpoint-specific packets */
  85. /**
  86. * struct _HTC_PACKET - HTC Packet data structure
  87. * @ListLink: double link
  88. * @pPktContext: caller's per packet specific context
  89. * @pBufferStart: The true buffer start, the caller can store the real buffer
  90. * start here. In receive callbacks, the HTC layer sets pBuffer
  91. * to the start of the payload past the header. This field allows
  92. * the caller to reset pBuffer when it recycles receive packets
  93. * back to HTC
  94. * @pBuffer: payload start (RX/TX)
  95. * @BufferLength: length of buffer
  96. * @ActualLength: actual length of payload
  97. * @Endpoint: endpoint that this packet was sent/recv'd from
  98. * @Status: completion status
  99. * @PktInfo: Packet specific info
  100. * @netbufOrigHeadRoom: Original head room of skb
  101. * @Completion: completion
  102. * @pContext: HTC private completion context
  103. * @pNetBufContext: optimization for network-oriented data, the HTC packet can
  104. * pass the network buffer corresponding to the HTC packet
  105. * lower layers may optimized the transfer knowing this is a
  106. * network buffer
  107. * @magic_cookie: HTC Magic cookie
  108. */
  109. typedef struct _HTC_PACKET {
  110. DL_LIST ListLink;
  111. void *pPktContext;
  112. uint8_t *pBufferStart;
  113. /*
  114. * Pointer to the start of the buffer. In the transmit
  115. * direction this points to the start of the payload. In the
  116. * receive direction, however, the buffer when queued up
  117. * points to the start of the HTC header but when returned
  118. * to the caller points to the start of the payload
  119. */
  120. uint8_t *pBuffer;
  121. uint32_t BufferLength;
  122. uint32_t ActualLength;
  123. HTC_ENDPOINT_ID Endpoint;
  124. QDF_STATUS Status;
  125. union {
  126. struct htc_tx_packet_info AsTx;
  127. struct htc_rx_packet_info AsRx;
  128. } PktInfo;
  129. /* the following fields are for internal HTC use */
  130. uint32_t netbufOrigHeadRoom;
  131. HTC_PACKET_COMPLETION Completion;
  132. void *pContext;
  133. void *pNetBufContext;
  134. uint32_t magic_cookie;
  135. } HTC_PACKET;
  136. #define COMPLETE_HTC_PACKET(p, status) \
  137. { \
  138. (p)->Status = (status); \
  139. (p)->Completion((p)->pContext, (p)); \
  140. }
  141. #define INIT_HTC_PACKET_INFO(p, b, len) \
  142. { \
  143. (p)->pBufferStart = (b); \
  144. (p)->BufferLength = (len); \
  145. }
  146. /* macro to set an initial RX packet for refilling HTC */
  147. #define SET_HTC_PACKET_INFO_RX_REFILL(p, c, b, len, ep) \
  148. do { \
  149. (p)->pPktContext = (c); \
  150. (p)->pBuffer = (b); \
  151. (p)->pBufferStart = (b); \
  152. (p)->BufferLength = (len); \
  153. (p)->Endpoint = (ep); \
  154. } while (0)
  155. /* fast macro to recycle an RX packet that will be re-queued to HTC */
  156. #define HTC_PACKET_RESET_RX(p) \
  157. { (p)->pBuffer = (p)->pBufferStart; (p)->ActualLength = 0; }
  158. /* macro to set packet parameters for TX */
  159. #define SET_HTC_PACKET_INFO_TX(p, c, b, len, ep, tag) \
  160. do { \
  161. (p)->pPktContext = (c); \
  162. (p)->pBuffer = (b); \
  163. (p)->ActualLength = (len); \
  164. (p)->Endpoint = (ep); \
  165. (p)->PktInfo.AsTx.Tag = (tag); \
  166. (p)->PktInfo.AsTx.Flags = 0; \
  167. (p)->PktInfo.AsTx.SendFlags = 0; \
  168. } while (0)
  169. #define SET_HTC_PACKET_NET_BUF_CONTEXT(p, nb) \
  170. { \
  171. (p)->pNetBufContext = (nb); \
  172. }
  173. #define GET_HTC_PACKET_NET_BUF_CONTEXT(p) (p)->pNetBufContext
  174. /* HTC Packet Queueing Macros */
  175. typedef struct _HTC_PACKET_QUEUE {
  176. DL_LIST QueueHead;
  177. int Depth;
  178. } HTC_PACKET_QUEUE;
  179. /* initialize queue */
  180. #define INIT_HTC_PACKET_QUEUE(pQ) \
  181. { \
  182. DL_LIST_INIT(&(pQ)->QueueHead); \
  183. (pQ)->Depth = 0; \
  184. }
  185. /* enqueue HTC packet to the tail of the queue */
  186. #define HTC_PACKET_ENQUEUE(pQ, p) \
  187. { dl_list_insert_tail(&(pQ)->QueueHead, &(p)->ListLink); \
  188. (pQ)->Depth++; \
  189. }
  190. /* enqueue HTC packet to the tail of the queue */
  191. #define HTC_PACKET_ENQUEUE_TO_HEAD(pQ, p) \
  192. { dl_list_insert_head(&(pQ)->QueueHead, &(p)->ListLink); \
  193. (pQ)->Depth++; \
  194. }
  195. /* test if a queue is empty */
  196. #define HTC_QUEUE_EMPTY(pQ) ((pQ)->Depth == 0)
  197. /* get packet at head without removing it */
  198. static inline HTC_PACKET *htc_get_pkt_at_head(HTC_PACKET_QUEUE *queue)
  199. {
  200. if (queue->Depth == 0)
  201. return NULL;
  202. return A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(
  203. &queue->QueueHead)),
  204. HTC_PACKET, ListLink);
  205. }
  206. /* remove a packet from a queue, where-ever it is in the queue */
  207. #define HTC_PACKET_REMOVE(pQ, p) \
  208. { \
  209. dl_list_remove(&(p)->ListLink); \
  210. (pQ)->Depth--; \
  211. }
  212. /* dequeue an HTC packet from the head of the queue */
  213. static inline HTC_PACKET *htc_packet_dequeue(HTC_PACKET_QUEUE *queue)
  214. {
  215. DL_LIST *pItem = dl_list_remove_item_from_head(&queue->QueueHead);
  216. if (pItem) {
  217. queue->Depth--;
  218. return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
  219. }
  220. return NULL;
  221. }
  222. /* dequeue an HTC packet from the tail of the queue */
  223. static inline HTC_PACKET *htc_packet_dequeue_tail(HTC_PACKET_QUEUE *queue)
  224. {
  225. DL_LIST *pItem = dl_list_remove_item_from_tail(&queue->QueueHead);
  226. if (pItem) {
  227. queue->Depth--;
  228. return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
  229. }
  230. return NULL;
  231. }
  232. #define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth
  233. #define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint
  234. #define HTC_GET_TAG_FROM_PKT(p) (p)->PktInfo.AsTx.Tag
  235. /* transfer the packets from one queue to the tail of another queue */
  236. #define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest, pQSrc) \
  237. { \
  238. dl_list_transfer_items_to_tail(&(pQDest)->QueueHead, \
  239. &(pQSrc)->QueueHead); \
  240. (pQDest)->Depth += (pQSrc)->Depth; \
  241. (pQSrc)->Depth = 0; \
  242. }
  243. /*
  244. * Transfer the packets from one queue to the head of another queue.
  245. * This xfer_to_head(q1,q2) is basically equivalent to xfer_to_tail(q2,q1),
  246. * but it updates the queue descriptor object for the initial queue to refer
  247. * to the concatenated queue.
  248. */
  249. #define HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(pQDest, pQSrc) \
  250. { \
  251. dl_list_transfer_items_to_head(&(pQDest)->QueueHead, \
  252. &(pQSrc)->QueueHead); \
  253. (pQDest)->Depth += (pQSrc)->Depth; \
  254. (pQSrc)->Depth = 0; \
  255. }
  256. /* fast version to init and add a single packet to a queue */
  257. #define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ, pP) \
  258. { \
  259. DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead, &(pP)->ListLink) \
  260. (pQ)->Depth = 1; \
  261. }
  262. #define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \
  263. ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead, \
  264. (pPTemp), HTC_PACKET, ListLink)
  265. #define HTC_PACKET_QUEUE_ITERATE_IS_VALID(pQ) ITERATE_IS_VALID(&(pQ)->QueueHead)
  266. #define HTC_PACKET_QUEUE_ITERATE_RESET(pQ) ITERATE_RESET(&(pQ)->QueueHead)
  267. #define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END
  268. /**
  269. * htc_packet_set_magic_cookie() - set magic cookie in htc packet
  270. * htc_pkt - pointer to htc packet
  271. * value - value to set in magic cookie
  272. *
  273. * This API sets the magic cookie passed in htc packet.
  274. *
  275. * Return : None
  276. */
  277. static inline void htc_packet_set_magic_cookie(HTC_PACKET *htc_pkt,
  278. uint32_t value)
  279. {
  280. htc_pkt->magic_cookie = value;
  281. }
  282. /**
  283. * htc_packet_set_magic_cookie() - get magic cookie in htc packet
  284. * htc_pkt - pointer to htc packet
  285. *
  286. * This API returns the magic cookie in htc packet.
  287. *
  288. * Return : magic cookie
  289. */
  290. static inline uint32_t htc_packet_get_magic_cookie(HTC_PACKET *htc_pkt)
  291. {
  292. return htc_pkt->magic_cookie;
  293. }
  294. #endif /*HTC_PACKET_H_ */