htc.c 34 KB

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