htt.c 25 KB

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