blob: 6eb8205df1718d4b4c8e1cc6ea5d92927e8b6d55 [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
Manikandan Mohane3e209e2017-04-13 20:19:26 -070055/**
56 * struct htc_tx_packet_info - HTC TX packet information
57 * @Tag: tag used to selective flush packets
58 * @CreditsUsed: number of credits used for this TX packet (HTC internal)
59 * @SendFlags: send flags (HTC internal)
60 * @SeqNo: internal seq no for debugging (HTC internal)
61 * @Flags: Internal use
62 */
63struct htc_tx_packet_info {
64 HTC_TX_TAG Tag;
65 int CreditsUsed;
66 uint8_t SendFlags;
67 int SeqNo;
68 uint32_t Flags;
69};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080070
Houston Hoffmanc5141b02015-11-18 02:36:30 -080071/**
72 * HTC_TX_PACKET_TAG_XXX - #defines for tagging packets for special handling
73 * HTC_TX_PACKET_TAG_ALL: zero is reserved and used to flush ALL packets
74 * HTC_TX_PACKET_TAG_INTERNAL: internal tags start here
75 * HTC_TX_PACKET_TAG_USER_DEFINED: user-defined tags start here
76 * HTC_TX_PACKET_TAG_BUNDLED: indicate this is a bundled tx packet
77 * HTC_TX_PACKET_TAG_AUTO_PM: indicate a power management wmi command
78 */
79#define HTC_TX_PACKET_TAG_ALL 0
80#define HTC_TX_PACKET_TAG_INTERNAL 1
81#define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_TX_PACKET_TAG_INTERNAL + 9)
82#define HTC_TX_PACKET_TAG_BUNDLED (HTC_TX_PACKET_TAG_USER_DEFINED + 1)
83#define HTC_TX_PACKET_TAG_AUTO_PM (HTC_TX_PACKET_TAG_USER_DEFINED + 2)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080084
Houston Hoffman1dd22762015-11-10 11:35:49 -080085/* Tag packet for runtime put after sending */
86#define HTC_TX_PACKET_TAG_RUNTIME_PUT (HTC_TX_PACKET_TAG_USER_DEFINED + 3)
87
88
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080089#define HTC_TX_PACKET_FLAG_FIXUP_NETBUF (1 << 0)
90
Manikandan Mohane3e209e2017-04-13 20:19:26 -070091/**
92 * struct htc_rx_packet_info - HTC RX Packet information
93 * @ExpectedHdr: HTC Internal use
94 * @HTCRxFlags: HTC Internal use
95 * @IndicationFlags: indication flags set on each RX packet indication
96 */
97struct htc_rx_packet_info {
98 uint32_t ExpectedHdr;
99 uint32_t HTCRxFlags;
100 uint32_t IndicationFlags;
101};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800102
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700103/* more packets on this endpoint are being fetched */
104#define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0)
Himanshu Agarwal974d0a52017-03-08 21:13:51 +0530105#define HTC_PACKET_MAGIC_COOKIE 0xdeadbeef
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800106
107/* wrapper around endpoint-specific packets */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700108/**
109 * struct _HTC_PACKET - HTC Packet data structure
110 * @ListLink: double link
111 * @pPktContext: caller's per packet specific context
112 * @pBufferStart: The true buffer start, the caller can store the real buffer
113 * start here. In receive callbacks, the HTC layer sets pBuffer
114 * to the start of the payload past the header. This field allows
115 * the caller to reset pBuffer when it recycles receive packets
116 * back to HTC
117 * @pBuffer: payload start (RX/TX)
118 * @BufferLength: length of buffer
119 * @ActualLength: actual length of payload
120 * @Endpoint: endpoint that this packet was sent/recv'd from
121 * @Status: completion status
122 * @PktInfo: Packet specific info
123 * @netbufOrigHeadRoom: Original head room of skb
124 * @Completion: completion
125 * @pContext: HTC private completion context
126 * @pNetBufContext: optimization for network-oriented data, the HTC packet can
127 * pass the network buffer corresponding to the HTC packet
128 * lower layers may optimized the transfer knowing this is a
129 * network buffer
130 * @magic_cookie: HTC Magic cookie
131 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800132typedef struct _HTC_PACKET {
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700133 DL_LIST ListLink;
134 void *pPktContext;
135 uint8_t *pBufferStart;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800136 /*
137 * Pointer to the start of the buffer. In the transmit
138 * direction this points to the start of the payload. In the
139 * receive direction, however, the buffer when queued up
140 * points to the start of the HTC header but when returned
141 * to the caller points to the start of the payload
142 */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700143 uint8_t *pBuffer;
144 uint32_t BufferLength;
145 uint32_t ActualLength;
146 HTC_ENDPOINT_ID Endpoint;
Rakesh Pillai13146452017-06-22 12:52:31 +0530147 QDF_STATUS Status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800148 union {
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700149 struct htc_tx_packet_info AsTx;
150 struct htc_rx_packet_info AsRx;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800151 } PktInfo;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800152 /* the following fields are for internal HTC use */
Yue Mab16cf302016-03-08 18:30:25 -0800153 uint32_t netbufOrigHeadRoom;
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700154 HTC_PACKET_COMPLETION Completion;
155 void *pContext;
156 void *pNetBufContext;
Himanshu Agarwal974d0a52017-03-08 21:13:51 +0530157 uint32_t magic_cookie;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800158} HTC_PACKET;
159
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530160#define COMPLETE_HTC_PACKET(p, status) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800161 { \
162 (p)->Status = (status); \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530163 (p)->Completion((p)->pContext, (p)); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800164 }
165
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530166#define INIT_HTC_PACKET_INFO(p, b, len) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800167 { \
168 (p)->pBufferStart = (b); \
169 (p)->BufferLength = (len); \
170 }
171
172/* macro to set an initial RX packet for refilling HTC */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530173#define SET_HTC_PACKET_INFO_RX_REFILL(p, c, b, len, ep) \
174 do { \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800175 (p)->pPktContext = (c); \
176 (p)->pBuffer = (b); \
177 (p)->pBufferStart = (b); \
178 (p)->BufferLength = (len); \
179 (p)->Endpoint = (ep); \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530180 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800181
182/* fast macro to recycle an RX packet that will be re-queued to HTC */
183#define HTC_PACKET_RESET_RX(p) \
184 { (p)->pBuffer = (p)->pBufferStart; (p)->ActualLength = 0; }
185
186/* macro to set packet parameters for TX */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530187#define SET_HTC_PACKET_INFO_TX(p, c, b, len, ep, tag) \
188 do { \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800189 (p)->pPktContext = (c); \
190 (p)->pBuffer = (b); \
191 (p)->ActualLength = (len); \
192 (p)->Endpoint = (ep); \
193 (p)->PktInfo.AsTx.Tag = (tag); \
194 (p)->PktInfo.AsTx.Flags = 0; \
DARAM SUDHAe428c4c2015-03-13 19:15:00 +0530195 (p)->PktInfo.AsTx.SendFlags = 0; \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530196 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800197
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530198#define SET_HTC_PACKET_NET_BUF_CONTEXT(p, nb) \
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700199 { \
200 (p)->pNetBufContext = (nb); \
201 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800202
203#define GET_HTC_PACKET_NET_BUF_CONTEXT(p) (p)->pNetBufContext
204
205/* HTC Packet Queueing Macros */
206typedef struct _HTC_PACKET_QUEUE {
207 DL_LIST QueueHead;
208 int Depth;
209} HTC_PACKET_QUEUE;
210
211/* initialize queue */
212#define INIT_HTC_PACKET_QUEUE(pQ) \
213 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530214 DL_LIST_INIT(&(pQ)->QueueHead); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800215 (pQ)->Depth = 0; \
216 }
217
218/* enqueue HTC packet to the tail of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530219#define HTC_PACKET_ENQUEUE(pQ, p) \
220 { dl_list_insert_tail(&(pQ)->QueueHead, &(p)->ListLink); \
221 (pQ)->Depth++; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800222 }
223
224/* enqueue HTC packet to the tail of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530225#define HTC_PACKET_ENQUEUE_TO_HEAD(pQ, p) \
226 { dl_list_insert_head(&(pQ)->QueueHead, &(p)->ListLink); \
227 (pQ)->Depth++; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800228 }
229/* test if a queue is empty */
230#define HTC_QUEUE_EMPTY(pQ) ((pQ)->Depth == 0)
231/* get packet at head without removing it */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530232static inline HTC_PACKET *htc_get_pkt_at_head(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800233{
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700234 if (queue->Depth == 0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800235 return NULL;
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700236
237 return A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(
238 &queue->QueueHead)),
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800239 HTC_PACKET, ListLink);
240}
241
242/* remove a packet from a queue, where-ever it is in the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530243#define HTC_PACKET_REMOVE(pQ, p) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800244 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530245 dl_list_remove(&(p)->ListLink); \
246 (pQ)->Depth--; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800247 }
248
249/* dequeue an HTC packet from the head of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530250static inline HTC_PACKET *htc_packet_dequeue(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800251{
252 DL_LIST *pItem = dl_list_remove_item_from_head(&queue->QueueHead);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700253
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800254 if (pItem != NULL) {
255 queue->Depth--;
256 return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
257 }
258 return NULL;
259}
260
261/* dequeue an HTC packet from the tail of the queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530262static inline HTC_PACKET *htc_packet_dequeue_tail(HTC_PACKET_QUEUE *queue)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800263{
264 DL_LIST *pItem = dl_list_remove_item_from_tail(&queue->QueueHead);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700265
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800266 if (pItem != NULL) {
267 queue->Depth--;
268 return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
269 }
270 return NULL;
271}
272
273#define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth
274
275#define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint
276#define HTC_GET_TAG_FROM_PKT(p) (p)->PktInfo.AsTx.Tag
277
278/* transfer the packets from one queue to the tail of another queue */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700279#define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest, pQSrc) \
280 { \
281 dl_list_transfer_items_to_tail(&(pQDest)->QueueHead, \
282 &(pQSrc)->QueueHead); \
283 (pQDest)->Depth += (pQSrc)->Depth; \
284 (pQSrc)->Depth = 0; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800285 }
286
287/*
288 * Transfer the packets from one queue to the head of another queue.
289 * This xfer_to_head(q1,q2) is basically equivalent to xfer_to_tail(q2,q1),
290 * but it updates the queue descriptor object for the initial queue to refer
291 * to the concatenated queue.
292 */
293#define HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(pQDest, pQSrc) \
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700294 { \
295 dl_list_transfer_items_to_head(&(pQDest)->QueueHead, \
296 &(pQSrc)->QueueHead); \
297 (pQDest)->Depth += (pQSrc)->Depth; \
298 (pQSrc)->Depth = 0; \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800299 }
300
301/* fast version to init and add a single packet to a queue */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530302#define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ, pP) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800303 { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530304 DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead, &(pP)->ListLink) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800305 (pQ)->Depth = 1; \
306 }
307
308#define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700309 ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead, \
310 (pPTemp), HTC_PACKET, ListLink)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800311
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700312#define HTC_PACKET_QUEUE_ITERATE_IS_VALID(pQ) ITERATE_IS_VALID(&(pQ)->QueueHead)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800313#define HTC_PACKET_QUEUE_ITERATE_RESET(pQ) ITERATE_RESET(&(pQ)->QueueHead)
314
315#define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END
316
Himanshu Agarwal974d0a52017-03-08 21:13:51 +0530317/**
318 * htc_packet_set_magic_cookie() - set magic cookie in htc packet
319 * htc_pkt - pointer to htc packet
320 * value - value to set in magic cookie
321 *
322 * This API sets the magic cookie passed in htc packet.
323 *
324 * Return : None
325 */
326static inline void htc_packet_set_magic_cookie(HTC_PACKET *htc_pkt,
327 uint32_t value)
328{
329 htc_pkt->magic_cookie = value;
330}
331
332/**
333 * htc_packet_set_magic_cookie() - get magic cookie in htc packet
334 * htc_pkt - pointer to htc packet
335 *
336 * This API returns the magic cookie in htc packet.
337 *
338 * Return : magic cookie
339 */
340static inline uint32_t htc_packet_get_magic_cookie(HTC_PACKET *htc_pkt)
341{
342 return htc_pkt->magic_cookie;
343}
344
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800345#endif /*HTC_PACKET_H_ */