htc.c 31 KB

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