htt.c 25 KB

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