dp_main.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  1. /*
  2. * Copyright (c) 2016 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. #include <qdf_types.h>
  19. #include <qdf_lock.h>
  20. #include <hal_api.h>
  21. #include <hif.h>
  22. #include <htt.h>
  23. #include <wdi_event.h>
  24. #include <queue.h>
  25. #include "dp_htt.h"
  26. #include "dp_types.h"
  27. #include "dp_internal.h"
  28. #include "dp_tx.h"
  29. #include "dp_rx.h"
  30. #include "../../wlan_cfg/wlan_cfg.h"
  31. /**
  32. * dp_setup_srng - Internal function to setup SRNG rings used by data path
  33. */
  34. static int dp_srng_setup(struct dp_soc *soc, struct dp_srng *srng,
  35. int ring_type, int ring_num, int pdev_id, uint32_t num_entries)
  36. {
  37. void *hal_soc = soc->hal_soc;
  38. uint32_t entry_size = hal_srng_get_entrysize(hal_soc, ring_type);
  39. /* TODO: See if we should get align size from hal */
  40. uint32_t ring_base_align = 8;
  41. struct hal_srng_params ring_params;
  42. srng->hal_srng = NULL;
  43. srng->alloc_size = (num_entries * entry_size) + ring_base_align - 1;
  44. srng->base_vaddr_unaligned = qdf_mem_alloc_consistent(
  45. soc->osdev, NULL, srng->alloc_size,
  46. &(srng->base_paddr_unaligned));
  47. if (!srng->base_vaddr_unaligned) {
  48. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  49. "%s: alloc failed - ring_type: %d, ring_num %d\n",
  50. __func__, ring_type, ring_num);
  51. return QDF_STATUS_E_NOMEM;
  52. }
  53. ring_params.ring_base_vaddr = srng->base_vaddr_unaligned +
  54. ((unsigned long)srng->base_vaddr_unaligned % ring_base_align);
  55. ring_params.ring_base_paddr = srng->base_paddr_unaligned +
  56. ((unsigned long)(ring_params.ring_base_vaddr) -
  57. (unsigned long)srng->base_vaddr_unaligned);
  58. ring_params.num_entries = num_entries;
  59. /* TODO: Check MSI support and get MSI settings from HIF layer */
  60. ring_params.msi_data = 0;
  61. ring_params.msi_addr = 0;
  62. /* TODO: Setup interrupt timer and batch counter thresholds for
  63. * interrupt mitigation based on ring type
  64. */
  65. ring_params.intr_timer_thres_us = 8;
  66. ring_params.intr_batch_cntr_thres_entries = 1;
  67. /* TODO: Currently hal layer takes care of endianness related settings.
  68. * See if these settings need to passed from DP layer
  69. */
  70. ring_params.flags = 0;
  71. /* Enable low threshold interrupts for rx buffer rings (regular and
  72. * monitor buffer rings.
  73. * TODO: See if this is required for any other ring
  74. */
  75. if ((ring_type == RXDMA_BUF) || (ring_type == RXDMA_MONITOR_BUF)) {
  76. /* TODO: Setting low threshold to 1/8th of ring size
  77. * see if this needs to be configurable
  78. */
  79. ring_params.low_threshold = num_entries >> 3;
  80. ring_params.flags |= HAL_SRNG_LOW_THRES_INTR_ENABLE;
  81. }
  82. srng->hal_srng = hal_srng_setup(hal_soc, ring_type, ring_num,
  83. pdev_id, &ring_params);
  84. return 0;
  85. }
  86. /**
  87. * dp_srng_cleanup - Internal function to cleanup SRNG rings used by data path
  88. * Any buffers allocated and attached to ring entries are expected to be freed
  89. * before calling this function.
  90. */
  91. static void dp_srng_cleanup(struct dp_soc *soc, struct dp_srng *srng,
  92. int ring_type, int ring_num)
  93. {
  94. if (!srng->hal_srng) {
  95. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  96. "%s: Ring type: %d, num:%d not setup\n",
  97. __func__, ring_type, ring_num);
  98. return;
  99. }
  100. hal_srng_cleanup(soc->hal_soc, srng->hal_srng);
  101. qdf_mem_free_consistent(soc->osdev, NULL,
  102. srng->alloc_size,
  103. srng->base_vaddr_unaligned,
  104. srng->base_paddr_unaligned, 0);
  105. }
  106. /* TODO: Need this interface from HIF */
  107. void *hif_get_hal_handle(void *hif_handle);
  108. /*
  109. * dp_service_srngs() - Top level interrupt handler for DP Ring interrupts
  110. * @dp_ctx: DP SOC handle
  111. * @budget: Number of frames/descriptors that can be processed in one shot
  112. *
  113. * Return: remaining budget/quota for the soc device
  114. */
  115. uint32_t dp_service_srngs(void *dp_ctx, uint32_t dp_budget)
  116. {
  117. struct dp_intr *int_ctx = (struct dp_intr *)dp_ctx;
  118. struct dp_soc *soc = int_ctx->soc;
  119. int ring = 0;
  120. uint32_t work_done = 0;
  121. uint32_t budget = dp_budget;
  122. uint8_t tx_mask = int_ctx->tx_ring_mask;
  123. uint8_t rx_mask = int_ctx->rx_ring_mask;
  124. /* Process Tx completion interrupts first to return back buffers */
  125. if (tx_mask) {
  126. for (ring = 0; ring < soc->num_tcl_data_rings; ring++) {
  127. if (tx_mask & (1 << ring)) {
  128. work_done =
  129. dp_tx_comp_handler(soc, ring, budget);
  130. budget -= work_done;
  131. if (work_done)
  132. DP_TRACE(INFO, "tx mask 0x%x ring %d, budget %d\n",
  133. tx_mask, ring, budget);
  134. if (budget <= 0)
  135. goto budget_done;
  136. }
  137. }
  138. }
  139. /* Process Rx interrupts */
  140. if (rx_mask) {
  141. for (ring = 0; ring < soc->num_reo_dest_rings; ring++) {
  142. if (rx_mask & (1 << ring)) {
  143. work_done =
  144. dp_rx_process(soc,
  145. soc->reo_dest_ring[ring].hal_srng,
  146. budget);
  147. budget -= work_done;
  148. if (work_done)
  149. DP_TRACE(INFO, "rx mask 0x%x ring %d, budget %d\n",
  150. tx_mask, ring, budget);
  151. if (budget <= 0)
  152. goto budget_done;
  153. }
  154. }
  155. }
  156. budget_done:
  157. return dp_budget - budget;
  158. }
  159. /* dp_interrupt_timer()- timer poll for interrupts
  160. *
  161. * @arg: SoC Handle
  162. *
  163. * Return:
  164. *
  165. */
  166. #ifdef DP_INTR_POLL_BASED
  167. void dp_interrupt_timer(void *arg)
  168. {
  169. struct dp_soc *soc = (struct dp_soc *) arg;
  170. int i;
  171. for (i = 0 ; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++)
  172. dp_service_srngs(&soc->intr_ctx[i], 0xffff);
  173. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  174. }
  175. /*
  176. * dp_soc_interrupt_attach() - Register handlers for DP interrupts
  177. * @txrx_soc: DP SOC handle
  178. *
  179. * Host driver will register for “DP_NUM_INTERRUPT_CONTEXTS” number of NAPI
  180. * contexts. Each NAPI context will have a tx_ring_mask , rx_ring_mask ,and
  181. * rx_monitor_ring mask to indicate the rings that are processed by the handler.
  182. *
  183. * Return: 0 for success. nonzero for failure.
  184. */
  185. QDF_STATUS dp_soc_interrupt_attach(void *txrx_soc)
  186. {
  187. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  188. int i;
  189. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  190. soc->intr_ctx[i].tx_ring_mask = 0xF;
  191. soc->intr_ctx[i].rx_ring_mask = 0xF;
  192. soc->intr_ctx[i].rx_mon_ring_mask = 0xF;
  193. soc->intr_ctx[i].soc = soc;
  194. }
  195. qdf_timer_init(soc->osdev, &soc->int_timer,
  196. dp_interrupt_timer, (void *)soc,
  197. QDF_TIMER_TYPE_WAKE_APPS);
  198. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  199. return QDF_STATUS_SUCCESS;
  200. }
  201. /*
  202. * dp_soc_interrupt_detach() - Deregister any allocations done for interrupts
  203. * @txrx_soc: DP SOC handle
  204. *
  205. * Return: void
  206. */
  207. void dp_soc_interrupt_detach(void *txrx_soc)
  208. {
  209. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  210. qdf_timer_stop(&soc->int_timer);
  211. qdf_timer_detach(&soc->int_timer);
  212. }
  213. #else
  214. /*
  215. * dp_soc_interrupt_attach() - Register handlers for DP interrupts
  216. * @txrx_soc: DP SOC handle
  217. *
  218. * Host driver will register for “DP_NUM_INTERRUPT_CONTEXTS” number of NAPI
  219. * contexts. Each NAPI context will have a tx_ring_mask , rx_ring_mask ,and
  220. * rx_monitor_ring mask to indicate the rings that are processed by the handler.
  221. *
  222. * Return: 0 for success. nonzero for failure.
  223. */
  224. QDF_STATUS dp_soc_interrupt_attach(void *txrx_soc)
  225. {
  226. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  227. int i = 0;
  228. int num_irq = 0;
  229. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  230. int j = 0;
  231. int ret = 0;
  232. /* Map of IRQ ids registered with one interrupt context */
  233. int irq_id_map[HIF_MAX_GRP_IRQ];
  234. int tx_mask =
  235. wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, i);
  236. int rx_mask =
  237. wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, i);
  238. int rx_mon_mask =
  239. wlan_cfg_get_rx_mon_ring_mask(soc->wlan_cfg_ctx, i);
  240. soc->intr_ctx[i].tx_ring_mask = tx_mask;
  241. soc->intr_ctx[i].rx_ring_mask = rx_mask;
  242. soc->intr_ctx[i].rx_mon_ring_mask = rx_mon_mask;
  243. soc->intr_ctx[i].soc = soc;
  244. num_irq = 0;
  245. for (j = 0; j < HIF_MAX_GRP_IRQ; j++) {
  246. if (tx_mask & (1 << j)) {
  247. irq_id_map[num_irq++] =
  248. (wbm2host_tx_completions_ring1 - j);
  249. }
  250. if (rx_mask & (1 << j)) {
  251. irq_id_map[num_irq++] =
  252. (reo2host_destination_ring1 - j);
  253. }
  254. if (rx_mon_mask & (1 << j)) {
  255. irq_id_map[num_irq++] =
  256. (rxdma2host_monitor_destination_mac1
  257. - j);
  258. }
  259. }
  260. ret = hif_register_ext_group_int_handler(soc->hif_handle,
  261. num_irq, irq_id_map,
  262. dp_service_srngs,
  263. &soc->intr_ctx[i]);
  264. if (ret) {
  265. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  266. "%s: failed, ret = %d", __func__, ret);
  267. return QDF_STATUS_E_FAILURE;
  268. }
  269. }
  270. return QDF_STATUS_SUCCESS;
  271. }
  272. /*
  273. * dp_soc_interrupt_detach() - Deregister any allocations done for interrupts
  274. * @txrx_soc: DP SOC handle
  275. *
  276. * Return: void
  277. */
  278. void dp_soc_interrupt_detach(void *txrx_soc)
  279. {
  280. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  281. int i;
  282. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  283. soc->intr_ctx[i].tx_ring_mask = 0;
  284. soc->intr_ctx[i].rx_ring_mask = 0;
  285. soc->intr_ctx[i].rx_mon_ring_mask = 0;
  286. }
  287. }
  288. #endif
  289. #define AVG_MAX_MPDUS_PER_TID 128
  290. #define AVG_TIDS_PER_CLIENT 2
  291. #define AVG_FLOWS_PER_TID 2
  292. #define AVG_MSDUS_PER_FLOW 128
  293. #define AVG_MSDUS_PER_MPDU 4
  294. /*
  295. * Allocate and setup link descriptor pool that will be used by HW for
  296. * various link and queue descriptors and managed by WBM
  297. */
  298. static int dp_hw_link_desc_pool_setup(struct dp_soc *soc)
  299. {
  300. int link_desc_size = hal_get_link_desc_size(soc->hal_soc);
  301. int link_desc_align = hal_get_link_desc_align(soc->hal_soc);
  302. uint32_t max_clients = wlan_cfg_get_max_clients(soc->wlan_cfg_ctx);
  303. uint32_t num_mpdus_per_link_desc =
  304. hal_num_mpdus_per_link_desc(soc->hal_soc);
  305. uint32_t num_msdus_per_link_desc =
  306. hal_num_msdus_per_link_desc(soc->hal_soc);
  307. uint32_t num_mpdu_links_per_queue_desc =
  308. hal_num_mpdu_links_per_queue_desc(soc->hal_soc);
  309. uint32_t max_alloc_size = wlan_cfg_max_alloc_size(soc->wlan_cfg_ctx);
  310. uint32_t total_link_descs, total_mem_size;
  311. uint32_t num_mpdu_link_descs, num_mpdu_queue_descs;
  312. uint32_t num_tx_msdu_link_descs, num_rx_msdu_link_descs;
  313. uint32_t num_link_desc_banks;
  314. uint32_t last_bank_size = 0;
  315. uint32_t entry_size, num_entries;
  316. int i;
  317. /* Only Tx queue descriptors are allocated from common link descriptor
  318. * pool Rx queue descriptors are not included in this because (REO queue
  319. * extension descriptors) they are expected to be allocated contiguously
  320. * with REO queue descriptors
  321. */
  322. num_mpdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  323. AVG_MAX_MPDUS_PER_TID) / num_mpdus_per_link_desc;
  324. num_mpdu_queue_descs = num_mpdu_link_descs /
  325. num_mpdu_links_per_queue_desc;
  326. num_tx_msdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  327. AVG_FLOWS_PER_TID * AVG_MSDUS_PER_FLOW) /
  328. num_msdus_per_link_desc;
  329. num_rx_msdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  330. AVG_MAX_MPDUS_PER_TID * AVG_MSDUS_PER_MPDU) / 6;
  331. num_entries = num_mpdu_link_descs + num_mpdu_queue_descs +
  332. num_tx_msdu_link_descs + num_rx_msdu_link_descs;
  333. /* Round up to power of 2 */
  334. total_link_descs = 1;
  335. while (total_link_descs < num_entries)
  336. total_link_descs <<= 1;
  337. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  338. "%s: total_link_descs: %u, link_desc_size: %d\n",
  339. __func__, total_link_descs, link_desc_size);
  340. total_mem_size = total_link_descs * link_desc_size;
  341. total_mem_size += link_desc_align;
  342. if (total_mem_size <= max_alloc_size) {
  343. num_link_desc_banks = 0;
  344. last_bank_size = total_mem_size;
  345. } else {
  346. num_link_desc_banks = (total_mem_size) /
  347. (max_alloc_size - link_desc_align);
  348. last_bank_size = total_mem_size %
  349. (max_alloc_size - link_desc_align);
  350. }
  351. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  352. "%s: total_mem_size: %d, num_link_desc_banks: %u\n",
  353. __func__, total_mem_size, num_link_desc_banks);
  354. for (i = 0; i < num_link_desc_banks; i++) {
  355. soc->link_desc_banks[i].base_vaddr_unaligned =
  356. qdf_mem_alloc_consistent(soc->osdev, NULL,
  357. max_alloc_size,
  358. &(soc->link_desc_banks[i].base_paddr_unaligned));
  359. soc->link_desc_banks[i].size = max_alloc_size;
  360. soc->link_desc_banks[i].base_vaddr = (void *)((unsigned long)(
  361. soc->link_desc_banks[i].base_vaddr_unaligned) +
  362. ((unsigned long)(
  363. soc->link_desc_banks[i].base_vaddr_unaligned) %
  364. link_desc_align));
  365. soc->link_desc_banks[i].base_paddr = (unsigned long)(
  366. soc->link_desc_banks[i].base_paddr_unaligned) +
  367. ((unsigned long)(soc->link_desc_banks[i].base_vaddr) -
  368. (unsigned long)(
  369. soc->link_desc_banks[i].base_vaddr_unaligned));
  370. if (!soc->link_desc_banks[i].base_vaddr_unaligned) {
  371. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  372. "%s: Link descriptor memory alloc failed\n",
  373. __func__);
  374. goto fail;
  375. }
  376. }
  377. if (last_bank_size) {
  378. /* Allocate last bank in case total memory required is not exact
  379. * multiple of max_alloc_size
  380. */
  381. soc->link_desc_banks[i].base_vaddr_unaligned =
  382. qdf_mem_alloc_consistent(soc->osdev, NULL,
  383. last_bank_size,
  384. &(soc->link_desc_banks[i].base_paddr_unaligned));
  385. soc->link_desc_banks[i].size = last_bank_size;
  386. soc->link_desc_banks[i].base_vaddr = (void *)((unsigned long)
  387. (soc->link_desc_banks[i].base_vaddr_unaligned) +
  388. ((unsigned long)(
  389. soc->link_desc_banks[i].base_vaddr_unaligned) %
  390. link_desc_align));
  391. soc->link_desc_banks[i].base_paddr =
  392. (unsigned long)(
  393. soc->link_desc_banks[i].base_paddr_unaligned) +
  394. ((unsigned long)(soc->link_desc_banks[i].base_vaddr) -
  395. (unsigned long)(
  396. soc->link_desc_banks[i].base_vaddr_unaligned));
  397. }
  398. /* Allocate and setup link descriptor idle list for HW internal use */
  399. entry_size = hal_srng_get_entrysize(soc->hal_soc, WBM_IDLE_LINK);
  400. total_mem_size = entry_size * total_link_descs;
  401. if (total_mem_size <= max_alloc_size) {
  402. void *desc;
  403. if (dp_srng_setup(soc, &soc->wbm_idle_link_ring,
  404. WBM_IDLE_LINK, 0, 0, total_link_descs)) {
  405. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  406. "%s: Link desc idle ring setup failed\n",
  407. __func__);
  408. goto fail;
  409. }
  410. hal_srng_access_start_unlocked(soc->hal_soc,
  411. soc->wbm_idle_link_ring.hal_srng);
  412. for (i = 0; i < MAX_LINK_DESC_BANKS &&
  413. soc->link_desc_banks[i].base_paddr; i++) {
  414. uint32_t num_entries = (soc->link_desc_banks[i].size -
  415. (unsigned long)(
  416. soc->link_desc_banks[i].base_vaddr) -
  417. (unsigned long)(
  418. soc->link_desc_banks[i].base_vaddr_unaligned))
  419. / link_desc_size;
  420. unsigned long paddr = (unsigned long)(
  421. soc->link_desc_banks[i].base_paddr);
  422. while (num_entries && (desc = hal_srng_src_get_next(
  423. soc->hal_soc,
  424. soc->wbm_idle_link_ring.hal_srng))) {
  425. hal_set_link_desc_addr(desc, i, paddr);
  426. num_entries--;
  427. paddr += link_desc_size;
  428. }
  429. }
  430. hal_srng_access_end_unlocked(soc->hal_soc,
  431. soc->wbm_idle_link_ring.hal_srng);
  432. } else {
  433. uint32_t num_scatter_bufs;
  434. uint32_t num_entries_per_buf;
  435. uint32_t rem_entries;
  436. uint8_t *scatter_buf_ptr;
  437. uint16_t scatter_buf_num;
  438. soc->wbm_idle_scatter_buf_size =
  439. hal_idle_list_scatter_buf_size(soc->hal_soc);
  440. num_entries_per_buf = hal_idle_scatter_buf_num_entries(
  441. soc->hal_soc, soc->wbm_idle_scatter_buf_size);
  442. num_scatter_bufs = (total_mem_size /
  443. soc->wbm_idle_scatter_buf_size) + (total_mem_size %
  444. soc->wbm_idle_scatter_buf_size) ? 1 : 0;
  445. for (i = 0; i < num_scatter_bufs; i++) {
  446. soc->wbm_idle_scatter_buf_base_vaddr[i] =
  447. qdf_mem_alloc_consistent(soc->osdev, NULL,
  448. soc->wbm_idle_scatter_buf_size,
  449. &(soc->wbm_idle_scatter_buf_base_paddr[i]));
  450. if (soc->wbm_idle_scatter_buf_base_vaddr[i] == NULL) {
  451. QDF_TRACE(QDF_MODULE_ID_TXRX,
  452. QDF_TRACE_LEVEL_ERROR,
  453. "%s:Scatter list memory alloc failed\n",
  454. __func__);
  455. goto fail;
  456. }
  457. }
  458. /* Populate idle list scatter buffers with link descriptor
  459. * pointers
  460. */
  461. scatter_buf_num = 0;
  462. scatter_buf_ptr = (uint8_t *)(
  463. soc->wbm_idle_scatter_buf_base_vaddr[scatter_buf_num]);
  464. rem_entries = num_entries_per_buf;
  465. for (i = 0; i < MAX_LINK_DESC_BANKS &&
  466. soc->link_desc_banks[i].base_paddr; i++) {
  467. uint32_t num_link_descs =
  468. (soc->link_desc_banks[i].size -
  469. (unsigned long)(
  470. soc->link_desc_banks[i].base_vaddr) -
  471. (unsigned long)(
  472. soc->link_desc_banks[i].base_vaddr_unaligned)) /
  473. link_desc_size;
  474. unsigned long paddr = (unsigned long)(
  475. soc->link_desc_banks[i].base_paddr);
  476. void *desc = NULL;
  477. while (num_link_descs && (desc =
  478. hal_srng_src_get_next(soc->hal_soc,
  479. soc->wbm_idle_link_ring.hal_srng))) {
  480. hal_set_link_desc_addr((void *)scatter_buf_ptr,
  481. i, paddr);
  482. num_link_descs--;
  483. paddr += link_desc_size;
  484. if (rem_entries) {
  485. rem_entries--;
  486. scatter_buf_ptr += link_desc_size;
  487. } else {
  488. rem_entries = num_entries_per_buf;
  489. scatter_buf_num++;
  490. scatter_buf_ptr = (uint8_t *)(
  491. soc->wbm_idle_scatter_buf_base_vaddr[
  492. scatter_buf_num]);
  493. }
  494. }
  495. }
  496. /* Setup link descriptor idle list in HW */
  497. hal_setup_link_idle_list(soc->hal_soc,
  498. soc->wbm_idle_scatter_buf_base_paddr,
  499. soc->wbm_idle_scatter_buf_base_vaddr,
  500. num_scatter_bufs, soc->wbm_idle_scatter_buf_size,
  501. (uint32_t)(scatter_buf_ptr -
  502. (uint8_t *)(soc->wbm_idle_scatter_buf_base_vaddr[
  503. scatter_buf_num])));
  504. }
  505. return 0;
  506. fail:
  507. if (soc->wbm_idle_link_ring.hal_srng) {
  508. dp_srng_cleanup(soc->hal_soc, &soc->wbm_idle_link_ring,
  509. WBM_IDLE_LINK, 0);
  510. }
  511. for (i = 0; i < MAX_IDLE_SCATTER_BUFS; i++) {
  512. if (soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  513. qdf_mem_free_consistent(soc->osdev, NULL,
  514. soc->wbm_idle_scatter_buf_size,
  515. soc->wbm_idle_scatter_buf_base_vaddr[i],
  516. soc->wbm_idle_scatter_buf_base_paddr[i], 0);
  517. }
  518. }
  519. for (i = 0; i < MAX_LINK_DESC_BANKS; i++) {
  520. if (soc->link_desc_banks[i].base_vaddr_unaligned) {
  521. qdf_mem_free_consistent(soc->osdev, NULL,
  522. soc->link_desc_banks[i].size,
  523. soc->link_desc_banks[i].base_vaddr_unaligned,
  524. soc->link_desc_banks[i].base_paddr_unaligned,
  525. 0);
  526. }
  527. }
  528. return QDF_STATUS_E_FAILURE;
  529. }
  530. /*
  531. * Free link descriptor pool that was setup HW
  532. */
  533. void dp_hw_link_desc_pool_cleanup(struct dp_soc *soc)
  534. {
  535. int i;
  536. if (soc->wbm_idle_link_ring.hal_srng) {
  537. dp_srng_cleanup(soc->hal_soc, &soc->wbm_idle_link_ring,
  538. WBM_IDLE_LINK, 0);
  539. }
  540. for (i = 0; i < MAX_IDLE_SCATTER_BUFS; i++) {
  541. if (soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  542. qdf_mem_free_consistent(soc->osdev, NULL,
  543. soc->wbm_idle_scatter_buf_size,
  544. soc->wbm_idle_scatter_buf_base_vaddr[i],
  545. soc->wbm_idle_scatter_buf_base_paddr[i], 0);
  546. }
  547. }
  548. for (i = 0; i < MAX_LINK_DESC_BANKS; i++) {
  549. if (soc->link_desc_banks[i].base_vaddr_unaligned) {
  550. qdf_mem_free_consistent(soc->osdev, NULL,
  551. soc->link_desc_banks[i].size,
  552. soc->link_desc_banks[i].base_vaddr_unaligned,
  553. soc->link_desc_banks[i].base_paddr_unaligned,
  554. 0);
  555. }
  556. }
  557. }
  558. /* TODO: Following should be configurable */
  559. #define WBM_RELEASE_RING_SIZE 64
  560. #define TCL_DATA_RING_SIZE 512
  561. #define TCL_CMD_RING_SIZE 32
  562. #define TCL_STATUS_RING_SIZE 32
  563. #define REO_DST_RING_SIZE 2048
  564. #define REO_REINJECT_RING_SIZE 32
  565. #define RX_RELEASE_RING_SIZE 256
  566. #define REO_EXCEPTION_RING_SIZE 128
  567. #define REO_CMD_RING_SIZE 32
  568. #define REO_STATUS_RING_SIZE 32
  569. #define RXDMA_BUF_RING_SIZE 8192
  570. #define RXDMA_MONITOR_BUF_RING_SIZE 8192
  571. #define RXDMA_MONITOR_DST_RING_SIZE 2048
  572. #define RXDMA_MONITOR_STATUS_RING_SIZE 2048
  573. /*
  574. * dp_soc_cmn_setup() - Common SoC level initializion
  575. * @soc: Datapath SOC handle
  576. *
  577. * This is an internal function used to setup common SOC data structures,
  578. * to be called from PDEV attach after receiving HW mode capabilities from FW
  579. */
  580. static int dp_soc_cmn_setup(struct dp_soc *soc)
  581. {
  582. int i;
  583. if (soc->cmn_init_done)
  584. return 0;
  585. if (dp_peer_find_attach(soc))
  586. goto fail0;
  587. if (dp_hw_link_desc_pool_setup(soc))
  588. goto fail1;
  589. /* Setup SRNG rings */
  590. /* Common rings */
  591. if (dp_srng_setup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0, 0,
  592. WBM_RELEASE_RING_SIZE)) {
  593. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  594. "%s: dp_srng_setup failed for wbm_desc_rel_ring\n",
  595. __func__);
  596. goto fail1;
  597. }
  598. soc->num_tcl_data_rings = 0;
  599. /* Tx data rings */
  600. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  601. soc->num_tcl_data_rings =
  602. wlan_cfg_num_tcl_data_rings(soc->wlan_cfg_ctx);
  603. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  604. if (dp_srng_setup(soc, &soc->tcl_data_ring[i],
  605. TCL_DATA, i, 0, TCL_DATA_RING_SIZE)) {
  606. QDF_TRACE(QDF_MODULE_ID_TXRX,
  607. QDF_TRACE_LEVEL_ERROR,
  608. "%s: dp_srng_setup failed for tcl_data_ring[%d]\n",
  609. __func__, i);
  610. goto fail1;
  611. }
  612. if (dp_srng_setup(soc, &soc->tx_comp_ring[i],
  613. WBM2SW_RELEASE, i, 0, TCL_DATA_RING_SIZE)) {
  614. QDF_TRACE(QDF_MODULE_ID_TXRX,
  615. QDF_TRACE_LEVEL_ERROR,
  616. "%s: dp_srng_setup failed for tx_comp_ring[%d]\n",
  617. __func__, i);
  618. goto fail1;
  619. }
  620. }
  621. } else {
  622. /* This will be incremented during per pdev ring setup */
  623. soc->num_tcl_data_rings = 0;
  624. }
  625. if (dp_tx_soc_attach(soc)) {
  626. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  627. "%s: dp_tx_soc_attach failed\n", __func__);
  628. goto fail1;
  629. }
  630. /* TCL command and status rings */
  631. if (dp_srng_setup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0, 0,
  632. TCL_CMD_RING_SIZE)) {
  633. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  634. "%s: dp_srng_setup failed for tcl_cmd_ring\n",
  635. __func__);
  636. goto fail1;
  637. }
  638. if (dp_srng_setup(soc, &soc->tcl_status_ring, TCL_STATUS, 0, 0,
  639. TCL_STATUS_RING_SIZE)) {
  640. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  641. "%s: dp_srng_setup failed for tcl_status_ring\n",
  642. __func__);
  643. goto fail1;
  644. }
  645. /* TBD: call dp_tx_init to setup Tx SW descriptors and MSDU extension
  646. * descriptors
  647. */
  648. /* Rx data rings */
  649. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  650. soc->num_reo_dest_rings =
  651. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  652. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  653. if (dp_srng_setup(soc, &soc->reo_dest_ring[i], REO_DST,
  654. i, 0, REO_DST_RING_SIZE)) {
  655. QDF_TRACE(QDF_MODULE_ID_TXRX,
  656. QDF_TRACE_LEVEL_ERROR,
  657. "%s: dp_srng_setup failed for reo_dest_ring[%d]\n",
  658. __func__, i);
  659. goto fail1;
  660. }
  661. }
  662. } else {
  663. /* This will be incremented during per pdev ring setup */
  664. soc->num_reo_dest_rings = 0;
  665. }
  666. /* TBD: call dp_rx_init to setup Rx SW descriptors */
  667. /* REO reinjection ring */
  668. if (dp_srng_setup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0, 0,
  669. REO_REINJECT_RING_SIZE)) {
  670. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  671. "%s: dp_srng_setup failed for reo_reinject_ring\n",
  672. __func__);
  673. goto fail1;
  674. }
  675. /* Rx release ring */
  676. if (dp_srng_setup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 3, 0,
  677. RX_RELEASE_RING_SIZE)) {
  678. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  679. "%s: dp_srng_setup failed for rx_rel_ring\n",
  680. __func__);
  681. goto fail1;
  682. }
  683. /* Rx exception ring */
  684. if (dp_srng_setup(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0,
  685. MAX_REO_DEST_RINGS, REO_EXCEPTION_RING_SIZE)) {
  686. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  687. "%s: dp_srng_setup failed for reo_exception_ring\n",
  688. __func__);
  689. goto fail1;
  690. }
  691. /* REO command and status rings */
  692. if (dp_srng_setup(soc, &soc->reo_cmd_ring, REO_CMD, 0, 0,
  693. REO_CMD_RING_SIZE)) {
  694. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  695. "%s: dp_srng_setup failed for reo_cmd_ring\n",
  696. __func__);
  697. goto fail1;
  698. }
  699. if (dp_srng_setup(soc, &soc->reo_status_ring, REO_STATUS, 0, 0,
  700. REO_STATUS_RING_SIZE)) {
  701. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  702. "%s: dp_srng_setup failed for reo_status_ring\n",
  703. __func__);
  704. goto fail1;
  705. }
  706. dp_soc_interrupt_attach(soc);
  707. /* Setup HW REO */
  708. hal_reo_setup(soc->hal_soc);
  709. soc->cmn_init_done = 1;
  710. return 0;
  711. fail1:
  712. /*
  713. * Cleanup will be done as part of soc_detach, which will
  714. * be called on pdev attach failure
  715. */
  716. fail0:
  717. return QDF_STATUS_E_FAILURE;
  718. }
  719. static void dp_pdev_detach_wifi3(void *txrx_pdev, int force);
  720. /*
  721. * dp_pdev_attach_wifi3() - attach txrx pdev
  722. * @osif_pdev: Opaque PDEV handle from OSIF/HDD
  723. * @txrx_soc: Datapath SOC handle
  724. * @htc_handle: HTC handle for host-target interface
  725. * @qdf_osdev: QDF OS device
  726. * @pdev_id: PDEV ID
  727. *
  728. * Return: DP PDEV handle on success, NULL on failure
  729. */
  730. void *dp_pdev_attach_wifi3(struct cdp_soc_t *txrx_soc, void *ctrl_pdev,
  731. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev, uint8_t pdev_id)
  732. {
  733. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  734. struct dp_pdev *pdev = qdf_mem_malloc(sizeof(*pdev));
  735. if (!pdev) {
  736. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  737. "%s: DP PDEV memory allocation failed\n", __func__);
  738. goto fail0;
  739. }
  740. pdev->wlan_cfg_ctx = wlan_cfg_pdev_attach();
  741. if (!pdev->wlan_cfg_ctx) {
  742. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  743. "%s: pdev cfg_attach failed\n", __func__);
  744. qdf_mem_free(pdev);
  745. goto fail0;
  746. }
  747. pdev->soc = soc;
  748. pdev->osif_pdev = ctrl_pdev;
  749. pdev->pdev_id = pdev_id;
  750. soc->pdev_list[pdev_id] = pdev;
  751. TAILQ_INIT(&pdev->vdev_list);
  752. pdev->vdev_count = 0;
  753. if (dp_soc_cmn_setup(soc)) {
  754. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  755. "%s: dp_soc_cmn_setup failed\n", __func__);
  756. goto fail1;
  757. }
  758. /* Setup per PDEV TCL rings if configured */
  759. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  760. if (dp_srng_setup(soc, &soc->tcl_data_ring[pdev_id], TCL_DATA,
  761. pdev_id, pdev_id, TCL_DATA_RING_SIZE)) {
  762. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  763. "%s: dp_srng_setup failed for tcl_data_ring\n",
  764. __func__);
  765. goto fail1;
  766. }
  767. if (dp_srng_setup(soc, &soc->tx_comp_ring[pdev_id],
  768. WBM2SW_RELEASE, pdev_id, pdev_id, TCL_DATA_RING_SIZE)) {
  769. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  770. "%s: dp_srng_setup failed for tx_comp_ring\n",
  771. __func__);
  772. goto fail1;
  773. }
  774. soc->num_tcl_data_rings++;
  775. }
  776. /* Tx specific init */
  777. if (dp_tx_pdev_attach(pdev)) {
  778. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  779. "%s: dp_tx_pdev_attach failed\n", __func__);
  780. goto fail1;
  781. }
  782. /* Setup per PDEV REO rings if configured */
  783. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  784. if (dp_srng_setup(soc, &soc->reo_dest_ring[pdev_id], REO_DST,
  785. pdev_id, pdev_id, REO_DST_RING_SIZE)) {
  786. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  787. "%s: dp_srng_setup failed for reo_dest_ring\n",
  788. __func__);
  789. goto fail1;
  790. }
  791. soc->num_reo_dest_rings++;
  792. }
  793. if (dp_srng_setup(soc, &pdev->rx_refill_buf_ring, RXDMA_BUF, 0, pdev_id,
  794. RXDMA_BUF_RING_SIZE)) {
  795. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  796. "%s: dp_srng_setup failed rx refill ring\n", __func__);
  797. goto fail1;
  798. }
  799. #ifdef QCA_HOST2FW_RXBUF_RING
  800. if (dp_srng_setup(soc, &pdev->rx_mac_buf_ring, RXDMA_BUF, 1, pdev_id,
  801. RXDMA_BUF_RING_SIZE)) {
  802. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  803. "%s: dp_srng_setup failed rx mac ring\n", __func__);
  804. goto fail1;
  805. }
  806. #endif
  807. /* TODO: RXDMA destination ring is not planned to be used currently.
  808. * Setup the ring when required
  809. */
  810. if (dp_srng_setup(soc, &pdev->rxdma_mon_buf_ring, RXDMA_MONITOR_BUF, 0,
  811. pdev_id, RXDMA_MONITOR_BUF_RING_SIZE)) {
  812. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  813. "%s: dp_srng_setup failed for rxdma_mon_buf_ring\n",
  814. __func__);
  815. goto fail1;
  816. }
  817. if (dp_srng_setup(soc, &pdev->rxdma_mon_dst_ring, RXDMA_MONITOR_DST, 0,
  818. pdev_id, RXDMA_MONITOR_DST_RING_SIZE)) {
  819. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  820. "%s: dp_srng_setup failed for rxdma_mon_dst_ring\n",
  821. __func__);
  822. goto fail1;
  823. }
  824. if (dp_srng_setup(soc, &pdev->rxdma_mon_status_ring,
  825. RXDMA_MONITOR_STATUS, 0, pdev_id,
  826. RXDMA_MONITOR_STATUS_RING_SIZE)) {
  827. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  828. "%s: dp_srng_setup failed for rxdma_mon_status_ring\n",
  829. __func__);
  830. goto fail1;
  831. }
  832. /* Rx specific init */
  833. if (dp_rx_pdev_attach(pdev)) {
  834. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  835. "%s: dp_rx_pdev_attach failed \n", __func__);
  836. goto fail0;
  837. }
  838. /* MCL */
  839. dp_local_peer_id_pool_init(pdev);
  840. return (void *)pdev;
  841. fail1:
  842. dp_pdev_detach_wifi3((void *)pdev, 0);
  843. fail0:
  844. return NULL;
  845. }
  846. /*
  847. * dp_pdev_detach_wifi3() - detach txrx pdev
  848. * @txrx_pdev: Datapath PDEV handle
  849. * @force: Force detach
  850. *
  851. */
  852. static void dp_pdev_detach_wifi3(void *txrx_pdev, int force)
  853. {
  854. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  855. struct dp_soc *soc = pdev->soc;
  856. dp_tx_pdev_detach(pdev);
  857. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  858. dp_srng_cleanup(soc, &soc->tcl_data_ring[pdev->pdev_id],
  859. TCL_DATA, pdev->pdev_id);
  860. dp_srng_cleanup(soc, &soc->tx_comp_ring[pdev->pdev_id],
  861. WBM2SW_RELEASE, pdev->pdev_id);
  862. }
  863. dp_rx_pdev_detach(pdev);
  864. /* Setup per PDEV REO rings if configured */
  865. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  866. dp_srng_cleanup(soc, &soc->reo_dest_ring[pdev->pdev_id],
  867. REO_DST, pdev->pdev_id);
  868. }
  869. dp_srng_cleanup(soc, &pdev->rx_refill_buf_ring, RXDMA_BUF, 0);
  870. #ifdef QCA_HOST2FW_RXBUF_RING
  871. dp_srng_cleanup(soc, &pdev->rx_mac_buf_ring, RXDMA_BUF, 1);
  872. #endif
  873. dp_srng_cleanup(soc, &pdev->rxdma_mon_buf_ring, RXDMA_MONITOR_BUF, 0);
  874. dp_srng_cleanup(soc, &pdev->rxdma_mon_dst_ring, RXDMA_MONITOR_DST, 0);
  875. dp_srng_cleanup(soc, &pdev->rxdma_mon_status_ring,
  876. RXDMA_MONITOR_STATUS, 0);
  877. soc->pdev_list[pdev->pdev_id] = NULL;
  878. qdf_mem_free(pdev);
  879. }
  880. /*
  881. * dp_soc_detach_wifi3() - Detach txrx SOC
  882. * @txrx_soc: DP SOC handle
  883. *
  884. */
  885. void dp_soc_detach_wifi3(void *txrx_soc)
  886. {
  887. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  888. struct dp_pdev *pdev = qdf_mem_malloc(sizeof(*pdev));
  889. int i;
  890. soc->cmn_init_done = 0;
  891. for (i = 0; i < MAX_PDEV_CNT; i++) {
  892. if (soc->pdev_list[i])
  893. dp_pdev_detach_wifi3((void *)pdev, 1);
  894. }
  895. dp_peer_find_detach(soc);
  896. /* TBD: Call Tx and Rx cleanup functions to free buffers and
  897. * SW descriptors
  898. */
  899. /* Free the ring memories */
  900. /* Common rings */
  901. dp_srng_cleanup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0);
  902. /* Tx data rings */
  903. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  904. dp_tx_soc_detach(soc);
  905. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  906. dp_srng_cleanup(soc, &soc->tcl_data_ring[i],
  907. TCL_DATA, i);
  908. dp_srng_cleanup(soc, &soc->tx_comp_ring[i],
  909. WBM2SW_RELEASE, i);
  910. }
  911. }
  912. /* TCL command and status rings */
  913. dp_srng_cleanup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0);
  914. dp_srng_cleanup(soc, &soc->tcl_status_ring, TCL_STATUS, 0);
  915. /* Rx data rings */
  916. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  917. soc->num_reo_dest_rings =
  918. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  919. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  920. /* TODO: Get number of rings and ring sizes
  921. * from wlan_cfg
  922. */
  923. dp_srng_cleanup(soc, &soc->reo_dest_ring[i],
  924. REO_DST, i);
  925. }
  926. }
  927. /* REO reinjection ring */
  928. dp_srng_cleanup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0);
  929. /* Rx release ring */
  930. dp_srng_cleanup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 0);
  931. /* Rx exception ring */
  932. /* TODO: Better to store ring_type and ring_num in
  933. * dp_srng during setup
  934. */
  935. dp_srng_cleanup(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0);
  936. /* REO command and status rings */
  937. dp_srng_cleanup(soc, &soc->reo_cmd_ring, REO_CMD, 0);
  938. dp_srng_cleanup(soc, &soc->reo_status_ring, REO_STATUS, 0);
  939. qdf_spinlock_destroy(&soc->peer_ref_mutex);
  940. htt_soc_detach(soc->htt_handle);
  941. }
  942. /*
  943. * dp_soc_attach_target_wifi3() - SOC initialization in the target
  944. * @txrx_soc: Datapath SOC handle
  945. */
  946. int dp_soc_attach_target_wifi3(struct cdp_soc_t *cdp_soc)
  947. {
  948. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  949. int i;
  950. htt_soc_attach_target(soc->htt_handle);
  951. for (i = 0; i < MAX_PDEV_CNT; i++) {
  952. struct dp_pdev *pdev = soc->pdev_list[i];
  953. if (pdev) {
  954. htt_srng_setup(soc->htt_handle, i,
  955. pdev->rx_refill_buf_ring.hal_srng, RXDMA_BUF);
  956. #ifdef QCA_HOST2FW_RXBUF_RING
  957. htt_srng_setup(soc->htt_handle, i,
  958. pdev->rx_mac_buf_ring.hal_srng, RXDMA_BUF);
  959. #endif
  960. #ifdef notyet /* FW doesn't handle monitor rings yet */
  961. htt_srng_setup(soc->htt_handle, i,
  962. pdev->rxdma_mon_buf_ring.hal_srng,
  963. RXDMA_MONITOR_BUF);
  964. htt_srng_setup(soc->htt_handle, i,
  965. pdev->rxdma_mon_dst_ring.hal_srng,
  966. RXDMA_MONITOR_DST);
  967. htt_srng_setup(soc->htt_handle, i,
  968. pdev->rxdma_mon_status_ring.hal_srng,
  969. RXDMA_MONITOR_STATUS);
  970. #endif
  971. }
  972. }
  973. return 0;
  974. }
  975. /*
  976. * dp_vdev_attach_wifi3() - attach txrx vdev
  977. * @txrx_pdev: Datapath PDEV handle
  978. * @vdev_mac_addr: MAC address of the virtual interface
  979. * @vdev_id: VDEV Id
  980. * @wlan_op_mode: VDEV operating mode
  981. *
  982. * Return: DP VDEV handle on success, NULL on failure
  983. */
  984. void *dp_vdev_attach_wifi3(void *txrx_pdev,
  985. uint8_t *vdev_mac_addr, uint8_t vdev_id, enum wlan_op_mode op_mode)
  986. {
  987. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  988. struct dp_soc *soc = pdev->soc;
  989. struct dp_vdev *vdev = qdf_mem_malloc(sizeof(*vdev));
  990. if (!vdev) {
  991. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  992. "%s: DP VDEV memory allocation failed\n", __func__);
  993. goto fail0;
  994. }
  995. vdev->pdev = pdev;
  996. vdev->vdev_id = vdev_id;
  997. vdev->opmode = op_mode;
  998. vdev->osdev = soc->osdev;
  999. vdev->osif_rx = NULL;
  1000. vdev->osif_rx_mon = NULL;
  1001. vdev->osif_vdev = NULL;
  1002. vdev->delete.pending = 0;
  1003. vdev->safemode = 0;
  1004. vdev->drop_unenc = 1;
  1005. #ifdef notyet
  1006. vdev->filters_num = 0;
  1007. #endif
  1008. qdf_mem_copy(
  1009. &vdev->mac_addr.raw[0], vdev_mac_addr, OL_TXRX_MAC_ADDR_LEN);
  1010. vdev->tx_encap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  1011. vdev->rx_decap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  1012. /* TODO: Initialize default HTT meta data that will be used in
  1013. * TCL descriptors for packets transmitted from this VDEV
  1014. */
  1015. TAILQ_INIT(&vdev->peer_list);
  1016. /* add this vdev into the pdev's list */
  1017. TAILQ_INSERT_TAIL(&pdev->vdev_list, vdev, vdev_list_elem);
  1018. pdev->vdev_count++;
  1019. dp_tx_vdev_attach(vdev);
  1020. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1021. "Created vdev %p (%02x:%02x:%02x:%02x:%02x:%02x)\n", vdev,
  1022. vdev->mac_addr.raw[0], vdev->mac_addr.raw[1],
  1023. vdev->mac_addr.raw[2], vdev->mac_addr.raw[3],
  1024. vdev->mac_addr.raw[4], vdev->mac_addr.raw[5]);
  1025. return (void *)vdev;
  1026. fail0:
  1027. return NULL;
  1028. }
  1029. /**
  1030. * dp_vdev_register_wifi3() - Register VDEV operations from osif layer
  1031. * @vdev: Datapath VDEV handle
  1032. * @osif_vdev: OSIF vdev handle
  1033. * @txrx_ops: Tx and Rx operations
  1034. *
  1035. * Return: DP VDEV handle on success, NULL on failure
  1036. */
  1037. void dp_vdev_register_wifi3(void *vdev_handle, void *osif_vdev,
  1038. struct ol_txrx_ops *txrx_ops)
  1039. {
  1040. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  1041. vdev->osif_vdev = osif_vdev;
  1042. vdev->osif_rx = txrx_ops->rx.rx;
  1043. vdev->osif_rx_mon = txrx_ops->rx.mon;
  1044. #ifdef notyet
  1045. #if ATH_SUPPORT_WAPI
  1046. vdev->osif_check_wai = txrx_ops->rx.wai_check;
  1047. #endif
  1048. #if UMAC_SUPPORT_PROXY_ARP
  1049. vdev->osif_proxy_arp = txrx_ops->proxy_arp;
  1050. #endif
  1051. #endif
  1052. /* TODO: Enable the following once Tx code is integrated */
  1053. txrx_ops->tx.tx = dp_tx_send;
  1054. DP_TRACE(ERROR, "DP Vdev Register success");
  1055. }
  1056. /*
  1057. * dp_vdev_detach_wifi3() - Detach txrx vdev
  1058. * @txrx_vdev: Datapath VDEV handle
  1059. * @callback: Callback OL_IF on completion of detach
  1060. * @cb_context: Callback context
  1061. *
  1062. */
  1063. void dp_vdev_detach_wifi3(void *vdev_handle,
  1064. ol_txrx_vdev_delete_cb callback, void *cb_context)
  1065. {
  1066. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  1067. struct dp_pdev *pdev = vdev->pdev;
  1068. struct dp_soc *soc = pdev->soc;
  1069. /* preconditions */
  1070. qdf_assert(vdev);
  1071. /* remove the vdev from its parent pdev's list */
  1072. TAILQ_REMOVE(&pdev->vdev_list, vdev, vdev_list_elem);
  1073. /*
  1074. * Use peer_ref_mutex while accessing peer_list, in case
  1075. * a peer is in the process of being removed from the list.
  1076. */
  1077. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  1078. /* check that the vdev has no peers allocated */
  1079. if (!TAILQ_EMPTY(&vdev->peer_list)) {
  1080. /* debug print - will be removed later */
  1081. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  1082. "%s: not deleting vdev object %p (%02x:%02x:%02x:%02x:%02x:%02x)"
  1083. "until deletion finishes for all its peers\n",
  1084. __func__, vdev,
  1085. vdev->mac_addr.raw[0], vdev->mac_addr.raw[1],
  1086. vdev->mac_addr.raw[2], vdev->mac_addr.raw[3],
  1087. vdev->mac_addr.raw[4], vdev->mac_addr.raw[5]);
  1088. /* indicate that the vdev needs to be deleted */
  1089. vdev->delete.pending = 1;
  1090. vdev->delete.callback = callback;
  1091. vdev->delete.context = cb_context;
  1092. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1093. return;
  1094. }
  1095. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1096. dp_tx_vdev_detach(vdev);
  1097. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1098. "%s: deleting vdev object %p (%02x:%02x:%02x:%02x:%02x:%02x)\n",
  1099. __func__, vdev,
  1100. vdev->mac_addr.raw[0], vdev->mac_addr.raw[1],
  1101. vdev->mac_addr.raw[2], vdev->mac_addr.raw[3],
  1102. vdev->mac_addr.raw[4], vdev->mac_addr.raw[5]);
  1103. qdf_mem_free(vdev);
  1104. if (callback)
  1105. callback(cb_context);
  1106. }
  1107. /*
  1108. * dp_peer_attach_wifi3() - attach txrx peer
  1109. * @txrx_vdev: Datapath VDEV handle
  1110. * @peer_mac_addr: Peer MAC address
  1111. *
  1112. * Return: DP peeer handle on success, NULL on failure
  1113. */
  1114. void *dp_peer_attach_wifi3(void *vdev_handle, uint8_t *peer_mac_addr)
  1115. {
  1116. struct dp_peer *peer;
  1117. int i;
  1118. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  1119. struct dp_pdev *pdev;
  1120. struct dp_soc *soc;
  1121. /* preconditions */
  1122. qdf_assert(vdev);
  1123. qdf_assert(peer_mac_addr);
  1124. pdev = vdev->pdev;
  1125. soc = pdev->soc;
  1126. #ifdef notyet
  1127. peer = (struct dp_peer *)qdf_mempool_alloc(soc->osdev,
  1128. soc->mempool_ol_ath_peer);
  1129. #else
  1130. peer = (struct dp_peer *)qdf_mem_malloc(sizeof(*peer));
  1131. #endif
  1132. if (!peer)
  1133. return NULL; /* failure */
  1134. qdf_mem_zero(peer, sizeof(struct dp_peer));
  1135. qdf_spinlock_create(&peer->peer_info_lock);
  1136. /* store provided params */
  1137. peer->vdev = vdev;
  1138. qdf_mem_copy(
  1139. &peer->mac_addr.raw[0], peer_mac_addr, OL_TXRX_MAC_ADDR_LEN);
  1140. /* TODO: See of rx_opt_proc is really required */
  1141. peer->rx_opt_proc = soc->rx_opt_proc;
  1142. dp_peer_rx_init(pdev, peer);
  1143. /* initialize the peer_id */
  1144. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++)
  1145. peer->peer_ids[i] = HTT_INVALID_PEER;
  1146. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  1147. qdf_atomic_init(&peer->ref_cnt);
  1148. /* keep one reference for attach */
  1149. qdf_atomic_inc(&peer->ref_cnt);
  1150. /* add this peer into the vdev's list */
  1151. TAILQ_INSERT_TAIL(&vdev->peer_list, peer, peer_list_elem);
  1152. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1153. /* TODO: See if hash based search is required */
  1154. dp_peer_find_hash_add(soc, peer);
  1155. if (soc->cdp_soc.ol_ops->peer_set_default_routing) {
  1156. /* TODO: Check on the destination ring number to be passed to FW */
  1157. soc->cdp_soc.ol_ops->peer_set_default_routing(soc->osif_soc, peer->mac_addr.raw,
  1158. peer->vdev->vdev_id, 0, 1);
  1159. }
  1160. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1161. "vdev %p created peer %p (%02x:%02x:%02x:%02x:%02x:%02x)\n",
  1162. vdev, peer,
  1163. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  1164. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  1165. peer->mac_addr.raw[4], peer->mac_addr.raw[5]);
  1166. /*
  1167. * For every peer MAp message search and set if bss_peer
  1168. */
  1169. if (memcmp(peer->mac_addr.raw, vdev->mac_addr.raw, 6) == 0) {
  1170. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1171. "vdev bss_peer!!!!\n");
  1172. peer->bss_peer = 1;
  1173. vdev->vap_bss_peer = peer;
  1174. }
  1175. dp_local_peer_id_alloc(pdev, peer);
  1176. return (void *)peer;
  1177. }
  1178. /*
  1179. * dp_peer_authorize() - authorize txrx peer
  1180. * @peer_handle: Datapath peer handle
  1181. * @authorize
  1182. *
  1183. */
  1184. void dp_peer_authorize(void *peer_handle, uint32_t authorize)
  1185. {
  1186. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  1187. struct dp_soc *soc;
  1188. if (peer != NULL) {
  1189. soc = peer->vdev->pdev->soc;
  1190. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  1191. peer->authorize = authorize ? 1 : 0;
  1192. #ifdef notyet /* ATH_BAND_STEERING */
  1193. peer->peer_bs_inact_flag = 0;
  1194. peer->peer_bs_inact = soc->pdev_bs_inact_reload;
  1195. #endif
  1196. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1197. }
  1198. }
  1199. /*
  1200. * dp_peer_unref_delete() - unref and delete peer
  1201. * @peer_handle: Datapath peer handle
  1202. *
  1203. */
  1204. void dp_peer_unref_delete(void *peer_handle)
  1205. {
  1206. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  1207. struct dp_vdev *vdev = peer->vdev;
  1208. struct dp_soc *soc = vdev->pdev->soc;
  1209. struct dp_peer *tmppeer;
  1210. int found = 0;
  1211. uint16_t peer_id;
  1212. /*
  1213. * Hold the lock all the way from checking if the peer ref count
  1214. * is zero until the peer references are removed from the hash
  1215. * table and vdev list (if the peer ref count is zero).
  1216. * This protects against a new HL tx operation starting to use the
  1217. * peer object just after this function concludes it's done being used.
  1218. * Furthermore, the lock needs to be held while checking whether the
  1219. * vdev's list of peers is empty, to make sure that list is not modified
  1220. * concurrently with the empty check.
  1221. */
  1222. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  1223. if (qdf_atomic_dec_and_test(&peer->ref_cnt)) {
  1224. peer_id = peer->peer_ids[0];
  1225. /*
  1226. * Make sure that the reference to the peer in
  1227. * peer object map is removed
  1228. */
  1229. if (peer_id != HTT_INVALID_PEER)
  1230. soc->peer_id_to_obj_map[peer_id] = NULL;
  1231. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1232. "Deleting peer %p (%02x:%02x:%02x:%02x:%02x:%02x)\n",
  1233. peer, peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  1234. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  1235. peer->mac_addr.raw[4], peer->mac_addr.raw[5]);
  1236. /* remove the reference to the peer from the hash table */
  1237. dp_peer_find_hash_remove(soc, peer);
  1238. TAILQ_FOREACH(tmppeer, &peer->vdev->peer_list, peer_list_elem) {
  1239. if (tmppeer == peer) {
  1240. found = 1;
  1241. break;
  1242. }
  1243. }
  1244. if (found) {
  1245. TAILQ_REMOVE(&peer->vdev->peer_list, peer,
  1246. peer_list_elem);
  1247. } else {
  1248. /*Ignoring the remove operation as peer not found*/
  1249. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  1250. "WARN peer %p not found in vdev (%p)->peer_list:%p\n",
  1251. peer, vdev, &peer->vdev->peer_list);
  1252. }
  1253. /* cleanup the Rx reorder queues for this peer */
  1254. dp_peer_rx_cleanup(vdev, peer);
  1255. /* check whether the parent vdev has no peers left */
  1256. if (TAILQ_EMPTY(&vdev->peer_list)) {
  1257. /*
  1258. * Now that there are no references to the peer, we can
  1259. * release the peer reference lock.
  1260. */
  1261. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1262. /*
  1263. * Check if the parent vdev was waiting for its peers
  1264. * to be deleted, in order for it to be deleted too.
  1265. */
  1266. if (vdev->delete.pending) {
  1267. ol_txrx_vdev_delete_cb vdev_delete_cb =
  1268. vdev->delete.callback;
  1269. void *vdev_delete_context =
  1270. vdev->delete.context;
  1271. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1272. QDF_TRACE_LEVEL_INFO_HIGH,
  1273. "%s: deleting vdev object %p "
  1274. "(%02x:%02x:%02x:%02x:%02x:%02x)"
  1275. " - its last peer is done\n",
  1276. __func__, vdev,
  1277. vdev->mac_addr.raw[0],
  1278. vdev->mac_addr.raw[1],
  1279. vdev->mac_addr.raw[2],
  1280. vdev->mac_addr.raw[3],
  1281. vdev->mac_addr.raw[4],
  1282. vdev->mac_addr.raw[5]);
  1283. /* all peers are gone, go ahead and delete it */
  1284. qdf_mem_free(vdev);
  1285. if (vdev_delete_cb)
  1286. vdev_delete_cb(vdev_delete_context);
  1287. }
  1288. } else {
  1289. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1290. }
  1291. #ifdef notyet
  1292. qdf_mempool_free(soc->osdev, soc->mempool_ol_ath_peer, peer);
  1293. #else
  1294. qdf_mem_free(peer);
  1295. #endif
  1296. #ifdef notyet /* See why this should be done in DP layer */
  1297. qdf_atomic_inc(&soc->peer_count);
  1298. #endif
  1299. } else {
  1300. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1301. }
  1302. }
  1303. /*
  1304. * dp_peer_detach_wifi3() – Detach txrx peer
  1305. * @peer_handle: Datapath peer handle
  1306. *
  1307. */
  1308. void dp_peer_detach_wifi3(void *peer_handle)
  1309. {
  1310. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  1311. /* redirect the peer's rx delivery function to point to a
  1312. * discard func
  1313. */
  1314. peer->rx_opt_proc = dp_rx_discard;
  1315. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1316. "%s:peer %p (%02x:%02x:%02x:%02x:%02x:%02x)\n", __func__, peer,
  1317. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  1318. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  1319. peer->mac_addr.raw[4], peer->mac_addr.raw[5]);
  1320. /*
  1321. * Remove the reference added during peer_attach.
  1322. * The peer will still be left allocated until the
  1323. * PEER_UNMAP message arrives to remove the other
  1324. * reference, added by the PEER_MAP message.
  1325. */
  1326. dp_peer_unref_delete(peer_handle);
  1327. dp_local_peer_id_free(peer->vdev->pdev, peer);
  1328. qdf_spinlock_destroy(&peer->peer_info_lock);
  1329. }
  1330. /*
  1331. * dp_get_vdev_mac_addr_wifi3() – Detach txrx peer
  1332. * @peer_handle: Datapath peer handle
  1333. *
  1334. */
  1335. uint8 *dp_get_vdev_mac_addr_wifi3(void *pvdev)
  1336. {
  1337. struct dp_vdev *vdev = pvdev;
  1338. return vdev->mac_addr.raw;
  1339. }
  1340. /*
  1341. * dp_get_vdev_from_vdev_id_wifi3() – Detach txrx peer
  1342. * @peer_handle: Datapath peer handle
  1343. *
  1344. */
  1345. void *dp_get_vdev_from_vdev_id_wifi3(void *dev, uint8_t vdev_id)
  1346. {
  1347. struct dp_pdev *pdev = dev;
  1348. struct dp_vdev *vdev = NULL;
  1349. if (qdf_unlikely(!pdev))
  1350. return NULL;
  1351. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  1352. if (vdev->vdev_id == vdev_id)
  1353. break;
  1354. }
  1355. return vdev;
  1356. }
  1357. int dp_get_opmode(void *vdev_handle)
  1358. {
  1359. struct dp_vdev *vdev = vdev_handle;
  1360. return vdev->opmode;
  1361. }
  1362. void *dp_get_ctrl_pdev_from_vdev_wifi3(void *pvdev)
  1363. {
  1364. struct dp_vdev *vdev = pvdev;
  1365. struct dp_pdev *pdev = vdev->pdev;
  1366. return (void *)pdev->wlan_cfg_ctx;
  1367. }
  1368. static struct cdp_cmn_ops dp_ops_cmn = {
  1369. .txrx_soc_attach_target = dp_soc_attach_target_wifi3,
  1370. .txrx_vdev_attach = dp_vdev_attach_wifi3,
  1371. .txrx_vdev_detach = dp_vdev_detach_wifi3,
  1372. .txrx_pdev_attach = dp_pdev_attach_wifi3,
  1373. .txrx_pdev_detach = dp_pdev_detach_wifi3,
  1374. .txrx_peer_attach = dp_peer_attach_wifi3,
  1375. .txrx_peer_detach = dp_peer_detach_wifi3,
  1376. .txrx_vdev_register = dp_vdev_register_wifi3,
  1377. .txrx_soc_detach = dp_soc_detach_wifi3,
  1378. .txrx_get_vdev_mac_addr = dp_get_vdev_mac_addr_wifi3,
  1379. .txrx_get_vdev_from_vdev_id = dp_get_vdev_from_vdev_id_wifi3,
  1380. .txrx_get_ctrl_pdev_from_vdev = dp_get_ctrl_pdev_from_vdev_wifi3,
  1381. /* TODO: Add other functions */
  1382. };
  1383. static struct cdp_ctrl_ops dp_ops_ctrl = {
  1384. .txrx_peer_authorize = dp_peer_authorize,
  1385. /* TODO: Add other functions */
  1386. };
  1387. static struct cdp_me_ops dp_ops_me = {
  1388. /* TODO */
  1389. };
  1390. static struct cdp_mon_ops dp_ops_mon = {
  1391. /* TODO */
  1392. };
  1393. static struct cdp_host_stats_ops dp_ops_host_stats = {
  1394. /* TODO */
  1395. };
  1396. static struct cdp_wds_ops dp_ops_wds = {
  1397. /* TODO */
  1398. };
  1399. static struct cdp_raw_ops dp_ops_raw = {
  1400. /* TODO */
  1401. };
  1402. #ifdef CONFIG_WIN
  1403. static struct cdp_pflow_ops dp_ops_pflow = {
  1404. /* TODO */
  1405. };
  1406. #endif /* CONFIG_WIN */
  1407. static struct cdp_misc_ops dp_ops_misc = {
  1408. .get_opmode = dp_get_opmode,
  1409. };
  1410. static struct cdp_flowctl_ops dp_ops_flowctl = {
  1411. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1412. };
  1413. static struct cdp_lflowctl_ops dp_ops_l_flowctl = {
  1414. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1415. };
  1416. static struct cdp_ipa_ops dp_ops_ipa = {
  1417. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1418. };
  1419. static struct cdp_lro_ops dp_ops_lro = {
  1420. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1421. };
  1422. static struct cdp_bus_ops dp_ops_bus = {
  1423. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1424. };
  1425. static struct cdp_ocb_ops dp_ops_ocb = {
  1426. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1427. };
  1428. static struct cdp_throttle_ops dp_ops_throttle = {
  1429. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1430. };
  1431. static struct cdp_mob_stats_ops dp_ops_mob_stats = {
  1432. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1433. };
  1434. static struct cdp_cfg_ops dp_ops_cfg = {
  1435. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  1436. };
  1437. static struct cdp_peer_ops dp_ops_peer = {
  1438. .register_peer = dp_register_peer,
  1439. .clear_peer = dp_clear_peer,
  1440. .find_peer_by_addr = dp_find_peer_by_addr,
  1441. .find_peer_by_addr_and_vdev = dp_find_peer_by_addr_and_vdev,
  1442. .local_peer_id = dp_local_peer_id,
  1443. .peer_find_by_local_id = dp_peer_find_by_local_id,
  1444. .peer_state_update = dp_peer_state_update,
  1445. .get_vdevid = dp_get_vdevid,
  1446. .peer_get_peer_mac_addr = dp_peer_get_peer_mac_addr,
  1447. .get_vdev_for_peer = dp_get_vdev_for_peer,
  1448. .get_peer_state = dp_get_peer_state,
  1449. };
  1450. static struct cdp_ops dp_txrx_ops = {
  1451. .cmn_drv_ops = &dp_ops_cmn,
  1452. .ctrl_ops = &dp_ops_ctrl,
  1453. .me_ops = &dp_ops_me,
  1454. .mon_ops = &dp_ops_mon,
  1455. .host_stats_ops = &dp_ops_host_stats,
  1456. .wds_ops = &dp_ops_wds,
  1457. .raw_ops = &dp_ops_raw,
  1458. #ifdef CONFIG_WIN
  1459. .pflow_ops = &dp_ops_pflow,
  1460. #endif /* CONFIG_WIN */
  1461. .misc_ops = &dp_ops_misc,
  1462. .cfg_ops = &dp_ops_cfg,
  1463. .flowctl_ops = &dp_ops_flowctl,
  1464. .l_flowctl_ops = &dp_ops_l_flowctl,
  1465. .ipa_ops = &dp_ops_ipa,
  1466. .lro_ops = &dp_ops_lro,
  1467. .bus_ops = &dp_ops_bus,
  1468. .ocb_ops = &dp_ops_ocb,
  1469. .peer_ops = &dp_ops_peer,
  1470. .throttle_ops = &dp_ops_throttle,
  1471. .mob_stats_ops = &dp_ops_mob_stats,
  1472. };
  1473. /*
  1474. * dp_soc_attach_wifi3() - Attach txrx SOC
  1475. * @osif_soc: Opaque SOC handle from OSIF/HDD
  1476. * @htc_handle: Opaque HTC handle
  1477. * @hif_handle: Opaque HIF handle
  1478. * @qdf_osdev: QDF device
  1479. *
  1480. * Return: DP SOC handle on success, NULL on failure
  1481. */
  1482. void *dp_soc_attach_wifi3(void *osif_soc, void *hif_handle,
  1483. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  1484. struct ol_if_ops *ol_ops)
  1485. {
  1486. struct dp_soc *soc = qdf_mem_malloc(sizeof(*soc));
  1487. if (!soc) {
  1488. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1489. "%s: DP SOC memory allocation failed\n", __func__);
  1490. goto fail0;
  1491. }
  1492. soc->cdp_soc.ops = &dp_txrx_ops;
  1493. soc->cdp_soc.ol_ops = ol_ops;
  1494. soc->osif_soc = osif_soc;
  1495. soc->osdev = qdf_osdev;
  1496. soc->hif_handle = hif_handle;
  1497. soc->hal_soc = hif_get_hal_handle(hif_handle);
  1498. soc->htt_handle = htt_soc_attach(soc, osif_soc, htc_handle,
  1499. soc->hal_soc, qdf_osdev);
  1500. if (soc->htt_handle == NULL) {
  1501. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1502. "%s: HTT attach failed\n", __func__);
  1503. goto fail1;
  1504. }
  1505. soc->wlan_cfg_ctx = wlan_cfg_soc_attach();
  1506. if (!soc->wlan_cfg_ctx) {
  1507. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1508. "%s: wlan_cfg_soc_attach failed\n", __func__);
  1509. goto fail2;
  1510. }
  1511. qdf_spinlock_create(&soc->peer_ref_mutex);
  1512. #ifdef notyet
  1513. if (wdi_event_attach(soc)) {
  1514. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1515. "%s: WDI event attach failed\n", __func__);
  1516. goto fail2;
  1517. }
  1518. #endif
  1519. if (dp_soc_interrupt_attach(soc) != QDF_STATUS_SUCCESS) {
  1520. goto fail2;
  1521. }
  1522. return (void *)soc;
  1523. fail2:
  1524. htt_soc_detach(soc->htt_handle);
  1525. fail1:
  1526. qdf_mem_free(soc);
  1527. fail0:
  1528. return NULL;
  1529. }