htt.c 26 KB

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