htt.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. /*
  2. * Copyright (c) 2011, 2014-2017 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. pkt = pdev->htt_htc_pkt_freelist;
  95. while (pkt) {
  96. next = pkt->u.next;
  97. qdf_mem_free(pkt);
  98. pkt = next;
  99. }
  100. pdev->htt_htc_pkt_freelist = NULL;
  101. }
  102. #ifdef ATH_11AC_TXCOMPACT
  103. void
  104. htt_htc_misc_pkt_list_trim(struct htt_pdev_t *pdev, int level)
  105. {
  106. struct htt_htc_pkt_union *pkt, *next, *prev = NULL;
  107. int i = 0;
  108. qdf_nbuf_t netbuf;
  109. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  110. pkt = pdev->htt_htc_pkt_misclist;
  111. while (pkt) {
  112. next = pkt->u.next;
  113. /* trim the out grown list*/
  114. if (++i > level) {
  115. netbuf =
  116. (qdf_nbuf_t)(pkt->u.pkt.htc_pkt.pNetBufContext);
  117. qdf_nbuf_unmap(pdev->osdev, netbuf, QDF_DMA_TO_DEVICE);
  118. qdf_nbuf_free(netbuf);
  119. qdf_mem_free(pkt);
  120. pkt = NULL;
  121. if (prev)
  122. prev->u.next = NULL;
  123. }
  124. prev = pkt;
  125. pkt = next;
  126. }
  127. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  128. }
  129. void htt_htc_misc_pkt_list_add(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
  130. {
  131. struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
  132. int misclist_trim_level = htc_get_tx_queue_depth(pdev->htc_pdev,
  133. pkt->htc_pkt.Endpoint)
  134. + HTT_HTC_PKT_MISCLIST_SIZE;
  135. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  136. if (pdev->htt_htc_pkt_misclist) {
  137. u_pkt->u.next = pdev->htt_htc_pkt_misclist;
  138. pdev->htt_htc_pkt_misclist = u_pkt;
  139. } else {
  140. pdev->htt_htc_pkt_misclist = u_pkt;
  141. }
  142. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  143. /* only ce pipe size + tx_queue_depth could possibly be in use
  144. * free older packets in the msiclist
  145. */
  146. htt_htc_misc_pkt_list_trim(pdev, misclist_trim_level);
  147. }
  148. void htt_htc_misc_pkt_pool_free(struct htt_pdev_t *pdev)
  149. {
  150. struct htt_htc_pkt_union *pkt, *next;
  151. qdf_nbuf_t netbuf;
  152. pkt = pdev->htt_htc_pkt_misclist;
  153. while (pkt) {
  154. next = pkt->u.next;
  155. if (htc_packet_get_magic_cookie(&(pkt->u.pkt.htc_pkt)) !=
  156. HTC_PACKET_MAGIC_COOKIE) {
  157. pkt = next;
  158. continue;
  159. }
  160. netbuf = (qdf_nbuf_t) (pkt->u.pkt.htc_pkt.pNetBufContext);
  161. qdf_nbuf_unmap(pdev->osdev, netbuf, QDF_DMA_TO_DEVICE);
  162. qdf_nbuf_free(netbuf);
  163. qdf_mem_free(pkt);
  164. pkt = next;
  165. }
  166. pdev->htt_htc_pkt_misclist = NULL;
  167. }
  168. #endif
  169. /* AR6004 don't need HTT layer. */
  170. #ifdef AR6004_HW
  171. #define NO_HTT_NEEDED true
  172. #else
  173. #define NO_HTT_NEEDED false
  174. #endif
  175. #if defined(QCA_TX_HTT2_SUPPORT) && defined(CONFIG_HL_SUPPORT)
  176. /**
  177. * htt_htc_tx_htt2_service_start() - Start TX HTT2 service
  178. *
  179. * @pdev: pointer to htt device.
  180. * @connect_req: pointer to service connection request information
  181. * @connect_resp: pointer to service connection response information
  182. *
  183. *
  184. * Return: None
  185. */
  186. static void
  187. htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
  188. struct htc_service_connect_req *connect_req,
  189. struct htc_service_connect_resp *connect_resp)
  190. {
  191. QDF_STATUS status;
  192. qdf_mem_set(connect_req, 0, sizeof(struct htc_service_connect_req));
  193. qdf_mem_set(connect_resp, 0, sizeof(struct htc_service_connect_resp));
  194. /* The same as HTT service but no RX. */
  195. connect_req->EpCallbacks.pContext = pdev;
  196. connect_req->EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  197. connect_req->EpCallbacks.EpSendFull = htt_h2t_full;
  198. connect_req->MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  199. /* Should NOT support credit flow control. */
  200. connect_req->ConnectionFlags |=
  201. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  202. /* Enable HTC schedule mechanism for TX HTT2 service. */
  203. connect_req->ConnectionFlags |= HTC_CONNECT_FLAGS_ENABLE_HTC_SCHEDULE;
  204. connect_req->service_id = HTT_DATA2_MSG_SVC;
  205. status = htc_connect_service(pdev->htc_pdev, connect_req, connect_resp);
  206. if (status != QDF_STATUS_SUCCESS) {
  207. pdev->htc_tx_htt2_endpoint = ENDPOINT_UNUSED;
  208. pdev->htc_tx_htt2_max_size = 0;
  209. } else {
  210. pdev->htc_tx_htt2_endpoint = connect_resp->Endpoint;
  211. pdev->htc_tx_htt2_max_size = HTC_TX_HTT2_MAX_SIZE;
  212. }
  213. qdf_print("TX HTT %s, ep %d size %d\n",
  214. (status == QDF_STATUS_SUCCESS ? "ON" : "OFF"),
  215. pdev->htc_tx_htt2_endpoint,
  216. pdev->htc_tx_htt2_max_size);
  217. }
  218. #else
  219. static inline void
  220. htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
  221. struct htc_service_connect_req *connect_req,
  222. struct htc_service_connect_resp *connect_resp)
  223. {
  224. }
  225. #endif
  226. /**
  227. * htt_htc_credit_flow_disable() - disable flow control for
  228. * HTT data message service
  229. *
  230. * @pdev: pointer to htt device.
  231. * @connect_req: pointer to service connection request information
  232. *
  233. * HTC Credit mechanism is disabled based on
  234. * default_tx_comp_req as throughput will be lower
  235. * if we disable htc credit mechanism with default_tx_comp_req
  236. * set since txrx download packet will be limited by ota
  237. * completion.
  238. *
  239. * Return: None
  240. */
  241. static
  242. void htt_htc_credit_flow_disable(struct htt_pdev_t *pdev,
  243. struct htc_service_connect_req *connect_req)
  244. {
  245. if (pdev->osdev->bus_type == QDF_BUS_TYPE_SDIO) {
  246. /*
  247. * TODO:Conditional disabling will be removed once firmware
  248. * with reduced tx completion is pushed into release builds.
  249. */
  250. if (!pdev->cfg.default_tx_comp_req)
  251. connect_req->ConnectionFlags |=
  252. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  253. } else {
  254. connect_req->ConnectionFlags |=
  255. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  256. }
  257. }
  258. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  259. /**
  260. * htt_dump_bundle_stats() - dump wlan stats
  261. * @pdev: handle to the HTT instance
  262. *
  263. * Return: None
  264. */
  265. void htt_dump_bundle_stats(htt_pdev_handle pdev)
  266. {
  267. htc_dump_bundle_stats(pdev->htc_pdev);
  268. }
  269. /**
  270. * htt_clear_bundle_stats() - clear wlan stats
  271. * @pdev: handle to the HTT instance
  272. *
  273. * Return: None
  274. */
  275. void htt_clear_bundle_stats(htt_pdev_handle pdev)
  276. {
  277. htc_clear_bundle_stats(pdev->htc_pdev);
  278. }
  279. #endif
  280. #if defined(QCA_WIFI_3_0_ADRASTEA)
  281. /**
  282. * htt_htc_attach_all() - Connect to HTC service for HTT
  283. * @pdev: pdev ptr
  284. *
  285. * Return: 0 for success or error code.
  286. */
  287. static int
  288. htt_htc_attach_all(struct htt_pdev_t *pdev)
  289. {
  290. if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
  291. return -EIO;
  292. if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
  293. return -EIO;
  294. if (htt_htc_attach(pdev, HTT_DATA3_MSG_SVC))
  295. return -EIO;
  296. return 0;
  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. "is_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_enabled? %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. if (htt_htc_attach_all(pdev))
  373. goto htt_htc_attach_fail;
  374. if (hif_ce_fastpath_cb_register(osc, htt_t2h_msg_handler_fast, pdev))
  375. qdf_print("failed to register fastpath callback\n");
  376. success:
  377. return pdev;
  378. htt_htc_attach_fail:
  379. qdf_mem_free(pdev);
  380. fail1:
  381. return NULL;
  382. }
  383. /**
  384. * htt_attach() - Allocate and setup HTT TX/RX descriptors
  385. * @pdev: pdev ptr
  386. * @desc_pool_size: size of tx descriptors
  387. *
  388. * Return: 0 for success or error code.
  389. */
  390. int
  391. htt_attach(struct htt_pdev_t *pdev, int desc_pool_size)
  392. {
  393. int i;
  394. int ret = 0;
  395. ret = htt_tx_attach(pdev, desc_pool_size);
  396. if (ret)
  397. goto fail1;
  398. ret = htt_rx_attach(pdev);
  399. if (ret)
  400. goto fail2;
  401. HTT_TX_MUTEX_INIT(&pdev->htt_tx_mutex);
  402. HTT_TX_NBUF_QUEUE_MUTEX_INIT(pdev);
  403. HTT_TX_MUTEX_INIT(&pdev->credit_mutex);
  404. /* pre-allocate some HTC_PACKET objects */
  405. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  406. struct htt_htc_pkt_union *pkt;
  407. pkt = qdf_mem_malloc(sizeof(*pkt));
  408. if (!pkt)
  409. break;
  410. htt_htc_pkt_free(pdev, &pkt->u.pkt);
  411. }
  412. if (pdev->cfg.is_high_latency) {
  413. /*
  414. * HL - download the whole frame.
  415. * Specify a download length greater than the max MSDU size,
  416. * so the downloads will be limited by the actual frame sizes.
  417. */
  418. pdev->download_len = 5000;
  419. if (ol_cfg_tx_free_at_download(pdev->ctrl_pdev))
  420. pdev->tx_send_complete_part2 =
  421. ol_tx_download_done_hl_free;
  422. else
  423. pdev->tx_send_complete_part2 =
  424. ol_tx_download_done_hl_retain;
  425. /*
  426. * CHECK THIS LATER: does the HL HTT version of
  427. * htt_rx_mpdu_desc_list_next
  428. * (which is not currently implemented) present the
  429. * adf_nbuf_data(rx_ind_msg)
  430. * as the abstract rx descriptor?
  431. * If not, the rx_fw_desc_offset initialization
  432. * here will have to be adjusted accordingly.
  433. * NOTE: for HL, because fw rx desc is in ind msg,
  434. * not in rx desc, so the
  435. * offset should be negtive value
  436. */
  437. pdev->rx_fw_desc_offset =
  438. HTT_ENDIAN_BYTE_IDX_SWAP(
  439. HTT_RX_IND_FW_RX_DESC_BYTE_OFFSET
  440. - HTT_RX_IND_HL_BYTES);
  441. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_hl;
  442. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_hl;
  443. /* initialize the txrx credit count */
  444. ol_tx_target_credit_update(
  445. pdev->txrx_pdev, ol_cfg_target_tx_credit(
  446. pdev->ctrl_pdev));
  447. } else {
  448. enum wlan_frm_fmt frm_type;
  449. /*
  450. * LL - download just the initial portion of the frame.
  451. * Download enough to cover the encapsulation headers checked
  452. * by the target's tx classification descriptor engine.
  453. *
  454. * For LL, the FW rx desc directly referenced at its location
  455. * inside the rx indication message.
  456. */
  457. /* account for the 802.3 or 802.11 header */
  458. frm_type = ol_cfg_frame_type(pdev->ctrl_pdev);
  459. if (frm_type == wlan_frm_fmt_native_wifi) {
  460. pdev->download_len = HTT_TX_HDR_SIZE_NATIVE_WIFI;
  461. } else if (frm_type == wlan_frm_fmt_802_3) {
  462. pdev->download_len = HTT_TX_HDR_SIZE_ETHERNET;
  463. } else {
  464. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  465. "Unexpected frame type spec: %d", frm_type);
  466. HTT_ASSERT0(0);
  467. }
  468. /*
  469. * Account for the optional L2 / ethernet header fields:
  470. * 802.1Q, LLC/SNAP
  471. */
  472. pdev->download_len +=
  473. HTT_TX_HDR_SIZE_802_1Q + HTT_TX_HDR_SIZE_LLC_SNAP;
  474. /*
  475. * Account for the portion of the L3 (IP) payload that the
  476. * target needs for its tx classification.
  477. */
  478. pdev->download_len += ol_cfg_tx_download_size(pdev->ctrl_pdev);
  479. /*
  480. * Account for the HTT tx descriptor, including the
  481. * HTC header + alignment padding.
  482. */
  483. pdev->download_len += sizeof(struct htt_host_tx_desc_t);
  484. /*
  485. * The TXCOMPACT htt_tx_sched function uses pdev->download_len
  486. * to apply for all requeued tx frames. Thus,
  487. * pdev->download_len has to be the largest download length of
  488. * any tx frame that will be downloaded.
  489. * This maximum download length is for management tx frames,
  490. * which have an 802.11 header.
  491. */
  492. #ifdef ATH_11AC_TXCOMPACT
  493. pdev->download_len = sizeof(struct htt_host_tx_desc_t)
  494. + HTT_TX_HDR_SIZE_OUTER_HDR_MAX /* worst case */
  495. + HTT_TX_HDR_SIZE_802_1Q
  496. + HTT_TX_HDR_SIZE_LLC_SNAP
  497. + ol_cfg_tx_download_size(pdev->ctrl_pdev);
  498. #endif
  499. pdev->tx_send_complete_part2 = ol_tx_download_done_ll;
  500. /*
  501. * For LL, the FW rx desc is alongside the HW rx desc fields in
  502. * the htt_host_rx_desc_base struct/.
  503. */
  504. pdev->rx_fw_desc_offset = RX_STD_DESC_FW_MSDU_OFFSET;
  505. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_ll;
  506. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_ll;
  507. }
  508. return 0;
  509. fail2:
  510. htt_tx_detach(pdev);
  511. fail1:
  512. return ret;
  513. }
  514. QDF_STATUS htt_attach_target(htt_pdev_handle pdev)
  515. {
  516. QDF_STATUS status;
  517. status = htt_h2t_ver_req_msg(pdev);
  518. if (status != QDF_STATUS_SUCCESS) {
  519. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  520. "%s:%d: could not send h2t_ver_req msg",
  521. __func__, __LINE__);
  522. return status;
  523. }
  524. #if defined(HELIUMPLUS)
  525. /*
  526. * Send the frag_desc info to target.
  527. */
  528. status = htt_h2t_frag_desc_bank_cfg_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_frag_desc_bank_cfg msg",
  532. __func__, __LINE__);
  533. return status;
  534. }
  535. #endif /* defined(HELIUMPLUS) */
  536. /*
  537. * If applicable, send the rx ring config message to the target.
  538. * The host could wait for the HTT version number confirmation message
  539. * from the target before sending any further HTT messages, but it's
  540. * reasonable to assume that the host and target HTT version numbers
  541. * match, and proceed immediately with the remaining configuration
  542. * handshaking.
  543. */
  544. status = htt_h2t_rx_ring_rfs_cfg_msg(pdev);
  545. if (status != QDF_STATUS_SUCCESS) {
  546. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  547. "%s:%d: could not send h2t_rx_ring_rfs_cfg msg",
  548. __func__, __LINE__);
  549. return status;
  550. }
  551. status = htt_h2t_rx_ring_cfg_msg(pdev);
  552. if (status != QDF_STATUS_SUCCESS) {
  553. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  554. "%s:%d: could not send h2t_rx_ring_cfg msg",
  555. __func__, __LINE__);
  556. return status;
  557. }
  558. status = HTT_IPA_CONFIG(pdev, status);
  559. if (status != QDF_STATUS_SUCCESS) {
  560. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  561. "%s:%d: could not send h2t_ipa_uc_rsc_cfg msg",
  562. __func__, __LINE__);
  563. return status;
  564. }
  565. return status;
  566. }
  567. void htt_detach(htt_pdev_handle pdev)
  568. {
  569. htt_rx_detach(pdev);
  570. htt_tx_detach(pdev);
  571. htt_htc_pkt_pool_free(pdev);
  572. #ifdef ATH_11AC_TXCOMPACT
  573. htt_htc_misc_pkt_pool_free(pdev);
  574. #endif
  575. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  576. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  577. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  578. htt_rx_dbg_rxbuf_deinit(pdev);
  579. }
  580. /**
  581. * htt_pdev_free() - Free HTT pdev
  582. * @pdev: htt pdev
  583. *
  584. * Return: none
  585. */
  586. void htt_pdev_free(htt_pdev_handle pdev)
  587. {
  588. qdf_mem_free(pdev);
  589. }
  590. void htt_detach_target(htt_pdev_handle pdev)
  591. {
  592. }
  593. static inline
  594. int htt_update_endpoint(struct htt_pdev_t *pdev,
  595. uint16_t service_id, HTC_ENDPOINT_ID ep)
  596. {
  597. struct hif_opaque_softc *hif_ctx;
  598. uint8_t ul = 0xff, dl = 0xff;
  599. int ul_polled, dl_polled;
  600. int tx_service = 0;
  601. int rc = 0;
  602. hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
  603. if (qdf_unlikely(NULL == hif_ctx)) {
  604. QDF_ASSERT(NULL != hif_ctx);
  605. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  606. "%s:%d: assuming non-tx service.",
  607. __func__, __LINE__);
  608. } else {
  609. ul = dl = 0xff;
  610. if (QDF_STATUS_SUCCESS !=
  611. hif_map_service_to_pipe(hif_ctx, service_id,
  612. &ul, &dl,
  613. &ul_polled, &dl_polled))
  614. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  615. "%s:%d: assuming non-tx srv.",
  616. __func__, __LINE__);
  617. else
  618. tx_service = (ul != 0xff);
  619. }
  620. if (tx_service) {
  621. /* currently we have only one OUT htt tx service */
  622. QDF_BUG(service_id == HTT_DATA_MSG_SVC);
  623. pdev->htc_tx_endpoint = ep;
  624. hif_save_htc_htt_config_endpoint(hif_ctx, ep);
  625. rc = 1;
  626. }
  627. return rc;
  628. }
  629. int htt_htc_attach(struct htt_pdev_t *pdev, uint16_t service_id)
  630. {
  631. struct htc_service_connect_req connect;
  632. struct htc_service_connect_resp response;
  633. QDF_STATUS status;
  634. qdf_mem_set(&connect, sizeof(connect), 0);
  635. qdf_mem_set(&response, sizeof(response), 0);
  636. connect.pMetaData = NULL;
  637. connect.MetaDataLength = 0;
  638. connect.EpCallbacks.pContext = pdev;
  639. connect.EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  640. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  641. connect.EpCallbacks.EpRecv = htt_t2h_msg_handler;
  642. connect.EpCallbacks.ep_resume_tx_queue = htt_tx_resume_handler;
  643. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  644. connect.EpCallbacks.EpRecvRefill = NULL;
  645. connect.EpCallbacks.RecvRefillWaterMark = 1;
  646. /* N/A, fill is done by HIF */
  647. connect.EpCallbacks.EpSendFull = htt_h2t_full;
  648. /*
  649. * Specify how deep to let a queue get before htc_send_pkt will
  650. * call the EpSendFull function due to excessive send queue depth.
  651. */
  652. connect.MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  653. /* disable flow control for HTT data message service */
  654. htt_htc_credit_flow_disable(pdev, &connect);
  655. /* connect to control service */
  656. connect.service_id = service_id;
  657. status = htc_connect_service(pdev->htc_pdev, &connect, &response);
  658. if (status != QDF_STATUS_SUCCESS) {
  659. if (!cds_is_fw_down())
  660. QDF_BUG(0);
  661. return -EIO; /* failure */
  662. }
  663. htt_update_endpoint(pdev, service_id, response.Endpoint);
  664. /* Start TX HTT2 service if the target support it. */
  665. htt_htc_tx_htt2_service_start(pdev, &connect, &response);
  666. return 0; /* success */
  667. }
  668. #if HTT_DEBUG_LEVEL > 5
  669. void htt_display(htt_pdev_handle pdev, int indent)
  670. {
  671. qdf_print("%*s%s:\n", indent, " ", "HTT");
  672. qdf_print("%*stx desc pool: %d elems of %d bytes, %d allocated\n",
  673. indent + 4, " ",
  674. pdev->tx_descs.pool_elems,
  675. pdev->tx_descs.size, pdev->tx_descs.alloc_cnt);
  676. qdf_print("%*srx ring: space for %d elems, filled with %d buffers\n",
  677. indent + 4, " ",
  678. pdev->rx_ring.size, pdev->rx_ring.fill_level);
  679. qdf_print("%*sat %p (%llx paddr)\n", indent + 8, " ",
  680. pdev->rx_ring.buf.paddrs_ring,
  681. (unsigned long long)pdev->rx_ring.base_paddr);
  682. qdf_print("%*snetbuf ring @ %p\n", indent + 8, " ",
  683. pdev->rx_ring.buf.netbufs_ring);
  684. qdf_print("%*sFW_IDX shadow register: vaddr = %p, paddr = %llx\n",
  685. indent + 8, " ",
  686. pdev->rx_ring.alloc_idx.vaddr,
  687. (unsigned long long)pdev->rx_ring.alloc_idx.paddr);
  688. qdf_print("%*sSW enqueue idx= %d, SW dequeue idx: desc= %d, buf= %d\n",
  689. indent + 8, " ", *pdev->rx_ring.alloc_idx.vaddr,
  690. pdev->rx_ring.sw_rd_idx.msdu_desc,
  691. pdev->rx_ring.sw_rd_idx.msdu_payld);
  692. }
  693. #endif
  694. #ifdef IPA_OFFLOAD
  695. /**
  696. * htt_ipa_uc_attach() - Allocate UC data path resources
  697. * @pdev: handle to the HTT instance
  698. *
  699. * Return: 0 success
  700. * none 0 fail
  701. */
  702. int htt_ipa_uc_attach(struct htt_pdev_t *pdev)
  703. {
  704. int error;
  705. /* TX resource attach */
  706. error = htt_tx_ipa_uc_attach(
  707. pdev,
  708. ol_cfg_ipa_uc_tx_buf_size(pdev->ctrl_pdev),
  709. ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev),
  710. ol_cfg_ipa_uc_tx_partition_base(pdev->ctrl_pdev));
  711. if (error) {
  712. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  713. "HTT IPA UC TX attach fail code %d", error);
  714. HTT_ASSERT0(0);
  715. return error;
  716. }
  717. /* RX resource attach */
  718. error = htt_rx_ipa_uc_attach(
  719. pdev, qdf_get_pwr2(pdev->rx_ring.fill_level));
  720. if (error) {
  721. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  722. "HTT IPA UC RX attach fail code %d", error);
  723. htt_tx_ipa_uc_detach(pdev);
  724. HTT_ASSERT0(0);
  725. return error;
  726. }
  727. return 0; /* success */
  728. }
  729. /**
  730. * htt_ipa_uc_attach() - Remove UC data path resources
  731. * @pdev: handle to the HTT instance
  732. *
  733. * Return: None
  734. */
  735. void htt_ipa_uc_detach(struct htt_pdev_t *pdev)
  736. {
  737. /* TX IPA micro controller detach */
  738. htt_tx_ipa_uc_detach(pdev);
  739. /* RX IPA micro controller detach */
  740. htt_rx_ipa_uc_detach(pdev);
  741. }
  742. /**
  743. * htt_ipa_uc_get_resource() - Get uc resource from htt and lower layer
  744. * @pdev: handle to the HTT instance
  745. * @ce_sr_base_paddr: copy engine source ring base physical address
  746. * @ce_sr_ring_size: copy engine source ring size
  747. * @ce_reg_paddr: copy engine register physical address
  748. * @tx_comp_ring_base_paddr: tx comp ring base physical address
  749. * @tx_comp_ring_size: tx comp ring size
  750. * @tx_num_alloc_buffer: number of allocated tx buffer
  751. * @rx_rdy_ring_base_paddr: rx ready ring base physical address
  752. * @rx_rdy_ring_size: rx ready ring size
  753. * @rx_proc_done_idx_paddr: rx process done index physical address
  754. * @rx_proc_done_idx_vaddr: rx process done index virtual address
  755. * @rx2_rdy_ring_base_paddr: rx done ring base physical address
  756. * @rx2_rdy_ring_size: rx done ring size
  757. * @rx2_proc_done_idx_paddr: rx done index physical address
  758. * @rx2_proc_done_idx_vaddr: rx done index virtual address
  759. *
  760. * Return: 0 success
  761. */
  762. int
  763. htt_ipa_uc_get_resource(htt_pdev_handle pdev,
  764. qdf_dma_addr_t *ce_sr_base_paddr,
  765. uint32_t *ce_sr_ring_size,
  766. qdf_dma_addr_t *ce_reg_paddr,
  767. qdf_dma_addr_t *tx_comp_ring_base_paddr,
  768. uint32_t *tx_comp_ring_size,
  769. uint32_t *tx_num_alloc_buffer,
  770. qdf_dma_addr_t *rx_rdy_ring_base_paddr,
  771. uint32_t *rx_rdy_ring_size,
  772. qdf_dma_addr_t *rx_proc_done_idx_paddr,
  773. void **rx_proc_done_idx_vaddr,
  774. qdf_dma_addr_t *rx2_rdy_ring_base_paddr,
  775. uint32_t *rx2_rdy_ring_size,
  776. qdf_dma_addr_t *rx2_proc_done_idx_paddr,
  777. void **rx2_proc_done_idx_vaddr)
  778. {
  779. /* Release allocated resource to client */
  780. *tx_comp_ring_base_paddr =
  781. pdev->ipa_uc_tx_rsc.tx_comp_base.paddr;
  782. *tx_comp_ring_size =
  783. (uint32_t) ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev);
  784. *tx_num_alloc_buffer = (uint32_t) pdev->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
  785. *rx_rdy_ring_base_paddr =
  786. pdev->ipa_uc_rx_rsc.rx_ind_ring_base.paddr;
  787. *rx_rdy_ring_size = (uint32_t) pdev->ipa_uc_rx_rsc.rx_ind_ring_size;
  788. *rx_proc_done_idx_paddr =
  789. pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx.paddr;
  790. *rx_proc_done_idx_vaddr =
  791. (void *)pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx.vaddr;
  792. *rx2_rdy_ring_base_paddr =
  793. pdev->ipa_uc_rx_rsc.rx2_ind_ring_base.paddr;
  794. *rx2_rdy_ring_size = (uint32_t) pdev->ipa_uc_rx_rsc.rx2_ind_ring_size;
  795. *rx2_proc_done_idx_paddr =
  796. pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx.paddr;
  797. *rx2_proc_done_idx_vaddr =
  798. (void *)pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx.vaddr;
  799. /* Get copy engine, bus resource */
  800. htc_ipa_get_ce_resource(pdev->htc_pdev,
  801. ce_sr_base_paddr,
  802. ce_sr_ring_size, ce_reg_paddr);
  803. return 0;
  804. }
  805. /**
  806. * htt_ipa_uc_set_doorbell_paddr() - Propagate IPA doorbell address
  807. * @pdev: handle to the HTT instance
  808. * @ipa_uc_tx_doorbell_paddr: TX doorbell base physical address
  809. * @ipa_uc_rx_doorbell_paddr: RX doorbell base physical address
  810. *
  811. * Return: 0 success
  812. */
  813. int
  814. htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,
  815. qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,
  816. qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)
  817. {
  818. pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr = ipa_uc_tx_doorbell_paddr;
  819. pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr = ipa_uc_rx_doorbell_paddr;
  820. return 0;
  821. }
  822. #endif /* IPA_OFFLOAD */
  823. /**
  824. * htt_mark_first_wakeup_packet() - set flag to indicate that
  825. * fw is compatible for marking first packet after wow wakeup
  826. * @pdev: pointer to htt pdev
  827. * @value: 1 for enabled/ 0 for disabled
  828. *
  829. * Return: None
  830. */
  831. void htt_mark_first_wakeup_packet(htt_pdev_handle pdev,
  832. uint8_t value)
  833. {
  834. if (!pdev) {
  835. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  836. "%s: htt pdev is NULL", __func__);
  837. return;
  838. }
  839. pdev->cfg.is_first_wakeup_packet = value;
  840. }