htt.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. /*
  2. * Copyright (c) 2011, 2014-2019-2020 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. /**
  20. * @file htt.c
  21. * @brief Provide functions to create+init and destroy a HTT instance.
  22. * @details
  23. * This file contains functions for creating a HTT instance; initializing
  24. * the HTT instance, e.g. by allocating a pool of HTT tx descriptors and
  25. * connecting the HTT service with HTC; and deleting a HTT instance.
  26. */
  27. #include <qdf_mem.h> /* qdf_mem_malloc */
  28. #include <qdf_types.h> /* qdf_device_t, qdf_print */
  29. #include <htt.h> /* htt_tx_msdu_desc_t */
  30. #include <ol_cfg.h>
  31. #include <ol_txrx_htt_api.h> /* ol_tx_dowload_done_ll, etc. */
  32. #include <ol_htt_api.h>
  33. #include <htt_internal.h>
  34. #include <ol_htt_tx_api.h>
  35. #include <cds_api.h>
  36. #include "hif.h"
  37. #include <cdp_txrx_handle.h>
  38. #include <ol_txrx_peer_find.h>
  39. #define HTT_HTC_PKT_POOL_INIT_SIZE 100 /* enough for a large A-MPDU */
  40. QDF_STATUS(*htt_h2t_rx_ring_cfg_msg)(struct htt_pdev_t *pdev);
  41. QDF_STATUS(*htt_h2t_rx_ring_rfs_cfg_msg)(struct htt_pdev_t *pdev);
  42. #ifdef IPA_OFFLOAD
  43. static QDF_STATUS htt_ipa_config(htt_pdev_handle pdev, QDF_STATUS status)
  44. {
  45. if ((QDF_STATUS_SUCCESS == status) &&
  46. ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
  47. status = htt_h2t_ipa_uc_rsc_cfg_msg(pdev);
  48. return status;
  49. }
  50. #define HTT_IPA_CONFIG htt_ipa_config
  51. #else
  52. #define HTT_IPA_CONFIG(pdev, status) status /* no-op */
  53. #endif /* IPA_OFFLOAD */
  54. struct htt_htc_pkt *htt_htc_pkt_alloc(struct htt_pdev_t *pdev)
  55. {
  56. struct htt_htc_pkt_union *pkt = NULL;
  57. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  58. if (pdev->htt_htc_pkt_freelist) {
  59. pkt = pdev->htt_htc_pkt_freelist;
  60. pdev->htt_htc_pkt_freelist = pdev->htt_htc_pkt_freelist->u.next;
  61. }
  62. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  63. if (!pkt)
  64. pkt = qdf_mem_malloc(sizeof(*pkt));
  65. if (!pkt)
  66. return NULL;
  67. htc_packet_set_magic_cookie(&(pkt->u.pkt.htc_pkt), 0);
  68. return &pkt->u.pkt; /* not actually a dereference */
  69. }
  70. void htt_htc_pkt_free(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
  71. {
  72. struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
  73. if (!u_pkt) {
  74. qdf_print("HTC packet is NULL");
  75. return;
  76. }
  77. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  78. htc_packet_set_magic_cookie(&(u_pkt->u.pkt.htc_pkt), 0);
  79. u_pkt->u.next = pdev->htt_htc_pkt_freelist;
  80. pdev->htt_htc_pkt_freelist = u_pkt;
  81. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  82. }
  83. void htt_htc_pkt_pool_free(struct htt_pdev_t *pdev)
  84. {
  85. struct htt_htc_pkt_union *pkt, *next;
  86. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  87. pkt = pdev->htt_htc_pkt_freelist;
  88. pdev->htt_htc_pkt_freelist = NULL;
  89. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  90. while (pkt) {
  91. next = pkt->u.next;
  92. qdf_mem_free(pkt);
  93. pkt = next;
  94. }
  95. }
  96. #ifdef ATH_11AC_TXCOMPACT
  97. void
  98. htt_htc_misc_pkt_list_trim(struct htt_pdev_t *pdev, int level)
  99. {
  100. struct htt_htc_pkt_union *pkt, *next, *prev = NULL;
  101. int i = 0;
  102. qdf_nbuf_t netbuf;
  103. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  104. pkt = pdev->htt_htc_pkt_misclist;
  105. while (pkt) {
  106. next = pkt->u.next;
  107. /* trim the out grown list*/
  108. if (++i > level) {
  109. netbuf =
  110. (qdf_nbuf_t)(pkt->u.pkt.htc_pkt.pNetBufContext);
  111. qdf_nbuf_unmap(pdev->osdev, netbuf, QDF_DMA_TO_DEVICE);
  112. qdf_nbuf_free(netbuf);
  113. qdf_mem_free(pkt);
  114. pkt = NULL;
  115. if (prev)
  116. prev->u.next = NULL;
  117. }
  118. prev = pkt;
  119. pkt = next;
  120. }
  121. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  122. }
  123. void htt_htc_misc_pkt_list_add(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
  124. {
  125. struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
  126. int misclist_trim_level = htc_get_tx_queue_depth(pdev->htc_pdev,
  127. pkt->htc_pkt.Endpoint)
  128. + HTT_HTC_PKT_MISCLIST_SIZE;
  129. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  130. if (pdev->htt_htc_pkt_misclist) {
  131. u_pkt->u.next = pdev->htt_htc_pkt_misclist;
  132. pdev->htt_htc_pkt_misclist = u_pkt;
  133. } else {
  134. pdev->htt_htc_pkt_misclist = u_pkt;
  135. }
  136. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  137. /* only ce pipe size + tx_queue_depth could possibly be in use
  138. * free older packets in the msiclist
  139. */
  140. htt_htc_misc_pkt_list_trim(pdev, misclist_trim_level);
  141. }
  142. void htt_htc_misc_pkt_pool_free(struct htt_pdev_t *pdev)
  143. {
  144. struct htt_htc_pkt_union *pkt, *next;
  145. qdf_nbuf_t netbuf;
  146. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  147. pkt = pdev->htt_htc_pkt_misclist;
  148. pdev->htt_htc_pkt_misclist = NULL;
  149. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  150. while (pkt) {
  151. next = pkt->u.next;
  152. if (htc_packet_get_magic_cookie(&(pkt->u.pkt.htc_pkt)) !=
  153. HTC_PACKET_MAGIC_COOKIE) {
  154. QDF_ASSERT(0);
  155. pkt = next;
  156. continue;
  157. }
  158. netbuf = (qdf_nbuf_t) (pkt->u.pkt.htc_pkt.pNetBufContext);
  159. qdf_nbuf_unmap(pdev->osdev, netbuf, QDF_DMA_TO_DEVICE);
  160. qdf_nbuf_free(netbuf);
  161. qdf_mem_free(pkt);
  162. pkt = next;
  163. }
  164. }
  165. #endif
  166. /* AR6004 don't need HTT layer. */
  167. #ifdef AR6004_HW
  168. #define NO_HTT_NEEDED true
  169. #else
  170. #define NO_HTT_NEEDED false
  171. #endif
  172. #if defined(QCA_TX_HTT2_SUPPORT) && defined(CONFIG_HL_SUPPORT)
  173. /**
  174. * htt_htc_tx_htt2_service_start() - Start TX HTT2 service
  175. *
  176. * @pdev: pointer to htt device.
  177. * @connect_req: pointer to service connection request information
  178. * @connect_resp: pointer to service connection response information
  179. *
  180. *
  181. * Return: None
  182. */
  183. static void
  184. htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
  185. struct htc_service_connect_req *connect_req,
  186. struct htc_service_connect_resp *connect_resp)
  187. {
  188. QDF_STATUS status;
  189. qdf_mem_zero(connect_req, sizeof(struct htc_service_connect_req));
  190. qdf_mem_zero(connect_resp, sizeof(struct htc_service_connect_resp));
  191. /* The same as HTT service but no RX. */
  192. connect_req->EpCallbacks.pContext = pdev;
  193. connect_req->EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  194. connect_req->EpCallbacks.EpSendFull = htt_h2t_full;
  195. connect_req->MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  196. /* Should NOT support credit flow control. */
  197. connect_req->ConnectionFlags |=
  198. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  199. /* Enable HTC schedule mechanism for TX HTT2 service. */
  200. connect_req->ConnectionFlags |= HTC_CONNECT_FLAGS_ENABLE_HTC_SCHEDULE;
  201. connect_req->service_id = HTT_DATA2_MSG_SVC;
  202. status = htc_connect_service(pdev->htc_pdev, connect_req, connect_resp);
  203. if (status != QDF_STATUS_SUCCESS) {
  204. pdev->htc_tx_htt2_endpoint = ENDPOINT_UNUSED;
  205. pdev->htc_tx_htt2_max_size = 0;
  206. } else {
  207. pdev->htc_tx_htt2_endpoint = connect_resp->Endpoint;
  208. pdev->htc_tx_htt2_max_size = HTC_TX_HTT2_MAX_SIZE;
  209. }
  210. qdf_print("TX HTT %s, ep %d size %d\n",
  211. (status == QDF_STATUS_SUCCESS ? "ON" : "OFF"),
  212. pdev->htc_tx_htt2_endpoint,
  213. pdev->htc_tx_htt2_max_size);
  214. }
  215. #else
  216. static inline void
  217. htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
  218. struct htc_service_connect_req *connect_req,
  219. struct htc_service_connect_resp *connect_resp)
  220. {
  221. }
  222. #endif
  223. /**
  224. * htt_htc_credit_flow_disable() - disable flow control for
  225. * HTT data message service
  226. *
  227. * @pdev: pointer to htt device.
  228. * @connect_req: pointer to service connection request information
  229. *
  230. * HTC Credit mechanism is disabled based on
  231. * default_tx_comp_req as throughput will be lower
  232. * if we disable htc credit mechanism with default_tx_comp_req
  233. * set since txrx download packet will be limited by ota
  234. * completion.
  235. *
  236. * Return: None
  237. */
  238. static
  239. void htt_htc_credit_flow_disable(struct htt_pdev_t *pdev,
  240. struct htc_service_connect_req *connect_req)
  241. {
  242. if (pdev->osdev->bus_type == QDF_BUS_TYPE_SDIO) {
  243. /*
  244. * TODO:Conditional disabling will be removed once firmware
  245. * with reduced tx completion is pushed into release builds.
  246. */
  247. if (!pdev->cfg.default_tx_comp_req)
  248. connect_req->ConnectionFlags |=
  249. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  250. } else {
  251. connect_req->ConnectionFlags |=
  252. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  253. }
  254. }
  255. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  256. /**
  257. * htt_dump_bundle_stats() - dump wlan stats
  258. * @pdev: handle to the HTT instance
  259. *
  260. * Return: None
  261. */
  262. void htt_dump_bundle_stats(htt_pdev_handle pdev)
  263. {
  264. htc_dump_bundle_stats(pdev->htc_pdev);
  265. }
  266. /**
  267. * htt_clear_bundle_stats() - clear wlan stats
  268. * @pdev: handle to the HTT instance
  269. *
  270. * Return: None
  271. */
  272. void htt_clear_bundle_stats(htt_pdev_handle pdev)
  273. {
  274. htc_clear_bundle_stats(pdev->htc_pdev);
  275. }
  276. #endif
  277. #if defined(QCA_WIFI_3_0_ADRASTEA)
  278. /**
  279. * htt_htc_attach_all() - Connect to HTC service for HTT
  280. * @pdev: pdev ptr
  281. *
  282. * Return: 0 for success or error code.
  283. */
  284. #if defined(QCN7605_SUPPORT) && defined(IPA_OFFLOAD)
  285. /* In case of QCN7605 with IPA offload only 2 CE
  286. * are used for RFS
  287. */
  288. static int
  289. htt_htc_attach_all(struct htt_pdev_t *pdev)
  290. {
  291. if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
  292. goto flush_endpoint;
  293. if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
  294. goto flush_endpoint;
  295. return 0;
  296. flush_endpoint:
  297. htc_flush_endpoint(pdev->htc_pdev, ENDPOINT_0, HTC_TX_PACKET_TAG_ALL);
  298. return -EIO;
  299. }
  300. #else
  301. static int
  302. htt_htc_attach_all(struct htt_pdev_t *pdev)
  303. {
  304. if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
  305. goto flush_endpoint;
  306. if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
  307. goto flush_endpoint;
  308. if (htt_htc_attach(pdev, HTT_DATA3_MSG_SVC))
  309. goto flush_endpoint;
  310. return 0;
  311. flush_endpoint:
  312. htc_flush_endpoint(pdev->htc_pdev, ENDPOINT_0, HTC_TX_PACKET_TAG_ALL);
  313. return -EIO;
  314. }
  315. #endif
  316. #else
  317. /**
  318. * htt_htc_attach_all() - Connect to HTC service for HTT
  319. * @pdev: pdev ptr
  320. *
  321. * Return: 0 for success or error code.
  322. */
  323. static int
  324. htt_htc_attach_all(struct htt_pdev_t *pdev)
  325. {
  326. return htt_htc_attach(pdev, HTT_DATA_MSG_SVC);
  327. }
  328. #endif
  329. /**
  330. * htt_pdev_alloc() - allocate HTT pdev
  331. * @txrx_pdev: txrx pdev
  332. * @ctrl_pdev: cfg pdev
  333. * @htc_pdev: HTC pdev
  334. * @osdev: os device
  335. *
  336. * Return: HTT pdev handle
  337. */
  338. htt_pdev_handle
  339. htt_pdev_alloc(ol_txrx_pdev_handle txrx_pdev,
  340. struct cdp_cfg *ctrl_pdev,
  341. HTC_HANDLE htc_pdev, qdf_device_t osdev)
  342. {
  343. struct htt_pdev_t *pdev;
  344. struct hif_opaque_softc *osc = cds_get_context(QDF_MODULE_ID_HIF);
  345. if (!osc)
  346. goto fail1;
  347. pdev = qdf_mem_malloc(sizeof(*pdev));
  348. if (!pdev)
  349. goto fail1;
  350. pdev->osdev = osdev;
  351. pdev->ctrl_pdev = ctrl_pdev;
  352. pdev->txrx_pdev = txrx_pdev;
  353. pdev->htc_pdev = htc_pdev;
  354. pdev->htt_htc_pkt_freelist = NULL;
  355. #ifdef ATH_11AC_TXCOMPACT
  356. pdev->htt_htc_pkt_misclist = NULL;
  357. #endif
  358. /* for efficiency, store a local copy of the is_high_latency flag */
  359. pdev->cfg.is_high_latency = ol_cfg_is_high_latency(pdev->ctrl_pdev);
  360. /*
  361. * Credit reporting through HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND
  362. * enabled or not.
  363. */
  364. pdev->cfg.credit_update_enabled =
  365. ol_cfg_is_credit_update_enabled(pdev->ctrl_pdev);
  366. pdev->cfg.request_tx_comp = cds_is_ptp_rx_opt_enabled() ||
  367. cds_is_packet_log_enabled();
  368. pdev->cfg.default_tx_comp_req =
  369. !ol_cfg_tx_free_at_download(pdev->ctrl_pdev);
  370. pdev->cfg.is_full_reorder_offload =
  371. ol_cfg_is_full_reorder_offload(pdev->ctrl_pdev);
  372. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO_LOW,
  373. "full_reorder_offloaded %d",
  374. (int)pdev->cfg.is_full_reorder_offload);
  375. pdev->cfg.ce_classify_enabled =
  376. ol_cfg_is_ce_classify_enabled(ctrl_pdev);
  377. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO_LOW,
  378. "ce_classify %d",
  379. pdev->cfg.ce_classify_enabled);
  380. if (pdev->cfg.is_high_latency) {
  381. qdf_atomic_init(&pdev->htt_tx_credit.target_delta);
  382. qdf_atomic_init(&pdev->htt_tx_credit.bus_delta);
  383. qdf_atomic_add(HTT_MAX_BUS_CREDIT,
  384. &pdev->htt_tx_credit.bus_delta);
  385. }
  386. pdev->targetdef = htc_get_targetdef(htc_pdev);
  387. #if defined(HELIUMPLUS)
  388. HTT_SET_WIFI_IP(pdev, 2, 0);
  389. #endif /* defined(HELIUMPLUS) */
  390. if (NO_HTT_NEEDED)
  391. goto success;
  392. /*
  393. * Connect to HTC service.
  394. * This has to be done before calling htt_rx_attach,
  395. * since htt_rx_attach involves sending a rx ring configure
  396. * message to the target.
  397. */
  398. HTT_TX_MUTEX_INIT(&pdev->htt_tx_mutex);
  399. HTT_TX_NBUF_QUEUE_MUTEX_INIT(pdev);
  400. HTT_TX_MUTEX_INIT(&pdev->credit_mutex);
  401. if (htt_htc_attach_all(pdev))
  402. goto htt_htc_attach_fail;
  403. if (hif_ce_fastpath_cb_register(osc, htt_t2h_msg_handler_fast, pdev))
  404. qdf_print("failed to register fastpath callback\n");
  405. success:
  406. return pdev;
  407. htt_htc_attach_fail:
  408. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  409. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  410. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  411. qdf_mem_free(pdev);
  412. fail1:
  413. return NULL;
  414. }
  415. /**
  416. * htt_attach() - Allocate and setup HTT TX/RX descriptors
  417. * @pdev: pdev ptr
  418. * @desc_pool_size: size of tx descriptors
  419. *
  420. * Return: 0 for success or error code.
  421. */
  422. int
  423. htt_attach(struct htt_pdev_t *pdev, int desc_pool_size)
  424. {
  425. int i;
  426. int ret = 0;
  427. pdev->is_ipa_uc_enabled = false;
  428. if (ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
  429. pdev->is_ipa_uc_enabled = true;
  430. pdev->new_htt_format_enabled = false;
  431. if (ol_cfg_is_htt_new_format_enabled(pdev->ctrl_pdev))
  432. pdev->new_htt_format_enabled = true;
  433. htc_enable_hdr_length_check(pdev->htc_pdev,
  434. pdev->new_htt_format_enabled);
  435. ret = htt_tx_attach(pdev, desc_pool_size);
  436. if (ret)
  437. goto fail1;
  438. ret = htt_rx_attach(pdev);
  439. if (ret)
  440. goto fail2;
  441. /* pre-allocate some HTC_PACKET objects */
  442. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  443. struct htt_htc_pkt_union *pkt;
  444. pkt = qdf_mem_malloc(sizeof(*pkt));
  445. if (!pkt)
  446. break;
  447. htt_htc_pkt_free(pdev, &pkt->u.pkt);
  448. }
  449. if (pdev->cfg.is_high_latency) {
  450. /*
  451. * HL - download the whole frame.
  452. * Specify a download length greater than the max MSDU size,
  453. * so the downloads will be limited by the actual frame sizes.
  454. */
  455. pdev->download_len = 5000;
  456. if (ol_cfg_tx_free_at_download(pdev->ctrl_pdev) &&
  457. !pdev->cfg.request_tx_comp)
  458. pdev->tx_send_complete_part2 =
  459. ol_tx_download_done_hl_free;
  460. else
  461. pdev->tx_send_complete_part2 =
  462. ol_tx_download_done_hl_retain;
  463. /*
  464. * CHECK THIS LATER: does the HL HTT version of
  465. * htt_rx_mpdu_desc_list_next
  466. * (which is not currently implemented) present the
  467. * adf_nbuf_data(rx_ind_msg)
  468. * as the abstract rx descriptor?
  469. * If not, the rx_fw_desc_offset initialization
  470. * here will have to be adjusted accordingly.
  471. * NOTE: for HL, because fw rx desc is in ind msg,
  472. * not in rx desc, so the
  473. * offset should be negative value
  474. */
  475. pdev->rx_fw_desc_offset =
  476. HTT_ENDIAN_BYTE_IDX_SWAP(
  477. HTT_RX_IND_FW_RX_DESC_BYTE_OFFSET
  478. - HTT_RX_IND_HL_BYTES);
  479. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_hl;
  480. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_hl;
  481. /* initialize the txrx credit count */
  482. ol_tx_target_credit_update(
  483. pdev->txrx_pdev, ol_cfg_target_tx_credit(
  484. pdev->ctrl_pdev));
  485. DPTRACE(qdf_dp_trace_credit_record(QDF_HTT_ATTACH,
  486. QDF_CREDIT_INC,
  487. ol_cfg_target_tx_credit(pdev->ctrl_pdev),
  488. qdf_atomic_read(&pdev->txrx_pdev->target_tx_credit),
  489. qdf_atomic_read(&pdev->txrx_pdev->txq_grps[0].credit),
  490. qdf_atomic_read(&pdev->txrx_pdev->txq_grps[1].credit)));
  491. } else {
  492. enum wlan_frm_fmt frm_type;
  493. /*
  494. * LL - download just the initial portion of the frame.
  495. * Download enough to cover the encapsulation headers checked
  496. * by the target's tx classification descriptor engine.
  497. *
  498. * For LL, the FW rx desc directly referenced at its location
  499. * inside the rx indication message.
  500. */
  501. /* account for the 802.3 or 802.11 header */
  502. frm_type = ol_cfg_frame_type(pdev->ctrl_pdev);
  503. if (frm_type == wlan_frm_fmt_native_wifi) {
  504. pdev->download_len = HTT_TX_HDR_SIZE_NATIVE_WIFI;
  505. } else if (frm_type == wlan_frm_fmt_802_3) {
  506. pdev->download_len = HTT_TX_HDR_SIZE_ETHERNET;
  507. } else {
  508. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  509. "Unexpected frame type spec: %d", frm_type);
  510. HTT_ASSERT0(0);
  511. }
  512. /*
  513. * Account for the optional L2 / ethernet header fields:
  514. * 802.1Q, LLC/SNAP
  515. */
  516. pdev->download_len +=
  517. HTT_TX_HDR_SIZE_802_1Q + HTT_TX_HDR_SIZE_LLC_SNAP;
  518. /*
  519. * Account for the portion of the L3 (IP) payload that the
  520. * target needs for its tx classification.
  521. */
  522. pdev->download_len += ol_cfg_tx_download_size(pdev->ctrl_pdev);
  523. /*
  524. * Account for the HTT tx descriptor, including the
  525. * HTC header + alignment padding.
  526. */
  527. pdev->download_len += sizeof(struct htt_host_tx_desc_t);
  528. /*
  529. * The TXCOMPACT htt_tx_sched function uses pdev->download_len
  530. * to apply for all requeued tx frames. Thus,
  531. * pdev->download_len has to be the largest download length of
  532. * any tx frame that will be downloaded.
  533. * This maximum download length is for management tx frames,
  534. * which have an 802.11 header.
  535. */
  536. #ifdef ATH_11AC_TXCOMPACT
  537. pdev->download_len = sizeof(struct htt_host_tx_desc_t)
  538. + HTT_TX_HDR_SIZE_OUTER_HDR_MAX /* worst case */
  539. + HTT_TX_HDR_SIZE_802_1Q
  540. + HTT_TX_HDR_SIZE_LLC_SNAP
  541. + ol_cfg_tx_download_size(pdev->ctrl_pdev);
  542. #endif
  543. pdev->tx_send_complete_part2 = ol_tx_download_done_ll;
  544. /*
  545. * For LL, the FW rx desc is alongside the HW rx desc fields in
  546. * the htt_host_rx_desc_base struct/.
  547. */
  548. pdev->rx_fw_desc_offset = RX_STD_DESC_FW_MSDU_OFFSET;
  549. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_ll;
  550. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_ll;
  551. }
  552. return 0;
  553. fail2:
  554. htt_tx_detach(pdev);
  555. fail1:
  556. return ret;
  557. }
  558. QDF_STATUS htt_attach_target(htt_pdev_handle pdev)
  559. {
  560. QDF_STATUS status;
  561. status = htt_h2t_ver_req_msg(pdev);
  562. if (status != QDF_STATUS_SUCCESS) {
  563. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  564. "%s:%d: could not send h2t_ver_req msg",
  565. __func__, __LINE__);
  566. return status;
  567. }
  568. #if defined(HELIUMPLUS)
  569. /*
  570. * Send the frag_desc info to target.
  571. */
  572. status = htt_h2t_frag_desc_bank_cfg_msg(pdev);
  573. if (status != QDF_STATUS_SUCCESS) {
  574. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  575. "%s:%d: could not send h2t_frag_desc_bank_cfg msg",
  576. __func__, __LINE__);
  577. return status;
  578. }
  579. #endif /* defined(HELIUMPLUS) */
  580. /*
  581. * If applicable, send the rx ring config message to the target.
  582. * The host could wait for the HTT version number confirmation message
  583. * from the target before sending any further HTT messages, but it's
  584. * reasonable to assume that the host and target HTT version numbers
  585. * match, and proceed immediately with the remaining configuration
  586. * handshaking.
  587. */
  588. status = htt_h2t_rx_ring_rfs_cfg_msg(pdev);
  589. if (status != QDF_STATUS_SUCCESS) {
  590. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  591. "%s:%d: could not send h2t_rx_ring_rfs_cfg msg",
  592. __func__, __LINE__);
  593. return status;
  594. }
  595. status = htt_h2t_rx_ring_cfg_msg(pdev);
  596. if (status != QDF_STATUS_SUCCESS) {
  597. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  598. "%s:%d: could not send h2t_rx_ring_cfg msg",
  599. __func__, __LINE__);
  600. return status;
  601. }
  602. status = HTT_IPA_CONFIG(pdev, status);
  603. if (status != QDF_STATUS_SUCCESS) {
  604. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  605. "%s:%d: could not send h2t_ipa_uc_rsc_cfg msg",
  606. __func__, __LINE__);
  607. return status;
  608. }
  609. return status;
  610. }
  611. void htt_detach(htt_pdev_handle pdev)
  612. {
  613. htt_rx_detach(pdev);
  614. htt_tx_detach(pdev);
  615. htt_htc_pkt_pool_free(pdev);
  616. #ifdef ATH_11AC_TXCOMPACT
  617. htt_htc_misc_pkt_pool_free(pdev);
  618. #endif
  619. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  620. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  621. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  622. }
  623. /**
  624. * htt_pdev_free() - Free HTT pdev
  625. * @pdev: htt pdev
  626. *
  627. * Return: none
  628. */
  629. void htt_pdev_free(htt_pdev_handle pdev)
  630. {
  631. qdf_mem_free(pdev);
  632. }
  633. void htt_detach_target(htt_pdev_handle pdev)
  634. {
  635. }
  636. static inline
  637. int htt_update_endpoint(struct htt_pdev_t *pdev,
  638. uint16_t service_id, HTC_ENDPOINT_ID ep)
  639. {
  640. struct hif_opaque_softc *hif_ctx;
  641. uint8_t ul = 0xff, dl = 0xff;
  642. int ul_polled, dl_polled;
  643. int tx_service = 0;
  644. int rc = 0;
  645. hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
  646. if (qdf_unlikely(!hif_ctx)) {
  647. QDF_ASSERT(hif_ctx);
  648. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  649. "%s:%d: assuming non-tx service.",
  650. __func__, __LINE__);
  651. } else {
  652. ul = dl = 0xff;
  653. if (QDF_STATUS_SUCCESS !=
  654. hif_map_service_to_pipe(hif_ctx, service_id,
  655. &ul, &dl,
  656. &ul_polled, &dl_polled))
  657. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  658. "%s:%d: assuming non-tx srv.",
  659. __func__, __LINE__);
  660. else
  661. tx_service = (ul != 0xff);
  662. }
  663. if (tx_service) {
  664. /* currently we have only one OUT htt tx service */
  665. QDF_BUG(service_id == HTT_DATA_MSG_SVC);
  666. pdev->htc_tx_endpoint = ep;
  667. hif_save_htc_htt_config_endpoint(hif_ctx, ep);
  668. rc = 1;
  669. }
  670. return rc;
  671. }
  672. int htt_htc_attach(struct htt_pdev_t *pdev, uint16_t service_id)
  673. {
  674. struct htc_service_connect_req connect;
  675. struct htc_service_connect_resp response;
  676. QDF_STATUS status;
  677. qdf_mem_zero(&connect, sizeof(connect));
  678. qdf_mem_zero(&response, sizeof(response));
  679. connect.pMetaData = NULL;
  680. connect.MetaDataLength = 0;
  681. connect.EpCallbacks.pContext = pdev;
  682. connect.EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  683. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  684. connect.EpCallbacks.EpRecv = htt_t2h_msg_handler;
  685. connect.EpCallbacks.ep_resume_tx_queue = htt_tx_resume_handler;
  686. connect.EpCallbacks.ep_padding_credit_update =
  687. htt_tx_padding_credit_update_handler;
  688. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  689. connect.EpCallbacks.EpRecvRefill = NULL;
  690. connect.EpCallbacks.RecvRefillWaterMark = 1;
  691. /* N/A, fill is done by HIF */
  692. connect.EpCallbacks.EpSendFull = htt_h2t_full;
  693. /*
  694. * Specify how deep to let a queue get before htc_send_pkt will
  695. * call the EpSendFull function due to excessive send queue depth.
  696. */
  697. connect.MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  698. /* disable flow control for HTT data message service */
  699. htt_htc_credit_flow_disable(pdev, &connect);
  700. /* connect to control service */
  701. connect.service_id = service_id;
  702. status = htc_connect_service(pdev->htc_pdev, &connect, &response);
  703. if (status != QDF_STATUS_SUCCESS) {
  704. if (cds_is_fw_down())
  705. return -EIO;
  706. if (status == QDF_STATUS_E_NOMEM ||
  707. cds_is_self_recovery_enabled())
  708. return qdf_status_to_os_return(status);
  709. QDF_BUG(0);
  710. }
  711. htt_update_endpoint(pdev, service_id, response.Endpoint);
  712. /* Start TX HTT2 service if the target support it. */
  713. htt_htc_tx_htt2_service_start(pdev, &connect, &response);
  714. return 0; /* success */
  715. }
  716. void htt_log_rx_ring_info(htt_pdev_handle pdev)
  717. {
  718. if (!pdev) {
  719. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  720. "%s: htt pdev is NULL", __func__);
  721. return;
  722. }
  723. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG,
  724. "%s: Data Stall Detected with reason 4 (=FW_RX_REFILL_FAILED)."
  725. "src htt rx ring: space for %d elements, filled with %d buffers, buffers in the ring %d, refill debt %d",
  726. __func__, pdev->rx_ring.size, pdev->rx_ring.fill_level,
  727. qdf_atomic_read(&pdev->rx_ring.fill_cnt),
  728. qdf_atomic_read(&pdev->rx_ring.refill_debt));
  729. }
  730. void htt_rx_refill_failure(htt_pdev_handle pdev)
  731. {
  732. QDF_BUG(qdf_atomic_read(&pdev->rx_ring.refill_debt));
  733. }
  734. #if HTT_DEBUG_LEVEL > 5
  735. void htt_display(htt_pdev_handle pdev, int indent)
  736. {
  737. qdf_print("%*s%s:\n", indent, " ", "HTT");
  738. qdf_print("%*stx desc pool: %d elems of %d bytes, %d allocated\n",
  739. indent + 4, " ",
  740. pdev->tx_descs.pool_elems,
  741. pdev->tx_descs.size, pdev->tx_descs.alloc_cnt);
  742. qdf_print("%*srx ring: space for %d elems, filled with %d buffers\n",
  743. indent + 4, " ",
  744. pdev->rx_ring.size, pdev->rx_ring.fill_level);
  745. qdf_print("%*sat %pK (%llx paddr)\n", indent + 8, " ",
  746. pdev->rx_ring.buf.paddrs_ring,
  747. (unsigned long long)pdev->rx_ring.base_paddr);
  748. qdf_print("%*snetbuf ring @ %pK\n", indent + 8, " ",
  749. pdev->rx_ring.buf.netbufs_ring);
  750. qdf_print("%*sFW_IDX shadow register: vaddr = %pK, paddr = %llx\n",
  751. indent + 8, " ",
  752. pdev->rx_ring.alloc_idx.vaddr,
  753. (unsigned long long)pdev->rx_ring.alloc_idx.paddr);
  754. qdf_print("%*sSW enqueue idx= %d, SW dequeue idx: desc= %d, buf= %d\n",
  755. indent + 8, " ", *pdev->rx_ring.alloc_idx.vaddr,
  756. pdev->rx_ring.sw_rd_idx.msdu_desc,
  757. pdev->rx_ring.sw_rd_idx.msdu_payld);
  758. }
  759. #endif
  760. #ifdef IPA_OFFLOAD
  761. /**
  762. * htt_ipa_uc_attach() - Allocate UC data path resources
  763. * @pdev: handle to the HTT instance
  764. *
  765. * Return: 0 success
  766. * none 0 fail
  767. */
  768. int htt_ipa_uc_attach(struct htt_pdev_t *pdev)
  769. {
  770. int error;
  771. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
  772. __func__);
  773. /* TX resource attach */
  774. error = htt_tx_ipa_uc_attach(
  775. pdev,
  776. ol_cfg_ipa_uc_tx_buf_size(pdev->ctrl_pdev),
  777. ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev),
  778. ol_cfg_ipa_uc_tx_partition_base(pdev->ctrl_pdev));
  779. if (error) {
  780. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  781. "HTT IPA UC TX attach fail code %d", error);
  782. HTT_ASSERT0(0);
  783. return error;
  784. }
  785. /* RX resource attach */
  786. error = htt_rx_ipa_uc_attach(
  787. pdev, qdf_get_pwr2(pdev->rx_ring.fill_level));
  788. if (error) {
  789. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  790. "HTT IPA UC RX attach fail code %d", error);
  791. htt_tx_ipa_uc_detach(pdev);
  792. HTT_ASSERT0(0);
  793. return error;
  794. }
  795. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
  796. __func__);
  797. return 0; /* success */
  798. }
  799. /**
  800. * htt_ipa_uc_attach() - Remove UC data path resources
  801. * @pdev: handle to the HTT instance
  802. *
  803. * Return: None
  804. */
  805. void htt_ipa_uc_detach(struct htt_pdev_t *pdev)
  806. {
  807. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
  808. __func__);
  809. /* TX IPA micro controller detach */
  810. htt_tx_ipa_uc_detach(pdev);
  811. /* RX IPA micro controller detach */
  812. htt_rx_ipa_uc_detach(pdev);
  813. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
  814. __func__);
  815. }
  816. int
  817. htt_ipa_uc_get_resource(htt_pdev_handle pdev,
  818. qdf_shared_mem_t **ce_sr,
  819. qdf_shared_mem_t **tx_comp_ring,
  820. qdf_shared_mem_t **rx_rdy_ring,
  821. qdf_shared_mem_t **rx2_rdy_ring,
  822. qdf_shared_mem_t **rx_proc_done_idx,
  823. qdf_shared_mem_t **rx2_proc_done_idx,
  824. uint32_t *ce_sr_ring_size,
  825. qdf_dma_addr_t *ce_reg_paddr,
  826. uint32_t *tx_num_alloc_buffer)
  827. {
  828. /* Release allocated resource to client */
  829. *tx_comp_ring = pdev->ipa_uc_tx_rsc.tx_comp_ring;
  830. *rx_rdy_ring = pdev->ipa_uc_rx_rsc.rx_ind_ring;
  831. *rx2_rdy_ring = pdev->ipa_uc_rx_rsc.rx2_ind_ring;
  832. *rx_proc_done_idx = pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx;
  833. *rx2_proc_done_idx = pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx;
  834. *tx_num_alloc_buffer = (uint32_t)pdev->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
  835. /* Get copy engine, bus resource */
  836. htc_ipa_get_ce_resource(pdev->htc_pdev, ce_sr,
  837. ce_sr_ring_size, ce_reg_paddr);
  838. return 0;
  839. }
  840. /**
  841. * htt_ipa_uc_set_doorbell_paddr() - Propagate IPA doorbell address
  842. * @pdev: handle to the HTT instance
  843. * @ipa_uc_tx_doorbell_paddr: TX doorbell base physical address
  844. * @ipa_uc_rx_doorbell_paddr: RX doorbell base physical address
  845. *
  846. * Return: 0 success
  847. */
  848. int
  849. htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,
  850. qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,
  851. qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)
  852. {
  853. pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr = ipa_uc_tx_doorbell_paddr;
  854. pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr = ipa_uc_rx_doorbell_paddr;
  855. return 0;
  856. }
  857. #endif /* IPA_OFFLOAD */
  858. /**
  859. * htt_mark_first_wakeup_packet() - set flag to indicate that
  860. * fw is compatible for marking first packet after wow wakeup
  861. * @pdev: pointer to htt pdev
  862. * @value: 1 for enabled/ 0 for disabled
  863. *
  864. * Return: None
  865. */
  866. void htt_mark_first_wakeup_packet(htt_pdev_handle pdev,
  867. uint8_t value)
  868. {
  869. if (!pdev) {
  870. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  871. "%s: htt pdev is NULL", __func__);
  872. return;
  873. }
  874. pdev->cfg.is_first_wakeup_packet = value;
  875. }