blob: bb23dcbf3cc05b08c39ac5a4039d9ae3c54c2235 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Himanshu Agarwal974d0a52017-03-08 21:13:51 +05302 * Copyright (c) 2013-2014, 2016-2017 The Linux Foundation. All rights reserved.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08003 *
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 Dhavalid5c9f1c2015-11-08 19:04:44 -080032#include "dl_list.h"
33
34/* ------ Endpoint IDS ------ */
35typedef 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
49struct _HTC_PACKET;
50
51typedef void (*HTC_PACKET_COMPLETION)(void *, struct _HTC_PACKET *);
52
Yue Mab16cf302016-03-08 18:30:25 -080053typedef uint16_t HTC_TX_TAG;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080054
55typedef 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 Mab16cf302016-03-08 18:30:25 -080058 uint8_t SendFlags; /* send flags (HTC internal) */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080059 int SeqNo; /* internal seq no for debugging (HTC internal) */
Yue Mab16cf302016-03-08 18:30:25 -080060 uint32_t Flags; /* internal use */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080061} HTC_TX_PACKET_INFO;
62
Houston Hoffmanc5141b02015-11-18 02:36:30 -080063/**
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 Dhavalid5c9f1c2015-11-08 19:04:44 -080076
Houston Hoffman1dd22762015-11-10 11:35:49 -080077/* 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 Dhavalid5c9f1c2015-11-08 19:04:44 -080081#define HTC_TX_PACKET_FLAG_FIXUP_NETBUF (1 << 0)
82
83typedef struct _HTC_RX_PACKET_INFO {
Yue Mab16cf302016-03-08 18:30:25 -080084 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 Dhavalid5c9f1c2015-11-08 19:04:44 -080087} HTC_RX_PACKET_INFO;
88
89#define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0) /* more packets on this endpoint are being fetched */
Himanshu Agarwal974d0a52017-03-08 21:13:51 +053090#define HTC_PACKET_MAGIC_COOKIE 0xdeadbeef
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080091
92/* wrapper around endpoint-specific packets */
93typedef struct _HTC_PACKET {
94 DL_LIST ListLink; /* double link */
95 void *pPktContext; /* caller's per packet specific context */
96
Yue Mab16cf302016-03-08 18:30:25 -080097 uint8_t *pBufferStart; /* the true buffer start , the caller can
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053098 store the real buffer start here. In
99 receive callbacks, the HTC layer sets pBuffer
100 to the start of the payload past the header. This
101 field allows the caller to reset pBuffer when it
102 recycles receive packets back to HTC */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800103 /*
104 * Pointer to the start of the buffer. In the transmit
105 * direction this points to the start of the payload. In the
106 * receive direction, however, the buffer when queued up
107 * points to the start of the HTC header but when returned
108 * to the caller points to the start of the payload
109 */
Yue Mab16cf302016-03-08 18:30:25 -0800110 uint8_t *pBuffer; /* payload start (RX/TX) */
111 uint32_t BufferLength; /* length of buffer */
112 uint32_t ActualLength; /* actual length of payload */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800113 HTC_ENDPOINT_ID Endpoint; /* endpoint that this packet was sent/recv'd from */
114 A_STATUS Status; /* completion status */
115 union {
116 HTC_TX_PACKET_INFO AsTx; /* Tx Packet specific info */
117 HTC_RX_PACKET_INFO AsRx; /* Rx Packet specific info */
118 } PktInfo;
119
120 /* the following fields are for internal HTC use */
Yue Mab16cf302016-03-08 18:30:25 -0800121 uint32_t netbufOrigHeadRoom;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800122 HTC_PACKET_COMPLETION Completion; /* completion */
123 void *pContext; /* HTC private completion context */
124 void *pNetBufContext; /* optimization for network-oriented data, the HTC packet
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530125 can pass the network buffer corresponding to the HTC packet
126 lower layers may optimized the transfer knowing this is
127 a network buffer */
Himanshu Agarwal974d0a52017-03-08 21:13:51 +0530128 uint32_t magic_cookie;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800129} HTC_PACKET;
130
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530131#define COMPLETE_HTC_PACKET(p, status) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800132 { \
133 (p)->Status = (status); \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530134 (p)->Completion((p)->pContext, (p)); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800135 }
136
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530137#define INIT_HTC_PACKET_INFO(p, b, len) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800138 { \
139 (p)->pBufferStart = (b); \
140 (p)->BufferLength = (len); \
141 }
142
143/* macro to set an initial RX packet for refilling HTC */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530144#define SET_HTC_PACKET_INFO_RX_REFILL(p, c, b, len, ep) \
145 do { \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800146 (p)->pPktContext = (c); \
147 (p)->pBuffer = (b); \
148 (p)->pBufferStart = (b); \
149 (p)->BufferLength = (len); \
150 (p)->Endpoint = (ep); \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530151 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800152
153/* fast macro to recycle an RX packet that will be re-queued to HTC */
154#define HTC_PACKET_RESET_RX(p) \
155 { (p)->pBuffer = (p)->pBufferStart; (p)->ActualLength = 0; }
156
157/* macro to set packet parameters for TX */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530158#define SET_HTC_PACKET_INFO_TX(p, c, b, len, ep, tag) \
159 do { \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800160 (p)->pPktContext = (c); \
161 (p)->pBuffer = (b); \
162 (p)->ActualLength = (len); \
163 (p)->Endpoint = (ep); \
164 (p)->PktInfo.AsTx.Tag = (tag); \
165 (p)->PktInfo.AsTx.Flags = 0; \
DARAM SUDHAe428c4c2015-03-13 19:15:00 +0530166 (p)->PktInfo.AsTx.SendFlags = 0; \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530167 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800168
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530169#define SET_HTC_PACKET_NET_BUF_CONTEXT(p, nb) \
170 do { \
171 (p)->pNetBufContext = (nb); \
172 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800173
174#define GET_HTC_PACKET_NET_BUF_CONTEXT(p) (p)->pNetBufContext
175
176/* HTC Packet Queueing Macros */
177typedef struct _HTC_PACKET_QUEUE {
178 DL_LIST QueueHead;
179 int Depth;
180} HTC_PACKET_QUEUE;
181
182/* initialize queue */
183#define INIT_HTC_PACKET_QUEUE(pQ) \
184 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530185 DL_LIST_INIT(&(pQ)->QueueHead); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800186 (pQ)->Depth = 0; \
187 }
188
189/* enqueue HTC packet to the tail of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530190#define HTC_PACKET_ENQUEUE(pQ, p) \
191 { dl_list_insert_tail(&(pQ)->QueueHead, &(p)->ListLink); \
192 (pQ)->Depth++; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800193 }
194
195/* enqueue HTC packet to the tail of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530196#define HTC_PACKET_ENQUEUE_TO_HEAD(pQ, p) \
197 { dl_list_insert_head(&(pQ)->QueueHead, &(p)->ListLink); \
198 (pQ)->Depth++; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800199 }
200/* test if a queue is empty */
201#define HTC_QUEUE_EMPTY(pQ) ((pQ)->Depth == 0)
202/* get packet at head without removing it */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530203static inline HTC_PACKET *htc_get_pkt_at_head(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800204{
205 if (queue->Depth == 0) {
206 return NULL;
207 }
208 return
209 A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(&queue->QueueHead)),
210 HTC_PACKET, ListLink);
211}
212
213/* remove a packet from a queue, where-ever it is in the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530214#define HTC_PACKET_REMOVE(pQ, p) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800215 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530216 dl_list_remove(&(p)->ListLink); \
217 (pQ)->Depth--; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800218 }
219
220/* dequeue an HTC packet from the head of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530221static inline HTC_PACKET *htc_packet_dequeue(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800222{
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
231/* dequeue an HTC packet from the tail of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530232static inline HTC_PACKET *htc_packet_dequeue_tail(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800233{
234 DL_LIST *pItem = dl_list_remove_item_from_tail(&queue->QueueHead);
235 if (pItem != NULL) {
236 queue->Depth--;
237 return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
238 }
239 return NULL;
240}
241
242#define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth
243
244#define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint
245#define HTC_GET_TAG_FROM_PKT(p) (p)->PktInfo.AsTx.Tag
246
247/* transfer the packets from one queue to the tail of another queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530248#define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest, pQSrc) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800249 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530250 dl_list_transfer_items_to_tail(&(pQDest)->QueueHead, &(pQSrc)->QueueHead); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800251 (pQDest)->Depth += (pQSrc)->Depth; \
252 (pQSrc)->Depth = 0; \
253 }
254
255/*
256 * Transfer the packets from one queue to the head of another queue.
257 * This xfer_to_head(q1,q2) is basically equivalent to xfer_to_tail(q2,q1),
258 * but it updates the queue descriptor object for the initial queue to refer
259 * to the concatenated queue.
260 */
261#define HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(pQDest, pQSrc) \
262 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530263 dl_list_transfer_items_to_head(&(pQDest)->QueueHead, &(pQSrc)->QueueHead); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800264 (pQDest)->Depth += (pQSrc)->Depth; \
265 (pQSrc)->Depth = 0; \
266 }
267
268/* fast version to init and add a single packet to a queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530269#define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ, pP) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800270 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530271 DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead, &(pP)->ListLink) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800272 (pQ)->Depth = 1; \
273 }
274
275#define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530276 ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead, (pPTemp), HTC_PACKET, ListLink)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800277
278#define HTC_PACKET_QUEUE_ITERATE_IS_VALID(pQ) ITERATE_IS_VALID(&(pQ)->QueueHead)
279#define HTC_PACKET_QUEUE_ITERATE_RESET(pQ) ITERATE_RESET(&(pQ)->QueueHead)
280
281#define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END
282
Himanshu Agarwal974d0a52017-03-08 21:13:51 +0530283/**
284 * htc_packet_set_magic_cookie() - set magic cookie in htc packet
285 * htc_pkt - pointer to htc packet
286 * value - value to set in magic cookie
287 *
288 * This API sets the magic cookie passed in htc packet.
289 *
290 * Return : None
291 */
292static inline void htc_packet_set_magic_cookie(HTC_PACKET *htc_pkt,
293 uint32_t value)
294{
295 htc_pkt->magic_cookie = value;
296}
297
298/**
299 * htc_packet_set_magic_cookie() - get magic cookie in htc packet
300 * htc_pkt - pointer to htc packet
301 *
302 * This API returns the magic cookie in htc packet.
303 *
304 * Return : magic cookie
305 */
306static inline uint32_t htc_packet_get_magic_cookie(HTC_PACKET *htc_pkt)
307{
308 return htc_pkt->magic_cookie;
309}
310
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800311#endif /*HTC_PACKET_H_ */