xref: /wlan-dirver/qca-wifi-host-cmn/htc/htc_api.h (revision a175314c51a4ce5cec2835cc8a8c7dc0c1810915)
1 /*
2  * Copyright (c) 2013-2014, 2016-2018 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _HTC_API_H_
20 #define _HTC_API_H_
21 
22 #include <htc.h>
23 #include <htc_services.h>
24 #include <qdf_types.h>          /* qdf_device_t */
25 #include "htc_packet.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
30 
31 /* TODO.. for BMI */
32 #define ENDPOINT1 0
33 /* TODO -remove me, but we have to fix BMI first */
34 #define HTC_MAILBOX_NUM_MAX    4
35 
36 /* this is the amount of header room required by users of HTC */
37 #define HTC_HEADER_LEN         HTC_HDR_LENGTH
38 
39 #define HTC_HTT_TRANSFER_HDRSIZE 24
40 
41 typedef void *HTC_HANDLE;
42 
43 typedef uint16_t HTC_SERVICE_ID;
44 
45 typedef void (*HTC_TARGET_FAILURE)(void *Instance, QDF_STATUS Status);
46 
47 struct htc_init_info {
48 	void *pContext;         /* context for target notifications */
49 	void (*TargetFailure)(void *Instance, QDF_STATUS Status);
50 	void (*TargetSendSuspendComplete)(void *ctx, bool is_nack);
51 	void (*target_initial_wakeup_cb)(void *cb_ctx);
52 	void *target_psoc;
53 };
54 
55 /* Struct for HTC layer packet stats*/
56 struct ol_ath_htc_stats {
57 	int htc_get_pkt_q_fail_count;
58 	int htc_pkt_q_empty_count;
59 	int htc_send_q_empty_count;
60 };
61 
62 /* To resume HTT Tx queue during runtime resume */
63 typedef void (*HTC_EP_RESUME_TX_QUEUE)(void *);
64 
65 /* per service connection send completion */
66 typedef void (*HTC_EP_SEND_PKT_COMPLETE)(void *, HTC_PACKET *);
67 /* per service connection callback when a plurality of packets have been sent
68  * The HTC_PACKET_QUEUE is a temporary queue object (e.g. freed on return from
69  * the callback) to hold a list of completed send packets.
70  * If the handler cannot fully traverse the packet queue before returning, it
71  * should transfer the items of the queue into the caller's private queue using:
72  * HTC_PACKET_ENQUEUE()
73  */
74 typedef void (*HTC_EP_SEND_PKT_COMP_MULTIPLE)(void *,
75 					      HTC_PACKET_QUEUE *);
76 /* per service connection pkt received */
77 typedef void (*HTC_EP_RECV_PKT)(void *, HTC_PACKET *);
78 /* per service connection callback when a plurality of packets are received
79  * The HTC_PACKET_QUEUE is a temporary queue object (e.g. freed on return from
80  * the callback) to hold a list of recv packets.
81  * If the handler cannot fully traverse the packet queue before returning, it
82  * should transfer the items of the queue into the caller's private queue using:
83  * HTC_PACKET_ENQUEUE()
84  */
85 typedef void (*HTC_EP_RECV_PKT_MULTIPLE)(void *, HTC_PACKET_QUEUE *);
86 
87 /* Optional per service connection receive buffer re-fill callback,
88  * On some OSes (like Linux) packets are allocated from a global pool and
89  * indicated up to the network stack.  The driver never gets the packets back
90  * from the OS. For these OSes a refill callback can be used to allocate and
91  * re-queue buffers into HTC.
92  *
93  * On other OSes, the network stack can call into the driver's OS-specific
94  * "return_packet" handler and the driver can re-queue these buffers into HTC.
95  * In this regard a refill callback is unnecessary
96  */
97 typedef void (*HTC_EP_RECV_REFILL)(void *, HTC_ENDPOINT_ID Endpoint);
98 
99 /* Optional per service connection receive buffer allocation callback.
100  * On some systems packet buffers are an extremely limited resource. Rather than
101  * queue largest-possible-sized buffers to HTC, some systems would rather
102  * allocate a specific size as the packet is received.  The trade off is
103  * slightly more processing (callback invoked for each RX packet)
104  * for the benefit of committing fewer buffer resources into HTC.
105  *
106  * The callback is provided the length of the pending packet to fetch. This
107  * includes the HTC header length plus the length of payload.  The callback can
108  * return a pointer to the allocated HTC packet for immediate use.
109  *
110  * Alternatively a variant of this handler can be used to allocate large receive
111  * packets as needed. For example an application can use the refill mechanism
112  * for normal packets and the recv-alloc mechanism to handle the case where a
113  * large packet buffer is required.  This can significantly reduce the
114  * amount of "committed" memory used to receive packets.
115  */
116 typedef HTC_PACKET *(*HTC_EP_RECV_ALLOC)(void *,
117 					 HTC_ENDPOINT_ID Endpoint,
118 					 int Length);
119 
120 enum htc_send_full_action {
121 	/* packet that overflowed should be kept in the queue */
122 	HTC_SEND_FULL_KEEP = 0,
123 	/* packet that overflowed should be dropped */
124 	HTC_SEND_FULL_DROP = 1,
125 };
126 
127 /* Optional per service connection callback when a send queue is full. This can
128  * occur if host continues queueing up TX packets faster than credits can arrive
129  * To prevent the host (on some Oses like Linux) from continuously queueing pkts
130  * and consuming resources, this callback is provided so that that the host
131  * can disable TX in the subsystem (i.e. network stack).
132  * This callback is invoked for each packet that "overflows" the HTC queue. The
133  * callback can determine whether the new packet that overflowed the queue can
134  * be kept (HTC_SEND_FULL_KEEP) or dropped (HTC_SEND_FULL_DROP). If a packet is
135  * dropped, the EpTxComplete handler will be called and the packet's status
136  * field will be set to A_NO_RESOURCE.
137  * Other OSes require a "per-packet" indication for each completed TX packet,
138  * this closed loop mechanism will prevent the network stack from overunning the
139  * NIC. The packet to keep or drop is passed for inspection to the registered
140  * handler the handler must ONLY inspect the packet, it may not free or reclaim
141  * the packet.
142  */
143 typedef enum htc_send_full_action (*HTC_EP_SEND_QUEUE_FULL)(void *,
144 					       HTC_PACKET *pPacket);
145 
146 struct htc_ep_callbacks {
147 	/* context for each callback */
148 	void *pContext;
149 	/* tx completion callback for connected endpoint */
150 	HTC_EP_SEND_PKT_COMPLETE EpTxComplete;
151 	/* receive callback for connected endpoint */
152 	HTC_EP_RECV_PKT EpRecv;
153 	/* OPTIONAL receive re-fill callback for connected endpoint */
154 	HTC_EP_RECV_REFILL EpRecvRefill;
155 	/* OPTIONAL send full callback */
156 	HTC_EP_SEND_QUEUE_FULL EpSendFull;
157 	/* OPTIONAL recv allocation callback */
158 	HTC_EP_RECV_ALLOC EpRecvAlloc;
159 	/* OPTIONAL recv allocation callback based on a threshold */
160 	HTC_EP_RECV_ALLOC EpRecvAllocThresh;
161 	/* OPTIONAL completion handler for multiple complete
162 	 * indications (EpTxComplete must be NULL)
163 	 */
164 	HTC_EP_SEND_PKT_COMP_MULTIPLE EpTxCompleteMultiple;
165 
166 	HTC_EP_RESUME_TX_QUEUE ep_resume_tx_queue;
167 	/* if EpRecvAllocThresh is non-NULL, HTC will compare the
168 	 * threshold value to the current recv packet length and invoke
169 	 * the EpRecvAllocThresh callback to acquire a packet buffer
170 	 */
171 	int RecvAllocThreshold;
172 	/* if a EpRecvRefill handler is provided, this value
173 	 * can be used to set a trigger refill callback
174 	 * when the recv queue drops below this value
175 	 * if set to 0, the refill is only called when packets
176 	 * are empty
177 	 */
178 	int RecvRefillWaterMark;
179 };
180 
181 /* service connection information */
182 struct htc_service_connect_req {
183 	/* service ID to connect to */
184 	HTC_SERVICE_ID service_id;
185 	/* connection flags, see htc protocol definition */
186 	uint16_t ConnectionFlags;
187 	/* ptr to optional service-specific meta-data */
188 	uint8_t *pMetaData;
189 	/* optional meta data length */
190 	uint8_t MetaDataLength;
191 	/* endpoint callbacks */
192 	struct htc_ep_callbacks EpCallbacks;
193 	/* maximum depth of any send queue */
194 	int MaxSendQueueDepth;
195 	/* HTC flags for the host-side (local) connection */
196 	uint32_t LocalConnectionFlags;
197 	/* override max message size in send direction */
198 	unsigned int MaxSendMsgSize;
199 };
200 
201 /* enable send bundle padding for this endpoint */
202 #define HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING (1 << 0)
203 
204 /* service connection response information */
205 struct htc_service_connect_resp {
206 	/* caller supplied buffer to optional meta-data */
207 	uint8_t *pMetaData;
208 	/* length of caller supplied buffer */
209 	uint8_t BufferLength;
210 	/* actual length of meta data */
211 	uint8_t ActualLength;
212 	/* endpoint to communicate over */
213 	HTC_ENDPOINT_ID Endpoint;
214 	/* max length of all messages over this endpoint */
215 	unsigned int MaxMsgLength;
216 	/* connect response code from target */
217 	uint8_t ConnectRespCode;
218 };
219 
220 /* endpoint distribution structure */
221 struct htc_endpoint_credit_dist {
222 	struct _htc_endpoint_credit_dist *pNext;
223 	struct _htc_endpoint_credit_dist *pPrev;
224 	/* Service ID (set by HTC) */
225 	HTC_SERVICE_ID service_id;
226 	/* endpoint for this distribution struct (set by HTC) */
227 	HTC_ENDPOINT_ID Endpoint;
228 	/* distribution flags, distribution function can
229 	 * set default activity using SET_EP_ACTIVE() macro
230 	 */
231 	uint32_t DistFlags;
232 	/* credits for normal operation, anything above this
233 	 * indicates the endpoint is over-subscribed, this field
234 	 * is only relevant to the credit distribution function
235 	 */
236 	int TxCreditsNorm;
237 	/* floor for credit distribution, this field is
238 	 * only relevant to the credit distribution function
239 	 */
240 	int TxCreditsMin;
241 	/* number of credits assigned to this EP, this field
242 	 * is only relevant to the credit dist function
243 	 */
244 	int TxCreditsAssigned;
245 	/* current credits available, this field is used by
246 	 * HTC to determine whether a message can be sent or
247 	 * must be queued
248 	 */
249 	int TxCredits;
250 	/* pending credits to distribute on this endpoint, this
251 	 * is set by HTC when credit reports arrive.
252 	 * The credit distribution functions sets this to zero
253 	 * when it distributes the credits
254 	 */
255 	int TxCreditsToDist;
256 	/* this is the number of credits that the current pending TX
257 	 * packet needs to transmit.  This is set by HTC when
258 	 * and endpoint needs credits in order to transmit
259 	 */
260 	int TxCreditsSeek;
261 	/* size in bytes of each credit (set by HTC) */
262 	int TxCreditSize;
263 	/* credits required for a maximum sized messages (set by HTC) */
264 	int TxCreditsPerMaxMsg;
265 	/* reserved for HTC use */
266 	void *pHTCReserved;
267 	/* current depth of TX queue , i.e. messages waiting for credits
268 	 * This field is valid only when HTC_CREDIT_DIST_ACTIVITY_CHANGE
269 	 * or HTC_CREDIT_DIST_SEND_COMPLETE is indicated on an endpoint
270 	 * that has non-zero credits to recover
271 	 */
272 	int TxQueueDepth;
273 };
274 
275 #define HTC_EP_ACTIVE                            ((uint32_t) (1u << 31))
276 
277 /* macro to check if an endpoint has gone active, useful for credit
278  * distributions */
279 #define IS_EP_ACTIVE(epDist)  ((epDist)->DistFlags & HTC_EP_ACTIVE)
280 #define SET_EP_ACTIVE(epDist) (epDist)->DistFlags |= HTC_EP_ACTIVE
281 
282 /* credit distibution code that is passed into the distrbution function,
283  * there are mandatory and optional codes that must be handled
284  */
285 enum htc_credit_dist_reason {
286 	/* credits available as a result of completed
287 	 * send operations (MANDATORY) resulting in credit reports
288 	 */
289 	HTC_CREDIT_DIST_SEND_COMPLETE = 0,
290 	/* a change in endpoint activity occurred (OPTIONAL) */
291 	HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1,
292 	/* an endpoint needs to "seek" credits (OPTIONAL) */
293 	HTC_CREDIT_DIST_SEEK_CREDITS,
294 	/* for debugging, dump any state information that is kept by
295 	 * the distribution function
296 	 */
297 	HTC_DUMP_CREDIT_STATE
298 };
299 
300 typedef void (*HTC_CREDIT_DIST_CALLBACK)(void *Context,
301 					 struct htc_endpoint_credit_dist *
302 					 pEPList,
303 					 enum htc_credit_dist_reason
304 					 Reason);
305 
306 typedef void (*HTC_CREDIT_INIT_CALLBACK)(void *Context,
307 					 struct htc_endpoint_credit_dist *
308 					 pEPList, int TotalCredits);
309 
310 /* endpoint statistics action */
311 enum htc_endpoint_stat_action {
312 	/* only read statistics */
313 	HTC_EP_STAT_SAMPLE = 0,
314 	/* sample and immediately clear statistics */
315 	HTC_EP_STAT_SAMPLE_AND_CLEAR = 1,
316 	/* clear only */
317 	HTC_EP_STAT_CLEAR
318 };
319 
320 /* endpoint statistics */
321 struct htc_endpoint_stats {
322 	/* number of TX packets posted to the endpoint */
323 	uint32_t TxPosted;
324 	/* number of times the host set the credit-low flag in a send message on
325 	 * this endpoint
326 	 */
327 	uint32_t TxCreditLowIndications;
328 	/* running count of total TX packets issued */
329 	uint32_t TxIssued;
330 	/* running count of TX packets that were issued in bundles */
331 	uint32_t TxPacketsBundled;
332 	/* running count of TX bundles that were issued */
333 	uint32_t TxBundles;
334 	/* tx packets that were dropped */
335 	uint32_t TxDropped;
336 	/* running count of total credit reports received for this endpoint */
337 	uint32_t TxCreditRpts;
338 	/* credit reports received from this endpoint's RX packets */
339 	uint32_t TxCreditRptsFromRx;
340 	/* credit reports received from RX packets of other endpoints */
341 	uint32_t TxCreditRptsFromOther;
342 	/* credit reports received from endpoint 0 RX packets */
343 	uint32_t TxCreditRptsFromEp0;
344 	/* count of credits received via Rx packets on this endpoint */
345 	uint32_t TxCreditsFromRx;
346 	/* count of credits received via another endpoint */
347 	uint32_t TxCreditsFromOther;
348 	/* count of credits received via another endpoint */
349 	uint32_t TxCreditsFromEp0;
350 	/* count of consummed credits */
351 	uint32_t TxCreditsConsummed;
352 	/* count of credits returned */
353 	uint32_t TxCreditsReturned;
354 	/* count of RX packets received */
355 	uint32_t RxReceived;
356 	/* count of lookahead records
357 	 * found in messages received on this endpoint
358 	 */
359 	uint32_t RxLookAheads;
360 	/* count of recv packets received in a bundle */
361 	uint32_t RxPacketsBundled;
362 	/* count of number of bundled lookaheads */
363 	uint32_t RxBundleLookAheads;
364 	/* count of the number of bundle indications from the HTC header */
365 	uint32_t RxBundleIndFromHdr;
366 	/* number of times the recv allocation threshold was hit */
367 	uint32_t RxAllocThreshHit;
368 	/* total number of bytes */
369 	uint32_t RxAllocThreshBytes;
370 };
371 
372 /* ------ Function Prototypes ------ */
373 /**
374  * htc_create - Create an instance of HTC over the underlying HIF device
375  * @HifDevice: hif device handle,
376  * @pInfo: initialization information
377  * @osdev: QDF device structure
378  * @con_mode: driver connection mode
379  *
380  * Return: HTC_HANDLE on success, NULL on failure
381  */
382 HTC_HANDLE htc_create(void *HifDevice, struct htc_init_info *pInfo,
383 			qdf_device_t osdev, uint32_t con_mode);
384 
385 /**
386  * htc_get_hif_device - Get the underlying HIF device handle
387  * @HTCHandle: handle passed into the AddInstance callback
388  *
389  * Return: opaque HIF device handle usable in HIF API calls.
390  */
391 void *htc_get_hif_device(HTC_HANDLE HTCHandle);
392 
393 /**
394  * htc_set_credit_distribution - Set credit distribution parameters
395  * @HTCHandle: HTC handle
396  * @pCreditDistCont: caller supplied context to pass into distribution functions
397  * @CreditDistFunc: Distribution function callback
398  * @CreditDistInit: Credit Distribution initialization callback
399  * @ServicePriorityOrder: Array containing list of service IDs, lowest index
400  * @is highestpriority: ListLength - number of elements in ServicePriorityOrder
401  *
402  * The user can set a custom credit distribution function to handle
403  * special requirementsfor each endpoint.  A default credit distribution
404  * routine can be used by setting CreditInitFunc to NULL. The default
405  * credit distribution is only provided for simple "fair" credit distribution
406  * without regard to any prioritization.
407  * Return: None
408  */
409 void htc_set_credit_distribution(HTC_HANDLE HTCHandle,
410 				 void *pCreditDistContext,
411 				 HTC_CREDIT_DIST_CALLBACK CreditDistFunc,
412 				 HTC_CREDIT_INIT_CALLBACK CreditInitFunc,
413 				 HTC_SERVICE_ID ServicePriorityOrder[],
414 				 int ListLength);
415 
416 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
417  * Wait for the target to indicate the HTC layer is ready
418  * htc_wait_target
419  * @HTCHandle - HTC handle
420  *
421  * This API blocks until the target responds with an HTC ready message.
422  * The caller should not connect services until the target has indicated it is
423  * ready.
424  * Return: None
425  */
426 QDF_STATUS htc_wait_target(HTC_HANDLE HTCHandle);
427 
428 /**
429  * htc_start - Start target service communications
430  * @HTCHandle - HTC handle
431  *
432  * This API indicates to the target that the service connection phase
433  * is completeand the target can freely start all connected services.  This
434  * API should only be called AFTER all service connections have been made.
435  * TCStart will issue a SETUP_COMPLETE message to the target to indicate that
436  * all service connections have been made and the target can start
437  * communicating over the endpoints.
438  * Return: None
439  */
440 QDF_STATUS htc_start(HTC_HANDLE HTCHandle);
441 
442 /**
443  * htc_connect_service - Connect to an HTC service
444  * @HTCHandle - HTC handle
445  * @pReq - connection details
446  * @pResp - connection response
447  *
448  * Service connections must be performed before htc_start.
449  * User provides callback handlersfor various endpoint events.
450  * Return: None
451  */
452 QDF_STATUS htc_connect_service(HTC_HANDLE HTCHandle,
453 			     struct htc_service_connect_req *pReq,
454 			     struct htc_service_connect_resp *pResp);
455 
456 /**
457  * htc_dump - HTC register log dump
458  * @HTCHandle - HTC handle
459  * @CmdId - Log command
460  * @start - start/print logs
461  *
462  * Register logs will be started/printed/ be flushed.
463  * Return: None
464  */
465 void htc_dump(HTC_HANDLE HTCHandle, uint8_t CmdId, bool start);
466 
467 /**
468  * htc_send_pkt - Send an HTC packet
469  * @HTCHandle - HTC handle
470  * @pPacket - packet to send
471  *
472  * Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
473  * This interface is fully asynchronous.  On error, HTC SendPkt will
474  * call the registered Endpoint callback to cleanup the packet.
475  * Return: QDF_STATUS_SUCCESS
476  */
477 QDF_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket);
478 
479 /**
480  * htc_send_data_pkt - Send an HTC packet containing a tx descriptor and data
481  * @HTCHandle - HTC handle
482  * @pPacket - packet to send
483  *
484  * Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
485  * Caller must provide headroom in an initial fragment added to the
486  * network buffer to store a HTC_FRAME_HDR.
487  * This interface is fully asynchronous.  On error, htc_send_data_pkt will
488  * call the registered Endpoint EpDataTxComplete callback to cleanup
489  * the packet.
490  * Return: A_OK
491  */
492 #ifdef ATH_11AC_TXCOMPACT
493 QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, qdf_nbuf_t netbuf,
494 			   int Epid, int ActualLength);
495 #else                           /*ATH_11AC_TXCOMPACT */
496 QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
497 			   uint8_t more_data);
498 #endif /*ATH_11AC_TXCOMPACT */
499 
500 /**
501  * htc_flush_surprise_remove - Flush HTC when target is removed surprisely
502  *                             service communications
503  * @HTCHandle - HTC handle
504  *
505  * All receive and pending TX packets will be flushed.
506  * Return: None
507  */
508 void htc_flush_surprise_remove(HTC_HANDLE HTCHandle);
509 
510 /**
511  * htc_stop - Stop HTC service communications
512  * @HTCHandle - HTC handle
513  *
514  * HTC communications is halted.  All receive and pending TX packets
515  * will  be flushed.
516  * Return: None
517  */
518 void htc_stop(HTC_HANDLE HTCHandle);
519 
520 /**
521  * htc_destroy - Destroy HTC service
522  * @HTCHandle - HTC handle
523  *
524  * This cleans up all resources allocated by htc_create().
525  * Return: None
526  */
527 void htc_destroy(HTC_HANDLE HTCHandle);
528 
529 /**
530  * htc_flush_endpoint - Flush pending TX packets
531  * @HTCHandle - HTC handle
532  * @Endpoint - Endpoint to flush
533  * @Tag - flush tag
534  *
535  * The Tag parameter is used to selectively flush packets with matching
536  * tags. The value of 0 forces all packets to be flush regardless of tag
537  * Return: None
538  */
539 void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
540 			HTC_TX_TAG Tag);
541 /**
542  * htc_dump_credit_states - Dump credit distribution state
543  * @HTCHandle - HTC handle
544  *
545  * This dumps all credit distribution information to the debugger
546  * Return: None
547  */
548 void htc_dump_credit_states(HTC_HANDLE HTCHandle);
549 
550 /**
551  * htc_indicate_activity_change - Indicate a traffic activity change on an
552  *                                endpoint
553  * @HTCHandle - HTC handle
554  * @Endpoint - endpoint in which activity has changed
555  * @Active - true if active, false if it has become inactive
556  *
557  * This triggers the registered credit distribution function to
558  * re-adjust credits for active/inactive endpoints.
559  * Return: None
560  */
561 void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
562 				  HTC_ENDPOINT_ID Endpoint, bool Active);
563 
564 /**
565  * htc_get_endpoint_statistics - Get endpoint statistics
566  * @HTCHandle - HTC handle
567  * @Endpoint - Endpoint identifier
568  * @Action - action to take with statistics
569  * @pStats - statistics that were sampled (can be NULL if Action is
570  *           HTC_EP_STAT_CLEAR)
571  *
572  * Statistics is a compile-time option and this function may return
573  * false if HTC is not compiled with profiling.
574  * The caller can specify the statistic "action" to take when sampling
575  * the statistics.  This includes :
576  * HTC_EP_STAT_SAMPLE : The pStats structure is filled with the current
577  *                      values.
578  * HTC_EP_STAT_SAMPLE_AND_CLEAR : The structure is filled and the current
579  *                                statisticsare cleared.
580  * HTC_EP_STAT_CLEA : the statistics are cleared, the called can pass
581  *                    a NULL value for pStats
582  * Return: true if statistics profiling is enabled, otherwise false.
583  */
584 bool htc_get_endpoint_statistics(HTC_HANDLE HTCHandle,
585 				   HTC_ENDPOINT_ID Endpoint,
586 				   enum htc_endpoint_stat_action Action,
587 				   struct htc_endpoint_stats *pStats);
588 
589 /**
590  * htc_unblock_recv - Unblock HTC message reception
591  * @HTCHandle - HTC handle
592  *
593  * HTC will block the receiver if the EpRecvAlloc callback fails to provide a
594  * packet. The caller can use this API to indicate to HTC when resources
595  * (buffers) are available such that the  receiver can be unblocked and HTC
596  * may re-attempt fetching the pending message.
597  * This API is not required if the user uses the EpRecvRefill callback or uses
598  * the HTCAddReceivePacket()API to recycle or provide receive packets to HTC.
599  * Return: None
600  */
601 void htc_unblock_recv(HTC_HANDLE HTCHandle);
602 
603 /**
604  * htc_add_receive_pkt_multiple - Add multiple receive packets to HTC
605  * @HTCHandle - HTC handle
606  * @pPktQueue - HTC receive packet queue holding packets to add
607  *
608  * User must supply HTC packets for capturing incoming HTC frames.
609  * The caller mmust initialize each HTC packet using the
610  * SET_HTC_PACKET_INFO_RX_REFILL() macro. The queue must only contain
611  * recv packets for the same endpoint. Caller supplies a pointer to an
612  * HTC_PACKET_QUEUE structure holding the recv packet. This API will
613  * remove the packets from the pkt queue and place them into internal
614  * recv packet list.
615  * The caller may allocate the pkt queue on the stack to hold the pkts.
616  * Return: A_OK on success
617  */
618 A_STATUS htc_add_receive_pkt_multiple(HTC_HANDLE HTCHandle,
619 				      HTC_PACKET_QUEUE *pPktQueue);
620 
621 /**
622  * htc_is_endpoint_active - Check if an endpoint is marked active
623  * @HTCHandle - HTC handle
624  * @Endpoint - endpoint to check for active state
625  *
626  * Return: returns true if Endpoint is Active
627  */
628 bool htc_is_endpoint_active(HTC_HANDLE HTCHandle,
629 			      HTC_ENDPOINT_ID Endpoint);
630 
631 /**
632  * htc_set_nodrop_pkt - Set up nodrop pkt flag for mboxping nodrop pkt
633  * @HTCHandle - HTC handle
634  * @isNodropPkt - indicates whether it is nodrop pkt
635  *
636  * Return: None
637  * Return:
638  *
639  */
640 void htc_set_nodrop_pkt(HTC_HANDLE HTCHandle, A_BOOL isNodropPkt);
641 
642 /**
643  * htc_get_num_recv_buffers - Get the number of recv buffers currently queued
644  *                            into an HTC endpoint
645  * @HTCHandle - HTC handle
646  * @Endpoint - endpoint to check
647  *
648  * Return: returns number of buffers in queue
649  *
650  */
651 int htc_get_num_recv_buffers(HTC_HANDLE HTCHandle,
652 			     HTC_ENDPOINT_ID Endpoint);
653 
654 /**
655  * htc_set_target_failure_callback - Set the target failure handling callback
656  *                                   in HTC layer
657  * @HTCHandle - HTC handle
658  * @Callback - target failure handling callback
659  *
660  * Return: None
661  */
662 void htc_set_target_failure_callback(HTC_HANDLE HTCHandle,
663 				     HTC_TARGET_FAILURE Callback);
664 
665 /* internally used functions for testing... */
666 void htc_enable_recv(HTC_HANDLE HTCHandle);
667 void htc_disable_recv(HTC_HANDLE HTCHandle);
668 A_STATUS HTCWaitForPendingRecv(HTC_HANDLE HTCHandle,
669 			       uint32_t TimeoutInMs,
670 			       bool *pbIsRecvPending);
671 
672 /* function to fetch stats from htc layer*/
673 struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE
674 						       HTCHandle);
675 /**
676  * htc_get_tx_queue_depth() - get the tx queue depth of an htc endpoint
677  * @htc_handle: htc handle
678  * @enpoint_id: endpoint to check
679  *
680  * Return: htc_handle tx queue depth
681  */
682 int htc_get_tx_queue_depth(HTC_HANDLE *htc_handle, HTC_ENDPOINT_ID endpoint_id);
683 
684 #ifdef WLAN_FEATURE_FASTPATH
685 void htc_ctrl_msg_cmpl(HTC_HANDLE htc_pdev, HTC_ENDPOINT_ID htc_ep_id);
686 
687 #define HTC_TX_DESC_FILL(_htc_tx_desc, _download_len, _ep_id, _seq_no)	\
688 do {                                                            \
689 	HTC_WRITE32((_htc_tx_desc),                             \
690 		SM((_download_len), HTC_FRAME_HDR_PAYLOADLEN) | \
691 		SM((_ep_id), HTC_FRAME_HDR_ENDPOINTID));        \
692 	HTC_WRITE32((uint32_t *)(_htc_tx_desc) + 1,             \
693 		SM((_seq_no), HTC_FRAME_HDR_CONTROLBYTES1));    \
694 } while (0)
695 #endif /* WLAN_FEATURE_FASTPATH */
696 
697 #ifdef __cplusplus
698 }
699 #endif
700 void htc_get_control_endpoint_tx_host_credits(HTC_HANDLE HTCHandle,
701 						int *credit);
702 void htc_dump_counter_info(HTC_HANDLE HTCHandle);
703 void *htc_get_targetdef(HTC_HANDLE htc_handle);
704 #ifdef FEATURE_RUNTIME_PM
705 int htc_runtime_suspend(HTC_HANDLE htc_ctx);
706 int htc_runtime_resume(HTC_HANDLE htc_ctx);
707 #endif
708 void htc_global_credit_flow_disable(void);
709 void htc_global_credit_flow_enable(void);
710 
711 /* Disable ASPM : Disable PCIe low power */
712 bool htc_can_suspend_link(HTC_HANDLE HTCHandle);
713 void htc_vote_link_down(HTC_HANDLE HTCHandle);
714 void htc_vote_link_up(HTC_HANDLE HTCHandle);
715 #ifdef IPA_OFFLOAD
716 void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle,
717 			     qdf_shared_mem_t **ce_sr,
718 			     uint32_t *ce_sr_ring_size,
719 			     qdf_dma_addr_t *ce_reg_paddr);
720 #else
721 #define htc_ipa_get_ce_resource(htc_handle,                \
722 			ce_sr, ce_sr_ring_size, ce_reg_paddr)     /* NO-OP */
723 #endif /* IPA_OFFLOAD */
724 
725 #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
726 
727 /**
728  * htc_dump_bundle_stats() - dump tx and rx htc message bundle stats
729  * @HTCHandle: htc handle
730  *
731  * Return: None
732  */
733 void htc_dump_bundle_stats(HTC_HANDLE HTCHandle);
734 
735 /**
736  * htc_clear_bundle_stats() - clear tx and rx htc message bundle stats
737  * @HTCHandle: htc handle
738  *
739  * Return: None
740  */
741 void htc_clear_bundle_stats(HTC_HANDLE HTCHandle);
742 #endif
743 
744 #ifdef FEATURE_RUNTIME_PM
745 int htc_pm_runtime_get(HTC_HANDLE htc_handle);
746 int htc_pm_runtime_put(HTC_HANDLE htc_handle);
747 #else
748 static inline int htc_pm_runtime_get(HTC_HANDLE htc_handle) { return 0; }
749 static inline int htc_pm_runtime_put(HTC_HANDLE htc_handle) { return 0; }
750 #endif
751 
752 /**
753   * htc_set_async_ep() - set async HTC end point
754   *           user should call this function after htc_connect_service before
755   *           queing any packets to end point
756   * @HTCHandle: htc handle
757   * @HTC_ENDPOINT_ID: end point id
758   * @value: true or false
759   *
760   * Return: None
761   */
762 
763 void htc_set_async_ep(HTC_HANDLE HTCHandle,
764 			HTC_ENDPOINT_ID htc_ep_id, bool value);
765 
766 /**
767  * htc_set_wmi_endpoint_count: Set number of WMI endpoint
768  * @htc_handle: HTC handle
769  * @wmi_ep_count: WMI enpoint count
770  *
771  * return: None
772  */
773 void htc_set_wmi_endpoint_count(HTC_HANDLE htc_handle, uint8_t wmi_ep_count);
774 
775 /**
776  * htc_get_wmi_endpoint_count: Get number of WMI endpoint
777  * @htc_handle: HTC handle
778  *
779  * return: WMI enpoint count
780  */
781 uint8_t  htc_get_wmi_endpoint_count(HTC_HANDLE htc_handle);
782 
783 /**
784  * htc_print_credit_history: print HTC credit history in buffer
785  * @htc:        HTC handle
786  * @count:      Number of lines to be copied
787  * @print:      Print callback to print in the buffer
788  * @print_priv: any data required by the print method, e.g. a file handle
789  *
790  * return: None
791  */
792 #ifdef FEATURE_HTC_CREDIT_HISTORY
793 void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
794 			      qdf_abstract_print * print, void *print_priv);
795 #else
796 static inline
797 void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
798 			      qdf_abstract_print *print, void *print_priv)
799 {
800 	print(print_priv, "HTC Credit History Feature is disabled");
801 }
802 #endif
803 #endif /* _HTC_API_H_ */
804