18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: BSD-3-Clause-Clear 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include "hal_desc.h" 78c2ecf20Sopenharmony_ci#include "hal.h" 88c2ecf20Sopenharmony_ci#include "hal_tx.h" 98c2ecf20Sopenharmony_ci#include "hif.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define DSCP_TID_MAP_TBL_ENTRY_SIZE 64 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* dscp_tid_map - Default DSCP-TID mapping 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * DSCP TID 168c2ecf20Sopenharmony_ci * 000000 0 178c2ecf20Sopenharmony_ci * 001000 1 188c2ecf20Sopenharmony_ci * 010000 2 198c2ecf20Sopenharmony_ci * 011000 3 208c2ecf20Sopenharmony_ci * 100000 4 218c2ecf20Sopenharmony_ci * 101000 5 228c2ecf20Sopenharmony_ci * 110000 6 238c2ecf20Sopenharmony_ci * 111000 7 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_cistatic const u8 dscp_tid_map[DSCP_TID_MAP_TBL_ENTRY_SIZE] = { 268c2ecf20Sopenharmony_ci 0, 0, 0, 0, 0, 0, 0, 0, 278c2ecf20Sopenharmony_ci 1, 1, 1, 1, 1, 1, 1, 1, 288c2ecf20Sopenharmony_ci 2, 2, 2, 2, 2, 2, 2, 2, 298c2ecf20Sopenharmony_ci 3, 3, 3, 3, 3, 3, 3, 3, 308c2ecf20Sopenharmony_ci 4, 4, 4, 4, 4, 4, 4, 4, 318c2ecf20Sopenharmony_ci 5, 5, 5, 5, 5, 5, 5, 5, 328c2ecf20Sopenharmony_ci 6, 6, 6, 6, 6, 6, 6, 6, 338c2ecf20Sopenharmony_ci 7, 7, 7, 7, 7, 7, 7, 7, 348c2ecf20Sopenharmony_ci}; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_civoid ath11k_hal_tx_cmd_desc_setup(struct ath11k_base *ab, void *cmd, 378c2ecf20Sopenharmony_ci struct hal_tx_info *ti) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci struct hal_tcl_data_cmd *tcl_cmd = (struct hal_tcl_data_cmd *)cmd; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci tcl_cmd->buf_addr_info.info0 = 428c2ecf20Sopenharmony_ci FIELD_PREP(BUFFER_ADDR_INFO0_ADDR, ti->paddr); 438c2ecf20Sopenharmony_ci tcl_cmd->buf_addr_info.info1 = 448c2ecf20Sopenharmony_ci FIELD_PREP(BUFFER_ADDR_INFO1_ADDR, 458c2ecf20Sopenharmony_ci ((uint64_t)ti->paddr >> HAL_ADDR_MSB_REG_SHIFT)); 468c2ecf20Sopenharmony_ci tcl_cmd->buf_addr_info.info1 |= 478c2ecf20Sopenharmony_ci FIELD_PREP(BUFFER_ADDR_INFO1_RET_BUF_MGR, 488c2ecf20Sopenharmony_ci (ti->ring_id + HAL_RX_BUF_RBM_SW0_BM)) | 498c2ecf20Sopenharmony_ci FIELD_PREP(BUFFER_ADDR_INFO1_SW_COOKIE, ti->desc_id); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci tcl_cmd->info0 = 528c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_DESC_TYPE, ti->type) | 538c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_ENCAP_TYPE, ti->encap_type) | 548c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_ENCRYPT_TYPE, 558c2ecf20Sopenharmony_ci ti->encrypt_type) | 568c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_SEARCH_TYPE, 578c2ecf20Sopenharmony_ci ti->search_type) | 588c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_ADDR_EN, 598c2ecf20Sopenharmony_ci ti->addr_search_flags) | 608c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_CMD_NUM, 618c2ecf20Sopenharmony_ci ti->meta_data_flags); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci tcl_cmd->info1 = ti->flags0 | 648c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_DATA_LEN, ti->data_len) | 658c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_PKT_OFFSET, ti->pkt_offset); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci tcl_cmd->info2 = ti->flags1 | 688c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO2_TID, ti->tid) | 698c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO2_LMAC_ID, ti->lmac_id); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci tcl_cmd->info3 = FIELD_PREP(HAL_TCL_DATA_CMD_INFO3_DSCP_TID_TABLE_IDX, 728c2ecf20Sopenharmony_ci ti->dscp_tid_tbl_idx) | 738c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL_DATA_CMD_INFO3_SEARCH_INDEX, 748c2ecf20Sopenharmony_ci ti->bss_ast_hash); 758c2ecf20Sopenharmony_ci tcl_cmd->info4 = 0; 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_civoid ath11k_hal_tx_set_dscp_tid_map(struct ath11k_base *ab, int id) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci u32 ctrl_reg_val; 818c2ecf20Sopenharmony_ci u32 addr; 828c2ecf20Sopenharmony_ci u8 hw_map_val[HAL_DSCP_TID_TBL_SIZE]; 838c2ecf20Sopenharmony_ci int i; 848c2ecf20Sopenharmony_ci u32 value; 858c2ecf20Sopenharmony_ci int cnt = 0; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci ctrl_reg_val = ath11k_hif_read32(ab, HAL_SEQ_WCSS_UMAC_TCL_REG + 888c2ecf20Sopenharmony_ci HAL_TCL1_RING_CMN_CTRL_REG); 898c2ecf20Sopenharmony_ci /* Enable read/write access */ 908c2ecf20Sopenharmony_ci ctrl_reg_val |= HAL_TCL1_RING_CMN_CTRL_DSCP_TID_MAP_PROG_EN; 918c2ecf20Sopenharmony_ci ath11k_hif_write32(ab, HAL_SEQ_WCSS_UMAC_TCL_REG + 928c2ecf20Sopenharmony_ci HAL_TCL1_RING_CMN_CTRL_REG, ctrl_reg_val); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci addr = HAL_SEQ_WCSS_UMAC_TCL_REG + HAL_TCL1_RING_DSCP_TID_MAP + 958c2ecf20Sopenharmony_ci (4 * id * (HAL_DSCP_TID_TBL_SIZE / 4)); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci /* Configure each DSCP-TID mapping in three bits there by configure 988c2ecf20Sopenharmony_ci * three bytes in an iteration. 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_ci for (i = 0; i < DSCP_TID_MAP_TBL_ENTRY_SIZE; i += 8) { 1018c2ecf20Sopenharmony_ci value = FIELD_PREP(HAL_TCL1_RING_FIELD_DSCP_TID_MAP0, 1028c2ecf20Sopenharmony_ci dscp_tid_map[i]) | 1038c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL1_RING_FIELD_DSCP_TID_MAP1, 1048c2ecf20Sopenharmony_ci dscp_tid_map[i + 1]) | 1058c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL1_RING_FIELD_DSCP_TID_MAP2, 1068c2ecf20Sopenharmony_ci dscp_tid_map[i + 2]) | 1078c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL1_RING_FIELD_DSCP_TID_MAP3, 1088c2ecf20Sopenharmony_ci dscp_tid_map[i + 3]) | 1098c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL1_RING_FIELD_DSCP_TID_MAP4, 1108c2ecf20Sopenharmony_ci dscp_tid_map[i + 4]) | 1118c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL1_RING_FIELD_DSCP_TID_MAP5, 1128c2ecf20Sopenharmony_ci dscp_tid_map[i + 5]) | 1138c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL1_RING_FIELD_DSCP_TID_MAP6, 1148c2ecf20Sopenharmony_ci dscp_tid_map[i + 6]) | 1158c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TCL1_RING_FIELD_DSCP_TID_MAP7, 1168c2ecf20Sopenharmony_ci dscp_tid_map[i + 7]); 1178c2ecf20Sopenharmony_ci memcpy(&hw_map_val[cnt], (u8 *)&value, 3); 1188c2ecf20Sopenharmony_ci cnt += 3; 1198c2ecf20Sopenharmony_ci } 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci for (i = 0; i < HAL_DSCP_TID_TBL_SIZE; i += 4) { 1228c2ecf20Sopenharmony_ci ath11k_hif_write32(ab, addr, *(u32 *)&hw_map_val[i]); 1238c2ecf20Sopenharmony_ci addr += 4; 1248c2ecf20Sopenharmony_ci } 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci /* Disable read/write access */ 1278c2ecf20Sopenharmony_ci ctrl_reg_val = ath11k_hif_read32(ab, HAL_SEQ_WCSS_UMAC_TCL_REG + 1288c2ecf20Sopenharmony_ci HAL_TCL1_RING_CMN_CTRL_REG); 1298c2ecf20Sopenharmony_ci ctrl_reg_val &= ~HAL_TCL1_RING_CMN_CTRL_DSCP_TID_MAP_PROG_EN; 1308c2ecf20Sopenharmony_ci ath11k_hif_write32(ab, HAL_SEQ_WCSS_UMAC_TCL_REG + 1318c2ecf20Sopenharmony_ci HAL_TCL1_RING_CMN_CTRL_REG, 1328c2ecf20Sopenharmony_ci ctrl_reg_val); 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_civoid ath11k_hal_tx_init_data_ring(struct ath11k_base *ab, struct hal_srng *srng) 1368c2ecf20Sopenharmony_ci{ 1378c2ecf20Sopenharmony_ci struct hal_srng_params params; 1388c2ecf20Sopenharmony_ci struct hal_tlv_hdr *tlv; 1398c2ecf20Sopenharmony_ci int i, entry_size; 1408c2ecf20Sopenharmony_ci u8 *desc; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci memset(¶ms, 0, sizeof(params)); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci entry_size = ath11k_hal_srng_get_entrysize(ab, HAL_TCL_DATA); 1458c2ecf20Sopenharmony_ci ath11k_hal_srng_get_params(ab, srng, ¶ms); 1468c2ecf20Sopenharmony_ci desc = (u8 *)params.ring_base_vaddr; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci for (i = 0; i < params.num_entries; i++) { 1498c2ecf20Sopenharmony_ci tlv = (struct hal_tlv_hdr *)desc; 1508c2ecf20Sopenharmony_ci tlv->tl = FIELD_PREP(HAL_TLV_HDR_TAG, HAL_TCL_DATA_CMD) | 1518c2ecf20Sopenharmony_ci FIELD_PREP(HAL_TLV_HDR_LEN, 1528c2ecf20Sopenharmony_ci sizeof(struct hal_tcl_data_cmd)); 1538c2ecf20Sopenharmony_ci desc += entry_size; 1548c2ecf20Sopenharmony_ci } 1558c2ecf20Sopenharmony_ci} 156