htc_packet.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * Copyright (c) 2013-2014, 2016-2017, 2019-2021 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. /*Tag packet for runtime put in response or cleanup */
  70. #define HTC_TX_PACKET_TAG_RTPM_PUT_RC (HTC_TX_PACKET_TAG_USER_DEFINED + 4)
  71. #define HTC_TX_PACKET_SYSTEM_SUSPEND (HTC_TX_PACKET_TAG_USER_DEFINED + 5)
  72. #define HTC_TX_PACKET_SYSTEM_RESUME (HTC_TX_PACKET_TAG_USER_DEFINED + 6)
  73. #define HTC_TX_PACKET_FLAG_FIXUP_NETBUF (1 << 0)
  74. #define HTC_TX_PACKET_FLAG_HTC_HEADER_IN_NETBUF_DATA (1 << 1)
  75. /**
  76. * struct htc_rx_packet_info - HTC RX Packet information
  77. * @ExpectedHdr: HTC Internal use
  78. * @HTCRxFlags: HTC Internal use
  79. * @IndicationFlags: indication flags set on each RX packet indication
  80. */
  81. struct htc_rx_packet_info {
  82. uint32_t ExpectedHdr;
  83. uint32_t HTCRxFlags;
  84. uint32_t IndicationFlags;
  85. };
  86. /* more packets on this endpoint are being fetched */
  87. #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0)
  88. #define HTC_PACKET_MAGIC_COOKIE 0xdeadbeef
  89. /* wrapper around endpoint-specific packets */
  90. /**
  91. * struct _HTC_PACKET - HTC Packet data structure
  92. * @ListLink: double link
  93. * @pPktContext: caller's per packet specific context
  94. * @pBufferStart: The true buffer start, the caller can store the real buffer
  95. * start here. In receive callbacks, the HTC layer sets pBuffer
  96. * to the start of the payload past the header. This field allows
  97. * the caller to reset pBuffer when it recycles receive packets
  98. * back to HTC
  99. * @pBuffer: payload start (RX/TX)
  100. * @BufferLength: length of buffer
  101. * @ActualLength: actual length of payload
  102. * @Endpoint: endpoint that this packet was sent/recv'd from
  103. * @Status: completion status
  104. * @PktInfo: Packet specific info
  105. * @netbufOrigHeadRoom: Original head room of skb
  106. * @Completion: completion
  107. * @pContext: HTC private completion context
  108. * @pNetBufContext: optimization for network-oriented data, the HTC packet can
  109. * pass the network buffer corresponding to the HTC packet
  110. * lower layers may optimized the transfer knowing this is a
  111. * network buffer
  112. * @magic_cookie: HTC Magic cookie
  113. */
  114. typedef struct _HTC_PACKET {
  115. DL_LIST ListLink;
  116. void *pPktContext;
  117. uint8_t *pBufferStart;
  118. /*
  119. * Pointer to the start of the buffer. In the transmit
  120. * direction this points to the start of the payload. In the
  121. * receive direction, however, the buffer when queued up
  122. * points to the start of the HTC header but when returned
  123. * to the caller points to the start of the payload
  124. */
  125. uint8_t *pBuffer;
  126. uint32_t BufferLength;
  127. uint32_t ActualLength;
  128. HTC_ENDPOINT_ID Endpoint;
  129. QDF_STATUS Status;
  130. union {
  131. struct htc_tx_packet_info AsTx;
  132. struct htc_rx_packet_info AsRx;
  133. } PktInfo;
  134. /* the following fields are for internal HTC use */
  135. uint32_t netbufOrigHeadRoom;
  136. HTC_PACKET_COMPLETION Completion;
  137. void *pContext;
  138. void *pNetBufContext;
  139. uint32_t magic_cookie;
  140. } HTC_PACKET;
  141. #define COMPLETE_HTC_PACKET(p, status) \
  142. { \
  143. (p)->Status = (status); \
  144. (p)->Completion((p)->pContext, (p)); \
  145. }
  146. #define INIT_HTC_PACKET_INFO(p, b, len) \
  147. { \
  148. (p)->pBufferStart = (b); \
  149. (p)->BufferLength = (len); \
  150. }
  151. /* macro to set an initial RX packet for refilling HTC */
  152. #define SET_HTC_PACKET_INFO_RX_REFILL(p, c, b, len, ep) \
  153. do { \
  154. (p)->pPktContext = (c); \
  155. (p)->pBuffer = (b); \
  156. (p)->pBufferStart = (b); \
  157. (p)->BufferLength = (len); \
  158. (p)->Endpoint = (ep); \
  159. } while (0)
  160. /* fast macro to recycle an RX packet that will be re-queued to HTC */
  161. #define HTC_PACKET_RESET_RX(p) \
  162. { (p)->pBuffer = (p)->pBufferStart; (p)->ActualLength = 0; }
  163. /* macro to set packet parameters for TX */
  164. #define SET_HTC_PACKET_INFO_TX(p, c, b, len, ep, tag) \
  165. do { \
  166. (p)->pPktContext = (c); \
  167. (p)->pBuffer = (b); \
  168. (p)->ActualLength = (len); \
  169. (p)->Endpoint = (ep); \
  170. (p)->PktInfo.AsTx.Tag = (tag); \
  171. (p)->PktInfo.AsTx.Flags = 0; \
  172. (p)->PktInfo.AsTx.SendFlags = 0; \
  173. } while (0)
  174. #define SET_HTC_PACKET_NET_BUF_CONTEXT(p, nb) \
  175. { \
  176. (p)->pNetBufContext = (nb); \
  177. }
  178. #define GET_HTC_PACKET_NET_BUF_CONTEXT(p) (p)->pNetBufContext
  179. /* HTC Packet Queueing Macros */
  180. typedef struct _HTC_PACKET_QUEUE {
  181. DL_LIST QueueHead;
  182. int Depth;
  183. } HTC_PACKET_QUEUE;
  184. /* initialize queue */
  185. #define INIT_HTC_PACKET_QUEUE(pQ) \
  186. { \
  187. DL_LIST_INIT(&(pQ)->QueueHead); \
  188. (pQ)->Depth = 0; \
  189. }
  190. /* enqueue HTC packet to the tail of the queue */
  191. #define HTC_PACKET_ENQUEUE(pQ, p) \
  192. { dl_list_insert_tail(&(pQ)->QueueHead, &(p)->ListLink); \
  193. (pQ)->Depth++; \
  194. }
  195. /* enqueue HTC packet to the tail of the queue */
  196. #define HTC_PACKET_ENQUEUE_TO_HEAD(pQ, p) \
  197. { dl_list_insert_head(&(pQ)->QueueHead, &(p)->ListLink); \
  198. (pQ)->Depth++; \
  199. }
  200. /* test if a queue is empty */
  201. #define HTC_QUEUE_EMPTY(pQ) ((pQ)->Depth == 0)
  202. /* get packet at head without removing it */
  203. static inline HTC_PACKET *htc_get_pkt_at_head(HTC_PACKET_QUEUE *queue)
  204. {
  205. if (queue->Depth == 0)
  206. return NULL;
  207. return A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(
  208. &queue->QueueHead)),
  209. HTC_PACKET, ListLink);
  210. }
  211. /* remove a packet from a queue, where-ever it is in the queue */
  212. #define HTC_PACKET_REMOVE(pQ, p) \
  213. { \
  214. dl_list_remove(&(p)->ListLink); \
  215. (pQ)->Depth--; \
  216. }
  217. /* dequeue an HTC packet from the head of the queue */
  218. static inline HTC_PACKET *htc_packet_dequeue(HTC_PACKET_QUEUE *queue)
  219. {
  220. DL_LIST *pItem = dl_list_remove_item_from_head(&queue->QueueHead);
  221. if (pItem) {
  222. queue->Depth--;
  223. return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
  224. }
  225. return NULL;
  226. }
  227. /* dequeue an HTC packet from the tail of the queue */
  228. static inline HTC_PACKET *htc_packet_dequeue_tail(HTC_PACKET_QUEUE *queue)
  229. {
  230. DL_LIST *pItem = dl_list_remove_item_from_tail(&queue->QueueHead);
  231. if (pItem) {
  232. queue->Depth--;
  233. return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
  234. }
  235. return NULL;
  236. }
  237. #define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth
  238. #define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint
  239. #define HTC_GET_TAG_FROM_PKT(p) (p)->PktInfo.AsTx.Tag
  240. /* transfer the packets from one queue to the tail of another queue */
  241. #define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest, pQSrc) \
  242. { \
  243. dl_list_transfer_items_to_tail(&(pQDest)->QueueHead, \
  244. &(pQSrc)->QueueHead); \
  245. (pQDest)->Depth += (pQSrc)->Depth; \
  246. (pQSrc)->Depth = 0; \
  247. }
  248. /*
  249. * Transfer the packets from one queue to the head of another queue.
  250. * This xfer_to_head(q1,q2) is basically equivalent to xfer_to_tail(q2,q1),
  251. * but it updates the queue descriptor object for the initial queue to refer
  252. * to the concatenated queue.
  253. */
  254. #define HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(pQDest, pQSrc) \
  255. { \
  256. dl_list_transfer_items_to_head(&(pQDest)->QueueHead, \
  257. &(pQSrc)->QueueHead); \
  258. (pQDest)->Depth += (pQSrc)->Depth; \
  259. (pQSrc)->Depth = 0; \
  260. }
  261. /* fast version to init and add a single packet to a queue */
  262. #define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ, pP) \
  263. { \
  264. DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead, &(pP)->ListLink) \
  265. (pQ)->Depth = 1; \
  266. }
  267. #define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \
  268. ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead, \
  269. (pPTemp), HTC_PACKET, ListLink)
  270. #define HTC_PACKET_QUEUE_ITERATE_IS_VALID(pQ) ITERATE_IS_VALID(&(pQ)->QueueHead)
  271. #define HTC_PACKET_QUEUE_ITERATE_RESET(pQ) ITERATE_RESET(&(pQ)->QueueHead)
  272. #define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END
  273. /**
  274. * htc_packet_set_magic_cookie() - set magic cookie in htc packet
  275. * htc_pkt - pointer to htc packet
  276. * value - value to set in magic cookie
  277. *
  278. * This API sets the magic cookie passed in htc packet.
  279. *
  280. * Return : None
  281. */
  282. static inline void htc_packet_set_magic_cookie(HTC_PACKET *htc_pkt,
  283. uint32_t value)
  284. {
  285. htc_pkt->magic_cookie = value;
  286. }
  287. /**
  288. * htc_packet_set_magic_cookie() - get magic cookie in htc packet
  289. * htc_pkt - pointer to htc packet
  290. *
  291. * This API returns the magic cookie in htc packet.
  292. *
  293. * Return : magic cookie
  294. */
  295. static inline uint32_t htc_packet_get_magic_cookie(HTC_PACKET *htc_pkt)
  296. {
  297. return htc_pkt->magic_cookie;
  298. }
  299. #endif /*HTC_PACKET_H_ */