htt.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. /*
  2. * Copyright (c) 2011, 2014-2016 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. #define HTT_HTC_PKT_POOL_INIT_SIZE 100 /* enough for a large A-MPDU */
  45. QDF_STATUS(*htt_h2t_rx_ring_cfg_msg)(struct htt_pdev_t *pdev);
  46. #ifdef IPA_OFFLOAD
  47. A_STATUS htt_ipa_config(htt_pdev_handle pdev, A_STATUS status)
  48. {
  49. if ((A_OK == status) &&
  50. ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
  51. status = htt_h2t_ipa_uc_rsc_cfg_msg(pdev);
  52. return status;
  53. }
  54. #define HTT_IPA_CONFIG htt_ipa_config
  55. #else
  56. #define HTT_IPA_CONFIG(pdev, status) status /* no-op */
  57. #endif /* IPA_OFFLOAD */
  58. struct htt_htc_pkt *htt_htc_pkt_alloc(struct htt_pdev_t *pdev)
  59. {
  60. struct htt_htc_pkt_union *pkt = NULL;
  61. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  62. if (pdev->htt_htc_pkt_freelist) {
  63. pkt = pdev->htt_htc_pkt_freelist;
  64. pdev->htt_htc_pkt_freelist = pdev->htt_htc_pkt_freelist->u.next;
  65. }
  66. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  67. if (pkt == NULL)
  68. pkt = qdf_mem_malloc(sizeof(*pkt));
  69. return &pkt->u.pkt; /* not actually a dereference */
  70. }
  71. void htt_htc_pkt_free(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
  72. {
  73. struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
  74. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  75. u_pkt->u.next = pdev->htt_htc_pkt_freelist;
  76. pdev->htt_htc_pkt_freelist = u_pkt;
  77. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  78. }
  79. void htt_htc_pkt_pool_free(struct htt_pdev_t *pdev)
  80. {
  81. struct htt_htc_pkt_union *pkt, *next;
  82. pkt = pdev->htt_htc_pkt_freelist;
  83. while (pkt) {
  84. next = pkt->u.next;
  85. qdf_mem_free(pkt);
  86. pkt = next;
  87. }
  88. pdev->htt_htc_pkt_freelist = NULL;
  89. }
  90. #ifdef ATH_11AC_TXCOMPACT
  91. void htt_htc_misc_pkt_list_add(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
  92. {
  93. struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
  94. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  95. if (pdev->htt_htc_pkt_misclist) {
  96. u_pkt->u.next = pdev->htt_htc_pkt_misclist;
  97. pdev->htt_htc_pkt_misclist = u_pkt;
  98. } else {
  99. pdev->htt_htc_pkt_misclist = u_pkt;
  100. }
  101. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  102. }
  103. void htt_htc_misc_pkt_pool_free(struct htt_pdev_t *pdev)
  104. {
  105. struct htt_htc_pkt_union *pkt, *next;
  106. qdf_nbuf_t netbuf;
  107. pkt = pdev->htt_htc_pkt_misclist;
  108. while (pkt) {
  109. next = pkt->u.next;
  110. netbuf = (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 = next;
  115. }
  116. pdev->htt_htc_pkt_misclist = NULL;
  117. }
  118. #endif
  119. /* AR6004 don't need HTT layer. */
  120. #ifdef AR6004_HW
  121. #define NO_HTT_NEEDED true
  122. #else
  123. #define NO_HTT_NEEDED false
  124. #endif
  125. #if defined(QCA_TX_HTT2_SUPPORT) && defined(CONFIG_HL_SUPPORT)
  126. /**
  127. * htt_htc_tx_htt2_service_start() - Start TX HTT2 service
  128. *
  129. * @pdev: pointer to htt device.
  130. * @connect_req: pointer to service connection request information
  131. * @connect_resp: pointer to service connection response information
  132. *
  133. *
  134. * Return: None
  135. */
  136. static void
  137. htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
  138. HTC_SERVICE_CONNECT_REQ *connect_req,
  139. HTC_SERVICE_CONNECT_RESP *connect_resp)
  140. {
  141. A_STATUS status;
  142. qdf_mem_set(connect_req, 0, sizeof(HTC_SERVICE_CONNECT_REQ));
  143. qdf_mem_set(connect_resp, 0, sizeof(HTC_SERVICE_CONNECT_RESP));
  144. /* The same as HTT service but no RX. */
  145. connect_req->EpCallbacks.pContext = pdev;
  146. connect_req->EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  147. connect_req->EpCallbacks.EpSendFull = htt_h2t_full;
  148. connect_req->MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  149. /* Should NOT support credit flow control. */
  150. connect_req->ConnectionFlags |=
  151. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  152. /* Enable HTC schedule mechanism for TX HTT2 service. */
  153. connect_req->ConnectionFlags |= HTC_CONNECT_FLAGS_ENABLE_HTC_SCHEDULE;
  154. connect_req->ServiceID = HTT_DATA2_MSG_SVC;
  155. status = htc_connect_service(pdev->htc_pdev, connect_req, connect_resp);
  156. if (status != A_OK) {
  157. pdev->htc_tx_htt2_endpoint = ENDPOINT_UNUSED;
  158. pdev->htc_tx_htt2_max_size = 0;
  159. } else {
  160. pdev->htc_tx_htt2_endpoint = connect_resp->Endpoint;
  161. pdev->htc_tx_htt2_max_size = HTC_TX_HTT2_MAX_SIZE;
  162. }
  163. qdf_print("TX HTT %s, ep %d size %d\n",
  164. (status == A_OK ? "ON" : "OFF"),
  165. pdev->htc_tx_htt2_endpoint,
  166. pdev->htc_tx_htt2_max_size);
  167. }
  168. #else
  169. static inline void
  170. htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
  171. HTC_SERVICE_CONNECT_REQ *connect_req,
  172. HTC_SERVICE_CONNECT_RESP *connect_resp)
  173. {
  174. return;
  175. }
  176. #endif
  177. /**
  178. * htt_htc_credit_flow_disable() - disable flow control for
  179. * HTT data message service
  180. *
  181. * @pdev: pointer to htt device.
  182. * @connect_req: pointer to service connection request information
  183. *
  184. * HTC Credit mechanism is disabled based on
  185. * default_tx_comp_req as throughput will be lower
  186. * if we disable htc credit mechanism with default_tx_comp_req
  187. * set since txrx download packet will be limited by ota
  188. * completion.
  189. *
  190. * Return: None
  191. */
  192. static
  193. void htt_htc_credit_flow_disable(struct htt_pdev_t *pdev,
  194. HTC_SERVICE_CONNECT_REQ *connect_req)
  195. {
  196. if (pdev->osdev->bus_type == QDF_BUS_TYPE_SDIO) {
  197. /*
  198. * TODO:Conditional disabling will be removed once firmware
  199. * with reduced tx completion is pushed into release builds.
  200. */
  201. if (!pdev->cfg.default_tx_comp_req)
  202. connect_req->ConnectionFlags |=
  203. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  204. } else {
  205. connect_req->ConnectionFlags |=
  206. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  207. }
  208. }
  209. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  210. /**
  211. * htt_dump_bundle_stats() - dump wlan stats
  212. * @pdev: handle to the HTT instance
  213. *
  214. * Return: None
  215. */
  216. void htt_dump_bundle_stats(htt_pdev_handle pdev)
  217. {
  218. htc_dump_bundle_stats(pdev->htc_pdev);
  219. }
  220. /**
  221. * htt_clear_bundle_stats() - clear wlan stats
  222. * @pdev: handle to the HTT instance
  223. *
  224. * Return: None
  225. */
  226. void htt_clear_bundle_stats(htt_pdev_handle pdev)
  227. {
  228. htc_clear_bundle_stats(pdev->htc_pdev);
  229. }
  230. #endif
  231. /**
  232. * htt_pdev_alloc() - allocate HTT pdev
  233. * @txrx_pdev: txrx pdev
  234. * @ctrl_pdev: cfg pdev
  235. * @htc_pdev: HTC pdev
  236. * @osdev: os device
  237. *
  238. * Return: HTT pdev handle
  239. */
  240. htt_pdev_handle
  241. htt_pdev_alloc(ol_txrx_pdev_handle txrx_pdev,
  242. ol_pdev_handle ctrl_pdev,
  243. HTC_HANDLE htc_pdev, qdf_device_t osdev)
  244. {
  245. struct htt_pdev_t *pdev;
  246. struct hif_opaque_softc *osc = cds_get_context(QDF_MODULE_ID_HIF);
  247. if (!osc)
  248. goto fail1;
  249. pdev = qdf_mem_malloc(sizeof(*pdev));
  250. if (!pdev)
  251. goto fail1;
  252. pdev->osdev = osdev;
  253. pdev->ctrl_pdev = ctrl_pdev;
  254. pdev->txrx_pdev = txrx_pdev;
  255. pdev->htc_pdev = htc_pdev;
  256. qdf_mem_set(&pdev->stats, sizeof(pdev->stats), 0);
  257. pdev->htt_htc_pkt_freelist = NULL;
  258. #ifdef ATH_11AC_TXCOMPACT
  259. pdev->htt_htc_pkt_misclist = NULL;
  260. #endif
  261. /* for efficiency, store a local copy of the is_high_latency flag */
  262. pdev->cfg.is_high_latency = ol_cfg_is_high_latency(pdev->ctrl_pdev);
  263. pdev->cfg.default_tx_comp_req =
  264. !ol_cfg_tx_free_at_download(pdev->ctrl_pdev);
  265. pdev->cfg.is_full_reorder_offload =
  266. ol_cfg_is_full_reorder_offload(pdev->ctrl_pdev);
  267. qdf_print("is_full_reorder_offloaded? %d\n",
  268. (int)pdev->cfg.is_full_reorder_offload);
  269. pdev->cfg.ce_classify_enabled =
  270. ol_cfg_is_ce_classify_enabled(ctrl_pdev);
  271. qdf_print("ce_classify_enabled %d\n",
  272. pdev->cfg.ce_classify_enabled);
  273. if (pdev->cfg.is_high_latency) {
  274. qdf_atomic_init(&pdev->htt_tx_credit.target_delta);
  275. qdf_atomic_init(&pdev->htt_tx_credit.bus_delta);
  276. qdf_atomic_add(HTT_MAX_BUS_CREDIT,
  277. &pdev->htt_tx_credit.bus_delta);
  278. }
  279. pdev->targetdef = htc_get_targetdef(htc_pdev);
  280. #if defined(HELIUMPLUS_PADDR64)
  281. /* TODO: OKA: Remove hard-coding */
  282. HTT_SET_WIFI_IP(pdev, 2, 0);
  283. #endif /* defined(HELIUMPLUS_PADDR64) */
  284. if (NO_HTT_NEEDED)
  285. goto success;
  286. /*
  287. * Connect to HTC service.
  288. * This has to be done before calling htt_rx_attach,
  289. * since htt_rx_attach involves sending a rx ring configure
  290. * message to the target.
  291. */
  292. if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
  293. goto fail2;
  294. if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
  295. ;
  296. /* TODO: enable the following line once FW is ready */
  297. /* goto fail2; */
  298. if (htt_htc_attach(pdev, HTT_DATA3_MSG_SVC))
  299. ;
  300. /* TODO: enable the following line once FW is ready */
  301. /* goto fail2; */
  302. if (hif_ce_fastpath_cb_register(osc, htt_t2h_msg_handler_fast, pdev))
  303. qdf_print("failed to register fastpath callback\n");
  304. success:
  305. return pdev;
  306. fail2:
  307. qdf_mem_free(pdev);
  308. fail1:
  309. return NULL;
  310. }
  311. /**
  312. * htt_attach() - Allocate and setup HTT TX/RX descriptors
  313. * @pdev: pdev ptr
  314. * @desc_pool_size: size of tx descriptors
  315. *
  316. * Return: 0 for success or error code.
  317. */
  318. int
  319. htt_attach(struct htt_pdev_t *pdev, int desc_pool_size)
  320. {
  321. int i;
  322. int ret = 0;
  323. ret = htt_tx_attach(pdev, desc_pool_size);
  324. if (ret)
  325. goto fail1;
  326. ret = htt_rx_attach(pdev);
  327. if (ret)
  328. goto fail2;
  329. HTT_TX_MUTEX_INIT(&pdev->htt_tx_mutex);
  330. HTT_TX_NBUF_QUEUE_MUTEX_INIT(pdev);
  331. /* pre-allocate some HTC_PACKET objects */
  332. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  333. struct htt_htc_pkt_union *pkt;
  334. pkt = qdf_mem_malloc(sizeof(*pkt));
  335. if (!pkt)
  336. break;
  337. htt_htc_pkt_free(pdev, &pkt->u.pkt);
  338. }
  339. if (pdev->cfg.is_high_latency) {
  340. /*
  341. * HL - download the whole frame.
  342. * Specify a download length greater than the max MSDU size,
  343. * so the downloads will be limited by the actual frame sizes.
  344. */
  345. pdev->download_len = 5000;
  346. if (ol_cfg_tx_free_at_download(pdev->ctrl_pdev))
  347. pdev->tx_send_complete_part2 =
  348. ol_tx_download_done_hl_free;
  349. else
  350. pdev->tx_send_complete_part2 =
  351. ol_tx_download_done_hl_retain;
  352. /*
  353. * CHECK THIS LATER: does the HL HTT version of
  354. * htt_rx_mpdu_desc_list_next
  355. * (which is not currently implemented) present the
  356. * adf_nbuf_data(rx_ind_msg)
  357. * as the abstract rx descriptor?
  358. * If not, the rx_fw_desc_offset initialization
  359. * here will have to be adjusted accordingly.
  360. * NOTE: for HL, because fw rx desc is in ind msg,
  361. * not in rx desc, so the
  362. * offset should be negtive value
  363. */
  364. pdev->rx_fw_desc_offset =
  365. HTT_ENDIAN_BYTE_IDX_SWAP(
  366. HTT_RX_IND_FW_RX_DESC_BYTE_OFFSET
  367. - HTT_RX_IND_HL_BYTES);
  368. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_hl;
  369. /* initialize the txrx credit count */
  370. ol_tx_target_credit_update(
  371. pdev->txrx_pdev, ol_cfg_target_tx_credit(
  372. pdev->ctrl_pdev));
  373. } else {
  374. enum wlan_frm_fmt frm_type;
  375. /*
  376. * LL - download just the initial portion of the frame.
  377. * Download enough to cover the encapsulation headers checked
  378. * by the target's tx classification descriptor engine.
  379. *
  380. * For LL, the FW rx desc directly referenced at its location
  381. * inside the rx indication message.
  382. */
  383. /* account for the 802.3 or 802.11 header */
  384. frm_type = ol_cfg_frame_type(pdev->ctrl_pdev);
  385. if (frm_type == wlan_frm_fmt_native_wifi) {
  386. pdev->download_len = HTT_TX_HDR_SIZE_NATIVE_WIFI;
  387. } else if (frm_type == wlan_frm_fmt_802_3) {
  388. pdev->download_len = HTT_TX_HDR_SIZE_ETHERNET;
  389. } else {
  390. qdf_print("Unexpected frame type spec: %d\n", frm_type);
  391. HTT_ASSERT0(0);
  392. }
  393. /*
  394. * Account for the optional L2 / ethernet header fields:
  395. * 802.1Q, LLC/SNAP
  396. */
  397. pdev->download_len +=
  398. HTT_TX_HDR_SIZE_802_1Q + HTT_TX_HDR_SIZE_LLC_SNAP;
  399. /*
  400. * Account for the portion of the L3 (IP) payload that the
  401. * target needs for its tx classification.
  402. */
  403. pdev->download_len += ol_cfg_tx_download_size(pdev->ctrl_pdev);
  404. /*
  405. * Account for the HTT tx descriptor, including the
  406. * HTC header + alignment padding.
  407. */
  408. pdev->download_len += sizeof(struct htt_host_tx_desc_t);
  409. /*
  410. * The TXCOMPACT htt_tx_sched function uses pdev->download_len
  411. * to apply for all requeued tx frames. Thus,
  412. * pdev->download_len has to be the largest download length of
  413. * any tx frame that will be downloaded.
  414. * This maximum download length is for management tx frames,
  415. * which have an 802.11 header.
  416. */
  417. #ifdef ATH_11AC_TXCOMPACT
  418. pdev->download_len = sizeof(struct htt_host_tx_desc_t)
  419. + HTT_TX_HDR_SIZE_OUTER_HDR_MAX /* worst case */
  420. + HTT_TX_HDR_SIZE_802_1Q
  421. + HTT_TX_HDR_SIZE_LLC_SNAP
  422. + ol_cfg_tx_download_size(pdev->ctrl_pdev);
  423. #endif
  424. pdev->tx_send_complete_part2 = ol_tx_download_done_ll;
  425. /*
  426. * For LL, the FW rx desc is alongside the HW rx desc fields in
  427. * the htt_host_rx_desc_base struct/.
  428. */
  429. pdev->rx_fw_desc_offset = RX_STD_DESC_FW_MSDU_OFFSET;
  430. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_ll;
  431. }
  432. return 0;
  433. fail2:
  434. htt_tx_detach(pdev);
  435. fail1:
  436. return ret;
  437. }
  438. A_STATUS htt_attach_target(htt_pdev_handle pdev)
  439. {
  440. A_STATUS status;
  441. status = htt_h2t_ver_req_msg(pdev);
  442. if (status != A_OK)
  443. return status;
  444. #if defined(HELIUMPLUS_PADDR64)
  445. /*
  446. * Send the frag_desc info to target.
  447. */
  448. htt_h2t_frag_desc_bank_cfg_msg(pdev);
  449. #endif /* defined(HELIUMPLUS_PADDR64) */
  450. /*
  451. * If applicable, send the rx ring config message to the target.
  452. * The host could wait for the HTT version number confirmation message
  453. * from the target before sending any further HTT messages, but it's
  454. * reasonable to assume that the host and target HTT version numbers
  455. * match, and proceed immediately with the remaining configuration
  456. * handshaking.
  457. */
  458. status = htt_h2t_rx_ring_cfg_msg(pdev);
  459. status = HTT_IPA_CONFIG(pdev, status);
  460. return status;
  461. }
  462. void htt_detach(htt_pdev_handle pdev)
  463. {
  464. htt_rx_detach(pdev);
  465. htt_tx_detach(pdev);
  466. htt_htc_pkt_pool_free(pdev);
  467. #ifdef ATH_11AC_TXCOMPACT
  468. htt_htc_misc_pkt_pool_free(pdev);
  469. #endif
  470. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  471. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  472. htt_rx_dbg_rxbuf_deinit(pdev);
  473. }
  474. /**
  475. * htt_pdev_free() - Free HTT pdev
  476. * @pdev: htt pdev
  477. *
  478. * Return: none
  479. */
  480. void htt_pdev_free(htt_pdev_handle pdev)
  481. {
  482. qdf_mem_free(pdev);
  483. }
  484. void htt_detach_target(htt_pdev_handle pdev)
  485. {
  486. }
  487. static inline
  488. int htt_update_endpoint(struct htt_pdev_t *pdev,
  489. uint16_t service_id, HTC_ENDPOINT_ID ep)
  490. {
  491. struct hif_opaque_softc *hif_ctx;
  492. uint8_t ul = 0xff, dl = 0xff;
  493. int ul_polled, dl_polled;
  494. int tx_service = 0;
  495. int rc = 0;
  496. hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
  497. if (qdf_unlikely(NULL == hif_ctx)) {
  498. QDF_ASSERT(NULL != hif_ctx);
  499. qdf_print("%s:%d: assuming non-tx service.",
  500. __func__, __LINE__);
  501. } else {
  502. ul = dl = 0xff;
  503. if (QDF_STATUS_SUCCESS !=
  504. hif_map_service_to_pipe(hif_ctx, service_id,
  505. &ul, &dl,
  506. &ul_polled, &dl_polled))
  507. qdf_print("%s:%d: assuming non-tx srv.",
  508. __func__, __LINE__);
  509. else
  510. tx_service = (ul != 0xff);
  511. }
  512. if (tx_service) {
  513. /* currently we have only one OUT htt tx service */
  514. QDF_BUG(service_id == HTT_DATA_MSG_SVC);
  515. pdev->htc_tx_endpoint = ep;
  516. hif_save_htc_htt_config_endpoint(hif_ctx, ep);
  517. rc = 1;
  518. }
  519. return rc;
  520. }
  521. int htt_htc_attach(struct htt_pdev_t *pdev, uint16_t service_id)
  522. {
  523. HTC_SERVICE_CONNECT_REQ connect;
  524. HTC_SERVICE_CONNECT_RESP response;
  525. A_STATUS status;
  526. qdf_mem_set(&connect, sizeof(connect), 0);
  527. qdf_mem_set(&response, sizeof(response), 0);
  528. connect.pMetaData = NULL;
  529. connect.MetaDataLength = 0;
  530. connect.EpCallbacks.pContext = pdev;
  531. connect.EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  532. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  533. connect.EpCallbacks.EpRecv = htt_t2h_msg_handler;
  534. connect.EpCallbacks.ep_resume_tx_queue = htt_tx_resume_handler;
  535. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  536. connect.EpCallbacks.EpRecvRefill = NULL;
  537. connect.EpCallbacks.RecvRefillWaterMark = 1;
  538. /* N/A, fill is done by HIF */
  539. connect.EpCallbacks.EpSendFull = htt_h2t_full;
  540. /*
  541. * Specify how deep to let a queue get before htc_send_pkt will
  542. * call the EpSendFull function due to excessive send queue depth.
  543. */
  544. connect.MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  545. /* disable flow control for HTT data message service */
  546. htt_htc_credit_flow_disable(pdev, &connect);
  547. /* connect to control service */
  548. connect.service_id = service_id;
  549. status = htc_connect_service(pdev->htc_pdev, &connect, &response);
  550. if (status != A_OK)
  551. return -EIO; /* failure */
  552. htt_update_endpoint(pdev, service_id, response.Endpoint);
  553. /* Start TX HTT2 service if the target support it. */
  554. htt_htc_tx_htt2_service_start(pdev, &connect, &response);
  555. return 0; /* success */
  556. }
  557. #if HTT_DEBUG_LEVEL > 5
  558. void htt_display(htt_pdev_handle pdev, int indent)
  559. {
  560. qdf_print("%*s%s:\n", indent, " ", "HTT");
  561. qdf_print("%*stx desc pool: %d elems of %d bytes, %d allocated\n",
  562. indent + 4, " ",
  563. pdev->tx_descs.pool_elems,
  564. pdev->tx_descs.size, pdev->tx_descs.alloc_cnt);
  565. qdf_print("%*srx ring: space for %d elems, filled with %d buffers\n",
  566. indent + 4, " ",
  567. pdev->rx_ring.size, pdev->rx_ring.fill_level);
  568. qdf_print("%*sat %p (%#x paddr)\n", indent + 8, " ",
  569. pdev->rx_ring.buf.paddrs_ring, pdev->rx_ring.base_paddr);
  570. qdf_print("%*snetbuf ring @ %p\n", indent + 8, " ",
  571. pdev->rx_ring.buf.netbufs_ring);
  572. qdf_print("%*sFW_IDX shadow register: vaddr = %p, paddr = %#x\n",
  573. indent + 8, " ",
  574. pdev->rx_ring.alloc_idx.vaddr, pdev->rx_ring.alloc_idx.paddr);
  575. qdf_print("%*sSW enqueue idx= %d, SW dequeue idx: desc= %d, buf= %d\n",
  576. indent + 8, " ", *pdev->rx_ring.alloc_idx.vaddr,
  577. pdev->rx_ring.sw_rd_idx.msdu_desc,
  578. pdev->rx_ring.sw_rd_idx.msdu_payld);
  579. }
  580. #endif
  581. #ifdef IPA_OFFLOAD
  582. /**
  583. * htt_ipa_uc_attach() - Allocate UC data path resources
  584. * @pdev: handle to the HTT instance
  585. *
  586. * Return: 0 success
  587. * none 0 fail
  588. */
  589. int htt_ipa_uc_attach(struct htt_pdev_t *pdev)
  590. {
  591. int error;
  592. /* TX resource attach */
  593. error = htt_tx_ipa_uc_attach(
  594. pdev,
  595. ol_cfg_ipa_uc_tx_buf_size(pdev->ctrl_pdev),
  596. ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev),
  597. ol_cfg_ipa_uc_tx_partition_base(pdev->ctrl_pdev));
  598. if (error) {
  599. qdf_print("HTT IPA UC TX attach fail code %d\n", error);
  600. HTT_ASSERT0(0);
  601. return error;
  602. }
  603. /* RX resource attach */
  604. error = htt_rx_ipa_uc_attach(
  605. pdev,
  606. ol_cfg_ipa_uc_rx_ind_ring_size(pdev->ctrl_pdev));
  607. if (error) {
  608. qdf_print("HTT IPA UC RX attach fail code %d\n", error);
  609. htt_tx_ipa_uc_detach(pdev);
  610. HTT_ASSERT0(0);
  611. return error;
  612. }
  613. return 0; /* success */
  614. }
  615. /**
  616. * htt_ipa_uc_attach() - Remove UC data path resources
  617. * @pdev: handle to the HTT instance
  618. *
  619. * Return: None
  620. */
  621. void htt_ipa_uc_detach(struct htt_pdev_t *pdev)
  622. {
  623. /* TX IPA micro controller detach */
  624. htt_tx_ipa_uc_detach(pdev);
  625. /* RX IPA micro controller detach */
  626. htt_rx_ipa_uc_detach(pdev);
  627. }
  628. /**
  629. * htt_ipa_uc_get_resource() - Get uc resource from htt and lower layer
  630. * @pdev: handle to the HTT instance
  631. * @ce_sr_base_paddr: copy engine source ring base physical address
  632. * @ce_sr_ring_size: copy engine source ring size
  633. * @ce_reg_paddr: copy engine register physical address
  634. * @tx_comp_ring_base_paddr: tx comp ring base physical address
  635. * @tx_comp_ring_size: tx comp ring size
  636. * @tx_num_alloc_buffer: number of allocated tx buffer
  637. * @rx_rdy_ring_base_paddr: rx ready ring base physical address
  638. * @rx_rdy_ring_size: rx ready ring size
  639. * @rx_proc_done_idx_paddr: rx process done index physical address
  640. * @rx_proc_done_idx_vaddr: rx process done index virtual address
  641. * @rx2_rdy_ring_base_paddr: rx done ring base physical address
  642. * @rx2_rdy_ring_size: rx done ring size
  643. * @rx2_proc_done_idx_paddr: rx done index physical address
  644. * @rx2_proc_done_idx_vaddr: rx done index virtual address
  645. *
  646. * Return: 0 success
  647. */
  648. int
  649. htt_ipa_uc_get_resource(htt_pdev_handle pdev,
  650. qdf_dma_addr_t *ce_sr_base_paddr,
  651. uint32_t *ce_sr_ring_size,
  652. qdf_dma_addr_t *ce_reg_paddr,
  653. qdf_dma_addr_t *tx_comp_ring_base_paddr,
  654. uint32_t *tx_comp_ring_size,
  655. uint32_t *tx_num_alloc_buffer,
  656. qdf_dma_addr_t *rx_rdy_ring_base_paddr,
  657. uint32_t *rx_rdy_ring_size,
  658. qdf_dma_addr_t *rx_proc_done_idx_paddr,
  659. void **rx_proc_done_idx_vaddr,
  660. qdf_dma_addr_t *rx2_rdy_ring_base_paddr,
  661. uint32_t *rx2_rdy_ring_size,
  662. qdf_dma_addr_t *rx2_proc_done_idx_paddr,
  663. void **rx2_proc_done_idx_vaddr)
  664. {
  665. /* Release allocated resource to client */
  666. *tx_comp_ring_base_paddr =
  667. pdev->ipa_uc_tx_rsc.tx_comp_base.paddr;
  668. *tx_comp_ring_size =
  669. (uint32_t) ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev);
  670. *tx_num_alloc_buffer = (uint32_t) pdev->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
  671. *rx_rdy_ring_base_paddr =
  672. pdev->ipa_uc_rx_rsc.rx_ind_ring_base.paddr;
  673. *rx_rdy_ring_size = (uint32_t) pdev->ipa_uc_rx_rsc.rx_ind_ring_size;
  674. *rx_proc_done_idx_paddr =
  675. pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx.paddr;
  676. *rx_proc_done_idx_vaddr =
  677. (void *)pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx.vaddr;
  678. *rx2_rdy_ring_base_paddr =
  679. pdev->ipa_uc_rx_rsc.rx2_ind_ring_base.paddr;
  680. *rx2_rdy_ring_size = (uint32_t) pdev->ipa_uc_rx_rsc.rx2_ind_ring_size;
  681. *rx2_proc_done_idx_paddr =
  682. pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx.paddr;
  683. *rx2_proc_done_idx_vaddr =
  684. (void *)pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx.vaddr;
  685. /* Get copy engine, bus resource */
  686. htc_ipa_get_ce_resource(pdev->htc_pdev,
  687. ce_sr_base_paddr,
  688. ce_sr_ring_size, ce_reg_paddr);
  689. return 0;
  690. }
  691. /**
  692. * htt_ipa_uc_set_doorbell_paddr() - Propagate IPA doorbell address
  693. * @pdev: handle to the HTT instance
  694. * @ipa_uc_tx_doorbell_paddr: TX doorbell base physical address
  695. * @ipa_uc_rx_doorbell_paddr: RX doorbell base physical address
  696. *
  697. * Return: 0 success
  698. */
  699. int
  700. htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,
  701. qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,
  702. qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)
  703. {
  704. pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr = ipa_uc_tx_doorbell_paddr;
  705. pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr = ipa_uc_rx_doorbell_paddr;
  706. return 0;
  707. }
  708. #endif /* IPA_OFFLOAD */