ath11k: driver for Qualcomm IEEE 802.11ax devices
Subsystems (5)
PATCH v3 17/49 ath11k: add dp_rx.c
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/dp_rx.c | 4143 +++++++++++++++++++++++++++++++ 1 file changed, 4143 insertions(+)
drivers/net/wireless/ath/ath11k/dp_rx.c new file +4143 -0
@@ -0,0 +1,4143 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#include <linux/ieee80211.h> +#include "core.h" +#include "debug.h" +#include "hal_desc.h" +#include "hw.h" +#include "dp_rx.h" +#include "hal_rx.h" +#include "dp_tx.h" +#include "peer.h" + +static u8 *ath11k_dp_rx_h_80211_hdr (struct hal_rx_desc *desc) +{ +return desc->hdr_status; +} + +static enum hal_encrypt_type ath11k_dp_rx_h_mpdu_start_enctype (struct hal_rx_desc *desc) +{ +if (!(__le32_to_cpu (desc->mpdu_start.info1) & +RX_MPDU_START_INFO1_ENCRYPT_INFO_VALID )) +return HAL_ENCRYPT_TYPE_OPEN ; + +return FIELD_GET (RX_MPDU_START_INFO2_ENC_TYPE , +__le32_to_cpu (desc->mpdu_start.info2)); +} + +static u8 ath11k_dp_rx_h_mpdu_start_decap_type (struct hal_rx_desc *desc) +{ +return FIELD_GET (RX_MPDU_START_INFO5_DECAP_TYPE , +__le32_to_cpu (desc->mpdu_start.info5)); +} + +static bool ath11k_dp_rx_h_attn_msdu_done (struct hal_rx_desc *desc) +{ +return !!FIELD_GET (RX_ATTENTION_INFO2_MSDU_DONE , +__le32_to_cpu (desc->attention.info2)); +} + +static bool ath11k_dp_rx_h_attn_first_mpdu (struct hal_rx_desc *desc) +{ +return !!FIELD_GET (RX_ATTENTION_INFO1_FIRST_MPDU , +__le32_to_cpu (desc->attention.info1)); +} + +static bool ath11k_dp_rx_h_attn_l4_cksum_fail (struct hal_rx_desc *desc) +{ +return !!FIELD_GET (RX_ATTENTION_INFO1_TCP_UDP_CKSUM_FAIL , +__le32_to_cpu (desc->attention.info1)); +} + +static bool ath11k_dp_rx_h_attn_ip_cksum_fail (struct hal_rx_desc *desc) +{ +return !!FIELD_GET (RX_ATTENTION_INFO1_IP_CKSUM_FAIL , +__le32_to_cpu (desc->attention.info1)); +} + +static bool ath11k_dp_rx_h_attn_is_decrypted (struct hal_rx_desc *desc) +{ +return (FIELD_GET (RX_ATTENTION_INFO2_DCRYPT_STATUS_CODE , +__le32_to_cpu (desc->attention.info2)) == +RX_DESC_DECRYPT_STATUS_CODE_OK ); +} + +static u32 ath11k_dp_rx_h_attn_mpdu_err (struct hal_rx_desc *desc) +{ +u32 info =__le32_to_cpu (desc->attention.info1); +u32 errmap =0 ; + +if (info &RX_ATTENTION_INFO1_FCS_ERR ) + errmap |=DP_RX_MPDU_ERR_FCS ; + +if (info &RX_ATTENTION_INFO1_DECRYPT_ERR ) + errmap |=DP_RX_MPDU_ERR_DECRYPT ; + +if (info &RX_ATTENTION_INFO1_TKIP_MIC_ERR ) + errmap |=DP_RX_MPDU_ERR_TKIP_MIC ; + +if (info &RX_ATTENTION_INFO1_A_MSDU_ERROR ) + errmap |=DP_RX_MPDU_ERR_AMSDU_ERR ; + +if (info &RX_ATTENTION_INFO1_OVERFLOW_ERR ) + errmap |=DP_RX_MPDU_ERR_OVERFLOW ; + +if (info &RX_ATTENTION_INFO1_MSDU_LEN_ERR ) + errmap |=DP_RX_MPDU_ERR_MSDU_LEN ; + +if (info &RX_ATTENTION_INFO1_MPDU_LEN_ERR ) + errmap |=DP_RX_MPDU_ERR_MPDU_LEN ; + +return errmap; +} + +static u16 ath11k_dp_rx_h_msdu_start_msdu_len (struct hal_rx_desc *desc) +{ +return FIELD_GET (RX_MSDU_START_INFO1_MSDU_LENGTH , +__le32_to_cpu (desc->msdu_start.info1)); +} + +static u8 ath11k_dp_rx_h_msdu_start_sgi (struct hal_rx_desc *desc) +{ +return FIELD_GET (RX_MSDU_START_INFO3_SGI , +__le32_to_cpu (desc->msdu_start.info3)); +} + +static u8 ath11k_dp_rx_h_msdu_start_rate_mcs (struct hal_rx_desc *desc) +{ +return FIELD_GET (RX_MSDU_START_INFO3_RATE_MCS , +__le32_to_cpu (desc->msdu_start.info3)); +} + +static u8 ath11k_dp_rx_h_msdu_start_rx_bw (struct hal_rx_desc *desc) +{ +return FIELD_GET (RX_MSDU_START_INFO3_RECV_BW , +__le32_to_cpu (desc->msdu_start.info3)); +} + +static u32 ath11k_dp_rx_h_msdu_start_freq (struct hal_rx_desc *desc) +{ +return __le32_to_cpu (desc->msdu_start.phy_meta_data); +} + +static u8 ath11k_dp_rx_h_msdu_start_pkt_type (struct hal_rx_desc *desc) +{ +return FIELD_GET (RX_MSDU_START_INFO3_PKT_TYPE , +__le32_to_cpu (desc->msdu_start.info3)); +} + +static u8 ath11k_dp_rx_h_msdu_start_nss (struct hal_rx_desc *desc) +{ +u8 mimo_ss_bitmap =FIELD_GET (RX_MSDU_START_INFO3_MIMO_SS_BITMAP , +__le32_to_cpu (desc->msdu_start.info3)); + +return hweight8 (mimo_ss_bitmap); +} + +static u8 ath11k_dp_rx_h_msdu_end_l3pad (struct hal_rx_desc *desc) +{ +return FIELD_GET (RX_MSDU_END_INFO2_L3_HDR_PADDING , +__le32_to_cpu (desc->msdu_end.info2)); +} + +static bool ath11k_dp_rx_h_msdu_end_first_msdu (struct hal_rx_desc *desc) +{ +return !!FIELD_GET (RX_MSDU_END_INFO2_FIRST_MSDU , +__le32_to_cpu (desc->msdu_end.info2)); +} + +static bool ath11k_dp_rx_h_msdu_end_last_msdu (struct hal_rx_desc *desc) +{ +return !!FIELD_GET (RX_MSDU_END_INFO2_LAST_MSDU , +__le32_to_cpu (desc->msdu_end.info2)); +} + +static void ath11k_dp_rx_desc_end_tlv_copy (struct hal_rx_desc *fdesc, +struct hal_rx_desc *ldesc) +{ +memcpy ((u8 *)&fdesc->msdu_end, (u8 *)&ldesc->msdu_end, +sizeof (struct rx_msdu_end )); +memcpy ((u8 *)&fdesc->attention, (u8 *)&ldesc->attention, +sizeof (struct rx_attention )); +memcpy ((u8 *)&fdesc->mpdu_end, (u8 *)&ldesc->mpdu_end, +sizeof (struct rx_mpdu_end )); +} + +static u32 ath11k_dp_rxdesc_get_mpdulen_err (struct hal_rx_desc *rx_desc) +{ +struct rx_attention *rx_attn; + + rx_attn = &rx_desc->attention; + +return FIELD_GET (RX_ATTENTION_INFO1_MPDU_LEN_ERR , +__le32_to_cpu (rx_attn->info1)); +} + +static u32 ath11k_dp_rxdesc_get_decap_format (struct hal_rx_desc *rx_desc) +{ +struct rx_msdu_start *rx_msdu_start; + + rx_msdu_start = &rx_desc->msdu_start; + +return FIELD_GET (RX_MSDU_START_INFO2_DECAP_FORMAT , +__le32_to_cpu (rx_msdu_start->info2)); +} + +static u8 *ath11k_dp_rxdesc_get_80211hdr (struct hal_rx_desc *rx_desc) +{ +u8 *rx_pkt_hdr; + + rx_pkt_hdr = &rx_desc->msdu_payload[0 ]; + +return rx_pkt_hdr; +} + +static bool ath11k_dp_rxdesc_mpdu_valid (struct hal_rx_desc *rx_desc) +{ +u32 tlv_tag; + + tlv_tag =FIELD_GET (HAL_TLV_HDR_TAG , +__le32_to_cpu (rx_desc->mpdu_start_tag)); + +return tlv_tag ==HAL_RX_MPDU_START ? true : false; +} + +static u32 ath11k_dp_rxdesc_get_ppduid (struct hal_rx_desc *rx_desc) +{ +return __le16_to_cpu (rx_desc->mpdu_start.phy_ppdu_id); +} + +/* Returns number of Rx buffers replenished */ +int ath11k_dp_rxbufs_replenish (struct ath11k_base *ab,int mac_id, +struct dp_rxdma_ring *rx_ring, +int req_entries, +enum hal_rx_buf_return_buf_manager mgr, +gfp_t gfp) +{ +struct hal_srng *srng; +u32 *desc; +struct sk_buff *skb; +int num_free; +int num_remain; +int buf_id; +u32 cookie; +dma_addr_t paddr; + + req_entries =min (req_entries, rx_ring->bufs_max); + + srng = &ab->hal.srng_list[rx_ring->refill_buf_ring.ring_id]; + +spin_lock_bh (&srng->lock); + +ath11k_hal_srng_access_begin (ab, srng); + + num_free =ath11k_hal_srng_src_num_free (ab, srng, true); +if (!req_entries && (num_free > (rx_ring->bufs_max *3 ) /4 )) + req_entries = num_free; + + req_entries =min (num_free, req_entries); + num_remain = req_entries; + +while (num_remain >0 ) { + skb =dev_alloc_skb (DP_RX_BUFFER_SIZE + +DP_RX_BUFFER_ALIGN_SIZE ); +if (!skb) +break ; + +if (!IS_ALIGNED ((unsigned long )skb->data, +DP_RX_BUFFER_ALIGN_SIZE )) { +skb_pull (skb, +PTR_ALIGN (skb->data,DP_RX_BUFFER_ALIGN_SIZE ) - + skb->data); + } + + paddr =dma_map_single (ab->dev, skb->data, + skb->len +skb_tailroom (skb), +DMA_FROM_DEVICE ); +if (dma_mapping_error (ab->dev, paddr)) + goto fail_free_skb; + +spin_lock_bh (&rx_ring->idr_lock); + buf_id =idr_alloc (&rx_ring->bufs_idr, skb,0 , + rx_ring->bufs_max *3 , gfp); +spin_unlock_bh (&rx_ring->idr_lock); +if (buf_id <0 ) + goto fail_dma_unmap; + + desc =ath11k_hal_srng_src_get_next_entry (ab, srng); +if (!desc) + goto fail_idr_remove; + +ATH11K_SKB_RXCB (skb)->paddr = paddr; + + cookie =FIELD_PREP (DP_RXDMA_BUF_COOKIE_PDEV_ID , mac_id) | +FIELD_PREP (DP_RXDMA_BUF_COOKIE_BUF_ID , buf_id); + + num_remain--; + +ath11k_hal_rx_buf_addr_info_set (desc, paddr, cookie, mgr); + } + +ath11k_hal_srng_access_end (ab, srng); + +spin_unlock_bh (&srng->lock); + +return req_entries - num_remain; + +fail_idr_remove: +spin_lock_bh (&rx_ring->idr_lock); +idr_remove (&rx_ring->bufs_idr, buf_id); +spin_unlock_bh (&rx_ring->idr_lock); +fail_dma_unmap: +dma_unmap_single (ab->dev, paddr, skb->len +skb_tailroom (skb), +DMA_FROM_DEVICE ); +fail_free_skb: +dev_kfree_skb_any (skb); + +ath11k_hal_srng_access_end (ab, srng); + +spin_unlock_bh (&srng->lock); + +return req_entries - num_remain; +} + +static int ath11k_dp_rxdma_buf_ring_free (struct ath11k *ar, +struct dp_rxdma_ring *rx_ring) +{ +struct ath11k_pdev_dp *dp = &ar->dp; +struct sk_buff *skb; +int buf_id; + +spin_lock_bh (&rx_ring->idr_lock); +idr_for_each_entry (&rx_ring->bufs_idr, skb, buf_id) { +idr_remove (&rx_ring->bufs_idr, buf_id); +/* TODO: Understand where internal driver does this dma_unmap of +* of rxdma_buffer. +*/ +dma_unmap_single (ar->ab->dev,ATH11K_SKB_RXCB (skb)->paddr, + skb->len +skb_tailroom (skb),DMA_FROM_DEVICE ); +dev_kfree_skb_any (skb); + } + +idr_destroy (&rx_ring->bufs_idr); +spin_unlock_bh (&rx_ring->idr_lock); + + rx_ring = &dp->rx_mon_status_refill_ring; + +spin_lock_bh (&rx_ring->idr_lock); +idr_for_each_entry (&rx_ring->bufs_idr, skb, buf_id) { +idr_remove (&rx_ring->bufs_idr, buf_id); +/* XXX: Understand where internal driver does this dma_unmap of +* of rxdma_buffer. +*/ +dma_unmap_single (ar->ab->dev,ATH11K_SKB_RXCB (skb)->paddr, + skb->len +skb_tailroom (skb),DMA_BIDIRECTIONAL ); +dev_kfree_skb_any (skb); + } + +idr_destroy (&rx_ring->bufs_idr); +spin_unlock_bh (&rx_ring->idr_lock); +return 0 ; +} + +static int ath11k_dp_rxdma_pdev_buf_free (struct ath11k *ar) +{ +struct ath11k_pdev_dp *dp = &ar->dp; +struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring; + +ath11k_dp_rxdma_buf_ring_free (ar, rx_ring); + + rx_ring = &dp->rxdma_mon_buf_ring; +ath11k_dp_rxdma_buf_ring_free (ar, rx_ring); + + rx_ring = &dp->rx_mon_status_refill_ring; +ath11k_dp_rxdma_buf_ring_free (ar, rx_ring); +return 0 ; +} + +static int ath11k_dp_rxdma_ring_buf_setup (struct ath11k *ar, +struct dp_rxdma_ring *rx_ring, +u32 ringtype) +{ +struct ath11k_pdev_dp *dp = &ar->dp; +int num_entries; + + num_entries = rx_ring->refill_buf_ring.size / +ath11k_hal_srng_get_entrysize (ringtype); + + rx_ring->bufs_max = num_entries; +ath11k_dp_rxbufs_replenish (ar->ab, dp->mac_id, rx_ring, num_entries, +HAL_RX_BUF_RBM_SW3_BM ,GFP_KERNEL ); +return 0 ; +} + +static int ath11k_dp_rxdma_pdev_buf_setup (struct ath11k *ar) +{ +struct ath11k_pdev_dp *dp = &ar->dp; +struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring; + +ath11k_dp_rxdma_ring_buf_setup (ar, rx_ring,HAL_RXDMA_BUF ); + + rx_ring = &dp->rxdma_mon_buf_ring; +ath11k_dp_rxdma_ring_buf_setup (ar, rx_ring,HAL_RXDMA_MONITOR_BUF ); + + rx_ring = &dp->rx_mon_status_refill_ring; +ath11k_dp_rxdma_ring_buf_setup (ar, rx_ring,HAL_RXDMA_MONITOR_STATUS ); + +return 0 ; +} + +static void ath11k_dp_rx_pdev_srng_free (struct ath11k *ar) +{ +struct ath11k_pdev_dp *dp = &ar->dp; + +ath11k_dp_srng_cleanup (ar->ab, &dp->rx_refill_buf_ring.refill_buf_ring); +ath11k_dp_srng_cleanup (ar->ab, &dp->reo_dst_ring); +ath11k_dp_srng_cleanup (ar->ab, &dp->rxdma_err_dst_ring); +ath11k_dp_srng_cleanup (ar->ab, &dp->rx_mon_status_refill_ring.refill_buf_ring); +ath11k_dp_srng_cleanup (ar->ab, &dp->rxdma_mon_buf_ring.refill_buf_ring); +} + +static int ath11k_dp_rx_pdev_srng_alloc (struct ath11k *ar) +{ +struct ath11k_pdev_dp *dp = &ar->dp; +struct dp_srng *srng =NULL ; +int ret; + + ret =ath11k_dp_srng_setup (ar->ab, + &dp->rx_refill_buf_ring.refill_buf_ring, +HAL_RXDMA_BUF ,0 , + dp->mac_id,DP_RXDMA_BUF_RING_SIZE ); +if (ret) { +ath11k_warn (ar->ab,"failed to setup rx_refill_buf_ring\n" ); +return ret; + } + + ret =ath11k_dp_srng_setup (ar->ab, &dp->reo_dst_ring,HAL_REO_DST , + dp->mac_id, dp->mac_id, +DP_REO_DST_RING_SIZE ); +if (ret) { +ath11k_warn (ar->ab,"failed to setup reo_dst_ring\n" ); +return ret; + } + + ret =ath11k_dp_srng_setup (ar->ab, &dp->rxdma_err_dst_ring, +HAL_RXDMA_DST ,0 , dp->mac_id, +DP_RXDMA_ERR_DST_RING_SIZE ); +if (ret) { +ath11k_warn (ar->ab,"failed to setup rxdma_err_dst_ring\n" ); +return ret; + } + + srng = &dp->rx_mon_status_refill_ring.refill_buf_ring; + ret =ath11k_dp_srng_setup (ar->ab, + srng, +HAL_RXDMA_MONITOR_STATUS ,0 , dp->mac_id, +DP_RXDMA_MON_STATUS_RING_SIZE ); +if (ret) { +ath11k_warn (ar->ab, +"failed to setup rx_mon_status_refill_ring\n" ); +return ret; + } + ret =ath11k_dp_srng_setup (ar->ab, + &dp->rxdma_mon_buf_ring.refill_buf_ring, +HAL_RXDMA_MONITOR_BUF ,0 , dp->mac_id, +DP_RXDMA_MONITOR_BUF_RING_SIZE ); +if (ret) { +ath11k_warn (ar->ab, +"failed to setup HAL_RXDMA_MONITOR_BUF\n" ); +return ret; + } + + ret =ath11k_dp_srng_setup (ar->ab, &dp->rxdma_mon_dst_ring, +HAL_RXDMA_MONITOR_DST ,0 , dp->mac_id, +DP_RXDMA_MONITOR_DST_RING_SIZE ); +if (ret) { +ath11k_warn (ar->ab, +"failed to setup HAL_RXDMA_MONITOR_DST\n" ); +return ret; + } + + ret =ath11k_dp_srng_setup (ar->ab, &dp->rxdma_mon_desc_ring, +HAL_RXDMA_MONITOR_DESC ,0 , dp->mac_id, +DP_RXDMA_MONITOR_DESC_RING_SIZE ); +if (ret) { +ath11k_warn (ar->ab, +"failed to setup HAL_RXDMA_MONITOR_DESC\n" ); +return ret; + } + +return 0 ; +} + +void ath11k_dp_reo_cmd_list_cleanup (struct ath11k_base *ab) +{ +struct ath11k_dp *dp = &ab->dp; +struct dp_reo_cmd *cmd, *tmp; +struct dp_reo_cache_flush_elem *cmd_cache, *tmp_cache; + +spin_lock_bh (&dp->reo_cmd_lock); +list_for_each_entry_safe (cmd, tmp, &dp->reo_cmd_list, list) { +list_del (&cmd->list); +dma_unmap_single (ab->dev, cmd->data.paddr, + cmd->data.size,DMA_BIDIRECTIONAL ); +kfree (cmd->data.vaddr); +kfree (cmd); + } + +list_for_each_entry_safe (cmd_cache, tmp_cache, + &dp->reo_cmd_cache_flush_list, list) { +list_del (&cmd_cache->list); +dma_unmap_single (ab->dev, cmd_cache->data.paddr, + cmd_cache->data.size,DMA_BIDIRECTIONAL ); +kfree (cmd_cache->data.vaddr); +kfree (cmd_cache); + } +spin_unlock_bh (&dp->reo_cmd_lock); +} + +static void ath11k_dp_reo_cmd_free (struct ath11k_dp *dp,void *ctx, +enum hal_reo_cmd_status status) +{ +struct dp_rx_tid *rx_tid = ctx; + +if (status !=HAL_REO_CMD_SUCCESS ) +ath11k_warn (dp->ab,"failed to flush rx tid hw desc, tid %d status %d\n" , + rx_tid->tid, status); + +dma_unmap_single (dp->ab->dev, rx_tid->paddr, rx_tid->size, +DMA_BIDIRECTIONAL ); +kfree (rx_tid->vaddr); +} + +static void ath11k_dp_reo_cache_flush (struct ath11k_base *ab, +struct dp_rx_tid *rx_tid) +{ +struct ath11k_hal_reo_cmd cmd = {0 }; +unsigned long tot_desc_sz, desc_sz; +int ret; + + tot_desc_sz = rx_tid->size; + desc_sz =ath11k_hal_reo_qdesc_size (0 ,HAL_DESC_REO_NON_QOS_TID ); + +while (tot_desc_sz > desc_sz) { + tot_desc_sz -= desc_sz; + cmd.addr_lo =lower_32_bits (rx_tid->paddr + tot_desc_sz); + cmd.addr_hi =upper_32_bits (rx_tid->paddr); + ret =ath11k_dp_tx_send_reo_cmd (ab, rx_tid, +HAL_REO_CMD_FLUSH_CACHE , &cmd, +NULL ); +if (ret) +ath11k_warn (ab, +"failed to send HAL_REO_CMD_FLUSH_CACHE, tid %d (%d)\n" , + rx_tid->tid, ret); + } + +memset (&cmd,0 ,sizeof (cmd)); + cmd.addr_lo =lower_32_bits (rx_tid->paddr); + cmd.addr_hi =upper_32_bits (rx_tid->paddr); + cmd.flag |=HAL_REO_CMD_FLG_NEED_STATUS ; + ret =ath11k_dp_tx_send_reo_cmd (ab, rx_tid, +HAL_REO_CMD_FLUSH_CACHE , + &cmd, ath11k_dp_reo_cmd_free); +if (ret) { +ath11k_err (ab,"failed to send HAL_REO_CMD_FLUSH_CACHE cmd, tid %d (%d)\n" , + rx_tid->tid, ret); +dma_unmap_single (ab->dev, rx_tid->paddr, rx_tid->size, +DMA_BIDIRECTIONAL ); +kfree (rx_tid->vaddr); + } +} + +static void ath11k_dp_rx_tid_del_func (struct ath11k_dp *dp,void *ctx, +enum hal_reo_cmd_status status) +{ +struct ath11k_base *ab = dp->ab; +struct dp_rx_tid *rx_tid = ctx; +struct dp_reo_cache_flush_elem *elem, *tmp; + +if (status ==HAL_REO_CMD_DRAIN ) { + goto free_desc; + }else if (status !=HAL_REO_CMD_SUCCESS ) { +/* Shouldn't happen! Cleanup in case of other failure? */ +ath11k_warn (ab,"failed to delete rx tid %d hw descriptor %d\n" , + rx_tid->tid, status); +return ; + } + + elem =kzalloc (sizeof (*elem),GFP_ATOMIC ); +if (!elem) + goto free_desc; + + elem->ts = jiffies; +memcpy (&elem->data, rx_tid,sizeof (*rx_tid)); + +spin_lock_bh (&dp->reo_cmd_lock); +list_add_tail (&elem->list, &dp->reo_cmd_cache_flush_list); +spin_unlock_bh (&dp->reo_cmd_lock); + +/* Flush and invalidate aged REO desc from HW cache */ +spin_lock_bh (&dp->reo_cmd_lock); +list_for_each_entry_safe (elem, tmp, &dp->reo_cmd_cache_flush_list, + list) { +if (time_after (jiffies, elem->ts + +msecs_to_jiffies (DP_REO_DESC_FREE_TIMEOUT_MS ))) { +list_del (&elem->list); +spin_unlock_bh (&dp->reo_cmd_lock); + +ath11k_dp_reo_cache_flush (ab, &elem->data); +kfree (elem); +spin_lock_bh (&dp->reo_cmd_lock); + } + } +spin_unlock_bh (&dp->reo_cmd_lock); + +return ; +free_desc: +dma_unmap_single (ab->dev, rx_tid->paddr, rx_tid->size, +DMA_BIDIRECTIONAL ); +kfree (rx_tid->vaddr); +} + +static void ath11k_peer_rx_tid_delete (struct ath11k *ar, +struct ath11k_peer *peer,u8 tid) +{ +struct ath11k_hal_reo_cmd cmd = {0 }; +struct dp_rx_tid *rx_tid = &peer->rx_tid[tid]; +int ret; + +if (!rx_tid->active) +return ; + + cmd.flag =HAL_REO_CMD_FLG_NEED_STATUS ; + cmd.addr_lo =lower_32_bits (rx_tid->paddr); + cmd.addr_hi =upper_32_bits (rx_tid->paddr); + cmd.upd0 |=HAL_REO_CMD_UPD0_VLD ; + ret =ath11k_dp_tx_send_reo_cmd (ar->ab, rx_tid, +HAL_REO_CMD_UPDATE_RX_QUEUE , &cmd, + ath11k_dp_rx_tid_del_func); +if (ret) { +ath11k_err (ar->ab,"failed to send HAL_REO_CMD_UPDATE_RX_QUEUE cmd, tid %d (%d)\n" , + tid, ret); +dma_unmap_single (ar->ab->dev, rx_tid->paddr, rx_tid->size, +DMA_BIDIRECTIONAL ); +kfree (rx_tid->vaddr); + } + + rx_tid->active = false; +} + +void ath11k_peer_rx_tid_cleanup (struct ath11k *ar,struct ath11k_peer *peer) +{ +int i; + +for (i =0 ; i <=IEEE80211_NUM_TIDS ; i++) +ath11k_peer_rx_tid_delete (ar, peer, i); +} + +static int ath11k_peer_rx_tid_reo_update (struct ath11k *ar, +struct ath11k_peer *peer, +struct dp_rx_tid *rx_tid, +u32 ba_win_sz,u16 ssn) +{ +struct ath11k_hal_reo_cmd cmd = {0 }; +int ret; + + cmd.addr_lo =lower_32_bits (rx_tid->paddr); + cmd.addr_hi =upper_32_bits (rx_tid->paddr); + cmd.flag =HAL_REO_CMD_FLG_NEED_STATUS ; + cmd.upd0 =HAL_REO_CMD_UPD0_BA_WINDOW_SIZE | +HAL_REO_CMD_UPD0_SSN ; + cmd.ba_window_size = ba_win_sz; + cmd.upd2 =FIELD_PREP (HAL_REO_CMD_UPD2_SSN , ssn); + + ret =ath11k_dp_tx_send_reo_cmd (ar->ab, rx_tid, +HAL_REO_CMD_UPDATE_RX_QUEUE , &cmd, +NULL ); +if (ret) { +ath11k_warn (ar->ab,"failed to update rx tid queue, tid %d (%d)\n" , + rx_tid->tid, ret); +return ret; + } + + rx_tid->ba_win_sz = ba_win_sz; + +return 0 ; +} + +static void ath11k_dp_rx_tid_mem_free (struct ath11k_base *ab, +const u8 *peer_mac,int vdev_id,u8 tid) +{ +struct ath11k_peer *peer; +struct dp_rx_tid *rx_tid; + +spin_lock_bh (&ab->base_lock); + + peer =ath11k_peer_find (ab, vdev_id, peer_mac); +if (!peer) { +ath11k_warn (ab,"failed to find the peer to free up rx tid mem\n" ); + goto unlock_exit; + } + + rx_tid = &peer->rx_tid[tid]; +if (!rx_tid->active) + goto unlock_exit; + +dma_unmap_single (ab->dev, rx_tid->paddr, rx_tid->size, +DMA_BIDIRECTIONAL ); +kfree (rx_tid->vaddr); + + rx_tid->active = false; + +unlock_exit: +spin_unlock_bh (&ab->base_lock); +} + +int ath11k_peer_rx_tid_setup (struct ath11k *ar,const u8 *peer_mac,int vdev_id, +u8 tid,u32 ba_win_sz,u16 ssn) +{ +struct ath11k_base *ab = ar->ab; +struct ath11k_peer *peer; +struct dp_rx_tid *rx_tid; +u32 hw_desc_sz; +u32 *addr_aligned; +void *vaddr; +dma_addr_t paddr; +int ret; + +spin_lock_bh (&ab->base_lock); + + peer =ath11k_peer_find (ab, vdev_id, peer_mac); +if (!peer) { +ath11k_warn (ab,"failed to find the peer to set up rx tid\n" ); +spin_unlock_bh (&ab->base_lock); +return -ENOENT ; + } + + rx_tid = &peer->rx_tid[tid]; +/* Update the tid queue if it is already setup */ +if (rx_tid->active) { + paddr = rx_tid->paddr; + ret =ath11k_peer_rx_tid_reo_update (ar, peer, rx_tid, + ba_win_sz, ssn); +spin_unlock_bh (&ab->base_lock); +if (ret) { +ath11k_warn (ab,"failed to update reo for rx tid %d\n" , tid); +return ret; + } + + ret =ath11k_wmi_peer_rx_reorder_queue_setup (ar, vdev_id, + peer_mac, paddr, + tid,1 , ba_win_sz); +if (ret) +ath11k_warn (ab,"failed to send wmi command to update rx reorder queue, tid :%d (%d)\n" , + tid, ret); +return ret; + } + + rx_tid->tid = tid; + + rx_tid->ba_win_sz = ba_win_sz; + +/* TODO: Optimize the memory allocation for qos tid based on the +* the actual BA window size in REO tid update path. +*/ +if (tid ==HAL_DESC_REO_NON_QOS_TID ) + hw_desc_sz =ath11k_hal_reo_qdesc_size (ba_win_sz, tid); +else + hw_desc_sz =ath11k_hal_reo_qdesc_size (DP_BA_WIN_SZ_MAX , tid); + + vaddr =kzalloc (hw_desc_sz +HAL_LINK_DESC_ALIGN -1 ,GFP_KERNEL ); +if (!vaddr) { +spin_unlock_bh (&ab->base_lock); +return -ENOMEM ; + } + + addr_aligned =PTR_ALIGN (vaddr,HAL_LINK_DESC_ALIGN ); + +ath11k_hal_reo_qdesc_setup (addr_aligned, tid, ba_win_sz, ssn); + + paddr =dma_map_single (ab->dev, addr_aligned, hw_desc_sz, +DMA_BIDIRECTIONAL ); + + ret =dma_mapping_error (ab->dev, paddr); +if (ret) { +spin_unlock_bh (&ab->base_lock); + goto err_mem_free; + } + + rx_tid->vaddr = vaddr; + rx_tid->paddr = paddr; + rx_tid->size = hw_desc_sz; + rx_tid->active = true; + +spin_unlock_bh (&ab->base_lock); + + ret =ath11k_wmi_peer_rx_reorder_queue_setup (ar, vdev_id, peer_mac, + paddr, tid,1 , ba_win_sz); +if (ret) { +ath11k_warn (ar->ab,"failed to setup rx reorder queue, tid :%d (%d)\n" , + tid, ret); +ath11k_dp_rx_tid_mem_free (ab, peer_mac, vdev_id, tid); + } + +return ret; + +err_mem_free: +kfree (vaddr); + +return ret; +} + +int ath11k_dp_rx_ampdu_start (struct ath11k *ar, +struct ieee80211_ampdu_params *params) +{ +struct ath11k_base *ab = ar->ab; +struct ath11k_sta *arsta = (void *)params->sta->drv_priv; +int vdev_id = arsta->arvif->vdev_id; +int ret; + + ret =ath11k_peer_rx_tid_setup (ar, params->sta->addr, vdev_id, + params->tid, params->buf_size, + params->ssn); +if (ret) +ath11k_warn (ab,"failed to setup rx tid %d\n" , ret); + +return ret; +} + +int ath11k_dp_rx_ampdu_stop (struct ath11k *ar, +struct ieee80211_ampdu_params *params) +{ +struct ath11k_base *ab = ar->ab; +struct ath11k_peer *peer; +struct ath11k_sta *arsta = (void *)params->sta->drv_priv; +int vdev_id = arsta->arvif->vdev_id; +dma_addr_t paddr; +bool active; +int ret; + +spin_lock_bh (&ab->base_lock); + + peer =ath11k_peer_find (ab, vdev_id, params->sta->addr); +if (!peer) { +ath11k_warn (ab,"failed to find the peer to stop rx aggregation\n" ); +spin_unlock_bh (&ab->base_lock); +return -ENOENT ; + } + + paddr = peer->rx_tid[params->tid].paddr; + active = peer->rx_tid[params->tid].active; + +ath11k_peer_rx_tid_delete (ar, peer, params->tid); + +spin_unlock_bh (&ab->base_lock); + +if (!active) +return 0 ; + + ret =ath11k_wmi_peer_rx_reorder_queue_setup (ar, vdev_id, + params->sta->addr, paddr, + params->tid,1 ,1 ); +if (ret) +ath11k_warn (ab,"failed to send wmi to delete rx tid %d\n" , + ret); + +return ret; +} + +static int ath11k_get_ppdu_user_index (struct htt_ppdu_stats *ppdu_stats, +u16 peer_id) +{ +int i; + +for (i =0 ; i <HTT_PPDU_STATS_MAX_USERS -1 ; i++) { +if (ppdu_stats->user_stats[i].is_valid_peer_id) { +if (peer_id == ppdu_stats->user_stats[i].peer_id) +return i; + }else { +return i; + } + } + +return -EINVAL ; +} + +static int ath11k_htt_tlv_ppdu_stats_parse (struct ath11k_base *ab, +u16 tag,u16 len,const void *ptr, +void *data) +{ +struct htt_ppdu_stats_info *ppdu_info; +struct htt_ppdu_user_stats *user_stats; +int cur_user; +u16 peer_id; + + ppdu_info = (struct htt_ppdu_stats_info *)data; + +switch (tag) { +case HTT_PPDU_STATS_TAG_COMMON : +if (len <sizeof (struct htt_ppdu_stats_common )) { +ath11k_warn (ab,"Invalid len %d for the tag 0x%x\n" , + len, tag); +return -EINVAL ; + } +memcpy ((void *)&ppdu_info->ppdu_stats.common, ptr, +sizeof (struct htt_ppdu_stats_common )); +break ; +case HTT_PPDU_STATS_TAG_USR_RATE : +if (len <sizeof (struct htt_ppdu_stats_user_rate )) { +ath11k_warn (ab,"Invalid len %d for the tag 0x%x\n" , + len, tag); +return -EINVAL ; + } + + peer_id = ((struct htt_ppdu_stats_user_rate *)ptr)->sw_peer_id; + cur_user =ath11k_get_ppdu_user_index (&ppdu_info->ppdu_stats, + peer_id); +if (cur_user <0 ) +return -EINVAL ; + user_stats = &ppdu_info->ppdu_stats.user_stats[cur_user]; + user_stats->peer_id = peer_id; + user_stats->is_valid_peer_id = true; +memcpy ((void *)&user_stats->rate, ptr, +sizeof (struct htt_ppdu_stats_user_rate )); + user_stats->tlv_flags |=BIT (tag); +break ; +case HTT_PPDU_STATS_TAG_USR_COMPLTN_COMMON : +if (len <sizeof (struct htt_ppdu_stats_usr_cmpltn_cmn )) { +ath11k_warn (ab,"Invalid len %d for the tag 0x%x\n" , + len, tag); +return -EINVAL ; + } + + peer_id = ((struct htt_ppdu_stats_usr_cmpltn_cmn *)ptr)->sw_peer_id; + cur_user =ath11k_get_ppdu_user_index (&ppdu_info->ppdu_stats, + peer_id); +if (cur_user <0 ) +return -EINVAL ; + user_stats = &ppdu_info->ppdu_stats.user_stats[cur_user]; + user_stats->peer_id = peer_id; + user_stats->is_valid_peer_id = true; +memcpy ((void *)&user_stats->cmpltn_cmn, ptr, +sizeof (struct htt_ppdu_stats_usr_cmpltn_cmn )); + user_stats->tlv_flags |=BIT (tag); +break ; +case HTT_PPDU_STATS_TAG_USR_COMPLTN_ACK_BA_STATUS : +if (len < +sizeof (struct htt_ppdu_stats_usr_cmpltn_ack_ba_status )) { +ath11k_warn (ab,"Invalid len %d for the tag 0x%x\n" , + len, tag); +return -EINVAL ; + } + + peer_id = + ((struct htt_ppdu_stats_usr_cmpltn_ack_ba_status *)ptr)->sw_peer_id; + cur_user =ath11k_get_ppdu_user_index (&ppdu_info->ppdu_stats, + peer_id); +if (cur_user <0 ) +return -EINVAL ; + user_stats = &ppdu_info->ppdu_stats.user_stats[cur_user]; + user_stats->peer_id = peer_id; + user_stats->is_valid_peer_id = true; +memcpy ((void *)&user_stats->ack_ba, ptr, +sizeof (struct htt_ppdu_stats_usr_cmpltn_ack_ba_status )); + user_stats->tlv_flags |=BIT (tag); +break ; + } +return 0 ; +} + +int ath11k_dp_htt_tlv_iter (struct ath11k_base *ab,const void *ptr,size_t len, +int (*iter)(struct ath11k_base *ar,u16 tag,u16 len, +const void *ptr,void *data), +void *data) +{ +const struct htt_tlv *tlv; +const void *begin = ptr; +u16 tlv_tag, tlv_len; +int ret = -EINVAL ; + +while (len >0 ) { +if (len <sizeof (*tlv)) { +ath11k_err (ab,"htt tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n" , + ptr - begin, len,sizeof (*tlv)); +return -EINVAL ; + } + tlv = (struct htt_tlv *)ptr; + tlv_tag =FIELD_GET (HTT_TLV_TAG , tlv->header); + tlv_len =FIELD_GET (HTT_TLV_LEN , tlv->header); + ptr +=sizeof (*tlv); + len -=sizeof (*tlv); + +if (tlv_len > len) { +ath11k_err (ab,"htt tlv parse failure of tag %hhu at byte %zd (%zu bytes left, %hhu expected)\n" , + tlv_tag, ptr - begin, len, tlv_len); +return -EINVAL ; + } + ret =iter (ab, tlv_tag, tlv_len, ptr, data); +if (ret == -ENOMEM ) +return ret; + + ptr += tlv_len; + len -= tlv_len; + } +return 0 ; +} + +static u8 ath11k_bw_to_mac80211_bw (u8 bw) +{ +u8 ret =0 ; + +switch (bw) { +case ATH11K_BW_20 : + ret =RATE_INFO_BW_20 ; +break ; +case ATH11K_BW_40 : + ret =RATE_INFO_BW_40 ; +break ; +case ATH11K_BW_80 : + ret =RATE_INFO_BW_80 ; +break ; +case ATH11K_BW_160 : + ret =RATE_INFO_BW_160 ; +break ; + } + +return ret; +} + +static u32 ath11k_bw_to_mac80211_bwflags (u8 bw) +{ +u32 bwflags =0 ; + +switch (bw) { +case ATH11K_BW_40 : + bwflags =IEEE80211_TX_RC_40_MHZ_WIDTH ; +break ; +case ATH11K_BW_80 : + bwflags =IEEE80211_TX_RC_80_MHZ_WIDTH ; +break ; +case ATH11K_BW_160 : + bwflags =IEEE80211_TX_RC_160_MHZ_WIDTH ; +break ; + } + +return bwflags; +} + +static void +ath11k_update_per_peer_tx_stats (struct ath11k *ar, +struct htt_ppdu_stats *ppdu_stats,u8 user) +{ +struct ath11k_base *ab = ar->ab; +struct ath11k_peer *peer; +struct ieee80211_sta *sta; +struct ath11k_sta *arsta; +struct htt_ppdu_stats_user_rate *user_rate; +struct ieee80211_chanctx_conf *conf =NULL ; +struct ath11k_per_peer_tx_stats *peer_stats = &ar->peer_tx_stats; +struct htt_ppdu_user_stats *usr_stats = &ppdu_stats->user_stats[user]; +struct htt_ppdu_stats_common *common = &ppdu_stats->common; +int ret; +u8 flags, mcs, nss, bw, sgi, rate_idx =0 ; +u32 succ_bytes =0 ; +u16 rate =0 , succ_pkts =0 ; +u32 tx_duration =0 ; +bool is_ampdu = false; + +if (!usr_stats) +return ; + +if (!(usr_stats->tlv_flags &BIT (HTT_PPDU_STATS_TAG_USR_RATE ))) +return ; + +if (usr_stats->tlv_flags &BIT (HTT_PPDU_STATS_TAG_USR_COMPLTN_COMMON )) + is_ampdu = +HTT_USR_CMPLTN_IS_AMPDU (usr_stats->cmpltn_cmn.flags); + +if (usr_stats->tlv_flags & +BIT (HTT_PPDU_STATS_TAG_USR_COMPLTN_ACK_BA_STATUS )) { + succ_bytes = usr_stats->ack_ba.success_bytes; + succ_pkts =FIELD_GET (HTT_PPDU_STATS_ACK_BA_INFO_NUM_MSDU_M , + usr_stats->ack_ba.info); + } + +if (common->fes_duration_us) + tx_duration = common->fes_duration_us; + + user_rate = &usr_stats->rate; + flags =HTT_USR_RATE_PREAMBLE (user_rate->rate_flags); + bw =HTT_USR_RATE_BW (user_rate->rate_flags) -2 ; + nss =HTT_USR_RATE_NSS (user_rate->rate_flags) +1 ; + mcs =HTT_USR_RATE_MCS (user_rate->rate_flags); + sgi =HTT_USR_RATE_GI (user_rate->rate_flags); + +/* Note: If host configured fixed rates and in some other special +* cases, the broadcast/management frames are sent in different rates. +* Firmware rate's control to be skipped for this? +*/ + +if (flags ==WMI_RATE_PREAMBLE_VHT && mcs >9 ) { +ath11k_warn (ab,"Invalid VHT mcs %hhd peer stats" , mcs); +return ; + } + +if (flags ==WMI_RATE_PREAMBLE_HT && (mcs >7 || nss <1 )) { +ath11k_warn (ab,"Invalid HT mcs %hhd nss %hhd peer stats" , + mcs, nss); +return ; + } + +if (flags ==WMI_RATE_PREAMBLE_CCK || flags ==WMI_RATE_PREAMBLE_OFDM ) { + ret =ath11k_mac_hw_ratecode_to_legacy_rate (mcs, + flags, + &rate_idx, + &rate); +if (ret <0 ) +return ; + } + +rcu_read_lock (); +spin_lock_bh (&ab->base_lock); + peer =ath11k_peer_find_by_id (ab, usr_stats->peer_id); + +if (!peer || !peer->sta) { +spin_unlock_bh (&ab->base_lock); +rcu_read_unlock (); +return ; + } + + sta = peer->sta; + arsta = (struct ath11k_sta *)sta->drv_priv; + +memset (&arsta->txrate,0 ,sizeof (arsta->txrate)); +memset (&arsta->tx_info.status,0 ,sizeof (arsta->tx_info.status)); + +switch (flags) { +case WMI_RATE_PREAMBLE_OFDM : + arsta->txrate.legacy = rate; +if (arsta->arvif && arsta->arvif->vif) + conf =rcu_dereference (arsta->arvif->vif->chanctx_conf); +if (conf && conf->def.chan->band ==NL80211_BAND_5GHZ ) + arsta->tx_info.status.rates[0 ].idx = rate_idx -4 ; +break ; +case WMI_RATE_PREAMBLE_CCK : + arsta->txrate.legacy = rate; + arsta->tx_info.status.rates[0 ].idx = rate_idx; +if (mcs >ATH11K_HW_RATE_CCK_LP_1M && + mcs <=ATH11K_HW_RATE_CCK_SP_2M ) + arsta->tx_info.status.rates[0 ].flags |= +IEEE80211_TX_RC_USE_SHORT_PREAMBLE ; +break ; +case WMI_RATE_PREAMBLE_HT : + arsta->txrate.mcs = mcs +8 * (nss -1 ); + arsta->tx_info.status.rates[0 ].idx = arsta->txrate.mcs; + arsta->txrate.flags =RATE_INFO_FLAGS_MCS ; + arsta->tx_info.status.rates[0 ].flags |=IEEE80211_TX_RC_MCS ; +if (sgi) { + arsta->txrate.flags |=RATE_INFO_FLAGS_SHORT_GI ; + arsta->tx_info.status.rates[0 ].flags |= +IEEE80211_TX_RC_SHORT_GI ; + } +break ; +case WMI_RATE_PREAMBLE_VHT : + arsta->txrate.mcs = mcs; +ieee80211_rate_set_vht (&arsta->tx_info.status.rates[0 ], mcs, nss); + arsta->txrate.flags =RATE_INFO_FLAGS_VHT_MCS ; + arsta->tx_info.status.rates[0 ].flags |=IEEE80211_TX_RC_VHT_MCS ; +if (sgi) { + arsta->txrate.flags |=RATE_INFO_FLAGS_SHORT_GI ; + arsta->tx_info.status.rates[0 ].flags |= +IEEE80211_TX_RC_SHORT_GI ; + } +break ; + } + + arsta->txrate.nss = nss; + arsta->txrate.bw =ath11k_bw_to_mac80211_bw (bw); + arsta->tx_info.status.rates[0 ].flags |=ath11k_bw_to_mac80211_bwflags (bw); + +memcpy (&arsta->last_txrate, &arsta->txrate,sizeof (struct rate_info )); + +if (succ_pkts) { + arsta->tx_info.flags =IEEE80211_TX_STAT_ACK ; + arsta->tx_info.status.rates[0 ].count =1 ; +ieee80211_tx_rate_update (ar->hw, sta, &arsta->tx_info); + } + +memset (peer_stats,0 ,sizeof (*peer_stats)); + + peer_stats->succ_pkts = succ_pkts; + peer_stats->succ_bytes = succ_bytes; + peer_stats->is_ampdu = is_ampdu; + peer_stats->duration = tx_duration; + peer_stats->ba_fails = +HTT_USR_CMPLTN_LONG_RETRY (usr_stats->cmpltn_cmn.flags) + +HTT_USR_CMPLTN_SHORT_RETRY (usr_stats->cmpltn_cmn.flags); + +if (ath11k_debug_is_extd_tx_stats_enabled (ar)) +ath11k_accumulate_per_peer_tx_stats (arsta, + peer_stats, rate_idx); + +spin_unlock_bh (&ab->base_lock); +rcu_read_unlock (); +} + +static void ath11k_htt_update_ppdu_stats (struct ath11k *ar, +struct htt_ppdu_stats *ppdu_stats) +{ +u8 user; + +for (user =0 ; user <HTT_PPDU_STATS_MAX_USERS -1 ; user++) +ath11k_update_per_peer_tx_stats (ar, ppdu_stats, user); +} + +static +struct htt_ppdu_stats_info *ath11k_dp_htt_get_ppdu_desc (struct ath11k *ar, +u32 ppdu_id) +{ +struct htt_ppdu_stats_info *ppdu_info =NULL ; + +spin_lock_bh (&ar->data_lock); +if (!list_empty (&ar->ppdu_stats_info)) { +list_for_each_entry (ppdu_info, &ar->ppdu_stats_info, list) { +if (ppdu_info && ppdu_info->ppdu_id == ppdu_id) { +spin_unlock_bh (&ar->data_lock); +return ppdu_info; + } + } + +if (ar->ppdu_stat_list_depth >HTT_PPDU_DESC_MAX_DEPTH ) { + ppdu_info =list_first_entry (&ar->ppdu_stats_info, +typeof (*ppdu_info), list); +list_del (&ppdu_info->list); + ar->ppdu_stat_list_depth--; +ath11k_htt_update_ppdu_stats (ar, &ppdu_info->ppdu_stats); +kfree (ppdu_info); + } + } +spin_unlock_bh (&ar->data_lock); + + ppdu_info =kzalloc (sizeof (*ppdu_info),GFP_KERNEL ); +if (!ppdu_info) +return NULL ; + +spin_lock_bh (&ar->data_lock); +list_add_tail (&ppdu_info->list, &ar->ppdu_stats_info); + ar->ppdu_stat_list_depth++; +spin_unlock_bh (&ar->data_lock); + +return ppdu_info; +} + +static int ath11k_htt_pull_ppdu_stats (struct ath11k_base *ab, +struct sk_buff *skb) +{ +struct ath11k_htt_ppdu_stats_msg *msg; +struct htt_ppdu_stats_info *ppdu_info; +struct ath11k *ar; +int ret; +u8 pdev_id; +u32 ppdu_id, len; + + msg = (struct ath11k_htt_ppdu_stats_msg *)skb->data; + len =FIELD_GET (HTT_T2H_PPDU_STATS_INFO_PAYLOAD_SIZE , msg->info); + pdev_id =FIELD_GET (HTT_T2H_PPDU_STATS_INFO_PDEV_ID , msg->info); + ppdu_id = msg->ppdu_id; + +rcu_read_lock (); + ar =ath11k_mac_get_ar_by_pdev_id (ab, pdev_id); +if (!ar) { + ret = -EINVAL ; + goto exit; + } + +if (ath11k_debug_is_pktlog_lite_mode_enabled (ar)) +trace_ath11k_htt_ppdu_stats (ar, skb->data, len); + + ppdu_info =ath11k_dp_htt_get_ppdu_desc (ar, ppdu_id); +if (!ppdu_info) { + ret = -EINVAL ; + goto exit; + } + + ppdu_info->ppdu_id = ppdu_id; + ret =ath11k_dp_htt_tlv_iter (ab, msg->data, len, + ath11k_htt_tlv_ppdu_stats_parse, + (void *)ppdu_info); +if (ret) { +ath11k_warn (ab,"Failed to parse tlv %d\n" , ret); + goto exit; + } + +exit: +rcu_read_unlock (); + +return ret; +} + +static void ath11k_htt_pktlog (struct ath11k_base *ab,struct sk_buff *skb) +{ +struct htt_pktlog_msg *data = (struct htt_pktlog_msg *)skb->data; +struct ath11k *ar; +u32 len; +u8 pdev_id; + + len =FIELD_GET (HTT_T2H_PPDU_STATS_INFO_PAYLOAD_SIZE , data->hdr); + +if (len >ATH11K_HTT_PKTLOG_MAX_SIZE ) { +ath11k_warn (ab,"htt pktlog buffer size %d, expected < %d\n" , + len, +ATH11K_HTT_PKTLOG_MAX_SIZE ); +return ; + } + + pdev_id =FIELD_GET (HTT_T2H_PPDU_STATS_INFO_PDEV_ID , data->hdr); + pdev_id =DP_HW2SW_MACID (pdev_id); + ar = ab->pdevs[pdev_id].ar; + +trace_ath11k_htt_pktlog (ar, data->payload, len); +} + +void ath11k_dp_htt_htc_t2h_msg_handler (struct ath11k_base *ab, +struct sk_buff *skb) +{ +struct ath11k_dp *dp = &ab->dp; +struct htt_resp_msg *resp = (struct htt_resp_msg *)skb->data; +enum htt_t2h_msg_type type =FIELD_GET (HTT_T2H_MSG_TYPE , *(u32 *)resp); +u16 peer_id; +u8 vdev_id; +u8 mac_addr[ETH_ALEN ]; +u16 peer_mac_h16; +u16 ast_hash; + +ath11k_dbg (ab,ATH11K_DBG_DP_HTT ,"dp_htt rx msg type :0x%0x\n" , type); + +switch (type) { +case HTT_T2H_MSG_TYPE_VERSION_CONF : + dp->htt_tgt_ver_major =FIELD_GET (HTT_T2H_VERSION_CONF_MAJOR , + resp->version_msg.version); + dp->htt_tgt_ver_minor =FIELD_GET (HTT_T2H_VERSION_CONF_MINOR , + resp->version_msg.version); +complete (&dp->htt_tgt_version_received); +break ; +case HTT_T2H_MSG_TYPE_PEER_MAP : + vdev_id =FIELD_GET (HTT_T2H_PEER_MAP_INFO_VDEV_ID , + resp->peer_map_ev.info); + peer_id =FIELD_GET (HTT_T2H_PEER_MAP_INFO_PEER_ID , + resp->peer_map_ev.info); + peer_mac_h16 =FIELD_GET (HTT_T2H_PEER_MAP_INFO1_MAC_ADDR_H16 , + resp->peer_map_ev.info1); +ath11k_dp_get_mac_addr (resp->peer_map_ev.mac_addr_l32, + peer_mac_h16, mac_addr); + ast_hash =FIELD_GET (HTT_T2H_PEER_MAP_INFO2_AST_HASH_VAL , + resp->peer_map_ev.info1); +ath11k_peer_map_event (ab, vdev_id, peer_id, mac_addr, ast_hash); +break ; +case HTT_T2H_MSG_TYPE_PEER_UNMAP : + peer_id =FIELD_GET (HTT_T2H_PEER_UNMAP_INFO_PEER_ID , + resp->peer_unmap_ev.info); +ath11k_peer_unmap_event (ab, peer_id); +break ; +case HTT_T2H_MSG_TYPE_PPDU_STATS_IND : +ath11k_htt_pull_ppdu_stats (ab, skb); +break ; +case HTT_T2H_MSG_TYPE_EXT_STATS_CONF : +ath11k_dbg_htt_ext_stats_handler (ab, skb); +break ; +case HTT_T2H_MSG_TYPE_PKTLOG : +ath11k_htt_pktlog (ab, skb); +break ; +default : +ath11k_warn (ab,"htt event %d not handled\n" , type); +break ; + } + +dev_kfree_skb_any (skb); +} + +static int ath11k_dp_rx_msdu_coalesce (struct ath11k *ar, +struct sk_buff_head *msdu_list, +struct sk_buff *first,struct sk_buff *last, +u8 l3pad_bytes,int msdu_len) +{ +struct sk_buff *skb; +struct ath11k_skb_rxcb *rxcb =ATH11K_SKB_RXCB (first); +struct hal_rx_desc *ldesc; +int space_extra; +int rem_len; +int buf_len; + +if (!rxcb->is_continuation) { +skb_put (first,HAL_RX_DESC_SIZE + l3pad_bytes + msdu_len); +skb_pull (first,HAL_RX_DESC_SIZE + l3pad_bytes); +return 0 ; + } + +if (WARN_ON_ONCE (msdu_len <= (DP_RX_BUFFER_SIZE - + (HAL_RX_DESC_SIZE + l3pad_bytes)))) { +skb_put (first,HAL_RX_DESC_SIZE + l3pad_bytes + msdu_len); +skb_pull (first,HAL_RX_DESC_SIZE + l3pad_bytes); +return 0 ; + } + + ldesc = (struct hal_rx_desc *)last->data; + rxcb->is_first_msdu =ath11k_dp_rx_h_msdu_end_first_msdu (ldesc); + rxcb->is_last_msdu =ath11k_dp_rx_h_msdu_end_last_msdu (ldesc); + +/* MSDU spans over multiple buffers because the length of the MSDU +* exceeds DP_RX_BUFFER_SIZE - HAL_RX_DESC_SIZE. So assume the data +* in the first buf is of length DP_RX_BUFFER_SIZE - HAL_RX_DESC_SIZE. +*/ +skb_put (first,DP_RX_BUFFER_SIZE ); +skb_pull (first,HAL_RX_DESC_SIZE + l3pad_bytes); + + space_extra = msdu_len - (DP_RX_BUFFER_SIZE +skb_tailroom (first)); +if (space_extra >0 && + (pskb_expand_head (first,0 , space_extra,GFP_ATOMIC ) <0 )) { +/* Free up all buffers of the MSDU */ +while ((skb =__skb_dequeue (msdu_list)) !=NULL ) { + rxcb =ATH11K_SKB_RXCB (skb); +if (!rxcb->is_continuation) { +dev_kfree_skb_any (skb); +break ; + } +dev_kfree_skb_any (skb); + } +return -ENOMEM ; + } + +/* When an MSDU spread over multiple buffers attention, MSDU_END and +* MPDU_END tlvs are valid only in the last buffer. Copy those tlvs. +*/ +ath11k_dp_rx_desc_end_tlv_copy (rxcb->rx_desc, ldesc); + + rem_len = msdu_len - + (DP_RX_BUFFER_SIZE -HAL_RX_DESC_SIZE - l3pad_bytes); +while ((skb =__skb_dequeue (msdu_list)) !=NULL && rem_len >0 ) { + rxcb =ATH11K_SKB_RXCB (skb); +if (rxcb->is_continuation) + buf_len =DP_RX_BUFFER_SIZE -HAL_RX_DESC_SIZE ; +else + buf_len = rem_len; + +if (buf_len > (DP_RX_BUFFER_SIZE -HAL_RX_DESC_SIZE )) { +WARN_ON_ONCE (1 ); +dev_kfree_skb_any (skb); +return -EINVAL ; + } + +skb_put (skb, buf_len +HAL_RX_DESC_SIZE ); +skb_pull (skb,HAL_RX_DESC_SIZE ); +skb_copy_from_linear_data (skb,skb_put (first, buf_len), + buf_len); +dev_kfree_skb_any (skb); + + rem_len -= buf_len; +if (!rxcb->is_continuation) +break ; + } + +return 0 ; +} + +static struct sk_buff *ath11k_dp_rx_get_msdu_last_buf (struct sk_buff_head *msdu_list, +struct sk_buff *first) +{ +struct sk_buff *skb; +struct ath11k_skb_rxcb *rxcb =ATH11K_SKB_RXCB (first); + +if (!rxcb->is_continuation) +return first; + + skb_queue_walk(msdu_list, skb) { + rxcb =ATH11K_SKB_RXCB (skb); +if (!rxcb->is_continuation) +return skb; + } + +return NULL ; +} + +static int ath11k_dp_rx_retrieve_amsdu (struct ath11k *ar, +struct sk_buff_head *msdu_list, +struct sk_buff_head *amsdu_list) +{ +struct sk_buff *msdu =skb_peek (msdu_list); +struct sk_buff *last_buf; +struct ath11k_skb_rxcb *rxcb; +struct ieee80211_hdr *hdr; +struct hal_rx_desc *rx_desc, *lrx_desc; +u16 msdu_len; +u8 l3_pad_bytes; +u8 *hdr_status; +int ret; + +if (!msdu) +return -ENOENT ; + + rx_desc = (struct hal_rx_desc *)msdu->data; + hdr_status =ath11k_dp_rx_h_80211_hdr (rx_desc); + hdr = (struct ieee80211_hdr *)hdr_status; +/* Process only data frames */ +if (!ieee80211_is_data (hdr->frame_control)) { +__skb_unlink (msdu, msdu_list); +dev_kfree_skb_any (msdu); +return -EINVAL ; + } + +do { +__skb_unlink (msdu, msdu_list); + last_buf =ath11k_dp_rx_get_msdu_last_buf (msdu_list, msdu); +if (!last_buf) { +ath11k_warn (ar->ab, +"No valid Rx buffer to access Atten/MSDU_END/MPDU_END tlvs\n" ); + ret = -EIO ; + goto free_out; + } + + rx_desc = (struct hal_rx_desc *)msdu->data; + lrx_desc = (struct hal_rx_desc *)last_buf->data; + +if (!ath11k_dp_rx_h_attn_msdu_done (lrx_desc)) { +ath11k_warn (ar->ab,"msdu_done bit in attention is not set\n" ); + ret = -EIO ; + goto free_out; + } + + rxcb =ATH11K_SKB_RXCB (msdu); + rxcb->rx_desc = rx_desc; + msdu_len =ath11k_dp_rx_h_msdu_start_msdu_len (rx_desc); + l3_pad_bytes =ath11k_dp_rx_h_msdu_end_l3pad (lrx_desc); + +if (!rxcb->is_continuation) { +skb_put (msdu,HAL_RX_DESC_SIZE + l3_pad_bytes + msdu_len); +skb_pull (msdu,HAL_RX_DESC_SIZE + l3_pad_bytes); + }else { + ret =ath11k_dp_rx_msdu_coalesce (ar, msdu_list, + msdu, last_buf, + l3_pad_bytes, msdu_len); +if (ret) { +ath11k_warn (ar->ab, +"failed to coalesce msdu rx buffer%d\n" , ret); + goto free_out; + } + } +__skb_queue_tail (amsdu_list, msdu); + +/* Should we also consider msdu_cnt from mpdu_meta while +* preparing amsdu list? +*/ +if (rxcb->is_last_msdu) +break ; + }while ((msdu =skb_peek (msdu_list)) !=NULL ); + +return 0 ; + +free_out: +dev_kfree_skb_any (msdu); +__skb_queue_purge (amsdu_list); + +return ret; +} + +static void ath11k_dp_rx_h_csum_offload (struct sk_buff *msdu) +{ +struct ath11k_skb_rxcb *rxcb =ATH11K_SKB_RXCB (msdu); +bool ip_csum_fail, l4_csum_fail; + + ip_csum_fail =ath11k_dp_rx_h_attn_ip_cksum_fail (rxcb->rx_desc); + l4_csum_fail =ath11k_dp_rx_h_attn_l4_cksum_fail (rxcb->rx_desc); + + msdu->ip_summed = (ip_csum_fail || l4_csum_fail) ? +CHECKSUM_NONE :CHECKSUM_UNNECESSARY ; +} + +static int ath11k_dp_rx_crypto_mic_len (struct ath11k *ar, +enum hal_encrypt_type enctype) +{ +switch (enctype) { +case HAL_ENCRYPT_TYPE_OPEN : +case HAL_ENCRYPT_TYPE_TKIP_NO_MIC : +case HAL_ENCRYPT_TYPE_TKIP_MIC : +return 0 ; +case HAL_ENCRYPT_TYPE_CCMP_128 : +return IEEE80211_CCMP_MIC_LEN ; +case HAL_ENCRYPT_TYPE_CCMP_256 : +return IEEE80211_CCMP_256_MIC_LEN ; +case HAL_ENCRYPT_TYPE_GCMP_128 : +case HAL_ENCRYPT_TYPE_AES_GCMP_256 : +return IEEE80211_GCMP_MIC_LEN ; +case HAL_ENCRYPT_TYPE_WEP_40 : +case HAL_ENCRYPT_TYPE_WEP_104 : +case HAL_ENCRYPT_TYPE_WEP_128 : +case HAL_ENCRYPT_TYPE_WAPI_GCM_SM4 : +case HAL_ENCRYPT_TYPE_WAPI : +break ; + } + +ath11k_warn (ar->ab,"unsupported encryption type %d for mic len\n" , enctype); +return 0 ; +} + +static int ath11k_dp_rx_crypto_param_len (struct ath11k *ar, +enum hal_encrypt_type enctype) +{ +switch (enctype) { +case HAL_ENCRYPT_TYPE_OPEN : +return 0 ; +case HAL_ENCRYPT_TYPE_TKIP_NO_MIC : +case HAL_ENCRYPT_TYPE_TKIP_MIC : +return IEEE80211_TKIP_IV_LEN ; +case HAL_ENCRYPT_TYPE_CCMP_128 : +return IEEE80211_CCMP_HDR_LEN ; +case HAL_ENCRYPT_TYPE_CCMP_256 : +return IEEE80211_CCMP_256_HDR_LEN ; +case HAL_ENCRYPT_TYPE_GCMP_128 : +case HAL_ENCRYPT_TYPE_AES_GCMP_256 : +return IEEE80211_GCMP_HDR_LEN ; +case HAL_ENCRYPT_TYPE_WEP_40 : +case HAL_ENCRYPT_TYPE_WEP_104 : +case HAL_ENCRYPT_TYPE_WEP_128 : +case HAL_ENCRYPT_TYPE_WAPI_GCM_SM4 : +case HAL_ENCRYPT_TYPE_WAPI : +break ; + } + +ath11k_warn (ar->ab,"unsupported encryption type %d\n" , enctype); +return 0 ; +} + +static int ath11k_dp_rx_crypto_icv_len (struct ath11k *ar, +enum hal_encrypt_type enctype) +{ +switch (enctype) { +case HAL_ENCRYPT_TYPE_OPEN : +case HAL_ENCRYPT_TYPE_CCMP_128 : +case HAL_ENCRYPT_TYPE_CCMP_256 : +case HAL_ENCRYPT_TYPE_GCMP_128 : +case HAL_ENCRYPT_TYPE_AES_GCMP_256 : +return 0 ; +case HAL_ENCRYPT_TYPE_TKIP_NO_MIC : +case HAL_ENCRYPT_TYPE_TKIP_MIC : +return IEEE80211_TKIP_ICV_LEN ; +case HAL_ENCRYPT_TYPE_WEP_40 : +case HAL_ENCRYPT_TYPE_WEP_104 : +case HAL_ENCRYPT_TYPE_WEP_128 : +case HAL_ENCRYPT_TYPE_WAPI_GCM_SM4 : +case HAL_ENCRYPT_TYPE_WAPI : +break ; + } + +ath11k_warn (ar->ab,"unsupported encryption type %d\n" , enctype); +return 0 ; +} + +static void ath11k_dp_rx_h_undecap_nwifi (struct ath11k *ar, +struct sk_buff *msdu, +u8 *first_hdr, +enum hal_encrypt_type enctype, +struct ieee80211_rx_status *status) +{ +struct ieee80211_hdr *hdr; +size_t hdr_len; +u8 da[ETH_ALEN ]; +u8 sa[ETH_ALEN ]; + +/* pull decapped header and copy SA & DA */ + hdr = (struct ieee80211_hdr *)msdu->data; +ether_addr_copy (da,ieee80211_get_DA (hdr)); +ether_addr_copy (sa,ieee80211_get_SA (hdr)); +skb_pull (msdu,ieee80211_hdrlen (hdr->frame_control)); + +/* push original 802.11 header */ + hdr = (struct ieee80211_hdr *)first_hdr; + hdr_len =ieee80211_hdrlen (hdr->frame_control); + +if (!(status->flag &RX_FLAG_IV_STRIPPED )) { +memcpy (skb_push (msdu, +ath11k_dp_rx_crypto_param_len (ar, enctype)), + (void *)hdr + hdr_len, +ath11k_dp_rx_crypto_param_len (ar, enctype)); + } + +memcpy (skb_push (msdu, hdr_len), hdr, hdr_len); + +/* original 802.11 header has a different DA and in +* case of 4addr it may also have different SA +*/ + hdr = (struct ieee80211_hdr *)msdu->data; +ether_addr_copy (ieee80211_get_DA (hdr), da); +ether_addr_copy (ieee80211_get_SA (hdr), sa); +} + +static void ath11k_dp_rx_h_undecap_raw (struct ath11k *ar,struct sk_buff *msdu, +enum hal_encrypt_type enctype, +struct ieee80211_rx_status *status, +bool decrypted) +{ +struct ath11k_skb_rxcb *rxcb =ATH11K_SKB_RXCB (msdu); +struct ieee80211_hdr *hdr; +size_t hdr_len; +size_t crypto_len; + +if (!rxcb->is_first_msdu || + !(rxcb->is_first_msdu && rxcb->is_last_msdu)) { +WARN_ON_ONCE (1 ); +return ; + } + +skb_trim (msdu, msdu->len -FCS_LEN ); + +if (!decrypted) +return ; + + hdr = (void *)msdu->data; + +/* Tail */ +if (status->flag &RX_FLAG_IV_STRIPPED ) { +skb_trim (msdu, msdu->len - +ath11k_dp_rx_crypto_mic_len (ar, enctype)); + +skb_trim (msdu, msdu->len - +ath11k_dp_rx_crypto_icv_len (ar, enctype)); + }else { +/* MIC */ +if (status->flag &RX_FLAG_MIC_STRIPPED ) +skb_trim (msdu, msdu->len - +ath11k_dp_rx_crypto_mic_len (ar, enctype)); + +/* ICV */ +if (status->flag &RX_FLAG_ICV_STRIPPED ) +skb_trim (msdu, msdu->len - +ath11k_dp_rx_crypto_icv_len (ar, enctype)); + } + +/* MMIC */ +if ((status->flag &RX_FLAG_MMIC_STRIPPED ) && + !ieee80211_has_morefrags (hdr->frame_control) && + enctype ==HAL_ENCRYPT_TYPE_TKIP_MIC ) +skb_trim (msdu, msdu->len -IEEE80211_CCMP_MIC_LEN ); + +/* Head */ +if (status->flag &RX_FLAG_IV_STRIPPED ) { + hdr_len =ieee80211_hdrlen (hdr->frame_control); + crypto_len =ath11k_dp_rx_crypto_param_len (ar, enctype); + +memmove ((void *)msdu->data + crypto_len, + (void *)msdu->data, hdr_len); +skb_pull (msdu, crypto_len); + } +} + +static void *ath11k_dp_rx_h_find_rfc1042 (struct ath11k *ar, +struct sk_buff *msdu, +enum hal_encrypt_type enctype) +{ +struct ath11k_skb_rxcb *rxcb =ATH11K_SKB_RXCB (msdu); +struct ieee80211_hdr *hdr; +size_t hdr_len, crypto_len; +void *rfc1042; +bool is_amsdu; + + is_amsdu = !(rxcb->is_first_msdu && rxcb->is_last_msdu); + hdr = (struct ieee80211_hdr *)ath11k_dp_rx_h_80211_hdr (rxcb->rx_desc); + rfc1042 = hdr; + +if (rxcb->is_first_msdu) { + hdr_len =ieee80211_hdrlen (hdr->frame_control); + crypto_len =ath11k_dp_rx_crypto_param_len (ar, enctype); + + rfc1042 += hdr_len + crypto_len; + } + +if (is_amsdu) + rfc1042 +=sizeof (struct ath11k_dp_amsdu_subframe_hdr ); + +return rfc1042; +} + +static void ath11k_dp_rx_h_undecap_eth (struct ath11k *ar, +struct sk_buff *msdu, +u8 *first_hdr, +enum hal_encrypt_type enctype, +struct ieee80211_rx_status *status) +{ +struct ieee80211_hdr *hdr; +struct ethhdr *eth; +size_t hdr_len; +u8 da[ETH_ALEN ]; +u8 sa[ETH_ALEN ]; +void *rfc1042; + + rfc1042 =ath11k_dp_rx_h_find_rfc1042 (ar, msdu, enctype); +if (WARN_ON_ONCE (!rfc1042)) +return ; + +/* pull decapped header and copy SA & DA */ + eth = (struct ethhdr *)msdu->data; +ether_addr_copy (da, eth->h_dest); +ether_addr_copy (sa, eth->h_source); +skb_pull (msdu,sizeof (struct ethhdr )); + +/* push rfc1042/llc/snap */ +memcpy (skb_push (msdu,sizeof (struct ath11k_dp_rfc1042_hdr )), rfc1042, +sizeof (struct ath11k_dp_rfc1042_hdr )); + +/* push original 802.11 header */ + hdr = (struct ieee80211_hdr *)first_hdr; + hdr_len =ieee80211_hdrlen (hdr->frame_control); + +if (!(status->flag &RX_FLAG_IV_STRIPPED )) { +memcpy (skb_push (msdu, +ath11k_dp_rx_crypto_param_len (ar, enctype)), + (void *)hdr + hdr_len, +ath11k_dp_rx_crypto_param_len (ar, enctype)); + } + +memcpy (skb_push (msdu, hdr_len), hdr, hdr_len); + +/* original 802.11 header has a different DA and in +* case of 4addr it may also have different SA +*/ + hdr = (struct ieee80211_hdr *)msdu->data; +ether_addr_copy (ieee80211_get_DA (hdr), da); +ether_addr_copy (ieee80211_get_SA (hdr), sa); +} + +static void ath11k_dp_rx_h_undecap (struct ath11k *ar,struct sk_buff *msdu, +struct hal_rx_desc *rx_desc, +enum hal_encrypt_type enctype, +struct ieee80211_rx_status *status, +bool decrypted) +{ +u8 *first_hdr; +u8 decap; + + first_hdr =ath11k_dp_rx_h_80211_hdr (rx_desc); + decap =ath11k_dp_rx_h_mpdu_start_decap_type (rx_desc); + +switch (decap) { +case DP_RX_DECAP_TYPE_NATIVE_WIFI : +ath11k_dp_rx_h_undecap_nwifi (ar, msdu, first_hdr, + enctype, status); +break ; +case DP_RX_DECAP_TYPE_RAW : +ath11k_dp_rx_h_undecap_raw (ar, msdu, enctype, status, + decrypted); +break ; +case DP_RX_DECAP_TYPE_ETHERNET2_DIX : +ath11k_dp_rx_h_undecap_eth (ar, msdu, first_hdr, + enctype, status); +break ; +case DP_RX_DECAP_TYPE_8023 : +/* TODO: Handle undecap for these formats */ +break ; + } +} + +static void ath11k_dp_rx_h_mpdu (struct ath11k *ar, +struct sk_buff_head *amsdu_list, +struct hal_rx_desc *rx_desc, +struct ieee80211_rx_status *rx_status) +{ +struct ieee80211_hdr *hdr; +enum hal_encrypt_type enctype; +struct sk_buff *last_msdu; +struct sk_buff *msdu; +struct ath11k_skb_rxcb *last_rxcb; +bool is_decrypted; +u32 err_bitmap; +u8 *qos; + +if (skb_queue_empty (amsdu_list)) +return ; + + hdr = (struct ieee80211_hdr *)ath11k_dp_rx_h_80211_hdr (rx_desc); + +/* Each A-MSDU subframe will use the original header as the base and be +* reported as a separate MSDU so strip the A-MSDU bit from QoS Ctl. +*/ +if (ieee80211_is_data_qos (hdr->frame_control)) { + qos =ieee80211_get_qos_ctl (hdr); + qos[0 ] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT ; + } + + is_decrypted =ath11k_dp_rx_h_attn_is_decrypted (rx_desc); + enctype =ath11k_dp_rx_h_mpdu_start_enctype (rx_desc); + +/* Some attention flags are valid only in the last MSDU. */ + last_msdu =skb_peek_tail (amsdu_list); + last_rxcb =ATH11K_SKB_RXCB (last_msdu); + + err_bitmap =ath11k_dp_rx_h_attn_mpdu_err (last_rxcb->rx_desc); + +/* Clear per-MPDU flags while leaving per-PPDU flags intact. */ + rx_status->flag &= ~(RX_FLAG_FAILED_FCS_CRC | +RX_FLAG_MMIC_ERROR | +RX_FLAG_DECRYPTED | +RX_FLAG_IV_STRIPPED | +RX_FLAG_MMIC_STRIPPED ); + +if (err_bitmap &DP_RX_MPDU_ERR_FCS ) + rx_status->flag |=RX_FLAG_FAILED_FCS_CRC ; + +if (err_bitmap &DP_RX_MPDU_ERR_TKIP_MIC ) + rx_status->flag |=RX_FLAG_MMIC_ERROR ; + +if (is_decrypted) + rx_status->flag |=RX_FLAG_DECRYPTED |RX_FLAG_MMIC_STRIPPED | +RX_FLAG_MIC_STRIPPED |RX_FLAG_ICV_STRIPPED ; + + skb_queue_walk(amsdu_list, msdu) { +ath11k_dp_rx_h_csum_offload (msdu); +ath11k_dp_rx_h_undecap (ar, msdu, rx_desc, + enctype, rx_status, is_decrypted); + } +} + +static void ath11k_dp_rx_h_rate (struct ath11k *ar,struct hal_rx_desc *rx_desc, +struct ieee80211_rx_status *rx_status) +{ +struct ieee80211_supported_band *sband; +enum rx_msdu_start_pkt_type pkt_type; +u8 bw; +u8 rate_mcs, nss; +u8 sgi; +bool is_cck; + + pkt_type =ath11k_dp_rx_h_msdu_start_pkt_type (rx_desc); + bw =ath11k_dp_rx_h_msdu_start_rx_bw (rx_desc); + rate_mcs =ath11k_dp_rx_h_msdu_start_rate_mcs (rx_desc); + nss =ath11k_dp_rx_h_msdu_start_nss (rx_desc); + sgi =ath11k_dp_rx_h_msdu_start_sgi (rx_desc); + +switch (pkt_type) { +case RX_MSDU_START_PKT_TYPE_11A : +case RX_MSDU_START_PKT_TYPE_11B : + is_cck = (pkt_type ==RX_MSDU_START_PKT_TYPE_11B ); + sband = &ar->mac.sbands[rx_status->band]; + rx_status->rate_idx =ath11k_mac_hw_rate_to_idx (sband, rate_mcs, + is_cck); +break ; +case RX_MSDU_START_PKT_TYPE_11N : + rx_status->encoding =RX_ENC_HT ; +if (rate_mcs >ATH11K_HT_MCS_MAX ) { +ath11k_warn (ar->ab, +"Received with invalid mcs in HT mode %d\n" , + rate_mcs); +break ; + } + rx_status->rate_idx = rate_mcs + (8 * (nss -1 )); +if (sgi) + rx_status->enc_flags |=RX_ENC_FLAG_SHORT_GI ; + rx_status->bw =ath11k_bw_to_mac80211_bw (bw); +break ; +case RX_MSDU_START_PKT_TYPE_11AC : + rx_status->encoding =RX_ENC_VHT ; + rx_status->rate_idx = rate_mcs; +if (rate_mcs >ATH11K_VHT_MCS_MAX ) { +ath11k_warn (ar->ab, +"Received with invalid mcs in VHT mode %d\n" , + rate_mcs); +break ; + } + rx_status->nss = nss; +if (sgi) + rx_status->enc_flags |=RX_ENC_FLAG_SHORT_GI ; + rx_status->bw =ath11k_bw_to_mac80211_bw (bw); +break ; +case RX_MSDU_START_PKT_TYPE_11AX : + rx_status->rate_idx = rate_mcs; +if (rate_mcs >ATH11K_HE_MCS_MAX ) { +ath11k_warn (ar->ab, +"Received with invalid mcs in HE mode %d\n" , + rate_mcs); +break ; + } + rx_status->encoding =RX_ENC_HE ; + rx_status->nss = nss; + rx_status->bw =ath11k_bw_to_mac80211_bw (bw); +break ; + } +} + +static void ath11k_dp_rx_h_ppdu (struct ath11k *ar,struct hal_rx_desc *rx_desc, +struct ieee80211_rx_status *rx_status) +{ +u8 channel_num; + + rx_status->freq =0 ; + rx_status->rate_idx =0 ; + rx_status->nss =0 ; + rx_status->encoding =RX_ENC_LEGACY ; + rx_status->bw =RATE_INFO_BW_20 ; + + rx_status->flag |=RX_FLAG_NO_SIGNAL_VAL ; + + channel_num =ath11k_dp_rx_h_msdu_start_freq (rx_desc); + +if (channel_num >=1 && channel_num <=14 ) { + rx_status->band =NL80211_BAND_2GHZ ; + }else if (channel_num >=36 && channel_num <=173 ) { + rx_status->band =NL80211_BAND_5GHZ ; + }else { +ath11k_warn (ar->ab,"Unsupported Channel info received %d\n" , + channel_num); +return ; + } + + rx_status->freq =ieee80211_channel_to_frequency (channel_num, + rx_status->band); + +ath11k_dp_rx_h_rate (ar, rx_desc, rx_status); +} + +static void ath11k_dp_rx_process_amsdu (struct ath11k *ar, +struct sk_buff_head *amsdu_list, +struct ieee80211_rx_status *rx_status) +{ +struct sk_buff *first; +struct ath11k_skb_rxcb *rxcb; +struct hal_rx_desc *rx_desc; +bool first_mpdu; + +if (skb_queue_empty (amsdu_list)) +return ; + + first =skb_peek (amsdu_list); + rxcb =ATH11K_SKB_RXCB (first); + rx_desc = rxcb->rx_desc; + + first_mpdu =ath11k_dp_rx_h_attn_first_mpdu (rx_desc); +if (first_mpdu) +ath11k_dp_rx_h_ppdu (ar, rx_desc, rx_status); + +ath11k_dp_rx_h_mpdu (ar, amsdu_list, rx_desc, rx_status); +} + +static char *ath11k_print_get_tid (struct ieee80211_hdr *hdr,char *out, +size_t size) +{ +u8 *qc; +int tid; + +if (!ieee80211_is_data_qos (hdr->frame_control)) +return "" ; + + qc =ieee80211_get_qos_ctl (hdr); + tid = *qc &IEEE80211_QOS_CTL_TID_MASK ; +snprintf (out, size,"tid %d" , tid); + +return out; +} + +static void ath11k_dp_rx_deliver_msdu (struct ath11k *ar,struct napi_struct *napi, +struct sk_buff *msdu) +{ +struct ieee80211_rx_status *status; +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data; +char tid[32 ]; + + status =IEEE80211_SKB_RXCB (msdu); + +ath11k_dbg (ar->ab,ATH11K_DBG_DATA , +"rx skb %pK len %u peer %pM %s %s sn %u %s%s%s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i mic-err %i amsdu-more %i\n" , + msdu, + msdu->len, +ieee80211_get_SA (hdr), +ath11k_print_get_tid (hdr, tid,sizeof (tid)), +is_multicast_ether_addr (ieee80211_get_DA (hdr)) ? +"mcast" :"ucast" , + (__le16_to_cpu (hdr->seq_ctrl) &IEEE80211_SCTL_SEQ ) >>4 , + (status->encoding ==RX_ENC_LEGACY ) ?"legacy" :"" , + (status->encoding ==RX_ENC_HT ) ?"ht" :"" , + (status->encoding ==RX_ENC_VHT ) ?"vht" :"" , + (status->encoding ==RX_ENC_HE ) ?"he" :"" , + (status->bw ==RATE_INFO_BW_40 ) ?"40" :"" , + (status->bw ==RATE_INFO_BW_80 ) ?"80" :"" , + (status->bw ==RATE_INFO_BW_160 ) ?"160" :"" , + status->enc_flags &RX_ENC_FLAG_SHORT_GI ?"sgi " :"" , + status->rate_idx, + status->nss, + status->freq, + status->band, status->flag, + !!(status->flag &RX_FLAG_FAILED_FCS_CRC ), + !!(status->flag &RX_FLAG_MMIC_ERROR ), + !!(status->flag &RX_FLAG_AMSDU_MORE )); + +/* TODO: trace rx packet */ + +ieee80211_rx_napi (ar->hw,NULL , msdu, napi); +} + +static void ath11k_dp_rx_pre_deliver_amsdu (struct ath11k *ar, +struct sk_buff_head *amsdu_list, +struct ieee80211_rx_status *rxs) +{ +struct sk_buff *msdu; +struct sk_buff *first_subframe; +struct ieee80211_rx_status *status; + + first_subframe =skb_peek (amsdu_list); + + skb_queue_walk(amsdu_list, msdu) { +/* Setup per-MSDU flags */ +if (skb_queue_empty (amsdu_list)) + rxs->flag &= ~RX_FLAG_AMSDU_MORE ; +else + rxs->flag |=RX_FLAG_AMSDU_MORE ; + +if (msdu == first_subframe) { + first_subframe =NULL ; + rxs->flag &= ~RX_FLAG_ALLOW_SAME_PN ; + }else { + rxs->flag |=RX_FLAG_ALLOW_SAME_PN ; + } + rxs->flag |=RX_FLAG_SKIP_MONITOR ; + + status =IEEE80211_SKB_RXCB (msdu); + *status = *rxs; + } +} + +static void ath11k_dp_rx_process_pending_packets (struct ath11k_base *ab, +struct napi_struct *napi, +struct sk_buff_head *pending_q, +int *quota,u8 mac_id) +{ +struct ath11k *ar; +struct sk_buff *msdu; +struct ath11k_pdev *pdev; + +if (skb_queue_empty (pending_q)) +return ; + + ar = ab->pdevs[mac_id].ar; + +rcu_read_lock (); + pdev =rcu_dereference (ab->pdevs_active[mac_id]); + +while (*quota && (msdu =__skb_dequeue (pending_q))) { +if (!pdev) { +dev_kfree_skb_any (msdu); +continue ; + } + +ath11k_dp_rx_deliver_msdu (ar, napi, msdu); + (*quota)--; + } +rcu_read_unlock (); +} + +int ath11k_dp_process_rx (struct ath11k_base *ab,int mac_id, +struct napi_struct *napi,struct sk_buff_head *pending_q, +int budget) +{ +struct ath11k *ar = ab->pdevs[mac_id].ar; +struct ath11k_pdev_dp *dp = &ar->dp; +struct ieee80211_rx_status *rx_status = &dp->rx_status; +struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring; +struct hal_srng *srng; +struct hal_rx_meta_info meta_info; +struct sk_buff *msdu; +struct sk_buff_head msdu_list; +struct sk_buff_head amsdu_list; +struct ath11k_skb_rxcb *rxcb; +u32 *rx_desc; +int buf_id; +int num_buffs_reaped =0 ; +int quota = budget; +int ret; +bool done = false; + +/* Process any pending packets from the previous napi poll. +* Note: All msdu's in this pending_q corresponds to the same mac id +* due to pdev based reo dest mapping and also since each irq group id +* maps to specific reo dest ring. +*/ +ath11k_dp_rx_process_pending_packets (ab, napi, pending_q, "a, + mac_id); + +/* If all quota is exhausted by processing the pending_q, +* Wait for the next napi poll to reap the new info +*/ +if (!quota) + goto exit; + +__skb_queue_head_init (&msdu_list); + + srng = &ab->hal.srng_list[dp->reo_dst_ring.ring_id]; + +spin_lock_bh (&srng->lock); + +ath11k_hal_srng_access_begin (ab, srng); + +try_again: +while ((rx_desc =ath11k_hal_srng_dst_get_next_entry (ab, srng))) { +memset (&meta_info,0 ,sizeof (meta_info)); +ath11k_hal_rx_parse_dst_ring_desc (ab, rx_desc, &meta_info); + + buf_id =FIELD_GET (DP_RXDMA_BUF_COOKIE_BUF_ID , + meta_info.msdu_meta.cookie); +spin_lock_bh (&rx_ring->idr_lock); + msdu =idr_find (&rx_ring->bufs_idr, buf_id); +if (!msdu) { +ath11k_warn (ab,"frame rx with invalid buf_id %d\n" , + buf_id); +spin_unlock_bh (&rx_ring->idr_lock); +continue ; + } + +idr_remove (&rx_ring->bufs_idr, buf_id); +spin_unlock_bh (&rx_ring->idr_lock); + + rxcb =ATH11K_SKB_RXCB (msdu); +dma_unmap_single (ab->dev, rxcb->paddr, + msdu->len +skb_tailroom (msdu), +DMA_FROM_DEVICE ); + + num_buffs_reaped++; + +if (meta_info.push_reason != +HAL_REO_DEST_RING_PUSH_REASON_ROUTING_INSTRUCTION ) { +/* TODO: Check if the msdu can be sent up for processing */ +dev_kfree_skb_any (msdu); + ab->soc_stats.hal_reo_error[dp->reo_dst_ring.ring_id]++; +continue ; + } + + rxcb->is_first_msdu = meta_info.msdu_meta.first; + rxcb->is_last_msdu = meta_info.msdu_meta.last; + rxcb->is_continuation = meta_info.msdu_meta.continuation; + rxcb->mac_id = mac_id; +__skb_queue_tail (&msdu_list, msdu); + +/* Stop reaping from the ring once quota is exhausted +* and we've received all msdu's in the the AMSDU. The +* additional msdu's reaped in excess of quota here would +* be pushed into the pending queue to be processed during +* the next napi poll. +* Note: More profiling can be done to see the impact on +* pending_q and throughput during various traffic & density +* and how use of budget instead of remaining quota affects it. +*/ +if (num_buffs_reaped >= quota && rxcb->is_last_msdu && + !rxcb->is_continuation) { + done = true; +break ; + } + } + +/* Hw might have updated the head pointer after we cached it. +* In this case, even though there are entries in the ring we'll +* get rx_desc NULL. Give the read another try with updated cached +* head pointer so that we can reap complete MPDU in the current +* rx processing. +*/ +if (!done &&ath11k_hal_srng_dst_num_free (ab, srng, true)) { +ath11k_hal_srng_access_end (ab, srng); + goto try_again; + } + +ath11k_hal_srng_access_end (ab, srng); + +spin_unlock_bh (&srng->lock); + +if (!num_buffs_reaped) + goto exit; + +/* Should we reschedule it later if we are not able to replenish all +* the buffers? +*/ +ath11k_dp_rxbufs_replenish (ab, mac_id, rx_ring, num_buffs_reaped, +HAL_RX_BUF_RBM_SW3_BM ,GFP_ATOMIC ); + +rcu_read_lock (); +if (!rcu_dereference (ab->pdevs_active[mac_id])) { +__skb_queue_purge (&msdu_list); + goto rcu_unlock; + } + +if (test_bit (ATH11K_CAC_RUNNING , &ar->dev_flags)) { +__skb_queue_purge (&msdu_list); + goto rcu_unlock; + } + +while (!skb_queue_empty (&msdu_list)) { +__skb_queue_head_init (&amsdu_list); + ret =ath11k_dp_rx_retrieve_amsdu (ar, &msdu_list, &amsdu_list); +if (ret) { +if (ret == -EIO ) { +ath11k_err (ab,"rx ring got corrupted %d\n" , ret); +__skb_queue_purge (&msdu_list); +/* Should stop processing any more rx in +* future from this ring? +*/ + goto rcu_unlock; + } + +/* A-MSDU retrieval got failed due to non-fatal condition, +* continue processing with the next msdu. +*/ +continue ; + } + +ath11k_dp_rx_process_amsdu (ar, &amsdu_list, rx_status); + +ath11k_dp_rx_pre_deliver_amsdu (ar, &amsdu_list, rx_status); +skb_queue_splice_tail (&amsdu_list, pending_q); + } + +while (quota && (msdu =__skb_dequeue (pending_q))) { +ath11k_dp_rx_deliver_msdu (ar, napi, msdu); + quota--; + } + +rcu_unlock: +rcu_read_unlock (); +exit: +return budget - quota; +} + +static void ath11k_dp_rx_update_peer_stats (struct ath11k_sta *arsta, +struct hal_rx_mon_ppdu_info *ppdu_info) +{ +struct ath11k_rx_peer_stats *rx_stats = arsta->rx_stats; +u32 num_msdu; + +if (!rx_stats) +return ; + + num_msdu = ppdu_info->tcp_msdu_count + ppdu_info->tcp_ack_msdu_count + + ppdu_info->udp_msdu_count + ppdu_info->other_msdu_count; + + rx_stats->num_msdu += num_msdu; + rx_stats->tcp_msdu_count += ppdu_info->tcp_msdu_count + + ppdu_info->tcp_ack_msdu_count; + rx_stats->udp_msdu_count += ppdu_info->udp_msdu_count; + rx_stats->other_msdu_count += ppdu_info->other_msdu_count; + +if (ppdu_info->preamble_type ==HAL_RX_PREAMBLE_11A || + ppdu_info->preamble_type ==HAL_RX_PREAMBLE_11B ) { + ppdu_info->nss =1 ; + ppdu_info->mcs =HAL_RX_MAX_MCS ; + ppdu_info->tid =IEEE80211_NUM_TIDS ; + } + +if (ppdu_info->nss >0 && ppdu_info->nss <=HAL_RX_MAX_NSS ) + rx_stats->nss_count[ppdu_info->nss -1 ] += num_msdu; + +if (ppdu_info->mcs <=HAL_RX_MAX_MCS ) + rx_stats->mcs_count[ppdu_info->mcs] += num_msdu; + +if (ppdu_info->gi <HAL_RX_GI_MAX ) + rx_stats->gi_count[ppdu_info->gi] += num_msdu; + +if (ppdu_info->bw <HAL_RX_BW_MAX ) + rx_stats->bw_count[ppdu_info->bw] += num_msdu; + +if (ppdu_info->ldpc <HAL_RX_SU_MU_CODING_MAX ) + rx_stats->coding_count[ppdu_info->ldpc] += num_msdu; + +if (ppdu_info->tid <=IEEE80211_NUM_TIDS ) + rx_stats->tid_count[ppdu_info->tid] += num_msdu; + +if (ppdu_info->preamble_type <HAL_RX_PREAMBLE_MAX ) + rx_stats->pream_cnt[ppdu_info->preamble_type] += num_msdu; + +if (ppdu_info->reception_type <HAL_RX_RECEPTION_TYPE_MAX ) + rx_stats->reception_type[ppdu_info->reception_type] += num_msdu; + +if (ppdu_info->is_stbc) + rx_stats->stbc_count += num_msdu; + +if (ppdu_info->beamformed) + rx_stats->beamformed_count += num_msdu; + +if (ppdu_info->num_mpdu_fcs_ok >1 ) + rx_stats->ampdu_msdu_count += num_msdu; +else + rx_stats->non_ampdu_msdu_count += num_msdu; + + rx_stats->num_mpdu_fcs_ok += ppdu_info->num_mpdu_fcs_ok; + rx_stats->num_mpdu_fcs_err += ppdu_info->num_mpdu_fcs_err; + + arsta->rssi_comb = ppdu_info->rssi_comb; + rx_stats->rx_duration += ppdu_info->rx_duration; + arsta->rx_duration = rx_stats->rx_duration; +} + +static struct sk_buff *ath11k_dp_rx_alloc_mon_status_buf (struct ath11k_base *ab, +struct dp_rxdma_ring *rx_ring, +int *buf_id,gfp_t gfp) +{ +struct sk_buff *skb; +dma_addr_t paddr; + + skb =dev_alloc_skb (DP_RX_BUFFER_SIZE + +DP_RX_BUFFER_ALIGN_SIZE ); + +if (!skb) + goto fail_alloc_skb; + +if (!IS_ALIGNED ((unsigned long )skb->data, +DP_RX_BUFFER_ALIGN_SIZE )) { +skb_pull (skb,PTR_ALIGN (skb->data,DP_RX_BUFFER_ALIGN_SIZE ) - + skb->data); + } + + paddr =dma_map_single (ab->dev, skb->data, + skb->len +skb_tailroom (skb), +DMA_BIDIRECTIONAL ); +if (unlikely (dma_mapping_error (ab->dev, paddr))) + goto fail_free_skb; + +spin_lock_bh (&rx_ring->idr_lock); + *buf_id =idr_alloc (&rx_ring->bufs_idr, skb,0 , + rx_ring->bufs_max, gfp); +spin_unlock_bh (&rx_ring->idr_lock); +if (*buf_id <0 ) + goto fail_dma_unmap; + +ATH11K_SKB_RXCB (skb)->paddr = paddr; +return skb; + +fail_dma_unmap: +dma_unmap_single (ab->dev, paddr, skb->len +skb_tailroom (skb), +DMA_BIDIRECTIONAL ); +fail_free_skb: +dev_kfree_skb_any (skb); +fail_alloc_skb: +return NULL ; +} + +int ath11k_dp_rx_mon_status_bufs_replenish (struct ath11k_base *ab,int mac_id, +struct dp_rxdma_ring *rx_ring, +int req_entries, +enum hal_rx_buf_return_buf_manager mgr, +gfp_t gfp) +{ +struct hal_srng *srng; +u32 *desc; +struct sk_buff *skb; +int num_free; +int num_remain; +int buf_id; +u32 cookie; +dma_addr_t paddr; + + req_entries =min (req_entries, rx_ring->bufs_max); + + srng = &ab->hal.srng_list[rx_ring->refill_buf_ring.ring_id]; + +spin_lock_bh (&srng->lock); + +ath11k_hal_srng_access_begin (ab, srng); + + num_free =ath11k_hal_srng_src_num_free (ab, srng, true); + + req_entries =min (num_free, req_entries); + num_remain = req_entries; + +while (num_remain >0 ) { + skb =ath11k_dp_rx_alloc_mon_status_buf (ab, rx_ring, + &buf_id, gfp); +if (!skb) +break ; + paddr =ATH11K_SKB_RXCB (skb)->paddr; + + desc =ath11k_hal_srng_src_get_next_entry (ab, srng); +if (!desc) + goto fail_desc_get; + + cookie =FIELD_PREP (DP_RXDMA_BUF_COOKIE_PDEV_ID , mac_id) | +FIELD_PREP (DP_RXDMA_BUF_COOKIE_BUF_ID , buf_id); + + num_remain--; + +ath11k_hal_rx_buf_addr_info_set (desc, paddr, cookie, mgr); + } + +ath11k_hal_srng_access_end (ab, srng); + +spin_unlock_bh (&srng->lock); + +return req_entries - num_remain; + +fail_desc_get: +spin_lock_bh (&rx_ring->idr_lock); +idr_remove (&rx_ring->bufs_idr, buf_id); +spin_unlock_bh (&rx_ring->idr_lock); +dma_unmap_single (ab->dev, paddr, skb->len +skb_tailroom (skb), +DMA_BIDIRECTIONAL ); +dev_kfree_skb_any (skb); +ath11k_hal_srng_access_end (ab, srng); +spin_unlock_bh (&srng->lock); + +return req_entries - num_remain; +} + +static int ath11k_dp_rx_reap_mon_status_ring (struct ath11k_base *ab,int mac_id, +int *budget,struct sk_buff_head *skb_list) +{ +struct ath11k *ar = ab->pdevs[mac_id].ar; +struct ath11k_pdev_dp *dp = &ar->dp; +struct dp_rxdma_ring *rx_ring = &dp->rx_mon_status_refill_ring; +struct hal_srng *srng; +void *rx_mon_status_desc; +struct sk_buff *skb; +struct ath11k_skb_rxcb *rxcb; +struct hal_tlv_hdr *tlv; +u32 cookie; +int buf_id; +dma_addr_t paddr; +u8 rbm; +int num_buffs_reaped =0 ; + + srng = &ab->hal.srng_list[rx_ring->refill_buf_ring.ring_id]; + +spin_lock_bh (&srng->lock); + +ath11k_hal_srng_access_begin (ab, srng); +while (*budget) { + *budget -=1 ; + rx_mon_status_desc = +ath11k_hal_srng_src_peek (ab, srng); +if (!rx_mon_status_desc) +break ; + +ath11k_hal_rx_buf_addr_info_get (rx_mon_status_desc, &paddr, + &cookie, &rbm); +if (paddr) { + buf_id =FIELD_GET (DP_RXDMA_BUF_COOKIE_BUF_ID , cookie); + +spin_lock_bh (&rx_ring->idr_lock); + skb =idr_find (&rx_ring->bufs_idr, buf_id); +if (!skb) { +ath11k_warn (ab,"rx monitor status with invalid buf_id %d\n" , + buf_id); +spin_unlock_bh (&rx_ring->idr_lock); +continue ; + } + +idr_remove (&rx_ring->bufs_idr, buf_id); +spin_unlock_bh (&rx_ring->idr_lock); + + rxcb =ATH11K_SKB_RXCB (skb); + +dma_sync_single_for_cpu (ab->dev, rxcb->paddr, + skb->len +skb_tailroom (skb), +DMA_FROM_DEVICE ); + +dma_unmap_single (ab->dev, rxcb->paddr, + skb->len +skb_tailroom (skb), +DMA_BIDIRECTIONAL ); + + tlv = (struct hal_tlv_hdr *)skb->data; +if (FIELD_GET (HAL_TLV_HDR_TAG , tlv->tl) != +HAL_RX_STATUS_BUFFER_DONE ) { +ath11k_hal_srng_src_get_next_entry (ab, srng); +continue ; + } + +__skb_queue_tail (skb_list, skb); + } + + skb =ath11k_dp_rx_alloc_mon_status_buf (ab, rx_ring, + &buf_id,GFP_ATOMIC ); + +if (!skb) { +ath11k_hal_rx_buf_addr_info_set (rx_mon_status_desc,0 ,0 , +HAL_RX_BUF_RBM_SW3_BM ); + num_buffs_reaped++; +break ; + } + rxcb =ATH11K_SKB_RXCB (skb); + + cookie =FIELD_PREP (DP_RXDMA_BUF_COOKIE_PDEV_ID , mac_id) | +FIELD_PREP (DP_RXDMA_BUF_COOKIE_BUF_ID , buf_id); + +ath11k_hal_rx_buf_addr_info_set (rx_mon_status_desc, rxcb->paddr, + cookie,HAL_RX_BUF_RBM_SW3_BM ); +ath11k_hal_srng_src_get_next_entry (ab, srng); + num_buffs_reaped++; + } +ath11k_hal_srng_access_end (ab, srng); +spin_unlock_bh (&srng->lock); + +return num_buffs_reaped; +} + +int ath11k_dp_rx_process_mon_status (struct ath11k_base *ab,int mac_id, +struct napi_struct *napi,int budget) +{ +struct ath11k *ar = ab->pdevs[mac_id].ar; +enum hal_rx_mon_status hal_status; +struct sk_buff *skb; +struct sk_buff_head skb_list; +struct hal_rx_mon_ppdu_info ppdu_info; +struct ath11k_peer *peer; +struct ath11k_sta *arsta; +int num_buffs_reaped =0 ; + +__skb_queue_head_init (&skb_list); + + num_buffs_reaped =ath11k_dp_rx_reap_mon_status_ring (ab, mac_id, &budget, + &skb_list); +if (!num_buffs_reaped) + goto exit; + +while ((skb =__skb_dequeue (&skb_list))) { +memset (&ppdu_info,0 ,sizeof (ppdu_info)); + ppdu_info.peer_id =HAL_INVALID_PEERID ; + +if (ath11k_debug_is_pktlog_rx_stats_enabled (ar)) +trace_ath11k_htt_rxdesc (ar, skb->data,DP_RX_BUFFER_SIZE ); + + hal_status =ath11k_hal_rx_parse_mon_status (ab, &ppdu_info, skb); + +if (ppdu_info.peer_id ==HAL_INVALID_PEERID || + hal_status !=HAL_RX_MON_STATUS_PPDU_DONE ) { +dev_kfree_skb_any (skb); +continue ; + } + +rcu_read_lock (); +spin_lock_bh (&ab->base_lock); + peer =ath11k_peer_find_by_id (ab, ppdu_info.peer_id); + +if (!peer || !peer->sta) { +ath11k_warn (ab,"failed to find the peer with peer_id %d\n" , + ppdu_info.peer_id); +spin_unlock_bh (&ab->base_lock); +rcu_read_unlock (); +dev_kfree_skb_any (skb); +continue ; + } + + arsta = (struct ath11k_sta *)peer->sta->drv_priv; +ath11k_dp_rx_update_peer_stats (arsta, &ppdu_info); + +if (ath11k_debug_is_pktlog_peer_valid (ar, peer->addr)) +trace_ath11k_htt_rxdesc (ar, skb->data,DP_RX_BUFFER_SIZE ); + +spin_unlock_bh (&ab->base_lock); +rcu_read_unlock (); + +dev_kfree_skb_any (skb); + } +exit: +return num_buffs_reaped; +} + +static int ath11k_dp_rx_link_desc_return (struct ath11k_base *ab, +u32 *link_desc, +enum hal_wbm_rel_bm_act action) +{ +struct ath11k_dp *dp = &ab->dp; +struct hal_srng *srng; +u32 *desc; +int ret =0 ; + + srng = &ab->hal.srng_list[dp->wbm_desc_rel_ring.ring_id]; + +spin_lock_bh (&srng->lock); + +ath11k_hal_srng_access_begin (ab, srng); + + desc =ath11k_hal_srng_src_get_next_entry (ab, srng); +if (!desc) { + ret = -ENOBUFS ; + goto exit; + } + +ath11k_hal_rx_msdu_link_desc_set (ab, (void *)desc, (void *)link_desc, + action); + +exit: +ath11k_hal_srng_access_end (ab, srng); + +spin_unlock_bh (&srng->lock); + +return ret; +} + +static void ath11k_dp_rx_frag_h_mpdu (struct ath11k *ar, +struct sk_buff *msdu, +struct hal_rx_desc *rx_desc, +struct ieee80211_rx_status *rx_status) +{ +u8 rx_channel; +enum hal_encrypt_type enctype; +bool is_decrypted; +u32 err_bitmap; + + is_decrypted =ath11k_dp_rx_h_attn_is_decrypted (rx_desc); + enctype =ath11k_dp_rx_h_mpdu_start_enctype (rx_desc); + err_bitmap =ath11k_dp_rx_h_attn_mpdu_err (rx_desc); + +if (err_bitmap &DP_RX_MPDU_ERR_FCS ) + rx_status->flag |=RX_FLAG_FAILED_FCS_CRC ; + +if (err_bitmap &DP_RX_MPDU_ERR_TKIP_MIC ) + rx_status->flag |=RX_FLAG_MMIC_ERROR ; + + rx_status->encoding =RX_ENC_LEGACY ; + rx_status->bw =RATE_INFO_BW_20 ; + + rx_status->flag |=RX_FLAG_NO_SIGNAL_VAL ; + + rx_channel =ath11k_dp_rx_h_msdu_start_freq (rx_desc); + +if (rx_channel >=1 && rx_channel <=14 ) { + rx_status->band =NL80211_BAND_2GHZ ; + }else if (rx_channel >=36 && rx_channel <=173 ) { + rx_status->band =NL80211_BAND_5GHZ ; + }else { +ath11k_warn (ar->ab,"Unsupported Channel info received %d\n" , + rx_channel); +return ; + } + + rx_status->freq =ieee80211_channel_to_frequency (rx_channel, + rx_status->band); +ath11k_dp_rx_h_rate (ar, rx_desc, rx_status); + +/* Rx fragments are received in raw mode */ +skb_trim (msdu, msdu->len -FCS_LEN ); + +if (is_decrypted) { + rx_status->flag |=RX_FLAG_DECRYPTED |RX_FLAG_MIC_STRIPPED ; +skb_trim (msdu, msdu->len - +ath11k_dp_rx_crypto_mic_len (ar, enctype)); + } +} + +static int +ath11k_dp_process_rx_err_buf (struct ath11k *ar,struct napi_struct *napi, +int buf_id,bool frag) +{ +struct ath11k_pdev_dp *dp = &ar->dp; +struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring; +struct ieee80211_rx_status rx_status = {0 }; +struct sk_buff *msdu; +struct ath11k_skb_rxcb *rxcb; +struct ieee80211_rx_status *status; +struct hal_rx_desc *rx_desc; +u16 msdu_len; + +spin_lock_bh (&rx_ring->idr_lock); + msdu =idr_find (&rx_ring->bufs_idr, buf_id); +if (!msdu) { +ath11k_warn (ar->ab,"rx err buf with invalid buf_id %d\n" , + buf_id); +spin_unlock_bh (&rx_ring->idr_lock); +return -EINVAL ; + } + +idr_remove (&rx_ring->bufs_idr, buf_id); +spin_unlock_bh (&rx_ring->idr_lock); + + rxcb =ATH11K_SKB_RXCB (msdu); +dma_unmap_single (ar->ab->dev, rxcb->paddr, + msdu->len +skb_tailroom (msdu), +DMA_FROM_DEVICE ); + +if (!frag) { +/* Process only rx fragments below, and drop +* msdu's indicated due to error reasons. +*/ +dev_kfree_skb_any (msdu); +return 0 ; + } + +rcu_read_lock (); +if (!rcu_dereference (ar->ab->pdevs_active[ar->pdev_idx])) { +dev_kfree_skb_any (msdu); + goto exit; + } + +if (test_bit (ATH11K_CAC_RUNNING , &ar->dev_flags)) { +dev_kfree_skb_any (msdu); + goto exit; + } + + rx_desc = (struct hal_rx_desc *)msdu->data; + msdu_len =ath11k_dp_rx_h_msdu_start_msdu_len (rx_desc); +skb_put (msdu,HAL_RX_DESC_SIZE + msdu_len); +skb_pull (msdu,HAL_RX_DESC_SIZE ); + +ath11k_dp_rx_frag_h_mpdu (ar, msdu, rx_desc, &rx_status); + + status =IEEE80211_SKB_RXCB (msdu); + + *status = rx_status; + +ath11k_dp_rx_deliver_msdu (ar, napi, msdu); + +exit: +rcu_read_unlock (); +return 0 ; +} + +int ath11k_dp_process_rx_err (struct ath11k_base *ab,struct napi_struct *napi, +int budget) +{ +struct hal_rx_msdu_meta meta[HAL_NUM_RX_MSDUS_PER_LINK_DESC ]; +struct dp_link_desc_bank *link_desc_banks; +enum hal_rx_buf_return_buf_manager rbm; +int tot_n_bufs_reaped, quota, ret, i; +int n_bufs_reaped[MAX_RADIOS ] = {0 }; +struct hal_rx_meta_info meta_info; +struct dp_rxdma_ring *rx_ring; +struct dp_srng *reo_except; +u32 desc_bank, num_msdus; +struct hal_srng *srng; +struct ath11k_dp *dp; +void *link_desc_va; +int buf_id, mac_id; +struct ath11k *ar; +dma_addr_t paddr; +u32 *desc; +bool is_frag; + + tot_n_bufs_reaped =0 ; + quota = budget; + + dp = &ab->dp; + reo_except = &dp->reo_except_ring; + link_desc_banks = dp->link_desc_banks; + + srng = &ab->hal.srng_list[reo_except->ring_id]; + +spin_lock_bh (&srng->lock); + +ath11k_hal_srng_access_begin (ab, srng); + +while (budget && + (desc =ath11k_hal_srng_dst_get_next_entry (ab, srng))) { + ab->soc_stats.err_ring_pkts++; + ret =ath11k_hal_desc_reo_parse_err (ab, desc, &paddr, + &desc_bank); +if (ret) { +ath11k_warn (ab,"failed to parse error reo desc %d\n" , + ret); +continue ; + } + link_desc_va = link_desc_banks[desc_bank].vaddr + + (paddr - link_desc_banks[desc_bank].paddr); +ath11k_hal_rx_msdu_link_info_get (link_desc_va, &num_msdus, meta, + &rbm); +if (rbm !=HAL_RX_BUF_RBM_WBM_IDLE_DESC_LIST && + rbm !=HAL_RX_BUF_RBM_SW3_BM ) { + ab->soc_stats.invalid_rbm++; +ath11k_warn (ab,"invalid return buffer manager %d\n" , rbm); +ath11k_dp_rx_link_desc_return (ab, desc, +HAL_WBM_REL_BM_ACT_REL_MSDU ); +continue ; + } + +memset (&meta_info,0 ,sizeof (meta_info)); +ath11k_hal_rx_parse_dst_ring_desc (ab, desc, &meta_info); + + is_frag = meta_info.mpdu_meta.frag; + +/* Return the link desc back to wbm idle list */ +ath11k_dp_rx_link_desc_return (ab, desc, +HAL_WBM_REL_BM_ACT_PUT_IN_IDLE ); + +for (i =0 ; i < num_msdus; i++) { + buf_id =FIELD_GET (DP_RXDMA_BUF_COOKIE_BUF_ID , + meta[i].cookie); + + mac_id =FIELD_GET (DP_RXDMA_BUF_COOKIE_PDEV_ID , + meta[i].cookie); + + ar = ab->pdevs[mac_id].ar; + +if (!ath11k_dp_process_rx_err_buf (ar, napi, buf_id, + is_frag)) { + n_bufs_reaped[mac_id]++; + tot_n_bufs_reaped++; + } + } + +if (tot_n_bufs_reaped >= quota) { + tot_n_bufs_reaped = quota; + goto exit; + } + + budget = quota - tot_n_bufs_reaped; + } + +exit: +ath11k_hal_srng_access_end (ab, srng); + +spin_unlock_bh (&srng->lock); + +for (i =0 ; i < ab->num_radios; i++) { +if (!n_bufs_reaped[i]) +continue ; + + ar = ab->pdevs[i].ar; + rx_ring = &ar->dp.rx_refill_buf_ring; + +ath11k_dp_rxbufs_replenish (ab, i, rx_ring, n_bufs_reaped[i], +HAL_RX_BUF_RBM_SW3_BM ,GFP_ATOMIC ); + } + +return tot_n_bufs_reaped; +} + +static void ath11k_dp_rx_null_q_desc_sg_drop (struct ath11k *ar, +int msdu_len, +struct sk_buff_head *msdu_list) +{ +struct sk_buff *skb, *tmp; +struct ath11k_skb_rxcb *rxcb; +int n_buffs; + + n_buffs =DIV_ROUND_UP (msdu_len, + (DP_RX_BUFFER_SIZE -HAL_RX_DESC_SIZE )); + + skb_queue_walk_safe(msdu_list, skb, tmp) { + rxcb =ATH11K_SKB_RXCB (skb); +if (rxcb->err_rel_src ==HAL_WBM_REL_SRC_MODULE_REO && + rxcb->err_code ==HAL_REO_DEST_RING_ERROR_CODE_DESC_ADDR_ZERO ) { +if (!n_buffs) +break ; +__skb_unlink (skb, msdu_list); +dev_kfree_skb_any (skb); + n_buffs--; + } + } +} + +static int ath11k_dp_rx_h_null_q_desc (struct ath11k *ar,struct sk_buff *msdu, +struct ieee80211_rx_status *status, +struct sk_buff_head *msdu_list) +{ +struct sk_buff_head amsdu_list; +u16 msdu_len; +struct hal_rx_desc *desc = (struct hal_rx_desc *)msdu->data; +u8 l3pad_bytes; +struct ath11k_skb_rxcb *rxcb =ATH11K_SKB_RXCB (msdu); + + msdu_len =ath11k_dp_rx_h_msdu_start_msdu_len (desc); + +if ((msdu_len +HAL_RX_DESC_SIZE ) >DP_RX_BUFFER_SIZE ) { +/* First buffer will be freed by the caller, so deduct it's length */ + msdu_len = msdu_len - (DP_RX_BUFFER_SIZE -HAL_RX_DESC_SIZE ); +ath11k_dp_rx_null_q_desc_sg_drop (ar, msdu_len, msdu_list); +return -EINVAL ; + } + +if (!ath11k_dp_rx_h_attn_msdu_done (desc)) { +ath11k_warn (ar->ab, +"msdu_done bit not set in null_q_des processing\n" ); +__skb_queue_purge (msdu_list); +return -EIO ; + } + +/* Handle NULL queue descriptor violations arising out a missing +* REO queue for a given peer or a given TID. This typically +* may happen if a packet is received on a QOS enabled TID before the +* ADDBA negotiation for that TID, when the TID queue is setup. Or +* it may also happen for MC/BC frames if they are not routed to the +* non-QOS TID queue, in the absence of any other default TID queue. +* This error can show up both in a REO destination or WBM release ring. +*/ + +__skb_queue_head_init (&amsdu_list); + + rxcb->is_first_msdu =ath11k_dp_rx_h_msdu_end_first_msdu (desc); + rxcb->is_last_msdu =ath11k_dp_rx_h_msdu_end_last_msdu (desc); + + l3pad_bytes =ath11k_dp_rx_h_msdu_end_l3pad (desc); + +if ((HAL_RX_DESC_SIZE + l3pad_bytes + msdu_len) >DP_RX_BUFFER_SIZE ) +return -EINVAL ; + +skb_put (msdu,HAL_RX_DESC_SIZE + l3pad_bytes + msdu_len); +skb_pull (msdu,HAL_RX_DESC_SIZE + l3pad_bytes); + +ath11k_dp_rx_h_ppdu (ar, desc, status); + +__skb_queue_tail (&amsdu_list, msdu); + +ath11k_dp_rx_h_mpdu (ar, &amsdu_list, desc, status); + +/* Please note that caller will having the access to msdu and completing +* rx with mac80211. Need not worry about cleaning up amsdu_list. +*/ + +return 0 ; +} + +static bool ath11k_dp_rx_h_reo_err (struct ath11k *ar,struct sk_buff *msdu, +struct ieee80211_rx_status *status, +struct sk_buff_head *msdu_list) +{ +struct ath11k_skb_rxcb *rxcb =ATH11K_SKB_RXCB (msdu); +bool drop = false; + + ar->ab->soc_stats.reo_error[rxcb->err_code]++; + +switch (rxcb->err_code) { +case HAL_REO_DEST_RING_ERROR_CODE_DESC_ADDR_ZERO : +if (ath11k_dp_rx_h_null_q_desc (ar, msdu, status, msdu_list)) + drop = true; +break ; +default : +/* TODO: Review other errors and process them to mac80211 +* as appropriate. +*/ + drop = true; +break ;
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
_______________________________________________
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
Part of the diff is not shown here. View the raw message.
PATCH v3 18/49 ath11k: add dp_rx.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/dp_rx.h | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
drivers/net/wireless/ath/ath11k/dp_rx.h new file +84 -0
@@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ +#ifndef ATH11K_DP_RX_H +#define ATH11K_DP_RX_H + +#include "core.h" +#include "rx_desc.h" +#include "debug.h" + +#define DP_RX_MPDU_ERR_FCS BIT(0) +#define DP_RX_MPDU_ERR_DECRYPT BIT(1) +#define DP_RX_MPDU_ERR_TKIP_MIC BIT(2) +#define DP_RX_MPDU_ERR_AMSDU_ERR BIT(3) +#define DP_RX_MPDU_ERR_OVERFLOW BIT(4) +#define DP_RX_MPDU_ERR_MSDU_LEN BIT(5) +#define DP_RX_MPDU_ERR_MPDU_LEN BIT(6) +#define DP_RX_MPDU_ERR_UNENCRYPTED_FRAME BIT(7) + +enum dp_rx_decap_type { +DP_RX_DECAP_TYPE_RAW , +DP_RX_DECAP_TYPE_NATIVE_WIFI , +DP_RX_DECAP_TYPE_ETHERNET2_DIX , +DP_RX_DECAP_TYPE_8023 , +}; + +struct ath11k_dp_amsdu_subframe_hdr { +u8 dst[ETH_ALEN ]; +u8 src[ETH_ALEN ]; +__be16 len; +} __packed; + +struct ath11k_dp_rfc1042_hdr { +u8 llc_dsap; +u8 llc_ssap; +u8 llc_ctrl; +u8 snap_oui[3 ]; +__be16 snap_type; +} __packed; + +int ath11k_dp_rx_ampdu_start (struct ath11k *ar, +struct ieee80211_ampdu_params *params); +int ath11k_dp_rx_ampdu_stop (struct ath11k *ar, +struct ieee80211_ampdu_params *params); +void ath11k_peer_rx_tid_cleanup (struct ath11k *ar,struct ath11k_peer *peer); +int ath11k_peer_rx_tid_setup (struct ath11k *ar,const u8 *peer_mac,int vdev_id, +u8 tid,u32 ba_win_sz,u16 ssn); +void ath11k_dp_htt_htc_t2h_msg_handler (struct ath11k_base *ab, +struct sk_buff *skb); +int ath11k_dp_rx_pdev_alloc (struct ath11k_base *ab,int pdev_idx); +void ath11k_dp_rx_pdev_free (struct ath11k_base *ab,int pdev_idx); +void ath11k_dp_reo_cmd_list_cleanup (struct ath11k_base *ab); +void ath11k_dp_process_reo_status (struct ath11k_base *ab); +int ath11k_dp_process_rxdma_err (struct ath11k_base *ab,int mac_id,int budget); +int ath11k_dp_rx_process_wbm_err (struct ath11k_base *ab, +struct napi_struct *napi,int budget); +int ath11k_dp_process_rx_err (struct ath11k_base *ab,struct napi_struct *napi, +int budget); +int ath11k_dp_process_rx (struct ath11k_base *ab,int mac_id, +struct napi_struct *napi,struct sk_buff_head *pending_q, +int budget); +int ath11k_dp_rxbufs_replenish (struct ath11k_base *ab,int mac_id, +struct dp_rxdma_ring *rx_ring, +int req_entries, +enum hal_rx_buf_return_buf_manager mgr, +gfp_t gfp); +int ath11k_dp_htt_tlv_iter (struct ath11k_base *ab,const void *ptr,size_t len, +int (*iter)(struct ath11k_base *ar,u16 tag,u16 len, +const void *ptr,void *data), +void *data); +int ath11k_dp_rx_process_mon_rings (struct ath11k_base *ab,int mac_id, +struct napi_struct *napi,int budget); +int ath11k_dp_rx_process_mon_status (struct ath11k_base *ab,int mac_id, +struct napi_struct *napi,int budget); +int ath11k_dp_rx_mon_status_bufs_replenish (struct ath11k_base *ab,int mac_id, +struct dp_rxdma_ring *rx_ring, +int req_entries, +enum hal_rx_buf_return_buf_manager mgr, +gfp_t gfp); +int ath11k_dp_rx_pdev_mon_detach (struct ath11k *ar); +int ath11k_dp_rx_pdev_mon_attach (struct ath11k *ar); + +#endif /* ATH11K_DP_RX_H */
_______________________________________________
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v3 19/49 ath11k: add dp_tx.c
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/dp_tx.c | 943 ++++++++++++++++++++++++++++++++ 1 file changed, 943 insertions(+)
drivers/net/wireless/ath/ath11k/dp_tx.c new file +943 -0
@@ -0,0 +1,943 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#include "core.h" +#include "dp_tx.h" +#include "debug.h" +#include "hw.h" + +/* NOTE: Any of the mapped ring id value must not exceed DP_TCL_NUM_RING_MAX */ +static const u8 +ath11k_txq_tcl_ring_map[ATH11K_HW_MAX_QUEUES ] = {0x0 ,0x1 ,0x2 ,0x2 }; + +static enum hal_tcl_encap_type +ath11k_dp_tx_get_encap_type (struct ath11k_vif *arvif,struct sk_buff *skb) +{ +/* TODO: Determine encap type based on vif_type and configuration */ +return HAL_TCL_ENCAP_TYPE_NATIVE_WIFI ; +} + +static void ath11k_dp_tx_encap_nwifi (struct sk_buff *skb) +{ +struct ieee80211_hdr *hdr = (void *)skb->data; +u8 *qos_ctl; + +if (!ieee80211_is_data_qos (hdr->frame_control)) +return ; + + qos_ctl =ieee80211_get_qos_ctl (hdr); +memmove (skb->data +IEEE80211_QOS_CTL_LEN , + skb->data, (void *)qos_ctl - (void *)skb->data); +skb_pull (skb,IEEE80211_QOS_CTL_LEN ); + + hdr = (void *)skb->data; + hdr->frame_control &= ~__cpu_to_le16 (IEEE80211_STYPE_QOS_DATA ); +} + +static u8 ath11k_dp_tx_get_tid (struct sk_buff *skb) +{ +struct ieee80211_hdr *hdr = (void *)skb->data; + +if (!ieee80211_is_data_qos (hdr->frame_control)) +return HAL_DESC_REO_NON_QOS_TID ; +else +return skb->priority &IEEE80211_QOS_CTL_TID_MASK ; +} + +static enum hal_encrypt_type ath11k_dp_tx_get_encrypt_type (u32 cipher) +{ +switch (cipher) { +case WLAN_CIPHER_SUITE_WEP40 : +return HAL_ENCRYPT_TYPE_WEP_40 ; +case WLAN_CIPHER_SUITE_WEP104 : +return HAL_ENCRYPT_TYPE_WEP_104 ; +case WLAN_CIPHER_SUITE_TKIP : +return HAL_ENCRYPT_TYPE_TKIP_MIC ; +case WLAN_CIPHER_SUITE_CCMP : +return HAL_ENCRYPT_TYPE_CCMP_128 ; +case WLAN_CIPHER_SUITE_CCMP_256 : +return HAL_ENCRYPT_TYPE_CCMP_256 ; +case WLAN_CIPHER_SUITE_GCMP : +return HAL_ENCRYPT_TYPE_GCMP_128 ; +case WLAN_CIPHER_SUITE_GCMP_256 : +return HAL_ENCRYPT_TYPE_AES_GCMP_256 ; +default : +return HAL_ENCRYPT_TYPE_OPEN ; + } +} + +int ath11k_dp_tx (struct ath11k *ar,struct ath11k_vif *arvif, +struct sk_buff *skb) +{ +struct ath11k_base *ab = ar->ab; +struct ath11k_dp *dp = &ab->dp; +struct hal_tx_info ti = {0 }; +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb); +struct ath11k_skb_cb *skb_cb =ATH11K_SKB_CB (skb); +struct hal_srng *tcl_ring; +struct ieee80211_hdr *hdr = (void *)skb->data; +struct dp_tx_ring *tx_ring; +u8 cached_desc[HAL_TCL_DESC_LEN ]; +void *hal_tcl_desc; +u8 pool_id; +u8 hal_ring_id; +int ret; + +if (test_bit (ATH11K_FLAG_CRASH_FLUSH , &ar->ab->dev_flags)) +return -ESHUTDOWN ; + +if (!ieee80211_is_data (hdr->frame_control)) +return -ENOTSUPP ; + + pool_id =skb_get_queue_mapping (skb) & (ATH11K_HW_MAX_QUEUES -1 ); + ti.ring_id = ath11k_txq_tcl_ring_map[pool_id]; + + tx_ring = &dp->tx_ring[ti.ring_id]; + +spin_lock_bh (&tx_ring->tx_idr_lock); + ret =idr_alloc (&tx_ring->txbuf_idr, skb,0 , +DP_TX_IDR_SIZE -1 ,GFP_ATOMIC ); +spin_unlock_bh (&tx_ring->tx_idr_lock); + +if (ret <0 ) +return -ENOSPC ; + + ti.desc_id =FIELD_PREP (DP_TX_DESC_ID_MAC_ID , ar->pdev_idx) | +FIELD_PREP (DP_TX_DESC_ID_MSDU_ID , ret) | +FIELD_PREP (DP_TX_DESC_ID_POOL_ID , pool_id); + ti.encap_type =ath11k_dp_tx_get_encap_type (arvif, skb); + ti.meta_data_flags = arvif->tcl_metadata; + +if (info->control.hw_key) + ti.encrypt_type = +ath11k_dp_tx_get_encrypt_type (info->control.hw_key->cipher); +else + ti.encrypt_type =HAL_ENCRYPT_TYPE_OPEN ; + + ti.addr_search_flags = arvif->hal_addr_search_flags; + ti.search_type = arvif->search_type; + ti.type =HAL_TCL_DESC_TYPE_BUFFER ; + ti.pkt_offset =0 ; + ti.lmac_id = ar->lmac_id; + ti.bss_ast_hash = arvif->ast_hash; + ti.dscp_tid_tbl_idx =0 ; + +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + ti.flags0 |=FIELD_PREP (HAL_TCL_DATA_CMD_INFO1_IP4_CKSUM_EN ,1 ) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO1_UDP4_CKSUM_EN ,1 ) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO1_UDP6_CKSUM_EN ,1 ) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO1_TCP4_CKSUM_EN ,1 ) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO1_TCP6_CKSUM_EN ,1 ); + } + +if (ieee80211_vif_is_mesh (arvif->vif)) + ti.flags1 |=FIELD_PREP (HAL_TCL_DATA_CMD_INFO2_MESH_ENABLE ,1 ); + + ti.flags1 |=FIELD_PREP (HAL_TCL_DATA_CMD_INFO2_TID_OVERWRITE ,1 ); + + ti.tid =ath11k_dp_tx_get_tid (skb); + +switch (ti.encap_type) { +case HAL_TCL_ENCAP_TYPE_NATIVE_WIFI : +ath11k_dp_tx_encap_nwifi (skb); +break ; +case HAL_TCL_ENCAP_TYPE_RAW : +/* TODO: for CHECKSUM_PARTIAL case in raw mode, HW checksum offload +* is not applicable, hence manual checksum calculation using +* skb_checksum_help() is needed +*/ +case HAL_TCL_ENCAP_TYPE_ETHERNET : +case HAL_TCL_ENCAP_TYPE_802_3 : +/* TODO: Take care of other encap modes as well */ + ret = -EINVAL ; + goto fail_remove_idr; + } + + ti.paddr =dma_map_single (ab->dev, skb->data, skb->len,DMA_TO_DEVICE ); +if (dma_mapping_error (ab->dev, ti.paddr)) { +ath11k_warn (ab,"failed to DMA map data Tx buffer\n" ); + ret = -ENOMEM ; + goto fail_remove_idr; + } + + ti.data_len = skb->len; + skb_cb->paddr = ti.paddr; + skb_cb->vif = arvif->vif; + skb_cb->ar = ar; + +memset (cached_desc,0 ,HAL_TCL_DESC_LEN ); + +ath11k_hal_tx_cmd_desc_setup (ab, cached_desc, &ti); + + hal_ring_id = tx_ring->tcl_data_ring.ring_id; + tcl_ring = &ab->hal.srng_list[hal_ring_id]; + +spin_lock_bh (&tcl_ring->lock); + +ath11k_hal_srng_access_begin (ab, tcl_ring); + + hal_tcl_desc = (void *)ath11k_hal_srng_src_get_next_entry (ab, tcl_ring); +if (!hal_tcl_desc) { +/* NOTE: It is highly unlikely we'll be running out of tcl_ring +* desc because the desc is directly enqueued onto hw queue. +* So add tx packet throttling logic in future if required. +*/ +ath11k_hal_srng_access_end (ab, tcl_ring); +spin_unlock_bh (&tcl_ring->lock); + ret = -ENOMEM ; + goto fail_unmap_dma; + } + +ath11k_hal_tx_desc_sync (cached_desc, hal_tcl_desc); + +ath11k_hal_srng_access_end (ab, tcl_ring); + +spin_unlock_bh (&tcl_ring->lock); + +spin_lock_bh (&tx_ring->tx_idr_lock); + tx_ring->num_tx_pending++; +spin_unlock_bh (&tx_ring->tx_idr_lock); + +atomic_inc (&ar->dp.num_tx_pending); + +return 0 ; + +fail_unmap_dma: +dma_unmap_single (ab->dev, ti.paddr, ti.data_len,DMA_TO_DEVICE ); + +fail_remove_idr: +spin_lock_bh (&tx_ring->tx_idr_lock); +idr_remove (&tx_ring->txbuf_idr, +FIELD_GET (DP_TX_DESC_ID_MSDU_ID , ti.desc_id)); +spin_unlock_bh (&tx_ring->tx_idr_lock); + +return ret; +} + +static void ath11k_dp_tx_free_txbuf (struct ath11k_base *ab,u8 mac_id, +int msdu_id, +struct dp_tx_ring *tx_ring) +{ +struct ath11k *ar; +struct sk_buff *msdu; +struct ath11k_skb_cb *skb_cb; + +spin_lock_bh (&tx_ring->tx_idr_lock); + msdu =idr_find (&tx_ring->txbuf_idr, msdu_id); +if (!msdu) { +ath11k_warn (ab,"tx completion for unknown msdu_id %d\n" , + msdu_id); +spin_unlock_bh (&tx_ring->tx_idr_lock); +return ; + } + + skb_cb =ATH11K_SKB_CB (msdu); + +idr_remove (&tx_ring->txbuf_idr, msdu_id); + tx_ring->num_tx_pending--; +spin_unlock_bh (&tx_ring->tx_idr_lock); + +dma_unmap_single (ab->dev, skb_cb->paddr, msdu->len,DMA_TO_DEVICE ); +dev_kfree_skb_any (msdu); + + ar = ab->pdevs[mac_id].ar; +if (atomic_dec_and_test (&ar->dp.num_tx_pending)) +wake_up (&ar->dp.tx_empty_waitq); +} + +static void +ath11k_dp_tx_htt_tx_complete_buf (struct ath11k_base *ab, +struct dp_tx_ring *tx_ring, +struct ath11k_dp_htt_wbm_tx_status *ts) +{ +struct sk_buff *msdu; +struct ieee80211_tx_info *info; +struct ath11k_skb_cb *skb_cb; +struct ath11k *ar; + +spin_lock_bh (&tx_ring->tx_idr_lock); + msdu =idr_find (&tx_ring->txbuf_idr, ts->msdu_id); +if (!msdu) { +ath11k_warn (ab,"htt tx completion for unknown msdu_id %d\n" , + ts->msdu_id); +spin_unlock_bh (&tx_ring->tx_idr_lock); +return ; + } + + skb_cb =ATH11K_SKB_CB (msdu); + info =IEEE80211_SKB_CB (msdu); + + ar = skb_cb->ar; + +idr_remove (&tx_ring->txbuf_idr, ts->msdu_id); + tx_ring->num_tx_pending--; +spin_unlock_bh (&tx_ring->tx_idr_lock); + +if (atomic_dec_and_test (&ar->dp.num_tx_pending)) +wake_up (&ar->dp.tx_empty_waitq); + +dma_unmap_single (ab->dev, skb_cb->paddr, msdu->len,DMA_TO_DEVICE ); + +memset (&info->status,0 ,sizeof (info->status)); + +if (ts->acked) { +if (!(info->flags &IEEE80211_TX_CTL_NO_ACK )) { + info->flags |=IEEE80211_TX_STAT_ACK ; + info->status.ack_signal =ATH11K_DEFAULT_NOISE_FLOOR + + ts->ack_rssi; + info->status.is_valid_ack_signal = true; + }else { + info->flags |=IEEE80211_TX_STAT_NOACK_TRANSMITTED ; + } + } + +ieee80211_tx_status (ar->hw, msdu); +} + +static void +ath11k_dp_tx_process_htt_tx_complete (struct ath11k_base *ab, +void *desc,u8 mac_id, +u32 msdu_id,struct dp_tx_ring *tx_ring) +{ +struct htt_tx_wbm_completion *status_desc; +struct ath11k_dp_htt_wbm_tx_status ts = {0 }; +enum hal_wbm_htt_tx_comp_status wbm_status; + + status_desc = desc +HTT_TX_WBM_COMP_STATUS_OFFSET ; + + wbm_status =FIELD_GET (HTT_TX_WBM_COMP_INFO0_STATUS , + status_desc->info0); + +switch (wbm_status) { +case HAL_WBM_REL_HTT_TX_COMP_STATUS_OK : +case HAL_WBM_REL_HTT_TX_COMP_STATUS_DROP : +case HAL_WBM_REL_HTT_TX_COMP_STATUS_TTL : + ts.acked = (wbm_status ==HAL_WBM_REL_HTT_TX_COMP_STATUS_OK ); + ts.msdu_id = msdu_id; + ts.ack_rssi =FIELD_GET (HTT_TX_WBM_COMP_INFO1_ACK_RSSI , + status_desc->info1); +ath11k_dp_tx_htt_tx_complete_buf (ab, tx_ring, &ts); +break ; +case HAL_WBM_REL_HTT_TX_COMP_STATUS_REINJ : +case HAL_WBM_REL_HTT_TX_COMP_STATUS_INSPECT : +ath11k_dp_tx_free_txbuf (ab, mac_id, msdu_id, tx_ring); +break ; +case HAL_WBM_REL_HTT_TX_COMP_STATUS_MEC_NOTIFY : +/* This event is to be handled only when the driver decides to +* use WDS offload functionality. +*/ +break ; +default : +ath11k_warn (ab,"Unknown htt tx status %d\n" , wbm_status); +break ; + } +} + +static void ath11k_dp_tx_cache_peer_stats (struct ath11k *ar, +struct sk_buff *msdu, +struct hal_tx_status *ts) +{ +struct ath11k_per_peer_tx_stats *peer_stats = &ar->cached_stats; + +if (ts->try_cnt >1 ) { + peer_stats->retry_pkts += ts->try_cnt -1 ; + peer_stats->retry_bytes += (ts->try_cnt -1 ) * msdu->len; + +if (ts->status !=HAL_WBM_TQM_REL_REASON_FRAME_ACKED ) { + peer_stats->failed_pkts +=1 ; + peer_stats->failed_bytes += msdu->len; + } + } +} + +static void ath11k_dp_tx_complete_msdu (struct ath11k *ar, +struct sk_buff *msdu, +struct hal_tx_status *ts) +{ +struct ath11k_base *ab = ar->ab; +struct ieee80211_tx_info *info; +struct ath11k_skb_cb *skb_cb; + +if (WARN_ON_ONCE (ts->buf_rel_source !=HAL_WBM_REL_SRC_MODULE_TQM )) { +/* Must not happen */ +return ; + } + + skb_cb =ATH11K_SKB_CB (msdu); + +dma_unmap_single (ab->dev, skb_cb->paddr, msdu->len,DMA_TO_DEVICE ); + +rcu_read_lock (); + +if (!rcu_dereference (ab->pdevs_active[ar->pdev_idx])) { +dev_kfree_skb_any (msdu); + goto exit; + } + +if (!skb_cb->vif) { +dev_kfree_skb_any (msdu); + goto exit; + } + + info =IEEE80211_SKB_CB (msdu); +memset (&info->status,0 ,sizeof (info->status)); + +/* skip tx rate update from ieee80211_status*/ + info->status.rates[0 ].idx =-1 ; + +if (ts->status ==HAL_WBM_TQM_REL_REASON_FRAME_ACKED && + !(info->flags &IEEE80211_TX_CTL_NO_ACK )) { + info->flags |=IEEE80211_TX_STAT_ACK ; + info->status.ack_signal =ATH11K_DEFAULT_NOISE_FLOOR + + ts->ack_rssi; + info->status.is_valid_ack_signal = true; + } + +if (ts->status ==HAL_WBM_TQM_REL_REASON_CMD_REMOVE_TX && + (info->flags &IEEE80211_TX_CTL_NO_ACK )) + info->flags |=IEEE80211_TX_STAT_NOACK_TRANSMITTED ; + +if (ath11k_debug_is_extd_tx_stats_enabled (ar)) { +if (ts->flags &HAL_TX_STATUS_FLAGS_FIRST_MSDU ) { +if (ar->last_ppdu_id ==0 ) { + ar->last_ppdu_id = ts->ppdu_id; + }else if (ar->last_ppdu_id == ts->ppdu_id || + ar->cached_ppdu_id == ar->last_ppdu_id) { + ar->cached_ppdu_id = ar->last_ppdu_id; + ar->cached_stats.is_ampdu = true; +ath11k_update_per_peer_stats_from_txcompl (ar, msdu, ts); +memset (&ar->cached_stats,0 , +sizeof (struct ath11k_per_peer_tx_stats )); + }else { + ar->cached_stats.is_ampdu = false; +ath11k_update_per_peer_stats_from_txcompl (ar, msdu, ts); +memset (&ar->cached_stats,0 , +sizeof (struct ath11k_per_peer_tx_stats )); + } + ar->last_ppdu_id = ts->ppdu_id; + } + +ath11k_dp_tx_cache_peer_stats (ar, msdu, ts); + } + +/* NOTE: Tx rate status reporting. Tx completion status does not have +* necessary information (for example nss) to build the tx rate. +* Might end up reporting it out-of-band from HTT stats. +*/ + +ieee80211_tx_status (ar->hw, msdu); + +exit: +rcu_read_unlock (); +} + +void ath11k_dp_tx_completion_handler (struct ath11k_base *ab,int ring_id) +{ +struct ath11k *ar; +struct ath11k_dp *dp = &ab->dp; +int hal_ring_id = dp->tx_ring[ring_id].tcl_comp_ring.ring_id; +struct hal_srng *status_ring = &ab->hal.srng_list[hal_ring_id]; +struct sk_buff *msdu; +struct hal_wbm_release_ring tx_status; +struct hal_tx_status ts; +struct dp_tx_ring *tx_ring = &dp->tx_ring[ring_id]; +u32 *desc; +u32 msdu_id; +u8 mac_id; + +spin_lock_bh (&status_ring->lock); + +ath11k_hal_srng_access_begin (ab, status_ring); + +spin_lock_bh (&tx_ring->tx_status_lock); +while (!kfifo_is_full (&tx_ring->tx_status_fifo) && + (desc =ath11k_hal_srng_dst_get_next_entry (ab, status_ring))) { +ath11k_hal_tx_status_desc_sync ((void *)desc, + (void *)&tx_status); +kfifo_put (&tx_ring->tx_status_fifo, tx_status); + } + +if ((ath11k_hal_srng_dst_peek (ab, status_ring) !=NULL ) && +kfifo_is_full (&tx_ring->tx_status_fifo)) { +/* TODO: Process pending tx_status messages when kfifo_is_full() */ +ath11k_warn (ab,"Unable to process some of the tx_status ring desc because status_fifo is full\n" ); + } + +spin_unlock_bh (&tx_ring->tx_status_lock); + +ath11k_hal_srng_access_end (ab, status_ring); +spin_unlock_bh (&status_ring->lock); + +spin_lock_bh (&tx_ring->tx_status_lock); +while (kfifo_get (&tx_ring->tx_status_fifo, &tx_status)) { +memset (&ts,0 ,sizeof (ts)); +ath11k_hal_tx_status_parse (ab, &tx_status, &ts); + + mac_id =FIELD_GET (DP_TX_DESC_ID_MAC_ID , ts.desc_id); + msdu_id =FIELD_GET (DP_TX_DESC_ID_MSDU_ID , ts.desc_id); + +if (ts.buf_rel_source ==HAL_WBM_REL_SRC_MODULE_FW ) { +ath11k_dp_tx_process_htt_tx_complete (ab, + (void *)&tx_status, + mac_id, msdu_id, + tx_ring); +continue ; + } + +spin_lock_bh (&tx_ring->tx_idr_lock); + msdu =idr_find (&tx_ring->txbuf_idr, msdu_id); +if (!msdu) { +ath11k_warn (ab,"tx completion for unknown msdu_id %d\n" , + msdu_id); +spin_unlock_bh (&tx_ring->tx_idr_lock); +continue ; + } +idr_remove (&tx_ring->txbuf_idr, msdu_id); + tx_ring->num_tx_pending--; +spin_unlock_bh (&tx_ring->tx_idr_lock); + + ar = ab->pdevs[mac_id].ar; + +if (atomic_dec_and_test (&ar->dp.num_tx_pending)) +wake_up (&ar->dp.tx_empty_waitq); + +/* TODO: Locking optimization so that tx_completion for an msdu +* is not called with tx_status_lock acquired +*/ +ath11k_dp_tx_complete_msdu (ar, msdu, &ts); + } +spin_unlock_bh (&tx_ring->tx_status_lock); +} + +int ath11k_dp_tx_send_reo_cmd (struct ath11k_base *ab,struct dp_rx_tid *rx_tid, +enum hal_reo_cmd_type type, +struct ath11k_hal_reo_cmd *cmd, +void (*cb)(struct ath11k_dp *,void *, +enum hal_reo_cmd_status )) +{ +struct ath11k_dp *dp = &ab->dp; +struct dp_reo_cmd *dp_cmd; +struct hal_srng *cmd_ring; +int cmd_num; + + cmd_ring = &ab->hal.srng_list[dp->reo_cmd_ring.ring_id]; + cmd_num =ath11k_hal_reo_cmd_send (ab, cmd_ring, type, cmd); + +/* reo cmd ring descriptors has cmd_num starting from 1 */ +if (cmd_num <=0 ) +return -EINVAL ; + +if (!cb) +return 0 ; + +/* Can this be optimized so that we keep the pending command list only +* for tid delete command to free up the resoruce on the command status +* indication? +*/ + dp_cmd =kzalloc (sizeof (*dp_cmd),GFP_ATOMIC ); + +if (!dp_cmd) +return -ENOMEM ; + +memcpy (&dp_cmd->data, rx_tid,sizeof (struct dp_rx_tid )); + dp_cmd->cmd_num = cmd_num; + dp_cmd->handler = cb; + +spin_lock_bh (&dp->reo_cmd_lock); +list_add_tail (&dp_cmd->list, &dp->reo_cmd_list); +spin_unlock_bh (&dp->reo_cmd_lock); + +return 0 ; +} + +static int +ath11k_dp_tx_get_ring_id_type (struct ath11k_base *ab, +int mac_id,u32 ring_id, +enum hal_ring_type ring_type, +enum htt_srng_ring_type *htt_ring_type, +enum htt_srng_ring_id *htt_ring_id) +{ +int lmac_ring_id_offset =0 ; +int ret =0 ; + +switch (ring_type) { +case HAL_RXDMA_BUF : + lmac_ring_id_offset = mac_id *HAL_SRNG_RINGS_PER_LMAC ; +if (!(ring_id == (HAL_SRNG_RING_ID_WMAC1_SW2RXDMA0_BUF + + lmac_ring_id_offset) || + ring_id == (HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_BUF + + lmac_ring_id_offset))) { + ret = -EINVAL ; + } + *htt_ring_id =HTT_RXDMA_HOST_BUF_RING ; + *htt_ring_type =HTT_SW_TO_HW_RING ; +break ; +case HAL_RXDMA_DST : + *htt_ring_id =HTT_RXDMA_NON_MONITOR_DEST_RING ; + *htt_ring_type =HTT_HW_TO_SW_RING ; +break ; +case HAL_RXDMA_MONITOR_BUF : + *htt_ring_id =HTT_RXDMA_MONITOR_BUF_RING ; + *htt_ring_type =HTT_SW_TO_HW_RING ; +break ; +case HAL_RXDMA_MONITOR_STATUS : + *htt_ring_id =HTT_RXDMA_MONITOR_STATUS_RING ; + *htt_ring_type =HTT_SW_TO_HW_RING ; +break ; +case HAL_RXDMA_MONITOR_DST : + *htt_ring_id =HTT_RXDMA_MONITOR_DEST_RING ; + *htt_ring_type =HTT_HW_TO_SW_RING ; +break ; +case HAL_RXDMA_MONITOR_DESC : + *htt_ring_id =HTT_RXDMA_MONITOR_DESC_RING ; + *htt_ring_type =HTT_SW_TO_HW_RING ; +break ; +default : +ath11k_warn (ab,"Unsupported ring type in DP :%d\n" , ring_type); + ret = -EINVAL ; + } +return ret; +} + +int ath11k_dp_tx_htt_srng_setup (struct ath11k_base *ab,u32 ring_id, +int mac_id,enum hal_ring_type ring_type) +{ +struct htt_srng_setup_cmd *cmd; +struct hal_srng *srng = &ab->hal.srng_list[ring_id]; +struct hal_srng_params params; +struct sk_buff *skb; +u32 ring_entry_sz; +int len =sizeof (*cmd); +dma_addr_t hp_addr, tp_addr; +enum htt_srng_ring_type htt_ring_type; +enum htt_srng_ring_id htt_ring_id; +int ret =0 ; + + skb =ath11k_htc_alloc_skb (ab, len); +if (!skb) +return -ENOMEM ; + +memset (¶ms,0 ,sizeof (params)); +ath11k_hal_srng_get_params (ab, srng, ¶ms); + + hp_addr =ath11k_hal_srng_get_hp_addr (ab, srng); + tp_addr =ath11k_hal_srng_get_tp_addr (ab, srng); + +if (ath11k_dp_tx_get_ring_id_type (ab, mac_id, ring_id, + ring_type, &htt_ring_type, + &htt_ring_id)) + goto err_free; + +skb_put (skb, len); + cmd = (struct htt_srng_setup_cmd *)skb->data; + cmd->info0 =FIELD_PREP (HTT_SRNG_SETUP_CMD_INFO0_MSG_TYPE , +HTT_H2T_MSG_TYPE_SRING_SETUP ); +if (htt_ring_type ==HTT_SW_TO_HW_RING || + htt_ring_type ==HTT_HW_TO_SW_RING ) + cmd->info0 |=FIELD_PREP (HTT_SRNG_SETUP_CMD_INFO0_PDEV_ID , +DP_SW2HW_MACID (mac_id)); +else + cmd->info0 |=FIELD_PREP (HTT_SRNG_SETUP_CMD_INFO0_PDEV_ID , + mac_id); + cmd->info0 |=FIELD_PREP (HTT_SRNG_SETUP_CMD_INFO0_RING_TYPE , + htt_ring_type); + cmd->info0 |=FIELD_PREP (HTT_SRNG_SETUP_CMD_INFO0_RING_ID , htt_ring_id); + + cmd->ring_base_addr_lo = params.ring_base_paddr & +HAL_ADDR_LSB_REG_MASK ; + + cmd->ring_base_addr_hi = (u64 )params.ring_base_paddr >> +HAL_ADDR_MSB_REG_SHIFT ; + + ret =ath11k_hal_srng_get_entrysize (ring_type); +if (ret <0 ) +return -EINVAL ; + + ring_entry_sz = ret; + + ring_entry_sz >>=2 ; + cmd->info1 =FIELD_PREP (HTT_SRNG_SETUP_CMD_INFO1_RING_ENTRY_SIZE , + ring_entry_sz); + cmd->info1 |=FIELD_PREP (HTT_SRNG_SETUP_CMD_INFO1_RING_SIZE , + params.num_entries * ring_entry_sz); + cmd->info1 |=FIELD_PREP (HTT_SRNG_SETUP_CMD_INFO1_RING_FLAGS_MSI_SWAP , + !!(params.flags &HAL_SRNG_FLAGS_MSI_SWAP )); + cmd->info1 |=FIELD_PREP ( +HTT_SRNG_SETUP_CMD_INFO1_RING_FLAGS_TLV_SWAP , + !!(params.flags &HAL_SRNG_FLAGS_DATA_TLV_SWAP )); + cmd->info1 |=FIELD_PREP ( +HTT_SRNG_SETUP_CMD_INFO1_RING_FLAGS_HOST_FW_SWAP , + !!(params.flags &HAL_SRNG_FLAGS_RING_PTR_SWAP )); +if (htt_ring_type ==HTT_SW_TO_HW_RING ) + cmd->info1 |=HTT_SRNG_SETUP_CMD_INFO1_RING_LOOP_CNT_DIS ; + + cmd->ring_head_off32_remote_addr_lo = hp_addr &HAL_ADDR_LSB_REG_MASK ; + cmd->ring_head_off32_remote_addr_hi = (u64 )hp_addr >> +HAL_ADDR_MSB_REG_SHIFT ; + + cmd->ring_tail_off32_remote_addr_lo = tp_addr &HAL_ADDR_LSB_REG_MASK ; + cmd->ring_tail_off32_remote_addr_hi = (u64 )tp_addr >> +HAL_ADDR_MSB_REG_SHIFT ; + + cmd->ring_msi_addr_lo =0 ; + cmd->ring_msi_addr_hi =0 ; + cmd->msi_data =0 ; + + cmd->intr_info =FIELD_PREP ( +HTT_SRNG_SETUP_CMD_INTR_INFO_BATCH_COUNTER_THRESH , + params.intr_batch_cntr_thres_entries * ring_entry_sz); + cmd->intr_info |=FIELD_PREP ( +HTT_SRNG_SETUP_CMD_INTR_INFO_INTR_TIMER_THRESH , + params.intr_timer_thres_us >>3 ); + + cmd->info2 =0 ; +if (params.flags &HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN ) { + cmd->info2 =FIELD_PREP ( +HTT_SRNG_SETUP_CMD_INFO2_INTR_LOW_THRESH , + params.low_threshold); + } + + ret =ath11k_htc_send (&ab->htc, ab->dp.eid, skb); +if (ret) + goto err_free; + +return 0 ; + +err_free: +dev_kfree_skb_any (skb); + +return ret; +} + +#define HTT_TARGET_VERSION_TIMEOUT_HZ (3 * HZ) + +int ath11k_dp_tx_htt_h2t_ver_req_msg (struct ath11k_base *ab) +{ +struct ath11k_dp *dp = &ab->dp; +struct sk_buff *skb; +struct htt_ver_req_cmd *cmd; +int len =sizeof (*cmd); +int ret; + +init_completion (&dp->htt_tgt_version_received); + + skb =ath11k_htc_alloc_skb (ab, len); +if (!skb) +return -ENOMEM ; + +skb_put (skb, len); + cmd = (struct htt_ver_req_cmd *)skb->data; + cmd->ver_reg_info =FIELD_PREP (HTT_VER_REQ_INFO_MSG_ID , +HTT_H2T_MSG_TYPE_VERSION_REQ ); + + ret =ath11k_htc_send (&ab->htc, dp->eid, skb); +if (ret) { +dev_kfree_skb_any (skb); +return ret; + } + + ret =wait_for_completion_timeout (&dp->htt_tgt_version_received, +HTT_TARGET_VERSION_TIMEOUT_HZ ); +if (ret ==0 ) { +ath11k_warn (ab,"htt target version request timed out\n" ); +return -ETIMEDOUT ; + } + +if (dp->htt_tgt_ver_major !=HTT_TARGET_VERSION_MAJOR ) { +ath11k_err (ab,"unsupported htt major version %d supported version is %d\n" , + dp->htt_tgt_ver_major,HTT_TARGET_VERSION_MAJOR ); +return -ENOTSUPP ; + } + +return 0 ; +} + +int ath11k_dp_tx_htt_h2t_ppdu_stats_req (struct ath11k *ar,u32 mask) +{ +struct ath11k_base *ab = ar->ab; +struct ath11k_dp *dp = &ab->dp; +struct sk_buff *skb; +struct htt_ppdu_stats_cfg_cmd *cmd; +int len =sizeof (*cmd); +u8 pdev_mask; +int ret; + + skb =ath11k_htc_alloc_skb (ab, len); +if (!skb) +return -ENOMEM ; + +skb_put (skb, len); + cmd = (struct htt_ppdu_stats_cfg_cmd *)skb->data; + cmd->msg =FIELD_PREP (HTT_PPDU_STATS_CFG_MSG_TYPE , +HTT_H2T_MSG_TYPE_PPDU_STATS_CFG ); + + pdev_mask =1 << (ar->pdev_idx); + cmd->msg |=FIELD_PREP (HTT_PPDU_STATS_CFG_PDEV_ID , pdev_mask); + cmd->msg |=FIELD_PREP (HTT_PPDU_STATS_CFG_TLV_TYPE_BITMASK , mask); + + ret =ath11k_htc_send (&ab->htc, dp->eid, skb); +if (ret) { +dev_kfree_skb_any (skb); +return ret; + } + +return 0 ; +} + +int ath11k_dp_tx_htt_rx_filter_setup (struct ath11k_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) +{ +struct htt_rx_ring_selection_cfg_cmd *cmd; +struct hal_srng *srng = &ab->hal.srng_list[ring_id]; +struct hal_srng_params params; +struct sk_buff *skb; +int len =sizeof (*cmd); +enum htt_srng_ring_type htt_ring_type; +enum htt_srng_ring_id htt_ring_id; +int ret =0 ; + + skb =ath11k_htc_alloc_skb (ab, len); +if (!skb) +return -ENOMEM ; + +memset (¶ms,0 ,sizeof (params)); +ath11k_hal_srng_get_params (ab, srng, ¶ms); + +if (ath11k_dp_tx_get_ring_id_type (ab, mac_id, ring_id, + ring_type, &htt_ring_type, + &htt_ring_id)) + goto err_free; + +skb_put (skb, len); + cmd = (struct htt_rx_ring_selection_cfg_cmd *)skb->data; + cmd->info0 =FIELD_PREP (HTT_RX_RING_SELECTION_CFG_CMD_INFO0_MSG_TYPE , +HTT_H2T_MSG_TYPE_RX_RING_SELECTION_CFG ); +if (htt_ring_type ==HTT_SW_TO_HW_RING || + htt_ring_type ==HTT_HW_TO_SW_RING ) + cmd->info0 |= +FIELD_PREP (HTT_RX_RING_SELECTION_CFG_CMD_INFO0_PDEV_ID , +DP_SW2HW_MACID (mac_id)); +else + cmd->info0 |= +FIELD_PREP (HTT_RX_RING_SELECTION_CFG_CMD_INFO0_PDEV_ID , + mac_id); + cmd->info0 |=FIELD_PREP (HTT_RX_RING_SELECTION_CFG_CMD_INFO0_RING_ID , + htt_ring_id); + cmd->info0 |=FIELD_PREP (HTT_RX_RING_SELECTION_CFG_CMD_INFO0_SS , + !!(params.flags &HAL_SRNG_FLAGS_MSI_SWAP )); + cmd->info0 |=FIELD_PREP (HTT_RX_RING_SELECTION_CFG_CMD_INFO0_PS , + !!(params.flags &HAL_SRNG_FLAGS_DATA_TLV_SWAP )); + + cmd->info1 =FIELD_PREP (HTT_RX_RING_SELECTION_CFG_CMD_INFO1_BUF_SIZE , + rx_buf_size); + cmd->pkt_type_en_flags0 = tlv_filter->pkt_filter_flags0; + cmd->pkt_type_en_flags1 = tlv_filter->pkt_filter_flags1; + cmd->pkt_type_en_flags2 = tlv_filter->pkt_filter_flags2; + cmd->pkt_type_en_flags3 = tlv_filter->pkt_filter_flags3; + cmd->rx_filter_tlv = tlv_filter->rx_filter; + + ret =ath11k_htc_send (&ab->htc, ab->dp.eid, skb); +if (ret) + goto err_free; + +return 0 ; + +err_free: +dev_kfree_skb_any (skb); + +return ret; +} + +int +ath11k_dp_tx_htt_h2t_ext_stats_req (struct ath11k *ar,u8 type, +struct htt_ext_stats_cfg_params *cfg_params, +u64 cookie) +{ +struct ath11k_base *ab = ar->ab; +struct ath11k_dp *dp = &ab->dp; +struct sk_buff *skb; +struct htt_ext_stats_cfg_cmd *cmd; +int len =sizeof (*cmd); +int ret; + + skb =ath11k_htc_alloc_skb (ab, len); +if (!skb) +return -ENOMEM ; + +skb_put (skb, len); + + cmd = (struct htt_ext_stats_cfg_cmd *)skb->data; +memset (cmd,0 ,sizeof (*cmd)); + cmd->hdr.msg_type =HTT_H2T_MSG_TYPE_EXT_STATS_CFG ; + + cmd->hdr.pdev_mask =1 << ar->pdev->pdev_id; + + cmd->hdr.stats_type = type; + cmd->cfg_param0 = cfg_params->cfg0; + cmd->cfg_param1 = cfg_params->cfg1; + cmd->cfg_param2 = cfg_params->cfg2; + cmd->cfg_param3 = cfg_params->cfg3; + cmd->cookie_lsb =lower_32_bits (cookie); + cmd->cookie_msb =upper_32_bits (cookie); + + ret =ath11k_htc_send (&ab->htc, dp->eid, skb); +if (ret) { +ath11k_warn (ab,"failed to send htt type stats request: %d" , + ret); +dev_kfree_skb_any (skb); +return ret; + } + +return 0 ; +} + +int ath11k_dp_tx_htt_monitor_mode_ring_config (struct ath11k *ar,bool reset) +{ +struct ath11k_pdev_dp *dp = &ar->dp; +struct htt_rx_ring_tlv_filter tlv_filter = {0 }; +int ret =0 , ring_id =0 ; + + ring_id = dp->rxdma_mon_buf_ring.refill_buf_ring.ring_id; + +if (!reset) { + tlv_filter.rx_filter =HTT_RX_MON_FILTER_TLV_FLAGS_MON_BUF_RING ; + tlv_filter.pkt_filter_flags0 = +HTT_RX_MON_FP_MGMT_FILTER_FLAGS0 | +HTT_RX_MON_MO_MGMT_FILTER_FLAGS0 ; + tlv_filter.pkt_filter_flags1 = +HTT_RX_MON_FP_MGMT_FILTER_FLAGS1 | +HTT_RX_MON_MO_MGMT_FILTER_FLAGS1 ; + tlv_filter.pkt_filter_flags2 = +HTT_RX_MON_FP_CTRL_FILTER_FLASG2 | +HTT_RX_MON_MO_CTRL_FILTER_FLASG2 ; + tlv_filter.pkt_filter_flags3 = +HTT_RX_MON_FP_CTRL_FILTER_FLASG3 | +HTT_RX_MON_MO_CTRL_FILTER_FLASG3 | +HTT_RX_MON_FP_DATA_FILTER_FLASG3 | +HTT_RX_MON_MO_DATA_FILTER_FLASG3 ; + } + + ret =ath11k_dp_tx_htt_rx_filter_setup (ar->ab, ring_id, dp->mac_id, +HAL_RXDMA_MONITOR_BUF , +DP_RXDMA_REFILL_RING_SIZE , + &tlv_filter); +if (ret) +return ret; + + ring_id = dp->rx_mon_status_refill_ring.refill_buf_ring.ring_id; +if (!reset) + tlv_filter.rx_filter = +HTT_RX_MON_FILTER_TLV_FLAGS_MON_STATUS_RING ; +else + tlv_filter = ath11k_mac_mon_status_filter_default; + + ret =ath11k_dp_tx_htt_rx_filter_setup (ar->ab, ring_id, dp->mac_id, +HAL_RXDMA_MONITOR_STATUS , +DP_RXDMA_REFILL_RING_SIZE , + &tlv_filter); +return ret; +}
_______________________________________________
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v3 20/49 ath11k: add dp_tx.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/dp_tx.h | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
drivers/net/wireless/ath/ath11k/dp_tx.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#ifndef ATH11K_DP_TX_H +#define ATH11K_DP_TX_H + +#include "core.h" +#include "hal_tx.h" + +struct ath11k_dp_htt_wbm_tx_status { +u32 msdu_id; +bool acked; +int ack_rssi; +}; + +int ath11k_dp_tx_htt_h2t_ver_req_msg (struct ath11k_base *ab); +int ath11k_dp_tx (struct ath11k *ar,struct ath11k_vif *arvif, +struct sk_buff *skb); +void ath11k_dp_tx_completion_handler (struct ath11k_base *ab,int ring_id); +int ath11k_dp_tx_send_reo_cmd (struct ath11k_base *ab,struct dp_rx_tid *rx_tid, +enum hal_reo_cmd_type type, +struct ath11k_hal_reo_cmd *cmd, +void (*func)(struct ath11k_dp *,void *, +enum hal_reo_cmd_status )); + +int ath11k_dp_tx_htt_h2t_ppdu_stats_req (struct ath11k *ar,u32 mask); +int +ath11k_dp_tx_htt_h2t_ext_stats_req (struct ath11k *ar,u8 type, +struct htt_ext_stats_cfg_params *cfg_params, +u64 cookie); +int ath11k_dp_tx_htt_monitor_mode_ring_config (struct ath11k *ar,bool reset); + +int ath11k_dp_tx_htt_rx_filter_setup (struct ath11k_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); + +#endif
PATCH v3 21/49 ath11k: add hal.c
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/hal.c | 1124 +++++++++++++++++++++++++++++++++ 1 file changed, 1124 insertions(+)
drivers/net/wireless/ath/ath11k/hal.c new file +1124 -0
@@ -0,0 +1,1124 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ +#include <linux/dma-mapping.h> +#include "ahb.h" +#include "hal_tx.h" +#include "debug.h" +#include "hal_desc.h" + +static const struct hal_srng_config hw_srng_config[] = { +/* TODO: max_rings can populated by querying HW capabilities */ + {/* REO_DST */ + .start_ring_id =HAL_SRNG_RING_ID_REO2SW1 , + .max_rings =4 , + .entry_size =sizeof (struct hal_reo_dest_ring ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_DST , + .reg_start = { +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_REO1_RING_BASE_LSB , +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_REO1_RING_HP , + }, + .reg_size = { +HAL_REO2_RING_BASE_LSB -HAL_REO1_RING_BASE_LSB , +HAL_REO2_RING_HP -HAL_REO1_RING_HP , + }, + .max_size =HAL_REO_REO2SW1_RING_BASE_MSB_RING_SIZE , + }, + {/* REO_EXCEPTION */ +/* Designating REO2TCL ring as exception ring. This ring is +* similar to other REO2SW rings though it is named as REO2TCL. +* Any of theREO2SW rings can be used as exception ring. +*/ + .start_ring_id =HAL_SRNG_RING_ID_REO2TCL , + .max_rings =1 , + .entry_size =sizeof (struct hal_reo_dest_ring ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_DST , + .reg_start = { +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_REO_TCL_RING_BASE_LSB , +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_REO_TCL_RING_HP , + }, + .max_size =HAL_REO_REO2TCL_RING_BASE_MSB_RING_SIZE , + }, + {/* REO_REINJECT */ + .start_ring_id =HAL_SRNG_RING_ID_SW2REO , + .max_rings =1 , + .entry_size =sizeof (struct hal_reo_entrance_ring ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_SRC , + .reg_start = { +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_SW2REO_RING_BASE_LSB , +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_SW2REO_RING_HP , + }, + .max_size =HAL_REO_SW2REO_RING_BASE_MSB_RING_SIZE , + }, + {/* REO_CMD */ + .start_ring_id =HAL_SRNG_RING_ID_REO_CMD , + .max_rings =1 , + .entry_size = (sizeof (struct hal_tlv_hdr ) + +sizeof (struct hal_reo_get_queue_stats )) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_SRC , + .reg_start = { +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_REO_CMD_RING_BASE_LSB , +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_REO_CMD_HP , + }, + .max_size =HAL_REO_CMD_RING_BASE_MSB_RING_SIZE , + }, + {/* REO_STATUS */ + .start_ring_id =HAL_SRNG_RING_ID_REO_STATUS , + .max_rings =1 , + .entry_size = (sizeof (struct hal_tlv_hdr ) + +sizeof (struct hal_reo_get_queue_stats_status )) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_DST , + .reg_start = { +HAL_SEQ_WCSS_UMAC_REO_REG + +HAL_REO_STATUS_RING_BASE_LSB , +HAL_SEQ_WCSS_UMAC_REO_REG +HAL_REO_STATUS_HP , + }, + .max_size =HAL_REO_STATUS_RING_BASE_MSB_RING_SIZE , + }, + {/* TCL_DATA */ + .start_ring_id =HAL_SRNG_RING_ID_SW2TCL1 , + .max_rings =3 , + .entry_size = (sizeof (struct hal_tlv_hdr ) + +sizeof (struct hal_tcl_data_cmd )) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_SRC , + .reg_start = { +HAL_SEQ_WCSS_UMAC_TCL_REG +HAL_TCL1_RING_BASE_LSB , +HAL_SEQ_WCSS_UMAC_TCL_REG +HAL_TCL1_RING_HP , + }, + .reg_size = { +HAL_TCL2_RING_BASE_LSB -HAL_TCL1_RING_BASE_LSB , +HAL_TCL2_RING_HP -HAL_TCL1_RING_HP , + }, + .max_size =HAL_SW2TCL1_RING_BASE_MSB_RING_SIZE , + }, + {/* TCL_CMD */ + .start_ring_id =HAL_SRNG_RING_ID_SW2TCL_CMD , + .max_rings =1 , + .entry_size = (sizeof (struct hal_tlv_hdr ) + +sizeof (struct hal_tcl_gse_cmd )) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_SRC , + .reg_start = { +HAL_SEQ_WCSS_UMAC_TCL_REG +HAL_TCL_RING_BASE_LSB , +HAL_SEQ_WCSS_UMAC_TCL_REG +HAL_TCL_RING_HP , + }, + .max_size =HAL_SW2TCL1_CMD_RING_BASE_MSB_RING_SIZE , + }, + {/* TCL_STATUS */ + .start_ring_id =HAL_SRNG_RING_ID_TCL_STATUS , + .max_rings =1 , + .entry_size = (sizeof (struct hal_tlv_hdr ) + +sizeof (struct hal_tcl_status_ring )) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_DST , + .reg_start = { +HAL_SEQ_WCSS_UMAC_TCL_REG + +HAL_TCL_STATUS_RING_BASE_LSB , +HAL_SEQ_WCSS_UMAC_TCL_REG +HAL_TCL_STATUS_RING_HP , + }, + .max_size =HAL_TCL_STATUS_RING_BASE_MSB_RING_SIZE , + }, + {/* CE_SRC */ + .start_ring_id =HAL_SRNG_RING_ID_CE0_SRC , + .max_rings =12 , + .entry_size =sizeof (struct hal_ce_srng_src_desc ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_SRC , + .reg_start = { + (HAL_SEQ_WCSS_UMAC_CE0_SRC_REG + +HAL_CE_DST_RING_BASE_LSB ), +HAL_SEQ_WCSS_UMAC_CE0_SRC_REG +HAL_CE_DST_RING_HP , + }, + .reg_size = { + (HAL_SEQ_WCSS_UMAC_CE1_SRC_REG - +HAL_SEQ_WCSS_UMAC_CE0_SRC_REG ), + (HAL_SEQ_WCSS_UMAC_CE1_SRC_REG - +HAL_SEQ_WCSS_UMAC_CE0_SRC_REG ), + }, + .max_size =HAL_CE_SRC_RING_BASE_MSB_RING_SIZE , + }, + {/* CE_DST */ + .start_ring_id =HAL_SRNG_RING_ID_CE0_DST , + .max_rings =12 , + .entry_size =sizeof (struct hal_ce_srng_dest_desc ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_SRC , + .reg_start = { + (HAL_SEQ_WCSS_UMAC_CE0_DST_REG + +HAL_CE_DST_RING_BASE_LSB ), +HAL_SEQ_WCSS_UMAC_CE0_DST_REG +HAL_CE_DST_RING_HP , + }, + .reg_size = { + (HAL_SEQ_WCSS_UMAC_CE1_DST_REG - +HAL_SEQ_WCSS_UMAC_CE0_DST_REG ), + (HAL_SEQ_WCSS_UMAC_CE1_DST_REG - +HAL_SEQ_WCSS_UMAC_CE0_DST_REG ), + }, + .max_size =HAL_CE_DST_RING_BASE_MSB_RING_SIZE , + }, + {/* CE_DST_STATUS */ + .start_ring_id =HAL_SRNG_RING_ID_CE0_DST_STATUS , + .max_rings =12 , + .entry_size =sizeof (struct hal_ce_srng_dst_status_desc ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_DST , + .reg_start = { + (HAL_SEQ_WCSS_UMAC_CE0_DST_REG + +HAL_CE_DST_STATUS_RING_BASE_LSB ), + (HAL_SEQ_WCSS_UMAC_CE0_DST_REG + +HAL_CE_DST_STATUS_RING_HP ), + }, + .reg_size = { + (HAL_SEQ_WCSS_UMAC_CE1_DST_REG - +HAL_SEQ_WCSS_UMAC_CE0_DST_REG ), + (HAL_SEQ_WCSS_UMAC_CE1_DST_REG - +HAL_SEQ_WCSS_UMAC_CE0_DST_REG ), + }, + .max_size =HAL_CE_DST_STATUS_RING_BASE_MSB_RING_SIZE , + }, + {/* WBM_IDLE_LINK */ + .start_ring_id =HAL_SRNG_RING_ID_WBM_IDLE_LINK , + .max_rings =1 , + .entry_size =sizeof (struct hal_wbm_link_desc ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_SRC , + .reg_start = { + (HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_IDLE_LINK_RING_BASE_LSB ), + (HAL_SEQ_WCSS_UMAC_WBM_REG +HAL_WBM_IDLE_LINK_RING_HP ), + }, + .max_size =HAL_WBM_IDLE_LINK_RING_BASE_MSB_RING_SIZE , + }, + {/* SW2WBM_RELEASE */ + .start_ring_id =HAL_SRNG_RING_ID_WBM_SW_RELEASE , + .max_rings =1 , + .entry_size =sizeof (struct hal_wbm_release_ring ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_SRC , + .reg_start = { + (HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_RELEASE_RING_BASE_LSB ), + (HAL_SEQ_WCSS_UMAC_WBM_REG +HAL_WBM_RELEASE_RING_HP ), + }, + .max_size =HAL_SW2WBM_RELEASE_RING_BASE_MSB_RING_SIZE , + }, + {/* WBM2SW_RELEASE */ + .start_ring_id =HAL_SRNG_RING_ID_WBM2SW0_RELEASE , + .max_rings =4 , + .entry_size =sizeof (struct hal_wbm_release_ring ) >>2 , + .lmac_ring = false, + .ring_dir =HAL_SRNG_DIR_DST , + .reg_start = { + (HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM0_RELEASE_RING_BASE_LSB ), + (HAL_SEQ_WCSS_UMAC_WBM_REG +HAL_WBM0_RELEASE_RING_HP ), + }, + .reg_size = { + (HAL_WBM1_RELEASE_RING_BASE_LSB - +HAL_WBM0_RELEASE_RING_BASE_LSB ), + (HAL_WBM1_RELEASE_RING_HP -HAL_WBM0_RELEASE_RING_HP ), + }, + .max_size =HAL_WBM2SW_RELEASE_RING_BASE_MSB_RING_SIZE , + }, + {/* RXDMA_BUF */ + .start_ring_id =HAL_SRNG_RING_ID_WMAC1_SW2RXDMA0_BUF , + .max_rings =2 , + .entry_size =sizeof (struct hal_wbm_buffer_ring ) >>2 , + .lmac_ring = true, + .ring_dir =HAL_SRNG_DIR_SRC , + .max_size =HAL_RXDMA_RING_MAX_SIZE , + }, + {/* RXDMA_DST */ + .start_ring_id =HAL_SRNG_RING_ID_WMAC1_RXDMA2SW0 , + .max_rings =1 , + .entry_size =sizeof (struct hal_reo_entrance_ring ) >>2 , + .lmac_ring = true, + .ring_dir =HAL_SRNG_DIR_DST , + .max_size =HAL_RXDMA_RING_MAX_SIZE , + }, + {/* RXDMA_MONITOR_BUF */ + .start_ring_id =HAL_SRNG_RING_ID_WMAC1_SW2RXDMA2_BUF , + .max_rings =1 , + .entry_size =sizeof (struct hal_wbm_buffer_ring ) >>2 , + .lmac_ring = true, + .ring_dir =HAL_SRNG_DIR_SRC , + .max_size =HAL_RXDMA_RING_MAX_SIZE , + }, + {/* RXDMA_MONITOR_STATUS */ + .start_ring_id =HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_STATBUF , + .max_rings =1 , + .entry_size =sizeof (struct hal_wbm_buffer_ring ) >>2 , + .lmac_ring = true, + .ring_dir =HAL_SRNG_DIR_SRC , + .max_size =HAL_RXDMA_RING_MAX_SIZE , + }, + {/* RXDMA_MONITOR_DST */ + .start_ring_id =HAL_SRNG_RING_ID_WMAC1_RXDMA2SW1 , + .max_rings =1 , + .entry_size =sizeof (struct hal_reo_entrance_ring ) >>2 , + .lmac_ring = true, + .ring_dir =HAL_SRNG_DIR_DST , + .max_size =HAL_RXDMA_RING_MAX_SIZE , + }, + {/* RXDMA_MONITOR_DESC */ + .start_ring_id =HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_DESC , + .max_rings =1 , + .entry_size =sizeof (struct hal_wbm_buffer_ring ) >>2 , + .lmac_ring = true, + .ring_dir =HAL_SRNG_DIR_SRC , + .max_size =HAL_RXDMA_RING_MAX_SIZE , + }, + {/* RXDMA DIR BUF */ + .start_ring_id =HAL_SRNG_RING_ID_RXDMA_DIR_BUF , + .max_rings =1 , + .entry_size =8 >>2 ,/* TODO: Define the struct */ + .lmac_ring = true, + .ring_dir =HAL_SRNG_DIR_SRC , + .max_size =HAL_RXDMA_RING_MAX_SIZE , + }, +}; + +static int ath11k_hal_alloc_cont_rdp (struct ath11k_base *ab) +{ +struct ath11k_hal *hal = &ab->hal; +size_t size; + + size =sizeof (u32) *HAL_SRNG_RING_ID_MAX ; + hal->rdp.vaddr =dma_alloc_coherent (ab->dev, size, &hal->rdp.paddr, +GFP_KERNEL ); +if (!hal->rdp.vaddr) +return -ENOMEM ; + +return 0 ; +} + +static void ath11k_hal_free_cont_rdp (struct ath11k_base *ab) +{ +struct ath11k_hal *hal = &ab->hal; +size_t size; + +if (!hal->rdp.vaddr) +return ; + + size =sizeof (u32) *HAL_SRNG_RING_ID_MAX ; +dma_free_coherent (ab->dev, size, + hal->rdp.vaddr, hal->rdp.paddr); + hal->rdp.vaddr =NULL ; +} + +static int ath11k_hal_alloc_cont_wrp (struct ath11k_base *ab) +{ +struct ath11k_hal *hal = &ab->hal; +size_t size; + + size =sizeof (u32) *HAL_SRNG_NUM_LMAC_RINGS ; + hal->wrp.vaddr =dma_alloc_coherent (ab->dev, size, &hal->wrp.paddr, +GFP_KERNEL ); +if (!hal->wrp.vaddr) +return -ENOMEM ; + +return 0 ; +} + +static void ath11k_hal_free_cont_wrp (struct ath11k_base *ab) +{ +struct ath11k_hal *hal = &ab->hal; +size_t size; + +if (!hal->wrp.vaddr) +return ; + + size =sizeof (u32) *HAL_SRNG_NUM_LMAC_RINGS ; +dma_free_coherent (ab->dev, size, + hal->wrp.vaddr, hal->wrp.paddr); + hal->wrp.vaddr =NULL ; +} + +static void ath11k_hal_ce_dst_setup (struct ath11k_base *ab, +struct hal_srng *srng,int ring_num) +{ +const struct hal_srng_config *srng_config = &hw_srng_config[HAL_CE_DST ]; +u32 addr; +u32 val; + + addr =HAL_CE_DST_RING_CTRL + + srng_config->reg_start[HAL_SRNG_REG_GRP_R0 ] + + ring_num * srng_config->reg_size[HAL_SRNG_REG_GRP_R0 ]; + val =ath11k_ahb_read32 (ab, addr); + val &= ~HAL_CE_DST_R0_DEST_CTRL_MAX_LEN ; + val |=FIELD_PREP (HAL_CE_DST_R0_DEST_CTRL_MAX_LEN , + srng->u.dst_ring.max_buffer_length); +ath11k_ahb_write32 (ab, addr, val); +} + +static void ath11k_hal_srng_dst_hw_init (struct ath11k_base *ab, +struct hal_srng *srng) +{ +struct ath11k_hal *hal = &ab->hal; +u32 val; +u64 hp_addr; +u32 reg_base; + + reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R0 ]; + +if (srng->flags &HAL_SRNG_FLAGS_MSI_INTR ) { +ath11k_ahb_write32 (ab, reg_base + +HAL_REO1_RING_MSI1_BASE_LSB_OFFSET , + (u32 )srng->msi_addr); + + val =FIELD_PREP (HAL_REO1_RING_MSI1_BASE_MSB_ADDR , + ((u64 )srng->msi_addr >> +HAL_ADDR_MSB_REG_SHIFT )) | +HAL_REO1_RING_MSI1_BASE_MSB_MSI1_ENABLE ; +ath11k_ahb_write32 (ab, reg_base + +HAL_REO1_RING_MSI1_BASE_MSB_OFFSET , val); + +ath11k_ahb_write32 (ab, + reg_base +HAL_REO1_RING_MSI1_DATA_OFFSET , + srng->msi_data); + } + +ath11k_ahb_write32 (ab, reg_base, (u32 )srng->ring_base_paddr); + + val =FIELD_PREP (HAL_REO1_RING_BASE_MSB_RING_BASE_ADDR_MSB , + ((u64 )srng->ring_base_paddr >> +HAL_ADDR_MSB_REG_SHIFT )) | +FIELD_PREP (HAL_REO1_RING_BASE_MSB_RING_SIZE , + (srng->entry_size * srng->num_entries)); +ath11k_ahb_write32 (ab, reg_base +HAL_REO1_RING_BASE_MSB_OFFSET , val); + + val =FIELD_PREP (HAL_REO1_RING_ID_RING_ID , srng->ring_id) | +FIELD_PREP (HAL_REO1_RING_ID_ENTRY_SIZE , srng->entry_size); +ath11k_ahb_write32 (ab, reg_base +HAL_REO1_RING_ID_OFFSET , val); + +/* interrupt setup */ + val =FIELD_PREP (HAL_REO1_RING_PRDR_INT_SETUP_INTR_TMR_THOLD , + (srng->intr_timer_thres_us >>3 )); + + val |=FIELD_PREP (HAL_REO1_RING_PRDR_INT_SETUP_BATCH_COUNTER_THOLD , + (srng->intr_batch_cntr_thres_entries * + srng->entry_size)); + +ath11k_ahb_write32 (ab, + reg_base +HAL_REO1_RING_PRODUCER_INT_SETUP_OFFSET , + val); + + hp_addr = hal->rdp.paddr + + ((unsigned long )srng->u.dst_ring.hp_addr - + (unsigned long )hal->rdp.vaddr); +ath11k_ahb_write32 (ab, reg_base +HAL_REO1_RING_HP_ADDR_LSB_OFFSET , + hp_addr &HAL_ADDR_LSB_REG_MASK ); +ath11k_ahb_write32 (ab, reg_base +HAL_REO1_RING_HP_ADDR_MSB_OFFSET , + hp_addr >>HAL_ADDR_MSB_REG_SHIFT ); + +/* Initialize head and tail pointers to indicate ring is empty */ + reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R2 ]; +ath11k_ahb_write32 (ab, reg_base,0 ); +ath11k_ahb_write32 (ab, reg_base +HAL_REO1_RING_TP_OFFSET ,0 ); + *srng->u.dst_ring.hp_addr =0 ; + + reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R0 ]; + val =0 ; +if (srng->flags &HAL_SRNG_FLAGS_DATA_TLV_SWAP ) + val |=HAL_REO1_RING_MISC_DATA_TLV_SWAP ; +if (srng->flags &HAL_SRNG_FLAGS_RING_PTR_SWAP ) + val |=HAL_REO1_RING_MISC_HOST_FW_SWAP ; +if (srng->flags &HAL_SRNG_FLAGS_MSI_SWAP ) + val |=HAL_REO1_RING_MISC_MSI_SWAP ; + val |=HAL_REO1_RING_MISC_SRNG_ENABLE ; + +ath11k_ahb_write32 (ab, reg_base +HAL_REO1_RING_MISC_OFFSET , val); +} + +static void ath11k_hal_srng_src_hw_init (struct ath11k_base *ab, +struct hal_srng *srng) +{ +struct ath11k_hal *hal = &ab->hal; +u32 val; +u64 tp_addr; +u32 reg_base; + + reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R0 ]; + +if (srng->flags &HAL_SRNG_FLAGS_MSI_INTR ) { +ath11k_ahb_write32 (ab, reg_base + +HAL_TCL1_RING_MSI1_BASE_LSB_OFFSET , + (u32 )srng->msi_addr); + + val =FIELD_PREP (HAL_TCL1_RING_MSI1_BASE_MSB_ADDR , + ((u64 )srng->msi_addr >> +HAL_ADDR_MSB_REG_SHIFT )) | +HAL_TCL1_RING_MSI1_BASE_MSB_MSI1_ENABLE ; +ath11k_ahb_write32 (ab, reg_base + +HAL_TCL1_RING_MSI1_BASE_MSB_OFFSET , + val); + +ath11k_ahb_write32 (ab, reg_base + +HAL_TCL1_RING_MSI1_DATA_OFFSET , + srng->msi_data); + } + +ath11k_ahb_write32 (ab, reg_base, (u32 )srng->ring_base_paddr); + + val =FIELD_PREP (HAL_TCL1_RING_BASE_MSB_RING_BASE_ADDR_MSB , + ((u64 )srng->ring_base_paddr >> +HAL_ADDR_MSB_REG_SHIFT )) | +FIELD_PREP (HAL_TCL1_RING_BASE_MSB_RING_SIZE , + (srng->entry_size * srng->num_entries)); +ath11k_ahb_write32 (ab, reg_base +HAL_TCL1_RING_BASE_MSB_OFFSET , val); + + val =FIELD_PREP (HAL_REO1_RING_ID_ENTRY_SIZE , srng->entry_size); +ath11k_ahb_write32 (ab, reg_base +HAL_TCL1_RING_ID_OFFSET , val); + +/* interrupt setup */ +/* NOTE: IPQ8074 v2 requires the interrupt timer threshold in the +* unit of 8 usecs instead of 1 usec (as required by v1). +*/ + val =FIELD_PREP (HAL_TCL1_RING_CONSR_INT_SETUP_IX0_INTR_TMR_THOLD , + srng->intr_timer_thres_us); + + val |=FIELD_PREP (HAL_TCL1_RING_CONSR_INT_SETUP_IX0_BATCH_COUNTER_THOLD , + (srng->intr_batch_cntr_thres_entries * + srng->entry_size)); + +ath11k_ahb_write32 (ab, + reg_base +HAL_TCL1_RING_CONSR_INT_SETUP_IX0_OFFSET , + val); + + val =0 ; +if (srng->flags &HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN ) { + val |=FIELD_PREP (HAL_TCL1_RING_CONSR_INT_SETUP_IX1_LOW_THOLD , + srng->u.src_ring.low_threshold); + } +ath11k_ahb_write32 (ab, + reg_base +HAL_TCL1_RING_CONSR_INT_SETUP_IX1_OFFSET , + val); + +if (srng->ring_id !=HAL_SRNG_RING_ID_WBM_IDLE_LINK ) { + tp_addr = hal->rdp.paddr + + ((unsigned long )srng->u.src_ring.tp_addr - + (unsigned long )hal->rdp.vaddr); +ath11k_ahb_write32 (ab, + reg_base +HAL_TCL1_RING_TP_ADDR_LSB_OFFSET , + tp_addr &HAL_ADDR_LSB_REG_MASK ); +ath11k_ahb_write32 (ab, + reg_base +HAL_TCL1_RING_TP_ADDR_MSB_OFFSET , + tp_addr >>HAL_ADDR_MSB_REG_SHIFT ); + } + +/* Initialize head and tail pointers to indicate ring is empty */ + reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R2 ]; +ath11k_ahb_write32 (ab, reg_base,0 ); +ath11k_ahb_write32 (ab, reg_base +HAL_TCL1_RING_TP_OFFSET ,0 ); + *srng->u.src_ring.tp_addr =0 ; + + reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R0 ]; + val =0 ; +if (srng->flags &HAL_SRNG_FLAGS_DATA_TLV_SWAP ) + val |=HAL_TCL1_RING_MISC_DATA_TLV_SWAP ; +if (srng->flags &HAL_SRNG_FLAGS_RING_PTR_SWAP ) + val |=HAL_TCL1_RING_MISC_HOST_FW_SWAP ; +if (srng->flags &HAL_SRNG_FLAGS_MSI_SWAP ) + val |=HAL_TCL1_RING_MISC_MSI_SWAP ; + +/* Loop count is not used for SRC rings */ + val |=HAL_TCL1_RING_MISC_MSI_LOOPCNT_DISABLE ; + + val |=HAL_TCL1_RING_MISC_SRNG_ENABLE ; + +ath11k_ahb_write32 (ab, reg_base +HAL_TCL1_RING_MISC_OFFSET , val); +} + +static void ath11k_hal_srng_hw_init (struct ath11k_base *ab, +struct hal_srng *srng) +{ +if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) +ath11k_hal_srng_src_hw_init (ab, srng); +else +ath11k_hal_srng_dst_hw_init (ab, srng); +} + +static int ath11k_hal_srng_get_ring_id (struct ath11k_base *ab, +enum hal_ring_type type, +int ring_num,int mac_id) +{ +const struct hal_srng_config *srng_config = &hw_srng_config[type]; +int ring_id; + +if (ring_num >= srng_config->max_rings) { +ath11k_warn (ab,"invalid ring number :%d\n" , ring_num); +return -EINVAL ; + } + + ring_id = srng_config->start_ring_id + ring_num; +if (srng_config->lmac_ring) + ring_id += mac_id *HAL_SRNG_RINGS_PER_LMAC ; + +if (WARN_ON (ring_id >=HAL_SRNG_RING_ID_MAX )) +return -EINVAL ; + +return ring_id; +} + +int ath11k_hal_srng_get_entrysize (u32 ring_type) +{ +const struct hal_srng_config *srng_config; + +if (WARN_ON (ring_type >=HAL_MAX_RING_TYPES )) +return -EINVAL ; + + srng_config = &hw_srng_config[ring_type]; + +return (srng_config->entry_size <<2 ); +} + +int ath11k_hal_srng_get_max_entries (u32 ring_type) +{ +const struct hal_srng_config *srng_config; + +if (WARN_ON (ring_type >=HAL_MAX_RING_TYPES )) +return -EINVAL ; + + srng_config = &hw_srng_config[ring_type]; + +return (srng_config->max_size / srng_config->entry_size); +} + +void ath11k_hal_srng_get_params (struct ath11k_base *ab,struct hal_srng *srng, +struct hal_srng_params *params) +{ + params->ring_base_paddr = srng->ring_base_paddr; + params->ring_base_vaddr = srng->ring_base_vaddr; + params->num_entries = srng->num_entries; + params->intr_timer_thres_us = srng->intr_timer_thres_us; + params->intr_batch_cntr_thres_entries = + srng->intr_batch_cntr_thres_entries; + params->low_threshold = srng->u.src_ring.low_threshold; + params->flags = srng->flags; +} + +dma_addr_t ath11k_hal_srng_get_hp_addr (struct ath11k_base *ab, +struct hal_srng *srng) +{ +if (!(srng->flags &HAL_SRNG_FLAGS_LMAC_RING )) +return 0 ; + +if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) +return ab->hal.wrp.paddr + + ((unsigned long )srng->u.src_ring.hp_addr - + (unsigned long )ab->hal.wrp.vaddr); +else +return ab->hal.rdp.paddr + + ((unsigned long )srng->u.dst_ring.hp_addr - + (unsigned long )ab->hal.rdp.vaddr); +} + +dma_addr_t ath11k_hal_srng_get_tp_addr (struct ath11k_base *ab, +struct hal_srng *srng) +{ +if (!(srng->flags &HAL_SRNG_FLAGS_LMAC_RING )) +return 0 ; + +if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) +return ab->hal.rdp.paddr + + ((unsigned long )srng->u.src_ring.tp_addr - + (unsigned long )ab->hal.rdp.vaddr); +else +return ab->hal.wrp.paddr + + ((unsigned long )srng->u.dst_ring.tp_addr - + (unsigned long )ab->hal.wrp.vaddr); +} + +u32 ath11k_hal_ce_get_desc_size (enum hal_ce_desc type) +{ +switch (type) { +case HAL_CE_DESC_SRC : +return sizeof (struct hal_ce_srng_src_desc ); +case HAL_CE_DESC_DST : +return sizeof (struct hal_ce_srng_dest_desc ); +case HAL_CE_DESC_DST_STATUS : +return sizeof (struct hal_ce_srng_dst_status_desc ); + } + +return 0 ; +} + +void ath11k_hal_ce_src_set_desc (void *buf,dma_addr_t paddr,u32 len,u32 id, +u8 byte_swap_data) +{ +struct hal_ce_srng_src_desc *desc = (struct hal_ce_srng_src_desc *)buf; + + desc->buffer_addr_low = paddr &HAL_ADDR_LSB_REG_MASK ; + desc->buffer_addr_info = +FIELD_PREP (HAL_CE_SRC_DESC_ADDR_INFO_ADDR_HI , + ((u64 )paddr >>HAL_ADDR_MSB_REG_SHIFT )) | +FIELD_PREP (HAL_CE_SRC_DESC_ADDR_INFO_BYTE_SWAP , + byte_swap_data) | +FIELD_PREP (HAL_CE_SRC_DESC_ADDR_INFO_GATHER ,0 ) | +FIELD_PREP (HAL_CE_SRC_DESC_ADDR_INFO_LEN , len); + desc->meta_info =FIELD_PREP (HAL_CE_SRC_DESC_META_INFO_DATA , id); +} + +void ath11k_hal_ce_dst_set_desc (void *buf,dma_addr_t paddr) +{ +struct hal_ce_srng_dest_desc *desc = + (struct hal_ce_srng_dest_desc *)buf; + + desc->buffer_addr_low = paddr &HAL_ADDR_LSB_REG_MASK ; + desc->buffer_addr_info = +FIELD_PREP (HAL_CE_DEST_DESC_ADDR_INFO_ADDR_HI , + ((u64 )paddr >>HAL_ADDR_MSB_REG_SHIFT )); +} + +u32 ath11k_hal_ce_dst_status_get_length (void *buf) +{ +struct hal_ce_srng_dst_status_desc *desc = + (struct hal_ce_srng_dst_status_desc *)buf; +u32 len; + + len =FIELD_GET (HAL_CE_DST_STATUS_DESC_FLAGS_LEN , desc->flags); + desc->flags &= ~HAL_CE_DST_STATUS_DESC_FLAGS_LEN ; + +return len; +} + +void ath11k_hal_set_link_desc_addr (struct hal_wbm_link_desc *desc,u32 cookie, +dma_addr_t paddr) +{ + desc->buf_addr_info.info0 =FIELD_PREP (BUFFER_ADDR_INFO0_ADDR , + (paddr &HAL_ADDR_LSB_REG_MASK )); + desc->buf_addr_info.info1 =FIELD_PREP (BUFFER_ADDR_INFO1_ADDR , + ((u64 )paddr >>HAL_ADDR_MSB_REG_SHIFT )) | +FIELD_PREP (BUFFER_ADDR_INFO1_RET_BUF_MGR ,1 ) | +FIELD_PREP (BUFFER_ADDR_INFO1_SW_COOKIE , cookie); +} + +u32 *ath11k_hal_srng_dst_peek (struct ath11k_base *ab,struct hal_srng *srng) +{ +lockdep_assert_held (&srng->lock); + +if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) +return (srng->ring_base_vaddr + srng->u.dst_ring.tp); + +return NULL ; +} + +u32 *ath11k_hal_srng_dst_get_next_entry (struct ath11k_base *ab, +struct hal_srng *srng) +{ +u32 *desc; + +lockdep_assert_held (&srng->lock); + +if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp) +return NULL ; + + desc = srng->ring_base_vaddr + srng->u.dst_ring.tp; + + srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) % + srng->ring_size; + +return desc; +} + +int ath11k_hal_srng_dst_num_free (struct ath11k_base *ab,struct hal_srng *srng, +bool sync_hw_ptr) +{ +u32 tp, hp; + +lockdep_assert_held (&srng->lock); + + tp = srng->u.dst_ring.tp; + +if (sync_hw_ptr) { + hp = *srng->u.dst_ring.hp_addr; + srng->u.dst_ring.cached_hp = hp; + }else { + hp = srng->u.dst_ring.cached_hp; + } + +if (hp >= tp) +return (hp - tp) / srng->entry_size; +else +return (srng->ring_size - tp + hp) / srng->entry_size; +} + +/* Returns number of available entries in src ring */ +int ath11k_hal_srng_src_num_free (struct ath11k_base *ab,struct hal_srng *srng, +bool sync_hw_ptr) +{ +u32 tp, hp; + +lockdep_assert_held (&srng->lock); + + hp = srng->u.src_ring.hp; + +if (sync_hw_ptr) { + tp = *srng->u.src_ring.tp_addr; + srng->u.src_ring.cached_tp = tp; + }else { + tp = srng->u.src_ring.cached_tp; + } + +if (tp > hp) +return ((tp - hp) / srng->entry_size) -1 ; +else +return ((srng->ring_size - hp + tp) / srng->entry_size) -1 ; +} + +u32 *ath11k_hal_srng_src_get_next_entry (struct ath11k_base *ab, +struct hal_srng *srng) +{ +u32 *desc; +u32 next_hp; + +lockdep_assert_held (&srng->lock); + +/* TODO: Using % is expensive, but we have to do this since size of some +* SRNG rings is not power of 2 (due to descriptor sizes). Need to see +* if separate function is defined for rings having power of 2 ring size +* (TCL2SW, REO2SW, SW2RXDMA and CE rings) so that we can avoid the +* overhead of % by using mask (with &). +*/ + next_hp = (srng->u.src_ring.hp + srng->entry_size) % srng->ring_size; + +if (next_hp == srng->u.src_ring.cached_tp) +return NULL ; + + desc = srng->ring_base_vaddr + srng->u.src_ring.hp; + srng->u.src_ring.hp = next_hp; + +/* TODO: Reap functionality is not used by all rings. If particular +* ring does not use reap functionality, we need not update reap_hp +* with next_hp pointer. Need to make sure a separate function is used +* before doing any optimization by removing below code updating +* reap_hp. +*/ + srng->u.src_ring.reap_hp = next_hp; + +return desc; +} + +u32 *ath11k_hal_srng_src_reap_next (struct ath11k_base *ab, +struct hal_srng *srng) +{ +u32 *desc; +u32 next_reap_hp; + +lockdep_assert_held (&srng->lock); + + next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) % + srng->ring_size; + +if (next_reap_hp == srng->u.src_ring.cached_tp) +return NULL ; + + desc = srng->ring_base_vaddr + next_reap_hp; + srng->u.src_ring.reap_hp = next_reap_hp; + +return desc; +} + +u32 *ath11k_hal_srng_src_get_next_reaped (struct ath11k_base *ab, +struct hal_srng *srng) +{ +u32 *desc; + +lockdep_assert_held (&srng->lock); + +if (srng->u.src_ring.hp == srng->u.src_ring.reap_hp) +return NULL ; + + desc = srng->ring_base_vaddr + srng->u.src_ring.hp; + srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) % + srng->ring_size; + +return desc; +} + +u32 *ath11k_hal_srng_src_peek (struct ath11k_base *ab,struct hal_srng *srng) +{ +lockdep_assert_held (&srng->lock); + +if (((srng->u.src_ring.hp + srng->entry_size) % srng->ring_size) == + srng->u.src_ring.cached_tp) +return NULL ; + +return srng->ring_base_vaddr + srng->u.src_ring.hp; +} + +void ath11k_hal_srng_access_begin (struct ath11k_base *ab,struct hal_srng *srng) +{ +lockdep_assert_held (&srng->lock); + +if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) + srng->u.src_ring.cached_tp = + *(volatile u32 *)srng->u.src_ring.tp_addr; +else + srng->u.dst_ring.cached_hp = *srng->u.dst_ring.hp_addr; +} + +/* Update cached ring head/tail pointers to HW. ath11k_hal_srng_access_begin() +* should have been called before this. +*/ +void ath11k_hal_srng_access_end (struct ath11k_base *ab,struct hal_srng *srng) +{ +lockdep_assert_held (&srng->lock); + +/* TODO: See if we need a write memory barrier here */ +if (srng->flags &HAL_SRNG_FLAGS_LMAC_RING ) { +/* For LMAC rings, ring pointer updates are done through FW and +* hence written to a shared memory location that is read by FW +*/ +if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) + *srng->u.src_ring.hp_addr = srng->u.src_ring.hp; +else + *srng->u.dst_ring.tp_addr = srng->u.dst_ring.tp; + }else { +if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) { +ath11k_ahb_write32 (ab, + (unsigned long )srng->u.src_ring.hp_addr - + (unsigned long )ab->mem, + srng->u.src_ring.hp); + }else { +ath11k_ahb_write32 (ab, + (unsigned long )srng->u.dst_ring.tp_addr - + (unsigned long )ab->mem, + srng->u.dst_ring.tp); + } + } +} + +void ath11k_hal_setup_link_idle_list (struct ath11k_base *ab, +struct hal_wbm_idle_scatter_list *sbuf, +u32 nsbufs,u32 tot_link_desc, +u32 end_offset) +{ +struct ath11k_buffer_addr *link_addr; +int i; +u32 reg_scatter_buf_sz =HAL_WBM_IDLE_SCATTER_BUF_SIZE /64 ; + + link_addr = (void *)sbuf[0 ].vaddr +HAL_WBM_IDLE_SCATTER_BUF_SIZE ; + +for (i =1 ; i < nsbufs; i++) { + link_addr->info0 = sbuf[i].paddr &HAL_ADDR_LSB_REG_MASK ; + link_addr->info1 =FIELD_PREP ( +HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32 , + (u64 )sbuf[i].paddr >>HAL_ADDR_MSB_REG_SHIFT ) | +FIELD_PREP ( +HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_MATCH_TAG , +BASE_ADDR_MATCH_TAG_VAL ); + + link_addr = (void *)sbuf[i].vaddr + +HAL_WBM_IDLE_SCATTER_BUF_SIZE ; + } + +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG +HAL_WBM_R0_IDLE_LIST_CONTROL_ADDR , +FIELD_PREP (HAL_WBM_SCATTER_BUFFER_SIZE , reg_scatter_buf_sz) | +FIELD_PREP (HAL_WBM_LINK_DESC_IDLE_LIST_MODE ,0x1 )); +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG +HAL_WBM_R0_IDLE_LIST_SIZE_ADDR , +FIELD_PREP (HAL_WBM_SCATTER_RING_SIZE_OF_IDLE_LINK_DESC_LIST , + reg_scatter_buf_sz * nsbufs)); +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_SCATTERED_RING_BASE_LSB , +FIELD_PREP (BUFFER_ADDR_INFO0_ADDR , + sbuf[0 ].paddr &HAL_ADDR_LSB_REG_MASK )); +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_SCATTERED_RING_BASE_MSB , +FIELD_PREP ( +HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32 , + (u64 )sbuf[0 ].paddr >>HAL_ADDR_MSB_REG_SHIFT ) | +FIELD_PREP ( +HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_MATCH_TAG , +BASE_ADDR_MATCH_TAG_VAL )); + +/* Setup head and tail pointers for the idle list */ +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX0 , +FIELD_PREP (BUFFER_ADDR_INFO0_ADDR , + sbuf[nsbufs -1 ].paddr)); +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX1 , +FIELD_PREP ( +HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32 , + ((u64 )sbuf[nsbufs -1 ].paddr >> +HAL_ADDR_MSB_REG_SHIFT )) | +FIELD_PREP (HAL_WBM_SCATTERED_DESC_HEAD_P_OFFSET_IX1 , + (end_offset >>2 ))); +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX0 , +FIELD_PREP (BUFFER_ADDR_INFO0_ADDR , + sbuf[0 ].paddr)); + +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_SCATTERED_DESC_PTR_TAIL_INFO_IX0 , +FIELD_PREP (BUFFER_ADDR_INFO0_ADDR , + sbuf[0 ].paddr)); +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_SCATTERED_DESC_PTR_TAIL_INFO_IX1 , +FIELD_PREP ( +HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32 , + ((u64 )sbuf[0 ].paddr >>HAL_ADDR_MSB_REG_SHIFT )) | +FIELD_PREP (HAL_WBM_SCATTERED_DESC_TAIL_P_OFFSET_IX1 , +0 )); +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_SCATTERED_DESC_PTR_HP_ADDR , +2 * tot_link_desc); + +/* Enable the SRNG */ +ath11k_ahb_write32 (ab, +HAL_SEQ_WCSS_UMAC_WBM_REG + +HAL_WBM_IDLE_LINK_RING_MISC_ADDR ,0x40 ); +} + +int ath11k_hal_srng_setup (struct ath11k_base *ab,enum hal_ring_type type, +int ring_num,int mac_id, +struct hal_srng_params *params) +{ +struct ath11k_hal *hal = &ab->hal; +const struct hal_srng_config *srng_config = &hw_srng_config[type]; +struct hal_srng *srng; +int ring_id; +u32 lmac_idx; +int i; +u32 reg_base; + + ring_id =ath11k_hal_srng_get_ring_id (ab, type, ring_num, mac_id); +if (ring_id <0 ) +return ring_id; + + srng = &hal->srng_list[ring_id]; + + srng->ring_id = ring_id; + srng->ring_dir = srng_config->ring_dir; + srng->ring_base_paddr = params->ring_base_paddr; + srng->ring_base_vaddr = params->ring_base_vaddr; + srng->entry_size = srng_config->entry_size; + srng->num_entries = params->num_entries; + srng->ring_size = srng->entry_size * srng->num_entries; + srng->intr_batch_cntr_thres_entries = + params->intr_batch_cntr_thres_entries; + srng->intr_timer_thres_us = params->intr_timer_thres_us; + srng->flags = params->flags; +spin_lock_init (&srng->lock); + +for (i =0 ; i <HAL_SRNG_NUM_REG_GRP ; i++) { + srng->hwreg_base[i] = srng_config->reg_start[i] + + (ring_num * srng_config->reg_size[i]); + } + +memset (srng->ring_base_vaddr,0 , + (srng->entry_size * srng->num_entries) <<2 ); + +/* TODO: Add comments on these swap configurations */ +if (IS_ENABLED (CONFIG_CPU_BIG_ENDIAN )) + srng->flags |=HAL_SRNG_FLAGS_MSI_SWAP |HAL_SRNG_FLAGS_DATA_TLV_SWAP | +HAL_SRNG_FLAGS_RING_PTR_SWAP ; + + reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R2 ]; + +if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) { + srng->u.src_ring.hp =0 ; + srng->u.src_ring.cached_tp =0 ; + srng->u.src_ring.reap_hp = srng->ring_size - srng->entry_size; + srng->u.src_ring.tp_addr = (void *)(hal->rdp.vaddr + ring_id); + srng->u.src_ring.low_threshold = params->low_threshold * + srng->entry_size; +if (srng_config->lmac_ring) { + lmac_idx = ring_id -HAL_SRNG_RING_ID_LMAC1_ID_START ; + srng->u.src_ring.hp_addr = (void *)(hal->wrp.vaddr + + lmac_idx); + srng->flags |=HAL_SRNG_FLAGS_LMAC_RING ; + }else { + srng->u.src_ring.hp_addr = + (u32 *)((unsigned long )ab->mem + reg_base); + } + }else { +/* During initialization loop count in all the descriptors +* will be set to zero, and HW will set it to 1 on completing +* descriptor update in first loop, and increments it by 1 on +* subsequent loops (loop count wraps around after reaching +* 0xffff). The 'loop_cnt' in SW ring state is the expected +* loop count in descriptors updated by HW (to be processed +* by SW). +*/ + srng->u.dst_ring.loop_cnt =1 ; + srng->u.dst_ring.tp =0 ; + srng->u.dst_ring.cached_hp =0 ; + srng->u.dst_ring.hp_addr = (void *)(hal->rdp.vaddr + ring_id); +if (srng_config->lmac_ring) { +/* For LMAC rings, tail pointer updates will be done +* through FW by writing to a shared memory location +*/ + lmac_idx = ring_id -HAL_SRNG_RING_ID_LMAC1_ID_START ; + srng->u.dst_ring.tp_addr = (void *)(hal->wrp.vaddr + + lmac_idx); + srng->flags |=HAL_SRNG_FLAGS_LMAC_RING ; + }else { + srng->u.dst_ring.tp_addr = + (u32 *)((unsigned long )ab->mem + reg_base + + (HAL_REO1_RING_TP -HAL_REO1_RING_HP )); + } + } + +if (srng_config->lmac_ring) +return ring_id; + +ath11k_hal_srng_hw_init (ab, srng); + +if (type ==HAL_CE_DST ) { + srng->u.dst_ring.max_buffer_length = params->max_buffer_len; +ath11k_hal_ce_dst_setup (ab, srng, ring_num); + } + +return ring_id; +} + +int ath11k_hal_srng_init (struct ath11k_base *ab) +{ +struct ath11k_hal *hal = &ab->hal; +int ret; + +memset (hal,0 ,sizeof (*hal)); + + hal->srng_config = hw_srng_config; + + ret =ath11k_hal_alloc_cont_rdp (ab); +if (ret) + goto err_hal; + + ret =ath11k_hal_alloc_cont_wrp (ab); +if (ret) + goto err_free_cont_rdp; + +return 0 ; + +err_free_cont_rdp: +ath11k_hal_free_cont_rdp (ab); + +err_hal: +return ret; +} + +void ath11k_hal_srng_deinit (struct ath11k_base *ab) +{ +ath11k_hal_free_cont_rdp (ab); +ath11k_hal_free_cont_wrp (ab); +}
PATCH v3 22/49 ath11k: add hal.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/hal.h | 897 ++++++++++++++++++++++++++++++++++ 1 file changed, 897 insertions(+)
drivers/net/wireless/ath/ath11k/hal.h new file +897 -0
@@ -0,0 +1,897 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#ifndef ATH11K_HAL_H +#define ATH11K_HAL_H + +#include "hal_desc.h" +#include "rx_desc.h" + +struct ath11k_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) + +#define HAL_DSCP_TID_MAP_TBL_NUM_ENTRIES_MAX 48 +#define HAL_DSCP_TID_TBL_SIZE 24 + +/* calculate the register address from bar0 of shadow register x */ +#define SHADOW_BASE_ADDRESS 0x00003024 +#define SHADOW_NUM_REGISTERS 36 + +/* WCSS Relative address */ +#define HAL_SEQ_WCSS_UMAC_REO_REG 0x00a38000 +#define HAL_SEQ_WCSS_UMAC_TCL_REG 0x00a44000 +#define HAL_SEQ_WCSS_UMAC_CE0_SRC_REG 0x00a00000 +#define HAL_SEQ_WCSS_UMAC_CE0_DST_REG 0x00a01000 +#define HAL_SEQ_WCSS_UMAC_CE1_SRC_REG 0x00a02000 +#define HAL_SEQ_WCSS_UMAC_CE1_DST_REG 0x00a03000 +#define HAL_SEQ_WCSS_UMAC_WBM_REG 0x00a34000 + +/* SW2TCL(x) R0 ring configuration address */ +#define HAL_TCL1_RING_CMN_CTRL_REG 0x00000014 +#define HAL_TCL1_RING_DSCP_TID_MAP 0x0000002c +#define HAL_TCL1_RING_BASE_LSB 0x00000510 +#define HAL_TCL1_RING_BASE_MSB 0x00000514 +#define HAL_TCL1_RING_ID 0x00000518 +#define HAL_TCL1_RING_MISC 0x00000520 +#define HAL_TCL1_RING_TP_ADDR_LSB 0x0000052c +#define HAL_TCL1_RING_TP_ADDR_MSB 0x00000530 +#define HAL_TCL1_RING_CONSUMER_INT_SETUP_IX0 0x00000540 +#define HAL_TCL1_RING_CONSUMER_INT_SETUP_IX1 0x00000544 +#define HAL_TCL1_RING_MSI1_BASE_LSB 0x00000558 +#define HAL_TCL1_RING_MSI1_BASE_MSB 0x0000055c +#define HAL_TCL1_RING_MSI1_DATA 0x00000560 +#define HAL_TCL2_RING_BASE_LSB 0x00000568 +#define HAL_TCL_RING_BASE_LSB 0x00000618 + +#define HAL_TCL1_RING_MSI1_BASE_LSB_OFFSET \ + (HAL_TCL1_RING_MSI1_BASE_LSB - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_MSI1_BASE_MSB_OFFSET \ + (HAL_TCL1_RING_MSI1_BASE_MSB - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_MSI1_DATA_OFFSET \ + (HAL_TCL1_RING_MSI1_DATA - 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 \ + (HAL_TCL1_RING_ID - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_CONSR_INT_SETUP_IX0_OFFSET \ + (HAL_TCL1_RING_CONSUMER_INT_SETUP_IX0 - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_CONSR_INT_SETUP_IX1_OFFSET \ + (HAL_TCL1_RING_CONSUMER_INT_SETUP_IX1 - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_TP_ADDR_LSB_OFFSET \ + (HAL_TCL1_RING_TP_ADDR_LSB - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_TP_ADDR_MSB_OFFSET \ + (HAL_TCL1_RING_TP_ADDR_MSB - HAL_TCL1_RING_BASE_LSB) +#define HAL_TCL1_RING_MISC_OFFSET \ + (HAL_TCL1_RING_MISC - 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 0x00002018 + +#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 0x00000720 +#define HAL_TCL_STATUS_RING_HP 0x00002030 + +/* REO2SW(x) R0 ring configuration address */ +#define HAL_REO1_GEN_ENABLE 0x00000000 +#define HAL_REO1_DEST_RING_CTRL_IX_2 0x0000000c +#define HAL_REO1_DEST_RING_CTRL_IX_3 0x00000010 +#define HAL_REO1_RING_BASE_LSB 0x0000029c +#define HAL_REO1_RING_BASE_MSB 0x000002a0 +#define HAL_REO1_RING_ID 0x000002a4 +#define HAL_REO1_RING_MISC 0x000002ac +#define HAL_REO1_RING_HP_ADDR_LSB 0x000002b0 +#define HAL_REO1_RING_HP_ADDR_MSB 0x000002b4 +#define HAL_REO1_RING_PRODUCER_INT_SETUP 0x000002c0 +#define HAL_REO1_RING_MSI1_BASE_LSB 0x000002e4 +#define HAL_REO1_RING_MSI1_BASE_MSB 0x000002e8 +#define HAL_REO1_RING_MSI1_DATA 0x000002ec +#define HAL_REO2_RING_BASE_LSB 0x000002f4 +#define HAL_REO1_AGING_THRESH_IX_0 0x00000564 +#define HAL_REO1_AGING_THRESH_IX_1 0x00000568 +#define HAL_REO1_AGING_THRESH_IX_2 0x0000056c +#define HAL_REO1_AGING_THRESH_IX_3 0x00000570 + +#define HAL_REO1_RING_MSI1_BASE_LSB_OFFSET \ + (HAL_REO1_RING_MSI1_BASE_LSB - HAL_REO1_RING_BASE_LSB) +#define HAL_REO1_RING_MSI1_BASE_MSB_OFFSET \ + (HAL_REO1_RING_MSI1_BASE_MSB - HAL_REO1_RING_BASE_LSB) +#define HAL_REO1_RING_MSI1_DATA_OFFSET \ + (HAL_REO1_RING_MSI1_DATA - HAL_REO1_RING_BASE_LSB) +#define HAL_REO1_RING_BASE_MSB_OFFSET \ + (HAL_REO1_RING_BASE_MSB - HAL_REO1_RING_BASE_LSB) +#define HAL_REO1_RING_ID_OFFSET (HAL_REO1_RING_ID - HAL_REO1_RING_BASE_LSB) +#define HAL_REO1_RING_PRODUCER_INT_SETUP_OFFSET \ + (HAL_REO1_RING_PRODUCER_INT_SETUP - HAL_REO1_RING_BASE_LSB) +#define HAL_REO1_RING_HP_ADDR_LSB_OFFSET \ + (HAL_REO1_RING_HP_ADDR_LSB - HAL_REO1_RING_BASE_LSB) +#define HAL_REO1_RING_HP_ADDR_MSB_OFFSET \ + (HAL_REO1_RING_HP_ADDR_MSB - HAL_REO1_RING_BASE_LSB) +#define HAL_REO1_RING_MISC_OFFSET (HAL_REO1_RING_MISC - HAL_REO1_RING_BASE_LSB) + +/* REO2SW(x) R2 ring pointers (head/tail) address */ +#define HAL_REO1_RING_HP 0x00003038 +#define HAL_REO1_RING_TP 0x0000303c +#define HAL_REO2_RING_HP 0x00003040 + +#define HAL_REO1_RING_TP_OFFSET (HAL_REO1_RING_TP - HAL_REO1_RING_HP) + +/* REO2TCL R0 ring configuration address */ +#define HAL_REO_TCL_RING_BASE_LSB 0x000003fc + +/* REO2TCL R2 ring pointer (head/tail) address */ +#define HAL_REO_TCL_RING_HP 0x00003058 + +/* REO CMD R0 address */ +#define HAL_REO_CMD_RING_BASE_LSB 0x00000194 + +/* REO CMD R2 address */ +#define HAL_REO_CMD_HP 0x00003020 + +/* SW2REO R0 address */ +#define HAL_SW2REO_RING_BASE_LSB 0x000001ec + +/* SW2REO R2 address */ +#define HAL_SW2REO_RING_HP 0x00003028 + +/* CE ring R0 address */ +#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 0x00000504 +#define HAL_REO_STATUS_HP 0x00003070 + +/* WBM Idle R0 address */ +#define HAL_WBM_IDLE_LINK_RING_BASE_LSB 0x00000860 +#define HAL_WBM_IDLE_LINK_RING_MISC_ADDR 0x00000870 +#define HAL_WBM_R0_IDLE_LIST_CONTROL_ADDR 0x00000048 +#define HAL_WBM_R0_IDLE_LIST_SIZE_ADDR 0x0000004c +#define HAL_WBM_SCATTERED_RING_BASE_LSB 0x00000058 +#define HAL_WBM_SCATTERED_RING_BASE_MSB 0x0000005c +#define HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX0 0x00000068 +#define HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX1 0x0000006c +#define HAL_WBM_SCATTERED_DESC_PTR_TAIL_INFO_IX0 0x00000078 +#define HAL_WBM_SCATTERED_DESC_PTR_TAIL_INFO_IX1 0x0000007c +#define HAL_WBM_SCATTERED_DESC_PTR_HP_ADDR 0x00000084 + +/* WBM Idle R2 address */ +#define HAL_WBM_IDLE_LINK_RING_HP 0x000030b0 + +/* SW2WBM R0 release address */ +#define HAL_WBM_RELEASE_RING_BASE_LSB 0x000001d8 + +/* SW2WBM R2 release address */ +#define HAL_WBM_RELEASE_RING_HP 0x00003018 + +/* WBM2SW R0 release address */ +#define HAL_WBM0_RELEASE_RING_BASE_LSB 0x00000910 +#define HAL_WBM1_RELEASE_RING_BASE_LSB 0x00000968 + +/* WBM2SW R2 release address */ +#define HAL_WBM0_RELEASE_RING_HP 0x000030c0 +#define HAL_WBM1_RELEASE_RING_HP 0x000030c8 + +/* 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_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(17) +#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_GEN_ENABLE_FRAG_DST_RING GENMASK(25, 23) +#define HAL_REO1_GEN_ENABLE_AGING_LIST_ENABLE BIT(2) +#define HAL_REO1_GEN_ENABLE_AGING_FLUSH_ENABLE BIT(3) + +/* 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 BASE_ADDR_MATCH_TAG_VAL 0x5 + +#define HAL_REO_REO2SW1_RING_BASE_MSB_RING_SIZE 0x000fffff +#define HAL_REO_REO2TCL_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 0x0000ffff +#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_RX_DESC_SIZE (sizeof(struct hal_rx_desc)) + +/* Add any other errors here and return them in +* ath11k_hal_rx_desc_get_err(). +*/ + +enum hal_srng_ring_id { +HAL_SRNG_RING_ID_REO2SW1 =0 , +HAL_SRNG_RING_ID_REO2SW2 , +HAL_SRNG_RING_ID_REO2SW3 , +HAL_SRNG_RING_ID_REO2SW4 , +HAL_SRNG_RING_ID_REO2TCL , +HAL_SRNG_RING_ID_SW2REO , + +HAL_SRNG_RING_ID_REO_CMD =8 , +HAL_SRNG_RING_ID_REO_STATUS , + +HAL_SRNG_RING_ID_SW2TCL1 =16 , +HAL_SRNG_RING_ID_SW2TCL2 , +HAL_SRNG_RING_ID_SW2TCL3 , +HAL_SRNG_RING_ID_SW2TCL4 , + +HAL_SRNG_RING_ID_SW2TCL_CMD =24 , +HAL_SRNG_RING_ID_TCL_STATUS , + +HAL_SRNG_RING_ID_CE0_SRC =32 , +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_CE0_DST =56 , +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_CE0_DST_STATUS =80 , +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_WBM_IDLE_LINK =104 , +HAL_SRNG_RING_ID_WBM_SW_RELEASE , +HAL_SRNG_RING_ID_WBM2SW0_RELEASE , +HAL_SRNG_RING_ID_WBM2SW1_RELEASE , +HAL_SRNG_RING_ID_WBM2SW2_RELEASE , +HAL_SRNG_RING_ID_WBM2SW3_RELEASE , + +HAL_SRNG_RING_ID_UMAC_ID_END =127 , +HAL_SRNG_RING_ID_LMAC1_ID_START , + +HAL_SRNG_RING_ID_WMAC1_SW2RXDMA0_BUF =HAL_SRNG_RING_ID_LMAC1_ID_START , +HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_BUF , +HAL_SRNG_RING_ID_WMAC1_SW2RXDMA2_BUF , +HAL_SRNG_RING_ID_WMAC1_SW2RXDMA0_STATBUF , +HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_STATBUF , +HAL_SRNG_RING_ID_WMAC1_RXDMA2SW0 , +HAL_SRNG_RING_ID_WMAC1_RXDMA2SW1 , +HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_DESC , +HAL_SRNG_RING_ID_RXDMA_DIR_BUF , + +HAL_SRNG_RING_ID_LMAC1_ID_END =143 +}; + +/* 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 + +#define HAL_SRNG_NUM_LMACS 3 +#define HAL_SRNG_REO_EXCEPTION HAL_SRNG_RING_ID_REO2SW1 +#define HAL_SRNG_RINGS_PER_LMAC (HAL_SRNG_RING_ID_LMAC1_ID_END - \ + HAL_SRNG_RING_ID_LMAC1_ID_START) +#define HAL_SRNG_NUM_LMAC_RINGS (HAL_SRNG_NUM_LMACS * HAL_SRNG_RINGS_PER_LMAC) +#define HAL_SRNG_RING_ID_MAX (HAL_SRNG_RING_ID_UMAC_ID_END + \ + HAL_SRNG_NUM_LMAC_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_MAX_RING_TYPES , +}; + +#define HAL_RX_MAX_BA_WINDOW 256 + +#define HAL_DEFAULT_REO_TIMEOUT_USEC (40 * 1000) + +/** +* enum hal_reo_cmd_type: Enum for REO command type +* @CMD_GET_QUEUE_STATS: Get REO queue status/stats +* @CMD_FLUSH_QUEUE: Flush all frames in REO queue +* @CMD_FLUSH_CACHE: Flush descriptor entries in the cache +* @CMD_UNBLOCK_CACHE: Unblock a descriptor's address that was blocked +* earlier with a 'REO_FLUSH_CACHE' command +* @CMD_FLUSH_TIMEOUT_LIST: Flush buffers/descriptors from timeout list +* @CMD_UPDATE_RX_REO_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; + +/* 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_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; + +/* Misc flags */ +u32 flags; + +/* Lock for serializing ring index updates */ +spinlock_t lock; + +/* 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 ]; + +/* 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; + } 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; + } 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 1000 + +/* 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 ]; +u8 lmac_ring; +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_IDLE_DESC_LIST: Descriptor returned to WBM idle +* descriptor list. +* @HAL_RX_BUF_RBM_FW_BM: Buffer returned to FW +* @HAL_RX_BUF_RBM_SW0_BM: For Tx completion -- returned to host +* @HAL_RX_BUF_RBM_SW1_BM: For Tx completion -- returned to host +* @HAL_RX_BUF_RBM_SW2_BM: For Tx completion -- returned to host +* @HAL_RX_BUF_RBM_SW3_BM: For Rx release -- returned to host +*/ + +enum hal_rx_buf_return_buf_manager { +HAL_RX_BUF_RBM_WBM_IDLE_BUF_LIST , +HAL_RX_BUF_RBM_WBM_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 , +}; + +#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) + +#define HAL_REO_DEST_RING_CTRL_HASH_RING_MAP GENMASK(31, 8) + +struct ath11k_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 , +}; + +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 ath11k_hal { +/* HAL internal state for all SRNG rings. +*/ +struct hal_srng srng_list[HAL_SRNG_RING_ID_MAX ]; + +/* SRNG configuration table */ +const 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[SHADOW_NUM_REGISTERS ]; +int num_shadow_reg_configured; +}; + +u32 ath11k_hal_reo_qdesc_size (u32 ba_window_size,u8 tid); +void ath11k_hal_reo_qdesc_setup (void *vaddr,int tid,u32 ba_window_size, +u32 start_seqtype); +void ath11k_hal_reo_init_cmd_ring (struct ath11k_base *ab, +struct hal_srng *srng); +void ath11k_hal_reo_hw_setup (struct ath11k_base *ab); +void ath11k_hal_setup_link_idle_list (struct ath11k_base *ab, +struct hal_wbm_idle_scatter_list *sbuf, +u32 nsbufs,u32 tot_link_desc, +u32 end_offset); + +dma_addr_t ath11k_hal_srng_get_tp_addr (struct ath11k_base *ab, +struct hal_srng *srng); +dma_addr_t ath11k_hal_srng_get_hp_addr (struct ath11k_base *ab, +struct hal_srng *srng); +void ath11k_hal_set_link_desc_addr (struct hal_wbm_link_desc *desc,u32 cookie, +dma_addr_t paddr); +u32 ath11k_hal_ce_get_desc_size (enum hal_ce_desc type); +void ath11k_hal_ce_src_set_desc (void *buf,dma_addr_t paddr,u32 len,u32 id, +u8 byte_swap_data); +void ath11k_hal_ce_dst_set_desc (void *buf,dma_addr_t paddr); +u32 ath11k_hal_ce_dst_status_get_length (void *buf); +int ath11k_hal_srng_get_entrysize (u32 ring_type); +int ath11k_hal_srng_get_max_entries (u32 ring_type); +void ath11k_hal_srng_get_params (struct ath11k_base *ab,struct hal_srng *srng, +struct hal_srng_params *params); +u32 *ath11k_hal_srng_dst_get_next_entry (struct ath11k_base *ab, +struct hal_srng *srng); +u32 *ath11k_hal_srng_dst_peek (struct ath11k_base *ab,struct hal_srng *srng); +int ath11k_hal_srng_dst_num_free (struct ath11k_base *ab,struct hal_srng *srng, +bool sync_hw_ptr); +u32 *ath11k_hal_srng_src_peek (struct ath11k_base *ab,struct hal_srng *srng); +u32 *ath11k_hal_srng_src_get_next_reaped (struct ath11k_base *ab, +struct hal_srng *srng); +u32 *ath11k_hal_srng_src_reap_next (struct ath11k_base *ab, +struct hal_srng *srng); +u32 *ath11k_hal_srng_src_get_next_entry (struct ath11k_base *ab, +struct hal_srng *srng); +int ath11k_hal_srng_src_num_free (struct ath11k_base *ab,struct hal_srng *srng, +bool sync_hw_ptr); +void ath11k_hal_srng_access_begin (struct ath11k_base *ab, +struct hal_srng *srng); +void ath11k_hal_srng_access_end (struct ath11k_base *ab,struct hal_srng *srng); +int ath11k_hal_srng_setup (struct ath11k_base *ab,enum hal_ring_type type, +int ring_num,int mac_id, +struct hal_srng_params *params); +int ath11k_hal_srng_init (struct ath11k_base *ath11k); +void ath11k_hal_srng_deinit (struct ath11k_base *ath11k); + +#endif
PATCH v3 23/49 ath11k: add hal_desc.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/hal_desc.h | 2469 ++++++++++++++++++++++++++++ 1 file changed, 2469 insertions(+)
drivers/net/wireless/ath/ath11k/hal_desc.h new file +2469 -0
@@ -0,0 +1,2469 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ +#ifndef ATH11K_HAL_DESC_H +#define ATH11K_HAL_DESC_H + +#define BUFFER_ADDR_INFO0_ADDR GENMASK(31, 0) + +#define BUFFER_ADDR_INFO1_ADDR GENMASK(7, 0) +#define BUFFER_ADDR_INFO1_RET_BUF_MGR GENMASK(10, 8) +#define BUFFER_ADDR_INFO1_SW_COOKIE GENMASK(31, 11) + +struct ath11k_buffer_addr { +u32 info0; +u32 info1; +} __packed; + +/* ath11k_buffer_addr +* +* info0 +* Address (lower 32 bits) of the msdu buffer or msdu extension +* descriptor or Link descriptor +* +* addr +* Address (upper 8 bits) of the msdu buffer or msdu extension +* descriptor or Link descriptor +* +* return_buffer_manager (RBM) +* Consumer: WBM +* Producer: SW/FW +* Indicates to which buffer manager the buffer or MSDU_EXTENSION +* descriptor or link descriptor that is being pointed to shall be +* returned after the frame has been processed. It is used by WBM +* for routing purposes. +* +* Values are defined in enum %HAL_RX_BUF_RBM_ +* +* sw_buffer_cookie +* Cookie field exclusively used by SW. HW ignores the contents, +* accept that it passes the programmed value on to other +* descriptors together with the physical address. +* +* Field can be used by SW to for example associate the buffers +* physical address with the virtual address. +*/ + +enum hal_tlv_tag { +HAL_MACTX_CBF_START =0 /* 0x0 */ , +HAL_PHYRX_DATA =1 /* 0x1 */ , +HAL_PHYRX_CBF_DATA_RESP =2 /* 0x2 */ , +HAL_PHYRX_ABORT_REQUEST =3 /* 0x3 */ , +HAL_PHYRX_USER_ABORT_NOTIFICATION =4 /* 0x4 */ , +HAL_MACTX_DATA_RESP =5 /* 0x5 */ , +HAL_MACTX_CBF_DATA =6 /* 0x6 */ , +HAL_MACTX_CBF_DONE =7 /* 0x7 */ , +HAL_MACRX_CBF_READ_REQUEST =8 /* 0x8 */ , +HAL_MACRX_CBF_DATA_REQUEST =9 /* 0x9 */ , +HAL_MACRX_EXPECT_NDP_RECEPTION =10 /* 0xa */ , +HAL_MACRX_FREEZE_CAPTURE_CHANNEL =11 /* 0xb */ , +HAL_MACRX_NDP_TIMEOUT =12 /* 0xc */ , +HAL_MACRX_ABORT_ACK =13 /* 0xd */ , +HAL_MACRX_REQ_IMPLICIT_FB =14 /* 0xe */ , +HAL_MACRX_CHAIN_MASK =15 /* 0xf */ , +HAL_MACRX_NAP_USER =16 /* 0x10 */ , +HAL_MACRX_ABORT_REQUEST =17 /* 0x11 */ , +HAL_PHYTX_OTHER_TRANSMIT_INFO16 =18 /* 0x12 */ , +HAL_PHYTX_ABORT_ACK =19 /* 0x13 */ , +HAL_PHYTX_ABORT_REQUEST =20 /* 0x14 */ , +HAL_PHYTX_PKT_END =21 /* 0x15 */ , +HAL_PHYTX_PPDU_HEADER_INFO_REQUEST =22 /* 0x16 */ , +HAL_PHYTX_REQUEST_CTRL_INFO =23 /* 0x17 */ , +HAL_PHYTX_DATA_REQUEST =24 /* 0x18 */ , +HAL_PHYTX_BF_CV_LOADING_DONE =25 /* 0x19 */ , +HAL_PHYTX_NAP_ACK =26 /* 0x1a */ , +HAL_PHYTX_NAP_DONE =27 /* 0x1b */ , +HAL_PHYTX_OFF_ACK =28 /* 0x1c */ , +HAL_PHYTX_ON_ACK =29 /* 0x1d */ , +HAL_PHYTX_SYNTH_OFF_ACK =30 /* 0x1e */ , +HAL_PHYTX_DEBUG16 =31 /* 0x1f */ , +HAL_MACTX_ABORT_REQUEST =32 /* 0x20 */ , +HAL_MACTX_ABORT_ACK =33 /* 0x21 */ , +HAL_MACTX_PKT_END =34 /* 0x22 */ , +HAL_MACTX_PRE_PHY_DESC =35 /* 0x23 */ , +HAL_MACTX_BF_PARAMS_COMMON =36 /* 0x24 */ , +HAL_MACTX_BF_PARAMS_PER_USER =37 /* 0x25 */ , +HAL_MACTX_PREFETCH_CV =38 /* 0x26 */ , +HAL_MACTX_USER_DESC_COMMON =39 /* 0x27 */ , +HAL_MACTX_USER_DESC_PER_USER =40 /* 0x28 */ , +HAL_EXAMPLE_USER_TLV_16 =41 /* 0x29 */ , +HAL_EXAMPLE_TLV_16 =42 /* 0x2a */ , +HAL_MACTX_PHY_OFF =43 /* 0x2b */ , +HAL_MACTX_PHY_ON =44 /* 0x2c */ , +HAL_MACTX_SYNTH_OFF =45 /* 0x2d */ , +HAL_MACTX_EXPECT_CBF_COMMON =46 /* 0x2e */ , +HAL_MACTX_EXPECT_CBF_PER_USER =47 /* 0x2f */ , +HAL_MACTX_PHY_DESC =48 /* 0x30 */ , +HAL_MACTX_L_SIG_A =49 /* 0x31 */ , +HAL_MACTX_L_SIG_B =50 /* 0x32 */ , +HAL_MACTX_HT_SIG =51 /* 0x33 */ , +HAL_MACTX_VHT_SIG_A =52 /* 0x34 */ , +HAL_MACTX_VHT_SIG_B_SU20 =53 /* 0x35 */ , +HAL_MACTX_VHT_SIG_B_SU40 =54 /* 0x36 */ , +HAL_MACTX_VHT_SIG_B_SU80 =55 /* 0x37 */ , +HAL_MACTX_VHT_SIG_B_SU160 =56 /* 0x38 */ , +HAL_MACTX_VHT_SIG_B_MU20 =57 /* 0x39 */ , +HAL_MACTX_VHT_SIG_B_MU40 =58 /* 0x3a */ , +HAL_MACTX_VHT_SIG_B_MU80 =59 /* 0x3b */ , +HAL_MACTX_VHT_SIG_B_MU160 =60 /* 0x3c */ , +HAL_MACTX_SERVICE =61 /* 0x3d */ , +HAL_MACTX_HE_SIG_A_SU =62 /* 0x3e */ , +HAL_MACTX_HE_SIG_A_MU_DL =63 /* 0x3f */ , +HAL_MACTX_HE_SIG_A_MU_UL =64 /* 0x40 */ , +HAL_MACTX_HE_SIG_B1_MU =65 /* 0x41 */ , +HAL_MACTX_HE_SIG_B2_MU =66 /* 0x42 */ , +HAL_MACTX_HE_SIG_B2_OFDMA =67 /* 0x43 */ , +HAL_MACTX_DELETE_CV =68 /* 0x44 */ , +HAL_MACTX_MU_UPLINK_COMMON =69 /* 0x45 */ , +HAL_MACTX_MU_UPLINK_USER_SETUP =70 /* 0x46 */ , +HAL_MACTX_OTHER_TRANSMIT_INFO =71 /* 0x47 */ , +HAL_MACTX_PHY_NAP =72 /* 0x48 */ , +HAL_MACTX_DEBUG =73 /* 0x49 */ , +HAL_PHYRX_ABORT_ACK =74 /* 0x4a */ , +HAL_PHYRX_GENERATED_CBF_DETAILS =75 /* 0x4b */ , +HAL_PHYRX_RSSI_LEGACY =76 /* 0x4c */ , +HAL_PHYRX_RSSI_HT =77 /* 0x4d */ , +HAL_PHYRX_USER_INFO =78 /* 0x4e */ , +HAL_PHYRX_PKT_END =79 /* 0x4f */ , +HAL_PHYRX_DEBUG =80 /* 0x50 */ , +HAL_PHYRX_CBF_TRANSFER_DONE =81 /* 0x51 */ , +HAL_PHYRX_CBF_TRANSFER_ABORT =82 /* 0x52 */ , +HAL_PHYRX_L_SIG_A =83 /* 0x53 */ , +HAL_PHYRX_L_SIG_B =84 /* 0x54 */ , +HAL_PHYRX_HT_SIG =85 /* 0x55 */ , +HAL_PHYRX_VHT_SIG_A =86 /* 0x56 */ , +HAL_PHYRX_VHT_SIG_B_SU20 =87 /* 0x57 */ , +HAL_PHYRX_VHT_SIG_B_SU40 =88 /* 0x58 */ , +HAL_PHYRX_VHT_SIG_B_SU80 =89 /* 0x59 */ , +HAL_PHYRX_VHT_SIG_B_SU160 =90 /* 0x5a */ , +HAL_PHYRX_VHT_SIG_B_MU20 =91 /* 0x5b */ , +HAL_PHYRX_VHT_SIG_B_MU40 =92 /* 0x5c */ , +HAL_PHYRX_VHT_SIG_B_MU80 =93 /* 0x5d */ , +HAL_PHYRX_VHT_SIG_B_MU160 =94 /* 0x5e */ , +HAL_PHYRX_HE_SIG_A_SU =95 /* 0x5f */ , +HAL_PHYRX_HE_SIG_A_MU_DL =96 /* 0x60 */ , +HAL_PHYRX_HE_SIG_A_MU_UL =97 /* 0x61 */ , +HAL_PHYRX_HE_SIG_B1_MU =98 /* 0x62 */ , +HAL_PHYRX_HE_SIG_B2_MU =99 /* 0x63 */ , +HAL_PHYRX_HE_SIG_B2_OFDMA =100 /* 0x64 */ , +HAL_PHYRX_OTHER_RECEIVE_INFO =101 /* 0x65 */ , +HAL_PHYRX_COMMON_USER_INFO =102 /* 0x66 */ , +HAL_PHYRX_DATA_DONE =103 /* 0x67 */ , +HAL_RECEIVE_RSSI_INFO =104 /* 0x68 */ , +HAL_RECEIVE_USER_INFO =105 /* 0x69 */ , +HAL_MIMO_CONTROL_INFO =106 /* 0x6a */ , +HAL_RX_LOCATION_INFO =107 /* 0x6b */ , +HAL_COEX_TX_REQ =108 /* 0x6c */ , +HAL_DUMMY =109 /* 0x6d */ , +HAL_RX_TIMING_OFFSET_INFO =110 /* 0x6e */ , +HAL_EXAMPLE_TLV_32_NAME =111 /* 0x6f */ , +HAL_MPDU_LIMIT =112 /* 0x70 */ , +HAL_NA_LENGTH_END =113 /* 0x71 */ , +HAL_OLE_BUF_STATUS =114 /* 0x72 */ , +HAL_PCU_PPDU_SETUP_DONE =115 /* 0x73 */ , +HAL_PCU_PPDU_SETUP_END =116 /* 0x74 */ , +HAL_PCU_PPDU_SETUP_INIT =117 /* 0x75 */ , +HAL_PCU_PPDU_SETUP_START =118 /* 0x76 */ , +HAL_PDG_FES_SETUP =119 /* 0x77 */ , +HAL_PDG_RESPONSE =120 /* 0x78 */ , +HAL_PDG_TX_REQ =121 /* 0x79 */ , +HAL_SCH_WAIT_INSTR =122 /* 0x7a */ , +HAL_SCHEDULER_TLV =123 /* 0x7b */ , +HAL_TQM_FLOW_EMPTY_STATUS =124 /* 0x7c */ , +HAL_TQM_FLOW_NOT_EMPTY_STATUS =125 /* 0x7d */ , +HAL_TQM_GEN_MPDU_LENGTH_LIST =126 /* 0x7e */ , +HAL_TQM_GEN_MPDU_LENGTH_LIST_STATUS =127 /* 0x7f */ , +HAL_TQM_GEN_MPDUS =128 /* 0x80 */ , +HAL_TQM_GEN_MPDUS_STATUS =129 /* 0x81 */ , +HAL_TQM_REMOVE_MPDU =130 /* 0x82 */ , +HAL_TQM_REMOVE_MPDU_STATUS =131 /* 0x83 */ , +HAL_TQM_REMOVE_MSDU =132 /* 0x84 */ , +HAL_TQM_REMOVE_MSDU_STATUS =133 /* 0x85 */ , +HAL_TQM_UPDATE_TX_MPDU_COUNT =134 /* 0x86 */ , +HAL_TQM_WRITE_CMD =135 /* 0x87 */ , +HAL_OFDMA_TRIGGER_DETAILS =136 /* 0x88 */ , +HAL_TX_DATA =137 /* 0x89 */ , +HAL_TX_FES_SETUP =138 /* 0x8a */ , +HAL_RX_PACKET =139 /* 0x8b */ , +HAL_EXPECTED_RESPONSE =140 /* 0x8c */ , +HAL_TX_MPDU_END =141 /* 0x8d */ , +HAL_TX_MPDU_START =142 /* 0x8e */ , +HAL_TX_MSDU_END =143 /* 0x8f */ , +HAL_TX_MSDU_START =144 /* 0x90 */ , +HAL_TX_SW_MODE_SETUP =145 /* 0x91 */ , +HAL_TXPCU_BUFFER_STATUS =146 /* 0x92 */ , +HAL_TXPCU_USER_BUFFER_STATUS =147 /* 0x93 */ , +HAL_DATA_TO_TIME_CONFIG =148 /* 0x94 */ , +HAL_EXAMPLE_USER_TLV_32 =149 /* 0x95 */ , +HAL_MPDU_INFO =150 /* 0x96 */ , +HAL_PDG_USER_SETUP =151 /* 0x97 */ , +HAL_TX_11AH_SETUP =152 /* 0x98 */ , +HAL_REO_UPDATE_RX_REO_QUEUE_STATUS =153 /* 0x99 */ , +HAL_TX_PEER_ENTRY =154 /* 0x9a */ , +HAL_TX_RAW_OR_NATIVE_FRAME_SETUP =155 /* 0x9b */ , +HAL_EXAMPLE_STRUCT_NAME =156 /* 0x9c */ , +HAL_PCU_PPDU_SETUP_END_INFO =157 /* 0x9d */ , +HAL_PPDU_RATE_SETTING =158 /* 0x9e */ , +HAL_PROT_RATE_SETTING =159 /* 0x9f */ , +HAL_RX_MPDU_DETAILS =160 /* 0xa0 */ , +HAL_EXAMPLE_USER_TLV_42 =161 /* 0xa1 */ , +HAL_RX_MSDU_LINK =162 /* 0xa2 */ , +HAL_RX_REO_QUEUE =163 /* 0xa3 */ , +HAL_ADDR_SEARCH_ENTRY =164 /* 0xa4 */ , +HAL_SCHEDULER_CMD =165 /* 0xa5 */ , +HAL_TX_FLUSH =166 /* 0xa6 */ , +HAL_TQM_ENTRANCE_RING =167 /* 0xa7 */ , +HAL_TX_DATA_WORD =168 /* 0xa8 */ , +HAL_TX_MPDU_DETAILS =169 /* 0xa9 */ , +HAL_TX_MPDU_LINK =170 /* 0xaa */ , +HAL_TX_MPDU_LINK_PTR =171 /* 0xab */ , +HAL_TX_MPDU_QUEUE_HEAD =172 /* 0xac */ , +HAL_TX_MPDU_QUEUE_EXT =173 /* 0xad */ , +HAL_TX_MPDU_QUEUE_EXT_PTR =174 /* 0xae */ , +HAL_TX_MSDU_DETAILS =175 /* 0xaf */ , +HAL_TX_MSDU_EXTENSION =176 /* 0xb0 */ , +HAL_TX_MSDU_FLOW =177 /* 0xb1 */ , +HAL_TX_MSDU_LINK =178 /* 0xb2 */ , +HAL_TX_MSDU_LINK_ENTRY_PTR =179 /* 0xb3 */ , +HAL_RESPONSE_RATE_SETTING =180 /* 0xb4 */ , +HAL_TXPCU_BUFFER_BASICS =181 /* 0xb5 */ , +HAL_UNIFORM_DESCRIPTOR_HEADER =182 /* 0xb6 */ , +HAL_UNIFORM_TQM_CMD_HEADER =183 /* 0xb7 */ , +HAL_UNIFORM_TQM_STATUS_HEADER =184 /* 0xb8 */ , +HAL_USER_RATE_SETTING =185 /* 0xb9 */ , +HAL_WBM_BUFFER_RING =186 /* 0xba */ , +HAL_WBM_LINK_DESCRIPTOR_RING =187 /* 0xbb */ , +HAL_WBM_RELEASE_RING =188 /* 0xbc */ , +HAL_TX_FLUSH_REQ =189 /* 0xbd */ , +HAL_RX_MSDU_DETAILS =190 /* 0xbe */ , +HAL_TQM_WRITE_CMD_STATUS =191 /* 0xbf */ , +HAL_TQM_GET_MPDU_QUEUE_STATS =192 /* 0xc0 */ , +HAL_TQM_GET_MSDU_FLOW_STATS =193 /* 0xc1 */ , +HAL_EXAMPLE_USER_CTLV_32 =194 /* 0xc2 */ , +HAL_TX_FES_STATUS_START =195 /* 0xc3 */ , +HAL_TX_FES_STATUS_USER_PPDU =196 /* 0xc4 */ , +HAL_TX_FES_STATUS_USER_RESPONSE =197 /* 0xc5 */ , +HAL_TX_FES_STATUS_END =198 /* 0xc6 */ , +HAL_RX_TRIG_INFO =199 /* 0xc7 */ , +HAL_RXPCU_TX_SETUP_CLEAR =200 /* 0xc8 */ , +HAL_RX_FRAME_BITMAP_REQ =201 /* 0xc9 */ , +HAL_RX_FRAME_BITMAP_ACK =202 /* 0xca */ , +HAL_COEX_RX_STATUS =203 /* 0xcb */ , +HAL_RX_START_PARAM =204 /* 0xcc */ , +HAL_RX_PPDU_START =205 /* 0xcd */ , +HAL_RX_PPDU_END =206 /* 0xce */ , +HAL_RX_MPDU_START =207 /* 0xcf */ , +HAL_RX_MPDU_END =208 /* 0xd0 */ , +HAL_RX_MSDU_START =209 /* 0xd1 */ , +HAL_RX_MSDU_END =210 /* 0xd2 */ , +HAL_RX_ATTENTION =211 /* 0xd3 */ , +HAL_RECEIVED_RESPONSE_INFO =212 /* 0xd4 */ , +HAL_RX_PHY_SLEEP =213 /* 0xd5 */ , +HAL_RX_HEADER =214 /* 0xd6 */ , +HAL_RX_PEER_ENTRY =215 /* 0xd7 */ , +HAL_RX_FLUSH =216 /* 0xd8 */ , +HAL_RX_RESPONSE_REQUIRED_INFO =217 /* 0xd9 */ , +HAL_RX_FRAMELESS_BAR_DETAILS =218 /* 0xda */ , +HAL_TQM_GET_MPDU_QUEUE_STATS_STATUS =219 /* 0xdb */ , +HAL_TQM_GET_MSDU_FLOW_STATS_STATUS =220 /* 0xdc */ , +HAL_TX_CBF_INFO =221 /* 0xdd */ , +HAL_PCU_PPDU_SETUP_USER =222 /* 0xde */ , +HAL_RX_MPDU_PCU_START =223 /* 0xdf */ , +HAL_RX_PM_INFO =224 /* 0xe0 */ , +HAL_RX_USER_PPDU_END =225 /* 0xe1 */ , +HAL_RX_PRE_PPDU_START =226 /* 0xe2 */ , +HAL_RX_PREAMBLE =227 /* 0xe3 */ , +HAL_TX_FES_SETUP_COMPLETE =228 /* 0xe4 */ , +HAL_TX_LAST_MPDU_FETCHED =229 /* 0xe5 */ , +HAL_TXDMA_STOP_REQUEST =230 /* 0xe6 */ , +HAL_RXPCU_SETUP =231 /* 0xe7 */ , +HAL_RXPCU_USER_SETUP =232 /* 0xe8 */ , +HAL_TX_FES_STATUS_ACK_OR_BA =233 /* 0xe9 */ , +HAL_TQM_ACKED_MPDU =234 /* 0xea */ , +HAL_COEX_TX_RESP =235 /* 0xeb */ , +HAL_COEX_TX_STATUS =236 /* 0xec */ , +HAL_MACTX_COEX_PHY_CTRL =237 /* 0xed */ , +HAL_COEX_STATUS_BROADCAST =238 /* 0xee */ , +HAL_RESPONSE_START_STATUS =239 /* 0xef */ , +HAL_RESPONSE_END_STATUS =240 /* 0xf0 */ , +HAL_CRYPTO_STATUS =241 /* 0xf1 */ , +HAL_RECEIVED_TRIGGER_INFO =242 /* 0xf2 */ , +HAL_REO_ENTRANCE_RING =243 /* 0xf3 */ , +HAL_RX_MPDU_LINK =244 /* 0xf4 */ , +HAL_COEX_TX_STOP_CTRL =245 /* 0xf5 */ , +HAL_RX_PPDU_ACK_REPORT =246 /* 0xf6 */ , +HAL_RX_PPDU_NO_ACK_REPORT =247 /* 0xf7 */ , +HAL_SCH_COEX_STATUS =248 /* 0xf8 */ , +HAL_SCHEDULER_COMMAND_STATUS =249 /* 0xf9 */ , +HAL_SCHEDULER_RX_PPDU_NO_RESPONSE_STATUS =250 /* 0xfa */ , +HAL_TX_FES_STATUS_PROT =251 /* 0xfb */ , +HAL_TX_FES_STATUS_START_PPDU =252 /* 0xfc */ , +HAL_TX_FES_STATUS_START_PROT =253 /* 0xfd */ , +HAL_TXPCU_PHYTX_DEBUG32 =254 /* 0xfe */ , +HAL_TXPCU_PHYTX_OTHER_TRANSMIT_INFO32 =255 /* 0xff */ , +HAL_TX_MPDU_COUNT_TRANSFER_END =256 /* 0x100 */ , +HAL_WHO_ANCHOR_OFFSET =257 /* 0x101 */ , +HAL_WHO_ANCHOR_VALUE =258 /* 0x102 */ , +HAL_WHO_CCE_INFO =259 /* 0x103 */ , +HAL_WHO_COMMIT =260 /* 0x104 */ , +HAL_WHO_COMMIT_DONE =261 /* 0x105 */ , +HAL_WHO_FLUSH =262 /* 0x106 */ , +HAL_WHO_L2_LLC =263 /* 0x107 */ , +HAL_WHO_L2_PAYLOAD =264 /* 0x108 */ , +HAL_WHO_L3_CHECKSUM =265 /* 0x109 */ , +HAL_WHO_L3_INFO =266 /* 0x10a */ , +HAL_WHO_L4_CHECKSUM =267 /* 0x10b */ , +HAL_WHO_L4_INFO =268 /* 0x10c */ , +HAL_WHO_MSDU =269 /* 0x10d */ , +HAL_WHO_MSDU_MISC =270 /* 0x10e */ , +HAL_WHO_PACKET_DATA =271 /* 0x10f */ , +HAL_WHO_PACKET_HDR =272 /* 0x110 */ , +HAL_WHO_PPDU_END =273 /* 0x111 */ , +HAL_WHO_PPDU_START =274 /* 0x112 */ , +HAL_WHO_TSO =275 /* 0x113 */ , +HAL_WHO_WMAC_HEADER_PV0 =276 /* 0x114 */ , +HAL_WHO_WMAC_HEADER_PV1 =277 /* 0x115 */ , +HAL_WHO_WMAC_IV =278 /* 0x116 */ , +HAL_MPDU_INFO_END =279 /* 0x117 */ , +HAL_MPDU_INFO_BITMAP =280 /* 0x118 */ , +HAL_TX_QUEUE_EXTENSION =281 /* 0x119 */ , +HAL_RX_PEER_ENTRY_DETAILS =282 /* 0x11a */ , +HAL_RX_REO_QUEUE_REFERENCE =283 /* 0x11b */ , +HAL_RX_REO_QUEUE_EXT =284 /* 0x11c */ , +HAL_SCHEDULER_SELFGEN_RESPONSE_STATUS =285 /* 0x11d */ , +HAL_TQM_UPDATE_TX_MPDU_COUNT_STATUS =286 /* 0x11e */ , +HAL_TQM_ACKED_MPDU_STATUS =287 /* 0x11f */ , +HAL_TQM_ADD_MSDU_STATUS =288 /* 0x120 */ , +HAL_RX_MPDU_LINK_PTR =289 /* 0x121 */ , +HAL_REO_DESTINATION_RING =290 /* 0x122 */ , +HAL_TQM_LIST_GEN_DONE =291 /* 0x123 */ , +HAL_WHO_TERMINATE =292 /* 0x124 */ , +HAL_TX_LAST_MPDU_END =293 /* 0x125 */ , +HAL_TX_CV_DATA =294 /* 0x126 */ , +HAL_TCL_ENTRANCE_FROM_PPE_RING =295 /* 0x127 */ , +HAL_PPDU_TX_END =296 /* 0x128 */ , +HAL_PROT_TX_END =297 /* 0x129 */ , +HAL_PDG_RESPONSE_RATE_SETTING =298 /* 0x12a */ , +HAL_MPDU_INFO_GLOBAL_END =299 /* 0x12b */ , +HAL_TQM_SCH_INSTR_GLOBAL_END =300 /* 0x12c */ , +HAL_RX_PPDU_END_USER_STATS =301 /* 0x12d */ , +HAL_RX_PPDU_END_USER_STATS_EXT =302 /* 0x12e */ , +HAL_NO_ACK_REPORT =303 /* 0x12f */ , +HAL_ACK_REPORT =304 /* 0x130 */ , +HAL_UNIFORM_REO_CMD_HEADER =305 /* 0x131 */ , +HAL_REO_GET_QUEUE_STATS =306 /* 0x132 */ , +HAL_REO_FLUSH_QUEUE =307 /* 0x133 */ , +HAL_REO_FLUSH_CACHE =308 /* 0x134 */ , +HAL_REO_UNBLOCK_CACHE =309 /* 0x135 */ , +HAL_UNIFORM_REO_STATUS_HEADER =310 /* 0x136 */ , +HAL_REO_GET_QUEUE_STATS_STATUS =311 /* 0x137 */ , +HAL_REO_FLUSH_QUEUE_STATUS =312 /* 0x138 */ , +HAL_REO_FLUSH_CACHE_STATUS =313 /* 0x139 */ , +HAL_REO_UNBLOCK_CACHE_STATUS =314 /* 0x13a */ , +HAL_TQM_FLUSH_CACHE =315 /* 0x13b */ , +HAL_TQM_UNBLOCK_CACHE =316 /* 0x13c */ , +HAL_TQM_FLUSH_CACHE_STATUS =317 /* 0x13d */ , +HAL_TQM_UNBLOCK_CACHE_STATUS =318 /* 0x13e */ , +HAL_RX_PPDU_END_STATUS_DONE =319 /* 0x13f */ , +HAL_RX_STATUS_BUFFER_DONE =320 /* 0x140 */ , +HAL_BUFFER_ADDR_INFO =321 /* 0x141 */ , +HAL_RX_MSDU_DESC_INFO =322 /* 0x142 */ , +HAL_RX_MPDU_DESC_INFO =323 /* 0x143 */ , +HAL_TCL_DATA_CMD =324 /* 0x144 */ , +HAL_TCL_GSE_CMD =325 /* 0x145 */ , +HAL_TCL_EXIT_BASE =326 /* 0x146 */ , +HAL_TCL_COMPACT_EXIT_RING =327 /* 0x147 */ , +HAL_TCL_REGULAR_EXIT_RING =328 /* 0x148 */ , +HAL_TCL_EXTENDED_EXIT_RING =329 /* 0x149 */ , +HAL_UPLINK_COMMON_INFO =330 /* 0x14a */ , +HAL_UPLINK_USER_SETUP_INFO =331 /* 0x14b */ , +HAL_TX_DATA_SYNC =332 /* 0x14c */ , +HAL_PHYRX_CBF_READ_REQUEST_ACK =333 /* 0x14d */ , +HAL_TCL_STATUS_RING =334 /* 0x14e */ , +HAL_TQM_GET_MPDU_HEAD_INFO =335 /* 0x14f */ , +HAL_TQM_SYNC_CMD =336 /* 0x150 */ , +HAL_TQM_GET_MPDU_HEAD_INFO_STATUS =337 /* 0x151 */ , +HAL_TQM_SYNC_CMD_STATUS =338 /* 0x152 */ , +HAL_TQM_THRESHOLD_DROP_NOTIFICATION_STATUS =339 /* 0x153 */ , +HAL_TQM_DESCRIPTOR_THRESHOLD_REACHED_STATUS =340 /* 0x154 */ , +HAL_REO_FLUSH_TIMEOUT_LIST =341 /* 0x155 */ , +HAL_REO_FLUSH_TIMEOUT_LIST_STATUS =342 /* 0x156 */ , +HAL_REO_TO_PPE_RING =343 /* 0x157 */ , +HAL_RX_MPDU_INFO =344 /* 0x158 */ , +HAL_REO_DESCRIPTOR_THRESHOLD_REACHED_STATUS =345 /* 0x159 */ , +HAL_SCHEDULER_RX_SIFS_RESPONSE_TRIGGER_STATUS =346 /* 0x15a */ , +HAL_EXAMPLE_USER_TLV_32_NAME =347 /* 0x15b */ , +HAL_RX_PPDU_START_USER_INFO =348 /* 0x15c */ , +HAL_RX_RXPCU_CLASSIFICATION_OVERVIEW =349 /* 0x15d */ , +HAL_RX_RING_MASK =350 /* 0x15e */ , +HAL_WHO_CLASSIFY_INFO =351 /* 0x15f */ , +HAL_TXPT_CLASSIFY_INFO =352 /* 0x160 */ , +HAL_RXPT_CLASSIFY_INFO =353 /* 0x161 */ , +HAL_TX_FLOW_SEARCH_ENTRY =354 /* 0x162 */ , +HAL_RX_FLOW_SEARCH_ENTRY =355 /* 0x163 */ , +HAL_RECEIVED_TRIGGER_INFO_DETAILS =356 /* 0x164 */ , +HAL_COEX_MAC_NAP =357 /* 0x165 */ , +HAL_MACRX_ABORT_REQUEST_INFO =358 /* 0x166 */ , +HAL_MACTX_ABORT_REQUEST_INFO =359 /* 0x167 */ , +HAL_PHYRX_ABORT_REQUEST_INFO =360 /* 0x168 */ , +HAL_PHYTX_ABORT_REQUEST_INFO =361 /* 0x169 */ , +HAL_RXPCU_PPDU_END_INFO =362 /* 0x16a */ , +HAL_WHO_MESH_CONTROL =363 /* 0x16b */ , +HAL_L_SIG_A_INFO =364 /* 0x16c */ , +HAL_L_SIG_B_INFO =365 /* 0x16d */ , +HAL_HT_SIG_INFO =366 /* 0x16e */ , +HAL_VHT_SIG_A_INFO =367 /* 0x16f */ , +HAL_VHT_SIG_B_SU20_INFO =368 /* 0x170 */ , +HAL_VHT_SIG_B_SU40_INFO =369 /* 0x171 */ , +HAL_VHT_SIG_B_SU80_INFO =370 /* 0x172 */ , +HAL_VHT_SIG_B_SU160_INFO =371 /* 0x173 */ , +HAL_VHT_SIG_B_MU20_INFO =372 /* 0x174 */ , +HAL_VHT_SIG_B_MU40_INFO =373 /* 0x175 */ , +HAL_VHT_SIG_B_MU80_INFO =374 /* 0x176 */ , +HAL_VHT_SIG_B_MU160_INFO =375 /* 0x177 */ , +HAL_SERVICE_INFO =376 /* 0x178 */ , +HAL_HE_SIG_A_SU_INFO =377 /* 0x179 */ , +HAL_HE_SIG_A_MU_DL_INFO =378 /* 0x17a */ , +HAL_HE_SIG_A_MU_UL_INFO =379 /* 0x17b */ , +HAL_HE_SIG_B1_MU_INFO =380 /* 0x17c */ , +HAL_HE_SIG_B2_MU_INFO =381 /* 0x17d */ , +HAL_HE_SIG_B2_OFDMA_INFO =382 /* 0x17e */ , +HAL_PDG_SW_MODE_BW_START =383 /* 0x17f */ , +HAL_PDG_SW_MODE_BW_END =384 /* 0x180 */ , +HAL_PDG_WAIT_FOR_MAC_REQUEST =385 /* 0x181 */ , +HAL_PDG_WAIT_FOR_PHY_REQUEST =386 /* 0x182 */ , +HAL_SCHEDULER_END =387 /* 0x183 */ , +HAL_PEER_TABLE_ENTRY =388 /* 0x184 */ , +HAL_SW_PEER_INFO =389 /* 0x185 */ , +HAL_RXOLE_CCE_CLASSIFY_INFO =390 /* 0x186 */ , +HAL_TCL_CCE_CLASSIFY_INFO =391 /* 0x187 */ , +HAL_RXOLE_CCE_INFO =392 /* 0x188 */ , +HAL_TCL_CCE_INFO =393 /* 0x189 */ , +HAL_TCL_CCE_SUPERRULE =394 /* 0x18a */ , +HAL_CCE_RULE =395 /* 0x18b */ , +HAL_RX_PPDU_START_DROPPED =396 /* 0x18c */ , +HAL_RX_PPDU_END_DROPPED =397 /* 0x18d */ , +HAL_RX_PPDU_END_STATUS_DONE_DROPPED =398 /* 0x18e */ , +HAL_RX_MPDU_START_DROPPED =399 /* 0x18f */ , +HAL_RX_MSDU_START_DROPPED =400 /* 0x190 */ , +HAL_RX_MSDU_END_DROPPED =401 /* 0x191 */ , +HAL_RX_MPDU_END_DROPPED =402 /* 0x192 */ , +HAL_RX_ATTENTION_DROPPED =403 /* 0x193 */ , +HAL_TXPCU_USER_SETUP =404 /* 0x194 */ , +HAL_RXPCU_USER_SETUP_EXT =405 /* 0x195 */ , +HAL_CE_SRC_DESC =406 /* 0x196 */ , +HAL_CE_STAT_DESC =407 /* 0x197 */ , +HAL_RXOLE_CCE_SUPERRULE =408 /* 0x198 */ , +HAL_TX_RATE_STATS_INFO =409 /* 0x199 */ , +HAL_CMD_PART_0_END =410 /* 0x19a */ , +HAL_MACTX_SYNTH_ON =411 /* 0x19b */ , +HAL_SCH_CRITICAL_TLV_REFERENCE =412 /* 0x19c */ , +HAL_TQM_MPDU_GLOBAL_START =413 /* 0x19d */ , +HAL_EXAMPLE_TLV_32 =414 /* 0x19e */ , +HAL_TQM_UPDATE_TX_MSDU_FLOW =415 /* 0x19f */ , +HAL_TQM_UPDATE_TX_MPDU_QUEUE_HEAD =416 /* 0x1a0 */ , +HAL_TQM_UPDATE_TX_MSDU_FLOW_STATUS =417 /* 0x1a1 */ , +HAL_TQM_UPDATE_TX_MPDU_QUEUE_HEAD_STATUS =418 /* 0x1a2 */ , +HAL_REO_UPDATE_RX_REO_QUEUE =419 /* 0x1a3 */ , +HAL_CE_DST_DESC =420 /* 0x1a4 */ , +HAL_TLV_BASE =511 /* 0x1ff */ , +}; + +#define HAL_TLV_HDR_TAG GENMASK(9, 1) +#define HAL_TLV_HDR_LEN GENMASK(25, 10) + +#define HAL_TLV_ALIGN 4 + +struct hal_tlv_hdr { +u32 tl; +u8 value[0 ]; +} __packed; + +#define RX_MPDU_DESC_INFO0_MSDU_COUNT GENMASK(7, 0) +#define RX_MPDU_DESC_INFO0_SEQ_NUM GENMASK(19, 8) +#define RX_MPDU_DESC_INFO0_FRAG_FLAG BIT(20) +#define RX_MPDU_DESC_INFO0_MPDU_RETRY BIT(21) +#define RX_MPDU_DESC_INFO0_AMPDU_FLAG BIT(22) +#define RX_MPDU_DESC_INFO0_BAR_FRAME BIT(23) +#define RX_MPDU_DESC_INFO0_VALID_PN BIT(24) +#define RX_MPDU_DESC_INFO0_VALID_SA BIT(25) +#define RX_MPDU_DESC_INFO0_SA_IDX_TIMEOUT BIT(26) +#define RX_MPDU_DESC_INFO0_VALID_DA BIT(27) +#define RX_MPDU_DESC_INFO0_DA_MCBC BIT(28) +#define RX_MPDU_DESC_INFO0_DA_IDX_TIMEOUT BIT(29) +#define RX_MPDU_DESC_INFO0_RAW_MPDU BIT(30) + +struct rx_mpdu_desc { +u32 info0;/* %RX_MPDU_DESC_INFO */ +u32 meta_data; +} __packed; + +/* rx_mpdu_desc +* Producer: RXDMA +* Consumer: REO/SW/FW +* +* msdu_count +* The number of MSDUs within the MPDU +* +* mpdu_sequence_number +* The field can have two different meanings based on the setting +* of field 'bar_frame'. If 'bar_frame' is set, it means the MPDU +* start sequence number from the BAR frame otherwise it means +* the MPDU sequence number of the received frame. +* +* fragment_flag +* When set, this MPDU is a fragment and REO should forward this +* fragment MPDU to the REO destination ring without any reorder +* checks, pn checks or bitmap update. This implies that REO is +* forwarding the pointer to the MSDU link descriptor. +* +* mpdu_retry_bit +* The retry bit setting from the MPDU header of the received frame +* +* ampdu_flag +* Indicates the MPDU was received as part of an A-MPDU. +* +* bar_frame +* Indicates the received frame is a BAR frame. After processing, +* this frame shall be pushed to SW or deleted. +* +* valid_pn +* When not set, REO will not perform a PN sequence number check. +* +* valid_sa +* Indicates OLE found a valid SA entry for all MSDUs in this MPDU. +* +* sa_idx_timeout +* Indicates, at least 1 MSDU within the MPDU has an unsuccessful +* MAC source address search due to the expiration of search timer. +* +* valid_da +* When set, OLE found a valid DA entry for all MSDUs in this MPDU. +* +* da_mcbc +* Field Only valid if valid_da is set. Indicates at least one of +* the DA addresses is a Multicast or Broadcast address. +* +* da_idx_timeout +* Indicates, at least 1 MSDU within the MPDU has an unsuccessful +* MAC destination address search due to the expiration of search +* timer. +* +* raw_mpdu +* Field only valid when first_msdu_in_mpdu_flag is set. Indicates +* the contents in the MSDU buffer contains a 'RAW' MPDU. +*/ + +enum hal_rx_msdu_desc_reo_dest_ind { +HAL_RX_MSDU_DESC_REO_DEST_IND_TCL , +HAL_RX_MSDU_DESC_REO_DEST_IND_SW1 , +HAL_RX_MSDU_DESC_REO_DEST_IND_SW2 , +HAL_RX_MSDU_DESC_REO_DEST_IND_SW3 , +HAL_RX_MSDU_DESC_REO_DEST_IND_SW4 , +HAL_RX_MSDU_DESC_REO_DEST_IND_RELEASE , +HAL_RX_MSDU_DESC_REO_DEST_IND_FW , +}; + +#define RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU BIT(0) +#define RX_MSDU_DESC_INFO0_LAST_MSDU_IN_MPDU BIT(1) +#define RX_MSDU_DESC_INFO0_MSDU_CONTINUATION BIT(2) +#define RX_MSDU_DESC_INFO0_MSDU_LENGTH GENMASK(16, 3) +#define RX_MSDU_DESC_INFO0_REO_DEST_IND GENMASK(21, 17) +#define RX_MSDU_DESC_INFO0_MSDU_DROP BIT(22) +#define RX_MSDU_DESC_INFO0_VALID_SA BIT(23) +#define RX_MSDU_DESC_INFO0_SA_IDX_TIMEOUT BIT(24) +#define RX_MSDU_DESC_INFO0_VALID_DA BIT(25) +#define RX_MSDU_DESC_INFO0_DA_MCBC BIT(26) +#define RX_MSDU_DESC_INFO0_DA_IDX_TIMEOUT BIT(27) + +#define HAL_RX_MSDU_PKT_LENGTH_GET (val) \ + (FIELD_GET(RX_MSDU_DESC_INFO0_MSDU_LENGTH, (val))) + +struct rx_msdu_desc { +u32 info0; +u32 rsvd0; +} __packed; + +/* rx_msdu_desc +* +* first_msdu_in_mpdu +* Indicates first msdu in mpdu. +* +* last_msdu_in_mpdu +* Indicates last msdu in mpdu. This flag can be true only when +* 'Msdu_continuation' set to 0. This implies that when an msdu +* is spread out over multiple buffers and thus msdu_continuation +* is set, only for the very last buffer of the msdu, can the +* 'last_msdu_in_mpdu' be set. +* +* When both first_msdu_in_mpdu and last_msdu_in_mpdu are set, +* the MPDU that this MSDU belongs to only contains a single MSDU. +* +* msdu_continuation +* When set, this MSDU buffer was not able to hold the entire MSDU. +* The next buffer will therefor contain additional information +* related to this MSDU. +* +* msdu_length +* Field is only valid in combination with the 'first_msdu_in_mpdu' +* being set. Full MSDU length in bytes after decapsulation. This +* field is still valid for MPDU frames without A-MSDU. It still +* represents MSDU length after decapsulation Or in case of RAW +* MPDUs, it indicates the length of the entire MPDU (without FCS +* field). +* +* 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_. +* +* msdu_drop +* Indicates that REO shall drop this MSDU and not forward it to +* any other ring. +* +* valid_sa +* Indicates OLE found a valid SA entry for this MSDU. +* +* sa_idx_timeout +* Indicates, an unsuccessful MAC source address search due to +* the expiration of search timer for this MSDU. +* +* valid_da +* When set, OLE found a valid DA entry for this MSDU. +* +* da_mcbc +* Field Only valid if valid_da is set. Indicates the DA address +* is a Multicast or Broadcast address for this MSDU. +* +* da_idx_timeout +* Indicates, an unsuccessful MAC destination address search due +* to the expiration of search timer fot this MSDU. +*/ + +enum hal_reo_dest_ring_buffer_type { +HAL_REO_DEST_RING_BUFFER_TYPE_MSDU , +HAL_REO_DEST_RING_BUFFER_TYPE_LINK_DESC , +}; + +enum hal_reo_dest_ring_push_reason { +HAL_REO_DEST_RING_PUSH_REASON_ERR_DETECTED , +HAL_REO_DEST_RING_PUSH_REASON_ROUTING_INSTRUCTION , +}; + +enum hal_reo_dest_ring_error_code { +HAL_REO_DEST_RING_ERROR_CODE_DESC_ADDR_ZERO , +HAL_REO_DEST_RING_ERROR_CODE_DESC_INVALID , +HAL_REO_DEST_RING_ERROR_CODE_AMPDU_IN_NON_BA , +HAL_REO_DEST_RING_ERROR_CODE_NON_BA_DUPLICATE , +HAL_REO_DEST_RING_ERROR_CODE_BA_DUPLICATE , +HAL_REO_DEST_RING_ERROR_CODE_FRAME_2K_JUMP , +HAL_REO_DEST_RING_ERROR_CODE_BAR_2K_JUMP , +HAL_REO_DEST_RING_ERROR_CODE_FRAME_OOR , +HAL_REO_DEST_RING_ERROR_CODE_BAR_OOR , +HAL_REO_DEST_RING_ERROR_CODE_NO_BA_SESSION , +HAL_REO_DEST_RING_ERROR_CODE_FRAME_SN_EQUALS_SSN , +HAL_REO_DEST_RING_ERROR_CODE_PN_CHECK_FAILED , +HAL_REO_DEST_RING_ERROR_CODE_2K_ERR_FLAG_SET , +HAL_REO_DEST_RING_ERROR_CODE_PN_ERR_FLAG_SET , +HAL_REO_DEST_RING_ERROR_CODE_DESC_BLOCKED , +HAL_REO_DEST_RING_ERROR_CODE_MAX , +}; + +#define HAL_REO_DEST_RING_INFO0_QUEUE_ADDR_HI GENMASK(7, 0) +#define HAL_REO_DEST_RING_INFO0_BUFFER_TYPE BIT(8) +#define HAL_REO_DEST_RING_INFO0_PUSH_REASON GENMASK(10, 9) +#define HAL_REO_DEST_RING_INFO0_ERROR_CODE GENMASK(15, 11) +#define HAL_REO_DEST_RING_INFO0_RX_QUEUE_NUM GENMASK(31, 16) + +#define HAL_REO_DEST_RING_INFO1_REORDER_INFO_VALID BIT(0) +#define HAL_REO_DEST_RING_INFO1_REORDER_OPCODE GENMASK(4, 1) +#define HAL_REO_DEST_RING_INFO1_REORDER_SLOT_IDX GENMASK(12, 5) + +#define HAL_REO_DEST_RING_INFO2_RING_ID GENMASK(27, 20) +#define HAL_REO_DEST_RING_INFO2_LOOPING_COUNT GENMASK(31, 28) + +struct hal_reo_dest_ring { +struct ath11k_buffer_addr buf_addr_info; +struct rx_mpdu_desc rx_mpdu_info; +struct rx_msdu_desc rx_msdu_info; +u32 queue_addr_lo; +u32 info0;/* %HAL_REO_DEST_RING_INFO0_ */ +u32 info1;/* %HAL_REO_DEST_RING_INFO1_ */ +u32 rsvd0; +u32 rsvd1; +u32 rsvd2; +u32 rsvd3; +u32 rsvd4; +u32 rsvd5; +u32 info2;/* %HAL_REO_DEST_RING_INFO2_ */ +} __packed; + +/* hal_reo_dest_ring +* +* Producer: RXDMA +* Consumer: REO/SW/FW +* +* buf_addr_info +* Details of the physical address of a buffer or MSDU +* link descriptor. +* +* rx_mpdu_info +* General information related to the MPDU that is passed +* on from REO entrance ring to the REO destination ring. +* +* rx_msdu_info +* General information related to the MSDU that is passed +* on from RXDMA all the way to to the REO destination ring. +* +* queue_addr_lo +* Address (lower 32 bits) of the REO queue descriptor. +* +* queue_addr_hi +* Address (upper 8 bits) of the REO queue descriptor. +* +* buffer_type +* Indicates the type of address provided in the buf_addr_info. +* Values are defined in enum %HAL_REO_DEST_RING_BUFFER_TYPE_. +* +* push_reason +* Reason for pushing this frame to this exit ring. Values are +* defined in enum %HAL_REO_DEST_RING_PUSH_REASON_. +* +* error_code +* Valid only when 'push_reason' is set. All error codes are +* defined in enum %HAL_REO_DEST_RING_ERROR_CODE_. +* +* rx_queue_num +* Indicates the REO MPDU reorder queue id from which this frame +* originated. +* +* reorder_info_valid +* When set, REO has been instructed to not perform the actual +* re-ordering of frames for this queue, but just to insert +* the reorder opcodes. +* +* reorder_opcode +* Field is valid when 'reorder_info_valid' is set. This field is +* always valid for debug purpose as well. +* +* reorder_slot_idx +* Valid only when 'reorder_info_valid' is set. +* +* ring_id +* The buffer pointer ring id. +* 0 - Idle ring +* 1 - N refers to other rings. +* +* looping_count +* Indicates the number of times the producer of entries into +* this ring has looped around the ring. +*/ + +enum hal_reo_entr_rxdma_ecode { +HAL_REO_ENTR_RING_RXDMA_ECODE_OVERFLOW_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_MPDU_LEN_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_FCS_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_DECRYPT_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_TKIP_MIC_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_UNECRYPTED_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_MSDU_LEN_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_MSDU_LIMIT_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_WIFI_PARSE_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_AMSDU_PARSE_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_SA_TIMEOUT_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_DA_TIMEOUT_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_FLOW_TIMEOUT_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_FLUSH_REQUEST_ERR , +HAL_REO_ENTR_RING_RXDMA_ECODE_MAX , +}; + +#define HAL_REO_ENTR_RING_INFO0_QUEUE_ADDR_HI GENMASK(7, 0) +#define HAL_REO_ENTR_RING_INFO0_MPDU_BYTE_COUNT GENMASK(21, 8) +#define HAL_REO_ENTR_RING_INFO0_DEST_IND GENMASK(26, 22) +#define HAL_REO_ENTR_RING_INFO0_FRAMELESS_BAR BIT(27) + +#define HAL_REO_ENTR_RING_INFO1_RXDMA_PUSH_REASON GENMASK(1, 0) +#define HAL_REO_ENTR_RING_INFO1_RXDMA_ERROR_CODE GENMASK(6, 2) + +struct hal_reo_entrance_ring { +struct ath11k_buffer_addr buf_addr_info; +struct rx_mpdu_desc rx_mpdu_info; +u32 queue_addr_lo; +u32 info0;/* %HAL_REO_ENTR_RING_INFO0_ */ +u32 info1;/* %HAL_REO_ENTR_RING_INFO1_ */ +u32 info2;/* %HAL_REO_DEST_RING_INFO2_ */ + +} __packed; + +/* hal_reo_entrance_ring +* +* Producer: RXDMA +* Consumer: REO +* +* buf_addr_info +* Details of the physical address of a buffer or MSDU +* link descriptor. +* +* rx_mpdu_info +* General information related to the MPDU that is passed +* on from REO entrance ring to the REO destination ring. +* +* queue_addr_lo +* Address (lower 32 bits) of the REO queue descriptor. +* +* queue_addr_hi +* Address (upper 8 bits) of the REO queue descriptor. +* +* mpdu_byte_count +* An approximation of the number of bytes received in this MPDU. +* Used to keeps stats on the amount of data flowing +* through a queue. +* +* 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_. +* +* frameless_bar +* Indicates that this REO entrance ring struct contains BAR info +* from a multi TID BAR frame. The original multi TID BAR frame +* itself contained all the REO info for the first TID, but all +* the subsequent TID info and their linkage to the REO descriptors +* is passed down as 'frameless' BAR info. +* +* The only fields valid in this descriptor when this bit is set +* are queue_addr_lo, queue_addr_hi, mpdu_sequence_number, +* bar_frame and peer_meta_data. +* +* rxdma_push_reason +* Reason for pushing this frame to this exit ring. Values are +* defined in enum %HAL_REO_DEST_RING_PUSH_REASON_. +* +* rxdma_error_code +* Valid only when 'push_reason' is set. All error codes are +* defined in enum %HAL_REO_ENTR_RING_RXDMA_ECODE_. +* +* ring_id +* The buffer pointer ring id. +* 0 - Idle ring +* 1 - N refers to other rings. +* +* looping_count +* Indicates the number of times the producer of entries into +* this ring has looped around the ring. +*/ + +#define HAL_REO_CMD_HDR_INFO0_CMD_NUMBER GENMASK(15, 0) +#define HAL_REO_CMD_HDR_INFO0_STATUS_REQUIRED BIT(16) + +struct hal_reo_cmd_hdr { +u32 info0; +} __packed; + +#define HAL_REO_GET_QUEUE_STATS_INFO0_QUEUE_ADDR_HI GENMASK(7, 0) +#define HAL_REO_GET_QUEUE_STATS_INFO0_CLEAR_STATS BIT(8) + +struct hal_reo_get_queue_stats { +struct hal_reo_cmd_hdr cmd; +u32 queue_addr_lo; +u32 info0; +u32 rsvd0[6 ]; +} __packed; + +/* hal_reo_get_queue_stats +* Producer: SW +* Consumer: REO +* +* cmd +* Details for command execution tracking purposes. +* +* queue_addr_lo +* Address (lower 32 bits) of the REO queue descriptor. +* +* queue_addr_hi +* Address (upper 8 bits) of the REO queue descriptor. +* +* clear_stats +* Clear stats settings. When set, Clear the stats after +* generating the status. +* +* Following stats will be cleared. +* Timeout_count +* Forward_due_to_bar_count +* Duplicate_count +* Frames_in_order_count +* BAR_received_count +* MPDU_Frames_processed_count +* MSDU_Frames_processed_count +* Total_processed_byte_count +* Late_receive_MPDU_count +* window_jump_2k +* Hole_count +*/ + +#define HAL_REO_FLUSH_QUEUE_INFO0_DESC_ADDR_HI GENMASK(7, 0) +#define HAL_REO_FLUSH_QUEUE_INFO0_BLOCK_DESC_ADDR BIT(8) +#define HAL_REO_FLUSH_QUEUE_INFO0_BLOCK_RESRC_IDX GENMASK(10, 9) + +struct hal_reo_flush_queue { +struct hal_reo_cmd_hdr cmd; +u32 desc_addr_lo; +u32 info0; +u32 rsvd0[6 ]; +} __packed; + +#define HAL_REO_FLUSH_CACHE_INFO0_CACHE_ADDR_HI GENMASK(7, 0) +#define HAL_REO_FLUSH_CACHE_INFO0_FWD_ALL_MPDUS BIT(8) +#define HAL_REO_FLUSH_CACHE_INFO0_RELEASE_BLOCK_IDX BIT(9) +#define HAL_REO_FLUSH_CACHE_INFO0_BLOCK_RESRC_IDX GENMASK(11, 10) +#define HAL_REO_FLUSH_CACHE_INFO0_FLUSH_WO_INVALIDATE BIT(12) +#define HAL_REO_FLUSH_CACHE_INFO0_BLOCK_CACHE_USAGE BIT(13) +#define HAL_REO_FLUSH_CACHE_INFO0_FLUSH_ALL BIT(14) + +struct hal_reo_flush_cache { +struct hal_reo_cmd_hdr cmd; +u32 cache_addr_lo; +u32 info0; +u32 rsvd0[6 ]; +} __packed; + +#define HAL_TCL_DATA_CMD_INFO0_DESC_TYPE BIT(0) +#define HAL_TCL_DATA_CMD_INFO0_EPD BIT(1) +#define HAL_TCL_DATA_CMD_INFO0_ENCAP_TYPE GENMASK(3, 2) +#define HAL_TCL_DATA_CMD_INFO0_ENCRYPT_TYPE GENMASK(7, 4) +#define HAL_TCL_DATA_CMD_INFO0_SRC_BUF_SWAP BIT(8) +#define HAL_TCL_DATA_CMD_INFO0_LNK_META_SWAP BIT(9) +#define HAL_TCL_DATA_CMD_INFO0_SEARCH_TYPE BIT(12) +#define HAL_TCL_DATA_CMD_INFO0_ADDRX_EN BIT(14) +#define HAL_TCL_DATA_CMD_INFO0_ADDRY_EN BIT(15) +#define HAL_TCL_DATA_CMD_INFO0_CMD_NUM GENMASK(31, 16) + +#define HAL_TCL_DATA_CMD_INFO1_DATA_LEN GENMASK(15, 0) +#define HAL_TCL_DATA_CMD_INFO1_IP4_CKSUM_EN BIT(16) +#define HAL_TCL_DATA_CMD_INFO1_UDP4_CKSUM_EN BIT(17) +#define HAL_TCL_DATA_CMD_INFO1_UDP6_CKSUM_EN BIT(18) +#define HAL_TCL_DATA_CMD_INFO1_TCP4_CKSUM_EN BIT(19) +#define HAL_TCL_DATA_CMD_INFO1_TCP6_CKSUM_EN BIT(20) +#define HAL_TCL_DATA_CMD_INFO1_TO_FW BIT(21) +#define HAL_TCL_DATA_CMD_INFO1_PKT_OFFSET GENMASK(31, 23) + +#define HAL_TCL_DATA_CMD_INFO2_BUF_TIMESTAMP GENMASK(18, 0) +#define HAL_TCL_DATA_CMD_INFO2_BUF_T_VALID BIT(19) +#define HAL_TCL_DATA_CMD_INFO2_MESH_ENABLE BIT(20) +#define HAL_TCL_DATA_CMD_INFO2_TID_OVERWRITE BIT(21) +#define HAL_TCL_DATA_CMD_INFO2_TID GENMASK(25, 22) +#define HAL_TCL_DATA_CMD_INFO2_LMAC_ID GENMASK(27, 26) + +#define HAL_TCL_DATA_CMD_INFO3_DSCP_TID_TABLE_IDX GENMASK(5, 0) +#define HAL_TCL_DATA_CMD_INFO3_SEARCH_INDEX GENMASK(25, 6) +#define HAL_TCL_DATA_CMD_INFO3_CACHE_SET_NUM GENMASK(29, 26) + +#define HAL_TCL_DATA_CMD_INFO4_RING_ID GENMASK(27, 20) +#define HAL_TCL_DATA_CMD_INFO4_LOOPING_COUNT GENMASK(31, 28) + +enum hal_encrypt_type { +HAL_ENCRYPT_TYPE_WEP_40 , +HAL_ENCRYPT_TYPE_WEP_104 , +HAL_ENCRYPT_TYPE_TKIP_NO_MIC , +HAL_ENCRYPT_TYPE_WEP_128 , +HAL_ENCRYPT_TYPE_TKIP_MIC , +HAL_ENCRYPT_TYPE_WAPI , +HAL_ENCRYPT_TYPE_CCMP_128 , +HAL_ENCRYPT_TYPE_OPEN , +HAL_ENCRYPT_TYPE_CCMP_256 , +HAL_ENCRYPT_TYPE_GCMP_128 , +HAL_ENCRYPT_TYPE_AES_GCMP_256 , +HAL_ENCRYPT_TYPE_WAPI_GCM_SM4 , +}; + +enum hal_tcl_encap_type { +HAL_TCL_ENCAP_TYPE_RAW , +HAL_TCL_ENCAP_TYPE_NATIVE_WIFI , +HAL_TCL_ENCAP_TYPE_ETHERNET , +HAL_TCL_ENCAP_TYPE_802_3 =3 , +}; + +enum hal_tcl_desc_type { +HAL_TCL_DESC_TYPE_BUFFER , +HAL_TCL_DESC_TYPE_EXT_DESC , +}; + +enum hal_wbm_htt_tx_comp_status { +HAL_WBM_REL_HTT_TX_COMP_STATUS_OK , +HAL_WBM_REL_HTT_TX_COMP_STATUS_DROP , +HAL_WBM_REL_HTT_TX_COMP_STATUS_TTL , +HAL_WBM_REL_HTT_TX_COMP_STATUS_REINJ , +HAL_WBM_REL_HTT_TX_COMP_STATUS_INSPECT , +HAL_WBM_REL_HTT_TX_COMP_STATUS_MEC_NOTIFY , +}; + +struct hal_tcl_data_cmd { +struct ath11k_buffer_addr buf_addr_info; +u32 info0; +u32 info1; +u32 info2; +u32 info3; +u32 info4; +} __packed; + +/* hal_tcl_data_cmd +* +* buf_addr_info +* Details of the physical address of a buffer or MSDU +* link descriptor. +* +* desc_type +* Indicates the type of address provided in the buf_addr_info. +* Values are defined in enum %HAL_REO_DEST_RING_BUFFER_TYPE_. +* +* epd +* When this bit is set then input packet is an EPD type. +* +* encap_type +* Indicates the encapsulation that HW will perform. Values are +* defined in enum %HAL_TCL_ENCAP_TYPE_. +* +* encrypt_type +* Field only valid for encap_type: RAW +* Values are defined in enum %HAL_ENCRYPT_TYPE_. +* +* src_buffer_swap +* Treats source memory (packet buffer) organization as big-endian. +* 1'b0: Source memory is little endian +* 1'b1: Source memory is big endian +* +* link_meta_swap +* Treats link descriptor and Metadata as big-endian. +* 1'b0: memory is little endian +* 1'b1: memory is big endian +* +* search_type +* Search type select +* 0 - Normal search, 1 - Index based address search, +* 2 - Index based flow search +* +* addrx_en +* addry_en +* Address X/Y search enable in ASE correspondingly. +* 1'b0: Search disable +* 1'b1: Search Enable +* +* cmd_num +* This number can be used to match against status. +* +* data_length +* MSDU length in case of direct descriptor. Length of link +* extension descriptor in case of Link extension descriptor. +* +* *_checksum_en +* Enable checksum replacement for ipv4, udp_over_ipv4, ipv6, +* udp_over_ipv6, tcp_over_ipv4 and tcp_over_ipv6. +* +* to_fw +* Forward packet to FW along with classification result. The +* packet will not be forward to TQM when this bit is set. +* 1'b0: Use classification result to forward the packet. +* 1'b1: Override classification result & forward packet only to fw +* +* packet_offset +* Packet offset from Metadata in case of direct buffer descriptor. +* +* buffer_timestamp +* buffer_timestamp_valid +* Frame system entrance timestamp. It shall be filled by first +* module (SW, TCL or TQM) that sees the frames first. +* +* mesh_enable +* For raw WiFi frames, this indicates transmission to a mesh STA, +* enabling the interpretation of the 'Mesh Control Present' bit +* (bit 8) of QoS Control. +* For native WiFi frames, this indicates that a 'Mesh Control' +* field is present between the header and the LLC. +* +* hlos_tid_overwrite +* +* When set, TCL shall ignore the IP DSCP and VLAN PCP +* fields and use HLOS_TID as the final TID. Otherwise TCL +* shall consider the DSCP and PCP fields as well as HLOS_TID +* and choose a final TID based on the configured priority +* +* hlos_tid +* HLOS MSDU priority +* Field is used when HLOS_TID_overwrite is set. +* +* lmac_id +* TCL uses this LMAC_ID in address search, i.e, while +* finding matching entry for the packet in AST corresponding +* to given LMAC_ID +* +* If LMAC ID is all 1s (=> value 3), it indicates wildcard +* match for any MAC +* +* dscp_tid_table_num +* DSCP to TID mapping table number that need to be used +* for the MSDU. +* +* search_index +* The index that will be used for index based address or +* flow search. The field is valid when 'search_type' is 1 or 2. +* +* cache_set_num +* +* Cache set number that should be used to cache the index +* based search results, for address and flow search. This +* value should be equal to LSB four bits of the hash value of +* match data, in case of search index points to an entry which +* may be used in content based search also. The value can be +* anything when the entry pointed by search index will not be +* used for content based search. +* +* ring_id +* The buffer pointer ring ID. +* 0 refers to the IDLE ring +* 1 - N refers to other rings +* +* looping_count +* +* A count value that indicates the number of times the +* producer of entries into the Ring has looped around the +* ring. +* +* At initialization time, this value is set to 0. On the +* first loop, this value is set to 1. After the max value is +* reached allowed by the number of bits for this field, the +* count value continues with 0 again. +* +* In case SW is the consumer of the ring entries, it can +* use this field to figure out up to where the producer of +* entries has created new entries. This eliminates the need to +* check where the head pointer' of the ring is located once +* the SW starts processing an interrupt indicating that new +* entries have been put into this ring... +* +* Also note that SW if it wants only needs to look at the +* LSB bit of this count value. +*/ + +#define HAL_TCL_DESC_LEN sizeof(struct hal_tcl_data_cmd) + +enum hal_tcl_gse_ctrl { +HAL_TCL_GSE_CTRL_RD_STAT , +HAL_TCL_GSE_CTRL_SRCH_DIS , +HAL_TCL_GSE_CTRL_WR_BK_SINGLE , +HAL_TCL_GSE_CTRL_WR_BK_ALL , +HAL_TCL_GSE_CTRL_INVAL_SINGLE , +HAL_TCL_GSE_CTRL_INVAL_ALL , +HAL_TCL_GSE_CTRL_WR_BK_INVAL_SINGLE , +HAL_TCL_GSE_CTRL_WR_BK_INVAL_ALL , +HAL_TCL_GSE_CTRL_CLR_STAT_SINGLE , +}; + +/* hal_tcl_gse_ctrl +* +* rd_stat +* Report or Read statistics +* srch_dis +* Search disable. Report only Hash. +* wr_bk_single +* Write Back single entry +* wr_bk_all +* Write Back entire cache entry +* inval_single +* Invalidate single cache entry +* inval_all +* Invalidate entire cache +* wr_bk_inval_single +* Write back and invalidate single entry in cache +* wr_bk_inval_all +* Write back and invalidate entire cache +* clr_stat_single +* Clear statistics for single entry +*/ + +#define HAL_TCL_GSE_CMD_INFO0_CTRL_BUF_ADDR_HI GENMASK(7, 0) +#define HAL_TCL_GSE_CMD_INFO0_GSE_CTRL GENMASK(11, 8) +#define HAL_TCL_GSE_CMD_INFO0_GSE_SEL BIT(12) +#define HAL_TCL_GSE_CMD_INFO0_STATUS_DEST_RING_ID BIT(13) +#define HAL_TCL_GSE_CMD_INFO0_SWAP BIT(14) + +#define HAL_TCL_GSE_CMD_INFO1_RING_ID GENMASK(27, 20) +#define HAL_TCL_GSE_CMD_INFO1_LOOPING_COUNT GENMASK(31, 28) + +struct hal_tcl_gse_cmd { +u32 ctrl_buf_addr_lo; +u32 info0; +u32 meta_data[2 ]; +u32 rsvd0[2 ]; +u32 info1; +} __packed; + +/* hal_tcl_gse_cmd +* +* ctrl_buf_addr_lo, ctrl_buf_addr_hi +* Address of a control buffer containing additional info needed +* for this command execution. +* +* gse_ctrl +* GSE control operations. This includes cache operations and table +* entry statistics read/clear operation. Values are defined in +* enum %HAL_TCL_GSE_CTRL. +* +* gse_sel +* To select the ASE/FSE to do the operation mention by GSE_ctrl. +* 0: FSE select 1: ASE select +* +* status_destination_ring_id +* TCL status ring to which the GSE status needs to be send. +* +* swap +* Bit to enable byte swapping of contents of buffer. +* +* meta_data +* Meta data to be returned in the status descriptor +*/ + +enum hal_tcl_cache_op_res { +HAL_TCL_CACHE_OP_RES_DONE , +HAL_TCL_CACHE_OP_RES_NOT_FOUND , +HAL_TCL_CACHE_OP_RES_TIMEOUT , +}; + +#define HAL_TCL_STATUS_RING_INFO0_GSE_CTRL GENMASK(3, 0) +#define HAL_TCL_STATUS_RING_INFO0_GSE_SEL BIT(4) +#define HAL_TCL_STATUS_RING_INFO0_CACHE_OP_RES GENMASK(6, 5) +#define HAL_TCL_STATUS_RING_INFO0_MSDU_CNT GENMASK(31, 8) + +#define HAL_TCL_STATUS_RING_INFO1_HASH_IDX GENMASK(19, 0) + +#define HAL_TCL_STATUS_RING_INFO2_RING_ID GENMASK(27, 20) +#define HAL_TCL_STATUS_RING_INFO2_LOOPING_COUNT GENMASK(31, 28) + +struct hal_tcl_status_ring { +u32 info0; +u32 msdu_byte_count; +u32 msdu_timestamp; +u32 meta_data[2 ]; +u32 info1; +u32 rsvd0; +u32 info2; +} __packed; + +/* hal_tcl_status_ring +* +* gse_ctrl +* GSE control operations. This includes cache operations and table +* entry statistics read/clear operation. Values are defined in +* enum %HAL_TCL_GSE_CTRL. +* +* gse_sel +* To select the ASE/FSE to do the operation mention by GSE_ctrl. +* 0: FSE select 1: ASE select +* +* cache_op_res +* Cache operation result. Values are defined in enum +* %HAL_TCL_CACHE_OP_RES_. +* +* msdu_cnt +* msdu_byte_count +* MSDU count of Entry and MSDU byte count for entry 1. +* +* hash_indx +* Hash value of the entry in case of search failed or disabled. +*/ + +#define HAL_CE_SRC_DESC_ADDR_INFO_ADDR_HI GENMASK(7, 0) +#define HAL_CE_SRC_DESC_ADDR_INFO_HASH_EN BIT(8) +#define HAL_CE_SRC_DESC_ADDR_INFO_BYTE_SWAP BIT(9) +#define HAL_CE_SRC_DESC_ADDR_INFO_DEST_SWAP BIT(10) +#define HAL_CE_SRC_DESC_ADDR_INFO_GATHER BIT(11) +#define HAL_CE_SRC_DESC_ADDR_INFO_LEN GENMASK(31, 16) + +#define HAL_CE_SRC_DESC_META_INFO_DATA GENMASK(15, 0) + +#define HAL_CE_SRC_DESC_FLAGS_RING_ID GENMASK(27, 20) +#define HAL_CE_SRC_DESC_FLAGS_LOOP_CNT HAL_SRNG_DESC_LOOP_CNT + +struct hal_ce_srng_src_desc { +u32 buffer_addr_low; +u32 buffer_addr_info;/* %HAL_CE_SRC_DESC_ADDR_INFO_ */ +u32 meta_info;/* %HAL_CE_SRC_DESC_META_INFO_ */ +u32 flags;/* %HAL_CE_SRC_DESC_FLAGS_ */ +} __packed; + +/* +* hal_ce_srng_src_desc +* +* buffer_addr_lo +* LSB 32 bits of the 40 Bit Pointer to the source buffer +* +* buffer_addr_hi +* MSB 8 bits of the 40 Bit Pointer to the source buffer +* +* toeplitz_en +* Enable generation of 32-bit Toeplitz-LFSR hash for +* data transfer. In case of gather field in first source +* ring entry of the gather copy cycle in taken into account. +* +* src_swap +* Treats source memory organization as big-endian. For +* each dword read (4 bytes), the byte 0 is swapped with byte 3 +* and byte 1 is swapped with byte 2. +* In case of gather field in first source ring entry of +* the gather copy cycle in taken into account. +* +* dest_swap +* Treats destination memory organization as big-endian. +* For each dword write (4 bytes), the byte 0 is swapped with +* byte 3 and byte 1 is swapped with byte 2. +* In case of gather field in first source ring entry of +* the gather copy cycle in taken into account. +* +* gather +* Enables gather of multiple copy engine source +* descriptors to one destination. +* +* ce_res_0 +* Reserved +* +* +* length +* Length of the buffer in units of octets of the current +* descriptor +* +* fw_metadata +* Meta data used by FW. +* In case of gather field in first source ring entry of +* the gather copy cycle in taken into account. +* +* ce_res_1 +* Reserved +* +* ce_res_2 +* Reserved +* +* ring_id +* The buffer pointer ring ID. +* 0 refers to the IDLE ring +* 1 - N refers to other rings +* Helps with debugging when dumping ring contents. +* +* looping_count +* A count value that indicates the number of times the +* producer of entries into the Ring has looped around the +* ring. +* +* At initialization time, this value is set to 0. On the +* first loop, this value is set to 1. After the max value is +* reached allowed by the number of bits for this field, the +* count value continues with 0 again. +* +* In case SW is the consumer of the ring entries, it can +* use this field to figure out up to where the producer of +* entries has created new entries. This eliminates the need to +* check where the head pointer' of the ring is located once +* the SW starts processing an interrupt indicating that new +* entries have been put into this ring... +* +* Also note that SW if it wants only needs to look at the +* LSB bit of this count value. +*/ + +#define HAL_CE_DEST_DESC_ADDR_INFO_ADDR_HI GENMASK(7, 0) +#define HAL_CE_DEST_DESC_ADDR_INFO_RING_ID GENMASK(27, 20) +#define HAL_CE_DEST_DESC_ADDR_INFO_LOOP_CNT HAL_SRNG_DESC_LOOP_CNT + +struct hal_ce_srng_dest_desc { +u32 buffer_addr_low; +u32 buffer_addr_info;/* %HAL_CE_DEST_DESC_ADDR_INFO_ */ +} __packed; + +/* hal_ce_srng_dest_desc +* +* dst_buffer_low +* LSB 32 bits of the 40 Bit Pointer to the Destination +* buffer +* +* dst_buffer_high +* MSB 8 bits of the 40 Bit Pointer to the Destination +* buffer +* +* ce_res_4 +* Reserved +* +* ring_id +* The buffer pointer ring ID. +* 0 refers to the IDLE ring +* 1 - N refers to other rings +* Helps with debugging when dumping ring contents. +* +* looping_count +* A count value that indicates the number of times the +* producer of entries into the Ring has looped around the +* ring. +* +* At initialization time, this value is set to 0. On the +* first loop, this value is set to 1. After the max value is +* reached allowed by the number of bits for this field, the +* count value continues with 0 again. +* +* In case SW is the consumer of the ring entries, it can +* use this field to figure out up to where the producer of +* entries has created new entries. This eliminates the need to +* check where the head pointer' of the ring is located once +* the SW starts processing an interrupt indicating that new +* entries have been put into this ring... +* +* Also note that SW if it wants only needs to look at the +* LSB bit of this count value. +*/ + +#define HAL_CE_DST_STATUS_DESC_FLAGS_HASH_EN BIT(8) +#define HAL_CE_DST_STATUS_DESC_FLAGS_BYTE_SWAP BIT(9) +#define HAL_CE_DST_STATUS_DESC_FLAGS_DEST_SWAP BIT(10) +#define HAL_CE_DST_STATUS_DESC_FLAGS_GATHER BIT(11) +#define HAL_CE_DST_STATUS_DESC_FLAGS_LEN GENMASK(31, 16) + +#define HAL_CE_DST_STATUS_DESC_META_INFO_DATA GENMASK(7, 0) +#define HAL_CE_DST_STATUS_DESC_META_INFO_RING_ID GENMASK(27, 20) +#define HAL_CE_DST_STATUS_DESC_META_INFO_LOOP_CNT HAL_SRNG_DESC_LOOP_CNT + +struct hal_ce_srng_dst_status_desc { +u32 flags;/* %HAL_CE_DST_STATUS_DESC_FLAGS_ */ +u32 toeplitz_hash0; +u32 toeplitz_hash1; +u32 meta_info;/* HAL_CE_DST_STATUS_DESC_META_INFO_ */ +} __packed; + +/* hal_ce_srng_dst_status_desc +* +* ce_res_5 +* Reserved +* +* toeplitz_en +* +* src_swap +* Source memory buffer swapped +* +* dest_swap +* Destination memory buffer swapped +* +* gather +* Gather of multiple copy engine source descriptors to one +* destination enabled +* +* ce_res_6 +* Reserved +* +* length +* Sum of all the Lengths of the source descriptor in the +* gather chain +* +* toeplitz_hash_0 +* 32 LS bits of 64 bit Toeplitz LFSR hash result +* +* toeplitz_hash_1 +* 32 MS bits of 64 bit Toeplitz LFSR hash result +* +* fw_metadata +* Meta data used by FW +* In case of gather field in first source ring entry of +* the gather copy cycle in taken into account. +* +* ce_res_7 +* Reserved +* +* ring_id +* The buffer pointer ring ID. +* 0 refers to the IDLE ring +* 1 - N refers to other rings +* Helps with debugging when dumping ring contents. +* +* looping_count +* A count value that indicates the number of times the +* producer of entries into the Ring has looped around the +* ring. +* +* At initialization time, this value is set to 0. On the +* first loop, this value is set to 1. After the max value is +* reached allowed by the number of bits for this field, the +* count value continues with 0 again. +* +* In case SW is the consumer of the ring entries, it can +* use this field to figure out up to where the producer of +* entries has created new entries. This eliminates the need to +* check where the head pointer' of the ring is located once +* the SW starts processing an interrupt indicating that new +* entries have been put into this ring... +* +* Also note that SW if it wants only needs to look at the +* LSB bit of this count value. +*/ + +#define HAL_TX_RATE_STATS_INFO0_VALID BIT(0) +#define HAL_TX_RATE_STATS_INFO0_BW GENMASK(2, 1) +#define HAL_TX_RATE_STATS_INFO0_PKT_TYPE GENMASK(6, 3) +#define HAL_TX_RATE_STATS_INFO0_STBC BIT(7) +#define HAL_TX_RATE_STATS_INFO0_LDPC BIT(8) +#define HAL_TX_RATE_STATS_INFO0_SGI GENMASK(10, 9) +#define HAL_TX_RATE_STATS_INFO0_MCS GENMASK(14, 11) +#define HAL_TX_RATE_STATS_INFO0_OFDMA_TX BIT(15) +#define HAL_TX_RATE_STATS_INFO0_TONES_IN_RU GENMASK(27, 16) + +enum hal_tx_rate_stats_bw { +HAL_TX_RATE_STATS_BW_20 , +HAL_TX_RATE_STATS_BW_40 , +HAL_TX_RATE_STATS_BW_80 , +HAL_TX_RATE_STATS_BW_160 , +}; + +enum hal_tx_rate_stats_pkt_type { +HAL_TX_RATE_STATS_PKT_TYPE_11A , +HAL_TX_RATE_STATS_PKT_TYPE_11B , +HAL_TX_RATE_STATS_PKT_TYPE_11N , +HAL_TX_RATE_STATS_PKT_TYPE_11AC , +HAL_TX_RATE_STATS_PKT_TYPE_11AX , +}; + +enum hal_tx_rate_stats_sgi { +HAL_TX_RATE_STATS_SGI_08US , +HAL_TX_RATE_STATS_SGI_04US , +HAL_TX_RATE_STATS_SGI_16US , +HAL_TX_RATE_STATS_SGI_32US , +}; + +struct hal_tx_rate_stats { +u32 info0; +u32 tsf; +} __packed; + +struct hal_wbm_link_desc { +struct ath11k_buffer_addr buf_addr_info; +} __packed; + +/* hal_wbm_link_desc +* +* Producer: WBM +* Consumer: WBM +* +* buf_addr_info +* Details of the physical address of a buffer or MSDU +* link descriptor. +*/ + +enum hal_wbm_rel_src_module { +HAL_WBM_REL_SRC_MODULE_TQM , +HAL_WBM_REL_SRC_MODULE_RXDMA , +HAL_WBM_REL_SRC_MODULE_REO , +HAL_WBM_REL_SRC_MODULE_FW , +HAL_WBM_REL_SRC_MODULE_SW , +}; + +enum hal_wbm_rel_desc_type { +HAL_WBM_REL_DESC_TYPE_REL_MSDU , +HAL_WBM_REL_DESC_TYPE_MSDU_LINK , +HAL_WBM_REL_DESC_TYPE_MPDU_LINK , +HAL_WBM_REL_DESC_TYPE_MSDU_EXT , +HAL_WBM_REL_DESC_TYPE_QUEUE_EXT , +}; + +/* hal_wbm_rel_desc_type +* +* msdu_buffer +* The address points to an MSDU buffer +* +* msdu_link_descriptor +* The address points to an Tx MSDU link descriptor +* +* mpdu_link_descriptor +* The address points to an MPDU link descriptor +* +* msdu_ext_descriptor +* The address points to an MSDU extension descriptor +* +* queue_ext_descriptor +* The address points to an TQM queue extension descriptor. WBM should +* treat this is the same way as a link descriptor. +*/ + +enum hal_wbm_rel_bm_act { +HAL_WBM_REL_BM_ACT_PUT_IN_IDLE , +HAL_WBM_REL_BM_ACT_REL_MSDU , +}; + +/* hal_wbm_rel_bm_act +* +* put_in_idle_list +* Put the buffer or descriptor back in the idle list. In case of MSDU or +* MDPU link descriptor, BM does not need to check to release any +* individual MSDU buffers. +* +* release_msdu_list +* This BM action can only be used in combination with desc_type being +* msdu_link_descriptor. Field first_msdu_index points out which MSDU +* pointer in the MSDU link descriptor is the first of an MPDU that is +* released. BM shall release all the MSDU buffers linked to this first +* MSDU buffer pointer. All related MSDU buffer pointer entries shall be +* set to value 0, which represents the 'NULL' pointer. When all MSDU +* buffer pointers in the MSDU link descriptor are 'NULL', the MSDU link +* descriptor itself shall also be released. +*/ + +#define HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE GENMASK(2, 0) +#define HAL_WBM_RELEASE_INFO0_BM_ACTION GENMASK(5, 3) +#define HAL_WBM_RELEASE_INFO0_DESC_TYPE GENMASK(8, 6) +#define HAL_WBM_RELEASE_INFO0_FIRST_MSDU_IDX GENMASK(12, 9) +#define HAL_WBM_RELEASE_INFO0_TQM_RELEASE_REASON GENMASK(16, 13) +#define HAL_WBM_RELEASE_INFO0_RXDMA_PUSH_REASON GENMASK(18, 17) +#define HAL_WBM_RELEASE_INFO0_RXDMA_ERROR_CODE GENMASK(23, 19) +#define HAL_WBM_RELEASE_INFO0_REO_PUSH_REASON GENMASK(25, 24) +#define HAL_WBM_RELEASE_INFO0_REO_ERROR_CODE GENMASK(30, 26) +#define HAL_WBM_RELEASE_INFO0_WBM_INTERNAL_ERROR BIT(31) + +#define HAL_WBM_RELEASE_INFO1_TQM_STATUS_NUMBER GENMASK(23, 0) +#define HAL_WBM_RELEASE_INFO1_TRANSMIT_COUNT GENMASK(30, 24) + +#define HAL_WBM_RELEASE_INFO2_ACK_FRAME_RSSI GENMASK(7, 0) +#define HAL_WBM_RELEASE_INFO2_SW_REL_DETAILS_VALID BIT(8) +#define HAL_WBM_RELEASE_INFO2_FIRST_MSDU BIT(9) +#define HAL_WBM_RELEASE_INFO2_LAST_MSDU BIT(10) +#define HAL_WBM_RELEASE_INFO2_MSDU_IN_AMSDU BIT(11) +#define HAL_WBM_RELEASE_INFO2_FW_TX_NOTIF_FRAME BIT(12) +#define HAL_WBM_RELEASE_INFO2_BUFFER_TIMESTAMP GENMASK(31, 13) + +#define HAL_WBM_RELEASE_INFO3_PEER_ID GENMASK(15, 0) +#define HAL_WBM_RELEASE_INFO3_TID GENMASK(19, 16) +#define HAL_WBM_RELEASE_INFO3_RING_ID GENMASK(27, 20) +#define HAL_WBM_RELEASE_INFO3_LOOPING_COUNT GENMASK(31, 28) + +#define HAL_WBM_REL_HTT_TX_COMP_INFO0_STATUS GENMASK(12, 9) +#define HAL_WBM_REL_HTT_TX_COMP_INFO0_REINJ_REASON GENMASK(16, 13) +#define HAL_WBM_REL_HTT_TX_COMP_INFO0_EXP_FRAME BIT(17) + +struct hal_wbm_release_ring { +struct ath11k_buffer_addr buf_addr_info; +u32 info0; +u32 info1; +u32 info2; +struct hal_tx_rate_stats rate_stats; +u32 info3; +} __packed; + +/* hal_wbm_release_ring +* +* Producer: SW/TQM/RXDMA/REO/SWITCH +* Consumer: WBM/SW/FW +* +* HTT tx status is overlayed on wbm_release ring on 4-byte words 2, 3, 4 and 5 +* for software based completions. +* +* buf_addr_info +* Details of the physical address of the buffer or link descriptor. +* +* release_source_module +* Indicates which module initiated the release of this buffer/descriptor. +* Values are defined in enum %HAL_WBM_REL_SRC_MODULE_. +* +* bm_action +* Field only valid when the field return_buffer_manager in +* Released_buff_or_desc_addr_info indicates: +* WBM_IDLE_BUF_LIST / WBM_IDLE_DESC_LIST +* Values are defined in enum %HAL_WBM_REL_BM_ACT_. +* +* buffer_or_desc_type +* Field only valid when WBM is marked as the return_buffer_manager in +* the Released_Buffer_address_info. Indicates that type of buffer or +* descriptor is being released. Values are in enum %HAL_WBM_REL_DESC_TYPE. +* +* first_msdu_index +* Field only valid for the bm_action release_msdu_list. The index of the +* first MSDU in an MSDU link descriptor all belonging to the same MPDU. +* +* tqm_release_reason +* Field only valid when Release_source_module is set to release_source_TQM +* Release reasons are defined in enum %HAL_WBM_TQM_REL_REASON_. +* +* rxdma_push_reason +* reo_push_reason +* Indicates why rxdma/reo pushed the frame to this ring and values are +* defined in enum %HAL_REO_DEST_RING_PUSH_REASON_. +* +* rxdma_error_code +* Field only valid when 'rxdma_push_reason' set to 'error_detected'. +* Values are defined in enum %HAL_REO_ENTR_RING_RXDMA_ECODE_. +* +* reo_error_code +* Field only valid when 'reo_push_reason' set to 'error_detected'. Values +* are defined in enum %HAL_REO_DEST_RING_ERROR_CODE_. +* +* wbm_internal_error +* Is set when WBM got a buffer pointer but the action was to push it to +* the idle link descriptor ring or do link related activity OR +* Is set when WBM got a link buffer pointer but the action was to push it +* to the buffer descriptor ring. +* +* tqm_status_number +* The value in this field is equal to tqm_cmd_number in TQM command. It is +* used to correlate the statu with TQM commands. Only valid when +* release_source_module is TQM. +* +* transmit_count +* The number of times the frame has been transmitted, valid only when +* release source in TQM. +* +* ack_frame_rssi +* This field is only valid when the source is TQM. If this frame is +* removed as the result of the reception of an ACK or BA, this field +* indicates the RSSI of the received ACK or BA frame. +* +* sw_release_details_valid +* This is set when WMB got a 'release_msdu_list' command from TQM and +* return buffer manager is not WMB. WBM will then de-aggregate all MSDUs +* and pass them one at a time on to the 'buffer owner'. +* +* first_msdu +* Field only valid when SW_release_details_valid is set. +* When set, this MSDU is the first MSDU pointed to in the +* 'release_msdu_list' command. +* +* last_msdu +* Field only valid when SW_release_details_valid is set. +* When set, this MSDU is the last MSDU pointed to in the +* 'release_msdu_list' command. +* +* msdu_part_of_amsdu +* Field only valid when SW_release_details_valid is set. +* When set, this MSDU was part of an A-MSDU in MPDU +* +* fw_tx_notify_frame +* Field only valid when SW_release_details_valid is set. +* +* buffer_timestamp +* Field only valid when SW_release_details_valid is set. +* This is the Buffer_timestamp field from the +* Timestamp in units of 1024 us +* +* struct hal_tx_rate_stats rate_stats +* Details for command execution tracking purposes. +* +* sw_peer_id +* tid +* Field only valid when Release_source_module is set to +* release_source_TQM +* +* 1) Release of msdu buffer due to drop_frame = 1. Flow is +* not fetched and hence sw_peer_id and tid = 0 +* +* buffer_or_desc_type = e_num 0 +* MSDU_rel_buffertqm_release_reason = e_num 1 +* tqm_rr_rem_cmd_rem +* +* 2) Release of msdu buffer due to Flow is not fetched and +* hence sw_peer_id and tid = 0 +* +* buffer_or_desc_type = e_num 0 +* MSDU_rel_buffertqm_release_reason = e_num 1 +* tqm_rr_rem_cmd_rem +* +* 3) Release of msdu link due to remove_mpdu or acked_mpdu +* command. +* +* buffer_or_desc_type = e_num1 +* msdu_link_descriptortqm_release_reason can be:e_num 1 +* tqm_rr_rem_cmd_reme_num 2 tqm_rr_rem_cmd_tx +* e_num 3 tqm_rr_rem_cmd_notxe_num 4 tqm_rr_rem_cmd_aged +* +* This field represents the TID from the TX_MSDU_FLOW +* descriptor or TX_MPDU_QUEUE descriptor +* +* rind_id +* For debugging. +* This field is filled in by the SRNG module. +* It help to identify the ring that is being looked +* +* looping_count +* A count value that indicates the number of times the +* producer of entries into the Buffer Manager Ring has looped +* around the ring. +* +* At initialization time, this value is set to 0. On the +* first loop, this value is set to 1. After the max value is +* reached allowed by the number of bits for this field, the +* count value continues with 0 again. +* +* In case SW is the consumer of the ring entries, it can +* use this field to figure out up to where the producer of +* entries has created new entries. This eliminates the need to +* check where the head pointer' of the ring is located once +* the SW starts processing an interrupt indicating that new +* entries have been put into this ring... +* +* Also note that SW if it wants only needs to look at the +* LSB bit of this count value. +*/ + +/** +* enum hal_wbm_tqm_rel_reason - TQM release reason code +* @HAL_WBM_TQM_REL_REASON_FRAME_ACKED: ACK or BACK received for the frame +* @HAL_WBM_TQM_REL_REASON_CMD_REMOVE_MPDU: Command remove_mpdus initiated by SW +* @HAL_WBM_TQM_REL_REASON_CMD_REMOVE_TX: Command remove transmitted_mpdus +* initiated by sw. +* @HAL_WBM_TQM_REL_REASON_CMD_REMOVE_NOTX: Command remove untransmitted_mpdus +* initiated by sw. +* @HAL_WBM_TQM_REL_REASON_CMD_REMOVE_AGED_FRAMES: Command remove aged msdus or +* mpdus. +* @HAL_WBM_TQM_REL_REASON_CMD_REMOVE_RESEAON1: Remove command initiated by +* fw with fw_reason1. +* @HAL_WBM_TQM_REL_REASON_CMD_REMOVE_RESEAON2: Remove command initiated by +* fw with fw_reason2. +* @HAL_WBM_TQM_REL_REASON_CMD_REMOVE_RESEAON3: Remove command initiated by +* fw with fw_reason3. +*/ +enum hal_wbm_tqm_rel_reason { +HAL_WBM_TQM_REL_REASON_FRAME_ACKED , +HAL_WBM_TQM_REL_REASON_CMD_REMOVE_MPDU , +HAL_WBM_TQM_REL_REASON_CMD_REMOVE_TX , +HAL_WBM_TQM_REL_REASON_CMD_REMOVE_NOTX , +HAL_WBM_TQM_REL_REASON_CMD_REMOVE_AGED_FRAMES , +HAL_WBM_TQM_REL_REASON_CMD_REMOVE_RESEAON1 , +HAL_WBM_TQM_REL_REASON_CMD_REMOVE_RESEAON2 , +HAL_WBM_TQM_REL_REASON_CMD_REMOVE_RESEAON3 , +}; + +struct hal_wbm_buffer_ring { +struct ath11k_buffer_addr buf_addr_info; +}; + +enum hal_desc_owner { +HAL_DESC_OWNER_WBM , +HAL_DESC_OWNER_SW , +HAL_DESC_OWNER_TQM , +HAL_DESC_OWNER_RXDMA , +HAL_DESC_OWNER_REO , +HAL_DESC_OWNER_SWITCH , +}; + +enum hal_desc_buf_type { +HAL_DESC_BUF_TYPE_TX_MSDU_LINK , +HAL_DESC_BUF_TYPE_TX_MPDU_LINK , +HAL_DESC_BUF_TYPE_TX_MPDU_QUEUE_HEAD , +HAL_DESC_BUF_TYPE_TX_MPDU_QUEUE_EXT , +HAL_DESC_BUF_TYPE_TX_FLOW , +HAL_DESC_BUF_TYPE_TX_BUFFER , +HAL_DESC_BUF_TYPE_RX_MSDU_LINK , +HAL_DESC_BUF_TYPE_RX_MPDU_LINK , +HAL_DESC_BUF_TYPE_RX_REO_QUEUE , +HAL_DESC_BUF_TYPE_RX_REO_QUEUE_EXT , +HAL_DESC_BUF_TYPE_RX_BUFFER , +HAL_DESC_BUF_TYPE_IDLE_LINK , +}; + +#define HAL_DESC_REO_OWNED 4 +#define HAL_DESC_REO_QUEUE_DESC 8 +#define HAL_DESC_REO_QUEUE_EXT_DESC 9 +#define HAL_DESC_REO_NON_QOS_TID 16 + +#define HAL_DESC_HDR_INFO0_OWNER GENMASK(3, 0) +#define HAL_DESC_HDR_INFO0_BUF_TYPE GENMASK(7, 4) +#define HAL_DESC_HDR_INFO0_DBG_RESERVED GENMASK(31, 8) + +struct hal_desc_header { +u32 info0; +} __packed; + +struct hal_rx_mpdu_link_ptr { +struct ath11k_buffer_addr addr_info; +} __packed; + +struct hal_rx_msdu_details { +struct ath11k_buffer_addr buf_addr_info; +struct rx_msdu_desc rx_msdu_info; +} __packed; + +#define HAL_RX_MSDU_LNK_INFO0_RX_QUEUE_NUMBER GENMASK(15, 0) +#define HAL_RX_MSDU_LNK_INFO0_FIRST_MSDU_LNK BIT(16) + +struct hal_rx_msdu_link { +struct hal_desc_header desc_hdr; +struct ath11k_buffer_addr buf_addr_info; +u32 info0; +u32 pn[4 ]; +struct hal_rx_msdu_details msdu_link[6 ]; +} __packed; + +struct hal_rx_reo_queue_ext { +struct hal_desc_header desc_hdr; +u32 rsvd; +struct hal_rx_mpdu_link_ptr mpdu_link[15 ]; +} __packed; + +/* hal_rx_reo_queue_ext +* Consumer: REO +* Producer: REO +* +* descriptor_header +* Details about which module owns this struct. +* +* mpdu_link +* Pointer to the next MPDU_link descriptor in the MPDU queue. +*/ + +enum hal_rx_reo_queue_pn_size { +HAL_RX_REO_QUEUE_PN_SIZE_24 , +HAL_RX_REO_QUEUE_PN_SIZE_48 , +HAL_RX_REO_QUEUE_PN_SIZE_128 , +}; + +#define HAL_RX_REO_QUEUE_RX_QUEUE_NUMBER GENMASK(15, 0) + +#define HAL_RX_REO_QUEUE_INFO0_VLD BIT(0) +#define HAL_RX_REO_QUEUE_INFO0_ASSOC_LNK_DESC_COUNTER GENMASK(2, 1) +#define HAL_RX_REO_QUEUE_INFO0_DIS_DUP_DETECTION BIT(3) +#define HAL_RX_REO_QUEUE_INFO0_SOFT_REORDER_EN BIT(4) +#define HAL_RX_REO_QUEUE_INFO0_AC GENMASK(6, 5) +#define HAL_RX_REO_QUEUE_INFO0_BAR BIT(7) +#define HAL_RX_REO_QUEUE_INFO0_RETRY BIT(8) +#define HAL_RX_REO_QUEUE_INFO0_CHECK_2K_MODE BIT(9) +#define HAL_RX_REO_QUEUE_INFO0_OOR_MODE BIT(10) +#define HAL_RX_REO_QUEUE_INFO0_BA_WINDOW_SIZE GENMASK(18, 11) +#define HAL_RX_REO_QUEUE_INFO0_PN_CHECK BIT(19) +#define HAL_RX_REO_QUEUE_INFO0_EVEN_PN BIT(20) +#define HAL_RX_REO_QUEUE_INFO0_UNEVEN_PN BIT(21) +#define HAL_RX_REO_QUEUE_INFO0_PN_HANDLE_ENABLE BIT(22) +#define HAL_RX_REO_QUEUE_INFO0_PN_SIZE GENMASK(24, 23) +#define HAL_RX_REO_QUEUE_INFO0_IGNORE_AMPDU_FLG BIT(25) + +#define HAL_RX_REO_QUEUE_INFO1_SVLD BIT(0) +#define HAL_RX_REO_QUEUE_INFO1_SSN GENMASK(12, 1) +#define HAL_RX_REO_QUEUE_INFO1_CURRENT_IDX GENMASK(20, 13) +#define HAL_RX_REO_QUEUE_INFO1_SEQ_2K_ERR BIT(21) +#define HAL_RX_REO_QUEUE_INFO1_PN_ERR BIT(22) +#define HAL_RX_REO_QUEUE_INFO1_PN_VALID BIT(31) + +#define HAL_RX_REO_QUEUE_INFO2_MPDU_COUNT GENMASK(6, 0) +#define HAL_RX_REO_QUEUE_INFO2_MSDU_COUNT (31, 7) + +#define HAL_RX_REO_QUEUE_INFO3_TIMEOUT_COUNT GENMASK(9, 4) +#define HAL_RX_REO_QUEUE_INFO3_FWD_DUE_TO_BAR_CNT GENMASK(15, 10) +#define HAL_RX_REO_QUEUE_INFO3_DUPLICATE_COUNT GENMASK(31, 10) + +#define HAL_RX_REO_QUEUE_INFO4_FRAME_IN_ORD_COUNT GENMASK(23, 0) +#define HAL_RX_REO_QUEUE_INFO4_BAR_RECVD_COUNT GENMASK(31, 24) + +#define HAL_RX_REO_QUEUE_INFO5_LATE_RX_MPDU_COUNT GENMASK(11, 0) +#define HAL_RX_REO_QUEUE_INFO5_WINDOW_JUMP_2K GENMASK(15, 12) +#define HAL_RX_REO_QUEUE_INFO5_HOLE_COUNT GENMASK(31, 16) + +struct hal_rx_reo_queue { +struct hal_desc_header desc_hdr; +u32 rx_queue_num; +u32 info0; +u32 info1; +u32 pn[4 ]; +u32 last_rx_enqueue_timestamp; +u32 last_rx_dequeue_timestamp; +u32 next_aging_queue[2 ]; +u32 prev_aging_queue[2 ]; +u32 rx_bitmap[8 ]; +u32 info2; +u32 info3; +u32 info4; +u32 processed_mpdus; +u32 processed_msdus; +u32 processed_total_bytes; +u32 info5; +u32 rsvd[3 ]; +struct hal_rx_reo_queue_ext ext_desc[0 ]; +} __packed; + +/* hal_rx_reo_queue +* +* descriptor_header +* Details about which module owns this struct. Note that sub field +* Buffer_type shall be set to receive_reo_queue_descriptor. +* +* receive_queue_number +* Indicates the MPDU queue ID to which this MPDU link descriptor belongs. +* +* vld +* Valid bit indicating a session is established and the queue descriptor +* is valid. +* associated_link_descriptor_counter +* Indicates which of the 3 link descriptor counters shall be incremented +* or decremented when link descriptors are added or removed from this +* flow queue. +* disable_duplicate_detection +* When set, do not perform any duplicate detection. +* soft_reorder_enable +* When set, REO has been instructed to not perform the actual re-ordering +* of frames for this queue, but just to insert the reorder opcodes. +* ac +* Indicates the access category of the queue descriptor. +* bar +* Indicates if BAR has been received. +* retry +* Retry bit is checked if this bit is set. +* chk_2k_mode +* Indicates what type of operation is expected from Reo when the received +* frame SN falls within the 2K window. +* oor_mode +* Indicates what type of operation is expected when the received frame +* falls within the OOR window. +* ba_window_size +* Indicates the negotiated (window size + 1). Max of 256 bits. +* +* A value 255 means 256 bitmap, 63 means 64 bitmap, 0 (means non-BA +* session, with window size of 0). The 3 values here are the main values +* validated, but other values should work as well. +* +* A BA window size of 0 (=> one frame entry bitmat), means that there is +* no additional rx_reo_queue_ext desc. following rx_reo_queue in memory. +* A BA window size of 1 - 105, means that there is 1 rx_reo_queue_ext. +* A BA window size of 106 - 210, means that there are 2 rx_reo_queue_ext. +* A BA window size of 211 - 256, means that there are 3 rx_reo_queue_ext. +* pn_check_needed, pn_shall_be_even, pn_shall_be_uneven, pn_handling_enable, +* pn_size +* REO shall perform the PN increment check, even number check, uneven +* number check, PN error check and size of the PN field check. +* ignore_ampdu_flag +* REO shall ignore the ampdu_flag on entrance descriptor for this queue. +* +* svld +* Sequence number in next field is valid one. +* ssn +* Starting Sequence number of the session. +* current_index +* Points to last forwarded packet +* seq_2k_error_detected_flag +* REO has detected a 2k error jump in the sequence number and from that +* moment forward, all new frames are forwarded directly to FW, without +* duplicate detect, reordering, etc. +* pn_error_detected_flag +* REO has detected a PN error. +*/ + +#define HAL_REO_UPD_RX_QUEUE_INFO0_QUEUE_ADDR_HI GENMASK(7, 0) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_RX_QUEUE_NUM BIT(8) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_VLD BIT(9) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_ASSOC_LNK_DESC_CNT BIT(10) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_DIS_DUP_DETECTION BIT(11) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_SOFT_REORDER_EN BIT(12) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_AC BIT(13) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_BAR BIT(14) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_RETRY BIT(15) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_CHECK_2K_MODE BIT(16) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_OOR_MODE BIT(17) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_BA_WINDOW_SIZE BIT(18) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_CHECK BIT(19) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_EVEN_PN BIT(20) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_UNEVEN_PN BIT(21) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_HANDLE_ENABLE BIT(22) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_SIZE BIT(23) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_IGNORE_AMPDU_FLG BIT(24) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_SVLD BIT(25) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_SSN BIT(26) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_SEQ_2K_ERR BIT(27) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_ERR BIT(28) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_VALID BIT(29) +#define HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN BIT(30) + +#define HAL_REO_UPD_RX_QUEUE_INFO1_RX_QUEUE_NUMBER GENMASK(15, 0) +#define HAL_REO_UPD_RX_QUEUE_INFO1_VLD BIT(16) +#define HAL_REO_UPD_RX_QUEUE_INFO1_ASSOC_LNK_DESC_COUNTER GENMASK(18, 17) +#define HAL_REO_UPD_RX_QUEUE_INFO1_DIS_DUP_DETECTION BIT(19) +#define HAL_REO_UPD_RX_QUEUE_INFO1_SOFT_REORDER_EN BIT(20) +#define HAL_REO_UPD_RX_QUEUE_INFO1_AC GENMASK(22, 21) +#define HAL_REO_UPD_RX_QUEUE_INFO1_BAR BIT(23) +#define HAL_REO_UPD_RX_QUEUE_INFO1_RETRY BIT(24) +#define HAL_REO_UPD_RX_QUEUE_INFO1_CHECK_2K_MODE BIT(25) +#define HAL_REO_UPD_RX_QUEUE_INFO1_OOR_MODE BIT(26) +#define HAL_REO_UPD_RX_QUEUE_INFO1_PN_CHECK BIT(27) +#define HAL_REO_UPD_RX_QUEUE_INFO1_EVEN_PN BIT(28) +#define HAL_REO_UPD_RX_QUEUE_INFO1_UNEVEN_PN BIT(29) +#define HAL_REO_UPD_RX_QUEUE_INFO1_PN_HANDLE_ENABLE BIT(30) +#define HAL_REO_UPD_RX_QUEUE_INFO1_IGNORE_AMPDU_FLG BIT(31) + +#define HAL_REO_UPD_RX_QUEUE_INFO2_BA_WINDOW_SIZE GENMASK(7, 0) +#define HAL_REO_UPD_RX_QUEUE_INFO2_PN_SIZE GENMASK(9, 8) +#define HAL_REO_UPD_RX_QUEUE_INFO2_SVLD BIT(10) +#define HAL_REO_UPD_RX_QUEUE_INFO2_SSN GENMASK(22, 11) +#define HAL_REO_UPD_RX_QUEUE_INFO2_SEQ_2K_ERR BIT(23) +#define HAL_REO_UPD_RX_QUEUE_INFO2_PN_ERR BIT(24) +#define HAL_REO_UPD_RX_QUEUE_INFO2_PN_VALID BIT(25) + +struct hal_reo_update_rx_queue { +struct hal_reo_cmd_hdr cmd; +u32 queue_addr_lo; +u32 info0; +u32 info1; +u32 info2; +u32 pn[4 ]; +} __packed; + +#define HAL_REO_UNBLOCK_CACHE_INFO0_UNBLK_CACHE BIT(0) +#define HAL_REO_UNBLOCK_CACHE_INFO0_RESOURCE_IDX GENMASK(2, 1) + +struct hal_reo_unblock_cache { +struct hal_reo_cmd_hdr cmd; +u32 info0; +u32 rsvd[7 ]; +} __packed; + +enum hal_reo_exec_status { +HAL_REO_EXEC_STATUS_SUCCESS , +HAL_REO_EXEC_STATUS_BLOCKED , +HAL_REO_EXEC_STATUS_FAILED , +HAL_REO_EXEC_STATUS_RESOURCE_BLOCKED , +}; + +#define HAL_REO_STATUS_HDR_INFO0_STATUS_NUM GENMASK(15, 0) +#define HAL_REO_STATUS_HDR_INFO0_EXEC_TIME GENMASK(25, 16) +#define HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS GENMASK(27, 26) + +struct hal_reo_status_hdr { +u32 info0; +u32 timestamp; +} __packed; + +/* hal_reo_status_hdr +* Producer: REO +* Consumer: SW +* +* status_num +* The value in this field is equal to value of the reo command +* number. This field helps to correlate the statuses with the REO +* commands. +* +* execution_time (in us) +* The amount of time REO took to excecute the command. Note that +* this time does not include the duration of the command waiting +* in the command ring, before the execution started. +* +* execution_status +* Execution status of the command. Values are defined in +* enum %HAL_REO_EXEC_STATUS_. +*/ +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO0_SSN GENMASK(11, 0) +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO0_CUR_IDX GENMASK(19, 12) + +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO1_MPDU_COUNT GENMASK(6, 0) +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO1_MSDU_COUNT GENMASK(31, 7) + +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_TIMEOUT_COUNT GENMASK(9, 4) +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_FDTB_COUNT GENMASK(15, 10) +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_DUPLICATE_COUNT GENMASK(31, 16) + +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO3_FIO_COUNT GENMASK(23, 0) +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO3_BAR_RCVD_CNT GENMASK(31, 24) + +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_LATE_RX_MPDU GENMASK(11, 0) +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_WINDOW_JMP2K GENMASK(15, 12) +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_HOLE_COUNT GENMASK(31, 16) + +#define HAL_REO_GET_QUEUE_STATS_STATUS_INFO5_LOOPING_CNT GENMASK(31, 28) + +struct hal_reo_get_queue_stats_status { +struct hal_reo_status_hdr hdr; +u32 info0; +u32 pn[4 ]; +u32 last_rx_enqueue_timestamp; +u32 last_rx_dequeue_timestamp; +u32 rx_bitmap[8 ]; +u32 info1; +u32 info2; +u32 info3; +u32 num_mpdu_frames; +u32 num_msdu_frames; +u32 total_bytes; +u32 info4; +u32 info5; +} __packed; + +/* hal_reo_get_queue_stats_status +* Producer: REO +* Consumer: SW +* +* status_hdr +* Details that can link this status with the original command. It +* also contains info on how long REO took to execute this command. +* +* ssn +* Starting Sequence number of the session, this changes whenever +* window moves (can be filled by SW then maintained by REO). +* +* current_index +* Points to last forwarded packet. +* +* pn +* Bits of the PN number. +* +* last_rx_enqueue_timestamp +* last_rx_dequeue_timestamp +* Timestamp of arrival of the last MPDU for this queue and +* Timestamp of forwarding an MPDU accordingly. +* +* rx_bitmap +* When a bit is set, the corresponding frame is currently held +* in the re-order queue. The bitmap is Fully managed by HW. +* +* current_mpdu_count +* current_msdu_count +* The number of MPDUs and MSDUs in the queue. +* +* timeout_count +* The number of times REO started forwarding frames even though +* there is a hole in the bitmap. Forwarding reason is timeout. +* +* forward_due_to_bar_count +* The number of times REO started forwarding frames even though +* there is a hole in the bitmap. Fwd reason is reception of BAR. +* +* duplicate_count +* The number of duplicate frames that have been detected. +* +* frames_in_order_count +* The number of frames that have been received in order (without +* a hole that prevented them from being forwarded immediately). +* +* bar_received_count +* The number of times a BAR frame is received. +* +* mpdu_frames_processed_count +* msdu_frames_processed_count +* The total number of MPDU/MSDU frames that have been processed. +* +* total_bytes +* An approximation of the number of bytes received for this queue. +* +* late_receive_mpdu_count +* The number of MPDUs received after the window had already moved +* on. The 'late' sequence window is defined as +* (Window SSN - 256) - (Window SSN - 1). +* +* window_jump_2k +* The number of times the window moved more than 2K +* +* hole_count +* The number of times a hole was created in the receive bitmap. +* +* looping_count +* A count value that indicates the number of times the producer of +* entries into this Ring has looped around the ring. +*/ + +#define HAL_REO_STATUS_LOOP_CNT GENMASK(31, 28) + +#define HAL_REO_FLUSH_QUEUE_INFO0_ERR_DETECTED BIT(0) +#define HAL_REO_FLUSH_QUEUE_INFO0_RSVD GENMASK(31, 1) +#define HAL_REO_FLUSH_QUEUE_INFO1_RSVD GENMASK(27, 0) + +struct hal_reo_flush_queue_status { +struct hal_reo_status_hdr hdr; +u32 info0; +u32 rsvd0[21 ]; +u32 info1; +} __packed; + +/* hal_reo_flush_queue_status +* Producer: REO +* Consumer: SW +* +* status_hdr +* Details that can link this status with the original command. It +* also contains info on how long REO took to execute this command. +* +* error_detected +* Status of blocking resource +* +* 0 - No error has been detected while executing this command +* 1 - Error detected. The resource to be used for blocking was +* already in use. +* +* looping_count +* A count value that indicates the number of times the producer of +* entries into this Ring has looped around the ring. +*/ + +#define HAL_REO_FLUSH_CACHE_STATUS_INFO0_IS_ERR BIT(0) +#define HAL_REO_FLUSH_CACHE_STATUS_INFO0_BLOCK_ERR_CODE GENMASK(2, 1) +#define HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_STATUS_HIT BIT(8) +#define HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_DESC_TYPE GENMASK(11, 9) +#define HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_CLIENT_ID GENMASK(15, 12) +#define HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_ERR GENMASK(17, 16) +#define HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_COUNT GENMASK(25, 18) + +struct hal_reo_flush_cache_status { +struct hal_reo_status_hdr hdr; +u32 info0; +u32 rsvd0[21 ]; +u32 info1; +} __packed; + +/* hal_reo_flush_cache_status +* Producer: REO +* Consumer: SW +* +* status_hdr +* Details that can link this status with the original command. It +* also contains info on how long REO took to execute this command. +* +* error_detected +* Status for blocking resource handling +* +* 0 - No error has been detected while executing this command +* 1 - An error in the blocking resource management was detected +* +* block_error_details +* only valid when error_detected is set +* +* 0 - No blocking related errors found +* 1 - Blocking resource is already in use +* 2 - Resource requested to be unblocked, was not blocked +* +* cache_controller_flush_status_hit +* The status that the cache controller returned on executing the +* flush command. +* +* 0 - miss; 1 - hit +* +* cache_controller_flush_status_desc_type +* Flush descriptor type +* +* cache_controller_flush_status_client_id +* Module who made the flush request +* +* In REO, this is always 0 +* +* cache_controller_flush_status_error +* Error condition +* +* 0 - No error found +* 1 - HW interface is still busy +* 2 - Line currently locked. Used for one line flush command +* 3 - At least one line is still locked. +* Used for cache flush command. +* +* cache_controller_flush_count +* The number of lines that were actually flushed out +* +* looping_count +* A count value that indicates the number of times the producer of +* entries into this Ring has looped around the ring. +*/ + +#define HAL_REO_UNBLOCK_CACHE_STATUS_INFO0_IS_ERR BIT(0) +#define HAL_REO_UNBLOCK_CACHE_STATUS_INFO0_TYPE BIT(1) + +struct hal_reo_unblock_cache_status { +struct hal_reo_status_hdr hdr; +u32 info0; +u32 rsvd0[21 ]; +u32 info1; +} __packed; + +/* hal_reo_unblock_cache_status +* Producer: REO +* Consumer: SW +* +* status_hdr +* Details that can link this status with the original command. It +* also contains info on how long REO took to execute this command. +* +* error_detected +* 0 - No error has been detected while executing this command +* 1 - The blocking resource was not in use, and therefore it could +* not be unblocked. +* +* unblock_type +* Reference to the type of unblock command +* 0 - Unblock a blocking resource +* 1 - The entire cache usage is unblock +* +* looping_count +* A count value that indicates the number of times the producer of +* entries into this Ring has looped around the ring. +*/ + +#define HAL_REO_FLUSH_TIMEOUT_STATUS_INFO0_IS_ERR BIT(0) +#define HAL_REO_FLUSH_TIMEOUT_STATUS_INFO0_LIST_EMPTY BIT(1) + +#define HAL_REO_FLUSH_TIMEOUT_STATUS_INFO1_REL_DESC_COUNT GENMASK(15, 0) +#define HAL_REO_FLUSH_TIMEOUT_STATUS_INFO1_FWD_BUF_COUNT GENMASK(31, 16) + +struct hal_reo_flush_timeout_list_status { +struct hal_reo_status_hdr hdr; +u32 info0; +u32 info1; +u32 rsvd0[20 ]; +u32 info2; +} __packed; + +/* hal_reo_flush_timeout_list_status +* Producer: REO +* Consumer: SW +* +* status_hdr +* Details that can link this status with the original command. It +* also contains info on how long REO took to execute this command. +* +* error_detected +* 0 - No error has been detected while executing this command +* 1 - Command not properly executed and returned with error +* +* timeout_list_empty +* When set, REO has depleted the timeout list and all entries are +* gone. +* +* release_desc_count +* Producer: SW; Consumer: REO +* The number of link descriptor released +* +* forward_buf_count +* Producer: SW; Consumer: REO +* The number of buffers forwarded to the REO destination rings +* +* looping_count +* A count value that indicates the number of times the producer of +* entries into this Ring has looped around the ring. +*/ + +#define HAL_REO_DESC_THRESH_STATUS_INFO0_THRESH_INDEX GENMASK(1, 0) +#define HAL_REO_DESC_THRESH_STATUS_INFO1_LINK_DESC_COUNTER0 GENMASK(23, 0) +#define HAL_REO_DESC_THRESH_STATUS_INFO2_LINK_DESC_COUNTER1 GENMASK(23, 0) +#define HAL_REO_DESC_THRESH_STATUS_INFO3_LINK_DESC_COUNTER2 GENMASK(23, 0) +#define HAL_REO_DESC_THRESH_STATUS_INFO4_LINK_DESC_COUNTER_SUM GENMASK(23, 0) + +struct hal_reo_desc_thresh_reached_status { +struct hal_reo_status_hdr hdr; +u32 info0; +u32 info1; +u32 info2; +u32 info3; +u32 info4; +u32 rsvd0[17 ]; +u32 info5; +} __packed; + +/* hal_reo_desc_thresh_reached_status +* Producer: REO +* Consumer: SW +* +* status_hdr +* Details that can link this status with the original command. It +* also contains info on how long REO took to execute this command. +* +* threshold_index +* The index of the threshold register whose value got reached +* +* link_descriptor_counter0 +* link_descriptor_counter1 +* link_descriptor_counter2 +* link_descriptor_counter_sum +* Value of the respective counters at generation of this message +* +* looping_count +* A count value that indicates the number of times the producer of +* entries into this Ring has looped around the ring. +*/ + +#endif /* ATH11K_HAL_DESC_H */
PATCH v3 24/49 ath11k: add hal_rx.c
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/hal_rx.c | 1221 ++++++++++++++++++++++++++++++ 1 file changed, 1221 insertions(+)
drivers/net/wireless/ath/ath11k/hal_rx.c new file +1221 -0
@@ -0,0 +1,1221 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#include "ahb.h" +#include "debug.h" +#include "hal.h" +#include "hal_tx.h" +#include "hal_rx.h" +#include "hal_desc.h" + +static void ath11k_hal_reo_set_desc_hdr (struct hal_desc_header *hdr, +u8 owner,u8 buffer_type,u32 magic) +{ + hdr->info0 =FIELD_PREP (HAL_DESC_HDR_INFO0_OWNER , owner) | +FIELD_PREP (HAL_DESC_HDR_INFO0_BUF_TYPE , buffer_type); + +/* Magic pattern in reserved bits for debugging */ + hdr->info0 |=FIELD_PREP (HAL_DESC_HDR_INFO0_DBG_RESERVED , magic); +} + +static int ath11k_hal_reo_cmd_queue_stats (struct hal_tlv_hdr *tlv, +struct ath11k_hal_reo_cmd *cmd) +{ +struct hal_reo_get_queue_stats *desc; + + tlv->tl =FIELD_PREP (HAL_TLV_HDR_TAG ,HAL_REO_GET_QUEUE_STATS ) | +FIELD_PREP (HAL_TLV_HDR_LEN ,sizeof (*desc)); + + desc = (struct hal_reo_get_queue_stats *)tlv->value; +memset (&desc->queue_addr_lo,0 , + (sizeof (*desc) -sizeof (struct hal_reo_cmd_hdr ))); + + desc->cmd.info0 &= ~HAL_REO_CMD_HDR_INFO0_STATUS_REQUIRED ; +if (cmd->flag &HAL_REO_CMD_FLG_NEED_STATUS ) + desc->cmd.info0 |=HAL_REO_CMD_HDR_INFO0_STATUS_REQUIRED ; + + desc->queue_addr_lo = cmd->addr_lo; + desc->info0 =FIELD_PREP (HAL_REO_GET_QUEUE_STATS_INFO0_QUEUE_ADDR_HI , + cmd->addr_hi); +if (cmd->flag &HAL_REO_CMD_FLG_STATS_CLEAR ) + desc->info0 |=HAL_REO_GET_QUEUE_STATS_INFO0_CLEAR_STATS ; + +return FIELD_GET (HAL_REO_CMD_HDR_INFO0_CMD_NUMBER , desc->cmd.info0); +} + +static int ath11k_hal_reo_cmd_flush_cache (struct ath11k_hal *hal,struct hal_tlv_hdr *tlv, +struct ath11k_hal_reo_cmd *cmd) +{ +struct hal_reo_flush_cache *desc; +u8 avail_slot =ffz (hal->avail_blk_resource); + +if (cmd->flag &HAL_REO_CMD_FLG_FLUSH_BLOCK_LATER ) { +if (avail_slot >=HAL_MAX_AVAIL_BLK_RES ) +return -ENOSPC ; + + hal->current_blk_index = avail_slot; + } + + tlv->tl =FIELD_PREP (HAL_TLV_HDR_TAG ,HAL_REO_FLUSH_CACHE ) | +FIELD_PREP (HAL_TLV_HDR_LEN ,sizeof (*desc)); + + desc = (struct hal_reo_flush_cache *)tlv->value; +memset (&desc->cache_addr_lo,0 , + (sizeof (*desc) -sizeof (struct hal_reo_cmd_hdr ))); + + desc->cmd.info0 &= ~HAL_REO_CMD_HDR_INFO0_STATUS_REQUIRED ; +if (cmd->flag &HAL_REO_CMD_FLG_NEED_STATUS ) + desc->cmd.info0 |=HAL_REO_CMD_HDR_INFO0_STATUS_REQUIRED ; + + desc->cache_addr_lo = cmd->addr_lo; + desc->info0 =FIELD_PREP (HAL_REO_FLUSH_CACHE_INFO0_CACHE_ADDR_HI , + cmd->addr_hi); + +if (cmd->flag &HAL_REO_CMD_FLG_FLUSH_FWD_ALL_MPDUS ) + desc->info0 |=HAL_REO_FLUSH_CACHE_INFO0_FWD_ALL_MPDUS ; + +if (cmd->flag &HAL_REO_CMD_FLG_FLUSH_BLOCK_LATER ) { + desc->info0 |=HAL_REO_FLUSH_CACHE_INFO0_BLOCK_CACHE_USAGE ; + desc->info0 |= +FIELD_PREP (HAL_REO_FLUSH_CACHE_INFO0_BLOCK_RESRC_IDX , + avail_slot); + } + +if (cmd->flag &HAL_REO_CMD_FLG_FLUSH_NO_INVAL ) + desc->info0 |=HAL_REO_FLUSH_CACHE_INFO0_FLUSH_WO_INVALIDATE ; + +if (cmd->flag &HAL_REO_CMD_FLG_FLUSH_ALL ) + desc->info0 |=HAL_REO_FLUSH_CACHE_INFO0_FLUSH_ALL ; + +return FIELD_GET (HAL_REO_CMD_HDR_INFO0_CMD_NUMBER , desc->cmd.info0); +} + +static int ath11k_hal_reo_cmd_update_rx_queue (struct hal_tlv_hdr *tlv, +struct ath11k_hal_reo_cmd *cmd) +{ +struct hal_reo_update_rx_queue *desc; + + tlv->tl =FIELD_PREP (HAL_TLV_HDR_TAG ,HAL_REO_UPDATE_RX_REO_QUEUE ) | +FIELD_PREP (HAL_TLV_HDR_LEN ,sizeof (*desc)); + + desc = (struct hal_reo_update_rx_queue *)tlv->value; +memset (&desc->queue_addr_lo,0 , + (sizeof (*desc) -sizeof (struct hal_reo_cmd_hdr ))); + + desc->cmd.info0 &= ~HAL_REO_CMD_HDR_INFO0_STATUS_REQUIRED ; +if (cmd->flag &HAL_REO_CMD_FLG_NEED_STATUS ) + desc->cmd.info0 |=HAL_REO_CMD_HDR_INFO0_STATUS_REQUIRED ; + + desc->queue_addr_lo = cmd->addr_lo; + desc->info0 = +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_QUEUE_ADDR_HI , + cmd->addr_hi) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_RX_QUEUE_NUM , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_RX_QUEUE_NUM )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_VLD , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_VLD )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_ASSOC_LNK_DESC_CNT , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_ALDC )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_DIS_DUP_DETECTION , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_DIS_DUP_DETECTION )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_SOFT_REORDER_EN , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_SOFT_REORDER_EN )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_AC , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_AC )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_BAR , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_BAR )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_RETRY , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_RETRY )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_CHECK_2K_MODE , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_CHECK_2K_MODE )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_OOR_MODE , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_OOR_MODE )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_BA_WINDOW_SIZE , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_BA_WINDOW_SIZE )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_CHECK , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_PN_CHECK )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_EVEN_PN , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_EVEN_PN )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_UNEVEN_PN , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_UNEVEN_PN )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_HANDLE_ENABLE , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_PN_HANDLE_ENABLE )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_SIZE , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_PN_SIZE )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_IGNORE_AMPDU_FLG , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_IGNORE_AMPDU_FLG )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_SVLD , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_SVLD )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_SSN , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_SSN )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_SEQ_2K_ERR , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_SEQ_2K_ERR )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN_VALID , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_PN_VALID )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO0_UPD_PN , + !!(cmd->upd0 &HAL_REO_CMD_UPD0_PN )); + + desc->info1 = +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_RX_QUEUE_NUMBER , + cmd->rx_queue_num) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_VLD , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_VLD )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_ASSOC_LNK_DESC_COUNTER , +FIELD_GET (HAL_REO_CMD_UPD1_ALDC , cmd->upd1)) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_DIS_DUP_DETECTION , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_DIS_DUP_DETECTION )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_SOFT_REORDER_EN , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_SOFT_REORDER_EN )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_AC , +FIELD_GET (HAL_REO_CMD_UPD1_AC , cmd->upd1)) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_BAR , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_BAR )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_CHECK_2K_MODE , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_CHECK_2K_MODE )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_RETRY , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_RETRY )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_OOR_MODE , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_OOR_MODE )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_PN_CHECK , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_PN_CHECK )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_EVEN_PN , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_EVEN_PN )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_UNEVEN_PN , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_UNEVEN_PN )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_PN_HANDLE_ENABLE , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_PN_HANDLE_ENABLE )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO1_IGNORE_AMPDU_FLG , + !!(cmd->upd1 &HAL_REO_CMD_UPD1_IGNORE_AMPDU_FLG )); + +if (cmd->pn_size ==24 ) + cmd->pn_size =HAL_RX_REO_QUEUE_PN_SIZE_24 ; +else if (cmd->pn_size ==48 ) + cmd->pn_size =HAL_RX_REO_QUEUE_PN_SIZE_48 ; +else if (cmd->pn_size ==128 ) + cmd->pn_size =HAL_RX_REO_QUEUE_PN_SIZE_128 ; + +if (cmd->ba_window_size <1 ) + cmd->ba_window_size =1 ; + +if (cmd->ba_window_size ==1 ) + cmd->ba_window_size++; + + desc->info2 = +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO2_BA_WINDOW_SIZE , + cmd->ba_window_size -1 ) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO2_PN_SIZE , cmd->pn_size) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO2_SVLD , + !!(cmd->upd2 &HAL_REO_CMD_UPD2_SVLD )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO2_SSN , +FIELD_GET (HAL_REO_CMD_UPD2_SSN , cmd->upd2)) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO2_SEQ_2K_ERR , + !!(cmd->upd2 &HAL_REO_CMD_UPD2_SEQ_2K_ERR )) | +FIELD_PREP (HAL_REO_UPD_RX_QUEUE_INFO2_PN_ERR , + !!(cmd->upd2 &HAL_REO_CMD_UPD2_PN_ERR )); + +return FIELD_GET (HAL_REO_CMD_HDR_INFO0_CMD_NUMBER , desc->cmd.info0); +} + +int ath11k_hal_reo_cmd_send (struct ath11k_base *ab,struct hal_srng *srng, +enum hal_reo_cmd_type type, +struct ath11k_hal_reo_cmd *cmd) +{ +struct hal_tlv_hdr *reo_desc; +int ret; + +spin_lock_bh (&srng->lock); + +ath11k_hal_srng_access_begin (ab, srng); + reo_desc = (struct hal_tlv_hdr *)ath11k_hal_srng_src_get_next_entry (ab, srng); +if (!reo_desc) { + ret = -ENOBUFS ; + goto out; + } + +switch (type) { +case HAL_REO_CMD_GET_QUEUE_STATS : + ret =ath11k_hal_reo_cmd_queue_stats (reo_desc, cmd); +break ; +case HAL_REO_CMD_FLUSH_CACHE : + ret =ath11k_hal_reo_cmd_flush_cache (&ab->hal, reo_desc, cmd); +break ; +case HAL_REO_CMD_UPDATE_RX_QUEUE : + ret =ath11k_hal_reo_cmd_update_rx_queue (reo_desc, cmd); +break ; +case HAL_REO_CMD_FLUSH_QUEUE : +case HAL_REO_CMD_UNBLOCK_CACHE : +case HAL_REO_CMD_FLUSH_TIMEOUT_LIST : +ath11k_warn (ab,"Unsupported reo command %d\n" , type); + ret = -ENOTSUPP ; +break ; +default : +ath11k_warn (ab,"Unknown reo command %d\n" , type); + ret = -EINVAL ; +break ; + } + +out: +ath11k_hal_srng_access_end (ab, srng); +spin_unlock_bh (&srng->lock); + +return ret; +} + +void ath11k_hal_rx_buf_addr_info_set (void *desc,dma_addr_t paddr, +u32 cookie,u8 manager) +{ +struct ath11k_buffer_addr *binfo = (struct ath11k_buffer_addr *)desc; +u32 paddr_lo, paddr_hi; + + paddr_lo =lower_32_bits (paddr); + paddr_hi =upper_32_bits (paddr); + binfo->info0 =FIELD_PREP (BUFFER_ADDR_INFO0_ADDR , paddr_lo); + binfo->info1 =FIELD_PREP (BUFFER_ADDR_INFO1_ADDR , paddr_hi) | +FIELD_PREP (BUFFER_ADDR_INFO1_SW_COOKIE , cookie) | +FIELD_PREP (BUFFER_ADDR_INFO1_RET_BUF_MGR , manager); +} + +void ath11k_hal_rx_buf_addr_info_get (void *desc,dma_addr_t *paddr, +u32 *cookie,u8 *rbm) +{ +struct ath11k_buffer_addr *binfo = (struct ath11k_buffer_addr *)desc; + + *paddr = + (((u64 )FIELD_GET (BUFFER_ADDR_INFO1_ADDR , binfo->info1)) <<32 ) | +FIELD_GET (BUFFER_ADDR_INFO0_ADDR , binfo->info0); + *cookie =FIELD_GET (BUFFER_ADDR_INFO1_SW_COOKIE , binfo->info1); + *rbm =FIELD_GET (BUFFER_ADDR_INFO1_RET_BUF_MGR , binfo->info1); +} + +void ath11k_hal_rx_msdu_link_info_get (void *link_desc,u32 *num_msdus, +struct hal_rx_msdu_meta *meta, +enum hal_rx_buf_return_buf_manager *rbm) +{ +struct hal_rx_msdu_link *link = (struct hal_rx_msdu_link *)link_desc; +struct hal_rx_msdu_details *msdu; +int i; + + *num_msdus =HAL_NUM_RX_MSDUS_PER_LINK_DESC ; + + msdu = &link->msdu_link[0 ]; + *rbm =FIELD_GET (BUFFER_ADDR_INFO1_RET_BUF_MGR , + msdu->buf_addr_info.info1); + +for (i =0 ; i < *num_msdus; i++) { + msdu = &link->msdu_link[i]; + +if (!FIELD_GET (BUFFER_ADDR_INFO0_ADDR , + msdu->buf_addr_info.info0)) { + *num_msdus = i; +break ; + } + meta->msdu_len =FIELD_GET (RX_MSDU_DESC_INFO0_MSDU_LENGTH , + msdu->rx_msdu_info.info0); + meta->first = !!(msdu->rx_msdu_info.info0 & +RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU ); + meta->last = !!(msdu->rx_msdu_info.info0 & +RX_MSDU_DESC_INFO0_LAST_MSDU_IN_MPDU ); + meta->continuation = !!(msdu->rx_msdu_info.info0 & +RX_MSDU_DESC_INFO0_MSDU_CONTINUATION ); + meta->cookie =FIELD_GET (BUFFER_ADDR_INFO1_SW_COOKIE , + msdu->buf_addr_info.info1); + meta++; + } +} + +int ath11k_hal_desc_reo_parse_err (struct ath11k_base *ab,u32 *rx_desc, +dma_addr_t *paddr,u32 *desc_bank) +{ +struct hal_reo_dest_ring *desc = (struct hal_reo_dest_ring *)rx_desc; +enum hal_reo_dest_ring_push_reason push_reason; +enum hal_reo_dest_ring_error_code err_code; + + push_reason =FIELD_GET (HAL_REO_DEST_RING_INFO0_PUSH_REASON , + desc->info0); + err_code =FIELD_GET (HAL_REO_DEST_RING_INFO0_ERROR_CODE , + desc->info0); + ab->soc_stats.reo_error[err_code]++; + +if (push_reason !=HAL_REO_DEST_RING_PUSH_REASON_ERR_DETECTED && + push_reason !=HAL_REO_DEST_RING_PUSH_REASON_ROUTING_INSTRUCTION ) { +ath11k_warn (ab,"expected error push reason code, received %d\n" , + push_reason); +return -EINVAL ; + } + +if (FIELD_GET (HAL_REO_DEST_RING_INFO0_BUFFER_TYPE , desc->info0) != +HAL_REO_DEST_RING_BUFFER_TYPE_LINK_DESC ) { +ath11k_warn (ab,"expected buffer type link_desc" ); +return -EINVAL ; + } + +ath11k_hal_rx_reo_ent_paddr_get (ab, rx_desc, paddr, desc_bank); + +return 0 ; +} + +void ath11k_hal_rx_parse_dst_ring_desc (struct ath11k_base *ab,u32 *rx_desc, +struct hal_rx_meta_info *meta_info) +{ +struct hal_reo_dest_ring *desc = (struct hal_reo_dest_ring *)rx_desc; +struct rx_mpdu_desc *mpdu = &desc->rx_mpdu_info; +struct rx_msdu_desc *msdu = &desc->rx_msdu_info; +struct hal_rx_mpdu_meta *meta_mpdu = &meta_info->mpdu_meta; +struct hal_rx_msdu_meta *meta_msdu = &meta_info->msdu_meta; + + meta_info->push_reason =FIELD_GET (HAL_REO_DEST_RING_INFO0_PUSH_REASON , + desc->info0); + + meta_mpdu->msdu_cnt =FIELD_GET (RX_MPDU_DESC_INFO0_MSDU_COUNT , + mpdu->info0); + meta_mpdu->seq_num =FIELD_GET (RX_MPDU_DESC_INFO0_SEQ_NUM , mpdu->info0); + meta_mpdu->frag = !!(mpdu->info0 &RX_MPDU_DESC_INFO0_FRAG_FLAG ); + meta_mpdu->retry = !!(mpdu->info0 &RX_MPDU_DESC_INFO0_MPDU_RETRY ); + meta_mpdu->ampdu = !!(mpdu->info0 &RX_MPDU_DESC_INFO0_AMPDU_FLAG ); + meta_mpdu->raw = !!(mpdu->info0 &RX_MPDU_DESC_INFO0_RAW_MPDU ); + meta_mpdu->peer_meta = mpdu->meta_data; + + meta_msdu->cookie =FIELD_GET (BUFFER_ADDR_INFO1_SW_COOKIE , + desc->buf_addr_info.info1); + meta_msdu->msdu_len =FIELD_GET (RX_MSDU_DESC_INFO0_MSDU_LENGTH , + msdu->info0); + meta_msdu->first = + !!(msdu->info0 &RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU ); + meta_msdu->last = + !!(msdu->info0 &RX_MSDU_DESC_INFO0_LAST_MSDU_IN_MPDU ); + meta_msdu->continuation = + !!(msdu->info0 &RX_MSDU_DESC_INFO0_MSDU_CONTINUATION ); +} + +int ath11k_hal_wbm_desc_parse_err (struct ath11k_base *ab,void *desc, +struct hal_rx_wbm_rel_info *rel_info) +{ +struct hal_wbm_release_ring *wbm_desc = desc; +enum hal_wbm_rel_desc_type type; +enum hal_wbm_rel_src_module rel_src; + + type =FIELD_GET (HAL_WBM_RELEASE_INFO0_DESC_TYPE , + wbm_desc->info0); +/* We expect only WBM_REL buffer type */ +if (type !=HAL_WBM_REL_DESC_TYPE_REL_MSDU ) { +WARN_ON (1 ); +return -EINVAL ; + } + + rel_src =FIELD_GET (HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE , + wbm_desc->info0); +if (rel_src !=HAL_WBM_REL_SRC_MODULE_RXDMA && + rel_src !=HAL_WBM_REL_SRC_MODULE_REO ) +return -EINVAL ; + +if (FIELD_GET (BUFFER_ADDR_INFO1_RET_BUF_MGR , + wbm_desc->buf_addr_info.info1) !=HAL_RX_BUF_RBM_SW3_BM ) { + ab->soc_stats.invalid_rbm++; +return -EINVAL ; + } + + rel_info->cookie =FIELD_GET (BUFFER_ADDR_INFO1_SW_COOKIE , + wbm_desc->buf_addr_info.info1); + rel_info->err_rel_src = rel_src; +if (rel_src ==HAL_WBM_REL_SRC_MODULE_REO ) { + rel_info->push_reason = +FIELD_GET (HAL_WBM_RELEASE_INFO0_REO_PUSH_REASON , + wbm_desc->info0); + rel_info->err_code = +FIELD_GET (HAL_WBM_RELEASE_INFO0_REO_ERROR_CODE , + wbm_desc->info0); + }else { + rel_info->push_reason = +FIELD_GET (HAL_WBM_RELEASE_INFO0_RXDMA_PUSH_REASON , + wbm_desc->info0); + rel_info->err_code = +FIELD_GET (HAL_WBM_RELEASE_INFO0_RXDMA_ERROR_CODE , + wbm_desc->info0); + } + + rel_info->first_msdu =FIELD_GET (HAL_WBM_RELEASE_INFO2_FIRST_MSDU , + wbm_desc->info2); + rel_info->last_msdu =FIELD_GET (HAL_WBM_RELEASE_INFO2_LAST_MSDU , + wbm_desc->info2); +return 0 ; +} + +void ath11k_hal_rx_reo_ent_paddr_get (struct ath11k_base *ab,void *desc, +dma_addr_t *paddr,u32 *desc_bank) +{ +struct ath11k_buffer_addr *buff_addr = desc; + + *paddr = ((u64)(FIELD_GET (BUFFER_ADDR_INFO1_ADDR , buff_addr->info1)) <<32 ) | +FIELD_GET (BUFFER_ADDR_INFO0_ADDR , buff_addr->info0); + + *desc_bank =FIELD_GET (BUFFER_ADDR_INFO1_SW_COOKIE , buff_addr->info1); +} + +void ath11k_hal_rx_msdu_link_desc_set (struct ath11k_base *ab,void *desc, +void *link_desc, +enum hal_wbm_rel_bm_act action) +{ +struct hal_wbm_release_ring *dst_desc = desc; +struct hal_wbm_release_ring *src_desc = link_desc; + + dst_desc->buf_addr_info = src_desc->buf_addr_info; + dst_desc->info0 |=FIELD_PREP (HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE , +HAL_WBM_REL_SRC_MODULE_SW ) | +FIELD_PREP (HAL_WBM_RELEASE_INFO0_BM_ACTION , action) | +FIELD_PREP (HAL_WBM_RELEASE_INFO0_DESC_TYPE , +HAL_WBM_REL_DESC_TYPE_MSDU_LINK ); +} + +void ath11k_hal_reo_status_queue_stats (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status) +{ +struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; +struct hal_reo_get_queue_stats_status *desc = + (struct hal_reo_get_queue_stats_status *)tlv->value; + + status->uniform_hdr.cmd_num = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_STATUS_NUM , + desc->hdr.info0); + status->uniform_hdr.cmd_status = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS , + desc->hdr.info0); + +ath11k_dbg (ab, ATH11k_DBG_HAL,"Queue stats status:\n" ); +ath11k_dbg (ab, ATH11k_DBG_HAL,"header: cmd_num %d status %d\n" , + status->uniform_hdr.cmd_num, + status->uniform_hdr.cmd_status); +ath11k_dbg (ab, ATH11k_DBG_HAL,"ssn %ld cur_idx %ld\n" , +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO0_SSN , + desc->info0), +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO0_CUR_IDX , + desc->info0)); +ath11k_dbg (ab, ATH11k_DBG_HAL,"pn = [%08x, %08x, %08x, %08x]\n" , + desc->pn[0 ], desc->pn[1 ], desc->pn[2 ], desc->pn[3 ]); +ath11k_dbg (ab, ATH11k_DBG_HAL,"last_rx: enqueue_tstamp %08x dequeue_tstamp %08x\n" , + desc->last_rx_enqueue_timestamp, + desc->last_rx_dequeue_timestamp); +ath11k_dbg (ab, ATH11k_DBG_HAL,"rx_bitmap [%08x %08x %08x %08x %08x %08x %08x %08x]\n" , + desc->rx_bitmap[0 ], desc->rx_bitmap[1 ], desc->rx_bitmap[2 ], + desc->rx_bitmap[3 ], desc->rx_bitmap[4 ], desc->rx_bitmap[5 ], + desc->rx_bitmap[6 ], desc->rx_bitmap[7 ]); +ath11k_dbg (ab, ATH11k_DBG_HAL,"count: cur_mpdu %ld cur_msdu %ld\n" , +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO1_MPDU_COUNT , + desc->info1), +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO1_MSDU_COUNT , + desc->info1)); +ath11k_dbg (ab, ATH11k_DBG_HAL,"fwd_timeout %ld fwd_bar %ld dup_count %ld\n" , +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_TIMEOUT_COUNT , + desc->info2), +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_FDTB_COUNT , + desc->info2), +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_DUPLICATE_COUNT , + desc->info2)); +ath11k_dbg (ab, ATH11k_DBG_HAL,"frames_in_order %ld bar_rcvd %ld\n" , +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO3_FIO_COUNT , + desc->info3), +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO3_BAR_RCVD_CNT , + desc->info3)); +ath11k_dbg (ab, ATH11k_DBG_HAL,"num_mpdus %d num_msdus %d total_bytes %d\n" , + desc->num_mpdu_frames, desc->num_msdu_frames, + desc->total_bytes); +ath11k_dbg (ab, ATH11k_DBG_HAL,"late_rcvd %ld win_jump_2k %ld hole_cnt %ld\n" , +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_LATE_RX_MPDU , + desc->info4), +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_WINDOW_JMP2K , + desc->info4), +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_HOLE_COUNT , + desc->info4)); +ath11k_dbg (ab, ATH11k_DBG_HAL,"looping count %ld\n" , +FIELD_GET (HAL_REO_GET_QUEUE_STATS_STATUS_INFO5_LOOPING_CNT , + desc->info5)); +} + +int ath11k_hal_reo_process_status (u8 *reo_desc,u8 *status) +{ +struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; +struct hal_reo_status_hdr *hdr; + + hdr = (struct hal_reo_status_hdr *)tlv->value; + *status =FIELD_GET (HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS , hdr->info0); + +return FIELD_GET (HAL_REO_STATUS_HDR_INFO0_STATUS_NUM , hdr->info0); +} + +void ath11k_hal_reo_flush_queue_status (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status) +{ +struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; +struct hal_reo_flush_queue_status *desc = + (struct hal_reo_flush_queue_status *)tlv->value; + + status->uniform_hdr.cmd_num = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_STATUS_NUM , + desc->hdr.info0); + status->uniform_hdr.cmd_status = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS , + desc->hdr.info0); + status->u.flush_queue.err_detected = +FIELD_GET (HAL_REO_FLUSH_QUEUE_INFO0_ERR_DETECTED , + desc->info0); +} + +void ath11k_hal_reo_flush_cache_status (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status) +{ +struct ath11k_hal *hal = &ab->hal; +struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; +struct hal_reo_flush_cache_status *desc = + (struct hal_reo_flush_cache_status *)tlv->value; + + status->uniform_hdr.cmd_num = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_STATUS_NUM , + desc->hdr.info0); + status->uniform_hdr.cmd_status = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS , + desc->hdr.info0); + + status->u.flush_cache.err_detected = +FIELD_GET (HAL_REO_FLUSH_CACHE_STATUS_INFO0_IS_ERR , + desc->info0); + status->u.flush_cache.err_code = +FIELD_GET (HAL_REO_FLUSH_CACHE_STATUS_INFO0_BLOCK_ERR_CODE , + desc->info0); +if (!status->u.flush_cache.err_code) + hal->avail_blk_resource |=BIT (hal->current_blk_index); + + status->u.flush_cache.cache_controller_flush_status_hit = +FIELD_GET (HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_STATUS_HIT , + desc->info0); + + status->u.flush_cache.cache_controller_flush_status_desc_type = +FIELD_GET (HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_DESC_TYPE , + desc->info0); + status->u.flush_cache.cache_controller_flush_status_client_id = +FIELD_GET (HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_CLIENT_ID , + desc->info0); + status->u.flush_cache.cache_controller_flush_status_err = +FIELD_GET (HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_ERR , + desc->info0); + status->u.flush_cache.cache_controller_flush_status_cnt = +FIELD_GET (HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_COUNT , + desc->info0); +} + +void ath11k_hal_reo_unblk_cache_status (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status) +{ +struct ath11k_hal *hal = &ab->hal; +struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; +struct hal_reo_unblock_cache_status *desc = + (struct hal_reo_unblock_cache_status *)tlv->value; + + status->uniform_hdr.cmd_num = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_STATUS_NUM , + desc->hdr.info0); + status->uniform_hdr.cmd_status = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS , + desc->hdr.info0); + + status->u.unblock_cache.err_detected = +FIELD_GET (HAL_REO_UNBLOCK_CACHE_STATUS_INFO0_IS_ERR , + desc->info0); + status->u.unblock_cache.unblock_type = +FIELD_GET (HAL_REO_UNBLOCK_CACHE_STATUS_INFO0_TYPE , + desc->info0); + +if (!status->u.unblock_cache.err_detected && + status->u.unblock_cache.unblock_type == +HAL_REO_STATUS_UNBLOCK_BLOCKING_RESOURCE ) + hal->avail_blk_resource &= ~BIT (hal->current_blk_index); +} + +void ath11k_hal_reo_flush_timeout_list_status (struct ath11k_base *ab, +u32 *reo_desc, +struct hal_reo_status *status) +{ +struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; +struct hal_reo_flush_timeout_list_status *desc = + (struct hal_reo_flush_timeout_list_status *)tlv->value; + + status->uniform_hdr.cmd_num = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_STATUS_NUM , + desc->hdr.info0); + status->uniform_hdr.cmd_status = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS , + desc->hdr.info0); + + status->u.timeout_list.err_detected = +FIELD_GET (HAL_REO_FLUSH_TIMEOUT_STATUS_INFO0_IS_ERR , + desc->info0); + status->u.timeout_list.list_empty = +FIELD_GET (HAL_REO_FLUSH_TIMEOUT_STATUS_INFO0_LIST_EMPTY , + desc->info0); + + status->u.timeout_list.release_desc_cnt = +FIELD_GET (HAL_REO_FLUSH_TIMEOUT_STATUS_INFO1_REL_DESC_COUNT , + desc->info1); + status->u.timeout_list.fwd_buf_cnt = +FIELD_GET (HAL_REO_FLUSH_TIMEOUT_STATUS_INFO1_FWD_BUF_COUNT , + desc->info1); +} + +void ath11k_hal_reo_desc_thresh_reached_status (struct ath11k_base *ab, +u32 *reo_desc, +struct hal_reo_status *status) +{ +struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; +struct hal_reo_desc_thresh_reached_status *desc = + (struct hal_reo_desc_thresh_reached_status *)tlv->value; + + status->uniform_hdr.cmd_num = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_STATUS_NUM , + desc->hdr.info0); + status->uniform_hdr.cmd_status = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS , + desc->hdr.info0); + + status->u.desc_thresh_reached.threshold_idx = +FIELD_GET (HAL_REO_DESC_THRESH_STATUS_INFO0_THRESH_INDEX , + desc->info0); + + status->u.desc_thresh_reached.link_desc_counter0 = +FIELD_GET (HAL_REO_DESC_THRESH_STATUS_INFO1_LINK_DESC_COUNTER0 , + desc->info1); + + status->u.desc_thresh_reached.link_desc_counter1 = +FIELD_GET (HAL_REO_DESC_THRESH_STATUS_INFO2_LINK_DESC_COUNTER1 , + desc->info2); + + status->u.desc_thresh_reached.link_desc_counter2 = +FIELD_GET (HAL_REO_DESC_THRESH_STATUS_INFO3_LINK_DESC_COUNTER2 , + desc->info3); + + status->u.desc_thresh_reached.link_desc_counter_sum = +FIELD_GET (HAL_REO_DESC_THRESH_STATUS_INFO4_LINK_DESC_COUNTER_SUM , + desc->info4); +} + +void ath11k_hal_reo_update_rx_reo_queue_status (struct ath11k_base *ab, +u32 *reo_desc, +struct hal_reo_status *status) +{ +struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; +struct hal_reo_status_hdr *desc = + (struct hal_reo_status_hdr *)tlv->value; + + status->uniform_hdr.cmd_num = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_STATUS_NUM , + desc->info0); + status->uniform_hdr.cmd_status = +FIELD_GET (HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS , + desc->info0); +} + +u32 ath11k_hal_reo_qdesc_size (u32 ba_window_size,u8 tid) +{ +u32 num_ext_desc; + +if (ba_window_size <=1 ) { +if (tid !=HAL_DESC_REO_NON_QOS_TID ) + num_ext_desc =1 ; +else + num_ext_desc =0 ; + }else if (ba_window_size <=105 ) { + num_ext_desc =1 ; + }else if (ba_window_size <=210 ) { + num_ext_desc =2 ; + }else { + num_ext_desc =3 ; + } + +return sizeof (struct hal_rx_reo_queue ) + + (num_ext_desc *sizeof (struct hal_rx_reo_queue_ext )); +} + +void ath11k_hal_reo_qdesc_setup (void *vaddr,int tid,u32 ba_window_size, +u32 start_seq) +{ +struct hal_rx_reo_queue *qdesc = (struct hal_rx_reo_queue *)vaddr; +struct hal_rx_reo_queue_ext *ext_desc; + +memset (qdesc,0 ,sizeof (*qdesc)); + +ath11k_hal_reo_set_desc_hdr (&qdesc->desc_hdr,HAL_DESC_REO_OWNED , +HAL_DESC_REO_QUEUE_DESC , +REO_QUEUE_DESC_MAGIC_DEBUG_PATTERN_0 ); + + qdesc->rx_queue_num =FIELD_PREP (HAL_RX_REO_QUEUE_RX_QUEUE_NUMBER , tid); + + qdesc->info0 = +FIELD_PREP (HAL_RX_REO_QUEUE_INFO0_VLD ,1 ) | +FIELD_PREP (HAL_RX_REO_QUEUE_INFO0_ASSOC_LNK_DESC_COUNTER ,1 ) | +FIELD_PREP (HAL_RX_REO_QUEUE_INFO0_AC ,ath11k_tid_to_ac (tid)); + +if (ba_window_size <1 ) + ba_window_size =1 ; + +if (ba_window_size ==1 && tid !=HAL_DESC_REO_NON_QOS_TID ) + ba_window_size++; + +if (ba_window_size ==1 ) + qdesc->info0 |=FIELD_PREP (HAL_RX_REO_QUEUE_INFO0_RETRY ,1 ); + + qdesc->info0 |=FIELD_PREP (HAL_RX_REO_QUEUE_INFO0_BA_WINDOW_SIZE , + ba_window_size -1 ); + +/* TODO: Set Ignore ampdu flags based on BA window size and/or +* AMPDU capabilities +*/ + qdesc->info0 |=FIELD_PREP (HAL_RX_REO_QUEUE_INFO0_IGNORE_AMPDU_FLG ,1 ); + + qdesc->info1 |=FIELD_PREP (HAL_RX_REO_QUEUE_INFO1_SVLD ,0 ); + +if (start_seq <=0xfff ) + qdesc->info1 =FIELD_PREP (HAL_RX_REO_QUEUE_INFO1_SSN , + start_seq); + +if (tid ==HAL_DESC_REO_NON_QOS_TID ) +return ; + + ext_desc = qdesc->ext_desc; + +/* TODO: HW queue descriptors are currently allocated for max BA +* window size for all QOS TIDs so that same descriptor can be used +* later when ADDBA request is recevied. This should be changed to +* allocate HW queue descriptors based on BA window size being +* negotiated (0 for non BA cases), and reallocate when BA window +* size changes and also send WMI message to FW to change the REO +* queue descriptor in Rx peer entry as part of dp_rx_tid_update. +*/ +memset (ext_desc,0 ,3 *sizeof (*ext_desc)); +ath11k_hal_reo_set_desc_hdr (&ext_desc->desc_hdr,HAL_DESC_REO_OWNED , +HAL_DESC_REO_QUEUE_EXT_DESC , +REO_QUEUE_DESC_MAGIC_DEBUG_PATTERN_1 ); + ext_desc++; +ath11k_hal_reo_set_desc_hdr (&ext_desc->desc_hdr,HAL_DESC_REO_OWNED , +HAL_DESC_REO_QUEUE_EXT_DESC , +REO_QUEUE_DESC_MAGIC_DEBUG_PATTERN_2 ); + ext_desc++; +ath11k_hal_reo_set_desc_hdr (&ext_desc->desc_hdr,HAL_DESC_REO_OWNED , +HAL_DESC_REO_QUEUE_EXT_DESC , +REO_QUEUE_DESC_MAGIC_DEBUG_PATTERN_3 ); +} + +void ath11k_hal_reo_init_cmd_ring (struct ath11k_base *ab, +struct hal_srng *srng) +{ +struct hal_srng_params params; +struct hal_tlv_hdr *tlv; +struct hal_reo_get_queue_stats *desc; +int i, cmd_num =1 ; +int entry_size; +u8 *entry; + +memset (¶ms,0 ,sizeof (params)); + + entry_size =ath11k_hal_srng_get_entrysize (HAL_REO_CMD ); +ath11k_hal_srng_get_params (ab, srng, ¶ms); + entry = (u8 *)params.ring_base_vaddr; + +for (i =0 ; i < params.num_entries; i++) { + tlv = (struct hal_tlv_hdr *)entry; + desc = (struct hal_reo_get_queue_stats *)tlv->value; + desc->cmd.info0 = +FIELD_PREP (HAL_REO_CMD_HDR_INFO0_CMD_NUMBER , cmd_num++); + entry += entry_size; + } +} + +void ath11k_hal_reo_hw_setup (struct ath11k_base *ab) +{ +u32 reo_base =HAL_SEQ_WCSS_UMAC_REO_REG ; +u32 val; + + val =ath11k_ahb_read32 (ab, reo_base +HAL_REO1_GEN_ENABLE ); + + val &= ~HAL_REO1_GEN_ENABLE_FRAG_DST_RING ; + val |=FIELD_PREP (HAL_REO1_GEN_ENABLE_FRAG_DST_RING , +HAL_SRNG_RING_ID_REO2SW1 ) | +FIELD_PREP (HAL_REO1_GEN_ENABLE_AGING_LIST_ENABLE ,1 ) | +FIELD_PREP (HAL_REO1_GEN_ENABLE_AGING_FLUSH_ENABLE ,1 ); +ath11k_ahb_write32 (ab, reo_base +HAL_REO1_GEN_ENABLE , val); + +ath11k_ahb_write32 (ab, reo_base +HAL_REO1_AGING_THRESH_IX_0 , +HAL_DEFAULT_REO_TIMEOUT_USEC ); +ath11k_ahb_write32 (ab, reo_base +HAL_REO1_AGING_THRESH_IX_1 , +HAL_DEFAULT_REO_TIMEOUT_USEC ); +ath11k_ahb_write32 (ab, reo_base +HAL_REO1_AGING_THRESH_IX_2 , +HAL_DEFAULT_REO_TIMEOUT_USEC ); +ath11k_ahb_write32 (ab, reo_base +HAL_REO1_AGING_THRESH_IX_3 , +HAL_DEFAULT_REO_TIMEOUT_USEC ); +} + +static enum hal_rx_mon_status +ath11k_hal_rx_parse_mon_status_tlv (struct ath11k_base *ab, +struct hal_rx_mon_ppdu_info *ppdu_info, +u32 tlv_tag,u8 *tlv_data) +{ +u32 info0, info1; + +switch (tlv_tag) { +case HAL_RX_PPDU_START : { +struct hal_rx_ppdu_start *ppdu_start = + (struct hal_rx_ppdu_start *)tlv_data; + + ppdu_info->ppdu_id = +FIELD_GET (HAL_RX_PPDU_START_INFO0_PPDU_ID , +__le32_to_cpu (ppdu_start->info0)); + ppdu_info->chan_num =__le32_to_cpu (ppdu_start->chan_num); + ppdu_info->ppdu_ts =__le32_to_cpu (ppdu_start->ppdu_start_ts); +break ; + } +case HAL_RX_PPDU_END_USER_STATS : { +struct hal_rx_ppdu_end_user_stats *eu_stats = + (struct hal_rx_ppdu_end_user_stats *)tlv_data; + + info0 =__le32_to_cpu (eu_stats->info0); + info1 =__le32_to_cpu (eu_stats->info1); + + ppdu_info->tid = +ffs (FIELD_GET (HAL_RX_PPDU_END_USER_STATS_INFO6_TID_BITMAP , +__le32_to_cpu (eu_stats->info6))) -1 ; + ppdu_info->tcp_msdu_count = +FIELD_GET (HAL_RX_PPDU_END_USER_STATS_INFO4_TCP_MSDU_CNT , +__le32_to_cpu (eu_stats->info4)); + ppdu_info->udp_msdu_count = +FIELD_GET (HAL_RX_PPDU_END_USER_STATS_INFO4_UDP_MSDU_CNT , +__le32_to_cpu (eu_stats->info4)); + ppdu_info->other_msdu_count = +FIELD_GET (HAL_RX_PPDU_END_USER_STATS_INFO5_OTHER_MSDU_CNT , +__le32_to_cpu (eu_stats->info5)); + ppdu_info->tcp_ack_msdu_count = +FIELD_GET (HAL_RX_PPDU_END_USER_STATS_INFO5_TCP_ACK_MSDU_CNT , +__le32_to_cpu (eu_stats->info5)); + ppdu_info->preamble_type = +FIELD_GET (HAL_RX_PPDU_END_USER_STATS_INFO1_PKT_TYPE , info1); + ppdu_info->num_mpdu_fcs_ok = +FIELD_GET (HAL_RX_PPDU_END_USER_STATS_INFO1_MPDU_CNT_FCS_OK , + info1); + ppdu_info->num_mpdu_fcs_err = +FIELD_GET (HAL_RX_PPDU_END_USER_STATS_INFO0_MPDU_CNT_FCS_ERR , + info0); +break ; + } +case HAL_PHYRX_HT_SIG : { +struct hal_rx_ht_sig_info *ht_sig = + (struct hal_rx_ht_sig_info *)tlv_data; + + info0 =__le32_to_cpu (ht_sig->info0); + info1 =__le32_to_cpu (ht_sig->info1); + + ppdu_info->mcs =FIELD_GET (HAL_RX_HT_SIG_INFO_INFO0_MCS , info0); + ppdu_info->bw =FIELD_GET (HAL_RX_HT_SIG_INFO_INFO0_BW , info0); + ppdu_info->is_stbc =FIELD_GET (HAL_RX_HT_SIG_INFO_INFO1_STBC , + info1); + ppdu_info->ldpc =FIELD_GET (HAL_RX_HT_SIG_INFO_INFO1_FEC_CODING , info1); + ppdu_info->gi = info1 &HAL_RX_HT_SIG_INFO_INFO1_GI ; + +switch (ppdu_info->mcs) { + case 0 ... 7: + ppdu_info->nss =1 ; +break ; + case 8 ... 15: + ppdu_info->nss =2 ; +break ; + case 16 ... 23: + ppdu_info->nss =3 ; +break ; + case 24 ... 31: + ppdu_info->nss =4 ; +break ; + } + +if (ppdu_info->nss >1 ) + ppdu_info->mcs = ppdu_info->mcs %8 ; + + ppdu_info->reception_type =HAL_RX_RECEPTION_TYPE_SU ; +break ; + } +case HAL_PHYRX_L_SIG_B : { +struct hal_rx_lsig_b_info *lsigb = + (struct hal_rx_lsig_b_info *)tlv_data; + + ppdu_info->rate =FIELD_GET (HAL_RX_LSIG_B_INFO_INFO0_RATE , +__le32_to_cpu (lsigb->info0)); + ppdu_info->reception_type =HAL_RX_RECEPTION_TYPE_SU ; +break ; + } +case HAL_PHYRX_L_SIG_A : { +struct hal_rx_lsig_a_info *lsiga = + (struct hal_rx_lsig_a_info *)tlv_data; + + ppdu_info->rate =FIELD_GET (HAL_RX_LSIG_A_INFO_INFO0_RATE , +__le32_to_cpu (lsiga->info0)); + ppdu_info->reception_type =HAL_RX_RECEPTION_TYPE_SU ; +break ; + } +case HAL_PHYRX_VHT_SIG_A : { +struct hal_rx_vht_sig_a_info *vht_sig = + (struct hal_rx_vht_sig_a_info *)tlv_data; +u32 nsts; +u32 group_id; + + info0 =__le32_to_cpu (vht_sig->info0); + info1 =__le32_to_cpu (vht_sig->info1); + + ppdu_info->ldpc =FIELD_GET (HAL_RX_VHT_SIG_A_INFO_INFO1_SU_MU_CODING , + info0); + ppdu_info->mcs =FIELD_GET (HAL_RX_VHT_SIG_A_INFO_INFO1_MCS , + info1); + ppdu_info->gi = +FIELD_GET (HAL_RX_VHT_SIG_A_INFO_INFO1_GI_SETTING , + info1); + ppdu_info->is_stbc = info0 &HAL_RX_VHT_SIG_A_INFO_INFO0_STBC ; + nsts =FIELD_GET (HAL_RX_VHT_SIG_A_INFO_INFO0_NSTS , info0); +if (ppdu_info->is_stbc && nsts >0 ) + nsts = ((nsts +1 ) >>1 ) -1 ; + + ppdu_info->nss = (nsts &VHT_SIG_SU_NSS_MASK ) +1 ; + ppdu_info->bw =FIELD_GET (HAL_RX_VHT_SIG_A_INFO_INFO0_BW , + info0); + ppdu_info->beamformed = info1 & +HAL_RX_VHT_SIG_A_INFO_INFO1_BEAMFORMED ; + group_id =FIELD_GET (HAL_RX_VHT_SIG_A_INFO_INFO0_GROUP_ID , + info0); +if (group_id ==0 || group_id ==63 ) + ppdu_info->reception_type =HAL_RX_RECEPTION_TYPE_SU ; +else + ppdu_info->reception_type = +HAL_RX_RECEPTION_TYPE_MU_MIMO ; +break ; + } +case HAL_PHYRX_HE_SIG_A_SU : { +struct hal_rx_he_sig_a_su_info *he_sig_a = + (struct hal_rx_he_sig_a_su_info *)tlv_data; +u32 nsts, cp_ltf, dcm; + + info0 =__le32_to_cpu (he_sig_a->info0); + info1 =__le32_to_cpu (he_sig_a->info1); + + ppdu_info->mcs = +FIELD_GET (HAL_RX_HE_SIG_A_SU_INFO_INFO0_TRANSMIT_MCS , + info0); + ppdu_info->bw = +FIELD_GET (HAL_RX_HE_SIG_A_SU_INFO_INFO0_TRANSMIT_BW , + info0); + ppdu_info->ldpc =FIELD_GET (HAL_RX_HE_SIG_A_SU_INFO_INFO1_CODING , info0); + ppdu_info->is_stbc = info1 & +HAL_RX_HE_SIG_A_SU_INFO_INFO1_STBC ; + ppdu_info->beamformed = info1 & +HAL_RX_HE_SIG_A_SU_INFO_INFO1_TXBF ; + dcm = info0 &HAL_RX_HE_SIG_A_SU_INFO_INFO0_DCM ; + cp_ltf =FIELD_GET (HAL_RX_HE_SIG_A_SU_INFO_INFO0_CP_LTF_SIZE , + info0); + nsts =FIELD_GET (HAL_RX_HE_SIG_A_SU_INFO_INFO0_NSTS , info0); + +switch (cp_ltf) { +case 0 : +case 1 : + ppdu_info->gi =HAL_RX_GI_0_8_US ; +break ; +case 2 : + ppdu_info->gi =HAL_RX_GI_1_6_US ; +break ; +case 3 : +if (dcm && ppdu_info->is_stbc) + ppdu_info->gi =HAL_RX_GI_0_8_US ; +else + ppdu_info->gi =HAL_RX_GI_3_2_US ; +break ; + } + + ppdu_info->nss = nsts +1 ; + ppdu_info->reception_type =HAL_RX_RECEPTION_TYPE_SU ; +break ; + } +case HAL_PHYRX_HE_SIG_A_MU_DL : { +struct hal_rx_he_sig_a_mu_dl_info *he_sig_a_mu_dl = + (struct hal_rx_he_sig_a_mu_dl_info *)tlv_data; + +u32 cp_ltf; + + info0 =__le32_to_cpu (he_sig_a_mu_dl->info0); + info1 =__le32_to_cpu (he_sig_a_mu_dl->info1); + + ppdu_info->bw = +FIELD_GET (HAL_RX_HE_SIG_A_MU_DL_INFO_INFO0_TRANSMIT_BW , + info0); + cp_ltf =FIELD_GET (HAL_RX_HE_SIG_A_MU_DL_INFO_INFO0_CP_LTF_SIZE , + info0); + +switch (cp_ltf) { +case 0 : +case 1 : + ppdu_info->gi =HAL_RX_GI_0_8_US ; +break ; +case 2 : + ppdu_info->gi =HAL_RX_GI_1_6_US ; +break ; +case 3 : + ppdu_info->gi =HAL_RX_GI_3_2_US ; +break ; + } + + ppdu_info->is_stbc = info1 & +HAL_RX_HE_SIG_A_MU_DL_INFO_INFO1_STBC ; + ppdu_info->reception_type =HAL_RX_RECEPTION_TYPE_MU_MIMO ; +break ; + } +case HAL_PHYRX_HE_SIG_B1_MU : { +/* TODO: Check if resource unit(RU) allocation stats +* are required +*/ + ppdu_info->reception_type =HAL_RX_RECEPTION_TYPE_MU_MIMO ; +break ; + } +case HAL_PHYRX_HE_SIG_B2_MU : { +struct hal_rx_he_sig_b2_mu_info *he_sig_b2_mu = + (struct hal_rx_he_sig_b2_mu_info *)tlv_data; + + info0 =__le32_to_cpu (he_sig_b2_mu->info0); + + ppdu_info->mcs = +FIELD_GET (HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_MCS , + info0); + ppdu_info->nss = +FIELD_GET (HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_NSTS , + info0) +1 ; + ppdu_info->ldpc =FIELD_GET (HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_CODING , + info0); +break ; + } +case HAL_PHYRX_HE_SIG_B2_OFDMA : { +struct hal_rx_he_sig_b2_ofdma_info *he_sig_b2_ofdma = + (struct hal_rx_he_sig_b2_ofdma_info *)tlv_data; + + info0 =__le32_to_cpu (he_sig_b2_ofdma->info0); + + ppdu_info->mcs = +FIELD_GET (HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_MCS , + info0); + ppdu_info->nss = +FIELD_GET (HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_NSTS , + info0) +1 ; + ppdu_info->beamformed = + info0 & +HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_TXBF ; + ppdu_info->ldpc =FIELD_GET (HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_CODING , + info0); + ppdu_info->reception_type =HAL_RX_RECEPTION_TYPE_MU_OFDMA ; +break ; + } +case HAL_PHYRX_RSSI_LEGACY : { +struct hal_rx_phyrx_rssi_legacy_info *rssi = + (struct hal_rx_phyrx_rssi_legacy_info *)tlv_data; + +/* TODO: Please note that the combined rssi will not be accurate +* in MU case. Rssi in MU needs to be retrieved from +* PHYRX_OTHER_RECEIVE_INFO TLV. +*/ + ppdu_info->rssi_comb = +FIELD_GET (HAL_RX_PHYRX_RSSI_LEGACY_INFO_INFO1_RSSI_COMB , +__le32_to_cpu (rssi->info0)); +break ; + } +case HAL_RX_MPDU_START : { +struct hal_rx_mpdu_info *mpdu_info = + (struct hal_rx_mpdu_info *)tlv_data; +u16 peer_id; + + peer_id =FIELD_GET (HAL_RX_MPDU_INFO_INFO0_PEERID , +__le32_to_cpu (mpdu_info->info0)); +if (peer_id) + ppdu_info->peer_id = peer_id; +break ; + } +case HAL_RXPCU_PPDU_END_INFO : { +struct hal_rx_ppdu_end_duration *ppdu_rx_duration = + (struct hal_rx_ppdu_end_duration *)tlv_data; + ppdu_info->rx_duration = +FIELD_GET (HAL_RX_PPDU_END_DURATION , +__le32_to_cpu (ppdu_rx_duration->info0)); +break ; + } +case HAL_DUMMY : +return HAL_RX_MON_STATUS_BUF_DONE ; +case HAL_RX_PPDU_END_STATUS_DONE : +case 0 : +return HAL_RX_MON_STATUS_PPDU_DONE ; +default : +break ; + } + +return HAL_RX_MON_STATUS_PPDU_NOT_DONE ; +} + +enum hal_rx_mon_status +ath11k_hal_rx_parse_mon_status (struct ath11k_base *ab, +struct hal_rx_mon_ppdu_info *ppdu_info, +struct sk_buff *skb) +{ +struct hal_tlv_hdr *tlv; +enum hal_rx_mon_status hal_status =HAL_RX_MON_STATUS_BUF_DONE ; +u16 tlv_tag; +u16 tlv_len; +u8 *ptr = skb->data; + +do { + tlv = (struct hal_tlv_hdr *)ptr; + tlv_tag =FIELD_GET (HAL_TLV_HDR_TAG , tlv->tl); + tlv_len =FIELD_GET (HAL_TLV_HDR_LEN , tlv->tl); + ptr +=sizeof (*tlv); + +/* The actual length of PPDU_END is the combined length of many PHY +* TLVs that follow. Skip the TLV header and +* rx_rxpcu_classification_overview that follows the header to get to +* next TLV. +*/ +if (tlv_tag ==HAL_RX_PPDU_END ) + tlv_len =sizeof (struct hal_rx_rxpcu_classification_overview ); + + hal_status =ath11k_hal_rx_parse_mon_status_tlv (ab, ppdu_info, + tlv_tag, ptr); + ptr += tlv_len; + ptr =PTR_ALIGN (ptr,HAL_TLV_ALIGN ); + +if ((ptr - skb->data) >=DP_RX_BUFFER_SIZE ) +break ; + }while (hal_status ==HAL_RX_MON_STATUS_PPDU_NOT_DONE ); + +return hal_status; +} + +void ath11k_hal_rx_reo_ent_buf_paddr_get (void *rx_desc,dma_addr_t *paddr, +u32 *sw_cookie,void **pp_buf_addr, +u32 *msdu_cnt) +{ +struct hal_reo_entrance_ring *reo_ent_ring = + (struct hal_reo_entrance_ring *)rx_desc; +struct ath11k_buffer_addr *buf_addr_info; +struct rx_mpdu_desc *rx_mpdu_desc_info_details; + + rx_mpdu_desc_info_details = + (struct rx_mpdu_desc *)&reo_ent_ring->rx_mpdu_info; + + *msdu_cnt =FIELD_GET (RX_MPDU_DESC_INFO0_MSDU_COUNT , + rx_mpdu_desc_info_details->info0); + + buf_addr_info = (struct ath11k_buffer_addr *)&reo_ent_ring->buf_addr_info; + + *paddr = (((u64 )FIELD_GET (BUFFER_ADDR_INFO1_ADDR , + buf_addr_info->info1)) <<32 ) | +FIELD_GET (BUFFER_ADDR_INFO0_ADDR , + buf_addr_info->info0); + + *sw_cookie =FIELD_GET (BUFFER_ADDR_INFO1_SW_COOKIE , + buf_addr_info->info1); + + *pp_buf_addr = (void *)buf_addr_info; +}
PATCH v3 25/49 ath11k: add hal_rx.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/hal_rx.h | 352 +++++++++++++++++++++++++++++++ 1 file changed, 352 insertions(+)
drivers/net/wireless/ath/ath11k/hal_rx.h new file +352 -0
@@ -0,0 +1,352 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#ifndef ATH11K_HAL_RX_H +#define ATH11K_HAL_RX_H + +struct hal_rx_mpdu_meta { +u32 peer_meta; +u16 msdu_cnt; +u16 seq_num; +bool frag; +bool retry; +bool ampdu; +bool raw; +}; + +struct hal_rx_msdu_meta { +u32 cookie; +u32 msdu_len; +bool first; +bool last; +bool continuation; +}; + +struct hal_rx_meta_info { +enum hal_reo_dest_ring_push_reason push_reason; +struct hal_rx_mpdu_meta mpdu_meta; +struct hal_rx_msdu_meta msdu_meta; +}; + +struct hal_rx_wbm_rel_info { +u32 cookie; +enum hal_wbm_rel_src_module err_rel_src; +enum hal_reo_dest_ring_push_reason push_reason; +u32 err_code; +bool first_msdu; +bool last_msdu; +}; + +#define HAL_INVALID_PEERID 0xffff +#define VHT_SIG_SU_NSS_MASK 0x7 + +#define HAL_RX_MAX_MCS 12 +#define HAL_RX_MAX_NSS 8 + +struct hal_rx_mon_status_tlv_hdr { +u32 hdr; +u8 value[0 ]; +}; + +enum hal_rx_su_mu_coding { +HAL_RX_SU_MU_CODING_BCC , +HAL_RX_SU_MU_CODING_LDPC , +HAL_RX_SU_MU_CODING_MAX , +}; + +enum hal_rx_gi { +HAL_RX_GI_0_8_US , +HAL_RX_GI_0_4_US , +HAL_RX_GI_1_6_US , +HAL_RX_GI_3_2_US , +HAL_RX_GI_MAX , +}; + +enum hal_rx_bw { +HAL_RX_BW_20MHZ , +HAL_RX_BW_40MHZ , +HAL_RX_BW_80MHZ , +HAL_RX_BW_160MHZ , +HAL_RX_BW_MAX , +}; + +enum hal_rx_preamble { +HAL_RX_PREAMBLE_11A , +HAL_RX_PREAMBLE_11B , +HAL_RX_PREAMBLE_11N , +HAL_RX_PREAMBLE_11AC , +HAL_RX_PREAMBLE_11AX , +HAL_RX_PREAMBLE_MAX , +}; + +enum hal_rx_reception_type { +HAL_RX_RECEPTION_TYPE_SU , +HAL_RX_RECEPTION_TYPE_MU_MIMO , +HAL_RX_RECEPTION_TYPE_MU_OFDMA , +HAL_RX_RECEPTION_TYPE_MU_OFDMA_MIMO , +HAL_RX_RECEPTION_TYPE_MAX , +}; + +#define HAL_TLV_STATUS_PPDU_NOT_DONE 0 +#define HAL_TLV_STATUS_PPDU_DONE 1 +#define HAL_TLV_STATUS_BUF_DONE 2 +#define HAL_TLV_STATUS_PPDU_NON_STD_DONE 3 +#define HAL_RX_FCS_LEN 4 + +enum hal_rx_mon_status { +HAL_RX_MON_STATUS_PPDU_NOT_DONE , +HAL_RX_MON_STATUS_PPDU_DONE , +HAL_RX_MON_STATUS_BUF_DONE , +}; + +struct hal_rx_mon_ppdu_info { +u32 ppdu_id; +u32 ppdu_ts; +u32 num_mpdu_fcs_ok; +u32 num_mpdu_fcs_err; +u32 preamble_type; +u16 chan_num; +u16 tcp_msdu_count; +u16 tcp_ack_msdu_count; +u16 udp_msdu_count; +u16 other_msdu_count; +u16 peer_id; +u8 rate; +u8 mcs; +u8 nss; +u8 bw; +u8 is_stbc; +u8 gi; +u8 ldpc; +u8 beamformed; +u8 rssi_comb; +u8 tid; +u8 reception_type; +u64 rx_duration; +}; + +#define HAL_RX_PPDU_START_INFO0_PPDU_ID GENMASK(15, 0) + +struct hal_rx_ppdu_start { +__le32 info0; +__le32 chan_num; +__le32 ppdu_start_ts; +} __packed; + +#define HAL_RX_PPDU_END_USER_STATS_INFO0_MPDU_CNT_FCS_ERR GENMASK(25, 16) + +#define HAL_RX_PPDU_END_USER_STATS_INFO1_MPDU_CNT_FCS_OK GENMASK(8, 0) +#define HAL_RX_PPDU_END_USER_STATS_INFO1_FC_VALID BIT(9) +#define HAL_RX_PPDU_END_USER_STATS_INFO1_QOS_CTRL_VALID BIT(10) +#define HAL_RX_PPDU_END_USER_STATS_INFO1_HT_CTRL_VALID BIT(11) +#define HAL_RX_PPDU_END_USER_STATS_INFO1_PKT_TYPE GENMASK(23, 20) + +#define HAL_RX_PPDU_END_USER_STATS_INFO2_AST_INDEX GENMASK(15, 0) +#define HAL_RX_PPDU_END_USER_STATS_INFO2_FRAME_CTRL GENMASK(31, 16) + +#define HAL_RX_PPDU_END_USER_STATS_INFO3_QOS_CTRL GENMASK(31, 16) + +#define HAL_RX_PPDU_END_USER_STATS_INFO4_UDP_MSDU_CNT GENMASK(15, 0) +#define HAL_RX_PPDU_END_USER_STATS_INFO4_TCP_MSDU_CNT GENMASK(31, 16) + +#define HAL_RX_PPDU_END_USER_STATS_INFO5_OTHER_MSDU_CNT GENMASK(15, 0) +#define HAL_RX_PPDU_END_USER_STATS_INFO5_TCP_ACK_MSDU_CNT GENMASK(31, 16) + +#define HAL_RX_PPDU_END_USER_STATS_INFO6_TID_BITMAP GENMASK(15, 0) +#define HAL_RX_PPDU_END_USER_STATS_INFO6_TID_EOSP_BITMAP GENMASK(31, 16) + +struct hal_rx_ppdu_end_user_stats { +__le32 rsvd0[2 ]; +__le32 info0; +__le32 info1; +__le32 info2; +__le32 info3; +__le32 ht_ctrl; +__le32 rsvd1[2 ]; +__le32 info4; +__le32 info5; +__le32 info6; +__le32 rsvd2[11 ]; +} __packed; + +#define HAL_RX_HT_SIG_INFO_INFO0_MCS GENMASK(6, 0) +#define HAL_RX_HT_SIG_INFO_INFO0_BW BIT(7) + +#define HAL_RX_HT_SIG_INFO_INFO1_STBC GENMASK(5, 4) +#define HAL_RX_HT_SIG_INFO_INFO1_FEC_CODING BIT(6) +#define HAL_RX_HT_SIG_INFO_INFO1_GI BIT(7) + +struct hal_rx_ht_sig_info { +__le32 info0; +__le32 info1; +} __packed; + +#define HAL_RX_LSIG_B_INFO_INFO0_RATE GENMASK(3, 0) +#define HAL_RX_LSIG_B_INFO_INFO0_LEN GENMASK(15, 4) + +struct hal_rx_lsig_b_info { +__le32 info0; +} __packed; + +#define HAL_RX_LSIG_A_INFO_INFO0_RATE GENMASK(3, 0) +#define HAL_RX_LSIG_A_INFO_INFO0_LEN GENMASK(16, 5) +#define HAL_RX_LSIG_A_INFO_INFO0_PKT_TYPE GENMASK(27, 24) + +struct hal_rx_lsig_a_info { +__le32 info0; +} __packed; + +#define HAL_RX_VHT_SIG_A_INFO_INFO0_BW GENMASK(1, 0) +#define HAL_RX_VHT_SIG_A_INFO_INFO0_STBC BIT(3) +#define HAL_RX_VHT_SIG_A_INFO_INFO0_GROUP_ID GENMASK(9, 4) +#define HAL_RX_VHT_SIG_A_INFO_INFO0_NSTS GENMASK(21, 10) + +#define HAL_RX_VHT_SIG_A_INFO_INFO1_GI_SETTING GENMASK(1, 0) +#define HAL_RX_VHT_SIG_A_INFO_INFO1_SU_MU_CODING BIT(2) +#define HAL_RX_VHT_SIG_A_INFO_INFO1_MCS GENMASK(7, 4) +#define HAL_RX_VHT_SIG_A_INFO_INFO1_BEAMFORMED BIT(8) + +struct hal_rx_vht_sig_a_info { +__le32 info0; +__le32 info1; +} __packed; + +#define HAL_RX_HE_SIG_A_SU_INFO_INFO0_TRANSMIT_MCS GENMASK(6, 3) +#define HAL_RX_HE_SIG_A_SU_INFO_INFO0_DCM BIT(7) +#define HAL_RX_HE_SIG_A_SU_INFO_INFO0_TRANSMIT_BW GENMASK(20, 19) +#define HAL_RX_HE_SIG_A_SU_INFO_INFO0_CP_LTF_SIZE GENMASK(22, 21) +#define HAL_RX_HE_SIG_A_SU_INFO_INFO0_NSTS GENMASK(25, 23) + +#define HAL_RX_HE_SIG_A_SU_INFO_INFO1_CODING BIT(7) +#define HAL_RX_HE_SIG_A_SU_INFO_INFO1_STBC BIT(9) +#define HAL_RX_HE_SIG_A_SU_INFO_INFO1_TXBF BIT(10) + +struct hal_rx_he_sig_a_su_info { +__le32 info0; +__le32 info1; +} __packed; + +#define HAL_RX_HE_SIG_A_MU_DL_INFO_INFO0_TRANSMIT_BW GENMASK(17, 15) +#define HAL_RX_HE_SIG_A_MU_DL_INFO_INFO0_CP_LTF_SIZE GENMASK(24, 23) + +#define HAL_RX_HE_SIG_A_MU_DL_INFO_INFO1_STBC BIT(12) + +struct hal_rx_he_sig_a_mu_dl_info { +__le32 info0; +__le32 info1; +} __packed; + +#define HAL_RX_HE_SIG_B1_MU_INFO_INFO0_RU_ALLOCATION GENMASK(7, 0) + +struct hal_rx_he_sig_b1_mu_info { +__le32 info0; +} __packed; + +#define HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_MCS GENMASK(18, 15) +#define HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_CODING BIT(20) +#define HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_NSTS GENMASK(31, 29) + +struct hal_rx_he_sig_b2_mu_info { +__le32 info0; +} __packed; + +#define HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_NSTS GENMASK(13, 11) +#define HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_TXBF BIT(19) +#define HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_MCS GENMASK(18, 15) +#define HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_DCM BIT(19) +#define HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_CODING BIT(20) + +struct hal_rx_he_sig_b2_ofdma_info { +__le32 info0; +} __packed; + +#define HAL_RX_PHYRX_RSSI_LEGACY_INFO_INFO1_RSSI_COMB GENMASK(15, 8) + +struct hal_rx_phyrx_rssi_legacy_info { +__le32 rsvd[35 ]; +__le32 info0; +} __packed; + +#define HAL_RX_MPDU_INFO_INFO0_PEERID GENMASK(31, 16) +struct hal_rx_mpdu_info { +__le32 rsvd0; +__le32 info0; +__le32 rsvd1[21 ]; +} __packed; + +#define HAL_RX_PPDU_END_DURATION GENMASK(23, 0) +struct hal_rx_ppdu_end_duration { +__le32 rsvd0[9 ]; +__le32 info0; +__le32 rsvd1[4 ]; +} __packed; + +struct hal_rx_rxpcu_classification_overview { +u32 rsvd0; +} __packed; + +struct hal_rx_msdu_desc_info { +u32 msdu_flags; +u16 msdu_len;/* 14 bits for length */ +}; + +#define HAL_RX_NUM_MSDU_DESC 6 +struct hal_rx_msdu_list { +struct hal_rx_msdu_desc_info msdu_info[HAL_RX_NUM_MSDU_DESC ]; +u32 sw_cookie[HAL_RX_NUM_MSDU_DESC ]; +u8 rbm[HAL_RX_NUM_MSDU_DESC ]; +}; + +void ath11k_hal_reo_status_queue_stats (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status); +void ath11k_hal_reo_flush_queue_status (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status); +void ath11k_hal_reo_flush_cache_status (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status); +void ath11k_hal_reo_flush_cache_status (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status); +void ath11k_hal_reo_unblk_cache_status (struct ath11k_base *ab,u32 *reo_desc, +struct hal_reo_status *status); +void ath11k_hal_reo_flush_timeout_list_status (struct ath11k_base *ab, +u32 *reo_desc, +struct hal_reo_status *status); +void ath11k_hal_reo_desc_thresh_reached_status (struct ath11k_base *ab, +u32 *reo_desc, +struct hal_reo_status *status); +void ath11k_hal_reo_update_rx_reo_queue_status (struct ath11k_base *ab, +u32 *reo_desc, +struct hal_reo_status *status); +int ath11k_hal_reo_process_status (u8 *reo_desc,u8 *status); +void ath11k_hal_rx_msdu_link_info_get (void *link_desc,u32 *num_msdus, +struct hal_rx_msdu_meta *meta, +enum hal_rx_buf_return_buf_manager *rbm); +void ath11k_hal_rx_msdu_link_desc_set (struct ath11k_base *ab,void *desc, +void *link_desc, +enum hal_wbm_rel_bm_act action); +void ath11k_hal_rx_buf_addr_info_set (void *desc,dma_addr_t paddr, +u32 cookie,u8 manager); +void ath11k_hal_rx_buf_addr_info_get (void *desc,dma_addr_t *paddr, +u32 *cookie,u8 *rbm); +int ath11k_hal_desc_reo_parse_err (struct ath11k_base *ab,u32 *rx_desc, +dma_addr_t *paddr,u32 *desc_bank); +void ath11k_hal_rx_parse_dst_ring_desc (struct ath11k_base *ab,u32 *rx_desc, +struct hal_rx_meta_info *meta_info); +int ath11k_hal_wbm_desc_parse_err (struct ath11k_base *ab,void *desc, +struct hal_rx_wbm_rel_info *rel_info); +void ath11k_hal_rx_reo_ent_paddr_get (struct ath11k_base *ab,void *desc, +dma_addr_t *paddr,u32 *desc_bank); +void ath11k_hal_rx_reo_ent_buf_paddr_get (void *rx_desc, +dma_addr_t *paddr,u32 *sw_cookie, +void **pp_buf_addr_info, +u32 *msdu_cnt); +enum hal_rx_mon_status +ath11k_hal_rx_parse_mon_status (struct ath11k_base *ab, +struct hal_rx_mon_ppdu_info *ppdu_info, +struct sk_buff *skb); +#define REO_QUEUE_DESC_MAGIC_DEBUG_PATTERN_0 0xDDBEEF +#define REO_QUEUE_DESC_MAGIC_DEBUG_PATTERN_1 0xADBEEF +#define REO_QUEUE_DESC_MAGIC_DEBUG_PATTERN_2 0xBDBEEF +#define REO_QUEUE_DESC_MAGIC_DEBUG_PATTERN_3 0xCDBEEF +#endif
PATCH v3 26/49 ath11k: add hal_tx.c
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/hal_tx.c | 226 +++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+)
drivers/net/wireless/ath/ath11k/hal_tx.c new file +226 -0
@@ -0,0 +1,226 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#include "ahb.h" +#include "hal.h" +#include "hal_tx.h" + +#define DSCP_TID_MAP_TBL_ENTRY_SIZE 64 + +/* dscp_tid_map - Default DSCP-TID mapping +* +* DSCP TID +* 000000 0 +* 001000 1 +* 010000 2 +* 011000 3 +* 100000 4 +* 101000 5 +* 110000 6 +* 111000 7 +*/ +static const u8 dscp_tid_map[DSCP_TID_MAP_TBL_ENTRY_SIZE ] = { +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , +1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 , +2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 , +3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 , +4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 , +5 ,5 ,5 ,5 ,5 ,5 ,5 ,5 , +6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 , +7 ,7 ,7 ,7 ,7 ,7 ,7 ,7 , +}; + +void ath11k_hal_tx_cmd_desc_setup (struct ath11k_base *ab,void *cmd, +struct hal_tx_info *ti) +{ +struct hal_tcl_data_cmd *tcl_cmd = (struct hal_tcl_data_cmd *)cmd; + + tcl_cmd->buf_addr_info.info0 = +FIELD_PREP (BUFFER_ADDR_INFO0_ADDR , ti->paddr); + tcl_cmd->buf_addr_info.info1 = +FIELD_PREP (BUFFER_ADDR_INFO1_ADDR , + ((uint64_t )ti->paddr >>HAL_ADDR_MSB_REG_SHIFT )); + tcl_cmd->buf_addr_info.info1 |= +FIELD_PREP (BUFFER_ADDR_INFO1_RET_BUF_MGR , + (ti->ring_id +HAL_RX_BUF_RBM_SW0_BM )) | +FIELD_PREP (BUFFER_ADDR_INFO1_SW_COOKIE , ti->desc_id); + + tcl_cmd->info0 = +FIELD_PREP (HAL_TCL_DATA_CMD_INFO0_DESC_TYPE , ti->type) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO0_ENCAP_TYPE , ti->encap_type) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO0_ENCRYPT_TYPE , + ti->encrypt_type) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO0_ADDRX_EN , + ti->addr_search_flags) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO0_ADDRY_EN , + ti->addr_search_flags) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO0_CMD_NUM , + ti->meta_data_flags); + + tcl_cmd->info1 = ti->flags0 | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO1_DATA_LEN , ti->data_len) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO1_PKT_OFFSET , ti->pkt_offset); + + tcl_cmd->info2 = ti->flags1 | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO2_TID , ti->tid) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO2_LMAC_ID , ti->lmac_id); + + tcl_cmd->info3 =FIELD_PREP (HAL_TCL_DATA_CMD_INFO3_DSCP_TID_TABLE_IDX , + ti->dscp_tid_tbl_idx) | +FIELD_PREP (HAL_TCL_DATA_CMD_INFO3_SEARCH_INDEX , + ti->bss_ast_hash); +} + +/* Commit the descriptor to hardware */ +void ath11k_hal_tx_desc_sync (void *tx_desc_cached,void *hw_desc) +{ +memcpy (hw_desc +sizeof (struct hal_tlv_hdr ), tx_desc_cached, +sizeof (struct hal_tcl_data_cmd )); +} + +/* Get the descriptor status from hardware */ +void ath11k_hal_tx_status_desc_sync (void *hw_desc,void *local_desc) +{ +memcpy (local_desc, hw_desc,HAL_TX_STATUS_DESC_LEN ); +} + +void ath11k_hal_tx_status_parse (struct ath11k_base *ab, +struct hal_wbm_release_ring *desc, +struct hal_tx_status *ts) +{ + ts->buf_rel_source = +FIELD_GET (HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE , desc->info0); +if (ts->buf_rel_source !=HAL_WBM_REL_SRC_MODULE_FW && + ts->buf_rel_source !=HAL_WBM_REL_SRC_MODULE_TQM ) +return ; + + ts->desc_id =FIELD_GET (BUFFER_ADDR_INFO1_SW_COOKIE , + desc->buf_addr_info.info1); + +if (ts->buf_rel_source ==HAL_WBM_REL_SRC_MODULE_FW ) +return ; + + ts->status =FIELD_GET (HAL_WBM_RELEASE_INFO0_TQM_RELEASE_REASON , + desc->info0); + ts->ppdu_id =FIELD_GET (HAL_WBM_RELEASE_INFO1_TQM_STATUS_NUMBER , + desc->info1); + ts->try_cnt =FIELD_GET (HAL_WBM_RELEASE_INFO1_TRANSMIT_COUNT , + desc->info1); + + ts->ack_rssi =FIELD_GET (HAL_WBM_RELEASE_INFO2_ACK_FRAME_RSSI , + desc->info2); +if (desc->info2 &HAL_WBM_RELEASE_INFO2_FIRST_MSDU ) + ts->flags |=HAL_TX_STATUS_FLAGS_FIRST_MSDU ; + +if (desc->info2 &HAL_WBM_RELEASE_INFO2_LAST_MSDU ) + ts->flags |=HAL_TX_STATUS_FLAGS_LAST_MSDU ; + +if (desc->info2 &HAL_WBM_RELEASE_INFO2_MSDU_IN_AMSDU ) + ts->flags |=HAL_TX_STATUS_FLAGS_MSDU_IN_AMSDU ; + + ts->peer_id =FIELD_GET (HAL_WBM_RELEASE_INFO3_PEER_ID , desc->info3); + ts->tid =FIELD_GET (HAL_WBM_RELEASE_INFO3_TID , desc->info3); + +if (!(desc->rate_stats.info0 &HAL_TX_RATE_STATS_INFO0_VALID )) +return ; + + ts->flags |=HAL_TX_STATUS_FLAGS_RATE_STATS_VALID ; + ts->tsf = desc->rate_stats.tsf; + ts->bw =FIELD_GET (HAL_TX_RATE_STATS_INFO0_BW , desc->rate_stats.info0); + ts->pkt_type =FIELD_GET (HAL_TX_RATE_STATS_INFO0_PKT_TYPE , + desc->rate_stats.info0); +if (desc->rate_stats.info0 &HAL_TX_RATE_STATS_INFO0_STBC ) + ts->flags |=HAL_TX_STATUS_FLAGS_RATE_STBC ; +if (desc->rate_stats.info0 &HAL_TX_RATE_STATS_INFO0_LDPC ) + ts->flags |=HAL_TX_STATUS_FLAGS_RATE_LDPC ; +if (desc->rate_stats.info0 &HAL_TX_RATE_STATS_INFO0_OFDMA_TX ) + ts->flags |=HAL_TX_STATUS_FLAGS_OFDMA ; + + ts->sgi =FIELD_GET (HAL_TX_RATE_STATS_INFO0_SGI , + desc->rate_stats.info0); + ts->mcs =FIELD_GET (HAL_TX_RATE_STATS_INFO0_MCS , + desc->rate_stats.info0); + ts->num_tones_in_ru =FIELD_GET (HAL_TX_RATE_STATS_INFO0_TONES_IN_RU , + desc->rate_stats.info0); +} + +void ath11k_hal_tx_set_dscp_tid_map (struct ath11k_base *ab,int id) +{ +u32 ctrl_reg_val; +u32 addr; +u8 hw_map_val[HAL_DSCP_TID_TBL_SIZE ]; +int i; +u32 value; +int cnt =0 ; + + ctrl_reg_val =ath11k_ahb_read32 (ab,HAL_SEQ_WCSS_UMAC_TCL_REG + +HAL_TCL1_RING_CMN_CTRL_REG ); +/* Enable read/write access */ + ctrl_reg_val |=HAL_TCL1_RING_CMN_CTRL_DSCP_TID_MAP_PROG_EN ; +ath11k_ahb_write32 (ab,HAL_SEQ_WCSS_UMAC_TCL_REG + +HAL_TCL1_RING_CMN_CTRL_REG , ctrl_reg_val); + + addr =HAL_SEQ_WCSS_UMAC_TCL_REG +HAL_TCL1_RING_DSCP_TID_MAP + + (4 * id * (HAL_DSCP_TID_TBL_SIZE /4 )); + +/* Configure each DSCP-TID mapping in three bits there by configure +* three bytes in an iteration. +*/ +for (i =0 ; i <DSCP_TID_MAP_TBL_ENTRY_SIZE ; i +=8 ) { + value =FIELD_PREP (HAL_TCL1_RING_FIELD_DSCP_TID_MAP0 , + dscp_tid_map[i]) | +FIELD_PREP (HAL_TCL1_RING_FIELD_DSCP_TID_MAP1 , + dscp_tid_map[i +1 ]) | +FIELD_PREP (HAL_TCL1_RING_FIELD_DSCP_TID_MAP2 , + dscp_tid_map[i +2 ]) | +FIELD_PREP (HAL_TCL1_RING_FIELD_DSCP_TID_MAP3 , + dscp_tid_map[i +3 ]) | +FIELD_PREP (HAL_TCL1_RING_FIELD_DSCP_TID_MAP4 , + dscp_tid_map[i +4 ]) | +FIELD_PREP (HAL_TCL1_RING_FIELD_DSCP_TID_MAP5 , + dscp_tid_map[i +5 ]) | +FIELD_PREP (HAL_TCL1_RING_FIELD_DSCP_TID_MAP6 , + dscp_tid_map[i +6 ]) | +FIELD_PREP (HAL_TCL1_RING_FIELD_DSCP_TID_MAP7 , + dscp_tid_map[i +7 ]); +memcpy (&hw_map_val[cnt], (u8 *)&value,3 ); + cnt +=3 ; + } + +for (i =0 ; i <HAL_DSCP_TID_TBL_SIZE ; i +=4 ) { +ath11k_ahb_write32 (ab, addr, *(u32 *)&hw_map_val[i]); + addr +=4 ; + } + +/* Disable read/write access */ + ctrl_reg_val =ath11k_ahb_read32 (ab,HAL_SEQ_WCSS_UMAC_TCL_REG + +HAL_TCL1_RING_CMN_CTRL_REG ); + ctrl_reg_val &= ~HAL_TCL1_RING_CMN_CTRL_DSCP_TID_MAP_PROG_EN ; +ath11k_ahb_write32 (ab,HAL_SEQ_WCSS_UMAC_TCL_REG + +HAL_TCL1_RING_CMN_CTRL_REG , + ctrl_reg_val); +} + +void ath11k_hal_tx_init_data_ring (struct ath11k_base *ab,struct hal_srng *srng) +{ +struct hal_srng_params params; +struct hal_tlv_hdr *tlv; +int i, entry_size; +u8 *desc; + +memset (¶ms,0 ,sizeof (params)); + + entry_size =ath11k_hal_srng_get_entrysize (HAL_TCL_DATA ); +ath11k_hal_srng_get_params (ab, srng, ¶ms); + desc = (u8 *)params.ring_base_vaddr; + +for (i =0 ; i < params.num_entries; i++) { + tlv = (struct hal_tlv_hdr *)desc; + tlv->tl =FIELD_PREP (HAL_TLV_HDR_TAG ,HAL_TCL_DATA_CMD ) | +FIELD_PREP (HAL_TLV_HDR_LEN , +sizeof (struct hal_tcl_data_cmd )); + desc += entry_size; + } +}
_______________________________________________
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v3 27/49 ath11k: add hal_tx.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/hal_tx.h | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
drivers/net/wireless/ath/ath11k/hal_tx.h new file +80 -0
@@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#ifndef ATH11K_HAL_TX_H +#define ATH11K_HAL_TX_H + +#include "hal_desc.h" + +#define HAL_TX_ADDRX_EN 1 +#define HAL_TX_ADDRY_EN 2 + +#define HAL_TX_ADDR_SEARCH_INDEX 0 +#define HAL_TX_ADDR_SEARCH_DEFAULT 1 + +struct hal_tx_info { +u16 meta_data_flags;/* %HAL_TCL_DATA_CMD_INFO0_META_ */ +u8 ring_id; +u32 desc_id; +enum hal_tcl_desc_type type; +enum hal_tcl_encap_type encap_type; +dma_addr_t paddr; +u32 data_len; +u32 pkt_offset; +enum hal_encrypt_type encrypt_type; +u32 flags0;/* %HAL_TCL_DATA_CMD_INFO1_ */ +u32 flags1;/* %HAL_TCL_DATA_CMD_INFO2_ */ +u16 addr_search_flags;/* %HAL_TCL_DATA_CMD_INFO0_ADDR(X/Y)_ */ +u16 bss_ast_hash; +u8 tid; +u8 search_type;/* %HAL_TX_ADDR_SEARCH_ */ +u8 lmac_id; +u8 dscp_tid_tbl_idx; +}; + +/* TODO: Check if the actual desc macros can be used instead */ +#define HAL_TX_STATUS_FLAGS_FIRST_MSDU BIT(0) +#define HAL_TX_STATUS_FLAGS_LAST_MSDU BIT(1) +#define HAL_TX_STATUS_FLAGS_MSDU_IN_AMSDU BIT(2) +#define HAL_TX_STATUS_FLAGS_RATE_STATS_VALID BIT(3) +#define HAL_TX_STATUS_FLAGS_RATE_LDPC BIT(4) +#define HAL_TX_STATUS_FLAGS_RATE_STBC BIT(5) +#define HAL_TX_STATUS_FLAGS_OFDMA BIT(6) + +#define HAL_TX_STATUS_DESC_LEN sizeof(struct hal_wbm_release_ring) + +/* Tx status parsed from srng desc */ +struct hal_tx_status { +enum hal_wbm_rel_src_module buf_rel_source; +u32 desc_id; +enum hal_wbm_tqm_rel_reason status; +u8 ack_rssi; +enum hal_tx_rate_stats_bw bw; +enum hal_tx_rate_stats_pkt_type pkt_type; +enum hal_tx_rate_stats_sgi sgi; +u8 mcs; +u16 num_tones_in_ru; +u32 flags;/* %HAL_TX_STATUS_FLAGS_ */ +u32 tsf; +u32 ppdu_id; +u8 try_cnt; +u8 tid; +u16 peer_id; +}; + +void ath11k_hal_tx_cmd_desc_setup (struct ath11k_base *ab,void *cmd, +struct hal_tx_info *ti); +void ath11k_hal_tx_desc_sync (void *tx_desc_cached,void *hw_desc); +void ath11k_hal_tx_status_parse (struct ath11k_base *ab, +struct hal_wbm_release_ring *desc, +struct hal_tx_status *ts); +void ath11k_hal_tx_status_desc_sync (void *hw_desc,void *local_desc); +void ath11k_hal_tx_set_dscp_tid_map (struct ath11k_base *ab,int id); +int ath11k_hal_reo_cmd_send (struct ath11k_base *ab,struct hal_srng *srng, +enum hal_reo_cmd_type type, +struct ath11k_hal_reo_cmd *cmd); +void ath11k_hal_tx_init_data_ring (struct ath11k_base *ab, +struct hal_srng *srng); +#endif
PATCH v3 28/49 ath11k: add htc.c
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/htc.c | 773 ++++++++++++++++++++++++++++++++++ 1 file changed, 773 insertions(+)
drivers/net/wireless/ath/ath11k/htc.c new file +773 -0
@@ -0,0 +1,773 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ +#include <linux/skbuff.h> +#include <linux/ctype.h> + +#include "ahb.h" +#include "debug.h" + +struct sk_buff *ath11k_htc_alloc_skb (struct ath11k_base *ab,int size) +{ +struct sk_buff *skb; + + skb =dev_alloc_skb (size +sizeof (struct ath11k_htc_hdr )); +if (!skb) +return NULL ; + +skb_reserve (skb,sizeof (struct ath11k_htc_hdr )); + +/* FW/HTC requires 4-byte aligned streams */ +if (!IS_ALIGNED ((unsigned long )skb->data,4 )) +ath11k_warn (ab,"Unaligned HTC tx skb\n" ); + +return skb; +} + +static void ath11k_htc_control_tx_complete (struct ath11k_base *ab, +struct sk_buff *skb) +{ +kfree_skb (skb); +} + +static struct sk_buff *ath11k_htc_build_tx_ctrl_skb (void *ab) +{ +struct sk_buff *skb; +struct ath11k_skb_cb *skb_cb; + + skb =dev_alloc_skb (ATH11K_HTC_CONTROL_BUFFER_SIZE ); +if (!skb) +return NULL ; + +skb_reserve (skb,sizeof (struct ath11k_htc_hdr )); +WARN_ON_ONCE (!IS_ALIGNED ((unsigned long )skb->data,4 )); + + skb_cb =ATH11K_SKB_CB (skb); +memset (skb_cb,0 ,sizeof (*skb_cb)); + +ath11k_dbg (ab,ATH11K_DBG_HTC ,"%s: skb %pK\n" , __func__, skb); +return skb; +} + +static inline void ath11k_htc_restore_tx_skb (struct ath11k_htc *htc, +struct sk_buff *skb) +{ +struct ath11k_skb_cb *skb_cb =ATH11K_SKB_CB (skb); + +dma_unmap_single (htc->ab->dev, skb_cb->paddr, skb->len,DMA_TO_DEVICE ); +skb_pull (skb,sizeof (struct ath11k_htc_hdr )); +} + +static void ath11k_htc_prepare_tx_skb (struct ath11k_htc_ep *ep, +struct sk_buff *skb) +{ +struct ath11k_htc_hdr *hdr; + + hdr = (struct ath11k_htc_hdr *)skb->data; + +memset (hdr,0 ,sizeof (*hdr)); + hdr->htc_info =FIELD_PREP (HTC_HDR_ENDPOINTID , ep->eid) | +FIELD_PREP (HTC_HDR_PAYLOADLEN , + (skb->len -sizeof (*hdr))) | +FIELD_PREP (HTC_HDR_FLAGS , +ATH11K_HTC_FLAG_NEED_CREDIT_UPDATE ); + +spin_lock_bh (&ep->htc->tx_lock); + hdr->ctrl_info =FIELD_PREP (HTC_HDR_CONTROLBYTES1 , ep->seq_no++); +spin_unlock_bh (&ep->htc->tx_lock); +} + +int ath11k_htc_send (struct ath11k_htc *htc, +enum ath11k_htc_ep_id eid, +struct sk_buff *skb) +{ +struct ath11k_htc_ep *ep = &htc->endpoint[eid]; +struct ath11k_skb_cb *skb_cb =ATH11K_SKB_CB (skb); +struct device *dev = htc->ab->dev; +struct ath11k_base *ab = htc->ab; +int credits =0 ; +int ret; + +if (eid >=ATH11K_HTC_EP_COUNT ) { +ath11k_warn (ab,"Invalid endpoint id: %d\n" , eid); +return -ENOENT ; + } + +skb_push (skb,sizeof (struct ath11k_htc_hdr )); + +if (ep->tx_credit_flow_enabled) { + credits =DIV_ROUND_UP (skb->len, htc->target_credit_size); +spin_lock_bh (&htc->tx_lock); +if (ep->tx_credits < credits) { +ath11k_dbg (ab,ATH11K_DBG_HTC , +"htc insufficient credits ep %d required %d available %d\n" , + eid, credits, ep->tx_credits); +spin_unlock_bh (&htc->tx_lock); + ret = -EAGAIN ; + goto err_pull; + } + ep->tx_credits -= credits; +ath11k_dbg (ab,ATH11K_DBG_HTC , +"htc ep %d consumed %d credits (total %d)\n" , + eid, credits, ep->tx_credits); +spin_unlock_bh (&htc->tx_lock); + } + +ath11k_htc_prepare_tx_skb (ep, skb); + + skb_cb->eid = eid; + skb_cb->paddr =dma_map_single (dev, skb->data, skb->len,DMA_TO_DEVICE ); + ret =dma_mapping_error (dev, skb_cb->paddr); +if (ret) { + ret = -EIO ; + goto err_credits; + } + + ret =ath11k_ce_send (htc->ab, skb, ep->ul_pipe_id, ep->eid); +if (ret) + goto err_unmap; + +return 0 ; + +err_unmap: +dma_unmap_single (dev, skb_cb->paddr, skb->len,DMA_TO_DEVICE ); +err_credits: +if (ep->tx_credit_flow_enabled) { +spin_lock_bh (&htc->tx_lock); + ep->tx_credits += credits; +ath11k_dbg (ab,ATH11K_DBG_HTC , +"htc ep %d reverted %d credits back (total %d)\n" , + eid, credits, ep->tx_credits); +spin_unlock_bh (&htc->tx_lock); + +if (ep->ep_ops.ep_tx_credits) + ep->ep_ops.ep_tx_credits (htc->ab); + } +err_pull: +skb_pull (skb,sizeof (struct ath11k_htc_hdr )); +return ret; +} + +static void +ath11k_htc_process_credit_report (struct ath11k_htc *htc, +const struct ath11k_htc_credit_report *report, +int len, +enum ath11k_htc_ep_id eid) +{ +struct ath11k_base *ab = htc->ab; +struct ath11k_htc_ep *ep; +int i, n_reports; + +if (len %sizeof (*report)) +ath11k_warn (ab,"Uneven credit report len %d" , len); + + n_reports = len /sizeof (*report); + +spin_lock_bh (&htc->tx_lock); +for (i =0 ; i < n_reports; i++, report++) { +if (report->eid >=ATH11K_HTC_EP_COUNT ) +break ; + + ep = &htc->endpoint[report->eid]; + ep->tx_credits += report->credits; + +ath11k_dbg (ab,ATH11K_DBG_HTC ,"htc ep %d got %d credits (total %d)\n" , + report->eid, report->credits, ep->tx_credits); + +if (ep->ep_ops.ep_tx_credits) { +spin_unlock_bh (&htc->tx_lock); + ep->ep_ops.ep_tx_credits (htc->ab); +spin_lock_bh (&htc->tx_lock); + } + } +spin_unlock_bh (&htc->tx_lock); +} + +static int ath11k_htc_process_trailer (struct ath11k_htc *htc, +u8 *buffer, +int length, +enum ath11k_htc_ep_id src_eid) +{ +struct ath11k_base *ab = htc->ab; +int status =0 ; +struct ath11k_htc_record *record; +size_t len; + +while (length >0 ) { + record = (struct ath11k_htc_record *)buffer; + +if (length <sizeof (record->hdr)) { + status = -EINVAL ; +break ; + } + +if (record->hdr.len > length) { +/* no room left in buffer for record */ +ath11k_warn (ab,"Invalid record length: %d\n" , + record->hdr.len); + status = -EINVAL ; +break ; + } + +switch (record->hdr.id) { +case ATH11K_HTC_RECORD_CREDITS : + len =sizeof (struct ath11k_htc_credit_report ); +if (record->hdr.len < len) { +ath11k_warn (ab,"Credit report too long\n" ); + status = -EINVAL ; +break ; + } +ath11k_htc_process_credit_report (htc, + record->credit_report, + record->hdr.len, + src_eid); +break ; +default : +ath11k_warn (ab,"Unhandled record: id:%d length:%d\n" , + record->hdr.id, record->hdr.len); +break ; + } + +if (status) +break ; + +/* multiple records may be present in a trailer */ + buffer +=sizeof (record->hdr) + record->hdr.len; + length -=sizeof (record->hdr) + record->hdr.len; + } + +return status; +} + +void ath11k_htc_rx_completion_handler (struct ath11k_base *ab, +struct sk_buff *skb) +{ +int status =0 ; +struct ath11k_htc *htc = &ab->htc; +struct ath11k_htc_hdr *hdr; +struct ath11k_htc_ep *ep; +u16 payload_len; +u32 trailer_len =0 ; +size_t min_len; +u8 eid; +bool trailer_present; + + hdr = (struct ath11k_htc_hdr *)skb->data; +skb_pull (skb,sizeof (*hdr)); + + eid =FIELD_GET (HTC_HDR_ENDPOINTID , hdr->htc_info); + +if (eid >=ATH11K_HTC_EP_COUNT ) { +ath11k_warn (ab,"HTC Rx: invalid eid %d\n" , eid); + goto out; + } + + ep = &htc->endpoint[eid]; + + payload_len =FIELD_GET (HTC_HDR_PAYLOADLEN , hdr->htc_info); + +if (payload_len +sizeof (*hdr) >ATH11K_HTC_MAX_LEN ) { +ath11k_warn (ab,"HTC rx frame too long, len: %zu\n" , + payload_len +sizeof (*hdr)); + goto out; + } + +if (skb->len < payload_len) { +ath11k_warn (ab,"HTC Rx: insufficient length, got %d, expected %d\n" , + skb->len, payload_len); + goto out; + } + +/* get flags to check for trailer */ + trailer_present = (FIELD_GET (HTC_HDR_FLAGS , hdr->htc_info)) & +ATH11K_HTC_FLAG_TRAILER_PRESENT ; + +if (trailer_present) { +u8 *trailer; + + trailer_len =FIELD_GET (HTC_HDR_CONTROLBYTES0 , hdr->ctrl_info); + min_len =sizeof (struct ath11k_htc_record_hdr ); + +if ((trailer_len < min_len) || + (trailer_len > payload_len)) { +ath11k_warn (ab,"Invalid trailer length: %d\n" , + trailer_len); + goto out; + } + + trailer = (u8 *)hdr; + trailer +=sizeof (*hdr); + trailer += payload_len; + trailer -= trailer_len; + status =ath11k_htc_process_trailer (htc, trailer, + trailer_len, eid); +if (status) + goto out; + +skb_trim (skb, skb->len - trailer_len); + } + +if (trailer_len >= payload_len) +/* zero length packet with trailer data, just drop these */ + goto out; + +if (eid ==ATH11K_HTC_EP_0 ) { +struct ath11k_htc_msg *msg = (struct ath11k_htc_msg *)skb->data; + +switch (FIELD_GET (HTC_MSG_MESSAGEID , msg->msg_svc_id)) { +case ATH11K_HTC_MSG_READY_ID : +case ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID : +/* handle HTC control message */ +if (completion_done (&htc->ctl_resp)) { +/* this is a fatal error, target should not be +* sending unsolicited messages on the ep 0 +*/ +ath11k_warn (ab,"HTC rx ctrl still processing\n" ); +complete (&htc->ctl_resp); + goto out; + } + + htc->control_resp_len = +min_t (int, skb->len, +ATH11K_HTC_MAX_CTRL_MSG_LEN ); + +memcpy (htc->control_resp_buffer, skb->data, + htc->control_resp_len); + +complete (&htc->ctl_resp); +break ; +default : +ath11k_warn (ab,"ignoring unsolicited htc ep0 event\n" ); +break ; + } + goto out; + } + +ath11k_dbg (ab,ATH11K_DBG_HTC ,"htc rx completion ep %d skb %pK\n" , + eid, skb); + ep->ep_ops.ep_rx_complete (ab, skb); + +/* poll tx completion for interrupt disabled CE's */ +ath11k_ce_poll_send_completed (ab, ep->ul_pipe_id); + +/* skb is now owned by the rx completion handler */ + skb =NULL ; +out: +kfree_skb (skb); +} + +static void ath11k_htc_control_rx_complete (struct ath11k_base *ab, +struct sk_buff *skb) +{ +/* This is unexpected. FW is not supposed to send regular rx on this +* endpoint. +*/ +ath11k_warn (ab,"unexpected htc rx\n" ); +kfree_skb (skb); +} + +static const char *htc_service_name (enum ath11k_htc_svc_id id) +{ +switch (id) { +case ATH11K_HTC_SVC_ID_RESERVED : +return "Reserved" ; +case ATH11K_HTC_SVC_ID_RSVD_CTRL : +return "Control" ; +case ATH11K_HTC_SVC_ID_WMI_CONTROL : +return "WMI" ; +case ATH11K_HTC_SVC_ID_WMI_DATA_BE : +return "DATA BE" ; +case ATH11K_HTC_SVC_ID_WMI_DATA_BK : +return "DATA BK" ; +case ATH11K_HTC_SVC_ID_WMI_DATA_VI : +return "DATA VI" ; +case ATH11K_HTC_SVC_ID_WMI_DATA_VO : +return "DATA VO" ; +case ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1 : +return "WMI MAC1" ; +case ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 : +return "WMI MAC2" ; +case ATH11K_HTC_SVC_ID_NMI_CONTROL : +return "NMI Control" ; +case ATH11K_HTC_SVC_ID_NMI_DATA : +return "NMI Data" ; +case ATH11K_HTC_SVC_ID_HTT_DATA_MSG : +return "HTT Data" ; +case ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS : +return "RAW" ; +case ATH11K_HTC_SVC_ID_IPA_TX : +return "IPA TX" ; +case ATH11K_HTC_SVC_ID_PKT_LOG : +return "PKT LOG" ; + } + +return "Unknown" ; +} + +static void ath11k_htc_reset_endpoint_states (struct ath11k_htc *htc) +{ +struct ath11k_htc_ep *ep; +int i; + +for (i =ATH11K_HTC_EP_0 ; i <ATH11K_HTC_EP_COUNT ; i++) { + ep = &htc->endpoint[i]; + ep->service_id =ATH11K_HTC_SVC_ID_UNUSED ; + ep->max_ep_message_len =0 ; + ep->max_tx_queue_depth =0 ; + ep->eid = i; + ep->htc = htc; + ep->tx_credit_flow_enabled = true; + } +} + +static u8 ath11k_htc_get_credit_allocation (struct ath11k_htc *htc, +u16 service_id) +{ +u8 i, allocation =0 ; + +for (i =0 ; i <ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES ; i++) { +if (htc->service_alloc_table[i].service_id == service_id) { + allocation = + htc->service_alloc_table[i].credit_allocation; + } + } + +return allocation; +} + +static int ath11k_htc_setup_target_buffer_assignments (struct ath11k_htc *htc) +{ +struct ath11k_htc_svc_tx_credits *serv_entry; +u32 svc_id[] = { +ATH11K_HTC_SVC_ID_WMI_CONTROL , +ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1 , +ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 , + }; +int i, credits; + + credits = htc->total_transmit_credits; + serv_entry = htc->service_alloc_table; + +if ((htc->wmi_ep_count ==0 ) || + (htc->wmi_ep_count >ARRAY_SIZE (svc_id))) +return -EINVAL ; + +/* Divide credits among number of endpoints for WMI */ + credits = credits / htc->wmi_ep_count; +for (i =0 ; i < htc->wmi_ep_count; i++) { + serv_entry[i].service_id = svc_id[i]; + serv_entry[i].credit_allocation = credits; + } + +return 0 ; +} + +int ath11k_htc_wait_target (struct ath11k_htc *htc) +{ +int i, status =0 ; +struct ath11k_base *ab = htc->ab; +unsigned long time_left; +struct ath11k_htc_ready *ready; +u16 message_id; +u16 credit_count; +u16 credit_size; + + time_left =wait_for_completion_timeout (&htc->ctl_resp, +ATH11K_HTC_WAIT_TIMEOUT_HZ ); +if (!time_left) { +ath11k_warn (ab,"failed to receive control response completion, polling..\n" ); + +for (i =0 ; i <CE_COUNT ; i++) +ath11k_ce_per_engine_service (htc->ab, i); + + time_left = +wait_for_completion_timeout (&htc->ctl_resp, +ATH11K_HTC_WAIT_TIMEOUT_HZ ); + +if (!time_left) + status = -ETIMEDOUT ; + } + +if (status <0 ) { +ath11k_warn (ab,"ctl_resp never came in (%d)\n" , status); +return status; + } + +if (htc->control_resp_len <sizeof (*ready)) { +ath11k_warn (ab,"Invalid HTC ready msg len:%d\n" , + htc->control_resp_len); +return -ECOMM ; + } + + ready = (struct ath11k_htc_ready *)htc->control_resp_buffer; + message_id =FIELD_GET (HTC_MSG_MESSAGEID , ready->id_credit_count); + credit_count =FIELD_GET (HTC_READY_MSG_CREDITCOUNT , + ready->id_credit_count); + credit_size =FIELD_GET (HTC_READY_MSG_CREDITSIZE , ready->size_ep); + +if (message_id !=ATH11K_HTC_MSG_READY_ID ) { +ath11k_warn (ab,"Invalid HTC ready msg: 0x%x\n" , message_id); +return -ECOMM ; + } + + htc->total_transmit_credits = credit_count; + htc->target_credit_size = credit_size; + +ath11k_dbg (ab,ATH11K_DBG_HTC , +"Target ready! transmit resources: %d size:%d\n" , + htc->total_transmit_credits, htc->target_credit_size); + +if ((htc->total_transmit_credits ==0 ) || + (htc->target_credit_size ==0 )) { +ath11k_warn (ab,"Invalid credit size received\n" ); +return -ECOMM ; + } + +ath11k_htc_setup_target_buffer_assignments (htc); + +return 0 ; +} + +int ath11k_htc_connect_service (struct ath11k_htc *htc, +struct ath11k_htc_svc_conn_req *conn_req, +struct ath11k_htc_svc_conn_resp *conn_resp) +{ +struct ath11k_base *ab = htc->ab; +struct ath11k_htc_conn_svc *req_msg; +struct ath11k_htc_conn_svc_resp resp_msg_dummy; +struct ath11k_htc_conn_svc_resp *resp_msg = &resp_msg_dummy; +enum ath11k_htc_ep_id assigned_eid =ATH11K_HTC_EP_COUNT ; +struct ath11k_htc_ep *ep; +struct sk_buff *skb; +unsigned int max_msg_size =0 ; +int length, status; +unsigned long time_left; +bool disable_credit_flow_ctrl = false; +u16 message_id, service_id, flags =0 ; +u8 tx_alloc =0 ; + +/* special case for HTC pseudo control service */ +if (conn_req->service_id ==ATH11K_HTC_SVC_ID_RSVD_CTRL ) { + disable_credit_flow_ctrl = true; + assigned_eid =ATH11K_HTC_EP_0 ; + max_msg_size =ATH11K_HTC_MAX_CTRL_MSG_LEN ; +memset (&resp_msg_dummy,0 ,sizeof (resp_msg_dummy)); + goto setup; + } + + tx_alloc =ath11k_htc_get_credit_allocation (htc, + conn_req->service_id); +if (!tx_alloc) +ath11k_dbg (ab,ATH11K_DBG_BOOT , +"boot htc service %s does not allocate target credits\n" , +htc_service_name (conn_req->service_id)); + + skb =ath11k_htc_build_tx_ctrl_skb (htc->ab); +if (!skb) { +ath11k_warn (ab,"Failed to allocate HTC packet\n" ); +return -ENOMEM ; + } + + length =sizeof (*req_msg); +skb_put (skb, length); +memset (skb->data,0 , length); + + req_msg = (struct ath11k_htc_conn_svc *)skb->data; + req_msg->msg_svc_id =FIELD_PREP (HTC_MSG_MESSAGEID , +ATH11K_HTC_MSG_CONNECT_SERVICE_ID ); + + flags |=FIELD_PREP (ATH11K_HTC_CONN_FLAGS_RECV_ALLOC , tx_alloc); + +/* Only enable credit flow control for WMI ctrl service */ +if (!(conn_req->service_id ==ATH11K_HTC_SVC_ID_WMI_CONTROL || + conn_req->service_id ==ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1 || + conn_req->service_id ==ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 )) { + flags |=ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL ; + disable_credit_flow_ctrl = true; + } + + req_msg->flags_len =FIELD_PREP (HTC_SVC_MSG_CONNECTIONFLAGS , flags); + req_msg->msg_svc_id |=FIELD_PREP (HTC_SVC_MSG_SERVICE_ID , + conn_req->service_id); + +reinit_completion (&htc->ctl_resp); + + status =ath11k_htc_send (htc,ATH11K_HTC_EP_0 , skb); +if (status) { +kfree_skb (skb); +return status; + } + +/* wait for response */ + time_left =wait_for_completion_timeout (&htc->ctl_resp, +ATH11K_HTC_CONN_SVC_TIMEOUT_HZ ); +if (!time_left) { +ath11k_err (ab,"Service connect timeout\n" ); +return -ETIMEDOUT ; + } + +/* we controlled the buffer creation, it's aligned */ + resp_msg = (struct ath11k_htc_conn_svc_resp *)htc->control_resp_buffer; + message_id =FIELD_GET (HTC_MSG_MESSAGEID , resp_msg->msg_svc_id); + service_id =FIELD_GET (HTC_SVC_RESP_MSG_SERVICEID , + resp_msg->msg_svc_id); + +if ((message_id !=ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID ) || + (htc->control_resp_len <sizeof (*resp_msg))) { +ath11k_err (ab,"Invalid resp message ID 0x%x" , message_id); +return -EPROTO ; + } + +ath11k_dbg (ab,ATH11K_DBG_HTC , +"HTC Service %s connect response: status: 0x%lx, assigned ep: 0x%lx\n" , +htc_service_name (service_id), +FIELD_GET (HTC_SVC_RESP_MSG_STATUS , resp_msg->flags_len), +FIELD_GET (HTC_SVC_RESP_MSG_ENDPOINTID , resp_msg->flags_len)); + + conn_resp->connect_resp_code =FIELD_GET (HTC_SVC_RESP_MSG_STATUS , + resp_msg->flags_len); + +/* check response status */ +if (conn_resp->connect_resp_code !=ATH11K_HTC_CONN_SVC_STATUS_SUCCESS ) { +ath11k_err (ab,"HTC Service %s connect request failed: 0x%x)\n" , +htc_service_name (service_id), + conn_resp->connect_resp_code); +return -EPROTO ; + } + + assigned_eid = (enum ath11k_htc_ep_id )FIELD_GET ( +HTC_SVC_RESP_MSG_ENDPOINTID , + resp_msg->flags_len); + + max_msg_size =FIELD_GET (HTC_SVC_RESP_MSG_MAXMSGSIZE , + resp_msg->flags_len); + +setup: + +if (assigned_eid >=ATH11K_HTC_EP_COUNT ) +return -EPROTO ; + +if (max_msg_size ==0 ) +return -EPROTO ; + + ep = &htc->endpoint[assigned_eid]; + ep->eid = assigned_eid; + +if (ep->service_id !=ATH11K_HTC_SVC_ID_UNUSED ) +return -EPROTO ; + +/* return assigned endpoint to caller */ + conn_resp->eid = assigned_eid; + conn_resp->max_msg_len =FIELD_GET (HTC_SVC_RESP_MSG_MAXMSGSIZE , + resp_msg->flags_len); + +/* setup the endpoint */ + ep->service_id = conn_req->service_id; + ep->max_tx_queue_depth = conn_req->max_send_queue_depth; + ep->max_ep_message_len =FIELD_GET (HTC_SVC_RESP_MSG_MAXMSGSIZE , + resp_msg->flags_len); + ep->tx_credits = tx_alloc; + +/* copy all the callbacks */ + ep->ep_ops = conn_req->ep_ops; + + status =ath11k_ahb_map_service_to_pipe (htc->ab, + ep->service_id, + &ep->ul_pipe_id, + &ep->dl_pipe_id); +if (status) +return status; + +ath11k_dbg (ab,ATH11K_DBG_BOOT , +"boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n" , +htc_service_name (ep->service_id), ep->ul_pipe_id, + ep->dl_pipe_id, ep->eid); + +if (disable_credit_flow_ctrl && ep->tx_credit_flow_enabled) { + ep->tx_credit_flow_enabled = false; +ath11k_dbg (ab,ATH11K_DBG_BOOT , +"boot htc service '%s' eid %d TX flow control disabled\n" , +htc_service_name (ep->service_id), assigned_eid); + } + +return status; +} + +int ath11k_htc_start (struct ath11k_htc *htc) +{ +struct sk_buff *skb; +int status =0 ; +struct ath11k_base *ab = htc->ab; +struct ath11k_htc_setup_complete_extended *msg; + + skb =ath11k_htc_build_tx_ctrl_skb (htc->ab); +if (!skb) +return -ENOMEM ; + +skb_put (skb,sizeof (*msg)); +memset (skb->data,0 , skb->len); + + msg = (struct ath11k_htc_setup_complete_extended *)skb->data; + msg->msg_id =FIELD_PREP (HTC_MSG_MESSAGEID , +ATH11K_HTC_MSG_SETUP_COMPLETE_EX_ID ); + +ath11k_dbg (ab,ATH11K_DBG_HTC ,"HTC is using TX credit flow control\n" ); + + status =ath11k_htc_send (htc,ATH11K_HTC_EP_0 , skb); +if (status) { +kfree_skb (skb); +return status; + } + +return 0 ; +} + +int ath11k_htc_init (struct ath11k_base *ab) +{ +struct ath11k_htc *htc = &ab->htc; +struct ath11k_htc_svc_conn_req conn_req; +struct ath11k_htc_svc_conn_resp conn_resp; +int ret; + +spin_lock_init (&htc->tx_lock); + +ath11k_htc_reset_endpoint_states (htc); + + htc->ab = ab; + +switch (ab->wmi_sc.preferred_hw_mode) { +case WMI_HOST_HW_MODE_SINGLE : + htc->wmi_ep_count =1 ; +break ; +case WMI_HOST_HW_MODE_DBS : +case WMI_HOST_HW_MODE_DBS_OR_SBS : + htc->wmi_ep_count =2 ; +break ; +case WMI_HOST_HW_MODE_DBS_SBS : + htc->wmi_ep_count =3 ; +break ; +default : + htc->wmi_ep_count =3 ; +break ; + } + +/* setup our pseudo HTC control endpoint connection */ +memset (&conn_req,0 ,sizeof (conn_req)); +memset (&conn_resp,0 ,sizeof (conn_resp)); + conn_req.ep_ops.ep_tx_complete = ath11k_htc_control_tx_complete; + conn_req.ep_ops.ep_rx_complete = ath11k_htc_control_rx_complete; + conn_req.max_send_queue_depth =ATH11K_NUM_CONTROL_TX_BUFFERS ; + conn_req.service_id =ATH11K_HTC_SVC_ID_RSVD_CTRL ; + +/* connect fake service */ + ret =ath11k_htc_connect_service (htc, &conn_req, &conn_resp); +if (ret) { +ath11k_err (ab,"could not connect to htc service (%d)\n" , ret); +return ret; + } + +init_completion (&htc->ctl_resp); + +return 0 ; +}
_______________________________________________
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v3 29/49 ath11k: add htc.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/htc.h | 313 ++++++++++++++++++++++++++++++++++ 1 file changed, 313 insertions(+)
drivers/net/wireless/ath/ath11k/htc.h new file +313 -0
@@ -0,0 +1,313 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#ifndef ATH11K_HTC_H +#define ATH11K_HTC_H + +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/bug.h> +#include <linux/skbuff.h> +#include <linux/timer.h> + +struct ath11k_base ; + +#define HTC_HDR_ENDPOINTID GENMASK(7, 0) +#define HTC_HDR_FLAGS GENMASK(15, 8) +#define HTC_HDR_PAYLOADLEN GENMASK(31, 16) +#define HTC_HDR_CONTROLBYTES0 GENMASK(7, 0) +#define HTC_HDR_CONTROLBYTES1 GENMASK(15, 8) +#define HTC_HDR_RESERVED GENMASK(31, 16) + +#define HTC_SVC_MSG_SERVICE_ID GENMASK(31, 16) +#define HTC_SVC_MSG_CONNECTIONFLAGS GENMASK(15, 0) +#define HTC_SVC_MSG_SERVICEMETALENGTH GENMASK(23, 16) +#define HTC_READY_MSG_CREDITCOUNT GENMASK(31, 16) +#define HTC_READY_MSG_CREDITSIZE GENMASK(15, 0) +#define HTC_READY_MSG_MAXENDPOINTS GENMASK(23, 16) + +#define HTC_READY_EX_MSG_HTCVERSION GENMASK(7, 0) +#define HTC_READY_EX_MSG_MAXMSGSPERHTCBUNDLE GENMASK(15, 8) + +#define HTC_SVC_RESP_MSG_SERVICEID GENMASK(31, 16) +#define HTC_SVC_RESP_MSG_STATUS GENMASK(7, 0) +#define HTC_SVC_RESP_MSG_ENDPOINTID GENMASK(15, 8) +#define HTC_SVC_RESP_MSG_MAXMSGSIZE GENMASK(31, 16) +#define HTC_SVC_RESP_MSG_SERVICEMETALENGTH GENMASK(7, 0) + +#define HTC_MSG_MESSAGEID GENMASK(15, 0) +#define HTC_SETUP_COMPLETE_EX_MSG_SETUPFLAGS GENMASK(31, 0) +#define HTC_SETUP_COMPLETE_EX_MSG_MAXMSGSPERBUNDLEDRECV GENMASK(7, 0) +#define HTC_SETUP_COMPLETE_EX_MSG_RSVD0 GENMASK(15, 8) +#define HTC_SETUP_COMPLETE_EX_MSG_RSVD1 GENMASK(23, 16) +#define HTC_SETUP_COMPLETE_EX_MSG_RSVD2 GENMASK(31, 24) + +enum ath11k_htc_tx_flags { +ATH11K_HTC_FLAG_NEED_CREDIT_UPDATE =0x01 , +ATH11K_HTC_FLAG_SEND_BUNDLE =0x02 +}; + +enum ath11k_htc_rx_flags { +ATH11K_HTC_FLAG_TRAILER_PRESENT =0x02 , +ATH11K_HTC_FLAG_BUNDLE_MASK =0xF0 +}; + +struct ath11k_htc_hdr { +u32 htc_info; +u32 ctrl_info; +} __packed__aligned(4) ; + +enum ath11k_htc_msg_id { +ATH11K_HTC_MSG_READY_ID =1 , +ATH11K_HTC_MSG_CONNECT_SERVICE_ID =2 , +ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID =3 , +ATH11K_HTC_MSG_SETUP_COMPLETE_ID =4 , +ATH11K_HTC_MSG_SETUP_COMPLETE_EX_ID =5 , +ATH11K_HTC_MSG_SEND_SUSPEND_COMPLETE =6 +}; + +enum ath11k_htc_version { +ATH11K_HTC_VERSION_2P0 =0x00 ,/* 2.0 */ +ATH11K_HTC_VERSION_2P1 =0x01 ,/* 2.1 */ +}; + +#define ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_MASK GENMASK(1, 0) +#define ATH11K_HTC_CONN_FLAGS_RECV_ALLOC GENMASK(15, 8) + +enum ath11k_htc_conn_flags { +ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH =0x0 , +ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_ONE_HALF =0x1 , +ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS =0x2 , +ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_UNITY =0x3 , +ATH11K_HTC_CONN_FLAGS_REDUCE_CREDIT_DRIBBLE =1 <<2 , +ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL =1 <<3 +}; + +enum ath11k_htc_conn_svc_status { +ATH11K_HTC_CONN_SVC_STATUS_SUCCESS =0 , +ATH11K_HTC_CONN_SVC_STATUS_NOT_FOUND =1 , +ATH11K_HTC_CONN_SVC_STATUS_FAILED =2 , +ATH11K_HTC_CONN_SVC_STATUS_NO_RESOURCES =3 , +ATH11K_HTC_CONN_SVC_STATUS_NO_MORE_EP =4 +}; + +struct ath11k_htc_ready { +u32 id_credit_count; +u32 size_ep; +} __packed; + +struct ath11k_htc_ready_extended { +struct ath11k_htc_ready base; +u32 ver_bundle; +} __packed; + +struct ath11k_htc_conn_svc { +u32 msg_svc_id; +u32 flags_len; +} __packed; + +struct ath11k_htc_conn_svc_resp { +u32 msg_svc_id; +u32 flags_len; +u32 svc_meta_pad; +} __packed; + +struct ath11k_htc_setup_complete_extended { +u32 msg_id; +u32 flags; +u32 max_msgs_per_bundled_recv; +} __packed; + +struct ath11k_htc_msg { +u32 msg_svc_id; +u32 flags_len; +} __packed__aligned(4) ; + +enum ath11k_htc_record_id { +ATH11K_HTC_RECORD_NULL =0 , +ATH11K_HTC_RECORD_CREDITS =1 +}; + +struct ath11k_htc_record_hdr { +u8 id;/* @enum ath11k_htc_record_id */ +u8 len; +u8 pad0; +u8 pad1; +} __packed; + +struct ath11k_htc_credit_report { +u8 eid;/* @enum ath11k_htc_ep_id */ +u8 credits; +u8 pad0; +u8 pad1; +} __packed; + +struct ath11k_htc_record { +struct ath11k_htc_record_hdr hdr; +union { +struct ath11k_htc_credit_report credit_report[0 ]; +u8 pauload[0 ]; + }; +} __packed__aligned(4) ; + +/* note: the trailer offset is dynamic depending +* on payload length. this is only a struct layout draft +*/ +struct ath11k_htc_frame { +struct ath11k_htc_hdr hdr; +union { +struct ath11k_htc_msg msg; +u8 payload[0 ]; + }; +struct ath11k_htc_record trailer[0 ]; +} __packed__aligned(4) ; + +enum ath11k_htc_svc_gid { +ATH11K_HTC_SVC_GRP_RSVD =0 , +ATH11K_HTC_SVC_GRP_WMI =1 , +ATH11K_HTC_SVC_GRP_NMI =2 , +ATH11K_HTC_SVC_GRP_HTT =3 , +ATH11K_HTC_SVC_GRP_CFG =4 , +ATH11K_HTC_SVC_GRP_IPA =5 , +ATH11K_HTC_SVC_GRP_PKTLOG =6 , + +ATH11K_HTC_SVC_GRP_TEST =254 , +ATH11K_HTC_SVC_GRP_LAST =255 , +}; + +#define SVC (group, idx) \ + (int)(((int)(group) << 8) | (int)(idx)) + +enum ath11k_htc_svc_id { +/* NOTE: service ID of 0x0000 is reserved and should never be used */ +ATH11K_HTC_SVC_ID_RESERVED =0x0000 , +ATH11K_HTC_SVC_ID_UNUSED =ATH11K_HTC_SVC_ID_RESERVED , + +ATH11K_HTC_SVC_ID_RSVD_CTRL =SVC (ATH11K_HTC_SVC_GRP_RSVD ,1 ), +ATH11K_HTC_SVC_ID_WMI_CONTROL =SVC (ATH11K_HTC_SVC_GRP_WMI ,0 ), +ATH11K_HTC_SVC_ID_WMI_DATA_BE =SVC (ATH11K_HTC_SVC_GRP_WMI ,1 ), +ATH11K_HTC_SVC_ID_WMI_DATA_BK =SVC (ATH11K_HTC_SVC_GRP_WMI ,2 ), +ATH11K_HTC_SVC_ID_WMI_DATA_VI =SVC (ATH11K_HTC_SVC_GRP_WMI ,3 ), +ATH11K_HTC_SVC_ID_WMI_DATA_VO =SVC (ATH11K_HTC_SVC_GRP_WMI ,4 ), +ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1 =SVC (ATH11K_HTC_SVC_GRP_WMI ,5 ), +ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 =SVC (ATH11K_HTC_SVC_GRP_WMI ,6 ), + +ATH11K_HTC_SVC_ID_NMI_CONTROL =SVC (ATH11K_HTC_SVC_GRP_NMI ,0 ), +ATH11K_HTC_SVC_ID_NMI_DATA =SVC (ATH11K_HTC_SVC_GRP_NMI ,1 ), + +ATH11K_HTC_SVC_ID_HTT_DATA_MSG =SVC (ATH11K_HTC_SVC_GRP_HTT ,0 ), + +/* raw stream service (i.e. flash, tcmd, calibration apps) */ +ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS =SVC (ATH11K_HTC_SVC_GRP_TEST ,0 ), +ATH11K_HTC_SVC_ID_IPA_TX =SVC (ATH11K_HTC_SVC_GRP_IPA ,0 ), +ATH11K_HTC_SVC_ID_PKT_LOG =SVC (ATH11K_HTC_SVC_GRP_PKTLOG ,0 ), +}; + +#undef SVC + +enum ath11k_htc_ep_id { +ATH11K_HTC_EP_UNUSED =-1 , +ATH11K_HTC_EP_0 =0 , +ATH11K_HTC_EP_1 =1 , +ATH11K_HTC_EP_2 , +ATH11K_HTC_EP_3 , +ATH11K_HTC_EP_4 , +ATH11K_HTC_EP_5 , +ATH11K_HTC_EP_6 , +ATH11K_HTC_EP_7 , +ATH11K_HTC_EP_8 , +ATH11K_HTC_EP_COUNT , +}; + +struct ath11k_htc_ops { +void (*target_send_suspend_complete)(struct ath11k_base *ar); +}; + +struct ath11k_htc_ep_ops { +void (*ep_tx_complete)(struct ath11k_base *,struct sk_buff *); +void (*ep_rx_complete)(struct ath11k_base *,struct sk_buff *); +void (*ep_tx_credits)(struct ath11k_base *); +}; + +/* service connection information */ +struct ath11k_htc_svc_conn_req { +u16 service_id; +struct ath11k_htc_ep_ops ep_ops; +int max_send_queue_depth; +}; + +/* service connection response information */ +struct ath11k_htc_svc_conn_resp { +u8 buffer_len; +u8 actual_len; +enum ath11k_htc_ep_id eid; +unsigned int max_msg_len; +u8 connect_resp_code; +}; + +#define ATH11K_NUM_CONTROL_TX_BUFFERS 2 +#define ATH11K_HTC_MAX_LEN 4096 +#define ATH11K_HTC_MAX_CTRL_MSG_LEN 256 +#define ATH11K_HTC_WAIT_TIMEOUT_HZ (1 * HZ) +#define ATH11K_HTC_CONTROL_BUFFER_SIZE (ATH11K_HTC_MAX_CTRL_MSG_LEN + \ + sizeof(struct ath11k_htc_hdr)) +#define ATH11K_HTC_CONN_SVC_TIMEOUT_HZ (1 * HZ) +#define ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES 8 + +struct ath11k_htc_ep { +struct ath11k_htc *htc; +enum ath11k_htc_ep_id eid; +enum ath11k_htc_svc_id service_id; +struct ath11k_htc_ep_ops ep_ops; + +int max_tx_queue_depth; +int max_ep_message_len; +u8 ul_pipe_id; +u8 dl_pipe_id; + +u8 seq_no;/* for debugging */ +int tx_credits; +bool tx_credit_flow_enabled; +}; + +struct ath11k_htc_svc_tx_credits { +u16 service_id; +u8 credit_allocation; +}; + +struct ath11k_htc { +struct ath11k_base *ab; +struct ath11k_htc_ep endpoint[ATH11K_HTC_EP_COUNT ]; + +/* protects endpoints */ +spinlock_t tx_lock; + +struct ath11k_htc_ops htc_ops; + +u8 control_resp_buffer[ATH11K_HTC_MAX_CTRL_MSG_LEN ]; +int control_resp_len; + +struct completion ctl_resp; + +int total_transmit_credits; +struct ath11k_htc_svc_tx_credits + service_alloc_table[ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES ]; +int target_credit_size; +u8 wmi_ep_count; +}; + +int ath11k_htc_init (struct ath11k_base *ar); +int ath11k_htc_wait_target (struct ath11k_htc *htc); +int ath11k_htc_start (struct ath11k_htc *htc); +int ath11k_htc_connect_service (struct ath11k_htc *htc, +struct ath11k_htc_svc_conn_req *conn_req, +struct ath11k_htc_svc_conn_resp *conn_resp); +int ath11k_htc_send (struct ath11k_htc *htc,enum ath11k_htc_ep_id eid, +struct sk_buff *packet); +struct sk_buff *ath11k_htc_alloc_skb (struct ath11k_base *ar,int size); +void ath11k_htc_rx_completion_handler (struct ath11k_base *ar, +struct sk_buff *skb); + +#endif
PATCH v3 30/49 ath11k: add hw.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/hw.h | 127 +++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+)
drivers/net/wireless/ath/ath11k/hw.h new file +127 -0
@@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#ifndef ATH11K_HW_H +#define ATH11K_HW_H + +/* Target configuration defines */ + +/* Num VDEVS per radio */ +#define TARGET_NUM_VDEVS (16 + 1) + +#define TARGET_NUM_PEERS_PDEV (512 + TARGET_NUM_VDEVS) + +/* Num of peers for Single Radio mode */ +#define TARGET_NUM_PEERS_SINGLE (TARGET_NUM_PEERS_PDEV) + +/* Num of peers for DBS */ +#define TARGET_NUM_PEERS_DBS (2 * TARGET_NUM_PEERS_PDEV) + +/* Num of peers for DBS_SBS */ +#define TARGET_NUM_PEERS_DBS_SBS (3 * TARGET_NUM_PEERS_PDEV) + +/* Max num of stations (per radio) */ +#define TARGET_NUM_STATIONS 512 + +#define TARGET_NUM_PEERS (x) TARGET_NUM_PEERS_##x +#define TARGET_NUM_PEER_KEYS 2 +#define TARGET_NUM_TIDS (x) (2 * TARGET_NUM_PEERS(x) + \ + 4 * TARGET_NUM_VDEVS + 8) + +#define TARGET_AST_SKID_LIMIT 16 +#define TARGET_NUM_OFFLD_PEERS 4 +#define TARGET_NUM_OFFLD_REORDER_BUFFS 4 + +#define TARGET_TX_CHAIN_MASK (BIT(0) | BIT(1) | BIT(2) | BIT(4)) +#define TARGET_RX_CHAIN_MASK (BIT(0) | BIT(1) | BIT(2) | BIT(4)) +#define TARGET_RX_TIMEOUT_LO_PRI 100 +#define TARGET_RX_TIMEOUT_HI_PRI 40 + +#define TARGET_DECAP_MODE_RAW 0 +#define TARGET_DECAP_MODE_NATIVE_WIFI 1 +#define TARGET_DECAP_MODE_ETH 2 + +#define TARGET_SCAN_MAX_PENDING_REQS 4 +#define TARGET_BMISS_OFFLOAD_MAX_VDEV 3 +#define TARGET_ROAM_OFFLOAD_MAX_VDEV 3 +#define TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES 8 +#define TARGET_GTK_OFFLOAD_MAX_VDEV 3 +#define TARGET_NUM_MCAST_GROUPS 12 +#define TARGET_NUM_MCAST_TABLE_ELEMS 64 +#define TARGET_MCAST2UCAST_MODE 2 +#define TARGET_TX_DBG_LOG_SIZE 1024 +#define TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK 1 +#define TARGET_VOW_CONFIG 0 +#define TARGET_NUM_MSDU_DESC (2500) +#define TARGET_MAX_FRAG_ENTRIES 6 +#define TARGET_MAX_BCN_OFFLD 16 +#define TARGET_NUM_WDS_ENTRIES 32 +#define TARGET_DMA_BURST_SIZE 1 +#define TARGET_RX_BATCHMODE 1 + +#define ATH11K_HW_MAX_QUEUES 4 + +#define ATH11k_HW_RATECODE_CCK_SHORT_PREAM_MASK 0x4 + +#define ATH11K_FW_DIR "ath11k" + +/* IPQ8074 definitions */ +#define IPQ8074_FW_DIR "IPQ8074" +#define IPQ8074_MAX_BOARD_DATA_SZ (256 * 1024) +#define IPQ8074_MAX_CAL_DATA_SZ IPQ8074_MAX_BOARD_DATA_SZ + +#define ATH11K_BOARD_MAGIC "QCA-ATH11K-BOARD" +#define ATH11K_BOARD_API2_FILE "board-2.bin" +#define ATH11K_DEFAULT_BOARD_FILE "bdwlan.bin" +#define ATH11K_DEFAULT_CAL_FILE "caldata.bin" + +enum ath11k_hw_rate_cck { +ATH11K_HW_RATE_CCK_LP_11M =0 , +ATH11K_HW_RATE_CCK_LP_5_5M , +ATH11K_HW_RATE_CCK_LP_2M , +ATH11K_HW_RATE_CCK_LP_1M , +ATH11K_HW_RATE_CCK_SP_11M , +ATH11K_HW_RATE_CCK_SP_5_5M , +ATH11K_HW_RATE_CCK_SP_2M , +}; + +enum ath11k_hw_rate_ofdm { +ATH11K_HW_RATE_OFDM_48M =0 , +ATH11K_HW_RATE_OFDM_24M , +ATH11K_HW_RATE_OFDM_12M , +ATH11K_HW_RATE_OFDM_6M , +ATH11K_HW_RATE_OFDM_54M , +ATH11K_HW_RATE_OFDM_36M , +ATH11K_HW_RATE_OFDM_18M , +ATH11K_HW_RATE_OFDM_9M , +}; + +struct ath11k_hw_params { +const char *name; +struct { +const char *dir; +size_t board_size; +size_t cal_size; + } fw; +}; + +struct ath11k_fw_ie { +__le32 id; +__le32 len; +u8 data[0 ]; +}; + +enum ath11k_bd_ie_board_type { +ATH11K_BD_IE_BOARD_NAME =0 , +ATH11K_BD_IE_BOARD_DATA =1 , +}; + +enum ath11k_bd_ie_type { +/* contains sub IEs of enum ath11k_bd_ie_board_type */ +ATH11K_BD_IE_BOARD =0 , +ATH11K_BD_IE_BOARD_EXT =1 , +}; + +#endif
PATCH v3 31/49 ath11k: add mac.c
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/mac.c | 5427 +++++++++++++++++++++++++++++++++ 1 file changed, 5427 insertions(+)
drivers/net/wireless/ath/ath11k/mac.c new file +5427 -0
@@ -0,0 +1,5427 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2019 The Linux Foundation. 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 "testmode.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, \ +} + +static const struct ieee80211_channel ath11k_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 ath11k_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 struct ieee80211_rate ath11k_legacy_rates[] = { + { .bitrate =10 , + .hw_value =ATH11K_HW_RATE_CCK_LP_1M }, + { .bitrate =20 , + .hw_value =ATH11K_HW_RATE_CCK_LP_2M , + .hw_value_short =ATH11K_HW_RATE_CCK_SP_2M , + .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + { .bitrate =55 , + .hw_value =ATH11K_HW_RATE_CCK_LP_5_5M , + .hw_value_short =ATH11K_HW_RATE_CCK_SP_5_5M , + .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + { .bitrate =110 , + .hw_value =ATH11K_HW_RATE_CCK_LP_11M , + .hw_value_short =ATH11K_HW_RATE_CCK_SP_11M , + .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + + { .bitrate =60 , .hw_value =ATH11K_HW_RATE_OFDM_6M }, + { .bitrate =90 , .hw_value =ATH11K_HW_RATE_OFDM_9M }, + { .bitrate =120 , .hw_value =ATH11K_HW_RATE_OFDM_12M }, + { .bitrate =180 , .hw_value =ATH11K_HW_RATE_OFDM_18M }, + { .bitrate =240 , .hw_value =ATH11K_HW_RATE_OFDM_24M }, + { .bitrate =360 , .hw_value =ATH11K_HW_RATE_OFDM_36M }, + { .bitrate =480 , .hw_value =ATH11K_HW_RATE_OFDM_48M }, + { .bitrate =540 , .hw_value =ATH11K_HW_RATE_OFDM_54M }, +}; + +static const int +ath11k_phymodes[NUM_NL80211_BANDS ][ATH11K_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 , + }, +}; + +const struct htt_rx_ring_tlv_filter ath11k_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 ATH11K_MAC_FIRST_OFDM_RATE_IDX 4 +#define ath11k_g_rates ath11k_legacy_rates +#define ath11k_g_rates_size (ARRAY_SIZE(ath11k_legacy_rates)) +#define ath11k_a_rates (ath11k_legacy_rates + 4) +#define ath11k_a_rates_size (ARRAY_SIZE(ath11k_legacy_rates) - 4) + +#define ATH11K_MAC_SCAN_TIMEOUT_MSECS 200/* in msecs */ + +static const u32 ath11k_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 , +}; + +int ath11k_mac_hw_ratecode_to_legacy_rate (u8 hw_rc,u8 preamble,u8 *rateidx, +u16 *rate) +{ +/* As default, it is OFDM rates */ +int i =ATH11K_MAC_FIRST_OFDM_RATE_IDX ; +int max_rates_idx = ath11k_g_rates_size; + +if (preamble ==WMI_RATE_PREAMBLE_CCK ) { + hw_rc &= ~ATH11k_HW_RATECODE_CCK_SHORT_PREAM_MASK; + i =0 ; + max_rates_idx =ATH11K_MAC_FIRST_OFDM_RATE_IDX ; + } + +while (i < max_rates_idx) { +if (hw_rc == ath11k_legacy_rates[i].hw_value) { + *rateidx = i; + *rate = ath11k_legacy_rates[i].bitrate; +return 0 ; + } + i++; + } + +return -EINVAL ; +} + +static int get_num_chains (u32 mask) +{ +int num_chains =0 ; + +while (mask) { +if (mask &BIT (0 )) + num_chains++; + mask >>=1 ; + } + +return num_chains; +} + +u8 ath11k_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 +ath11k_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 +ath11k_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 ath11k_parse_mpdudensity (u8 mpdudensity) +{ +/* 802.11n D2.0 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 ath11k_mac_vif_chan (struct ieee80211_vif *vif, +struct cfg80211_chan_def *def) +{ +struct ieee80211_chanctx_conf *conf; + +rcu_read_lock (); + conf =rcu_dereference (vif->chanctx_conf); +if (!conf) { +rcu_read_unlock (); +return -ENOENT ; + } + + *def = conf->def; +rcu_read_unlock (); + +return 0 ; +} + +static bool ath11k_mac_bitrate_is_cck (int bitrate) +{ +switch (bitrate) { +case 10 : +case 20 : +case 55 : +case 110 : +return true; + } + +return false; +} + +u8 ath11k_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 (ath11k_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 ath11k_mac_bitrate_to_rate (int bitrate) +{ +return DIV_ROUND_UP (bitrate,5 ) | + (ath11k_mac_bitrate_is_cck (bitrate) ?BIT (7 ) :0 ); +} + +static void ath11k_get_arvif_iter (void *data,u8 *mac, +struct ieee80211_vif *vif) +{ +struct ath11k_vif_iter *arvif_iter = data; +struct ath11k_vif *arvif = (void *)vif->drv_priv; + +if (arvif->vdev_id == arvif_iter->vdev_id) + arvif_iter->arvif = arvif; +} + +struct ath11k_vif *ath11k_mac_get_arvif (struct ath11k *ar,u32 vdev_id) +{ +struct ath11k_vif_iter arvif_iter; +u32 flags; + +memset (&arvif_iter,0 ,sizeof (struct ath11k_vif_iter )); + arvif_iter.vdev_id = vdev_id; + + flags =IEEE80211_IFACE_ITER_RESUME_ALL ; +ieee80211_iterate_active_interfaces_atomic (ar->hw, + flags, + ath11k_get_arvif_iter, + &arvif_iter); +if (!arvif_iter.arvif) +return NULL ; + +return arvif_iter.arvif; +} + +struct ath11k_vif *ath11k_mac_get_arvif_by_vdev_id (struct ath11k_base *ab, +u32 vdev_id) +{ +int i; +struct ath11k_pdev *pdev; +struct ath11k_vif *arvif; + +for (i =0 ; i < ab->num_radios; i++) { + pdev =rcu_dereference (ab->pdevs_active[i]); +if (pdev && pdev->ar) { + arvif =ath11k_mac_get_arvif (pdev->ar, vdev_id); +if (arvif) +return arvif; + } + } + +return NULL ; +} + +struct ath11k *ath11k_mac_get_ar_by_vdev_id (struct ath11k_base *ab,u32 vdev_id) +{ +int i; +struct ath11k_pdev *pdev; +struct ath11k_vif *arvif; + +for (i =0 ; i < ab->num_radios; i++) { + pdev =rcu_dereference (ab->pdevs_active[i]); +if (pdev && pdev->ar) { + arvif =ath11k_mac_get_arvif (pdev->ar, vdev_id); +if (arvif) +return arvif->ar; + } + } + +return NULL ; +} + +struct ath11k *ath11k_mac_get_ar_by_pdev_id (struct ath11k_base *ab,u32 pdev_id) +{ +int i; +struct ath11k_pdev *pdev; + +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 ; +} + +struct ath11k *ath11k_mac_get_ar_vdev_stop_status (struct ath11k_base *ab, +u32 vdev_id) +{ +int i; +struct ath11k_pdev *pdev; +struct ath11k *ar; + +for (i =0 ; i < ab->num_radios; i++) { + pdev =rcu_dereference (ab->pdevs_active[i]); +if (pdev && pdev->ar) { + ar = pdev->ar; + +spin_lock_bh (&ar->data_lock); +if (ar->vdev_stop_status.stop_in_progress && + ar->vdev_stop_status.vdev_id == vdev_id) { + ar->vdev_stop_status.stop_in_progress = false; +spin_unlock_bh (&ar->data_lock); +return ar; + } +spin_unlock_bh (&ar->data_lock); + } + } +return NULL ; +} + +static void ath11k_pdev_caps_update (struct ath11k *ar) +{ +struct ath11k_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 ath11k_mac_txpower_recalc (struct ath11k *ar) +{ +struct ath11k_pdev *pdev = ar->pdev; +struct ath11k_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 ; + +ath11k_dbg (ar->ab,ATH11K_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 =ath11k_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 =ath11k_wmi_pdev_set_param (ar, param, + txpower, ar->pdev->pdev_id); +if (ret) + goto fail; + ar->txpower_limit_5g = txpower; + } + +return 0 ; + +fail: +ath11k_warn (ar->ab,"failed to recalc txpower limit %d using pdev param %d: %d\n" , + txpower /2 , param, ret); +return ret; +} + +static int ath11k_recalc_rtscts_prot (struct ath11k_vif *arvif) +{ +struct ath11k *ar = arvif->ar; +u32 vdev_param, rts_cts =0 ; +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; + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac vdev %d recalc rts/cts prot %d\n" , + arvif->vdev_id, rts_cts); + + ret =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + vdev_param, rts_cts); +if (ret) +ath11k_warn (ar->ab,"failed to recalculate rts/cts prot for vdev %d: %d\n" , + arvif->vdev_id, ret); + +return ret; +} + +static int ath11k_mac_set_kickout (struct ath11k_vif *arvif) +{ +struct ath11k *ar = arvif->ar; +u32 param; +int ret; + + ret =ath11k_wmi_pdev_set_param (ar,WMI_PDEV_PARAM_STA_KICKOUT_TH , +ATH11K_KICKOUT_THRESHOLD , + ar->pdev->pdev_id); +if (ret) { +ath11k_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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, param, +ATH11K_KEEPALIVE_MIN_IDLE ); +if (ret) { +ath11k_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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, param, +ATH11K_KEEPALIVE_MAX_IDLE ); +if (ret) { +ath11k_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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, param, +ATH11K_KEEPALIVE_MAX_UNRESPONSIVE ); +if (ret) { +ath11k_warn (ar->ab,"failed to set keepalive maximum unresponsive time on vdev %i: %d\n" , + arvif->vdev_id, ret); +return ret; + } + +return 0 ; +} + +void ath11k_mac_peer_cleanup_all (struct ath11k *ar) +{ +struct ath11k_peer *peer, *tmp; +struct ath11k_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) { +ath11k_peer_rx_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 ath11k_monitor_vdev_up (struct ath11k *ar,int vdev_id) +{ +int ret =0 ; + + ret =ath11k_wmi_vdev_up (ar, vdev_id,0 , ar->mac_addr); +if (ret) { +ath11k_warn (ar->ab,"failed to put up monitor vdev %i: %d\n" , + vdev_id, ret); +return ret; + } + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac monitor vdev %i started\n" , + vdev_id); +return 0 ; +} + +static int ath11k_mac_op_config (struct ieee80211_hw *hw,u32 changed) +{ +struct ath11k *ar = hw->priv; +int ret =0 ; + +/* mac80211 requires this op to be present and that's why +* there's an empty function, this can be extended when +* required. +*/ + +mutex_lock (&ar->conf_mutex); + +/* TODO: Handle configuration changes as appropriate */ + +mutex_unlock (&ar->conf_mutex); + +return ret; +} + +static int ath11k_mac_setup_bcn_tmpl (struct ath11k_vif *arvif) +{ +struct ath11k *ar = arvif->ar; +struct ath11k_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; +int ret; + +if (arvif->vdev_type !=WMI_VDEV_TYPE_AP ) +return 0 ; + + bcn =ieee80211_beacon_get_template (hw, vif, &offs); +if (!bcn) { +ath11k_warn (ab,"failed to get beacon template from mac80211\n" ); +return -EPERM ; + } + + ret =ath11k_wmi_bcn_tmpl (ar, arvif->vdev_id, &offs, bcn); + +kfree_skb (bcn); + +if (ret) +ath11k_warn (ab,"failed to submit beacon template command: %d\n" , + ret); + +return ret; +} + +static void ath11k_control_beaconing (struct ath11k_vif *arvif, +struct ieee80211_bss_conf *info) +{ +struct ath11k *ar = arvif->ar; +int ret =0 ; + +lockdep_assert_held (&arvif->ar->conf_mutex); + +if (!info->enable_beacon) { + ret =ath11k_wmi_vdev_down (ar, arvif->vdev_id); +if (ret) +ath11k_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 =ath11k_mac_setup_bcn_tmpl (arvif); +if (ret) { +ath11k_warn (ar->ab,"failed to update bcn tmpl during vdev up: %d\n" , + ret); +return ; + } + + arvif->tx_seq_no =0x1000 ; + + arvif->aid =0 ; + +ether_addr_copy (arvif->bssid, info->bssid); + + ret =ath11k_wmi_vdev_up (arvif->ar, arvif->vdev_id, arvif->aid, + arvif->bssid); +if (ret) { +ath11k_warn (ar->ab,"failed to bring up vdev %d: %i\n" , + arvif->vdev_id, ret); +return ; + } + + arvif->is_up = true; + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac vdev %d up\n" , arvif->vdev_id); +} + +static void ath11k_peer_assoc_h_basic (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +struct ath11k_vif *arvif = (void *)vif->drv_priv; +u32 aid; + +lockdep_assert_held (&ar->conf_mutex); + +if (vif->type ==NL80211_IFTYPE_STATION ) + aid = vif->bss_conf.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 ath11k_peer_assoc_h_crypto (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +struct ieee80211_bss_conf *info = &vif->bss_conf; +struct cfg80211_chan_def def; +struct cfg80211_bss *bss; +const u8 *rsnie =NULL ; +const u8 *wpaie =NULL ; + +lockdep_assert_held (&ar->conf_mutex); + +if (WARN_ON (ath11k_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 (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) { +ath11k_dbg (ar->ab,ATH11K_DBG_WMI , +"%s: rsn ie found\n" , __func__); + arg->need_ptk_4_way = true; + } + +if (wpaie) { +ath11k_dbg (ar->ab,ATH11K_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 ath11k_peer_assoc_h_rates (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +struct ath11k_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 (ath11k_mac_vif_chan (vif, &def))) +return ; + + band = def.chan->band; + sband = ar->hw->wiphy->bands[band]; + ratemask = sta->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 =ath11k_mac_bitrate_to_rate (rates->bitrate); + rateset->rates[rateset->num_rates] = rate; + rateset->num_rates++; + } +} + +static bool +ath11k_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 +ath11k_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 ath11k_peer_assoc_h_ht (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; +struct ath11k_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 (ath11k_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 (ath11k_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 = +ath11k_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->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->rx_nss, max_nss); + } + +ath11k_dbg (ar->ab,ATH11K_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 ath11k_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 +ath11k_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 =ath11k_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 :/* fall through */ +case 1 :/* fall through */ +case 2 :/* fall through */ +case 3 :/* fall through */ +case 4 :/* fall through */ +case 5 :/* fall through */ +case 6 :/* fall through */ +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 ); +/* fall through */ +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 ath11k_peer_assoc_h_vht (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; +struct ath11k_vif *arvif = (void *)vif->drv_priv; +struct cfg80211_chan_def def; +enum nl80211_band band; +const u16 *vht_mcs_mask; +u8 ampdu_factor; +u8 max_nss, vht_mcs; +int i; + +if (WARN_ON (ath11k_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 (ath11k_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->bandwidth ==IEEE80211_STA_RX_BW_80 ) + arg->bw_80 = true; + +if (sta->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->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); + arg->tx_mcs_set =ath11k_peer_assoc_h_vht_limit ( +__le16_to_cpu (vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask); + +/* In IPQ8074 platform, VHT mcs rate 10 and 11 is enabled by default. +* VHT mcs rate 10 and 11 is not suppoerted 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 ; + +/* TODO: Check */ + arg->tx_max_mcs_nss =0xFF ; + +ath11k_dbg (ar->ab,ATH11K_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 ath11k_peer_assoc_h_he (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +/* TODO: Implementation */ +} + +static void ath11k_peer_assoc_h_smps (struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +const struct ieee80211_sta_ht_cap *ht_cap = &sta->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 ath11k_peer_assoc_h_qos (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +struct ath11k_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 ; + } + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac peer %pM qos %d\n" , + sta->addr, arg->qos_flag); +} + +static int ath11k_peer_assoc_qos_ap (struct ath11k *ar, +struct ath11k_vif *arvif, +struct ieee80211_sta *sta) +{ +struct ap_ps_params params; +u32 max_sp; +u32 uapsd; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + + params.vdev_id = arvif->vdev_id; + +ath11k_dbg (ar->ab,ATH11K_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; + + params.param =WMI_AP_PS_PEER_PARAM_UAPSD ; + params.value = uapsd; + ret =ath11k_wmi_send_set_ap_ps_param_cmd (ar, sta->addr, ¶ms); +if (ret) + goto err; + + params.param =WMI_AP_PS_PEER_PARAM_MAX_SP ; + params.value = max_sp; + ret =ath11k_wmi_send_set_ap_ps_param_cmd (ar, sta->addr, ¶ms); +if (ret) + goto err; + +/* TODO revisit during testing */ + params.param =WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE ; + params.value =DISABLE_SIFS_RESPONSE_TRIGGER ; + ret =ath11k_wmi_send_set_ap_ps_param_cmd (ar, sta->addr, ¶ms); +if (ret) + goto err; + + params.param =WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD ; + params.value =DISABLE_SIFS_RESPONSE_TRIGGER ; + ret =ath11k_wmi_send_set_ap_ps_param_cmd (ar, sta->addr, ¶ms); +if (ret) + goto err; + +return 0 ; + +err: +ath11k_warn (ar->ab,"failed to set ap ps peer param %d for vdev %i: %d\n" , + params.param, arvif->vdev_id, ret); +return ret; +} + +static bool ath11k_mac_sta_has_ofdm_only (struct ieee80211_sta *sta) +{ +return sta->supp_rates[NL80211_BAND_2GHZ ] >> +ATH11K_MAC_FIRST_OFDM_RATE_IDX ; +} + +static enum wmi_phy_mode ath11k_mac_get_phymode_vht (struct ath11k *ar, +struct ieee80211_sta *sta) +{ +if (sta->bandwidth ==IEEE80211_STA_RX_BW_160 ) { +switch (sta->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->bandwidth ==IEEE80211_STA_RX_BW_80 ) +return MODE_11AC_VHT80 ; + +if (sta->bandwidth ==IEEE80211_STA_RX_BW_40 ) +return MODE_11AC_VHT40 ; + +if (sta->bandwidth ==IEEE80211_STA_RX_BW_20 ) +return MODE_11AC_VHT20 ; + +return MODE_UNKNOWN ; +} + +static void ath11k_peer_assoc_h_phymode (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *arg) +{ +struct ath11k_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 (ath11k_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->vht_cap.vht_supported && + !ath11k_peer_assoc_h_vht_masked (vht_mcs_mask)) { +if (sta->bandwidth ==IEEE80211_STA_RX_BW_40 ) + phymode =MODE_11AC_VHT40 ; +else + phymode =MODE_11AC_VHT20 ; + }else if (sta->ht_cap.ht_supported && + !ath11k_peer_assoc_h_ht_masked (ht_mcs_mask)) { +if (sta->bandwidth ==IEEE80211_STA_RX_BW_40 ) + phymode =MODE_11NG_HT40 ; +else + phymode =MODE_11NG_HT20 ; + }else if (ath11k_mac_sta_has_ofdm_only (sta)) { + phymode =MODE_11G ; + }else { + phymode =MODE_11B ; + } +/* TODO: HE */ + +break ; +case NL80211_BAND_5GHZ : +/* Check VHT first */ +if (sta->vht_cap.vht_supported && + !ath11k_peer_assoc_h_vht_masked (vht_mcs_mask)) { + phymode =ath11k_mac_get_phymode_vht (ar, sta); + }else if (sta->ht_cap.ht_supported && + !ath11k_peer_assoc_h_ht_masked (ht_mcs_mask)) { +if (sta->bandwidth >=IEEE80211_STA_RX_BW_40 ) + phymode =MODE_11NA_HT40 ; +else + phymode =MODE_11NA_HT20 ; + }else { + phymode =MODE_11A ; + } +/* TODO: HE Phymode */ +break ; +default : +break ; + } + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac peer %pM phymode %s\n" , + sta->addr,ath11k_wmi_phymode_str (phymode)); + + arg->peer_phymode = phymode; +WARN_ON (phymode ==MODE_UNKNOWN ); +} + +static void ath11k_peer_assoc_prepare (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct peer_assoc_params *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; +ath11k_peer_assoc_h_basic (ar, vif, sta, arg); +ath11k_peer_assoc_h_crypto (ar, vif, sta, arg); +ath11k_peer_assoc_h_rates (ar, vif, sta, arg); +ath11k_peer_assoc_h_ht (ar, vif, sta, arg); +ath11k_peer_assoc_h_vht (ar, vif, sta, arg); +ath11k_peer_assoc_h_he (ar, vif, sta, arg); +ath11k_peer_assoc_h_qos (ar, vif, sta, arg); +ath11k_peer_assoc_h_phymode (ar, vif, sta, arg); +ath11k_peer_assoc_h_smps (sta, arg); + +/* TODO: amsdu_disable req? */ +} + +static int ath11k_setup_peer_smps (struct ath11k *ar,struct ath11k_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 (ath11k_smps_map)) +return -EINVAL ; + +return ath11k_wmi_set_peer_param (ar, addr, arvif->vdev_id, +WMI_PEER_MIMO_PS_STATE , + ath11k_smps_map[smps]); +} + +static void ath11k_bss_assoc (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_bss_conf *bss_conf) +{ +struct ath11k *ar = hw->priv; +struct ath11k_vif *arvif = (void *)vif->drv_priv; +struct peer_assoc_params peer_arg; +struct ieee80211_sta *ap_sta; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +ath11k_dbg (ar->ab,ATH11K_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) { +ath11k_warn (ar->ab,"failed to find station entry for bss %pM vdev %i\n" , + bss_conf->bssid, arvif->vdev_id); +rcu_read_unlock (); +return ; + } + +ath11k_peer_assoc_prepare (ar, vif, ap_sta, &peer_arg, false); + +rcu_read_unlock (); + + ret =ath11k_wmi_send_peer_assoc_cmd (ar, &peer_arg); +if (ret) { +ath11k_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 )) { +ath11k_warn (ar->ab,"failed to get peer assoc conf event for %pM vdev %i\n" , + bss_conf->bssid, arvif->vdev_id); +return ; + } + + ret =ath11k_setup_peer_smps (ar, arvif, bss_conf->bssid, + &ap_sta->ht_cap); +if (ret) { +ath11k_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 = bss_conf->aid; +ether_addr_copy (arvif->bssid, bss_conf->bssid); + + ret =ath11k_wmi_vdev_up (ar, arvif->vdev_id, arvif->aid, arvif->bssid); +if (ret) { +ath11k_warn (ar->ab,"failed to set vdev %d up: %d\n" , + arvif->vdev_id, ret); +return ; + } + + arvif->is_up = true; + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC , +"mac vdev %d up (associated) bssid %pM aid %d\n" , + arvif->vdev_id, bss_conf->bssid, bss_conf->aid); + +/* Authorize BSS Peer */ + ret =ath11k_wmi_set_peer_param (ar, arvif->bssid, + arvif->vdev_id, +WMI_PEER_AUTHORIZE , +1 ); +if (ret) +ath11k_warn (ar->ab,"Unable to authorize BSS peer: %d\n" , ret); +} + +static void ath11k_bss_disassoc (struct ieee80211_hw *hw, +struct ieee80211_vif *vif) +{ +struct ath11k *ar = hw->priv; +struct ath11k_vif *arvif = (void *)vif->drv_priv; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac vdev %i disassoc bssid %pM\n" , + arvif->vdev_id, arvif->bssid); + + ret =ath11k_wmi_vdev_down (ar, arvif->vdev_id); +if (ret) +ath11k_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 ath11k_mac_get_rate_hw_value (int bitrate) +{ +u32 preamble; +u16 hw_value; +int rate; +size_t i; + +if (ath11k_mac_bitrate_is_cck (bitrate)) + preamble =WMI_RATE_PREAMBLE_CCK ; +else + preamble =WMI_RATE_PREAMBLE_OFDM ; + +for (i =0 ; i <ARRAY_SIZE (ath11k_legacy_rates); i++) { +if (ath11k_legacy_rates[i].bitrate != bitrate) +continue ; + + hw_value = ath11k_legacy_rates[i].hw_value; + rate =ATH11K_HW_RATE_CODE (hw_value,0 , preamble); + +return rate; + } + +return -EINVAL ; +} + +static void ath11k_recalculate_mgmt_rate (struct ath11k *ar, +struct ieee80211_vif *vif, +struct cfg80211_chan_def *def) +{ +struct ath11k_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 =ath11k_mac_get_rate_hw_value (bitrate); +if (hw_rate_code <0 ) { +ath11k_warn (ar->ab,"bitrate not supported %d\n" , bitrate); +return ; + } + + vdev_param =WMI_VDEV_PARAM_MGMT_RATE ; + ret =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, vdev_param, + hw_rate_code); +if (ret) +ath11k_warn (ar->ab,"failed to set mgmt tx rate %d\n" , ret); + + vdev_param =WMI_VDEV_PARAM_BEACON_RATE ; + ret =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, vdev_param, + hw_rate_code); +if (ret) +ath11k_warn (ar->ab,"failed to set beacon tx rate %d\n" , ret); +} + +static void ath11k_mac_op_bss_info_changed (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_bss_conf *info, +u32 changed) +{ +struct ath11k *ar = hw->priv; +struct ath11k_vif *arvif =ath11k_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 =0 ; +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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, + arvif->beacon_interval); +if (ret) +ath11k_warn (ar->ab,"Failed to set beacon interval for VDEV: %d\n" , + arvif->vdev_id); +else +ath11k_dbg (ar->ab,ATH11K_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 =ath11k_wmi_pdev_set_param (ar, param_id, + param_value, ar->pdev->pdev_id); +if (ret) +ath11k_warn (ar->ab,"Failed to set beacon mode for VDEV: %d\n" , + arvif->vdev_id); +else +ath11k_dbg (ar->ab,ATH11K_DBG_MAC , +"Set staggered beacon mode for VDEV: %d\n" , + arvif->vdev_id); + + ret =ath11k_mac_setup_bcn_tmpl (arvif); +if (ret) +ath11k_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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, + arvif->dtim_period); + +if (ret) +ath11k_warn (ar->ab,"Failed to set dtim period for VDEV %d: %i\n" , + arvif->vdev_id, ret); +else +ath11k_dbg (ar->ab,ATH11K_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 = info->ssid_len; +if (info->ssid_len) +memcpy (arvif->u.ap.ssid, info->ssid, info->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 ) +ath11k_control_beaconing (arvif, info); + +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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, cts_prot); +if (ret) +ath11k_warn (ar->ab,"Failed to set CTS prot for VDEV: %d\n" , + arvif->vdev_id); +else +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"Set CTS prot: %d for VDEV: %d\n" , + cts_prot, arvif->vdev_id); + }else { +ath11k_dbg (ar->ab,ATH11K_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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, slottime); +if (ret) +ath11k_warn (ar->ab,"Failed to set erp slot for VDEV: %d\n" , + arvif->vdev_id); +else +ath11k_dbg (ar->ab,ATH11K_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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + param_id, preamble); +if (ret) +ath11k_warn (ar->ab,"Failed to set preamble for VDEV: %d\n" , + arvif->vdev_id); +else +ath11k_dbg (ar->ab,ATH11K_DBG_MAC , +"Set preamble: %d for VDEV: %d\n" , + preamble, arvif->vdev_id); + } + +if (changed &BSS_CHANGED_ASSOC ) { +if (info->assoc) +ath11k_bss_assoc (hw, vif, info); +else +ath11k_bss_disassoc (hw, vif); + } + +if (changed &BSS_CHANGED_TXPOWER ) { +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac vdev_id %i txpower %d\n" , + arvif->vdev_id, info->txpower); + + arvif->txpower = info->txpower; +ath11k_mac_txpower_recalc (ar); + } + +if (changed &BSS_CHANGED_MCAST_RATE && + !ath11k_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 +=ATH11K_MAC_FIRST_OFDM_RATE_IDX ; + + bitrate = ath11k_legacy_rates[rateidx].bitrate; + hw_value = ath11k_legacy_rates[rateidx].hw_value; + +if (ath11k_mac_bitrate_is_cck (bitrate)) + preamble =WMI_RATE_PREAMBLE_CCK ; +else + preamble =WMI_RATE_PREAMBLE_OFDM ; + + rate =ATH11K_HW_RATE_CODE (hw_value,0 , preamble); + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC , +"mac vdev %d mcast_rate %x\n" , + arvif->vdev_id, rate); + + vdev_param =WMI_VDEV_PARAM_MCAST_DATA_RATE ; + ret =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + vdev_param, rate); +if (ret) +ath11k_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 =ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + vdev_param, rate); +if (ret) +ath11k_warn (ar->ab, +"failed to set bcast rate on vdev %i: %d\n" , + arvif->vdev_id, ret); + } + +if (changed &BSS_CHANGED_BASIC_RATES && + !ath11k_mac_vif_chan (arvif->vif, &def)) +ath11k_recalculate_mgmt_rate (ar, vif, &def); + +mutex_unlock (&ar->conf_mutex); +} + +void __ath11k_mac_scan_finish (struct ath11k *ar) +{ +lockdep_assert_held (&ar->data_lock); + +switch (ar->scan.state) { +case ATH11K_SCAN_IDLE : +break ; +case ATH11K_SCAN_RUNNING : +case ATH11K_SCAN_ABORTING : +if (!ar->scan.is_roc) { +struct cfg80211_scan_info info = { + .aborted = (ar->scan.state == +ATH11K_SCAN_ABORTING ), + }; + +ieee80211_scan_completed (ar->hw, &info); + }else if (ar->scan.roc_notify) { +ieee80211_remain_on_channel_expired (ar->hw); + } +/* fall through */ +case ATH11K_SCAN_STARTING : + ar->scan.state =ATH11K_SCAN_IDLE ; + ar->scan_channel =NULL ; + ar->scan.roc_freq =0 ; +cancel_delayed_work (&ar->scan.timeout); +complete (&ar->scan.completed); +break ; + } +} + +void ath11k_mac_scan_finish (struct ath11k *ar) +{ +spin_lock_bh (&ar->data_lock); +__ath11k_mac_scan_finish (ar); +spin_unlock_bh (&ar->data_lock); +} + +static int ath11k_scan_stop (struct ath11k *ar) +{ +struct scan_cancel_param arg = { + .req_type =WLAN_SCAN_CANCEL_SINGLE , + .scan_id =ATH11K_SCAN_ID , + }; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +/* TODO: Fill other STOP Params */ + arg.pdev_id = ar->pdev->pdev_id; + + ret =ath11k_wmi_send_scan_stop_cmd (ar, &arg); +if (ret) { +ath11k_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 ) { +ath11k_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 !=ATH11K_SCAN_IDLE ) +__ath11k_mac_scan_finish (ar); +spin_unlock_bh (&ar->data_lock); + +return ret; +} + +static void ath11k_scan_abort (struct ath11k *ar) +{ +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +spin_lock_bh (&ar->data_lock); + +switch (ar->scan.state) { +case ATH11K_SCAN_IDLE : +/* This can happen if timeout worker kicked in and called +* abortion while scan completion was being processed. +*/ +break ; +case ATH11K_SCAN_STARTING : +case ATH11K_SCAN_ABORTING : +ath11k_warn (ar->ab,"refusing scan abortion due to invalid scan state: %d\n" , + ar->scan.state); +break ; +case ATH11K_SCAN_RUNNING : + ar->scan.state =ATH11K_SCAN_ABORTING ; +spin_unlock_bh (&ar->data_lock); + + ret =ath11k_scan_stop (ar); +if (ret) +ath11k_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 ath11k_scan_timeout_work (struct work_struct *work) +{ + struct ath11k *ar = container_of(work, struct ath11k, + scan.timeout.work); + +mutex_lock (&ar->conf_mutex); +ath11k_scan_abort (ar); +mutex_unlock (&ar->conf_mutex); +} + +static int ath11k_start_scan (struct ath11k *ar, +struct scan_req_params *arg) +{ +int ret; + +lockdep_assert_held (&ar->conf_mutex); + + ret =ath11k_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 =ath11k_scan_stop (ar); +if (ret) +ath11k_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 ==ATH11K_SCAN_IDLE ) { +spin_unlock_bh (&ar->data_lock); +return -EINVAL ; + } +spin_unlock_bh (&ar->data_lock); + +return 0 ; +} + +static int ath11k_mac_op_hw_scan (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_scan_request *hw_req) +{ +struct ath11k *ar = hw->priv; +struct ath11k_vif *arvif =ath11k_vif_to_arvif (vif); +struct cfg80211_scan_request *req = &hw_req->req; +struct scan_req_params arg; +int ret =0 ; +int i; + +mutex_lock (&ar->conf_mutex); + +spin_lock_bh (&ar->data_lock); +switch (ar->scan.state) { +case ATH11K_SCAN_IDLE : +reinit_completion (&ar->scan.started); +reinit_completion (&ar->scan.completed); + ar->scan.state =ATH11K_SCAN_STARTING ; + ar->scan.is_roc = false; + ar->scan.vdev_id = arvif->vdev_id; + ret =0 ; +break ; +case ATH11K_SCAN_STARTING : +case ATH11K_SCAN_RUNNING : +case ATH11K_SCAN_ABORTING : + ret = -EBUSY ; +break ; + } +spin_unlock_bh (&ar->data_lock); + +if (ret) + goto exit; + +memset (&arg,0 ,sizeof (arg)); +ath11k_wmi_start_scan_init (ar, &arg); + arg.vdev_id = arvif->vdev_id; + arg.scan_id =ATH11K_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].length = req->ssids[i].ssid_len; +memcpy (&arg.ssid[i].ssid, req->ssids[i].ssid, + req->ssids[i].ssid_len); + } + }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 =ath11k_start_scan (ar, &arg); +if (ret) { +ath11k_warn (ar->ab,"failed to start hw scan: %d\n" , ret); +spin_lock_bh (&ar->data_lock); + ar->scan.state =ATH11K_SCAN_IDLE ; +spin_unlock_bh (&ar->data_lock); + } + +/* Add a 200ms margin to account for event/command processing */ +ieee80211_queue_delayed_work (ar->hw, &ar->scan.timeout, +msecs_to_jiffies (arg.max_scan_time + +ATH11K_MAC_SCAN_TIMEOUT_MSECS )); + +exit: +if (req->ie_len) +kfree (arg.extraie.ptr); + +mutex_unlock (&ar->conf_mutex); +return ret; +} + +static void ath11k_mac_op_cancel_hw_scan (struct ieee80211_hw *hw, +struct ieee80211_vif *vif) +{ +struct ath11k *ar = hw->priv; + +mutex_lock (&ar->conf_mutex); +ath11k_scan_abort (ar); +mutex_unlock (&ar->conf_mutex); + +cancel_delayed_work_sync (&ar->scan.timeout); +} + +static int ath11k_install_key (struct ath11k_vif *arvif, +struct ieee80211_key_conf *key, +enum set_key_cmd cmd, +const u8 *macaddr,u32 flags) +{ +int ret; +struct ath11k *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 (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 : +ath11k_warn (ar->ab,"cipher %d is not supported\n" , key->cipher); +return -EOPNOTSUPP ; + } + +install: + ret =ath11k_wmi_vdev_install_key (arvif->ar, &arg); +if (ret) +return ret; + +if (!wait_for_completion_timeout (&ar->install_key_done,1 *HZ )) +return -ETIMEDOUT ; + +return ar->install_key_status ? -EINVAL :0 ; +} + +static int ath11k_clear_peer_keys (struct ath11k_vif *arvif, +const u8 *addr) +{ +struct ath11k *ar = arvif->ar; +struct ath11k_base *ab = ar->ab; +struct ath11k_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 =ath11k_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 =ath11k_install_key (arvif, peer->keys[i], +DISABLE_KEY , addr, flags); +if (ret <0 && first_errno ==0 ) + first_errno = ret; + +if (ret <0 ) +ath11k_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 ath11k_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 ath11k *ar = hw->priv; +struct ath11k_base *ab = ar->ab; +struct ath11k_vif *arvif =ath11k_vif_to_arvif (vif); +struct ath11k_peer *peer; +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 (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 =ath11k_peer_find (ab, arvif->vdev_id, peer_addr); +spin_unlock_bh (&ab->base_lock); + +if (!peer) { +if (cmd ==SET_KEY ) { +ath11k_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 =ath11k_install_key (arvif, key, cmd, peer_addr, flags); +if (ret) { +ath11k_warn (ab,"ath11k_install_key failed (%d)\n" , ret); + goto exit; + } + +spin_lock_bh (&ab->base_lock); + peer =ath11k_peer_find (ab, arvif->vdev_id, peer_addr); +if (peer && cmd ==SET_KEY ) + peer->keys[key->keyidx] = key; +else if (peer && cmd ==DISABLE_KEY ) + peer->keys[key->keyidx] =NULL ; +else if (!peer) +/* impossible unless FW goes crazy */ +ath11k_warn (ab,"peer %pM disappeared!\n" , peer_addr); +spin_unlock_bh (&ab->base_lock); + +exit: +mutex_unlock (&ar->conf_mutex); +return ret; +} + +static int +ath11k_mac_bitrate_mask_num_vht_rates (struct ath11k *ar, +enum nl80211_band band, +const struct cfg80211_bitrate_mask *mask) +{ +int num_rates =0 ; +int i; + +for (i =0 ; i <ARRAY_SIZE (mask->control[band].vht_mcs); i++) + num_rates +=hweight16 (mask->control[band].vht_mcs[i]); + +return num_rates; +} + +static int +ath11k_mac_set_peer_vht_fixed_rate (struct ath11k_vif *arvif, +struct ieee80211_sta *sta, +const struct cfg80211_bitrate_mask *mask, +enum nl80211_band band) +{ +struct ath11k *ar = arvif->ar; +u8 vht_rate, nss; +u32 rate_code; +int ret, i; + +lockdep_assert_held (&ar->conf_mutex); + + nss =0 ; + +for (i =0 ; i <ARRAY_SIZE (mask->control[band].vht_mcs); i++) { +if (hweight16 (mask->control[band].vht_mcs[i]) ==1 ) { + nss = i +1 ; + vht_rate =ffs (mask->control[band].vht_mcs[i]) -1 ; + } + } + +if (!nss) { +ath11k_warn (ar->ab,"No single VHT Fixed rate found to set for %pM" , + sta->addr); +return -EINVAL ; + } + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC , +"Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates" , + sta->addr); + + rate_code =ATH11K_HW_RATE_CODE (vht_rate, nss -1 , +WMI_RATE_PREAMBLE_VHT ); + ret =ath11k_wmi_set_peer_param (ar, sta->addr, + arvif->vdev_id, +WMI_PEER_PARAM_FIXED_RATE , + rate_code); +if (ret) +ath11k_warn (ar->ab, +"failed to update STA %pM Fixed Rate %d: %d\n" , + sta->addr, rate_code, ret); + +return ret; +} + +static int ath11k_station_assoc (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +bool reassoc) +{ +struct ath11k_vif *arvif =ath11k_vif_to_arvif (vif); +struct peer_assoc_params peer_arg; +int ret =0 ; +struct cfg80211_chan_def def; +enum nl80211_band band; +struct cfg80211_bitrate_mask *mask; +u8 num_vht_rates; + +lockdep_assert_held (&ar->conf_mutex); + +if (WARN_ON (ath11k_mac_vif_chan (vif, &def))) +return -EPERM ; + + band = def.chan->band; + mask = &arvif->bitrate_mask; + +ath11k_peer_assoc_prepare (ar, vif, sta, &peer_arg, reassoc); + + ret =ath11k_wmi_send_peer_assoc_cmd (ar, &peer_arg); +if (ret) { +ath11k_warn (ar->ab,"failed to run peer assoc for STA %pM vdev %i: %d\n" , + sta->addr, arvif->vdev_id, ret); +return ret; + } + +if (!wait_for_completion_timeout (&ar->peer_assoc_done,1 *HZ )) { +ath11k_warn (ar->ab,"failed to get peer assoc conf event for %pM vdev %i\n" , + sta->addr, arvif->vdev_id); +return -ETIMEDOUT ; + } + + num_vht_rates =ath11k_mac_bitrate_mask_num_vht_rates (ar, band, mask); + +/* If single VHT rate is configured (by set_bitrate_mask()), +* peer_assoc will disable VHT. This is now enabled by a peer specific +* fixed param. +* Note that all other rates and NSS will be disabled for this peer. +*/ +if (sta->vht_cap.vht_supported && num_vht_rates ==1 ) { + ret =ath11k_mac_set_peer_vht_fixed_rate (arvif, sta, mask, + band); +if (ret) +return ret; + } + +/* Re-assoc is run only to update supported rates for given station. It +* doesn't make much sense to reconfigure the peer completely. +*/ +if (reassoc) +return 0 ; + + ret =ath11k_setup_peer_smps (ar, arvif, sta->addr, + &sta->ht_cap); +if (ret) { +ath11k_warn (ar->ab,"failed to setup peer SMPS for vdev %d: %d\n" , + arvif->vdev_id, ret); +return ret; + } + +if (!sta->wme) { + arvif->num_legacy_stations++; + ret =ath11k_recalc_rtscts_prot (arvif); +if (ret) +return ret; + } + +if (sta->wme && sta->uapsd_queues) { + ret =ath11k_peer_assoc_qos_ap (ar, arvif, sta); +if (ret) { +ath11k_warn (ar->ab,"failed to set qos params for STA %pM for vdev %i: %d\n" , + sta->addr, arvif->vdev_id, ret); +return ret; + } + } + +return 0 ; +} + +static int ath11k_station_disassoc (struct ath11k *ar, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +struct ath11k_vif *arvif = (void *)vif->drv_priv; +int ret =0 ; + +lockdep_assert_held (&ar->conf_mutex); + +if (!sta->wme) { + arvif->num_legacy_stations--; + ret =ath11k_recalc_rtscts_prot (arvif); +if (ret) +return ret; + } + + ret =ath11k_clear_peer_keys (arvif, sta->addr); +if (ret) { +ath11k_warn (ar->ab,"failed to clear all peer keys for vdev %i: %d\n" , + arvif->vdev_id, ret); +return ret; + } +return 0 ; +} + +static void ath11k_sta_rc_update_wk (struct work_struct *wk) +{ +struct ath11k *ar; +struct ath11k_vif *arvif; +struct ath11k_sta *arsta; +struct ieee80211_sta *sta; +struct cfg80211_chan_def def; +enum nl80211_band band; +const u8 *ht_mcs_mask; +const u16 *vht_mcs_mask; +u32 changed, bw, nss, smps; +int err, num_vht_rates; +const struct cfg80211_bitrate_mask *mask; +struct peer_assoc_params peer_arg; + + arsta = container_of(wk, struct ath11k_sta, update_wk); + sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); + arvif = arsta->arvif; + ar = arvif->ar; + +if (WARN_ON (ath11k_mac_vif_chan (arvif->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; + +spin_lock_bh (&ar->data_lock); + + changed = arsta->changed; + arsta->changed =0 ; + + bw = arsta->bw; + nss = arsta->nss; + smps = arsta->smps; + +spin_unlock_bh (&ar->data_lock); + +mutex_lock (&ar->conf_mutex); + + nss =max_t (u32,1 , nss); + nss =min (nss,max (ath11k_mac_max_ht_nss (ht_mcs_mask), +ath11k_mac_max_vht_nss (vht_mcs_mask))); + +if (changed &IEEE80211_RC_BW_CHANGED ) { + err =ath11k_wmi_set_peer_param (ar, sta->addr, arvif->vdev_id, +WMI_PEER_CHWIDTH , bw); +if (err) +ath11k_warn (ar->ab,"failed to update STA %pM peer bw %d: %d\n" , + sta->addr, bw, err); + } + +if (changed &IEEE80211_RC_NSS_CHANGED ) { +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac update sta %pM nss %d\n" , + sta->addr, nss); + + err =ath11k_wmi_set_peer_param (ar, sta->addr, arvif->vdev_id, +WMI_PEER_NSS , nss); +if (err) +ath11k_warn (ar->ab,"failed to update STA %pM nss %d: %d\n" , + sta->addr, nss, err); + } + +if (changed &IEEE80211_RC_SMPS_CHANGED ) { +ath11k_dbg (ar->ab,ATH11K_DBG_MAC ,"mac update sta %pM smps %d\n" , + sta->addr, smps); + + err =ath11k_wmi_set_peer_param (ar, sta->addr, arvif->vdev_id, +WMI_PEER_MIMO_PS_STATE , smps); +if (err) +ath11k_warn (ar->ab,"failed to update STA %pM smps %d: %d\n" , + sta->addr, smps, err); + } + +if (changed &IEEE80211_RC_SUPP_RATES_CHANGED ) { + mask = &arvif->bitrate_mask; + num_vht_rates =ath11k_mac_bitrate_mask_num_vht_rates (ar, band, + mask); + +/* Peer_assoc_prepare will reject vht rates in +* bitrate_mask if its not available in range format and +* sets vht tx_rateset as unsupported. So multiple VHT MCS +* setting(eg. MCS 4,5,6) per peer is not supported here. +* But, Single rate in VHT mask can be set as per-peer +* fixed rate. But even if any HT rates are configured in +* the bitrate mask, device will not switch to those rates +* when per-peer Fixed rate is set. +* TODO: Check RATEMASK_CMDID to support auto rates selection +* across HT/VHT and for multiple VHT MCS support. +*/ +if (sta->vht_cap.vht_supported && num_vht_rates ==1 ) { +ath11k_mac_set_peer_vht_fixed_rate (arvif, sta, mask, + band); + }else { +/* If the peer is non-VHT or no fixed VHT rate +* is provided in the new bitrate mask we set the +* other rates using peer_assoc command. +*/ +ath11k_peer_assoc_prepare (ar, arvif->vif, sta, + &peer_arg, true); + + err =ath11k_wmi_send_peer_assoc_cmd (ar, &peer_arg); +if (err) +ath11k_warn (ar->ab,"failed to run peer assoc for STA %pM vdev %i: %d\n" , + sta->addr, arvif->vdev_id, err); + +if (!wait_for_completion_timeout (&ar->peer_assoc_done,1 *HZ )) +ath11k_warn (ar->ab,"failed to get peer assoc conf event for %pM vdev %i\n" , + sta->addr, arvif->vdev_id); + } + } + +mutex_unlock (&ar->conf_mutex); +} + +static int ath11k_mac_inc_num_stations (struct ath11k_vif *arvif, +struct ieee80211_sta *sta) +{ +struct ath11k *ar = arvif->ar; + +lockdep_assert_held (&ar->conf_mutex); + +if (arvif->vdev_type ==WMI_VDEV_TYPE_STA && !sta->tdls) +return 0 ; + +if (ar->num_stations >= ar->max_num_stations) +return -ENOBUFS ; + + ar->num_stations++; + +return 0 ; +} + +static void ath11k_mac_dec_num_stations (struct ath11k_vif *arvif, +struct ieee80211_sta *sta) +{ +struct ath11k *ar = arvif->ar; + +lockdep_assert_held (&ar->conf_mutex); + +if (arvif->vdev_type ==WMI_VDEV_TYPE_STA && !sta->tdls) +return ; + + ar->num_stations--; +} + +static int ath11k_mac_op_sta_state (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +enum ieee80211_sta_state old_state, +enum ieee80211_sta_state new_state) +{ +struct ath11k *ar = hw->priv; +struct ath11k_vif *arvif =ath11k_vif_to_arvif (vif); +struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; +struct peer_create_params peer_param; +int ret =0 ; + +/* cancel must be done outside the mutex to avoid deadlock */ +if ((old_state ==IEEE80211_STA_NONE && + new_state ==IEEE80211_STA_NOTEXIST )) +cancel_work_sync (&arsta->update_wk); + +mutex_lock (&ar->conf_mutex); + +if (old_state ==IEEE80211_STA_NOTEXIST && + new_state ==IEEE80211_STA_NONE ) { +memset (arsta,0 ,sizeof (*arsta)); + arsta->arvif = arvif; +INIT_WORK (&arsta->update_wk, ath11k_sta_rc_update_wk); + + ret =ath11k_mac_inc_num_stations (arvif, sta); +if (ret) { +ath11k_warn (ar->ab,"refusing to associate station: too many connected already (%d)\n" , + ar->max_num_stations); + goto exit; + } + + arsta->rx_stats =kzalloc (sizeof (*arsta->rx_stats),GFP_KERNEL ); +if (!arsta->rx_stats) { + ret = -ENOMEM ; + goto exit; + } + + peer_param.vdev_id = arvif->vdev_id; + peer_param.peer_addr = sta->addr; + peer_param.peer_type =WMI_PEER_TYPE_DEFAULT ; + ret =ath11k_peer_create (ar, arvif, sta, &peer_param); +if (ret) { +ath11k_warn (ar->ab,"Failed to add peer: %pM for VDEV: %d\n" , + sta->addr, arvif->vdev_id); +ath11k_mac_dec_num_stations (arvif, sta); + goto exit; + } + +ath11k_info (ar->ab,"Added peer: %pM for VDEV: %d\n" , + sta->addr, arvif->vdev_id); + +if (ath11k_debug_is_extd_tx_stats_enabled (ar)) { + arsta->tx_stats =kzalloc (sizeof (*arsta->tx_stats), +GFP_KERNEL ); +if (!arsta->tx_stats) { + ret = -ENOMEM ; + goto exit; + } + } + +if (ieee80211_vif_is_mesh (vif)) { + ret =ath11k_wmi_set_peer_param (ar, sta->addr, + arvif->vdev_id, +WMI_PEER_USE_4ADDR ,1 ); +if (ret) { +ath11k_warn (ar->ab,"failed to STA %pM 4addr capability: %d\n" , + sta->addr, ret); + goto exit; + } + } + + ret =ath11k_dp_peer_setup (ar, arvif->vdev_id, sta->addr); +if (ret) { +ath11k_warn (ar->ab,"failed to setup dp for peer %pM on vdev %i (%d)\n" , + sta->addr, arvif->vdev_id, ret); +ath11k_peer_delete (ar, arvif->vdev_id, sta->addr); +ath11k_mac_dec_num_stations (arvif, sta); + } + }else if ((old_state ==IEEE80211_STA_NONE && + new_state ==IEEE80211_STA_NOTEXIST )) { +ath11k_dp_peer_cleanup (ar, arvif->vdev_id, sta->addr); + + ret =ath11k_peer_delete (ar, arvif->vdev_id, sta->addr); +if (ret) +ath11k_warn (ar->ab,"Failed to delete peer: %pM for VDEV: %d\n" , + sta->addr, arvif->vdev_id); +else +ath11k_info (ar->ab, +"Removed peer: %pM for VDEV: %d\n" , + sta->addr, arvif->vdev_id); + +ath11k_mac_dec_num_stations (arvif, sta); + +kfree (arsta->tx_stats); + arsta->tx_stats =NULL ; + +kfree (arsta->rx_stats); + arsta->rx_stats =NULL ; + }else if (old_state ==IEEE80211_STA_AUTH && + new_state ==IEEE80211_STA_ASSOC && + (vif->type ==NL80211_IFTYPE_AP || + vif->type ==NL80211_IFTYPE_MESH_POINT || + vif->type ==NL80211_IFTYPE_ADHOC )) { + ret =ath11k_station_assoc (ar, vif, sta, false); +if (ret) +ath11k_warn (ar->ab,"Failed to associate station: %pM\n" , + sta->addr); +else +ath11k_info (ar->ab, +"Station %pM moved to assoc state\n" , + sta->addr); + }else if (old_state ==IEEE80211_STA_ASSOC && + new_state ==IEEE80211_STA_AUTH && + (vif->type ==NL80211_IFTYPE_AP || + vif->type ==NL80211_IFTYPE_MESH_POINT || + vif->type ==NL80211_IFTYPE_ADHOC )) { + ret =ath11k_station_disassoc (ar, vif, sta); +if (ret) +ath11k_warn (ar->ab,"Failed to disassociate station: %pM\n" , + sta->addr); +else +ath11k_info (ar->ab, +"Station %pM moved to disassociated state\n" , + sta->addr); + } + +exit: +mutex_unlock (&ar->conf_mutex); +return ret; +} + +static void ath11k_mac_op_sta_rc_update (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +u32 changed) +{ +struct ath11k *ar = hw->priv; +struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; +struct ath11k_vif *arvif = (void *)vif->drv_priv; +struct ath11k_peer *peer; +u32 bw, smps; + +spin_lock_bh (&ar->ab->base_lock); + + peer =ath11k_peer_find (ar->ab, arvif->vdev_id, sta->addr); +if (!peer) { +spin_unlock_bh (&ar->ab->base_lock); +ath11k_warn (ar->ab,"mac sta rc update failed to find peer %pM on vdev %i\n" , + sta->addr, arvif->vdev_id); +return ; + } + +spin_unlock_bh (&ar->ab->base_lock); + +ath11k_dbg (ar->ab,ATH11K_DBG_MAC , +"mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n" , + sta->addr, changed, sta->bandwidth, sta->rx_nss, + sta->smps_mode); + +spin_lock_bh (&ar->data_lock); + +if (changed &IEEE80211_RC_BW_CHANGED ) { + bw =WMI_PEER_CHWIDTH_20MHZ ; + +switch (sta->bandwidth) { +case IEEE80211_STA_RX_BW_20 : + bw =WMI_PEER_CHWIDTH_20MHZ ; +break ; +case IEEE80211_STA_RX_BW_40 : + bw =WMI_PEER_CHWIDTH_40MHZ ; +break ; +case IEEE80211_STA_RX_BW_80 : + bw =WMI_PEER_CHWIDTH_80MHZ ; +break ; +case IEEE80211_STA_RX_BW_160 : + bw =WMI_PEER_CHWIDTH_160MHZ ; +break ; +default : +ath11k_warn (ar->ab,"Invalid bandwidth %d in rc update for %pM\n" , + sta->bandwidth, sta->addr); + bw =WMI_PEER_CHWIDTH_20MHZ ; +break ; + } + + arsta->bw = bw; + } + +if (changed &IEEE80211_RC_NSS_CHANGED ) + arsta->nss = sta->rx_nss; + +if (changed &IEEE80211_RC_SMPS_CHANGED ) { + smps =WMI_PEER_SMPS_PS_NONE ; + +switch (sta->smps_mode) { +case IEEE80211_SMPS_AUTOMATIC : +case IEEE80211_SMPS_OFF : + smps =WMI_PEER_SMPS_PS_NONE ; +break ; +case IEEE80211_SMPS_STATIC : + smps =WMI_PEER_SMPS_STATIC ; +break ; +case IEEE80211_SMPS_DYNAMIC : + smps =WMI_PEER_SMPS_DYNAMIC ; +break ; +default : +ath11k_warn (ar->ab,"Invalid smps %d in sta rc update for %pM\n" , + sta->smps_mode, sta->addr); + smps =WMI_PEER_SMPS_PS_NONE ; +break ; + } + + arsta->smps = smps; + } + + arsta->changed |= changed; + +spin_unlock_bh (&ar->data_lock); + +ieee80211_queue_work (hw, &arsta->update_wk); +} + +static int ath11k_conf_tx_uapsd (struct ath11k *ar,struct ieee80211_vif *vif, +u16 ac,bool enable) +{ +struct ath11k_vif *arvif =ath11k_vif_to_arvif (vif); +u32 value =0 ; +int ret =0 ; + +if (arvif->vdev_type !=WMI_VDEV_TYPE_STA ) +return 0 ; + +switch (ac) { +case IEEE80211_AC_VO : + value =WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | +WMI_STA_PS_UAPSD_AC3_TRIGGER_EN ; +break ; +case IEEE80211_AC_VI : + value =WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | +WMI_STA_PS_UAPSD_AC2_TRIGGER_EN ; +break ; +case IEEE80211_AC_BE : + value =WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | +WMI_STA_PS_UAPSD_AC1_TRIGGER_EN ; +break ; +case IEEE80211_AC_BK : + value =WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | +WMI_STA_PS_UAPSD_AC0_TRIGGER_EN ; +break ; + } + +if (enable) + arvif->u.sta.uapsd |= value; +else + arvif->u.sta.uapsd &= ~value; + + ret =ath11k_wmi_set_sta_ps_param (ar, arvif->vdev_id, +WMI_STA_PS_PARAM_UAPSD , + arvif->u.sta.uapsd); +if (ret) { +ath11k_warn (ar->ab,"could not set uapsd params %d\n" , ret); + goto exit; + } + +if (arvif->u.sta.uapsd) + value =WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD ; +else + value =WMI_STA_PS_RX_WAKE_POLICY_WAKE ; + + ret =ath11k_wmi_set_sta_ps_param (ar, arvif->vdev_id, +WMI_STA_PS_PARAM_RX_WAKE_POLICY , + value); +if (ret) +ath11k_warn (ar->ab,"could not set rx wake param %d\n" , ret); + +exit: +return ret; +} + +static int ath11k_mac_op_conf_tx (struct ieee80211_hw *hw, +struct ieee80211_vif *vif,u16 ac, +const struct ieee80211_tx_queue_params *params) +{ +struct ath11k *ar = hw->priv; +struct ath11k_vif *arvif = (void *)vif->drv_priv; +struct wmi_wmm_params_arg *p =NULL ; +int ret; + +mutex_lock (&ar->conf_mutex); + +switch (ac) { +case IEEE80211_AC_VO : + p = &arvif->wmm_params.ac_vo; +break ; +case IEEE80211_AC_VI : + p = &arvif->wmm_params.ac_vi; +break ; +case IEEE80211_AC_BE : + p = &arvif->wmm_params.ac_be; +break ; +case IEEE80211_AC_BK : + p = &arvif->wmm_params.ac_bk; +break ; + } + +if (WARN_ON (!p)) { + ret = -EINVAL ; + goto exit; + } + + p->cwmin = params->cw_min; + p->cwmax = params->cw_max; + p->aifs = params->aifs; + +/* The channel time duration programmed in the HW is in absolute +* microseconds, while mac80211 gives the txop in units of +* 32 microseconds. +*/ + p->txop = params->txop *32 ; + + ret =ath11k_wmi_send_wmm_update_cmd_tlv (ar, arvif->vdev_id, + &arvif->wmm_params); +if (ret) { +ath11k_warn (ar->ab,"failed to set wmm params: %d\n" , ret); + goto exit; + } + + ret =ath11k_conf_tx_uapsd (ar, vif, ac, params->uapsd); + +if (ret) +ath11k_warn (ar->ab,"failed to set sta uapsd: %d\n" , ret); + +exit: +mutex_unlock (&ar->conf_mutex); +return ret; +} + +static struct ieee80211_sta_ht_cap +ath11k_create_ht_cap (struct ath11k *ar,u32 ar_ht_cap,u32 rate_cap_rx_chainmask) +{ +int i; +struct ieee80211_sta_ht_cap ht_cap = {0 }; +u32 ar_vht_cap = ar->pdev->cap.vht_cap; + +if (!(ar_ht_cap &WMI_HT_CAP_ENABLED )) +return ht_cap; + + ht_cap.ht_supported =1 ; + ht_cap.ampdu_factor =IEEE80211_HT_MAX_AMPDU_64K ; + ht_cap.ampdu_density =IEEE80211_HT_MPDU_DENSITY_8 ; + ht_cap.cap |=IEEE80211_HT_CAP_SUP_WIDTH_20_40 ; + ht_cap.cap |=IEEE80211_HT_CAP_DSSSCCK40 ; + ht_cap.cap |=WLAN_HT_CAP_SM_PS_STATIC <<IEEE80211_HT_CAP_SM_PS_SHIFT ; + +if (ar_ht_cap &WMI_HT_CAP_HT20_SGI ) + ht_cap.cap |=IEEE80211_HT_CAP_SGI_20 ; + +if (ar_ht_cap &WMI_HT_CAP_HT40_SGI ) + ht_cap.cap |=IEEE80211_HT_CAP_SGI_40 ; + +if (ar_ht_cap &WMI_HT_CAP_DYNAMIC_SMPS ) { +u32 smps; + + smps =WLAN_HT_CAP_SM_PS_DYNAMIC ; + smps <<=IEEE80211_HT_CAP_SM_PS_SHIFT ; + + ht_cap.cap |= smps; + } + +if (ar_ht_cap &WMI_HT_CAP_TX_STBC ) + ht_cap.cap |=IEEE80211_HT_CAP_TX_STBC ; + +if (ar_ht_cap &WMI_HT_CAP_RX_STBC ) { +u32 stbc; + + stbc = ar_ht_cap; + stbc &=WMI_HT_CAP_RX_STBC ; + stbc >>=WMI_HT_CAP_RX_STBC_MASK_SHIFT ; + stbc <<=IEEE80211_HT_CAP_RX_STBC_SHIFT ; + stbc &=IEEE80211_HT_CAP_RX_STBC ; + + ht_cap.cap |= stbc; + } + +if (ar_ht_cap &WMI_HT_CAP_RX_LDPC ) + ht_cap.cap |=IEEE80211_HT_CAP_LDPC_CODING ; + +if (ar_ht_cap &WMI_HT_CAP_L_SIG_TXOP_PROT ) + ht_cap.cap |=IEEE80211_HT_CAP_LSIG_TXOP_PROT ; + +if (ar_vht_cap &WMI_VHT_CAP_MAX_MPDU_LEN_MASK ) + ht_cap.cap |=IEEE80211_HT_CAP_MAX_AMSDU ; + +for (i =0 ; i < ar->num_rx_chains; i++) { +if (rate_cap_rx_chainmask &BIT (i)) + ht_cap.mcs.rx_mask[i] =0xFF ; + } + + ht_cap.mcs.tx_params |=IEEE80211_HT_MCS_TX_DEFINED ; + +return ht_cap; +} + +static int ath11k_mac_set_txbf_conf (struct ath11k_vif *arvif) +{ +u32 value =0 ; +struct ath11k *ar = arvif->ar; +int nsts; +int sound_dim; +u32 vht_cap = ar->pdev->cap.vht_cap; +u32 vdev_param =WMI_VDEV_PARAM_TXBF ; + +if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE )) { + nsts = vht_cap &IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK ; + nsts >>=IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT ; + value |=SM (nsts,WMI_TXBF_STS_CAP_OFFSET ); + } + +if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE )) { + sound_dim = vht_cap & +IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK ; + sound_dim >>=IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT ; +if (sound_dim > (ar->num_tx_chains -1 )) + sound_dim = ar->num_tx_chains -1 ; + value |=SM (sound_dim,WMI_BF_SOUND_DIM_OFFSET ); + } + +if (!value) +return 0 ; + +if (vht_cap &IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE ) { + value |=WMI_VDEV_PARAM_TXBF_SU_TX_BFER ; + +if ((vht_cap &IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE ) && + arvif->vdev_type ==WMI_VDEV_TYPE_AP ) + value |=WMI_VDEV_PARAM_TXBF_MU_TX_BFER ; + } + +/* TODO: SUBFEE not validated in HK, disable here until validated? */ + +if (vht_cap &IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE ) { + value |=WMI_VDEV_PARAM_TXBF_SU_TX_BFEE ; + +if ((vht_cap &IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE ) && + arvif->vdev_type ==WMI_VDEV_TYPE_STA ) + value |=WMI_VDEV_PARAM_TXBF_MU_TX_BFEE ; + } + +return ath11k_wmi_vdev_set_param_cmd (ar, arvif->vdev_id, + vdev_param, value); +} + +static void ath11k_set_vht_txbf_cap (struct ath11k *ar,u32 *vht_cap) +{ +bool subfer, subfee; +int sound_dim =0 ; + + subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE )); + subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE )); + +if (ar->num_tx_chains <2 ) { + *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE ); + subfer = false; + } + +/* If SU Beaformer is not set, then disable MU Beamformer Capability */ +if (!subfer) + *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE ); + +/* If SU Beaformee is not set, then disable MU Beamformee Capability */ +if (!subfee)
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
_______________________________________________
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
Part of the diff is not shown here. View the raw message.
PATCH v3 32/49 ath11k: add mac.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/mac.h | 145 ++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)
drivers/net/wireless/ath/ath11k/mac.h new file +145 -0
@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#ifndef ATH11K_MAC_H +#define ATH11K_MAC_H + +#include <net/mac80211.h> +#include <net/cfg80211.h> + +struct ath11k ; +struct ath11k_base ; + +struct ath11k_generic_iter { +struct ath11k *ar; +int ret; +}; + +/* number of failed packets (20 packets with 16 sw reties each) */ +#define ATH11K_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 ATH11K_KEEPALIVE_MIN_IDLE 3747 +#define ATH11K_KEEPALIVE_MAX_IDLE 3895 +#define ATH11K_KEEPALIVE_MAX_UNRESPONSIVE 3900 + +#define WMI_HOST_RC_DS_FLAG 0x01 +#define WMI_HOST_RC_CW40_FLAG 0x02 +#define WMI_HOST_RC_SGI_FLAG 0x04 +#define WMI_HOST_RC_HT_FLAG 0x08 +#define WMI_HOST_RC_RTSCTS_FLAG 0x10 +#define WMI_HOST_RC_TX_STBC_FLAG 0x20 +#define WMI_HOST_RC_RX_STBC_FLAG 0xC0 +#define WMI_HOST_RC_RX_STBC_FLAG_S 6 +#define WMI_HOST_RC_WEP_TKIP_FLAG 0x100 +#define WMI_HOST_RC_TS_FLAG 0x200 +#define WMI_HOST_RC_UAPSD_FLAG 0x400 + +#define WMI_HT_CAP_ENABLED 0x0001 +#define WMI_HT_CAP_HT20_SGI 0x0002 +#define WMI_HT_CAP_DYNAMIC_SMPS 0x0004 +#define WMI_HT_CAP_TX_STBC 0x0008 +#define WMI_HT_CAP_TX_STBC_MASK_SHIFT 3 +#define WMI_HT_CAP_RX_STBC 0x0030 +#define WMI_HT_CAP_RX_STBC_MASK_SHIFT 4 +#define WMI_HT_CAP_LDPC 0x0040 +#define WMI_HT_CAP_L_SIG_TXOP_PROT 0x0080 +#define WMI_HT_CAP_MPDU_DENSITY 0x0700 +#define WMI_HT_CAP_MPDU_DENSITY_MASK_SHIFT 8 +#define WMI_HT_CAP_HT40_SGI 0x0800 +#define WMI_HT_CAP_RX_LDPC 0x1000 +#define WMI_HT_CAP_TX_LDPC 0x2000 +#define WMI_HT_CAP_IBF_BFER 0x4000 + +/* These macros should be used when we wish to advertise STBC support for +* only 1SS or 2SS or 3SS. +*/ +#define WMI_HT_CAP_RX_STBC_1SS 0x0010 +#define WMI_HT_CAP_RX_STBC_2SS 0x0020 +#define WMI_HT_CAP_RX_STBC_3SS 0x0030 + +#define WMI_HT_CAP_DEFAULT_ALL (WMI_HT_CAP_ENABLED | \ + WMI_HT_CAP_HT20_SGI | \ + WMI_HT_CAP_HT40_SGI | \ + WMI_HT_CAP_TX_STBC | \ + WMI_HT_CAP_RX_STBC | \ + WMI_HT_CAP_LDPC) + +#define WMI_VHT_CAP_MAX_MPDU_LEN_MASK 0x00000003 +#define WMI_VHT_CAP_RX_LDPC 0x00000010 +#define WMI_VHT_CAP_SGI_80MHZ 0x00000020 +#define WMI_VHT_CAP_SGI_160MHZ 0x00000040 +#define WMI_VHT_CAP_TX_STBC 0x00000080 +#define WMI_VHT_CAP_RX_STBC_MASK 0x00000300 +#define WMI_VHT_CAP_RX_STBC_MASK_SHIFT 8 +#define WMI_VHT_CAP_SU_BFER 0x00000800 +#define WMI_VHT_CAP_SU_BFEE 0x00001000 +#define WMI_VHT_CAP_MAX_CS_ANT_MASK 0x0000E000 +#define WMI_VHT_CAP_MAX_CS_ANT_MASK_SHIFT 13 +#define WMI_VHT_CAP_MAX_SND_DIM_MASK 0x00070000 +#define WMI_VHT_CAP_MAX_SND_DIM_MASK_SHIFT 16 +#define WMI_VHT_CAP_MU_BFER 0x00080000 +#define WMI_VHT_CAP_MU_BFEE 0x00100000 +#define WMI_VHT_CAP_MAX_AMPDU_LEN_EXP 0x03800000 +#define WMI_VHT_CAP_MAX_AMPDU_LEN_EXP_SHIT 23 +#define WMI_VHT_CAP_RX_FIXED_ANT 0x10000000 +#define WMI_VHT_CAP_TX_FIXED_ANT 0x20000000 + +#define WMI_VHT_CAP_MAX_MPDU_LEN_11454 0x00000002 + +/* These macros should be used when we wish to advertise STBC support for +* only 1SS or 2SS or 3SS. +*/ +#define WMI_VHT_CAP_RX_STBC_1SS 0x00000100 +#define WMI_VHT_CAP_RX_STBC_2SS 0x00000200 +#define WMI_VHT_CAP_RX_STBC_3SS 0x00000300 + +#define WMI_VHT_CAP_DEFAULT_ALL (WMI_VHT_CAP_MAX_MPDU_LEN_11454 | \ + WMI_VHT_CAP_SGI_80MHZ | \ + WMI_VHT_CAP_TX_STBC | \ + WMI_VHT_CAP_RX_STBC_MASK | \ + WMI_VHT_CAP_RX_LDPC | \ + WMI_VHT_CAP_MAX_AMPDU_LEN_EXP | \ + WMI_VHT_CAP_RX_FIXED_ANT | \ + WMI_VHT_CAP_TX_FIXED_ANT) + +/* 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 WMI_MAX_SPATIAL_STREAM 3 + +#define ATH11K_CHAN_WIDTH_NUM 8 + +extern const struct htt_rx_ring_tlv_filter ath11k_mac_mon_status_filter_default; + +int ath11k_mac_create (struct ath11k_base *ab); +void ath11k_mac_destroy (struct ath11k_base *ab); +void ath11k_mac_unregister (struct ath11k_base *ab); +int ath11k_mac_hw_ratecode_to_legacy_rate (u8 hw_rc,u8 preamble,u8 *rateidx, +u16 *rate); +u8 ath11k_mac_bitrate_to_idx (const struct ieee80211_supported_band *sband, +u32 bitrate); +u8 ath11k_mac_hw_rate_to_idx (const struct ieee80211_supported_band *sband, +u8 hw_rate,bool cck); + +void __ath11k_mac_scan_finish (struct ath11k *ar); +void ath11k_mac_scan_finish (struct ath11k *ar); + +struct ath11k_vif *ath11k_mac_get_arvif (struct ath11k *ar,u32 vdev_id); +struct ath11k_vif *ath11k_mac_get_arvif_by_vdev_id (struct ath11k_base *ab, +u32 vdev_id); +struct ath11k *ath11k_mac_get_ar_by_vdev_id (struct ath11k_base *ab,u32 vdev_id); +struct ath11k *ath11k_mac_get_ar_by_pdev_id (struct ath11k_base *ab,u32 pdev_id); +struct ath11k *ath11k_mac_get_ar_vdev_stop_status (struct ath11k_base *ab, +u32 vdev_id); + +void ath11k_mac_drain_tx (struct ath11k *ar); +void ath11k_mac_peer_cleanup_all (struct ath11k *ar); +int ath11k_mac_tx_mgmt_pending_free (int buf_id,void *skb,void *ctx); +#endif
_______________________________________________
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v3 33/49 ath11k: add peer.c
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/peer.c | 236 +++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+)
drivers/net/wireless/ath/ath11k/peer.c new file +236 -0
@@ -0,0 +1,236 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#include "core.h" +#include "peer.h" +#include "debug.h" + +struct ath11k_peer *ath11k_peer_find (struct ath11k_base *ab,int vdev_id, +const u8 *addr) +{ +struct ath11k_peer *peer; + +lockdep_assert_held (&ab->base_lock); + +list_for_each_entry (peer, &ab->peers, list) { +if (peer->vdev_id != vdev_id) +continue ; +if (memcmp (peer->addr, addr,ETH_ALEN )) +continue ; + +return peer; + } + +return NULL ; +} + +struct ath11k_peer *ath11k_peer_find_by_addr (struct ath11k_base *ab, +const u8 *addr) +{ +struct ath11k_peer *peer; + +lockdep_assert_held (&ab->base_lock); + +list_for_each_entry (peer, &ab->peers, list) { +if (memcmp (peer->addr, addr,ETH_ALEN )) +continue ; + +return peer; + } + +return NULL ; +} + +struct ath11k_peer *ath11k_peer_find_by_id (struct ath11k_base *ab, +int peer_id) +{ +struct ath11k_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 ; +} + +void ath11k_peer_unmap_event (struct ath11k_base *ab,u16 peer_id) +{ +struct ath11k_peer *peer; + +spin_lock_bh (&ab->base_lock); + + peer =ath11k_peer_find_by_id (ab, peer_id); +if (!peer) { +ath11k_warn (ab,"peer-unmap-event: unknown peer id %d\n" , + peer_id); + goto exit; + } + +ath11k_dbg (ab,ATH11K_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 ath11k_peer_map_event (struct ath11k_base *ab,u8 vdev_id,u16 peer_id, +u8 *mac_addr,u16 ast_hash) +{ +struct ath11k_peer *peer; + +spin_lock_bh (&ab->base_lock); + peer =ath11k_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; +ether_addr_copy (peer->addr, mac_addr); +list_add (&peer->list, &ab->peers); +wake_up (&ab->peer_mapping_wq); + } + +ath11k_dbg (ab,ATH11K_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 ath11k_wait_for_peer_common (struct ath11k_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 = !!ath11k_peer_find (ab, vdev_id, addr); +spin_unlock_bh (&ab->base_lock); + + (mapped == expect_mapped || +test_bit (ATH11K_FLAG_CRASH_FLUSH , &ab->dev_flags)); + }),3 *HZ ); + +if (ret <=0 ) +return -ETIMEDOUT ; + +return 0 ; +} + +void ath11k_peer_cleanup (struct ath11k *ar,u32 vdev_id) +{ +struct ath11k_peer *peer, *tmp; +struct ath11k_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 ; + +ath11k_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 ath11k_wait_for_peer_deleted (struct ath11k *ar,int vdev_id,const u8 *addr) +{ +return ath11k_wait_for_peer_common (ar->ab, vdev_id, addr, false); +} + +int ath11k_peer_delete (struct ath11k *ar,u32 vdev_id,u8 *addr) +{ +int ret; + +lockdep_assert_held (&ar->conf_mutex); + + ret =ath11k_wmi_send_peer_delete_cmd (ar, addr, vdev_id); +if (ret) { +ath11k_warn (ar->ab, +"failed to delete peer vdev_id %d addr %pM ret %d\n" , + vdev_id, addr, ret); +return ret; + } + + ret =ath11k_wait_for_peer_deleted (ar, vdev_id, addr); +if (ret) +return ret; + + ar->num_peers--; + +return 0 ; +} + +static int ath11k_wait_for_peer_created (struct ath11k *ar,int vdev_id,const u8 *addr) +{ +return ath11k_wait_for_peer_common (ar->ab, vdev_id, addr, true); +} + +int ath11k_peer_create (struct ath11k *ar,struct ath11k_vif *arvif, +struct ieee80211_sta *sta,struct peer_create_params *param) +{ +struct ath11k_peer *peer; +int ret; + +lockdep_assert_held (&ar->conf_mutex); + +if (ar->num_peers > (ar->max_num_peers -1 )) { +ath11k_warn (ar->ab, +"failed to create peer due to insufficient peer entry resource in firmware\n" ); +return -ENOBUFS ; + } + + ret =ath11k_wmi_send_peer_create_cmd (ar, param); +if (ret) { +ath11k_warn (ar->ab, +"failed to send peer create vdev_id %d ret %d\n" , + param->vdev_id, ret); +return ret; + } + + ret =ath11k_wait_for_peer_created (ar, param->vdev_id, + param->peer_addr); +if (ret) +return ret; + +spin_lock_bh (&ar->ab->base_lock); + + peer =ath11k_peer_find (ar->ab, param->vdev_id, param->peer_addr); +if (!peer) { +spin_unlock_bh (&ar->ab->base_lock); +ath11k_warn (ar->ab,"failed to find peer %pM on vdev %i after creation\n" , + param->peer_addr, param->vdev_id); +ath11k_wmi_send_peer_delete_cmd (ar, param->peer_addr, + param->vdev_id); +return -ENOENT ; + } + + peer->sta = sta; + arvif->ast_hash = peer->ast_hash; + + ar->num_peers++; + +spin_unlock_bh (&ar->ab->base_lock); + +return 0 ; +}
PATCH v3 34/49 ath11k: add peer.h
In reply to Kalle Valo(patches split for easier review, see the cover letter for more)
--- drivers/net/wireless/ath/ath11k/peer.h | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
drivers/net/wireless/ath/ath11k/peer.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* +* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. +*/ + +#ifndef ATH11K_PEER_H +#define ATH11K_PEER_H + +struct ath11k_peer { +struct list_head list; +struct ieee80211_sta *sta; +int vdev_id; +u8 addr[ETH_ALEN ]; +int peer_id; +u16 ast_hash; + +/* protected by ab->data_lock */ +struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX +1 ]; +struct dp_rx_tid rx_tid[IEEE80211_NUM_TIDS +1 ]; +}; + +void ath11k_peer_unmap_event (struct ath11k_base *ab,u16 peer_id); +void ath11k_peer_map_event (struct ath11k_base *ab,u8 vdev_id,u16 peer_id, +u8 *mac_addr,u16 ast_hash); +struct ath11k_peer *ath11k_peer_find (struct ath11k_base *ab,int vdev_id, +const u8 *addr); +struct ath11k_peer *ath11k_peer_find_by_addr (struct ath11k_base *ab, +const u8 *addr); +struct ath11k_peer *ath11k_peer_find_by_id (struct ath11k_base *ab,int peer_id); +void ath11k_peer_cleanup (struct ath11k *ar,u32 vdev_id); +int ath11k_peer_delete (struct ath11k *ar,u32 vdev_id,u8 *addr); +int ath11k_peer_create (struct ath11k *ar,struct ath11k_vif *arvif, +struct ieee80211_sta *sta,struct peer_create_params *param); + +#endif /* _PEER_H_ */