htt.c 23 KB

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