htt.c 25 KB

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