htc.c 32 KB

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