htt.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /*
  2. * Copyright (c) 2011, 2014-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * @file htt.c
  20. * @brief Provide functions to create+init and destroy a HTT instance.
  21. * @details
  22. * This file contains functions for creating a HTT instance; initializing
  23. * the HTT instance, e.g. by allocating a pool of HTT tx descriptors and
  24. * connecting the HTT service with HTC; and deleting a HTT instance.
  25. */
  26. #include <qdf_mem.h> /* qdf_mem_malloc */
  27. #include <qdf_types.h> /* qdf_device_t, qdf_print */
  28. #include <htt.h> /* htt_tx_msdu_desc_t */
  29. #include <ol_cfg.h>
  30. #include <ol_txrx_htt_api.h> /* ol_tx_dowload_done_ll, etc. */
  31. #include <ol_htt_api.h>
  32. #include <htt_internal.h>
  33. #include <ol_htt_tx_api.h>
  34. #include <cds_api.h>
  35. #include "hif.h"
  36. #include <cdp_txrx_handle.h>
  37. #define HTT_HTC_PKT_POOL_INIT_SIZE 100 /* enough for a large A-MPDU */
  38. QDF_STATUS(*htt_h2t_rx_ring_cfg_msg)(struct htt_pdev_t *pdev);
  39. QDF_STATUS(*htt_h2t_rx_ring_rfs_cfg_msg)(struct htt_pdev_t *pdev);
  40. #ifdef IPA_OFFLOAD
  41. static QDF_STATUS htt_ipa_config(htt_pdev_handle pdev, QDF_STATUS status)
  42. {
  43. if ((QDF_STATUS_SUCCESS == status) &&
  44. ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
  45. status = htt_h2t_ipa_uc_rsc_cfg_msg(pdev);
  46. return status;
  47. }
  48. #define HTT_IPA_CONFIG htt_ipa_config
  49. #else
  50. #define HTT_IPA_CONFIG(pdev, status) status /* no-op */
  51. #endif /* IPA_OFFLOAD */
  52. struct htt_htc_pkt *htt_htc_pkt_alloc(struct htt_pdev_t *pdev)
  53. {
  54. struct htt_htc_pkt_union *pkt = NULL;
  55. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  56. if (pdev->htt_htc_pkt_freelist) {
  57. pkt = pdev->htt_htc_pkt_freelist;
  58. pdev->htt_htc_pkt_freelist = pdev->htt_htc_pkt_freelist->u.next;
  59. }
  60. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  61. if (pkt == NULL)
  62. pkt = qdf_mem_malloc(sizeof(*pkt));
  63. if (!pkt) {
  64. qdf_print("%s: HTC packet allocation failed\n", __func__);
  65. return NULL;
  66. }
  67. htc_packet_set_magic_cookie(&(pkt->u.pkt.htc_pkt), 0);
  68. return &pkt->u.pkt; /* not actually a dereference */
  69. }
  70. void htt_htc_pkt_free(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
  71. {
  72. struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
  73. if (!u_pkt) {
  74. qdf_print("%s: HTC packet is NULL\n", __func__);
  75. return;
  76. }
  77. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  78. htc_packet_set_magic_cookie(&(u_pkt->u.pkt.htc_pkt), 0);
  79. u_pkt->u.next = pdev->htt_htc_pkt_freelist;
  80. pdev->htt_htc_pkt_freelist = u_pkt;
  81. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  82. }
  83. void htt_htc_pkt_pool_free(struct htt_pdev_t *pdev)
  84. {
  85. struct htt_htc_pkt_union *pkt, *next;
  86. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  87. pkt = pdev->htt_htc_pkt_freelist;
  88. pdev->htt_htc_pkt_freelist = NULL;
  89. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  90. while (pkt) {
  91. next = pkt->u.next;
  92. qdf_mem_free(pkt);
  93. pkt = next;
  94. }
  95. }
  96. #ifdef ATH_11AC_TXCOMPACT
  97. void
  98. htt_htc_misc_pkt_list_trim(struct htt_pdev_t *pdev, int level)
  99. {
  100. struct htt_htc_pkt_union *pkt, *next, *prev = NULL;
  101. int i = 0;
  102. qdf_nbuf_t netbuf;
  103. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  104. pkt = pdev->htt_htc_pkt_misclist;
  105. while (pkt) {
  106. next = pkt->u.next;
  107. /* trim the out grown list*/
  108. if (++i > level) {
  109. netbuf =
  110. (qdf_nbuf_t)(pkt->u.pkt.htc_pkt.pNetBufContext);
  111. qdf_nbuf_unmap(pdev->osdev, netbuf, QDF_DMA_TO_DEVICE);
  112. qdf_nbuf_free(netbuf);
  113. qdf_mem_free(pkt);
  114. pkt = NULL;
  115. if (prev)
  116. prev->u.next = NULL;
  117. }
  118. prev = pkt;
  119. pkt = next;
  120. }
  121. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  122. }
  123. void htt_htc_misc_pkt_list_add(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
  124. {
  125. struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
  126. int misclist_trim_level = htc_get_tx_queue_depth(pdev->htc_pdev,
  127. pkt->htc_pkt.Endpoint)
  128. + HTT_HTC_PKT_MISCLIST_SIZE;
  129. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  130. if (pdev->htt_htc_pkt_misclist) {
  131. u_pkt->u.next = pdev->htt_htc_pkt_misclist;
  132. pdev->htt_htc_pkt_misclist = u_pkt;
  133. } else {
  134. pdev->htt_htc_pkt_misclist = u_pkt;
  135. }
  136. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  137. /* only ce pipe size + tx_queue_depth could possibly be in use
  138. * free older packets in the msiclist
  139. */
  140. htt_htc_misc_pkt_list_trim(pdev, misclist_trim_level);
  141. }
  142. void htt_htc_misc_pkt_pool_free(struct htt_pdev_t *pdev)
  143. {
  144. struct htt_htc_pkt_union *pkt, *next;
  145. qdf_nbuf_t netbuf;
  146. HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
  147. pkt = pdev->htt_htc_pkt_misclist;
  148. pdev->htt_htc_pkt_misclist = NULL;
  149. HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
  150. while (pkt) {
  151. next = pkt->u.next;
  152. if (htc_packet_get_magic_cookie(&(pkt->u.pkt.htc_pkt)) !=
  153. HTC_PACKET_MAGIC_COOKIE) {
  154. QDF_ASSERT(0);
  155. pkt = next;
  156. continue;
  157. }
  158. netbuf = (qdf_nbuf_t) (pkt->u.pkt.htc_pkt.pNetBufContext);
  159. qdf_nbuf_unmap(pdev->osdev, netbuf, QDF_DMA_TO_DEVICE);
  160. qdf_nbuf_free(netbuf);
  161. qdf_mem_free(pkt);
  162. pkt = next;
  163. }
  164. }
  165. #endif
  166. /* AR6004 don't need HTT layer. */
  167. #ifdef AR6004_HW
  168. #define NO_HTT_NEEDED true
  169. #else
  170. #define NO_HTT_NEEDED false
  171. #endif
  172. #if defined(QCA_TX_HTT2_SUPPORT) && defined(CONFIG_HL_SUPPORT)
  173. /**
  174. * htt_htc_tx_htt2_service_start() - Start TX HTT2 service
  175. *
  176. * @pdev: pointer to htt device.
  177. * @connect_req: pointer to service connection request information
  178. * @connect_resp: pointer to service connection response information
  179. *
  180. *
  181. * Return: None
  182. */
  183. static void
  184. htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
  185. struct htc_service_connect_req *connect_req,
  186. struct htc_service_connect_resp *connect_resp)
  187. {
  188. QDF_STATUS status;
  189. qdf_mem_set(connect_req, 0, sizeof(struct htc_service_connect_req));
  190. qdf_mem_set(connect_resp, 0, sizeof(struct htc_service_connect_resp));
  191. /* The same as HTT service but no RX. */
  192. connect_req->EpCallbacks.pContext = pdev;
  193. connect_req->EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  194. connect_req->EpCallbacks.EpSendFull = htt_h2t_full;
  195. connect_req->MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  196. /* Should NOT support credit flow control. */
  197. connect_req->ConnectionFlags |=
  198. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  199. /* Enable HTC schedule mechanism for TX HTT2 service. */
  200. connect_req->ConnectionFlags |= HTC_CONNECT_FLAGS_ENABLE_HTC_SCHEDULE;
  201. connect_req->service_id = HTT_DATA2_MSG_SVC;
  202. status = htc_connect_service(pdev->htc_pdev, connect_req, connect_resp);
  203. if (status != QDF_STATUS_SUCCESS) {
  204. pdev->htc_tx_htt2_endpoint = ENDPOINT_UNUSED;
  205. pdev->htc_tx_htt2_max_size = 0;
  206. } else {
  207. pdev->htc_tx_htt2_endpoint = connect_resp->Endpoint;
  208. pdev->htc_tx_htt2_max_size = HTC_TX_HTT2_MAX_SIZE;
  209. }
  210. qdf_print("TX HTT %s, ep %d size %d\n",
  211. (status == QDF_STATUS_SUCCESS ? "ON" : "OFF"),
  212. pdev->htc_tx_htt2_endpoint,
  213. pdev->htc_tx_htt2_max_size);
  214. }
  215. #else
  216. static inline void
  217. htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
  218. struct htc_service_connect_req *connect_req,
  219. struct htc_service_connect_resp *connect_resp)
  220. {
  221. }
  222. #endif
  223. /**
  224. * htt_htc_credit_flow_disable() - disable flow control for
  225. * HTT data message service
  226. *
  227. * @pdev: pointer to htt device.
  228. * @connect_req: pointer to service connection request information
  229. *
  230. * HTC Credit mechanism is disabled based on
  231. * default_tx_comp_req as throughput will be lower
  232. * if we disable htc credit mechanism with default_tx_comp_req
  233. * set since txrx download packet will be limited by ota
  234. * completion.
  235. *
  236. * Return: None
  237. */
  238. static
  239. void htt_htc_credit_flow_disable(struct htt_pdev_t *pdev,
  240. struct htc_service_connect_req *connect_req)
  241. {
  242. if (pdev->osdev->bus_type == QDF_BUS_TYPE_SDIO) {
  243. /*
  244. * TODO:Conditional disabling will be removed once firmware
  245. * with reduced tx completion is pushed into release builds.
  246. */
  247. if (!pdev->cfg.default_tx_comp_req)
  248. connect_req->ConnectionFlags |=
  249. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  250. } else {
  251. connect_req->ConnectionFlags |=
  252. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  253. }
  254. }
  255. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  256. /**
  257. * htt_dump_bundle_stats() - dump wlan stats
  258. * @pdev: handle to the HTT instance
  259. *
  260. * Return: None
  261. */
  262. void htt_dump_bundle_stats(htt_pdev_handle pdev)
  263. {
  264. htc_dump_bundle_stats(pdev->htc_pdev);
  265. }
  266. /**
  267. * htt_clear_bundle_stats() - clear wlan stats
  268. * @pdev: handle to the HTT instance
  269. *
  270. * Return: None
  271. */
  272. void htt_clear_bundle_stats(htt_pdev_handle pdev)
  273. {
  274. htc_clear_bundle_stats(pdev->htc_pdev);
  275. }
  276. #endif
  277. #if defined(QCA_WIFI_3_0_ADRASTEA)
  278. /**
  279. * htt_htc_attach_all() - Connect to HTC service for HTT
  280. * @pdev: pdev ptr
  281. *
  282. * Return: 0 for success or error code.
  283. */
  284. #if defined(QCN7605_SUPPORT) && defined(IPA_OFFLOAD)
  285. /* In case of QCN7605 with IPA offload only 2 CE
  286. * are used for RFS
  287. */
  288. static int
  289. htt_htc_attach_all(struct htt_pdev_t *pdev)
  290. {
  291. if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
  292. goto flush_endpoint;
  293. if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
  294. goto flush_endpoint;
  295. return 0;
  296. flush_endpoint:
  297. htc_flush_endpoint(pdev->htc_pdev, ENDPOINT_0, HTC_TX_PACKET_TAG_ALL);
  298. return -EIO;
  299. }
  300. #else
  301. static int
  302. htt_htc_attach_all(struct htt_pdev_t *pdev)
  303. {
  304. if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
  305. goto flush_endpoint;
  306. if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
  307. goto flush_endpoint;
  308. if (htt_htc_attach(pdev, HTT_DATA3_MSG_SVC))
  309. goto flush_endpoint;
  310. return 0;
  311. flush_endpoint:
  312. htc_flush_endpoint(pdev->htc_pdev, ENDPOINT_0, HTC_TX_PACKET_TAG_ALL);
  313. return -EIO;
  314. }
  315. #endif
  316. #else
  317. /**
  318. * htt_htc_attach_all() - Connect to HTC service for HTT
  319. * @pdev: pdev ptr
  320. *
  321. * Return: 0 for success or error code.
  322. */
  323. static int
  324. htt_htc_attach_all(struct htt_pdev_t *pdev)
  325. {
  326. return htt_htc_attach(pdev, HTT_DATA_MSG_SVC);
  327. }
  328. #endif
  329. /**
  330. * htt_pdev_alloc() - allocate HTT pdev
  331. * @txrx_pdev: txrx pdev
  332. * @ctrl_pdev: cfg pdev
  333. * @htc_pdev: HTC pdev
  334. * @osdev: os device
  335. *
  336. * Return: HTT pdev handle
  337. */
  338. htt_pdev_handle
  339. htt_pdev_alloc(ol_txrx_pdev_handle txrx_pdev,
  340. struct cdp_cfg *ctrl_pdev,
  341. HTC_HANDLE htc_pdev, qdf_device_t osdev)
  342. {
  343. struct htt_pdev_t *pdev;
  344. struct hif_opaque_softc *osc = cds_get_context(QDF_MODULE_ID_HIF);
  345. if (!osc)
  346. goto fail1;
  347. pdev = qdf_mem_malloc(sizeof(*pdev));
  348. if (!pdev)
  349. goto fail1;
  350. pdev->osdev = osdev;
  351. pdev->ctrl_pdev = ctrl_pdev;
  352. pdev->txrx_pdev = txrx_pdev;
  353. pdev->htc_pdev = htc_pdev;
  354. pdev->htt_htc_pkt_freelist = NULL;
  355. #ifdef ATH_11AC_TXCOMPACT
  356. pdev->htt_htc_pkt_misclist = NULL;
  357. #endif
  358. /* for efficiency, store a local copy of the is_high_latency flag */
  359. pdev->cfg.is_high_latency = ol_cfg_is_high_latency(pdev->ctrl_pdev);
  360. /*
  361. * Credit reporting through HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND
  362. * enabled or not.
  363. */
  364. pdev->cfg.credit_update_enabled =
  365. ol_cfg_is_credit_update_enabled(pdev->ctrl_pdev);
  366. pdev->cfg.request_tx_comp = cds_is_ptp_rx_opt_enabled() ||
  367. cds_is_packet_log_enabled();
  368. pdev->cfg.default_tx_comp_req =
  369. !ol_cfg_tx_free_at_download(pdev->ctrl_pdev);
  370. pdev->cfg.is_full_reorder_offload =
  371. ol_cfg_is_full_reorder_offload(pdev->ctrl_pdev);
  372. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  373. "full_reorder_offloaded %d",
  374. (int)pdev->cfg.is_full_reorder_offload);
  375. pdev->cfg.ce_classify_enabled =
  376. ol_cfg_is_ce_classify_enabled(ctrl_pdev);
  377. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  378. "ce_classify %d",
  379. pdev->cfg.ce_classify_enabled);
  380. if (pdev->cfg.is_high_latency) {
  381. qdf_atomic_init(&pdev->htt_tx_credit.target_delta);
  382. qdf_atomic_init(&pdev->htt_tx_credit.bus_delta);
  383. qdf_atomic_add(HTT_MAX_BUS_CREDIT,
  384. &pdev->htt_tx_credit.bus_delta);
  385. }
  386. pdev->targetdef = htc_get_targetdef(htc_pdev);
  387. #if defined(HELIUMPLUS)
  388. HTT_SET_WIFI_IP(pdev, 2, 0);
  389. #endif /* defined(HELIUMPLUS) */
  390. if (NO_HTT_NEEDED)
  391. goto success;
  392. /*
  393. * Connect to HTC service.
  394. * This has to be done before calling htt_rx_attach,
  395. * since htt_rx_attach involves sending a rx ring configure
  396. * message to the target.
  397. */
  398. HTT_TX_MUTEX_INIT(&pdev->htt_tx_mutex);
  399. HTT_TX_NBUF_QUEUE_MUTEX_INIT(pdev);
  400. HTT_TX_MUTEX_INIT(&pdev->credit_mutex);
  401. if (htt_htc_attach_all(pdev))
  402. goto htt_htc_attach_fail;
  403. if (hif_ce_fastpath_cb_register(osc, htt_t2h_msg_handler_fast, pdev))
  404. qdf_print("failed to register fastpath callback\n");
  405. success:
  406. return pdev;
  407. htt_htc_attach_fail:
  408. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  409. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  410. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  411. qdf_mem_free(pdev);
  412. fail1:
  413. return NULL;
  414. }
  415. /**
  416. * htt_attach() - Allocate and setup HTT TX/RX descriptors
  417. * @pdev: pdev ptr
  418. * @desc_pool_size: size of tx descriptors
  419. *
  420. * Return: 0 for success or error code.
  421. */
  422. int
  423. htt_attach(struct htt_pdev_t *pdev, int desc_pool_size)
  424. {
  425. int i;
  426. int ret = 0;
  427. pdev->is_ipa_uc_enabled = false;
  428. if (ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
  429. pdev->is_ipa_uc_enabled = true;
  430. ret = htt_tx_attach(pdev, desc_pool_size);
  431. if (ret)
  432. goto fail1;
  433. ret = htt_rx_attach(pdev);
  434. if (ret)
  435. goto fail2;
  436. /* pre-allocate some HTC_PACKET objects */
  437. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  438. struct htt_htc_pkt_union *pkt;
  439. pkt = qdf_mem_malloc(sizeof(*pkt));
  440. if (!pkt)
  441. break;
  442. htt_htc_pkt_free(pdev, &pkt->u.pkt);
  443. }
  444. if (pdev->cfg.is_high_latency) {
  445. /*
  446. * HL - download the whole frame.
  447. * Specify a download length greater than the max MSDU size,
  448. * so the downloads will be limited by the actual frame sizes.
  449. */
  450. pdev->download_len = 5000;
  451. if (ol_cfg_tx_free_at_download(pdev->ctrl_pdev) &&
  452. !pdev->cfg.request_tx_comp)
  453. pdev->tx_send_complete_part2 =
  454. ol_tx_download_done_hl_free;
  455. else
  456. pdev->tx_send_complete_part2 =
  457. ol_tx_download_done_hl_retain;
  458. /*
  459. * CHECK THIS LATER: does the HL HTT version of
  460. * htt_rx_mpdu_desc_list_next
  461. * (which is not currently implemented) present the
  462. * adf_nbuf_data(rx_ind_msg)
  463. * as the abstract rx descriptor?
  464. * If not, the rx_fw_desc_offset initialization
  465. * here will have to be adjusted accordingly.
  466. * NOTE: for HL, because fw rx desc is in ind msg,
  467. * not in rx desc, so the
  468. * offset should be negtive value
  469. */
  470. pdev->rx_fw_desc_offset =
  471. HTT_ENDIAN_BYTE_IDX_SWAP(
  472. HTT_RX_IND_FW_RX_DESC_BYTE_OFFSET
  473. - HTT_RX_IND_HL_BYTES);
  474. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_hl;
  475. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_hl;
  476. /* initialize the txrx credit count */
  477. ol_tx_target_credit_update(
  478. pdev->txrx_pdev, ol_cfg_target_tx_credit(
  479. pdev->ctrl_pdev));
  480. } else {
  481. enum wlan_frm_fmt frm_type;
  482. /*
  483. * LL - download just the initial portion of the frame.
  484. * Download enough to cover the encapsulation headers checked
  485. * by the target's tx classification descriptor engine.
  486. *
  487. * For LL, the FW rx desc directly referenced at its location
  488. * inside the rx indication message.
  489. */
  490. /* account for the 802.3 or 802.11 header */
  491. frm_type = ol_cfg_frame_type(pdev->ctrl_pdev);
  492. if (frm_type == wlan_frm_fmt_native_wifi) {
  493. pdev->download_len = HTT_TX_HDR_SIZE_NATIVE_WIFI;
  494. } else if (frm_type == wlan_frm_fmt_802_3) {
  495. pdev->download_len = HTT_TX_HDR_SIZE_ETHERNET;
  496. } else {
  497. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  498. "Unexpected frame type spec: %d", frm_type);
  499. HTT_ASSERT0(0);
  500. }
  501. /*
  502. * Account for the optional L2 / ethernet header fields:
  503. * 802.1Q, LLC/SNAP
  504. */
  505. pdev->download_len +=
  506. HTT_TX_HDR_SIZE_802_1Q + HTT_TX_HDR_SIZE_LLC_SNAP;
  507. /*
  508. * Account for the portion of the L3 (IP) payload that the
  509. * target needs for its tx classification.
  510. */
  511. pdev->download_len += ol_cfg_tx_download_size(pdev->ctrl_pdev);
  512. /*
  513. * Account for the HTT tx descriptor, including the
  514. * HTC header + alignment padding.
  515. */
  516. pdev->download_len += sizeof(struct htt_host_tx_desc_t);
  517. /*
  518. * The TXCOMPACT htt_tx_sched function uses pdev->download_len
  519. * to apply for all requeued tx frames. Thus,
  520. * pdev->download_len has to be the largest download length of
  521. * any tx frame that will be downloaded.
  522. * This maximum download length is for management tx frames,
  523. * which have an 802.11 header.
  524. */
  525. #ifdef ATH_11AC_TXCOMPACT
  526. pdev->download_len = sizeof(struct htt_host_tx_desc_t)
  527. + HTT_TX_HDR_SIZE_OUTER_HDR_MAX /* worst case */
  528. + HTT_TX_HDR_SIZE_802_1Q
  529. + HTT_TX_HDR_SIZE_LLC_SNAP
  530. + ol_cfg_tx_download_size(pdev->ctrl_pdev);
  531. #endif
  532. pdev->tx_send_complete_part2 = ol_tx_download_done_ll;
  533. /*
  534. * For LL, the FW rx desc is alongside the HW rx desc fields in
  535. * the htt_host_rx_desc_base struct/.
  536. */
  537. pdev->rx_fw_desc_offset = RX_STD_DESC_FW_MSDU_OFFSET;
  538. htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_ll;
  539. htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_ll;
  540. }
  541. return 0;
  542. fail2:
  543. htt_tx_detach(pdev);
  544. fail1:
  545. return ret;
  546. }
  547. QDF_STATUS htt_attach_target(htt_pdev_handle pdev)
  548. {
  549. QDF_STATUS status;
  550. status = htt_h2t_ver_req_msg(pdev);
  551. if (status != QDF_STATUS_SUCCESS) {
  552. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  553. "%s:%d: could not send h2t_ver_req msg",
  554. __func__, __LINE__);
  555. return status;
  556. }
  557. #if defined(HELIUMPLUS)
  558. /*
  559. * Send the frag_desc info to target.
  560. */
  561. status = htt_h2t_frag_desc_bank_cfg_msg(pdev);
  562. if (status != QDF_STATUS_SUCCESS) {
  563. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  564. "%s:%d: could not send h2t_frag_desc_bank_cfg msg",
  565. __func__, __LINE__);
  566. return status;
  567. }
  568. #endif /* defined(HELIUMPLUS) */
  569. /*
  570. * If applicable, send the rx ring config message to the target.
  571. * The host could wait for the HTT version number confirmation message
  572. * from the target before sending any further HTT messages, but it's
  573. * reasonable to assume that the host and target HTT version numbers
  574. * match, and proceed immediately with the remaining configuration
  575. * handshaking.
  576. */
  577. status = htt_h2t_rx_ring_rfs_cfg_msg(pdev);
  578. if (status != QDF_STATUS_SUCCESS) {
  579. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  580. "%s:%d: could not send h2t_rx_ring_rfs_cfg msg",
  581. __func__, __LINE__);
  582. return status;
  583. }
  584. status = htt_h2t_rx_ring_cfg_msg(pdev);
  585. if (status != QDF_STATUS_SUCCESS) {
  586. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  587. "%s:%d: could not send h2t_rx_ring_cfg msg",
  588. __func__, __LINE__);
  589. return status;
  590. }
  591. status = HTT_IPA_CONFIG(pdev, status);
  592. if (status != QDF_STATUS_SUCCESS) {
  593. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  594. "%s:%d: could not send h2t_ipa_uc_rsc_cfg msg",
  595. __func__, __LINE__);
  596. return status;
  597. }
  598. return status;
  599. }
  600. void htt_detach(htt_pdev_handle pdev)
  601. {
  602. htt_rx_detach(pdev);
  603. htt_tx_detach(pdev);
  604. htt_htc_pkt_pool_free(pdev);
  605. #ifdef ATH_11AC_TXCOMPACT
  606. htt_htc_misc_pkt_pool_free(pdev);
  607. #endif
  608. HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
  609. HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
  610. HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
  611. }
  612. /**
  613. * htt_pdev_free() - Free HTT pdev
  614. * @pdev: htt pdev
  615. *
  616. * Return: none
  617. */
  618. void htt_pdev_free(htt_pdev_handle pdev)
  619. {
  620. qdf_mem_free(pdev);
  621. }
  622. void htt_detach_target(htt_pdev_handle pdev)
  623. {
  624. }
  625. static inline
  626. int htt_update_endpoint(struct htt_pdev_t *pdev,
  627. uint16_t service_id, HTC_ENDPOINT_ID ep)
  628. {
  629. struct hif_opaque_softc *hif_ctx;
  630. uint8_t ul = 0xff, dl = 0xff;
  631. int ul_polled, dl_polled;
  632. int tx_service = 0;
  633. int rc = 0;
  634. hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
  635. if (qdf_unlikely(NULL == hif_ctx)) {
  636. QDF_ASSERT(NULL != hif_ctx);
  637. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  638. "%s:%d: assuming non-tx service.",
  639. __func__, __LINE__);
  640. } else {
  641. ul = dl = 0xff;
  642. if (QDF_STATUS_SUCCESS !=
  643. hif_map_service_to_pipe(hif_ctx, service_id,
  644. &ul, &dl,
  645. &ul_polled, &dl_polled))
  646. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
  647. "%s:%d: assuming non-tx srv.",
  648. __func__, __LINE__);
  649. else
  650. tx_service = (ul != 0xff);
  651. }
  652. if (tx_service) {
  653. /* currently we have only one OUT htt tx service */
  654. QDF_BUG(service_id == HTT_DATA_MSG_SVC);
  655. pdev->htc_tx_endpoint = ep;
  656. hif_save_htc_htt_config_endpoint(hif_ctx, ep);
  657. rc = 1;
  658. }
  659. return rc;
  660. }
  661. int htt_htc_attach(struct htt_pdev_t *pdev, uint16_t service_id)
  662. {
  663. struct htc_service_connect_req connect;
  664. struct htc_service_connect_resp response;
  665. QDF_STATUS status;
  666. qdf_mem_set(&connect, sizeof(connect), 0);
  667. qdf_mem_set(&response, sizeof(response), 0);
  668. connect.pMetaData = NULL;
  669. connect.MetaDataLength = 0;
  670. connect.EpCallbacks.pContext = pdev;
  671. connect.EpCallbacks.EpTxComplete = htt_h2t_send_complete;
  672. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  673. connect.EpCallbacks.EpRecv = htt_t2h_msg_handler;
  674. connect.EpCallbacks.ep_resume_tx_queue = htt_tx_resume_handler;
  675. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  676. connect.EpCallbacks.EpRecvRefill = NULL;
  677. connect.EpCallbacks.RecvRefillWaterMark = 1;
  678. /* N/A, fill is done by HIF */
  679. connect.EpCallbacks.EpSendFull = htt_h2t_full;
  680. /*
  681. * Specify how deep to let a queue get before htc_send_pkt will
  682. * call the EpSendFull function due to excessive send queue depth.
  683. */
  684. connect.MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
  685. /* disable flow control for HTT data message service */
  686. htt_htc_credit_flow_disable(pdev, &connect);
  687. /* connect to control service */
  688. connect.service_id = service_id;
  689. status = htc_connect_service(pdev->htc_pdev, &connect, &response);
  690. if (status != QDF_STATUS_SUCCESS) {
  691. if (cds_is_fw_down())
  692. return -EIO;
  693. if (status == QDF_STATUS_E_NOMEM ||
  694. cds_is_self_recovery_enabled())
  695. return qdf_status_to_os_return(status);
  696. QDF_BUG(0);
  697. }
  698. htt_update_endpoint(pdev, service_id, response.Endpoint);
  699. /* Start TX HTT2 service if the target support it. */
  700. htt_htc_tx_htt2_service_start(pdev, &connect, &response);
  701. return 0; /* success */
  702. }
  703. void htt_log_rx_ring_info(htt_pdev_handle pdev)
  704. {
  705. if (!pdev) {
  706. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  707. "%s: htt pdev is NULL", __func__);
  708. return;
  709. }
  710. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG,
  711. "%s: Data Stall Detected with reason 4 (=FW_RX_REFILL_FAILED)."
  712. "src htt rx ring: space for %d elements, filled with %d buffers, buffers in the ring %d, refill debt %d",
  713. __func__, pdev->rx_ring.size, pdev->rx_ring.fill_level,
  714. pdev->rx_ring.fill_cnt,
  715. qdf_atomic_read(&pdev->rx_ring.refill_debt));
  716. }
  717. #if HTT_DEBUG_LEVEL > 5
  718. void htt_display(htt_pdev_handle pdev, int indent)
  719. {
  720. qdf_print("%*s%s:\n", indent, " ", "HTT");
  721. qdf_print("%*stx desc pool: %d elems of %d bytes, %d allocated\n",
  722. indent + 4, " ",
  723. pdev->tx_descs.pool_elems,
  724. pdev->tx_descs.size, pdev->tx_descs.alloc_cnt);
  725. qdf_print("%*srx ring: space for %d elems, filled with %d buffers\n",
  726. indent + 4, " ",
  727. pdev->rx_ring.size, pdev->rx_ring.fill_level);
  728. qdf_print("%*sat %pK (%llx paddr)\n", indent + 8, " ",
  729. pdev->rx_ring.buf.paddrs_ring,
  730. (unsigned long long)pdev->rx_ring.base_paddr);
  731. qdf_print("%*snetbuf ring @ %pK\n", indent + 8, " ",
  732. pdev->rx_ring.buf.netbufs_ring);
  733. qdf_print("%*sFW_IDX shadow register: vaddr = %pK, paddr = %llx\n",
  734. indent + 8, " ",
  735. pdev->rx_ring.alloc_idx.vaddr,
  736. (unsigned long long)pdev->rx_ring.alloc_idx.paddr);
  737. qdf_print("%*sSW enqueue idx= %d, SW dequeue idx: desc= %d, buf= %d\n",
  738. indent + 8, " ", *pdev->rx_ring.alloc_idx.vaddr,
  739. pdev->rx_ring.sw_rd_idx.msdu_desc,
  740. pdev->rx_ring.sw_rd_idx.msdu_payld);
  741. }
  742. #endif
  743. #ifdef IPA_OFFLOAD
  744. /**
  745. * htt_ipa_uc_attach() - Allocate UC data path resources
  746. * @pdev: handle to the HTT instance
  747. *
  748. * Return: 0 success
  749. * none 0 fail
  750. */
  751. int htt_ipa_uc_attach(struct htt_pdev_t *pdev)
  752. {
  753. int error;
  754. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
  755. __func__);
  756. /* TX resource attach */
  757. error = htt_tx_ipa_uc_attach(
  758. pdev,
  759. ol_cfg_ipa_uc_tx_buf_size(pdev->ctrl_pdev),
  760. ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev),
  761. ol_cfg_ipa_uc_tx_partition_base(pdev->ctrl_pdev));
  762. if (error) {
  763. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  764. "HTT IPA UC TX attach fail code %d", error);
  765. HTT_ASSERT0(0);
  766. return error;
  767. }
  768. /* RX resource attach */
  769. error = htt_rx_ipa_uc_attach(
  770. pdev, qdf_get_pwr2(pdev->rx_ring.fill_level));
  771. if (error) {
  772. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  773. "HTT IPA UC RX attach fail code %d", error);
  774. htt_tx_ipa_uc_detach(pdev);
  775. HTT_ASSERT0(0);
  776. return error;
  777. }
  778. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
  779. __func__);
  780. return 0; /* success */
  781. }
  782. /**
  783. * htt_ipa_uc_attach() - Remove UC data path resources
  784. * @pdev: handle to the HTT instance
  785. *
  786. * Return: None
  787. */
  788. void htt_ipa_uc_detach(struct htt_pdev_t *pdev)
  789. {
  790. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
  791. __func__);
  792. /* TX IPA micro controller detach */
  793. htt_tx_ipa_uc_detach(pdev);
  794. /* RX IPA micro controller detach */
  795. htt_rx_ipa_uc_detach(pdev);
  796. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
  797. __func__);
  798. }
  799. int
  800. htt_ipa_uc_get_resource(htt_pdev_handle pdev,
  801. qdf_shared_mem_t **ce_sr,
  802. qdf_shared_mem_t **tx_comp_ring,
  803. qdf_shared_mem_t **rx_rdy_ring,
  804. qdf_shared_mem_t **rx2_rdy_ring,
  805. qdf_shared_mem_t **rx_proc_done_idx,
  806. qdf_shared_mem_t **rx2_proc_done_idx,
  807. uint32_t *ce_sr_ring_size,
  808. qdf_dma_addr_t *ce_reg_paddr,
  809. uint32_t *tx_num_alloc_buffer)
  810. {
  811. /* Release allocated resource to client */
  812. *tx_comp_ring = pdev->ipa_uc_tx_rsc.tx_comp_ring;
  813. *rx_rdy_ring = pdev->ipa_uc_rx_rsc.rx_ind_ring;
  814. *rx2_rdy_ring = pdev->ipa_uc_rx_rsc.rx2_ind_ring;
  815. *rx_proc_done_idx = pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx;
  816. *rx2_proc_done_idx = pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx;
  817. *tx_num_alloc_buffer = (uint32_t)pdev->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
  818. /* Get copy engine, bus resource */
  819. htc_ipa_get_ce_resource(pdev->htc_pdev, ce_sr,
  820. ce_sr_ring_size, ce_reg_paddr);
  821. return 0;
  822. }
  823. /**
  824. * htt_ipa_uc_set_doorbell_paddr() - Propagate IPA doorbell address
  825. * @pdev: handle to the HTT instance
  826. * @ipa_uc_tx_doorbell_paddr: TX doorbell base physical address
  827. * @ipa_uc_rx_doorbell_paddr: RX doorbell base physical address
  828. *
  829. * Return: 0 success
  830. */
  831. int
  832. htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,
  833. qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,
  834. qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)
  835. {
  836. pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr = ipa_uc_tx_doorbell_paddr;
  837. pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr = ipa_uc_rx_doorbell_paddr;
  838. return 0;
  839. }
  840. #endif /* IPA_OFFLOAD */
  841. /**
  842. * htt_mark_first_wakeup_packet() - set flag to indicate that
  843. * fw is compatible for marking first packet after wow wakeup
  844. * @pdev: pointer to htt pdev
  845. * @value: 1 for enabled/ 0 for disabled
  846. *
  847. * Return: None
  848. */
  849. void htt_mark_first_wakeup_packet(htt_pdev_handle pdev,
  850. uint8_t value)
  851. {
  852. if (!pdev) {
  853. QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
  854. "%s: htt pdev is NULL", __func__);
  855. return;
  856. }
  857. pdev->cfg.is_first_wakeup_packet = value;
  858. }