xref: /wlan-dirver/qca-wifi-host-cmn/htc/htc.c (revision f28396d060cff5c6519f883cb28ae0116ce479f1)
1 /*
2  * Copyright (c) 2013-2020 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 #include "htc_debug.h"
20 #include "htc_internal.h"
21 #include "htc_credit_history.h"
22 #include <hif.h>
23 #include <qdf_nbuf.h>           /* qdf_nbuf_t */
24 #include <qdf_types.h>          /* qdf_print */
25 
26 #define MAX_HTC_RX_BUNDLE  2
27 
28 #if defined(WLAN_DEBUG) || defined(DEBUG)
29 static ATH_DEBUG_MASK_DESCRIPTION g_htc_debug_description[] = {
30 	{ATH_DEBUG_SEND, "Send"},
31 	{ATH_DEBUG_RECV, "Recv"},
32 	{ATH_DEBUG_SYNC, "Sync"},
33 	{ATH_DEBUG_DUMP, "Dump Data (RX or TX)"},
34 	{ATH_DEBUG_SETUP, "Setup"},
35 };
36 
37 ATH_DEBUG_INSTANTIATE_MODULE_VAR(htc,
38 				 "htc",
39 				 "Host Target Communications",
40 				 ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_INFO |
41 				 ATH_DEBUG_SETUP,
42 				 ATH_DEBUG_DESCRIPTION_COUNT
43 					 (g_htc_debug_description),
44 				 g_htc_debug_description);
45 
46 #endif
47 
48 #if (defined(WMI_MULTI_MAC_SVC) || defined(QCA_WIFI_QCA8074) || \
49 	defined(QCA_WIFI_QCA6018))
50 static const uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1,
51 						WMI_CONTROL_SVC_WMAC2};
52 #else
53 static const uint32_t svc_id[] = {WMI_CONTROL_SVC};
54 #endif
55 
56 extern unsigned int htc_credit_flow;
57 
58 static void reset_endpoint_states(HTC_TARGET *target);
59 
60 static void destroy_htc_tx_ctrl_packet(HTC_PACKET *pPacket)
61 {
62 	qdf_nbuf_t netbuf;
63 
64 	netbuf = (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
65 	if (netbuf)
66 		qdf_nbuf_free(netbuf);
67 	qdf_mem_free(pPacket);
68 }
69 
70 static HTC_PACKET *build_htc_tx_ctrl_packet(qdf_device_t osdev)
71 {
72 	HTC_PACKET *pPacket = NULL;
73 	qdf_nbuf_t netbuf;
74 
75 	do {
76 		pPacket = (HTC_PACKET *) qdf_mem_malloc(sizeof(HTC_PACKET));
77 		if (!pPacket)
78 			break;
79 		netbuf = qdf_nbuf_alloc(osdev, HTC_CONTROL_BUFFER_SIZE,
80 					20, 4, true);
81 		if (!netbuf) {
82 			qdf_mem_free(pPacket);
83 			pPacket = NULL;
84 			break;
85 		}
86 		SET_HTC_PACKET_NET_BUF_CONTEXT(pPacket, netbuf);
87 	} while (false);
88 
89 	return pPacket;
90 }
91 
92 void htc_free_control_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket)
93 {
94 
95 #ifdef TODO_FIXME
96 	LOCK_HTC(target);
97 	HTC_PACKET_ENQUEUE(&target->ControlBufferTXFreeList, pPacket);
98 	UNLOCK_HTC(target);
99 	/* TODO_FIXME netbufs cannot be RESET! */
100 #else
101 	destroy_htc_tx_ctrl_packet(pPacket);
102 #endif
103 
104 }
105 
106 HTC_PACKET *htc_alloc_control_tx_packet(HTC_TARGET *target)
107 {
108 #ifdef TODO_FIXME
109 	HTC_PACKET *pPacket;
110 
111 	LOCK_HTC(target);
112 	pPacket = htc_packet_dequeue(&target->ControlBufferTXFreeList);
113 	UNLOCK_HTC(target);
114 
115 	return pPacket;
116 #else
117 	return build_htc_tx_ctrl_packet(target->osdev);
118 #endif
119 }
120 
121 /* Set the target failure handling callback */
122 void htc_set_target_failure_callback(HTC_HANDLE HTCHandle,
123 				     HTC_TARGET_FAILURE Callback)
124 {
125 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
126 
127 	target->HTCInitInfo.TargetFailure = Callback;
128 }
129 
130 void htc_dump(HTC_HANDLE HTCHandle, uint8_t CmdId, bool start)
131 {
132 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
133 
134 	hif_dump(target->hif_dev, CmdId, start);
135 }
136 
137 void htc_ce_tasklet_debug_dump(HTC_HANDLE htc_handle)
138 {
139 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
140 
141 	if (!target->hif_dev)
142 		return;
143 
144 	hif_display_stats(target->hif_dev);
145 }
146 
147 /* cleanup the HTC instance */
148 static void htc_cleanup(HTC_TARGET *target)
149 {
150 	HTC_PACKET *pPacket;
151 	int i;
152 	HTC_ENDPOINT *endpoint;
153 	HTC_PACKET_QUEUE *pkt_queue;
154 	qdf_nbuf_t netbuf;
155 
156 	if (target->hif_dev) {
157 		hif_detach_htc(target->hif_dev);
158 		hif_mask_interrupt_call(target->hif_dev);
159 		target->hif_dev = NULL;
160 	}
161 
162 	while (true) {
163 		pPacket = allocate_htc_packet_container(target);
164 		if (!pPacket)
165 			break;
166 		qdf_mem_free(pPacket);
167 	}
168 
169 	LOCK_HTC_TX(target);
170 	pPacket = target->pBundleFreeList;
171 	target->pBundleFreeList = NULL;
172 	UNLOCK_HTC_TX(target);
173 	while (pPacket) {
174 		HTC_PACKET *pPacketTmp = (HTC_PACKET *) pPacket->ListLink.pNext;
175 		netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
176 		if (netbuf)
177 			qdf_nbuf_free(netbuf);
178 		pkt_queue = pPacket->pContext;
179 		if (pkt_queue)
180 			qdf_mem_free(pkt_queue);
181 		qdf_mem_free(pPacket);
182 		pPacket = pPacketTmp;
183 	}
184 
185 #ifdef TODO_FIXME
186 	while (true) {
187 		pPacket = htc_alloc_control_tx_packet(target);
188 		if (!pPacket)
189 			break;
190 		netbuf = (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
191 		if (netbuf)
192 			qdf_nbuf_free(netbuf);
193 		qdf_mem_free(pPacket);
194 	}
195 #endif
196 
197 	htc_flush_endpoint_txlookupQ(target, ENDPOINT_0, true);
198 
199 	qdf_spinlock_destroy(&target->HTCLock);
200 	qdf_spinlock_destroy(&target->HTCRxLock);
201 	qdf_spinlock_destroy(&target->HTCTxLock);
202 	for (i = 0; i < ENDPOINT_MAX; i++) {
203 		endpoint = &target->endpoint[i];
204 		qdf_spinlock_destroy(&endpoint->lookup_queue_lock);
205 	}
206 
207 	/* free our instance */
208 	qdf_mem_free(target);
209 }
210 
211 #ifdef FEATURE_RUNTIME_PM
212 /**
213  * htc_runtime_pm_init(): runtime pm related intialization
214  *
215  * need to initialize a work item.
216  */
217 static void htc_runtime_pm_init(HTC_TARGET *target)
218 {
219 	qdf_create_work(0, &target->queue_kicker, htc_kick_queues, target);
220 }
221 
222 /**
223  * htc_runtime_suspend() - runtime suspend HTC
224  *
225  * @htc_ctx: HTC context pointer
226  *
227  * This is a dummy function for symmetry.
228  *
229  * Return: 0 for success
230  */
231 int htc_runtime_suspend(HTC_HANDLE htc_ctx)
232 {
233 	return 0;
234 }
235 
236 /**
237  * htc_runtime_resume(): resume htc
238  *
239  * The htc message queue needs to be kicked off after
240  * a runtime resume.  Otherwise messages would get stuck.
241  *
242  * @htc_ctx: HTC context pointer
243  *
244  * Return: 0 for success;
245  */
246 int htc_runtime_resume(HTC_HANDLE htc_ctx)
247 {
248 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_ctx);
249 
250 	if (!target)
251 		return 0;
252 
253 	qdf_sched_work(0, &target->queue_kicker);
254 	return 0;
255 }
256 #else
257 static inline void htc_runtime_pm_init(HTC_TARGET *target) { }
258 #endif
259 
260 #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
261 static
262 void htc_update_rx_bundle_stats(void *ctx, uint8_t no_of_pkt_in_bundle)
263 {
264 	HTC_TARGET *target = (HTC_TARGET *)ctx;
265 
266 	no_of_pkt_in_bundle--;
267 	if (target && (no_of_pkt_in_bundle < HTC_MAX_MSG_PER_BUNDLE_RX))
268 		target->rx_bundle_stats[no_of_pkt_in_bundle]++;
269 }
270 #else
271 static
272 void htc_update_rx_bundle_stats(void *ctx, uint8_t no_of_pkt_in_bundle)
273 {
274 }
275 #endif
276 
277 /* registered target arrival callback from the HIF layer */
278 HTC_HANDLE htc_create(void *ol_sc, struct htc_init_info *pInfo,
279 			qdf_device_t osdev, uint32_t con_mode)
280 {
281 	struct hif_msg_callbacks htcCallbacks;
282 	HTC_ENDPOINT *pEndpoint = NULL;
283 	HTC_TARGET *target = NULL;
284 	int i;
285 
286 	if (!ol_sc) {
287 		HTC_ERROR("%s: ol_sc = NULL", __func__);
288 		return NULL;
289 	}
290 	HTC_TRACE("+htc_create ..  HIF :%pK", ol_sc);
291 
292 	A_REGISTER_MODULE_DEBUG_INFO(htc);
293 
294 	target = (HTC_TARGET *) qdf_mem_malloc(sizeof(HTC_TARGET));
295 	if (!target)
296 		return NULL;
297 
298 	htc_runtime_pm_init(target);
299 	htc_credit_history_init();
300 	qdf_spinlock_create(&target->HTCLock);
301 	qdf_spinlock_create(&target->HTCRxLock);
302 	qdf_spinlock_create(&target->HTCTxLock);
303 	for (i = 0; i < ENDPOINT_MAX; i++) {
304 		pEndpoint = &target->endpoint[i];
305 		qdf_spinlock_create(&pEndpoint->lookup_queue_lock);
306 	}
307 	target->is_nodrop_pkt = false;
308 	target->htc_hdr_length_check = false;
309 	target->wmi_ep_count = 1;
310 
311 	do {
312 		qdf_mem_copy(&target->HTCInitInfo, pInfo,
313 			     sizeof(struct htc_init_info));
314 		target->host_handle = pInfo->pContext;
315 		target->osdev = osdev;
316 		target->con_mode = con_mode;
317 
318 		reset_endpoint_states(target);
319 
320 		INIT_HTC_PACKET_QUEUE(&target->ControlBufferTXFreeList);
321 
322 		for (i = 0; i < HTC_PACKET_CONTAINER_ALLOCATION; i++) {
323 			HTC_PACKET *pPacket = (HTC_PACKET *)
324 					qdf_mem_malloc(sizeof(HTC_PACKET));
325 			if (pPacket)
326 				free_htc_packet_container(target, pPacket);
327 		}
328 
329 #ifdef TODO_FIXME
330 		for (i = 0; i < NUM_CONTROL_TX_BUFFERS; i++) {
331 			pPacket = build_htc_tx_ctrl_packet();
332 			if (!pPacket)
333 				break;
334 			htc_free_control_tx_packet(target, pPacket);
335 		}
336 #endif
337 
338 		/* setup HIF layer callbacks */
339 		qdf_mem_zero(&htcCallbacks, sizeof(struct hif_msg_callbacks));
340 		htcCallbacks.Context = target;
341 		htcCallbacks.rxCompletionHandler = htc_rx_completion_handler;
342 		htcCallbacks.txCompletionHandler = htc_tx_completion_handler;
343 		htcCallbacks.txResourceAvailHandler =
344 						 htc_tx_resource_avail_handler;
345 		htcCallbacks.fwEventHandler = htc_fw_event_handler;
346 		htcCallbacks.update_bundle_stats = htc_update_rx_bundle_stats;
347 		target->hif_dev = ol_sc;
348 
349 		/* Get HIF default pipe for HTC message exchange */
350 		pEndpoint = &target->endpoint[ENDPOINT_0];
351 
352 		hif_post_init(target->hif_dev, target, &htcCallbacks);
353 		hif_get_default_pipe(target->hif_dev, &pEndpoint->UL_PipeID,
354 				     &pEndpoint->DL_PipeID);
355 		hif_set_initial_wakeup_cb(target->hif_dev,
356 					  pInfo->target_initial_wakeup_cb,
357 					  pInfo->target_psoc);
358 
359 	} while (false);
360 
361 	htc_recv_init(target);
362 
363 	HTC_TRACE("-htc_create: (0x%pK)", target);
364 
365 	return (HTC_HANDLE) target;
366 }
367 
368 void htc_destroy(HTC_HANDLE HTCHandle)
369 {
370 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
371 
372 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
373 			("+htc_destroy ..  Destroying :0x%pK\n", target));
374 	hif_stop(htc_get_hif_device(HTCHandle));
375 	if (target)
376 		htc_cleanup(target);
377 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_destroy\n"));
378 }
379 
380 /* get the low level HIF device for the caller , the caller may wish to do low
381  * level HIF requests
382  */
383 void *htc_get_hif_device(HTC_HANDLE HTCHandle)
384 {
385 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
386 
387 	return target->hif_dev;
388 }
389 
390 static void htc_control_tx_complete(void *Context, HTC_PACKET *pPacket)
391 {
392 	HTC_TARGET *target = (HTC_TARGET *) Context;
393 
394 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
395 			("+-htc_control_tx_complete 0x%pK (l:%d)\n", pPacket,
396 			 pPacket->ActualLength));
397 	htc_free_control_tx_packet(target, pPacket);
398 }
399 
400 /* TODO, this is just a temporary max packet size */
401 #define MAX_MESSAGE_SIZE 1536
402 
403 /**
404  * htc_setup_epping_credit_allocation() - allocate credits/HTC buffers to WMI
405  * @scn: pointer to hif_opaque_softc
406  * @pEntry: pointer to tx credit allocation entry
407  * @credits: number of credits
408  *
409  * Return: None
410  */
411 static void
412 htc_setup_epping_credit_allocation(struct hif_opaque_softc *scn,
413 			   struct htc_service_tx_credit_allocation *pEntry,
414 			   int credits)
415 {
416 	switch (hif_get_bus_type(scn)) {
417 	case QDF_BUS_TYPE_PCI:
418 	case QDF_BUS_TYPE_USB:
419 		pEntry++;
420 		pEntry->service_id = WMI_DATA_BE_SVC;
421 		pEntry->CreditAllocation = (credits >> 1);
422 
423 		pEntry++;
424 		pEntry->service_id = WMI_DATA_BK_SVC;
425 		pEntry->CreditAllocation = (credits >> 1);
426 		break;
427 	case QDF_BUS_TYPE_SDIO:
428 		pEntry++;
429 		pEntry->service_id = WMI_DATA_BE_SVC;
430 		pEntry->CreditAllocation = credits;
431 		break;
432 	default:
433 		break;
434 	}
435 }
436 
437 /**
438  * htc_setup_target_buffer_assignments() - setup target buffer assignments
439  * @target: HTC Target Pointer
440  *
441  * Return: A_STATUS
442  */
443 static
444 A_STATUS htc_setup_target_buffer_assignments(HTC_TARGET *target)
445 {
446 	struct htc_service_tx_credit_allocation *pEntry;
447 	A_STATUS status;
448 	int credits;
449 	int creditsPerMaxMsg;
450 
451 	creditsPerMaxMsg = MAX_MESSAGE_SIZE / target->TargetCreditSize;
452 	if (MAX_MESSAGE_SIZE % target->TargetCreditSize)
453 		creditsPerMaxMsg++;
454 
455 	/* TODO, this should be configured by the caller! */
456 
457 	credits = target->TotalTransmitCredits;
458 	pEntry = &target->ServiceTxAllocTable[0];
459 
460 	status = A_OK;
461 	/*
462 	 * Allocate all credists/HTC buffers to WMI.
463 	 * no buffers are used/required for data. data always
464 	 * remains on host.
465 	 */
466 	if (HTC_IS_EPPING_ENABLED(target->con_mode)) {
467 		pEntry++;
468 		pEntry->service_id = WMI_CONTROL_SVC;
469 		pEntry->CreditAllocation = credits;
470 		/* endpoint ping is a testing tool directly on top of HTC in
471 		 * both target and host sides.
472 		 * In target side, the endppint ping fw has no wlan stack and
473 		 * FW mboxping app directly sits on HTC and it simply drops
474 		 * or loops back TX packets. For rx perf, FW mboxping app
475 		 * generates packets and passes packets to HTC to send to host.
476 		 * There is no WMI message exchanges between host and target
477 		 * in endpoint ping case.
478 		 * In host side, the endpoint ping driver is a Ethernet driver
479 		 * and it directly sits on HTC. Only HIF, HTC, QDF, ADF are
480 		 * used by the endpoint ping driver. There is no wifi stack
481 		 * at all in host side also. For tx perf use case,
482 		 * the user space mboxping app sends the raw packets to endpoint
483 		 * ping driver and it directly forwards to HTC for transmission
484 		 * to stress the bus. For the rx perf, HTC passes the received
485 		 * packets to endpoint ping driver and it is passed to the user
486 		 * space through the Ethernet interface.
487 		 * For credit allocation, in SDIO bus case, only BE service is
488 		 * used for tx/rx perf testing so that all credits are given
489 		 * to BE service. In PCIe and USB bus case, endpoint ping uses
490 		 * both BE and BK services to stress the bus so that the total
491 		 * credits are equally distributed to BE and BK services.
492 		 */
493 
494 		htc_setup_epping_credit_allocation(target->hif_dev,
495 						   pEntry, credits);
496 	} else {
497 		int i;
498 		uint32_t max_wmi_svc = (sizeof(svc_id) / sizeof(uint32_t));
499 
500 		if ((target->wmi_ep_count == 0) ||
501 				(target->wmi_ep_count > max_wmi_svc))
502 			return A_ERROR;
503 
504 		/*
505 		 * Divide credit among number of endpoints for WMI
506 		 */
507 		credits = credits / target->wmi_ep_count;
508 		for (i = 0; i < target->wmi_ep_count; i++) {
509 			status = A_OK;
510 			pEntry++;
511 			pEntry->service_id = svc_id[i];
512 			pEntry->CreditAllocation = credits;
513 		}
514 	}
515 
516 	if (A_SUCCESS(status)) {
517 		int i;
518 
519 		for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
520 			if (target->ServiceTxAllocTable[i].service_id != 0) {
521 				AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
522 						("SVS Index : %d TX : 0x%2.2X : alloc:%d",
523 						 i,
524 						 target->ServiceTxAllocTable[i].
525 						 service_id,
526 						 target->ServiceTxAllocTable[i].
527 						 CreditAllocation));
528 			}
529 		}
530 	}
531 
532 	return status;
533 }
534 
535 uint8_t htc_get_credit_allocation(HTC_TARGET *target, uint16_t service_id)
536 {
537 	uint8_t allocation = 0;
538 	int i;
539 
540 	for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
541 		if (target->ServiceTxAllocTable[i].service_id == service_id) {
542 			allocation =
543 				target->ServiceTxAllocTable[i].CreditAllocation;
544 		}
545 	}
546 
547 	if (0 == allocation) {
548 		AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1,
549 			("HTC Service TX : 0x%2.2X : allocation is zero!\n",
550 				 service_id));
551 	}
552 
553 	return allocation;
554 }
555 
556 QDF_STATUS htc_wait_target(HTC_HANDLE HTCHandle)
557 {
558 	QDF_STATUS status = QDF_STATUS_SUCCESS;
559 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
560 	HTC_READY_EX_MSG *pReadyMsg;
561 	struct htc_service_connect_req connect;
562 	struct htc_service_connect_resp resp;
563 	HTC_READY_MSG *rdy_msg;
564 	uint16_t htc_rdy_msg_id;
565 	uint8_t i = 0;
566 	HTC_PACKET *rx_bundle_packet, *temp_bundle_packet;
567 
568 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
569 			("htc_wait_target - Enter (target:0x%pK)\n", HTCHandle));
570 	AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1, ("+HWT\n"));
571 
572 	do {
573 
574 		status = hif_start(target->hif_dev);
575 		if (QDF_IS_STATUS_ERROR(status)) {
576 			AR_DEBUG_PRINTF(ATH_DEBUG_ERROR,
577 					("hif_start failed\n"));
578 			break;
579 		}
580 
581 		status = htc_wait_recv_ctrl_message(target);
582 
583 		if (QDF_IS_STATUS_ERROR(status))
584 			break;
585 
586 		if (target->CtrlResponseLength < (sizeof(HTC_READY_EX_MSG))) {
587 			AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
588 					("Invalid HTC Ready Msg Len:%d!\n",
589 					 target->CtrlResponseLength));
590 			status = QDF_STATUS_E_BADMSG;
591 			break;
592 		}
593 
594 		pReadyMsg = (HTC_READY_EX_MSG *) target->CtrlResponseBuffer;
595 
596 		rdy_msg = &pReadyMsg->Version2_0_Info;
597 		htc_rdy_msg_id =
598 			HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, MESSAGEID);
599 		if (htc_rdy_msg_id != HTC_MSG_READY_ID) {
600 			AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
601 					("Invalid HTC Ready Msg : 0x%X!\n",
602 					 htc_rdy_msg_id));
603 			status = QDF_STATUS_E_BADMSG;
604 			break;
605 		}
606 
607 		target->TotalTransmitCredits = HTC_GET_FIELD(rdy_msg,
608 						HTC_READY_MSG, CREDITCOUNT);
609 		if (target->HTCInitInfo.cfg_wmi_credit_cnt &&
610 			(target->HTCInitInfo.cfg_wmi_credit_cnt <
611 						target->TotalTransmitCredits))
612 			/*
613 			 * If INI configured value is less than FW advertised,
614 			 * then use INI configured value, otherwise use FW
615 			 * advertised.
616 			 */
617 			target->TotalTransmitCredits =
618 				target->HTCInitInfo.cfg_wmi_credit_cnt;
619 
620 		target->TargetCreditSize =
621 			(int)HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, CREDITSIZE);
622 		target->MaxMsgsPerHTCBundle =
623 			(uint8_t) pReadyMsg->MaxMsgsPerHTCBundle;
624 		UPDATE_ALT_CREDIT(target, pReadyMsg->AltDataCreditSize);
625 		/* for old fw this value is set to 0. But the minimum value
626 		 * should be 1, i.e., no bundling
627 		 */
628 		if (target->MaxMsgsPerHTCBundle < 1)
629 			target->MaxMsgsPerHTCBundle = 1;
630 
631 		AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
632 				("Target Ready! TX resource : %d size:%d, MaxMsgsPerHTCBundle = %d",
633 				 target->TotalTransmitCredits,
634 				 target->TargetCreditSize,
635 				 target->MaxMsgsPerHTCBundle));
636 
637 		if ((0 == target->TotalTransmitCredits)
638 		    || (0 == target->TargetCreditSize)) {
639 			status = QDF_STATUS_E_ABORTED;
640 			break;
641 		}
642 
643 		/* Allocate expected number of RX bundle buffer allocation */
644 		if (HTC_RX_BUNDLE_ENABLED(target)) {
645 			temp_bundle_packet = NULL;
646 			for (i = 0; i < MAX_HTC_RX_BUNDLE; i++) {
647 				rx_bundle_packet =
648 					allocate_htc_bundle_packet(target);
649 				if (rx_bundle_packet)
650 					rx_bundle_packet->ListLink.pNext =
651 						(DL_LIST *)temp_bundle_packet;
652 				else
653 					break;
654 
655 				temp_bundle_packet = rx_bundle_packet;
656 			}
657 			LOCK_HTC_TX(target);
658 			target->pBundleFreeList = temp_bundle_packet;
659 			UNLOCK_HTC_TX(target);
660 		}
661 
662 		/* done processing */
663 		target->CtrlResponseProcessing = false;
664 
665 		htc_setup_target_buffer_assignments(target);
666 
667 		/* setup our pseudo HTC control endpoint connection */
668 		qdf_mem_zero(&connect, sizeof(connect));
669 		qdf_mem_zero(&resp, sizeof(resp));
670 		connect.EpCallbacks.pContext = target;
671 		connect.EpCallbacks.EpTxComplete = htc_control_tx_complete;
672 		connect.EpCallbacks.EpRecv = htc_control_rx_complete;
673 		connect.MaxSendQueueDepth = NUM_CONTROL_TX_BUFFERS;
674 		connect.service_id = HTC_CTRL_RSVD_SVC;
675 
676 		/* connect fake service */
677 		status = htc_connect_service((HTC_HANDLE) target,
678 					     &connect, &resp);
679 
680 	} while (false);
681 
682 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_wait_target - Exit (%d)\n",
683 			status));
684 	AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1, ("-HWT\n"));
685 	return status;
686 }
687 
688 /* start HTC, this is called after all services are connected */
689 static A_STATUS htc_config_target_hif_pipe(HTC_TARGET *target)
690 {
691 
692 	return A_OK;
693 }
694 
695 static void reset_endpoint_states(HTC_TARGET *target)
696 {
697 	HTC_ENDPOINT *pEndpoint;
698 	int i;
699 
700 	for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
701 		pEndpoint = &target->endpoint[i];
702 		pEndpoint->service_id = 0;
703 		pEndpoint->MaxMsgLength = 0;
704 		pEndpoint->MaxTxQueueDepth = 0;
705 		pEndpoint->Id = i;
706 		INIT_HTC_PACKET_QUEUE(&pEndpoint->TxQueue);
707 		INIT_HTC_PACKET_QUEUE(&pEndpoint->TxLookupQueue);
708 		INIT_HTC_PACKET_QUEUE(&pEndpoint->RxBufferHoldQueue);
709 		pEndpoint->target = target;
710 		pEndpoint->TxCreditFlowEnabled = (bool)htc_credit_flow;
711 		qdf_atomic_init(&pEndpoint->TxProcessCount);
712 	}
713 }
714 
715 /**
716  * htc_start() - Main HTC function to trigger HTC start
717  * @HTCHandle: pointer to HTC handle
718  *
719  * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
720  */
721 QDF_STATUS htc_start(HTC_HANDLE HTCHandle)
722 {
723 	qdf_nbuf_t netbuf;
724 	QDF_STATUS status = QDF_STATUS_SUCCESS;
725 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
726 	HTC_SETUP_COMPLETE_EX_MSG *pSetupComp;
727 	HTC_PACKET *pSendPacket;
728 
729 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Enter\n"));
730 
731 	do {
732 
733 		htc_config_target_hif_pipe(target);
734 
735 		/* allocate a buffer to send */
736 		pSendPacket = htc_alloc_control_tx_packet(target);
737 		if (!pSendPacket) {
738 			AR_DEBUG_ASSERT(false);
739 			qdf_print("%s: allocControlTxPacket failed",
740 				  __func__);
741 			status = QDF_STATUS_E_NOMEM;
742 			break;
743 		}
744 
745 		netbuf =
746 		   (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pSendPacket);
747 		/* assemble setup complete message */
748 		qdf_nbuf_put_tail(netbuf, sizeof(HTC_SETUP_COMPLETE_EX_MSG));
749 		pSetupComp =
750 			(HTC_SETUP_COMPLETE_EX_MSG *) qdf_nbuf_data(netbuf);
751 		qdf_mem_zero(pSetupComp, sizeof(HTC_SETUP_COMPLETE_EX_MSG));
752 
753 		HTC_SET_FIELD(pSetupComp, HTC_SETUP_COMPLETE_EX_MSG,
754 			      MESSAGEID, HTC_MSG_SETUP_COMPLETE_EX_ID);
755 
756 		if (!htc_credit_flow) {
757 			AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
758 					("HTC will not use TX credit flow control"));
759 			pSetupComp->SetupFlags |=
760 				HTC_SETUP_COMPLETE_FLAGS_DISABLE_TX_CREDIT_FLOW;
761 		} else {
762 			AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
763 					("HTC using TX credit flow control"));
764 		}
765 
766 		if ((hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_SDIO) ||
767 					(hif_get_bus_type(target->hif_dev) ==
768 							 QDF_BUS_TYPE_USB)) {
769 			if (HTC_RX_BUNDLE_ENABLED(target))
770 			pSetupComp->SetupFlags |=
771 				HTC_SETUP_COMPLETE_FLAGS_ENABLE_BUNDLE_RECV;
772 			hif_set_bundle_mode(target->hif_dev, true,
773 				HTC_MAX_MSG_PER_BUNDLE_RX);
774 			pSetupComp->MaxMsgsPerBundledRecv = HTC_MAX_MSG_PER_BUNDLE_RX;
775 		}
776 
777 		SET_HTC_PACKET_INFO_TX(pSendPacket,
778 				       NULL,
779 				       (uint8_t *) pSetupComp,
780 				       sizeof(HTC_SETUP_COMPLETE_EX_MSG),
781 				       ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
782 
783 		status = htc_send_pkt((HTC_HANDLE) target, pSendPacket);
784 		if (QDF_IS_STATUS_ERROR(status))
785 			break;
786 	} while (false);
787 
788 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Exit\n"));
789 	return status;
790 }
791 
792 /*flush all queued buffers for surpriseremove case*/
793 void htc_flush_surprise_remove(HTC_HANDLE HTCHandle)
794 {
795 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
796 	int i;
797 	HTC_ENDPOINT *pEndpoint;
798 #ifdef RX_SG_SUPPORT
799 	qdf_nbuf_t netbuf;
800 	qdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
801 #endif
802 
803 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_flush_surprise_remove\n"));
804 
805 	/* cleanup endpoints */
806 	for (i = 0; i < ENDPOINT_MAX; i++) {
807 		pEndpoint = &target->endpoint[i];
808 		htc_flush_rx_hold_queue(target, pEndpoint);
809 		htc_flush_endpoint_tx(target, pEndpoint, HTC_TX_PACKET_TAG_ALL);
810 	}
811 
812 	hif_flush_surprise_remove(target->hif_dev);
813 
814 #ifdef RX_SG_SUPPORT
815 	LOCK_HTC_RX(target);
816 	while ((netbuf = qdf_nbuf_queue_remove(rx_sg_queue)) != NULL)
817 		qdf_nbuf_free(netbuf);
818 	RESET_RX_SG_CONFIG(target);
819 	UNLOCK_HTC_RX(target);
820 #endif
821 
822 	reset_endpoint_states(target);
823 
824 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_flush_surprise_remove\n"));
825 }
826 
827 /* stop HTC communications, i.e. stop interrupt reception, and flush all queued
828  * buffers
829  */
830 void htc_stop(HTC_HANDLE HTCHandle)
831 {
832 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
833 	int i;
834 	HTC_ENDPOINT *endpoint;
835 #ifdef RX_SG_SUPPORT
836 	qdf_nbuf_t netbuf;
837 	qdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
838 #endif
839 
840 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_stop\n"));
841 
842 	HTC_INFO("%s: endpoints cleanup\n", __func__);
843 	/* cleanup endpoints */
844 	for (i = 0; i < ENDPOINT_MAX; i++) {
845 		endpoint = &target->endpoint[i];
846 		htc_flush_rx_hold_queue(target, endpoint);
847 		htc_flush_endpoint_tx(target, endpoint, HTC_TX_PACKET_TAG_ALL);
848 		if (endpoint->ul_is_polled) {
849 			qdf_timer_stop(&endpoint->ul_poll_timer);
850 			qdf_timer_free(&endpoint->ul_poll_timer);
851 		}
852 	}
853 
854 	/* Note: htc_flush_endpoint_tx for all endpoints should be called before
855 	 * hif_stop - otherwise htc_tx_completion_handler called from
856 	 * hif_send_buffer_cleanup_on_pipe for residual tx frames in HIF layer,
857 	 * might queue the packet again to HIF Layer - which could cause tx
858 	 * buffer leak
859 	 */
860 
861 	HTC_INFO("%s: stopping hif layer\n", __func__);
862 	hif_stop(target->hif_dev);
863 
864 #ifdef RX_SG_SUPPORT
865 	LOCK_HTC_RX(target);
866 	while ((netbuf = qdf_nbuf_queue_remove(rx_sg_queue)) != NULL)
867 		qdf_nbuf_free(netbuf);
868 	RESET_RX_SG_CONFIG(target);
869 	UNLOCK_HTC_RX(target);
870 #endif
871 
872 	/**
873 	 * In SSR case, HTC tx completion callback for wmi will be blocked
874 	 * by TARGET_STATUS_RESET and HTC packets will be left unfreed on
875 	 * lookup queue.
876 	 *
877 	 * In case of target failing to send wmi_ready_event, the htc connect
878 	 * msg buffer will be left unmapped and not freed. So calling the
879 	 * completion handler for this buffer will handle this scenario.
880 	 */
881 	HTC_INFO("%s: flush endpoints Tx lookup queue\n", __func__);
882 	for (i = 0; i < ENDPOINT_MAX; i++) {
883 		endpoint = &target->endpoint[i];
884 		if (endpoint->service_id == WMI_CONTROL_SVC)
885 			htc_flush_endpoint_txlookupQ(target, i, false);
886 		else if (endpoint->service_id == HTC_CTRL_RSVD_SVC)
887 			htc_flush_endpoint_txlookupQ(target, i, true);
888 	}
889 	HTC_INFO("%s: resetting endpoints state\n", __func__);
890 
891 	reset_endpoint_states(target);
892 
893 	AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_stop\n"));
894 }
895 
896 void htc_dump_credit_states(HTC_HANDLE HTCHandle)
897 {
898 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
899 	HTC_ENDPOINT *pEndpoint;
900 	int i;
901 
902 	for (i = 0; i < ENDPOINT_MAX; i++) {
903 		pEndpoint = &target->endpoint[i];
904 		if (0 == pEndpoint->service_id)
905 			continue;
906 
907 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
908 			("--- EP : %d  service_id: 0x%X    --------------\n",
909 				 pEndpoint->Id, pEndpoint->service_id));
910 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
911 				(" TxCredits          : %d\n",
912 				 pEndpoint->TxCredits));
913 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
914 				(" TxCreditSize       : %d\n",
915 				 pEndpoint->TxCreditSize));
916 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
917 				(" TxCreditsPerMaxMsg : %d\n",
918 				 pEndpoint->TxCreditsPerMaxMsg));
919 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
920 				(" TxQueueDepth       : %d\n",
921 				 HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)));
922 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
923 				("----------------------------------------\n"));
924 	}
925 }
926 
927 bool htc_get_endpoint_statistics(HTC_HANDLE HTCHandle,
928 				   HTC_ENDPOINT_ID Endpoint,
929 				   enum htc_endpoint_stat_action Action,
930 				   struct htc_endpoint_stats *pStats)
931 {
932 #ifdef HTC_EP_STAT_PROFILING
933 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
934 	bool clearStats = false;
935 	bool sample = false;
936 
937 	switch (Action) {
938 	case HTC_EP_STAT_SAMPLE:
939 		sample = true;
940 		break;
941 	case HTC_EP_STAT_SAMPLE_AND_CLEAR:
942 		sample = true;
943 		clearStats = true;
944 		break;
945 	case HTC_EP_STAT_CLEAR:
946 		clearStats = true;
947 		break;
948 	default:
949 		break;
950 	}
951 
952 	A_ASSERT(Endpoint < ENDPOINT_MAX);
953 
954 	/* lock out TX and RX while we sample and/or clear */
955 	LOCK_HTC_TX(target);
956 	LOCK_HTC_RX(target);
957 
958 	if (sample) {
959 		A_ASSERT(pStats);
960 		/* return the stats to the caller */
961 		qdf_mem_copy(pStats, &target->endpoint[Endpoint].endpoint_stats,
962 			 sizeof(struct htc_endpoint_stats));
963 	}
964 
965 	if (clearStats) {
966 		/* reset stats */
967 		qdf_mem_zero(&target->endpoint[Endpoint].endpoint_stats,
968 			  sizeof(struct htc_endpoint_stats));
969 	}
970 
971 	UNLOCK_HTC_RX(target);
972 	UNLOCK_HTC_TX(target);
973 
974 	return true;
975 #else
976 	return false;
977 #endif
978 }
979 
980 void *htc_get_targetdef(HTC_HANDLE htc_handle)
981 {
982 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
983 
984 	return hif_get_targetdef(target->hif_dev);
985 }
986 
987 #ifdef IPA_OFFLOAD
988 /**
989  * htc_ipa_get_ce_resource() - get uc resource on lower layer
990  * @htc_handle: htc context
991  * @ce_sr_base_paddr: copyengine source ring base physical address
992  * @ce_sr_ring_size: copyengine source ring size
993  * @ce_reg_paddr: copyengine register physical address
994  *
995  * Return: None
996  */
997 void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle,
998 			     qdf_shared_mem_t **ce_sr,
999 			     uint32_t *ce_sr_ring_size,
1000 			     qdf_dma_addr_t *ce_reg_paddr)
1001 {
1002 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
1003 
1004 	if (target->hif_dev)
1005 		hif_ipa_get_ce_resource(target->hif_dev,
1006 					ce_sr, ce_sr_ring_size, ce_reg_paddr);
1007 }
1008 #endif /* IPA_OFFLOAD */
1009 
1010 #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
1011 
1012 void htc_dump_bundle_stats(HTC_HANDLE HTCHandle)
1013 {
1014 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1015 	int total, i;
1016 
1017 	total = 0;
1018 	for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_RX; i++)
1019 		total += target->rx_bundle_stats[i];
1020 
1021 	if (total) {
1022 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("RX Bundle stats:\n"));
1023 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("Total RX packets: %d\n",
1024 						total));
1025 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (
1026 				"Number of bundle: Number of packets\n"));
1027 		for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_RX; i++)
1028 			AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
1029 					("%10d:%10d(%2d%s)\n", (i+1),
1030 					 target->rx_bundle_stats[i],
1031 					 ((target->rx_bundle_stats[i]*100)/
1032 					  total), "%"));
1033 	}
1034 
1035 
1036 	total = 0;
1037 	for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_TX; i++)
1038 		total += target->tx_bundle_stats[i];
1039 
1040 	if (total) {
1041 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("TX Bundle stats:\n"));
1042 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("Total TX packets: %d\n",
1043 						total));
1044 		AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
1045 				("Number of bundle: Number of packets\n"));
1046 		for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_TX; i++)
1047 			AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
1048 					("%10d:%10d(%2d%s)\n", (i+1),
1049 					 target->tx_bundle_stats[i],
1050 					 ((target->tx_bundle_stats[i]*100)/
1051 					  total), "%"));
1052 	}
1053 }
1054 
1055 void htc_clear_bundle_stats(HTC_HANDLE HTCHandle)
1056 {
1057 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1058 
1059 	qdf_mem_zero(&target->rx_bundle_stats, sizeof(target->rx_bundle_stats));
1060 	qdf_mem_zero(&target->tx_bundle_stats, sizeof(target->tx_bundle_stats));
1061 }
1062 #endif
1063 
1064 /**
1065  * htc_vote_link_down - API to vote for link down
1066  * @htc_handle: HTC handle
1067  *
1068  * API for upper layers to call HIF to vote for link down
1069  *
1070  * Return: void
1071  */
1072 void htc_vote_link_down(HTC_HANDLE htc_handle)
1073 {
1074 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
1075 
1076 	if (!target->hif_dev)
1077 		return;
1078 
1079 	hif_vote_link_down(target->hif_dev);
1080 }
1081 
1082 /**
1083  * htc_vote_link_up - API to vote for link up
1084  * @htc_handle: HTC Handle
1085  *
1086  * API for upper layers to call HIF to vote for link up
1087  *
1088  * Return: void
1089  */
1090 void htc_vote_link_up(HTC_HANDLE htc_handle)
1091 {
1092 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
1093 
1094 	if (!target->hif_dev)
1095 		return;
1096 
1097 	hif_vote_link_up(target->hif_dev);
1098 }
1099 
1100 /**
1101  * htc_can_suspend_link - API to query HIF for link status
1102  * @htc_handle: HTC Handle
1103  *
1104  * API for upper layers to call HIF to query if the link can suspend
1105  *
1106  * Return: void
1107  */
1108 bool htc_can_suspend_link(HTC_HANDLE htc_handle)
1109 {
1110 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
1111 
1112 	if (!target->hif_dev)
1113 		return false;
1114 
1115 	return hif_can_suspend_link(target->hif_dev);
1116 }
1117 
1118 #ifdef FEATURE_RUNTIME_PM
1119 int htc_pm_runtime_get(HTC_HANDLE htc_handle)
1120 {
1121 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
1122 
1123 	return hif_pm_runtime_get(target->hif_dev);
1124 }
1125 
1126 int htc_pm_runtime_put(HTC_HANDLE htc_handle)
1127 {
1128 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
1129 
1130 	return hif_pm_runtime_put(target->hif_dev);
1131 }
1132 #endif
1133 
1134 /**
1135  * htc_set_wmi_endpoint_count: Set number of WMI endpoint
1136  * @htc_handle: HTC handle
1137  * @wmi_ep_count: WMI enpoint count
1138  *
1139  * return: None
1140  */
1141 void htc_set_wmi_endpoint_count(HTC_HANDLE htc_handle, uint8_t wmi_ep_count)
1142 {
1143 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
1144 
1145 	target->wmi_ep_count = wmi_ep_count;
1146 }
1147 
1148 /**
1149  * htc_get_wmi_endpoint_count: Get number of WMI endpoint
1150  * @htc_handle: HTC handle
1151  *
1152  * return: WMI enpoint count
1153  */
1154 uint8_t htc_get_wmi_endpoint_count(HTC_HANDLE htc_handle)
1155 {
1156 	HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
1157 
1158 	return target->wmi_ep_count;
1159 }
1160