Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1 | /* |
Houston Hoffman | c5141b0 | 2015-11-18 02:36:30 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, 2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 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 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | #ifndef HTC_PACKET_H_ |
| 29 | #define HTC_PACKET_H_ |
| 30 | |
| 31 | #include <osdep.h> |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 32 | #include "dl_list.h" |
| 33 | |
| 34 | /* ------ Endpoint IDS ------ */ |
| 35 | typedef enum { |
| 36 | ENDPOINT_UNUSED = -1, |
| 37 | ENDPOINT_0 = 0, |
| 38 | ENDPOINT_1 = 1, |
| 39 | ENDPOINT_2 = 2, |
| 40 | ENDPOINT_3, |
| 41 | ENDPOINT_4, |
| 42 | ENDPOINT_5, |
| 43 | ENDPOINT_6, |
| 44 | ENDPOINT_7, |
| 45 | ENDPOINT_8, |
| 46 | ENDPOINT_MAX, |
| 47 | } HTC_ENDPOINT_ID; |
| 48 | |
| 49 | struct _HTC_PACKET; |
| 50 | |
| 51 | typedef void (*HTC_PACKET_COMPLETION)(void *, struct _HTC_PACKET *); |
| 52 | |
Yue Ma | b16cf30 | 2016-03-08 18:30:25 -0800 | [diff] [blame] | 53 | typedef uint16_t HTC_TX_TAG; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 54 | |
| 55 | typedef struct _HTC_TX_PACKET_INFO { |
| 56 | HTC_TX_TAG Tag; /* tag used to selective flush packets */ |
| 57 | int CreditsUsed; /* number of credits used for this TX packet (HTC internal) */ |
Yue Ma | b16cf30 | 2016-03-08 18:30:25 -0800 | [diff] [blame] | 58 | uint8_t SendFlags; /* send flags (HTC internal) */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 59 | int SeqNo; /* internal seq no for debugging (HTC internal) */ |
Yue Ma | b16cf30 | 2016-03-08 18:30:25 -0800 | [diff] [blame] | 60 | uint32_t Flags; /* internal use */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 61 | } HTC_TX_PACKET_INFO; |
| 62 | |
Houston Hoffman | c5141b0 | 2015-11-18 02:36:30 -0800 | [diff] [blame] | 63 | /** |
| 64 | * HTC_TX_PACKET_TAG_XXX - #defines for tagging packets for special handling |
| 65 | * HTC_TX_PACKET_TAG_ALL: zero is reserved and used to flush ALL packets |
| 66 | * HTC_TX_PACKET_TAG_INTERNAL: internal tags start here |
| 67 | * HTC_TX_PACKET_TAG_USER_DEFINED: user-defined tags start here |
| 68 | * HTC_TX_PACKET_TAG_BUNDLED: indicate this is a bundled tx packet |
| 69 | * HTC_TX_PACKET_TAG_AUTO_PM: indicate a power management wmi command |
| 70 | */ |
| 71 | #define HTC_TX_PACKET_TAG_ALL 0 |
| 72 | #define HTC_TX_PACKET_TAG_INTERNAL 1 |
| 73 | #define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_TX_PACKET_TAG_INTERNAL + 9) |
| 74 | #define HTC_TX_PACKET_TAG_BUNDLED (HTC_TX_PACKET_TAG_USER_DEFINED + 1) |
| 75 | #define HTC_TX_PACKET_TAG_AUTO_PM (HTC_TX_PACKET_TAG_USER_DEFINED + 2) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 76 | |
Houston Hoffman | 1dd2276 | 2015-11-10 11:35:49 -0800 | [diff] [blame] | 77 | /* Tag packet for runtime put after sending */ |
| 78 | #define HTC_TX_PACKET_TAG_RUNTIME_PUT (HTC_TX_PACKET_TAG_USER_DEFINED + 3) |
| 79 | |
| 80 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 81 | #define HTC_TX_PACKET_FLAG_FIXUP_NETBUF (1 << 0) |
| 82 | |
| 83 | typedef struct _HTC_RX_PACKET_INFO { |
Yue Ma | b16cf30 | 2016-03-08 18:30:25 -0800 | [diff] [blame] | 84 | uint32_t ExpectedHdr; /* HTC internal use */ |
| 85 | uint32_t HTCRxFlags; /* HTC internal use */ |
| 86 | uint32_t IndicationFlags; /* indication flags set on each RX packet indication */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 87 | } HTC_RX_PACKET_INFO; |
| 88 | |
| 89 | #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0) /* more packets on this endpoint are being fetched */ |
| 90 | |
| 91 | /* wrapper around endpoint-specific packets */ |
| 92 | typedef struct _HTC_PACKET { |
| 93 | DL_LIST ListLink; /* double link */ |
| 94 | void *pPktContext; /* caller's per packet specific context */ |
| 95 | |
Yue Ma | b16cf30 | 2016-03-08 18:30:25 -0800 | [diff] [blame] | 96 | uint8_t *pBufferStart; /* the true buffer start , the caller can |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 97 | store the real buffer start here. In |
| 98 | receive callbacks, the HTC layer sets pBuffer |
| 99 | to the start of the payload past the header. This |
| 100 | field allows the caller to reset pBuffer when it |
| 101 | recycles receive packets back to HTC */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 102 | /* |
| 103 | * Pointer to the start of the buffer. In the transmit |
| 104 | * direction this points to the start of the payload. In the |
| 105 | * receive direction, however, the buffer when queued up |
| 106 | * points to the start of the HTC header but when returned |
| 107 | * to the caller points to the start of the payload |
| 108 | */ |
Yue Ma | b16cf30 | 2016-03-08 18:30:25 -0800 | [diff] [blame] | 109 | uint8_t *pBuffer; /* payload start (RX/TX) */ |
| 110 | uint32_t BufferLength; /* length of buffer */ |
| 111 | uint32_t ActualLength; /* actual length of payload */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 112 | HTC_ENDPOINT_ID Endpoint; /* endpoint that this packet was sent/recv'd from */ |
| 113 | A_STATUS Status; /* completion status */ |
| 114 | union { |
| 115 | HTC_TX_PACKET_INFO AsTx; /* Tx Packet specific info */ |
| 116 | HTC_RX_PACKET_INFO AsRx; /* Rx Packet specific info */ |
| 117 | } PktInfo; |
| 118 | |
| 119 | /* the following fields are for internal HTC use */ |
Yue Ma | b16cf30 | 2016-03-08 18:30:25 -0800 | [diff] [blame] | 120 | uint32_t netbufOrigHeadRoom; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 121 | HTC_PACKET_COMPLETION Completion; /* completion */ |
| 122 | void *pContext; /* HTC private completion context */ |
| 123 | void *pNetBufContext; /* optimization for network-oriented data, the HTC packet |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 124 | can pass the network buffer corresponding to the HTC packet |
| 125 | lower layers may optimized the transfer knowing this is |
| 126 | a network buffer */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 127 | } HTC_PACKET; |
| 128 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 129 | #define COMPLETE_HTC_PACKET(p, status) \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 130 | { \ |
| 131 | (p)->Status = (status); \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 132 | (p)->Completion((p)->pContext, (p)); \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 135 | #define INIT_HTC_PACKET_INFO(p, b, len) \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 136 | { \ |
| 137 | (p)->pBufferStart = (b); \ |
| 138 | (p)->BufferLength = (len); \ |
| 139 | } |
| 140 | |
| 141 | /* macro to set an initial RX packet for refilling HTC */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 142 | #define SET_HTC_PACKET_INFO_RX_REFILL(p, c, b, len, ep) \ |
| 143 | do { \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 144 | (p)->pPktContext = (c); \ |
| 145 | (p)->pBuffer = (b); \ |
| 146 | (p)->pBufferStart = (b); \ |
| 147 | (p)->BufferLength = (len); \ |
| 148 | (p)->Endpoint = (ep); \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 149 | } while (0) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 150 | |
| 151 | /* fast macro to recycle an RX packet that will be re-queued to HTC */ |
| 152 | #define HTC_PACKET_RESET_RX(p) \ |
| 153 | { (p)->pBuffer = (p)->pBufferStart; (p)->ActualLength = 0; } |
| 154 | |
| 155 | /* macro to set packet parameters for TX */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 156 | #define SET_HTC_PACKET_INFO_TX(p, c, b, len, ep, tag) \ |
| 157 | do { \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 158 | (p)->pPktContext = (c); \ |
| 159 | (p)->pBuffer = (b); \ |
| 160 | (p)->ActualLength = (len); \ |
| 161 | (p)->Endpoint = (ep); \ |
| 162 | (p)->PktInfo.AsTx.Tag = (tag); \ |
| 163 | (p)->PktInfo.AsTx.Flags = 0; \ |
DARAM SUDHA | e428c4c | 2015-03-13 19:15:00 +0530 | [diff] [blame] | 164 | (p)->PktInfo.AsTx.SendFlags = 0; \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 165 | } while (0) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 166 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 167 | #define SET_HTC_PACKET_NET_BUF_CONTEXT(p, nb) \ |
| 168 | do { \ |
| 169 | (p)->pNetBufContext = (nb); \ |
| 170 | } while (0) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 171 | |
| 172 | #define GET_HTC_PACKET_NET_BUF_CONTEXT(p) (p)->pNetBufContext |
| 173 | |
| 174 | /* HTC Packet Queueing Macros */ |
| 175 | typedef struct _HTC_PACKET_QUEUE { |
| 176 | DL_LIST QueueHead; |
| 177 | int Depth; |
| 178 | } HTC_PACKET_QUEUE; |
| 179 | |
| 180 | /* initialize queue */ |
| 181 | #define INIT_HTC_PACKET_QUEUE(pQ) \ |
| 182 | { \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 183 | DL_LIST_INIT(&(pQ)->QueueHead); \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 184 | (pQ)->Depth = 0; \ |
| 185 | } |
| 186 | |
| 187 | /* enqueue HTC packet to the tail of the queue */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 188 | #define HTC_PACKET_ENQUEUE(pQ, p) \ |
| 189 | { dl_list_insert_tail(&(pQ)->QueueHead, &(p)->ListLink); \ |
| 190 | (pQ)->Depth++; \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /* enqueue HTC packet to the tail of the queue */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 194 | #define HTC_PACKET_ENQUEUE_TO_HEAD(pQ, p) \ |
| 195 | { dl_list_insert_head(&(pQ)->QueueHead, &(p)->ListLink); \ |
| 196 | (pQ)->Depth++; \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 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 */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 201 | static inline HTC_PACKET *htc_get_pkt_at_head(HTC_PACKET_QUEUE *queue) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 202 | { |
| 203 | if (queue->Depth == 0) { |
| 204 | return NULL; |
| 205 | } |
| 206 | return |
| 207 | A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(&queue->QueueHead)), |
| 208 | HTC_PACKET, ListLink); |
| 209 | } |
| 210 | |
| 211 | /* remove a packet from a queue, where-ever it is in the queue */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 212 | #define HTC_PACKET_REMOVE(pQ, p) \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 213 | { \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 214 | dl_list_remove(&(p)->ListLink); \ |
| 215 | (pQ)->Depth--; \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* dequeue an HTC packet from the head of the queue */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 219 | static inline HTC_PACKET *htc_packet_dequeue(HTC_PACKET_QUEUE *queue) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 220 | { |
| 221 | DL_LIST *pItem = dl_list_remove_item_from_head(&queue->QueueHead); |
| 222 | if (pItem != NULL) { |
| 223 | queue->Depth--; |
| 224 | return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink); |
| 225 | } |
| 226 | return NULL; |
| 227 | } |
| 228 | |
| 229 | /* dequeue an HTC packet from the tail of the queue */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 230 | static inline HTC_PACKET *htc_packet_dequeue_tail(HTC_PACKET_QUEUE *queue) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 231 | { |
| 232 | DL_LIST *pItem = dl_list_remove_item_from_tail(&queue->QueueHead); |
| 233 | if (pItem != NULL) { |
| 234 | queue->Depth--; |
| 235 | return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink); |
| 236 | } |
| 237 | return NULL; |
| 238 | } |
| 239 | |
| 240 | #define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth |
| 241 | |
| 242 | #define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint |
| 243 | #define HTC_GET_TAG_FROM_PKT(p) (p)->PktInfo.AsTx.Tag |
| 244 | |
| 245 | /* transfer the packets from one queue to the tail of another queue */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 246 | #define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest, pQSrc) \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 247 | { \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 248 | dl_list_transfer_items_to_tail(&(pQDest)->QueueHead, &(pQSrc)->QueueHead); \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 249 | (pQDest)->Depth += (pQSrc)->Depth; \ |
| 250 | (pQSrc)->Depth = 0; \ |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | * Transfer the packets from one queue to the head of another queue. |
| 255 | * This xfer_to_head(q1,q2) is basically equivalent to xfer_to_tail(q2,q1), |
| 256 | * but it updates the queue descriptor object for the initial queue to refer |
| 257 | * to the concatenated queue. |
| 258 | */ |
| 259 | #define HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(pQDest, pQSrc) \ |
| 260 | { \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 261 | dl_list_transfer_items_to_head(&(pQDest)->QueueHead, &(pQSrc)->QueueHead); \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 262 | (pQDest)->Depth += (pQSrc)->Depth; \ |
| 263 | (pQSrc)->Depth = 0; \ |
| 264 | } |
| 265 | |
| 266 | /* fast version to init and add a single packet to a queue */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 267 | #define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ, pP) \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 268 | { \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 269 | DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead, &(pP)->ListLink) \ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 270 | (pQ)->Depth = 1; \ |
| 271 | } |
| 272 | |
| 273 | #define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 274 | ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead, (pPTemp), HTC_PACKET, ListLink) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 275 | |
| 276 | #define HTC_PACKET_QUEUE_ITERATE_IS_VALID(pQ) ITERATE_IS_VALID(&(pQ)->QueueHead) |
| 277 | #define HTC_PACKET_QUEUE_ITERATE_RESET(pQ) ITERATE_RESET(&(pQ)->QueueHead) |
| 278 | |
| 279 | #define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END |
| 280 | |
| 281 | #endif /*HTC_PACKET_H_ */ |