wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices
Subsystems (2)
PATCH v2 1/50 wifi: ath12k: add Kconfig
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/Kconfig | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/net/wireless/ath/ath12k/Kconfig new file +34 -0
@@ -0,0 +1,34 @@ +# SPDX-License-Identifier: BSD-3-Clause-Clear +config ATH12K + tristate "Qualcomm Technologies Wi-Fi 7 support (ath12k)" + depends on MAC80211 && HAS_DMA && PCI + depends on CRYPTO_MICHAEL_MIC + select QCOM_QMI_HELPERS + select MHI_BUS + select QRTR + select QRTR_MHI + help + Enable support for Qualcomm Technologies Wi-Fi 7 (IEEE + 802.11be) family of chipsets, for example WCN7850 and + QCN9274. + + If you choose to build a module, it'll be called ath12k. + +config ATH12K_DEBUG + bool "ath12k debugging" + depends on ATH12K + help + Enable debug support, for example debug messages which must + be enabled separately using the debug_mask module parameter. + + If unsure, say Y to make it easier to debug problems. But if + you want optimal performance choose N. + +config ATH12K_TRACING + bool "ath12k tracing support" + depends on ATH12K && EVENT_TRACING + help + Enable ath12k tracing infrastructure. + + If unsure, say Y to make it easier to debug problems. But if + you want optimal performance choose N.
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 2/50 wifi: ath12k: add Makefile
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/Makefile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/net/wireless/ath/ath12k/Makefile new file +27 -0
@@ -0,0 +1,27 @@ +# SPDX-License-Identifier: BSD-3-Clause-Clear +obj-$(CONFIG_ATH12K) += ath12k.o +ath12k-y += core.o \ + hal.o \ + hal_tx.o \ + hal_rx.o \ + wmi.o \ + mac.o \ + reg.o \ + htc.o \ + qmi.o \ + dp.o \ + dp_tx.o \ + dp_rx.o \ + debug.o \ + ce.o \ + peer.o \ + dbring.o \ + hw.o \ + mhi.o \ + pci.o \ + dp_mon.o + +ath12k-$(CONFIG_ATH12K_TRACING) += trace.o + +# for tracing framework to find trace.h +CFLAGS_trace.o := -I$(src)
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 3/50 wifi: ath12k: add ce.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/ce.c | 964 +++++++++++++++++++++++++++++++++++ 1 file changed, 964 insertions(+)
drivers/net/wireless/ath/ath12k/ce.c new file +964 -0
@@ -0,0 +1,964 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include "dp_rx.h" +#include "debug.h" +#include "hif.h" + +const struct ce_attr ath12k_host_ce_config_qcn9274[] = { +/* CE0: host->target HTC control and raw streams */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =16 , + .src_sz_max =2048 , + .dest_nentries =0 , + }, + +/* CE1: target->host HTT + HTC control */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =0 , + .src_sz_max =2048 , + .dest_nentries =512 , + .recv_cb = ath12k_htc_rx_completion_handler, + }, + +/* CE2: target->host WMI */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =0 , + .src_sz_max =2048 , + .dest_nentries =128 , + .recv_cb = ath12k_htc_rx_completion_handler, + }, + +/* CE3: host->target WMI (mac0) */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =32 , + .src_sz_max =2048 , + .dest_nentries =0 , + }, + +/* CE4: host->target HTT */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =2048 , + .src_sz_max =256 , + .dest_nentries =0 , + }, + +/* CE5: target->host pktlog */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =0 , + .src_sz_max =2048 , + .dest_nentries =512 , + .recv_cb = ath12k_dp_htt_htc_t2h_msg_handler, + }, + +/* CE6: target autonomous hif_memcpy */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE7: host->target WMI (mac1) */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =32 , + .src_sz_max =2048 , + .dest_nentries =0 , + }, + +/* CE8: target autonomous hif_memcpy */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE9: MHI */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE10: MHI */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE11: MHI */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE12: CV Prefetch */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE13: CV Prefetch */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE14: target->host dbg log */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =0 , + .src_sz_max =2048 , + .dest_nentries =512 , + .recv_cb = ath12k_htc_rx_completion_handler, + }, + +/* CE15: reserved for future use */ + { + .flags = (CE_ATTR_FLAGS |CE_ATTR_DIS_INTR ), + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, +}; + +const struct ce_attr ath12k_host_ce_config_wcn7850[] = { +/* CE0: host->target HTC control and raw streams */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =16 , + .src_sz_max =2048 , + .dest_nentries =0 , + }, + +/* CE1: target->host HTT + HTC control */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =0 , + .src_sz_max =2048 , + .dest_nentries =512 , + .recv_cb = ath12k_htc_rx_completion_handler, + }, + +/* CE2: target->host WMI */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =0 , + .src_sz_max =2048 , + .dest_nentries =64 , + .recv_cb = ath12k_htc_rx_completion_handler, + }, + +/* CE3: host->target WMI (mac0) */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =32 , + .src_sz_max =2048 , + .dest_nentries =0 , + }, + +/* CE4: host->target HTT */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =2048 , + .src_sz_max =256 , + .dest_nentries =0 , + }, + +/* CE5: target->host pktlog */ + { + .flags =CE_ATTR_FLAGS , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE6: target autonomous hif_memcpy */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +/* CE7: host->target WMI (mac1) */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =2048 , + .dest_nentries =0 , + }, + +/* CE8: target autonomous hif_memcpy */ + { + .flags =CE_ATTR_FLAGS |CE_ATTR_DIS_INTR , + .src_nentries =0 , + .src_sz_max =0 , + .dest_nentries =0 , + }, + +}; + +static int ath12k_ce_rx_buf_enqueue_pipe (struct ath12k_ce_pipe *pipe, +struct sk_buff *skb,dma_addr_t paddr) +{ +struct ath12k_base *ab = pipe->ab; +struct ath12k_ce_ring *ring = pipe->dest_ring; +struct hal_srng *srng; +unsigned int write_index; +unsigned int nentries_mask = ring->nentries_mask; +struct hal_ce_srng_dest_desc *desc; +int ret; + +lockdep_assert_held (&ab->ce.ce_lock); + + write_index = ring->write_index; + + srng = &ab->hal.srng_list[ring->hal_ring_id]; + +spin_lock_bh (&srng->lock); + +ath12k_hal_srng_access_begin (ab, srng); + +if (unlikely (ath12k_hal_srng_src_num_free (ab, srng, false) <1 )) { + ret = -ENOSPC ; + goto exit; + } + + desc =ath12k_hal_srng_src_get_next_entry (ab, srng); +if (!desc) { + ret = -ENOSPC ; + goto exit; + } + +ath12k_hal_ce_dst_set_desc (desc, paddr); + + ring->skb[write_index] = skb; + write_index =CE_RING_IDX_INCR (nentries_mask, write_index); + ring->write_index = write_index; + + pipe->rx_buf_needed--; + + ret =0 ; +exit: +ath12k_hal_srng_access_end (ab, srng); + +spin_unlock_bh (&srng->lock); + +return ret; +} + +static int ath12k_ce_rx_post_pipe (struct ath12k_ce_pipe *pipe) +{ +struct ath12k_base *ab = pipe->ab; +struct sk_buff *skb; +dma_addr_t paddr; +int ret =0 ; + +if (!(pipe->dest_ring || pipe->status_ring)) +return 0 ; + +spin_lock_bh (&ab->ce.ce_lock); +while (pipe->rx_buf_needed) { + skb =dev_alloc_skb (pipe->buf_sz); +if (!skb) { + ret = -ENOMEM ; + goto exit; + } + +WARN_ON_ONCE (!IS_ALIGNED ((unsigned long )skb->data,4 )); + + paddr =dma_map_single (ab->dev, skb->data, + skb->len +skb_tailroom (skb), +DMA_FROM_DEVICE ); +if (unlikely (dma_mapping_error (ab->dev, paddr))) { +ath12k_warn (ab,"failed to dma map ce rx buf\n" ); +dev_kfree_skb_any (skb); + ret = -EIO ; + goto exit; + } + +ATH12K_SKB_RXCB (skb)->paddr = paddr; + + ret =ath12k_ce_rx_buf_enqueue_pipe (pipe, skb, paddr); +if (ret) { +ath12k_warn (ab,"failed to enqueue rx buf: %d\n" , ret); +dma_unmap_single (ab->dev, paddr, + skb->len +skb_tailroom (skb), +DMA_FROM_DEVICE ); +dev_kfree_skb_any (skb); + goto exit; + } + } + +exit: +spin_unlock_bh (&ab->ce.ce_lock); +return ret; +} + +static int ath12k_ce_completed_recv_next (struct ath12k_ce_pipe *pipe, +struct sk_buff **skb,int *nbytes) +{ +struct ath12k_base *ab = pipe->ab; +struct hal_ce_srng_dst_status_desc *desc; +struct hal_srng *srng; +unsigned int sw_index; +unsigned int nentries_mask; +int ret =0 ; + +spin_lock_bh (&ab->ce.ce_lock); + + sw_index = pipe->dest_ring->sw_index; + nentries_mask = pipe->dest_ring->nentries_mask; + + srng = &ab->hal.srng_list[pipe->status_ring->hal_ring_id]; + +spin_lock_bh (&srng->lock); + +ath12k_hal_srng_access_begin (ab, srng); + + desc =ath12k_hal_srng_dst_get_next_entry (ab, srng); +if (!desc) { + ret = -EIO ; + goto err; + } + + *nbytes =ath12k_hal_ce_dst_status_get_length (desc); +if (*nbytes ==0 ) { + ret = -EIO ; + goto err; + } + + *skb = pipe->dest_ring->skb[sw_index]; + pipe->dest_ring->skb[sw_index] =NULL ; + + sw_index =CE_RING_IDX_INCR (nentries_mask, sw_index); + pipe->dest_ring->sw_index = sw_index; + + pipe->rx_buf_needed++; +err: +ath12k_hal_srng_access_end (ab, srng); + +spin_unlock_bh (&srng->lock); + +spin_unlock_bh (&ab->ce.ce_lock); + +return ret; +} + +static void ath12k_ce_recv_process_cb (struct ath12k_ce_pipe *pipe) +{ +struct ath12k_base *ab = pipe->ab; +struct sk_buff *skb; +struct sk_buff_head list; +unsigned int nbytes, max_nbytes; +int ret; + +__skb_queue_head_init (&list); +while (ath12k_ce_completed_recv_next (pipe, &skb, &nbytes) ==0 ) { + max_nbytes = skb->len +skb_tailroom (skb); +dma_unmap_single (ab->dev,ATH12K_SKB_RXCB (skb)->paddr, + max_nbytes,DMA_FROM_DEVICE ); + +if (unlikely (max_nbytes < nbytes)) { +ath12k_warn (ab,"rxed more than expected (nbytes %d, max %d)" , + nbytes, max_nbytes); +dev_kfree_skb_any (skb); +continue ; + } + +skb_put (skb, nbytes); +__skb_queue_tail (&list, skb); + } + +while ((skb =__skb_dequeue (&list))) { +ath12k_dbg (ab,ATH12K_DBG_AHB ,"rx ce pipe %d len %d\n" , + pipe->pipe_num, skb->len); + pipe->recv_cb (ab, skb); + } + + ret =ath12k_ce_rx_post_pipe (pipe); +if (ret && ret != -ENOSPC ) { +ath12k_warn (ab,"failed to post rx buf to pipe: %d err: %d\n" , + pipe->pipe_num, ret); +mod_timer (&ab->rx_replenish_retry, + jiffies +ATH12K_CE_RX_POST_RETRY_JIFFIES ); + } +} + +static struct sk_buff *ath12k_ce_completed_send_next (struct ath12k_ce_pipe *pipe) +{ +struct ath12k_base *ab = pipe->ab; +struct hal_ce_srng_src_desc *desc; +struct hal_srng *srng; +unsigned int sw_index; +unsigned int nentries_mask; +struct sk_buff *skb; + +spin_lock_bh (&ab->ce.ce_lock); + + sw_index = pipe->src_ring->sw_index; + nentries_mask = pipe->src_ring->nentries_mask; + + srng = &ab->hal.srng_list[pipe->src_ring->hal_ring_id]; + +spin_lock_bh (&srng->lock); + +ath12k_hal_srng_access_begin (ab, srng); + + desc =ath12k_hal_srng_src_reap_next (ab, srng); +if (!desc) { + skb =ERR_PTR (-EIO ); + goto err_unlock; + } + + skb = pipe->src_ring->skb[sw_index]; + + pipe->src_ring->skb[sw_index] =NULL ; + + sw_index =CE_RING_IDX_INCR (nentries_mask, sw_index); + pipe->src_ring->sw_index = sw_index; + +err_unlock: +spin_unlock_bh (&srng->lock); + +spin_unlock_bh (&ab->ce.ce_lock); + +return skb; +} + +static void ath12k_ce_send_done_cb (struct ath12k_ce_pipe *pipe) +{ +struct ath12k_base *ab = pipe->ab; +struct sk_buff *skb; + +while (!IS_ERR (skb =ath12k_ce_completed_send_next (pipe))) { +if (!skb) +continue ; + +dma_unmap_single (ab->dev,ATH12K_SKB_CB (skb)->paddr, skb->len, +DMA_TO_DEVICE ); +dev_kfree_skb_any (skb); + } +} + +static void ath12k_ce_srng_msi_ring_params_setup (struct ath12k_base *ab,u32 ce_id, +struct hal_srng_params *ring_params) +{ +u32 msi_data_start; +u32 msi_data_count, msi_data_idx; +u32 msi_irq_start; +u32 addr_lo; +u32 addr_hi; +int ret; + + ret =ath12k_hif_get_user_msi_vector (ab,"CE" , + &msi_data_count, &msi_data_start, + &msi_irq_start); + +if (ret) +return ; + +ath12k_hif_get_msi_address (ab, &addr_lo, &addr_hi); +ath12k_hif_get_ce_msi_idx (ab, ce_id, &msi_data_idx); + + ring_params->msi_addr = addr_lo; + ring_params->msi_addr |= (dma_addr_t)(((uint64_t )addr_hi) <<32 ); + ring_params->msi_data = (msi_data_idx % msi_data_count) + msi_data_start; + ring_params->flags |=HAL_SRNG_FLAGS_MSI_INTR ; +} + +static int ath12k_ce_init_ring (struct ath12k_base *ab, +struct ath12k_ce_ring *ce_ring, +int ce_id,enum hal_ring_type type) +{ +struct hal_srng_params params = {0 }; +int ret; + + params.ring_base_paddr = ce_ring->base_addr_ce_space; + params.ring_base_vaddr = ce_ring->base_addr_owner_space; + params.num_entries = ce_ring->nentries; + +if (!(CE_ATTR_DIS_INTR & ab->hw_params->host_ce_config[ce_id].flags)) +ath12k_ce_srng_msi_ring_params_setup (ab, ce_id, ¶ms); + +switch (type) { +case HAL_CE_SRC : +if (!(CE_ATTR_DIS_INTR & ab->hw_params->host_ce_config[ce_id].flags)) + params.intr_batch_cntr_thres_entries =1 ; +break ; +case HAL_CE_DST : + params.max_buffer_len = ab->hw_params->host_ce_config[ce_id].src_sz_max; +if (!(ab->hw_params->host_ce_config[ce_id].flags &CE_ATTR_DIS_INTR )) { + params.intr_timer_thres_us =1024 ; + params.flags |=HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN ; + params.low_threshold = ce_ring->nentries -3 ; + } +break ; +case HAL_CE_DST_STATUS : +if (!(ab->hw_params->host_ce_config[ce_id].flags &CE_ATTR_DIS_INTR )) { + params.intr_batch_cntr_thres_entries =1 ; + params.intr_timer_thres_us =0x1000 ; + } +break ; +default : +ath12k_warn (ab,"Invalid CE ring type %d\n" , type); +return -EINVAL ; + } + +/* TODO: Init other params needed by HAL to init the ring */ + + ret =ath12k_hal_srng_setup (ab, type, ce_id,0 , ¶ms); +if (ret <0 ) { +ath12k_warn (ab,"failed to setup srng: %d ring_id %d\n" , + ret, ce_id); +return ret; + } + + ce_ring->hal_ring_id = ret; + +return 0 ; +} + +static struct ath12k_ce_ring * +ath12k_ce_alloc_ring (struct ath12k_base *ab,int nentries,int desc_sz) +{ +struct ath12k_ce_ring *ce_ring; +dma_addr_t base_addr; + + ce_ring =kzalloc (struct_size (ce_ring, skb, nentries),GFP_KERNEL ); +if (!ce_ring) +return ERR_PTR (-ENOMEM ); + + ce_ring->nentries = nentries; + ce_ring->nentries_mask = nentries -1 ; + +/* Legacy platforms that do not support cache +* coherent DMA are unsupported +*/ + ce_ring->base_addr_owner_space_unaligned = +dma_alloc_coherent (ab->dev, + nentries * desc_sz +CE_DESC_RING_ALIGN , + &base_addr,GFP_KERNEL ); +if (!ce_ring->base_addr_owner_space_unaligned) { +kfree (ce_ring); +return ERR_PTR (-ENOMEM ); + } + + ce_ring->base_addr_ce_space_unaligned = base_addr; + + ce_ring->base_addr_owner_space = +PTR_ALIGN (ce_ring->base_addr_owner_space_unaligned, +CE_DESC_RING_ALIGN ); + + ce_ring->base_addr_ce_space =ALIGN (ce_ring->base_addr_ce_space_unaligned, +CE_DESC_RING_ALIGN ); + +return ce_ring; +} + +static int ath12k_ce_alloc_pipe (struct ath12k_base *ab,int ce_id) +{ +struct ath12k_ce_pipe *pipe = &ab->ce.ce_pipe[ce_id]; +const struct ce_attr *attr = &ab->hw_params->host_ce_config[ce_id]; +struct ath12k_ce_ring *ring; +int nentries; +int desc_sz; + + pipe->attr_flags = attr->flags; + +if (attr->src_nentries) { + pipe->send_cb = ath12k_ce_send_done_cb; + nentries =roundup_pow_of_two (attr->src_nentries); + desc_sz =ath12k_hal_ce_get_desc_size (HAL_CE_DESC_SRC ); + ring =ath12k_ce_alloc_ring (ab, nentries, desc_sz); +if (IS_ERR (ring)) +return PTR_ERR (ring); + pipe->src_ring = ring; + } + +if (attr->dest_nentries) { + pipe->recv_cb = attr->recv_cb; + nentries =roundup_pow_of_two (attr->dest_nentries); + desc_sz =ath12k_hal_ce_get_desc_size (HAL_CE_DESC_DST ); + ring =ath12k_ce_alloc_ring (ab, nentries, desc_sz); +if (IS_ERR (ring)) +return PTR_ERR (ring); + pipe->dest_ring = ring; + + desc_sz =ath12k_hal_ce_get_desc_size (HAL_CE_DESC_DST_STATUS ); + ring =ath12k_ce_alloc_ring (ab, nentries, desc_sz); +if (IS_ERR (ring)) +return PTR_ERR (ring); + pipe->status_ring = ring; + } + +return 0 ; +} + +void ath12k_ce_per_engine_service (struct ath12k_base *ab,u16 ce_id) +{ +struct ath12k_ce_pipe *pipe = &ab->ce.ce_pipe[ce_id]; + +if (pipe->send_cb) + pipe->send_cb (pipe); + +if (pipe->recv_cb) +ath12k_ce_recv_process_cb (pipe); +} + +void ath12k_ce_poll_send_completed (struct ath12k_base *ab,u8 pipe_id) +{ +struct ath12k_ce_pipe *pipe = &ab->ce.ce_pipe[pipe_id]; + +if ((pipe->attr_flags &CE_ATTR_DIS_INTR ) && pipe->send_cb) + pipe->send_cb (pipe); +} + +int ath12k_ce_send (struct ath12k_base *ab,struct sk_buff *skb,u8 pipe_id, +u16 transfer_id) +{ +struct ath12k_ce_pipe *pipe = &ab->ce.ce_pipe[pipe_id]; +struct hal_ce_srng_src_desc *desc; +struct hal_srng *srng; +unsigned int write_index, sw_index; +unsigned int nentries_mask; +int ret =0 ; +u8 byte_swap_data =0 ; +int num_used; + +/* Check if some entries could be regained by handling tx completion if +* the CE has interrupts disabled and the used entries is more than the +* defined usage threshold. +*/ +if (pipe->attr_flags &CE_ATTR_DIS_INTR ) { +spin_lock_bh (&ab->ce.ce_lock); + write_index = pipe->src_ring->write_index; + + sw_index = pipe->src_ring->sw_index; + +if (write_index >= sw_index) + num_used = write_index - sw_index; +else + num_used = pipe->src_ring->nentries - sw_index + + write_index; + +spin_unlock_bh (&ab->ce.ce_lock); + +if (num_used >ATH12K_CE_USAGE_THRESHOLD ) +ath12k_ce_poll_send_completed (ab, pipe->pipe_num); + } + +if (test_bit (ATH12K_FLAG_CRASH_FLUSH , &ab->dev_flags)) +return -ESHUTDOWN ; + +spin_lock_bh (&ab->ce.ce_lock); + + write_index = pipe->src_ring->write_index; + nentries_mask = pipe->src_ring->nentries_mask; + + srng = &ab->hal.srng_list[pipe->src_ring->hal_ring_id]; + +spin_lock_bh (&srng->lock); + +ath12k_hal_srng_access_begin (ab, srng); + +if (unlikely (ath12k_hal_srng_src_num_free (ab, srng, false) <1 )) { +ath12k_hal_srng_access_end (ab, srng); + ret = -ENOBUFS ; + goto unlock; + } + + desc =ath12k_hal_srng_src_get_next_reaped (ab, srng); +if (!desc) { +ath12k_hal_srng_access_end (ab, srng); + ret = -ENOBUFS ; + goto unlock; + } + +if (pipe->attr_flags &CE_ATTR_BYTE_SWAP_DATA ) + byte_swap_data =1 ; + +ath12k_hal_ce_src_set_desc (desc,ATH12K_SKB_CB (skb)->paddr, + skb->len, transfer_id, byte_swap_data); + + pipe->src_ring->skb[write_index] = skb; + pipe->src_ring->write_index =CE_RING_IDX_INCR (nentries_mask, + write_index); + +ath12k_hal_srng_access_end (ab, srng); + +unlock: +spin_unlock_bh (&srng->lock); + +spin_unlock_bh (&ab->ce.ce_lock); + +return ret; +} + +static void ath12k_ce_rx_pipe_cleanup (struct ath12k_ce_pipe *pipe) +{ +struct ath12k_base *ab = pipe->ab; +struct ath12k_ce_ring *ring = pipe->dest_ring; +struct sk_buff *skb; +int i; + +if (!(ring && pipe->buf_sz)) +return ; + +for (i =0 ; i < ring->nentries; i++) { + skb = ring->skb[i]; +if (!skb) +continue ; + + ring->skb[i] =NULL ; +dma_unmap_single (ab->dev,ATH12K_SKB_RXCB (skb)->paddr, + skb->len +skb_tailroom (skb),DMA_FROM_DEVICE ); +dev_kfree_skb_any (skb); + } +} + +void ath12k_ce_cleanup_pipes (struct ath12k_base *ab) +{ +struct ath12k_ce_pipe *pipe; +int pipe_num; + +for (pipe_num =0 ; pipe_num < ab->hw_params->ce_count; pipe_num++) { + pipe = &ab->ce.ce_pipe[pipe_num]; +ath12k_ce_rx_pipe_cleanup (pipe); + +/* Cleanup any src CE's which have interrupts disabled */ +ath12k_ce_poll_send_completed (ab, pipe_num); + +/* NOTE: Should we also clean up tx buffer in all pipes? */ + } +} + +void ath12k_ce_rx_post_buf (struct ath12k_base *ab) +{ +struct ath12k_ce_pipe *pipe; +int i; +int ret; + +for (i =0 ; i < ab->hw_params->ce_count; i++) { + pipe = &ab->ce.ce_pipe[i]; + ret =ath12k_ce_rx_post_pipe (pipe); +if (ret) { +if (ret == -ENOSPC ) +continue ; + +ath12k_warn (ab,"failed to post rx buf to pipe: %d err: %d\n" , + i, ret); +mod_timer (&ab->rx_replenish_retry, + jiffies +ATH12K_CE_RX_POST_RETRY_JIFFIES ); + +return ; + } + } +} + +void ath12k_ce_rx_replenish_retry (struct timer_list *t) +{ +struct ath12k_base *ab =from_timer (ab, t, rx_replenish_retry); + +ath12k_ce_rx_post_buf (ab); +} + +static void ath12k_ce_shadow_config (struct ath12k_base *ab) +{ +int i; + +for (i =0 ; i < ab->hw_params->ce_count; i++) { +if (ab->hw_params->host_ce_config[i].src_nentries) +ath12k_hal_srng_update_shadow_config (ab,HAL_CE_SRC , i); + +if (ab->hw_params->host_ce_config[i].dest_nentries) { +ath12k_hal_srng_update_shadow_config (ab,HAL_CE_DST , i); +ath12k_hal_srng_update_shadow_config (ab,HAL_CE_DST_STATUS , i); + } + } +} + +void ath12k_ce_get_shadow_config (struct ath12k_base *ab, +u32 **shadow_cfg,u32 *shadow_cfg_len) +{ +if (!ab->hw_params->supports_shadow_regs) +return ; + +ath12k_hal_srng_get_shadow_config (ab, shadow_cfg, shadow_cfg_len); + +/* shadow is already configured */ +if (*shadow_cfg_len) +return ; + +/* shadow isn't configured yet, configure now. +* non-CE srngs are configured firstly, then +* all CE srngs. +*/ +ath12k_hal_srng_shadow_config (ab); +ath12k_ce_shadow_config (ab); + +/* get the shadow configuration */ +ath12k_hal_srng_get_shadow_config (ab, shadow_cfg, shadow_cfg_len); +} + +int ath12k_ce_init_pipes (struct ath12k_base *ab) +{ +struct ath12k_ce_pipe *pipe; +int i; +int ret; + +ath12k_ce_get_shadow_config (ab, &ab->qmi.ce_cfg.shadow_reg_v3, + &ab->qmi.ce_cfg.shadow_reg_v3_len); + +for (i =0 ; i < ab->hw_params->ce_count; i++) { + pipe = &ab->ce.ce_pipe[i]; + +if (pipe->src_ring) { + ret =ath12k_ce_init_ring (ab, pipe->src_ring, i, +HAL_CE_SRC ); +if (ret) { +ath12k_warn (ab,"failed to init src ring: %d\n" , + ret); +/* Should we clear any partial init */ +return ret; + } + + pipe->src_ring->write_index =0 ; + pipe->src_ring->sw_index =0 ; + } + +if (pipe->dest_ring) { + ret =ath12k_ce_init_ring (ab, pipe->dest_ring, i, +HAL_CE_DST ); +if (ret) { +ath12k_warn (ab,"failed to init dest ring: %d\n" , + ret); +/* Should we clear any partial init */ +return ret; + } + + pipe->rx_buf_needed = pipe->dest_ring->nentries ? + pipe->dest_ring->nentries -2 :0 ; + + pipe->dest_ring->write_index =0 ; + pipe->dest_ring->sw_index =0 ; + } + +if (pipe->status_ring) { + ret =ath12k_ce_init_ring (ab, pipe->status_ring, i, +HAL_CE_DST_STATUS ); +if (ret) { +ath12k_warn (ab,"failed to init dest status ing: %d\n" , + ret); +/* Should we clear any partial init */ +return ret; + } + + pipe->status_ring->write_index =0 ; + pipe->status_ring->sw_index =0 ; + } + } + +return 0 ; +} + +void ath12k_ce_free_pipes (struct ath12k_base *ab) +{ +struct ath12k_ce_pipe *pipe; +int desc_sz; +int i; + +for (i =0 ; i < ab->hw_params->ce_count; i++) { + pipe = &ab->ce.ce_pipe[i]; + +if (pipe->src_ring) { + desc_sz =ath12k_hal_ce_get_desc_size (HAL_CE_DESC_SRC ); +dma_free_coherent (ab->dev, + pipe->src_ring->nentries * desc_sz + +CE_DESC_RING_ALIGN , + pipe->src_ring->base_addr_owner_space, + pipe->src_ring->base_addr_ce_space); +kfree (pipe->src_ring); + pipe->src_ring =NULL ; + } + +if (pipe->dest_ring) { + desc_sz =ath12k_hal_ce_get_desc_size (HAL_CE_DESC_DST ); +dma_free_coherent (ab->dev, + pipe->dest_ring->nentries * desc_sz + +CE_DESC_RING_ALIGN , + pipe->dest_ring->base_addr_owner_space, + pipe->dest_ring->base_addr_ce_space); +kfree (pipe->dest_ring); + pipe->dest_ring =NULL ; + } + +if (pipe->status_ring) { + desc_sz = +ath12k_hal_ce_get_desc_size (HAL_CE_DESC_DST_STATUS ); +dma_free_coherent (ab->dev, + pipe->status_ring->nentries * desc_sz + +CE_DESC_RING_ALIGN , + pipe->status_ring->base_addr_owner_space, + pipe->status_ring->base_addr_ce_space); +kfree (pipe->status_ring); + pipe->status_ring =NULL ; + } + } +} + +int ath12k_ce_alloc_pipes (struct ath12k_base *ab) +{ +struct ath12k_ce_pipe *pipe; +int i; +int ret; +const struct ce_attr *attr; + +spin_lock_init (&ab->ce.ce_lock); + +for (i =0 ; i < ab->hw_params->ce_count; i++) { + attr = &ab->hw_params->host_ce_config[i]; + pipe = &ab->ce.ce_pipe[i]; + pipe->pipe_num = i; + pipe->ab = ab; + pipe->buf_sz = attr->src_sz_max; + + ret =ath12k_ce_alloc_pipe (ab, i); +if (ret) { +/* Free any parial successful allocation */ +ath12k_ce_free_pipes (ab); +return ret; + } + } + +return 0 ; +} + +int ath12k_ce_get_attr_flags (struct ath12k_base *ab,int ce_id) +{ +if (ce_id >= ab->hw_params->ce_count) +return -EINVAL ; + +return ab->hw_params->host_ce_config[ce_id].flags; +}
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 4/50 wifi: ath12k: add ce.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/ce.h | 184 +++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+)
drivers/net/wireless/ath/ath12k/ce.h new file +184 -0
@@ -0,0 +1,184 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#ifndef ATH12K_CE_H +#define ATH12K_CE_H + +#define CE_COUNT_MAX 16 + +/* Byte swap data words */ +#define CE_ATTR_BYTE_SWAP_DATA 2 + +/* no interrupt on copy completion */ +#define CE_ATTR_DIS_INTR 8 + +/* Host software's Copy Engine configuration. */ +#define CE_ATTR_FLAGS 0 + +/* Threshold to poll for tx completion in case of Interrupt disabled CE's */ +#define ATH12K_CE_USAGE_THRESHOLD 32 + +/* Directions for interconnect pipe configuration. +* These definitions may be used during configuration and are shared +* between Host and Target. +* +* Pipe Directions are relative to the Host, so PIPEDIR_IN means +* "coming IN over air through Target to Host" as with a WiFi Rx operation. +* Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air" +* as with a WiFi Tx operation. This is somewhat awkward for the "middle-man" +* Target since things that are "PIPEDIR_OUT" are coming IN to the Target +* over the interconnect. +*/ +#define PIPEDIR_NONE 0 +#define PIPEDIR_IN 1/* Target-->Host, WiFi Rx direction */ +#define PIPEDIR_OUT 2/* Host->Target, WiFi Tx direction */ +#define PIPEDIR_INOUT 3/* bidirectional */ +#define PIPEDIR_INOUT_H2H 4/* bidirectional, host to host */ + +/* CE address/mask */ +#define CE_HOST_IE_ADDRESS 0x00A1803C +#define CE_HOST_IE_2_ADDRESS 0x00A18040 +#define CE_HOST_IE_3_ADDRESS CE_HOST_IE_ADDRESS + +#define CE_HOST_IE_3_SHIFT 0xC + +#define CE_RING_IDX_INCR (nentries_mask, idx) (((idx) + 1) & (nentries_mask)) + +#define ATH12K_CE_RX_POST_RETRY_JIFFIES 50 + +struct ath12k_base ; + +/* Establish a mapping between a service/direction and a pipe. +* Configuration information for a Copy Engine pipe and services. +* Passed from Host to Target through QMI message and must be in +* little endian format. +*/ +struct service_to_pipe { +__le32 service_id; +__le32 pipedir; +__le32 pipenum; +}; + +/* Configuration information for a Copy Engine pipe. +* Passed from Host to Target through QMI message during startup (one per CE). +* +* NOTE: Structure is shared between Host software and Target firmware! +*/ +struct ce_pipe_config { +__le32 pipenum; +__le32 pipedir; +__le32 nentries; +__le32 nbytes_max; +__le32 flags; +__le32 reserved; +}; + +struct ce_attr { +/* CE_ATTR_* values */ +unsigned int flags; + +/* #entries in source ring - Must be a power of 2 */ +unsigned int src_nentries; + +/* Max source send size for this CE. +* This is also the minimum size of a destination buffer. +*/ +unsigned int src_sz_max; + +/* #entries in destination ring - Must be a power of 2 */ +unsigned int dest_nentries; + +void (*recv_cb)(struct ath12k_base *ab,struct sk_buff *skb); +}; + +#define CE_DESC_RING_ALIGN 8 + +struct ath12k_ce_ring { +/* Number of entries in this ring; must be power of 2 */ +unsigned int nentries; +unsigned int nentries_mask; + +/* For dest ring, this is the next index to be processed +* by software after it was/is received into. +* +* For src ring, this is the last descriptor that was sent +* and completion processed by software. +* +* Regardless of src or dest ring, this is an invariant +* (modulo ring size): +* write index >= read index >= sw_index +*/ +unsigned int sw_index; +/* cached copy */ +unsigned int write_index; + +/* Start of DMA-coherent area reserved for descriptors */ +/* Host address space */ +void *base_addr_owner_space_unaligned; +/* CE address space */ +u32 base_addr_ce_space_unaligned; + +/* Actual start of descriptors. +* Aligned to descriptor-size boundary. +* Points into reserved DMA-coherent area, above. +*/ +/* Host address space */ +void *base_addr_owner_space; + +/* CE address space */ +u32 base_addr_ce_space; + +/* HAL ring id */ +u32 hal_ring_id; + +/* keep last */ +struct sk_buff *skb[]; +}; + +struct ath12k_ce_pipe { +struct ath12k_base *ab; +u16 pipe_num; +unsigned int attr_flags; +unsigned int buf_sz; +unsigned int rx_buf_needed; + +void (*send_cb)(struct ath12k_ce_pipe *pipe); +void (*recv_cb)(struct ath12k_base *ab,struct sk_buff *skb); + +struct tasklet_struct intr_tq; +struct ath12k_ce_ring *src_ring; +struct ath12k_ce_ring *dest_ring; +struct ath12k_ce_ring *status_ring; +u64 timestamp; +}; + +struct ath12k_ce { +struct ath12k_ce_pipe ce_pipe[CE_COUNT_MAX ]; +/* Protects rings of all ce pipes */ +spinlock_t ce_lock; +struct ath12k_hp_update_timer hp_timer[CE_COUNT_MAX ]; +}; + +extern const struct ce_attr ath12k_host_ce_config_qcn9274[]; +extern const struct ce_attr ath12k_host_ce_config_wcn7850[]; + +void ath12k_ce_cleanup_pipes (struct ath12k_base *ab); +void ath12k_ce_rx_replenish_retry (struct timer_list *t); +void ath12k_ce_per_engine_service (struct ath12k_base *ab,u16 ce_id); +int ath12k_ce_send (struct ath12k_base *ab,struct sk_buff *skb,u8 pipe_id, +u16 transfer_id); +void ath12k_ce_rx_post_buf (struct ath12k_base *ab); +int ath12k_ce_init_pipes (struct ath12k_base *ab); +int ath12k_ce_alloc_pipes (struct ath12k_base *ab); +void ath12k_ce_free_pipes (struct ath12k_base *ab); +int ath12k_ce_get_attr_flags (struct ath12k_base *ab,int ce_id); +void ath12k_ce_poll_send_completed (struct ath12k_base *ab,u8 pipe_id); +int ath12k_ce_map_service_to_pipe (struct ath12k_base *ab,u16 service_id, +u8 *ul_pipe,u8 *dl_pipe); +int ath12k_ce_attr_attach (struct ath12k_base *ab); +void ath12k_ce_get_shadow_config (struct ath12k_base *ab, +u32 **shadow_cfg,u32 *shadow_cfg_len); +#endif
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 5/50 wifi: ath12k: add core.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/core.c | 939 +++++++++++++++++++++++++++++++++ 1 file changed, 939 insertions(+)
drivers/net/wireless/ath/ath12k/core.c new file +939 -0
@@ -0,0 +1,939 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/remoteproc.h> +#include <linux/firmware.h> +#include <linux/of.h> +#include "core.h" +#include "dp_tx.h" +#include "dp_rx.h" +#include "debug.h" +#include "hif.h" + +unsigned int ath12k_debug_mask; +module_param_named (debug_mask, ath12k_debug_mask, uint,0644 ); +MODULE_PARM_DESC (debug_mask,"Debugging mask" ); + +int ath12k_core_suspend (struct ath12k_base *ab) +{ +int ret; + +if (!ab->hw_params->supports_suspend) +return -EOPNOTSUPP ; + +/* TODO: there can frames in queues so for now add delay as a hack. +* Need to implement to handle and remove this delay. +*/ +msleep (500 ); + + ret =ath12k_dp_rx_pktlog_stop (ab, true); +if (ret) { +ath12k_warn (ab,"failed to stop dp rx (and timer) pktlog during suspend: %d\n" , + ret); +return ret; + } + + ret =ath12k_dp_rx_pktlog_stop (ab, false); +if (ret) { +ath12k_warn (ab,"failed to stop dp rx pktlog during suspend: %d\n" , + ret); +return ret; + } + +ath12k_hif_irq_disable (ab); +ath12k_hif_ce_irq_disable (ab); + + ret =ath12k_hif_suspend (ab); +if (ret) { +ath12k_warn (ab,"failed to suspend hif: %d\n" , ret); +return ret; + } + +return 0 ; +} + +int ath12k_core_resume (struct ath12k_base *ab) +{ +int ret; + +if (!ab->hw_params->supports_suspend) +return -EOPNOTSUPP ; + + ret =ath12k_hif_resume (ab); +if (ret) { +ath12k_warn (ab,"failed to resume hif during resume: %d\n" , ret); +return ret; + } + +ath12k_hif_ce_irq_enable (ab); +ath12k_hif_irq_enable (ab); + + ret =ath12k_dp_rx_pktlog_start (ab); +if (ret) { +ath12k_warn (ab,"failed to start rx pktlog during resume: %d\n" , + ret); +return ret; + } + +return 0 ; +} + +static int ath12k_core_create_board_name (struct ath12k_base *ab,char *name, +size_t name_len) +{ +/* strlen(',variant=') + strlen(ab->qmi.target.bdf_ext) */ +char variant[9 +ATH12K_QMI_BDF_EXT_STR_LENGTH ] = {0 }; + +if (ab->qmi.target.bdf_ext[0 ] !='\0' ) +scnprintf (variant,sizeof (variant),",variant=%s" , + ab->qmi.target.bdf_ext); + +scnprintf (name, name_len, +"bus=%s,qmi-chip-id=%d,qmi-board-id=%d%s" , +ath12k_bus_str (ab->hif.bus), + ab->qmi.target.chip_id, + ab->qmi.target.board_id, variant); + +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"boot using board name '%s'\n" , name); + +return 0 ; +} + +const struct firmware *ath12k_core_firmware_request (struct ath12k_base *ab, +const char *file) +{ +const struct firmware *fw; +char path[100 ]; +int ret; + +if (!file) +return ERR_PTR (-ENOENT ); + +ath12k_core_create_firmware_path (ab, file, path,sizeof (path)); + + ret =firmware_request_nowarn (&fw, path, ab->dev); +if (ret) +return ERR_PTR (ret); + +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"boot firmware request %s size %zu\n" , + path, fw->size); + +return fw; +} + +void ath12k_core_free_bdf (struct ath12k_base *ab,struct ath12k_board_data *bd) +{ +if (!IS_ERR (bd->fw)) +release_firmware (bd->fw); + +memset (bd,0 ,sizeof (*bd)); +} + +static int ath12k_core_parse_bd_ie_board (struct ath12k_base *ab, +struct ath12k_board_data *bd, +const void *buf,size_t buf_len, +const char *boardname, +int bd_ie_type) +{ +const struct ath12k_fw_ie *hdr; +bool name_match_found; +int ret, board_ie_id; +size_t board_ie_len; +const void *board_ie_data; + + name_match_found = false; + +/* go through ATH12K_BD_IE_BOARD_ elements */ +while (buf_len >sizeof (struct ath12k_fw_ie )) { + hdr = buf; + board_ie_id =le32_to_cpu (hdr->id); + board_ie_len =le32_to_cpu (hdr->len); + board_ie_data = hdr->data; + + buf_len -=sizeof (*hdr); + buf +=sizeof (*hdr); + +if (buf_len <ALIGN (board_ie_len,4 )) { +ath12k_err (ab,"invalid ATH12K_BD_IE_BOARD length: %zu < %zu\n" , + buf_len,ALIGN (board_ie_len,4 )); + ret = -EINVAL ; + goto out; + } + +switch (board_ie_id) { +case ATH12K_BD_IE_BOARD_NAME : +ath12k_dbg_dump (ab,ATH12K_DBG_BOOT ,"board name" ,"" , + board_ie_data, board_ie_len); + +if (board_ie_len !=strlen (boardname)) +break ; + + ret =memcmp (board_ie_data, boardname,strlen (boardname)); +if (ret) +break ; + + name_match_found = true; +ath12k_dbg (ab,ATH12K_DBG_BOOT , +"boot found match for name '%s'" , + boardname); +break ; +case ATH12K_BD_IE_BOARD_DATA : +if (!name_match_found) +/* no match found */ +break ; + +ath12k_dbg (ab,ATH12K_DBG_BOOT , +"boot found board data for '%s'" , boardname); + + bd->data = board_ie_data; + bd->len = board_ie_len; + + ret =0 ; + goto out; +default : +ath12k_warn (ab,"unknown ATH12K_BD_IE_BOARD found: %d\n" , + board_ie_id); +break ; + } + +/* jump over the padding */ + board_ie_len =ALIGN (board_ie_len,4 ); + + buf_len -= board_ie_len; + buf += board_ie_len; + } + +/* no match found */ + ret = -ENOENT ; + +out: +return ret; +} + +static int ath12k_core_fetch_board_data_api_n (struct ath12k_base *ab, +struct ath12k_board_data *bd, +const char *boardname) +{ +size_t len, magic_len; +const u8 *data; +char *filename, filepath[100 ]; +size_t ie_len; +struct ath12k_fw_ie *hdr; +int ret, ie_id; + + filename =ATH12K_BOARD_API2_FILE ; + +if (!bd->fw) + bd->fw =ath12k_core_firmware_request (ab, filename); + +if (IS_ERR (bd->fw)) +return PTR_ERR (bd->fw); + + data = bd->fw->data; + len = bd->fw->size; + +ath12k_core_create_firmware_path (ab, filename, + filepath,sizeof (filepath)); + +/* magic has extra null byte padded */ + magic_len =strlen (ATH12K_BOARD_MAGIC ) +1 ; +if (len < magic_len) { +ath12k_err (ab,"failed to find magic value in %s, file too short: %zu\n" , + filepath, len); + ret = -EINVAL ; + goto err; + } + +if (memcmp (data,ATH12K_BOARD_MAGIC , magic_len)) { +ath12k_err (ab,"found invalid board magic\n" ); + ret = -EINVAL ; + goto err; + } + +/* magic is padded to 4 bytes */ + magic_len =ALIGN (magic_len,4 ); +if (len < magic_len) { +ath12k_err (ab,"failed: %s too small to contain board data, len: %zu\n" , + filepath, len); + ret = -EINVAL ; + goto err; + } + + data += magic_len; + len -= magic_len; + +while (len >sizeof (struct ath12k_fw_ie )) { + hdr = (struct ath12k_fw_ie *)data; + ie_id =le32_to_cpu (hdr->id); + ie_len =le32_to_cpu (hdr->len); + + len -=sizeof (*hdr); + data = hdr->data; + +if (len <ALIGN (ie_len,4 )) { +ath12k_err (ab,"invalid length for board ie_id %d ie_len %zu len %zu\n" , + ie_id, ie_len, len); + ret = -EINVAL ; + goto err; + } + +switch (ie_id) { +case ATH12K_BD_IE_BOARD : + ret =ath12k_core_parse_bd_ie_board (ab, bd, data, + ie_len, + boardname, +ATH12K_BD_IE_BOARD ); +if (ret == -ENOENT ) +/* no match found, continue */ +break ; +else if (ret) +/* there was an error, bail out */ + goto err; +/* either found or error, so stop searching */ + goto out; + } + +/* jump over the padding */ + ie_len =ALIGN (ie_len,4 ); + + len -= ie_len; + data += ie_len; + } + +out: +if (!bd->data || !bd->len) { +ath12k_err (ab, +"failed to fetch board data for %s from %s\n" , + boardname, filepath); + ret = -ENODATA ; + goto err; + } + +return 0 ; + +err: +ath12k_core_free_bdf (ab, bd); +return ret; +} + +int ath12k_core_fetch_board_data_api_1 (struct ath12k_base *ab, +struct ath12k_board_data *bd, +char *filename) +{ + bd->fw =ath12k_core_firmware_request (ab, filename); +if (IS_ERR (bd->fw)) +return PTR_ERR (bd->fw); + + bd->data = bd->fw->data; + bd->len = bd->fw->size; + +return 0 ; +} + +#define BOARD_NAME_SIZE 100 +int ath12k_core_fetch_bdf (struct ath12k_base *ab,struct ath12k_board_data *bd) +{ +char boardname[BOARD_NAME_SIZE ]; +int ret; + + ret =ath12k_core_create_board_name (ab, boardname,BOARD_NAME_SIZE ); +if (ret) { +ath12k_err (ab,"failed to create board name: %d" , ret); +return ret; + } + + ab->bd_api =2 ; + ret =ath12k_core_fetch_board_data_api_n (ab, bd, boardname); +if (!ret) + goto success; + + ab->bd_api =1 ; + ret =ath12k_core_fetch_board_data_api_1 (ab, bd,ATH12K_DEFAULT_BOARD_FILE ); +if (ret) { +ath12k_err (ab,"failed to fetch board-2.bin or board.bin from %s\n" , + ab->hw_params->fw.dir); +return ret; + } + +success: +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"using board api %d\n" , ab->bd_api); +return 0 ; +} + +static void ath12k_core_stop (struct ath12k_base *ab) +{ +if (!test_bit (ATH12K_FLAG_CRASH_FLUSH , &ab->dev_flags)) +ath12k_qmi_firmware_stop (ab); + +ath12k_hif_stop (ab); +ath12k_wmi_detach (ab); +ath12k_dp_rx_pdev_reo_cleanup (ab); + +/* De-Init of components as needed */ +} + +static int ath12k_core_soc_create (struct ath12k_base *ab) +{ +int ret; + + ret =ath12k_qmi_init_service (ab); +if (ret) { +ath12k_err (ab,"failed to initialize qmi :%d\n" , ret); +return ret; + } + + ret =ath12k_hif_power_up (ab); +if (ret) { +ath12k_err (ab,"failed to power up :%d\n" , ret); + goto err_qmi_deinit; + } + +return 0 ; + +err_qmi_deinit: +ath12k_qmi_deinit_service (ab); +return ret; +} + +static void ath12k_core_soc_destroy (struct ath12k_base *ab) +{ +ath12k_dp_free (ab); +ath12k_reg_free (ab); +ath12k_qmi_deinit_service (ab); +} + +static int ath12k_core_pdev_create (struct ath12k_base *ab) +{ +int ret; + + ret =ath12k_mac_register (ab); +if (ret) { +ath12k_err (ab,"failed register the radio with mac80211: %d\n" , ret); +return ret; + } + + ret =ath12k_dp_pdev_alloc (ab); +if (ret) { +ath12k_err (ab,"failed to attach DP pdev: %d\n" , ret); + goto err_mac_unregister; + } + +return 0 ; + +err_mac_unregister: +ath12k_mac_unregister (ab); + +return ret; +} + +static void ath12k_core_pdev_destroy (struct ath12k_base *ab) +{ +ath12k_mac_unregister (ab); +ath12k_hif_irq_disable (ab); +ath12k_dp_pdev_free (ab); +} + +static int ath12k_core_start (struct ath12k_base *ab, +enum ath12k_firmware_mode mode) +{ +int ret; + + ret =ath12k_wmi_attach (ab); +if (ret) { +ath12k_err (ab,"failed to attach wmi: %d\n" , ret); +return ret; + } + + ret =ath12k_htc_init (ab); +if (ret) { +ath12k_err (ab,"failed to init htc: %d\n" , ret); + goto err_wmi_detach; + } + + ret =ath12k_hif_start (ab); +if (ret) { +ath12k_err (ab,"failed to start HIF: %d\n" , ret); + goto err_wmi_detach; + } + + ret =ath12k_htc_wait_target (&ab->htc); +if (ret) { +ath12k_err (ab,"failed to connect to HTC: %d\n" , ret); + goto err_hif_stop; + } + + ret =ath12k_dp_htt_connect (&ab->dp); +if (ret) { +ath12k_err (ab,"failed to connect to HTT: %d\n" , ret); + goto err_hif_stop; + } + + ret =ath12k_wmi_connect (ab); +if (ret) { +ath12k_err (ab,"failed to connect wmi: %d\n" , ret); + goto err_hif_stop; + } + + ret =ath12k_htc_start (&ab->htc); +if (ret) { +ath12k_err (ab,"failed to start HTC: %d\n" , ret); + goto err_hif_stop; + } + + ret =ath12k_wmi_wait_for_service_ready (ab); +if (ret) { +ath12k_err (ab,"failed to receive wmi service ready event: %d\n" , + ret); + goto err_hif_stop; + } + + ret =ath12k_mac_allocate (ab); +if (ret) { +ath12k_err (ab,"failed to create new hw device with mac80211 :%d\n" , + ret); + goto err_hif_stop; + } + +ath12k_dp_cc_config (ab); + +ath12k_dp_pdev_pre_alloc (ab); + + ret =ath12k_dp_rx_pdev_reo_setup (ab); +if (ret) { +ath12k_err (ab,"failed to initialize reo destination rings: %d\n" , ret); + goto err_mac_destroy; + } + + ret =ath12k_wmi_cmd_init (ab); +if (ret) { +ath12k_err (ab,"failed to send wmi init cmd: %d\n" , ret); + goto err_reo_cleanup; + } + + ret =ath12k_wmi_wait_for_unified_ready (ab); +if (ret) { +ath12k_err (ab,"failed to receive wmi unified ready event: %d\n" , + ret); + goto err_reo_cleanup; + } + +/* put hardware to DBS mode */ +if (ab->hw_params->single_pdev_only) { + ret =ath12k_wmi_set_hw_mode (ab,WMI_HOST_HW_MODE_DBS ); +if (ret) { +ath12k_err (ab,"failed to send dbs mode: %d\n" , ret); + goto err_reo_cleanup; + } + } + + ret =ath12k_dp_tx_htt_h2t_ver_req_msg (ab); +if (ret) { +ath12k_err (ab,"failed to send htt version request message: %d\n" , + ret); + goto err_reo_cleanup; + } + +return 0 ; + +err_reo_cleanup: +ath12k_dp_rx_pdev_reo_cleanup (ab); +err_mac_destroy: +ath12k_mac_destroy (ab); +err_hif_stop: +ath12k_hif_stop (ab); +err_wmi_detach: +ath12k_wmi_detach (ab); +return ret; +} + +static int ath12k_core_start_firmware (struct ath12k_base *ab, +enum ath12k_firmware_mode mode) +{ +int ret; + +ath12k_ce_get_shadow_config (ab, &ab->qmi.ce_cfg.shadow_reg_v3, + &ab->qmi.ce_cfg.shadow_reg_v3_len); + + ret =ath12k_qmi_firmware_start (ab, mode); +if (ret) { +ath12k_err (ab,"failed to send firmware start: %d\n" , ret); +return ret; + } + +return ret; +} + +int ath12k_core_qmi_firmware_ready (struct ath12k_base *ab) +{ +int ret; + + ret =ath12k_core_start_firmware (ab,ATH12K_FIRMWARE_MODE_NORMAL ); +if (ret) { +ath12k_err (ab,"failed to start firmware: %d\n" , ret); +return ret; + } + + ret =ath12k_ce_init_pipes (ab); +if (ret) { +ath12k_err (ab,"failed to initialize CE: %d\n" , ret); + goto err_firmware_stop; + } + + ret =ath12k_dp_alloc (ab); +if (ret) { +ath12k_err (ab,"failed to init DP: %d\n" , ret); + goto err_firmware_stop; + } + +mutex_lock (&ab->core_lock); + ret =ath12k_core_start (ab,ATH12K_FIRMWARE_MODE_NORMAL ); +if (ret) { +ath12k_err (ab,"failed to start core: %d\n" , ret); + goto err_dp_free; + } + + ret =ath12k_core_pdev_create (ab); +if (ret) { +ath12k_err (ab,"failed to create pdev core: %d\n" , ret); + goto err_core_stop; + } +ath12k_hif_irq_enable (ab); +mutex_unlock (&ab->core_lock); + +return 0 ; + +err_core_stop: +ath12k_core_stop (ab); +ath12k_mac_destroy (ab); +err_dp_free: +ath12k_dp_free (ab); +mutex_unlock (&ab->core_lock); +err_firmware_stop: +ath12k_qmi_firmware_stop (ab); + +return ret; +} + +static int ath12k_core_reconfigure_on_crash (struct ath12k_base *ab) +{ +int ret; + +mutex_lock (&ab->core_lock); +ath12k_hif_irq_disable (ab); +ath12k_dp_pdev_free (ab); +ath12k_hif_stop (ab); +ath12k_wmi_detach (ab); +ath12k_dp_rx_pdev_reo_cleanup (ab); +mutex_unlock (&ab->core_lock); + +ath12k_dp_free (ab); +ath12k_hal_srng_deinit (ab); + + ab->free_vdev_map = (1LL << (ab->num_radios *TARGET_NUM_VDEVS )) -1 ; + + ret =ath12k_hal_srng_init (ab); +if (ret) +return ret; + +clear_bit (ATH12K_FLAG_CRASH_FLUSH , &ab->dev_flags); + + ret =ath12k_core_qmi_firmware_ready (ab); +if (ret) + goto err_hal_srng_deinit; + +clear_bit (ATH12K_FLAG_RECOVERY , &ab->dev_flags); + +return 0 ; + +err_hal_srng_deinit: +ath12k_hal_srng_deinit (ab); +return ret; +} + +void ath12k_core_halt (struct ath12k *ar) +{ +struct ath12k_base *ab = ar->ab; + +lockdep_assert_held (&ar->conf_mutex); + + ar->num_created_vdevs =0 ; + ar->allocated_vdev_map =0 ; + +ath12k_mac_scan_finish (ar); +ath12k_mac_peer_cleanup_all (ar); +cancel_delayed_work_sync (&ar->scan.timeout); +cancel_work_sync (&ar->regd_update_work); + +rcu_assign_pointer (ab->pdevs_active[ar->pdev_idx],NULL ); +synchronize_rcu (); +INIT_LIST_HEAD (&ar->arvifs); +idr_init (&ar->txmgmt_idr); +} + +static void ath12k_core_pre_reconfigure_recovery (struct ath12k_base *ab) +{ +struct ath12k *ar; +struct ath12k_pdev *pdev; +int i; + +spin_lock_bh (&ab->base_lock); + ab->stats.fw_crash_counter++; +spin_unlock_bh (&ab->base_lock); + +for (i =0 ; i < ab->num_radios; i++) { + pdev = &ab->pdevs[i]; + ar = pdev->ar; +if (!ar || ar->state ==ATH12K_STATE_OFF ) +continue ; + +ieee80211_stop_queues (ar->hw); +ath12k_mac_drain_tx (ar); +complete (&ar->scan.started); +complete (&ar->scan.completed); +complete (&ar->peer_assoc_done); +complete (&ar->peer_delete_done); +complete (&ar->install_key_done); +complete (&ar->vdev_setup_done); +complete (&ar->vdev_delete_done); +complete (&ar->bss_survey_done); + +wake_up (&ar->dp.tx_empty_waitq); +idr_for_each (&ar->txmgmt_idr, + ath12k_mac_tx_mgmt_pending_free, ar); +idr_destroy (&ar->txmgmt_idr); + } + +wake_up (&ab->wmi_ab.tx_credits_wq); +wake_up (&ab->peer_mapping_wq); +} + +static void ath12k_core_post_reconfigure_recovery (struct ath12k_base *ab) +{ +struct ath12k *ar; +struct ath12k_pdev *pdev; +int i; + +for (i =0 ; i < ab->num_radios; i++) { + pdev = &ab->pdevs[i]; + ar = pdev->ar; +if (!ar || ar->state ==ATH12K_STATE_OFF ) +continue ; + +mutex_lock (&ar->conf_mutex); + +switch (ar->state) { +case ATH12K_STATE_ON : + ar->state =ATH12K_STATE_RESTARTING ; +ath12k_core_halt (ar); +ieee80211_restart_hw (ar->hw); +break ; +case ATH12K_STATE_OFF : +ath12k_warn (ab, +"cannot restart radio %d that hasn't been started\n" , + i); +break ; +case ATH12K_STATE_RESTARTING : +break ; +case ATH12K_STATE_RESTARTED : + ar->state =ATH12K_STATE_WEDGED ; + fallthrough; +case ATH12K_STATE_WEDGED : +ath12k_warn (ab, +"device is wedged, will not restart radio %d\n" , i); +break ; + } +mutex_unlock (&ar->conf_mutex); + } +complete (&ab->driver_recovery); +} + +static void ath12k_core_restart (struct work_struct *work) +{ + struct ath12k_base *ab = container_of(work, struct ath12k_base, restart_work); +int ret; + +if (!ab->is_reset) +ath12k_core_pre_reconfigure_recovery (ab); + + ret =ath12k_core_reconfigure_on_crash (ab); +if (ret) { +ath12k_err (ab,"failed to reconfigure driver on crash recovery\n" ); +return ; + } + +if (ab->is_reset) +complete_all (&ab->reconfigure_complete); + +if (!ab->is_reset) +ath12k_core_post_reconfigure_recovery (ab); +} + +static void ath12k_core_reset (struct work_struct *work) +{ + struct ath12k_base *ab = container_of(work, struct ath12k_base, reset_work); +int reset_count, fail_cont_count; +long time_left; + +if (!(test_bit (ATH12K_FLAG_REGISTERED , &ab->dev_flags))) { +ath12k_warn (ab,"ignore reset dev flags 0x%lx\n" , ab->dev_flags); +return ; + } + +/* Sometimes the recovery will fail and then the next all recovery fail, +* this is to avoid infinite recovery since it can not recovery success +*/ + fail_cont_count =atomic_read (&ab->fail_cont_count); + +if (fail_cont_count >=ATH12K_RESET_MAX_FAIL_COUNT_FINAL ) +return ; + +if (fail_cont_count >=ATH12K_RESET_MAX_FAIL_COUNT_FIRST && +time_before (jiffies, ab->reset_fail_timeout)) +return ; + + reset_count =atomic_inc_return (&ab->reset_count); + +if (reset_count >1 ) { +/* Sometimes it happened another reset worker before the previous one +* completed, then the second reset worker will destroy the previous one, +* thus below is to avoid that. +*/ +ath12k_warn (ab,"already resetting count %d\n" , reset_count); + +reinit_completion (&ab->reset_complete); + time_left =wait_for_completion_timeout (&ab->reset_complete, +ATH12K_RESET_TIMEOUT_HZ ); +if (time_left) { +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"to skip reset\n" ); +atomic_dec (&ab->reset_count); +return ; + } + + ab->reset_fail_timeout = jiffies +ATH12K_RESET_FAIL_TIMEOUT_HZ ; +/* Record the continuous recovery fail count when recovery failed*/ + fail_cont_count =atomic_inc_return (&ab->fail_cont_count); + } + +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"reset starting\n" ); + + ab->is_reset = true; +atomic_set (&ab->recovery_count,0 ); + +ath12k_core_pre_reconfigure_recovery (ab); + +reinit_completion (&ab->reconfigure_complete); +ath12k_core_post_reconfigure_recovery (ab); + +reinit_completion (&ab->recovery_start); +atomic_set (&ab->recovery_start_count,0 ); + +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"waiting recovery start...\n" ); + + time_left =wait_for_completion_timeout (&ab->recovery_start, +ATH12K_RECOVER_START_TIMEOUT_HZ ); + +ath12k_hif_power_down (ab); +ath12k_hif_power_up (ab); + +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"reset started\n" ); +} + +int ath12k_core_pre_init (struct ath12k_base *ab) +{ +int ret; + + ret =ath12k_hw_init (ab); +if (ret) { +ath12k_err (ab,"failed to init hw params: %d\n" , ret); +return ret; + } + +return 0 ; +} + +int ath12k_core_init (struct ath12k_base *ab) +{ +int ret; + + ret =ath12k_core_soc_create (ab); +if (ret) { +ath12k_err (ab,"failed to create soc core: %d\n" , ret); +return ret; + } + +return 0 ; +} + +void ath12k_core_deinit (struct ath12k_base *ab) +{ +mutex_lock (&ab->core_lock); + +ath12k_core_pdev_destroy (ab); +ath12k_core_stop (ab); + +mutex_unlock (&ab->core_lock); + +ath12k_hif_power_down (ab); +ath12k_mac_destroy (ab); +ath12k_core_soc_destroy (ab); +} + +void ath12k_core_free (struct ath12k_base *ab) +{ +destroy_workqueue (ab->workqueue_aux); +destroy_workqueue (ab->workqueue); +kfree (ab); +} + +struct ath12k_base *ath12k_core_alloc (struct device *dev,size_t priv_size, +enum ath12k_bus bus) +{ +struct ath12k_base *ab; + + ab =kzalloc (sizeof (*ab) + priv_size,GFP_KERNEL ); +if (!ab) +return NULL ; + +init_completion (&ab->driver_recovery); + + ab->workqueue =create_singlethread_workqueue ("ath12k_wq" ); +if (!ab->workqueue) + goto err_sc_free; + + ab->workqueue_aux =create_singlethread_workqueue ("ath12k_aux_wq" ); +if (!ab->workqueue_aux) + goto err_free_wq; + +mutex_init (&ab->core_lock); +spin_lock_init (&ab->base_lock); +init_completion (&ab->reset_complete); +init_completion (&ab->reconfigure_complete); +init_completion (&ab->recovery_start); + +INIT_LIST_HEAD (&ab->peers); +init_waitqueue_head (&ab->peer_mapping_wq); +init_waitqueue_head (&ab->wmi_ab.tx_credits_wq); +INIT_WORK (&ab->restart_work, ath12k_core_restart); +INIT_WORK (&ab->reset_work, ath12k_core_reset); +timer_setup (&ab->rx_replenish_retry, ath12k_ce_rx_replenish_retry,0 ); +init_completion (&ab->htc_suspend); + + ab->dev = dev; + ab->hif.bus = bus; + +return ab; + +err_free_wq: +destroy_workqueue (ab->workqueue); +err_sc_free: +kfree (ab); +return NULL ; +} + +MODULE_DESCRIPTION ("Core module for Qualcomm Atheros 802.11be wireless LAN cards." ); +MODULE_LICENSE ("Dual BSD/GPL" );
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 7/50 wifi: ath12k: add dbring.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/dbring.c | 357 +++++++++++++++++++++++++++++++ 1 file changed, 357 insertions(+)
drivers/net/wireless/ath/ath12k/dbring.c new file +357 -0
@@ -0,0 +1,357 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2019-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include "core.h" +#include "debug.h" + +static int ath12k_dbring_bufs_replenish (struct ath12k *ar, +struct ath12k_dbring *ring, +struct ath12k_dbring_element *buff, +gfp_t gfp) +{ +struct ath12k_base *ab = ar->ab; +struct hal_srng *srng; +dma_addr_t paddr; +void *ptr_aligned, *ptr_unaligned, *desc; +int ret; +int buf_id; +u32 cookie; + + srng = &ab->hal.srng_list[ring->refill_srng.ring_id]; + +lockdep_assert_held (&srng->lock); + +ath12k_hal_srng_access_begin (ab, srng); + + ptr_unaligned = buff->payload; + ptr_aligned =PTR_ALIGN (ptr_unaligned, ring->buf_align); + paddr =dma_map_single (ab->dev, ptr_aligned, ring->buf_sz, +DMA_FROM_DEVICE ); + + ret =dma_mapping_error (ab->dev, paddr); +if (ret) + goto err; + +spin_lock_bh (&ring->idr_lock); + buf_id =idr_alloc (&ring->bufs_idr, buff,0 , ring->bufs_max, gfp); +spin_unlock_bh (&ring->idr_lock); +if (buf_id <0 ) { + ret = -ENOBUFS ; + goto err_dma_unmap; + } + + desc =ath12k_hal_srng_src_get_next_entry (ab, srng); +if (!desc) { + ret = -ENOENT ; + goto err_idr_remove; + } + + buff->paddr = paddr; + + cookie =u32_encode_bits (ar->pdev_idx,DP_RXDMA_BUF_COOKIE_PDEV_ID ) | +u32_encode_bits (buf_id,DP_RXDMA_BUF_COOKIE_BUF_ID ); + +ath12k_hal_rx_buf_addr_info_set (desc, paddr, cookie,0 ); + +ath12k_hal_srng_access_end (ab, srng); + +return 0 ; + +err_idr_remove: +spin_lock_bh (&ring->idr_lock); +idr_remove (&ring->bufs_idr, buf_id); +spin_unlock_bh (&ring->idr_lock); +err_dma_unmap: +dma_unmap_single (ab->dev, paddr, ring->buf_sz, +DMA_FROM_DEVICE ); +err: +ath12k_hal_srng_access_end (ab, srng); +return ret; +} + +static int ath12k_dbring_fill_bufs (struct ath12k *ar, +struct ath12k_dbring *ring, +gfp_t gfp) +{ +struct ath12k_dbring_element *buff; +struct hal_srng *srng; +struct ath12k_base *ab = ar->ab; +int num_remain, req_entries, num_free; +u32 align; +int size, ret; + + srng = &ab->hal.srng_list[ring->refill_srng.ring_id]; + +spin_lock_bh (&srng->lock); + + num_free =ath12k_hal_srng_src_num_free (ab, srng, true); + req_entries =min (num_free, ring->bufs_max); + num_remain = req_entries; + align = ring->buf_align; + size =sizeof (*buff) + ring->buf_sz + align -1 ; + +while (num_remain >0 ) { + buff =kzalloc (size, gfp); +if (!buff) +break ; + + ret =ath12k_dbring_bufs_replenish (ar, ring, buff, gfp); +if (ret) { +ath12k_warn (ab,"failed to replenish db ring num_remain %d req_ent %d\n" , + num_remain, req_entries); +kfree (buff); +break ; + } + num_remain--; + } + +spin_unlock_bh (&srng->lock); + +return num_remain; +} + +int ath12k_dbring_wmi_cfg_setup (struct ath12k *ar, +struct ath12k_dbring *ring, +enum wmi_direct_buffer_module id) +{ +struct ath12k_wmi_pdev_dma_ring_cfg_arg arg = {0 }; +int ret; + +if (id >=WMI_DIRECT_BUF_MAX ) +return -EINVAL ; + + arg.pdev_id =DP_SW2HW_MACID (ring->pdev_id); + arg.module_id = id; + arg.base_paddr_lo =lower_32_bits (ring->refill_srng.paddr); + arg.base_paddr_hi =upper_32_bits (ring->refill_srng.paddr); + arg.head_idx_paddr_lo =lower_32_bits (ring->hp_addr); + arg.head_idx_paddr_hi =upper_32_bits (ring->hp_addr); + arg.tail_idx_paddr_lo =lower_32_bits (ring->tp_addr); + arg.tail_idx_paddr_hi =upper_32_bits (ring->tp_addr); + arg.num_elems = ring->bufs_max; + arg.buf_size = ring->buf_sz; + arg.num_resp_per_event = ring->num_resp_per_event; + arg.event_timeout_ms = ring->event_timeout_ms; + + ret =ath12k_wmi_pdev_dma_ring_cfg (ar, &arg); +if (ret) { +ath12k_warn (ar->ab,"failed to setup db ring cfg\n" ); +return ret; + } + +return 0 ; +} + +int ath12k_dbring_set_cfg (struct ath12k *ar,struct ath12k_dbring *ring, +u32 num_resp_per_event,u32 event_timeout_ms, +int (*handler)(struct ath12k *, +struct ath12k_dbring_data *)) +{ +if (WARN_ON (!ring)) +return -EINVAL ; + + ring->num_resp_per_event = num_resp_per_event; + ring->event_timeout_ms = event_timeout_ms; + ring->handler = handler; + +return 0 ; +} + +int ath12k_dbring_buf_setup (struct ath12k *ar, +struct ath12k_dbring *ring, +struct ath12k_dbring_cap *db_cap) +{ +struct ath12k_base *ab = ar->ab; +struct hal_srng *srng; +int ret; + + srng = &ab->hal.srng_list[ring->refill_srng.ring_id]; + ring->bufs_max = ring->refill_srng.size / +ath12k_hal_srng_get_entrysize (ab,HAL_RXDMA_DIR_BUF ); + + ring->buf_sz = db_cap->min_buf_sz; + ring->buf_align = db_cap->min_buf_align; + ring->pdev_id = db_cap->pdev_id; + ring->hp_addr =ath12k_hal_srng_get_hp_addr (ab, srng); + ring->tp_addr =ath12k_hal_srng_get_tp_addr (ab, srng); + + ret =ath12k_dbring_fill_bufs (ar, ring,GFP_KERNEL ); + +return ret; +} + +int ath12k_dbring_srng_setup (struct ath12k *ar,struct ath12k_dbring *ring, +int ring_num,int num_entries) +{ +int ret; + + ret =ath12k_dp_srng_setup (ar->ab, &ring->refill_srng,HAL_RXDMA_DIR_BUF , + ring_num, ar->pdev_idx, num_entries); +if (ret <0 ) { +ath12k_warn (ar->ab,"failed to setup srng: %d ring_id %d\n" , + ret, ring_num); + goto err; + } + +return 0 ; +err: +ath12k_dp_srng_cleanup (ar->ab, &ring->refill_srng); +return ret; +} + +int ath12k_dbring_get_cap (struct ath12k_base *ab, +u8 pdev_idx, +enum wmi_direct_buffer_module id, +struct ath12k_dbring_cap *db_cap) +{ +int i; + +if (!ab->num_db_cap || !ab->db_caps) +return -ENOENT ; + +if (id >=WMI_DIRECT_BUF_MAX ) +return -EINVAL ; + +for (i =0 ; i < ab->num_db_cap; i++) { +if (pdev_idx == ab->db_caps[i].pdev_id && + id == ab->db_caps[i].id) { + *db_cap = ab->db_caps[i]; + +return 0 ; + } + } + +return -ENOENT ; +} + +int ath12k_dbring_buffer_release_event (struct ath12k_base *ab, +struct ath12k_dbring_buf_release_event *ev) +{ +struct ath12k_dbring *ring; +struct hal_srng *srng; +struct ath12k *ar; +struct ath12k_dbring_element *buff; +struct ath12k_dbring_data handler_data; +struct ath12k_buffer_addr desc; +u8 *vaddr_unalign; +u32 num_entry, num_buff_reaped; +u8 pdev_idx, rbm; +u32 cookie; +int buf_id; +int size; +dma_addr_t paddr; +int ret =0 ; + + pdev_idx =le32_to_cpu (ev->fixed.pdev_id); + +if (pdev_idx >= ab->num_radios) { +ath12k_warn (ab,"Invalid pdev id %d\n" , pdev_idx); +return -EINVAL ; + } + +if (ev->fixed.num_buf_release_entry != + ev->fixed.num_meta_data_entry) { +ath12k_warn (ab,"Buffer entry %d mismatch meta entry %d\n" , + ev->fixed.num_buf_release_entry, + ev->fixed.num_meta_data_entry); +return -EINVAL ; + } + + ar = ab->pdevs[pdev_idx].ar; + +rcu_read_lock (); +if (!rcu_dereference (ab->pdevs_active[pdev_idx])) { + ret = -EINVAL ; + goto rcu_unlock; + } + +switch (ev->fixed.module_id) { +case WMI_DIRECT_BUF_SPECTRAL : +break ; +default : + ring =NULL ; +ath12k_warn (ab,"Recv dma buffer release ev on unsupp module %d\n" , + ev->fixed.module_id); +break ; + } + +if (!ring) { + ret = -EINVAL ; + goto rcu_unlock; + } + + srng = &ab->hal.srng_list[ring->refill_srng.ring_id]; + num_entry =le32_to_cpu (ev->fixed.num_buf_release_entry); + size =sizeof (*buff) + ring->buf_sz + ring->buf_align -1 ; + num_buff_reaped =0 ; + +spin_lock_bh (&srng->lock); + +while (num_buff_reaped < num_entry) { + desc.info0 = ev->buf_entry[num_buff_reaped].paddr_lo; + desc.info1 = ev->buf_entry[num_buff_reaped].paddr_hi; + handler_data.meta = ev->meta_data[num_buff_reaped]; + + num_buff_reaped++; + +ath12k_hal_rx_buf_addr_info_get (&desc, &paddr, &cookie, &rbm); + + buf_id =u32_get_bits (cookie,DP_RXDMA_BUF_COOKIE_BUF_ID ); + +spin_lock_bh (&ring->idr_lock); + buff =idr_find (&ring->bufs_idr, buf_id); +if (!buff) { +spin_unlock_bh (&ring->idr_lock); +continue ; + } +idr_remove (&ring->bufs_idr, buf_id); +spin_unlock_bh (&ring->idr_lock); + +dma_unmap_single (ab->dev, buff->paddr, ring->buf_sz, +DMA_FROM_DEVICE ); + +if (ring->handler) { + vaddr_unalign = buff->payload; + handler_data.data =PTR_ALIGN (vaddr_unalign, + ring->buf_align); + handler_data.data_sz = ring->buf_sz; + + ring->handler (ar, &handler_data); + } + +memset (buff,0 , size); +ath12k_dbring_bufs_replenish (ar, ring, buff,GFP_ATOMIC ); + } + +spin_unlock_bh (&srng->lock); + +rcu_unlock: +rcu_read_unlock (); + +return ret; +} + +void ath12k_dbring_srng_cleanup (struct ath12k *ar,struct ath12k_dbring *ring) +{ +ath12k_dp_srng_cleanup (ar->ab, &ring->refill_srng); +} + +void ath12k_dbring_buf_cleanup (struct ath12k *ar,struct ath12k_dbring *ring) +{ +struct ath12k_dbring_element *buff; +int buf_id; + +spin_lock_bh (&ring->idr_lock); +idr_for_each_entry (&ring->bufs_idr, buff, buf_id) { +idr_remove (&ring->bufs_idr, buf_id); +dma_unmap_single (ar->ab->dev, buff->paddr, + ring->buf_sz,DMA_FROM_DEVICE ); +kfree (buff); + } + +idr_destroy (&ring->bufs_idr); +spin_unlock_bh (&ring->idr_lock); +}
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 10/50 wifi: ath12k: add debug.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/debug.h | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
drivers/net/wireless/ath/ath12k/debug.h new file +67 -0
@@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#ifndef _ATH12K_DEBUG_H_ +#define _ATH12K_DEBUG_H_ + +#include "trace.h" + +enum ath12k_debug_mask { +ATH12K_DBG_AHB =0x00000001 , +ATH12K_DBG_WMI =0x00000002 , +ATH12K_DBG_HTC =0x00000004 , +ATH12K_DBG_DP_HTT =0x00000008 , +ATH12K_DBG_MAC =0x00000010 , +ATH12K_DBG_BOOT =0x00000020 , +ATH12K_DBG_QMI =0x00000040 , +ATH12K_DBG_DATA =0x00000080 , +ATH12K_DBG_MGMT =0x00000100 , +ATH12K_DBG_REG =0x00000200 , +ATH12K_DBG_TESTMODE =0x00000400 , +ATH12K_DBG_HAL =0x00000800 , +ATH12K_DBG_PCI =0x00001000 , +ATH12K_DBG_DP_TX =0x00002000 , +ATH12K_DBG_DP_RX =0x00004000 , +ATH12K_DBG_ANY =0xffffffff , +}; + +__printf(2, 3) void ath12k_info(struct ath12k_base *ab, const char *fmt, ...); +__printf(2, 3) void ath12k_err(struct ath12k_base *ab, const char *fmt, ...); +__printf(2, 3) void ath12k_warn(struct ath12k_base *ab, const char *fmt, ...); + +extern unsigned int ath12k_debug_mask; + +#ifdef CONFIG_ATH12K_DEBUG +__printf(3, 4) void __ath12k_dbg(struct ath12k_base *ab, +enum ath12k_debug_mask mask, +const char *fmt, ...); +void ath12k_dbg_dump (struct ath12k_base *ab, +enum ath12k_debug_mask mask, +const char *msg,const char *prefix, +const void *buf,size_t len); +#else /* CONFIG_ATH12K_DEBUG */ +static inline void __ath12k_dbg (struct ath12k_base *ab, +enum ath12k_debug_mask dbg_mask, +const char *fmt, ...) +{ +} + +static inline void ath12k_dbg_dump (struct ath12k_base *ab, +enum ath12k_debug_mask mask, +const char *msg,const char *prefix, +const void *buf,size_t len) +{ +} +#endif /* CONFIG_ATH12K_DEBUG */ + +#define ath12k_dbg (ar, dbg_mask, fmt, ...) \ +do { \ + typeof(dbg_mask) mask = (dbg_mask); \ + if (ath12k_debug_mask & mask) \ + __ath12k_dbg(ar, mask, fmt, ##__VA_ARGS__); \ +} while (0) + +#endif /* _ATH12K_DEBUG_H_ */
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 8/50 wifi: ath12k: add dbring.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/dbring.h | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
drivers/net/wireless/ath/ath12k/dbring.h new file +80 -0
@@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2019-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#ifndef ATH12K_DBRING_H +#define ATH12K_DBRING_H + +#include <linux/types.h> +#include <linux/idr.h> +#include <linux/spinlock.h> +#include "dp.h" + +struct ath12k_dbring_element { +dma_addr_t paddr; +u8 payload[]; +}; + +struct ath12k_dbring_data { +void *data; +u32 data_sz; +struct ath12k_wmi_dma_buf_release_meta_data_params meta; +}; + +struct ath12k_dbring_buf_release_event { +struct ath12k_wmi_dma_buf_release_fixed_params fixed; +const struct ath12k_wmi_dma_buf_release_entry_params *buf_entry; +const struct ath12k_wmi_dma_buf_release_meta_data_params *meta_data; +u32 num_buf_entry; +u32 num_meta; +}; + +struct ath12k_dbring_cap { +u32 pdev_id; +enum wmi_direct_buffer_module id; +u32 min_elem; +u32 min_buf_sz; +u32 min_buf_align; +}; + +struct ath12k_dbring { +struct dp_srng refill_srng; +struct idr bufs_idr; +/* Protects bufs_idr */ +spinlock_t idr_lock; +dma_addr_t tp_addr; +dma_addr_t hp_addr; +int bufs_max; +u32 pdev_id; +u32 buf_sz; +u32 buf_align; +u32 num_resp_per_event; +u32 event_timeout_ms; +int (*handler)(struct ath12k *ar,struct ath12k_dbring_data *data); +}; + +int ath12k_dbring_set_cfg (struct ath12k *ar, +struct ath12k_dbring *ring, +u32 num_resp_per_event, +u32 event_timeout_ms, +int (*handler)(struct ath12k *, +struct ath12k_dbring_data *)); +int ath12k_dbring_wmi_cfg_setup (struct ath12k *ar, +struct ath12k_dbring *ring, +enum wmi_direct_buffer_module id); +int ath12k_dbring_buf_setup (struct ath12k *ar, +struct ath12k_dbring *ring, +struct ath12k_dbring_cap *db_cap); +int ath12k_dbring_srng_setup (struct ath12k *ar,struct ath12k_dbring *ring, +int ring_num,int num_entries); +int ath12k_dbring_buffer_release_event (struct ath12k_base *ab, +struct ath12k_dbring_buf_release_event *ev); +int ath12k_dbring_get_cap (struct ath12k_base *ab, +u8 pdev_idx, +enum wmi_direct_buffer_module id, +struct ath12k_dbring_cap *db_cap); +void ath12k_dbring_srng_cleanup (struct ath12k *ar,struct ath12k_dbring *ring); +void ath12k_dbring_buf_cleanup (struct ath12k *ar,struct ath12k_dbring *ring); +#endif /* ATH12K_DBRING_H */
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 20/50 wifi: ath12k: add hal.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/hal.h | 1166 +++++++++++++++++++++++++++++++++ 1 file changed, 1166 insertions(+)
drivers/net/wireless/ath/ath12k/hal.h new file +1166 -0
@@ -0,0 +1,1166 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#ifndef ATH12K_HAL_H +#define ATH12K_HAL_H + +#include "hal_desc.h" +#include "rx_desc.h" + +struct ath12k_base ; + +#define HAL_LINK_DESC_SIZE (32 << 2) +#define HAL_LINK_DESC_ALIGN 128 +#define HAL_NUM_MPDUS_PER_LINK_DESC 6 +#define HAL_NUM_TX_MSDUS_PER_LINK_DESC 7 +#define HAL_NUM_RX_MSDUS_PER_LINK_DESC 6 +#define HAL_NUM_MPDU_LINKS_PER_QUEUE_DESC 12 +#define HAL_MAX_AVAIL_BLK_RES 3 + +#define HAL_RING_BASE_ALIGN 8 + +#define HAL_WBM_IDLE_SCATTER_BUF_SIZE_MAX 32704 +/* TODO: Check with hw team on the supported scatter buf size */ +#define HAL_WBM_IDLE_SCATTER_NEXT_PTR_SIZE 8 +#define HAL_WBM_IDLE_SCATTER_BUF_SIZE (HAL_WBM_IDLE_SCATTER_BUF_SIZE_MAX - \ + HAL_WBM_IDLE_SCATTER_NEXT_PTR_SIZE) + +/* TODO: 16 entries per radio times MAX_VAPS_SUPPORTED */ +#define HAL_DSCP_TID_MAP_TBL_NUM_ENTRIES_MAX 32 +#define HAL_DSCP_TID_TBL_SIZE 24 + +/* calculate the register address from bar0 of shadow register x */ +#define HAL_SHADOW_BASE_ADDR 0x000008fc +#define HAL_SHADOW_NUM_REGS 40 +#define HAL_HP_OFFSET_IN_REG_START 1 +#define HAL_OFFSET_FROM_HP_TO_TP 4 + +#define HAL_SHADOW_REG (x) (HAL_SHADOW_BASE_ADDR + (4 * (x))) + +/* WCSS Relative address */ +#define HAL_SEQ_WCSS_UMAC_OFFSET 0x00a00000 +#define HAL_SEQ_WCSS_UMAC_REO_REG 0x00a38000 +#define HAL_SEQ_WCSS_UMAC_TCL_REG 0x00a44000 +#define HAL_SEQ_WCSS_UMAC_CE0_SRC_REG 0x01b80000 +#define HAL_SEQ_WCSS_UMAC_CE0_DST_REG 0x01b81000 +#define HAL_SEQ_WCSS_UMAC_CE1_SRC_REG 0x01b82000 +#define HAL_SEQ_WCSS_UMAC_CE1_DST_REG 0x01b83000 +#define HAL_SEQ_WCSS_UMAC_WBM_REG 0x00a34000 + +#define HAL_CE_WFSS_CE_REG_BASE 0x01b80000 + +#define HAL_TCL_SW_CONFIG_BANK_ADDR 0x00a4408c + +/* SW2TCL(x) R0 ring configuration address */ +#define HAL_TCL1_RING_CMN_CTRL_REG 0x00000020 +#define HAL_TCL1_RING_DSCP_TID_MAP 0x00000240 +#define HAL_TCL1_RING_BASE_LSB 0x00000900 +#define HAL_TCL1_RING_BASE_MSB 0x00000904 +#define HAL_TCL1_RING_ID (ab) ((ab)->hw_params->regs->hal_tcl1_ring_id) +#define HAL_TCL1_RING_MISC (ab) \ + ((ab)->hw_params->regs->hal_tcl1_ring_misc) +#define HAL_TCL1_RING_TP_ADDR_LSB (ab) \ + ((ab)->hw_params->regs->hal_tcl1_ring_tp_addr_lsb) +#define HAL_TCL1_RING_TP_ADDR_MSB (ab) \ + ((ab)->hw_params->regs->hal_tcl1_ring_tp_addr_msb) +#define HAL_TCL1_RING_CONSUMER_INT_SETUP_IX0 (ab) \ + ((ab)->hw_params->regs->hal_tcl1_ring_consumer_int_setup_ix0) +#define HAL_TCL1_RING_CONSUMER_INT_SETUP_IX1 (ab) \ + ((ab)->hw_params->regs->hal_tcl1_ring_consumer_int_setup_ix1) +#define HAL_TCL1_RING_MSI1_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_tcl1_ring_msi1_base_lsb) +#define HAL_TCL1_RING_MSI1_BASE_MSB (ab) \ + ((ab)->hw_params->regs->hal_tcl1_ring_msi1_base_msb) +#define HAL_TCL1_RING_MSI1_DATA (ab) \ + ((ab)->hw_params->regs->hal_tcl1_ring_msi1_data) +#define HAL_TCL2_RING_BASE_LSB 0x00000978 +#define HAL_TCL_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_tcl_ring_base_lsb) + +#define HAL_TCL1_RING_MSI1_BASE_LSB_OFFSET (ab) \ + (HAL_TCL1_RING_MSI1_BASE_LSB(ab) - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_MSI1_BASE_MSB_OFFSET (ab) \ + (HAL_TCL1_RING_MSI1_BASE_MSB(ab) - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_MSI1_DATA_OFFSET (ab) \ + (HAL_TCL1_RING_MSI1_DATA(ab) - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_BASE_MSB_OFFSET \ + (HAL_TCL1_RING_BASE_MSB - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_ID_OFFSET (ab) \ + (HAL_TCL1_RING_ID(ab) - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_CONSR_INT_SETUP_IX0_OFFSET (ab) \ + (HAL_TCL1_RING_CONSUMER_INT_SETUP_IX0(ab) - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_CONSR_INT_SETUP_IX1_OFFSET (ab) \ + (HAL_TCL1_RING_CONSUMER_INT_SETUP_IX1(ab) - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_TP_ADDR_LSB_OFFSET (ab) \ + (HAL_TCL1_RING_TP_ADDR_LSB(ab) - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_TP_ADDR_MSB_OFFSET (ab) \ + (HAL_TCL1_RING_TP_ADDR_MSB(ab) - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_MISC_OFFSET (ab) \ + (HAL_TCL1_RING_MISC(ab) - HAL_TCL1_RING_BASE_LSB) + +/* SW2TCL(x) R2 ring pointers (head/tail) address */ +#define HAL_TCL1_RING_HP 0x00002000 +#define HAL_TCL1_RING_TP 0x00002004 +#define HAL_TCL2_RING_HP 0x00002008 +#define HAL_TCL_RING_HP 0x00002028 + +#define HAL_TCL1_RING_TP_OFFSET \ + (HAL_TCL1_RING_TP - HAL_TCL1_RING_HP) + +/* TCL STATUS ring address */ +#define HAL_TCL_STATUS_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_tcl_status_ring_base_lsb) +#define HAL_TCL_STATUS_RING_HP 0x00002048 + +/* PPE2TCL1 Ring address */ +#define HAL_TCL_PPE2TCL1_RING_BASE_LSB 0x00000c48 +#define HAL_TCL_PPE2TCL1_RING_HP 0x00002038 + +/* WBM PPE Release Ring address */ +#define HAL_WBM_PPE_RELEASE_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_ppe_rel_ring_base) +#define HAL_WBM_PPE_RELEASE_RING_HP 0x00003020 + +/* REO2SW(x) R0 ring configuration address */ +#define HAL_REO1_GEN_ENABLE 0x00000000 +#define HAL_REO1_MISC_CTRL_ADDR (ab) \ + ((ab)->hw_params->regs->hal_reo1_misc_ctrl_addr) +#define HAL_REO1_DEST_RING_CTRL_IX_0 0x00000004 +#define HAL_REO1_DEST_RING_CTRL_IX_1 0x00000008 +#define HAL_REO1_DEST_RING_CTRL_IX_2 0x0000000c +#define HAL_REO1_DEST_RING_CTRL_IX_3 0x00000010 +#define HAL_REO1_SW_COOKIE_CFG0 (ab) ((ab)->hw_params->regs->hal_reo1_sw_cookie_cfg0) +#define HAL_REO1_SW_COOKIE_CFG1 (ab) ((ab)->hw_params->regs->hal_reo1_sw_cookie_cfg1) +#define HAL_REO1_QDESC_LUT_BASE0 (ab) ((ab)->hw_params->regs->hal_reo1_qdesc_lut_base0) +#define HAL_REO1_QDESC_LUT_BASE1 (ab) ((ab)->hw_params->regs->hal_reo1_qdesc_lut_base1) +#define HAL_REO1_RING_BASE_LSB (ab) ((ab)->hw_params->regs->hal_reo1_ring_base_lsb) +#define HAL_REO1_RING_BASE_MSB (ab) ((ab)->hw_params->regs->hal_reo1_ring_base_msb) +#define HAL_REO1_RING_ID (ab) ((ab)->hw_params->regs->hal_reo1_ring_id) +#define HAL_REO1_RING_MISC (ab) ((ab)->hw_params->regs->hal_reo1_ring_misc) +#define HAL_REO1_RING_HP_ADDR_LSB (ab) ((ab)->hw_params->regs->hal_reo1_ring_hp_addr_lsb) +#define HAL_REO1_RING_HP_ADDR_MSB (ab) ((ab)->hw_params->regs->hal_reo1_ring_hp_addr_msb) +#define HAL_REO1_RING_PRODUCER_INT_SETUP (ab) \ + ((ab)->hw_params->regs->hal_reo1_ring_producer_int_setup) +#define HAL_REO1_RING_MSI1_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_reo1_ring_msi1_base_lsb) +#define HAL_REO1_RING_MSI1_BASE_MSB (ab) \ + ((ab)->hw_params->regs->hal_reo1_ring_msi1_base_msb) +#define HAL_REO1_RING_MSI1_DATA (ab) ((ab)->hw_params->regs->hal_reo1_ring_msi1_data) +#define HAL_REO2_RING_BASE_LSB (ab) ((ab)->hw_params->regs->hal_reo2_ring_base) +#define HAL_REO1_AGING_THRESH_IX_0 (ab) ((ab)->hw_params->regs->hal_reo1_aging_thres_ix0) +#define HAL_REO1_AGING_THRESH_IX_1 (ab) ((ab)->hw_params->regs->hal_reo1_aging_thres_ix1) +#define HAL_REO1_AGING_THRESH_IX_2 (ab) ((ab)->hw_params->regs->hal_reo1_aging_thres_ix2) +#define HAL_REO1_AGING_THRESH_IX_3 (ab) ((ab)->hw_params->regs->hal_reo1_aging_thres_ix3) + +#define HAL_REO1_RING_MSI1_BASE_LSB_OFFSET \ + (HAL_REO1_RING_MSI1_BASE_LSB(ab) - HAL_REO1_RING_BASE_LSB(ab)) +#define HAL_REO1_RING_MSI1_BASE_MSB_OFFSET \ + (HAL_REO1_RING_MSI1_BASE_MSB(ab) - HAL_REO1_RING_BASE_LSB(ab)) +#define HAL_REO1_RING_MSI1_DATA_OFFSET \ + (HAL_REO1_RING_MSI1_DATA(ab) - HAL_REO1_RING_BASE_LSB(ab)) +#define HAL_REO1_RING_BASE_MSB_OFFSET \ + (HAL_REO1_RING_BASE_MSB(ab) - HAL_REO1_RING_BASE_LSB(ab)) + +#define HAL_REO1_RING_ID_OFFSET (ab) \ + ({ \ + struct ath12k_base *_ab = (ab); \ + (HAL_REO1_RING_ID(_ab) - HAL_REO1_RING_BASE_LSB(_ab)); \ + }) + +#define HAL_REO1_RING_PRODUCER_INT_SETUP_OFFSET \ + (HAL_REO1_RING_PRODUCER_INT_SETUP(ab) - HAL_REO1_RING_BASE_LSB(ab)) +#define HAL_REO1_RING_HP_ADDR_LSB_OFFSET \ + (HAL_REO1_RING_HP_ADDR_LSB(ab) - HAL_REO1_RING_BASE_LSB(ab)) +#define HAL_REO1_RING_HP_ADDR_MSB_OFFSET \ + (HAL_REO1_RING_HP_ADDR_MSB(ab) - HAL_REO1_RING_BASE_LSB(ab)) +#define HAL_REO1_RING_MISC_OFFSET \ + (HAL_REO1_RING_MISC(ab) - HAL_REO1_RING_BASE_LSB(ab)) + +/* REO2SW(x) R2 ring pointers (head/tail) address */ +#define HAL_REO1_RING_HP 0x00003048 +#define HAL_REO1_RING_TP 0x0000304c +#define HAL_REO2_RING_HP 0x00003050 + +#define HAL_REO1_RING_TP_OFFSET (HAL_REO1_RING_TP - HAL_REO1_RING_HP) + +/* REO2SW0 ring configuration address */ +#define HAL_REO_SW0_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_reo2_sw0_ring_base) + +/* REO2SW0 R2 ring pointer (head/tail) address */ +#define HAL_REO_SW0_RING_HP 0x00003088 + +/* REO CMD R0 address */ +#define HAL_REO_CMD_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_reo_cmd_ring_base) + +/* REO CMD R2 address */ +#define HAL_REO_CMD_HP 0x00003020 + +/* SW2REO R0 address */ +#define HAL_SW2REO_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_sw2reo_ring_base) +#define HAL_SW2REO1_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_sw2reo1_ring_base) + +/* SW2REO R2 address */ +#define HAL_SW2REO_RING_HP 0x00003028 +#define HAL_SW2REO1_RING_HP 0x00003030 + +/* CE ring R0 address */ +#define HAL_CE_SRC_RING_BASE_LSB 0x00000000 +#define HAL_CE_DST_RING_BASE_LSB 0x00000000 +#define HAL_CE_DST_STATUS_RING_BASE_LSB 0x00000058 +#define HAL_CE_DST_RING_CTRL 0x000000b0 + +/* CE ring R2 address */ +#define HAL_CE_DST_RING_HP 0x00000400 +#define HAL_CE_DST_STATUS_RING_HP 0x00000408 + +/* REO status address */ +#define HAL_REO_STATUS_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_reo_status_ring_base) +#define HAL_REO_STATUS_HP 0x000030a8 + +/* WBM Idle R0 address */ +#define HAL_WBM_IDLE_LINK_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_wbm_idle_ring_base_lsb) +#define HAL_WBM_IDLE_LINK_RING_MISC_ADDR (ab) \ + ((ab)->hw_params->regs->hal_wbm_idle_ring_misc_addr) +#define HAL_WBM_R0_IDLE_LIST_CONTROL_ADDR (ab) \ + ((ab)->hw_params->regs->hal_wbm_r0_idle_list_cntl_addr) +#define HAL_WBM_R0_IDLE_LIST_SIZE_ADDR (ab) \ + ((ab)->hw_params->regs->hal_wbm_r0_idle_list_size_addr) +#define HAL_WBM_SCATTERED_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_wbm_scattered_ring_base_lsb) +#define HAL_WBM_SCATTERED_RING_BASE_MSB (ab) \ + ((ab)->hw_params->regs->hal_wbm_scattered_ring_base_msb) +#define HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX0 (ab) \ + ((ab)->hw_params->regs->hal_wbm_scattered_desc_head_info_ix0) +#define HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX1 (ab) \ + ((ab)->hw_params->regs->hal_wbm_scattered_desc_head_info_ix1) +#define HAL_WBM_SCATTERED_DESC_PTR_TAIL_INFO_IX0 (ab) \ + ((ab)->hw_params->regs->hal_wbm_scattered_desc_tail_info_ix0) +#define HAL_WBM_SCATTERED_DESC_PTR_TAIL_INFO_IX1 (ab) \ + ((ab)->hw_params->regs->hal_wbm_scattered_desc_tail_info_ix1) +#define HAL_WBM_SCATTERED_DESC_PTR_HP_ADDR (ab) \ + ((ab)->hw_params->regs->hal_wbm_scattered_desc_ptr_hp_addr) + +/* WBM Idle R2 address */ +#define HAL_WBM_IDLE_LINK_RING_HP 0x000030b8 + +/* SW2WBM R0 release address */ +#define HAL_WBM_SW_RELEASE_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_wbm_sw_release_ring_base_lsb) +#define HAL_WBM_SW1_RELEASE_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_wbm_sw1_release_ring_base_lsb) + +/* SW2WBM R2 release address */ +#define HAL_WBM_SW_RELEASE_RING_HP 0x00003010 +#define HAL_WBM_SW1_RELEASE_RING_HP 0x00003018 + +/* WBM2SW R0 release address */ +#define HAL_WBM0_RELEASE_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_wbm0_release_ring_base_lsb) + +#define HAL_WBM1_RELEASE_RING_BASE_LSB (ab) \ + ((ab)->hw_params->regs->hal_wbm1_release_ring_base_lsb) + +/* WBM2SW R2 release address */ +#define HAL_WBM0_RELEASE_RING_HP 0x000030c8 +#define HAL_WBM1_RELEASE_RING_HP 0x000030d0 + +/* WBM cookie config address and mask */ +#define HAL_WBM_SW_COOKIE_CFG0 0x00000040 +#define HAL_WBM_SW_COOKIE_CFG1 0x00000044 +#define HAL_WBM_SW_COOKIE_CFG2 0x00000090 +#define HAL_WBM_SW_COOKIE_CONVERT_CFG 0x00000094 + +#define HAL_WBM_SW_COOKIE_CFG_CMEM_BASE_ADDR_MSB GENMASK(7, 0) +#define HAL_WBM_SW_COOKIE_CFG_COOKIE_PPT_MSB GENMASK(12, 8) +#define HAL_WBM_SW_COOKIE_CFG_COOKIE_SPT_MSB GENMASK(17, 13) +#define HAL_WBM_SW_COOKIE_CFG_ALIGN BIT(18) +#define HAL_WBM_SW_COOKIE_CFG_RELEASE_PATH_EN BIT(0) +#define HAL_WBM_SW_COOKIE_CFG_ERR_PATH_EN BIT(1) +#define HAL_WBM_SW_COOKIE_CFG_CONV_IND_EN BIT(3) + +#define HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW0_EN BIT(1) +#define HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW1_EN BIT(2) +#define HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW2_EN BIT(3) +#define HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW3_EN BIT(4) +#define HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW4_EN BIT(5) +#define HAL_WBM_SW_COOKIE_CONV_CFG_GLOBAL_EN BIT(8) + +/* TCL ring feild mask and offset */ +#define HAL_TCL1_RING_BASE_MSB_RING_SIZE GENMASK(27, 8) +#define HAL_TCL1_RING_BASE_MSB_RING_BASE_ADDR_MSB GENMASK(7, 0) +#define HAL_TCL1_RING_ID_ENTRY_SIZE GENMASK(7, 0) +#define HAL_TCL1_RING_MISC_MSI_RING_ID_DISABLE BIT(0) +#define HAL_TCL1_RING_MISC_MSI_LOOPCNT_DISABLE BIT(1) +#define HAL_TCL1_RING_MISC_MSI_SWAP BIT(3) +#define HAL_TCL1_RING_MISC_HOST_FW_SWAP BIT(4) +#define HAL_TCL1_RING_MISC_DATA_TLV_SWAP BIT(5) +#define HAL_TCL1_RING_MISC_SRNG_ENABLE BIT(6) +#define HAL_TCL1_RING_CONSR_INT_SETUP_IX0_INTR_TMR_THOLD GENMASK(31, 16) +#define HAL_TCL1_RING_CONSR_INT_SETUP_IX0_BATCH_COUNTER_THOLD GENMASK(14, 0) +#define HAL_TCL1_RING_CONSR_INT_SETUP_IX1_LOW_THOLD GENMASK(15, 0) +#define HAL_TCL1_RING_MSI1_BASE_MSB_MSI1_ENABLE BIT(8) +#define HAL_TCL1_RING_MSI1_BASE_MSB_ADDR GENMASK(7, 0) +#define HAL_TCL1_RING_CMN_CTRL_DSCP_TID_MAP_PROG_EN BIT(23) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP GENMASK(31, 0) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP0 GENMASK(2, 0) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP1 GENMASK(5, 3) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP2 GENMASK(8, 6) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP3 GENMASK(11, 9) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP4 GENMASK(14, 12) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP5 GENMASK(17, 15) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP6 GENMASK(20, 18) +#define HAL_TCL1_RING_FIELD_DSCP_TID_MAP7 GENMASK(23, 21) + +/* REO ring feild mask and offset */ +#define HAL_REO1_RING_BASE_MSB_RING_SIZE GENMASK(27, 8) +#define HAL_REO1_RING_BASE_MSB_RING_BASE_ADDR_MSB GENMASK(7, 0) +#define HAL_REO1_RING_ID_RING_ID GENMASK(15, 8) +#define HAL_REO1_RING_ID_ENTRY_SIZE GENMASK(7, 0) +#define HAL_REO1_RING_MISC_MSI_SWAP BIT(3) +#define HAL_REO1_RING_MISC_HOST_FW_SWAP BIT(4) +#define HAL_REO1_RING_MISC_DATA_TLV_SWAP BIT(5) +#define HAL_REO1_RING_MISC_SRNG_ENABLE BIT(6) +#define HAL_REO1_RING_PRDR_INT_SETUP_INTR_TMR_THOLD GENMASK(31, 16) +#define HAL_REO1_RING_PRDR_INT_SETUP_BATCH_COUNTER_THOLD GENMASK(14, 0) +#define HAL_REO1_RING_MSI1_BASE_MSB_MSI1_ENABLE BIT(8) +#define HAL_REO1_RING_MSI1_BASE_MSB_ADDR GENMASK(7, 0) +#define HAL_REO1_MISC_CTL_FRAG_DST_RING GENMASK(20, 17) +#define HAL_REO1_MISC_CTL_BAR_DST_RING GENMASK(24, 21) +#define HAL_REO1_GEN_ENABLE_AGING_LIST_ENABLE BIT(2) +#define HAL_REO1_GEN_ENABLE_AGING_FLUSH_ENABLE BIT(3) +#define HAL_REO1_SW_COOKIE_CFG_CMEM_BASE_ADDR_MSB GENMASK(7, 0) +#define HAL_REO1_SW_COOKIE_CFG_COOKIE_PPT_MSB GENMASK(12, 8) +#define HAL_REO1_SW_COOKIE_CFG_COOKIE_SPT_MSB GENMASK(17, 13) +#define HAL_REO1_SW_COOKIE_CFG_ALIGN BIT(18) +#define HAL_REO1_SW_COOKIE_CFG_ENABLE BIT(19) +#define HAL_REO1_SW_COOKIE_CFG_GLOBAL_ENABLE BIT(20) + +/* CE ring bit field mask and shift */ +#define HAL_CE_DST_R0_DEST_CTRL_MAX_LEN GENMASK(15, 0) + +#define HAL_ADDR_LSB_REG_MASK 0xffffffff + +#define HAL_ADDR_MSB_REG_SHIFT 32 + +/* WBM ring bit field mask and shift */ +#define HAL_WBM_LINK_DESC_IDLE_LIST_MODE BIT(1) +#define HAL_WBM_SCATTER_BUFFER_SIZE GENMASK(10, 2) +#define HAL_WBM_SCATTER_RING_SIZE_OF_IDLE_LINK_DESC_LIST GENMASK(31, 16) +#define HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32 GENMASK(7, 0) +#define HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_MATCH_TAG GENMASK(31, 8) + +#define HAL_WBM_SCATTERED_DESC_HEAD_P_OFFSET_IX1 GENMASK(20, 8) +#define HAL_WBM_SCATTERED_DESC_TAIL_P_OFFSET_IX1 GENMASK(20, 8) + +#define HAL_WBM_IDLE_LINK_RING_MISC_SRNG_ENABLE BIT(6) +#define HAL_WBM_IDLE_LINK_RING_MISC_RIND_ID_DISABLE BIT(0) + +#define BASE_ADDR_MATCH_TAG_VAL 0x5 + +#define HAL_REO_REO2SW1_RING_BASE_MSB_RING_SIZE 0x000fffff +#define HAL_REO_REO2SW0_RING_BASE_MSB_RING_SIZE 0x000fffff +#define HAL_REO_SW2REO_RING_BASE_MSB_RING_SIZE 0x0000ffff +#define HAL_REO_CMD_RING_BASE_MSB_RING_SIZE 0x0000ffff +#define HAL_REO_STATUS_RING_BASE_MSB_RING_SIZE 0x0000ffff +#define HAL_SW2TCL1_RING_BASE_MSB_RING_SIZE 0x000fffff +#define HAL_SW2TCL1_CMD_RING_BASE_MSB_RING_SIZE 0x000fffff +#define HAL_TCL_STATUS_RING_BASE_MSB_RING_SIZE 0x0000ffff +#define HAL_CE_SRC_RING_BASE_MSB_RING_SIZE 0x0000ffff +#define HAL_CE_DST_RING_BASE_MSB_RING_SIZE 0x0000ffff +#define HAL_CE_DST_STATUS_RING_BASE_MSB_RING_SIZE 0x0000ffff +#define HAL_WBM_IDLE_LINK_RING_BASE_MSB_RING_SIZE 0x000fffff +#define HAL_SW2WBM_RELEASE_RING_BASE_MSB_RING_SIZE 0x0000ffff +#define HAL_WBM2SW_RELEASE_RING_BASE_MSB_RING_SIZE 0x000fffff +#define HAL_RXDMA_RING_MAX_SIZE 0x0000ffff +#define HAL_RXDMA_RING_MAX_SIZE_BE 0x000fffff +#define HAL_WBM2PPE_RELEASE_RING_BASE_MSB_RING_SIZE 0x000fffff + +#define HAL_WBM2SW_REL_ERR_RING_NUM 3 +/* Add any other errors here and return them in +* ath12k_hal_rx_desc_get_err(). +*/ + +enum hal_srng_ring_id { +HAL_SRNG_RING_ID_REO2SW0 =0 , +HAL_SRNG_RING_ID_REO2SW1 , +HAL_SRNG_RING_ID_REO2SW2 , +HAL_SRNG_RING_ID_REO2SW3 , +HAL_SRNG_RING_ID_REO2SW4 , +HAL_SRNG_RING_ID_REO2SW5 , +HAL_SRNG_RING_ID_REO2SW6 , +HAL_SRNG_RING_ID_REO2SW7 , +HAL_SRNG_RING_ID_REO2SW8 , +HAL_SRNG_RING_ID_REO2TCL , +HAL_SRNG_RING_ID_REO2PPE , + +HAL_SRNG_RING_ID_SW2REO =16 , +HAL_SRNG_RING_ID_SW2REO1 , +HAL_SRNG_RING_ID_SW2REO2 , +HAL_SRNG_RING_ID_SW2REO3 , + +HAL_SRNG_RING_ID_REO_CMD , +HAL_SRNG_RING_ID_REO_STATUS , + +HAL_SRNG_RING_ID_SW2TCL1 =24 , +HAL_SRNG_RING_ID_SW2TCL2 , +HAL_SRNG_RING_ID_SW2TCL3 , +HAL_SRNG_RING_ID_SW2TCL4 , +HAL_SRNG_RING_ID_SW2TCL5 , +HAL_SRNG_RING_ID_SW2TCL6 , +HAL_SRNG_RING_ID_PPE2TCL1 =30 , + +HAL_SRNG_RING_ID_SW2TCL_CMD =40 , +HAL_SRNG_RING_ID_SW2TCL1_CMD , +HAL_SRNG_RING_ID_TCL_STATUS , + +HAL_SRNG_RING_ID_CE0_SRC =64 , +HAL_SRNG_RING_ID_CE1_SRC , +HAL_SRNG_RING_ID_CE2_SRC , +HAL_SRNG_RING_ID_CE3_SRC , +HAL_SRNG_RING_ID_CE4_SRC , +HAL_SRNG_RING_ID_CE5_SRC , +HAL_SRNG_RING_ID_CE6_SRC , +HAL_SRNG_RING_ID_CE7_SRC , +HAL_SRNG_RING_ID_CE8_SRC , +HAL_SRNG_RING_ID_CE9_SRC , +HAL_SRNG_RING_ID_CE10_SRC , +HAL_SRNG_RING_ID_CE11_SRC , +HAL_SRNG_RING_ID_CE12_SRC , +HAL_SRNG_RING_ID_CE13_SRC , +HAL_SRNG_RING_ID_CE14_SRC , +HAL_SRNG_RING_ID_CE15_SRC , + +HAL_SRNG_RING_ID_CE0_DST =81 , +HAL_SRNG_RING_ID_CE1_DST , +HAL_SRNG_RING_ID_CE2_DST , +HAL_SRNG_RING_ID_CE3_DST , +HAL_SRNG_RING_ID_CE4_DST , +HAL_SRNG_RING_ID_CE5_DST , +HAL_SRNG_RING_ID_CE6_DST , +HAL_SRNG_RING_ID_CE7_DST , +HAL_SRNG_RING_ID_CE8_DST , +HAL_SRNG_RING_ID_CE9_DST , +HAL_SRNG_RING_ID_CE10_DST , +HAL_SRNG_RING_ID_CE11_DST , +HAL_SRNG_RING_ID_CE12_DST , +HAL_SRNG_RING_ID_CE13_DST , +HAL_SRNG_RING_ID_CE14_DST , +HAL_SRNG_RING_ID_CE15_DST , + +HAL_SRNG_RING_ID_CE0_DST_STATUS =100 , +HAL_SRNG_RING_ID_CE1_DST_STATUS , +HAL_SRNG_RING_ID_CE2_DST_STATUS , +HAL_SRNG_RING_ID_CE3_DST_STATUS , +HAL_SRNG_RING_ID_CE4_DST_STATUS , +HAL_SRNG_RING_ID_CE5_DST_STATUS , +HAL_SRNG_RING_ID_CE6_DST_STATUS , +HAL_SRNG_RING_ID_CE7_DST_STATUS , +HAL_SRNG_RING_ID_CE8_DST_STATUS , +HAL_SRNG_RING_ID_CE9_DST_STATUS , +HAL_SRNG_RING_ID_CE10_DST_STATUS , +HAL_SRNG_RING_ID_CE11_DST_STATUS , +HAL_SRNG_RING_ID_CE12_DST_STATUS , +HAL_SRNG_RING_ID_CE13_DST_STATUS , +HAL_SRNG_RING_ID_CE14_DST_STATUS , +HAL_SRNG_RING_ID_CE15_DST_STATUS , + +HAL_SRNG_RING_ID_WBM_IDLE_LINK =120 , +HAL_SRNG_RING_ID_WBM_SW0_RELEASE , +HAL_SRNG_RING_ID_WBM_SW1_RELEASE , +HAL_SRNG_RING_ID_WBM_PPE_RELEASE =123 , + +HAL_SRNG_RING_ID_WBM2SW0_RELEASE =128 , +HAL_SRNG_RING_ID_WBM2SW1_RELEASE , +HAL_SRNG_RING_ID_WBM2SW2_RELEASE , +HAL_SRNG_RING_ID_WBM2SW3_RELEASE ,/* RX ERROR RING */ +HAL_SRNG_RING_ID_WBM2SW4_RELEASE , +HAL_SRNG_RING_ID_WBM2SW5_RELEASE , +HAL_SRNG_RING_ID_WBM2SW6_RELEASE , +HAL_SRNG_RING_ID_WBM2SW7_RELEASE , + +HAL_SRNG_RING_ID_UMAC_ID_END =159 , + +/* Common DMAC rings shared by all LMACs */ +HAL_SRNG_RING_ID_DMAC_CMN_ID_START =160 , +HAL_SRNG_SW2RXDMA_BUF0 =HAL_SRNG_RING_ID_DMAC_CMN_ID_START , +HAL_SRNG_SW2RXDMA_BUF1 =161 , +HAL_SRNG_SW2RXDMA_BUF2 =162 , + +HAL_SRNG_SW2RXMON_BUF0 =168 , + +HAL_SRNG_SW2TXMON_BUF0 =176 , + +HAL_SRNG_RING_ID_DMAC_CMN_ID_END =183 , +HAL_SRNG_RING_ID_PMAC1_ID_START =184 , + +HAL_SRNG_RING_ID_WMAC1_SW2RXMON_BUF0 =HAL_SRNG_RING_ID_PMAC1_ID_START , + +HAL_SRNG_RING_ID_WMAC1_RXDMA2SW0 , +HAL_SRNG_RING_ID_WMAC1_RXDMA2SW1 , +HAL_SRNG_RING_ID_WMAC1_RXMON2SW0 =HAL_SRNG_RING_ID_WMAC1_RXDMA2SW1 , +HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_DESC , +HAL_SRNG_RING_ID_RXDMA_DIR_BUF , +HAL_SRNG_RING_ID_WMAC1_SW2TXMON_BUF0 , +HAL_SRNG_RING_ID_WMAC1_TXMON2SW0_BUF0 , + +HAL_SRNG_RING_ID_PMAC1_ID_END , +}; + +/* SRNG registers are split into two groups R0 and R2 */ +#define HAL_SRNG_REG_GRP_R0 0 +#define HAL_SRNG_REG_GRP_R2 1 +#define HAL_SRNG_NUM_REG_GRP 2 + +/* TODO: number of PMACs */ +#define HAL_SRNG_NUM_PMACS 3 +#define HAL_SRNG_NUM_DMAC_RINGS (HAL_SRNG_RING_ID_DMAC_CMN_ID_END - \ + HAL_SRNG_RING_ID_DMAC_CMN_ID_START) +#define HAL_SRNG_RINGS_PER_PMAC (HAL_SRNG_RING_ID_PMAC1_ID_END - \ + HAL_SRNG_RING_ID_PMAC1_ID_START) +#define HAL_SRNG_NUM_PMAC_RINGS (HAL_SRNG_NUM_PMACS * HAL_SRNG_RINGS_PER_PMAC) +#define HAL_SRNG_RING_ID_MAX (HAL_SRNG_RING_ID_DMAC_CMN_ID_END + \ + HAL_SRNG_NUM_PMAC_RINGS) + +enum hal_ring_type { +HAL_REO_DST , +HAL_REO_EXCEPTION , +HAL_REO_REINJECT , +HAL_REO_CMD , +HAL_REO_STATUS , +HAL_TCL_DATA , +HAL_TCL_CMD , +HAL_TCL_STATUS , +HAL_CE_SRC , +HAL_CE_DST , +HAL_CE_DST_STATUS , +HAL_WBM_IDLE_LINK , +HAL_SW2WBM_RELEASE , +HAL_WBM2SW_RELEASE , +HAL_RXDMA_BUF , +HAL_RXDMA_DST , +HAL_RXDMA_MONITOR_BUF , +HAL_RXDMA_MONITOR_STATUS , +HAL_RXDMA_MONITOR_DST , +HAL_RXDMA_MONITOR_DESC , +HAL_RXDMA_DIR_BUF , +HAL_PPE2TCL , +HAL_PPE_RELEASE , +HAL_TX_MONITOR_BUF , +HAL_TX_MONITOR_DST , +HAL_MAX_RING_TYPES , +}; + +#define HAL_RX_MAX_BA_WINDOW 256 + +#define HAL_DEFAULT_BE_BK_VI_REO_TIMEOUT_USEC (100 * 1000) +#define HAL_DEFAULT_VO_REO_TIMEOUT_USEC (40 * 1000) + +/** +* enum hal_reo_cmd_type: Enum for REO command type +* @HAL_REO_CMD_GET_QUEUE_STATS: Get REO queue status/stats +* @HAL_REO_CMD_FLUSH_QUEUE: Flush all frames in REO queue +* @HAL_REO_CMD_FLUSH_CACHE: Flush descriptor entries in the cache +* @HAL_REO_CMD_UNBLOCK_CACHE: Unblock a descriptor's address that was blocked +* earlier with a 'REO_FLUSH_CACHE' command +* @HAL_REO_CMD_FLUSH_TIMEOUT_LIST: Flush buffers/descriptors from timeout list +* @HAL_REO_CMD_UPDATE_RX_QUEUE: Update REO queue settings +*/ +enum hal_reo_cmd_type { +HAL_REO_CMD_GET_QUEUE_STATS =0 , +HAL_REO_CMD_FLUSH_QUEUE =1 , +HAL_REO_CMD_FLUSH_CACHE =2 , +HAL_REO_CMD_UNBLOCK_CACHE =3 , +HAL_REO_CMD_FLUSH_TIMEOUT_LIST =4 , +HAL_REO_CMD_UPDATE_RX_QUEUE =5 , +}; + +/** +* enum hal_reo_cmd_status: Enum for execution status of REO command +* @HAL_REO_CMD_SUCCESS: Command has successfully executed +* @HAL_REO_CMD_BLOCKED: Command could not be executed as the queue +* or cache was blocked +* @HAL_REO_CMD_FAILED: Command execution failed, could be due to +* invalid queue desc +* @HAL_REO_CMD_RESOURCE_BLOCKED: +* @HAL_REO_CMD_DRAIN: +*/ +enum hal_reo_cmd_status { +HAL_REO_CMD_SUCCESS =0 , +HAL_REO_CMD_BLOCKED =1 , +HAL_REO_CMD_FAILED =2 , +HAL_REO_CMD_RESOURCE_BLOCKED =3 , +HAL_REO_CMD_DRAIN =0xff , +}; + +struct hal_wbm_idle_scatter_list { +dma_addr_t paddr; +struct hal_wbm_link_desc *vaddr; +}; + +struct hal_srng_params { +dma_addr_t ring_base_paddr; +u32 *ring_base_vaddr; +int num_entries; +u32 intr_batch_cntr_thres_entries; +u32 intr_timer_thres_us; +u32 flags; +u32 max_buffer_len; +u32 low_threshold; +u32 high_threshold; +dma_addr_t msi_addr; +dma_addr_t msi2_addr; +u32 msi_data; +u32 msi2_data; + +/* Add more params as needed */ +}; + +enum hal_srng_dir { +HAL_SRNG_DIR_SRC , +HAL_SRNG_DIR_DST +}; + +/* srng flags */ +#define HAL_SRNG_FLAGS_MSI_SWAP 0x00000008 +#define HAL_SRNG_FLAGS_RING_PTR_SWAP 0x00000010 +#define HAL_SRNG_FLAGS_DATA_TLV_SWAP 0x00000020 +#define HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN 0x00010000 +#define HAL_SRNG_FLAGS_MSI_INTR 0x00020000 +#define HAL_SRNG_FLAGS_HIGH_THRESH_INTR_EN 0x00080000 +#define HAL_SRNG_FLAGS_LMAC_RING 0x80000000 + +#define HAL_SRNG_TLV_HDR_TAG GENMASK(9, 1) +#define HAL_SRNG_TLV_HDR_LEN GENMASK(25, 10) + +/* Common SRNG ring structure for source and destination rings */ +struct hal_srng { +/* Unique SRNG ring ID */ +u8 ring_id; + +/* Ring initialization done */ +u8 initialized; + +/* Interrupt/MSI value assigned to this ring */ +int irq; + +/* Physical base address of the ring */ +dma_addr_t ring_base_paddr; + +/* Virtual base address of the ring */ +u32 *ring_base_vaddr; + +/* Number of entries in ring */ +u32 num_entries; + +/* Ring size */ +u32 ring_size; + +/* Ring size mask */ +u32 ring_size_mask; + +/* Size of ring entry */ +u32 entry_size; + +/* Interrupt timer threshold - in micro seconds */ +u32 intr_timer_thres_us; + +/* Interrupt batch counter threshold - in number of ring entries */ +u32 intr_batch_cntr_thres_entries; + +/* MSI Address */ +dma_addr_t msi_addr; + +/* MSI data */ +u32 msi_data; + +/* MSI2 Address */ +dma_addr_t msi2_addr; + +/* MSI2 data */ +u32 msi2_data; + +/* Misc flags */ +u32 flags; + +/* Lock for serializing ring index updates */ +spinlock_t lock; + +struct lock_class_key lock_key; + +/* Start offset of SRNG register groups for this ring +* TBD: See if this is required - register address can be derived +* from ring ID +*/ +u32 hwreg_base[HAL_SRNG_NUM_REG_GRP ]; + +u64 timestamp; + +/* Source or Destination ring */ +enum hal_srng_dir ring_dir; + +union { +struct { +/* SW tail pointer */ +u32 tp; + +/* Shadow head pointer location to be updated by HW */ +volatile u32 *hp_addr; + +/* Cached head pointer */ +u32 cached_hp; + +/* Tail pointer location to be updated by SW - This +* will be a register address and need not be +* accessed through SW structure +*/ +u32 *tp_addr; + +/* Current SW loop cnt */ +u32 loop_cnt; + +/* max transfer size */ +u16 max_buffer_length; + +/* head pointer at access end */ +u32 last_hp; + } dst_ring; + +struct { +/* SW head pointer */ +u32 hp; + +/* SW reap head pointer */ +u32 reap_hp; + +/* Shadow tail pointer location to be updated by HW */ +u32 *tp_addr; + +/* Cached tail pointer */ +u32 cached_tp; + +/* Head pointer location to be updated by SW - This +* will be a register address and need not be accessed +* through SW structure +*/ +u32 *hp_addr; + +/* Low threshold - in number of ring entries */ +u32 low_threshold; + +/* tail pointer at access end */ +u32 last_tp; + } src_ring; + } u; +}; + +/* Interrupt mitigation - Batch threshold in terms of numer of frames */ +#define HAL_SRNG_INT_BATCH_THRESHOLD_TX 256 +#define HAL_SRNG_INT_BATCH_THRESHOLD_RX 128 +#define HAL_SRNG_INT_BATCH_THRESHOLD_OTHER 1 + +/* Interrupt mitigation - timer threshold in us */ +#define HAL_SRNG_INT_TIMER_THRESHOLD_TX 1000 +#define HAL_SRNG_INT_TIMER_THRESHOLD_RX 500 +#define HAL_SRNG_INT_TIMER_THRESHOLD_OTHER 256 + +enum hal_srng_mac_type { +ATH12K_HAL_SRNG_UMAC , +ATH12K_HAL_SRNG_DMAC , +ATH12K_HAL_SRNG_PMAC +}; + +/* HW SRNG configuration table */ +struct hal_srng_config { +int start_ring_id; +u16 max_rings; +u16 entry_size; +u32 reg_start[HAL_SRNG_NUM_REG_GRP ]; +u16 reg_size[HAL_SRNG_NUM_REG_GRP ]; +enum hal_srng_mac_type mac_type; +enum hal_srng_dir ring_dir; +u32 max_size; +}; + +/** +* enum hal_rx_buf_return_buf_manager +* +* @HAL_RX_BUF_RBM_WBM_IDLE_BUF_LIST: Buffer returned to WBM idle buffer list +* @HAL_RX_BUF_RBM_WBM_CHIP0_IDLE_DESC_LIST: Descriptor returned to WBM idle +* descriptor list, where the chip 0 WBM is chosen in case of a multi-chip config +* @HAL_RX_BUF_RBM_WBM_CHIP1_IDLE_DESC_LIST: Descriptor returned to WBM idle +* descriptor list, where the chip 1 WBM is chosen in case of a multi-chip config +* @HAL_RX_BUF_RBM_WBM_CHIP2_IDLE_DESC_LIST: Descriptor returned to WBM idle +* descriptor list, where the chip 2 WBM is chosen in case of a multi-chip config +* @HAL_RX_BUF_RBM_FW_BM: Buffer returned to FW +* @HAL_RX_BUF_RBM_SW0_BM: For ring 0 -- returned to host +* @HAL_RX_BUF_RBM_SW1_BM: For ring 1 -- returned to host +* @HAL_RX_BUF_RBM_SW2_BM: For ring 2 -- returned to host +* @HAL_RX_BUF_RBM_SW3_BM: For ring 3 -- returned to host +* @HAL_RX_BUF_RBM_SW4_BM: For ring 4 -- returned to host +* @HAL_RX_BUF_RBM_SW5_BM: For ring 5 -- returned to host +* @HAL_RX_BUF_RBM_SW6_BM: For ring 6 -- returned to host +*/ + +enum hal_rx_buf_return_buf_manager { +HAL_RX_BUF_RBM_WBM_IDLE_BUF_LIST , +HAL_RX_BUF_RBM_WBM_CHIP0_IDLE_DESC_LIST , +HAL_RX_BUF_RBM_WBM_CHIP1_IDLE_DESC_LIST , +HAL_RX_BUF_RBM_WBM_CHIP2_IDLE_DESC_LIST , +HAL_RX_BUF_RBM_FW_BM , +HAL_RX_BUF_RBM_SW0_BM , +HAL_RX_BUF_RBM_SW1_BM , +HAL_RX_BUF_RBM_SW2_BM , +HAL_RX_BUF_RBM_SW3_BM , +HAL_RX_BUF_RBM_SW4_BM , +HAL_RX_BUF_RBM_SW5_BM , +HAL_RX_BUF_RBM_SW6_BM , +}; + +#define HAL_SRNG_DESC_LOOP_CNT 0xf0000000 + +#define HAL_REO_CMD_FLG_NEED_STATUS BIT(0) +#define HAL_REO_CMD_FLG_STATS_CLEAR BIT(1) +#define HAL_REO_CMD_FLG_FLUSH_BLOCK_LATER BIT(2) +#define HAL_REO_CMD_FLG_FLUSH_RELEASE_BLOCKING BIT(3) +#define HAL_REO_CMD_FLG_FLUSH_NO_INVAL BIT(4) +#define HAL_REO_CMD_FLG_FLUSH_FWD_ALL_MPDUS BIT(5) +#define HAL_REO_CMD_FLG_FLUSH_ALL BIT(6) +#define HAL_REO_CMD_FLG_UNBLK_RESOURCE BIT(7) +#define HAL_REO_CMD_FLG_UNBLK_CACHE BIT(8) + +/* Should be matching with HAL_REO_UPD_RX_QUEUE_INFO0_UPD_* feilds */ +#define HAL_REO_CMD_UPD0_RX_QUEUE_NUM BIT(8) +#define HAL_REO_CMD_UPD0_VLD BIT(9) +#define HAL_REO_CMD_UPD0_ALDC BIT(10) +#define HAL_REO_CMD_UPD0_DIS_DUP_DETECTION BIT(11) +#define HAL_REO_CMD_UPD0_SOFT_REORDER_EN BIT(12) +#define HAL_REO_CMD_UPD0_AC BIT(13) +#define HAL_REO_CMD_UPD0_BAR BIT(14) +#define HAL_REO_CMD_UPD0_RETRY BIT(15) +#define HAL_REO_CMD_UPD0_CHECK_2K_MODE BIT(16) +#define HAL_REO_CMD_UPD0_OOR_MODE BIT(17) +#define HAL_REO_CMD_UPD0_BA_WINDOW_SIZE BIT(18) +#define HAL_REO_CMD_UPD0_PN_CHECK BIT(19) +#define HAL_REO_CMD_UPD0_EVEN_PN BIT(20) +#define HAL_REO_CMD_UPD0_UNEVEN_PN BIT(21) +#define HAL_REO_CMD_UPD0_PN_HANDLE_ENABLE BIT(22) +#define HAL_REO_CMD_UPD0_PN_SIZE BIT(23) +#define HAL_REO_CMD_UPD0_IGNORE_AMPDU_FLG BIT(24) +#define HAL_REO_CMD_UPD0_SVLD BIT(25) +#define HAL_REO_CMD_UPD0_SSN BIT(26) +#define HAL_REO_CMD_UPD0_SEQ_2K_ERR BIT(27) +#define HAL_REO_CMD_UPD0_PN_ERR BIT(28) +#define HAL_REO_CMD_UPD0_PN_VALID BIT(29) +#define HAL_REO_CMD_UPD0_PN BIT(30) + +/* Should be matching with HAL_REO_UPD_RX_QUEUE_INFO1_* feilds */ +#define HAL_REO_CMD_UPD1_VLD BIT(16) +#define HAL_REO_CMD_UPD1_ALDC GENMASK(18, 17) +#define HAL_REO_CMD_UPD1_DIS_DUP_DETECTION BIT(19) +#define HAL_REO_CMD_UPD1_SOFT_REORDER_EN BIT(20) +#define HAL_REO_CMD_UPD1_AC GENMASK(22, 21) +#define HAL_REO_CMD_UPD1_BAR BIT(23) +#define HAL_REO_CMD_UPD1_RETRY BIT(24) +#define HAL_REO_CMD_UPD1_CHECK_2K_MODE BIT(25) +#define HAL_REO_CMD_UPD1_OOR_MODE BIT(26) +#define HAL_REO_CMD_UPD1_PN_CHECK BIT(27) +#define HAL_REO_CMD_UPD1_EVEN_PN BIT(28) +#define HAL_REO_CMD_UPD1_UNEVEN_PN BIT(29) +#define HAL_REO_CMD_UPD1_PN_HANDLE_ENABLE BIT(30) +#define HAL_REO_CMD_UPD1_IGNORE_AMPDU_FLG BIT(31) + +/* Should be matching with HAL_REO_UPD_RX_QUEUE_INFO2_* feilds */ +#define HAL_REO_CMD_UPD2_SVLD BIT(10) +#define HAL_REO_CMD_UPD2_SSN GENMASK(22, 11) +#define HAL_REO_CMD_UPD2_SEQ_2K_ERR BIT(23) +#define HAL_REO_CMD_UPD2_PN_ERR BIT(24) + +struct ath12k_hal_reo_cmd { +u32 addr_lo; +u32 flag; +u32 upd0; +u32 upd1; +u32 upd2; +u32 pn[4 ]; +u16 rx_queue_num; +u16 min_rel; +u16 min_fwd; +u8 addr_hi; +u8 ac_list; +u8 blocking_idx; +u16 ba_window_size; +u8 pn_size; +}; + +enum hal_pn_type { +HAL_PN_TYPE_NONE , +HAL_PN_TYPE_WPA , +HAL_PN_TYPE_WAPI_EVEN , +HAL_PN_TYPE_WAPI_UNEVEN , +}; + +enum hal_ce_desc { +HAL_CE_DESC_SRC , +HAL_CE_DESC_DST , +HAL_CE_DESC_DST_STATUS , +}; + +#define HAL_HASH_ROUTING_RING_TCL 0 +#define HAL_HASH_ROUTING_RING_SW1 1 +#define HAL_HASH_ROUTING_RING_SW2 2 +#define HAL_HASH_ROUTING_RING_SW3 3 +#define HAL_HASH_ROUTING_RING_SW4 4 +#define HAL_HASH_ROUTING_RING_REL 5 +#define HAL_HASH_ROUTING_RING_FW 6 + +struct hal_reo_status_header { +u16 cmd_num; +enum hal_reo_cmd_status cmd_status; +u16 cmd_exe_time; +u32 timestamp; +}; + +struct hal_reo_status_queue_stats { +u16 ssn; +u16 curr_idx; +u32 pn[4 ]; +u32 last_rx_queue_ts; +u32 last_rx_dequeue_ts; +u32 rx_bitmap[8 ];/* Bitmap from 0-255 */ +u32 curr_mpdu_cnt; +u32 curr_msdu_cnt; +u16 fwd_due_to_bar_cnt; +u16 dup_cnt; +u32 frames_in_order_cnt; +u32 num_mpdu_processed_cnt; +u32 num_msdu_processed_cnt; +u32 total_num_processed_byte_cnt; +u32 late_rx_mpdu_cnt; +u32 reorder_hole_cnt; +u8 timeout_cnt; +u8 bar_rx_cnt; +u8 num_window_2k_jump_cnt; +}; + +struct hal_reo_status_flush_queue { +bool err_detected; +}; + +enum hal_reo_status_flush_cache_err_code { +HAL_REO_STATUS_FLUSH_CACHE_ERR_CODE_SUCCESS , +HAL_REO_STATUS_FLUSH_CACHE_ERR_CODE_IN_USE , +HAL_REO_STATUS_FLUSH_CACHE_ERR_CODE_NOT_FOUND , +}; + +struct hal_reo_status_flush_cache { +bool err_detected; +enum hal_reo_status_flush_cache_err_code err_code; +bool cache_controller_flush_status_hit; +u8 cache_controller_flush_status_desc_type; +u8 cache_controller_flush_status_client_id; +u8 cache_controller_flush_status_err; +u8 cache_controller_flush_status_cnt; +}; + +enum hal_reo_status_unblock_cache_type { +HAL_REO_STATUS_UNBLOCK_BLOCKING_RESOURCE , +HAL_REO_STATUS_UNBLOCK_ENTIRE_CACHE_USAGE , +}; + +struct hal_reo_status_unblock_cache { +bool err_detected; +enum hal_reo_status_unblock_cache_type unblock_type; +}; + +struct hal_reo_status_flush_timeout_list { +bool err_detected; +bool list_empty; +u16 release_desc_cnt; +u16 fwd_buf_cnt; +}; + +enum hal_reo_threshold_idx { +HAL_REO_THRESHOLD_IDX_DESC_COUNTER0 , +HAL_REO_THRESHOLD_IDX_DESC_COUNTER1 , +HAL_REO_THRESHOLD_IDX_DESC_COUNTER2 , +HAL_REO_THRESHOLD_IDX_DESC_COUNTER_SUM , +}; + +struct hal_reo_status_desc_thresh_reached { +enum hal_reo_threshold_idx threshold_idx; +u32 link_desc_counter0; +u32 link_desc_counter1; +u32 link_desc_counter2; +u32 link_desc_counter_sum; +}; + +struct hal_reo_status { +struct hal_reo_status_header uniform_hdr; +u8 loop_cnt; +union { +struct hal_reo_status_queue_stats queue_stats; +struct hal_reo_status_flush_queue flush_queue; +struct hal_reo_status_flush_cache flush_cache; +struct hal_reo_status_unblock_cache unblock_cache; +struct hal_reo_status_flush_timeout_list timeout_list; +struct hal_reo_status_desc_thresh_reached desc_thresh_reached; + } u; +}; + +/* HAL context to be used to access SRNG APIs (currently used by data path +* and transport (CE) modules) +*/ +struct ath12k_hal { +/* HAL internal state for all SRNG rings. +*/ +struct hal_srng srng_list[HAL_SRNG_RING_ID_MAX ]; + +/* SRNG configuration table */ +struct hal_srng_config *srng_config; + +/* Remote pointer memory for HW/FW updates */ +struct { +u32 *vaddr; +dma_addr_t paddr; + } rdp; + +/* Shared memory for ring pointer updates from host to FW */ +struct { +u32 *vaddr; +dma_addr_t paddr; + } wrp; + +/* Available REO blocking resources bitmap */ +u8 avail_blk_resource; + +u8 current_blk_index; + +/* shadow register configuration */ +u32 shadow_reg_addr[HAL_SHADOW_NUM_REGS ]; +int num_shadow_reg_configured; +}; + +/* Maps WBM ring number and Return Buffer Manager Id per TCL ring */ +struct ath12k_hal_tcl_to_wbm_rbm_map { +u8 wbm_ring_num; +u8 rbm_id; +}; + +struct hal_ops { +bool (*rx_desc_get_first_msdu)(struct hal_rx_desc *desc); +bool (*rx_desc_get_last_msdu)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_l3_pad_bytes)(struct hal_rx_desc *desc); +u8 *(*rx_desc_get_hdr_status)(struct hal_rx_desc *desc); +bool (*rx_desc_encrypt_valid)(struct hal_rx_desc *desc); +u32 (*rx_desc_get_encrypt_type)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_decap_type)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_mesh_ctl)(struct hal_rx_desc *desc); +bool (*rx_desc_get_mpdu_seq_ctl_vld)(struct hal_rx_desc *desc); +bool (*rx_desc_get_mpdu_fc_valid)(struct hal_rx_desc *desc); +u16 (*rx_desc_get_mpdu_start_seq_no)(struct hal_rx_desc *desc); +u16 (*rx_desc_get_msdu_len)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_msdu_sgi)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_msdu_rate_mcs)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_msdu_rx_bw)(struct hal_rx_desc *desc); +u32 (*rx_desc_get_msdu_freq)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_msdu_pkt_type)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_msdu_nss)(struct hal_rx_desc *desc); +u8 (*rx_desc_get_mpdu_tid)(struct hal_rx_desc *desc); +u16 (*rx_desc_get_mpdu_peer_id)(struct hal_rx_desc *desc); +void (*rx_desc_copy_end_tlv)(struct hal_rx_desc *fdesc, +struct hal_rx_desc *ldesc); +u32 (*rx_desc_get_mpdu_start_tag)(struct hal_rx_desc *desc); +u32 (*rx_desc_get_mpdu_ppdu_id)(struct hal_rx_desc *desc); +void (*rx_desc_set_msdu_len)(struct hal_rx_desc *desc,u16 len); +struct rx_attention *(*rx_desc_get_attention)(struct hal_rx_desc *desc); +u8 *(*rx_desc_get_msdu_payload)(struct hal_rx_desc *desc); +u32 (*rx_desc_get_mpdu_start_offset)(void ); +u32 (*rx_desc_get_msdu_end_offset)(void ); +bool (*rx_desc_mac_addr2_valid)(struct hal_rx_desc *desc); +u8 * (*rx_desc_mpdu_start_addr2)(struct hal_rx_desc *desc); +bool (*rx_desc_is_mcbc)(struct hal_rx_desc *desc); +void (*rx_desc_get_dot11_hdr)(struct hal_rx_desc *desc, +struct ieee80211_hdr *hdr); +u16 (*rx_desc_get_mpdu_frame_ctl)(struct hal_rx_desc *desc); +void (*rx_desc_get_crypto_header)(struct hal_rx_desc *desc, +u8 *crypto_hdr, +enum hal_encrypt_type enctype); +int (*create_srng_config)(struct ath12k_base *ab); +bool (*dp_rx_h_msdu_done)(struct hal_rx_desc *desc); +bool (*dp_rx_h_l4_cksum_fail)(struct hal_rx_desc *desc); +bool (*dp_rx_h_ip_cksum_fail)(struct hal_rx_desc *desc); +bool (*dp_rx_h_is_decrypted)(struct hal_rx_desc *desc); +u32 (*dp_rx_h_mpdu_err)(struct hal_rx_desc *desc); +const struct ath12k_hal_tcl_to_wbm_rbm_map *tcl_to_wbm_rbm_map; +}; + +extern const struct hal_ops hal_qcn9274_ops; +extern const struct hal_ops hal_wcn7850_ops; + +u32 ath12k_hal_reo_qdesc_size (u32 ba_window_size,u8 tid); +void ath12k_hal_reo_qdesc_setup (struct hal_rx_reo_queue *qdesc, +int tid,u32 ba_window_size, +u32 start_seq,enum hal_pn_type type); +void ath12k_hal_reo_init_cmd_ring (struct ath12k_base *ab, +struct hal_srng *srng); +void ath12k_hal_reo_hw_setup (struct ath12k_base *ab,u32 ring_hash_map); +void ath12k_hal_setup_link_idle_list (struct ath12k_base *ab, +struct hal_wbm_idle_scatter_list *sbuf, +u32 nsbufs,u32 tot_link_desc, +u32 end_offset); + +dma_addr_t ath12k_hal_srng_get_tp_addr (struct ath12k_base *ab, +struct hal_srng *srng); +dma_addr_t ath12k_hal_srng_get_hp_addr (struct ath12k_base *ab, +struct hal_srng *srng); +void ath12k_hal_set_link_desc_addr (struct hal_wbm_link_desc *desc,u32 cookie, +dma_addr_t paddr); +u32 ath12k_hal_ce_get_desc_size (enum hal_ce_desc type); +void ath12k_hal_ce_src_set_desc (struct hal_ce_srng_src_desc *desc,dma_addr_t paddr, +u32 len,u32 id,u8 byte_swap_data); +void ath12k_hal_ce_dst_set_desc (struct hal_ce_srng_dest_desc *desc,dma_addr_t paddr); +u32 ath12k_hal_ce_dst_status_get_length (struct hal_ce_srng_dst_status_desc *desc); +int ath12k_hal_srng_get_entrysize (struct ath12k_base *ab,u32 ring_type); +int ath12k_hal_srng_get_max_entries (struct ath12k_base *ab,u32 ring_type); +void ath12k_hal_srng_get_params (struct ath12k_base *ab,struct hal_srng *srng, +struct hal_srng_params *params); +void *ath12k_hal_srng_dst_get_next_entry (struct ath12k_base *ab, +struct hal_srng *srng); +void *ath12k_hal_srng_dst_peek (struct ath12k_base *ab,struct hal_srng *srng); +int ath12k_hal_srng_dst_num_free (struct ath12k_base *ab,struct hal_srng *srng, +bool sync_hw_ptr); +void *ath12k_hal_srng_src_get_next_reaped (struct ath12k_base *ab, +struct hal_srng *srng); +void *ath12k_hal_srng_src_reap_next (struct ath12k_base *ab, +struct hal_srng *srng); +void *ath12k_hal_srng_src_get_next_entry (struct ath12k_base *ab, +struct hal_srng *srng); +int ath12k_hal_srng_src_num_free (struct ath12k_base *ab,struct hal_srng *srng, +bool sync_hw_ptr); +void ath12k_hal_srng_access_begin (struct ath12k_base *ab, +struct hal_srng *srng); +void ath12k_hal_srng_access_end (struct ath12k_base *ab,struct hal_srng *srng); +int ath12k_hal_srng_setup (struct ath12k_base *ab,enum hal_ring_type type, +int ring_num,int mac_id, +struct hal_srng_params *params); +int ath12k_hal_srng_init (struct ath12k_base *ath12k); +void ath12k_hal_srng_deinit (struct ath12k_base *ath12k); +void ath12k_hal_dump_srng_stats (struct ath12k_base *ab); +void ath12k_hal_srng_get_shadow_config (struct ath12k_base *ab, +u32 **cfg,u32 *len); +int ath12k_hal_srng_update_shadow_config (struct ath12k_base *ab, +enum hal_ring_type ring_type, +int ring_num); +void ath12k_hal_srng_shadow_config (struct ath12k_base *ab); +void ath12k_hal_srng_shadow_update_hp_tp (struct ath12k_base *ab, +struct hal_srng *srng); +#endif
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 18/50 wifi: ath12k: add dp_tx.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/dp_tx.h | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/net/wireless/ath/ath12k/dp_tx.h new file +41 -0
@@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#ifndef ATH12K_DP_TX_H +#define ATH12K_DP_TX_H + +#include "core.h" +#include "hal_tx.h" + +struct ath12k_dp_htt_wbm_tx_status { +bool acked; +int ack_rssi; +}; + +int ath12k_dp_tx_htt_h2t_ver_req_msg (struct ath12k_base *ab); +int ath12k_dp_tx (struct ath12k *ar,struct ath12k_vif *arvif, +struct sk_buff *skb); +void ath12k_dp_tx_completion_handler (struct ath12k_base *ab,int ring_id); + +int ath12k_dp_tx_htt_h2t_ppdu_stats_req (struct ath12k *ar,u32 mask); +int +ath12k_dp_tx_htt_h2t_ext_stats_req (struct ath12k *ar,u8 type, +struct htt_ext_stats_cfg_params *cfg_params, +u64 cookie); +int ath12k_dp_tx_htt_rx_monitor_mode_ring_config (struct ath12k *ar,bool reset); + +int ath12k_dp_tx_htt_rx_filter_setup (struct ath12k_base *ab,u32 ring_id, +int mac_id,enum hal_ring_type ring_type, +int rx_buf_size, +struct htt_rx_ring_tlv_filter *tlv_filter); +void ath12k_dp_tx_put_bank_profile (struct ath12k_dp *dp,u8 bank_id); +int ath12k_dp_tx_htt_tx_filter_setup (struct ath12k_base *ab,u32 ring_id, +int mac_id,enum hal_ring_type ring_type, +int tx_buf_size, +struct htt_tx_ring_tlv_filter *htt_tlv_filter); +int ath12k_dp_tx_htt_tx_monitor_mode_ring_config (struct ath12k *ar,bool reset); +int ath12k_dp_tx_htt_monitor_mode_ring_config (struct ath12k *ar,bool reset); +#endif
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 29/50 wifi: ath12k: add hw.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/hw.c | 1041 ++++++++++++++++++++++++++++++++++ 1 file changed, 1041 insertions(+)
drivers/net/wireless/ath/ath12k/hw.c new file +1041 -0
@@ -0,0 +1,1041 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include <linux/types.h> +#include <linux/bitops.h> +#include <linux/bitfield.h> + +#include "debug.h" +#include "core.h" +#include "ce.h" +#include "hw.h" +#include "mhi.h" +#include "dp_rx.h" + +static u8 ath12k_hw_qcn9274_mac_from_pdev_id (int pdev_idx) +{ +return pdev_idx; +} + +static int ath12k_hw_mac_id_to_pdev_id_qcn9274 (const struct ath12k_hw_params *hw, +int mac_id) +{ +return mac_id; +} + +static int ath12k_hw_mac_id_to_srng_id_qcn9274 (const struct ath12k_hw_params *hw, +int mac_id) +{ +return 0 ; +} + +static u8 ath12k_hw_get_ring_selector_qcn9274 (struct sk_buff *skb) +{ +return smp_processor_id (); +} + +static bool ath12k_dp_srng_is_comp_ring_qcn9274 (int ring_num) +{ +if (ring_num <3 || ring_num ==4 ) +return true; + +return false; +} + +static int ath12k_hw_mac_id_to_pdev_id_wcn7850 (const struct ath12k_hw_params *hw, +int mac_id) +{ +return 0 ; +} + +static int ath12k_hw_mac_id_to_srng_id_wcn7850 (const struct ath12k_hw_params *hw, +int mac_id) +{ +return mac_id; +} + +static u8 ath12k_hw_get_ring_selector_wcn7850 (struct sk_buff *skb) +{ +return skb_get_queue_mapping (skb); +} + +static bool ath12k_dp_srng_is_comp_ring_wcn7850 (int ring_num) +{ +if (ring_num ==0 || ring_num ==2 || ring_num ==4 ) +return true; + +return false; +} + +static const struct ath12k_hw_ops qcn9274_ops = { + .get_hw_mac_from_pdev_id = ath12k_hw_qcn9274_mac_from_pdev_id, + .mac_id_to_pdev_id = ath12k_hw_mac_id_to_pdev_id_qcn9274, + .mac_id_to_srng_id = ath12k_hw_mac_id_to_srng_id_qcn9274, + .rxdma_ring_sel_config = ath12k_dp_rxdma_ring_sel_config_qcn9274, + .get_ring_selector = ath12k_hw_get_ring_selector_qcn9274, + .dp_srng_is_tx_comp_ring = ath12k_dp_srng_is_comp_ring_qcn9274, +}; + +static const struct ath12k_hw_ops wcn7850_ops = { + .get_hw_mac_from_pdev_id = ath12k_hw_qcn9274_mac_from_pdev_id, + .mac_id_to_pdev_id = ath12k_hw_mac_id_to_pdev_id_wcn7850, + .mac_id_to_srng_id = ath12k_hw_mac_id_to_srng_id_wcn7850, + .rxdma_ring_sel_config = ath12k_dp_rxdma_ring_sel_config_wcn7850, + .get_ring_selector = ath12k_hw_get_ring_selector_wcn7850, + .dp_srng_is_tx_comp_ring = ath12k_dp_srng_is_comp_ring_wcn7850, +}; + +#define ATH12K_TX_RING_MASK_0 0x1 +#define ATH12K_TX_RING_MASK_1 0x2 +#define ATH12K_TX_RING_MASK_2 0x4 +#define ATH12K_TX_RING_MASK_3 0x8 +#define ATH12K_TX_RING_MASK_4 0x10 + +#define ATH12K_RX_RING_MASK_0 0x1 +#define ATH12K_RX_RING_MASK_1 0x2 +#define ATH12K_RX_RING_MASK_2 0x4 +#define ATH12K_RX_RING_MASK_3 0x8 + +#define ATH12K_RX_ERR_RING_MASK_0 0x1 + +#define ATH12K_RX_WBM_REL_RING_MASK_0 0x1 + +#define ATH12K_REO_STATUS_RING_MASK_0 0x1 + +#define ATH12K_HOST2RXDMA_RING_MASK_0 0x1 + +#define ATH12K_RX_MON_RING_MASK_0 0x1 +#define ATH12K_RX_MON_RING_MASK_1 0x2 +#define ATH12K_RX_MON_RING_MASK_2 0x4 + +#define ATH12K_TX_MON_RING_MASK_0 0x1 +#define ATH12K_TX_MON_RING_MASK_1 0x2 + +/* Target firmware's Copy Engine configuration. */ +static const struct ce_pipe_config ath12k_target_ce_config_wlan_qcn9274[] = { +/* CE0: host->target HTC control and raw streams */ + { + .pipenum =__cpu_to_le32 (0 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE1: target->host HTT + HTC control */ + { + .pipenum =__cpu_to_le32 (1 ), + .pipedir =__cpu_to_le32 (PIPEDIR_IN ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE2: target->host WMI */ + { + .pipenum =__cpu_to_le32 (2 ), + .pipedir =__cpu_to_le32 (PIPEDIR_IN ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE3: host->target WMI (mac0) */ + { + .pipenum =__cpu_to_le32 (3 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE4: host->target HTT */ + { + .pipenum =__cpu_to_le32 (4 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (256 ), + .nbytes_max =__cpu_to_le32 (256 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS |CE_ATTR_DIS_INTR ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE5: target->host Pktlog */ + { + .pipenum =__cpu_to_le32 (5 ), + .pipedir =__cpu_to_le32 (PIPEDIR_IN ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE6: Reserved for target autonomous hif_memcpy */ + { + .pipenum =__cpu_to_le32 (6 ), + .pipedir =__cpu_to_le32 (PIPEDIR_INOUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (16384 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE7: host->target WMI (mac1) */ + { + .pipenum =__cpu_to_le32 (7 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE8: Reserved for target autonomous hif_memcpy */ + { + .pipenum =__cpu_to_le32 (8 ), + .pipedir =__cpu_to_le32 (PIPEDIR_INOUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (16384 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE9, 10 and 11: Reserved for MHI */ + +/* CE12: Target CV prefetch */ + { + .pipenum =__cpu_to_le32 (12 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE13: Target CV prefetch */ + { + .pipenum =__cpu_to_le32 (13 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE14: WMI logging/CFR/Spectral/Radar */ + { + .pipenum =__cpu_to_le32 (14 ), + .pipedir =__cpu_to_le32 (PIPEDIR_IN ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE15: Reserved */ +}; + +/* Target firmware's Copy Engine configuration. */ +static const struct ce_pipe_config ath12k_target_ce_config_wlan_wcn7850[] = { +/* CE0: host->target HTC control and raw streams */ + { + .pipenum =__cpu_to_le32 (0 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE1: target->host HTT + HTC control */ + { + .pipenum =__cpu_to_le32 (1 ), + .pipedir =__cpu_to_le32 (PIPEDIR_IN ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE2: target->host WMI */ + { + .pipenum =__cpu_to_le32 (2 ), + .pipedir =__cpu_to_le32 (PIPEDIR_IN ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE3: host->target WMI */ + { + .pipenum =__cpu_to_le32 (3 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE4: host->target HTT */ + { + .pipenum =__cpu_to_le32 (4 ), + .pipedir =__cpu_to_le32 (PIPEDIR_OUT ), + .nentries =__cpu_to_le32 (256 ), + .nbytes_max =__cpu_to_le32 (256 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS |CE_ATTR_DIS_INTR ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE5: target->host Pktlog */ + { + .pipenum =__cpu_to_le32 (5 ), + .pipedir =__cpu_to_le32 (PIPEDIR_IN ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (2048 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE6: Reserved for target autonomous hif_memcpy */ + { + .pipenum =__cpu_to_le32 (6 ), + .pipedir =__cpu_to_le32 (PIPEDIR_INOUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (16384 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE7 used only by Host */ + { + .pipenum =__cpu_to_le32 (7 ), + .pipedir =__cpu_to_le32 (PIPEDIR_INOUT_H2H ), + .nentries =__cpu_to_le32 (0 ), + .nbytes_max =__cpu_to_le32 (0 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS |CE_ATTR_DIS_INTR ), + .reserved =__cpu_to_le32 (0 ), + }, + +/* CE8 target->host used only by IPA */ + { + .pipenum =__cpu_to_le32 (8 ), + .pipedir =__cpu_to_le32 (PIPEDIR_INOUT ), + .nentries =__cpu_to_le32 (32 ), + .nbytes_max =__cpu_to_le32 (16384 ), + .flags =__cpu_to_le32 (CE_ATTR_FLAGS ), + .reserved =__cpu_to_le32 (0 ), + }, +/* CE 9, 10, 11 are used by MHI driver */ +}; + +/* Map from service/endpoint to Copy Engine. +* This table is derived from the CE_PCI TABLE, above. +* It is passed to the Target at startup for use by firmware. +*/ +static const struct service_to_pipe ath12k_target_service_to_ce_map_wlan_qcn9274[] = { + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_VO ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_VO ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_BK ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_BK ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_BE ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_BE ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_VI ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_VI ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_CONTROL ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_CONTROL ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_RSVD_CTRL ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (0 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_RSVD_CTRL ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (1 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_TEST_RAW_STREAMS ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (0 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_TEST_RAW_STREAMS ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (1 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_HTT_DATA_MSG ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (4 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_HTT_DATA_MSG ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (1 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_CONTROL_MAC1 ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (7 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_CONTROL_MAC1 ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_PKT_LOG ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (5 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_CONTROL_DIAG ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (14 ), + }, + +/* (Additions here) */ + + {/* must be last */ +__cpu_to_le32 (0 ), +__cpu_to_le32 (0 ), +__cpu_to_le32 (0 ), + }, +}; + +static const struct service_to_pipe ath12k_target_service_to_ce_map_wlan_wcn7850[] = { + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_VO ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_VO ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_BK ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_BK ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_BE ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_BE ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_VI ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_DATA_VI ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_CONTROL ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (3 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_WMI_CONTROL ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_RSVD_CTRL ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (0 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_RSVD_CTRL ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (2 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_HTT_DATA_MSG ), +__cpu_to_le32 (PIPEDIR_OUT ),/* out = UL = host -> target */ +__cpu_to_le32 (4 ), + }, + { +__cpu_to_le32 (ATH12K_HTC_SVC_ID_HTT_DATA_MSG ), +__cpu_to_le32 (PIPEDIR_IN ),/* in = DL = target -> host */ +__cpu_to_le32 (1 ), + }, + +/* (Additions here) */ + + {/* must be last */ +__cpu_to_le32 (0 ), +__cpu_to_le32 (0 ), +__cpu_to_le32 (0 ), + }, +}; + +static const struct ath12k_hw_ring_mask ath12k_hw_ring_mask_qcn9274 = { + .tx = { +ATH12K_TX_RING_MASK_0 , +ATH12K_TX_RING_MASK_1 , +ATH12K_TX_RING_MASK_2 , +ATH12K_TX_RING_MASK_3 , + }, + .rx_mon_dest = { +0 ,0 ,0 , +ATH12K_RX_MON_RING_MASK_0 , +ATH12K_RX_MON_RING_MASK_1 , +ATH12K_RX_MON_RING_MASK_2 , + }, + .rx = { +0 ,0 ,0 ,0 , +ATH12K_RX_RING_MASK_0 , +ATH12K_RX_RING_MASK_1 , +ATH12K_RX_RING_MASK_2 , +ATH12K_RX_RING_MASK_3 , + }, + .rx_err = { +0 ,0 ,0 , +ATH12K_RX_ERR_RING_MASK_0 , + }, + .rx_wbm_rel = { +0 ,0 ,0 , +ATH12K_RX_WBM_REL_RING_MASK_0 , + }, + .reo_status = { +0 ,0 ,0 , +ATH12K_REO_STATUS_RING_MASK_0 , + }, + .host2rxdma = { +0 ,0 ,0 , +ATH12K_HOST2RXDMA_RING_MASK_0 , + }, + .tx_mon_dest = { +ATH12K_TX_MON_RING_MASK_0 , +ATH12K_TX_MON_RING_MASK_1 , + }, +}; + +static const struct ath12k_hw_ring_mask ath12k_hw_ring_mask_wcn7850 = { + .tx = { +ATH12K_TX_RING_MASK_0 , +ATH12K_TX_RING_MASK_2 , +ATH12K_TX_RING_MASK_4 , + }, + .rx_mon_dest = { + }, + .rx = { +0 ,0 ,0 , +ATH12K_RX_RING_MASK_0 , +ATH12K_RX_RING_MASK_1 , +ATH12K_RX_RING_MASK_2 , +ATH12K_RX_RING_MASK_3 , + }, + .rx_err = { +ATH12K_RX_ERR_RING_MASK_0 , + }, + .rx_wbm_rel = { +ATH12K_RX_WBM_REL_RING_MASK_0 , + }, + .reo_status = { +ATH12K_REO_STATUS_RING_MASK_0 , + }, + .host2rxdma = { + }, + .tx_mon_dest = { + }, +}; + +static const struct ath12k_hw_regs qcn9274_v1_regs = { +/* SW2TCL(x) R0 ring configuration address */ + .hal_tcl1_ring_id =0x00000908 , + .hal_tcl1_ring_misc =0x00000910 , + .hal_tcl1_ring_tp_addr_lsb =0x0000091c , + .hal_tcl1_ring_tp_addr_msb =0x00000920 , + .hal_tcl1_ring_consumer_int_setup_ix0 =0x00000930 , + .hal_tcl1_ring_consumer_int_setup_ix1 =0x00000934 , + .hal_tcl1_ring_msi1_base_lsb =0x00000948 , + .hal_tcl1_ring_msi1_base_msb =0x0000094c , + .hal_tcl1_ring_msi1_data =0x00000950 , + .hal_tcl_ring_base_lsb =0x00000b58 , + +/* TCL STATUS ring address */ + .hal_tcl_status_ring_base_lsb =0x00000d38 , + + .hal_wbm_idle_ring_base_lsb =0x00000d0c , + .hal_wbm_idle_ring_misc_addr =0x00000d1c , + .hal_wbm_r0_idle_list_cntl_addr =0x00000210 , + .hal_wbm_r0_idle_list_size_addr =0x00000214 , + .hal_wbm_scattered_ring_base_lsb =0x00000220 , + .hal_wbm_scattered_ring_base_msb =0x00000224 , + .hal_wbm_scattered_desc_head_info_ix0 =0x00000230 , + .hal_wbm_scattered_desc_head_info_ix1 =0x00000234 , + .hal_wbm_scattered_desc_tail_info_ix0 =0x00000240 , + .hal_wbm_scattered_desc_tail_info_ix1 =0x00000244 , + .hal_wbm_scattered_desc_ptr_hp_addr =0x0000024c , + + .hal_wbm_sw_release_ring_base_lsb =0x0000034c , + .hal_wbm_sw1_release_ring_base_lsb =0x000003c4 , + .hal_wbm0_release_ring_base_lsb =0x00000dd8 , + .hal_wbm1_release_ring_base_lsb =0x00000e50 , + +/* PCIe base address */ + .pcie_qserdes_sysclk_en_sel =0x01e0c0a8 , + .pcie_pcs_osc_dtct_config_base =0x01e0d45c , + +/* PPE release ring address */ + .hal_ppe_rel_ring_base =0x0000043c , + +/* REO DEST ring address */ + .hal_reo2_ring_base =0x0000055c , + .hal_reo1_misc_ctrl_addr =0x00000b7c , + .hal_reo1_sw_cookie_cfg0 =0x00000050 , + .hal_reo1_sw_cookie_cfg1 =0x00000054 , + .hal_reo1_qdesc_lut_base0 =0x00000058 , + .hal_reo1_qdesc_lut_base1 =0x0000005c , + .hal_reo1_ring_base_lsb =0x000004e4 , + .hal_reo1_ring_base_msb =0x000004e8 , + .hal_reo1_ring_id =0x000004ec , + .hal_reo1_ring_misc =0x000004f4 , + .hal_reo1_ring_hp_addr_lsb =0x000004f8 , + .hal_reo1_ring_hp_addr_msb =0x000004fc , + .hal_reo1_ring_producer_int_setup =0x00000508 , + .hal_reo1_ring_msi1_base_lsb =0x0000052C , + .hal_reo1_ring_msi1_base_msb =0x00000530 , + .hal_reo1_ring_msi1_data =0x00000534 , + .hal_reo1_aging_thres_ix0 =0x00000b08 , + .hal_reo1_aging_thres_ix1 =0x00000b0c , + .hal_reo1_aging_thres_ix2 =0x00000b10 , + .hal_reo1_aging_thres_ix3 =0x00000b14 , + +/* REO Exception ring address */ + .hal_reo2_sw0_ring_base =0x000008a4 , + +/* REO Reinject ring address */ + .hal_sw2reo_ring_base =0x00000304 , + .hal_sw2reo1_ring_base =0x0000037c , + +/* REO cmd ring address */ + .hal_reo_cmd_ring_base =0x0000028c , + +/* REO status ring address */ + .hal_reo_status_ring_base =0x00000a84 , +}; + +static const struct ath12k_hw_regs qcn9274_v2_regs = { +/* SW2TCL(x) R0 ring configuration address */ + .hal_tcl1_ring_id =0x00000908 , + .hal_tcl1_ring_misc =0x00000910 , + .hal_tcl1_ring_tp_addr_lsb =0x0000091c , + .hal_tcl1_ring_tp_addr_msb =0x00000920 , + .hal_tcl1_ring_consumer_int_setup_ix0 =0x00000930 , + .hal_tcl1_ring_consumer_int_setup_ix1 =0x00000934 , + .hal_tcl1_ring_msi1_base_lsb =0x00000948 , + .hal_tcl1_ring_msi1_base_msb =0x0000094c , + .hal_tcl1_ring_msi1_data =0x00000950 , + .hal_tcl_ring_base_lsb =0x00000b58 , + +/* TCL STATUS ring address */ + .hal_tcl_status_ring_base_lsb =0x00000d38 , + +/* WBM idle link ring address */ + .hal_wbm_idle_ring_base_lsb =0x00000d3c , + .hal_wbm_idle_ring_misc_addr =0x00000d4c , + .hal_wbm_r0_idle_list_cntl_addr =0x00000240 , + .hal_wbm_r0_idle_list_size_addr =0x00000244 , + .hal_wbm_scattered_ring_base_lsb =0x00000250 , + .hal_wbm_scattered_ring_base_msb =0x00000254 , + .hal_wbm_scattered_desc_head_info_ix0 =0x00000260 , + .hal_wbm_scattered_desc_head_info_ix1 =0x00000264 , + .hal_wbm_scattered_desc_tail_info_ix0 =0x00000270 , + .hal_wbm_scattered_desc_tail_info_ix1 =0x00000274 , + .hal_wbm_scattered_desc_ptr_hp_addr =0x0000027c , + +/* SW2WBM release ring address */ + .hal_wbm_sw_release_ring_base_lsb =0x0000037c , + .hal_wbm_sw1_release_ring_base_lsb =0x000003f4 , + +/* WBM2SW release ring address */ + .hal_wbm0_release_ring_base_lsb =0x00000e08 , + .hal_wbm1_release_ring_base_lsb =0x00000e80 , + +/* PCIe base address */ + .pcie_qserdes_sysclk_en_sel =0x01e0c0a8 , + .pcie_pcs_osc_dtct_config_base =0x01e0d45c , + +/* PPE release ring address */ + .hal_ppe_rel_ring_base =0x0000046c , + +/* REO DEST ring address */ + .hal_reo2_ring_base =0x00000578 , + .hal_reo1_misc_ctrl_addr =0x00000b9c , + .hal_reo1_sw_cookie_cfg0 =0x0000006c , + .hal_reo1_sw_cookie_cfg1 =0x00000070 , + .hal_reo1_qdesc_lut_base0 =0x00000074 , + .hal_reo1_qdesc_lut_base1 =0x00000078 , + .hal_reo1_ring_base_lsb =0x00000500 , + .hal_reo1_ring_base_msb =0x00000504 , + .hal_reo1_ring_id =0x00000508 , + .hal_reo1_ring_misc =0x00000510 , + .hal_reo1_ring_hp_addr_lsb =0x00000514 , + .hal_reo1_ring_hp_addr_msb =0x00000518 , + .hal_reo1_ring_producer_int_setup =0x00000524 , + .hal_reo1_ring_msi1_base_lsb =0x00000548 , + .hal_reo1_ring_msi1_base_msb =0x0000054C , + .hal_reo1_ring_msi1_data =0x00000550 , + .hal_reo1_aging_thres_ix0 =0x00000B28 , + .hal_reo1_aging_thres_ix1 =0x00000B2C , + .hal_reo1_aging_thres_ix2 =0x00000B30 , + .hal_reo1_aging_thres_ix3 =0x00000B34 , + +/* REO Exception ring address */ + .hal_reo2_sw0_ring_base =0x000008c0 , + +/* REO Reinject ring address */ + .hal_sw2reo_ring_base =0x00000320 , + .hal_sw2reo1_ring_base =0x00000398 , + +/* REO cmd ring address */ + .hal_reo_cmd_ring_base =0x000002A8 , + +/* REO status ring address */ + .hal_reo_status_ring_base =0x00000aa0 , +}; + +static const struct ath12k_hw_regs wcn7850_regs = { +/* SW2TCL(x) R0 ring configuration address */ + .hal_tcl1_ring_id =0x00000908 , + .hal_tcl1_ring_misc =0x00000910 , + .hal_tcl1_ring_tp_addr_lsb =0x0000091c , + .hal_tcl1_ring_tp_addr_msb =0x00000920 , + .hal_tcl1_ring_consumer_int_setup_ix0 =0x00000930 , + .hal_tcl1_ring_consumer_int_setup_ix1 =0x00000934 , + .hal_tcl1_ring_msi1_base_lsb =0x00000948 , + .hal_tcl1_ring_msi1_base_msb =0x0000094c , + .hal_tcl1_ring_msi1_data =0x00000950 , + .hal_tcl_ring_base_lsb =0x00000b58 , + +/* TCL STATUS ring address */ + .hal_tcl_status_ring_base_lsb =0x00000d38 , + + .hal_wbm_idle_ring_base_lsb =0x00000d3c , + .hal_wbm_idle_ring_misc_addr =0x00000d4c , + .hal_wbm_r0_idle_list_cntl_addr =0x00000240 , + .hal_wbm_r0_idle_list_size_addr =0x00000244 , + .hal_wbm_scattered_ring_base_lsb =0x00000250 , + .hal_wbm_scattered_ring_base_msb =0x00000254 , + .hal_wbm_scattered_desc_head_info_ix0 =0x00000260 , + .hal_wbm_scattered_desc_head_info_ix1 =0x00000264 , + .hal_wbm_scattered_desc_tail_info_ix0 =0x00000270 , + .hal_wbm_scattered_desc_tail_info_ix1 =0x00000274 , + .hal_wbm_scattered_desc_ptr_hp_addr =0x00000027c , + + .hal_wbm_sw_release_ring_base_lsb =0x0000037c , + .hal_wbm_sw1_release_ring_base_lsb =0x00000284 , + .hal_wbm0_release_ring_base_lsb =0x00000e08 , + .hal_wbm1_release_ring_base_lsb =0x00000e80 , + +/* PCIe base address */ + .pcie_qserdes_sysclk_en_sel =0x01e0e0a8 , + .pcie_pcs_osc_dtct_config_base =0x01e0f45c , + +/* PPE release ring address */ + .hal_ppe_rel_ring_base =0x0000043c , + +/* REO DEST ring address */ + .hal_reo2_ring_base =0x0000055c , + .hal_reo1_misc_ctrl_addr =0x00000b7c , + .hal_reo1_sw_cookie_cfg0 =0x00000050 , + .hal_reo1_sw_cookie_cfg1 =0x00000054 , + .hal_reo1_qdesc_lut_base0 =0x00000058 , + .hal_reo1_qdesc_lut_base1 =0x0000005c , + .hal_reo1_ring_base_lsb =0x000004e4 , + .hal_reo1_ring_base_msb =0x000004e8 , + .hal_reo1_ring_id =0x000004ec , + .hal_reo1_ring_misc =0x000004f4 , + .hal_reo1_ring_hp_addr_lsb =0x000004f8 , + .hal_reo1_ring_hp_addr_msb =0x000004fc , + .hal_reo1_ring_producer_int_setup =0x00000508 , + .hal_reo1_ring_msi1_base_lsb =0x0000052C , + .hal_reo1_ring_msi1_base_msb =0x00000530 , + .hal_reo1_ring_msi1_data =0x00000534 , + .hal_reo1_aging_thres_ix0 =0x00000b08 , + .hal_reo1_aging_thres_ix1 =0x00000b0c , + .hal_reo1_aging_thres_ix2 =0x00000b10 , + .hal_reo1_aging_thres_ix3 =0x00000b14 , + +/* REO Exception ring address */ + .hal_reo2_sw0_ring_base =0x000008a4 , + +/* REO Reinject ring address */ + .hal_sw2reo_ring_base =0x00000304 , + .hal_sw2reo1_ring_base =0x0000037c , + +/* REO cmd ring address */ + .hal_reo_cmd_ring_base =0x0000028c , + +/* REO status ring address */ + .hal_reo_status_ring_base =0x00000a84 , +}; + +static const struct ath12k_hw_hal_params ath12k_hw_hal_params_qcn9274 = { + .rx_buf_rbm =HAL_RX_BUF_RBM_SW3_BM , + .wbm2sw_cc_enable =HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW0_EN | +HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW1_EN | +HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW2_EN | +HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW3_EN | +HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW4_EN , +}; + +static const struct ath12k_hw_hal_params ath12k_hw_hal_params_wcn7850 = { + .rx_buf_rbm =HAL_RX_BUF_RBM_SW1_BM , + .wbm2sw_cc_enable =HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW0_EN | +HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW2_EN | +HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW3_EN | +HAL_WBM_SW_COOKIE_CONV_CFG_WBM2SW4_EN , +}; + +static const struct ath12k_hw_params ath12k_hw_params[] = { + { + .name ="qcn9274 hw1.0" , + .hw_rev =ATH12K_HW_QCN9274_HW10 , + .fw = { + .dir ="QCN9274/hw1.0" , + .board_size =256 *1024 , + .cal_offset =128 *1024 , + }, + .max_radios =1 , + .single_pdev_only = false, + .qmi_service_ins_id =ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9274 , + .internal_sleep_clock = false, + + .hw_ops = &qcn9274_ops, + .ring_mask = &ath12k_hw_ring_mask_qcn9274, + .regs = &qcn9274_v1_regs, + + .host_ce_config = ath12k_host_ce_config_qcn9274, + .ce_count =16 , + .target_ce_config = ath12k_target_ce_config_wlan_qcn9274, + .target_ce_count =12 , + .svc_to_ce_map = ath12k_target_service_to_ce_map_wlan_qcn9274, + .svc_to_ce_map_len =18 , + + .hal_params = &ath12k_hw_hal_params_qcn9274, + + .rxdma1_enable = false, + .num_rxmda_per_pdev =1 , + .num_rxdma_dst_ring =0 , + .rx_mac_buf_ring = false, + .vdev_start_delay = false, + + .interface_modes =BIT (NL80211_IFTYPE_STATION ) | +BIT (NL80211_IFTYPE_AP ), + .supports_monitor = false, + + .idle_ps = false, + .download_calib = true, + .supports_suspend = false, + .tcl_ring_retry = true, + .reoq_lut_support = false, + .supports_shadow_regs = false, + + .hal_desc_sz =sizeof (struct hal_rx_desc_qcn9274 ), + .num_tcl_banks =48 , + .max_tx_ring =4 , + + .mhi_config = &ath12k_mhi_config_qcn9274, + + .wmi_init = ath12k_wmi_init_qcn9274, + + .hal_ops = &hal_qcn9274_ops, + + }, + { + .name ="wcn7850 hw2.0" , + .hw_rev =ATH12K_HW_WCN7850_HW20 , + + .fw = { + .dir ="WCN7850/hw2.0" , + .board_size =256 *1024 , + .cal_offset =256 *1024 , + }, + + .max_radios =1 , + .single_pdev_only = true, + .qmi_service_ins_id =ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_WCN7850 , + .internal_sleep_clock = true, + + .hw_ops = &wcn7850_ops, + .ring_mask = &ath12k_hw_ring_mask_wcn7850, + .regs = &wcn7850_regs, + + .host_ce_config = ath12k_host_ce_config_wcn7850, + .ce_count =9 , + .target_ce_config = ath12k_target_ce_config_wlan_wcn7850, + .target_ce_count =9 , + .svc_to_ce_map = ath12k_target_service_to_ce_map_wlan_wcn7850, + .svc_to_ce_map_len =14 , + + .hal_params = &ath12k_hw_hal_params_wcn7850, + + .rxdma1_enable = false, + .num_rxmda_per_pdev =2 , + .num_rxdma_dst_ring =1 , + .rx_mac_buf_ring = true, + .vdev_start_delay = true, + + .interface_modes =BIT (NL80211_IFTYPE_STATION ), + .supports_monitor = false, + + .idle_ps = false, + .download_calib = false, + .supports_suspend = false, + .tcl_ring_retry = false, + .reoq_lut_support = false, + .supports_shadow_regs = true, + + .hal_desc_sz =sizeof (struct hal_rx_desc_wcn7850 ), + .num_tcl_banks =7 , + .max_tx_ring =3 , + + .mhi_config = &ath12k_mhi_config_wcn7850, + + .wmi_init = ath12k_wmi_init_wcn7850, + + .hal_ops = &hal_wcn7850_ops, + }, + { + .name ="qcn9274 hw2.0" , + .hw_rev =ATH12K_HW_QCN9274_HW20 , + .fw = { + .dir ="QCN9274/hw2.0" , + .board_size =256 *1024 , + .cal_offset =128 *1024 , + }, + .max_radios =1 , + .single_pdev_only = false, + .qmi_service_ins_id =ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9274 , + .internal_sleep_clock = false, + + .hw_ops = &qcn9274_ops, + .ring_mask = &ath12k_hw_ring_mask_qcn9274, + .regs = &qcn9274_v2_regs, + + .host_ce_config = ath12k_host_ce_config_qcn9274, + .ce_count =16 , + .target_ce_config = ath12k_target_ce_config_wlan_qcn9274, + .target_ce_count =12 , + .svc_to_ce_map = ath12k_target_service_to_ce_map_wlan_qcn9274, + .svc_to_ce_map_len =18 , + + .hal_params = &ath12k_hw_hal_params_qcn9274, + + .rxdma1_enable = false, + .num_rxmda_per_pdev =1 , + .num_rxdma_dst_ring =0 , + .rx_mac_buf_ring = false, + .vdev_start_delay = false, + + .interface_modes =BIT (NL80211_IFTYPE_STATION ) | +BIT (NL80211_IFTYPE_AP ), + .supports_monitor = false, + + .idle_ps = false, + .download_calib = true, + .supports_suspend = false, + .tcl_ring_retry = true, + .reoq_lut_support = false, + .supports_shadow_regs = false, + + .hal_desc_sz =sizeof (struct hal_rx_desc_qcn9274 ), + .num_tcl_banks =48 , + .max_tx_ring =4 , + + .mhi_config = &ath12k_mhi_config_qcn9274, + + .wmi_init = ath12k_wmi_init_qcn9274, + + .hal_ops = &hal_qcn9274_ops, + }, +}; + +int ath12k_hw_init (struct ath12k_base *ab) +{ +const struct ath12k_hw_params *hw_params =NULL ; +int i; + +for (i =0 ; i <ARRAY_SIZE (ath12k_hw_params); i++) { + hw_params = &ath12k_hw_params[i]; + +if (hw_params->hw_rev == ab->hw_rev) +break ; + } + +if (i ==ARRAY_SIZE (ath12k_hw_params)) { +ath12k_err (ab,"Unsupported hardware version: 0x%x\n" , ab->hw_rev); +return -EINVAL ; + } + + ab->hw_params = hw_params; + +ath12k_info (ab,"Hardware name: %s\n" , ab->hw_params->name); + +return 0 ; +}
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 32/50 wifi: ath12k: add mac.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/mac.h | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
drivers/net/wireless/ath/ath12k/mac.h new file +76 -0
@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#ifndef ATH12K_MAC_H +#define ATH12K_MAC_H + +#include <net/mac80211.h> +#include <net/cfg80211.h> + +struct ath12k ; +struct ath12k_base ; + +struct ath12k_generic_iter { +struct ath12k *ar; +int ret; +}; + +/* number of failed packets (20 packets with 16 sw reties each) */ +#define ATH12K_KICKOUT_THRESHOLD (20 * 16) + +/* Use insanely high numbers to make sure that the firmware implementation +* won't start, we have the same functionality already in hostapd. Unit +* is seconds. +*/ +#define ATH12K_KEEPALIVE_MIN_IDLE 3747 +#define ATH12K_KEEPALIVE_MAX_IDLE 3895 +#define ATH12K_KEEPALIVE_MAX_UNRESPONSIVE 3900 + +/* FIXME: should these be in ieee80211.h? */ +#define IEEE80211_VHT_MCS_SUPPORT_0_11_MASK GENMASK(23, 16) +#define IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11 BIT(24) + +#define ATH12K_CHAN_WIDTH_NUM 8 + +#define ATH12K_TX_POWER_MAX_VAL 70 +#define ATH12K_TX_POWER_MIN_VAL 0 + +enum ath12k_supported_bw { +ATH12K_BW_20 =0 , +ATH12K_BW_40 =1 , +ATH12K_BW_80 =2 , +ATH12K_BW_160 =3 , +}; + +extern const struct htt_rx_ring_tlv_filter ath12k_mac_mon_status_filter_default; + +void ath12k_mac_destroy (struct ath12k_base *ab); +void ath12k_mac_unregister (struct ath12k_base *ab); +int ath12k_mac_register (struct ath12k_base *ab); +int ath12k_mac_allocate (struct ath12k_base *ab); +int ath12k_mac_hw_ratecode_to_legacy_rate (u8 hw_rc,u8 preamble,u8 *rateidx, +u16 *rate); +u8 ath12k_mac_bitrate_to_idx (const struct ieee80211_supported_band *sband, +u32 bitrate); +u8 ath12k_mac_hw_rate_to_idx (const struct ieee80211_supported_band *sband, +u8 hw_rate,bool cck); + +void __ath12k_mac_scan_finish (struct ath12k *ar); +void ath12k_mac_scan_finish (struct ath12k *ar); + +struct ath12k_vif *ath12k_mac_get_arvif (struct ath12k *ar,u32 vdev_id); +struct ath12k_vif *ath12k_mac_get_arvif_by_vdev_id (struct ath12k_base *ab, +u32 vdev_id); +struct ath12k *ath12k_mac_get_ar_by_vdev_id (struct ath12k_base *ab,u32 vdev_id); +struct ath12k *ath12k_mac_get_ar_by_pdev_id (struct ath12k_base *ab,u32 pdev_id); + +void ath12k_mac_drain_tx (struct ath12k *ar); +void ath12k_mac_peer_cleanup_all (struct ath12k *ar); +int ath12k_mac_tx_mgmt_pending_free (int buf_id,void *skb,void *ctx); +enum rate_info_bw ath12k_mac_bw_to_mac80211_bw (enum ath12k_supported_bw bw); +enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw (enum rate_info_bw bw); +enum hal_encrypt_type ath12k_dp_tx_get_encrypt_type (u32 cipher); +#endif
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 34/50 wifi: ath12k: add mhi.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/mhi.h | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/net/wireless/ath/ath12k/mhi.h new file +46 -0
@@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2020-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ +#ifndef _ATH12K_MHI_H +#define _ATH12K_MHI_H + +#include "pci.h" + +#define PCIE_TXVECDB 0x360 +#define PCIE_TXVECSTATUS 0x368 +#define PCIE_RXVECDB 0x394 +#define PCIE_RXVECSTATUS 0x39C + +#define MHISTATUS 0x48 +#define MHICTRL 0x38 +#define MHICTRL_RESET_MASK 0x2 + +enum ath12k_mhi_state { +ATH12K_MHI_INIT , +ATH12K_MHI_DEINIT , +ATH12K_MHI_POWER_ON , +ATH12K_MHI_POWER_OFF , +ATH12K_MHI_FORCE_POWER_OFF , +ATH12K_MHI_SUSPEND , +ATH12K_MHI_RESUME , +ATH12K_MHI_TRIGGER_RDDM , +ATH12K_MHI_RDDM , +ATH12K_MHI_RDDM_DONE , +}; + +extern const struct mhi_controller_config ath12k_mhi_config_qcn9274; +extern const struct mhi_controller_config ath12k_mhi_config_wcn7850; + +int ath12k_mhi_start (struct ath12k_pci *ar_pci); +void ath12k_mhi_stop (struct ath12k_pci *ar_pci); +int ath12k_mhi_register (struct ath12k_pci *ar_pci); +void ath12k_mhi_unregister (struct ath12k_pci *ar_pci); +void ath12k_mhi_set_mhictrl_reset (struct ath12k_base *ab); +void ath12k_mhi_clear_vector (struct ath12k_base *ab); + +void ath12k_mhi_suspend (struct ath12k_pci *ar_pci); +void ath12k_mhi_resume (struct ath12k_pci *ar_pci); + +#endif
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 37/50 wifi: ath12k: add peer.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/peer.c | 342 +++++++++++++++++++++++++++++++++ 1 file changed, 342 insertions(+)
drivers/net/wireless/ath/ath12k/peer.c new file +342 -0
@@ -0,0 +1,342 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include "core.h" +#include "peer.h" +#include "debug.h" + +struct ath12k_peer *ath12k_peer_find (struct ath12k_base *ab,int vdev_id, +const u8 *addr) +{ +struct ath12k_peer *peer; + +lockdep_assert_held (&ab->base_lock); + +list_for_each_entry (peer, &ab->peers, list) { +if (peer->vdev_id != vdev_id) +continue ; +if (!ether_addr_equal (peer->addr, addr)) +continue ; + +return peer; + } + +return NULL ; +} + +static struct ath12k_peer *ath12k_peer_find_by_pdev_idx (struct ath12k_base *ab, +u8 pdev_idx,const u8 *addr) +{ +struct ath12k_peer *peer; + +lockdep_assert_held (&ab->base_lock); + +list_for_each_entry (peer, &ab->peers, list) { +if (peer->pdev_idx != pdev_idx) +continue ; +if (!ether_addr_equal (peer->addr, addr)) +continue ; + +return peer; + } + +return NULL ; +} + +struct ath12k_peer *ath12k_peer_find_by_addr (struct ath12k_base *ab, +const u8 *addr) +{ +struct ath12k_peer *peer; + +lockdep_assert_held (&ab->base_lock); + +list_for_each_entry (peer, &ab->peers, list) { +if (!ether_addr_equal (peer->addr, addr)) +continue ; + +return peer; + } + +return NULL ; +} + +struct ath12k_peer *ath12k_peer_find_by_id (struct ath12k_base *ab, +int peer_id) +{ +struct ath12k_peer *peer; + +lockdep_assert_held (&ab->base_lock); + +list_for_each_entry (peer, &ab->peers, list) +if (peer_id == peer->peer_id) +return peer; + +return NULL ; +} + +bool ath12k_peer_exist_by_vdev_id (struct ath12k_base *ab,int vdev_id) +{ +struct ath12k_peer *peer; + +spin_lock_bh (&ab->base_lock); + +list_for_each_entry (peer, &ab->peers, list) { +if (vdev_id == peer->vdev_id) { +spin_unlock_bh (&ab->base_lock); +return true; + } + } +spin_unlock_bh (&ab->base_lock); +return false; +} + +struct ath12k_peer *ath12k_peer_find_by_ast (struct ath12k_base *ab, +int ast_hash) +{ +struct ath12k_peer *peer; + +lockdep_assert_held (&ab->base_lock); + +list_for_each_entry (peer, &ab->peers, list) +if (ast_hash == peer->ast_hash) +return peer; + +return NULL ; +} + +void ath12k_peer_unmap_event (struct ath12k_base *ab,u16 peer_id) +{ +struct ath12k_peer *peer; + +spin_lock_bh (&ab->base_lock); + + peer =ath12k_peer_find_by_id (ab, peer_id); +if (!peer) { +ath12k_warn (ab,"peer-unmap-event: unknown peer id %d\n" , + peer_id); + goto exit; + } + +ath12k_dbg (ab,ATH12K_DBG_DP_HTT ,"htt peer unmap vdev %d peer %pM id %d\n" , + peer->vdev_id, peer->addr, peer_id); + +list_del (&peer->list); +kfree (peer); +wake_up (&ab->peer_mapping_wq); + +exit: +spin_unlock_bh (&ab->base_lock); +} + +void ath12k_peer_map_event (struct ath12k_base *ab,u8 vdev_id,u16 peer_id, +u8 *mac_addr,u16 ast_hash,u16 hw_peer_id) +{ +struct ath12k_peer *peer; + +spin_lock_bh (&ab->base_lock); + peer =ath12k_peer_find (ab, vdev_id, mac_addr); +if (!peer) { + peer =kzalloc (sizeof (*peer),GFP_ATOMIC ); +if (!peer) + goto exit; + + peer->vdev_id = vdev_id; + peer->peer_id = peer_id; + peer->ast_hash = ast_hash; + peer->hw_peer_id = hw_peer_id; +ether_addr_copy (peer->addr, mac_addr); +list_add (&peer->list, &ab->peers); +wake_up (&ab->peer_mapping_wq); + } + +ath12k_dbg (ab,ATH12K_DBG_DP_HTT ,"htt peer map vdev %d peer %pM id %d\n" , + vdev_id, mac_addr, peer_id); + +exit: +spin_unlock_bh (&ab->base_lock); +} + +static int ath12k_wait_for_peer_common (struct ath12k_base *ab,int vdev_id, +const u8 *addr,bool expect_mapped) +{ +int ret; + + ret =wait_event_timeout (ab->peer_mapping_wq, ({ +bool mapped; + +spin_lock_bh (&ab->base_lock); + mapped = !!ath12k_peer_find (ab, vdev_id, addr); +spin_unlock_bh (&ab->base_lock); + + (mapped == expect_mapped || +test_bit (ATH12K_FLAG_CRASH_FLUSH , &ab->dev_flags)); + }),3 *HZ ); + +if (ret <=0 ) +return -ETIMEDOUT ; + +return 0 ; +} + +void ath12k_peer_cleanup (struct ath12k *ar,u32 vdev_id) +{ +struct ath12k_peer *peer, *tmp; +struct ath12k_base *ab = ar->ab; + +lockdep_assert_held (&ar->conf_mutex); + +spin_lock_bh (&ab->base_lock); +list_for_each_entry_safe (peer, tmp, &ab->peers, list) { +if (peer->vdev_id != vdev_id) +continue ; + +ath12k_warn (ab,"removing stale peer %pM from vdev_id %d\n" , + peer->addr, vdev_id); + +list_del (&peer->list); +kfree (peer); + ar->num_peers--; + } + +spin_unlock_bh (&ab->base_lock); +} + +static int ath12k_wait_for_peer_deleted (struct ath12k *ar,int vdev_id,const u8 *addr) +{ +return ath12k_wait_for_peer_common (ar->ab, vdev_id, addr, false); +} + +int ath12k_wait_for_peer_delete_done (struct ath12k *ar,u32 vdev_id, +const u8 *addr) +{ +int ret; +unsigned long time_left; + + ret =ath12k_wait_for_peer_deleted (ar, vdev_id, addr); +if (ret) { +ath12k_warn (ar->ab,"failed wait for peer deleted" ); +return ret; + } + + time_left =wait_for_completion_timeout (&ar->peer_delete_done, +3 *HZ ); +if (time_left ==0 ) { +ath12k_warn (ar->ab,"Timeout in receiving peer delete response\n" ); +return -ETIMEDOUT ; + } + +return 0 ; +} + +int ath12k_peer_delete (struct ath12k *ar,u32 vdev_id,u8 *addr) +{ +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +reinit_completion (&ar->peer_delete_done); + + ret =ath12k_wmi_send_peer_delete_cmd (ar, addr, vdev_id); +if (ret) { +ath12k_warn (ar->ab, +"failed to delete peer vdev_id %d addr %pM ret %d\n" , + vdev_id, addr, ret); +return ret; + } + + ret =ath12k_wait_for_peer_delete_done (ar, vdev_id, addr); +if (ret) +return ret; + + ar->num_peers--; + +return 0 ; +} + +static int ath12k_wait_for_peer_created (struct ath12k *ar,int vdev_id,const u8 *addr) +{ +return ath12k_wait_for_peer_common (ar->ab, vdev_id, addr, true); +} + +int ath12k_peer_create (struct ath12k *ar,struct ath12k_vif *arvif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_create_arg *arg) +{ +struct ath12k_peer *peer; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +if (ar->num_peers > (ar->max_num_peers -1 )) { +ath12k_warn (ar->ab, +"failed to create peer due to insufficient peer entry resource in firmware\n" ); +return -ENOBUFS ; + } + +spin_lock_bh (&ar->ab->base_lock); + peer =ath12k_peer_find_by_pdev_idx (ar->ab, ar->pdev_idx, arg->peer_addr); +if (peer) { +spin_unlock_bh (&ar->ab->base_lock); +return -EINVAL ; + } +spin_unlock_bh (&ar->ab->base_lock); + + ret =ath12k_wmi_send_peer_create_cmd (ar, arg); +if (ret) { +ath12k_warn (ar->ab, +"failed to send peer create vdev_id %d ret %d\n" , + arg->vdev_id, ret); +return ret; + } + + ret =ath12k_wait_for_peer_created (ar, arg->vdev_id, + arg->peer_addr); +if (ret) +return ret; + +spin_lock_bh (&ar->ab->base_lock); + + peer =ath12k_peer_find (ar->ab, arg->vdev_id, arg->peer_addr); +if (!peer) { +spin_unlock_bh (&ar->ab->base_lock); +ath12k_warn (ar->ab,"failed to find peer %pM on vdev %i after creation\n" , + arg->peer_addr, arg->vdev_id); + +reinit_completion (&ar->peer_delete_done); + + ret =ath12k_wmi_send_peer_delete_cmd (ar, arg->peer_addr, + arg->vdev_id); +if (ret) { +ath12k_warn (ar->ab,"failed to delete peer vdev_id %d addr %pM\n" , + arg->vdev_id, arg->peer_addr); +return ret; + } + + ret =ath12k_wait_for_peer_delete_done (ar, arg->vdev_id, + arg->peer_addr); +if (ret) +return ret; + +return -ENOENT ; + } + + peer->pdev_idx = ar->pdev_idx; + peer->sta = sta; + +if (arvif->vif->type ==NL80211_IFTYPE_STATION ) { + arvif->ast_hash = peer->ast_hash; + arvif->ast_idx = peer->hw_peer_id; + } + + peer->sec_type =HAL_ENCRYPT_TYPE_OPEN ; + peer->sec_type_grp =HAL_ENCRYPT_TYPE_OPEN ; + + ar->num_peers++; + +spin_unlock_bh (&ar->ab->base_lock); + +return 0 ; +}
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 31/50 wifi: ath12k: add mac.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/mac.c | 7038 +++++++++++++++++++++++++++++++++ 1 file changed, 7038 insertions(+)
drivers/net/wireless/ath/ath12k/mac.c new file +7038 -0
@@ -0,0 +1,7038 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include <net/mac80211.h> +#include <linux/etherdevice.h> +#include "mac.h" +#include "core.h" +#include "debug.h" +#include "wmi.h" +#include "hw.h" +#include "dp_tx.h" +#include "dp_rx.h" +#include "peer.h" + +#define CHAN2G (_channel, _freq, _flags) { \ + .band = NL80211_BAND_2GHZ, \ + .hw_value = (_channel), \ + .center_freq = (_freq), \ + .flags = (_flags), \ + .max_antenna_gain = 0, \ + .max_power = 30, \ +} + +#define CHAN5G (_channel, _freq, _flags) { \ + .band = NL80211_BAND_5GHZ, \ + .hw_value = (_channel), \ + .center_freq = (_freq), \ + .flags = (_flags), \ + .max_antenna_gain = 0, \ + .max_power = 30, \ +} + +#define CHAN6G (_channel, _freq, _flags) { \ + .band = NL80211_BAND_6GHZ, \ + .hw_value = (_channel), \ + .center_freq = (_freq), \ + .flags = (_flags), \ + .max_antenna_gain = 0, \ + .max_power = 30, \ +} + +static const struct ieee80211_channel ath12k_2ghz_channels[] = { +CHAN2G (1 ,2412 ,0 ), +CHAN2G (2 ,2417 ,0 ), +CHAN2G (3 ,2422 ,0 ), +CHAN2G (4 ,2427 ,0 ), +CHAN2G (5 ,2432 ,0 ), +CHAN2G (6 ,2437 ,0 ), +CHAN2G (7 ,2442 ,0 ), +CHAN2G (8 ,2447 ,0 ), +CHAN2G (9 ,2452 ,0 ), +CHAN2G (10 ,2457 ,0 ), +CHAN2G (11 ,2462 ,0 ), +CHAN2G (12 ,2467 ,0 ), +CHAN2G (13 ,2472 ,0 ), +CHAN2G (14 ,2484 ,0 ), +}; + +static const struct ieee80211_channel ath12k_5ghz_channels[] = { +CHAN5G (36 ,5180 ,0 ), +CHAN5G (40 ,5200 ,0 ), +CHAN5G (44 ,5220 ,0 ), +CHAN5G (48 ,5240 ,0 ), +CHAN5G (52 ,5260 ,0 ), +CHAN5G (56 ,5280 ,0 ), +CHAN5G (60 ,5300 ,0 ), +CHAN5G (64 ,5320 ,0 ), +CHAN5G (100 ,5500 ,0 ), +CHAN5G (104 ,5520 ,0 ), +CHAN5G (108 ,5540 ,0 ), +CHAN5G (112 ,5560 ,0 ), +CHAN5G (116 ,5580 ,0 ), +CHAN5G (120 ,5600 ,0 ), +CHAN5G (124 ,5620 ,0 ), +CHAN5G (128 ,5640 ,0 ), +CHAN5G (132 ,5660 ,0 ), +CHAN5G (136 ,5680 ,0 ), +CHAN5G (140 ,5700 ,0 ), +CHAN5G (144 ,5720 ,0 ), +CHAN5G (149 ,5745 ,0 ), +CHAN5G (153 ,5765 ,0 ), +CHAN5G (157 ,5785 ,0 ), +CHAN5G (161 ,5805 ,0 ), +CHAN5G (165 ,5825 ,0 ), +CHAN5G (169 ,5845 ,0 ), +CHAN5G (173 ,5865 ,0 ), +}; + +static const struct ieee80211_channel ath12k_6ghz_channels[] = { +CHAN6G (1 ,5955 ,0 ), +CHAN6G (5 ,5975 ,0 ), +CHAN6G (9 ,5995 ,0 ), +CHAN6G (13 ,6015 ,0 ), +CHAN6G (17 ,6035 ,0 ), +CHAN6G (21 ,6055 ,0 ), +CHAN6G (25 ,6075 ,0 ), +CHAN6G (29 ,6095 ,0 ), +CHAN6G (33 ,6115 ,0 ), +CHAN6G (37 ,6135 ,0 ), +CHAN6G (41 ,6155 ,0 ), +CHAN6G (45 ,6175 ,0 ), +CHAN6G (49 ,6195 ,0 ), +CHAN6G (53 ,6215 ,0 ), +CHAN6G (57 ,6235 ,0 ), +CHAN6G (61 ,6255 ,0 ), +CHAN6G (65 ,6275 ,0 ), +CHAN6G (69 ,6295 ,0 ), +CHAN6G (73 ,6315 ,0 ), +CHAN6G (77 ,6335 ,0 ), +CHAN6G (81 ,6355 ,0 ), +CHAN6G (85 ,6375 ,0 ), +CHAN6G (89 ,6395 ,0 ), +CHAN6G (93 ,6415 ,0 ), +CHAN6G (97 ,6435 ,0 ), +CHAN6G (101 ,6455 ,0 ), +CHAN6G (105 ,6475 ,0 ), +CHAN6G (109 ,6495 ,0 ), +CHAN6G (113 ,6515 ,0 ), +CHAN6G (117 ,6535 ,0 ), +CHAN6G (121 ,6555 ,0 ), +CHAN6G (125 ,6575 ,0 ), +CHAN6G (129 ,6595 ,0 ), +CHAN6G (133 ,6615 ,0 ), +CHAN6G (137 ,6635 ,0 ), +CHAN6G (141 ,6655 ,0 ), +CHAN6G (145 ,6675 ,0 ), +CHAN6G (149 ,6695 ,0 ), +CHAN6G (153 ,6715 ,0 ), +CHAN6G (157 ,6735 ,0 ), +CHAN6G (161 ,6755 ,0 ), +CHAN6G (165 ,6775 ,0 ), +CHAN6G (169 ,6795 ,0 ), +CHAN6G (173 ,6815 ,0 ), +CHAN6G (177 ,6835 ,0 ), +CHAN6G (181 ,6855 ,0 ), +CHAN6G (185 ,6875 ,0 ), +CHAN6G (189 ,6895 ,0 ), +CHAN6G (193 ,6915 ,0 ), +CHAN6G (197 ,6935 ,0 ), +CHAN6G (201 ,6955 ,0 ), +CHAN6G (205 ,6975 ,0 ), +CHAN6G (209 ,6995 ,0 ), +CHAN6G (213 ,7015 ,0 ), +CHAN6G (217 ,7035 ,0 ), +CHAN6G (221 ,7055 ,0 ), +CHAN6G (225 ,7075 ,0 ), +CHAN6G (229 ,7095 ,0 ), +CHAN6G (233 ,7115 ,0 ), +}; + +static struct ieee80211_rate ath12k_legacy_rates[] = { + { .bitrate =10 , + .hw_value =ATH12K_HW_RATE_CCK_LP_1M }, + { .bitrate =20 , + .hw_value =ATH12K_HW_RATE_CCK_LP_2M , + .hw_value_short =ATH12K_HW_RATE_CCK_SP_2M , + .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + { .bitrate =55 , + .hw_value =ATH12K_HW_RATE_CCK_LP_5_5M , + .hw_value_short =ATH12K_HW_RATE_CCK_SP_5_5M , + .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + { .bitrate =110 , + .hw_value =ATH12K_HW_RATE_CCK_LP_11M , + .hw_value_short =ATH12K_HW_RATE_CCK_SP_11M , + .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + + { .bitrate =60 , .hw_value =ATH12K_HW_RATE_OFDM_6M }, + { .bitrate =90 , .hw_value =ATH12K_HW_RATE_OFDM_9M }, + { .bitrate =120 , .hw_value =ATH12K_HW_RATE_OFDM_12M }, + { .bitrate =180 , .hw_value =ATH12K_HW_RATE_OFDM_18M }, + { .bitrate =240 , .hw_value =ATH12K_HW_RATE_OFDM_24M }, + { .bitrate =360 , .hw_value =ATH12K_HW_RATE_OFDM_36M }, + { .bitrate =480 , .hw_value =ATH12K_HW_RATE_OFDM_48M }, + { .bitrate =540 , .hw_value =ATH12K_HW_RATE_OFDM_54M }, +}; + +static const int +ath12k_phymodes[NUM_NL80211_BANDS ][ATH12K_CHAN_WIDTH_NUM ] = { + [NL80211_BAND_2GHZ ] = { + [NL80211_CHAN_WIDTH_5 ] =MODE_UNKNOWN , + [NL80211_CHAN_WIDTH_10 ] =MODE_UNKNOWN , + [NL80211_CHAN_WIDTH_20_NOHT ] =MODE_11AX_HE20_2G , + [NL80211_CHAN_WIDTH_20 ] =MODE_11AX_HE20_2G , + [NL80211_CHAN_WIDTH_40 ] =MODE_11AX_HE40_2G , + [NL80211_CHAN_WIDTH_80 ] =MODE_11AX_HE80_2G , + [NL80211_CHAN_WIDTH_80P80 ] =MODE_UNKNOWN , + [NL80211_CHAN_WIDTH_160 ] =MODE_UNKNOWN , + }, + [NL80211_BAND_5GHZ ] = { + [NL80211_CHAN_WIDTH_5 ] =MODE_UNKNOWN , + [NL80211_CHAN_WIDTH_10 ] =MODE_UNKNOWN , + [NL80211_CHAN_WIDTH_20_NOHT ] =MODE_11AX_HE20 , + [NL80211_CHAN_WIDTH_20 ] =MODE_11AX_HE20 , + [NL80211_CHAN_WIDTH_40 ] =MODE_11AX_HE40 , + [NL80211_CHAN_WIDTH_80 ] =MODE_11AX_HE80 , + [NL80211_CHAN_WIDTH_160 ] =MODE_11AX_HE160 , + [NL80211_CHAN_WIDTH_80P80 ] =MODE_11AX_HE80_80 , + }, + [NL80211_BAND_6GHZ ] = { + [NL80211_CHAN_WIDTH_5 ] =MODE_UNKNOWN , + [NL80211_CHAN_WIDTH_10 ] =MODE_UNKNOWN , + [NL80211_CHAN_WIDTH_20_NOHT ] =MODE_11AX_HE20 , + [NL80211_CHAN_WIDTH_20 ] =MODE_11AX_HE20 , + [NL80211_CHAN_WIDTH_40 ] =MODE_11AX_HE40 , + [NL80211_CHAN_WIDTH_80 ] =MODE_11AX_HE80 , + [NL80211_CHAN_WIDTH_160 ] =MODE_11AX_HE160 , + [NL80211_CHAN_WIDTH_80P80 ] =MODE_11AX_HE80_80 , + }, + +}; + +const struct htt_rx_ring_tlv_filter ath12k_mac_mon_status_filter_default = { + .rx_filter =HTT_RX_FILTER_TLV_FLAGS_MPDU_START | +HTT_RX_FILTER_TLV_FLAGS_PPDU_END | +HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE , + .pkt_filter_flags0 =HTT_RX_FP_MGMT_FILTER_FLAGS0 , + .pkt_filter_flags1 =HTT_RX_FP_MGMT_FILTER_FLAGS1 , + .pkt_filter_flags2 =HTT_RX_FP_CTRL_FILTER_FLASG2 , + .pkt_filter_flags3 =HTT_RX_FP_DATA_FILTER_FLASG3 | +HTT_RX_FP_CTRL_FILTER_FLASG3 +}; + +#define ATH12K_MAC_FIRST_OFDM_RATE_IDX 4 +#define ath12k_g_rates ath12k_legacy_rates +#define ath12k_g_rates_size (ARRAY_SIZE(ath12k_legacy_rates)) +#define ath12k_a_rates (ath12k_legacy_rates + 4) +#define ath12k_a_rates_size (ARRAY_SIZE(ath12k_legacy_rates) - 4) + +#define ATH12K_MAC_SCAN_TIMEOUT_MSECS 200/* in msecs */ + +static const u32 ath12k_smps_map[] = { + [WLAN_HT_CAP_SM_PS_STATIC ] =WMI_PEER_SMPS_STATIC , + [WLAN_HT_CAP_SM_PS_DYNAMIC ] =WMI_PEER_SMPS_DYNAMIC , + [WLAN_HT_CAP_SM_PS_INVALID ] =WMI_PEER_SMPS_PS_NONE , + [WLAN_HT_CAP_SM_PS_DISABLED ] =WMI_PEER_SMPS_PS_NONE , +}; + +static int ath12k_start_vdev_delay (struct ieee80211_hw *hw, +struct ieee80211_vif *vif); + +static const char *ath12k_mac_phymode_str (enum wmi_phy_mode mode) +{ +switch (mode) { +case MODE_11A : +return "11a" ; +case MODE_11G : +return "11g" ; +case MODE_11B : +return "11b" ; +case MODE_11GONLY : +return "11gonly" ; +case MODE_11NA_HT20 : +return "11na-ht20" ; +case MODE_11NG_HT20 : +return "11ng-ht20" ; +case MODE_11NA_HT40 : +return "11na-ht40" ; +case MODE_11NG_HT40 : +return "11ng-ht40" ; +case MODE_11AC_VHT20 : +return "11ac-vht20" ; +case MODE_11AC_VHT40 : +return "11ac-vht40" ; +case MODE_11AC_VHT80 : +return "11ac-vht80" ; +case MODE_11AC_VHT160 : +return "11ac-vht160" ; +case MODE_11AC_VHT80_80 : +return "11ac-vht80+80" ; +case MODE_11AC_VHT20_2G : +return "11ac-vht20-2g" ; +case MODE_11AC_VHT40_2G : +return "11ac-vht40-2g" ; +case MODE_11AC_VHT80_2G : +return "11ac-vht80-2g" ; +case MODE_11AX_HE20 : +return "11ax-he20" ; +case MODE_11AX_HE40 : +return "11ax-he40" ; +case MODE_11AX_HE80 : +return "11ax-he80" ; +case MODE_11AX_HE80_80 : +return "11ax-he80+80" ; +case MODE_11AX_HE160 : +return "11ax-he160" ; +case MODE_11AX_HE20_2G : +return "11ax-he20-2g" ; +case MODE_11AX_HE40_2G : +return "11ax-he40-2g" ; +case MODE_11AX_HE80_2G : +return "11ax-he80-2g" ; +case MODE_UNKNOWN : +/* skip */ +break ; + +/* no default handler to allow compiler to check that the +* enum is fully handled +*/ + } + +return "<unknown>" ; +} + +enum rate_info_bw +ath12k_mac_bw_to_mac80211_bw (enum ath12k_supported_bw bw) +{ +u8 ret =RATE_INFO_BW_20 ; + +switch (bw) { +case ATH12K_BW_20 : + ret =RATE_INFO_BW_20 ; +break ; +case ATH12K_BW_40 : + ret =RATE_INFO_BW_40 ; +break ; +case ATH12K_BW_80 : + ret =RATE_INFO_BW_80 ; +break ; +case ATH12K_BW_160 : + ret =RATE_INFO_BW_160 ; +break ; + } + +return ret; +} + +enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw (enum rate_info_bw bw) +{ +switch (bw) { +case RATE_INFO_BW_20 : +return ATH12K_BW_20 ; +case RATE_INFO_BW_40 : +return ATH12K_BW_40 ; +case RATE_INFO_BW_80 : +return ATH12K_BW_80 ; +case RATE_INFO_BW_160 : +return ATH12K_BW_160 ; +default : +return ATH12K_BW_20 ; + } +} + +int ath12k_mac_hw_ratecode_to_legacy_rate (u8 hw_rc,u8 preamble,u8 *rateidx, +u16 *rate) +{ +/* As default, it is OFDM rates */ +int i =ATH12K_MAC_FIRST_OFDM_RATE_IDX ; +int max_rates_idx = ath12k_g_rates_size; + +if (preamble ==WMI_RATE_PREAMBLE_CCK ) { + hw_rc &= ~ATH12K_HW_RATECODE_CCK_SHORT_PREAM_MASK ; + i =0 ; + max_rates_idx =ATH12K_MAC_FIRST_OFDM_RATE_IDX ; + } + +while (i < max_rates_idx) { +if (hw_rc == ath12k_legacy_rates[i].hw_value) { + *rateidx = i; + *rate = ath12k_legacy_rates[i].bitrate; +return 0 ; + } + i++; + } + +return -EINVAL ; +} + +u8 ath12k_mac_bitrate_to_idx (const struct ieee80211_supported_band *sband, +u32 bitrate) +{ +int i; + +for (i =0 ; i < sband->n_bitrates; i++) +if (sband->bitrates[i].bitrate == bitrate) +return i; + +return 0 ; +} + +static u32 +ath12k_mac_max_ht_nss (const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN ]) +{ +int nss; + +for (nss =IEEE80211_HT_MCS_MASK_LEN -1 ; nss >=0 ; nss--) +if (ht_mcs_mask[nss]) +return nss +1 ; + +return 1 ; +} + +static u32 +ath12k_mac_max_vht_nss (const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX ]) +{ +int nss; + +for (nss =NL80211_VHT_NSS_MAX -1 ; nss >=0 ; nss--) +if (vht_mcs_mask[nss]) +return nss +1 ; + +return 1 ; +} + +static u8 ath12k_parse_mpdudensity (u8 mpdudensity) +{ +/* From IEEE Std 802.11-2020 defined values for "Minimum MPDU Start Spacing": +* 0 for no restriction +* 1 for 1/4 us +* 2 for 1/2 us +* 3 for 1 us +* 4 for 2 us +* 5 for 4 us +* 6 for 8 us +* 7 for 16 us +*/ +switch (mpdudensity) { +case 0 : +return 0 ; +case 1 : +case 2 : +case 3 : +/* Our lower layer calculations limit our precision to +* 1 microsecond +*/ +return 1 ; +case 4 : +return 2 ; +case 5 : +return 4 ; +case 6 : +return 8 ; +case 7 : +return 16 ; +default : +return 0 ; + } +} + +static int ath12k_mac_vif_chan (struct ieee80211_vif *vif, +struct cfg80211_chan_def *def) +{ +struct ieee80211_chanctx_conf *conf; + +rcu_read_lock (); + conf =rcu_dereference (vif->bss_conf.chanctx_conf); +if (!conf) { +rcu_read_unlock (); +return -ENOENT ; + } + + *def = conf->def; +rcu_read_unlock (); + +return 0 ; +} + +static bool ath12k_mac_bitrate_is_cck (int bitrate) +{ +switch (bitrate) { +case 10 : +case 20 : +case 55 : +case 110 : +return true; + } + +return false; +} + +u8 ath12k_mac_hw_rate_to_idx (const struct ieee80211_supported_band *sband, +u8 hw_rate,bool cck) +{ +const struct ieee80211_rate *rate; +int i; + +for (i =0 ; i < sband->n_bitrates; i++) { + rate = &sband->bitrates[i]; + +if (ath12k_mac_bitrate_is_cck (rate->bitrate) != cck) +continue ; + +if (rate->hw_value == hw_rate) +return i; +else if (rate->flags &IEEE80211_RATE_SHORT_PREAMBLE && + rate->hw_value_short == hw_rate) +return i; + } + +return 0 ; +} + +static u8 ath12k_mac_bitrate_to_rate (int bitrate) +{ +return DIV_ROUND_UP (bitrate,5 ) | + (ath12k_mac_bitrate_is_cck (bitrate) ?BIT (7 ) :0 ); +} + +static void ath12k_get_arvif_iter (void *data,u8 *mac, +struct ieee80211_vif *vif) +{ +struct ath12k_vif_iter *arvif_iter = data; +struct ath12k_vif *arvif = (void *)vif->drv_priv; + +if (arvif->vdev_id == arvif_iter->vdev_id) + arvif_iter->arvif = arvif; +} + +struct ath12k_vif *ath12k_mac_get_arvif (struct ath12k *ar,u32 vdev_id) +{ +struct ath12k_vif_iter arvif_iter = {}; +u32 flags; + + arvif_iter.vdev_id = vdev_id; + + flags =IEEE80211_IFACE_ITER_RESUME_ALL ; +ieee80211_iterate_active_interfaces_atomic (ar->hw, + flags, + ath12k_get_arvif_iter, + &arvif_iter); +if (!arvif_iter.arvif) { +ath12k_warn (ar->ab,"No VIF found for vdev %d\n" , vdev_id); +return NULL ; + } + +return arvif_iter.arvif; +} + +struct ath12k_vif *ath12k_mac_get_arvif_by_vdev_id (struct ath12k_base *ab, +u32 vdev_id) +{ +int i; +struct ath12k_pdev *pdev; +struct ath12k_vif *arvif; + +for (i =0 ; i < ab->num_radios; i++) { + pdev =rcu_dereference (ab->pdevs_active[i]); +if (pdev && pdev->ar) { + arvif =ath12k_mac_get_arvif (pdev->ar, vdev_id); +if (arvif) +return arvif; + } + } + +return NULL ; +} + +struct ath12k *ath12k_mac_get_ar_by_vdev_id (struct ath12k_base *ab,u32 vdev_id) +{ +int i; +struct ath12k_pdev *pdev; + +for (i =0 ; i < ab->num_radios; i++) { + pdev =rcu_dereference (ab->pdevs_active[i]); +if (pdev && pdev->ar) { +if (pdev->ar->allocated_vdev_map & (1LL << vdev_id)) +return pdev->ar; + } + } + +return NULL ; +} + +struct ath12k *ath12k_mac_get_ar_by_pdev_id (struct ath12k_base *ab,u32 pdev_id) +{ +int i; +struct ath12k_pdev *pdev; + +if (ab->hw_params->single_pdev_only) { + pdev =rcu_dereference (ab->pdevs_active[0 ]); +return pdev ? pdev->ar :NULL ; + } + +if (WARN_ON (pdev_id > ab->num_radios)) +return NULL ; + +for (i =0 ; i < ab->num_radios; i++) { + pdev =rcu_dereference (ab->pdevs_active[i]); + +if (pdev && pdev->pdev_id == pdev_id) +return (pdev->ar ? pdev->ar :NULL ); + } + +return NULL ; +} + +static void ath12k_pdev_caps_update (struct ath12k *ar) +{ +struct ath12k_base *ab = ar->ab; + + ar->max_tx_power = ab->target_caps.hw_max_tx_power; + +/* FIXME: Set min_tx_power to ab->target_caps.hw_min_tx_power. +* But since the received value in svcrdy is same as hw_max_tx_power, +* we can set ar->min_tx_power to 0 currently until +* this is fixed in firmware +*/ + ar->min_tx_power =0 ; + + ar->txpower_limit_2g = ar->max_tx_power; + ar->txpower_limit_5g = ar->max_tx_power; + ar->txpower_scale =WMI_HOST_TP_SCALE_MAX ; +} + +static int ath12k_mac_txpower_recalc (struct ath12k *ar) +{ +struct ath12k_pdev *pdev = ar->pdev; +struct ath12k_vif *arvif; +int ret, txpower =-1 ; +u32 param; + +lockdep_assert_held (&ar->conf_mutex); + +list_for_each_entry (arvif, &ar->arvifs, list) { +if (arvif->txpower <=0 ) +continue ; + +if (txpower ==-1 ) + txpower = arvif->txpower; +else + txpower =min (txpower, arvif->txpower); + } + +if (txpower ==-1 ) +return 0 ; + +/* txpwr is set as 2 units per dBm in FW*/ + txpower =min_t (u32,max_t (u32, ar->min_tx_power, txpower), + ar->max_tx_power) *2 ; + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"txpower to set in hw %d\n" , + txpower /2 ); + +if ((pdev->cap.supported_bands &WMI_HOST_WLAN_2G_CAP ) && + ar->txpower_limit_2g != txpower) { + param =WMI_PDEV_PARAM_TXPOWER_LIMIT2G ; + ret =ath12k_wmi_pdev_set_param (ar, param, + txpower, ar->pdev->pdev_id); +if (ret) + goto fail; + ar->txpower_limit_2g = txpower; + } + +if ((pdev->cap.supported_bands &WMI_HOST_WLAN_5G_CAP ) && + ar->txpower_limit_5g != txpower) { + param =WMI_PDEV_PARAM_TXPOWER_LIMIT5G ; + ret =ath12k_wmi_pdev_set_param (ar, param, + txpower, ar->pdev->pdev_id); +if (ret) + goto fail; + ar->txpower_limit_5g = txpower; + } + +return 0 ; + +fail: +ath12k_warn (ar->ab,"failed to recalc txpower limit %d using pdev param %d: %d\n" , + txpower /2 , param, ret); +return ret; +} + +static int ath12k_recalc_rtscts_prot (struct ath12k_vif *arvif) +{ +struct ath12k *ar = arvif->ar; +u32 vdev_param, rts_cts; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + + vdev_param =WMI_VDEV_PARAM_ENABLE_RTSCTS ; + +/* Enable RTS/CTS protection for sw retries (when legacy stations +* are in BSS) or by default only for second rate series. +* TODO: Check if we need to enable CTS 2 Self in any case +*/ + rts_cts =WMI_USE_RTS_CTS ; + +if (arvif->num_legacy_stations >0 ) + rts_cts |=WMI_RTSCTS_ACROSS_SW_RETRIES <<4 ; +else + rts_cts |=WMI_RTSCTS_FOR_SECOND_RATESERIES <<4 ; + +/* Need not send duplicate param value to firmware */ +if (arvif->rtscts_prot_mode == rts_cts) +return 0 ; + + arvif->rtscts_prot_mode = rts_cts; + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac vdev %d recalc rts/cts prot %d\n" , + arvif->vdev_id, rts_cts); + + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + vdev_param, rts_cts); +if (ret) +ath12k_warn (ar->ab,"failed to recalculate rts/cts prot for vdev %d: %d\n" , + arvif->vdev_id, ret); + +return ret; +} + +static int ath12k_mac_set_kickout (struct ath12k_vif *arvif) +{ +struct ath12k *ar = arvif->ar; +u32 param; +int ret; + + ret =ath12k_wmi_pdev_set_param (ar,WMI_PDEV_PARAM_STA_KICKOUT_TH , +ATH12K_KICKOUT_THRESHOLD , + ar->pdev->pdev_id); +if (ret) { +ath12k_warn (ar->ab,"failed to set kickout threshold on vdev %i: %d\n" , + arvif->vdev_id, ret); +return ret; + } + + param =WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, param, +ATH12K_KEEPALIVE_MIN_IDLE ); +if (ret) { +ath12k_warn (ar->ab,"failed to set keepalive minimum idle time on vdev %i: %d\n" , + arvif->vdev_id, ret); +return ret; + } + + param =WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, param, +ATH12K_KEEPALIVE_MAX_IDLE ); +if (ret) { +ath12k_warn (ar->ab,"failed to set keepalive maximum idle time on vdev %i: %d\n" , + arvif->vdev_id, ret); +return ret; + } + + param =WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, param, +ATH12K_KEEPALIVE_MAX_UNRESPONSIVE ); +if (ret) { +ath12k_warn (ar->ab,"failed to set keepalive maximum unresponsive time on vdev %i: %d\n" , + arvif->vdev_id, ret); +return ret; + } + +return 0 ; +} + +void ath12k_mac_peer_cleanup_all (struct ath12k *ar) +{ +struct ath12k_peer *peer, *tmp; +struct ath12k_base *ab = ar->ab; + +lockdep_assert_held (&ar->conf_mutex); + +spin_lock_bh (&ab->base_lock); +list_for_each_entry_safe (peer, tmp, &ab->peers, list) { +ath12k_dp_rx_peer_tid_cleanup (ar, peer); +list_del (&peer->list); +kfree (peer); + } +spin_unlock_bh (&ab->base_lock); + + ar->num_peers =0 ; + ar->num_stations =0 ; +} + +static int ath12k_mac_vdev_setup_sync (struct ath12k *ar) +{ +lockdep_assert_held (&ar->conf_mutex); + +if (test_bit (ATH12K_FLAG_CRASH_FLUSH , &ar->ab->dev_flags)) +return -ESHUTDOWN ; + +if (!wait_for_completion_timeout (&ar->vdev_setup_done, +ATH12K_VDEV_SETUP_TIMEOUT_HZ )) +return -ETIMEDOUT ; + +return ar->last_wmi_vdev_start_status ? -EINVAL :0 ; +} + +static int ath12k_monitor_vdev_up (struct ath12k *ar,int vdev_id) +{ +int ret; + + ret =ath12k_wmi_vdev_up (ar, vdev_id,0 , ar->mac_addr); +if (ret) { +ath12k_warn (ar->ab,"failed to put up monitor vdev %i: %d\n" , + vdev_id, ret); +return ret; + } + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac monitor vdev %i started\n" , + vdev_id); +return 0 ; +} + +static int ath12k_mac_monitor_vdev_start (struct ath12k *ar,int vdev_id, +struct cfg80211_chan_def *chandef) +{ +struct ieee80211_channel *channel; +struct wmi_vdev_start_req_arg arg = {}; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + + channel = chandef->chan; + arg.vdev_id = vdev_id; + arg.freq = channel->center_freq; + arg.band_center_freq1 = chandef->center_freq1; + arg.band_center_freq2 = chandef->center_freq2; + arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; + arg.chan_radar = !!(channel->flags &IEEE80211_CHAN_RADAR ); + + arg.min_power =0 ; + arg.max_power = channel->max_power; + arg.max_reg_power = channel->max_reg_power; + arg.max_antenna_gain = channel->max_antenna_gain; + + arg.pref_tx_streams = ar->num_tx_chains; + arg.pref_rx_streams = ar->num_rx_chains; + + arg.passive |= !!(chandef->chan->flags &IEEE80211_CHAN_NO_IR ); + +reinit_completion (&ar->vdev_setup_done); +reinit_completion (&ar->vdev_delete_done); + + ret =ath12k_wmi_vdev_start (ar, &arg, false); +if (ret) { +ath12k_warn (ar->ab,"failed to request monitor vdev %i start: %d\n" , + vdev_id, ret); +return ret; + } + + ret =ath12k_mac_vdev_setup_sync (ar); +if (ret) { +ath12k_warn (ar->ab,"failed to synchronize setup for monitor vdev %i start: %d\n" , + vdev_id, ret); +return ret; + } + + ret =ath12k_wmi_vdev_up (ar, vdev_id,0 , ar->mac_addr); +if (ret) { +ath12k_warn (ar->ab,"failed to put up monitor vdev %i: %d\n" , + vdev_id, ret); + goto vdev_stop; + } + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac monitor vdev %i started\n" , + vdev_id); +return 0 ; + +vdev_stop: + ret =ath12k_wmi_vdev_stop (ar, vdev_id); +if (ret) +ath12k_warn (ar->ab,"failed to stop monitor vdev %i after start failure: %d\n" , + vdev_id, ret); +return ret; +} + +static int ath12k_mac_monitor_vdev_stop (struct ath12k *ar) +{ +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +reinit_completion (&ar->vdev_setup_done); + + ret =ath12k_wmi_vdev_stop (ar, ar->monitor_vdev_id); +if (ret) +ath12k_warn (ar->ab,"failed to request monitor vdev %i stop: %d\n" , + ar->monitor_vdev_id, ret); + + ret =ath12k_mac_vdev_setup_sync (ar); +if (ret) +ath12k_warn (ar->ab,"failed to synchronize monitor vdev %i stop: %d\n" , + ar->monitor_vdev_id, ret); + + ret =ath12k_wmi_vdev_down (ar, ar->monitor_vdev_id); +if (ret) +ath12k_warn (ar->ab,"failed to put down monitor vdev %i: %d\n" , + ar->monitor_vdev_id, ret); + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac monitor vdev %i stopped\n" , + ar->monitor_vdev_id); +return ret; +} + +static int ath12k_mac_monitor_vdev_create (struct ath12k *ar) +{ +struct ath12k_pdev *pdev = ar->pdev; +struct ath12k_wmi_vdev_create_arg arg = {}; +int bit, ret; +u8 tmp_addr[6 ]; +u16 nss; + +lockdep_assert_held (&ar->conf_mutex); + +if (ar->monitor_vdev_created) +return 0 ; + +if (ar->ab->free_vdev_map ==0 ) { +ath12k_warn (ar->ab,"failed to find free vdev id for monitor vdev\n" ); +return -ENOMEM ; + } + + bit =__ffs64 (ar->ab->free_vdev_map); + + ar->monitor_vdev_id = bit; + + arg.if_id = ar->monitor_vdev_id; + arg.type =WMI_VDEV_TYPE_MONITOR ; + arg.subtype =WMI_VDEV_SUBTYPE_NONE ; + arg.pdev_id = pdev->pdev_id; + arg.if_stats_id =ATH12K_INVAL_VDEV_STATS_ID ; + +if (pdev->cap.supported_bands &WMI_HOST_WLAN_2G_CAP ) { + arg.chains[NL80211_BAND_2GHZ ].tx = ar->num_tx_chains; + arg.chains[NL80211_BAND_2GHZ ].rx = ar->num_rx_chains; + } + +if (pdev->cap.supported_bands &WMI_HOST_WLAN_5G_CAP ) { + arg.chains[NL80211_BAND_5GHZ ].tx = ar->num_tx_chains; + arg.chains[NL80211_BAND_5GHZ ].rx = ar->num_rx_chains; + } + + ret =ath12k_wmi_vdev_create (ar, tmp_addr, &arg); +if (ret) { +ath12k_warn (ar->ab,"failed to request monitor vdev %i creation: %d\n" , + ar->monitor_vdev_id, ret); + ar->monitor_vdev_id =-1 ; +return ret; + } + + nss =hweight32 (ar->cfg_tx_chainmask) ? :1 ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, ar->monitor_vdev_id, +WMI_VDEV_PARAM_NSS , nss); +if (ret) { +ath12k_warn (ar->ab,"failed to set vdev %d chainmask 0x%x, nss %d :%d\n" , + ar->monitor_vdev_id, ar->cfg_tx_chainmask, nss, ret); +return ret; + } + + ret =ath12k_mac_txpower_recalc (ar); +if (ret) +return ret; + + ar->allocated_vdev_map |=1LL << ar->monitor_vdev_id; + ar->ab->free_vdev_map &= ~(1LL << ar->monitor_vdev_id); + ar->num_created_vdevs++; + ar->monitor_vdev_created = true; +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac monitor vdev %d created\n" , + ar->monitor_vdev_id); + +return 0 ; +} + +static int ath12k_mac_monitor_vdev_delete (struct ath12k *ar) +{ +int ret; +unsigned long time_left; + +lockdep_assert_held (&ar->conf_mutex); + +if (!ar->monitor_vdev_created) +return 0 ; + +reinit_completion (&ar->vdev_delete_done); + + ret =ath12k_wmi_vdev_delete (ar, ar->monitor_vdev_id); +if (ret) { +ath12k_warn (ar->ab,"failed to request wmi monitor vdev %i removal: %d\n" , + ar->monitor_vdev_id, ret); +return ret; + } + + time_left =wait_for_completion_timeout (&ar->vdev_delete_done, +ATH12K_VDEV_DELETE_TIMEOUT_HZ ); +if (time_left ==0 ) { +ath12k_warn (ar->ab,"Timeout in receiving vdev delete response\n" ); + }else { + ar->allocated_vdev_map &= ~(1LL << ar->monitor_vdev_id); + ar->ab->free_vdev_map |=1LL << (ar->monitor_vdev_id); +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac monitor vdev %d deleted\n" , + ar->monitor_vdev_id); + ar->num_created_vdevs--; + ar->monitor_vdev_id =-1 ; + ar->monitor_vdev_created = false; + } + +return ret; +} + +static void +ath12k_mac_get_any_chandef_iter (struct ieee80211_hw *hw, +struct ieee80211_chanctx_conf *conf, +void *data) +{ +struct cfg80211_chan_def **def = data; + + *def = &conf->def; +} + +static int ath12k_mac_monitor_start (struct ath12k *ar) +{ +struct cfg80211_chan_def *chandef =NULL ; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +if (ar->monitor_started) +return 0 ; + +ieee80211_iter_chan_contexts_atomic (ar->hw, + ath12k_mac_get_any_chandef_iter, + &chandef); +if (!chandef) +return 0 ; + + ret =ath12k_mac_monitor_vdev_start (ar, ar->monitor_vdev_id, chandef); +if (ret) { +ath12k_warn (ar->ab,"failed to start monitor vdev: %d\n" , ret); +ath12k_mac_monitor_vdev_delete (ar); +return ret; + } + + ar->monitor_started = true; + ar->num_started_vdevs++; + ret =ath12k_dp_tx_htt_monitor_mode_ring_config (ar, false); +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac monitor started ret %d\n" , ret); + +return ret; +} + +static int ath12k_mac_monitor_stop (struct ath12k *ar) +{ +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +if (!ar->monitor_started) +return 0 ; + + ret =ath12k_mac_monitor_vdev_stop (ar); +if (ret) { +ath12k_warn (ar->ab,"failed to stop monitor vdev: %d\n" , ret); +return ret; + } + + ar->monitor_started = false; + ar->num_started_vdevs--; + ret =ath12k_dp_tx_htt_monitor_mode_ring_config (ar, true); +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac monitor stopped ret %d\n" , ret); +return ret; +} + +static int ath12k_mac_op_config (struct ieee80211_hw *hw,u32 changed) +{ +struct ath12k *ar = hw->priv; +struct ieee80211_conf *conf = &hw->conf; +int ret; + +mutex_lock (&ar->conf_mutex); + +if (changed &IEEE80211_CONF_CHANGE_MONITOR ) { + ar->monitor_conf_enabled = conf->flags &IEEE80211_CONF_MONITOR ; +if (ar->monitor_conf_enabled) { +if (ar->monitor_vdev_created) + goto exit; + ret =ath12k_mac_monitor_vdev_create (ar); +if (ret) + goto exit; + ret =ath12k_mac_monitor_start (ar); +if (ret) + goto err_mon_del; + }else { +if (!ar->monitor_vdev_created) + goto exit; + ret =ath12k_mac_monitor_stop (ar); +if (ret) + goto exit; +ath12k_mac_monitor_vdev_delete (ar); + } + } + +exit: +mutex_unlock (&ar->conf_mutex); +return ret; + +err_mon_del: +ath12k_mac_monitor_vdev_delete (ar); +mutex_unlock (&ar->conf_mutex); +return 0 ; +} + +static int ath12k_mac_setup_bcn_tmpl (struct ath12k_vif *arvif) +{ +struct ath12k *ar = arvif->ar; +struct ath12k_base *ab = ar->ab; +struct ieee80211_hw *hw = ar->hw; +struct ieee80211_vif *vif = arvif->vif; +struct ieee80211_mutable_offsets offs = {}; +struct sk_buff *bcn; +struct ieee80211_mgmt *mgmt; +u8 *ies; +int ret; + +if (arvif->vdev_type !=WMI_VDEV_TYPE_AP ) +return 0 ; + + bcn =ieee80211_beacon_get_template (hw, vif, &offs,0 ); +if (!bcn) { +ath12k_warn (ab,"failed to get beacon template from mac80211\n" ); +return -EPERM ; + } + + ies = bcn->data +ieee80211_get_hdrlen_from_skb (bcn); + ies +=sizeof (mgmt->u.beacon); + +if (cfg80211_find_ie (WLAN_EID_RSN , ies, (skb_tail_pointer (bcn) - ies))) + arvif->rsnie_present = true; + +if (cfg80211_find_vendor_ie (WLAN_OUI_MICROSOFT , +WLAN_OUI_TYPE_MICROSOFT_WPA , + ies, (skb_tail_pointer (bcn) - ies))) + arvif->wpaie_present = true; + + ret =ath12k_wmi_bcn_tmpl (ar, arvif->vdev_id, &offs, bcn); + +kfree_skb (bcn); + +if (ret) +ath12k_warn (ab,"failed to submit beacon template command: %d\n" , + ret); + +return ret; +} + +static void ath12k_control_beaconing (struct ath12k_vif *arvif, +struct ieee80211_bss_conf *info) +{ +struct ath12k *ar = arvif->ar; +int ret; + +lockdep_assert_held (&arvif->ar->conf_mutex); + +if (!info->enable_beacon) { + ret =ath12k_wmi_vdev_down (ar, arvif->vdev_id); +if (ret) +ath12k_warn (ar->ab,"failed to down vdev_id %i: %d\n" , + arvif->vdev_id, ret); + + arvif->is_up = false; +return ; + } + +/* Install the beacon template to the FW */ + ret =ath12k_mac_setup_bcn_tmpl (arvif); +if (ret) { +ath12k_warn (ar->ab,"failed to update bcn tmpl during vdev up: %d\n" , + ret); +return ; + } + + arvif->aid =0 ; + +ether_addr_copy (arvif->bssid, info->bssid); + + ret =ath12k_wmi_vdev_up (arvif->ar, arvif->vdev_id, arvif->aid, + arvif->bssid); +if (ret) { +ath12k_warn (ar->ab,"failed to bring up vdev %d: %i\n" , + arvif->vdev_id, ret); +return ; + } + + arvif->is_up = true; + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac vdev %d up\n" , arvif->vdev_id); +} + +static void ath12k_peer_assoc_h_basic (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +struct ath12k_vif *arvif = (void *)vif->drv_priv; +u32 aid; + +lockdep_assert_held (&ar->conf_mutex); + +if (vif->type ==NL80211_IFTYPE_STATION ) + aid = vif->cfg.aid; +else + aid = sta->aid; + +ether_addr_copy (arg->peer_mac, sta->addr); + arg->vdev_id = arvif->vdev_id; + arg->peer_associd = aid; + arg->auth_flag = true; +/* TODO: STA WAR in ath10k for listen interval required? */ + arg->peer_listen_intval = ar->hw->conf.listen_interval; + arg->peer_nss =1 ; + arg->peer_caps = vif->bss_conf.assoc_capability; +} + +static void ath12k_peer_assoc_h_crypto (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +struct ieee80211_bss_conf *info = &vif->bss_conf; +struct cfg80211_chan_def def; +struct cfg80211_bss *bss; +struct ath12k_vif *arvif = (struct ath12k_vif *)vif->drv_priv; +const u8 *rsnie =NULL ; +const u8 *wpaie =NULL ; + +lockdep_assert_held (&ar->conf_mutex); + +if (WARN_ON (ath12k_mac_vif_chan (vif, &def))) +return ; + + bss =cfg80211_get_bss (ar->hw->wiphy, def.chan, info->bssid,NULL ,0 , +IEEE80211_BSS_TYPE_ANY ,IEEE80211_PRIVACY_ANY ); + +if (arvif->rsnie_present || arvif->wpaie_present) { + arg->need_ptk_4_way = true; +if (arvif->wpaie_present) + arg->need_gtk_2_way = true; + }else if (bss) { +const struct cfg80211_bss_ies *ies; + +rcu_read_lock (); + rsnie =ieee80211_bss_get_ie (bss,WLAN_EID_RSN ); + + ies =rcu_dereference (bss->ies); + + wpaie =cfg80211_find_vendor_ie (WLAN_OUI_MICROSOFT , +WLAN_OUI_TYPE_MICROSOFT_WPA , + ies->data, + ies->len); +rcu_read_unlock (); +cfg80211_put_bss (ar->hw->wiphy, bss); + } + +/* FIXME: base on RSN IE/WPA IE is a correct idea? */ +if (rsnie || wpaie) { +ath12k_dbg (ar->ab,ATH12K_DBG_WMI , +"%s: rsn ie found\n" , __func__); + arg->need_ptk_4_way = true; + } + +if (wpaie) { +ath12k_dbg (ar->ab,ATH12K_DBG_WMI , +"%s: wpa ie found\n" , __func__); + arg->need_gtk_2_way = true; + } + +if (sta->mfp) { +/* TODO: Need to check if FW supports PMF? */ + arg->is_pmf_enabled = true; + } + +/* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */ +} + +static void ath12k_peer_assoc_h_rates (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +struct ath12k_vif *arvif = (void *)vif->drv_priv; +struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; +struct cfg80211_chan_def def; +const struct ieee80211_supported_band *sband; +const struct ieee80211_rate *rates; +enum nl80211_band band; +u32 ratemask; +u8 rate; +int i; + +lockdep_assert_held (&ar->conf_mutex); + +if (WARN_ON (ath12k_mac_vif_chan (vif, &def))) +return ; + + band = def.chan->band; + sband = ar->hw->wiphy->bands[band]; + ratemask = sta->deflink.supp_rates[band]; + ratemask &= arvif->bitrate_mask.control[band].legacy; + rates = sband->bitrates; + + rateset->num_rates =0 ; + +for (i =0 ; i <32 ; i++, ratemask >>=1 , rates++) { +if (!(ratemask &1 )) +continue ; + + rate =ath12k_mac_bitrate_to_rate (rates->bitrate); + rateset->rates[rateset->num_rates] = rate; + rateset->num_rates++; + } +} + +static bool +ath12k_peer_assoc_h_ht_masked (const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN ]) +{ +int nss; + +for (nss =0 ; nss <IEEE80211_HT_MCS_MASK_LEN ; nss++) +if (ht_mcs_mask[nss]) +return false; + +return true; +} + +static bool +ath12k_peer_assoc_h_vht_masked (const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX ]) +{ +int nss; + +for (nss =0 ; nss <NL80211_VHT_NSS_MAX ; nss++) +if (vht_mcs_mask[nss]) +return false; + +return true; +} + +static void ath12k_peer_assoc_h_ht (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +const struct ieee80211_sta_ht_cap *ht_cap = &sta->deflink.ht_cap; +struct ath12k_vif *arvif = (void *)vif->drv_priv; +struct cfg80211_chan_def def; +enum nl80211_band band; +const u8 *ht_mcs_mask; +int i, n; +u8 max_nss; +u32 stbc; + +lockdep_assert_held (&ar->conf_mutex); + +if (WARN_ON (ath12k_mac_vif_chan (vif, &def))) +return ; + +if (!ht_cap->ht_supported) +return ; + + band = def.chan->band; + ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; + +if (ath12k_peer_assoc_h_ht_masked (ht_mcs_mask)) +return ; + + arg->ht_flag = true; + + arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + + ht_cap->ampdu_factor)) -1 ; + + arg->peer_mpdu_density = +ath12k_parse_mpdudensity (ht_cap->ampdu_density); + + arg->peer_ht_caps = ht_cap->cap; + arg->peer_rate_caps |=WMI_HOST_RC_HT_FLAG ; + +if (ht_cap->cap &IEEE80211_HT_CAP_LDPC_CODING ) + arg->ldpc_flag = true; + +if (sta->deflink.bandwidth >=IEEE80211_STA_RX_BW_40 ) { + arg->bw_40 = true; + arg->peer_rate_caps |=WMI_HOST_RC_CW40_FLAG ; + } + +if (arvif->bitrate_mask.control[band].gi !=NL80211_TXRATE_FORCE_LGI ) { +if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 | +IEEE80211_HT_CAP_SGI_40 )) + arg->peer_rate_caps |=WMI_HOST_RC_SGI_FLAG ; + } + +if (ht_cap->cap &IEEE80211_HT_CAP_TX_STBC ) { + arg->peer_rate_caps |=WMI_HOST_RC_TX_STBC_FLAG ; + arg->stbc_flag = true; + } + +if (ht_cap->cap &IEEE80211_HT_CAP_RX_STBC ) { + stbc = ht_cap->cap &IEEE80211_HT_CAP_RX_STBC ; + stbc = stbc >>IEEE80211_HT_CAP_RX_STBC_SHIFT ; + stbc = stbc <<WMI_HOST_RC_RX_STBC_FLAG_S ; + arg->peer_rate_caps |= stbc; + arg->stbc_flag = true; + } + +if (ht_cap->mcs.rx_mask[1 ] && ht_cap->mcs.rx_mask[2 ]) + arg->peer_rate_caps |=WMI_HOST_RC_TS_FLAG ; +else if (ht_cap->mcs.rx_mask[1 ]) + arg->peer_rate_caps |=WMI_HOST_RC_DS_FLAG ; + +for (i =0 , n =0 , max_nss =0 ; i <IEEE80211_HT_MCS_MASK_LEN *8 ; i++) +if ((ht_cap->mcs.rx_mask[i /8 ] &BIT (i %8 )) && + (ht_mcs_mask[i /8 ] &BIT (i %8 ))) { + max_nss = (i /8 ) +1 ; + arg->peer_ht_rates.rates[n++] = i; + } + +/* This is a workaround for HT-enabled STAs which break the spec +* and have no HT capabilities RX mask (no HT RX MCS map). +* +* As per spec, in section 20.3.5 Modulation and coding scheme (MCS), +* MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. +* +* Firmware asserts if such situation occurs. +*/ +if (n ==0 ) { + arg->peer_ht_rates.num_rates =8 ; +for (i =0 ; i < arg->peer_ht_rates.num_rates; i++) + arg->peer_ht_rates.rates[i] = i; + }else { + arg->peer_ht_rates.num_rates = n; + arg->peer_nss =min (sta->deflink.rx_nss, max_nss); + } + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac ht peer %pM mcs cnt %d nss %d\n" , + arg->peer_mac, + arg->peer_ht_rates.num_rates, + arg->peer_nss); +} + +static int ath12k_mac_get_max_vht_mcs_map (u16 mcs_map,int nss) +{ +switch ((mcs_map >> (2 * nss)) &0x3 ) { +case IEEE80211_VHT_MCS_SUPPORT_0_7 :return BIT (8 ) -1 ; +case IEEE80211_VHT_MCS_SUPPORT_0_8 :return BIT (9 ) -1 ; +case IEEE80211_VHT_MCS_SUPPORT_0_9 :return BIT (10 ) -1 ; + } +return 0 ; +} + +static u16 +ath12k_peer_assoc_h_vht_limit (u16 tx_mcs_set, +const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX ]) +{ +int idx_limit; +int nss; +u16 mcs_map; +u16 mcs; + +for (nss =0 ; nss <NL80211_VHT_NSS_MAX ; nss++) { + mcs_map =ath12k_mac_get_max_vht_mcs_map (tx_mcs_set, nss) & + vht_mcs_limit[nss]; + +if (mcs_map) + idx_limit =fls (mcs_map) -1 ; +else + idx_limit =-1 ; + +switch (idx_limit) { +case 0 : +case 1 : +case 2 : +case 3 : +case 4 : +case 5 : +case 6 : +case 7 : + mcs =IEEE80211_VHT_MCS_SUPPORT_0_7 ; +break ; +case 8 : + mcs =IEEE80211_VHT_MCS_SUPPORT_0_8 ; +break ; +case 9 : + mcs =IEEE80211_VHT_MCS_SUPPORT_0_9 ; +break ; +default : +WARN_ON (1 ); + fallthrough; +case -1 : + mcs =IEEE80211_VHT_MCS_NOT_SUPPORTED ; +break ; + } + + tx_mcs_set &= ~(0x3 << (nss *2 )); + tx_mcs_set |= mcs << (nss *2 ); + } + +return tx_mcs_set; +} + +static void ath12k_peer_assoc_h_vht (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +const struct ieee80211_sta_vht_cap *vht_cap = &sta->deflink.vht_cap; +struct ath12k_vif *arvif = (void *)vif->drv_priv; +struct cfg80211_chan_def def; +enum nl80211_band band; +const u16 *vht_mcs_mask; +u16 tx_mcs_map; +u8 ampdu_factor; +u8 max_nss, vht_mcs; +int i; + +if (WARN_ON (ath12k_mac_vif_chan (vif, &def))) +return ; + +if (!vht_cap->vht_supported) +return ; + + band = def.chan->band; + vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; + +if (ath12k_peer_assoc_h_vht_masked (vht_mcs_mask)) +return ; + + arg->vht_flag = true; + +/* TODO: similar flags required? */ + arg->vht_capable = true; + +if (def.chan->band ==NL80211_BAND_2GHZ ) + arg->vht_ng_flag = true; + + arg->peer_vht_caps = vht_cap->cap; + + ampdu_factor = (vht_cap->cap & +IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK ) >> +IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT ; + +/* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to +* zero in VHT IE. Using it would result in degraded throughput. +* arg->peer_max_mpdu at this point contains HT max_mpdu so keep +* it if VHT max_mpdu is smaller. +*/ + arg->peer_max_mpdu =max (arg->peer_max_mpdu, + (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + + ampdu_factor)) -1 ); + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_80 ) + arg->bw_80 = true; + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_160 ) + arg->bw_160 = true; + +/* Calculate peer NSS capability from VHT capabilities if STA +* supports VHT. +*/ +for (i =0 , max_nss =0 , vht_mcs =0 ; i <NL80211_VHT_NSS_MAX ; i++) { + vht_mcs =__le16_to_cpu (vht_cap->vht_mcs.rx_mcs_map) >> + (2 * i) &3 ; + +if (vht_mcs !=IEEE80211_VHT_MCS_NOT_SUPPORTED && + vht_mcs_mask[i]) + max_nss = i +1 ; + } + arg->peer_nss =min (sta->deflink.rx_nss, max_nss); + arg->rx_max_rate =__le16_to_cpu (vht_cap->vht_mcs.rx_highest); + arg->rx_mcs_set =__le16_to_cpu (vht_cap->vht_mcs.rx_mcs_map); + arg->tx_max_rate =__le16_to_cpu (vht_cap->vht_mcs.tx_highest); + + tx_mcs_map =__le16_to_cpu (vht_cap->vht_mcs.tx_mcs_map); + arg->tx_mcs_set =ath12k_peer_assoc_h_vht_limit (tx_mcs_map, vht_mcs_mask); + +/* In QCN9274 platform, VHT MCS rate 10 and 11 is enabled by default. +* VHT MCS rate 10 and 11 is not supported in 11ac standard. +* so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode. +*/ + arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK ; + arg->tx_mcs_set |=IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11 ; + +if ((arg->tx_mcs_set &IEEE80211_VHT_MCS_NOT_SUPPORTED ) == +IEEE80211_VHT_MCS_NOT_SUPPORTED ) + arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE ; + +/* TODO: Check */ + arg->tx_max_mcs_nss =0xFF ; + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac vht peer %pM max_mpdu %d flags 0x%x\n" , + sta->addr, arg->peer_max_mpdu, arg->peer_flags); + +/* TODO: rxnss_override */ +} + +static void ath12k_peer_assoc_h_he (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +const struct ieee80211_sta_he_cap *he_cap = &sta->deflink.he_cap; +int i; +u8 ampdu_factor, rx_mcs_80, rx_mcs_160, max_nss; +u16 mcs_160_map, mcs_80_map; +bool support_160; +u16 v; + +if (!he_cap->has_he) +return ; + + arg->he_flag = true; + + support_160 = !!(he_cap->he_cap_elem.phy_cap_info[0 ] & +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G ); + +/* Supported HE-MCS and NSS Set of peer he_cap is intersection with self he_cp */ + mcs_160_map =le16_to_cpu (he_cap->he_mcs_nss_supp.rx_mcs_160); + mcs_80_map =le16_to_cpu (he_cap->he_mcs_nss_supp.rx_mcs_80); + +if (support_160) { +for (i =7 ; i >=0 ; i--) { +u8 mcs_160 = (mcs_160_map >> (2 * i)) &3 ; + +if (mcs_160 !=IEEE80211_HE_MCS_NOT_SUPPORTED ) { + rx_mcs_160 = i +1 ; +break ; + } + } + } + +for (i =7 ; i >=0 ; i--) { +u8 mcs_80 = (mcs_80_map >> (2 * i)) &3 ; + +if (mcs_80 !=IEEE80211_HE_MCS_NOT_SUPPORTED ) { + rx_mcs_80 = i +1 ; +break ; + } + } + +if (support_160) + max_nss =min (rx_mcs_80, rx_mcs_160); +else + max_nss = rx_mcs_80; + + arg->peer_nss =min (sta->deflink.rx_nss, max_nss); + +memcpy (&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info, +sizeof (arg->peer_he_cap_macinfo)); +memcpy (&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info, +sizeof (arg->peer_he_cap_phyinfo)); + arg->peer_he_ops = vif->bss_conf.he_oper.params; + +/* the top most byte is used to indicate BSS color info */ + arg->peer_he_ops &=0xffffff ; + +/* As per section 26.6.1 IEEE Std 802.11ax‐2022, if the Max AMPDU +* Exponent Extension in HE cap is zero, use the arg->peer_max_mpdu +* as calculated while parsing VHT caps(if VHT caps is present) +* or HT caps (if VHT caps is not present). +* +* For non-zero value of Max AMPDU Exponent Extension in HE MAC caps, +* if a HE STA sends VHT cap and HE cap IE in assoc request then, use +* MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length. +* If a HE STA that does not send VHT cap, but HE and HT cap in assoc +* request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu +* length. +*/ + ampdu_factor = (he_cap->he_cap_elem.mac_cap_info[3 ] & +IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK ) >> +IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK ; + +if (ampdu_factor) { +if (sta->deflink.vht_cap.vht_supported) + arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR + + ampdu_factor)) -1 ; +else if (sta->deflink.ht_cap.ht_supported) + arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR + + ampdu_factor)) -1 ; + } + +if (he_cap->he_cap_elem.phy_cap_info[6 ] & +IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT ) { +int bit =7 ; +int nss, ru; + + arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0 ] & +IEEE80211_PPE_THRES_NSS_MASK ; + arg->peer_ppet.ru_bit_mask = + (he_cap->ppe_thres[0 ] & +IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK ) >> +IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS ; + +for (nss =0 ; nss <= arg->peer_ppet.numss_m1; nss++) { +for (ru =0 ; ru <4 ; ru++) { +u32 val =0 ; +int i; + +if ((arg->peer_ppet.ru_bit_mask &BIT (ru)) ==0 ) +continue ; +for (i =0 ; i <6 ; i++) { + val >>=1 ; + val |= ((he_cap->ppe_thres[bit /8 ] >> + (bit %8 )) &0x1 ) <<5 ; + bit++; + } + arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |= + val << (ru *6 ); + } + } + } + +if (he_cap->he_cap_elem.mac_cap_info[0 ] &IEEE80211_HE_MAC_CAP0_TWT_RES ) + arg->twt_responder = true; +if (he_cap->he_cap_elem.mac_cap_info[0 ] &IEEE80211_HE_MAC_CAP0_TWT_REQ ) + arg->twt_requester = true; + +switch (sta->deflink.bandwidth) { +case IEEE80211_STA_RX_BW_160 : +if (he_cap->he_cap_elem.phy_cap_info[0 ] & +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G ) { + v =le16_to_cpu (he_cap->he_mcs_nss_supp.rx_mcs_80p80); + arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80 ] = v; + + v =le16_to_cpu (he_cap->he_mcs_nss_supp.tx_mcs_80p80); + arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80 ] = v; + + arg->peer_he_mcs_count++; + } + v =le16_to_cpu (he_cap->he_mcs_nss_supp.rx_mcs_160); + arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160 ] = v; + + v =le16_to_cpu (he_cap->he_mcs_nss_supp.tx_mcs_160); + arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160 ] = v; + + arg->peer_he_mcs_count++; + fallthrough; + +default : + v =le16_to_cpu (he_cap->he_mcs_nss_supp.rx_mcs_80); + arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80 ] = v; + + v =le16_to_cpu (he_cap->he_mcs_nss_supp.tx_mcs_80); + arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80 ] = v; + + arg->peer_he_mcs_count++; +break ; + } +} + +static void ath12k_peer_assoc_h_smps (struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +const struct ieee80211_sta_ht_cap *ht_cap = &sta->deflink.ht_cap; +int smps; + +if (!ht_cap->ht_supported) +return ; + + smps = ht_cap->cap &IEEE80211_HT_CAP_SM_PS ; + smps >>=IEEE80211_HT_CAP_SM_PS_SHIFT ; + +switch (smps) { +case WLAN_HT_CAP_SM_PS_STATIC : + arg->static_mimops_flag = true; +break ; +case WLAN_HT_CAP_SM_PS_DYNAMIC : + arg->dynamic_mimops_flag = true; +break ; +case WLAN_HT_CAP_SM_PS_DISABLED : + arg->spatial_mux_flag = true; +break ; +default : +break ; + } +} + +static void ath12k_peer_assoc_h_qos (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +struct ath12k_vif *arvif = (void *)vif->drv_priv; + +switch (arvif->vdev_type) { +case WMI_VDEV_TYPE_AP : +if (sta->wme) { +/* TODO: Check WME vs QoS */ + arg->is_wme_set = true; + arg->qos_flag = true; + } + +if (sta->wme && sta->uapsd_queues) { +/* TODO: Check WME vs QoS */ + arg->is_wme_set = true; + arg->apsd_flag = true; + arg->peer_rate_caps |=WMI_HOST_RC_UAPSD_FLAG ; + } +break ; +case WMI_VDEV_TYPE_STA : +if (sta->wme) { + arg->is_wme_set = true; + arg->qos_flag = true; + } +break ; +default : +break ; + } + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac peer %pM qos %d\n" , + sta->addr, arg->qos_flag); +} + +static int ath12k_peer_assoc_qos_ap (struct ath12k *ar, +struct ath12k_vif *arvif, +struct ieee80211_sta *sta) +{ +struct ath12k_wmi_ap_ps_arg arg; +u32 max_sp; +u32 uapsd; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + + arg.vdev_id = arvif->vdev_id; + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac uapsd_queues 0x%x max_sp %d\n" , + sta->uapsd_queues, sta->max_sp); + + uapsd =0 ; +if (sta->uapsd_queues &IEEE80211_WMM_IE_STA_QOSINFO_AC_VO ) + uapsd |=WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | +WMI_AP_PS_UAPSD_AC3_TRIGGER_EN ; +if (sta->uapsd_queues &IEEE80211_WMM_IE_STA_QOSINFO_AC_VI ) + uapsd |=WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | +WMI_AP_PS_UAPSD_AC2_TRIGGER_EN ; +if (sta->uapsd_queues &IEEE80211_WMM_IE_STA_QOSINFO_AC_BK ) + uapsd |=WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | +WMI_AP_PS_UAPSD_AC1_TRIGGER_EN ; +if (sta->uapsd_queues &IEEE80211_WMM_IE_STA_QOSINFO_AC_BE ) + uapsd |=WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | +WMI_AP_PS_UAPSD_AC0_TRIGGER_EN ; + + max_sp =0 ; +if (sta->max_sp <MAX_WMI_AP_PS_PEER_PARAM_MAX_SP ) + max_sp = sta->max_sp; + + arg.param =WMI_AP_PS_PEER_PARAM_UAPSD ; + arg.value = uapsd; + ret =ath12k_wmi_send_set_ap_ps_param_cmd (ar, sta->addr, &arg); +if (ret) + goto err; + + arg.param =WMI_AP_PS_PEER_PARAM_MAX_SP ; + arg.value = max_sp; + ret =ath12k_wmi_send_set_ap_ps_param_cmd (ar, sta->addr, &arg); +if (ret) + goto err; + +/* TODO: revisit during testing */ + arg.param =WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE ; + arg.value =DISABLE_SIFS_RESPONSE_TRIGGER ; + ret =ath12k_wmi_send_set_ap_ps_param_cmd (ar, sta->addr, &arg); +if (ret) + goto err; + + arg.param =WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD ; + arg.value =DISABLE_SIFS_RESPONSE_TRIGGER ; + ret =ath12k_wmi_send_set_ap_ps_param_cmd (ar, sta->addr, &arg); +if (ret) + goto err; + +return 0 ; + +err: +ath12k_warn (ar->ab,"failed to set ap ps peer param %d for vdev %i: %d\n" , + arg.param, arvif->vdev_id, ret); +return ret; +} + +static bool ath12k_mac_sta_has_ofdm_only (struct ieee80211_sta *sta) +{ +return sta->deflink.supp_rates[NL80211_BAND_2GHZ ] >> +ATH12K_MAC_FIRST_OFDM_RATE_IDX ; +} + +static enum wmi_phy_mode ath12k_mac_get_phymode_vht (struct ath12k *ar, +struct ieee80211_sta *sta) +{ +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_160 ) { +switch (sta->deflink.vht_cap.cap & +IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK ) { +case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ : +return MODE_11AC_VHT160 ; +case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ : +return MODE_11AC_VHT80_80 ; +default : +/* not sure if this is a valid case? */ +return MODE_11AC_VHT160 ; + } + } + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_80 ) +return MODE_11AC_VHT80 ; + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_40 ) +return MODE_11AC_VHT40 ; + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_20 ) +return MODE_11AC_VHT20 ; + +return MODE_UNKNOWN ; +} + +static enum wmi_phy_mode ath12k_mac_get_phymode_he (struct ath12k *ar, +struct ieee80211_sta *sta) +{ +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_160 ) { +if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[0 ] & +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G ) +return MODE_11AX_HE160 ; +else if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[0 ] & +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G ) +return MODE_11AX_HE80_80 ; +/* not sure if this is a valid case? */ +return MODE_11AX_HE160 ; + } + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_80 ) +return MODE_11AX_HE80 ; + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_40 ) +return MODE_11AX_HE40 ; + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_20 ) +return MODE_11AX_HE20 ; + +return MODE_UNKNOWN ; +} + +static void ath12k_peer_assoc_h_phymode (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg) +{ +struct ath12k_vif *arvif = (void *)vif->drv_priv; +struct cfg80211_chan_def def; +enum nl80211_band band; +const u8 *ht_mcs_mask; +const u16 *vht_mcs_mask; +enum wmi_phy_mode phymode =MODE_UNKNOWN ; + +if (WARN_ON (ath12k_mac_vif_chan (vif, &def))) +return ; + + band = def.chan->band; + ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; + vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; + +switch (band) { +case NL80211_BAND_2GHZ : +if (sta->deflink.he_cap.has_he) { +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_80 ) + phymode =MODE_11AX_HE80_2G ; +else if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_40 ) + phymode =MODE_11AX_HE40_2G ; +else + phymode =MODE_11AX_HE20_2G ; + }else if (sta->deflink.vht_cap.vht_supported && + !ath12k_peer_assoc_h_vht_masked (vht_mcs_mask)) { +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_40 ) + phymode =MODE_11AC_VHT40 ; +else + phymode =MODE_11AC_VHT20 ; + }else if (sta->deflink.ht_cap.ht_supported && + !ath12k_peer_assoc_h_ht_masked (ht_mcs_mask)) { +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_40 ) + phymode =MODE_11NG_HT40 ; +else + phymode =MODE_11NG_HT20 ; + }else if (ath12k_mac_sta_has_ofdm_only (sta)) { + phymode =MODE_11G ; + }else { + phymode =MODE_11B ; + } +break ; +case NL80211_BAND_5GHZ : +case NL80211_BAND_6GHZ : +/* Check HE first */ +if (sta->deflink.he_cap.has_he) { + phymode =ath12k_mac_get_phymode_he (ar, sta); + }else if (sta->deflink.vht_cap.vht_supported && + !ath12k_peer_assoc_h_vht_masked (vht_mcs_mask)) { + phymode =ath12k_mac_get_phymode_vht (ar, sta); + }else if (sta->deflink.ht_cap.ht_supported && + !ath12k_peer_assoc_h_ht_masked (ht_mcs_mask)) { +if (sta->deflink.bandwidth >=IEEE80211_STA_RX_BW_40 ) + phymode =MODE_11NA_HT40 ; +else + phymode =MODE_11NA_HT20 ; + }else { + phymode =MODE_11A ; + } +break ; +default : +break ; + } + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac peer %pM phymode %s\n" , + sta->addr,ath12k_mac_phymode_str (phymode)); + + arg->peer_phymode = phymode; +WARN_ON (phymode ==MODE_UNKNOWN ); +} + +static void ath12k_peer_assoc_prepare (struct ath12k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ath12k_wmi_peer_assoc_arg *arg, +bool reassoc) +{ +lockdep_assert_held (&ar->conf_mutex); + +memset (arg,0 ,sizeof (*arg)); + +reinit_completion (&ar->peer_assoc_done); + + arg->peer_new_assoc = !reassoc; +ath12k_peer_assoc_h_basic (ar, vif, sta, arg); +ath12k_peer_assoc_h_crypto (ar, vif, sta, arg); +ath12k_peer_assoc_h_rates (ar, vif, sta, arg); +ath12k_peer_assoc_h_ht (ar, vif, sta, arg); +ath12k_peer_assoc_h_vht (ar, vif, sta, arg); +ath12k_peer_assoc_h_he (ar, vif, sta, arg); +ath12k_peer_assoc_h_qos (ar, vif, sta, arg); +ath12k_peer_assoc_h_phymode (ar, vif, sta, arg); +ath12k_peer_assoc_h_smps (sta, arg); + +/* TODO: amsdu_disable req? */ +} + +static int ath12k_setup_peer_smps (struct ath12k *ar,struct ath12k_vif *arvif, +const u8 *addr, +const struct ieee80211_sta_ht_cap *ht_cap) +{ +int smps; + +if (!ht_cap->ht_supported) +return 0 ; + + smps = ht_cap->cap &IEEE80211_HT_CAP_SM_PS ; + smps >>=IEEE80211_HT_CAP_SM_PS_SHIFT ; + +if (smps >=ARRAY_SIZE (ath12k_smps_map)) +return -EINVAL ; + +return ath12k_wmi_set_peer_param (ar, addr, arvif->vdev_id, +WMI_PEER_MIMO_PS_STATE , + ath12k_smps_map[smps]); +} + +static void ath12k_bss_assoc (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_bss_conf *bss_conf) +{ +struct ath12k *ar = hw->priv; +struct ath12k_vif *arvif = (void *)vif->drv_priv; +struct ath12k_wmi_peer_assoc_arg peer_arg; +struct ieee80211_sta *ap_sta; +struct ath12k_peer *peer; +bool is_auth = false; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac vdev %i assoc bssid %pM aid %d\n" , + arvif->vdev_id, arvif->bssid, arvif->aid); + +rcu_read_lock (); + + ap_sta =ieee80211_find_sta (vif, bss_conf->bssid); +if (!ap_sta) { +ath12k_warn (ar->ab,"failed to find station entry for bss %pM vdev %i\n" , + bss_conf->bssid, arvif->vdev_id); +rcu_read_unlock (); +return ; + } + +ath12k_peer_assoc_prepare (ar, vif, ap_sta, &peer_arg, false); + +rcu_read_unlock (); + + ret =ath12k_wmi_send_peer_assoc_cmd (ar, &peer_arg); +if (ret) { +ath12k_warn (ar->ab,"failed to run peer assoc for %pM vdev %i: %d\n" , + bss_conf->bssid, arvif->vdev_id, ret); +return ; + } + +if (!wait_for_completion_timeout (&ar->peer_assoc_done,1 *HZ )) { +ath12k_warn (ar->ab,"failed to get peer assoc conf event for %pM vdev %i\n" , + bss_conf->bssid, arvif->vdev_id); +return ; + } + + ret =ath12k_setup_peer_smps (ar, arvif, bss_conf->bssid, + &ap_sta->deflink.ht_cap); +if (ret) { +ath12k_warn (ar->ab,"failed to setup peer SMPS for vdev %d: %d\n" , + arvif->vdev_id, ret); +return ; + } + +WARN_ON (arvif->is_up); + + arvif->aid = vif->cfg.aid; +ether_addr_copy (arvif->bssid, bss_conf->bssid); + + ret =ath12k_wmi_vdev_up (ar, arvif->vdev_id, arvif->aid, arvif->bssid); +if (ret) { +ath12k_warn (ar->ab,"failed to set vdev %d up: %d\n" , + arvif->vdev_id, ret); +return ; + } + + arvif->is_up = true; + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC , +"mac vdev %d up (associated) bssid %pM aid %d\n" , + arvif->vdev_id, bss_conf->bssid, vif->cfg.aid); + +spin_lock_bh (&ar->ab->base_lock); + + peer =ath12k_peer_find (ar->ab, arvif->vdev_id, arvif->bssid); +if (peer && peer->is_authorized) + is_auth = true; + +spin_unlock_bh (&ar->ab->base_lock); + +/* Authorize BSS Peer */ +if (is_auth) { + ret =ath12k_wmi_set_peer_param (ar, arvif->bssid, + arvif->vdev_id, +WMI_PEER_AUTHORIZE , +1 ); +if (ret) +ath12k_warn (ar->ab,"Unable to authorize BSS peer: %d\n" , ret); + } + + ret =ath12k_wmi_send_obss_spr_cmd (ar, arvif->vdev_id, + &bss_conf->he_obss_pd); +if (ret) +ath12k_warn (ar->ab,"failed to set vdev %i OBSS PD parameters: %d\n" , + arvif->vdev_id, ret); +} + +static void ath12k_bss_disassoc (struct ieee80211_hw *hw, +struct ieee80211_vif *vif) +{ +struct ath12k *ar = hw->priv; +struct ath12k_vif *arvif = (void *)vif->drv_priv; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac vdev %i disassoc bssid %pM\n" , + arvif->vdev_id, arvif->bssid); + + ret =ath12k_wmi_vdev_down (ar, arvif->vdev_id); +if (ret) +ath12k_warn (ar->ab,"failed to down vdev %i: %d\n" , + arvif->vdev_id, ret); + + arvif->is_up = false; + +/* TODO: cancel connection_loss_work */ +} + +static u32 ath12k_mac_get_rate_hw_value (int bitrate) +{ +u32 preamble; +u16 hw_value; +int rate; +size_t i; + +if (ath12k_mac_bitrate_is_cck (bitrate)) + preamble =WMI_RATE_PREAMBLE_CCK ; +else + preamble =WMI_RATE_PREAMBLE_OFDM ; + +for (i =0 ; i <ARRAY_SIZE (ath12k_legacy_rates); i++) { +if (ath12k_legacy_rates[i].bitrate != bitrate) +continue ; + + hw_value = ath12k_legacy_rates[i].hw_value; + rate =ATH12K_HW_RATE_CODE (hw_value,0 , preamble); + +return rate; + } + +return -EINVAL ; +} + +static void ath12k_recalculate_mgmt_rate (struct ath12k *ar, +struct ieee80211_vif *vif, +struct cfg80211_chan_def *def) +{ +struct ath12k_vif *arvif = (void *)vif->drv_priv; +const struct ieee80211_supported_band *sband; +u8 basic_rate_idx; +int hw_rate_code; +u32 vdev_param; +u16 bitrate; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + + sband = ar->hw->wiphy->bands[def->chan->band]; + basic_rate_idx =ffs (vif->bss_conf.basic_rates) -1 ; + bitrate = sband->bitrates[basic_rate_idx].bitrate; + + hw_rate_code =ath12k_mac_get_rate_hw_value (bitrate); +if (hw_rate_code <0 ) { +ath12k_warn (ar->ab,"bitrate not supported %d\n" , bitrate); +return ; + } + + vdev_param =WMI_VDEV_PARAM_MGMT_RATE ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, vdev_param, + hw_rate_code); +if (ret) +ath12k_warn (ar->ab,"failed to set mgmt tx rate %d\n" , ret); + + vdev_param =WMI_VDEV_PARAM_BEACON_RATE ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, vdev_param, + hw_rate_code); +if (ret) +ath12k_warn (ar->ab,"failed to set beacon tx rate %d\n" , ret); +} + +static int ath12k_mac_fils_discovery (struct ath12k_vif *arvif, +struct ieee80211_bss_conf *info) +{ +struct ath12k *ar = arvif->ar; +struct sk_buff *tmpl; +int ret; +u32 interval; +bool unsol_bcast_probe_resp_enabled = false; + +if (info->fils_discovery.max_interval) { + interval = info->fils_discovery.max_interval; + + tmpl =ieee80211_get_fils_discovery_tmpl (ar->hw, arvif->vif); +if (tmpl) + ret =ath12k_wmi_fils_discovery_tmpl (ar, arvif->vdev_id, + tmpl); + }else if (info->unsol_bcast_probe_resp_interval) { + unsol_bcast_probe_resp_enabled =1 ; + interval = info->unsol_bcast_probe_resp_interval; + + tmpl =ieee80211_get_unsol_bcast_probe_resp_tmpl (ar->hw, + arvif->vif); +if (tmpl) + ret =ath12k_wmi_probe_resp_tmpl (ar, arvif->vdev_id, + tmpl); + }else {/* Disable */ +return ath12k_wmi_fils_discovery (ar, arvif->vdev_id,0 , false); + } + +if (!tmpl) { +ath12k_warn (ar->ab, +"mac vdev %i failed to retrieve %s template\n" , + arvif->vdev_id, (unsol_bcast_probe_resp_enabled ? +"unsolicited broadcast probe response" : +"FILS discovery" )); +return -EPERM ; + } +kfree_skb (tmpl); + +if (!ret) + ret =ath12k_wmi_fils_discovery (ar, arvif->vdev_id, interval, + unsol_bcast_probe_resp_enabled); + +return ret; +} + +static void ath12k_mac_op_bss_info_changed (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_bss_conf *info, +u64 changed) +{ +struct ath12k *ar = hw->priv; +struct ath12k_vif *arvif =ath12k_vif_to_arvif (vif); +struct cfg80211_chan_def def; +u32 param_id, param_value; +enum nl80211_band band; +u32 vdev_param; +int mcast_rate; +u32 preamble; +u16 hw_value; +u16 bitrate; +int ret; +u8 rateidx; +u32 rate; + +mutex_lock (&ar->conf_mutex); + +if (changed &BSS_CHANGED_BEACON_INT ) { + arvif->beacon_interval = info->beacon_int; + + param_id =WMI_VDEV_PARAM_BEACON_INTERVAL ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, + arvif->beacon_interval); +if (ret) +ath12k_warn (ar->ab,"Failed to set beacon interval for VDEV: %d\n" , + arvif->vdev_id); +else +ath12k_dbg (ar->ab,ATH12K_DBG_MAC , +"Beacon interval: %d set for VDEV: %d\n" , + arvif->beacon_interval, arvif->vdev_id); + } + +if (changed &BSS_CHANGED_BEACON ) { + param_id =WMI_PDEV_PARAM_BEACON_TX_MODE ; + param_value =WMI_BEACON_STAGGERED_MODE ; + ret =ath12k_wmi_pdev_set_param (ar, param_id, + param_value, ar->pdev->pdev_id); +if (ret) +ath12k_warn (ar->ab,"Failed to set beacon mode for VDEV: %d\n" , + arvif->vdev_id); +else +ath12k_dbg (ar->ab,ATH12K_DBG_MAC , +"Set staggered beacon mode for VDEV: %d\n" , + arvif->vdev_id); + + ret =ath12k_mac_setup_bcn_tmpl (arvif); +if (ret) +ath12k_warn (ar->ab,"failed to update bcn template: %d\n" , + ret); + } + +if (changed & (BSS_CHANGED_BEACON_INFO |BSS_CHANGED_BEACON )) { + arvif->dtim_period = info->dtim_period; + + param_id =WMI_VDEV_PARAM_DTIM_PERIOD ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, + arvif->dtim_period); + +if (ret) +ath12k_warn (ar->ab,"Failed to set dtim period for VDEV %d: %i\n" , + arvif->vdev_id, ret); +else +ath12k_dbg (ar->ab,ATH12K_DBG_MAC , +"DTIM period: %d set for VDEV: %d\n" , + arvif->dtim_period, arvif->vdev_id); + } + +if (changed &BSS_CHANGED_SSID && + vif->type ==NL80211_IFTYPE_AP ) { + arvif->u.ap.ssid_len = vif->cfg.ssid_len; +if (vif->cfg.ssid_len) +memcpy (arvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len); + arvif->u.ap.hidden_ssid = info->hidden_ssid; + } + +if (changed &BSS_CHANGED_BSSID && !is_zero_ether_addr (info->bssid)) +ether_addr_copy (arvif->bssid, info->bssid); + +if (changed &BSS_CHANGED_BEACON_ENABLED ) { +ath12k_control_beaconing (arvif, info); + +if (arvif->is_up && vif->bss_conf.he_support && + vif->bss_conf.he_oper.params) { +/* TODO: Extend to support 1024 BA Bitmap size */ + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, +WMI_VDEV_PARAM_BA_MODE , +WMI_BA_MODE_BUFFER_SIZE_256 ); +if (ret) +ath12k_warn (ar->ab, +"failed to set BA BUFFER SIZE 256 for vdev: %d\n" , + arvif->vdev_id); + + param_id =WMI_VDEV_PARAM_HEOPS_0_31 ; + param_value = vif->bss_conf.he_oper.params; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, param_value); +ath12k_dbg (ar->ab,ATH12K_DBG_MAC , +"he oper param: %x set for VDEV: %d\n" , + param_value, arvif->vdev_id); + +if (ret) +ath12k_warn (ar->ab,"Failed to set he oper params %x for VDEV %d: %i\n" , + param_value, arvif->vdev_id, ret); + } + } + +if (changed &BSS_CHANGED_ERP_CTS_PROT ) { +u32 cts_prot; + + cts_prot = !!(info->use_cts_prot); + param_id =WMI_VDEV_PARAM_PROTECTION_MODE ; + +if (arvif->is_started) { + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, cts_prot); +if (ret) +ath12k_warn (ar->ab,"Failed to set CTS prot for VDEV: %d\n" , + arvif->vdev_id); +else +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"Set CTS prot: %d for VDEV: %d\n" , + cts_prot, arvif->vdev_id); + }else { +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"defer protection mode setup, vdev is not ready yet\n" ); + } + } + +if (changed &BSS_CHANGED_ERP_SLOT ) { +u32 slottime; + +if (info->use_short_slot) + slottime =WMI_VDEV_SLOT_TIME_SHORT ;/* 9us */ + +else + slottime =WMI_VDEV_SLOT_TIME_LONG ;/* 20us */ + + param_id =WMI_VDEV_PARAM_SLOT_TIME ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, slottime); +if (ret) +ath12k_warn (ar->ab,"Failed to set erp slot for VDEV: %d\n" , + arvif->vdev_id); +else +ath12k_dbg (ar->ab,ATH12K_DBG_MAC , +"Set slottime: %d for VDEV: %d\n" , + slottime, arvif->vdev_id); + } + +if (changed &BSS_CHANGED_ERP_PREAMBLE ) { +u32 preamble; + +if (info->use_short_preamble) + preamble =WMI_VDEV_PREAMBLE_SHORT ; +else + preamble =WMI_VDEV_PREAMBLE_LONG ; + + param_id =WMI_VDEV_PARAM_PREAMBLE ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, preamble); +if (ret) +ath12k_warn (ar->ab,"Failed to set preamble for VDEV: %d\n" , + arvif->vdev_id); +else +ath12k_dbg (ar->ab,ATH12K_DBG_MAC , +"Set preamble: %d for VDEV: %d\n" , + preamble, arvif->vdev_id); + } + +if (changed &BSS_CHANGED_ASSOC ) { +if (vif->cfg.assoc) +ath12k_bss_assoc (hw, vif, info); +else +ath12k_bss_disassoc (hw, vif); + } + +if (changed &BSS_CHANGED_TXPOWER ) { +ath12k_dbg (ar->ab,ATH12K_DBG_MAC ,"mac vdev_id %i txpower %d\n" , + arvif->vdev_id, info->txpower); + + arvif->txpower = info->txpower; +ath12k_mac_txpower_recalc (ar); + } + +if (changed &BSS_CHANGED_MCAST_RATE && + !ath12k_mac_vif_chan (arvif->vif, &def)) { + band = def.chan->band; + mcast_rate = vif->bss_conf.mcast_rate[band]; + +if (mcast_rate >0 ) + rateidx = mcast_rate -1 ; +else + rateidx =ffs (vif->bss_conf.basic_rates) -1 ; + +if (ar->pdev->cap.supported_bands &WMI_HOST_WLAN_5G_CAP ) + rateidx +=ATH12K_MAC_FIRST_OFDM_RATE_IDX ; + + bitrate = ath12k_legacy_rates[rateidx].bitrate; + hw_value = ath12k_legacy_rates[rateidx].hw_value; + +if (ath12k_mac_bitrate_is_cck (bitrate)) + preamble =WMI_RATE_PREAMBLE_CCK ; +else + preamble =WMI_RATE_PREAMBLE_OFDM ; + + rate =ATH12K_HW_RATE_CODE (hw_value,0 , preamble); + +ath12k_dbg (ar->ab,ATH12K_DBG_MAC , +"mac vdev %d mcast_rate %x\n" , + arvif->vdev_id, rate); + + vdev_param =WMI_VDEV_PARAM_MCAST_DATA_RATE ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + vdev_param, rate); +if (ret) +ath12k_warn (ar->ab, +"failed to set mcast rate on vdev %i: %d\n" , + arvif->vdev_id, ret); + + vdev_param =WMI_VDEV_PARAM_BCAST_DATA_RATE ; + ret =ath12k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + vdev_param, rate); +if (ret) +ath12k_warn (ar->ab, +"failed to set bcast rate on vdev %i: %d\n" , + arvif->vdev_id, ret); + } + +if (changed &BSS_CHANGED_BASIC_RATES && + !ath12k_mac_vif_chan (arvif->vif, &def)) +ath12k_recalculate_mgmt_rate (ar, vif, &def); + +if (changed &BSS_CHANGED_TWT ) { +if (info->twt_requester || info->twt_responder) +ath12k_wmi_send_twt_enable_cmd (ar, ar->pdev->pdev_id); +else +ath12k_wmi_send_twt_disable_cmd (ar, ar->pdev->pdev_id); + } + +if (changed &BSS_CHANGED_HE_OBSS_PD ) +ath12k_wmi_send_obss_spr_cmd (ar, arvif->vdev_id, + &info->he_obss_pd); + +if (changed &BSS_CHANGED_HE_BSS_COLOR ) { +if (vif->type ==NL80211_IFTYPE_AP ) { + ret =ath12k_wmi_obss_color_cfg_cmd (ar, + arvif->vdev_id, + info->he_bss_color.color, +ATH12K_BSS_COLOR_AP_PERIODS , + info->he_bss_color.enabled); +if (ret) +ath12k_warn (ar->ab,"failed to set bss color collision on vdev %i: %d\n" , + arvif->vdev_id, ret); + }else if (vif->type ==NL80211_IFTYPE_STATION ) { + ret =ath12k_wmi_send_bss_color_change_enable_cmd (ar, + arvif->vdev_id, +1 ); +if (ret) +ath12k_warn (ar->ab,"failed to enable bss color change on vdev %i: %d\n" , + arvif->vdev_id, ret); + ret =ath12k_wmi_obss_color_cfg_cmd (ar, + arvif->vdev_id, +0 , +ATH12K_BSS_COLOR_STA_PERIODS , +1 ); +if (ret) +ath12k_warn (ar->ab,"failed to set bss color collision on vdev %i: %d\n" , + arvif->vdev_id, ret); + } + } + +if (changed &BSS_CHANGED_FILS_DISCOVERY || + changed &BSS_CHANGED_UNSOL_BCAST_PROBE_RESP ) +ath12k_mac_fils_discovery (arvif, info); + +mutex_unlock (&ar->conf_mutex); +} + +void __ath12k_mac_scan_finish (struct ath12k *ar) +{ +lockdep_assert_held (&ar->data_lock); + +switch (ar->scan.state) { +case ATH12K_SCAN_IDLE : +break ; +case ATH12K_SCAN_RUNNING : +case ATH12K_SCAN_ABORTING : +if (!ar->scan.is_roc) { +struct cfg80211_scan_info info = { + .aborted = (ar->scan.state == +ATH12K_SCAN_ABORTING ), + }; + +ieee80211_scan_completed (ar->hw, &info); + }else if (ar->scan.roc_notify) { +ieee80211_remain_on_channel_expired (ar->hw); + } + fallthrough; +case ATH12K_SCAN_STARTING : + ar->scan.state =ATH12K_SCAN_IDLE ; + ar->scan_channel =NULL ; + ar->scan.roc_freq =0 ; +cancel_delayed_work (&ar->scan.timeout); +complete (&ar->scan.completed); +break ; + } +} + +void ath12k_mac_scan_finish (struct ath12k *ar) +{ +spin_lock_bh (&ar->data_lock); +__ath12k_mac_scan_finish (ar); +spin_unlock_bh (&ar->data_lock); +} + +static int ath12k_scan_stop (struct ath12k *ar) +{ +struct ath12k_wmi_scan_cancel_arg arg = { + .req_type =WLAN_SCAN_CANCEL_SINGLE , + .scan_id =ATH12K_SCAN_ID , + }; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +/* TODO: Fill other STOP Params */ + arg.pdev_id = ar->pdev->pdev_id; + + ret =ath12k_wmi_send_scan_stop_cmd (ar, &arg); +if (ret) { +ath12k_warn (ar->ab,"failed to stop wmi scan: %d\n" , ret); + goto out; + } + + ret =wait_for_completion_timeout (&ar->scan.completed,3 *HZ ); +if (ret ==0 ) { +ath12k_warn (ar->ab, +"failed to receive scan abort comple: timed out\n" ); + ret = -ETIMEDOUT ; + }else if (ret >0 ) { + ret =0 ; + } + +out: +/* Scan state should be updated upon scan completion but in case +* firmware fails to deliver the event (for whatever reason) it is +* desired to clean up scan state anyway. Firmware may have just +* dropped the scan completion event delivery due to transport pipe +* being overflown with data and/or it can recover on its own before +* next scan request is submitted. +*/ +spin_lock_bh (&ar->data_lock); +if (ar->scan.state !=ATH12K_SCAN_IDLE ) +__ath12k_mac_scan_finish (ar); +spin_unlock_bh (&ar->data_lock); + +return ret; +} + +static void ath12k_scan_abort (struct ath12k *ar) +{ +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +spin_lock_bh (&ar->data_lock); + +switch (ar->scan.state) { +case ATH12K_SCAN_IDLE : +/* This can happen if timeout worker kicked in and called +* abortion while scan completion was being processed. +*/ +break ; +case ATH12K_SCAN_STARTING : +case ATH12K_SCAN_ABORTING : +ath12k_warn (ar->ab,"refusing scan abortion due to invalid scan state: %d\n" , + ar->scan.state); +break ; +case ATH12K_SCAN_RUNNING : + ar->scan.state =ATH12K_SCAN_ABORTING ; +spin_unlock_bh (&ar->data_lock); + + ret =ath12k_scan_stop (ar); +if (ret) +ath12k_warn (ar->ab,"failed to abort scan: %d\n" , ret); + +spin_lock_bh (&ar->data_lock); +break ; + } + +spin_unlock_bh (&ar->data_lock); +} + +static void ath12k_scan_timeout_work (struct work_struct *work) +{ + struct ath12k *ar = container_of(work, struct ath12k, + scan.timeout.work); + +mutex_lock (&ar->conf_mutex); +ath12k_scan_abort (ar); +mutex_unlock (&ar->conf_mutex); +} + +static int ath12k_start_scan (struct ath12k *ar, +struct ath12k_wmi_scan_req_arg *arg) +{ +int ret; + +lockdep_assert_held (&ar->conf_mutex); + + ret =ath12k_wmi_send_scan_start_cmd (ar, arg); +if (ret) +return ret; + + ret =wait_for_completion_timeout (&ar->scan.started,1 *HZ ); +if (ret ==0 ) { + ret =ath12k_scan_stop (ar); +if (ret) +ath12k_warn (ar->ab,"failed to stop scan: %d\n" , ret); + +return -ETIMEDOUT ; + } + +/* If we failed to start the scan, return error code at +* this point. This is probably due to some issue in the +* firmware, but no need to wedge the driver due to that... +*/ +spin_lock_bh (&ar->data_lock); +if (ar->scan.state ==ATH12K_SCAN_IDLE ) { +spin_unlock_bh (&ar->data_lock); +return -EINVAL ; + } +spin_unlock_bh (&ar->data_lock); + +return 0 ; +} + +static int ath12k_mac_op_hw_scan (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_scan_request *hw_req) +{ +struct ath12k *ar = hw->priv; +struct ath12k_vif *arvif =ath12k_vif_to_arvif (vif); +struct cfg80211_scan_request *req = &hw_req->req; +struct ath12k_wmi_scan_req_arg arg = {}; +int ret; +int i; + +mutex_lock (&ar->conf_mutex); + +spin_lock_bh (&ar->data_lock); +switch (ar->scan.state) { +case ATH12K_SCAN_IDLE : +reinit_completion (&ar->scan.started); +reinit_completion (&ar->scan.completed); + ar->scan.state =ATH12K_SCAN_STARTING ; + ar->scan.is_roc = false; + ar->scan.vdev_id = arvif->vdev_id; + ret =0 ; +break ; +case ATH12K_SCAN_STARTING : +case ATH12K_SCAN_RUNNING : +case ATH12K_SCAN_ABORTING : + ret = -EBUSY ; +break ; + } +spin_unlock_bh (&ar->data_lock); + +if (ret) + goto exit; + +ath12k_wmi_start_scan_init (ar, &arg); + arg.vdev_id = arvif->vdev_id; + arg.scan_id =ATH12K_SCAN_ID ; + +if (req->ie_len) { + arg.extraie.len = req->ie_len; + arg.extraie.ptr =kzalloc (req->ie_len,GFP_KERNEL ); +memcpy (arg.extraie.ptr, req->ie, req->ie_len); + } + +if (req->n_ssids) { + arg.num_ssids = req->n_ssids; +for (i =0 ; i < arg.num_ssids; i++) + arg.ssid[i] = req->ssids[i]; + }else { + arg.scan_flags |=WMI_SCAN_FLAG_PASSIVE ; + } + +if (req->n_channels) { + arg.num_chan = req->n_channels; +for (i =0 ; i < arg.num_chan; i++) + arg.chan_list[i] = req->channels[i]->center_freq; + } + + ret =ath12k_start_scan (ar, &arg); +if (ret) { +ath12k_warn (ar->ab,"failed to start hw scan: %d\n" , ret); +spin_lock_bh (&ar->data_lock); + ar->scan.state =ATH12K_SCAN_IDLE ; +spin_unlock_bh (&ar->data_lock); + } + +/* Add a margin to account for event/command processing */ +ieee80211_queue_delayed_work (ar->hw, &ar->scan.timeout, +msecs_to_jiffies (arg.max_scan_time + +ATH12K_MAC_SCAN_TIMEOUT_MSECS )); + +exit: +if (req->ie_len) +kfree (arg.extraie.ptr); + +mutex_unlock (&ar->conf_mutex); +return ret; +} + +static void ath12k_mac_op_cancel_hw_scan (struct ieee80211_hw *hw, +struct ieee80211_vif *vif) +{ +struct ath12k *ar = hw->priv; + +mutex_lock (&ar->conf_mutex); +ath12k_scan_abort (ar); +mutex_unlock (&ar->conf_mutex); + +cancel_delayed_work_sync (&ar->scan.timeout); +} + +static int ath12k_install_key (struct ath12k_vif *arvif, +struct ieee80211_key_conf *key, +enum set_key_cmd cmd, +const u8 *macaddr,u32 flags) +{ +int ret; +struct ath12k *ar = arvif->ar; +struct wmi_vdev_install_key_arg arg = { + .vdev_id = arvif->vdev_id, + .key_idx = key->keyidx, + .key_len = key->keylen, + .key_data = key->key, + .key_flags = flags, + .macaddr = macaddr, + }; + +lockdep_assert_held (&arvif->ar->conf_mutex); + +reinit_completion (&ar->install_key_done); + +if (test_bit (ATH12K_FLAG_HW_CRYPTO_DISABLED , &ar->ab->dev_flags)) +return 0 ; + +if (cmd ==DISABLE_KEY ) { +/* TODO: Check if FW expects value other than NONE for del */ +/* arg.key_cipher = WMI_CIPHER_NONE; */ + arg.key_len =0 ; + arg.key_data =NULL ; + goto install; + } + +switch (key->cipher) { +case WLAN_CIPHER_SUITE_CCMP : + arg.key_cipher =WMI_CIPHER_AES_CCM ; +/* TODO: Re-check if flag is valid */ + key->flags |=IEEE80211_KEY_FLAG_GENERATE_IV_MGMT ; +break ; +case WLAN_CIPHER_SUITE_TKIP : + arg.key_cipher =WMI_CIPHER_TKIP ; + arg.key_txmic_len =8 ; + arg.key_rxmic_len =8 ; +break ; +case WLAN_CIPHER_SUITE_CCMP_256 : + arg.key_cipher =WMI_CIPHER_AES_CCM ; +break ; +case WLAN_CIPHER_SUITE_GCMP : +case WLAN_CIPHER_SUITE_GCMP_256 : + arg.key_cipher =WMI_CIPHER_AES_GCM ; +break ; +default : +ath12k_warn (ar->ab,"cipher %d is not supported\n" , key->cipher); +return -EOPNOTSUPP ; + } + +if (test_bit (ATH12K_FLAG_RAW_MODE , &ar->ab->dev_flags)) + key->flags |=IEEE80211_KEY_FLAG_GENERATE_IV | +IEEE80211_KEY_FLAG_RESERVE_TAILROOM ; + +install: + ret =ath12k_wmi_vdev_install_key (arvif->ar, &arg); + +if (ret) +return ret; + +if (!wait_for_completion_timeout (&ar->install_key_done,1 *HZ )) +return -ETIMEDOUT ; + +if (ether_addr_equal (macaddr, arvif->vif->addr)) + arvif->key_cipher = key->cipher; + +return ar->install_key_status ? -EINVAL :0 ; +} + +static int ath12k_clear_peer_keys (struct ath12k_vif *arvif, +const u8 *addr) +{ +struct ath12k *ar = arvif->ar; +struct ath12k_base *ab = ar->ab; +struct ath12k_peer *peer; +int first_errno =0 ; +int ret; +int i; +u32 flags =0 ; + +lockdep_assert_held (&ar->conf_mutex); + +spin_lock_bh (&ab->base_lock); + peer =ath12k_peer_find (ab, arvif->vdev_id, addr); +spin_unlock_bh (&ab->base_lock); + +if (!peer) +return -ENOENT ; + +for (i =0 ; i <ARRAY_SIZE (peer->keys); i++) { +if (!peer->keys[i]) +continue ; + +/* key flags are not required to delete the key */ + ret =ath12k_install_key (arvif, peer->keys[i], +DISABLE_KEY , addr, flags); +if (ret <0 && first_errno ==0 ) + first_errno = ret; + +if (ret <0 ) +ath12k_warn (ab,"failed to remove peer key %d: %d\n" , + i, ret); + +spin_lock_bh (&ab->base_lock); + peer->keys[i] =NULL ; +spin_unlock_bh (&ab->base_lock); + } + +return first_errno; +} + +static int ath12k_mac_op_set_key (struct ieee80211_hw *hw,enum set_key_cmd cmd, +struct ieee80211_vif *vif,struct ieee80211_sta *sta, +struct ieee80211_key_conf *key) +{ +struct ath12k *ar = hw->priv; +struct ath12k_base *ab = ar->ab; +struct ath12k_vif *arvif =ath12k_vif_to_arvif (vif); +struct ath12k_peer *peer; +struct ath12k_sta *arsta; +const u8 *peer_addr; +int ret =0 ; +u32 flags =0 ; + +/* BIP needs to be done in software */ +if (key->cipher ==WLAN_CIPHER_SUITE_AES_CMAC || + key->cipher ==WLAN_CIPHER_SUITE_BIP_GMAC_128 || + key->cipher ==WLAN_CIPHER_SUITE_BIP_GMAC_256 || + key->cipher ==WLAN_CIPHER_SUITE_BIP_CMAC_256 ) +return 1 ; + +if (test_bit (ATH12K_FLAG_HW_CRYPTO_DISABLED , &ar->ab->dev_flags)) +return 1 ; + +if (key->keyidx >WMI_MAX_KEY_INDEX ) +return -ENOSPC ; + +mutex_lock (&ar->conf_mutex); + +if (sta) + peer_addr = sta->addr; +else if (arvif->vdev_type ==WMI_VDEV_TYPE_STA ) + peer_addr = vif->bss_conf.bssid; +else + peer_addr = vif->addr; + + key->hw_key_idx = key->keyidx; + +/* the peer should not disappear in mid-way (unless FW goes awry) since +* we already hold conf_mutex. we just make sure its there now. +*/ +spin_lock_bh (&ab->base_lock); + peer =ath12k_peer_find (ab, arvif->vdev_id, peer_addr); +spin_unlock_bh (&ab->base_lock); + +if (!peer) { +if (cmd ==SET_KEY ) { +ath12k_warn (ab,"cannot install key for non-existent peer %pM\n" , + peer_addr); + ret = -EOPNOTSUPP ; + goto exit; + }else { +/* if the peer doesn't exist there is no key to disable +* anymore +*/ + goto exit; + } + } + +if (key->flags &IEEE80211_KEY_FLAG_PAIRWISE ) + flags |=WMI_KEY_PAIRWISE ; +else + flags |=WMI_KEY_GROUP ; + + ret =ath12k_install_key (arvif, key, cmd, peer_addr, flags); +if (ret) { +ath12k_warn (ab,"ath12k_install_key failed (%d)\n" , ret); + goto exit; + } + + ret =ath12k_dp_rx_peer_pn_replay_config (arvif, peer_addr, cmd, key); +if (ret) { +ath12k_warn (ab,"failed to offload PN replay detection %d\n" , ret); + goto exit; + } + +spin_lock_bh (&ab->base_lock); + peer =ath12k_peer_find (ab, arvif->vdev_id, peer_addr); +if (peer && cmd ==SET_KEY ) { + peer->keys[key->keyidx] = key;
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
Part of the diff is not shown here. View the raw message.
PATCH v2 33/50 wifi: ath12k: add mhi.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/mhi.c | 616 ++++++++++++++++++++++++++++++++++ 1 file changed, 616 insertions(+)
drivers/net/wireless/ath/ath12k/mhi.c new file +616 -0
@@ -0,0 +1,616 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2020-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include <linux/msi.h> +#include <linux/pci.h> + +#include "core.h" +#include "debug.h" +#include "mhi.h" +#include "pci.h" + +#define MHI_TIMEOUT_DEFAULT_MS 90000 + +static const struct mhi_channel_config ath12k_mhi_channels_qcn9274[] = { + { + .num =0 , + .name ="LOOPBACK" , + .num_elements =32 , + .event_ring =1 , + .dir =DMA_TO_DEVICE , + .ee_mask =0x4 , + .pollcfg =0 , + .doorbell =MHI_DB_BRST_DISABLE , + .lpm_notify = false, + .offload_channel = false, + .doorbell_mode_switch = false, + .auto_queue = false, + }, + { + .num =1 , + .name ="LOOPBACK" , + .num_elements =32 , + .event_ring =1 , + .dir =DMA_FROM_DEVICE , + .ee_mask =0x4 , + .pollcfg =0 , + .doorbell =MHI_DB_BRST_DISABLE , + .lpm_notify = false, + .offload_channel = false, + .doorbell_mode_switch = false, + .auto_queue = false, + }, + { + .num =20 , + .name ="IPCR" , + .num_elements =32 , + .event_ring =1 , + .dir =DMA_TO_DEVICE , + .ee_mask =0x4 , + .pollcfg =0 , + .doorbell =MHI_DB_BRST_DISABLE , + .lpm_notify = false, + .offload_channel = false, + .doorbell_mode_switch = false, + .auto_queue = false, + }, + { + .num =21 , + .name ="IPCR" , + .num_elements =32 , + .event_ring =1 , + .dir =DMA_FROM_DEVICE , + .ee_mask =0x4 , + .pollcfg =0 , + .doorbell =MHI_DB_BRST_DISABLE , + .lpm_notify = false, + .offload_channel = false, + .doorbell_mode_switch = false, + .auto_queue = true, + }, +}; + +static struct mhi_event_config ath12k_mhi_events_qcn9274[] = { + { + .num_elements =32 , + .irq_moderation_ms =0 , + .irq =1 , + .data_type =MHI_ER_CTRL , + .mode =MHI_DB_BRST_DISABLE , + .hardware_event = false, + .client_managed = false, + .offload_channel = false, + }, + { + .num_elements =256 , + .irq_moderation_ms =1 , + .irq =2 , + .mode =MHI_DB_BRST_DISABLE , + .priority =1 , + .hardware_event = false, + .client_managed = false, + .offload_channel = false, + }, +}; + +const struct mhi_controller_config ath12k_mhi_config_qcn9274 = { + .max_channels =30 , + .timeout_ms =10000 , + .use_bounce_buf = false, + .buf_len =0 , + .num_channels =ARRAY_SIZE (ath12k_mhi_channels_qcn9274), + .ch_cfg = ath12k_mhi_channels_qcn9274, + .num_events =ARRAY_SIZE (ath12k_mhi_events_qcn9274), + .event_cfg = ath12k_mhi_events_qcn9274, +}; + +static const struct mhi_channel_config ath12k_mhi_channels_wcn7850[] = { + { + .num =0 , + .name ="LOOPBACK" , + .num_elements =32 , + .event_ring =0 , + .dir =DMA_TO_DEVICE , + .ee_mask =0x4 , + .pollcfg =0 , + .doorbell =MHI_DB_BRST_DISABLE , + .lpm_notify = false, + .offload_channel = false, + .doorbell_mode_switch = false, + .auto_queue = false, + }, + { + .num =1 , + .name ="LOOPBACK" , + .num_elements =32 , + .event_ring =0 , + .dir =DMA_FROM_DEVICE , + .ee_mask =0x4 , + .pollcfg =0 , + .doorbell =MHI_DB_BRST_DISABLE , + .lpm_notify = false, + .offload_channel = false, + .doorbell_mode_switch = false, + .auto_queue = false, + }, + { + .num =20 , + .name ="IPCR" , + .num_elements =64 , + .event_ring =1 , + .dir =DMA_TO_DEVICE , + .ee_mask =0x4 , + .pollcfg =0 , + .doorbell =MHI_DB_BRST_DISABLE , + .lpm_notify = false, + .offload_channel = false, + .doorbell_mode_switch = false, + .auto_queue = false, + }, + { + .num =21 , + .name ="IPCR" , + .num_elements =64 , + .event_ring =1 , + .dir =DMA_FROM_DEVICE , + .ee_mask =0x4 , + .pollcfg =0 , + .doorbell =MHI_DB_BRST_DISABLE , + .lpm_notify = false, + .offload_channel = false, + .doorbell_mode_switch = false, + .auto_queue = true, + }, +}; + +static struct mhi_event_config ath12k_mhi_events_wcn7850[] = { + { + .num_elements =32 , + .irq_moderation_ms =0 , + .irq =1 , + .mode =MHI_DB_BRST_DISABLE , + .data_type =MHI_ER_CTRL , + .hardware_event = false, + .client_managed = false, + .offload_channel = false, + }, + { + .num_elements =256 , + .irq_moderation_ms =1 , + .irq =2 , + .mode =MHI_DB_BRST_DISABLE , + .priority =1 , + .hardware_event = false, + .client_managed = false, + .offload_channel = false, + }, +}; + +const struct mhi_controller_config ath12k_mhi_config_wcn7850 = { + .max_channels =128 , + .timeout_ms =2000 , + .use_bounce_buf = false, + .buf_len =0 , + .num_channels =ARRAY_SIZE (ath12k_mhi_channels_wcn7850), + .ch_cfg = ath12k_mhi_channels_wcn7850, + .num_events =ARRAY_SIZE (ath12k_mhi_events_wcn7850), + .event_cfg = ath12k_mhi_events_wcn7850, +}; + +void ath12k_mhi_set_mhictrl_reset (struct ath12k_base *ab) +{ +u32 val; + + val =ath12k_pci_read32 (ab,MHISTATUS ); + +ath12k_dbg (ab,ATH12K_DBG_PCI ,"MHISTATUS 0x%x\n" , val); + +/* Observed on some targets that after SOC_GLOBAL_RESET, MHISTATUS +* has SYSERR bit set and thus need to set MHICTRL_RESET +* to clear SYSERR. +*/ +ath12k_pci_write32 (ab,MHICTRL ,MHICTRL_RESET_MASK ); + +mdelay (10 ); +} + +static void ath12k_mhi_reset_txvecdb (struct ath12k_base *ab) +{ +ath12k_pci_write32 (ab,PCIE_TXVECDB ,0 ); +} + +static void ath12k_mhi_reset_txvecstatus (struct ath12k_base *ab) +{ +ath12k_pci_write32 (ab,PCIE_TXVECSTATUS ,0 ); +} + +static void ath12k_mhi_reset_rxvecdb (struct ath12k_base *ab) +{ +ath12k_pci_write32 (ab,PCIE_RXVECDB ,0 ); +} + +static void ath12k_mhi_reset_rxvecstatus (struct ath12k_base *ab) +{ +ath12k_pci_write32 (ab,PCIE_RXVECSTATUS ,0 ); +} + +void ath12k_mhi_clear_vector (struct ath12k_base *ab) +{ +ath12k_mhi_reset_txvecdb (ab); +ath12k_mhi_reset_txvecstatus (ab); +ath12k_mhi_reset_rxvecdb (ab); +ath12k_mhi_reset_rxvecstatus (ab); +} + +static int ath12k_mhi_get_msi (struct ath12k_pci *ab_pci) +{ +struct ath12k_base *ab = ab_pci->ab; +u32 user_base_data, base_vector; +int ret, num_vectors, i; +int *irq; + + ret =ath12k_pci_get_user_msi_assignment (ab, +"MHI" , &num_vectors, + &user_base_data, &base_vector); +if (ret) +return ret; + +ath12k_dbg (ab,ATH12K_DBG_PCI ,"Number of assigned MSI for MHI is %d, base vector is %d\n" , + num_vectors, base_vector); + + irq =kcalloc (num_vectors,sizeof (*irq),GFP_KERNEL ); +if (!irq) +return -ENOMEM ; + +for (i =0 ; i < num_vectors; i++) + irq[i] =ath12k_pci_get_msi_irq (ab->dev, + base_vector + i); + + ab_pci->mhi_ctrl->irq = irq; + ab_pci->mhi_ctrl->nr_irqs = num_vectors; + +return 0 ; +} + +static int ath12k_mhi_op_runtime_get (struct mhi_controller *mhi_cntrl) +{ +return 0 ; +} + +static void ath12k_mhi_op_runtime_put (struct mhi_controller *mhi_cntrl) +{ +} + +static char *ath12k_mhi_op_callback_to_str (enum mhi_callback reason) +{ +switch (reason) { +case MHI_CB_IDLE : +return "MHI_CB_IDLE" ; +case MHI_CB_PENDING_DATA : +return "MHI_CB_PENDING_DATA" ; +case MHI_CB_LPM_ENTER : +return "MHI_CB_LPM_ENTER" ; +case MHI_CB_LPM_EXIT : +return "MHI_CB_LPM_EXIT" ; +case MHI_CB_EE_RDDM : +return "MHI_CB_EE_RDDM" ; +case MHI_CB_EE_MISSION_MODE : +return "MHI_CB_EE_MISSION_MODE" ; +case MHI_CB_SYS_ERROR : +return "MHI_CB_SYS_ERROR" ; +case MHI_CB_FATAL_ERROR : +return "MHI_CB_FATAL_ERROR" ; +case MHI_CB_BW_REQ : +return "MHI_CB_BW_REQ" ; +default : +return "UNKNOWN" ; + } +} + +static void ath12k_mhi_op_status_cb (struct mhi_controller *mhi_cntrl, +enum mhi_callback cb) +{ +struct ath12k_base *ab =dev_get_drvdata (mhi_cntrl->cntrl_dev); + +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"mhi notify status reason %s\n" , +ath12k_mhi_op_callback_to_str (cb)); + +switch (cb) { +case MHI_CB_SYS_ERROR : +ath12k_warn (ab,"firmware crashed: MHI_CB_SYS_ERROR\n" ); +break ; +case MHI_CB_EE_RDDM : +if (!(test_bit (ATH12K_FLAG_UNREGISTERING , &ab->dev_flags))) +queue_work (ab->workqueue_aux, &ab->reset_work); +break ; +default : +break ; + } +} + +static int ath12k_mhi_op_read_reg (struct mhi_controller *mhi_cntrl, +void __iomem *addr, +u32 *out) +{ + *out =readl (addr); + +return 0 ; +} + +static void ath12k_mhi_op_write_reg (struct mhi_controller *mhi_cntrl, +void __iomem *addr, +u32 val) +{ +writel (val, addr); +} + +int ath12k_mhi_register (struct ath12k_pci *ab_pci) +{ +struct ath12k_base *ab = ab_pci->ab; +struct mhi_controller *mhi_ctrl; +int ret; + + mhi_ctrl =mhi_alloc_controller (); +if (!mhi_ctrl) +return -ENOMEM ; + +ath12k_core_create_firmware_path (ab,ATH12K_AMSS_FILE , + ab_pci->amss_path, +sizeof (ab_pci->amss_path)); + + ab_pci->mhi_ctrl = mhi_ctrl; + mhi_ctrl->cntrl_dev = ab->dev; + mhi_ctrl->fw_image = ab_pci->amss_path; + mhi_ctrl->regs = ab->mem; + mhi_ctrl->reg_len = ab->mem_len; + + ret =ath12k_mhi_get_msi (ab_pci); +if (ret) { +ath12k_err (ab,"failed to get msi for mhi\n" ); +mhi_free_controller (mhi_ctrl); +return ret; + } + + mhi_ctrl->iova_start =0 ; + mhi_ctrl->iova_stop =0xffffffff ; + mhi_ctrl->sbl_size =SZ_512K ; + mhi_ctrl->seg_len =SZ_512K ; + mhi_ctrl->fbc_download = true; + mhi_ctrl->runtime_get = ath12k_mhi_op_runtime_get; + mhi_ctrl->runtime_put = ath12k_mhi_op_runtime_put; + mhi_ctrl->status_cb = ath12k_mhi_op_status_cb; + mhi_ctrl->read_reg = ath12k_mhi_op_read_reg; + mhi_ctrl->write_reg = ath12k_mhi_op_write_reg; + + ret =mhi_register_controller (mhi_ctrl, ab->hw_params->mhi_config); +if (ret) { +ath12k_err (ab,"failed to register to mhi bus, err = %d\n" , ret); +mhi_free_controller (mhi_ctrl); +return ret; + } + +return 0 ; +} + +void ath12k_mhi_unregister (struct ath12k_pci *ab_pci) +{ +struct mhi_controller *mhi_ctrl = ab_pci->mhi_ctrl; + +mhi_unregister_controller (mhi_ctrl); +kfree (mhi_ctrl->irq); +mhi_free_controller (mhi_ctrl); + ab_pci->mhi_ctrl =NULL ; +} + +static char *ath12k_mhi_state_to_str (enum ath12k_mhi_state mhi_state) +{ +switch (mhi_state) { +case ATH12K_MHI_INIT : +return "INIT" ; +case ATH12K_MHI_DEINIT : +return "DEINIT" ; +case ATH12K_MHI_POWER_ON : +return "POWER_ON" ; +case ATH12K_MHI_POWER_OFF : +return "POWER_OFF" ; +case ATH12K_MHI_FORCE_POWER_OFF : +return "FORCE_POWER_OFF" ; +case ATH12K_MHI_SUSPEND : +return "SUSPEND" ; +case ATH12K_MHI_RESUME : +return "RESUME" ; +case ATH12K_MHI_TRIGGER_RDDM : +return "TRIGGER_RDDM" ; +case ATH12K_MHI_RDDM_DONE : +return "RDDM_DONE" ; +default : +return "UNKNOWN" ; + } +}; + +static void ath12k_mhi_set_state_bit (struct ath12k_pci *ab_pci, +enum ath12k_mhi_state mhi_state) +{ +struct ath12k_base *ab = ab_pci->ab; + +switch (mhi_state) { +case ATH12K_MHI_INIT : +set_bit (ATH12K_MHI_INIT , &ab_pci->mhi_state); +break ; +case ATH12K_MHI_DEINIT : +clear_bit (ATH12K_MHI_INIT , &ab_pci->mhi_state); +break ; +case ATH12K_MHI_POWER_ON : +set_bit (ATH12K_MHI_POWER_ON , &ab_pci->mhi_state); +break ; +case ATH12K_MHI_POWER_OFF : +case ATH12K_MHI_FORCE_POWER_OFF : +clear_bit (ATH12K_MHI_POWER_ON , &ab_pci->mhi_state); +clear_bit (ATH12K_MHI_TRIGGER_RDDM , &ab_pci->mhi_state); +clear_bit (ATH12K_MHI_RDDM_DONE , &ab_pci->mhi_state); +break ; +case ATH12K_MHI_SUSPEND : +set_bit (ATH12K_MHI_SUSPEND , &ab_pci->mhi_state); +break ; +case ATH12K_MHI_RESUME : +clear_bit (ATH12K_MHI_SUSPEND , &ab_pci->mhi_state); +break ; +case ATH12K_MHI_TRIGGER_RDDM : +set_bit (ATH12K_MHI_TRIGGER_RDDM , &ab_pci->mhi_state); +break ; +case ATH12K_MHI_RDDM_DONE : +set_bit (ATH12K_MHI_RDDM_DONE , &ab_pci->mhi_state); +break ; +default : +ath12k_err (ab,"unhandled mhi state (%d)\n" , mhi_state); + } +} + +static int ath12k_mhi_check_state_bit (struct ath12k_pci *ab_pci, +enum ath12k_mhi_state mhi_state) +{ +struct ath12k_base *ab = ab_pci->ab; + +switch (mhi_state) { +case ATH12K_MHI_INIT : +if (!test_bit (ATH12K_MHI_INIT , &ab_pci->mhi_state)) +return 0 ; +break ; +case ATH12K_MHI_DEINIT : +case ATH12K_MHI_POWER_ON : +if (test_bit (ATH12K_MHI_INIT , &ab_pci->mhi_state) && + !test_bit (ATH12K_MHI_POWER_ON , &ab_pci->mhi_state)) +return 0 ; +break ; +case ATH12K_MHI_FORCE_POWER_OFF : +if (test_bit (ATH12K_MHI_POWER_ON , &ab_pci->mhi_state)) +return 0 ; +break ; +case ATH12K_MHI_POWER_OFF : +case ATH12K_MHI_SUSPEND : +if (test_bit (ATH12K_MHI_POWER_ON , &ab_pci->mhi_state) && + !test_bit (ATH12K_MHI_SUSPEND , &ab_pci->mhi_state)) +return 0 ; +break ; +case ATH12K_MHI_RESUME : +if (test_bit (ATH12K_MHI_SUSPEND , &ab_pci->mhi_state)) +return 0 ; +break ; +case ATH12K_MHI_TRIGGER_RDDM : +if (test_bit (ATH12K_MHI_POWER_ON , &ab_pci->mhi_state) && + !test_bit (ATH12K_MHI_TRIGGER_RDDM , &ab_pci->mhi_state)) +return 0 ; +break ; +case ATH12K_MHI_RDDM_DONE : +return 0 ; +default : +ath12k_err (ab,"unhandled mhi state: %s(%d)\n" , +ath12k_mhi_state_to_str (mhi_state), mhi_state); + } + +ath12k_err (ab,"failed to set mhi state %s(%d) in current mhi state (0x%lx)\n" , +ath12k_mhi_state_to_str (mhi_state), mhi_state, + ab_pci->mhi_state); + +return -EINVAL ; +} + +static int ath12k_mhi_set_state (struct ath12k_pci *ab_pci, +enum ath12k_mhi_state mhi_state) +{ +struct ath12k_base *ab = ab_pci->ab; +int ret; + + ret =ath12k_mhi_check_state_bit (ab_pci, mhi_state); +if (ret) + goto out; + +ath12k_dbg (ab,ATH12K_DBG_PCI ,"setting mhi state: %s(%d)\n" , +ath12k_mhi_state_to_str (mhi_state), mhi_state); + +switch (mhi_state) { +case ATH12K_MHI_INIT : + ret =mhi_prepare_for_power_up (ab_pci->mhi_ctrl); +break ; +case ATH12K_MHI_DEINIT : +mhi_unprepare_after_power_down (ab_pci->mhi_ctrl); + ret =0 ; +break ; +case ATH12K_MHI_POWER_ON : + ret =mhi_async_power_up (ab_pci->mhi_ctrl); +break ; +case ATH12K_MHI_POWER_OFF : +mhi_power_down (ab_pci->mhi_ctrl, true); + ret =0 ; +break ; +case ATH12K_MHI_FORCE_POWER_OFF : +mhi_power_down (ab_pci->mhi_ctrl, false); + ret =0 ; +break ; +case ATH12K_MHI_SUSPEND : + ret =mhi_pm_suspend (ab_pci->mhi_ctrl); +break ; +case ATH12K_MHI_RESUME : + ret =mhi_pm_resume (ab_pci->mhi_ctrl); +break ; +case ATH12K_MHI_TRIGGER_RDDM : + ret =mhi_force_rddm_mode (ab_pci->mhi_ctrl); +break ; +case ATH12K_MHI_RDDM_DONE : +break ; +default : +ath12k_err (ab,"unhandled MHI state (%d)\n" , mhi_state); + ret = -EINVAL ; + } + +if (ret) + goto out; + +ath12k_mhi_set_state_bit (ab_pci, mhi_state); + +return 0 ; + +out: +ath12k_err (ab,"failed to set mhi state: %s(%d)\n" , +ath12k_mhi_state_to_str (mhi_state), mhi_state); +return ret; +} + +int ath12k_mhi_start (struct ath12k_pci *ab_pci) +{ +int ret; + + ab_pci->mhi_ctrl->timeout_ms =MHI_TIMEOUT_DEFAULT_MS ; + + ret =ath12k_mhi_set_state (ab_pci,ATH12K_MHI_INIT ); +if (ret) + goto out; + + ret =ath12k_mhi_set_state (ab_pci,ATH12K_MHI_POWER_ON ); +if (ret) + goto out; + +return 0 ; + +out: +return ret; +} + +void ath12k_mhi_stop (struct ath12k_pci *ab_pci) +{ +ath12k_mhi_set_state (ab_pci,ATH12K_MHI_POWER_OFF ); +ath12k_mhi_set_state (ab_pci,ATH12K_MHI_DEINIT ); +} + +void ath12k_mhi_suspend (struct ath12k_pci *ab_pci) +{ +ath12k_mhi_set_state (ab_pci,ATH12K_MHI_SUSPEND ); +} + +void ath12k_mhi_resume (struct ath12k_pci *ab_pci) +{ +ath12k_mhi_set_state (ab_pci,ATH12K_MHI_RESUME ); +}
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 35/50 wifi: ath12k: add pci.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/pci.c | 1374 +++++++++++++++++++++++++++++++++ 1 file changed, 1374 insertions(+)
drivers/net/wireless/ath/ath12k/pci.c new file +1374 -0
@@ -0,0 +1,1374 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2019-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include <linux/module.h> +#include <linux/msi.h> +#include <linux/pci.h> + +#include "pci.h" +#include "core.h" +#include "hif.h" +#include "mhi.h" +#include "debug.h" + +#define ATH12K_PCI_BAR_NUM 0 +#define ATH12K_PCI_DMA_MASK 32 + +#define ATH12K_PCI_IRQ_CE0_OFFSET 3 + +#define WINDOW_ENABLE_BIT 0x40000000 +#define WINDOW_REG_ADDRESS 0x310c +#define WINDOW_VALUE_MASK GENMASK(24, 19) +#define WINDOW_START 0x80000 +#define WINDOW_RANGE_MASK GENMASK(18, 0) +#define WINDOW_STATIC_MASK GENMASK(31, 6) + +#define TCSR_SOC_HW_VERSION 0x1B00000 +#define TCSR_SOC_HW_VERSION_MAJOR_MASK GENMASK(11, 8) +#define TCSR_SOC_HW_VERSION_MINOR_MASK GENMASK(7, 4) + +/* BAR0 + 4k is always accessible, and no +* need to force wakeup. +* 4K - 32 = 0xFE0 +*/ +#define ACCESS_ALWAYS_OFF 0xFE0 + +#define QCN9274_DEVICE_ID 0x1109 +#define WCN7850_DEVICE_ID 0x1107 + +static const struct pci_device_id ath12k_pci_id_table[] = { + {PCI_VDEVICE (QCOM ,QCN9274_DEVICE_ID ) }, + {PCI_VDEVICE (QCOM ,WCN7850_DEVICE_ID ) }, + {0 } +}; + +MODULE_DEVICE_TABLE (pci, ath12k_pci_id_table); + +/* TODO: revisit IRQ mapping for new SRNG's */ +static const struct ath12k_msi_config ath12k_msi_config[] = { + { + .total_vectors =16 , + .total_users =3 , + .users = (struct ath12k_msi_user []) { + { .name ="MHI" , .num_vectors =3 , .base_vector =0 }, + { .name ="CE" , .num_vectors =5 , .base_vector =3 }, + { .name ="DP" , .num_vectors =8 , .base_vector =8 }, + }, + }, +}; + +static const char *irq_name[ATH12K_IRQ_NUM_MAX ] = { +"bhi" , +"mhi-er0" , +"mhi-er1" , +"ce0" , +"ce1" , +"ce2" , +"ce3" , +"ce4" , +"ce5" , +"ce6" , +"ce7" , +"ce8" , +"ce9" , +"ce10" , +"ce11" , +"ce12" , +"ce13" , +"ce14" , +"ce15" , +"host2wbm-desc-feed" , +"host2reo-re-injection" , +"host2reo-command" , +"host2rxdma-monitor-ring3" , +"host2rxdma-monitor-ring2" , +"host2rxdma-monitor-ring1" , +"reo2ost-exception" , +"wbm2host-rx-release" , +"reo2host-status" , +"reo2host-destination-ring4" , +"reo2host-destination-ring3" , +"reo2host-destination-ring2" , +"reo2host-destination-ring1" , +"rxdma2host-monitor-destination-mac3" , +"rxdma2host-monitor-destination-mac2" , +"rxdma2host-monitor-destination-mac1" , +"ppdu-end-interrupts-mac3" , +"ppdu-end-interrupts-mac2" , +"ppdu-end-interrupts-mac1" , +"rxdma2host-monitor-status-ring-mac3" , +"rxdma2host-monitor-status-ring-mac2" , +"rxdma2host-monitor-status-ring-mac1" , +"host2rxdma-host-buf-ring-mac3" , +"host2rxdma-host-buf-ring-mac2" , +"host2rxdma-host-buf-ring-mac1" , +"rxdma2host-destination-ring-mac3" , +"rxdma2host-destination-ring-mac2" , +"rxdma2host-destination-ring-mac1" , +"host2tcl-input-ring4" , +"host2tcl-input-ring3" , +"host2tcl-input-ring2" , +"host2tcl-input-ring1" , +"wbm2host-tx-completions-ring4" , +"wbm2host-tx-completions-ring3" , +"wbm2host-tx-completions-ring2" , +"wbm2host-tx-completions-ring1" , +"tcl2host-status-ring" , +}; + +static void ath12k_pci_select_window (struct ath12k_pci *ab_pci,u32 offset) +{ +struct ath12k_base *ab = ab_pci->ab; + +u32 window =u32_get_bits (offset,WINDOW_VALUE_MASK ); +u32 static_window; + +lockdep_assert_held (&ab_pci->window_lock); + +/* Preserve the static window configuration and reset only dynamic window */ + static_window = ab_pci->register_window &WINDOW_STATIC_MASK ; + window |= static_window; + +if (window != ab_pci->register_window) { +iowrite32 (WINDOW_ENABLE_BIT | window, + ab->mem +WINDOW_REG_ADDRESS ); +ioread32 (ab->mem +WINDOW_REG_ADDRESS ); + ab_pci->register_window = window; + } +} + +static void ath12k_pci_select_static_window (struct ath12k_pci *ab_pci) +{ +u32 umac_window =u32_get_bits (HAL_SEQ_WCSS_UMAC_OFFSET ,WINDOW_VALUE_MASK ); +u32 ce_window =u32_get_bits (HAL_CE_WFSS_CE_REG_BASE ,WINDOW_VALUE_MASK ); +u32 window; + + window = (umac_window <<12 ) | (ce_window <<6 ); + +spin_lock_bh (&ab_pci->window_lock); + ab_pci->register_window = window; +spin_unlock_bh (&ab_pci->window_lock); + +iowrite32 (WINDOW_ENABLE_BIT | window, ab_pci->ab->mem +WINDOW_REG_ADDRESS ); +} + +static u32 ath12k_pci_get_window_start (struct ath12k_base *ab, +u32 offset) +{ +u32 window_start; + +/* If offset lies within DP register range, use 3rd window */ +if ((offset ^HAL_SEQ_WCSS_UMAC_OFFSET ) <WINDOW_RANGE_MASK ) + window_start =3 *WINDOW_START ; +/* If offset lies within CE register range, use 2nd window */ +else if ((offset ^HAL_CE_WFSS_CE_REG_BASE ) <WINDOW_RANGE_MASK ) + window_start =2 *WINDOW_START ; +/* If offset lies within PCI_BAR_WINDOW0_BASE and within PCI_SOC_PCI_REG_BASE +* use 0th window +*/ +else if (((offset ^PCI_BAR_WINDOW0_BASE ) <WINDOW_RANGE_MASK ) && + !((offset ^PCI_SOC_PCI_REG_BASE ) <PCI_SOC_RANGE_MASK )) + window_start =0 ; +else + window_start =WINDOW_START ; + +return window_start; +} + +static void ath12k_pci_soc_global_reset (struct ath12k_base *ab) +{ +u32 val, delay; + + val =ath12k_pci_read32 (ab,PCIE_SOC_GLOBAL_RESET ); + + val |=PCIE_SOC_GLOBAL_RESET_V ; + +ath12k_pci_write32 (ab,PCIE_SOC_GLOBAL_RESET , val); + +/* TODO: exact time to sleep is uncertain */ + delay =10 ; +mdelay (delay); + +/* Need to toggle V bit back otherwise stuck in reset status */ + val &= ~PCIE_SOC_GLOBAL_RESET_V ; + +ath12k_pci_write32 (ab,PCIE_SOC_GLOBAL_RESET , val); + +mdelay (delay); + + val =ath12k_pci_read32 (ab,PCIE_SOC_GLOBAL_RESET ); +if (val ==0xffffffff ) +ath12k_warn (ab,"link down error during global reset\n" ); +} + +static void ath12k_pci_clear_dbg_registers (struct ath12k_base *ab) +{ +u32 val; + +/* read cookie */ + val =ath12k_pci_read32 (ab,PCIE_Q6_COOKIE_ADDR ); +ath12k_dbg (ab,ATH12K_DBG_PCI ,"cookie:0x%x\n" , val); + + val =ath12k_pci_read32 (ab,WLAON_WARM_SW_ENTRY ); +ath12k_dbg (ab,ATH12K_DBG_PCI ,"WLAON_WARM_SW_ENTRY 0x%x\n" , val); + +/* TODO: exact time to sleep is uncertain */ +mdelay (10 ); + +/* write 0 to WLAON_WARM_SW_ENTRY to prevent Q6 from +* continuing warm path and entering dead loop. +*/ +ath12k_pci_write32 (ab,WLAON_WARM_SW_ENTRY ,0 ); +mdelay (10 ); + + val =ath12k_pci_read32 (ab,WLAON_WARM_SW_ENTRY ); +ath12k_dbg (ab,ATH12K_DBG_PCI ,"WLAON_WARM_SW_ENTRY 0x%x\n" , val); + +/* A read clear register. clear the register to prevent +* Q6 from entering wrong code path. +*/ + val =ath12k_pci_read32 (ab,WLAON_SOC_RESET_CAUSE_REG ); +ath12k_dbg (ab,ATH12K_DBG_PCI ,"soc reset cause:%d\n" , val); +} + +static void ath12k_pci_enable_ltssm (struct ath12k_base *ab) +{ +u32 val; +int i; + + val =ath12k_pci_read32 (ab,PCIE_PCIE_PARF_LTSSM ); + +/* PCIE link seems very unstable after the Hot Reset*/ +for (i =0 ; val !=PARM_LTSSM_VALUE && i <5 ; i++) { +if (val ==0xffffffff ) +mdelay (5 ); + +ath12k_pci_write32 (ab,PCIE_PCIE_PARF_LTSSM ,PARM_LTSSM_VALUE ); + val =ath12k_pci_read32 (ab,PCIE_PCIE_PARF_LTSSM ); + } + +ath12k_dbg (ab,ATH12K_DBG_PCI ,"pci ltssm 0x%x\n" , val); + + val =ath12k_pci_read32 (ab,GCC_GCC_PCIE_HOT_RST ); + val |=GCC_GCC_PCIE_HOT_RST_VAL ; +ath12k_pci_write32 (ab,GCC_GCC_PCIE_HOT_RST , val); + val =ath12k_pci_read32 (ab,GCC_GCC_PCIE_HOT_RST ); + +ath12k_dbg (ab,ATH12K_DBG_PCI ,"pci pcie_hot_rst 0x%x\n" , val); + +mdelay (5 ); +} + +static void ath12k_pci_clear_all_intrs (struct ath12k_base *ab) +{ +/* This is a WAR for PCIE Hotreset. +* When target receive Hotreset, but will set the interrupt. +* So when download SBL again, SBL will open Interrupt and +* receive it, and crash immediately. +*/ +ath12k_pci_write32 (ab,PCIE_PCIE_INT_ALL_CLEAR ,PCIE_INT_CLEAR_ALL ); +} + +static void ath12k_pci_set_wlaon_pwr_ctrl (struct ath12k_base *ab) +{ +u32 val; + + val =ath12k_pci_read32 (ab,WLAON_QFPROM_PWR_CTRL_REG ); + val &= ~QFPROM_PWR_CTRL_VDD4BLOW_MASK ; +ath12k_pci_write32 (ab,WLAON_QFPROM_PWR_CTRL_REG , val); +} + +static void ath12k_pci_force_wake (struct ath12k_base *ab) +{ +ath12k_pci_write32 (ab,PCIE_SOC_WAKE_PCIE_LOCAL_REG ,1 ); +mdelay (5 ); +} + +static void ath12k_pci_sw_reset (struct ath12k_base *ab,bool power_on) +{ +if (power_on) { +ath12k_pci_enable_ltssm (ab); +ath12k_pci_clear_all_intrs (ab); +ath12k_pci_set_wlaon_pwr_ctrl (ab); + } + +ath12k_mhi_clear_vector (ab); +ath12k_pci_clear_dbg_registers (ab); +ath12k_pci_soc_global_reset (ab); +ath12k_mhi_set_mhictrl_reset (ab); +} + +static void ath12k_pci_free_ext_irq (struct ath12k_base *ab) +{ +int i, j; + +for (i =0 ; i <ATH12K_EXT_IRQ_GRP_NUM_MAX ; i++) { +struct ath12k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i]; + +for (j =0 ; j < irq_grp->num_irq; j++) +free_irq (ab->irq_num[irq_grp->irqs[j]], irq_grp); + +netif_napi_del (&irq_grp->napi); + } +} + +static void ath12k_pci_free_irq (struct ath12k_base *ab) +{ +int i, irq_idx; + +for (i =0 ; i < ab->hw_params->ce_count; i++) { +if (ath12k_ce_get_attr_flags (ab, i) &CE_ATTR_DIS_INTR ) +continue ; + irq_idx =ATH12K_PCI_IRQ_CE0_OFFSET + i; +free_irq (ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]); + } + +ath12k_pci_free_ext_irq (ab); +} + +static void ath12k_pci_ce_irq_enable (struct ath12k_base *ab,u16 ce_id) +{ +u32 irq_idx; + + irq_idx =ATH12K_PCI_IRQ_CE0_OFFSET + ce_id; +enable_irq (ab->irq_num[irq_idx]); +} + +static void ath12k_pci_ce_irq_disable (struct ath12k_base *ab,u16 ce_id) +{ +u32 irq_idx; + + irq_idx =ATH12K_PCI_IRQ_CE0_OFFSET + ce_id; +disable_irq_nosync (ab->irq_num[irq_idx]); +} + +static void ath12k_pci_ce_irqs_disable (struct ath12k_base *ab) +{ +int i; + +for (i =0 ; i < ab->hw_params->ce_count; i++) { +if (ath12k_ce_get_attr_flags (ab, i) &CE_ATTR_DIS_INTR ) +continue ; +ath12k_pci_ce_irq_disable (ab, i); + } +} + +static void ath12k_pci_sync_ce_irqs (struct ath12k_base *ab) +{ +int i; +int irq_idx; + +for (i =0 ; i < ab->hw_params->ce_count; i++) { +if (ath12k_ce_get_attr_flags (ab, i) &CE_ATTR_DIS_INTR ) +continue ; + + irq_idx =ATH12K_PCI_IRQ_CE0_OFFSET + i; +synchronize_irq (ab->irq_num[irq_idx]); + } +} + +static void ath12k_pci_ce_tasklet (struct tasklet_struct *t) +{ +struct ath12k_ce_pipe *ce_pipe =from_tasklet (ce_pipe, t, intr_tq); + +ath12k_ce_per_engine_service (ce_pipe->ab, ce_pipe->pipe_num); + +ath12k_pci_ce_irq_enable (ce_pipe->ab, ce_pipe->pipe_num); +} + +static irqreturn_t ath12k_pci_ce_interrupt_handler (int irq,void *arg) +{ +struct ath12k_ce_pipe *ce_pipe = arg; + +/* last interrupt received for this CE */ + ce_pipe->timestamp = jiffies; + +ath12k_pci_ce_irq_disable (ce_pipe->ab, ce_pipe->pipe_num); +tasklet_schedule (&ce_pipe->intr_tq); + +return IRQ_HANDLED ; +} + +static void ath12k_pci_ext_grp_disable (struct ath12k_ext_irq_grp *irq_grp) +{ +int i; + +for (i =0 ; i < irq_grp->num_irq; i++) +disable_irq_nosync (irq_grp->ab->irq_num[irq_grp->irqs[i]]); +} + +static void __ath12k_pci_ext_irq_disable (struct ath12k_base *sc) +{ +int i; + +for (i =0 ; i <ATH12K_EXT_IRQ_GRP_NUM_MAX ; i++) { +struct ath12k_ext_irq_grp *irq_grp = &sc->ext_irq_grp[i]; + +ath12k_pci_ext_grp_disable (irq_grp); + +napi_synchronize (&irq_grp->napi); +napi_disable (&irq_grp->napi); + } +} + +static void ath12k_pci_ext_grp_enable (struct ath12k_ext_irq_grp *irq_grp) +{ +int i; + +for (i =0 ; i < irq_grp->num_irq; i++) +enable_irq (irq_grp->ab->irq_num[irq_grp->irqs[i]]); +} + +static void ath12k_pci_sync_ext_irqs (struct ath12k_base *ab) +{ +int i, j, irq_idx; + +for (i =0 ; i <ATH12K_EXT_IRQ_GRP_NUM_MAX ; i++) { +struct ath12k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i]; + +for (j =0 ; j < irq_grp->num_irq; j++) { + irq_idx = irq_grp->irqs[j]; +synchronize_irq (ab->irq_num[irq_idx]); + } + } +} + +static int ath12k_pci_ext_grp_napi_poll (struct napi_struct *napi,int budget) +{ +struct ath12k_ext_irq_grp *irq_grp =container_of (napi, + struct ath12k_ext_irq_grp, + napi); +struct ath12k_base *ab = irq_grp->ab; +int work_done; + + work_done =ath12k_dp_service_srng (ab, irq_grp, budget); +if (work_done < budget) { +napi_complete_done (napi, work_done); +ath12k_pci_ext_grp_enable (irq_grp); + } + +if (work_done > budget) + work_done = budget; + +return work_done; +} + +static irqreturn_t ath12k_pci_ext_interrupt_handler (int irq,void *arg) +{ +struct ath12k_ext_irq_grp *irq_grp = arg; + +ath12k_dbg (irq_grp->ab,ATH12K_DBG_PCI ,"ext irq:%d\n" , irq); + +/* last interrupt received for this group */ + irq_grp->timestamp = jiffies; + +ath12k_pci_ext_grp_disable (irq_grp); + +napi_schedule (&irq_grp->napi); + +return IRQ_HANDLED ; +} + +static int ath12k_pci_ext_irq_config (struct ath12k_base *ab) +{ +int i, j, ret, num_vectors =0 ; +u32 user_base_data =0 , base_vector =0 , base_idx; + + base_idx =ATH12K_PCI_IRQ_CE0_OFFSET +CE_COUNT_MAX ; + ret =ath12k_pci_get_user_msi_assignment (ab,"DP" , + &num_vectors, + &user_base_data, + &base_vector); +if (ret <0 ) +return ret; + +for (i =0 ; i <ATH12K_EXT_IRQ_GRP_NUM_MAX ; i++) { +struct ath12k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i]; +u32 num_irq =0 ; + + irq_grp->ab = ab; + irq_grp->grp_id = i; +init_dummy_netdev (&irq_grp->napi_ndev); +netif_napi_add (&irq_grp->napi_ndev, &irq_grp->napi, + ath12k_pci_ext_grp_napi_poll); + +if (ab->hw_params->ring_mask->tx[i] || + ab->hw_params->ring_mask->rx[i] || + ab->hw_params->ring_mask->rx_err[i] || + ab->hw_params->ring_mask->rx_wbm_rel[i] || + ab->hw_params->ring_mask->reo_status[i] || + ab->hw_params->ring_mask->host2rxdma[i] || + ab->hw_params->ring_mask->rx_mon_dest[i]) { + num_irq =1 ; + } + + irq_grp->num_irq = num_irq; + irq_grp->irqs[0 ] = base_idx + i; + +for (j =0 ; j < irq_grp->num_irq; j++) { +int irq_idx = irq_grp->irqs[j]; +int vector = (i % num_vectors) + base_vector; +int irq =ath12k_pci_get_msi_irq (ab->dev, vector); + + ab->irq_num[irq_idx] = irq; + +ath12k_dbg (ab,ATH12K_DBG_PCI , +"irq:%d group:%d\n" , irq, i); + +irq_set_status_flags (irq,IRQ_DISABLE_UNLAZY ); + ret =request_irq (irq, ath12k_pci_ext_interrupt_handler, +IRQF_SHARED , +"DP_EXT_IRQ" , irq_grp); +if (ret) { +ath12k_err (ab,"failed request irq %d: %d\n" , + vector, ret); +return ret; + } + +disable_irq_nosync (ab->irq_num[irq_idx]); + } + } + +return 0 ; +} + +static int ath12k_pci_config_irq (struct ath12k_base *ab) +{ +struct ath12k_ce_pipe *ce_pipe; +u32 msi_data_start; +u32 msi_data_count, msi_data_idx; +u32 msi_irq_start; +unsigned int msi_data; +int irq, i, ret, irq_idx; + + ret =ath12k_pci_get_user_msi_assignment (ab, +"CE" , &msi_data_count, + &msi_data_start, &msi_irq_start); +if (ret) +return ret; + +/* Configure CE irqs */ + +for (i =0 , msi_data_idx =0 ; i < ab->hw_params->ce_count; i++) { +if (ath12k_ce_get_attr_flags (ab, i) &CE_ATTR_DIS_INTR ) +continue ; + + msi_data = (msi_data_idx % msi_data_count) + msi_irq_start; + irq =ath12k_pci_get_msi_irq (ab->dev, msi_data); + ce_pipe = &ab->ce.ce_pipe[i]; + + irq_idx =ATH12K_PCI_IRQ_CE0_OFFSET + i; + +tasklet_setup (&ce_pipe->intr_tq, ath12k_pci_ce_tasklet); + + ret =request_irq (irq, ath12k_pci_ce_interrupt_handler, +IRQF_SHARED , irq_name[irq_idx], + ce_pipe); +if (ret) { +ath12k_err (ab,"failed to request irq %d: %d\n" , + irq_idx, ret); +return ret; + } + + ab->irq_num[irq_idx] = irq; + msi_data_idx++; + +ath12k_pci_ce_irq_disable (ab, i); + } + + ret =ath12k_pci_ext_irq_config (ab); +if (ret) +return ret; + +return 0 ; +} + +static void ath12k_pci_init_qmi_ce_config (struct ath12k_base *ab) +{ +struct ath12k_qmi_ce_cfg *cfg = &ab->qmi.ce_cfg; + + cfg->tgt_ce = ab->hw_params->target_ce_config; + cfg->tgt_ce_len = ab->hw_params->target_ce_count; + + cfg->svc_to_ce_map = ab->hw_params->svc_to_ce_map; + cfg->svc_to_ce_map_len = ab->hw_params->svc_to_ce_map_len; + ab->qmi.service_ins_id = ab->hw_params->qmi_service_ins_id; +} + +static void ath12k_pci_ce_irqs_enable (struct ath12k_base *ab) +{ +int i; + +for (i =0 ; i < ab->hw_params->ce_count; i++) { +if (ath12k_ce_get_attr_flags (ab, i) &CE_ATTR_DIS_INTR ) +continue ; +ath12k_pci_ce_irq_enable (ab, i); + } +} + +static void ath12k_pci_msi_config (struct ath12k_pci *ab_pci,bool enable) +{ +struct pci_dev *dev = ab_pci->pdev; +u16 control; + +pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &control); + +if (enable) + control |=PCI_MSI_FLAGS_ENABLE ; +else + control &= ~PCI_MSI_FLAGS_ENABLE ; + +pci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , control); +} + +static void ath12k_pci_msi_enable (struct ath12k_pci *ab_pci) +{ +ath12k_pci_msi_config (ab_pci, true); +} + +static void ath12k_pci_msi_disable (struct ath12k_pci *ab_pci) +{ +ath12k_pci_msi_config (ab_pci, false); +} + +static int ath12k_pci_msi_alloc (struct ath12k_pci *ab_pci) +{ +struct ath12k_base *ab = ab_pci->ab; +const struct ath12k_msi_config *msi_config = ab_pci->msi_config; +struct msi_desc *msi_desc; +int num_vectors; +int ret; + + num_vectors =pci_alloc_irq_vectors (ab_pci->pdev, + msi_config->total_vectors, + msi_config->total_vectors, +PCI_IRQ_MSI ); +if (num_vectors != msi_config->total_vectors) { +ath12k_err (ab,"failed to get %d MSI vectors, only %d available" , + msi_config->total_vectors, num_vectors); + +if (num_vectors >=0 ) +return -EINVAL ; +else +return num_vectors; + } + +ath12k_pci_msi_disable (ab_pci); + + msi_desc =irq_get_msi_desc (ab_pci->pdev->irq); +if (!msi_desc) { +ath12k_err (ab,"msi_desc is NULL!\n" ); + ret = -EINVAL ; + goto free_msi_vector; + } + + ab_pci->msi_ep_base_data = msi_desc->msg.data; +if (msi_desc->pci.msi_attrib.is_64) +set_bit (ATH12K_PCI_FLAG_IS_MSI_64 , &ab_pci->flags); + +ath12k_dbg (ab,ATH12K_DBG_PCI ,"msi base data is %d\n" , ab_pci->msi_ep_base_data); + +return 0 ; + +free_msi_vector: +pci_free_irq_vectors (ab_pci->pdev); + +return ret; +} + +static void ath12k_pci_msi_free (struct ath12k_pci *ab_pci) +{ +pci_free_irq_vectors (ab_pci->pdev); +} + +static int ath12k_pci_claim (struct ath12k_pci *ab_pci,struct pci_dev *pdev) +{ +struct ath12k_base *ab = ab_pci->ab; +u16 device_id; +int ret =0 ; + +pci_read_config_word (pdev,PCI_DEVICE_ID , &device_id); +if (device_id != ab_pci->dev_id) { +ath12k_err (ab,"pci device id mismatch: 0x%x 0x%x\n" , + device_id, ab_pci->dev_id); + ret = -EIO ; + goto out; + } + + ret =pci_assign_resource (pdev,ATH12K_PCI_BAR_NUM ); +if (ret) { +ath12k_err (ab,"failed to assign pci resource: %d\n" , ret); + goto out; + } + + ret =pci_enable_device (pdev); +if (ret) { +ath12k_err (ab,"failed to enable pci device: %d\n" , ret); + goto out; + } + + ret =pci_request_region (pdev,ATH12K_PCI_BAR_NUM ,"ath12k_pci" ); +if (ret) { +ath12k_err (ab,"failed to request pci region: %d\n" , ret); + goto disable_device; + } + + ret =dma_set_mask_and_coherent (&pdev->dev, +DMA_BIT_MASK (ATH12K_PCI_DMA_MASK )); +if (ret) { +ath12k_err (ab,"failed to set pci dma mask to %d: %d\n" , +ATH12K_PCI_DMA_MASK , ret); + goto release_region; + } + +pci_set_master (pdev); + + ab->mem_len =pci_resource_len (pdev,ATH12K_PCI_BAR_NUM ); + ab->mem =pci_iomap (pdev,ATH12K_PCI_BAR_NUM ,0 ); +if (!ab->mem) { +ath12k_err (ab,"failed to map pci bar %d\n" ,ATH12K_PCI_BAR_NUM ); + ret = -EIO ; + goto clear_master; + } + +ath12k_dbg (ab,ATH12K_DBG_BOOT ,"boot pci_mem 0x%pK\n" , ab->mem); +return 0 ; + +clear_master: +pci_clear_master (pdev); +release_region: +pci_release_region (pdev,ATH12K_PCI_BAR_NUM ); +disable_device: +pci_disable_device (pdev); +out: +return ret; +} + +static void ath12k_pci_free_region (struct ath12k_pci *ab_pci) +{ +struct ath12k_base *ab = ab_pci->ab; +struct pci_dev *pci_dev = ab_pci->pdev; + +pci_iounmap (pci_dev, ab->mem); + ab->mem =NULL ; +pci_clear_master (pci_dev); +pci_release_region (pci_dev,ATH12K_PCI_BAR_NUM ); +if (pci_is_enabled (pci_dev)) +pci_disable_device (pci_dev); +} + +static void ath12k_pci_aspm_disable (struct ath12k_pci *ab_pci) +{ +struct ath12k_base *ab = ab_pci->ab; + +pcie_capability_read_word (ab_pci->pdev,PCI_EXP_LNKCTL , + &ab_pci->link_ctl); + +ath12k_dbg (ab,ATH12K_DBG_PCI ,"pci link_ctl 0x%04x L0s %d L1 %d\n" , + ab_pci->link_ctl, +u16_get_bits (ab_pci->link_ctl,PCI_EXP_LNKCTL_ASPM_L0S ), +u16_get_bits (ab_pci->link_ctl,PCI_EXP_LNKCTL_ASPM_L1 )); + +/* disable L0s and L1 */ +pcie_capability_write_word (ab_pci->pdev,PCI_EXP_LNKCTL , + ab_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC ); + +set_bit (ATH12K_PCI_ASPM_RESTORE , &ab_pci->flags); +} + +static void ath12k_pci_aspm_restore (struct ath12k_pci *ab_pci) +{ +if (test_and_clear_bit (ATH12K_PCI_ASPM_RESTORE , &ab_pci->flags)) +pcie_capability_write_word (ab_pci->pdev,PCI_EXP_LNKCTL , + ab_pci->link_ctl); +} + +static void ath12k_pci_kill_tasklets (struct ath12k_base *ab) +{ +int i; + +for (i =0 ; i < ab->hw_params->ce_count; i++) { +struct ath12k_ce_pipe *ce_pipe = &ab->ce.ce_pipe[i]; + +if (ath12k_ce_get_attr_flags (ab, i) &CE_ATTR_DIS_INTR ) +continue ; + +tasklet_kill (&ce_pipe->intr_tq); + } +} + +static void ath12k_pci_ce_irq_disable_sync (struct ath12k_base *ab) +{ +ath12k_pci_ce_irqs_disable (ab); +ath12k_pci_sync_ce_irqs (ab); +ath12k_pci_kill_tasklets (ab); +} + +int ath12k_pci_map_service_to_pipe (struct ath12k_base *ab,u16 service_id, +u8 *ul_pipe,u8 *dl_pipe) +{ +const struct service_to_pipe *entry; +bool ul_set = false, dl_set = false; +int i; + +for (i =0 ; i < ab->hw_params->svc_to_ce_map_len; i++) { + entry = &ab->hw_params->svc_to_ce_map[i]; + +if (__le32_to_cpu (entry->service_id) != service_id) +continue ; + +switch (__le32_to_cpu (entry->pipedir)) { +case PIPEDIR_NONE : +break ; +case PIPEDIR_IN : +WARN_ON (dl_set); + *dl_pipe =__le32_to_cpu (entry->pipenum); + dl_set = true; +break ; +case PIPEDIR_OUT : +WARN_ON (ul_set); + *ul_pipe =__le32_to_cpu (entry->pipenum); + ul_set = true; +break ; +case PIPEDIR_INOUT : +WARN_ON (dl_set); +WARN_ON (ul_set); + *dl_pipe =__le32_to_cpu (entry->pipenum); + *ul_pipe =__le32_to_cpu (entry->pipenum); + dl_set = true; + ul_set = true; +break ; + } + } + +if (WARN_ON (!ul_set || !dl_set)) +return -ENOENT ; + +return 0 ; +} + +int ath12k_pci_get_msi_irq (struct device *dev,unsigned int vector) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); + +return pci_irq_vector (pci_dev, vector); +} + +int ath12k_pci_get_user_msi_assignment (struct ath12k_base *ab,char *user_name, +int *num_vectors,u32 *user_base_data, +u32 *base_vector) +{ +struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); +const struct ath12k_msi_config *msi_config = ab_pci->msi_config; +int idx; + +for (idx =0 ; idx < msi_config->total_users; idx++) { +if (strcmp (user_name, msi_config->users[idx].name) ==0 ) { + *num_vectors = msi_config->users[idx].num_vectors; + *user_base_data = msi_config->users[idx].base_vector + + ab_pci->msi_ep_base_data; + *base_vector = msi_config->users[idx].base_vector; + +ath12k_dbg (ab,ATH12K_DBG_PCI ,"Assign MSI to user: %s, num_vectors: %d, user_base_data: %u, base_vector: %u\n" , + user_name, *num_vectors, *user_base_data, + *base_vector); + +return 0 ; + } + } + +ath12k_err (ab,"Failed to find MSI assignment for %s!\n" , user_name); + +return -EINVAL ; +} + +void ath12k_pci_get_msi_address (struct ath12k_base *ab,u32 *msi_addr_lo, +u32 *msi_addr_hi) +{ +struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); +struct pci_dev *pci_dev =to_pci_dev (ab->dev); + +pci_read_config_dword (pci_dev, pci_dev->msi_cap +PCI_MSI_ADDRESS_LO , + msi_addr_lo); + +if (test_bit (ATH12K_PCI_FLAG_IS_MSI_64 , &ab_pci->flags)) { +pci_read_config_dword (pci_dev, pci_dev->msi_cap +PCI_MSI_ADDRESS_HI , + msi_addr_hi); + }else { + *msi_addr_hi =0 ; + } +} + +void ath12k_pci_get_ce_msi_idx (struct ath12k_base *ab,u32 ce_id, +u32 *msi_idx) +{ +u32 i, msi_data_idx; + +for (i =0 , msi_data_idx =0 ; i < ab->hw_params->ce_count; i++) { +if (ath12k_ce_get_attr_flags (ab, i) &CE_ATTR_DIS_INTR ) +continue ; + +if (ce_id == i) +break ; + + msi_data_idx++; + } + *msi_idx = msi_data_idx; +} + +void ath12k_pci_hif_ce_irq_enable (struct ath12k_base *ab) +{ +ath12k_pci_ce_irqs_enable (ab); +} + +void ath12k_pci_hif_ce_irq_disable (struct ath12k_base *ab) +{ +ath12k_pci_ce_irq_disable_sync (ab); +} + +void ath12k_pci_ext_irq_enable (struct ath12k_base *ab) +{ +int i; + +for (i =0 ; i <ATH12K_EXT_IRQ_GRP_NUM_MAX ; i++) { +struct ath12k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i]; + +napi_enable (&irq_grp->napi); +ath12k_pci_ext_grp_enable (irq_grp); + } +} + +void ath12k_pci_ext_irq_disable (struct ath12k_base *ab) +{ +__ath12k_pci_ext_irq_disable (ab); +ath12k_pci_sync_ext_irqs (ab); +} + +int ath12k_pci_hif_suspend (struct ath12k_base *ab) +{ +struct ath12k_pci *ar_pci =ath12k_pci_priv (ab); + +ath12k_mhi_suspend (ar_pci); + +return 0 ; +} + +int ath12k_pci_hif_resume (struct ath12k_base *ab) +{ +struct ath12k_pci *ar_pci =ath12k_pci_priv (ab); + +ath12k_mhi_resume (ar_pci); + +return 0 ; +} + +void ath12k_pci_stop (struct ath12k_base *ab) +{ +ath12k_pci_ce_irq_disable_sync (ab); +ath12k_ce_cleanup_pipes (ab); +} + +int ath12k_pci_start (struct ath12k_base *ab) +{ +struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); + +set_bit (ATH12K_PCI_FLAG_INIT_DONE , &ab_pci->flags); + +ath12k_pci_aspm_restore (ab_pci); + +ath12k_pci_ce_irqs_enable (ab); +ath12k_ce_rx_post_buf (ab); + +return 0 ; +} + +u32 ath12k_pci_read32 (struct ath12k_base *ab,u32 offset) +{ +struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); +u32 val, window_start; + +/* for offset beyond BAR + 4K - 32, may +* need to wakeup MHI to access. +*/ +if (test_bit (ATH12K_PCI_FLAG_INIT_DONE , &ab_pci->flags) && + offset >=ACCESS_ALWAYS_OFF ) +mhi_device_get_sync (ab_pci->mhi_ctrl->mhi_dev); + +if (offset <WINDOW_START ) { + val =ioread32 (ab->mem + offset); + }else { +if (ab->static_window_map) + window_start =ath12k_pci_get_window_start (ab, offset); +else + window_start =WINDOW_START ; + +if (window_start ==WINDOW_START ) { +spin_lock_bh (&ab_pci->window_lock); +ath12k_pci_select_window (ab_pci, offset); + val =ioread32 (ab->mem + window_start + + (offset &WINDOW_RANGE_MASK )); +spin_unlock_bh (&ab_pci->window_lock); + }else { +if ((!window_start) && + (offset >=PCI_MHIREGLEN_REG && + offset <=PCI_MHI_REGION_END )) + offset = offset -PCI_MHIREGLEN_REG ; + + val =ioread32 (ab->mem + window_start + + (offset &WINDOW_RANGE_MASK )); + } + } + +if (test_bit (ATH12K_PCI_FLAG_INIT_DONE , &ab_pci->flags) && + offset >=ACCESS_ALWAYS_OFF ) +mhi_device_put (ab_pci->mhi_ctrl->mhi_dev); + +return val; +} + +void ath12k_pci_write32 (struct ath12k_base *ab,u32 offset,u32 value) +{ +struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); +u32 window_start; + +/* for offset beyond BAR + 4K - 32, may +* need to wakeup MHI to access. +*/ +if (test_bit (ATH12K_PCI_FLAG_INIT_DONE , &ab_pci->flags) && + offset >=ACCESS_ALWAYS_OFF ) +mhi_device_get_sync (ab_pci->mhi_ctrl->mhi_dev); + +if (offset <WINDOW_START ) { +iowrite32 (value, ab->mem + offset); + }else { +if (ab->static_window_map) + window_start =ath12k_pci_get_window_start (ab, offset); +else + window_start =WINDOW_START ; + +if (window_start ==WINDOW_START ) { +spin_lock_bh (&ab_pci->window_lock); +ath12k_pci_select_window (ab_pci, offset); +iowrite32 (value, ab->mem + window_start + + (offset &WINDOW_RANGE_MASK )); +spin_unlock_bh (&ab_pci->window_lock); + }else { +if ((!window_start) && + (offset >=PCI_MHIREGLEN_REG && + offset <=PCI_MHI_REGION_END )) + offset = offset -PCI_MHIREGLEN_REG ; + +iowrite32 (value, ab->mem + window_start + + (offset &WINDOW_RANGE_MASK )); + } + } + +if (test_bit (ATH12K_PCI_FLAG_INIT_DONE , &ab_pci->flags) && + offset >=ACCESS_ALWAYS_OFF ) +mhi_device_put (ab_pci->mhi_ctrl->mhi_dev); +} + +int ath12k_pci_power_up (struct ath12k_base *ab) +{ +struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); +int ret; + + ab_pci->register_window =0 ; +clear_bit (ATH12K_PCI_FLAG_INIT_DONE , &ab_pci->flags); +ath12k_pci_sw_reset (ab_pci->ab, true); + +/* Disable ASPM during firmware download due to problems switching +* to AMSS state. +*/ +ath12k_pci_aspm_disable (ab_pci); + +ath12k_pci_msi_enable (ab_pci); + + ret =ath12k_mhi_start (ab_pci); +if (ret) { +ath12k_err (ab,"failed to start mhi: %d\n" , ret); +return ret; + } + +if (ab->static_window_map) +ath12k_pci_select_static_window (ab_pci); + +return 0 ; +} + +void ath12k_pci_power_down (struct ath12k_base *ab) +{ +struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); + +/* restore aspm in case firmware bootup fails */ +ath12k_pci_aspm_restore (ab_pci); + +ath12k_pci_force_wake (ab_pci->ab); +ath12k_pci_msi_disable (ab_pci); +ath12k_mhi_stop (ab_pci); +clear_bit (ATH12K_PCI_FLAG_INIT_DONE , &ab_pci->flags); +ath12k_pci_sw_reset (ab_pci->ab, false); +} + +static const struct ath12k_hif_ops ath12k_pci_hif_ops = { + .start = ath12k_pci_start, + .stop = ath12k_pci_stop, + .read32 = ath12k_pci_read32, + .write32 = ath12k_pci_write32, + .power_down = ath12k_pci_power_down, + .power_up = ath12k_pci_power_up, + .suspend = ath12k_pci_hif_suspend, + .resume = ath12k_pci_hif_resume, + .irq_enable = ath12k_pci_ext_irq_enable, + .irq_disable = ath12k_pci_ext_irq_disable, + .get_msi_address = ath12k_pci_get_msi_address, + .get_user_msi_vector = ath12k_pci_get_user_msi_assignment, + .map_service_to_pipe = ath12k_pci_map_service_to_pipe, + .ce_irq_enable = ath12k_pci_hif_ce_irq_enable, + .ce_irq_disable = ath12k_pci_hif_ce_irq_disable, + .get_ce_msi_idx = ath12k_pci_get_ce_msi_idx, +}; + +static +void ath12k_pci_read_hw_version (struct ath12k_base *ab,u32 *major,u32 *minor) +{ +u32 soc_hw_version; + + soc_hw_version =ath12k_pci_read32 (ab,TCSR_SOC_HW_VERSION ); + *major =FIELD_GET (TCSR_SOC_HW_VERSION_MAJOR_MASK , + soc_hw_version); + *minor =FIELD_GET (TCSR_SOC_HW_VERSION_MINOR_MASK , + soc_hw_version); + +ath12k_dbg (ab,ATH12K_DBG_PCI , +"pci tcsr_soc_hw_version major %d minor %d\n" , + *major, *minor); +} + +static int ath12k_pci_probe (struct pci_dev *pdev, +const struct pci_device_id *pci_dev) +{ +struct ath12k_base *ab; +struct ath12k_pci *ab_pci; +u32 soc_hw_version_major, soc_hw_version_minor; +int ret; + + ab =ath12k_core_alloc (&pdev->dev,sizeof (*ab_pci),ATH12K_BUS_PCI ); +if (!ab) { +dev_err (&pdev->dev,"failed to allocate ath12k base\n" ); +return -ENOMEM ; + } + + ab->dev = &pdev->dev; +pci_set_drvdata (pdev, ab); + ab_pci =ath12k_pci_priv (ab); + ab_pci->dev_id = pci_dev->device; + ab_pci->ab = ab; + ab_pci->pdev = pdev; + ab->hif.ops = &ath12k_pci_hif_ops; +pci_set_drvdata (pdev, ab); +spin_lock_init (&ab_pci->window_lock); + + ret =ath12k_pci_claim (ab_pci, pdev); +if (ret) { +ath12k_err (ab,"failed to claim device: %d\n" , ret); + goto err_free_core; + } + +switch (pci_dev->device) { +case QCN9274_DEVICE_ID : + ab_pci->msi_config = &ath12k_msi_config[0 ]; + ab->static_window_map = true; +ath12k_pci_read_hw_version (ab, &soc_hw_version_major, + &soc_hw_version_minor); +switch (soc_hw_version_major) { +case ATH12K_PCI_SOC_HW_VERSION_2 : + ab->hw_rev =ATH12K_HW_QCN9274_HW20 ; +break ; +case ATH12K_PCI_SOC_HW_VERSION_1 : + ab->hw_rev =ATH12K_HW_QCN9274_HW10 ; +break ; +default : +dev_err (&pdev->dev, +"Unknown hardware version found for QCN9274: 0x%x\n" , + soc_hw_version_major); +return -EOPNOTSUPP ; + } +break ; +case WCN7850_DEVICE_ID : + ab_pci->msi_config = &ath12k_msi_config[0 ]; + ab->static_window_map = false; + ab->hw_rev =ATH12K_HW_WCN7850_HW20 ; +break ; + +default : +dev_err (&pdev->dev,"Unknown PCI device found: 0x%x\n" , + pci_dev->device); + ret = -EOPNOTSUPP ; + goto err_pci_free_region; + } + + ret =ath12k_pci_msi_alloc (ab_pci); +if (ret) { +ath12k_err (ab,"failed to alloc msi: %d\n" , ret); + goto err_pci_free_region; + } + + ret =ath12k_core_pre_init (ab); +if (ret) + goto err_pci_msi_free; + + ret =ath12k_mhi_register (ab_pci); +if (ret) { +ath12k_err (ab,"failed to register mhi: %d\n" , ret); + goto err_pci_msi_free; + } + + ret =ath12k_hal_srng_init (ab); +if (ret) + goto err_mhi_unregister; + + ret =ath12k_ce_alloc_pipes (ab); +if (ret) { +ath12k_err (ab,"failed to allocate ce pipes: %d\n" , ret); + goto err_hal_srng_deinit; + } + +ath12k_pci_init_qmi_ce_config (ab); + + ret =ath12k_pci_config_irq (ab); +if (ret) { +ath12k_err (ab,"failed to config irq: %d\n" , ret); + goto err_ce_free; + } + + ret =ath12k_core_init (ab); +if (ret) { +ath12k_err (ab,"failed to init core: %d\n" , ret); + goto err_free_irq; + } +return 0 ; + +err_free_irq: +ath12k_pci_free_irq (ab); + +err_ce_free: +ath12k_ce_free_pipes (ab); + +err_hal_srng_deinit: +ath12k_hal_srng_deinit (ab); + +err_mhi_unregister: +ath12k_mhi_unregister (ab_pci); + +err_pci_msi_free: +ath12k_pci_msi_free (ab_pci); + +err_pci_free_region: +ath12k_pci_free_region (ab_pci); + +err_free_core: +ath12k_core_free (ab); + +return ret; +} + +static void ath12k_pci_remove (struct pci_dev *pdev) +{ +struct ath12k_base *ab =pci_get_drvdata (pdev); +struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); + +if (test_bit (ATH12K_FLAG_QMI_FAIL , &ab->dev_flags)) { +ath12k_pci_power_down (ab); +ath12k_qmi_deinit_service (ab); + goto qmi_fail; + } + +set_bit (ATH12K_FLAG_UNREGISTERING , &ab->dev_flags); + +cancel_work_sync (&ab->reset_work); +ath12k_core_deinit (ab); + +qmi_fail: +ath12k_mhi_unregister (ab_pci); + +ath12k_pci_free_irq (ab); +ath12k_pci_msi_free (ab_pci); +ath12k_pci_free_region (ab_pci); + +ath12k_hal_srng_deinit (ab); +ath12k_ce_free_pipes (ab); +ath12k_core_free (ab); +} + +static void ath12k_pci_shutdown (struct pci_dev *pdev) +{ +struct ath12k_base *ab =pci_get_drvdata (pdev); + +ath12k_pci_power_down (ab); +} + +static __maybe_unused int ath12k_pci_pm_suspend (struct device *dev) +{ +struct ath12k_base *ab =dev_get_drvdata (dev); +int ret; + + ret =ath12k_core_suspend (ab); +if (ret) +ath12k_warn (ab,"failed to suspend core: %d\n" , ret); + +return ret; +} + +static __maybe_unused int ath12k_pci_pm_resume (struct device *dev) +{ +struct ath12k_base *ab =dev_get_drvdata (dev); +int ret; + + ret =ath12k_core_resume (ab); +if (ret) +ath12k_warn (ab,"failed to resume core: %d\n" , ret); + +return ret; +} + +static SIMPLE_DEV_PM_OPS(ath12k_pci_pm_ops, + ath12k_pci_pm_suspend, + ath12k_pci_pm_resume); + +static struct pci_driver ath12k_pci_driver = { + .name ="ath12k_pci" , + .id_table = ath12k_pci_id_table, + .probe = ath12k_pci_probe, + .remove = ath12k_pci_remove, + .shutdown = ath12k_pci_shutdown, + .driver.pm = &ath12k_pci_pm_ops, +}; + +static int ath12k_pci_init (void ) +{ +int ret; + + ret =pci_register_driver (&ath12k_pci_driver); +if (ret) { +pr_err ("failed to register ath12k pci driver: %d\n" , + ret); +return ret; + } + +return 0 ; +} +module_init (ath12k_pci_init); + +static void ath12k_pci_exit (void ) +{ +pci_unregister_driver (&ath12k_pci_driver); +} + +module_exit (ath12k_pci_exit); + +MODULE_DESCRIPTION ("Driver support for Qualcomm Technologies 802.11be WLAN PCIe devices" ); +MODULE_LICENSE ("Dual BSD/GPL" );
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 39/50 wifi: ath12k: add qmi.c
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/qmi.c | 3096 +++++++++++++++++++++++++++++++++ 1 file changed, 3096 insertions(+)
drivers/net/wireless/ath/ath12k/qmi.c new file +3096 -0
@@ -0,0 +1,3096 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#include <linux/elf.h> + +#include "qmi.h" +#include "core.h" +#include "debug.h" +#include <linux/of.h> +#include <linux/firmware.h> + +#define SLEEP_CLOCK_SELECT_INTERNAL_BIT 0x02 +#define HOST_CSTATE_BIT 0x04 +#define PLATFORM_CAP_PCIE_GLOBAL_RESET 0x08 +#define ATH12K_QMI_MAX_CHUNK_SIZE 2097152 + +static struct qmi_elem_info wlfw_host_mlo_chip_info_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct wlfw_host_mlo_chip_info_s_v01 , + chip_id), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct wlfw_host_mlo_chip_info_s_v01 , + num_local_links), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =QMI_WLFW_MAX_NUM_MLO_LINKS_PER_CHIP_V01 , + .elem_size =sizeof (u8), + .array_type =STATIC_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct wlfw_host_mlo_chip_info_s_v01 , + hw_link_id), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =QMI_WLFW_MAX_NUM_MLO_LINKS_PER_CHIP_V01 , + .elem_size =sizeof (u8), + .array_type =STATIC_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct wlfw_host_mlo_chip_info_s_v01 , + valid_mlo_link_id), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_host_cap_req_msg_v01_ei[] = { + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + num_clients_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + num_clients), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + wake_msi_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + wake_msi), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + gpios_valid), + }, + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + gpios_len), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =QMI_WLFW_MAX_NUM_GPIO_V01 , + .elem_size =sizeof (u32), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + gpios), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + nm_modem_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + nm_modem), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x14 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + bdf_support_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x14 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + bdf_support), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x15 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + bdf_cache_support_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x15 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + bdf_cache_support), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x16 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + m3_support_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x16 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + m3_support), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + m3_cache_support_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + m3_cache_support), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x18 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + cal_filesys_support_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x18 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + cal_filesys_support), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x19 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + cal_cache_support_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x19 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + cal_cache_support), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1A , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + cal_done_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1A , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + cal_done), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1B , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mem_bucket_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x1B , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mem_bucket), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1C , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mem_cfg_mode_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1C , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mem_cfg_mode), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1D , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + cal_duration_valid), + }, + { + .data_type =QMI_UNSIGNED_2_BYTE , + .elem_len =1 , + .elem_size =sizeof (u16), + .array_type =NO_ARRAY , + .tlv_type =0x1D , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + cal_duraiton), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1E , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + platform_name_valid), + }, + { + .data_type =QMI_STRING , + .elem_len =QMI_WLANFW_MAX_PLATFORM_NAME_LEN_V01 +1 , + .elem_size =sizeof (char ), + .array_type =NO_ARRAY , + .tlv_type =0x1E , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + platform_name), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1F , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + ddr_range_valid), + }, + { + .data_type =QMI_STRUCT , + .elem_len =QMI_WLANFW_MAX_HOST_DDR_RANGE_SIZE_V01 , + .elem_size =sizeof (struct qmi_wlanfw_host_ddr_range ), + .array_type =STATIC_ARRAY , + .tlv_type =0x1F , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + ddr_range), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x20 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + host_build_type_valid), + }, + { + .data_type =QMI_SIGNED_4_BYTE_ENUM , + .elem_len =1 , + .elem_size =sizeof (enum qmi_wlanfw_host_build_type ), + .array_type =NO_ARRAY , + .tlv_type =0x20 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + host_build_type), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x21 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_capable_valid), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x21 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_capable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x22 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_chip_id_valid), + }, + { + .data_type =QMI_UNSIGNED_2_BYTE , + .elem_len =1 , + .elem_size =sizeof (u16), + .array_type =NO_ARRAY , + .tlv_type =0x22 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_chip_id), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x23 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_group_id_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x23 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_group_id), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x24 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + max_mlo_peer_valid), + }, + { + .data_type =QMI_UNSIGNED_2_BYTE , + .elem_len =1 , + .elem_size =sizeof (u16), + .array_type =NO_ARRAY , + .tlv_type =0x24 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + max_mlo_peer), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x25 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_num_chips_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x25 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_num_chips), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x26 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_chip_info_valid), + }, + { + .data_type =QMI_STRUCT , + .elem_len =QMI_WLFW_MAX_NUM_MLO_CHIPS_V01 , + .elem_size =sizeof (struct wlfw_host_mlo_chip_info_s_v01 ), + .array_type =STATIC_ARRAY , + .tlv_type =0x26 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + mlo_chip_info), + .ei_array = wlfw_host_mlo_chip_info_s_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x27 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + feature_list_valid), + }, + { + .data_type =QMI_UNSIGNED_8_BYTE , + .elem_len =1 , + .elem_size =sizeof (u64), + .array_type =NO_ARRAY , + .tlv_type =0x27 , + .offset = offsetof(struct qmi_wlanfw_host_cap_req_msg_v01 , + feature_list), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_host_cap_resp_msg_v01_ei[] = { + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_response_type_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_host_cap_resp_msg_v01 , resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_ind_register_req_msg_v01_ei[] = { + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + fw_ready_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + fw_ready_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + initiate_cal_download_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + initiate_cal_download_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + initiate_cal_update_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + initiate_cal_update_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + msa_ready_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + msa_ready_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x14 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + pin_connect_result_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x14 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + pin_connect_result_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x15 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + client_id_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x15 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + client_id), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x16 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + request_mem_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x16 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + request_mem_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + fw_mem_ready_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + fw_mem_ready_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x18 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + fw_init_done_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x18 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + fw_init_done_enable), + }, + + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x19 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + rejuvenate_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x19 , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + rejuvenate_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1A , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + xo_cal_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1A , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + xo_cal_enable), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1B , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + cal_done_enable_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1B , + .offset = offsetof(struct qmi_wlanfw_ind_register_req_msg_v01 , + cal_done_enable), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_ind_register_resp_msg_v01_ei[] = { + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_response_type_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01 , + resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01 , + fw_status_valid), + }, + { + .data_type =QMI_UNSIGNED_8_BYTE , + .elem_len =1 , + .elem_size =sizeof (u64), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01 , + fw_status), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_mem_cfg_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_8_BYTE , + .elem_len =1 , + .elem_size =sizeof (u64), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_cfg_s_v01 , offset), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_cfg_s_v01 , size), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_cfg_s_v01 , secure_flag), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_mem_seg_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_seg_s_v01 , + size), + }, + { + .data_type =QMI_SIGNED_4_BYTE_ENUM , + .elem_len =1 , + .elem_size =sizeof (enum qmi_wlanfw_mem_type_enum_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_seg_s_v01 , type), + }, + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_seg_s_v01 , mem_cfg_len), + }, + { + .data_type =QMI_STRUCT , + .elem_len =QMI_WLANFW_MAX_NUM_MEM_CFG_V01 , + .elem_size =sizeof (struct qmi_wlanfw_mem_cfg_s_v01 ), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_seg_s_v01 , mem_cfg), + .ei_array = qmi_wlanfw_mem_cfg_s_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_request_mem_ind_msg_v01_ei[] = { + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x01 , + .offset = offsetof(struct qmi_wlanfw_request_mem_ind_msg_v01 , + mem_seg_len), + }, + { + .data_type =QMI_STRUCT , + .elem_len =ATH12K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01 , + .elem_size =sizeof (struct qmi_wlanfw_mem_seg_s_v01 ), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0x01 , + .offset = offsetof(struct qmi_wlanfw_request_mem_ind_msg_v01 , + mem_seg), + .ei_array = qmi_wlanfw_mem_seg_s_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_mem_seg_resp_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_8_BYTE , + .elem_len =1 , + .elem_size =sizeof (u64), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01 , addr), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01 , size), + }, + { + .data_type =QMI_SIGNED_4_BYTE_ENUM , + .elem_len =1 , + .elem_size =sizeof (enum qmi_wlanfw_mem_type_enum_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01 , type), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01 , restore), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_respond_mem_req_msg_v01_ei[] = { + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x01 , + .offset = offsetof(struct qmi_wlanfw_respond_mem_req_msg_v01 , + mem_seg_len), + }, + { + .data_type =QMI_STRUCT , + .elem_len =ATH12K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01 , + .elem_size =sizeof (struct qmi_wlanfw_mem_seg_resp_s_v01 ), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0x01 , + .offset = offsetof(struct qmi_wlanfw_respond_mem_req_msg_v01 , + mem_seg), + .ei_array = qmi_wlanfw_mem_seg_resp_s_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_respond_mem_resp_msg_v01_ei[] = { + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_response_type_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_respond_mem_resp_msg_v01 , + resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_cap_req_msg_v01_ei[] = { + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_rf_chip_info_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_rf_chip_info_s_v01 , + chip_id), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_rf_chip_info_s_v01 , + chip_family), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_rf_board_info_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_rf_board_info_s_v01 , + board_id), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_soc_info_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_soc_info_s_v01 , soc_id), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_dev_mem_info_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_8_BYTE , + .elem_len =1 , + .elem_size =sizeof (u64), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_dev_mem_info_s_v01 , + start), + }, + { + .data_type =QMI_UNSIGNED_8_BYTE , + .elem_len =1 , + .elem_size =sizeof (u64), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_dev_mem_info_s_v01 , + size), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_fw_version_info_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_fw_version_info_s_v01 , + fw_version), + }, + { + .data_type =QMI_STRING , + .elem_len =ATH12K_QMI_WLANFW_MAX_TIMESTAMP_LEN_V01 +1 , + .elem_size =sizeof (char ), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_fw_version_info_s_v01 , + fw_build_timestamp), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_cap_resp_msg_v01_ei[] = { + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_response_type_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + chip_info_valid), + }, + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_wlanfw_rf_chip_info_s_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + chip_info), + .ei_array = qmi_wlanfw_rf_chip_info_s_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + board_info_valid), + }, + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_wlanfw_rf_board_info_s_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + board_info), + .ei_array = qmi_wlanfw_rf_board_info_s_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + soc_info_valid), + }, + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_wlanfw_soc_info_s_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + soc_info), + .ei_array = qmi_wlanfw_soc_info_s_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + fw_version_info_valid), + }, + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_wlanfw_fw_version_info_s_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + fw_version_info), + .ei_array = qmi_wlanfw_fw_version_info_s_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x14 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + fw_build_id_valid), + }, + { + .data_type =QMI_STRING , + .elem_len =ATH12K_QMI_WLANFW_MAX_BUILD_ID_LEN_V01 +1 , + .elem_size =sizeof (char ), + .array_type =NO_ARRAY , + .tlv_type =0x14 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + fw_build_id), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x15 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + num_macs_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x15 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + num_macs), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x16 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + voltage_mv_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x16 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + voltage_mv), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + time_freq_hz_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + time_freq_hz), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x18 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + otp_version_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x18 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + otp_version), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x19 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + eeprom_caldata_read_timeout_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x19 , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + eeprom_caldata_read_timeout), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1A , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + fw_caps_valid), + }, + { + .data_type =QMI_UNSIGNED_8_BYTE , + .elem_len =1 , + .elem_size =sizeof (u64), + .array_type =NO_ARRAY , + .tlv_type =0x1A , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , fw_caps), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1B , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + rd_card_chain_cap_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x1B , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + rd_card_chain_cap), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x1C , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , + dev_mem_info_valid), + }, + { + .data_type =QMI_STRUCT , + .elem_len =ATH12K_QMI_WLFW_MAX_DEV_MEM_NUM_V01 , + .elem_size =sizeof (struct qmi_wlanfw_dev_mem_info_s_v01 ), + .array_type =STATIC_ARRAY , + .tlv_type =0x1C , + .offset = offsetof(struct qmi_wlanfw_cap_resp_msg_v01 , dev_mem), + .ei_array = qmi_wlanfw_dev_mem_info_s_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_bdf_download_req_msg_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x01 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + valid), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + file_id_valid), + }, + { + .data_type =QMI_SIGNED_4_BYTE_ENUM , + .elem_len =1 , + .elem_size =sizeof (enum qmi_wlanfw_cal_temp_id_enum_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + file_id), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + total_size_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + total_size), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + seg_id_valid), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + seg_id), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + data_valid), + }, + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u16), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + data_len), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =QMI_WLANFW_MAX_DATA_SIZE_V01 , + .elem_size =sizeof (u8), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + data), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x14 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + end_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x14 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + end), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x15 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + bdf_type_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x15 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01 , + bdf_type), + }, + + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_bdf_download_resp_msg_v01_ei[] = { + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_response_type_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_bdf_download_resp_msg_v01 , + resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_m3_info_req_msg_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_8_BYTE , + .elem_len =1 , + .elem_size =sizeof (u64), + .array_type =NO_ARRAY , + .tlv_type =0x01 , + .offset = offsetof(struct qmi_wlanfw_m3_info_req_msg_v01 , addr), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_m3_info_req_msg_v01 , size), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_m3_info_resp_msg_v01_ei[] = { + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_response_type_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_m3_info_resp_msg_v01 , resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_ce_tgt_pipe_cfg_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01 , + pipe_num), + }, + { + .data_type =QMI_SIGNED_4_BYTE_ENUM , + .elem_len =1 , + .elem_size =sizeof (enum qmi_wlanfw_pipedir_enum_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01 , + pipe_dir), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01 , + nentries), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01 , + nbytes_max), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01 , + flags), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_ce_svc_pipe_cfg_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01 , + service_id), + }, + { + .data_type =QMI_SIGNED_4_BYTE_ENUM , + .elem_len =1 , + .elem_size =sizeof (enum qmi_wlanfw_pipedir_enum_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01 , + pipe_dir), + }, + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01 , + pipe_num), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_shadow_reg_cfg_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_2_BYTE , + .elem_len =1 , + .elem_size =sizeof (u16), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_shadow_reg_cfg_s_v01 , id), + }, + { + .data_type =QMI_UNSIGNED_2_BYTE , + .elem_len =1 , + .elem_size =sizeof (u16), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_shadow_reg_cfg_s_v01 , + offset), + }, + { + .data_type =QMI_EOTI , + .array_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_shadow_reg_v3_cfg_s_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0 , + .offset = offsetof(struct qmi_wlanfw_shadow_reg_v3_cfg_s_v01 , + addr), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_wlan_mode_req_msg_v01_ei[] = { + { + .data_type =QMI_UNSIGNED_4_BYTE , + .elem_len =1 , + .elem_size =sizeof (u32), + .array_type =NO_ARRAY , + .tlv_type =0x01 , + .offset = offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01 , + mode), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01 , + hw_debug_valid), + }, + { + .data_type =QMI_UNSIGNED_1_BYTE , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01 , + hw_debug), + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_wlan_mode_resp_msg_v01_ei[] = { + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_response_type_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_wlan_mode_resp_msg_v01 , + resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_wlan_cfg_req_msg_v01_ei[] = { + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + host_version_valid), + }, + { + .data_type =QMI_STRING , + .elem_len =QMI_WLANFW_MAX_STR_LEN_V01 +1 , + .elem_size =sizeof (char ), + .array_type =NO_ARRAY , + .tlv_type =0x10 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + host_version), + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + tgt_cfg_valid), + }, + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + tgt_cfg_len), + }, + { + .data_type =QMI_STRUCT , + .elem_len =QMI_WLANFW_MAX_NUM_CE_V01 , + .elem_size =sizeof (struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01 ), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0x11 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + tgt_cfg), + .ei_array = qmi_wlanfw_ce_tgt_pipe_cfg_s_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + svc_cfg_valid), + }, + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + svc_cfg_len), + }, + { + .data_type =QMI_STRUCT , + .elem_len =QMI_WLANFW_MAX_NUM_SVC_V01 , + .elem_size =sizeof (struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01 ), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0x12 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + svc_cfg), + .ei_array = qmi_wlanfw_ce_svc_pipe_cfg_s_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + shadow_reg_valid), + }, + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + shadow_reg_len), + }, + { + .data_type =QMI_STRUCT , + .elem_len =QMI_WLANFW_MAX_NUM_SHADOW_REG_V01 , + .elem_size =sizeof (struct qmi_wlanfw_shadow_reg_cfg_s_v01 ), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0x13 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + shadow_reg), + .ei_array = qmi_wlanfw_shadow_reg_cfg_s_v01_ei, + }, + { + .data_type =QMI_OPT_FLAG , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + shadow_reg_v3_valid), + }, + { + .data_type =QMI_DATA_LEN , + .elem_len =1 , + .elem_size =sizeof (u8), + .array_type =NO_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + shadow_reg_v3_len), + }, + { + .data_type =QMI_STRUCT , + .elem_len =QMI_WLANFW_MAX_NUM_SHADOW_REG_V3_V01 , + .elem_size =sizeof (struct qmi_wlanfw_shadow_reg_v3_cfg_s_v01 ), + .array_type =VAR_LEN_ARRAY , + .tlv_type =0x17 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01 , + shadow_reg_v3), + .ei_array = qmi_wlanfw_shadow_reg_v3_cfg_s_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_wlan_cfg_resp_msg_v01_ei[] = { + { + .data_type =QMI_STRUCT , + .elem_len =1 , + .elem_size =sizeof (struct qmi_response_type_v01 ), + .array_type =NO_ARRAY , + .tlv_type =0x02 , + .offset = offsetof(struct qmi_wlanfw_wlan_cfg_resp_msg_v01 , resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + .tlv_type =QMI_COMMON_TLV_TYPE , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_mem_ready_ind_msg_v01_ei[] = { + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + }, +}; + +static struct qmi_elem_info qmi_wlanfw_fw_ready_ind_msg_v01_ei[] = { + { + .data_type =QMI_EOTI , + .array_type =NO_ARRAY , + }, +}; + +static void ath12k_host_cap_parse_mlo (struct qmi_wlanfw_host_cap_req_msg_v01 *req) +{ + req->mlo_capable_valid =1 ; + req->mlo_capable =1 ; + req->mlo_chip_id_valid =1 ; + req->mlo_chip_id =0 ; + req->mlo_group_id_valid =1 ; + req->mlo_group_id =0 ; + req->max_mlo_peer_valid =1 ; +/* Max peer number generally won't change for the same device +* but needs to be synced with host driver. +*/ + req->max_mlo_peer =32 ; + req->mlo_num_chips_valid =1 ; + req->mlo_num_chips =1 ; + req->mlo_chip_info_valid =1 ; + req->mlo_chip_info[0 ].chip_id =0 ; + req->mlo_chip_info[0 ].num_local_links =2 ; + req->mlo_chip_info[0 ].hw_link_id[0 ] =0 ; + req->mlo_chip_info[0 ].hw_link_id[1 ] =1 ; + req->mlo_chip_info[0 ].valid_mlo_link_id[0 ] =1 ; + req->mlo_chip_info[0 ].valid_mlo_link_id[1 ] =1 ; +} + +static int ath12k_qmi_host_cap_send (struct ath12k_base *ab) +{ +struct qmi_wlanfw_host_cap_req_msg_v01 req; +struct qmi_wlanfw_host_cap_resp_msg_v01 resp; +struct qmi_txn txn = {}; +int ret =0 ; + +memset (&req,0 ,sizeof (req)); +memset (&resp,0 ,sizeof (resp)); + + req.num_clients_valid =1 ; + req.num_clients =1 ; + req.mem_cfg_mode = ab->qmi.target_mem_mode; + req.mem_cfg_mode_valid =1 ; + req.bdf_support_valid =1 ; + req.bdf_support =1 ; + + req.m3_support_valid =1 ; + req.m3_support =1 ; + req.m3_cache_support_valid =1 ; + req.m3_cache_support =1 ; + + req.cal_done_valid =1 ; + req.cal_done = ab->qmi.cal_done; + + req.feature_list_valid =1 ; + req.feature_list =BIT (CNSS_QDSS_CFG_MISS_V01 ); + +/* BRINGUP: here we are piggybacking a lot of stuff using +* internal_sleep_clock, should it be split? +*/ +if (ab->hw_params->internal_sleep_clock) { + req.nm_modem_valid =1 ; + +/* Notify firmware that this is non-qualcomm platform. */ + req.nm_modem |=HOST_CSTATE_BIT ; + +/* Notify firmware about the sleep clock selection, +* nm_modem_bit[1] is used for this purpose. Host driver on +* non-qualcomm platforms should select internal sleep +* clock. +*/ + req.nm_modem |=SLEEP_CLOCK_SELECT_INTERNAL_BIT ; + req.nm_modem |=PLATFORM_CAP_PCIE_GLOBAL_RESET ; + +ath12k_host_cap_parse_mlo (&req); + } + + ret =qmi_txn_init (&ab->qmi.handle, &txn, + qmi_wlanfw_host_cap_resp_msg_v01_ei, &resp); +if (ret <0 ) + goto out; + + ret =qmi_send_request (&ab->qmi.handle,NULL , &txn, +QMI_WLANFW_HOST_CAP_REQ_V01 , +QMI_WLANFW_HOST_CAP_REQ_MSG_V01_MAX_LEN , + qmi_wlanfw_host_cap_req_msg_v01_ei, &req); +if (ret <0 ) { +ath12k_warn (ab,"Failed to send host capability request,err = %d\n" , ret); + goto out; + } + + ret =qmi_txn_wait (&txn,msecs_to_jiffies (ATH12K_QMI_WLANFW_TIMEOUT_MS )); +if (ret <0 ) + goto out; + +if (resp.resp.result !=QMI_RESULT_SUCCESS_V01 ) { +ath12k_warn (ab,"Host capability request failed, result: %d, err: %d\n" , + resp.resp.result, resp.resp.error); + ret = -EINVAL ; + goto out; + } + +out: +return ret; +} + +static int ath12k_qmi_fw_ind_register_send (struct ath12k_base *ab) +{ +struct qmi_wlanfw_ind_register_req_msg_v01 *req; +struct qmi_wlanfw_ind_register_resp_msg_v01 *resp; +struct qmi_handle *handle = &ab->qmi.handle; +struct qmi_txn txn; +int ret; + + req =kzalloc (sizeof (*req),GFP_KERNEL ); +if (!req) +return -ENOMEM ; + + resp =kzalloc (sizeof (*resp),GFP_KERNEL ); +if (!resp) { + ret = -ENOMEM ; + goto resp_out; + } + + req->client_id_valid =1 ; + req->client_id =QMI_WLANFW_CLIENT_ID ; + req->fw_ready_enable_valid =1 ; + req->fw_ready_enable =1 ; + req->request_mem_enable_valid =1 ; + req->request_mem_enable =1 ; + req->fw_mem_ready_enable_valid =1 ; + req->fw_mem_ready_enable =1 ; + req->cal_done_enable_valid =1 ; + req->cal_done_enable =1 ; + req->fw_init_done_enable_valid =1 ; + req->fw_init_done_enable =1 ; + + req->pin_connect_result_enable_valid =0 ; + req->pin_connect_result_enable =0 ; + + ret =qmi_txn_init (handle, &txn, + qmi_wlanfw_ind_register_resp_msg_v01_ei, resp); +if (ret <0 ) + goto out; + + ret =qmi_send_request (&ab->qmi.handle,NULL , &txn, +QMI_WLANFW_IND_REGISTER_REQ_V01 , +QMI_WLANFW_IND_REGISTER_REQ_MSG_V01_MAX_LEN , + qmi_wlanfw_ind_register_req_msg_v01_ei, req); +if (ret <0 ) { +ath12k_warn (ab,"Failed to send indication register request, err = %d\n" , + ret); + goto out; + } + + ret =qmi_txn_wait (&txn,msecs_to_jiffies (ATH12K_QMI_WLANFW_TIMEOUT_MS )); +if (ret <0 ) { +ath12k_warn (ab,"failed to register fw indication %d\n" , ret); + goto out; + } + +if (resp->resp.result !=QMI_RESULT_SUCCESS_V01 ) { +ath12k_warn (ab,"FW Ind register request failed, result: %d, err: %d\n" , + resp->resp.result, resp->resp.error); + ret = -EINVAL ; + goto out; + } + +out: +kfree (resp); +resp_out: +kfree (req); +return ret; +} + +static int ath12k_qmi_respond_fw_mem_request (struct ath12k_base *ab) +{ +struct qmi_wlanfw_respond_mem_req_msg_v01 *req; +struct qmi_wlanfw_respond_mem_resp_msg_v01 resp; +struct qmi_txn txn = {}; +int ret =0 , i; +bool delayed; + + req =kzalloc (sizeof (*req),GFP_KERNEL ); +if (!req) +return -ENOMEM ; + +memset (&resp,0 ,sizeof (resp)); + +/* Some targets by default request a block of big contiguous +* DMA memory, it's hard to allocate from kernel. So host returns +* failure to firmware and firmware then request multiple blocks of +* small chunk size memory. +*/ +if (ab->qmi.target_mem_delayed) { + delayed = true; +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi delays mem_request %d\n" , + ab->qmi.mem_seg_count); +memset (req,0 ,sizeof (*req)); + }else { + delayed = false; + req->mem_seg_len = ab->qmi.mem_seg_count; +for (i =0 ; i < req->mem_seg_len ; i++) { + req->mem_seg[i].addr = ab->qmi.target_mem[i].paddr; + req->mem_seg[i].size = ab->qmi.target_mem[i].size; + req->mem_seg[i].type = ab->qmi.target_mem[i].type; +ath12k_dbg (ab,ATH12K_DBG_QMI , +"qmi req mem_seg[%d] %pad %u %u\n" , i, + &ab->qmi.target_mem[i].paddr, + ab->qmi.target_mem[i].size, + ab->qmi.target_mem[i].type); + } + } + + ret =qmi_txn_init (&ab->qmi.handle, &txn, + qmi_wlanfw_respond_mem_resp_msg_v01_ei, &resp); +if (ret <0 ) + goto out; + + ret =qmi_send_request (&ab->qmi.handle,NULL , &txn, +QMI_WLANFW_RESPOND_MEM_REQ_V01 , +QMI_WLANFW_RESPOND_MEM_REQ_MSG_V01_MAX_LEN , + qmi_wlanfw_respond_mem_req_msg_v01_ei, req); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to respond memory request, err = %d\n" , + ret); + goto out; + } + + ret =qmi_txn_wait (&txn,msecs_to_jiffies (ATH12K_QMI_WLANFW_TIMEOUT_MS )); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed memory request, err = %d\n" , ret); + goto out; + } + +if (resp.resp.result !=QMI_RESULT_SUCCESS_V01 ) { +/* the error response is expected when +* target_mem_delayed is true. +*/ +if (delayed && resp.resp.error ==0 ) + goto out; + +ath12k_warn (ab,"Respond mem req failed, result: %d, err: %d\n" , + resp.resp.result, resp.resp.error); + ret = -EINVAL ; + goto out; + } +out: +kfree (req); +return ret; +} + +static void ath12k_qmi_free_target_mem_chunk (struct ath12k_base *ab) +{ +int i; + +for (i =0 ; i < ab->qmi.mem_seg_count; i++) { +if (!ab->qmi.target_mem[i].v.addr) +continue ; +dma_free_coherent (ab->dev, + ab->qmi.target_mem[i].size, + ab->qmi.target_mem[i].v.addr, + ab->qmi.target_mem[i].paddr); + ab->qmi.target_mem[i].v.addr =NULL ; + } +} + +static int ath12k_qmi_alloc_target_mem_chunk (struct ath12k_base *ab) +{ +int i; +struct target_mem_chunk *chunk; + + ab->qmi.target_mem_delayed = false; + +for (i =0 ; i < ab->qmi.mem_seg_count; i++) { + chunk = &ab->qmi.target_mem[i]; + +/* Allocate memory for the region and the functionality supported +* on the host. For the non-supported memory region, host does not +* allocate memory, assigns NULL and FW will handle this without crashing. +*/ +switch (chunk->type) { +case HOST_DDR_REGION_TYPE : +case M3_DUMP_REGION_TYPE : +case PAGEABLE_MEM_REGION_TYPE : +case CALDB_MEM_REGION_TYPE : + chunk->v.addr =dma_alloc_coherent (ab->dev, + chunk->size, + &chunk->paddr, +GFP_KERNEL | __GFP_NOWARN); +if (!chunk->v.addr) { +if (chunk->size >ATH12K_QMI_MAX_CHUNK_SIZE ) { + ab->qmi.target_mem_delayed = true; +ath12k_warn (ab, +"qmi dma allocation failed (%d B type %u), will try later with small size\n" , + chunk->size, + chunk->type); +ath12k_qmi_free_target_mem_chunk (ab); +return 0 ; + } +ath12k_warn (ab,"memory allocation failure for %u size: %d\n" , + chunk->type, chunk->size); +return -ENOMEM ; + } +break ; +default : +ath12k_warn (ab,"memory type %u not supported\n" , + chunk->type); + chunk->paddr =0 ; + chunk->v.addr =NULL ; +break ; + } + } +return 0 ; +} + +static int ath12k_qmi_request_target_cap (struct ath12k_base *ab) +{ +struct qmi_wlanfw_cap_req_msg_v01 req; +struct qmi_wlanfw_cap_resp_msg_v01 resp; +struct qmi_txn txn = {}; +unsigned int board_id =ATH12K_BOARD_ID_DEFAULT ; +int ret =0 ; +int i; + +memset (&req,0 ,sizeof (req)); +memset (&resp,0 ,sizeof (resp)); + + ret =qmi_txn_init (&ab->qmi.handle, &txn, + qmi_wlanfw_cap_resp_msg_v01_ei, &resp); +if (ret <0 ) + goto out; + + ret =qmi_send_request (&ab->qmi.handle,NULL , &txn, +QMI_WLANFW_CAP_REQ_V01 , +QMI_WLANFW_CAP_REQ_MSG_V01_MAX_LEN , + qmi_wlanfw_cap_req_msg_v01_ei, &req); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send target cap request, err = %d\n" , + ret); + goto out; + } + + ret =qmi_txn_wait (&txn,msecs_to_jiffies (ATH12K_QMI_WLANFW_TIMEOUT_MS )); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed target cap request %d\n" , ret); + goto out; + } + +if (resp.resp.result !=QMI_RESULT_SUCCESS_V01 ) { +ath12k_warn (ab,"qmi targetcap req failed, result: %d, err: %d\n" , + resp.resp.result, resp.resp.error); + ret = -EINVAL ; + goto out; + } + +if (resp.chip_info_valid) { + ab->qmi.target.chip_id = resp.chip_info.chip_id; + ab->qmi.target.chip_family = resp.chip_info.chip_family; + } + +if (resp.board_info_valid) + ab->qmi.target.board_id = resp.board_info.board_id; +else + ab->qmi.target.board_id = board_id; + +if (resp.soc_info_valid) + ab->qmi.target.soc_id = resp.soc_info.soc_id; + +if (resp.fw_version_info_valid) { + ab->qmi.target.fw_version = resp.fw_version_info.fw_version; +strscpy (ab->qmi.target.fw_build_timestamp, + resp.fw_version_info.fw_build_timestamp, +sizeof (ab->qmi.target.fw_build_timestamp)); + } + +if (resp.fw_build_id_valid) +strscpy (ab->qmi.target.fw_build_id, resp.fw_build_id, +sizeof (ab->qmi.target.fw_build_id)); + +if (resp.dev_mem_info_valid) { +for (i =0 ; i <ATH12K_QMI_WLFW_MAX_DEV_MEM_NUM_V01 ; i++) { + ab->qmi.dev_mem[i].start = + resp.dev_mem[i].start; + ab->qmi.dev_mem[i].size = + resp.dev_mem[i].size; +ath12k_dbg (ab,ATH12K_DBG_QMI , +"devmem [%d] start ox%llx size %llu\n" , i, + ab->qmi.dev_mem[i].start, + ab->qmi.dev_mem[i].size); + } + } + +if (resp.eeprom_caldata_read_timeout_valid) { + ab->qmi.target.eeprom_caldata = resp.eeprom_caldata_read_timeout; +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi cal data supported from eeprom\n" ); + } + +ath12k_info (ab,"chip_id 0x%x chip_family 0x%x board_id 0x%x soc_id 0x%x\n" , + ab->qmi.target.chip_id, ab->qmi.target.chip_family, + ab->qmi.target.board_id, ab->qmi.target.soc_id); + +ath12k_info (ab,"fw_version 0x%x fw_build_timestamp %s fw_build_id %s" , + ab->qmi.target.fw_version, + ab->qmi.target.fw_build_timestamp, + ab->qmi.target.fw_build_id); + +out: +return ret; +} + +static int ath12k_qmi_load_file_target_mem (struct ath12k_base *ab, +const u8 *data,u32 len,u8 type) +{ +struct qmi_wlanfw_bdf_download_req_msg_v01 *req; +struct qmi_wlanfw_bdf_download_resp_msg_v01 resp; +struct qmi_txn txn = {}; +const u8 *temp = data; +int ret; +u32 remaining = len; + + req =kzalloc (sizeof (*req),GFP_KERNEL ); +if (!req) +return -ENOMEM ; +memset (&resp,0 ,sizeof (resp)); + +while (remaining) { + req->valid =1 ; + req->file_id_valid =1 ; + req->file_id = ab->qmi.target.board_id; + req->total_size_valid =1 ; + req->total_size = remaining; + req->seg_id_valid =1 ; + req->data_valid =1 ; + req->bdf_type = type; + req->bdf_type_valid =1 ; + req->end_valid =1 ; + req->end =0 ; + +if (remaining >QMI_WLANFW_MAX_DATA_SIZE_V01 ) { + req->data_len =QMI_WLANFW_MAX_DATA_SIZE_V01 ; + }else { + req->data_len = remaining; + req->end =1 ; + } + +if (type ==ATH12K_QMI_FILE_TYPE_EEPROM ) { + req->data_valid =0 ; + req->end =1 ; + req->data_len =ATH12K_QMI_MAX_BDF_FILE_NAME_SIZE ; + }else { +memcpy (req->data, temp, req->data_len); + } + + ret =qmi_txn_init (&ab->qmi.handle, &txn, + qmi_wlanfw_bdf_download_resp_msg_v01_ei, + &resp); +if (ret <0 ) + goto out; + +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi bdf download req fixed addr type %d\n" , + type); + + ret =qmi_send_request (&ab->qmi.handle,NULL , &txn, +QMI_WLANFW_BDF_DOWNLOAD_REQ_V01 , +QMI_WLANFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_LEN , + qmi_wlanfw_bdf_download_req_msg_v01_ei, req); +if (ret <0 ) { +qmi_txn_cancel (&txn); + goto out; + } + + ret =qmi_txn_wait (&txn,msecs_to_jiffies (ATH12K_QMI_WLANFW_TIMEOUT_MS )); +if (ret <0 ) + goto out; + +if (resp.resp.result !=QMI_RESULT_SUCCESS_V01 ) { +ath12k_warn (ab,"qmi BDF download failed, result: %d, err: %d\n" , + resp.resp.result, resp.resp.error); + ret = -EINVAL ; + goto out; + } + + remaining -= req->data_len; + temp += req->data_len; + req->seg_id++; +ath12k_dbg (ab,ATH12K_DBG_QMI , +"qmi bdf download request remaining %i\n" , + remaining); + } + +out: +kfree (req); +return ret; +} + +static int ath12k_qmi_load_bdf_qmi (struct ath12k_base *ab, +enum ath12k_qmi_bdf_type type) +{ +struct device *dev = ab->dev; +char filename[ATH12K_QMI_MAX_BDF_FILE_NAME_SIZE ]; +const struct firmware *fw_entry; +struct ath12k_board_data bd; +u32 fw_size, file_type; +int ret =0 ; +const u8 *tmp; + +memset (&bd,0 ,sizeof (bd)); + +switch (type) { +case ATH12K_QMI_BDF_TYPE_ELF : + ret =ath12k_core_fetch_bdf (ab, &bd); +if (ret) { +ath12k_warn (ab,"qmi failed to load bdf:\n" ); + goto out; + } + +if (bd.len >=SELFMAG &&memcmp (bd.data,ELFMAG ,SELFMAG ) ==0 ) + type =ATH12K_QMI_BDF_TYPE_ELF ; +else + type =ATH12K_QMI_BDF_TYPE_BIN ; + +break ; +case ATH12K_QMI_BDF_TYPE_REGDB : + ret =ath12k_core_fetch_board_data_api_1 (ab, &bd, +ATH12K_REGDB_FILE_NAME ); +if (ret) { +ath12k_warn (ab,"qmi failed to load regdb bin:\n" ); + goto out; + } +break ; +default : +ath12k_warn (ab,"unknown file type for load %d" , type); + goto out; + } + +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi bdf_type %d\n" , type); + + fw_size =min_t (u32, ab->hw_params->fw.board_size, bd.len); + + ret =ath12k_qmi_load_file_target_mem (ab, bd.data, fw_size, type); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to load bdf file\n" ); + goto out; + } + +if (!ab->hw_params->download_calib) + goto out; + + file_type =ATH12K_QMI_FILE_TYPE_CALDATA ; + +/* cal-<bus>-<id>.bin */ +snprintf (filename,sizeof (filename),"cal-%s-%s.bin" , +ath12k_bus_str (ab->hif.bus),dev_name (dev)); + fw_entry =ath12k_core_firmware_request (ab, filename); +if (!IS_ERR (fw_entry)) + goto success; + + fw_entry =ath12k_core_firmware_request (ab,ATH12K_DEFAULT_CAL_FILE ); +if (IS_ERR (fw_entry)) { + ret =PTR_ERR (fw_entry); +ath12k_warn (ab, +"qmi failed to load CAL data file:%s\n" , + filename); + goto out; + } + +if (ab->qmi.target.eeprom_caldata) { + file_type =ATH12K_QMI_FILE_TYPE_CALDATA ; + tmp = filename; + fw_size =ATH12K_QMI_MAX_BDF_FILE_NAME_SIZE ; + }else { + file_type =ATH12K_QMI_FILE_TYPE_CALDATA ; + +/* cal-<bus>-<id>.bin */ +snprintf (filename,sizeof (filename),"cal-%s-%s.bin" , +ath12k_bus_str (ab->hif.bus),dev_name (dev)); + fw_entry =ath12k_core_firmware_request (ab, filename); +if (!IS_ERR (fw_entry)) + goto success; + + fw_entry =ath12k_core_firmware_request (ab,ATH12K_DEFAULT_CAL_FILE ); +if (IS_ERR (fw_entry)) { + ret =PTR_ERR (fw_entry); +ath12k_warn (ab, +"qmi failed to load CAL data file:%s\n" , + filename); + goto out; + } + +success: + fw_size =min_t (u32, ab->hw_params->fw.board_size, fw_entry->size); + tmp = fw_entry->data; + } + + ret =ath12k_qmi_load_file_target_mem (ab, tmp, fw_size, file_type); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to load caldata\n" ); + goto out_qmi_cal; + } + +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi caldata downloaded: type: %u\n" , + file_type); + +out_qmi_cal: +if (!ab->qmi.target.eeprom_caldata) +release_firmware (fw_entry); +out: +ath12k_core_free_bdf (ab, &bd); +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi BDF download sequence completed\n" ); + +return ret; +} + +static int ath12k_qmi_m3_load (struct ath12k_base *ab) +{ +struct m3_mem_region *m3_mem = &ab->qmi.m3_mem; +const struct firmware *fw; +char path[100 ]; +int ret; + +if (m3_mem->vaddr || m3_mem->size) +return 0 ; + + fw =ath12k_core_firmware_request (ab,ATH12K_M3_FILE ); +if (IS_ERR (fw)) { + ret =PTR_ERR (fw); +ath12k_core_create_firmware_path (ab,ATH12K_M3_FILE , + path,sizeof (path)); +ath12k_err (ab,"failed to load %s: %d\n" , path, ret); +return ret; + } + + m3_mem->vaddr =dma_alloc_coherent (ab->dev, + fw->size, &m3_mem->paddr, +GFP_KERNEL ); +if (!m3_mem->vaddr) { +ath12k_err (ab,"failed to allocate memory for M3 with size %zu\n" , + fw->size); +release_firmware (fw); +return -ENOMEM ; + } + +memcpy (m3_mem->vaddr, fw->data, fw->size); + m3_mem->size = fw->size; +release_firmware (fw); + +return 0 ; +} + +static void ath12k_qmi_m3_free (struct ath12k_base *ab) +{ +struct m3_mem_region *m3_mem = &ab->qmi.m3_mem; + +if (!m3_mem->vaddr) +return ; + +dma_free_coherent (ab->dev, m3_mem->size, + m3_mem->vaddr, m3_mem->paddr); + m3_mem->vaddr =NULL ; +} + +static int ath12k_qmi_wlanfw_m3_info_send (struct ath12k_base *ab) +{ +struct m3_mem_region *m3_mem = &ab->qmi.m3_mem; +struct qmi_wlanfw_m3_info_req_msg_v01 req; +struct qmi_wlanfw_m3_info_resp_msg_v01 resp; +struct qmi_txn txn = {}; +int ret =0 ; + +memset (&req,0 ,sizeof (req)); +memset (&resp,0 ,sizeof (resp)); + + ret =ath12k_qmi_m3_load (ab); +if (ret) { +ath12k_err (ab,"failed to load m3 firmware: %d" , ret); +return ret; + } + + req.addr = m3_mem->paddr; + req.size = m3_mem->size; + + ret =qmi_txn_init (&ab->qmi.handle, &txn, + qmi_wlanfw_m3_info_resp_msg_v01_ei, &resp); +if (ret <0 ) + goto out; + + ret =qmi_send_request (&ab->qmi.handle,NULL , &txn, +QMI_WLANFW_M3_INFO_REQ_V01 , +QMI_WLANFW_M3_INFO_REQ_MSG_V01_MAX_MSG_LEN , + qmi_wlanfw_m3_info_req_msg_v01_ei, &req); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send M3 information request, err = %d\n" , + ret); + goto out; + } + + ret =qmi_txn_wait (&txn,msecs_to_jiffies (ATH12K_QMI_WLANFW_TIMEOUT_MS )); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed M3 information request %d\n" , ret); + goto out; + } + +if (resp.resp.result !=QMI_RESULT_SUCCESS_V01 ) { +ath12k_warn (ab,"qmi M3 info request failed, result: %d, err: %d\n" , + resp.resp.result, resp.resp.error); + ret = -EINVAL ; + goto out; + } +out: +return ret; +} + +static int ath12k_qmi_wlanfw_mode_send (struct ath12k_base *ab, +u32 mode) +{ +struct qmi_wlanfw_wlan_mode_req_msg_v01 req; +struct qmi_wlanfw_wlan_mode_resp_msg_v01 resp; +struct qmi_txn txn = {}; +int ret =0 ; + +memset (&req,0 ,sizeof (req)); +memset (&resp,0 ,sizeof (resp)); + + req.mode = mode; + req.hw_debug_valid =1 ; + req.hw_debug =0 ; + + ret =qmi_txn_init (&ab->qmi.handle, &txn, + qmi_wlanfw_wlan_mode_resp_msg_v01_ei, &resp); +if (ret <0 ) + goto out; + + ret =qmi_send_request (&ab->qmi.handle,NULL , &txn, +QMI_WLANFW_WLAN_MODE_REQ_V01 , +QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN , + qmi_wlanfw_wlan_mode_req_msg_v01_ei, &req); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send mode request, mode: %d, err = %d\n" , + mode, ret); + goto out; + } + + ret =qmi_txn_wait (&txn,msecs_to_jiffies (ATH12K_QMI_WLANFW_TIMEOUT_MS )); +if (ret <0 ) { +if (mode ==ATH12K_FIRMWARE_MODE_OFF && ret == -ENETRESET ) { +ath12k_warn (ab,"WLFW service is dis-connected\n" ); +return 0 ; + } +ath12k_warn (ab,"qmi failed set mode request, mode: %d, err = %d\n" , + mode, ret); + goto out; + } + +if (resp.resp.result !=QMI_RESULT_SUCCESS_V01 ) { +ath12k_warn (ab,"Mode request failed, mode: %d, result: %d err: %d\n" , + mode, resp.resp.result, resp.resp.error); + ret = -EINVAL ; + goto out; + } + +out: +return ret; +} + +static int ath12k_qmi_wlanfw_wlan_cfg_send (struct ath12k_base *ab) +{ +struct qmi_wlanfw_wlan_cfg_req_msg_v01 *req; +struct qmi_wlanfw_wlan_cfg_resp_msg_v01 resp; +struct ce_pipe_config *ce_cfg; +struct service_to_pipe *svc_cfg; +struct qmi_txn txn = {}; +int ret =0 , pipe_num; + + ce_cfg = (struct ce_pipe_config *)ab->qmi.ce_cfg.tgt_ce; + svc_cfg = (struct service_to_pipe *)ab->qmi.ce_cfg.svc_to_ce_map; + + req =kzalloc (sizeof (*req),GFP_KERNEL ); +if (!req) +return -ENOMEM ; + +memset (&resp,0 ,sizeof (resp)); + + req->host_version_valid =1 ; +strscpy (req->host_version,ATH12K_HOST_VERSION_STRING , +sizeof (req->host_version)); + + req->tgt_cfg_valid =1 ; +/* This is number of CE configs */ + req->tgt_cfg_len = ab->qmi.ce_cfg.tgt_ce_len; +for (pipe_num =0 ; pipe_num < req->tgt_cfg_len ; pipe_num++) { + req->tgt_cfg[pipe_num].pipe_num = ce_cfg[pipe_num].pipenum; + req->tgt_cfg[pipe_num].pipe_dir = ce_cfg[pipe_num].pipedir; + req->tgt_cfg[pipe_num].nentries = ce_cfg[pipe_num].nentries; + req->tgt_cfg[pipe_num].nbytes_max = ce_cfg[pipe_num].nbytes_max; + req->tgt_cfg[pipe_num].flags = ce_cfg[pipe_num].flags; + } + + req->svc_cfg_valid =1 ; +/* This is number of Service/CE configs */ + req->svc_cfg_len = ab->qmi.ce_cfg.svc_to_ce_map_len; +for (pipe_num =0 ; pipe_num < req->svc_cfg_len; pipe_num++) { + req->svc_cfg[pipe_num].service_id = svc_cfg[pipe_num].service_id; + req->svc_cfg[pipe_num].pipe_dir = svc_cfg[pipe_num].pipedir; + req->svc_cfg[pipe_num].pipe_num = svc_cfg[pipe_num].pipenum; + } + +/* set shadow v3 configuration */ +if (ab->hw_params->supports_shadow_regs) { + req->shadow_reg_v3_valid =1 ; + req->shadow_reg_v3_len =min_t (u32, + ab->qmi.ce_cfg.shadow_reg_v3_len, +QMI_WLANFW_MAX_NUM_SHADOW_REG_V3_V01 ); +memcpy (&req->shadow_reg_v3, ab->qmi.ce_cfg.shadow_reg_v3, +sizeof (u32) * req->shadow_reg_v3_len); + }else { + req->shadow_reg_v3_valid =0 ; + } + + ret =qmi_txn_init (&ab->qmi.handle, &txn, + qmi_wlanfw_wlan_cfg_resp_msg_v01_ei, &resp); +if (ret <0 ) + goto out; + + ret =qmi_send_request (&ab->qmi.handle,NULL , &txn, +QMI_WLANFW_WLAN_CFG_REQ_V01 , +QMI_WLANFW_WLAN_CFG_REQ_MSG_V01_MAX_LEN , + qmi_wlanfw_wlan_cfg_req_msg_v01_ei, req); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send wlan config request, err = %d\n" , + ret); + goto out; + } + + ret =qmi_txn_wait (&txn,msecs_to_jiffies (ATH12K_QMI_WLANFW_TIMEOUT_MS )); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed wlan config request, err = %d\n" , ret); + goto out; + } + +if (resp.resp.result !=QMI_RESULT_SUCCESS_V01 ) { +ath12k_warn (ab,"qmi wlan config request failed, result: %d, err: %d\n" , + resp.resp.result, resp.resp.error); + ret = -EINVAL ; + goto out; + } + +out: +kfree (req); +return ret; +} + +void ath12k_qmi_firmware_stop (struct ath12k_base *ab) +{ +int ret; + + ret =ath12k_qmi_wlanfw_mode_send (ab,ATH12K_FIRMWARE_MODE_OFF ); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send wlan mode off\n" ); +return ; + } +} + +int ath12k_qmi_firmware_start (struct ath12k_base *ab, +u32 mode) +{ +int ret; + + ret =ath12k_qmi_wlanfw_wlan_cfg_send (ab); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send wlan cfg:%d\n" , ret); +return ret; + } + + ret =ath12k_qmi_wlanfw_mode_send (ab, mode); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send wlan fw mode:%d\n" , ret); +return ret; + } + +return 0 ; +} + +static int +ath12k_qmi_driver_event_post (struct ath12k_qmi *qmi, +enum ath12k_qmi_event_type type, +void *data) +{ +struct ath12k_qmi_driver_event *event; + + event =kzalloc (sizeof (*event),GFP_ATOMIC ); +if (!event) +return -ENOMEM ; + + event->type = type; + event->data = data; + +spin_lock (&qmi->event_lock); +list_add_tail (&event->list, &qmi->event_list); +spin_unlock (&qmi->event_lock); + +queue_work (qmi->event_wq, &qmi->event_work); + +return 0 ; +} + +static int ath12k_qmi_event_server_arrive (struct ath12k_qmi *qmi) +{ +struct ath12k_base *ab = qmi->ab; +int ret; + + ret =ath12k_qmi_fw_ind_register_send (ab); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send FW indication QMI:%d\n" , ret); +return ret; + } + + ret =ath12k_qmi_host_cap_send (ab); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send host cap QMI:%d\n" , ret); +return ret; + } + +return ret; +} + +static int ath12k_qmi_event_mem_request (struct ath12k_qmi *qmi) +{ +struct ath12k_base *ab = qmi->ab; +int ret; + + ret =ath12k_qmi_respond_fw_mem_request (ab); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to respond fw mem req:%d\n" , ret); +return ret; + } + +return ret; +} + +static int ath12k_qmi_event_load_bdf (struct ath12k_qmi *qmi) +{ +struct ath12k_base *ab = qmi->ab; +int ret; + + ret =ath12k_qmi_request_target_cap (ab); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to req target capabilities:%d\n" , ret); +return ret; + } + + ret =ath12k_qmi_load_bdf_qmi (ab,ATH12K_QMI_BDF_TYPE_REGDB ); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to load regdb file:%d\n" , ret); +return ret; + } + + ret =ath12k_qmi_load_bdf_qmi (ab,ATH12K_QMI_BDF_TYPE_ELF ); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to load board data file:%d\n" , ret); +return ret; + } + + ret =ath12k_qmi_wlanfw_m3_info_send (ab); +if (ret <0 ) { +ath12k_warn (ab,"qmi failed to send m3 info req:%d\n" , ret); +return ret; + } + +return ret; +} + +static void ath12k_qmi_msg_mem_request_cb (struct qmi_handle *qmi_hdl, +struct sockaddr_qrtr *sq, +struct qmi_txn *txn, +const void *data) +{ + struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle); +struct ath12k_base *ab = qmi->ab; +const struct qmi_wlanfw_request_mem_ind_msg_v01 *msg = data; +int i, ret; + +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi firmware request memory request\n" ); + +if (msg->mem_seg_len ==0 || + msg->mem_seg_len >ATH12K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01 ) +ath12k_warn (ab,"Invalid memory segment length: %u\n" , + msg->mem_seg_len); + + ab->qmi.mem_seg_count = msg->mem_seg_len; + +for (i =0 ; i < qmi->mem_seg_count ; i++) { + ab->qmi.target_mem[i].type = msg->mem_seg[i].type; + ab->qmi.target_mem[i].size = msg->mem_seg[i].size; +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi mem seg type %d size %d\n" , + msg->mem_seg[i].type, msg->mem_seg[i].size); + } + + ret =ath12k_qmi_alloc_target_mem_chunk (ab); +if (ret) { +ath12k_warn (ab,"qmi failed to alloc target memory: %d\n" , + ret); +return ; + } + +ath12k_qmi_driver_event_post (qmi,ATH12K_QMI_EVENT_REQUEST_MEM ,NULL ); +} + +static void ath12k_qmi_msg_mem_ready_cb (struct qmi_handle *qmi_hdl, +struct sockaddr_qrtr *sq, +struct qmi_txn *txn, +const void *decoded) +{ + struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle); +struct ath12k_base *ab = qmi->ab; + +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi firmware memory ready indication\n" ); +ath12k_qmi_driver_event_post (qmi,ATH12K_QMI_EVENT_FW_MEM_READY ,NULL ); +} + +static void ath12k_qmi_msg_fw_ready_cb (struct qmi_handle *qmi_hdl, +struct sockaddr_qrtr *sq, +struct qmi_txn *txn, +const void *decoded) +{ + struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle); +struct ath12k_base *ab = qmi->ab; + +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi firmware ready\n" ); +ath12k_qmi_driver_event_post (qmi,ATH12K_QMI_EVENT_FW_READY ,NULL ); +} + +static const struct qmi_msg_handler ath12k_qmi_msg_handlers[] = { + { + .type =QMI_INDICATION , + .msg_id =QMI_WLFW_REQUEST_MEM_IND_V01 , + .ei = qmi_wlanfw_request_mem_ind_msg_v01_ei, + .decoded_size =sizeof (struct qmi_wlanfw_request_mem_ind_msg_v01 ), + .fn = ath12k_qmi_msg_mem_request_cb, + }, + { + .type =QMI_INDICATION , + .msg_id =QMI_WLFW_FW_MEM_READY_IND_V01 , + .ei = qmi_wlanfw_mem_ready_ind_msg_v01_ei, + .decoded_size =sizeof (struct qmi_wlanfw_fw_mem_ready_ind_msg_v01 ), + .fn = ath12k_qmi_msg_mem_ready_cb, + }, + { + .type =QMI_INDICATION , + .msg_id =QMI_WLFW_FW_READY_IND_V01 , + .ei = qmi_wlanfw_fw_ready_ind_msg_v01_ei, + .decoded_size =sizeof (struct qmi_wlanfw_fw_ready_ind_msg_v01 ), + .fn = ath12k_qmi_msg_fw_ready_cb, + }, +}; + +static int ath12k_qmi_ops_new_server (struct qmi_handle *qmi_hdl, +struct qmi_service *service) +{ + struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle); +struct ath12k_base *ab = qmi->ab; +struct sockaddr_qrtr *sq = &qmi->sq; +int ret; + + sq->sq_family =AF_QIPCRTR ; + sq->sq_node = service->node; + sq->sq_port = service->port; + + ret =kernel_connect (qmi_hdl->sock, (struct sockaddr *)sq, +sizeof (*sq),0 ); +if (ret) { +ath12k_warn (ab,"qmi failed to connect to remote service %d\n" , ret); +return ret; + } + +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi wifi fw qmi service connected\n" ); +ath12k_qmi_driver_event_post (qmi,ATH12K_QMI_EVENT_SERVER_ARRIVE ,NULL ); + +return ret; +} + +static void ath12k_qmi_ops_del_server (struct qmi_handle *qmi_hdl, +struct qmi_service *service) +{ + struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle); +struct ath12k_base *ab = qmi->ab; + +ath12k_dbg (ab,ATH12K_DBG_QMI ,"qmi wifi fw del server\n" ); +ath12k_qmi_driver_event_post (qmi,ATH12K_QMI_EVENT_SERVER_EXIT ,NULL ); +} + +static const struct qmi_ops ath12k_qmi_ops = { + .new_server = ath12k_qmi_ops_new_server, + .del_server = ath12k_qmi_ops_del_server, +}; + +static void ath12k_qmi_driver_event_work (struct work_struct *work) +{ + struct ath12k_qmi *qmi = container_of(work, struct ath12k_qmi, + event_work); +struct ath12k_qmi_driver_event *event; +struct ath12k_base *ab = qmi->ab; +int ret; + +spin_lock (&qmi->event_lock); +while (!list_empty (&qmi->event_list)) { + event =list_first_entry (&qmi->event_list, + struct ath12k_qmi_driver_event, list); +list_del (&event->list); +spin_unlock (&qmi->event_lock);
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
Part of the diff is not shown here. View the raw message.
PATCH v2 42/50 wifi: ath12k: add reg.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/reg.h | 95 +++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
drivers/net/wireless/ath/ath12k/reg.h new file +95 -0
@@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2019-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#ifndef ATH12K_REG_H +#define ATH12K_REG_H + +#include <linux/kernel.h> +#include <net/regulatory.h> + +struct ath12k_base ; +struct ath12k ; + +/* DFS regdomains supported by Firmware */ +enum ath12k_dfs_region { +ATH12K_DFS_REG_UNSET , +ATH12K_DFS_REG_FCC , +ATH12K_DFS_REG_ETSI , +ATH12K_DFS_REG_MKK , +ATH12K_DFS_REG_CN , +ATH12K_DFS_REG_KR , +ATH12K_DFS_REG_MKK_N , +ATH12K_DFS_REG_UNDEF , +}; + +enum ath12k_reg_cc_code { +REG_SET_CC_STATUS_PASS =0 , +REG_CURRENT_ALPHA2_NOT_FOUND =1 , +REG_INIT_ALPHA2_NOT_FOUND =2 , +REG_SET_CC_CHANGE_NOT_ALLOWED =3 , +REG_SET_CC_STATUS_NO_MEMORY =4 , +REG_SET_CC_STATUS_FAIL =5 , +}; + +struct ath12k_reg_rule { +u16 start_freq; +u16 end_freq; +u16 max_bw; +u8 reg_power; +u8 ant_gain; +u16 flags; +bool psd_flag; +u16 psd_eirp; +}; + +struct ath12k_reg_info { +enum ath12k_reg_cc_code status_code; +u8 num_phy; +u8 phy_id; +u16 reg_dmn_pair; +u16 ctry_code; +u8 alpha2[REG_ALPHA2_LEN +1 ]; +u32 dfs_region; +u32 phybitmap; +bool is_ext_reg_event; +u32 min_bw_2g; +u32 max_bw_2g; +u32 min_bw_5g; +u32 max_bw_5g; +u32 num_2g_reg_rules; +u32 num_5g_reg_rules; +struct ath12k_reg_rule *reg_rules_2g_ptr; +struct ath12k_reg_rule *reg_rules_5g_ptr; +enum wmi_reg_6g_client_type client_type; +bool rnr_tpe_usable; +bool unspecified_ap_usable; +/* TODO: All 6G related info can be stored only for required +* combination instead of all types, to optimize memory usage. +*/ +u8 domain_code_6g_ap[WMI_REG_CURRENT_MAX_AP_TYPE ]; +u8 domain_code_6g_client[WMI_REG_CURRENT_MAX_AP_TYPE ][WMI_REG_MAX_CLIENT_TYPE ]; +u32 domain_code_6g_super_id; +u32 min_bw_6g_ap[WMI_REG_CURRENT_MAX_AP_TYPE ]; +u32 max_bw_6g_ap[WMI_REG_CURRENT_MAX_AP_TYPE ]; +u32 min_bw_6g_client[WMI_REG_CURRENT_MAX_AP_TYPE ][WMI_REG_MAX_CLIENT_TYPE ]; +u32 max_bw_6g_client[WMI_REG_CURRENT_MAX_AP_TYPE ][WMI_REG_MAX_CLIENT_TYPE ]; +u32 num_6g_reg_rules_ap[WMI_REG_CURRENT_MAX_AP_TYPE ]; +u32 num_6g_reg_rules_cl[WMI_REG_CURRENT_MAX_AP_TYPE ][WMI_REG_MAX_CLIENT_TYPE ]; +struct ath12k_reg_rule *reg_rules_6g_ap_ptr[WMI_REG_CURRENT_MAX_AP_TYPE ]; +struct ath12k_reg_rule *reg_rules_6g_client_ptr + [WMI_REG_CURRENT_MAX_AP_TYPE ][WMI_REG_MAX_CLIENT_TYPE ]; +}; + +void ath12k_reg_init (struct ath12k *ar); +void ath12k_reg_free (struct ath12k_base *ab); +void ath12k_regd_update_work (struct work_struct *work); +struct ieee80211_regdomain *ath12k_reg_build_regd (struct ath12k_base *ab, +struct ath12k_reg_info *reg_info, +bool intersect); +int ath12k_regd_update (struct ath12k *ar,bool init); +int ath12k_reg_update_chan_list (struct ath12k *ar); + +#endif
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 43/50 wifi: ath12k: add rx_desc.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/rx_desc.h | 1441 +++++++++++++++++++++++++++++ 1 file changed, 1441 insertions(+)
drivers/net/wireless/ath/ath12k/rx_desc.h new file +1441 -0
@@ -0,0 +1,1441 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ +#ifndef ATH12K_RX_DESC_H +#define ATH12K_RX_DESC_H + +enum rx_desc_decap_type { +RX_DESC_DECAP_TYPE_RAW , +RX_DESC_DECAP_TYPE_NATIVE_WIFI , +RX_DESC_DECAP_TYPE_ETHERNET2_DIX , +RX_DESC_DECAP_TYPE_8023 , +}; + +enum rx_desc_decrypt_status_code { +RX_DESC_DECRYPT_STATUS_CODE_OK , +RX_DESC_DECRYPT_STATUS_CODE_UNPROTECTED_FRAME , +RX_DESC_DECRYPT_STATUS_CODE_DATA_ERR , +RX_DESC_DECRYPT_STATUS_CODE_KEY_INVALID , +RX_DESC_DECRYPT_STATUS_CODE_PEER_ENTRY_INVALID , +RX_DESC_DECRYPT_STATUS_CODE_OTHER , +}; + +#define RX_MPDU_START_INFO0_REO_DEST_IND GENMASK(4, 0) +#define RX_MPDU_START_INFO0_LMAC_PEER_ID_MSB GENMASK(6, 5) +#define RX_MPDU_START_INFO0_FLOW_ID_TOEPLITZ BIT(7) +#define RX_MPDU_START_INFO0_PKT_SEL_FP_UCAST_DATA BIT(8) +#define RX_MPDU_START_INFO0_PKT_SEL_FP_MCAST_DATA BIT(9) +#define RX_MPDU_START_INFO0_PKT_SEL_FP_CTRL_BAR BIT(10) +#define RX_MPDU_START_INFO0_RXDMA0_SRC_RING_SEL GENMASK(13, 11) +#define RX_MPDU_START_INFO0_RXDMA0_DST_RING_SEL GENMASK(16, 14) +#define RX_MPDU_START_INFO0_MCAST_ECHO_DROP_EN BIT(17) +#define RX_MPDU_START_INFO0_WDS_LEARN_DETECT_EN BIT(18) +#define RX_MPDU_START_INFO0_INTRA_BSS_CHECK_EN BIT(19) +#define RX_MPDU_START_INFO0_USE_PPE BIT(20) +#define RX_MPDU_START_INFO0_PPE_ROUTING_EN BIT(21) + +#define RX_MPDU_START_INFO1_REO_QUEUE_DESC_HI GENMASK(7, 0) +#define RX_MPDU_START_INFO1_RECV_QUEUE_NUM GENMASK(23, 8) +#define RX_MPDU_START_INFO1_PRE_DELIM_ERR_WARN BIT(24) +#define RX_MPDU_START_INFO1_FIRST_DELIM_ERR BIT(25) + +#define RX_MPDU_START_INFO2_EPD_EN BIT(0) +#define RX_MPDU_START_INFO2_ALL_FRAME_ENCPD BIT(1) +#define RX_MPDU_START_INFO2_ENC_TYPE GENMASK(5, 2) +#define RX_MPDU_START_INFO2_VAR_WEP_KEY_WIDTH GENMASK(7, 6) +#define RX_MPDU_START_INFO2_MESH_STA GENMASK(9, 8) +#define RX_MPDU_START_INFO2_BSSID_HIT BIT(10) +#define RX_MPDU_START_INFO2_BSSID_NUM GENMASK(14, 11) +#define RX_MPDU_START_INFO2_TID GENMASK(18, 15) + +#define RX_MPDU_START_INFO3_RXPCU_MPDU_FLTR GENMASK(1, 0) +#define RX_MPDU_START_INFO3_SW_FRAME_GRP_ID GENMASK(8, 2) +#define RX_MPDU_START_INFO3_NDP_FRAME BIT(9) +#define RX_MPDU_START_INFO3_PHY_ERR BIT(10) +#define RX_MPDU_START_INFO3_PHY_ERR_MPDU_HDR BIT(11) +#define RX_MPDU_START_INFO3_PROTO_VER_ERR BIT(12) +#define RX_MPDU_START_INFO3_AST_LOOKUP_VALID BIT(13) +#define RX_MPDU_START_INFO3_RANGING BIT(14) + +#define RX_MPDU_START_INFO4_MPDU_FCTRL_VALID BIT(0) +#define RX_MPDU_START_INFO4_MPDU_DUR_VALID BIT(1) +#define RX_MPDU_START_INFO4_MAC_ADDR1_VALID BIT(2) +#define RX_MPDU_START_INFO4_MAC_ADDR2_VALID BIT(3) +#define RX_MPDU_START_INFO4_MAC_ADDR3_VALID BIT(4) +#define RX_MPDU_START_INFO4_MAC_ADDR4_VALID BIT(5) +#define RX_MPDU_START_INFO4_MPDU_SEQ_CTRL_VALID BIT(6) +#define RX_MPDU_START_INFO4_MPDU_QOS_CTRL_VALID BIT(7) +#define RX_MPDU_START_INFO4_MPDU_HT_CTRL_VALID BIT(8) +#define RX_MPDU_START_INFO4_ENCRYPT_INFO_VALID BIT(9) +#define RX_MPDU_START_INFO4_MPDU_FRAG_NUMBER GENMASK(13, 10) +#define RX_MPDU_START_INFO4_MORE_FRAG_FLAG BIT(14) +#define RX_MPDU_START_INFO4_FROM_DS BIT(16) +#define RX_MPDU_START_INFO4_TO_DS BIT(17) +#define RX_MPDU_START_INFO4_ENCRYPTED BIT(18) +#define RX_MPDU_START_INFO4_MPDU_RETRY BIT(19) +#define RX_MPDU_START_INFO4_MPDU_SEQ_NUM GENMASK(31, 20) + +#define RX_MPDU_START_INFO5_KEY_ID GENMASK(7, 0) +#define RX_MPDU_START_INFO5_NEW_PEER_ENTRY BIT(8) +#define RX_MPDU_START_INFO5_DECRYPT_NEEDED BIT(9) +#define RX_MPDU_START_INFO5_DECAP_TYPE GENMASK(11, 10) +#define RX_MPDU_START_INFO5_VLAN_TAG_C_PADDING BIT(12) +#define RX_MPDU_START_INFO5_VLAN_TAG_S_PADDING BIT(13) +#define RX_MPDU_START_INFO5_STRIP_VLAN_TAG_C BIT(14) +#define RX_MPDU_START_INFO5_STRIP_VLAN_TAG_S BIT(15) +#define RX_MPDU_START_INFO5_PRE_DELIM_COUNT GENMASK(27, 16) +#define RX_MPDU_START_INFO5_AMPDU_FLAG BIT(28) +#define RX_MPDU_START_INFO5_BAR_FRAME BIT(29) +#define RX_MPDU_START_INFO5_RAW_MPDU BIT(30) + +#define RX_MPDU_START_INFO6_MPDU_LEN GENMASK(13, 0) +#define RX_MPDU_START_INFO6_FIRST_MPDU BIT(14) +#define RX_MPDU_START_INFO6_MCAST_BCAST BIT(15) +#define RX_MPDU_START_INFO6_AST_IDX_NOT_FOUND BIT(16) +#define RX_MPDU_START_INFO6_AST_IDX_TIMEOUT BIT(17) +#define RX_MPDU_START_INFO6_POWER_MGMT BIT(18) +#define RX_MPDU_START_INFO6_NON_QOS BIT(19) +#define RX_MPDU_START_INFO6_NULL_DATA BIT(20) +#define RX_MPDU_START_INFO6_MGMT_TYPE BIT(21) +#define RX_MPDU_START_INFO6_CTRL_TYPE BIT(22) +#define RX_MPDU_START_INFO6_MORE_DATA BIT(23) +#define RX_MPDU_START_INFO6_EOSP BIT(24) +#define RX_MPDU_START_INFO6_FRAGMENT BIT(25) +#define RX_MPDU_START_INFO6_ORDER BIT(26) +#define RX_MPDU_START_INFO6_UAPSD_TRIGGER BIT(27) +#define RX_MPDU_START_INFO6_ENCRYPT_REQUIRED BIT(28) +#define RX_MPDU_START_INFO6_DIRECTED BIT(29) +#define RX_MPDU_START_INFO6_AMSDU_PRESENT BIT(30) + +#define RX_MPDU_START_INFO7_VDEV_ID GENMASK(7, 0) +#define RX_MPDU_START_INFO7_SERVICE_CODE GENMASK(16, 8) +#define RX_MPDU_START_INFO7_PRIORITY_VALID BIT(17) +#define RX_MPDU_START_INFO7_SRC_INFO GENMASK(29, 18) + +#define RX_MPDU_START_INFO8_AUTH_TO_SEND_WDS BIT(0) + +struct rx_mpdu_start_qcn9274 { +__le32 info0; +__le32 reo_queue_desc_lo; +__le32 info1; +__le32 pn[4 ]; +__le32 info2; +__le32 peer_meta_data; +__le16 info3; +__le16 phy_ppdu_id; +__le16 ast_index; +__le16 sw_peer_id; +__le32 info4; +__le32 info5; +__le32 info6; +__le16 frame_ctrl; +__le16 duration; +u8 addr1[ETH_ALEN ]; +u8 addr2[ETH_ALEN ]; +u8 addr3[ETH_ALEN ]; +__le16 seq_ctrl; +u8 addr4[ETH_ALEN ]; +__le16 qos_ctrl; +__le32 ht_ctrl; +__le32 info7; +u8 multi_link_addr1[ETH_ALEN ]; +u8 multi_link_addr2[ETH_ALEN ]; +__le32 info8; +__le32 res0; +__le32 res1; +} __packed; + +/* rx_mpdu_start +* +* reo_destination_indication +* The id of the reo exit ring where the msdu frame shall push +* after (MPDU level) reordering has finished. Values are defined +* in enum %HAL_RX_MSDU_DESC_REO_DEST_IND_. +* +* lmac_peer_id_msb +* +* If use_flow_id_toeplitz_clfy is set and lmac_peer_id_'sb +* is 2'b00, Rx OLE uses a REO destination indicati'n of {1'b1, +* hash[3:0]} using the chosen Toeplitz hash from Common Parser +* if flow search fails. +* If use_flow_id_toeplitz_clfy is set and lmac_peer_id_msb +* 's not 2'b00, Rx OLE uses a REO destination indication of +* {lmac_peer_id_msb, hash[2:0]} using the chosen Toeplitz +* hash from Common Parser if flow search fails. +* +* use_flow_id_toeplitz_clfy +* Indication to Rx OLE to enable REO destination routing based +* on the chosen Toeplitz hash from Common Parser, in case +* flow search fails +* +* pkt_selection_fp_ucast_data +* Filter pass Unicast data frame (matching rxpcu_filter_pass +* and sw_frame_group_Unicast_data) routing selection +* +* pkt_selection_fp_mcast_data +* Filter pass Multicast data frame (matching rxpcu_filter_pass +* and sw_frame_group_Multicast_data) routing selection +* +* pkt_selection_fp_ctrl_bar +* Filter pass BAR frame (matching rxpcu_filter_pass +* and sw_frame_group_ctrl_1000) routing selection +* +* rxdma0_src_ring_selection +* Field only valid when for the received frame type the corresponding +* pkt_selection_fp_... bit is set +* +* rxdma0_dst_ring_selection +* Field only valid when for the received frame type the corresponding +* pkt_selection_fp_... bit is set +* +* mcast_echo_drop_enable +* If set, for multicast packets, multicast echo check (i.e. +* SA search with mcast_echo_check = 1) shall be performed +* by RXOLE, and any multicast echo packets should be indicated +* to RXDMA for release to WBM +* +* wds_learning_detect_en +* If set, WDS learning detection based on SA search and notification +* to FW (using RXDMA0 status ring) is enabled and the "timestamp" +* field in address search failure cache-only entry should +* be used to avoid multiple WDS learning notifications. +* +* intrabss_check_en +* If set, intra-BSS routing detection is enabled +* +* use_ppe +* Indicates to RXDMA to ignore the REO_destination_indication +* and use a programmed value corresponding to the REO2PPE +* ring +* This override to REO2PPE for packets requiring multiple +* buffers shall be disabled based on an RXDMA configuration, +* as PPE may not support such packets. +* +* Supported only in full AP chips, not in client/soft +* chips +* +* ppe_routing_enable +* Global enable/disable bit for routing to PPE, used to disable +* PPE routing even if RXOLE CCE or flow search indicate 'Use_PPE' +* This is set by SW for peers which are being handled by a +* host SW/accelerator subsystem that also handles packet +* uffer management for WiFi-to-PPE routing. +* +* This is cleared by SW for peers which are being handled +* by a different subsystem, completely disabling WiFi-to-PPE +* routing for such peers. +* +* rx_reo_queue_desc_addr_lo +* Address (lower 32 bits) of the REO queue descriptor. +* +* rx_reo_queue_desc_addr_hi +* Address (upper 8 bits) of the REO queue descriptor. +* +* receive_queue_number +* Indicates the MPDU queue ID to which this MPDU link +* descriptor belongs. +* +* pre_delim_err_warning +* Indicates that a delimiter FCS error was found in between the +* previous MPDU and this MPDU. Note that this is just a warning, +* and does not mean that this MPDU is corrupted in any way. If +* it is, there will be other errors indicated such as FCS or +* decrypt errors. +* +* first_delim_err +* Indicates that the first delimiter had a FCS failure. +* +* pn +* The PN number. +* +* epd_en +* Field only valid when AST_based_lookup_valid == 1. +* In case of ndp or phy_err or AST_based_lookup_valid == 0, +* this field will be set to 0 +* If set to one use EPD instead of LPD +* In case of ndp or phy_err, this field will never be set. +* +* all_frames_shall_be_encrypted +* In case of ndp or phy_err or AST_based_lookup_valid == 0, +* this field will be set to 0 +* +* When set, all frames (data only ?) shall be encrypted. If +* not, RX CRYPTO shall set an error flag. +* +* +* encrypt_type +* In case of ndp or phy_err or AST_based_lookup_valid == 0, +* this field will be set to 0 +* +* Indicates type of decrypt cipher used (as defined in the +* peer entry) +* +* wep_key_width_for_variable_key +* +* Field only valid when key_type is set to wep_varied_width. +* +* mesh_sta +* +* bssid_hit +* When set, the BSSID of the incoming frame matched one of +* the 8 BSSID register values +* bssid_number +* Field only valid when bssid_hit is set. +* This number indicates which one out of the 8 BSSID register +* values matched the incoming frame +* +* tid +* Field only valid when mpdu_qos_control_valid is set +* The TID field in the QoS control field +* +* peer_meta_data +* Meta data that SW has programmed in the Peer table entry +* of the transmitting STA. +* +* rxpcu_mpdu_filter_in_category +* Field indicates what the reason was that this mpdu frame +* was allowed to come into the receive path by rxpcu. Values +* are defined in enum %RX_DESC_RXPCU_FILTER_*. +* +* sw_frame_group_id +* SW processes frames based on certain classifications. Values +* are defined in enum %RX_DESC_SW_FRAME_GRP_ID_*. +* +* ndp_frame +* When set, the received frame was an NDP frame, and thus +* there will be no MPDU data. +* phy_err +* When set, a PHY error was received before MAC received any +* data, and thus there will be no MPDU data. +* +* phy_err_during_mpdu_header +* When set, a PHY error was received before MAC received the +* complete MPDU header which was needed for proper decoding +* +* protocol_version_err +* Set when RXPCU detected a version error in the Frame control +* field +* +* ast_based_lookup_valid +* When set, AST based lookup for this frame has found a valid +* result. +* +* ranging +* When set, a ranging NDPA or a ranging NDP was received. +* +* phy_ppdu_id +* A ppdu counter value that PHY increments for every PPDU +* received. The counter value wraps around. +* +* ast_index +* +* This field indicates the index of the AST entry corresponding +* to this MPDU. It is provided by the GSE module instantiated +* in RXPCU. +* A value of 0xFFFF indicates an invalid AST index, meaning +* that No AST entry was found or NO AST search was performed +* +* sw_peer_id +* In case of ndp or phy_err or AST_based_lookup_valid == 0, +* this field will be set to 0 +* This field indicates a unique peer identifier. It is set +* equal to field 'sw_peer_id' from the AST entry +* +* frame_control_valid +* When set, the field Mpdu_Frame_control_field has valid information +* +* frame_duration_valid +* When set, the field Mpdu_duration_field has valid information +* +* mac_addr_ad1..4_valid +* When set, the fields mac_addr_adx_..... have valid information +* +* mpdu_seq_ctrl_valid +* +* When set, the fields mpdu_sequence_control_field and mpdu_sequence_number +* have valid information as well as field +* For MPDUs without a sequence control field, this field will +* not be set. +* +* mpdu_qos_ctrl_valid, mpdu_ht_ctrl_valid +* +* When set, the field mpdu_qos_control_field, mpdu_ht_control has valid +* information, For MPDUs without a QoS,HT control field, this field +* will not be set. +* +* frame_encryption_info_valid +* +* When set, the encryption related info fields, like IV and +* PN are valid +* For MPDUs that are not encrypted, this will not be set. +* +* mpdu_fragment_number +* +* Field only valid when Mpdu_sequence_control_valid is set +* AND Fragment_flag is set. The fragment number from the 802.11 header +* +* more_fragment_flag +* +* The More Fragment bit setting from the MPDU header of the +* received frame +* +* fr_ds +* +* Field only valid when Mpdu_frame_control_valid is set +* Set if the from DS bit is set in the frame control. +* +* to_ds +* +* Field only valid when Mpdu_frame_control_valid is set +* Set if the to DS bit is set in the frame control. +* +* encrypted +* +* Field only valid when Mpdu_frame_control_valid is set. +* Protected bit from the frame control. +* +* mpdu_retry +* Field only valid when Mpdu_frame_control_valid is set. +* Retry bit from the frame control. Only valid when first_msdu is set +* +* mpdu_sequence_number +* Field only valid when Mpdu_sequence_control_valid is set. +* +* The sequence number from the 802.11 header. +* key_id +* The key ID octet from the IV. +* Field only valid when Frame_encryption_info_valid is set +* +* new_peer_entry +* Set if new RX_PEER_ENTRY TLV follows. If clear, RX_PEER_ENTRY +* doesn't follow so RX DECRYPTION module either uses old peer +* entry or not decrypt. +* +* decrypt_needed +* When RXPCU sets bit 'ast_index_not_found or ast_index_timeout', +* RXPCU will also ensure that this bit is NOT set. CRYPTO for that +* reason only needs to evaluate this bit and non of the other ones +* +* decap_type +* Used by the OLE during decapsulation. Values are defined in +* enum %MPDU_START_DECAP_TYPE_*. +* +* rx_insert_vlan_c_tag_padding +* rx_insert_vlan_s_tag_padding +* Insert 4 byte of all zeros as VLAN tag or double VLAN tag if +* the rx payload does not have VLAN. +* +* strip_vlan_c_tag_decap +* strip_vlan_s_tag_decap +* Strip VLAN or double VLAN during decapsulation. +* +* pre_delim_count +* The number of delimiters before this MPDU. Note that this +* number is cleared at PPDU start. If this MPDU is the first +* received MPDU in the PPDU and this MPDU gets filtered-in, +* this field will indicate the number of delimiters located +* after the last MPDU in the previous PPDU. +* +* If this MPDU is located after the first received MPDU in +* an PPDU, this field will indicate the number of delimiters +* located between the previous MPDU and this MPDU. +* +* ampdu_flag +* Received frame was part of an A-MPDU. +* +* bar_frame +* Received frame is a BAR frame +* +* raw_mpdu +* Set when no 802.11 to nwifi/ethernet hdr conversion is done +* +* mpdu_length +* MPDU length before decapsulation. +* +* first_mpdu +* Indicates the first MSDU of the PPDU. If both first_mpdu +* and last_mpdu are set in the MSDU then this is a not an +* A-MPDU frame but a stand alone MPDU. Interior MPDU in an +* A-MPDU shall have both first_mpdu and last_mpdu bits set to +* 0. The PPDU start status will only be valid when this bit +* is set. +* +* mcast_bcast +* Multicast / broadcast indicator. Only set when the MAC +* address 1 bit 0 is set indicating mcast/bcast and the BSSID +* matches one of the 4 BSSID registers. Only set when +* first_msdu is set. +* +* ast_index_not_found +* Only valid when first_msdu is set. Indicates no AST matching +* entries within the max search count. +* +* ast_index_timeout +* Only valid when first_msdu is set. Indicates an unsuccessful +* search in the address search table due to timeout. +* +* power_mgmt +* Power management bit set in the 802.11 header. Only set +* when first_msdu is set. +* +* non_qos +* Set if packet is not a non-QoS data frame. Only set when +* first_msdu is set. +* +* null_data +* Set if frame type indicates either null data or QoS null +* data format. Only set when first_msdu is set. +* +* mgmt_type +* Set if packet is a management packet. Only set when +* first_msdu is set. +* +* ctrl_type +* Set if packet is a control packet. Only set when first_msdu +* is set. +* +* more_data +* Set if more bit in frame control is set. Only set when +* first_msdu is set. +* +* eosp +* Set if the EOSP (end of service period) bit in the QoS +* control field is set. Only set when first_msdu is set. +* +* +* fragment_flag +* Fragment indication +* +* order +* Set if the order bit in the frame control is set. Only +* set when first_msdu is set. +* +* u_apsd_trigger +* U-APSD trigger frame +* +* encrypt_required +* Indicates that this data type frame is not encrypted even if +* the policy for this MPDU requires encryption as indicated in +* the peer table key type. +* +* directed +* MPDU is a directed packet which means that the RA matched +* our STA addresses. In proxySTA it means that the TA matched +* an entry in our address search table with the corresponding +* 'no_ack' bit is the address search entry cleared. +* amsdu_present +* AMSDU present +* +* mpdu_frame_control_field +* Frame control field in header. Only valid when the field is marked valid. +* +* mpdu_duration_field +* Duration field in header. Only valid when the field is marked valid. +* +* mac_addr_adx +* MAC addresses in the received frame. Only valid when corresponding +* address valid bit is set +* +* mpdu_qos_control_field, mpdu_ht_control_field +* QoS/HT control fields from header. Valid only when corresponding fields +* are marked valid +* +* vdev_id +* Virtual device associated with this peer +* RXOLE uses this to determine intra-BSS routing. +* +* service_code +* Opaque service code between PPE and Wi-Fi +* This field gets passed on by REO to PPE in the EDMA descriptor +* ('REO_TO_PPE_RING'). +* +* priority_valid +* This field gets passed on by REO to PPE in the EDMA descriptor +* ('REO_TO_PPE_RING'). +* +* src_info +* Source (virtual) device/interface info. associated with +* this peer +* This field gets passed on by REO to PPE in the EDMA descriptor +* ('REO_TO_PPE_RING'). +* +* multi_link_addr_ad1_ad2_valid +* If set, Rx OLE shall convert Address1 and Address2 of received +* data frames to multi-link addresses during decapsulation to eth/nwifi +* +* multi_link_addr_ad1,ad2 +* Multi-link receiver address1,2. Only valid when corresponding +* valid bit is set +* +* authorize_to_send_wds +* If not set, RXDMA shall perform error-routing for WDS packets +* as the sender is not authorized and might misuse WDS frame +* format to inject packets with arbitrary DA/SA. +* +*/ + +enum rx_msdu_start_pkt_type { +RX_MSDU_START_PKT_TYPE_11A , +RX_MSDU_START_PKT_TYPE_11B , +RX_MSDU_START_PKT_TYPE_11N , +RX_MSDU_START_PKT_TYPE_11AC , +RX_MSDU_START_PKT_TYPE_11AX , +}; + +enum rx_msdu_start_sgi { +RX_MSDU_START_SGI_0_8_US , +RX_MSDU_START_SGI_0_4_US , +RX_MSDU_START_SGI_1_6_US , +RX_MSDU_START_SGI_3_2_US , +}; + +enum rx_msdu_start_recv_bw { +RX_MSDU_START_RECV_BW_20MHZ , +RX_MSDU_START_RECV_BW_40MHZ , +RX_MSDU_START_RECV_BW_80MHZ , +RX_MSDU_START_RECV_BW_160MHZ , +}; + +enum rx_msdu_start_reception_type { +RX_MSDU_START_RECEPTION_TYPE_SU , +RX_MSDU_START_RECEPTION_TYPE_DL_MU_MIMO , +RX_MSDU_START_RECEPTION_TYPE_DL_MU_OFDMA , +RX_MSDU_START_RECEPTION_TYPE_DL_MU_OFDMA_MIMO , +RX_MSDU_START_RECEPTION_TYPE_UL_MU_MIMO , +RX_MSDU_START_RECEPTION_TYPE_UL_MU_OFDMA , +RX_MSDU_START_RECEPTION_TYPE_UL_MU_OFDMA_MIMO , +}; + +#define RX_MSDU_END_INFO0_RXPCU_MPDU_FITLER GENMASK(1, 0) +#define RX_MSDU_END_INFO0_SW_FRAME_GRP_ID GENMASK(8, 2) + +#define RX_MSDU_END_INFO1_REPORTED_MPDU_LENGTH GENMASK(13, 0) + +#define RX_MSDU_END_INFO2_CCE_SUPER_RULE GENMASK(13, 8) +#define RX_MSDU_END_INFO2_CCND_TRUNCATE BIT(14) +#define RX_MSDU_END_INFO2_CCND_CCE_DIS BIT(15) + +#define RX_MSDU_END_INFO3_DA_OFFSET GENMASK(5, 0) +#define RX_MSDU_END_INFO3_SA_OFFSET GENMASK(11, 6) +#define RX_MSDU_END_INFO3_DA_OFFSET_VALID BIT(12) +#define RX_MSDU_END_INFO3_SA_OFFSET_VALID BIT(13) + +#define RX_MSDU_END_INFO4_TCP_FLAG GENMASK(8, 0) +#define RX_MSDU_END_INFO4_LRO_ELIGIBLE BIT(9) + +#define RX_MSDU_END_INFO5_SA_IDX_TIMEOUT BIT(0) +#define RX_MSDU_END_INFO5_DA_IDX_TIMEOUT BIT(1) +#define RX_MSDU_END_INFO5_TO_DS BIT(2) +#define RX_MSDU_END_INFO5_TID GENMASK(6, 3) +#define RX_MSDU_END_INFO5_SA_IS_VALID BIT(7) +#define RX_MSDU_END_INFO5_DA_IS_VALID BIT(8) +#define RX_MSDU_END_INFO5_DA_IS_MCBC BIT(9) +#define RX_MSDU_END_INFO5_L3_HDR_PADDING GENMASK(11, 10) +#define RX_MSDU_END_INFO5_FIRST_MSDU BIT(12) +#define RX_MSDU_END_INFO5_LAST_MSDU BIT(13) +#define RX_MSDU_END_INFO5_FROM_DS BIT(14) +#define RX_MSDU_END_INFO5_IP_CHKSUM_FAIL_COPY BIT(15) + +#define RX_MSDU_END_INFO6_MSDU_DROP BIT(0) +#define RX_MSDU_END_INFO6_REO_DEST_IND GENMASK(5, 1) +#define RX_MSDU_END_INFO6_FLOW_IDX GENMASK(25, 6) +#define RX_MSDU_END_INFO6_USE_PPE BIT(26) +#define RX_MSDU_END_INFO6_MESH_STA GENMASK(28, 27) +#define RX_MSDU_END_INFO6_VLAN_CTAG_STRIPPED BIT(29) +#define RX_MSDU_END_INFO6_VLAN_STAG_STRIPPED BIT(30) +#define RX_MSDU_END_INFO6_FRAGMENT_FLAG BIT(31) + +#define RX_MSDU_END_INFO7_AGGR_COUNT GENMASK(7, 0) +#define RX_MSDU_END_INFO7_FLOW_AGGR_CONTN BIT(8) +#define RX_MSDU_END_INFO7_FISA_TIMEOUT BIT(9) +#define RX_MSDU_END_INFO7_TCPUDP_CSUM_FAIL_CPY BIT(10) +#define RX_MSDU_END_INFO7_MSDU_LIMIT_ERROR BIT(11) +#define RX_MSDU_END_INFO7_FLOW_IDX_TIMEOUT BIT(12) +#define RX_MSDU_END_INFO7_FLOW_IDX_INVALID BIT(13) +#define RX_MSDU_END_INFO7_CCE_MATCH BIT(14) +#define RX_MSDU_END_INFO7_AMSDU_PARSER_ERR BIT(15) + +#define RX_MSDU_END_INFO8_KEY_ID GENMASK(7, 0) + +#define RX_MSDU_END_INFO9_SERVICE_CODE GENMASK(14, 6) +#define RX_MSDU_END_INFO9_PRIORITY_VALID BIT(15) +#define RX_MSDU_END_INFO9_INRA_BSS BIT(16) +#define RX_MSDU_END_INFO9_DEST_CHIP_ID GENMASK(18, 17) +#define RX_MSDU_END_INFO9_MCAST_ECHO BIT(19) +#define RX_MSDU_END_INFO9_WDS_LEARN_EVENT BIT(20) +#define RX_MSDU_END_INFO9_WDS_ROAM_EVENT BIT(21) +#define RX_MSDU_END_INFO9_WDS_KEEP_ALIVE_EVENT BIT(22) + +#define RX_MSDU_END_INFO10_MSDU_LENGTH GENMASK(13, 0) +#define RX_MSDU_END_INFO10_STBC BIT(14) +#define RX_MSDU_END_INFO10_IPSEC_ESP BIT(15) +#define RX_MSDU_END_INFO10_L3_OFFSET GENMASK(22, 16) +#define RX_MSDU_END_INFO10_IPSEC_AH BIT(23) +#define RX_MSDU_END_INFO10_L4_OFFSET GENMASK(31, 24) + +#define RX_MSDU_END_INFO11_MSDU_NUMBER GENMASK(7, 0) +#define RX_MSDU_END_INFO11_DECAP_FORMAT GENMASK(9, 8) +#define RX_MSDU_END_INFO11_IPV4 BIT(10) +#define RX_MSDU_END_INFO11_IPV6 BIT(11) +#define RX_MSDU_END_INFO11_TCP BIT(12) +#define RX_MSDU_END_INFO11_UDP BIT(13) +#define RX_MSDU_END_INFO11_IP_FRAG BIT(14) +#define RX_MSDU_END_INFO11_TCP_ONLY_ACK BIT(15) +#define RX_MSDU_END_INFO11_DA_IS_BCAST_MCAST BIT(16) +#define RX_MSDU_END_INFO11_SEL_TOEPLITZ_HASH GENMASK(18, 17) +#define RX_MSDU_END_INFO11_IP_FIXED_HDR_VALID BIT(19) +#define RX_MSDU_END_INFO11_IP_EXTN_HDR_VALID BIT(20) +#define RX_MSDU_END_INFO11_IP_TCP_UDP_HDR_VALID BIT(21) +#define RX_MSDU_END_INFO11_MESH_CTRL_PRESENT BIT(22) +#define RX_MSDU_END_INFO11_LDPC BIT(23) +#define RX_MSDU_END_INFO11_IP4_IP6_NXT_HDR GENMASK(31, 24) + +#define RX_MSDU_END_INFO12_USER_RSSI GENMASK(7, 0) +#define RX_MSDU_END_INFO12_PKT_TYPE GENMASK(11, 8) +#define RX_MSDU_END_INFO12_SGI GENMASK(13, 12) +#define RX_MSDU_END_INFO12_RATE_MCS GENMASK(17, 14) +#define RX_MSDU_END_INFO12_RECV_BW GENMASK(20, 18) +#define RX_MSDU_END_INFO12_RECEPTION_TYPE GENMASK(23, 21) +#define RX_MSDU_END_INFO12_MIMO_SS_BITMAP GENMASK(30, 24) +#define RX_MSDU_END_INFO12_MIMO_DONE_COPY BIT(31) + +#define RX_MSDU_END_INFO13_FIRST_MPDU BIT(0) +#define RX_MSDU_END_INFO13_MCAST_BCAST BIT(2) +#define RX_MSDU_END_INFO13_AST_IDX_NOT_FOUND BIT(3) +#define RX_MSDU_END_INFO13_AST_IDX_TIMEDOUT BIT(4) +#define RX_MSDU_END_INFO13_POWER_MGMT BIT(5) +#define RX_MSDU_END_INFO13_NON_QOS BIT(6) +#define RX_MSDU_END_INFO13_NULL_DATA BIT(7) +#define RX_MSDU_END_INFO13_MGMT_TYPE BIT(8) +#define RX_MSDU_END_INFO13_CTRL_TYPE BIT(9) +#define RX_MSDU_END_INFO13_MORE_DATA BIT(10) +#define RX_MSDU_END_INFO13_EOSP BIT(11) +#define RX_MSDU_END_INFO13_A_MSDU_ERROR BIT(12) +#define RX_MSDU_END_INFO13_ORDER BIT(14) +#define RX_MSDU_END_INFO13_WIFI_PARSER_ERR BIT(15) +#define RX_MSDU_END_INFO13_OVERFLOW_ERR BIT(16) +#define RX_MSDU_END_INFO13_MSDU_LEN_ERR BIT(17) +#define RX_MSDU_END_INFO13_TCP_UDP_CKSUM_FAIL BIT(18) +#define RX_MSDU_END_INFO13_IP_CKSUM_FAIL BIT(19) +#define RX_MSDU_END_INFO13_SA_IDX_INVALID BIT(20) +#define RX_MSDU_END_INFO13_DA_IDX_INVALID BIT(21) +#define RX_MSDU_END_INFO13_AMSDU_ADDR_MISMATCH BIT(22) +#define RX_MSDU_END_INFO13_RX_IN_TX_DECRYPT_BYP BIT(23) +#define RX_MSDU_END_INFO13_ENCRYPT_REQUIRED BIT(24) +#define RX_MSDU_END_INFO13_DIRECTED BIT(25) +#define RX_MSDU_END_INFO13_BUFFER_FRAGMENT BIT(26) +#define RX_MSDU_END_INFO13_MPDU_LEN_ERR BIT(27) +#define RX_MSDU_END_INFO13_TKIP_MIC_ERR BIT(28) +#define RX_MSDU_END_INFO13_DECRYPT_ERR BIT(29) +#define RX_MSDU_END_INFO13_UNDECRYPT_FRAME_ERR BIT(30) +#define RX_MSDU_END_INFO13_FCS_ERR BIT(31) + +#define RX_MSDU_END_INFO14_DECRYPT_STATUS_CODE GENMASK(12, 10) +#define RX_MSDU_END_INFO14_RX_BITMAP_NOT_UPDED BIT(13) +#define RX_MSDU_END_INFO14_MSDU_DONE BIT(31) + +struct rx_msdu_end_qcn9274 { +__le16 info0; +__le16 phy_ppdu_id; +__le16 ip_hdr_cksum; +__le16 info1; +__le16 info2; +__le16 cumulative_l3_checksum; +__le32 rule_indication0; +__le32 ipv6_options_crc; +__le16 info3; +__le16 l3_type; +__le32 rule_indication1; +__le32 tcp_seq_num; +__le32 tcp_ack_num; +__le16 info4; +__le16 window_size; +__le16 sa_sw_peer_id; +__le16 info5; +__le16 sa_idx; +__le16 da_idx_or_sw_peer_id; +__le32 info6; +__le32 fse_metadata; +__le16 cce_metadata; +__le16 tcp_udp_cksum; +__le16 info7; +__le16 cumulative_ip_length; +__le32 info8; +__le32 info9; +__le32 info10; +__le32 info11; +__le16 vlan_ctag_ci; +__le16 vlan_stag_ci; +__le32 peer_meta_data; +__le32 info12; +__le32 flow_id_toeplitz; +__le32 ppdu_start_timestamp_63_32; +__le32 phy_meta_data; +__le32 ppdu_start_timestamp_31_0; +__le32 toeplitz_hash_2_or_4; +__le16 res0; +__le16 sa_15_0; +__le32 sa_47_16; +__le32 info13; +__le32 info14; +} __packed; + +/* rx_msdu_end +* +* rxpcu_mpdu_filter_in_category +* Field indicates what the reason was that this mpdu frame +* was allowed to come into the receive path by rxpcu. Values +* are defined in enum %RX_DESC_RXPCU_FILTER_*. +* +* sw_frame_group_id +* SW processes frames based on certain classifications. Values +* are defined in enum %RX_DESC_SW_FRAME_GRP_ID_*. +* +* phy_ppdu_id +* A ppdu counter value that PHY increments for every PPDU +* received. The counter value wraps around. +* +* ip_hdr_cksum +* This can include the IP header checksum or the pseudo +* header checksum used by TCP/UDP checksum. +* +* reported_mpdu_length +* MPDU length before decapsulation. Only valid when first_msdu is +* set. This field is taken directly from the length field of the +* A-MPDU delimiter or the preamble length field for non-A-MPDU +* frames. +* +* cce_super_rule +* Indicates the super filter rule. +* +* cce_classify_not_done_truncate +* Classification failed due to truncated frame. +* +* cce_classify_not_done_cce_dis +* Classification failed due to CCE global disable +* +* cumulative_l3_checksum +* FISA: IP header checksum including the total MSDU length +* that is part of this flow aggregated so far, reported if +* 'RXOLE_R0_FISA_CTRL. CHKSUM_CUM_IP_LEN_EN' is set +* +* rule_indication +* Bitmap indicating which of rules have matched. +* +* ipv6_options_crc +* 32 bit CRC computed out of IP v6 extension headers. +* +* da_offset +* Offset into MSDU buffer for DA. +* +* sa_offset +* Offset into MSDU buffer for SA. +* +* da_offset_valid +* da_offset field is valid. This will be set to 0 in case +* of a dynamic A-MSDU when DA is compressed. +* +* sa_offset_valid +* sa_offset field is valid. This will be set to 0 in case +* of a dynamic A-MSDU when SA is compressed. +* +* l3_type +* The 16-bit type value indicating the type of L3 later +* extracted from LLC/SNAP, set to zero if SNAP is not +* available. +* +* tcp_seq_number +* TCP sequence number. +* +* tcp_ack_number +* TCP acknowledge number. +* +* tcp_flag +* TCP flags {NS, CWR, ECE, URG, ACK, PSH, RST, SYN, FIN}. +* +* lro_eligible +* Computed out of TCP and IP fields to indicate that this +* MSDU is eligible for LRO. +* +* window_size +* TCP receive window size. +* +* sa_sw_peer_id +* sw_peer_id from the address search entry corresponding to the +* source address of the MSDU. +* +* sa_idx_timeout +* Indicates an unsuccessful MAC source address search due to the +* expiring of the search timer. +* +* da_idx_timeout +* Indicates an unsuccessful MAC destination address search due to +* the expiring of the search timer. +* +* to_ds +* Set if the to DS bit is set in the frame control. +* +* tid +* TID field in the QoS control field +* +* sa_is_valid +* Indicates that OLE found a valid SA entry. +* +* da_is_valid +* Indicates that OLE found a valid DA entry. +* +* da_is_mcbc +* Field Only valid if da_is_valid is set. Indicates the DA address +* was a Multicast of Broadcast address. +* +* l3_header_padding +* Number of bytes padded to make sure that the L3 header will +* always start of a Dword boundary. +* +* first_msdu +* Indicates the first MSDU of A-MSDU. If both first_msdu and +* last_msdu are set in the MSDU then this is a non-aggregated MSDU +* frame: normal MPDU. Interior MSDU in an A-MSDU shall have both +* first_mpdu and last_mpdu bits set to 0. +* +* last_msdu +* Indicates the last MSDU of the A-MSDU. MPDU end status is only +* valid when last_msdu is set. +* +* fr_ds +* Set if the from DS bit is set in the frame control. +* +* ip_chksum_fail_copy +* Indicates that the computed checksum did not match the +* checksum in the IP header. +* +* sa_idx +* The offset in the address table which matches the MAC source +* address. +* +* da_idx_or_sw_peer_id +* Based on a register configuration in RXOLE, this field will +* contain: +* The offset in the address table which matches the MAC destination +* address +* OR: +* sw_peer_id from the address search entry corresponding to +* the destination address of the MSDU +* +* msdu_drop +* REO shall drop this MSDU and not forward it to any other ring. +* +* The id of the reo exit ring where the msdu frame shall push +* after (MPDU level) reordering has finished. Values are defined +* in enum %HAL_RX_MSDU_DESC_REO_DEST_IND_. +* +* flow_idx +* Flow table index. +* +* use_ppe +* Indicates to RXDMA to ignore the REO_destination_indication +* and use a programmed value corresponding to the REO2PPE +* ring +* +* mesh_sta +* When set, this is a Mesh (11s) STA. +* +* vlan_ctag_stripped +* Set by RXOLE if it stripped 4-bytes of C-VLAN Tag from the +* packet +* +* vlan_stag_stripped +* Set by RXOLE if it stripped 4-bytes of S-VLAN Tag from the +* packet +* +* fragment_flag +* Indicates that this is an 802.11 fragment frame. This is +* set when either the more_frag bit is set in the frame control +* or the fragment number is not zero. Only set when first_msdu +* is set. +* +* fse_metadata +* FSE related meta data. +* +* cce_metadata +* CCE related meta data. +* +* tcp_udp_chksum +* The value of the computed TCP/UDP checksum. A mode bit +* selects whether this checksum is the full checksum or the +* partial checksum which does not include the pseudo header. +* +* aggregation_count +* Number of MSDU's aggregated so far +* +* flow_aggregation_continuation +* To indicate that this MSDU can be aggregated with +* the previous packet with the same flow id +* +* fisa_timeout +* To indicate that the aggregation has restarted for +* this flow due to timeout +* +* tcp_udp_chksum_fail +* Indicates that the computed checksum (tcp_udp_chksum) did +* not match the checksum in the TCP/UDP header. +* +* msdu_limit_error +* Indicates that the MSDU threshold was exceeded and thus all the +* rest of the MSDUs will not be scattered and will not be +* decapsulated but will be DMA'ed in RAW format as a single MSDU. +* +* flow_idx_timeout +* Indicates an unsuccessful flow search due to the expiring of +* the search timer. +* +* flow_idx_invalid +* flow id is not valid. +* +* cce_match +* Indicates that this status has a corresponding MSDU that +* requires FW processing. The OLE will have classification +* ring mask registers which will indicate the ring(s) for +* packets and descriptors which need FW attention. +* +* amsdu_parser_error +* A-MSDU could not be properly de-agregated. +* +* cumulative_ip_length +* Total MSDU length that is part of this flow aggregated +* so far +* +* key_id +* The key ID octet from the IV. Only valid when first_msdu is set. +* +* service_code +* Opaque service code between PPE and Wi-Fi +* +* priority_valid +* This field gets passed on by REO to PPE in the EDMA descriptor +* +* intra_bss +* This packet needs intra-BSS routing by SW as the 'vdev_id' +* for the destination is the same as 'vdev_id' (from 'RX_MPDU_PCU_START') +* that this MSDU was got in. +* +* dest_chip_id +* If intra_bss is set, copied by RXOLE from 'ADDR_SEARCH_ENTRY' +* to support intra-BSS routing with multi-chip multi-link +* operation. This indicates into which chip's TCL the packet should be +* queueued +* +* multicast_echo +* If set, this packet is a multicast echo, i.e. the DA is +* multicast and Rx OLE SA search with mcast_echo_check = 1 +* passed. RXDMA should release such packets to WBM. +* +* wds_learning_event +* If set, this packet has an SA search failure with WDS learning +* enabled for the peer. RXOLE should route this TLV to the +* RXDMA0 status ring to notify FW. +* +* wds_roaming_event +* If set, this packet's SA 'Sw_peer_id' mismatches the 'Sw_peer_id' +* of the peer through which the packet was got, indicating +* the SA node has roamed. RXOLE should route this TLV to +* the RXDMA0 status ring to notify FW. +* +* wds_keep_alive_event +* If set, the AST timestamp for this packet's SA is older +* than the current timestamp by more than a threshold programmed +* in RXOLE. RXOLE should route this TLV to the RXDMA0 status +* ring to notify FW to keep the AST entry for the SA alive. +* +* msdu_length +* MSDU length in bytes after decapsulation. +* This field is still valid for MPDU frames without A-MSDU. +* It still represents MSDU length after decapsulation +* +* stbc +* When set, use STBC transmission rates. +* +* ipsec_esp +* Set if IPv4/v6 packet is using IPsec ESP. +* +* l3_offset +* Depending upon mode bit, this field either indicates the +* L3 offset in bytes from the start of the RX_HEADER or the IP +* offset in bytes from the start of the packet after +* decapsulation. The latter is only valid if ipv4_proto or +* ipv6_proto is set. +* +* ipsec_ah +* Set if IPv4/v6 packet is using IPsec AH +* +* l4_offset +* Depending upon mode bit, this field either indicates the +* L4 offset nin bytes from the start of RX_HEADER (only valid +* if either ipv4_proto or ipv6_proto is set to 1) or indicates +* the offset in bytes to the start of TCP or UDP header from +* the start of the IP header after decapsulation (Only valid if +* tcp_proto or udp_proto is set). The value 0 indicates that +* the offset is longer than 127 bytes. +* +* msdu_number +* Indicates the MSDU number within a MPDU. This value is +* reset to zero at the start of each MPDU. If the number of +* MSDU exceeds 255 this number will wrap using modulo 256. +* +* decap_type +* Indicates the format after decapsulation. Values are defined in +* enum %MPDU_START_DECAP_TYPE_*. +* +* ipv4_proto +* Set if L2 layer indicates IPv4 protocol. +* +* ipv6_proto +* Set if L2 layer indicates IPv6 protocol. +* +* tcp_proto +* Set if the ipv4_proto or ipv6_proto are set and the IP protocol +* indicates TCP. +* +* udp_proto +* Set if the ipv4_proto or ipv6_proto are set and the IP protocol +* indicates UDP. +* +* ip_frag +* Indicates that either the IP More frag bit is set or IP frag +* number is non-zero. If set indicates that this is a fragmented +* IP packet. +* +* tcp_only_ack +* Set if only the TCP Ack bit is set in the TCP flags and if +* the TCP payload is 0. +* +* da_is_bcast_mcast +* The destination address is broadcast or multicast. +* +* toeplitz_hash +* Actual chosen Hash. +* 0 - Toeplitz hash of 2-tuple (IP source address, IP +* destination address) +* 1 - Toeplitz hash of 4-tuple (IP source address, +* IP destination address, L4 (TCP/UDP) source port, +* L4 (TCP/UDP) destination port) +* 2 - Toeplitz of flow_id +* 3 - Zero is used +* +* ip_fixed_header_valid +* Fixed 20-byte IPv4 header or 40-byte IPv6 header parsed +* fully within first 256 bytes of the packet +* +* ip_extn_header_valid +* IPv6/IPv6 header, including IPv4 options and +* recognizable extension headers parsed fully within first 256 +* bytes of the packet +* +* tcp_udp_header_valid +* Fixed 20-byte TCP (excluding TCP options) or 8-byte UDP +* header parsed fully within first 256 bytes of the packet +* +* mesh_control_present +* When set, this MSDU includes the 'Mesh Control' field +* +* ldpc +* +* ip4_protocol_ip6_next_header +* For IPv4, this is the 8 bit protocol field set). For IPv6 this +* is the 8 bit next_header field. +* +* +* vlan_ctag_ci +* 2 bytes of C-VLAN Tag Control Information from WHO_L2_LLC +* +* vlan_stag_ci +* 2 bytes of S-VLAN Tag Control Information from WHO_L2_LLC +* in case of double VLAN +* +* peer_meta_data +* Meta data that SW has programmed in the Peer table entry +* of the transmitting STA. +* +* user_rssi +* RSSI for this user +* +* pkt_type +* Values are defined in enum %RX_MSDU_START_PKT_TYPE_*. +* +* sgi +* Field only valid when pkt type is HT, VHT or HE. Values are +* defined in enum %RX_MSDU_START_SGI_*. +* +* rate_mcs +* MCS Rate used. +* +* receive_bandwidth +* Full receive Bandwidth. Values are defined in enum +* %RX_MSDU_START_RECV_*. +* +* reception_type +* Indicates what type of reception this is and defined in enum +* %RX_MSDU_START_RECEPTION_TYPE_*. +* +* mimo_ss_bitmap +* Field only valid when +* Reception_type is RX_MSDU_START_RECEPTION_TYPE_DL_MU_MIMO or +* RX_MSDU_START_RECEPTION_TYPE_DL_MU_OFDMA_MIMO. +* +* Bitmap, with each bit indicating if the related spatial +* stream is used for this STA +* +* LSB related to SS 0 +* +* 0 - spatial stream not used for this reception +* 1 - spatial stream used for this reception +* +* msdu_done_copy +* If set indicates that the RX packet data, RX header data, +* RX PPDU start descriptor, RX MPDU start/end descriptor, +* RX MSDU start/end descriptors and RX Attention descriptor +* are all valid. This bit is in the last 64-bit of the descriptor +* expected to be subscribed in future hardware. +* +* flow_id_toeplitz +* Toeplitz hash of 5-tuple +* {IP source address, IP destination address, IP source port, IP +* destination port, L4 protocol} in case of non-IPSec. +* +* In case of IPSec - Toeplitz hash of 4-tuple +* {IP source address, IP destination address, SPI, L4 protocol} +* +* The relevant Toeplitz key registers are provided in RxOLE's +* instance of common parser module. These registers are separate +* from the Toeplitz keys used by ASE/FSE modules inside RxOLE. +* The actual value will be passed on from common parser module +* to RxOLE in one of the WHO_* TLVs. +* +* ppdu_start_timestamp +* Timestamp that indicates when the PPDU that contained this MPDU +* started on the medium. +* +* phy_meta_data +* SW programmed Meta data provided by the PHY. Can be used for SW +* to indicate the channel the device is on. +* +* toeplitz_hash_2_or_4 +* Controlled by multiple RxOLE registers for TCP/UDP over +* IPv4/IPv6 - Either, Toeplitz hash computed over 2-tuple +* IPv4 or IPv6 src/dest addresses is reported; or, Toeplitz +* hash computed over 4-tuple IPv4 or IPv6 src/dest addresses +* and src/dest ports is reported. The Flow_id_toeplitz hash +* can also be reported here. Usually the hash reported here +* is the one used for hash-based REO routing (see use_flow_id_toeplitz_clfy +* in 'RXPT_CLASSIFY_INFO'). +* +* sa +* Source MAC address +* +* first_mpdu +* Indicates the first MSDU of the PPDU. If both first_mpdu +* and last_mpdu are set in the MSDU then this is a not an +* A-MPDU frame but a stand alone MPDU. Interior MPDU in an +* A-MPDU shall have both first_mpdu and last_mpdu bits set to +* 0. The PPDU start status will only be valid when this bit +* is set. +* +* mcast_bcast +* Multicast / broadcast indicator. Only set when the MAC +* address 1 bit 0 is set indicating mcast/bcast and the BSSID +* matches one of the 4 BSSID registers. Only set when +* first_msdu is set. +* +* ast_index_not_found +* Only valid when first_msdu is set. Indicates no AST matching +* entries within the max search count. +* +* ast_index_timeout +* Only valid when first_msdu is set. Indicates an unsuccessful +* search in the address search table due to timeout. +* +* power_mgmt +* Power management bit set in the 802.11 header. Only set +* when first_msdu is set. +* +* non_qos +* Set if packet is not a non-QoS data frame. Only set when +* first_msdu is set. +* +* null_data +* Set if frame type indicates either null data or QoS null +* data format. Only set when first_msdu is set. +* +* mgmt_type +* Set if packet is a management packet. Only set when +* first_msdu is set. +* +* ctrl_type +* Set if packet is a control packet. Only set when first_msdu +* is set. +* +* more_data +* Set if more bit in frame control is set. Only set when +* first_msdu is set. +* +* eosp +* Set if the EOSP (end of service period) bit in the QoS +* control field is set. Only set when first_msdu is set. +* +* a_msdu_error +* Set if number of MSDUs in A-MSDU is above a threshold or if the +* size of the MSDU is invalid. This receive buffer will contain +* all of the remainder of MSDUs in this MPDU w/o decapsulation. +* +* order +* Set if the order bit in the frame control is set. Only +* set when first_msdu is set. +* +* wifi_parser_error +* Indicates that the WiFi frame has one of the following errors +* +* overflow_err +* RXPCU Receive FIFO ran out of space to receive the full MPDU. +* Therefore this MPDU is terminated early and is thus corrupted. +* +* This MPDU will not be ACKed. +* +* RXPCU might still be able to correctly receive the following +* MPDUs in the PPDU if enough fifo space became available in time. +* +* mpdu_length_err +* Set by RXPCU if the expected MPDU length does not correspond +* with the actually received number of bytes in the MPDU. +* +* tcp_udp_chksum_fail +* Indicates that the computed checksum (tcp_udp_chksum) did +* not match the checksum in the TCP/UDP header. +* +* ip_chksum_fail +* Indicates that the computed checksum did not match the +* checksum in the IP header. +* +* sa_idx_invalid +* Indicates no matching entry was found in the address search +* table for the source MAC address. +* +* da_idx_invalid +* Indicates no matching entry was found in the address search +* table for the destination MAC address. +* +* amsdu_addr_mismatch +* Indicates that an A-MSDU with 'from DS = 0' had an SA mismatching +* TA or an A-MDU with 'to DS = 0' had a DA mismatching RA +* +* rx_in_tx_decrypt_byp +* Indicates that RX packet is not decrypted as Crypto is busy +* with TX packet processing. +* +* encrypt_required +* Indicates that this data type frame is not encrypted even if +* the policy for this MPDU requires encryption as indicated in +* the peer table key type. +* +* directed +* MPDU is a directed packet which means that the RA matched +* our STA addresses. In proxySTA it means that the TA matched +* an entry in our address search table with the corresponding +* 'no_ack' bit is the address search entry cleared. +* +* buffer_fragment +* Indicates that at least one of the rx buffers has been +* fragmented. If set the FW should look at the rx_frag_info +* descriptor described below. +* +* mpdu_length_err +* Indicates that the MPDU was pre-maturely terminated +* resulting in a truncated MPDU. Don't trust the MPDU length +* field. +* +* tkip_mic_err +* Indicates that the MPDU Michael integrity check failed +* +* decrypt_err +* Indicates that the MPDU decrypt integrity check failed +* +* fcs_err +* Indicates that the MPDU FCS check failed +* +* flow_idx_timeout +* Indicates an unsuccessful flow search due to the expiring of +* the search timer. +* +* flow_idx_invalid +* flow id is not valid. +* +* decrypt_status_code +* Field provides insight into the decryption performed. Values +* are defined in enum %RX_DESC_DECRYPT_STATUS_CODE_*. +* +* rx_bitmap_not_updated +* Frame is received, but RXPCU could not update the receive bitmap +* due to (temporary) fifo constraints. +* +* msdu_done +* If set indicates that the RX packet data, RX header data, RX +* PPDU start descriptor, RX MPDU start/end descriptor, RX MSDU +* start/end descriptors and RX Attention descriptor are all +* valid. This bit must be in the last octet of the +* descriptor. +* +*/ + +/* TODO: Move to compact TLV approach +* By default these tlv's are not aligned to 128b boundary +* Need to remove unused qwords and make them compact/aligned +*/ +struct hal_rx_desc_qcn9274 { +struct rx_msdu_end_qcn9274 msdu_end; +struct rx_mpdu_start_qcn9274 mpdu_start; +u8 msdu_payload[]; +} __packed; + +#define RX_BE_PADDING0_BYTES 8 +#define RX_BE_PADDING1_BYTES 8 + +#define HAL_RX_BE_PKT_HDR_TLV_LEN 112 + +struct rx_pkt_hdr_tlv { +__le64 tag; +__le64 phy_ppdu_id; +u8 rx_pkt_hdr[HAL_RX_BE_PKT_HDR_TLV_LEN ]; +}; + +struct hal_rx_desc_wcn7850 { +__le64 msdu_end_tag; +struct rx_msdu_end_qcn9274 msdu_end; +u8 rx_padding0[RX_BE_PADDING0_BYTES ]; +__le64 mpdu_start_tag; +struct rx_mpdu_start_qcn9274 mpdu_start; +struct rx_pkt_hdr_tlv pkt_hdr_tlv; +u8 msdu_payload[]; +}; + +struct hal_rx_desc { +union { +struct hal_rx_desc_qcn9274 qcn9274; +struct hal_rx_desc_wcn7850 wcn7850; + } u; +} __packed; + +#define MAX_USER_POS 8 +#define MAX_MU_GROUP_ID 64 +#define MAX_MU_GROUP_SHOW 16 +#define MAX_MU_GROUP_LENGTH (6 * MAX_MU_GROUP_SHOW) + +#define HAL_RX_RU_ALLOC_TYPE_MAX 6 +#define RU_26 1 +#define RU_52 2 +#define RU_106 4 +#define RU_242 9 +#define RU_484 18 +#define RU_996 37 + +#endif /* ATH12K_RX_DESC_H */
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k
PATCH v2 45/50 wifi: ath12k: add trace.h
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
(Patches split into one patch per file for easier review, but the final commit will be one big patch. See the cover letter for more info.)
--- drivers/net/wireless/ath/ath12k/trace.h | 152 ++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+)
drivers/net/wireless/ath/ath12k/trace.h new file +152 -0
@@ -0,0 +1,152 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2019-2021 The Linux Foundation. All rights reserved. +* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. +*/ + +#if !defined(_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ ) + +#include <linux/tracepoint.h> +#include "core.h" + +#define _TRACE_H_ + +/* create empty functions when tracing is disabled */ +#if !defined(CONFIG_ATH12K_TRACING ) +#undef TRACE_EVENT +#define TRACE_EVENT (name, proto, ...) \ +static inline void trace_ ## name(proto) {} +#endif /* !CONFIG_ATH12K_TRACING || __CHECKER__ */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM ath12k + +TRACE_EVENT (ath12k_htt_pktlog, + TP_PROTO(struct ath12k *ar, const void *buf, u16 buf_len, + u32 pktlog_checksum), + +TP_ARGS (ar, buf, buf_len, pktlog_checksum), + +TP_STRUCT__entry ( + __string(device, dev_name(ar->ab->dev)) + __string(driver, dev_driver_string(ar->ab->dev)) + __field(u16, buf_len) + __field(u32, pktlog_checksum) +__dynamic_array (u8, pktlog, buf_len) + ), + +TP_fast_assign ( + __assign_str(device, dev_name(ar->ab->dev)); + __assign_str(driver, dev_driver_string(ar->ab->dev)); + __entry->buf_len = buf_len; + __entry->pktlog_checksum = pktlog_checksum; + memcpy(__get_dynamic_array(pktlog), buf, buf_len); + ), + +TP_printk ( +"%s %s size %u pktlog_checksum %d" , +__get_str (driver), +__get_str (device), + __entry->buf_len, + __entry->pktlog_checksum + ) +); + +TRACE_EVENT (ath12k_htt_ppdu_stats, + TP_PROTO(struct ath12k *ar, const void *data, size_t len), + +TP_ARGS (ar, data, len), + +TP_STRUCT__entry ( + __string(device, dev_name(ar->ab->dev)) + __string(driver, dev_driver_string(ar->ab->dev)) + __field(u16, len) + __field(u32, info) + __field(u32, sync_tstmp_lo_us) + __field(u32, sync_tstmp_hi_us) + __field(u32, mlo_offset_lo) + __field(u32, mlo_offset_hi) + __field(u32, mlo_offset_clks) + __field(u32, mlo_comp_clks) + __field(u32, mlo_comp_timer) +__dynamic_array (u8, ppdu, len) + ), + +TP_fast_assign ( + __assign_str(device, dev_name(ar->ab->dev)); + __assign_str(driver, dev_driver_string(ar->ab->dev)); + __entry->len = len; + __entry->info = ar->pdev->timestamp.info; + __entry->sync_tstmp_lo_us = ar->pdev->timestamp.sync_timestamp_hi_us; + __entry->sync_tstmp_hi_us = ar->pdev->timestamp.sync_timestamp_lo_us; + __entry->mlo_offset_lo = ar->pdev->timestamp.mlo_offset_lo; + __entry->mlo_offset_hi = ar->pdev->timestamp.mlo_offset_hi; + __entry->mlo_offset_clks = ar->pdev->timestamp.mlo_offset_clks; + __entry->mlo_comp_clks = ar->pdev->timestamp.mlo_comp_clks; + __entry->mlo_comp_timer = ar->pdev->timestamp.mlo_comp_timer; + memcpy(__get_dynamic_array(ppdu), data, len); + ), + +TP_printk ( +"%s %s ppdu len %d" , +__get_str (driver), +__get_str (device), + __entry->len + ) +); + +TRACE_EVENT (ath12k_htt_rxdesc, + TP_PROTO(struct ath12k *ar, const void *data, size_t type, size_t len), + +TP_ARGS (ar, data, type, len), + +TP_STRUCT__entry ( + __string(device, dev_name(ar->ab->dev)) + __string(driver, dev_driver_string(ar->ab->dev)) + __field(u16, len) + __field(u16, type) + __field(u32, info) + __field(u32, sync_tstmp_lo_us) + __field(u32, sync_tstmp_hi_us) + __field(u32, mlo_offset_lo) + __field(u32, mlo_offset_hi) + __field(u32, mlo_offset_clks) + __field(u32, mlo_comp_clks) + __field(u32, mlo_comp_timer) +__dynamic_array (u8, rxdesc, len) + ), + +TP_fast_assign ( + __assign_str(device, dev_name(ar->ab->dev)); + __assign_str(driver, dev_driver_string(ar->ab->dev)); + __entry->len = len; + __entry->type = type; + __entry->info = ar->pdev->timestamp.info; + __entry->sync_tstmp_lo_us = ar->pdev->timestamp.sync_timestamp_hi_us; + __entry->sync_tstmp_hi_us = ar->pdev->timestamp.sync_timestamp_lo_us; + __entry->mlo_offset_lo = ar->pdev->timestamp.mlo_offset_lo; + __entry->mlo_offset_hi = ar->pdev->timestamp.mlo_offset_hi; + __entry->mlo_offset_clks = ar->pdev->timestamp.mlo_offset_clks; + __entry->mlo_comp_clks = ar->pdev->timestamp.mlo_comp_clks; + __entry->mlo_comp_timer = ar->pdev->timestamp.mlo_comp_timer; + memcpy(__get_dynamic_array(rxdesc), data, len); + ), + +TP_printk ( +"%s %s rxdesc len %d" , +__get_str (driver), +__get_str (device), + __entry->len + ) +); + +#endif /* _TRACE_H_ || TRACE_HEADER_MULTI_READ*/ + +/* we don't want to use include/trace/events */ +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +/* This part must be outside protection */ +#include <trace/define_trace.h>
Signature · 3 lines
ath12k mailing list [email protected] https://lists.infradead.org/mailman/listinfo/ath12k