htt.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  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. #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. pdev->cfg.default_tx_comp_req =
  361. !ol_cfg_tx_free_at_download(pdev->ctrl_pdev);
  362. pdev->cfg.is_full_reorder_offload =
  363. ol_cfg_is_full_reorder_offload(pdev->ctrl_pdev);
  364. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  365. "full_reorder_offloaded %d",
  366. (int)pdev->cfg.is_full_reorder_offload);
  367. pdev->cfg.ce_classify_enabled =
  368. ol_cfg_is_ce_classify_enabled(ctrl_pdev);
  369. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  370. "ce_classify %d",
  371. pdev->cfg.ce_classify_enabled);
  372. if (pdev->cfg.is_high_latency) {
  373. qdf_atomic_init(&pdev->htt_tx_credit.target_delta);
  374. qdf_atomic_init(&pdev->htt_tx_credit.bus_delta);
  375. qdf_atomic_add(HTT_MAX_BUS_CREDIT,
  376. &pdev->htt_tx_credit.bus_delta);
  377. }
  378. pdev->targetdef = htc_get_targetdef(htc_pdev);
  379. #if defined(HELIUMPLUS)
  380. HTT_SET_WIFI_IP(pdev, 2, 0);
  381. #endif /* defined(HELIUMPLUS) */
  382. if (NO_HTT_NEEDED)
  383. goto success;
  384. /*
  385. * Connect to HTC service.
  386. * This has to be done before calling htt_rx_attach,
  387. * since htt_rx_attach involves sending a rx ring configure
  388. * message to the target.
  389. */
  390. HTT_TX_MUTEX_INIT(&pdev->htt_tx_mutex);
  391. HTT_TX_NBUF_QUEUE_MUTEX_INIT(pdev);
  392. HTT_TX_MUTEX_INIT(&pdev->credit_mutex);
  393. if (htt_htc_attach_all(pdev))
  394. goto htt_htc_attach_fail;
  395. if (hif_ce_fastpath_cb_register(osc, htt_t2h_msg_handler_fast, pdev))
  396. qdf_print("failed to register fastpath callback\n");
  397. success:
  398. return pdev;
  399. htt_htc_attach_fail:
  400. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  401. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  402. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  403. qdf_mem_free(pdev);
  404. fail1:
  405. return NULL;
  406. }
  407. /**
  408. * htt_attach() - Allocate and setup HTT TX/RX descriptors
  409. * @pdev: pdev ptr
  410. * @desc_pool_size: size of tx descriptors
  411. *
  412. * Return: 0 for success or error code.
  413. */
  414. int
  415. htt_attach(struct htt_pdev_t *pdev, int desc_pool_size)
  416. {
  417. int i;
  418. int ret = 0;
  419. pdev->is_ipa_uc_enabled = false;
  420. if (ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
  421. pdev->is_ipa_uc_enabled = true;
  422. ret = htt_tx_attach(pdev, desc_pool_size);
  423. if (ret)
  424. goto fail1;
  425. ret = htt_rx_attach(pdev);
  426. if (ret)
  427. goto fail2;
  428. /* pre-allocate some HTC_PACKET objects */
  429. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  430. struct htt_htc_pkt_union *pkt;
  431. pkt = qdf_mem_malloc(sizeof(*pkt));
  432. if (!pkt)
  433. break;
  434. htt_htc_pkt_free(pdev, &pkt->u.pkt);
  435. }
  436. if (pdev->cfg.is_high_latency) {
  437. /*
  438. * HL - download the whole frame.
  439. * Specify a download length greater than the max MSDU size,
  440. * so the downloads will be limited by the actual frame sizes.
  441. */
  442. pdev->download_len = 5000;
  443. if (ol_cfg_tx_free_at_download(pdev->ctrl_pdev))
  444. pdev->tx_send_complete_part2 =
  445. ol_tx_download_done_hl_free;
  446. else
  447. pdev->tx_send_complete_part2 =
  448. ol_tx_download_done_hl_retain;
  449. /*
  450. * CHECK THIS LATER: does the HL HTT version of
  451. * htt_rx_mpdu_desc_list_next
  452. * (which is not currently implemented) present the
  453. * adf_nbuf_data(rx_ind_msg)
  454. * as the abstract rx descriptor?
  455. * If not, the rx_fw_desc_offset initialization
  456. * here will have to be adjusted accordingly.
  457. * NOTE: for HL, because fw rx desc is in ind msg,
  458. * not in rx desc, so the
  459. * offset should be negtive value
  460. */
  461. pdev->rx_fw_desc_offset =
  462. HTT_ENDIAN_BYTE_IDX_SWAP(
  463. HTT_RX_IND_FW_RX_DESC_BYTE_OFFSET
  464. - HTT_RX_IND_HL_BYTES);
  465. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_hl;
  466. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_hl;
  467. /* initialize the txrx credit count */
  468. ol_tx_target_credit_update(
  469. pdev->txrx_pdev, ol_cfg_target_tx_credit(
  470. pdev->ctrl_pdev));
  471. } else {
  472. enum wlan_frm_fmt frm_type;
  473. /*
  474. * LL - download just the initial portion of the frame.
  475. * Download enough to cover the encapsulation headers checked
  476. * by the target's tx classification descriptor engine.
  477. *
  478. * For LL, the FW rx desc directly referenced at its location
  479. * inside the rx indication message.
  480. */
  481. /* account for the 802.3 or 802.11 header */
  482. frm_type = ol_cfg_frame_type(pdev->ctrl_pdev);
  483. if (frm_type == wlan_frm_fmt_native_wifi) {
  484. pdev->download_len = HTT_TX_HDR_SIZE_NATIVE_WIFI;
  485. } else if (frm_type == wlan_frm_fmt_802_3) {
  486. pdev->download_len = HTT_TX_HDR_SIZE_ETHERNET;
  487. } else {
  488. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  489. "Unexpected frame type spec: %d", frm_type);
  490. HTT_ASSERT0(0);
  491. }
  492. /*
  493. * Account for the optional L2 / ethernet header fields:
  494. * 802.1Q, LLC/SNAP
  495. */
  496. pdev->download_len +=
  497. HTT_TX_HDR_SIZE_802_1Q + HTT_TX_HDR_SIZE_LLC_SNAP;
  498. /*
  499. * Account for the portion of the L3 (IP) payload that the
  500. * target needs for its tx classification.
  501. */
  502. pdev->download_len += ol_cfg_tx_download_size(pdev->ctrl_pdev);
  503. /*
  504. * Account for the HTT tx descriptor, including the
  505. * HTC header + alignment padding.
  506. */
  507. pdev->download_len += sizeof(struct htt_host_tx_desc_t);
  508. /*
  509. * The TXCOMPACT htt_tx_sched function uses pdev->download_len
  510. * to apply for all requeued tx frames. Thus,
  511. * pdev->download_len has to be the largest download length of
  512. * any tx frame that will be downloaded.
  513. * This maximum download length is for management tx frames,
  514. * which have an 802.11 header.
  515. */
  516. #ifdef ATH_11AC_TXCOMPACT
  517. pdev->download_len = sizeof(struct htt_host_tx_desc_t)
  518. + HTT_TX_HDR_SIZE_OUTER_HDR_MAX /* worst case */
  519. + HTT_TX_HDR_SIZE_802_1Q
  520. + HTT_TX_HDR_SIZE_LLC_SNAP
  521. + ol_cfg_tx_download_size(pdev->ctrl_pdev);
  522. #endif
  523. pdev->tx_send_complete_part2 = ol_tx_download_done_ll;
  524. /*
  525. * For LL, the FW rx desc is alongside the HW rx desc fields in
  526. * the htt_host_rx_desc_base struct/.
  527. */
  528. pdev->rx_fw_desc_offset = RX_STD_DESC_FW_MSDU_OFFSET;
  529. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_ll;
  530. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_ll;
  531. }
  532. return 0;
  533. fail2:
  534. htt_tx_detach(pdev);
  535. fail1:
  536. return ret;
  537. }
  538. QDF_STATUS htt_attach_target(htt_pdev_handle pdev)
  539. {
  540. QDF_STATUS status;
  541. status = htt_h2t_ver_req_msg(pdev);
  542. if (status != QDF_STATUS_SUCCESS) {
  543. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  544. "%s:%d: could not send h2t_ver_req msg",
  545. __func__, __LINE__);
  546. return status;
  547. }
  548. #if defined(HELIUMPLUS)
  549. /*
  550. * Send the frag_desc info to target.
  551. */
  552. status = htt_h2t_frag_desc_bank_cfg_msg(pdev);
  553. if (status != QDF_STATUS_SUCCESS) {
  554. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  555. "%s:%d: could not send h2t_frag_desc_bank_cfg msg",
  556. __func__, __LINE__);
  557. return status;
  558. }
  559. #endif /* defined(HELIUMPLUS) */
  560. /*
  561. * If applicable, send the rx ring config message to the target.
  562. * The host could wait for the HTT version number confirmation message
  563. * from the target before sending any further HTT messages, but it's
  564. * reasonable to assume that the host and target HTT version numbers
  565. * match, and proceed immediately with the remaining configuration
  566. * handshaking.
  567. */
  568. status = htt_h2t_rx_ring_rfs_cfg_msg(pdev);
  569. if (status != QDF_STATUS_SUCCESS) {
  570. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  571. "%s:%d: could not send h2t_rx_ring_rfs_cfg msg",
  572. __func__, __LINE__);
  573. return status;
  574. }
  575. status = htt_h2t_rx_ring_cfg_msg(pdev);
  576. if (status != QDF_STATUS_SUCCESS) {
  577. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  578. "%s:%d: could not send h2t_rx_ring_cfg msg",
  579. __func__, __LINE__);
  580. return status;
  581. }
  582. status = HTT_IPA_CONFIG(pdev, status);
  583. if (status != QDF_STATUS_SUCCESS) {
  584. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  585. "%s:%d: could not send h2t_ipa_uc_rsc_cfg msg",
  586. __func__, __LINE__);
  587. return status;
  588. }
  589. return status;
  590. }
  591. void htt_detach(htt_pdev_handle pdev)
  592. {
  593. htt_rx_detach(pdev);
  594. htt_tx_detach(pdev);
  595. htt_htc_pkt_pool_free(pdev);
  596. #ifdef ATH_11AC_TXCOMPACT
  597. htt_htc_misc_pkt_pool_free(pdev);
  598. #endif
  599. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  600. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  601. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  602. }
  603. /**
  604. * htt_pdev_free() - Free HTT pdev
  605. * @pdev: htt pdev
  606. *
  607. * Return: none
  608. */
  609. void htt_pdev_free(htt_pdev_handle pdev)
  610. {
  611. qdf_mem_free(pdev);
  612. }
  613. void htt_detach_target(htt_pdev_handle pdev)
  614. {
  615. }
  616. static inline
  617. int htt_update_endpoint(struct htt_pdev_t *pdev,
  618. uint16_t service_id, HTC_ENDPOINT_ID ep)
  619. {
  620. struct hif_opaque_softc *hif_ctx;
  621. uint8_t ul = 0xff, dl = 0xff;
  622. int ul_polled, dl_polled;
  623. int tx_service = 0;
  624. int rc = 0;
  625. hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
  626. if (qdf_unlikely(NULL == hif_ctx)) {
  627. QDF_ASSERT(NULL != hif_ctx);
  628. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  629. "%s:%d: assuming non-tx service.",
  630. __func__, __LINE__);
  631. } else {
  632. ul = dl = 0xff;
  633. if (QDF_STATUS_SUCCESS !=
  634. hif_map_service_to_pipe(hif_ctx, service_id,
  635. &ul, &dl,
  636. &ul_polled, &dl_polled))
  637. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  638. "%s:%d: assuming non-tx srv.",
  639. __func__, __LINE__);
  640. else
  641. tx_service = (ul != 0xff);
  642. }
  643. if (tx_service) {
  644. /* currently we have only one OUT htt tx service */
  645. QDF_BUG(service_id == HTT_DATA_MSG_SVC);
  646. pdev->htc_tx_endpoint = ep;
  647. hif_save_htc_htt_config_endpoint(hif_ctx, ep);
  648. rc = 1;
  649. }
  650. return rc;
  651. }
  652. int htt_htc_attach(struct htt_pdev_t *pdev, uint16_t service_id)
  653. {
  654. struct htc_service_connect_req connect;
  655. struct htc_service_connect_resp response;
  656. QDF_STATUS status;
  657. qdf_mem_set(&connect, sizeof(connect), 0);
  658. qdf_mem_set(&response, sizeof(response), 0);
  659. connect.pMetaData = NULL;
  660. connect.MetaDataLength = 0;
  661. connect.EpCallbacks.pContext = pdev;
  662. connect.EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  663. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  664. connect.EpCallbacks.EpRecv = htt_t2h_msg_handler;
  665. connect.EpCallbacks.ep_resume_tx_queue = htt_tx_resume_handler;
  666. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  667. connect.EpCallbacks.EpRecvRefill = NULL;
  668. connect.EpCallbacks.RecvRefillWaterMark = 1;
  669. /* N/A, fill is done by HIF */
  670. connect.EpCallbacks.EpSendFull = htt_h2t_full;
  671. /*
  672. * Specify how deep to let a queue get before htc_send_pkt will
  673. * call the EpSendFull function due to excessive send queue depth.
  674. */
  675. connect.MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  676. /* disable flow control for HTT data message service */
  677. htt_htc_credit_flow_disable(pdev, &connect);
  678. /* connect to control service */
  679. connect.service_id = service_id;
  680. status = htc_connect_service(pdev->htc_pdev, &connect, &response);
  681. if (status != QDF_STATUS_SUCCESS) {
  682. if (cds_is_fw_down())
  683. return -EIO;
  684. if (status == QDF_STATUS_E_NOMEM ||
  685. cds_is_self_recovery_enabled())
  686. return qdf_status_to_os_return(status);
  687. QDF_BUG(0);
  688. }
  689. htt_update_endpoint(pdev, service_id, response.Endpoint);
  690. /* Start TX HTT2 service if the target support it. */
  691. htt_htc_tx_htt2_service_start(pdev, &connect, &response);
  692. return 0; /* success */
  693. }
  694. void htt_log_rx_ring_info(htt_pdev_handle pdev)
  695. {
  696. if (!pdev) {
  697. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  698. "%s: htt pdev is NULL", __func__);
  699. return;
  700. }
  701. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG,
  702. "%s: Data Stall Detected with reason 4 (=FW_RX_REFILL_FAILED)."
  703. "src htt rx ring: space for %d elements, filled with %d buffers, buffers in the ring %d, refill debt %d",
  704. __func__, pdev->rx_ring.size, pdev->rx_ring.fill_level,
  705. pdev->rx_ring.fill_cnt,
  706. qdf_atomic_read(&pdev->rx_ring.refill_debt));
  707. }
  708. #if HTT_DEBUG_LEVEL > 5
  709. void htt_display(htt_pdev_handle pdev, int indent)
  710. {
  711. qdf_print("%*s%s:\n", indent, " ", "HTT");
  712. qdf_print("%*stx desc pool: %d elems of %d bytes, %d allocated\n",
  713. indent + 4, " ",
  714. pdev->tx_descs.pool_elems,
  715. pdev->tx_descs.size, pdev->tx_descs.alloc_cnt);
  716. qdf_print("%*srx ring: space for %d elems, filled with %d buffers\n",
  717. indent + 4, " ",
  718. pdev->rx_ring.size, pdev->rx_ring.fill_level);
  719. qdf_print("%*sat %pK (%llx paddr)\n", indent + 8, " ",
  720. pdev->rx_ring.buf.paddrs_ring,
  721. (unsigned long long)pdev->rx_ring.base_paddr);
  722. qdf_print("%*snetbuf ring @ %pK\n", indent + 8, " ",
  723. pdev->rx_ring.buf.netbufs_ring);
  724. qdf_print("%*sFW_IDX shadow register: vaddr = %pK, paddr = %llx\n",
  725. indent + 8, " ",
  726. pdev->rx_ring.alloc_idx.vaddr,
  727. (unsigned long long)pdev->rx_ring.alloc_idx.paddr);
  728. qdf_print("%*sSW enqueue idx= %d, SW dequeue idx: desc= %d, buf= %d\n",
  729. indent + 8, " ", *pdev->rx_ring.alloc_idx.vaddr,
  730. pdev->rx_ring.sw_rd_idx.msdu_desc,
  731. pdev->rx_ring.sw_rd_idx.msdu_payld);
  732. }
  733. #endif
  734. #ifdef IPA_OFFLOAD
  735. /**
  736. * htt_ipa_uc_attach() - Allocate UC data path resources
  737. * @pdev: handle to the HTT instance
  738. *
  739. * Return: 0 success
  740. * none 0 fail
  741. */
  742. int htt_ipa_uc_attach(struct htt_pdev_t *pdev)
  743. {
  744. int error;
  745. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
  746. __func__);
  747. /* TX resource attach */
  748. error = htt_tx_ipa_uc_attach(
  749. pdev,
  750. ol_cfg_ipa_uc_tx_buf_size(pdev->ctrl_pdev),
  751. ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev),
  752. ol_cfg_ipa_uc_tx_partition_base(pdev->ctrl_pdev));
  753. if (error) {
  754. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  755. "HTT IPA UC TX attach fail code %d", error);
  756. HTT_ASSERT0(0);
  757. return error;
  758. }
  759. /* RX resource attach */
  760. error = htt_rx_ipa_uc_attach(
  761. pdev, qdf_get_pwr2(pdev->rx_ring.fill_level));
  762. if (error) {
  763. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  764. "HTT IPA UC RX attach fail code %d", error);
  765. htt_tx_ipa_uc_detach(pdev);
  766. HTT_ASSERT0(0);
  767. return error;
  768. }
  769. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
  770. __func__);
  771. return 0; /* success */
  772. }
  773. /**
  774. * htt_ipa_uc_attach() - Remove UC data path resources
  775. * @pdev: handle to the HTT instance
  776. *
  777. * Return: None
  778. */
  779. void htt_ipa_uc_detach(struct htt_pdev_t *pdev)
  780. {
  781. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
  782. __func__);
  783. /* TX IPA micro controller detach */
  784. htt_tx_ipa_uc_detach(pdev);
  785. /* RX IPA micro controller detach */
  786. htt_rx_ipa_uc_detach(pdev);
  787. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
  788. __func__);
  789. }
  790. int
  791. htt_ipa_uc_get_resource(htt_pdev_handle pdev,
  792. qdf_shared_mem_t **ce_sr,
  793. qdf_shared_mem_t **tx_comp_ring,
  794. qdf_shared_mem_t **rx_rdy_ring,
  795. qdf_shared_mem_t **rx2_rdy_ring,
  796. qdf_shared_mem_t **rx_proc_done_idx,
  797. qdf_shared_mem_t **rx2_proc_done_idx,
  798. uint32_t *ce_sr_ring_size,
  799. qdf_dma_addr_t *ce_reg_paddr,
  800. uint32_t *tx_num_alloc_buffer)
  801. {
  802. /* Release allocated resource to client */
  803. *tx_comp_ring = pdev->ipa_uc_tx_rsc.tx_comp_ring;
  804. *rx_rdy_ring = pdev->ipa_uc_rx_rsc.rx_ind_ring;
  805. *rx2_rdy_ring = pdev->ipa_uc_rx_rsc.rx2_ind_ring;
  806. *rx_proc_done_idx = pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx;
  807. *rx2_proc_done_idx = pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx;
  808. *tx_num_alloc_buffer = (uint32_t)pdev->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
  809. /* Get copy engine, bus resource */
  810. htc_ipa_get_ce_resource(pdev->htc_pdev, ce_sr,
  811. ce_sr_ring_size, ce_reg_paddr);
  812. return 0;
  813. }
  814. /**
  815. * htt_ipa_uc_set_doorbell_paddr() - Propagate IPA doorbell address
  816. * @pdev: handle to the HTT instance
  817. * @ipa_uc_tx_doorbell_paddr: TX doorbell base physical address
  818. * @ipa_uc_rx_doorbell_paddr: RX doorbell base physical address
  819. *
  820. * Return: 0 success
  821. */
  822. int
  823. htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,
  824. qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,
  825. qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)
  826. {
  827. pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr = ipa_uc_tx_doorbell_paddr;
  828. pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr = ipa_uc_rx_doorbell_paddr;
  829. return 0;
  830. }
  831. #endif /* IPA_OFFLOAD */
  832. /**
  833. * htt_mark_first_wakeup_packet() - set flag to indicate that
  834. * fw is compatible for marking first packet after wow wakeup
  835. * @pdev: pointer to htt pdev
  836. * @value: 1 for enabled/ 0 for disabled
  837. *
  838. * Return: None
  839. */
  840. void htt_mark_first_wakeup_packet(htt_pdev_handle pdev,
  841. uint8_t value)
  842. {
  843. if (!pdev) {
  844. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  845. "%s: htt pdev is NULL", __func__);
  846. return;
  847. }
  848. pdev->cfg.is_first_wakeup_packet = value;
  849. }