htc.c 33 KB

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