htc.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. /*
  2. * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include "htc_debug.h"
  20. #include "htc_internal.h"
  21. #include "htc_credit_history.h"
  22. #include "htc_hang_event.h"
  23. #include <hif.h>
  24. #include <qdf_nbuf.h> /* qdf_nbuf_t */
  25. #include <qdf_types.h> /* qdf_print */
  26. #define MAX_HTC_RX_BUNDLE 2
  27. #if defined(WLAN_DEBUG) || defined(DEBUG)
  28. static ATH_DEBUG_MASK_DESCRIPTION g_htc_debug_description[] = {
  29. {ATH_DEBUG_SEND, "Send"},
  30. {ATH_DEBUG_RECV, "Recv"},
  31. {ATH_DEBUG_SYNC, "Sync"},
  32. {ATH_DEBUG_DUMP, "Dump Data (RX or TX)"},
  33. {ATH_DEBUG_SETUP, "Setup"},
  34. };
  35. ATH_DEBUG_INSTANTIATE_MODULE_VAR(htc,
  36. "htc",
  37. "Host Target Communications",
  38. ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_INFO |
  39. ATH_DEBUG_SETUP,
  40. ATH_DEBUG_DESCRIPTION_COUNT
  41. (g_htc_debug_description),
  42. g_htc_debug_description);
  43. #endif
  44. #if defined(WMI_MULTI_MAC_SVC)
  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_rtpm_put(HIF_RTPM_PUT_ASYNC, HIF_RTPM_ID_HTT);
  131. if (target->hif_dev) {
  132. hif_detach_htc(target->hif_dev);
  133. hif_mask_interrupt_call(target->hif_dev);
  134. target->hif_dev = NULL;
  135. }
  136. while (true) {
  137. pPacket = allocate_htc_packet_container(target);
  138. if (!pPacket)
  139. break;
  140. qdf_mem_free(pPacket);
  141. }
  142. LOCK_HTC_TX(target);
  143. pPacket = target->pBundleFreeList;
  144. target->pBundleFreeList = NULL;
  145. UNLOCK_HTC_TX(target);
  146. while (pPacket) {
  147. HTC_PACKET *pPacketTmp = (HTC_PACKET *) pPacket->ListLink.pNext;
  148. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  149. if (netbuf)
  150. qdf_nbuf_free(netbuf);
  151. pkt_queue = pPacket->pContext;
  152. if (pkt_queue)
  153. qdf_mem_free(pkt_queue);
  154. qdf_mem_free(pPacket);
  155. pPacket = pPacketTmp;
  156. }
  157. #ifdef TODO_FIXME
  158. while (true) {
  159. pPacket = htc_alloc_control_tx_packet(target);
  160. if (!pPacket)
  161. break;
  162. netbuf = (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  163. if (netbuf)
  164. qdf_nbuf_free(netbuf);
  165. qdf_mem_free(pPacket);
  166. }
  167. #endif
  168. HTC_INFO("%s: Non flow ctrl enabled endpoints nbuf map: %d, unamp: %d",
  169. __func__, target->nbuf_nfc_map_count,
  170. target->nbuf_nfc_unmap_count);
  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. #ifdef WLAN_DEBUG_LINK_VOTE
  277. static qdf_atomic_t htc_link_vote_ids[HTC_LINK_VOTE_INVALID_MAX_USER_ID];
  278. static void htc_init_link_vote_ids(void)
  279. {
  280. uint32_t i;
  281. for (i = HTC_LINK_VOTE_INVALID_MIN_USER_ID;
  282. i < HTC_LINK_VOTE_INVALID_MAX_USER_ID; i++)
  283. qdf_atomic_init(&htc_link_vote_ids[i]);
  284. }
  285. void htc_log_link_user_votes(void)
  286. {
  287. uint32_t i;
  288. uint32_t link_vote;
  289. for (i = HTC_LINK_VOTE_INVALID_MIN_USER_ID + 1;
  290. i < HTC_LINK_VOTE_INVALID_MAX_USER_ID; i++) {
  291. link_vote = qdf_atomic_read(&htc_link_vote_ids[i]);
  292. if (link_vote)
  293. HTC_NOFL_INFO("Link vote %d user id: %d",
  294. link_vote, i);
  295. }
  296. }
  297. void htc_vote_link_down(HTC_HANDLE htc_handle, enum htc_link_vote_user_id id)
  298. {
  299. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  300. if (!target->hif_dev)
  301. return;
  302. if (id >= HTC_LINK_VOTE_INVALID_MAX_USER_ID ||
  303. id <= HTC_LINK_VOTE_INVALID_MIN_USER_ID) {
  304. HTC_ERROR("invalid id: %d", id);
  305. return;
  306. }
  307. hif_vote_link_down(target->hif_dev);
  308. qdf_atomic_dec(&htc_link_vote_ids[id]);
  309. }
  310. void htc_vote_link_up(HTC_HANDLE htc_handle, enum htc_link_vote_user_id id)
  311. {
  312. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  313. if (!target->hif_dev)
  314. return;
  315. if (id >= HTC_LINK_VOTE_INVALID_MAX_USER_ID ||
  316. id <= HTC_LINK_VOTE_INVALID_MIN_USER_ID) {
  317. HTC_ERROR("invalid link vote user id: %d", id);
  318. return;
  319. }
  320. hif_vote_link_up(target->hif_dev);
  321. qdf_atomic_inc(&htc_link_vote_ids[id]);
  322. }
  323. #else
  324. static inline
  325. void htc_init_link_vote_ids(void)
  326. {
  327. }
  328. #endif
  329. /* registered target arrival callback from the HIF layer */
  330. HTC_HANDLE htc_create(void *ol_sc, struct htc_init_info *pInfo,
  331. qdf_device_t osdev, uint32_t con_mode)
  332. {
  333. struct hif_msg_callbacks htcCallbacks;
  334. HTC_ENDPOINT *pEndpoint = NULL;
  335. HTC_TARGET *target = NULL;
  336. int i;
  337. if (!ol_sc) {
  338. HTC_ERROR("%s: ol_sc = NULL", __func__);
  339. return NULL;
  340. }
  341. HTC_TRACE("+htc_create .. HIF :%pK", ol_sc);
  342. A_REGISTER_MODULE_DEBUG_INFO(htc);
  343. target = (HTC_TARGET *) qdf_mem_malloc(sizeof(HTC_TARGET));
  344. if (!target)
  345. return NULL;
  346. htc_runtime_pm_init(target);
  347. htc_credit_history_init();
  348. qdf_spinlock_create(&target->HTCLock);
  349. qdf_spinlock_create(&target->HTCRxLock);
  350. qdf_spinlock_create(&target->HTCTxLock);
  351. for (i = 0; i < ENDPOINT_MAX; i++) {
  352. pEndpoint = &target->endpoint[i];
  353. qdf_spinlock_create(&pEndpoint->lookup_queue_lock);
  354. }
  355. target->is_nodrop_pkt = false;
  356. target->htc_hdr_length_check = false;
  357. target->wmi_ep_count = 1;
  358. do {
  359. qdf_mem_copy(&target->HTCInitInfo, pInfo,
  360. sizeof(struct htc_init_info));
  361. target->host_handle = pInfo->pContext;
  362. target->osdev = osdev;
  363. target->con_mode = con_mode;
  364. /* If htc_ready_timeout_ms is not configured from CFG,
  365. * assign the default timeout value here.
  366. */
  367. if (!target->HTCInitInfo.htc_ready_timeout_ms)
  368. target->HTCInitInfo.htc_ready_timeout_ms =
  369. HTC_CONTROL_RX_TIMEOUT;
  370. reset_endpoint_states(target);
  371. INIT_HTC_PACKET_QUEUE(&target->ControlBufferTXFreeList);
  372. for (i = 0; i < HTC_PACKET_CONTAINER_ALLOCATION; i++) {
  373. HTC_PACKET *pPacket = (HTC_PACKET *)
  374. qdf_mem_malloc(sizeof(HTC_PACKET));
  375. if (pPacket)
  376. free_htc_packet_container(target, pPacket);
  377. }
  378. #ifdef TODO_FIXME
  379. for (i = 0; i < NUM_CONTROL_TX_BUFFERS; i++) {
  380. pPacket = build_htc_tx_ctrl_packet();
  381. if (!pPacket)
  382. break;
  383. htc_free_control_tx_packet(target, pPacket);
  384. }
  385. #endif
  386. /* setup HIF layer callbacks */
  387. qdf_mem_zero(&htcCallbacks, sizeof(struct hif_msg_callbacks));
  388. htcCallbacks.Context = target;
  389. htcCallbacks.rxCompletionHandler = htc_rx_completion_handler;
  390. htcCallbacks.txCompletionHandler = htc_tx_completion_handler;
  391. htcCallbacks.txResourceAvailHandler =
  392. htc_tx_resource_avail_handler;
  393. htcCallbacks.fwEventHandler = htc_fw_event_handler;
  394. htcCallbacks.update_bundle_stats = htc_update_rx_bundle_stats;
  395. target->hif_dev = ol_sc;
  396. /* Get HIF default pipe for HTC message exchange */
  397. pEndpoint = &target->endpoint[ENDPOINT_0];
  398. hif_post_init(target->hif_dev, target, &htcCallbacks);
  399. hif_get_default_pipe(target->hif_dev, &pEndpoint->UL_PipeID,
  400. &pEndpoint->DL_PipeID);
  401. hif_set_initial_wakeup_cb(target->hif_dev,
  402. pInfo->target_initial_wakeup_cb,
  403. pInfo->target_psoc);
  404. } while (false);
  405. htc_recv_init(target);
  406. htc_init_runtime_cnt(target);
  407. HTC_TRACE("-htc_create: (0x%pK)", target);
  408. htc_hang_event_notifier_register(target);
  409. htc_init_link_vote_ids();
  410. hif_rtpm_register(HIF_RTPM_ID_WMI, NULL);
  411. hif_rtpm_register(HIF_RTPM_ID_HTT, NULL);
  412. return (HTC_HANDLE) target;
  413. }
  414. void htc_destroy(HTC_HANDLE HTCHandle)
  415. {
  416. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  417. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  418. ("+htc_destroy .. Destroying :0x%pK\n", target));
  419. htc_hang_event_notifier_unregister();
  420. if (target) {
  421. hif_rtpm_deregister(HIF_RTPM_ID_HTT);
  422. hif_rtpm_deregister(HIF_RTPM_ID_WMI);
  423. hif_stop(htc_get_hif_device(HTCHandle));
  424. htc_cleanup(target);
  425. }
  426. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_destroy\n"));
  427. htc_credit_history_deinit();
  428. }
  429. /* get the low level HIF device for the caller , the caller may wish to do low
  430. * level HIF requests
  431. */
  432. void *htc_get_hif_device(HTC_HANDLE HTCHandle)
  433. {
  434. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  435. return target->hif_dev;
  436. }
  437. static void htc_control_tx_complete(void *Context, HTC_PACKET *pPacket)
  438. {
  439. HTC_TARGET *target = (HTC_TARGET *) Context;
  440. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  441. ("+-htc_control_tx_complete 0x%pK (l:%d)\n", pPacket,
  442. pPacket->ActualLength));
  443. htc_free_control_tx_packet(target, pPacket);
  444. }
  445. /* TODO, this is just a temporary max packet size */
  446. #define MAX_MESSAGE_SIZE 1536
  447. /**
  448. * htc_setup_epping_credit_allocation() - allocate credits/HTC buffers to WMI
  449. * @scn: pointer to hif_opaque_softc
  450. * @pEntry: pointer to tx credit allocation entry
  451. * @credits: number of credits
  452. *
  453. * Return: None
  454. */
  455. static void
  456. htc_setup_epping_credit_allocation(struct hif_opaque_softc *scn,
  457. struct htc_service_tx_credit_allocation *pEntry,
  458. int credits)
  459. {
  460. switch (hif_get_bus_type(scn)) {
  461. case QDF_BUS_TYPE_PCI:
  462. case QDF_BUS_TYPE_USB:
  463. pEntry++;
  464. pEntry->service_id = WMI_DATA_BE_SVC;
  465. pEntry->CreditAllocation = (credits >> 1);
  466. pEntry++;
  467. pEntry->service_id = WMI_DATA_BK_SVC;
  468. pEntry->CreditAllocation = (credits >> 1);
  469. break;
  470. case QDF_BUS_TYPE_SDIO:
  471. pEntry++;
  472. pEntry->service_id = WMI_DATA_BE_SVC;
  473. pEntry->CreditAllocation = credits;
  474. break;
  475. default:
  476. break;
  477. }
  478. }
  479. /**
  480. * htc_setup_target_buffer_assignments() - setup target buffer assignments
  481. * @target: HTC Target Pointer
  482. *
  483. * Return: A_STATUS
  484. */
  485. static
  486. A_STATUS htc_setup_target_buffer_assignments(HTC_TARGET *target)
  487. {
  488. struct htc_service_tx_credit_allocation *pEntry;
  489. A_STATUS status;
  490. int credits;
  491. int creditsPerMaxMsg;
  492. creditsPerMaxMsg = MAX_MESSAGE_SIZE / target->TargetCreditSize;
  493. if (MAX_MESSAGE_SIZE % target->TargetCreditSize)
  494. creditsPerMaxMsg++;
  495. /* TODO, this should be configured by the caller! */
  496. credits = target->TotalTransmitCredits;
  497. pEntry = &target->ServiceTxAllocTable[0];
  498. status = A_OK;
  499. /*
  500. * Allocate all credists/HTC buffers to WMI.
  501. * no buffers are used/required for data. data always
  502. * remains on host.
  503. */
  504. if (HTC_IS_EPPING_ENABLED(target->con_mode)) {
  505. pEntry++;
  506. pEntry->service_id = WMI_CONTROL_SVC;
  507. pEntry->CreditAllocation = credits;
  508. /* endpoint ping is a testing tool directly on top of HTC in
  509. * both target and host sides.
  510. * In target side, the endppint ping fw has no wlan stack and
  511. * FW mboxping app directly sits on HTC and it simply drops
  512. * or loops back TX packets. For rx perf, FW mboxping app
  513. * generates packets and passes packets to HTC to send to host.
  514. * There is no WMI message exchanges between host and target
  515. * in endpoint ping case.
  516. * In host side, the endpoint ping driver is a Ethernet driver
  517. * and it directly sits on HTC. Only HIF, HTC, QDF, ADF are
  518. * used by the endpoint ping driver. There is no wifi stack
  519. * at all in host side also. For tx perf use case,
  520. * the user space mboxping app sends the raw packets to endpoint
  521. * ping driver and it directly forwards to HTC for transmission
  522. * to stress the bus. For the rx perf, HTC passes the received
  523. * packets to endpoint ping driver and it is passed to the user
  524. * space through the Ethernet interface.
  525. * For credit allocation, in SDIO bus case, only BE service is
  526. * used for tx/rx perf testing so that all credits are given
  527. * to BE service. In PCIe and USB bus case, endpoint ping uses
  528. * both BE and BK services to stress the bus so that the total
  529. * credits are equally distributed to BE and BK services.
  530. */
  531. htc_setup_epping_credit_allocation(target->hif_dev,
  532. pEntry, credits);
  533. } else {
  534. int i;
  535. uint32_t max_wmi_svc = (sizeof(svc_id) / sizeof(uint32_t));
  536. if ((target->wmi_ep_count == 0) ||
  537. (target->wmi_ep_count > max_wmi_svc))
  538. return A_ERROR;
  539. /*
  540. * Divide credit among number of endpoints for WMI
  541. */
  542. credits = credits / target->wmi_ep_count;
  543. for (i = 0; i < target->wmi_ep_count; i++) {
  544. status = A_OK;
  545. pEntry++;
  546. pEntry->service_id = svc_id[i];
  547. pEntry->CreditAllocation = credits;
  548. }
  549. }
  550. if (A_SUCCESS(status)) {
  551. int i;
  552. for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
  553. if (target->ServiceTxAllocTable[i].service_id != 0) {
  554. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  555. ("SVS Index : %d TX : 0x%2.2X : alloc:%d",
  556. i,
  557. target->ServiceTxAllocTable[i].
  558. service_id,
  559. target->ServiceTxAllocTable[i].
  560. CreditAllocation));
  561. }
  562. }
  563. }
  564. return status;
  565. }
  566. uint8_t htc_get_credit_allocation(HTC_TARGET *target, uint16_t service_id)
  567. {
  568. uint8_t allocation = 0;
  569. int i;
  570. for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
  571. if (target->ServiceTxAllocTable[i].service_id == service_id) {
  572. allocation =
  573. target->ServiceTxAllocTable[i].CreditAllocation;
  574. }
  575. }
  576. if (0 == allocation) {
  577. AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1,
  578. ("HTC Service TX : 0x%2.2X : allocation is zero!\n",
  579. service_id));
  580. }
  581. return allocation;
  582. }
  583. QDF_STATUS htc_wait_target(HTC_HANDLE HTCHandle)
  584. {
  585. QDF_STATUS status = QDF_STATUS_SUCCESS;
  586. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  587. HTC_READY_EX_MSG *pReadyMsg;
  588. struct htc_service_connect_req connect;
  589. struct htc_service_connect_resp resp;
  590. HTC_READY_MSG *rdy_msg;
  591. uint16_t htc_rdy_msg_id;
  592. uint8_t i = 0;
  593. HTC_PACKET *rx_bundle_packet, *temp_bundle_packet;
  594. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  595. ("htc_wait_target - Enter (target:0x%pK)\n", HTCHandle));
  596. AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1, ("+HWT\n"));
  597. do {
  598. status = hif_start(target->hif_dev);
  599. if (QDF_IS_STATUS_ERROR(status)) {
  600. AR_DEBUG_PRINTF(ATH_DEBUG_ERROR,
  601. ("hif_start failed\n"));
  602. break;
  603. }
  604. status = htc_wait_recv_ctrl_message(target);
  605. if (QDF_IS_STATUS_ERROR(status))
  606. break;
  607. if (target->CtrlResponseLength < (sizeof(HTC_READY_EX_MSG))) {
  608. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  609. ("Invalid HTC Ready Msg Len:%d!\n",
  610. target->CtrlResponseLength));
  611. status = QDF_STATUS_E_BADMSG;
  612. break;
  613. }
  614. pReadyMsg = (HTC_READY_EX_MSG *) target->CtrlResponseBuffer;
  615. rdy_msg = &pReadyMsg->Version2_0_Info;
  616. htc_rdy_msg_id =
  617. HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, MESSAGEID);
  618. if (htc_rdy_msg_id != HTC_MSG_READY_ID) {
  619. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  620. ("Invalid HTC Ready Msg : 0x%X!\n",
  621. htc_rdy_msg_id));
  622. status = QDF_STATUS_E_BADMSG;
  623. break;
  624. }
  625. target->TotalTransmitCredits = HTC_GET_FIELD(rdy_msg,
  626. HTC_READY_MSG, CREDITCOUNT);
  627. if (target->HTCInitInfo.cfg_wmi_credit_cnt &&
  628. (target->HTCInitInfo.cfg_wmi_credit_cnt <
  629. target->TotalTransmitCredits))
  630. /*
  631. * If INI configured value is less than FW advertised,
  632. * then use INI configured value, otherwise use FW
  633. * advertised.
  634. */
  635. target->TotalTransmitCredits =
  636. target->HTCInitInfo.cfg_wmi_credit_cnt;
  637. target->TargetCreditSize =
  638. (int)HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, CREDITSIZE);
  639. target->MaxMsgsPerHTCBundle =
  640. (uint8_t) pReadyMsg->MaxMsgsPerHTCBundle;
  641. UPDATE_ALT_CREDIT(target, pReadyMsg->AltDataCreditSize);
  642. /* for old fw this value is set to 0. But the minimum value
  643. * should be 1, i.e., no bundling
  644. */
  645. if (target->MaxMsgsPerHTCBundle < 1)
  646. target->MaxMsgsPerHTCBundle = 1;
  647. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  648. ("Target Ready! TX resource : %d size:%d, MaxMsgsPerHTCBundle = %d",
  649. target->TotalTransmitCredits,
  650. target->TargetCreditSize,
  651. target->MaxMsgsPerHTCBundle));
  652. if ((0 == target->TotalTransmitCredits)
  653. || (0 == target->TargetCreditSize)) {
  654. status = QDF_STATUS_E_ABORTED;
  655. break;
  656. }
  657. /* Allocate expected number of RX bundle buffer allocation */
  658. if (HTC_RX_BUNDLE_ENABLED(target)) {
  659. temp_bundle_packet = NULL;
  660. for (i = 0; i < MAX_HTC_RX_BUNDLE; i++) {
  661. rx_bundle_packet =
  662. allocate_htc_bundle_packet(target);
  663. if (rx_bundle_packet)
  664. rx_bundle_packet->ListLink.pNext =
  665. (DL_LIST *)temp_bundle_packet;
  666. else
  667. break;
  668. temp_bundle_packet = rx_bundle_packet;
  669. }
  670. LOCK_HTC_TX(target);
  671. target->pBundleFreeList = temp_bundle_packet;
  672. UNLOCK_HTC_TX(target);
  673. }
  674. /* done processing */
  675. target->CtrlResponseProcessing = false;
  676. htc_setup_target_buffer_assignments(target);
  677. /* setup our pseudo HTC control endpoint connection */
  678. qdf_mem_zero(&connect, sizeof(connect));
  679. qdf_mem_zero(&resp, sizeof(resp));
  680. connect.EpCallbacks.pContext = target;
  681. connect.EpCallbacks.EpTxComplete = htc_control_tx_complete;
  682. connect.EpCallbacks.EpRecv = htc_control_rx_complete;
  683. connect.MaxSendQueueDepth = NUM_CONTROL_TX_BUFFERS;
  684. connect.service_id = HTC_CTRL_RSVD_SVC;
  685. /* connect fake service */
  686. status = htc_connect_service((HTC_HANDLE) target,
  687. &connect, &resp);
  688. } while (false);
  689. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_wait_target - Exit (%d)\n",
  690. status));
  691. AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1, ("-HWT\n"));
  692. return status;
  693. }
  694. /* start HTC, this is called after all services are connected */
  695. static A_STATUS htc_config_target_hif_pipe(HTC_TARGET *target)
  696. {
  697. return A_OK;
  698. }
  699. static void reset_endpoint_states(HTC_TARGET *target)
  700. {
  701. HTC_ENDPOINT *pEndpoint;
  702. int i;
  703. for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
  704. pEndpoint = &target->endpoint[i];
  705. pEndpoint->service_id = 0;
  706. pEndpoint->MaxMsgLength = 0;
  707. pEndpoint->MaxTxQueueDepth = 0;
  708. pEndpoint->Id = i;
  709. INIT_HTC_PACKET_QUEUE(&pEndpoint->TxQueue);
  710. INIT_HTC_PACKET_QUEUE(&pEndpoint->TxLookupQueue);
  711. INIT_HTC_PACKET_QUEUE(&pEndpoint->RxBufferHoldQueue);
  712. pEndpoint->target = target;
  713. pEndpoint->TxCreditFlowEnabled = (bool)htc_credit_flow;
  714. pEndpoint->num_requeues_warn = 0;
  715. pEndpoint->total_num_requeues = 0;
  716. qdf_atomic_init(&pEndpoint->TxProcessCount);
  717. }
  718. }
  719. /**
  720. * htc_start() - Main HTC function to trigger HTC start
  721. * @HTCHandle: pointer to HTC handle
  722. *
  723. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  724. */
  725. QDF_STATUS htc_start(HTC_HANDLE HTCHandle)
  726. {
  727. qdf_nbuf_t netbuf;
  728. QDF_STATUS status = QDF_STATUS_SUCCESS;
  729. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  730. HTC_SETUP_COMPLETE_EX_MSG *pSetupComp;
  731. HTC_PACKET *pSendPacket;
  732. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Enter\n"));
  733. do {
  734. htc_config_target_hif_pipe(target);
  735. /* allocate a buffer to send */
  736. pSendPacket = htc_alloc_control_tx_packet(target);
  737. if (!pSendPacket) {
  738. AR_DEBUG_ASSERT(false);
  739. qdf_print("%s: allocControlTxPacket failed",
  740. __func__);
  741. status = QDF_STATUS_E_NOMEM;
  742. break;
  743. }
  744. netbuf =
  745. (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pSendPacket);
  746. /* assemble setup complete message */
  747. qdf_nbuf_put_tail(netbuf, sizeof(HTC_SETUP_COMPLETE_EX_MSG));
  748. pSetupComp =
  749. (HTC_SETUP_COMPLETE_EX_MSG *) qdf_nbuf_data(netbuf);
  750. qdf_mem_zero(pSetupComp, sizeof(HTC_SETUP_COMPLETE_EX_MSG));
  751. HTC_SET_FIELD(pSetupComp, HTC_SETUP_COMPLETE_EX_MSG,
  752. MESSAGEID, HTC_MSG_SETUP_COMPLETE_EX_ID);
  753. if (!htc_credit_flow) {
  754. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  755. ("HTC will not use TX credit flow control"));
  756. pSetupComp->SetupFlags |=
  757. HTC_SETUP_COMPLETE_FLAGS_DISABLE_TX_CREDIT_FLOW;
  758. } else {
  759. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  760. ("HTC using TX credit flow control"));
  761. }
  762. if ((hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_SDIO) ||
  763. (hif_get_bus_type(target->hif_dev) ==
  764. QDF_BUS_TYPE_USB)) {
  765. if (HTC_RX_BUNDLE_ENABLED(target))
  766. pSetupComp->SetupFlags |=
  767. HTC_SETUP_COMPLETE_FLAGS_ENABLE_BUNDLE_RECV;
  768. hif_set_bundle_mode(target->hif_dev, true,
  769. HTC_MAX_MSG_PER_BUNDLE_RX);
  770. pSetupComp->MaxMsgsPerBundledRecv = HTC_MAX_MSG_PER_BUNDLE_RX;
  771. }
  772. SET_HTC_PACKET_INFO_TX(pSendPacket,
  773. NULL,
  774. (uint8_t *) pSetupComp,
  775. sizeof(HTC_SETUP_COMPLETE_EX_MSG),
  776. ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
  777. status = htc_send_pkt((HTC_HANDLE) target, pSendPacket);
  778. if (QDF_IS_STATUS_ERROR(status))
  779. break;
  780. } while (false);
  781. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Exit\n"));
  782. return status;
  783. }
  784. /*flush all queued buffers for surpriseremove case*/
  785. void htc_flush_surprise_remove(HTC_HANDLE HTCHandle)
  786. {
  787. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  788. int i;
  789. HTC_ENDPOINT *pEndpoint;
  790. #ifdef RX_SG_SUPPORT
  791. qdf_nbuf_t netbuf;
  792. qdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
  793. #endif
  794. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_flush_surprise_remove\n"));
  795. /* cleanup endpoints */
  796. for (i = 0; i < ENDPOINT_MAX; i++) {
  797. pEndpoint = &target->endpoint[i];
  798. htc_flush_rx_hold_queue(target, pEndpoint);
  799. htc_flush_endpoint_tx(target, pEndpoint, HTC_TX_PACKET_TAG_ALL);
  800. }
  801. hif_flush_surprise_remove(target->hif_dev);
  802. #ifdef RX_SG_SUPPORT
  803. LOCK_HTC_RX(target);
  804. while ((netbuf = qdf_nbuf_queue_remove(rx_sg_queue)) != NULL)
  805. qdf_nbuf_free(netbuf);
  806. RESET_RX_SG_CONFIG(target);
  807. UNLOCK_HTC_RX(target);
  808. #endif
  809. reset_endpoint_states(target);
  810. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_flush_surprise_remove\n"));
  811. }
  812. /* stop HTC communications, i.e. stop interrupt reception, and flush all queued
  813. * buffers
  814. */
  815. void htc_stop(HTC_HANDLE HTCHandle)
  816. {
  817. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  818. int i;
  819. HTC_ENDPOINT *endpoint;
  820. #ifdef RX_SG_SUPPORT
  821. qdf_nbuf_t netbuf;
  822. qdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
  823. #endif
  824. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_stop\n"));
  825. htc_runtime_pm_deinit(target);
  826. HTC_INFO("%s: endpoints cleanup\n", __func__);
  827. /* cleanup endpoints */
  828. for (i = 0; i < ENDPOINT_MAX; i++) {
  829. endpoint = &target->endpoint[i];
  830. htc_flush_rx_hold_queue(target, endpoint);
  831. htc_flush_endpoint_tx(target, endpoint, HTC_TX_PACKET_TAG_ALL);
  832. if (endpoint->ul_is_polled) {
  833. qdf_timer_stop(&endpoint->ul_poll_timer);
  834. qdf_timer_free(&endpoint->ul_poll_timer);
  835. }
  836. }
  837. /* Note: htc_flush_endpoint_tx for all endpoints should be called before
  838. * hif_stop - otherwise htc_tx_completion_handler called from
  839. * hif_send_buffer_cleanup_on_pipe for residual tx frames in HIF layer,
  840. * might queue the packet again to HIF Layer - which could cause tx
  841. * buffer leak
  842. */
  843. HTC_INFO("%s: stopping hif layer\n", __func__);
  844. hif_stop(target->hif_dev);
  845. #ifdef RX_SG_SUPPORT
  846. LOCK_HTC_RX(target);
  847. while ((netbuf = qdf_nbuf_queue_remove(rx_sg_queue)) != NULL)
  848. qdf_nbuf_free(netbuf);
  849. RESET_RX_SG_CONFIG(target);
  850. UNLOCK_HTC_RX(target);
  851. #endif
  852. /**
  853. * In SSR case, HTC tx completion callback for wmi will be blocked
  854. * by TARGET_STATUS_RESET and HTC packets will be left unfreed on
  855. * lookup queue.
  856. *
  857. * In case of target failing to send wmi_ready_event, the htc connect
  858. * msg buffer will be left unmapped and not freed. So calling the
  859. * completion handler for this buffer will handle this scenario.
  860. */
  861. HTC_INFO("%s: flush endpoints Tx lookup queue\n", __func__);
  862. for (i = 0; i < ENDPOINT_MAX; i++) {
  863. endpoint = &target->endpoint[i];
  864. if (endpoint->service_id == WMI_CONTROL_SVC)
  865. htc_flush_endpoint_txlookupQ(target, i, false);
  866. else if (endpoint->service_id == HTC_CTRL_RSVD_SVC)
  867. htc_flush_endpoint_txlookupQ(target, i, true);
  868. }
  869. HTC_INFO("%s: resetting endpoints state\n", __func__);
  870. reset_endpoint_states(target);
  871. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_stop\n"));
  872. }
  873. void htc_dump_credit_states(HTC_HANDLE HTCHandle)
  874. {
  875. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  876. HTC_ENDPOINT *pEndpoint;
  877. int i;
  878. for (i = 0; i < ENDPOINT_MAX; i++) {
  879. pEndpoint = &target->endpoint[i];
  880. if (0 == pEndpoint->service_id)
  881. continue;
  882. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  883. ("--- EP : %d service_id: 0x%X --------------\n",
  884. pEndpoint->Id, pEndpoint->service_id));
  885. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  886. (" TxCredits : %d\n",
  887. pEndpoint->TxCredits));
  888. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  889. (" TxCreditSize : %d\n",
  890. pEndpoint->TxCreditSize));
  891. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  892. (" TxCreditsPerMaxMsg : %d\n",
  893. pEndpoint->TxCreditsPerMaxMsg));
  894. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  895. (" TxQueueDepth : %d\n",
  896. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)));
  897. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  898. ("----------------------------------------\n"));
  899. }
  900. }
  901. bool htc_get_endpoint_statistics(HTC_HANDLE HTCHandle,
  902. HTC_ENDPOINT_ID Endpoint,
  903. enum htc_endpoint_stat_action Action,
  904. struct htc_endpoint_stats *pStats)
  905. {
  906. #ifdef HTC_EP_STAT_PROFILING
  907. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  908. bool clearStats = false;
  909. bool sample = false;
  910. switch (Action) {
  911. case HTC_EP_STAT_SAMPLE:
  912. sample = true;
  913. break;
  914. case HTC_EP_STAT_SAMPLE_AND_CLEAR:
  915. sample = true;
  916. clearStats = true;
  917. break;
  918. case HTC_EP_STAT_CLEAR:
  919. clearStats = true;
  920. break;
  921. default:
  922. break;
  923. }
  924. A_ASSERT(Endpoint < ENDPOINT_MAX);
  925. /* lock out TX and RX while we sample and/or clear */
  926. LOCK_HTC_TX(target);
  927. LOCK_HTC_RX(target);
  928. if (sample) {
  929. A_ASSERT(pStats);
  930. /* return the stats to the caller */
  931. qdf_mem_copy(pStats, &target->endpoint[Endpoint].endpoint_stats,
  932. sizeof(struct htc_endpoint_stats));
  933. }
  934. if (clearStats) {
  935. /* reset stats */
  936. qdf_mem_zero(&target->endpoint[Endpoint].endpoint_stats,
  937. sizeof(struct htc_endpoint_stats));
  938. }
  939. UNLOCK_HTC_RX(target);
  940. UNLOCK_HTC_TX(target);
  941. return true;
  942. #else
  943. return false;
  944. #endif
  945. }
  946. void *htc_get_targetdef(HTC_HANDLE htc_handle)
  947. {
  948. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  949. return hif_get_targetdef(target->hif_dev);
  950. }
  951. #ifdef IPA_OFFLOAD
  952. /**
  953. * htc_ipa_get_ce_resource() - get uc resource on lower layer
  954. * @htc_handle: htc context
  955. * @ce_sr_base_paddr: copyengine source ring base physical address
  956. * @ce_sr_ring_size: copyengine source ring size
  957. * @ce_reg_paddr: copyengine register physical address
  958. *
  959. * Return: None
  960. */
  961. void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle,
  962. qdf_shared_mem_t **ce_sr,
  963. uint32_t *ce_sr_ring_size,
  964. qdf_dma_addr_t *ce_reg_paddr)
  965. {
  966. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  967. if (target->hif_dev)
  968. hif_ipa_get_ce_resource(target->hif_dev,
  969. ce_sr, ce_sr_ring_size, ce_reg_paddr);
  970. }
  971. #endif /* IPA_OFFLOAD */
  972. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  973. void htc_dump_bundle_stats(HTC_HANDLE HTCHandle)
  974. {
  975. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  976. int total, i;
  977. total = 0;
  978. for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_RX; i++)
  979. total += target->rx_bundle_stats[i];
  980. if (total) {
  981. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("RX Bundle stats:\n"));
  982. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("Total RX packets: %d\n",
  983. total));
  984. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (
  985. "Number of bundle: Number of packets\n"));
  986. for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_RX; i++)
  987. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  988. ("%10d:%10d(%2d%s)\n", (i+1),
  989. target->rx_bundle_stats[i],
  990. ((target->rx_bundle_stats[i]*100)/
  991. total), "%"));
  992. }
  993. total = 0;
  994. for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_TX; i++)
  995. total += target->tx_bundle_stats[i];
  996. if (total) {
  997. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("TX Bundle stats:\n"));
  998. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("Total TX packets: %d\n",
  999. total));
  1000. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  1001. ("Number of bundle: Number of packets\n"));
  1002. for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_TX; i++)
  1003. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  1004. ("%10d:%10d(%2d%s)\n", (i+1),
  1005. target->tx_bundle_stats[i],
  1006. ((target->tx_bundle_stats[i]*100)/
  1007. total), "%"));
  1008. }
  1009. }
  1010. void htc_clear_bundle_stats(HTC_HANDLE HTCHandle)
  1011. {
  1012. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1013. qdf_mem_zero(&target->rx_bundle_stats, sizeof(target->rx_bundle_stats));
  1014. qdf_mem_zero(&target->tx_bundle_stats, sizeof(target->tx_bundle_stats));
  1015. }
  1016. #endif
  1017. /**
  1018. * htc_can_suspend_link - API to query HIF for link status
  1019. * @htc_handle: HTC Handle
  1020. *
  1021. * API for upper layers to call HIF to query if the link can suspend
  1022. *
  1023. * Return: void
  1024. */
  1025. bool htc_can_suspend_link(HTC_HANDLE htc_handle)
  1026. {
  1027. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  1028. if (!target->hif_dev)
  1029. return false;
  1030. return hif_can_suspend_link(target->hif_dev);
  1031. }
  1032. #ifdef FEATURE_RUNTIME_PM
  1033. int htc_pm_runtime_get(HTC_HANDLE htc_handle)
  1034. {
  1035. return hif_rtpm_get(HIF_RTPM_GET_ASYNC, HIF_RTPM_ID_HTT);
  1036. }
  1037. int htc_pm_runtime_put(HTC_HANDLE htc_handle)
  1038. {
  1039. return hif_rtpm_put(HIF_RTPM_PUT_ASYNC, HIF_RTPM_ID_HTT);
  1040. }
  1041. #endif
  1042. /**
  1043. * htc_set_wmi_endpoint_count: Set number of WMI endpoint
  1044. * @htc_handle: HTC handle
  1045. * @wmi_ep_count: WMI enpoint count
  1046. *
  1047. * return: None
  1048. */
  1049. void htc_set_wmi_endpoint_count(HTC_HANDLE htc_handle, uint8_t wmi_ep_count)
  1050. {
  1051. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  1052. target->wmi_ep_count = wmi_ep_count;
  1053. }
  1054. /**
  1055. * htc_get_wmi_endpoint_count: Get number of WMI endpoint
  1056. * @htc_handle: HTC handle
  1057. *
  1058. * return: WMI enpoint count
  1059. */
  1060. uint8_t htc_get_wmi_endpoint_count(HTC_HANDLE htc_handle)
  1061. {
  1062. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  1063. return target->wmi_ep_count;
  1064. }