htc_packet.h 10 KB

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