blob: 7d13b40ae55c7745bbe21e25f22510c0651e7dac [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Houston Hoffmanc5141b02015-11-18 02:36:30 -08002 * Copyright (c) 2013-2014, 2016 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 */
90
91/* wrapper around endpoint-specific packets */
92typedef struct _HTC_PACKET {
93 DL_LIST ListLink; /* double link */
94 void *pPktContext; /* caller's per packet specific context */
95
Yue Mab16cf302016-03-08 18:30:25 -080096 uint8_t *pBufferStart; /* the true buffer start , the caller can
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053097 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 Dhavalid5c9f1c2015-11-08 19:04:44 -0800102 /*
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 Mab16cf302016-03-08 18:30:25 -0800109 uint8_t *pBuffer; /* payload start (RX/TX) */
110 uint32_t BufferLength; /* length of buffer */
111 uint32_t ActualLength; /* actual length of payload */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800112 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 Mab16cf302016-03-08 18:30:25 -0800120 uint32_t netbufOrigHeadRoom;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800121 HTC_PACKET_COMPLETION Completion; /* completion */
122 void *pContext; /* HTC private completion context */
123 void *pNetBufContext; /* optimization for network-oriented data, the HTC packet
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530124 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 Dhavalid5c9f1c2015-11-08 19:04:44 -0800127} HTC_PACKET;
128
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530129#define COMPLETE_HTC_PACKET(p, status) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800130 { \
131 (p)->Status = (status); \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530132 (p)->Completion((p)->pContext, (p)); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800133 }
134
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530135#define INIT_HTC_PACKET_INFO(p, b, len) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800136 { \
137 (p)->pBufferStart = (b); \
138 (p)->BufferLength = (len); \
139 }
140
141/* macro to set an initial RX packet for refilling HTC */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530142#define SET_HTC_PACKET_INFO_RX_REFILL(p, c, b, len, ep) \
143 do { \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800144 (p)->pPktContext = (c); \
145 (p)->pBuffer = (b); \
146 (p)->pBufferStart = (b); \
147 (p)->BufferLength = (len); \
148 (p)->Endpoint = (ep); \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530149 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800150
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, Anuragfc06aa92016-03-03 19:05:05 +0530156#define SET_HTC_PACKET_INFO_TX(p, c, b, len, ep, tag) \
157 do { \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800158 (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 SUDHAe428c4c2015-03-13 19:15:00 +0530164 (p)->PktInfo.AsTx.SendFlags = 0; \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530165 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800166
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530167#define SET_HTC_PACKET_NET_BUF_CONTEXT(p, nb) \
168 do { \
169 (p)->pNetBufContext = (nb); \
170 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800171
172#define GET_HTC_PACKET_NET_BUF_CONTEXT(p) (p)->pNetBufContext
173
174/* HTC Packet Queueing Macros */
175typedef 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, Anuragfc06aa92016-03-03 19:05:05 +0530183 DL_LIST_INIT(&(pQ)->QueueHead); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800184 (pQ)->Depth = 0; \
185 }
186
187/* enqueue HTC packet to the tail of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530188#define HTC_PACKET_ENQUEUE(pQ, p) \
189 { dl_list_insert_tail(&(pQ)->QueueHead, &(p)->ListLink); \
190 (pQ)->Depth++; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800191 }
192
193/* enqueue HTC packet to the tail of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530194#define HTC_PACKET_ENQUEUE_TO_HEAD(pQ, p) \
195 { dl_list_insert_head(&(pQ)->QueueHead, &(p)->ListLink); \
196 (pQ)->Depth++; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800197 }
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, Anuragfc06aa92016-03-03 19:05:05 +0530201static inline HTC_PACKET *htc_get_pkt_at_head(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800202{
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, Anuragfc06aa92016-03-03 19:05:05 +0530212#define HTC_PACKET_REMOVE(pQ, p) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800213 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530214 dl_list_remove(&(p)->ListLink); \
215 (pQ)->Depth--; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800216 }
217
218/* dequeue an HTC packet from the head of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530219static inline HTC_PACKET *htc_packet_dequeue(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800220{
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, Anuragfc06aa92016-03-03 19:05:05 +0530230static inline HTC_PACKET *htc_packet_dequeue_tail(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800231{
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, Anuragfc06aa92016-03-03 19:05:05 +0530246#define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest, pQSrc) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800247 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530248 dl_list_transfer_items_to_tail(&(pQDest)->QueueHead, &(pQSrc)->QueueHead); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800249 (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, Anuragfc06aa92016-03-03 19:05:05 +0530261 dl_list_transfer_items_to_head(&(pQDest)->QueueHead, &(pQSrc)->QueueHead); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800262 (pQDest)->Depth += (pQSrc)->Depth; \
263 (pQSrc)->Depth = 0; \
264 }
265
266/* fast version to init and add a single packet to a queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530267#define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ, pP) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800268 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530269 DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead, &(pP)->ListLink) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800270 (pQ)->Depth = 1; \
271 }
272
273#define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530274 ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead, (pPTemp), HTC_PACKET, ListLink)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800275
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_ */