htt.c 23 KB

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