htc.c 31 KB

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