htc.c 31 KB

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