htt.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. /*
  2. * Copyright (c) 2011, 2014-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * @file htt.c
  20. * @brief Provide functions to create+init and destroy a HTT instance.
  21. * @details
  22. * This file contains functions for creating a HTT instance; initializing
  23. * the HTT instance, e.g. by allocating a pool of HTT tx descriptors and
  24. * connecting the HTT service with HTC; and deleting a HTT instance.
  25. */
  26. #include <qdf_mem.h> /* qdf_mem_malloc */
  27. #include <qdf_types.h> /* qdf_device_t, qdf_print */
  28. #include <htt.h> /* htt_tx_msdu_desc_t */
  29. #include <ol_cfg.h>
  30. #include <ol_txrx_htt_api.h> /* ol_tx_dowload_done_ll, etc. */
  31. #include <ol_htt_api.h>
  32. #include <htt_internal.h>
  33. #include <ol_htt_tx_api.h>
  34. #include <cds_api.h>
  35. #include "hif.h"
  36. #include <cdp_txrx_handle.h>
  37. #define HTT_HTC_PKT_POOL_INIT_SIZE 100 /* enough for a large A-MPDU */
  38. QDF_STATUS(*htt_h2t_rx_ring_cfg_msg)(struct htt_pdev_t *pdev);
  39. QDF_STATUS(*htt_h2t_rx_ring_rfs_cfg_msg)(struct htt_pdev_t *pdev);
  40. #ifdef IPA_OFFLOAD
  41. static QDF_STATUS htt_ipa_config(htt_pdev_handle pdev, QDF_STATUS status)
  42. {
  43. if ((QDF_STATUS_SUCCESS == status) &&
  44. ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
  45. status = htt_h2t_ipa_uc_rsc_cfg_msg(pdev);
  46. return status;
  47. }
  48. #define HTT_IPA_CONFIG htt_ipa_config
  49. #else
  50. #define HTT_IPA_CONFIG(pdev, status) status /* no-op */
  51. #endif /* IPA_OFFLOAD */
  52. struct htt_htc_pkt *htt_htc_pkt_alloc(struct htt_pdev_t *pdev)
  53. {
  54. struct htt_htc_pkt_union *pkt = NULL;
  55. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  56. if (pdev->htt_htc_pkt_freelist) {
  57. pkt = pdev->htt_htc_pkt_freelist;
  58. pdev->htt_htc_pkt_freelist = pdev->htt_htc_pkt_freelist->u.next;
  59. }
  60. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  61. if (pkt == NULL)
  62. pkt = qdf_mem_malloc(sizeof(*pkt));
  63. if (!pkt) {
  64. qdf_print("%s: HTC packet allocation failed\n", __func__);
  65. return NULL;
  66. }
  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("%s: HTC packet is NULL\n", __func__);
  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_set(connect_req, 0, sizeof(struct htc_service_connect_req));
  190. qdf_mem_set(connect_resp, 0, 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. static int
  285. htt_htc_attach_all(struct htt_pdev_t *pdev)
  286. {
  287. if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
  288. goto flush_endpoint;
  289. if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
  290. goto flush_endpoint;
  291. if (htt_htc_attach(pdev, HTT_DATA3_MSG_SVC))
  292. goto flush_endpoint;
  293. return 0;
  294. flush_endpoint:
  295. htc_flush_endpoint(pdev->htc_pdev, ENDPOINT_0, HTC_TX_PACKET_TAG_ALL);
  296. return -EIO;
  297. }
  298. #else
  299. /**
  300. * htt_htc_attach_all() - Connect to HTC service for HTT
  301. * @pdev: pdev ptr
  302. *
  303. * Return: 0 for success or error code.
  304. */
  305. static int
  306. htt_htc_attach_all(struct htt_pdev_t *pdev)
  307. {
  308. return htt_htc_attach(pdev, HTT_DATA_MSG_SVC);
  309. }
  310. #endif
  311. /**
  312. * htt_pdev_alloc() - allocate HTT pdev
  313. * @txrx_pdev: txrx pdev
  314. * @ctrl_pdev: cfg pdev
  315. * @htc_pdev: HTC pdev
  316. * @osdev: os device
  317. *
  318. * Return: HTT pdev handle
  319. */
  320. htt_pdev_handle
  321. htt_pdev_alloc(ol_txrx_pdev_handle txrx_pdev,
  322. struct cdp_cfg *ctrl_pdev,
  323. HTC_HANDLE htc_pdev, qdf_device_t osdev)
  324. {
  325. struct htt_pdev_t *pdev;
  326. struct hif_opaque_softc *osc = cds_get_context(QDF_MODULE_ID_HIF);
  327. if (!osc)
  328. goto fail1;
  329. pdev = qdf_mem_malloc(sizeof(*pdev));
  330. if (!pdev)
  331. goto fail1;
  332. pdev->osdev = osdev;
  333. pdev->ctrl_pdev = ctrl_pdev;
  334. pdev->txrx_pdev = txrx_pdev;
  335. pdev->htc_pdev = htc_pdev;
  336. pdev->htt_htc_pkt_freelist = NULL;
  337. #ifdef ATH_11AC_TXCOMPACT
  338. pdev->htt_htc_pkt_misclist = NULL;
  339. #endif
  340. /* for efficiency, store a local copy of the is_high_latency flag */
  341. pdev->cfg.is_high_latency = ol_cfg_is_high_latency(pdev->ctrl_pdev);
  342. pdev->cfg.default_tx_comp_req =
  343. !ol_cfg_tx_free_at_download(pdev->ctrl_pdev);
  344. pdev->cfg.is_full_reorder_offload =
  345. ol_cfg_is_full_reorder_offload(pdev->ctrl_pdev);
  346. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  347. "full_reorder_offloaded %d",
  348. (int)pdev->cfg.is_full_reorder_offload);
  349. pdev->cfg.ce_classify_enabled =
  350. ol_cfg_is_ce_classify_enabled(ctrl_pdev);
  351. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  352. "ce_classify %d",
  353. pdev->cfg.ce_classify_enabled);
  354. if (pdev->cfg.is_high_latency) {
  355. qdf_atomic_init(&pdev->htt_tx_credit.target_delta);
  356. qdf_atomic_init(&pdev->htt_tx_credit.bus_delta);
  357. qdf_atomic_add(HTT_MAX_BUS_CREDIT,
  358. &pdev->htt_tx_credit.bus_delta);
  359. }
  360. pdev->targetdef = htc_get_targetdef(htc_pdev);
  361. #if defined(HELIUMPLUS)
  362. HTT_SET_WIFI_IP(pdev, 2, 0);
  363. #endif /* defined(HELIUMPLUS) */
  364. if (NO_HTT_NEEDED)
  365. goto success;
  366. /*
  367. * Connect to HTC service.
  368. * This has to be done before calling htt_rx_attach,
  369. * since htt_rx_attach involves sending a rx ring configure
  370. * message to the target.
  371. */
  372. HTT_TX_MUTEX_INIT(&pdev->htt_tx_mutex);
  373. HTT_TX_NBUF_QUEUE_MUTEX_INIT(pdev);
  374. HTT_TX_MUTEX_INIT(&pdev->credit_mutex);
  375. if (htt_htc_attach_all(pdev))
  376. goto htt_htc_attach_fail;
  377. if (hif_ce_fastpath_cb_register(osc, htt_t2h_msg_handler_fast, pdev))
  378. qdf_print("failed to register fastpath callback\n");
  379. success:
  380. return pdev;
  381. htt_htc_attach_fail:
  382. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  383. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  384. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  385. qdf_mem_free(pdev);
  386. fail1:
  387. return NULL;
  388. }
  389. /**
  390. * htt_attach() - Allocate and setup HTT TX/RX descriptors
  391. * @pdev: pdev ptr
  392. * @desc_pool_size: size of tx descriptors
  393. *
  394. * Return: 0 for success or error code.
  395. */
  396. int
  397. htt_attach(struct htt_pdev_t *pdev, int desc_pool_size)
  398. {
  399. int i;
  400. int ret = 0;
  401. pdev->is_ipa_uc_enabled = false;
  402. if (ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
  403. pdev->is_ipa_uc_enabled = true;
  404. ret = htt_tx_attach(pdev, desc_pool_size);
  405. if (ret)
  406. goto fail1;
  407. ret = htt_rx_attach(pdev);
  408. if (ret)
  409. goto fail2;
  410. /* pre-allocate some HTC_PACKET objects */
  411. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  412. struct htt_htc_pkt_union *pkt;
  413. pkt = qdf_mem_malloc(sizeof(*pkt));
  414. if (!pkt)
  415. break;
  416. htt_htc_pkt_free(pdev, &pkt->u.pkt);
  417. }
  418. if (pdev->cfg.is_high_latency) {
  419. /*
  420. * HL - download the whole frame.
  421. * Specify a download length greater than the max MSDU size,
  422. * so the downloads will be limited by the actual frame sizes.
  423. */
  424. pdev->download_len = 5000;
  425. if (ol_cfg_tx_free_at_download(pdev->ctrl_pdev))
  426. pdev->tx_send_complete_part2 =
  427. ol_tx_download_done_hl_free;
  428. else
  429. pdev->tx_send_complete_part2 =
  430. ol_tx_download_done_hl_retain;
  431. /*
  432. * CHECK THIS LATER: does the HL HTT version of
  433. * htt_rx_mpdu_desc_list_next
  434. * (which is not currently implemented) present the
  435. * adf_nbuf_data(rx_ind_msg)
  436. * as the abstract rx descriptor?
  437. * If not, the rx_fw_desc_offset initialization
  438. * here will have to be adjusted accordingly.
  439. * NOTE: for HL, because fw rx desc is in ind msg,
  440. * not in rx desc, so the
  441. * offset should be negtive value
  442. */
  443. pdev->rx_fw_desc_offset =
  444. HTT_ENDIAN_BYTE_IDX_SWAP(
  445. HTT_RX_IND_FW_RX_DESC_BYTE_OFFSET
  446. - HTT_RX_IND_HL_BYTES);
  447. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_hl;
  448. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_hl;
  449. /* initialize the txrx credit count */
  450. ol_tx_target_credit_update(
  451. pdev->txrx_pdev, ol_cfg_target_tx_credit(
  452. pdev->ctrl_pdev));
  453. } else {
  454. enum wlan_frm_fmt frm_type;
  455. /*
  456. * LL - download just the initial portion of the frame.
  457. * Download enough to cover the encapsulation headers checked
  458. * by the target's tx classification descriptor engine.
  459. *
  460. * For LL, the FW rx desc directly referenced at its location
  461. * inside the rx indication message.
  462. */
  463. /* account for the 802.3 or 802.11 header */
  464. frm_type = ol_cfg_frame_type(pdev->ctrl_pdev);
  465. if (frm_type == wlan_frm_fmt_native_wifi) {
  466. pdev->download_len = HTT_TX_HDR_SIZE_NATIVE_WIFI;
  467. } else if (frm_type == wlan_frm_fmt_802_3) {
  468. pdev->download_len = HTT_TX_HDR_SIZE_ETHERNET;
  469. } else {
  470. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  471. "Unexpected frame type spec: %d", frm_type);
  472. HTT_ASSERT0(0);
  473. }
  474. /*
  475. * Account for the optional L2 / ethernet header fields:
  476. * 802.1Q, LLC/SNAP
  477. */
  478. pdev->download_len +=
  479. HTT_TX_HDR_SIZE_802_1Q + HTT_TX_HDR_SIZE_LLC_SNAP;
  480. /*
  481. * Account for the portion of the L3 (IP) payload that the
  482. * target needs for its tx classification.
  483. */
  484. pdev->download_len += ol_cfg_tx_download_size(pdev->ctrl_pdev);
  485. /*
  486. * Account for the HTT tx descriptor, including the
  487. * HTC header + alignment padding.
  488. */
  489. pdev->download_len += sizeof(struct htt_host_tx_desc_t);
  490. /*
  491. * The TXCOMPACT htt_tx_sched function uses pdev->download_len
  492. * to apply for all requeued tx frames. Thus,
  493. * pdev->download_len has to be the largest download length of
  494. * any tx frame that will be downloaded.
  495. * This maximum download length is for management tx frames,
  496. * which have an 802.11 header.
  497. */
  498. #ifdef ATH_11AC_TXCOMPACT
  499. pdev->download_len = sizeof(struct htt_host_tx_desc_t)
  500. + HTT_TX_HDR_SIZE_OUTER_HDR_MAX /* worst case */
  501. + HTT_TX_HDR_SIZE_802_1Q
  502. + HTT_TX_HDR_SIZE_LLC_SNAP
  503. + ol_cfg_tx_download_size(pdev->ctrl_pdev);
  504. #endif
  505. pdev->tx_send_complete_part2 = ol_tx_download_done_ll;
  506. /*
  507. * For LL, the FW rx desc is alongside the HW rx desc fields in
  508. * the htt_host_rx_desc_base struct/.
  509. */
  510. pdev->rx_fw_desc_offset = RX_STD_DESC_FW_MSDU_OFFSET;
  511. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_ll;
  512. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_ll;
  513. }
  514. return 0;
  515. fail2:
  516. htt_tx_detach(pdev);
  517. fail1:
  518. return ret;
  519. }
  520. QDF_STATUS htt_attach_target(htt_pdev_handle pdev)
  521. {
  522. QDF_STATUS status;
  523. status = htt_h2t_ver_req_msg(pdev);
  524. if (status != QDF_STATUS_SUCCESS) {
  525. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  526. "%s:%d: could not send h2t_ver_req msg",
  527. __func__, __LINE__);
  528. return status;
  529. }
  530. #if defined(HELIUMPLUS)
  531. /*
  532. * Send the frag_desc info to target.
  533. */
  534. status = htt_h2t_frag_desc_bank_cfg_msg(pdev);
  535. if (status != QDF_STATUS_SUCCESS) {
  536. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  537. "%s:%d: could not send h2t_frag_desc_bank_cfg msg",
  538. __func__, __LINE__);
  539. return status;
  540. }
  541. #endif /* defined(HELIUMPLUS) */
  542. /*
  543. * If applicable, send the rx ring config message to the target.
  544. * The host could wait for the HTT version number confirmation message
  545. * from the target before sending any further HTT messages, but it's
  546. * reasonable to assume that the host and target HTT version numbers
  547. * match, and proceed immediately with the remaining configuration
  548. * handshaking.
  549. */
  550. status = htt_h2t_rx_ring_rfs_cfg_msg(pdev);
  551. if (status != QDF_STATUS_SUCCESS) {
  552. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  553. "%s:%d: could not send h2t_rx_ring_rfs_cfg msg",
  554. __func__, __LINE__);
  555. return status;
  556. }
  557. status = htt_h2t_rx_ring_cfg_msg(pdev);
  558. if (status != QDF_STATUS_SUCCESS) {
  559. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  560. "%s:%d: could not send h2t_rx_ring_cfg msg",
  561. __func__, __LINE__);
  562. return status;
  563. }
  564. status = HTT_IPA_CONFIG(pdev, status);
  565. if (status != QDF_STATUS_SUCCESS) {
  566. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  567. "%s:%d: could not send h2t_ipa_uc_rsc_cfg msg",
  568. __func__, __LINE__);
  569. return status;
  570. }
  571. return status;
  572. }
  573. void htt_detach(htt_pdev_handle pdev)
  574. {
  575. htt_rx_detach(pdev);
  576. htt_tx_detach(pdev);
  577. htt_htc_pkt_pool_free(pdev);
  578. #ifdef ATH_11AC_TXCOMPACT
  579. htt_htc_misc_pkt_pool_free(pdev);
  580. #endif
  581. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  582. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  583. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  584. }
  585. /**
  586. * htt_pdev_free() - Free HTT pdev
  587. * @pdev: htt pdev
  588. *
  589. * Return: none
  590. */
  591. void htt_pdev_free(htt_pdev_handle pdev)
  592. {
  593. qdf_mem_free(pdev);
  594. }
  595. void htt_detach_target(htt_pdev_handle pdev)
  596. {
  597. }
  598. static inline
  599. int htt_update_endpoint(struct htt_pdev_t *pdev,
  600. uint16_t service_id, HTC_ENDPOINT_ID ep)
  601. {
  602. struct hif_opaque_softc *hif_ctx;
  603. uint8_t ul = 0xff, dl = 0xff;
  604. int ul_polled, dl_polled;
  605. int tx_service = 0;
  606. int rc = 0;
  607. hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
  608. if (qdf_unlikely(NULL == hif_ctx)) {
  609. QDF_ASSERT(NULL != hif_ctx);
  610. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  611. "%s:%d: assuming non-tx service.",
  612. __func__, __LINE__);
  613. } else {
  614. ul = dl = 0xff;
  615. if (QDF_STATUS_SUCCESS !=
  616. hif_map_service_to_pipe(hif_ctx, service_id,
  617. &ul, &dl,
  618. &ul_polled, &dl_polled))
  619. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  620. "%s:%d: assuming non-tx srv.",
  621. __func__, __LINE__);
  622. else
  623. tx_service = (ul != 0xff);
  624. }
  625. if (tx_service) {
  626. /* currently we have only one OUT htt tx service */
  627. QDF_BUG(service_id == HTT_DATA_MSG_SVC);
  628. pdev->htc_tx_endpoint = ep;
  629. hif_save_htc_htt_config_endpoint(hif_ctx, ep);
  630. rc = 1;
  631. }
  632. return rc;
  633. }
  634. int htt_htc_attach(struct htt_pdev_t *pdev, uint16_t service_id)
  635. {
  636. struct htc_service_connect_req connect;
  637. struct htc_service_connect_resp response;
  638. QDF_STATUS status;
  639. qdf_mem_set(&connect, sizeof(connect), 0);
  640. qdf_mem_set(&response, sizeof(response), 0);
  641. connect.pMetaData = NULL;
  642. connect.MetaDataLength = 0;
  643. connect.EpCallbacks.pContext = pdev;
  644. connect.EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  645. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  646. connect.EpCallbacks.EpRecv = htt_t2h_msg_handler;
  647. connect.EpCallbacks.ep_resume_tx_queue = htt_tx_resume_handler;
  648. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  649. connect.EpCallbacks.EpRecvRefill = NULL;
  650. connect.EpCallbacks.RecvRefillWaterMark = 1;
  651. /* N/A, fill is done by HIF */
  652. connect.EpCallbacks.EpSendFull = htt_h2t_full;
  653. /*
  654. * Specify how deep to let a queue get before htc_send_pkt will
  655. * call the EpSendFull function due to excessive send queue depth.
  656. */
  657. connect.MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  658. /* disable flow control for HTT data message service */
  659. htt_htc_credit_flow_disable(pdev, &connect);
  660. /* connect to control service */
  661. connect.service_id = service_id;
  662. status = htc_connect_service(pdev->htc_pdev, &connect, &response);
  663. if (status != QDF_STATUS_SUCCESS) {
  664. if (cds_is_fw_down())
  665. return -EIO;
  666. if (status == QDF_STATUS_E_NOMEM ||
  667. cds_is_self_recovery_enabled())
  668. return qdf_status_to_os_return(status);
  669. QDF_BUG(0);
  670. }
  671. htt_update_endpoint(pdev, service_id, response.Endpoint);
  672. /* Start TX HTT2 service if the target support it. */
  673. htt_htc_tx_htt2_service_start(pdev, &connect, &response);
  674. return 0; /* success */
  675. }
  676. void htt_log_rx_ring_info(htt_pdev_handle pdev)
  677. {
  678. if (!pdev) {
  679. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  680. "%s: htt pdev is NULL", __func__);
  681. return;
  682. }
  683. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG,
  684. "%s: Data Stall Detected with reason 4 (=FW_RX_REFILL_FAILED)."
  685. "src htt rx ring: space for %d elements, filled with %d buffers, buffers in the ring %d, refill debt %d",
  686. __func__, pdev->rx_ring.size, pdev->rx_ring.fill_level,
  687. pdev->rx_ring.fill_cnt,
  688. qdf_atomic_read(&pdev->rx_ring.refill_debt));
  689. }
  690. #if HTT_DEBUG_LEVEL > 5
  691. void htt_display(htt_pdev_handle pdev, int indent)
  692. {
  693. qdf_print("%*s%s:\n", indent, " ", "HTT");
  694. qdf_print("%*stx desc pool: %d elems of %d bytes, %d allocated\n",
  695. indent + 4, " ",
  696. pdev->tx_descs.pool_elems,
  697. pdev->tx_descs.size, pdev->tx_descs.alloc_cnt);
  698. qdf_print("%*srx ring: space for %d elems, filled with %d buffers\n",
  699. indent + 4, " ",
  700. pdev->rx_ring.size, pdev->rx_ring.fill_level);
  701. qdf_print("%*sat %pK (%llx paddr)\n", indent + 8, " ",
  702. pdev->rx_ring.buf.paddrs_ring,
  703. (unsigned long long)pdev->rx_ring.base_paddr);
  704. qdf_print("%*snetbuf ring @ %pK\n", indent + 8, " ",
  705. pdev->rx_ring.buf.netbufs_ring);
  706. qdf_print("%*sFW_IDX shadow register: vaddr = %pK, paddr = %llx\n",
  707. indent + 8, " ",
  708. pdev->rx_ring.alloc_idx.vaddr,
  709. (unsigned long long)pdev->rx_ring.alloc_idx.paddr);
  710. qdf_print("%*sSW enqueue idx= %d, SW dequeue idx: desc= %d, buf= %d\n",
  711. indent + 8, " ", *pdev->rx_ring.alloc_idx.vaddr,
  712. pdev->rx_ring.sw_rd_idx.msdu_desc,
  713. pdev->rx_ring.sw_rd_idx.msdu_payld);
  714. }
  715. #endif
  716. #ifdef IPA_OFFLOAD
  717. /**
  718. * htt_ipa_uc_attach() - Allocate UC data path resources
  719. * @pdev: handle to the HTT instance
  720. *
  721. * Return: 0 success
  722. * none 0 fail
  723. */
  724. int htt_ipa_uc_attach(struct htt_pdev_t *pdev)
  725. {
  726. int error;
  727. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
  728. __func__);
  729. /* TX resource attach */
  730. error = htt_tx_ipa_uc_attach(
  731. pdev,
  732. ol_cfg_ipa_uc_tx_buf_size(pdev->ctrl_pdev),
  733. ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev),
  734. ol_cfg_ipa_uc_tx_partition_base(pdev->ctrl_pdev));
  735. if (error) {
  736. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  737. "HTT IPA UC TX attach fail code %d", error);
  738. HTT_ASSERT0(0);
  739. return error;
  740. }
  741. /* RX resource attach */
  742. error = htt_rx_ipa_uc_attach(
  743. pdev, qdf_get_pwr2(pdev->rx_ring.fill_level));
  744. if (error) {
  745. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  746. "HTT IPA UC RX attach fail code %d", error);
  747. htt_tx_ipa_uc_detach(pdev);
  748. HTT_ASSERT0(0);
  749. return error;
  750. }
  751. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
  752. __func__);
  753. return 0; /* success */
  754. }
  755. /**
  756. * htt_ipa_uc_attach() - Remove UC data path resources
  757. * @pdev: handle to the HTT instance
  758. *
  759. * Return: None
  760. */
  761. void htt_ipa_uc_detach(struct htt_pdev_t *pdev)
  762. {
  763. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
  764. __func__);
  765. /* TX IPA micro controller detach */
  766. htt_tx_ipa_uc_detach(pdev);
  767. /* RX IPA micro controller detach */
  768. htt_rx_ipa_uc_detach(pdev);
  769. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
  770. __func__);
  771. }
  772. int
  773. htt_ipa_uc_get_resource(htt_pdev_handle pdev,
  774. qdf_shared_mem_t **ce_sr,
  775. qdf_shared_mem_t **tx_comp_ring,
  776. qdf_shared_mem_t **rx_rdy_ring,
  777. qdf_shared_mem_t **rx2_rdy_ring,
  778. qdf_shared_mem_t **rx_proc_done_idx,
  779. qdf_shared_mem_t **rx2_proc_done_idx,
  780. uint32_t *ce_sr_ring_size,
  781. qdf_dma_addr_t *ce_reg_paddr,
  782. uint32_t *tx_num_alloc_buffer)
  783. {
  784. /* Release allocated resource to client */
  785. *tx_comp_ring = pdev->ipa_uc_tx_rsc.tx_comp_ring;
  786. *rx_rdy_ring = pdev->ipa_uc_rx_rsc.rx_ind_ring;
  787. *rx2_rdy_ring = pdev->ipa_uc_rx_rsc.rx2_ind_ring;
  788. *rx_proc_done_idx = pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx;
  789. *rx2_proc_done_idx = pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx;
  790. *tx_num_alloc_buffer = (uint32_t)pdev->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
  791. /* Get copy engine, bus resource */
  792. htc_ipa_get_ce_resource(pdev->htc_pdev, ce_sr,
  793. ce_sr_ring_size, ce_reg_paddr);
  794. return 0;
  795. }
  796. /**
  797. * htt_ipa_uc_set_doorbell_paddr() - Propagate IPA doorbell address
  798. * @pdev: handle to the HTT instance
  799. * @ipa_uc_tx_doorbell_paddr: TX doorbell base physical address
  800. * @ipa_uc_rx_doorbell_paddr: RX doorbell base physical address
  801. *
  802. * Return: 0 success
  803. */
  804. int
  805. htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,
  806. qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,
  807. qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)
  808. {
  809. pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr = ipa_uc_tx_doorbell_paddr;
  810. pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr = ipa_uc_rx_doorbell_paddr;
  811. return 0;
  812. }
  813. #endif /* IPA_OFFLOAD */
  814. /**
  815. * htt_mark_first_wakeup_packet() - set flag to indicate that
  816. * fw is compatible for marking first packet after wow wakeup
  817. * @pdev: pointer to htt pdev
  818. * @value: 1 for enabled/ 0 for disabled
  819. *
  820. * Return: None
  821. */
  822. void htt_mark_first_wakeup_packet(htt_pdev_handle pdev,
  823. uint8_t value)
  824. {
  825. if (!pdev) {
  826. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  827. "%s: htt pdev is NULL", __func__);
  828. return;
  829. }
  830. pdev->cfg.is_first_wakeup_packet = value;
  831. }