dp_ipa.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  1. /*
  2. * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifdef IPA_OFFLOAD
  17. #include <qdf_ipa_wdi3.h>
  18. #include <qdf_types.h>
  19. #include <qdf_lock.h>
  20. #include <hal_hw_headers.h>
  21. #include <hal_api.h>
  22. #include <hif.h>
  23. #include <htt.h>
  24. #include <wdi_event.h>
  25. #include <queue.h>
  26. #include "dp_types.h"
  27. #include "dp_htt.h"
  28. #include "dp_tx.h"
  29. #include "dp_rx.h"
  30. #include "dp_ipa.h"
  31. /* Hard coded config parameters until dp_ops_cfg.cfg_attach implemented */
  32. #define CFG_IPA_UC_TX_BUF_SIZE_DEFAULT (2048)
  33. /* WAR for IPA_OFFLOAD case. In some cases, its observed that WBM tries to
  34. * release a buffer into WBM2SW RELEASE ring for IPA, and the ring is full.
  35. * This causes back pressure, resulting in a FW crash.
  36. * By leaving some entries with no buffer attached, WBM will be able to write
  37. * to the ring, and from dumps we can figure out the buffer which is causing
  38. * this issue.
  39. */
  40. #define DP_IPA_WAR_WBM2SW_REL_RING_NO_BUF_ENTRIES 16
  41. /**
  42. *struct dp_ipa_reo_remap_record - history for dp ipa reo remaps
  43. * @ix0_reg: reo destination ring IX0 value
  44. * @ix2_reg: reo destination ring IX2 value
  45. * @ix3_reg: reo destination ring IX3 value
  46. */
  47. struct dp_ipa_reo_remap_record {
  48. uint64_t timestamp;
  49. uint32_t ix0_reg;
  50. uint32_t ix2_reg;
  51. uint32_t ix3_reg;
  52. };
  53. #define REO_REMAP_HISTORY_SIZE 32
  54. struct dp_ipa_reo_remap_record dp_ipa_reo_remap_history[REO_REMAP_HISTORY_SIZE];
  55. static qdf_atomic_t dp_ipa_reo_remap_history_index;
  56. static int dp_ipa_reo_remap_record_index_next(qdf_atomic_t *index)
  57. {
  58. int next = qdf_atomic_inc_return(index);
  59. if (next == REO_REMAP_HISTORY_SIZE)
  60. qdf_atomic_sub(REO_REMAP_HISTORY_SIZE, index);
  61. return next % REO_REMAP_HISTORY_SIZE;
  62. }
  63. /**
  64. * dp_ipa_reo_remap_history_add() - Record dp ipa reo remap values
  65. * @ix0_val: reo destination ring IX0 value
  66. * @ix2_val: reo destination ring IX2 value
  67. * @ix3_val: reo destination ring IX3 value
  68. *
  69. * Return: None
  70. */
  71. static void dp_ipa_reo_remap_history_add(uint32_t ix0_val, uint32_t ix2_val,
  72. uint32_t ix3_val)
  73. {
  74. int idx = dp_ipa_reo_remap_record_index_next(
  75. &dp_ipa_reo_remap_history_index);
  76. struct dp_ipa_reo_remap_record *record = &dp_ipa_reo_remap_history[idx];
  77. record->timestamp = qdf_get_log_timestamp();
  78. record->ix0_reg = ix0_val;
  79. record->ix2_reg = ix2_val;
  80. record->ix3_reg = ix3_val;
  81. }
  82. static QDF_STATUS __dp_ipa_handle_buf_smmu_mapping(struct dp_soc *soc,
  83. qdf_nbuf_t nbuf,
  84. bool create)
  85. {
  86. qdf_mem_info_t mem_map_table = {0};
  87. qdf_update_mem_map_table(soc->osdev, &mem_map_table,
  88. qdf_nbuf_get_frag_paddr(nbuf, 0),
  89. skb_end_pointer(nbuf) - nbuf->data);
  90. if (create)
  91. qdf_ipa_wdi_create_smmu_mapping(1, &mem_map_table);
  92. else
  93. qdf_ipa_wdi_release_smmu_mapping(1, &mem_map_table);
  94. return QDF_STATUS_SUCCESS;
  95. }
  96. QDF_STATUS dp_ipa_handle_rx_buf_smmu_mapping(struct dp_soc *soc,
  97. qdf_nbuf_t nbuf,
  98. bool create)
  99. {
  100. struct dp_pdev *pdev;
  101. int i;
  102. for (i = 0; i < soc->pdev_count; i++) {
  103. pdev = soc->pdev_list[i];
  104. if (pdev && pdev->monitor_configured)
  105. return QDF_STATUS_SUCCESS;
  106. }
  107. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx) ||
  108. !qdf_mem_smmu_s1_enabled(soc->osdev))
  109. return QDF_STATUS_SUCCESS;
  110. if (!qdf_atomic_read(&soc->ipa_pipes_enabled))
  111. return QDF_STATUS_SUCCESS;
  112. return __dp_ipa_handle_buf_smmu_mapping(soc, nbuf, create);
  113. }
  114. #ifdef RX_DESC_MULTI_PAGE_ALLOC
  115. static QDF_STATUS dp_ipa_handle_rx_buf_pool_smmu_mapping(struct dp_soc *soc,
  116. struct dp_pdev *pdev,
  117. bool create)
  118. {
  119. struct rx_desc_pool *rx_pool;
  120. uint8_t pdev_id;
  121. uint32_t num_desc, page_id, offset, i;
  122. uint16_t num_desc_per_page;
  123. union dp_rx_desc_list_elem_t *rx_desc_elem;
  124. struct dp_rx_desc *rx_desc;
  125. qdf_nbuf_t nbuf;
  126. if (!qdf_mem_smmu_s1_enabled(soc->osdev))
  127. return QDF_STATUS_SUCCESS;
  128. pdev_id = pdev->pdev_id;
  129. rx_pool = &soc->rx_desc_buf[pdev_id];
  130. qdf_spin_lock_bh(&rx_pool->lock);
  131. num_desc = rx_pool->pool_size;
  132. num_desc_per_page = rx_pool->desc_pages.num_element_per_page;
  133. for (i = 0; i < num_desc; i++) {
  134. page_id = i / num_desc_per_page;
  135. offset = i % num_desc_per_page;
  136. if (qdf_unlikely(!(rx_pool->desc_pages.cacheable_pages)))
  137. break;
  138. rx_desc_elem = dp_rx_desc_find(page_id, offset, rx_pool);
  139. rx_desc = &rx_desc_elem->rx_desc;
  140. if ((!(rx_desc->in_use)) || rx_desc->unmapped)
  141. continue;
  142. nbuf = rx_desc->nbuf;
  143. __dp_ipa_handle_buf_smmu_mapping(soc, nbuf, create);
  144. }
  145. qdf_spin_unlock_bh(&rx_pool->lock);
  146. return QDF_STATUS_SUCCESS;
  147. }
  148. #else
  149. static QDF_STATUS dp_ipa_handle_rx_buf_pool_smmu_mapping(struct dp_soc *soc,
  150. struct dp_pdev *pdev,
  151. bool create)
  152. {
  153. struct rx_desc_pool *rx_pool;
  154. uint8_t pdev_id;
  155. qdf_nbuf_t nbuf;
  156. int i;
  157. if (!qdf_mem_smmu_s1_enabled(soc->osdev))
  158. return QDF_STATUS_SUCCESS;
  159. pdev_id = pdev->pdev_id;
  160. rx_pool = &soc->rx_desc_buf[pdev_id];
  161. qdf_spin_lock_bh(&rx_pool->lock);
  162. for (i = 0; i < rx_pool->pool_size; i++) {
  163. if ((!(rx_pool->array[i].rx_desc.in_use)) ||
  164. rx_pool->array[i].rx_desc.unmapped)
  165. continue;
  166. nbuf = rx_pool->array[i].rx_desc.nbuf;
  167. __dp_ipa_handle_buf_smmu_mapping(soc, nbuf, create);
  168. }
  169. qdf_spin_unlock_bh(&rx_pool->lock);
  170. return QDF_STATUS_SUCCESS;
  171. }
  172. #endif /* RX_DESC_MULTI_PAGE_ALLOC */
  173. /**
  174. * dp_tx_ipa_uc_detach - Free autonomy TX resources
  175. * @soc: data path instance
  176. * @pdev: core txrx pdev context
  177. *
  178. * Free allocated TX buffers with WBM SRNG
  179. *
  180. * Return: none
  181. */
  182. static void dp_tx_ipa_uc_detach(struct dp_soc *soc, struct dp_pdev *pdev)
  183. {
  184. int idx;
  185. qdf_nbuf_t nbuf;
  186. struct dp_ipa_resources *ipa_res;
  187. for (idx = 0; idx < soc->ipa_uc_tx_rsc.alloc_tx_buf_cnt; idx++) {
  188. nbuf = (qdf_nbuf_t)
  189. soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned[idx];
  190. if (!nbuf)
  191. continue;
  192. if (qdf_mem_smmu_s1_enabled(soc->osdev))
  193. __dp_ipa_handle_buf_smmu_mapping(soc, nbuf, false);
  194. qdf_nbuf_unmap_single(soc->osdev, nbuf, QDF_DMA_BIDIRECTIONAL);
  195. qdf_nbuf_free(nbuf);
  196. soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned[idx] =
  197. (void *)NULL;
  198. }
  199. qdf_mem_free(soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned);
  200. soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned = NULL;
  201. ipa_res = &pdev->ipa_resource;
  202. iounmap(ipa_res->tx_comp_doorbell_vaddr);
  203. qdf_mem_free_sgtable(&ipa_res->tx_ring.sgtable);
  204. qdf_mem_free_sgtable(&ipa_res->tx_comp_ring.sgtable);
  205. }
  206. /**
  207. * dp_rx_ipa_uc_detach - free autonomy RX resources
  208. * @soc: data path instance
  209. * @pdev: core txrx pdev context
  210. *
  211. * This function will detach DP RX into main device context
  212. * will free DP Rx resources.
  213. *
  214. * Return: none
  215. */
  216. static void dp_rx_ipa_uc_detach(struct dp_soc *soc, struct dp_pdev *pdev)
  217. {
  218. struct dp_ipa_resources *ipa_res = &pdev->ipa_resource;
  219. qdf_mem_free_sgtable(&ipa_res->rx_rdy_ring.sgtable);
  220. qdf_mem_free_sgtable(&ipa_res->rx_refill_ring.sgtable);
  221. }
  222. int dp_ipa_uc_detach(struct dp_soc *soc, struct dp_pdev *pdev)
  223. {
  224. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  225. return QDF_STATUS_SUCCESS;
  226. /* TX resource detach */
  227. dp_tx_ipa_uc_detach(soc, pdev);
  228. /* RX resource detach */
  229. dp_rx_ipa_uc_detach(soc, pdev);
  230. return QDF_STATUS_SUCCESS; /* success */
  231. }
  232. /**
  233. * dp_tx_ipa_uc_attach - Allocate autonomy TX resources
  234. * @soc: data path instance
  235. * @pdev: Physical device handle
  236. *
  237. * Allocate TX buffer from non-cacheable memory
  238. * Attache allocated TX buffers with WBM SRNG
  239. *
  240. * Return: int
  241. */
  242. static int dp_tx_ipa_uc_attach(struct dp_soc *soc, struct dp_pdev *pdev)
  243. {
  244. uint32_t tx_buffer_count;
  245. uint32_t ring_base_align = 8;
  246. qdf_dma_addr_t buffer_paddr;
  247. struct hal_srng *wbm_srng = (struct hal_srng *)
  248. soc->tx_comp_ring[IPA_TX_COMP_RING_IDX].hal_srng;
  249. struct hal_srng_params srng_params;
  250. uint32_t paddr_lo;
  251. uint32_t paddr_hi;
  252. void *ring_entry;
  253. int num_entries;
  254. qdf_nbuf_t nbuf;
  255. int retval = QDF_STATUS_SUCCESS;
  256. int max_alloc_count = 0;
  257. /*
  258. * Uncomment when dp_ops_cfg.cfg_attach is implemented
  259. * unsigned int uc_tx_buf_sz =
  260. * dp_cfg_ipa_uc_tx_buf_size(pdev->osif_pdev);
  261. */
  262. unsigned int uc_tx_buf_sz = CFG_IPA_UC_TX_BUF_SIZE_DEFAULT;
  263. unsigned int alloc_size = uc_tx_buf_sz + ring_base_align - 1;
  264. hal_get_srng_params(soc->hal_soc, hal_srng_to_hal_ring_handle(wbm_srng),
  265. &srng_params);
  266. num_entries = srng_params.num_entries;
  267. max_alloc_count =
  268. num_entries - DP_IPA_WAR_WBM2SW_REL_RING_NO_BUF_ENTRIES;
  269. if (max_alloc_count <= 0) {
  270. dp_err("incorrect value for buffer count %u", max_alloc_count);
  271. return -EINVAL;
  272. }
  273. dp_info("requested %d buffers to be posted to wbm ring",
  274. max_alloc_count);
  275. soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned =
  276. qdf_mem_malloc(num_entries *
  277. sizeof(*soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned));
  278. if (!soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned) {
  279. dp_err("IPA WBM Ring Tx buf pool vaddr alloc fail");
  280. return -ENOMEM;
  281. }
  282. hal_srng_access_start_unlocked(soc->hal_soc,
  283. hal_srng_to_hal_ring_handle(wbm_srng));
  284. /*
  285. * Allocate Tx buffers as many as possible.
  286. * Leave DP_IPA_WAR_WBM2SW_REL_RING_NO_BUF_ENTRIES empty
  287. * Populate Tx buffers into WBM2IPA ring
  288. * This initial buffer population will simulate H/W as source ring,
  289. * and update HP
  290. */
  291. for (tx_buffer_count = 0;
  292. tx_buffer_count < max_alloc_count - 1; tx_buffer_count++) {
  293. nbuf = qdf_nbuf_alloc(soc->osdev, alloc_size, 0, 256, FALSE);
  294. if (!nbuf)
  295. break;
  296. ring_entry = hal_srng_dst_get_next_hp(soc->hal_soc,
  297. hal_srng_to_hal_ring_handle(wbm_srng));
  298. if (!ring_entry) {
  299. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  300. "%s: Failed to get WBM ring entry",
  301. __func__);
  302. qdf_nbuf_free(nbuf);
  303. break;
  304. }
  305. qdf_nbuf_map_single(soc->osdev, nbuf,
  306. QDF_DMA_BIDIRECTIONAL);
  307. buffer_paddr = qdf_nbuf_get_frag_paddr(nbuf, 0);
  308. paddr_lo = ((uint64_t)buffer_paddr & 0x00000000ffffffff);
  309. paddr_hi = ((uint64_t)buffer_paddr & 0x0000001f00000000) >> 32;
  310. HAL_RXDMA_PADDR_LO_SET(ring_entry, paddr_lo);
  311. HAL_RXDMA_PADDR_HI_SET(ring_entry, paddr_hi);
  312. HAL_RXDMA_MANAGER_SET(ring_entry, (IPA_TCL_DATA_RING_IDX +
  313. HAL_WBM_SW0_BM_ID));
  314. soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned[tx_buffer_count]
  315. = (void *)nbuf;
  316. if (qdf_mem_smmu_s1_enabled(soc->osdev))
  317. __dp_ipa_handle_buf_smmu_mapping(soc, nbuf, true);
  318. }
  319. hal_srng_access_end_unlocked(soc->hal_soc,
  320. hal_srng_to_hal_ring_handle(wbm_srng));
  321. soc->ipa_uc_tx_rsc.alloc_tx_buf_cnt = tx_buffer_count;
  322. if (tx_buffer_count) {
  323. dp_info("IPA WDI TX buffer: %d allocated", tx_buffer_count);
  324. } else {
  325. dp_err("No IPA WDI TX buffer allocated!");
  326. qdf_mem_free(soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned);
  327. soc->ipa_uc_tx_rsc.tx_buf_pool_vaddr_unaligned = NULL;
  328. retval = -ENOMEM;
  329. }
  330. return retval;
  331. }
  332. /**
  333. * dp_rx_ipa_uc_attach - Allocate autonomy RX resources
  334. * @soc: data path instance
  335. * @pdev: core txrx pdev context
  336. *
  337. * This function will attach a DP RX instance into the main
  338. * device (SOC) context.
  339. *
  340. * Return: QDF_STATUS_SUCCESS: success
  341. * QDF_STATUS_E_RESOURCES: Error return
  342. */
  343. static int dp_rx_ipa_uc_attach(struct dp_soc *soc, struct dp_pdev *pdev)
  344. {
  345. return QDF_STATUS_SUCCESS;
  346. }
  347. int dp_ipa_uc_attach(struct dp_soc *soc, struct dp_pdev *pdev)
  348. {
  349. int error;
  350. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  351. return QDF_STATUS_SUCCESS;
  352. /* TX resource attach */
  353. error = dp_tx_ipa_uc_attach(soc, pdev);
  354. if (error) {
  355. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  356. "%s: DP IPA UC TX attach fail code %d",
  357. __func__, error);
  358. return error;
  359. }
  360. /* RX resource attach */
  361. error = dp_rx_ipa_uc_attach(soc, pdev);
  362. if (error) {
  363. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  364. "%s: DP IPA UC RX attach fail code %d",
  365. __func__, error);
  366. dp_tx_ipa_uc_detach(soc, pdev);
  367. return error;
  368. }
  369. return QDF_STATUS_SUCCESS; /* success */
  370. }
  371. /*
  372. * dp_ipa_ring_resource_setup() - setup IPA ring resources
  373. * @soc: data path SoC handle
  374. *
  375. * Return: none
  376. */
  377. int dp_ipa_ring_resource_setup(struct dp_soc *soc,
  378. struct dp_pdev *pdev)
  379. {
  380. struct hal_soc *hal_soc = (struct hal_soc *)soc->hal_soc;
  381. struct hal_srng *hal_srng;
  382. struct hal_srng_params srng_params;
  383. qdf_dma_addr_t hp_addr;
  384. unsigned long addr_offset, dev_base_paddr;
  385. uint32_t ix0;
  386. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  387. return QDF_STATUS_SUCCESS;
  388. /* IPA TCL_DATA Ring - HAL_SRNG_SW2TCL3 */
  389. hal_srng = (struct hal_srng *)
  390. soc->tcl_data_ring[IPA_TCL_DATA_RING_IDX].hal_srng;
  391. hal_get_srng_params(hal_soc_to_hal_soc_handle(hal_soc),
  392. hal_srng_to_hal_ring_handle(hal_srng),
  393. &srng_params);
  394. soc->ipa_uc_tx_rsc.ipa_tcl_ring_base_paddr =
  395. srng_params.ring_base_paddr;
  396. soc->ipa_uc_tx_rsc.ipa_tcl_ring_base_vaddr =
  397. srng_params.ring_base_vaddr;
  398. soc->ipa_uc_tx_rsc.ipa_tcl_ring_size =
  399. (srng_params.num_entries * srng_params.entry_size) << 2;
  400. /*
  401. * For the register backed memory addresses, use the scn->mem_pa to
  402. * calculate the physical address of the shadow registers
  403. */
  404. dev_base_paddr =
  405. (unsigned long)
  406. ((struct hif_softc *)(hal_soc->hif_handle))->mem_pa;
  407. addr_offset = (unsigned long)(hal_srng->u.src_ring.hp_addr) -
  408. (unsigned long)(hal_soc->dev_base_addr);
  409. soc->ipa_uc_tx_rsc.ipa_tcl_hp_paddr =
  410. (qdf_dma_addr_t)(addr_offset + dev_base_paddr);
  411. dp_info("IPA TCL_DATA Ring addr_offset=%x, dev_base_paddr=%x, hp_paddr=%x paddr=%pK vaddr=%pK size= %u(%u bytes)",
  412. (unsigned int)addr_offset,
  413. (unsigned int)dev_base_paddr,
  414. (unsigned int)(soc->ipa_uc_tx_rsc.ipa_tcl_hp_paddr),
  415. (void *)soc->ipa_uc_tx_rsc.ipa_tcl_ring_base_paddr,
  416. (void *)soc->ipa_uc_tx_rsc.ipa_tcl_ring_base_vaddr,
  417. srng_params.num_entries,
  418. soc->ipa_uc_tx_rsc.ipa_tcl_ring_size);
  419. /* IPA TX COMP Ring - HAL_SRNG_WBM2SW2_RELEASE */
  420. hal_srng = (struct hal_srng *)
  421. soc->tx_comp_ring[IPA_TX_COMP_RING_IDX].hal_srng;
  422. hal_get_srng_params(hal_soc_to_hal_soc_handle(hal_soc),
  423. hal_srng_to_hal_ring_handle(hal_srng),
  424. &srng_params);
  425. soc->ipa_uc_tx_rsc.ipa_wbm_ring_base_paddr =
  426. srng_params.ring_base_paddr;
  427. soc->ipa_uc_tx_rsc.ipa_wbm_ring_base_vaddr =
  428. srng_params.ring_base_vaddr;
  429. soc->ipa_uc_tx_rsc.ipa_wbm_ring_size =
  430. (srng_params.num_entries * srng_params.entry_size) << 2;
  431. addr_offset = (unsigned long)(hal_srng->u.dst_ring.tp_addr) -
  432. (unsigned long)(hal_soc->dev_base_addr);
  433. soc->ipa_uc_tx_rsc.ipa_wbm_tp_paddr =
  434. (qdf_dma_addr_t)(addr_offset + dev_base_paddr);
  435. dp_info("IPA TX COMP Ring addr_offset=%x, dev_base_paddr=%x, ipa_wbm_tp_paddr=%x paddr=%pK vaddr=0%pK size= %u(%u bytes)",
  436. (unsigned int)addr_offset,
  437. (unsigned int)dev_base_paddr,
  438. (unsigned int)(soc->ipa_uc_tx_rsc.ipa_wbm_tp_paddr),
  439. (void *)soc->ipa_uc_tx_rsc.ipa_wbm_ring_base_paddr,
  440. (void *)soc->ipa_uc_tx_rsc.ipa_wbm_ring_base_vaddr,
  441. srng_params.num_entries,
  442. soc->ipa_uc_tx_rsc.ipa_wbm_ring_size);
  443. /* IPA REO_DEST Ring - HAL_SRNG_REO2SW4 */
  444. hal_srng = (struct hal_srng *)
  445. soc->reo_dest_ring[IPA_REO_DEST_RING_IDX].hal_srng;
  446. hal_get_srng_params(hal_soc_to_hal_soc_handle(hal_soc),
  447. hal_srng_to_hal_ring_handle(hal_srng),
  448. &srng_params);
  449. soc->ipa_uc_rx_rsc.ipa_reo_ring_base_paddr =
  450. srng_params.ring_base_paddr;
  451. soc->ipa_uc_rx_rsc.ipa_reo_ring_base_vaddr =
  452. srng_params.ring_base_vaddr;
  453. soc->ipa_uc_rx_rsc.ipa_reo_ring_size =
  454. (srng_params.num_entries * srng_params.entry_size) << 2;
  455. addr_offset = (unsigned long)(hal_srng->u.dst_ring.tp_addr) -
  456. (unsigned long)(hal_soc->dev_base_addr);
  457. soc->ipa_uc_rx_rsc.ipa_reo_tp_paddr =
  458. (qdf_dma_addr_t)(addr_offset + dev_base_paddr);
  459. dp_info("IPA REO_DEST Ring addr_offset=%x, dev_base_paddr=%x, tp_paddr=%x paddr=%pK vaddr=%pK size= %u(%u bytes)",
  460. (unsigned int)addr_offset,
  461. (unsigned int)dev_base_paddr,
  462. (unsigned int)(soc->ipa_uc_rx_rsc.ipa_reo_tp_paddr),
  463. (void *)soc->ipa_uc_rx_rsc.ipa_reo_ring_base_paddr,
  464. (void *)soc->ipa_uc_rx_rsc.ipa_reo_ring_base_vaddr,
  465. srng_params.num_entries,
  466. soc->ipa_uc_rx_rsc.ipa_reo_ring_size);
  467. hal_srng = (struct hal_srng *)
  468. pdev->rx_refill_buf_ring2.hal_srng;
  469. hal_get_srng_params(hal_soc_to_hal_soc_handle(hal_soc),
  470. hal_srng_to_hal_ring_handle(hal_srng),
  471. &srng_params);
  472. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_base_paddr =
  473. srng_params.ring_base_paddr;
  474. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_base_vaddr =
  475. srng_params.ring_base_vaddr;
  476. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_size =
  477. (srng_params.num_entries * srng_params.entry_size) << 2;
  478. hp_addr = hal_srng_get_hp_addr(hal_soc_to_hal_soc_handle(hal_soc),
  479. hal_srng_to_hal_ring_handle(hal_srng));
  480. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_hp_paddr =
  481. qdf_mem_paddr_from_dmaaddr(soc->osdev, hp_addr);
  482. dp_info("IPA REFILL_BUF Ring hp_paddr=%x paddr=%pK vaddr=%pK size= %u(%u bytes)",
  483. (unsigned int)(soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_hp_paddr),
  484. (void *)soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_base_paddr,
  485. (void *)soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_base_vaddr,
  486. srng_params.num_entries,
  487. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_size);
  488. /*
  489. * Set DEST_RING_MAPPING_4 to SW2 as default value for
  490. * DESTINATION_RING_CTRL_IX_0.
  491. */
  492. ix0 = HAL_REO_REMAP_IX0(REO_REMAP_TCL, 0) |
  493. HAL_REO_REMAP_IX0(REO_REMAP_SW1, 1) |
  494. HAL_REO_REMAP_IX0(REO_REMAP_SW2, 2) |
  495. HAL_REO_REMAP_IX0(REO_REMAP_SW3, 3) |
  496. HAL_REO_REMAP_IX0(REO_REMAP_SW2, 4) |
  497. HAL_REO_REMAP_IX0(REO_REMAP_RELEASE, 5) |
  498. HAL_REO_REMAP_IX0(REO_REMAP_FW, 6) |
  499. HAL_REO_REMAP_IX0(REO_REMAP_FW, 7);
  500. hal_reo_read_write_ctrl_ix(soc->hal_soc, false, &ix0, NULL, NULL, NULL);
  501. return 0;
  502. }
  503. static QDF_STATUS dp_ipa_get_shared_mem_info(qdf_device_t osdev,
  504. qdf_shared_mem_t *shared_mem,
  505. void *cpu_addr,
  506. qdf_dma_addr_t dma_addr,
  507. uint32_t size)
  508. {
  509. qdf_dma_addr_t paddr;
  510. int ret;
  511. shared_mem->vaddr = cpu_addr;
  512. qdf_mem_set_dma_size(osdev, &shared_mem->mem_info, size);
  513. *qdf_mem_get_dma_addr_ptr(osdev, &shared_mem->mem_info) = dma_addr;
  514. paddr = qdf_mem_paddr_from_dmaaddr(osdev, dma_addr);
  515. qdf_mem_set_dma_pa(osdev, &shared_mem->mem_info, paddr);
  516. ret = qdf_mem_dma_get_sgtable(osdev->dev, &shared_mem->sgtable,
  517. shared_mem->vaddr, dma_addr, size);
  518. if (ret) {
  519. dp_err("Unable to get DMA sgtable");
  520. return QDF_STATUS_E_NOMEM;
  521. }
  522. qdf_dma_get_sgtable_dma_addr(&shared_mem->sgtable);
  523. return QDF_STATUS_SUCCESS;
  524. }
  525. QDF_STATUS dp_ipa_get_resource(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  526. {
  527. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  528. struct dp_pdev *pdev =
  529. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  530. struct dp_ipa_resources *ipa_res;
  531. if (!pdev) {
  532. dp_err("%s invalid instance", __func__);
  533. return QDF_STATUS_E_FAILURE;
  534. }
  535. ipa_res = &pdev->ipa_resource;
  536. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  537. return QDF_STATUS_SUCCESS;
  538. ipa_res->tx_num_alloc_buffer =
  539. (uint32_t)soc->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
  540. dp_ipa_get_shared_mem_info(soc->osdev, &ipa_res->tx_ring,
  541. soc->ipa_uc_tx_rsc.ipa_tcl_ring_base_vaddr,
  542. soc->ipa_uc_tx_rsc.ipa_tcl_ring_base_paddr,
  543. soc->ipa_uc_tx_rsc.ipa_tcl_ring_size);
  544. dp_ipa_get_shared_mem_info(soc->osdev, &ipa_res->tx_comp_ring,
  545. soc->ipa_uc_tx_rsc.ipa_wbm_ring_base_vaddr,
  546. soc->ipa_uc_tx_rsc.ipa_wbm_ring_base_paddr,
  547. soc->ipa_uc_tx_rsc.ipa_wbm_ring_size);
  548. dp_ipa_get_shared_mem_info(soc->osdev, &ipa_res->rx_rdy_ring,
  549. soc->ipa_uc_rx_rsc.ipa_reo_ring_base_vaddr,
  550. soc->ipa_uc_rx_rsc.ipa_reo_ring_base_paddr,
  551. soc->ipa_uc_rx_rsc.ipa_reo_ring_size);
  552. dp_ipa_get_shared_mem_info(
  553. soc->osdev, &ipa_res->rx_refill_ring,
  554. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_base_vaddr,
  555. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_base_paddr,
  556. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_ring_size);
  557. if (!qdf_mem_get_dma_addr(soc->osdev,
  558. &ipa_res->tx_comp_ring.mem_info) ||
  559. !qdf_mem_get_dma_addr(soc->osdev, &ipa_res->rx_rdy_ring.mem_info))
  560. return QDF_STATUS_E_FAILURE;
  561. return QDF_STATUS_SUCCESS;
  562. }
  563. QDF_STATUS dp_ipa_set_doorbell_paddr(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  564. {
  565. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  566. struct dp_pdev *pdev =
  567. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  568. struct dp_ipa_resources *ipa_res;
  569. struct hal_srng *wbm_srng = (struct hal_srng *)
  570. soc->tx_comp_ring[IPA_TX_COMP_RING_IDX].hal_srng;
  571. struct hal_srng *reo_srng = (struct hal_srng *)
  572. soc->reo_dest_ring[IPA_REO_DEST_RING_IDX].hal_srng;
  573. uint32_t tx_comp_doorbell_dmaaddr;
  574. uint32_t rx_ready_doorbell_dmaaddr;
  575. if (!pdev) {
  576. dp_err("%s invalid instance", __func__);
  577. return QDF_STATUS_E_FAILURE;
  578. }
  579. ipa_res = &pdev->ipa_resource;
  580. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  581. return QDF_STATUS_SUCCESS;
  582. ipa_res->tx_comp_doorbell_vaddr =
  583. ioremap(ipa_res->tx_comp_doorbell_paddr, 4);
  584. if (qdf_mem_smmu_s1_enabled(soc->osdev)) {
  585. pld_smmu_map(soc->osdev->dev, ipa_res->tx_comp_doorbell_paddr,
  586. &tx_comp_doorbell_dmaaddr, sizeof(uint32_t));
  587. ipa_res->tx_comp_doorbell_paddr = tx_comp_doorbell_dmaaddr;
  588. pld_smmu_map(soc->osdev->dev, ipa_res->rx_ready_doorbell_paddr,
  589. &rx_ready_doorbell_dmaaddr, sizeof(uint32_t));
  590. ipa_res->rx_ready_doorbell_paddr = rx_ready_doorbell_dmaaddr;
  591. }
  592. hal_srng_dst_set_hp_paddr(wbm_srng, ipa_res->tx_comp_doorbell_paddr);
  593. dp_info("paddr %pK vaddr %pK",
  594. (void *)ipa_res->tx_comp_doorbell_paddr,
  595. (void *)ipa_res->tx_comp_doorbell_vaddr);
  596. hal_srng_dst_init_hp(wbm_srng, ipa_res->tx_comp_doorbell_vaddr);
  597. /*
  598. * For RX, REO module on Napier/Hastings does reordering on incoming
  599. * Ethernet packets and writes one or more descriptors to REO2IPA Rx
  600. * ring.It then updates the ring’s Write/Head ptr and rings a doorbell
  601. * to IPA.
  602. * Set the doorbell addr for the REO ring.
  603. */
  604. hal_srng_dst_set_hp_paddr(reo_srng, ipa_res->rx_ready_doorbell_paddr);
  605. return QDF_STATUS_SUCCESS;
  606. }
  607. QDF_STATUS dp_ipa_op_response(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  608. uint8_t *op_msg)
  609. {
  610. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  611. struct dp_pdev *pdev =
  612. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  613. if (!pdev) {
  614. dp_err("%s invalid instance", __func__);
  615. return QDF_STATUS_E_FAILURE;
  616. }
  617. if (!wlan_cfg_is_ipa_enabled(pdev->soc->wlan_cfg_ctx))
  618. return QDF_STATUS_SUCCESS;
  619. if (pdev->ipa_uc_op_cb) {
  620. pdev->ipa_uc_op_cb(op_msg, pdev->usr_ctxt);
  621. } else {
  622. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  623. "%s: IPA callback function is not registered", __func__);
  624. qdf_mem_free(op_msg);
  625. return QDF_STATUS_E_FAILURE;
  626. }
  627. return QDF_STATUS_SUCCESS;
  628. }
  629. QDF_STATUS dp_ipa_register_op_cb(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  630. ipa_uc_op_cb_type op_cb,
  631. void *usr_ctxt)
  632. {
  633. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  634. struct dp_pdev *pdev =
  635. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  636. if (!pdev) {
  637. dp_err("%s invalid instance", __func__);
  638. return QDF_STATUS_E_FAILURE;
  639. }
  640. if (!wlan_cfg_is_ipa_enabled(pdev->soc->wlan_cfg_ctx))
  641. return QDF_STATUS_SUCCESS;
  642. pdev->ipa_uc_op_cb = op_cb;
  643. pdev->usr_ctxt = usr_ctxt;
  644. return QDF_STATUS_SUCCESS;
  645. }
  646. QDF_STATUS dp_ipa_get_stat(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  647. {
  648. /* TBD */
  649. return QDF_STATUS_SUCCESS;
  650. }
  651. qdf_nbuf_t dp_tx_send_ipa_data_frame(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  652. qdf_nbuf_t skb)
  653. {
  654. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  655. struct dp_vdev *vdev =
  656. dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  657. qdf_nbuf_t ret;
  658. if (!vdev) {
  659. dp_err("%s invalid instance", __func__);
  660. return skb;
  661. }
  662. /* Terminate the (single-element) list of tx frames */
  663. qdf_nbuf_set_next(skb, NULL);
  664. ret = dp_tx_send(dp_vdev_to_cdp_vdev(vdev), skb);
  665. if (ret) {
  666. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  667. "%s: Failed to tx", __func__);
  668. return ret;
  669. }
  670. return NULL;
  671. }
  672. QDF_STATUS dp_ipa_enable_autonomy(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  673. {
  674. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  675. struct dp_pdev *pdev =
  676. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  677. uint32_t ix0;
  678. uint32_t ix2;
  679. if (!pdev) {
  680. dp_err("%s invalid instance", __func__);
  681. return QDF_STATUS_E_FAILURE;
  682. }
  683. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  684. return QDF_STATUS_SUCCESS;
  685. if (!hif_is_target_ready(HIF_GET_SOFTC(soc->hif_handle)))
  686. return QDF_STATUS_E_AGAIN;
  687. /* Call HAL API to remap REO rings to REO2IPA ring */
  688. ix0 = HAL_REO_REMAP_IX0(REO_REMAP_TCL, 0) |
  689. HAL_REO_REMAP_IX0(REO_REMAP_SW4, 1) |
  690. HAL_REO_REMAP_IX0(REO_REMAP_SW4, 2) |
  691. HAL_REO_REMAP_IX0(REO_REMAP_SW4, 3) |
  692. HAL_REO_REMAP_IX0(REO_REMAP_SW4, 4) |
  693. HAL_REO_REMAP_IX0(REO_REMAP_RELEASE, 5) |
  694. HAL_REO_REMAP_IX0(REO_REMAP_FW, 6) |
  695. HAL_REO_REMAP_IX0(REO_REMAP_FW, 7);
  696. if (wlan_cfg_is_rx_hash_enabled(soc->wlan_cfg_ctx)) {
  697. ix2 = HAL_REO_REMAP_IX2(REO_REMAP_SW4, 16) |
  698. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 17) |
  699. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 18) |
  700. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 19) |
  701. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 20) |
  702. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 21) |
  703. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 22) |
  704. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 23);
  705. hal_reo_read_write_ctrl_ix(soc->hal_soc, false, &ix0, NULL,
  706. &ix2, &ix2);
  707. dp_ipa_reo_remap_history_add(ix0, ix2, ix2);
  708. } else {
  709. hal_reo_read_write_ctrl_ix(soc->hal_soc, false, &ix0, NULL,
  710. NULL, NULL);
  711. dp_ipa_reo_remap_history_add(ix0, 0, 0);
  712. }
  713. return QDF_STATUS_SUCCESS;
  714. }
  715. QDF_STATUS dp_ipa_disable_autonomy(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  716. {
  717. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  718. struct dp_pdev *pdev =
  719. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  720. uint32_t ix0;
  721. uint32_t ix2;
  722. uint32_t ix3;
  723. if (!pdev) {
  724. dp_err("%s invalid instance", __func__);
  725. return QDF_STATUS_E_FAILURE;
  726. }
  727. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  728. return QDF_STATUS_SUCCESS;
  729. if (!hif_is_target_ready(HIF_GET_SOFTC(soc->hif_handle)))
  730. return QDF_STATUS_E_AGAIN;
  731. /* Call HAL API to remap REO rings to REO2IPA ring */
  732. ix0 = HAL_REO_REMAP_IX0(REO_REMAP_TCL, 0) |
  733. HAL_REO_REMAP_IX0(REO_REMAP_SW1, 1) |
  734. HAL_REO_REMAP_IX0(REO_REMAP_SW2, 2) |
  735. HAL_REO_REMAP_IX0(REO_REMAP_SW3, 3) |
  736. HAL_REO_REMAP_IX0(REO_REMAP_SW2, 4) |
  737. HAL_REO_REMAP_IX0(REO_REMAP_RELEASE, 5) |
  738. HAL_REO_REMAP_IX0(REO_REMAP_FW, 6) |
  739. HAL_REO_REMAP_IX0(REO_REMAP_FW, 7);
  740. if (wlan_cfg_is_rx_hash_enabled(soc->wlan_cfg_ctx)) {
  741. dp_reo_remap_config(soc, &ix2, &ix3);
  742. hal_reo_read_write_ctrl_ix(soc->hal_soc, false, &ix0, NULL,
  743. &ix2, &ix3);
  744. dp_ipa_reo_remap_history_add(ix0, ix2, ix3);
  745. } else {
  746. hal_reo_read_write_ctrl_ix(soc->hal_soc, false, &ix0, NULL,
  747. NULL, NULL);
  748. dp_ipa_reo_remap_history_add(ix0, 0, 0);
  749. }
  750. return QDF_STATUS_SUCCESS;
  751. }
  752. /* This should be configurable per H/W configuration enable status */
  753. #define L3_HEADER_PADDING 2
  754. #ifdef CONFIG_IPA_WDI_UNIFIED_API
  755. #ifndef QCA_LL_TX_FLOW_CONTROL_V2
  756. static inline void dp_setup_mcc_sys_pipes(
  757. qdf_ipa_sys_connect_params_t *sys_in,
  758. qdf_ipa_wdi_conn_in_params_t *pipe_in)
  759. {
  760. /* Setup MCC sys pipe */
  761. QDF_IPA_WDI_CONN_IN_PARAMS_NUM_SYS_PIPE_NEEDED(pipe_in) =
  762. DP_IPA_MAX_IFACE;
  763. for (int i = 0; i < DP_IPA_MAX_IFACE; i++)
  764. memcpy(&QDF_IPA_WDI_CONN_IN_PARAMS_SYS_IN(pipe_in)[i],
  765. &sys_in[i], sizeof(qdf_ipa_sys_connect_params_t));
  766. }
  767. #else
  768. static inline void dp_setup_mcc_sys_pipes(
  769. qdf_ipa_sys_connect_params_t *sys_in,
  770. qdf_ipa_wdi_conn_in_params_t *pipe_in)
  771. {
  772. QDF_IPA_WDI_CONN_IN_PARAMS_NUM_SYS_PIPE_NEEDED(pipe_in) = 0;
  773. }
  774. #endif
  775. static void dp_ipa_wdi_tx_params(struct dp_soc *soc,
  776. struct dp_ipa_resources *ipa_res,
  777. qdf_ipa_wdi_pipe_setup_info_t *tx,
  778. bool over_gsi)
  779. {
  780. struct tcl_data_cmd *tcl_desc_ptr;
  781. uint8_t *desc_addr;
  782. uint32_t desc_size;
  783. if (over_gsi)
  784. QDF_IPA_WDI_SETUP_INFO_CLIENT(tx) = IPA_CLIENT_WLAN2_CONS;
  785. else
  786. QDF_IPA_WDI_SETUP_INFO_CLIENT(tx) = IPA_CLIENT_WLAN1_CONS;
  787. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_BASE_PA(tx) =
  788. qdf_mem_get_dma_addr(soc->osdev,
  789. &ipa_res->tx_comp_ring.mem_info);
  790. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_SIZE(tx) =
  791. qdf_mem_get_dma_size(soc->osdev,
  792. &ipa_res->tx_comp_ring.mem_info);
  793. /* WBM Tail Pointer Address */
  794. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_DOORBELL_PA(tx) =
  795. soc->ipa_uc_tx_rsc.ipa_wbm_tp_paddr;
  796. QDF_IPA_WDI_SETUP_INFO_IS_TXR_RN_DB_PCIE_ADDR(tx) = true;
  797. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_BASE_PA(tx) =
  798. qdf_mem_get_dma_addr(soc->osdev,
  799. &ipa_res->tx_ring.mem_info);
  800. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_SIZE(tx) =
  801. qdf_mem_get_dma_size(soc->osdev,
  802. &ipa_res->tx_ring.mem_info);
  803. /* TCL Head Pointer Address */
  804. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_DOORBELL_PA(tx) =
  805. soc->ipa_uc_tx_rsc.ipa_tcl_hp_paddr;
  806. QDF_IPA_WDI_SETUP_INFO_IS_EVT_RN_DB_PCIE_ADDR(tx) = true;
  807. QDF_IPA_WDI_SETUP_INFO_NUM_PKT_BUFFERS(tx) =
  808. ipa_res->tx_num_alloc_buffer;
  809. QDF_IPA_WDI_SETUP_INFO_PKT_OFFSET(tx) = 0;
  810. /* Preprogram TCL descriptor */
  811. desc_addr =
  812. (uint8_t *)QDF_IPA_WDI_SETUP_INFO_DESC_FORMAT_TEMPLATE(tx);
  813. desc_size = sizeof(struct tcl_data_cmd);
  814. HAL_TX_DESC_SET_TLV_HDR(desc_addr, HAL_TX_TCL_DATA_TAG, desc_size);
  815. tcl_desc_ptr = (struct tcl_data_cmd *)
  816. (QDF_IPA_WDI_SETUP_INFO_DESC_FORMAT_TEMPLATE(tx) + 1);
  817. tcl_desc_ptr->buf_addr_info.return_buffer_manager =
  818. HAL_RX_BUF_RBM_SW2_BM;
  819. tcl_desc_ptr->addrx_en = 1; /* Address X search enable in ASE */
  820. tcl_desc_ptr->encap_type = HAL_TX_ENCAP_TYPE_ETHERNET;
  821. tcl_desc_ptr->packet_offset = 2; /* padding for alignment */
  822. }
  823. static void dp_ipa_wdi_rx_params(struct dp_soc *soc,
  824. struct dp_ipa_resources *ipa_res,
  825. qdf_ipa_wdi_pipe_setup_info_t *rx,
  826. bool over_gsi)
  827. {
  828. if (over_gsi)
  829. QDF_IPA_WDI_SETUP_INFO_CLIENT(rx) =
  830. IPA_CLIENT_WLAN2_PROD;
  831. else
  832. QDF_IPA_WDI_SETUP_INFO_CLIENT(rx) =
  833. IPA_CLIENT_WLAN1_PROD;
  834. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_BASE_PA(rx) =
  835. qdf_mem_get_dma_addr(soc->osdev,
  836. &ipa_res->rx_rdy_ring.mem_info);
  837. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_SIZE(rx) =
  838. qdf_mem_get_dma_size(soc->osdev,
  839. &ipa_res->rx_rdy_ring.mem_info);
  840. /* REO Tail Pointer Address */
  841. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_DOORBELL_PA(rx) =
  842. soc->ipa_uc_rx_rsc.ipa_reo_tp_paddr;
  843. QDF_IPA_WDI_SETUP_INFO_IS_TXR_RN_DB_PCIE_ADDR(rx) = true;
  844. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_BASE_PA(rx) =
  845. qdf_mem_get_dma_addr(soc->osdev,
  846. &ipa_res->rx_refill_ring.mem_info);
  847. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_SIZE(rx) =
  848. qdf_mem_get_dma_size(soc->osdev,
  849. &ipa_res->rx_refill_ring.mem_info);
  850. /* FW Head Pointer Address */
  851. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_DOORBELL_PA(rx) =
  852. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_hp_paddr;
  853. QDF_IPA_WDI_SETUP_INFO_IS_EVT_RN_DB_PCIE_ADDR(rx) = false;
  854. QDF_IPA_WDI_SETUP_INFO_PKT_OFFSET(rx) =
  855. RX_PKT_TLVS_LEN + L3_HEADER_PADDING;
  856. }
  857. static void
  858. dp_ipa_wdi_tx_smmu_params(struct dp_soc *soc,
  859. struct dp_ipa_resources *ipa_res,
  860. qdf_ipa_wdi_pipe_setup_info_smmu_t *tx_smmu,
  861. bool over_gsi)
  862. {
  863. struct tcl_data_cmd *tcl_desc_ptr;
  864. uint8_t *desc_addr;
  865. uint32_t desc_size;
  866. if (over_gsi)
  867. QDF_IPA_WDI_SETUP_INFO_SMMU_CLIENT(tx_smmu) =
  868. IPA_CLIENT_WLAN2_CONS;
  869. else
  870. QDF_IPA_WDI_SETUP_INFO_SMMU_CLIENT(tx_smmu) =
  871. IPA_CLIENT_WLAN1_CONS;
  872. qdf_mem_copy(&QDF_IPA_WDI_SETUP_INFO_SMMU_TRANSFER_RING_BASE(tx_smmu),
  873. &ipa_res->tx_comp_ring.sgtable,
  874. sizeof(sgtable_t));
  875. QDF_IPA_WDI_SETUP_INFO_SMMU_TRANSFER_RING_SIZE(tx_smmu) =
  876. qdf_mem_get_dma_size(soc->osdev,
  877. &ipa_res->tx_comp_ring.mem_info);
  878. /* WBM Tail Pointer Address */
  879. QDF_IPA_WDI_SETUP_INFO_SMMU_TRANSFER_RING_DOORBELL_PA(tx_smmu) =
  880. soc->ipa_uc_tx_rsc.ipa_wbm_tp_paddr;
  881. QDF_IPA_WDI_SETUP_INFO_SMMU_IS_TXR_RN_DB_PCIE_ADDR(tx_smmu) = true;
  882. qdf_mem_copy(&QDF_IPA_WDI_SETUP_INFO_SMMU_EVENT_RING_BASE(tx_smmu),
  883. &ipa_res->tx_ring.sgtable,
  884. sizeof(sgtable_t));
  885. QDF_IPA_WDI_SETUP_INFO_SMMU_EVENT_RING_SIZE(tx_smmu) =
  886. qdf_mem_get_dma_size(soc->osdev,
  887. &ipa_res->tx_ring.mem_info);
  888. /* TCL Head Pointer Address */
  889. QDF_IPA_WDI_SETUP_INFO_SMMU_EVENT_RING_DOORBELL_PA(tx_smmu) =
  890. soc->ipa_uc_tx_rsc.ipa_tcl_hp_paddr;
  891. QDF_IPA_WDI_SETUP_INFO_SMMU_IS_EVT_RN_DB_PCIE_ADDR(tx_smmu) = true;
  892. QDF_IPA_WDI_SETUP_INFO_SMMU_NUM_PKT_BUFFERS(tx_smmu) =
  893. ipa_res->tx_num_alloc_buffer;
  894. QDF_IPA_WDI_SETUP_INFO_SMMU_PKT_OFFSET(tx_smmu) = 0;
  895. /* Preprogram TCL descriptor */
  896. desc_addr = (uint8_t *)QDF_IPA_WDI_SETUP_INFO_SMMU_DESC_FORMAT_TEMPLATE(
  897. tx_smmu);
  898. desc_size = sizeof(struct tcl_data_cmd);
  899. HAL_TX_DESC_SET_TLV_HDR(desc_addr, HAL_TX_TCL_DATA_TAG, desc_size);
  900. tcl_desc_ptr = (struct tcl_data_cmd *)
  901. (QDF_IPA_WDI_SETUP_INFO_SMMU_DESC_FORMAT_TEMPLATE(tx_smmu) + 1);
  902. tcl_desc_ptr->buf_addr_info.return_buffer_manager =
  903. HAL_RX_BUF_RBM_SW2_BM;
  904. tcl_desc_ptr->addrx_en = 1; /* Address X search enable in ASE */
  905. tcl_desc_ptr->encap_type = HAL_TX_ENCAP_TYPE_ETHERNET;
  906. tcl_desc_ptr->packet_offset = 2; /* padding for alignment */
  907. }
  908. static void
  909. dp_ipa_wdi_rx_smmu_params(struct dp_soc *soc,
  910. struct dp_ipa_resources *ipa_res,
  911. qdf_ipa_wdi_pipe_setup_info_smmu_t *rx_smmu,
  912. bool over_gsi)
  913. {
  914. if (over_gsi)
  915. QDF_IPA_WDI_SETUP_INFO_SMMU_CLIENT(rx_smmu) =
  916. IPA_CLIENT_WLAN2_PROD;
  917. else
  918. QDF_IPA_WDI_SETUP_INFO_SMMU_CLIENT(rx_smmu) =
  919. IPA_CLIENT_WLAN1_PROD;
  920. qdf_mem_copy(&QDF_IPA_WDI_SETUP_INFO_SMMU_TRANSFER_RING_BASE(rx_smmu),
  921. &ipa_res->rx_rdy_ring.sgtable,
  922. sizeof(sgtable_t));
  923. QDF_IPA_WDI_SETUP_INFO_SMMU_TRANSFER_RING_SIZE(rx_smmu) =
  924. qdf_mem_get_dma_size(soc->osdev,
  925. &ipa_res->rx_rdy_ring.mem_info);
  926. /* REO Tail Pointer Address */
  927. QDF_IPA_WDI_SETUP_INFO_SMMU_TRANSFER_RING_DOORBELL_PA(rx_smmu) =
  928. soc->ipa_uc_rx_rsc.ipa_reo_tp_paddr;
  929. QDF_IPA_WDI_SETUP_INFO_SMMU_IS_TXR_RN_DB_PCIE_ADDR(rx_smmu) = true;
  930. qdf_mem_copy(&QDF_IPA_WDI_SETUP_INFO_SMMU_EVENT_RING_BASE(rx_smmu),
  931. &ipa_res->rx_refill_ring.sgtable,
  932. sizeof(sgtable_t));
  933. QDF_IPA_WDI_SETUP_INFO_SMMU_EVENT_RING_SIZE(rx_smmu) =
  934. qdf_mem_get_dma_size(soc->osdev,
  935. &ipa_res->rx_refill_ring.mem_info);
  936. /* FW Head Pointer Address */
  937. QDF_IPA_WDI_SETUP_INFO_SMMU_EVENT_RING_DOORBELL_PA(rx_smmu) =
  938. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_hp_paddr;
  939. QDF_IPA_WDI_SETUP_INFO_SMMU_IS_EVT_RN_DB_PCIE_ADDR(rx_smmu) = false;
  940. QDF_IPA_WDI_SETUP_INFO_SMMU_PKT_OFFSET(rx_smmu) =
  941. RX_PKT_TLVS_LEN + L3_HEADER_PADDING;
  942. }
  943. QDF_STATUS dp_ipa_setup(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  944. void *ipa_i2w_cb, void *ipa_w2i_cb,
  945. void *ipa_wdi_meter_notifier_cb,
  946. uint32_t ipa_desc_size, void *ipa_priv,
  947. bool is_rm_enabled, uint32_t *tx_pipe_handle,
  948. uint32_t *rx_pipe_handle, bool is_smmu_enabled,
  949. qdf_ipa_sys_connect_params_t *sys_in, bool over_gsi)
  950. {
  951. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  952. struct dp_pdev *pdev =
  953. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  954. struct dp_ipa_resources *ipa_res;
  955. qdf_ipa_ep_cfg_t *tx_cfg;
  956. qdf_ipa_ep_cfg_t *rx_cfg;
  957. qdf_ipa_wdi_pipe_setup_info_t *tx = NULL;
  958. qdf_ipa_wdi_pipe_setup_info_t *rx = NULL;
  959. qdf_ipa_wdi_pipe_setup_info_smmu_t *tx_smmu;
  960. qdf_ipa_wdi_pipe_setup_info_smmu_t *rx_smmu;
  961. qdf_ipa_wdi_conn_in_params_t pipe_in;
  962. qdf_ipa_wdi_conn_out_params_t pipe_out;
  963. int ret;
  964. if (!pdev) {
  965. dp_err("%s invalid instance", __func__);
  966. return QDF_STATUS_E_FAILURE;
  967. }
  968. ipa_res = &pdev->ipa_resource;
  969. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  970. return QDF_STATUS_SUCCESS;
  971. qdf_mem_zero(&pipe_in, sizeof(pipe_in));
  972. qdf_mem_zero(&pipe_out, sizeof(pipe_out));
  973. if (is_smmu_enabled)
  974. QDF_IPA_WDI_CONN_IN_PARAMS_SMMU_ENABLED(&pipe_in) = true;
  975. else
  976. QDF_IPA_WDI_CONN_IN_PARAMS_SMMU_ENABLED(&pipe_in) = false;
  977. dp_setup_mcc_sys_pipes(sys_in, &pipe_in);
  978. /* TX PIPE */
  979. if (QDF_IPA_WDI_CONN_IN_PARAMS_SMMU_ENABLED(&pipe_in)) {
  980. tx_smmu = &QDF_IPA_WDI_CONN_IN_PARAMS_TX_SMMU(&pipe_in);
  981. tx_cfg = &QDF_IPA_WDI_SETUP_INFO_SMMU_EP_CFG(tx_smmu);
  982. } else {
  983. tx = &QDF_IPA_WDI_CONN_IN_PARAMS_TX(&pipe_in);
  984. tx_cfg = &QDF_IPA_WDI_SETUP_INFO_EP_CFG(tx);
  985. }
  986. QDF_IPA_EP_CFG_NAT_EN(tx_cfg) = IPA_BYPASS_NAT;
  987. QDF_IPA_EP_CFG_HDR_LEN(tx_cfg) = DP_IPA_UC_WLAN_TX_HDR_LEN;
  988. QDF_IPA_EP_CFG_HDR_OFST_PKT_SIZE_VALID(tx_cfg) = 0;
  989. QDF_IPA_EP_CFG_HDR_OFST_PKT_SIZE(tx_cfg) = 0;
  990. QDF_IPA_EP_CFG_HDR_ADDITIONAL_CONST_LEN(tx_cfg) = 0;
  991. QDF_IPA_EP_CFG_MODE(tx_cfg) = IPA_BASIC;
  992. QDF_IPA_EP_CFG_HDR_LITTLE_ENDIAN(tx_cfg) = true;
  993. /**
  994. * Transfer Ring: WBM Ring
  995. * Transfer Ring Doorbell PA: WBM Tail Pointer Address
  996. * Event Ring: TCL ring
  997. * Event Ring Doorbell PA: TCL Head Pointer Address
  998. */
  999. if (is_smmu_enabled)
  1000. dp_ipa_wdi_tx_smmu_params(soc, ipa_res, tx_smmu, over_gsi);
  1001. else
  1002. dp_ipa_wdi_tx_params(soc, ipa_res, tx, over_gsi);
  1003. /* RX PIPE */
  1004. if (QDF_IPA_WDI_CONN_IN_PARAMS_SMMU_ENABLED(&pipe_in)) {
  1005. rx_smmu = &QDF_IPA_WDI_CONN_IN_PARAMS_RX_SMMU(&pipe_in);
  1006. rx_cfg = &QDF_IPA_WDI_SETUP_INFO_SMMU_EP_CFG(rx_smmu);
  1007. } else {
  1008. rx = &QDF_IPA_WDI_CONN_IN_PARAMS_RX(&pipe_in);
  1009. rx_cfg = &QDF_IPA_WDI_SETUP_INFO_EP_CFG(rx);
  1010. }
  1011. QDF_IPA_EP_CFG_NAT_EN(rx_cfg) = IPA_BYPASS_NAT;
  1012. QDF_IPA_EP_CFG_HDR_LEN(rx_cfg) = DP_IPA_UC_WLAN_RX_HDR_LEN;
  1013. QDF_IPA_EP_CFG_HDR_OFST_PKT_SIZE_VALID(rx_cfg) = 1;
  1014. QDF_IPA_EP_CFG_HDR_OFST_PKT_SIZE(rx_cfg) = 0;
  1015. QDF_IPA_EP_CFG_HDR_ADDITIONAL_CONST_LEN(rx_cfg) = 0;
  1016. QDF_IPA_EP_CFG_HDR_OFST_METADATA_VALID(rx_cfg) = 0;
  1017. QDF_IPA_EP_CFG_HDR_METADATA_REG_VALID(rx_cfg) = 1;
  1018. QDF_IPA_EP_CFG_MODE(rx_cfg) = IPA_BASIC;
  1019. QDF_IPA_EP_CFG_HDR_LITTLE_ENDIAN(rx_cfg) = true;
  1020. /**
  1021. * Transfer Ring: REO Ring
  1022. * Transfer Ring Doorbell PA: REO Tail Pointer Address
  1023. * Event Ring: FW ring
  1024. * Event Ring Doorbell PA: FW Head Pointer Address
  1025. */
  1026. if (is_smmu_enabled)
  1027. dp_ipa_wdi_rx_smmu_params(soc, ipa_res, rx_smmu, over_gsi);
  1028. else
  1029. dp_ipa_wdi_rx_params(soc, ipa_res, rx, over_gsi);
  1030. QDF_IPA_WDI_CONN_IN_PARAMS_NOTIFY(&pipe_in) = ipa_w2i_cb;
  1031. QDF_IPA_WDI_CONN_IN_PARAMS_PRIV(&pipe_in) = ipa_priv;
  1032. /* Connect WDI IPA PIPEs */
  1033. ret = qdf_ipa_wdi_conn_pipes(&pipe_in, &pipe_out);
  1034. if (ret) {
  1035. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1036. "%s: ipa_wdi_conn_pipes: IPA pipe setup failed: ret=%d",
  1037. __func__, ret);
  1038. return QDF_STATUS_E_FAILURE;
  1039. }
  1040. /* IPA uC Doorbell registers */
  1041. dp_info("Tx DB PA=0x%x, Rx DB PA=0x%x",
  1042. (unsigned int)QDF_IPA_WDI_CONN_OUT_PARAMS_TX_UC_DB_PA(&pipe_out),
  1043. (unsigned int)QDF_IPA_WDI_CONN_OUT_PARAMS_RX_UC_DB_PA(&pipe_out));
  1044. ipa_res->tx_comp_doorbell_paddr =
  1045. QDF_IPA_WDI_CONN_OUT_PARAMS_TX_UC_DB_PA(&pipe_out);
  1046. ipa_res->rx_ready_doorbell_paddr =
  1047. QDF_IPA_WDI_CONN_OUT_PARAMS_RX_UC_DB_PA(&pipe_out);
  1048. return QDF_STATUS_SUCCESS;
  1049. }
  1050. /**
  1051. * dp_ipa_setup_iface() - Setup IPA header and register interface
  1052. * @ifname: Interface name
  1053. * @mac_addr: Interface MAC address
  1054. * @prod_client: IPA prod client type
  1055. * @cons_client: IPA cons client type
  1056. * @session_id: Session ID
  1057. * @is_ipv6_enabled: Is IPV6 enabled or not
  1058. *
  1059. * Return: QDF_STATUS
  1060. */
  1061. QDF_STATUS dp_ipa_setup_iface(char *ifname, uint8_t *mac_addr,
  1062. qdf_ipa_client_type_t prod_client,
  1063. qdf_ipa_client_type_t cons_client,
  1064. uint8_t session_id, bool is_ipv6_enabled)
  1065. {
  1066. qdf_ipa_wdi_reg_intf_in_params_t in;
  1067. qdf_ipa_wdi_hdr_info_t hdr_info;
  1068. struct dp_ipa_uc_tx_hdr uc_tx_hdr;
  1069. struct dp_ipa_uc_tx_hdr uc_tx_hdr_v6;
  1070. int ret = -EINVAL;
  1071. dp_debug("Add Partial hdr: %s, %pM", ifname, mac_addr);
  1072. qdf_mem_zero(&hdr_info, sizeof(qdf_ipa_wdi_hdr_info_t));
  1073. qdf_ether_addr_copy(uc_tx_hdr.eth.h_source, mac_addr);
  1074. /* IPV4 header */
  1075. uc_tx_hdr.eth.h_proto = qdf_htons(ETH_P_IP);
  1076. QDF_IPA_WDI_HDR_INFO_HDR(&hdr_info) = (uint8_t *)&uc_tx_hdr;
  1077. QDF_IPA_WDI_HDR_INFO_HDR_LEN(&hdr_info) = DP_IPA_UC_WLAN_TX_HDR_LEN;
  1078. QDF_IPA_WDI_HDR_INFO_HDR_TYPE(&hdr_info) = IPA_HDR_L2_ETHERNET_II;
  1079. QDF_IPA_WDI_HDR_INFO_DST_MAC_ADDR_OFFSET(&hdr_info) =
  1080. DP_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
  1081. QDF_IPA_WDI_REG_INTF_IN_PARAMS_NETDEV_NAME(&in) = ifname;
  1082. qdf_mem_copy(&(QDF_IPA_WDI_REG_INTF_IN_PARAMS_HDR_INFO(&in)[IPA_IP_v4]),
  1083. &hdr_info, sizeof(qdf_ipa_wdi_hdr_info_t));
  1084. QDF_IPA_WDI_REG_INTF_IN_PARAMS_ALT_DST_PIPE(&in) = cons_client;
  1085. QDF_IPA_WDI_REG_INTF_IN_PARAMS_IS_META_DATA_VALID(&in) = 1;
  1086. QDF_IPA_WDI_REG_INTF_IN_PARAMS_META_DATA(&in) =
  1087. htonl(session_id << 16);
  1088. QDF_IPA_WDI_REG_INTF_IN_PARAMS_META_DATA_MASK(&in) = htonl(0x00FF0000);
  1089. /* IPV6 header */
  1090. if (is_ipv6_enabled) {
  1091. qdf_mem_copy(&uc_tx_hdr_v6, &uc_tx_hdr,
  1092. DP_IPA_UC_WLAN_TX_HDR_LEN);
  1093. uc_tx_hdr_v6.eth.h_proto = qdf_htons(ETH_P_IPV6);
  1094. QDF_IPA_WDI_HDR_INFO_HDR(&hdr_info) = (uint8_t *)&uc_tx_hdr_v6;
  1095. qdf_mem_copy(&(QDF_IPA_WDI_REG_INTF_IN_PARAMS_HDR_INFO(&in)[IPA_IP_v6]),
  1096. &hdr_info, sizeof(qdf_ipa_wdi_hdr_info_t));
  1097. }
  1098. dp_debug("registering for session_id: %u", session_id);
  1099. ret = qdf_ipa_wdi_reg_intf(&in);
  1100. if (ret) {
  1101. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1102. "%s: ipa_wdi_reg_intf: register IPA interface falied: ret=%d",
  1103. __func__, ret);
  1104. return QDF_STATUS_E_FAILURE;
  1105. }
  1106. return QDF_STATUS_SUCCESS;
  1107. }
  1108. #else /* CONFIG_IPA_WDI_UNIFIED_API */
  1109. QDF_STATUS dp_ipa_setup(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  1110. void *ipa_i2w_cb, void *ipa_w2i_cb,
  1111. void *ipa_wdi_meter_notifier_cb,
  1112. uint32_t ipa_desc_size, void *ipa_priv,
  1113. bool is_rm_enabled, uint32_t *tx_pipe_handle,
  1114. uint32_t *rx_pipe_handle)
  1115. {
  1116. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1117. struct dp_pdev *pdev =
  1118. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  1119. struct dp_ipa_resources *ipa_res;
  1120. qdf_ipa_wdi_pipe_setup_info_t *tx;
  1121. qdf_ipa_wdi_pipe_setup_info_t *rx;
  1122. qdf_ipa_wdi_conn_in_params_t pipe_in;
  1123. qdf_ipa_wdi_conn_out_params_t pipe_out;
  1124. struct tcl_data_cmd *tcl_desc_ptr;
  1125. uint8_t *desc_addr;
  1126. uint32_t desc_size;
  1127. int ret;
  1128. if (!pdev) {
  1129. dp_err("%s invalid instance", __func__);
  1130. return QDF_STATUS_E_FAILURE;
  1131. }
  1132. ipa_res = &pdev->ipa_resource;
  1133. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  1134. return QDF_STATUS_SUCCESS;
  1135. qdf_mem_zero(&tx, sizeof(qdf_ipa_wdi_pipe_setup_info_t));
  1136. qdf_mem_zero(&rx, sizeof(qdf_ipa_wdi_pipe_setup_info_t));
  1137. qdf_mem_zero(&pipe_in, sizeof(pipe_in));
  1138. qdf_mem_zero(&pipe_out, sizeof(pipe_out));
  1139. /* TX PIPE */
  1140. /**
  1141. * Transfer Ring: WBM Ring
  1142. * Transfer Ring Doorbell PA: WBM Tail Pointer Address
  1143. * Event Ring: TCL ring
  1144. * Event Ring Doorbell PA: TCL Head Pointer Address
  1145. */
  1146. tx = &QDF_IPA_WDI_CONN_IN_PARAMS_TX(&pipe_in);
  1147. QDF_IPA_WDI_SETUP_INFO_NAT_EN(tx) = IPA_BYPASS_NAT;
  1148. QDF_IPA_WDI_SETUP_INFO_HDR_LEN(tx) = DP_IPA_UC_WLAN_TX_HDR_LEN;
  1149. QDF_IPA_WDI_SETUP_INFO_HDR_OFST_PKT_SIZE_VALID(tx) = 0;
  1150. QDF_IPA_WDI_SETUP_INFO_HDR_OFST_PKT_SIZE(tx) = 0;
  1151. QDF_IPA_WDI_SETUP_INFO_HDR_ADDITIONAL_CONST_LEN(tx) = 0;
  1152. QDF_IPA_WDI_SETUP_INFO_MODE(tx) = IPA_BASIC;
  1153. QDF_IPA_WDI_SETUP_INFO_HDR_LITTLE_ENDIAN(tx) = true;
  1154. QDF_IPA_WDI_SETUP_INFO_CLIENT(tx) = IPA_CLIENT_WLAN1_CONS;
  1155. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_BASE_PA(tx) =
  1156. ipa_res->tx_comp_ring_base_paddr;
  1157. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_SIZE(tx) =
  1158. ipa_res->tx_comp_ring_size;
  1159. /* WBM Tail Pointer Address */
  1160. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_DOORBELL_PA(tx) =
  1161. soc->ipa_uc_tx_rsc.ipa_wbm_tp_paddr;
  1162. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_BASE_PA(tx) =
  1163. ipa_res->tx_ring_base_paddr;
  1164. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_SIZE(tx) = ipa_res->tx_ring_size;
  1165. /* TCL Head Pointer Address */
  1166. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_DOORBELL_PA(tx) =
  1167. soc->ipa_uc_tx_rsc.ipa_tcl_hp_paddr;
  1168. QDF_IPA_WDI_SETUP_INFO_NUM_PKT_BUFFERS(tx) =
  1169. ipa_res->tx_num_alloc_buffer;
  1170. QDF_IPA_WDI_SETUP_INFO_PKT_OFFSET(tx) = 0;
  1171. /* Preprogram TCL descriptor */
  1172. desc_addr =
  1173. (uint8_t *)QDF_IPA_WDI_SETUP_INFO_DESC_FORMAT_TEMPLATE(tx);
  1174. desc_size = sizeof(struct tcl_data_cmd);
  1175. HAL_TX_DESC_SET_TLV_HDR(desc_addr, HAL_TX_TCL_DATA_TAG, desc_size);
  1176. tcl_desc_ptr = (struct tcl_data_cmd *)
  1177. (QDF_IPA_WDI_SETUP_INFO_DESC_FORMAT_TEMPLATE(tx) + 1);
  1178. tcl_desc_ptr->buf_addr_info.return_buffer_manager =
  1179. HAL_RX_BUF_RBM_SW2_BM;
  1180. tcl_desc_ptr->addrx_en = 1; /* Address X search enable in ASE */
  1181. tcl_desc_ptr->encap_type = HAL_TX_ENCAP_TYPE_ETHERNET;
  1182. tcl_desc_ptr->packet_offset = 2; /* padding for alignment */
  1183. /* RX PIPE */
  1184. /**
  1185. * Transfer Ring: REO Ring
  1186. * Transfer Ring Doorbell PA: REO Tail Pointer Address
  1187. * Event Ring: FW ring
  1188. * Event Ring Doorbell PA: FW Head Pointer Address
  1189. */
  1190. rx = &QDF_IPA_WDI_CONN_IN_PARAMS_RX(&pipe_in);
  1191. QDF_IPA_WDI_SETUP_INFO_NAT_EN(rx) = IPA_BYPASS_NAT;
  1192. QDF_IPA_WDI_SETUP_INFO_HDR_LEN(rx) = DP_IPA_UC_WLAN_RX_HDR_LEN;
  1193. QDF_IPA_WDI_SETUP_INFO_HDR_OFST_PKT_SIZE_VALID(rx) = 0;
  1194. QDF_IPA_WDI_SETUP_INFO_HDR_OFST_PKT_SIZE(rx) = 0;
  1195. QDF_IPA_WDI_SETUP_INFO_HDR_ADDITIONAL_CONST_LEN(rx) = 0;
  1196. QDF_IPA_WDI_SETUP_INFO_HDR_OFST_METADATA_VALID(rx) = 0;
  1197. QDF_IPA_WDI_SETUP_INFO_HDR_METADATA_REG_VALID(rx) = 1;
  1198. QDF_IPA_WDI_SETUP_INFO_MODE(rx) = IPA_BASIC;
  1199. QDF_IPA_WDI_SETUP_INFO_HDR_LITTLE_ENDIAN(rx) = true;
  1200. QDF_IPA_WDI_SETUP_INFO_CLIENT(rx) = IPA_CLIENT_WLAN1_PROD;
  1201. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_BASE_PA(rx) =
  1202. ipa_res->rx_rdy_ring_base_paddr;
  1203. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_SIZE(rx) =
  1204. ipa_res->rx_rdy_ring_size;
  1205. /* REO Tail Pointer Address */
  1206. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_DOORBELL_PA(rx) =
  1207. soc->ipa_uc_rx_rsc.ipa_reo_tp_paddr;
  1208. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_BASE_PA(rx) =
  1209. ipa_res->rx_refill_ring_base_paddr;
  1210. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_SIZE(rx) =
  1211. ipa_res->rx_refill_ring_size;
  1212. /* FW Head Pointer Address */
  1213. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_DOORBELL_PA(rx) =
  1214. soc->ipa_uc_rx_rsc.ipa_rx_refill_buf_hp_paddr;
  1215. QDF_IPA_WDI_SETUP_INFO_PKT_OFFSET(rx) = RX_PKT_TLVS_LEN +
  1216. L3_HEADER_PADDING;
  1217. QDF_IPA_WDI_CONN_IN_PARAMS_NOTIFY(&pipe_in) = ipa_w2i_cb;
  1218. QDF_IPA_WDI_CONN_IN_PARAMS_PRIV(&pipe_in) = ipa_priv;
  1219. /* Connect WDI IPA PIPE */
  1220. ret = qdf_ipa_wdi_conn_pipes(&pipe_in, &pipe_out);
  1221. if (ret) {
  1222. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1223. "%s: ipa_wdi_conn_pipes: IPA pipe setup failed: ret=%d",
  1224. __func__, ret);
  1225. return QDF_STATUS_E_FAILURE;
  1226. }
  1227. /* IPA uC Doorbell registers */
  1228. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  1229. "%s: Tx DB PA=0x%x, Rx DB PA=0x%x",
  1230. __func__,
  1231. (unsigned int)QDF_IPA_WDI_CONN_OUT_PARAMS_TX_UC_DB_PA(&pipe_out),
  1232. (unsigned int)QDF_IPA_WDI_CONN_OUT_PARAMS_RX_UC_DB_PA(&pipe_out));
  1233. ipa_res->tx_comp_doorbell_paddr =
  1234. QDF_IPA_WDI_CONN_OUT_PARAMS_TX_UC_DB_PA(&pipe_out);
  1235. ipa_res->tx_comp_doorbell_vaddr =
  1236. QDF_IPA_WDI_CONN_OUT_PARAMS_TX_UC_DB_VA(&pipe_out);
  1237. ipa_res->rx_ready_doorbell_paddr =
  1238. QDF_IPA_WDI_CONN_OUT_PARAMS_RX_UC_DB_PA(&pipe_out);
  1239. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  1240. "%s: Tx: %s=%pK, %s=%d, %s=%pK, %s=%pK, %s=%d, %s=%pK, %s=%d, %s=%pK",
  1241. __func__,
  1242. "transfer_ring_base_pa",
  1243. (void *)QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_BASE_PA(tx),
  1244. "transfer_ring_size",
  1245. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_SIZE(tx),
  1246. "transfer_ring_doorbell_pa",
  1247. (void *)QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_DOORBELL_PA(tx),
  1248. "event_ring_base_pa",
  1249. (void *)QDF_IPA_WDI_SETUP_INFO_EVENT_RING_BASE_PA(tx),
  1250. "event_ring_size",
  1251. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_SIZE(tx),
  1252. "event_ring_doorbell_pa",
  1253. (void *)QDF_IPA_WDI_SETUP_INFO_EVENT_RING_DOORBELL_PA(tx),
  1254. "num_pkt_buffers",
  1255. QDF_IPA_WDI_SETUP_INFO_NUM_PKT_BUFFERS(tx),
  1256. "tx_comp_doorbell_paddr",
  1257. (void *)ipa_res->tx_comp_doorbell_paddr);
  1258. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  1259. "%s: Rx: %s=%pK, %s=%d, %s=%pK, %s=%pK, %s=%d, %s=%pK, %s=%d, %s=%pK",
  1260. __func__,
  1261. "transfer_ring_base_pa",
  1262. (void *)QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_BASE_PA(rx),
  1263. "transfer_ring_size",
  1264. QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_SIZE(rx),
  1265. "transfer_ring_doorbell_pa",
  1266. (void *)QDF_IPA_WDI_SETUP_INFO_TRANSFER_RING_DOORBELL_PA(rx),
  1267. "event_ring_base_pa",
  1268. (void *)QDF_IPA_WDI_SETUP_INFO_EVENT_RING_BASE_PA(rx),
  1269. "event_ring_size",
  1270. QDF_IPA_WDI_SETUP_INFO_EVENT_RING_SIZE(rx),
  1271. "event_ring_doorbell_pa",
  1272. (void *)QDF_IPA_WDI_SETUP_INFO_EVENT_RING_DOORBELL_PA(rx),
  1273. "num_pkt_buffers",
  1274. QDF_IPA_WDI_SETUP_INFO_NUM_PKT_BUFFERS(rx),
  1275. "tx_comp_doorbell_paddr",
  1276. (void *)ipa_res->rx_ready_doorbell_paddr);
  1277. return QDF_STATUS_SUCCESS;
  1278. }
  1279. /**
  1280. * dp_ipa_setup_iface() - Setup IPA header and register interface
  1281. * @ifname: Interface name
  1282. * @mac_addr: Interface MAC address
  1283. * @prod_client: IPA prod client type
  1284. * @cons_client: IPA cons client type
  1285. * @session_id: Session ID
  1286. * @is_ipv6_enabled: Is IPV6 enabled or not
  1287. *
  1288. * Return: QDF_STATUS
  1289. */
  1290. QDF_STATUS dp_ipa_setup_iface(char *ifname, uint8_t *mac_addr,
  1291. qdf_ipa_client_type_t prod_client,
  1292. qdf_ipa_client_type_t cons_client,
  1293. uint8_t session_id, bool is_ipv6_enabled)
  1294. {
  1295. qdf_ipa_wdi_reg_intf_in_params_t in;
  1296. qdf_ipa_wdi_hdr_info_t hdr_info;
  1297. struct dp_ipa_uc_tx_hdr uc_tx_hdr;
  1298. struct dp_ipa_uc_tx_hdr uc_tx_hdr_v6;
  1299. int ret = -EINVAL;
  1300. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  1301. "%s: Add Partial hdr: %s, %pM",
  1302. __func__, ifname, mac_addr);
  1303. qdf_mem_zero(&hdr_info, sizeof(qdf_ipa_wdi_hdr_info_t));
  1304. qdf_ether_addr_copy(uc_tx_hdr.eth.h_source, mac_addr);
  1305. /* IPV4 header */
  1306. uc_tx_hdr.eth.h_proto = qdf_htons(ETH_P_IP);
  1307. QDF_IPA_WDI_HDR_INFO_HDR(&hdr_info) = (uint8_t *)&uc_tx_hdr;
  1308. QDF_IPA_WDI_HDR_INFO_HDR_LEN(&hdr_info) = DP_IPA_UC_WLAN_TX_HDR_LEN;
  1309. QDF_IPA_WDI_HDR_INFO_HDR_TYPE(&hdr_info) = IPA_HDR_L2_ETHERNET_II;
  1310. QDF_IPA_WDI_HDR_INFO_DST_MAC_ADDR_OFFSET(&hdr_info) =
  1311. DP_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
  1312. QDF_IPA_WDI_REG_INTF_IN_PARAMS_NETDEV_NAME(&in) = ifname;
  1313. qdf_mem_copy(&(QDF_IPA_WDI_REG_INTF_IN_PARAMS_HDR_INFO(&in)[IPA_IP_v4]),
  1314. &hdr_info, sizeof(qdf_ipa_wdi_hdr_info_t));
  1315. QDF_IPA_WDI_REG_INTF_IN_PARAMS_IS_META_DATA_VALID(&in) = 1;
  1316. QDF_IPA_WDI_REG_INTF_IN_PARAMS_META_DATA(&in) =
  1317. htonl(session_id << 16);
  1318. QDF_IPA_WDI_REG_INTF_IN_PARAMS_META_DATA_MASK(&in) = htonl(0x00FF0000);
  1319. /* IPV6 header */
  1320. if (is_ipv6_enabled) {
  1321. qdf_mem_copy(&uc_tx_hdr_v6, &uc_tx_hdr,
  1322. DP_IPA_UC_WLAN_TX_HDR_LEN);
  1323. uc_tx_hdr_v6.eth.h_proto = qdf_htons(ETH_P_IPV6);
  1324. QDF_IPA_WDI_HDR_INFO_HDR(&hdr_info) = (uint8_t *)&uc_tx_hdr_v6;
  1325. qdf_mem_copy(&(QDF_IPA_WDI_REG_INTF_IN_PARAMS_HDR_INFO(&in)[IPA_IP_v6]),
  1326. &hdr_info, sizeof(qdf_ipa_wdi_hdr_info_t));
  1327. }
  1328. ret = qdf_ipa_wdi_reg_intf(&in);
  1329. if (ret) {
  1330. dp_err("ipa_wdi_reg_intf: register IPA interface falied: ret=%d",
  1331. ret);
  1332. return QDF_STATUS_E_FAILURE;
  1333. }
  1334. return QDF_STATUS_SUCCESS;
  1335. }
  1336. #endif /* CONFIG_IPA_WDI_UNIFIED_API */
  1337. /**
  1338. * dp_ipa_cleanup() - Disconnect IPA pipes
  1339. * @tx_pipe_handle: Tx pipe handle
  1340. * @rx_pipe_handle: Rx pipe handle
  1341. *
  1342. * Return: QDF_STATUS
  1343. */
  1344. QDF_STATUS dp_ipa_cleanup(uint32_t tx_pipe_handle, uint32_t rx_pipe_handle)
  1345. {
  1346. int ret;
  1347. ret = qdf_ipa_wdi_disconn_pipes();
  1348. if (ret) {
  1349. dp_err("ipa_wdi_disconn_pipes: IPA pipe cleanup failed: ret=%d",
  1350. ret);
  1351. return QDF_STATUS_E_FAILURE;
  1352. }
  1353. return QDF_STATUS_SUCCESS;
  1354. }
  1355. /**
  1356. * dp_ipa_cleanup_iface() - Cleanup IPA header and deregister interface
  1357. * @ifname: Interface name
  1358. * @is_ipv6_enabled: Is IPV6 enabled or not
  1359. *
  1360. * Return: QDF_STATUS
  1361. */
  1362. QDF_STATUS dp_ipa_cleanup_iface(char *ifname, bool is_ipv6_enabled)
  1363. {
  1364. int ret;
  1365. ret = qdf_ipa_wdi_dereg_intf(ifname);
  1366. if (ret) {
  1367. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1368. "%s: ipa_wdi_dereg_intf: IPA pipe deregistration failed: ret=%d",
  1369. __func__, ret);
  1370. return QDF_STATUS_E_FAILURE;
  1371. }
  1372. return QDF_STATUS_SUCCESS;
  1373. }
  1374. QDF_STATUS dp_ipa_enable_pipes(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  1375. {
  1376. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1377. struct dp_pdev *pdev =
  1378. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  1379. QDF_STATUS result;
  1380. if (!pdev) {
  1381. dp_err("%s invalid instance", __func__);
  1382. return QDF_STATUS_E_FAILURE;
  1383. }
  1384. qdf_atomic_set(&soc->ipa_pipes_enabled, 1);
  1385. dp_ipa_handle_rx_buf_pool_smmu_mapping(soc, pdev, true);
  1386. result = qdf_ipa_wdi_enable_pipes();
  1387. if (result) {
  1388. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1389. "%s: Enable WDI PIPE fail, code %d",
  1390. __func__, result);
  1391. qdf_atomic_set(&soc->ipa_pipes_enabled, 0);
  1392. dp_ipa_handle_rx_buf_pool_smmu_mapping(soc, pdev, false);
  1393. return QDF_STATUS_E_FAILURE;
  1394. }
  1395. return QDF_STATUS_SUCCESS;
  1396. }
  1397. QDF_STATUS dp_ipa_disable_pipes(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  1398. {
  1399. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1400. struct dp_pdev *pdev =
  1401. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  1402. QDF_STATUS result;
  1403. if (!pdev) {
  1404. dp_err("%s invalid instance", __func__);
  1405. return QDF_STATUS_E_FAILURE;
  1406. }
  1407. result = qdf_ipa_wdi_disable_pipes();
  1408. if (result)
  1409. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1410. "%s: Disable WDI PIPE fail, code %d",
  1411. __func__, result);
  1412. qdf_atomic_set(&soc->ipa_pipes_enabled, 0);
  1413. dp_ipa_handle_rx_buf_pool_smmu_mapping(soc, pdev, false);
  1414. return result ? QDF_STATUS_E_FAILURE : QDF_STATUS_SUCCESS;
  1415. }
  1416. /**
  1417. * dp_ipa_set_perf_level() - Set IPA clock bandwidth based on data rates
  1418. * @client: Client type
  1419. * @max_supported_bw_mbps: Maximum bandwidth needed (in Mbps)
  1420. *
  1421. * Return: QDF_STATUS
  1422. */
  1423. QDF_STATUS dp_ipa_set_perf_level(int client, uint32_t max_supported_bw_mbps)
  1424. {
  1425. qdf_ipa_wdi_perf_profile_t profile;
  1426. QDF_STATUS result;
  1427. profile.client = client;
  1428. profile.max_supported_bw_mbps = max_supported_bw_mbps;
  1429. result = qdf_ipa_wdi_set_perf_profile(&profile);
  1430. if (result) {
  1431. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1432. "%s: ipa_wdi_set_perf_profile fail, code %d",
  1433. __func__, result);
  1434. return QDF_STATUS_E_FAILURE;
  1435. }
  1436. return QDF_STATUS_SUCCESS;
  1437. }
  1438. /**
  1439. * dp_ipa_intrabss_send - send IPA RX intra-bss frames
  1440. * @pdev: pdev
  1441. * @vdev: vdev
  1442. * @nbuf: skb
  1443. *
  1444. * Return: nbuf if TX fails and NULL if TX succeeds
  1445. */
  1446. static qdf_nbuf_t dp_ipa_intrabss_send(struct dp_pdev *pdev,
  1447. struct dp_vdev *vdev,
  1448. qdf_nbuf_t nbuf)
  1449. {
  1450. struct dp_peer *vdev_peer;
  1451. uint16_t len;
  1452. vdev_peer = vdev->vap_bss_peer;
  1453. if (qdf_unlikely(!vdev_peer))
  1454. return nbuf;
  1455. qdf_mem_zero(nbuf->cb, sizeof(nbuf->cb));
  1456. len = qdf_nbuf_len(nbuf);
  1457. if (dp_tx_send(dp_vdev_to_cdp_vdev(vdev), nbuf)) {
  1458. DP_STATS_INC_PKT(vdev_peer, rx.intra_bss.fail, 1, len);
  1459. return nbuf;
  1460. }
  1461. DP_STATS_INC_PKT(vdev_peer, rx.intra_bss.pkts, 1, len);
  1462. return NULL;
  1463. }
  1464. bool dp_ipa_rx_intrabss_fwd(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  1465. qdf_nbuf_t nbuf, bool *fwd_success)
  1466. {
  1467. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  1468. struct dp_vdev *vdev =
  1469. dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  1470. struct dp_pdev *pdev;
  1471. struct dp_peer *da_peer;
  1472. struct dp_peer *sa_peer;
  1473. qdf_nbuf_t nbuf_copy;
  1474. uint8_t da_is_bcmc;
  1475. struct ethhdr *eh;
  1476. uint8_t local_id;
  1477. *fwd_success = false; /* set default as failure */
  1478. /*
  1479. * WDI 3.0 skb->cb[] info from IPA driver
  1480. * skb->cb[0] = vdev_id
  1481. * skb->cb[1].bit#1 = da_is_bcmc
  1482. */
  1483. da_is_bcmc = ((uint8_t)nbuf->cb[1]) & 0x2;
  1484. if (qdf_unlikely(!vdev))
  1485. return false;
  1486. pdev = vdev->pdev;
  1487. if (qdf_unlikely(!pdev))
  1488. return false;
  1489. /* no fwd for station mode and just pass up to stack */
  1490. if (vdev->opmode == wlan_op_mode_sta)
  1491. return false;
  1492. if (da_is_bcmc) {
  1493. nbuf_copy = qdf_nbuf_copy(nbuf);
  1494. if (!nbuf_copy)
  1495. return false;
  1496. if (dp_ipa_intrabss_send(pdev, vdev, nbuf_copy))
  1497. qdf_nbuf_free(nbuf_copy);
  1498. else
  1499. *fwd_success = true;
  1500. /* return false to pass original pkt up to stack */
  1501. return false;
  1502. }
  1503. eh = (struct ethhdr *)qdf_nbuf_data(nbuf);
  1504. if (!qdf_mem_cmp(eh->h_dest, vdev->mac_addr.raw, QDF_MAC_ADDR_SIZE))
  1505. return false;
  1506. da_peer = dp_find_peer_by_addr((struct cdp_pdev *)pdev, eh->h_dest,
  1507. &local_id);
  1508. if (!da_peer)
  1509. return false;
  1510. if (da_peer->vdev != vdev)
  1511. return false;
  1512. sa_peer = dp_find_peer_by_addr((struct cdp_pdev *)pdev, eh->h_source,
  1513. &local_id);
  1514. if (!sa_peer)
  1515. return false;
  1516. if (sa_peer->vdev != vdev)
  1517. return false;
  1518. /*
  1519. * In intra-bss forwarding scenario, skb is allocated by IPA driver.
  1520. * Need to add skb to internal tracking table to avoid nbuf memory
  1521. * leak check for unallocated skb.
  1522. */
  1523. qdf_net_buf_debug_acquire_skb(nbuf, __FILE__, __LINE__);
  1524. if (dp_ipa_intrabss_send(pdev, vdev, nbuf))
  1525. qdf_nbuf_free(nbuf);
  1526. else
  1527. *fwd_success = true;
  1528. return true;
  1529. }
  1530. #ifdef MDM_PLATFORM
  1531. bool dp_ipa_is_mdm_platform(void)
  1532. {
  1533. return true;
  1534. }
  1535. #else
  1536. bool dp_ipa_is_mdm_platform(void)
  1537. {
  1538. return false;
  1539. }
  1540. #endif
  1541. /**
  1542. * dp_ipa_handle_rx_reo_reinject - Handle RX REO reinject skb buffer
  1543. * @soc: soc
  1544. * @nbuf: skb
  1545. *
  1546. * Return: nbuf if success and otherwise NULL
  1547. */
  1548. qdf_nbuf_t dp_ipa_handle_rx_reo_reinject(struct dp_soc *soc, qdf_nbuf_t nbuf)
  1549. {
  1550. uint8_t *rx_pkt_tlvs;
  1551. if (!wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx))
  1552. return nbuf;
  1553. /* WLAN IPA is run-time disabled */
  1554. if (!qdf_atomic_read(&soc->ipa_pipes_enabled))
  1555. return nbuf;
  1556. /* Linearize the skb since IPA assumes linear buffer */
  1557. if (qdf_likely(qdf_nbuf_is_frag(nbuf))) {
  1558. if (qdf_nbuf_linearize(nbuf)) {
  1559. dp_err_rl("nbuf linearize failed");
  1560. return NULL;
  1561. }
  1562. }
  1563. rx_pkt_tlvs = qdf_mem_malloc(RX_PKT_TLVS_LEN);
  1564. if (!rx_pkt_tlvs) {
  1565. dp_err_rl("rx_pkt_tlvs alloc failed");
  1566. return NULL;
  1567. }
  1568. qdf_mem_copy(rx_pkt_tlvs, qdf_nbuf_data(nbuf), RX_PKT_TLVS_LEN);
  1569. /* Pad L3_HEADER_PADDING before ethhdr and after rx_pkt_tlvs */
  1570. qdf_nbuf_push_head(nbuf, L3_HEADER_PADDING);
  1571. qdf_mem_copy(qdf_nbuf_data(nbuf), rx_pkt_tlvs, RX_PKT_TLVS_LEN);
  1572. /* L3_HEADDING_PADDING is not accounted for real skb length */
  1573. qdf_nbuf_set_len(nbuf, qdf_nbuf_len(nbuf) - L3_HEADER_PADDING);
  1574. qdf_mem_free(rx_pkt_tlvs);
  1575. return nbuf;
  1576. }
  1577. #endif