162306a36Sopenharmony_ci// SPDX-License-Identifier: ISC 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2005-2011 Atheros Communications Inc. 462306a36Sopenharmony_ci * Copyright (c) 2011-2017 Qualcomm Atheros, Inc. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <linux/slab.h> 862306a36Sopenharmony_ci#include <linux/if_ether.h> 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include "htt.h" 1162306a36Sopenharmony_ci#include "core.h" 1262306a36Sopenharmony_ci#include "debug.h" 1362306a36Sopenharmony_ci#include "hif.h" 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cistatic const enum htt_t2h_msg_type htt_main_t2h_msg_types[] = { 1662306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF, 1762306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND, 1862306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH, 1962306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP, 2062306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP, 2162306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA, 2262306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA, 2362306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND, 2462306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG, 2562306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF, 2662306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND, 2762306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND, 2862306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_TX_INSPECT_IND] = 2962306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_TX_INSPECT_IND, 3062306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] = 3162306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION, 3262306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] = 3362306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND, 3462306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND, 3562306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] = 3662306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND, 3762306a36Sopenharmony_ci [HTT_MAIN_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST, 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cistatic const enum htt_t2h_msg_type htt_10x_t2h_msg_types[] = { 4162306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF, 4262306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND, 4362306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH, 4462306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP, 4562306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP, 4662306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA, 4762306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA, 4862306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND, 4962306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG, 5062306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF, 5162306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND, 5262306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND, 5362306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND, 5462306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_TX_INSPECT_IND] = HTT_T2H_MSG_TYPE_TX_INSPECT_IND, 5562306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST, 5662306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE, 5762306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_AGGR_CONF] = HTT_T2H_MSG_TYPE_AGGR_CONF, 5862306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_STATS_NOUPLOAD] = HTT_T2H_MSG_TYPE_STATS_NOUPLOAD, 5962306a36Sopenharmony_ci [HTT_10X_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] = 6062306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION, 6162306a36Sopenharmony_ci}; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistatic const enum htt_t2h_msg_type htt_tlv_t2h_msg_types[] = { 6462306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF, 6562306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND, 6662306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH, 6762306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP, 6862306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP, 6962306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA, 7062306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA, 7162306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND, 7262306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG, 7362306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF, 7462306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND, 7562306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND, 7662306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND, 7762306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_TX_INSPECT_IND] = HTT_T2H_MSG_TYPE_TX_INSPECT_IND, 7862306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] = 7962306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION, 8062306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] = 8162306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND, 8262306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND, 8362306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] = 8462306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND, 8562306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND] = 8662306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND, 8762306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE] = 8862306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE, 8962306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE, 9062306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_RX_OFLD_PKT_ERR] = 9162306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_RX_OFLD_PKT_ERR, 9262306a36Sopenharmony_ci [HTT_TLV_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST, 9362306a36Sopenharmony_ci}; 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistatic const enum htt_t2h_msg_type htt_10_4_t2h_msg_types[] = { 9662306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF, 9762306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND, 9862306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH, 9962306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP, 10062306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP, 10162306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA, 10262306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA, 10362306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND, 10462306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG, 10562306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF, 10662306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND, 10762306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND, 10862306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND, 10962306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_TX_INSPECT_IND] = 11062306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_TX_INSPECT_IND, 11162306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] = 11262306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION, 11362306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE, 11462306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] = 11562306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND, 11662306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND, 11762306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] = 11862306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND, 11962306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST, 12062306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_EN_STATS] = HTT_T2H_MSG_TYPE_EN_STATS, 12162306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_AGGR_CONF] = HTT_T2H_MSG_TYPE_AGGR_CONF, 12262306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_TX_FETCH_IND] = 12362306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_TX_FETCH_IND, 12462306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_TX_FETCH_CONFIRM] = 12562306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_TX_FETCH_CONFIRM, 12662306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_STATS_NOUPLOAD] = 12762306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_STATS_NOUPLOAD, 12862306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_TX_MODE_SWITCH_IND] = 12962306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_TX_MODE_SWITCH_IND, 13062306a36Sopenharmony_ci [HTT_10_4_T2H_MSG_TYPE_PEER_STATS] = 13162306a36Sopenharmony_ci HTT_T2H_MSG_TYPE_PEER_STATS, 13262306a36Sopenharmony_ci}; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ciconst struct ath10k_htt_rx_desc_ops qca988x_rx_desc_ops = { 13562306a36Sopenharmony_ci .rx_desc_size = sizeof(struct htt_rx_desc_v1), 13662306a36Sopenharmony_ci .rx_desc_msdu_payload_offset = offsetof(struct htt_rx_desc_v1, msdu_payload) 13762306a36Sopenharmony_ci}; 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_cistatic int ath10k_qca99x0_rx_desc_get_l3_pad_bytes(struct htt_rx_desc *rxd) 14062306a36Sopenharmony_ci{ 14162306a36Sopenharmony_ci struct htt_rx_desc_v1 *rx_desc = container_of(rxd, 14262306a36Sopenharmony_ci struct htt_rx_desc_v1, 14362306a36Sopenharmony_ci base); 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci return MS(__le32_to_cpu(rx_desc->msdu_end.qca99x0.info1), 14662306a36Sopenharmony_ci RX_MSDU_END_INFO1_L3_HDR_PAD); 14762306a36Sopenharmony_ci} 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_cistatic bool ath10k_qca99x0_rx_desc_msdu_limit_error(struct htt_rx_desc *rxd) 15062306a36Sopenharmony_ci{ 15162306a36Sopenharmony_ci struct htt_rx_desc_v1 *rx_desc = container_of(rxd, 15262306a36Sopenharmony_ci struct htt_rx_desc_v1, 15362306a36Sopenharmony_ci base); 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci return !!(rx_desc->msdu_end.common.info0 & 15662306a36Sopenharmony_ci __cpu_to_le32(RX_MSDU_END_INFO0_MSDU_LIMIT_ERR)); 15762306a36Sopenharmony_ci} 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ciconst struct ath10k_htt_rx_desc_ops qca99x0_rx_desc_ops = { 16062306a36Sopenharmony_ci .rx_desc_size = sizeof(struct htt_rx_desc_v1), 16162306a36Sopenharmony_ci .rx_desc_msdu_payload_offset = offsetof(struct htt_rx_desc_v1, msdu_payload), 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci .rx_desc_get_l3_pad_bytes = ath10k_qca99x0_rx_desc_get_l3_pad_bytes, 16462306a36Sopenharmony_ci .rx_desc_get_msdu_limit_error = ath10k_qca99x0_rx_desc_msdu_limit_error, 16562306a36Sopenharmony_ci}; 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_cistatic void ath10k_rx_desc_wcn3990_get_offsets(struct htt_rx_ring_rx_desc_offsets *off) 16862306a36Sopenharmony_ci{ 16962306a36Sopenharmony_ci#define desc_offset(x) (offsetof(struct htt_rx_desc_v2, x) / 4) 17062306a36Sopenharmony_ci off->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status)); 17162306a36Sopenharmony_ci off->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload)); 17262306a36Sopenharmony_ci off->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start)); 17362306a36Sopenharmony_ci off->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end)); 17462306a36Sopenharmony_ci off->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start)); 17562306a36Sopenharmony_ci off->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end)); 17662306a36Sopenharmony_ci off->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start)); 17762306a36Sopenharmony_ci off->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end)); 17862306a36Sopenharmony_ci off->rx_attention_offset = __cpu_to_le16(desc_offset(attention)); 17962306a36Sopenharmony_ci off->frag_info_offset = __cpu_to_le16(desc_offset(frag_info)); 18062306a36Sopenharmony_ci#undef desc_offset 18162306a36Sopenharmony_ci} 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_cistatic struct htt_rx_desc * 18462306a36Sopenharmony_ciath10k_rx_desc_wcn3990_from_raw_buffer(void *buff) 18562306a36Sopenharmony_ci{ 18662306a36Sopenharmony_ci return &((struct htt_rx_desc_v2 *)buff)->base; 18762306a36Sopenharmony_ci} 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_cistatic struct rx_attention * 19062306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_attention(struct htt_rx_desc *rxd) 19162306a36Sopenharmony_ci{ 19262306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci return &rx_desc->attention; 19562306a36Sopenharmony_ci} 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_cistatic struct rx_frag_info_common * 19862306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_frag_info(struct htt_rx_desc *rxd) 19962306a36Sopenharmony_ci{ 20062306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ci return &rx_desc->frag_info.common; 20362306a36Sopenharmony_ci} 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_cistatic struct rx_mpdu_start * 20662306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_mpdu_start(struct htt_rx_desc *rxd) 20762306a36Sopenharmony_ci{ 20862306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci return &rx_desc->mpdu_start; 21162306a36Sopenharmony_ci} 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_cistatic struct rx_mpdu_end * 21462306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_mpdu_end(struct htt_rx_desc *rxd) 21562306a36Sopenharmony_ci{ 21662306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci return &rx_desc->mpdu_end; 21962306a36Sopenharmony_ci} 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_cistatic struct rx_msdu_start_common * 22262306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_msdu_start(struct htt_rx_desc *rxd) 22362306a36Sopenharmony_ci{ 22462306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci return &rx_desc->msdu_start.common; 22762306a36Sopenharmony_ci} 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_cistatic struct rx_msdu_end_common * 23062306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_msdu_end(struct htt_rx_desc *rxd) 23162306a36Sopenharmony_ci{ 23262306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci return &rx_desc->msdu_end.common; 23562306a36Sopenharmony_ci} 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_cistatic struct rx_ppdu_start * 23862306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_ppdu_start(struct htt_rx_desc *rxd) 23962306a36Sopenharmony_ci{ 24062306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci return &rx_desc->ppdu_start; 24362306a36Sopenharmony_ci} 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_cistatic struct rx_ppdu_end_common * 24662306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_ppdu_end(struct htt_rx_desc *rxd) 24762306a36Sopenharmony_ci{ 24862306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci return &rx_desc->ppdu_end.common; 25162306a36Sopenharmony_ci} 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_cistatic u8 * 25462306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_rx_hdr_status(struct htt_rx_desc *rxd) 25562306a36Sopenharmony_ci{ 25662306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci return rx_desc->rx_hdr_status; 25962306a36Sopenharmony_ci} 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_cistatic u8 * 26262306a36Sopenharmony_ciath10k_rx_desc_wcn3990_get_msdu_payload(struct htt_rx_desc *rxd) 26362306a36Sopenharmony_ci{ 26462306a36Sopenharmony_ci struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base); 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci return rx_desc->msdu_payload; 26762306a36Sopenharmony_ci} 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ciconst struct ath10k_htt_rx_desc_ops wcn3990_rx_desc_ops = { 27062306a36Sopenharmony_ci .rx_desc_size = sizeof(struct htt_rx_desc_v2), 27162306a36Sopenharmony_ci .rx_desc_msdu_payload_offset = offsetof(struct htt_rx_desc_v2, msdu_payload), 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci .rx_desc_from_raw_buffer = ath10k_rx_desc_wcn3990_from_raw_buffer, 27462306a36Sopenharmony_ci .rx_desc_get_offsets = ath10k_rx_desc_wcn3990_get_offsets, 27562306a36Sopenharmony_ci .rx_desc_get_attention = ath10k_rx_desc_wcn3990_get_attention, 27662306a36Sopenharmony_ci .rx_desc_get_frag_info = ath10k_rx_desc_wcn3990_get_frag_info, 27762306a36Sopenharmony_ci .rx_desc_get_mpdu_start = ath10k_rx_desc_wcn3990_get_mpdu_start, 27862306a36Sopenharmony_ci .rx_desc_get_mpdu_end = ath10k_rx_desc_wcn3990_get_mpdu_end, 27962306a36Sopenharmony_ci .rx_desc_get_msdu_start = ath10k_rx_desc_wcn3990_get_msdu_start, 28062306a36Sopenharmony_ci .rx_desc_get_msdu_end = ath10k_rx_desc_wcn3990_get_msdu_end, 28162306a36Sopenharmony_ci .rx_desc_get_ppdu_start = ath10k_rx_desc_wcn3990_get_ppdu_start, 28262306a36Sopenharmony_ci .rx_desc_get_ppdu_end = ath10k_rx_desc_wcn3990_get_ppdu_end, 28362306a36Sopenharmony_ci .rx_desc_get_rx_hdr_status = ath10k_rx_desc_wcn3990_get_rx_hdr_status, 28462306a36Sopenharmony_ci .rx_desc_get_msdu_payload = ath10k_rx_desc_wcn3990_get_msdu_payload, 28562306a36Sopenharmony_ci}; 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ciint ath10k_htt_connect(struct ath10k_htt *htt) 28862306a36Sopenharmony_ci{ 28962306a36Sopenharmony_ci struct ath10k_htc_svc_conn_req conn_req; 29062306a36Sopenharmony_ci struct ath10k_htc_svc_conn_resp conn_resp; 29162306a36Sopenharmony_ci struct ath10k *ar = htt->ar; 29262306a36Sopenharmony_ci struct ath10k_htc_ep *ep; 29362306a36Sopenharmony_ci int status; 29462306a36Sopenharmony_ci 29562306a36Sopenharmony_ci memset(&conn_req, 0, sizeof(conn_req)); 29662306a36Sopenharmony_ci memset(&conn_resp, 0, sizeof(conn_resp)); 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci conn_req.ep_ops.ep_tx_complete = ath10k_htt_htc_tx_complete; 29962306a36Sopenharmony_ci conn_req.ep_ops.ep_rx_complete = ath10k_htt_htc_t2h_msg_handler; 30062306a36Sopenharmony_ci conn_req.ep_ops.ep_tx_credits = ath10k_htt_op_ep_tx_credits; 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci /* connect to control service */ 30362306a36Sopenharmony_ci conn_req.service_id = ATH10K_HTC_SVC_ID_HTT_DATA_MSG; 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_ci status = ath10k_htc_connect_service(&htt->ar->htc, &conn_req, 30662306a36Sopenharmony_ci &conn_resp); 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci if (status) 30962306a36Sopenharmony_ci return status; 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci htt->eid = conn_resp.eid; 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL) { 31462306a36Sopenharmony_ci ep = &ar->htc.endpoint[htt->eid]; 31562306a36Sopenharmony_ci ath10k_htc_setup_tx_req(ep); 31662306a36Sopenharmony_ci } 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci htt->disable_tx_comp = ath10k_hif_get_htt_tx_complete(htt->ar); 31962306a36Sopenharmony_ci if (htt->disable_tx_comp) 32062306a36Sopenharmony_ci ath10k_htc_change_tx_credit_flow(&htt->ar->htc, htt->eid, true); 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci return 0; 32362306a36Sopenharmony_ci} 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ciint ath10k_htt_init(struct ath10k *ar) 32662306a36Sopenharmony_ci{ 32762306a36Sopenharmony_ci struct ath10k_htt *htt = &ar->htt; 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci htt->ar = ar; 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci /* 33262306a36Sopenharmony_ci * Prefetch enough data to satisfy target 33362306a36Sopenharmony_ci * classification engine. 33462306a36Sopenharmony_ci * This is for LL chips. HL chips will probably 33562306a36Sopenharmony_ci * transfer all frame in the tx fragment. 33662306a36Sopenharmony_ci */ 33762306a36Sopenharmony_ci htt->prefetch_len = 33862306a36Sopenharmony_ci 36 + /* 802.11 + qos + ht */ 33962306a36Sopenharmony_ci 4 + /* 802.1q */ 34062306a36Sopenharmony_ci 8 + /* llc snap */ 34162306a36Sopenharmony_ci 2; /* ip4 dscp or ip6 priority */ 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci switch (ar->running_fw->fw_file.htt_op_version) { 34462306a36Sopenharmony_ci case ATH10K_FW_HTT_OP_VERSION_10_4: 34562306a36Sopenharmony_ci ar->htt.t2h_msg_types = htt_10_4_t2h_msg_types; 34662306a36Sopenharmony_ci ar->htt.t2h_msg_types_max = HTT_10_4_T2H_NUM_MSGS; 34762306a36Sopenharmony_ci break; 34862306a36Sopenharmony_ci case ATH10K_FW_HTT_OP_VERSION_10_1: 34962306a36Sopenharmony_ci ar->htt.t2h_msg_types = htt_10x_t2h_msg_types; 35062306a36Sopenharmony_ci ar->htt.t2h_msg_types_max = HTT_10X_T2H_NUM_MSGS; 35162306a36Sopenharmony_ci break; 35262306a36Sopenharmony_ci case ATH10K_FW_HTT_OP_VERSION_TLV: 35362306a36Sopenharmony_ci ar->htt.t2h_msg_types = htt_tlv_t2h_msg_types; 35462306a36Sopenharmony_ci ar->htt.t2h_msg_types_max = HTT_TLV_T2H_NUM_MSGS; 35562306a36Sopenharmony_ci break; 35662306a36Sopenharmony_ci case ATH10K_FW_HTT_OP_VERSION_MAIN: 35762306a36Sopenharmony_ci ar->htt.t2h_msg_types = htt_main_t2h_msg_types; 35862306a36Sopenharmony_ci ar->htt.t2h_msg_types_max = HTT_MAIN_T2H_NUM_MSGS; 35962306a36Sopenharmony_ci break; 36062306a36Sopenharmony_ci case ATH10K_FW_HTT_OP_VERSION_MAX: 36162306a36Sopenharmony_ci case ATH10K_FW_HTT_OP_VERSION_UNSET: 36262306a36Sopenharmony_ci WARN_ON(1); 36362306a36Sopenharmony_ci return -EINVAL; 36462306a36Sopenharmony_ci } 36562306a36Sopenharmony_ci ath10k_htt_set_tx_ops(htt); 36662306a36Sopenharmony_ci ath10k_htt_set_rx_ops(htt); 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ci return 0; 36962306a36Sopenharmony_ci} 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci#define HTT_TARGET_VERSION_TIMEOUT_HZ (3 * HZ) 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_cistatic int ath10k_htt_verify_version(struct ath10k_htt *htt) 37462306a36Sopenharmony_ci{ 37562306a36Sopenharmony_ci struct ath10k *ar = htt->ar; 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ci ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt target version %d.%d\n", 37862306a36Sopenharmony_ci htt->target_version_major, htt->target_version_minor); 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci if (htt->target_version_major != 2 && 38162306a36Sopenharmony_ci htt->target_version_major != 3) { 38262306a36Sopenharmony_ci ath10k_err(ar, "unsupported htt major version %d. supported versions are 2 and 3\n", 38362306a36Sopenharmony_ci htt->target_version_major); 38462306a36Sopenharmony_ci return -ENOTSUPP; 38562306a36Sopenharmony_ci } 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci return 0; 38862306a36Sopenharmony_ci} 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_ciint ath10k_htt_setup(struct ath10k_htt *htt) 39162306a36Sopenharmony_ci{ 39262306a36Sopenharmony_ci struct ath10k *ar = htt->ar; 39362306a36Sopenharmony_ci int status; 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ci init_completion(&htt->target_version_received); 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_ci status = ath10k_htt_h2t_ver_req_msg(htt); 39862306a36Sopenharmony_ci if (status) 39962306a36Sopenharmony_ci return status; 40062306a36Sopenharmony_ci 40162306a36Sopenharmony_ci status = wait_for_completion_timeout(&htt->target_version_received, 40262306a36Sopenharmony_ci HTT_TARGET_VERSION_TIMEOUT_HZ); 40362306a36Sopenharmony_ci if (status == 0) { 40462306a36Sopenharmony_ci ath10k_warn(ar, "htt version request timed out\n"); 40562306a36Sopenharmony_ci return -ETIMEDOUT; 40662306a36Sopenharmony_ci } 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ci status = ath10k_htt_verify_version(htt); 40962306a36Sopenharmony_ci if (status) { 41062306a36Sopenharmony_ci ath10k_warn(ar, "failed to verify htt version: %d\n", 41162306a36Sopenharmony_ci status); 41262306a36Sopenharmony_ci return status; 41362306a36Sopenharmony_ci } 41462306a36Sopenharmony_ci 41562306a36Sopenharmony_ci status = ath10k_htt_send_frag_desc_bank_cfg(htt); 41662306a36Sopenharmony_ci if (status) 41762306a36Sopenharmony_ci return status; 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_ci status = ath10k_htt_send_rx_ring_cfg(htt); 42062306a36Sopenharmony_ci if (status) { 42162306a36Sopenharmony_ci ath10k_warn(ar, "failed to setup rx ring: %d\n", 42262306a36Sopenharmony_ci status); 42362306a36Sopenharmony_ci return status; 42462306a36Sopenharmony_ci } 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_ci status = ath10k_htt_h2t_aggr_cfg_msg(htt, 42762306a36Sopenharmony_ci htt->max_num_ampdu, 42862306a36Sopenharmony_ci htt->max_num_amsdu); 42962306a36Sopenharmony_ci if (status) { 43062306a36Sopenharmony_ci ath10k_warn(ar, "failed to setup amsdu/ampdu limit: %d\n", 43162306a36Sopenharmony_ci status); 43262306a36Sopenharmony_ci return status; 43362306a36Sopenharmony_ci } 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci return 0; 43662306a36Sopenharmony_ci} 437