htt.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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_print("is_full_reorder_offloaded? %d\n",
  310. (int)pdev->cfg.is_full_reorder_offload);
  311. pdev->cfg.ce_classify_enabled =
  312. ol_cfg_is_ce_classify_enabled(ctrl_pdev);
  313. qdf_print("ce_classify_enabled %d\n",
  314. pdev->cfg.ce_classify_enabled);
  315. if (pdev->cfg.is_high_latency) {
  316. qdf_atomic_init(&pdev->htt_tx_credit.target_delta);
  317. qdf_atomic_init(&pdev->htt_tx_credit.bus_delta);
  318. qdf_atomic_add(HTT_MAX_BUS_CREDIT,
  319. &pdev->htt_tx_credit.bus_delta);
  320. }
  321. pdev->targetdef = htc_get_targetdef(htc_pdev);
  322. #if defined(HELIUMPLUS)
  323. HTT_SET_WIFI_IP(pdev, 2, 0);
  324. #endif /* defined(HELIUMPLUS) */
  325. if (NO_HTT_NEEDED)
  326. goto success;
  327. /*
  328. * Connect to HTC service.
  329. * This has to be done before calling htt_rx_attach,
  330. * since htt_rx_attach involves sending a rx ring configure
  331. * message to the target.
  332. */
  333. if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
  334. goto fail2;
  335. if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
  336. ;
  337. /* TODO: enable the following line once FW is ready */
  338. /* goto fail2; */
  339. if (htt_htc_attach(pdev, HTT_DATA3_MSG_SVC))
  340. ;
  341. /* TODO: enable the following line once FW is ready */
  342. /* goto fail2; */
  343. if (hif_ce_fastpath_cb_register(osc, htt_t2h_msg_handler_fast, pdev))
  344. qdf_print("failed to register fastpath callback\n");
  345. success:
  346. return pdev;
  347. fail2:
  348. qdf_mem_free(pdev);
  349. fail1:
  350. return NULL;
  351. }
  352. /**
  353. * htt_attach() - Allocate and setup HTT TX/RX descriptors
  354. * @pdev: pdev ptr
  355. * @desc_pool_size: size of tx descriptors
  356. *
  357. * Return: 0 for success or error code.
  358. */
  359. int
  360. htt_attach(struct htt_pdev_t *pdev, int desc_pool_size)
  361. {
  362. int i;
  363. int ret = 0;
  364. ret = htt_tx_attach(pdev, desc_pool_size);
  365. if (ret)
  366. goto fail1;
  367. ret = htt_rx_attach(pdev);
  368. if (ret)
  369. goto fail2;
  370. HTT_TX_MUTEX_INIT(&pdev->htt_tx_mutex);
  371. HTT_TX_NBUF_QUEUE_MUTEX_INIT(pdev);
  372. /* pre-allocate some HTC_PACKET objects */
  373. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  374. struct htt_htc_pkt_union *pkt;
  375. pkt = qdf_mem_malloc(sizeof(*pkt));
  376. if (!pkt)
  377. break;
  378. htt_htc_pkt_free(pdev, &pkt->u.pkt);
  379. }
  380. if (pdev->cfg.is_high_latency) {
  381. /*
  382. * HL - download the whole frame.
  383. * Specify a download length greater than the max MSDU size,
  384. * so the downloads will be limited by the actual frame sizes.
  385. */
  386. pdev->download_len = 5000;
  387. if (ol_cfg_tx_free_at_download(pdev->ctrl_pdev))
  388. pdev->tx_send_complete_part2 =
  389. ol_tx_download_done_hl_free;
  390. else
  391. pdev->tx_send_complete_part2 =
  392. ol_tx_download_done_hl_retain;
  393. /*
  394. * CHECK THIS LATER: does the HL HTT version of
  395. * htt_rx_mpdu_desc_list_next
  396. * (which is not currently implemented) present the
  397. * adf_nbuf_data(rx_ind_msg)
  398. * as the abstract rx descriptor?
  399. * If not, the rx_fw_desc_offset initialization
  400. * here will have to be adjusted accordingly.
  401. * NOTE: for HL, because fw rx desc is in ind msg,
  402. * not in rx desc, so the
  403. * offset should be negtive value
  404. */
  405. pdev->rx_fw_desc_offset =
  406. HTT_ENDIAN_BYTE_IDX_SWAP(
  407. HTT_RX_IND_FW_RX_DESC_BYTE_OFFSET
  408. - HTT_RX_IND_HL_BYTES);
  409. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_hl;
  410. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_hl;
  411. /* initialize the txrx credit count */
  412. ol_tx_target_credit_update(
  413. pdev->txrx_pdev, ol_cfg_target_tx_credit(
  414. pdev->ctrl_pdev));
  415. } else {
  416. enum wlan_frm_fmt frm_type;
  417. /*
  418. * LL - download just the initial portion of the frame.
  419. * Download enough to cover the encapsulation headers checked
  420. * by the target's tx classification descriptor engine.
  421. *
  422. * For LL, the FW rx desc directly referenced at its location
  423. * inside the rx indication message.
  424. */
  425. /* account for the 802.3 or 802.11 header */
  426. frm_type = ol_cfg_frame_type(pdev->ctrl_pdev);
  427. if (frm_type == wlan_frm_fmt_native_wifi) {
  428. pdev->download_len = HTT_TX_HDR_SIZE_NATIVE_WIFI;
  429. } else if (frm_type == wlan_frm_fmt_802_3) {
  430. pdev->download_len = HTT_TX_HDR_SIZE_ETHERNET;
  431. } else {
  432. qdf_print("Unexpected frame type spec: %d\n", frm_type);
  433. HTT_ASSERT0(0);
  434. }
  435. /*
  436. * Account for the optional L2 / ethernet header fields:
  437. * 802.1Q, LLC/SNAP
  438. */
  439. pdev->download_len +=
  440. HTT_TX_HDR_SIZE_802_1Q + HTT_TX_HDR_SIZE_LLC_SNAP;
  441. /*
  442. * Account for the portion of the L3 (IP) payload that the
  443. * target needs for its tx classification.
  444. */
  445. pdev->download_len += ol_cfg_tx_download_size(pdev->ctrl_pdev);
  446. /*
  447. * Account for the HTT tx descriptor, including the
  448. * HTC header + alignment padding.
  449. */
  450. pdev->download_len += sizeof(struct htt_host_tx_desc_t);
  451. /*
  452. * The TXCOMPACT htt_tx_sched function uses pdev->download_len
  453. * to apply for all requeued tx frames. Thus,
  454. * pdev->download_len has to be the largest download length of
  455. * any tx frame that will be downloaded.
  456. * This maximum download length is for management tx frames,
  457. * which have an 802.11 header.
  458. */
  459. #ifdef ATH_11AC_TXCOMPACT
  460. pdev->download_len = sizeof(struct htt_host_tx_desc_t)
  461. + HTT_TX_HDR_SIZE_OUTER_HDR_MAX /* worst case */
  462. + HTT_TX_HDR_SIZE_802_1Q
  463. + HTT_TX_HDR_SIZE_LLC_SNAP
  464. + ol_cfg_tx_download_size(pdev->ctrl_pdev);
  465. #endif
  466. pdev->tx_send_complete_part2 = ol_tx_download_done_ll;
  467. /*
  468. * For LL, the FW rx desc is alongside the HW rx desc fields in
  469. * the htt_host_rx_desc_base struct/.
  470. */
  471. pdev->rx_fw_desc_offset = RX_STD_DESC_FW_MSDU_OFFSET;
  472. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_ll;
  473. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_ll;
  474. }
  475. return 0;
  476. fail2:
  477. htt_tx_detach(pdev);
  478. fail1:
  479. return ret;
  480. }
  481. A_STATUS htt_attach_target(htt_pdev_handle pdev)
  482. {
  483. A_STATUS status;
  484. status = htt_h2t_ver_req_msg(pdev);
  485. if (status != A_OK)
  486. return status;
  487. #if defined(HELIUMPLUS)
  488. /*
  489. * Send the frag_desc info to target.
  490. */
  491. htt_h2t_frag_desc_bank_cfg_msg(pdev);
  492. #endif /* defined(HELIUMPLUS) */
  493. /*
  494. * If applicable, send the rx ring config message to the target.
  495. * The host could wait for the HTT version number confirmation message
  496. * from the target before sending any further HTT messages, but it's
  497. * reasonable to assume that the host and target HTT version numbers
  498. * match, and proceed immediately with the remaining configuration
  499. * handshaking.
  500. */
  501. status = htt_h2t_rx_ring_rfs_cfg_msg(pdev);
  502. status = htt_h2t_rx_ring_cfg_msg(pdev);
  503. status = HTT_IPA_CONFIG(pdev, status);
  504. return status;
  505. }
  506. void htt_detach(htt_pdev_handle pdev)
  507. {
  508. htt_rx_detach(pdev);
  509. htt_tx_detach(pdev);
  510. htt_htc_pkt_pool_free(pdev);
  511. #ifdef ATH_11AC_TXCOMPACT
  512. htt_htc_misc_pkt_pool_free(pdev);
  513. #endif
  514. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  515. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  516. htt_rx_dbg_rxbuf_deinit(pdev);
  517. }
  518. /**
  519. * htt_pdev_free() - Free HTT pdev
  520. * @pdev: htt pdev
  521. *
  522. * Return: none
  523. */
  524. void htt_pdev_free(htt_pdev_handle pdev)
  525. {
  526. qdf_mem_free(pdev);
  527. }
  528. void htt_detach_target(htt_pdev_handle pdev)
  529. {
  530. }
  531. static inline
  532. int htt_update_endpoint(struct htt_pdev_t *pdev,
  533. uint16_t service_id, HTC_ENDPOINT_ID ep)
  534. {
  535. struct hif_opaque_softc *hif_ctx;
  536. uint8_t ul = 0xff, dl = 0xff;
  537. int ul_polled, dl_polled;
  538. int tx_service = 0;
  539. int rc = 0;
  540. hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
  541. if (qdf_unlikely(NULL == hif_ctx)) {
  542. QDF_ASSERT(NULL != hif_ctx);
  543. qdf_print("%s:%d: assuming non-tx service.",
  544. __func__, __LINE__);
  545. } else {
  546. ul = dl = 0xff;
  547. if (QDF_STATUS_SUCCESS !=
  548. hif_map_service_to_pipe(hif_ctx, service_id,
  549. &ul, &dl,
  550. &ul_polled, &dl_polled))
  551. qdf_print("%s:%d: assuming non-tx srv.",
  552. __func__, __LINE__);
  553. else
  554. tx_service = (ul != 0xff);
  555. }
  556. if (tx_service) {
  557. /* currently we have only one OUT htt tx service */
  558. QDF_BUG(service_id == HTT_DATA_MSG_SVC);
  559. pdev->htc_tx_endpoint = ep;
  560. hif_save_htc_htt_config_endpoint(hif_ctx, ep);
  561. rc = 1;
  562. }
  563. return rc;
  564. }
  565. int htt_htc_attach(struct htt_pdev_t *pdev, uint16_t service_id)
  566. {
  567. HTC_SERVICE_CONNECT_REQ connect;
  568. HTC_SERVICE_CONNECT_RESP response;
  569. A_STATUS status;
  570. qdf_mem_set(&connect, sizeof(connect), 0);
  571. qdf_mem_set(&response, sizeof(response), 0);
  572. connect.pMetaData = NULL;
  573. connect.MetaDataLength = 0;
  574. connect.EpCallbacks.pContext = pdev;
  575. connect.EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  576. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  577. connect.EpCallbacks.EpRecv = htt_t2h_msg_handler;
  578. connect.EpCallbacks.ep_resume_tx_queue = htt_tx_resume_handler;
  579. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  580. connect.EpCallbacks.EpRecvRefill = NULL;
  581. connect.EpCallbacks.RecvRefillWaterMark = 1;
  582. /* N/A, fill is done by HIF */
  583. connect.EpCallbacks.EpSendFull = htt_h2t_full;
  584. /*
  585. * Specify how deep to let a queue get before htc_send_pkt will
  586. * call the EpSendFull function due to excessive send queue depth.
  587. */
  588. connect.MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  589. /* disable flow control for HTT data message service */
  590. htt_htc_credit_flow_disable(pdev, &connect);
  591. /* connect to control service */
  592. connect.service_id = service_id;
  593. status = htc_connect_service(pdev->htc_pdev, &connect, &response);
  594. if (status != A_OK)
  595. return -EIO; /* failure */
  596. htt_update_endpoint(pdev, service_id, response.Endpoint);
  597. /* Start TX HTT2 service if the target support it. */
  598. htt_htc_tx_htt2_service_start(pdev, &connect, &response);
  599. return 0; /* success */
  600. }
  601. #if HTT_DEBUG_LEVEL > 5
  602. void htt_display(htt_pdev_handle pdev, int indent)
  603. {
  604. qdf_print("%*s%s:\n", indent, " ", "HTT");
  605. qdf_print("%*stx desc pool: %d elems of %d bytes, %d allocated\n",
  606. indent + 4, " ",
  607. pdev->tx_descs.pool_elems,
  608. pdev->tx_descs.size, pdev->tx_descs.alloc_cnt);
  609. qdf_print("%*srx ring: space for %d elems, filled with %d buffers\n",
  610. indent + 4, " ",
  611. pdev->rx_ring.size, pdev->rx_ring.fill_level);
  612. qdf_print("%*sat %p (%llx paddr)\n", indent + 8, " ",
  613. pdev->rx_ring.buf.paddrs_ring,
  614. (unsigned long long)pdev->rx_ring.base_paddr);
  615. qdf_print("%*snetbuf ring @ %p\n", indent + 8, " ",
  616. pdev->rx_ring.buf.netbufs_ring);
  617. qdf_print("%*sFW_IDX shadow register: vaddr = %p, paddr = %llx\n",
  618. indent + 8, " ",
  619. pdev->rx_ring.alloc_idx.vaddr,
  620. (unsigned long long)pdev->rx_ring.alloc_idx.paddr);
  621. qdf_print("%*sSW enqueue idx= %d, SW dequeue idx: desc= %d, buf= %d\n",
  622. indent + 8, " ", *pdev->rx_ring.alloc_idx.vaddr,
  623. pdev->rx_ring.sw_rd_idx.msdu_desc,
  624. pdev->rx_ring.sw_rd_idx.msdu_payld);
  625. }
  626. #endif
  627. #ifdef IPA_OFFLOAD
  628. /**
  629. * htt_ipa_uc_attach() - Allocate UC data path resources
  630. * @pdev: handle to the HTT instance
  631. *
  632. * Return: 0 success
  633. * none 0 fail
  634. */
  635. int htt_ipa_uc_attach(struct htt_pdev_t *pdev)
  636. {
  637. int error;
  638. /* TX resource attach */
  639. error = htt_tx_ipa_uc_attach(
  640. pdev,
  641. ol_cfg_ipa_uc_tx_buf_size(pdev->ctrl_pdev),
  642. ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev),
  643. ol_cfg_ipa_uc_tx_partition_base(pdev->ctrl_pdev));
  644. if (error) {
  645. qdf_print("HTT IPA UC TX attach fail code %d\n", error);
  646. HTT_ASSERT0(0);
  647. return error;
  648. }
  649. /* RX resource attach */
  650. error = htt_rx_ipa_uc_attach(
  651. pdev, qdf_get_pwr2(pdev->rx_ring.fill_level));
  652. if (error) {
  653. qdf_print("HTT IPA UC RX attach fail code %d\n", error);
  654. htt_tx_ipa_uc_detach(pdev);
  655. HTT_ASSERT0(0);
  656. return error;
  657. }
  658. return 0; /* success */
  659. }
  660. /**
  661. * htt_ipa_uc_attach() - Remove UC data path resources
  662. * @pdev: handle to the HTT instance
  663. *
  664. * Return: None
  665. */
  666. void htt_ipa_uc_detach(struct htt_pdev_t *pdev)
  667. {
  668. /* TX IPA micro controller detach */
  669. htt_tx_ipa_uc_detach(pdev);
  670. /* RX IPA micro controller detach */
  671. htt_rx_ipa_uc_detach(pdev);
  672. }
  673. /**
  674. * htt_ipa_uc_get_resource() - Get uc resource from htt and lower layer
  675. * @pdev: handle to the HTT instance
  676. * @ce_sr_base_paddr: copy engine source ring base physical address
  677. * @ce_sr_ring_size: copy engine source ring size
  678. * @ce_reg_paddr: copy engine register physical address
  679. * @tx_comp_ring_base_paddr: tx comp ring base physical address
  680. * @tx_comp_ring_size: tx comp ring size
  681. * @tx_num_alloc_buffer: number of allocated tx buffer
  682. * @rx_rdy_ring_base_paddr: rx ready ring base physical address
  683. * @rx_rdy_ring_size: rx ready ring size
  684. * @rx_proc_done_idx_paddr: rx process done index physical address
  685. * @rx_proc_done_idx_vaddr: rx process done index virtual address
  686. * @rx2_rdy_ring_base_paddr: rx done ring base physical address
  687. * @rx2_rdy_ring_size: rx done ring size
  688. * @rx2_proc_done_idx_paddr: rx done index physical address
  689. * @rx2_proc_done_idx_vaddr: rx done index virtual address
  690. *
  691. * Return: 0 success
  692. */
  693. int
  694. htt_ipa_uc_get_resource(htt_pdev_handle pdev,
  695. qdf_dma_addr_t *ce_sr_base_paddr,
  696. uint32_t *ce_sr_ring_size,
  697. qdf_dma_addr_t *ce_reg_paddr,
  698. qdf_dma_addr_t *tx_comp_ring_base_paddr,
  699. uint32_t *tx_comp_ring_size,
  700. uint32_t *tx_num_alloc_buffer,
  701. qdf_dma_addr_t *rx_rdy_ring_base_paddr,
  702. uint32_t *rx_rdy_ring_size,
  703. qdf_dma_addr_t *rx_proc_done_idx_paddr,
  704. void **rx_proc_done_idx_vaddr,
  705. qdf_dma_addr_t *rx2_rdy_ring_base_paddr,
  706. uint32_t *rx2_rdy_ring_size,
  707. qdf_dma_addr_t *rx2_proc_done_idx_paddr,
  708. void **rx2_proc_done_idx_vaddr)
  709. {
  710. /* Release allocated resource to client */
  711. *tx_comp_ring_base_paddr =
  712. pdev->ipa_uc_tx_rsc.tx_comp_base.paddr;
  713. *tx_comp_ring_size =
  714. (uint32_t) ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev);
  715. *tx_num_alloc_buffer = (uint32_t) pdev->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
  716. *rx_rdy_ring_base_paddr =
  717. pdev->ipa_uc_rx_rsc.rx_ind_ring_base.paddr;
  718. *rx_rdy_ring_size = (uint32_t) pdev->ipa_uc_rx_rsc.rx_ind_ring_size;
  719. *rx_proc_done_idx_paddr =
  720. pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx.paddr;
  721. *rx_proc_done_idx_vaddr =
  722. (void *)pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx.vaddr;
  723. *rx2_rdy_ring_base_paddr =
  724. pdev->ipa_uc_rx_rsc.rx2_ind_ring_base.paddr;
  725. *rx2_rdy_ring_size = (uint32_t) pdev->ipa_uc_rx_rsc.rx2_ind_ring_size;
  726. *rx2_proc_done_idx_paddr =
  727. pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx.paddr;
  728. *rx2_proc_done_idx_vaddr =
  729. (void *)pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx.vaddr;
  730. /* Get copy engine, bus resource */
  731. htc_ipa_get_ce_resource(pdev->htc_pdev,
  732. ce_sr_base_paddr,
  733. ce_sr_ring_size, ce_reg_paddr);
  734. return 0;
  735. }
  736. /**
  737. * htt_ipa_uc_set_doorbell_paddr() - Propagate IPA doorbell address
  738. * @pdev: handle to the HTT instance
  739. * @ipa_uc_tx_doorbell_paddr: TX doorbell base physical address
  740. * @ipa_uc_rx_doorbell_paddr: RX doorbell base physical address
  741. *
  742. * Return: 0 success
  743. */
  744. int
  745. htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,
  746. qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,
  747. qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)
  748. {
  749. pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr = ipa_uc_tx_doorbell_paddr;
  750. pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr = ipa_uc_rx_doorbell_paddr;
  751. return 0;
  752. }
  753. #endif /* IPA_OFFLOAD */
  754. /**
  755. * htt_mark_first_wakeup_packet() - set flag to indicate that
  756. * fw is compatible for marking first packet after wow wakeup
  757. * @pdev: pointer to htt pdev
  758. * @value: 1 for enabled/ 0 for disabled
  759. *
  760. * Return: None
  761. */
  762. void htt_mark_first_wakeup_packet(htt_pdev_handle pdev,
  763. uint8_t value)
  764. {
  765. if (!pdev) {
  766. qdf_print("%s: htt pdev is NULL", __func__);
  767. return;
  768. }
  769. pdev->cfg.is_first_wakeup_packet = value;
  770. }