1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
7 #include <crypto/hash.h>
17 static void ath12k_dp_htt_htc_tx_complete(struct ath12k_base *ab,
20 dev_kfree_skb_any(skb);
23 void ath12k_dp_peer_cleanup(struct ath12k *ar, int vdev_id, const u8 *addr)
25 struct ath12k_base *ab = ar->ab;
26 struct ath12k_peer *peer;
28 /* TODO: Any other peer specific DP cleanup */
30 spin_lock_bh(&ab->base_lock);
31 peer = ath12k_peer_find(ab, vdev_id, addr);
33 ath12k_warn(ab, "failed to lookup peer %pM on vdev %d\n",
35 spin_unlock_bh(&ab->base_lock);
39 ath12k_dp_rx_peer_tid_cleanup(ar, peer);
40 crypto_free_shash(peer->tfm_mmic);
41 spin_unlock_bh(&ab->base_lock);
44 int ath12k_dp_peer_setup(struct ath12k *ar, int vdev_id, const u8 *addr)
46 struct ath12k_base *ab = ar->ab;
47 struct ath12k_peer *peer;
51 /* NOTE: reo_dest ring id starts from 1 unlike mac_id which starts from 0 */
52 reo_dest = ar->dp.mac_id + 1;
53 ret = ath12k_wmi_set_peer_param(ar, addr, vdev_id,
54 WMI_PEER_SET_DEFAULT_ROUTING,
55 DP_RX_HASH_ENABLE | (reo_dest << 1));
58 ath12k_warn(ab, "failed to set default routing %d peer :%pM vdev_id :%d\n",
63 for (tid = 0; tid <= IEEE80211_NUM_TIDS; tid++) {
64 ret = ath12k_dp_rx_peer_tid_setup(ar, addr, vdev_id, tid, 1, 0,
67 ath12k_warn(ab, "failed to setup rxd tid queue for tid %d: %d\n",
73 ret = ath12k_dp_rx_peer_frag_setup(ar, addr, vdev_id);
75 ath12k_warn(ab, "failed to setup rx defrag context\n");
79 /* TODO: Setup other peer specific resource used in data path */
84 spin_lock_bh(&ab->base_lock);
86 peer = ath12k_peer_find(ab, vdev_id, addr);
88 ath12k_warn(ab, "failed to find the peer to del rx tid\n");
89 spin_unlock_bh(&ab->base_lock);
93 for (; tid >= 0; tid--)
94 ath12k_dp_rx_peer_tid_delete(ar, peer, tid);
96 spin_unlock_bh(&ab->base_lock);
101 void ath12k_dp_srng_cleanup(struct ath12k_base *ab, struct dp_srng *ring)
103 if (!ring->vaddr_unaligned)
106 dma_free_coherent(ab->dev, ring->size, ring->vaddr_unaligned,
107 ring->paddr_unaligned);
109 ring->vaddr_unaligned = NULL;
112 static int ath12k_dp_srng_find_ring_in_mask(int ring_num, const u8 *grp_mask)
115 u8 mask = 1 << ring_num;
117 for (ext_group_num = 0; ext_group_num < ATH12K_EXT_IRQ_GRP_NUM_MAX;
119 if (mask & grp_mask[ext_group_num])
120 return ext_group_num;
126 static int ath12k_dp_srng_calculate_msi_group(struct ath12k_base *ab,
127 enum hal_ring_type type, int ring_num)
132 case HAL_WBM2SW_RELEASE:
133 if (ring_num == HAL_WBM2SW_REL_ERR_RING_NUM) {
134 grp_mask = &ab->hw_params->ring_mask->rx_wbm_rel[0];
137 grp_mask = &ab->hw_params->ring_mask->tx[0];
140 case HAL_REO_EXCEPTION:
141 grp_mask = &ab->hw_params->ring_mask->rx_err[0];
144 grp_mask = &ab->hw_params->ring_mask->rx[0];
147 grp_mask = &ab->hw_params->ring_mask->reo_status[0];
149 case HAL_RXDMA_MONITOR_STATUS:
150 case HAL_RXDMA_MONITOR_DST:
151 grp_mask = &ab->hw_params->ring_mask->rx_mon_dest[0];
153 case HAL_TX_MONITOR_DST:
154 grp_mask = &ab->hw_params->ring_mask->tx_mon_dest[0];
157 grp_mask = &ab->hw_params->ring_mask->host2rxdma[0];
159 case HAL_RXDMA_MONITOR_BUF:
163 case HAL_SW2WBM_RELEASE:
164 case HAL_WBM_IDLE_LINK:
166 case HAL_REO_REINJECT:
169 case HAL_CE_DST_STATUS:
174 return ath12k_dp_srng_find_ring_in_mask(ring_num, grp_mask);
177 static void ath12k_dp_srng_msi_setup(struct ath12k_base *ab,
178 struct hal_srng_params *ring_params,
179 enum hal_ring_type type, int ring_num)
181 int msi_group_number, msi_data_count;
182 u32 msi_data_start, msi_irq_start, addr_lo, addr_hi;
185 ret = ath12k_hif_get_user_msi_vector(ab, "DP",
186 &msi_data_count, &msi_data_start,
191 msi_group_number = ath12k_dp_srng_calculate_msi_group(ab, type,
193 if (msi_group_number < 0) {
194 ath12k_dbg(ab, ATH12K_DBG_PCI,
195 "ring not part of an ext_group; ring_type: %d,ring_num %d",
197 ring_params->msi_addr = 0;
198 ring_params->msi_data = 0;
202 if (msi_group_number > msi_data_count) {
203 ath12k_dbg(ab, ATH12K_DBG_PCI,
204 "multiple msi_groups share one msi, msi_group_num %d",
208 ath12k_hif_get_msi_address(ab, &addr_lo, &addr_hi);
210 ring_params->msi_addr = addr_lo;
211 ring_params->msi_addr |= (dma_addr_t)(((uint64_t)addr_hi) << 32);
212 ring_params->msi_data = (msi_group_number % msi_data_count)
214 ring_params->flags |= HAL_SRNG_FLAGS_MSI_INTR;
217 int ath12k_dp_srng_setup(struct ath12k_base *ab, struct dp_srng *ring,
218 enum hal_ring_type type, int ring_num,
219 int mac_id, int num_entries)
221 struct hal_srng_params params = { 0 };
222 int entry_sz = ath12k_hal_srng_get_entrysize(ab, type);
223 int max_entries = ath12k_hal_srng_get_max_entries(ab, type);
226 if (max_entries < 0 || entry_sz < 0)
229 if (num_entries > max_entries)
230 num_entries = max_entries;
232 ring->size = (num_entries * entry_sz) + HAL_RING_BASE_ALIGN - 1;
233 ring->vaddr_unaligned = dma_alloc_coherent(ab->dev, ring->size,
234 &ring->paddr_unaligned,
236 if (!ring->vaddr_unaligned)
239 ring->vaddr = PTR_ALIGN(ring->vaddr_unaligned, HAL_RING_BASE_ALIGN);
240 ring->paddr = ring->paddr_unaligned + ((unsigned long)ring->vaddr -
241 (unsigned long)ring->vaddr_unaligned);
243 params.ring_base_vaddr = ring->vaddr;
244 params.ring_base_paddr = ring->paddr;
245 params.num_entries = num_entries;
246 ath12k_dp_srng_msi_setup(ab, ¶ms, type, ring_num + mac_id);
250 params.intr_batch_cntr_thres_entries =
251 HAL_SRNG_INT_BATCH_THRESHOLD_RX;
252 params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_RX;
255 case HAL_RXDMA_MONITOR_BUF:
256 case HAL_RXDMA_MONITOR_STATUS:
257 params.low_threshold = num_entries >> 3;
258 params.flags |= HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN;
259 params.intr_batch_cntr_thres_entries = 0;
260 params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_RX;
262 case HAL_TX_MONITOR_DST:
263 params.low_threshold = DP_TX_MONITOR_BUF_SIZE_MAX >> 3;
264 params.flags |= HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN;
265 params.intr_batch_cntr_thres_entries = 0;
266 params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_RX;
268 case HAL_WBM2SW_RELEASE:
269 if (ab->hw_params->hw_ops->dp_srng_is_tx_comp_ring(ring_num)) {
270 params.intr_batch_cntr_thres_entries =
271 HAL_SRNG_INT_BATCH_THRESHOLD_TX;
272 params.intr_timer_thres_us =
273 HAL_SRNG_INT_TIMER_THRESHOLD_TX;
276 /* follow through when ring_num != HAL_WBM2SW_REL_ERR_RING_NUM */
278 case HAL_REO_EXCEPTION:
279 case HAL_REO_REINJECT:
285 case HAL_WBM_IDLE_LINK:
286 case HAL_SW2WBM_RELEASE:
288 case HAL_RXDMA_MONITOR_DST:
289 case HAL_RXDMA_MONITOR_DESC:
290 params.intr_batch_cntr_thres_entries =
291 HAL_SRNG_INT_BATCH_THRESHOLD_OTHER;
292 params.intr_timer_thres_us = HAL_SRNG_INT_TIMER_THRESHOLD_OTHER;
294 case HAL_RXDMA_DIR_BUF:
297 ath12k_warn(ab, "Not a valid ring type in dp :%d\n", type);
301 ret = ath12k_hal_srng_setup(ab, type, ring_num, mac_id, ¶ms);
303 ath12k_warn(ab, "failed to setup srng: %d ring_id %d\n",
314 u32 ath12k_dp_tx_get_vdev_bank_config(struct ath12k_base *ab, struct ath12k_vif *arvif)
318 /* Only valid for raw frames with HW crypto enabled.
319 * With SW crypto, mac80211 sets key per packet
321 if (arvif->tx_encap_type == HAL_TCL_ENCAP_TYPE_RAW &&
322 test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags))
324 u32_encode_bits(ath12k_dp_tx_get_encrypt_type(arvif->key_cipher),
325 HAL_TX_BANK_CONFIG_ENCRYPT_TYPE);
327 bank_config |= u32_encode_bits(arvif->tx_encap_type,
328 HAL_TX_BANK_CONFIG_ENCAP_TYPE);
329 bank_config |= u32_encode_bits(0, HAL_TX_BANK_CONFIG_SRC_BUFFER_SWAP) |
330 u32_encode_bits(0, HAL_TX_BANK_CONFIG_LINK_META_SWAP) |
331 u32_encode_bits(0, HAL_TX_BANK_CONFIG_EPD);
333 /* only valid if idx_lookup_override is not set in tcl_data_cmd */
334 bank_config |= u32_encode_bits(0, HAL_TX_BANK_CONFIG_INDEX_LOOKUP_EN);
336 bank_config |= u32_encode_bits(arvif->hal_addr_search_flags & HAL_TX_ADDRX_EN,
337 HAL_TX_BANK_CONFIG_ADDRX_EN) |
338 u32_encode_bits(!!(arvif->hal_addr_search_flags &
340 HAL_TX_BANK_CONFIG_ADDRY_EN);
342 bank_config |= u32_encode_bits(ieee80211_vif_is_mesh(arvif->vif) ? 3 : 0,
343 HAL_TX_BANK_CONFIG_MESH_EN) |
344 u32_encode_bits(arvif->vdev_id_check_en,
345 HAL_TX_BANK_CONFIG_VDEV_ID_CHECK_EN);
347 bank_config |= u32_encode_bits(0, HAL_TX_BANK_CONFIG_DSCP_TIP_MAP_ID);
352 static int ath12k_dp_tx_get_bank_profile(struct ath12k_base *ab, struct ath12k_vif *arvif,
353 struct ath12k_dp *dp)
355 int bank_id = DP_INVALID_BANK_ID;
358 bool configure_register = false;
360 /* convert vdev params into hal_tx_bank_config */
361 bank_config = ath12k_dp_tx_get_vdev_bank_config(ab, arvif);
363 spin_lock_bh(&dp->tx_bank_lock);
364 /* TODO: implement using idr kernel framework*/
365 for (i = 0; i < dp->num_bank_profiles; i++) {
366 if (dp->bank_profiles[i].is_configured &&
367 (dp->bank_profiles[i].bank_config ^ bank_config) == 0) {
369 goto inc_ref_and_return;
371 if (!dp->bank_profiles[i].is_configured ||
372 !dp->bank_profiles[i].num_users) {
374 goto configure_and_return;
378 if (bank_id == DP_INVALID_BANK_ID) {
379 spin_unlock_bh(&dp->tx_bank_lock);
380 ath12k_err(ab, "unable to find TX bank!");
384 configure_and_return:
385 dp->bank_profiles[bank_id].is_configured = true;
386 dp->bank_profiles[bank_id].bank_config = bank_config;
387 configure_register = true;
389 dp->bank_profiles[bank_id].num_users++;
390 spin_unlock_bh(&dp->tx_bank_lock);
392 if (configure_register)
393 ath12k_hal_tx_configure_bank_register(ab, bank_config, bank_id);
395 ath12k_dbg(ab, ATH12K_DBG_DP_HTT, "dp_htt tcl bank_id %d input 0x%x match 0x%x num_users %u",
396 bank_id, bank_config, dp->bank_profiles[bank_id].bank_config,
397 dp->bank_profiles[bank_id].num_users);
402 void ath12k_dp_tx_put_bank_profile(struct ath12k_dp *dp, u8 bank_id)
404 spin_lock_bh(&dp->tx_bank_lock);
405 dp->bank_profiles[bank_id].num_users--;
406 spin_unlock_bh(&dp->tx_bank_lock);
409 static void ath12k_dp_deinit_bank_profiles(struct ath12k_base *ab)
411 struct ath12k_dp *dp = &ab->dp;
413 kfree(dp->bank_profiles);
414 dp->bank_profiles = NULL;
417 static int ath12k_dp_init_bank_profiles(struct ath12k_base *ab)
419 struct ath12k_dp *dp = &ab->dp;
420 u32 num_tcl_banks = ab->hw_params->num_tcl_banks;
423 dp->num_bank_profiles = num_tcl_banks;
424 dp->bank_profiles = kmalloc_array(num_tcl_banks,
425 sizeof(struct ath12k_dp_tx_bank_profile),
427 if (!dp->bank_profiles)
430 spin_lock_init(&dp->tx_bank_lock);
432 for (i = 0; i < num_tcl_banks; i++) {
433 dp->bank_profiles[i].is_configured = false;
434 dp->bank_profiles[i].num_users = 0;
440 static void ath12k_dp_srng_common_cleanup(struct ath12k_base *ab)
442 struct ath12k_dp *dp = &ab->dp;
445 ath12k_dp_srng_cleanup(ab, &dp->reo_status_ring);
446 ath12k_dp_srng_cleanup(ab, &dp->reo_cmd_ring);
447 ath12k_dp_srng_cleanup(ab, &dp->reo_except_ring);
448 ath12k_dp_srng_cleanup(ab, &dp->rx_rel_ring);
449 ath12k_dp_srng_cleanup(ab, &dp->reo_reinject_ring);
450 for (i = 0; i < ab->hw_params->max_tx_ring; i++) {
451 ath12k_dp_srng_cleanup(ab, &dp->tx_ring[i].tcl_comp_ring);
452 ath12k_dp_srng_cleanup(ab, &dp->tx_ring[i].tcl_data_ring);
454 ath12k_dp_srng_cleanup(ab, &dp->tcl_status_ring);
455 ath12k_dp_srng_cleanup(ab, &dp->tcl_cmd_ring);
456 ath12k_dp_srng_cleanup(ab, &dp->wbm_desc_rel_ring);
459 static int ath12k_dp_srng_common_setup(struct ath12k_base *ab)
461 struct ath12k_dp *dp = &ab->dp;
462 const struct ath12k_hal_tcl_to_wbm_rbm_map *map;
463 struct hal_srng *srng;
464 int i, ret, tx_comp_ring_num;
467 ret = ath12k_dp_srng_setup(ab, &dp->wbm_desc_rel_ring,
468 HAL_SW2WBM_RELEASE, 0, 0,
469 DP_WBM_RELEASE_RING_SIZE);
471 ath12k_warn(ab, "failed to set up wbm2sw_release ring :%d\n",
476 ret = ath12k_dp_srng_setup(ab, &dp->tcl_cmd_ring, HAL_TCL_CMD, 0, 0,
477 DP_TCL_CMD_RING_SIZE);
479 ath12k_warn(ab, "failed to set up tcl_cmd ring :%d\n", ret);
483 ret = ath12k_dp_srng_setup(ab, &dp->tcl_status_ring, HAL_TCL_STATUS,
484 0, 0, DP_TCL_STATUS_RING_SIZE);
486 ath12k_warn(ab, "failed to set up tcl_status ring :%d\n", ret);
490 for (i = 0; i < ab->hw_params->max_tx_ring; i++) {
491 map = ab->hw_params->hal_ops->tcl_to_wbm_rbm_map;
492 tx_comp_ring_num = map[i].wbm_ring_num;
494 ret = ath12k_dp_srng_setup(ab, &dp->tx_ring[i].tcl_data_ring,
496 DP_TCL_DATA_RING_SIZE);
498 ath12k_warn(ab, "failed to set up tcl_data ring (%d) :%d\n",
503 ret = ath12k_dp_srng_setup(ab, &dp->tx_ring[i].tcl_comp_ring,
504 HAL_WBM2SW_RELEASE, tx_comp_ring_num, 0,
505 DP_TX_COMP_RING_SIZE);
507 ath12k_warn(ab, "failed to set up tcl_comp ring (%d) :%d\n",
508 tx_comp_ring_num, ret);
513 ret = ath12k_dp_srng_setup(ab, &dp->reo_reinject_ring, HAL_REO_REINJECT,
514 0, 0, DP_REO_REINJECT_RING_SIZE);
516 ath12k_warn(ab, "failed to set up reo_reinject ring :%d\n",
521 ret = ath12k_dp_srng_setup(ab, &dp->rx_rel_ring, HAL_WBM2SW_RELEASE,
522 HAL_WBM2SW_REL_ERR_RING_NUM, 0,
523 DP_RX_RELEASE_RING_SIZE);
525 ath12k_warn(ab, "failed to set up rx_rel ring :%d\n", ret);
529 ret = ath12k_dp_srng_setup(ab, &dp->reo_except_ring, HAL_REO_EXCEPTION,
530 0, 0, DP_REO_EXCEPTION_RING_SIZE);
532 ath12k_warn(ab, "failed to set up reo_exception ring :%d\n",
537 ret = ath12k_dp_srng_setup(ab, &dp->reo_cmd_ring, HAL_REO_CMD,
538 0, 0, DP_REO_CMD_RING_SIZE);
540 ath12k_warn(ab, "failed to set up reo_cmd ring :%d\n", ret);
544 srng = &ab->hal.srng_list[dp->reo_cmd_ring.ring_id];
545 ath12k_hal_reo_init_cmd_ring(ab, srng);
547 ret = ath12k_dp_srng_setup(ab, &dp->reo_status_ring, HAL_REO_STATUS,
548 0, 0, DP_REO_STATUS_RING_SIZE);
550 ath12k_warn(ab, "failed to set up reo_status ring :%d\n", ret);
554 /* When hash based routing of rx packet is enabled, 32 entries to map
555 * the hash values to the ring will be configured. Each hash entry uses
556 * four bits to map to a particular ring. The ring mapping will be
557 * 0:TCL, 1:SW1, 2:SW2, 3:SW3, 4:SW4, 5:Release, 6:FW and 7:SW5
558 * 8:SW6, 9:SW7, 10:SW8, 11:Not used.
560 ring_hash_map = HAL_HASH_ROUTING_RING_SW1 |
561 HAL_HASH_ROUTING_RING_SW2 << 4 |
562 HAL_HASH_ROUTING_RING_SW3 << 8 |
563 HAL_HASH_ROUTING_RING_SW4 << 12 |
564 HAL_HASH_ROUTING_RING_SW1 << 16 |
565 HAL_HASH_ROUTING_RING_SW2 << 20 |
566 HAL_HASH_ROUTING_RING_SW3 << 24 |
567 HAL_HASH_ROUTING_RING_SW4 << 28;
569 ath12k_hal_reo_hw_setup(ab, ring_hash_map);
574 ath12k_dp_srng_common_cleanup(ab);
579 static void ath12k_dp_scatter_idle_link_desc_cleanup(struct ath12k_base *ab)
581 struct ath12k_dp *dp = &ab->dp;
582 struct hal_wbm_idle_scatter_list *slist = dp->scatter_list;
585 for (i = 0; i < DP_IDLE_SCATTER_BUFS_MAX; i++) {
589 dma_free_coherent(ab->dev, HAL_WBM_IDLE_SCATTER_BUF_SIZE_MAX,
590 slist[i].vaddr, slist[i].paddr);
591 slist[i].vaddr = NULL;
595 static int ath12k_dp_scatter_idle_link_desc_setup(struct ath12k_base *ab,
597 u32 n_link_desc_bank,
601 struct ath12k_dp *dp = &ab->dp;
602 struct dp_link_desc_bank *link_desc_banks = dp->link_desc_banks;
603 struct hal_wbm_idle_scatter_list *slist = dp->scatter_list;
604 u32 n_entries_per_buf;
605 int num_scatter_buf, scatter_idx;
606 struct hal_wbm_link_desc *scatter_buf;
607 int align_bytes, n_entries;
612 u32 end_offset, cookie;
614 n_entries_per_buf = HAL_WBM_IDLE_SCATTER_BUF_SIZE /
615 ath12k_hal_srng_get_entrysize(ab, HAL_WBM_IDLE_LINK);
616 num_scatter_buf = DIV_ROUND_UP(size, HAL_WBM_IDLE_SCATTER_BUF_SIZE);
618 if (num_scatter_buf > DP_IDLE_SCATTER_BUFS_MAX)
621 for (i = 0; i < num_scatter_buf; i++) {
622 slist[i].vaddr = dma_alloc_coherent(ab->dev,
623 HAL_WBM_IDLE_SCATTER_BUF_SIZE_MAX,
624 &slist[i].paddr, GFP_KERNEL);
625 if (!slist[i].vaddr) {
632 scatter_buf = slist[scatter_idx].vaddr;
633 rem_entries = n_entries_per_buf;
635 for (i = 0; i < n_link_desc_bank; i++) {
636 align_bytes = link_desc_banks[i].vaddr -
637 link_desc_banks[i].vaddr_unaligned;
638 n_entries = (DP_LINK_DESC_ALLOC_SIZE_THRESH - align_bytes) /
640 paddr = link_desc_banks[i].paddr;
642 cookie = DP_LINK_DESC_COOKIE_SET(n_entries, i);
643 ath12k_hal_set_link_desc_addr(scatter_buf, cookie, paddr);
645 paddr += HAL_LINK_DESC_SIZE;
652 rem_entries = n_entries_per_buf;
654 scatter_buf = slist[scatter_idx].vaddr;
658 end_offset = (scatter_buf - slist[scatter_idx].vaddr) *
659 sizeof(struct hal_wbm_link_desc);
660 ath12k_hal_setup_link_idle_list(ab, slist, num_scatter_buf,
661 n_link_desc, end_offset);
666 ath12k_dp_scatter_idle_link_desc_cleanup(ab);
672 ath12k_dp_link_desc_bank_free(struct ath12k_base *ab,
673 struct dp_link_desc_bank *link_desc_banks)
677 for (i = 0; i < DP_LINK_DESC_BANKS_MAX; i++) {
678 if (link_desc_banks[i].vaddr_unaligned) {
679 dma_free_coherent(ab->dev,
680 link_desc_banks[i].size,
681 link_desc_banks[i].vaddr_unaligned,
682 link_desc_banks[i].paddr_unaligned);
683 link_desc_banks[i].vaddr_unaligned = NULL;
688 static int ath12k_dp_link_desc_bank_alloc(struct ath12k_base *ab,
689 struct dp_link_desc_bank *desc_bank,
690 int n_link_desc_bank,
693 struct ath12k_dp *dp = &ab->dp;
696 int desc_sz = DP_LINK_DESC_ALLOC_SIZE_THRESH;
698 for (i = 0; i < n_link_desc_bank; i++) {
699 if (i == (n_link_desc_bank - 1) && last_bank_sz)
700 desc_sz = last_bank_sz;
702 desc_bank[i].vaddr_unaligned =
703 dma_alloc_coherent(ab->dev, desc_sz,
704 &desc_bank[i].paddr_unaligned,
706 if (!desc_bank[i].vaddr_unaligned) {
711 desc_bank[i].vaddr = PTR_ALIGN(desc_bank[i].vaddr_unaligned,
712 HAL_LINK_DESC_ALIGN);
713 desc_bank[i].paddr = desc_bank[i].paddr_unaligned +
714 ((unsigned long)desc_bank[i].vaddr -
715 (unsigned long)desc_bank[i].vaddr_unaligned);
716 desc_bank[i].size = desc_sz;
722 ath12k_dp_link_desc_bank_free(ab, dp->link_desc_banks);
727 void ath12k_dp_link_desc_cleanup(struct ath12k_base *ab,
728 struct dp_link_desc_bank *desc_bank,
729 u32 ring_type, struct dp_srng *ring)
731 ath12k_dp_link_desc_bank_free(ab, desc_bank);
733 if (ring_type != HAL_RXDMA_MONITOR_DESC) {
734 ath12k_dp_srng_cleanup(ab, ring);
735 ath12k_dp_scatter_idle_link_desc_cleanup(ab);
739 static int ath12k_wbm_idle_ring_setup(struct ath12k_base *ab, u32 *n_link_desc)
741 struct ath12k_dp *dp = &ab->dp;
742 u32 n_mpdu_link_desc, n_mpdu_queue_desc;
743 u32 n_tx_msdu_link_desc, n_rx_msdu_link_desc;
746 n_mpdu_link_desc = (DP_NUM_TIDS_MAX * DP_AVG_MPDUS_PER_TID_MAX) /
747 HAL_NUM_MPDUS_PER_LINK_DESC;
749 n_mpdu_queue_desc = n_mpdu_link_desc /
750 HAL_NUM_MPDU_LINKS_PER_QUEUE_DESC;
752 n_tx_msdu_link_desc = (DP_NUM_TIDS_MAX * DP_AVG_FLOWS_PER_TID *
753 DP_AVG_MSDUS_PER_FLOW) /
754 HAL_NUM_TX_MSDUS_PER_LINK_DESC;
756 n_rx_msdu_link_desc = (DP_NUM_TIDS_MAX * DP_AVG_MPDUS_PER_TID_MAX *
757 DP_AVG_MSDUS_PER_MPDU) /
758 HAL_NUM_RX_MSDUS_PER_LINK_DESC;
760 *n_link_desc = n_mpdu_link_desc + n_mpdu_queue_desc +
761 n_tx_msdu_link_desc + n_rx_msdu_link_desc;
763 if (*n_link_desc & (*n_link_desc - 1))
764 *n_link_desc = 1 << fls(*n_link_desc);
766 ret = ath12k_dp_srng_setup(ab, &dp->wbm_idle_ring,
767 HAL_WBM_IDLE_LINK, 0, 0, *n_link_desc);
769 ath12k_warn(ab, "failed to setup wbm_idle_ring: %d\n", ret);
775 int ath12k_dp_link_desc_setup(struct ath12k_base *ab,
776 struct dp_link_desc_bank *link_desc_banks,
777 u32 ring_type, struct hal_srng *srng,
781 u32 n_link_desc_bank, last_bank_sz;
782 u32 entry_sz, align_bytes, n_entries;
783 struct hal_wbm_link_desc *desc;
788 tot_mem_sz = n_link_desc * HAL_LINK_DESC_SIZE;
789 tot_mem_sz += HAL_LINK_DESC_ALIGN;
791 if (tot_mem_sz <= DP_LINK_DESC_ALLOC_SIZE_THRESH) {
792 n_link_desc_bank = 1;
793 last_bank_sz = tot_mem_sz;
795 n_link_desc_bank = tot_mem_sz /
796 (DP_LINK_DESC_ALLOC_SIZE_THRESH -
797 HAL_LINK_DESC_ALIGN);
798 last_bank_sz = tot_mem_sz %
799 (DP_LINK_DESC_ALLOC_SIZE_THRESH -
800 HAL_LINK_DESC_ALIGN);
803 n_link_desc_bank += 1;
806 if (n_link_desc_bank > DP_LINK_DESC_BANKS_MAX)
809 ret = ath12k_dp_link_desc_bank_alloc(ab, link_desc_banks,
810 n_link_desc_bank, last_bank_sz);
814 /* Setup link desc idle list for HW internal usage */
815 entry_sz = ath12k_hal_srng_get_entrysize(ab, ring_type);
816 tot_mem_sz = entry_sz * n_link_desc;
818 /* Setup scatter desc list when the total memory requirement is more */
819 if (tot_mem_sz > DP_LINK_DESC_ALLOC_SIZE_THRESH &&
820 ring_type != HAL_RXDMA_MONITOR_DESC) {
821 ret = ath12k_dp_scatter_idle_link_desc_setup(ab, tot_mem_sz,
826 ath12k_warn(ab, "failed to setup scatting idle list descriptor :%d\n",
828 goto fail_desc_bank_free;
834 spin_lock_bh(&srng->lock);
836 ath12k_hal_srng_access_begin(ab, srng);
838 for (i = 0; i < n_link_desc_bank; i++) {
839 align_bytes = link_desc_banks[i].vaddr -
840 link_desc_banks[i].vaddr_unaligned;
841 n_entries = (link_desc_banks[i].size - align_bytes) /
843 paddr = link_desc_banks[i].paddr;
845 (desc = ath12k_hal_srng_src_get_next_entry(ab, srng))) {
846 cookie = DP_LINK_DESC_COOKIE_SET(n_entries, i);
847 ath12k_hal_set_link_desc_addr(desc,
850 paddr += HAL_LINK_DESC_SIZE;
854 ath12k_hal_srng_access_end(ab, srng);
856 spin_unlock_bh(&srng->lock);
861 ath12k_dp_link_desc_bank_free(ab, link_desc_banks);
866 int ath12k_dp_service_srng(struct ath12k_base *ab,
867 struct ath12k_ext_irq_grp *irq_grp,
870 struct napi_struct *napi = &irq_grp->napi;
871 int grp_id = irq_grp->grp_id;
874 int tot_work_done = 0;
875 enum dp_monitor_mode monitor_mode;
878 while (i < ab->hw_params->max_tx_ring) {
879 if (ab->hw_params->ring_mask->tx[grp_id] &
880 BIT(ab->hw_params->hal_ops->tcl_to_wbm_rbm_map[i].wbm_ring_num))
881 ath12k_dp_tx_completion_handler(ab, i);
885 if (ab->hw_params->ring_mask->rx_err[grp_id]) {
886 work_done = ath12k_dp_rx_process_err(ab, napi, budget);
888 tot_work_done += work_done;
893 if (ab->hw_params->ring_mask->rx_wbm_rel[grp_id]) {
894 work_done = ath12k_dp_rx_process_wbm_err(ab,
898 tot_work_done += work_done;
904 if (ab->hw_params->ring_mask->rx[grp_id]) {
905 i = fls(ab->hw_params->ring_mask->rx[grp_id]) - 1;
906 work_done = ath12k_dp_rx_process(ab, i, napi,
909 tot_work_done += work_done;
914 if (ab->hw_params->ring_mask->rx_mon_dest[grp_id]) {
915 monitor_mode = ATH12K_DP_RX_MONITOR_MODE;
916 ring_mask = ab->hw_params->ring_mask->rx_mon_dest[grp_id];
917 for (i = 0; i < ab->num_radios; i++) {
918 for (j = 0; j < ab->hw_params->num_rxmda_per_pdev; j++) {
919 int id = i * ab->hw_params->num_rxmda_per_pdev + j;
921 if (ring_mask & BIT(id)) {
923 ath12k_dp_mon_process_ring(ab, id, napi, budget,
926 tot_work_done += work_done;
935 if (ab->hw_params->ring_mask->tx_mon_dest[grp_id]) {
936 monitor_mode = ATH12K_DP_TX_MONITOR_MODE;
937 ring_mask = ab->hw_params->ring_mask->tx_mon_dest[grp_id];
938 for (i = 0; i < ab->num_radios; i++) {
939 for (j = 0; j < ab->hw_params->num_rxmda_per_pdev; j++) {
940 int id = i * ab->hw_params->num_rxmda_per_pdev + j;
942 if (ring_mask & BIT(id)) {
944 ath12k_dp_mon_process_ring(ab, id, napi, budget,
947 tot_work_done += work_done;
956 if (ab->hw_params->ring_mask->reo_status[grp_id])
957 ath12k_dp_rx_process_reo_status(ab);
959 if (ab->hw_params->ring_mask->host2rxdma[grp_id]) {
960 struct ath12k_dp *dp = &ab->dp;
961 struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring;
963 ath12k_dp_rx_bufs_replenish(ab, 0, rx_ring, 0,
964 ab->hw_params->hal_params->rx_buf_rbm,
968 /* TODO: Implement handler for other interrupts */
971 return tot_work_done;
974 void ath12k_dp_pdev_free(struct ath12k_base *ab)
978 del_timer_sync(&ab->mon_reap_timer);
980 for (i = 0; i < ab->num_radios; i++)
981 ath12k_dp_rx_pdev_free(ab, i);
984 void ath12k_dp_pdev_pre_alloc(struct ath12k_base *ab)
987 struct ath12k_pdev_dp *dp;
990 for (i = 0; i < ab->num_radios; i++) {
991 ar = ab->pdevs[i].ar;
994 atomic_set(&dp->num_tx_pending, 0);
995 init_waitqueue_head(&dp->tx_empty_waitq);
997 /* TODO: Add any RXDMA setup required per pdev */
1001 static void ath12k_dp_service_mon_ring(struct timer_list *t)
1003 struct ath12k_base *ab = from_timer(ab, t, mon_reap_timer);
1006 for (i = 0; i < ab->hw_params->num_rxmda_per_pdev; i++)
1007 ath12k_dp_mon_process_ring(ab, i, NULL, DP_MON_SERVICE_BUDGET,
1008 ATH12K_DP_RX_MONITOR_MODE);
1010 mod_timer(&ab->mon_reap_timer, jiffies +
1011 msecs_to_jiffies(ATH12K_MON_TIMER_INTERVAL));
1014 static void ath12k_dp_mon_reap_timer_init(struct ath12k_base *ab)
1016 if (ab->hw_params->rxdma1_enable)
1019 timer_setup(&ab->mon_reap_timer, ath12k_dp_service_mon_ring, 0);
1022 int ath12k_dp_pdev_alloc(struct ath12k_base *ab)
1028 ret = ath12k_dp_rx_htt_setup(ab);
1032 ath12k_dp_mon_reap_timer_init(ab);
1034 /* TODO: Per-pdev rx ring unlike tx ring which is mapped to different AC's */
1035 for (i = 0; i < ab->num_radios; i++) {
1036 ar = ab->pdevs[i].ar;
1037 ret = ath12k_dp_rx_pdev_alloc(ab, i);
1039 ath12k_warn(ab, "failed to allocate pdev rx for pdev_id :%d\n",
1043 ret = ath12k_dp_rx_pdev_mon_attach(ar);
1045 ath12k_warn(ab, "failed to initialize mon pdev %d\n", i);
1052 ath12k_dp_pdev_free(ab);
1057 int ath12k_dp_htt_connect(struct ath12k_dp *dp)
1059 struct ath12k_htc_svc_conn_req conn_req = {0};
1060 struct ath12k_htc_svc_conn_resp conn_resp = {0};
1063 conn_req.ep_ops.ep_tx_complete = ath12k_dp_htt_htc_tx_complete;
1064 conn_req.ep_ops.ep_rx_complete = ath12k_dp_htt_htc_t2h_msg_handler;
1066 /* connect to control service */
1067 conn_req.service_id = ATH12K_HTC_SVC_ID_HTT_DATA_MSG;
1069 status = ath12k_htc_connect_service(&dp->ab->htc, &conn_req,
1075 dp->eid = conn_resp.eid;
1080 static void ath12k_dp_update_vdev_search(struct ath12k_vif *arvif)
1082 switch (arvif->vdev_type) {
1083 case WMI_VDEV_TYPE_STA:
1084 /* TODO: Verify the search type and flags since ast hash
1085 * is not part of peer mapv3
1087 arvif->hal_addr_search_flags = HAL_TX_ADDRY_EN;
1088 arvif->search_type = HAL_TX_ADDR_SEARCH_DEFAULT;
1090 case WMI_VDEV_TYPE_AP:
1091 case WMI_VDEV_TYPE_IBSS:
1092 arvif->hal_addr_search_flags = HAL_TX_ADDRX_EN;
1093 arvif->search_type = HAL_TX_ADDR_SEARCH_DEFAULT;
1095 case WMI_VDEV_TYPE_MONITOR:
1101 void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_vif *arvif)
1103 struct ath12k_base *ab = ar->ab;
1105 arvif->tcl_metadata |= u32_encode_bits(1, HTT_TCL_META_DATA_TYPE) |
1106 u32_encode_bits(arvif->vdev_id,
1107 HTT_TCL_META_DATA_VDEV_ID) |
1108 u32_encode_bits(ar->pdev->pdev_id,
1109 HTT_TCL_META_DATA_PDEV_ID);
1111 /* set HTT extension valid bit to 0 by default */
1112 arvif->tcl_metadata &= ~HTT_TCL_META_DATA_VALID_HTT;
1114 ath12k_dp_update_vdev_search(arvif);
1115 arvif->vdev_id_check_en = true;
1116 arvif->bank_id = ath12k_dp_tx_get_bank_profile(ab, arvif, &ab->dp);
1118 /* TODO: error path for bank id failure */
1119 if (arvif->bank_id == DP_INVALID_BANK_ID) {
1120 ath12k_err(ar->ab, "Failed to initialize DP TX Banks");
1125 static void ath12k_dp_cc_cleanup(struct ath12k_base *ab)
1127 struct ath12k_rx_desc_info *desc_info, *tmp;
1128 struct ath12k_tx_desc_info *tx_desc_info, *tmp1;
1129 struct ath12k_dp *dp = &ab->dp;
1130 struct sk_buff *skb;
1132 u32 pool_id, tx_spt_page;
1137 /* RX Descriptor cleanup */
1138 spin_lock_bh(&dp->rx_desc_lock);
1140 list_for_each_entry_safe(desc_info, tmp, &dp->rx_desc_used_list, list) {
1141 list_del(&desc_info->list);
1142 skb = desc_info->skb;
1147 dma_unmap_single(ab->dev, ATH12K_SKB_RXCB(skb)->paddr,
1148 skb->len + skb_tailroom(skb), DMA_FROM_DEVICE);
1149 dev_kfree_skb_any(skb);
1152 for (i = 0; i < ATH12K_NUM_RX_SPT_PAGES; i++) {
1153 if (!dp->spt_info->rxbaddr[i])
1156 kfree(dp->spt_info->rxbaddr[i]);
1157 dp->spt_info->rxbaddr[i] = NULL;
1160 spin_unlock_bh(&dp->rx_desc_lock);
1162 /* TX Descriptor cleanup */
1163 for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) {
1164 spin_lock_bh(&dp->tx_desc_lock[i]);
1166 list_for_each_entry_safe(tx_desc_info, tmp1, &dp->tx_desc_used_list[i],
1168 list_del(&tx_desc_info->list);
1169 skb = tx_desc_info->skb;
1174 dma_unmap_single(ab->dev, ATH12K_SKB_CB(skb)->paddr,
1175 skb->len, DMA_TO_DEVICE);
1176 dev_kfree_skb_any(skb);
1179 spin_unlock_bh(&dp->tx_desc_lock[i]);
1182 for (pool_id = 0; pool_id < ATH12K_HW_MAX_QUEUES; pool_id++) {
1183 spin_lock_bh(&dp->tx_desc_lock[pool_id]);
1185 for (i = 0; i < ATH12K_TX_SPT_PAGES_PER_POOL; i++) {
1186 tx_spt_page = i + pool_id * ATH12K_TX_SPT_PAGES_PER_POOL;
1187 if (!dp->spt_info->txbaddr[tx_spt_page])
1190 kfree(dp->spt_info->txbaddr[tx_spt_page]);
1191 dp->spt_info->txbaddr[tx_spt_page] = NULL;
1194 spin_unlock_bh(&dp->tx_desc_lock[pool_id]);
1197 /* unmap SPT pages */
1198 for (i = 0; i < dp->num_spt_pages; i++) {
1199 if (!dp->spt_info[i].vaddr)
1202 dma_free_coherent(ab->dev, ATH12K_PAGE_SIZE,
1203 dp->spt_info[i].vaddr, dp->spt_info[i].paddr);
1204 dp->spt_info[i].vaddr = NULL;
1207 kfree(dp->spt_info);
1210 static void ath12k_dp_reoq_lut_cleanup(struct ath12k_base *ab)
1212 struct ath12k_dp *dp = &ab->dp;
1214 if (!ab->hw_params->reoq_lut_support)
1217 if (!dp->reoq_lut.vaddr)
1220 dma_free_coherent(ab->dev, DP_REOQ_LUT_SIZE,
1221 dp->reoq_lut.vaddr, dp->reoq_lut.paddr);
1222 dp->reoq_lut.vaddr = NULL;
1224 ath12k_hif_write32(ab,
1225 HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO1_QDESC_LUT_BASE0(ab), 0);
1228 void ath12k_dp_free(struct ath12k_base *ab)
1230 struct ath12k_dp *dp = &ab->dp;
1233 ath12k_dp_link_desc_cleanup(ab, dp->link_desc_banks,
1234 HAL_WBM_IDLE_LINK, &dp->wbm_idle_ring);
1236 ath12k_dp_cc_cleanup(ab);
1237 ath12k_dp_reoq_lut_cleanup(ab);
1238 ath12k_dp_deinit_bank_profiles(ab);
1239 ath12k_dp_srng_common_cleanup(ab);
1241 ath12k_dp_rx_reo_cmd_list_cleanup(ab);
1243 for (i = 0; i < ab->hw_params->max_tx_ring; i++)
1244 kfree(dp->tx_ring[i].tx_status);
1246 ath12k_dp_rx_free(ab);
1247 /* Deinit any SOC level resource */
1250 void ath12k_dp_cc_config(struct ath12k_base *ab)
1252 u32 cmem_base = ab->qmi.dev_mem[ATH12K_QMI_DEVMEM_CMEM_INDEX].start;
1253 u32 reo_base = HAL_SEQ_WCSS_UMAC_REO_REG;
1254 u32 wbm_base = HAL_SEQ_WCSS_UMAC_WBM_REG;
1257 ath12k_hif_write32(ab, reo_base + HAL_REO1_SW_COOKIE_CFG0(ab), cmem_base);
1259 val |= u32_encode_bits(ATH12K_CMEM_ADDR_MSB,
1260 HAL_REO1_SW_COOKIE_CFG_CMEM_BASE_ADDR_MSB) |
1261 u32_encode_bits(ATH12K_CC_PPT_MSB,
1262 HAL_REO1_SW_COOKIE_CFG_COOKIE_PPT_MSB) |
1263 u32_encode_bits(ATH12K_CC_SPT_MSB,
1264 HAL_REO1_SW_COOKIE_CFG_COOKIE_SPT_MSB) |
1265 u32_encode_bits(1, HAL_REO1_SW_COOKIE_CFG_ALIGN) |
1266 u32_encode_bits(1, HAL_REO1_SW_COOKIE_CFG_ENABLE) |
1267 u32_encode_bits(1, HAL_REO1_SW_COOKIE_CFG_GLOBAL_ENABLE);
1269 ath12k_hif_write32(ab, reo_base + HAL_REO1_SW_COOKIE_CFG1(ab), val);
1271 /* Enable HW CC for WBM */
1272 ath12k_hif_write32(ab, wbm_base + HAL_WBM_SW_COOKIE_CFG0, cmem_base);
1274 val = u32_encode_bits(ATH12K_CMEM_ADDR_MSB,
1275 HAL_WBM_SW_COOKIE_CFG_CMEM_BASE_ADDR_MSB) |
1276 u32_encode_bits(ATH12K_CC_PPT_MSB,
1277 HAL_WBM_SW_COOKIE_CFG_COOKIE_PPT_MSB) |
1278 u32_encode_bits(ATH12K_CC_SPT_MSB,
1279 HAL_WBM_SW_COOKIE_CFG_COOKIE_SPT_MSB) |
1280 u32_encode_bits(1, HAL_WBM_SW_COOKIE_CFG_ALIGN);
1282 ath12k_hif_write32(ab, wbm_base + HAL_WBM_SW_COOKIE_CFG1, val);
1284 /* Enable conversion complete indication */
1285 val = ath12k_hif_read32(ab, wbm_base + HAL_WBM_SW_COOKIE_CFG2);
1286 val |= u32_encode_bits(1, HAL_WBM_SW_COOKIE_CFG_RELEASE_PATH_EN) |
1287 u32_encode_bits(1, HAL_WBM_SW_COOKIE_CFG_ERR_PATH_EN) |
1288 u32_encode_bits(1, HAL_WBM_SW_COOKIE_CFG_CONV_IND_EN);
1290 ath12k_hif_write32(ab, wbm_base + HAL_WBM_SW_COOKIE_CFG2, val);
1292 /* Enable Cookie conversion for WBM2SW Rings */
1293 val = ath12k_hif_read32(ab, wbm_base + HAL_WBM_SW_COOKIE_CONVERT_CFG);
1294 val |= u32_encode_bits(1, HAL_WBM_SW_COOKIE_CONV_CFG_GLOBAL_EN) |
1295 ab->hw_params->hal_params->wbm2sw_cc_enable;
1297 ath12k_hif_write32(ab, wbm_base + HAL_WBM_SW_COOKIE_CONVERT_CFG, val);
1300 static u32 ath12k_dp_cc_cookie_gen(u16 ppt_idx, u16 spt_idx)
1302 return (u32)ppt_idx << ATH12K_CC_PPT_SHIFT | spt_idx;
1305 static inline void *ath12k_dp_cc_get_desc_addr_ptr(struct ath12k_base *ab,
1306 u16 ppt_idx, u16 spt_idx)
1308 struct ath12k_dp *dp = &ab->dp;
1310 return dp->spt_info[ppt_idx].vaddr + spt_idx;
1313 struct ath12k_rx_desc_info *ath12k_dp_get_rx_desc(struct ath12k_base *ab,
1316 struct ath12k_rx_desc_info **desc_addr_ptr;
1317 u16 ppt_idx, spt_idx;
1319 ppt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_PPT);
1320 spt_idx = u32_get_bits(cookie, ATH12k_DP_CC_COOKIE_SPT);
1322 if (ppt_idx > ATH12K_NUM_RX_SPT_PAGES ||
1323 spt_idx > ATH12K_MAX_SPT_ENTRIES)
1326 desc_addr_ptr = ath12k_dp_cc_get_desc_addr_ptr(ab, ppt_idx, spt_idx);
1328 return *desc_addr_ptr;
1331 struct ath12k_tx_desc_info *ath12k_dp_get_tx_desc(struct ath12k_base *ab,
1334 struct ath12k_tx_desc_info **desc_addr_ptr;
1335 u16 ppt_idx, spt_idx;
1337 ppt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_PPT);
1338 spt_idx = u32_get_bits(cookie, ATH12k_DP_CC_COOKIE_SPT);
1340 if (ppt_idx < ATH12K_NUM_RX_SPT_PAGES ||
1341 ppt_idx > ab->dp.num_spt_pages ||
1342 spt_idx > ATH12K_MAX_SPT_ENTRIES)
1345 desc_addr_ptr = ath12k_dp_cc_get_desc_addr_ptr(ab, ppt_idx, spt_idx);
1347 return *desc_addr_ptr;
1350 static int ath12k_dp_cc_desc_init(struct ath12k_base *ab)
1352 struct ath12k_dp *dp = &ab->dp;
1353 struct ath12k_rx_desc_info *rx_descs, **rx_desc_addr;
1354 struct ath12k_tx_desc_info *tx_descs, **tx_desc_addr;
1355 u32 i, j, pool_id, tx_spt_page;
1358 spin_lock_bh(&dp->rx_desc_lock);
1360 /* First ATH12K_NUM_RX_SPT_PAGES of allocated SPT pages are used for RX */
1361 for (i = 0; i < ATH12K_NUM_RX_SPT_PAGES; i++) {
1362 rx_descs = kcalloc(ATH12K_MAX_SPT_ENTRIES, sizeof(*rx_descs),
1366 spin_unlock_bh(&dp->rx_desc_lock);
1370 dp->spt_info->rxbaddr[i] = &rx_descs[0];
1372 for (j = 0; j < ATH12K_MAX_SPT_ENTRIES; j++) {
1373 rx_descs[j].cookie = ath12k_dp_cc_cookie_gen(i, j);
1374 rx_descs[j].magic = ATH12K_DP_RX_DESC_MAGIC;
1375 list_add_tail(&rx_descs[j].list, &dp->rx_desc_free_list);
1377 /* Update descriptor VA in SPT */
1378 rx_desc_addr = ath12k_dp_cc_get_desc_addr_ptr(ab, i, j);
1379 *rx_desc_addr = &rx_descs[j];
1383 spin_unlock_bh(&dp->rx_desc_lock);
1385 for (pool_id = 0; pool_id < ATH12K_HW_MAX_QUEUES; pool_id++) {
1386 spin_lock_bh(&dp->tx_desc_lock[pool_id]);
1387 for (i = 0; i < ATH12K_TX_SPT_PAGES_PER_POOL; i++) {
1388 tx_descs = kcalloc(ATH12K_MAX_SPT_ENTRIES, sizeof(*tx_descs),
1392 spin_unlock_bh(&dp->tx_desc_lock[pool_id]);
1393 /* Caller takes care of TX pending and RX desc cleanup */
1397 tx_spt_page = i + pool_id * ATH12K_TX_SPT_PAGES_PER_POOL;
1398 dp->spt_info->txbaddr[tx_spt_page] = &tx_descs[0];
1400 for (j = 0; j < ATH12K_MAX_SPT_ENTRIES; j++) {
1401 ppt_idx = ATH12K_NUM_RX_SPT_PAGES + tx_spt_page;
1402 tx_descs[j].desc_id = ath12k_dp_cc_cookie_gen(ppt_idx, j);
1403 tx_descs[j].pool_id = pool_id;
1404 list_add_tail(&tx_descs[j].list,
1405 &dp->tx_desc_free_list[pool_id]);
1407 /* Update descriptor VA in SPT */
1409 ath12k_dp_cc_get_desc_addr_ptr(ab, ppt_idx, j);
1410 *tx_desc_addr = &tx_descs[j];
1413 spin_unlock_bh(&dp->tx_desc_lock[pool_id]);
1418 static int ath12k_dp_cc_init(struct ath12k_base *ab)
1420 struct ath12k_dp *dp = &ab->dp;
1424 INIT_LIST_HEAD(&dp->rx_desc_free_list);
1425 INIT_LIST_HEAD(&dp->rx_desc_used_list);
1426 spin_lock_init(&dp->rx_desc_lock);
1428 for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) {
1429 INIT_LIST_HEAD(&dp->tx_desc_free_list[i]);
1430 INIT_LIST_HEAD(&dp->tx_desc_used_list[i]);
1431 spin_lock_init(&dp->tx_desc_lock[i]);
1434 dp->num_spt_pages = ATH12K_NUM_SPT_PAGES;
1435 if (dp->num_spt_pages > ATH12K_MAX_PPT_ENTRIES)
1436 dp->num_spt_pages = ATH12K_MAX_PPT_ENTRIES;
1438 dp->spt_info = kcalloc(dp->num_spt_pages, sizeof(struct ath12k_spt_info),
1441 if (!dp->spt_info) {
1442 ath12k_warn(ab, "SPT page allocation failure");
1446 cmem_base = ab->qmi.dev_mem[ATH12K_QMI_DEVMEM_CMEM_INDEX].start;
1448 for (i = 0; i < dp->num_spt_pages; i++) {
1449 dp->spt_info[i].vaddr = dma_alloc_coherent(ab->dev,
1451 &dp->spt_info[i].paddr,
1454 if (!dp->spt_info[i].vaddr) {
1459 if (dp->spt_info[i].paddr & ATH12K_SPT_4K_ALIGN_CHECK) {
1460 ath12k_warn(ab, "SPT allocated memory is not 4K aligned");
1465 /* Write to PPT in CMEM */
1466 ath12k_hif_write32(ab, cmem_base + ATH12K_PPT_ADDR_OFFSET(i),
1467 dp->spt_info[i].paddr >> ATH12K_SPT_4K_ALIGN_OFFSET);
1470 ret = ath12k_dp_cc_desc_init(ab);
1472 ath12k_warn(ab, "HW CC desc init failed %d", ret);
1478 ath12k_dp_cc_cleanup(ab);
1482 static int ath12k_dp_reoq_lut_setup(struct ath12k_base *ab)
1484 struct ath12k_dp *dp = &ab->dp;
1486 if (!ab->hw_params->reoq_lut_support)
1489 dp->reoq_lut.vaddr = dma_alloc_coherent(ab->dev,
1491 &dp->reoq_lut.paddr,
1492 GFP_KERNEL | __GFP_ZERO);
1493 if (!dp->reoq_lut.vaddr) {
1494 ath12k_warn(ab, "failed to allocate memory for reoq table");
1498 ath12k_hif_write32(ab, HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO1_QDESC_LUT_BASE0(ab),
1499 dp->reoq_lut.paddr);
1503 int ath12k_dp_alloc(struct ath12k_base *ab)
1505 struct ath12k_dp *dp = &ab->dp;
1506 struct hal_srng *srng = NULL;
1508 u32 n_link_desc = 0;
1514 INIT_LIST_HEAD(&dp->reo_cmd_list);
1515 INIT_LIST_HEAD(&dp->reo_cmd_cache_flush_list);
1516 spin_lock_init(&dp->reo_cmd_lock);
1518 dp->reo_cmd_cache_flush_count = 0;
1520 ret = ath12k_wbm_idle_ring_setup(ab, &n_link_desc);
1522 ath12k_warn(ab, "failed to setup wbm_idle_ring: %d\n", ret);
1526 srng = &ab->hal.srng_list[dp->wbm_idle_ring.ring_id];
1528 ret = ath12k_dp_link_desc_setup(ab, dp->link_desc_banks,
1529 HAL_WBM_IDLE_LINK, srng, n_link_desc);
1531 ath12k_warn(ab, "failed to setup link desc: %d\n", ret);
1535 ret = ath12k_dp_cc_init(ab);
1538 ath12k_warn(ab, "failed to setup cookie converter %d\n", ret);
1539 goto fail_link_desc_cleanup;
1541 ret = ath12k_dp_init_bank_profiles(ab);
1543 ath12k_warn(ab, "failed to setup bank profiles %d\n", ret);
1544 goto fail_hw_cc_cleanup;
1547 ret = ath12k_dp_srng_common_setup(ab);
1549 goto fail_dp_bank_profiles_cleanup;
1551 size = sizeof(struct hal_wbm_release_ring_tx) * DP_TX_COMP_RING_SIZE;
1553 ret = ath12k_dp_reoq_lut_setup(ab);
1555 ath12k_warn(ab, "failed to setup reoq table %d\n", ret);
1556 goto fail_cmn_srng_cleanup;
1559 for (i = 0; i < ab->hw_params->max_tx_ring; i++) {
1560 dp->tx_ring[i].tcl_data_ring_id = i;
1562 dp->tx_ring[i].tx_status_head = 0;
1563 dp->tx_ring[i].tx_status_tail = DP_TX_COMP_RING_SIZE - 1;
1564 dp->tx_ring[i].tx_status = kmalloc(size, GFP_KERNEL);
1565 if (!dp->tx_ring[i].tx_status) {
1567 /* FIXME: The allocated tx status is not freed
1570 goto fail_cmn_reoq_cleanup;
1574 for (i = 0; i < HAL_DSCP_TID_MAP_TBL_NUM_ENTRIES_MAX; i++)
1575 ath12k_hal_tx_set_dscp_tid_map(ab, i);
1577 ret = ath12k_dp_rx_alloc(ab);
1579 goto fail_dp_rx_free;
1581 /* Init any SOC level resource for DP */
1586 ath12k_dp_rx_free(ab);
1588 fail_cmn_reoq_cleanup:
1589 ath12k_dp_reoq_lut_cleanup(ab);
1591 fail_cmn_srng_cleanup:
1592 ath12k_dp_srng_common_cleanup(ab);
1594 fail_dp_bank_profiles_cleanup:
1595 ath12k_dp_deinit_bank_profiles(ab);
1598 ath12k_dp_cc_cleanup(ab);
1600 fail_link_desc_cleanup:
1601 ath12k_dp_link_desc_cleanup(ab, dp->link_desc_banks,
1602 HAL_WBM_IDLE_LINK, &dp->wbm_idle_ring);