dp_main.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  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 "wlan_cfg.h"
  30. /**
  31. * dp_setup_srng - Internal function to setup SRNG rings used by data path
  32. */
  33. static int dp_srng_setup(struct dp_soc *soc, struct dp_srng *srng,
  34. int ring_type, int ring_num, int pdev_id, uint32_t num_entries)
  35. {
  36. void *hal_soc = soc->hal_soc;
  37. uint32_t entry_size = hal_srng_get_entrysize(hal_soc, ring_type);
  38. /* TODO: See if we should get align size from hal */
  39. uint32_t ring_base_align = 8;
  40. struct hal_srng_params ring_params;
  41. srng->hal_srng = NULL;
  42. srng->alloc_size = (num_entries * entry_size) + ring_base_align - 1;
  43. srng->base_vaddr_unaligned = qdf_mem_alloc_consistent(
  44. soc->osdev, NULL, srng->alloc_size,
  45. &(srng->base_paddr_unaligned));
  46. if (!srng->base_vaddr_unaligned) {
  47. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  48. "%s: alloc failed - ring_type: %d, ring_num %d\n",
  49. __func__, ring_type, ring_num);
  50. return QDF_STATUS_E_NOMEM;
  51. }
  52. ring_params.ring_base_vaddr = srng->base_vaddr_unaligned +
  53. ((unsigned long)srng->base_vaddr_unaligned % ring_base_align);
  54. ring_params.ring_base_paddr = srng->base_paddr_unaligned +
  55. ((unsigned long)(ring_params.ring_base_vaddr) -
  56. (unsigned long)srng->base_vaddr_unaligned);
  57. ring_params.num_entries = num_entries;
  58. /* TODO: Check MSI support and get MSI settings from HIF layer */
  59. ring_params.msi_data = 0;
  60. ring_params.msi_addr = 0;
  61. /* TODO: Setup interrupt timer and batch counter thresholds for
  62. * interrupt mitigation based on ring type
  63. */
  64. ring_params.intr_timer_thres_us = 8;
  65. ring_params.intr_batch_cntr_thres_entries = 1;
  66. /* TODO: Currently hal layer takes care of endianness related settings.
  67. * See if these settings need to passed from DP layer
  68. */
  69. ring_params.flags = 0;
  70. /* Enable low threshold interrupts for rx buffer rings (regular and
  71. * monitor buffer rings.
  72. * TODO: See if this is required for any other ring
  73. */
  74. if ((ring_type == RXDMA_BUF) || (ring_type == RXDMA_MONITOR_BUF)) {
  75. /* TODO: Setting low threshold to 1/8th of ring size
  76. * see if this needs to be configurable
  77. */
  78. ring_params.low_threshold = num_entries >> 3;
  79. ring_params.flags |= HAL_SRNG_LOW_THRES_INTR_ENABLE;
  80. }
  81. srng->hal_srng = hal_srng_setup(hal_soc, ring_type, ring_num,
  82. pdev_id, &ring_params);
  83. return 0;
  84. }
  85. /**
  86. * dp_srng_cleanup - Internal function to cleanup SRNG rings used by data path
  87. * Any buffers allocated and attached to ring entries are expected to be freed
  88. * before calling this function.
  89. */
  90. static void dp_srng_cleanup(struct dp_soc *soc, struct dp_srng *srng,
  91. int ring_type, int ring_num)
  92. {
  93. if (!srng->hal_srng) {
  94. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  95. "%s: Ring type: %d, num:%d not setup\n",
  96. __func__, ring_type, ring_num);
  97. return;
  98. }
  99. hal_srng_cleanup(soc->hal_soc, srng->hal_srng);
  100. qdf_mem_free_consistent(soc->osdev, NULL,
  101. srng->alloc_size,
  102. srng->base_vaddr_unaligned,
  103. srng->base_paddr_unaligned, 0);
  104. }
  105. /* TODO: Need this interface from HIF */
  106. void *hif_get_hal_handle(void *hif_handle);
  107. /*
  108. * dp_soc_attach_wifi3() - Attach txrx SOC
  109. * @osif_soc: Opaque SOC handle from OSIF/HDD
  110. * @htc_handle: Opaque HTC handle
  111. * @hif_handle: Opaque HIF handle
  112. * @qdf_osdev: QDF device
  113. *
  114. * Return: DP SOC handle on success, NULL on failure
  115. */
  116. void *dp_soc_attach_wifi3(void *osif_soc, void *hif_handle,
  117. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  118. struct ol_if_ops *ol_ops)
  119. {
  120. struct dp_soc *soc = qdf_mem_malloc(sizeof(*soc));
  121. if (!soc) {
  122. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  123. "%s: DP SOC memory allocation failed\n", __func__);
  124. goto fail0;
  125. }
  126. soc->osif_soc = osif_soc;
  127. soc->osdev = qdf_osdev;
  128. soc->ol_ops = ol_ops;
  129. soc->hif_handle = hif_handle;
  130. soc->hal_soc = hif_get_hal_handle(hif_handle);
  131. soc->htt_handle = htt_soc_attach(soc, osif_soc, htc_handle,
  132. soc->hal_soc, qdf_osdev);
  133. if (soc->htt_handle == NULL) {
  134. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  135. "%s: HTT attach failed\n", __func__);
  136. goto fail1;
  137. }
  138. #ifdef notyet
  139. if (wdi_event_attach(soc)) {
  140. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  141. "%s: WDI event attach failed\n", __func__);
  142. goto fail2;
  143. }
  144. #endif
  145. return (void *)soc;
  146. #ifdef notyet
  147. fail2:
  148. htt_soc_detach(soc->htt_handle);
  149. #endif
  150. fail1:
  151. qdf_mem_free(soc);
  152. fail0:
  153. return NULL;
  154. }
  155. #define AVG_MAX_MPDUS_PER_TID 128
  156. #define AVG_TIDS_PER_CLIENT 2
  157. #define AVG_FLOWS_PER_TID 2
  158. #define AVG_MSDUS_PER_FLOW 128
  159. #define AVG_MSDUS_PER_MPDU 4
  160. /*
  161. * Allocate and setup link descriptor pool that will be used by HW for
  162. * various link and queue descriptors and managed by WBM
  163. */
  164. static int dp_hw_link_desc_pool_setup(struct dp_soc *soc)
  165. {
  166. int link_desc_size = hal_get_link_desc_size(soc->hal_soc);
  167. int link_desc_align = hal_get_link_desc_align(soc->hal_soc);
  168. uint32_t max_clients = wlan_cfg_get_max_clients(soc->wlan_cfg_ctx);
  169. uint32_t num_mpdus_per_link_desc =
  170. hal_num_mpdus_per_link_desc(soc->hal_soc);
  171. uint32_t num_msdus_per_link_desc =
  172. hal_num_msdus_per_link_desc(soc->hal_soc);
  173. uint32_t num_mpdu_links_per_queue_desc =
  174. hal_num_mpdu_links_per_queue_desc(soc->hal_soc);
  175. uint32_t max_alloc_size = wlan_cfg_max_alloc_size(soc->wlan_cfg_ctx);
  176. uint32_t total_link_descs, total_mem_size;
  177. uint32_t num_mpdu_link_descs, num_mpdu_queue_descs;
  178. uint32_t num_tx_msdu_link_descs, num_rx_msdu_link_descs;
  179. uint32_t num_link_desc_banks;
  180. uint32_t last_bank_size = 0;
  181. uint32_t entry_size, num_entries;
  182. int i;
  183. /* Only Tx queue descriptors are allocated from common link descriptor
  184. * pool Rx queue descriptors are not included in this because (REO queue
  185. * extension descriptors) they are expected to be allocated contiguously
  186. * with REO queue descriptors
  187. */
  188. num_mpdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  189. AVG_MAX_MPDUS_PER_TID) / num_mpdus_per_link_desc;
  190. num_mpdu_queue_descs = num_mpdu_link_descs /
  191. num_mpdu_links_per_queue_desc;
  192. num_tx_msdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  193. AVG_FLOWS_PER_TID * AVG_MSDUS_PER_FLOW) /
  194. num_msdus_per_link_desc;
  195. num_rx_msdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  196. AVG_MAX_MPDUS_PER_TID * AVG_MSDUS_PER_MPDU) / 6;
  197. num_entries = num_mpdu_link_descs + num_mpdu_queue_descs +
  198. num_tx_msdu_link_descs + num_rx_msdu_link_descs;
  199. /* Round up to power of 2 */
  200. total_link_descs = 1;
  201. while (total_link_descs < num_entries)
  202. total_link_descs <<= 1;
  203. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  204. "%s: total_link_descs: %u, link_desc_size: %d\n",
  205. __func__, total_link_descs, link_desc_size);
  206. total_mem_size = total_link_descs * link_desc_size;
  207. total_mem_size += link_desc_align;
  208. if (total_mem_size <= max_alloc_size) {
  209. num_link_desc_banks = 0;
  210. last_bank_size = total_mem_size;
  211. } else {
  212. num_link_desc_banks = (total_mem_size) /
  213. (max_alloc_size - link_desc_align);
  214. last_bank_size = total_mem_size %
  215. (max_alloc_size - link_desc_align);
  216. }
  217. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  218. "%s: total_mem_size: %d, num_link_desc_banks: %u\n",
  219. __func__, total_mem_size, num_link_desc_banks);
  220. for (i = 0; i < num_link_desc_banks; i++) {
  221. soc->link_desc_banks[i].base_vaddr_unaligned =
  222. qdf_mem_alloc_consistent(soc->osdev, NULL,
  223. max_alloc_size,
  224. &(soc->link_desc_banks[i].base_paddr_unaligned));
  225. soc->link_desc_banks[i].size = max_alloc_size;
  226. soc->link_desc_banks[i].base_vaddr = (void *)((unsigned long)(
  227. soc->link_desc_banks[i].base_vaddr_unaligned) +
  228. ((unsigned long)(
  229. soc->link_desc_banks[i].base_vaddr_unaligned) %
  230. link_desc_align));
  231. soc->link_desc_banks[i].base_paddr = (unsigned long)(
  232. soc->link_desc_banks[i].base_paddr_unaligned) +
  233. ((unsigned long)(soc->link_desc_banks[i].base_vaddr) -
  234. (unsigned long)(
  235. soc->link_desc_banks[i].base_vaddr_unaligned));
  236. if (!soc->link_desc_banks[i].base_vaddr_unaligned) {
  237. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  238. "%s: Link descriptor memory alloc failed\n",
  239. __func__);
  240. goto fail;
  241. }
  242. }
  243. if (last_bank_size) {
  244. /* Allocate last bank in case total memory required is not exact
  245. * multiple of max_alloc_size
  246. */
  247. soc->link_desc_banks[i].base_vaddr_unaligned =
  248. qdf_mem_alloc_consistent(soc->osdev, NULL,
  249. last_bank_size,
  250. &(soc->link_desc_banks[i].base_paddr_unaligned));
  251. soc->link_desc_banks[i].size = last_bank_size;
  252. soc->link_desc_banks[i].base_vaddr = (void *)((unsigned long)
  253. (soc->link_desc_banks[i].base_vaddr_unaligned) +
  254. ((unsigned long)(
  255. soc->link_desc_banks[i].base_vaddr_unaligned) %
  256. link_desc_align));
  257. soc->link_desc_banks[i].base_paddr =
  258. (unsigned long)(
  259. soc->link_desc_banks[i].base_paddr_unaligned) +
  260. ((unsigned long)(soc->link_desc_banks[i].base_vaddr) -
  261. (unsigned long)(
  262. soc->link_desc_banks[i].base_vaddr_unaligned));
  263. }
  264. /* Allocate and setup link descriptor idle list for HW internal use */
  265. entry_size = hal_srng_get_entrysize(soc->hal_soc, WBM_IDLE_LINK);
  266. total_mem_size = entry_size * total_link_descs;
  267. if (total_mem_size <= max_alloc_size) {
  268. void *desc;
  269. if (dp_srng_setup(soc, &soc->wbm_idle_link_ring,
  270. WBM_IDLE_LINK, 0, 0, total_link_descs)) {
  271. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  272. "%s: Link desc idle ring setup failed\n",
  273. __func__);
  274. goto fail;
  275. }
  276. hal_srng_access_start_unlocked(soc->hal_soc,
  277. soc->wbm_idle_link_ring.hal_srng);
  278. for (i = 0; i < MAX_LINK_DESC_BANKS &&
  279. soc->link_desc_banks[i].base_paddr; i++) {
  280. uint32_t num_entries = (soc->link_desc_banks[i].size -
  281. (unsigned long)(
  282. soc->link_desc_banks[i].base_vaddr) -
  283. (unsigned long)(
  284. soc->link_desc_banks[i].base_vaddr_unaligned))
  285. / link_desc_size;
  286. unsigned long paddr = (unsigned long)(
  287. soc->link_desc_banks[i].base_paddr);
  288. while (num_entries && (desc = hal_srng_src_get_next(
  289. soc->hal_soc,
  290. soc->wbm_idle_link_ring.hal_srng))) {
  291. hal_set_link_desc_addr(desc, i, paddr);
  292. num_entries--;
  293. paddr += link_desc_size;
  294. }
  295. }
  296. hal_srng_access_end_unlocked(soc->hal_soc,
  297. soc->wbm_idle_link_ring.hal_srng);
  298. } else {
  299. uint32_t num_scatter_bufs;
  300. uint32_t num_entries_per_buf;
  301. uint32_t rem_entries;
  302. uint8_t *scatter_buf_ptr;
  303. uint16_t scatter_buf_num;
  304. soc->wbm_idle_scatter_buf_size =
  305. hal_idle_list_scatter_buf_size(soc->hal_soc);
  306. num_entries_per_buf = hal_idle_scatter_buf_num_entries(
  307. soc->hal_soc, soc->wbm_idle_scatter_buf_size);
  308. num_scatter_bufs = (total_mem_size /
  309. soc->wbm_idle_scatter_buf_size) + (total_mem_size %
  310. soc->wbm_idle_scatter_buf_size) ? 1 : 0;
  311. for (i = 0; i < num_scatter_bufs; i++) {
  312. soc->wbm_idle_scatter_buf_base_vaddr[i] =
  313. qdf_mem_alloc_consistent(soc->osdev, NULL,
  314. soc->wbm_idle_scatter_buf_size,
  315. &(soc->wbm_idle_scatter_buf_base_paddr[i]));
  316. if (soc->wbm_idle_scatter_buf_base_vaddr[i] == NULL) {
  317. QDF_TRACE(QDF_MODULE_ID_TXRX,
  318. QDF_TRACE_LEVEL_ERROR,
  319. "%s:Scatter list memory alloc failed\n",
  320. __func__);
  321. goto fail;
  322. }
  323. }
  324. /* Populate idle list scatter buffers with link descriptor
  325. * pointers
  326. */
  327. scatter_buf_num = 0;
  328. scatter_buf_ptr = (uint8_t *)(
  329. soc->wbm_idle_scatter_buf_base_vaddr[scatter_buf_num]);
  330. rem_entries = num_entries_per_buf;
  331. for (i = 0; i < MAX_LINK_DESC_BANKS &&
  332. soc->link_desc_banks[i].base_paddr; i++) {
  333. uint32_t num_link_descs =
  334. (soc->link_desc_banks[i].size -
  335. (unsigned long)(
  336. soc->link_desc_banks[i].base_vaddr) -
  337. (unsigned long)(
  338. soc->link_desc_banks[i].base_vaddr_unaligned)) /
  339. link_desc_size;
  340. unsigned long paddr = (unsigned long)(
  341. soc->link_desc_banks[i].base_paddr);
  342. void *desc = NULL;
  343. while (num_link_descs && (desc =
  344. hal_srng_src_get_next(soc->hal_soc,
  345. soc->wbm_idle_link_ring.hal_srng))) {
  346. hal_set_link_desc_addr((void *)scatter_buf_ptr,
  347. i, paddr);
  348. num_link_descs--;
  349. paddr += link_desc_size;
  350. if (rem_entries) {
  351. rem_entries--;
  352. scatter_buf_ptr += link_desc_size;
  353. } else {
  354. rem_entries = num_entries_per_buf;
  355. scatter_buf_num++;
  356. scatter_buf_ptr = (uint8_t *)(
  357. soc->wbm_idle_scatter_buf_base_vaddr[
  358. scatter_buf_num]);
  359. }
  360. }
  361. }
  362. /* Setup link descriptor idle list in HW */
  363. hal_setup_link_idle_list(soc->hal_soc,
  364. soc->wbm_idle_scatter_buf_base_paddr,
  365. soc->wbm_idle_scatter_buf_base_vaddr,
  366. num_scatter_bufs, soc->wbm_idle_scatter_buf_size,
  367. (uint32_t)(scatter_buf_ptr - (unsigned long)(
  368. soc->wbm_idle_scatter_buf_base_vaddr[
  369. scatter_buf_num])));
  370. }
  371. return 0;
  372. fail:
  373. if (soc->wbm_idle_link_ring.hal_srng) {
  374. dp_srng_cleanup(soc->hal_soc, &soc->wbm_idle_link_ring,
  375. WBM_IDLE_LINK, 0);
  376. }
  377. for (i = 0; i < MAX_IDLE_SCATTER_BUFS; i++) {
  378. if (soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  379. qdf_mem_free_consistent(soc->osdev, NULL,
  380. soc->wbm_idle_scatter_buf_size,
  381. soc->wbm_idle_scatter_buf_base_vaddr[i],
  382. soc->wbm_idle_scatter_buf_base_paddr[i], 0);
  383. }
  384. }
  385. for (i = 0; i < MAX_LINK_DESC_BANKS; i++) {
  386. if (soc->link_desc_banks[i].base_vaddr_unaligned) {
  387. qdf_mem_free_consistent(soc->osdev, NULL,
  388. soc->link_desc_banks[i].size,
  389. soc->link_desc_banks[i].base_vaddr_unaligned,
  390. soc->link_desc_banks[i].base_paddr_unaligned,
  391. 0);
  392. }
  393. }
  394. return QDF_STATUS_E_FAILURE;
  395. }
  396. /*
  397. * Free link descriptor pool that was setup HW
  398. */
  399. static void dp_hw_link_desc_pool_cleanup(struct dp_soc *soc)
  400. {
  401. int i;
  402. if (soc->wbm_idle_link_ring.hal_srng) {
  403. dp_srng_cleanup(soc->hal_soc, &soc->wbm_idle_link_ring,
  404. WBM_IDLE_LINK, 0);
  405. }
  406. for (i = 0; i < MAX_IDLE_SCATTER_BUFS; i++) {
  407. if (soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  408. qdf_mem_free_consistent(soc->osdev, NULL,
  409. soc->wbm_idle_scatter_buf_size,
  410. soc->wbm_idle_scatter_buf_base_vaddr[i],
  411. soc->wbm_idle_scatter_buf_base_paddr[i], 0);
  412. }
  413. }
  414. for (i = 0; i < MAX_LINK_DESC_BANKS; i++) {
  415. if (soc->link_desc_banks[i].base_vaddr_unaligned) {
  416. qdf_mem_free_consistent(soc->osdev, NULL,
  417. soc->link_desc_banks[i].size,
  418. soc->link_desc_banks[i].base_vaddr_unaligned,
  419. soc->link_desc_banks[i].base_paddr_unaligned,
  420. 0);
  421. }
  422. }
  423. }
  424. /* TODO: Following should be configurable */
  425. #define WBM_RELEASE_RING_SIZE 64
  426. #define TCL_DATA_RING_SIZE 512
  427. #define TCL_CMD_RING_SIZE 32
  428. #define TCL_STATUS_RING_SIZE 32
  429. #define REO_DST_RING_SIZE 2048
  430. #define REO_REINJECT_RING_SIZE 32
  431. #define RX_RELEASE_RING_SIZE 256
  432. #define REO_EXCEPTION_RING_SIZE 128
  433. #define REO_CMD_RING_SIZE 32
  434. #define REO_STATUS_RING_SIZE 32
  435. #define RXDMA_BUF_RING_SIZE 8192
  436. #define RXDMA_MONITOR_BUF_RING_SIZE 8192
  437. #define RXDMA_MONITOR_DST_RING_SIZE 2048
  438. #define RXDMA_MONITOR_STATUS_RING_SIZE 2048
  439. /*
  440. * dp_soc_cmn_setup() - Common SoC level initializion
  441. * @soc: Datapath SOC handle
  442. *
  443. * This is an internal function used to setup common SOC data structures,
  444. * to be called from PDEV attach after receiving HW mode capabilities from FW
  445. */
  446. static int dp_soc_cmn_setup(struct dp_soc *soc)
  447. {
  448. int i;
  449. if (soc->cmn_init_done)
  450. return 0;
  451. soc->wlan_cfg_ctx = wlan_cfg_soc_attach();
  452. if (!soc->wlan_cfg_ctx) {
  453. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  454. "%s: wlan_cfg_soc_attach failed\n", __func__);
  455. goto fail0;
  456. }
  457. if (dp_peer_find_attach(soc))
  458. goto fail0;
  459. if (dp_hw_link_desc_pool_setup(soc))
  460. goto fail1;
  461. /* Setup SRNG rings */
  462. /* Common rings */
  463. if (dp_srng_setup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0, 0,
  464. WBM_RELEASE_RING_SIZE)) {
  465. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  466. "%s: dp_srng_setup failed for wbm_desc_rel_ring\n",
  467. __func__);
  468. goto fail1;
  469. }
  470. soc->num_tcl_data_rings = 0;
  471. /* Tx data rings */
  472. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  473. soc->num_tcl_data_rings =
  474. wlan_cfg_num_tcl_data_rings(soc->wlan_cfg_ctx);
  475. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  476. if (dp_srng_setup(soc, &soc->tcl_data_ring[i],
  477. TCL_DATA, i, 0, TCL_DATA_RING_SIZE)) {
  478. QDF_TRACE(QDF_MODULE_ID_TXRX,
  479. QDF_TRACE_LEVEL_ERROR,
  480. "%s: dp_srng_setup failed for tcl_data_ring[%d]\n",
  481. __func__, i);
  482. goto fail1;
  483. }
  484. if (dp_srng_setup(soc, &soc->tx_comp_ring[i],
  485. WBM2SW_RELEASE, i, 0, TCL_DATA_RING_SIZE)) {
  486. QDF_TRACE(QDF_MODULE_ID_TXRX,
  487. QDF_TRACE_LEVEL_ERROR,
  488. "%s: dp_srng_setup failed for tx_comp_ring[%d]\n",
  489. __func__, i);
  490. goto fail1;
  491. }
  492. }
  493. } else {
  494. /* This will be incremented during per pdev ring setup */
  495. soc->num_tcl_data_rings = 0;
  496. }
  497. if (dp_tx_soc_attach(soc)) {
  498. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  499. "%s: dp_tx_soc_attach failed\n", __func__);
  500. goto fail1;
  501. }
  502. /* TCL command and status rings */
  503. if (dp_srng_setup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0, 0,
  504. TCL_CMD_RING_SIZE)) {
  505. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  506. "%s: dp_srng_setup failed for tcl_cmd_ring\n",
  507. __func__);
  508. goto fail1;
  509. }
  510. if (dp_srng_setup(soc, &soc->tcl_status_ring, TCL_STATUS, 0, 0,
  511. TCL_STATUS_RING_SIZE)) {
  512. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  513. "%s: dp_srng_setup failed for tcl_status_ring\n",
  514. __func__);
  515. goto fail1;
  516. }
  517. /* TBD: call dp_tx_init to setup Tx SW descriptors and MSDU extension
  518. * descriptors
  519. */
  520. /* Rx data rings */
  521. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  522. soc->num_reo_dest_rings =
  523. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  524. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  525. if (dp_srng_setup(soc, &soc->reo_dest_ring[i], REO_DST,
  526. i, 0, REO_DST_RING_SIZE)) {
  527. QDF_TRACE(QDF_MODULE_ID_TXRX,
  528. QDF_TRACE_LEVEL_ERROR,
  529. "%s: dp_srng_setup failed for reo_dest_ring[%d]\n",
  530. __func__, i);
  531. goto fail1;
  532. }
  533. }
  534. } else {
  535. /* This will be incremented during per pdev ring setup */
  536. soc->num_reo_dest_rings = 0;
  537. }
  538. /* TBD: call dp_rx_init to setup Rx SW descriptors */
  539. /* REO reinjection ring */
  540. if (dp_srng_setup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0, 0,
  541. REO_REINJECT_RING_SIZE)) {
  542. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  543. "%s: dp_srng_setup failed for reo_reinject_ring\n",
  544. __func__);
  545. goto fail1;
  546. }
  547. /* Rx release ring */
  548. if (dp_srng_setup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 3, 0,
  549. RX_RELEASE_RING_SIZE)) {
  550. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  551. "%s: dp_srng_setup failed for rx_rel_ring\n",
  552. __func__);
  553. goto fail1;
  554. }
  555. /* Rx exception ring */
  556. if (dp_srng_setup(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0,
  557. MAX_REO_DEST_RINGS, REO_EXCEPTION_RING_SIZE)) {
  558. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  559. "%s: dp_srng_setup failed for reo_exception_ring\n",
  560. __func__);
  561. goto fail1;
  562. }
  563. /* REO command and status rings */
  564. if (dp_srng_setup(soc, &soc->reo_cmd_ring, REO_CMD, 0, 0,
  565. REO_CMD_RING_SIZE)) {
  566. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  567. "%s: dp_srng_setup failed for reo_cmd_ring\n",
  568. __func__);
  569. goto fail1;
  570. }
  571. if (dp_srng_setup(soc, &soc->reo_status_ring, REO_STATUS, 0, 0,
  572. REO_STATUS_RING_SIZE)) {
  573. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  574. "%s: dp_srng_setup failed for reo_status_ring\n",
  575. __func__);
  576. goto fail1;
  577. }
  578. /* Setup HW REO */
  579. hal_reo_setup(soc->hal_soc);
  580. soc->cmn_init_done = 1;
  581. return 0;
  582. fail1:
  583. /*
  584. * Cleanup will be done as part of soc_detach, which will
  585. * be called on pdev attach failure
  586. */
  587. fail0:
  588. return QDF_STATUS_E_FAILURE;
  589. }
  590. static void dp_pdev_detach_wifi3(void *txrx_pdev, int force);
  591. /*
  592. * dp_pdev_attach_wifi3() - attach txrx pdev
  593. * @osif_pdev: Opaque PDEV handle from OSIF/HDD
  594. * @txrx_soc: Datapath SOC handle
  595. * @htc_handle: HTC handle for host-target interface
  596. * @qdf_osdev: QDF OS device
  597. * @pdev_id: PDEV ID
  598. *
  599. * Return: DP PDEV handle on success, NULL on failure
  600. */
  601. void *dp_pdev_attach_wifi3(void *txrx_soc, void *ctrl_pdev,
  602. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev, int pdev_id)
  603. {
  604. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  605. struct dp_pdev *pdev = qdf_mem_malloc(sizeof(*pdev));
  606. if (!pdev) {
  607. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  608. "%s: DP PDEV memory allocation failed\n", __func__);
  609. goto fail0;
  610. }
  611. pdev->wlan_cfg_ctx = wlan_cfg_pdev_attach();
  612. if (!pdev->wlan_cfg_ctx) {
  613. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  614. "%s: pdev cfg_attach failed\n", __func__);
  615. goto fail0;
  616. }
  617. pdev->soc = soc;
  618. pdev->osif_pdev = ctrl_pdev;
  619. pdev->pdev_id = pdev_id;
  620. soc->pdev_list[pdev_id] = pdev;
  621. TAILQ_INIT(&pdev->vdev_list);
  622. pdev->vdev_count = 0;
  623. if (dp_soc_cmn_setup(soc)) {
  624. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  625. "%s: dp_soc_cmn_setup failed\n", __func__);
  626. goto fail0;
  627. }
  628. /* Setup per PDEV TCL rings if configured */
  629. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  630. if (dp_srng_setup(soc, &soc->tcl_data_ring[pdev_id], TCL_DATA,
  631. pdev_id, pdev_id, TCL_DATA_RING_SIZE)) {
  632. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  633. "%s: dp_srng_setup failed for tcl_data_ring\n",
  634. __func__);
  635. goto fail0;
  636. }
  637. if (dp_srng_setup(soc, &soc->tx_comp_ring[pdev_id],
  638. WBM2SW_RELEASE, pdev_id, pdev_id, TCL_DATA_RING_SIZE)) {
  639. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  640. "%s: dp_srng_setup failed for tx_comp_ring\n",
  641. __func__);
  642. goto fail0;
  643. }
  644. soc->num_tcl_data_rings++;
  645. }
  646. /* Tx specific init */
  647. if (dp_tx_pdev_attach(pdev)) {
  648. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  649. "%s: dp_tx_pdev_attach failed\n", __func__);
  650. goto fail0;
  651. }
  652. /* Setup per PDEV REO rings if configured */
  653. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  654. if (dp_srng_setup(soc, &soc->reo_dest_ring[pdev_id], REO_DST,
  655. pdev_id, pdev_id, REO_DST_RING_SIZE)) {
  656. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  657. "%s: dp_srng_setup failed for reo_dest_ring\n",
  658. __func__);
  659. goto fail0;
  660. }
  661. soc->num_reo_dest_rings++;
  662. }
  663. if (dp_srng_setup(soc, &pdev->rx_refill_buf_ring, RXDMA_BUF, 0, pdev_id,
  664. RXDMA_BUF_RING_SIZE)) {
  665. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  666. "%s: dp_srng_setup failed rx refill ring\n", __func__);
  667. goto fail0;
  668. }
  669. #ifdef QCA_HOST2FW_RXBUF_RING
  670. if (dp_srng_setup(soc, &pdev->rx_mac_buf_ring, RXDMA_BUF, 1, pdev_id,
  671. RXDMA_BUF_RING_SIZE)) {
  672. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  673. "%s: dp_srng_setup failed rx mac ring\n", __func__);
  674. goto fail0;
  675. }
  676. #endif
  677. /* TODO: RXDMA destination ring is not planned to be used currently.
  678. * Setup the ring when required
  679. */
  680. if (dp_srng_setup(soc, &pdev->rxdma_mon_buf_ring, RXDMA_MONITOR_BUF, 0,
  681. pdev_id, RXDMA_MONITOR_BUF_RING_SIZE)) {
  682. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  683. "%s: dp_srng_setup failed for rxdma_mon_buf_ring\n",
  684. __func__);
  685. goto fail0;
  686. }
  687. if (dp_srng_setup(soc, &pdev->rxdma_mon_dst_ring, RXDMA_MONITOR_DST, 0,
  688. pdev_id, RXDMA_MONITOR_DST_RING_SIZE)) {
  689. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  690. "%s: dp_srng_setup failed for rxdma_mon_dst_ring\n",
  691. __func__);
  692. goto fail0;
  693. }
  694. if (dp_srng_setup(soc, &pdev->rxdma_mon_status_ring,
  695. RXDMA_MONITOR_STATUS, 0, pdev_id,
  696. RXDMA_MONITOR_STATUS_RING_SIZE)) {
  697. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  698. "%s: dp_srng_setup failed for rxdma_mon_status_ring\n",
  699. __func__);
  700. goto fail0;
  701. }
  702. return (void *)pdev;
  703. fail0:
  704. dp_pdev_detach_wifi3((void *)pdev, 0);
  705. return NULL;
  706. }
  707. /*
  708. * dp_pdev_detach_wifi3() - detach txrx pdev
  709. * @txrx_pdev: Datapath PDEV handle
  710. * @force: Force detach
  711. *
  712. */
  713. static void dp_pdev_detach_wifi3(void *txrx_pdev, int force)
  714. {
  715. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  716. struct dp_soc *soc = pdev->soc;
  717. dp_tx_pdev_detach(pdev);
  718. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  719. dp_srng_cleanup(soc, &soc->tcl_data_ring[pdev->pdev_id],
  720. TCL_DATA, pdev->pdev_id);
  721. dp_srng_cleanup(soc, &soc->tx_comp_ring[pdev->pdev_id],
  722. WBM2SW_RELEASE, pdev->pdev_id);
  723. }
  724. /* Setup per PDEV REO rings if configured */
  725. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  726. dp_srng_cleanup(soc, &soc->reo_dest_ring[pdev->pdev_id],
  727. REO_DST, pdev->pdev_id);
  728. }
  729. dp_srng_cleanup(soc, &pdev->rx_refill_buf_ring, RXDMA_BUF, 0);
  730. #ifdef QCA_HOST2FW_RXBUF_RING
  731. dp_srng_cleanup(soc, &pdev->rx_mac_buf_ring, RXDMA_BUF, 1);
  732. #endif
  733. dp_srng_cleanup(soc, &pdev->rxdma_mon_buf_ring, RXDMA_MONITOR_BUF, 0);
  734. dp_srng_cleanup(soc, &pdev->rxdma_mon_dst_ring, RXDMA_MONITOR_DST, 0);
  735. dp_srng_cleanup(soc, &pdev->rxdma_mon_status_ring,
  736. RXDMA_MONITOR_STATUS, 0);
  737. soc->pdev_list[pdev->pdev_id] = NULL;
  738. qdf_mem_free(pdev);
  739. }
  740. /*
  741. * dp_soc_detach_wifi3() - Detach txrx SOC
  742. * @txrx_soc: DP SOC handle
  743. *
  744. */
  745. void dp_soc_detach_wifi3(void *txrx_soc)
  746. {
  747. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  748. struct dp_pdev *pdev = qdf_mem_malloc(sizeof(*pdev));
  749. int i;
  750. soc->cmn_init_done = 0;
  751. for (i = 0; i < MAX_PDEV_CNT; i++) {
  752. if (soc->pdev_list[i])
  753. dp_pdev_detach_wifi3((void *)pdev, 1);
  754. }
  755. dp_peer_find_detach(soc);
  756. /* TBD: Call Tx and Rx cleanup functions to free buffers and
  757. * SW descriptors
  758. */
  759. /* Free the ring memories */
  760. /* Common rings */
  761. dp_srng_cleanup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0);
  762. /* Tx data rings */
  763. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  764. dp_tx_soc_detach(soc);
  765. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  766. dp_srng_cleanup(soc, &soc->tcl_data_ring[i],
  767. TCL_DATA, i);
  768. dp_srng_cleanup(soc, &soc->tx_comp_ring[i],
  769. WBM2SW_RELEASE, i);
  770. }
  771. }
  772. /* TCL command and status rings */
  773. dp_srng_cleanup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0);
  774. dp_srng_cleanup(soc, &soc->tcl_status_ring, TCL_STATUS, 0);
  775. /* Rx data rings */
  776. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  777. soc->num_reo_dest_rings =
  778. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  779. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  780. /* TODO: Get number of rings and ring sizes
  781. * from wlan_cfg
  782. */
  783. dp_srng_cleanup(soc, &soc->reo_dest_ring[i],
  784. REO_DST, i);
  785. }
  786. }
  787. /* REO reinjection ring */
  788. dp_srng_cleanup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0);
  789. /* Rx release ring */
  790. dp_srng_cleanup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 0);
  791. /* Rx exception ring */
  792. /* TODO: Better to store ring_type and ring_num in
  793. * dp_srng during setup
  794. */
  795. dp_srng_cleanup(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0);
  796. /* REO command and status rings */
  797. dp_srng_cleanup(soc, &soc->reo_cmd_ring, REO_CMD, 0);
  798. dp_srng_cleanup(soc, &soc->reo_status_ring, REO_STATUS, 0);
  799. htt_soc_detach(soc->htt_handle);
  800. }
  801. /*
  802. * dp_soc_attach_target_wifi3() - SOC initialization in the target
  803. * @txrx_soc: Datapath SOC handle
  804. */
  805. int dp_soc_attach_target_wifi3(void *txrx_soc)
  806. {
  807. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  808. int i;
  809. htt_soc_attach_target(soc->htt_handle);
  810. for (i = 0; i < MAX_PDEV_CNT; i++) {
  811. struct dp_pdev *pdev = soc->pdev_list[i];
  812. if (pdev) {
  813. htt_srng_setup(soc->htt_handle, i,
  814. pdev->rx_refill_buf_ring.hal_srng, RXDMA_BUF);
  815. #ifdef QCA_HOST2FW_RXBUF_RING
  816. htt_srng_setup(soc->htt_handle, i,
  817. pdev->rx_mac_buf_ring.hal_srng, RXDMA_BUF);
  818. #endif
  819. #ifdef notyet /* FW doesn't handle monitor rings yet */
  820. htt_srng_setup(soc->htt_handle, i,
  821. pdev->rxdma_mon_buf_ring.hal_srng,
  822. RXDMA_MONITOR_BUF);
  823. htt_srng_setup(soc->htt_handle, i,
  824. pdev->rxdma_mon_dst_ring.hal_srng,
  825. RXDMA_MONITOR_DST);
  826. htt_srng_setup(soc->htt_handle, i,
  827. pdev->rxdma_mon_status_ring.hal_srng,
  828. RXDMA_MONITOR_STATUS);
  829. #endif
  830. }
  831. }
  832. return 0;
  833. }
  834. /*
  835. * dp_vdev_attach_wifi3() - attach txrx vdev
  836. * @txrx_pdev: Datapath PDEV handle
  837. * @vdev_mac_addr: MAC address of the virtual interface
  838. * @vdev_id: VDEV Id
  839. * @wlan_op_mode: VDEV operating mode
  840. *
  841. * Return: DP VDEV handle on success, NULL on failure
  842. */
  843. void *dp_vdev_attach_wifi3(void *txrx_pdev,
  844. uint8_t *vdev_mac_addr, uint8_t vdev_id, enum wlan_op_mode op_mode)
  845. {
  846. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  847. struct dp_soc *soc = pdev->soc;
  848. struct dp_vdev *vdev = qdf_mem_malloc(sizeof(*vdev));
  849. if (!vdev) {
  850. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  851. "%s: DP VDEV memory allocation failed\n", __func__);
  852. goto fail0;
  853. }
  854. vdev->pdev = pdev;
  855. vdev->vdev_id = vdev_id;
  856. vdev->opmode = op_mode;
  857. vdev->osdev = soc->osdev;
  858. vdev->osif_rx = NULL;
  859. vdev->osif_rx_mon = NULL;
  860. vdev->osif_vdev = NULL;
  861. vdev->delete.pending = 0;
  862. vdev->safemode = 0;
  863. vdev->drop_unenc = 1;
  864. #ifdef notyet
  865. vdev->filters_num = 0;
  866. #endif
  867. qdf_mem_copy(
  868. &vdev->mac_addr.raw[0], vdev_mac_addr, OL_TXRX_MAC_ADDR_LEN);
  869. vdev->tx_encap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  870. vdev->rx_decap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  871. /* TODO: Initialize default HTT meta data that will be used in
  872. * TCL descriptors for packets transmitted from this VDEV
  873. */
  874. TAILQ_INIT(&vdev->peer_list);
  875. /* add this vdev into the pdev's list */
  876. TAILQ_INSERT_TAIL(&pdev->vdev_list, vdev, vdev_list_elem);
  877. pdev->vdev_count++;
  878. dp_tx_vdev_attach(vdev);
  879. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  880. "Created vdev %p (%02x:%02x:%02x:%02x:%02x:%02x)\n", vdev,
  881. vdev->mac_addr.raw[0], vdev->mac_addr.raw[1],
  882. vdev->mac_addr.raw[2], vdev->mac_addr.raw[3],
  883. vdev->mac_addr.raw[4], vdev->mac_addr.raw[5]);
  884. return (void *)vdev;
  885. fail0:
  886. return NULL;
  887. }
  888. /**
  889. * dp_vdev_register_wifi3() - Register VDEV operations from osif layer
  890. * @vdev: Datapath VDEV handle
  891. * @osif_vdev: OSIF vdev handle
  892. * @txrx_ops: Tx and Rx operations
  893. *
  894. * Return: DP VDEV handle on success, NULL on failure
  895. */
  896. void dp_vdev_register_wifi3(void *vdev_handle, void *osif_vdev,
  897. struct ol_txrx_ops *txrx_ops)
  898. {
  899. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  900. vdev->osif_vdev = osif_vdev;
  901. vdev->osif_rx = txrx_ops->rx.rx;
  902. vdev->osif_rx_mon = txrx_ops->rx.mon;
  903. #ifdef notyet
  904. #if ATH_SUPPORT_WAPI
  905. vdev->osif_check_wai = txrx_ops->rx.wai_check;
  906. #endif
  907. #if UMAC_SUPPORT_PROXY_ARP
  908. vdev->osif_proxy_arp = txrx_ops->proxy_arp;
  909. #endif
  910. #endif
  911. #ifdef notyet
  912. /* TODO: Enable the following once Tx code is integrated */
  913. txrx_ops->tx.tx = dp_tx_send;
  914. #endif
  915. }
  916. /*
  917. * dp_vdev_detach_wifi3() - Detach txrx vdev
  918. * @txrx_vdev: Datapath VDEV handle
  919. * @callback: Callback OL_IF on completion of detach
  920. * @cb_context: Callback context
  921. *
  922. */
  923. void dp_vdev_detach_wifi3(void *vdev_handle,
  924. ol_txrx_vdev_delete_cb callback, void *cb_context)
  925. {
  926. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  927. struct dp_pdev *pdev = vdev->pdev;
  928. struct dp_soc *soc = pdev->soc;
  929. /* preconditions */
  930. qdf_assert(vdev);
  931. /* remove the vdev from its parent pdev's list */
  932. TAILQ_REMOVE(&pdev->vdev_list, vdev, vdev_list_elem);
  933. /*
  934. * Use peer_ref_mutex while accessing peer_list, in case
  935. * a peer is in the process of being removed from the list.
  936. */
  937. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  938. /* check that the vdev has no peers allocated */
  939. if (!TAILQ_EMPTY(&vdev->peer_list)) {
  940. /* debug print - will be removed later */
  941. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  942. "%s: not deleting vdev object %p (%02x:%02x:%02x:%02x:%02x:%02x)"
  943. "until deletion finishes for all its peers\n",
  944. __func__, vdev,
  945. vdev->mac_addr.raw[0], vdev->mac_addr.raw[1],
  946. vdev->mac_addr.raw[2], vdev->mac_addr.raw[3],
  947. vdev->mac_addr.raw[4], vdev->mac_addr.raw[5]);
  948. /* indicate that the vdev needs to be deleted */
  949. vdev->delete.pending = 1;
  950. vdev->delete.callback = callback;
  951. vdev->delete.context = cb_context;
  952. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  953. return;
  954. }
  955. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  956. dp_tx_vdev_detach(vdev);
  957. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  958. "%s: deleting vdev object %p (%02x:%02x:%02x:%02x:%02x:%02x)\n",
  959. __func__, vdev,
  960. vdev->mac_addr.raw[0], vdev->mac_addr.raw[1],
  961. vdev->mac_addr.raw[2], vdev->mac_addr.raw[3],
  962. vdev->mac_addr.raw[4], vdev->mac_addr.raw[5]);
  963. qdf_mem_free(vdev);
  964. if (callback)
  965. callback(cb_context);
  966. }
  967. /*
  968. * dp_peer_attach_wifi3() - attach txrx peer
  969. * @txrx_vdev: Datapath VDEV handle
  970. * @peer_mac_addr: Peer MAC address
  971. *
  972. * Return: DP peeer handle on success, NULL on failure
  973. */
  974. void *dp_peer_attach_wifi3(void *vdev_handle, uint8_t *peer_mac_addr)
  975. {
  976. struct dp_peer *peer;
  977. int i;
  978. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  979. struct dp_pdev *pdev;
  980. struct dp_soc *soc;
  981. /* preconditions */
  982. qdf_assert(vdev);
  983. qdf_assert(peer_mac_addr);
  984. pdev = vdev->pdev;
  985. soc = pdev->soc;
  986. #ifdef notyet
  987. peer = (struct dp_peer *)qdf_mempool_alloc(soc->osdev,
  988. soc->mempool_ol_ath_peer);
  989. #else
  990. peer = (struct dp_peer *)qdf_mem_malloc(sizeof(*peer));
  991. #endif
  992. if (!peer)
  993. return NULL; /* failure */
  994. qdf_mem_zero(peer, sizeof(struct dp_peer));
  995. /* store provided params */
  996. peer->vdev = vdev;
  997. qdf_mem_copy(
  998. &peer->mac_addr.raw[0], peer_mac_addr, OL_TXRX_MAC_ADDR_LEN);
  999. /* TODO: See of rx_opt_proc is really required */
  1000. peer->rx_opt_proc = soc->rx_opt_proc;
  1001. dp_peer_rx_init(pdev, peer);
  1002. /* initialize the peer_id */
  1003. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++)
  1004. peer->peer_ids[i] = HTT_INVALID_PEER;
  1005. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  1006. qdf_atomic_init(&peer->ref_cnt);
  1007. /* keep one reference for attach */
  1008. qdf_atomic_inc(&peer->ref_cnt);
  1009. /* add this peer into the vdev's list */
  1010. TAILQ_INSERT_TAIL(&vdev->peer_list, peer, peer_list_elem);
  1011. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1012. /* TODO: See if hash based search is required */
  1013. dp_peer_find_hash_add(soc, peer);
  1014. if (soc->ol_ops->peer_set_default_routing) {
  1015. /* TODO: Check on the destination ring number to be passed
  1016. * to FW
  1017. */
  1018. soc->ol_ops->peer_set_default_routing(soc->osif_soc,
  1019. peer->mac_addr.raw, peer->vdev->vdev_id, 0, 1);
  1020. }
  1021. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1022. "vdev %p created peer %p (%02x:%02x:%02x:%02x:%02x:%02x)\n",
  1023. vdev, peer,
  1024. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  1025. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  1026. peer->mac_addr.raw[4], peer->mac_addr.raw[5]);
  1027. /*
  1028. * For every peer MAp message search and set if bss_peer
  1029. */
  1030. if (memcmp(peer->mac_addr.raw, vdev->mac_addr.raw, 6) == 0) {
  1031. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1032. "vdev bss_peer!!!!\n");
  1033. peer->bss_peer = 1;
  1034. vdev->vap_bss_peer = peer;
  1035. }
  1036. return (void *)peer;
  1037. }
  1038. /*
  1039. * dp_peer_authorize() - authorize txrx peer
  1040. * @peer_handle: Datapath peer handle
  1041. * @authorize
  1042. *
  1043. */
  1044. void dp_peer_authorize(void *peer_handle, uint32_t authorize)
  1045. {
  1046. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  1047. struct dp_soc *soc;
  1048. if (peer != NULL) {
  1049. soc = peer->vdev->pdev->soc;
  1050. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  1051. peer->authorize = authorize ? 1 : 0;
  1052. #ifdef notyet /* ATH_BAND_STEERING */
  1053. peer->peer_bs_inact_flag = 0;
  1054. peer->peer_bs_inact = soc->pdev_bs_inact_reload;
  1055. #endif
  1056. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1057. }
  1058. }
  1059. /*
  1060. * dp_peer_unref_delete() - unref and delete peer
  1061. * @peer_handle: Datapath peer handle
  1062. *
  1063. */
  1064. void dp_peer_unref_delete(void *peer_handle)
  1065. {
  1066. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  1067. struct dp_vdev *vdev = peer->vdev;
  1068. struct dp_soc *soc = vdev->pdev->soc;
  1069. struct dp_peer *tmppeer;
  1070. int found = 0;
  1071. uint16_t peer_id;
  1072. /*
  1073. * Hold the lock all the way from checking if the peer ref count
  1074. * is zero until the peer references are removed from the hash
  1075. * table and vdev list (if the peer ref count is zero).
  1076. * This protects against a new HL tx operation starting to use the
  1077. * peer object just after this function concludes it's done being used.
  1078. * Furthermore, the lock needs to be held while checking whether the
  1079. * vdev's list of peers is empty, to make sure that list is not modified
  1080. * concurrently with the empty check.
  1081. */
  1082. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  1083. if (qdf_atomic_dec_and_test(&peer->ref_cnt)) {
  1084. peer_id = peer->peer_ids[0];
  1085. /*
  1086. * Make sure that the reference to the peer in
  1087. * peer object map is removed
  1088. */
  1089. if (peer_id != HTT_INVALID_PEER)
  1090. soc->peer_id_to_obj_map[peer_id] = NULL;
  1091. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1092. "Deleting peer %p (%02x:%02x:%02x:%02x:%02x:%02x)\n",
  1093. peer, peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  1094. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  1095. peer->mac_addr.raw[4], peer->mac_addr.raw[5]);
  1096. /* remove the reference to the peer from the hash table */
  1097. dp_peer_find_hash_remove(soc, peer);
  1098. TAILQ_FOREACH(tmppeer, &peer->vdev->peer_list, peer_list_elem) {
  1099. if (tmppeer == peer) {
  1100. found = 1;
  1101. break;
  1102. }
  1103. }
  1104. if (found) {
  1105. TAILQ_REMOVE(&peer->vdev->peer_list, peer,
  1106. peer_list_elem);
  1107. } else {
  1108. /*Ignoring the remove operation as peer not found*/
  1109. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  1110. "WARN peer %p not found in vdev (%p)->peer_list:%p\n",
  1111. peer, vdev, &peer->vdev->peer_list);
  1112. }
  1113. /* cleanup the Rx reorder queues for this peer */
  1114. dp_peer_rx_cleanup(vdev, peer);
  1115. /* check whether the parent vdev has no peers left */
  1116. if (TAILQ_EMPTY(&vdev->peer_list)) {
  1117. /*
  1118. * Now that there are no references to the peer, we can
  1119. * release the peer reference lock.
  1120. */
  1121. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1122. /*
  1123. * Check if the parent vdev was waiting for its peers
  1124. * to be deleted, in order for it to be deleted too.
  1125. */
  1126. if (vdev->delete.pending) {
  1127. ol_txrx_vdev_delete_cb vdev_delete_cb =
  1128. vdev->delete.callback;
  1129. void *vdev_delete_context =
  1130. vdev->delete.context;
  1131. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1132. QDF_TRACE_LEVEL_INFO_HIGH,
  1133. "%s: deleting vdev object %p "
  1134. "(%02x:%02x:%02x:%02x:%02x:%02x)"
  1135. " - its last peer is done\n",
  1136. __func__, vdev,
  1137. vdev->mac_addr.raw[0],
  1138. vdev->mac_addr.raw[1],
  1139. vdev->mac_addr.raw[2],
  1140. vdev->mac_addr.raw[3],
  1141. vdev->mac_addr.raw[4],
  1142. vdev->mac_addr.raw[5]);
  1143. /* all peers are gone, go ahead and delete it */
  1144. qdf_mem_free(vdev);
  1145. if (vdev_delete_cb)
  1146. vdev_delete_cb(vdev_delete_context);
  1147. }
  1148. } else {
  1149. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1150. }
  1151. #ifdef notyet
  1152. qdf_mempool_free(soc->osdev, soc->mempool_ol_ath_peer, peer);
  1153. #else
  1154. qdf_mem_free(peer);
  1155. #endif
  1156. #ifdef notyet /* See why this should be done in DP layer */
  1157. qdf_atomic_inc(&soc->peer_count);
  1158. #endif
  1159. } else {
  1160. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1161. }
  1162. }
  1163. /*
  1164. * dp_peer_detach_wifi3() – Detach txrx peer
  1165. * @peer_handle: Datapath peer handle
  1166. *
  1167. */
  1168. void dp_peer_detach_wifi3(void *peer_handle)
  1169. {
  1170. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  1171. /* redirect the peer's rx delivery function to point to a
  1172. * discard func
  1173. */
  1174. peer->rx_opt_proc = dp_rx_discard;
  1175. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1176. "%s:peer %p (%02x:%02x:%02x:%02x:%02x:%02x)\n", __func__, peer,
  1177. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  1178. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  1179. peer->mac_addr.raw[4], peer->mac_addr.raw[5]);
  1180. /*
  1181. * Remove the reference added during peer_attach.
  1182. * The peer will still be left allocated until the
  1183. * PEER_UNMAP message arrives to remove the other
  1184. * reference, added by the PEER_MAP message.
  1185. */
  1186. dp_peer_unref_delete(peer_handle);
  1187. }