htc.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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) || defined(QCA_WIFI_QCA9574))
  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. #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. return (HTC_HANDLE) target;
  411. }
  412. void htc_destroy(HTC_HANDLE HTCHandle)
  413. {
  414. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  415. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  416. ("+htc_destroy .. Destroying :0x%pK\n", target));
  417. htc_hang_event_notifier_unregister();
  418. hif_stop(htc_get_hif_device(HTCHandle));
  419. if (target)
  420. htc_cleanup(target);
  421. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_destroy\n"));
  422. htc_credit_history_deinit();
  423. }
  424. /* get the low level HIF device for the caller , the caller may wish to do low
  425. * level HIF requests
  426. */
  427. void *htc_get_hif_device(HTC_HANDLE HTCHandle)
  428. {
  429. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  430. return target->hif_dev;
  431. }
  432. static void htc_control_tx_complete(void *Context, HTC_PACKET *pPacket)
  433. {
  434. HTC_TARGET *target = (HTC_TARGET *) Context;
  435. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  436. ("+-htc_control_tx_complete 0x%pK (l:%d)\n", pPacket,
  437. pPacket->ActualLength));
  438. htc_free_control_tx_packet(target, pPacket);
  439. }
  440. /* TODO, this is just a temporary max packet size */
  441. #define MAX_MESSAGE_SIZE 1536
  442. /**
  443. * htc_setup_epping_credit_allocation() - allocate credits/HTC buffers to WMI
  444. * @scn: pointer to hif_opaque_softc
  445. * @pEntry: pointer to tx credit allocation entry
  446. * @credits: number of credits
  447. *
  448. * Return: None
  449. */
  450. static void
  451. htc_setup_epping_credit_allocation(struct hif_opaque_softc *scn,
  452. struct htc_service_tx_credit_allocation *pEntry,
  453. int credits)
  454. {
  455. switch (hif_get_bus_type(scn)) {
  456. case QDF_BUS_TYPE_PCI:
  457. case QDF_BUS_TYPE_USB:
  458. pEntry++;
  459. pEntry->service_id = WMI_DATA_BE_SVC;
  460. pEntry->CreditAllocation = (credits >> 1);
  461. pEntry++;
  462. pEntry->service_id = WMI_DATA_BK_SVC;
  463. pEntry->CreditAllocation = (credits >> 1);
  464. break;
  465. case QDF_BUS_TYPE_SDIO:
  466. pEntry++;
  467. pEntry->service_id = WMI_DATA_BE_SVC;
  468. pEntry->CreditAllocation = credits;
  469. break;
  470. default:
  471. break;
  472. }
  473. }
  474. /**
  475. * htc_setup_target_buffer_assignments() - setup target buffer assignments
  476. * @target: HTC Target Pointer
  477. *
  478. * Return: A_STATUS
  479. */
  480. static
  481. A_STATUS htc_setup_target_buffer_assignments(HTC_TARGET *target)
  482. {
  483. struct htc_service_tx_credit_allocation *pEntry;
  484. A_STATUS status;
  485. int credits;
  486. int creditsPerMaxMsg;
  487. creditsPerMaxMsg = MAX_MESSAGE_SIZE / target->TargetCreditSize;
  488. if (MAX_MESSAGE_SIZE % target->TargetCreditSize)
  489. creditsPerMaxMsg++;
  490. /* TODO, this should be configured by the caller! */
  491. credits = target->TotalTransmitCredits;
  492. pEntry = &target->ServiceTxAllocTable[0];
  493. status = A_OK;
  494. /*
  495. * Allocate all credists/HTC buffers to WMI.
  496. * no buffers are used/required for data. data always
  497. * remains on host.
  498. */
  499. if (HTC_IS_EPPING_ENABLED(target->con_mode)) {
  500. pEntry++;
  501. pEntry->service_id = WMI_CONTROL_SVC;
  502. pEntry->CreditAllocation = credits;
  503. /* endpoint ping is a testing tool directly on top of HTC in
  504. * both target and host sides.
  505. * In target side, the endppint ping fw has no wlan stack and
  506. * FW mboxping app directly sits on HTC and it simply drops
  507. * or loops back TX packets. For rx perf, FW mboxping app
  508. * generates packets and passes packets to HTC to send to host.
  509. * There is no WMI message exchanges between host and target
  510. * in endpoint ping case.
  511. * In host side, the endpoint ping driver is a Ethernet driver
  512. * and it directly sits on HTC. Only HIF, HTC, QDF, ADF are
  513. * used by the endpoint ping driver. There is no wifi stack
  514. * at all in host side also. For tx perf use case,
  515. * the user space mboxping app sends the raw packets to endpoint
  516. * ping driver and it directly forwards to HTC for transmission
  517. * to stress the bus. For the rx perf, HTC passes the received
  518. * packets to endpoint ping driver and it is passed to the user
  519. * space through the Ethernet interface.
  520. * For credit allocation, in SDIO bus case, only BE service is
  521. * used for tx/rx perf testing so that all credits are given
  522. * to BE service. In PCIe and USB bus case, endpoint ping uses
  523. * both BE and BK services to stress the bus so that the total
  524. * credits are equally distributed to BE and BK services.
  525. */
  526. htc_setup_epping_credit_allocation(target->hif_dev,
  527. pEntry, credits);
  528. } else {
  529. int i;
  530. uint32_t max_wmi_svc = (sizeof(svc_id) / sizeof(uint32_t));
  531. if ((target->wmi_ep_count == 0) ||
  532. (target->wmi_ep_count > max_wmi_svc))
  533. return A_ERROR;
  534. /*
  535. * Divide credit among number of endpoints for WMI
  536. */
  537. credits = credits / target->wmi_ep_count;
  538. for (i = 0; i < target->wmi_ep_count; i++) {
  539. status = A_OK;
  540. pEntry++;
  541. pEntry->service_id = svc_id[i];
  542. pEntry->CreditAllocation = credits;
  543. }
  544. }
  545. if (A_SUCCESS(status)) {
  546. int i;
  547. for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
  548. if (target->ServiceTxAllocTable[i].service_id != 0) {
  549. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  550. ("SVS Index : %d TX : 0x%2.2X : alloc:%d",
  551. i,
  552. target->ServiceTxAllocTable[i].
  553. service_id,
  554. target->ServiceTxAllocTable[i].
  555. CreditAllocation));
  556. }
  557. }
  558. }
  559. return status;
  560. }
  561. uint8_t htc_get_credit_allocation(HTC_TARGET *target, uint16_t service_id)
  562. {
  563. uint8_t allocation = 0;
  564. int i;
  565. for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
  566. if (target->ServiceTxAllocTable[i].service_id == service_id) {
  567. allocation =
  568. target->ServiceTxAllocTable[i].CreditAllocation;
  569. }
  570. }
  571. if (0 == allocation) {
  572. AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1,
  573. ("HTC Service TX : 0x%2.2X : allocation is zero!\n",
  574. service_id));
  575. }
  576. return allocation;
  577. }
  578. QDF_STATUS htc_wait_target(HTC_HANDLE HTCHandle)
  579. {
  580. QDF_STATUS status = QDF_STATUS_SUCCESS;
  581. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  582. HTC_READY_EX_MSG *pReadyMsg;
  583. struct htc_service_connect_req connect;
  584. struct htc_service_connect_resp resp;
  585. HTC_READY_MSG *rdy_msg;
  586. uint16_t htc_rdy_msg_id;
  587. uint8_t i = 0;
  588. HTC_PACKET *rx_bundle_packet, *temp_bundle_packet;
  589. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  590. ("htc_wait_target - Enter (target:0x%pK)\n", HTCHandle));
  591. AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1, ("+HWT\n"));
  592. do {
  593. status = hif_start(target->hif_dev);
  594. if (QDF_IS_STATUS_ERROR(status)) {
  595. AR_DEBUG_PRINTF(ATH_DEBUG_ERROR,
  596. ("hif_start failed\n"));
  597. break;
  598. }
  599. status = htc_wait_recv_ctrl_message(target);
  600. if (QDF_IS_STATUS_ERROR(status))
  601. break;
  602. if (target->CtrlResponseLength < (sizeof(HTC_READY_EX_MSG))) {
  603. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  604. ("Invalid HTC Ready Msg Len:%d!\n",
  605. target->CtrlResponseLength));
  606. status = QDF_STATUS_E_BADMSG;
  607. break;
  608. }
  609. pReadyMsg = (HTC_READY_EX_MSG *) target->CtrlResponseBuffer;
  610. rdy_msg = &pReadyMsg->Version2_0_Info;
  611. htc_rdy_msg_id =
  612. HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, MESSAGEID);
  613. if (htc_rdy_msg_id != HTC_MSG_READY_ID) {
  614. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  615. ("Invalid HTC Ready Msg : 0x%X!\n",
  616. htc_rdy_msg_id));
  617. status = QDF_STATUS_E_BADMSG;
  618. break;
  619. }
  620. target->TotalTransmitCredits = HTC_GET_FIELD(rdy_msg,
  621. HTC_READY_MSG, CREDITCOUNT);
  622. if (target->HTCInitInfo.cfg_wmi_credit_cnt &&
  623. (target->HTCInitInfo.cfg_wmi_credit_cnt <
  624. target->TotalTransmitCredits))
  625. /*
  626. * If INI configured value is less than FW advertised,
  627. * then use INI configured value, otherwise use FW
  628. * advertised.
  629. */
  630. target->TotalTransmitCredits =
  631. target->HTCInitInfo.cfg_wmi_credit_cnt;
  632. target->TargetCreditSize =
  633. (int)HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, CREDITSIZE);
  634. target->MaxMsgsPerHTCBundle =
  635. (uint8_t) pReadyMsg->MaxMsgsPerHTCBundle;
  636. UPDATE_ALT_CREDIT(target, pReadyMsg->AltDataCreditSize);
  637. /* for old fw this value is set to 0. But the minimum value
  638. * should be 1, i.e., no bundling
  639. */
  640. if (target->MaxMsgsPerHTCBundle < 1)
  641. target->MaxMsgsPerHTCBundle = 1;
  642. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  643. ("Target Ready! TX resource : %d size:%d, MaxMsgsPerHTCBundle = %d",
  644. target->TotalTransmitCredits,
  645. target->TargetCreditSize,
  646. target->MaxMsgsPerHTCBundle));
  647. if ((0 == target->TotalTransmitCredits)
  648. || (0 == target->TargetCreditSize)) {
  649. status = QDF_STATUS_E_ABORTED;
  650. break;
  651. }
  652. /* Allocate expected number of RX bundle buffer allocation */
  653. if (HTC_RX_BUNDLE_ENABLED(target)) {
  654. temp_bundle_packet = NULL;
  655. for (i = 0; i < MAX_HTC_RX_BUNDLE; i++) {
  656. rx_bundle_packet =
  657. allocate_htc_bundle_packet(target);
  658. if (rx_bundle_packet)
  659. rx_bundle_packet->ListLink.pNext =
  660. (DL_LIST *)temp_bundle_packet;
  661. else
  662. break;
  663. temp_bundle_packet = rx_bundle_packet;
  664. }
  665. LOCK_HTC_TX(target);
  666. target->pBundleFreeList = temp_bundle_packet;
  667. UNLOCK_HTC_TX(target);
  668. }
  669. /* done processing */
  670. target->CtrlResponseProcessing = false;
  671. htc_setup_target_buffer_assignments(target);
  672. /* setup our pseudo HTC control endpoint connection */
  673. qdf_mem_zero(&connect, sizeof(connect));
  674. qdf_mem_zero(&resp, sizeof(resp));
  675. connect.EpCallbacks.pContext = target;
  676. connect.EpCallbacks.EpTxComplete = htc_control_tx_complete;
  677. connect.EpCallbacks.EpRecv = htc_control_rx_complete;
  678. connect.MaxSendQueueDepth = NUM_CONTROL_TX_BUFFERS;
  679. connect.service_id = HTC_CTRL_RSVD_SVC;
  680. /* connect fake service */
  681. status = htc_connect_service((HTC_HANDLE) target,
  682. &connect, &resp);
  683. } while (false);
  684. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_wait_target - Exit (%d)\n",
  685. status));
  686. AR_DEBUG_PRINTF(ATH_DEBUG_RSVD1, ("-HWT\n"));
  687. return status;
  688. }
  689. /* start HTC, this is called after all services are connected */
  690. static A_STATUS htc_config_target_hif_pipe(HTC_TARGET *target)
  691. {
  692. return A_OK;
  693. }
  694. static void reset_endpoint_states(HTC_TARGET *target)
  695. {
  696. HTC_ENDPOINT *pEndpoint;
  697. int i;
  698. for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
  699. pEndpoint = &target->endpoint[i];
  700. pEndpoint->service_id = 0;
  701. pEndpoint->MaxMsgLength = 0;
  702. pEndpoint->MaxTxQueueDepth = 0;
  703. pEndpoint->Id = i;
  704. INIT_HTC_PACKET_QUEUE(&pEndpoint->TxQueue);
  705. INIT_HTC_PACKET_QUEUE(&pEndpoint->TxLookupQueue);
  706. INIT_HTC_PACKET_QUEUE(&pEndpoint->RxBufferHoldQueue);
  707. pEndpoint->target = target;
  708. pEndpoint->TxCreditFlowEnabled = (bool)htc_credit_flow;
  709. pEndpoint->num_requeues_warn = 0;
  710. pEndpoint->total_num_requeues = 0;
  711. qdf_atomic_init(&pEndpoint->TxProcessCount);
  712. }
  713. }
  714. /**
  715. * htc_start() - Main HTC function to trigger HTC start
  716. * @HTCHandle: pointer to HTC handle
  717. *
  718. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  719. */
  720. QDF_STATUS htc_start(HTC_HANDLE HTCHandle)
  721. {
  722. qdf_nbuf_t netbuf;
  723. QDF_STATUS status = QDF_STATUS_SUCCESS;
  724. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  725. HTC_SETUP_COMPLETE_EX_MSG *pSetupComp;
  726. HTC_PACKET *pSendPacket;
  727. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Enter\n"));
  728. do {
  729. htc_config_target_hif_pipe(target);
  730. /* allocate a buffer to send */
  731. pSendPacket = htc_alloc_control_tx_packet(target);
  732. if (!pSendPacket) {
  733. AR_DEBUG_ASSERT(false);
  734. qdf_print("%s: allocControlTxPacket failed",
  735. __func__);
  736. status = QDF_STATUS_E_NOMEM;
  737. break;
  738. }
  739. netbuf =
  740. (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pSendPacket);
  741. /* assemble setup complete message */
  742. qdf_nbuf_put_tail(netbuf, sizeof(HTC_SETUP_COMPLETE_EX_MSG));
  743. pSetupComp =
  744. (HTC_SETUP_COMPLETE_EX_MSG *) qdf_nbuf_data(netbuf);
  745. qdf_mem_zero(pSetupComp, sizeof(HTC_SETUP_COMPLETE_EX_MSG));
  746. HTC_SET_FIELD(pSetupComp, HTC_SETUP_COMPLETE_EX_MSG,
  747. MESSAGEID, HTC_MSG_SETUP_COMPLETE_EX_ID);
  748. if (!htc_credit_flow) {
  749. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  750. ("HTC will not use TX credit flow control"));
  751. pSetupComp->SetupFlags |=
  752. HTC_SETUP_COMPLETE_FLAGS_DISABLE_TX_CREDIT_FLOW;
  753. } else {
  754. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  755. ("HTC using TX credit flow control"));
  756. }
  757. if ((hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_SDIO) ||
  758. (hif_get_bus_type(target->hif_dev) ==
  759. QDF_BUS_TYPE_USB)) {
  760. if (HTC_RX_BUNDLE_ENABLED(target))
  761. pSetupComp->SetupFlags |=
  762. HTC_SETUP_COMPLETE_FLAGS_ENABLE_BUNDLE_RECV;
  763. hif_set_bundle_mode(target->hif_dev, true,
  764. HTC_MAX_MSG_PER_BUNDLE_RX);
  765. pSetupComp->MaxMsgsPerBundledRecv = HTC_MAX_MSG_PER_BUNDLE_RX;
  766. }
  767. SET_HTC_PACKET_INFO_TX(pSendPacket,
  768. NULL,
  769. (uint8_t *) pSetupComp,
  770. sizeof(HTC_SETUP_COMPLETE_EX_MSG),
  771. ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
  772. status = htc_send_pkt((HTC_HANDLE) target, pSendPacket);
  773. if (QDF_IS_STATUS_ERROR(status))
  774. break;
  775. } while (false);
  776. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Exit\n"));
  777. return status;
  778. }
  779. /*flush all queued buffers for surpriseremove case*/
  780. void htc_flush_surprise_remove(HTC_HANDLE HTCHandle)
  781. {
  782. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  783. int i;
  784. HTC_ENDPOINT *pEndpoint;
  785. #ifdef RX_SG_SUPPORT
  786. qdf_nbuf_t netbuf;
  787. qdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
  788. #endif
  789. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_flush_surprise_remove\n"));
  790. /* cleanup endpoints */
  791. for (i = 0; i < ENDPOINT_MAX; i++) {
  792. pEndpoint = &target->endpoint[i];
  793. htc_flush_rx_hold_queue(target, pEndpoint);
  794. htc_flush_endpoint_tx(target, pEndpoint, HTC_TX_PACKET_TAG_ALL);
  795. }
  796. hif_flush_surprise_remove(target->hif_dev);
  797. #ifdef RX_SG_SUPPORT
  798. LOCK_HTC_RX(target);
  799. while ((netbuf = qdf_nbuf_queue_remove(rx_sg_queue)) != NULL)
  800. qdf_nbuf_free(netbuf);
  801. RESET_RX_SG_CONFIG(target);
  802. UNLOCK_HTC_RX(target);
  803. #endif
  804. reset_endpoint_states(target);
  805. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_flush_surprise_remove\n"));
  806. }
  807. /* stop HTC communications, i.e. stop interrupt reception, and flush all queued
  808. * buffers
  809. */
  810. void htc_stop(HTC_HANDLE HTCHandle)
  811. {
  812. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  813. int i;
  814. HTC_ENDPOINT *endpoint;
  815. #ifdef RX_SG_SUPPORT
  816. qdf_nbuf_t netbuf;
  817. qdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
  818. #endif
  819. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_stop\n"));
  820. htc_runtime_pm_deinit(target);
  821. HTC_INFO("%s: endpoints cleanup\n", __func__);
  822. /* cleanup endpoints */
  823. for (i = 0; i < ENDPOINT_MAX; i++) {
  824. endpoint = &target->endpoint[i];
  825. htc_flush_rx_hold_queue(target, endpoint);
  826. htc_flush_endpoint_tx(target, endpoint, HTC_TX_PACKET_TAG_ALL);
  827. if (endpoint->ul_is_polled) {
  828. qdf_timer_stop(&endpoint->ul_poll_timer);
  829. qdf_timer_free(&endpoint->ul_poll_timer);
  830. }
  831. }
  832. /* Note: htc_flush_endpoint_tx for all endpoints should be called before
  833. * hif_stop - otherwise htc_tx_completion_handler called from
  834. * hif_send_buffer_cleanup_on_pipe for residual tx frames in HIF layer,
  835. * might queue the packet again to HIF Layer - which could cause tx
  836. * buffer leak
  837. */
  838. HTC_INFO("%s: stopping hif layer\n", __func__);
  839. hif_stop(target->hif_dev);
  840. #ifdef RX_SG_SUPPORT
  841. LOCK_HTC_RX(target);
  842. while ((netbuf = qdf_nbuf_queue_remove(rx_sg_queue)) != NULL)
  843. qdf_nbuf_free(netbuf);
  844. RESET_RX_SG_CONFIG(target);
  845. UNLOCK_HTC_RX(target);
  846. #endif
  847. /**
  848. * In SSR case, HTC tx completion callback for wmi will be blocked
  849. * by TARGET_STATUS_RESET and HTC packets will be left unfreed on
  850. * lookup queue.
  851. *
  852. * In case of target failing to send wmi_ready_event, the htc connect
  853. * msg buffer will be left unmapped and not freed. So calling the
  854. * completion handler for this buffer will handle this scenario.
  855. */
  856. HTC_INFO("%s: flush endpoints Tx lookup queue\n", __func__);
  857. for (i = 0; i < ENDPOINT_MAX; i++) {
  858. endpoint = &target->endpoint[i];
  859. if (endpoint->service_id == WMI_CONTROL_SVC)
  860. htc_flush_endpoint_txlookupQ(target, i, false);
  861. else if (endpoint->service_id == HTC_CTRL_RSVD_SVC)
  862. htc_flush_endpoint_txlookupQ(target, i, true);
  863. }
  864. HTC_INFO("%s: resetting endpoints state\n", __func__);
  865. reset_endpoint_states(target);
  866. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_stop\n"));
  867. }
  868. void htc_dump_credit_states(HTC_HANDLE HTCHandle)
  869. {
  870. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  871. HTC_ENDPOINT *pEndpoint;
  872. int i;
  873. for (i = 0; i < ENDPOINT_MAX; i++) {
  874. pEndpoint = &target->endpoint[i];
  875. if (0 == pEndpoint->service_id)
  876. continue;
  877. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  878. ("--- EP : %d service_id: 0x%X --------------\n",
  879. pEndpoint->Id, pEndpoint->service_id));
  880. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  881. (" TxCredits : %d\n",
  882. pEndpoint->TxCredits));
  883. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  884. (" TxCreditSize : %d\n",
  885. pEndpoint->TxCreditSize));
  886. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  887. (" TxCreditsPerMaxMsg : %d\n",
  888. pEndpoint->TxCreditsPerMaxMsg));
  889. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  890. (" TxQueueDepth : %d\n",
  891. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)));
  892. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  893. ("----------------------------------------\n"));
  894. }
  895. }
  896. bool htc_get_endpoint_statistics(HTC_HANDLE HTCHandle,
  897. HTC_ENDPOINT_ID Endpoint,
  898. enum htc_endpoint_stat_action Action,
  899. struct htc_endpoint_stats *pStats)
  900. {
  901. #ifdef HTC_EP_STAT_PROFILING
  902. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  903. bool clearStats = false;
  904. bool sample = false;
  905. switch (Action) {
  906. case HTC_EP_STAT_SAMPLE:
  907. sample = true;
  908. break;
  909. case HTC_EP_STAT_SAMPLE_AND_CLEAR:
  910. sample = true;
  911. clearStats = true;
  912. break;
  913. case HTC_EP_STAT_CLEAR:
  914. clearStats = true;
  915. break;
  916. default:
  917. break;
  918. }
  919. A_ASSERT(Endpoint < ENDPOINT_MAX);
  920. /* lock out TX and RX while we sample and/or clear */
  921. LOCK_HTC_TX(target);
  922. LOCK_HTC_RX(target);
  923. if (sample) {
  924. A_ASSERT(pStats);
  925. /* return the stats to the caller */
  926. qdf_mem_copy(pStats, &target->endpoint[Endpoint].endpoint_stats,
  927. sizeof(struct htc_endpoint_stats));
  928. }
  929. if (clearStats) {
  930. /* reset stats */
  931. qdf_mem_zero(&target->endpoint[Endpoint].endpoint_stats,
  932. sizeof(struct htc_endpoint_stats));
  933. }
  934. UNLOCK_HTC_RX(target);
  935. UNLOCK_HTC_TX(target);
  936. return true;
  937. #else
  938. return false;
  939. #endif
  940. }
  941. void *htc_get_targetdef(HTC_HANDLE htc_handle)
  942. {
  943. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  944. return hif_get_targetdef(target->hif_dev);
  945. }
  946. #ifdef IPA_OFFLOAD
  947. /**
  948. * htc_ipa_get_ce_resource() - get uc resource on lower layer
  949. * @htc_handle: htc context
  950. * @ce_sr_base_paddr: copyengine source ring base physical address
  951. * @ce_sr_ring_size: copyengine source ring size
  952. * @ce_reg_paddr: copyengine register physical address
  953. *
  954. * Return: None
  955. */
  956. void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle,
  957. qdf_shared_mem_t **ce_sr,
  958. uint32_t *ce_sr_ring_size,
  959. qdf_dma_addr_t *ce_reg_paddr)
  960. {
  961. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  962. if (target->hif_dev)
  963. hif_ipa_get_ce_resource(target->hif_dev,
  964. ce_sr, ce_sr_ring_size, ce_reg_paddr);
  965. }
  966. #endif /* IPA_OFFLOAD */
  967. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  968. void htc_dump_bundle_stats(HTC_HANDLE HTCHandle)
  969. {
  970. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  971. int total, i;
  972. total = 0;
  973. for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_RX; i++)
  974. total += target->rx_bundle_stats[i];
  975. if (total) {
  976. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("RX Bundle stats:\n"));
  977. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("Total RX packets: %d\n",
  978. total));
  979. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (
  980. "Number of bundle: Number of packets\n"));
  981. for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_RX; i++)
  982. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  983. ("%10d:%10d(%2d%s)\n", (i+1),
  984. target->rx_bundle_stats[i],
  985. ((target->rx_bundle_stats[i]*100)/
  986. total), "%"));
  987. }
  988. total = 0;
  989. for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_TX; i++)
  990. total += target->tx_bundle_stats[i];
  991. if (total) {
  992. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("TX Bundle stats:\n"));
  993. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("Total TX packets: %d\n",
  994. total));
  995. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  996. ("Number of bundle: Number of packets\n"));
  997. for (i = 0; i < HTC_MAX_MSG_PER_BUNDLE_TX; i++)
  998. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  999. ("%10d:%10d(%2d%s)\n", (i+1),
  1000. target->tx_bundle_stats[i],
  1001. ((target->tx_bundle_stats[i]*100)/
  1002. total), "%"));
  1003. }
  1004. }
  1005. void htc_clear_bundle_stats(HTC_HANDLE HTCHandle)
  1006. {
  1007. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1008. qdf_mem_zero(&target->rx_bundle_stats, sizeof(target->rx_bundle_stats));
  1009. qdf_mem_zero(&target->tx_bundle_stats, sizeof(target->tx_bundle_stats));
  1010. }
  1011. #endif
  1012. /**
  1013. * htc_can_suspend_link - API to query HIF for link status
  1014. * @htc_handle: HTC Handle
  1015. *
  1016. * API for upper layers to call HIF to query if the link can suspend
  1017. *
  1018. * Return: void
  1019. */
  1020. bool htc_can_suspend_link(HTC_HANDLE htc_handle)
  1021. {
  1022. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  1023. if (!target->hif_dev)
  1024. return false;
  1025. return hif_can_suspend_link(target->hif_dev);
  1026. }
  1027. #ifdef FEATURE_RUNTIME_PM
  1028. int htc_pm_runtime_get(HTC_HANDLE htc_handle)
  1029. {
  1030. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  1031. return hif_pm_runtime_get(target->hif_dev,
  1032. RTPM_ID_HTC, false);
  1033. }
  1034. int htc_pm_runtime_put(HTC_HANDLE htc_handle)
  1035. {
  1036. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  1037. hif_pm_runtime_update_stats(target->hif_dev, RTPM_ID_HTC,
  1038. HIF_PM_HTC_STATS_PUT_HTT_RESPONSE);
  1039. return hif_pm_runtime_put(target->hif_dev, RTPM_ID_HTC);
  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. }