htt.c 26 KB

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