blob: 09d7d0dcf28188f7ea8d957faeef7c40a3c39b3d [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Dustin Brown1e61fbc2018-01-08 12:30:30 -08002 * Copyright (c) 2013-2014, 2016-2018 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_API_H_
29#define _HTC_API_H_
30
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080031#include <htc.h>
32#include <htc_services.h>
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053033#include <qdf_types.h> /* qdf_device_t */
Yue Mab16cf302016-03-08 18:30:25 -080034#include "htc_packet.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080035
36#ifdef __cplusplus
37extern "C" {
38#endif /* __cplusplus */
39
40/* TODO.. for BMI */
41#define ENDPOINT1 0
42/* TODO -remove me, but we have to fix BMI first */
43#define HTC_MAILBOX_NUM_MAX 4
44
45/* this is the amount of header room required by users of HTC */
46#define HTC_HEADER_LEN HTC_HDR_LENGTH
47
Houston Hoffman93481862016-05-05 18:49:59 -070048#define HTC_HTT_TRANSFER_HDRSIZE 24
49
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080050typedef void *HTC_HANDLE;
51
Yue Mab16cf302016-03-08 18:30:25 -080052typedef uint16_t HTC_SERVICE_ID;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080053
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053054typedef void (*HTC_TARGET_FAILURE)(void *Instance, QDF_STATUS Status);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080055
Manikandan Mohane3e209e2017-04-13 20:19:26 -070056struct htc_init_info {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080057 void *pContext; /* context for target notifications */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053058 void (*TargetFailure)(void *Instance, QDF_STATUS Status);
Houston Hoffman61fad9f2016-04-14 17:09:37 -070059 void (*TargetSendSuspendComplete)(void *ctx, bool is_nack);
Mukul Sharma51420172017-03-06 14:28:56 +053060 void (*target_initial_wakeup_cb)(void *cb_ctx);
61 void *target_psoc;
Manikandan Mohane3e209e2017-04-13 20:19:26 -070062};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080063
64/* Struct for HTC layer packet stats*/
65struct ol_ath_htc_stats {
66 int htc_get_pkt_q_fail_count;
67 int htc_pkt_q_empty_count;
68 int htc_send_q_empty_count;
69};
70
Houston Hoffman47e387b2015-10-20 17:04:42 -070071/* To resume HTT Tx queue during runtime resume */
72typedef void (*HTC_EP_RESUME_TX_QUEUE)(void *);
73
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080074/* per service connection send completion */
75typedef void (*HTC_EP_SEND_PKT_COMPLETE)(void *, HTC_PACKET *);
76/* per service connection callback when a plurality of packets have been sent
Manikandan Mohane3e209e2017-04-13 20:19:26 -070077 * The HTC_PACKET_QUEUE is a temporary queue object (e.g. freed on return from
78 * the callback) to hold a list of completed send packets.
79 * If the handler cannot fully traverse the packet queue before returning, it
80 * should transfer the items of the queue into the caller's private queue using:
81 * HTC_PACKET_ENQUEUE()
82 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080083typedef void (*HTC_EP_SEND_PKT_COMP_MULTIPLE)(void *,
84 HTC_PACKET_QUEUE *);
85/* per service connection pkt received */
86typedef void (*HTC_EP_RECV_PKT)(void *, HTC_PACKET *);
87/* per service connection callback when a plurality of packets are received
Manikandan Mohane3e209e2017-04-13 20:19:26 -070088 * The HTC_PACKET_QUEUE is a temporary queue object (e.g. freed on return from
89 * the callback) to hold a list of recv packets.
90 * If the handler cannot fully traverse the packet queue before returning, it
91 * should transfer the items of the queue into the caller's private queue using:
92 * HTC_PACKET_ENQUEUE()
93 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080094typedef void (*HTC_EP_RECV_PKT_MULTIPLE)(void *, HTC_PACKET_QUEUE *);
95
96/* Optional per service connection receive buffer re-fill callback,
Manikandan Mohane3e209e2017-04-13 20:19:26 -070097 * On some OSes (like Linux) packets are allocated from a global pool and
98 * indicated up to the network stack. The driver never gets the packets back
99 * from the OS. For these OSes a refill callback can be used to allocate and
100 * re-queue buffers into HTC.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800101 *
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700102 * On other OSes, the network stack can call into the driver's OS-specific
103 * "return_packet" handler and the driver can re-queue these buffers into HTC.
104 * In this regard a refill callback is unnecessary
105 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800106typedef void (*HTC_EP_RECV_REFILL)(void *, HTC_ENDPOINT_ID Endpoint);
107
108/* Optional per service connection receive buffer allocation callback.
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700109 * On some systems packet buffers are an extremely limited resource. Rather than
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800110 * queue largest-possible-sized buffers to HTC, some systems would rather
111 * allocate a specific size as the packet is received. The trade off is
112 * slightly more processing (callback invoked for each RX packet)
113 * for the benefit of committing fewer buffer resources into HTC.
114 *
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700115 * The callback is provided the length of the pending packet to fetch. This
116 * includes the HTC header length plus the length of payload. The callback can
117 * return a pointer to the allocated HTC packet for immediate use.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800118 *
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700119 * Alternatively a variant of this handler can be used to allocate large receive
120 * packets as needed. For example an application can use the refill mechanism
121 * for normal packets and the recv-alloc mechanism to handle the case where a
122 * large packet buffer is required. This can significantly reduce the
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800123 * amount of "committed" memory used to receive packets.
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700124 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800125typedef HTC_PACKET *(*HTC_EP_RECV_ALLOC)(void *,
126 HTC_ENDPOINT_ID Endpoint,
127 int Length);
128
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700129enum htc_send_full_action {
130 /* packet that overflowed should be kept in the queue */
131 HTC_SEND_FULL_KEEP = 0,
132 /* packet that overflowed should be dropped */
133 HTC_SEND_FULL_DROP = 1,
134};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800135
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700136/* Optional per service connection callback when a send queue is full. This can
137 * occur if host continues queueing up TX packets faster than credits can arrive
138 * To prevent the host (on some Oses like Linux) from continuously queueing pkts
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800139 * and consuming resources, this callback is provided so that that the host
140 * can disable TX in the subsystem (i.e. network stack).
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700141 * This callback is invoked for each packet that "overflows" the HTC queue. The
142 * callback can determine whether the new packet that overflowed the queue can
143 * be kept (HTC_SEND_FULL_KEEP) or dropped (HTC_SEND_FULL_DROP). If a packet is
144 * dropped, the EpTxComplete handler will be called and the packet's status
145 * field will be set to A_NO_RESOURCE.
146 * Other OSes require a "per-packet" indication for each completed TX packet,
147 * this closed loop mechanism will prevent the network stack from overunning the
148 * NIC. The packet to keep or drop is passed for inspection to the registered
149 * handler the handler must ONLY inspect the packet, it may not free or reclaim
150 * the packet.
151 */
152typedef enum htc_send_full_action (*HTC_EP_SEND_QUEUE_FULL)(void *,
153 HTC_PACKET *pPacket);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800154
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700155struct htc_ep_callbacks {
156 /* context for each callback */
157 void *pContext;
158 /* tx completion callback for connected endpoint */
159 HTC_EP_SEND_PKT_COMPLETE EpTxComplete;
160 /* receive callback for connected endpoint */
161 HTC_EP_RECV_PKT EpRecv;
162 /* OPTIONAL receive re-fill callback for connected endpoint */
163 HTC_EP_RECV_REFILL EpRecvRefill;
164 /* OPTIONAL send full callback */
165 HTC_EP_SEND_QUEUE_FULL EpSendFull;
166 /* OPTIONAL recv allocation callback */
167 HTC_EP_RECV_ALLOC EpRecvAlloc;
168 /* OPTIONAL recv allocation callback based on a threshold */
169 HTC_EP_RECV_ALLOC EpRecvAllocThresh;
170 /* OPTIONAL completion handler for multiple complete
171 * indications (EpTxComplete must be NULL)
172 */
173 HTC_EP_SEND_PKT_COMP_MULTIPLE EpTxCompleteMultiple;
Dustin Brown1e61fbc2018-01-08 12:30:30 -0800174
Houston Hoffman47e387b2015-10-20 17:04:42 -0700175 HTC_EP_RESUME_TX_QUEUE ep_resume_tx_queue;
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700176 /* if EpRecvAllocThresh is non-NULL, HTC will compare the
177 * threshold value to the current recv packet length and invoke
178 * the EpRecvAllocThresh callback to acquire a packet buffer
179 */
180 int RecvAllocThreshold;
181 /* if a EpRecvRefill handler is provided, this value
182 * can be used to set a trigger refill callback
183 * when the recv queue drops below this value
184 * if set to 0, the refill is only called when packets
185 * are empty
186 */
187 int RecvRefillWaterMark;
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700188};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800189
190/* service connection information */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700191struct htc_service_connect_req {
192 /* service ID to connect to */
193 HTC_SERVICE_ID service_id;
194 /* connection flags, see htc protocol definition */
195 uint16_t ConnectionFlags;
196 /* ptr to optional service-specific meta-data */
197 uint8_t *pMetaData;
198 /* optional meta data length */
199 uint8_t MetaDataLength;
200 /* endpoint callbacks */
201 struct htc_ep_callbacks EpCallbacks;
202 /* maximum depth of any send queue */
203 int MaxSendQueueDepth;
204 /* HTC flags for the host-side (local) connection */
205 uint32_t LocalConnectionFlags;
206 /* override max message size in send direction */
207 unsigned int MaxSendMsgSize;
208};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800209
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700210/* enable send bundle padding for this endpoint */
211#define HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING (1 << 0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800212
213/* service connection response information */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700214struct htc_service_connect_resp {
215 /* caller supplied buffer to optional meta-data */
216 uint8_t *pMetaData;
217 /* length of caller supplied buffer */
218 uint8_t BufferLength;
219 /* actual length of meta data */
220 uint8_t ActualLength;
221 /* endpoint to communicate over */
222 HTC_ENDPOINT_ID Endpoint;
223 /* max length of all messages over this endpoint */
224 unsigned int MaxMsgLength;
225 /* connect response code from target */
226 uint8_t ConnectRespCode;
227};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800228
229/* endpoint distribution structure */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700230struct htc_endpoint_credit_dist {
231 struct _htc_endpoint_credit_dist *pNext;
232 struct _htc_endpoint_credit_dist *pPrev;
233 /* Service ID (set by HTC) */
234 HTC_SERVICE_ID service_id;
235 /* endpoint for this distribution struct (set by HTC) */
236 HTC_ENDPOINT_ID Endpoint;
237 /* distribution flags, distribution function can
238 * set default activity using SET_EP_ACTIVE() macro
239 */
240 uint32_t DistFlags;
241 /* credits for normal operation, anything above this
242 * indicates the endpoint is over-subscribed, this field
243 * is only relevant to the credit distribution function
244 */
245 int TxCreditsNorm;
246 /* floor for credit distribution, this field is
247 * only relevant to the credit distribution function
248 */
249 int TxCreditsMin;
250 /* number of credits assigned to this EP, this field
251 * is only relevant to the credit dist function
252 */
253 int TxCreditsAssigned;
254 /* current credits available, this field is used by
255 * HTC to determine whether a message can be sent or
256 * must be queued
257 */
258 int TxCredits;
259 /* pending credits to distribute on this endpoint, this
260 * is set by HTC when credit reports arrive.
261 * The credit distribution functions sets this to zero
262 * when it distributes the credits
263 */
264 int TxCreditsToDist;
265 /* this is the number of credits that the current pending TX
266 * packet needs to transmit. This is set by HTC when
267 * and endpoint needs credits in order to transmit
268 */
269 int TxCreditsSeek;
270 /* size in bytes of each credit (set by HTC) */
271 int TxCreditSize;
272 /* credits required for a maximum sized messages (set by HTC) */
273 int TxCreditsPerMaxMsg;
274 /* reserved for HTC use */
275 void *pHTCReserved;
276 /* current depth of TX queue , i.e. messages waiting for credits
277 * This field is valid only when HTC_CREDIT_DIST_ACTIVITY_CHANGE
278 * or HTC_CREDIT_DIST_SEND_COMPLETE is indicated on an endpoint
279 * that has non-zero credits to recover
280 */
281 int TxQueueDepth;
282};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800283
Yue Mab16cf302016-03-08 18:30:25 -0800284#define HTC_EP_ACTIVE ((uint32_t) (1u << 31))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800285
286/* macro to check if an endpoint has gone active, useful for credit
287 * distributions */
288#define IS_EP_ACTIVE(epDist) ((epDist)->DistFlags & HTC_EP_ACTIVE)
289#define SET_EP_ACTIVE(epDist) (epDist)->DistFlags |= HTC_EP_ACTIVE
290
291/* credit distibution code that is passed into the distrbution function,
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700292 * there are mandatory and optional codes that must be handled
293 */
294enum htc_credit_dist_reason {
295 /* credits available as a result of completed
296 * send operations (MANDATORY) resulting in credit reports
297 */
298 HTC_CREDIT_DIST_SEND_COMPLETE = 0,
299 /* a change in endpoint activity occurred (OPTIONAL) */
300 HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1,
301 /* an endpoint needs to "seek" credits (OPTIONAL) */
302 HTC_CREDIT_DIST_SEEK_CREDITS,
303 /* for debugging, dump any state information that is kept by
304 * the distribution function
305 */
306 HTC_DUMP_CREDIT_STATE
307};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800308
309typedef void (*HTC_CREDIT_DIST_CALLBACK)(void *Context,
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700310 struct htc_endpoint_credit_dist *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800311 pEPList,
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700312 enum htc_credit_dist_reason
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800313 Reason);
314
315typedef void (*HTC_CREDIT_INIT_CALLBACK)(void *Context,
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700316 struct htc_endpoint_credit_dist *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800317 pEPList, int TotalCredits);
318
319/* endpoint statistics action */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700320enum htc_endpoint_stat_action {
321 /* only read statistics */
322 HTC_EP_STAT_SAMPLE = 0,
323 /* sample and immediately clear statistics */
324 HTC_EP_STAT_SAMPLE_AND_CLEAR = 1,
325 /* clear only */
326 HTC_EP_STAT_CLEAR
327};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800328
329/* endpoint statistics */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700330struct htc_endpoint_stats {
331 /* number of TX packets posted to the endpoint */
332 uint32_t TxPosted;
333 /* number of times the host set the credit-low flag in a send message on
334 * this endpoint
335 */
336 uint32_t TxCreditLowIndications;
337 /* running count of total TX packets issued */
338 uint32_t TxIssued;
339 /* running count of TX packets that were issued in bundles */
340 uint32_t TxPacketsBundled;
341 /* running count of TX bundles that were issued */
342 uint32_t TxBundles;
343 /* tx packets that were dropped */
344 uint32_t TxDropped;
345 /* running count of total credit reports received for this endpoint */
346 uint32_t TxCreditRpts;
347 /* credit reports received from this endpoint's RX packets */
348 uint32_t TxCreditRptsFromRx;
349 /* credit reports received from RX packets of other endpoints */
350 uint32_t TxCreditRptsFromOther;
351 /* credit reports received from endpoint 0 RX packets */
352 uint32_t TxCreditRptsFromEp0;
353 /* count of credits received via Rx packets on this endpoint */
354 uint32_t TxCreditsFromRx;
355 /* count of credits received via another endpoint */
356 uint32_t TxCreditsFromOther;
357 /* count of credits received via another endpoint */
358 uint32_t TxCreditsFromEp0;
359 /* count of consummed credits */
360 uint32_t TxCreditsConsummed;
361 /* count of credits returned */
362 uint32_t TxCreditsReturned;
363 /* count of RX packets received */
364 uint32_t RxReceived;
365 /* count of lookahead records
366 * found in messages received on this endpoint
367 */
368 uint32_t RxLookAheads;
369 /* count of recv packets received in a bundle */
370 uint32_t RxPacketsBundled;
371 /* count of number of bundled lookaheads */
372 uint32_t RxBundleLookAheads;
373 /* count of the number of bundle indications from the HTC header */
374 uint32_t RxBundleIndFromHdr;
375 /* number of times the recv allocation threshold was hit */
376 uint32_t RxAllocThreshHit;
377 /* total number of bytes */
378 uint32_t RxAllocThreshBytes;
379};
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800380
381/* ------ Function Prototypes ------ */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700382/**
383 * htc_create - Create an instance of HTC over the underlying HIF device
384 * @HifDevice: hif device handle,
385 * @pInfo: initialization information
386 * @osdev: QDF device structure
387 * @con_mode: driver connection mode
388 *
389 * Return: HTC_HANDLE on success, NULL on failure
390 */
391HTC_HANDLE htc_create(void *HifDevice, struct htc_init_info *pInfo,
392 qdf_device_t osdev, uint32_t con_mode);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800393
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700394/**
395 * htc_get_hif_device - Get the underlying HIF device handle
396 * @HTCHandle: handle passed into the AddInstance callback
397 *
398 * Return: opaque HIF device handle usable in HIF API calls.
399 */
400void *htc_get_hif_device(HTC_HANDLE HTCHandle);
401
402/**
403 * htc_set_credit_distribution - Set credit distribution parameters
404 * @HTCHandle: HTC handle
405 * @pCreditDistCont: caller supplied context to pass into distribution functions
406 * @CreditDistFunc: Distribution function callback
407 * @CreditDistInit: Credit Distribution initialization callback
408 * @ServicePriorityOrder: Array containing list of service IDs, lowest index
409 * @is highestpriority: ListLength - number of elements in ServicePriorityOrder
410 *
411 * The user can set a custom credit distribution function to handle
412 * special requirementsfor each endpoint. A default credit distribution
413 * routine can be used by setting CreditInitFunc to NULL. The default
414 * credit distribution is only provided for simple "fair" credit distribution
415 * without regard to any prioritization.
416 * Return: None
417 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800418void htc_set_credit_distribution(HTC_HANDLE HTCHandle,
419 void *pCreditDistContext,
420 HTC_CREDIT_DIST_CALLBACK CreditDistFunc,
421 HTC_CREDIT_INIT_CALLBACK CreditInitFunc,
422 HTC_SERVICE_ID ServicePriorityOrder[],
423 int ListLength);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800424
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700425/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
426 * Wait for the target to indicate the HTC layer is ready
427 * htc_wait_target
428 * @HTCHandle - HTC handle
429 *
430 * This API blocks until the target responds with an HTC ready message.
431 * The caller should not connect services until the target has indicated it is
432 * ready.
433 * Return: None
434 */
Rakesh Pillai13146452017-06-22 12:52:31 +0530435QDF_STATUS htc_wait_target(HTC_HANDLE HTCHandle);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700436
437/**
438 * htc_start - Start target service communications
439 * @HTCHandle - HTC handle
440 *
441 * This API indicates to the target that the service connection phase
442 * is completeand the target can freely start all connected services. This
443 * API should only be called AFTER all service connections have been made.
444 * TCStart will issue a SETUP_COMPLETE message to the target to indicate that
445 * all service connections have been made and the target can start
446 * communicating over the endpoints.
447 * Return: None
448 */
Rakesh Pillai13146452017-06-22 12:52:31 +0530449QDF_STATUS htc_start(HTC_HANDLE HTCHandle);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700450
451/**
452 * htc_add_receive_pkt - Add receive packet to HTC
453 * @HTCHandle - HTC handle
454 * @pPacket - HTC receive packet to add
455 *
456 * User must supply HTC packets for capturing incoming HTC frames.
457 * The caller must initialize each HTC packet using the
458 * SET_HTC_PACKET_INFO_RX_REFILL() macro.
459 * Return: A_OK on success
460 */
461A_STATUS htc_add_receive_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket);
462
463/**
464 * htc_connect_service - Connect to an HTC service
465 * @HTCHandle - HTC handle
466 * @pReq - connection details
467 * @pResp - connection response
468 *
469 * Service connections must be performed before htc_start.
470 * User provides callback handlersfor various endpoint events.
471 * Return: None
472 */
Rakesh Pillai13146452017-06-22 12:52:31 +0530473QDF_STATUS htc_connect_service(HTC_HANDLE HTCHandle,
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700474 struct htc_service_connect_req *pReq,
475 struct htc_service_connect_resp *pResp);
476
477/**
478 * htc_dump - HTC register log dump
479 * @HTCHandle - HTC handle
480 * @CmdId - Log command
481 * @start - start/print logs
482 *
483 * Register logs will be started/printed/ be flushed.
484 * Return: None
485 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800486void htc_dump(HTC_HANDLE HTCHandle, uint8_t CmdId, bool start);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700487
488/**
489 * htc_send_pkt - Send an HTC packet
490 * @HTCHandle - HTC handle
491 * @pPacket - packet to send
492 *
493 * Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
494 * This interface is fully asynchronous. On error, HTC SendPkt will
495 * call the registered Endpoint callback to cleanup the packet.
Rakesh Pillai13146452017-06-22 12:52:31 +0530496 * Return: QDF_STATUS_SUCCESS
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700497 */
Rakesh Pillai13146452017-06-22 12:52:31 +0530498QDF_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700499
500/**
501 * htc_send_data_pkt - Send an HTC packet containing a tx descriptor and data
502 * @HTCHandle - HTC handle
503 * @pPacket - packet to send
504 *
505 * Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
506 * Caller must provide headroom in an initial fragment added to the
507 * network buffer to store a HTC_FRAME_HDR.
508 * This interface is fully asynchronous. On error, htc_send_data_pkt will
509 * call the registered Endpoint EpDataTxComplete callback to cleanup
510 * the packet.
511 * Return: A_OK
512 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800513#ifdef ATH_11AC_TXCOMPACT
Rakesh Pillai13146452017-06-22 12:52:31 +0530514QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, qdf_nbuf_t netbuf,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800515 int Epid, int ActualLength);
516#else /*ATH_11AC_TXCOMPACT */
Rakesh Pillai13146452017-06-22 12:52:31 +0530517QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
Yue Mab16cf302016-03-08 18:30:25 -0800518 uint8_t more_data);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800519#endif /*ATH_11AC_TXCOMPACT */
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700520
521/**
522 * htc_flush_surprise_remove - Flush HTC when target is removed surprisely
523 * service communications
524 * @HTCHandle - HTC handle
525 *
526 * All receive and pending TX packets will be flushed.
527 * Return: None
528 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800529void htc_flush_surprise_remove(HTC_HANDLE HTCHandle);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700530
531/**
532 * htc_stop - Stop HTC service communications
533 * @HTCHandle - HTC handle
534 *
535 * HTC communications is halted. All receive and pending TX packets
536 * will be flushed.
537 * Return: None
538 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800539void htc_stop(HTC_HANDLE HTCHandle);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700540
541/**
542 * htc_destroy - Destroy HTC service
543 * @HTCHandle - HTC handle
544 *
545 * This cleans up all resources allocated by htc_create().
546 * Return: None
547 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800548void htc_destroy(HTC_HANDLE HTCHandle);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700549
550/**
551 * htc_flush_endpoint - Flush pending TX packets
552 * @HTCHandle - HTC handle
553 * @Endpoint - Endpoint to flush
554 * @Tag - flush tag
555 *
556 * The Tag parameter is used to selectively flush packets with matching
557 * tags. The value of 0 forces all packets to be flush regardless of tag
558 * Return: None
559 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800560void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
561 HTC_TX_TAG Tag);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700562/**
563 * htc_dump_credit_states - Dump credit distribution state
564 * @HTCHandle - HTC handle
565 *
566 * This dumps all credit distribution information to the debugger
567 * Return: None
568 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800569void htc_dump_credit_states(HTC_HANDLE HTCHandle);
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700570
571/**
572 * htc_indicate_activity_change - Indicate a traffic activity change on an
573 * endpoint
574 * @HTCHandle - HTC handle
575 * @Endpoint - endpoint in which activity has changed
576 * @Active - true if active, false if it has become inactive
577 *
578 * This triggers the registered credit distribution function to
579 * re-adjust credits for active/inactive endpoints.
580 * Return: None
581 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800582void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
Yue Mab16cf302016-03-08 18:30:25 -0800583 HTC_ENDPOINT_ID Endpoint, bool Active);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800584
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700585/**
586 * htc_get_endpoint_statistics - Get endpoint statistics
587 * @HTCHandle - HTC handle
588 * @Endpoint - Endpoint identifier
589 * @Action - action to take with statistics
590 * @pStats - statistics that were sampled (can be NULL if Action is
591 * HTC_EP_STAT_CLEAR)
592 *
593 * Statistics is a compile-time option and this function may return
594 * false if HTC is not compiled with profiling.
595 * The caller can specify the statistic "action" to take when sampling
596 * the statistics. This includes :
597 * HTC_EP_STAT_SAMPLE : The pStats structure is filled with the current
598 * values.
599 * HTC_EP_STAT_SAMPLE_AND_CLEAR : The structure is filled and the current
600 * statisticsare cleared.
601 * HTC_EP_STAT_CLEA : the statistics are cleared, the called can pass
602 * a NULL value for pStats
603 * Return: true if statistics profiling is enabled, otherwise false.
604 */
Yue Mab16cf302016-03-08 18:30:25 -0800605bool htc_get_endpoint_statistics(HTC_HANDLE HTCHandle,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800606 HTC_ENDPOINT_ID Endpoint,
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700607 enum htc_endpoint_stat_action Action,
608 struct htc_endpoint_stats *pStats);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800609
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700610/**
611 * htc_unblock_recv - Unblock HTC message reception
612 * @HTCHandle - HTC handle
613 *
614 * HTC will block the receiver if the EpRecvAlloc callback fails to provide a
615 * packet. The caller can use this API to indicate to HTC when resources
616 * (buffers) are available such that the receiver can be unblocked and HTC
617 * may re-attempt fetching the pending message.
618 * This API is not required if the user uses the EpRecvRefill callback or uses
619 * the HTCAddReceivePacket()API to recycle or provide receive packets to HTC.
620 * Return: None
621 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800622void htc_unblock_recv(HTC_HANDLE HTCHandle);
623
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700624/**
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700625 * htc_add_receive_pkt_multiple - Add multiple receive packets to HTC
626 * @HTCHandle - HTC handle
627 * @pPktQueue - HTC receive packet queue holding packets to add
628 *
629 * User must supply HTC packets for capturing incoming HTC frames.
630 * The caller mmust initialize each HTC packet using the
631 * SET_HTC_PACKET_INFO_RX_REFILL() macro. The queue must only contain
632 * recv packets for the same endpoint. Caller supplies a pointer to an
633 * HTC_PACKET_QUEUE structure holding the recv packet. This API will
634 * remove the packets from the pkt queue and place them into internal
635 * recv packet list.
636 * The caller may allocate the pkt queue on the stack to hold the pkts.
637 * Return: A_OK on success
638 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800639A_STATUS htc_add_receive_pkt_multiple(HTC_HANDLE HTCHandle,
640 HTC_PACKET_QUEUE *pPktQueue);
641
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700642/**
643 * htc_is_endpoint_active - Check if an endpoint is marked active
644 * @HTCHandle - HTC handle
645 * @Endpoint - endpoint to check for active state
646 *
647 * Return: returns true if Endpoint is Active
648 */
Yue Mab16cf302016-03-08 18:30:25 -0800649bool htc_is_endpoint_active(HTC_HANDLE HTCHandle,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800650 HTC_ENDPOINT_ID Endpoint);
651
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700652/**
653 * htc_set_nodrop_pkt - Set up nodrop pkt flag for mboxping nodrop pkt
654 * @HTCHandle - HTC handle
655 * @isNodropPkt - indicates whether it is nodrop pkt
656 *
657 * Return: None
658 * Return:
659 *
660 */
gbianb417db22016-09-30 17:01:07 +0800661void htc_set_nodrop_pkt(HTC_HANDLE HTCHandle, A_BOOL isNodropPkt);
662
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700663/**
664 * htc_get_num_recv_buffers - Get the number of recv buffers currently queued
665 * into an HTC endpoint
666 * @HTCHandle - HTC handle
667 * @Endpoint - endpoint to check
668 *
669 * Return: returns number of buffers in queue
670 *
671 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800672int htc_get_num_recv_buffers(HTC_HANDLE HTCHandle,
673 HTC_ENDPOINT_ID Endpoint);
674
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700675/**
676 * htc_set_target_failure_callback - Set the target failure handling callback
677 * in HTC layer
678 * @HTCHandle - HTC handle
679 * @Callback - target failure handling callback
680 *
681 * Return: None
682 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800683void htc_set_target_failure_callback(HTC_HANDLE HTCHandle,
684 HTC_TARGET_FAILURE Callback);
685
686/* internally used functions for testing... */
687void htc_enable_recv(HTC_HANDLE HTCHandle);
688void htc_disable_recv(HTC_HANDLE HTCHandle);
689A_STATUS HTCWaitForPendingRecv(HTC_HANDLE HTCHandle,
Yue Mab16cf302016-03-08 18:30:25 -0800690 uint32_t TimeoutInMs,
691 bool *pbIsRecvPending);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800692
693/* function to fetch stats from htc layer*/
694struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE
695 HTCHandle);
Houston Hoffmanadc31472017-03-14 16:15:29 -0700696/**
697 * htc_get_tx_queue_depth() - get the tx queue depth of an htc endpoint
698 * @htc_handle: htc handle
699 * @enpoint_id: endpoint to check
700 *
701 * Return: htc_handle tx queue depth
702 */
703int htc_get_tx_queue_depth(HTC_HANDLE *htc_handle, HTC_ENDPOINT_ID endpoint_id);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800704
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530705#ifdef HIF_USB
706#define HTCReturnReceivePkt(target, p, osbuf) \
707 do { \
708 A_NETBUF_FREE(osbuf); \
709 if (p->Status == A_CLONE) { \
710 qdf_mem_free(p); \
711 } \
712 } while (0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800713#else
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530714#define HTCReturnReceivePkt(target, p, osbuf) htc_add_receive_pkt(target, p)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800715#endif
716
717#ifdef WLAN_FEATURE_FASTPATH
Houston Hoffman93481862016-05-05 18:49:59 -0700718void htc_ctrl_msg_cmpl(HTC_HANDLE htc_pdev, HTC_ENDPOINT_ID htc_ep_id);
719
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800720#define HTC_TX_DESC_FILL(_htc_tx_desc, _download_len, _ep_id, _seq_no) \
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700721do { \
722 HTC_WRITE32((_htc_tx_desc), \
723 SM((_download_len), HTC_FRAME_HDR_PAYLOADLEN) | \
724 SM((_ep_id), HTC_FRAME_HDR_ENDPOINTID)); \
725 HTC_WRITE32((uint32_t *)(_htc_tx_desc) + 1, \
726 SM((_seq_no), HTC_FRAME_HDR_CONTROLBYTES1)); \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800727} while (0)
728#endif /* WLAN_FEATURE_FASTPATH */
729
730#ifdef __cplusplus
731}
732#endif
Manikandan Mohane3e209e2017-04-13 20:19:26 -0700733void htc_get_control_endpoint_tx_host_credits(HTC_HANDLE HTCHandle,
734 int *credit);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800735void htc_dump_counter_info(HTC_HANDLE HTCHandle);
736void *htc_get_targetdef(HTC_HANDLE htc_handle);
Yue Maec9e71c2016-02-26 18:52:20 -0800737#ifdef FEATURE_RUNTIME_PM
738int htc_runtime_suspend(HTC_HANDLE htc_ctx);
739int htc_runtime_resume(HTC_HANDLE htc_ctx);
740#endif
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700741void htc_global_credit_flow_disable(void);
742void htc_global_credit_flow_enable(void);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800743
744/* Disable ASPM : Disable PCIe low power */
Komal Seelamf8600682016-02-02 18:17:13 +0530745bool htc_can_suspend_link(HTC_HANDLE HTCHandle);
746void htc_vote_link_down(HTC_HANDLE HTCHandle);
747void htc_vote_link_up(HTC_HANDLE HTCHandle);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800748#ifdef IPA_OFFLOAD
749void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle,
Sravan Kumar Kairam58e0adf2018-02-27 18:37:40 +0530750 qdf_shared_mem_t **ce_sr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800751 uint32_t *ce_sr_ring_size,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530752 qdf_dma_addr_t *ce_reg_paddr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800753#else
754#define htc_ipa_get_ce_resource(htc_handle, \
Sravan Kumar Kairam58e0adf2018-02-27 18:37:40 +0530755 ce_sr, ce_sr_ring_size, ce_reg_paddr) /* NO-OP */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800756#endif /* IPA_OFFLOAD */
Houston Hoffman93481862016-05-05 18:49:59 -0700757
Poddar, Siddarthdf030092016-04-28 11:41:57 +0530758#if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
759
760/**
761 * htc_dump_bundle_stats() - dump tx and rx htc message bundle stats
762 * @HTCHandle: htc handle
763 *
764 * Return: None
765 */
766void htc_dump_bundle_stats(HTC_HANDLE HTCHandle);
767
768/**
769 * htc_clear_bundle_stats() - clear tx and rx htc message bundle stats
770 * @HTCHandle: htc handle
771 *
772 * Return: None
773 */
774void htc_clear_bundle_stats(HTC_HANDLE HTCHandle);
775#endif
776
Houston Hoffman4d9b0802016-07-20 10:10:35 -0700777#ifdef FEATURE_RUNTIME_PM
778int htc_pm_runtime_get(HTC_HANDLE htc_handle);
779int htc_pm_runtime_put(HTC_HANDLE htc_handle);
780#else
781static inline int htc_pm_runtime_get(HTC_HANDLE htc_handle) { return 0; }
782static inline int htc_pm_runtime_put(HTC_HANDLE htc_handle) { return 0; }
783#endif
Venkateswara Swamy Bandaruae41b9e2016-11-21 15:06:24 +0530784
785/**
786 * htc_set_async_ep() - set async HTC end point
787 * user should call this function after htc_connect_service before
788 * queing any packets to end point
789 * @HTCHandle: htc handle
790 * @HTC_ENDPOINT_ID: end point id
791 * @value: true or false
792 *
793 * Return: None
794 */
795
796void htc_set_async_ep(HTC_HANDLE HTCHandle,
797 HTC_ENDPOINT_ID htc_ep_id, bool value);
Kiran Venkatappae17e3b62017-02-10 16:31:49 +0530798
799/**
800 * htc_set_wmi_endpoint_count: Set number of WMI endpoint
801 * @htc_handle: HTC handle
802 * @wmi_ep_count: WMI enpoint count
803 *
804 * return: None
805 */
806void htc_set_wmi_endpoint_count(HTC_HANDLE htc_handle, uint8_t wmi_ep_count);
807
808/**
809 * htc_get_wmi_endpoint_count: Get number of WMI endpoint
810 * @htc_handle: HTC handle
811 *
812 * return: WMI enpoint count
813 */
814uint8_t htc_get_wmi_endpoint_count(HTC_HANDLE htc_handle);
Dustin Brown536064a2017-04-03 17:00:07 -0700815
Rachit Kankane1bc11492018-01-24 18:48:17 +0530816/**
817 * htc_print_credit_history: print HTC credit history in buffer
818 * @htc: HTC handle
819 * @count: Number of lines to be copied
820 * @print: Print callback to print in the buffer
821 * @print_priv: any data required by the print method, e.g. a file handle
822 *
823 * return: None
824 */
825#ifdef FEATURE_HTC_CREDIT_HISTORY
Dustin Brown536064a2017-04-03 17:00:07 -0700826void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
827 qdf_abstract_print * print, void *print_priv);
Rachit Kankane1bc11492018-01-24 18:48:17 +0530828#else
829static inline
830void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
831 qdf_abstract_print *print, void *print_priv)
832{
833 print(print_priv, "HTC Credit History Feature is disabled");
834}
Dustin Brown536064a2017-04-03 17:00:07 -0700835#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800836#endif /* _HTC_API_H_ */