dp.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  1. // SPDX-License-Identifier: BSD-3-Clause-Clear
  2. /*
  3. * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
  5. */
  6. #include <crypto/hash.h>
  7. #include "core.h"
  8. #include "dp_tx.h"
  9. #include "hif.h"
  10. #include "hal.h"
  11. #include "debug.h"
  12. #include "peer.h"
  13. #include "dp_cmn.h"
  14. enum ath12k_dp_desc_type {
  15. ATH12K_DP_TX_DESC,
  16. ATH12K_DP_RX_DESC,
  17. };
  18. void ath12k_dp_peer_cleanup(struct ath12k *ar, int vdev_id, const u8 *addr)
  19. {
  20. struct ath12k_base *ab = ar->ab;
  21. struct ath12k_dp_link_peer *peer;
  22. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  23. /* TODO: Any other peer specific DP cleanup */
  24. spin_lock_bh(&dp->dp_lock);
  25. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, vdev_id, addr);
  26. if (!peer || !peer->dp_peer) {
  27. ath12k_warn(ab, "failed to lookup peer %pM on vdev %d\n",
  28. addr, vdev_id);
  29. spin_unlock_bh(&dp->dp_lock);
  30. return;
  31. }
  32. if (!peer->primary_link) {
  33. spin_unlock_bh(&dp->dp_lock);
  34. return;
  35. }
  36. ath12k_dp_rx_peer_tid_cleanup(ar, peer);
  37. crypto_free_shash(peer->dp_peer->tfm_mmic);
  38. peer->dp_peer->dp_setup_done = false;
  39. spin_unlock_bh(&dp->dp_lock);
  40. }
  41. int ath12k_dp_peer_setup(struct ath12k *ar, int vdev_id, const u8 *addr)
  42. {
  43. struct ath12k_base *ab = ar->ab;
  44. struct ath12k_dp_link_peer *peer;
  45. u32 reo_dest;
  46. int ret = 0, tid;
  47. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  48. /* NOTE: reo_dest ring id starts from 1 unlike mac_id which starts from 0 */
  49. reo_dest = ar->dp.mac_id + 1;
  50. ret = ath12k_wmi_set_peer_param(ar, addr, vdev_id,
  51. WMI_PEER_SET_DEFAULT_ROUTING,
  52. DP_RX_HASH_ENABLE | (reo_dest << 1));
  53. if (ret) {
  54. ath12k_warn(ab, "failed to set default routing %d peer :%pM vdev_id :%d\n",
  55. ret, addr, vdev_id);
  56. return ret;
  57. }
  58. for (tid = 0; tid <= IEEE80211_NUM_TIDS; tid++) {
  59. ret = ath12k_dp_rx_peer_tid_setup(ar, addr, vdev_id, tid, 1, 0,
  60. HAL_PN_TYPE_NONE);
  61. if (ret) {
  62. ath12k_warn(ab, "failed to setup rxd tid queue for tid %d: %d\n",
  63. tid, ret);
  64. goto peer_clean;
  65. }
  66. }
  67. ret = ath12k_dp_rx_peer_frag_setup(ar, addr, vdev_id);
  68. if (ret) {
  69. ath12k_warn(ab, "failed to setup rx defrag context\n");
  70. goto peer_clean;
  71. }
  72. /* TODO: Setup other peer specific resource used in data path */
  73. return 0;
  74. peer_clean:
  75. spin_lock_bh(&dp->dp_lock);
  76. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, vdev_id, addr);
  77. if (!peer) {
  78. ath12k_warn(ab, "failed to find the peer to del rx tid\n");
  79. spin_unlock_bh(&dp->dp_lock);
  80. return -ENOENT;
  81. }
  82. for (tid--; tid >= 0; tid--)
  83. ath12k_dp_arch_rx_peer_tid_delete(dp, peer, tid);
  84. spin_unlock_bh(&dp->dp_lock);
  85. return ret;
  86. }
  87. void ath12k_dp_srng_cleanup(struct ath12k_base *ab, struct dp_srng *ring)
  88. {
  89. if (!ring->vaddr_unaligned)
  90. return;
  91. dma_free_coherent(ab->dev, ring->size, ring->vaddr_unaligned,
  92. ring->paddr_unaligned);
  93. ring->vaddr_unaligned = NULL;
  94. }
  95. static int ath12k_dp_srng_find_ring_in_mask(int ring_num, const u8 *grp_mask)
  96. {
  97. int ext_group_num;
  98. u8 mask = 1 << ring_num;
  99. for (ext_group_num = 0; ext_group_num < ATH12K_EXT_IRQ_GRP_NUM_MAX;
  100. ext_group_num++) {
  101. if (mask & grp_mask[ext_group_num])
  102. return ext_group_num;
  103. }
  104. return -ENOENT;
  105. }
  106. static int ath12k_dp_srng_calculate_msi_group(struct ath12k_base *ab,
  107. enum hal_ring_type type, int ring_num)
  108. {
  109. const struct ath12k_hal_tcl_to_wbm_rbm_map *map;
  110. const u8 *grp_mask;
  111. int i;
  112. switch (type) {
  113. case HAL_WBM2SW_RELEASE:
  114. if (ring_num == HAL_WBM2SW_REL_ERR_RING_NUM) {
  115. grp_mask = &ab->hw_params->ring_mask->rx_wbm_rel[0];
  116. ring_num = 0;
  117. } else {
  118. map = ab->hal.tcl_to_wbm_rbm_map;
  119. for (i = 0; i < ab->hw_params->max_tx_ring; i++) {
  120. if (ring_num == map[i].wbm_ring_num) {
  121. ring_num = i;
  122. break;
  123. }
  124. }
  125. grp_mask = &ab->hw_params->ring_mask->tx[0];
  126. }
  127. break;
  128. case HAL_REO_EXCEPTION:
  129. grp_mask = &ab->hw_params->ring_mask->rx_err[0];
  130. break;
  131. case HAL_REO_DST:
  132. grp_mask = &ab->hw_params->ring_mask->rx[0];
  133. break;
  134. case HAL_REO_STATUS:
  135. grp_mask = &ab->hw_params->ring_mask->reo_status[0];
  136. break;
  137. case HAL_RXDMA_MONITOR_STATUS:
  138. grp_mask = &ab->hw_params->ring_mask->rx_mon_status[0];
  139. break;
  140. case HAL_RXDMA_MONITOR_DST:
  141. grp_mask = &ab->hw_params->ring_mask->rx_mon_dest[0];
  142. break;
  143. case HAL_TX_MONITOR_DST:
  144. grp_mask = &ab->hw_params->ring_mask->tx_mon_dest[0];
  145. break;
  146. case HAL_RXDMA_BUF:
  147. grp_mask = &ab->hw_params->ring_mask->host2rxdma[0];
  148. break;
  149. case HAL_RXDMA_MONITOR_BUF:
  150. case HAL_TCL_DATA:
  151. case HAL_TCL_CMD:
  152. case HAL_REO_CMD:
  153. case HAL_SW2WBM_RELEASE:
  154. case HAL_WBM_IDLE_LINK:
  155. case HAL_TCL_STATUS:
  156. case HAL_REO_REINJECT:
  157. case HAL_CE_SRC:
  158. case HAL_CE_DST:
  159. case HAL_CE_DST_STATUS:
  160. default:
  161. return -ENOENT;
  162. }
  163. return ath12k_dp_srng_find_ring_in_mask(ring_num, grp_mask);
  164. }
  165. static void ath12k_dp_srng_msi_setup(struct ath12k_base *ab,
  166. struct hal_srng_params *ring_params,
  167. enum hal_ring_type type, int ring_num)
  168. {
  169. int msi_group_number, msi_data_count;
  170. u32 msi_data_start, msi_irq_start, addr_lo, addr_hi;
  171. int ret;
  172. ret = ath12k_hif_get_user_msi_vector(ab, "DP",
  173. &msi_data_count, &msi_data_start,
  174. &msi_irq_start);
  175. if (ret)
  176. return;
  177. msi_group_number = ath12k_dp_srng_calculate_msi_group(ab, type,
  178. ring_num);
  179. if (msi_group_number < 0) {
  180. ath12k_dbg(ab, ATH12K_DBG_PCI,
  181. "ring not part of an ext_group; ring_type: %d,ring_num %d",
  182. type, ring_num);
  183. ring_params->msi_addr = 0;
  184. ring_params->msi_data = 0;
  185. return;
  186. }
  187. if (msi_group_number > msi_data_count) {
  188. ath12k_dbg(ab, ATH12K_DBG_PCI,
  189. "multiple msi_groups share one msi, msi_group_num %d",
  190. msi_group_number);
  191. }
  192. ath12k_hif_get_msi_address(ab, &addr_lo, &addr_hi);
  193. ring_params->msi_addr = addr_lo;
  194. ring_params->msi_addr |= (dma_addr_t)(((uint64_t)addr_hi) << 32);
  195. ring_params->msi_data = (msi_group_number % msi_data_count)
  196. + msi_data_start;
  197. ring_params->flags |= HAL_SRNG_FLAGS_MSI_INTR;
  198. }
  199. int ath12k_dp_srng_setup(struct ath12k_base *ab, struct dp_srng *ring,
  200. enum hal_ring_type type, int ring_num,
  201. int mac_id, int num_entries)
  202. {
  203. struct hal_srng_params params = {};
  204. int entry_sz = ath12k_hal_srng_get_entrysize(ab, type);
  205. int max_entries = ath12k_hal_srng_get_max_entries(ab, type);
  206. int ret;
  207. if (max_entries < 0 || entry_sz < 0)
  208. return -EINVAL;
  209. if (num_entries > max_entries)
  210. num_entries = max_entries;
  211. ring->size = (num_entries * entry_sz) + HAL_RING_BASE_ALIGN - 1;
  212. ring->vaddr_unaligned = dma_alloc_coherent(ab->dev, ring->size,
  213. &ring->paddr_unaligned,
  214. GFP_KERNEL);
  215. if (!ring->vaddr_unaligned)
  216. return -ENOMEM;
  217. ring->vaddr = PTR_ALIGN(ring->vaddr_unaligned, HAL_RING_BASE_ALIGN);
  218. ring->paddr = ring->paddr_unaligned + ((unsigned long)ring->vaddr -
  219. (unsigned long)ring->vaddr_unaligned);
  220. params.ring_base_vaddr = ring->vaddr;
  221. params.ring_base_paddr = ring->paddr;
  222. params.num_entries = num_entries;
  223. ath12k_dp_srng_msi_setup(ab, &params, type, ring_num + mac_id);
  224. switch (type) {
  225. case HAL_REO_DST:
  226. params.intr_batch_cntr_thres_entries =
  227. HAL_SRNG_INT_BATCH_THRESHOLD_RX;
  228. params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_RX;
  229. break;
  230. case HAL_RXDMA_BUF:
  231. case HAL_RXDMA_MONITOR_BUF:
  232. params.low_threshold = num_entries >> 3;
  233. params.flags |= HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN;
  234. params.intr_batch_cntr_thres_entries = 0;
  235. params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_RX;
  236. break;
  237. case HAL_RXDMA_MONITOR_STATUS:
  238. params.low_threshold = num_entries >> 3;
  239. params.flags |= HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN;
  240. params.intr_batch_cntr_thres_entries = 1;
  241. params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_RX;
  242. break;
  243. case HAL_TX_MONITOR_DST:
  244. params.low_threshold = DP_TX_MONITOR_BUF_SIZE_MAX >> 3;
  245. params.flags |= HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN;
  246. params.intr_batch_cntr_thres_entries = 0;
  247. params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_RX;
  248. break;
  249. case HAL_WBM2SW_RELEASE:
  250. if (ab->hw_params->hw_ops->dp_srng_is_tx_comp_ring(ring_num)) {
  251. params.intr_batch_cntr_thres_entries =
  252. HAL_SRNG_INT_BATCH_THRESHOLD_TX;
  253. params.intr_timer_thres_us =
  254. HAL_SRNG_INT_TIMER_THRESHOLD_TX;
  255. break;
  256. }
  257. /* follow through when ring_num != HAL_WBM2SW_REL_ERR_RING_NUM */
  258. fallthrough;
  259. case HAL_REO_EXCEPTION:
  260. case HAL_REO_REINJECT:
  261. case HAL_REO_CMD:
  262. case HAL_REO_STATUS:
  263. case HAL_TCL_DATA:
  264. case HAL_TCL_CMD:
  265. case HAL_TCL_STATUS:
  266. case HAL_WBM_IDLE_LINK:
  267. case HAL_SW2WBM_RELEASE:
  268. case HAL_RXDMA_DST:
  269. case HAL_RXDMA_MONITOR_DST:
  270. case HAL_RXDMA_MONITOR_DESC:
  271. params.intr_batch_cntr_thres_entries =
  272. HAL_SRNG_INT_BATCH_THRESHOLD_OTHER;
  273. params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_OTHER;
  274. break;
  275. case HAL_RXDMA_DIR_BUF:
  276. break;
  277. default:
  278. ath12k_warn(ab, "Not a valid ring type in dp :%d\n", type);
  279. return -EINVAL;
  280. }
  281. ret = ath12k_hal_srng_setup(ab, type, ring_num, mac_id, &params);
  282. if (ret < 0) {
  283. ath12k_warn(ab, "failed to setup srng: %d ring_id %d\n",
  284. ret, ring_num);
  285. return ret;
  286. }
  287. ring->ring_id = ret;
  288. return 0;
  289. }
  290. static int ath12k_dp_tx_get_bank_profile(struct ath12k_base *ab,
  291. struct ath12k_link_vif *arvif,
  292. struct ath12k_dp *dp)
  293. {
  294. int bank_id = DP_INVALID_BANK_ID;
  295. int i;
  296. u32 bank_config;
  297. bool configure_register = false;
  298. /* convert vdev params into hal_tx_bank_config */
  299. bank_config = ath12k_dp_arch_tx_get_vdev_bank_config(dp, arvif);
  300. spin_lock_bh(&dp->tx_bank_lock);
  301. /* TODO: implement using idr kernel framework*/
  302. for (i = 0; i < dp->num_bank_profiles; i++) {
  303. if (dp->bank_profiles[i].is_configured &&
  304. (dp->bank_profiles[i].bank_config ^ bank_config) == 0) {
  305. bank_id = i;
  306. goto inc_ref_and_return;
  307. }
  308. if (!dp->bank_profiles[i].is_configured ||
  309. !dp->bank_profiles[i].num_users) {
  310. bank_id = i;
  311. goto configure_and_return;
  312. }
  313. }
  314. if (bank_id == DP_INVALID_BANK_ID) {
  315. spin_unlock_bh(&dp->tx_bank_lock);
  316. ath12k_err(ab, "unable to find TX bank!");
  317. return bank_id;
  318. }
  319. configure_and_return:
  320. dp->bank_profiles[bank_id].is_configured = true;
  321. dp->bank_profiles[bank_id].bank_config = bank_config;
  322. configure_register = true;
  323. inc_ref_and_return:
  324. dp->bank_profiles[bank_id].num_users++;
  325. spin_unlock_bh(&dp->tx_bank_lock);
  326. if (configure_register)
  327. ath12k_hal_tx_configure_bank_register(ab,
  328. bank_config, bank_id);
  329. ath12k_dbg(ab, ATH12K_DBG_DP_HTT, "dp_htt tcl bank_id %d input 0x%x match 0x%x num_users %u",
  330. bank_id, bank_config, dp->bank_profiles[bank_id].bank_config,
  331. dp->bank_profiles[bank_id].num_users);
  332. return bank_id;
  333. }
  334. void ath12k_dp_tx_put_bank_profile(struct ath12k_dp *dp, u8 bank_id)
  335. {
  336. spin_lock_bh(&dp->tx_bank_lock);
  337. dp->bank_profiles[bank_id].num_users--;
  338. spin_unlock_bh(&dp->tx_bank_lock);
  339. }
  340. static void ath12k_dp_deinit_bank_profiles(struct ath12k_base *ab)
  341. {
  342. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  343. kfree(dp->bank_profiles);
  344. dp->bank_profiles = NULL;
  345. }
  346. static int ath12k_dp_init_bank_profiles(struct ath12k_base *ab)
  347. {
  348. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  349. u32 num_tcl_banks = ab->hw_params->num_tcl_banks;
  350. int i;
  351. dp->num_bank_profiles = num_tcl_banks;
  352. dp->bank_profiles = kmalloc_objs(struct ath12k_dp_tx_bank_profile,
  353. num_tcl_banks);
  354. if (!dp->bank_profiles)
  355. return -ENOMEM;
  356. spin_lock_init(&dp->tx_bank_lock);
  357. for (i = 0; i < num_tcl_banks; i++) {
  358. dp->bank_profiles[i].is_configured = false;
  359. dp->bank_profiles[i].num_users = 0;
  360. }
  361. return 0;
  362. }
  363. static void ath12k_dp_srng_common_cleanup(struct ath12k_base *ab)
  364. {
  365. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  366. int i;
  367. ath12k_dp_srng_cleanup(ab, &dp->reo_status_ring);
  368. ath12k_dp_srng_cleanup(ab, &dp->reo_cmd_ring);
  369. ath12k_dp_srng_cleanup(ab, &dp->reo_except_ring);
  370. ath12k_dp_srng_cleanup(ab, &dp->rx_rel_ring);
  371. ath12k_dp_srng_cleanup(ab, &dp->reo_reinject_ring);
  372. for (i = 0; i < ab->hw_params->max_tx_ring; i++) {
  373. ath12k_dp_srng_cleanup(ab, &dp->tx_ring[i].tcl_comp_ring);
  374. ath12k_dp_srng_cleanup(ab, &dp->tx_ring[i].tcl_data_ring);
  375. }
  376. ath12k_dp_srng_cleanup(ab, &dp->wbm_desc_rel_ring);
  377. }
  378. static int ath12k_dp_srng_common_setup(struct ath12k_base *ab)
  379. {
  380. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  381. const struct ath12k_hal_tcl_to_wbm_rbm_map *map;
  382. struct hal_srng *srng;
  383. int i, ret, tx_comp_ring_num;
  384. u32 ring_hash_map;
  385. ret = ath12k_dp_srng_setup(ab, &dp->wbm_desc_rel_ring,
  386. HAL_SW2WBM_RELEASE, 0, 0,
  387. DP_WBM_RELEASE_RING_SIZE);
  388. if (ret) {
  389. ath12k_warn(ab, "failed to set up wbm2sw_release ring :%d\n",
  390. ret);
  391. goto err;
  392. }
  393. for (i = 0; i < ab->hw_params->max_tx_ring; i++) {
  394. map = ab->hal.tcl_to_wbm_rbm_map;
  395. tx_comp_ring_num = map[i].wbm_ring_num;
  396. ret = ath12k_dp_srng_setup(ab, &dp->tx_ring[i].tcl_data_ring,
  397. HAL_TCL_DATA, i, 0,
  398. DP_TCL_DATA_RING_SIZE);
  399. if (ret) {
  400. ath12k_warn(ab, "failed to set up tcl_data ring (%d) :%d\n",
  401. i, ret);
  402. goto err;
  403. }
  404. ret = ath12k_dp_srng_setup(ab, &dp->tx_ring[i].tcl_comp_ring,
  405. HAL_WBM2SW_RELEASE, tx_comp_ring_num, 0,
  406. DP_TX_COMP_RING_SIZE(ab));
  407. if (ret) {
  408. ath12k_warn(ab, "failed to set up tcl_comp ring (%d) :%d\n",
  409. tx_comp_ring_num, ret);
  410. goto err;
  411. }
  412. }
  413. ret = ath12k_dp_srng_setup(ab, &dp->reo_reinject_ring, HAL_REO_REINJECT,
  414. 0, 0, DP_REO_REINJECT_RING_SIZE);
  415. if (ret) {
  416. ath12k_warn(ab, "failed to set up reo_reinject ring :%d\n",
  417. ret);
  418. goto err;
  419. }
  420. ret = ath12k_dp_srng_setup(ab, &dp->rx_rel_ring, HAL_WBM2SW_RELEASE,
  421. HAL_WBM2SW_REL_ERR_RING_NUM, 0,
  422. DP_RX_RELEASE_RING_SIZE);
  423. if (ret) {
  424. ath12k_warn(ab, "failed to set up rx_rel ring :%d\n", ret);
  425. goto err;
  426. }
  427. ret = ath12k_dp_srng_setup(ab, &dp->reo_except_ring, HAL_REO_EXCEPTION,
  428. 0, 0, DP_REO_EXCEPTION_RING_SIZE);
  429. if (ret) {
  430. ath12k_warn(ab, "failed to set up reo_exception ring :%d\n",
  431. ret);
  432. goto err;
  433. }
  434. ret = ath12k_dp_srng_setup(ab, &dp->reo_cmd_ring, HAL_REO_CMD,
  435. 0, 0, DP_REO_CMD_RING_SIZE);
  436. if (ret) {
  437. ath12k_warn(ab, "failed to set up reo_cmd ring :%d\n", ret);
  438. goto err;
  439. }
  440. srng = &ab->hal.srng_list[dp->reo_cmd_ring.ring_id];
  441. ath12k_hal_reo_init_cmd_ring(ab, srng);
  442. ret = ath12k_dp_srng_setup(ab, &dp->reo_status_ring, HAL_REO_STATUS,
  443. 0, 0, DP_REO_STATUS_RING_SIZE);
  444. if (ret) {
  445. ath12k_warn(ab, "failed to set up reo_status ring :%d\n", ret);
  446. goto err;
  447. }
  448. /* When hash based routing of rx packet is enabled, 32 entries to map
  449. * the hash values to the ring will be configured. Each hash entry uses
  450. * four bits to map to a particular ring. The ring mapping will be
  451. * 0:TCL, 1:SW1, 2:SW2, 3:SW3, 4:SW4, 5:Release, 6:FW and 7:SW5
  452. * 8:SW6, 9:SW7, 10:SW8, 11:Not used.
  453. */
  454. ring_hash_map = HAL_HASH_ROUTING_RING_SW1 |
  455. HAL_HASH_ROUTING_RING_SW2 << 4 |
  456. HAL_HASH_ROUTING_RING_SW3 << 8 |
  457. HAL_HASH_ROUTING_RING_SW4 << 12 |
  458. HAL_HASH_ROUTING_RING_SW1 << 16 |
  459. HAL_HASH_ROUTING_RING_SW2 << 20 |
  460. HAL_HASH_ROUTING_RING_SW3 << 24 |
  461. HAL_HASH_ROUTING_RING_SW4 << 28;
  462. ath12k_hal_reo_hw_setup(ab, ring_hash_map);
  463. return 0;
  464. err:
  465. ath12k_dp_srng_common_cleanup(ab);
  466. return ret;
  467. }
  468. static void ath12k_dp_scatter_idle_link_desc_cleanup(struct ath12k_base *ab)
  469. {
  470. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  471. struct hal_wbm_idle_scatter_list *slist = dp->scatter_list;
  472. int i;
  473. for (i = 0; i < DP_IDLE_SCATTER_BUFS_MAX; i++) {
  474. if (!slist[i].vaddr)
  475. continue;
  476. dma_free_coherent(ab->dev, HAL_WBM_IDLE_SCATTER_BUF_SIZE_MAX,
  477. slist[i].vaddr, slist[i].paddr);
  478. slist[i].vaddr = NULL;
  479. }
  480. }
  481. static int ath12k_dp_scatter_idle_link_desc_setup(struct ath12k_base *ab,
  482. int size,
  483. u32 n_link_desc_bank,
  484. u32 n_link_desc,
  485. u32 last_bank_sz)
  486. {
  487. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  488. struct dp_link_desc_bank *link_desc_banks = dp->link_desc_banks;
  489. struct hal_wbm_idle_scatter_list *slist = dp->scatter_list;
  490. u32 n_entries_per_buf;
  491. int num_scatter_buf, scatter_idx;
  492. struct hal_wbm_link_desc *scatter_buf;
  493. int align_bytes, n_entries;
  494. dma_addr_t paddr;
  495. int rem_entries;
  496. int i;
  497. int ret = 0;
  498. u32 end_offset, cookie;
  499. enum hal_rx_buf_return_buf_manager rbm = dp->idle_link_rbm;
  500. n_entries_per_buf = HAL_WBM_IDLE_SCATTER_BUF_SIZE /
  501. ath12k_hal_srng_get_entrysize(ab, HAL_WBM_IDLE_LINK);
  502. num_scatter_buf = DIV_ROUND_UP(size, HAL_WBM_IDLE_SCATTER_BUF_SIZE);
  503. if (num_scatter_buf > DP_IDLE_SCATTER_BUFS_MAX)
  504. return -EINVAL;
  505. for (i = 0; i < num_scatter_buf; i++) {
  506. slist[i].vaddr = dma_alloc_coherent(ab->dev,
  507. HAL_WBM_IDLE_SCATTER_BUF_SIZE_MAX,
  508. &slist[i].paddr, GFP_KERNEL);
  509. if (!slist[i].vaddr) {
  510. ret = -ENOMEM;
  511. goto err;
  512. }
  513. }
  514. scatter_idx = 0;
  515. scatter_buf = slist[scatter_idx].vaddr;
  516. rem_entries = n_entries_per_buf;
  517. for (i = 0; i < n_link_desc_bank; i++) {
  518. align_bytes = link_desc_banks[i].vaddr -
  519. link_desc_banks[i].vaddr_unaligned;
  520. n_entries = (DP_LINK_DESC_ALLOC_SIZE_THRESH - align_bytes) /
  521. HAL_LINK_DESC_SIZE;
  522. paddr = link_desc_banks[i].paddr;
  523. while (n_entries) {
  524. cookie = DP_LINK_DESC_COOKIE_SET(n_entries, i);
  525. ath12k_hal_set_link_desc_addr(dp->hal, scatter_buf, cookie,
  526. paddr, rbm);
  527. n_entries--;
  528. paddr += HAL_LINK_DESC_SIZE;
  529. if (rem_entries) {
  530. rem_entries--;
  531. scatter_buf++;
  532. continue;
  533. }
  534. rem_entries = n_entries_per_buf;
  535. scatter_idx++;
  536. scatter_buf = slist[scatter_idx].vaddr;
  537. }
  538. }
  539. end_offset = (scatter_buf - slist[scatter_idx].vaddr) *
  540. sizeof(struct hal_wbm_link_desc);
  541. ath12k_hal_setup_link_idle_list(ab, slist, num_scatter_buf,
  542. n_link_desc, end_offset);
  543. return 0;
  544. err:
  545. ath12k_dp_scatter_idle_link_desc_cleanup(ab);
  546. return ret;
  547. }
  548. static void
  549. ath12k_dp_link_desc_bank_free(struct ath12k_base *ab,
  550. struct dp_link_desc_bank *link_desc_banks)
  551. {
  552. int i;
  553. for (i = 0; i < DP_LINK_DESC_BANKS_MAX; i++) {
  554. if (link_desc_banks[i].vaddr_unaligned) {
  555. dma_free_coherent(ab->dev,
  556. link_desc_banks[i].size,
  557. link_desc_banks[i].vaddr_unaligned,
  558. link_desc_banks[i].paddr_unaligned);
  559. link_desc_banks[i].vaddr_unaligned = NULL;
  560. }
  561. }
  562. }
  563. static int ath12k_dp_link_desc_bank_alloc(struct ath12k_base *ab,
  564. struct dp_link_desc_bank *desc_bank,
  565. int n_link_desc_bank,
  566. int last_bank_sz)
  567. {
  568. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  569. int i;
  570. int ret = 0;
  571. int desc_sz = DP_LINK_DESC_ALLOC_SIZE_THRESH;
  572. for (i = 0; i < n_link_desc_bank; i++) {
  573. if (i == (n_link_desc_bank - 1) && last_bank_sz)
  574. desc_sz = last_bank_sz;
  575. desc_bank[i].vaddr_unaligned =
  576. dma_alloc_coherent(ab->dev, desc_sz,
  577. &desc_bank[i].paddr_unaligned,
  578. GFP_KERNEL);
  579. if (!desc_bank[i].vaddr_unaligned) {
  580. ret = -ENOMEM;
  581. goto err;
  582. }
  583. desc_bank[i].vaddr = PTR_ALIGN(desc_bank[i].vaddr_unaligned,
  584. HAL_LINK_DESC_ALIGN);
  585. desc_bank[i].paddr = desc_bank[i].paddr_unaligned +
  586. ((unsigned long)desc_bank[i].vaddr -
  587. (unsigned long)desc_bank[i].vaddr_unaligned);
  588. desc_bank[i].size = desc_sz;
  589. }
  590. return 0;
  591. err:
  592. ath12k_dp_link_desc_bank_free(ab, dp->link_desc_banks);
  593. return ret;
  594. }
  595. void ath12k_dp_link_desc_cleanup(struct ath12k_base *ab,
  596. struct dp_link_desc_bank *desc_bank,
  597. u32 ring_type, struct dp_srng *ring)
  598. {
  599. ath12k_dp_link_desc_bank_free(ab, desc_bank);
  600. if (ring_type != HAL_RXDMA_MONITOR_DESC) {
  601. ath12k_dp_srng_cleanup(ab, ring);
  602. ath12k_dp_scatter_idle_link_desc_cleanup(ab);
  603. }
  604. }
  605. static int ath12k_wbm_idle_ring_setup(struct ath12k_base *ab, u32 *n_link_desc)
  606. {
  607. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  608. u32 n_mpdu_link_desc, n_mpdu_queue_desc;
  609. u32 n_tx_msdu_link_desc, n_rx_msdu_link_desc;
  610. int ret = 0;
  611. n_mpdu_link_desc = (DP_NUM_TIDS_MAX * DP_AVG_MPDUS_PER_TID_MAX) /
  612. HAL_NUM_MPDUS_PER_LINK_DESC;
  613. n_mpdu_queue_desc = n_mpdu_link_desc /
  614. HAL_NUM_MPDU_LINKS_PER_QUEUE_DESC;
  615. n_tx_msdu_link_desc = (DP_NUM_TIDS_MAX * DP_AVG_FLOWS_PER_TID *
  616. DP_AVG_MSDUS_PER_FLOW) /
  617. HAL_NUM_TX_MSDUS_PER_LINK_DESC;
  618. n_rx_msdu_link_desc = (DP_NUM_TIDS_MAX * DP_AVG_MPDUS_PER_TID_MAX *
  619. DP_AVG_MSDUS_PER_MPDU) /
  620. HAL_NUM_RX_MSDUS_PER_LINK_DESC;
  621. *n_link_desc = n_mpdu_link_desc + n_mpdu_queue_desc +
  622. n_tx_msdu_link_desc + n_rx_msdu_link_desc;
  623. if (*n_link_desc & (*n_link_desc - 1))
  624. *n_link_desc = 1 << fls(*n_link_desc);
  625. ret = ath12k_dp_srng_setup(ab, &dp->wbm_idle_ring,
  626. HAL_WBM_IDLE_LINK, 0, 0, *n_link_desc);
  627. if (ret) {
  628. ath12k_warn(ab, "failed to setup wbm_idle_ring: %d\n", ret);
  629. return ret;
  630. }
  631. return ret;
  632. }
  633. int ath12k_dp_link_desc_setup(struct ath12k_base *ab,
  634. struct dp_link_desc_bank *link_desc_banks,
  635. u32 ring_type, struct hal_srng *srng,
  636. u32 n_link_desc)
  637. {
  638. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  639. u32 tot_mem_sz;
  640. u32 n_link_desc_bank, last_bank_sz;
  641. u32 entry_sz, align_bytes, n_entries;
  642. struct hal_wbm_link_desc *desc;
  643. u32 paddr;
  644. int i, ret;
  645. u32 cookie;
  646. enum hal_rx_buf_return_buf_manager rbm = dp->idle_link_rbm;
  647. tot_mem_sz = n_link_desc * HAL_LINK_DESC_SIZE;
  648. tot_mem_sz += HAL_LINK_DESC_ALIGN;
  649. if (tot_mem_sz <= DP_LINK_DESC_ALLOC_SIZE_THRESH) {
  650. n_link_desc_bank = 1;
  651. last_bank_sz = tot_mem_sz;
  652. } else {
  653. n_link_desc_bank = tot_mem_sz /
  654. (DP_LINK_DESC_ALLOC_SIZE_THRESH -
  655. HAL_LINK_DESC_ALIGN);
  656. last_bank_sz = tot_mem_sz %
  657. (DP_LINK_DESC_ALLOC_SIZE_THRESH -
  658. HAL_LINK_DESC_ALIGN);
  659. if (last_bank_sz)
  660. n_link_desc_bank += 1;
  661. }
  662. if (n_link_desc_bank > DP_LINK_DESC_BANKS_MAX)
  663. return -EINVAL;
  664. ret = ath12k_dp_link_desc_bank_alloc(ab, link_desc_banks,
  665. n_link_desc_bank, last_bank_sz);
  666. if (ret)
  667. return ret;
  668. /* Setup link desc idle list for HW internal usage */
  669. entry_sz = ath12k_hal_srng_get_entrysize(ab, ring_type);
  670. tot_mem_sz = entry_sz * n_link_desc;
  671. /* Setup scatter desc list when the total memory requirement is more */
  672. if (tot_mem_sz > DP_LINK_DESC_ALLOC_SIZE_THRESH &&
  673. ring_type != HAL_RXDMA_MONITOR_DESC) {
  674. ret = ath12k_dp_scatter_idle_link_desc_setup(ab, tot_mem_sz,
  675. n_link_desc_bank,
  676. n_link_desc,
  677. last_bank_sz);
  678. if (ret) {
  679. ath12k_warn(ab, "failed to setup scatting idle list descriptor :%d\n",
  680. ret);
  681. goto fail_desc_bank_free;
  682. }
  683. return 0;
  684. }
  685. spin_lock_bh(&srng->lock);
  686. ath12k_hal_srng_access_begin(ab, srng);
  687. for (i = 0; i < n_link_desc_bank; i++) {
  688. align_bytes = link_desc_banks[i].vaddr -
  689. link_desc_banks[i].vaddr_unaligned;
  690. n_entries = (link_desc_banks[i].size - align_bytes) /
  691. HAL_LINK_DESC_SIZE;
  692. paddr = link_desc_banks[i].paddr;
  693. while (n_entries &&
  694. (desc = ath12k_hal_srng_src_get_next_entry(ab, srng))) {
  695. cookie = DP_LINK_DESC_COOKIE_SET(n_entries, i);
  696. ath12k_hal_set_link_desc_addr(dp->hal, desc, cookie, paddr,
  697. rbm);
  698. n_entries--;
  699. paddr += HAL_LINK_DESC_SIZE;
  700. }
  701. }
  702. ath12k_hal_srng_access_end(ab, srng);
  703. spin_unlock_bh(&srng->lock);
  704. return 0;
  705. fail_desc_bank_free:
  706. ath12k_dp_link_desc_bank_free(ab, link_desc_banks);
  707. return ret;
  708. }
  709. void ath12k_dp_pdev_free(struct ath12k_base *ab)
  710. {
  711. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  712. struct ath12k *ar;
  713. int i;
  714. for (i = 0; i < ab->num_radios; i++) {
  715. ar = ab->pdevs[i].ar;
  716. rcu_assign_pointer(dp->dp_pdevs[ar->pdev_idx], NULL);
  717. }
  718. synchronize_rcu();
  719. for (i = 0; i < ab->num_radios; i++)
  720. ath12k_dp_rx_pdev_free(ab, i);
  721. }
  722. void ath12k_dp_pdev_pre_alloc(struct ath12k *ar)
  723. {
  724. struct ath12k_pdev_dp *dp = &ar->dp;
  725. dp->mac_id = ar->pdev_idx;
  726. atomic_set(&dp->num_tx_pending, 0);
  727. init_waitqueue_head(&dp->tx_empty_waitq);
  728. /* TODO: Add any RXDMA setup required per pdev */
  729. }
  730. int ath12k_dp_pdev_alloc(struct ath12k_base *ab)
  731. {
  732. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  733. struct ath12k_pdev_dp *dp_pdev;
  734. struct ath12k *ar;
  735. int ret;
  736. int i;
  737. ret = ath12k_dp_rx_htt_setup(ab);
  738. if (ret)
  739. goto out;
  740. /* TODO: Per-pdev rx ring unlike tx ring which is mapped to different AC's */
  741. for (i = 0; i < ab->num_radios; i++) {
  742. ar = ab->pdevs[i].ar;
  743. dp_pdev = &ar->dp;
  744. dp_pdev->hw = ar->ah->hw;
  745. dp_pdev->dp = dp;
  746. dp_pdev->hw_link_id = ar->hw_link_id;
  747. dp_pdev->dp_hw = &ar->ah->dp_hw;
  748. ret = ath12k_dp_rx_pdev_alloc(ab, i);
  749. if (ret) {
  750. ath12k_warn(ab, "failed to allocate pdev rx for pdev_id :%d\n",
  751. i);
  752. goto err;
  753. }
  754. ret = ath12k_dp_rx_pdev_mon_attach(ar);
  755. if (ret) {
  756. ath12k_warn(ab, "failed to initialize mon pdev %d\n", i);
  757. goto err;
  758. }
  759. }
  760. for (i = 0; i < ab->num_radios; i++) {
  761. ar = ab->pdevs[i].ar;
  762. rcu_assign_pointer(dp->dp_pdevs[ar->pdev_idx], &ar->dp);
  763. }
  764. return 0;
  765. err:
  766. ath12k_dp_pdev_free(ab);
  767. out:
  768. return ret;
  769. }
  770. static void ath12k_dp_update_vdev_search(struct ath12k_link_vif *arvif)
  771. {
  772. u8 link_id = arvif->link_id;
  773. struct ath12k_vif *ahvif = arvif->ahvif;
  774. struct ath12k_dp_link_vif *dp_link_vif;
  775. dp_link_vif = ath12k_dp_vif_to_dp_link_vif(&ahvif->dp_vif, link_id);
  776. switch (arvif->ahvif->vdev_type) {
  777. case WMI_VDEV_TYPE_STA:
  778. dp_link_vif->hal_addr_search_flags = HAL_TX_ADDRY_EN;
  779. dp_link_vif->search_type = HAL_TX_ADDR_SEARCH_DEFAULT;
  780. break;
  781. case WMI_VDEV_TYPE_AP:
  782. case WMI_VDEV_TYPE_IBSS:
  783. dp_link_vif->hal_addr_search_flags = HAL_TX_ADDRX_EN;
  784. dp_link_vif->search_type = HAL_TX_ADDR_SEARCH_DEFAULT;
  785. break;
  786. case WMI_VDEV_TYPE_MONITOR:
  787. default:
  788. return;
  789. }
  790. }
  791. void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif)
  792. {
  793. struct ath12k_base *ab = ar->ab;
  794. struct ath12k_vif *ahvif = arvif->ahvif;
  795. u8 link_id = arvif->link_id;
  796. int bank_id;
  797. struct ath12k_dp_link_vif *dp_link_vif;
  798. dp_link_vif = ath12k_dp_vif_to_dp_link_vif(&ahvif->dp_vif, link_id);
  799. dp_link_vif->tcl_metadata |= u32_encode_bits(1, HTT_TCL_META_DATA_TYPE) |
  800. u32_encode_bits(arvif->vdev_id,
  801. HTT_TCL_META_DATA_VDEV_ID) |
  802. u32_encode_bits(ar->pdev->pdev_id,
  803. HTT_TCL_META_DATA_PDEV_ID);
  804. /* set HTT extension valid bit to 0 by default */
  805. dp_link_vif->tcl_metadata &= ~HTT_TCL_META_DATA_VALID_HTT;
  806. ath12k_dp_update_vdev_search(arvif);
  807. dp_link_vif->vdev_id_check_en = true;
  808. bank_id = ath12k_dp_tx_get_bank_profile(ab, arvif, ath12k_ab_to_dp(ab));
  809. dp_link_vif->bank_id = bank_id;
  810. /* TODO: error path for bank id failure */
  811. if (bank_id == DP_INVALID_BANK_ID) {
  812. ath12k_err(ar->ab, "Failed to initialize DP TX Banks");
  813. return;
  814. }
  815. }
  816. static void ath12k_dp_cc_cleanup(struct ath12k_base *ab)
  817. {
  818. struct ath12k_rx_desc_info *desc_info;
  819. struct ath12k_tx_desc_info *tx_desc_info, *tmp1;
  820. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  821. struct ath12k_skb_cb *skb_cb;
  822. struct sk_buff *skb;
  823. struct ath12k *ar;
  824. int i, j;
  825. u32 pool_id, tx_spt_page;
  826. if (!dp->spt_info)
  827. return;
  828. /* RX Descriptor cleanup */
  829. spin_lock_bh(&dp->rx_desc_lock);
  830. if (dp->rxbaddr) {
  831. for (i = 0; i < ATH12K_NUM_RX_SPT_PAGES(ab); i++) {
  832. if (!dp->rxbaddr[i])
  833. continue;
  834. desc_info = dp->rxbaddr[i];
  835. for (j = 0; j < ATH12K_MAX_SPT_ENTRIES; j++) {
  836. if (!desc_info[j].in_use) {
  837. list_del(&desc_info[j].list);
  838. continue;
  839. }
  840. skb = desc_info[j].skb;
  841. if (!skb)
  842. continue;
  843. dma_unmap_single(ab->dev,
  844. ATH12K_SKB_RXCB(skb)->paddr,
  845. skb->len + skb_tailroom(skb),
  846. DMA_FROM_DEVICE);
  847. dev_kfree_skb_any(skb);
  848. }
  849. kfree(dp->rxbaddr[i]);
  850. dp->rxbaddr[i] = NULL;
  851. }
  852. kfree(dp->rxbaddr);
  853. dp->rxbaddr = NULL;
  854. }
  855. spin_unlock_bh(&dp->rx_desc_lock);
  856. /* TX Descriptor cleanup */
  857. for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) {
  858. spin_lock_bh(&dp->tx_desc_lock[i]);
  859. list_for_each_entry_safe(tx_desc_info, tmp1,
  860. &dp->tx_desc_used_list[i], list) {
  861. list_del(&tx_desc_info->list);
  862. skb = tx_desc_info->skb;
  863. if (!skb)
  864. continue;
  865. skb_cb = ATH12K_SKB_CB(skb);
  866. if (skb_cb->paddr_ext_desc) {
  867. dma_unmap_single(ab->dev,
  868. skb_cb->paddr_ext_desc,
  869. tx_desc_info->skb_ext_desc->len,
  870. DMA_TO_DEVICE);
  871. dev_kfree_skb_any(tx_desc_info->skb_ext_desc);
  872. }
  873. /* if we are unregistering, hw would've been destroyed and
  874. * ar is no longer valid.
  875. */
  876. if (!(test_bit(ATH12K_FLAG_UNREGISTERING, &ab->dev_flags))) {
  877. ar = skb_cb->ar;
  878. if (atomic_dec_and_test(&ar->dp.num_tx_pending))
  879. wake_up(&ar->dp.tx_empty_waitq);
  880. }
  881. dma_unmap_single(ab->dev, ATH12K_SKB_CB(skb)->paddr,
  882. skb->len, DMA_TO_DEVICE);
  883. dev_kfree_skb_any(skb);
  884. }
  885. spin_unlock_bh(&dp->tx_desc_lock[i]);
  886. }
  887. if (dp->txbaddr) {
  888. for (pool_id = 0; pool_id < ATH12K_HW_MAX_QUEUES; pool_id++) {
  889. spin_lock_bh(&dp->tx_desc_lock[pool_id]);
  890. for (i = 0; i < ATH12K_TX_SPT_PAGES_PER_POOL(ab); i++) {
  891. tx_spt_page = i + pool_id *
  892. ATH12K_TX_SPT_PAGES_PER_POOL(ab);
  893. if (!dp->txbaddr[tx_spt_page])
  894. continue;
  895. kfree(dp->txbaddr[tx_spt_page]);
  896. dp->txbaddr[tx_spt_page] = NULL;
  897. }
  898. spin_unlock_bh(&dp->tx_desc_lock[pool_id]);
  899. }
  900. kfree(dp->txbaddr);
  901. dp->txbaddr = NULL;
  902. }
  903. /* unmap SPT pages */
  904. for (i = 0; i < dp->num_spt_pages; i++) {
  905. if (!dp->spt_info[i].vaddr)
  906. continue;
  907. dma_free_coherent(ab->dev, ATH12K_PAGE_SIZE,
  908. dp->spt_info[i].vaddr, dp->spt_info[i].paddr);
  909. dp->spt_info[i].vaddr = NULL;
  910. }
  911. kfree(dp->spt_info);
  912. dp->spt_info = NULL;
  913. }
  914. static void ath12k_dp_reoq_lut_cleanup(struct ath12k_base *ab)
  915. {
  916. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  917. if (!ab->hw_params->reoq_lut_support)
  918. return;
  919. if (dp->reoq_lut.vaddr_unaligned) {
  920. ath12k_hal_write_reoq_lut_addr(ab, 0);
  921. dma_free_coherent(ab->dev, dp->reoq_lut.size,
  922. dp->reoq_lut.vaddr_unaligned,
  923. dp->reoq_lut.paddr_unaligned);
  924. dp->reoq_lut.vaddr_unaligned = NULL;
  925. }
  926. if (dp->ml_reoq_lut.vaddr_unaligned) {
  927. ath12k_hal_write_ml_reoq_lut_addr(ab, 0);
  928. dma_free_coherent(ab->dev, dp->ml_reoq_lut.size,
  929. dp->ml_reoq_lut.vaddr_unaligned,
  930. dp->ml_reoq_lut.paddr_unaligned);
  931. dp->ml_reoq_lut.vaddr_unaligned = NULL;
  932. }
  933. }
  934. static void ath12k_dp_cleanup(struct ath12k_base *ab)
  935. {
  936. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  937. int i;
  938. ath12k_dp_link_peer_rhash_tbl_destroy(dp);
  939. if (!dp->ab)
  940. return;
  941. ath12k_dp_link_desc_cleanup(ab, dp->link_desc_banks,
  942. HAL_WBM_IDLE_LINK, &dp->wbm_idle_ring);
  943. ath12k_dp_cc_cleanup(ab);
  944. ath12k_dp_reoq_lut_cleanup(ab);
  945. ath12k_dp_deinit_bank_profiles(ab);
  946. ath12k_dp_srng_common_cleanup(ab);
  947. ath12k_dp_rx_reo_cmd_list_cleanup(ab);
  948. for (i = 0; i < ab->hw_params->max_tx_ring; i++) {
  949. kfree(dp->tx_ring[i].tx_status);
  950. dp->tx_ring[i].tx_status = NULL;
  951. }
  952. ath12k_dp_rx_free(ab);
  953. /* Deinit any SOC level resource */
  954. }
  955. static u32 ath12k_dp_cc_cookie_gen(u16 ppt_idx, u16 spt_idx)
  956. {
  957. return (u32)ppt_idx << ATH12K_CC_PPT_SHIFT | spt_idx;
  958. }
  959. static void *ath12k_dp_cc_get_desc_addr_ptr(struct ath12k_dp *dp,
  960. u16 ppt_idx, u16 spt_idx)
  961. {
  962. return dp->spt_info[ppt_idx].vaddr + spt_idx;
  963. }
  964. struct ath12k_rx_desc_info *ath12k_dp_get_rx_desc(struct ath12k_dp *dp,
  965. u32 cookie)
  966. {
  967. struct ath12k_rx_desc_info **desc_addr_ptr;
  968. u16 start_ppt_idx, end_ppt_idx, ppt_idx, spt_idx;
  969. ppt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_PPT);
  970. spt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_SPT);
  971. start_ppt_idx = dp->rx_ppt_base + ATH12K_RX_SPT_PAGE_OFFSET(dp->ab);
  972. end_ppt_idx = start_ppt_idx + ATH12K_NUM_RX_SPT_PAGES(dp->ab);
  973. if (ppt_idx < start_ppt_idx ||
  974. ppt_idx >= end_ppt_idx ||
  975. spt_idx > ATH12K_MAX_SPT_ENTRIES)
  976. return NULL;
  977. ppt_idx = ppt_idx - dp->rx_ppt_base;
  978. desc_addr_ptr = ath12k_dp_cc_get_desc_addr_ptr(dp, ppt_idx, spt_idx);
  979. return *desc_addr_ptr;
  980. }
  981. EXPORT_SYMBOL(ath12k_dp_get_rx_desc);
  982. struct ath12k_tx_desc_info *ath12k_dp_get_tx_desc(struct ath12k_dp *dp,
  983. u32 cookie)
  984. {
  985. struct ath12k_tx_desc_info **desc_addr_ptr;
  986. u16 start_ppt_idx, end_ppt_idx, ppt_idx, spt_idx;
  987. ppt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_PPT);
  988. spt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_SPT);
  989. start_ppt_idx = ATH12K_TX_SPT_PAGE_OFFSET;
  990. end_ppt_idx = start_ppt_idx +
  991. (ATH12K_TX_SPT_PAGES_PER_POOL(dp->ab) * ATH12K_HW_MAX_QUEUES);
  992. if (ppt_idx < start_ppt_idx ||
  993. ppt_idx >= end_ppt_idx ||
  994. spt_idx > ATH12K_MAX_SPT_ENTRIES)
  995. return NULL;
  996. desc_addr_ptr = ath12k_dp_cc_get_desc_addr_ptr(dp, ppt_idx, spt_idx);
  997. return *desc_addr_ptr;
  998. }
  999. EXPORT_SYMBOL(ath12k_dp_get_tx_desc);
  1000. static int ath12k_dp_cc_desc_init(struct ath12k_base *ab)
  1001. {
  1002. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  1003. struct ath12k_rx_desc_info *rx_descs, **rx_desc_addr;
  1004. struct ath12k_tx_desc_info *tx_descs, **tx_desc_addr;
  1005. u32 num_rx_spt_pages = ATH12K_NUM_RX_SPT_PAGES(ab);
  1006. u32 i, j, pool_id, tx_spt_page;
  1007. u32 ppt_idx, cookie_ppt_idx;
  1008. spin_lock_bh(&dp->rx_desc_lock);
  1009. dp->rxbaddr = kzalloc_objs(struct ath12k_rx_desc_info *,
  1010. num_rx_spt_pages, GFP_ATOMIC);
  1011. if (!dp->rxbaddr) {
  1012. spin_unlock_bh(&dp->rx_desc_lock);
  1013. return -ENOMEM;
  1014. }
  1015. /* First ATH12K_NUM_RX_SPT_PAGES(ab) of allocated SPT pages are used for
  1016. * RX
  1017. */
  1018. for (i = 0; i < num_rx_spt_pages; i++) {
  1019. rx_descs = kzalloc_objs(*rx_descs, ATH12K_MAX_SPT_ENTRIES,
  1020. GFP_ATOMIC);
  1021. if (!rx_descs) {
  1022. spin_unlock_bh(&dp->rx_desc_lock);
  1023. return -ENOMEM;
  1024. }
  1025. ppt_idx = ATH12K_RX_SPT_PAGE_OFFSET(ab) + i;
  1026. cookie_ppt_idx = dp->rx_ppt_base + ppt_idx;
  1027. dp->rxbaddr[i] = &rx_descs[0];
  1028. for (j = 0; j < ATH12K_MAX_SPT_ENTRIES; j++) {
  1029. rx_descs[j].cookie = ath12k_dp_cc_cookie_gen(cookie_ppt_idx, j);
  1030. rx_descs[j].magic = ATH12K_DP_RX_DESC_MAGIC;
  1031. rx_descs[j].device_id = ab->device_id;
  1032. list_add_tail(&rx_descs[j].list, &dp->rx_desc_free_list);
  1033. /* Update descriptor VA in SPT */
  1034. rx_desc_addr = ath12k_dp_cc_get_desc_addr_ptr(dp, ppt_idx, j);
  1035. *rx_desc_addr = &rx_descs[j];
  1036. }
  1037. }
  1038. spin_unlock_bh(&dp->rx_desc_lock);
  1039. dp->txbaddr = kzalloc_objs(struct ath12k_tx_desc_info *,
  1040. ATH12K_NUM_TX_SPT_PAGES(ab), GFP_ATOMIC);
  1041. if (!dp->txbaddr)
  1042. return -ENOMEM;
  1043. for (pool_id = 0; pool_id < ATH12K_HW_MAX_QUEUES; pool_id++) {
  1044. spin_lock_bh(&dp->tx_desc_lock[pool_id]);
  1045. for (i = 0; i < ATH12K_TX_SPT_PAGES_PER_POOL(ab); i++) {
  1046. tx_descs = kzalloc_objs(*tx_descs,
  1047. ATH12K_MAX_SPT_ENTRIES,
  1048. GFP_ATOMIC);
  1049. if (!tx_descs) {
  1050. spin_unlock_bh(&dp->tx_desc_lock[pool_id]);
  1051. /* Caller takes care of TX pending and RX desc cleanup */
  1052. return -ENOMEM;
  1053. }
  1054. tx_spt_page = i + pool_id *
  1055. ATH12K_TX_SPT_PAGES_PER_POOL(ab);
  1056. ppt_idx = ATH12K_TX_SPT_PAGE_OFFSET + tx_spt_page;
  1057. dp->txbaddr[tx_spt_page] = &tx_descs[0];
  1058. for (j = 0; j < ATH12K_MAX_SPT_ENTRIES; j++) {
  1059. tx_descs[j].desc_id = ath12k_dp_cc_cookie_gen(ppt_idx, j);
  1060. tx_descs[j].pool_id = pool_id;
  1061. list_add_tail(&tx_descs[j].list,
  1062. &dp->tx_desc_free_list[pool_id]);
  1063. /* Update descriptor VA in SPT */
  1064. tx_desc_addr =
  1065. ath12k_dp_cc_get_desc_addr_ptr(dp, ppt_idx, j);
  1066. *tx_desc_addr = &tx_descs[j];
  1067. }
  1068. }
  1069. spin_unlock_bh(&dp->tx_desc_lock[pool_id]);
  1070. }
  1071. return 0;
  1072. }
  1073. static int ath12k_dp_cmem_init(struct ath12k_base *ab,
  1074. struct ath12k_dp *dp,
  1075. enum ath12k_dp_desc_type type)
  1076. {
  1077. u32 cmem_base;
  1078. int i, start, end;
  1079. cmem_base = ab->qmi.dev_mem[ATH12K_QMI_DEVMEM_CMEM_INDEX].start;
  1080. switch (type) {
  1081. case ATH12K_DP_TX_DESC:
  1082. start = ATH12K_TX_SPT_PAGE_OFFSET;
  1083. end = start + ATH12K_NUM_TX_SPT_PAGES(ab);
  1084. break;
  1085. case ATH12K_DP_RX_DESC:
  1086. cmem_base += ATH12K_PPT_ADDR_OFFSET(dp->rx_ppt_base);
  1087. start = ATH12K_RX_SPT_PAGE_OFFSET(ab);
  1088. end = start + ATH12K_NUM_RX_SPT_PAGES(ab);
  1089. break;
  1090. default:
  1091. ath12k_err(ab, "invalid descriptor type %d in cmem init\n", type);
  1092. return -EINVAL;
  1093. }
  1094. /* Write to PPT in CMEM */
  1095. for (i = start; i < end; i++)
  1096. ath12k_hif_write32(ab, cmem_base + ATH12K_PPT_ADDR_OFFSET(i),
  1097. dp->spt_info[i].paddr >> ATH12K_SPT_4K_ALIGN_OFFSET);
  1098. return 0;
  1099. }
  1100. void ath12k_dp_partner_cc_init(struct ath12k_base *ab)
  1101. {
  1102. struct ath12k_hw_group *ag = ab->ag;
  1103. int i;
  1104. for (i = 0; i < ag->num_devices; i++) {
  1105. if (ag->ab[i] == ab)
  1106. continue;
  1107. ath12k_dp_cmem_init(ab, ath12k_ab_to_dp(ag->ab[i]), ATH12K_DP_RX_DESC);
  1108. }
  1109. }
  1110. static u32 ath12k_dp_get_num_spt_pages(struct ath12k_base *ab)
  1111. {
  1112. return ATH12K_NUM_RX_SPT_PAGES(ab) + ATH12K_NUM_TX_SPT_PAGES(ab);
  1113. }
  1114. static int ath12k_dp_cc_init(struct ath12k_base *ab)
  1115. {
  1116. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  1117. int i, ret = 0;
  1118. INIT_LIST_HEAD(&dp->rx_desc_free_list);
  1119. spin_lock_init(&dp->rx_desc_lock);
  1120. for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) {
  1121. INIT_LIST_HEAD(&dp->tx_desc_free_list[i]);
  1122. INIT_LIST_HEAD(&dp->tx_desc_used_list[i]);
  1123. spin_lock_init(&dp->tx_desc_lock[i]);
  1124. }
  1125. dp->num_spt_pages = ath12k_dp_get_num_spt_pages(ab);
  1126. if (dp->num_spt_pages > ATH12K_MAX_PPT_ENTRIES)
  1127. dp->num_spt_pages = ATH12K_MAX_PPT_ENTRIES;
  1128. dp->spt_info = kzalloc_objs(struct ath12k_spt_info, dp->num_spt_pages);
  1129. if (!dp->spt_info) {
  1130. ath12k_warn(ab, "SPT page allocation failure");
  1131. return -ENOMEM;
  1132. }
  1133. dp->rx_ppt_base = ab->device_id * ATH12K_NUM_RX_SPT_PAGES(ab);
  1134. for (i = 0; i < dp->num_spt_pages; i++) {
  1135. dp->spt_info[i].vaddr = dma_alloc_coherent(ab->dev,
  1136. ATH12K_PAGE_SIZE,
  1137. &dp->spt_info[i].paddr,
  1138. GFP_KERNEL);
  1139. if (!dp->spt_info[i].vaddr) {
  1140. ret = -ENOMEM;
  1141. goto free;
  1142. }
  1143. if (dp->spt_info[i].paddr & ATH12K_SPT_4K_ALIGN_CHECK) {
  1144. ath12k_warn(ab, "SPT allocated memory is not 4K aligned");
  1145. ret = -EINVAL;
  1146. goto free;
  1147. }
  1148. }
  1149. ret = ath12k_dp_cmem_init(ab, dp, ATH12K_DP_TX_DESC);
  1150. if (ret) {
  1151. ath12k_warn(ab, "HW CC Tx cmem init failed %d", ret);
  1152. goto free;
  1153. }
  1154. ret = ath12k_dp_cmem_init(ab, dp, ATH12K_DP_RX_DESC);
  1155. if (ret) {
  1156. ath12k_warn(ab, "HW CC Rx cmem init failed %d", ret);
  1157. goto free;
  1158. }
  1159. ret = ath12k_dp_cc_desc_init(ab);
  1160. if (ret) {
  1161. ath12k_warn(ab, "HW CC desc init failed %d", ret);
  1162. goto free;
  1163. }
  1164. return 0;
  1165. free:
  1166. ath12k_dp_cc_cleanup(ab);
  1167. return ret;
  1168. }
  1169. static int ath12k_dp_alloc_reoq_lut(struct ath12k_base *ab,
  1170. struct ath12k_reo_q_addr_lut *lut)
  1171. {
  1172. lut->size = DP_REOQ_LUT_SIZE + HAL_REO_QLUT_ADDR_ALIGN - 1;
  1173. lut->vaddr_unaligned = dma_alloc_coherent(ab->dev, lut->size,
  1174. &lut->paddr_unaligned,
  1175. GFP_KERNEL | __GFP_ZERO);
  1176. if (!lut->vaddr_unaligned)
  1177. return -ENOMEM;
  1178. lut->vaddr = PTR_ALIGN(lut->vaddr_unaligned, HAL_REO_QLUT_ADDR_ALIGN);
  1179. lut->paddr = lut->paddr_unaligned +
  1180. ((unsigned long)lut->vaddr - (unsigned long)lut->vaddr_unaligned);
  1181. return 0;
  1182. }
  1183. static int ath12k_dp_reoq_lut_setup(struct ath12k_base *ab)
  1184. {
  1185. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  1186. int ret;
  1187. if (!ab->hw_params->reoq_lut_support)
  1188. return 0;
  1189. ret = ath12k_dp_alloc_reoq_lut(ab, &dp->reoq_lut);
  1190. if (ret) {
  1191. ath12k_warn(ab, "failed to allocate memory for reoq table");
  1192. return ret;
  1193. }
  1194. ret = ath12k_dp_alloc_reoq_lut(ab, &dp->ml_reoq_lut);
  1195. if (ret) {
  1196. ath12k_warn(ab, "failed to allocate memory for ML reoq table");
  1197. dma_free_coherent(ab->dev, dp->reoq_lut.size,
  1198. dp->reoq_lut.vaddr_unaligned,
  1199. dp->reoq_lut.paddr_unaligned);
  1200. dp->reoq_lut.vaddr_unaligned = NULL;
  1201. return ret;
  1202. }
  1203. /* Bits in the register have address [39:8] LUT base address to be
  1204. * allocated such that LSBs are assumed to be zero. Also, current
  1205. * design supports paddr up to 4 GB max hence it fits in 32 bit
  1206. * register only
  1207. */
  1208. ath12k_hal_write_reoq_lut_addr(ab, dp->reoq_lut.paddr >> 8);
  1209. ath12k_hal_write_ml_reoq_lut_addr(ab, dp->ml_reoq_lut.paddr >> 8);
  1210. ath12k_hal_reoq_lut_addr_read_enable(ab);
  1211. ath12k_hal_reoq_lut_set_max_peerid(ab);
  1212. return 0;
  1213. }
  1214. static int ath12k_dp_setup(struct ath12k_base *ab)
  1215. {
  1216. struct ath12k_dp *dp;
  1217. struct hal_srng *srng = NULL;
  1218. size_t size = 0;
  1219. u32 n_link_desc = 0;
  1220. int ret;
  1221. int i;
  1222. dp = ath12k_ab_to_dp(ab);
  1223. dp->ab = ab;
  1224. INIT_LIST_HEAD(&dp->reo_cmd_list);
  1225. INIT_LIST_HEAD(&dp->reo_cmd_cache_flush_list);
  1226. INIT_LIST_HEAD(&dp->reo_cmd_update_rx_queue_list);
  1227. spin_lock_init(&dp->reo_cmd_lock);
  1228. spin_lock_init(&dp->reo_rxq_flush_lock);
  1229. spin_lock_init(&dp->dp_lock);
  1230. INIT_LIST_HEAD(&dp->peers);
  1231. mutex_init(&dp->link_peer_rhash_tbl_lock);
  1232. dp->reo_cmd_cache_flush_count = 0;
  1233. dp->idle_link_rbm =
  1234. ath12k_hal_get_idle_link_rbm(&ab->hal, ab->device_id);
  1235. ret = ath12k_dp_link_peer_rhash_tbl_init(dp);
  1236. if (ret) {
  1237. ath12k_warn(ab, "failed to init link_peer rhash table: %d\n", ret);
  1238. return ret;
  1239. }
  1240. ret = ath12k_wbm_idle_ring_setup(ab, &n_link_desc);
  1241. if (ret) {
  1242. ath12k_warn(ab, "failed to setup wbm_idle_ring: %d\n", ret);
  1243. goto rhash_destroy;
  1244. }
  1245. srng = &ab->hal.srng_list[dp->wbm_idle_ring.ring_id];
  1246. ret = ath12k_dp_link_desc_setup(ab, dp->link_desc_banks,
  1247. HAL_WBM_IDLE_LINK, srng, n_link_desc);
  1248. if (ret) {
  1249. ath12k_warn(ab, "failed to setup link desc: %d\n", ret);
  1250. goto rhash_destroy;
  1251. }
  1252. ret = ath12k_dp_cc_init(ab);
  1253. if (ret) {
  1254. ath12k_warn(ab, "failed to setup cookie converter %d\n", ret);
  1255. goto fail_link_desc_cleanup;
  1256. }
  1257. ret = ath12k_dp_init_bank_profiles(ab);
  1258. if (ret) {
  1259. ath12k_warn(ab, "failed to setup bank profiles %d\n", ret);
  1260. goto fail_hw_cc_cleanup;
  1261. }
  1262. ret = ath12k_dp_srng_common_setup(ab);
  1263. if (ret)
  1264. goto fail_dp_bank_profiles_cleanup;
  1265. size = ab->hal.hal_wbm_release_ring_tx_size *
  1266. DP_TX_COMP_RING_SIZE(ab);
  1267. ret = ath12k_dp_reoq_lut_setup(ab);
  1268. if (ret) {
  1269. ath12k_warn(ab, "failed to setup reoq table %d\n", ret);
  1270. goto fail_cmn_srng_cleanup;
  1271. }
  1272. for (i = 0; i < ab->hw_params->max_tx_ring; i++) {
  1273. dp->tx_ring[i].tcl_data_ring_id = i;
  1274. dp->tx_ring[i].tx_status_head = 0;
  1275. dp->tx_ring[i].tx_status_tail = DP_TX_COMP_RING_SIZE(ab) - 1;
  1276. dp->tx_ring[i].tx_status = kmalloc(size, GFP_KERNEL);
  1277. if (!dp->tx_ring[i].tx_status) {
  1278. ret = -ENOMEM;
  1279. /* FIXME: The allocated tx status is not freed
  1280. * properly here
  1281. */
  1282. goto fail_cmn_reoq_cleanup;
  1283. }
  1284. }
  1285. for (i = 0; i < HAL_DSCP_TID_MAP_TBL_NUM_ENTRIES_MAX; i++)
  1286. ath12k_hal_tx_set_dscp_tid_map(ab, i);
  1287. ret = ath12k_dp_rx_alloc(ab);
  1288. if (ret)
  1289. goto fail_dp_rx_free;
  1290. /* Init any SOC level resource for DP */
  1291. return 0;
  1292. fail_dp_rx_free:
  1293. ath12k_dp_rx_free(ab);
  1294. fail_cmn_reoq_cleanup:
  1295. ath12k_dp_reoq_lut_cleanup(ab);
  1296. fail_cmn_srng_cleanup:
  1297. ath12k_dp_srng_common_cleanup(ab);
  1298. fail_dp_bank_profiles_cleanup:
  1299. ath12k_dp_deinit_bank_profiles(ab);
  1300. fail_hw_cc_cleanup:
  1301. ath12k_dp_cc_cleanup(ab);
  1302. fail_link_desc_cleanup:
  1303. ath12k_dp_link_desc_cleanup(ab, dp->link_desc_banks,
  1304. HAL_WBM_IDLE_LINK, &dp->wbm_idle_ring);
  1305. rhash_destroy:
  1306. ath12k_dp_link_peer_rhash_tbl_destroy(dp);
  1307. return ret;
  1308. }
  1309. void ath12k_dp_cmn_device_deinit(struct ath12k_dp *dp)
  1310. {
  1311. ath12k_dp_cleanup(dp->ab);
  1312. }
  1313. int ath12k_dp_cmn_device_init(struct ath12k_dp *dp)
  1314. {
  1315. int ret;
  1316. ret = ath12k_dp_setup(dp->ab);
  1317. if (ret)
  1318. return ret;
  1319. return 0;
  1320. }
  1321. void ath12k_dp_cmn_hw_group_unassign(struct ath12k_dp *dp,
  1322. struct ath12k_hw_group *ag)
  1323. {
  1324. struct ath12k_dp_hw_group *dp_hw_grp = &ag->dp_hw_grp;
  1325. lockdep_assert_held(&ag->mutex);
  1326. dp_hw_grp->dp[dp->device_id] = NULL;
  1327. dp->ag = NULL;
  1328. dp->device_id = ATH12K_INVALID_DEVICE_ID;
  1329. }
  1330. void ath12k_dp_cmn_hw_group_assign(struct ath12k_dp *dp,
  1331. struct ath12k_hw_group *ag)
  1332. {
  1333. struct ath12k_base *ab = dp->ab;
  1334. struct ath12k_dp_hw_group *dp_hw_grp = &ag->dp_hw_grp;
  1335. dp->ag = ag;
  1336. dp->device_id = ab->device_id;
  1337. dp_hw_grp->dp[dp->device_id] = dp;
  1338. }