htc_packet.h 10 KB

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