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